
(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 3 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}
(FPCore (x y) :precision binary64 (+ (/ 0.5 y) (/ -0.5 x)))
double code(double x, double y) {
return (0.5 / y) + (-0.5 / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (0.5d0 / y) + ((-0.5d0) / x)
end function
public static double code(double x, double y) {
return (0.5 / y) + (-0.5 / x);
}
def code(x, y): return (0.5 / y) + (-0.5 / x)
function code(x, y) return Float64(Float64(0.5 / y) + Float64(-0.5 / x)) end
function tmp = code(x, y) tmp = (0.5 / y) + (-0.5 / x); end
code[x_, y_] := N[(N[(0.5 / y), $MachinePrecision] + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{y} + \frac{-0.5}{x}
\end{array}
Initial program 78.6%
Simplified0
(FPCore (x y)
:precision binary64
(if (<= x -2850000000000.0)
(/ 0.5 y)
(if (<= x -5.9e-64)
(/ -0.5 x)
(if (<= x -6.6e-103)
(/ 0.5 y)
(if (<= x 1.3e+16) (/ -0.5 x) (/ 0.5 y))))))
double code(double x, double y) {
double tmp;
if (x <= -2850000000000.0) {
tmp = 0.5 / y;
} else if (x <= -5.9e-64) {
tmp = -0.5 / x;
} else if (x <= -6.6e-103) {
tmp = 0.5 / y;
} else if (x <= 1.3e+16) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2850000000000.0d0)) then
tmp = 0.5d0 / y
else if (x <= (-5.9d-64)) then
tmp = (-0.5d0) / x
else if (x <= (-6.6d-103)) then
tmp = 0.5d0 / y
else if (x <= 1.3d+16) then
tmp = (-0.5d0) / x
else
tmp = 0.5d0 / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2850000000000.0) {
tmp = 0.5 / y;
} else if (x <= -5.9e-64) {
tmp = -0.5 / x;
} else if (x <= -6.6e-103) {
tmp = 0.5 / y;
} else if (x <= 1.3e+16) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2850000000000.0: tmp = 0.5 / y elif x <= -5.9e-64: tmp = -0.5 / x elif x <= -6.6e-103: tmp = 0.5 / y elif x <= 1.3e+16: tmp = -0.5 / x else: tmp = 0.5 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -2850000000000.0) tmp = Float64(0.5 / y); elseif (x <= -5.9e-64) tmp = Float64(-0.5 / x); elseif (x <= -6.6e-103) tmp = Float64(0.5 / y); elseif (x <= 1.3e+16) tmp = Float64(-0.5 / x); else tmp = Float64(0.5 / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2850000000000.0) tmp = 0.5 / y; elseif (x <= -5.9e-64) tmp = -0.5 / x; elseif (x <= -6.6e-103) tmp = 0.5 / y; elseif (x <= 1.3e+16) tmp = -0.5 / x; else tmp = 0.5 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2850000000000.0], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, -5.9e-64], N[(-0.5 / x), $MachinePrecision], If[LessEqual[x, -6.6e-103], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, 1.3e+16], N[(-0.5 / x), $MachinePrecision], N[(0.5 / y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2850000000000:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;x \leq -5.9 \cdot 10^{-64}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{elif}\;x \leq -6.6 \cdot 10^{-103}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{+16}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{y}\\
\end{array}
\end{array}
if x < -2.85e12 or -5.89999999999999995e-64 < x < -6.59999999999999979e-103 or 1.3e16 < x Initial program 79.6%
Simplified0
Taylor expanded in y around 0 0
Simplified0
if -2.85e12 < x < -5.89999999999999995e-64 or -6.59999999999999979e-103 < x < 1.3e16Initial program 77.3%
Simplified0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y) :precision binary64 (/ -0.5 x))
double code(double x, double y) {
return -0.5 / x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-0.5d0) / x
end function
public static double code(double x, double y) {
return -0.5 / x;
}
def code(x, y): return -0.5 / x
function code(x, y) return Float64(-0.5 / x) end
function tmp = code(x, y) tmp = -0.5 / x; end
code[x_, y_] := N[(-0.5 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5}{x}
\end{array}
Initial program 78.6%
Simplified0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y) :precision binary64 (- (/ 0.5 y) (/ 0.5 x)))
double code(double x, double y) {
return (0.5 / y) - (0.5 / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (0.5d0 / y) - (0.5d0 / x)
end function
public static double code(double x, double y) {
return (0.5 / y) - (0.5 / x);
}
def code(x, y): return (0.5 / y) - (0.5 / x)
function code(x, y) return Float64(Float64(0.5 / y) - Float64(0.5 / x)) end
function tmp = code(x, y) tmp = (0.5 / y) - (0.5 / x); end
code[x_, y_] := N[(N[(0.5 / y), $MachinePrecision] - N[(0.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{y} - \frac{0.5}{x}
\end{array}
herbie shell --seed 2024110
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, B"
:precision binary64
:alt
(- (/ 0.5 y) (/ 0.5 x))
(/ (- x y) (* (* x 2.0) y)))