2

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.

1 Answer 1

2

In the last case of distrib1 you have a total of 3 opening parentheses, but 4 closing:

| distrib1 (Or(And(prop1, prop2), prop3) ) ) =

Which is why you get the the syntax error about the RPAREN.

You're getting an error in distrib because distrib1 has not been defined due to the syntax errors and thus it is an unknown variable. Fixing the syntax error in distrib1 will fix this too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.