-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPruebas_de_length_(repeat_x_n)_Ig_n.thy
76 lines (65 loc) · 1.94 KB
/
Pruebas_de_length_(repeat_x_n)_Ig_n.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(* Pruebas_de_length_(repeat_x_n)_Ig_n.thy
-- Pruebas de length (replicate n x) = n
-- José A. Alonso Jiménez <https://jaalonso.github.io>
-- Sevilla, 29-julio-2024
-- ------------------------------------------------------------------ *)
(* ---------------------------------------------------------------------
-- En Lean están definidas length y replicate tales que
-- + (length xs) es la longitud de la lista xs. Por ejemplo,
-- length [1,2,5,2] = 4
-- + (replicate n n) es la lista que tiene el elemento x n veces. Por
-- ejemplo,
-- replicate 3 7 = [7, 7, 7]
--
-- Demostrar que
-- length (replicate n x) = n
-- ------------------------------------------------------------------ *)
theory "Pruebas_de_length_(repeat_x_n)_Ig_n"
imports Main
begin
(* 1\<ordfeminine> demostración⁾*)
lemma "length (replicate n x) = n"
proof (induct n)
have "length (replicate 0 x) = length ([] :: 'a list)"
by (simp only: replicate.simps(1))
also have "\<dots> = 0"
by (rule list.size(3))
finally show "length (replicate 0 x) = 0"
by this
next
fix n
assume HI : "length (replicate n x) = n"
have "length (replicate (Suc n) x) =
length (x # replicate n x)"
by (simp only: replicate.simps(2))
also have "\<dots> = length (replicate n x) + 1"
by (simp only: list.size(4))
also have "\<dots> = Suc n"
by (simp only: HI)
finally show "length (replicate (Suc n) x) = Suc n"
by this
qed
(* 2\<ordfeminine> demostración⁾*)
lemma "length (replicate n x) = n"
proof (induct n)
show "length (replicate 0 x) = 0"
by simp
next
fix n
assume "length (replicate n x) = n"
then show "length (replicate (Suc n) x) = Suc n"
by simp
qed
(* 3\<ordfeminine> demostración⁾*)
lemma "length (replicate n x) = n"
proof (induct n)
case 0
then show ?case by simp
next
case (Suc n)
then show ?case by simp
qed
(* 4\<ordfeminine> demostración⁾*)
lemma "length (replicate n x) = n"
by (rule length_replicate)
end