
(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 12 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}
(FPCore (a b angle)
:precision binary64
(fma
(* a 1.0)
a
(pow
(*
b
(sin (* (/ angle (pow (PI) -0.5)) (* 0.005555555555555556 (sqrt (PI))))))
2.0)))\begin{array}{l}
\\
\mathsf{fma}\left(a \cdot 1, a, {\left(b \cdot \sin \left(\frac{angle}{{\mathsf{PI}\left(\right)}^{-0.5}} \cdot \left(0.005555555555555556 \cdot \sqrt{\mathsf{PI}\left(\right)}\right)\right)\right)}^{2}\right)
\end{array}
Initial program 78.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites78.8%
Taylor expanded in angle around 0
Applied rewrites79.0%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
associate-*l/N/A
associate-/l*N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-/l*N/A
lift-/.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-*.f64N/A
div-invN/A
times-fracN/A
lift-/.f64N/A
Applied rewrites79.0%
Final simplification79.0%
(FPCore (a b angle) :precision binary64 (fma (* a 1.0) a (pow (* (sin (* (* -0.005555555555555556 (PI)) (pow (/ -1.0 angle) -1.0))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(a \cdot 1, a, {\left(\sin \left(\left(-0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot {\left(\frac{-1}{angle}\right)}^{-1}\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 78.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites78.8%
Taylor expanded in angle around 0
Applied rewrites79.0%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
associate-*l/N/A
lift-/.f64N/A
clear-numN/A
frac-2negN/A
metadata-evalN/A
associate-/r/N/A
distribute-neg-frac2N/A
unpow-1N/A
times-fracN/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6479.0
Applied rewrites79.0%
Final simplification79.0%
(FPCore (a b angle) :precision binary64 (fma (* a 1.0) a (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(a \cdot 1, a, {\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 78.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites78.8%
Taylor expanded in angle around 0
Applied rewrites79.0%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
associate-*l/N/A
associate-/l*N/A
lift-PI.f64N/A
add-cube-cbrtN/A
unpow2N/A
associate-/l*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.0%
Final simplification79.0%
(FPCore (a b angle) :precision binary64 (fma (* a 1.0) a (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(a \cdot 1, a, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 78.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites78.8%
Taylor expanded in angle around 0
Applied rewrites79.0%
Final simplification79.0%
(FPCore (a b angle)
:precision binary64
(if (<= b 4.6e-15)
(* a a)
(fma
(* a 1.0)
a
(pow
(*
(*
(*
(fma
(* (* angle angle) -2.8577960676726107e-8)
(* (PI) (PI))
0.005555555555555556)
(PI))
angle)
b)
2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.6 \cdot 10^{-15}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 1, a, {\left(\left(\left(\mathsf{fma}\left(\left(angle \cdot angle\right) \cdot -2.8577960676726107 \cdot 10^{-8}, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if b < 4.59999999999999981e-15Initial program 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.5
Applied rewrites57.5%
if 4.59999999999999981e-15 < b Initial program 82.3%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites82.3%
Taylor expanded in angle around 0
Applied rewrites82.3%
Taylor expanded in angle around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites80.1%
Final simplification64.7%
(FPCore (a b angle) :precision binary64 (if (<= b 4.6e-15) (* a a) (fma (* a 1.0) a (pow (* (* (* 0.005555555555555556 (PI)) angle) b) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.6 \cdot 10^{-15}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 1, a, {\left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if b < 4.59999999999999981e-15Initial program 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.5
Applied rewrites57.5%
if 4.59999999999999981e-15 < b Initial program 82.3%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites82.3%
Taylor expanded in angle around 0
Applied rewrites82.3%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6480.3
Applied rewrites80.3%
Final simplification64.7%
(FPCore (a b angle)
:precision binary64
(if (<= a 7.5e+70)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 b) b (* (* -3.08641975308642e-5 a) a)))
angle
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.5 \cdot 10^{+70}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot b, b, \left(-3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot a\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 7.50000000000000031e70Initial program 76.8%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
pow2N/A
lower-pow.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
inv-powN/A
lower-pow.f6476.9
Applied rewrites76.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites44.9%
Applied rewrites49.6%
if 7.50000000000000031e70 < a Initial program 89.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.6
Applied rewrites87.6%
Final simplification55.5%
(FPCore (a b angle)
:precision binary64
(if (<= b 4.6e-15)
(* a a)
(fma
(* (* (* b b) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.6 \cdot 10^{-15}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, a \cdot a\right)\\
\end{array}
\end{array}
if b < 4.59999999999999981e-15Initial program 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.5
Applied rewrites57.5%
if 4.59999999999999981e-15 < b Initial program 82.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
pow2N/A
lower-pow.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
inv-powN/A
lower-pow.f6482.2
Applied rewrites82.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites39.8%
Taylor expanded in b around inf
Applied rewrites67.2%
Final simplification60.6%
(FPCore (a b angle)
:precision binary64
(if (<= b 4.6e-15)
(* a a)
(fma
(* (* (* 3.08641975308642e-5 (* (PI) (PI))) b) b)
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.6 \cdot 10^{-15}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot b\right) \cdot b, angle \cdot angle, a \cdot a\right)\\
\end{array}
\end{array}
if b < 4.59999999999999981e-15Initial program 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.5
Applied rewrites57.5%
if 4.59999999999999981e-15 < b Initial program 82.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
pow2N/A
lower-pow.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
inv-powN/A
lower-pow.f6482.2
Applied rewrites82.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites39.8%
Taylor expanded in b around inf
Applied rewrites67.2%
(FPCore (a b angle) :precision binary64 (if (<= b 3e+137) (* a a) (* (* (* (* (PI) (PI)) b) b) (* (* 3.08641975308642e-5 angle) angle))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3 \cdot 10^{+137}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot b\right) \cdot \left(\left(3.08641975308642 \cdot 10^{-5} \cdot angle\right) \cdot angle\right)\\
\end{array}
\end{array}
if b < 3.0000000000000001e137Initial program 75.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.3
Applied rewrites54.3%
if 3.0000000000000001e137 < b Initial program 94.0%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
pow2N/A
lower-pow.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
inv-powN/A
lower-pow.f6494.0
Applied rewrites94.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites41.8%
Taylor expanded in b around inf
Applied rewrites73.7%
Applied rewrites73.7%
Final simplification57.6%
(FPCore (a b angle) :precision binary64 (if (<= b 3e+137) (* a a) (* (* 3.08641975308642e-5 (* angle angle)) (* (* (* (PI) (PI)) b) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3 \cdot 10^{+137}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\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 < 3.0000000000000001e137Initial program 75.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.3
Applied rewrites54.3%
if 3.0000000000000001e137 < b Initial program 94.0%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*l*N/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
pow2N/A
lower-pow.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
inv-powN/A
lower-pow.f6494.0
Applied rewrites94.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites41.8%
Taylor expanded in b around inf
Applied rewrites73.7%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 78.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6451.9
Applied rewrites51.9%
herbie shell --seed 2024268
(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)))