Said I have got 2 CNF logical phrases a,b and my distrib function should return the CNF form of a|b (a OR b).
Replacing rules that I’ve got are:
1) Replace p|(q&r) by (p|q)&(p|r)
2) Replace (q&r)|p by (q|p)&(r|p)
A prop defined this way:
datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;
The function:
local
fun doOr(prop1,prop2) = (Or(prop1,prop2))
fun distrib1 (Or(Atom(sName1),Atom(sName2) ) ) = Or(Atom(sName1), Atom(sName2) )
|distrib1 (Or(Not(Atom(sName1) ),Atom(sName2) ) ) = Or(Not(Atom(sName1) ), Atom(sName2) )
| distrib1 (Or(Atom(sName1),Not(Atom(sName2) ) ) ) = Or(Atom(sName1), Not(Atom(sName2) ) )
| distrib1 (Or(Not(Atom(sName1)),Not(Atom(sName2) ) ) ) = Or(Not(Atom(sName1)), Not(Atom(sName2) ) )
| distrib1 (Or(prop1,And(prop2,prop3) ) ) = And( distrib1(Or(prop1,prop2) ), distrib1(Or(prop1,prop3) ) )
| distrib1 (Or(And(prop1, prop2), prop3) ) ) = And( distrib1(Or(prop1,prop3) ), distrib1(Or(prop2,prop3) ) )
in
fun distrib (prop1,prop2) = distrib1(doOr(prop1,prop2) );
end;
Well, I don’t know if the function itself is right although I just went through all the base options and the replacing rules but for now I get the above errors when the EQALOP appear after the distrib1 function and the constructors error appear the distrib function.
Why I get those errors? I am not sure but maybe I am supposed to use let and not local but then how can I transform it to a let structure?
Thanks.
In the last case of
distrib1you have a total of 3 opening parentheses, but 4 closing:Which is why you get the the syntax error about the RPAREN.
You’re getting an error in
distribbecausedistrib1has not been defined due to the syntax errors and thus it is an unknown variable. Fixing the syntax error indistrib1will fix this too.