X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=hints%2Fassignment_7_hint_6.mdwn;h=740eba2b637e3d8a27116507b6693d77050d7bab;hp=ed3828b7e83fb5059212f02f145dd932697ac3ea;hb=4bbcf7dfee362fee1c3a23650912a2e259f2f51a;hpb=f212354152a53c6a3ab018c7874570c600f463b9;ds=sidebyside diff --git a/hints/assignment_7_hint_6.mdwn b/hints/assignment_7_hint_6.mdwn index ed3828b7..740eba2b 100644 --- a/hints/assignment_7_hint_6.mdwn +++ b/hints/assignment_7_hint_6.mdwn @@ -5,26 +5,19 @@ 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;; + + (* filter out which bool dpms in a set are true when receiving (r, h) as input *) + let extensions set (r, h) = List.filter (fun one_dpm -> let (truth_value, _, _) = one_dpm (r, h) in truth_value) 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 truth_value' = extensions (phi one_dpm) (r, h) = [] + in (truth_value', r, h) + ) * Representing \[[and φ ψ]] is simple: @@ -32,13 +25,25 @@ 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) -> + in let truth_value' = extensions (phi one_dpm) (r, h) <> [] || extensions (bind_set (negate_op phi one_dpm) psi) (r, h) <> [] + 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) -> + 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) (r, h) <> [] + ) (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 +121,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! *)