
(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 11 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}
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
(FPCore (a_m b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) angle)))
(if (<= b_m 6.8e-35)
(*
180.0
(/
(atan
(*
(/
(*
(* (* -2.0 (/ b_m (* x-scale x-scale))) (/ y-scale (- b_m a_m)))
x-scale)
t_0)
90.0))
(PI)))
(/
(*
(atan
(*
0.5
(/
(*
(pow (cos (* t_0 -0.005555555555555556)) 2.0)
(/ (* -2.0 y-scale) x-scale))
(*
(sin (fma t_0 -0.005555555555555556 (/ (PI) 2.0)))
(sin (* t_0 0.005555555555555556))))))
180.0)
(PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;b\_m \leq 6.8 \cdot 10^{-35}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(\left(-2 \cdot \frac{b\_m}{x-scale \cdot x-scale}\right) \cdot \frac{y-scale}{b\_m - a\_m}\right) \cdot x-scale}{t\_0} \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{{\cos \left(t\_0 \cdot -0.005555555555555556\right)}^{2} \cdot \frac{-2 \cdot y-scale}{x-scale}}{\sin \left(\mathsf{fma}\left(t\_0, -0.005555555555555556, \frac{\mathsf{PI}\left(\right)}{2}\right)\right) \cdot \sin \left(t\_0 \cdot 0.005555555555555556\right)}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 6.8000000000000005e-35Initial program 7.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites8.2%
Applied rewrites22.7%
Taylor expanded in a around 0
Applied rewrites39.7%
if 6.8000000000000005e-35 < b Initial program 12.4%
Taylor expanded in b around inf
Applied rewrites35.3%
Taylor expanded in x-scale around 0
Applied rewrites62.8%
Applied rewrites62.8%
Applied rewrites67.3%
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
(FPCore (a_m b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) angle)) (t_1 (cos (* t_0 -0.005555555555555556))))
(if (<= b_m 2.15e-44)
(*
180.0
(/
(atan
(*
(/
(*
(* (* -2.0 (/ b_m (* x-scale x-scale))) (/ y-scale (- b_m a_m)))
x-scale)
t_0)
90.0))
(PI)))
(/
(*
(atan
(*
0.5
(/
(* (pow t_1 2.0) (/ (* -2.0 y-scale) x-scale))
(* t_1 (sin (* t_0 0.005555555555555556))))))
180.0)
(PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
t_1 := \cos \left(t\_0 \cdot -0.005555555555555556\right)\\
\mathbf{if}\;b\_m \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(\left(-2 \cdot \frac{b\_m}{x-scale \cdot x-scale}\right) \cdot \frac{y-scale}{b\_m - a\_m}\right) \cdot x-scale}{t\_0} \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{{t\_1}^{2} \cdot \frac{-2 \cdot y-scale}{x-scale}}{t\_1 \cdot \sin \left(t\_0 \cdot 0.005555555555555556\right)}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 2.15000000000000007e-44Initial program 7.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites8.4%
Applied rewrites23.2%
Taylor expanded in a around 0
Applied rewrites39.9%
if 2.15000000000000007e-44 < b Initial program 11.8%
Taylor expanded in b around inf
Applied rewrites33.6%
Taylor expanded in x-scale around 0
Applied rewrites63.4%
Applied rewrites63.5%
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
(FPCore (a_m b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) angle)))
(if (<= b_m 2.15e-44)
(*
180.0
(/
(atan
(*
(/
(*
(* (* -2.0 (/ b_m (* x-scale x-scale))) (/ y-scale (- b_m a_m)))
x-scale)
t_0)
90.0))
(PI)))
(*
180.0
(/
(atan
(*
(/
(/
(*
(* -2.0 y-scale)
(pow (cos (* -0.005555555555555556 (* angle (PI)))) 2.0))
x-scale)
(*
(sin (* t_0 0.005555555555555556))
(cos (* -0.005555555555555556 t_0))))
0.5))
(PI))))))\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;b\_m \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(\left(-2 \cdot \frac{b\_m}{x-scale \cdot x-scale}\right) \cdot \frac{y-scale}{b\_m - a\_m}\right) \cdot x-scale}{t\_0} \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\frac{\left(-2 \cdot y-scale\right) \cdot {\cos \left(-0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}}{x-scale}}{\sin \left(t\_0 \cdot 0.005555555555555556\right) \cdot \cos \left(-0.005555555555555556 \cdot t\_0\right)} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 2.15000000000000007e-44Initial program 7.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites8.4%
Applied rewrites23.2%
Taylor expanded in a around 0
Applied rewrites39.9%
if 2.15000000000000007e-44 < b Initial program 11.8%
Taylor expanded in b around inf
Applied rewrites33.6%
Taylor expanded in x-scale around 0
Applied rewrites63.4%
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
(FPCore (a_m b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) angle)))
(if (<= b_m 2.15e-44)
(*
180.0
(/
(atan
(*
(/
(*
(* (* -2.0 (/ b_m (* x-scale x-scale))) (/ y-scale (- b_m a_m)))
x-scale)
t_0)
90.0))
(PI)))
(/
(*
(atan
(*
0.5
(/
(* (pow 1.0 2.0) (/ (* -2.0 y-scale) x-scale))
(*
(cos (* t_0 -0.005555555555555556))
(sin (* t_0 0.005555555555555556))))))
180.0)
(PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;b\_m \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(\left(-2 \cdot \frac{b\_m}{x-scale \cdot x-scale}\right) \cdot \frac{y-scale}{b\_m - a\_m}\right) \cdot x-scale}{t\_0} \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{{1}^{2} \cdot \frac{-2 \cdot y-scale}{x-scale}}{\cos \left(t\_0 \cdot -0.005555555555555556\right) \cdot \sin \left(t\_0 \cdot 0.005555555555555556\right)}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 2.15000000000000007e-44Initial program 7.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites8.4%
Applied rewrites23.2%
Taylor expanded in a around 0
Applied rewrites39.9%
if 2.15000000000000007e-44 < b Initial program 11.8%
Taylor expanded in b around inf
Applied rewrites33.6%
Taylor expanded in x-scale around 0
Applied rewrites63.4%
Applied rewrites63.5%
Taylor expanded in angle around 0
Applied rewrites62.6%
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
(FPCore (a_m b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) angle)))
(if (<= b_m 2.15e-44)
(*
180.0
(/
(atan
(*
(/
(*
(* (* -2.0 (/ b_m (* x-scale x-scale))) (/ y-scale (- b_m a_m)))
x-scale)
t_0)
90.0))
(PI)))
(*
180.0
(/
(atan
(*
(/
(* -2.0 (/ y-scale x-scale))
(*
(sin (* t_0 0.005555555555555556))
(cos (* -0.005555555555555556 t_0))))
0.5))
(PI))))))\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;b\_m \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(\left(-2 \cdot \frac{b\_m}{x-scale \cdot x-scale}\right) \cdot \frac{y-scale}{b\_m - a\_m}\right) \cdot x-scale}{t\_0} \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale}{x-scale}}{\sin \left(t\_0 \cdot 0.005555555555555556\right) \cdot \cos \left(-0.005555555555555556 \cdot t\_0\right)} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 2.15000000000000007e-44Initial program 7.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites8.4%
Applied rewrites23.2%
Taylor expanded in a around 0
Applied rewrites39.9%
if 2.15000000000000007e-44 < b Initial program 11.8%
Taylor expanded in b around inf
Applied rewrites33.6%
Taylor expanded in angle around 0
Applied rewrites62.6%
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
(FPCore (a_m b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 2e+155)
(*
180.0
(/
(atan
(*
(/
(*
(* (* -2.0 (/ b_m (* x-scale x-scale))) (/ y-scale (- b_m a_m)))
x-scale)
(* (PI) angle))
90.0))
(PI)))
(*
180.0
(/ (atan (* (* -2.0 (/ (/ y-scale angle) (* (PI) x-scale))) 90.0)) (PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;b\_m \leq 2 \cdot 10^{+155}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(\left(-2 \cdot \frac{b\_m}{x-scale \cdot x-scale}\right) \cdot \frac{y-scale}{b\_m - a\_m}\right) \cdot x-scale}{\mathsf{PI}\left(\right) \cdot angle} \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \frac{\frac{y-scale}{angle}}{\mathsf{PI}\left(\right) \cdot x-scale}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 2.00000000000000001e155Initial program 10.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.8%
Applied rewrites25.3%
Taylor expanded in a around 0
Applied rewrites41.0%
if 2.00000000000000001e155 < b Initial program 0.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites0.0%
Taylor expanded in a around 0
Applied rewrites50.8%
Applied rewrites50.8%
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
(FPCore (a_m b_m angle x-scale y-scale)
:precision binary64
(if (<= a_m 5.2e-91)
(/ (* 180.0 (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.0))) (PI))
(*
180.0
(/
(atan
(*
(/ (* (* -2.0 (/ y-scale (* x-scale x-scale))) x-scale) (* (PI) angle))
90.0))
(PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 5.2 \cdot 10^{-91}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(\frac{y-scale}{\left(x-scale \cdot \mathsf{PI}\left(\right)\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(-2 \cdot \frac{y-scale}{x-scale \cdot x-scale}\right) \cdot x-scale}{\mathsf{PI}\left(\right) \cdot angle} \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 5.20000000000000028e-91Initial program 11.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.1%
Applied rewrites15.0%
Taylor expanded in a around 0
Applied rewrites44.4%
if 5.20000000000000028e-91 < a Initial program 4.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites6.8%
Applied rewrites17.4%
Taylor expanded in a around 0
Applied rewrites32.2%
b_m = (fabs.f64 b) a_m = (fabs.f64 a) (FPCore (a_m b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ (* -2.0 (/ y-scale x-scale)) (* (PI) angle)) 90.0)) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale}{x-scale}}{\mathsf{PI}\left(\right) \cdot angle} \cdot 90\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 9.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites9.8%
Applied rewrites27.5%
Taylor expanded in a around 0
Applied rewrites42.0%
b_m = (fabs.f64 b) a_m = (fabs.f64 a) (FPCore (a_m b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (* -2.0 (/ (/ y-scale angle) (* (PI) x-scale))) 90.0)) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \frac{\frac{y-scale}{angle}}{\mathsf{PI}\left(\right) \cdot x-scale}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 9.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites9.8%
Taylor expanded in a around 0
Applied rewrites39.0%
Applied rewrites39.0%
b_m = (fabs.f64 b) a_m = (fabs.f64 a) (FPCore (a_m b_m angle x-scale y-scale) :precision binary64 (/ (* 180.0 (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.0))) (PI)))
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\frac{180 \cdot \tan^{-1} \left(\frac{y-scale}{\left(x-scale \cdot \mathsf{PI}\left(\right)\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 9.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites9.8%
Applied rewrites12.1%
Taylor expanded in a around 0
Applied rewrites39.0%
b_m = (fabs.f64 b) a_m = (fabs.f64 a) (FPCore (a_m b_m angle x-scale y-scale) :precision binary64 (/ (* 180.0 (atan (* (/ x-scale (* (* y-scale (PI)) angle)) -180.0))) (PI)))
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
\frac{180 \cdot \tan^{-1} \left(\frac{x-scale}{\left(y-scale \cdot \mathsf{PI}\left(\right)\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 9.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites9.8%
Applied rewrites12.1%
Taylor expanded in a around inf
Applied rewrites13.0%
herbie shell --seed 2024360
(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))))