
(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}
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (PI) (/ angle 180.0)))
(t_1 (cos t_0))
(t_2 (* (* (PI) angle) 0.005555555555555556))
(t_3 (cos t_2))
(t_4 (pow t_3 2.0))
(t_5 (sin t_0))
(t_6
(/
(/ (* (* (* (- (pow b 2.0) (pow a 2.0)) 2.0) t_5) t_1) x-scale)
y-scale))
(t_7
(/ (/ (+ (pow (* t_5 b) 2.0) (pow (* t_1 a) 2.0)) y-scale) y-scale))
(t_8
(/ (/ (+ (pow (* b t_1) 2.0) (pow (* t_5 a) 2.0)) x-scale) x-scale))
(t_9 (sin t_2)))
(if (<=
(/ (- (- t_7 t_8) (sqrt (+ (pow t_6 2.0) (pow (- t_8 t_7) 2.0)))) t_6)
INFINITY)
(*
(/
(atan
(*
(*
(/
(* (fma (* a a) (pow t_9 2.0) (* t_4 (* b b))) 2.0)
(* t_3 (* t_9 (- (* b b) (* a a)))))
(/ y-scale x-scale))
-0.5))
(PI))
180.0)
(/
1.0
(/
(PI)
(*
(atan (* (/ 0.5 t_9) (/ (* -2.0 (* (/ t_4 x-scale) y-scale)) t_3)))
180.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
t_1 := \cos t\_0\\
t_2 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_3 := \cos t\_2\\
t_4 := {t\_3}^{2}\\
t_5 := \sin t\_0\\
t_6 := \frac{\frac{\left(\left(\left({b}^{2} - {a}^{2}\right) \cdot 2\right) \cdot t\_5\right) \cdot t\_1}{x-scale}}{y-scale}\\
t_7 := \frac{\frac{{\left(t\_5 \cdot b\right)}^{2} + {\left(t\_1 \cdot a\right)}^{2}}{y-scale}}{y-scale}\\
t_8 := \frac{\frac{{\left(b \cdot t\_1\right)}^{2} + {\left(t\_5 \cdot a\right)}^{2}}{x-scale}}{x-scale}\\
t_9 := \sin t\_2\\
\mathbf{if}\;\frac{\left(t\_7 - t\_8\right) - \sqrt{{t\_6}^{2} + {\left(t\_8 - t\_7\right)}^{2}}}{t\_6} \leq \infty:\\
\;\;\;\;\frac{\tan^{-1} \left(\left(\frac{\mathsf{fma}\left(a \cdot a, {t\_9}^{2}, t\_4 \cdot \left(b \cdot b\right)\right) \cdot 2}{t\_3 \cdot \left(t\_9 \cdot \left(b \cdot b - a \cdot a\right)\right)} \cdot \frac{y-scale}{x-scale}\right) \cdot -0.5\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{PI}\left(\right)}{\tan^{-1} \left(\frac{0.5}{t\_9} \cdot \frac{-2 \cdot \left(\frac{t\_4}{x-scale} \cdot y-scale\right)}{t\_3}\right) \cdot 180}}\\
\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)) < +inf.0Initial program 51.2%
Taylor expanded in b around inf
Applied rewrites40.0%
Taylor expanded in x-scale around 0
lower-*.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites60.3%
if +inf.0 < (/.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 0.0%
Taylor expanded in b around inf
Applied rewrites25.4%
Taylor expanded in x-scale around 0
Applied rewrites50.0%
Applied rewrites50.0%
Final simplification52.7%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556))
(t_1 (/ 0.5 (sin t_0)))
(t_2 (sqrt (PI)))
(t_3 (cos t_0))
(t_4 (* -2.0 (* (/ (pow t_3 2.0) x-scale) y-scale))))
(if (<= x-scale 1e-181)
(/ 1.0 (/ (PI) (* (atan (* t_1 (/ t_4 t_3))) 180.0)))
(/
1.0
(/
(PI)
(*
(atan
(* (/ t_4 (cos (* (* (* t_2 t_2) angle) 0.005555555555555556))) t_1))
180.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \frac{0.5}{\sin t\_0}\\
t_2 := \sqrt{\mathsf{PI}\left(\right)}\\
t_3 := \cos t\_0\\
t_4 := -2 \cdot \left(\frac{{t\_3}^{2}}{x-scale} \cdot y-scale\right)\\
\mathbf{if}\;x-scale \leq 10^{-181}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{PI}\left(\right)}{\tan^{-1} \left(t\_1 \cdot \frac{t\_4}{t\_3}\right) \cdot 180}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{PI}\left(\right)}{\tan^{-1} \left(\frac{t\_4}{\cos \left(\left(\left(t\_2 \cdot t\_2\right) \cdot angle\right) \cdot 0.005555555555555556\right)} \cdot t\_1\right) \cdot 180}}\\
\end{array}
\end{array}
if x-scale < 1.00000000000000005e-181Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites38.7%
Taylor expanded in x-scale around 0
Applied rewrites55.1%
Applied rewrites55.1%
if 1.00000000000000005e-181 < x-scale Initial program 10.4%
Taylor expanded in b around inf
Applied rewrites16.7%
Taylor expanded in x-scale around 0
Applied rewrites41.5%
Applied rewrites41.5%
Applied rewrites46.8%
Final simplification51.5%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556))
(t_1 (sin t_0))
(t_2 (cos t_0))
(t_3 (pow t_2 2.0))
(t_4 (sqrt (PI))))
(if (<= x-scale 1e-181)
(/
1.0
(/
(PI)
(*
(atan (* (/ 0.5 t_1) (/ (* -2.0 (* (/ t_3 x-scale) y-scale)) t_2)))
180.0)))
(*
(/
(atan
(*
(/
(* (/ (* t_3 y-scale) x-scale) -2.0)
(* (cos (* (* (* t_4 t_4) angle) 0.005555555555555556)) t_1))
0.5))
(PI))
180.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
t_3 := {t\_2}^{2}\\
t_4 := \sqrt{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;x-scale \leq 10^{-181}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{PI}\left(\right)}{\tan^{-1} \left(\frac{0.5}{t\_1} \cdot \frac{-2 \cdot \left(\frac{t\_3}{x-scale} \cdot y-scale\right)}{t\_2}\right) \cdot 180}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\frac{t\_3 \cdot y-scale}{x-scale} \cdot -2}{\cos \left(\left(\left(t\_4 \cdot t\_4\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot t\_1} \cdot 0.5\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if x-scale < 1.00000000000000005e-181Initial program 15.3%
Taylor expanded in b around inf
Applied rewrites38.7%
Taylor expanded in x-scale around 0
Applied rewrites55.1%
Applied rewrites55.1%
if 1.00000000000000005e-181 < x-scale Initial program 10.4%
Taylor expanded in b around inf
Applied rewrites16.7%
Taylor expanded in x-scale around 0
Applied rewrites41.5%
Applied rewrites46.8%
Final simplification51.5%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556)) (t_1 (cos t_0)))
(/
1.0
(/
(PI)
(*
(atan
(*
(/ 0.5 (sin t_0))
(/ (* -2.0 (* (/ (pow t_1 2.0) x-scale) y-scale)) t_1)))
180.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \cos t\_0\\
\frac{1}{\frac{\mathsf{PI}\left(\right)}{\tan^{-1} \left(\frac{0.5}{\sin t\_0} \cdot \frac{-2 \cdot \left(\frac{{t\_1}^{2}}{x-scale} \cdot y-scale\right)}{t\_1}\right) \cdot 180}}
\end{array}
\end{array}
Initial program 13.2%
Taylor expanded in b around inf
Applied rewrites29.1%
Taylor expanded in x-scale around 0
Applied rewrites49.2%
Applied rewrites49.2%
Final simplification49.2%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (* (PI) angle) 0.005555555555555556)))
(*
(/ (atan (* (/ (- y-scale) x-scale) (/ (cos t_0) (sin t_0)))) (PI))
180.0)))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\\
\frac{\tan^{-1} \left(\frac{-y-scale}{x-scale} \cdot \frac{\cos t\_0}{\sin t\_0}\right)}{\mathsf{PI}\left(\right)} \cdot 180
\end{array}
\end{array}
Initial program 13.2%
Taylor expanded in b around inf
Applied rewrites29.1%
Taylor expanded in angle around 0
Applied rewrites29.2%
Taylor expanded in x-scale around 0
Applied rewrites49.2%
Final simplification49.2%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (/ (atan (* (/ (/ y-scale (* x-scale (PI))) angle) -180.0)) (PI)) 180.0))
\begin{array}{l}
\\
\frac{\tan^{-1} \left(\frac{\frac{y-scale}{x-scale \cdot \mathsf{PI}\left(\right)}}{angle} \cdot -180\right)}{\mathsf{PI}\left(\right)} \cdot 180
\end{array}
Initial program 13.2%
Taylor expanded in b around inf
Applied rewrites29.1%
Taylor expanded in angle around 0
Applied rewrites29.2%
Taylor expanded in angle around 0
Applied rewrites39.8%
Applied rewrites42.6%
Final simplification42.6%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (/ (atan (* (/ y-scale (* (* x-scale (PI)) angle)) -180.0)) (PI)) 180.0))
\begin{array}{l}
\\
\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)} \cdot 180
\end{array}
Initial program 13.2%
Taylor expanded in b around inf
Applied rewrites29.1%
Taylor expanded in angle around 0
Applied rewrites29.2%
Taylor expanded in angle around 0
Applied rewrites39.8%
Final simplification39.8%
herbie shell --seed 2024283
(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))))