
(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}
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* angle (PI)))
(t_1 (* 0.005555555555555556 t_0))
(t_2 (cos t_1))
(t_3 (/ x-scale t_2))
(t_4 (sqrt (PI)))
(t_5 (* (* (PI) angle) 0.005555555555555556))
(t_6 (cos t_5))
(t_7 (sin t_5)))
(if (<= b_m 1.8e-188)
(*
180.0
(/
(atan
(*
-0.5
(* t_3 (* -2.0 (* y-scale (/ (sin t_1) (* x-scale x-scale)))))))
(PI)))
(if (<= b_m 7.2e-100)
(*
(/
(atan
(*
-2.0
(*
(/ y-scale x-scale)
(/ (pow t_2 2.0) (sin (* 0.011111111111111112 t_0))))))
(PI))
180.0)
(if (<= b_m 2.45e+50)
(*
180.0
(/
(atan
(*
-0.5
(*
t_3
(/
(*
(* y-scale 2.0)
(+
(pow (* t_7 (/ a x-scale)) 2.0)
(pow (* (/ b_m x-scale) t_6) 2.0)))
(* (* t_7 (- b_m a)) (+ b_m a))))))
(PI)))
(*
(/
(atan
(*
0.5
(/
(* (* -2.0 y-scale) (/ (pow t_6 2.0) x-scale))
(* (sin (* (* (* t_4 t_4) angle) 0.011111111111111112)) 0.5))))
(PI))
180.0))))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := angle \cdot \mathsf{PI}\left(\right)\\
t_1 := 0.005555555555555556 \cdot t\_0\\
t_2 := \cos t\_1\\
t_3 := \frac{x-scale}{t\_2}\\
t_4 := \sqrt{\mathsf{PI}\left(\right)}\\
t_5 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_6 := \cos t\_5\\
t_7 := \sin t\_5\\
\mathbf{if}\;b\_m \leq 1.8 \cdot 10^{-188}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(t\_3 \cdot \left(-2 \cdot \left(y-scale \cdot \frac{\sin t\_1}{x-scale \cdot x-scale}\right)\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;b\_m \leq 7.2 \cdot 10^{-100}:\\
\;\;\;\;\frac{\tan^{-1} \left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{{t\_2}^{2}}{\sin \left(0.011111111111111112 \cdot t\_0\right)}\right)\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{elif}\;b\_m \leq 2.45 \cdot 10^{+50}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(t\_3 \cdot \frac{\left(y-scale \cdot 2\right) \cdot \left({\left(t\_7 \cdot \frac{a}{x-scale}\right)}^{2} + {\left(\frac{b\_m}{x-scale} \cdot t\_6\right)}^{2}\right)}{\left(t\_7 \cdot \left(b\_m - a\right)\right) \cdot \left(b\_m + a\right)}\right)\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{\left(-2 \cdot y-scale\right) \cdot \frac{{t\_6}^{2}}{x-scale}}{\sin \left(\left(\left(t\_4 \cdot t\_4\right) \cdot angle\right) \cdot 0.011111111111111112\right) \cdot 0.5}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if b < 1.7999999999999998e-188Initial program 15.6%
Taylor expanded in b around inf
Applied rewrites29.4%
Taylor expanded in y-scale around inf
Applied rewrites18.4%
Taylor expanded in a around inf
Applied rewrites44.2%
if 1.7999999999999998e-188 < b < 7.1999999999999997e-100Initial program 21.4%
Taylor expanded in b around inf
Applied rewrites37.7%
Taylor expanded in x-scale around 0
Applied rewrites55.1%
Applied rewrites55.1%
Taylor expanded in x-scale around 0
Applied rewrites55.1%
if 7.1999999999999997e-100 < b < 2.4500000000000001e50Initial program 34.0%
Taylor expanded in b around inf
Applied rewrites17.9%
Taylor expanded in y-scale around inf
Applied rewrites46.5%
Applied rewrites55.5%
Applied rewrites59.6%
if 2.4500000000000001e50 < b Initial program 6.4%
Taylor expanded in b around inf
Applied rewrites28.3%
Taylor expanded in x-scale around 0
Applied rewrites54.8%
Applied rewrites54.8%
Applied rewrites54.6%
Final simplification49.2%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI))))
(t_1 (cos t_0))
(t_2 (/ x-scale t_1))
(t_3 (sin t_0))
(t_4 (* (* (PI) angle) 0.005555555555555556))
(t_5 (sin t_4)))
(if (<= a 7.2e-46)
(* 180.0 (/ (atan (/ (* (- y-scale) t_1) (* x-scale t_3))) (PI)))
(if (<= a 8.5e+173)
(*
180.0
(/
(atan
(*
-0.5
(*
t_2
(/
(*
y-scale
(*
(/
(*
(pow x-scale -2.0)
(+ (pow (* (cos t_4) b_m) 2.0) (pow (* t_5 a) 2.0)))
(+ b_m a))
(/ 2.0 (- b_m a))))
t_5))))
(PI)))
(*
180.0
(/
(atan
(* -0.5 (* t_2 (* -2.0 (* y-scale (/ t_3 (* x-scale x-scale)))))))
(PI)))))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
t_1 := \cos t\_0\\
t_2 := \frac{x-scale}{t\_1}\\
t_3 := \sin t\_0\\
t_4 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_5 := \sin t\_4\\
\mathbf{if}\;a \leq 7.2 \cdot 10^{-46}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(-y-scale\right) \cdot t\_1}{x-scale \cdot t\_3}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;a \leq 8.5 \cdot 10^{+173}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(t\_2 \cdot \frac{y-scale \cdot \left(\frac{{x-scale}^{-2} \cdot \left({\left(\cos t\_4 \cdot b\_m\right)}^{2} + {\left(t\_5 \cdot a\right)}^{2}\right)}{b\_m + a} \cdot \frac{2}{b\_m - a}\right)}{t\_5}\right)\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(t\_2 \cdot \left(-2 \cdot \left(y-scale \cdot \frac{t\_3}{x-scale \cdot x-scale}\right)\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 7.2e-46Initial program 16.5%
Taylor expanded in b around inf
Applied rewrites29.6%
Applied rewrites29.5%
Taylor expanded in x-scale around 0
Applied rewrites55.0%
if 7.2e-46 < a < 8.5000000000000003e173Initial program 23.0%
Taylor expanded in b around inf
Applied rewrites26.8%
Taylor expanded in y-scale around inf
Applied rewrites41.4%
Applied rewrites54.1%
if 8.5000000000000003e173 < a Initial program 0.0%
Taylor expanded in b around inf
Applied rewrites25.4%
Taylor expanded in y-scale around inf
Applied rewrites0.0%
Taylor expanded in a around inf
Applied rewrites45.6%
Final simplification53.6%
b_m = (fabs.f64 b)
(FPCore (a b_m 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 4e+15)
(* 180.0 (/ (atan (/ (* (- y-scale) t_1) (* x-scale t_2))) (PI)))
(*
180.0
(/
(atan
(*
-0.5
(* (/ x-scale t_1) (* -2.0 (* y-scale (/ t_2 (* x-scale x-scale)))))))
(PI))))))\begin{array}{l}
b_m = \left|b\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 \leq 4 \cdot 10^{+15}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(-y-scale\right) \cdot t\_1}{x-scale \cdot t\_2}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{x-scale}{t\_1} \cdot \left(-2 \cdot \left(y-scale \cdot \frac{t\_2}{x-scale \cdot x-scale}\right)\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 4e15Initial program 17.7%
Taylor expanded in b around inf
Applied rewrites30.6%
Applied rewrites30.6%
Taylor expanded in x-scale around 0
Applied rewrites55.2%
if 4e15 < a Initial program 7.0%
Taylor expanded in b around inf
Applied rewrites21.9%
Taylor expanded in y-scale around inf
Applied rewrites18.3%
Taylor expanded in a around inf
Applied rewrites51.0%
Final simplification54.2%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556)))
(*
180.0
(/
(atan (* (/ (* -2.0 (/ y-scale x-scale)) (* (sin t_0) (cos t_0))) 0.5))
(PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
180 \cdot \frac{\tan^{-1} \left(\frac{-2 \cdot \frac{y-scale}{x-scale}}{\sin t\_0 \cdot \cos t\_0} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}
\end{array}
\end{array}
Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites28.6%
Taylor expanded in angle around 0
Applied rewrites51.6%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI)))))
(*
180.0
(/ (atan (/ (* (- y-scale) (cos t_0)) (* x-scale (sin t_0)))) (PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
180 \cdot \frac{\tan^{-1} \left(\frac{\left(-y-scale\right) \cdot \cos t\_0}{x-scale \cdot \sin t\_0}\right)}{\mathsf{PI}\left(\right)}
\end{array}
\end{array}
Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites28.6%
Applied rewrites28.6%
Taylor expanded in x-scale around 0
Applied rewrites49.3%
Final simplification49.3%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 2.4e+121)
(*
180.0
(/
(atan
(/
(* -180.0 (* (* b_m b_m) y-scale))
(* (* angle x-scale) (* (* (PI) (+ b_m a)) (- b_m a)))))
(PI)))
(*
180.0
(/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
\mathbf{if}\;b\_m \leq 2.4 \cdot 10^{+121}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-180 \cdot \left(\left(b\_m \cdot b\_m\right) \cdot y-scale\right)}{\left(angle \cdot x-scale\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \left(b\_m + a\right)\right) \cdot \left(b\_m - a\right)\right)}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;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}
\end{array}
if b < 2.4e121Initial program 18.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites15.3%
Applied rewrites17.0%
Taylor expanded in x-scale around 0
Applied rewrites31.5%
if 2.4e121 < b Initial program 2.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites6.0%
Applied rewrites6.6%
Taylor expanded in a around 0
Applied rewrites62.4%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI))))
\begin{array}{l}
b_m = \left|b\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 15.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites13.4%
Applied rewrites14.9%
Taylor expanded in a around 0
Applied rewrites45.0%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* -180.0 (/ x-scale (* angle (* y-scale (PI)))))) (PI))))
\begin{array}{l}
b_m = \left|b\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 15.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites13.4%
Applied rewrites14.9%
Taylor expanded in a around inf
Applied rewrites14.9%
herbie shell --seed 2024307
(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))))