Simplify in GF(2)
31 views (last 30 days)
Show older comments
Nicolas
on 9 Dec 2024 at 16:28
Commented: Nicolas
on 10 Dec 2024 at 21:35
I have computations that I perform symbolically, but they involve integers modulo 2.
It seems that Matlab does not simplify mod expressions (e.g., mod(sym('x')+2,2) results in mod(x + 2, 2) ; specifying that x is an integer does not change anything). Even assuming my variables are integers between 0 and 1 does not result in simpler expressions. For instance:
syms x;
assume(in(x,"integer") & (x>=0) & (x<=1));
simplify(x*x)
% ans = x^2
% I would expect ans = x
In my expressions where I only work in GF(2) using polynomial expressions recursively on matrices of symbols, I rapidly obtain gigantic expressions that would be trivially simplified (e.g: 2*x^8*y*z + x*y^2 + x^2*y etc. that would here be 0, but my formulas are way longer and I can't do it by hand).
Is-there any way to make Matlab simplify expressions knowing that they involve computations modulo 2 ? I use R2023b.
Thanks !
0 Comments
Accepted Answer
John D'Errico
on 9 Dec 2024 at 17:26
Edited: John D'Errico
on 9 Dec 2024 at 17:39
In the help docs for simplify, we see:
The key word there is ALGEBRAIC.
However, you want it to perform simplification in mod 2 arithmetic. Simplify is not designed to solve that problem. In order for MATLAB to perform what you wish to see, this would require it to evaluate the equivalent of truth tables, over possibly many variables.
Now, could you make that expression simpler?
syms x y z
expr = 2*x^8*y*z + x*y^2 + x^2*y
Knowing that x and x^n are the same for a binary variable x, you could do this:
expr = subs(expr,[x^2 y^2],[x y])
And you could do it again, until you come to something simpler, that you could simplify. But just wanting code to do what it is not designed to do will never work.
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!