I'm confused with symbolic fractions

25 views
Skip to first unread message

Ricardo Fodra

unread,
Nov 26, 2021, 2:19:06 PM11/26/21
to sage-support
So I tried to do:

var('a b c')
f = 1/(a-b) + 2/(b-c) + 3/(c-a)
# get rid of the denominators
g = f*(a-b)*(b-c)*(c-a)
g.expand()

And I was hoping to get something like:

-a*b + a*c + b*c - c^2 - 2*a - 2*b - c

and instead I got:

-a^2*b/(a - b) + 3*a^2*b/(a - c) - 2*a^2*b/(b - c) + a*b^2/(a - b) - 3*a*b^2/(a - c) + 2*a*b^2/(b - c) + a^2*c/(a - b) - 3*a^2*c/(a - c) + 2*a^2*c/(b - c) - b^2*c/(a - b) + 3*b^2*c/(a - c) - 2*b^2*c/(b - c) - a*c^2/(a - b) + 3*a*c^2/(a - c) - 2*a*c^2/(b - c) + b*c^2/(a - b) - 3*b*c^2/(a - c) + 2*b*c^2/(b - c)

Are those equivalent? Am I doing something wrong?

Dima Pasechnik

unread,
Nov 26, 2021, 2:25:08 PM11/26/21
to sage-support
do the following:

sage: g.simplify_rational()
-2*a^2 + 4*a*b - 3*b^2 + 2*b*c - c^2

>
> --
> 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/5d5f136d-637b-4dd9-9c9b-eb00b7609401n%40googlegroups.com.

slelievre

unread,
Nov 26, 2021, 3:18:31 PM11/26/21
to sage-support
Or use polynomial variables rather than symbolic variables.

```
sage: R.<a, b, c> = PolynomialRing(QQ)
sage: f = 1/(a-b) + 2/(b-c) + 3/(c-a)
sage: f
(-2*a^2 + 4*a*b - 3*b^2 + 2*b*c - c^2)/(-a^2*b + a*b^2 + a^2*c - b^2*c - a*c^2 + b*c^2)
sage: g = f*(a-b)*(b-c)*(c-a)
sage: g
-2*a^2 + 4*a*b - 3*b^2 + 2*b*c - c^2
sage: f.numerator()
```

Emmanuel Charpentier

unread,
Nov 27, 2021, 8:15:57 AM11/27/21
to sage-support

Alternatives :

sage: var("a, b, c")
(a, b, c)
sage: f=1/(a-b)+2/(b-c)+3/(c-a)
sage: g=f*(a-b)*(b-c)*(c-a)
sage: f
1/(a - b) - 3/(a - c) + 2/(b - c)
sage: f.factor()
(2*a^2 - 4*a*b + 3*b^2 - 2*b*c + c^2)/((a - b)*(a - c)*(b - c))
sage: g
-(a - b)*(a - c)*(b - c)*(1/(a - b) - 3/(a - c) + 2/(b - c))
sage: g.expand()
-a^2*b/(a - b) + 3*a^2*b/(a - c) - 2*a^2*b/(b - c) + a*b^2/(a - b) - 3*a*b^2/(a - c) + 2*a*b^2/(b - c) + a^2*c/(a - b) - 3*a^2*c/(a - c) + 2*a^2*c/(b - c) - b^2*c/(a - b) + 3*b^2*c/(a - c) - 2*b^2*c/(b - c) - a*c^2/(a - b) + 3*a*c^2/(a - c) - 2*a*c^2/(b - c) + b*c^2/(a - b) - 3*b*c^2/(a - c) + 2*b*c^2/(b - c)
sage: g.expand().factor()
-2*a^2 + 4*a*b - 3*b^2 + 2*b*c - c^2

And, indeed :

sage: R1.<t, u, v>=QQ[]
sage: fp = FractionField(R1)(f.subs(dict(zip((a,b,c),(t,u,v))))).numerator() ; fp
2*t^2 - 4*t*u + 3*u^2 - 2*u*v + v^2
sage: SR(fp).subs(dict(zip((t,u,v), (a,b,c))))
2*a^2 - 4*a*b + 3*b^2 - 2*b*c + c^2

HTH,

Reply all
Reply to author
Forward
0 new messages