expand()

Christian Bauer cbauer at student.physik.uni-mainz.de
Tue Jun 26 17:24:32 CEST 2001


Hi!

On Tue, Jun 26, 2001 at 03:00:42PM +0200, Stefan Weinzierl wrote:
> You say, that all terms of a sum must be of the same type, so that would
> involve to define a unit element in the algebra called for example "ONE"
> and write
> 
>  ( ONE + A ) * B
> 
> instead.

This is how it is intended to be used (and also algebraically most correct).

> But in this case I would think it's better if
> 
>  ( 1 + A ) * B
> 
> throws an exception instead of just returning A*B.

Maybe add::eval() should throw an exception as soon as it encounters a
constant numeric term and a noncommutative object. This would be easy to
implement.

However, it gets worse when someone writes something like

  ( m + A ) * B  instead of  ( m*ONE + A ) * B

where "m" is a symbol. In this case you may get totally screwed results
because the "*" could end up being a _commutative_ product (this happens
if add::return_type() sees the "m" first). To track these kind of errors
would require the add class to check whether all terms really are of the
same commutativity class, which could cause a severe slowdown (and a
totally unnecessary one for people who only use commutative algebra).
So it would never be perfect...

Bye,
Christian

-- 
  / Coding on PowerPC and proud of it
\/ http://www.uni-mainz.de/~bauec002/



More information about the GiNaC-devel mailing list