
(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 4 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 38.4%
log1p-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (/ (* x 2.0) (+ x 2.0)))
double code(double x) {
return (x * 2.0) / (x + 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 2.0d0) / (x + 2.0d0)
end function
public static double code(double x) {
return (x * 2.0) / (x + 2.0);
}
def code(x): return (x * 2.0) / (x + 2.0)
function code(x) return Float64(Float64(x * 2.0) / Float64(x + 2.0)) end
function tmp = code(x) tmp = (x * 2.0) / (x + 2.0); end
code[x_] := N[(N[(x * 2.0), $MachinePrecision] / N[(x + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{x + 2}
\end{array}
Initial program 38.4%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 67.6%
expm1-log1p-u67.6%
expm1-udef6.6%
flip--6.4%
pow26.4%
log1p-udef6.4%
rem-exp-log6.4%
+-commutative6.4%
metadata-eval6.4%
log1p-udef6.4%
rem-exp-log6.4%
+-commutative6.4%
Applied egg-rr6.4%
unpow26.4%
difference-of-sqr-16.4%
associate-+l+6.4%
metadata-eval6.4%
associate--l+67.5%
metadata-eval67.5%
+-rgt-identity67.5%
associate-+l+67.5%
metadata-eval67.5%
Simplified67.5%
Taylor expanded in x around 0 71.1%
*-commutative71.1%
Simplified71.1%
Final simplification71.1%
(FPCore (x) :precision binary64 (if (<= x 2.0) x 2.0))
double code(double x) {
double tmp;
if (x <= 2.0) {
tmp = x;
} else {
tmp = 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.0d0) then
tmp = x
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2.0) {
tmp = x;
} else {
tmp = 2.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 2.0: tmp = x else: tmp = 2.0 return tmp
function code(x) tmp = 0.0 if (x <= 2.0) tmp = x; else tmp = 2.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2.0) tmp = x; else tmp = 2.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2.0], x, 2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if x < 2Initial program 8.4%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 97.9%
if 2 < x Initial program 100.0%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 5.6%
expm1-log1p-u5.6%
expm1-udef5.6%
flip--5.3%
pow25.3%
log1p-udef5.3%
rem-exp-log5.3%
+-commutative5.3%
metadata-eval5.3%
log1p-udef5.3%
rem-exp-log5.3%
+-commutative5.3%
Applied egg-rr5.3%
unpow25.3%
difference-of-sqr-15.3%
associate-+l+5.3%
metadata-eval5.3%
associate--l+5.3%
metadata-eval5.3%
+-rgt-identity5.3%
associate-+l+5.3%
metadata-eval5.3%
Simplified5.3%
Taylor expanded in x around 0 14.5%
*-commutative14.5%
Simplified14.5%
Taylor expanded in x around inf 14.5%
Final simplification70.5%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 38.4%
log1p-def100.0%
Simplified100.0%
Taylor expanded in x around 0 67.6%
expm1-log1p-u67.6%
expm1-udef6.6%
flip--6.4%
pow26.4%
log1p-udef6.4%
rem-exp-log6.4%
+-commutative6.4%
metadata-eval6.4%
log1p-udef6.4%
rem-exp-log6.4%
+-commutative6.4%
Applied egg-rr6.4%
unpow26.4%
difference-of-sqr-16.4%
associate-+l+6.4%
metadata-eval6.4%
associate--l+67.5%
metadata-eval67.5%
+-rgt-identity67.5%
associate-+l+67.5%
metadata-eval67.5%
Simplified67.5%
Taylor expanded in x around 0 71.1%
*-commutative71.1%
Simplified71.1%
Taylor expanded in x around inf 7.4%
Final simplification7.4%
(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 2024096
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:herbie-target
(if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))
(log (+ 1.0 x)))