Example #1
0
 def get_proof_term(self, thy, t):
     if is_plus(t.arg):
         return every_conv(rewr_conv("add_assoc", sym=True),
                           arg1_conv(norm_add_polynomial()),
                           norm_add_monomial()).get_proof_term(thy, t)
     else:
         return norm_add_monomial().get_proof_term(thy, t)
Example #2
0
 def get_proof_term(self, thy, t):
     if is_times(t.arg):
         return every_conv(rewr_conv("mult_assoc", sym=True),
                           arg1_conv(norm_mult_monomial()),
                           norm_mult_atom()).get_proof_term(thy, t)
     else:
         return norm_mult_atom().get_proof_term(thy, t)
Example #3
0
 def get_proof_term(self, thy, t):
     if is_plus(t.arg):
         return every_conv(rewr_conv("distrib_l"),
                           arg1_conv(norm_mult_polynomial()),
                           arg_conv(norm_mult_poly_monomial()),
                           norm_add_polynomial()).get_proof_term(thy, t)
     else:
         return norm_mult_poly_monomial().get_proof_term(thy, t)
Example #4
0
 def get_proof_term(self, thy, t):
     if is_plus(t.arg1):
         return every_conv(rewr_conv("add_assoc"),
                           arg_conv(rewr_conv("add_comm")),
                           rewr_conv("add_assoc",
                                     sym=True)).get_proof_term(thy, t)
     else:
         return rewr_conv("add_comm").get_proof_term(thy, t)
Example #5
0
def get_encode_proof(th):
    """Given resulting theorem for an encoding, obtain the proof
    of the theorem.

    The theorem is structured as follows:

    Each of the assumptions, except the last, is an equality, where
    the right side is either an atom or a logical operation between
    atoms. We call these assumptions As.

    The last assumption is the original formula. We call it F.

    The conclusion is in CNF. Each clause except the last is an
    expansion of one of As. The last clause is obtained by performing
    substitutions of As on F.

    """
    As, F = th.hyps[:-1], th.hyps[-1]

    # Obtain the assumptions
    ptAs = [ProofTerm.assume(A) for A in As]
    ptF = ProofTerm.assume(F)

    # Obtain the expansion of each As to a non-atomic term.
    pts = []
    for ptA in ptAs:
        rhs = ptA.prop.rhs
        if logic.is_conj(rhs):
            pts.append(ptA.on_prop(thy, rewr_conv("encode_conj")))
        elif logic.is_disj(rhs):
            pts.append(ptA.on_prop(thy, rewr_conv("encode_disj")))
        elif rhs.is_implies():
            pts.append(ptA.on_prop(thy, rewr_conv("encode_imp")))
        elif rhs.is_equals():
            pts.append(ptA.on_prop(thy, rewr_conv("encode_eq")))
        elif logic.is_neg(rhs):
            pts.append(ptA.on_prop(thy, rewr_conv("encode_not")))

    # Obtain the rewrite of the original formula.
    cvs = [
        top_conv(rewr_conv(ProofTerm.symmetric(ptA), match_vars=False))
        for ptA in ptAs
    ]
    cv = every_conv(*cvs)

    pts.append(ptF.on_prop(thy, cv))

    pt = pts[0]
    for pt2 in pts[1:]:
        pt = logic_macro.apply_theorem(thy, 'conjI', pt, pt2)

    return pt.on_prop(thy, logic.norm_conj_assoc())
Example #6
0
def norm_term(t):
    # Collect list of theorems that can be used.
    cvs = []
    for th_name in norm_thms:
        if isinstance(th_name, str) and theory.thy.has_theorem(th_name):
            cvs.append(conv.try_conv(conv.rewr_conv(th_name)))
        elif theory.thy.has_theorem(th_name[0]):
            cvs.append(conv.try_conv(conv.rewr_conv(th_name[0], sym=True)))
    cvs.append(conv.try_conv(conv.beta_conv()))
    cv = conv.top_conv(conv.every_conv(*cvs))
    while True:
        rhs = cv.eval(t).rhs
        if rhs == t:
            break
        else:
            t = rhs
    return fologic.simplify(t)
Example #7
0
    def get_proof_term(self, thy, t):
        if not (is_plus(t) and is_binary(t.arg1) and is_binary(t.arg)):
            raise ConvException
        n1, n2 = t.arg1, t.arg  # two summands
        if n1 == zero:
            cv = rewr_conv("plus_def_1")
        elif n2 == zero:
            cv = rewr_conv("add_0_right")
        elif n1 == one:
            cv = then_conv(rewr_conv("add_1_left"), Suc_conv())
        elif n2 == one:
            cv = then_conv(rewr_conv("add_1_right"), Suc_conv())
        elif n1.head == bit0 and n2.head == bit0:
            cv = then_conv(rewr_conv("bit0_bit0_add"), arg_conv(self))
        elif n1.head == bit0 and n2.head == bit1:
            cv = then_conv(rewr_conv("bit0_bit1_add"), arg_conv(self))
        elif n1.head == bit1 and n2.head == bit0:
            cv = then_conv(rewr_conv("bit1_bit0_add"), arg_conv(self))
        else:
            cv = every_conv(rewr_conv("bit1_bit1_add"),
                            arg_conv(arg_conv(self)), arg_conv(Suc_conv()))

        return cv.get_proof_term(thy, t)
Example #8
0
    def get_proof_term(self, thy, t):
        n1, n2 = t.arg1, t.arg  # two summands
        if n1 == zero:
            cv = rewr_conv("times_def_1")
        elif n2 == zero:
            cv = rewr_conv("mult_0_right")
        elif n1 == one:
            cv = rewr_conv("mult_1_left")
        elif n2 == one:
            cv = rewr_conv("mult_1_right")
        elif n1.head == bit0 and n2.head == bit0:
            cv = then_conv(rewr_conv("bit0_bit0_mult"),
                           arg_conv(arg_conv(self)))
        elif n1.head == bit0 and n2.head == bit1:
            cv = then_conv(rewr_conv("bit0_bit1_mult"), arg_conv(self))
        elif n1.head == bit1 and n2.head == bit0:
            cv = then_conv(rewr_conv("bit1_bit0_mult"), arg_conv(self))
        else:
            cv = every_conv(rewr_conv("bit1_bit1_mult"),
                            arg_conv(arg1_conv(add_conv())),
                            arg_conv(arg_conv(arg_conv(self))),
                            arg_conv(add_conv()))

        return cv.get_proof_term(thy, t)
Example #9
0
    return Const("Sem", TFun(comT(T), T, T, boolT))


def Valid(T):
    return Const("Valid", TFun(TFun(T, boolT), comT(T), TFun(T, boolT), boolT))


def Entail(T):
    return Const("Entail", TFun(TFun(T, boolT), TFun(T, boolT), boolT))


# Normalize evaluation of function as well as arithmetic.
norm_cv = then_conv(top_conv(function.fun_upd_eval_conv()), nat.norm_full())

# Normalize a condition.
norm_cond_cv = every_conv(norm_cv, top_conv(nat.nat_eq_conv()),
                          logic.norm_bool_expr())


def eval_Sem(thy, com, st):
    """Evaluates the effect of program com on state st."""
    f, args = com.strip_comb()
    T = st.get_type()
    if f.is_const_name("Skip"):
        return apply_theorem(thy, "Sem_Skip", tyinst={"a": T}, inst={"s": st})
    elif f.is_const_name("Assign"):
        a, b = args
        Ta = a.get_type()
        Tb = b.get_type().range_type()
        pt = apply_theorem(thy,
                           "Sem_Assign",
                           tyinst={
Example #10
0
def combine_monomial(thy):
    """Combine two monomials with the same body."""
    return every_conv(binop_conv(to_coeff_form()),
                      rewr_conv("distrib_l", sym=True), arg_conv(nat_conv()),
                      from_coeff_form())