Mathematically naive (and incorrect) output

61 views
Skip to first unread message

Jesús Torrado

unread,
Jul 21, 2014, 9:16:08 AM7/21/14
to sage-s...@googlegroups.com
Hi guys,

This is so simple that probably someone else has already noticed it, but just in case:

    sage: x,t = var('x,t')
    sage: f = (1-x)/(1-x*cos(t))
    sage: f(x=1)
    0
    sage: f(t=0)(x=1)
    1

The second one is, of course, the correct answer. (FYI, Mathematica9 fails, too.)

Wouldn't the first one return some sort of conditional expression: "if t=0 then 1, else 0"

I would be happy to help in the debugging, if I can get some indication of what is running in the background, i.e. what function is called when one does the substitution "f(x=1)".

Cheers,
Jesús Torrado

kcrisman

unread,
Jul 21, 2014, 10:14:09 AM7/21/14
to sage-s...@googlegroups.com
Hi guys,

This is so simple that probably someone else has already noticed it, but just in case:

    sage: x,t = var('x,t')
    sage: f = (1-x)/(1-x*cos(t))
    sage: f(x=1)
    0
    sage: f(t=0)(x=1)
    1


My guess is that this is more of a convention than anything else.

sage: x/x
1
sage: 0/x
0

Maxima:
(%i1) x/x;
(%o1)                                  1
(%i2) 0/x;
(%o2)                                  0

If Mma and Maple do it too, that would be my guess.  In any case, it is 'known' and I bet you'll find other examples with a search of the email lists (though searching for x/x might be hard!).  It's possible to not immediately do such reductions

sage: x.mul(1/x,hold=True)
x/x

but I'm not sure how to combine that with the substitution that you are doing.

- kcrisman

Jesús TC

unread,
Jul 21, 2014, 10:42:30 AM7/21/14
to sage-s...@googlegroups.com
Thanks for the answer, kcrisman!

> My guess is that this is more of a convention than anything else.
> [...]
> sage: 0/x
> 0
> If Mma and Maple do it too, that would be my guess. In any case, it is
> 'known' and I bet you'll find other examples with a search of the email
> lists (though searching for x/x might be hard!).

Mathematica does indeed the same for "0/x". It may be a convention, so
I guess there is no room to freak out because "it's just wrong!".

But it makes me sad, since I will not be able to avoid a feeling of
insecurity when substituting variables that I didn't have before :(

Isn't there a way to answer with an "undetermined" in those cases?

Best,
Jesús

John Cremona

unread,
Jul 21, 2014, 10:44:39 AM7/21/14
to SAGE support
The expression y = (1-x)/(1-x*cos(t)) is, as given, undefined whenever
x*cos(t)=1, for example at (x,t)=(1,0).

When x=1 it simplifies to 0/(1-cos(t)), which equals 0 except where
cos(t)=1 where it is undefined but has a limiting value of 0.

When t=0 it simplfies to (1-x)/(1-x), which equals 1 except when x=1
where it is undefined, but has a limiting value of 1.

So you get different limits when first x -> 1 and then t->0 compared
with first t->0 and then x->1. The function has no continuous
extension to (x,t)=(1,0). Hence I would not expect a computer algebra
system to give the same answers with simple substitutions in the two
orders.
> --
> 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 sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.

Jesús TC

unread,
Aug 1, 2014, 5:20:11 PM8/1/14
to sage-s...@googlegroups.com
Thanks a lot, John! (and sorry for the delay in answering)

I see the point: it is simply undefined.

But I do not quite agree with you in that "[one] would not expect a
computer algebra system to give the same answers with simple
substitutions in the two orders": ideally, I would expect that the
answer to substituting x=1 is something like "undefined", since it is
so. But I don't know if that is possible in Sage right now.

Cheers,
Jesús
> You received this message because you are subscribed to a topic in the Google Groups "sage-support" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-support/Gxaui0CAzCM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to sage-support...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages