
(FPCore (x y) :precision binary64 (/ (+ x y) (* (* x 2.0) y)))
double code(double x, double y) {
return (x + y) / ((x * 2.0) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / ((x * 2.0d0) * y)
end function
public static double code(double x, double y) {
return (x + y) / ((x * 2.0) * y);
}
def code(x, y): return (x + y) / ((x * 2.0) * y)
function code(x, y) return Float64(Float64(x + y) / Float64(Float64(x * 2.0) * y)) end
function tmp = code(x, y) tmp = (x + y) / ((x * 2.0) * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{\left(x \cdot 2\right) \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (+ x y) (* (* x 2.0) y)))
double code(double x, double y) {
return (x + y) / ((x * 2.0) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / ((x * 2.0d0) * y)
end function
public static double code(double x, double y) {
return (x + y) / ((x * 2.0) * y);
}
def code(x, y): return (x + y) / ((x * 2.0) * y)
function code(x, y) return Float64(Float64(x + y) / Float64(Float64(x * 2.0) * y)) end
function tmp = code(x, y) tmp = (x + y) / ((x * 2.0) * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{\left(x \cdot 2\right) \cdot y}
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 3.2e+134) (/ (fma 0.5 (/ y x) 0.5) y) (/ 0.5 x)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3.2e+134) {
tmp = fma(0.5, (y / x), 0.5) / y;
} else {
tmp = 0.5 / x;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3.2e+134) tmp = Float64(fma(0.5, Float64(y / x), 0.5) / y); else tmp = Float64(0.5 / x); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 3.2e+134], N[(N[(0.5 * N[(y / x), $MachinePrecision] + 0.5), $MachinePrecision] / y), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{+134}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if y < 3.2000000000000001e134Initial program 78.6%
Taylor expanded in y around 0
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6490.9
Simplified90.9%
if 3.2000000000000001e134 < y Initial program 65.9%
Taylor expanded in x around 0
/-lowering-/.f6484.9
Simplified84.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -6.2e+148) (/ 0.5 y) (if (<= x -2.8e-183) (/ (+ y x) (* y (* x 2.0))) (/ 0.5 x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -6.2e+148) {
tmp = 0.5 / y;
} else if (x <= -2.8e-183) {
tmp = (y + x) / (y * (x * 2.0));
} else {
tmp = 0.5 / x;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-6.2d+148)) then
tmp = 0.5d0 / y
else if (x <= (-2.8d-183)) then
tmp = (y + x) / (y * (x * 2.0d0))
else
tmp = 0.5d0 / x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -6.2e+148) {
tmp = 0.5 / y;
} else if (x <= -2.8e-183) {
tmp = (y + x) / (y * (x * 2.0));
} else {
tmp = 0.5 / x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -6.2e+148: tmp = 0.5 / y elif x <= -2.8e-183: tmp = (y + x) / (y * (x * 2.0)) else: tmp = 0.5 / x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -6.2e+148) tmp = Float64(0.5 / y); elseif (x <= -2.8e-183) tmp = Float64(Float64(y + x) / Float64(y * Float64(x * 2.0))); else tmp = Float64(0.5 / x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -6.2e+148)
tmp = 0.5 / y;
elseif (x <= -2.8e-183)
tmp = (y + x) / (y * (x * 2.0));
else
tmp = 0.5 / x;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -6.2e+148], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, -2.8e-183], N[(N[(y + x), $MachinePrecision] / N[(y * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+148}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;x \leq -2.8 \cdot 10^{-183}:\\
\;\;\;\;\frac{y + x}{y \cdot \left(x \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -6.19999999999999951e148Initial program 83.6%
Taylor expanded in x around inf
/-lowering-/.f6497.4
Simplified97.4%
if -6.19999999999999951e148 < x < -2.79999999999999985e-183Initial program 85.5%
if -2.79999999999999985e-183 < x Initial program 72.0%
Taylor expanded in x around 0
/-lowering-/.f6456.3
Simplified56.3%
Final simplification69.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -3.6e-21) (/ 0.5 y) (/ 0.5 x)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.6e-21) {
tmp = 0.5 / y;
} else {
tmp = 0.5 / x;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.6d-21)) then
tmp = 0.5d0 / y
else
tmp = 0.5d0 / x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -3.6e-21) {
tmp = 0.5 / y;
} else {
tmp = 0.5 / x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -3.6e-21: tmp = 0.5 / y else: tmp = 0.5 / x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -3.6e-21) tmp = Float64(0.5 / y); else tmp = Float64(0.5 / x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -3.6e-21)
tmp = 0.5 / y;
else
tmp = 0.5 / x;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -3.6e-21], N[(0.5 / y), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-21}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -3.59999999999999989e-21Initial program 84.5%
Taylor expanded in x around inf
/-lowering-/.f6477.7
Simplified77.7%
if -3.59999999999999989e-21 < x Initial program 74.1%
Taylor expanded in x around 0
/-lowering-/.f6458.5
Simplified58.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (/ 0.5 x))
assert(x < y);
double code(double x, double y) {
return 0.5 / x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 / x
end function
assert x < y;
public static double code(double x, double y) {
return 0.5 / x;
}
[x, y] = sort([x, y]) def code(x, y): return 0.5 / x
x, y = sort([x, y]) function code(x, y) return Float64(0.5 / x) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = 0.5 / x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(0.5 / x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{0.5}{x}
\end{array}
Initial program 77.2%
Taylor expanded in x around 0
/-lowering-/.f6448.4
Simplified48.4%
(FPCore (x y) :precision binary64 (+ (/ 0.5 x) (/ 0.5 y)))
double code(double x, double y) {
return (0.5 / x) + (0.5 / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (0.5d0 / x) + (0.5d0 / y)
end function
public static double code(double x, double y) {
return (0.5 / x) + (0.5 / y);
}
def code(x, y): return (0.5 / x) + (0.5 / y)
function code(x, y) return Float64(Float64(0.5 / x) + Float64(0.5 / y)) end
function tmp = code(x, y) tmp = (0.5 / x) + (0.5 / y); end
code[x_, y_] := N[(N[(0.5 / x), $MachinePrecision] + N[(0.5 / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{x} + \frac{0.5}{y}
\end{array}
herbie shell --seed 2024204
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, C"
:precision binary64
:alt
(! :herbie-platform default (+ (/ 1/2 x) (/ 1/2 y)))
(/ (+ x y) (* (* x 2.0) y)))