Hi Jerome,

On Mon, 8 Feb 2010 02:51:31 -0800 (PST)
Jerome Lacoste <[email protected]> wrote:

> Hi all,
> 
> We're trying to find a way to get sage to generate latex
> representation of numeric expressions without fully evaluating them.
> 
> For example this would allow us to do something like render 1+5 in
> latex as $1+5$ instead of 6.
> Can someone tell us if it's possible to achieve this goal ? Maybe by
> doing something like
> 
> var('a')
> var('b')
> sage_exp("a + b", locals={'a': 1, 'b': 5})
> 
> This may require adding new code.
> 
> I prefer to discuss design upfront. I am new to the project.
> I've been looking a bit at the sage.symbolic.expression class.
> 
> Pointers appreciated.

I have a patch which allows you to "hold" automatic evaluation of
most symbolic expressions. It doesn't work for addition and
multiplication yet though. This would let you do

sage: SR(1).add(1, hold=True)
1 + 1

or when we implement contexts

sage: with hold:
....:     t = SR(1) + 1; t # SR(1) is not necessary if we decide to
....:                      # make everything a symbolic expression
....:                      # in the hold context
....:
sage: t
1 + 1


Unfortunately, the library we use for the symbolics, pynac, has the
automatic evaluation of add and mul objects built into the class
constructors [1, 2]. Changing this behavior means adding a parameter to
the constructor to delay this evaluation/normalization. If you're only
going to use these expressions for printing, this should be enough.
However, if you compute with them further, there will be lots of subtle
problems, since basic assumptions about the data structure is violated. 

[1] http://pynac.sagemath.org/hg/file/9ff767fb0c18/ginac/add.cpp#l63
[2]
http://pynac.sagemath.org/hg/file/9ff767fb0c18/ginac/expairseq.cpp#l801

One can overcome this limitation by keeping a flag and performing the
auto evaluation when necessary. I haven't had time to implement this
yet. I would be glad to rebase my patch to the latest Sage version and
make it available so you can build on it, if you think it will be
helpful. I don't think I'll have the time to make the necessary changes
in pynac myself at least for the next 2 weeks.


Cheers,
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

Reply via email to