
(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 95.9%
+-commutative95.9%
distribute-lft-in95.9%
associate-*r*99.9%
*-rgt-identity99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+195) (* x (+ (* y y) 1.0)) (* y (/ x (/ 1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+195) {
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+195) 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+195) {
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+195: 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+195) 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+195) 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+195], 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^{+195}:\\
\;\;\;\;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) < 4.9999999999999998e195Initial program 99.9%
if 4.9999999999999998e195 < (*.f64 y y) Initial program 88.9%
flip-+10.3%
associate-*r/10.3%
metadata-eval10.3%
pow210.3%
pow210.3%
pow-prod-up10.3%
metadata-eval10.3%
pow210.3%
Applied egg-rr10.3%
associate-/l*10.3%
Simplified10.3%
clear-num10.3%
add-sqr-sqrt10.3%
sqrt-div10.3%
metadata-eval10.3%
metadata-eval10.3%
metadata-eval10.3%
pow-prod-up10.3%
flip-+10.3%
metadata-eval10.3%
unpow210.3%
hypot-udef10.3%
sqrt-div10.3%
metadata-eval10.3%
metadata-eval10.3%
metadata-eval10.3%
pow-prod-up10.3%
Applied egg-rr89.8%
unpow289.8%
Simplified89.8%
Taylor expanded in y around inf 89.8%
*-un-lft-identity89.8%
unpow289.8%
times-frac99.8%
clear-num99.8%
/-rgt-identity99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (* x (+ (* y y) 1.0)))
double code(double x, double y) {
return x * ((y * y) + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * ((y * y) + 1.0d0)
end function
public static double code(double x, double y) {
return x * ((y * y) + 1.0);
}
def code(x, y): return x * ((y * y) + 1.0)
function code(x, y) return Float64(x * Float64(Float64(y * y) + 1.0)) end
function tmp = code(x, y) tmp = x * ((y * y) + 1.0); end
code[x_, y_] := N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y \cdot y + 1\right)
\end{array}
Initial program 95.9%
Final simplification95.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 95.9%
Taylor expanded in y around 0 53.0%
Final simplification53.0%
(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 2023313
(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))))