The Completeness Theorem of Equivalential Calculus

rulesG={{x_,{x_,y_}}:>y,{{x_,y_},z_}:>{x,{y,z}},{x_,{{y_,z_},w_}}:>{x,{y,{z,w}}},{x_,{y_,z_}}:>{x,{z,y}},{x_,{{y_,z_},w_}}:>{x,{z,{y,w}}}};

pletters=CharacterRange["p","v"];

formulaexample={{{{x,y},z},w},{{{{{x,y},z},w},v},a},{{{{{{{x,y},z},w},v},a},b},c},{{{{{{{{{x,y},z},w},v},a},b},c},d},e},{{{{{{{{{{{x,y},z},w},v},a},b},c},d},e},f},g}};

RandomKsublist[set_,k_]:=Module[{sub={},rest=set,new},
Do[new=rest[[RandomInteger[{1,Length[rest]}]]];sub=AppendTo[sub,new];rest=Complement[rest,{new}],{k}];sub];
Randompermut[k_]:=RandomKsublist[Range[k],k];
set2[n_]:=Flatten[Table[{i,j},{i,-n+1,n-1},{j,-n+1,n-1}],1];

taut= {{{2,2}},{{2,2,2},{4,2}},{{2,2,2,2},{4,2,2},{4,4}},{{2,2,2,2,2},{4,2,2,2},{4,4,2}},{{2,2,2,2,2,2},{4,2,2,2,2},{4,4,2,2},{4,4,4}}};

set[k_]:=Module[{kom=Random[Integer,{1,Length[taut[[k]]]}],komb},komb=taut[[k,kom]];Flatten[Table[Table[pletters[[i]],{komb[[i]]}],{i,1,Length[komb]}]][[Randompermut[2k+2]]]];

rulesLetter1={x,y,z,w,v,a,b,c,d,e,f,g};

randformulaT[k_]:=Module[{formula=formulaexample[[k]],kk=Random[Integer,{1,k}],set1,rul},Do[formula=formula/.rulesG,{i,1,kk} ];set1=set[k];rul=Table[rulesLetter1[[i]]->set1[[i]],{i,1,2k+2}];formula/.rul]

setpl=Join[Take[pletters,3],Take[pletters,3],Take[pletters,3],Take[pletters,3]][[Randompermut[12]]];

randformula[k_]:=Module[{formula=formulaexample[[k]],kk=Random[Integer,{1,k}],rul},Do[formula=formula/.rulesG,{i,1,k} ];rul=Table[rulesLetter1[[i]]->setpl[[i]],{i,1,2k+2}];formula/.rul];
Convert[p_]:=(p/;AtomQ[p]);
Convert[{p_,q_}]:=StringJoin["E",Convert[p],Convert[q]];

rules={{x_,{x_,y_}}:>y/;AtomQ[x],{{x_,y_},z_}:>{x,{y,z}},{x_,{{y_,z_},w_}}:>{x,{y,{z,w}}}/;AtomQ[x]&&OccursQ[x,y],{x_,{y_,z_}}:>{x,{z,y}}/;AtomQ[x]&&OccursQ[x,z]&&!OccursQ[x,y],{x_,{{y_,z_},w_}}:>{x,{z,{y,w}}}/;AtomQ[x]&&OccursQ[x,z]&&!OccursQ[x,y]};

rulesE={"1. ExExy~y","2. EExyz~ExEyz","3. ExEEyzw~ExEyEzw","4. ExEyz~ExEzy","5. ExEEyzw~ExEzEyw"};

rules1={{x_,{x_,y_}}/;AtomQ[x],{{x_,y_},z_},{x_,{{y_,z_},w_}}/;AtomQ[x]&&OccursQ[x,y],{x_,{y_,z_}}/;AtomQ[x]&&OccursQ[x,z]&&!OccursQ[x,y],{x_,{{y_,z_},w_}}/;AtomQ[x]&&OccursQ[x,z]&&!OccursQ[x,y]};

theq[formula_]:=Module[{expr=formula,theorem=True,mapmatch,pos,subs,formule},formule={Convert[expr]};
While[theorem && !MatchQ[expr,{x_,x_}/;AtomQ[x]],mapmatch=Map[MatchQ[expr,#]&,rules1];pos=Position[mapmatch,True];If[!MemberQ[mapmatch,True],theorem=False,subs=Sub[expr,pos[[1,1]]];expr=(expr/.rules[[pos[[1,1]]]]);formule=Append[formule,Row[{Convert[expr],", ",pos[[1,1]],MapAt[Convert,subs,Table[{i,2},{i,1,Length[subs]}]]}]]]];Column[{Style[Column[formule],"MR"],"",Text@If[theorem,"The formula is a tautology.","The formula is not a tautology."]}]]

OccursQ[x_,y_]:=If[AtomQ[y],x===y ,MemberQ[Flatten[y],x]];
Sub[expr_,1]:={x->expr[[1]],y->expr[[2,2]] };
Sub[expr_,2]:={x->expr[[1,1]],y->expr[[1,2]],z-> expr[[2]]};
Sub[expr_,3]:={x->expr[[1]],y->expr[[2,1,1]],z-> expr[[2,1,2]],w->expr[[2,2]]};
Sub[expr_,4]:={x->expr[[1]],y->expr[[2,1]],z-> expr[[2,2]]};
Sub[expr_,5]:={x->expr[[1]],y->expr[[2,1,1]],z-> expr[[2,1,2]],w->expr[[2,2]]};

Manipulate[SeedRandom[ranint];With[{len=Random[Integer,{1,5}]},With[{formula={randformulaT[len],randformula[len]}[[Random[Integer,{1,2}]]]},Style[Column[{Text@"Is the following formula a tautology?\n",Style[Convert[formula],"MR"]," ",
If[
show,
Column[{Text@"Proof:\n",theq[formula]}],
Column[{
Text@"Rules:\n",
Style[Column[rulesE],"MR"],
Text@Row[{"\n",Style["Mathematica",Italic]," implementation:\n"}],
Style[Column[rules],"MR"]
}]
]
}],14]
]
],{{ranint,RandomInteger[1233455]},ControlType->None},Button["new equivalential formula",(*an=0;*)show=False;ranint=RandomInteger[{1,23423}]],{{show,False,"show proof/rules"},{True,False}},SaveDefinitions->True,ContentSize->{540,450}]

This Demonstration shows Łukasiewicz's completeness theorem for the equivalential calculus. A formula is a theorem if it is deductively equivalent to a formula Exx, where x is a propositional variable (propositional letter). Two adjacent  lines in a proof such as

EpEpEqErErq, 5{x->p, y->q, z->p, w->ErErq}

EqErErq, 1{x->p, y->EqErErq}

mean that the formula in the second line is obtained from the formula in the first line, and the rule 1 on which the substitution {x->p, y->ErErq} is applied. In this case the rule 1 has the form

EpEpEqErErq~EqErErq

showing equivalence of the formulas.

The equivalential calculus is a subsystem of propositional calculus with equivalence as the only connective. In 1929 Leśniewski recognized that the equivalential calculus could be axiomatized. He used two axioms and the rules of detachment and substitution. He also observed that a formula of propositional calculus in which equivalence was the only propositional function was a tautology if and only if each propositional letter has an even number of appearances in it.

In 1932 Wajsberg showed that the calculus can be based on a single axiom. In 1933 Łukasiewicz found the shortest axiom EEEpqErsEtu and gave a simple completeness proof. He derived certain tautologies, such as EEEpqrEpEqr, which were used as rules. The rule EExyz~ExEyz says that a formula of the form EExyz is equivalent to ExEyz. A formula of the calculus is a tautology if it is deductively equivalent to Exx, where x is a propositional variable [1]. The realization of the completeness theorem as a Prolog program was given in [2].

In 1981 Hafner gave a more complicated completeness proof showing the proof length (the number of proof steps) is linear in formula size [3].

References

[1] J. Łukasiewicz, "The Equivalential Calculus," in Polish Logic (1920–1939), S. McCall, ed., Oxfordk: Clarendon Press, 1967 pp. 88–115.

[2] I. Hafner, "The Completeness Theorem of Equivalential Calculus as Prolog Program," Logic Programming Newsletter, May 1987 pp. 7–8.

[3] I. Hafner, "On Proof Length in the Equivalential Calculus," Glasnik Matematički, 15(35), 1980 pp. 233–242.

[4] S. Wolfram, A New Kind of Science, Champaign, IL: Wolfram Media, 2002 p. 1170e.

Contributed by: Izidor Hafner