Skip to content

Conversation

@ChrisRackauckas
Copy link
Member

No description provided.

@fgerick
Copy link

fgerick commented Aug 27, 2024

I think comparing to Float64 is not the best/for some cases the substitution gives a BigFloat instead. E.g here from the discourse discussion example:

julia> using Symbolics, Nemo

julia> @variables x
1-element Vector{Num}:
 x

julia> eq =-279//16 + x^2 ~ 0
-(279//16) + x^2 ~ 0

julia> sol = symbolic_solve(s,x)[1]
(1//2)*√(279//4)

julia> typeof(sol)
SymbolicUtils.BasicSymbolic{Real}

julia> typeof(substitute(sol,Dict()))
BigFloat

julia> y = (1//2*x)/x
1//2

julia> typeof(y)
Num

julia> typeof(substitute(y,Dict()))
Num

julia> typeof(substitute(Symbolics.unwrap(sol),Dict()))
BigFloat

julia> typeof(substitute(Symbolics.unwrap(y),Dict()))
Rational{Int64}

@ChrisRackauckas
Copy link
Member Author

That depends on the types inside of the symbolic expression. Symbolic solving uses bigints which is the cause for the bigfloats. It's just the same behavior as float. Float64 is the right answer for those tests.

@ChrisRackauckas ChrisRackauckas merged commit f4d53fe into master Aug 27, 2024
@ChrisRackauckas ChrisRackauckas deleted the symbolics_to_float branch August 27, 2024 16:37
@fgerick
Copy link

fgerick commented Aug 27, 2024

Is there a reason why we cannot use Base.float instead of symbolic_to_float ? I guess there is a reason this is defined like this:

Base.float(x::Num) = x

@ChrisRackauckas
Copy link
Member Author

It would effect tracing as it would make the tracers become non-lazy in numerical contexts that use float, like linear algebra.

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

Successfully merging this pull request may close these issues.

3 participants