From: Jim Pryor Date: Sat, 20 Nov 2010 12:29:01 +0000 (-0500) Subject: assignment7 tweaks X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=efa4651049a770c2935ebc11770bbdb23b8a3c6d assignment7 tweaks Signed-off-by: Jim Pryor --- diff --git a/hints/assignment_7_hint_6.mdwn b/hints/assignment_7_hint_6.mdwn index 0859706b..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: