
(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 2e+300)
(* -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 <= 2e+300) {
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 <= 2e+300) {
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 <= 2e+300: 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 <= 2e+300) 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 <= 2e+300) 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, 2e+300], 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 2 \cdot 10^{+300}:\\
\;\;\;\;-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.8%
associate-*l*5.8%
associate-*l*5.8%
*-commutative5.8%
unpow25.8%
sqr-neg5.8%
distribute-frac-neg5.8%
distribute-frac-neg5.8%
unpow25.8%
Simplified51.7%
Taylor expanded in J around 0 45.1%
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)))) < 2.0000000000000001e300Initial 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 2.0000000000000001e300 < (*.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 13.1%
associate-*l*13.1%
associate-*l*13.1%
*-commutative13.1%
unpow213.1%
sqr-neg13.1%
distribute-frac-neg13.1%
distribute-frac-neg13.1%
unpow213.1%
Simplified64.2%
Taylor expanded in U around -inf 46.3%
*-commutative46.3%
Simplified46.3%
Final simplification85.9%
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.67)
t_2
(if (<= t_0 -0.44)
t_1
(if (<= t_0 -5e-310)
t_2
(if (<= t_0 0.67)
(* -2.0 (* U_m 0.5))
(if (<= t_0 0.72)
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.67) {
tmp = t_2;
} else if (t_0 <= -0.44) {
tmp = t_1;
} else if (t_0 <= -5e-310) {
tmp = t_2;
} else if (t_0 <= 0.67) {
tmp = -2.0 * (U_m * 0.5);
} else if (t_0 <= 0.72) {
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.67) {
tmp = t_2;
} else if (t_0 <= -0.44) {
tmp = t_1;
} else if (t_0 <= -5e-310) {
tmp = t_2;
} else if (t_0 <= 0.67) {
tmp = -2.0 * (U_m * 0.5);
} else if (t_0 <= 0.72) {
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.67: tmp = t_2 elif t_0 <= -0.44: tmp = t_1 elif t_0 <= -5e-310: tmp = t_2 elif t_0 <= 0.67: tmp = -2.0 * (U_m * 0.5) elif t_0 <= 0.72: 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.67) tmp = t_2; elseif (t_0 <= -0.44) tmp = t_1; elseif (t_0 <= -5e-310) tmp = t_2; elseif (t_0 <= 0.67) tmp = Float64(-2.0 * Float64(U_m * 0.5)); elseif (t_0 <= 0.72) 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.67) tmp = t_2; elseif (t_0 <= -0.44) tmp = t_1; elseif (t_0 <= -5e-310) tmp = t_2; elseif (t_0 <= 0.67) tmp = -2.0 * (U_m * 0.5); elseif (t_0 <= 0.72) 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.67], t$95$2, If[LessEqual[t$95$0, -0.44], t$95$1, If[LessEqual[t$95$0, -5e-310], t$95$2, If[LessEqual[t$95$0, 0.67], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.72], 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.67:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_0 \leq -0.44:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_0 \leq 0.67:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\mathbf{elif}\;t_0 \leq 0.72:\\
\;\;\;\;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.67000000000000004 or -0.440000000000000002 < (cos.f64 (/.f64 K 2)) < -4.999999999999985e-310Initial program 57.2%
associate-*l*57.2%
associate-*l*57.2%
*-commutative57.2%
unpow257.2%
sqr-neg57.2%
distribute-frac-neg57.2%
distribute-frac-neg57.2%
unpow257.2%
Simplified80.3%
Taylor expanded in U around -inf 27.9%
*-commutative27.9%
Simplified27.9%
if -0.67000000000000004 < (cos.f64 (/.f64 K 2)) < -0.440000000000000002 or 0.67000000000000004 < (cos.f64 (/.f64 K 2)) < 0.71999999999999997Initial program 93.1%
associate-*l*93.1%
associate-*l*93.1%
*-commutative93.1%
unpow293.1%
sqr-neg93.1%
distribute-frac-neg93.1%
distribute-frac-neg93.1%
unpow293.1%
Simplified99.6%
Taylor expanded in J around inf 87.1%
if -4.999999999999985e-310 < (cos.f64 (/.f64 K 2)) < 0.67000000000000004Initial program 66.8%
associate-*l*66.8%
associate-*l*66.8%
*-commutative66.8%
unpow266.8%
sqr-neg66.8%
distribute-frac-neg66.8%
distribute-frac-neg66.8%
unpow266.8%
Simplified84.7%
Taylor expanded in J around 0 26.0%
if 0.71999999999999997 < (cos.f64 (/.f64 K 2)) Initial program 84.2%
associate-*l*84.2%
associate-*l*84.2%
unpow284.2%
sqr-neg84.2%
distribute-frac-neg84.2%
distribute-frac-neg84.2%
unpow284.2%
Simplified92.4%
add-cbrt-cube42.0%
pow342.0%
div-inv42.0%
metadata-eval42.0%
Applied egg-rr42.0%
rem-cbrt-cube92.4%
*-commutative92.4%
metadata-eval92.4%
div-inv92.4%
add-sqr-sqrt45.5%
associate-*r*45.5%
div-inv45.5%
metadata-eval45.5%
Applied egg-rr45.5%
Taylor expanded in K around 0 64.2%
metadata-eval64.2%
unpow264.2%
unpow264.2%
times-frac77.3%
swap-sqr77.3%
associate-*r/77.3%
*-commutative77.3%
associate-*r/77.3%
*-commutative77.3%
hypot-1-def85.5%
*-commutative85.5%
associate-*r/85.5%
Simplified85.5%
Final simplification65.1%
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 (* -2.0 (* t_0 (* J_m (hypot 1.0 (/ (/ U_m 2.0) (* J_m t_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 t_0 = cos((K / 2.0));
return J_s * (-2.0 * (t_0 * (J_m * hypot(1.0, ((U_m / 2.0) / (J_m * t_0))))));
}
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));
return J_s * (-2.0 * (t_0 * (J_m * Math.hypot(1.0, ((U_m / 2.0) / (J_m * t_0))))));
}
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)) return J_s * (-2.0 * (t_0 * (J_m * math.hypot(1.0, ((U_m / 2.0) / (J_m * t_0))))))
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)) return Float64(J_s * Float64(-2.0 * Float64(t_0 * Float64(J_m * hypot(1.0, Float64(Float64(U_m / 2.0) / Float64(J_m * t_0))))))) 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) t_0 = cos((K / 2.0)); tmp = J_s * (-2.0 * (t_0 * (J_m * hypot(1.0, ((U_m / 2.0) / (J_m * t_0)))))); 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 * 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]), $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 \left(-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)\right)
\end{array}
\end{array}
Initial program 76.7%
associate-*l*76.7%
associate-*l*76.7%
*-commutative76.7%
unpow276.7%
sqr-neg76.7%
distribute-frac-neg76.7%
distribute-frac-neg76.7%
unpow276.7%
Simplified89.2%
Final simplification89.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 8.2e-100)
(* -2.0 (* U_m 0.5))
(* -2.0 (* (* J_m (cos (/ K 2.0))) (hypot 1.0 (* U_m (/ 0.5 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 <= 8.2e-100) {
tmp = -2.0 * (U_m * 0.5);
} else {
tmp = -2.0 * ((J_m * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / 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 tmp;
if (J_m <= 8.2e-100) {
tmp = -2.0 * (U_m * 0.5);
} else {
tmp = -2.0 * ((J_m * Math.cos((K / 2.0))) * Math.hypot(1.0, (U_m * (0.5 / 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 <= 8.2e-100: tmp = -2.0 * (U_m * 0.5) else: tmp = -2.0 * ((J_m * math.cos((K / 2.0))) * math.hypot(1.0, (U_m * (0.5 / 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 <= 8.2e-100) tmp = Float64(-2.0 * Float64(U_m * 0.5)); else tmp = Float64(-2.0 * Float64(Float64(J_m * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U_m * Float64(0.5 / 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 <= 8.2e-100) tmp = -2.0 * (U_m * 0.5); else tmp = -2.0 * ((J_m * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / 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[LessEqual[J$95$m, 8.2e-100], N[(-2.0 * N[(U$95$m * 0.5), $MachinePrecision]), $MachinePrecision], 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]]), $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 8.2 \cdot 10^{-100}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;-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)\\
\end{array}
\end{array}
if J < 8.1999999999999998e-100Initial program 69.9%
associate-*l*69.9%
associate-*l*69.9%
*-commutative69.9%
unpow269.9%
sqr-neg69.9%
distribute-frac-neg69.9%
distribute-frac-neg69.9%
unpow269.9%
Simplified84.7%
Taylor expanded in J around 0 25.9%
if 8.1999999999999998e-100 < J Initial program 89.3%
associate-*l*89.3%
associate-*l*89.3%
unpow289.3%
sqr-neg89.3%
distribute-frac-neg89.3%
distribute-frac-neg89.3%
unpow289.3%
Simplified97.7%
Taylor expanded in K around 0 82.0%
associate-*r/82.0%
*-commutative82.0%
associate-*r/81.9%
Simplified81.9%
Final simplification45.4%
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 540000000000.0)
(* -2.0 (* J_m (cos (/ K 2.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 tmp;
if (U_m <= 540000000000.0) {
tmp = -2.0 * (J_m * cos((K / 2.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.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 (u_m <= 540000000000.0d0) then
tmp = (-2.0d0) * (j_m * cos((k / 2.0d0)))
else
tmp = (-2.0d0) * (u_m * 0.5d0)
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 (U_m <= 540000000000.0) {
tmp = -2.0 * (J_m * Math.cos((K / 2.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): tmp = 0 if U_m <= 540000000000.0: tmp = -2.0 * (J_m * math.cos((K / 2.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) tmp = 0.0 if (U_m <= 540000000000.0) tmp = Float64(-2.0 * Float64(J_m * cos(Float64(K / 2.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) tmp = 0.0; if (U_m <= 540000000000.0) tmp = -2.0 * (J_m * cos((K / 2.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_] := N[(J$95$s * If[LessEqual[U$95$m, 540000000000.0], N[(-2.0 * N[(J$95$m * N[Cos[N[(K / 2.0), $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)
\\
J_s \cdot \begin{array}{l}
\mathbf{if}\;U_m \leq 540000000000:\\
\;\;\;\;-2 \cdot \left(J_m \cdot \cos \left(\frac{K}{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\end{array}
\end{array}
if U < 5.4e11Initial program 82.2%
associate-*l*82.2%
associate-*l*82.2%
*-commutative82.2%
unpow282.2%
sqr-neg82.2%
distribute-frac-neg82.2%
distribute-frac-neg82.2%
unpow282.2%
Simplified92.4%
Taylor expanded in J around inf 61.8%
if 5.4e11 < U Initial program 56.1%
associate-*l*56.1%
associate-*l*56.1%
*-commutative56.1%
unpow256.1%
sqr-neg56.1%
distribute-frac-neg56.1%
distribute-frac-neg56.1%
unpow256.1%
Simplified77.2%
Taylor expanded in J around 0 37.8%
Final simplification56.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 (* J_s (if (<= U_m 6.6e-42) (* -2.0 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.6e-42) {
tmp = -2.0 * 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.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 (u_m <= 6.6d-42) then
tmp = (-2.0d0) * j_m
else
tmp = (-2.0d0) * (u_m * 0.5d0)
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 (U_m <= 6.6e-42) {
tmp = -2.0 * 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.6e-42: tmp = -2.0 * 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.6e-42) tmp = Float64(-2.0 * 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.6e-42) tmp = -2.0 * 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.6e-42], N[(-2.0 * J$95$m), $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.6 \cdot 10^{-42}:\\
\;\;\;\;-2 \cdot J_m\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(U_m \cdot 0.5\right)\\
\end{array}
\end{array}
if U < 6.6000000000000005e-42Initial program 82.4%
associate-*l*82.4%
associate-*l*82.4%
*-commutative82.4%
unpow282.4%
sqr-neg82.4%
distribute-frac-neg82.4%
distribute-frac-neg82.4%
unpow282.4%
Simplified91.9%
Taylor expanded in J around inf 61.9%
Taylor expanded in K around 0 37.6%
if 6.6000000000000005e-42 < U Initial program 60.8%
associate-*l*60.8%
associate-*l*60.8%
*-commutative60.8%
unpow260.8%
sqr-neg60.8%
distribute-frac-neg60.8%
distribute-frac-neg60.8%
unpow260.8%
Simplified81.8%
Taylor expanded in J around 0 32.1%
Final simplification36.1%
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 76.7%
associate-*l*76.7%
associate-*l*76.7%
*-commutative76.7%
unpow276.7%
sqr-neg76.7%
distribute-frac-neg76.7%
distribute-frac-neg76.7%
unpow276.7%
Simplified89.2%
Taylor expanded in J around inf 53.8%
Taylor expanded in K around 0 32.7%
Final simplification32.7%
herbie shell --seed 2023337
(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)))))