
(FPCore (x) :precision binary64 (- (log (- (/ 1.0 x) 1.0))))
double code(double x) {
return -log(((1.0 / x) - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = -log(((1.0d0 / x) - 1.0d0))
end function
public static double code(double x) {
return -Math.log(((1.0 / x) - 1.0));
}
def code(x): return -math.log(((1.0 / x) - 1.0))
function code(x) return Float64(-log(Float64(Float64(1.0 / x) - 1.0))) end
function tmp = code(x) tmp = -log(((1.0 / x) - 1.0)); end
code[x_] := (-N[Log[N[(N[(1.0 / x), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}
\\
-\log \left(\frac{1}{x} - 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (log (- (/ 1.0 x) 1.0))))
double code(double x) {
return -log(((1.0 / x) - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = -log(((1.0d0 / x) - 1.0d0))
end function
public static double code(double x) {
return -Math.log(((1.0 / x) - 1.0));
}
def code(x): return -math.log(((1.0 / x) - 1.0))
function code(x) return Float64(-log(Float64(Float64(1.0 / x) - 1.0))) end
function tmp = code(x) tmp = -log(((1.0 / x) - 1.0)); end
code[x_] := (-N[Log[N[(N[(1.0 / x), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}
\\
-\log \left(\frac{1}{x} - 1\right)
\end{array}
(FPCore (x) :precision binary64 (log (/ (* (+ 1.0 x) (fma x x 1.0)) (- (/ 1.0 x) (* x (* x x))))))
double code(double x) {
return log((((1.0 + x) * fma(x, x, 1.0)) / ((1.0 / x) - (x * (x * x)))));
}
function code(x) return log(Float64(Float64(Float64(1.0 + x) * fma(x, x, 1.0)) / Float64(Float64(1.0 / x) - Float64(x * Float64(x * x))))) end
code[x_] := N[Log[N[(N[(N[(1.0 + x), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\frac{\left(1 + x\right) \cdot \mathsf{fma}\left(x, x, 1\right)}{\frac{1}{x} - x \cdot \left(x \cdot x\right)}\right)
\end{array}
Initial program 100.0%
Applied egg-rr26.5%
Taylor expanded in x around 0
/-lowering-/.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
associate-+r+N/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
distribute-lft-outN/A
+-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
unpow2N/A
accelerator-lowering-fma.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6426.5
Simplified26.5%
neg-logN/A
clear-numN/A
log-lowering-log.f64N/A
associate-/l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
Applied egg-rr26.5%
Taylor expanded in x around 0
mul-1-negN/A
unsub-negN/A
div-subN/A
metadata-evalN/A
pow-plusN/A
*-lft-identityN/A
lft-mult-inverseN/A
associate-*r*N/A
unpow2N/A
unpow3N/A
associate-*l/N/A
*-lft-identityN/A
associate-/l*N/A
pow-sqrN/A
metadata-evalN/A
associate-/l/N/A
metadata-evalN/A
pow-sqrN/A
unpow2N/A
cube-multN/A
associate-/l*N/A
Simplified100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (* x (* x x))))
(if (<= (- (log (+ (/ 1.0 x) -1.0))) -250.0)
(* x (* x 0.5))
(/
(fma x (* x x) (* t_0 (* t_0 0.125)))
(fma x (* (* x x) -0.5) (* (* x x) (* (* x x) 0.25)))))))
double code(double x) {
double t_0 = x * (x * x);
double tmp;
if (-log(((1.0 / x) + -1.0)) <= -250.0) {
tmp = x * (x * 0.5);
} else {
tmp = fma(x, (x * x), (t_0 * (t_0 * 0.125))) / fma(x, ((x * x) * -0.5), ((x * x) * ((x * x) * 0.25)));
}
return tmp;
}
function code(x) t_0 = Float64(x * Float64(x * x)) tmp = 0.0 if (Float64(-log(Float64(Float64(1.0 / x) + -1.0))) <= -250.0) tmp = Float64(x * Float64(x * 0.5)); else tmp = Float64(fma(x, Float64(x * x), Float64(t_0 * Float64(t_0 * 0.125))) / fma(x, Float64(Float64(x * x) * -0.5), Float64(Float64(x * x) * Float64(Float64(x * x) * 0.25)))); end return tmp end
code[x_] := Block[{t$95$0 = N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[(-N[Log[N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]), -250.0], N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(x * x), $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(x \cdot x\right)\\
\mathbf{if}\;-\log \left(\frac{1}{x} + -1\right) \leq -250:\\
\;\;\;\;x \cdot \left(x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x \cdot x, t\_0 \cdot \left(t\_0 \cdot 0.125\right)\right)}{\mathsf{fma}\left(x, \left(x \cdot x\right) \cdot -0.5, \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.25\right)\right)}\\
\end{array}
\end{array}
if (neg.f64 (log.f64 (-.f64 (/.f64 #s(literal 1 binary64) x) #s(literal 1 binary64)))) < -250Initial program 100.0%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f64100.0
Simplified100.0%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f643.0
Simplified3.0%
if -250 < (neg.f64 (log.f64 (-.f64 (/.f64 #s(literal 1 binary64) x) #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f6497.8
Simplified97.8%
Taylor expanded in x around inf
distribute-lft-inN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f641.9
Simplified1.9%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr1.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6414.9
Simplified14.9%
Final simplification7.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (* x (* x x))))
(if (<= (- (log (+ (/ 1.0 x) -1.0))) -250.0)
(* x (* x 0.5))
(/
(fma x (* x x) (* t_0 (* t_0 0.125)))
(* (* x t_0) (+ 0.25 (/ -0.5 x)))))))
double code(double x) {
double t_0 = x * (x * x);
double tmp;
if (-log(((1.0 / x) + -1.0)) <= -250.0) {
tmp = x * (x * 0.5);
} else {
tmp = fma(x, (x * x), (t_0 * (t_0 * 0.125))) / ((x * t_0) * (0.25 + (-0.5 / x)));
}
return tmp;
}
function code(x) t_0 = Float64(x * Float64(x * x)) tmp = 0.0 if (Float64(-log(Float64(Float64(1.0 / x) + -1.0))) <= -250.0) tmp = Float64(x * Float64(x * 0.5)); else tmp = Float64(fma(x, Float64(x * x), Float64(t_0 * Float64(t_0 * 0.125))) / Float64(Float64(x * t_0) * Float64(0.25 + Float64(-0.5 / x)))); end return tmp end
code[x_] := Block[{t$95$0 = N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[(-N[Log[N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]), -250.0], N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(x * x), $MachinePrecision] + N[(t$95$0 * N[(t$95$0 * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * t$95$0), $MachinePrecision] * N[(0.25 + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(x \cdot x\right)\\
\mathbf{if}\;-\log \left(\frac{1}{x} + -1\right) \leq -250:\\
\;\;\;\;x \cdot \left(x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x \cdot x, t\_0 \cdot \left(t\_0 \cdot 0.125\right)\right)}{\left(x \cdot t\_0\right) \cdot \left(0.25 + \frac{-0.5}{x}\right)}\\
\end{array}
\end{array}
if (neg.f64 (log.f64 (-.f64 (/.f64 #s(literal 1 binary64) x) #s(literal 1 binary64)))) < -250Initial program 100.0%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f64100.0
Simplified100.0%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f643.0
Simplified3.0%
if -250 < (neg.f64 (log.f64 (-.f64 (/.f64 #s(literal 1 binary64) x) #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f6497.8
Simplified97.8%
Taylor expanded in x around inf
distribute-lft-inN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f641.9
Simplified1.9%
flip3-+N/A
/-lowering-/.f64N/A
Applied egg-rr1.9%
Taylor expanded in x around inf
Simplified11.9%
Final simplification6.4%
(FPCore (x) :precision binary64 (- (log (+ (/ 1.0 x) -1.0))))
double code(double x) {
return -log(((1.0 / x) + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = -log(((1.0d0 / x) + (-1.0d0)))
end function
public static double code(double x) {
return -Math.log(((1.0 / x) + -1.0));
}
def code(x): return -math.log(((1.0 / x) + -1.0))
function code(x) return Float64(-log(Float64(Float64(1.0 / x) + -1.0))) end
function tmp = code(x) tmp = -log(((1.0 / x) + -1.0)); end
code[x_] := (-N[Log[N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}
\\
-\log \left(\frac{1}{x} + -1\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (fma x (fma x 0.5 1.0) (log x)))
double code(double x) {
return fma(x, fma(x, 0.5, 1.0), log(x));
}
function code(x) return fma(x, fma(x, 0.5, 1.0), log(x)) end
code[x_] := N[(x * N[(x * 0.5 + 1.0), $MachinePrecision] + N[Log[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.5, 1\right), \log x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f6499.2
Simplified99.2%
(FPCore (x) :precision binary64 (+ x (log x)))
double code(double x) {
return x + log(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + log(x)
end function
public static double code(double x) {
return x + Math.log(x);
}
def code(x): return x + math.log(x)
function code(x) return Float64(x + log(x)) end
function tmp = code(x) tmp = x + log(x); end
code[x_] := N[(x + N[Log[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \log x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
remove-double-negN/A
+-lowering-+.f64N/A
log-lowering-log.f6498.9
Simplified98.9%
(FPCore (x) :precision binary64 (log x))
double code(double x) {
return log(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = log(x)
end function
public static double code(double x) {
return Math.log(x);
}
def code(x): return math.log(x)
function code(x) return log(x) end
function tmp = code(x) tmp = log(x); end
code[x_] := N[Log[x], $MachinePrecision]
\begin{array}{l}
\\
\log x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
log-lowering-log.f6497.5
Simplified97.5%
(FPCore (x) :precision binary64 (* x (* x 0.5)))
double code(double x) {
return x * (x * 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * 0.5d0)
end function
public static double code(double x) {
return x * (x * 0.5);
}
def code(x): return x * (x * 0.5)
function code(x) return Float64(x * Float64(x * 0.5)) end
function tmp = code(x) tmp = x * (x * 0.5); end
code[x_] := N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f6499.2
Simplified99.2%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f642.7
Simplified2.7%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
remove-double-negN/A
+-lowering-+.f64N/A
log-lowering-log.f6498.9
Simplified98.9%
Taylor expanded in x around inf
Simplified2.3%
herbie shell --seed 2024205
(FPCore (x)
:name "neg log"
:precision binary64
(- (log (- (/ 1.0 x) 1.0))))