
(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 (* 0.005555555555555556 (* angle (PI)))))
(if (<= b_m 6.4e-52)
(* 180.0 (/ (atan (* (/ y-scale x-scale) (tan t_0))) (PI)))
(* 180.0 (/ (atan (/ (* (- y-scale) 1.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)\\
\mathbf{if}\;b\_m \leq 6.4 \cdot 10^{-52}:\\
\;\;\;\;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{\left(-y-scale\right) \cdot 1}{x-scale \cdot \sin t\_0}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 6.4000000000000002e-52Initial program 11.1%
Taylor expanded in x-scale around 0
Applied rewrites32.3%
Taylor expanded in a around inf
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6452.9
Applied rewrites52.9%
if 6.4000000000000002e-52 < b Initial program 15.4%
Taylor expanded in x-scale around 0
Applied rewrites28.8%
Taylor expanded in a around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
lower-/.f64N/A
Applied rewrites63.6%
Taylor expanded in angle around 0
Applied rewrites64.2%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
frac-timesN/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites65.4%
Final simplification56.7%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 6.4e-52)
(*
180.0
(/
(atan
(* (/ y-scale x-scale) (tan (* 0.005555555555555556 (* angle (PI))))))
(PI)))
(if (<= b_m 9.5e+89)
(*
180.0
(/
(atan
(*
(/ (- y-scale) x-scale)
(/
(fma
(* angle angle)
(- (* -0.002777777777777778 (PI)) (* -0.000925925925925926 (PI)))
(* 180.0 (/ 1.0 (PI))))
angle)))
(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 6.4 \cdot 10^{-52}:\\
\;\;\;\;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{elif}\;b\_m \leq 9.5 \cdot 10^{+89}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-y-scale}{x-scale} \cdot \frac{\mathsf{fma}\left(angle \cdot angle, -0.002777777777777778 \cdot \mathsf{PI}\left(\right) - -0.000925925925925926 \cdot \mathsf{PI}\left(\right), 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}\right)}{angle}\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 < 6.4000000000000002e-52Initial program 11.1%
Taylor expanded in x-scale around 0
Applied rewrites32.3%
Taylor expanded in a around inf
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6452.9
Applied rewrites52.9%
if 6.4000000000000002e-52 < b < 9.5000000000000003e89Initial program 35.0%
Taylor expanded in x-scale around 0
Applied rewrites62.8%
Taylor expanded in a around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
lower-/.f64N/A
Applied rewrites62.6%
Taylor expanded in angle around 0
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-PI.f6460.3
Applied rewrites60.3%
lift-PI.f64N/A
lift-pow.f64N/A
inv-powN/A
lower-/.f64N/A
lift-PI.f6460.3
Applied rewrites60.3%
if 9.5000000000000003e89 < b Initial program 4.1%
Taylor expanded in angle around 0
Applied rewrites4.2%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6459.2
Applied rewrites59.2%
Final simplification54.9%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (- (* -0.002777777777777778 (PI)) (* -0.000925925925925926 (PI))))
(t_1 (/ (- y-scale) x-scale)))
(if (<= b_m 6.2e-52)
(* 180.0 (/ (atan (* t_1 (* angle t_0))) (PI)))
(if (<= b_m 9.5e+89)
(*
180.0
(/
(atan
(* t_1 (/ (fma (* angle angle) t_0 (* 180.0 (/ 1.0 (PI)))) angle)))
(PI)))
(*
180.0
(/ (atan (* -180.0 (/ y-scale (* angle (* x-scale (PI)))))) (PI)))))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := -0.002777777777777778 \cdot \mathsf{PI}\left(\right) - -0.000925925925925926 \cdot \mathsf{PI}\left(\right)\\
t_1 := \frac{-y-scale}{x-scale}\\
\mathbf{if}\;b\_m \leq 6.2 \cdot 10^{-52}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(t\_1 \cdot \left(angle \cdot t\_0\right)\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;b\_m \leq 9.5 \cdot 10^{+89}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(t\_1 \cdot \frac{\mathsf{fma}\left(angle \cdot angle, t\_0, 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}\right)}{angle}\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 < 6.1999999999999998e-52Initial program 11.1%
Taylor expanded in x-scale around 0
Applied rewrites32.3%
Taylor expanded in a around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
lower-/.f64N/A
Applied rewrites35.9%
Taylor expanded in angle around 0
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-PI.f6434.8
Applied rewrites34.8%
Taylor expanded in angle around inf
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift--.f6441.4
Applied rewrites41.4%
if 6.1999999999999998e-52 < b < 9.5000000000000003e89Initial program 35.0%
Taylor expanded in x-scale around 0
Applied rewrites62.8%
Taylor expanded in a around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
lower-/.f64N/A
Applied rewrites62.6%
Taylor expanded in angle around 0
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-PI.f6460.3
Applied rewrites60.3%
lift-PI.f64N/A
lift-pow.f64N/A
inv-powN/A
lower-/.f64N/A
lift-PI.f6460.3
Applied rewrites60.3%
if 9.5000000000000003e89 < b Initial program 4.1%
Taylor expanded in angle around 0
Applied rewrites4.2%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6459.2
Applied rewrites59.2%
Final simplification47.0%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(if (<= b_m 7.5e+48)
(*
180.0
(/
(atan
(*
(/ (- y-scale) x-scale)
(*
angle
(- (* -0.002777777777777778 (PI)) (* -0.000925925925925926 (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 7.5 \cdot 10^{+48}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-y-scale}{x-scale} \cdot \left(angle \cdot \left(-0.002777777777777778 \cdot \mathsf{PI}\left(\right) - -0.000925925925925926 \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 < 7.5000000000000006e48Initial program 14.0%
Taylor expanded in x-scale around 0
Applied rewrites34.6%
Taylor expanded in a around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
lower-/.f64N/A
Applied rewrites37.8%
Taylor expanded in angle around 0
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-PI.f6436.8
Applied rewrites36.8%
Taylor expanded in angle around inf
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift--.f6440.0
Applied rewrites40.0%
if 7.5000000000000006e48 < b Initial program 7.1%
Taylor expanded in angle around 0
Applied rewrites7.2%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6459.8
Applied rewrites59.8%
Final simplification44.5%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ (- y-scale) x-scale) (/ 180.0 (* angle (PI))))) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
180 \cdot \frac{\tan^{-1} \left(\frac{-y-scale}{x-scale} \cdot \frac{180}{angle \cdot \mathsf{PI}\left(\right)}\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 12.4%
Taylor expanded in x-scale around 0
Applied rewrites31.2%
Taylor expanded in a around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
lift-/.f64N/A
lower-/.f64N/A
Applied rewrites44.4%
Taylor expanded in angle around 0
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f6439.2
Applied rewrites39.2%
Final simplification39.2%
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 12.4%
Taylor expanded in angle around 0
Applied rewrites8.6%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6438.1
Applied rewrites38.1%
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 12.4%
Taylor expanded in angle around 0
Applied rewrites8.6%
Taylor expanded in a around inf
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6412.0
Applied rewrites12.0%
herbie shell --seed 2025047
(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))))