
(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 7 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 40.2%
log1p-define100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (if (<= x 1.58) (* x (+ 1.0 (* x (- (* x (+ 0.3333333333333333 (* x -0.25))) 0.5)))) 9.0))
double code(double x) {
double tmp;
if (x <= 1.58) {
tmp = x * (1.0 + (x * ((x * (0.3333333333333333 + (x * -0.25))) - 0.5)));
} else {
tmp = 9.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.58d0) then
tmp = x * (1.0d0 + (x * ((x * (0.3333333333333333d0 + (x * (-0.25d0)))) - 0.5d0)))
else
tmp = 9.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.58) {
tmp = x * (1.0 + (x * ((x * (0.3333333333333333 + (x * -0.25))) - 0.5)));
} else {
tmp = 9.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.58: tmp = x * (1.0 + (x * ((x * (0.3333333333333333 + (x * -0.25))) - 0.5))) else: tmp = 9.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.58) tmp = Float64(x * Float64(1.0 + Float64(x * Float64(Float64(x * Float64(0.3333333333333333 + Float64(x * -0.25))) - 0.5)))); else tmp = 9.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.58) tmp = x * (1.0 + (x * ((x * (0.3333333333333333 + (x * -0.25))) - 0.5))); else tmp = 9.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.58], N[(x * N[(1.0 + N[(x * N[(N[(x * N[(0.3333333333333333 + N[(x * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 9.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.58:\\
\;\;\;\;x \cdot \left(1 + x \cdot \left(x \cdot \left(0.3333333333333333 + x \cdot -0.25\right) - 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;9\\
\end{array}
\end{array}
if x < 1.5800000000000001Initial program 9.5%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
if 1.5800000000000001 < x Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 0.8%
*-commutative0.8%
Simplified0.8%
Taylor expanded in x around inf 0.8%
Taylor expanded in x around 0 5.1%
Applied egg-rr15.2%
Final simplification70.6%
(FPCore (x) :precision binary64 (if (<= x 3.2) (* x (+ 1.0 (* x (- (* x 0.3333333333333333) 0.5)))) 9.0))
double code(double x) {
double tmp;
if (x <= 3.2) {
tmp = x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5)));
} else {
tmp = 9.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 3.2d0) then
tmp = x * (1.0d0 + (x * ((x * 0.3333333333333333d0) - 0.5d0)))
else
tmp = 9.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 3.2) {
tmp = x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5)));
} else {
tmp = 9.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 3.2: tmp = x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5))) else: tmp = 9.0 return tmp
function code(x) tmp = 0.0 if (x <= 3.2) tmp = Float64(x * Float64(1.0 + Float64(x * Float64(Float64(x * 0.3333333333333333) - 0.5)))); else tmp = 9.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 3.2) tmp = x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5))); else tmp = 9.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 3.2], N[(x * N[(1.0 + N[(x * N[(N[(x * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 9.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.2:\\
\;\;\;\;x \cdot \left(1 + x \cdot \left(x \cdot 0.3333333333333333 - 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;9\\
\end{array}
\end{array}
if x < 3.2000000000000002Initial program 9.5%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
if 3.2000000000000002 < x Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 0.8%
*-commutative0.8%
Simplified0.8%
Taylor expanded in x around inf 0.8%
Taylor expanded in x around 0 5.1%
Applied egg-rr15.2%
Final simplification70.5%
(FPCore (x) :precision binary64 (if (<= x 1.9) (* x (+ 1.0 (* x -0.5))) 9.0))
double code(double x) {
double tmp;
if (x <= 1.9) {
tmp = x * (1.0 + (x * -0.5));
} else {
tmp = 9.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.9d0) then
tmp = x * (1.0d0 + (x * (-0.5d0)))
else
tmp = 9.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.9) {
tmp = x * (1.0 + (x * -0.5));
} else {
tmp = 9.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.9: tmp = x * (1.0 + (x * -0.5)) else: tmp = 9.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.9) tmp = Float64(x * Float64(1.0 + Float64(x * -0.5))); else tmp = 9.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.9) tmp = x * (1.0 + (x * -0.5)); else tmp = 9.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.9], N[(x * N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 9.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9:\\
\;\;\;\;x \cdot \left(1 + x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;9\\
\end{array}
\end{array}
if x < 1.8999999999999999Initial program 9.5%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 98.6%
*-commutative98.6%
Simplified98.6%
if 1.8999999999999999 < x Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 0.8%
*-commutative0.8%
Simplified0.8%
Taylor expanded in x around inf 0.8%
Taylor expanded in x around 0 5.1%
Applied egg-rr15.2%
(FPCore (x) :precision binary64 (if (<= x 9.0) x 9.0))
double code(double x) {
double tmp;
if (x <= 9.0) {
tmp = x;
} else {
tmp = 9.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 9.0d0) then
tmp = x
else
tmp = 9.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 9.0) {
tmp = x;
} else {
tmp = 9.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 9.0: tmp = x else: tmp = 9.0 return tmp
function code(x) tmp = 0.0 if (x <= 9.0) tmp = x; else tmp = 9.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 9.0) tmp = x; else tmp = 9.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 9.0], x, 9.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;9\\
\end{array}
\end{array}
if x < 9Initial program 9.5%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 97.3%
if 9 < x Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 0.8%
*-commutative0.8%
Simplified0.8%
Taylor expanded in x around inf 0.8%
Taylor expanded in x around 0 5.1%
Applied egg-rr15.2%
(FPCore (x) :precision binary64 9.0)
double code(double x) {
return 9.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 9.0d0
end function
public static double code(double x) {
return 9.0;
}
def code(x): return 9.0
function code(x) return 9.0 end
function tmp = code(x) tmp = 9.0; end
code[x_] := 9.0
\begin{array}{l}
\\
9
\end{array}
Initial program 40.2%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 65.4%
*-commutative65.4%
Simplified65.4%
Taylor expanded in x around inf 65.2%
Taylor expanded in x around 0 65.8%
Applied egg-rr7.7%
(FPCore (x) :precision binary64 0.5)
double code(double x) {
return 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0
end function
public static double code(double x) {
return 0.5;
}
def code(x): return 0.5
function code(x) return 0.5 end
function tmp = code(x) tmp = 0.5; end
code[x_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 40.2%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around 0 65.4%
*-commutative65.4%
Simplified65.4%
Taylor expanded in x around inf 65.2%
Taylor expanded in x around 0 65.8%
Applied egg-rr7.3%
(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 2024148
(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)))