
(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 10 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 (* (* 0.005555555555555556 angle) (PI)))
(t_1 (sin t_0))
(t_2 (* (* (PI) angle) 0.005555555555555556))
(t_3 (sin t_2))
(t_4 (cos t_2))
(t_5 (cos t_0)))
(if (<= b_m 5e-52)
(* (/ (atan (* (/ t_3 t_4) (/ y-scale x-scale))) (PI)) 180.0)
(if (<= b_m 1.9e+88)
(*
(/
(atan
(*
(/ (+ (pow (* t_5 b_m) 2.0) (pow (* t_1 a) 2.0)) (* t_5 x-scale))
(/ y-scale (* (* (- a b_m) t_1) (+ a b_m)))))
(PI))
180.0)
(* (/ (atan (/ (* (- y-scale) t_4) (* t_3 x-scale))) (PI)) 180.0)))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := \left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin t\_0\\
t_2 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_3 := \sin t\_2\\
t_4 := \cos t\_2\\
t_5 := \cos t\_0\\
\mathbf{if}\;b\_m \leq 5 \cdot 10^{-52}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{t\_3}{t\_4} \cdot \frac{y-scale}{x-scale}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{elif}\;b\_m \leq 1.9 \cdot 10^{+88}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{{\left(t\_5 \cdot b\_m\right)}^{2} + {\left(t\_1 \cdot a\right)}^{2}}{t\_5 \cdot x-scale} \cdot \frac{y-scale}{\left(\left(a - b\_m\right) \cdot t\_1\right) \cdot \left(a + b\_m\right)}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\left(-y-scale\right) \cdot t\_4}{t\_3 \cdot x-scale}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if b < 5e-52Initial program 18.7%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites33.6%
Taylor expanded in b around 0
Applied rewrites50.4%
if 5e-52 < b < 1.8999999999999998e88Initial program 28.9%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites50.9%
Applied rewrites58.1%
Applied rewrites62.6%
if 1.8999999999999998e88 < b Initial program 9.6%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites12.2%
Taylor expanded in b around inf
Applied rewrites79.4%
Final simplification56.9%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556)) (t_1 (sin t_0)))
(if (<= b_m 4.5e-35)
(* (/ (atan (* (/ t_1 (cos t_0)) (/ y-scale x-scale))) (PI)) 180.0)
(*
(/
(atan
(*
(*
(*
(/ (cos (* (* 0.005555555555555556 angle) (PI))) t_1)
(/ y-scale x-scale))
2.0)
-0.5))
(PI))
180.0))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \sin t\_0\\
\mathbf{if}\;b\_m \leq 4.5 \cdot 10^{-35}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{t\_1}{\cos t\_0} \cdot \frac{y-scale}{x-scale}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\left(\left(\frac{\cos \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)}{t\_1} \cdot \frac{y-scale}{x-scale}\right) \cdot 2\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if b < 4.5000000000000001e-35Initial program 19.9%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.4%
Taylor expanded in b around 0
Applied rewrites50.7%
if 4.5000000000000001e-35 < b Initial program 15.6%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites27.9%
Taylor expanded in b around inf
Applied rewrites67.6%
Applied rewrites69.0%
Final simplification55.9%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556))
(t_1 (cos t_0))
(t_2 (sin t_0)))
(if (<= b_m 4.7e-35)
(* (/ (atan (* (/ t_2 t_1) (/ y-scale x-scale))) (PI)) 180.0)
(* (/ (atan (/ (* (- y-scale) t_1) (* t_2 x-scale))) (PI)) 180.0))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
\mathbf{if}\;b\_m \leq 4.7 \cdot 10^{-35}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{t\_2}{t\_1} \cdot \frac{y-scale}{x-scale}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\left(-y-scale\right) \cdot t\_1}{t\_2 \cdot x-scale}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if b < 4.7e-35Initial program 19.9%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.4%
Taylor expanded in b around 0
Applied rewrites50.7%
if 4.7e-35 < b Initial program 15.6%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites27.9%
Taylor expanded in b around inf
Applied rewrites67.5%
Final simplification55.5%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556)))
(if (<= (/ angle 180.0) 2e+14)
(/
(* (atan (* (/ (* (/ y-scale x-scale) 2.0) (tan t_0)) -0.5)) 180.0)
(PI))
(*
(/
(atan
(*
(*
(*
(/
(fma (* (* angle angle) -1.54320987654321e-5) (* (PI) (PI)) 1.0)
(sin t_0))
(/ y-scale x-scale))
2.0)
-0.5))
(PI))
180.0))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
\mathbf{if}\;\frac{angle}{180} \leq 2 \cdot 10^{+14}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\frac{y-scale}{x-scale} \cdot 2}{\tan t\_0} \cdot -0.5\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\left(\left(\frac{\mathsf{fma}\left(\left(angle \cdot angle\right) \cdot -1.54320987654321 \cdot 10^{-5}, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)}{\sin t\_0} \cdot \frac{y-scale}{x-scale}\right) \cdot 2\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 2e14Initial program 19.6%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites33.4%
Taylor expanded in b around inf
Applied rewrites53.2%
Applied rewrites53.1%
Applied rewrites53.2%
if 2e14 < (/.f64 angle #s(literal 180 binary64)) Initial program 13.7%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.3%
Taylor expanded in b around inf
Applied rewrites35.0%
Taylor expanded in angle around 0
Applied rewrites48.5%
Final simplification52.4%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 5e-35)
(*
(/
(atan
(/
(* (* (* b_m b_m) y-scale) -180.0)
(* (* (* (+ a b_m) (PI)) (- b_m a)) (* x-scale angle))))
(PI))
180.0)
(*
(/
(atan
(*
(*
(/ y-scale (* (tan (* (* 0.005555555555555556 angle) (PI))) x-scale))
2.0)
-0.5))
(PI))
180.0)))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
\mathbf{if}\;b\_m \leq 5 \cdot 10^{-35}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\left(\left(b\_m \cdot b\_m\right) \cdot y-scale\right) \cdot -180}{\left(\left(\left(a + b\_m\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(b\_m - a\right)\right) \cdot \left(x-scale \cdot angle\right)}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\left(\frac{y-scale}{\tan \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot x-scale} \cdot 2\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if b < 4.99999999999999964e-35Initial program 19.9%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.4%
Taylor expanded in angle around 0
Applied rewrites32.1%
if 4.99999999999999964e-35 < b Initial program 15.6%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites27.9%
Taylor expanded in b around inf
Applied rewrites67.6%
Applied rewrites67.8%
Final simplification42.3%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(/
(*
(atan
(*
(/
(* (/ y-scale x-scale) 2.0)
(tan (* (* (PI) angle) 0.005555555555555556)))
-0.5))
180.0)
(PI)))\begin{array}{l}
b_m = \left|b\right|
\\
\frac{\tan^{-1} \left(\frac{\frac{y-scale}{x-scale} \cdot 2}{\tan \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right)} \cdot -0.5\right) \cdot 180}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 18.7%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites32.5%
Taylor expanded in b around inf
Applied rewrites50.3%
Applied rewrites51.3%
Applied rewrites50.3%
Final simplification50.3%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(*
(/
(atan
(*
(/
(* (/ y-scale x-scale) 2.0)
(tan (* (* (PI) angle) 0.005555555555555556)))
-0.5))
(PI))
180.0))\begin{array}{l}
b_m = \left|b\right|
\\
\frac{\tan^{-1} \left(\frac{\frac{y-scale}{x-scale} \cdot 2}{\tan \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right)} \cdot -0.5\right)}{\mathsf{PI}\left(\right)} \cdot 180
\end{array}
Initial program 18.7%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites32.5%
Taylor expanded in b around inf
Applied rewrites50.3%
Applied rewrites51.3%
Applied rewrites50.3%
Final simplification50.3%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 1.6e+87)
(*
(/
(atan
(/
(* (* (* b_m b_m) y-scale) -180.0)
(* (* (* (+ a b_m) (PI)) (- b_m a)) (* x-scale angle))))
(PI))
180.0)
(*
(/ (atan (* 90.0 (* -2.0 (/ y-scale (* (* (PI) x-scale) angle))))) (PI))
180.0)))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
\mathbf{if}\;b\_m \leq 1.6 \cdot 10^{+87}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\left(\left(b\_m \cdot b\_m\right) \cdot y-scale\right) \cdot -180}{\left(\left(\left(a + b\_m\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(b\_m - a\right)\right) \cdot \left(x-scale \cdot angle\right)}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(90 \cdot \left(-2 \cdot \frac{y-scale}{\left(\mathsf{PI}\left(\right) \cdot x-scale\right) \cdot angle}\right)\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if b < 1.6e87Initial program 20.5%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites36.7%
Taylor expanded in angle around 0
Applied rewrites34.4%
if 1.6e87 < b Initial program 9.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites14.2%
Taylor expanded in b around 0
Applied rewrites24.2%
Taylor expanded in b around inf
Applied rewrites74.9%
Final simplification41.2%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* (/ (atan (* 90.0 (* -2.0 (/ y-scale (* (* (PI) x-scale) angle))))) (PI)) 180.0))
\begin{array}{l}
b_m = \left|b\right|
\\
\frac{\tan^{-1} \left(90 \cdot \left(-2 \cdot \frac{y-scale}{\left(\mathsf{PI}\left(\right) \cdot x-scale\right) \cdot angle}\right)\right)}{\mathsf{PI}\left(\right)} \cdot 180
\end{array}
Initial program 18.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites16.5%
Taylor expanded in b around 0
Applied rewrites15.5%
Taylor expanded in b around inf
Applied rewrites42.0%
Final simplification42.0%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* (/ (atan (* (* (/ x-scale (* (* (PI) y-scale) angle)) -2.0) 90.0)) (PI)) 180.0))
\begin{array}{l}
b_m = \left|b\right|
\\
\frac{\tan^{-1} \left(\left(\frac{x-scale}{\left(\mathsf{PI}\left(\right) \cdot y-scale\right) \cdot angle} \cdot -2\right) \cdot 90\right)}{\mathsf{PI}\left(\right)} \cdot 180
\end{array}
Initial program 18.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites16.5%
Taylor expanded in b around 0
Applied rewrites15.5%
Taylor expanded in b around 0
Applied rewrites15.5%
Final simplification15.5%
herbie shell --seed 2024241
(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))))