X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=hints%2Fassignment_7_hint_6.mdwn;h=344451a80a6200dbce92ea34d47652a9c7659032;hp=ed3828b7e83fb5059212f02f145dd932697ac3ea;hb=efa4651049a770c2935ebc11770bbdb23b8a3c6d;hpb=f212354152a53c6a3ab018c7874570c600f463b9 diff --git a/hints/assignment_7_hint_6.mdwn b/hints/assignment_7_hint_6.mdwn index ed3828b7..344451a8 100644 --- a/hints/assignment_7_hint_6.mdwn +++ b/hints/assignment_7_hint_6.mdwn @@ -5,26 +5,17 @@ where `i` *subsists* in s[φ] if there are any `i'` that *extend* `i` in s[φ]. ------- wrong.... - - In our framework, we just have to convert the operation >>= \[[ψ]] into another operation >>= \[[ψ]] >>= neg, where `neg` flips the truth-value of all the `bool dpm`s it operates on: + Here's how to do that in our framework: type clause_op = bool dpm -> bool dpm set;; let negate_op (phi : clause_op) : clause_op = - let neg : clause_op = fun one_dpm -> - unit_set (fun (r, h) -> - let (truth_value, r', h') = one_dpm (r, h) - in (not truth_value, r', h')) - in fun one_dpm -> bind_set (phi one_dpm) neg;; - - - let negate_op (phi : clause_op) : clause_op = - fun one_dpm -> - if blah - then unit_set one_dpm - else empty_set ------- + fun one_dpm -> unit_set ( + fun (r, h) -> + let extensions set = List.filter (fun one_dpm -> let (truth_value, _, _) = one_dpm (r, h) in truth_value) set + in let truth_value' = extensions (phi one_dpm) = [] + in (truth_value', r, h) + ) * Representing \[[and φ ψ]] is simple: @@ -32,13 +23,24 @@ let and_op (phi : clause_op) (psi : clause_op) : clause_op = fun one_dpm -> bind_set (phi one_dpm) psi;; -* We define the other connectives in terms of `not` and `and`: +* Here are `or` and `if`: let or_op (phi : clause_op) (psi : clause_op) = - negate_op (and_op (negate_op phi) (negate_op psi)) + (* NOT: negate_op (and_op (negate_op phi) (negate_op psi)) *) + fun one_dpm -> unit_set ( + fun (r, h) -> + let extensions set = List.filter (fun one_dpm -> let (truth_value, _, _) = one_dpm (r, h) in truth_value) set + in let truth_value' = extensions (phi one_dpm) <> [] || extensions (bind_set (negate_op phi one_dpm) psi) <> [] + in (truth_value', r, h)) + + let if_op (phi : clause_op) (psi : clause_op) : clause_op = + (* NOT: negate_op (and_op phi (negate_op psi)) *) + fun one_dpm -> unit_set ( + fun (r, h) -> + let extensions set = List.filter (fun one_dpm -> let (truth_value, _, _) = one_dpm (r, h) in truth_value) set + in let truth_value' = List.for_all (fun one_dpm -> let (truth_value, _, _) = one_dpm (r, h) in truth_value = false || extensions (psi one_dpm) <> []) (phi one_dpm) + in (truth_value', r, h));; - let if_op (phi : clause_op) (psi : clause_op) = - negate_op (and_op phi (negate_op psi));; * Now let's test everything we've developed: @@ -116,10 +118,10 @@ let antecedent = fun one_dpm -> exists 'x' one_dpm >>= lift_predicate male getx >>= exists 'y' >>= lift_predicate2 wife_of getx gety;; (* "if a man x has a wife y, x kisses y" *) - run (initial_set >>= if_op antecedent lift_predicate2 kisses getx gety);; + run (initial_set >>= if_op antecedent (lift_predicate2 kisses getx gety));; (* Bob has wife Carol, and kisses her; and Ted has wife Alice and kisses her; so this is true! *) (* "if a man x has a wife y, x misses y" *) - run (initial_set >>= if_op antecedent lift_predicate2 misses getx gety);; + run (initial_set >>= if_op antecedent (lift_predicate2 misses getx gety));; (* Bob has wife Carol, and misses her; but Ted misses only Carol, not his wife Alice; so this is false! *)