
(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
double code(double x) {
return (exp(x) - 1.0) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 1.0d0) / x
end function
public static double code(double x) {
return (Math.exp(x) - 1.0) / x;
}
def code(x): return (math.exp(x) - 1.0) / x
function code(x) return Float64(Float64(exp(x) - 1.0) / x) end
function tmp = code(x) tmp = (exp(x) - 1.0) / x; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - 1}{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
double code(double x) {
return (exp(x) - 1.0) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 1.0d0) / x
end function
public static double code(double x) {
return (Math.exp(x) - 1.0) / x;
}
def code(x): return (math.exp(x) - 1.0) / x
function code(x) return Float64(Float64(exp(x) - 1.0) / x) end
function tmp = code(x) tmp = (exp(x) - 1.0) / x; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - 1}{x}
\end{array}
(FPCore (x) :precision binary64 (/ 1.0 (/ x (expm1 x))))
double code(double x) {
return 1.0 / (x / expm1(x));
}
public static double code(double x) {
return 1.0 / (x / Math.expm1(x));
}
def code(x): return 1.0 / (x / math.expm1(x))
function code(x) return Float64(1.0 / Float64(x / expm1(x))) end
code[x_] := N[(1.0 / N[(x / N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{x}{\mathsf{expm1}\left(x\right)}}
\end{array}
Initial program 59.2%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (/ (expm1 x) x))
double code(double x) {
return expm1(x) / x;
}
public static double code(double x) {
return Math.expm1(x) / x;
}
def code(x): return math.expm1(x) / x
function code(x) return Float64(expm1(x) / x) end
code[x_] := N[(N[(Exp[x] - 1), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{expm1}\left(x\right)}{x}
\end{array}
Initial program 59.2%
expm1-define100.0%
Simplified100.0%
(FPCore (x)
:precision binary64
(if (<= x -2.35)
(/ (- (- 2.0) (/ 4.0 x)) x)
(+
1.0
(*
x
(+
0.5
(*
x
(*
(+ (* (* x (* x x)) 7.233796296296296e-5) 0.004629629629629629)
(+ 36.0 (* x 9.0)))))))))
double code(double x) {
double tmp;
if (x <= -2.35) {
tmp = (-2.0 - (4.0 / x)) / x;
} else {
tmp = 1.0 + (x * (0.5 + (x * ((((x * (x * x)) * 7.233796296296296e-5) + 0.004629629629629629) * (36.0 + (x * 9.0))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.35d0)) then
tmp = (-2.0d0 - (4.0d0 / x)) / x
else
tmp = 1.0d0 + (x * (0.5d0 + (x * ((((x * (x * x)) * 7.233796296296296d-5) + 0.004629629629629629d0) * (36.0d0 + (x * 9.0d0))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.35) {
tmp = (-2.0 - (4.0 / x)) / x;
} else {
tmp = 1.0 + (x * (0.5 + (x * ((((x * (x * x)) * 7.233796296296296e-5) + 0.004629629629629629) * (36.0 + (x * 9.0))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.35: tmp = (-2.0 - (4.0 / x)) / x else: tmp = 1.0 + (x * (0.5 + (x * ((((x * (x * x)) * 7.233796296296296e-5) + 0.004629629629629629) * (36.0 + (x * 9.0)))))) return tmp
function code(x) tmp = 0.0 if (x <= -2.35) tmp = Float64(Float64(Float64(-2.0) - Float64(4.0 / x)) / x); else tmp = Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * Float64(Float64(Float64(Float64(x * Float64(x * x)) * 7.233796296296296e-5) + 0.004629629629629629) * Float64(36.0 + Float64(x * 9.0))))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.35) tmp = (-2.0 - (4.0 / x)) / x; else tmp = 1.0 + (x * (0.5 + (x * ((((x * (x * x)) * 7.233796296296296e-5) + 0.004629629629629629) * (36.0 + (x * 9.0)))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.35], N[(N[((-2.0) - N[(4.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(1.0 + N[(x * N[(0.5 + N[(x * N[(N[(N[(N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] * 7.233796296296296e-5), $MachinePrecision] + 0.004629629629629629), $MachinePrecision] * N[(36.0 + N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35:\\
\;\;\;\;\frac{\left(-2\right) - \frac{4}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(\left(\left(x \cdot \left(x \cdot x\right)\right) \cdot 7.233796296296296 \cdot 10^{-5} + 0.004629629629629629\right) \cdot \left(36 + x \cdot 9\right)\right)\right)\\
\end{array}
\end{array}
if x < -2.35000000000000009Initial program 100.0%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
div-inv100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 18.8%
*-commutative18.8%
Simplified18.8%
Taylor expanded in x around inf 18.8%
mul-1-neg18.8%
distribute-neg-frac218.8%
associate-*r/18.8%
metadata-eval18.8%
neg-sub018.8%
Simplified18.8%
if -2.35000000000000009 < x Initial program 43.3%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 88.1%
*-commutative88.1%
Simplified88.1%
flip3-+66.9%
div-inv66.9%
pow366.9%
+-commutative66.9%
pow366.9%
unpow-prod-down66.9%
pow366.9%
associate-*l*66.9%
metadata-eval66.9%
metadata-eval66.9%
metadata-eval66.9%
distribute-rgt-out--66.9%
Applied egg-rr66.9%
Taylor expanded in x around 0 95.3%
*-commutative95.3%
Simplified95.3%
Final simplification73.8%
(FPCore (x)
:precision binary64
(if (<= x 0.78)
(/ 1.0 (+ 1.0 (* x -0.5)))
(+
1.0
(*
x
(+
0.5
(*
x
(*
(+ 0.0006510416666666666 (/ 0.0026041666666666665 x))
(* (* x x) (* x x)))))))))
double code(double x) {
double tmp;
if (x <= 0.78) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * (0.5 + (x * ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * (x * x))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.78d0) then
tmp = 1.0d0 / (1.0d0 + (x * (-0.5d0)))
else
tmp = 1.0d0 + (x * (0.5d0 + (x * ((0.0006510416666666666d0 + (0.0026041666666666665d0 / x)) * ((x * x) * (x * x))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.78) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * (0.5 + (x * ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * (x * x))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.78: tmp = 1.0 / (1.0 + (x * -0.5)) else: tmp = 1.0 + (x * (0.5 + (x * ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * (x * x)))))) return tmp
function code(x) tmp = 0.0 if (x <= 0.78) tmp = Float64(1.0 / Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * Float64(Float64(0.0006510416666666666 + Float64(0.0026041666666666665 / x)) * Float64(Float64(x * x) * Float64(x * x))))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.78) tmp = 1.0 / (1.0 + (x * -0.5)); else tmp = 1.0 + (x * (0.5 + (x * ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * (x * x)))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.78], N[(1.0 / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * N[(0.5 + N[(x * N[(N[(0.0006510416666666666 + N[(0.0026041666666666665 / x), $MachinePrecision]), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.78:\\
\;\;\;\;\frac{1}{1 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(\left(0.0006510416666666666 + \frac{0.0026041666666666665}{x}\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\\
\end{array}
\end{array}
if x < 0.78000000000000003Initial program 43.6%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.6%
if 0.78000000000000003 < x Initial program 100.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 69.4%
*-commutative69.4%
Simplified69.4%
flip3-+14.5%
div-inv14.5%
pow314.5%
+-commutative14.5%
pow314.5%
unpow-prod-down14.5%
pow314.5%
associate-*l*14.5%
metadata-eval14.5%
metadata-eval14.5%
metadata-eval14.5%
distribute-rgt-out--14.5%
Applied egg-rr14.5%
Taylor expanded in x around 0 88.1%
*-commutative88.1%
Simplified88.1%
Taylor expanded in x around inf 88.1%
*-commutative88.1%
associate-*r/88.1%
metadata-eval88.1%
metadata-eval88.1%
pow-plus88.1%
unpow388.1%
associate-*r*88.1%
Simplified88.1%
Final simplification73.3%
(FPCore (x)
:precision binary64
(if (<= x 1.7)
(/ 1.0 (+ 1.0 (* x -0.5)))
(+
1.0
(*
(+ 0.0006510416666666666 (/ 0.0026041666666666665 x))
(* (* x x) (* (* x x) (* x x)))))))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * ((x * x) * (x * x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.7d0) then
tmp = 1.0d0 / (1.0d0 + (x * (-0.5d0)))
else
tmp = 1.0d0 + ((0.0006510416666666666d0 + (0.0026041666666666665d0 / x)) * ((x * x) * ((x * x) * (x * x))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * ((x * x) * (x * x))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = 1.0 / (1.0 + (x * -0.5)) else: tmp = 1.0 + ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * ((x * x) * (x * x)))) return tmp
function code(x) tmp = 0.0 if (x <= 1.7) tmp = Float64(1.0 / Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(1.0 + Float64(Float64(0.0006510416666666666 + Float64(0.0026041666666666665 / x)) * Float64(Float64(x * x) * Float64(Float64(x * x) * Float64(x * x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.7) tmp = 1.0 / (1.0 + (x * -0.5)); else tmp = 1.0 + ((0.0006510416666666666 + (0.0026041666666666665 / x)) * ((x * x) * ((x * x) * (x * x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.7], N[(1.0 / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(0.0006510416666666666 + N[(0.0026041666666666665 / x), $MachinePrecision]), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;\frac{1}{1 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(0.0006510416666666666 + \frac{0.0026041666666666665}{x}\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 43.6%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.6%
if 1.69999999999999996 < x Initial program 100.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 69.4%
*-commutative69.4%
Simplified69.4%
flip3-+14.5%
div-inv14.5%
pow314.5%
+-commutative14.5%
pow314.5%
unpow-prod-down14.5%
pow314.5%
associate-*l*14.5%
metadata-eval14.5%
metadata-eval14.5%
metadata-eval14.5%
distribute-rgt-out--14.5%
Applied egg-rr14.5%
Taylor expanded in x around 0 88.1%
*-commutative88.1%
Simplified88.1%
Taylor expanded in x around inf 88.1%
*-commutative88.1%
associate-*r/88.1%
metadata-eval88.1%
metadata-eval88.1%
pow-sqr88.1%
unpow388.1%
unpow388.1%
swap-sqr88.1%
Simplified88.1%
Final simplification73.3%
(FPCore (x) :precision binary64 (if (<= x 0.78) (/ 1.0 (+ 1.0 (* x -0.5))) (+ 1.0 (* x (+ 0.5 (* x (* 0.0006510416666666666 (* (* x x) (* x x)))))))))
double code(double x) {
double tmp;
if (x <= 0.78) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * (0.5 + (x * (0.0006510416666666666 * ((x * x) * (x * x))))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.78d0) then
tmp = 1.0d0 / (1.0d0 + (x * (-0.5d0)))
else
tmp = 1.0d0 + (x * (0.5d0 + (x * (0.0006510416666666666d0 * ((x * x) * (x * x))))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.78) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * (0.5 + (x * (0.0006510416666666666 * ((x * x) * (x * x))))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.78: tmp = 1.0 / (1.0 + (x * -0.5)) else: tmp = 1.0 + (x * (0.5 + (x * (0.0006510416666666666 * ((x * x) * (x * x)))))) return tmp
function code(x) tmp = 0.0 if (x <= 0.78) tmp = Float64(1.0 / Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * Float64(0.0006510416666666666 * Float64(Float64(x * x) * Float64(x * x))))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.78) tmp = 1.0 / (1.0 + (x * -0.5)); else tmp = 1.0 + (x * (0.5 + (x * (0.0006510416666666666 * ((x * x) * (x * x)))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.78], N[(1.0 / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * N[(0.5 + N[(x * N[(0.0006510416666666666 * N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.78:\\
\;\;\;\;\frac{1}{1 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(0.0006510416666666666 \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\\
\end{array}
\end{array}
if x < 0.78000000000000003Initial program 43.6%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.6%
if 0.78000000000000003 < x Initial program 100.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 69.4%
*-commutative69.4%
Simplified69.4%
flip3-+14.5%
div-inv14.5%
pow314.5%
+-commutative14.5%
pow314.5%
unpow-prod-down14.5%
pow314.5%
associate-*l*14.5%
metadata-eval14.5%
metadata-eval14.5%
metadata-eval14.5%
distribute-rgt-out--14.5%
Applied egg-rr14.5%
Taylor expanded in x around 0 88.1%
*-commutative88.1%
Simplified88.1%
Taylor expanded in x around inf 88.1%
metadata-eval88.1%
pow-plus88.1%
unpow388.1%
associate-*r*88.1%
Simplified88.1%
Final simplification73.3%
(FPCore (x) :precision binary64 (if (<= x 1.7) (/ 1.0 (+ 1.0 (* x -0.5))) (+ 1.0 (* 0.0006510416666666666 (* (* x x) (* (* x x) (* x x)))))))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (0.0006510416666666666 * ((x * x) * ((x * x) * (x * x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.7d0) then
tmp = 1.0d0 / (1.0d0 + (x * (-0.5d0)))
else
tmp = 1.0d0 + (0.0006510416666666666d0 * ((x * x) * ((x * x) * (x * x))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (0.0006510416666666666 * ((x * x) * ((x * x) * (x * x))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = 1.0 / (1.0 + (x * -0.5)) else: tmp = 1.0 + (0.0006510416666666666 * ((x * x) * ((x * x) * (x * x)))) return tmp
function code(x) tmp = 0.0 if (x <= 1.7) tmp = Float64(1.0 / Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(1.0 + Float64(0.0006510416666666666 * Float64(Float64(x * x) * Float64(Float64(x * x) * Float64(x * x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.7) tmp = 1.0 / (1.0 + (x * -0.5)); else tmp = 1.0 + (0.0006510416666666666 * ((x * x) * ((x * x) * (x * x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.7], N[(1.0 / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(0.0006510416666666666 * N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;\frac{1}{1 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + 0.0006510416666666666 \cdot \left(\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 43.6%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.6%
if 1.69999999999999996 < x Initial program 100.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 69.4%
*-commutative69.4%
Simplified69.4%
flip3-+14.5%
div-inv14.5%
pow314.5%
+-commutative14.5%
pow314.5%
unpow-prod-down14.5%
pow314.5%
associate-*l*14.5%
metadata-eval14.5%
metadata-eval14.5%
metadata-eval14.5%
distribute-rgt-out--14.5%
Applied egg-rr14.5%
Taylor expanded in x around 0 88.1%
*-commutative88.1%
Simplified88.1%
Taylor expanded in x around inf 88.1%
metadata-eval88.1%
pow-sqr88.1%
unpow388.1%
unpow388.1%
swap-sqr88.1%
Simplified88.1%
Final simplification73.3%
(FPCore (x)
:precision binary64
(if (<= x -2.5)
(/ (- (- 2.0) (/ 4.0 x)) x)
(+
1.0
(* x (+ 0.5 (* x (+ 0.16666666666666666 (* x 0.041666666666666664))))))))
double code(double x) {
double tmp;
if (x <= -2.5) {
tmp = (-2.0 - (4.0 / x)) / x;
} else {
tmp = 1.0 + (x * (0.5 + (x * (0.16666666666666666 + (x * 0.041666666666666664)))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.5d0)) then
tmp = (-2.0d0 - (4.0d0 / x)) / x
else
tmp = 1.0d0 + (x * (0.5d0 + (x * (0.16666666666666666d0 + (x * 0.041666666666666664d0)))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.5) {
tmp = (-2.0 - (4.0 / x)) / x;
} else {
tmp = 1.0 + (x * (0.5 + (x * (0.16666666666666666 + (x * 0.041666666666666664)))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.5: tmp = (-2.0 - (4.0 / x)) / x else: tmp = 1.0 + (x * (0.5 + (x * (0.16666666666666666 + (x * 0.041666666666666664))))) return tmp
function code(x) tmp = 0.0 if (x <= -2.5) tmp = Float64(Float64(Float64(-2.0) - Float64(4.0 / x)) / x); else tmp = Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * Float64(0.16666666666666666 + Float64(x * 0.041666666666666664)))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.5) tmp = (-2.0 - (4.0 / x)) / x; else tmp = 1.0 + (x * (0.5 + (x * (0.16666666666666666 + (x * 0.041666666666666664))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.5], N[(N[((-2.0) - N[(4.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(1.0 + N[(x * N[(0.5 + N[(x * N[(0.16666666666666666 + N[(x * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5:\\
\;\;\;\;\frac{\left(-2\right) - \frac{4}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\\
\end{array}
\end{array}
if x < -2.5Initial program 100.0%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
div-inv100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 18.8%
*-commutative18.8%
Simplified18.8%
Taylor expanded in x around inf 18.8%
mul-1-neg18.8%
distribute-neg-frac218.8%
associate-*r/18.8%
metadata-eval18.8%
neg-sub018.8%
Simplified18.8%
if -2.5 < x Initial program 43.3%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 88.1%
*-commutative88.1%
Simplified88.1%
Final simplification68.6%
(FPCore (x) :precision binary64 (if (<= x 0.64) (/ 1.0 (+ 1.0 (* x -0.5))) (+ 1.0 (* x (+ 0.5 (* x (* x 0.041666666666666664)))))))
double code(double x) {
double tmp;
if (x <= 0.64) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * (0.5 + (x * (x * 0.041666666666666664))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.64d0) then
tmp = 1.0d0 / (1.0d0 + (x * (-0.5d0)))
else
tmp = 1.0d0 + (x * (0.5d0 + (x * (x * 0.041666666666666664d0))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.64) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * (0.5 + (x * (x * 0.041666666666666664))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.64: tmp = 1.0 / (1.0 + (x * -0.5)) else: tmp = 1.0 + (x * (0.5 + (x * (x * 0.041666666666666664)))) return tmp
function code(x) tmp = 0.0 if (x <= 0.64) tmp = Float64(1.0 / Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * Float64(x * 0.041666666666666664))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.64) tmp = 1.0 / (1.0 + (x * -0.5)); else tmp = 1.0 + (x * (0.5 + (x * (x * 0.041666666666666664)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.64], N[(1.0 / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * N[(0.5 + N[(x * N[(x * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.64:\\
\;\;\;\;\frac{1}{1 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(x \cdot 0.041666666666666664\right)\right)\\
\end{array}
\end{array}
if x < 0.640000000000000013Initial program 43.6%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.6%
if 0.640000000000000013 < x Initial program 100.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 69.4%
*-commutative69.4%
Simplified69.4%
Taylor expanded in x around inf 69.4%
Final simplification68.1%
(FPCore (x) :precision binary64 (if (<= x 1.65) (/ 1.0 (+ 1.0 (* x -0.5))) (+ 1.0 (* x (* (* x x) 0.041666666666666664)))))
double code(double x) {
double tmp;
if (x <= 1.65) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * ((x * x) * 0.041666666666666664));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.65d0) then
tmp = 1.0d0 / (1.0d0 + (x * (-0.5d0)))
else
tmp = 1.0d0 + (x * ((x * x) * 0.041666666666666664d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.65) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + (x * ((x * x) * 0.041666666666666664));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.65: tmp = 1.0 / (1.0 + (x * -0.5)) else: tmp = 1.0 + (x * ((x * x) * 0.041666666666666664)) return tmp
function code(x) tmp = 0.0 if (x <= 1.65) tmp = Float64(1.0 / Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(1.0 + Float64(x * Float64(Float64(x * x) * 0.041666666666666664))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.65) tmp = 1.0 / (1.0 + (x * -0.5)); else tmp = 1.0 + (x * ((x * x) * 0.041666666666666664)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.65], N[(1.0 / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * N[(N[(x * x), $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.65:\\
\;\;\;\;\frac{1}{1 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(\left(x \cdot x\right) \cdot 0.041666666666666664\right)\\
\end{array}
\end{array}
if x < 1.6499999999999999Initial program 43.6%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.6%
if 1.6499999999999999 < x Initial program 100.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 69.4%
*-commutative69.4%
Simplified69.4%
Taylor expanded in x around inf 69.4%
cube-unmult69.4%
*-commutative69.4%
associate-*l*69.4%
*-commutative69.4%
Simplified69.4%
Final simplification68.1%
(FPCore (x) :precision binary64 (if (<= x 1.5) (/ 1.0 (+ 1.0 (* x -0.5))) (+ 1.0 (* (* x x) 0.16666666666666666))))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + ((x * x) * 0.16666666666666666);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = 1.0d0 / (1.0d0 + (x * (-0.5d0)))
else
tmp = 1.0d0 + ((x * x) * 0.16666666666666666d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = 1.0 / (1.0 + (x * -0.5));
} else {
tmp = 1.0 + ((x * x) * 0.16666666666666666);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = 1.0 / (1.0 + (x * -0.5)) else: tmp = 1.0 + ((x * x) * 0.16666666666666666) return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(1.0 / Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(1.0 + Float64(Float64(x * x) * 0.16666666666666666)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = 1.0 / (1.0 + (x * -0.5)); else tmp = 1.0 + ((x * x) * 0.16666666666666666); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(1.0 / N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x * x), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;\frac{1}{1 + x \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot 0.16666666666666666\\
\end{array}
\end{array}
if x < 1.5Initial program 43.6%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.6%
if 1.5 < x Initial program 100.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 58.7%
*-commutative58.7%
Simplified58.7%
Taylor expanded in x around inf 58.7%
unpow258.7%
Simplified58.7%
Final simplification65.1%
(FPCore (x) :precision binary64 (if (<= x -1.5) (/ -2.0 x) (+ 1.0 (* (* x x) 0.16666666666666666))))
double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = -2.0 / x;
} else {
tmp = 1.0 + ((x * x) * 0.16666666666666666);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.5d0)) then
tmp = (-2.0d0) / x
else
tmp = 1.0d0 + ((x * x) * 0.16666666666666666d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = -2.0 / x;
} else {
tmp = 1.0 + ((x * x) * 0.16666666666666666);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.5: tmp = -2.0 / x else: tmp = 1.0 + ((x * x) * 0.16666666666666666) return tmp
function code(x) tmp = 0.0 if (x <= -1.5) tmp = Float64(-2.0 / x); else tmp = Float64(1.0 + Float64(Float64(x * x) * 0.16666666666666666)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.5) tmp = -2.0 / x; else tmp = 1.0 + ((x * x) * 0.16666666666666666); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.5], N[(-2.0 / x), $MachinePrecision], N[(1.0 + N[(N[(x * x), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot 0.16666666666666666\\
\end{array}
\end{array}
if x < -1.5Initial program 100.0%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
div-inv100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 18.8%
*-commutative18.8%
Simplified18.8%
Taylor expanded in x around inf 18.7%
if -1.5 < x Initial program 43.3%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 83.7%
*-commutative83.7%
Simplified83.7%
Taylor expanded in x around inf 82.2%
unpow282.2%
Simplified82.2%
Final simplification64.4%
(FPCore (x) :precision binary64 (if (<= x -1.55) (/ -2.0 x) (+ 1.0 (* x 0.5))))
double code(double x) {
double tmp;
if (x <= -1.55) {
tmp = -2.0 / x;
} else {
tmp = 1.0 + (x * 0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.55d0)) then
tmp = (-2.0d0) / x
else
tmp = 1.0d0 + (x * 0.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.55) {
tmp = -2.0 / x;
} else {
tmp = 1.0 + (x * 0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.55: tmp = -2.0 / x else: tmp = 1.0 + (x * 0.5) return tmp
function code(x) tmp = 0.0 if (x <= -1.55) tmp = Float64(-2.0 / x); else tmp = Float64(1.0 + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.55) tmp = -2.0 / x; else tmp = 1.0 + (x * 0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.55], N[(-2.0 / x), $MachinePrecision], N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot 0.5\\
\end{array}
\end{array}
if x < -1.55000000000000004Initial program 100.0%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
div-inv100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 18.8%
*-commutative18.8%
Simplified18.8%
Taylor expanded in x around inf 18.7%
if -1.55000000000000004 < x Initial program 43.3%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 62.8%
Final simplification50.4%
(FPCore (x) :precision binary64 (if (<= x -2.0) (/ -2.0 x) 1.0))
double code(double x) {
double tmp;
if (x <= -2.0) {
tmp = -2.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.0d0)) then
tmp = (-2.0d0) / x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.0) {
tmp = -2.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.0: tmp = -2.0 / x else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= -2.0) tmp = Float64(-2.0 / x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.0) tmp = -2.0 / x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.0], N[(-2.0 / x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2Initial program 100.0%
expm1-define100.0%
Simplified100.0%
clear-num100.0%
Applied egg-rr100.0%
div-inv100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 18.8%
*-commutative18.8%
Simplified18.8%
Taylor expanded in x around inf 18.7%
if -2 < x Initial program 43.3%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 60.8%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 59.2%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 45.3%
(FPCore (x) :precision binary64 (let* ((t_0 (- (exp x) 1.0))) (if (and (< x 1.0) (> x -1.0)) (/ t_0 (log (exp x))) (/ t_0 x))))
double code(double x) {
double t_0 = exp(x) - 1.0;
double tmp;
if ((x < 1.0) && (x > -1.0)) {
tmp = t_0 / log(exp(x));
} else {
tmp = t_0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = exp(x) - 1.0d0
if ((x < 1.0d0) .and. (x > (-1.0d0))) then
tmp = t_0 / log(exp(x))
else
tmp = t_0 / x
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.exp(x) - 1.0;
double tmp;
if ((x < 1.0) && (x > -1.0)) {
tmp = t_0 / Math.log(Math.exp(x));
} else {
tmp = t_0 / x;
}
return tmp;
}
def code(x): t_0 = math.exp(x) - 1.0 tmp = 0 if (x < 1.0) and (x > -1.0): tmp = t_0 / math.log(math.exp(x)) else: tmp = t_0 / x return tmp
function code(x) t_0 = Float64(exp(x) - 1.0) tmp = 0.0 if ((x < 1.0) && (x > -1.0)) tmp = Float64(t_0 / log(exp(x))); else tmp = Float64(t_0 / x); end return tmp end
function tmp_2 = code(x) t_0 = exp(x) - 1.0; tmp = 0.0; if ((x < 1.0) && (x > -1.0)) tmp = t_0 / log(exp(x)); else tmp = t_0 / x; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]}, If[And[Less[x, 1.0], Greater[x, -1.0]], N[(t$95$0 / N[Log[N[Exp[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{x} - 1\\
\mathbf{if}\;x < 1 \land x > -1:\\
\;\;\;\;\frac{t\_0}{\log \left(e^{x}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{x}\\
\end{array}
\end{array}
herbie shell --seed 2024098
(FPCore (x)
:name "Kahan's exp quotient"
:precision binary64
:alt
(if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))
(/ (- (exp x) 1.0) x))