Calculus.jl
Calculus.jl copied to clipboard
Remove call to `eval` in `simplify`
I have some code where I want to use Calculus.jl to differentiate symbolic expressions inside a @generated
function. This currently does not work because after differentiating Calculus.jl calls simplify
, which in turn often ends up calling eval
. As of right now @generated
functions are not allowed to call eval.
I'm opening this issue to see if those who know the internals here better think it would be possible/feasible to remove the call to eval
inside simplify
?
ref: https://github.com/EconForge/Dolang/pull/31#issuecomment-307791343
I had exactly the same issue today. Looking in the symbolic.jl I saw that it was only used for doing arithmetics. Thus replaced eval
with a following code
if all(isnumber, ex.args[2:end]) && length(ex.args) > 1
### Doing numerical stuff!!!
################ A Patch Here #################
op = ex.args[1]
nums = ex.args[2:end]
if op==:+
return +(nums...)
elseif op==:-
return -(nums...)
elseif op==:/
return /(nums...)
elseif op==:*
return *(nums...)
else
error("Operation $op not implemented")
end
############# Replaces ######################
#return eval(current_module(), ex)
#############################################
end
which seems to work fine ;)