
(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 7 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 (log (exp (/ (log1p (- x)) (log1p x)))))
double code(double x) {
return log(exp((log1p(-x) / log1p(x))));
}
public static double code(double x) {
return Math.log(Math.exp((Math.log1p(-x) / Math.log1p(x))));
}
def code(x): return math.log(math.exp((math.log1p(-x) / math.log1p(x))))
function code(x) return log(exp(Float64(log1p(Float64(-x)) / log1p(x)))) end
code[x_] := N[Log[N[Exp[N[(N[Log[1 + (-x)], $MachinePrecision] / N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}}\right)
\end{array}
Initial program 4.1%
Taylor expanded in x around inf 4.2%
expm1-log1p-u3.8%
expm1-undefine3.6%
sub-neg3.6%
distribute-lft-in4.1%
div-inv4.1%
*-inverses4.1%
metadata-eval4.1%
Applied egg-rr4.1%
sub-neg4.1%
metadata-eval4.1%
+-commutative4.1%
log1p-undefine3.9%
rem-exp-log3.9%
*-commutative3.9%
neg-mul-13.9%
associate-+r+4.3%
metadata-eval4.3%
sub-neg4.3%
Simplified4.3%
add-log-exp4.3%
associate-+r-4.1%
metadata-eval4.1%
sub-neg4.1%
log1p-define4.6%
log1p-define100.0%
Applied egg-rr100.0%
(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.1%
sub-neg4.1%
log1p-define4.6%
log1p-define100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (/ (* x (+ (* x (- (* x (- (* x -0.25) 0.3333333333333333)) 0.5)) -1.0)) (* x (+ 1.0 (* x (- (* x (+ (* x -0.25) 0.3333333333333333)) 0.5))))))
double code(double x) {
return (x * ((x * ((x * ((x * -0.25) - 0.3333333333333333)) - 0.5)) + -1.0)) / (x * (1.0 + (x * ((x * ((x * -0.25) + 0.3333333333333333)) - 0.5))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * ((x * ((x * ((x * (-0.25d0)) - 0.3333333333333333d0)) - 0.5d0)) + (-1.0d0))) / (x * (1.0d0 + (x * ((x * ((x * (-0.25d0)) + 0.3333333333333333d0)) - 0.5d0))))
end function
public static double code(double x) {
return (x * ((x * ((x * ((x * -0.25) - 0.3333333333333333)) - 0.5)) + -1.0)) / (x * (1.0 + (x * ((x * ((x * -0.25) + 0.3333333333333333)) - 0.5))));
}
def code(x): return (x * ((x * ((x * ((x * -0.25) - 0.3333333333333333)) - 0.5)) + -1.0)) / (x * (1.0 + (x * ((x * ((x * -0.25) + 0.3333333333333333)) - 0.5))))
function code(x) return Float64(Float64(x * Float64(Float64(x * Float64(Float64(x * Float64(Float64(x * -0.25) - 0.3333333333333333)) - 0.5)) + -1.0)) / Float64(x * Float64(1.0 + Float64(x * Float64(Float64(x * Float64(Float64(x * -0.25) + 0.3333333333333333)) - 0.5))))) end
function tmp = code(x) tmp = (x * ((x * ((x * ((x * -0.25) - 0.3333333333333333)) - 0.5)) + -1.0)) / (x * (1.0 + (x * ((x * ((x * -0.25) + 0.3333333333333333)) - 0.5)))); end
code[x_] := N[(N[(x * N[(N[(x * N[(N[(x * N[(N[(x * -0.25), $MachinePrecision] - 0.3333333333333333), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x * N[(1.0 + N[(x * N[(N[(x * N[(N[(x * -0.25), $MachinePrecision] + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(x \cdot \left(x \cdot \left(x \cdot -0.25 - 0.3333333333333333\right) - 0.5\right) + -1\right)}{x \cdot \left(1 + x \cdot \left(x \cdot \left(x \cdot -0.25 + 0.3333333333333333\right) - 0.5\right)\right)}
\end{array}
Initial program 4.1%
Taylor expanded in x around 0 5.6%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (+ (* x (+ (* x (- (* x -0.4166666666666667) 0.5)) -1.0)) -1.0))
double code(double x) {
return (x * ((x * ((x * -0.4166666666666667) - 0.5)) + -1.0)) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * ((x * ((x * (-0.4166666666666667d0)) - 0.5d0)) + (-1.0d0))) + (-1.0d0)
end function
public static double code(double x) {
return (x * ((x * ((x * -0.4166666666666667) - 0.5)) + -1.0)) + -1.0;
}
def code(x): return (x * ((x * ((x * -0.4166666666666667) - 0.5)) + -1.0)) + -1.0
function code(x) return Float64(Float64(x * Float64(Float64(x * Float64(Float64(x * -0.4166666666666667) - 0.5)) + -1.0)) + -1.0) end
function tmp = code(x) tmp = (x * ((x * ((x * -0.4166666666666667) - 0.5)) + -1.0)) + -1.0; end
code[x_] := N[(N[(x * N[(N[(x * N[(N[(x * -0.4166666666666667), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(x \cdot -0.4166666666666667 - 0.5\right) + -1\right) + -1
\end{array}
Initial program 4.1%
Taylor expanded in x around 0 99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (+ (* x (+ (* x -0.5) -1.0)) -1.0))
double code(double x) {
return (x * ((x * -0.5) + -1.0)) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * ((x * (-0.5d0)) + (-1.0d0))) + (-1.0d0)
end function
public static double code(double x) {
return (x * ((x * -0.5) + -1.0)) + -1.0;
}
def code(x): return (x * ((x * -0.5) + -1.0)) + -1.0
function code(x) return Float64(Float64(x * Float64(Float64(x * -0.5) + -1.0)) + -1.0) end
function tmp = code(x) tmp = (x * ((x * -0.5) + -1.0)) + -1.0; end
code[x_] := N[(N[(x * N[(N[(x * -0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot -0.5 + -1\right) + -1
\end{array}
Initial program 4.1%
Taylor expanded in x around 0 99.5%
Final simplification99.5%
(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.1%
Taylor expanded in x around 0 99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
(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.1%
Taylor expanded in x around 0 98.2%
(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 2024169
(FPCore (x)
:name "qlog (example 3.10)"
:precision binary64
:pre (<= (fabs x) 1.0)
:alt
(! :herbie-platform default (/ (log1p (- x)) (log1p x)))
(/ (log (- 1.0 x)) (log (+ 1.0 x))))