
(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}
(FPCore (a b angle) :precision binary64 (+ (* (* (* 1.0 a) 1.0) a) (pow (* b (sin (* 0.005555555555555556 (/ (PI) (pow angle -1.0))))) 2.0)))
\begin{array}{l}
\\
\left(\left(1 \cdot a\right) \cdot 1\right) \cdot a + {\left(b \cdot \sin \left(0.005555555555555556 \cdot \frac{\mathsf{PI}\left(\right)}{{angle}^{-1}}\right)\right)}^{2}
\end{array}
Initial program 76.9%
Taylor expanded in angle around 0
Applied rewrites77.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
*-commutativeN/A
times-fracN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6477.3
Applied rewrites77.3%
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6477.3
lift-*.f64N/A
*-commutativeN/A
lift-*.f6477.3
Applied rewrites77.3%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6477.3
Applied rewrites77.3%
Final simplification77.3%
(FPCore (a b angle) :precision binary64 (fma (* (* a 1.0) a) 1.0 (pow (* (sin (/ (PI) (/ 180.0 angle))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(a \cdot 1\right) \cdot a, 1, {\left(\sin \left(\frac{\mathsf{PI}\left(\right)}{\frac{180}{angle}}\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 76.9%
Taylor expanded in angle around 0
Applied rewrites77.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
*-commutativeN/A
times-fracN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6477.3
Applied rewrites77.3%
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6477.3
lift-*.f64N/A
*-commutativeN/A
lift-*.f6477.3
Applied rewrites77.3%
lift-+.f64N/A
Applied rewrites77.3%
(FPCore (a b angle) :precision binary64 (+ (* (* (* 1.0 a) 1.0) a) (pow (* b (sin (* 0.005555555555555556 (* (PI) angle)))) 2.0)))
\begin{array}{l}
\\
\left(\left(1 \cdot a\right) \cdot 1\right) \cdot a + {\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 76.9%
Taylor expanded in angle around 0
Applied rewrites77.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
*-commutativeN/A
times-fracN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6477.3
Applied rewrites77.3%
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6477.3
lift-*.f64N/A
*-commutativeN/A
lift-*.f6477.3
Applied rewrites77.3%
lift-/.f64N/A
div-invN/A
lift-pow.f64N/A
unpow-1N/A
remove-double-divN/A
lower-*.f6477.3
Applied rewrites77.3%
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 a) 1.0) a (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot a\right) \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 76.9%
Taylor expanded in angle around 0
Applied rewrites77.2%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites77.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 3.5e-35)
(* a a)
(+
(* (* (* 1.0 a) 1.0) a)
(pow
(*
b
(*
(*
(PI)
(fma
(* -2.8577960676726107e-8 (* angle angle))
(* (PI) (PI))
0.005555555555555556))
angle))
2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-35}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(1 \cdot a\right) \cdot 1\right) \cdot a + {\left(b \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2.8577960676726107 \cdot 10^{-8} \cdot \left(angle \cdot angle\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 0.005555555555555556\right)\right) \cdot angle\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 3.49999999999999996e-35Initial program 76.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
if 3.49999999999999996e-35 < b Initial program 76.7%
Taylor expanded in angle around 0
Applied rewrites76.6%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
*-commutativeN/A
times-fracN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6476.7
Applied rewrites76.7%
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6476.7
lift-*.f64N/A
*-commutativeN/A
lift-*.f6476.7
Applied rewrites76.7%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites73.1%
(FPCore (a b angle)
:precision binary64
(if (<= b 3.5e-35)
(* a a)
(if (<= b 5.1e+167)
(fma
(* (* (* (* (PI) (PI)) 3.08641975308642e-5) b) b)
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-35}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 5.1 \cdot 10^{+167}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot b, angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 3.49999999999999996e-35Initial program 76.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
if 3.49999999999999996e-35 < b < 5.10000000000000004e167Initial program 62.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites32.4%
Taylor expanded in a around 0
Applied rewrites53.1%
if 5.10000000000000004e167 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites56.5%
Taylor expanded in a around 0
Applied rewrites68.5%
Applied rewrites88.1%
(FPCore (a b angle)
:precision binary64
(if (<= b 3.5e-35)
(* a a)
(fma
(* (* (* (* (PI) (PI)) 3.08641975308642e-5) b) b)
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-35}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot b, angle \cdot angle, a \cdot a\right)\\
\end{array}
\end{array}
if b < 3.49999999999999996e-35Initial program 76.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
if 3.49999999999999996e-35 < b Initial program 76.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites41.5%
Taylor expanded in a around 0
Applied rewrites58.9%
(FPCore (a b angle) :precision binary64 (if (<= b 1.5e+134) (* a a) (* (* (* (* angle angle) 3.08641975308642e-5) b) (* (* (PI) (PI)) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.5 \cdot 10^{+134}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(angle \cdot angle\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 < 1.49999999999999998e134Initial program 74.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.2
Applied rewrites61.2%
if 1.49999999999999998e134 < b Initial program 92.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites56.4%
Taylor expanded in a around 0
Applied rewrites62.5%
Applied rewrites65.6%
(FPCore (a b angle) :precision binary64 (if (<= b 1.5e+134) (* a a) (* (* (* angle angle) 3.08641975308642e-5) (* (* (* (PI) (PI)) b) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.5 \cdot 10^{+134}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\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 < 1.49999999999999998e134Initial program 74.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.2
Applied rewrites61.2%
if 1.49999999999999998e134 < b Initial program 92.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites56.4%
Taylor expanded in a around 0
Applied rewrites62.5%
(FPCore (a b angle) :precision binary64 (if (<= b 1.5e+134) (* a a) (* (* (PI) (PI)) (* (* b b) (* (* angle angle) 3.08641975308642e-5)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.5 \cdot 10^{+134}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(b \cdot b\right) \cdot \left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\right)\\
\end{array}
\end{array}
if b < 1.49999999999999998e134Initial program 74.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.2
Applied rewrites61.2%
if 1.49999999999999998e134 < b Initial program 92.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites56.4%
Taylor expanded in a around 0
Applied rewrites62.5%
Applied rewrites62.5%
(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 76.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6456.0
Applied rewrites56.0%
herbie shell --seed 2024309
(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)))