
(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 14 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))) (t_2 (- (exp l) t_1)))
(if (<= t_2 (- INFINITY))
(+ (* (* J (- 27.0 t_1)) t_0) U)
(if (<= t_2 5e-8)
(+ U (* t_0 (* J (* l 2.0))))
(+ U (* t_0 (* t_2 J)))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = exp(-l);
double t_2 = exp(l) - t_1;
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = ((J * (27.0 - t_1)) * t_0) + U;
} else if (t_2 <= 5e-8) {
tmp = U + (t_0 * (J * (l * 2.0)));
} else {
tmp = U + (t_0 * (t_2 * J));
}
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);
double t_2 = Math.exp(l) - t_1;
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = ((J * (27.0 - t_1)) * t_0) + U;
} else if (t_2 <= 5e-8) {
tmp = U + (t_0 * (J * (l * 2.0)));
} else {
tmp = U + (t_0 * (t_2 * J));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = math.exp(-l) t_2 = math.exp(l) - t_1 tmp = 0 if t_2 <= -math.inf: tmp = ((J * (27.0 - t_1)) * t_0) + U elif t_2 <= 5e-8: tmp = U + (t_0 * (J * (l * 2.0))) else: tmp = U + (t_0 * (t_2 * J)) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = exp(Float64(-l)) t_2 = Float64(exp(l) - t_1) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(Float64(Float64(J * Float64(27.0 - t_1)) * t_0) + U); elseif (t_2 <= 5e-8) tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0)))); else tmp = Float64(U + Float64(t_0 * Float64(t_2 * J))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = exp(-l); t_2 = exp(l) - t_1; tmp = 0.0; if (t_2 <= -Inf) tmp = ((J * (27.0 - t_1)) * t_0) + U; elseif (t_2 <= 5e-8) tmp = U + (t_0 * (J * (l * 2.0))); else tmp = U + (t_0 * (t_2 * J)); 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[Exp[(-l)], $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[l], $MachinePrecision] - t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(N[(J * N[(27.0 - t$95$1), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[t$95$2, 5e-8], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(t$95$2 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{-\ell}\\
t_2 := e^{\ell} - t\_1\\
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;\left(J \cdot \left(27 - t\_1\right)\right) \cdot t\_0 + U\\
\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-8}:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(t\_2 \cdot J\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0Initial program 100.0%
Applied egg-rr100.0%
if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 4.9999999999999998e-8Initial program 68.6%
Taylor expanded in l around 0 99.9%
*-commutative99.9%
associate-*l*99.9%
Simplified99.9%
if 4.9999999999999998e-8 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
Final simplification99.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= l -225.0)
(+ (* (* J (- 27.0 (exp (- l)))) t_0) U)
(if (<= l 450.0)
(+ U (* t_0 (* J (* l 2.0))))
(if (<= l 6.6e+101)
(+ U (* J (log1p (expm1 (* l 2.0)))))
(+ U (* t_0 (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (l <= -225.0) {
tmp = ((J * (27.0 - exp(-l))) * t_0) + U;
} else if (l <= 450.0) {
tmp = U + (t_0 * (J * (l * 2.0)));
} else if (l <= 6.6e+101) {
tmp = U + (J * log1p(expm1((l * 2.0))));
} else {
tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
return tmp;
}
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (l <= -225.0) {
tmp = ((J * (27.0 - Math.exp(-l))) * t_0) + U;
} else if (l <= 450.0) {
tmp = U + (t_0 * (J * (l * 2.0)));
} else if (l <= 6.6e+101) {
tmp = U + (J * Math.log1p(Math.expm1((l * 2.0))));
} else {
tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if l <= -225.0: tmp = ((J * (27.0 - math.exp(-l))) * t_0) + U elif l <= 450.0: tmp = U + (t_0 * (J * (l * 2.0))) elif l <= 6.6e+101: tmp = U + (J * math.log1p(math.expm1((l * 2.0)))) else: tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (l <= -225.0) tmp = Float64(Float64(Float64(J * Float64(27.0 - exp(Float64(-l)))) * t_0) + U); elseif (l <= 450.0) tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0)))); elseif (l <= 6.6e+101) tmp = Float64(U + Float64(J * log1p(expm1(Float64(l * 2.0))))); else tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l))))))); end return tmp end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -225.0], N[(N[(N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 450.0], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.6e+101], N[(U + N[(J * N[Log[1 + N[(Exp[N[(l * 2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -225:\\
\;\;\;\;\left(J \cdot \left(27 - e^{-\ell}\right)\right) \cdot t\_0 + U\\
\mathbf{elif}\;\ell \leq 450:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\
\mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+101}:\\
\;\;\;\;U + J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\
\end{array}
\end{array}
if l < -225Initial program 100.0%
Applied egg-rr100.0%
if -225 < l < 450Initial program 68.6%
Taylor expanded in l around 0 99.9%
*-commutative99.9%
associate-*l*99.9%
Simplified99.9%
if 450 < l < 6.60000000000000022e101Initial program 100.0%
Taylor expanded in l around 0 19.8%
*-commutative19.8%
associate-*l*19.8%
*-commutative19.8%
*-commutative19.8%
Simplified19.8%
Taylor expanded in K around 0 15.5%
associate-*r*15.5%
*-commutative15.5%
associate-*l*15.5%
Simplified15.5%
log1p-expm1-u92.0%
*-commutative92.0%
Applied egg-rr92.0%
if 6.60000000000000022e101 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
unpow2100.0%
Applied egg-rr100.0%
Final simplification99.2%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) 0.98) (* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U))))) (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= 0.98) {
tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
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.98d0) then
tmp = u * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
else
tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l)))))
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.98) {
tmp = U * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= 0.98: tmp = U * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U)))) else: tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= 0.98) tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U))))); else tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= 0.98) tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U)))); else tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.98], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.98:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.97999999999999998Initial program 79.2%
Taylor expanded in l around 0 66.4%
*-commutative66.4%
associate-*l*66.4%
*-commutative66.4%
*-commutative66.4%
Simplified66.4%
Taylor expanded in U around inf 67.9%
associate-/l*73.6%
Simplified73.6%
if 0.97999999999999998 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 90.9%
Taylor expanded in l around 0 84.3%
Taylor expanded in K around 0 84.1%
unpow284.3%
Applied egg-rr84.1%
Final simplification79.3%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= t_0 0.98)
(+ U (* t_0 (* J (* l 2.0))))
(+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (t_0 <= 0.98) {
tmp = U + (t_0 * (J * (l * 2.0)));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
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.98d0) then
tmp = u + (t_0 * (j * (l * 2.0d0)))
else
tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l)))))
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.98) {
tmp = U + (t_0 * (J * (l * 2.0)));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if t_0 <= 0.98: tmp = U + (t_0 * (J * (l * 2.0))) else: tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (t_0 <= 0.98) tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0)))); else tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))); 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.98) tmp = U + (t_0 * (J * (l * 2.0))); else tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))); 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.98], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t\_0 \leq 0.98:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.97999999999999998Initial program 79.2%
Taylor expanded in l around 0 66.4%
*-commutative66.4%
associate-*l*66.4%
Simplified66.4%
if 0.97999999999999998 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 90.9%
Taylor expanded in l around 0 84.3%
Taylor expanded in K around 0 84.1%
unpow284.3%
Applied egg-rr84.1%
Final simplification76.0%
(FPCore (J l K U)
:precision binary64
(if (<= (/ K 2.0) 5e-20)
(+ U (* J (log1p (expm1 (* l 2.0)))))
(+
U
(* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))))
double code(double J, double l, double K, double U) {
double tmp;
if ((K / 2.0) <= 5e-20) {
tmp = U + (J * log1p(expm1((l * 2.0))));
} else {
tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
return tmp;
}
public static double code(double J, double l, double K, double U) {
double tmp;
if ((K / 2.0) <= 5e-20) {
tmp = U + (J * Math.log1p(Math.expm1((l * 2.0))));
} else {
tmp = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (K / 2.0) <= 5e-20: tmp = U + (J * math.log1p(math.expm1((l * 2.0)))) else: tmp = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))) return tmp
function code(J, l, K, U) tmp = 0.0 if (Float64(K / 2.0) <= 5e-20) tmp = Float64(U + Float64(J * log1p(expm1(Float64(l * 2.0))))); else tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l))))))); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 5e-20], N[(U + N[(J * N[Log[1 + N[(Exp[N[(l * 2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-20}:\\
\;\;\;\;U + J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\
\end{array}
\end{array}
if (/.f64 K #s(literal 2 binary64)) < 4.9999999999999999e-20Initial program 85.7%
Taylor expanded in l around 0 64.4%
*-commutative64.4%
associate-*l*64.4%
*-commutative64.4%
*-commutative64.4%
Simplified64.4%
Taylor expanded in K around 0 53.6%
associate-*r*53.6%
*-commutative53.6%
associate-*l*53.6%
Simplified53.6%
log1p-expm1-u83.7%
*-commutative83.7%
Applied egg-rr83.7%
if 4.9999999999999999e-20 < (/.f64 K #s(literal 2 binary64)) Initial program 84.8%
Taylor expanded in l around 0 83.1%
unpow283.1%
Applied egg-rr83.1%
Final simplification83.6%
(FPCore (J l K U)
:precision binary64
(if (or (<= U -2.05e-81) (not (<= U 5800000.0)))
(+
U
(* (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))) (cos (* K -4.0))))
(* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U)))))))
double code(double J, double l, double K, double U) {
double tmp;
if ((U <= -2.05e-81) || !(U <= 5800000.0)) {
tmp = U + ((J * (l * (2.0 + (0.3333333333333333 * (l * l))))) * cos((K * -4.0)));
} else {
tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
}
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 ((u <= (-2.05d-81)) .or. (.not. (u <= 5800000.0d0))) then
tmp = u + ((j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))) * cos((k * (-4.0d0))))
else
tmp = u * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((U <= -2.05e-81) || !(U <= 5800000.0)) {
tmp = U + ((J * (l * (2.0 + (0.3333333333333333 * (l * l))))) * Math.cos((K * -4.0)));
} else {
tmp = U * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (U <= -2.05e-81) or not (U <= 5800000.0): tmp = U + ((J * (l * (2.0 + (0.3333333333333333 * (l * l))))) * math.cos((K * -4.0))) else: tmp = U * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U)))) return tmp
function code(J, l, K, U) tmp = 0.0 if ((U <= -2.05e-81) || !(U <= 5800000.0)) tmp = Float64(U + Float64(Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l))))) * cos(Float64(K * -4.0)))); else tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((U <= -2.05e-81) || ~((U <= 5800000.0))) tmp = U + ((J * (l * (2.0 + (0.3333333333333333 * (l * l))))) * cos((K * -4.0))); else tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U)))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[U, -2.05e-81], N[Not[LessEqual[U, 5800000.0]], $MachinePrecision]], N[(U + N[(N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;U \leq -2.05 \cdot 10^{-81} \lor \neg \left(U \leq 5800000\right):\\
\;\;\;\;U + \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \cdot \cos \left(K \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\
\end{array}
\end{array}
if U < -2.04999999999999992e-81 or 5.8e6 < U Initial program 97.1%
Taylor expanded in l around 0 90.0%
unpow290.0%
Applied egg-rr90.0%
Applied egg-rr83.1%
rem-log-exp83.1%
*-commutative83.1%
Simplified83.1%
if -2.04999999999999992e-81 < U < 5.8e6Initial program 70.9%
Taylor expanded in l around 0 62.6%
*-commutative62.6%
associate-*l*62.6%
*-commutative62.6%
*-commutative62.6%
Simplified62.6%
Taylor expanded in U around inf 74.3%
associate-/l*80.2%
Simplified80.2%
Final simplification81.8%
(FPCore (J l K U) :precision binary64 (+ U (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))
double code(double J, double l, double K, double U) {
return U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
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 + (cos((k / 2.0d0)) * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))))
end function
public static double code(double J, double l, double K, double U) {
return U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
def code(J, l, K, U): return U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
function code(J, l, K, U) return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l))))))) end
function tmp = code(J, l, K, U) tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))); end
code[J_, l_, K_, U_] := N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)
\end{array}
Initial program 85.5%
Taylor expanded in l around 0 86.2%
unpow286.2%
Applied egg-rr86.2%
Final simplification86.2%
(FPCore (J l K U) :precision binary64 (if (<= K 98000000000.0) (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))) (+ U (* l (* (cos (* K 0.5)) (* J 2.0))))))
double code(double J, double l, double K, double U) {
double tmp;
if (K <= 98000000000.0) {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
} else {
tmp = U + (l * (cos((K * 0.5)) * (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 (k <= 98000000000.0d0) then
tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l)))))
else
tmp = u + (l * (cos((k * 0.5d0)) * (j * 2.0d0)))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if (K <= 98000000000.0) {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
} else {
tmp = U + (l * (Math.cos((K * 0.5)) * (J * 2.0)));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if K <= 98000000000.0: tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))) else: tmp = U + (l * (math.cos((K * 0.5)) * (J * 2.0))) return tmp
function code(J, l, K, U) tmp = 0.0 if (K <= 98000000000.0) tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))); else tmp = Float64(U + Float64(l * Float64(cos(Float64(K * 0.5)) * Float64(J * 2.0)))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (K <= 98000000000.0) tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))); else tmp = U + (l * (cos((K * 0.5)) * (J * 2.0))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[K, 98000000000.0], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;K \leq 98000000000:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\
\end{array}
\end{array}
if K < 9.8e10Initial program 86.0%
Taylor expanded in l around 0 87.4%
Taylor expanded in K around 0 71.9%
unpow287.4%
Applied egg-rr71.9%
if 9.8e10 < K Initial program 83.6%
Taylor expanded in l around 0 81.8%
unpow281.8%
Applied egg-rr81.8%
Taylor expanded in l around 0 56.3%
*-commutative56.3%
associate-*r*56.3%
associate-*l*56.3%
*-commutative56.3%
*-commutative56.3%
*-commutative56.3%
associate-*l*56.3%
*-commutative56.3%
Simplified56.3%
Final simplification68.7%
(FPCore (J l K U) :precision binary64 (if (<= K 18000000000.0) (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))) (+ U (* J (* 2.0 (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
double tmp;
if (K <= 18000000000.0) {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
} else {
tmp = U + (J * (2.0 * (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 (k <= 18000000000.0d0) then
tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l)))))
else
tmp = u + (j * (2.0d0 * (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 (K <= 18000000000.0) {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
} else {
tmp = U + (J * (2.0 * (l * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if K <= 18000000000.0: tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))) else: tmp = U + (J * (2.0 * (l * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) tmp = 0.0 if (K <= 18000000000.0) tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))); else tmp = Float64(U + Float64(J * Float64(2.0 * Float64(l * cos(Float64(K * 0.5)))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (K <= 18000000000.0) tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))); else tmp = U + (J * (2.0 * (l * cos((K * 0.5))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[K, 18000000000.0], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(2.0 * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;K \leq 18000000000:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if K < 1.8e10Initial program 86.0%
Taylor expanded in l around 0 87.4%
Taylor expanded in K around 0 71.9%
unpow287.4%
Applied egg-rr71.9%
if 1.8e10 < K Initial program 83.6%
Taylor expanded in l around 0 56.3%
*-commutative56.3%
associate-*l*56.3%
*-commutative56.3%
*-commutative56.3%
Simplified56.3%
Final simplification68.7%
(FPCore (J l K U) :precision binary64 (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))
double code(double J, double l, double K, double U) {
return U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
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 + (0.3333333333333333d0 * (l * l)))))
end function
public static double code(double J, double l, double K, double U) {
return U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
def code(J, l, K, U): return U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))
function code(J, l, K, U) return Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))) end
function tmp = code(J, l, K, U) tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l))))); end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)
\end{array}
Initial program 85.5%
Taylor expanded in l around 0 86.2%
Taylor expanded in K around 0 65.9%
unpow286.2%
Applied egg-rr65.9%
Final simplification65.9%
(FPCore (J l K U) :precision binary64 (* U (+ 1.0 (* 2.0 (* J (/ l U))))))
double code(double J, double l, double K, double U) {
return U * (1.0 + (2.0 * (J * (l / 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 * (1.0d0 + (2.0d0 * (j * (l / u))))
end function
public static double code(double J, double l, double K, double U) {
return U * (1.0 + (2.0 * (J * (l / U))));
}
def code(J, l, K, U): return U * (1.0 + (2.0 * (J * (l / U))))
function code(J, l, K, U) return Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U))))) end
function tmp = code(J, l, K, U) tmp = U * (1.0 + (2.0 * (J * (l / U)))); end
code[J_, l_, K_, U_] := N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)
\end{array}
Initial program 85.5%
Taylor expanded in l around 0 62.2%
*-commutative62.2%
associate-*l*62.2%
*-commutative62.2%
*-commutative62.2%
Simplified62.2%
Taylor expanded in K around 0 48.4%
associate-*r*48.4%
*-commutative48.4%
associate-*l*48.4%
Simplified48.4%
log1p-expm1-u78.1%
*-commutative78.1%
Applied egg-rr78.1%
Taylor expanded in U around inf 54.8%
associate-/l*56.2%
Simplified56.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 85.5%
Taylor expanded in l around 0 62.2%
*-commutative62.2%
associate-*l*62.2%
*-commutative62.2%
*-commutative62.2%
Simplified62.2%
Taylor expanded in K around 0 48.4%
associate-*r*48.4%
*-commutative48.4%
associate-*l*48.4%
Simplified48.4%
Final simplification48.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.5%
Applied egg-rr23.7%
Taylor expanded in U around inf 32.5%
(FPCore (J l K U) :precision binary64 -4.0)
double code(double J, double l, double K, double U) {
return -4.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 = -4.0d0
end function
public static double code(double J, double l, double K, double U) {
return -4.0;
}
def code(J, l, K, U): return -4.0
function code(J, l, K, U) return -4.0 end
function tmp = code(J, l, K, U) tmp = -4.0; end
code[J_, l_, K_, U_] := -4.0
\begin{array}{l}
\\
-4
\end{array}
Initial program 85.5%
Applied egg-rr23.7%
Taylor expanded in U around 0 2.8%
herbie shell --seed 2024150
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))