コード例 #1
0
    def declare_functions():
        assert None not in (YicesSignature.thing_type, YicesSignature.pt2_type,
                            YicesSignature.stage_type,
                            YicesSignature.time_type,
                            YicesSignature.stage_type)

        YicesSignature.b_op = Terms.new_uninterpreted_term(
            YicesSignature.b_type, SymbolTable.B)
        if YicesSignature.b_op is None:
            sys.stderr.write(
                'declare_functions: YicesSignature.b_op is none {0}\n',
                Yices.error_string())
        YicesSignature.op_map[SymbolTable.B] = YicesSignature.b_op

        YicesSignature.ob_op = Terms.new_uninterpreted_term(
            YicesSignature.ob_type, SymbolTable.OB)
        if YicesSignature.ob_op is None:
            sys.stderr.write(
                'declare_functions: YicesSignature.ob_op is none {0}\n',
                Yices.error_string())
        YicesSignature.op_map[SymbolTable.OB] = YicesSignature.ob_op

        YicesSignature.pt_op = Terms.new_uninterpreted_term(
            YicesSignature.pt_type, SymbolTable.PT)
        if YicesSignature.pt_op is None:
            sys.stderr.write(
                'declare_functions: YicesSignature.pt_op is none {0}\n',
                Yices.error_string())
        YicesSignature.op_map[SymbolTable.PT] = YicesSignature.pt_op

        YicesSignature.atloc_op = Terms.new_uninterpreted_term(
            YicesSignature.atloc_type, SymbolTable.ATLOC)
        if YicesSignature.atloc_op is None:
            sys.stderr.write(
                'declare_functions: YicesSignature.atloc_op is none {0}\n',
                Yices.error_string())
        YicesSignature.op_map[SymbolTable.ATLOC] = YicesSignature.atloc_op

        YicesSignature.treatstage_op = Terms.new_uninterpreted_term(
            YicesSignature.treatstage_type, SymbolTable.TREATSTAGE)
        if YicesSignature.treatstage_op is None:
            sys.stderr.write(
                'declare_functions: YicesSignature.treatstage_op is none {0}\n',
                Yices.error_string())
        YicesSignature.op_map[
            SymbolTable.TREATSTAGE] = YicesSignature.treatstage_op

        # DANGER: python2 crazyness! Enter at own risk!!
        YicesSignature.abs_op = Terms.abs
        YicesSignature.op_map[
            SymbolTable.
            ABS] = Terms.abs  # cannot use YicesSignature.abs_op because it has been mangled into an "unbound method"!!!!
        #print(f'YicesSignature.abs_op = {YicesSignature.abs_op}')
        #print(f'YicesSignature.op_map[SymbolTable.ABS] = {YicesSignature.op_map[SymbolTable.ABS]}')

        return True
コード例 #2
0
    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