
(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 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}
Initial program 75.7%
+-commutative75.7%
remove-double-neg75.7%
unsub-neg75.7%
div-sub75.3%
associate-/l/83.6%
*-inverses83.6%
metadata-eval83.6%
distribute-neg-frac83.6%
distribute-frac-neg283.6%
distribute-rgt-neg-in83.6%
metadata-eval83.6%
distribute-neg-frac83.6%
associate-/r*99.6%
distribute-neg-frac99.6%
associate-/r*100.0%
*-inverses100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
(FPCore (x y) :precision binary64 (if (<= x -7.5e-73) (/ 0.5 y) (/ 0.5 x)))
double code(double x, double y) {
double tmp;
if (x <= -7.5e-73) {
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 <= (-7.5d-73)) 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 <= -7.5e-73) {
tmp = 0.5 / y;
} else {
tmp = 0.5 / x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.5e-73: tmp = 0.5 / y else: tmp = 0.5 / x return tmp
function code(x, y) tmp = 0.0 if (x <= -7.5e-73) 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 <= -7.5e-73) tmp = 0.5 / y; else tmp = 0.5 / x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.5e-73], N[(0.5 / y), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-73}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -7.5e-73Initial program 78.2%
+-commutative78.2%
remove-double-neg78.2%
unsub-neg78.2%
div-sub78.2%
associate-/l/87.3%
*-inverses87.3%
metadata-eval87.3%
distribute-neg-frac87.3%
distribute-frac-neg287.3%
distribute-rgt-neg-in87.3%
metadata-eval87.3%
distribute-neg-frac87.3%
associate-/r*98.8%
distribute-neg-frac98.8%
associate-/r*100.0%
*-inverses100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 69.1%
if -7.5e-73 < x Initial program 74.4%
+-commutative74.4%
remove-double-neg74.4%
unsub-neg74.4%
div-sub73.9%
associate-/l/81.7%
*-inverses81.7%
metadata-eval81.7%
distribute-neg-frac81.7%
distribute-frac-neg281.7%
distribute-rgt-neg-in81.7%
metadata-eval81.7%
distribute-neg-frac81.7%
associate-/r*100.0%
distribute-neg-frac100.0%
associate-/r*100.0%
*-inverses100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 63.5%
(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.7%
+-commutative75.7%
remove-double-neg75.7%
unsub-neg75.7%
div-sub75.3%
associate-/l/83.6%
*-inverses83.6%
metadata-eval83.6%
distribute-neg-frac83.6%
distribute-frac-neg283.6%
distribute-rgt-neg-in83.6%
metadata-eval83.6%
distribute-neg-frac83.6%
associate-/r*99.6%
distribute-neg-frac99.6%
associate-/r*100.0%
*-inverses100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 53.6%
(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 2024108
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, C"
:precision binary64
:alt
(+ (/ 0.5 x) (/ 0.5 y))
(/ (+ x y) (* (* x 2.0) y)))