
(FPCore (x) :precision binary64 (- (exp x) 1.0))
double code(double x) {
return exp(x) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) - 1.0d0
end function
public static double code(double x) {
return Math.exp(x) - 1.0;
}
def code(x): return math.exp(x) - 1.0
function code(x) return Float64(exp(x) - 1.0) end
function tmp = code(x) tmp = exp(x) - 1.0; end
code[x_] := N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{x} - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (exp x) 1.0))
double code(double x) {
return exp(x) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) - 1.0d0
end function
public static double code(double x) {
return Math.exp(x) - 1.0;
}
def code(x): return math.exp(x) - 1.0
function code(x) return Float64(exp(x) - 1.0) end
function tmp = code(x) tmp = exp(x) - 1.0; end
code[x_] := N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{x} - 1
\end{array}
(FPCore (x) :precision binary64 (expm1 x))
double code(double x) {
return expm1(x);
}
public static double code(double x) {
return Math.expm1(x);
}
def code(x): return math.expm1(x)
function code(x) return expm1(x) end
code[x_] := N[(Exp[x] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(x\right)
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ -0.5 (* x 0.08333333333333333))) (t_1 (* x t_0)))
(*
(/ x (+ 1.0 (* t_1 (* (* x x) (* t_0 t_0)))))
(+ 1.0 (* t_1 (+ t_1 -1.0))))))
double code(double x) {
double t_0 = -0.5 + (x * 0.08333333333333333);
double t_1 = x * t_0;
return (x / (1.0 + (t_1 * ((x * x) * (t_0 * t_0))))) * (1.0 + (t_1 * (t_1 + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
t_0 = (-0.5d0) + (x * 0.08333333333333333d0)
t_1 = x * t_0
code = (x / (1.0d0 + (t_1 * ((x * x) * (t_0 * t_0))))) * (1.0d0 + (t_1 * (t_1 + (-1.0d0))))
end function
public static double code(double x) {
double t_0 = -0.5 + (x * 0.08333333333333333);
double t_1 = x * t_0;
return (x / (1.0 + (t_1 * ((x * x) * (t_0 * t_0))))) * (1.0 + (t_1 * (t_1 + -1.0)));
}
def code(x): t_0 = -0.5 + (x * 0.08333333333333333) t_1 = x * t_0 return (x / (1.0 + (t_1 * ((x * x) * (t_0 * t_0))))) * (1.0 + (t_1 * (t_1 + -1.0)))
function code(x) t_0 = Float64(-0.5 + Float64(x * 0.08333333333333333)) t_1 = Float64(x * t_0) return Float64(Float64(x / Float64(1.0 + Float64(t_1 * Float64(Float64(x * x) * Float64(t_0 * t_0))))) * Float64(1.0 + Float64(t_1 * Float64(t_1 + -1.0)))) end
function tmp = code(x) t_0 = -0.5 + (x * 0.08333333333333333); t_1 = x * t_0; tmp = (x / (1.0 + (t_1 * ((x * x) * (t_0 * t_0))))) * (1.0 + (t_1 * (t_1 + -1.0))); end
code[x_] := Block[{t$95$0 = N[(-0.5 + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * t$95$0), $MachinePrecision]}, N[(N[(x / N[(1.0 + N[(t$95$1 * N[(N[(x * x), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(t$95$1 * N[(t$95$1 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 + x \cdot 0.08333333333333333\\
t_1 := x \cdot t\_0\\
\frac{x}{1 + t\_1 \cdot \left(\left(x \cdot x\right) \cdot \left(t\_0 \cdot t\_0\right)\right)} \cdot \left(1 + t\_1 \cdot \left(t\_1 + -1\right)\right)
\end{array}
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4%
Simplified99.4%
distribute-lft-inN/A
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr32.3%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.1%
Simplified99.1%
clear-numN/A
flip3-+N/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (let* ((t_0 (+ -0.5 (* x 0.08333333333333333)))) (* (/ x (- 1.0 (* (* x x) (* t_0 t_0)))) (- 1.0 (* x t_0)))))
double code(double x) {
double t_0 = -0.5 + (x * 0.08333333333333333);
return (x / (1.0 - ((x * x) * (t_0 * t_0)))) * (1.0 - (x * t_0));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = (-0.5d0) + (x * 0.08333333333333333d0)
code = (x / (1.0d0 - ((x * x) * (t_0 * t_0)))) * (1.0d0 - (x * t_0))
end function
public static double code(double x) {
double t_0 = -0.5 + (x * 0.08333333333333333);
return (x / (1.0 - ((x * x) * (t_0 * t_0)))) * (1.0 - (x * t_0));
}
def code(x): t_0 = -0.5 + (x * 0.08333333333333333) return (x / (1.0 - ((x * x) * (t_0 * t_0)))) * (1.0 - (x * t_0))
function code(x) t_0 = Float64(-0.5 + Float64(x * 0.08333333333333333)) return Float64(Float64(x / Float64(1.0 - Float64(Float64(x * x) * Float64(t_0 * t_0)))) * Float64(1.0 - Float64(x * t_0))) end
function tmp = code(x) t_0 = -0.5 + (x * 0.08333333333333333); tmp = (x / (1.0 - ((x * x) * (t_0 * t_0)))) * (1.0 - (x * t_0)); end
code[x_] := Block[{t$95$0 = N[(-0.5 + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]}, N[(N[(x / N[(1.0 - N[(N[(x * x), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 + x \cdot 0.08333333333333333\\
\frac{x}{1 - \left(x \cdot x\right) \cdot \left(t\_0 \cdot t\_0\right)} \cdot \left(1 - x \cdot t\_0\right)
\end{array}
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4%
Simplified99.4%
distribute-lft-inN/A
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr32.3%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.1%
Simplified99.1%
clear-numN/A
flip-+N/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr99.5%
(FPCore (x) :precision binary64 (/ x (+ 1.0 (* x (+ -0.5 (* x 0.08333333333333333))))))
double code(double x) {
return x / (1.0 + (x * (-0.5 + (x * 0.08333333333333333))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (1.0d0 + (x * ((-0.5d0) + (x * 0.08333333333333333d0))))
end function
public static double code(double x) {
return x / (1.0 + (x * (-0.5 + (x * 0.08333333333333333))));
}
def code(x): return x / (1.0 + (x * (-0.5 + (x * 0.08333333333333333))))
function code(x) return Float64(x / Float64(1.0 + Float64(x * Float64(-0.5 + Float64(x * 0.08333333333333333))))) end
function tmp = code(x) tmp = x / (1.0 + (x * (-0.5 + (x * 0.08333333333333333)))); end
code[x_] := N[(x / N[(1.0 + N[(x * N[(-0.5 + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)}
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4%
Simplified99.4%
distribute-lft-inN/A
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr32.3%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.1%
Simplified99.1%
clear-numN/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f6499.5%
Applied egg-rr99.5%
(FPCore (x) :precision binary64 (+ x (* x (* x (+ 0.5 (* x 0.16666666666666666))))))
double code(double x) {
return x + (x * (x * (0.5 + (x * 0.16666666666666666))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + (x * (x * (0.5d0 + (x * 0.16666666666666666d0))))
end function
public static double code(double x) {
return x + (x * (x * (0.5 + (x * 0.16666666666666666))));
}
def code(x): return x + (x * (x * (0.5 + (x * 0.16666666666666666))))
function code(x) return Float64(x + Float64(x * Float64(x * Float64(0.5 + Float64(x * 0.16666666666666666))))) end
function tmp = code(x) tmp = x + (x * (x * (0.5 + (x * 0.16666666666666666)))); end
code[x_] := N[(x + N[(x * N[(x * N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.1%
Simplified99.1%
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f6499.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x) :precision binary64 (* x (+ 1.0 (* x (+ 0.5 (* x 0.16666666666666666))))))
double code(double x) {
return x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 + (x * (0.5d0 + (x * 0.16666666666666666d0))))
end function
public static double code(double x) {
return x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))));
}
def code(x): return x * (1.0 + (x * (0.5 + (x * 0.16666666666666666))))
function code(x) return Float64(x * Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * 0.16666666666666666))))) end
function tmp = code(x) tmp = x * (1.0 + (x * (0.5 + (x * 0.16666666666666666)))); end
code[x_] := N[(x * N[(1.0 + N[(x * N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.1%
Simplified99.1%
(FPCore (x) :precision binary64 (/ x (+ 1.0 (* x -0.5))))
double code(double x) {
return x / (1.0 + (x * -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (1.0d0 + (x * (-0.5d0)))
end function
public static double code(double x) {
return x / (1.0 + (x * -0.5));
}
def code(x): return x / (1.0 + (x * -0.5))
function code(x) return Float64(x / Float64(1.0 + Float64(x * -0.5))) end
function tmp = code(x) tmp = x / (1.0 + (x * -0.5)); end
code[x_] := N[(x / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + x \cdot -0.5}
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.4%
Simplified99.4%
distribute-lft-inN/A
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr32.3%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6498.5%
Simplified98.5%
clear-numN/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f6498.9%
Applied egg-rr98.9%
(FPCore (x) :precision binary64 (+ x (* x (* x 0.5))))
double code(double x) {
return x + (x * (x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + (x * (x * 0.5d0))
end function
public static double code(double x) {
return x + (x * (x * 0.5));
}
def code(x): return x + (x * (x * 0.5))
function code(x) return Float64(x + Float64(x * Float64(x * 0.5))) end
function tmp = code(x) tmp = x + (x * (x * 0.5)); end
code[x_] := N[(x + N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \left(x \cdot 0.5\right)
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6498.9%
Simplified98.9%
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6498.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (* x (+ 1.0 (* x 0.5))))
double code(double x) {
return x * (1.0 + (x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 + (x * 0.5d0))
end function
public static double code(double x) {
return x * (1.0 + (x * 0.5));
}
def code(x): return x * (1.0 + (x * 0.5))
function code(x) return Float64(x * Float64(1.0 + Float64(x * 0.5))) end
function tmp = code(x) tmp = x * (1.0 + (x * 0.5)); end
code[x_] := N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + x \cdot 0.5\right)
\end{array}
Initial program 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6498.9%
Simplified98.9%
(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 8.1%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified98.0%
(FPCore (x) :precision binary64 (expm1 x))
double code(double x) {
return expm1(x);
}
public static double code(double x) {
return Math.expm1(x);
}
def code(x): return math.expm1(x)
function code(x) return expm1(x) end
code[x_] := N[(Exp[x] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(x\right)
\end{array}
herbie shell --seed 2024155
(FPCore (x)
:name "expm1 (example 3.7)"
:precision binary64
:pre (<= (fabs x) 1.0)
:alt
(! :herbie-platform default (expm1 x))
(- (exp x) 1.0))