Example #1
0
def proofll(ifthen, reductors, redsb=True, prot=True):

    if prot and (not ifthen.supposedToBeValid):
        print "THIS THEOREM IS NOT SUPPOSED TO BE VALID"
    ip_pre = ifthen.ifpart
    ip = []

    for p in ip_pre:
        p = Polynomial(p)
        if p.is_zero():
            continue
        li = list(p.lead().variables())
        if len(li) == 1 and (not (li[0] in list(
                Polynomial(reductors).lead().variables()))):
            assert not Polynomial(reductors).is_zero()
            lead_index = li[0]
            if redsb:
                p = ll_red_nf_redsb(p, reductors)
                reductors = ll_red_nf_redsb(Polynomial(reductors),
                                            BooleSet(p.set()))

            p_nav = p.navigation()
            reductors = recursively_insert(p_nav.else_branch(), p_nav.value(),
                                           reductors)
        else:
            ip.append(p)
    it = ifthen.thenpart
    if prot:
        print "proofing:", ifthen
    ip = logicaland(ip)
    for c in it:
        if prot:
            print "proofing part:", c
        c = logicalor([BooleConstant(1) + ip, c])

        if c.is_zero():
            if prot:
                print "TRUE (trivial)"
            return True
        else:
            c_orig = c
            if redsb:
                c = ll_red_nf_redsb(c, reductors)
            else:
                c = ll_red_nf_noredsb(c, reductors)
            if c.is_zero():
                if prot:
                    print "TRUE"
                return True
            else:
                if prot:
                    print "FAILED"
                    print "can construct COUNTER EXAMPLE with:", find_one(c)
                return False
def proofll(ifthen,reductors,redsb=True,prot=True):
  
  if prot and (not ifthen.supposedToBeValid):
      print "THIS THEOREM IS NOT SUPPOSED TO BE VALID"
  ip_pre=ifthen.ifpart
  ip=[]

  for p in ip_pre:
    p=Polynomial(p)
    if p.is_zero(): continue
    li=list(p.lead().variables())
    if len(li)==1 and (not (li[0] in list(Polynomial(reductors).lead().variables()))):
      assert not Polynomial(reductors).is_zero()
      lead_index=li[0]
      if redsb:
          p=ll_red_nf_redsb(p,reductors)
          reductors=ll_red_nf_redsb(Polynomial(reductors),BooleSet(p.set()))

      
      p_nav=p.navigation()
      reductors=recursively_insert(p_nav.else_branch(),p_nav.value(),reductors)
    else:
      ip.append(p)
  it=ifthen.thenpart
  if prot:
      print "proofing:", ifthen
  ip=logicaland(ip)
  for c in it:
    if prot:
        print "proofing part:",c
    c=logicalor([BooleConstant(1)+ip,c])

    if c.is_zero():
      if prot:
         print "TRUE (trivial)"
      return True
    else:
      c_orig=c
      if redsb:
          c=ll_red_nf_redsb(c,reductors)
      else:
          c=ll_red_nf_noredsb(c,reductors)
      if c.is_zero():
        if prot:
            print "TRUE"
        return True
      else:
        if prot:
            print "FAILED"
            print "can construct COUNTER EXAMPLE with:", find_one(c)
        return False
def gen_random_poly(ring, l,deg,vars_set,seed=123):

    myrange=vars_set
    r=Random(seed)
    def helper(samples):
        if samples==0:
            return Polynomial(ring.zero())
        if samples==1:
            d=r.randint(0,deg)
            variables=r.sample(myrange,d)
            m=Monomial(ring)
            for v in sorted(set(variables),reverse=True):
                m=m*Variable(v, ring)
            return Polynomial(m)
        assert samples>=2
        return helper(samples/2)+helper(samples-samples/2)
    p=Polynomial(ring.zero())
    while(len(p)<l):
        p=Polynomial(p.set().union(helper(l-len(p)).set()))
    return p