
(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
double code(double x, double y) {
return x * (1.0 + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (1.0d0 + (y * y))
end function
public static double code(double x, double y) {
return x * (1.0 + (y * y));
}
def code(x, y): return x * (1.0 + (y * y))
function code(x, y) return Float64(x * Float64(1.0 + Float64(y * y))) end
function tmp = code(x, y) tmp = x * (1.0 + (y * y)); end
code[x_, y_] := N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + y \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
double code(double x, double y) {
return x * (1.0 + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (1.0d0 + (y * y))
end function
public static double code(double x, double y) {
return x * (1.0 + (y * y));
}
def code(x, y): return x * (1.0 + (y * y))
function code(x, y) return Float64(x * Float64(1.0 + Float64(y * y))) end
function tmp = code(x, y) tmp = x * (1.0 + (y * y)); end
code[x_, y_] := N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + y \cdot y\right)
\end{array}
(FPCore (x y) :precision binary64 (if (<= (* y y) 1000000000000.0) (fma x (* y y) x) (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1000000000000.0) {
tmp = fma(x, (y * y), x);
} else {
tmp = y * (y * x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1000000000000.0) tmp = fma(x, Float64(y * y), x); else tmp = Float64(y * Float64(y * x)); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1000000000000.0], N[(x * N[(y * y), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 1000000000000:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 1e12Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
fma-def100.0%
Simplified100.0%
if 1e12 < (*.f64 y y) Initial program 87.2%
Taylor expanded in y around inf 87.2%
unpow287.2%
associate-*l*99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (cbrt (* y x)))) (fma (* y (* (* (cbrt x) t_0) (cbrt y))) t_0 x)))
double code(double x, double y) {
double t_0 = cbrt((y * x));
return fma((y * ((cbrt(x) * t_0) * cbrt(y))), t_0, x);
}
function code(x, y) t_0 = cbrt(Float64(y * x)) return fma(Float64(y * Float64(Float64(cbrt(x) * t_0) * cbrt(y))), t_0, x) end
code[x_, y_] := Block[{t$95$0 = N[Power[N[(y * x), $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[(y * N[(N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0), $MachinePrecision] * N[Power[y, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{y \cdot x}\\
\mathsf{fma}\left(y \cdot \left(\left(\sqrt[3]{x} \cdot t_0\right) \cdot \sqrt[3]{y}\right), t_0, x\right)
\end{array}
\end{array}
Initial program 93.6%
+-commutative93.6%
distribute-lft-in93.6%
*-rgt-identity93.6%
Applied egg-rr93.6%
*-commutative93.6%
associate-*r*99.9%
add-cube-cbrt99.4%
associate-*r*99.4%
fma-def99.4%
pow299.4%
*-commutative99.4%
*-commutative99.4%
Applied egg-rr99.4%
unpow299.4%
cbrt-prod99.5%
associate-*r*99.5%
*-commutative99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (cbrt (* y x)))) (fma (* y (pow t_0 2.0)) t_0 x)))
double code(double x, double y) {
double t_0 = cbrt((y * x));
return fma((y * pow(t_0, 2.0)), t_0, x);
}
function code(x, y) t_0 = cbrt(Float64(y * x)) return fma(Float64(y * (t_0 ^ 2.0)), t_0, x) end
code[x_, y_] := Block[{t$95$0 = N[Power[N[(y * x), $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[(y * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] * t$95$0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{y \cdot x}\\
\mathsf{fma}\left(y \cdot {t_0}^{2}, t_0, x\right)
\end{array}
\end{array}
Initial program 93.6%
+-commutative93.6%
distribute-lft-in93.6%
*-rgt-identity93.6%
Applied egg-rr93.6%
*-commutative93.6%
associate-*r*99.9%
add-cube-cbrt99.4%
associate-*r*99.4%
fma-def99.4%
pow299.4%
*-commutative99.4%
*-commutative99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (<= (* y y) 1000000000000.0) (* x (+ (* y y) 1.0)) (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1000000000000.0) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (y * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 1000000000000.0d0) then
tmp = x * ((y * y) + 1.0d0)
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 1000000000000.0) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 1000000000000.0: tmp = x * ((y * y) + 1.0) else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1000000000000.0) tmp = Float64(x * Float64(Float64(y * y) + 1.0)); else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 1000000000000.0) tmp = x * ((y * y) + 1.0); else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1000000000000.0], N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 1000000000000:\\
\;\;\;\;x \cdot \left(y \cdot y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 1e12Initial program 100.0%
if 1e12 < (*.f64 y y) Initial program 87.2%
Taylor expanded in y around inf 87.2%
unpow287.2%
associate-*l*99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 1000000000000.0) (+ x (* x (* y y))) (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1000000000000.0) {
tmp = x + (x * (y * y));
} else {
tmp = y * (y * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 1000000000000.0d0) then
tmp = x + (x * (y * y))
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 1000000000000.0) {
tmp = x + (x * (y * y));
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 1000000000000.0: tmp = x + (x * (y * y)) else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1000000000000.0) tmp = Float64(x + Float64(x * Float64(y * y))); else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 1000000000000.0) tmp = x + (x * (y * y)); else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1000000000000.0], N[(x + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 1000000000000:\\
\;\;\;\;x + x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 1e12Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
if 1e12 < (*.f64 y y) Initial program 87.2%
Taylor expanded in y around inf 87.2%
unpow287.2%
associate-*l*99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 1.0) x (* x (* y y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1.0) {
tmp = x;
} else {
tmp = x * (y * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 1.0d0) then
tmp = x
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 1.0) {
tmp = x;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 1.0: tmp = x else: tmp = x * (y * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1.0) tmp = x; else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 1.0) tmp = x; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1.0], x, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 1Initial program 100.0%
Taylor expanded in y around 0 98.2%
if 1 < (*.f64 y y) Initial program 87.5%
Taylor expanded in y around inf 86.8%
unpow286.8%
*-commutative86.8%
Simplified86.8%
Final simplification92.4%
(FPCore (x y) :precision binary64 (if (<= (* y y) 0.005) x (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 0.005) {
tmp = x;
} else {
tmp = y * (y * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 0.005d0) then
tmp = x
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 0.005) {
tmp = x;
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 0.005: tmp = x else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 0.005) tmp = x; else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 0.005) tmp = x; else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 0.005], x, N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 0.005:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0 98.2%
if 0.0050000000000000001 < (*.f64 y y) Initial program 87.5%
Taylor expanded in y around inf 86.8%
unpow286.8%
associate-*l*99.1%
Simplified99.1%
Final simplification98.6%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 93.6%
Taylor expanded in y around 0 50.8%
Final simplification50.8%
(FPCore (x y) :precision binary64 (+ x (* (* x y) y)))
double code(double x, double y) {
return x + ((x * y) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((x * y) * y)
end function
public static double code(double x, double y) {
return x + ((x * y) * y);
}
def code(x, y): return x + ((x * y) * y)
function code(x, y) return Float64(x + Float64(Float64(x * y) * y)) end
function tmp = code(x, y) tmp = x + ((x * y) * y); end
code[x_, y_] := N[(x + N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x \cdot y\right) \cdot y
\end{array}
herbie shell --seed 2023200
(FPCore (x y)
:name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"
:precision binary64
:herbie-target
(+ x (* (* x y) y))
(* x (+ 1.0 (* y y))))