The Symbolism library overloads arithmetic operators. Although it is written in C #, I can use it from F #:
open Symbolism let x = new Symbol("x") let y = new Symbol("y") let z = new Symbol("z") printfn "%A" (2*x + 3 + 4*x + 5*y + z + 8*y)
output:
3 + 6 * x + 13 * y + z
However, it also overloads ^ for authority. This, of course, works poorly with F #.
As a step towards a workaround, I exported a group of methods for permissions:
printfn "%A" (Aux.Pow(x, 2) * x)
output:
x ^ 3
How can I overload ** instead of the Aux.Pow group of methods?
I can do something like this:
let ( ** ) (a: MathObject) (b: MathObject) = Aux.Pow(a, b)
And this works for MathObject values:
> x ** y * x;; val it : MathObject = x ^ (1 + y)
But Aux.Pow also overloaded for int :
public static MathObject Pow(MathObject a, MathObject b) { return new Power(a, b).Simplify(); } public static MathObject Pow(MathObject a, int b) { return a ^ new Integer(b); } public static MathObject Pow(int a, MathObject b) { return new Integer(a) ^ b; }
Any suggestions are welcome!