Skip to content

Instantly share code, notes, and snippets.

@antimatter15
Last active September 9, 2016 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antimatter15/2586bc653c503ed30e31bff596563200 to your computer and use it in GitHub Desktop.
Save antimatter15/2586bc653c503ed30e31bff596563200 to your computer and use it in GitHub Desktop.
Mandelbrot Set for Antimony

Mandelbrot Set in Antimony

This is a little experiment in using CAD software with a functional representation for solids. I used Mathematica to construct a giant polynomial, and wrote a script which converts arbitrary Mathematica expressions into Antimony's prefix notation.

# Kevin Kwok 9/9/2016
import fab
import math
title('Mandelbrot')
fn = "+f-2r+q+Y*f2*+Y*f2*XY-+XqXqYq-+Xq-+XqXqYq+Y*f2*XY"
fn = "+f-2if10r+q+Y*f2*+Y*f2*+Y*f2*+Y*f2*+Y*f2*+Y*f2*+Y*f2*+Y*f2*+Y*f2*XY-+\
XqXqY-+Xq-+XqXqYq+Y*f2*XY-+Xq-+Xq-+XqXqYq+Y*f2*XYq+Y*f2*+Y*f2*XY-+\
XqXqY-+Xq-+Xq-+Xq-+XqXqYq+Y*f2*XYq+Y*f2*+Y*f2*XY-+XqXqYq+Y*f2*+Y*f2*+\
Y*f2*XY-+XqXqY-+Xq-+XqXqYq+Y*f2*XY-+Xq-+Xq-+Xq-+Xq-+XqXqYq+Y*f2*XYq+Y*\
f2*+Y*f2*XY-+XqXqYq+Y*f2*+Y*f2*+Y*f2*XY-+XqXqY-+Xq-+XqXqYq+Y*f2*XYq+Y*\
f2*+Y*f2*+Y*f2*+Y*f2*XY-+XqXqY-+Xq-+XqXqYq+Y*f2*XY-+Xq-+Xq-+XqXqYq+Y*\
f2*XYq+Y*f2*+Y*f2*XY-+XqXqY-+Xq-+Xq-+Xq-+Xq-+Xq-+XqXqYq+Y*f2*XYq+Y*f2*\
+Y*f2*XY-+XqXqYq+Y*f2*+Y*f2*+Y*f2*XY-+XqXqY-+Xq-+XqXqYq+Y*f2*XYq+Y*f2*\
+Y*f2*+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_]] := "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]]
Antimony[Min[10,
ComplexExpand[Abs[Nest[(#^2 + x + I y) &, x + I y, 9]]]] - 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment