forked from SciML/ModelingToolkit.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequations.jl
42 lines (31 loc) · 884 Bytes
/
equations.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export Equation
"""
$(TYPEDEF)
An equality relationship between two expressions.
# Fields
$(FIELDS)
"""
struct Equation
"""The expression on the left hand side of the equation."""
lhs::Expression
"""The expression on the right hand side of the equation."""
rhs::Expression
end
Base.:(==)(a::Equation, b::Equation) = isequal((a.lhs, a.rhs), (b.lhs, b.rhs))
"""
$(TYPEDSIGNATURES)
Create an [`Equation`](@ref) out of two [`Expression`](@ref) instances, or an
`Expression` and a `Number`.
# Examples
```jldoctest
julia> using ModelingToolkit
julia> @variables x y;
julia> x ~ y
Equation(x(), y())
julia> x - y ~ 0
Equation(x() - y(), ModelingToolkit.Constant(0))
```
"""
Base.:~(lhs::Expression, rhs::Expression) = Equation(lhs, rhs)
Base.:~(lhs::Expression, rhs::Number ) = Equation(lhs, rhs)
Base.:~(lhs::Number , rhs::Expression) = Equation(lhs, rhs)