Skip to content

Instantly share code, notes, and snippets.

@antimatter15
Last active September 9, 2016 19:57
Show Gist options
  • Save antimatter15/221b18c596b066a5f2771411943ba9c1 to your computer and use it in GitHub Desktop.
Save antimatter15/221b18c596b066a5f2771411943ba9c1 to your computer and use it in GitHub Desktop.
Translate Mathematica expressions into Antimony's Prefix Notation
(* The f-rep syntax accepts four distinct types of atoms.X,Y,and Z \
are replaced by position in the world\[CloseCurlyQuote]s coordinate system at any \
given evaluation point. *)
Antimony[x] := "X"
Antimony[y] := "Y"
Antimony[z] := "Z"
(* Table A.1:Unary F-rep functions (pg. 93) *)
Antimony[Sin[x_]] := "s" <> Antimony[x]
Antimony[Cos[x_]] := "c" <> Antimony[x]
Antimony[Tan[x_]] := "t" <> Antimony[x]
Antimony[ArcSin[x_]] := "S" <> Antimony[x]
Antimony[ArcCos[x_]] := "C" <> Antimony[x]
Antimony[ArcTan[x_]] := "T" <> Antimony[x]
Antimony[Abs[x_]] := "b" <> Antimony[x]
Antimony[Power[x_, 2]] := "q" <> Antimony[x]
Antimony[Sqrt[x_]] := "r" <> Antimony[x]
Antimony[-x_] := "n" <> Antimony[x]
(* Floating point constants are preceded by f, followed by the value \
(e.g.f3.14159 or f6.023e23). *)
Antimony[x_Real] := "f" <> ToString[x]
Antimony[x_Integer] := "f" <> ToString[x]
(*Table A.2:Binary F-rep functions*)
Antimony[Times[a_, b__]] := "*" <> Antimony[a] <> Antimony[Times[b]]
Antimony[Plus[a_, b__]] := "+" <> Antimony[a] <> Antimony[Plus[b]]
Antimony[Power[x_, y_]] := "p" <> Antimony[x] <> Antimony[y]
Antimony[Plus[a__, -b_]] := "-" <> Antimony[Plus[a]] <> Antimony[b]
Antimony[Times[a_, Power[b_, -1]]] := "/" <> Antimony[a] <> Antimony[b]
Antimony[Max[a_, b__]] := "a" <> Antimony[a] <> Antimony[Max[b]]
Antimony[Min[a_, b__]] := "i" <> Antimony[a] <> Antimony[Min[b]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment