
(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
double code(double x) {
return log((1.0 - x)) / log((1.0 + x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((1.0d0 - x)) / log((1.0d0 + x))
end function
public static double code(double x) {
return Math.log((1.0 - x)) / Math.log((1.0 + x));
}
def code(x): return math.log((1.0 - x)) / math.log((1.0 + x))
function code(x) return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x))) end
function tmp = code(x) tmp = log((1.0 - x)) / log((1.0 + x)); end
code[x_] := N[(N[Log[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] / N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
double code(double x) {
return log((1.0 - x)) / log((1.0 + x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((1.0d0 - x)) / log((1.0d0 + x))
end function
public static double code(double x) {
return Math.log((1.0 - x)) / Math.log((1.0 + x));
}
def code(x): return math.log((1.0 - x)) / math.log((1.0 + x))
function code(x) return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x))) end
function tmp = code(x) tmp = log((1.0 - x)) / log((1.0 + x)); end
code[x_] := N[(N[Log[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] / N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\end{array}
(FPCore (x) :precision binary64 (/ (log1p (- x)) (log1p x)))
double code(double x) {
return log1p(-x) / log1p(x);
}
public static double code(double x) {
return Math.log1p(-x) / Math.log1p(x);
}
def code(x): return math.log1p(-x) / math.log1p(x)
function code(x) return Float64(log1p(Float64(-x)) / log1p(x)) end
code[x_] := N[(N[Log[1 + (-x)], $MachinePrecision] / N[Log[1 + x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}
\end{array}
Initial program 4.0%
sub-neg4.0%
log1p-def5.2%
log1p-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (+ -1.0 (- (* (pow x 2.0) (+ (* x -0.4166666666666667) -0.5)) x)))
double code(double x) {
return -1.0 + ((pow(x, 2.0) * ((x * -0.4166666666666667) + -0.5)) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + (((x ** 2.0d0) * ((x * (-0.4166666666666667d0)) + (-0.5d0))) - x)
end function
public static double code(double x) {
return -1.0 + ((Math.pow(x, 2.0) * ((x * -0.4166666666666667) + -0.5)) - x);
}
def code(x): return -1.0 + ((math.pow(x, 2.0) * ((x * -0.4166666666666667) + -0.5)) - x)
function code(x) return Float64(-1.0 + Float64(Float64((x ^ 2.0) * Float64(Float64(x * -0.4166666666666667) + -0.5)) - x)) end
function tmp = code(x) tmp = -1.0 + (((x ^ 2.0) * ((x * -0.4166666666666667) + -0.5)) - x); end
code[x_] := N[(-1.0 + N[(N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(x * -0.4166666666666667), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left({x}^{2} \cdot \left(x \cdot -0.4166666666666667 + -0.5\right) - x\right)
\end{array}
Initial program 4.0%
sub-neg4.0%
log1p-def5.2%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 99.6%
expm1-log1p-u99.6%
expm1-udef99.6%
+-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
expm1-def99.6%
expm1-log1p99.6%
fma-udef99.6%
*-commutative99.6%
unpow399.6%
unpow299.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
distribute-lft-out99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (+ -1.0 (- (* (pow x 2.0) -0.5) x)))
double code(double x) {
return -1.0 + ((pow(x, 2.0) * -0.5) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + (((x ** 2.0d0) * (-0.5d0)) - x)
end function
public static double code(double x) {
return -1.0 + ((Math.pow(x, 2.0) * -0.5) - x);
}
def code(x): return -1.0 + ((math.pow(x, 2.0) * -0.5) - x)
function code(x) return Float64(-1.0 + Float64(Float64((x ^ 2.0) * -0.5) - x)) end
function tmp = code(x) tmp = -1.0 + (((x ^ 2.0) * -0.5) - x); end
code[x_] := N[(-1.0 + N[(N[(N[Power[x, 2.0], $MachinePrecision] * -0.5), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left({x}^{2} \cdot -0.5 - x\right)
\end{array}
Initial program 4.0%
sub-neg4.0%
log1p-def5.2%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (- -1.0 x))
double code(double x) {
return -1.0 - x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) - x
end function
public static double code(double x) {
return -1.0 - x;
}
def code(x): return -1.0 - x
function code(x) return Float64(-1.0 - x) end
function tmp = code(x) tmp = -1.0 - x; end
code[x_] := N[(-1.0 - x), $MachinePrecision]
\begin{array}{l}
\\
-1 - x
\end{array}
Initial program 4.0%
sub-neg4.0%
log1p-def5.2%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 4.0%
sub-neg4.0%
log1p-def5.2%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 97.7%
Final simplification97.7%
(FPCore (x) :precision binary64 (/ (log1p (- x)) (log1p x)))
double code(double x) {
return log1p(-x) / log1p(x);
}
public static double code(double x) {
return Math.log1p(-x) / Math.log1p(x);
}
def code(x): return math.log1p(-x) / math.log1p(x)
function code(x) return Float64(log1p(Float64(-x)) / log1p(x)) end
code[x_] := N[(N[Log[1 + (-x)], $MachinePrecision] / N[Log[1 + x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}
\end{array}
herbie shell --seed 2024033
(FPCore (x)
:name "qlog (example 3.10)"
:precision binary64
:pre (<= (fabs x) 1.0)
:herbie-target
(/ (log1p (- x)) (log1p x))
(/ (log (- 1.0 x)) (log (+ 1.0 x))))