Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Opgave 5.1
- //Declare an F# function isConsistent that checks the consistency of a set of literals.
- //Set version, men mit dilemma er at jeg ikke formår at matche x mod sin modsætning, e.g. x er endten Neg(Prop) eller A(c)
- let rec isConsistentset :Set<Prop> -> bool = function
- |latSet -> let comparisonSet = Set.foldBack(fun x set -> if(x = Neg of Prop)if Set.contains x (Set.remove x latSet) then Set.add x Set.empty else set) latSet Set.empty
- if Set.intersect latSet comparisonSet <> Set.empty then false else true
- //List version af isConsistent
- let rec isConsistent :Prop list*Prop list -> bool = function
- |[],auxlist -> true //Base case
- |Neg(A(p))::pp,auxlist -> if List.exists(fun y -> y = A(p)) auxlist then
- false
- else
- isConsistent(pp,A(p)::auxlist)
- |A(p)::pp,auxlist -> if List.exists(fun y -> y = A(p)) auxlist then
- false
- else
- isConsistent(pp,A(p)::auxlist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement