
(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 5 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 (+ x (* y (* y x))))
double code(double x, double y) {
return x + (y * (y * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (y * (y * x))
end function
public static double code(double x, double y) {
return x + (y * (y * x));
}
def code(x, y): return x + (y * (y * x))
function code(x, y) return Float64(x + Float64(y * Float64(y * x))) end
function tmp = code(x, y) tmp = x + (y * (y * x)); end
code[x_, y_] := N[(x + N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(y \cdot x\right)
\end{array}
Initial program 95.9%
distribute-rgt-in95.9%
*-un-lft-identity95.9%
+-commutative95.9%
associate-*l*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 4e+16) (* x (+ (* y y) 1.0)) (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 4e+16) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (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) <= 4d+16) then
tmp = x * ((y * y) + 1.0d0)
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 4e+16) {
tmp = x * ((y * y) + 1.0);
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 4e+16: tmp = x * ((y * y) + 1.0) else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 4e+16) tmp = Float64(x * Float64(Float64(y * y) + 1.0)); else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 4e+16) tmp = x * ((y * y) + 1.0); else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 4e+16], N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 4 \cdot 10^{+16}:\\
\;\;\;\;x \cdot \left(y \cdot y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4e16Initial program 100.0%
if 4e16 < (*.f64 y y) Initial program 91.5%
distribute-rgt-in91.5%
*-un-lft-identity91.5%
flip-+18.3%
associate-*l*18.3%
associate-*l*18.3%
associate-*l*21.9%
Applied egg-rr21.9%
difference-of-squares22.0%
associate-*r*18.8%
distribute-rgt1-in18.8%
fma-udef18.8%
*-commutative18.8%
associate-/l*33.4%
*-inverses91.5%
associate-/l*91.4%
Simplified91.4%
Taylor expanded in y around inf 91.4%
unpow291.4%
Simplified91.4%
associate-/r/91.5%
/-rgt-identity91.5%
associate-*r*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e-17) x (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e-17) {
tmp = x;
} else {
tmp = y * (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) <= 5d-17) then
tmp = x
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 5e-17) {
tmp = x;
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e-17: tmp = x else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e-17) tmp = x; else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e-17) tmp = x; else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e-17], x, N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.9999999999999999e-17Initial program 100.0%
Taylor expanded in y around 0 100.0%
if 4.9999999999999999e-17 < (*.f64 y y) Initial program 91.8%
distribute-rgt-in91.8%
*-un-lft-identity91.8%
flip-+19.1%
associate-*l*19.1%
associate-*l*19.2%
associate-*l*22.6%
Applied egg-rr22.6%
difference-of-squares22.8%
associate-*r*19.8%
distribute-rgt1-in19.8%
fma-udef19.8%
*-commutative19.8%
associate-/l*35.2%
*-inverses91.8%
associate-/l*91.7%
Simplified91.7%
Taylor expanded in y around inf 90.6%
unpow290.6%
Simplified90.6%
associate-/r/90.6%
/-rgt-identity90.6%
associate-*r*98.7%
Applied egg-rr98.7%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (<= y 1.0) x (* x (* y y))))
double code(double x, double y) {
double tmp;
if (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 <= 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 <= 1.0) {
tmp = x;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = x else: tmp = x * (y * y) return tmp
function code(x, y) tmp = 0.0 if (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 <= 1.0) tmp = x; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], x, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 1Initial program 97.5%
Taylor expanded in y around 0 66.2%
if 1 < y Initial program 90.3%
Taylor expanded in y around inf 89.0%
unpow289.0%
Simplified89.0%
Final simplification71.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 95.9%
Taylor expanded in y around 0 52.2%
Final simplification52.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 2023282
(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))))