src/HOL/Lex/Prefix.ML
author paulson
Fri, 21 Apr 2000 11:28:18 +0200
changeset 8756 b03a0b219139
parent 8442 96023903c2df
child 9747 043098ba5098
permissions -rw-r--r--
new file Integ/NatSimprocs.ML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1344
diff changeset
     1
(*  Title:      HOL/Lex/Prefix.thy
1344
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1344
diff changeset
     3
    Author:     Richard Mayr & Tobias Nipkow
1344
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
     4
    Copyright   1995 TUM
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
     5
*)
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
     6
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
     7
(** <= is a partial order: **)
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
     8
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
     9
Goalw [prefix_def] "xs <= (xs::'a list)";
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    10
by (Simp_tac 1);
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    11
qed "prefix_refl";
4647
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    12
AddIffs[prefix_refl];
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    13
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    14
Goalw [prefix_def] "!!xs::'a list. [| xs <= ys; ys <= zs |] ==> xs <= zs";
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    15
by (Clarify_tac 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    16
by (Simp_tac 1);
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    17
qed "prefix_trans";
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    18
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    19
Goalw [prefix_def] "!!xs::'a list. [| xs <= ys; ys <= xs |] ==> xs = ys";
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    20
by (Clarify_tac 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    21
by (Asm_full_simp_tac 1);
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    22
qed "prefix_antisym";
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    23
6675
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
    24
Goalw [strict_prefix_def] "!!xs::'a list. (xs < zs) = (xs <= zs & xs ~= zs)";
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
    25
by Auto_tac;
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
    26
qed "prefix_less_le";
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
    27
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
    28
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    29
(** recursion equations **)
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    30
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    31
Goalw [prefix_def] "[] <= xs";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3842
diff changeset
    32
by (simp_tac (simpset() addsimps [eq_sym_conv]) 1);
1344
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    33
qed "Nil_prefix";
4647
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    34
AddIffs[Nil_prefix];
1344
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    35
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    36
Goalw [prefix_def] "(xs <= []) = (xs = [])";
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5132
diff changeset
    37
by (induct_tac "xs" 1);
1344
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    38
by (Simp_tac 1);
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    39
by (Simp_tac 1);
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    40
qed "prefix_Nil";
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    41
Addsimps [prefix_Nil];
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    42
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    43
Goalw [prefix_def] "(xs <= ys@[y]) = (xs = ys@[y] | xs <= ys)";
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    44
by (rtac iffI 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    45
 by (etac exE 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    46
 by (rename_tac "zs" 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    47
 by (res_inst_tac [("xs","zs")] rev_exhaust 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    48
  by (Asm_full_simp_tac 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    49
 by (hyp_subst_tac 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    50
 by (asm_full_simp_tac (simpset() delsimps [append_assoc]
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    51
                                 addsimps [append_assoc RS sym])1);
6808
paulson
parents: 6675
diff changeset
    52
by (Force_tac 1);
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    53
qed "prefix_snoc";
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    54
Addsimps [prefix_snoc];
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    55
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    56
Goalw [prefix_def] "(x#xs <= y#ys) = (x=y & xs<=ys)";
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    57
by (Simp_tac 1);
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    58
by (Fast_tac 1);
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    59
qed"Cons_prefix_Cons";
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    60
Addsimps [Cons_prefix_Cons];
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    61
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    62
Goal "(xs@ys <= xs@zs) = (ys <= zs)";
4647
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    63
by (induct_tac "xs" 1);
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    64
by (ALLGOALS Asm_simp_tac);
4647
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    65
qed "same_prefix_prefix";
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    66
Addsimps [same_prefix_prefix];
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    67
5456
paulson
parents: 5184
diff changeset
    68
AddIffs   (* (xs@ys <= xs) = (ys <= []) *)
4647
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    69
 [simplify (simpset()) (read_instantiate [("zs","[]")] same_prefix_prefix)];
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    70
5118
6b995dad8a9d Removed leading !! in goals.
nipkow
parents: 5069
diff changeset
    71
Goalw [prefix_def] "xs <= ys ==> xs <= ys@zs";
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    72
by (Clarify_tac 1);
4643
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    73
by (Simp_tac 1);
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    74
qed "prefix_prefix";
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    75
Addsimps [prefix_prefix];
1b40fcac5a09 New induction schemas for lists (length and snoc).
nipkow
parents: 4423
diff changeset
    76
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    77
Goalw [prefix_def]
1344
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    78
   "(xs <= y#ys) = (xs=[] | (? zs. xs=y#zs & zs <= ys))";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
    79
by (case_tac "xs" 1);
5456
paulson
parents: 5184
diff changeset
    80
by Auto_tac;
1344
f172a7f14e49 Half a lexical analyzer generator.
nipkow
parents:
diff changeset
    81
qed "prefix_Cons";
4647
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    82
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4936
diff changeset
    83
Goal "(xs <= ys@zs) = (xs <= ys | (? us. xs = ys@us & us <= zs))";
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    84
by (res_inst_tac [("xs","zs")] rev_induct 1);
6808
paulson
parents: 6675
diff changeset
    85
 by (Force_tac 1);
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    86
by (asm_full_simp_tac (simpset() delsimps [append_assoc]
5456
paulson
parents: 5184
diff changeset
    87
                                 addsimps [append_assoc RS sym])1);
5132
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    88
by (Simp_tac 1);
24f992a25adc isatool expandshort;
wenzelm
parents: 5118
diff changeset
    89
by (Blast_tac 1);
4647
42af8ae6e2c1 Added some lemmas.
nipkow
parents: 4643
diff changeset
    90
qed "prefix_append";
5619
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    91
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    92
Goalw [prefix_def]
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    93
  "[| xs <= ys; length xs < length ys |] ==> xs @ [ys ! length xs] <= ys";
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    94
by (auto_tac(claset(), simpset() addsimps [nth_append]));
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
    95
by (case_tac "ys" 1);
5619
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    96
by Auto_tac;
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    97
qed "append_one_prefix";
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    98
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
    99
Goalw [prefix_def] "xs <= ys ==> length xs <= length ys";
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
   100
by Auto_tac;
76a8c72e3fd4 new theorems
paulson
parents: 5609
diff changeset
   101
qed "prefix_length_le";
6675
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
   102
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
   103
Goal "mono length";
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
   104
by (blast_tac (claset() addIs [monoI, prefix_length_le]) 1);
63e53327f5e5 changes to show that Lists are partially ordered by the prefix relation
paulson
parents: 5619
diff changeset
   105
qed "mono_length";