Tag Info

New answers tagged


Here's a simple method. First, I'll construct an expression that has lots of cross terms: expr = Sum[a[i, j, k] x^i y^j z^k, {i, 0, 4}, {j, 0, 3}, {k, 0, 2}]; Then I'll use CoefficientRules to pull out all the coefficients, Select to keep only those with total order of 1 or less, and then FromCoefficientRules to put it back together again: ...


Due to not having such a framework at hand, I used the following workaround, which allowed me to still shorten some computation time as compared to doing everything by hand. It boils down to having a set of conventions in place for how to write functions of arbitrarily many variables (or vectors or matrices of these). Here is a summary of the main ideas: ...


Perhaps this will work for you: MakeBoxes[Superscript[b_, x_, y__], form_] ^:= ToBoxes[Superscript[b, Row[{x, y}]], form] Example: Sum[Superscript[G, a, b], {a, 1, 2}, {b, 1, 2}] $G^{11}+G^{12}+G^{21}+G^{22}$


This can be a start: ClearAll[fun, $opsPatt]; $opsPatt = Alternatives @@ {Less, Greater, LessEqual, GreaterEqual, Equal, Unequal}; SetAttributes[fun, HoldAll]; fun[code_] := ReleaseHold[ Hold[code] //. { (head : $opsPatt)[x_, y_] :> COperator[head, {x, y}], HoldPattern[Set[lhs_, rhs_]] :> CAssign[lhs, rhs], ...


It seems to me that Denominator helps a lot: fractionQ = Denominator@# =!= 1 &; fractionQ /@ {a/b, 1/a, 1/5, b/2, a, .5} (* {True, True, True, True, False, False} *)


The goal is not so clear for me, but probably something like this can be useful: test = MatchQ[#, HoldPattern[_. _^-1] | _Rational | HoldPattern[_ Rational[1, _]] ] & test /@ {a/b, 1/a, 1/5, a, .5, b/2} {True, True, True, False, False, True} Notice the dot in _., it is crucial for detecting 1/a since there is no Times really.

Top 50 recent answers are included