-
Notifications
You must be signed in to change notification settings - Fork 157
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
avoiding integer overflow in symbolic calculations? #1044
Comments
It just follows Julia's rules, so function Babylonian(x; N = 10)
t = (1+x)/2
for i = 2:N; t=(t + x/t)/big(2) end
t
end
using Symbolics
@variables x
Symbolics.derivative(simplify(Babylonian(x,N=4)),x)
simplify(Symbolics.derivative(simplify(Babylonian(x,N=4)),x)) julia> Symbolics.derivative(simplify(Babylonian(x,N=4)),x)
(15 + 454x + 3003(x^2) + 6432(x^3) + 5005(x^4) + 1362(x^5) + 105(x^6)) / (128(1 + x)*((1//4) + (3//2)*x + (1//4)*(x^2))*((1//16) + (7//4)*x + (35//8)*(x^2) + (7//4)*(x^3) + (1//16)*(x^4))) - (128((1//4) + (3//2)*x + (1//4)*(x^2))*((1//16) + (7//4)*x + (35//8)*(x^2) + (7//4)*(x^3) + (1//16)*(x^4)) + 128(1 + x)*((1//4) + (3//2)*x + (1//4)*(x^2))*((7//4) + (35//4)*x + (21//4)*(x^2) + (1//4)*(x^3)) + 128(1 + x)*((3//2) + (1//2)*x)*((1//16) + (7//4)*x + (35//8)*(x^2) + (7//4)*(x^3) + (1//16)*(x^4)))*((15x + 227(x^2) + 1001(x^3) + 1608(x^4) + 1001(x^5) + 227(x^6) + 15(x^7)) / (16384((1 + x)^2)*(((1//4) + (3//2)*x + (1//4)*(x^2))^2)*(((1//16) + (7//4)*x + (35//8)*(x^2) + (7//4)*(x^3) + (1//16)*(x^4))^2)))
julia> simplify(Symbolics.derivative(simplify(Babylonian(x,N=4)),x))
(960.0 + 29056.0x + 438592.0(x^2) + 3.523328e+06(x^3) + 1.6168832e+07(x^4) + 4.342272e+07(x^5) + 7.0727424e+07(x^6) + 7.0659072e+07(x^7) + 4.3384384e+07(x^8) + 1.6060544e+07(x^9) + 3.474368e+06(x^10) + 396032.0(x^11) + 19072.0(x^12)) / (524288((1 + x)^2)*(((1//4) + (3//2)*x + (1//4)*(x^2))^2)*(((1//16) + (7//4)*x + (35//8)*(x^2) + (7//4)*(x^3) + (1//16)*(x^4))^2)) works, though the fact that the last simplify changes to floats is a bug. @shashi do you know why that might be happening? |
Julia evaluation for What I would like would be a promotion rule (maybe enabled by a flag or a type of symbolic variable?), that allows one to use Is there a way to attach a type to a symbolic variable? e.g. |
This is an example from our matrix calculus class that worked in SymPy but is failing with Symbolics:
which gives
followed by a long stacktrace.
Is there a way to tell Symbolics that I want it to use
BigInt
arithmetic here? e.g. shouldn't(1+x)/2
useBigInt
ifx
is symbolic?The text was updated successfully, but these errors were encountered: