Beispiel #1
0
 def slow_closure(p):
     '''For a set of partitions p, compute the closure, that is, the set of 
     all partitions respected by all unary ops that respect all partitions in p.  
     This is the old, slower way of computing the closure.'''
     A = BasicPartition.unaryPolymorphismsAlgebra(p)
     print "|ConA| = ", len(A.con().universe())
     AlgebraIO.writeAlgebraFile(A, "/tmp/A.ua")
     return A.con()
Beispiel #2
0
# make a list of the operations we want in the algebra
ops = op0, op1

# construct the algebra
alg = BasicAlgebra("MyAlgebra", 5, ops)

print "Quick check that we constructed an algebra:"
print "   alg.getName() = ", alg.getName()
print "   alg.universe() = ", alg.universe()

import os.path
if os.path.exists("../Algebras"):

    # write the algebra to a UACalc file
    AlgebraIO.writeAlgebraFile(alg, "../Algebras/Example1_ConstructAlgebra.ua")
    print "UACalc algebra file created: ../Algebras/Example1_ConstructAlgebra.ua"

print "\n\n---- Example 2 ----"
print "Constructing an algebra with unary operations defined 'by hand' as vectors."

# The algebra will have universe {0, 1, ..., 7}, and the following unary operations:
f0 = 7, 6, 6, 7, 3, 2, 2, 3
f1 = 0, 1, 1, 0, 4, 5, 5, 4
f2 = 0, 2, 3, 1, 0, 2, 3, 1

# Use the functions above to construct UACalc operations:
op0 = Operation(f0, "f0", 1, 8)
op1 = Operation(f1, "f1", 1, 8)
op2 = Operation(f2, "f2", 1, 8)
# make a list of the operations we want in the algebra
ops = op0, op1

# construct the algebra
alg = BasicAlgebra("MyAlgebra", 5, ops)

print "Quick check that we constructed an algebra:"
print "   alg.getName() = ", alg.getName()        
print "   alg.universe() = ", alg.universe()

import os.path
if os.path.exists("../Algebras"):

    # write the algebra to a UACalc file
    AlgebraIO.writeAlgebraFile(alg, "../Algebras/Example1_ConstructAlgebra.ua")
    print "UACalc algebra file created: ../Algebras/Example1_ConstructAlgebra.ua"




print "\n\n---- Example 2 ----"
print "Constructing an algebra with unary operations defined 'by hand' as vectors."

# The algebra will have universe {0, 1, ..., 7}, and the following unary operations: 
f0 = 7,6,6,7,3,2,2,3
f1 = 0,1,1,0,4,5,5,4
f2 = 0,2,3,1,0,2,3,1

# Use the functions above to construct UACalc operations:
op0 = Operation(f0, "f0", 1, 8)
    def plus_mod5(args):
        result = 0
        for x in args:
            result = result + x
        return result % 5
     
    # use it to construct some UACalc operations
    op0 = Operation(plus_mod5, "binaryPlusMod5", 2, 5)
    op1 = Operation(plus_mod5, "ternaryPlusMod5", 3, 5)

    # quick check that the operations give what we expect
    print "4 + 10 mod 5 = ", op0.intValueAt([4,10])
    print "4 + 10 + 1 mod 5 = ", op1.intValueAt([4,10,1])

    # make a list of the operations we want in the algebra
    ops = op0, op1

    # construct the algebra
    alg = BasicAlgebra("MyAlgebra", 5, ops)

    # quick check that we actually constructed an algebra
    print "alg.getName() = ", alg.getName()        
    print "alg.universe() = ", alg.universe()

    import os.path
    if os.path.exists("../Algebras/"):
    
        # write the algebra to a UACalc file:
        AlgebraIO.writeAlgebraFile(alg, "../Algebras/Example_ConstructAlgebra.ua")

Beispiel #5
0
# make a list of the operations we want in the algebra
ops = op0, op1

# construct the algebra
alg = BasicAlgebra("MyAlgebra", 5, ops)

print "Quick check that we constructed an algebra:"
print "   alg.getName() = ", alg.getName()        
print "   alg.universe() = ", alg.universe()

import os.path
if os.path.exists("../Algebras"):

    # write the algebra to a UACalc file
    AlgebraIO.writeAlgebraFile(alg, "../Algebras/Example1_ConstructAlgebra.ua")
    print "UACalc algebra file created: ../Algebras/Example1_ConstructAlgebra.ua"




print "\n\n---- Example 2 ----"
print "Constructing an algebra with unary operations defined 'by hand' as vectors."

# The algebra will have universe {0, 1, ..., 7}, and the following unary operations: 
f0 = 7,6,6,7,3,2,2,3
f1 = 0,1,1,0,4,5,5,4
f2 = 0,2,3,1,0,2,3,1

# Use the functions above to construct UACalc operations:
op0 = Operation(f0, "f0", 1, 8)
Beispiel #6
0
def SlowClosure(p):
    A = BasicPartition.unaryPolymorphismsAlgebra(p)
    print "|ConA| = ", len(A.con().universe())
    AlgebraIO.writeAlgebraFile(A, "/tmp/A.ua")
    return A.con()
Beispiel #7
0
    f0 = (0,1,1,0,0) 
    f1 = (1,1,2,2,2) 
    f2 = (3,2,2,4,4)
    fns = f0, f1, f2
    
    ops = []
    # use the functions above to construct UACalc operations
    for i in range(len(fns)):
        ops.append(Operation(fns[i], "f"+str(i), 1, 5))

    # check that the operations give what we expect
    print "Operations:"
    for i in range(len(ops)):
        print "   " + ops[i].symbol().name() + ":", 
        for j in range(5):
            print ops[i].intValueAt([j]),
        print " "

    # construct the algebra
    A = BasicAlgebra("MyUnaryAlgebra", 5, ops)

    # quick check that we constructed an algebra
    print "\nA.getName() = ", A.getName()        
    print "A.universe() = ", A.universe()


    BL = BasicLattice("ConA", A.con(), 0)
    AlgebraIO.writeAlgebraFile(A, "/tmp/A.ua")
    # AlgebraIO.writeAlgebraFile(L, "/tmp/ConA.ua")
    
    test_conjecture(BL, 1)