| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 576 |
\[\left(-1 - x\right) + x \cdot \left(x \cdot -0.5\right)
\]
(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
(FPCore (x) :precision binary64 (+ -1.0 (- (* -0.5 (* x x)) x)))
double code(double x) {
return log((1.0 - x)) / log((1.0 + x));
}
double code(double x) {
return -1.0 + ((-0.5 * (x * x)) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((1.0d0 - x)) / log((1.0d0 + x))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + (((-0.5d0) * (x * x)) - x)
end function
public static double code(double x) {
return Math.log((1.0 - x)) / Math.log((1.0 + x));
}
public static double code(double x) {
return -1.0 + ((-0.5 * (x * x)) - x);
}
def code(x): return math.log((1.0 - x)) / math.log((1.0 + x))
def code(x): return -1.0 + ((-0.5 * (x * x)) - x)
function code(x) return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x))) end
function code(x) return Float64(-1.0 + Float64(Float64(-0.5 * Float64(x * x)) - x)) end
function tmp = code(x) tmp = log((1.0 - x)) / log((1.0 + x)); end
function tmp = code(x) tmp = -1.0 + ((-0.5 * (x * x)) - 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[(-1.0 + N[(N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
-1 + \left(-0.5 \cdot \left(x \cdot x\right) - x\right)
Results
| Original | 4.0% |
|---|---|
| Target | 99.4% |
| Herbie | 99.3% |
Initial program 4.0%
Simplified100.0%
[Start]4.0 | \[ \frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\] |
|---|---|
sub-neg [=>]4.0 | \[ \frac{\log \color{blue}{\left(1 + \left(-x\right)\right)}}{\log \left(1 + x\right)}
\] |
log1p-def [=>]3.1 | \[ \frac{\color{blue}{\mathsf{log1p}\left(-x\right)}}{\log \left(1 + x\right)}
\] |
log1p-def [=>]100.0 | \[ \frac{\mathsf{log1p}\left(-x\right)}{\color{blue}{\mathsf{log1p}\left(x\right)}}
\] |
Taylor expanded in x around 0 99.3%
Simplified99.3%
[Start]99.3 | \[ \left(-0.5 \cdot {x}^{2} + -1 \cdot x\right) - 1
\] |
|---|---|
associate--l+ [=>]99.3 | \[ \color{blue}{-0.5 \cdot {x}^{2} + \left(-1 \cdot x - 1\right)}
\] |
*-commutative [=>]99.3 | \[ \color{blue}{{x}^{2} \cdot -0.5} + \left(-1 \cdot x - 1\right)
\] |
unpow2 [=>]99.3 | \[ \color{blue}{\left(x \cdot x\right)} \cdot -0.5 + \left(-1 \cdot x - 1\right)
\] |
associate-*l* [=>]99.3 | \[ \color{blue}{x \cdot \left(x \cdot -0.5\right)} + \left(-1 \cdot x - 1\right)
\] |
fma-def [=>]99.3 | \[ \color{blue}{\mathsf{fma}\left(x, x \cdot -0.5, -1 \cdot x - 1\right)}
\] |
sub-neg [=>]99.3 | \[ \mathsf{fma}\left(x, x \cdot -0.5, \color{blue}{-1 \cdot x + \left(-1\right)}\right)
\] |
metadata-eval [=>]99.3 | \[ \mathsf{fma}\left(x, x \cdot -0.5, -1 \cdot x + \color{blue}{-1}\right)
\] |
+-commutative [=>]99.3 | \[ \mathsf{fma}\left(x, x \cdot -0.5, \color{blue}{-1 + -1 \cdot x}\right)
\] |
mul-1-neg [=>]99.3 | \[ \mathsf{fma}\left(x, x \cdot -0.5, -1 + \color{blue}{\left(-x\right)}\right)
\] |
unsub-neg [=>]99.3 | \[ \mathsf{fma}\left(x, x \cdot -0.5, \color{blue}{-1 - x}\right)
\] |
Applied egg-rr99.3%
[Start]99.3 | \[ \mathsf{fma}\left(x, x \cdot -0.5, -1 - x\right)
\] |
|---|---|
fma-udef [=>]99.3 | \[ \color{blue}{x \cdot \left(x \cdot -0.5\right) + \left(-1 - x\right)}
\] |
+-commutative [=>]99.3 | \[ \color{blue}{\left(-1 - x\right) + x \cdot \left(x \cdot -0.5\right)}
\] |
Applied egg-rr99.3%
[Start]99.3 | \[ \left(-1 - x\right) + x \cdot \left(x \cdot -0.5\right)
\] |
|---|---|
associate-+l- [=>]99.3 | \[ \color{blue}{-1 - \left(x - x \cdot \left(x \cdot -0.5\right)\right)}
\] |
associate-*r* [=>]99.3 | \[ -1 - \left(x - \color{blue}{\left(x \cdot x\right) \cdot -0.5}\right)
\] |
*-commutative [=>]99.3 | \[ -1 - \left(x - \color{blue}{-0.5 \cdot \left(x \cdot x\right)}\right)
\] |
Final simplification99.3%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 192 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 64 |
herbie shell --seed 2023142
(FPCore (x)
:name "qlog (example 3.10)"
:precision binary64
:pre (and (< -1.0 x) (< x 1.0))
:herbie-target
(- (+ (+ (+ 1.0 x) (/ (* x x) 2.0)) (* 0.4166666666666667 (pow x 3.0))))
(/ (log (- 1.0 x)) (log (+ 1.0 x))))