
(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 (+ (* J (log1p (expm1 (* l (* 2.0 (cos (* K 0.5))))))) U))
double code(double J, double l, double K, double U) {
return (J * log1p(expm1((l * (2.0 * cos((K * 0.5))))))) + U;
}
public static double code(double J, double l, double K, double U) {
return (J * Math.log1p(Math.expm1((l * (2.0 * Math.cos((K * 0.5))))))) + U;
}
def code(J, l, K, U): return (J * math.log1p(math.expm1((l * (2.0 * math.cos((K * 0.5))))))) + U
function code(J, l, K, U) return Float64(Float64(J * log1p(expm1(Float64(l * Float64(2.0 * cos(Float64(K * 0.5))))))) + U) end
code[J_, l_, K_, U_] := N[(N[(J * N[Log[1 + N[(Exp[N[(l * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U
\end{array}
Initial program 85.9%
Taylor expanded in l around 0 89.5%
Taylor expanded in l around 0 64.9%
associate-*r*64.9%
*-commutative64.9%
associate-*l*64.9%
*-commutative64.9%
associate-*l*64.9%
*-commutative64.9%
Simplified64.9%
log1p-expm1-u99.4%
*-commutative99.4%
associate-*l*99.4%
*-commutative99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (* J (- (exp l) (exp (- l))))))
(if (or (<= t_0 -2e+25) (not (<= t_0 2e+141)))
(+ U t_0)
(+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
double t_0 = J * (exp(l) - exp(-l));
double tmp;
if ((t_0 <= -2e+25) || !(t_0 <= 2e+141)) {
tmp = U + t_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) :: t_0
real(8) :: tmp
t_0 = j * (exp(l) - exp(-l))
if ((t_0 <= (-2d+25)) .or. (.not. (t_0 <= 2d+141))) then
tmp = u + t_0
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 t_0 = J * (Math.exp(l) - Math.exp(-l));
double tmp;
if ((t_0 <= -2e+25) || !(t_0 <= 2e+141)) {
tmp = U + t_0;
} else {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): t_0 = J * (math.exp(l) - math.exp(-l)) tmp = 0 if (t_0 <= -2e+25) or not (t_0 <= 2e+141): tmp = U + t_0 else: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) t_0 = Float64(J * Float64(exp(l) - exp(Float64(-l)))) tmp = 0.0 if ((t_0 <= -2e+25) || !(t_0 <= 2e+141)) tmp = Float64(U + t_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) t_0 = J * (exp(l) - exp(-l)); tmp = 0.0; if ((t_0 <= -2e+25) || ~((t_0 <= 2e+141))) tmp = U + t_0; else tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+25], N[Not[LessEqual[t$95$0, 2e+141]], $MachinePrecision]], N[(U + t$95$0), $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}
t_0 := J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+25} \lor \neg \left(t_0 \leq 2 \cdot 10^{+141}\right):\\
\;\;\;\;U + t_0\\
\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 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -2.00000000000000018e25 or 2.00000000000000003e141 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) Initial program 100.0%
Taylor expanded in K around 0 74.5%
if -2.00000000000000018e25 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 2.00000000000000003e141Initial program 71.7%
Taylor expanded in l around 0 99.6%
Final simplification87.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= t_0 -0.55)
(+ U (* t_0 (* l (* J 2.0))))
(if (<= t_0 -0.04)
(+ U (* -0.25 (* J (* l (pow K 2.0)))))
(+ U (* J (+ (* (pow l 3.0) 0.3333333333333333) (* l 2.0))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (t_0 <= -0.55) {
tmp = U + (t_0 * (l * (J * 2.0)));
} else if (t_0 <= -0.04) {
tmp = U + (-0.25 * (J * (l * pow(K, 2.0))));
} else {
tmp = U + (J * ((pow(l, 3.0) * 0.3333333333333333) + (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) :: t_0
real(8) :: tmp
t_0 = cos((k / 2.0d0))
if (t_0 <= (-0.55d0)) then
tmp = u + (t_0 * (l * (j * 2.0d0)))
else if (t_0 <= (-0.04d0)) then
tmp = u + ((-0.25d0) * (j * (l * (k ** 2.0d0))))
else
tmp = u + (j * (((l ** 3.0d0) * 0.3333333333333333d0) + (l * 2.0d0)))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (t_0 <= -0.55) {
tmp = U + (t_0 * (l * (J * 2.0)));
} else if (t_0 <= -0.04) {
tmp = U + (-0.25 * (J * (l * Math.pow(K, 2.0))));
} else {
tmp = U + (J * ((Math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0)));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if t_0 <= -0.55: tmp = U + (t_0 * (l * (J * 2.0))) elif t_0 <= -0.04: tmp = U + (-0.25 * (J * (l * math.pow(K, 2.0)))) else: tmp = U + (J * ((math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (t_0 <= -0.55) tmp = Float64(U + Float64(t_0 * Float64(l * Float64(J * 2.0)))); elseif (t_0 <= -0.04) tmp = Float64(U + Float64(-0.25 * Float64(J * Float64(l * (K ^ 2.0))))); else tmp = Float64(U + Float64(J * Float64(Float64((l ^ 3.0) * 0.3333333333333333) + Float64(l * 2.0)))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); tmp = 0.0; if (t_0 <= -0.55) tmp = U + (t_0 * (l * (J * 2.0))); elseif (t_0 <= -0.04) tmp = U + (-0.25 * (J * (l * (K ^ 2.0)))); else tmp = U + (J * (((l ^ 3.0) * 0.3333333333333333) + (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]}, If[LessEqual[t$95$0, -0.55], N[(U + N[(t$95$0 * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.04], N[(U + N[(-0.25 * N[(J * N[(l * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq -0.55:\\
\;\;\;\;U + t_0 \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\
\mathbf{elif}\;t_0 \leq -0.04:\\
\;\;\;\;U + -0.25 \cdot \left(J \cdot \left(\ell \cdot {K}^{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.55000000000000004Initial program 82.5%
Taylor expanded in l around 0 67.9%
associate-*r*67.9%
*-commutative67.9%
Simplified67.9%
if -0.55000000000000004 < (cos.f64 (/.f64 K 2)) < -0.0400000000000000008Initial program 87.8%
Taylor expanded in l around 0 51.5%
associate-*r*51.5%
*-commutative51.5%
associate-*l*51.5%
Simplified51.5%
Taylor expanded in K around 0 53.8%
Taylor expanded in K around inf 70.5%
if -0.0400000000000000008 < (cos.f64 (/.f64 K 2)) Initial program 86.4%
Taylor expanded in l around 0 89.1%
Taylor expanded in K around 0 85.7%
Final simplification81.5%
(FPCore (J l K U)
:precision binary64
(let* ((t_0
(+ U (* (* (pow l 3.0) (* J 0.3333333333333333)) (cos (/ K 2.0)))))
(t_1 (+ U (* J (- (exp l) (exp (- l)))))))
(if (<= l -5.8e+102)
t_0
(if (<= l -0.00145)
t_1
(if (<= l 1.3e-18)
(+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
(if (<= l 5.6e+102) t_1 t_0))))))
double code(double J, double l, double K, double U) {
double t_0 = U + ((pow(l, 3.0) * (J * 0.3333333333333333)) * cos((K / 2.0)));
double t_1 = U + (J * (exp(l) - exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_0;
} else if (l <= -0.00145) {
tmp = t_1;
} else if (l <= 1.3e-18) {
tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
} else if (l <= 5.6e+102) {
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 + (((l ** 3.0d0) * (j * 0.3333333333333333d0)) * cos((k / 2.0d0)))
t_1 = u + (j * (exp(l) - exp(-l)))
if (l <= (-5.8d+102)) then
tmp = t_0
else if (l <= (-0.00145d0)) then
tmp = t_1
else if (l <= 1.3d-18) then
tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
else if (l <= 5.6d+102) 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 + ((Math.pow(l, 3.0) * (J * 0.3333333333333333)) * Math.cos((K / 2.0)));
double t_1 = U + (J * (Math.exp(l) - Math.exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_0;
} else if (l <= -0.00145) {
tmp = t_1;
} else if (l <= 1.3e-18) {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
} else if (l <= 5.6e+102) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(J, l, K, U): t_0 = U + ((math.pow(l, 3.0) * (J * 0.3333333333333333)) * math.cos((K / 2.0))) t_1 = U + (J * (math.exp(l) - math.exp(-l))) tmp = 0 if l <= -5.8e+102: tmp = t_0 elif l <= -0.00145: tmp = t_1 elif l <= 1.3e-18: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) elif l <= 5.6e+102: tmp = t_1 else: tmp = t_0 return tmp
function code(J, l, K, U) t_0 = Float64(U + Float64(Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)) * cos(Float64(K / 2.0)))) t_1 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l))))) tmp = 0.0 if (l <= -5.8e+102) tmp = t_0; elseif (l <= -0.00145) tmp = t_1; elseif (l <= 1.3e-18) tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5)))))); elseif (l <= 5.6e+102) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = U + (((l ^ 3.0) * (J * 0.3333333333333333)) * cos((K / 2.0))); t_1 = U + (J * (exp(l) - exp(-l))); tmp = 0.0; if (l <= -5.8e+102) tmp = t_0; elseif (l <= -0.00145) tmp = t_1; elseif (l <= 1.3e-18) tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); elseif (l <= 5.6e+102) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.8e+102], t$95$0, If[LessEqual[l, -0.00145], t$95$1, If[LessEqual[l, 1.3e-18], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.6e+102], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\
t_1 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;\ell \leq -5.8 \cdot 10^{+102}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\ell \leq -0.00145:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-18}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if l < -5.8000000000000005e102 or 5.60000000000000037e102 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
Taylor expanded in l around inf 100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
if -5.8000000000000005e102 < l < -0.00145 or 1.3e-18 < l < 5.60000000000000037e102Initial program 99.9%
Taylor expanded in K around 0 82.9%
if -0.00145 < l < 1.3e-18Initial program 71.0%
Taylor expanded in l around 0 99.6%
Final simplification97.1%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1 (+ U (* (* (pow l 3.0) (* J 0.3333333333333333)) t_0)))
(t_2 (+ U (* J (- (exp l) (exp (- l)))))))
(if (<= l -5.8e+102)
t_1
(if (<= l -0.031)
t_2
(if (<= l 2200000.0)
(+ U (* t_0 (* J (+ (* (pow l 3.0) 0.3333333333333333) (* l 2.0)))))
(if (<= l 5.6e+102) t_2 t_1))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = U + ((pow(l, 3.0) * (J * 0.3333333333333333)) * t_0);
double t_2 = U + (J * (exp(l) - exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_1;
} else if (l <= -0.031) {
tmp = t_2;
} else if (l <= 2200000.0) {
tmp = U + (t_0 * (J * ((pow(l, 3.0) * 0.3333333333333333) + (l * 2.0))));
} else if (l <= 5.6e+102) {
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 / 2.0d0))
t_1 = u + (((l ** 3.0d0) * (j * 0.3333333333333333d0)) * t_0)
t_2 = u + (j * (exp(l) - exp(-l)))
if (l <= (-5.8d+102)) then
tmp = t_1
else if (l <= (-0.031d0)) then
tmp = t_2
else if (l <= 2200000.0d0) then
tmp = u + (t_0 * (j * (((l ** 3.0d0) * 0.3333333333333333d0) + (l * 2.0d0))))
else if (l <= 5.6d+102) 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 / 2.0));
double t_1 = U + ((Math.pow(l, 3.0) * (J * 0.3333333333333333)) * t_0);
double t_2 = U + (J * (Math.exp(l) - Math.exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_1;
} else if (l <= -0.031) {
tmp = t_2;
} else if (l <= 2200000.0) {
tmp = U + (t_0 * (J * ((Math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0))));
} else if (l <= 5.6e+102) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = U + ((math.pow(l, 3.0) * (J * 0.3333333333333333)) * t_0) t_2 = U + (J * (math.exp(l) - math.exp(-l))) tmp = 0 if l <= -5.8e+102: tmp = t_1 elif l <= -0.031: tmp = t_2 elif l <= 2200000.0: tmp = U + (t_0 * (J * ((math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0)))) elif l <= 5.6e+102: tmp = t_2 else: tmp = t_1 return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(U + Float64(Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)) * t_0)) t_2 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l))))) tmp = 0.0 if (l <= -5.8e+102) tmp = t_1; elseif (l <= -0.031) tmp = t_2; elseif (l <= 2200000.0) tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64((l ^ 3.0) * 0.3333333333333333) + Float64(l * 2.0))))); elseif (l <= 5.6e+102) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = U + (((l ^ 3.0) * (J * 0.3333333333333333)) * t_0); t_2 = U + (J * (exp(l) - exp(-l))); tmp = 0.0; if (l <= -5.8e+102) tmp = t_1; elseif (l <= -0.031) tmp = t_2; elseif (l <= 2200000.0) tmp = U + (t_0 * (J * (((l ^ 3.0) * 0.3333333333333333) + (l * 2.0)))); elseif (l <= 5.6e+102) 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 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.8e+102], t$95$1, If[LessEqual[l, -0.031], t$95$2, If[LessEqual[l, 2200000.0], N[(U + N[(t$95$0 * N[(J * N[(N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.6e+102], t$95$2, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot t_0\\
t_2 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;\ell \leq -5.8 \cdot 10^{+102}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq -0.031:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq 2200000:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\right)\\
\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if l < -5.8000000000000005e102 or 5.60000000000000037e102 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
Taylor expanded in l around inf 100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
if -5.8000000000000005e102 < l < -0.031 or 2.2e6 < l < 5.60000000000000037e102Initial program 100.0%
Taylor expanded in K around 0 85.3%
if -0.031 < l < 2.2e6Initial program 72.3%
Taylor expanded in l around 0 98.5%
Final simplification97.3%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.04) (+ U (* -0.25 (* J (* l (pow K 2.0))))) (+ U (* 0.3333333333333333 (* J (pow l 3.0))))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.04) {
tmp = U + (-0.25 * (J * (l * pow(K, 2.0))));
} else {
tmp = U + (0.3333333333333333 * (J * pow(l, 3.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.04d0)) then
tmp = u + ((-0.25d0) * (j * (l * (k ** 2.0d0))))
else
tmp = u + (0.3333333333333333d0 * (j * (l ** 3.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.04) {
tmp = U + (-0.25 * (J * (l * Math.pow(K, 2.0))));
} else {
tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= -0.04: tmp = U + (-0.25 * (J * (l * math.pow(K, 2.0)))) else: tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0))) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.04) tmp = Float64(U + Float64(-0.25 * Float64(J * Float64(l * (K ^ 2.0))))); else tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= -0.04) tmp = U + (-0.25 * (J * (l * (K ^ 2.0)))); else tmp = U + (0.3333333333333333 * (J * (l ^ 3.0))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.04], N[(U + N[(-0.25 * N[(J * N[(l * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.04:\\
\;\;\;\;U + -0.25 \cdot \left(J \cdot \left(\ell \cdot {K}^{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.0400000000000000008Initial program 84.5%
Taylor expanded in l around 0 61.7%
associate-*r*61.7%
*-commutative61.7%
associate-*l*61.7%
Simplified61.7%
Taylor expanded in K around 0 50.9%
Taylor expanded in K around inf 61.9%
if -0.0400000000000000008 < (cos.f64 (/.f64 K 2)) Initial program 86.4%
Taylor expanded in l around 0 89.1%
Taylor expanded in K around 0 85.7%
Taylor expanded in l around inf 75.3%
Final simplification71.9%
(FPCore (J l K U) :precision binary64 (if (or (<= l -780000.0) (not (<= l 4.4))) (+ 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 <= -780000.0) || !(l <= 4.4)) {
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 <= (-780000.0d0)) .or. (.not. (l <= 4.4d0))) 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 <= -780000.0) || !(l <= 4.4)) {
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 <= -780000.0) or not (l <= 4.4): 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 <= -780000.0) || !(l <= 4.4)) 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 <= -780000.0) || ~((l <= 4.4))) 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, -780000.0], N[Not[LessEqual[l, 4.4]], $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 -780000 \lor \neg \left(\ell \leq 4.4\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 < -7.8e5 or 4.4000000000000004 < l Initial program 100.0%
Taylor expanded in l around 0 79.1%
Taylor expanded in K around 0 58.7%
Taylor expanded in l around inf 58.7%
if -7.8e5 < l < 4.4000000000000004Initial program 71.9%
Taylor expanded in l around 0 99.6%
Final simplification79.1%
(FPCore (J l K U) :precision binary64 (if (or (<= l -7.2e-5) (not (<= l 2.6))) (+ U (* 0.3333333333333333 (* J (pow l 3.0)))) (+ U (* l (* J 2.0)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -7.2e-5) || !(l <= 2.6)) {
tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
} else {
tmp = U + (l * (J * 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 <= (-7.2d-5)) .or. (.not. (l <= 2.6d0))) then
tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
else
tmp = u + (l * (j * 2.0d0))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -7.2e-5) || !(l <= 2.6)) {
tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
} else {
tmp = U + (l * (J * 2.0));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -7.2e-5) or not (l <= 2.6): tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0))) else: tmp = U + (l * (J * 2.0)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -7.2e-5) || !(l <= 2.6)) tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))); else tmp = Float64(U + Float64(l * Float64(J * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -7.2e-5) || ~((l <= 2.6))) tmp = U + (0.3333333333333333 * (J * (l ^ 3.0))); else tmp = U + (l * (J * 2.0)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -7.2e-5], N[Not[LessEqual[l, 2.6]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7.2 \cdot 10^{-5} \lor \neg \left(\ell \leq 2.6\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\
\end{array}
\end{array}
if l < -7.20000000000000018e-5 or 2.60000000000000009 < l Initial program 99.8%
Taylor expanded in l around 0 79.3%
Taylor expanded in K around 0 58.3%
Taylor expanded in l around inf 58.3%
if -7.20000000000000018e-5 < l < 2.60000000000000009Initial program 71.8%
Taylor expanded in l around 0 99.9%
associate-*r*99.9%
*-commutative99.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in K around 0 87.1%
Final simplification72.6%
(FPCore (J l K U) :precision binary64 (+ U (* l (* J 2.0))))
double code(double J, double l, double K, double U) {
return U + (l * (J * 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 + (l * (j * 2.0d0))
end function
public static double code(double J, double l, double K, double U) {
return U + (l * (J * 2.0));
}
def code(J, l, K, U): return U + (l * (J * 2.0))
function code(J, l, K, U) return Float64(U + Float64(l * Float64(J * 2.0))) end
function tmp = code(J, l, K, U) tmp = U + (l * (J * 2.0)); end
code[J_, l_, K_, U_] := N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + \ell \cdot \left(J \cdot 2\right)
\end{array}
Initial program 85.9%
Taylor expanded in l around 0 64.9%
associate-*r*64.9%
*-commutative64.9%
associate-*l*64.9%
Simplified64.9%
Taylor expanded in K around 0 55.4%
Final simplification55.4%
(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 85.9%
Taylor expanded in l around 0 89.5%
Taylor expanded in l around inf 75.1%
*-commutative75.1%
*-commutative75.1%
associate-*l*75.1%
Simplified75.1%
Taylor expanded in l around 0 36.3%
Final simplification36.3%
herbie shell --seed 2024024
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))