Symbolics and Sage 4.0

12 views
Skip to first unread message

Mike Hansen

unread,
May 7, 2009, 7:10:30 AM5/7/09
to sage-devel
Hello all,

I've been doing a lot of work recent trying to get the new symbolics
ready for Sage 4.0. With 4.0 due out in 8 days, we're trying to do
the final push.

There are currently a lot of printing errors since Pynac/GiNaC prints
expressions differently than Maxima does. Some things still need
doctests, and there are a few small features left to implement. If
you have some free time in the next few days and want to help out,
it'd be greatly appreciated.

If you want to try the code out, there is an spkg and two patches in
http://sage.math.washington.edu/home/mhansen/symbolics/. These should
install and apply cleanly to Sage 3.4.2.

I'll try to be around in IRC most of the day tomorrow. Sometime during
the day or evening, we'll set up a public notebook for people to try
things out and try to break things.

--Mike

Jaap Spies

unread,
May 7, 2009, 10:16:04 AM5/7/09
to sage-...@googlegroups.com
Mike Hansen wrote:

Hi Mike
[...]


> If you want to try the code out, there is an spkg and two patches in
> http://sage.math.washington.edu/home/mhansen/symbolics/. These should
> install and apply cleanly to Sage 3.4.2.
>

I tried applying to sage-3.4.2, got:
[jaap@paix sage-3.4.2]$ ./sage
----------------------------------------------------------------------
| Sage Version 3.4.2, Release Date: 2009-05-04 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)

/home/jaap/downloads/sage-3.4.2/local/lib/python2.5/site-packages/IPython/ipmaker.pyc in force_import(modname)
64 reload(sys.modules[modname])
65 else:
---> 66 __import__(modname)
67
68

/home/jaap/downloads/sage-3.4.2/local/bin/ipy_profile_sage.py in <module>()
5 preparser(True)
6
----> 7 import sage.all_cmdline
8 sage.all_cmdline._init_cmdline(globals())
9

/home/jaap/downloads/sage-3.4.2/local/lib/python2.5/site-packages/sage/all_cmdline.py in <module>()
12 try:
13
---> 14 from sage.all import *
15 from sage.calculus.predefined import x
16 preparser(on=True)

/home/jaap/downloads/sage-3.4.2/local/lib/python2.5/site-packages/sage/all.py in <module>()
90 from sage.functions.all import *
91
---> 92 import sage.symbolic.pynac # This must come before Calculus -- it initializes the Pynac library.
93 from sage.calculus.all import *
94 from sage.server.all import *

ImportError: libpynac-0.1.so.2: cannot open shared object file: No such file or directory
Error importing ipy_profile_sage - perhaps you should run %upgrade?
WARNING: Loading of ipy_profile_sage failed.

What's wrong?

Jaap

mabshoff

unread,
May 7, 2009, 10:18:19 AM5/7/09
to sage-devel


On May 7, 7:16 am, Jaap Spies <j.sp...@hccnet.nl> wrote:
> Mike Hansen wrote:
>
> Hi Mike

<SNIP>

> ImportError: libpynac-0.1.so.2: cannot open shared object file: No such file or directory
> Error importing ipy_profile_sage - perhaps you should run %upgrade?
> WARNING: Loading of ipy_profile_sage failed.
>
> What's wrong?

(a) There are some known libtool problems. Please check the
pynac-1.1.6.spkg build for you.

or

(b) sage -b does not rebuild all the needed files since some of the
new extensions might not depend on the pynac header, but I haven't
read Mike's patch yet.

> Jaap

Cheers,

Michael

Burcin Erocal

unread,
May 7, 2009, 11:25:25 AM5/7/09
to sage-...@googlegroups.com
On Thu, 7 May 2009 04:10:30 -0700
Mike Hansen <mha...@gmail.com> wrote:

>
> Hello all,
>
> I've been doing a lot of work recent trying to get the new symbolics
> ready for Sage 4.0. With 4.0 due out in 8 days, we're trying to do
> the final push.

Thank you very much for working on this. I am really amazed to see how
you rebased all the pynac patches from William and me to version 1.4.3.

> There are currently a lot of printing errors since Pynac/GiNaC prints
> expressions differently than Maxima does. Some things still need
> doctests, and there are a few small features left to implement. If
> you have some free time in the next few days and want to help out,
> it'd be greatly appreciated.
>
> If you want to try the code out, there is an spkg and two patches in
> http://sage.math.washington.edu/home/mhansen/symbolics/. These should
> install and apply cleanly to Sage 3.4.2.

I guess the first patch is a collection of my patches sitting on trac,
so I didn't read it. Is this right?

Some minor comments after reading the 2nd patch:

* does new_Expression_from_GEx() really need the new parent parameter?

* how does the new _convert() function relate to the _eval_self() I
defined to handle numerical approximations?

* in the _factor_list() method, the line "if op is not None:" seems
superfluous

* in the initialization of SFunction, I had removed the find_function()
call, since you don't want to overwrite a previously user created
function which might be present in previously created expressions.
It seems that your patch adds it back.

* I don't think SFunction should have a .serial() method. It is useful
for debugging but it shouldn't be exposed to users.

* can we not use from sage.all import ... in function.pyx?

* why is SR.pi() necessary?

* the docstring for SR.var() is confusing, since you use it to create
multiple symbolic variables, and return expressions if the argument
is already an expression

* I don't see immediately why the printing functions are in the
parent, and not the elements. I.e., why is printing deferred to
SR._repr_element() and SR._latex_element()?


As I pointed out earlier on IRC, I don't think it's necessary to patch
pynac at all for the constant evaluation. You can just pass in any
python object which implements a .numerical_approx() method (the python
object for the constant itself?) to the constant constructor. This
would also remove the need for a lookup table for numerical
approximation of constants.


This is the first time I saw the default_variable() function in the previous symbolics code. I suggest that this is deprecated, and the functions that need this require explicitly stating variables. Maybe this discussion should take place in a different thread though, since it's independent of your patch.


Thanks again for your time and effort.


Cheers,
Burcin

Jason Grout

unread,
May 7, 2009, 12:05:04 PM5/7/09
to sage-...@googlegroups.com

I got a similar error, but a different traceback (ubuntu 9.04, 32 bit,
sage 3.4.2)

$ sage
----------------------------------------------------------------------
| Sage Version 3.4.2, Release Date: 2009-05-05 |


| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)

/home/jason/sage/local/lib/python2.5/site-packages/IPython/ipmaker.pyc
in force_import(modname)

/home/jason/sage/local/bin/ipy_profile_sage.py in <module>()


5 preparser(True)
6
----> 7 import sage.all_cmdline
8 sage.all_cmdline._init_cmdline(globals())
9

/home/jason/download/sage-3.4.1/local/lib/python2.5/site-packages/sage/all_cmdline.py
in <module>()

/home/jason/sage/local/lib/python2.5/site-packages/sage/all.py in <module>()
92 from sage.interfaces.all import *
93
---> 94 from sage.symbolic.all import *
95
96 from sage.functions.all import *

/home/jason/sage/local/lib/python2.5/site-packages/sage/symbolic/all.py
in <module>()
1
----> 2 from ring import SR, is_SymbolicExpressionRing, is_SymbolicVariable
3 from constants import (pi, e, NaN, golden_ratio, log2,
euler_gamma, catalan,
4 khinchin, twinprime, merten, brun, i, I)
5 from expression import Expression, is_Expression
6 from function import SFunction, PrimitiveFunction

ImportError: libpynac-0.1.so.2: cannot open shared object file: No such
file or directory
Error importing ipy_profile_sage - perhaps you should run %upgrade?
WARNING: Loading of ipy_profile_sage failed.


I have the following pynac spkgs installed:
~/sage/spkg/installed$ ls | grep pynac
pynac-0.1.3
pynac-0.1.6-mh


I can't seem to find the file it complains about, but I find similar
libraries:

~/sage$ find . -name libpynac-0.1.so.2
~/sage$ find . -name libpynac\*
./local/lib/libpynac.la
./local/lib/libpynac-0.1.so.5
./local/lib/libpynac-0.1.so.5.0.0
./local/lib/libpynac.so


The full log of everything I did and all the output from the
installation is here:

http://sage.pastebin.com/m29fd2be0

I'm looking forward to trying this!

Thanks,

Jason

William Stein

unread,
May 7, 2009, 12:51:41 PM5/7/09
to sage-...@googlegroups.com

Delete constants.so:

$ rm devel/sage/build/lib.macosx-10.3-i386-2.5/sage/symbolic/constants*
$ rm devel/sage/build/temp.macosx-10.3-i386-2.5/sage/symbolic/constants*
$ rm devel/sage/build/sage/symbolic/constants.so

Then

teragon:sage-3.4.2 wstein$ sage


----------------------------------------------------------------------
| Sage Version 3.4.2, Release Date: 2009-05-05 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: f = expand((sin(x)+cos(x^2))^3); f # no pause while
maxima starts
sin(x)^3 + 3*sin(x)^2*cos(x^2) + 3*sin(x)*cos(x^2)^2 + cos(x^2)^3
sage: type(f)
<type 'sage.symbolic.expression.Expression'>
sage:
Exiting SAGE (CPU time 0m0.10s, Wall time 0m5.37s). # no
maxima shutting down


-- William

William Stein

unread,
May 7, 2009, 1:16:43 PM5/7/09
to sage-...@googlegroups.com

I posted more complete step-by-step directions here:

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

I also installed a command system wide on sage.math so that typing
sage-symbolics will run a clean 3.4.2 Sage install that has the new
symbolics code built and working. So for those with accounts, just
login to sage.math.washington.edu and type "sage-symbolics". I'm also
currently updating http://alpha.sagenb.org, so it uses 3.4.2 + new
symbolics:

wstein@sage:~$ sage-symbolics


----------------------------------------------------------------------
| Sage Version 3.4.2, Release Date: 2009-05-04 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: type(x)
<type 'sage.symbolic.expression.Expression'>


-- William


--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Mike Hansen

unread,
May 7, 2009, 1:20:05 PM5/7/09
to sage-...@googlegroups.com
Hi Burcin,

On Thu, May 7, 2009 at 8:25 AM, Burcin Erocal <bur...@erocal.org> wrote:
> I guess the first patch is a collection of my patches sitting on trac,
> so I didn't read it. Is this right?

Yep.

> Some minor comments after reading the 2nd patch:
>
>  * does new_Expression_from_GEx() really need the new parent parameter?

Yes, since callable symbolic expressions which you get from doing
things like "f(x) = x^2" are just Expressions with different parents.
This avoids having two parallel classes that we have to keep in sync.
If you can think of a different solution, I'd be all for it.

>  * how does the new _convert() function relate to the _eval_self() I
>   defined to handle numerical approximations?

Actually, _convert() can be deleted, it's left over from before we had
_eval_self().

>  * in the _factor_list() method, the line "if op is not None:" seems
>   superfluous

Yep -- it was from the original _factor_list. I've taken care of this
in my tree which is at
/scratch/mhansen/sage-3.4.2.alpha0-sage.math-only-x86_64-Linux/devel/sage-symbolics

>  * in the initialization of SFunction, I had removed the find_function()
>   call, since you don't want to overwrite a previously user created
>   function which might be present in previously created expressions.
>   It seems that your patch adds it back.

We need this in order to have our sin function match up with the one
in GiNaC. There's a check that the end so that it only takes the
serial from find_function if it isn't a builtin function in GiNaC.

>  * I don't think SFunction should have a .serial() method. It is useful
>   for debugging but it shouldn't be exposed to users.

Fair enough -- it should be removed.

>  * can we not use from sage.all import ... in function.pyx?

Not at the top level. Things such as sin, cos, etc. all use function.pyx.

>  * why is SR.pi() necessary?

Compatibility with the old interface.

>  * the docstring for SR.var() is confusing, since you use it to create
>   multiple symbolic variables, and return expressions if the argument
>   is already an expression

We can fix this.

>  * I don't see immediately why the printing functions are in the
>   parent, and not the elements. I.e., why is printing deferred to
>   SR._repr_element() and SR._latex_element()?

This is for callable symbolic expressions.

> As I pointed out earlier on IRC, I don't think it's necessary to patch
> pynac at all for the constant evaluation. You can just pass in any
> python object which implements a .numerical_approx() method (the python
> object for the constant itself?) to the constant constructor. This
> would also remove the need for a lookup table for numerical
> approximation of constants.
>
>
> This is the first time I saw the default_variable() function in the previous symbolics code. I suggest that this is deprecated, and the functions that need this require explicitly stating variables. Maybe this discussion should take place in a different thread though, since it's independent of your patch.

I believe sin(x).derivative() breaks without it. Another thread would be good.

--Mike

Jaap Spies

unread,
May 7, 2009, 1:35:50 PM5/7/09
to sage-...@googlegroups.com
William Stein wrote:
[...]
>
> Delete constants.so:
>
> $ rm devel/sage/build/lib.macosx-10.3-i386-2.5/sage/symbolic/constants*
> $ rm devel/sage/build/temp.macosx-10.3-i386-2.5/sage/symbolic/constants*
> $ rm devel/sage/build/sage/symbolic/constants.so
>
> Then
>
> teragon:sage-3.4.2 wstein$ sage
> ----------------------------------------------------------------------
> | Sage Version 3.4.2, Release Date: 2009-05-05 |
> | Type notebook() for the GUI, and license() for information. |
> ----------------------------------------------------------------------
> sage: f = expand((sin(x)+cos(x^2))^3); f # no pause while
> maxima starts
> sin(x)^3 + 3*sin(x)^2*cos(x^2) + 3*sin(x)*cos(x^2)^2 + cos(x^2)^3
> sage: type(f)
> <type 'sage.symbolic.expression.Expression'>
> sage:
> Exiting SAGE (CPU time 0m0.10s, Wall time 0m5.37s). # no
> maxima shutting down
>

Works! Great.

Jaap


>
> -- William
>
> >
>

Robert Bradshaw

unread,
May 7, 2009, 6:25:51 PM5/7/09
to sage-...@googlegroups.com

I just noticed

sage: sqrt(x)^2
x

sage: sqrt(2)^2
sqrt(2)^2

- Robert

William Stein

unread,
May 7, 2009, 7:45:26 PM5/7/09
to sage-...@googlegroups.com

OK, that's definitely a bug. By the way, testing this in Ginac
directly is useful, which anybody can do by typing ginsh on sage.math:

wstein@sage:~$ ginsh
ginsh - GiNaC Interactive Shell (ginac V1.4.1)
...
> sqrt(2)^2;
2

I've added this to the wiki.

Jason Grout

unread,
May 7, 2009, 8:04:44 PM5/7/09
to sage-...@googlegroups.com


It might be useful, if possible, to make sage -ginsh launch ginsh, or
something similar.

Jason

mabshoff

unread,
May 7, 2009, 8:10:21 PM5/7/09
to sage-devel


On May 7, 5:04 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> William Stein wrote:

<SNIP>

> > wstein@sage:~$ ginsh
> > ginsh - GiNaC Interactive Shell (ginac V1.4.1)
> > ...
> >> sqrt(2)^2;
> > 2
>
> > I've added this to the wiki.
>
> It might be useful, if possible, to make sage -ginsh launch ginsh, or
> something similar.

Well, ginsh isn't available from inside Sage, i.e. pynac doesn't seem
to build it, so I would be -1 on this. And it is longer than typing
ginsh anyway.

> Jason

Cheers,

Michael

William Stein

unread,
May 7, 2009, 8:13:12 PM5/7/09
to sage-...@googlegroups.com

Michael's right, your suggestion turns out to make no sense, as it is
impossible to build ginsh without using the non-forked version of
ginac (!= pynac), and having the huge CLN library built, which we
don't use in Sage.


William

Robert Bradshaw

unread,
May 8, 2009, 3:56:43 AM5/8/09
to sage-...@googlegroups.com

Also

sage: sqrt(SR(16))
sqrt(16)
sage: 27^(1/3)
27^(1/3)

$ ginsh
> sqrt(16);
4
> 27 ^ (1/3);
3

I think this will solve 90% of the remaining errors outside the
symbolics directory.

- Robert

William Stein

unread,
May 8, 2009, 1:41:47 PM5/8/09
to sage-...@googlegroups.com
On Fri, May 8, 2009 at 12:56 AM, Robert Bradshaw

The little patch I posted to
http://trac.sagemath.org/sage_trac/ticket/5930
fixes

sage: sqrt(2)^2
2

However, still

sage: sqrt(SR(16))
sqrt(16)
sage: SR(16)^(1/2)
sqrt(16)


William

Robert Bradshaw

unread,
May 8, 2009, 2:52:55 PM5/8/09
to sage-...@googlegroups.com

I fixed that one too. What I couldn't figure out how to fix was

sage: sqrt(32)
sqrt(32) # rather than 4*sqrt(2), which isn't near as bad.

- Robert

Reply all
Reply to author
Forward
0 new messages