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
For example the following gives Float64 instead of rational values:
julia>@variables x y;
julia> Symbolics.solve_for([x + y ~2, x - y ~1], [x, y])
2-element Vector{Float64}:1.50.5
julia> Symbolics.solve_for([x + y ~2//1, x - y ~1//1], [x, y])
2-element Vector{Float64}:1.50.5
Here using rational coefficients makes no difference.
Note that the behavior depends on the values of the coefficients. Here's a case where using rational literals results in a mix of Rational and Float64:
julia> Symbolics.solve_for([x + y ~3, x - y ~1], [x, y])
2-element Vector{Float64}:2.01.0
julia> Symbolics.solve_for([x + y ~3//1, x - y ~1//1], [x, y])
2-element Vector{Real}:21.0
And here's one where a rational coefficient gives all-rational output:
julia> Symbolics.solve_for([x +2y ~2, x - y ~1], [x, y])
2-element Vector{Float64}:1.33333333333333350.3333333333333333
julia> Symbolics.solve_for([x +2//1*y ~2, x - y ~1], [x, y])
2-element Vector{Rational{Int64}}:4/31/3
It seems to me that the issue is that the coefficients of x and y are automatically set to 1 under the hood, and not 1//1. To enforce that the coefficients become rational, multiply one (or both) equation(s) by 2 and make at least one coefficient rational, to "trigger" promotion to rationals during construction of the linear system A*x = B
using Symbolics
@variables x y
Symbolics.solve_for([
2//1*x +2*y ~4//1,
x - y ~1
], [x, y])
For example the following gives Float64 instead of rational values:
Here using rational coefficients makes no difference.
Note that the behavior depends on the values of the coefficients. Here's a case where using rational literals results in a mix of Rational and Float64:
And here's one where a rational coefficient gives all-rational output:
┆Issue is synchronized with this Trello card by Unito
The text was updated successfully, but these errors were encountered: