
(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 4 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 93.3%
+-commutative93.3%
distribute-lft-in93.3%
associate-*r*99.9%
*-rgt-identity99.9%
fma-define99.9%
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 4e+232) (* x (+ (* y y) 1.0)) (* y (* x y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 4e+232) {
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) <= 4d+232) 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) <= 4e+232) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 4e+232: tmp = x * ((y * y) + 1.0) else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 4e+232) 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) <= 4e+232) 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], 4e+232], 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 4 \cdot 10^{+232}:\\
\;\;\;\;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) < 4.00000000000000023e232Initial program 99.9%
if 4.00000000000000023e232 < (*.f64 y y) Initial program 79.5%
add-sqr-sqrt46.5%
sqrt-unprod44.5%
pow1/244.5%
pow244.5%
add-sqr-sqrt44.4%
pow244.4%
pow-pow44.4%
*-commutative44.4%
sqrt-prod44.4%
hypot-1-def49.0%
metadata-eval49.0%
Applied egg-rr49.0%
unpow1/249.0%
Simplified49.0%
Taylor expanded in y around inf 49.0%
sqrt-pow161.2%
metadata-eval61.2%
unpow261.2%
swap-sqr46.6%
add-sqr-sqrt79.5%
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 96.5%
Taylor expanded in y around 0 69.7%
if 1 < y Initial program 83.9%
add-sqr-sqrt46.6%
sqrt-unprod36.9%
pow1/236.9%
pow236.9%
add-sqr-sqrt36.5%
pow236.5%
pow-pow36.5%
*-commutative36.5%
sqrt-prod36.5%
hypot-1-def40.9%
metadata-eval40.9%
Applied egg-rr40.9%
unpow1/240.9%
Simplified40.9%
Taylor expanded in y around inf 40.9%
sqrt-pow157.9%
metadata-eval57.9%
unpow257.9%
swap-sqr46.5%
add-sqr-sqrt82.8%
associate-*l*98.7%
Applied egg-rr98.7%
Final simplification77.0%
(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.3%
Taylor expanded in y around 0 53.3%
(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 2024130
(FPCore (x y)
:name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"
:precision binary64
:alt
(! :herbie-platform default (+ x (* (* x y) y)))
(* x (+ 1.0 (* y y))))