| Alternative 1 | |
|---|---|
| Error | 9.7 |
| Cost | 20616 |
(FPCore (J K U) :precision binary64 (* (* (* -2.0 J) (cos (/ K 2.0))) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) (cos (/ K 2.0)))) 2.0)))))
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= U -6.6e+249)
(- U)
(if (<= U 4.5e+171)
(* (* (* -2.0 J) t_0) (hypot 1.0 (/ U (* 2.0 (* J t_0)))))
(if (<= U 9.5e+276)
U
(- (/ -2.0 (/ (/ U J) (* J (pow (cos (* K 0.5)) 2.0)))) U))))))double code(double J, double K, double U) {
return ((-2.0 * J) * cos((K / 2.0))) * sqrt((1.0 + pow((U / ((2.0 * J) * cos((K / 2.0)))), 2.0)));
}
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (U <= -6.6e+249) {
tmp = -U;
} else if (U <= 4.5e+171) {
tmp = ((-2.0 * J) * t_0) * hypot(1.0, (U / (2.0 * (J * t_0))));
} else if (U <= 9.5e+276) {
tmp = U;
} else {
tmp = (-2.0 / ((U / J) / (J * pow(cos((K * 0.5)), 2.0)))) - U;
}
return tmp;
}
public static double code(double J, double K, double U) {
return ((-2.0 * J) * Math.cos((K / 2.0))) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * Math.cos((K / 2.0)))), 2.0)));
}
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (U <= -6.6e+249) {
tmp = -U;
} else if (U <= 4.5e+171) {
tmp = ((-2.0 * J) * t_0) * Math.hypot(1.0, (U / (2.0 * (J * t_0))));
} else if (U <= 9.5e+276) {
tmp = U;
} else {
tmp = (-2.0 / ((U / J) / (J * Math.pow(Math.cos((K * 0.5)), 2.0)))) - U;
}
return tmp;
}
def code(J, K, U): return ((-2.0 * J) * math.cos((K / 2.0))) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * math.cos((K / 2.0)))), 2.0)))
def code(J, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if U <= -6.6e+249: tmp = -U elif U <= 4.5e+171: tmp = ((-2.0 * J) * t_0) * math.hypot(1.0, (U / (2.0 * (J * t_0)))) elif U <= 9.5e+276: tmp = U else: tmp = (-2.0 / ((U / J) / (J * math.pow(math.cos((K * 0.5)), 2.0)))) - U return tmp
function code(J, K, U) return Float64(Float64(Float64(-2.0 * J) * cos(Float64(K / 2.0))) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * cos(Float64(K / 2.0)))) ^ 2.0)))) end
function code(J, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (U <= -6.6e+249) tmp = Float64(-U); elseif (U <= 4.5e+171) tmp = Float64(Float64(Float64(-2.0 * J) * t_0) * hypot(1.0, Float64(U / Float64(2.0 * Float64(J * t_0))))); elseif (U <= 9.5e+276) tmp = U; else tmp = Float64(Float64(-2.0 / Float64(Float64(U / J) / Float64(J * (cos(Float64(K * 0.5)) ^ 2.0)))) - U); end return tmp end
function tmp = code(J, K, U) tmp = ((-2.0 * J) * cos((K / 2.0))) * sqrt((1.0 + ((U / ((2.0 * J) * cos((K / 2.0)))) ^ 2.0))); end
function tmp_2 = code(J, K, U) t_0 = cos((K / 2.0)); tmp = 0.0; if (U <= -6.6e+249) tmp = -U; elseif (U <= 4.5e+171) tmp = ((-2.0 * J) * t_0) * hypot(1.0, (U / (2.0 * (J * t_0)))); elseif (U <= 9.5e+276) tmp = U; else tmp = (-2.0 / ((U / J) / (J * (cos((K * 0.5)) ^ 2.0)))) - U; end tmp_2 = tmp; end
code[J_, K_, U_] := N[(N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[U, -6.6e+249], (-U), If[LessEqual[U, 4.5e+171], N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[U, 9.5e+276], U, N[(N[(-2.0 / N[(N[(U / J), $MachinePrecision] / N[(J * N[Power[N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - U), $MachinePrecision]]]]]
\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;U \leq -6.6 \cdot 10^{+249}:\\
\;\;\;\;-U\\
\mathbf{elif}\;U \leq 4.5 \cdot 10^{+171}:\\
\;\;\;\;\left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot t_0\right)}\right)\\
\mathbf{elif}\;U \leq 9.5 \cdot 10^{+276}:\\
\;\;\;\;U\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{\frac{\frac{U}{J}}{J \cdot {\cos \left(K \cdot 0.5\right)}^{2}}} - U\\
\end{array}
Results
if U < -6.60000000000000027e249Initial program 45.6
Simplified27.1
[Start]45.6 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}
\] |
|---|---|
unpow2 [=>]45.6 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}}
\] |
hypot-1-def [=>]27.1 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\mathsf{hypot}\left(1, \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}
\] |
associate-*l* [=>]27.1 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)
\] |
Taylor expanded in J around 0 32.9
Simplified32.9
[Start]32.9 | \[ -1 \cdot U
\] |
|---|---|
mul-1-neg [=>]32.9 | \[ \color{blue}{-U}
\] |
if -6.60000000000000027e249 < U < 4.49999999999999969e171Initial program 13.8
Simplified4.8
[Start]13.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}
\] |
|---|---|
unpow2 [=>]13.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}}
\] |
hypot-1-def [=>]4.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\mathsf{hypot}\left(1, \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}
\] |
associate-*l* [=>]4.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)
\] |
if 4.49999999999999969e171 < U < 9.50000000000000013e276Initial program 40.8
Simplified23.8
[Start]40.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}
\] |
|---|---|
unpow2 [=>]40.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}}
\] |
hypot-1-def [=>]23.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\mathsf{hypot}\left(1, \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}
\] |
associate-*l* [=>]23.8 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)
\] |
Taylor expanded in U around -inf 35.8
if 9.50000000000000013e276 < U Initial program 48.1
Simplified31.6
[Start]48.1 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}
\] |
|---|---|
unpow2 [=>]48.1 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}}
\] |
hypot-1-def [=>]31.6 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\mathsf{hypot}\left(1, \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}
\] |
associate-*l* [=>]31.6 | \[ \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)
\] |
Taylor expanded in J around 0 40.4
Simplified34.5
[Start]40.4 | \[ -2 \cdot \frac{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}{U} + -1 \cdot U
\] |
|---|---|
mul-1-neg [=>]40.4 | \[ -2 \cdot \frac{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}{U} + \color{blue}{\left(-U\right)}
\] |
unsub-neg [=>]40.4 | \[ \color{blue}{-2 \cdot \frac{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}{U} - U}
\] |
associate-*r/ [=>]40.4 | \[ \color{blue}{\frac{-2 \cdot \left({\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}\right)}{U}} - U
\] |
associate-/l* [=>]40.4 | \[ \color{blue}{\frac{-2}{\frac{U}{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}}} - U
\] |
*-commutative [=>]40.4 | \[ \frac{-2}{\frac{U}{\color{blue}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}} - U
\] |
unpow2 [=>]40.4 | \[ \frac{-2}{\frac{U}{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}} - U
\] |
associate-*l* [=>]40.4 | \[ \frac{-2}{\frac{U}{\color{blue}{J \cdot \left(J \cdot {\cos \left(0.5 \cdot K\right)}^{2}\right)}}} - U
\] |
associate-/r* [=>]34.5 | \[ \frac{-2}{\color{blue}{\frac{\frac{U}{J}}{J \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}} - U
\] |
Final simplification9.6
| Alternative 1 | |
|---|---|
| Error | 9.7 |
| Cost | 20616 |
| Alternative 2 | |
|---|---|
| Error | 17.9 |
| Cost | 14224 |
| Alternative 3 | |
|---|---|
| Error | 22.8 |
| Cost | 7568 |
| Alternative 4 | |
|---|---|
| Error | 26.2 |
| Cost | 7376 |
| Alternative 5 | |
|---|---|
| Error | 46.6 |
| Cost | 788 |
| Alternative 6 | |
|---|---|
| Error | 39.8 |
| Cost | 788 |
| Alternative 7 | |
|---|---|
| Error | 46.7 |
| Cost | 64 |
herbie shell --seed 2023038
(FPCore (J K U)
:name "Maksimov and Kolovsky, Equation (3)"
:precision binary64
(* (* (* -2.0 J) (cos (/ K 2.0))) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) (cos (/ K 2.0)))) 2.0)))))