
(FPCore (x0 x1) :precision binary64 (- (/ x0 (- 1.0 x1)) x0))
double code(double x0, double x1) {
return (x0 / (1.0 - x1)) - x0;
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = (x0 / (1.0d0 - x1)) - x0
end function
public static double code(double x0, double x1) {
return (x0 / (1.0 - x1)) - x0;
}
def code(x0, x1): return (x0 / (1.0 - x1)) - x0
function code(x0, x1) return Float64(Float64(x0 / Float64(1.0 - x1)) - x0) end
function tmp = code(x0, x1) tmp = (x0 / (1.0 - x1)) - x0; end
code[x0_, x1_] := N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x0}{1 - x1} - x0
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x0 x1) :precision binary64 (- (/ x0 (- 1.0 x1)) x0))
double code(double x0, double x1) {
return (x0 / (1.0 - x1)) - x0;
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = (x0 / (1.0d0 - x1)) - x0
end function
public static double code(double x0, double x1) {
return (x0 / (1.0 - x1)) - x0;
}
def code(x0, x1): return (x0 / (1.0 - x1)) - x0
function code(x0, x1) return Float64(Float64(x0 / Float64(1.0 - x1)) - x0) end
function tmp = code(x0, x1) tmp = (x0 / (1.0 - x1)) - x0; end
code[x0_, x1_] := N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x0}{1 - x1} - x0
\end{array}
(FPCore (x0 x1) :precision binary64 (* x1 (+ x0 (* x1 (+ x0 (* x1 (/ x0 (- 1.0 x1))))))))
double code(double x0, double x1) {
return x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1))))));
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0d0 - x1))))))
end function
public static double code(double x0, double x1) {
return x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1))))));
}
def code(x0, x1): return x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1))))))
function code(x0, x1) return Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 / Float64(1.0 - x1))))))) end
function tmp = code(x0, x1) tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1)))))); end
code[x0_, x1_] := N[(x1 * N[(x0 + N[(x1 * N[(x0 + N[(x1 * N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \frac{x0}{1 - x1}\right)\right)
\end{array}
Initial program 88.9%
Taylor expanded in x0 around 0 89.4%
Taylor expanded in x1 around 0 73.2%
Applied egg-rr100.0%
distribute-neg-in100.0%
metadata-eval100.0%
sub-neg100.0%
Simplified100.0%
(FPCore (x0 x1) :precision binary64 (if (<= (- 1.0 x1) 0.99) (- (/ x0 (- 1.0 x1)) x0) (* x1 (+ x0 (* x1 (+ x0 (* x1 (+ x0 (* x1 x0)))))))))
double code(double x0, double x1) {
double tmp;
if ((1.0 - x1) <= 0.99) {
tmp = (x0 / (1.0 - x1)) - x0;
} else {
tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))));
}
return tmp;
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
real(8) :: tmp
if ((1.0d0 - x1) <= 0.99d0) then
tmp = (x0 / (1.0d0 - x1)) - x0
else
tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))))
end if
code = tmp
end function
public static double code(double x0, double x1) {
double tmp;
if ((1.0 - x1) <= 0.99) {
tmp = (x0 / (1.0 - x1)) - x0;
} else {
tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))));
}
return tmp;
}
def code(x0, x1): tmp = 0 if (1.0 - x1) <= 0.99: tmp = (x0 / (1.0 - x1)) - x0 else: tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0)))))) return tmp
function code(x0, x1) tmp = 0.0 if (Float64(1.0 - x1) <= 0.99) tmp = Float64(Float64(x0 / Float64(1.0 - x1)) - x0); else tmp = Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 + Float64(x1 * x0))))))); end return tmp end
function tmp_2 = code(x0, x1) tmp = 0.0; if ((1.0 - x1) <= 0.99) tmp = (x0 / (1.0 - x1)) - x0; else tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0)))))); end tmp_2 = tmp; end
code[x0_, x1_] := If[LessEqual[N[(1.0 - x1), $MachinePrecision], 0.99], N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision], N[(x1 * N[(x0 + N[(x1 * N[(x0 + N[(x1 * N[(x0 + N[(x1 * x0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x1 \leq 0.99:\\
\;\;\;\;\frac{x0}{1 - x1} - x0\\
\mathbf{else}:\\
\;\;\;\;x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot x0\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) x1) < 0.98999999999999999Initial program 94.4%
if 0.98999999999999999 < (-.f64 #s(literal 1 binary64) x1) Initial program 82.6%
Taylor expanded in x0 around 0 84.0%
Taylor expanded in x1 around 0 94.4%
Final simplification94.4%
(FPCore (x0 x1) :precision binary64 (* x0 (+ (/ 1.0 (- 1.0 x1)) -1.0)))
double code(double x0, double x1) {
return x0 * ((1.0 / (1.0 - x1)) + -1.0);
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = x0 * ((1.0d0 / (1.0d0 - x1)) + (-1.0d0))
end function
public static double code(double x0, double x1) {
return x0 * ((1.0 / (1.0 - x1)) + -1.0);
}
def code(x0, x1): return x0 * ((1.0 / (1.0 - x1)) + -1.0)
function code(x0, x1) return Float64(x0 * Float64(Float64(1.0 / Float64(1.0 - x1)) + -1.0)) end
function tmp = code(x0, x1) tmp = x0 * ((1.0 / (1.0 - x1)) + -1.0); end
code[x0_, x1_] := N[(x0 * N[(N[(1.0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x0 \cdot \left(\frac{1}{1 - x1} + -1\right)
\end{array}
Initial program 88.9%
Taylor expanded in x0 around 0 89.4%
Final simplification89.4%
(FPCore (x0 x1) :precision binary64 (- (/ x0 (- 1.0 x1)) x0))
double code(double x0, double x1) {
return (x0 / (1.0 - x1)) - x0;
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = (x0 / (1.0d0 - x1)) - x0
end function
public static double code(double x0, double x1) {
return (x0 / (1.0 - x1)) - x0;
}
def code(x0, x1): return (x0 / (1.0 - x1)) - x0
function code(x0, x1) return Float64(Float64(x0 / Float64(1.0 - x1)) - x0) end
function tmp = code(x0, x1) tmp = (x0 / (1.0 - x1)) - x0; end
code[x0_, x1_] := N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x0}{1 - x1} - x0
\end{array}
Initial program 88.9%
(FPCore (x0 x1) :precision binary64 (* x1 x0))
double code(double x0, double x1) {
return x1 * x0;
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = x1 * x0
end function
public static double code(double x0, double x1) {
return x1 * x0;
}
def code(x0, x1): return x1 * x0
function code(x0, x1) return Float64(x1 * x0) end
function tmp = code(x0, x1) tmp = x1 * x0; end
code[x0_, x1_] := N[(x1 * x0), $MachinePrecision]
\begin{array}{l}
\\
x1 \cdot x0
\end{array}
Initial program 88.9%
Taylor expanded in x1 around 0 32.1%
Final simplification32.1%
(FPCore (x0 x1) :precision binary64 0.0)
double code(double x0, double x1) {
return 0.0;
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = 0.0d0
end function
public static double code(double x0, double x1) {
return 0.0;
}
def code(x0, x1): return 0.0
function code(x0, x1) return 0.0 end
function tmp = code(x0, x1) tmp = 0.0; end
code[x0_, x1_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 88.9%
sub-neg88.9%
+-commutative88.9%
add-sqr-sqrt88.9%
distribute-rgt-neg-in88.9%
fma-define91.5%
Applied egg-rr91.5%
Taylor expanded in x1 around 0 3.1%
distribute-rgt1-in3.1%
metadata-eval3.1%
mul0-lft3.1%
Simplified3.1%
(FPCore (x0 x1) :precision binary64 (/ (* x0 x1) (- 1.0 x1)))
double code(double x0, double x1) {
return (x0 * x1) / (1.0 - x1);
}
real(8) function code(x0, x1)
real(8), intent (in) :: x0
real(8), intent (in) :: x1
code = (x0 * x1) / (1.0d0 - x1)
end function
public static double code(double x0, double x1) {
return (x0 * x1) / (1.0 - x1);
}
def code(x0, x1): return (x0 * x1) / (1.0 - x1)
function code(x0, x1) return Float64(Float64(x0 * x1) / Float64(1.0 - x1)) end
function tmp = code(x0, x1) tmp = (x0 * x1) / (1.0 - x1); end
code[x0_, x1_] := N[(N[(x0 * x1), $MachinePrecision] / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x0 \cdot x1}{1 - x1}
\end{array}
herbie shell --seed 2024169
(FPCore (x0 x1)
:name "(- (/ x0 (- 1 x1)) x0)"
:precision binary64
:pre (or (and (== x0 1.855) (== x1 0.000209)) (and (== x0 2.985) (== x1 0.0186)))
:alt
(! :herbie-platform default (/ (* x0 x1) (- 1 x1)))
(- (/ x0 (- 1.0 x1)) x0))