
(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 5 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 (fma (* x y) y x))
double code(double x, double y) {
return fma((x * y), y, x);
}
function code(x, y) return fma(Float64(x * y), y, x) end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, y, x\right)
\end{array}
Initial program 94.8%
+-commutative94.8%
distribute-lft-in94.8%
associate-*r*99.9%
*-rgt-identity99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 20.0) (* x (+ (* y y) 1.0)) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 20.0) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (x * 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) <= 20.0d0) then
tmp = x * ((y * y) + 1.0d0)
else
tmp = y * (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 20.0) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 20.0: tmp = x * ((y * y) + 1.0) else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 20.0) tmp = Float64(x * Float64(Float64(y * y) + 1.0)); else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 20.0) tmp = x * ((y * y) + 1.0); else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 20.0], N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 20:\\
\;\;\;\;x \cdot \left(y \cdot y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 20Initial program 100.0%
if 20 < (*.f64 y y) Initial program 90.2%
add-sqr-sqrt46.4%
sqrt-unprod39.8%
pow1/239.8%
pow239.8%
add-sqr-sqrt39.5%
pow-prod-down39.5%
pow-prod-up39.5%
*-commutative39.5%
sqrt-prod39.5%
hypot-1-def41.5%
metadata-eval41.5%
Applied egg-rr41.5%
unpow1/241.5%
metadata-eval41.5%
pow-sqr41.6%
exp-to-pow40.9%
exp-to-pow40.7%
rem-sqrt-square48.7%
exp-to-pow50.5%
unpow250.5%
fabs-sqr50.5%
unpow250.5%
Simplified50.5%
Taylor expanded in y around inf 50.5%
unpow250.5%
associate-*r*50.5%
*-commutative50.5%
associate-*r*50.5%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 4e+22) (* x (+ (* y y) 1.0)) (/ y (/ (/ 1.0 x) y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 4e+22) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y / ((1.0 / x) / 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) <= 4d+22) then
tmp = x * ((y * y) + 1.0d0)
else
tmp = y / ((1.0d0 / x) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 4e+22) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y / ((1.0 / x) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 4e+22: tmp = x * ((y * y) + 1.0) else: tmp = y / ((1.0 / x) / y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 4e+22) tmp = Float64(x * Float64(Float64(y * y) + 1.0)); else tmp = Float64(y / Float64(Float64(1.0 / x) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 4e+22) tmp = x * ((y * y) + 1.0); else tmp = y / ((1.0 / x) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 4e+22], N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(N[(1.0 / x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 4 \cdot 10^{+22}:\\
\;\;\;\;x \cdot \left(y \cdot y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{\frac{1}{x}}{y}}\\
\end{array}
\end{array}
if (*.f64 y y) < 4e22Initial program 100.0%
if 4e22 < (*.f64 y y) Initial program 90.0%
add-sqr-sqrt47.1%
sqrt-unprod40.4%
pow1/240.4%
pow240.4%
add-sqr-sqrt40.1%
pow-prod-down40.1%
pow-prod-up40.1%
*-commutative40.1%
sqrt-prod40.1%
hypot-1-def42.2%
metadata-eval42.2%
Applied egg-rr42.2%
unpow1/242.2%
metadata-eval42.2%
pow-sqr42.2%
exp-to-pow41.5%
exp-to-pow41.3%
rem-sqrt-square49.4%
exp-to-pow51.2%
unpow251.2%
fabs-sqr51.2%
unpow251.2%
Simplified51.2%
Taylor expanded in y around inf 51.2%
unpow251.2%
associate-*r*51.3%
*-commutative51.3%
associate-*r*51.3%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
*-commutative99.8%
associate-*r*90.0%
unpow290.0%
/-rgt-identity90.0%
associate-/r/90.0%
unpow290.0%
associate-/l*99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y 1.0) x (* y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x;
} else {
tmp = y * (x * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.0d0) then
tmp = x
else
tmp = y * (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x;
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = x else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = x; else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.0) tmp = x; else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], x, N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < 1Initial program 95.9%
Taylor expanded in y around 0 64.2%
if 1 < y Initial program 91.5%
add-sqr-sqrt45.6%
sqrt-unprod37.8%
pow1/237.8%
pow237.8%
add-sqr-sqrt37.4%
pow-prod-down37.4%
pow-prod-up37.3%
*-commutative37.3%
sqrt-prod37.3%
hypot-1-def40.1%
metadata-eval40.1%
Applied egg-rr40.1%
unpow1/240.1%
metadata-eval40.1%
pow-sqr40.1%
exp-to-pow39.0%
exp-to-pow38.8%
rem-sqrt-square47.3%
exp-to-pow49.7%
unpow249.7%
fabs-sqr49.7%
unpow249.7%
Simplified49.7%
Taylor expanded in y around inf 49.7%
unpow249.7%
associate-*r*49.8%
*-commutative49.8%
associate-*r*49.8%
add-sqr-sqrt98.6%
Applied egg-rr98.6%
Final simplification73.4%
(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 94.8%
Taylor expanded in y around 0 48.6%
Final simplification48.6%
(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 2024033
(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))))