
(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 9 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 7.6%
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))
(t_2 (* t_0 t_1)))
(*
x
(* (/ (- 1.0 t_1) (- 1.0 (* t_1 (* (* x t_1) t_2)))) (+ 1.0 (* x t_2))))))
double code(double x) {
double t_0 = -0.5 + (x * 0.08333333333333333);
double t_1 = x * t_0;
double t_2 = t_0 * t_1;
return x * (((1.0 - t_1) / (1.0 - (t_1 * ((x * t_1) * t_2)))) * (1.0 + (x * t_2)));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = (-0.5d0) + (x * 0.08333333333333333d0)
t_1 = x * t_0
t_2 = t_0 * t_1
code = x * (((1.0d0 - t_1) / (1.0d0 - (t_1 * ((x * t_1) * t_2)))) * (1.0d0 + (x * t_2)))
end function
public static double code(double x) {
double t_0 = -0.5 + (x * 0.08333333333333333);
double t_1 = x * t_0;
double t_2 = t_0 * t_1;
return x * (((1.0 - t_1) / (1.0 - (t_1 * ((x * t_1) * t_2)))) * (1.0 + (x * t_2)));
}
def code(x): t_0 = -0.5 + (x * 0.08333333333333333) t_1 = x * t_0 t_2 = t_0 * t_1 return x * (((1.0 - t_1) / (1.0 - (t_1 * ((x * t_1) * t_2)))) * (1.0 + (x * t_2)))
function code(x) t_0 = Float64(-0.5 + Float64(x * 0.08333333333333333)) t_1 = Float64(x * t_0) t_2 = Float64(t_0 * t_1) return Float64(x * Float64(Float64(Float64(1.0 - t_1) / Float64(1.0 - Float64(t_1 * Float64(Float64(x * t_1) * t_2)))) * Float64(1.0 + Float64(x * t_2)))) end
function tmp = code(x) t_0 = -0.5 + (x * 0.08333333333333333); t_1 = x * t_0; t_2 = t_0 * t_1; tmp = x * (((1.0 - t_1) / (1.0 - (t_1 * ((x * t_1) * t_2)))) * (1.0 + (x * t_2))); 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]}, Block[{t$95$2 = N[(t$95$0 * t$95$1), $MachinePrecision]}, N[(x * N[(N[(N[(1.0 - t$95$1), $MachinePrecision] / N[(1.0 - N[(t$95$1 * N[(N[(x * t$95$1), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(x * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 + x \cdot 0.08333333333333333\\
t_1 := x \cdot t\_0\\
t_2 := t\_0 \cdot t\_1\\
x \cdot \left(\frac{1 - t\_1}{1 - t\_1 \cdot \left(\left(x \cdot t\_1\right) \cdot t\_2\right)} \cdot \left(1 + x \cdot t\_2\right)\right)
\end{array}
\end{array}
Initial program 7.6%
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.8%
Simplified99.8%
+-commutativeN/A
flip3-+N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr99.8%
Taylor expanded in x around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.8%
Simplified99.8%
flip-+N/A
clear-numN/A
metadata-evalN/A
flip--N/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (* x (/ 1.0 (+ (+ 1.0 (* x -0.5)) (* 0.08333333333333333 (* x x))))))
double code(double x) {
return x * (1.0 / ((1.0 + (x * -0.5)) + (0.08333333333333333 * (x * x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 / ((1.0d0 + (x * (-0.5d0))) + (0.08333333333333333d0 * (x * x))))
end function
public static double code(double x) {
return x * (1.0 / ((1.0 + (x * -0.5)) + (0.08333333333333333 * (x * x))));
}
def code(x): return x * (1.0 / ((1.0 + (x * -0.5)) + (0.08333333333333333 * (x * x))))
function code(x) return Float64(x * Float64(1.0 / Float64(Float64(1.0 + Float64(x * -0.5)) + Float64(0.08333333333333333 * Float64(x * x))))) end
function tmp = code(x) tmp = x * (1.0 / ((1.0 + (x * -0.5)) + (0.08333333333333333 * (x * x)))); end
code[x_] := N[(x * N[(1.0 / N[(N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + N[(0.08333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{1}{\left(1 + x \cdot -0.5\right) + 0.08333333333333333 \cdot \left(x \cdot x\right)}
\end{array}
Initial program 7.6%
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.8%
Simplified99.8%
+-commutativeN/A
flip3-+N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr99.8%
Taylor expanded in x around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.8%
Simplified99.8%
distribute-lft-inN/A
associate-+r+N/A
+-lowering-+.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8%
Applied egg-rr99.8%
(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 7.6%
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.8%
Simplified99.8%
+-commutativeN/A
flip3-+N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr99.8%
Taylor expanded in x around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6499.8%
Simplified99.8%
un-div-invN/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f6499.8%
Applied egg-rr99.8%
(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 7.6%
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.7%
Simplified99.7%
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f6499.7%
Applied egg-rr99.7%
Final simplification99.7%
(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 7.6%
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.7%
Simplified99.7%
(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 7.6%
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-*.f6499.6%
Simplified99.6%
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.6%
Applied egg-rr99.6%
Final simplification99.6%
(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 7.6%
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-*.f6499.6%
Simplified99.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 7.6%
expm1-defineN/A
expm1-lowering-expm1.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified98.5%
(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 2024158
(FPCore (x)
:name "expm1 (example 3.7)"
:precision binary64
:pre (<= (fabs x) 1.0)
:alt
(! :herbie-platform default (expm1 x))
(- (exp x) 1.0))