Skip to content

Commit 4e26a2d

Browse files
committed
Adjust interface, add sorted_* functions for arguments & children
1 parent 93a8f17 commit 4e26a2d

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/code.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ end
124124
function function_to_expr(op::Union{typeof(*),typeof(+)}, O, st)
125125
out = get(st.rewrites, O, nothing)
126126
out === nothing || return out
127-
args = map(Base.Fix2(toexpr, st), arguments(O; sort = true))
127+
args = map(Base.Fix2(toexpr, st), sorted_arguments(O))
128128
if length(args) >= 3 && symtype(O) <: Number
129129
x, xs = Iterators.peel(args)
130130
foldl(xs, init=x) do a, b

src/inspect.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ the expression.
3535
This function is used internally for printing via AbstractTrees.
3636
"""
3737
function AbstractTrees.children(x::Symbolic)
38-
iscall(x) ? arguments(x; sort = true) : isexpr(x) ? children(x; sort = true) : ()
38+
iscall(x) ? sorted_arguments(x) : isexpr(x) ? sorted_children(x) : ()
3939
end
4040

4141
"""

src/ordering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function get_degrees(expr)
2626
((Symbol(expr),) => 1,)
2727
elseif iscall(expr)
2828
op = operation(expr)
29-
args = arguments(expr; sort = true)
29+
args = sorted_arguments(expr)
3030
if op == (^) && args[2] isa Number
3131
return map(get_degrees(args[1])) do (base, pow)
3232
(base => pow * args[2])

src/polyform.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ end
187187
head(::PolyForm) = PolyForm
188188
operation(x::PolyForm) = MP.nterms(x.p) == 1 ? (*) : (+)
189189

190-
function arguments(x::PolyForm{T}; kwargs...) where {T}
190+
function arguments(x::PolyForm{T}) where {T}
191191

192192
function is_var(v)
193193
MP.nterms(v) == 1 &&
@@ -231,6 +231,9 @@ function arguments(x::PolyForm{T}; kwargs...) where {T}
231231
PolyForm{T}(t, x.pvar2sym, x.sym2term, nothing)) for t in ts]
232232
end
233233
end
234+
235+
sorted_arguments(x::PolyForm) = arguments(x)
236+
234237
children(x::PolyForm) = [operation(x); arguments(x)]
235238

236239
Base.show(io::IO, x::PolyForm) = show_term(io, x)

src/types.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,8 @@ end
116116

117117
@inline head(x::BasicSymbolic) = operation(x)
118118

119-
function arguments(x::BasicSymbolic; sort::Bool = false)
120-
args = unsorted_arguments(x)
121-
if !sort
122-
return args
123-
end
119+
function sorted_arguments(x::BasicSymbolic)
120+
args = arguments(x)
124121
@compactified x::BasicSymbolic begin
125122
Add => @goto ADD
126123
Mul => @goto MUL
@@ -141,9 +138,11 @@ function arguments(x::BasicSymbolic; sort::Bool = false)
141138
return args
142139
end
143140

144-
unsorted_arguments(x) = arguments(x)
145-
children(x::BasicSymbolic; kwargs...) = arguments(x; kwargs...)
146-
function unsorted_arguments(x::BasicSymbolic)
141+
children(x::BasicSymbolic) = arguments(x)
142+
143+
sorted_children(x::BasicSymbolic) = sorted_arguments(x)
144+
145+
function arguments(x::BasicSymbolic)
147146
@compactified x::BasicSymbolic begin
148147
Term => return x.arguments
149148
Add => @goto ADDMUL
@@ -812,7 +811,7 @@ function show_term(io::IO, t)
812811
end
813812

814813
f = operation(t)
815-
args = arguments(t; sort = true)
814+
args = sorted_arguments(t)
816815
if symtype(t) <: LiteralReal
817816
show_call(io, f, args)
818817
elseif f === (+)

0 commit comments

Comments
 (0)