Mizar manual

Andrzej Trybulec, Freek Wiedijk

2

Chapter 1

Background

???

1.1 Mizar history

???

1.2 Mizar sites

???

1.3 Large formalization projects

???

4 CHAPTER 1. BACKGROUND

Part I Reference

5

Chapter 2

Vocabularies

???

8 CHAPTER 2. VOCABULARIES

Language

???

3.1 Lexical syntax

???

3.1.1 Identifiers

???

3.1.2 Symbols

???

3.1.3 Keywords

???

3.2 Environment

???

3.2.1 Vocabulary directive

???

3.2.2 Notation directive

???

10 CHAPTER 3. LANGUAGE

3.2.3 Constructors directive

???

3.2.4 Clusters directive

???

3.2.5 Definitions directive

???

3.2.6 Theorems directive

???

3.2.7 Schemes directive

???

3.2.8 Requirements directive

???

3.3 Requirements

???

3.3.1 SUBSET

???

3.3.2 BOOLE

???

3.3.3 ARYTM

???

3.3.4 REAL

???

3.4. RESERVATIONS 11

3.4 Reservations

???

3.5 References

???

3.5.1 Labels

???

3.5.2 MML theorem references

???

3.5.3 MML definition references

???

3.5.4 Cancellations

???

3.5.5 Scheme names

???

3.6 Definitions

???

3.6.1 Modes defined using means

Syntax

definition [loci]

[assumptions] mode symbol [of arguments] [-> type] means :label: formula;

 existence

proof

end;

Description ???

Example

???

???

See also Section 3.6.2 (Modes defined using is), Section 3.7.1 (Existence), Section 3.14 (Type expressions).

3.6.2 Modes defined using is

Syntax

definition [loci]

mode symbol [of arguments] is type;

end;

Description ???

Example

???

???

See also Section 3.6.1 (Modes defined using means), Section 3.6.3 (Structures), Section 3.14 (Type expressions).

3.6.3 Structures

Syntax

definition [loci]

struct [(ancestors)] symbol [over arguments] (# field_{1} -> type_{1},

field_{2} -> type_{2},

…

field_{n} -> type_{n} #);

end;

Description ???

Example

definition let FS1,FS2 be 1-sorted;
 struct (VectSpStr over FS1, RightModStr over FS2) BiModStr over FS1,FS2
   (# carrier -> set,
    add -> BinOp of the carrier,
    compl -> UnOp of the carrier,
    Zero -> Element of the carrier,
    lmult -> Function of [:the carrier of FS1, the carrier:], the carrier,
    rmult -> Function of [:the carrier, the carrier of FS2:], the carrier #);
end;

???

See also Section 3.14 (Type expressions).

3.6.4 Attributes

Syntax

definition [loci]

attr variable is symbol means formula; [synonym pattern;] [antonym pattern;] [synonym variable is symbol;] [antonym variable is symbol;]

end;

Description ???

Example

???

???

See also ???

3.6.5 Existential clusters

Syntax

definition [loci]

cluster adjectives type;

 existence

proof

end;

Description ???

Example

???

???

See also ???

3.6.6 Conditional clusters

Syntax

definition [loci]

cluster adjectives_{1} -> adjectives_{2} type;

 coherence

proof

end;
definition [loci]

cluster -> adjectives_{2} type;

 coherence

proof

end;

Description Registering this kind of cluster causes all terms that have type adjectives_{1} type to also get adjectives adjectives_{2}. The loci give the variables that occur in type, if any.

If the cluster adjectives_{1} is empty, as in the second form, it means that every term of type type gets adjectives adjectives_{2}.

The coherence statement for this kind of cluster registration is:

for X being type st X is adjectives_{1} holds X is adjectives_{2}

Example

 reserve X for set;
 reserve D for non empty set;
definition let X,D;
 cluster quasi_total -> total PartFunc of X,D;
 coherence
  proof let f be PartFunc of X,D;
   assume f is quasi_total;
    then dom f = X by Def1;
   hence thesis by PARTFUN1:def 4;
  end;
end;

This cluster states that every term that has type quasi_total PartFunc of

X,D will get type quasi_total total PartFunc of X,D.

See also Section 3.6.5 (Existential clusters), Section 3.6.7 (Functorial clusters), Section 3.7.3 (Coherence), Section 3.14 (Type expressions).

3.6.7 Functorial clusters

Syntax

definition [loci]

cluster term -> adjectives;

 coherence

proof

end;

Description ???

Example

???

???

See also ???

3.6.8 Predicates

Syntax

definition [loci]

pred [arguments] symbol [arguments] means :label: formula

 [symmetry proof ]
 [connectedness proof ]
 [reflexivity proof ]
 [irreflexivity proof ]

[synonym pattern;] [antonym pattern;]

end;

Description ???

Example

???

???

See also ???

3.6.9 Functors defined using means

Syntax

definition [loci]

[assumptions] func [arguments] symbol [arguments] [-> type] means :label: formula;

existence

proof

uniqueness

proof

[commutativity proof ]
[projectivity proof ]
[involutiveness proof ]

[synonym pattern;] [antonym pattern;]

end;
definition [loci]

[assumptions] func symbol arguments symbol [-> type] means :label: formula;

existence

proof

uniqueness

proof

[commutativity proof ]
[projectivity proof ]
[involutiveness proof ]

[synonym pattern;] [antonym pattern;]

end;

Description ???

Example

???

???

See also ???

3.6.10 Functors defined using equals

Syntax

???

3.7. CORRECTNESS CONDITIONS 17 Description ??? Example

???

??? See also ???

3.6.11 Definitions by cases

Syntax

???

Description ??? Example

???

??? See also ???

3.6.12 Redefinitions

???

3.7 Correctness conditions

???

3.7.1 Existence

???

3.7.2 Uniqueness

???

3.7.3 Coherence

???

18 CHAPTER 3. LANGUAGE

3.7.4 Compatibility

???

3.7.5 Consistency

???

3.8 Properties

???

3.8.1 Commutativity

???

3.8.2 Symmetry

???

3.8.3 Connectedness

???

3.8.4 Reflexivity

???

3.8.5 Irreflexivity

???

3.8.6 Synonym

???

3.8.7 Antonym

???

3.9 Theorems and schemes

???

3.10. REASONING ITEMS 19

3.9.1 Theorems

Syntax

???

Description ???

Example

???

???

See also ???

3.9.2 Schemes

Syntax

???

Description ???

Example

???

???

See also ???

3.10 Reasoning Items

???

3.10.1 Compact statements

Syntax

???

Description ???

Example

???

???

20 CHAPTER 3. LANGUAGE

See also ???

3.10.2 Assume

Syntax

???

Description ??? Example

???

??? See also ???

3.10.3 Thus

Syntax

???

Description ??? Example

???

??? See also ???

3.10.4 Let

Syntax

???

Description ??? Example

???

???

3.10. REASONING ITEMS 21

See also ???

3.10.5 Take

Syntax

???

Description ??? Example

???

??? See also ???

3.10.6 Given

Syntax

???

Description ??? Example

???

??? See also ???

3.10.7 Consider

Syntax

???

Description ??? Example

???

???

22 CHAPTER 3. LANGUAGE

See also ???

3.10.8 Reconsider

Syntax

???

Description ??? Example

???

??? See also ???

3.10.9 Set

Syntax

???

Description ??? Example

???

??? See also ???

3.10.10 Deffunc and defpred

Syntax

???

Description ??? Example

???

???

3.10. REASONING ITEMS 23

See also ???

3.10.11 Per cases with case

Syntax

???

Description ??? Example

???

??? See also ???

3.10.12 Per cases with suppose

Syntax

???

Description ??? Example

???

??? See also ???

3.10.13 Iterative equalities

Syntax

???

Description ??? Example

???

???

24 CHAPTER 3. LANGUAGE See also ???

3.11 Justification

???

3.11.1 Proof

???

3.11.2 @Proof

???

3.11.3 Now

???

3.11.4 By

???

3.11.5 Then, hence, hereby

???

3.11.6 From

???

3.12 Formula expressions

???

3.12.1 Predicate logic

???

3.12.2 Atomic formulas

???

3.13 Type qualifications

???

3.14. TYPE EXPRESSIONS 25

3.14 Type expressions

???

3.14.1 Structures

???

   strict

???

3.15 Term expressions

???

3.15.1 Qua

???

3.15.2 Structures

???

3.15.3 Fraenkel operator

???

26 CHAPTER 3. LANGUAGE

System

???

4.1 Installing Mizar under Windows

???

4.2 Installing Mizar under Linux

???

4.3 Directories and files

???

4.3.1 TEXT directory

???

4.3.2 DICT directory

???

4.3.3 PREL directory

???

4.3.4 MIZ files

???

28 CHAPTER 4. SYSTEM

4.3.5 ABS files

???

4.3.6 VOC files

???

4.3.7 Other files in TEXT

???

4.3.8 Files in PREL

???

4.3.9 Other files in MIZFILES

???

4.4 Kernel programs

???

4.4.1 MIZF

???

4.4.2 MAKEENV

???

4.4.3 ACCOM

???

4.4.4 VERIFIER

???

4.4.5 ENV

???

4.4.6 EXPORTER

???

4.5. PROGRAMS FOR OPTIMIZATION 29

4.4.7 TRANSFER

???

4.4.8 PRE

???

4.5 Programs for optimization

???

4.5.1 RELPREM

???

4.5.2 RELINFER

???

4.5.3 RELITERS

???

4.5.4 TRIVDEMO

???

4.5.5 CHKLAB

???

4.5.6 INACC

???

4.5.7 IRRVOC

???

4.5.8 IRRTHS

???

30 CHAPTER 4. SYSTEM

4.6 Programs for error messages

???

4.6.1 REVF

???

4.6.2 CHKERR

???

4.6.3 ERRFLAG

???

4.6.4 REMFLAGS

???

4.6.5 ADDFMSG

???

4.7 Programs to generate the abstract

???

4.7.1 MIZ2ABS

???

4.7.2 ABSEDT

???

4.7.3 EDTFILE

???

4.8 Programs for vocabularies

???

4.9. OTHER PROGRAMS 31

4.8.1 CHECKVOC

???

4.8.2 FINDVOC

???

4.8.3 LISTVOC

???

4.9 Other programs

???

4.9.1 CONSTR

???

4.9.2 RATPROOF

???

4.9.3 BIBART

???

4.10 Obsolete programs

???

4.11 Error messages

???

32 CHAPTER 4. SYSTEM

Library

???

5.1 Getting the library

???

5.2 Submitting to the library

???

5.3 Copyright

???

34 CHAPTER 5. LIBRARY

Part II Tutorial

35

Writing a Mizar article in nine easy steps

After reading this chapter and doing the exercises, you will be able to write a basic Mizar article all by yourself.

The chapter presents an explanation of the nine steps needed to finish a Mizar article. For each step it also shows how this turns out for a specific example. There are exercises too, so you can test your understanding.

To be able to read this chapter you should know some basic mathematics but not much. You should know a little bit about:

• first order predicate logic

• some basic set theory

Mizar is based on set theory on top of predicate logic, that’s why.

The most difficult part of writing Mizar is finding what you need in the MML which is the name of the Mizar Mathematical Library. Unfortunately that problem has no easy solution. You will discover that apart from that, writing a Mizar article is straight-forward.

6.1 Step 1: the mathematics

Before you start writing a Mizar article you need to decide what it should be about. It’s very important not to start writing the article too soon! A proof that takes five minutes to explain – after which people look into the air and then mumble: ‘hm, yes, I see’ – takes about a week to formalize. So every improvement to the mathematics that you can make before you start formalizing will pay off very much.

38 CHAPTER 6. WRITING A MIZAR ARTICLE IN NINE EASY STEPS

The example As a running example in this chapter we write a small Mizar article called MY_MIZAR.MIZ. It is about Pythagorean triples. Those are triples of natural numbers {a, b, c} for which holds that:

a^{2} + b^{2} = c^{2}

The Pythagorean theorem tells us that these triples correspond to square angled triangles that have sides of integer length. The best known of these triples are {3, 4, 5} and {5, 12, 13} but there are an infinite number of them.

The theorem that we will formalize says that all Pythagorean triples are given by the formula:

a = n^{2} − m^{2}  b = 2mn  c = n^{2} + m^{2}

or are multiples of such a triple. For instance the triple {3, 4, 5} is given by n = 2, m = 1, and the triple {5, 12, 13} is given by n = 3, m = 2.

The proof of the theorem is straight-forward. You only needs to consider the case where a and b are relative prime. Some thought about parity gives that one of the a and b has to be even, and that the other and c is odd. Then if b is the even number of the two we get that:

(\frac{b}{2})^{2} = \frac{c^{2} − a^{2}}{4} = (\frac{c − a}{2})(\frac{c + a}{2})

But if the product of two relative prime numbers is a square, then both of those numbers are squares. So you get:

\frac{c − a}{2} = m^{2} \frac{c + a}{2} = n^{2}

which leads to the required formula.

Exercise 6.1.1 Study the Mizar Mathematical Library and try to decide whether Mizar is equally suited to all fields of mathematics and computer science, or that Mizar is best suited to certain subjects. In the latter case, what is most easily formalized in Mizar? And what least?

Exercise 6.1.2 We mentioned the Pythagorean theorem which says that the sides a, b and c of a square angled triangle satisfy a^{2} + b^{2} = c^{2}. Try to find this theorem in the MML. If it’s there, in what article does it occur and what is the theorem’s reference? If not, or if you don’t like the version that you find (exercise for when you finished this chapter): write an article that proves it.

6.2 Step 2: the empty Mizar article

In order to write a Mizar article you need a working Mizar system and a file to put the Mizar article in. In fact, as you will find out, you will need two files: a .MIZ file for your article and a .VOC file for its vocabulary.

In this tutorial we follow the Windows conventions of naming files. For Mizar under Unix everything should be lower case instead of upper case and the backslashes should go the other way. So what is called TEXT\MY_MIZAR.MIZ here, under Unix should be text/my_mizar.miz.

We will assume that you already have a properly installed Mizar system. For a description of how to install Mizar read Section 4.1, or see the README.TXT file that is in the Mizar distribution.

To write your article, you need to be in a directory that has two subdirectories called TEXT and DICT. If those directories don’t exist yet, make them. Put in the TEXT directory an empty file called MY_MIZAR.MIZ and put in the DICT directory an empty file called MY_MIZAR.VOC. (Replace the MY_MIZAR with a more appropriate name if you are writing an article of your own.)

The smallest legal .VOC file is empty but the smallest legal .MIZ file looks like this:

environ
begin

Use your favorite text editor to put those two lines in the TEXT\MY_MIZAR.MIZ file. Then check it using the command:

mizf text\my_mizar

It will both check syntax and mathematics of your article. If everything is well this command prints something like:

Make Environment, Mizar Ver. 6.1.05 (Win32/Delphi 4)
Copyright (c) 1990,2001 Association of Mizar Users
-Vocabularies-Constructors-Clusters-Notation
Verifier, Mizar Ver. 6.1.05 (Win32/Delphi 4)
Copyright (c) 1990,2001 Association of Mizar Users
Processing: text\my_mizar.miz
Parser   [   2]   0:00
Analyzer   0:00
Checker  [   1]   0:00
Time of mizaring: 0:01

meaning that this ‘article’ contains no errors. (If you use the emacs editor with its Mizar mode you don’t need to type the mizf command. In that case all you need to do to check the file is hit C-c RET.)

Apart from the MY_MIZAR.MIZ file, the TEXT directory now contains 24 other files. You never need to look inside them. They are only used internally by the Mizar system.

The next step is to connect the .MIZ file to the .VOC vocabulary. Add a vocabulary directive to your article:

environ
 vocabulary MY_MIZAR;
begin

Now the article is ready to be written. For the moment add some line of text at the end of the file just to find out what happens if the article contains errors:

environ
 vocabulary MY_MIZAR;
begin
 hello Mizar!

After you ran mizf text\my_mizar.miz command again, Mizar will insert the error messages inside your file. It will put a * with a number below any error. Also there will be an explanation of those error numbers at the end of the file. So after running the mizf command again your file looks like:

environ
 vocabulary MY_MIZAR;
begin
 hello Mizar!
::>  *143,321
::>
::> 143: No implicit qualification
::> 321: Predicate symbol or "is" expected

There is no need to try to understand those two error messages, because of course hello Mizar! is not legal Mizar. So remove this line, now that you have seen what Mizar thinks of it. You don’t need to remove the error message lines. They vanish the next time you run mizf.

The lines containing error messages can be recognized because they start with ::>. Mizar only gives you error numbers. It never prints anything about why it thinks it is wrong. Sometimes this lack of explanation is frustrating but generally Mizar errors are quite obvious.

Exercise 6.2.1 The minimal Mizar article that we showed is 2 lines long. What is the shortest article in the MML? What is the longest? What is the average number of lines in the articles in the MML?

As a rule of thumb an article less than a 1000 lines is considered too short to be submitted to the MML. However several articles in the MML are less than a 1000 lines long since articles are shortened during revision of the MML. How many of the articles in the MML are currently shorter than a 1000 lines?

Exercise 6.2.2 Copy an article from the MML to your private TEXT directory. Check that the Mizar checker mizf processes it without error messages. Experiment with making small modifications to it and see whether Mizar can detect where you tampered with it.

Put one screen-full of non-Mizar text – for instance from a Pascal or C program – somewhere in the middle of the article. How many error messages will you get? Can Mizar sufficiently recover from those errors to check the second half of the file reasonably well?

6.3 Step 3: the statement

To start translating your mathematics to Mizar you need to write the theorem that you want to prove in Mizar syntax.

There are two things about Mizar syntax that are important for you to note:

• There are no spelling variants in Mizar. Although Mizar resembles natural language a lot, it is a formal language and there are no possibilities to choose between phrasings. For example:

and means something different from &

not means something different from non

such that means something different from st

assume means something different from suppose

NAT means something different from Nat means something different

    from natural

So you should really pay attention to the exact keywords in the Mizar syntax. It’s not enough if it resembles it.

The only exception to this rule is that be and being are alternative spellings. So although it’s more natural to write let X be set and for X being set holds … you are also allowed to write let X being set

and for X be set holds . . .

• There is no distinction in Mizar between ‘function notation’ and ‘operator notation’. In most programming languages something like f(x,y) and x+y are syntactically different things. In Mizar this distinction doesn’t exist. In Mizar everything is an operator. If you write f(x,y) in Mizar then it really is a ‘operator symbol’ f with zero left arguments and two right arguments.

Similarly predicate names and type names can be any string of characters that you might wish. You can mix letters, digits and any other character you might like in them. So for instance if you want to call a predicate \/-distributive you can do so in Mizar. And it will be one ‘symbol’.

If you are not sure what characters go together as a symbol in a Mizar formula, you can go to the web pages of the MML abstracts. In those pages the symbols are hyperlinks that point to definitions. So just click on them to find out what symbol they are.

To write Mizar you need to know how to write terms and how to write formulas.

We tackle this in top-down fashion. First we describe how to translate formulas from predicate logic into Mizar. Then we describe how the syntax of Mizar terms works.

6.3.1 Formulas

Here is a table that shows all you want to know about how to write predicate logic in Mizar:

                 ⊥  contradiction
                 ¬ϕ  not ϕ

ϕ ∧ ψ  ϕ & ψ
ϕ ∨ ψ  ϕ or ψ

               ϕ ⇒ ψ  ϕ implies ψ

ϕ ⇔ ψ  ϕ iff ψ

               ∃ x. ψ  ex x st ψ
               ∀ x. ψ  for x holds ψ
             ∀ x. (ϕ ⇒ ψ) for x st ϕ holds ψ

There is no special way to write ⊤ in Mizar. One usually writes notcontradiction for this. Note that with the quantifiers it should be st and not suchthat.

Using this table you now can write logical formulas in Mizar. There is one more thing that you need to know to write Mizar formulas in

practice. Mizar is a typed language. We will discuss Mizar types in detail in Section 6.3.4 below, but the types turn up in the predicate logic formulas too. All variables that you use in formulas need to have a type. There are two ways to give a variable a type:

• Put the type in the formula using a being type attribution. For instance you can write an existential formula about natural numbers m and n as:

ex m,n being Nat st . . .

• Give the type for the variable with a reserve statement. This doesn’t introduce a variable, it just introduces a notation convention. If you use a reserve statement you can leave out the type in the formula:

reserve m,n for Nat;
ex m,n st . . .

This way of typing variables in formulas is much more convenient than explicitely typing the variables and so it is the method that is generally used.

Exercise 6.3.1 Translate the following Mizar formulas into predicate logic notation:

ϕ iff not not ϕ
not (ϕ & ψ) implies not ϕ or not ψ
ex x st ϕ implies ψ
for x st for y st ϕ holds ψ holds χ

Translate the following predicate logic formulas into Mizar syntax:

¬ϕ ⇔ ¬¬¬ϕ
¬(ϕ ∨ ψ) ⇒ (¬ϕ ∧ ¬ψ)
∃ x. (ϕ ∧ ψ)
∃ x. ((∃ y. (ϕ ⇒ ψ)) ⇒ χ)

If you worry about the priorities of the Mizar logical operators add as many brackets as you need to feel sure. Alternatively look at the table in Section 3.12.1.

6.3.2 Relations

You still need to know how to write atomic formulas. In Mizar there are two ways to write those:

• If R is a predicate symbol, write:

x_{1}, x_{2}, …, x_{m} R x_{m+1}, …, x_{m+n}

Both m or n might be 0, in which case this becomes prefix or postfix notation. Note that postfix notation can have more than one argument, as for instance in x,y are_relative_prime. Please note that brackets around the arguments of the predicate are not allowed.

• If T is a type, or the adjectives part of a type, write:

                                x is T

For instance you can write x is prime. We will discuss types in Section 6.3.4 below.

To find out what relations are available to you, you will need to browse the MML. Here is a short list of some of the most frequent used relations to get you started.

                              \begin{aligned}= & = \\ ≠ & <> \\ < & < \\ ≤ & <= \\ ∈ & in \\ ⊆ & c= \end{aligned}

The first character in the Mizar representation of ⊆ is the letter c.

6.3.3 Terms

There are three ways to write Mizar terms:

• If f is an operator symbol, which Mizar calls a functor, write:

(x_{1}, x_{2}, …, x_{m}) f (x_{m+1}, …, x_{m+n})

Again, m or n might be 0, in which case this becomes prefix or postfix notation. As an example of a postfix operator there is ^2 for square. The brackets around either list of arguments can be omitted if there is just one argument.

• If L and R are bracket symbols, write:

L x_{1}, x_{2}, …, x_{n} R

In this case brackets ( and ) around the arguments are not necessary, since the symbols themselves are already brackets. An example of this kind of term is the ordered pair [x,y]. In that case n = 2, L is [ and R is ].

• Any natural number is a Mizar term. If you write natural numbers, you should add to your environ the line:

requirements SUBSET, ARYTM;

because else they won’t behave like natural numbers.

The word functor for function symbol or operator symbol is Mizar terminology. It has nothing to do with the notion of functor in category theory. It is used to distinguish a function symbol in the logic from a function object in the set theory (which is a set of pairs).

Again to find out what operators are available to you, you will need to browse the MML. Here is a short list of some of the most frequent used operators to get you started.

                          ∅  {}

{x}  { x }
{x, y}  { x,y }
X ∪ Y  X U Y
X ∩ Y  X ∩ Y

                         ℕ  NAT
                         ℤ  INT
                         ℝ  REAL

x + y  x + y
x − y  x - y
−x  - x
xy  x · y
x/y  x / y
x^{2}  x^2

                         \sqrt{x}  sqrt x

P(X)  bool X
(x, y)  [ x,y]

                       X × Y  [:X,Y:]
                         Y^{X} Funcs(X,Y)

f(x)  f.x

                         ⟨⟩  <**>D
                         ⟨x⟩  <* x *>

⟨x, y⟩  <* x,y *>
p · q  p^q

The union operator is the capital letter U. The digit 2 is part of the symbol for the square operator. The last four operators are used to build finite sequences over the set D.

The characters · and ∩ are DOS characters with ASCII codes ≥ 128. Mizar uses that kind of character for some of its symbols. The specific characters · and ∩ have codes 249 and 239. How to type them may depend on your editor. Try holding the alt key and simultaneously typing the number on the numeric keypad.

The . operation is function application inside the set theory. If f is a symbol in the language representing a functor with zero left arguments and one right argument then you write:

f x

or (you can always put a term in brackets):

f(x)

If f is a function in the set theory – a set of pairs – then

f.x

is the image of x under f, in other words it is the y such that [x,y] in f.

6.3.4 Types: modes and attributes

The one thing left for you to understand to write Mizar formulas is Mizar’s types. Although Mizar is based on ZF-style set theory – so the objects of Mizar are untyped – the terms of Mizar are typed.

An example of a Mizar type is:

                  non empty finite Subset of NAT

This type should be parsed as:

                 non empty  finite

                                     \underline{Subset} of NAT

A Mizar type consists of an instance of a mode with in front a cluster of adjectives. The type without the adjectives is called the radix type. In this case the mode is Subset and its argument is NAT, the radix type is Subset of NAT, and the two adjectives are non empty and finite.

To put this abstractly, a Mizar type is written:

α_{1} α_{2} … α_{m} M of x_{1}, x_{2}, …, x_{n}

where α_{1}, … α_{m} are adjectives, M is a mode symbol and x_{1}, x_{2}, …, x_{n} are terms. The keyword of binds the arguments of the mode to the mode. It’s like the brackets in a term.

The number of arguments n is part of the definition of the mode. For instance for set it is zero. You can’t write set of …, because there does not exist a set mode that takes arguments.

Modes are dependent types. To find out what modes are available to you, you will need to browse the MML. Here is a short list of some of the most frequent used modes to get you started.

                               set
                              number
                          Element of X
                           Subset of X
                               Nat
                               Int
                               Real
                             Ordinal
                             Relation
                         Relation of X,Y
                             Function
                         Function of X,Y
                        FinSequence of X

Note that there both are modes Relation and Function with no arguments, and more specific modes RelationofX,Y and FunctionofX,Y with two arguments. They share the mode symbol but they are different.

Also note that the modes depend on terms. So there are no types representing the functions from a type to a type. The Function mode represents the functions from a set to a set. As an example the function space (X → Y) × X → Y

corresponds to the Mizar type Function of [:Funcs(X,Y),X:],Y

Adjectives restrict a radix type to a subtype. They either are an attribute, or the negation of an attribute using the keyword non. Again, to find out what attributes are available to you, you will need to browse the MML. Here is a list of a few attributes.

                              empty
                               even
                               odd
                              prime
                             natural
                             integer
                               real
                              finite
                             infinite
                            countable

Maybe you now wonder about how types are used in Mizar. To clarify this take a look at three Mizar notions – NAT, Nat and natural – that all mean the same thing: the set of natural numbers. Here is a table that compares their uses:

meaning  declaration  formula

             n ∈ ℕ  n in NAT
             n : ℕ  n be Nat          n is Nat
             n : ℕ n be natural number  n is natural

NAT is a term, Nat is a type and natural is an adjective. be/being are a typing in a declaration and go between a variable and a type. in is the ∈ relation of the set theory and goes between two terms. is goes between a term and a type or between a term and an adjective. Note that in Mizar you can have a ‘type judgement’ as a formula in the logic.

The example We now give the statement of the theorem for the example. The statement that we will prove in this chapter is:

reserve a,b,c,m,n for Nat;
a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd implies
 ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2;

So put this after the begin line of your MY_MIZAR.MIZ file.

We also could have made the quantification of the a, b and c explicit:

for a,b,c st
 a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd holds
  ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2;

but it is not necessary. Mizar automatically quantifies over free variables.

We now analyze this statement in some detail. The formula has the structure:

        ϕ_{1} & ϕ_{2} & ϕ_{3} implies ex m,n st ϕ_{4} & ϕ_{5} & ϕ_{6} & ϕ_{7};

The predicate logic formula that corresponds to this is:

(ϕ_{1} ∧ ϕ_{2} ∧ ϕ_{3}) ⇒ ∃ m, n. (ϕ_{4} ∧ ϕ_{5} ∧ ϕ_{6} ∧ ϕ_{7})

The first three atomic formulas in this are:

                  ϕ_{1} ≡ a^2 + b^2 = c^2
                  ϕ_{2} ≡ a,b are_relative_prime
                  ϕ_{3} ≡ a is odd

They have the structure:

ϕ_{1} ≡ t_{1} = t_{2}

                 ϕ_{2} ≡ t_{3}, t_{4} are relative prime

ϕ_{3} ≡ t_{5} is T

In this = and are_relative_prime are predicate symbols. T is the adjective odd. So we here see both kinds of atomic formula: twice a relation between terms and once a typing.

The first term t_{1} in ϕ_{1} is:

                         t_{1} ≡ a^2 + b^2

It has the structure:

t_{1} ≡ u_{1} + u_{2}
u_{1} ≡ v_{1} ^2
u_{2} ≡ v_{2} ^2
v_{1} ≡ a
v_{2} ≡ b

In this + and ^2 are functor symbols.

Exercise 6.3.2 Find Mizar types for the following concepts:

odd number that is not a prime number

empty finite sequence of natural numbers

uncountable set of reals

element of the empty set

non-empty subset of the empty set

What is the problem with the last two concepts? Do you think they should be allowed in Mizar? Study this manual to find out whether they are.

Exercise 6.3.3 Write the following statements as Mizar formulas:

The only even prime number is 2.

If a prime number divides a product it divides one of the factors.

There is no biggest prime number.

There are infinitely many prime twins.

Every even number ≥ 4 is the sum of two primes.

Write these statements first using reserve statements. Then write them again but this time with the types in the formulas.

6.4 Step 4: getting the environment right

Add the statement that you wrote to your article. Then check it. You will get error messages:

environ
 vocabulary MY_MIZAR;
begin
 reserve a,b,c,m,n for Nat;
::>                      *151
a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd implies
::>,203
 ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2;
::>
::> 151: Unknown mode format
::> 203: Unknown token

That’s because you didn’t import what you used from the MML. There’s nothing wrong with the statement, there’s something wrong with the environment (it’s empty). To correct this, you need to add directives to the environ part of the article to import what you need.

It is hard to get the environment of a Mizar article correct. In practice people often just copy the environment of an old article. However that doesn’t help much when it doesn’t work, and occasionally it doesn’t work. So you still have to understand how the environment works to get it right when you get environment related errors.

6.4.1 Vocabulary, notation, constructors

The rule is quite simple. For everything you use – predicate, functor, mode or attribute – you have to add a relevant reference to three directives:

   • vocabulary
   • notation
   • constructors

The list of references for notation and constructors is generally almost identical. In fact, if you follow the algorithm from this section to get them right they will be identical. These directives are about:

• Lexical analysis. The tokens in a Mizar article come from lists called vocabularies. Mizar variables are identifiers with a fixed syntax, but the predicates, functors, types and attributes all are symbols which can contain any character. You need to indicate from what vocabularies you use symbols.

• Parsing of expressions. To have an expression you need to list the articles that you use predicates, functors, types and attributes from. The notation directive is for the syntax of expressions. The constructors directive is for its meaning.

Here is a list of what we use in our statement, what kind of thing it is, and what vocabularies and articles we need for it:

symbol  kind vocabulary article

          =  pred  HIDDEN
          <=  pred  HIDDEN     ARYTM
          +  func  HIDDEN     ARYTM
          ·  func  HIDDEN     ARYTM
          -  func  REAL_1     REAL_1
          Nat  mode HIDDEN     NAT_1
          are_relative_prime pred  INT_2      INT_2
          ^2  func  SQUARE    SQUARE_1
          odd  attr  MATRIX2     ABIAN

You don’t need to refer to the HIDDEN vocabulary or the HIDDEN article but you need to list the others. The vocabularies should go in the vocabulary directive and the articles should go both in the notation and constructors directives. So your environment needs to be:

environ
 vocabulary MY_MIZAR, REAL_1, INT_2, SQUARE, MATRIX2;
 notation ARYTM, REAL_1, NAT_1, INT_2, SQUARE_1, ABIAN;
 constructors ARYTM, REAL_1, NAT_1, INT_2, SQUARE_1, ABIAN;

Here is the way to find out what the vocabulary and article a given symbol are:

• To find the vocabulary use the command:

     findvoc -w symbol

For instance the command:

     findvoc -w ^2

gives:

     FindVoc,  Mizar  Version 6.0.04 (/TP 7.0)
     Copyright (c) 1990,2000 Association of Mizar Users
     vocabulary: SQUARE
     O^2  254

The O means that this is a functor symbol, and 254 is the priority.

• To find the article, the easiest way is to go to the web pages of the abstracts of the MML, find a use of the symbol somewhere, and click on it to go to the definition.

6.4.2 Redefinitions and clusters

But now things get tough. It turns out that your environment still does not work! The problem is that the types are wrong. If we check the article with the new environment we get:

a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd implies
 ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2;
::>           *102                       *103
::>
::> 102: Unknown predicate
::> 103: Unknown functor

To get rid of these kind of typing problems is the most difficult part of writing a Mizar article. (In practice this kind of error often is caused because a cluster is missing. So if you are completely mystified by a Mizar error, start thinking ‘cluster!’)

In this specific case:

• The first error is caused by the fact that m and n have type Nat, but <= wants arguments of type real number.

• The second error is caused by the fact that Mizar doesn’t know (with this environment) that 2 has type Nat.

We solve the first error in this section and the second error in the next one.

A Mizar expression doesn’t have just one type, it has a whole set of types. There are two ways to influence the type of an expression.

• To give a specific expression a more precise radix type, you use redefinitions. A functor can have many redefinitions that cause it to have different radix types depending on the types of its arguments.

Here is an example of a redefinition taken from FINSET_1.

definition let E be set, let A,B be Subset of E;
 redefine func A U B -> Subset of E;
end;

It means that if A and B have type SubsetofE then AUB has type Subset of E instead of set.

See Section 3.6.12 for a full discussion of redefinitions.

Since the last defined redefinition that matches the types of the arguments is the one that is used, the order of the articles in the notation directive is important!

• To generate more adjectives for an expression, Mizar has something called clusters. The process of adding adjectives according to these cluster definitions is called the rounding up of clusters.

Here are examples of three kinds of clusters taken from FINSET_1.

definition
 cluster empty -> finite set;
end;

This means that every set that has adjective empty also will get adjective

finite.
definition let X,Y be finite set;
 cluster X U Y -> finite;
end;

This means that every expression of the shape X U Y where X and Y have type finite set also will get adjective finite.

definition let B be finite set;
 cluster -> finite Subset of B;
end;

This means that every expression that has type Subset of B where B has type finite set also will get adjective finite.

See Sections 3.6.6 and 3.6.7 for a full discussion of clusters.

So to summarize: redefinitions are for narrowing the radix type and clusters are for extending the set of adjectives. (There are also redefinitions that have nothing to do with typing, and clusters that have nothing to do with adding adjectives. You should not be confused by this.)

You can always test whether some type T is in the set of types of an expression t by changing it to ( t qua T ). You get an error if t didn’t have T in its set of types. In that case you might start looking for a redefinition or cluster that changes this situation.

The example Here is the solution to the first typing error. We want to accomplish that the type Nat widens to the type real number.

Type Nat expands to Element of omega. Furthermore number is equivalent to set and all types widen to set. The cluster from ARYTM_3:

definition
 cluster -> natural Element of omega;
end;

causes all expressions that have type Elementofomega to also get the adjective natural. The cluster from ARYTM:

definition
 cluster natural -> real number;
end;

causes all expressions that have type natural number to also get the adjective real. So adding:

 clusters ARYTM_3, ARYTM;

to the environment causes all expressions of type Nat to also get type real number. This gets rid of the first error.

6.4.3 The other directives

Here is a list of the eight kinds of directives in the environ and the kind of reference they take:

              vocabulary  vocabulary
              notation  article
              constructors article
              clusters  article
              definitions article
              theorems  article
              schemes  article
              requirements  SUBSET, BOOLE, ARYTM, REAL

Here is when you need the last four kinds of directive:

• The definitions directive is not about being able to use the theorems that are part of the definitions (that’s part of the theorems directive.) It’s about automatically unfolding predicates in the thesis that you are proving.

This directive is useful but not important. You can ignore it until you get up to speed with Mizar.

• The theorems and schemes directives list the articles you use theorems and schemes from. So whenever you refer to a theorem in a proof, you should check whether the article is in the list of this directive.

These are easy directives to get right.

• The requirements directive makes Mizar know appropriate things automatically.

For instance to give numerals type Nat you need

 requirements SUBSET, ARYTM;

So this is the solution to the second typing error left in our article.

With ARYTM and REAL Mizar knows some basic equations about numbers automatically. For instance with it, Mizar accepts 1+1 = 2 without proof.

This is an easy directive to get right. Just put in a requirement if you think it will help, and see what happens.

So now that we got the environment right the article checks like this:

environ
vocabulary MY_MIZAR, REAL_1, INT_2, SQUARE, MATRIX2;
notation ARYTM, REAL_1, NAT_1, INT_2, SQUARE_1, ABIAN;
constructors ARYTM, REAL_1, NAT_1, INT_2, SQUARE_1, ABIAN;
clusters ARYTM_3, ARYTM;
requirements SUBSET, ARYTM;
begin
reserve a,b,c,m,n for Nat;
a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd implies
ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2;
::>                                                         *4
::>
::> 4: This inference is not accepted

The only error left is *4. It means that Mizar is not able to prove the statement on its own.

This is an important milestone. Articles with only *4 errors are ‘almost finished’. They just need a bit of proof.

Exercise 6.4.1 Consider the nine types:

     Element of NAT
     Element of INT
     Element of REAL
     Nat
     Integer
     Real
     natural number
     integer number
     real number

There are 45 pairs of different types T_{1} and T_{2} from this list for which the formula:

for x being T_{1} holds (x qua T_{2}) = x;

should be allowed. What is an environment that gives the minimum number of error messages *116 (meaning Invalid "qua")? What is used from the articles in this environment?

In particular explain why Mizar will allow:

for x being Nat holds (x qua Real) = x;

What are the redefinitions that make this work?

Exercise 6.4.2 Apart from the kinds of cluster that we showed in Section 6.4.2 (the ones that generate extra adjectives for terms), Mizar has something called existential clusters. These are the clusters without ->. They don’t generate extra adjectives for a term. Instead they are needed to be allowed to add adjectives to a type.

The reason for this is that Mizar types always have to be non-empty. So to be allowed to use a type something has to be proved. That is what an existential cluster does.

For example to be allowed to use the type:

non empty finite Subset of NAT

you needs an existential cluster from GROUP_2:

definition let X be non empty set;
 cluster finite non empty Subset of X;
end;

If you don’t have the right existential clusters in your article you will get error

*136 which means Non registered cluster.

Which types in the following list have an existential cluster in the MML? For the ones that have one, where did you find them? For the ones that don’t have one, what would be an appropriate existential cluster?

     empty set

odd prime Nat
infinite Subset of REAL
non empty Relation of NAT,NAT

6.5 Step 5, maybe: definitions and lemmas

Step 5 you can skip. Then you just start working on the proof of the theorem immediately.

However if you did step 1 right, you probably have some lemmas that you know you will need. Or maybe you need to define some notions before being able to state your theorem at all.

So do so in this step. Add relevant definitions and lemmas to your article now. Just like the statement in step 3. Without proof. Yet.

6.5.1 Functors, predicates

There are two ways to define a functor in Mizar:

• As an abbreviation:

definition let x be Real;
 func x^2 -> Real equals x · x;
 coherence;
end;

The coherence correctness condition is that the expression x · x really has type Real like it was claimed. If Mizar can’t figure this out by itself you will have to prove it.

• By a characterization of the result:

definition let x be Real;
 assume 0 <= x;
 func sqrt x -> Real means
  0 <= it & it^2 = x;
 existence;
 uniqueness;
end;

In the characterizing statement the variable it is the result of the functor.

The existence and uniqueness are again correctness conditions. They state that there always exists a value that satisfies the defining property, and that this value is unique. (In the proof of them you are allowed to use that the assumption from the definition is satisfied.)

In this case existence is the statement:

ex y being Real st 0 <= y & y^2 = x

and uniqueness is the statement:

for y,y' being Real st
 0 <= y & y^2 = x & 0 <= y' & y'^2 = x holds y = y'

And here is an example of the way to define a predicate:

• definition let m,n be Nat;
 pred m,n are_relative_prime means
  m hcf n = 1;
end;

The definition of a predicate doesn’t have a correctness condition. (In this example hcf is the greatest common divisor.)

6.5.2 Modes and attributes

There are two ways to define a mode in Mizar:

• As an abbreviation:

definition let X,Y be set;
 mode Function of X,Y is
  quasi_total Function-like Relation of X,Y;
end;

In this definition quasi_total and Function-like are attributes.

• By a characterization of its elements.

definition
 let X,Y be set;
 mode Relation of X,Y means
  it c= [:X,Y:];
 existence;
end;

The existence correctness condition states that the mode is inhabited. This has to be the case because Mizar’s logic wants all Mizar types to be non-empty.

In this case existence is the statement:

ex R st R c= [:X,Y:]

And here is an example of the way to define an attribute:

   • definition let n be number;
      attr n is square means
       ex m being Nat st n = m^2;
     end;

If your symbol is not already in one of the MML vocabularies you need to put it in your own vocabulary. It should be on a line of its own with O in front for functors, R in front for predicates, M in front for modes or V in front for attributes. For instance you might add the line:

Vsquare

to the MY_MIZAR.VOC file. You can run:

listvoc vocabulary

to look at vocabularies from the MML.

The example The essential lemma for the example is that if two numbers are relative prime and their product is a square, then they are squares themselves. In Mizar syntax this is the statement:

m · n is square & m,n are_relative_prime implies
 m is square & n is square

A Mizar article is a sequence of definitions and statements. Definitions are always public, but statements can only be referred to from the outside of the article when they’re preceded by the keyword theorem. So change the body of the article to:

theorem Th1:
 m · n is square & m,n are_relative_prime implies
  m is square & n is square;
::>                       *4,4
theorem Th2:
 a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd implies
  ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2;
::>                                                          *4
::>
::> 4: This inference is not accepted

Exercise 6.5.1 We claimed that Mizar’s types are always non-empty. However you can write the type:

Element of {}

Explain why this is not a problem.

6.6 Step 6: proof skeleton

Mizar is a block structured language like the Pascal programming language. Instead of begin/end blocks it has proof/end blocks. And instead of procedures it has theorems. Apart from that it is a rather similar language.

We will now write the proof of the theorem. For the moment we just write the steps and not link them together. Linking the steps in the proof will be step 7 of the nine easy steps.

A Mizar proof begins with the keyword proof and ends with the keyword

end.

Important! If you have a proof after a statement there should not be a semicolon after the statement. So:

statement ;

proof

proof steps

end;

is wrong! It should be:

statement

proof

proof steps

end;

This is easy to do wrong. Then you will get a *4 error at the semicolon that shouldn’t be there.

In this section we will discuss the following kinds of proof step. There are some more but these are the frequently used ones:

step  section
compact  6.6.2

                          assume  6.6.1

thus  6.6.1
let  6.6.1
take  6.6.1

                         consider  6.6.2
                    per cases/suppose 6.6.2

set  6.6.3

                        reconsider  6.6.3

iterative equality  6.6.4

6.6.1 Skeleton steps

During the steps of the proof the statement that needs to be proved is kept track of. This is the ‘goal’ of the proof. It is called the thesis and can be referred to with the keyword thesis.

A Mizar proof consists of steps. Steps contain statements that you know to be true in the given context. Some of the steps reduce the thesis. At the end of the proof the thesis should be reduced to ⊤ or else you will get error *70 meaning Something remains to be proved. Steps that change the thesis are called skeleton steps.

The four basic skeleton steps are assume, thus, let and take. They correspond to the shape of the thesis in the following way:

thesis to be proved, before the step  thesis to be proved, after

    ϕ implies ψ  assume ϕ  ψ
    ϕ & ψ  thus ϕ  ψ
    for x being T holds ψ let x be T ψ
    ex x being T st ψ  take t  ψ[x := t]

Just like with for the typing can be left out of the let if the variable is in a reserve statement.

Here is an example of how these skeleton steps work in a very simple proof:

for x,y st x = y holds y = x
proof
 let x,y;
 assume x = y;
 thus y = x;
end;

At the start of the proof the thesis is for x,y st x = y holds y = x. After the let step it is reduced to x = y implies y = x. After the assume step it is reduced to y = x. After the thus step it is reduced to ⊤ and the proof is complete.

The skeleton steps of the proof of the example will be:

theorem Th2:
 a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd implies
  ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2
proof
 assume a^2 + b^2 = c^2;
 assume a,b are_relative_prime;
 assume a is odd;
 take m,n;
 thus m <= n;
 thus a = n^2 - m^2;
 thus b = 2 · m · n;
 thus c = n^2 + m^2;
end;

At this point we don’t have anything to put in the place of the m and n. We need another kind of step for that.

Exercise 6.6.1 Explain why you can always end a proof with a thus thesis step. This is the Mizar version of quod erat demonstrandum. Count in the MML how many times this construction occurs. (Include in your count hence thesis which is the same thing.) Is there an occurence of thesis in the MML which is not part of this construction?

Exercise 6.6.2 Write the skeleton steps in the proofs for the following Mizar statements:

     x = 0 & y = 0 implies x + y = 0 & x · y = 0
     ex x st x in X implies for y holds y in X
     for n st not ex m st n = 2 · m holds ex m st n = 2 · m + 1
     (ex n st n in X) implies
      ex n st n in X & for m st m < n holds not m in X

Write a fresh variable in the take steps if there is no good choice for the term.

6.6.2 Compact statements and elimination

The simplest step is a compact step. This is just a statement that is true in the current context. This is the most common step in a Mizar proof.

And these are the consider and per cases/suppose constructions. They are both related to a statement:

if you can prove this … you can have this as a proof step

                 ex x st ϕ  consider x such that ϕ;
     ϕ_{1} or ϕ_{2} or . . . or ϕ_{n}  per cases;

                                 suppose ϕ_{1};

proof for the case ϕ_{1}

                                 suppose ϕ_{2};

proof for the case ϕ_{2} …

                                 suppose ϕ_{n};

proof for the case ϕ_{n}

To use natural deduction terminology, these steps correspond to existential and disjuction elimination. The consider step introduces a variable that you can refer to in your proof, just like the let step.

We can now add the following steps to the example proof to give us terms m and n for the take step:

…

 ((c - a)/2) · ((c + a)/2) = (b/2)^2;
 ((c - a)/2) · ((c + a)/2) is square;
 (c - a)/2,(c + a)/2 are_relative_prime;
 (c - a)/2 is square & (c + a)/2 is square;

 consider m such that (c - a)/2 = m^2;
 consider n such that (c + a)/2 = n^2;
 take m,n;

…

The first four steps are compact statements. The two consider steps use the existential statement that’s part of the definition of square.

6.6.3 Macros and casts

Often in proofs certain expressions occur many times. It is possible to give such expressions a name using set commands:

 set h = b/2;
 set m2 = (c - a)/2;
 set n2 = (c + a)/2;

A set command is a definition of a constant that is local to the proof. It behaves very much like a macro.

When writing Mizar articles, often you want to use an expression with a different type than it’s got. You can change the type of an expression with the reconsider command. This is like a set, but also gives the type of the new variable.

In the example we will need the abbreviated variables h, m2 and n2 to have type Nat. This can be accomplished by changing the set lines in the previous paragraph to:

 reconsider h = b/2 as Nat;
 reconsider m2 = (c - a)/2 as Nat;
 reconsider n2 = (c + a)/2 as Nat;

Again the new variables behave like macros, but now with a different type. So reconsider is a way to cast the type of a term.

6.6.4 Iterative equalities

In mathematical calculations one often has a chain of equalities. Mizar has this feature too.

You can write a calculation:

(\frac{c − a}{2})(\frac{c + a}{2}) = \frac{(c − a)(c + a)}{4} = \frac{c^{2} − a^{2}}{4} = \frac{b^{2}}{4} = (\frac{b}{2})^{2}

in Mizar as:

 ((c - a)/2) · ((c + a)/2) = (c - a) · (c + a)/4
  .= (c^2 - a^2)/4
  .= b^2/4
  .= (b/2)^2;

Such a chain of .= equalities is called an iterative equality. Note that the first equality in the chain is written with the = symbol instead of with the .= symbol.

Exercise 6.6.3 Collect the steps for the proof of Th2 that were given in this section. Put them in the proper order in your MY_MIZAR.MIZ file. Use the reconsider lines (not the set lines) and replace the abbreviated expressions everywhere by their abbreviation. Put in the iterated equality as well.

Add two compact statements before the reconsider lines stating that b is even and that c is odd. They will be needed to justify the reconsider lines. Add two compact statements relating m2 and n2 to a and c after the reconsider lines.

Now check your file with mizf. Update the environment if necessary until you have only *4 errors left. How many *4 errors do you get?

6.7 Step 7: completing the proof

In this section you will add justifications to the steps of your proof. That will finish your article.

6.7.1 Getting rid of the *4 errors

There are three ways to justify a step in Mizar:

• By putting a semicolon ; after it:

statement ;

This is the empty justification. It tells Mizar: figure this out by yourself.

• By putting by after it with a list of labels of previous statements:

statement by reference , …, reference ;

In fact the previous way to justify a step is the special case of this in which the list of references is empty.

• By putting a subproof after it:

statement proof steps in the subproof end;

The subproofs are what gives Mizar proofs the block structured look.

If you don’t use thesis in the subproof, the statement can be reconstructed from the steps. Therefore you might want to omit the statement. You can do this by using now:

now steps in the subproof end; This is exactly the same as the statement with the subproof, but you don’t need to write the statement.

Here is a small example that shows how by is used:

(x in X implies x in Y) & x in X implies x in Y
proof
 assume
A1: x in X implies x in Y;
 assume
A2: x in X;
 thus x in Y  by A1,A2;
end;

Of course this one is so easy that Mizar can do it on its own:

(x in X implies x in Y) & x in X implies x in Y  ;

Often in the list of references after a by justification, there is a reference to the previous statement. This can also be written by putting then in front of the step. Using then you can often avoid having to label statements. So you can replace:

A1: statement; A2: statement; statement by A1,A2:

by

A1: statement; statement;

 then statement by A1;

Some people like writing the then on the previous line, after the statement that it refers to:

A1: statement; statement; then statement by A1;

This is a matter of taste. Other people choose the position of the then depending on whether the statement after the then has a label or not.

When you want to use then to justify a thus step you are not allowed to write then thus. You have to write hence. In Mizar when in certain combinations of two keyword get together you have to replace the combination by something else. Here are the two relevant equations:

                     then + thus = hence
                     thus + now = hereby

So the hence keyword means two things:

1. This follows from the previous step.

2. This is part of what was to be proved.

A common Mizar idiom is hencethesis. You see that many times in any Mizar article.

6.7.2 Properties and requirements

So now you need to hunt the MML for relevant theorems. This is made difficult by three reasons:

• The MML is big.

• The MML is not ordered systematically but chronologically. It is like a mediaeval library in which the books are put on the shelf in the order that they have been acquired.

• Mizar is smart. The theorem you can use might not look very much like the theorem you are looking for.

As an example of the fact that theorems can be in unexpected places, the basic theorem that relates the two kinds of dividability that are in the Mizar libary:

m | n iff m | (n qua Integer);

is in an article called SCPINVAR which is about loop invariants of a certain small computer program (SCP stands for SCMPDS program and SCMPDS stands for small computer model with push-down stack).

The best way to find theorems in the MML is by using the grep command to search all the .ABS abstract files. Although the MML is huge it’s small enough for this to be practical. For instance this is an appropriate command to search for the theorem in the SCPINVAR article:

% grep ' | qua ' *.ABS
INT_2.ABS:   a | b iff (abs(a)) | (abs(b) qua Nat);
SCPINVAR.ABS:   m | n iff m | (n qua Integer);
%

And another problem when looking for theorems is that Mizar is too smart.

If you look at the definitions of +, · and <= you will find that they con-

tain the keywords commutativity, reflexivity, connectedness, synonym and
antonym:
definition let x,y be real number;
 func x + y means
:: ARYTM:def 3

…

  commutativity;
 func x · y means

:: ARYTM:def 4

…

commutativity;
pred x <= y means
:: ARYTM:def 5

…

reflexivity;
connectedness;
synonym y >= x;
antonym y < x;
antonym x > y;
end;

These keywords mean two things:

• If you use a synonym or antonym then Mizar will internally use the real name. So if you write:

a < b

then internally Mizar will consider this to be an abbreviation of:

not b <= a

and if you write:

a >= b

then internally Mizar will consider this to mean:

b <= a

• Mizar will always ‘know’ when justifying a step, about the properties

commutativity, reflexivity and connectedness. So if you have a state-

ment:

… x · y …

then Mizar behaves as if this statement is exactly the same as:

… y · x …

Also Mizar will use all implication of the shape:

x = y ⇒ x ≤ y

and:

x ≤ y ∨ y ≤ x

6.7. STEP 7: COMPLETING THE PROOF 67 when trying to do a justification. These properties mean for the < relation that:

¬(x < x)

and:

x < y ⇒ x ≤ y

For instance if you have proved:

a < b

then you can refer to this when you only need:

a <> b

This is all very nice but let’s look at three examples of the subtlety it leads to:

• Suppose you want to justify the following step:

 a >= 0;
 then c - a <= c by . . . ;

It turns out that the theorem that you need is:

theorem :: REAL_2:173
 (a<0 implies a+b<b & b-a>b) & (a+b<b or b-a>b implies a<0);

It will give you:

c - a > c implies a < 0

but because of the antonym definition of < and > this really means:

not c - a <= c implies not 0 <= a

which is equivalent to:

0 <= a implies c - a <= c

Which is what you need.

• Suppose you need to prove the equation:

(c + a + c - a)/2 = (c + c + a - a)/2

The + and - operators have the same priority and are left associative, so this has to be read as:

(((c + a) + c) - a)/2 = (((c + c) + a) - a)/2

68 CHAPTER 6. WRITING A MIZAR ARTICLE IN NINE EASY STEPS Because of commutativity of + this really is the same as:

((c + (c + a)) - a)/2 = (((c + c) + a) - a)/2

So you need to show that: c + (c + a) = (c + c) + a which is associativity of +, a theorem from the AXIOMS article:

theorem :: AXIOMS:13
 x + (y + z) = (x + y) + z;

Note that the original equation doesn’t look very much like an instance of associativity!

• Consider the transitive law for <=:

theorem :: AXIOMS:22
 x <= y & y <= z implies x <= z;

It’s good to have this, but where is the analogous law for <:

x < y & y < z implies x < z;

It turns out that this also is AXIOMS:22! To see why this is the case, note that it is a consequence of the stronger theorem:

x <= y & y < z implies x < z;

and becase of the antonym definition of < this is the same as:

x <= y & not z <= y implies not z <= x;

which is equivalent to:

z <= x & x <= y implies z <= y;

which is indeed AXIOMS:22. (The ‘arithmetical lemmas’ for the arithmetical operations that we have used as examples here all are in the three articles AXIOMS, REAL_1 and REAL_2. Unfortunately you will often have to look in all three. There is not an easy rule that will tell you what is where.)

Sometimes you should not go look for a theorem. If you have requirements ARYTM then Mizar knows many facts about the natural numbers without help. Sometimes those facts even don’t have a theorem in the library anymore, so you search for a long time if you don’t realize that you should use requirements. For instance if you use requirements ARYTM:

x + 0 = x;

and:

0 · x = 0;

and:

1 · x = x;

and:

0 < 1;

and:

0 <> 1;

all don’t need any justification.

Suppose you want to justify:

 a >= 1;
 then a > 0 by . . . ;

If you had 0 < 1 then this would just be an instance of AXIOMS:22 (as we just saw). But requirements ARYTM gives that to you for free! So you can just justify this step with AXIOMS:22.

Exercise 6.7.1 We claim that the MML is big. Count how many source lines there are in the .MIZ articles in the MML. Try to guess how many lines of Mizar a competent Mizar author writes per day and then estimate the number of man-years that are in the MML.

6.7.3 Automation in Mizar

In Mizar it’s not possible to write tactics to automate part of your proof effort like you can do in other proof checkers. All Mizar’s automation is built into the Mizar system by its developers.

Mizar has four kinds of automation:

Semantic correlates Internally Mizar stores its formulas in some kind of conjunctive normal form that only uses ∧, ¬ and ∀.

This means that it automatically identifies some equivalent formulas. These equivalence classes of formulas are called semantic correlates. Because of semantic correlates, the skeleton steps of a formula are more powerful than you might expect. For instance you can prove:

ϕ

proof
 assume not ϕ;

…

 thus contradiction;
end;

and also you can prove:

ϕ or ψ
proof
 assume not ϕ;

…

 thus ψ;
end;

(Mizar does not identify ϕ & ψ with ψ & ϕ. You have to put the thus steps in a proof in the same order as the conjuncts appear in the thesis.)

Properties and requirements Properties and requirements were discussed in the previous section.

Clusters Clusters automatically generate adjectives for expressions. Often theorems can be rephrased as clusters, after which they will become automatic.

Consider for instance the theorem:

m is odd square & n is odd square implies m + n is non square;

which says that a square can never be the sum of two odd squares. (The reason for this is that odd squares are always 1 modulo 4, so the sum would be 2 modulo 4, but an even square is always 0 modulo 4.)

This theorem can be rephrased as a cluster:

definition let m,n be odd square Nat;
 cluster m + n -> non square;
end;

Once you have proved this cluster Mizar will apply the theorem automatically when appropriate and you don’t have to give a reference to it in your proofs.

Justification using by The by justifier is a weak first order prover. It tries to deduce the statement in front of the by from the statements that are referred to after the by.

A by justification pretty much feels like a ‘natural reasoning step’. When one studies the proofs that humans write, it turns out that they tend to choose slightly smaller steps than by can do.

The way by works is:

• It puts the implication that it has to prove in conjunctive normal form. Then it tries to do each conjunct separately.

That’s why you often get more than one *4 error for a failed justification. Mizar puts in an error for every conjunct that has not been justified.

• It then tries to prove the inference. In only one of the antecedents can a universal quantifier be instantiated. Therefore:

     A1: for x holds x in X;
     A2: for x holds not x in X;
      contradiction by A1,A2;

won’t work because it both has to instantiate the for in A1 and A2. You will need to split this into:

     A1: for x holds x in X;
     A2: for x holds not x in X;
      a in X by A1;
      then contradiction by A2;

• The by prover will do congruence closure of all the equalities that it knows. It also will combine the typing information of equal terms.

• A conclusion that has an existential quantifier is equivalent to an antecedent that has a universal quantifier. Therefore by is able to derive existential statements from instantiations of it.

6.7.4 Unfolding of definitions

Here is a table that shows when Mizar will unfold definitions:

                         func/equals −
                         func/means −
                         pred/means ⋄
                         mode/is  +
                         mode/means ⋄
                         attr/means ⋄
                         set  +

The items in this table that have a + behave like macros. For instance the definition of Nat is:

definition
 mode Nat is Element of NAT;
end;

If you write Nat it’s exactly like writing Element of NAT. So theorems about the Element mode will automatically apply to Nat.

The items in the table that have a − will never be expanded. All you get is a definitional theorem about the notion. You will need to refer to this theorem if you want to use the definition.

The items in the table that have a ⋄ will be expanded if you use the definitions directive. Expansion only happens in the thesis. It takes place if a skeleton step is attempted that disagrees with the shape of the thesis.

For instance the definition of c= is:

definition let X,Y;
 pred X c= Y means
:: TARSKI:def 3
  x in X implies x in Y;
 reflexivity;
end;

If you have TARSKI in your definitions you can prove set inclusion as follows:

X c= Y
proof
 let x be set;
 assume x in X;

…

 thus x in Y;
end;

Similarly consider the definition of equality in BOOLE:

definition let X,Y;
 redefine pred X = Y means
:: BOOLE:def 8
  X c= Y & Y c= X;
end;

If you add BOOLE to your definitions it will allow you to prove:

X = Y
proof

…

 thus X c= Y;

…

 thus Y c= X;
end;

or even:

X = Y
proof
 hereby
  let x be set;
  assume x in X;

…

  thus x in Y;
 end;
 let x be set;
 assume x in Y;

…

 thus x in X;
end;

Exercise 6.7.2 Take the following skeleton proof of the the drinker’s principle. Add labels to the statements and put in justifications for all the steps:

ex x st x in X implies for y holds y in X
proof
 per cases;
 suppose ex x st not x in X;
  consider x such that not x in X;
  take x;
  assume x in X;
  contradiction;
  let y;
  thus y in X;
 suppose not ex x st not x in X;
  for x holds x in X;
  assume x in X;
  thus thesis;
end;

Experiment with other proofs of the same statement.

If you know constructive logic: write a Mizar proof of this statement that shows where the non-constructive steps in the proof are.

Exercise 6.7.3 Write a proof of the following statement:

(ex x st x in X implies y in Y) & (ex x st y in Y implies x in X)
 iff (ex x st x in X iff y in Y);

Can you think of a proof that doesn’t need per cases?

Exercise 6.7.4 Finish the proof of Th2. Add as many clusters and lemmas as you need. For instance you might use:

Lm1: m is odd square & n is odd square implies
      m + n is non square;
Lm2: n is even iff n/2 is Nat;
Lm3: m,n are_relative_prime iff
      for p being prime Nat holds not (p | m & p | n);
Lm4: m^2 = n^2 iff m = n;

but if you choose to use different lemmas that’s fine too. Just put them before the theorem (you can prove them later if you like). If you don’t think a lemma will be useful to others you don’t have to put theorem in front of it.

Now add compact statements and justifications to the proof of Th2 until all the *4 errors are gone.

6.8 Step 8: cleaning the proof

Now that you finished your article the fun starts! Mizar has several utilities to help you improve your article. These utilities will point out to you what is in your article that is not necessary.

Those utilities don’t put their error messages inside your file on their own. You need to use the program called errflag after running them to accomplish that.

relprem This program points out references in a by justifications – as well occurrences of then – that are not necessary. These references can be safely removed from your article.

This program also points out the real errors in the article. Some people prefer to always use relprem instead of mizf.

relinfer This program points out steps in the proof that are not necessary. It will indicate references to statements that can be short-circuited. You can omit such a reference and replace it with the references from the step that it referred to.

As an example of relinfer consider the following part of a proof:

A1: m2 · n2 = h^2 by . . . ;
A2: m2 · n2 is square by A1;
A3: m2,n2 are_relative_prime by . . . ;
A4: m2 is square & n2 is square by A2,A3,Th1;
 consider m such that m2 = m^2 by A4;

…

If you run:

relinfer text\my_mizar
errflag text\my_mizar
then you will get *604 meaning Irrelevant inference:
A1: m2 · n2 = h^2 by . . . ;
A2: m2 · n2 is square by A1;
A3: m2,n2 are_relative_prime by . . . ;
A4: m2 is square & n2 is square by A2,A3,Th1;
::>                                 *604
 consider m such that m2 = m^2 by A4;

…

It means that you can replace the reference to A2 in step A4 with the references in the justification of A2 itself. In this case that’s A1. So the proof can be shortened to:

A1: m2 · n2 = h^2 by . . . ;
A3: m2,n2 are_relative_prime by . . . ;
A4: m2 is square & n2 is square by A1,A3,Th1;
 consider m such that m2 = m^2 by A4;

…

Please take note that the relinfer program is dangerous! Not because your proofs will break but because they might become ugly. relinfer encourages you to cut steps that a human might want to see.

reliters (pronounced rel-iters, not re-liters) This program points out steps in an interative equality that can be skipped. If you omit such a step you have to add its references to the references of the next one.

As an example of reliters consider the following iterative equality:

 m2 · n2 = (c - a) · (c + a)/(2 · 2) by REAL_1:35
  .= (c - a) · (c + a)/4
  .= (c^2 - a^2)/4 by SQUARE_1:67
  .= b^2/4 by A1,REAL_2:17
  .= b^2/(2 · 2)
  .= b^2/2^2 by SQUARE_1:def 3
  .= h^2 by SQUARE_1:69;

If you run:

reliters text\my_mizar
errflag text\my_mizar
then you will get *746 meaning References can be moved to the next step
of this iterative equality:
 m2 · n2 = (c - a) · (c + a)/(2 · 2) by REAL_1:35
  .= (c - a) · (c + a)/4
::>                  *746
  .= (c^2 - a^2)/4 by SQUARE_1:67
  .= b^2/4 by A1,REAL_2:17
::>         *746
  .= b^2/(2 · 2)
  .= b^2/2^2 by SQUARE_1:def 3
  .= h^2 by SQUARE_1:69;

So you can remove the terms with the *746 from the iterative equality. You then have to move the references in the justification to that of the next term in the sequence. So the iterative equality can be shortened to:

 m2 · n2 = (c - a) · (c + a)/(2 · 2) by REAL_1:35
  .= (c^2 - a^2)/4 by SQUARE_1:67
  .= b^2/(2 · 2) by A1,REAL_2:17
  .= b^2/2^2 by SQUARE_1:def 3
  .= h^2 by SQUARE_1:69;

trivdemo This program points out subproofs that are so simple that you can replace them with a single by justification. It’s surprising how often this turns out to be the case!

chklab This program points out all labels that are not referred to. They can be safely removed from your article.

inacc This program points out the parts of the proofs that are not referred to. They can be safely removed from your article.

irrvoc This program points out all vocabularies that are not used. They can be safely removed from your article.

irrths This program points out the articles in the theorem directive that are not used for references in the proofs. They can be safely removed from your article.

Cleaning your article is fun! It really feels like polishing something after it is finished and making it beautiful.

Remember to check your article once more with mizf after you’re finished optimizing it to make sure that you haven’t accidentally introduced any new errors.

Exercise 6.8.1 Take the proof that you made in exercise 6.7.2 and run the programs that are discussed in this section on it. Which of the programs advise you to change your proof?

Exercise 6.8.2 Consider the statements in a Mizar proof to be points in a graph and references to the statements to be the edges. What are the relprem and relinfer optimizations when you consider them as transformations of these graphs? Draw a picture!

6.9 Step 9: submitting to the library

So now your article is finished and clean. You should consider submitting it to the MML.

There are two rules that articles for the MML have to satisfy:

• It is mathematics that’s not yet in the MML.

There should not be alternate formalizations of the same concepts in the MML. There’s too much double work in the MML already.

• It is significant.

As a rule of thumb the article should be at least a 1000 lines long. If it’s too short consider extending your article until it’s long enough.

There are many reasons to submit your article to the MML:

• People will be able to use your work and build on it.

• Your definitions will be the standard for your subject in later Mizar articles.

• When the Mizar system changes your article will be kept compatible by the people of the Mizar group.

• An automatically generated TEX version of your article will be published in a journal called Formalized Mathematics.

To find the details of how to submit an article to the MML see Section 5.2 or go to the web page of the Mizar project and click on the appropriate link. Be aware that to submit your article to the MML you need to sign a form that gives the Mizar people the right to change it as they see fit.

If your article is not suitable for submission to the MML but you still want to use it to write further articles, you can put it in a local library of your own. Currently this kind of local library will only support a few articles before it becomes rather inefficient. The MML has been optimized such that library files don’t grow too much. You can’t do this optimization for your local library yourself, because the tool for it is not distributed. So it’s really better to submit your work to the MML if possible.

If you want a local library of your own there need to be a third directory called PREL next to the already existing TEXT and DICT directories. To put the files for your article in this directory you need to run the commands:

env text\my_mizar
pre text\my_mizar

The env command creates the necessary library files and the pre command copies them to your private PREL directory.

After you have run env and pre you can use your article in further articles.

Exercise 6.9.1 How many Mizar authors are there in the MML? Shouldn’t you be one?

78 CHAPTER 6. WRITING A MIZAR ARTICLE IN NINE EASY STEPS

Some advanced features

Now that you know how to write a Mizar article, let’s take a look at some more advanced features of Mizar that you haven’t seen yet.

To show these features we use a small proof by Grzegorz Bancerek from the article QUANTAL1.MIZ. This article is about the mathematical notion of quantales. It is not important that you know what quantales are. We just use this proof to show some of Mizar’s features.

reserve
 Q for left-distributive right-distributive complete Lattice-like
     (non empty QuantaleStr),
 a, b, c, d for Element of the carrier of Q;
theorem Th5:
 for Q for X,Y being set holds \/(X,Q) [*] \/(Y,Q) = \/({a[*]
b: a in X & b in Y}, Q)
  proof let Q; let X,Y be set;
A1:  for a holds a[*]\/(Y,Q) = \/({a[*]b: b in Y}, Q) by Def5;
    {c[*]\/(Y,Q): c in X} = {\/({a[*]b: b in Y},Q): a in
 X} from FraenkelF'(A1);
   hence
  \/(X,Q) [*] \/(Y,Q) =
    \/({\/({a[*]b where b is Element of the carrier of Q: b in Y}, Q)
       where a is Element of the carrier of Q: a in X}, Q) by Def6 .=
    \/({c[*]d where c is Element of the carrier of Q,
                  d is Element of the carrier of Q: c in X & d in Y}, Q)
       from LUBFraenkelDistr;
  end;

This proof is about a more abstract kind of mathematics than the example from the previous chapter. Mizar is especially good at formalizing abstract mathematics.

7.1 Set comprehension: the Fränkel operator

The proof of theorem Th5 from QUANTAL1.MIZ contains expressions like:

{ a[*]b where b is Element of the carrier of Q: a in X & b in Y }

This corresponds to:

{a ∗ b : a ∈ X ∧ b ∈ Y }

where a is a fixed parameter and b is allowed to range over the elements of the carrier of Q.

In Mizar this style of set comprehension is called the Fränkel operator. It corresponds to the axiom of replacement in set theory, which was first proposed by Fränkel, the F in ZF.

The general form of the Fränkel operator is:

{ term where declaration of the variables: formula }

As you can see in some of the other Fränkel operator terms in the proof, if all variables in the term occur in a reserve statement their declarations can be left implicit.

To be allowed to write a Fränkel operator, the types of the variables involved need to widen to a Mizar type that has the form Element of A. Only then can Mizar know that the defined set is really a set. Because else you could write proper classes like:

{ X where X is set: not X in X }

But in Mizar this expression is illegal because set doesn’t widen to a type of

the form Element of.

Exercise 7.1.1 Write in Mizar syntax the statement that the set of prime numbers is infinite. Prove it.

7.2 Beyond first order: schemes

The proof of theorem Th5 from QUANTAL1.MIZ uses the from justification.

Mizar is based on first order predicate logic. However first order logic is slightly too weak to do ZF-style set theory. With first order logic ZF-style set theory needs infinitely many axioms. That’s because ZF set theory contains an axiom scheme, the axiom of replacement.

Here is a table that shows how scheme and from is similar to theorem and

by:

order  item  used

                    first order  theorem   by

higher order scheme   from

Schemes are higher order but only in a very weak sense. It has been said that Mizar schemes are not second order but 1.001th order.

Let’s study the second from in the proof. It justifies an equality:

\/({\/({a[*]b where b is Element of the carrier of Q: b in Y}, Q)
   where a is Element of the carrier of Q: a in X}, Q) =
\/({c[*]d where c is Element of the carrier of Q,
              d is Element of the carrier of Q: c in X & d in Y}, Q)
   from LUBFraenkelDistr;

The scheme that is used is:

scheme LUBFraenkelDistr
    {Q() -> complete Lattice-like (non empty QuantaleStr),
     f(set, set) -> Element of the carrier of Q(),
     X, Y() -> set}:
  \/({\/({f(a,b) where b is Element of the carrier of Q(): b in Y()},Q())
                 where a is Element of the carrier of Q(): a in X()}, Q()) =
  \/({f(a,b) where a is Element of the carrier of Q(),
                   b is Element of the carrier of Q(): a in X() & b in
 Y()}, Q());

Clearly the statement in this scheme looks very similar to the statement that is being justified.

When using a scheme you don’t give the parameters of the scheme. Mizar figures them out by matching the statement you’re justifying to the statement in the scheme. So when using a scheme you really have to make sure that the statement that you’re justifying and the statement in the scheme match exactly.

In this case matching the statement to the scheme leads to the following substitutions:

                        \begin{aligned}Q() & → & Q \\ f(x,y) & → & x[*]y \\ X() & → & X \\ Y() & → & Y \end{aligned}

Here the parameters Q(), X() and Y() are very simple, but they could have been arbitrarily complicated expressions.

In real higher order logic finding higher order parameters by matching expressions is very difficult. However in Mizar it’s easy because Mizar is first order (it has no β conversion so it doesn’t get the difficulty).

Maybe this example of a scheme is hard to relate to because you probably don’t know what it is about. Let’s look at the most commonly used scheme. It is the scheme called Ind from the article NAT_1. It is used to do induction over the natural numbers. This scheme is:

scheme Ind { P[Nat] } :
 for k being Nat holds P[k]
   provided
   P[0] and
   for k being Nat st P[k] holds P[k + 1];

So let’s show how to use this scheme to prove some statement about the natural nummbers. For example consider the non-negativity of the natural numbers:

for n being Nat holds n >= 0

If you match this statement to the statement that’s given by the scheme:

for k being Nat holds P[k]

then clearly they match with the substitution:

                         P[x] → x >= 0

Now this scheme has conditions, after the keyword provided. When using the scheme you have to give references to statements that correspond to these conditions. (This is slightly confusing: the arguments of the scheme are figured out automatically by Mizar, but the conditions of the scheme you have to give as arguments in the from.)

Applying the substitution that we already found to the conditions we get:

                                          P[0] → 0 >= 0
        for k being Nat st P[k] holds P[k + 1] →

                for k being Nat st k >= 0 holds k + 1 >= 0

So the from justification will be from Ind(A1,A2) in the following proof:

A1: 0 >= 0 by . . . ;
A2: for k being Nat st k >= 0 holds k + 1 >= 0
    proof
     let k be Nat;
     assume k >= 0;

…

     thus k + 1 >= 0;
    end;
    for n being Nat holds n >= 0 from Ind(A1,A2);

Of course you still will need to prove the two cases A1 and A2. Note that A1 is the base case of the induction and that A2 is the induction case.

Mizar has a feature that makes it easier for you to ensure that your statements will match the statements in the scheme. You can define macros with

deffunc and defpred. deffunc and defpred are similar to set but with pa-

rameters. Using defpred, the proof of the non-negativity of natural numbers looks like:

    defpred P[Nat] means $1 >= 0;
A1: P[0] by . . . ;
A2: for k being Nat st P[k] holds P[k + 1]
    proof
     let k be Nat;
     assume k >= 0;

…

     thus k + 1 >= 0;
    end;
    for n being Nat holds P[n] from Ind(A1,A2);

If you write your induction in this way it is harder to see what you need to prove but it is easier to see that you are matching the statements in the scheme.

Exercise 7.2.1 Write the natural deduction rules as Mizar schemes and prove them. For instance the rule of implication elimination (‘modus ponens’) becomes:

scheme implication_elimination { P[], Q[] } : Q[]
provided
A1: P[] implies Q[] and
A2: P[]
 by A1,A2;

Exercise 7.2.2 The axioms of the Mizar set theory are in the article called TARSKI. It’s called that way because it contains the axioms of a theory called Tarski-Grothendieck set theory, which is ZF set theory with an axiom about the existence of big cardinal numbers. The TARSKI article contains one scheme:

scheme Fraenkel { A()-> set, P[set, set] }:
 ex X st for x holds x in X iff ex y st y in A() & P[y,x]
 provided for x,y,z st P[x,y] & P[x,z] holds y = z;

Is it possible to prove this scheme using the Fränkel operator from the previous section (and without using other schemes from the MML)?

Conversely, is it possible to eliminate the use of the Fränkel operator from Mizar proofs by using the Fraenkel scheme?

7.3 Structures

The proof of theorem Th5 from QUANTAL1.MIZ uses the exciting type:

left-distributive right-distributive complete Lattice-like
    (non empty QuantaleStr)
In this type left-distributive, right-distributive, complete, Lattice-

like and empty are just attributes like before, but the mode QuantaleStr is something new.

The mode QuantaleStr is a structure. Structures are the records of Mizar. They contain fields that you can select using the construction:

the field of structure

For an example, the Th5 proof contains the expression:

the carrier of Q

In this the structure is Q and the field name is carrier. Many Mizar structures have the carrier field.

The definition of the QuantaleStr structure is:

struct (LattStr, HGrStr) QuantaleStr
   (# carrier -> set,
     L_join, L_meet, mult -> BinOp of the carrier #);

Apparently it has four fields: carrier, L_join, L_meet and mult.

The modes LattStr and HGrStr are called the ancestors of the structure. They are structures that have a subset of the fields of the structure that is defined. Any term that has type QuantaleStr will automatically also get the

types LattStr and HGrStr.

The definitions of the ancestors of QuantaleStr are:

struct(/\-SemiLattStr,\/-SemiLattStr) LattStr
  (# carrier -> set, L_join, L_meet -> BinOp of the carrier #);

and:

struct(1-sorted) HGrStr (# carrier -> set,
                          mult -> BinOp of the carrier #);

Structures are a powerful concept. They give the MML its abstract flavor.

Exercise 7.3.1 Find the definition of the mode Field in VECTSP_1. What is the structure it is based on? Recursively trace all ancestors of that structure. Draw a graph of the widening relation between those ancestors.

Exercise 7.3.2 The most basic structure in the MML is from STRUCT_0:

definition
 struct 1-sorted (# carrier -> set #);
end;

Is an object of type 1-sorted uniquely determined by its carrier? Why or why not? And what if it has type strict 1-sorted? (For a description of the attribute strict see Section 3.14.1.)

Exercise 7.3.3 You can construct an object of type 1-sorted as:

1-sorted (# A #)

Use this notation to define functors in and out that map objects of type set to their natural counterparts in 1-sorted and back. Prove in Mizar that out is a left inverse to in.

Exercise 7.3.4 Are structures ZF sets or not? More specifically: if Q is a structure, can there be an x with x in Q?

If not, why not?

If so, can you prove the following?

ex Q being 1-sorted, x being set st x in Q

If a structure has elements: is it uniquely determined by its elements?

Exercise 7.3.5 Because of Gödel’s theorems we know that Mizar’s set theory is incomplete. That is, there has to be a Mizar formula ϕ without free variables, for which no Mizar proof exists of ϕ, and also no Mizar proof exists of not ϕ.

Can you think of a non-Gödelian ϕ that is provable nor disprovable in Mizar?

86 CHAPTER 7. SOME ADVANCED FEATURES

Appendix A

Mizar grammar

???

88 APPENDIX A. MIZAR GRAMMAR

Appendix B

Mizar glossary

???

90 APPENDIX B. MIZAR GLOSSARY

Appendix C

Answers to exercises

Answer to exercise 6.6.3 The proof, put together, becomes:

theorem Th2:
a^2 + b^2 = c^2 & a,b are_relative_prime & a is odd implies
 ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2
proof
assume a^2 + b^2 = c^2;
assume a,b are_relative_prime;
assume a is odd;
b is even;
c is odd;
reconsider h = b/2 as Nat;
reconsider m2 = (c - a)/2 as Nat;
reconsider n2 = (c + a)/2 as Nat;
n2 - m2 = a;
n2 + m2 = c;
m2 · n2 = (c - a) · (c + a)/4
 .= (c^2 - a^2)/4
 .= b^2/4
 .= h^2;
m2 · n2 is square;
m2,n2 are_relative_prime;
m2 is square & n2 is square;
consider m such that m2 = m^2;
consider n such that n2 = n^2;
take m,n;
thus m <= n;
thus a = n^2 - m^2;
thus b = 2 · m · n;
thus c = n^2 + m^2;
end;

No update to the environment has been necessary to check this proof.

Every step in the proof that’s not an assume or take step gives a *4 error. The step m2 is square & n2 is square gives two *4 errors because it is a conjunction of two statements, and Mizar tries to justify the conjuncts separately.

So there are twenty-one *4 errors in the proof of Th2. Together with the two *4 errors for Th1 there are at this point twenty-three *4 errors in the article.

Answer to exercise 6.7.4 Here is a possible proof. The skeleton that was the solution to exercise 6.6.3 has been underlined. Apart from the four lemmas, three clusters are used that tell when a term of the shape n^2 is even, odd and square.

theorem Th2:
a^2 + b^2 = c^2 & a,b are relative prime & a is odd implies
 ex m,n st m <= n & a = n^2 - m^2 & b = 2 · m · n & c = n^2 + m^2
\underline{proof}
\underline{assume}
A1: \underline{a^2 + b^2 = c^2;}
\underline{assume}
A2: \underline{a,b are relative prime;}
assume a is odd;
then reconsider a' = a as odd Nat;
\underline{b is even}
proof
 assume b is odd;
 then reconsider b' = b as odd Nat;
 a'^2 is odd square & b'^2 is odd square;
 hence contradiction by A1,Lm1;
end\underline{;}
then reconsider b' = b as even Nat;
\underline{c is odd}
proof
 assume c is even;
 then reconsider c' = c as even Nat;
 a'^2 + b'^2 is odd & c'^2 is even;
 hence contradiction by A1;
end\underline{;}
then reconsider c' = c as odd Nat;
\underline{reconsider h = b}'\underline{/2 as Nat} by Lm2\underline{;}
b^2 >= 0 by NAT_1:18;
then a^2 + b^2 >= a^2 + 0 by AXIOMS:24;
then c^2 >= a^2 & c >= 0 by A1,NAT_1:18;
then c >= a by SQUARE_1:78;
then c - a >= 0 by REAL_2:106;
then c - a is Nat by INT_1:16;
then \underline{reconsider m2 = (c}' \underline{- a}'\underline{)/2 as Nat} by Lm2\underline{;}

\underline{reconsider n2 = (c}' \underline{+ a}'\underline{)/2 as Nat} by Lm2\underline{;}
A3: \underline{n2 - m2 =} ((c + a) - (c - a))/2 by REAL_1:40
.= (c + a - c + a)/2 by REAL_1:28
.= (a + a)/2 by REAL_2:17
.= \underline{a} by SQUARE_1:15\underline{;}
A4: \underline{n2 + m2 =} ((c + a) + (c - a))/2 by REAL_1:40
.= (c + a + c - a)/2 by REAL_2:18
.= (c + c + a - a)/2 by AXIOMS:13
.= (c + c)/2 by REAL_2:17
.= \underline{c} by SQUARE_1:15\underline{;}
\underline{m2 · n2 =} (c - a) · (c + a)/(2 · 2) by REAL_1:35
.= \underline{(c - a) · (c + a)/4}
\underline{.= (c^2 - a^2)/4} by SQUARE_1:67
\underline{.= b^2/4} by A1,REAL_2:17
.= b^2/(2 · 2)
.= b^2/2^2 by SQUARE_1:def 3
\underline{.= h^2} by SQUARE_1:69;
then
A5: \underline{m2 · n2 is square;}
now
let p be prime Nat;
assume
A6: p | m2 & p | n2;
then p | (m2 qua Integer) & p | (n2 qua Integer) by SCPINVAR:2;
then p | (n2 qua Integer) & p | -m2 by INT_2:14;
then p | (n2 + -m2) by WSIERP_1:9;
then p | (a qua Integer) by A3,REAL_1:def 3;
then
A7: p | a by SCPINVAR:2;
A8: p | c by A4,A6,NAT_1:55;
A9: b · b = b^2 by SQUARE_1:def 3
 .= c^2 - a^2 by A1,REAL_2:17
 .= c · c - a^2 by SQUARE_1:def 3
 .= c · c - a · a by SQUARE_1:def 3
 .= c · c + -(a · a) by REAL_1:def 3;
p | c · c & p | a · a by A7,A8,NAT_1:56;
then p | (c · c qua Integer) & p | (a · a qua Integer) by SCPINVAR:2;
then p | (c · c qua Integer) & p | -(a · a) by INT_2:14;
then p | (b · b qua Integer) by A9,WSIERP_1:9;
then p | b · b by SCPINVAR:2;
then p | b by NAT_LAT:95;
hence contradiction by A2,A7,Lm3;
end;
then \underline{m2,n2 are relative prime} by Lm3\underline{;}
then
A10: \underline{m2 is square & n2 is square} by A5,Th1\underline{;}

consider m such that
A11: \underline{m2 = m^2} by A10,Def1\underline{;}
consider n such that
A12: \underline{n2 = n^2} by A10,Def1\underline{;}
\underline{take m,n;}
a >= 0 by NAT_1:18;
then c - a <= c & c + a >= c by REAL_2:173;
then c - a <= c + a by AXIOMS:22;
then m^2 <= n^2 & n >= 0 by A11,A12,REAL_1:73,NAT_1:18;
\underline{hence m <= n} by SQUARE_1:78\underline{;}
\underline{thus a = n^2 - m^2} by A3,A11,A12\underline{;}
b^2 = c^2 - a^2 by A1,REAL_2:17
 .= (c - a) · (c + a) by SQUARE_1:67
 .= (2 · ((c - a)/2)) · (c + a) by REAL_2:62
 .= (2 · ((c - a)/2)) · (2 · ((c + a)/2)) by REAL_2:62
 .= 2 · m2 · 2 · n2 by AXIOMS:16
 .= 2 · 2 · m2 · n2 by AXIOMS:16
 .= 2^2 · m^2 · n^2 by A11,A12,SQUARE_1:def 3
 .= (2 · m)^2 · n^2 by SQUARE_1:68
 .= (2 · m · n)^2 by SQUARE_1:68;
\underline{hence b = 2 · m · n} by Lm4\underline{;}
\underline{thus c = n^2 + m^2} by A4,A11,A12\underline{;}
\underline{end;}