I'm not familiar with GEKKO. However, it should be possible to define
a lambdify printer to convert SymPy expressions to GEKKO expressions.
Basically you need to subclass sympy.printing.lambdarepr.LambdaPrinter
and define the relevant methods for the SymPy classes used in your
expressions. Judging from the example here
https://gekko.readthedocs.io/en/latest/quick_start.html, this
shouldn't be too difficult.
Here are some resources that should be helpful
Docs on printing:
http://docs.sympy.org/dev/modules/printing.html
Existing lambdify printers:
https://github.com/sympy/sympy/blob/master/sympy/printing/lambdarepr.py
and
https://github.com/sympy/sympy/blob/master/sympy/printing/python.py
Docs on how lambdify works:
https://github.com/sympy/sympy/pull/13485
You can also do this using only a modules dictionary in lambdify. That
is, lambdify prints an expression like sin(x + 1) as "sin(x + 1)", and
you can define what sin points to like lambdify(x, sin(x + 1), {'sin':
custom_sin}). See the docs in the above ummerged pull request for more
information on how this works. This only works for things that prints
as functions, as it basically is just a Python namespace replacement.
So if you need to do something special for things like addition,
you'll have to use a custom printer. A custom printer is also much
more maintainable, but it's more work to build up compared to a
namespace dictionary.
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
sympy+un...@googlegroups.com.
> To post to this group, send email to
sy...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/sympy.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/sympy/2c94ef4a-a15b-43cc-9939-64428e6bbfcb%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.