[GiNaC-list] Python wrapper for a GiNaC derived library
ondrej at certik.cz
Thu Aug 3 20:30:29 CEST 2006
> Yes, that would be easiest. However, I'm a bit afraid that it will not
> really work in C++. A power is a thing that has a basis and and exponent.
> So, I suppose these would need to be stored in basic. If power(a+b, 2)
> actually returns an object of type "power" it would get stripped of its
> non-basic members by the construction that you give.
I think it wouldn't. power(a+b,2) would return an instance of a class
power. power is however a subclass of basic. so in all the other
methods and functions, you would accept "basic"s only. Let's say:
series(basic &e, basic&x). if you need to access the power specific
methods, you need to retype the basic &e, to a power (if it is a power
I used this concept in my cas in python (in python you actually don't
have to retype the classes at all, you just call the method):
so I think it is the easiest and the simplest way how to do that. I am
not sure however, if this is the fastest.
> I sometimes wonder if it wouldn't be better if functions (not
> constructors) were used to construct our objects. Then there would be a
> function ex power(basis, exponent) and a class that would have to be
> called differently, say power_class. The function could dynamically
> allocate the object of type power_class. With this idea it would no longer
> be necessary to duplicate objects from stack to heap as is done now. This
> is not simpler, but I suppose it is more efficient. Maybe some
> cleverly-chosen macros could make it easier. Well, maybe it is simpler
> because the user will only see less objects derived from basic and only
> exes instead.
I don't know - I find it complicated. I am using just constructors of
the particular classes to construct objects. Like this:
mul(add(a,pow(b,c)),d) gives (a+b^c)*d
where mul,add,pow are classes. plus I of course overloaded the
operators *,/,+,- in the class basic, so you can actually write:
(a+b**c)*d, but this is just syntactic sugar for
so I don't need any extra functions, any extra macros, nothing. At
least to me, this looks simple.
When you created ginac, at around 2001, how much time did you spend
coding, to achieve the basic functionality? Couple of weeks? Or
months/years? And how many people - 4?
More information about the GiNaC-list