
(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 11 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 -2e+14) (not (<= t_1 5e-16)))
(+ (* (* t_1 J) t_0) U)
(+ U (* t_0 (* J (* 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 <= -2e+14) || !(t_1 <= 5e-16)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * (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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((k / 2.0d0))
t_1 = exp(l) - exp(-l)
if ((t_1 <= (-2d+14)) .or. (.not. (t_1 <= 5d-16))) then
tmp = ((t_1 * j) * t_0) + u
else
tmp = u + (t_0 * (j * (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 t_1 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_1 <= -2e+14) || !(t_1 <= 5e-16)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * (J * (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 <= -2e+14) or not (t_1 <= 5e-16): tmp = ((t_1 * J) * t_0) + U else: tmp = U + (t_0 * (J * (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 <= -2e+14) || !(t_1 <= 5e-16)) tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U); else tmp = Float64(U + Float64(t_0 * Float64(J * 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 <= -2e+14) || ~((t_1 <= 5e-16))) tmp = ((t_1 * J) * t_0) + U; else tmp = U + (t_0 * (J * (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, -2e+14], N[Not[LessEqual[t$95$1, 5e-16]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $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 -2 \cdot 10^{+14} \lor \neg \left(t_1 \leq 5 \cdot 10^{-16}\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\
\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -2e14 or 5.0000000000000004e-16 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
if -2e14 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.0000000000000004e-16Initial program 73.2%
Taylor expanded in l around 0 100.0%
Final simplification100.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1
(+
U
(*
(* J (pow l 3.0))
(+ 0.3333333333333333 (* -0.041666666666666664 (* K K)))))))
(if (<= t_0 -0.915)
t_1
(if (<= t_0 -0.49)
(+ U (* l (* J (* 2.0 (cos (* K 0.5))))))
(if (<= t_0 -0.01) t_1 (+ U (* (sinh l) (* J 2.0))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = U + ((J * pow(l, 3.0)) * (0.3333333333333333 + (-0.041666666666666664 * (K * K))));
double tmp;
if (t_0 <= -0.915) {
tmp = t_1;
} else if (t_0 <= -0.49) {
tmp = U + (l * (J * (2.0 * cos((K * 0.5)))));
} else if (t_0 <= -0.01) {
tmp = t_1;
} else {
tmp = U + (sinh(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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((k / 2.0d0))
t_1 = u + ((j * (l ** 3.0d0)) * (0.3333333333333333d0 + ((-0.041666666666666664d0) * (k * k))))
if (t_0 <= (-0.915d0)) then
tmp = t_1
else if (t_0 <= (-0.49d0)) then
tmp = u + (l * (j * (2.0d0 * cos((k * 0.5d0)))))
else if (t_0 <= (-0.01d0)) then
tmp = t_1
else
tmp = u + (sinh(l) * (j * 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 t_1 = U + ((J * Math.pow(l, 3.0)) * (0.3333333333333333 + (-0.041666666666666664 * (K * K))));
double tmp;
if (t_0 <= -0.915) {
tmp = t_1;
} else if (t_0 <= -0.49) {
tmp = U + (l * (J * (2.0 * Math.cos((K * 0.5)))));
} else if (t_0 <= -0.01) {
tmp = t_1;
} else {
tmp = U + (Math.sinh(l) * (J * 2.0));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = U + ((J * math.pow(l, 3.0)) * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))) tmp = 0 if t_0 <= -0.915: tmp = t_1 elif t_0 <= -0.49: tmp = U + (l * (J * (2.0 * math.cos((K * 0.5))))) elif t_0 <= -0.01: tmp = t_1 else: tmp = U + (math.sinh(l) * (J * 2.0)) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(U + Float64(Float64(J * (l ^ 3.0)) * Float64(0.3333333333333333 + Float64(-0.041666666666666664 * Float64(K * K))))) tmp = 0.0 if (t_0 <= -0.915) tmp = t_1; elseif (t_0 <= -0.49) tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 * cos(Float64(K * 0.5)))))); elseif (t_0 <= -0.01) tmp = t_1; else tmp = Float64(U + Float64(sinh(l) * Float64(J * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = U + ((J * (l ^ 3.0)) * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))); tmp = 0.0; if (t_0 <= -0.915) tmp = t_1; elseif (t_0 <= -0.49) tmp = U + (l * (J * (2.0 * cos((K * 0.5))))); elseif (t_0 <= -0.01) tmp = t_1; else tmp = U + (sinh(l) * (J * 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[(U + N[(N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] * N[(0.3333333333333333 + N[(-0.041666666666666664 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.915], t$95$1, If[LessEqual[t$95$0, -0.49], N[(U + N[(l * N[(J * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.01], t$95$1, N[(U + N[(N[Sinh[l], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + \left(J \cdot {\ell}^{3}\right) \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)\\
\mathbf{if}\;t_0 \leq -0.915:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -0.49:\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{elif}\;t_0 \leq -0.01:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;U + \sinh \ell \cdot \left(J \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.91500000000000004 or -0.48999999999999999 < (cos.f64 (/.f64 K 2)) < -0.0100000000000000002Initial program 92.1%
Taylor expanded in l around 0 91.7%
Taylor expanded in l around inf 83.3%
associate-*r*83.3%
*-commutative83.3%
associate-*l*83.3%
Simplified83.3%
Taylor expanded in K around 0 12.4%
+-commutative12.4%
unpow212.4%
associate-*r*12.4%
distribute-rgt-out83.0%
Simplified83.0%
if -0.91500000000000004 < (cos.f64 (/.f64 K 2)) < -0.48999999999999999Initial program 86.9%
Taylor expanded in l around 0 95.6%
Taylor expanded in l around 0 82.2%
associate-*r*82.2%
*-commutative82.2%
*-commutative82.2%
associate-*l*82.2%
*-commutative82.2%
Simplified82.2%
if -0.0100000000000000002 < (cos.f64 (/.f64 K 2)) Initial program 86.5%
Taylor expanded in K around 0 86.5%
expm1-log1p-u64.4%
expm1-udef63.9%
sinh-undef66.5%
Applied egg-rr66.5%
expm1-def69.7%
expm1-log1p96.8%
*-commutative96.8%
associate-*l*96.8%
Simplified96.8%
Final simplification93.7%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))) (t_1 (+ U (* J (* -0.25 (* K (* l K)))))))
(if (<= t_0 -0.915)
t_1
(if (<= t_0 -0.65)
(+ U (* l (* J (* 2.0 (cos (* K 0.5))))))
(if (<= t_0 -0.01) t_1 (+ U (* (sinh l) (* J 2.0))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = U + (J * (-0.25 * (K * (l * K))));
double tmp;
if (t_0 <= -0.915) {
tmp = t_1;
} else if (t_0 <= -0.65) {
tmp = U + (l * (J * (2.0 * cos((K * 0.5)))));
} else if (t_0 <= -0.01) {
tmp = t_1;
} else {
tmp = U + (sinh(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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((k / 2.0d0))
t_1 = u + (j * ((-0.25d0) * (k * (l * k))))
if (t_0 <= (-0.915d0)) then
tmp = t_1
else if (t_0 <= (-0.65d0)) then
tmp = u + (l * (j * (2.0d0 * cos((k * 0.5d0)))))
else if (t_0 <= (-0.01d0)) then
tmp = t_1
else
tmp = u + (sinh(l) * (j * 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 t_1 = U + (J * (-0.25 * (K * (l * K))));
double tmp;
if (t_0 <= -0.915) {
tmp = t_1;
} else if (t_0 <= -0.65) {
tmp = U + (l * (J * (2.0 * Math.cos((K * 0.5)))));
} else if (t_0 <= -0.01) {
tmp = t_1;
} else {
tmp = U + (Math.sinh(l) * (J * 2.0));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = U + (J * (-0.25 * (K * (l * K)))) tmp = 0 if t_0 <= -0.915: tmp = t_1 elif t_0 <= -0.65: tmp = U + (l * (J * (2.0 * math.cos((K * 0.5))))) elif t_0 <= -0.01: tmp = t_1 else: tmp = U + (math.sinh(l) * (J * 2.0)) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(U + Float64(J * Float64(-0.25 * Float64(K * Float64(l * K))))) tmp = 0.0 if (t_0 <= -0.915) tmp = t_1; elseif (t_0 <= -0.65) tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 * cos(Float64(K * 0.5)))))); elseif (t_0 <= -0.01) tmp = t_1; else tmp = Float64(U + Float64(sinh(l) * Float64(J * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = U + (J * (-0.25 * (K * (l * K)))); tmp = 0.0; if (t_0 <= -0.915) tmp = t_1; elseif (t_0 <= -0.65) tmp = U + (l * (J * (2.0 * cos((K * 0.5))))); elseif (t_0 <= -0.01) tmp = t_1; else tmp = U + (sinh(l) * (J * 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[(U + N[(J * N[(-0.25 * N[(K * N[(l * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.915], t$95$1, If[LessEqual[t$95$0, -0.65], N[(U + N[(l * N[(J * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.01], t$95$1, N[(U + N[(N[Sinh[l], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + J \cdot \left(-0.25 \cdot \left(K \cdot \left(\ell \cdot K\right)\right)\right)\\
\mathbf{if}\;t_0 \leq -0.915:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -0.65:\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{elif}\;t_0 \leq -0.01:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;U + \sinh \ell \cdot \left(J \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.91500000000000004 or -0.650000000000000022 < (cos.f64 (/.f64 K 2)) < -0.0100000000000000002Initial program 92.9%
Taylor expanded in l around 0 39.9%
Taylor expanded in K around 0 54.0%
fma-def54.0%
associate-*r*59.0%
unpow259.0%
Simplified59.0%
Taylor expanded in K around inf 64.5%
unpow264.5%
associate-*r*64.5%
associate-*r*69.5%
associate-*r*69.5%
unpow269.5%
*-commutative69.5%
unpow269.5%
*-commutative69.5%
associate-*r*74.6%
Simplified74.6%
if -0.91500000000000004 < (cos.f64 (/.f64 K 2)) < -0.650000000000000022Initial program 84.0%
Taylor expanded in l around 0 94.6%
Taylor expanded in l around 0 89.0%
associate-*r*89.0%
*-commutative89.0%
*-commutative89.0%
associate-*l*89.0%
*-commutative89.0%
Simplified89.0%
if -0.0100000000000000002 < (cos.f64 (/.f64 K 2)) Initial program 86.5%
Taylor expanded in K around 0 86.5%
expm1-log1p-u64.4%
expm1-udef63.9%
sinh-undef66.5%
Applied egg-rr66.5%
expm1-def69.7%
expm1-log1p96.8%
*-commutative96.8%
associate-*l*96.8%
Simplified96.8%
Final simplification93.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= t_0 0.68)
(+ U (* t_0 (* J (+ (* l 2.0) (* 0.3333333333333333 (pow l 3.0))))))
(+ U (* (sinh l) (* J 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.68) {
tmp = U + (t_0 * (J * ((l * 2.0) + (0.3333333333333333 * pow(l, 3.0)))));
} else {
tmp = U + (sinh(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) :: t_0
real(8) :: tmp
t_0 = cos((k / 2.0d0))
if (t_0 <= 0.68d0) then
tmp = u + (t_0 * (j * ((l * 2.0d0) + (0.3333333333333333d0 * (l ** 3.0d0)))))
else
tmp = u + (sinh(l) * (j * 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.68) {
tmp = U + (t_0 * (J * ((l * 2.0) + (0.3333333333333333 * Math.pow(l, 3.0)))));
} else {
tmp = U + (Math.sinh(l) * (J * 2.0));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if t_0 <= 0.68: tmp = U + (t_0 * (J * ((l * 2.0) + (0.3333333333333333 * math.pow(l, 3.0))))) else: tmp = U + (math.sinh(l) * (J * 2.0)) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (t_0 <= 0.68) tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(l * 2.0) + Float64(0.3333333333333333 * (l ^ 3.0)))))); else tmp = Float64(U + Float64(sinh(l) * Float64(J * 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.68) tmp = U + (t_0 * (J * ((l * 2.0) + (0.3333333333333333 * (l ^ 3.0))))); else tmp = U + (sinh(l) * (J * 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.68], N[(U + N[(t$95$0 * N[(J * N[(N[(l * 2.0), $MachinePrecision] + N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Sinh[l], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq 0.68:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(\ell \cdot 2 + 0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + \sinh \ell \cdot \left(J \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < 0.680000000000000049Initial program 87.7%
Taylor expanded in l around 0 94.9%
if 0.680000000000000049 < (cos.f64 (/.f64 K 2)) Initial program 87.1%
Taylor expanded in K around 0 87.1%
expm1-log1p-u63.7%
expm1-udef63.1%
sinh-undef66.7%
Applied egg-rr66.7%
expm1-def70.3%
expm1-log1p99.3%
*-commutative99.3%
associate-*l*99.3%
Simplified99.3%
Final simplification97.7%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= t_0 0.03)
(+ U (* t_0 (* (pow l 3.0) (* J 0.3333333333333333))))
(+ U (* (sinh l) (* J 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.03) {
tmp = U + (t_0 * (pow(l, 3.0) * (J * 0.3333333333333333)));
} else {
tmp = U + (sinh(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) :: t_0
real(8) :: tmp
t_0 = cos((k / 2.0d0))
if (t_0 <= 0.03d0) then
tmp = u + (t_0 * ((l ** 3.0d0) * (j * 0.3333333333333333d0)))
else
tmp = u + (sinh(l) * (j * 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.03) {
tmp = U + (t_0 * (Math.pow(l, 3.0) * (J * 0.3333333333333333)));
} else {
tmp = U + (Math.sinh(l) * (J * 2.0));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if t_0 <= 0.03: tmp = U + (t_0 * (math.pow(l, 3.0) * (J * 0.3333333333333333))) else: tmp = U + (math.sinh(l) * (J * 2.0)) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (t_0 <= 0.03) tmp = Float64(U + Float64(t_0 * Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)))); else tmp = Float64(U + Float64(sinh(l) * Float64(J * 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.03) tmp = U + (t_0 * ((l ^ 3.0) * (J * 0.3333333333333333))); else tmp = U + (sinh(l) * (J * 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.03], N[(U + N[(t$95$0 * N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Sinh[l], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq 0.03:\\
\;\;\;\;U + t_0 \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + \sinh \ell \cdot \left(J \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < 0.029999999999999999Initial program 90.2%
Taylor expanded in l around 0 93.4%
Taylor expanded in l around inf 83.4%
associate-*r*83.4%
*-commutative83.4%
associate-*l*83.4%
Simplified83.4%
if 0.029999999999999999 < (cos.f64 (/.f64 K 2)) Initial program 86.5%
Taylor expanded in K around 0 86.5%
expm1-log1p-u64.1%
expm1-udef63.6%
sinh-undef66.2%
Applied egg-rr66.2%
expm1-def69.5%
expm1-log1p96.9%
*-commutative96.9%
associate-*l*96.9%
Simplified96.9%
Final simplification93.9%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.01) (+ U (* J (* -0.25 (* K (* l K))))) (+ U (* (sinh l) (* J 2.0)))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.01) {
tmp = U + (J * (-0.25 * (K * (l * K))));
} else {
tmp = U + (sinh(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 (cos((k / 2.0d0)) <= (-0.01d0)) then
tmp = u + (j * ((-0.25d0) * (k * (l * k))))
else
tmp = u + (sinh(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 (Math.cos((K / 2.0)) <= -0.01) {
tmp = U + (J * (-0.25 * (K * (l * K))));
} else {
tmp = U + (Math.sinh(l) * (J * 2.0));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= -0.01: tmp = U + (J * (-0.25 * (K * (l * K)))) else: tmp = U + (math.sinh(l) * (J * 2.0)) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.01) tmp = Float64(U + Float64(J * Float64(-0.25 * Float64(K * Float64(l * K))))); else tmp = Float64(U + Float64(sinh(l) * Float64(J * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= -0.01) tmp = U + (J * (-0.25 * (K * (l * K)))); else tmp = U + (sinh(l) * (J * 2.0)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(U + N[(J * N[(-0.25 * N[(K * N[(l * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Sinh[l], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;U + J \cdot \left(-0.25 \cdot \left(K \cdot \left(\ell \cdot K\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + \sinh \ell \cdot \left(J \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.0100000000000000002Initial program 90.1%
Taylor expanded in l around 0 55.7%
Taylor expanded in K around 0 47.4%
fma-def47.4%
associate-*r*50.9%
unpow250.9%
Simplified50.9%
Taylor expanded in K around inf 58.2%
unpow258.2%
associate-*r*58.2%
associate-*r*61.6%
associate-*r*61.6%
unpow261.6%
*-commutative61.6%
unpow261.6%
*-commutative61.6%
associate-*r*67.0%
Simplified67.0%
if -0.0100000000000000002 < (cos.f64 (/.f64 K 2)) Initial program 86.5%
Taylor expanded in K around 0 86.5%
expm1-log1p-u64.4%
expm1-udef63.9%
sinh-undef66.5%
Applied egg-rr66.5%
expm1-def69.7%
expm1-log1p96.8%
*-commutative96.8%
associate-*l*96.8%
Simplified96.8%
Final simplification90.3%
(FPCore (J l K U) :precision binary64 (if (or (<= l -5.9e+31) (not (<= l 1.08e+51))) (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25)))) (+ U (* J (* l 2.0)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -5.9e+31) || !(l <= 1.08e+51)) {
tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
} 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 <= (-5.9d+31)) .or. (.not. (l <= 1.08d+51))) then
tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
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 <= -5.9e+31) || !(l <= 1.08e+51)) {
tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
} else {
tmp = U + (J * (l * 2.0));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -5.9e+31) or not (l <= 1.08e+51): tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25))) else: tmp = U + (J * (l * 2.0)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -5.9e+31) || !(l <= 1.08e+51)) tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25)))); 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 <= -5.9e+31) || ~((l <= 1.08e+51))) tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25))); else tmp = U + (J * (l * 2.0)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -5.9e+31], N[Not[LessEqual[l, 1.08e+51]], $MachinePrecision]], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $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 -5.9 \cdot 10^{+31} \lor \neg \left(\ell \leq 1.08 \cdot 10^{+51}\right):\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\
\end{array}
\end{array}
if l < -5.9000000000000004e31 or 1.08e51 < l Initial program 100.0%
Taylor expanded in l around 0 27.5%
Taylor expanded in K around 0 19.4%
+-commutative19.4%
associate-*r*19.4%
distribute-rgt-out36.6%
*-commutative36.6%
unpow236.6%
Simplified36.6%
if -5.9000000000000004e31 < l < 1.08e51Initial program 76.8%
Taylor expanded in l around 0 90.7%
Taylor expanded in K around 0 60.3%
fma-def60.3%
associate-*r*60.5%
unpow260.5%
Simplified60.5%
Taylor expanded in K around 0 81.9%
associate-*r*81.9%
*-commutative81.9%
Simplified81.9%
Final simplification61.4%
(FPCore (J l K U) :precision binary64 (if (or (<= J 1.7e-176) (not (<= J 2e+58))) (+ U (* J (* l 2.0))) (+ U (* J (* -0.25 (* K (* l K)))))))
double code(double J, double l, double K, double U) {
double tmp;
if ((J <= 1.7e-176) || !(J <= 2e+58)) {
tmp = U + (J * (l * 2.0));
} else {
tmp = U + (J * (-0.25 * (K * (l * K))));
}
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 ((j <= 1.7d-176) .or. (.not. (j <= 2d+58))) then
tmp = u + (j * (l * 2.0d0))
else
tmp = u + (j * ((-0.25d0) * (k * (l * k))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((J <= 1.7e-176) || !(J <= 2e+58)) {
tmp = U + (J * (l * 2.0));
} else {
tmp = U + (J * (-0.25 * (K * (l * K))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (J <= 1.7e-176) or not (J <= 2e+58): tmp = U + (J * (l * 2.0)) else: tmp = U + (J * (-0.25 * (K * (l * K)))) return tmp
function code(J, l, K, U) tmp = 0.0 if ((J <= 1.7e-176) || !(J <= 2e+58)) tmp = Float64(U + Float64(J * Float64(l * 2.0))); else tmp = Float64(U + Float64(J * Float64(-0.25 * Float64(K * Float64(l * K))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((J <= 1.7e-176) || ~((J <= 2e+58))) tmp = U + (J * (l * 2.0)); else tmp = U + (J * (-0.25 * (K * (l * K)))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[J, 1.7e-176], N[Not[LessEqual[J, 2e+58]], $MachinePrecision]], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(-0.25 * N[(K * N[(l * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;J \leq 1.7 \cdot 10^{-176} \lor \neg \left(J \leq 2 \cdot 10^{+58}\right):\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(-0.25 \cdot \left(K \cdot \left(\ell \cdot K\right)\right)\right)\\
\end{array}
\end{array}
if J < 1.6999999999999999e-176 or 1.99999999999999989e58 < J Initial program 85.8%
Taylor expanded in l around 0 67.6%
Taylor expanded in K around 0 39.4%
fma-def39.4%
associate-*r*46.2%
unpow246.2%
Simplified46.2%
Taylor expanded in K around 0 58.9%
associate-*r*58.9%
*-commutative58.9%
Simplified58.9%
if 1.6999999999999999e-176 < J < 1.99999999999999989e58Initial program 94.0%
Taylor expanded in l around 0 38.3%
Taylor expanded in K around 0 52.1%
fma-def52.1%
associate-*r*54.0%
unpow254.0%
Simplified54.0%
Taylor expanded in K around inf 49.0%
unpow249.0%
associate-*r*49.0%
associate-*r*50.8%
associate-*r*50.8%
unpow250.8%
*-commutative50.8%
unpow250.8%
*-commutative50.8%
associate-*r*50.8%
Simplified50.8%
Final simplification57.4%
(FPCore (J l K U) :precision binary64 (if (or (<= l -32.0) (not (<= l 1.2e-16))) (+ U (* J (* K K))) U))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -32.0) || !(l <= 1.2e-16)) {
tmp = U + (J * (K * K));
} else {
tmp = 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 ((l <= (-32.0d0)) .or. (.not. (l <= 1.2d-16))) then
tmp = u + (j * (k * k))
else
tmp = u
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -32.0) || !(l <= 1.2e-16)) {
tmp = U + (J * (K * K));
} else {
tmp = U;
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -32.0) or not (l <= 1.2e-16): tmp = U + (J * (K * K)) else: tmp = U return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -32.0) || !(l <= 1.2e-16)) tmp = Float64(U + Float64(J * Float64(K * K))); else tmp = U; end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -32.0) || ~((l <= 1.2e-16))) tmp = U + (J * (K * K)); else tmp = U; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -32.0], N[Not[LessEqual[l, 1.2e-16]], $MachinePrecision]], N[(U + N[(J * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -32 \lor \neg \left(\ell \leq 1.2 \cdot 10^{-16}\right):\\
\;\;\;\;U + J \cdot \left(K \cdot K\right)\\
\mathbf{else}:\\
\;\;\;\;U\\
\end{array}
\end{array}
if l < -32 or 1.20000000000000002e-16 < l Initial program 99.4%
Applied egg-rr5.0%
Taylor expanded in K around 0 16.1%
distribute-rgt-out16.1%
unpow216.1%
Simplified16.1%
Taylor expanded in K around inf 16.1%
*-commutative16.1%
unpow216.1%
Simplified16.1%
if -32 < l < 1.20000000000000002e-16Initial program 73.6%
Applied egg-rr53.3%
Taylor expanded in J around 0 73.4%
Final simplification43.0%
(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 87.3%
Taylor expanded in l around 0 62.1%
Taylor expanded in K around 0 41.8%
fma-def41.8%
associate-*r*47.6%
unpow247.6%
Simplified47.6%
Taylor expanded in K around 0 54.2%
associate-*r*54.2%
*-commutative54.2%
Simplified54.2%
Final simplification54.2%
(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 87.3%
Applied egg-rr27.8%
Taylor expanded in J around 0 37.0%
Final simplification37.0%
herbie shell --seed 2023187
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))