4
$\begingroup$

I need to work with a variable $u$ such that $u^2 + u + 1 = 0$. I don't want to find a root of the polynomial $u^2 + u + 1$. Rather, I have to work with $u$ symbolically so that a (polynomial) expression in $u$ gets simplified using the equation $u^2 + u + 1 =0$.

For example, let

y = Series[u + 1 + u*x + x^2, {x, 0, 4}]
z = Series[u^2 + u^2*x + x^4, {x, 0, 4}]

Then, I'd expect

SeriesCoefficient[y+z, 0] = 0
SeriesCoefficient[y+z, 1] = -1

Thank you.

$\endgroup$
  • $\begingroup$ I'm a Python/R user, this is unintelligible to me, can you explain without Mathematica jargon please? $\endgroup$ – smci May 14 at 5:51
4
$\begingroup$

You can use Assumptions

assume = u^2 + u + 1 == 0;

y = Series[u + 1 + u*x + x^2, {x, 0, 4}];
z = Series[u^2 + u^2*x + x^4, {x, 0, 4}];

Assuming[assume, SeriesCoefficient[y + z, 0] // Simplify]

(* 0 *)

Assuming[assume, SeriesCoefficient[y + z, 1] // Simplify]

(* -1 *)
$\endgroup$
  • $\begingroup$ With y = Series[u + 1 + x^2, {x, 0, 4}] your method produces u^2 for Assuming[assume, SeriesCoefficient[y + z, 1] // Simplify]. I think the expected result is -1-u. $\endgroup$ – Carl Woll May 13 at 20:26
  • $\begingroup$ @CarlWoll - I do not know what is "expected", but LeafCount /@ {u^2, -1 - u} indicates that u^2 is simpler in the usual sense. $\endgroup$ – Bob Hanlon May 13 at 20:30
5
$\begingroup$

You can give u an UpValues for Power:

u /: u^n_Integer := Block[{u},
    If[n<0,
        PolynomialMod[(-u-1)^-n, 1+u+u^2],
        PolynomialMod[u^n,1+u+u^2]
    ]
]

Then:

y = Series[u + 1 + u x + x^2, {x, 0, 4}];
z = Series[u^2 + u^2 x + x^4,{x, 0, 4}];

and:

y + z //TeXForm

$-x+x^2+x^4+O\left(x^5\right)$

$\endgroup$
  • $\begingroup$ Carl, what does the Block[{u}, ...] do here? I think I'm still confused about the usage of Block. $\endgroup$ – Roman May 13 at 15:46
  • 1
    $\begingroup$ @Roman The Block is needed so that recursion is avoided (preventing evaluation of u^n on the right hand side) $\endgroup$ – Carl Woll May 13 at 16:00
  • $\begingroup$ I get Iteration limit exceeded with $1/u$. $\endgroup$ – Myath May 13 at 17:40
2
$\begingroup$

The simplest methods are usually the best. I suggest

rule = {u^n_ :> {1, u, -1 - u}[[Mod[n, 3] + 1]]};
y + z /. rule

which will do what you want. Also, the following code

Table[u^n, {n, 0, 6}] /. rule

demonstrates that $u^3 = 1$ and the powers of $u$ are periodic with period $3$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.