and_exampletheoremProved here from basic factsNo axioms
and_exampleLean 4Proved here from basic factsFormally verified
/-- "12 is even **and** 12 is bigger than 20" is false, because its second part is false."12 is even **and** 12 is smaller than 20" is true, because both parts are true. -/theorem and_example : ¬ (12 % 2 = 0 ∧ 12 > 20) ∧ (12 % 2 = 0 ∧ 12 < 20) := by decide
or_exampletheoremProved here from basic factsNo axioms
or_exampleLean 4Proved here from basic factsFormally verified
/-- "Or" is inclusive. "6 is even **or** 6 is a multiple of 3" is true — and both of its partsare true. "7 is even or 7 is bigger than 10" is false, because neither part is true. -/theorem or_example : (6 % 2 = 0 ∨ 6 % 3 = 0) ∧ ¬ (7 % 2 = 0 ∨ 7 > 10) := by decide
and_tabletheoremProved here from basic factsNo axioms
and_tableLean 4Proved here from basic factsFormally verified
/-- The whole truth table of **and**: `p && q` is true in just one row, the row where both aretrue. -/theorem and_table : (true && true) = true ∧ (true && false) = false ∧ (false && true) = false ∧ (false && false) = false := by decide
or_tabletheoremProved here from basic factsNo axioms
or_tableLean 4Proved here from basic factsFormally verified
/-- The whole truth table of **or**: `p || q` is false in just one row, the row where both arefalse. In the first row both parts are true, and so is `p || q`: this "or" is inclusive. -/theorem or_table : (true || true) = true ∧ (true || false) = true ∧ (false || true) = true ∧ (false || false) = false := by decide
not_nottheoremProved here from basic factsNo axioms
not_notLean 4Proved here from basic factsFormally verified
/-- "Not not p" is the same as `p`: swapping true and false twice changes nothing. Two rows tocheck. -/theorem not_not (p : Bool) : (!!p) = p := by cases p <;> rfl
de_morgan_andtheoremProved here from basic factsNo axioms
de_morgan_andLean 4Proved here from basic factsFormally verified
/-- **De Morgan's law for "and".** "Not (p and q)" has the same truth value as"(not p) or (not q)" in every row. There are only four rows (`cases p <;> cases q`), sochecking all of them is a complete proof. -/theorem de_morgan_and (p q : Bool) : (!(p && q)) = (!p || !q) := by cases p <;> cases q <;> rfl
de_morgan_ortheoremProved here from basic factsNo axioms
de_morgan_orLean 4Proved here from basic factsFormally verified
/-- **De Morgan's law for "or".** "Not (p or q)" has the same truth value as"(not p) and (not q)" in all four rows. -/theorem de_morgan_or (p q : Bool) : (!(p || q)) = (!p && !q) := by cases p <;> cases q <;> rfl
not_or_ifftheoremProved here from basic factsNo axioms
not_or_iffLean 4Proved here from basic factsFormally verified
/-- The same law for statements (`Prop`), proved by reasoning instead of a table. If neither`P` nor `Q` may hold, then `P` fails and `Q` fails; and if both fail, "P or Q" cannot hold. -/theorem not_or_iff (P Q : Prop) : ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q := ⟨fun h => ⟨fun hp => h (Or.inl hp), fun hq => h (Or.inr hq)⟩, fun ⟨hnp, hnq⟩ h => h.elim hnp hnq⟩
ending_in_two_examplestheoremProved here from basic factsNo axioms
ending_in_two_examplesLean 4Proved here from basic factsFormally verified
/-- Five confirming examples: 12, 32, 52, 72 and 92 all end in 2, and all of them are divisibleby 4. -/theorem ending_in_two_examples : ∀ n ∈ [12, 32, 52, 72, 92], n % 10 = 2 ∧ n % 4 = 0 := by decide
ending_in_two_counterexampletheoremProved here from basic factsNo axioms
ending_in_two_counterexampleLean 4Proved here from basic factsFormally verified
/-- …and yet "every number that ends in 2 is divisible by 4" is **false**. One counterexampleis enough: 22 ends in 2, but 22 = 4 × 5 + 2 leaves a remainder. -/theorem ending_in_two_counterexample : ¬ ∀ n : Nat, n % 10 = 2 → n % 4 = 0 := fun h => absurd (h 22 rfl) (by decide)
odd_not_always_primetheoremProved here from basic factspropext, Quot.sound
odd_not_always_primeLean 4Proved here from basic factsFormally verified
/-- "Every odd number bigger than 1 is prime" (has no factors except 1 and itself) is false:3, 5 and 7 fit, but 9 is odd and has the factor 3. -/theorem odd_not_always_prime : ¬ ∀ n : Nat, n > 1 → n % 2 = 1 → ∀ d, d ∣ n → d = 1 ∨ d = n := by intro h have h3 := h 9 (by decide) (by decide) 3 ⟨3, rfl⟩ omega
even_prime_existstheoremProved here from basic factspropext, Quot.sound
even_prime_existsLean 4Proved here from basic factsFormally verified
/-- A "some" statement needs just one example. "Some number is even and has no factors except 1and itself" is true: 2 is such a number. -/theorem even_prime_exists : ∃ n : Nat, n % 2 = 0 ∧ n > 1 ∧ ∀ d, d ∣ n → d = 1 ∨ d = n := by refine ⟨2, rfl, by decide, fun d hd => ?_⟩ have hle : d ≤ 2 := Nat.le_of_dvd (by decide) hd have hpos : 0 < d := Nat.pos_of_dvd_of_pos hd (by decide) omega
double_checked_to_100theoremProved here from basic factsNo axioms
double_checked_to_100Lean 4Proved here from basic factsFormally verified
/-- Checking 100 cases: for each of the numbers 0, 1, …, 99, the double is even. Lean checksthe cases one by one. This says nothing yet about 100, or 1000. -/theorem double_checked_to_100 : ∀ n, n < 100 → (2 * n) % 2 = 0 := by decide
double_is_eventheoremApplies a library theorempropext
double_is_evenLean 4Applies a library theoremFormally verified
/-- Proving every case at once: for **every** whole number `n`, `2 × n` is even, because`2 × n` is `n` groups of 2 with nothing left over. This applies core Lean's`Nat.mul_mod_right`. -/theorem double_is_even (n : Nat) : (2 * n) % 2 = 0 := Nat.mul_mod_right 2 n
not_all_iff_exists_nottheoremProved here from basic factspropext, Quot.sound
not_all_iff_exists_notLean 4Proved here from basic factsFormally verified
/-- **The opposite of "all pass" is "at least one fails"** — not "none pass". For any list ofthings and any yes-or-no test `p`: it is *not* true that every item passes exactly when someitem fails. Proved for every list, by working through the list one item at a time. -/theorem not_all_iff_exists_not {α : Type} (items : List α) (p : α → Bool) : ¬ (∀ x ∈ items, p x = true) ↔ ∃ x ∈ items, p x = false := by induction items with | nil => simp | cons a as ih => cases h : p a <;> simp [h, ih]
not_all_ripetheoremProved here from basic factspropext
not_all_ripeLean 4Proved here from basic factsFormally verified
/-- A basket of four mangoes, ripe or not. "All the mangoes are ripe" is false, but "none of themangoes is ripe" is false too: the opposite of "all" is "at least one is not". -/theorem not_all_ripe : ¬ (∀ ripe ∈ [true, true, false, true], ripe = true) ∧ ¬ (∀ ripe ∈ [true, true, false, true], ripe = false) ∧ (∃ ripe ∈ [true, true, false, true], ripe = false) := by decide
/-- Show that "6 is even or 6 is a multiple of 3" is true, and that "7 is even or 7 is biggerthan 10" is false.Hint: these are statements about small numbers, so Lean can calculate: try `decide`. -/theorem or_example : (6 % 2 = 0 ∨ 6 % 3 = 0) ∧ ¬ (7 % 2 = 0 ∨ 7 > 10) := by sorry
Show the compiled solution
or_exampleLean 4Proved here from basic factsFormally verified
/-- "Or" is inclusive. "6 is even **or** 6 is a multiple of 3" is true — and both of its partsare true. "7 is even or 7 is bigger than 10" is false, because neither part is true. -/theorem or_example : (6 % 2 = 0 ∨ 6 % 3 = 0) ∧ ¬ (7 % 2 = 0 ∨ 7 > 10) := by decide
/-- Prove De Morgan's law for "or" by checking every row of the truth table.Hint: `cases p <;> cases q <;> rfl` splits into the four rows and checks each one. -/theorem de_morgan_or (p q : Bool) : (!(p || q)) = (!p && !q) := by sorry
Show the compiled solution
de_morgan_orLean 4Proved here from basic factsFormally verified
/-- **De Morgan's law for "or".** "Not (p or q)" has the same truth value as"(not p) and (not q)" in all four rows. -/theorem de_morgan_or (p q : Bool) : (!(p || q)) = (!p && !q) := by cases p <;> cases q <;> rfl
/-- Show that not every number ending in 2 is divisible by 4.Hint: start with `intro h`. Then `h 22 rfl` says that `22 % 4 = 0`. Is that true? -/theorem ending_in_two_counterexample : ¬ ∀ n : Nat, n % 10 = 2 → n % 4 = 0 := by sorry
Show the compiled solution
ending_in_two_counterexampleLean 4Proved here from basic factsFormally verified
/-- …and yet "every number that ends in 2 is divisible by 4" is **false**. One counterexampleis enough: 22 ends in 2, but 22 = 4 × 5 + 2 leaves a remainder. -/theorem ending_in_two_counterexample : ¬ ∀ n : Nat, n % 10 = 2 → n % 4 = 0 := fun h => absurd (h 22 rfl) (by decide)