Tag Info

Hot answers tagged

4

Often, it is desirable to apply Simplify or FullSimplify to parts of an expression and then recombine the parts. A particularly effective function for this purpose is Collect. For instance, Collect[expr, a^2 - b^2, Simplify] (* (4 a^2 - 3 b^2)/(a^2 - b^2)^2 - 8/(b^2 - c^2)^2 *) Although there is no need to use FullSimplifyin this case, it runs faster ...


4

I think the following code will do the trick: Collect[expr, Derivative[_, _][g][_, _]] If you want Mathematica to try to simplify each "coefficient", you can use this version instead: Collect[expr, Derivative[_, _][g][_, _], Simplify] I can't claim full credit for this code — there's an example in the "Scope" section of the documentation for Collect ...


3

I think this is easier to do by working with strings. First write a function that will expand strings of the form "Power(x,k)" where k is an integer in "xx...x" with k - 1 ""s. f[x_, k_] := Module[{i = Abs[ToExpression[k]] - 1}, Nest[StringJoin[#, "*" <> x] &, x, i]] A couple of tests for f. f["s", 2] "s*s" f["ab", "-3"] ...


3

Accepting that in Mathematica -c/y is automatically converted to -1*c*y^-1 and permitting the result shown in Andy's answer I believe we can use a simpler approach, at least for the kind of expression given in example. Define rules that determine how a Times or Power expression should be counted, then use Cases to find all instances in you expression and ...


1

This doesn't give the result you are looking for exactly because it uses the full form of the expression you give it. SetAttributes[countTimes, HoldAll]; countTimes[expr_] := Block[{Times, Power, power, times}, power[a_, b_ /; b > 0] := Nest[times[a, #] &, a, b - 1]; power[a_, b_ /; b < 0] := 1/power[a, -b]; power[a_, 0] := 1; times[a___, ...


1

I believe you want this: Module[{count}, count[__] = 0; # -> #2 <> ToString[++count[##]] & @@@ rules ] {"A2" -> "BO1", "A2" -> "BO2", "A2" -> "BO3", "A2" -> "BO4", "A2" -> "BO5", "A2" -> "BO6", "A2" -> "BO7", "A2" -> "BO8", "A2" -> "BO9", "A2" -> "BO10", "A2" -> "BO11", "A2" -> "BO12", "A2" -> ...



Only top voted, non community-wiki answers of a minimum length are eligible