naive question

53 views
Skip to first unread message

Fernando Gouvea

unread,
Mar 6, 2020, 8:44:10 AM3/6/20
to sage-support

OK, so I'm doing a computation and my result is something I called thirdroot. I'm trying to test whether it's equal to a particular expression. Can someone explain what is wrong here?

(s*t+1)^2/(s+t)^2
(s*t + 1)^2/(s + t)^2
factor(thirdroot+1)
(s*t + 1)^2/(s + t)^2
thirdroot+1-(s*t+1)^2/(s+t)^2
((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2) - (s*t + 1)^2/(s + t)^2 + 1
simplify(thirdroot+1-(s*t+1)^2/(s+t)^2)
((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2) - (s*t + 1)^2/(s + t)^2 + 1
expand(thirdroot+1-(s*t+1)^2/(s+t)^2)
-s^2/(s^2 + 2*s*t + t^2) - 2*s*t/(s^2 + 2*s*t + t^2) - t^2/(s^2 + 2*s*t + t^2) + 1

Seeing a 0 would make me happier...

Fernando

-- 
=============================================================
Fernando Q. Gouvea         http://www.colby.edu/~fqgouvea
Carter Professor of Mathematics
Dept. of Mathematics and Statistics
Colby College              
5836 Mayflower Hill        
Waterville, ME 04901       

When God is invisible behind the world, the contents of the world will
become new gods; when the symbols of transcendent religiosity are
banned, new symbols develop from the inner-worldly language of science
to take their place.
  -- Eric Voegelin

Dima Pasechnik

unread,
Mar 6, 2020, 8:58:46 AM3/6/20
to sage-support
On Fri, Mar 6, 2020 at 1:44 PM Fernando Gouvea <fqgo...@colby.edu> wrote:
>
> OK, so I'm doing a computation and my result is something I called thirdroot. I'm trying to test whether it's equal to a particular expression. Can someone explain what is wrong here?
>
> (s*t+1)^2/(s+t)^2
>
> (s*t + 1)^2/(s + t)^2
>
> factor(thirdroot+1)
>
> (s*t + 1)^2/(s + t)^2
>
> thirdroot+1-(s*t+1)^2/(s+t)^2
>
> ((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2) - (s*t + 1)^2/(s + t)^2 + 1
>
> simplify(thirdroot+1-(s*t+1)^2/(s+t)^2)
>
> ((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2) - (s*t + 1)^2/(s + t)^2 + 1
>
> expand(thirdroot+1-(s*t+1)^2/(s+t)^2)
>
> -s^2/(s^2 + 2*s*t + t^2) - 2*s*t/(s^2 + 2*s*t + t^2) - t^2/(s^2 + 2*s*t + t^2) + 1
>
> Seeing a 0 would make me happier...

If you work in a polynomial ring, it will work:

age: R.<s,t>=QQ[]
sage: f=-s^2/(s^2 + 2*s*t + t^2) - 2*s*t/(s^2 + 2*s*t + t^2) -
t^2/(s^2 + 2*s*t + t^2) + 1
sage: type(f)
<class 'sage.rings.fraction_field_element.FractionFieldElement'>
sage: f
0

>
> Fernando
>
> --
> =============================================================
> Fernando Q. Gouvea http://www.colby.edu/~fqgouvea
> Carter Professor of Mathematics
> Dept. of Mathematics and Statistics
> Colby College
> 5836 Mayflower Hill
> Waterville, ME 04901
>
> When God is invisible behind the world, the contents of the world will
> become new gods; when the symbols of transcendent religiosity are
> banned, new symbols develop from the inner-worldly language of science
> to take their place.
> -- Eric Voegelin
>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/3b48a9c3-c752-a0bf-9da8-f4359c53647d%40colby.edu.

Eric Gourgoulhon

unread,
Mar 7, 2020, 6:13:06 AM3/7/20
to sage-support
You should use simplify_full() instead of simplify():

sage: var('s t')
(s, t)
sage
: thirdroot = ((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2)
sage
: factor(thirdroot + 1)

(s*t + 1)^2/(s + t)^2

sage
: a = thirdroot + 1 - (s*t + 1)^2/(s+t)^2
sage
: a
((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2) - (s*t + 1)^2/(s + t)^2 + 1

sage
: a.simplify_full()
0




Simon King

unread,
Mar 7, 2020, 3:00:15 PM3/7/20
to sage-s...@googlegroups.com
On 2020-03-07, Eric Gourgoulhon <egourg...@gmail.com> wrote:
> You should use simplify_full() instead of simplify():

Or you should rather use *polynomials* instead of general symbolic
variables, provided of course that all your expressions are multivariate
rational functions (which is the case here):

> sage: var('s t')
> (s, t)

sage: R.<s,t> = QQ[]

> sage: thirdroot = ((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2)

sage: thirdroot = ((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2)

> sage: factor(thirdroot + 1)
> (s*t + 1)^2/(s + t)^2

sage: factor(thirdroot + 1)
(s + t)^-2 * (s*t + 1)^2

> sage: a = thirdroot + 1 - (s*t + 1)^2/(s+t)^2
> sage: a
> ((s^2 - 1)*t^2 - s^2 + 1)/(s^2 + 2*s*t + t^2) - (s*t + 1)^2/(s + t)^2 + 1
> sage: a.simplify_full()
> 0

sage: a = thirdroot + 1 - (s*t + 1)^2/(s+t)^2; a
0

That's because thirdroot is an element of the quotient field of a
polynomial ring, which does automatic simplifications (which in the
special context of polynomials is a lot easier than in the general
context of symbolic variables).

Best regards,
Simon

Fernando Q. Gouvea

unread,
Mar 9, 2020, 9:20:25 AM3/9/20
to sage-s...@googlegroups.com
Thanks. I was wondering why declaring the polynomial ring helped, but
this helps me understand.

Fernando
--
==================================================================
Fernando Q. Gouvea
Carter Professor of Mathematics
Colby College
Mayflower Hill 5836
Waterville, ME 04901
fqgo...@colby.edu http://www.colby.edu/~fqgouvea

Don't you feel more like you do now than you did when you came in?

Reply all
Reply to author
Forward
0 new messages