Example #1
0
def knuth():

    dig = DIG('../invgen/Traces/NLA/knuth.tcs')
    rs = dig.getInvs(inv_typ='eqt', seed=0, vs=dig.vs, deg=3)
    assert list_str(
        rs
    ) == '-k^2*t + k*t^2 == 0, 1/8*d^2*q + 1/2*d*k - 1/4*d*q - 1/2*d*rvu - nvu + rvu == 0, -k^2*t + t^3 == 0', rs
Example #2
0
    def rem_dup_arrs(ps, ainfo):
        """
        Remove relations that involve elements from same arrays

        Examples:

        sage: var('x_0 x_1 y_0 y_1')
        (x_0, x_1, y_0, y_1)
        sage: ainfo = {x_0:{'name':'x','idxs':[0]},x_1:{'name':'x','idxs':[1]}, y_0:{'name':'y','idxs':[0]},y_1:{'name':'y','idxs':[1]}}
        sage: FlatArray.rem_dup_arrs([x_0 + x_1 == 0, x_1 + y_1 == 0, x_0 + y_1 + y_0==0, x_0 + x_1-2==0], ainfo)
        dig_arrays:Warn:Removed 3 array eqts
        x_0 + x_1 == 0
        x_0 + y_0 + y_1 == 0
        x_0 + x_1 - 2 == 0
        [x_1 + y_1 == 0]

        
        """
        get_anames = lambda p: [ainfo[v]['name'] for v in get_vars(p)]
        ps_rem, ps = vpartition(ps, lambda p: vall_uniq(get_anames(p)))
        
        if not is_empty(ps_rem):
            logger.warn('Removed {} array eqts\n{}'
                        .format(len(ps_rem), list_str(ps_rem,'\n')))

            
        return ps
Example #3
0
    def modify_arr_eqts(ps, ainfo):
        """
        Shortcut to modify/format eqts
        """
        ps_old = set(map(str,ps))
        ps = [Miscs.elim_denom(p) for p in ps] #Eliminating denominators if exist
        ps = FlatArray.modify_signs(ps)
                
        if set(map(str,ps)) != ps_old:
            logger.warn('Some rels were modifed\n{}'.format(list_str(ps,'\n')))

        
        return ps
Example #4
0
    def genTemplate(name,d):
        if name == 'coef':
            assert(len(d.values())==1)
            coefVal = d.values()[0]
            template = None if coefVal == 0 else '(%s)'%str(coefVal)
        else:
            idxVals= ['[%s]'%d[name+str(idx)] for idx in srange(len(d)-1)]
            if d['coef'] == -1:
                coefStr = '-'
            elif d['coef'] == 1:
                coefStr = ''
            else:
                coefStr = "({}) *".format(d['coef'])

            template = '(%s%s%s)'%(coefStr,name,list_str(idxVals,''))

        return template
Example #5
0
        def compute_traces(aname, acontents, ainfo, tsinfo):
            vi = Miscs.travel(acontents)
            vals = Miscs.getVals(vi)
            idxs = Miscs.getIdxs(vi)
            aname = str(aname)
            newvars = [var(aname + '_' + list_str(idx, '_')) for idx in idxs]

            if aname not in tsinfo:
                tsinfo[aname] = newvars
            else:
                assert tsinfo[aname] == newvars
            
            dVals = dict(zip(newvars,vals)) #{A_0_0_1:'w'}
            for nv,idx in zip(newvars,idxs):
                if nv not in ainfo:
                    idx_ = zip([var('{}{}'.format(aname,li))
                                 for li in srange(len(idx))],idx)
                    ainfo[nv]={'name':aname, 'idx_':idx_}

            return dVals
Example #6
0
def sqrt1():
    dig = DIG('../invgen/Traces/NLA/sqrt1.tcs')
    rs = dig.getInvs(inv_typ='eqt', seed=0, vs=dig.vs, deg=2)
    assert list_str(
        rs
    ) == '-1/4*t^2 - a + s - 3/4 == 0, -2*a + t - 1 == 0, 1/4*t^2 + a - nvu + 3/4 <= 0', rs
Example #7
0
def knuth():


    dig = DIG('../invgen/Traces/NLA/knuth.tcs')
    rs = dig.getInvs(inv_typ='eqt', seed=0, vs=dig.vs, deg=3)
    assert list_str(rs) =='-k^2*t + k*t^2 == 0, 1/8*d^2*q + 1/2*d*k - 1/4*d*q - 1/2*d*rvu - nvu + rvu == 0, -k^2*t + t^3 == 0', rs
Example #8
0
def sqrt1():
    dig = DIG('../invgen/Traces/NLA/sqrt1.tcs')
    rs = dig.getInvs(inv_typ='eqt', seed=0, vs=dig.vs, deg=2)
    assert list_str(rs) == '-1/4*t^2 - a + s - 3/4 == 0, -2*a + t - 1 == 0, 1/4*t^2 + a - nvu + 3/4 <= 0', rs