On Fri, 30 Oct 2009 07:21:45 -0700 (PDT) kcrisman <[email protected]> wrote:
> On Oct 29, 11:23 pm, Jason Grout <[email protected]> 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 --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to [email protected] To unsubscribe from this group, send an email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
