I have a mathematica program which performs some manipulation which I then want to continue in another language, as I already have some code written in it. Syntactically this language is very similar to InputForm
and so I wanted to try and build my own output form based upon InputForm
which would transform an expression into something understandable in this other language.
The type of transformations would be things like swapping square brackets with parentheses, and renaming of functions. That is, a mapping like:
Den[x]*Den[y]+Den[x]*Den[z] --> D(x)*D(y) + D(x)*D(z)
My naive attempts at doing something like this were to try and copy InputForm
into MyForm
and then try and apply various calls to Format, that is something like (just using the renaming in this example):
MyForm = InputForm;
Format[Den[x_], MyForm] := D[x];
But as MyForm is simply pointing towards InputForm, I have not managed to copy InputForm and so the Format calls to MyForm affect InputForm as well.
At time of writing I do not have a complete list of the kind of output style transformations I wish to apply, but I am not looking for a complete solution, just an idea of how to get started with my own version of InputForm
(without breaking the original).
Any ideas on how to proceed would be appreciated. Thanks!
Edit: eldo's answer has made me realise that there is a loophole in what I have written - All of my symbols/expressions already have StandardForm set up, and I don't want to break that either. That is, for example, I have:
Format[Den[x_], StandardForm] := 1/x^2;
In principle, this is why I'm looking to define a NEW output form, I don't want to get it tangled with any other that is already defined.