Sunteți pe pagina 1din 24

Modi

ations on the implementation of a framework for tableaux methods


Adolfo Gustavo Serra Se a Neto
July 1, 2003
Abstra t

The method of tableaux is a formal proof pro edure with many varieties and for several logi s. Among other
important appli ations, it is used for the development of theorem-provers. An obje t-oriented framework for the
implementation of tableaux methods was presented in Wagner Dias's MS . Dissertation [Dia02. This framework
was implemented in the C++ programming language. In this paper, we des ribe some modi ations we have made
in that implementation in order to obtain shorter KE Tableau proofs. We also present the result of tests we have run
with both implementations omparing: (i) the number of formulas, (ii) the number of nodes in the losed tableaus
and (iii) the time spent for the losing of ea h tableau.

1 Introdu tion
The method of tableaux is a formal proof pro edure with many varieties and for several logi s. Among other
important appli ations, it is used for the development of theorem-provers. An obje t-oriented framework for the
implementation of tableaux methods was presented in Wagner Dias's MS . Dissertation [Dia02. This framework
was implemented in the C++ programming language. Three tableaux methods were overed by his implementation:
Smullyan's Analyti Tableaux, D'Agostino's KE Tableaux and Finger and Wasserman's KE-S3 Tableaux. In this
paper, our goal is des ribing some modi ations we have made in that implementation in order to obtain shorter
KE Tableau proofs, as well as presenting the result of tests we have run with both implementations omparing: (i)
the number of formulas, (ii) the number of nodes in the losed tableaus and (iii) the time spent for the losing of
ea h tableau.
In Se tion 2, we shortly present some of the history of tableaux, give a pre ise de nition of Analyti Tableaux,
and re all some of the onsiderations about tableaux made by Mar ello D'Agostino in [DAg99. After that, we
present his KE System in subse tion 3.1. Then in Se tion 4, we show the modi ations we have made in Wagner
Dias's system. After that, in Se tion 5, we introdu e the families of formulas that were used for the omparative
tests whose results are in Se tion 6. We present in Se tion 7 our on lusions and possible future works. And in
Appendix A, we give a personal evaluation on the experien e of rewriting ode.

2 What are Tableaux?


A ording to Smullyan [Smu68, Analyti Tableaux are \an extremely elegant and e ient proof pro edure for
propositional logi ". It is a variant of the \semanti tableaux" of Beth[Bet59, or of methods of Hintikka[Hin55.
Ultimately, the whole idea derives from Gentzen [Gen35.
The method of tableaux is a formal proof pro edure with many varieties and for several logi s. It is a refutation
pro edure | that is, in order to prove that a formula X is valid we try to show that it is not valid. With this in
mind, we apply a pro edure to infer the logi al onsequen es of the formulas present in the tableau. If some bran h
remains open, the we have a refutation of X .

2.1 The history of tableaux


In [Fit99, tableau history is analysed. It began with Gentzen, who introdu ed two formal proof pro edures, sequent
al ulus and natural dedu tion, in 1935. Gentzen showed that his sequent al ulus had a rule, alled Cut, whi h
ould be eliminated. He then proved the famous Cut elimination theorem.
1

In 1955, Beth, motivated by semanti on erns, introdu ed the `semanti tableaus'. Hintikka, simultaneously,
also motivated by semanti on erns, that is, \the idea behind a proof of X is that it is a systemati attempt to
onstru t a model in whi h :X is true, if the attempt fails, X has been established as valid", introdu ed model sets.
But it was with Smullyan [Smu68 that tableaus be ame widely known. In his book First-Order Logi he presents
a system alled `Analyti 1 Tableaux'.

2.2 Pre ise De nition of Tableaux


In order to give a pre ise de nition of Tableaux, Smullyan rst de ne trees, formulas and some other asso iated
on epts. Below we present some of these de nitions taken from [Smu68.

2.2.1 Trees
An unordered tree onsists of three mathemati al obje ts:
1. A set S of elements alled points
2. A fun tion l, whi h assigns to ea h point x a positive integer l(x) alled the level of x
3. A relation xRy de ned in S , whi h we read as \x is a prede essor of y " or \y is a su essor of x". This relation
must obey the following onditions:
C1 : There is a unique point a1 of level 1. This point is alled the origin of the tree.
C2 : Every other point besides the origin has exa tly one prede essor.
C3 : For any points x, y , if y is a su essor pof x, then l(y ) = l(x) + 1.
An end point is a point whi h has no su essors. A simple point has exa tly one su essor and a jun tion point
has more than one su essor. A path is any nite or denumerable sequen e of points, beginning with the origin,
whi h is su h that ea h term of the sequen e (ex ept the last, if there is one) is the prede essor of the next. And a
maximal path or bran h is either a path whose last term is an end point of the tree, or a path whi h is in nite.
An ordered tree is an unordered tree along with a fun tion  whi h assigns to ea h jun tion point z a sequen e
(z ) with no repetitions, and whose set of terms onsists of all the su essors of z . Therefore, if z is a jun tion point of
an ordered tree, we an speak of the 1st , 2nd , : : : , nth , : : : su essors of z (for any n up to the number of su essors
of z ) meaning, of ourse, the 1st , 2nd , : : : , nth , : : : terms of (z ). For a simple point x, we shall also speak of the
su essor of x as the sole su essor of x.
Given a tree T , we an add \new" points as su essors of an end point x of this tree. That is, for any element y
not belonging to T , the adjun tion of y as the sole su essor of x results in the tree obtained by:
1. adding y to the set S ,
2. adding the ordered pair < x; y > to the relation R (looked as a set of ordered pairs), and
3. extending the fun tion l by de ning l(y ) = l(x) + 1.
The above des ription serves for adding one point. If we want to add more than one point, that is, if we want to
add the distin t elements y1 ; : : : ; yn , ea h outside S , as respe tive 1st , 2nd , : : : , nth su essors of x, we will have to:
1. add the yi to S ,
2. add the pairs < x; yi > to R,
3. extend l by setting l(y1 ) = : : : = l(yn ) = l(x) + 1, and
4. extend the fun tion  by de ning (x) to be the sequen e (y1 ; : : : ; yn ).
A tree is alled nitely generated if ea h point has only nitely many su essors. A tree, T , is alled nite if
T has only nitely many points, otherwise the tree is alled in nite. Obviously, a nitely generated tree may be
in nite.
A dyadi tree is an ordered tree in whi h ea h jun tion point has exa tly 2 su essors. For su h trees, the rst
su essor of a jun tion point is alled the left su essor, and the se ond su essor is the right su essor.

1 Analyti be ause the subformula property is a entral feature.

2.2.2 Formulas of Propositional Logi


The logi al onne tives are represented by the following four symbols:
1. : : the negation (read \not"),
2. ^ : the onjun tion (read \and"),
3. _ : the disjun tion (read \or"),
4. ! : the impli ation (read \implies").
The rst sysmbol is the unary onne tive whilst the last three are olle tively alled binary onne tives. Other
symbols are:
 A denumerable set p1 ; p2 ; : : : ; pn ; : : : of symbols alled propositional variables. Usually the letters \p", \q",
\r", \s" stand for any of the variables p1 ; p2 ; : : : ; pn ; : : :
 The two symbols (, ), respe tively alled the left parenthesis and the right parenthesis, whi h are used for
pun tuation.
Then, a formula an be re ursively de ned from the following set of rules:
F0 Every propositional variable is a formula.
F1 If A is a formula, :A is also a formula.
F2 If A; B are formulas, (A ^ B ) is also a formula.
F3 If A; B are formulas, (A _ B ) is also a formula.
F4 If A; B are formulas, (A ! B ) is also a formula.
A formation sequen e is any nite sequen e su h that ea h term of the sequen e is either a propositional variable
or is of the form :A, where A is an earlier term of the sequen e, or is of one of the forms (A ^ B ), (A _ B ), (A ! B ),
where A; B appeared before in the sequen e. Then we de ne A to be a formula if there exists a formation sequen e
whose last term is A. And su h a sequen e is alled a formation sequen e for A.
For any formula A, :A is the negation of A. And for any two formulas A; B , we say that (A ^ B ), (A _ B ) and
(A ! B ) are the onjun tion, disjun tion and onditional of A; B respe tively. In a onditional formula, (A ! B ),
A is alled the ante edent and B the onsequent.
Parti ularly for tableaux, Smullyan presents signed formulas. A signed formula is an expression T X or F X where
X is a (unsigned) formula and the symbols T and F are the truth-values true and false.
The onjugate of a signed formula is the result of hanging \T " to \F " or \F " to \T " (thus teh onjugate of
T X if F X ; the onjgate of F X is T X ).
The method of tableaux is based on the fa t that [Smu68 \under any interpretation the following eight fa ts
hold (for any formulas X; Y ):
1. (a) If :X is true, then X is false.
(b) If :X is false, then X is true.
2. (a) If a onjun tion X ^ Y is true, then X; Y are both true.
(b) If a onjun tion X ^ Y is false, then either X is false or Y is false.
3. (a) If a disjun tion X _ Y is true, then either X is true or Y is true.
(b) If a disjun tion X _ Y is false, then both X; Y are false.
4. (a) If X ! Y is true, then either X is false or Y is true.
(b) If X ! Y is false, then X is true and Y is false."
After that the rules for ea h logi al onne tive are presented a ording to the eight fa ts shown above (see
Figure 1). These rules allow the expansion of tableaus, as will be seen in subse tion 2.2.4.

2.2.3 and Rules


Smullyan noti ed similarities between some rules and lassi ed them in two groups: formulas of onjun tive type (
rules, also known as linear type rules) and formulas of disjun tive type ( rules, also known as bran hing type rules).
The formulas of onjuntive type are represented by the greek letter . He uses \ " to stand for any signed formula
of type A|i.e. of one of the ve forms T (A ^ B ); F (A _ B ); F (A ! B ); T :A; F :A. For every su h formula, he
de nes the two formulas 1 and 2 as follows:
If T (A ^ B ), then 1 = T A and 2 = T B
If F (A _ B ), then 1 = F A and 2 = F B
If F (A ! B ), then 1 = T A and 2 = F B
If T :A, then 1 = F A and 2 = F A
If F :A, then 1 = T A and 2 = T A
This is summarized in the following table:


T (A ^ B )
F (A _ B )
T (A ! B )
T :A
F :A

1
TA
FA
TA
FA
TA

2
TB
FB
FB
FA
TA

The letter is used to stand for formulas of disjun tive type. These are the formulas of type B |i.e. one of
the three forms F (A ^ B ); T (A _ B ); T (A ! B ). For every su h formula , the two formulas 1 ; 2 are as in the
following table:

1 2

F (A ^ B ) F A F B
T (A _ B ) T A T B
T (A ! B ) F A T B
Therefore, all tableau rules an be resumed to the following two:

T :A
FA

T (A ^ B )
TA
TB

F :A
TA

T :)

F :)

T ^)

F (A ^ B )
F A jF B

T _)

F (A _ B )
FA
FB

T (A _ B )
T A jT B

T (A ! B )
F A jT B

F (A ! B )
TA
FB

F ^)
F ^)

Figure 1: Analyti tableau expansion rules

A Rule:


1
2

B Rule:


1 j 2

As an example, let us see a tableau proof of (A ^ B ) ! (A _ B )

F (A ^ B ) ! (A _ B )
T A^B
F A_B
TA
TB
FA
X

2.2.4 Pre ise De nition


Given the de nitions above, Smullyan ould present the following de nition [Smu68:
An analyti tableau for X is an ordered dyadi tree, whose points are (o uren es of) formulas, whi h
is onstru ted as follows. We start by pla ing X at the origin. Now suppose T is a tableau for X whi h
has already been onstru ted; let Y be an end point. Then we may extend T by either of the following
two operations.
(A) If some o urs on the path PY , then we may adjoin either 1 or 2 as the sole su essor of Y . (In
pra ti e, we usually su essively adjoin 1 and then 2 .)
(B) If some o urs on the path PY , then we may simultaneously adjoin 1 as the left su essor of Y
and 2 as the right su essor of Y .
The above indu tive de nition of tableau for X an be made expli it as follows. Given two ordered
dyadi trees T1 and T2 , whose points are o urren es of formulas, we all T2 a dire t extension of T1 if T2
an be obtained from T1 by one appli ation of the operation (A) or (B) above. Then T is a tableau for
X if and only if there exists a nite sequen e (T1 ; T2 ; : : : ; Tn = T ) su h that T1 is a 1-point tree whose
origin is X and su h that for ea h i < n; Ti+1 is a dire t extension of Ti .
A bran h  of a tableau for signed formulas is losed if it ontains some signed formula and its onjugate. And
T is alled losed if every bran h of T is losed. By a proof of an unsigned formula X is meant a losed tableau for
F X.
In [?, Smullyan proves the onsisten y and ompletenes of this system for propositional logi . Among other
things, he uses Hintikka's downward saturated sets in his proof.

3 Considerations about Tableau Systems


In [Fit99 one an see that there are several kinds of tableau systems for di erent logi s. He also points that tableau
systems are a good basis for the development of theorem-provers, although sometimes they may not turn out to be
the most e ient approa h to automated theorem-proving. But sin e tableau systems are relatively easy to develop,
they will always have an important role in automated theorem proving, even when theorem-provers are not based
on, but only derived from them.
Mar ello DAgostino in [DAg99 dis usses some important onsiderations about tableau systems and presents a
variant over Smullyan's Analyti Tableaux: the KE System.
He motivates his study by remembering that when Wittgenstein and Post independently devised (ba k in the
1920s) the well-known de ision pro edure based on the truth-tables, it was thought that the dedu ibility problem
of lassi al propositional logi was solved. However, the truth-table method requires he king 2n rows for a formula
with n di erent propositional variables. That is, it is a very ine ient algorithm, even for relatively small values of
n.
Besides that, reinfor ing the importan e of the analysis of proof pro edures asso iated with a logi , Gabbay
stated in [Gab96 that:
5

\a logi al system L is not just the traditional onsequen e relation `, but a pair (`; S` ), where `
is a mathemati ally de ned onsequen e relation (i.e. a set of pairs (; Q) su h that  ` Q) and S` is
an algorithmi system for generating all those pairs. Thus, a ording to this de nition, lassi al logi
` per eived as a set of tautologies together with a Gentzen system S` is not the same as lassi al logi
together with the two-valued truth-table de ision pro edure T` for it. In our on eptual framework,
(`; S` ) is not the same logi as (`; T` )."
D'Agostino argues that Gentzen's natural dedu tion is not really `natural', that is, it does not ome `as lose
to a tual reasoning' as Gentzen wrote in 1935. A ording to D'Agostino, \natural dedu tion rules do not apture
the lassi al meaning of the logi al operators" but, instead, natural dedu tion rules are a reading of Heyting's
explanations of the onstru tive meaning of the logi al operators.
He shows that some proofs in the natural dedu tion system, su h as that for one of the deMorgan's laws:
:(P ^ Q) ! (:P _ :Q)
are rather unnatural (See [DAg99, page 64).
D'Agostino also shows that some Cut free sequent proofs are very redundant as well as some tableau proofs. He
proves that the tableau system and ut free sequent al ulus are intrinsi ally redundant. Therefore, he on ludes,
\su h systems are not natural for lassi al logi ".

3.1 The KE System


D'Agostino states that tableau rules are not really lassi al sin e one of the two prin iples that form the basis of
the lassi al notion of truth, the Prin iple of Bivalen e, is not learly present in the tableau system. The prin iple
of bivalen e (also known as the Prin iple of the Ex luded Middle) states that every proposition is either true or
false, and there are no other possibilities. On the other hand, the other prin iple, the prin iple of Non- ontradi tion,
whi h asserts that no proposition an be true and false at the same time, is learly embodied in the rule for losing
a bran h in a tableau system.
Later D'Agostino presents the KE System, a refutation system that, he argues, though \being lose to the tableau
method, is not a e ted by the anomalies of ut-free systems." KE-Tableaux are very similar to Analyti Tableaux
be ause they also use signed formulas, have expansion rules with premises and on lusions and have the same rules
for the onstru tion of the initial tableau and the losing of the tableau.
D'Agostino proposed KE-Tableaux as an improvement, in the omputaional sense, over Smullyan's Analyti
Tableaux. He proved that a anoni al restri tion of the KE System an polynomially simulate the tableau method
but the tableau method annot polinomially simulate the anoni al restri tion of KE2 . That is, the KE System is a
`natural' proof method and it is more e ient than Smullyan's tableaux.
The set of rules for the KE System (see Figure 2) has only one rule of the bran hing type, the PB rule,
orresponding to the prin iple of bivalen e. With this rule, in onjun tion with the usual tableau rules, it is
not di ult to onstru t short refutations of the `hard examples' he showed for Smullyan's tableaux.
Besides that, the KE System introdu es simple elimination rules of linear type whi h ombined with PB yield
a refutation system for lassi al logi . And he also requires that the system is restri ted to analyti appli ations of
PB, i.e. appli ations whi h do not violate the subformula property.

4 Modi ations in the implementation


In his MS . dissertation [Dia02, Wagner Dias presented a framework for tableaux methods. One of the lasses
in this frammework is the Formula lass, whi h represents a formula. In the system implemented based on this
framework, a formula obje t is onstru ted by parsing a string using a fun tion alled parse. This fun tion does not
identify when two subformulas of a formula are the same and it always reates new instan es of any formula, either
atomi or omposite, that appears during the parse.
For instan e, if the string is:
A ! (B _ A)
the parse fun tion reates 5 formulas (5 instan es of the Formula lass), one for ea h subformula of the main formula:

2 In other words, for ea h analyti tableau proof of size n, there is a KE-Tableau proof with size polynomial in n.
one proof in KE-Tableau of size

n whose orresponding proof in Analyti


6

Tableaux has size superpolynomial in

n.

But there is at least

Disjun tion Rules


T A_B
FA
TB

T A_B
FB
TA

T _ 1)

(E

F A_B
FA
FB

T _ 2)

(E

(E

F _)

Conjun tion Rules


F A^B
TA
FB

(E

F A^B
TB
FA

F ^ 1)

(E

TA^B
TA
TB

F ^ 2)

T ^)

(E

Impli ation Rules


TA!B
TA
TB

(E

TA!B
FB
FA

1)

(E

2)

FA!B
TA
FB

Negation Rules
T :A
FA

F :A
TA

T :)

(E

(E

F :)

Prin iple of Bivalen e


T AjF A

(PB)

Figure 2: KE tableau expansion rules

(E

1. A
2. B
3. A
4. B ^ A
5. A ! (B _ A)
But sin e the third formula is equal to the rst, both ould be represented by two pointers to the same atom.
We modi ed Wagner Dias's system so that we have two ve tors of formulas: one for atomi formulas and other
for omposite formulas. In this representation, for the formula above we would have:

index
0
1

atomi formula
A
B

index
2
3

omposite formula
B_A
A ! (B _ A )

internal representation
1_0
0!2

In Wagner Dias's system, the prove program re eives a le ontaining a set of signed formulas and builds a
tableau for this set using one of the methods (analyti , KE or KES3) present in the framework. As a result, the
program shows the total number of nodes of the tableau, the total number of formulae and the elapsed time (in
se onds) ne essary for the onstru tion of the tableau. Optionally, it also shows a text representation of the tableau
proof. For instan e,
prove -m analyti -f gamma1.prove

builds an analyti tableau proof for the 1 set of formulas. And


prove -m ke -v -f gamma2.prove

builds and shows (-v option) a KE tableau proof for the 2 set of formulas.
In both ases above, the readProve fun tion is used to all parse on the set of formulas3 . The readProve fun tion
re eives as input a sequen e of strings su h as the one below for the 1 set of formulas:
T(a1|b1)
T(a1->(a2|b2))
T(b1->(a2|b2))
F(a2|b2)

and returns true if all formulas are well-formed and false otherwise. A tually, it re eives two parameters: the string
with the formulas and a pointer to a ve tor of signed formulas. If the string ontains only well-formed formulas, the
ve tor of signed formulas will re eive, for ea h line in the string, an obje t of the SignedFormula lass. This obje t
will be the result of alling the onstru tor of SignedFormula with two parameters:
1. the sign, whi h is one of the two onstants of the SignedFormula lass: SignedFormula::S T or SignedFormula::S F depending, of ourse, on the rst hara ter of the line and
2. the Formula obje t whi h is the result of applying parse to the hara ters on the line after the sign.
The ode for this fun tion is shown below:

3 There is also a readCNF fun tion whi h reads formulas in onjun tive normal form, but we have not used it.
8

bool readProve( onst string& file, ve tor<SignedFormula *>& v)


{
string s_fml;
har sign;
Formula *p_fml;
ifstream in(file. _str());
in >> sign;
in >> s_fml;
while (!in.eof()) {
p_fml = parse(s_fml);
if (p_fml) {
v.push_ba k(new SignedFormula(
sign=='T'?SignedFormula::S_T:SignedFormula::S_F,
p_fml));
}
else {
in. lose();
return false;
}
in >> sign;
in >> s_fml;
}
in. lose();
return true;
}

The all to readProve or readCNF fun tions depends on the extension of the le passed as a parameter to the
prove program after the -f option. If the le extension is `. nf' it alls readCNF, whilst if the le extension is
`.prove', it alls readProve. Below we show the lines that de lare the ve tor of signed formulas whi h re eives the
SignedFormula obje ts and, after that, all readCNF or readProve:
ve tor<SignedFormula *> v;
bool read_ok;
if ( nf)
read_ok = readCNF(file, v);
else
read_ok = readProve(file, v);

Then, in the main fun tion a Tableau obje t is de lared:


Tableau *tab;

And this obje t is initialized with an obje t of the lass that implements the spe i tableau method hosen in the
parameters passed to the prove program. The onstru tor of this lass re eives as parameter the ve tor ontaining
the set of formulas. For, instan e, for the `-m analyti ' option, the program would initialize the Tableau obje t in
the following way:
if (method == "analyti ") {
tab = new Analyti Tableau("1", v);
((Analyti Tableau *) tab)->setStrategy(new Analyti Strategy());
}

Noti e that in the last line a strategy is set for the Tableau obje t. The hoi e of strategy also depends on the
parameters given to the prove program.
Finally, the line
bool losed = tab-> lose();
9

alls a method that tries to lose the tableau. If it is su essful, the method returns true. Otherwise, it returns false.
Following is the new version of the readProve fun tion. It basi ally uses two ve tors to store the atomi formulas
and the omposite formulas.
bool readProve( onst string& file, ve tor<SignedFormula *>& v)
{
string s_fml;
har sign;
Formula *p_fml;
ve tor <Formula *> atomi Formulas, ompoundFormulas;
ifstream in(file. _str());
in >> sign;
in >> s_fml;
while (!in.eof()) {
p_fml = parse2(s_fml, &atomi Formulas, & ompoundFormulas);
if (p_fml) {
v.push_ba k(new SignedFormula(
sign=='T'?SignedFormula::S_T:SignedFormula::S_F,
p_fml));
}
else {
in. lose();
return false;
}
in >> sign;
in >> s_fml;
}
in. lose();
}

return true;

4.1 Modi ations in the Formula lass


A tually only one modi ation was ne essary in the Formula lass. The other modi ations were made in fun tions
that used instan es of this lasse. As one an see below, the destru tor of the Formula lass in Wagners system
deallo ates memory of all its subformulas. Now we annot do this anymore be ause the subformulas of a formula
an be subformulas of other formulas.
Formula::~Formula()
{
// removed be ause it is not adequate anymore
/* if (left)
delete left;
if (right)
delete right;
for (unsigned int i = 0; i < fmls.size(); i++)
delete fmls[i;
*/
}

These are new fun tions needed for the new parse:
10

// returns a previously allo ated pointer to a formula (an element of the "formulas"
// ve tor) if there is a formula equal to "aFormula" in this ve tor. Otherwise,
// returns NULL.
Formula *in ludes (ve tor <Formula *> formulas, Formula * aFormula){
for (unsigned int i = 0; i!=formulas.size(); i++){
if (equalFormula (aFormula, formulas[i))
return formulas[i;
}
};

return NULL;

// Insert a formula in the ve tor of formulas used by parse


// only if the formula is not there
void insert (ve tor <Formula *> *formulas, Formula *aux,
Formula **pFormula){
// if the formula "aux" has not already been parsed
Formula *aFormula = in ludes (*formulas, aux);
if (aFormula == NULL){
// returns it (as pFormula) and inserts it into the
// ve tor of formulas
(*pFormula) = aux;
formulas->push_ba k(*pFormula);
} else {
// otherwise returns the previously allo ated
// formula "aFormula" and deletes the re ently
// reated formula "aux".
(*pFormula) = aFormula;
delete aux;
};
}

And below is the new parse fun tion. It is named parse2. It re eives three parameters { bsides the string from
whi h the formula is parsed, it re eives two pointers to the two ve tors of atomi formulas and ompound formulas
already parsed in previous parses of the same tableau. This is ne esseary so that for ea h tableau ea h formula be
reated only on e.
//
//
//
//

Parse a formula from a string. The formula (and its subformulas


ex ept atoms) must be en losed in parenthesis. Returns a newly
allo ated pointer to the formula represented by the string or a
null pointer if the string is not a valid formula.

// Re eives a ve tor of atomi formulas and a ve tor of ompound


// formulas of previous parses (if ne essary).
Formula *parse2( onst string& s, ve tor <Formula *> *atomi Formulas,
ve tor<Formula *> * ompoundFormulas)
{
Formula *retval;
unsigned int i;
sta k<parsed_item> S;
11

for (i = 0; i < s.size(); ) {


parsed_item item;
if (s[i == ' ')
i++;
else
if (s[i == '(') {
item.type = PARSE_OPEN;
S.push(item);
i++;
} else
if (isalnum(s[i)) {
string a;
while (i < s.size() && (isalnum(s[i) || s[i == '_' || s[i == ',')) {
a += s[i;
i++;
}
item.type = PARSE_FORM;
if (!S.empty() && S.top().type == PARSE_OPER && S.top().op == Formula::NOT) {
// insert a negated atomi formula in the list of formulas
// (if it is a new one)
// reates a new atom only if ne essary
Formula * auxAtom1 = new Formula(a), *auxAtom2;
insert (atomi Formulas, auxAtom1, &auxAtom2);
Formula * aux = new Formula(Formula::NOT, auxAtom2);
insert ( ompoundFormulas, aux, &(item.formula));
S.pop();
}else {
// insert an atomi formula in the list of formulas
// (if it is a new one)
Formula * aux = new Formula(a);
insert (atomi Formulas, aux, &(item.formula));
}
S.push(item);
}else
if (s[i == '!') {
item.type = PARSE_OPER;
item.op = Formula::NOT;
S.push(item);
i++;
} else
if (s[i == '&') {
item.type = PARSE_OPER;
item.op = Formula::AND;
S.push(item);
i++;
} else
if (s[i == '|') {
item.type = PARSE_OPER;
item.op = Formula::OR;
S.push(item);
12

i++;
}
else
if (i+1 < s.size() && s[i == '-' && s[i+1 == '>') {
item.type = PARSE_OPER;
item.op = Formula::IMPLIES;
S.push(item);
i = i + 2;
}
else
if (s[i == ')') {
Formula *result;
assert(!S.empty() && S.top().type == PARSE_FORM);
ve tor<Formula *> fmls;
fmls.push_ba k(S.top().formula);
S.pop();
assert(!S.empty() &&
(S.top().type == PARSE_OPEN || S.top().type == PARSE_OPER));
Formula::opType op = S.top().op;
while (S.top().type == PARSE_OPER) {
assert(op == S.top().op);
S.pop();
assert(!S.empty() && S.top().type == PARSE_FORM);
// puts a formula in fmls
fmls.insert(fmls.begin(), S.top().formula);
S.pop();
}
// removes opening parenthesis from the sta k
assert(!S.empty() && S.top().type == PARSE_OPEN);
S.pop();
if (fmls.size() > 2) {
assert (op == Formula::AND || op == Formula::OR);
if (op == Formula::AND)
op = Formula::ANDN;
else
op = Formula::ORN;
Formula *aux = new Formula (op, fmls);
insert ( ompoundFormulas, aux, &result);
}else if (fmls.size() == 2){
Formula *aux = new Formula(op, fmls[0, fmls[1);
// insert a formula in the list of formulas
// (if it is a new one)
13

insert ( ompoundFormulas, aux, &result);


}
else // fmls.size() == 1
result = fmls[0;
item.type = PARSE_FORM;
if (!S.empty() && S.top().type == PARSE_OPER &&
S.top().op == Formula::NOT) {
// insert a formula in the list of formulas
// (if it is a new one)
Formula *aux = new Formula(Formula::NOT, result);
insert ( ompoundFormulas, aux, &(item.formula));
S.pop();
} else
item.formula = result;
S.push(item);
i++;
}
}
assert(!S.empty() && S.top().type == PARSE_FORM);
retval = S.top().formula;
S.pop();
assert(S.empty());
return retval;
}

We kept a parse fun tion that alls parse2 passing two ve tors that are not further used. It makes use of the
equalVe tors fun tion right below it.
// Calls parse2 passing two ve tors. Used when you do not want
// to take into a ount the atomi formulas and the ompoound
// formulas.
Formula *parse( onst string& s)
{
ve tor<Formula *> atomi Formulas, ompoundFormulas;
return parse2 (s, &atomi Formulas, & ompoundFormulas);
}

In order to he k if a formula was equal to another formula already parsed we had to implement teh following
fun tion that he ks if the ontent of a formula obje t is equal to anothers ontent.
// Returns true if a formula is synta ti ally equal to another formula
bool equalFormula (Formula* aFormula, Formula *anotherFormula){
if (aFormula->op != anotherFormula->op){
return false;
}
14

else {
swit h (aFormula->op) {
ase Formula::ATOM:
{
if (aFormula->atom == anotherFormula->atom)
return true;
else
return false;
}
break;
ase Formula::NOT:
{
return equalFormula (aFormula->right, anotherFormula->right);
}
break;
ase Formula::IMPLIES:
{
return (equalFormula (aFormula->right, anotherFormula->right) &&
equalFormula (aFormula->left, anotherFormula->left));
}
break;
ase Formula::OR: ase Formula::AND:
{
return ( (equalFormula (aFormula->right, anotherFormula->right)
&&
equalFormula (aFormula->left, anotherFormula->left)));
}
break;
ase Formula::ORN: ase Formula::ANDN:
{
if (equalVe tors (aFormula->fmls, anotherFormula->fmls))
return true;
else return false;
}
}
};
return false;
}
// returns true if the ve tors ontain the same formulas
// (a ording to equalFormula) in the same order
bool equalVe tors (ve tor<Formula *> v1, ve tor<Formula *> v2){
if (v1.size() != v2.size())
return false;
else {
for (unsigned int i = 0; i!=v1.size(); i++){
15

if (!(equalFormula (v1[i, v2[i) )){


return false;

}
}

return true;
};

4.2 Modi ations in other lasses


Having modi ed the parsing of formulas, we had to hange more three lasses (Tableau, TableauStrategy and
KETableau) so that we ould use the information about atomi and omposite formulas of a tableaux.
First, we had to make a modi ation in the format of rules that are used by tableau obje ts and tableau strategy
obje ts. Previously, these rules re eived only two parameters: the ve tors of signed formulas that are, respe tively,
input to and output from a rule. Now we have to re eive also the ve tor of all signed formulas in the tableau as well
as the ve tors of atomi and ompound formulas.
//////////////////////////////////////////////////////////////////////////////
// A rule is a pointer to a fun tion returning bool and having the
// input and output formulas as parameters.
//////////////////////////////////////////////////////////////////////////////
typedef bool (*Rule)( onst ve tor<SignedFormula *>&, ve tor<SignedFormula *>&,
ve tor<SignedFormula *>&,
ve tor<Formula *>&, ve tor<Formula *>&);

We had to make some hanges in the TableauStrategy lass, always following this pattern: adding the ve tor of
all signed formulas in the tableau as well as the ve tors of atomi and ompound formulas.
lass TableauStrategy
{
publi :
TableauStrategy();
virtual ~TableauStrategy();
// initializes the obje t with the items of a tableau. Returns true
// if the tableau is already lose. This method also uses the
// Floyd-Warshall algorithm to al ulate the minimum distan e
// between ea h pair of atoms.
virtual bool init( onst string& tableau_id,
ve tor<SignedFormula *> *items,
ve tor<SignedFormula *> *alphas,
ve tor<SignedFormula *> *betas,
ve tor<SignedFormula *> *lits,
ve tor<Formula *> *atomi Formulas,
ve tor<Formula *> * ompoundFormulas
);
(...)
// Atomi formulae of the tableau.
ve tor<Formula *> *_atomi Formulas;

16

// Compound formulae of the tableau.


ve tor<Formula *> *_ ompoundFormulas;
(...)
}

And it was ne essary to make modi ations in the applyRule method that alls rules, sin e we hanged the
format of rules:
bool Tableau::applyRule(unsigned int index,
onst ve tor<SignedFormula *>& in,
ve tor<SignedFormula *>& out,
ve tor<SignedFormula *>& items,
ve tor<Formula *>& atomi Formulas,
ve tor<Formula *>& ompoundFormulas)
{
if (index < _rules.size())
return (*_rules[index)(in, out, items, atomi Formulas, ompoundFormulas);
return false;
}

The implementation of all rules had to be modi ed be ause no new formulas or signed formulas should be reated
by them. In order to a hieve this obje tive, we had to implement four fun tions:
 aSignedFormula { returns a pointer to a new signed formula if there is no signed formula in items (with the
same sign and formula pointer) or to an existing formula.
 pushBa kIfNew { very similar to the previous fun tion, it pushes a new signed formula in items only if it is
not already there.
 aSignedFormulaIndex is the same as aSignedFormula only that it returns an index to the formula in the items
ve tor (if it is there) or -1 (in ase it is not there).
 aFormulaIndex { returns an index of a formula in a ve tor of formulas, or -1 if the ve tor does not in lude the
formula.
The ode for these fun tions is presented below:
SignedFormula *aSignedFormula(SignedFormula::Sign sign, Formula *fml,
ve tor<SignedFormula *>& items,
ve tor<Formula *>& atomi Formulas, ve tor<Formula *>& ompoundFormulas){
// verifies if the Signed Formula is in items. If it is, returns it. Otherwise,
// reates it.
for (unsigned int i=0; i< items.size(); i++){
if ( ( (items[i)->sign == sign
) &&
( (items[i)->formula == fml ) ) {
return items[i;
};
};
}

return new SignedFormula (sign, fml);

void pushBa kIfNew (ve tor <SignedFormula *>& aVe tor, SignedFormula::Sign sign, Formula *fml,
ve tor<SignedFormula *>& items,
17

ve tor<Formula *>& atomi Formulas, ve tor<Formula *>& ompoundFormulas){


// verifies if the Signed Formula is in items. If it is, returns it. Otherwise,
// reates it.
for (unsigned int i=0; i< items.size(); i++){
if ( ( (items[i)->sign == sign
) &&
( (items[i)->formula == fml ) ) {
return;
};
};
}

aVe tor.push_ba k(new SignedFormula (sign, fml));;

int aSignedFormulaIndex(SignedFormula::Sign sign, Formula *fml,


ve tor<SignedFormula *>& items,
ve tor<Formula *>& atomi Formulas, ve tor<Formula *>& ompoundFormulas){
// verifies if the Signed Formula is in items. If it is, returns its index. Otherwise,
// returns -1.
for (unsigned int i=0; i< items.size(); i++){
if ( ( (items[i)->sign == sign
) &&
( (items[i)->formula == fml ) ) {
return i;
};
};
}

return -1;

int aFormulaIndex(Formula *fml, ve tor<Formula *>& formulas){


// verifies if the formula is in ve tor formulas. If it is, returns its index. Otherwise,
// returns -1.
for (unsigned int i=0; i< formulas.size(); i++){
if ( formulas[i == fml) {
return i;
};
};
}

return -1;

Below is an example of a rule whose implementation was hanged:


bool KE_alpha_E_NOT_OR( onst ve tor<SignedFormula *>& in,
ve tor<SignedFormula *>& out,
ve tor<SignedFormula *>& items,
ve tor<Formula *>& atomi Formulas, ve tor<Formula *>& ompoundFormulas)
{
if (! (in.size() == 1 && in[0 && in[0->sign == SignedFormula::S_F &&
in[0->formula && in[0->formula->op == Formula::OR)) return false;

18

pushBa kIfNew(out,SignedFormula::S_F,
in[0->formula->left,
items, atomi Formulas, ompoundFormulas);
pushBa kIfNew(out, SignedFormula::S_F,
in[0->formula->right,
items, atomi Formulas, ompoundFormulas);
}

return true;

5 Families of formulas
In order to make omparative tests for the tableaux methods implemented in his dissertation, Dias [Dia02 onsidered
the following sets of formulas that are well known as di ult.

5.1
The

formulas
family of formulas [CS00 has the following form:

The

p1 ! (p2 _ q2 )
q1 ! (p2 _ q2 )
..
.
pi ! (pi+1 _ qi+1 )
qi ! (pi+1 _ qi+1 )

family has 2n formulas and 2n propositional variables. The sequent that one wants to prove is:

p1 _ q1 ;

` pn+1 _ qn+1

This family has ut-free proofs of size exponential and non-exponential in n.

5.2

H formulas

The H formulas, or fat formulas, were de ned in [DAg92 in order to prove that Smullyan's analyti tableaux did not
polinomially simulate truth-tables. A H formula is onstru ted in the following way: let p1 ; : : : ; pn be propositional
variables and onsider all possible disjun tions ontaining either li or li , where li = pi and li = :pi , and i = 1; : : : ; n.
The problem onsists in showing that the onjun tion of these disjun tions is unsatis able. The size of the problem
is the number of variables n. The initial number of formulas is one but the size of this formula is of order 2n .

5.3 Statman formulas


The Statman formulas [Sta78 have the following form:

p0 _ q0
((p0 _ q0 ) ! p1 ) _ ((p0 _ q0 ) ! q1 )
((p0 _ q0 ) ^ (p1 _ q1 ) ! p2 ) _ ((p0 _ q0 ) ^ (p1 _ q1 ) ! q2 )
..
.
((p0 _ q0 ) ^ (p1 _ q1 ) ^ : : : ^ (pi 1 _ qi 1 ) ! pi ) _ ((p0 _ q0 ) ^ (p1 _ q1 ) ^ : : : ^ (pi 1 _ qi 1 ) ! qi )
The problem is to de ide if pi ^ qi an be dedu ed from the set of formulas above. This family admits short
proofs with the use of the ut rule, but only exponential proof without ut.

19

5.4 PHP formulas


The formulas in the PHP (Pigeon Hole Prin iple) familiy [CS00 des ribe the problem of pla ing n + 1 letters in n
pigeon holes. A ording to the Pigeon Hole Prin iple, there is always one pigeon hole whi h will re eive at least two
letters. The family has the following form:
(p11 _ p12 _ : : : _ p1 n 1 )
(p21 _ p22 _ : : : _ p2 n 1 )
..
.
(pn1 _ pn2 _ : : : _ pn n 1 )
((p11 ^ p21 ) _ (p11 ^ p31 ) _ : : : _ (p11 ^ pn1 )
((p21 ^ p31 ) _ (p21 ^ p41 ) _ : : : _ (p21 ^ pn1 )
..
.
((pn 1 1 ^ pn1 ))
..
.
((p1n ^ p2n ) _ (p1n ^ p3n ) _ : : : _ (p1n ^ pn n )
((p2n ^ p3n ) _ (p2n ^ p4n ) _ : : : _ (p2n ^ pn n )
..
.
((pn 1 n ^ pn n ))

^
^
^
!
^
^
^
_
^
^
^

where pij means that the letter i is in pigeon hole j . The problem onsists in proving that the formula above is valid.
The problem with size n has n  (n 1) propositional variables and the formula's size is of order n3 . Cut-free proofs
of this problem are exponential. This problem auses a lot of bran hing and seems to be exponential, although there
is a proof by Buss that is polynomial.

6 Test results
We have tested both implementations with some instan es of the families of formulas presented in se tion [? in a
personal omputer. One an noti e that although the number of formulas in the losed tableaus de reased a little,
the number of nodes remained the same and the time spent for the losing of ea h tableau did not always de rease.
We believe this happened be ause there is an overhead asso iated with the sharing of subformulas. Below we present
the results.

6.1
Instan e
1
2
3
4
5
6
7
8

formulas
# nodes
3
13
37
109
325
973
2917
8749

Changed version
# formulas Time (s)
13
0.000363
41
0.002388
112
0.011127
321
0.086773
944
0.283089
2809
0.955900
8400
3.635644
25169
13.903300

# nodes
3
13
37
109
325
973
2917
8749

20

Original version
# formulas Time (s)
13
0.000351
42
0.002353
117
0.010763
338
0.047102
997
0.193968
2970
0.927524
8885
3.410045
26626
12.979512

6.2

H formulas

Instan e
H1
H2
H3
H4
H5

# nodes
1
3
21
105
465

Changed version
# formulas Time (s)
4
0.000040
15
0.000938
99
0.004384
669
0.094125
4761
2.574431

# nodes
1
3
21
105
465

Original version
# formulas Time (s)
4
0.000048
17
0.000329
103
0.004664
677
0.100072
4777
2.709676

6.3 Statman formulas


Instan e
Statman1
Statman2
Statman3
Statman4
Statman5
Statman6

# nodes
1
7
31
207
1079
5391

Changed version
# formulas Time (s)
5
0.000063
30
0.000901
124
0.008043
697
0.139583
3538
1.125550
18371
10.263416

# nodes
1
7
31
207
1079
5391

6.4 PHP formulas


Instan e
PHP1
PHP2
PHP3
PHP4

# nodes
1
3
61
483

Changed version
# formulas Time (s)
6
0.000072
26
0.000674
251
0.045288
2159
1.917854

# nodes
1
3
61
483

Original version
# formulas Time (s)
5
0.000069
30
0.000876
124
0.008224
711
0.098986
3696
1.176937
19539
10.126263

Original version
# formulas Time (s)
6
0.000088
29
0.000694
261
0.046799
2219
2.385304

7 Con lusion
In his MS . Dissertation [Dia02, Wagner Dias presented an obje t-oriented framework for tableaux methods. And
he also gave an implementation of this framework in the C++ programming language. His implementation overed
three tableaux methods: Smullyan's Analyti Tableaux, D'Agostino's KE Tableaux and Finger and Wasserman's
KE-S3 Tableaux. Our problem was to make some modi ations in his implementation so that KE Tableau proofs
be ame shorter. With this in mind, we rst had to make hanges in the representation of formulas, be ause the
original implementation did not take advantage of the fa t that some formulas may share subformulas. Then we
had to modify the Formula lass, as well as the lasses Tableau, TableauStrategy and KETableau. In this paper we
presented the major modi ations we have made.
We have run tests with both implementations and noti ed that, although the number of formulas in the losed
tableaus de reased a little, the number of nodes remained the same and the time spent for the losing of ea h tableau
did not always de rease, be ause there is an overhead asso iated with the sharing of subformulas.

7.1 Future works


First we will try to redu e the number of nodes of some losed KE Tableaus by allowing losing not only with atomi
formulas, but also with omposite formulas (e.g. T A _ B and F A _ B ). This will be relatively easy to implement
now that we have hanged the representation of formulas. Let us see if this diminishes or in reases the time spent
for losing, sin e su h strategy will result in more formulas to look at when sear hing for a losing ase.
Next, by also making use of the new representation of formulas, we shall try to apply some KE beta rules faster.
For instan e, if T X ! B and T X , then just by noti ing that X in both signed formulas is the same formula, we
an arrive at T B .
And nally, in a later stage, we intend to use aspe t-oriented programming te hniques for the development of a
more general framework for tableaux methods. Wagner Dias's framework is limited to lassi al logi . Why not have
21

a framework also for implementing tableaux methods for substru tural logi s or fuzzy logi , for instan e? Maybe
aspe ts, by giving us another dimension, an help us with that job.

22

A A personal evaluation on the experien e of rewriting ode


In Software Engineering books there are many listings of the advantages and disadvantages of rewriting ode. Here
I will give a personal evaluation based on my experien e with Wagner Dias's C++ implementation.
It is obvious that the rst thing one must do when he wants to modify somebody else's system is to understand
what has been done. It is not di ult to understand what Wagner has done be ause his ode is reasonably well
written and well ommented. That is, lasses, instan e variables and methods have adequate names, and there are
some omments for ea h major lass or method. Besides that, his dissertation des ribing the framework he used
helped a lot.
But of ourse there were problems:
 There were some errors aused by something obvious that I did not per eive until it happened. We all known
that a hange in one pla e may always ause an unante ipated result in other part of the system, ausing an
error. Sometimes this `unanti ipated' result is not so surprising { the problem is that we were not areful
enough. Computer programming is an a tivity that stimulates la k of dis ipline, says Valdemar Setzer. For
instan e, Wagner's destru tor for the Formula lass re ursively deallo ated memory for all the subformulas of
a formula. Sin e in our version we ould be sharing subformulas with other formulas, the destru tor had to be
modi ed (a tually it does nothing now). But I only noti ed that when the system rashed : : :
 I did not use any debugging environment. If the system were written in Smalltalk, for example, it would be
mu h easier to dis over the ontents of ea h data stru ture during exe ution, be ause Smalltalk has an ex ellent
debugging environment.
 There are some de isions that may help in one aspe t but be prejudi ial in others. For example, in a Tableau
obje t, all signed formulas of the tableau are stored in a ve tor alled items. But when this tableau is the hild
of another tableau, only the formulas that are new to this hild are stored in items. This saves memory but
makes it more di ult to dis over a losing ase and to he k if a signed formula that is going to be added to
the tableau is already in its list of signed formulas. But when I tried to hange items so that it would in lude
pointers to all signed formulas of the tableau up to that hild, I dis overed that the toString() method used
items to print a tableau proof, so I ould not hange this without some major modi ations in other parts of
the system.
 I did not have any ommuni ation with the writer of the ode.
Whenever a problem o ured I had to investigate the ode in order to dis over where and why it happened. I did
not think it was ne essary to study all the ode at on e, so I studied only the parts I would modify. And a tually
there are still some parts of the system whose working I still do not understand. However, there were some parts of
the ode that at rst I thought it would not be ne essary to understand but that ended up being relevant for my
modi ations.
In on lusion, it is a very enri hing experien e be ause I was really obliged to understand mu h of Wagner Dias's
system.

23

Referen es
[Bet59 E. W. Beth. The Foundations of Mathemati s, North Holland, 1959.
[CS00 A. Carbone and S. Semmes. A graphi al apology symmetry and impli itness. Oxford mathemati al Monographs, 2000.
[Dia02 Wagner Dias. Implementa ~oes de Tableaux para Ra io inio por Aproxima ~oes. Disserta ~ao de Mestrado,
Departamento de Ci^en ia da Computa ~ao, Instituto de Matemati a e Estatisti a, Universidade de S~ao
Paulo, 2002.
[DAg92 Mar ello DAgostino. Are tableaux improvement on truth-tables? Journal of Logi , Language and Information, 1992. Kluwer A ademi Publishers, 1999.
[DAg99 Mar ello DAgostino. Tableau Methods for Classi al Propositional Logi . In: Handbook of Tableau Methods,
Mar ello DAgostino et al. (eds), 45-123. Kluwer A ademi Publishers, 1999.
[Fit99 Melvin Fitting. Introdu tion. In: Handbook of Tableau Methods, Mar ello DAgostino et al. (eds), 1-43.
Kluwer A ademi Publishers, 1999.
[Gab96 Dov Gabbay. Labelled Dedu tive Systems, Volume 1 - Foundations. Oxford University Press, 1996.
[Sta78 R. Statman. Bounds for proof-sear h and speed-up in the predi ate al ulus. Annals of Mathemati al Logi ,
1978. Oxford University Press, 1996.
[Smu68 Raymond M. Smullyan. First-Order Logi . Springer-Verlag, 1968.
[Hin55 J. Hintikka. Form and ontent in quanti ation theory. A ta Philosophi a Fenni a. 8, 7-55, 1955.
[Gen35 G. Gentzen. Untersu hungen uber das logis he S hliessen. Mathematis he Zeits hrift 39, 176-210, 405-431,
1935. English translation, `Investigations into logi al dedu tion', in [Sza69.
[Mor01 Mortari, Cezar. Introdu ~ao a Logi a. Editora da UNESP, So Paulo, 2001.
[Sza69 M. E. Szabo, Ed. The Colle ted Papers of Gehrard Gentzen. North-Holland, Amsterdam, 1969.

24

S-ar putea să vă placă și