@@ -213,22 +213,22 @@ function sparsehessian(O, vars::AbstractVector; simplify = true)
213
213
return H
214
214
end
215
215
216
- function toexpr (O:: Term )
217
- if isa (operation (O), Differential)
218
- return :(derivative ($ (toexpr (arguments (O)[1 ])),$ (toexpr (operation (O). x))))
219
- elseif isa (operation (O), Sym)
220
- isempty (arguments (O)) && return operation (O). name
221
- return Expr (:call , toexpr (operation (O)), toexpr .(arguments (O))... )
222
- end
223
- if operation (O) === (^ )
224
- if length (arguments (O)) > 1 && arguments (O)[2 ] isa Number && arguments (O)[2 ] < 0
225
- return Expr (:call , ^ , Expr (:call , inv, toexpr (arguments (O)[1 ])), - (arguments (O)[2 ]))
226
- end
227
- end
228
- return Expr (:call , operation (O), toexpr .(arguments (O))... )
216
+ function toexpr (O)
217
+ ! istree (O) && return s
218
+ if isa (operation (O), Differential)
219
+ return :(derivative ($ (toexpr (arguments (O)[1 ])),$ (toexpr (operation (O). x))))
220
+ elseif isa (operation (O), Sym)
221
+ isempty (arguments (O)) && return operation (O). name
222
+ return Expr (:call , toexpr (operation (O)), toexpr .(arguments (O))... )
223
+ end
224
+ if operation (O) === (^ )
225
+ if length (arguments (O)) > 1 && arguments (O)[2 ] isa Number && arguments (O)[2 ] < 0
226
+ return Expr (:call , ^ , Expr (:call , inv, toexpr (arguments (O)[1 ])), - (arguments (O)[2 ]))
227
+ end
228
+ end
229
+ return Expr (:call , operation (O), toexpr .(arguments (O))... )
229
230
end
230
231
toexpr (s:: Sym ) = nameof (s)
231
- toexpr (s) = s
232
232
233
233
function toexpr (eq:: Equation )
234
234
Expr (:(= ), toexpr (eq. lhs), toexpr (eq. rhs))
0 commit comments