Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplying NumberSymbols turns them into their numerical approximation #407

Closed
mkualquiera opened this issue Feb 3, 2021 · 1 comment
Closed

Comments

@mkualquiera
Copy link

mkualquiera commented Feb 3, 2021

When a NumberSymbol such as pi is multiplied by a number or negated, it is converted to a Float64:

julia> typeof(pi)
Irrational{:π}

julia> typeof(pi*2)
Float64

For comparison, this is the result in python:

>>> type(pi)
<class 'sympy.core.numbers.Pi'>
>>> type(2*pi)
<class 'sympy.core.mul.Mul'>

This breaks any symbolic computation that involves such constants and their properties, for instance:

julia> i = symbols(:i, integer=True)
i

julia> sin(i*pi)
0

julia> sin(i*-pi)
-sin(3.14159265358979⋅i)
@jverzani
Copy link
Collaborator

jverzani commented Feb 3, 2021

Yes, this is true. You have to be wary of eager conversion to floating point before a value is converted to a symbolic value. In this case you can use PI (which is the same as PI=Sym(pi)) and the symbolic value will force others numbers to promote to symbolic values.

(As an example. Even this 1/2*PI will be an issue as 1/2 will be a floating point number. To avoid this you can use rationals, as in 1//2 * pi, or reexpress, as in PI/2.

Hope that clarifies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants