
(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 73.7%
remove-double-neg73.7%
distribute-rgt-neg-out73.7%
distribute-frac-neg273.7%
neg-mul-173.7%
div-sub73.4%
distribute-lft-out--73.4%
neg-mul-173.4%
distribute-frac-neg273.4%
distribute-rgt-neg-out73.4%
remove-double-neg73.4%
cancel-sign-sub-inv73.4%
associate-/r*83.0%
associate-/r*83.0%
*-inverses83.0%
metadata-eval83.0%
metadata-eval83.0%
metadata-eval83.0%
metadata-eval83.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.62e-52) (not (<= y 4e+56))) (/ -0.5 x) (/ 0.5 y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.62e-52) || !(y <= 4e+56)) {
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 ((y <= (-1.62d-52)) .or. (.not. (y <= 4d+56))) 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 ((y <= -1.62e-52) || !(y <= 4e+56)) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.62e-52) or not (y <= 4e+56): tmp = -0.5 / x else: tmp = 0.5 / y return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.62e-52) || !(y <= 4e+56)) 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 ((y <= -1.62e-52) || ~((y <= 4e+56))) tmp = -0.5 / x; else tmp = 0.5 / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.62e-52], N[Not[LessEqual[y, 4e+56]], $MachinePrecision]], N[(-0.5 / x), $MachinePrecision], N[(0.5 / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.62 \cdot 10^{-52} \lor \neg \left(y \leq 4 \cdot 10^{+56}\right):\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{y}\\
\end{array}
\end{array}
if y < -1.61999999999999995e-52 or 4.00000000000000037e56 < y Initial program 70.5%
remove-double-neg70.5%
distribute-rgt-neg-out70.5%
distribute-frac-neg270.5%
neg-mul-170.5%
div-sub70.4%
distribute-lft-out--70.4%
neg-mul-170.4%
distribute-frac-neg270.4%
distribute-rgt-neg-out70.4%
remove-double-neg70.4%
cancel-sign-sub-inv70.4%
associate-/r*86.7%
associate-/r*86.7%
*-inverses86.7%
metadata-eval86.7%
metadata-eval86.7%
metadata-eval86.7%
metadata-eval86.7%
Simplified100.0%
Taylor expanded in y around inf 71.0%
if -1.61999999999999995e-52 < y < 4.00000000000000037e56Initial program 77.8%
remove-double-neg77.8%
distribute-rgt-neg-out77.8%
distribute-frac-neg277.8%
neg-mul-177.8%
div-sub77.2%
distribute-lft-out--77.2%
neg-mul-177.2%
distribute-frac-neg277.2%
distribute-rgt-neg-out77.2%
remove-double-neg77.2%
cancel-sign-sub-inv77.2%
associate-/r*78.4%
associate-/r*78.4%
*-inverses78.4%
metadata-eval78.4%
metadata-eval78.4%
metadata-eval78.4%
metadata-eval78.4%
Simplified100.0%
Taylor expanded in y around 0 85.3%
Final simplification77.3%
(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 73.7%
remove-double-neg73.7%
distribute-rgt-neg-out73.7%
distribute-frac-neg273.7%
neg-mul-173.7%
div-sub73.4%
distribute-lft-out--73.4%
neg-mul-173.4%
distribute-frac-neg273.4%
distribute-rgt-neg-out73.4%
remove-double-neg73.4%
cancel-sign-sub-inv73.4%
associate-/r*83.0%
associate-/r*83.0%
*-inverses83.0%
metadata-eval83.0%
metadata-eval83.0%
metadata-eval83.0%
metadata-eval83.0%
Simplified100.0%
Taylor expanded in y around inf 47.6%
(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 2024185
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, B"
:precision binary64
:alt
(! :herbie-platform default (- (/ 1/2 y) (/ 1/2 x)))
(/ (- x y) (* (* x 2.0) y)))