
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
double code(double a, double x) {
return exp((a * x)) - 1.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = exp((a * x)) - 1.0d0
end function
public static double code(double a, double x) {
return Math.exp((a * x)) - 1.0;
}
def code(a, x): return math.exp((a * x)) - 1.0
function code(a, x) return Float64(exp(Float64(a * x)) - 1.0) end
function tmp = code(a, x) tmp = exp((a * x)) - 1.0; end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{a \cdot x} - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
double code(double a, double x) {
return exp((a * x)) - 1.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = exp((a * x)) - 1.0d0
end function
public static double code(double a, double x) {
return Math.exp((a * x)) - 1.0;
}
def code(a, x): return math.exp((a * x)) - 1.0
function code(a, x) return Float64(exp(Float64(a * x)) - 1.0) end
function tmp = code(a, x) tmp = exp((a * x)) - 1.0; end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{a \cdot x} - 1
\end{array}
(FPCore (a x) :precision binary64 (expm1 (* a x)))
double code(double a, double x) {
return expm1((a * x));
}
public static double code(double a, double x) {
return Math.expm1((a * x));
}
def code(a, x): return math.expm1((a * x))
function code(a, x) return expm1(Float64(a * x)) end
code[a_, x_] := N[(Exp[N[(a * x), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(a \cdot x\right)
\end{array}
Initial program 64.0%
expm1-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (a x) :precision binary64 (if (<= (* a x) -4000000000000.0) (- -2.0 (/ (/ 4.0 a) x)) (if (<= (* a x) 1e+91) (* a x) (* 0.5 (* (* a a) (* x x))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else if ((a * x) <= 1e+91) {
tmp = a * x;
} else {
tmp = 0.5 * ((a * a) * (x * x));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-4000000000000.0d0)) then
tmp = (-2.0d0) - ((4.0d0 / a) / x)
else if ((a * x) <= 1d+91) then
tmp = a * x
else
tmp = 0.5d0 * ((a * a) * (x * x))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else if ((a * x) <= 1e+91) {
tmp = a * x;
} else {
tmp = 0.5 * ((a * a) * (x * x));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -4000000000000.0: tmp = -2.0 - ((4.0 / a) / x) elif (a * x) <= 1e+91: tmp = a * x else: tmp = 0.5 * ((a * a) * (x * x)) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -4000000000000.0) tmp = Float64(-2.0 - Float64(Float64(4.0 / a) / x)); elseif (Float64(a * x) <= 1e+91) tmp = Float64(a * x); else tmp = Float64(0.5 * Float64(Float64(a * a) * Float64(x * x))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -4000000000000.0) tmp = -2.0 - ((4.0 / a) / x); elseif ((a * x) <= 1e+91) tmp = a * x; else tmp = 0.5 * ((a * a) * (x * x)); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -4000000000000.0], N[(-2.0 - N[(N[(4.0 / a), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * x), $MachinePrecision], 1e+91], N[(a * x), $MachinePrecision], N[(0.5 * N[(N[(a * a), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4000000000000:\\
\;\;\;\;-2 - \frac{\frac{4}{a}}{x}\\
\mathbf{elif}\;a \cdot x \leq 10^{+91}:\\
\;\;\;\;a \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(a \cdot a\right) \cdot \left(x \cdot x\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -4e12Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.5%
+-commutative0.5%
associate-*r*0.5%
unpow20.5%
associate-*r*0.9%
distribute-rgt-out1.1%
*-commutative1.1%
*-commutative1.1%
unpow21.1%
associate-*l*1.1%
Simplified1.1%
distribute-lft-in0.9%
flip-+0.6%
*-commutative0.6%
*-commutative0.6%
*-commutative0.6%
associate-*l*0.6%
*-commutative0.6%
associate-*l*0.4%
*-commutative0.4%
*-commutative0.4%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around 0 5.0%
unpow25.0%
unpow25.0%
Simplified5.0%
Taylor expanded in a around inf 18.8%
distribute-neg-in18.8%
unsub-neg18.8%
metadata-eval18.8%
associate-*r/18.8%
metadata-eval18.8%
associate-/r*18.8%
Simplified18.8%
if -4e12 < (*.f64 a x) < 1.00000000000000008e91Initial program 38.1%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 84.6%
if 1.00000000000000008e91 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 96.3%
*-commutative96.3%
associate-*l*96.3%
unpow296.3%
associate-*l*86.6%
distribute-lft-out86.6%
unpow286.6%
associate-*l*86.6%
Simplified86.6%
Taylor expanded in a around inf 96.3%
*-commutative96.3%
unpow296.3%
unpow296.3%
associate-*r*96.3%
rem-square-sqrt96.3%
swap-sqr96.3%
swap-sqr78.9%
rem-square-sqrt36.4%
associate-*r*36.4%
*-commutative36.4%
associate-*l*40.2%
*-commutative40.2%
associate-*l*40.2%
*-commutative40.2%
swap-sqr40.2%
rem-square-sqrt86.6%
swap-sqr86.6%
Simplified86.6%
Taylor expanded in a around 0 96.3%
unpow296.3%
unpow296.3%
Simplified96.3%
Final simplification71.6%
(FPCore (a x) :precision binary64 (if (<= (* a x) -4000000000000.0) (- -2.0 (/ (/ 4.0 a) x)) (if (<= (* a x) 500000.0) (* a x) (* a (* a (* x (* x 0.5)))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else if ((a * x) <= 500000.0) {
tmp = a * x;
} else {
tmp = a * (a * (x * (x * 0.5)));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-4000000000000.0d0)) then
tmp = (-2.0d0) - ((4.0d0 / a) / x)
else if ((a * x) <= 500000.0d0) then
tmp = a * x
else
tmp = a * (a * (x * (x * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else if ((a * x) <= 500000.0) {
tmp = a * x;
} else {
tmp = a * (a * (x * (x * 0.5)));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -4000000000000.0: tmp = -2.0 - ((4.0 / a) / x) elif (a * x) <= 500000.0: tmp = a * x else: tmp = a * (a * (x * (x * 0.5))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -4000000000000.0) tmp = Float64(-2.0 - Float64(Float64(4.0 / a) / x)); elseif (Float64(a * x) <= 500000.0) tmp = Float64(a * x); else tmp = Float64(a * Float64(a * Float64(x * Float64(x * 0.5)))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -4000000000000.0) tmp = -2.0 - ((4.0 / a) / x); elseif ((a * x) <= 500000.0) tmp = a * x; else tmp = a * (a * (x * (x * 0.5))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -4000000000000.0], N[(-2.0 - N[(N[(4.0 / a), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * x), $MachinePrecision], 500000.0], N[(a * x), $MachinePrecision], N[(a * N[(a * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4000000000000:\\
\;\;\;\;-2 - \frac{\frac{4}{a}}{x}\\
\mathbf{elif}\;a \cdot x \leq 500000:\\
\;\;\;\;a \cdot x\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -4e12Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.5%
+-commutative0.5%
associate-*r*0.5%
unpow20.5%
associate-*r*0.9%
distribute-rgt-out1.1%
*-commutative1.1%
*-commutative1.1%
unpow21.1%
associate-*l*1.1%
Simplified1.1%
distribute-lft-in0.9%
flip-+0.6%
*-commutative0.6%
*-commutative0.6%
*-commutative0.6%
associate-*l*0.6%
*-commutative0.6%
associate-*l*0.4%
*-commutative0.4%
*-commutative0.4%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around 0 5.0%
unpow25.0%
unpow25.0%
Simplified5.0%
Taylor expanded in a around inf 18.8%
distribute-neg-in18.8%
unsub-neg18.8%
metadata-eval18.8%
associate-*r/18.8%
metadata-eval18.8%
associate-/r*18.8%
Simplified18.8%
if -4e12 < (*.f64 a x) < 5e5Initial program 30.2%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 95.0%
if 5e5 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 71.6%
*-commutative71.6%
associate-*l*71.6%
unpow271.6%
associate-*l*70.9%
distribute-lft-out70.9%
unpow270.9%
associate-*l*70.9%
Simplified70.9%
Taylor expanded in a around inf 71.6%
*-commutative71.6%
unpow271.6%
unpow271.6%
associate-*r*71.6%
rem-square-sqrt71.6%
swap-sqr71.6%
swap-sqr59.3%
rem-square-sqrt27.5%
associate-*r*27.5%
*-commutative27.5%
associate-*l*31.8%
*-commutative31.8%
associate-*l*31.8%
*-commutative31.8%
swap-sqr36.1%
rem-square-sqrt70.8%
swap-sqr70.8%
Simplified70.8%
Final simplification71.3%
(FPCore (a x) :precision binary64 (if (<= (* a x) -4000000000000.0) (- -2.0 (/ (/ 4.0 a) x)) (+ (* a x) (* a (* x (* a (* x 0.5)))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else {
tmp = (a * x) + (a * (x * (a * (x * 0.5))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-4000000000000.0d0)) then
tmp = (-2.0d0) - ((4.0d0 / a) / x)
else
tmp = (a * x) + (a * (x * (a * (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else {
tmp = (a * x) + (a * (x * (a * (x * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -4000000000000.0: tmp = -2.0 - ((4.0 / a) / x) else: tmp = (a * x) + (a * (x * (a * (x * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -4000000000000.0) tmp = Float64(-2.0 - Float64(Float64(4.0 / a) / x)); else tmp = Float64(Float64(a * x) + Float64(a * Float64(x * Float64(a * Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -4000000000000.0) tmp = -2.0 - ((4.0 / a) / x); else tmp = (a * x) + (a * (x * (a * (x * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -4000000000000.0], N[(-2.0 - N[(N[(4.0 / a), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(a * x), $MachinePrecision] + N[(a * N[(x * N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4000000000000:\\
\;\;\;\;-2 - \frac{\frac{4}{a}}{x}\\
\mathbf{else}:\\
\;\;\;\;a \cdot x + a \cdot \left(x \cdot \left(a \cdot \left(x \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -4e12Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.5%
+-commutative0.5%
associate-*r*0.5%
unpow20.5%
associate-*r*0.9%
distribute-rgt-out1.1%
*-commutative1.1%
*-commutative1.1%
unpow21.1%
associate-*l*1.1%
Simplified1.1%
distribute-lft-in0.9%
flip-+0.6%
*-commutative0.6%
*-commutative0.6%
*-commutative0.6%
associate-*l*0.6%
*-commutative0.6%
associate-*l*0.4%
*-commutative0.4%
*-commutative0.4%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around 0 5.0%
unpow25.0%
unpow25.0%
Simplified5.0%
Taylor expanded in a around inf 18.8%
distribute-neg-in18.8%
unsub-neg18.8%
metadata-eval18.8%
associate-*r/18.8%
metadata-eval18.8%
associate-/r*18.8%
Simplified18.8%
if -4e12 < (*.f64 a x) Initial program 53.2%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 80.1%
*-commutative80.1%
associate-*l*80.1%
unpow280.1%
associate-*l*86.3%
distribute-lft-out86.3%
unpow286.3%
associate-*l*86.3%
Simplified86.3%
distribute-lft-in86.3%
*-commutative86.3%
associate-*l*86.1%
Applied egg-rr86.1%
Final simplification70.6%
(FPCore (a x) :precision binary64 (if (<= (* a x) -4000000000000.0) (- -2.0 (/ (/ 4.0 a) x)) (* a (+ x (* x (* a (* x 0.5)))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else {
tmp = a * (x + (x * (a * (x * 0.5))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-4000000000000.0d0)) then
tmp = (-2.0d0) - ((4.0d0 / a) / x)
else
tmp = a * (x + (x * (a * (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else {
tmp = a * (x + (x * (a * (x * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -4000000000000.0: tmp = -2.0 - ((4.0 / a) / x) else: tmp = a * (x + (x * (a * (x * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -4000000000000.0) tmp = Float64(-2.0 - Float64(Float64(4.0 / a) / x)); else tmp = Float64(a * Float64(x + Float64(x * Float64(a * Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -4000000000000.0) tmp = -2.0 - ((4.0 / a) / x); else tmp = a * (x + (x * (a * (x * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -4000000000000.0], N[(-2.0 - N[(N[(4.0 / a), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(a * N[(x + N[(x * N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4000000000000:\\
\;\;\;\;-2 - \frac{\frac{4}{a}}{x}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(x + x \cdot \left(a \cdot \left(x \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -4e12Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.5%
+-commutative0.5%
associate-*r*0.5%
unpow20.5%
associate-*r*0.9%
distribute-rgt-out1.1%
*-commutative1.1%
*-commutative1.1%
unpow21.1%
associate-*l*1.1%
Simplified1.1%
distribute-lft-in0.9%
flip-+0.6%
*-commutative0.6%
*-commutative0.6%
*-commutative0.6%
associate-*l*0.6%
*-commutative0.6%
associate-*l*0.4%
*-commutative0.4%
*-commutative0.4%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around 0 5.0%
unpow25.0%
unpow25.0%
Simplified5.0%
Taylor expanded in a around inf 18.8%
distribute-neg-in18.8%
unsub-neg18.8%
metadata-eval18.8%
associate-*r/18.8%
metadata-eval18.8%
associate-/r*18.8%
Simplified18.8%
if -4e12 < (*.f64 a x) Initial program 53.2%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 80.1%
*-commutative80.1%
associate-*l*80.1%
unpow280.1%
associate-*l*86.3%
distribute-lft-out86.3%
unpow286.3%
associate-*l*86.3%
Simplified86.3%
distribute-lft-in86.3%
*-commutative86.3%
associate-*l*86.1%
Applied egg-rr86.1%
+-commutative86.1%
distribute-lft-out86.1%
*-commutative86.1%
Applied egg-rr86.1%
Final simplification70.6%
(FPCore (a x) :precision binary64 (if (<= (* a x) -4000000000000.0) (- -2.0 (/ (/ 4.0 a) x)) (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else {
tmp = a * x;
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-4000000000000.0d0)) then
tmp = (-2.0d0) - ((4.0d0 / a) / x)
else
tmp = a * x
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -4000000000000.0) {
tmp = -2.0 - ((4.0 / a) / x);
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -4000000000000.0: tmp = -2.0 - ((4.0 / a) / x) else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -4000000000000.0) tmp = Float64(-2.0 - Float64(Float64(4.0 / a) / x)); else tmp = Float64(a * x); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -4000000000000.0) tmp = -2.0 - ((4.0 / a) / x); else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -4000000000000.0], N[(-2.0 - N[(N[(4.0 / a), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4000000000000:\\
\;\;\;\;-2 - \frac{\frac{4}{a}}{x}\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -4e12Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.5%
+-commutative0.5%
associate-*r*0.5%
unpow20.5%
associate-*r*0.9%
distribute-rgt-out1.1%
*-commutative1.1%
*-commutative1.1%
unpow21.1%
associate-*l*1.1%
Simplified1.1%
distribute-lft-in0.9%
flip-+0.6%
*-commutative0.6%
*-commutative0.6%
*-commutative0.6%
associate-*l*0.6%
*-commutative0.6%
associate-*l*0.4%
*-commutative0.4%
*-commutative0.4%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around 0 5.0%
unpow25.0%
unpow25.0%
Simplified5.0%
Taylor expanded in a around inf 18.8%
distribute-neg-in18.8%
unsub-neg18.8%
metadata-eval18.8%
associate-*r/18.8%
metadata-eval18.8%
associate-/r*18.8%
Simplified18.8%
if -4e12 < (*.f64 a x) Initial program 53.2%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 70.3%
Final simplification58.4%
(FPCore (a x) :precision binary64 (if (<= (* a x) -2.0) -2.0 (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -2.0) {
tmp = -2.0;
} else {
tmp = a * x;
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-2.0d0)) then
tmp = -2.0d0
else
tmp = a * x
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -2.0) {
tmp = -2.0;
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -2.0: tmp = -2.0 else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -2.0) tmp = -2.0; else tmp = Float64(a * x); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -2.0) tmp = -2.0; else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -2.0], -2.0, N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -2:\\
\;\;\;\;-2\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -2Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.5%
+-commutative0.5%
associate-*r*0.5%
unpow20.5%
associate-*r*0.9%
distribute-rgt-out1.1%
*-commutative1.1%
*-commutative1.1%
unpow21.1%
associate-*l*1.1%
Simplified1.1%
distribute-lft-in0.9%
flip-+0.6%
*-commutative0.6%
*-commutative0.6%
*-commutative0.6%
associate-*l*0.6%
*-commutative0.6%
associate-*l*0.4%
*-commutative0.4%
*-commutative0.4%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around 0 5.0%
unpow25.0%
unpow25.0%
Simplified5.0%
Taylor expanded in a around inf 18.8%
if -2 < (*.f64 a x) Initial program 53.2%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 70.3%
Final simplification58.4%
(FPCore (a x) :precision binary64 -2.0)
double code(double a, double x) {
return -2.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = -2.0d0
end function
public static double code(double a, double x) {
return -2.0;
}
def code(a, x): return -2.0
function code(a, x) return -2.0 end
function tmp = code(a, x) tmp = -2.0; end
code[a_, x_] := -2.0
\begin{array}{l}
\\
-2
\end{array}
Initial program 64.0%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 61.8%
+-commutative61.8%
associate-*r*61.8%
unpow261.8%
associate-*r*63.7%
distribute-rgt-out63.7%
*-commutative63.7%
*-commutative63.7%
unpow263.7%
associate-*l*63.7%
Simplified63.7%
distribute-lft-in63.7%
flip-+23.5%
*-commutative23.5%
*-commutative23.5%
*-commutative23.5%
associate-*l*23.5%
*-commutative23.5%
associate-*l*23.5%
*-commutative23.5%
*-commutative23.5%
associate-*l*28.5%
Applied egg-rr28.5%
Taylor expanded in a around 0 13.2%
unpow213.2%
unpow213.2%
Simplified13.2%
Taylor expanded in a around inf 6.5%
Final simplification6.5%
(FPCore (a x) :precision binary64 (if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0)))
double code(double a, double x) {
double tmp;
if (fabs((a * x)) < 0.1) {
tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (pow((a * x), 2.0) / 6.0)));
} else {
tmp = exp((a * x)) - 1.0;
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if (abs((a * x)) < 0.1d0) then
tmp = (a * x) * (1.0d0 + (((a * x) / 2.0d0) + (((a * x) ** 2.0d0) / 6.0d0)))
else
tmp = exp((a * x)) - 1.0d0
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if (Math.abs((a * x)) < 0.1) {
tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (Math.pow((a * x), 2.0) / 6.0)));
} else {
tmp = Math.exp((a * x)) - 1.0;
}
return tmp;
}
def code(a, x): tmp = 0 if math.fabs((a * x)) < 0.1: tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (math.pow((a * x), 2.0) / 6.0))) else: tmp = math.exp((a * x)) - 1.0 return tmp
function code(a, x) tmp = 0.0 if (abs(Float64(a * x)) < 0.1) tmp = Float64(Float64(a * x) * Float64(1.0 + Float64(Float64(Float64(a * x) / 2.0) + Float64((Float64(a * x) ^ 2.0) / 6.0)))); else tmp = Float64(exp(Float64(a * x)) - 1.0); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (abs((a * x)) < 0.1) tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (((a * x) ^ 2.0) / 6.0))); else tmp = exp((a * x)) - 1.0; end tmp_2 = tmp; end
code[a_, x_] := If[Less[N[Abs[N[(a * x), $MachinePrecision]], $MachinePrecision], 0.1], N[(N[(a * x), $MachinePrecision] * N[(1.0 + N[(N[(N[(a * x), $MachinePrecision] / 2.0), $MachinePrecision] + N[(N[Power[N[(a * x), $MachinePrecision], 2.0], $MachinePrecision] / 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|a \cdot x\right| < 0.1:\\
\;\;\;\;\left(a \cdot x\right) \cdot \left(1 + \left(\frac{a \cdot x}{2} + \frac{{\left(a \cdot x\right)}^{2}}{6}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;e^{a \cdot x} - 1\\
\end{array}
\end{array}
herbie shell --seed 2023201
(FPCore (a x)
:name "expax (section 3.5)"
:precision binary64
:herbie-target
(if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0))
(- (exp (* a x)) 1.0))