
(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) 3e+293) (+ x (* x (pow y 2.0))) (/ y (/ (/ 1.0 y) x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 3e+293) {
tmp = x + (x * pow(y, 2.0));
} else {
tmp = y / ((1.0 / 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) <= 3d+293) then
tmp = x + (x * (y ** 2.0d0))
else
tmp = y / ((1.0d0 / y) / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 3e+293) {
tmp = x + (x * Math.pow(y, 2.0));
} else {
tmp = y / ((1.0 / y) / x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 3e+293: tmp = x + (x * math.pow(y, 2.0)) else: tmp = y / ((1.0 / y) / x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 3e+293) tmp = Float64(x + Float64(x * (y ^ 2.0))); else tmp = Float64(y / Float64(Float64(1.0 / y) / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 3e+293) tmp = x + (x * (y ^ 2.0)); else tmp = y / ((1.0 / y) / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 3e+293], N[(x + N[(x * N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y / N[(N[(1.0 / y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 3 \cdot 10^{+293}:\\
\;\;\;\;x + x \cdot {y}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{\frac{1}{y}}{x}}\\
\end{array}
\end{array}
if (*.f64 y y) < 3.00000000000000013e293Initial program 99.9%
*-commutative99.9%
+-commutative99.9%
distribute-lft1-in99.9%
*-commutative99.9%
pow299.9%
Applied egg-rr99.9%
if 3.00000000000000013e293 < (*.f64 y y) Initial program 77.5%
flip-+2.7%
associate-*r/2.7%
associate-/l*2.7%
clear-num2.7%
flip-+77.5%
+-commutative77.5%
fma-def77.5%
Applied egg-rr77.5%
Taylor expanded in y around inf 77.5%
associate-/r/77.5%
unpow277.5%
associate-*r*99.8%
/-rgt-identity99.8%
Applied egg-rr99.8%
*-commutative99.8%
remove-double-div99.8%
div-inv99.8%
clear-num99.8%
un-div-inv99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (* (hypot 1.0 y) (* x (hypot 1.0 y))))
double code(double x, double y) {
return hypot(1.0, y) * (x * hypot(1.0, y));
}
public static double code(double x, double y) {
return Math.hypot(1.0, y) * (x * Math.hypot(1.0, y));
}
def code(x, y): return math.hypot(1.0, y) * (x * math.hypot(1.0, y))
function code(x, y) return Float64(hypot(1.0, y) * Float64(x * hypot(1.0, y))) end
function tmp = code(x, y) tmp = hypot(1.0, y) * (x * hypot(1.0, y)); end
code[x_, y_] := N[(N[Sqrt[1.0 ^ 2 + y ^ 2], $MachinePrecision] * N[(x * N[Sqrt[1.0 ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(1, y\right) \cdot \left(x \cdot \mathsf{hypot}\left(1, y\right)\right)
\end{array}
Initial program 93.0%
add-sqr-sqrt52.0%
pow252.0%
sqrt-prod52.0%
hypot-1-def56.7%
Applied egg-rr56.7%
*-commutative56.7%
Simplified56.7%
unpow256.7%
swap-sqr52.0%
unpow252.0%
hypot-1-def52.0%
unpow252.0%
+-commutative52.0%
unpow252.0%
fma-udef52.0%
pow252.0%
add-sqr-sqrt52.0%
add-sqr-sqrt93.0%
/-rgt-identity93.0%
*-commutative93.0%
add-sqr-sqrt93.0%
associate-*r*92.9%
/-rgt-identity92.9%
fma-udef92.9%
unpow292.9%
+-commutative92.9%
unpow292.9%
hypot-1-def92.9%
fma-udef92.9%
unpow292.9%
+-commutative92.9%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (<= (* y y) 3e+195) (* x (+ 1.0 (* y y))) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 3e+195) {
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) <= 3d+195) 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) <= 3e+195) {
tmp = x * (1.0 + (y * y));
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 3e+195: tmp = x * (1.0 + (y * y)) else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 3e+195) 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) <= 3e+195) 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], 3e+195], 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 3 \cdot 10^{+195}:\\
\;\;\;\;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) < 3.0000000000000001e195Initial program 99.9%
if 3.0000000000000001e195 < (*.f64 y y) Initial program 82.5%
flip-+11.6%
associate-*r/11.6%
associate-/l*11.6%
clear-num11.6%
flip-+82.5%
+-commutative82.5%
fma-def82.5%
Applied egg-rr82.5%
Taylor expanded in y around inf 82.5%
associate-/r/82.5%
unpow282.5%
associate-*r*99.8%
/-rgt-identity99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 3e+293) (* x (+ 1.0 (* y y))) (/ y (/ (/ 1.0 y) x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 3e+293) {
tmp = x * (1.0 + (y * y));
} else {
tmp = y / ((1.0 / 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) <= 3d+293) then
tmp = x * (1.0d0 + (y * y))
else
tmp = y / ((1.0d0 / y) / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 3e+293) {
tmp = x * (1.0 + (y * y));
} else {
tmp = y / ((1.0 / y) / x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 3e+293: tmp = x * (1.0 + (y * y)) else: tmp = y / ((1.0 / y) / x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 3e+293) tmp = Float64(x * Float64(1.0 + Float64(y * y))); else tmp = Float64(y / Float64(Float64(1.0 / y) / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 3e+293) tmp = x * (1.0 + (y * y)); else tmp = y / ((1.0 / y) / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 3e+293], N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y / N[(N[(1.0 / y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 3 \cdot 10^{+293}:\\
\;\;\;\;x \cdot \left(1 + y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{\frac{1}{y}}{x}}\\
\end{array}
\end{array}
if (*.f64 y y) < 3.00000000000000013e293Initial program 99.9%
if 3.00000000000000013e293 < (*.f64 y y) Initial program 77.5%
flip-+2.7%
associate-*r/2.7%
associate-/l*2.7%
clear-num2.7%
flip-+77.5%
+-commutative77.5%
fma-def77.5%
Applied egg-rr77.5%
Taylor expanded in y around inf 77.5%
associate-/r/77.5%
unpow277.5%
associate-*r*99.8%
/-rgt-identity99.8%
Applied egg-rr99.8%
*-commutative99.8%
remove-double-div99.8%
div-inv99.8%
clear-num99.8%
un-div-inv99.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 94.5%
Taylor expanded in y around 0 62.9%
if 1 < y Initial program 88.7%
flip-+32.2%
associate-*r/29.5%
associate-/l*32.2%
clear-num32.2%
flip-+88.7%
+-commutative88.7%
fma-def88.7%
Applied egg-rr88.7%
Taylor expanded in y around inf 87.0%
associate-/r/87.0%
unpow287.0%
associate-*r*98.0%
/-rgt-identity98.0%
Applied egg-rr98.0%
Final simplification72.1%
(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.0%
Taylor expanded in y around 0 47.6%
Final simplification47.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 2023326
(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))))