from pysmt.shortcuts import get_model, Symbol, And, BVUGE, BVfrom pysmt.typing import BVTypeM = 4N = 3# create a matrix of 8-bit BV variablesvar_matrix = [[] for _ in range(M)]for i in range(M):for j in range(N):v = Symbol("cell_%d_%d" % (i, j), BVType(8))var_matrix[i].append(v)# Impose some constraints on the variables# In this example, we require that the value of cell (i,j)# is greater or equal to i+jf = And(BVUGE(var_matrix[i][j], BV(j+i, width=8))for i in range(M) for j in range(N))m = get_model(f)assert m is not None# Print the resultfor i in range(M):for j in range(N):v = var_matrix[i][j]print("Value for cell (%d, %d) is %s" % (i, j, m[v]))
from pysmt.shortcuts import get_model, Symbol, And, BVUGE, BV, Select, Intfrom pysmt.typing import INT, BVType, ArrayType# Create an array INT -> INT -> BV, that is a 2D matrix with integer# indexes and BV valuesarr = Symbol("matrix", ArrayType(INT, ArrayType(INT, BVType(8))))# Impose some constraintsM = 4N = 3f = And(BVUGE(Select(Select(arr, Int(i)), Int(j)), BV(j+i, width=8))for i in range(M) for j in range(N))m = get_model(f)assert m is not None# Print the result: not that the size of the matrix is infinite, we# can ask the value for any integer index!for i in range(-M, 2*M):for j in range(-N, 2*N):v = Select(Select(arr, Int(i)), Int(j))print("Value for cell (%d, %d) is %s" % (i, j, m[v]))
--
You received this message because you are subscribed to the Google Groups "pySMT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pysmt+unsubscribe@googlegroups.com.
To post to this group, send email to py...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pysmt/1496049e-7ca8-4f5f-ad3a-db4b3e3334f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to pysmt+un...@googlegroups.com.