
(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 8 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}
U_m = (fabs.f64 U)
(FPCore (J K U_m)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1
(*
(* (* -2.0 J) t_0)
(sqrt (+ 1.0 (pow (/ U_m (* t_0 (* J 2.0))) 2.0))))))
(if (<= t_1 (- INFINITY))
(- U_m)
(if (<= t_1 1e+302)
(*
J
(* (* -2.0 t_0) (hypot 1.0 (/ (/ U_m (* -2.0 J)) (cos (* K 0.5))))))
U_m))))U_m = fabs(U);
double code(double J, double K, double U_m) {
double t_0 = cos((K / 2.0));
double t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U_m / (t_0 * (J * 2.0))), 2.0)));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = -U_m;
} else if (t_1 <= 1e+302) {
tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / (-2.0 * J)) / cos((K * 0.5)))));
} else {
tmp = U_m;
}
return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
double t_0 = Math.cos((K / 2.0));
double t_1 = ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U_m / (t_0 * (J * 2.0))), 2.0)));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = -U_m;
} else if (t_1 <= 1e+302) {
tmp = J * ((-2.0 * t_0) * Math.hypot(1.0, ((U_m / (-2.0 * J)) / Math.cos((K * 0.5)))));
} else {
tmp = U_m;
}
return tmp;
}
U_m = math.fabs(U) def code(J, K, U_m): t_0 = math.cos((K / 2.0)) t_1 = ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U_m / (t_0 * (J * 2.0))), 2.0))) tmp = 0 if t_1 <= -math.inf: tmp = -U_m elif t_1 <= 1e+302: tmp = J * ((-2.0 * t_0) * math.hypot(1.0, ((U_m / (-2.0 * J)) / math.cos((K * 0.5))))) else: tmp = U_m return tmp
U_m = abs(U) function code(J, K, U_m) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U_m / Float64(t_0 * Float64(J * 2.0))) ^ 2.0)))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(-U_m); elseif (t_1 <= 1e+302) tmp = Float64(J * Float64(Float64(-2.0 * t_0) * hypot(1.0, Float64(Float64(U_m / Float64(-2.0 * J)) / cos(Float64(K * 0.5)))))); else tmp = U_m; end return tmp end
U_m = abs(U); function tmp_2 = code(J, K, U_m) t_0 = cos((K / 2.0)); t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U_m / (t_0 * (J * 2.0))) ^ 2.0))); tmp = 0.0; if (t_1 <= -Inf) tmp = -U_m; elseif (t_1 <= 1e+302) tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / (-2.0 * J)) / cos((K * 0.5))))); else tmp = U_m; end tmp_2 = tmp; end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := 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$95$m / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U$95$m), If[LessEqual[t$95$1, 1e+302], N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / N[(-2.0 * J), $MachinePrecision]), $MachinePrecision] / N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], U$95$m]]]]
\begin{array}{l}
U_m = \left|U\right|
\\
\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\_m}{t\_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;-U\_m\\
\mathbf{elif}\;t\_1 \leq 10^{+302}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{-2 \cdot J}}{\cos \left(K \cdot 0.5\right)}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U\_m\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < -inf.0Initial program 5.8%
Simplified63.6%
Taylor expanded in J around 0 50.4%
neg-mul-150.4%
Simplified50.4%
if -inf.0 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < 1.0000000000000001e302Initial program 99.8%
Simplified99.7%
associate-/r*99.7%
associate-*l*99.7%
add-cube-cbrt99.2%
associate-/l*99.2%
pow299.2%
*-commutative99.2%
*-commutative99.2%
add-sqr-sqrt50.4%
div-inv50.4%
metadata-eval50.4%
sqrt-unprod85.9%
swap-sqr85.9%
metadata-eval85.9%
metadata-eval85.9%
swap-sqr85.9%
*-commutative85.9%
*-commutative85.9%
sqrt-unprod48.8%
add-sqr-sqrt99.2%
*-commutative99.2%
Applied egg-rr99.2%
associate-/r*99.2%
associate-*r/99.2%
associate-*l/99.2%
associate-*r/99.2%
associate-*l/99.2%
unpow299.2%
rem-3cbrt-lft99.8%
*-commutative99.8%
*-commutative99.8%
Simplified99.8%
if 1.0000000000000001e302 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) Initial program 4.7%
Simplified61.8%
Taylor expanded in U around -inf 51.5%
Final simplification84.4%
U_m = (fabs.f64 U)
(FPCore (J K U_m)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1 (* J (* (* -2.0 t_0) (+ 1.0 (* (* (/ U_m J) (/ U_m J)) 0.125))))))
(if (<= t_0 -0.55)
t_1
(if (<= t_0 -0.25)
U_m
(if (<= t_0 0.5)
t_1
(if (<= t_0 0.786)
(- U_m)
(if (<= t_0 0.998)
t_1
(* J (* -2.0 (hypot 1.0 (* U_m (/ -0.5 J))))))))))))U_m = fabs(U);
double code(double J, double K, double U_m) {
double t_0 = cos((K / 2.0));
double t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
double tmp;
if (t_0 <= -0.55) {
tmp = t_1;
} else if (t_0 <= -0.25) {
tmp = U_m;
} else if (t_0 <= 0.5) {
tmp = t_1;
} else if (t_0 <= 0.786) {
tmp = -U_m;
} else if (t_0 <= 0.998) {
tmp = t_1;
} else {
tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J))));
}
return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
double t_0 = Math.cos((K / 2.0));
double t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
double tmp;
if (t_0 <= -0.55) {
tmp = t_1;
} else if (t_0 <= -0.25) {
tmp = U_m;
} else if (t_0 <= 0.5) {
tmp = t_1;
} else if (t_0 <= 0.786) {
tmp = -U_m;
} else if (t_0 <= 0.998) {
tmp = t_1;
} else {
tmp = J * (-2.0 * Math.hypot(1.0, (U_m * (-0.5 / J))));
}
return tmp;
}
U_m = math.fabs(U) def code(J, K, U_m): t_0 = math.cos((K / 2.0)) t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125))) tmp = 0 if t_0 <= -0.55: tmp = t_1 elif t_0 <= -0.25: tmp = U_m elif t_0 <= 0.5: tmp = t_1 elif t_0 <= 0.786: tmp = -U_m elif t_0 <= 0.998: tmp = t_1 else: tmp = J * (-2.0 * math.hypot(1.0, (U_m * (-0.5 / J)))) return tmp
U_m = abs(U) function code(J, K, U_m) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(J * Float64(Float64(-2.0 * t_0) * Float64(1.0 + Float64(Float64(Float64(U_m / J) * Float64(U_m / J)) * 0.125)))) tmp = 0.0 if (t_0 <= -0.55) tmp = t_1; elseif (t_0 <= -0.25) tmp = U_m; elseif (t_0 <= 0.5) tmp = t_1; elseif (t_0 <= 0.786) tmp = Float64(-U_m); elseif (t_0 <= 0.998) tmp = t_1; else tmp = Float64(J * Float64(-2.0 * hypot(1.0, Float64(U_m * Float64(-0.5 / J))))); end return tmp end
U_m = abs(U); function tmp_2 = code(J, K, U_m) t_0 = cos((K / 2.0)); t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125))); tmp = 0.0; if (t_0 <= -0.55) tmp = t_1; elseif (t_0 <= -0.25) tmp = U_m; elseif (t_0 <= 0.5) tmp = t_1; elseif (t_0 <= 0.786) tmp = -U_m; elseif (t_0 <= 0.998) tmp = t_1; else tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J)))); end tmp_2 = tmp; end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[(1.0 + N[(N[(N[(U$95$m / J), $MachinePrecision] * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.55], t$95$1, If[LessEqual[t$95$0, -0.25], U$95$m, If[LessEqual[t$95$0, 0.5], t$95$1, If[LessEqual[t$95$0, 0.786], (-U$95$m), If[LessEqual[t$95$0, 0.998], t$95$1, N[(J * N[(-2.0 * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(-0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
U_m = \left|U\right|
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \left(1 + \left(\frac{U\_m}{J} \cdot \frac{U\_m}{J}\right) \cdot 0.125\right)\right)\\
\mathbf{if}\;t\_0 \leq -0.55:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -0.25:\\
\;\;\;\;U\_m\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.786:\\
\;\;\;\;-U\_m\\
\mathbf{elif}\;t\_0 \leq 0.998:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{-0.5}{J}\right)\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.55000000000000004 or -0.25 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.5 or 0.78600000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.998Initial program 71.8%
Simplified88.1%
Taylor expanded in K around 0 67.0%
associate-*r/67.0%
*-commutative67.0%
associate-*r/67.0%
Simplified67.0%
Taylor expanded in U around 0 53.4%
*-commutative53.4%
Simplified53.4%
unpow253.4%
unpow253.4%
times-frac62.2%
Applied egg-rr62.2%
if -0.55000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.25Initial program 57.9%
Simplified78.7%
Taylor expanded in U around -inf 34.9%
if 0.5 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.78600000000000003Initial program 62.9%
Simplified83.5%
Taylor expanded in J around 0 18.5%
neg-mul-118.5%
Simplified18.5%
if 0.998 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 71.2%
Simplified90.0%
associate-/r*90.0%
associate-*l*90.0%
add-cube-cbrt89.0%
associate-/l*89.0%
pow289.0%
*-commutative89.0%
*-commutative89.0%
add-sqr-sqrt42.4%
div-inv42.4%
metadata-eval42.4%
sqrt-unprod69.1%
swap-sqr69.1%
metadata-eval69.1%
metadata-eval69.1%
swap-sqr69.1%
*-commutative69.1%
*-commutative69.1%
sqrt-unprod46.6%
add-sqr-sqrt89.0%
*-commutative89.0%
Applied egg-rr89.0%
associate-/r*89.0%
associate-*r/89.0%
associate-*l/89.0%
associate-*r/89.0%
associate-*l/89.0%
unpow289.0%
rem-3cbrt-lft90.0%
*-commutative90.0%
*-commutative90.0%
Simplified90.0%
Taylor expanded in K around 0 51.4%
metadata-eval51.4%
metadata-eval51.4%
unpow251.4%
unpow251.4%
times-frac70.7%
swap-sqr70.7%
associate-*r/70.7%
*-commutative70.7%
associate-*r/70.6%
associate-*r/70.6%
*-commutative70.6%
associate-*r/70.6%
hypot-undefine89.4%
Simplified89.4%
Final simplification70.2%
U_m = (fabs.f64 U)
(FPCore (J K U_m)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= J 1.5e-205)
(- U_m)
(* J (* (* -2.0 t_0) (hypot 1.0 (/ (/ U_m 2.0) (* J t_0))))))))U_m = fabs(U);
double code(double J, double K, double U_m) {
double t_0 = cos((K / 2.0));
double tmp;
if (J <= 1.5e-205) {
tmp = -U_m;
} else {
tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J * t_0))));
}
return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (J <= 1.5e-205) {
tmp = -U_m;
} else {
tmp = J * ((-2.0 * t_0) * Math.hypot(1.0, ((U_m / 2.0) / (J * t_0))));
}
return tmp;
}
U_m = math.fabs(U) def code(J, K, U_m): t_0 = math.cos((K / 2.0)) tmp = 0 if J <= 1.5e-205: tmp = -U_m else: tmp = J * ((-2.0 * t_0) * math.hypot(1.0, ((U_m / 2.0) / (J * t_0)))) return tmp
U_m = abs(U) function code(J, K, U_m) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (J <= 1.5e-205) tmp = Float64(-U_m); else tmp = Float64(J * Float64(Float64(-2.0 * t_0) * hypot(1.0, Float64(Float64(U_m / 2.0) / Float64(J * t_0))))); end return tmp end
U_m = abs(U); function tmp_2 = code(J, K, U_m) t_0 = cos((K / 2.0)); tmp = 0.0; if (J <= 1.5e-205) tmp = -U_m; else tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J * t_0)))); end tmp_2 = tmp; end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[J, 1.5e-205], (-U$95$m), N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U_m = \left|U\right|
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq 1.5 \cdot 10^{-205}:\\
\;\;\;\;-U\_m\\
\mathbf{else}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J \cdot t\_0}\right)\right)\\
\end{array}
\end{array}
if J < 1.5e-205Initial program 65.2%
Simplified82.2%
Taylor expanded in J around 0 27.5%
neg-mul-127.5%
Simplified27.5%
if 1.5e-205 < J Initial program 76.0%
Simplified95.5%
Final simplification57.0%
U_m = (fabs.f64 U) (FPCore (J K U_m) :precision binary64 (if (<= J 6.4e-145) (- U_m) (* J (* (* -2.0 (cos (/ K 2.0))) (hypot 1.0 (* U_m (/ 0.5 J)))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
double tmp;
if (J <= 6.4e-145) {
tmp = -U_m;
} else {
tmp = J * ((-2.0 * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / J))));
}
return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
double tmp;
if (J <= 6.4e-145) {
tmp = -U_m;
} else {
tmp = J * ((-2.0 * Math.cos((K / 2.0))) * Math.hypot(1.0, (U_m * (0.5 / J))));
}
return tmp;
}
U_m = math.fabs(U) def code(J, K, U_m): tmp = 0 if J <= 6.4e-145: tmp = -U_m else: tmp = J * ((-2.0 * math.cos((K / 2.0))) * math.hypot(1.0, (U_m * (0.5 / J)))) return tmp
U_m = abs(U) function code(J, K, U_m) tmp = 0.0 if (J <= 6.4e-145) tmp = Float64(-U_m); else tmp = Float64(J * Float64(Float64(-2.0 * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U_m * Float64(0.5 / J))))); end return tmp end
U_m = abs(U); function tmp_2 = code(J, K, U_m) tmp = 0.0; if (J <= 6.4e-145) tmp = -U_m; else tmp = J * ((-2.0 * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / J)))); end tmp_2 = tmp; end
U_m = N[Abs[U], $MachinePrecision] code[J_, K_, U$95$m_] := If[LessEqual[J, 6.4e-145], (-U$95$m), N[(J * N[(N[(-2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|
\\
\begin{array}{l}
\mathbf{if}\;J \leq 6.4 \cdot 10^{-145}:\\
\;\;\;\;-U\_m\\
\mathbf{else}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{0.5}{J}\right)\right)\\
\end{array}
\end{array}
if J < 6.40000000000000017e-145Initial program 61.2%
Simplified80.6%
Taylor expanded in J around 0 29.2%
neg-mul-129.2%
Simplified29.2%
if 6.40000000000000017e-145 < J Initial program 83.6%
Simplified99.7%
Taylor expanded in K around 0 83.7%
associate-*r/83.7%
*-commutative83.7%
associate-*r/83.6%
Simplified83.6%
Final simplification50.3%
U_m = (fabs.f64 U)
(FPCore (J K U_m)
:precision binary64
(if (<= K 0.11)
(* J (* -2.0 (hypot 1.0 (* U_m (/ -0.5 J)))))
(if (or (<= K 6.2e+206) (and (not (<= K 5e+261)) (<= K 2.02e+298)))
(* (* -2.0 J) (cos (* K 0.5)))
U_m)))U_m = fabs(U);
double code(double J, double K, double U_m) {
double tmp;
if (K <= 0.11) {
tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J))));
} else if ((K <= 6.2e+206) || (!(K <= 5e+261) && (K <= 2.02e+298))) {
tmp = (-2.0 * J) * cos((K * 0.5));
} else {
tmp = U_m;
}
return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
double tmp;
if (K <= 0.11) {
tmp = J * (-2.0 * Math.hypot(1.0, (U_m * (-0.5 / J))));
} else if ((K <= 6.2e+206) || (!(K <= 5e+261) && (K <= 2.02e+298))) {
tmp = (-2.0 * J) * Math.cos((K * 0.5));
} else {
tmp = U_m;
}
return tmp;
}
U_m = math.fabs(U) def code(J, K, U_m): tmp = 0 if K <= 0.11: tmp = J * (-2.0 * math.hypot(1.0, (U_m * (-0.5 / J)))) elif (K <= 6.2e+206) or (not (K <= 5e+261) and (K <= 2.02e+298)): tmp = (-2.0 * J) * math.cos((K * 0.5)) else: tmp = U_m return tmp
U_m = abs(U) function code(J, K, U_m) tmp = 0.0 if (K <= 0.11) tmp = Float64(J * Float64(-2.0 * hypot(1.0, Float64(U_m * Float64(-0.5 / J))))); elseif ((K <= 6.2e+206) || (!(K <= 5e+261) && (K <= 2.02e+298))) tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))); else tmp = U_m; end return tmp end
U_m = abs(U); function tmp_2 = code(J, K, U_m) tmp = 0.0; if (K <= 0.11) tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J)))); elseif ((K <= 6.2e+206) || (~((K <= 5e+261)) && (K <= 2.02e+298))) tmp = (-2.0 * J) * cos((K * 0.5)); else tmp = U_m; end tmp_2 = tmp; end
U_m = N[Abs[U], $MachinePrecision] code[J_, K_, U$95$m_] := If[LessEqual[K, 0.11], N[(J * N[(-2.0 * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(-0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[K, 6.2e+206], And[N[Not[LessEqual[K, 5e+261]], $MachinePrecision], LessEqual[K, 2.02e+298]]], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], U$95$m]]
\begin{array}{l}
U_m = \left|U\right|
\\
\begin{array}{l}
\mathbf{if}\;K \leq 0.11:\\
\;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{-0.5}{J}\right)\right)\\
\mathbf{elif}\;K \leq 6.2 \cdot 10^{+206} \lor \neg \left(K \leq 5 \cdot 10^{+261}\right) \land K \leq 2.02 \cdot 10^{+298}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;U\_m\\
\end{array}
\end{array}
if K < 0.110000000000000001Initial program 70.9%
Simplified89.3%
associate-/r*89.3%
associate-*l*89.3%
add-cube-cbrt88.5%
associate-/l*88.5%
pow288.5%
*-commutative88.5%
*-commutative88.5%
add-sqr-sqrt46.8%
div-inv46.8%
metadata-eval46.8%
sqrt-unprod72.3%
swap-sqr72.3%
metadata-eval72.3%
metadata-eval72.3%
swap-sqr72.3%
*-commutative72.3%
*-commutative72.3%
sqrt-unprod41.7%
add-sqr-sqrt88.5%
*-commutative88.5%
Applied egg-rr88.5%
associate-/r*88.5%
associate-*r/88.5%
associate-*l/88.5%
associate-*r/88.5%
associate-*l/88.5%
unpow288.5%
rem-3cbrt-lft89.4%
*-commutative89.4%
*-commutative89.4%
Simplified89.4%
Taylor expanded in K around 0 36.2%
metadata-eval36.2%
metadata-eval36.2%
unpow236.2%
unpow236.2%
times-frac49.1%
swap-sqr49.1%
associate-*r/49.1%
*-commutative49.1%
associate-*r/49.1%
associate-*r/49.1%
*-commutative49.1%
associate-*r/49.1%
hypot-undefine62.7%
Simplified62.7%
if 0.110000000000000001 < K < 6.19999999999999981e206 or 5.0000000000000001e261 < K < 2.01999999999999994e298Initial program 72.7%
Simplified84.1%
Taylor expanded in J around inf 52.1%
associate-*r*52.1%
*-commutative52.1%
*-commutative52.1%
*-commutative52.1%
*-commutative52.1%
*-commutative52.1%
Simplified52.1%
if 6.19999999999999981e206 < K < 5.0000000000000001e261 or 2.01999999999999994e298 < K Initial program 39.3%
Simplified82.4%
Taylor expanded in U around -inf 36.9%
Final simplification59.6%
U_m = (fabs.f64 U) (FPCore (J K U_m) :precision binary64 (if (or (<= J 1.26e-56) (and (not (<= J 1.16e-26)) (<= J 3.9e+43))) (- U_m) (* (* -2.0 J) (cos (* K 0.5)))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
double tmp;
if ((J <= 1.26e-56) || (!(J <= 1.16e-26) && (J <= 3.9e+43))) {
tmp = -U_m;
} else {
tmp = (-2.0 * J) * cos((K * 0.5));
}
return tmp;
}
U_m = abs(u)
real(8) function code(j, k, u_m)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u_m
real(8) :: tmp
if ((j <= 1.26d-56) .or. (.not. (j <= 1.16d-26)) .and. (j <= 3.9d+43)) then
tmp = -u_m
else
tmp = ((-2.0d0) * j) * cos((k * 0.5d0))
end if
code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
double tmp;
if ((J <= 1.26e-56) || (!(J <= 1.16e-26) && (J <= 3.9e+43))) {
tmp = -U_m;
} else {
tmp = (-2.0 * J) * Math.cos((K * 0.5));
}
return tmp;
}
U_m = math.fabs(U) def code(J, K, U_m): tmp = 0 if (J <= 1.26e-56) or (not (J <= 1.16e-26) and (J <= 3.9e+43)): tmp = -U_m else: tmp = (-2.0 * J) * math.cos((K * 0.5)) return tmp
U_m = abs(U) function code(J, K, U_m) tmp = 0.0 if ((J <= 1.26e-56) || (!(J <= 1.16e-26) && (J <= 3.9e+43))) tmp = Float64(-U_m); else tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))); end return tmp end
U_m = abs(U); function tmp_2 = code(J, K, U_m) tmp = 0.0; if ((J <= 1.26e-56) || (~((J <= 1.16e-26)) && (J <= 3.9e+43))) tmp = -U_m; else tmp = (-2.0 * J) * cos((K * 0.5)); end tmp_2 = tmp; end
U_m = N[Abs[U], $MachinePrecision] code[J_, K_, U$95$m_] := If[Or[LessEqual[J, 1.26e-56], And[N[Not[LessEqual[J, 1.16e-26]], $MachinePrecision], LessEqual[J, 3.9e+43]]], (-U$95$m), N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|
\\
\begin{array}{l}
\mathbf{if}\;J \leq 1.26 \cdot 10^{-56} \lor \neg \left(J \leq 1.16 \cdot 10^{-26}\right) \land J \leq 3.9 \cdot 10^{+43}:\\
\;\;\;\;-U\_m\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\end{array}
\end{array}
if J < 1.26000000000000008e-56 or 1.16000000000000002e-26 < J < 3.9000000000000001e43Initial program 60.3%
Simplified83.2%
Taylor expanded in J around 0 29.3%
neg-mul-129.3%
Simplified29.3%
if 1.26000000000000008e-56 < J < 1.16000000000000002e-26 or 3.9000000000000001e43 < J Initial program 93.5%
Simplified99.7%
Taylor expanded in J around inf 71.6%
associate-*r*71.6%
*-commutative71.6%
*-commutative71.6%
*-commutative71.6%
*-commutative71.6%
*-commutative71.6%
Simplified71.6%
Final simplification41.5%
U_m = (fabs.f64 U) (FPCore (J K U_m) :precision binary64 (if (<= K 2.9e+206) (- U_m) U_m))
U_m = fabs(U);
double code(double J, double K, double U_m) {
double tmp;
if (K <= 2.9e+206) {
tmp = -U_m;
} else {
tmp = U_m;
}
return tmp;
}
U_m = abs(u)
real(8) function code(j, k, u_m)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u_m
real(8) :: tmp
if (k <= 2.9d+206) then
tmp = -u_m
else
tmp = u_m
end if
code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
double tmp;
if (K <= 2.9e+206) {
tmp = -U_m;
} else {
tmp = U_m;
}
return tmp;
}
U_m = math.fabs(U) def code(J, K, U_m): tmp = 0 if K <= 2.9e+206: tmp = -U_m else: tmp = U_m return tmp
U_m = abs(U) function code(J, K, U_m) tmp = 0.0 if (K <= 2.9e+206) tmp = Float64(-U_m); else tmp = U_m; end return tmp end
U_m = abs(U); function tmp_2 = code(J, K, U_m) tmp = 0.0; if (K <= 2.9e+206) tmp = -U_m; else tmp = U_m; end tmp_2 = tmp; end
U_m = N[Abs[U], $MachinePrecision] code[J_, K_, U$95$m_] := If[LessEqual[K, 2.9e+206], (-U$95$m), U$95$m]
\begin{array}{l}
U_m = \left|U\right|
\\
\begin{array}{l}
\mathbf{if}\;K \leq 2.9 \cdot 10^{+206}:\\
\;\;\;\;-U\_m\\
\mathbf{else}:\\
\;\;\;\;U\_m\\
\end{array}
\end{array}
if K < 2.9e206Initial program 71.2%
Simplified88.1%
Taylor expanded in J around 0 24.8%
neg-mul-124.8%
Simplified24.8%
if 2.9e206 < K Initial program 49.2%
Simplified87.0%
Taylor expanded in U around -inf 27.4%
Final simplification25.0%
U_m = (fabs.f64 U) (FPCore (J K U_m) :precision binary64 U_m)
U_m = fabs(U);
double code(double J, double K, double U_m) {
return U_m;
}
U_m = abs(u)
real(8) function code(j, k, u_m)
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u_m
code = u_m
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
return U_m;
}
U_m = math.fabs(U) def code(J, K, U_m): return U_m
U_m = abs(U) function code(J, K, U_m) return U_m end
U_m = abs(U); function tmp = code(J, K, U_m) tmp = U_m; end
U_m = N[Abs[U], $MachinePrecision] code[J_, K_, U$95$m_] := U$95$m
\begin{array}{l}
U_m = \left|U\right|
\\
U\_m
\end{array}
Initial program 69.9%
Simplified88.0%
Taylor expanded in U around -inf 28.6%
Final simplification28.6%
herbie shell --seed 2024067
(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)))))