Checking consistency of units in GiNaC
Hi all, Has anyone tried to add *units-of-measurement checking* to GiNaC? 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)" This units class could conceivably be extended to pass through expressions rather than simple numerical results, but operations like differentiation might need to become units-savvy I suspect. Does anyone have any comments on the advisability / feasibility of trying to do this, or have any references I should follow up relating to other people attempting this? Cheers JP -- John Pye School of Mechanical and Manufacturing Engineering The University of New South Wales Sydney NSW 2052 Australia t +61 2 9385 5127 f +61 2 9663 1222 mailto:john.pye_AT_student_DOT_unsw.edu.au http://pye.dyndns.org/
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)); assert(test.coeff(M)==1); assert(test.coeff(L)==-2); Best regards, Alexei
participants (2)
-
John Pye
-
varg@theor.jinr.ru