@@ -96,23 +96,38 @@ Base.convert(::Type{Assignment}, p::Pair) = Assignment(pair[1], pair[2])
9696
9797toexpr (a:: Assignment , st) = :($ (toexpr (a. lhs, st)) = $ (toexpr (a. rhs, st)))
9898
99- function toexpr (O, st)
100- ! istree (O) && return O
101- op = operation (O )
99+ function_to_expr (op, args, st) = nothing
100+
101+ function function_to_expr ( :: typeof ( ^ ), O, st )
102102 args = arguments (O)
103- if op === ( ^ ) && length (args) == 2 && args[2 ] isa Number && args[2 ] < 0
103+ if length (args) == 2 && args[2 ] isa Number && args[2 ] < 0
104104 ex = args[1 ]
105105 if args[2 ] == - 1
106106 return toexpr (Term {Any} (inv, [ex]), st)
107107 else
108108 return toexpr (Term {Any} (^ , [Term {Any} (inv, [ex]), - args[2 ]]), st)
109109 end
110- elseif op === (SymbolicUtils. ifelse)
111- return :($ (toexpr (args[1 ], st)) ? $ (toexpr (args[2 ], st)) : $ (toexpr (args[3 ], st)))
112- elseif op isa Sym && haskey (st. symbolify, O)
113- return st. symbolify[O]
114110 end
115- return Expr (:call , toexpr (op, st), map (x-> toexpr (x, st), args)... )
111+ return nothing
112+ end
113+
114+ function function_to_expr (:: typeof (SymbolicUtils. ifelse), O, st)
115+ args = arguments (O)
116+ :($ (toexpr (args[1 ], st)) ? $ (toexpr (args[2 ], st)) : $ (toexpr (args[3 ], st)))
117+ end
118+
119+ function_to_expr (:: Sym , O, st) = get (st. symbolify, O, nothing )
120+
121+ function toexpr (O, st)
122+ ! istree (O) && return O
123+ op = operation (O)
124+ expr′ = function_to_expr (op, O, st)
125+ if expr′ != = nothing
126+ return expr′
127+ else
128+ args = arguments (O)
129+ return Expr (:call , toexpr (op, st), map (x-> toexpr (x, st), args)... )
130+ end
116131end
117132
118133# Call elements of vector arguments by their name.
0 commit comments