Skip to content

Commit

Permalink
Issue 16 (#540)
Browse files Browse the repository at this point in the history
* move SymPyPyCall -> SymPy; breaking change

* fix for 1.6
  • Loading branch information
jverzani committed Nov 27, 2023
1 parent df4067e commit a6e74db
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 4 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 = "2.0.0"
version = "2.0.1"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand Down
155 changes: 152 additions & 3 deletions src/SymPy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,159 @@ _pyimport(a) = PyCall.pyimport(a)
_pyimport_conda(a,b) = PyCall.pyimport_conda(a, b)
_pyobject(x) = PyCall.PyObject(x)
_pytype_mapping(typ,a) = PyCall.pytype_mapping(typ, a)
const _pybuiltin = PyCall.builtin

core_src_path = joinpath(pathof(SymPy.SymPyCore), "../../src/SymPy")
include(joinpath(core_src_path, "sympy.jl"))
# for 1.6, we can't pass in _pybuiltin so we just
# paste in here sympy.jl and modify.
# not DRY!
#core_src_path = joinpath(pathof(SymPy.SymPyCore), "../../src/SymPy")
#include(joinpath(core_src_path, "sympy.jl"))
## Common code

using LinearAlgebra
import SpecialFunctions
import CommonEq
import CommonSolve

## XXX This should be in a file in SymPyCore...
#=
Several functions are exported
* generic functions in base `Julia` having a `sympy` counterpart have
methods defined to dispatch on the first argument. (Basically,
`Base.sin(x::Sym) = \uparrow(_sympy_.sin(\downarrow(x))`.) These are
defined in the `generic_methods` list in `SymPyCore` and read in via
the package once a Python bridge is in place.
* Some object methods, such as `ex.subs(...)` have exported functions
that use the `Julian` order `subs(ex, ...)`. All object methods
should be callable using the python syntax `obj.method(...)`.
* Functions in `sympy` that are foundational (e.g., `simplify`) have
methods created dispatch on the first argument being symbolic
(typically type `Sym`). These are exported. Other functions, e.g.,
`trigsimp` may be called via `sympy.trigsimp(...)`.
=#

## import/exports
import SymPyCore: , ,
import SymPyCore: SymbolicObject, Sym, SymFunction
import SymPyCore: symbols, free_symbols
import SymPyCore: simplify, expand, together, apart, factor, cancel
import SymPyCore: solve, dsolve, nsolve, linsolve, nonlinsolve, solveset
import SymPyCore: subs, lambdify, simplify
import SymPyCore: ask, doit
import SymPyCore: N
import SymPyCore: limit, diff, integrate, Differential, Heaviside
import SymPyCore: rhs, lhs
import SymPyCore: Wild, Permutation, PermutationGroup
import SymPyCore: , , ¬ # infix logical operators

# more exports defined in SymPyCore/src/gen_methods_sympy
export Sym, SymFunction
export sympy, PI, E, IM, oo, zoo
export @syms, sympify, symbols, free_symbols
export simplify, expand, together, apart, factor, cancel
export solve, dsolve, nsolve, linsolve, nonlinsolve, solveset
export real_roots, nroots # roots
export sign #,degree
export series, summation, hessian
export subs, lambdify
export ask, doit, rewrite
export N
export limit, diff, integrate, Differential, Heaviside
export rhs, lhs
export Wild #, cse
export Permutation, PermutationGroup
export , , ¬
export 𝑄, 𝑆, Introspection

export ,

# emacs and indent; this goes last
import SymPyCore: Lt, , Le, , Eq, , Ne, , , Ge, , Gt,
export Lt, , Le, , Eq, , Ne, , , Ge, , Gt,



# exported symbols and their python counterparts
const _sympy_ = _pynull()
const sympy = Sym(_sympy_)

const _combinatorics_ = _pynull()
const combinatorics = Sym(_combinatorics_)

const _PI_ =_pynull()
const PI = Sym(_PI_)

const _E_ =_pynull()
const E = Sym(_E_)

const _IM_ =_pynull()
const IM = Sym(_IM_)

const _oo_ =_pynull()
const oo = Sym(_oo_)

const _zoo_ =_pynull()
const zoo = Sym(_zoo_)

Base.@deprecate_binding TRUE Sym(true)
Base.@deprecate_binding FALSE Sym(false)

const _𝑄_ = _pynull()
const 𝑄 = Sym(_𝑄_)

const _𝑆_ = _pynull()
const 𝑆 = Sym(_𝑆_)

# ugly, but needed to speed up python_connection
const _pyset_ = _pynull()
const _pytuple_ = _pynull()
const _pylist_ = _pynull()
const _pydict_ = _pynull()
const _bool_ = _pynull()
const _types_ = _pynull()
const _ModuleType_ = _pynull()
const _FiniteSet_ = _pynull()
const _MutableDenseMatrix_ = _pynull()

function __init__()

## Define sympy, mpmath, ...
_copy!(_sympy_, _pyimport_conda("sympy", "sympy"))
_copy!(_combinatorics_, _pyimport_conda("sympy.combinatorics", "sympy"))

_copy!(_PI_, _sympy_.pi)
_copy!(_E_, _sympy_.E)
_copy!(_IM_, _sympy_.I)
_copy!(_oo_, _sympy_.oo)
_copy!(_zoo_, _sympy_.zoo)
_copy!(_𝑆_, _sympy_.S)
_copy!(_𝑄_, _sympy_.Q)

# ugly, avoids allocation in PyCall
_pybuiltin = PyCall.builtin # <-- needed with 1.6 + SymPy
_copy!(_pyset_, getproperty(_pybuiltin, :set))
_copy!(_pytuple_, getproperty(_pybuiltin, :tuple))
_copy!(_pylist_, getproperty(_pybuiltin, :list))
_copy!(_pydict_, getproperty(_pybuiltin, :dict))
_copy!(_bool_, getproperty(_pybuiltin, :bool))
_copy!(_types_, _pyimport_conda("types", "types"))
_copy!(_ModuleType_, getproperty(_types_, :ModuleType))
_copy!(_FiniteSet_, _sympy_.FiniteSet)
_copy!(_MutableDenseMatrix_, _sympy_.MutableDenseMatrix)


end


# includes
core_src_path = joinpath(pathof(SymPyCore), "../../src/SymPy")
include(joinpath(core_src_path, "constructors_sympy.jl"))
include(joinpath(core_src_path, "gen_methods_sympy.jl"))
include(joinpath(core_src_path, "additional_methods_sympy.jl"))
include(joinpath(core_src_path, "show_sympy.jl"))


include("python_connection.jl")

Expand Down

2 comments on commit a6e74db

@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/96012

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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 v2.0.1 -m "<description of version>" a6e74dbabeee0c19d9fcc7dda489552c276e129e
git push origin v2.0.1

Please sign in to comment.