
(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 7 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 (* (PI) angle)))
(if (<= a_m 4500000.0)
(/
(*
(atan
(*
(*
(* -2.0 y-scale)
(/
(pow
(cos (* (* (cbrt (pow (PI) 3.0)) angle) -0.005555555555555556))
2.0)
x-scale))
(/
0.5
(*
(cos (* t_1 -0.005555555555555556))
(sin (* t_1 0.005555555555555556))))))
180.0)
(PI))
(*
180.0
(/
(atan
(*
(*
(/ y-scale x-scale)
(*
-2.0
(/
(sin (* 0.005555555555555556 t_0))
(cos (* -0.005555555555555556 t_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 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;a\_m \leq 4500000:\\
\;\;\;\;\frac{\tan^{-1} \left(\left(\left(-2 \cdot y-scale\right) \cdot \frac{{\cos \left(\left(\sqrt[3]{{\mathsf{PI}\left(\right)}^{3}} \cdot angle\right) \cdot -0.005555555555555556\right)}^{2}}{x-scale}\right) \cdot \frac{0.5}{\cos \left(t\_1 \cdot -0.005555555555555556\right) \cdot \sin \left(t\_1 \cdot 0.005555555555555556\right)}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin \left(0.005555555555555556 \cdot t\_0\right)}{\cos \left(-0.005555555555555556 \cdot t\_0\right)}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 4.5e6Initial program 17.7%
Taylor expanded in b around inf
Applied rewrites29.4%
Taylor expanded in x-scale around 0
Applied rewrites55.4%
Applied rewrites55.4%
Applied rewrites55.4%
if 4.5e6 < a Initial program 2.3%
Taylor expanded in x-scale around inf
Applied rewrites2.0%
Taylor expanded in a around inf
Applied rewrites22.6%
Taylor expanded in angle around inf
Applied rewrites60.0%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) angle))
(t_1 (* angle (PI)))
(t_2 (cos (* -0.005555555555555556 t_1))))
(if (<= a_m 4500000.0)
(*
180.0
(/
(atan
(*
(/
(* -2.0 (/ (* y-scale (pow t_2 2.0)) x-scale))
(*
(sin (* t_0 0.005555555555555556))
(cos (* -0.005555555555555556 t_0))))
0.5))
(PI)))
(*
180.0
(/
(atan
(*
(*
(/ y-scale x-scale)
(* -2.0 (/ (sin (* 0.005555555555555556 t_1)) t_2)))
-0.5))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
t_1 := angle \cdot \mathsf{PI}\left(\right)\\
t_2 := \cos \left(-0.005555555555555556 \cdot t\_1\right)\\
\mathbf{if}\;a\_m \leq 4500000:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale \cdot {t\_2}^{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)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin \left(0.005555555555555556 \cdot t\_1\right)}{t\_2}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 4.5e6Initial program 17.7%
Taylor expanded in b around inf
Applied rewrites29.4%
Taylor expanded in x-scale around 0
Applied rewrites55.4%
if 4.5e6 < a Initial program 2.3%
Taylor expanded in x-scale around inf
Applied rewrites2.0%
Taylor expanded in a around inf
Applied rewrites22.6%
Taylor expanded in angle around inf
Applied rewrites60.0%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) angle)) (t_1 (* angle (PI))))
(if (<= a_m 3000000.0)
(*
180.0
(/
(atan
(*
(/
(* -2.0 (/ y-scale x-scale))
(*
(sin (* t_0 0.005555555555555556))
(cos (* -0.005555555555555556 t_0))))
0.5))
(PI)))
(*
180.0
(/
(atan
(*
(*
(/ y-scale x-scale)
(*
-2.0
(/
(sin (* 0.005555555555555556 t_1))
(cos (* -0.005555555555555556 t_1)))))
-0.5))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
t_1 := angle \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;a\_m \leq 3000000:\\
\;\;\;\;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)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin \left(0.005555555555555556 \cdot t\_1\right)}{\cos \left(-0.005555555555555556 \cdot t\_1\right)}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 3e6Initial program 17.7%
Taylor expanded in b around inf
Applied rewrites29.4%
Taylor expanded in angle around 0
Applied rewrites54.9%
if 3e6 < a Initial program 2.3%
Taylor expanded in x-scale around inf
Applied rewrites2.0%
Taylor expanded in a around inf
Applied rewrites22.6%
Taylor expanded in angle around inf
Applied rewrites60.0%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* angle (PI))))
(if (<= a_m 1400.0)
(*
180.0
(/ (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.0)) (PI)))
(*
180.0
(/
(atan
(*
(*
(/ y-scale x-scale)
(*
-2.0
(/
(sin (* 0.005555555555555556 t_0))
(cos (* -0.005555555555555556 t_0)))))
-0.5))
(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 1400:\\
\;\;\;\;180 \cdot \frac{\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(\left(\frac{y-scale}{x-scale} \cdot \left(-2 \cdot \frac{\sin \left(0.005555555555555556 \cdot t\_0\right)}{\cos \left(-0.005555555555555556 \cdot t\_0\right)}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 1400Initial program 17.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.5%
Applied rewrites31.9%
Taylor expanded in a around 0
Applied rewrites44.3%
if 1400 < a Initial program 2.2%
Taylor expanded in x-scale around inf
Applied rewrites1.9%
Taylor expanded in a around inf
Applied rewrites23.4%
Taylor expanded in angle around inf
Applied rewrites59.7%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 1400.0)
(* 180.0 (/ (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.0)) (PI)))
(*
180.0
(/
(atan
(*
(* (/ y-scale x-scale) (* -0.011111111111111112 (* angle (PI))))
-0.5))
(PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 1400:\\
\;\;\;\;180 \cdot \frac{\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(\left(\frac{y-scale}{x-scale} \cdot \left(-0.011111111111111112 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 1400Initial program 17.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.5%
Applied rewrites31.9%
Taylor expanded in a around 0
Applied rewrites44.3%
if 1400 < a Initial program 2.2%
Taylor expanded in x-scale around inf
Applied rewrites1.9%
Taylor expanded in a around inf
Applied rewrites23.4%
Taylor expanded in angle around 0
Applied rewrites57.7%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.0)) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\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 14.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites9.2%
Applied rewrites28.3%
Taylor expanded in a around 0
Applied rewrites36.7%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ x-scale (* (* y-scale (PI)) angle)) -180.0)) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\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 14.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites9.2%
Applied rewrites28.3%
Taylor expanded in a around inf
Applied rewrites12.2%
herbie shell --seed 2024340
(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))))