| Alternative 1 | |
|---|---|
| Error | 10.4 |
| Cost | 20882 |
(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)))
(t_1 (* (* (* J -2.0) t_0) (hypot 1.0 (/ U (* 2.0 (* J t_0))))))
(t_2 (cos (* K 0.5)))
(t_3 (- (/ -2.0 (/ (/ U J) (* J (pow t_2 2.0)))) U)))
(if (<= J -5e-134)
t_1
(if (<= J -7e-245)
t_3
(if (<= J -6e-275)
(* -2.0 (* t_0 (* J (hypot 1.0 (* U (/ (/ 0.5 J) t_2))))))
(if (<= J 1.1e-237) t_3 t_1))))))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 t_1 = ((J * -2.0) * t_0) * hypot(1.0, (U / (2.0 * (J * t_0))));
double t_2 = cos((K * 0.5));
double t_3 = (-2.0 / ((U / J) / (J * pow(t_2, 2.0)))) - U;
double tmp;
if (J <= -5e-134) {
tmp = t_1;
} else if (J <= -7e-245) {
tmp = t_3;
} else if (J <= -6e-275) {
tmp = -2.0 * (t_0 * (J * hypot(1.0, (U * ((0.5 / J) / t_2)))));
} else if (J <= 1.1e-237) {
tmp = t_3;
} else {
tmp = t_1;
}
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 t_1 = ((J * -2.0) * t_0) * Math.hypot(1.0, (U / (2.0 * (J * t_0))));
double t_2 = Math.cos((K * 0.5));
double t_3 = (-2.0 / ((U / J) / (J * Math.pow(t_2, 2.0)))) - U;
double tmp;
if (J <= -5e-134) {
tmp = t_1;
} else if (J <= -7e-245) {
tmp = t_3;
} else if (J <= -6e-275) {
tmp = -2.0 * (t_0 * (J * Math.hypot(1.0, (U * ((0.5 / J) / t_2)))));
} else if (J <= 1.1e-237) {
tmp = t_3;
} else {
tmp = t_1;
}
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)) t_1 = ((J * -2.0) * t_0) * math.hypot(1.0, (U / (2.0 * (J * t_0)))) t_2 = math.cos((K * 0.5)) t_3 = (-2.0 / ((U / J) / (J * math.pow(t_2, 2.0)))) - U tmp = 0 if J <= -5e-134: tmp = t_1 elif J <= -7e-245: tmp = t_3 elif J <= -6e-275: tmp = -2.0 * (t_0 * (J * math.hypot(1.0, (U * ((0.5 / J) / t_2))))) elif J <= 1.1e-237: tmp = t_3 else: tmp = t_1 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)) t_1 = Float64(Float64(Float64(J * -2.0) * t_0) * hypot(1.0, Float64(U / Float64(2.0 * Float64(J * t_0))))) t_2 = cos(Float64(K * 0.5)) t_3 = Float64(Float64(-2.0 / Float64(Float64(U / J) / Float64(J * (t_2 ^ 2.0)))) - U) tmp = 0.0 if (J <= -5e-134) tmp = t_1; elseif (J <= -7e-245) tmp = t_3; elseif (J <= -6e-275) tmp = Float64(-2.0 * Float64(t_0 * Float64(J * hypot(1.0, Float64(U * Float64(Float64(0.5 / J) / t_2)))))); elseif (J <= 1.1e-237) tmp = t_3; else tmp = t_1; 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)); t_1 = ((J * -2.0) * t_0) * hypot(1.0, (U / (2.0 * (J * t_0)))); t_2 = cos((K * 0.5)); t_3 = (-2.0 / ((U / J) / (J * (t_2 ^ 2.0)))) - U; tmp = 0.0; if (J <= -5e-134) tmp = t_1; elseif (J <= -7e-245) tmp = t_3; elseif (J <= -6e-275) tmp = -2.0 * (t_0 * (J * hypot(1.0, (U * ((0.5 / J) / t_2))))); elseif (J <= 1.1e-237) tmp = t_3; else tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(N[(J * -2.0), $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]}, Block[{t$95$2 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(-2.0 / N[(N[(U / J), $MachinePrecision] / N[(J * N[Power[t$95$2, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - U), $MachinePrecision]}, If[LessEqual[J, -5e-134], t$95$1, If[LessEqual[J, -7e-245], t$95$3, If[LessEqual[J, -6e-275], N[(-2.0 * N[(t$95$0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(U * N[(N[(0.5 / J), $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.1e-237], t$95$3, t$95$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}}
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(\left(J \cdot -2\right) \cdot t_0\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot t_0\right)}\right)\\
t_2 := \cos \left(K \cdot 0.5\right)\\
t_3 := \frac{-2}{\frac{\frac{U}{J}}{J \cdot {t_2}^{2}}} - U\\
\mathbf{if}\;J \leq -5 \cdot 10^{-134}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;J \leq -7 \cdot 10^{-245}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;J \leq -6 \cdot 10^{-275}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, U \cdot \frac{\frac{0.5}{J}}{t_2}\right)\right)\right)\\
\mathbf{elif}\;J \leq 1.1 \cdot 10^{-237}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
if J < -5.0000000000000003e-134 or 1.09999999999999999e-237 < J Initial program 12.9
Simplified4.3
[Start]12.9 | \[ \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 [=>]12.9 | \[ \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.3 | \[ \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.3 | \[ \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 -5.0000000000000003e-134 < J < -7.00000000000000033e-245 or -6.000000000000001e-275 < J < 1.09999999999999999e-237Initial program 41.1
Simplified23.8
[Start]41.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 [=>]41.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 [=>]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 J around 0 35.2
Simplified35.2
[Start]35.2 | \[ -2 \cdot \frac{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}{U} + -1 \cdot U
\] |
|---|---|
mul-1-neg [=>]35.2 | \[ -2 \cdot \frac{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}{U} + \color{blue}{\left(-U\right)}
\] |
unsub-neg [=>]35.2 | \[ \color{blue}{-2 \cdot \frac{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}{U} - U}
\] |
associate-*r/ [=>]35.2 | \[ \color{blue}{\frac{-2 \cdot \left({\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}\right)}{U}} - U
\] |
associate-/l* [=>]35.2 | \[ \color{blue}{\frac{-2}{\frac{U}{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}}} - U
\] |
*-commutative [=>]35.2 | \[ \frac{-2}{\frac{U}{\color{blue}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}} - U
\] |
unpow2 [=>]35.2 | \[ \frac{-2}{\frac{U}{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}} - U
\] |
associate-*l* [=>]35.2 | \[ \frac{-2}{\frac{U}{\color{blue}{J \cdot \left(J \cdot {\cos \left(0.5 \cdot K\right)}^{2}\right)}}} - U
\] |
associate-/r* [=>]35.2 | \[ \frac{-2}{\color{blue}{\frac{\frac{U}{J}}{J \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}} - U
\] |
if -7.00000000000000033e-245 < J < -6.000000000000001e-275Initial program 38.7
Simplified25.5
[Start]38.7 | \[ \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}}
\] |
|---|---|
associate-*l* [=>]38.7 | \[ \color{blue}{\left(-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\right)} \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}
\] |
associate-*l* [=>]38.7 | \[ \color{blue}{-2 \cdot \left(\left(J \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}}\right)}
\] |
*-commutative [=>]38.7 | \[ -2 \cdot \left(\color{blue}{\left(\cos \left(\frac{K}{2}\right) \cdot J\right)} \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)
\] |
associate-*l* [=>]38.7 | \[ -2 \cdot \color{blue}{\left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)\right)}
\] |
unpow2 [=>]38.7 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \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)}}}\right)\right)
\] |
hypot-1-def [=>]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \color{blue}{\mathsf{hypot}\left(1, \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}\right)\right)
\] |
associate-*l* [=>]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)\right)\right)
\] |
Taylor expanded in U around 0 25.5
Simplified25.5
[Start]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{\cos \left(0.5 \cdot K\right) \cdot J}\right)\right)\right)
\] |
|---|---|
associate-*r/ [=>]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{0.5 \cdot U}{\cos \left(0.5 \cdot K\right) \cdot J}}\right)\right)\right)
\] |
*-commutative [=>]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{0.5 \cdot U}{\color{blue}{J \cdot \cos \left(0.5 \cdot K\right)}}\right)\right)\right)
\] |
*-commutative [<=]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{0.5 \cdot U}{J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}}\right)\right)\right)
\] |
associate-*l/ [<=]25.6 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{0.5}{J \cdot \cos \left(K \cdot 0.5\right)} \cdot U}\right)\right)\right)
\] |
*-commutative [=>]25.6 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J \cdot \cos \left(K \cdot 0.5\right)}}\right)\right)\right)
\] |
associate-/r* [=>]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, U \cdot \color{blue}{\frac{\frac{0.5}{J}}{\cos \left(K \cdot 0.5\right)}}\right)\right)\right)
\] |
*-commutative [=>]25.5 | \[ -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, U \cdot \frac{\frac{0.5}{J}}{\cos \color{blue}{\left(0.5 \cdot K\right)}}\right)\right)\right)
\] |
Final simplification10.3
| Alternative 1 | |
|---|---|
| Error | 10.4 |
| Cost | 20882 |
| Alternative 2 | |
|---|---|
| Error | 10.4 |
| Cost | 20880 |
| Alternative 3 | |
|---|---|
| Error | 17.2 |
| Cost | 13960 |
| Alternative 4 | |
|---|---|
| Error | 17.2 |
| Cost | 13960 |
| Alternative 5 | |
|---|---|
| Error | 26.3 |
| Cost | 7376 |
| Alternative 6 | |
|---|---|
| Error | 24.0 |
| Cost | 7304 |
| Alternative 7 | |
|---|---|
| Error | 37.9 |
| Cost | 720 |
| Alternative 8 | |
|---|---|
| Error | 46.4 |
| Cost | 656 |
| Alternative 9 | |
|---|---|
| Error | 46.9 |
| Cost | 64 |
herbie shell --seed 2023056
(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)))))