[GiNaC-list] operations modulo 2

Kostas Patsakis kpatsak at gmail.com
Wed Jan 4 04:31:09 CET 2006


sorry for bothering the list again but I would appreciate some help.
I'm trying to do operation(addition,multiplications) with multivariate
polynomials. The variables cat take values 0 and 1 and I'm working with
about 30 variables k0,k1...
So since 0^2=0 and 1^1=1
I make the following substistution(written for ginsh) subs(e,$0^$1==$0).
Since 2*x=0 mod 2 I need to do parse all the coeffiients mod 2.
The problem is that even if I expand the expressions ginac(or at least my
code to be honest) does not appear to expand my expressions halting
immediately all my calculations
e.g. this list of expressions is an output that was supposed to have been
expanded and have been reduced mod 2
temp={1+k4+k5,(1+k5)*(1+k4)+k6,(1+k5)*(1+k6)*(1+k4)+k7,(1+k7)*(1+k5)*(1+k6)*(1+k4)+k8,1+k9+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4),1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4)),k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10,1+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10*(1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4)))+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10,k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10*(1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4)))+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10,k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10*(1+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10)*(1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))),k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10*(1+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10)*(1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))),k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10*(1+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10)*(1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))),k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10*(1+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10)*(1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))),1+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10*(1+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))*k10)*(1+k10+k9*(1+(1+k7)*(1+k8)*(1+k5)*(1+k6)*(1+k4))),0,0,1,0,1,0,1,0,0,1,1,1,0,k0,k1,k2,k3,1+k4}
Using ginsh is obvious that this has not happened.
Cutting and pasting code from manual has done some work but not much:(

This is what I've got so far:

const symbol & g_smbl(const string & s){
         static map<string, symbol> directory;
         map<string, symbol>::iterator i = directory.find(s);
         if (i != directory.end())
             return i->second;
         else
             return directory.insert(make_pair(s, symbol(s))).first->second;
}

struct map_rem_quad_evens : public map_function {
        ex var;
        ex tmp,tmp1;
        numeric coeff;

        map_rem_quad_evens(const ex & var_) : var(var_) {}
        ex operator()(const ex & e){
                if (is_a<add>(e))
                        return e.map(*this);
                if (is_a<mul>(e))
                        return e.map(*this);
                else if (is_a<power>(e) && e.op(0).is_equal(var))
                        return e.op(0);
                else if (is_a<numeric>(e)){
                        coeff=ex_to<numeric>(e);
            if (coeff>0) return mod(coeff,2);
            else return e.map(*this);
                }
                else
        return e;
        }
};


ex simpl(const ex & e){
        ex tmp;
        tmp=subs(expand(e),pow(wild(),wild(1))==wild());
        return tmp;
}

ex expr_simpl(const ex & e){

    ex a;
    a=expand(e);
    map_rem_quad_evens rem_quad_evens(g_smbl("k0"));
    a=rem_quad_evens(e);
        a=simpl(a);
        a=rem_quad_evens(e);
    return a;
}

lst expr_simpl(const lst & a){
    int i;
    lst tmp;
    tmp= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
    for (i=0;i<word_len;i++)
        tmp[i]=expr_simpl(a[i]);
    return tmp;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.cebix.net/pipermail/ginac-list/attachments/20060104/474f3a5f/attachment.html


More information about the GiNaC-list mailing list