In what is now clearly a fool’s errand, I’m trying to copy and type out equations from publications, render them as LaTeX and then transform them into Julia code, with as little room for accidental errors as possible. (My modest progress towards this goal is on GitHub (Pluto.jl
notebook), which also contains some “motivation” as to “why”…)
I generate Julia-functions from Symbolics.jl
expressions. Using build_function
, I get a function that takes an array as argument, such that I have to remember the order of inputs. On the other hand, I can get a keyword-argument-function using SymbolicUtils.jl
’s utilities Func
and toexpr
. I have two questions:
-
Is it a good idea? E.g., how would you “plot an expression” such as
mx + b
(imagine it’s much more complicated) given, say,m=2.; b = 3.; x=range(<something>)
? Would you compile it to a function (I do that in my notebook)? Would you directly usesubstitute
a bunch of times? -
I’m trying to have variable names that match publications, which require superscripts, etc., and render in LaTeX correctly. This can (but shouldn’t? What do you think?) be done with a dirty hack:
@variables var"{x^{p}_{q}}"
. The problem is that this name is ugly to type ever again. One can assign (abbr = var"{x^{p}_{q}}"
) and continue to use an alias. However, when I generate a keyword argument function withFunc
andtoexpr
, I have to specify default values for all keyword arguments (I guess that’s not so bad?) and I have to call the keyword arguments with the “proper and non-customizable” variable names, in particular, I cannot use theabbr
alias. Is there a way to customize the keyword arguments ofFunc
? Do I have to manually change the AST output oftoexpr
?
Sorry if this question sounds like it should be more focused. My smaller technical problems almost certainly really stem from from a bad high-level approach to the bigger problem, which is how to work with Symbolics expressions?.