Would it be useful to add a 'format hint' field to the nodes?
Expressions would remain stored as they are now, but the formatters
could use the hints to adjust the form of the output.

For example, if a user enters sqrt(2), the hint for the Pow node would
indicate 'radical'.  If the user enters '2**(1/2)', the hint would
indicate 'exponentiate'.   The hint could also be changed later to
alter the output form.

If this is a reasonable approach, there are some other issues to
consider:
 1. What is a good way to represent the hints?
 2. How should hints be handled when nodes are combined, split, or
otherwise transformed?
 3. Is adding extra memory usage to the nodes a problem?


On Jun 8, 3:27 am, "Ondrej Certik" <[EMAIL PROTECTED]> wrote:
> On Sun, Jun 8, 2008 at 6:13 AM, Mark Dewing <[EMAIL PROTECTED]> wrote:
>
> > Several expression forms seem be reduced to a canonical form (both in
> > the representation and in the pretty printed output).  Examples:
> > 1. Factorial  vs. Gamma function
> > 2. Sqrt(radical) vs.  a**(1/2)
>
> > Is there any way to control what form is used?
>
> In the cases above -- currently no.
>
>
>
> > Another case, (i*j)**(1/2) is represented as i**(1/2)*j**(1/2).   Is
> > there some way to collect the bases under the sqrt ?
>
> Also no.
>
> Would any or all of the above be useful for you? If you look at the
> definition of sqrt:
>
> def sqrt(arg):
>     arg = sympify(arg)
>     return arg**S.Half
>
> so it has the advantage that things are simple. As to factorials and
> gamma, unfortunately currently have two implementations that I think
> should be merged to one (gamma) and then we could have something like:
>
> def factorial(arg):
>     arg = sympify(arg)
>     return gamma(arg+1)
>
> or something similar.
>
> However, I think it could be useful to tell sympy --- rewrite all
> gamma to factorials, or rewrite all a**(1/2) to Sqrt (note that we
> don't have any Sqrt class in SymPy, but we could introduce one).
>
> Maybe a solution would be to have "sqrt" and "factorial" the simple
> functions above, and Sqrt and Factorial to be classes for representing
> the sqrt and factorial (not automatically evaluating them to a**(1/2)
> and gamma) and then we could enhance the rewrite functions in SymPy to
> be able to convert between these. Anyone interested in implementing
> this?
>
> If you would like to give it a shot, I (and I am sure others too) will
> be at hand to help you with the patch.
>
> Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to