Esempio n. 1
0
def model_checking_ans():
    not_p11 = model_checking.Formula("P11", True)  # !P(1,1)
    not_b11 = model_checking.Formula("B11", True)  # !B(1,1)
    b21_1 = model_checking.Formula("B21", True)  # B(2,1)
    conj_left_sub = model_checking.Conjunction(False, not_b11, b21_1)
    conj_left = model_checking.Conjunction(False, not_p11, conj_left_sub)  # !P(1,1) ^ !B(1,1) ^ B(2,1)

    b11 = model_checking.Formula("B11")
    p12 = model_checking.Formula("P12")
    p21 = model_checking.Formula("P21")
    disj_1 = model_checking.Disjunction(False, p12, p21)
    bi_1 = model_checking.Biconditional(False, b11, disj_1)  # B(1,1) <=> (P(1,2) V P(2,1))

    b21_2 = model_checking.Formula("B21")
    p11 = model_checking.Formula("P11")
    p22 = model_checking.Formula("P22")
    p31 = model_checking.Formula("P31")
    disj_2 = model_checking.Disjunction(False, p22, p31)
    disj_3 = model_checking.Disjunction(False, p11, disj_2)
    bi_2 = model_checking.Biconditional(False, b21_2, disj_3)  # B(2,1) <=> (P(1,1) V P(2,2) V P(3,1))

    conj_right = model_checking.Conjunction(False, bi_1, bi_2)
    conj_kb = model_checking.Conjunction(False, conj_left, conj_right)  # Knowledge base

    formula_query = model_checking.Formula("P12")
    return model_checking.print_ans(conj_kb, formula_query)
Esempio n. 2
0
def model_checking_ans2():
    # A <=> X
    a_1 = model_checking.Formula("A")
    x_1 = model_checking.Formula("X")
    bi_a = model_checking.Biconditional(False, a_1, x_1)

    # H <=> ((G ^ H) => A)
    h_1 = model_checking.Formula("H")
    g_1 = model_checking.Formula("G")
    h_2 = model_checking.Formula("H")
    conj_1 = model_checking.Conjunction(False, g_1, h_2)
    a_2 = model_checking.Formula("A")
    imply_1 = model_checking.Implication(False, conj_1, a_2)
    bi_h = model_checking.Biconditional(False, h_1, imply_1)

    conj_left = model_checking.Conjunction(False, bi_a, bi_h)

    # C <=> (A ^ ?)
    c_1 = model_checking.Formula("C")
    a_3 = model_checking.Formula("A")
    unknown_1 = model_checking.Formula("Unknown 1")
    conj_2 = model_checking.Conjunction(False, a_3, unknown_1)
    bi_c = model_checking.Biconditional(False, c_1, conj_2)

    # G <=> (C => ?)
    g_2 = model_checking.Formula("G")
    c_2 = model_checking.Formula("C")
    unknown_2 = model_checking.Formula("Unknown 2")
    imply_2 = model_checking.Implication(False, c_2, unknown_2)
    bi_g = model_checking.Biconditional(False, g_2, imply_2)

    conj_right = model_checking.Conjunction(False, bi_c, bi_g)
    conj_kb = model_checking.Conjunction(False, conj_left,
                                         conj_right)  # Knowledge base

    query_x = model_checking.Formula("X")
    query_y = model_checking.Formula("Y")
    query_z = model_checking.Formula("Z")
    query_w = model_checking.Formula("W")

    a1 = model_checking.print_ans(conj_kb, query_x)
    a2 = model_checking.print_ans(conj_kb, query_y)
    a3 = model_checking.print_ans(conj_kb, query_z)
    a4 = model_checking.print_ans(conj_kb, query_w)
    return [a1, a2, a3, a4]
def model_checking_ans():
    # P
    formula_p_1 = model_checking.Formula("P")
    # P => Q
    formula_p_2 = model_checking.Formula("P")
    formula_q = model_checking.Formula("Q")
    imply = model_checking.Implication(False, formula_p_2, formula_q)
    # KB: {P, P => Q}
    conj_kb = model_checking.Conjunction(False, formula_p_1, imply)
    # Query: Q
    formula_query = model_checking.Formula("Q")
    return model_checking.print_ans(conj_kb, formula_query)
def model_checking_ans():
    # MYTHICAL => IMMORTAL
    myth = model_checking.Formula("MYTHICAL")
    immortal_1 = model_checking.Formula("IMMORTAL")
    imply_1 = model_checking.Implication(False, myth, immortal_1)

    # !MYTHICAL => (!IMMORTAL ^ MAMMAL)
    not_myth = model_checking.Formula("MYTHICAL", True)
    not_immortal = model_checking.Formula("IMMORTAL", True)
    mammal_1 = model_checking.Formula("MAMMAL")
    conj_sub = model_checking.Conjunction(False, not_immortal, mammal_1)
    imply_2 = model_checking.Implication(False, not_myth, conj_sub)

    conj_left = model_checking.Conjunction(False, imply_1, imply_2)

    # (IMMORTAL V MAMMAL) => HORNED
    immortal_2 = model_checking.Formula("IMMORTAL")
    mammal_2 = model_checking.Formula("MAMMAL")
    disj_sub = model_checking.Disjunction(False, immortal_2, mammal_2)
    horn_1 = model_checking.Formula("HORNED")
    imply_3 = model_checking.Implication(False, disj_sub, horn_1)

    # HORNED => MAGICAL
    horn_2 = model_checking.Formula("HORNED")
    magical = model_checking.Formula("MAGICAL")
    imply_4 = model_checking.Implication(False, horn_2, magical)

    conj_right = model_checking.Conjunction(False, imply_3, imply_4)
    conj_kb = model_checking.Conjunction(False, conj_left,
                                         conj_right)  # Knowledge base

    query_myth = model_checking.Formula("MYTHICAL")
    query_magical = model_checking.Formula("MAGICAL")
    query_horn = model_checking.Formula("HORNED")

    a1 = model_checking.print_ans(conj_kb, query_myth)
    a2 = model_checking.print_ans(conj_kb, query_magical)
    a3 = model_checking.print_ans(conj_kb, query_horn)
    return [a1, a2, a3]
Esempio n. 5
0
def model_checking_ans1():
    # A <=> X
    a_1 = model_checking.Formula("A")
    x_1 = model_checking.Formula("X")
    bi_a = model_checking.Biconditional(False, a_1, x_1)

    # B <=> (Y V Z)
    b_1 = model_checking.Formula("B")
    y_1 = model_checking.Formula("Y")
    z_1 = model_checking.Formula("Z")
    disj_1 = model_checking.Disjunction(False, y_1, z_1)
    bi_b = model_checking.Biconditional(False, b_1, disj_1)

    conj_ab = model_checking.Conjunction(False, bi_a, bi_b)

    # C <=> (A ^ B)
    c_1 = model_checking.Formula("C")
    a_2 = model_checking.Formula("A")
    b_2 = model_checking.Formula("B")
    conj_1 = model_checking.Conjunction(False, a_2, b_2)
    bi_c = model_checking.Biconditional(False, c_1, conj_1)

    # D <=> (X ^ Y)
    d_1 = model_checking.Formula("D")
    x_2 = model_checking.Formula("X")
    y_2 = model_checking.Formula("Y")
    conj_2 = model_checking.Conjunction(False, x_2, y_2)
    bi_d = model_checking.Biconditional(False, d_1, conj_2)

    conj_cd = model_checking.Conjunction(False, bi_c, bi_d)
    conj_abcd = model_checking.Conjunction(False, conj_ab, conj_cd)

    # E <=> (X ^ Z)
    e_1 = model_checking.Formula("E")
    x_3 = model_checking.Formula("X")
    z_2 = model_checking.Formula("Z")
    conj_3 = model_checking.Conjunction(False, x_3, z_2)
    bi_e = model_checking.Biconditional(False, e_1, conj_3)

    # F <=> (D V E)
    f_1 = model_checking.Formula("F")
    d_2 = model_checking.Formula("D")
    e_2 = model_checking.Formula("E")
    disj_2 = model_checking.Disjunction(False, d_2, e_2)
    bi_f = model_checking.Biconditional(False, f_1, disj_2)

    conj_ef = model_checking.Conjunction(False, bi_e, bi_f)

    # G <=> (C => F)
    g_1 = model_checking.Formula("G")
    c_2 = model_checking.Formula("C")
    f_2 = model_checking.Formula("F")
    imply_1 = model_checking.Implication(False, c_2, f_2)
    bi_g = model_checking.Biconditional(False, g_1, imply_1)

    # H <=> ((G ^ H) => A)
    h_1 = model_checking.Formula("H")
    g_2 = model_checking.Formula("G")
    h_2 = model_checking.Formula("H")
    conj_4 = model_checking.Conjunction(False, g_2, h_2)
    a_3 = model_checking.Formula("A")
    imply_2 = model_checking.Implication(False, conj_4, a_3)
    bi_h = model_checking.Biconditional(False, h_1, imply_2)

    conj_gh = model_checking.Conjunction(False, bi_g, bi_h)
    conj_efgh = model_checking.Conjunction(False, conj_ef, conj_gh)
    conj_kb = model_checking.Conjunction(False, conj_abcd,
                                         conj_efgh)  # Knowledge base

    query_x = model_checking.Formula("X")
    query_y = model_checking.Formula("Y")
    query_z = model_checking.Formula("Z")
    query_w = model_checking.Formula("W")

    a1 = model_checking.print_ans(conj_kb, query_x)
    a2 = model_checking.print_ans(conj_kb, query_y)
    a3 = model_checking.print_ans(conj_kb, query_z)
    a4 = model_checking.print_ans(conj_kb, query_w)
    return [a1, a2, a3, a4]