
(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 69.1%
expm1-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -50.0)
-2.0
(if (<= (* a x) 4e-5)
(+ (* a x) (* x (* a (* x (* a 0.5)))))
(* x (+ a (* x (* a (* a 0.5))))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 4e-5) {
tmp = (a * x) + (x * (a * (x * (a * 0.5))));
} else {
tmp = x * (a + (x * (a * (a * 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) <= (-50.0d0)) then
tmp = -2.0d0
else if ((a * x) <= 4d-5) then
tmp = (a * x) + (x * (a * (x * (a * 0.5d0))))
else
tmp = x * (a + (x * (a * (a * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 4e-5) {
tmp = (a * x) + (x * (a * (x * (a * 0.5))));
} else {
tmp = x * (a + (x * (a * (a * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -50.0: tmp = -2.0 elif (a * x) <= 4e-5: tmp = (a * x) + (x * (a * (x * (a * 0.5)))) else: tmp = x * (a + (x * (a * (a * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -50.0) tmp = -2.0; elseif (Float64(a * x) <= 4e-5) tmp = Float64(Float64(a * x) + Float64(x * Float64(a * Float64(x * Float64(a * 0.5))))); else tmp = Float64(x * Float64(a + Float64(x * Float64(a * Float64(a * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -50.0) tmp = -2.0; elseif ((a * x) <= 4e-5) tmp = (a * x) + (x * (a * (x * (a * 0.5)))); else tmp = x * (a + (x * (a * (a * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -50.0], -2.0, If[LessEqual[N[(a * x), $MachinePrecision], 4e-5], N[(N[(a * x), $MachinePrecision] + N[(x * N[(a * N[(x * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(a + N[(x * N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;-2\\
\mathbf{elif}\;a \cdot x \leq 4 \cdot 10^{-5}:\\
\;\;\;\;a \cdot x + x \cdot \left(a \cdot \left(x \cdot \left(a \cdot 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(a + x \cdot \left(a \cdot \left(a \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -50Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.6%
+-commutative0.6%
associate-*r*0.6%
unpow20.6%
associate-*r*0.8%
distribute-rgt-out1.0%
*-commutative1.0%
*-commutative1.0%
unpow21.0%
associate-*l*1.0%
Simplified1.0%
distribute-lft-in0.8%
flip-+0.5%
*-commutative0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around inf 0.3%
unpow20.3%
unpow20.3%
associate-*r*0.3%
Simplified0.3%
Taylor expanded in a around 0 18.8%
if -50 < (*.f64 a x) < 4.00000000000000033e-5Initial program 33.5%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 84.0%
+-commutative84.0%
associate-*r*84.0%
unpow284.0%
associate-*r*88.2%
distribute-rgt-out88.2%
*-commutative88.2%
*-commutative88.2%
unpow288.2%
associate-*l*88.2%
Simplified88.2%
+-commutative88.2%
distribute-lft-in88.2%
*-commutative88.2%
associate-*l*98.7%
*-commutative98.7%
Applied egg-rr98.7%
if 4.00000000000000033e-5 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 76.9%
+-commutative76.9%
associate-*r*76.9%
unpow276.9%
associate-*r*79.0%
distribute-rgt-out79.0%
*-commutative79.0%
*-commutative79.0%
unpow279.0%
associate-*l*79.0%
Simplified79.0%
Final simplification70.7%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -50.0)
-2.0
(if (<= (* a x) 100000.0)
(* a (+ x (* x (* a (* x 0.5)))))
(* (* 0.5 (* a a)) (* x x)))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 100000.0) {
tmp = a * (x + (x * (a * (x * 0.5))));
} 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) <= (-50.0d0)) then
tmp = -2.0d0
else if ((a * x) <= 100000.0d0) then
tmp = a * (x + (x * (a * (x * 0.5d0))))
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) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 100000.0) {
tmp = a * (x + (x * (a * (x * 0.5))));
} else {
tmp = (0.5 * (a * a)) * (x * x);
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -50.0: tmp = -2.0 elif (a * x) <= 100000.0: tmp = a * (x + (x * (a * (x * 0.5)))) else: tmp = (0.5 * (a * a)) * (x * x) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -50.0) tmp = -2.0; elseif (Float64(a * x) <= 100000.0) tmp = Float64(a * Float64(x + Float64(x * Float64(a * Float64(x * 0.5))))); else tmp = Float64(Float64(0.5 * Float64(a * a)) * Float64(x * x)); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -50.0) tmp = -2.0; elseif ((a * x) <= 100000.0) tmp = a * (x + (x * (a * (x * 0.5)))); else tmp = (0.5 * (a * a)) * (x * x); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -50.0], -2.0, If[LessEqual[N[(a * x), $MachinePrecision], 100000.0], N[(a * N[(x + N[(x * N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(a * a), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;-2\\
\mathbf{elif}\;a \cdot x \leq 100000:\\
\;\;\;\;a \cdot \left(x + x \cdot \left(a \cdot \left(x \cdot 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \left(a \cdot a\right)\right) \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -50Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.6%
+-commutative0.6%
associate-*r*0.6%
unpow20.6%
associate-*r*0.8%
distribute-rgt-out1.0%
*-commutative1.0%
*-commutative1.0%
unpow21.0%
associate-*l*1.0%
Simplified1.0%
distribute-lft-in0.8%
flip-+0.5%
*-commutative0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around inf 0.3%
unpow20.3%
unpow20.3%
associate-*r*0.3%
Simplified0.3%
Taylor expanded in a around 0 18.8%
if -50 < (*.f64 a x) < 1e5Initial program 34.1%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 83.3%
+-commutative83.3%
associate-*r*83.3%
unpow283.3%
associate-*r*88.3%
distribute-rgt-out88.3%
*-commutative88.3%
*-commutative88.3%
unpow288.3%
associate-*l*88.3%
Simplified88.3%
+-commutative88.3%
distribute-lft-in88.3%
*-commutative88.3%
associate-*l*97.9%
*-commutative97.9%
Applied egg-rr97.9%
+-commutative97.9%
fma-def97.9%
associate-*r*97.9%
*-commutative97.9%
associate-*l*97.9%
associate-*l*97.9%
*-commutative97.9%
Applied egg-rr97.9%
fma-def97.9%
+-commutative97.9%
distribute-lft-out97.9%
Simplified97.9%
if 1e5 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 78.2%
+-commutative78.2%
associate-*r*78.2%
unpow278.2%
associate-*r*78.6%
distribute-rgt-out78.6%
*-commutative78.6%
*-commutative78.6%
unpow278.6%
associate-*l*78.6%
Simplified78.6%
+-commutative78.6%
distribute-lft-in78.6%
*-commutative78.6%
associate-*l*70.9%
*-commutative70.9%
Applied egg-rr70.9%
Taylor expanded in x around inf 78.2%
unpow278.2%
unpow278.2%
associate-*r*78.2%
Simplified78.2%
Final simplification70.2%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -50.0)
-2.0
(if (<= (* a x) 4e-5)
(* a (+ x (* x (* a (* x 0.5)))))
(* x (+ a (* x (* a (* a 0.5))))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 4e-5) {
tmp = a * (x + (x * (a * (x * 0.5))));
} else {
tmp = x * (a + (x * (a * (a * 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) <= (-50.0d0)) then
tmp = -2.0d0
else if ((a * x) <= 4d-5) then
tmp = a * (x + (x * (a * (x * 0.5d0))))
else
tmp = x * (a + (x * (a * (a * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 4e-5) {
tmp = a * (x + (x * (a * (x * 0.5))));
} else {
tmp = x * (a + (x * (a * (a * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -50.0: tmp = -2.0 elif (a * x) <= 4e-5: tmp = a * (x + (x * (a * (x * 0.5)))) else: tmp = x * (a + (x * (a * (a * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -50.0) tmp = -2.0; elseif (Float64(a * x) <= 4e-5) tmp = Float64(a * Float64(x + Float64(x * Float64(a * Float64(x * 0.5))))); else tmp = Float64(x * Float64(a + Float64(x * Float64(a * Float64(a * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -50.0) tmp = -2.0; elseif ((a * x) <= 4e-5) tmp = a * (x + (x * (a * (x * 0.5)))); else tmp = x * (a + (x * (a * (a * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -50.0], -2.0, If[LessEqual[N[(a * x), $MachinePrecision], 4e-5], N[(a * N[(x + N[(x * N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(a + N[(x * N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;-2\\
\mathbf{elif}\;a \cdot x \leq 4 \cdot 10^{-5}:\\
\;\;\;\;a \cdot \left(x + x \cdot \left(a \cdot \left(x \cdot 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(a + x \cdot \left(a \cdot \left(a \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -50Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.6%
+-commutative0.6%
associate-*r*0.6%
unpow20.6%
associate-*r*0.8%
distribute-rgt-out1.0%
*-commutative1.0%
*-commutative1.0%
unpow21.0%
associate-*l*1.0%
Simplified1.0%
distribute-lft-in0.8%
flip-+0.5%
*-commutative0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around inf 0.3%
unpow20.3%
unpow20.3%
associate-*r*0.3%
Simplified0.3%
Taylor expanded in a around 0 18.8%
if -50 < (*.f64 a x) < 4.00000000000000033e-5Initial program 33.5%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 84.0%
+-commutative84.0%
associate-*r*84.0%
unpow284.0%
associate-*r*88.2%
distribute-rgt-out88.2%
*-commutative88.2%
*-commutative88.2%
unpow288.2%
associate-*l*88.2%
Simplified88.2%
+-commutative88.2%
distribute-lft-in88.2%
*-commutative88.2%
associate-*l*98.7%
*-commutative98.7%
Applied egg-rr98.7%
+-commutative98.7%
fma-def98.7%
associate-*r*98.7%
*-commutative98.7%
associate-*l*98.7%
associate-*l*98.7%
*-commutative98.7%
Applied egg-rr98.7%
fma-def98.7%
+-commutative98.7%
distribute-lft-out98.7%
Simplified98.7%
if 4.00000000000000033e-5 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 76.9%
+-commutative76.9%
associate-*r*76.9%
unpow276.9%
associate-*r*79.0%
distribute-rgt-out79.0%
*-commutative79.0%
*-commutative79.0%
unpow279.0%
associate-*l*79.0%
Simplified79.0%
Final simplification70.7%
(FPCore (a x) :precision binary64 (if (<= (* a x) -50.0) -2.0 (if (<= (* a x) 100000.0) (* a x) (* 0.5 (* a (* a (* x x)))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 100000.0) {
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) <= (-50.0d0)) then
tmp = -2.0d0
else if ((a * x) <= 100000.0d0) 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) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 100000.0) {
tmp = a * x;
} else {
tmp = 0.5 * (a * (a * (x * x)));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -50.0: tmp = -2.0 elif (a * x) <= 100000.0: tmp = a * x else: tmp = 0.5 * (a * (a * (x * x))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -50.0) tmp = -2.0; elseif (Float64(a * x) <= 100000.0) tmp = Float64(a * x); else tmp = Float64(0.5 * Float64(a * Float64(a * Float64(x * x)))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -50.0) tmp = -2.0; elseif ((a * x) <= 100000.0) 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], -50.0], -2.0, If[LessEqual[N[(a * x), $MachinePrecision], 100000.0], N[(a * x), $MachinePrecision], N[(0.5 * N[(a * N[(a * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;-2\\
\mathbf{elif}\;a \cdot x \leq 100000:\\
\;\;\;\;a \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(a \cdot \left(a \cdot \left(x \cdot x\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -50Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.6%
+-commutative0.6%
associate-*r*0.6%
unpow20.6%
associate-*r*0.8%
distribute-rgt-out1.0%
*-commutative1.0%
*-commutative1.0%
unpow21.0%
associate-*l*1.0%
Simplified1.0%
distribute-lft-in0.8%
flip-+0.5%
*-commutative0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around inf 0.3%
unpow20.3%
unpow20.3%
associate-*r*0.3%
Simplified0.3%
Taylor expanded in a around 0 18.8%
if -50 < (*.f64 a x) < 1e5Initial program 34.1%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 96.5%
if 1e5 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 78.2%
*-commutative78.2%
associate-*l*78.2%
unpow278.2%
associate-*l*77.0%
distribute-lft-out77.0%
unpow277.0%
associate-*l*77.0%
Simplified77.0%
Taylor expanded in a around inf 78.2%
unpow278.2%
unpow278.2%
associate-*r*76.9%
Simplified76.9%
Final simplification69.3%
(FPCore (a x) :precision binary64 (if (<= (* a x) -50.0) -2.0 (if (<= (* a x) 100000.0) (* a x) (* (* 0.5 (* a a)) (* x x)))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 100000.0) {
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) <= (-50.0d0)) then
tmp = -2.0d0
else if ((a * x) <= 100000.0d0) 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) <= -50.0) {
tmp = -2.0;
} else if ((a * x) <= 100000.0) {
tmp = a * x;
} else {
tmp = (0.5 * (a * a)) * (x * x);
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -50.0: tmp = -2.0 elif (a * x) <= 100000.0: tmp = a * x else: tmp = (0.5 * (a * a)) * (x * x) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -50.0) tmp = -2.0; elseif (Float64(a * x) <= 100000.0) tmp = Float64(a * x); else tmp = Float64(Float64(0.5 * Float64(a * a)) * Float64(x * x)); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -50.0) tmp = -2.0; elseif ((a * x) <= 100000.0) 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], -50.0], -2.0, If[LessEqual[N[(a * x), $MachinePrecision], 100000.0], N[(a * x), $MachinePrecision], N[(N[(0.5 * N[(a * a), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;-2\\
\mathbf{elif}\;a \cdot x \leq 100000:\\
\;\;\;\;a \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \left(a \cdot a\right)\right) \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -50Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 0.6%
+-commutative0.6%
associate-*r*0.6%
unpow20.6%
associate-*r*0.8%
distribute-rgt-out1.0%
*-commutative1.0%
*-commutative1.0%
unpow21.0%
associate-*l*1.0%
Simplified1.0%
distribute-lft-in0.8%
flip-+0.5%
*-commutative0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around inf 0.3%
unpow20.3%
unpow20.3%
associate-*r*0.3%
Simplified0.3%
Taylor expanded in a around 0 18.8%
if -50 < (*.f64 a x) < 1e5Initial program 34.1%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 96.5%
if 1e5 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 78.2%
+-commutative78.2%
associate-*r*78.2%
unpow278.2%
associate-*r*78.6%
distribute-rgt-out78.6%
*-commutative78.6%
*-commutative78.6%
unpow278.6%
associate-*l*78.6%
Simplified78.6%
+-commutative78.6%
distribute-lft-in78.6%
*-commutative78.6%
associate-*l*70.9%
*-commutative70.9%
Applied egg-rr70.9%
Taylor expanded in x around inf 78.2%
unpow278.2%
unpow278.2%
associate-*r*78.2%
Simplified78.2%
Final simplification69.6%
(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.6%
+-commutative0.6%
associate-*r*0.6%
unpow20.6%
associate-*r*0.8%
distribute-rgt-out1.0%
*-commutative1.0%
*-commutative1.0%
unpow21.0%
associate-*l*1.0%
Simplified1.0%
distribute-lft-in0.8%
flip-+0.5%
*-commutative0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
associate-*l*0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l*0.4%
Applied egg-rr0.4%
Taylor expanded in a around inf 0.3%
unpow20.3%
unpow20.3%
associate-*r*0.3%
Simplified0.3%
Taylor expanded in a around 0 18.8%
if -2 < (*.f64 a x) Initial program 56.5%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 72.2%
Final simplification56.7%
(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 69.1%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 58.2%
+-commutative58.2%
associate-*r*58.2%
unpow258.2%
associate-*r*60.7%
distribute-rgt-out60.7%
*-commutative60.7%
*-commutative60.7%
unpow260.7%
associate-*l*60.7%
Simplified60.7%
distribute-lft-in60.7%
flip-+20.6%
*-commutative20.6%
*-commutative20.6%
*-commutative20.6%
associate-*l*20.6%
*-commutative20.6%
associate-*l*20.8%
*-commutative20.8%
*-commutative20.8%
associate-*l*26.4%
Applied egg-rr26.4%
Taylor expanded in a around inf 2.1%
unpow22.1%
unpow22.1%
associate-*r*2.1%
Simplified2.1%
Taylor expanded in a around 0 7.3%
Final simplification7.3%
(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 2023173
(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))