?

Average Error: 17.6 → 9.1
Time: 23.2s
Precision: binary64
Cost: 80776

?

\[\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(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t_0}\right)}^{2}}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;U\\ \mathbf{elif}\;t_1 \leq 10^{+297}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
(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
         (*
          (* (* -2.0 J) t_0)
          (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
   (if (<= t_1 (- INFINITY)) U (if (<= t_1 1e+297) t_1 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 t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = U;
	} else if (t_1 <= 1e+297) {
		tmp = t_1;
	} else {
		tmp = 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 t_1 = ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = U;
	} else if (t_1 <= 1e+297) {
		tmp = t_1;
	} else {
		tmp = 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))
	t_1 = ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = U
	elif t_1 <= 1e+297:
		tmp = t_1
	else:
		tmp = 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))
	t_1 = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = U;
	elseif (t_1 <= 1e+297)
		tmp = t_1;
	else
		tmp = 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));
	t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = U;
	elseif (t_1 <= 1e+297)
		tmp = t_1;
	else
		tmp = 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]}, Block[{t$95$1 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], U, If[LessEqual[t$95$1, 1e+297], t$95$1, U]]]]
\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(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t_0}\right)}^{2}}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;U\\

\mathbf{elif}\;t_1 \leq 10^{+297}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;U\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < -inf.0 or 1e297 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2))))

    1. Initial program 61.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}} \]
    2. Simplified61.9

      \[\leadsto \color{blue}{\cos \left(\frac{K}{2}\right) \cdot \left(\left(-2 \cdot J\right) \cdot \sqrt{1 + {\left(\frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)}^{2}}\right)} \]
      Proof

      [Start]61.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}} \]

      rational_best_45_simplify-91 [=>]61.9

      \[ \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]

      rational_best_45_simplify-100 [=>]61.9

      \[ \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \frac{-2 \cdot J}{-2 \cdot J}\right)\right)} \]

      rational_best_45_simplify-25 [=>]61.9

      \[ \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\cos \left(\frac{K}{2}\right) \cdot \left(\left(-2 \cdot J\right) \cdot \frac{-2 \cdot J}{-2 \cdot J}\right)\right)} \]

      rational_best_45_simplify-25 [=>]61.9

      \[ \color{blue}{\cos \left(\frac{K}{2}\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \frac{-2 \cdot J}{-2 \cdot J}\right)\right)} \]

      rational_best_45_simplify-91 [=>]61.9

      \[ \cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(\left(\left(-2 \cdot J\right) \cdot \frac{-2 \cdot J}{-2 \cdot J}\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Taylor expanded in U around -inf 31.8

      \[\leadsto \color{blue}{U} \]

    if -inf.0 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < 1e297

    1. Initial program 0.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}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification9.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\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}} \leq -\infty:\\ \;\;\;\;U\\ \mathbf{elif}\;\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}} \leq 10^{+297}:\\ \;\;\;\;\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}}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternatives

Alternative 1
Error16.4
Cost27408
\[\begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;U \leq -8.2 \cdot 10^{+273}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -6.4 \cdot 10^{+211}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -1.9 \cdot 10^{+185}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 4.4 \cdot 10^{+150}:\\ \;\;\;\;t_0 \cdot \left(\left(-2 \cdot J\right) \cdot \sqrt{1 + {\left(\frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 2
Error21.3
Cost21016
\[\begin{array}{l} t_0 := \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{2 \cdot J}\right)}^{2}}\\ \mathbf{if}\;U \leq -1.3 \cdot 10^{+269}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -7.2 \cdot 10^{+211}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -2.7 \cdot 10^{+185}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -7 \cdot 10^{+140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;U \leq -1.55 \cdot 10^{+107}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 5.7 \cdot 10^{+94}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 3
Error28.0
Cost20692
\[\begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot -2\right)\\ \mathbf{if}\;U \leq -4 \cdot 10^{+278}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -1.66 \cdot 10^{+139}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -4.8 \cdot 10^{+18}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 3.8 \cdot 10^{-48}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;U \leq 7.2 \cdot 10^{+46}:\\ \;\;\;\;2 \cdot \frac{{\cos \left(0.5 \cdot K\right)}^{2} \cdot {J}^{2}}{U} + U\\ \mathbf{elif}\;U \leq 7 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 4
Error28.0
Cost7640
\[\begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot -2\right)\\ \mathbf{if}\;U \leq -4.4 \cdot 10^{+278}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -6.4 \cdot 10^{+135}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -5.2 \cdot 10^{+18}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 3.8 \cdot 10^{-48}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;U \leq 1.45 \cdot 10^{+47}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 3.6 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;U \leq 5.3 \cdot 10^{+172}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 5
Error38.0
Cost720
\[\begin{array}{l} \mathbf{if}\;U \leq -2.1 \cdot 10^{+274}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -3.7 \cdot 10^{+138}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -4.6 \cdot 10^{+18}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 2.15 \cdot 10^{-48}:\\ \;\;\;\;J \cdot -2\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 6
Error46.5
Cost656
\[\begin{array}{l} \mathbf{if}\;U \leq -2 \cdot 10^{+271}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -7.8 \cdot 10^{+139}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -1.15 \cdot 10^{-68}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -9 \cdot 10^{-178}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 7
Error46.6
Cost64
\[U \]

Error

Reproduce?

herbie shell --seed 2023098 
(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)))))