Skip to content

Commit

Permalink
attempt #2
Browse files Browse the repository at this point in the history
  • Loading branch information
n0rbed committed Mar 24, 2024
1 parent ef3aa92 commit 6df3e59
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/linear_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@ julia> Symbolics.solve_for([x + y ~ 0, x - y ~ 2], [x, y])
-1.0
```
"""
function solve_for(eq::AbstractArray, var::AbstractArray; simplify=false, check=true) # scalar case
function solve_for(eq, var; simplify=false, check=true) # scalar case
# simplify defaults for `false` as canonicalization should handle most of
# the cases.
a, b, islinear = linear_expansion(eq, var)
check && @assert islinear

for eqᵢ in eq
islinear &= Symbolics.isaffine(eqᵢ.lhs-eqᵢ.rhs, var)
if eq isa AbstractArray
for eqᵢ in eq
islinear &= Symbolics.isaffine(eqᵢ.lhs-eqᵢ.rhs, var)
end
else
islinear &= Symbolics.isaffine(eq.lhs-eq.rhs, [var])
end

if !islinear
Expand All @@ -123,7 +127,6 @@ function solve_for(eq::AbstractArray, var::AbstractArray; simplify=false, check=
end
solve_for(eq::Equation, var::T; x...) where {T<:AbstractArray} = solve_for([eq],var, x...)
solve_for(eq::T, var::Num; x...) where {T<:AbstractArray} = first(solve_for(eq,[var], x...))
solve_for(eq::Equation, var::Num; x...) = (solve_for([eq],[var], x...))

function _solve(A::AbstractMatrix, b::AbstractArray, do_simplify)
A = Num.(SymbolicUtils.quick_cancel.(A))
Expand Down

0 comments on commit 6df3e59

Please sign in to comment.