UnitMathHelper.frink

Download or view UnitMathHelper.frink in plain text format


/** This program demonstrates how to write a transformer that turns Frink
    expressions into something that you can cut-and-paste into Java code.

    Instead of UnitMath, you may change this to something like BigInteger or
    BigDecimal.

    At the moment, this doesn't turn Frink's square brackets into Java's
    parentheses, though.
*/


symbolicMode[true]

transformations UnitMath
{
   _a _b <-> UnitMath.multiply[_a, _b]
   
   _a + _b <-> UnitMath.add[_a, _b]
}

/*equations = parseToExpression["""
      [a = n1.a n2.a + n2.b n1.c,          // a
       b = n2.a n1.b + n2.b n1.d,          // b
       c = n1.a n2.c + n1.c n2.d,          // c
       d = n1.b n2.c + n1.d n2.d,          // d
       e = n1.a n2.e + n1.c n2.f + n1.e,   // e
       f = n1.b n2.e + n1.d n2.f + n1.f]   // f
"""]*/


equations = parseToExpression["""
      [xp = a x + c y + e,
       yp = b x + d y + f]
"""]

println[join[";\n",transformExpression[equations]]]


Download or view UnitMathHelper.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19970 days, 20 hours, 25 minutes ago.