Skip to content

Commit

Permalink
Merge pull request #596 from JuliaSymbolics/myb/connect
Browse files Browse the repository at this point in the history
Move Connection to Symbolics
  • Loading branch information
YingboMa authored May 12, 2022
2 parents 80f8217 + aa9d97d commit 78fac4f
Show file tree
Hide file tree
Showing 2 changed files with 32 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 = "4.4.3"
version = "4.5.0"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
32 changes: 31 additions & 1 deletion src/equations.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
const NAMESPACE_SEPARATOR = ''

struct Connection
systems
end
Connection() = Connection(nothing)

function connect(sys1, sys2, syss...)
syss = (sys1, sys2, syss...)
length(unique(nameof, syss)) == length(syss) || error("connect takes distinct systems!")
Equation(Connection(), Connection(syss)) # the RHS are connected systems
end

function Base.show(io::IO, c::Connection)
print(io, "connect(")
n = length(c.systems)
for (i, s) in enumerate(c.systems)
str = join(split(string(nameof(s)), NAMESPACE_SEPARATOR), '.')
print(io, str)
i != n && print(io, ", ")
end
print(io, ")")
end

"""
$(TYPEDEF)
Expand All @@ -18,7 +42,13 @@ end
Base.:(==)(a::Equation, b::Equation) = all(isequal.((a.lhs, a.rhs), (b.lhs, b.rhs)))
Base.hash(a::Equation, salt::UInt) = hash(a.lhs, hash(a.rhs, salt))

Base.show(io::IO, eq::Equation) = print(io, eq.lhs, " ~ ", eq.rhs)
function Base.show(io::IO, eq::Equation)
if eq.lhs isa Connection
show(io, eq.rhs)
else
print(io, eq.lhs, " ~ ", eq.rhs)
end
end

scalarize(eq::Equation) = scalarize(eq.lhs) ~ scalarize(eq.rhs)
SymbolicUtils.simplify(x::Equation; kw...) = simplify(x.lhs; kw...) ~ simplify(x.rhs; kw...)
Expand Down

2 comments on commit 78fac4f

@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/60086

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 v4.5.0 -m "<description of version>" 78fac4f7533fe039e687acfaba255faeed30d36f
git push origin v4.5.0

Please sign in to comment.