#rstats hivemind assistance request:
How to structure an #rstats program to change the algebraic properties of an arithmetic calculation independent of the structure of the calculation?
(I want this in #rstats because it's the only programming language in which I am non-negatively competent.)
I have some simple arithmetic calculations structured as data flow graphs like the one below (where each node corresponds to an algebraic operator). I want to investigate the effect of changing the algebraic properties of the operators (in this example, addition and multiplication) while keeping the structure of the calculation constant.
[EDIT] I may eventually want to vary the algebraic properties of the operators per node in the data flow graph. For example, addition may work differently at different nodes in the days flow graph.
This is analogous to having an #rstats arithmetic expression (e..g. a + b * c) and changing the types of the operands (e.g. int, double, complex). The structure of the arithmetic expression stays constant and the operators just "do the right thing" dependent on the type of the operands.
Obviously, I will have to program the operators. For the types of algebraic operators I am considering I am reasonably confident that I can get away with representing the operands as #rstats primitive numeric types (int, double, or complex). That is, I am not contemplating algebras where the operands have to be composite structures like graphs or matrices.
Also, I want all the operands to be *vectors* of values of the same type, so that vectorised arithmetic just works in the standard #rstats fashion.
I am presuming the idiomatic way to do this in #rstats would involve object-oriented programming with me writing methods for the operators and dispatching on the types of the operands.
Given a choice, I would prefer an approach that minimises the code I have to write and minimises the extent to which I have to turn my brain inside-out to comprehend what I am doing (because I am a mediocre programmer, at best).
The implementation doesn't have to be blazingly fast, but I can't afford it to be pitch-drop slow (https://en.wikipedia.org/wiki/Pitch_drop_experiment). A typical experiment will consist of a few thousand replicates of a recurrent calculation consisting of maybe 10 operations on vectors of 10,000 elements, carried out for 100 iterations.
So:
1) What #rstats programming approach would you suggest for solving this problem?
2) Is there an idiots' guide to something similar that I might be able to follow and adapt?
Thanks in advance.
#algebra #ObjectOriented