Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

# Tag Info

10

There are different ways to go about doing this. I'll set UpValues on e for the multiplication of the basis vectors as you've defined them, and I'll use replacement Rules for the simplification of products of vectors expanded in the basis. First of all Unprotect[e] ClearAll@e e /: NonCommutativeMultiply[e[i_], e[j_]] /; i < j := -NonCommutativeMultiply[...

10

You can use ComplexityFunction option to "penalize" the number of terms with a negative sign: cf = (LeafCount[#] + 100 Count[#, _?InternalSyntacticNegativeQ, ∞] &); Simplify[(-2*x^2*(-1 + x^2))/135, ComplexityFunction -> cf] 2/135 x^2 (1 - x^2) As chris noted in comments, this gives an unsatisfactory result for the following example: ...

9

For moduli that are square-free one can use Chinese remaindering on the coefficient lists to get a result valid for the moduli product. cfs[p1_, p2_, x_, p_] := Reverse[CoefficientList[PolynomialGCD[p1, p2, Modulus -> p], x, 1 + Min[Exponent[p1, x], Exponent[p2, x]]]] FromDigits[ ChineseRemainder[ Transpose[{cfs[f[x], g[x], x, 7], cfs[f[x], g[x]...

9

The function NonCommutativeMultiply has too long of a name, so I make a short-hand version of it (NCP stands for non-commutative product): NCP[x___] := NonCommutativeMultiply[x]; Now, here's the code NCP[] := 1 NCP[left___, a, a†, right___] := NCP[left, a†, a, right] + NCP[left, right] NCP[left___, b, b†, right___] := NCP[left, b†, b, right] + NCP[left, ...

8

You get get far by just implementing the linearity rules for the commutator (and that 0 and 1 "escape" the matrix product. The first two aren't strictly needed, but I include them for completeness: commutator[Plus[a_,A__],B_]:=commutator[a,B]+commutator[Plus[A],B] commutator[A_,Plus[b_,B__]]:=commutator[A,b]+commutator[A,Plus[B]] commutator[A_**B_,C_]:=A**...

8

I upvoted the other responses. That said, there is a better way. CoefficientList[ Resultant[x^3 + a2*x^2 + a1*x + a0, y - (x^3 + x + 1), x], y] (* Out= {-1 + 4 a0 - 3 a0^2 + a0^3 - a1 - 2 a0 a1 + 2 a1^2 + a0 a1^2 - a1^3 + a2 + a0 a2 - 2 a0^2 a2 - 3 a1 a2 + 3 a0 a1 a2 + a0 a2^2 - a1 a2^2 + a2^3, 3 - 6 a0 + 3 a0^2 + a1 - 2 a1^2 + a1^3 - 2 a2 - ...

8

Something like this? (F1/F2 /. c/f -> Defer[c/f]) /. aa_*bb_Defer -> Defer[aa]*bb (* Out= c/f (d e)/(g h i k) *) Reordering will require a different operator e.g NonCommutativeMultiply on the rhs of the second replacement rule, and then some further formatting to make it look like ordinary multiplication. --- edit --- Except formatting ...

8

You can use a variation of the idea I gave here: Normal @ Series[ ss /. {f:u1|u2 -> (s f[#1,#2,#3,#4]&)}, {s, 0, 3} ] /. s->1 u2[x, y, z, t]^3 + Derivative[0, 0, 0, 2][u1][x, y, z, t] + (3*λ*Derivative[0, 0, 1, 0][u1][x, y, z, t]^2*Derivative[0, 0, 2, 0][u1][x, y, z, t])/2 + μ*Derivative[0, 0, 2, 0][u2][x, y, z, t]

8

Try this: J /: Power[J, p_Integer?OddQ] := J J /: Power[J, p_Integer?EvenQ] := 1 J^Range[-10, 10] {1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1}

7

Update: it seems this only works in 10.1 and later, but not in 10.0. This works: Assuming[(a | b | c) ∈ Matrices[{d, d}], TensorExpand@Transpose[a.(b + c)]] (* Transpose[b, {2, 1}].Transpose[a, {2, 1}] + Transpose[c, {2, 1}].Transpose[a, {2, 1}] *) We needed to tell Mathematica that a, b and c are square matrices and use TensorExpand. Check here: ...

7

It's clear from the box form of the expression in the notebook you linked that there is a misplaced RowBox wrapping the Mpc together with the right parenthesis that immediately precedes the ^(1/2) power. This is then incorrectly interpreted as Mpc being inside the square root. I have no idea how this RowBox got there, but when I simply highlight this ...

7

Maybe you can use the following: ClearAll[dmydot, mydot] Derivative[ndiff__][mydot][x__] := dmydot[ndiff][x]; dmydot /: Times[f__, dmydot[n1___, 1, n2___][x__]] := mydot @@ MapAt[Times[f] &, {x}, Length[{n1}] + 1] All I'm doing here is pull the inner derivative that came from the chain rule back into the mydot to replace the original entry at that ...

7

Rewriting your definitions slightly poly = (2 x1 x2 x5 x6 y2 (x2 y1 + x3 (y1 + y2)) y3^2 y4 (x5 y5 + x4 (y4 + y5)))/((x2 y2 + x1 (y1 + y2)) (x3 y3 + x2 (y2 + y3))^2 (x4 y3 + x5 (y3 + y4))^2 (x5 y4 + x6 (y4 + y5))); eqns = { K1 == ((x2 y2 + x1 (y1 + y2)) (x3 y3 + x2 (y2 + y3)))/(x2 y2 (x3 y3 + x2 (y2 + y3) + x1 (y1 + y2 + y3))), K2 == (...

7

An easy way to munge equations is to convert them to lists and then convert them back to equations when you are done munging. In your case, like so: eq1 = -2 x + f[x, y[x]] - x^2 y[x]^3 == hy[y[x]]; eq2 = -2 E^(4 y[x]) + f[x, y[x]] - x^2 y[x]^3 == hx[x]; w1 = List @@ eq1; w2 = List @@ eq2; w3 = w1 - w2; eq3 = Equal @@ w3 2 E^(4 y[x]) - 2 x == -hx[x] + ...

7

Here is a simple implementation: Protect[qCO, qDO]; qOperatorQ[expr_] := MatchQ[expr, qCO | qDO | Ket[n_Integer]]; (* take scalars out *) CenterDot[left___, Times[scalar_?NumericQ, op_?qOperatorQ], right___] := Times[ scalar, CenterDot[left, op, right] ]; (* Implement commutation relations *) CenterDot[left___, qDO, qCO, right___] := Plus[ ...

7

How about that -1 + x^(2/3) // ComplexExpand[#, TargetFunctions -> {Re, Im}] & // FullSimplify // Factor // PowerExpand (* (-1 + x^(1/3)) (1 + x^(1/3)) *)

6

Preamble You should be able to adapt this solution to your specific case, but I have taken the liberty of altering your code somewhat and even changing the definitions of some of the matrices. I will explain why I did what I did so that you can alter things to fit with your definitions. Main alterations: Instead of Setting the values of your Subscripted ...

6

By default, Mathematica always differentiates function heads that contain the independent differentiation variables, unless the function head is listed in the "DifferentiationOptions"->"ExcludedFunctions" system options. So, we can get the behavior you want by adding mydot to this list: SetSystemOptions[ "DifferentiationOptions" -> "...

6

I'm going to guess that your actual goal here is to eliminate one of the terms shared by the two equations. In that case, you could also use Eliminate: Eliminate[{eqfhx,eqhy},f[x,y[x]]] $\text{hy}(y(x))-2 e^{4 y(x)}+2 x=\text{hx}(x)$ This doesn't do the subtraction exactly the way you asked for, but usually the goal of such a subtraction is to eliminate ...

6

One should really use commutator rather than Commutator for future-proofing concerns, but I have some bad habits... Clear[Commutator] (* Manually implement the algebra of interest: *) Commutator[L1, L2] = I L3; Commutator[L2, L1] = -I L3; Commutator[L2, L3] = I L1; Commutator[L3, L2] = -I L1; Commutator[L3, L1] = I L2; Commutator[L1, L3] = -I L2; (* ...

6

Use PiecewiseExpand R[a_, b_] := KroneckerDelta[a, b] KroneckerDelta[a, b] // PiecewiseExpand R[a, b] R[a_, b_] := Product[KroneckerDelta[a, b] , {n, 5}] // PiecewiseExpand R[a, b] R[a_, b_] := Product[KroneckerDelta[a, b] , {n, m}] // PiecewiseExpand[#, m > 1] & R[a, b]

6

{a, b} = Pick[r, Element[#, Rationals] & /@ List @@ r, #] & /@ {True, False} {1, Sqrt + Sqrt}

6

abeliannessForcingNumberQ[n_Integer] := And @@ Flatten[{ Table[Not@Divisible[Power @@ p - 1, q], {p, FactorInteger[n]}, {q, First /@ FactorInteger[n]}], Thread[Last /@ FactorInteger[n] <= 2] }] Select[Range, abeliannessForcingNumberQ] (* 2, 3, 4, 5, 7, 9, 11, 13, 15, 17, 19 *) See also A051532.

5

Define the 2 operators whose commutator you wish to derive. I have ignored the dependence on $y$ to simplify the expressions without losing any essential content. op1 = (f[x] Dt[#, {x, 2}] + g[x] Dt[#, x] + h[x] #) &; op2 = (a[x] Dt[#, {x, 2}] + b[x] Dt[#, x] + c[x] #) &; Apply the commutator to a test function $u(x)$, and then separately collect ...

5

For the first part of your question please see a very recent Q&A: "How is + as an infix operator associated with Plus?" There you will find everything about defining operators yourself. For the second part, lets use your definition and bind it to CircleTimes. CircleTimes[a_, b_] := a + a*b + b; Now you can verify some of your assumptions. I use ...

5

As it turns out, there's an (undocumented) function eminently suitable for the task: poly = -1 + x + x^2 - x^4 + x^6 + x^9 - x^10; PolynomialMod[AlgebraPolynomialPowerMod`PolynomialPowerMod[poly, -1, x, x^11 - 1], 32] 5 + 9 x + 6 x^2 + 16 x^3 + 4 x^4 + 15 x^5 + 16 x^6 + 22 x^7 + 20 x^8 + 18 x^9 + 30 x^10 Check the result: PolynomialMod[...

5

Use a Gröbner basis. The idea is to set up an equation for this multiplicative inverse, in a ring where both $x^{11}-1$ and $32$ are zero (that is, $\mathbf Z[x]/(32,x^{11}-1)$). Then unravel that equation using GroebnerBasis to get the variable representing this reciprocal to f in terms of x: f = -1 + x + x^2 - x^4 + x^6 + x^9 - x^10; defpoly = x^11 - 1; ...

5

The following is a hacky way of doing it for finite groups only: quotientGroup[g_, h_] := RightCosetRepresentative[h, #] & /@ GroupElements[g] // DeleteDuplicates

5

Extending Patrick Stevens answer and modifying it somewhat. As an example, I'll use the Quaternions {1, -1, i, -i, j, -j, k, -k} (per our discussion in the comments to his answer) and factor by the normal subgroup {-1, 1}. Warning: if the groups are too big, the following calculations will probably take too much time. To extract a permutation-group ...

5

Represent a string of field operators a[k]$\equiv\hat{a}(k)$ and ad[k]$\equiv\hat{a}^\dagger(k)$sandwiched between the ground state as correlate. Then the definitions that will automate the manipulations is as follows: ClearAll[correlate]; (* Normalization <0|0> = 1 *) correlate[] = 1; (* Commutation relation: [a(k1), a†(k2)] = δ(k1-k2) *) ...

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