
(FPCore (x) :precision binary64 (log (+ 1.0 x)))
double code(double x) {
return log((1.0 + x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((1.0d0 + x))
end function
public static double code(double x) {
return Math.log((1.0 + x));
}
def code(x): return math.log((1.0 + x))
function code(x) return log(Float64(1.0 + x)) end
function tmp = code(x) tmp = log((1.0 + x)); end
code[x_] := N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\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)))
double code(double x) {
return log((1.0 + x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((1.0d0 + x))
end function
public static double code(double x) {
return Math.log((1.0 + x));
}
def code(x): return math.log((1.0 + x))
function code(x) return log(Float64(1.0 + x)) end
function tmp = code(x) tmp = log((1.0 + x)); end
code[x_] := N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(1 + x\right)
\end{array}
(FPCore (x) :precision binary64 (log1p x))
double code(double x) {
return log1p(x);
}
public static double code(double x) {
return Math.log1p(x);
}
def code(x): return math.log1p(x)
function code(x) return log1p(x) end
code[x_] := N[Log[1 + x], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(x\right)
\end{array}
Initial program 42.0%
lower-log1p.f64100.0
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (fma (* x 0.25) (/ x (fma x -0.3333333333333333 -0.5)) x))
double code(double x) {
return fma((x * 0.25), (x / fma(x, -0.3333333333333333, -0.5)), x);
}
function code(x) return fma(Float64(x * 0.25), Float64(x / fma(x, -0.3333333333333333, -0.5)), x) end
code[x_] := N[(N[(x * 0.25), $MachinePrecision] * N[(x / N[(x * -0.3333333333333333 + -0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot 0.25, \frac{x}{\mathsf{fma}\left(x, -0.3333333333333333, -0.5\right)}, x\right)
\end{array}
Initial program 42.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.6
Simplified64.6%
flip-+N/A
lower-/.f64N/A
sub-negN/A
swap-sqrN/A
lift-*.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lower-fma.f64N/A
metadata-eval64.6
Applied egg-rr64.6%
Taylor expanded in x around 0
Simplified64.5%
lift-fma.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
frac-2negN/A
associate-*l/N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f64N/A
Applied egg-rr65.1%
(FPCore (x) :precision binary64 (* x (fma x (/ -0.25 (fma x 0.3333333333333333 0.5)) 1.0)))
double code(double x) {
return x * fma(x, (-0.25 / fma(x, 0.3333333333333333, 0.5)), 1.0);
}
function code(x) return Float64(x * fma(x, Float64(-0.25 / fma(x, 0.3333333333333333, 0.5)), 1.0)) end
code[x_] := N[(x * N[(x * N[(-0.25 / N[(x * 0.3333333333333333 + 0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, \frac{-0.25}{\mathsf{fma}\left(x, 0.3333333333333333, 0.5\right)}, 1\right)
\end{array}
Initial program 42.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.6
Simplified64.6%
flip-+N/A
lower-/.f64N/A
sub-negN/A
swap-sqrN/A
lift-*.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lower-fma.f64N/A
metadata-eval64.6
Applied egg-rr64.6%
Taylor expanded in x around 0
Simplified64.5%
lift-fma.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
distribute-lft1-inN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f6465.1
Applied egg-rr65.1%
Final simplification65.1%
(FPCore (x) :precision binary64 (fma (fma x 0.3333333333333333 -0.5) (* x x) x))
double code(double x) {
return fma(fma(x, 0.3333333333333333, -0.5), (x * x), x);
}
function code(x) return fma(fma(x, 0.3333333333333333, -0.5), Float64(x * x), x) end
code[x_] := N[(N[(x * 0.3333333333333333 + -0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), x \cdot x, x\right)
\end{array}
Initial program 42.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6464.6
Simplified64.6%
(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 42.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6463.2
Simplified63.2%
lift-*.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
lower-*.f64N/A
lift-*.f64N/A
lower-fma.f6463.2
Applied egg-rr63.2%
Taylor expanded in x around 0
Simplified64.1%
Final simplification64.1%
(FPCore (x) :precision binary64 (if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0))))
double code(double x) {
double tmp;
if ((1.0 + x) == 1.0) {
tmp = x;
} else {
tmp = (x * log((1.0 + x))) / ((1.0 + x) - 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((1.0d0 + x) == 1.0d0) then
tmp = x
else
tmp = (x * log((1.0d0 + x))) / ((1.0d0 + x) - 1.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((1.0 + x) == 1.0) {
tmp = x;
} else {
tmp = (x * Math.log((1.0 + x))) / ((1.0 + x) - 1.0);
}
return tmp;
}
def code(x): tmp = 0 if (1.0 + x) == 1.0: tmp = x else: tmp = (x * math.log((1.0 + x))) / ((1.0 + x) - 1.0) return tmp
function code(x) tmp = 0.0 if (Float64(1.0 + x) == 1.0) tmp = x; else tmp = Float64(Float64(x * log(Float64(1.0 + x))) / Float64(Float64(1.0 + x) - 1.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((1.0 + x) == 1.0) tmp = x; else tmp = (x * log((1.0 + x))) / ((1.0 + x) - 1.0); end tmp_2 = tmp; end
code[x_] := If[Equal[N[(1.0 + x), $MachinePrecision], 1.0], x, N[(N[(x * N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 + x = 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \log \left(1 + x\right)}{\left(1 + x\right) - 1}\\
\end{array}
\end{array}
herbie shell --seed 2024207
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:alt
(! :herbie-platform default (if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1))))
(log (+ 1.0 x)))