
(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))))
(t_1 (sin t_0))
(t_2 (cos t_0)))
(if (<= b_m 3.6e+37)
(*
180.0
(/ (atan (* (* -2.0 (* (/ y-scale x-scale) (/ t_1 t_2))) -0.5)) (PI)))
(*
180.0
(/ (atan (* (* 2.0 (* (/ y-scale x-scale) (/ t_2 t_1))) -0.5)) (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 := \sin t\_0\\
t_2 := \cos t\_0\\
\mathbf{if}\;b\_m \leq 3.6 \cdot 10^{+37}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{t\_1}{t\_2}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{t\_2}{t\_1}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 3.59999999999999998e37Initial program 17.5%
Taylor expanded in b around inf
Applied rewrites27.2%
Taylor expanded in y-scale around inf
Applied rewrites28.2%
Taylor expanded in a around inf
Applied rewrites54.5%
if 3.59999999999999998e37 < b Initial program 11.3%
Taylor expanded in b around inf
Applied rewrites46.2%
Taylor expanded in y-scale around inf
Applied rewrites22.5%
Taylor expanded in a around 0
Applied rewrites73.7%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ angle 180.0) (PI)))
(t_1 (cos t_0))
(t_2 (* (* (PI) (+ b_m a)) (- b_m a)))
(t_3 (sin t_0))
(t_4
(/
(/ (* (* (* 2.0 (- (pow b_m 2.0) (pow a 2.0))) t_3) t_1) x-scale)
y-scale))
(t_5
(/ (/ (+ (pow (* a t_3) 2.0) (pow (* b_m t_1) 2.0)) x-scale) x-scale))
(t_6
(/
(/ (+ (pow (* a t_1) 2.0) (pow (* b_m t_3) 2.0)) y-scale)
y-scale)))
(if (<=
(/ (- (- t_6 t_5) (sqrt (+ (pow (- t_5 t_6) 2.0) (pow t_4 2.0)))) t_4)
-5e+77)
(*
180.0
(/
(atan
(*
(*
(/ x-scale angle)
(/
(fma
(* (* (/ b_m x-scale) (/ b_m x-scale)) (/ (* y-scale y-scale) t_2))
-2.0
(/ (* 2.0 (* a a)) t_2))
y-scale))
90.0))
(PI)))
(*
180.0
(/
(atan
(*
(* -180.0 (/ y-scale (* angle (* (* x-scale x-scale) (PI)))))
x-scale))
(PI))))))\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos t\_0\\
t_2 := \left(\mathsf{PI}\left(\right) \cdot \left(b\_m + a\right)\right) \cdot \left(b\_m - a\right)\\
t_3 := \sin t\_0\\
t_4 := \frac{\frac{\left(\left(2 \cdot \left({b\_m}^{2} - {a}^{2}\right)\right) \cdot t\_3\right) \cdot t\_1}{x-scale}}{y-scale}\\
t_5 := \frac{\frac{{\left(a \cdot t\_3\right)}^{2} + {\left(b\_m \cdot t\_1\right)}^{2}}{x-scale}}{x-scale}\\
t_6 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b\_m \cdot t\_3\right)}^{2}}{y-scale}}{y-scale}\\
\mathbf{if}\;\frac{\left(t\_6 - t\_5\right) - \sqrt{{\left(t\_5 - t\_6\right)}^{2} + {t\_4}^{2}}}{t\_4} \leq -5 \cdot 10^{+77}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(\frac{x-scale}{angle} \cdot \frac{\mathsf{fma}\left(\left(\frac{b\_m}{x-scale} \cdot \frac{b\_m}{x-scale}\right) \cdot \frac{y-scale \cdot y-scale}{t\_2}, -2, \frac{2 \cdot \left(a \cdot a\right)}{t\_2}\right)}{y-scale}\right) \cdot 90\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-180 \cdot \frac{y-scale}{angle \cdot \left(\left(x-scale \cdot x-scale\right) \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot x-scale\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (-.f64 (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) y-scale) y-scale) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) x-scale) x-scale)) (sqrt.f64 (+.f64 (pow.f64 (-.f64 (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) x-scale) x-scale) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) y-scale) y-scale)) #s(literal 2 binary64)) (pow.f64 (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale) #s(literal 2 binary64))))) (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale)) < -5.00000000000000004e77Initial program 54.2%
Taylor expanded in angle around 0
Applied rewrites29.8%
Taylor expanded in y-scale around 0
Applied rewrites46.9%
if -5.00000000000000004e77 < (/.f64 (-.f64 (-.f64 (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) y-scale) y-scale) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) x-scale) x-scale)) (sqrt.f64 (+.f64 (pow.f64 (-.f64 (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) x-scale) x-scale) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) y-scale) y-scale)) #s(literal 2 binary64)) (pow.f64 (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale) #s(literal 2 binary64))))) (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale)) Initial program 10.4%
Taylor expanded in angle around 0
Applied rewrites9.2%
Taylor expanded in x-scale around inf
Applied rewrites11.6%
Taylor expanded in a around 0
Applied rewrites47.6%
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 3.2e+94)
(*
180.0
(/
(atan (* (* -2.0 (* (/ y-scale x-scale) (/ (sin t_0) (cos t_0)))) -0.5))
(PI)))
(*
180.0
(/ (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.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 3.2 \cdot 10^{+94}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\left(-2 \cdot \left(\frac{y-scale}{x-scale} \cdot \frac{\sin t\_0}{\cos t\_0}\right)\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{\left(x-scale \cdot \mathsf{PI}\left(\right)\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if b < 3.20000000000000014e94Initial program 18.3%
Taylor expanded in b around inf
Applied rewrites27.9%
Taylor expanded in y-scale around inf
Applied rewrites29.7%
Taylor expanded in a around inf
Applied rewrites53.4%
if 3.20000000000000014e94 < b Initial program 5.0%
Taylor expanded in angle around 0
Applied rewrites5.2%
Taylor expanded in a around 0
Applied rewrites69.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 x-scale) (PI))))) x-scale))
(PI))))\begin{array}{l}
b_m = \left|b\right|
\\
180 \cdot \frac{\tan^{-1} \left(\left(-180 \cdot \frac{y-scale}{angle \cdot \left(\left(x-scale \cdot x-scale\right) \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot x-scale\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 16.2%
Taylor expanded in angle around 0
Applied rewrites12.0%
Taylor expanded in x-scale around inf
Applied rewrites13.4%
Taylor expanded in a around 0
Applied rewrites45.8%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.0)) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{\left(x-scale \cdot \mathsf{PI}\left(\right)\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 16.2%
Taylor expanded in angle around 0
Applied rewrites12.0%
Taylor expanded in a around 0
Applied rewrites41.9%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ x-scale (* y-scale (* (PI) angle))) -180.0)) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
180 \cdot \frac{\tan^{-1} \left(\frac{x-scale}{y-scale \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)} \cdot -180\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 16.2%
Taylor expanded in angle around 0
Applied rewrites12.0%
Taylor expanded in a around inf
Applied rewrites9.9%
Applied rewrites9.9%
b_m = (fabs.f64 b) (FPCore (a b_m angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ -180.0 (* angle (* y-scale (PI)))) x-scale)) (PI))))
\begin{array}{l}
b_m = \left|b\right|
\\
180 \cdot \frac{\tan^{-1} \left(\frac{-180}{angle \cdot \left(y-scale \cdot \mathsf{PI}\left(\right)\right)} \cdot x-scale\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 16.2%
Taylor expanded in angle around 0
Applied rewrites12.0%
Taylor expanded in x-scale around inf
Applied rewrites13.4%
Taylor expanded in a around inf
Applied rewrites9.9%
herbie shell --seed 2025019
(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))))