Internship report L3 Theorem proving in GeoGebra: Implementing

Internship report L3
Theorem proving in GeoGebra:
Implementing the area method into OpenGeoProver
Damien Desfontaines, supervised by Zoltán Kovács
May 21th 2012 - June 21th 2012
Abstract
GeoGebra is a well-known dynamic mathematics software, which includes features for algebra, statistics,
calculus, and which is mostly known for its geometry system. It is an educational software, used by many
teachers around the world.
Quite recently, the GeoGebra team decided to add a theorem proving feature into GeoGebra: before that,
when the user wanted to know if, on a given geometric gure, two lines were parallel, the only tool used to answer
that kind of questions was approximations and oating-point calculus. Since then, many work has been done
to implement automatic proving features into GeoGebra. Three methods have been internally implemented
(Recio's prover, PureSymbolic prover, and Botana's prover), and a stand-alone geometric theorem proving
system, OpenGeoProver, has been plugged to work with GeoGebra.
My work during this summer was to implement a brand new method, called the area method, along with
the other ones. This method can prove a dierent set of theorems (not bigger nor smaller, simply dierent).
Moreover, unlike the previous ones (algebraic ones), it is theoretically able to output simple, human-readable
proofs.
I have worked mainly with a paper written by Julien Narboux about an implementation of the area method
with Coq [1], and I have reproduced the steps of his work, adapting them to the GeoGebra input. I have thought
of several optimizations, to make the algorithm faster and to produce as readable as possible outputs.
1
Introduction
Thousands of students around the world use or have already used GeoGebra to learn mathematics and geometry. It
is usually when learning elementary geometry that the students learn how mathematical statements can be proved.
Thus the development team decided to implement a automated proving feature in GeoGebra as of version 5.0.
Several algebraic provers have been implemented, like Recio's [3]or Wu's [4], which are already able to prove many
well-known geometric statements. All these provers, which work dierently from each other, get totally distinct
benchmark results and can prove distinct sets of theorems. But they have one inconvenient in common: even if
they can give formal answers, the proofs generated are very algebraic, and highly unreadable.
GeoGebra, as a regular mentoring organization of the Google Summer of Code, chose me to implement during
the summer a new proving method along with the already-existing ones: the area method. This method has been
invented by Chou, Gao and Zhang in 1993 [2], and uses simpler concepts and geometric formulas to formally prove
geometric statements. It can deal with a dierent set of geometric gures and statements than the most known
algebraic methods.
The Google Summer of Code does not require the participating students to move away, but I chose to go to Austria,
where the main development of GeoGebra is done, to work directly with other interns and to experience working
in a public university, with researchers.
2
General idea of the area method
In this section, I will expose the principle of the area method.
Detailed explanations can be found in many
places [1, 2], but I will try here to make it possible for the reader to understand my work without knowing all the
details of the area method.
2.1
Objects and quantities used by the area method
The area method deals with very simple basic objects: a geometric gure is only seen as a particular set of points
with relations between those points, and a statement is a conjunction of equalities involving only three types of
geometric quantities.
2.1.1 Area method geometric quantities
The area method frequently use rational expressions in geometrical quantities. Here is how we dene such rational
expressions:
Denition 1.
A
geometrical quantity
is an expression of one of the three following types:
• SABC ,
representing the signed area of the triangle
• PABC ,
called the Pythagoras dierence of the points
•
ABC ,
−
−
→
AB
−
−
→ , the ratio between the directed collinear vectors
CD
−−→
−−→
such as AB = r CD , where A, B , C
and (CD) are parallel.
and
D
where
A, B
−−→
AB
and
and
A, B
C ,
−−→
CD,
and
C
are points.
dened as
PABC = AB 2 + BC 2 − AC 2 .
or, said dierently, the only number
are points. This makes sense only if
In Narboux' paper, two other shortcuts are used (SABCD and
PABCD ,
C 6= D
and if the lines
r∈R
(AB)
but we will not care about them in this
report).
Denition 2.
A
rational expression in geometrical quantities
• r,
where
r∈F
• q,
where
q
and where
F
is a sub-eld of
is an expression of the six following types:
R
is a geometrical quantity
• r1 + r2 ,
where
r1
and
r2
are rational expressions in geometrical quantities
• r1 − r2 ,
where
r1
and
r2
are rational expressions in geometrical quantities
• r1 ∗ r2 ,
•
r1
and
and
r2
where
r1
r2 , where
r1
r2
are rational expressions in geometrical quantities
are rational expressions in geometrical quantities
2.1.2 Area method geometric constructions
In the area method, all geometric constructions are points: more complex geometric objects like lines or circles are
seen as two distinct points, representing respectively two points through which the line passes, or the center and a
point of a circle.
Furthermore, there is only ve ways of constructing new points.
Denition 3.
An
elementary construction step
is one of the following ve point constructions:
1. Creating a new free point, anywhere in the plane this construction will be denoted as
2
P = Point ()
l1 and l2 ,
P = Intersection (U, V, P, Q)
2. Constructing the intersection between two non-parallel lines
points
(U, V )
and
(P, Q)
denoted as
3. Constructing the foot of a point
denoted as
U
and
l
seen as
(U, V )
a geometrical quantity
denoted as
r,
P = Foot (W, U, V )
constructing the point
V , and a geometrical quantity r, constructing
P = Tratio (U, V, r). Here is an outline to make it clearer:
5. Given two points
denoted as
on a line
V , and
P = Pratio (W, U, V, r).
4. Given three points
W, U
W
respectively seen as two couples of
and
the point
P
P
such as
such as
−−→
−−→
W P = rU V
4SU V Y
PU V U
= r
Figure 1: Tratio construction
With this set of elementary construction steps, one can construct many gures based on ruler and compass. For
[AB] is represented as the two points [P1 P2 ], where P1 = Pratio A, A, B, 21 ,
and P2 = Tratio (P1 , B, 1). Another example: if the points (O1 , P ) and (O2 , P ) represent two circles, the other
intersection between those two circles is the point Q such as Q = Pratio (P1 , P, P1 , 1), where P1 = Foot (P, O1 , O2 ).
example, the bisector line of a segment
Nonetheless, not all gures based on ruler and compass can be constructed with these elementary construction
steps: for example, one can not construct the intersection between two circles, or between one line and one circle,
in the general case.
Apart from this limitation, this set of construction steps allows us to construct many things: an arbitrary line or
circle can be constructed by creating two arbitrary free points, and the reader can verify that one can construct
an arbitrary point belonging to a given line or circle too.
Denition 4.
A
geometric gure
is a list
F = (C1 , ..., Cm ),
where
∀i ∈ [[1, m]], Ci
is an elementary construction
step.
2.1.3 Area method statements
Now that we have our geometric gures, let us describe with the concepts dened above a geometric statement as
seen by the area method.
Denition 5.
where
E1
and
Given a geometric gure
E2
F,
a
geometric statement
is a set of equalities of the form
E1 = E2 ,
are rational expressions in geometric quantities (in which, of course, all points appearing in the
geometrical quantities are dened in
F ).
A large majority of natural geometric properties can be described with this simple denition. Here is a table from
the Julien Narboux' paper, which shows several translations of geometric properties into area method geometric
statements:
Geometric property
Area method geometric statement
A and B are equal
A, B and C are collinear
Lines (AB) and (CD) are parallel
Lines (AB) and (CD) are perpendicular
\ and DEF
\ are equal
Angles ABC
Points A, B , C and D are concyclic
PABA = 0
SABC = 0
SABC = SABD
PACD = PBCD
SABC · PDEF = SDEF · PABC
SCAD · PCBD = SCBD · PCAD
Points
Points
Table 1: Connection between natural geometric properties and area method geometric statements
Several classic theorems can also be directly expressed with a geometric statement: Thales' theorem, for example,
or to pick a less-known example, Stewart's theorem :
Figure 2: Stewart's theorem construction
(D is any point on the line
(BC)).
The Stewart's theorem states that:
a · xy + p2 = x · b2 + y · c2
which can be re-written as:
(assuming
a 6= 0).
x
y
x 2
· y + p2 = · b2 + · c2
y
a
a
And as we can write ratios of collinear segments and squares of segment lengths (AB
2
= 12 PABA ),
we can express the Stewart's theorem with a geometric statement.
2.1.4 Non-degeneracy conditions
TODO
2.2
The area method algorithm
So, the prover algorithm will take a geometric gure and a geometric statement as an input ; and it must return
TRUE or FALSE as the result of the computation, whether all equalities of the geometric statement are veried
or not. To do so, it will modify the equalities into equivalent but simpler ones, until it nds an equality which is
trivially true or false.
4
2.2.1 Point elimination
If the given geometric gure
F = (C1 , ..., Cm )
constructs the point
Pi
at the step
i,
the area method algorithm
will remove one by one all construction points appearing in the geometric statement equalities. To achieve this,
eliminations lemmas are used. Here is a simple example:
Lemma. Let Y be a point constructed by Y
= Inter (U, V, P, Q). Then:
−→ ( SAP Q
if A ∈ (U V )
AY
SCP Q
−−→ = SAU V
otherwise
CY
SCU V
There is a dozen dierent elimination lemmas of this form, all transforming a given geometric quantity where a
point
P
appears into a rational expression in geometrical quantities, in which the point
P
does no longer appear,
but only points previously constructed. In the Appendix A, you will nd the exhaustive list of all the eliminations
lemmas.
By iterating the process, we can eliminate each constructed point to get a formula in which there is only free points
appearing. This is the rst step of the area method algorithm.
2.2.2 Transformation to an expression with independent variables
When we try to prove correct theorems, after the rst point elimination step, we often obtain equalities which
are - after simplication - trivially true.
SABC = SABD + SADC + SDBC
However, sometimes, this is not the case:
for example, the equality
is always true, but this kind of equality is not trivial.
In these cases, a additional step is needed: the geometric quantities (in which only free points appear) must be
transformed into independent variables. The
Denition 6.
(O, U, V )
Let
O, U
and
V
area coordinates
are used for this purpose.
be three non-collinear points. The
area coordinates
of a point
A
with respect to
are:
xA =
yA =
SOAV
,
SOU V
zA =
SAU V
SOU V
V are xed, there is a bijection between the points in a plane and their area coordinates.
SOU P and SOV P = −SOP V are independent. Furthermore, if OU ⊥ OV , OU = OV
and if we choose O such as O is not collinear to any couple of points in the gure, the three following lemmas
allow us to replace each geometrical quantity into rational expression with only SOU P and SOV P as variables. If
we denote XP = SOU P and YP = SOV P , we got:
If the three points
O, U
SOU A
,
SOU V
and
In particular, the quantities
Lemma. If A, B , C and D are points such as C 6= D and (AB) k (CD):
−−→ ( XC YA −XC YB −YA XB +YB XA −YC XA +YC XB
AB
XC YA −XC YD −YA XD −YC XA +YC XD +XA YD
−−→ = XB YA −XA YB
CD
XD YC −XC YD
SABC =
PABC = 4
if
(A, C, D)
are not collinear
otherwise
(YB − YC ) XA + (YC − YA ) XB + (YA − YB ) XC
SOU V
2
YA YC − YA YB + YB2 − YB YC − XA XB + XA XC + XB
− XB XC
SOU V
2.2.3 Conclusion
So, starting from equalities between rational expression in geometrical quantities, it is possible to transform them
into equalities between rational expressions in independent variables. Then, a simple decision procedure to decide
the equality of two rational expressions is enough to determine if the given theorem is true or false.
In practice, there is several problems left:
5
•
The elimination lemmas replace simple geometric quantities into more complicated rational expressions: from
step to step, the size of the formula is growing exponentially. Something needs to be done to avoid, or at least
to limit, this complexity problems.
•
To apply several elimination lemmas, we need to know if three given points are collinear or not, and to
compute this, we need to launch a sub-instance of the prover. It means that the prover will call itself several
times, which gives us again an exponential worst-case complexity.
•
We need to nd a ecient algorithm to determine the equality of to given rational expressions in independent
variables.
3
Implementation in OpenGeoProver
In this section, I will explain the implementation of the main concepts of the area method into OpenGeoProver.
Introduction
OpenGeoProver is, according to its main page [5], an open-source project developed in Java for implementation
of various Automated Geometry Theorem Provers.
integrated into existing geometry tools.
It can be used as a stand-alone application but also can be
In particular, OpenGeoProver is able to work with GeoGebra type of
input.
Zoltán Kovács asked me to add the area method prover into OpenGeoProver rather than directly into GeoGebra:
the translation part of geometric gures, from GeoGebra to OpenGeoProver's internal representation, was an
excellent opportunity to implement the necessary translation to the area method objects. Furthermore, it means
that it will be easy for anyone else to use what I have done this summer with another geometry tool.
3.1
Base types
In this subsection, I will expose the main types I have used to represent the concepts dened above.
3.1.1 Base type for geometric constructions
OpenGeoProver had already a Java package to represent geometric constructions. This package had many dierent
classes for every conceivable geometric construction. I only used several of them:
•
FreePoint
•
CircleWithCenterAndPoint
•
LineThroughTwoPoints
and created four other ones for the area method's construction steps:
•
AMFootPoint
•
AMIntersectionPoint
•
PRatioPoint
•
TRatioPoint
The ve dierent types for points inherit from the Point abstract class.
If we look into TRatioPoint.java, for
example, we can see that the construction of this kind of point requires the two previous points and the ratio used.
/∗ ∗
∗ P o i n t s used t o c o n s t r u c t t h i s p o i n t
∗/
protected
/∗ ∗
Point
u,v;
∗ Ratio used t o c o n s t r u c t t h i s p o i n t
∗/
protected
AMExpression
r;
/∗ ∗
∗ C o n s t r u c t o r method
∗/
public
TRatioPoint ( S t r i n g
pointLabel ,
this . g e o O b j e c t L a b e l
this . u = u ;
this . v = v ;
this . r = r ;
Point
u,
Point
v,
AMExpression
r)
{
= pointLabel ;
}
Listing 1: TRatioPoint.java
3.1.2 Base type for rational expressions
I had to create a new package (com.ogprover.pp.tp.expressions) in which I encoded rational expressions in a simple
way. Classes were created to represent the base geometric quantities (respectively AreaOfTriangle.java, PythagorasDierence.java and RatioOfCollinearSegments.java), and to represent the unary and binary arithmetic operators
(AdditiveInverse.java, Sum.java, Dierence.java, Product.java and Fraction.java).
All of those classes inherit from the abstract class AMExpression.java, giving an implementation like this:
/∗ ∗
∗ The two terms .
∗/
protected
AMExpression
term1 , t e r m 2 ;
/∗ ∗
∗ C o n s t r u c t o r method
∗/
public
Sum ( AMExpression
this . t e r m 1
this . t e r m 2
term1 ,
AMExpression
term2 )
{
= term1 ;
= term2 ;
}
Listing 2: Sum.java
This arity of two for the syntaxic tree has had many consequences: the simplication process was simplied, as well
as the reducing to single fraction step. We will come back on this later.
Apart from that, I had to choose the base eld on which the algorithm was based. The area method algorithm is
able to deal with any base eld, even bigger than the eld of constructible numbers. For this project, I simply used
the eld of rational numbers: BasicNumber.java, the AMExpression class used to represent the base coecients of
the rational expressions, contains only a BigInteger (for arbitrary precision).
7
This choice can seem limited, but currently, GeoGebra is only able to send integer or oating-point arguments to
OpenGeoProver: it is useless to deal with more complicated objects until GeoGebra modies its base types. This is
currently being implemented: work is being done to add a complete expression parser in GeoGebra, which will be
able to understand expressions like
√
2+3 without automatically convert them into their approximate oating-point
value. When it will be done, it will be easy to modify BasicNumber.java to add this kind of functionality.
3.1.3 Base type for statements
A class has been created to represent an area method statement object: AreaMethodTheoremStatement.java, in
the package com.ogprover.pp.tp.thmstatement.
Apart from the name of the statement (which is only a natural
description of the geometric proposition we want to prove), it contains a Vector of AMExpression.
This vector contains the dierent equalities which must be veried: every equality of type
transformed into
a − b = 0,
which allows us to store only
a − b,
a = b
can indeed be
to simplify the future processes: later, when we will
p
q = 0, and knowing that q 6= 0, we can directly get p = 0. In the code,
it allows us to launch every expression-modication function once at each step only, instead of twice. It can also
transform it into an expression of the form
lead to simplications which would not have been made otherwise:
than
a − c − (c − b)
3.2
into
a−b=c−b
is harder to simplify into
a=c
a − c = 0.
Implementation of the algorithm
In this subsection, I will explain the implementation choices that have been made to get a working and ecient
result.
3.2.1 Translation from GeoGebra's internal representation to OpenGeoProver's
Geometric constructions:
The rst step was to translate the GeoGebra's internal representation of geometric
gures into the type described above, designed for the area method.
Let us see what kind of input is sent by
GeoGebra. It is an XML le, with dierent GeoGebra commands, each introducing a new construction.
<command name=" P o l y g o n ">
<i n p u t
<o u t p u t
a 0="A"
a 1="B"
a0=" p o l y 1 "
a2="C" />
a1=" c "
a 2=" a "
a 3=" b " />
</command>
<command name=" M i d p o i n t ">
<i n p u t
<o u t p u t
a 0=" a " />
a0="D" />
</command>
Listing 3: A part of a geogebra.xml le
A, B and C have been previously dened, dene a polygon named poly1 with three
a = [AB], b = [BC] and c = [CA]. Then, the Midpoint command is used to create the midpoint
This command, assuming points
segments named
D
of segment
A.
In the translation process, segments are seen as lines, and polygons are ignored: three instances of LineThroughTwoPoints.java will be created for the three segments. The Midpoint command is then translated in the following
1
way .
1
The actual code contains safety checks and exceptions catching
8
protected
GeoConstruction
c o n v e r t M i d p o i n t C m d ( GeoGebraConstructionCommand ggCmd )
{
A r r a y L i s t <S t r i n g > i A r g s = ggCmd . g e t I n p u t A r g s ( ) ;
A r r a y L i s t <S t r i n g > o A r g s = ggCmd . g e t O u t p u t A r g s ( ) ;
Map<S t r i n g , G e o C o n s t r u c t i o n > consMap =
this . t h m P r o t o c o l . g e t C o n s t r u c t i o n M a p ( ) ;
Point
pt1 = ( Point )
consMap . g e t ( i A r g s . g e t ( 0 ) ) ;
Point
pt2 = ( Point )
consMap . g e t ( i A r g s . g e t ( 1 ) ) ;
return new
PRatioPoint ( oArgs . g e t ( 0 ) ,
pt1 ,
pt1 ,
pt2 ,
new
Fraction ( 1 , 2 ) ) ;
}
Listing 4: GGConsConverterForAreaMethod#convertMidpointCmd
This is a fairly simple example: more complicated constructions need intermediary points, for example the construction of a line orthogonal to a given line and which passes by a point. The intermediary point, whose name is
automatically generated (the current convention is
iP 0, iP 1,
etc.), is manually added in the list. We can remark
that a non-degeneracy condition is generated too: as we create the line which passes by
f ootP oint
and
pt,
we need
those two points to be dierent.
GeoConstruction
c o n v e r t O r t h o g o n a l L i n e C m d ( GeoGebraConstructionCommand ggCmd )
{
A r r a y L i s t <S t r i n g > i A r g s = ggCmd . g e t I n p u t A r g s ( ) ;
A r r a y L i s t <S t r i n g > o A r g s = ggCmd . g e t O u t p u t A r g s ( ) ;
Map<S t r i n g , G e o C o n s t r u c t i o n > consMap =
Point
pt = ( Point )
this . t h m P r o t o c o l . g e t C o n s t r u c t i o n M a p ( ) ;
consMap . g e t ( i A r g s . g e t ( 0 ) ) ;
LineThroughTwoPoints
line
Point
pointOnLine1 =
l i n e . getPoints ( ) . get ( 0 ) ;
= ( L i n e T h r o u g h T w o P o i n t s ) consMap . g e t ( i A r g s . g e t ( 1 ) ) ;
Point
pointOnLine2 =
l i n e . getPoints ( ) . get ( 1 ) ;
Point
footPoint =
new AMFootPoint ( n e x t A v a i l a b l e N a m e ( ) , pt , p o i n t O n L i n e 1 , p o i n t O n L i n e 2 ) ;
this . t h m P r o t o c o l . a d d G e o C o n s t r u c t i o n ( f o o t P o i n t ) ;
this . t h m P r o t o c o l . addSimpleNDGCondition ( new D i s t i n c t P o i n t s ( f o o t P o i n t , p t ) ) ;
return new L i n e T h r o u g h T w o P o i n t s ( o A r g s . g e t ( 0 ) , f o o t P o i n t , p t ) ;
}
Listing 5: GGConsConverterForAreaMethod#convertOrthogonalLineCmd
3.2.2 Uniformization, point elimination and reducing to independent variables
Uniformization:
First, we must precise what we mean by uniformization. Several relations between geometrical
SABC = SBCA = −SACB for every triple of points (A, B, C). But calling the
SBCA will fail, so the algorithm will not immediately recognize
that SABC − SBCA can be simplied into 0. To solve this issue, I implemented an uniformize() method, which
transforms automatically expressions like SBCA into expressions like SABC (the simple rule I followed was following
quantities are trivial. For example,
equals method on
SABC
to see if it is equal to
the alphabetical order on point's names).
Simplication:
The ecient simplication of a formula is one of the main issues in a practical work like this
one. Like I said before, the size of the formula tends to dramatically grow during the algorithm, so the only hope
we can have to avoid an exponential average complexity is to simplify as most as possible the formulas during the
algorithm. There is an exhaustive list of possible simplications given in Appendix B: one can nd simplications
linked to degenerated geometric quantities (like
eld simplications (like
a
a
SAAB → 0),
ring simplications (like
a.0 → 0
or
a + 0 → a)
and
→ 1).
We can see that all this dierent simplications can be done in only one pass: there is not need to use the rules in
a waterfall manner.
9
@Override
public
AMExpression
simplify ()
{
AMExpression
t 1 = term1 . s i m p l i f y ( ) ;
AMExpression
t 2 = term2 . s i m p l i f y ( ) ;
if
( t1 . i s Z e r o ( ) )
if
( t2 . i s Z e r o ( ) )
if
( t2
return
t2 ;
return t 1 ;
instanceof A d d i t i v e I n v e r s e )
return new D i f f e r e n c e ( t 1 , ( ( A d d i t i v e I n v e r s e ) t 2 ) . g e t E x p r ( ) ) ;
i f ( t 1 instanceof A d d i t i v e I n v e r s e )
return new D i f f e r e n c e ( t 2 , ( ( A d d i t i v e I n v e r s e ) t 1 ) . g e t E x p r ( ) ) ;
i f ( t 1 instanceof BasicNumber && t 2 instanceof BasicNumber )
return ( ( BasicNumber ) t 1 ) . add ( ( BasicNumber ) t 2 ) ;
return new Sum ( t 1 , t 2 ) ;
}
Listing 6: Sum.java#simplify()
The rules used above use the fact that the tree is binary: it would have been slightly more complicated with an
unlimited arity. There is an inconvenient to this issue: expressions of type
a + (b − a)
are not simplied. This is
not a real problem at this point: this kind of expression is almost never generated by our elimination or reducing
to independent variables lemmas. However, we will come back on this issue later.
All functions which transform expressions never modify their arguments: this rule make the debugging process
easier, and allows us to store intermediary steps without copying the expressions.
For example, if we take the
implementation of the uniformize() method called on a Sum object:
@Override
public
AMExpression
return new
u n i f o r m i z e ( H a s h S e t<H a s h S e t<P o i n t >> k n o w n C o l l i n e a r P o i n t s )
{
Sum ( t e r m 1 . u n i f o r m i z e ( k n o w n C o l l i n e a r P o i n t s ) ,
term2 . u n i f o r m i z e ( k n o w n C o l l i n e a r P o i n t s ) ) ;
}
Listing 7: Sum.java#uniformize()
we can see that the object on which the method is called is not modied, but another one is returned instead. We
will explain the knownCollinearPoints argument later.
3.2.3 Deciding whether a rational expression is zero or not
Reducing the problem to a ring expression:
As we want to verify if a given rational expression is zero or
not, the rst thing we have to do is to reduce it into a single fraction.
This is done in a quite simple recursive
function, dened - of course - dierently in each subclass of AMExpression.java. The list of rules applied can be
found in Appendix C.
@Override
public
AMExpression
reduceToSingleFraction ()
AMExpression
if
( term
{
term = e x p r . r e d u c e T o S i n g l e F r a c t i o n ( ) ;
instanceof
Fraction )
{
AMExpression
numerator = ( ( F r a c t i o n ) term ) . getNumerator ( ) ;
AMExpression
d e n o m i n a t o r = ( ( F r a c t i o n ) term ) . g e t D e n o m i n a t o r ( ) ;
return new
Fraction (
new
A d d i t i v e I n v e r s e ( numerator ) ,
denominator ) ;
}
return new
A d d i t i v e I n v e r s e ( term ) ;
}
Listing 8: AdditiveInverse.java#reduceToSingleFraction()
a
b , where a is a ring expressions: it does
not contain any fraction, only additions, multiplications and dierences. In both cases, considering we verify that
After calling this method, we got an expression which can be of form
a
or
the denominators are non-zero only when creating them (it is useless to do so at arithmetic rewriting steps), we
nally get
a = 0,
when
a
is a ring expression.
Deciding whether a ring expression is zero or not:
In Julien Narboux' paper, there is a set of rewriting
rules, which have to be applied in a waterfall manner to obtain an expression in right additive form: a big sum of
a + (b + (c + (d + (e + f )))),
(a + b) + c −→ a + (b + c), (a + b) · c → a · c + a · d, etc.
products of geometric quantities, internally represented in right associative form:
example. The rules were of the type
for
This method is technically correct, but it is actually very slow on large inputs: many rules need to be applied to
reduce an expression of the form
((((a + b) + c) + d) + e) + f ,
and a each step, one have to do two passes on the
syntaxic tree: one to verify the equality with the previous expression, and another one to actually apply the next
rule. Moreover, we would like to simplify on the y the expressions we got, to make the process faster - and this
time, getting expressions like
a + (b − a)
is very common.
So, I rstly implemented the Julien Narboux' method, and realized it could take hours to reduce an expression with
only hundreds of terms. So, I had to come with another method. I added two subclasses of AMExpression.java,
namely BigProduct.java and SumOfProducts.java, with the following elds:
/∗ ∗
∗ C o e f f i c i e n t in f r o n t o f t h e product , by d e f a u l t , i t i s o f c o u r s e 1 .
∗/
protected
BasicNumber
coeff
=
new
BasicNumber ( 1 ) ;
/∗ ∗
∗ Geometric q u a n t i t i e s a p p e a r i n g in t h e p r o d u c t
∗ I t i s r e p r e s e n t e d as an HashMap , a s s o c i a t i n g w i t h e v e r y g e o m e t r i c q u a n t i t y
∗
t h e number o f t ime s where i t appears .
∗/
protected
HashMap<G e o m e t r i c Q u a n t i t y ,
Integer>
factors ;
Listing 9: BigProduct.java
/∗ ∗
∗ Products a p p e a r i n g in t h e sum .
∗/
protected
H a s h S e t<B i g P r o d u c t > t e r m s =
new
H a s h S e t<B i g P r o d u c t > ( ) ;
Listing 10: SumOfProducts.java
and created a much simpler toSumOfProduct() recursive method.
11
@Override
public
AMExpression
toSumOfProducts ( )
{
SumOfProducts
sum1 = ( SumOfProducts )
f a c t o r 1 . toSumOfProducts ( ) ;
SumOfProducts
sum2 = ( SumOfProducts )
f a c t o r 2 . toSumOfProducts ( ) ;
SumOfProducts
sumToReturn =
new
SumOfProducts ( ) ;
H a s h S e t<B i g P r o d u c t > f a c t o r s 1 = sum1 . g e t T e r m s ( ) ;
H a s h S e t<B i g P r o d u c t > f a c t o r s 2 = sum2 . g e t T e r m s ( ) ;
for
( BigProduct
return
for
product1 :
( BigProduct
factors1 )
product2 :
factors2 )
sumToReturn . addTerm (
new
BigProduct ( product1 ,
product2 ) ) ;
sumToReturn ;
}
Listing 11: SumOfProducts.java
The method addTerm is smart: when adding a term like
result is
(−1) · x · z + 2 · x · y :
(−2) · x · y
to a formula like
(−1) · x · z + 4 · x · y ,
the
the simplication process is done on-the-y. So, once a ring expression has been
translated into a sumOfProducts instance, it is very easy to decide whether it is zero or not (after the reducing to
independent variables step, of course).
One of the main advantages of this method is that we avoid the slow-down due to associativity problems: dealing
with
a + (b + (c + (d + (e + f ))))
is as fast as dealing with
((((a + b) + c) + d) + e) + f .
Moreover, we do not need
to verify for equality at each step - in practice, it never takes more than a few seconds to transform an expression
with several hundreds of terms into a sum of products.
3.2.4 Pretty-printing proofs
In the original project, I had to implement the output of proofs, in a clear and readable way.
I was initially
AT X and a PDF or PostScript format. However, after discussing with Zoltan, we decided
thinking about using L
E
that this kind of output was not really useful for the GeoGebra's users. Indeed, GeoGebra is mean to be simple
and interactive, and this kind of xed output is not really convenient for the young students.
Another issue was raised too: the translation part automatically introduce new construction points. This is done
internally in OpenGeoProver, so GeoGebra does not know about those points. However, those points would have
appeared in the proofs: like the regular points, they appear in the formulas, can be eliminated too, etc. So, a
proof which uses points which the user can not see in the GeoGebra interface is quite unusable.
That is why the project of pretty-printing proofs has been postponed to a future date, when OpenGeoProver will
be able to send a new type of input into GeoGebra: then, the intermediary points would appear in the GeoGebra
interface, or we can even imagine an Area method mode in which the user could use directly (and only) the ve
elementary construction steps.
4
Additional optimizations tried, and results
I nished the area method implementation in the middle of July, (without counting debugging and documentation
writing). I spent my last weeks of work improving it by testing various optimizations, that I will present in this
last section.
I had three goals: proving a larger set of theorems, making the algorithm faster, and making the (future) proofs
more readable.
4.1
Proving formulas and not only geometric statements
Before I started to work on the area method, all the already-implemented provers could only prove geometric
statements, of the form Those two lines are parallel, Those three points are collinear, etc. But the area method
12
is able to prove the equality between any two rational expressions in geometric quantities. Let us show the dierence
with a well-known example: Pythagorean theorem.
Pythagorean theorem stands that if a given triangle
2
AB + AC
2
ABC
is right-angled (with
A
as the right angle), then
BC 2 =
. This kind of theorem is provable by the area method: the gure can obviously be constructing using
the ve construction steps, and considering that
PBCB
written
2
=
PABA
2
+
PACA
or, even simpler:
2
PP QP = 2 · P Q2
for any points
P
and
Q,
the statement can be
PBCB = PABA + PACA
So, proving this kind of theorem with the area method does not require any additional code ; but GeoGebra was
not able to send this kind of input. So, I had to write a parser for this kind of input to be allowed, and correctly
understood. After that, the prover linked with GeoGebra were able to prove a larger set of theorems than before,
which is a great progress.
4.2
Making the algorithm faster and the proofs more readable
Basically, the most obvious way of making the area method algorithm faster is to have a more ecient simplication
step, to avoid large formulas as much as possible. The goal is then to nd simplications which were not already
performed.
4.2.1 Elimination of equal points
During the test of the algorithm, I noticed that in some cases, the geometric construction translation step created
several times the same point. Let us take a little example: suppose that the user wants to draw the bisector
AB , and call M
AB .
given segment
of segment
the intersection between
AB
and the bisector. Then,
The good way of generating such a construction is to construct the midpoint
construct the line
l
which passes by
M
and is perpendicular to
AB .
M
M
l
of a
is - of course - the midpoint
of the segment rst, and then
But the user, in the GeoGebra interface, can
do otherwise: he can use the built-in line bisector tool of GeoGebra, and then naming
M
the intersection point
between them.
In the rst case, the corresponding GeoGebra commands will be translated the following way:
• M = Pratio A, A, B,
• iP0 = Tratio (M, B, 1)
1
2
(we need two points to construct a line)
• l = Line (M, iP0 )
but in the second case, they will be translated the following way:
• iP0 = Pratio A, A, B,
1
2
• iP1 = Tratio (iP0 , B, 1)
• l = Line (iP0 , iP1 )
• M = Intersection (A, B, iP0 , iP1 )
iP0
iP1 being the auxiliary points needed to construct l. In the second case, this seems obvious to us that the
iP0 and M are actually the same. But from the algorithm's point of view, these are two distinct points, so
will be both appear in formulas, expressions like SAiP0 M will not be simplied, there will be one elimination
and
point
they
step for each point, etc.
The solution to this problem is pretty simple: for each couple of points in the formula, the prover veries whether
those two points are the same or not. This can seem quite a naive solution, but actually:
13
•
When the points are not the same, the prover sees it immediately:
in the beginning of the algorithm,
random coordinates are computed for each point, and the formula (which is supposed to be equal to zero) is
numerically tested. If the points (A and
B,
for example) are not the same in the general case, then they will
probably not be the same in a particular trial either, so we will have
PABA 6= 0:
as a counter-example is a
valid way to prove that a given theorem is false, the prover stops immediately and returns that the statement
is false.
•
When the points are the same, usually, the construction which leads to such a situation is really simple, like
the one described above. So, the prover does not take very long to prove it.
If two identical points are found, one is replaced by the other (when they are automatically-generated points,
the rst one is kept, and when there is one visible point and one automatically generated, the visible is kept)
everywhere in the formulas: this way, only one is printed and eliminated.
The numerical results, quite predictable, show that this verication slows down a little bit every test case in which
the situation described above is not met, and speeds up signicantly the algorithm (and simplies considerably the
nal proof ) when two identical points are found.
4.2.2 Simplication non-trivially degenerated geometric quantities
Another possible simplication is the following. Let us consider three
simplify expressions like
SAAA
or
SAAB .
But if
A, B
and
C
collinear
A, B and C . We already
SABC = 0 too, and this kind
points
are collinear, then we got
of expression is not simplied. My idea was then to detect this situation, to be able to implement this additional
simplication.
The rst immediate problem is that in many cases, the collinearity between three given is not obvious: the goal
being to clarify the proofs, we only want to simplify the obviously collinear points. We need to dene precisely
this obviousness notion.
Denition 7.
Three points
if and only if (assuming that
A, B and C of an area method geometric construction are said to be trivially collinear
C was construction after A and B ) (at least) one of the following conditions is veried:
•
There exists two points
•
There exists a point
• C
and
Q
such as
such as
C
was constructed by
was constructed by
where
C
was constructed by
C = Pratio (P, Q, R, r),
P, Q, R ∈ {A, B}.
was constructed by
and where
• C
P
P
Q, R ∈ {A, B},
where
r
C = Intersection (A, B, P, Q).
C = Foot (P, A, B).
is a given rational expression in geometrical quantities,
C = Pratio (P, Q, R, r), where r is a given rational expression in geometrical quantities,
and (A, B, P ) are trivially collinear.
•
There exists a point
P
such as
(A, B, P )
are trivially collinear, and
(A, C, P )
are trivially collinear.
•
There exists a point
P
such as
(A, B, P )
are trivially collinear, and
(B, C, P )
are trivially collinear.
The reader can verify that this relation is computable for any nite geometric construction. Once this is computed
(which is quite fast), the simplications are done at each step (because after any point elimination, this kind of
degenerated geometric quantity can be generated), during uniformization.
Quite surprisingly, the results do not show a signicant speed-up: the slight speed-up due to simplications does
not compensate the (little) slow-down due to the calculus of trivially collinear points. Usually, between zero and
two geometric quantities are removed from formulas at each step.
However, it usually deletes several geometric
quantities that a human reader would have simplied immediately, so it does clarify the proofs a little bit.
4.3
Benchmark results
The benchmark of the area method algorithm compared to the other ones currently implemented in GeoGebra can
be found in the end of this le. The undened results mean that the statement has not been proved nor disproved,
because of a theoretical limitation or a bug. For example, the undened results in the Area Method's column are
due to intersection between lines and circles in the general case.
About the speed results, it is important to keep in mind that the two provers implemented directly in GeoGebra do
not suer from the input/output slow-down like the provers implemented in OpenGeoProver. This input/output
step lasts approximately 80ms on the machine used for the tests.
One interesting thing is that the area method is not clearly faster or slower than the other provers: on several tests,
it is more ecient, and on some simple tests, it timeouts. Another observation is that the area method's speed is
not as stable as the others methods: several tests try to prove the same theorem, but with dierent gures and
statements: orthocenter[1-7].ggb, or circumcenter[1-5].ggb, for example. The other methods take approximately the
same time to compute each of them, but the area method has very distinct results.
5
Conclusion and perspectives
The project I have worked on this summer is quite successful: GeoGebra can prove more geometric theorems than
before, and it competes pretty well with the other provers.
Furthermore, many things can be done from my work, and will probably be implemented in the few next months improvements as well as additional features.
•
The non-degeneracy conditions could be handled better: currently, they are simply added to a list each time a
line is constructed (the two points must be dierent), an intersection point is constructed (the two lines must
−
−
→
AB
C 6= D to write −
−
→ ). But
CD
some of them can be deduced from others: for example, if we have three points A, B and C , let P be the foot
of C on (AB). Let us suppose that we already have generated the non-degeneracy conditions A and B are
distinct, and C and P are distinct: then the non-degeneracy condition (AB) and (CP ) are not parallel
not be parallel) or a ratio appears in a formula (we must have
(AB) k (CD)
and
can be deduced from the previous ones. Such non-degeneracy condition does not need to be printed.
•
Of course, real interaction with GeoGebra could be awesome: it would allow the user to see the intermediary
points constructed by the area method, to verify quickly what happens when the non-degeneracy conditions
are not matched, etc. One of the other advantages of the area method is that the proofs can be manually
−
−
→
AB
AC
proof to make it as clear and simple as possible.
simplied (for example, if a term like −→ appears, and
•
B
is the middle of
[AC]):
the user could play with his
The automatic simplication of degenerated geometric quantities could be expanded, for example by simplifying
PABC → 0
when
\
ABC
is a right angle, or
SABC − SABD → 0
when
(AB) k (CD).
As we dened our
notion of trivially collinear points, one could dene similar notions of trivially parallel or perpendicular lines,
and do the corresponding simplications.
•
The area method can translate a given geometric statement in several dierent ways. For example, to translate
(AB), (CD) and (EF ) are concurrent, we can say The points P =
E and F are collinear (and then, SP EF = 0), but we can also choose The points P =
Inter (A, B, E, F ), C and D are collinear (SP CD = 0) or The points P = Inter (A, B, C, D) and Q =
Inter (A, B, E, F ) are equal (PP QP = 0). Each possibility will give us a totally dierent proof, and this
the geometric statement The lines
Inter (A, B, C, D),
seems quite hard to predict which one will be the fastest. However, one could use parallel programming to
try several possibilities at the same time, and stop the algorithm once one has been proved.
For me, this internship has been a really great experience:
I have discovered a country that I did not know,
encountered many people and learn many new concepts, theoretical as well as practical. I have greatly improved
my Java skills, I have learned to write a parser with JavaCC, to use SVN and Eclipse, and I have taken my rst
step into the world of automated proving.
15
I loved being a part of a big project such as GeoGebra: committing code in a SVN tree with dozens of new commits
every day, where automatic tests are launched every night, is something really dierent from coding personal
projects. It is very pleasant to have a little piece of his own code into Debian repositories, too !
Finally, I would like to thank a lot the people who welcomed me in Austria: Zoltan for his kindness and his help
the rst days (public holiday in Austria, nobody in the reception to give me the keys of my room), Markus, who is
the kind of manager you want to have for the rest of your life, and all the other interns who all were very welcoming
too. They all made me have a really good time here in Linz.
References
[1] Predrag Jani£i¢, Julien Narboux, Pedro Quaresma: The Area Method: a Recapitulation. In: Journal of Automated Reasoning, 2012, 48 (4), pp. 489-532
[2] Chou, S.C., Gao, X.S., Zhang, J.Z.:
Automated production of traditional proofs for constructive geometry
theorems. In: M. Vardi (ed.) Proceedings of the Eighth Annual IEEE Symposium on Logic in Computer Science
LICS, pp. 4856. IEEE Computer Society Press (1993)
[3] Jani£i¢, P., Quaresma, P.: Automatic verication of regular constructions in dynamic geometry systems. cc
In: F. Botana, T. Recio (eds.) Proceedings of Automated Deduction in Geometry (ADG06), Lecture Notes in
Articial Intelligence, vol. 4869, pp. 3951. Springer-Verlag, Pontevedra, Spain (2007)
[4] Wu, W.T.:
Automated Theorem Proving:
After 25 Years, vol. 29, chap. On the decision problem and the
mechanization of theorem proving in elementary geometry, pp. 213234. American Mathematical Society (1984)
[5] https://code.google.com/p/open-geo-prover/
Appendix A: List of elimination lemmas
Let us suppose that we want to eliminate the point
Y
from a given geometric quantity. First, we can remark than
we can rewrite the geometric quantity using only geometric quantities of one of those forms:
−
−
→
−
−
→
AY
AY
−
−
→ , or −
−
→ . Indeed:
BC
BY
PABY , PAY B , SABY ,
PY BA = PABY
SBY A = SY AB = SABY
−→
−→
−−→
−−→
YA
AY
BC
BC
1
=
−
and
=
−
−
→
−−→
−−→
−→
−→ = −
AY
BC
BC
AY
YA
−
−
→
BC
−→
−→
−→
−→
YA
YA
AY
AY
−−→ = − −−→ = − −−→ = −−→
YB
BY
YB
BY
Furthermore, we will take the same abbreviations as in the paper from Julien Narboux[1]:
and
PABCD = PABD − PCBD .
Lemma 1. If Y is introduced by Y
= Inter (U, V, P, Q), then, assuming A 6= Y :
−→ ( SAP Q
if A is on (U V )
AY
SCP Q
−−→ = SAU V
else
CY
SCU V
−→ ( SAP Q
if A is on (U V )
AY
SCP DQ
−−→ = SAU V
else
CD
SCU DV
16
SABCD = SABC + SACD ,
Lemma 2. If Y is introduced by Y
= Foot (P, U, V ), then, assuming A 6= Y :
−→ (
PP U V PP CAV +PP V U PP CAU
if A is on (U V )
AY
PP U V PCV C +PP V U PCU C −PP U V PP V U
=
−−→
SAU V
else
CY
SCU V
−→ ( PP CAD
if A is on (U V )
AY
PCDC
−−→ = SAU V
else
CD
SCU DV
Lemma 3. If Y is introduced by Y
= Pratio (R, P, Q, r), then, assuming A 6= Y :
−
−
→
AR
−
−
→ +r
−→ 
PQ

if A is on (RY )
−
−
→
AY
CR
−
→ +r
−−→ =  −
PQ
CY
 SAP RQ
else
SCP RQ
−
−
→
AR
−
→ +r

PQ
−
−
−
→
−→
AY
CD
−−→ =  P−−→
Q
CD  SAP RQ
if A is on (RY )
else
SCP DQ
Lemma 4. If Y is introduced by Y
= Tratio (P, Q, r), then, assuming A 6= Y :
−→ ( SAP Q − r4 PP QP
if A is on (P Y )
AY
SCP Q − r PP QP
−−→ = PAP Q 4
else
CY
PCP Q
−→ ( SAP Q − r4 PP QP
AY
SCP DQ
−−→ = PAP Q
CD
PCP DQ
Lemma 5. If Y is introduced by Y
= Inter (U, V, P, Q), then:
SABY =
Lemma 6. If Y is introduced by Y
SU P Q SABV − SV P Q SABU
SU P V Q
= Foot (P, U, V ), then:
SABY =
Lemma 7. If Y is introduced by Y
if A is on (P Y )
else
PP U V SABV − PP V U SABU
PU V U
= Pratio (W, U, V, r), then:
SABY = SABW + r (SABV − SABU )
Lemma 8. If Y is introduced by Y
= Tratio (P, Q, r), then:
r
SABY = SABP − PP AQB
4
17
Lemma 9. If Y is introduced by Y
= Tratio (P, Q, r), then:
PABY = PABP − 4rSP AQB
Lemma 10. If Y is introduced by Y
PAY B =
= Inter (U, V, P, Q), then:
SV P Q
SU P Q SV P Q PU V U
SU P Q
PAV B +
PAU B −
SU P V Q
SU P V Q
SU2 P V Q
Lemma 11. If Y is introduced by Y
= Foot (P, U, V ), then:
PAY B =
Lemma 12. If Y is introduced by Y
PP U V
PP V U
PP U V PP V U
PAV B +
PAU B −
PU V U
PU V U
PU V U
= Pratio (W, U, V, r), then:
PAY B = PAW B + r (PAV B − PAU V + 2.PW U V ) − r (1 − r) PU V U
Lemma 13. If Y is introduced by Y
= Tratio (P, Q, r), then:
PAY B = PAP B + r2 PP QP − 4r (SAP Q + SBP Q )
Lemma 14. If Y is introduced by Y
= Inter (U, V, P, Q), then:
SU P Q PABV − SV P Q PABU
SU P V Q
PABY =
Lemma 15. If Y is introduced by Y
= Foot (P, U, V ), then:
PABY =
Lemma 16. If Y is introduced by Y
PP U V PABV − PP V U PABU
PU V U
= Pratio (W, U, V, r), then:
PABY = PABW + r (PABV − PABU )
Appendix B: List of simplication rules
Degenerated geometric quantities:
SAAB → 0
−
−
→
YY
−
−
→
AB
→0
SABA → 0
SBAA → 0
PAAB → 0
PBAA → 0
18
Ring simplications:
a·0→0
0·a→0
1·a→a
a·1→a
Field simplications
0+a→a
a+0→a
a−0→a
0 − a → −a
a−a→0
(we assume that
−0 → 0
(−a) · b → − (a · b)
−−a→a
a · (−b) → − (a · b)
−a + a → 0
−a · −b → a · b
a + (−b) → a − b
−b + a → a − b
a 6= 0):
a
a →1
a
−a → −1
−a
a → −1
−a
−a → 1
0
a
a
1
→0
→
a
a · a1 → 1
−b
b
a → −a
b
b
−a → − a
a·b
a →b
b·a
a →b
Appendix C: List of the rules of the reducing to single fraction step
We assume that all the denominators are non-zero.
a
b
a+c·b
b
a
c·b+a
c+ b → b
a
c
a+c
b + b → b
a
c
a·d+c·b
b + d →
b·d
+c→
a·
a
b
a
b
b
c
→
·c→
· dc →
19
a·b
c
a·c
d
a·c
b·d
a·c
b
a
ca → b·c
a
b
c →
b
ab
a·d
b
c →
b·c
d
a
b
c
a
b
→