I'd like to delay evaluation of functions like gcd so that I can have users
enter an expression like gcd(a,b), where a and b will be replaced by
numbers. If I just enter gcd(a,b), it finds the gcd of the polynomials a
and b, which is one. Based on earlier feedback I receive here and by trial
and error, I came up with this method to delay evaluation, and I'm just
wondering if this is a reasonable way to do it. I can't say I really
understand the difference between subs and replace. I just messed around
until I found a method that worked.
For example, if a and b are eventually going to be 3 and 9, the following
seems to work correctly, giving 3. I'm using parse_expr, as the
expressions are entered in a web page.
In [170]: parse_expr('gcd(a,b)',local_dict={'gcd':
Function('gcd')}).subs([(Symbol('a'),3),(Symbol('b'),9)]).replace(Function('gcd'),gcd)
Out[170]: 3
Is this a reasonable approach? Or is there a better method?
Thanks,
Duane
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.