-
Notifications
You must be signed in to change notification settings - Fork 0
/
symmetry.thy
68 lines (55 loc) · 1.98 KB
/
symmetry.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
theory symmetry
imports Main
begin
datatype 'a palindrome = Nil | Merge "'a palindrome" "'a palindrome"
fun left :: "'a palindrome ⇒ 'a palindrome" where
"left Nil = Nil" |
"left (Merge l r) = l"
fun right :: "'a palindrome ⇒ 'a palindrome" where
"right Nil = Nil" |
"right (Merge l r) = r"
fun reversed :: "'a palindrome ⇒ 'a palindrome" where
"reversed Nil = Nil" |
"reversed (Merge l r) = Merge (reversed r) (reversed l)"
fun connect :: "'a palindrome ⇒ 'a palindrome ⇒ 'a palindrome" where
"connect Nil nw = Nil" |
"connect (Merge l r) m = Merge (Merge l m) (Merge (reversed m) (reversed l))"
lemma double_reverse: "reversed (reversed a) = a"
apply (induct_tac a)
apply (auto)
done
lemma reversed_commutativity:
assumes "reversed a = b"
shows "reversed b = a"
proof (cases "a")
case (Merge l r)
then have "b = Merge (reversed r) (reversed l)" using assms by simp
then have "reversed b = Merge (reversed (reversed l)) (reversed (reversed r))" by auto
then have "reversed b = Merge l r" using double_reverse by auto
thus ?thesis using Merge by auto
next
case Nil
then have "reversed a = Nil" by auto
then have "b = Nil" using assms by auto
then have "reversed b = Nil" by auto
thus ?thesis using local.Nil by simp
qed
theorem recurrence_is_symmetric:
fixes a b
assumes "p = connect a b"
shows "reversed (right p) = left p"
proof (cases "a")
case (Merge l r)
from assms have "p = connect a b" by auto
then have "p = Merge (Merge l b) (Merge (reversed b) (reversed l))" by (simp add: Merge)
also have "reversed (Merge l b) = Merge (reversed b) (reversed l)" by auto
then have "reversed (left p) = right p" by (simp add: calculation)
then have "reversed (right p) = left p" using reversed_commutativity by auto
thus ?thesis by auto
next
case Nil
then have "p = Nil" using assms by auto
then have "left p = Nil" and "right p = Nil" and "reversed (right p) = Nil" by auto
thus ?thesis by auto
qed
end