[GiNaC-list] using modulo and expanding
C.Dams at science.ru.nl
C.Dams at science.ru.nl
Sun Jan 1 15:19:33 CET 2006
Dear Kostas,
Citeren Kostas Patsakis <kpatsak at gmail.com>:
> is there a way to use modulo over an expression?
> for example:
> 3*k1^2+4*k1*k2+1231231*k1 mod 2=
> k1^2+k1
>
> all I really want is to work with polynomials over Z_2
> so with subs I can do subs(a,$1^2=$1)
This does not sound like a good idea. From the above I gather that you do not
want that you substitution gives k1^2 -> k1 but with the substitution given
here you will get this result.
> but some times it's not enough cause I might run into something with power
> more than 2 would subs(a,$1^$2=$1) be enough???
> I'm not using ginsh but c++
> any help???
Try a map function. Something like (not tested, so probably some things are
wrong):
struct Do_mod_2 : public map_function
{ ex operator()(const ex&x)
{ if(is_a<numeric>(x))
return mod(ex_to<numeric>(x),2);
return x.map(*this);
}
};
Do_mod_2 do_mod_2;
You can now use do_mod_2(3*k1^2+4*k1*k2+1231231*k1);
A happy new year!
Chris
More information about the GiNaC-list
mailing list