
(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 6 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) 2e+162) (* x (fma y y 1.0)) (* y (/ y (/ 1.0 x)))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e+162) {
tmp = x * fma(y, y, 1.0);
} else {
tmp = y * (y / (1.0 / x));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e+162) tmp = Float64(x * fma(y, y, 1.0)); else tmp = Float64(y * Float64(y / Float64(1.0 / x))); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e+162], N[(x * N[(y * y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(y / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{+162}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{y}{\frac{1}{x}}\\
\end{array}
\end{array}
if (*.f64 y y) < 1.9999999999999999e162Initial program 100.0%
sqr-neg100.0%
+-commutative100.0%
sqr-neg100.0%
fma-define100.0%
Simplified100.0%
if 1.9999999999999999e162 < (*.f64 y y) Initial program 80.2%
+-commutative80.2%
distribute-lft-in80.2%
associate-*r*99.9%
*-rgt-identity99.9%
fma-define99.9%
Applied egg-rr99.9%
fma-undefine99.9%
associate-*l*80.2%
unpow280.2%
*-un-lft-identity80.2%
*-commutative80.2%
distribute-lft-in80.2%
+-commutative80.2%
flip-+14.4%
metadata-eval14.4%
pow-sqr14.4%
metadata-eval14.4%
associate-/l*14.4%
*-commutative14.4%
clear-num14.4%
clear-num14.4%
*-commutative14.4%
associate-/l*14.4%
metadata-eval14.4%
metadata-eval14.4%
pow-sqr14.4%
Applied egg-rr80.2%
Taylor expanded in y around inf 80.2%
associate-/r*80.2%
Simplified80.2%
clear-num80.2%
unpow280.2%
associate-/l*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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 92.6%
+-commutative92.6%
distribute-lft-in92.6%
associate-*r*99.9%
*-rgt-identity99.9%
fma-define99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+113) (* x (+ (* y y) 1.0)) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+113) {
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) <= 5d+113) 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) <= 5e+113) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+113: tmp = x * ((y * y) + 1.0) else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+113) 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) <= 5e+113) 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], 5e+113], 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 5 \cdot 10^{+113}:\\
\;\;\;\;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) < 5e113Initial program 100.0%
if 5e113 < (*.f64 y y) Initial program 81.9%
*-commutative81.9%
add-sqr-sqrt45.8%
add-sqr-sqrt45.8%
pow245.8%
pow245.8%
unpow-prod-down45.7%
hypot-1-def55.5%
Applied egg-rr55.5%
Taylor expanded in y around inf 55.5%
unpow255.5%
swap-sqr45.8%
add-sqr-sqrt81.9%
associate-*r*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 2e+162) (* x (+ (* y y) 1.0)) (* y (/ y (/ 1.0 x)))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e+162) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (y / (1.0 / 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) <= 2d+162) then
tmp = x * ((y * y) + 1.0d0)
else
tmp = y * (y / (1.0d0 / x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 2e+162) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (y / (1.0 / x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 2e+162: tmp = x * ((y * y) + 1.0) else: tmp = y * (y / (1.0 / x)) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e+162) tmp = Float64(x * Float64(Float64(y * y) + 1.0)); else tmp = Float64(y * Float64(y / Float64(1.0 / x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 2e+162) tmp = x * ((y * y) + 1.0); else tmp = y * (y / (1.0 / x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e+162], N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(y / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{+162}:\\
\;\;\;\;x \cdot \left(y \cdot y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{y}{\frac{1}{x}}\\
\end{array}
\end{array}
if (*.f64 y y) < 1.9999999999999999e162Initial program 100.0%
if 1.9999999999999999e162 < (*.f64 y y) Initial program 80.2%
+-commutative80.2%
distribute-lft-in80.2%
associate-*r*99.9%
*-rgt-identity99.9%
fma-define99.9%
Applied egg-rr99.9%
fma-undefine99.9%
associate-*l*80.2%
unpow280.2%
*-un-lft-identity80.2%
*-commutative80.2%
distribute-lft-in80.2%
+-commutative80.2%
flip-+14.4%
metadata-eval14.4%
pow-sqr14.4%
metadata-eval14.4%
associate-/l*14.4%
*-commutative14.4%
clear-num14.4%
clear-num14.4%
*-commutative14.4%
associate-/l*14.4%
metadata-eval14.4%
metadata-eval14.4%
pow-sqr14.4%
Applied egg-rr80.2%
Taylor expanded in y around inf 80.2%
associate-/r*80.2%
Simplified80.2%
clear-num80.2%
unpow280.2%
associate-/l*99.9%
Applied egg-rr99.9%
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 93.5%
Taylor expanded in y around 0 66.8%
if 1 < y Initial program 89.4%
*-commutative89.4%
add-sqr-sqrt52.1%
add-sqr-sqrt52.1%
pow252.1%
pow252.1%
unpow-prod-down52.1%
hypot-1-def59.0%
Applied egg-rr59.0%
Taylor expanded in y around inf 59.0%
unpow259.0%
swap-sqr52.1%
add-sqr-sqrt89.4%
associate-*r*99.9%
Applied egg-rr99.9%
Final simplification73.8%
(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 92.6%
Taylor expanded in y around 0 53.6%
Final simplification53.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 2024047
(FPCore (x y)
:name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"
:precision binary64
:alt
(+ x (* (* x y) y))
(* x (+ 1.0 (* y y))))