
(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}
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)))
(if (<= b_m 1.28e+72)
(* 180.0 (/ (atan (* (/ y-scale x-scale) (tan t_1))) (PI)))
(*
180.0
(/
(atan
(/
(* (- y-scale) (sin (fma 0.005555555555555556 t_0 (/ (PI) 2.0))))
(* x-scale (sin t_1))))
(PI))))))\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\\
\mathbf{if}\;b\_m \leq 1.28 \cdot 10^{+72}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \tan t\_1\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\left(-y-scale\right) \cdot \sin \left(\mathsf{fma}\left(0.005555555555555556, t\_0, \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}{x-scale \cdot \sin t\_1}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 1.28000000000000009e72Initial program 15.1%
Taylor expanded in x-scale around 0
Applied rewrites38.0%
Taylor expanded in a around inf
lower-*.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6455.7
Applied rewrites55.7%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
tan-quotN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f6455.7
Applied rewrites55.7%
if 1.28000000000000009e72 < b Initial program 12.2%
Taylor expanded in x-scale around 0
Applied rewrites19.1%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lower-*.f64N/A
Applied rewrites55.5%
lift-cos.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
sin-+PI/2-revN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-fma.f64N/A
lift-sin.f6463.6
Applied rewrites63.6%
Final simplification57.3%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI)))))
(if (<= b_m 1.3e+72)
(* 180.0 (/ (atan (* (/ y-scale x-scale) (tan t_0))) (PI)))
(* 180.0 (/ (atan (/ (- y-scale) (* 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)\\
\mathbf{if}\;b\_m \leq 1.3 \cdot 10^{+72}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \tan t\_0\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-y-scale}{x-scale \cdot \sin t\_0}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 1.29999999999999991e72Initial program 15.1%
Taylor expanded in x-scale around 0
Applied rewrites38.0%
Taylor expanded in a around inf
lower-*.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6455.7
Applied rewrites55.7%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
tan-quotN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f6455.7
Applied rewrites55.7%
if 1.29999999999999991e72 < b Initial program 12.2%
Taylor expanded in x-scale around 0
Applied rewrites19.1%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lower-*.f64N/A
Applied rewrites55.5%
Taylor expanded in angle around 0
Applied rewrites62.5%
Final simplification57.0%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 3.8e+150)
(*
180.0
(/
(atan
(* (/ y-scale x-scale) (tan (* 0.005555555555555556 (* angle (PI))))))
(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 3.8 \cdot 10^{+150}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \tan \left(0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\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 < 3.79999999999999989e150Initial program 16.3%
Taylor expanded in x-scale around 0
Applied rewrites38.0%
Taylor expanded in a around inf
lower-*.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6453.9
Applied rewrites53.9%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
tan-quotN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f6453.9
Applied rewrites53.9%
if 3.79999999999999989e150 < b Initial program 0.0%
Taylor expanded in angle around 0
Applied rewrites0.1%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6465.6
Applied rewrites65.6%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 4.5e+150)
(*
180.0
(/
(atan (* (/ y-scale x-scale) (* 0.005555555555555556 (* angle (PI)))))
(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 4.5 \cdot 10^{+150}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\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 < 4.5e150Initial program 16.3%
Taylor expanded in x-scale around 0
Applied rewrites38.0%
Taylor expanded in a around inf
lower-*.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6453.9
Applied rewrites53.9%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
tan-quotN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f6453.9
Applied rewrites53.9%
Taylor expanded in angle around 0
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6452.0
Applied rewrites52.0%
if 4.5e150 < b Initial program 0.0%
Taylor expanded in angle around 0
Applied rewrites0.1%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6465.6
Applied rewrites65.6%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 6e+199)
(*
180.0
(/
(atan (* (/ y-scale x-scale) (* 0.005555555555555556 (* angle (PI)))))
(PI)))
(*
180.0
(/ (atan (* -180.0 (/ x-scale (* angle (* y-scale (PI)))))) (PI)))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
\mathbf{if}\;b\_m \leq 6 \cdot 10^{+199}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;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}
\end{array}
if b < 6.0000000000000002e199Initial program 15.7%
Taylor expanded in x-scale around 0
Applied rewrites37.0%
Taylor expanded in a around inf
lower-*.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6452.9
Applied rewrites52.9%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
tan-quotN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f6452.9
Applied rewrites52.9%
Taylor expanded in angle around 0
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6451.0
Applied rewrites51.0%
if 6.0000000000000002e199 < b Initial program 0.0%
Taylor expanded in angle around 0
Applied rewrites0.0%
Taylor expanded in a around inf
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6419.4
Applied rewrites19.4%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ y-scale x-scale) (* 0.005555555555555556 (* angle (PI))))) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 14.6%
Taylor expanded in x-scale around 0
Applied rewrites34.3%
Taylor expanded in a around inf
lower-*.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6450.4
Applied rewrites50.4%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
tan-quotN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f6450.4
Applied rewrites50.4%
Taylor expanded in angle around 0
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6448.1
Applied rewrites48.1%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* 0.005555555555555556 (/ (* angle (* y-scale (PI))) x-scale))) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
180 \cdot \frac{\tan^{-1} \left(0.005555555555555556 \cdot \frac{angle \cdot \left(y-scale \cdot \mathsf{PI}\left(\right)\right)}{x-scale}\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 14.6%
Taylor expanded in x-scale around 0
Applied rewrites34.3%
Taylor expanded in a around inf
lower-*.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6450.4
Applied rewrites50.4%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
tan-quotN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f6450.4
Applied rewrites50.4%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6442.0
Applied rewrites42.0%
herbie shell --seed 2025037
(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))))