Alternative 1 | |
---|---|
Error | 41.9 |
Cost | 6724 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 0.9:\\
\;\;\;\;x - \log x\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + \frac{-0.5}{x \cdot x}\\
\end{array}
\]
(FPCore (x) :precision binary64 (- (log (+ x 1.0)) (log x)))
(FPCore (x) :precision binary64 (log1p (/ 1.0 x)))
double code(double x) { return log((x + 1.0)) - log(x); }
double code(double x) { return log1p((1.0 / x)); }
public static double code(double x) { return Math.log((x + 1.0)) - Math.log(x); }
public static double code(double x) { return Math.log1p((1.0 / x)); }
def code(x): return math.log((x + 1.0)) - math.log(x)
def code(x): return math.log1p((1.0 / x))
function code(x) return Float64(log(Float64(x + 1.0)) - log(x)) end
function code(x) return log1p(Float64(1.0 / x)) end
code[x_] := N[(N[Log[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision]
\log \left(x + 1\right) - \log x
\mathsf{log1p}\left(\frac{1}{x}\right)
Results
Initial program 3.1
Applied egg-rr2.2
Applied egg-rr2.3
Simplified0.2
[Start]2.3 | \[ \mathsf{log1p}\left(\frac{x + 1}{x} - 1\right)
\] |
---|---|
*-lft-identity [<=]2.3 | \[ \mathsf{log1p}\left(\color{blue}{1 \cdot \frac{x + 1}{x}} - 1\right)
\] |
associate-*r/ [=>]2.3 | \[ \mathsf{log1p}\left(\color{blue}{\frac{1 \cdot \left(x + 1\right)}{x}} - 1\right)
\] |
associate-*l/ [<=]2.3 | \[ \mathsf{log1p}\left(\color{blue}{\frac{1}{x} \cdot \left(x + 1\right)} - 1\right)
\] |
distribute-rgt-in [=>]2.3 | \[ \mathsf{log1p}\left(\color{blue}{\left(x \cdot \frac{1}{x} + 1 \cdot \frac{1}{x}\right)} - 1\right)
\] |
+-commutative [=>]2.3 | \[ \mathsf{log1p}\left(\color{blue}{\left(1 \cdot \frac{1}{x} + x \cdot \frac{1}{x}\right)} - 1\right)
\] |
rgt-mult-inverse [=>]2.2 | \[ \mathsf{log1p}\left(\left(1 \cdot \frac{1}{x} + \color{blue}{1}\right) - 1\right)
\] |
*-lft-identity [=>]2.2 | \[ \mathsf{log1p}\left(\left(\color{blue}{\frac{1}{x}} + 1\right) - 1\right)
\] |
associate--l+ [=>]0.2 | \[ \mathsf{log1p}\left(\color{blue}{\frac{1}{x} + \left(1 - 1\right)}\right)
\] |
metadata-eval [=>]0.2 | \[ \mathsf{log1p}\left(\frac{1}{x} + \color{blue}{0}\right)
\] |
Final simplification0.2
Alternative 1 | |
---|---|
Error | 41.9 |
Cost | 6724 |
Alternative 2 | |
---|---|
Error | 2.2 |
Cost | 6720 |
Alternative 3 | |
---|---|
Error | 43.7 |
Cost | 6660 |
Alternative 4 | |
---|---|
Error | 45.7 |
Cost | 708 |
Alternative 5 | |
---|---|
Error | 49.0 |
Cost | 192 |
herbie shell --seed 1
(FPCore (x)
:name "log(x+1) - log(x)"
:precision binary64
:pre (and (<= 0.01 x) (<= x 1000.0))
(- (log (+ x 1.0)) (log x)))