
(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 7 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) 5e+307) (* x (+ (* y y) 1.0)) (* y (/ x (/ 1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+307) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (x / (1.0 / 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+307) then
tmp = x * ((y * y) + 1.0d0)
else
tmp = y * (x / (1.0d0 / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+307) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (x / (1.0 / y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+307: tmp = x * ((y * y) + 1.0) else: tmp = y * (x / (1.0 / y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+307) tmp = Float64(x * Float64(Float64(y * y) + 1.0)); else tmp = Float64(y * Float64(x / Float64(1.0 / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e+307) tmp = x * ((y * y) + 1.0); else tmp = y * (x / (1.0 / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+307], N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+307}:\\
\;\;\;\;x \cdot \left(y \cdot y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{\frac{1}{y}}\\
\end{array}
\end{array}
if (*.f64 y y) < 5e307Initial program 99.9%
if 5e307 < (*.f64 y y) Initial program 77.2%
distribute-rgt-in77.2%
*-un-lft-identity77.2%
+-commutative77.2%
associate-*l*99.9%
Applied egg-rr99.9%
+-commutative99.9%
flip3-+3.6%
clear-num3.6%
clear-num3.6%
flip3-+99.8%
+-commutative99.8%
associate-*r*77.2%
*-commutative77.2%
fma-def77.2%
Applied egg-rr77.2%
Taylor expanded in y around inf 77.2%
*-commutative77.2%
associate-/r*77.2%
unpow277.2%
associate-/r*81.2%
Simplified81.2%
clear-num81.2%
*-un-lft-identity81.2%
div-inv81.2%
times-frac99.9%
clear-num99.9%
/-rgt-identity99.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 94.8%
distribute-rgt-in94.8%
*-un-lft-identity94.8%
+-commutative94.8%
associate-*l*99.9%
Applied egg-rr99.9%
*-commutative99.9%
fma-def99.9%
*-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 1e+124) (* x (+ (* y y) 1.0)) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1e+124) {
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) <= 1d+124) 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) <= 1e+124) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 1e+124: tmp = x * ((y * y) + 1.0) else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1e+124) 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) <= 1e+124) 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], 1e+124], 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 10^{+124}:\\
\;\;\;\;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) < 9.99999999999999948e123Initial program 99.9%
if 9.99999999999999948e123 < (*.f64 y y) Initial program 87.3%
distribute-rgt-in87.3%
*-un-lft-identity87.3%
+-commutative87.3%
associate-*l*99.8%
Applied egg-rr99.8%
+-commutative99.8%
flip3-+15.5%
clear-num15.4%
clear-num15.4%
flip3-+99.8%
+-commutative99.8%
associate-*r*87.2%
*-commutative87.2%
fma-def87.2%
Applied egg-rr87.2%
Taylor expanded in y around inf 87.2%
*-commutative87.2%
associate-/r*87.1%
unpow287.1%
associate-/r*89.4%
Simplified89.4%
clear-num89.5%
div-inv87.2%
associate-/l/87.2%
remove-double-div87.3%
associate-*l*99.8%
Applied egg-rr99.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 99.0%
if 1 < (*.f64 y y) Initial program 89.8%
Taylor expanded in y around inf 88.8%
unpow288.8%
Simplified88.8%
Final simplification93.7%
(FPCore (x y) :precision binary64 (if (<= (* y y) 0.002) x (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 0.002) {
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 * y) <= 0.002d0) 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 * y) <= 0.002) {
tmp = x;
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 0.002: tmp = x else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 0.002) tmp = x; else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 0.002) tmp = x; else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 0.002], x, N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 0.002:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 2e-3Initial program 100.0%
Taylor expanded in y around 0 99.0%
if 2e-3 < (*.f64 y y) Initial program 89.8%
distribute-rgt-in89.8%
*-un-lft-identity89.8%
+-commutative89.8%
associate-*l*99.7%
Applied egg-rr99.7%
+-commutative99.7%
flip3-+22.9%
clear-num22.9%
clear-num22.9%
flip3-+99.6%
+-commutative99.6%
associate-*r*89.7%
*-commutative89.7%
fma-def89.7%
Applied egg-rr89.7%
Taylor expanded in y around inf 88.7%
*-commutative88.7%
associate-/r*88.5%
unpow288.5%
associate-/r*90.3%
Simplified90.3%
clear-num90.5%
div-inv88.6%
associate-/l/88.7%
remove-double-div88.8%
associate-*l*98.7%
Applied egg-rr98.7%
Final simplification98.8%
(FPCore (x y) :precision binary64 (+ x (* y (* x y))))
double code(double x, double y) {
return x + (y * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (y * (x * y))
end function
public static double code(double x, double y) {
return x + (y * (x * y));
}
def code(x, y): return x + (y * (x * y))
function code(x, y) return Float64(x + Float64(y * Float64(x * y))) end
function tmp = code(x, y) tmp = x + (y * (x * y)); end
code[x_, y_] := N[(x + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x \cdot y\right)
\end{array}
Initial program 94.8%
distribute-rgt-in94.8%
*-un-lft-identity94.8%
+-commutative94.8%
associate-*l*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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 50.6%
Final simplification50.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 2023285
(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))))