
(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}
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556)) (t_1 (cos t_0)))
(if (<= a_m 5.4e-54)
(* 180.0 (/ (atan (* (/ (- y-scale) x-scale) (/ t_1 (sin t_0)))) (PI)))
(*
180.0
(/
(atan
(*
(/ y-scale x-scale)
(/ (* 0.005555555555555556 (* angle (PI))) t_1)))
(PI))))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \cos t\_0\\
\mathbf{if}\;a\_m \leq 5.4 \cdot 10^{-54}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-y-scale}{x-scale} \cdot \frac{t\_1}{\sin t\_0}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \frac{0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)}{t\_1}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 5.40000000000000051e-54Initial program 15.2%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites27.8%
Taylor expanded in a around 0
Applied rewrites52.1%
if 5.40000000000000051e-54 < a Initial program 11.0%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites23.4%
Taylor expanded in a around inf
Applied rewrites63.3%
Taylor expanded in angle around 0
Applied rewrites64.4%
Final simplification56.2%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 3e-56)
(* 180.0 (/ (atan (* (/ y-scale (* (* (PI) x-scale) angle)) -180.0)) (PI)))
(*
180.0
(/
(atan
(*
(/ y-scale x-scale)
(/
(* 0.005555555555555556 (* angle (PI)))
(cos (* (* (PI) angle) 0.005555555555555556)))))
(PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 3 \cdot 10^{-56}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{\left(\mathsf{PI}\left(\right) \cdot x-scale\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \frac{0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)}{\cos \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right)}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 2.99999999999999989e-56Initial program 15.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites12.5%
Taylor expanded in a around 0
Applied rewrites43.0%
if 2.99999999999999989e-56 < a Initial program 11.0%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites23.4%
Taylor expanded in a around inf
Applied rewrites63.3%
Taylor expanded in angle around 0
Applied rewrites64.4%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 2.4e-55)
(* 180.0 (/ (atan (* (/ y-scale (* (* (PI) x-scale) angle)) -180.0)) (PI)))
(*
(/ -1.0 (PI))
(*
(atan
(* (tan (* (* (PI) angle) 0.005555555555555556)) (/ y-scale x-scale)))
-180.0))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 2.4 \cdot 10^{-55}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{\left(\mathsf{PI}\left(\right) \cdot x-scale\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\mathsf{PI}\left(\right)} \cdot \left(\tan^{-1} \left(\tan \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot \frac{y-scale}{x-scale}\right) \cdot -180\right)\\
\end{array}
\end{array}
if a < 2.39999999999999991e-55Initial program 15.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites12.5%
Taylor expanded in a around 0
Applied rewrites43.0%
if 2.39999999999999991e-55 < a Initial program 11.0%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites23.4%
Taylor expanded in a around inf
Applied rewrites63.3%
Applied rewrites62.9%
Applied rewrites63.4%
Final simplification49.8%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 2.4e-55)
(* 180.0 (/ (atan (* (/ y-scale (* (* (PI) x-scale) angle)) -180.0)) (PI)))
(*
(atan
(* (tan (* (* (PI) angle) 0.005555555555555556)) (/ y-scale x-scale)))
(/ 180.0 (PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 2.4 \cdot 10^{-55}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{\left(\mathsf{PI}\left(\right) \cdot x-scale\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\tan \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot \frac{y-scale}{x-scale}\right) \cdot \frac{180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 2.39999999999999991e-55Initial program 15.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites12.5%
Taylor expanded in a around 0
Applied rewrites43.0%
if 2.39999999999999991e-55 < a Initial program 11.0%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites23.4%
Taylor expanded in a around inf
Applied rewrites63.3%
Applied rewrites62.9%
Applied rewrites63.4%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= a_m 6.2e-54)
(* 180.0 (/ (atan (* (/ y-scale (* (* (PI) x-scale) angle)) -180.0)) (PI)))
(*
180.0
(/
(atan
(* (/ y-scale x-scale) (/ (* 0.005555555555555556 (* angle (PI))) 1.0)))
(PI)))))\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 6.2 \cdot 10^{-54}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{\left(\mathsf{PI}\left(\right) \cdot x-scale\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{x-scale} \cdot \frac{0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)}{1}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if a < 6.20000000000000008e-54Initial program 15.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites12.5%
Taylor expanded in a around 0
Applied rewrites43.0%
if 6.20000000000000008e-54 < a Initial program 11.0%
Taylor expanded in x-scale around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites23.4%
Taylor expanded in a around inf
Applied rewrites63.3%
Taylor expanded in angle around 0
Applied rewrites64.4%
Taylor expanded in angle around 0
Applied rewrites59.6%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* (/ y-scale (* (* (PI) x-scale) angle)) -180.0)) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(\frac{y-scale}{\left(\mathsf{PI}\left(\right) \cdot x-scale\right) \cdot angle} \cdot -180\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 13.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites10.5%
Taylor expanded in a around 0
Applied rewrites35.2%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* 180.0 (/ (atan (* x-scale (/ -180.0 (* (* (PI) y-scale) angle)))) (PI))))
\begin{array}{l}
a_m = \left|a\right|
\\
180 \cdot \frac{\tan^{-1} \left(x-scale \cdot \frac{-180}{\left(\mathsf{PI}\left(\right) \cdot y-scale\right) \cdot angle}\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 13.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites10.5%
Taylor expanded in a around inf
Applied rewrites11.8%
Applied rewrites11.8%
herbie shell --seed 2024318
(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))))