
(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) 5e+22) (fma x (* y y) x) (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+22) {
tmp = fma(x, (y * y), x);
} else {
tmp = y * (y * x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+22) tmp = fma(x, Float64(y * y), x); else tmp = Float64(y * Float64(y * x)); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+22], N[(x * N[(y * y), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+22}:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.9999999999999996e22Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
fma-def100.0%
Simplified100.0%
if 4.9999999999999996e22 < (*.f64 y y) Initial program 81.1%
Taylor expanded in y around inf 81.1%
unpow281.1%
associate-*l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ 1.0 (hypot 1.0 y)))) (* (/ 1.0 t_0) (/ x t_0))))
double code(double x, double y) {
double t_0 = 1.0 / hypot(1.0, y);
return (1.0 / t_0) * (x / t_0);
}
public static double code(double x, double y) {
double t_0 = 1.0 / Math.hypot(1.0, y);
return (1.0 / t_0) * (x / t_0);
}
def code(x, y): t_0 = 1.0 / math.hypot(1.0, y) return (1.0 / t_0) * (x / t_0)
function code(x, y) t_0 = Float64(1.0 / hypot(1.0, y)) return Float64(Float64(1.0 / t_0) * Float64(x / t_0)) end
function tmp = code(x, y) t_0 = 1.0 / hypot(1.0, y); tmp = (1.0 / t_0) * (x / t_0); end
code[x_, y_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[1.0 ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(1, y\right)}\\
\frac{1}{t_0} \cdot \frac{x}{t_0}
\end{array}
\end{array}
Initial program 90.8%
+-commutative90.8%
distribute-lft-in90.8%
*-rgt-identity90.8%
Applied egg-rr90.8%
*-commutative90.8%
distribute-lft1-in90.8%
fma-udef90.7%
*-commutative90.7%
/-rgt-identity90.7%
associate-/r/90.7%
*-un-lft-identity90.7%
add-sqr-sqrt90.7%
times-frac90.7%
clear-num90.7%
sqrt-div90.7%
metadata-eval90.7%
clear-num90.7%
remove-double-div90.7%
fma-udef90.7%
+-commutative90.7%
hypot-1-def90.7%
clear-num90.7%
sqrt-div90.7%
metadata-eval90.7%
clear-num90.7%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+22) (* x (+ 1.0 (* y y))) (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+22) {
tmp = x * (1.0 + (y * y));
} 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+22) then
tmp = x * (1.0d0 + (y * y))
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+22) {
tmp = x * (1.0 + (y * y));
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+22: tmp = x * (1.0 + (y * y)) else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+22) tmp = Float64(x * Float64(1.0 + Float64(y * y))); else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e+22) tmp = x * (1.0 + (y * y)); else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+22], N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+22}:\\
\;\;\;\;x \cdot \left(1 + y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.9999999999999996e22Initial program 100.0%
if 4.9999999999999996e22 < (*.f64 y y) Initial program 81.1%
Taylor expanded in y around inf 81.1%
unpow281.1%
associate-*l*99.9%
Simplified99.9%
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.0%
if 1 < (*.f64 y y) Initial program 81.9%
Taylor expanded in y around inf 81.0%
unpow281.0%
*-commutative81.0%
Simplified81.0%
Final simplification89.3%
(FPCore (x y) :precision binary64 (if (<= (* y y) 0.2) x (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 0.2) {
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) <= 0.2d0) 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) <= 0.2) {
tmp = x;
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 0.2: tmp = x else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 0.2) 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) <= 0.2) tmp = x; else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 0.2], x, N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 0.2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 0.20000000000000001Initial program 100.0%
Taylor expanded in y around 0 98.0%
if 0.20000000000000001 < (*.f64 y y) Initial program 81.9%
Taylor expanded in y around inf 81.0%
unpow281.0%
associate-*l*98.9%
Simplified98.9%
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 90.8%
Taylor expanded in y around 0 50.4%
Final simplification50.4%
(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 2023214
(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))))