Skip to content

Commit

Permalink
Issue sympy stats (#389)
Browse files Browse the repository at this point in the history
* adjust compat entry for RecipesBase; close #386

* add comment about import_from; bump version

* version bump
  • Loading branch information
jverzani authored Nov 29, 2020
1 parent 82d390f commit e6ced1f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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.32"
version = "1.0.33"


[deps]
Expand All @@ -11,7 +11,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[compat]
PyCall = "1.91"
RecipesBase = "0.7, 1.0"
RecipesBase = "0.7, 0.8, 1.0, 1.1"
SpecialFunctions = "0.8, 0.9, 0.10, 1.0"
julia = "1.0"

Expand Down
33 changes: 33 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,36 @@ julia> out.doit()
x ⋅(log(x) + 1)
```

## Using other features of SymPy

By design, along with methods defined for generic functions in `Julia`, only a select number of core SymPy functions are exported; others need to be qualified. Many can be found, as above, from the syntax `sympy.XXX`, where the `XXX` method from the underlying `sympy` module is used. Many more must be imported before being available.

For example, the [Stats](https://docs.sympy.org/latest/modules/stats.html) module provides methods to support the concept of a random variable used in probability and statistics. The following shows how to import all the methods into a session:

```jldoctest Stats
julia> SymPy.PyCall.pyimport_conda("sympy.stats", "sympy")
PyObject <module 'sympy.stats' from '/Users/verzani/.julia/conda/3/lib/python3.7/site-packages/sympy/stats/__init__.py'>
julia> SymPy.import_from(sympy.stats)
julia> p = 1//2
1//2
julia> @vars x integer=true positive=true
(x,)
julia> pdf = p * (1-p)^(x-1);
julia> D = DiscreteRV(x, pdf, set=sympy.S.Naturals)
x
julia> E(D)
2
julia> P(D ≫ 3)
1/8
```

The `import_from` function imports all the functions it can, creating methods specialized on their first argument being symbolic. In this case, `E` and `P` are used above without qualification. `Naturals`, above, is in a different sympy module, and hasn't been imported, so it must be qualified above. The `pyimport_conda` call of `PyCall` will import the module into the specific name, and if necessary install the underlying package.

The above works well for interactive usage, but would cause problems were it included in package code, as the assignment within `pyimport_conda` occurs at run time. There are necessary workarounds.

2 comments on commit e6ced1f

@jverzani
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/25487

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.33 -m "<description of version>" e6ced1f7bbe3550bc26a8ddc82d0fd6897059814
git push origin v1.0.33

Please sign in to comment.