Skip to content

Commit

Permalink
doctest fix=true (#420)
Browse files Browse the repository at this point in the history
* doctest fix=true

* adjust docs for improved syms macro
  • Loading branch information
jverzani authored Apr 29, 2021
1 parent a926969 commit 69f2fd2
Show file tree
Hide file tree
Showing 20 changed files with 352 additions and 257 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SymPy"
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
version = "1.0.43"
version = "1.0.44"


[deps]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@



# SymPy Package to bring Python's `Sympy` functionality into `Julia` via `PyCall`
# SymPy Package to bring Python's `SymPy` functionality into `Julia` via `PyCall`



Expand Down Expand Up @@ -92,7 +92,7 @@ With the `SymPy` package this gets replaced by a more `julia`n syntax:

```
using SymPy
x = symbols("x") # or @syms x, @vars x, Sym("x"), or Sym(:x)
x = symbols("x") # or @syms x
y = sin(pi*x)
y(1) # Does y.subs(x, 1). Use y(x=>1) to be specific as to which symbol to substitute
```
Expand Down Expand Up @@ -121,7 +121,7 @@ SymPy has a mix of function calls (as in `sin(x)`) and method calls
specialized methods for many generic `Julia` functions, such as `sin`,
a priviledged set of the function calls in `sympy` are imported as
generic functions narrowed on their first argument being a symbolic
object, as constructed by `Sym` or `symbols`. (Calling
object, as constructed by `@syms`, `Sym`, or `symbols`. (Calling
`import_from(sympy)` will import all the function calls.)

The basic usage follows these points:
Expand Down Expand Up @@ -150,7 +150,7 @@ dispatch, but refers to a SymPy function from the `sympy` object. Its
argument, `1`, is converted by `PyCall` into a Python object for the
function to process.

In the initial example, slightly rewritten, we could have written:
In the initial example, slightly rewritten, we could have issued:

```
x = symbols("x")
Expand All @@ -168,4 +168,4 @@ dot-call syntax of `PyCall` to call the `subs` method of the symbolic

Not illustrated above, but classes and other objects from SymPy are
not brought in by default, and can be accessed using qualification, as
in `sympy.Function` (used to define symbolic functions).
in `sympy.Function` (used, as is `@syms`, to define symbolic functions).
9 changes: 5 additions & 4 deletions docs/src/Tutorial/basic_operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ julia> expr = x^4 - 4*x^3 + 4*x^2 - 2*x + 3
x - 4⋅x + 4⋅x - 2⋅x + 3
julia> replacements = [(x^i, y^i) for i in 1:5 if iseven(i)]
2-element Array{Tuple{Sym,Sym},1}:
2-element Vector{Tuple{Sym, Sym}}:
(x^2, y^2)
(x^4, y^4)
Expand Down Expand Up @@ -366,7 +366,8 @@ argument to `evalf`. Let's compute the first 100 digits of `\pi`.

```jldoctest basicoperations
julia> PI.evalf(100)
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
3.1415926535897932384626433832795028841971693993751058209749445923078164062862
08998628034825342117068
```

----
Expand Down Expand Up @@ -490,7 +491,7 @@ sin(x)
julia> fn = lambdify(expr);
julia> fn.(a)
11-element Array{Float64,1}:
11-element Vector{Float64}:
0.0
0.8414709848078965
0.9092974268256817
Expand Down Expand Up @@ -518,7 +519,7 @@ julia> body = convert(Expr, ex)
:(x ^ 2 + sin(x) ^ 2)
julia> syms = Symbol.(free_symbols(ex))
1-element Array{Symbol,1}:
1-element Vector{Symbol}:
:x
julia> fn = eval(Expr(:function, Expr(:call, gensym(), syms...), body));
Expand Down
25 changes: 12 additions & 13 deletions docs/src/Tutorial/calculus.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ julia> x, y, z = symbols("x y z")
(x, y, z)
```

We can also use the convenient `@syms` macro, as with
We primarily will use the convenient `@syms` macro, as with

```jldoctest calculus
julia> @syms x y z
Expand Down Expand Up @@ -761,15 +761,15 @@ the `differentiate_finite` function:
* `differentiate_finite` is not exported
```jldoctest calculus
julia> f, g = symbols("f g", cls=sympy.Function)
(PyObject f, PyObject g)
julia> @syms f(), g()
(f, g)
julia> sympy.differentiate_finite(f(x)*g(x))
-f(x - 1/2)⋅g(x - 1/2) + f(x + 1/2)⋅g(x + 1/2)
```
(The functions `f` and `g` can also be created with the command `@symfuns f g`, using the `@symfuns` macro.)
(The functions `f` and `g` can also be created with `SymFunction`.)
----
Expand Down Expand Up @@ -893,19 +893,18 @@ takes `order`, `x_list`, `y_list` and `x0` as parameters:
* `apply_finite_diff` is not exported:
```jldoctest calculus
julia> x_list = [-3, 1, 2]
3-element Array{Int64,1}:
julia> xs = [-3, 1, 2]
3-element Vector{Int64}:
-3
1
2
julia> y_list = symbols("a b c")
(a, b, c)
julia> sympy.apply_finite_diff(1, x_list, y_list, 0)
3⋅a b 2⋅c
- ─── -+ ───
20 4 5
julia> @syms ys[1:3]
(Sym[ys₁, ys₂, ys₃],)
julia> sympy.apply_finite_diff(1, xs, ys, 0)
3⋅ys₁ ys₂ 2⋅ys₃
- ───── - ─── + ─────
20 4 5
```
36 changes: 29 additions & 7 deletions docs/src/Tutorial/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ To define variables, we must use `symbols`.

##### In `Julia`:

We can use `symbols`, as here:

```jldoctest gotchas
julia> x = symbols("x")
x
Expand All @@ -91,6 +93,13 @@ julia> x + 1
x + 1
```

but the recommended way is to use `@syms`:

```jldoctest gotchas
julia> @syms x
(x,)
```

----

`symbols` takes a string of variable names separated by spaces or commas,
Expand All @@ -105,11 +114,13 @@ For now, let us just define the most common variable names, `x`, `y`, and

##### In `Julia`:

Again, we use the `@syms` macro:

```jldoctest gotchas
julia> x + 1
x + 1
julia> x, y, z = symbols("x y z")
julia> @syms x, y, z
(x, y, z)
```

Expand Down Expand Up @@ -143,6 +154,17 @@ julia> b
a
```

This can also be done with the `@syms` macro:

```jldoctest gotchas
julia> @syms a=>"b" b=>"c"
(b, c)
julia> a + b
b + c
```


----

Here we have done the very confusing thing of assigning a Symbol with the name
Expand Down Expand Up @@ -205,7 +227,7 @@ you're wrong. Let's see what really happens

##### In `Julia`:

* we must change to double quotes (or use `@syms x`, say)
* we must change to double quotes (or, as recommended, use `@syms x`)

```jldoctest gotchas
julia> x = symbols("x")
Expand Down Expand Up @@ -281,8 +303,8 @@ julia> expr
##### In `Julia`:

```jldoctest gotchas
julia> x = symbols("x")
x
julia> @syms x
(x,)
julia> expr = x + 1
x + 1
Expand Down Expand Up @@ -314,8 +336,8 @@ discussed in more detail later.
##### In `Julia`:

```jldoctest gotchas
julia> x = symbols("x")
x
julia> @syms x
(x,)
julia> expr = x + 1
x + 1
Expand Down Expand Up @@ -583,7 +605,7 @@ julia> ex = x^2 - 2x + 2
x - 2⋅x + 2
julia> fn = lambdify(ex)
#89 (generic function with 1 method)
#99 (generic function with 1 method)
julia> fn(1) - ex(1)
0
Expand Down
17 changes: 13 additions & 4 deletions docs/src/Tutorial/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Let us define a symbolic expression, representing the mathematical expression
* the command `from sympy import *` is *essentially* run (only functions are "imported", not all objects), so this becomes the same after adjusting the quotes:

```jldoctest intro
julia> x, y = symbols("x y")
julia> @syms x, y
(x, y)
julia> expr = x + 2*y
Expand Down Expand Up @@ -243,7 +243,7 @@ of symbolic power SymPy is capable of, to whet your appetite.
* again, the functions in the `sympy` module are already imported:

```jldoctest intro
julia> x, t, z, nu = symbols("x t z nu")
julia> @syms x, t, z, nu
(x, t, z, nu)
```

Expand Down Expand Up @@ -346,7 +346,7 @@ Solve $x^2 - 2 = 0$.

```jldoctest intro
julia> solve(x^2 - 2, x)
2-element Array{Sym,1}:
2-element Vector{Sym}:
-√2
√2
```
Expand Down Expand Up @@ -388,6 +388,15 @@ julia> dsolve(y''(t) - y(t) - exp(t), y(t)) |> string
"Eq(y(t), C2*exp(-t) + (C1 + t/2)*exp(t))"
```

Even more so, `@syms` allows the specification of symbolic functions, as follows:

```jldoctest intro
julia> @syms y()::real t
(y, t)
julia> dsolve(y''(t) - y(t) - exp(t), y(t)) |> string
"Eq(y(t), C2*exp(-t) + (C1 + t/2)*exp(t))"
```
----

Find the eigenvalues of `\left[\begin{smallmatrix}1 & 2\\2 &
Expand All @@ -408,7 +417,7 @@ Find the eigenvalues of `\left[\begin{smallmatrix}1 & 2\\2 &
julia> out = sympy.Matrix([1 2; 2 2]).eigenvals();
julia> sort(collect(keys(out)))
2-element Array{Any,1}:
2-element Vector{Any}:
3/2 - sqrt(17)/2
3/2 + sqrt(17)/2
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Tutorial/manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ expression looks like internally by using `srepr`
```jldoctest manipulation
julia> using SymPy
julia> x, y, z = symbols("x y z")
julia> @syms x, y, z
(x, y, z)
julia> expr = 2^x + x*y
Expand Down
Loading

0 comments on commit 69f2fd2

Please sign in to comment.