
(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 1.44e-8)
(*
180.0
(/
(atan
(*
(/ (- y-scale) x-scale)
(/ (sin (fma 0.005555555555555556 t_0 (/ (PI) 2.0))) t_1)))
(PI)))
(*
180.0
(/
(atan
(*
(/ y-scale x-scale)
(/ t_1 (sin (fma 0.005555555555555556 t_0 (* 0.5 (PI)))))))
(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 1.44 \cdot 10^{-8}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-y-scale}{x-scale} \cdot \frac{\sin \left(\mathsf{fma}\left(0.005555555555555556, t\_0, \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}{t\_1}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \frac{t\_1}{\sin \left(\mathsf{fma}\left(0.005555555555555556, t\_0, 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 1.44e-8Initial program 13.3%
Taylor expanded in x-scale around 0
Applied rewrites30.1%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f6451.3
Applied rewrites51.3%
Taylor expanded in a around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
Applied rewrites51.3%
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.f6452.8
Applied rewrites52.8%
if 1.44e-8 < a Initial program 3.7%
Taylor expanded in x-scale around 0
Applied rewrites24.4%
lift-*.f64N/A
pow2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f6424.4
Applied rewrites24.4%
lift-cos.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f6428.0
Applied rewrites28.0%
Taylor expanded in a around inf
times-fracN/A
lift-/.f64N/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites61.0%
Final simplification54.7%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle (PI)))))
(if (<= b 1.3e-59)
(* 180.0 (/ (atan (* (/ y-scale x-scale) (tan t_0))) (PI)))
(*
180.0
(/
(atan (* -0.5 (* (/ y-scale x-scale) (* 2.0 (/ 1.0 (sin t_0))))))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;b \leq 1.3 \cdot 10^{-59}:\\
\;\;\;\;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(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(2 \cdot \frac{1}{\sin t\_0}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 1.29999999999999999e-59Initial program 9.6%
Taylor expanded in x-scale around 0
Applied rewrites32.2%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites51.4%
Applied rewrites53.0%
if 1.29999999999999999e-59 < b Initial program 13.7%
Taylor expanded in x-scale around 0
Applied rewrites22.3%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f6457.2
Applied rewrites57.2%
Taylor expanded in angle around 0
Applied rewrites62.0%
Final simplification56.1%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= b 800000000.0)
(*
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}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 800000000:\\
\;\;\;\;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 < 8e8Initial program 10.6%
Taylor expanded in x-scale around 0
Applied rewrites32.7%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites51.2%
Applied rewrites52.7%
if 8e8 < b Initial program 12.0%
Taylor expanded in angle around 0
Applied rewrites13.4%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6454.3
Applied rewrites54.3%
Final simplification53.1%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= b 2e-43)
(*
180.0
(/
(atan (* 0.005555555555555556 (/ (* angle (* y-scale (PI))) x-scale)))
(PI)))
(*
180.0
(/
(atan
(*
-0.5
(*
(/ y-scale x-scale)
(* 2.0 (/ 1.0 (* 0.005555555555555556 (* angle (PI))))))))
(PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{-43}:\\
\;\;\;\;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)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \left(2 \cdot \frac{1}{0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)}\right)\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 2.00000000000000015e-43Initial program 9.8%
Taylor expanded in x-scale around 0
Applied rewrites31.7%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites51.5%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6441.9
Applied rewrites41.9%
if 2.00000000000000015e-43 < b Initial program 13.5%
Taylor expanded in x-scale around 0
Applied rewrites22.6%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f6457.6
Applied rewrites57.6%
Taylor expanded in angle around 0
Applied rewrites61.5%
Taylor expanded in angle around 0
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6452.5
Applied rewrites52.5%
Final simplification45.3%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= b 2e-43)
(*
180.0
(/
(atan (* 0.005555555555555556 (/ (* angle (* y-scale (PI))) x-scale)))
(PI)))
(*
180.0
(/
(atan (* -0.5 (* (/ y-scale x-scale) (/ 360.0 (* angle (PI))))))
(PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{-43}:\\
\;\;\;\;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)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-0.5 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{360}{angle \cdot \mathsf{PI}\left(\right)}\right)\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 2.00000000000000015e-43Initial program 9.8%
Taylor expanded in x-scale around 0
Applied rewrites31.7%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites51.5%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6441.9
Applied rewrites41.9%
if 2.00000000000000015e-43 < b Initial program 13.5%
Taylor expanded in x-scale around 0
Applied rewrites22.6%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f6457.6
Applied rewrites57.6%
Taylor expanded in angle around 0
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f6452.5
Applied rewrites52.5%
Final simplification45.3%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= b 2e-43)
(*
180.0
(/
(atan (* 0.005555555555555556 (/ (* angle (* y-scale (PI))) x-scale)))
(PI)))
(*
180.0
(/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{-43}:\\
\;\;\;\;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)}\\
\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.00000000000000015e-43Initial program 9.8%
Taylor expanded in x-scale around 0
Applied rewrites31.7%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites51.5%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6441.9
Applied rewrites41.9%
if 2.00000000000000015e-43 < b Initial program 13.5%
Taylor expanded in angle around 0
Applied rewrites13.6%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6452.5
Applied rewrites52.5%
Final simplification45.3%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* angle (* y-scale (PI)))))
(if (<= a_m 7.4e-274)
(* 180.0 (/ (atan (* -180.0 (/ x-scale t_0))) (PI)))
(* 180.0 (/ (atan (* 0.005555555555555556 (/ t_0 x-scale))) (PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := angle \cdot \left(y-scale \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;a\_m \leq 7.4 \cdot 10^{-274}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(-180 \cdot \frac{x-scale}{t\_0}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(0.005555555555555556 \cdot \frac{t\_0}{x-scale}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 7.39999999999999967e-274Initial program 11.6%
Taylor expanded in angle around 0
Applied rewrites11.2%
Taylor expanded in a around inf
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6415.0
Applied rewrites15.0%
if 7.39999999999999967e-274 < a Initial program 10.4%
Taylor expanded in x-scale around 0
Applied rewrites28.7%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites47.2%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6442.6
Applied rewrites42.6%
Final simplification28.2%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* 0.005555555555555556 (/ (* angle (* y-scale (PI))) x-scale))) (PI))))
\begin{array}{l}
a_m = \left|a\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 11.0%
Taylor expanded in x-scale around 0
Applied rewrites28.8%
Taylor expanded in a around inf
lower-/.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites46.6%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6437.6
Applied rewrites37.6%
Final simplification37.6%
herbie shell --seed 2025051
(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))))