def toConstraintTerm(self, maxTimeStamp=None): if self.name == SymbolTable.MAXTIME: assert maxTimeStamp is not None yterm = Terms.get_by_name(SymbolTable.MAXTIME) assert yterm is not None return Terms.eq(yterm, YicesSignature.integer(maxTimeStamp)) def constrainVariable(maxValue): if maxValue is not None: ymax = None if maxValue == SymbolTable.MAXTIME: ymax = Terms.get_by_name(SymbolTable.MAXTIME) else: ymax = YicesSignature.integer(maxValue) yterms = [ Terms.arith_leq_atom(YicesSignature.integer(0), self.yices_term), Terms.arith_leq_atom(self.yices_term, ymax) ] return Terms.yand(yterms) return Terms.arith_leq_atom(YicesSignature.integer(0), self.yices_term) if self.vartype.name == SymbolTable.TIME: return constrainVariable(SymbolTable.MAXTIME) if self.vartype.name == SymbolTable.STAGE: return constrainVariable(Configuration.stage_count - 1) if self.vartype.name == SymbolTable.NAT: if self.yices_type == SymbolTable.BINDEX: return constrainVariable(Configuration.bot_count - 1) if self.yices_type == SymbolTable.OBINDEX: return constrainVariable(Configuration.obs_count - 1) if self.yices_type == SymbolTable.XAXIS: return constrainVariable(Configuration.grid_dimension[0] - 1) if self.yices_type == SymbolTable.YAXIS: return constrainVariable(Configuration.grid_dimension[1] - 1) return None
def constrainVariable(maxValue): if maxValue is not None: ymax = None if maxValue == SymbolTable.MAXTIME: ymax = Terms.get_by_name(SymbolTable.MAXTIME) else: ymax = YicesSignature.integer(maxValue) yterms = [ Terms.arith_leq_atom(YicesSignature.integer(0), self.yices_term), Terms.arith_leq_atom(self.yices_term, ymax) ] return Terms.yand(yterms) return Terms.arith_leq_atom(YicesSignature.integer(0), self.yices_term)
def declare_variable(var, bound_variables): """ constructs the yices term associated with the logical variable. In the case that bound_variables is not None, we are parsing an invariant, so that any NEW variables that we see are taken to be bound by the implicit universal quantifiers. """ varname = var.name vartype = var.vartype # check if it is bound and has already been seen if bound_variables is not None and varname in bound_variables: yvar = bound_variables[varname].yices_term var.bound = True return yvar # check if it has already been seen yvar = Terms.get_by_name(varname) if yvar is not None: #now we need to see if it is free or bound tag = Terms.constructor(yvar) if tag == Constructor.VARIABLE: var.bound = True bound_variables[varname] = var return yvar type_term = vartype.yices_term type_name = vartype.name var_term = None if bound_variables is not None: # we need to make a yices variable not an uninterpreted term var_term = Terms.new_variable(type_term, varname) if var_term is None: sys.stderr.write( f'declare_variable: Term.new_variable failed {Yices.error_string()}\n' ) return None bound_variables[varname] = var var.bound = True else: var_term = Terms.new_uninterpreted_term(type_term, varname) if var_term is None: sys.stderr.write( f'declare_variable: Term.new_uninterpreted_term failed {Yices.error_string()}\n' ) return None YicesSignature.types_to_variables[type_name].add(var) return var_term