simplification of expressions

0 views
Skip to first unread message

Jason Grout

unread,
Oct 29, 2009, 11:23:26 PM10/29/09
to sage-...@googlegroups.com
I'm working with someone in a college algebra. They were temporarily
confused when they typed:

2/(x+2)

and the worksheet printed back out (in Typeset mode) the equivalent of:

2 (1/(x+2))

Is there a reason the 2 was pulled off the top of the fraction? Does it
have to be?

I know it's silly, but looking at these things is what will help Sage be
more user-friendly to students in algebra.

Thanks,

Jason

--
Jason Grout

kcrisman

unread,
Oct 30, 2009, 10:21:45 AM10/30/09
to sage-devel


On Oct 29, 11:23 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> I'm working with someone in a college algebra.  They were temporarily
> confused when they typed:
>
> 2/(x+2)
>
> and the worksheet printed back out (in Typeset mode) the equivalent of:
>
> 2 (1/(x+2))
>
> Is there a reason the 2 was pulled off the top of the fraction?  Does it
> have to be?

Looks like a Pynac thing. Check out
sage: a=2/(x+2)
sage: a.operands()
sage: a.operands()[0].operands()
sage: a.operands()[0].operator()
So Pynac treats fractions fundamentally as negative powers, not as
division.
sage: b = 2*(x+2)^-1
sage: bool(b==a)
True
Here you would want the typesetting to have the 2 out front, right?

This doesn't suggest a solution, just diagnoses the issue. I'm not
sure whether there would be a consistent way to do this. Note,
however, that
sage: latex(1/(2*(x+2)))
also pulls the 2 out, so you get 1/2 "out front".

- kcrisman

Burcin Erocal

unread,
Oct 31, 2009, 7:15:48 AM10/31/09
to sage-...@googlegroups.com
On Fri, 30 Oct 2009 07:21:45 -0700 (PDT)
kcrisman <kcri...@gmail.com> wrote:

> On Oct 29, 11:23 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> > I'm working with someone in a college algebra.  They were
> > temporarily confused when they typed:
> >
> > 2/(x+2)
> >
> > and the worksheet printed back out (in Typeset mode) the equivalent
> > of:
> >
> > 2 (1/(x+2))
> >
> > Is there a reason the 2 was pulled off the top of the fraction?
> >  Does it have to be?
>
> Looks like a Pynac thing. Check out

<snip code segment looking at the representation of the expression>

Yes, this is implemented in Pynac.

> So Pynac treats fractions fundamentally as negative powers, not as
> division.

Here is a link to the GiNaC tutorial explaining the data
representation:

http://www.ginac.de/tutorial/Internal-representation-of-products-and-sums.html

As a summary, products and sums are represented as vectors of tuples,
and a numeric coefficient. For products, the tuples encode a base and
an exponent.

When printing products, we print the numeric coefficient first. Then
separate the elements in the vector to a numerator and denominator part
according to their exponents and print these parts in order.

Here is the code:

http://pynac.sagemath.org/hg/file/e569b1a9a6a5/ginac/mul.cpp#l230

> sage: b = 2*(x+2)^-1
> sage: bool(b==a)
> True
> Here you would want the typesetting to have the 2 out front, right?


> This doesn't suggest a solution, just diagnoses the issue. I'm not
> sure whether there would be a consistent way to do this. Note,
> however, that
> sage: latex(1/(2*(x+2)))
> also pulls the 2 out, so you get 1/2 "out front".

One way to get the representation Jason wants is to ask for the
numerator and denominator of the numeric coefficient, and set these to
be the coefficients of the mul objects created when separating the
vector into a numerator and denominator.

I will try this when I find time and see how it works. Feel free to
open a ticket so I don't forget. :)


Thanks.

Burcin

Jason Grout

unread,
Oct 31, 2009, 10:45:17 AM10/31/09
to sage-...@googlegroups.com
Burcin Erocal wrote:

> I will try this when I find time and see how it works. Feel free to
> open a ticket so I don't forget. :)
>


Okay:

http://trac.sagemath.org/sage_trac/ticket/7363


--
Jason Grout

Reply all
Reply to author
Forward
0 new messages