
(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 #s(literal 1 binary64) 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)
(sqrt (+ 1.0 (pow (/ U_m (* t_0 (* J_m 2.0))) 2.0))))))
(*
J_s
(if (<= t_1 (- INFINITY))
(- U_m)
(if (<= t_1 2e+303)
(*
(* J_m (* -2.0 t_0))
(hypot 1.0 (* 0.5 (/ U_m (* J_m (cos (* K 0.5)))))))
U_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) * sqrt((1.0 + pow((U_m / (t_0 * (J_m * 2.0))), 2.0)));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = -U_m;
} else if (t_1 <= 2e+303) {
tmp = (J_m * (-2.0 * t_0)) * hypot(1.0, (0.5 * (U_m / (J_m * cos((K * 0.5))))));
} else {
tmp = U_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) * Math.sqrt((1.0 + Math.pow((U_m / (t_0 * (J_m * 2.0))), 2.0)));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = -U_m;
} else if (t_1 <= 2e+303) {
tmp = (J_m * (-2.0 * t_0)) * Math.hypot(1.0, (0.5 * (U_m / (J_m * Math.cos((K * 0.5))))));
} else {
tmp = U_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) * math.sqrt((1.0 + math.pow((U_m / (t_0 * (J_m * 2.0))), 2.0))) tmp = 0 if t_1 <= -math.inf: tmp = -U_m elif t_1 <= 2e+303: tmp = (J_m * (-2.0 * t_0)) * math.hypot(1.0, (0.5 * (U_m / (J_m * math.cos((K * 0.5)))))) else: tmp = U_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(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_1 <= Float64(-Inf)) tmp = Float64(-U_m); elseif (t_1 <= 2e+303) tmp = Float64(Float64(J_m * Float64(-2.0 * t_0)) * hypot(1.0, Float64(0.5 * Float64(U_m / Float64(J_m * cos(Float64(K * 0.5))))))); else tmp = U_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) * sqrt((1.0 + ((U_m / (t_0 * (J_m * 2.0))) ^ 2.0))); tmp = 0.0; if (t_1 <= -Inf) tmp = -U_m; elseif (t_1 <= 2e+303) tmp = (J_m * (-2.0 * t_0)) * hypot(1.0, (0.5 * (U_m / (J_m * cos((K * 0.5)))))); else tmp = U_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[(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$1, (-Infinity)], (-U$95$m), If[LessEqual[t$95$1, 2e+303], N[(N[(J$95$m * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / N[(J$95$m * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], U$95$m]]), $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 := \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\_1 \leq -\infty:\\
\;\;\;\;-U\_m\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+303}:\\
\;\;\;\;\left(J\_m \cdot \left(-2 \cdot t\_0\right)\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J\_m \cdot \cos \left(K \cdot 0.5\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;U\_m\\
\end{array}
\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.7%
Simplified55.5%
Taylor expanded in J around 0 61.4%
neg-mul-161.4%
Simplified61.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))))) < 2e303Initial program 99.8%
*-commutative99.8%
associate-*l*99.8%
unpow299.8%
hypot-1-def99.8%
associate-/r*99.7%
cos-neg99.7%
distribute-frac-neg99.7%
associate-/r*99.8%
associate-/r*99.7%
*-commutative99.7%
distribute-frac-neg99.7%
cos-neg99.7%
Simplified99.7%
Taylor expanded in K around inf 77.2%
associate-*r/77.2%
*-commutative77.2%
unpow277.2%
*-commutative77.2%
unpow277.2%
sqr-neg77.2%
swap-sqr77.3%
unpow277.3%
metadata-eval77.3%
swap-sqr77.3%
times-frac99.8%
hypot-1-def99.8%
Simplified99.8%
if 2e303 < (*.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 7.6%
Simplified57.9%
Taylor expanded in U around -inf 45.3%
Final simplification84.0%
U_m = (fabs.f64 U)
J\_m = (fabs.f64 J)
J\_s = (copysign.f64 #s(literal 1 binary64) J)
(FPCore (J_s J_m K U_m)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(*
J_s
(if (<= U_m 4.8e+169)
(* J_m (* (* -2.0 t_0) (hypot 1.0 (/ (/ U_m 2.0) (* J_m t_0)))))
(- U_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 tmp;
if (U_m <= 4.8e+169) {
tmp = J_m * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J_m * t_0))));
} else {
tmp = -U_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 tmp;
if (U_m <= 4.8e+169) {
tmp = J_m * ((-2.0 * t_0) * Math.hypot(1.0, ((U_m / 2.0) / (J_m * t_0))));
} else {
tmp = -U_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)) tmp = 0 if U_m <= 4.8e+169: tmp = J_m * ((-2.0 * t_0) * math.hypot(1.0, ((U_m / 2.0) / (J_m * t_0)))) else: tmp = -U_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)) tmp = 0.0 if (U_m <= 4.8e+169) tmp = Float64(J_m * Float64(Float64(-2.0 * t_0) * hypot(1.0, Float64(Float64(U_m / 2.0) / Float64(J_m * t_0))))); else tmp = Float64(-U_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)); tmp = 0.0; if (U_m <= 4.8e+169) tmp = J_m * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J_m * t_0)))); else tmp = -U_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]}, N[(J$95$s * If[LessEqual[U$95$m, 4.8e+169], N[(J$95$m * N[(N[(-2.0 * t$95$0), $MachinePrecision] * 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], (-U$95$m)]), $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 4.8 \cdot 10^{+169}:\\
\;\;\;\;J\_m \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J\_m \cdot t\_0}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-U\_m\\
\end{array}
\end{array}
\end{array}
if U < 4.7999999999999997e169Initial program 74.1%
Simplified90.8%
if 4.7999999999999997e169 < U Initial program 36.5%
Simplified52.3%
Taylor expanded in J around 0 38.2%
neg-mul-138.2%
Simplified38.2%
Final simplification83.6%
U_m = (fabs.f64 U)
J\_m = (fabs.f64 J)
J\_s = (copysign.f64 #s(literal 1 binary64) J)
(FPCore (J_s J_m K U_m)
:precision binary64
(*
J_s
(if (<= J_m 4.8e-201)
(- U_m)
(if (<= J_m 7.8e-190)
U_m
(if (<= J_m 1.6e-108) (- U_m) (* (* -2.0 J_m) (cos (* K 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 (J_m <= 4.8e-201) {
tmp = -U_m;
} else if (J_m <= 7.8e-190) {
tmp = U_m;
} else if (J_m <= 1.6e-108) {
tmp = -U_m;
} else {
tmp = (-2.0 * J_m) * cos((K * 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 (j_m <= 4.8d-201) then
tmp = -u_m
else if (j_m <= 7.8d-190) then
tmp = u_m
else if (j_m <= 1.6d-108) then
tmp = -u_m
else
tmp = ((-2.0d0) * j_m) * cos((k * 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 (J_m <= 4.8e-201) {
tmp = -U_m;
} else if (J_m <= 7.8e-190) {
tmp = U_m;
} else if (J_m <= 1.6e-108) {
tmp = -U_m;
} else {
tmp = (-2.0 * J_m) * Math.cos((K * 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 J_m <= 4.8e-201: tmp = -U_m elif J_m <= 7.8e-190: tmp = U_m elif J_m <= 1.6e-108: tmp = -U_m else: tmp = (-2.0 * J_m) * math.cos((K * 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 (J_m <= 4.8e-201) tmp = Float64(-U_m); elseif (J_m <= 7.8e-190) tmp = U_m; elseif (J_m <= 1.6e-108) tmp = Float64(-U_m); else tmp = Float64(Float64(-2.0 * J_m) * cos(Float64(K * 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 (J_m <= 4.8e-201) tmp = -U_m; elseif (J_m <= 7.8e-190) tmp = U_m; elseif (J_m <= 1.6e-108) tmp = -U_m; else tmp = (-2.0 * J_m) * cos((K * 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[J$95$m, 4.8e-201], (-U$95$m), If[LessEqual[J$95$m, 7.8e-190], U$95$m, If[LessEqual[J$95$m, 1.6e-108], (-U$95$m), N[(N[(-2.0 * J$95$m), $MachinePrecision] * N[Cos[N[(K * 0.5), $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 4.8 \cdot 10^{-201}:\\
\;\;\;\;-U\_m\\
\mathbf{elif}\;J\_m \leq 7.8 \cdot 10^{-190}:\\
\;\;\;\;U\_m\\
\mathbf{elif}\;J\_m \leq 1.6 \cdot 10^{-108}:\\
\;\;\;\;-U\_m\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot J\_m\right) \cdot \cos \left(K \cdot 0.5\right)\\
\end{array}
\end{array}
if J < 4.80000000000000018e-201 or 7.7999999999999999e-190 < J < 1.6e-108Initial program 61.0%
Simplified79.7%
Taylor expanded in J around 0 35.2%
neg-mul-135.2%
Simplified35.2%
if 4.80000000000000018e-201 < J < 7.7999999999999999e-190Initial program 32.5%
Simplified73.4%
Taylor expanded in U around -inf 30.7%
if 1.6e-108 < J Initial program 88.5%
Simplified98.6%
Taylor expanded in J around inf 68.0%
associate-*r*68.0%
*-commutative68.0%
*-commutative68.0%
*-commutative68.0%
*-commutative68.0%
*-commutative68.0%
Simplified68.0%
Final simplification45.4%
U_m = (fabs.f64 U)
J\_m = (fabs.f64 J)
J\_s = (copysign.f64 #s(literal 1 binary64) J)
(FPCore (J_s J_m K U_m)
:precision binary64
(*
J_s
(if (<= U_m 3e-92)
(* (* -2.0 J_m) (cos (* K 0.5)))
(if (<= U_m 5.3e+65)
(* (* -2.0 J_m) (hypot 1.0 (* 0.5 (/ U_m J_m))))
(- U_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 (U_m <= 3e-92) {
tmp = (-2.0 * J_m) * cos((K * 0.5));
} else if (U_m <= 5.3e+65) {
tmp = (-2.0 * J_m) * hypot(1.0, (0.5 * (U_m / J_m)));
} else {
tmp = -U_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 (U_m <= 3e-92) {
tmp = (-2.0 * J_m) * Math.cos((K * 0.5));
} else if (U_m <= 5.3e+65) {
tmp = (-2.0 * J_m) * Math.hypot(1.0, (0.5 * (U_m / J_m)));
} else {
tmp = -U_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 U_m <= 3e-92: tmp = (-2.0 * J_m) * math.cos((K * 0.5)) elif U_m <= 5.3e+65: tmp = (-2.0 * J_m) * math.hypot(1.0, (0.5 * (U_m / J_m))) else: tmp = -U_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 (U_m <= 3e-92) tmp = Float64(Float64(-2.0 * J_m) * cos(Float64(K * 0.5))); elseif (U_m <= 5.3e+65) tmp = Float64(Float64(-2.0 * J_m) * hypot(1.0, Float64(0.5 * Float64(U_m / J_m)))); else tmp = Float64(-U_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 (U_m <= 3e-92) tmp = (-2.0 * J_m) * cos((K * 0.5)); elseif (U_m <= 5.3e+65) tmp = (-2.0 * J_m) * hypot(1.0, (0.5 * (U_m / J_m))); else tmp = -U_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[U$95$m, 3e-92], N[(N[(-2.0 * J$95$m), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 5.3e+65], N[(N[(-2.0 * J$95$m), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J$95$m), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], (-U$95$m)]]), $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 3 \cdot 10^{-92}:\\
\;\;\;\;\left(-2 \cdot J\_m\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{elif}\;U\_m \leq 5.3 \cdot 10^{+65}:\\
\;\;\;\;\left(-2 \cdot J\_m\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;-U\_m\\
\end{array}
\end{array}
if U < 3.00000000000000013e-92Initial program 77.1%
Simplified92.0%
Taylor expanded in J around inf 58.6%
associate-*r*58.6%
*-commutative58.6%
*-commutative58.6%
*-commutative58.6%
*-commutative58.6%
*-commutative58.6%
Simplified58.6%
if 3.00000000000000013e-92 < U < 5.30000000000000022e65Initial program 76.4%
*-commutative76.4%
associate-*l*76.4%
unpow276.4%
hypot-1-def99.8%
associate-/r*99.8%
cos-neg99.8%
distribute-frac-neg99.8%
associate-/r*99.8%
associate-/r*99.8%
*-commutative99.8%
distribute-frac-neg99.8%
cos-neg99.8%
Simplified99.8%
Taylor expanded in K around 0 64.0%
Taylor expanded in K around 0 77.3%
if 5.30000000000000022e65 < U Initial program 40.7%
Simplified58.8%
Taylor expanded in J around 0 39.6%
neg-mul-139.6%
Simplified39.6%
Final simplification56.5%
U_m = (fabs.f64 U)
J\_m = (fabs.f64 J)
J\_s = (copysign.f64 #s(literal 1 binary64) J)
(FPCore (J_s J_m K U_m)
:precision binary64
(*
J_s
(if (or (<= U_m 3.9e-66) (and (not (<= U_m 4.6e+32)) (<= U_m 5.2e+57)))
(* -2.0 J_m)
(- U_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 ((U_m <= 3.9e-66) || (!(U_m <= 4.6e+32) && (U_m <= 5.2e+57))) {
tmp = -2.0 * J_m;
} else {
tmp = -U_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 ((u_m <= 3.9d-66) .or. (.not. (u_m <= 4.6d+32)) .and. (u_m <= 5.2d+57)) then
tmp = (-2.0d0) * j_m
else
tmp = -u_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 ((U_m <= 3.9e-66) || (!(U_m <= 4.6e+32) && (U_m <= 5.2e+57))) {
tmp = -2.0 * J_m;
} else {
tmp = -U_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 (U_m <= 3.9e-66) or (not (U_m <= 4.6e+32) and (U_m <= 5.2e+57)): tmp = -2.0 * J_m else: tmp = -U_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 ((U_m <= 3.9e-66) || (!(U_m <= 4.6e+32) && (U_m <= 5.2e+57))) tmp = Float64(-2.0 * J_m); else tmp = Float64(-U_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 ((U_m <= 3.9e-66) || (~((U_m <= 4.6e+32)) && (U_m <= 5.2e+57))) tmp = -2.0 * J_m; else tmp = -U_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[U$95$m, 3.9e-66], And[N[Not[LessEqual[U$95$m, 4.6e+32]], $MachinePrecision], LessEqual[U$95$m, 5.2e+57]]], N[(-2.0 * J$95$m), $MachinePrecision], (-U$95$m)]), $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 3.9 \cdot 10^{-66} \lor \neg \left(U\_m \leq 4.6 \cdot 10^{+32}\right) \land U\_m \leq 5.2 \cdot 10^{+57}:\\
\;\;\;\;-2 \cdot J\_m\\
\mathbf{else}:\\
\;\;\;\;-U\_m\\
\end{array}
\end{array}
if U < 3.89999999999999983e-66 or 4.5999999999999999e32 < U < 5.2e57Initial program 77.7%
*-commutative77.7%
associate-*l*77.7%
unpow277.7%
hypot-1-def92.4%
associate-/r*92.4%
cos-neg92.4%
distribute-frac-neg92.4%
associate-/r*92.4%
associate-/r*92.4%
*-commutative92.4%
distribute-frac-neg92.4%
cos-neg92.4%
Simplified92.4%
Taylor expanded in K around 0 54.5%
Taylor expanded in J around inf 38.0%
if 3.89999999999999983e-66 < U < 4.5999999999999999e32 or 5.2e57 < U Initial program 48.5%
Simplified69.4%
Taylor expanded in J around 0 38.7%
neg-mul-138.7%
Simplified38.7%
Final simplification38.2%
U_m = (fabs.f64 U) J\_m = (fabs.f64 J) J\_s = (copysign.f64 #s(literal 1 binary64) J) (FPCore (J_s J_m K U_m) :precision binary64 (* J_s (- U_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 * -U_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 * -u_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 * -U_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 * -U_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(-U_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 * -U_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 * (-U$95$m)), $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(-U\_m\right)
\end{array}
Initial program 68.9%
Simplified85.5%
Taylor expanded in J around 0 30.4%
neg-mul-130.4%
Simplified30.4%
Final simplification30.4%
U_m = (fabs.f64 U) J\_m = (fabs.f64 J) J\_s = (copysign.f64 #s(literal 1 binary64) J) (FPCore (J_s J_m K U_m) :precision binary64 (* J_s U_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 * U_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 * u_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 * U_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 * U_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 * U_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 * U_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 * U$95$m), $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 U\_m
\end{array}
Initial program 68.9%
Simplified85.5%
Taylor expanded in U around -inf 25.5%
Final simplification25.5%
herbie shell --seed 2024078
(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)))))