
(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 (+ -1.0 (+ (* x (* x -0.5)) (- (* -0.4166666666666667 (pow x 3.0)) x))))
double code(double x) {
return -1.0 + ((x * (x * -0.5)) + ((-0.4166666666666667 * pow(x, 3.0)) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + ((x * (x * (-0.5d0))) + (((-0.4166666666666667d0) * (x ** 3.0d0)) - x))
end function
public static double code(double x) {
return -1.0 + ((x * (x * -0.5)) + ((-0.4166666666666667 * Math.pow(x, 3.0)) - x));
}
def code(x): return -1.0 + ((x * (x * -0.5)) + ((-0.4166666666666667 * math.pow(x, 3.0)) - x))
function code(x) return Float64(-1.0 + Float64(Float64(x * Float64(x * -0.5)) + Float64(Float64(-0.4166666666666667 * (x ^ 3.0)) - x))) end
function tmp = code(x) tmp = -1.0 + ((x * (x * -0.5)) + ((-0.4166666666666667 * (x ^ 3.0)) - x)); end
code[x_] := N[(-1.0 + N[(N[(x * N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.4166666666666667 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left(x \cdot \left(x \cdot -0.5\right) + \left(-0.4166666666666667 \cdot {x}^{3} - x\right)\right)
\end{array}
Initial program 2.5%
sub-neg2.5%
log1p-def3.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
*-commutative100.0%
unpow2100.0%
associate-*r*100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (+ (* x (* x -0.5)) (- -1.0 x)))
double code(double x) {
return (x * (x * -0.5)) + (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * (x * (-0.5d0))) + ((-1.0d0) - x)
end function
public static double code(double x) {
return (x * (x * -0.5)) + (-1.0 - x);
}
def code(x): return (x * (x * -0.5)) + (-1.0 - x)
function code(x) return Float64(Float64(x * Float64(x * -0.5)) + Float64(-1.0 - x)) end
function tmp = code(x) tmp = (x * (x * -0.5)) + (-1.0 - x); end
code[x_] := N[(N[(x * N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot -0.5\right) + \left(-1 - x\right)
\end{array}
Initial program 2.5%
sub-neg2.5%
log1p-def3.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
associate--l+99.9%
*-commutative99.9%
unpow299.9%
associate-*l*99.9%
fma-def99.9%
sub-neg99.9%
metadata-eval99.9%
+-commutative99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
fma-udef99.9%
associate-*r*99.9%
unpow299.9%
*-commutative99.9%
+-commutative99.9%
*-commutative99.9%
unpow299.9%
associate-*r*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (+ -1.0 (* x (+ (* x -0.5) -1.0))))
double code(double x) {
return -1.0 + (x * ((x * -0.5) + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + (x * ((x * (-0.5d0)) + (-1.0d0)))
end function
public static double code(double x) {
return -1.0 + (x * ((x * -0.5) + -1.0));
}
def code(x): return -1.0 + (x * ((x * -0.5) + -1.0))
function code(x) return Float64(-1.0 + Float64(x * Float64(Float64(x * -0.5) + -1.0))) end
function tmp = code(x) tmp = -1.0 + (x * ((x * -0.5) + -1.0)); end
code[x_] := N[(-1.0 + N[(x * N[(N[(x * -0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + x \cdot \left(x \cdot -0.5 + -1\right)
\end{array}
Initial program 2.5%
sub-neg2.5%
log1p-def3.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
associate--l+99.9%
*-commutative99.9%
unpow299.9%
associate-*l*99.9%
fma-def99.9%
sub-neg99.9%
metadata-eval99.9%
+-commutative99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
fma-udef99.9%
associate-*r*99.9%
unpow299.9%
*-commutative99.9%
+-commutative99.9%
*-commutative99.9%
unpow299.9%
associate-*r*99.9%
Applied egg-rr99.9%
associate-+l-99.9%
*-un-lft-identity99.9%
*-commutative99.9%
distribute-rgt-out--99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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 2.5%
sub-neg2.5%
log1p-def3.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
mul-1-neg99.5%
unsub-neg99.5%
Simplified99.5%
Final simplification99.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 2.5%
sub-neg2.5%
log1p-def3.6%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (- (+ (+ (+ 1.0 x) (/ (* x x) 2.0)) (* 0.4166666666666667 (pow x 3.0)))))
double code(double x) {
return -(((1.0 + x) + ((x * x) / 2.0)) + (0.4166666666666667 * pow(x, 3.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = -(((1.0d0 + x) + ((x * x) / 2.0d0)) + (0.4166666666666667d0 * (x ** 3.0d0)))
end function
public static double code(double x) {
return -(((1.0 + x) + ((x * x) / 2.0)) + (0.4166666666666667 * Math.pow(x, 3.0)));
}
def code(x): return -(((1.0 + x) + ((x * x) / 2.0)) + (0.4166666666666667 * math.pow(x, 3.0)))
function code(x) return Float64(-Float64(Float64(Float64(1.0 + x) + Float64(Float64(x * x) / 2.0)) + Float64(0.4166666666666667 * (x ^ 3.0)))) end
function tmp = code(x) tmp = -(((1.0 + x) + ((x * x) / 2.0)) + (0.4166666666666667 * (x ^ 3.0))); end
code[x_] := (-N[(N[(N[(1.0 + x), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + N[(0.4166666666666667 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision])
\begin{array}{l}
\\
-\left(\left(\left(1 + x\right) + \frac{x \cdot x}{2}\right) + 0.4166666666666667 \cdot {x}^{3}\right)
\end{array}
herbie shell --seed 2023224
(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))))