
(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 7 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)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1 (* J_m t_0))
(t_2
(*
(* (* -2.0 J_m) t_0)
(sqrt (+ 1.0 (pow (/ U_m (* t_0 (* J_m 2.0))) 2.0))))))
(*
J_s
(if (<= t_2 (- INFINITY))
(* -2.0 (* U_m 0.5))
(if (<= t_2 1e+301)
(* -2.0 (* t_1 (hypot 1.0 (/ (/ U_m 2.0) t_1))))
(* -2.0 (* U_m -0.5)))))))U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
double t_0 = cos((K / 2.0));
double t_1 = J_m * t_0;
double t_2 = ((-2.0 * J_m) * t_0) * sqrt((1.0 + pow((U_m / (t_0 * (J_m * 2.0))), 2.0)));
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = -2.0 * (U_m * 0.5);
} else if (t_2 <= 1e+301) {
tmp = -2.0 * (t_1 * hypot(1.0, ((U_m / 2.0) / t_1)));
} else {
tmp = -2.0 * (U_m * -0.5);
}
return J_s * tmp;
}
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
double t_0 = Math.cos((K / 2.0));
double t_1 = J_m * t_0;
double t_2 = ((-2.0 * J_m) * t_0) * Math.sqrt((1.0 + Math.pow((U_m / (t_0 * (J_m * 2.0))), 2.0)));
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = -2.0 * (U_m * 0.5);
} else if (t_2 <= 1e+301) {
tmp = -2.0 * (t_1 * Math.hypot(1.0, ((U_m / 2.0) / t_1)));
} else {
tmp = -2.0 * (U_m * -0.5);
}
return J_s * tmp;
}
U_m = math.fabs(U) J_m = math.fabs(J) J_s = math.copysign(1.0, J) def code(J_s, J_m, K, U_m): t_0 = math.cos((K / 2.0)) t_1 = J_m * t_0 t_2 = ((-2.0 * J_m) * t_0) * math.sqrt((1.0 + math.pow((U_m / (t_0 * (J_m * 2.0))), 2.0))) tmp = 0 if t_2 <= -math.inf: tmp = -2.0 * (U_m * 0.5) elif t_2 <= 1e+301: tmp = -2.0 * (t_1 * math.hypot(1.0, ((U_m / 2.0) / t_1))) else: tmp = -2.0 * (U_m * -0.5) return J_s * tmp
U_m = abs(U) J_m = abs(J) J_s = copysign(1.0, J) function code(J_s, J_m, K, U_m) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(J_m * t_0) t_2 = Float64(Float64(Float64(-2.0 * J_m) * t_0) * sqrt(Float64(1.0 + (Float64(U_m / Float64(t_0 * Float64(J_m * 2.0))) ^ 2.0)))) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(-2.0 * Float64(U_m * 0.5)); elseif (t_2 <= 1e+301) tmp = Float64(-2.0 * Float64(t_1 * hypot(1.0, Float64(Float64(U_m / 2.0) / t_1)))); else tmp = Float64(-2.0 * Float64(U_m * -0.5)); end return Float64(J_s * tmp) end
U_m = abs(U); J_m = abs(J); J_s = sign(J) * abs(1.0); function tmp_2 = code(J_s, J_m, K, U_m) t_0 = cos((K / 2.0)); t_1 = J_m * t_0; t_2 = ((-2.0 * J_m) * t_0) * sqrt((1.0 + ((U_m / (t_0 * (J_m * 2.0))) ^ 2.0))); tmp = 0.0; if (t_2 <= -Inf) tmp = -2.0 * (U_m * 0.5); elseif (t_2 <= 1e+301) tmp = -2.0 * (t_1 * hypot(1.0, ((U_m / 2.0) / t_1))); else tmp = -2.0 * (U_m * -0.5); end tmp_2 = J_s * tmp; end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(J$95$m * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(-2.0 * J$95$m), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U$95$m / N[(t$95$0 * N[(J$95$m * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(J$95$s * If[LessEqual[t$95$2, (-Infinity)], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+301], N[(-2.0 * N[(t$95$1 * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / t$95$1), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(U$95$m * -0.5), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := J_m \cdot t_0\\
t_2 := \left(\left(-2 \cdot J_m\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U_m}{t_0 \cdot \left(J_m \cdot 2\right)}\right)}^{2}}\\
J_s \cdot \begin{array}{l}
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\mathbf{elif}\;t_2 \leq 10^{+301}:\\
\;\;\;\;-2 \cdot \left(t_1 \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{t_1}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot -0.5\right)\\
\end{array}
\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 5.7%
associate-*l*5.7%
associate-*l*5.7%
*-commutative5.7%
unpow25.7%
sqr-neg5.7%
distribute-frac-neg5.7%
distribute-frac-neg5.7%
unpow25.7%
Simplified57.9%
Taylor expanded in J around 0 60.8%
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)))) < 1.00000000000000005e301Initial program 99.8%
associate-*l*99.8%
associate-*l*99.8%
unpow299.8%
sqr-neg99.8%
distribute-frac-neg99.8%
distribute-frac-neg99.8%
unpow299.8%
Simplified99.8%
if 1.00000000000000005e301 < (*.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 15.5%
associate-*l*15.5%
associate-*l*15.5%
*-commutative15.5%
unpow215.5%
sqr-neg15.5%
distribute-frac-neg15.5%
distribute-frac-neg15.5%
unpow215.5%
Simplified68.1%
Taylor expanded in U around -inf 38.8%
*-commutative38.8%
Simplified38.8%
Final simplification82.8%
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1 (* -2.0 (* J_m t_0)))
(t_2 (* -2.0 (* U_m -0.5))))
(*
J_s
(if (<= t_0 -0.8)
t_2
(if (<= t_0 -0.6545)
t_1
(if (<= t_0 -5e-310)
t_2
(if (<= t_0 0.65)
(* -2.0 (* U_m 0.5))
(if (<= t_0 0.99999)
t_1
(* -2.0 (* J_m (hypot 1.0 (* 0.5 (/ U_m J_m)))))))))))))U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
double t_0 = cos((K / 2.0));
double t_1 = -2.0 * (J_m * t_0);
double t_2 = -2.0 * (U_m * -0.5);
double tmp;
if (t_0 <= -0.8) {
tmp = t_2;
} else if (t_0 <= -0.6545) {
tmp = t_1;
} else if (t_0 <= -5e-310) {
tmp = t_2;
} else if (t_0 <= 0.65) {
tmp = -2.0 * (U_m * 0.5);
} else if (t_0 <= 0.99999) {
tmp = t_1;
} else {
tmp = -2.0 * (J_m * hypot(1.0, (0.5 * (U_m / J_m))));
}
return J_s * tmp;
}
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
double t_0 = Math.cos((K / 2.0));
double t_1 = -2.0 * (J_m * t_0);
double t_2 = -2.0 * (U_m * -0.5);
double tmp;
if (t_0 <= -0.8) {
tmp = t_2;
} else if (t_0 <= -0.6545) {
tmp = t_1;
} else if (t_0 <= -5e-310) {
tmp = t_2;
} else if (t_0 <= 0.65) {
tmp = -2.0 * (U_m * 0.5);
} else if (t_0 <= 0.99999) {
tmp = t_1;
} else {
tmp = -2.0 * (J_m * Math.hypot(1.0, (0.5 * (U_m / J_m))));
}
return J_s * tmp;
}
U_m = math.fabs(U) J_m = math.fabs(J) J_s = math.copysign(1.0, J) def code(J_s, J_m, K, U_m): t_0 = math.cos((K / 2.0)) t_1 = -2.0 * (J_m * t_0) t_2 = -2.0 * (U_m * -0.5) tmp = 0 if t_0 <= -0.8: tmp = t_2 elif t_0 <= -0.6545: tmp = t_1 elif t_0 <= -5e-310: tmp = t_2 elif t_0 <= 0.65: tmp = -2.0 * (U_m * 0.5) elif t_0 <= 0.99999: tmp = t_1 else: tmp = -2.0 * (J_m * math.hypot(1.0, (0.5 * (U_m / J_m)))) return J_s * tmp
U_m = abs(U) J_m = abs(J) J_s = copysign(1.0, J) function code(J_s, J_m, K, U_m) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(-2.0 * Float64(J_m * t_0)) t_2 = Float64(-2.0 * Float64(U_m * -0.5)) tmp = 0.0 if (t_0 <= -0.8) tmp = t_2; elseif (t_0 <= -0.6545) tmp = t_1; elseif (t_0 <= -5e-310) tmp = t_2; elseif (t_0 <= 0.65) tmp = Float64(-2.0 * Float64(U_m * 0.5)); elseif (t_0 <= 0.99999) tmp = t_1; else tmp = Float64(-2.0 * Float64(J_m * hypot(1.0, Float64(0.5 * Float64(U_m / J_m))))); end return Float64(J_s * tmp) end
U_m = abs(U); J_m = abs(J); J_s = sign(J) * abs(1.0); function tmp_2 = code(J_s, J_m, K, U_m) t_0 = cos((K / 2.0)); t_1 = -2.0 * (J_m * t_0); t_2 = -2.0 * (U_m * -0.5); tmp = 0.0; if (t_0 <= -0.8) tmp = t_2; elseif (t_0 <= -0.6545) tmp = t_1; elseif (t_0 <= -5e-310) tmp = t_2; elseif (t_0 <= 0.65) tmp = -2.0 * (U_m * 0.5); elseif (t_0 <= 0.99999) tmp = t_1; else tmp = -2.0 * (J_m * hypot(1.0, (0.5 * (U_m / J_m)))); end tmp_2 = J_s * tmp; end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * N[(J$95$m * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-2.0 * N[(U$95$m * -0.5), $MachinePrecision]), $MachinePrecision]}, N[(J$95$s * If[LessEqual[t$95$0, -0.8], t$95$2, If[LessEqual[t$95$0, -0.6545], t$95$1, If[LessEqual[t$95$0, -5e-310], t$95$2, If[LessEqual[t$95$0, 0.65], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.99999], t$95$1, N[(-2.0 * N[(J$95$m * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J$95$m), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]), $MachinePrecision]]]]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := -2 \cdot \left(J_m \cdot t_0\right)\\
t_2 := -2 \cdot \left(U_m \cdot -0.5\right)\\
J_s \cdot \begin{array}{l}
\mathbf{if}\;t_0 \leq -0.8:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_0 \leq -0.6545:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_0 \leq 0.65:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\mathbf{elif}\;t_0 \leq 0.99999:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J_m \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U_m}{J_m}\right)\right)\\
\end{array}
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.80000000000000004 or -0.654499999999999971 < (cos.f64 (/.f64 K 2)) < -4.999999999999985e-310Initial program 66.1%
associate-*l*66.1%
associate-*l*66.1%
*-commutative66.1%
unpow266.1%
sqr-neg66.1%
distribute-frac-neg66.1%
distribute-frac-neg66.1%
unpow266.1%
Simplified90.4%
Taylor expanded in U around -inf 29.1%
*-commutative29.1%
Simplified29.1%
if -0.80000000000000004 < (cos.f64 (/.f64 K 2)) < -0.654499999999999971 or 0.650000000000000022 < (cos.f64 (/.f64 K 2)) < 0.999990000000000046Initial program 81.0%
associate-*l*81.0%
associate-*l*81.0%
*-commutative81.0%
unpow281.0%
sqr-neg81.0%
distribute-frac-neg81.0%
distribute-frac-neg81.0%
unpow281.0%
Simplified88.5%
Taylor expanded in J around inf 68.4%
if -4.999999999999985e-310 < (cos.f64 (/.f64 K 2)) < 0.650000000000000022Initial program 56.2%
associate-*l*56.2%
associate-*l*56.2%
*-commutative56.2%
unpow256.2%
sqr-neg56.2%
distribute-frac-neg56.2%
distribute-frac-neg56.2%
unpow256.2%
Simplified82.8%
Taylor expanded in J around 0 47.4%
if 0.999990000000000046 < (cos.f64 (/.f64 K 2)) Initial program 71.0%
associate-*l*71.0%
associate-*l*71.0%
unpow271.0%
sqr-neg71.0%
distribute-frac-neg71.0%
distribute-frac-neg71.0%
unpow271.0%
Simplified87.5%
Taylor expanded in K around 0 87.2%
associate-*r/87.2%
*-commutative87.2%
associate-*r/87.1%
Simplified87.1%
Taylor expanded in K around 0 52.4%
metadata-eval52.4%
unpow252.4%
unpow252.4%
times-frac71.0%
swap-sqr71.0%
associate-*r/71.0%
*-commutative71.0%
associate-*r/70.9%
associate-*r/70.9%
*-commutative70.9%
associate-*r/70.9%
unpow270.9%
unpow270.9%
hypot-1-def87.4%
associate-*r/87.5%
*-commutative87.5%
associate-*r/87.5%
Simplified87.5%
Final simplification67.7%
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(*
J_s
(if (<= U_m 3.6e+199)
(* -2.0 (* t_0 (* J_m (hypot 1.0 (/ (/ U_m 2.0) (* J_m t_0))))))
(* -2.0 (* U_m 0.5))))))U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
double t_0 = cos((K / 2.0));
double tmp;
if (U_m <= 3.6e+199) {
tmp = -2.0 * (t_0 * (J_m * hypot(1.0, ((U_m / 2.0) / (J_m * t_0)))));
} else {
tmp = -2.0 * (U_m * 0.5);
}
return J_s * tmp;
}
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (U_m <= 3.6e+199) {
tmp = -2.0 * (t_0 * (J_m * Math.hypot(1.0, ((U_m / 2.0) / (J_m * t_0)))));
} else {
tmp = -2.0 * (U_m * 0.5);
}
return J_s * tmp;
}
U_m = math.fabs(U) J_m = math.fabs(J) J_s = math.copysign(1.0, J) def code(J_s, J_m, K, U_m): t_0 = math.cos((K / 2.0)) tmp = 0 if U_m <= 3.6e+199: tmp = -2.0 * (t_0 * (J_m * math.hypot(1.0, ((U_m / 2.0) / (J_m * t_0))))) else: tmp = -2.0 * (U_m * 0.5) return J_s * tmp
U_m = abs(U) J_m = abs(J) J_s = copysign(1.0, J) function code(J_s, J_m, K, U_m) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (U_m <= 3.6e+199) tmp = Float64(-2.0 * Float64(t_0 * Float64(J_m * hypot(1.0, Float64(Float64(U_m / 2.0) / Float64(J_m * t_0)))))); else tmp = Float64(-2.0 * Float64(U_m * 0.5)); end return Float64(J_s * tmp) end
U_m = abs(U); J_m = abs(J); J_s = sign(J) * abs(1.0); function tmp_2 = code(J_s, J_m, K, U_m) t_0 = cos((K / 2.0)); tmp = 0.0; if (U_m <= 3.6e+199) tmp = -2.0 * (t_0 * (J_m * hypot(1.0, ((U_m / 2.0) / (J_m * t_0))))); else tmp = -2.0 * (U_m * 0.5); end tmp_2 = J_s * tmp; end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(J$95$s * If[LessEqual[U$95$m, 3.6e+199], N[(-2.0 * N[(t$95$0 * N[(J$95$m * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / N[(J$95$m * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
J_s \cdot \begin{array}{l}
\mathbf{if}\;U_m \leq 3.6 \cdot 10^{+199}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(J_m \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{J_m \cdot t_0}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\end{array}
\end{array}
\end{array}
if U < 3.60000000000000001e199Initial program 73.6%
associate-*l*73.6%
associate-*l*73.6%
*-commutative73.6%
unpow273.6%
sqr-neg73.6%
distribute-frac-neg73.6%
distribute-frac-neg73.6%
unpow273.6%
Simplified91.4%
if 3.60000000000000001e199 < U Initial program 33.5%
associate-*l*33.5%
associate-*l*33.5%
*-commutative33.5%
unpow233.5%
sqr-neg33.5%
distribute-frac-neg33.5%
distribute-frac-neg33.5%
unpow233.5%
Simplified46.6%
Taylor expanded in J around 0 71.9%
Final simplification89.8%
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
:precision binary64
(*
J_s
(if (<= U_m 6.5e+72)
(* -2.0 (* (* J_m (cos (/ K 2.0))) (hypot 1.0 (* U_m (/ 0.5 J_m)))))
(* -2.0 (* U_m 0.5)))))U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
double tmp;
if (U_m <= 6.5e+72) {
tmp = -2.0 * ((J_m * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / J_m))));
} else {
tmp = -2.0 * (U_m * 0.5);
}
return J_s * tmp;
}
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
double tmp;
if (U_m <= 6.5e+72) {
tmp = -2.0 * ((J_m * Math.cos((K / 2.0))) * Math.hypot(1.0, (U_m * (0.5 / J_m))));
} else {
tmp = -2.0 * (U_m * 0.5);
}
return J_s * tmp;
}
U_m = math.fabs(U) J_m = math.fabs(J) J_s = math.copysign(1.0, J) def code(J_s, J_m, K, U_m): tmp = 0 if U_m <= 6.5e+72: tmp = -2.0 * ((J_m * math.cos((K / 2.0))) * math.hypot(1.0, (U_m * (0.5 / J_m)))) else: tmp = -2.0 * (U_m * 0.5) return J_s * tmp
U_m = abs(U) J_m = abs(J) J_s = copysign(1.0, J) function code(J_s, J_m, K, U_m) tmp = 0.0 if (U_m <= 6.5e+72) tmp = Float64(-2.0 * Float64(Float64(J_m * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U_m * Float64(0.5 / J_m))))); else tmp = Float64(-2.0 * Float64(U_m * 0.5)); end return Float64(J_s * tmp) end
U_m = abs(U); J_m = abs(J); J_s = sign(J) * abs(1.0); function tmp_2 = code(J_s, J_m, K, U_m) tmp = 0.0; if (U_m <= 6.5e+72) tmp = -2.0 * ((J_m * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / J_m)))); else tmp = -2.0 * (U_m * 0.5); end tmp_2 = J_s * tmp; end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * If[LessEqual[U$95$m, 6.5e+72], N[(-2.0 * N[(N[(J$95$m * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(0.5 / J$95$m), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)
\\
J_s \cdot \begin{array}{l}
\mathbf{if}\;U_m \leq 6.5 \cdot 10^{+72}:\\
\;\;\;\;-2 \cdot \left(\left(J_m \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U_m \cdot \frac{0.5}{J_m}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\end{array}
\end{array}
if U < 6.5000000000000001e72Initial program 77.0%
associate-*l*77.0%
associate-*l*77.0%
unpow277.0%
sqr-neg77.0%
distribute-frac-neg77.0%
distribute-frac-neg77.0%
unpow277.0%
Simplified92.8%
Taylor expanded in K around 0 77.3%
associate-*r/77.3%
*-commutative77.3%
associate-*r/77.3%
Simplified77.3%
if 6.5000000000000001e72 < U Initial program 39.3%
associate-*l*39.3%
associate-*l*39.3%
*-commutative39.3%
unpow239.3%
sqr-neg39.3%
distribute-frac-neg39.3%
distribute-frac-neg39.3%
unpow239.3%
Simplified64.3%
Taylor expanded in J around 0 53.9%
Final simplification73.2%
U_m = (fabs.f64 U) J_m = (fabs.f64 J) J_s = (copysign.f64 1 J) (FPCore (J_s J_m K U_m) :precision binary64 (* J_s (if (<= J_m 1.5e-75) (* -2.0 (* U_m 0.5)) (* -2.0 (* J_m (cos (/ K 2.0)))))))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
double tmp;
if (J_m <= 1.5e-75) {
tmp = -2.0 * (U_m * 0.5);
} else {
tmp = -2.0 * (J_m * cos((K / 2.0)));
}
return J_s * tmp;
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
real(8), intent (in) :: j_s
real(8), intent (in) :: j_m
real(8), intent (in) :: k
real(8), intent (in) :: u_m
real(8) :: tmp
if (j_m <= 1.5d-75) then
tmp = (-2.0d0) * (u_m * 0.5d0)
else
tmp = (-2.0d0) * (j_m * cos((k / 2.0d0)))
end if
code = j_s * tmp
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
double tmp;
if (J_m <= 1.5e-75) {
tmp = -2.0 * (U_m * 0.5);
} else {
tmp = -2.0 * (J_m * Math.cos((K / 2.0)));
}
return J_s * tmp;
}
U_m = math.fabs(U) J_m = math.fabs(J) J_s = math.copysign(1.0, J) def code(J_s, J_m, K, U_m): tmp = 0 if J_m <= 1.5e-75: tmp = -2.0 * (U_m * 0.5) else: tmp = -2.0 * (J_m * math.cos((K / 2.0))) return J_s * tmp
U_m = abs(U) J_m = abs(J) J_s = copysign(1.0, J) function code(J_s, J_m, K, U_m) tmp = 0.0 if (J_m <= 1.5e-75) tmp = Float64(-2.0 * Float64(U_m * 0.5)); else tmp = Float64(-2.0 * Float64(J_m * cos(Float64(K / 2.0)))); end return Float64(J_s * tmp) end
U_m = abs(U); J_m = abs(J); J_s = sign(J) * abs(1.0); function tmp_2 = code(J_s, J_m, K, U_m) tmp = 0.0; if (J_m <= 1.5e-75) tmp = -2.0 * (U_m * 0.5); else tmp = -2.0 * (J_m * cos((K / 2.0))); end tmp_2 = J_s * tmp; end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * If[LessEqual[J$95$m, 1.5e-75], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(J$95$m * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)
\\
J_s \cdot \begin{array}{l}
\mathbf{if}\;J_m \leq 1.5 \cdot 10^{-75}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J_m \cdot \cos \left(\frac{K}{2}\right)\right)\\
\end{array}
\end{array}
if J < 1.4999999999999999e-75Initial program 64.2%
associate-*l*64.2%
associate-*l*64.2%
*-commutative64.2%
unpow264.2%
sqr-neg64.2%
distribute-frac-neg64.2%
distribute-frac-neg64.2%
unpow264.2%
Simplified83.9%
Taylor expanded in J around 0 41.5%
if 1.4999999999999999e-75 < J Initial program 87.5%
associate-*l*87.5%
associate-*l*87.5%
*-commutative87.5%
unpow287.5%
sqr-neg87.5%
distribute-frac-neg87.5%
distribute-frac-neg87.5%
unpow287.5%
Simplified98.3%
Taylor expanded in J around inf 70.7%
Final simplification49.2%
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
:precision binary64
(*
J_s
(if (or (<= J_m 2.9e-27) (and (not (<= J_m 0.0009)) (<= J_m 1.7e+100)))
(* -2.0 (* U_m 0.5))
(* -2.0 J_m))))U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
double tmp;
if ((J_m <= 2.9e-27) || (!(J_m <= 0.0009) && (J_m <= 1.7e+100))) {
tmp = -2.0 * (U_m * 0.5);
} else {
tmp = -2.0 * J_m;
}
return J_s * tmp;
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
real(8), intent (in) :: j_s
real(8), intent (in) :: j_m
real(8), intent (in) :: k
real(8), intent (in) :: u_m
real(8) :: tmp
if ((j_m <= 2.9d-27) .or. (.not. (j_m <= 0.0009d0)) .and. (j_m <= 1.7d+100)) then
tmp = (-2.0d0) * (u_m * 0.5d0)
else
tmp = (-2.0d0) * j_m
end if
code = j_s * tmp
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
double tmp;
if ((J_m <= 2.9e-27) || (!(J_m <= 0.0009) && (J_m <= 1.7e+100))) {
tmp = -2.0 * (U_m * 0.5);
} else {
tmp = -2.0 * J_m;
}
return J_s * tmp;
}
U_m = math.fabs(U) J_m = math.fabs(J) J_s = math.copysign(1.0, J) def code(J_s, J_m, K, U_m): tmp = 0 if (J_m <= 2.9e-27) or (not (J_m <= 0.0009) and (J_m <= 1.7e+100)): tmp = -2.0 * (U_m * 0.5) else: tmp = -2.0 * J_m return J_s * tmp
U_m = abs(U) J_m = abs(J) J_s = copysign(1.0, J) function code(J_s, J_m, K, U_m) tmp = 0.0 if ((J_m <= 2.9e-27) || (!(J_m <= 0.0009) && (J_m <= 1.7e+100))) tmp = Float64(-2.0 * Float64(U_m * 0.5)); else tmp = Float64(-2.0 * J_m); end return Float64(J_s * tmp) end
U_m = abs(U); J_m = abs(J); J_s = sign(J) * abs(1.0); function tmp_2 = code(J_s, J_m, K, U_m) tmp = 0.0; if ((J_m <= 2.9e-27) || (~((J_m <= 0.0009)) && (J_m <= 1.7e+100))) tmp = -2.0 * (U_m * 0.5); else tmp = -2.0 * J_m; end tmp_2 = J_s * tmp; end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * If[Or[LessEqual[J$95$m, 2.9e-27], And[N[Not[LessEqual[J$95$m, 0.0009]], $MachinePrecision], LessEqual[J$95$m, 1.7e+100]]], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision], N[(-2.0 * J$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)
\\
J_s \cdot \begin{array}{l}
\mathbf{if}\;J_m \leq 2.9 \cdot 10^{-27} \lor \neg \left(J_m \leq 0.0009\right) \land J_m \leq 1.7 \cdot 10^{+100}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot J_m\\
\end{array}
\end{array}
if J < 2.90000000000000004e-27 or 8.9999999999999998e-4 < J < 1.69999999999999997e100Initial program 65.1%
associate-*l*65.1%
associate-*l*65.1%
*-commutative65.1%
unpow265.1%
sqr-neg65.1%
distribute-frac-neg65.1%
distribute-frac-neg65.1%
unpow265.1%
Simplified85.6%
Taylor expanded in J around 0 40.3%
if 2.90000000000000004e-27 < J < 8.9999999999999998e-4 or 1.69999999999999997e100 < J Initial program 99.7%
associate-*l*99.7%
associate-*l*99.7%
*-commutative99.7%
unpow299.7%
sqr-neg99.7%
distribute-frac-neg99.7%
distribute-frac-neg99.7%
unpow299.7%
Simplified99.7%
add-cube-cbrt97.9%
pow398.0%
div-inv98.0%
times-frac98.0%
metadata-eval98.0%
div-inv98.0%
metadata-eval98.0%
Applied egg-rr98.0%
Taylor expanded in J around inf 91.1%
Taylor expanded in K around 0 42.3%
Final simplification40.6%
U_m = (fabs.f64 U) J_m = (fabs.f64 J) J_s = (copysign.f64 1 J) (FPCore (J_s J_m K U_m) :precision binary64 (* J_s (* -2.0 J_m)))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
return J_s * (-2.0 * J_m);
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
real(8), intent (in) :: j_s
real(8), intent (in) :: j_m
real(8), intent (in) :: k
real(8), intent (in) :: u_m
code = j_s * ((-2.0d0) * j_m)
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
return J_s * (-2.0 * J_m);
}
U_m = math.fabs(U) J_m = math.fabs(J) J_s = math.copysign(1.0, J) def code(J_s, J_m, K, U_m): return J_s * (-2.0 * J_m)
U_m = abs(U) J_m = abs(J) J_s = copysign(1.0, J) function code(J_s, J_m, K, U_m) return Float64(J_s * Float64(-2.0 * J_m)) end
U_m = abs(U); J_m = abs(J); J_s = sign(J) * abs(1.0); function tmp = code(J_s, J_m, K, U_m) tmp = J_s * (-2.0 * J_m); end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * N[(-2.0 * J$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)
\\
J_s \cdot \left(-2 \cdot J_m\right)
\end{array}
Initial program 70.4%
associate-*l*70.4%
associate-*l*70.4%
*-commutative70.4%
unpow270.4%
sqr-neg70.4%
distribute-frac-neg70.4%
distribute-frac-neg70.4%
unpow270.4%
Simplified87.7%
add-cube-cbrt86.2%
pow386.2%
div-inv86.2%
times-frac86.2%
metadata-eval86.2%
div-inv86.2%
metadata-eval86.2%
Applied egg-rr86.2%
Taylor expanded in J around inf 47.1%
Taylor expanded in K around 0 27.6%
Final simplification27.6%
herbie shell --seed 2023333
(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)))))