Ask Your Question

adeacondarkly's profile - activity

2022-05-24 19:18:40 +0200 received badge  Notable Question (source)
2021-05-30 10:00:24 +0200 received badge  Popular Question (source)
2019-06-06 10:04:01 +0200 received badge  Student (source)
2019-06-05 21:19:55 +0200 asked a question Can I convert a Sage symbolic expression into a callable Python function?

Hi, and thanks ahead of time for the help! I haven't had any luck finding an answer to this so far, and I'm still fairly new to Sage (and honestly, code-work in general).

I've been working on a (probably for most) small project of determining coefficient functions by use of a taylor expansion and solving a linear system. Basically, I have one polynomial with unknown coefficient functions f_2, f_3, f_4, ..., expand it with a taylor series and then match the expansion to another, known polynomial function. Then, I am solving this system for f_2, f_3, f_4, etc.

I've got this all figured out for the most part since, but my research adviser wants these functions (once solved) to be output as a callable python function. Basically, once the Sage script finds the functions, the goal is to have a defined python function that can either be copy/pasted into another script for use (at the least), or for them to be output into their own type of package file that can then be imported into a python script for use.

Like, as an example, "f_2=2n_b+L*K" gets converted into a python function f_2(n_b, L, K) so the end-user doesn't have to rebuild f_2 from scratch in their python script.

I was thinking I might be able to spend a day or two grinding them out in a manual sense with print() commands, but was wondering if there is a better/good/any way to actually do this.