
(FPCore (J K U) :precision binary64 (let* ((t_0 (cos (/ K 2.0)))) (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
real(8) function code(j, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
t_0 = cos((k / 2.0d0))
code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K / 2.0));
return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U): t_0 = math.cos((K / 2.0)) return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U) t_0 = cos(Float64(K / 2.0)) return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0)))) end
function tmp = code(J, K, U) t_0 = cos((K / 2.0)); tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0))); end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, 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]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\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}}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (J K U) :precision binary64 (let* ((t_0 (cos (/ K 2.0)))) (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
real(8) function code(j, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
t_0 = cos((k / 2.0d0))
code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K / 2.0));
return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U): t_0 = math.cos((K / 2.0)) return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U) t_0 = cos(Float64(K / 2.0)) return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0)))) end
function tmp = code(J, K, U) t_0 = cos((K / 2.0)); tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0))); end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, 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]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\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}}
\end{array}
\end{array}
NOTE: U should be positive before calling this function
(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 (* t_0 (* J 2.0))) 2.0))))))
(if (<= t_1 (- INFINITY))
(- U)
(if (<= t_1 5e+306)
(* (* -2.0 J) (* t_0 (hypot 1.0 (/ (/ U (* J 2.0)) t_0))))
U))))U = abs(U);
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 / (t_0 * (J * 2.0))), 2.0)));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = -U;
} else if (t_1 <= 5e+306) {
tmp = (-2.0 * J) * (t_0 * hypot(1.0, ((U / (J * 2.0)) / t_0)));
} else {
tmp = U;
}
return tmp;
}
U = Math.abs(U);
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 / (t_0 * (J * 2.0))), 2.0)));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = -U;
} else if (t_1 <= 5e+306) {
tmp = (-2.0 * J) * (t_0 * Math.hypot(1.0, ((U / (J * 2.0)) / t_0)));
} else {
tmp = U;
}
return tmp;
}
U = abs(U) 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 / (t_0 * (J * 2.0))), 2.0))) tmp = 0 if t_1 <= -math.inf: tmp = -U elif t_1 <= 5e+306: tmp = (-2.0 * J) * (t_0 * math.hypot(1.0, ((U / (J * 2.0)) / t_0))) else: tmp = U return tmp
U = abs(U) 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(t_0 * Float64(J * 2.0))) ^ 2.0)))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(-U); elseif (t_1 <= 5e+306) tmp = Float64(Float64(-2.0 * J) * Float64(t_0 * hypot(1.0, Float64(Float64(U / Float64(J * 2.0)) / t_0)))); else tmp = U; end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) t_0 = cos((K / 2.0)); t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / (t_0 * (J * 2.0))) ^ 2.0))); tmp = 0.0; if (t_1 <= -Inf) tmp = -U; elseif (t_1 <= 5e+306) tmp = (-2.0 * J) * (t_0 * hypot(1.0, ((U / (J * 2.0)) / t_0))); else tmp = U; end tmp_2 = tmp; end
NOTE: U should be positive before calling this function
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[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U), If[LessEqual[t$95$1, 5e+306], N[(N[(-2.0 * J), $MachinePrecision] * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], U]]]]
\begin{array}{l}
U = |U|\\
\\
\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}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+306}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{t_0}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U\\
\end{array}
\end{array}
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.0Initial program 6.0%
Simplified53.1%
Taylor expanded in J around 0 52.7%
mul-1-neg52.7%
Simplified52.7%
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)))) < 4.99999999999999993e306Initial program 99.8%
Simplified99.8%
if 4.99999999999999993e306 < (*.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)))) Initial program 5.1%
Simplified60.0%
Taylor expanded in U around -inf 54.8%
Final simplification86.3%
NOTE: U should be positive before calling this function
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (* K 0.5)))
(t_1 (* t_0 (* (* -2.0 J) (hypot 1.0 (* (/ U J) (/ 0.5 t_0)))))))
(if (<= J -6.8e-205)
t_1
(if (<= J -2.4e-306) U (if (<= J 3e-179) (- U) t_1)))))U = abs(U);
double code(double J, double K, double U) {
double t_0 = cos((K * 0.5));
double t_1 = t_0 * ((-2.0 * J) * hypot(1.0, ((U / J) * (0.5 / t_0))));
double tmp;
if (J <= -6.8e-205) {
tmp = t_1;
} else if (J <= -2.4e-306) {
tmp = U;
} else if (J <= 3e-179) {
tmp = -U;
} else {
tmp = t_1;
}
return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K * 0.5));
double t_1 = t_0 * ((-2.0 * J) * Math.hypot(1.0, ((U / J) * (0.5 / t_0))));
double tmp;
if (J <= -6.8e-205) {
tmp = t_1;
} else if (J <= -2.4e-306) {
tmp = U;
} else if (J <= 3e-179) {
tmp = -U;
} else {
tmp = t_1;
}
return tmp;
}
U = abs(U) def code(J, K, U): t_0 = math.cos((K * 0.5)) t_1 = t_0 * ((-2.0 * J) * math.hypot(1.0, ((U / J) * (0.5 / t_0)))) tmp = 0 if J <= -6.8e-205: tmp = t_1 elif J <= -2.4e-306: tmp = U elif J <= 3e-179: tmp = -U else: tmp = t_1 return tmp
U = abs(U) function code(J, K, U) t_0 = cos(Float64(K * 0.5)) t_1 = Float64(t_0 * Float64(Float64(-2.0 * J) * hypot(1.0, Float64(Float64(U / J) * Float64(0.5 / t_0))))) tmp = 0.0 if (J <= -6.8e-205) tmp = t_1; elseif (J <= -2.4e-306) tmp = U; elseif (J <= 3e-179) tmp = Float64(-U); else tmp = t_1; end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) t_0 = cos((K * 0.5)); t_1 = t_0 * ((-2.0 * J) * hypot(1.0, ((U / J) * (0.5 / t_0)))); tmp = 0.0; if (J <= -6.8e-205) tmp = t_1; elseif (J <= -2.4e-306) tmp = U; elseif (J <= 3e-179) tmp = -U; else tmp = t_1; end tmp_2 = tmp; end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U / J), $MachinePrecision] * N[(0.5 / t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -6.8e-205], t$95$1, If[LessEqual[J, -2.4e-306], U, If[LessEqual[J, 3e-179], (-U), t$95$1]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := t_0 \cdot \left(\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J} \cdot \frac{0.5}{t_0}\right)\right)\\
\mathbf{if}\;J \leq -6.8 \cdot 10^{-205}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;J \leq -2.4 \cdot 10^{-306}:\\
\;\;\;\;U\\
\mathbf{elif}\;J \leq 3 \cdot 10^{-179}:\\
\;\;\;\;-U\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if J < -6.8000000000000004e-205 or 3.00000000000000006e-179 < J Initial program 84.1%
Simplified96.3%
associate-*r*96.2%
associate-*r*96.2%
associate-/l/96.2%
associate-/r*96.3%
expm1-log1p-u58.6%
expm1-udef38.8%
Applied egg-rr38.8%
expm1-def58.5%
expm1-log1p96.2%
*-commutative96.2%
*-commutative96.2%
Simplified96.2%
if -6.8000000000000004e-205 < J < -2.3999999999999999e-306Initial program 25.4%
Simplified52.2%
Taylor expanded in U around -inf 39.9%
if -2.3999999999999999e-306 < J < 3.00000000000000006e-179Initial program 17.8%
Simplified43.6%
Taylor expanded in J around 0 34.7%
mul-1-neg34.7%
Simplified34.7%
Final simplification85.0%
NOTE: U should be positive before calling this function
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= J -2.5e-135)
(* (* -2.0 J) (* t_0 (hypot 1.0 (* U (/ 0.5 J)))))
(if (<= J -4e-310)
U
(if (<= J 3.8e-91)
(fma -2.0 (/ (pow (* J (cos (* K 0.5))) 2.0) U) (- U))
(* (* -2.0 (* J t_0)) (hypot 1.0 (/ (/ U 2.0) J))))))))U = abs(U);
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (J <= -2.5e-135) {
tmp = (-2.0 * J) * (t_0 * hypot(1.0, (U * (0.5 / J))));
} else if (J <= -4e-310) {
tmp = U;
} else if (J <= 3.8e-91) {
tmp = fma(-2.0, (pow((J * cos((K * 0.5))), 2.0) / U), -U);
} else {
tmp = (-2.0 * (J * t_0)) * hypot(1.0, ((U / 2.0) / J));
}
return tmp;
}
U = abs(U) function code(J, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (J <= -2.5e-135) tmp = Float64(Float64(-2.0 * J) * Float64(t_0 * hypot(1.0, Float64(U * Float64(0.5 / J))))); elseif (J <= -4e-310) tmp = U; elseif (J <= 3.8e-91) tmp = fma(-2.0, Float64((Float64(J * cos(Float64(K * 0.5))) ^ 2.0) / U), Float64(-U)); else tmp = Float64(Float64(-2.0 * Float64(J * t_0)) * hypot(1.0, Float64(Float64(U / 2.0) / J))); end return tmp end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[J, -2.5e-135], N[(N[(-2.0 * J), $MachinePrecision] * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -4e-310], U, If[LessEqual[J, 3.8e-91], N[(-2.0 * N[(N[Power[N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / U), $MachinePrecision] + (-U)), $MachinePrecision], N[(N[(-2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq -2.5 \cdot 10^{-135}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\
\;\;\;\;U\\
\mathbf{elif}\;J \leq 3.8 \cdot 10^{-91}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}{U}, -U\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \left(J \cdot t_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\
\end{array}
\end{array}
if J < -2.5000000000000001e-135Initial program 91.7%
Simplified99.8%
Taylor expanded in K around 0 85.8%
associate-*r/85.8%
*-commutative85.8%
associate-*r/85.8%
Simplified85.8%
if -2.5000000000000001e-135 < J < -3.999999999999988e-310Initial program 36.5%
Simplified65.7%
Taylor expanded in U around -inf 43.6%
if -3.999999999999988e-310 < J < 3.79999999999999978e-91Initial program 38.0%
Simplified58.4%
Taylor expanded in J around 0 36.3%
mul-1-neg36.3%
fma-def36.3%
unpow236.3%
*-commutative36.3%
unpow236.3%
swap-sqr36.3%
unpow236.3%
*-commutative36.3%
Simplified36.3%
if 3.79999999999999978e-91 < J Initial program 87.5%
associate-*l*87.5%
associate-/r*87.4%
cos-neg87.4%
distribute-frac-neg87.4%
associate-/r*87.5%
unpow287.5%
hypot-1-def99.8%
associate-/r*99.7%
associate-/r*99.7%
distribute-frac-neg99.7%
Simplified99.8%
Taylor expanded in K around 0 85.4%
Final simplification70.1%
NOTE: U should be positive before calling this function
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= t_0 0.55)
(* (* -2.0 J) (* t_0 (+ 1.0 (* (* (/ U J) (/ U J)) 0.125))))
(* (* -2.0 J) (hypot 1.0 (/ (/ U 2.0) J))))))U = abs(U);
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (t_0 <= 0.55) {
tmp = (-2.0 * J) * (t_0 * (1.0 + (((U / J) * (U / J)) * 0.125)));
} else {
tmp = (-2.0 * J) * hypot(1.0, ((U / 2.0) / J));
}
return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (t_0 <= 0.55) {
tmp = (-2.0 * J) * (t_0 * (1.0 + (((U / J) * (U / J)) * 0.125)));
} else {
tmp = (-2.0 * J) * Math.hypot(1.0, ((U / 2.0) / J));
}
return tmp;
}
U = abs(U) def code(J, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if t_0 <= 0.55: tmp = (-2.0 * J) * (t_0 * (1.0 + (((U / J) * (U / J)) * 0.125))) else: tmp = (-2.0 * J) * math.hypot(1.0, ((U / 2.0) / J)) return tmp
U = abs(U) function code(J, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (t_0 <= 0.55) tmp = Float64(Float64(-2.0 * J) * Float64(t_0 * Float64(1.0 + Float64(Float64(Float64(U / J) * Float64(U / J)) * 0.125)))); else tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(Float64(U / 2.0) / J))); end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) t_0 = cos((K / 2.0)); tmp = 0.0; if (t_0 <= 0.55) tmp = (-2.0 * J) * (t_0 * (1.0 + (((U / J) * (U / J)) * 0.125))); else tmp = (-2.0 * J) * hypot(1.0, ((U / 2.0) / J)); end tmp_2 = tmp; end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.55], N[(N[(-2.0 * J), $MachinePrecision] * N[(t$95$0 * N[(1.0 + N[(N[(N[(U / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq 0.55:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \left(1 + \left(\frac{U}{J} \cdot \frac{U}{J}\right) \cdot 0.125\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < 0.55000000000000004Initial program 75.8%
Simplified90.7%
Taylor expanded in K around 0 62.9%
associate-*r/62.9%
*-commutative62.9%
associate-*r/62.9%
Simplified62.9%
Taylor expanded in U around 0 50.3%
*-commutative50.3%
Simplified50.3%
unpow250.3%
unpow250.3%
times-frac58.1%
Applied egg-rr58.1%
if 0.55000000000000004 < (cos.f64 (/.f64 K 2)) Initial program 70.1%
associate-*l*70.1%
associate-/r*70.1%
cos-neg70.1%
distribute-frac-neg70.1%
associate-/r*70.1%
unpow270.1%
hypot-1-def84.8%
associate-/r*84.8%
associate-/r*84.8%
distribute-frac-neg84.8%
Simplified84.8%
Taylor expanded in K around 0 76.2%
Taylor expanded in K around 0 75.0%
Final simplification68.8%
NOTE: U should be positive before calling this function
(FPCore (J K U)
:precision binary64
(let* ((t_0 (* (* -2.0 J) (* (cos (/ K 2.0)) (hypot 1.0 (* U (/ 0.5 J)))))))
(if (<= J -6.2e-135)
t_0
(if (<= J -4e-310) U (if (<= J 8e-175) (- U) t_0)))))U = abs(U);
double code(double J, double K, double U) {
double t_0 = (-2.0 * J) * (cos((K / 2.0)) * hypot(1.0, (U * (0.5 / J))));
double tmp;
if (J <= -6.2e-135) {
tmp = t_0;
} else if (J <= -4e-310) {
tmp = U;
} else if (J <= 8e-175) {
tmp = -U;
} else {
tmp = t_0;
}
return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
double t_0 = (-2.0 * J) * (Math.cos((K / 2.0)) * Math.hypot(1.0, (U * (0.5 / J))));
double tmp;
if (J <= -6.2e-135) {
tmp = t_0;
} else if (J <= -4e-310) {
tmp = U;
} else if (J <= 8e-175) {
tmp = -U;
} else {
tmp = t_0;
}
return tmp;
}
U = abs(U) def code(J, K, U): t_0 = (-2.0 * J) * (math.cos((K / 2.0)) * math.hypot(1.0, (U * (0.5 / J)))) tmp = 0 if J <= -6.2e-135: tmp = t_0 elif J <= -4e-310: tmp = U elif J <= 8e-175: tmp = -U else: tmp = t_0 return tmp
U = abs(U) function code(J, K, U) t_0 = Float64(Float64(-2.0 * J) * Float64(cos(Float64(K / 2.0)) * hypot(1.0, Float64(U * Float64(0.5 / J))))) tmp = 0.0 if (J <= -6.2e-135) tmp = t_0; elseif (J <= -4e-310) tmp = U; elseif (J <= 8e-175) tmp = Float64(-U); else tmp = t_0; end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) t_0 = (-2.0 * J) * (cos((K / 2.0)) * hypot(1.0, (U * (0.5 / J)))); tmp = 0.0; if (J <= -6.2e-135) tmp = t_0; elseif (J <= -4e-310) tmp = U; elseif (J <= 8e-175) tmp = -U; else tmp = t_0; end tmp_2 = tmp; end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(-2.0 * J), $MachinePrecision] * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -6.2e-135], t$95$0, If[LessEqual[J, -4e-310], U, If[LessEqual[J, 8e-175], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{if}\;J \leq -6.2 \cdot 10^{-135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\
\;\;\;\;U\\
\mathbf{elif}\;J \leq 8 \cdot 10^{-175}:\\
\;\;\;\;-U\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if J < -6.2000000000000001e-135 or 8e-175 < J Initial program 86.7%
Simplified97.4%
Taylor expanded in K around 0 81.5%
associate-*r/81.5%
*-commutative81.5%
associate-*r/81.4%
Simplified81.4%
if -6.2000000000000001e-135 < J < -3.999999999999988e-310Initial program 36.5%
Simplified65.7%
Taylor expanded in U around -inf 43.6%
if -3.999999999999988e-310 < J < 8e-175Initial program 17.8%
Simplified43.6%
Taylor expanded in J around 0 34.7%
mul-1-neg34.7%
Simplified34.7%
Final simplification71.1%
NOTE: U should be positive before calling this function
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= J -2.9e-135)
(* (* -2.0 J) (* t_0 (hypot 1.0 (* U (/ 0.5 J)))))
(if (<= J 4.3e-308)
U
(if (<= J 3.4e-174)
(- U)
(* (* -2.0 (* J t_0)) (hypot 1.0 (/ (/ U 2.0) J))))))))U = abs(U);
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (J <= -2.9e-135) {
tmp = (-2.0 * J) * (t_0 * hypot(1.0, (U * (0.5 / J))));
} else if (J <= 4.3e-308) {
tmp = U;
} else if (J <= 3.4e-174) {
tmp = -U;
} else {
tmp = (-2.0 * (J * t_0)) * hypot(1.0, ((U / 2.0) / J));
}
return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (J <= -2.9e-135) {
tmp = (-2.0 * J) * (t_0 * Math.hypot(1.0, (U * (0.5 / J))));
} else if (J <= 4.3e-308) {
tmp = U;
} else if (J <= 3.4e-174) {
tmp = -U;
} else {
tmp = (-2.0 * (J * t_0)) * Math.hypot(1.0, ((U / 2.0) / J));
}
return tmp;
}
U = abs(U) def code(J, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if J <= -2.9e-135: tmp = (-2.0 * J) * (t_0 * math.hypot(1.0, (U * (0.5 / J)))) elif J <= 4.3e-308: tmp = U elif J <= 3.4e-174: tmp = -U else: tmp = (-2.0 * (J * t_0)) * math.hypot(1.0, ((U / 2.0) / J)) return tmp
U = abs(U) function code(J, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (J <= -2.9e-135) tmp = Float64(Float64(-2.0 * J) * Float64(t_0 * hypot(1.0, Float64(U * Float64(0.5 / J))))); elseif (J <= 4.3e-308) tmp = U; elseif (J <= 3.4e-174) tmp = Float64(-U); else tmp = Float64(Float64(-2.0 * Float64(J * t_0)) * hypot(1.0, Float64(Float64(U / 2.0) / J))); end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) t_0 = cos((K / 2.0)); tmp = 0.0; if (J <= -2.9e-135) tmp = (-2.0 * J) * (t_0 * hypot(1.0, (U * (0.5 / J)))); elseif (J <= 4.3e-308) tmp = U; elseif (J <= 3.4e-174) tmp = -U; else tmp = (-2.0 * (J * t_0)) * hypot(1.0, ((U / 2.0) / J)); end tmp_2 = tmp; end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[J, -2.9e-135], N[(N[(-2.0 * J), $MachinePrecision] * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 4.3e-308], U, If[LessEqual[J, 3.4e-174], (-U), N[(N[(-2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq -2.9 \cdot 10^{-135}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{elif}\;J \leq 4.3 \cdot 10^{-308}:\\
\;\;\;\;U\\
\mathbf{elif}\;J \leq 3.4 \cdot 10^{-174}:\\
\;\;\;\;-U\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \left(J \cdot t_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\
\end{array}
\end{array}
if J < -2.9000000000000002e-135Initial program 91.7%
Simplified99.8%
Taylor expanded in K around 0 85.8%
associate-*r/85.8%
*-commutative85.8%
associate-*r/85.8%
Simplified85.8%
if -2.9000000000000002e-135 < J < 4.3000000000000002e-308Initial program 36.5%
Simplified65.7%
Taylor expanded in U around -inf 43.6%
if 4.3000000000000002e-308 < J < 3.4000000000000002e-174Initial program 17.8%
Simplified43.6%
Taylor expanded in J around 0 34.7%
mul-1-neg34.7%
Simplified34.7%
if 3.4000000000000002e-174 < J Initial program 83.2%
associate-*l*83.2%
associate-/r*83.2%
cos-neg83.2%
distribute-frac-neg83.2%
associate-/r*83.2%
unpow283.2%
hypot-1-def95.7%
associate-/r*95.6%
associate-/r*95.6%
distribute-frac-neg95.6%
Simplified95.7%
Taylor expanded in K around 0 78.4%
Final simplification71.1%
NOTE: U should be positive before calling this function
(FPCore (J K U)
:precision binary64
(let* ((t_0 (* (* -2.0 J) (cos (* K 0.5)))))
(if (<= J -7.5e-135)
t_0
(if (<= J -4e-310)
U
(if (or (<= J 8.6e-68) (and (not (<= J 4.1e-10)) (<= J 9e+26)))
(- U)
t_0)))))U = abs(U);
double code(double J, double K, double U) {
double t_0 = (-2.0 * J) * cos((K * 0.5));
double tmp;
if (J <= -7.5e-135) {
tmp = t_0;
} else if (J <= -4e-310) {
tmp = U;
} else if ((J <= 8.6e-68) || (!(J <= 4.1e-10) && (J <= 9e+26))) {
tmp = -U;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: tmp
t_0 = ((-2.0d0) * j) * cos((k * 0.5d0))
if (j <= (-7.5d-135)) then
tmp = t_0
else if (j <= (-4d-310)) then
tmp = u
else if ((j <= 8.6d-68) .or. (.not. (j <= 4.1d-10)) .and. (j <= 9d+26)) then
tmp = -u
else
tmp = t_0
end if
code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
double t_0 = (-2.0 * J) * Math.cos((K * 0.5));
double tmp;
if (J <= -7.5e-135) {
tmp = t_0;
} else if (J <= -4e-310) {
tmp = U;
} else if ((J <= 8.6e-68) || (!(J <= 4.1e-10) && (J <= 9e+26))) {
tmp = -U;
} else {
tmp = t_0;
}
return tmp;
}
U = abs(U) def code(J, K, U): t_0 = (-2.0 * J) * math.cos((K * 0.5)) tmp = 0 if J <= -7.5e-135: tmp = t_0 elif J <= -4e-310: tmp = U elif (J <= 8.6e-68) or (not (J <= 4.1e-10) and (J <= 9e+26)): tmp = -U else: tmp = t_0 return tmp
U = abs(U) function code(J, K, U) t_0 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))) tmp = 0.0 if (J <= -7.5e-135) tmp = t_0; elseif (J <= -4e-310) tmp = U; elseif ((J <= 8.6e-68) || (!(J <= 4.1e-10) && (J <= 9e+26))) tmp = Float64(-U); else tmp = t_0; end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) t_0 = (-2.0 * J) * cos((K * 0.5)); tmp = 0.0; if (J <= -7.5e-135) tmp = t_0; elseif (J <= -4e-310) tmp = U; elseif ((J <= 8.6e-68) || (~((J <= 4.1e-10)) && (J <= 9e+26))) tmp = -U; else tmp = t_0; end tmp_2 = tmp; end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -7.5e-135], t$95$0, If[LessEqual[J, -4e-310], U, If[Or[LessEqual[J, 8.6e-68], And[N[Not[LessEqual[J, 4.1e-10]], $MachinePrecision], LessEqual[J, 9e+26]]], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;J \leq -7.5 \cdot 10^{-135}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\
\;\;\;\;U\\
\mathbf{elif}\;J \leq 8.6 \cdot 10^{-68} \lor \neg \left(J \leq 4.1 \cdot 10^{-10}\right) \land J \leq 9 \cdot 10^{+26}:\\
\;\;\;\;-U\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if J < -7.5e-135 or 8.6000000000000002e-68 < J < 4.0999999999999998e-10 or 8.99999999999999957e26 < J Initial program 91.3%
Simplified99.8%
Taylor expanded in U around 0 73.2%
if -7.5e-135 < J < -3.999999999999988e-310Initial program 36.5%
Simplified65.7%
Taylor expanded in U around -inf 43.6%
if -3.999999999999988e-310 < J < 8.6000000000000002e-68 or 4.0999999999999998e-10 < J < 8.99999999999999957e26Initial program 46.5%
Simplified68.6%
Taylor expanded in J around 0 39.3%
mul-1-neg39.3%
Simplified39.3%
Final simplification60.3%
NOTE: U should be positive before calling this function (FPCore (J K U) :precision binary64 (if (<= (/ K 2.0) 5e-5) (* (* -2.0 J) (hypot 1.0 (/ (/ U 2.0) J))) (* (* -2.0 J) (cos (* K 0.5)))))
U = abs(U);
double code(double J, double K, double U) {
double tmp;
if ((K / 2.0) <= 5e-5) {
tmp = (-2.0 * J) * hypot(1.0, ((U / 2.0) / J));
} else {
tmp = (-2.0 * J) * cos((K * 0.5));
}
return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
double tmp;
if ((K / 2.0) <= 5e-5) {
tmp = (-2.0 * J) * Math.hypot(1.0, ((U / 2.0) / J));
} else {
tmp = (-2.0 * J) * Math.cos((K * 0.5));
}
return tmp;
}
U = abs(U) def code(J, K, U): tmp = 0 if (K / 2.0) <= 5e-5: tmp = (-2.0 * J) * math.hypot(1.0, ((U / 2.0) / J)) else: tmp = (-2.0 * J) * math.cos((K * 0.5)) return tmp
U = abs(U) function code(J, K, U) tmp = 0.0 if (Float64(K / 2.0) <= 5e-5) tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(Float64(U / 2.0) / J))); else tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))); end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) tmp = 0.0; if ((K / 2.0) <= 5e-5) tmp = (-2.0 * J) * hypot(1.0, ((U / 2.0) / J)); else tmp = (-2.0 * J) * cos((K * 0.5)); end tmp_2 = tmp; end
NOTE: U should be positive before calling this function code[J_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 5e-5], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\end{array}
\end{array}
if (/.f64 K 2) < 5.00000000000000024e-5Initial program 72.5%
associate-*l*72.5%
associate-/r*72.4%
cos-neg72.4%
distribute-frac-neg72.4%
associate-/r*72.5%
unpow272.5%
hypot-1-def87.2%
associate-/r*87.1%
associate-/r*87.1%
distribute-frac-neg87.1%
Simplified87.2%
Taylor expanded in K around 0 76.0%
Taylor expanded in K around 0 61.6%
if 5.00000000000000024e-5 < (/.f64 K 2) Initial program 71.2%
Simplified86.3%
Taylor expanded in U around 0 50.8%
Final simplification58.9%
NOTE: U should be positive before calling this function (FPCore (J K U) :precision binary64 (if (<= J 5e-310) U (- U)))
U = abs(U);
double code(double J, double K, double U) {
double tmp;
if (J <= 5e-310) {
tmp = U;
} else {
tmp = -U;
}
return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if (j <= 5d-310) then
tmp = u
else
tmp = -u
end if
code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
double tmp;
if (J <= 5e-310) {
tmp = U;
} else {
tmp = -U;
}
return tmp;
}
U = abs(U) def code(J, K, U): tmp = 0 if J <= 5e-310: tmp = U else: tmp = -U return tmp
U = abs(U) function code(J, K, U) tmp = 0.0 if (J <= 5e-310) tmp = U; else tmp = Float64(-U); end return tmp end
U = abs(U) function tmp_2 = code(J, K, U) tmp = 0.0; if (J <= 5e-310) tmp = U; else tmp = -U; end tmp_2 = tmp; end
NOTE: U should be positive before calling this function code[J_, K_, U_] := If[LessEqual[J, 5e-310], U, (-U)]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq 5 \cdot 10^{-310}:\\
\;\;\;\;U\\
\mathbf{else}:\\
\;\;\;\;-U\\
\end{array}
\end{array}
if J < 4.999999999999985e-310Initial program 75.6%
Simplified89.8%
Taylor expanded in U around -inf 20.0%
if 4.999999999999985e-310 < J Initial program 69.5%
Simplified84.8%
Taylor expanded in J around 0 27.6%
mul-1-neg27.6%
Simplified27.6%
Final simplification24.2%
NOTE: U should be positive before calling this function (FPCore (J K U) :precision binary64 U)
U = abs(U);
double code(double J, double K, double U) {
return U;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
return U;
}
U = abs(U) def code(J, K, U): return U
U = abs(U) function code(J, K, U) return U end
U = abs(U) function tmp = code(J, K, U) tmp = U; end
NOTE: U should be positive before calling this function code[J_, K_, U_] := U
\begin{array}{l}
U = |U|\\
\\
U
\end{array}
Initial program 72.2%
Simplified87.0%
Taylor expanded in U around -inf 24.5%
Final simplification24.5%
herbie shell --seed 2023301
(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)))))