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
However, from its python source code, sympy.prime only accepts integers, and errors if given expressions:
julia> sympy.prime(1)
2
julia>prime(1)
ERROR: MethodError: no method matching prime(::Int64)
Closest candidates are:prime(::SymPy.SymbolicObject, ::Any...; kwargs...) at C:\Users\melonedo\.julia\packages\SymPy\4256i\src\importexport.jl:124
julia>@vars s
(s,)
julia>prime(s)
ERROR: PyError ($(Expr(:escape, :(ccall(#= C:\Users\melonedo\.julia\packages\PyCall\tqyST\src\pyfncall.jl:43 =#@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'ValueError'>ValueError('s is not an integer',)
File "C:\Users\melonedo\.julia\conda\3\lib\site-packages\sympy\ntheory\generate.py", line 368, in prime
n =as_int(nth)
File "C:\Users\melonedo\.julia\conda\3\lib\site-packages\sympy\core\compatibility.py", line 425, in as_int
raise ValueError('%s is not an integer'% (n,))
sympy.isprime is only meaningful for integers, and returns false for expression:
julia> sympy.isprime(7)
true
julia>isprime(7)
ERROR: MethodError: no method matching isprime(::Int64)
Closest candidates are:isprime(::SymPy.SymbolicObject, ::Any...; kwargs...) at C:\Users\melonedo\.julia\packages\SymPy\4256i\src\importexport.jl:109
julia>isprime(s)
false
The text was updated successfully, but these errors were encountered:
Yup, that is the case. Some of the functions naturally expect numbers, not symbolic objects. There are then two ways to use these functions
As you say, qualifying, as in sympy.isprime
or passing in a symbolic integer, as in isprime(Sym(7)) or isprime(sympify(7)). This would be useful when the value passed is the result of a symbolic computation
Here is a made up example where both usages might be of interest:
@vars n
mersenne = 2^n - 1
[isprime(mersenne(n=>i)) for i ∈ 2:100 if isprime(Sym(i))]
Now the particular function isprime has a history. Many moons ago, isprime was in base, so it made sense to extend it to symbolic objects. The usage isprime(11) then fell back to a julia-specific defn. Then base got cleaned up and the Primes package was created. To keep dependencies down this is not a dependency of SymPy and so loading
using Primes
now complains about a name conflict with isprime. If you were using this often, it would be kind of annoying. At that point three things could be considered (removing isprime here so it is always qualified, importing Primes -- requiring qualifying that usage, or adding Primes as a dependency.)
The exported signature of these two functions are
However, from its python source code,
sympy.prime
only accepts integers, and errors if given expressions:sympy.isprime
is only meaningful for integers, and returns false for expression:The text was updated successfully, but these errors were encountered: