Alternative 1 | |
---|---|
Error | 0.3 |
Cost | 13056 |
\[\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}
\]
(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
(FPCore (x) :precision binary64 (/ (- (log1p (* x (- x))) (log1p x)) (log1p x)))
double code(double x) { return log((1.0 - x)) / log((1.0 + x)); }
double code(double x) { return (log1p((x * -x)) - log1p(x)) / log1p(x); }
public static double code(double x) { return Math.log((1.0 - x)) / Math.log((1.0 + x)); }
public static double code(double x) { return (Math.log1p((x * -x)) - Math.log1p(x)) / Math.log1p(x); }
def code(x): return math.log((1.0 - x)) / math.log((1.0 + x))
def code(x): return (math.log1p((x * -x)) - math.log1p(x)) / math.log1p(x)
function code(x) return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x))) end
function code(x) return Float64(Float64(log1p(Float64(x * Float64(-x))) - log1p(x)) / log1p(x)) end
code[x_] := N[(N[Log[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] / N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[Log[1 + N[(x * (-x)), $MachinePrecision]], $MachinePrecision] - N[Log[1 + x], $MachinePrecision]), $MachinePrecision] / N[Log[1 + x], $MachinePrecision]), $MachinePrecision]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \mathsf{log1p}\left(x\right)}{\mathsf{log1p}\left(x\right)}
Results
Initial program 2.2
Simplified2.6
[Start]2.2 | \[ \frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\] |
---|---|
log1p-def [=>]2.6 | \[ \frac{\log \left(1 - x\right)}{\color{blue}{\mathsf{log1p}\left(x\right)}}
\] |
Applied egg-rr3.6
Simplified0.2
[Start]3.6 | \[ \frac{\left(\log \left(1 - x \cdot x\right) - e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)}\right) + 1}{\mathsf{log1p}\left(x\right)}
\] |
---|---|
associate-+l- [=>]3.3 | \[ \frac{\color{blue}{\log \left(1 - x \cdot x\right) - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}}{\mathsf{log1p}\left(x\right)}
\] |
sub-neg [=>]3.3 | \[ \frac{\log \color{blue}{\left(1 + \left(-x \cdot x\right)\right)} - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}{\mathsf{log1p}\left(x\right)}
\] |
log1p-def [=>]3.3 | \[ \frac{\color{blue}{\mathsf{log1p}\left(-x \cdot x\right)} - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}{\mathsf{log1p}\left(x\right)}
\] |
distribute-rgt-neg-in [=>]3.3 | \[ \frac{\mathsf{log1p}\left(\color{blue}{x \cdot \left(-x\right)}\right) - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}{\mathsf{log1p}\left(x\right)}
\] |
expm1-def [=>]0.3 | \[ \frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)\right)}}{\mathsf{log1p}\left(x\right)}
\] |
expm1-log1p [=>]0.2 | \[ \frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \color{blue}{\mathsf{log1p}\left(x\right)}}{\mathsf{log1p}\left(x\right)}
\] |
Final simplification0.2
Alternative 1 | |
---|---|
Error | 0.3 |
Cost | 13056 |
Alternative 2 | |
---|---|
Error | 30.7 |
Cost | 832 |
Alternative 3 | |
---|---|
Error | 41.3 |
Cost | 192 |
Alternative 4 | |
---|---|
Error | 47.2 |
Cost | 64 |
herbie shell --seed 1
(FPCore (x)
:name "log(1 - x) / log(1 + x)"
:precision binary64
:pre (and (<= 0.001 x) (<= x 1.0))
(/ (log (- 1.0 x)) (log (+ 1.0 x))))