
(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 75.4%
remove-double-neg75.4%
distribute-rgt-neg-out75.4%
distribute-frac-neg275.4%
neg-mul-175.4%
div-sub74.8%
distribute-lft-out--74.8%
neg-mul-174.8%
distribute-frac-neg274.8%
distribute-rgt-neg-out74.8%
remove-double-neg74.8%
cancel-sign-sub-inv74.8%
associate-/r*80.7%
associate-/r*81.1%
*-inverses81.1%
metadata-eval81.1%
metadata-eval81.1%
*-lft-identity81.1%
distribute-rgt-neg-out81.1%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= y -4.2e-21)
(and (not (<= y 3e-97)) (or (<= y 2e-36) (not (<= y 0.00185)))))
(/ -0.5 x)
(/ 0.5 y)))
double code(double x, double y) {
double tmp;
if ((y <= -4.2e-21) || (!(y <= 3e-97) && ((y <= 2e-36) || !(y <= 0.00185)))) {
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 <= (-4.2d-21)) .or. (.not. (y <= 3d-97)) .and. (y <= 2d-36) .or. (.not. (y <= 0.00185d0))) 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 <= -4.2e-21) || (!(y <= 3e-97) && ((y <= 2e-36) || !(y <= 0.00185)))) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.2e-21) or (not (y <= 3e-97) and ((y <= 2e-36) or not (y <= 0.00185))): tmp = -0.5 / x else: tmp = 0.5 / y return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.2e-21) || (!(y <= 3e-97) && ((y <= 2e-36) || !(y <= 0.00185)))) 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 <= -4.2e-21) || (~((y <= 3e-97)) && ((y <= 2e-36) || ~((y <= 0.00185))))) tmp = -0.5 / x; else tmp = 0.5 / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.2e-21], And[N[Not[LessEqual[y, 3e-97]], $MachinePrecision], Or[LessEqual[y, 2e-36], N[Not[LessEqual[y, 0.00185]], $MachinePrecision]]]], N[(-0.5 / x), $MachinePrecision], N[(0.5 / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{-21} \lor \neg \left(y \leq 3 \cdot 10^{-97}\right) \land \left(y \leq 2 \cdot 10^{-36} \lor \neg \left(y \leq 0.00185\right)\right):\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{y}\\
\end{array}
\end{array}
if y < -4.20000000000000025e-21 or 3.00000000000000024e-97 < y < 1.9999999999999999e-36 or 0.0018500000000000001 < y Initial program 77.0%
remove-double-neg77.0%
distribute-rgt-neg-out77.0%
distribute-frac-neg277.0%
neg-mul-177.0%
div-sub76.9%
distribute-lft-out--76.9%
neg-mul-176.9%
distribute-frac-neg276.9%
distribute-rgt-neg-out76.9%
remove-double-neg76.9%
cancel-sign-sub-inv76.9%
associate-/r*86.6%
associate-/r*86.6%
*-inverses86.6%
metadata-eval86.6%
metadata-eval86.6%
*-lft-identity86.6%
distribute-rgt-neg-out86.6%
Simplified99.9%
Taylor expanded in y around inf 74.3%
if -4.20000000000000025e-21 < y < 3.00000000000000024e-97 or 1.9999999999999999e-36 < y < 0.0018500000000000001Initial program 73.4%
remove-double-neg73.4%
distribute-rgt-neg-out73.4%
distribute-frac-neg273.4%
neg-mul-173.4%
div-sub72.2%
distribute-lft-out--72.2%
neg-mul-172.2%
distribute-frac-neg272.2%
distribute-rgt-neg-out72.2%
remove-double-neg72.2%
cancel-sign-sub-inv72.2%
associate-/r*73.3%
associate-/r*74.1%
*-inverses74.1%
metadata-eval74.1%
metadata-eval74.1%
*-lft-identity74.1%
distribute-rgt-neg-out74.1%
Simplified100.0%
Taylor expanded in y around 0 84.1%
Final simplification78.6%
(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 75.4%
remove-double-neg75.4%
distribute-rgt-neg-out75.4%
distribute-frac-neg275.4%
neg-mul-175.4%
div-sub74.8%
distribute-lft-out--74.8%
neg-mul-174.8%
distribute-frac-neg274.8%
distribute-rgt-neg-out74.8%
remove-double-neg74.8%
cancel-sign-sub-inv74.8%
associate-/r*80.7%
associate-/r*81.1%
*-inverses81.1%
metadata-eval81.1%
metadata-eval81.1%
*-lft-identity81.1%
distribute-rgt-neg-out81.1%
Simplified100.0%
Taylor expanded in y around inf 48.3%
Final simplification48.3%
(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 2024039
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, B"
:precision binary64
:herbie-target
(- (/ 0.5 y) (/ 0.5 x))
(/ (- x y) (* (* x 2.0) y)))