
(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+57) (fma x (* y y) x) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+57) {
tmp = fma(x, (y * y), x);
} else {
tmp = y * (x * y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+57) tmp = fma(x, Float64(y * y), x); else tmp = Float64(y * Float64(x * y)); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+57], N[(x * N[(y * y), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+57}:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.99999999999999972e57Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
fma-def100.0%
Simplified100.0%
if 4.99999999999999972e57 < (*.f64 y y) Initial program 85.4%
Taylor expanded in y around inf 85.4%
unpow285.4%
associate-*l*99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (/ 1.0 (/ (/ (/ 1.0 x) (hypot 1.0 y)) (hypot 1.0 y))))
double code(double x, double y) {
return 1.0 / (((1.0 / x) / hypot(1.0, y)) / hypot(1.0, y));
}
public static double code(double x, double y) {
return 1.0 / (((1.0 / x) / Math.hypot(1.0, y)) / Math.hypot(1.0, y));
}
def code(x, y): return 1.0 / (((1.0 / x) / math.hypot(1.0, y)) / math.hypot(1.0, y))
function code(x, y) return Float64(1.0 / Float64(Float64(Float64(1.0 / x) / hypot(1.0, y)) / hypot(1.0, y))) end
function tmp = code(x, y) tmp = 1.0 / (((1.0 / x) / hypot(1.0, y)) / hypot(1.0, y)); end
code[x_, y_] := N[(1.0 / N[(N[(N[(1.0 / x), $MachinePrecision] / N[Sqrt[1.0 ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[1.0 ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\frac{\frac{1}{x}}{\mathsf{hypot}\left(1, y\right)}}{\mathsf{hypot}\left(1, y\right)}}
\end{array}
Initial program 94.5%
+-commutative94.5%
distribute-lft-in94.5%
*-rgt-identity94.5%
Applied egg-rr94.5%
flip-+42.6%
clear-num42.5%
clear-num42.6%
flip-+94.3%
fma-def94.4%
Applied egg-rr94.4%
fma-udef94.3%
*-commutative94.3%
distribute-lft1-in94.3%
/-rgt-identity94.3%
associate-/r/94.3%
clear-num94.3%
add-sqr-sqrt46.6%
add-sqr-sqrt46.6%
times-frac46.6%
inv-pow46.6%
sqrt-pow146.7%
metadata-eval46.7%
+-commutative46.7%
hypot-1-def46.7%
inv-pow46.7%
sqrt-pow146.6%
metadata-eval46.6%
+-commutative46.6%
hypot-1-def48.8%
Applied egg-rr48.8%
associate-*l/48.8%
associate-*r/48.8%
pow-sqr99.7%
metadata-eval99.7%
unpow-199.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+57) (* x (+ 1.0 (* y y))) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+57) {
tmp = x * (1.0 + (y * y));
} 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+57) then
tmp = x * (1.0d0 + (y * y))
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+57) {
tmp = x * (1.0 + (y * y));
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+57: tmp = x * (1.0 + (y * y)) else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+57) tmp = Float64(x * Float64(1.0 + Float64(y * y))); else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e+57) tmp = x * (1.0 + (y * y)); else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+57], N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+57}:\\
\;\;\;\;x \cdot \left(1 + y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.99999999999999972e57Initial program 100.0%
if 4.99999999999999972e57 < (*.f64 y y) Initial program 85.4%
Taylor expanded in y around inf 85.4%
unpow285.4%
associate-*l*99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+57) (+ x (* x (* y y))) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+57) {
tmp = x + (x * (y * y));
} 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+57) then
tmp = x + (x * (y * y))
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+57) {
tmp = x + (x * (y * y));
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+57: tmp = x + (x * (y * y)) else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+57) tmp = Float64(x + Float64(x * Float64(y * y))); else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e+57) tmp = x + (x * (y * y)); else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+57], N[(x + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+57}:\\
\;\;\;\;x + x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.99999999999999972e57Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
if 4.99999999999999972e57 < (*.f64 y y) Initial program 85.4%
Taylor expanded in y around inf 85.4%
unpow285.4%
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.8%
if 1 < (*.f64 y y) Initial program 87.6%
Taylor expanded in y around inf 85.8%
unpow285.8%
*-commutative85.8%
Simplified85.8%
Final simplification93.0%
(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 98.8%
if 2e-3 < (*.f64 y y) Initial program 87.6%
Taylor expanded in y around inf 85.8%
unpow285.8%
associate-*l*98.0%
Simplified98.0%
Final simplification98.5%
(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.5%
Taylor expanded in y around 0 57.2%
Final simplification57.2%
(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 2023199
(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))))