Hi Valerio,

On 2017-08-27, [email protected] <[email protected]> wrote:
> L(a,x)=f(a)+sl(a)*(x-a)
>
> L(1,x)
> ValueError: power::eval(): division by zero

The above syntax, as innocent as it looks, implies a lot of things,
via Sage's preparser:

  sage: preparse("L(a,x) = f(a)+sl(a)*(x-a)")
  '__tmp__=var("a,x"); L = symbolic_expression(f(a)+sl(a)*(x-a)).function(a,x)'

So, what exactly is happening here? Two symbolic variables are
created, and a symbolic function is created, whose definition
on the *result* of evaluating f(a)+sl(a)*(x-a).

And since `a` is just a symbolic variable at that point, which evaluates
unequal to one, sl(a) returns a fraction:

  sage: L(a,x) = f(a)+sl(a)*(x-a)
  sage: L(a,x)
  a^2 - (a^2 - 1)*(a - x)/(a - 1)

Apparently, inserting a=1 results in a division by zero.

Solution: Instead of invoking Sage's preparser and using a symbolic
function, just create a Python function, either like this:
  sage: L = lambda a,x:f(a)+sl(a)*(x-a)
  sage: L(1,x)
  2*x - 1
or like this:
  sage: def L(a,x): return f(a)+sl(a)*(x-a)
  sage: L(1,x)
  2*x - 1

Best regards,
Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" 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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to