Average Error: 18.4 → 8.3
Time: 19.2s
Precision: binary64
Cost: 20352
\[\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)\\ \left(t_0 \cdot \left(-2 \cdot J\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot t_0\right)}\right) \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_0 (* -2.0 J)) (hypot 1.0 (/ U (* 2.0 (* J t_0)))))))
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));
	return (t_0 * (-2.0 * J)) * hypot(1.0, (U / (2.0 * (J * t_0))));
}
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));
	return (t_0 * (-2.0 * J)) * Math.hypot(1.0, (U / (2.0 * (J * t_0))));
}
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))
	return (t_0 * (-2.0 * J)) * math.hypot(1.0, (U / (2.0 * (J * t_0))))
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))
	return Float64(Float64(t_0 * Float64(-2.0 * J)) * hypot(1.0, Float64(U / Float64(2.0 * Float64(J * t_0)))))
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 = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = (t_0 * (-2.0 * J)) * hypot(1.0, (U / (2.0 * (J * t_0))));
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]}, N[(N[(t$95$0 * N[(-2.0 * J), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $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)\\
\left(t_0 \cdot \left(-2 \cdot J\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot t_0\right)}\right)
\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 18.4

    \[\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. Simplified8.3

    \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}\right)} \]
    Proof
    (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (hypot.f64 1 (/.f64 U (*.f64 2 (*.f64 J (cos.f64 (/.f64 K 2))))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (hypot.f64 1 (/.f64 U (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2))))))): 0 points increase in error, 4 points decrease in error
    (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (Rewrite<= hypot-1-def_binary64 (sqrt.f64 (+.f64 1 (*.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2))))))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (Rewrite<= unpow2_binary64 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2))))): 0 points increase in error, 0 points decrease in error
  3. Final simplification8.3

    \[\leadsto \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \]

Alternatives

Alternative 1
Error8.4
Cost20352
\[-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{\frac{U}{\cos \left(K \cdot 0.5\right)}}{J}\right)\right)\right) \]
Alternative 2
Error27.0
Cost14952
\[\begin{array}{l} t_0 := J \cdot \frac{J}{U}\\ t_1 := \sqrt{\mathsf{fma}\left(0.25, \frac{U}{J} \cdot \frac{U}{J}, 1\right)} \cdot \left(-2 \cdot J\right)\\ \mathbf{if}\;U \leq -5.1 \cdot 10^{+278}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -9.2 \cdot 10^{+228}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -2.6 \cdot 10^{+205}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -5 \cdot 10^{+165}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;U \leq -3.9 \cdot 10^{+149}:\\ \;\;\;\;\mathsf{fma}\left(2, t_0, U\right)\\ \mathbf{elif}\;U \leq -1.5 \cdot 10^{+71}:\\ \;\;\;\;t_0 \cdot \left(-1 - \cos K\right) - U\\ \mathbf{elif}\;U \leq -9.8 \cdot 10^{-54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;U \leq 2.7 \cdot 10^{+69}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{elif}\;U \leq 5.6 \cdot 10^{+129}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 7.5 \cdot 10^{+178}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 3
Error17.1
Cost14092
\[\begin{array}{l} t_0 := \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \mathbf{if}\;J \leq -1.45 \cdot 10^{-238}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 2.6 \cdot 10^{-296}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.85 \cdot 10^{-202}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error26.3
Cost7896
\[\begin{array}{l} t_0 := J \cdot \frac{J}{U}\\ \mathbf{if}\;U \leq -5.2 \cdot 10^{+278}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -6.5 \cdot 10^{+229}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -6.4 \cdot 10^{+125}:\\ \;\;\;\;\mathsf{fma}\left(2, t_0, U\right)\\ \mathbf{elif}\;U \leq 3.6 \cdot 10^{+70}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{elif}\;U \leq 9.2 \cdot 10^{+89}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 2.56 \cdot 10^{+188}:\\ \;\;\;\;t_0 \cdot \left(-1 - \cos K\right) - U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 5
Error26.2
Cost7376
\[\begin{array}{l} \mathbf{if}\;U \leq -1.02 \cdot 10^{+278}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -3.2 \cdot 10^{+230}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -6.5 \cdot 10^{+123}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 1.15 \cdot 10^{+70}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{elif}\;U \leq 1.5 \cdot 10^{+90}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 1.75 \cdot 10^{+189}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 6
Error26.2
Cost7376
\[\begin{array}{l} \mathbf{if}\;U \leq -7.5 \cdot 10^{+277}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -5 \cdot 10^{+230}:\\ \;\;\;\;-U\\ \mathbf{elif}\;U \leq -3.3 \cdot 10^{+122}:\\ \;\;\;\;\mathsf{fma}\left(2, J \cdot \frac{J}{U}, U\right)\\ \mathbf{elif}\;U \leq 2.6 \cdot 10^{+70}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{elif}\;U \leq 2.3 \cdot 10^{+91}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 4.3 \cdot 10^{+188}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 7
Error38.6
Cost1116
\[\begin{array}{l} \mathbf{if}\;J \leq -2.75 \cdot 10^{+113}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2.1 \cdot 10^{+43}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -2.1 \cdot 10^{-57}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.45 \cdot 10^{-238}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.4 \cdot 10^{-296}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.2 \cdot 10^{-187}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 4 \cdot 10^{-13}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]
Alternative 8
Error46.6
Cost1052
\[\begin{array}{l} \mathbf{if}\;J \leq -4.8 \cdot 10^{-76}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -2.35 \cdot 10^{-110}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -1.46 \cdot 10^{-238}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.25 \cdot 10^{-296}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.4 \cdot 10^{-190}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 9.5 \cdot 10^{-8}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.25 \cdot 10^{+58}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 9
Error46.8
Cost64
\[U \]

Error

Reproduce

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