?

Average Error: 18.4 → 8.9
Time: 17.8s
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 5 \cdot 10^{+307}:\\ \;\;\;\;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 5e+307) 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 <= 5e+307) {
		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 <= 5e+307) {
		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 <= 5e+307:
		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 <= 5e+307)
		tmp = t_1;
	else
		tmp = Float64(-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 <= 5e+307)
		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, 5e+307], 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 5 \cdot 10^{+307}:\\
\;\;\;\;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 3 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

    1. Initial program 64.0

      \[\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. Taylor expanded in U around -inf 31.9

      \[\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)))) < 5e307

    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}} \]

    if 5e307 < (*.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 63.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}} \]
    2. Taylor expanded in J around 0 29.4

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Simplified29.4

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

      [Start]29.4

      \[ -1 \cdot U \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]29.4

      \[ \color{blue}{U \cdot -1} \]

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]29.4

      \[ \color{blue}{-U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.9

    \[\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 5 \cdot 10^{+307}:\\ \;\;\;\;\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
Error22.1
Cost20620
\[\begin{array}{l} \mathbf{if}\;U \leq -6.6 \cdot 10^{+259}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -1.9 \cdot 10^{+77}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 4.4 \cdot 10^{+133}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 2
Error26.5
Cost7244
\[\begin{array}{l} \mathbf{if}\;U \leq -4.8 \cdot 10^{+259}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -6.2 \cdot 10^{+75}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 4 \cdot 10^{+57}:\\ \;\;\;\;\cos \left(0.5 \cdot K\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
Alternative 3
Error46.5
Cost920
\[\begin{array}{l} \mathbf{if}\;K \leq -9.5 \cdot 10^{+87}:\\ \;\;\;\;-U\\ \mathbf{elif}\;K \leq -5.7 \cdot 10^{-50}:\\ \;\;\;\;U\\ \mathbf{elif}\;K \leq -4.2 \cdot 10^{-129}:\\ \;\;\;\;-U\\ \mathbf{elif}\;K \leq -1.7 \cdot 10^{-276}:\\ \;\;\;\;U\\ \mathbf{elif}\;K \leq 1.12 \cdot 10^{+46}:\\ \;\;\;\;-U\\ \mathbf{elif}\;K \leq 4 \cdot 10^{+161}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
Alternative 4
Error38.3
Cost788
\[\begin{array}{l} \mathbf{if}\;U \leq -2.4 \cdot 10^{+259}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -5.2 \cdot 10^{+75}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 1.15 \cdot 10^{+52}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;U \leq 3.6 \cdot 10^{+150}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq 1.25 \cdot 10^{+198}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
Alternative 5
Error47.3
Cost64
\[U \]

Error

Reproduce?

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