
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U): return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U) return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U) end
function tmp = code(J, l, K, U) tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U; end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U): return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U) return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U) end
function tmp = code(J, l, K, U) tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U; end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 5e-5)))
(+ (* (* t_1 J) t_0) U)
(+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = exp(l) - exp(-l);
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 5e-5)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
}
return tmp;
}
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double t_1 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 5e-5)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = math.exp(l) - math.exp(-l) tmp = 0 if (t_1 <= -math.inf) or not (t_1 <= 5e-5): tmp = ((t_1 * J) * t_0) + U else: tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 5e-5)) tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U); else tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = exp(l) - exp(-l); tmp = 0.0; if ((t_1 <= -Inf) || ~((t_1 <= 5e-5))) tmp = ((t_1 * J) * t_0) + U; else tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 5e-5]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 5 \cdot 10^{-5}\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\
\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 5.00000000000000024e-5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.00000000000000024e-5Initial program 74.5%
Taylor expanded in l around 0 99.9%
Final simplification100.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (* J (pow l 3.0)))
(t_1 (+ U (* 0.3333333333333333 (* t_0 (cos (* K 0.5))))))
(t_2 (+ (* (- (exp l) (exp (- l))) J) U)))
(if (<= l -2.9e+127)
t_1
(if (<= l -0.32)
t_2
(if (<= l 40000000.0)
(+
U
(* (cos (/ K 2.0)) (+ (* 0.3333333333333333 t_0) (* 2.0 (* l J)))))
(if (<= l 1.65e+88) t_2 t_1))))))
double code(double J, double l, double K, double U) {
double t_0 = J * pow(l, 3.0);
double t_1 = U + (0.3333333333333333 * (t_0 * cos((K * 0.5))));
double t_2 = ((exp(l) - exp(-l)) * J) + U;
double tmp;
if (l <= -2.9e+127) {
tmp = t_1;
} else if (l <= -0.32) {
tmp = t_2;
} else if (l <= 40000000.0) {
tmp = U + (cos((K / 2.0)) * ((0.3333333333333333 * t_0) + (2.0 * (l * J))));
} else if (l <= 1.65e+88) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = j * (l ** 3.0d0)
t_1 = u + (0.3333333333333333d0 * (t_0 * cos((k * 0.5d0))))
t_2 = ((exp(l) - exp(-l)) * j) + u
if (l <= (-2.9d+127)) then
tmp = t_1
else if (l <= (-0.32d0)) then
tmp = t_2
else if (l <= 40000000.0d0) then
tmp = u + (cos((k / 2.0d0)) * ((0.3333333333333333d0 * t_0) + (2.0d0 * (l * j))))
else if (l <= 1.65d+88) then
tmp = t_2
else
tmp = t_1
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = J * Math.pow(l, 3.0);
double t_1 = U + (0.3333333333333333 * (t_0 * Math.cos((K * 0.5))));
double t_2 = ((Math.exp(l) - Math.exp(-l)) * J) + U;
double tmp;
if (l <= -2.9e+127) {
tmp = t_1;
} else if (l <= -0.32) {
tmp = t_2;
} else if (l <= 40000000.0) {
tmp = U + (Math.cos((K / 2.0)) * ((0.3333333333333333 * t_0) + (2.0 * (l * J))));
} else if (l <= 1.65e+88) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(J, l, K, U): t_0 = J * math.pow(l, 3.0) t_1 = U + (0.3333333333333333 * (t_0 * math.cos((K * 0.5)))) t_2 = ((math.exp(l) - math.exp(-l)) * J) + U tmp = 0 if l <= -2.9e+127: tmp = t_1 elif l <= -0.32: tmp = t_2 elif l <= 40000000.0: tmp = U + (math.cos((K / 2.0)) * ((0.3333333333333333 * t_0) + (2.0 * (l * J)))) elif l <= 1.65e+88: tmp = t_2 else: tmp = t_1 return tmp
function code(J, l, K, U) t_0 = Float64(J * (l ^ 3.0)) t_1 = Float64(U + Float64(0.3333333333333333 * Float64(t_0 * cos(Float64(K * 0.5))))) t_2 = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U) tmp = 0.0 if (l <= -2.9e+127) tmp = t_1; elseif (l <= -0.32) tmp = t_2; elseif (l <= 40000000.0) tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(Float64(0.3333333333333333 * t_0) + Float64(2.0 * Float64(l * J))))); elseif (l <= 1.65e+88) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = J * (l ^ 3.0); t_1 = U + (0.3333333333333333 * (t_0 * cos((K * 0.5)))); t_2 = ((exp(l) - exp(-l)) * J) + U; tmp = 0.0; if (l <= -2.9e+127) tmp = t_1; elseif (l <= -0.32) tmp = t_2; elseif (l <= 40000000.0) tmp = U + (cos((K / 2.0)) * ((0.3333333333333333 * t_0) + (2.0 * (l * J)))); elseif (l <= 1.65e+88) tmp = t_2; else tmp = t_1; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(0.3333333333333333 * N[(t$95$0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]}, If[LessEqual[l, -2.9e+127], t$95$1, If[LessEqual[l, -0.32], t$95$2, If[LessEqual[l, 40000000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[(0.3333333333333333 * t$95$0), $MachinePrecision] + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.65e+88], t$95$2, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := J \cdot {\ell}^{3}\\
t_1 := U + 0.3333333333333333 \cdot \left(t_0 \cdot \cos \left(K \cdot 0.5\right)\right)\\
t_2 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
\mathbf{if}\;\ell \leq -2.9 \cdot 10^{+127}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq -0.32:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq 40000000:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(0.3333333333333333 \cdot t_0 + 2 \cdot \left(\ell \cdot J\right)\right)\\
\mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+88}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if l < -2.9000000000000002e127 or 1.6500000000000002e88 < l Initial program 100.0%
Taylor expanded in l around 0 98.8%
Taylor expanded in l around inf 98.8%
associate-*r*98.8%
Simplified98.8%
if -2.9000000000000002e127 < l < -0.320000000000000007 or 4e7 < l < 1.6500000000000002e88Initial program 100.0%
Taylor expanded in K around 0 84.2%
if -0.320000000000000007 < l < 4e7Initial program 75.3%
Taylor expanded in l around 0 97.5%
Final simplification95.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0
(+ U (* 0.3333333333333333 (* (* J (pow l 3.0)) (cos (* K 0.5))))))
(t_1 (+ (* (- (exp l) (exp (- l))) J) U)))
(if (<= l -2.9e+127)
t_0
(if (<= l -0.36)
t_1
(if (<= l 40000000.0)
(+
U
(*
(cos (/ K 2.0))
(* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
(if (<= l 1.26e+88) t_1 t_0))))))
double code(double J, double l, double K, double U) {
double t_0 = U + (0.3333333333333333 * ((J * pow(l, 3.0)) * cos((K * 0.5))));
double t_1 = ((exp(l) - exp(-l)) * J) + U;
double tmp;
if (l <= -2.9e+127) {
tmp = t_0;
} else if (l <= -0.36) {
tmp = t_1;
} else if (l <= 40000000.0) {
tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
} else if (l <= 1.26e+88) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = u + (0.3333333333333333d0 * ((j * (l ** 3.0d0)) * cos((k * 0.5d0))))
t_1 = ((exp(l) - exp(-l)) * j) + u
if (l <= (-2.9d+127)) then
tmp = t_0
else if (l <= (-0.36d0)) then
tmp = t_1
else if (l <= 40000000.0d0) then
tmp = u + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
else if (l <= 1.26d+88) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = U + (0.3333333333333333 * ((J * Math.pow(l, 3.0)) * Math.cos((K * 0.5))));
double t_1 = ((Math.exp(l) - Math.exp(-l)) * J) + U;
double tmp;
if (l <= -2.9e+127) {
tmp = t_0;
} else if (l <= -0.36) {
tmp = t_1;
} else if (l <= 40000000.0) {
tmp = U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
} else if (l <= 1.26e+88) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(J, l, K, U): t_0 = U + (0.3333333333333333 * ((J * math.pow(l, 3.0)) * math.cos((K * 0.5)))) t_1 = ((math.exp(l) - math.exp(-l)) * J) + U tmp = 0 if l <= -2.9e+127: tmp = t_0 elif l <= -0.36: tmp = t_1 elif l <= 40000000.0: tmp = U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))) elif l <= 1.26e+88: tmp = t_1 else: tmp = t_0 return tmp
function code(J, l, K, U) t_0 = Float64(U + Float64(0.3333333333333333 * Float64(Float64(J * (l ^ 3.0)) * cos(Float64(K * 0.5))))) t_1 = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U) tmp = 0.0 if (l <= -2.9e+127) tmp = t_0; elseif (l <= -0.36) tmp = t_1; elseif (l <= 40000000.0) tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))); elseif (l <= 1.26e+88) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = U + (0.3333333333333333 * ((J * (l ^ 3.0)) * cos((K * 0.5)))); t_1 = ((exp(l) - exp(-l)) * J) + U; tmp = 0.0; if (l <= -2.9e+127) tmp = t_0; elseif (l <= -0.36) tmp = t_1; elseif (l <= 40000000.0) tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))); elseif (l <= 1.26e+88) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(0.3333333333333333 * N[(N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]}, If[LessEqual[l, -2.9e+127], t$95$0, If[LessEqual[l, -0.36], t$95$1, If[LessEqual[l, 40000000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.26e+88], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := U + 0.3333333333333333 \cdot \left(\left(J \cdot {\ell}^{3}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\
t_1 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
\mathbf{if}\;\ell \leq -2.9 \cdot 10^{+127}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\ell \leq -0.36:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq 40000000:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\
\mathbf{elif}\;\ell \leq 1.26 \cdot 10^{+88}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if l < -2.9000000000000002e127 or 1.26e88 < l Initial program 100.0%
Taylor expanded in l around 0 98.8%
Taylor expanded in l around inf 98.8%
associate-*r*98.8%
Simplified98.8%
if -2.9000000000000002e127 < l < -0.35999999999999999 or 4e7 < l < 1.26e88Initial program 100.0%
Taylor expanded in K around 0 84.2%
if -0.35999999999999999 < l < 4e7Initial program 75.3%
Taylor expanded in l around 0 97.5%
Final simplification95.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (* K 0.5)))
(t_1 (+ U (* 0.3333333333333333 (* (* J (pow l 3.0)) t_0))))
(t_2 (+ (* (- (exp l) (exp (- l))) J) U)))
(if (<= l -1e+132)
t_1
(if (<= l -0.32)
t_2
(if (<= l 40000000.0)
(+ U (* 2.0 (* J (* l t_0))))
(if (<= l 7.8e+87) t_2 t_1))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K * 0.5));
double t_1 = U + (0.3333333333333333 * ((J * pow(l, 3.0)) * t_0));
double t_2 = ((exp(l) - exp(-l)) * J) + U;
double tmp;
if (l <= -1e+132) {
tmp = t_1;
} else if (l <= -0.32) {
tmp = t_2;
} else if (l <= 40000000.0) {
tmp = U + (2.0 * (J * (l * t_0)));
} else if (l <= 7.8e+87) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = cos((k * 0.5d0))
t_1 = u + (0.3333333333333333d0 * ((j * (l ** 3.0d0)) * t_0))
t_2 = ((exp(l) - exp(-l)) * j) + u
if (l <= (-1d+132)) then
tmp = t_1
else if (l <= (-0.32d0)) then
tmp = t_2
else if (l <= 40000000.0d0) then
tmp = u + (2.0d0 * (j * (l * t_0)))
else if (l <= 7.8d+87) then
tmp = t_2
else
tmp = t_1
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K * 0.5));
double t_1 = U + (0.3333333333333333 * ((J * Math.pow(l, 3.0)) * t_0));
double t_2 = ((Math.exp(l) - Math.exp(-l)) * J) + U;
double tmp;
if (l <= -1e+132) {
tmp = t_1;
} else if (l <= -0.32) {
tmp = t_2;
} else if (l <= 40000000.0) {
tmp = U + (2.0 * (J * (l * t_0)));
} else if (l <= 7.8e+87) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K * 0.5)) t_1 = U + (0.3333333333333333 * ((J * math.pow(l, 3.0)) * t_0)) t_2 = ((math.exp(l) - math.exp(-l)) * J) + U tmp = 0 if l <= -1e+132: tmp = t_1 elif l <= -0.32: tmp = t_2 elif l <= 40000000.0: tmp = U + (2.0 * (J * (l * t_0))) elif l <= 7.8e+87: tmp = t_2 else: tmp = t_1 return tmp
function code(J, l, K, U) t_0 = cos(Float64(K * 0.5)) t_1 = Float64(U + Float64(0.3333333333333333 * Float64(Float64(J * (l ^ 3.0)) * t_0))) t_2 = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U) tmp = 0.0 if (l <= -1e+132) tmp = t_1; elseif (l <= -0.32) tmp = t_2; elseif (l <= 40000000.0) tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0)))); elseif (l <= 7.8e+87) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K * 0.5)); t_1 = U + (0.3333333333333333 * ((J * (l ^ 3.0)) * t_0)); t_2 = ((exp(l) - exp(-l)) * J) + U; tmp = 0.0; if (l <= -1e+132) tmp = t_1; elseif (l <= -0.32) tmp = t_2; elseif (l <= 40000000.0) tmp = U + (2.0 * (J * (l * t_0))); elseif (l <= 7.8e+87) tmp = t_2; else tmp = t_1; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(0.3333333333333333 * N[(N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]}, If[LessEqual[l, -1e+132], t$95$1, If[LessEqual[l, -0.32], t$95$2, If[LessEqual[l, 40000000.0], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7.8e+87], t$95$2, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := U + 0.3333333333333333 \cdot \left(\left(J \cdot {\ell}^{3}\right) \cdot t_0\right)\\
t_2 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
\mathbf{if}\;\ell \leq -1 \cdot 10^{+132}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq -0.32:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq 40000000:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_0\right)\right)\\
\mathbf{elif}\;\ell \leq 7.8 \cdot 10^{+87}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if l < -9.99999999999999991e131 or 7.80000000000000039e87 < l Initial program 100.0%
Taylor expanded in l around 0 98.8%
Taylor expanded in l around inf 98.8%
associate-*r*98.8%
Simplified98.8%
if -9.99999999999999991e131 < l < -0.320000000000000007 or 4e7 < l < 7.80000000000000039e87Initial program 100.0%
Taylor expanded in K around 0 84.2%
if -0.320000000000000007 < l < 4e7Initial program 75.3%
Taylor expanded in l around 0 97.2%
Final simplification95.8%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) 0.02) (+ U (* 2.0 (* J (* l (cos (* K 0.5)))))) (+ U (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= 0.02) {
tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
} else {
tmp = U + (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0)));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if (cos((k / 2.0d0)) <= 0.02d0) then
tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
else
tmp = u + (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0)))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if (Math.cos((K / 2.0)) <= 0.02) {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
} else {
tmp = U + (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= 0.02: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) else: tmp = U + (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= 0.02) tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5)))))); else tmp = Float64(U + Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= 0.02) tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); else tmp = U + (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.02], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.02:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < 0.0200000000000000004Initial program 83.5%
Taylor expanded in l around 0 67.1%
if 0.0200000000000000004 < (cos.f64 (/.f64 K 2)) Initial program 87.6%
Taylor expanded in l around 0 89.2%
Taylor expanded in K around 0 87.3%
Final simplification81.9%
(FPCore (J l K U) :precision binary64 (if (or (<= l -0.32) (not (<= l 40000000.0))) (+ (* (- (exp l) (exp (- l))) J) U) (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -0.32) || !(l <= 40000000.0)) {
tmp = ((exp(l) - exp(-l)) * J) + U;
} else {
tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if ((l <= (-0.32d0)) .or. (.not. (l <= 40000000.0d0))) then
tmp = ((exp(l) - exp(-l)) * j) + u
else
tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -0.32) || !(l <= 40000000.0)) {
tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
} else {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -0.32) or not (l <= 40000000.0): tmp = ((math.exp(l) - math.exp(-l)) * J) + U else: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -0.32) || !(l <= 40000000.0)) tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U); else tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5)))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -0.32) || ~((l <= 40000000.0))) tmp = ((exp(l) - exp(-l)) * J) + U; else tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -0.32], N[Not[LessEqual[l, 40000000.0]], $MachinePrecision]], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.32 \lor \neg \left(\ell \leq 40000000\right):\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if l < -0.320000000000000007 or 4e7 < l Initial program 100.0%
Taylor expanded in K around 0 79.3%
if -0.320000000000000007 < l < 4e7Initial program 75.3%
Taylor expanded in l around 0 97.2%
Final simplification89.1%
(FPCore (J l K U) :precision binary64 (if (or (<= l -3400000000000.0) (not (<= l 2.75e+35))) (+ U (* 0.3333333333333333 (* J (pow l 3.0)))) (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -3400000000000.0) || !(l <= 2.75e+35)) {
tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
} else {
tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if ((l <= (-3400000000000.0d0)) .or. (.not. (l <= 2.75d+35))) then
tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
else
tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -3400000000000.0) || !(l <= 2.75e+35)) {
tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
} else {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -3400000000000.0) or not (l <= 2.75e+35): tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0))) else: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -3400000000000.0) || !(l <= 2.75e+35)) tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))); else tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5)))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -3400000000000.0) || ~((l <= 2.75e+35))) tmp = U + (0.3333333333333333 * (J * (l ^ 3.0))); else tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -3400000000000.0], N[Not[LessEqual[l, 2.75e+35]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3400000000000 \lor \neg \left(\ell \leq 2.75 \cdot 10^{+35}\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if l < -3.4e12 or 2.75000000000000001e35 < l Initial program 100.0%
Taylor expanded in l around 0 80.1%
Taylor expanded in l around inf 80.1%
associate-*r*80.1%
Simplified80.1%
Taylor expanded in K around 0 64.6%
if -3.4e12 < l < 2.75000000000000001e35Initial program 76.1%
Taylor expanded in l around 0 93.9%
Final simplification81.2%
(FPCore (J l K U) :precision binary64 (if (or (<= l -1600000000000.0) (not (<= l 0.075))) (+ U (* 0.3333333333333333 (* J (pow l 3.0)))) (+ U (* J (* l 2.0)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1600000000000.0) || !(l <= 0.075)) {
tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
} else {
tmp = U + (J * (l * 2.0));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if ((l <= (-1600000000000.0d0)) .or. (.not. (l <= 0.075d0))) then
tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
else
tmp = u + (j * (l * 2.0d0))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1600000000000.0) || !(l <= 0.075)) {
tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
} else {
tmp = U + (J * (l * 2.0));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -1600000000000.0) or not (l <= 0.075): tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0))) else: tmp = U + (J * (l * 2.0)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -1600000000000.0) || !(l <= 0.075)) tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))); else tmp = Float64(U + Float64(J * Float64(l * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -1600000000000.0) || ~((l <= 0.075))) tmp = U + (0.3333333333333333 * (J * (l ^ 3.0))); else tmp = U + (J * (l * 2.0)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1600000000000.0], N[Not[LessEqual[l, 0.075]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1600000000000 \lor \neg \left(\ell \leq 0.075\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\
\end{array}
\end{array}
if l < -1.6e12 or 0.0749999999999999972 < l Initial program 100.0%
Taylor expanded in l around 0 75.3%
Taylor expanded in l around inf 75.0%
associate-*r*75.0%
Simplified75.0%
Taylor expanded in K around 0 60.4%
if -1.6e12 < l < 0.0749999999999999972Initial program 74.7%
Taylor expanded in l around 0 99.0%
Taylor expanded in K around 0 88.1%
*-commutative88.1%
associate-*r*88.1%
Simplified88.1%
Final simplification75.2%
(FPCore (J l K U) :precision binary64 (+ U (* J (* l 2.0))))
double code(double J, double l, double K, double U) {
return U + (J * (l * 2.0));
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u + (j * (l * 2.0d0))
end function
public static double code(double J, double l, double K, double U) {
return U + (J * (l * 2.0));
}
def code(J, l, K, U): return U + (J * (l * 2.0))
function code(J, l, K, U) return Float64(U + Float64(J * Float64(l * 2.0))) end
function tmp = code(J, l, K, U) tmp = U + (J * (l * 2.0)); end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + J \cdot \left(\ell \cdot 2\right)
\end{array}
Initial program 86.5%
Taylor expanded in l around 0 64.8%
Taylor expanded in K around 0 57.0%
*-commutative57.0%
associate-*r*57.0%
Simplified57.0%
Final simplification57.0%
(FPCore (J l K U) :precision binary64 U)
double code(double J, double l, double K, double U) {
return U;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u
end function
public static double code(double J, double l, double K, double U) {
return U;
}
def code(J, l, K, U): return U
function code(J, l, K, U) return U end
function tmp = code(J, l, K, U) tmp = U; end
code[J_, l_, K_, U_] := U
\begin{array}{l}
\\
U
\end{array}
Initial program 86.5%
Applied egg-rr26.0%
Applied egg-rr25.4%
rem-log-exp25.4%
*-commutative25.4%
Simplified25.4%
Taylor expanded in J around 0 40.2%
Final simplification40.2%
herbie shell --seed 2023337
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))