
(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 79.8%
remove-double-neg79.8%
distribute-rgt-neg-out79.8%
distribute-frac-neg279.8%
neg-mul-179.8%
div-sub79.3%
distribute-lft-out--79.3%
neg-mul-179.3%
distribute-frac-neg279.3%
distribute-rgt-neg-out79.3%
remove-double-neg79.3%
cancel-sign-sub-inv79.3%
associate-/r*85.5%
associate-/r*85.5%
*-inverses85.5%
metadata-eval85.5%
metadata-eval85.5%
*-lft-identity85.5%
distribute-rgt-neg-out85.5%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -2.9e-42) (not (<= x 9.6e-43))) (/ 0.5 y) (/ -0.5 x)))
double code(double x, double y) {
double tmp;
if ((x <= -2.9e-42) || !(x <= 9.6e-43)) {
tmp = 0.5 / y;
} else {
tmp = -0.5 / x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-2.9d-42)) .or. (.not. (x <= 9.6d-43))) then
tmp = 0.5d0 / y
else
tmp = (-0.5d0) / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.9e-42) || !(x <= 9.6e-43)) {
tmp = 0.5 / y;
} else {
tmp = -0.5 / x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.9e-42) or not (x <= 9.6e-43): tmp = 0.5 / y else: tmp = -0.5 / x return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.9e-42) || !(x <= 9.6e-43)) tmp = Float64(0.5 / y); else tmp = Float64(-0.5 / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.9e-42) || ~((x <= 9.6e-43))) tmp = 0.5 / y; else tmp = -0.5 / x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.9e-42], N[Not[LessEqual[x, 9.6e-43]], $MachinePrecision]], N[(0.5 / y), $MachinePrecision], N[(-0.5 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{-42} \lor \neg \left(x \leq 9.6 \cdot 10^{-43}\right):\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{x}\\
\end{array}
\end{array}
if x < -2.9000000000000003e-42 or 9.6000000000000007e-43 < x Initial program 79.4%
remove-double-neg79.4%
distribute-rgt-neg-out79.4%
distribute-frac-neg279.4%
neg-mul-179.4%
div-sub79.4%
distribute-lft-out--79.4%
neg-mul-179.4%
distribute-frac-neg279.4%
distribute-rgt-neg-out79.4%
remove-double-neg79.4%
cancel-sign-sub-inv79.4%
associate-/r*90.7%
associate-/r*90.7%
*-inverses90.7%
metadata-eval90.7%
metadata-eval90.7%
*-lft-identity90.7%
distribute-rgt-neg-out90.7%
Simplified100.0%
Taylor expanded in y around 0 79.2%
if -2.9000000000000003e-42 < x < 9.6000000000000007e-43Initial program 80.2%
remove-double-neg80.2%
distribute-rgt-neg-out80.2%
distribute-frac-neg280.2%
neg-mul-180.2%
div-sub79.1%
distribute-lft-out--79.1%
neg-mul-179.1%
distribute-frac-neg279.1%
distribute-rgt-neg-out79.1%
remove-double-neg79.1%
cancel-sign-sub-inv79.1%
associate-/r*80.0%
associate-/r*80.0%
*-inverses80.0%
metadata-eval80.0%
metadata-eval80.0%
*-lft-identity80.0%
distribute-rgt-neg-out80.0%
Simplified100.0%
Taylor expanded in y around inf 82.6%
Final simplification80.9%
(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 79.8%
remove-double-neg79.8%
distribute-rgt-neg-out79.8%
distribute-frac-neg279.8%
neg-mul-179.8%
div-sub79.3%
distribute-lft-out--79.3%
neg-mul-179.3%
distribute-frac-neg279.3%
distribute-rgt-neg-out79.3%
remove-double-neg79.3%
cancel-sign-sub-inv79.3%
associate-/r*85.5%
associate-/r*85.5%
*-inverses85.5%
metadata-eval85.5%
metadata-eval85.5%
*-lft-identity85.5%
distribute-rgt-neg-out85.5%
Simplified100.0%
Taylor expanded in y around inf 52.0%
Final simplification52.0%
(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 2024053
(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)))