# [R] algebra

Franklin Parlamis fparlamis at mac.com
Thu Apr 6 21:09:42 CEST 2006

```hello all.  i have been trying to develop a representation (in the S4 sense) for a floating cash object, which would store a cash amount as a function of an arbitrary number of variables (with unknown values).  for example, an interest rate swap may call for a payment in one year that can be represented as a function of a 3-month libor rate to be determined in nine months.  this floating cash amount would be represented as, say, 250000*L (i am omitting some of the details leading to the scalar), where L is the unknown rate.  it will be necessary for addition and multiplication operations (among others) to make sense for the class.  i haven't found R to be particularly accommodating of this type of problem, in particular of the algebraic computations necessary to make addition and multiplication work.

my best thought so far was to have one slot in the representation be an expression object that would evaluate to a numeric cash object, if the evaluation were to take place in an environment where all the variables were ultimately bound to numerics (in the example above, expression(250000*L) would fill the slot).  this approach leads me to the following questions:

(i) does R have any native computer algebra functionality that would allow

> expression(250000*L) + expression(250000*M)

to evaluate to

 expression(250000*(L+M))

(ii) if not, does anyone have experience with integrating available computer algebra platforms (such as Mathomatic, which Gabor discussed in an earlier thread, but maybe not Mathomatic, because of its lack of natural log support) with R, i.e, passing expressions out for algebraic computations and then returning the result?  are there any packages available to provide APIs to any systems?  Any open source systems?

(iii) is there another way to handle all this other than algebraic manipulation of expressions?  even though i can't complete the thought, i keep picturing a massive n-dimensional array (if n is the total number of unknowns i am dealing with) that would somehow store scalars associated with all the possible combinations of variables?  does that thought have a future?  (please ignore this last question if i am not, as is often the case, making sense)

thanks in advance for any help.

franklin parlamis

```