
(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 8 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 (sin (* 0.005555555555555556 t_0)))
(t_2 (cbrt (PI))))
(if (<= a_m 2.7e-89)
(*
180.0
(/
(/
(atan
(/
(fma
(cos (fma (* angle 0.005555555555555556) (PI) (PI)))
y-scale
0.0)
(* x-scale t_1)))
(pow t_2 2.0))
t_2))
(if (<= a_m 8.5e+201)
(/
(*
(atan
(*
-0.5
(*
(* (/ y-scale x-scale) -2.0)
(tan (* t_0 0.005555555555555556)))))
180.0)
(PI))
(*
180.0
(/
(atan (* (* -2.0 (* (/ y-scale x-scale) (/ t_1 1.0))) -0.5))
(PI)))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := angle \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin \left(0.005555555555555556 \cdot t\_0\right)\\
t_2 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;a\_m \leq 2.7 \cdot 10^{-89}:\\
\;\;\;\;180 \cdot \frac{\frac{\tan^{-1} \left(\frac{\mathsf{fma}\left(\cos \left(\mathsf{fma}\left(angle \cdot 0.005555555555555556, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right)\right), y-scale, 0\right)}{x-scale \cdot t\_1}\right)}{{t\_2}^{2}}}{t\_2}\\
\mathbf{elif}\;a\_m \leq 8.5 \cdot 10^{+201}:\\
\;\;\;\;\frac{\tan^{-1} \left(-0.5 \cdot \left(\left(\frac{y-scale}{x-scale} \cdot -2\right) \cdot \tan \left(t\_0 \cdot 0.005555555555555556\right)\right)\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{t\_1}{1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 2.69999999999999988e-89Initial program 13.4%
Taylor expanded in x-scale around 0
Applied rewrites27.3%
Applied rewrites37.6%
Taylor expanded in b around inf
Applied rewrites45.2%
Applied rewrites45.0%
if 2.69999999999999988e-89 < a < 8.5e201Initial program 9.3%
Taylor expanded in x-scale around 0
Applied rewrites23.7%
Taylor expanded in a around inf
Applied rewrites58.3%
Applied rewrites56.1%
Applied rewrites58.4%
if 8.5e201 < a Initial program 0.0%
Taylor expanded in x-scale around 0
Applied rewrites0.0%
Taylor expanded in a around inf
Applied rewrites67.6%
Taylor expanded in angle around 0
Applied rewrites78.3%
Final simplification50.3%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* angle (PI))) (t_1 (* t_0 0.005555555555555556)))
(if (<= a_m 2.7e-89)
(*
180.0
(/
(atan (/ (fma (- y-scale) (cos t_1) 0.0) (* (sin t_1) x-scale)))
(PI)))
(if (<= a_m 8.5e+201)
(/
(* (atan (* -0.5 (* (* (/ y-scale x-scale) -2.0) (tan t_1)))) 180.0)
(PI))
(*
180.0
(/
(atan
(*
(*
-2.0
(* (/ y-scale x-scale) (/ (sin (* 0.005555555555555556 t_0)) 1.0)))
-0.5))
(PI)))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := angle \cdot \mathsf{PI}\left(\right)\\
t_1 := t\_0 \cdot 0.005555555555555556\\
\mathbf{if}\;a\_m \leq 2.7 \cdot 10^{-89}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\mathsf{fma}\left(-y-scale, \cos t\_1, 0\right)}{\sin t\_1 \cdot x-scale}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;a\_m \leq 8.5 \cdot 10^{+201}:\\
\;\;\;\;\frac{\tan^{-1} \left(-0.5 \cdot \left(\left(\frac{y-scale}{x-scale} \cdot -2\right) \cdot \tan t\_1\right)\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{\sin \left(0.005555555555555556 \cdot t\_0\right)}{1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 2.69999999999999988e-89Initial program 13.4%
Taylor expanded in x-scale around 0
Applied rewrites27.3%
Applied rewrites37.6%
Taylor expanded in b around inf
Applied rewrites45.2%
Applied rewrites45.8%
if 2.69999999999999988e-89 < a < 8.5e201Initial program 9.3%
Taylor expanded in x-scale around 0
Applied rewrites23.7%
Taylor expanded in a around inf
Applied rewrites58.3%
Applied rewrites56.1%
Applied rewrites58.4%
if 8.5e201 < a Initial program 0.0%
Taylor expanded in x-scale around 0
Applied rewrites0.0%
Taylor expanded in a around inf
Applied rewrites67.6%
Taylor expanded in angle around 0
Applied rewrites78.3%
Final simplification50.9%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* angle (PI))))
(if (<= a_m 1.6e-113)
(*
180.0
(/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI)))
(if (or (<= a_m 3.8e-45) (not (<= a_m 8.5e+201)))
(*
180.0
(/
(atan
(*
(*
-2.0
(* (/ y-scale x-scale) (/ (sin (* 0.005555555555555556 t_0)) 1.0)))
-0.5))
(PI)))
(/
(*
(atan
(*
-0.5
(*
(* (/ y-scale x-scale) -2.0)
(tan (* t_0 0.005555555555555556)))))
180.0)
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := angle \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;a\_m \leq 1.6 \cdot 10^{-113}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-180 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;a\_m \leq 3.8 \cdot 10^{-45} \lor \neg \left(a\_m \leq 8.5 \cdot 10^{+201}\right):\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{\sin \left(0.005555555555555556 \cdot t\_0\right)}{1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(-0.5 \cdot \left(\left(\frac{y-scale}{x-scale} \cdot -2\right) \cdot \tan \left(t\_0 \cdot 0.005555555555555556\right)\right)\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 1.6000000000000001e-113Initial program 13.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites13.6%
Taylor expanded in a around inf
Applied rewrites13.8%
Taylor expanded in a around 0
Applied rewrites41.7%
if 1.6000000000000001e-113 < a < 3.79999999999999997e-45 or 8.5e201 < a Initial program 8.1%
Taylor expanded in x-scale around 0
Applied rewrites16.1%
Taylor expanded in a around inf
Applied rewrites50.8%
Taylor expanded in angle around 0
Applied rewrites65.8%
if 3.79999999999999997e-45 < a < 8.5e201Initial program 8.6%
Taylor expanded in x-scale around 0
Applied rewrites25.9%
Taylor expanded in a around inf
Applied rewrites58.1%
Applied rewrites53.3%
Applied rewrites58.1%
Final simplification48.1%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 5e-91)
(* 180.0 (/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI)))
(/
(*
(atan
(*
-0.5
(*
(* (/ y-scale x-scale) -2.0)
(tan (* (* angle (PI)) 0.005555555555555556)))))
180.0)
(PI))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 5 \cdot 10^{-91}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-180 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(-0.5 \cdot \left(\left(\frac{y-scale}{x-scale} \cdot -2\right) \cdot \tan \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right)\right)\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 4.99999999999999997e-91Initial program 13.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites14.0%
Taylor expanded in a around inf
Applied rewrites13.7%
Taylor expanded in a around 0
Applied rewrites41.8%
if 4.99999999999999997e-91 < a Initial program 6.7%
Taylor expanded in x-scale around 0
Applied rewrites17.0%
Taylor expanded in a around inf
Applied rewrites61.0%
Applied rewrites60.7%
Applied rewrites61.0%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 5e-91)
(* 180.0 (/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI)))
(*
(/
(atan
(*
-0.5
(*
(* (/ y-scale x-scale) -2.0)
(tan (* (* angle (PI)) 0.005555555555555556)))))
(PI))
180.0)))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 5 \cdot 10^{-91}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-180 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(-0.5 \cdot \left(\left(\frac{y-scale}{x-scale} \cdot -2\right) \cdot \tan \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right)\right)\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if a < 4.99999999999999997e-91Initial program 13.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites14.0%
Taylor expanded in a around inf
Applied rewrites13.7%
Taylor expanded in a around 0
Applied rewrites41.8%
if 4.99999999999999997e-91 < a Initial program 6.7%
Taylor expanded in x-scale around 0
Applied rewrites17.0%
Taylor expanded in a around inf
Applied rewrites61.0%
Applied rewrites60.7%
Applied rewrites61.0%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= y-scale -2.85e+76)
(* 180.0 (/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI)))
(*
180.0
(/
(atan
(*
(*
(- x-scale)
(* 2.0 (/ y-scale (* angle (* (* x-scale x-scale) (PI))))))
90.0))
(PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;y-scale \leq -2.85 \cdot 10^{+76}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-180 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(\left(-x-scale\right) \cdot \left(2 \cdot \frac{y-scale}{angle \cdot \left(\left(x-scale \cdot x-scale\right) \cdot \mathsf{PI}\left(\right)\right)}\right)\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if y-scale < -2.85000000000000002e76Initial program 17.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites9.0%
Taylor expanded in a around inf
Applied rewrites9.5%
Taylor expanded in a around 0
Applied rewrites45.1%
if -2.85000000000000002e76 < y-scale Initial program 10.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.5%
Taylor expanded in x-scale around -inf
Applied rewrites13.8%
Taylor expanded in a around 0
Applied rewrites41.1%
Final simplification41.7%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(-180 \cdot \frac{y-scale}{angle \cdot \left(x-scale \cdot \mathsf{PI}\left(\right)\right)}\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 11.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.1%
Taylor expanded in a around inf
Applied rewrites11.3%
Taylor expanded in a around 0
Applied rewrites37.0%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* -180.0 (/ x-scale (* angle (* y-scale (PI)))))) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(-180 \cdot \frac{x-scale}{angle \cdot \left(y-scale \cdot \mathsf{PI}\left(\right)\right)}\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 11.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.1%
Taylor expanded in a around inf
Applied rewrites11.3%
Taylor expanded in a around inf
Applied rewrites11.3%
herbie shell --seed 2024354
(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))))