Tag Info

Hot answers tagged

4

It can be done with w.a.b.r + w.c.d.r /. Dot[FRONT_, AA__, BACK_] + Dot[FRONT_, BB__, BACK_] :> Dot[FRONT, Dot[AA] + Dot[BB], BACK] w.(a.b + c.d).r However, I like function argument destructuring, so I would probably write f[Dot[w_, a__, r_] + Dot[w_, b__, r_]] := w.(Dot[a] + Dot[b]).r f[w.a.b.r + w.c.d.r] w.(a.b + c.d).r


4

This is indeed somewhat confusing when you are new to Mathematica. In Mathematica, == stands for mathematical equality. Thus a == 0 does not evaluate to either True or to False until a is replaced by a numerical value. a is considered to be a variable that may or may not be zero. A pattern like x_ /; condition will only match if condition is explicitly ...


4

I'm not thrilled with the question since it provided no example, but there was a serious response and also a request to see an ILP approach. Here is one such. Start by creating an example. SeedRandom[1111]; n = 10; m = 4; intset = RandomInteger[100, n] (* Out[335]= {9, 78, 23, 59, 95, 51, 24, 29, 99, 68} *) Now we set up the ILP. We have our n -1/0/1 ...


4

Solution Suppose the list is list = Range[-3, 3] (* {-3, -2, -1, 0, 1, 2, -3} *) Then, the set of all subsets of, say, size 3 is sets = Subsets[list, {3}]; We define a list of signs that give all possible combinations of plusses and minuses to attach to each subset: signs = Tuples[{-1, 1}, 3] (* {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1} ...


3

To answer the question as asked, we modify the code as follows: replacementRule = Plus[ Dot[FRONT__, AA__, BACK__] , Dot[FRONT__, BB__, BACK__] ] :> Dot[FRONT, Plus[Dot[AA], Dot[BB]], BACK]}] w.a.b.r + w.c.d.r /. replacementRule First, we have changed -> (Rule) to :> (RuleDelayed) so that when the expression is re-written, it will write it ...


1

This expression, designated exp for convenience, can be simplified substantially as follows. num = Map[FullSimplify[#] &, Numerator[exp]]; Map[FullSimplify[#, θ[_] ∈ Reals && ϕ[_] ∈ Reals] &, Denominator[exp] /. Abs[z_]^2 :> FullSimplify[Abs[z]^2, θ[_] ∈ Reals && ϕ[_] ∈ Reals]; /. Abs[z_]^2 :> z^2] den = ...



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