fermat,logic - duke universityfermat,logic compsci230—discretemath february16,2017...

20
Fermat, Logic COMPSCI 230 — Discrete Math February 16, 2017 COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 1 / 20

Upload: others

Post on 13-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Fermat, Logic

COMPSCI 230 — Discrete Math

February 16, 2017

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 1 / 20

Page 2: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Outline

1 Proof of Fermat’s Little Theorem

2 Why Logic

3 Propositional Logic

4 Predicate Logic

5 The Dream of Automated Reasoning

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 2 / 20

Page 3: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Proof of Fermat’s Little Theorem

Very Creative Counting• Sometimes it takes creativityto even see a counting argument as an option

• Fermat’s little theorem (we saw that for RSA):

0 < 𝑛 ∈ 𝐍, 𝑝 prime ⇒ 𝑛𝑝−1 𝑝= 1

• Example: 𝑛 = 2, 𝑝 = 5 ⇒ 24 5= 1 ⇒ 16 5= 1• How to prove it?• What do we count here?• A proof of a result basedon counting is called acombinatorial proof

Solomon Golomb, 1932—

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 3 / 20

Page 4: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Proof of Fermat’s Little Theorem

Fermat’s Little Theorem• 0 < 𝑛 ∈ 𝐍, 𝑝 prime ⇒ 𝑛𝑝−1 𝑝= 1• Combinatorial proof (1956) due to Solomon Golomb• Rephrase as 𝑛𝑝 𝑝= 𝑛, so 𝑛𝑝 − 𝑛 𝑝= 0That is, 𝑝 divides 𝑛𝑝 − 𝑛, i.e., (𝑛𝑝 − 𝑛)/𝑝 is an integer

beads in 𝑛 colors bracelet with 𝑝 beads

• How many different multicolored bracelets with 𝑝 beads?• Turns out to be (𝑛𝑝 − 𝑛)/𝑝, which must therefore be an integer

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 4 / 20

Page 5: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Proof of Fermat’s Little Theorem

Counting Bracelets

• Given beads in 𝑛 colors and a prime number 𝑝there are (𝑛𝑝 − 𝑛)/𝑝 different multicolored braceletswith 𝑝 beads [multicolored: at least two colors]

• First put 𝑝 beads on a string (color repetitions OK)• 𝑛 choices for first color, 𝑛 for second, …, 𝑛 for 𝑝-th• 𝑝-sequence out of an 𝑛-set: 𝑛𝑝 bead choices• 𝑛 of those are monochrome• 𝑛𝑝 − 𝑛 remain

• Any problems with this count?

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 5 / 20

Page 6: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Proof of Fermat’s Little Theorem

Counting Bracelets

• We obtained 𝑛𝑝 − 𝑛 strings• We over-counted:

• Join the two ends of each string• Bracelets that differ by a cyclic permutation areindistinguishable

• If 𝑝 is prime, there are 𝑝 distinct cyclic permutationsfor each string

• [A non-prime 𝑝 may lead to sub-periods]

• Correct count: (𝑛𝑝 − 𝑛)/𝑝• Therefore, 𝑝 divides 𝑛𝑝 − 𝑛, so 𝑛𝑝 𝑝= 𝑛 or 𝑛𝑝−1 𝑝= 1• Fermat’s little theorem, crucial for provingcorrectness of RSA

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 6 / 20

Page 7: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Why Logic

Why Logic

Clean Thinking: Formalizing an argument helpsdiscovering possible flaws in it, or convincingus and others of its validity

Automatic Reasoning: A formal system can beimplemented as software on a computer, sothere is hope of building machines that reason

Human Cognition: If we believe that our brains aremachines, understanding logic may lead tounderstanding human thought

We will look at the first aspect most closely

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 7 / 20

Page 8: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Why Logic

Logical Fallacies

• If educational standards are lowered, the quality of argumentsseen on the Internet worsens. So if we see the level of debate onthe Internet degrade over the next few years, we’ll know thatour educational standards are still falling

𝑝 → 𝑞 ⇏ 𝑞 → 𝑝The fact that 𝑞 follows from 𝑝 does not implythat 𝑝 follows from 𝑞We could logically infer that if the level of debate onthe Internet improves over the next years, then we’llknow that our educational standards are rising𝑝 → 𝑞 ⇒ ∼𝑞 → ∼𝑝

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 8 / 20

Page 9: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Propositional Logic

Propositional Logic• A proposition is a statement to which it makes senseto assign a truth value“Stop giggling!” is not a proposition𝑝: “Martians are green”We may not know the truth value of 𝑝, but 𝑝 hassome truth value

• Propositional logic (PL) treats propositions as atomicNo internal structure: 𝑝 is 𝑝. It is a literalA formula combines propositions and connectives(not, and, or, if … then …)

• PL combines some given formulas taken to be true(axioms) to create new true formulas through a smallnumber of inference rules

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 9 / 20

Page 10: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Propositional Logic

Inference in Logic: An Example

• Modus Ponens:𝑝 → 𝑞𝑝𝑞

If 𝑝 then 𝑞 is true and 𝑝 is true, then 𝑞 is true• Suppose we know that 𝑝 and 𝑝 → 𝑞 are true, but wedo not know the truth value of 𝑞

• Modus ponens lets us infer (the truth of) 𝑞• 𝑝: It is raining (𝚃)• 𝑞: The streets are wet (?)• 𝑝 → 𝑞: If it is raining, the streets are wet (𝚃)• We cannot look out the window onto the street, butwe do see the sky (𝑝), and we understand what raindoes to streets (𝑝 → 𝑞)

• Modus ponens lets us infer that the streets are wetCOMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 10 / 20

Page 11: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Propositional Logic

Inference is Agnostic to Semantics

• Inference: Set knowledge base = axioms, thenrepeatedly do pattern matching with the inferencerules to add new statements to the knowledge base

• The whole point of inference is that it does not careabout semanticsModus ponens is valid regardless of what 𝑝, 𝑞 mean

• Valid: if you apply the rule, you will never addstatements that contradict the ones you already haveYou keep the growing knowledge base consistent

• You will read a proof of the validity of modus ponens(and several other inference rules) in FDM

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 11 / 20

Page 12: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Predicate Logic

Propositional Logic Has Limited Expressiveness

• Simple propositions are atomic• 𝑝: Martians are green• 𝑞: Agyr is Martian• 𝑝, 𝑞 are distinct symbols in propositional logic, butthey are connected in our minds

• Cannot infer that Agyr is green: Symbols don’t“know” about being Martian or being green

• No way to express relationships between objects(Agyr) and their properties (being green or Martian)

• Predicate logic addresses this limitation bydescribing relationships

• Predicate logic subsumes propositional logic

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 12 / 20

Page 13: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

Predicate Logic

Predicate Logic• Terms are basic objects: Agyr, Bob, 3, my house, ...• Variables are placeholders for objects: 𝑥, 𝑦, ...• Predicates are propositions that contain variables:

𝑃(𝑥): “𝑥 is a Martian” 𝑄(𝑦, 𝑧): “𝑦 is 𝑧’s child”• Predicates do not have truth values, but take on truth valueswhen• All variables are replaced by terms:

𝑃(Agyr): “Agyr is a Martian”(same as bound identifiers in Python)

• ... or all variables are quantified:∀𝑦 ∃𝑧 𝑄(𝑦, 𝑧) : “Everyone is someone’s child”

• Predicates describe objects, their properties (𝑃(𝑥)), and theirrelationships (𝑄(𝑦, 𝑧))

• Formulas are predicates combined with connectives• Inference is more complex in predicate logic

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 13 / 20

Page 14: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

The Dream of Automated Reasoning

Automated Reasoning? A Great Start• In his Elements (3rd century B.C.), Euclid formalizedall of known geometry at the time

• Five axioms, statements assumed to be true[E.g.: There is exactly one line between any twodistinct points]Everything else derived through five constructionrules[E.g.: Given a segment 𝐴𝐵, how to make a segment𝐶𝐷 of equal length]

• Euclidean geometry has a denumerable number ofstatements:Apply all rules in a fixed order to every inferredstatement, starting with the axiomsCould write a Python generator for all of geometry

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 14 / 20

Page 15: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

The Dream of Automated Reasoning

Euclid’s Elements• Everything inferred from 5 axioms and 5 construction rules• Concise premises, simple construction rules• All you need to believe is the truth of the premises and thevalidity of the rules

• Validity: a valid rule applied to true premises always yields atrue statement

• Simplicity of premises and rules is the whole pointThey capture everything you need to believeThe rest is machinery

Euclid, circa 300 B. C.

britannica.com

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 15 / 20

Page 16: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

The Dream of Automated Reasoning

Automated Reasoning? Not so Fast!

• Problem 1: The Python generator would alsogenerate a huge number of uninteresting statements[E.g.: There is exactly one line between any threedistinct points that are on the same line]

• Problem 2: We often want to go backwards: Startfrom a statement and either prove it or disprove it

• There are deep problems in doing so• It took Euclid’s genius to figure out which step toapply to which premises in what order

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 16 / 20

Page 17: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

The Dream of Automated Reasoning

All 13 Books of the Elements

http://www.maa.org

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 17 / 20

Page 18: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

The Dream of Automated Reasoning

Properties of an Inference System• Sound: Every formula that can be proven from agiven set of axioms is true if the axioms are true.That is, all inference rules are valid.

• Complete: Every formula that the axioms imply canbe proven through the given inference rules.That is, for any formula implied by the axioms thereexists a finite chain of inference rules that prove it.

• Decidable: An algorithm exists that determines thetruth value of any formula (implied or not) given aset of axioms.That is, a finite recipe exists to find a chain ofinference rules that prove or disprove any formula.

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 18 / 20

Page 19: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

The Dream of Automated Reasoning

Automated Reasoning: Good NewsBertrand Russell, 1872-1970

The Times Higher Education

• A valiant attempt: Whitehead andRussell attempted to formalizeall of mathematics in their bookPrincipia Mathematica (1910-13)

• Propositional logic was found tobe sound, complete, anddecidable (not too hard)

• Predicate logic was found to be sound, complete, butnot decidable (hard! Kurt Gödel, 1930,semi-decidability)

• Alan Robinson invented resolution theorem proving(1965), an inference system for predicate logic with asingle inference rule!

• Underlies the Prolog logical programming language[Read the optional parts of the notes if interested]

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 19 / 20

Page 20: Fermat,Logic - Duke UniversityFermat,Logic COMPSCI230—DiscreteMath February16,2017 COMPSCI230—DiscreteMath Fermat,Logic February16,2017 1/20

The Dream of Automated Reasoning

Automated Reasoning: Bad News• Predicate logic is not expressive enough to talk about naturalnumbers

• It can be extended with an induction schema to make itpowerful enough to do so

• Any sound predicate logic extended with an induction schema isincompleteThat is, it is always possible to build formulas that are implied bythe axioms but cannot be proven from them within the givenformal systemFamous Gödel’s Proof, 1931Uses diagonalization!Very readable short book by ErnestNagel and James Newman, 1958

• Does this mean that thinkingcannot be mechanized?

• Redefine “thinking?”

Kurt Gödel, 1906-1978

Life Magazine

COMPSCI 230 — Discrete Math Fermat, Logic February 16, 2017 20 / 20