Hot answers tagged

8

I think an acceptable solution is to Thread over Alternatives: Basic solution: SetAttributes[f, Flat]; f[a, b, c] /. Thread[f[a, f[b, c] | other], Alternatives] -> post post Though, it won't be very helpful in more complex situations: f[a | b, f[b, c | h]]. General solution (experimental) tupplesOver[ f[a | g, f[b, c | h] | other], ...


6

The two examples in this question relate to two different aspects of pattern matching. I will start with the simpler to understand and intentional aspect, which is the second example. g[2] /. g[ 1 + (1|other) ] -> post (* g[2] *) In the above, the pattern doesn't match, and it can never match. g[2] has one argument. Since Plus is OneIdentity, 2 ...


4

It's not entirely well defined due to handling of numbers, but the following should be at least close to what's wanted. poly1 = 1/64 (3 c^2 e - f^2 - x) (c^2 (4 e + b^2 g) - 4 (f^2 + x))^2 (c^2 (4 e + (a^2 + b^2) g) - 4 (f^2 + x)); poly2 = -(1/64) (b^2 c^2 - 4 x)^2 (a^2 c^2 + b^2 c^2 - 4 x) x; poly3 = x^42 (-(1/2) c^2 d^2 + x)^6; ...


4

Personally, I find this behavior somewhat surprising -- in particular, I would intuitively expect the following patterns to be completely equivalent: somePattern[..., a|b, ...] somePattern[..., a, ...] | somePattern[..., b, ...] While that may seem a natural expectation I do not believe the documentation ever states that they are. Nowhere can I ...


3

After discussing with Kuba, I conjecture the following: Patterns involving alternatives are not evaluated further when attempting to match each alternative That is, somePattern[..., a|b, ...] originally evaluates as if a|b is a black box. Then, during pattern matching, the pattern does not evaluate any further when a|b is replaced by a and b in turn. To ...


3

You have your expression expression = x^2 (6 (2 c1 x^6 + c2)/x^4) - x (4 c1 x^3 - 2 c2/x^3) - 8 (c1 x^4 + c2/x^2) (* -x (-((2 c2)/x^3) + 4 c1 x^3) - 8 (c2/x^2 + c1 x^4) + ( 6 (c2 + 2 c1 x^6))/x^2 *) for now it hasn't been evaluated to zero yet, but if you try most anything it will do so: Expand@expression Series[expression, {c1, 0, 2}] ...


2

I generalize Jason B's answer to group by like terms in any number of coefficients, as well as in cases where you have polynomials multiplying one another: It sounds like you mostly want Plus to keep from evaluating. You can do this by replacing Plus with plus, where plus is a Flat function (since we might as well keep associativity of addition) ...


1

Try fulleq=Append[eqnsMain, eqnsAdd]; And then Eliminate[fulleq, c] Using the {} parenthesis to fuse them would require Flatten on the result, as Mathematica will combine the vectors, not their components.



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