Disturbing Equality (from askSAGE)

78 views
Skip to first unread message

rickhg12hs

unread,
Jul 30, 2013, 10:29:43 AM7/30/13
to sage-s...@googlegroups.com
sage: var('a b')
(a, b)
sage
: assume(a, 'real')
sage
: assume(b, 'real')
sage
: bool( sqrt((a+b)^2) == sqrt(a^2) + sqrt(b^2) )
True
sage
:bool( (sqrt((a+b)^2) == sqrt(a^2) + sqrt(b^2)).subs(a=1,b=-1) )
False
sage
:

Why the strange equality?

JamesHDavenport

unread,
Jul 30, 2013, 1:40:29 PM7/30/13
to sage-s...@googlegroups.com
 Because square root is multivalued. Consider sqrt(1-z)*sqrt(1+z)=sqrt(1-z^2) and sqrt(z-1)*sqrt(z+1)=sqrt(z^2-1).
More academically, consider
Bradford,R.J. & Davenport,J.H.,
Towards Better Simplification of Elementary Functions.
Proc. ISSAC 2002 (ed. T. Mora), ACM Press, New York, 2002, pp. 15-22.
 

rickhg12hs

unread,
Jul 30, 2013, 1:45:07 PM7/30/13
to sage-s...@googlegroups.com
So you are saying the `True` Bool is the desired behavior? 

chris wuthrich

unread,
Jul 31, 2013, 3:57:25 AM7/31/13
to sage-s...@googlegroups.com
>  Because square root is multivalued.

Even so, I would  consider this to be wrong for

 a) I don't want my students to think it is true and

 b) the left hand side is two-valued while the right hand
     side is four-valued and hence they do not agree as
     multi-valued functions. (This objection does not cause
     a problem in your two examples.)

>  Consider sqrt(1-z)*sqrt(1+z)=sqrt(1-z^2) and sqrt(z-1)*sqrt(z+1)=sqrt(z^2-1)
 

JamesHDavenport

unread,
Aug 1, 2013, 1:08:21 AM8/1/13
to sage-s...@googlegroups.com
No - because sqrt is multivalued, the answer can be, and in this case is, multivalued: sometimes true and sometimes false. This isn't desperately helpful, or course, and can be cast in other ways in terms of the defect
Bradford,R.J.,
Algebraic Simplification of Multiple-Valued Functions.
Proc. DISCO '92 (Springer Lecture Notes in Computer Science 721, ed. J.P. Fitch), Springer, 1993, pp. 13-21.
or the unwinding number
Corless,R.M. & Jeffrey,D.J.,
The Unwinding Number.
SIGSAM Bulletin 30(1996) 2, pp. 28-35.

chris wuthrich

unread,
Aug 1, 2013, 6:10:27 AM8/1/13
to sage-s...@googlegroups.com


No - because sqrt is multivalued, the answer can be, and in this case is, multivalued: sometimes true and sometimes false. This isn't desperately helpful, or course, and can be cast in other ways in terms of the defect

If a boolean is "sometimes true and sometimes false" it is false and that is what I want sage to give back. Sage does not have "multi-valued booleans" I believe.


John Cremona

unread,
Aug 1, 2013, 7:11:06 AM8/1/13
to SAGE support
I mostly agree, but in the following:

sage: var('a b')
(a, b)
sage: bool(a==a)
True
sage: bool(a==a+1)
False
sage: bool(a==a*a)
False # bad? it is True for a=0,1
sage: bool(b*a==a*b)
True
sage: bool((a+b)^2==a^2+2*a*b+b^2)
True
sage: bool(sqrt(a)^2==a)
True #bad? is is False for all a<0

I don't like seeing True unless the expression is a tautology, i.e. an
identity, and I don't like seeing False unless it is always false (the
negation of a tautology. This is a different questions from the one
about branches of sqrt.

I try to avoid using symbolic expressions at all costs because of
things like this. After setting x = a==a+1 os that x has type
sage.symbolic.expression.Expression we have bool(x) is False, but I
don't know how bool(x) is evaluated. The documentation says that
bool(x) returns False because x is not always True, but
bool(x.negation()) is True even though x.negation() is 'a != a^2'
which is *not* always True. So that is surely a bug, anyway.

John

>
>
> --
> 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/groups/opt_out.
>
>

Georgi Guninski

unread,
Aug 1, 2013, 10:32:29 AM8/1/13
to sage-s...@googlegroups.com
probably this is the same:
(rhs - lhs).full_simplify()
returns zero for wrong stuff.

Georgi Guninski

unread,
Aug 1, 2013, 10:35:27 AM8/1/13
to sage-s...@googlegroups.com
On Thu, Aug 01, 2013 at 05:32:29PM +0300, Georgi Guninski wrote:
> probably this is the same:
> (rhs - lhs).full_simplify()
> returns zero for wrong stuff.
>
>

.full_simplify() appears better than bool:
sage: ex=a*a-a
sage: ex.full_simplify()
a^2 - a
sage: (sqrt(a)^2-a).full_simplify()
0

Reply all
Reply to author
Forward
0 new messages