
(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 8 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) x)) (log1p x)) (log1p x)))
double code(double x) {
return (log1p((-x * x)) - log1p(x)) / log1p(x);
}
public static double code(double x) {
return (Math.log1p((-x * x)) - Math.log1p(x)) / Math.log1p(x);
}
def code(x): return (math.log1p((-x * x)) - math.log1p(x)) / math.log1p(x)
function code(x) return Float64(Float64(log1p(Float64(Float64(-x) * x)) - log1p(x)) / log1p(x)) end
code[x_] := N[(N[(N[Log[1 + N[((-x) * x), $MachinePrecision]], $MachinePrecision] - N[Log[1 + x], $MachinePrecision]), $MachinePrecision] / N[Log[1 + x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(\left(-x\right) \cdot x\right) - \mathsf{log1p}\left(x\right)}{\mathsf{log1p}\left(x\right)}
\end{array}
Initial program 3.8%
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f646.4
Applied rewrites6.4%
lift-log.f64N/A
lift--.f64N/A
flip--N/A
log-divN/A
lift-log1p.f64N/A
lower--.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.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 3.8%
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f646.4
Applied rewrites6.4%
lift-log.f64N/A
lift--.f64N/A
flip--N/A
log-divN/A
lift-log1p.f64N/A
lower--.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
lift--.f64N/A
lift-log1p.f64N/A
lift-log1p.f64N/A
diff-logN/A
lift-*.f64N/A
lift-neg.f64N/A
fp-cancel-sub-signN/A
metadata-evalN/A
flip--N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
lift-neg.f64N/A
*-rgt-identityN/A
lower-log1p.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(/
(*
(-
(*
(-
(/
(* (- (pow (* -0.25 x) 2.0) 0.1111111111111111) x)
(fma -0.25 x 0.3333333333333333))
0.5)
x)
1.0)
x)
(* (fma (- (* (fma -0.25 x 0.3333333333333333) x) 0.5) x 1.0) x)))
double code(double x) {
return (((((((pow((-0.25 * x), 2.0) - 0.1111111111111111) * x) / fma(-0.25, x, 0.3333333333333333)) - 0.5) * x) - 1.0) * x) / (fma(((fma(-0.25, x, 0.3333333333333333) * x) - 0.5), x, 1.0) * x);
}
function code(x) return Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64((Float64(-0.25 * x) ^ 2.0) - 0.1111111111111111) * x) / fma(-0.25, x, 0.3333333333333333)) - 0.5) * x) - 1.0) * x) / Float64(fma(Float64(Float64(fma(-0.25, x, 0.3333333333333333) * x) - 0.5), x, 1.0) * x)) end
code[x_] := N[(N[(N[(N[(N[(N[(N[(N[(N[Power[N[(-0.25 * x), $MachinePrecision], 2.0], $MachinePrecision] - 0.1111111111111111), $MachinePrecision] * x), $MachinePrecision] / N[(-0.25 * x + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision] / N[(N[(N[(N[(N[(-0.25 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(\frac{\left({\left(-0.25 \cdot x\right)}^{2} - 0.1111111111111111\right) \cdot x}{\mathsf{fma}\left(-0.25, x, 0.3333333333333333\right)} - 0.5\right) \cdot x - 1\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(-0.25, x, 0.3333333333333333\right) \cdot x - 0.5, x, 1\right) \cdot x}
\end{array}
Initial program 3.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f645.7
Applied rewrites5.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6499.3
Applied rewrites99.3%
Applied rewrites99.3%
(FPCore (x) :precision binary64 (/ (* (- (* (- (* (- (* -0.25 x) 0.3333333333333333) x) 0.5) x) 1.0) x) (* (fma (- (* (fma -0.25 x 0.3333333333333333) x) 0.5) x 1.0) x)))
double code(double x) {
return (((((((-0.25 * x) - 0.3333333333333333) * x) - 0.5) * x) - 1.0) * x) / (fma(((fma(-0.25, x, 0.3333333333333333) * x) - 0.5), x, 1.0) * x);
}
function code(x) return Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.25 * x) - 0.3333333333333333) * x) - 0.5) * x) - 1.0) * x) / Float64(fma(Float64(Float64(fma(-0.25, x, 0.3333333333333333) * x) - 0.5), x, 1.0) * x)) end
code[x_] := N[(N[(N[(N[(N[(N[(N[(N[(-0.25 * x), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision] / N[(N[(N[(N[(N[(-0.25 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(\left(-0.25 \cdot x - 0.3333333333333333\right) \cdot x - 0.5\right) \cdot x - 1\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(-0.25, x, 0.3333333333333333\right) \cdot x - 0.5, x, 1\right) \cdot x}
\end{array}
Initial program 3.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f645.7
Applied rewrites5.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6499.3
Applied rewrites99.3%
(FPCore (x) :precision binary64 (- (* (- (* (- (* -0.4166666666666667 x) 0.5) x) 1.0) x) 1.0))
double code(double x) {
return (((((-0.4166666666666667 * x) - 0.5) * x) - 1.0) * x) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((((((-0.4166666666666667d0) * x) - 0.5d0) * x) - 1.0d0) * x) - 1.0d0
end function
public static double code(double x) {
return (((((-0.4166666666666667 * x) - 0.5) * x) - 1.0) * x) - 1.0;
}
def code(x): return (((((-0.4166666666666667 * x) - 0.5) * x) - 1.0) * x) - 1.0
function code(x) return Float64(Float64(Float64(Float64(Float64(Float64(-0.4166666666666667 * x) - 0.5) * x) - 1.0) * x) - 1.0) end
function tmp = code(x) tmp = (((((-0.4166666666666667 * x) - 0.5) * x) - 1.0) * x) - 1.0; end
code[x_] := N[(N[(N[(N[(N[(N[(-0.4166666666666667 * x), $MachinePrecision] - 0.5), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(-0.4166666666666667 \cdot x - 0.5\right) \cdot x - 1\right) \cdot x - 1
\end{array}
Initial program 3.8%
Taylor expanded in x around 0
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6499.2
Applied rewrites99.2%
(FPCore (x) :precision binary64 (- (* (fma -0.5 x -1.0) x) 1.0))
double code(double x) {
return (fma(-0.5, x, -1.0) * x) - 1.0;
}
function code(x) return Float64(Float64(fma(-0.5, x, -1.0) * x) - 1.0) end
code[x_] := N[(N[(N[(-0.5 * x + -1.0), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-0.5, x, -1\right) \cdot x - 1
\end{array}
Initial program 3.8%
Taylor expanded in x around 0
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6499.2
Applied rewrites99.2%
Taylor expanded in x around 0
lower--.f64N/A
Applied rewrites99.1%
(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 3.8%
Taylor expanded in x around 0
lower--.f64N/A
mul-1-negN/A
lower-neg.f6498.5
Applied rewrites98.5%
Taylor expanded in x around 0
mul-1-negN/A
*-rgt-identityN/A
distribute-lft-neg-inN/A
rgt-mult-inverseN/A
fp-cancel-sub-signN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
fp-cancel-sub-signN/A
distribute-lft-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
*-rgt-identityN/A
lower--.f6498.5
Applied rewrites98.5%
(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 3.8%
Taylor expanded in x around 0
Applied rewrites97.6%
(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 2024326
(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))))