Alternative 1 | |
---|---|
Error | 2.9 |
Cost | 6848 |
\[\log \left(\frac{1 - x}{x + 1}\right)
\]
(FPCore (x) :precision binary64 (log (/ (- 1.0 x) (+ 1.0 x))))
(FPCore (x) :precision binary64 (- (log1p (- x)) (log1p x)))
double code(double x) { return log(((1.0 - x) / (1.0 + x))); }
double code(double x) { return log1p(-x) - log1p(x); }
public static double code(double x) { return Math.log(((1.0 - x) / (1.0 + x))); }
public static double code(double x) { return Math.log1p(-x) - Math.log1p(x); }
def code(x): return math.log(((1.0 - x) / (1.0 + x)))
def code(x): return math.log1p(-x) - math.log1p(x)
function code(x) return log(Float64(Float64(1.0 - x) / Float64(1.0 + x))) end
function code(x) return Float64(log1p(Float64(-x)) - log1p(x)) end
code[x_] := N[Log[N[(N[(1.0 - x), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := N[(N[Log[1 + (-x)], $MachinePrecision] - N[Log[1 + x], $MachinePrecision]), $MachinePrecision]
\log \left(\frac{1 - x}{1 + x}\right)
\mathsf{log1p}\left(-x\right) - \mathsf{log1p}\left(x\right)
Results
Initial program 2.9
Simplified0.2
[Start]2.9 | \[ \log \left(\frac{1 - x}{1 + x}\right)
\] |
---|---|
log-div [=>]2.9 | \[ \color{blue}{\log \left(1 - x\right) - \log \left(1 + x\right)}
\] |
sub-neg [=>]2.9 | \[ \log \color{blue}{\left(1 + \left(-x\right)\right)} - \log \left(1 + x\right)
\] |
log1p-def [=>]2.8 | \[ \color{blue}{\mathsf{log1p}\left(-x\right)} - \log \left(1 + x\right)
\] |
log1p-def [=>]0.2 | \[ \mathsf{log1p}\left(-x\right) - \color{blue}{\mathsf{log1p}\left(x\right)}
\] |
Final simplification0.2
Alternative 1 | |
---|---|
Error | 2.9 |
Cost | 6848 |
Alternative 2 | |
---|---|
Error | 41.1 |
Cost | 192 |
Alternative 3 | |
---|---|
Error | 62.0 |
Cost | 64 |
herbie shell --seed 1
(FPCore (x)
:name "log((1 - x) / (1 + x))"
:precision binary64
:pre (and (<= 0.001 x) (<= x 1.0))
(log (/ (- 1.0 x) (+ 1.0 x))))