Exact solution of linear system with Symbolics

How can I get an exact solution to a linear system using Symbolics.jl? For example:

@variables x y
Symbolics.solve_for([x + y ~ 2,
                     x - y ~ 1],
                    [x, y])

# Result:
2-element Vector{Float64}:
 1.5
 0.5

I would expect fractions 3/2 and 1/2.

For comparison, with SymPy.jl I get

@vars x y
solve([x + y ⩵ 2,
       x - y ⩵ 1])

# Result:
Dict{Any, Any} with 2 entries:
  y => 1/2
  x => 3/2

yeah open an issue. If you make that 2//1 and 1//1 does it come out rational?

1 Like

In that particular case it makes no difference, but in other cases using rational literals indeed gives rational outputs. Sometimes I also get a mix of both. See details in this issue.

1 Like