[GiNaC-list] Python bindings to GiNaC

Matti Peltomäki ppv at fyslab.hut.fi
Sun Jan 9 19:47:03 CET 2005


On Tue, 4 Jan 2005, Jonathan Brandmeyer wrote:

> So have I, and I have support for a larger number of classes including

I find this project of your pretty interesting. I played around with it a 
little bit (was able to build it just fine etc.). However, I stumbled into
a problem. 

I wanted to check out the use of lsolve() inspired by check/exam_lsolve.cpp
in GiNaC source tree. Namely, I try to solve 3*x+5==8 for x. Since both 
the equation and the answer are instances of relational, one has to access 
the rhs and lhs to extract the answer. Now, it seems that if another side 
of a relational is numeric, unwrap_ex() does not seem to be able to unwrap
it properly, throwing the exception "Could not unwrap an ex of unknown type."
This seems strange since unwrap_ex() throws this exception if the tinfo of the 
object does not match any one listed in ex.cpp (and TINFO_numeric is listed). 
This does not happen, if the numeric is a term in an add, for instance. 

Is this something that I do wrong or what is going on in the relational?

Below is a short example showing what I did and which errors I got. I run 
python as './run python2.3' in the root of pyginac source tree after having
succesfully built it with scons. 

Python 2.3.4 (#2, Dec  3 2004, 13:53:17) 
[GCC 3.3.5 (Debian 1:3.3.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ginac import *;
>>> x = symbol("x");
>>> eq = ( 3*x + 5 == 8);
>>> eq.rhs[1]
<cginac.numeric object at 0xb7dda4f4>
>>> print(eq.rhs[1])
>>> eq.lhs  
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
RuntimeError: Could not unwrap an ex of unknown type.
>>> answer = lsolve([eq], [x])
>>> answer
[<cginac.relational object at 0xb7e43e3c>]
>>> answer[0].rhs
<cginac.symbol object at 0xb7e3d8cc>
>>> print(answer[0].rhs)
>>> answer[0].lhs     
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
RuntimeError: Could not unwrap an ex of unknown type.

Best regards, 

Matti Peltomaki, Undergraduate Research Assistant
Laboratory of Physics 
Helsinki University of Technology

More information about the GiNaC-list mailing list