Skip to content

Commit

Permalink
Merge pull request #66 from JuliaSymbolics/myb/solve_for
Browse files Browse the repository at this point in the history
Fix solve_for
  • Loading branch information
YingboMa authored Mar 1, 2021
2 parents d8ec558 + 0fe4aea commit 60cd6b8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Symbolics"
uuid = "0c5d862f-8b57-4792-8d23-62f2024744c7"
authors = ["Shashi Gowda <[email protected]>"]
version = "0.1.1"
version = "0.1.2"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Expand Down
3 changes: 3 additions & 0 deletions src/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Base.show(io::IO, eq::Equation) = print(io, eq.lhs, " ~ ", eq.rhs)

SymbolicUtils.simplify(x::Equation; kw...) = simplify(x.lhs; kw...) ~ simplify(x.rhs; kw...)

lhss(xs) = map(x->x.lhs, xs)
rhss(xs) = map(x->x.rhs, xs)

"""
$(TYPEDSIGNATURES)
Expand Down
3 changes: 2 additions & 1 deletion src/linear_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ w.r.t `vars`.
function solve_for(eqs, vars; simplify=true, check=true)
A, b = A_b(eqs, vars, check)
#TODO: we need to make sure that `solve_for(eqs, vars)` contains no `vars`
_solve(A, b, simplify)
sol = _solve(A, b, simplify)
sol isa AbstractArray ? map(Num, sol) : Num(sol)
end

function _solve(A::AbstractMatrix, b::AbstractArray, do_simplify)
Expand Down
9 changes: 9 additions & 0 deletions test/overloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,12 @@ z2 = c + d * im
@test real(a) === a
@test conj(a) === a
@test imag(a) === Num(0)

@variables x y z
eqs = [
2//1 * x + y - z ~ 2//1
2//1 + y - z ~ 3//1*x
2//1 + y - 2z ~ 3//1*z
]
@test [2 1 -1; -3 1 -1; 0 1 -5] * Symbolics.solve_for(eqs, [x, y, z]) == [2; -2; -2]
@test isequal(Symbolics.solve_for(2//1*x + y - 2//1*z ~ 9//1*x, 1//1*x), 1//7*y - 2//7*z)

2 comments on commit 60cd6b8

@YingboMa
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/31082

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 60cd6b8b4baa11beac0cd6e8f525469ac4bb667c
git push origin v0.1.2

Please sign in to comment.