
(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 9 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 (+ (pow (* (sin (/ (PI) (/ 180.0 angle))) b) 2.0) (* a a)))
\begin{array}{l}
\\
{\left(\sin \left(\frac{\mathsf{PI}\left(\right)}{\frac{180}{angle}}\right) \cdot b\right)}^{2} + a \cdot a
\end{array}
Initial program 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6477.9
Applied rewrites77.9%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6478.0
Applied rewrites78.0%
Final simplification78.0%
(FPCore (a b angle) :precision binary64 (if (<= b 7.2e-66) (* (pow (cos (* (* -0.005555555555555556 angle) (PI))) 2.0) (* a a)) (+ (pow (* (* (* 0.005555555555555556 angle) (PI)) b) 2.0) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.2 \cdot 10^{-66}:\\
\;\;\;\;{\cos \left(\left(-0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)}^{2} \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + a \cdot a\\
\end{array}
\end{array}
if b < 7.20000000000000025e-66Initial program 72.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6473.0
Applied rewrites73.0%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
div-invN/A
unpow-1N/A
lift-pow.f64N/A
*-commutativeN/A
frac-timesN/A
lift-pow.f64N/A
sqr-powN/A
associate-/r*N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites31.3%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites56.5%
if 7.20000000000000025e-66 < b Initial program 86.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
div-invN/A
unpow-1N/A
lift-pow.f64N/A
*-commutativeN/A
frac-timesN/A
lift-pow.f64N/A
sqr-powN/A
associate-/r*N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites48.3%
Taylor expanded in angle around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6483.9
Applied rewrites83.9%
Final simplification66.0%
(FPCore (a b angle) :precision binary64 (if (<= b 7.2e-66) (* (pow (cos (* (* (PI) angle) -0.005555555555555556)) 2.0) (* a a)) (+ (pow (* (* (* 0.005555555555555556 angle) (PI)) b) 2.0) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.2 \cdot 10^{-66}:\\
\;\;\;\;{\cos \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot -0.005555555555555556\right)}^{2} \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + a \cdot a\\
\end{array}
\end{array}
if b < 7.20000000000000025e-66Initial program 72.9%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites73.1%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6456.6
Applied rewrites56.6%
if 7.20000000000000025e-66 < b Initial program 86.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
div-invN/A
unpow-1N/A
lift-pow.f64N/A
*-commutativeN/A
frac-timesN/A
lift-pow.f64N/A
sqr-powN/A
associate-/r*N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites48.3%
Taylor expanded in angle around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6483.9
Applied rewrites83.9%
Final simplification66.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0) (* a a)))
\begin{array}{l}
\\
{\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + a \cdot a
\end{array}
Initial program 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6477.9
Applied rewrites77.9%
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f6478.0
lower-*.f64N/A
*-commutativeN/A
lift-*.f6478.0
Applied rewrites78.0%
Final simplification78.0%
(FPCore (a b angle) :precision binary64 (if (<= b 7.8e-66) (* a a) (+ (pow (* (* (* 0.005555555555555556 angle) (PI)) b) 2.0) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.8 \cdot 10^{-66}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + a \cdot a\\
\end{array}
\end{array}
if b < 7.79999999999999965e-66Initial program 72.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.1
Applied rewrites57.1%
if 7.79999999999999965e-66 < b Initial program 86.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
div-invN/A
unpow-1N/A
lift-pow.f64N/A
*-commutativeN/A
frac-timesN/A
lift-pow.f64N/A
sqr-powN/A
associate-/r*N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites48.3%
Taylor expanded in angle around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6483.9
Applied rewrites83.9%
Final simplification66.4%
(FPCore (a b angle) :precision binary64 (if (<= b 7.8e-66) (* a a) (+ (pow (* (* (* 0.005555555555555556 (PI)) angle) b) 2.0) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.8 \cdot 10^{-66}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2} + a \cdot a\\
\end{array}
\end{array}
if b < 7.79999999999999965e-66Initial program 72.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.1
Applied rewrites57.1%
if 7.79999999999999965e-66 < b Initial program 86.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6483.9
Applied rewrites83.9%
Final simplification66.4%
(FPCore (a b angle)
:precision binary64
(if (<= (/ angle 180.0) 2e-166)
(* a a)
(+
(* (* (* (* (PI) (PI)) b) b) (* (* angle angle) 3.08641975308642e-5))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle}{180} \leq 2 \cdot 10^{-166}:\\
\;\;\;\;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(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) + a \cdot a\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 2.00000000000000008e-166Initial program 83.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.0
Applied rewrites60.0%
if 2.00000000000000008e-166 < (/.f64 angle #s(literal 180 binary64)) Initial program 68.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6468.9
Applied rewrites68.9%
Taylor expanded in angle around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6458.8
Applied rewrites58.8%
Final simplification59.5%
(FPCore (a b angle)
:precision binary64
(if (<= b 7.8e-66)
(* a a)
(+
(* (* (* (PI) (PI)) b) (* (* (* 3.08641975308642e-5 angle) b) angle))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.8 \cdot 10^{-66}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot \left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot angle\right) \cdot b\right) \cdot angle\right) + a \cdot a\\
\end{array}
\end{array}
if b < 7.79999999999999965e-66Initial program 72.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.1
Applied rewrites57.1%
if 7.79999999999999965e-66 < b Initial program 86.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
Taylor expanded in angle around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6466.4
Applied rewrites66.4%
Applied rewrites81.8%
Applied rewrites84.0%
Final simplification66.4%
(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 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.9
Applied rewrites54.9%
herbie shell --seed 2024276
(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)))