You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-6Lines changed: 5 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -17,24 +17,23 @@ There would be a few deprecations:
17
17
18
18
*`elements` for sets would be removed (convert to a `Set` by default)
19
19
20
-
*`sympy.poly`*not*`sympy.Poly`, though `sympy.Poly` does work for now via a hacky thing to manage `ManagedProperties`,
20
+
*`sympy.poly`*not*`sympy.Poly`
21
21
22
22
*`limit(ex, x, c)` deprecated; use `limit(ex, x=>c)` or `sympy.limit`
23
23
24
-
*`Base.show` isn't *currently* using pretty priting
24
+
*`Base.show` isn't *currently* using pretty printing
25
25
26
26
* Would `Q` be ported? (Use `\itQ` for now)
27
27
28
-
* What to do with matrices? Using `Matrix{Sym}` with no `SymMatrix` type expected
29
-
30
-
* would we export `CommonEq` symbols?
28
+
* What to do with matrices? Using `Matrix{Sym}` with no `SymMatrix` type expected. Views seem off, so for now a copy is made.
31
29
32
30
* no new special functions exported, just the ones in SpecialFunctions.jl
33
31
34
32
35
33
## Installing `sympy`,
36
34
37
-
To install `sympy` in `PythonCall` isn't hard; below shows how it may be done. If this were to become registered, automating this would be very desirable.
35
+
The `sympy` package for Python should install with the package through `PythonCall` and `CondaPkg`. If not,
36
+
to install `sympy` in `PythonCall` isn't hard; below shows how it may be done.
Copy file name to clipboardExpand all lines: docs/src/introduction.md
+34-67Lines changed: 34 additions & 67 deletions
Original file line number
Diff line number
Diff line change
@@ -20,8 +20,7 @@ It owes an enormous debt to the tutorial for using SymPy within Python which may
20
20
[here](http://docs.sympy.org/dev/tutorial/index.html). The overall structure and many examples are taken from that work, with adjustments and additions to illustrate the differences due to using `SymPy` within `Julia`.
21
21
22
22
23
-
After installing `SymPy`, which is discussed in the package's `README`
24
-
file, we must first load it into `Julia` with the standard command
23
+
After installing `SymPyCall` we must first load it into `Julia` with the standard command
25
24
`using`:
26
25
27
26
@@ -91,7 +90,7 @@ The `@syms` macro is recommended, and will be modeled in the following, as it ma
91
90
92
91
### Assumptions
93
92
94
-
Finally, there is the `symbols` constructor for producing symbolic objects. With `symbols` it is
93
+
Finally, there is the `symbols` constructor for producing symbolic objects. With `symbols`(and with `@syms`) it is
95
94
possible to pass assumptions onto the variables. A list of possible
96
95
assumptions is
97
96
[here](http://docs.sympy.org/dev/modules/core.html#module-sympy.core.assumptions). Some
@@ -155,16 +154,14 @@ use `Sym` to create a variable from a function name in Base.
155
154
156
155
### Special constants
157
156
158
-
`Julia` has its math constants, like `pi` and `e`, `SymPy` as well. A few of these have `Julia` counterparts provided by `SymPy`. For example, these two constants are defined (where `oo` is for infinity):
157
+
`Julia` has its math constants, like `pi` and `e`, `SymPy` as well. A few of these have `Julia` counterparts provided by `SymPyCall`. For example, these two constants are defined (where `oo` is for infinity):
159
158
160
159
```jldoctest introduction
161
160
julia> PI, oo
162
161
(pi, oo)
163
162
164
163
```
165
164
166
-
(The pretty printing of SymPy objects does not work for tuples.)
167
-
168
165
Numeric values themselves can be symbolic. This example shows the
169
166
difference. The first `asin` call dispatches to `Julia`'s `asin`
170
167
function, the second to `SymPy`'s:
@@ -221,7 +218,7 @@ z + 1 + pi
221
218
222
219
!!! note
223
220
224
-
The calling pattern for `subs` is different from a typical `Julia` function call. The `subs` call is `object.method(arguments)` whereas a more "`Julia`n" function call is `method(objects, other objects....)`, as `Julia` offers multiple dispatch of methods. `SymPy` uses the Python calling method, adding in `Julia`n style when appropriate for generic usage within `Julia`. `SymPy` imports most all generic functions from the underlying `sympy` module and specializes them on a symbolic first argument.
221
+
The calling pattern for `subs` is different from a typical `Julia` function call. The `subs` call is `object.method(arguments)` whereas a more "`Julia`n" function call is `method(objects, other objects....)`, as `Julia` offers multiple dispatch of methods. `SymPy` uses the Python calling method, adding in `Julia`n style when appropriate for generic usage within `Julia`. `SymPyCall` imports many generic functions from the underlying `sympy` module and specializes them on a symbolic first argument.
225
222
226
223
For `subs`, the simple substitution `ex.object(x,a)` is similar to simple function evaluation, so `Julia`'s call notation will work. To specify the pairing off of `x` and `a`, the `=>` pairs notation is used.
227
224
@@ -287,9 +284,9 @@ necessary at times if `N` does not give the desired type.
287
284
288
285
## Algebraic expressions
289
286
290
-
`SymPy` overloads many of `Julia`'s functions to work with symbolic objects, such as seen above with `asin`. The usual mathematical operations such as `+`, `*`, `-`, `/` etc. work through `Julia`'s promotion mechanism, where numbers are promoted to symbolic objects, others dispatch internally to related `SymPy` functions.
287
+
`SymPyCall` overloads many of `Julia`'s functions to work with symbolic objects, such as seen above with `asin`. The usual mathematical operations such as `+`, `*`, `-`, `/` etc. work through `Julia`'s promotion mechanism, where numbers are promoted to symbolic objects, others dispatch internally to related SymPy functions.
291
288
292
-
In most all cases, thinking about this distinction between numbers and symbolic numbers is unnecessary, as numeric values passed to `SymPy` functions are typically promoted to symbolic expressions. This conversion will take math constants to their corresponding `SymPy` counterpart, rational expressions to rational expressions, and floating point values to floating point values. However there are edge cases. An expression like `1//2 * pi * x` will differ from the seemingly identical `1//2 * (pi * x)`. The former will produce a floating point value from `1//2 * pi` before being promoted to a symbolic instance. Using the symbolic value `PI` makes this expression work either way.
289
+
In most all cases, thinking about this distinction between numbers and symbolic numbers is unnecessary, as numeric values passed to `SymPyCall` functions are typically promoted to symbolic expressions. This conversion will take math constants to their corresponding `SymPyCall` counterpart, rational expressions to rational expressions, and floating point values to floating point values. However there are edge cases. An expression like `1//2 * pi * x` will differ from the seemingly identical `1//2 * (pi * x)`. The former will produce a floating point value from `1//2 * pi` before being promoted to a symbolic instance. Using the symbolic value `PI` makes this expression work either way.
@@ -301,7 +298,7 @@ expected, as the former call first dispatches to a generic defintion,
301
298
but the latter two expressions do not.
302
299
303
300
304
-
`SymPy` makes it very easy to work with polynomial and rational expressions. First we create some variables:
301
+
`SymPyCall` makes it very easy to work with polynomial and rational expressions. First we create some variables:
305
302
306
303
```jldoctest introduction
307
304
julia> @syms x y z
@@ -366,7 +363,7 @@ x*y^2 + x + y*(x^2 + x)
366
363
367
364
These are identical expressions, though viewed differently.
368
365
369
-
A more broad-brush approach is to let `SymPy` simplify the values. In this case, the common value of `x` is factored out:
366
+
A more broad-brush approach is to let `SymPyCall` simplify the values. In this case, the common value of `x` is factored out:
370
367
371
368
```jldoctest introduction
372
369
julia> simplify(q)
@@ -613,7 +610,7 @@ julia> q.coeffs()
613
610
614
611
!!! note
615
612
616
-
XXX This is SYmPy not SymPyCall Either `sympy.poly` or `sympy.Poly` may be used. The `Poly` constructor from SymPy is *not* a function, so is not exported when `SymPy` is loaded. To access it, the object must be qualified by its containing module, in this case `Poly`. Were it to be used frequently, an alias could be used, as in `const Poly=sympy.Poly` *or* the `import_from` function, as in `import_from(sympy, :Poly)`. The latter has some attempt to avoid naming collisions.
613
+
This is `sympy` not `SymPyCall`. Using `sympy.Poly` is not supported. The `Poly` constructor from SymPy is *not* a function, so is not exported when `SymPyCa;;` is loaded.
that for degree 5 polynomials, or higher, it is not always possible to
642
639
express the roots in terms of radicals. However, when the roots are
643
-
rational `SymPy` can have success:
640
+
rational SymPy can have success:
644
641
645
642
646
643
```jldoctest introduction
@@ -658,10 +655,6 @@ julia> real_roots(p)
658
655
659
656
```
660
657
661
-
!!! note "Why `string`?"
662
-
663
-
XXX THIS ISN"T CURRENTLY NEEDED, so we have commented them out. XXX The uses of `string(p)` above and elsewhere throughout the introduction is only for technical reasons related to doctesting and how `Documenter.jl` parses the expected output. This usage is not idiomatic, or suggested; it only allows the cell to be tested programatically for regressions. Similarly, expected errors are wrapped in `try`-`catch` blocks just for testing purposes.
664
-
665
658
666
659
In this example, the degree of `p` is 8, but only the 6 real roots
667
660
returned, the double root of $3$ is accounted for. The two complex
The output of `solveset` is a set, rather than a vector or
784
-
dictionary. To get the values requires some work. For *finite sets* we collect the elements
785
-
with `collect`, but first we must convert to a `Julia``Set`:
777
+
dictionary.
786
778
787
779
```jldoctest introduction
788
780
julia> v = solveset(x^2 - 4)
@@ -791,32 +783,6 @@ Set{Sym} with 2 elements:
791
783
-2
792
784
```
793
785
794
-
```
795
-
XXX This is not current
796
-
julia> collect(Set(v...))
797
-
```
798
-
799
-
This composition is done in the `elements` function:
800
-
801
-
```
802
-
XXX jldoctest introduction not current
803
-
julia> elements(v)
804
-
805
-
```
806
-
807
-
!!! note "no elements"
808
-
In `SymPyCall` the `elements` function is not used, just use `collect`, as in `collect(v)
809
-
810
-
```jldoctest introduction
811
-
julia> collect(v)
812
-
2-element Vector{Sym}:
813
-
2
814
-
-2
815
-
```
816
-
817
-
818
-
The `elements` function does not work for more complicated (non-finite) sets, such as `u`. For these, the `contains` method may be useful to query the underlying elements
819
-
820
786
821
787
822
788
Solving within Sympy has limits. For example, there is no symbolic solution here:
@@ -931,7 +897,7 @@ unknowns. When that is not the case, one can specify the variables to
931
897
solve for as a vector. In this example, we find a quadratic polynomial
@@ -971,7 +936,7 @@ Finally for `solve`, we show one way to re-express the polynomial $a_2x^2 + a_1x
971
936
as $b_2(x-c)^2 + b_1(x-c) + b_0$ using `solve` (and not, say, an
972
937
expansion theorem.)
973
938
974
-
```julia
939
+
```jldoctest introduction
975
940
julia> n = 3
976
941
3
977
942
@@ -988,18 +953,20 @@ julia> p = sum([as[i+1]*x^i for i in 0:(n-1)]);
988
953
989
954
julia> q = sum([bs[i+1]*(x-c)^i for i in 0:(n-1)]);
990
955
991
-
julia>solve(p-q, bs)
992
-
Dict{Any, Any} with 3 entries:
993
-
bs₁ => as₁ + as₂*c + as₃*c^2
994
-
bs₂ => as₂ +2*as₃*c
995
-
bs₃ => as₃
956
+
julia> d = solve(p-q, bs);
957
+
958
+
julia> [k => d[k] for k ∈ bs]
959
+
3-element Vector{Pair{Sym, Sym}}:
960
+
bs₁ => as₁ + as₂*c + as₃*c^2
961
+
bs₂ => as₂ + 2*as₃*c
962
+
bs₃ => as₃
996
963
997
964
```
998
965
999
966
1000
967
### Solving using logical operators
1001
968
1002
-
The `solve` function does not need to just solve `ex = 0`. There are other means to specify an equation. Ideally, it would be nice to say `ex1 == ex2`, but the interpretation of `==` is not for this. Rather, `SymPy` introduces `Eq` for equality. So this expression
969
+
The `solve` function does not need to just solve `ex = 0`. There are other means to specify an equation. Ideally, it would be nice to say `ex1 == ex2`, but the interpretation of `==` is not for this. Rather, `SymPyCall` introduces `Eq` for equality. So this expression
1003
970
1004
971
```jldoctest introduction
1005
972
julia> solve(Eq(x, 1))
@@ -1026,7 +993,7 @@ julia> solve(x ⩵ 1)
1026
993
1027
994
Here is an alternative way of asking a previous question on a pair of linear equations:
0 commit comments