• No results found

Sets of numbers

In document Reference Manual Visual Prolog 7.1 (Page 99-102)

Console Applications

Chapter 9 Data types

9.3 Sets of numbers

Mathematicians collect other things, besides coins, stamps, and slide rules.

They collect numbers, for instance; therefore you are supposed to learn a lot about sets of numbers.

N is the set of natural integers. Here is how mathematicians write the elements of N: {0, 1, 2, 3, 4 . . .}.

Z is the set of integers, i.e., Z = {. . . − 3, −2, −1, 0, 1, 2, 3, 4 . . .}.

Why is the set of integers represented by the letter Z? I do not know, but I can make an educated guess. The set theory was discovered by Georg Ferdinand Ludwig Philipp Cantor, a Russian whose parents were Danish, but who wrote his Mengenlehre in German! In this language, integers may have some strange name like Zahlen.

You may think that set theory is boring; however, many people think that it is quite interesting. For instance, there is an Argentinean that scholars con-sider to be the greatest writer that lived after the fall of Greek civilization. In few words, only the Greeks could put forward a better author. You probably heard Chileans saying that Argentineans are somewhat conceited. You know what is the best possible deal? It is to pay a fair price for Argentineans, and resell them at what they think is their worth. However, notwithstanding the opinion of the Chileans, Jorge Luiz Borges is the greatest writer who wrote in a language different from Greek. Do you know what was his favorite subject?

It was the Set Theory, or Der Mengenlehre, as he liked to call it.

Please, my Argentinian friends, no hard feelings. After all, your coun-try ranks fourth in my list of favorite countries, after Greece, France, and Paraguay. The high position of Paraguay in my list is solely due to the fact that Jos´e Asunci´on Flores was Paraguayan; for those who do not know Jos´e

Asunci´on Flores, listen to his song India, and I am sure that you will put Paraguay in your map. As for Argentina, it is the fatherland of Bernardo Houssay, Luis Federico Leloir, C´esar Milstein, Adolfo P´erez Esquivel, Carlos Saavedra Lamas, Jorge Luiz Borges, Alberto Calderon, Alberto Ginastera, Jos´e Cura, Dario Volont´e, Ver´onica Dahl, Carolina Monard, Che Guevara, Diego Maradona, Juan Manuel Fangio, Osvaldo Golijov, Eva Peron, Hector Panizza, Jos´e Cura etc. Before I forget, Jos´e Asunci´on Flores lived in Buenos Aires. But let us return to sets.

When a mathematician wants to say that an element is a member of a set, he writes something like

3 ∈ Z

If he wants to say that something is not an element of a set, for instance, if he wants to state that −3 is not an element of N, he writes:

−3 6∈ N

Let us summarize the notation that Algebra teachers use, when they explain set theory to their students.

Double backslash. The weird notation {x2||x ∈ N} represents the set of x2, such that x is a member of N, or else, {0, 1, 4, 9, 16, 25 . . .}

Guard. If you want to say that x is a member of N on the condition that x > 10, you can write {x||x ∈ N ∧ x > 10}.

Conjunction. In Mathematics, you can use a symbol ∧ to sayand; therefore x > 2 ∧ x < 5 means that x > 2and x < 5.

Disjunction. The expression

(x < 2) ∨ (x > 5) means x < 2 or x > 5.

Using the above notation, you can define the set of rational numbers:

Q = {p

q||p ∈ Z ∧ q ∈ N ∧ q 6= 0}

In informal English, this expression means that a rational number is a fraction p

q

such that p is a member of Z and q is also a member of N, submitted to the condition that q is not equal to 0.

9.3 Sets of numbers 99 Visual Prolog does not have a notation for sets, but you can use lists to represent sets. For instance, choose the option Project/New from the task menu, and fill the Project Settings dialog thus:

General

Project Name: zermelo UI Strategy: console

Pay attention that we are going to use the console strategy, not GUI. Choose the option Build/Build from the task menu to put a prototype of class zermelo into the project tree. Edit zermelo.pro as shown below. Build the project again, and execute it using Build/Run in Window.

implement main

foreach tuple(Num, Den)= list::getMember_nd(Q) do stdio::write(Num, "/", Den,", ")

end foreach, stdio::nl.

end implement main goal

mainExe::run(main::run).

You may wonder why I named the above program after the German mathematician Ernst Friedrich Ferdinand Zermelo. One reason could be that he was appointed to an honorary chair at Freiburg im Breisgau in 1926, which he resigned in 1935 because he disapproved of Hitler’s regime. Another reason was that he invented the notation for set that we have been using.

Q= [tuple(X, Y) || X= std::fromTo(1, 4), Y= std::fromTo(1, 5)],

In Zermelo’s notation, this expression is written thus:

Q = {(X, Y )||X ∈ [1 . . . 4] ∧ Y ∈ [1 . . . 5]}

In plain English, Q is a list of pairs (X, Y ) such that X belongs to [1, 2, 3, 4], and Y belongs to [1, 2, 3, 4, 5]. The snippet

foreach tuple(Num, Den)= list::getMember_nd(Q) do stdio::write(Num, "/", Den,", ")

end foreach

tells the computer to write(Num, "/", Den,", ") for each tuple (Num, Den) that is member of the list Q.

The set of rational numbers is so named because its elements can be represented as a fraction like

p q where p ∈ N and p ∈ N.

The next section is somewhat hard to digest. Therefore, if you want to skip it, feel free to do so. In the section about Real Numbers, I will summarize the important results, so you wont’t miss anything worth the effort of understanding a whole page of nasty mathematics.

In document Reference Manual Visual Prolog 7.1 (Page 99-102)