
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (cos (exp (- (log (* (PI) angle_m)) (log 180.0))))) 2.0) (pow (* b (sin (* (PI) (/ angle_m 180.0)))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \cos \left(e^{\log \left(\mathsf{PI}\left(\right) \cdot angle\_m\right) - \log 180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle\_m}{180}\right)\right)}^{2}
\end{array}
Initial program 77.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
inv-powN/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6438.1
Applied rewrites38.1%
rem-log-expN/A
lift-*.f64N/A
lift-log.f64N/A
exp-to-powN/A
unpow-1N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
clear-numN/A
log-divN/A
lower--.f64N/A
lower-log.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-log.f6438.1
Applied rewrites38.1%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (cos (exp (log (* (* 0.005555555555555556 angle_m) (PI)))))) 2.0) (pow (* b (sin (* (PI) (* angle_m 0.005555555555555556)))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \cos \left(e^{\log \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right)}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(angle\_m \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 77.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
inv-powN/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6438.1
Applied rewrites38.1%
rem-log-expN/A
lift-*.f64N/A
lift-log.f64N/A
exp-to-powN/A
unpow-1N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
clear-numN/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-log.f6438.1
lift-*.f64N/A
*-commutativeN/A
Applied rewrites38.1%
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6438.1
Applied rewrites38.1%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 1.65e-43)
(* (pow (cos (* -0.005555555555555556 (* (PI) angle_m))) 2.0) (* a a))
(if (<= b 1.4e+154)
(fma
(* (* (* 3.08641975308642e-5 (* b b)) (PI)) (PI))
(* angle_m angle_m)
(* a a))
(* (pow (* (* b (PI)) angle_m) 2.0) 3.08641975308642e-5))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.65 \cdot 10^{-43}:\\
\;\;\;\;{\cos \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\_m\right)\right)}^{2} \cdot \left(a \cdot a\right)\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle\_m \cdot angle\_m, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\_m\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 1.65000000000000008e-43Initial program 74.7%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6474.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6474.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6474.7
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval74.8
Applied rewrites74.8%
lift-pow.f64N/A
pow-to-expN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
lift-/.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-exp.f64N/A
Applied rewrites41.5%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6455.2
Applied rewrites55.2%
if 1.65000000000000008e-43 < b < 1.4e154Initial program 68.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites31.9%
Taylor expanded in a around 0
Applied rewrites59.7%
if 1.4e154 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.5%
Taylor expanded in a around 0
Applied rewrites58.5%
Applied rewrites82.4%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (fma (* 1.0 a) a (pow (* (sin (* (* 0.005555555555555556 angle_m) (PI))) b) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\mathsf{fma}\left(1 \cdot a, a, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 77.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
inv-powN/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6438.1
Applied rewrites38.1%
Applied rewrites77.3%
Taylor expanded in angle around 0
Applied rewrites77.4%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 9.5e-44)
(* a a)
(if (<= b 1.4e+154)
(fma
(* (* (* 3.08641975308642e-5 (* b b)) (PI)) (PI))
(* angle_m angle_m)
(* a a))
(* (pow (* (* b (PI)) angle_m) 2.0) 3.08641975308642e-5))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9.5 \cdot 10^{-44}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle\_m \cdot angle\_m, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\_m\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 9.49999999999999924e-44Initial program 74.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.2
Applied rewrites55.2%
if 9.49999999999999924e-44 < b < 1.4e154Initial program 68.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites31.9%
Taylor expanded in a around 0
Applied rewrites59.7%
if 1.4e154 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.5%
Taylor expanded in a around 0
Applied rewrites58.5%
Applied rewrites82.4%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(let* ((t_0 (* (* angle_m b) (PI))))
(if (<= a 3e-68)
(fma
(*
(*
(fma (* b b) 3.08641975308642e-5 (* (* a a) -3.08641975308642e-5))
angle_m)
angle_m)
(* (PI) (PI))
(* a a))
(if (<= a 8e+152)
(*
(fma
(* t_0 t_0)
(/ 3.08641975308642e-5 (* a a))
(fma (* (* (* angle_m angle_m) -3.08641975308642e-5) (PI)) (PI) 1.0))
(* a a))
(* a a)))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \left(angle\_m \cdot b\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;a \leq 3 \cdot 10^{-68}:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{fma}\left(b \cdot b, 3.08641975308642 \cdot 10^{-5}, \left(a \cdot a\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot angle\_m\right) \cdot angle\_m, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), a \cdot a\right)\\
\mathbf{elif}\;a \leq 8 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(t\_0 \cdot t\_0, \frac{3.08641975308642 \cdot 10^{-5}}{a \cdot a}, \mathsf{fma}\left(\left(\left(angle\_m \cdot angle\_m\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right), \mathsf{PI}\left(\right), 1\right)\right) \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 3e-68Initial program 74.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites41.2%
Applied rewrites44.7%
if 3e-68 < a < 8.0000000000000004e152Initial program 74.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.5%
Taylor expanded in a around 0
Applied rewrites18.6%
Taylor expanded in a around inf
Applied rewrites62.4%
if 8.0000000000000004e152 < a Initial program 97.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6497.9
Applied rewrites97.9%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= (/ angle_m 180.0) 8e-146)
(* a a)
(fma
(* (* (* 3.08641975308642e-5 (* b b)) (PI)) (PI))
(* angle_m angle_m)
(* a a))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle\_m}{180} \leq 8 \cdot 10^{-146}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle\_m \cdot angle\_m, a \cdot a\right)\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 8.00000000000000021e-146Initial program 80.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.6
Applied rewrites55.6%
if 8.00000000000000021e-146 < (/.f64 angle #s(literal 180 binary64)) Initial program 70.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites33.4%
Taylor expanded in a around 0
Applied rewrites59.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= b 6.6e+171) (* a a) (* (* (* (* (* angle_m angle_m) 3.08641975308642e-5) b) (* (PI) (PI))) b)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{+171}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle\_m \cdot angle\_m\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot b\\
\end{array}
\end{array}
if b < 6.59999999999999982e171Initial program 74.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.8
Applied rewrites54.8%
if 6.59999999999999982e171 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.1%
Taylor expanded in a around 0
Applied rewrites61.3%
Applied rewrites65.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= b 6.6e+171) (* a a) (* (* (* (* angle_m angle_m) 3.08641975308642e-5) b) (* (* (PI) (PI)) b))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{+171}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(angle\_m \cdot angle\_m\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)\\
\end{array}
\end{array}
if b < 6.59999999999999982e171Initial program 74.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.8
Applied rewrites54.8%
if 6.59999999999999982e171 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.1%
Taylor expanded in a around 0
Applied rewrites61.3%
Applied rewrites65.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= b 6.6e+171) (* a a) (* (* (* 3.08641975308642e-5 angle_m) angle_m) (* (* (* (PI) (PI)) b) b))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{+171}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(3.08641975308642 \cdot 10^{-5} \cdot angle\_m\right) \cdot angle\_m\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot b\right)\\
\end{array}
\end{array}
if b < 6.59999999999999982e171Initial program 74.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.8
Applied rewrites54.8%
if 6.59999999999999982e171 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.1%
Taylor expanded in a around 0
Applied rewrites61.3%
Applied rewrites61.3%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (* a a))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return a * a;
}
angle_m = abs(angle)
real(8) function code(a, b, angle_m)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle_m
code = a * a
end function
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return a * a;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return a * a
angle_m = abs(angle) function code(a, b, angle_m) return Float64(a * a) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = a * a; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
a \cdot a
\end{array}
Initial program 77.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6451.9
Applied rewrites51.9%
herbie shell --seed 2024322
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))