
(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))))
(if (<= a_m 4.6e-201)
(*
180.0
(/
(atan
(*
(*
2.0
(*
(/ y-scale x-scale)
(/
(+ 1.0 (* (* -1.54320987654321e-5 (* angle angle)) (* (PI) (PI))))
t_1)))
-0.5))
(PI)))
(if (<= a_m 4.2e+33)
(*
180.0
(/ (atan (* (* 2.0 (* (/ y-scale x-scale) (/ 1.0 t_1))) -0.5)) (PI)))
(*
180.0
(/
(atan
(*
(*
-2.0
(*
(/ y-scale x-scale)
(/ t_1 (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 := \sin \left(0.005555555555555556 \cdot t\_0\right)\\
\mathbf{if}\;a\_m \leq 4.6 \cdot 10^{-201}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{1 + \left(-1.54320987654321 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}{t\_1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;a\_m \leq 4.2 \cdot 10^{+33}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{1}{t\_1}\right)\right) \cdot -0.5\right)}{\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}{\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.59999999999999971e-201Initial program 13.0%
Taylor expanded in x-scale around 0
Applied rewrites28.3%
Taylor expanded in a around 0
Applied rewrites36.8%
Taylor expanded in angle around 0
Applied rewrites38.0%
if 4.59999999999999971e-201 < a < 4.2000000000000001e33Initial program 25.3%
Taylor expanded in x-scale around 0
Applied rewrites45.8%
Taylor expanded in a around 0
Applied rewrites41.9%
Taylor expanded in angle around 0
Applied rewrites49.0%
if 4.2000000000000001e33 < a Initial program 3.9%
Taylor expanded in x-scale around 0
Applied rewrites16.9%
Taylor expanded in a around inf
Applied rewrites58.0%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (sin (* 0.005555555555555556 (* angle (PI))))))
(if (<= a_m 4.6e-201)
(*
180.0
(/
(atan
(*
(*
2.0
(*
(/ y-scale x-scale)
(/
(+ 1.0 (* (* -1.54320987654321e-5 (* angle angle)) (* (PI) (PI))))
t_0)))
-0.5))
(PI)))
(if (<= a_m 9000000000.0)
(*
180.0
(/ (atan (* (* 2.0 (* (/ y-scale x-scale) (/ 1.0 t_0))) -0.5)) (PI)))
(*
180.0
(/
(atan (* (* -2.0 (* (/ y-scale x-scale) (/ t_0 1.0))) -0.5))
(PI)))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \sin \left(0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)\\
\mathbf{if}\;a\_m \leq 4.6 \cdot 10^{-201}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{1 + \left(-1.54320987654321 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}{t\_0}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;a\_m \leq 9000000000:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{1}{t\_0}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{t\_0}{1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 4.59999999999999971e-201Initial program 13.0%
Taylor expanded in x-scale around 0
Applied rewrites28.3%
Taylor expanded in a around 0
Applied rewrites36.8%
Taylor expanded in angle around 0
Applied rewrites38.0%
if 4.59999999999999971e-201 < a < 9e9Initial program 27.5%
Taylor expanded in x-scale around 0
Applied rewrites46.7%
Taylor expanded in a around 0
Applied rewrites42.0%
Taylor expanded in angle around 0
Applied rewrites52.6%
if 9e9 < a Initial program 3.7%
Taylor expanded in x-scale around 0
Applied rewrites17.8%
Taylor expanded in a around inf
Applied rewrites55.2%
Taylor expanded in angle around 0
Applied rewrites53.7%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (sin (* 0.005555555555555556 (* angle (PI))))))
(if (<= a_m 9000000000.0)
(*
180.0
(/ (atan (* (* 2.0 (* (/ y-scale x-scale) (/ 1.0 t_0))) -0.5)) (PI)))
(*
180.0
(/ (atan (* (* -2.0 (* (/ y-scale x-scale) (/ t_0 1.0))) -0.5)) (PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \sin \left(0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)\\
\mathbf{if}\;a\_m \leq 9000000000:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{1}{t\_0}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{t\_0}{1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 9e9Initial program 15.5%
Taylor expanded in x-scale around 0
Applied rewrites31.4%
Taylor expanded in a around 0
Applied rewrites37.7%
Taylor expanded in angle around 0
Applied rewrites41.7%
if 9e9 < a Initial program 3.7%
Taylor expanded in x-scale around 0
Applied rewrites17.8%
Taylor expanded in a around inf
Applied rewrites55.2%
Taylor expanded in angle around 0
Applied rewrites53.7%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 3200000000.0)
(*
180.0
(/ (atan (* (* -2.0 (/ y-scale (* angle (* x-scale (PI))))) 90.0)) (PI)))
(*
180.0
(/
(atan
(*
(*
-2.0
(*
(/ y-scale x-scale)
(/ (sin (* 0.005555555555555556 (* angle (PI)))) 1.0)))
-0.5))
(PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 3200000000:\\
\;\;\;\;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(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{\sin \left(0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}{1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 3.2e9Initial program 15.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites12.8%
Taylor expanded in a around inf
Applied rewrites11.9%
Taylor expanded in a around 0
Applied rewrites35.7%
if 3.2e9 < a Initial program 3.7%
Taylor expanded in x-scale around 0
Applied rewrites17.8%
Taylor expanded in a around inf
Applied rewrites55.2%
Taylor expanded in angle around 0
Applied rewrites53.7%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= b 7e+85)
(*
180.0
(/
(atan
(*
(*
y-scale
(/
(* -2.0 (* b b))
(* (* angle x-scale) (* (* (PI) (+ b a_m)) (- b a_m)))))
90.0))
(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 7 \cdot 10^{+85}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(y-scale \cdot \frac{-2 \cdot \left(b \cdot b\right)}{\left(angle \cdot x-scale\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \left(b + a\_m\right)\right) \cdot \left(b - a\_m\right)\right)}\right) \cdot 90\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 < 7.0000000000000001e85Initial program 12.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites11.4%
Taylor expanded in a around inf
Applied rewrites8.8%
Taylor expanded in y-scale around inf
Applied rewrites11.9%
Taylor expanded in x-scale around 0
Applied rewrites25.1%
if 7.0000000000000001e85 < b Initial program 12.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites7.7%
Taylor expanded in a around inf
Applied rewrites17.7%
Taylor expanded in a around 0
Applied rewrites49.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 12.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites10.8%
Taylor expanded in a around inf
Applied rewrites10.3%
Taylor expanded in a around 0
Applied rewrites33.2%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (* -2.0 (/ x-scale (* (* y-scale angle) (PI)))) 90.0)) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \frac{x-scale}{\left(y-scale \cdot angle\right) \cdot \mathsf{PI}\left(\right)}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 12.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites10.8%
Taylor expanded in a around inf
Applied rewrites10.3%
Taylor expanded in a around inf
Applied rewrites10.2%
Applied rewrites10.3%
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 12.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites10.8%
Taylor expanded in a around inf
Applied rewrites10.3%
Taylor expanded in a around inf
Applied rewrites10.2%
herbie shell --seed 2024351
(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))))