1
$\begingroup$

I am dealing with some calculations of integer variables, so I want to define a function $Modu[x]= x \; mod \; 2$ such that $Modu[2x]=0$.

If I directly use $Mod[2k,2]$, the output should still be $Mod[2k,2]$ because here $k$ is just a variable instead of an integer variable.

I tried

Simplify[Mod[2i+i+j,2],{i,j}\[Element]Integers]

but it outputs

Mod[3 i+j,2] 

instead of

Mod[i+j,2]
$\endgroup$
1
  • 1
    $\begingroup$ Try: Modu[k_Integer] = Mod[k, 2]; $\endgroup$ Commented Jun 27 at 19:32

2 Answers 2

2
$\begingroup$

I'm not really sure I completely understand the use-case. Here are two possibilities.

First, a function:

modu[_?EvenQ * _, 2] := 0;
modu[x_, 2] := Mod[x, 2];

modu[2 k, 2]

(* 0 *)

Second way:

Simplify[Mod[2 k, 2], k \[Element] Integers]

(* 0 *)

Or as a function:

modu // ClearAll;
modu[expr_, m_] := 
  Assuming[Integrate`getAllVariables[expr, {}] \[Element] Integers,
   Simplify@Mod[expr, m]
   ];
$\endgroup$
0
1
$\begingroup$

PolynomialMod might suit your needs:

PolynomialMod[3  x + 1, 2]
PolynomialMod[2 x, 2]
PolynomialMod[5 x^2 + 4  x + 3, 2]
PolynomialMod[5 x^4 + 3 x^3 + 7 x^2 + 3, 3]

->

1+x
0
1+ x^2
x^2+ 2 x^4
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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