[GiNaC-list] Checking consistency of units in GiNaC

Sheplyakov Alexei varg at theor.jinr.ru
Thu Jul 21 14:28:51 CEST 2005

On Thu, Jul 21, 2005 at 04:54:07PM +1000, John Pye wrote:

> I have some nice unit-checking code here as part of the freesteam project,
> http://pye.dyndns.org/freesteam/docs/class_units.html
> This class prevents things like "1 * bar + 3 * kg", and also ensures 
> validity of things like "Density rho = 5 * kg / (2 * metre2)"

It will work with _very_ simple expressions only, in particular,
it is impossible to check expression

pow(m1, 4-2*eps-2*j) - pow(m2, 2-2*j)*pow(p, 2-2*eps))

(where m1, m2, p have the same dimension) in this way.

> Does anyone have any comments on the advisability / feasibility of 
> trying to do this,

I don't think this code (or any other implementation playing with 
overloading of operator=, operator+, etc.) is suitable for GiNaC, since:

1) C++ compiler is unable[1] to do symbolic manipulations,
2) GiNaC overloads all these operators in its own way,
3) in some simple cases (say, polynomial or rational expressions) it 
is possible to do run-time checks in a far simpler way:

symbol M;
symbol L;
symbol a("a");
symbol b("b");

ex test = a*M/(b*pow(L,2));

Best regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20050721/e513b325/attachment.pgp

More information about the GiNaC-list mailing list