
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ angle 180.0) (PI)))
(t_1 (cos t_0))
(t_2 (sin t_0))
(t_3
(/
(/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_2) t_1) x-scale)
y-scale))
(t_4
(/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) y-scale) y-scale))
(t_5
(/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) x-scale) x-scale)))
(*
180.0
(/
(atan
(/ (- (- t_4 t_5) (sqrt (+ (pow (- t_5 t_4) 2.0) (pow t_3 2.0)))) t_3))
(PI)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_2\right) \cdot t\_1}{x-scale}}{y-scale}\\
t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{y-scale}}{y-scale}\\
t_5 := \frac{\frac{{\left(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{x-scale}}{x-scale}\\
180 \cdot \frac{\tan^{-1} \left(\frac{\left(t\_4 - t\_5\right) - \sqrt{{\left(t\_5 - t\_4\right)}^{2} + {t\_3}^{2}}}{t\_3}\right)}{\mathsf{PI}\left(\right)}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ angle 180.0) (PI)))
(t_1 (cos t_0))
(t_2 (sin t_0))
(t_3
(/
(/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_2) t_1) x-scale)
y-scale))
(t_4
(/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) y-scale) y-scale))
(t_5
(/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) x-scale) x-scale)))
(*
180.0
(/
(atan
(/ (- (- t_4 t_5) (sqrt (+ (pow (- t_5 t_4) 2.0) (pow t_3 2.0)))) t_3))
(PI)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_2\right) \cdot t\_1}{x-scale}}{y-scale}\\
t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{y-scale}}{y-scale}\\
t_5 := \frac{\frac{{\left(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{x-scale}}{x-scale}\\
180 \cdot \frac{\tan^{-1} \left(\frac{\left(t\_4 - t\_5\right) - \sqrt{{\left(t\_5 - t\_4\right)}^{2} + {t\_3}^{2}}}{t\_3}\right)}{\mathsf{PI}\left(\right)}
\end{array}
\end{array}
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* angle (PI))) (t_1 (* 0.005555555555555556 t_0)))
(if (<= a_m 4.5e+29)
(*
180.0
(/
(atan
(*
(/
(*
-2.0
(/
(* y-scale (pow (cos (* -0.005555555555555556 t_0)) 2.0))
x-scale))
(*
(sin (* (* (PI) angle) 0.005555555555555556))
(cos (* -0.005555555555555556 (* (cbrt (pow (PI) 3.0)) angle)))))
0.5))
(PI)))
(*
180.0
(/
(atan (* -0.5 (* (/ y-scale x-scale) (* -2.0 (/ (sin t_1) (cos t_1))))))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := angle \cdot \mathsf{PI}\left(\right)\\
t_1 := 0.005555555555555556 \cdot t\_0\\
\mathbf{if}\;a\_m \leq 4.5 \cdot 10^{+29}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale \cdot {\cos \left(-0.005555555555555556 \cdot t\_0\right)}^{2}}{x-scale}}{\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot \cos \left(-0.005555555555555556 \cdot \left(\sqrt[3]{{\mathsf{PI}\left(\right)}^{3}} \cdot angle\right)\right)} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin t\_1}{\cos t\_1}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 4.5000000000000002e29Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites30.6%
Taylor expanded in x-scale around 0
Applied rewrites50.5%
Applied rewrites51.8%
if 4.5000000000000002e29 < a Initial program 7.5%
Taylor expanded in b around inf
Applied rewrites20.0%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites29.0%
Taylor expanded in a around inf
Applied rewrites56.6%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI)))))
(if (<= a_m 4.5e+29)
(*
180.0
(/
(atan
(*
(/
(* -2.0 (/ (* y-scale (pow 1.0 2.0)) x-scale))
(*
(sin (* (* (PI) angle) 0.005555555555555556))
(cos (* -0.005555555555555556 (* (cbrt (pow (PI) 3.0)) angle)))))
0.5))
(PI)))
(*
180.0
(/
(atan (* -0.5 (* (/ y-scale x-scale) (* -2.0 (/ (sin t_0) (cos t_0))))))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;a\_m \leq 4.5 \cdot 10^{+29}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale \cdot {1}^{2}}{x-scale}}{\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot \cos \left(-0.005555555555555556 \cdot \left(\sqrt[3]{{\mathsf{PI}\left(\right)}^{3}} \cdot angle\right)\right)} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin t\_0}{\cos t\_0}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 4.5000000000000002e29Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites30.6%
Taylor expanded in x-scale around 0
Applied rewrites50.5%
Applied rewrites51.8%
Taylor expanded in angle around 0
Applied rewrites51.3%
if 4.5000000000000002e29 < a Initial program 7.5%
Taylor expanded in b around inf
Applied rewrites20.0%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites29.0%
Taylor expanded in a around inf
Applied rewrites56.6%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI)))) (t_1 (* (PI) angle)))
(if (<= a_m 9.5e+30)
(*
180.0
(/
(atan
(*
(/
(*
-2.0
(/
(*
y-scale
(pow
(sin (+ (* t_1 (- -0.005555555555555556)) (/ (PI) 2.0)))
2.0))
x-scale))
(*
(sin (* t_1 0.005555555555555556))
(cos (* -0.005555555555555556 t_1))))
0.5))
(PI)))
(*
180.0
(/
(atan (* -0.5 (* (/ y-scale x-scale) (* -2.0 (/ (sin t_0) (cos t_0))))))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
t_1 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;a\_m \leq 9.5 \cdot 10^{+30}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale \cdot {\sin \left(t\_1 \cdot \left(--0.005555555555555556\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)}^{2}}{x-scale}}{\sin \left(t\_1 \cdot 0.005555555555555556\right) \cdot \cos \left(-0.005555555555555556 \cdot t\_1\right)} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin t\_0}{\cos t\_0}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 9.5000000000000003e30Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites30.6%
Taylor expanded in x-scale around 0
Applied rewrites50.5%
Applied rewrites50.5%
if 9.5000000000000003e30 < a Initial program 7.5%
Taylor expanded in b around inf
Applied rewrites20.0%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites29.0%
Taylor expanded in a around inf
Applied rewrites56.6%
Final simplification51.8%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI)))) (t_1 (* (PI) angle)))
(if (<= a_m 9.5e+30)
(*
180.0
(/
(atan
(*
(/
(*
-2.0
(/
(*
y-scale
(pow
(- (cos (fma (* -0.005555555555555556 angle) (PI) (PI))))
2.0))
x-scale))
(*
(sin (* t_1 0.005555555555555556))
(cos (* -0.005555555555555556 t_1))))
0.5))
(PI)))
(*
180.0
(/
(atan (* -0.5 (* (/ y-scale x-scale) (* -2.0 (/ (sin t_0) (cos t_0))))))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
t_1 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;a\_m \leq 9.5 \cdot 10^{+30}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale \cdot {\left(-\cos \left(\mathsf{fma}\left(-0.005555555555555556 \cdot angle, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right)\right)\right)}^{2}}{x-scale}}{\sin \left(t\_1 \cdot 0.005555555555555556\right) \cdot \cos \left(-0.005555555555555556 \cdot t\_1\right)} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin t\_0}{\cos t\_0}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 9.5000000000000003e30Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites30.6%
Taylor expanded in x-scale around 0
Applied rewrites50.5%
Applied rewrites50.5%
Applied rewrites50.5%
if 9.5000000000000003e30 < a Initial program 7.5%
Taylor expanded in b around inf
Applied rewrites20.0%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites29.0%
Taylor expanded in a around inf
Applied rewrites56.6%
Final simplification51.8%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI))))
(t_1 (cos t_0))
(t_2 (sin t_0)))
(if (<= a_m 9.5e+30)
(*
180.0
(/ (atan (* -0.5 (* (/ y-scale x-scale) (* 2.0 (/ t_1 t_2))))) (PI)))
(*
180.0
(/ (atan (* -0.5 (* (/ y-scale x-scale) (* -2.0 (/ t_2 t_1))))) (PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
\mathbf{if}\;a\_m \leq 9.5 \cdot 10^{+30}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(2 \cdot \frac{t\_1}{t\_2}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{t\_2}{t\_1}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 9.5000000000000003e30Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites30.6%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites30.1%
Taylor expanded in a around 0
Applied rewrites50.5%
if 9.5000000000000003e30 < a Initial program 7.5%
Taylor expanded in b around inf
Applied rewrites20.0%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites29.0%
Taylor expanded in a around inf
Applied rewrites56.6%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI)))))
(if (<= a_m 1.6e-112)
(*
180.0
(/ (atan (* (* -2.0 (/ y-scale (* angle (* x-scale (PI))))) 90.0)) (PI)))
(*
180.0
(/
(atan (* -0.5 (* (/ y-scale x-scale) (* -2.0 (/ (sin t_0) (cos t_0))))))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;a\_m \leq 1.6 \cdot 10^{-112}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin t\_0}{\cos t\_0}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 1.59999999999999997e-112Initial program 15.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.9%
Taylor expanded in a around inf
Applied rewrites12.3%
Taylor expanded in a around 0
Applied rewrites43.2%
if 1.59999999999999997e-112 < a Initial program 9.4%
Taylor expanded in b around inf
Applied rewrites22.0%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites29.7%
Taylor expanded in a around inf
Applied rewrites51.3%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= b 6.5e-162)
(*
180.0
(/
(atan
(/
(*
y-scale
(fma
-180.0
(/ (* b b) (* x-scale (* (PI) (* (+ a_m b) (- b a_m)))))
(*
0.5
(* (* angle angle) (* 0.011111111111111112 (/ (PI) x-scale))))))
angle))
(PI)))
(*
180.0
(/ (atan (* (* -2.0 (/ y-scale (* angle (* x-scale (PI))))) 90.0)) (PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.5 \cdot 10^{-162}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale \cdot \mathsf{fma}\left(-180, \frac{b \cdot b}{x-scale \cdot \left(\mathsf{PI}\left(\right) \cdot \left(\left(a\_m + b\right) \cdot \left(b - a\_m\right)\right)\right)}, 0.5 \cdot \left(\left(angle \cdot angle\right) \cdot \left(0.011111111111111112 \cdot \frac{\mathsf{PI}\left(\right)}{x-scale}\right)\right)\right)}{angle}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 6.49999999999999989e-162Initial program 10.3%
Taylor expanded in angle around 0
Applied rewrites1.3%
Taylor expanded in y-scale around inf
Applied rewrites16.6%
Taylor expanded in a around inf
Applied rewrites29.5%
if 6.49999999999999989e-162 < b Initial program 20.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites18.3%
Taylor expanded in a around inf
Applied rewrites15.1%
Taylor expanded in a around 0
Applied rewrites52.8%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (* -2.0 (/ y-scale (* angle (* x-scale (PI))))) 90.0)) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 13.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.0%
Taylor expanded in a around inf
Applied rewrites10.8%
Taylor expanded in a around 0
Applied rewrites40.8%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (* -2.0 (/ x-scale (* angle (* y-scale (PI))))) 90.0)) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \frac{x-scale}{angle \cdot \left(y-scale \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 13.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.0%
Taylor expanded in a around inf
Applied rewrites10.8%
Taylor expanded in a around inf
Applied rewrites10.8%
herbie shell --seed 2024332
(FPCore (a b angle x-scale y-scale)
:name "raw-angle from scale-rotated-ellipse"
:precision binary64
(* 180.0 (/ (atan (/ (- (- (/ (/ (+ (pow (* a (cos (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (sin (* (/ angle 180.0) (PI)))) 2.0)) y-scale) y-scale) (/ (/ (+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)) x-scale) x-scale)) (sqrt (+ (pow (- (/ (/ (+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)) x-scale) x-scale) (/ (/ (+ (pow (* a (cos (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (sin (* (/ angle 180.0) (PI)))) 2.0)) y-scale) y-scale)) 2.0) (pow (/ (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) (PI)))) (cos (* (/ angle 180.0) (PI)))) x-scale) y-scale) 2.0)))) (/ (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) (PI)))) (cos (* (/ angle 180.0) (PI)))) x-scale) y-scale))) (PI))))