src/HOL/HOLCF/IOA/Sequence.thy
changeset 63549 b0d31c7def86
parent 63120 629a4c5e953e
child 74563 042041c0ebeb
equal deleted inserted replaced
63548:6c2c16fef8f1 63549:b0d31c7def86
    14 
    14 
    15 definition Consq :: "'a \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    15 definition Consq :: "'a \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    16   where "Consq a = (LAM s. Def a ## s)"
    16   where "Consq a = (LAM s. Def a ## s)"
    17 
    17 
    18 definition Filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    18 definition Filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    19   where "Filter P = sfilter $ (flift2 P)"
    19   where "Filter P = sfilter \<cdot> (flift2 P)"
    20 
    20 
    21 definition Map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a Seq \<rightarrow> 'b Seq"
    21 definition Map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a Seq \<rightarrow> 'b Seq"
    22   where "Map f = smap $ (flift2 f)"
    22   where "Map f = smap \<cdot> (flift2 f)"
    23 
    23 
    24 definition Forall :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<Rightarrow> bool"
    24 definition Forall :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<Rightarrow> bool"
    25   where "Forall P = sforall (flift2 P)"
    25   where "Forall P = sforall (flift2 P)"
    26 
    26 
    27 definition Last :: "'a Seq \<rightarrow> 'a lift"
    27 definition Last :: "'a Seq \<rightarrow> 'a lift"
    28   where "Last = slast"
    28   where "Last = slast"
    29 
    29 
    30 definition Dropwhile :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    30 definition Dropwhile :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    31   where "Dropwhile P = sdropwhile $ (flift2 P)"
    31   where "Dropwhile P = sdropwhile \<cdot> (flift2 P)"
    32 
    32 
    33 definition Takewhile :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    33 definition Takewhile :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    34   where "Takewhile P = stakewhile $ (flift2 P)"
    34   where "Takewhile P = stakewhile \<cdot> (flift2 P)"
    35 
    35 
    36 definition Zip :: "'a Seq \<rightarrow> 'b Seq \<rightarrow> ('a * 'b) Seq"
    36 definition Zip :: "'a Seq \<rightarrow> 'b Seq \<rightarrow> ('a * 'b) Seq"
    37   where "Zip =
    37   where "Zip =
    38     (fix $ (LAM h t1 t2.
    38     (fix \<cdot> (LAM h t1 t2.
    39       case t1 of
    39       case t1 of
    40         nil \<Rightarrow> nil
    40         nil \<Rightarrow> nil
    41       | x ## xs \<Rightarrow>
    41       | x ## xs \<Rightarrow>
    42           (case t2 of
    42           (case t2 of
    43             nil \<Rightarrow> UU
    43             nil \<Rightarrow> UU
    45               (case x of
    45               (case x of
    46                 UU \<Rightarrow> UU
    46                 UU \<Rightarrow> UU
    47               | Def a \<Rightarrow>
    47               | Def a \<Rightarrow>
    48                   (case y of
    48                   (case y of
    49                     UU \<Rightarrow> UU
    49                     UU \<Rightarrow> UU
    50                   | Def b \<Rightarrow> Def (a, b) ## (h $ xs $ ys))))))"
    50                   | Def b \<Rightarrow> Def (a, b) ## (h \<cdot> xs \<cdot> ys))))))"
    51 
    51 
    52 definition Flat :: "'a Seq seq \<rightarrow> 'a Seq"
    52 definition Flat :: "'a Seq seq \<rightarrow> 'a Seq"
    53   where "Flat = sflat"
    53   where "Flat = sflat"
    54 
    54 
    55 definition Filter2 :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    55 definition Filter2 :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Seq \<rightarrow> 'a Seq"
    56   where "Filter2 P =
    56   where "Filter2 P =
    57     (fix $
    57     (fix \<cdot>
    58       (LAM h t.
    58       (LAM h t.
    59         case t of
    59         case t of
    60           nil \<Rightarrow> nil
    60           nil \<Rightarrow> nil
    61         | x ## xs \<Rightarrow>
    61         | x ## xs \<Rightarrow>
    62             (case x of
    62             (case x of
    63               UU \<Rightarrow> UU
    63               UU \<Rightarrow> UU
    64             | Def y \<Rightarrow> (if P y then x ## (h $ xs) else h $ xs))))"
    64             | Def y \<Rightarrow> (if P y then x ## (h \<cdot> xs) else h \<cdot> xs))))"
    65 
    65 
    66 abbreviation Consq_syn  ("(_/\<leadsto>_)" [66, 65] 65)
    66 abbreviation Consq_syn  ("(_/\<leadsto>_)" [66, 65] 65)
    67   where "a \<leadsto> s \<equiv> Consq a $ s"
    67   where "a \<leadsto> s \<equiv> Consq a \<cdot> s"
    68 
    68 
    69 
    69 
    70 subsection \<open>List enumeration\<close>
    70 subsection \<open>List enumeration\<close>
    71 
    71 
    72 syntax
    72 syntax
    85 
    85 
    86 subsection \<open>Recursive equations of operators\<close>
    86 subsection \<open>Recursive equations of operators\<close>
    87 
    87 
    88 subsubsection \<open>Map\<close>
    88 subsubsection \<open>Map\<close>
    89 
    89 
    90 lemma Map_UU: "Map f $ UU = UU"
    90 lemma Map_UU: "Map f \<cdot> UU = UU"
    91   by (simp add: Map_def)
    91   by (simp add: Map_def)
    92 
    92 
    93 lemma Map_nil: "Map f $ nil = nil"
    93 lemma Map_nil: "Map f \<cdot> nil = nil"
    94   by (simp add: Map_def)
    94   by (simp add: Map_def)
    95 
    95 
    96 lemma Map_cons: "Map f $ (x \<leadsto> xs) = (f x) \<leadsto> Map f $ xs"
    96 lemma Map_cons: "Map f \<cdot> (x \<leadsto> xs) = (f x) \<leadsto> Map f \<cdot> xs"
    97   by (simp add: Map_def Consq_def flift2_def)
    97   by (simp add: Map_def Consq_def flift2_def)
    98 
    98 
    99 
    99 
   100 subsubsection \<open>Filter\<close>
   100 subsubsection \<open>Filter\<close>
   101 
   101 
   102 lemma Filter_UU: "Filter P $ UU = UU"
   102 lemma Filter_UU: "Filter P \<cdot> UU = UU"
   103   by (simp add: Filter_def)
   103   by (simp add: Filter_def)
   104 
   104 
   105 lemma Filter_nil: "Filter P $ nil = nil"
   105 lemma Filter_nil: "Filter P \<cdot> nil = nil"
   106   by (simp add: Filter_def)
   106   by (simp add: Filter_def)
   107 
   107 
   108 lemma Filter_cons: "Filter P $ (x \<leadsto> xs) = (if P x then x \<leadsto> (Filter P $ xs) else Filter P $ xs)"
   108 lemma Filter_cons: "Filter P \<cdot> (x \<leadsto> xs) = (if P x then x \<leadsto> (Filter P \<cdot> xs) else Filter P \<cdot> xs)"
   109   by (simp add: Filter_def Consq_def flift2_def If_and_if)
   109   by (simp add: Filter_def Consq_def flift2_def If_and_if)
   110 
   110 
   111 
   111 
   112 subsubsection \<open>Forall\<close>
   112 subsubsection \<open>Forall\<close>
   113 
   113 
   127   by (simp add: Consq_def)
   127   by (simp add: Consq_def)
   128 
   128 
   129 
   129 
   130 subsubsection \<open>Takewhile\<close>
   130 subsubsection \<open>Takewhile\<close>
   131 
   131 
   132 lemma Takewhile_UU: "Takewhile P $ UU = UU"
   132 lemma Takewhile_UU: "Takewhile P \<cdot> UU = UU"
   133   by (simp add: Takewhile_def)
   133   by (simp add: Takewhile_def)
   134 
   134 
   135 lemma Takewhile_nil: "Takewhile P $ nil = nil"
   135 lemma Takewhile_nil: "Takewhile P \<cdot> nil = nil"
   136   by (simp add: Takewhile_def)
   136   by (simp add: Takewhile_def)
   137 
   137 
   138 lemma Takewhile_cons:
   138 lemma Takewhile_cons:
   139   "Takewhile P $ (x \<leadsto> xs) = (if P x then x \<leadsto> (Takewhile P $ xs) else nil)"
   139   "Takewhile P \<cdot> (x \<leadsto> xs) = (if P x then x \<leadsto> (Takewhile P \<cdot> xs) else nil)"
   140   by (simp add: Takewhile_def Consq_def flift2_def If_and_if)
   140   by (simp add: Takewhile_def Consq_def flift2_def If_and_if)
   141 
   141 
   142 
   142 
   143 subsubsection \<open>DropWhile\<close>
   143 subsubsection \<open>DropWhile\<close>
   144 
   144 
   145 lemma Dropwhile_UU: "Dropwhile P $ UU = UU"
   145 lemma Dropwhile_UU: "Dropwhile P \<cdot> UU = UU"
   146   by (simp add: Dropwhile_def)
   146   by (simp add: Dropwhile_def)
   147 
   147 
   148 lemma Dropwhile_nil: "Dropwhile P $ nil = nil"
   148 lemma Dropwhile_nil: "Dropwhile P \<cdot> nil = nil"
   149   by (simp add: Dropwhile_def)
   149   by (simp add: Dropwhile_def)
   150 
   150 
   151 lemma Dropwhile_cons: "Dropwhile P $ (x \<leadsto> xs) = (if P x then Dropwhile P $ xs else x \<leadsto> xs)"
   151 lemma Dropwhile_cons: "Dropwhile P \<cdot> (x \<leadsto> xs) = (if P x then Dropwhile P \<cdot> xs else x \<leadsto> xs)"
   152   by (simp add: Dropwhile_def Consq_def flift2_def If_and_if)
   152   by (simp add: Dropwhile_def Consq_def flift2_def If_and_if)
   153 
   153 
   154 
   154 
   155 subsubsection \<open>Last\<close>
   155 subsubsection \<open>Last\<close>
   156 
   156 
   157 lemma Last_UU: "Last $ UU =UU"
   157 lemma Last_UU: "Last \<cdot> UU = UU"
   158   by (simp add: Last_def)
   158   by (simp add: Last_def)
   159 
   159 
   160 lemma Last_nil: "Last $ nil =UU"
   160 lemma Last_nil: "Last \<cdot> nil = UU"
   161   by (simp add: Last_def)
   161   by (simp add: Last_def)
   162 
   162 
   163 lemma Last_cons: "Last $ (x \<leadsto> xs) = (if xs = nil then Def x else Last $ xs)"
   163 lemma Last_cons: "Last \<cdot> (x \<leadsto> xs) = (if xs = nil then Def x else Last \<cdot> xs)"
   164   by (cases xs) (simp_all add: Last_def Consq_def)
   164   by (cases xs) (simp_all add: Last_def Consq_def)
   165 
   165 
   166 
   166 
   167 subsubsection \<open>Flat\<close>
   167 subsubsection \<open>Flat\<close>
   168 
   168 
   169 lemma Flat_UU: "Flat $ UU = UU"
   169 lemma Flat_UU: "Flat \<cdot> UU = UU"
   170   by (simp add: Flat_def)
   170   by (simp add: Flat_def)
   171 
   171 
   172 lemma Flat_nil: "Flat $ nil = nil"
   172 lemma Flat_nil: "Flat \<cdot> nil = nil"
   173   by (simp add: Flat_def)
   173   by (simp add: Flat_def)
   174 
   174 
   175 lemma Flat_cons: "Flat $ (x ## xs) = x @@ (Flat $ xs)"
   175 lemma Flat_cons: "Flat \<cdot> (x ## xs) = x @@ (Flat \<cdot> xs)"
   176   by (simp add: Flat_def Consq_def)
   176   by (simp add: Flat_def Consq_def)
   177 
   177 
   178 
   178 
   179 subsubsection \<open>Zip\<close>
   179 subsubsection \<open>Zip\<close>
   180 
   180 
   190               (case x of
   190               (case x of
   191                 UU \<Rightarrow> UU
   191                 UU \<Rightarrow> UU
   192               | Def a \<Rightarrow>
   192               | Def a \<Rightarrow>
   193                   (case y of
   193                   (case y of
   194                     UU \<Rightarrow> UU
   194                     UU \<Rightarrow> UU
   195                   | Def b \<Rightarrow> Def (a, b) ## (Zip $ xs $ ys)))))"
   195                   | Def b \<Rightarrow> Def (a, b) ## (Zip \<cdot> xs \<cdot> ys)))))"
   196   apply (rule trans)
   196   apply (rule trans)
   197   apply (rule fix_eq4)
   197   apply (rule fix_eq4)
   198   apply (rule Zip_def)
   198   apply (rule Zip_def)
   199   apply (rule beta_cfun)
   199   apply (rule beta_cfun)
   200   apply simp
   200   apply simp
   201   done
   201   done
   202 
   202 
   203 lemma Zip_UU1: "Zip $ UU $ y = UU"
   203 lemma Zip_UU1: "Zip \<cdot> UU \<cdot> y = UU"
   204   apply (subst Zip_unfold)
   204   apply (subst Zip_unfold)
   205   apply simp
   205   apply simp
   206   done
   206   done
   207 
   207 
   208 lemma Zip_UU2: "x \<noteq> nil \<Longrightarrow> Zip $ x $ UU = UU"
   208 lemma Zip_UU2: "x \<noteq> nil \<Longrightarrow> Zip \<cdot> x \<cdot> UU = UU"
   209   apply (subst Zip_unfold)
   209   apply (subst Zip_unfold)
   210   apply simp
   210   apply simp
   211   apply (cases x)
   211   apply (cases x)
   212   apply simp_all
   212   apply simp_all
   213   done
   213   done
   214 
   214 
   215 lemma Zip_nil: "Zip $ nil $ y = nil"
   215 lemma Zip_nil: "Zip \<cdot> nil \<cdot> y = nil"
   216   apply (subst Zip_unfold)
   216   apply (subst Zip_unfold)
   217   apply simp
   217   apply simp
   218   done
   218   done
   219 
   219 
   220 lemma Zip_cons_nil: "Zip $ (x \<leadsto> xs) $ nil = UU"
   220 lemma Zip_cons_nil: "Zip \<cdot> (x \<leadsto> xs) \<cdot> nil = UU"
   221   apply (subst Zip_unfold)
   221   apply (subst Zip_unfold)
   222   apply (simp add: Consq_def)
   222   apply (simp add: Consq_def)
   223   done
   223   done
   224 
   224 
   225 lemma Zip_cons: "Zip $ (x \<leadsto> xs) $ (y \<leadsto> ys) = (x, y) \<leadsto> Zip $ xs $ ys"
   225 lemma Zip_cons: "Zip \<cdot> (x \<leadsto> xs) \<cdot> (y \<leadsto> ys) = (x, y) \<leadsto> Zip \<cdot> xs \<cdot> ys"
   226   apply (rule trans)
   226   apply (rule trans)
   227   apply (subst Zip_unfold)
   227   apply (subst Zip_unfold)
   228   apply simp
   228   apply simp
   229   apply (simp add: Consq_def)
   229   apply (simp add: Consq_def)
   230   done
   230   done
   296   by (simp add: Consq_def2 scons_inject_eq)
   296   by (simp add: Consq_def2 scons_inject_eq)
   297 
   297 
   298 lemma Cons_inject_less_eq: "a \<leadsto> s \<sqsubseteq> b \<leadsto> t \<longleftrightarrow> a = b \<and> s \<sqsubseteq> t"
   298 lemma Cons_inject_less_eq: "a \<leadsto> s \<sqsubseteq> b \<leadsto> t \<longleftrightarrow> a = b \<and> s \<sqsubseteq> t"
   299   by (simp add: Consq_def2)
   299   by (simp add: Consq_def2)
   300 
   300 
   301 lemma seq_take_Cons: "seq_take (Suc n) $ (a \<leadsto> x) = a \<leadsto> (seq_take n $ x)"
   301 lemma seq_take_Cons: "seq_take (Suc n) \<cdot> (a \<leadsto> x) = a \<leadsto> (seq_take n \<cdot> x)"
   302   by (simp add: Consq_def)
   302   by (simp add: Consq_def)
   303 
   303 
   304 lemmas [simp] =
   304 lemmas [simp] =
   305   Cons_not_nil2 Cons_inject_eq Cons_inject_less_eq seq_take_Cons
   305   Cons_not_nil2 Cons_inject_eq Cons_inject_less_eq seq_take_Cons
   306   Cons_not_UU Cons_not_less_UU Cons_not_less_nil Cons_not_nil
   306   Cons_not_UU Cons_not_less_UU Cons_not_less_nil Cons_not_nil
   343   done
   343   done
   344 
   344 
   345 
   345 
   346 subsection \<open>\<open>HD\<close> and \<open>TL\<close>\<close>
   346 subsection \<open>\<open>HD\<close> and \<open>TL\<close>\<close>
   347 
   347 
   348 lemma HD_Cons [simp]: "HD $ (x \<leadsto> y) = Def x"
   348 lemma HD_Cons [simp]: "HD \<cdot> (x \<leadsto> y) = Def x"
   349   by (simp add: Consq_def)
   349   by (simp add: Consq_def)
   350 
   350 
   351 lemma TL_Cons [simp]: "TL $ (x \<leadsto> y) = y"
   351 lemma TL_Cons [simp]: "TL \<cdot> (x \<leadsto> y) = y"
   352   by (simp add: Consq_def)
   352   by (simp add: Consq_def)
   353 
   353 
   354 
   354 
   355 subsection \<open>\<open>Finite\<close>, \<open>Partial\<close>, \<open>Infinite\<close>\<close>
   355 subsection \<open>\<open>Finite\<close>, \<open>Partial\<close>, \<open>Infinite\<close>\<close>
   356 
   356 
   380   apply (rule FiniteConc_1 [rule_format])
   380   apply (rule FiniteConc_1 [rule_format])
   381   apply auto
   381   apply auto
   382   done
   382   done
   383 
   383 
   384 
   384 
   385 lemma FiniteMap1: "Finite s \<Longrightarrow> Finite (Map f $ s)"
   385 lemma FiniteMap1: "Finite s \<Longrightarrow> Finite (Map f \<cdot> s)"
   386   apply (erule Seq_Finite_ind)
   386   apply (erule Seq_Finite_ind)
   387   apply simp_all
   387   apply simp_all
   388   done
   388   done
   389 
   389 
   390 lemma FiniteMap2: "Finite s \<Longrightarrow> \<forall>t. s = Map f $ t \<longrightarrow> Finite t"
   390 lemma FiniteMap2: "Finite s \<Longrightarrow> \<forall>t. s = Map f \<cdot> t \<longrightarrow> Finite t"
   391   apply (erule Seq_Finite_ind)
   391   apply (erule Seq_Finite_ind)
   392   apply (intro strip)
   392   apply (intro strip)
   393   apply (rule_tac x="t" in Seq_cases, simp_all)
   393   apply (rule_tac x="t" in Seq_cases, simp_all)
   394   text \<open>\<open>main case\<close>\<close>
   394   text \<open>\<open>main case\<close>\<close>
   395   apply auto
   395   apply auto
   396   apply (rule_tac x="t" in Seq_cases, simp_all)
   396   apply (rule_tac x="t" in Seq_cases, simp_all)
   397   done
   397   done
   398 
   398 
   399 lemma Map2Finite: "Finite (Map f $ s) = Finite s"
   399 lemma Map2Finite: "Finite (Map f \<cdot> s) = Finite s"
   400   apply auto
   400   apply auto
   401   apply (erule FiniteMap2 [rule_format])
   401   apply (erule FiniteMap2 [rule_format])
   402   apply (rule refl)
   402   apply (rule refl)
   403   apply (erule FiniteMap1)
   403   apply (erule FiniteMap1)
   404   done
   404   done
   405 
   405 
   406 
   406 
   407 lemma FiniteFilter: "Finite s \<Longrightarrow> Finite (Filter P $ s)"
   407 lemma FiniteFilter: "Finite s \<Longrightarrow> Finite (Filter P \<cdot> s)"
   408   apply (erule Seq_Finite_ind)
   408   apply (erule Seq_Finite_ind)
   409   apply simp_all
   409   apply simp_all
   410   done
   410   done
   411 
   411 
   412 
   412 
   443   done
   443   done
   444 
   444 
   445 
   445 
   446 subsection \<open>Last\<close>
   446 subsection \<open>Last\<close>
   447 
   447 
   448 lemma Finite_Last1: "Finite s \<Longrightarrow> s \<noteq> nil \<longrightarrow> Last $ s \<noteq> UU"
   448 lemma Finite_Last1: "Finite s \<Longrightarrow> s \<noteq> nil \<longrightarrow> Last \<cdot> s \<noteq> UU"
   449   by (erule Seq_Finite_ind) simp_all
   449   by (erule Seq_Finite_ind) simp_all
   450 
   450 
   451 lemma Finite_Last2: "Finite s \<Longrightarrow> Last $ s = UU \<longrightarrow> s = nil"
   451 lemma Finite_Last2: "Finite s \<Longrightarrow> Last \<cdot> s = UU \<longrightarrow> s = nil"
   452   by (erule Seq_Finite_ind) auto
   452   by (erule Seq_Finite_ind) auto
   453 
   453 
   454 
   454 
   455 subsection \<open>Filter, Conc\<close>
   455 subsection \<open>Filter, Conc\<close>
   456 
   456 
   457 lemma FilterPQ: "Filter P $ (Filter Q $ s) = Filter (\<lambda>x. P x \<and> Q x) $ s"
   457 lemma FilterPQ: "Filter P \<cdot> (Filter Q \<cdot> s) = Filter (\<lambda>x. P x \<and> Q x) \<cdot> s"
   458   by (rule_tac x="s" in Seq_induct) simp_all
   458   by (rule_tac x="s" in Seq_induct) simp_all
   459 
   459 
   460 lemma FilterConc: "Filter P $ (x @@ y) = (Filter P $ x @@ Filter P $ y)"
   460 lemma FilterConc: "Filter P \<cdot> (x @@ y) = (Filter P \<cdot> x @@ Filter P \<cdot> y)"
   461   by (simp add: Filter_def sfiltersconc)
   461   by (simp add: Filter_def sfiltersconc)
   462 
   462 
   463 
   463 
   464 subsection \<open>Map\<close>
   464 subsection \<open>Map\<close>
   465 
   465 
   466 lemma MapMap: "Map f $ (Map g $ s) = Map (f \<circ> g) $ s"
   466 lemma MapMap: "Map f \<cdot> (Map g \<cdot> s) = Map (f \<circ> g) \<cdot> s"
   467   by (rule_tac x="s" in Seq_induct) simp_all
   467   by (rule_tac x="s" in Seq_induct) simp_all
   468 
   468 
   469 lemma MapConc: "Map f $ (x @@ y) = (Map f $ x) @@ (Map f $ y)"
   469 lemma MapConc: "Map f \<cdot> (x @@ y) = (Map f \<cdot> x) @@ (Map f \<cdot> y)"
   470   by (rule_tac x="x" in Seq_induct) simp_all
   470   by (rule_tac x="x" in Seq_induct) simp_all
   471 
   471 
   472 lemma MapFilter: "Filter P $ (Map f $ x) = Map f $ (Filter (P \<circ> f) $ x)"
   472 lemma MapFilter: "Filter P \<cdot> (Map f \<cdot> x) = Map f \<cdot> (Filter (P \<circ> f) \<cdot> x)"
   473   by (rule_tac x="x" in Seq_induct) simp_all
   473   by (rule_tac x="x" in Seq_induct) simp_all
   474 
   474 
   475 lemma nilMap: "nil = (Map f $ s) \<longrightarrow> s = nil"
   475 lemma nilMap: "nil = (Map f \<cdot> s) \<longrightarrow> s = nil"
   476   by (rule_tac x="s" in Seq_cases) simp_all
   476   by (rule_tac x="s" in Seq_cases) simp_all
   477 
   477 
   478 lemma ForallMap: "Forall P (Map f $ s) = Forall (P \<circ> f) s"
   478 lemma ForallMap: "Forall P (Map f \<cdot> s) = Forall (P \<circ> f) s"
   479   apply (rule_tac x="s" in Seq_induct)
   479   apply (rule_tac x="s" in Seq_induct)
   480   apply (simp add: Forall_def sforall_def)
   480   apply (simp add: Forall_def sforall_def)
   481   apply simp_all
   481   apply simp_all
   482   done
   482   done
   483 
   483 
   500   done
   500   done
   501 
   501 
   502 lemma Forall_Conc [simp]: "Finite x \<Longrightarrow> Forall P (x @@ y) \<longleftrightarrow> Forall P x \<and> Forall P y"
   502 lemma Forall_Conc [simp]: "Finite x \<Longrightarrow> Forall P (x @@ y) \<longleftrightarrow> Forall P x \<and> Forall P y"
   503   by (erule Seq_Finite_ind) simp_all
   503   by (erule Seq_Finite_ind) simp_all
   504 
   504 
   505 lemma ForallTL1: "Forall P s \<longrightarrow> Forall P (TL $ s)"
   505 lemma ForallTL1: "Forall P s \<longrightarrow> Forall P (TL \<cdot> s)"
   506   apply (rule_tac x="s" in Seq_induct)
   506   apply (rule_tac x="s" in Seq_induct)
   507   apply (simp add: Forall_def sforall_def)
   507   apply (simp add: Forall_def sforall_def)
   508   apply simp_all
   508   apply simp_all
   509   done
   509   done
   510 
   510 
   511 lemmas ForallTL = ForallTL1 [THEN mp]
   511 lemmas ForallTL = ForallTL1 [THEN mp]
   512 
   512 
   513 lemma ForallDropwhile1: "Forall P s \<longrightarrow> Forall P (Dropwhile Q $ s)"
   513 lemma ForallDropwhile1: "Forall P s \<longrightarrow> Forall P (Dropwhile Q \<cdot> s)"
   514   apply (rule_tac x="s" in Seq_induct)
   514   apply (rule_tac x="s" in Seq_induct)
   515   apply (simp add: Forall_def sforall_def)
   515   apply (simp add: Forall_def sforall_def)
   516   apply simp_all
   516   apply simp_all
   517   done
   517   done
   518 
   518 
   535 lemma Forall_postfixclosed: "Finite h \<Longrightarrow> Forall P s \<Longrightarrow> s= h @@ t \<Longrightarrow> Forall P t"
   535 lemma Forall_postfixclosed: "Finite h \<Longrightarrow> Forall P s \<Longrightarrow> s= h @@ t \<Longrightarrow> Forall P t"
   536   by auto
   536   by auto
   537 
   537 
   538 
   538 
   539 lemma ForallPFilterQR1:
   539 lemma ForallPFilterQR1:
   540   "(\<forall>x. P x \<longrightarrow> Q x = R x) \<and> Forall P tr \<longrightarrow> Filter Q $ tr = Filter R $ tr"
   540   "(\<forall>x. P x \<longrightarrow> Q x = R x) \<and> Forall P tr \<longrightarrow> Filter Q \<cdot> tr = Filter R \<cdot> tr"
   541   apply (rule_tac x="tr" in Seq_induct)
   541   apply (rule_tac x="tr" in Seq_induct)
   542   apply (simp add: Forall_def sforall_def)
   542   apply (simp add: Forall_def sforall_def)
   543   apply simp_all
   543   apply simp_all
   544   done
   544   done
   545 
   545 
   546 lemmas ForallPFilterQR = ForallPFilterQR1 [THEN mp, OF conjI, OF allI]
   546 lemmas ForallPFilterQR = ForallPFilterQR1 [THEN mp, OF conjI, OF allI]
   547 
   547 
   548 
   548 
   549 subsection \<open>Forall, Filter\<close>
   549 subsection \<open>Forall, Filter\<close>
   550 
   550 
   551 lemma ForallPFilterP: "Forall P (Filter P $ x)"
   551 lemma ForallPFilterP: "Forall P (Filter P \<cdot> x)"
   552   by (simp add: Filter_def Forall_def forallPsfilterP)
   552   by (simp add: Filter_def Forall_def forallPsfilterP)
   553 
   553 
   554 (*holds also in other direction, then equal to forallPfilterP*)
   554 (*holds also in other direction, then equal to forallPfilterP*)
   555 lemma ForallPFilterPid1: "Forall P x \<longrightarrow> Filter P $ x = x"
   555 lemma ForallPFilterPid1: "Forall P x \<longrightarrow> Filter P \<cdot> x = x"
   556   apply (rule_tac x="x" in Seq_induct)
   556   apply (rule_tac x="x" in Seq_induct)
   557   apply (simp add: Forall_def sforall_def Filter_def)
   557   apply (simp add: Forall_def sforall_def Filter_def)
   558   apply simp_all
   558   apply simp_all
   559   done
   559   done
   560 
   560 
   561 lemmas ForallPFilterPid = ForallPFilterPid1 [THEN mp]
   561 lemmas ForallPFilterPid = ForallPFilterPid1 [THEN mp]
   562 
   562 
   563 (*holds also in other direction*)
   563 (*holds also in other direction*)
   564 lemma ForallnPFilterPnil1: "Finite ys \<Longrightarrow> Forall (\<lambda>x. \<not> P x) ys \<longrightarrow> Filter P $ ys = nil"
   564 lemma ForallnPFilterPnil1: "Finite ys \<Longrightarrow> Forall (\<lambda>x. \<not> P x) ys \<longrightarrow> Filter P \<cdot> ys = nil"
   565   by (erule Seq_Finite_ind) simp_all
   565   by (erule Seq_Finite_ind) simp_all
   566 
   566 
   567 lemmas ForallnPFilterPnil = ForallnPFilterPnil1 [THEN mp]
   567 lemmas ForallnPFilterPnil = ForallnPFilterPnil1 [THEN mp]
   568 
   568 
   569 
   569 
   570 (*holds also in other direction*)
   570 (*holds also in other direction*)
   571 lemma ForallnPFilterPUU1: "\<not> Finite ys \<and> Forall (\<lambda>x. \<not> P x) ys \<longrightarrow> Filter P $ ys = UU"
   571 lemma ForallnPFilterPUU1: "\<not> Finite ys \<and> Forall (\<lambda>x. \<not> P x) ys \<longrightarrow> Filter P \<cdot> ys = UU"
   572   apply (rule_tac x="ys" in Seq_induct)
   572   apply (rule_tac x="ys" in Seq_induct)
   573   apply (simp add: Forall_def sforall_def)
   573   apply (simp add: Forall_def sforall_def)
   574   apply simp_all
   574   apply simp_all
   575   done
   575   done
   576 
   576 
   577 lemmas ForallnPFilterPUU = ForallnPFilterPUU1 [THEN mp, OF conjI]
   577 lemmas ForallnPFilterPUU = ForallnPFilterPUU1 [THEN mp, OF conjI]
   578 
   578 
   579 
   579 
   580 (*inverse of ForallnPFilterPnil*)
   580 (*inverse of ForallnPFilterPnil*)
   581 lemma FilternPnilForallP [rule_format]: "Filter P $ ys = nil \<longrightarrow> Forall (\<lambda>x. \<not> P x) ys \<and> Finite ys"
   581 lemma FilternPnilForallP [rule_format]: "Filter P \<cdot> ys = nil \<longrightarrow> Forall (\<lambda>x. \<not> P x) ys \<and> Finite ys"
   582   apply (rule_tac x="ys" in Seq_induct)
   582   apply (rule_tac x="ys" in Seq_induct)
   583   text \<open>adm\<close>
   583   text \<open>adm\<close>
   584   apply (simp add: Forall_def sforall_def)
   584   apply (simp add: Forall_def sforall_def)
   585   text \<open>base cases\<close>
   585   text \<open>base cases\<close>
   586   apply simp
   586   apply simp
   589   apply simp
   589   apply simp
   590   done
   590   done
   591 
   591 
   592 (*inverse of ForallnPFilterPUU*)
   592 (*inverse of ForallnPFilterPUU*)
   593 lemma FilternPUUForallP:
   593 lemma FilternPUUForallP:
   594   assumes "Filter P $ ys = UU"
   594   assumes "Filter P \<cdot> ys = UU"
   595   shows "Forall (\<lambda>x. \<not> P x) ys \<and> \<not> Finite ys"
   595   shows "Forall (\<lambda>x. \<not> P x) ys \<and> \<not> Finite ys"
   596 proof
   596 proof
   597   show "Forall (\<lambda>x. \<not> P x) ys"
   597   show "Forall (\<lambda>x. \<not> P x) ys"
   598   proof (rule classical)
   598   proof (rule classical)
   599     assume "\<not> ?thesis"
   599     assume "\<not> ?thesis"
   600     then have "Filter P $ ys \<noteq> UU"
   600     then have "Filter P \<cdot> ys \<noteq> UU"
   601       apply (rule rev_mp)
   601       apply (rule rev_mp)
   602       apply (induct ys rule: Seq_induct)
   602       apply (induct ys rule: Seq_induct)
   603       apply (simp add: Forall_def sforall_def)
   603       apply (simp add: Forall_def sforall_def)
   604       apply simp_all
   604       apply simp_all
   605       done
   605       done
   606     with assms show ?thesis by contradiction
   606     with assms show ?thesis by contradiction
   607   qed
   607   qed
   608   show "\<not> Finite ys"
   608   show "\<not> Finite ys"
   609   proof
   609   proof
   610     assume "Finite ys"
   610     assume "Finite ys"
   611     then have "Filter P$ys \<noteq> UU"
   611     then have "Filter P\<cdot>ys \<noteq> UU"
   612       by (rule Seq_Finite_ind) simp_all
   612       by (rule Seq_Finite_ind) simp_all
   613     with assms show False by contradiction
   613     with assms show False by contradiction
   614   qed
   614   qed
   615 qed
   615 qed
   616 
   616 
   617 
   617 
   618 lemma ForallQFilterPnil:
   618 lemma ForallQFilterPnil:
   619   "Forall Q ys \<Longrightarrow> Finite ys \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> \<not> P x) \<Longrightarrow> Filter P $ ys = nil"
   619   "Forall Q ys \<Longrightarrow> Finite ys \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> \<not> P x) \<Longrightarrow> Filter P \<cdot> ys = nil"
   620   apply (erule ForallnPFilterPnil)
   620   apply (erule ForallnPFilterPnil)
   621   apply (erule ForallPForallQ)
   621   apply (erule ForallPForallQ)
   622   apply auto
   622   apply auto
   623   done
   623   done
   624 
   624 
   625 lemma ForallQFilterPUU: "\<not> Finite ys \<Longrightarrow> Forall Q ys \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> \<not> P x) \<Longrightarrow> Filter P $ ys = UU"
   625 lemma ForallQFilterPUU: "\<not> Finite ys \<Longrightarrow> Forall Q ys \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> \<not> P x) \<Longrightarrow> Filter P \<cdot> ys = UU"
   626   apply (erule ForallnPFilterPUU)
   626   apply (erule ForallnPFilterPUU)
   627   apply (erule ForallPForallQ)
   627   apply (erule ForallPForallQ)
   628   apply auto
   628   apply auto
   629   done
   629   done
   630 
   630 
   631 
   631 
   632 subsection \<open>Takewhile, Forall, Filter\<close>
   632 subsection \<open>Takewhile, Forall, Filter\<close>
   633 
   633 
   634 lemma ForallPTakewhileP [simp]: "Forall P (Takewhile P $ x)"
   634 lemma ForallPTakewhileP [simp]: "Forall P (Takewhile P \<cdot> x)"
   635   by (simp add: Forall_def Takewhile_def sforallPstakewhileP)
   635   by (simp add: Forall_def Takewhile_def sforallPstakewhileP)
   636 
   636 
   637 
   637 
   638 lemma ForallPTakewhileQ [simp]: "(\<And>x. Q x \<Longrightarrow> P x) \<Longrightarrow> Forall P (Takewhile Q $ x)"
   638 lemma ForallPTakewhileQ [simp]: "(\<And>x. Q x \<Longrightarrow> P x) \<Longrightarrow> Forall P (Takewhile Q \<cdot> x)"
   639   apply (rule ForallPForallQ)
   639   apply (rule ForallPForallQ)
   640   apply (rule ForallPTakewhileP)
   640   apply (rule ForallPTakewhileP)
   641   apply auto
   641   apply auto
   642   done
   642   done
   643 
   643 
   644 
   644 
   645 lemma FilterPTakewhileQnil [simp]:
   645 lemma FilterPTakewhileQnil [simp]:
   646   "Finite (Takewhile Q $ ys) \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> \<not> P x) \<Longrightarrow> Filter P $ (Takewhile Q $ ys) = nil"
   646   "Finite (Takewhile Q \<cdot> ys) \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> \<not> P x) \<Longrightarrow> Filter P \<cdot> (Takewhile Q \<cdot> ys) = nil"
   647   apply (erule ForallnPFilterPnil)
   647   apply (erule ForallnPFilterPnil)
   648   apply (rule ForallPForallQ)
   648   apply (rule ForallPForallQ)
   649   apply (rule ForallPTakewhileP)
   649   apply (rule ForallPTakewhileP)
   650   apply auto
   650   apply auto
   651   done
   651   done
   652 
   652 
   653 lemma FilterPTakewhileQid [simp]:
   653 lemma FilterPTakewhileQid [simp]:
   654   "(\<And>x. Q x \<Longrightarrow> P x) \<Longrightarrow> Filter P $ (Takewhile Q $ ys) = Takewhile Q $ ys"
   654   "(\<And>x. Q x \<Longrightarrow> P x) \<Longrightarrow> Filter P \<cdot> (Takewhile Q \<cdot> ys) = Takewhile Q \<cdot> ys"
   655   apply (rule ForallPFilterPid)
   655   apply (rule ForallPFilterPid)
   656   apply (rule ForallPForallQ)
   656   apply (rule ForallPForallQ)
   657   apply (rule ForallPTakewhileP)
   657   apply (rule ForallPTakewhileP)
   658   apply auto
   658   apply auto
   659   done
   659   done
   660 
   660 
   661 
   661 
   662 lemma Takewhile_idempotent: "Takewhile P $ (Takewhile P $ s) = Takewhile P $ s"
   662 lemma Takewhile_idempotent: "Takewhile P \<cdot> (Takewhile P \<cdot> s) = Takewhile P \<cdot> s"
   663   apply (rule_tac x="s" in Seq_induct)
   663   apply (rule_tac x="s" in Seq_induct)
   664   apply (simp add: Forall_def sforall_def)
   664   apply (simp add: Forall_def sforall_def)
   665   apply simp_all
   665   apply simp_all
   666   done
   666   done
   667 
   667 
   668 lemma ForallPTakewhileQnP [simp]:
   668 lemma ForallPTakewhileQnP [simp]:
   669   "Forall P s \<longrightarrow> Takewhile (\<lambda>x. Q x \<or> (\<not> P x)) $ s = Takewhile Q $ s"
   669   "Forall P s \<longrightarrow> Takewhile (\<lambda>x. Q x \<or> (\<not> P x)) \<cdot> s = Takewhile Q \<cdot> s"
   670   apply (rule_tac x="s" in Seq_induct)
   670   apply (rule_tac x="s" in Seq_induct)
   671   apply (simp add: Forall_def sforall_def)
   671   apply (simp add: Forall_def sforall_def)
   672   apply simp_all
   672   apply simp_all
   673   done
   673   done
   674 
   674 
   675 lemma ForallPDropwhileQnP [simp]:
   675 lemma ForallPDropwhileQnP [simp]:
   676   "Forall P s \<longrightarrow> Dropwhile (\<lambda>x. Q x \<or> (\<not> P x)) $ s = Dropwhile Q $ s"
   676   "Forall P s \<longrightarrow> Dropwhile (\<lambda>x. Q x \<or> (\<not> P x)) \<cdot> s = Dropwhile Q \<cdot> s"
   677   apply (rule_tac x="s" in Seq_induct)
   677   apply (rule_tac x="s" in Seq_induct)
   678   apply (simp add: Forall_def sforall_def)
   678   apply (simp add: Forall_def sforall_def)
   679   apply simp_all
   679   apply simp_all
   680   done
   680   done
   681 
   681 
   682 
   682 
   683 lemma TakewhileConc1: "Forall P s \<longrightarrow> Takewhile P $ (s @@ t) = s @@ (Takewhile P $ t)"
   683 lemma TakewhileConc1: "Forall P s \<longrightarrow> Takewhile P \<cdot> (s @@ t) = s @@ (Takewhile P \<cdot> t)"
   684   apply (rule_tac x="s" in Seq_induct)
   684   apply (rule_tac x="s" in Seq_induct)
   685   apply (simp add: Forall_def sforall_def)
   685   apply (simp add: Forall_def sforall_def)
   686   apply simp_all
   686   apply simp_all
   687   done
   687   done
   688 
   688 
   689 lemmas TakewhileConc = TakewhileConc1 [THEN mp]
   689 lemmas TakewhileConc = TakewhileConc1 [THEN mp]
   690 
   690 
   691 lemma DropwhileConc1: "Finite s \<Longrightarrow> Forall P s \<longrightarrow> Dropwhile P $ (s @@ t) = Dropwhile P $ t"
   691 lemma DropwhileConc1: "Finite s \<Longrightarrow> Forall P s \<longrightarrow> Dropwhile P \<cdot> (s @@ t) = Dropwhile P \<cdot> t"
   692   by (erule Seq_Finite_ind) simp_all
   692   by (erule Seq_Finite_ind) simp_all
   693 
   693 
   694 lemmas DropwhileConc = DropwhileConc1 [THEN mp]
   694 lemmas DropwhileConc = DropwhileConc1 [THEN mp]
   695 
   695 
   696 
   696 
   697 subsection \<open>Coinductive characterizations of Filter\<close>
   697 subsection \<open>Coinductive characterizations of Filter\<close>
   698 
   698 
   699 lemma divide_Seq_lemma:
   699 lemma divide_Seq_lemma:
   700   "HD $ (Filter P $ y) = Def x \<longrightarrow>
   700   "HD \<cdot> (Filter P \<cdot> y) = Def x \<longrightarrow>
   701     y = (Takewhile (\<lambda>x. \<not> P x) $ y) @@ (x \<leadsto> TL $ (Dropwhile (\<lambda>a. \<not> P a) $ y)) \<and>
   701     y = (Takewhile (\<lambda>x. \<not> P x) \<cdot> y) @@ (x \<leadsto> TL \<cdot> (Dropwhile (\<lambda>a. \<not> P a) \<cdot> y)) \<and>
   702     Finite (Takewhile (\<lambda>x. \<not> P x) $ y) \<and> P x"
   702     Finite (Takewhile (\<lambda>x. \<not> P x) \<cdot> y) \<and> P x"
   703   (* FIX: pay attention: is only admissible with chain-finite package to be added to
   703   (* FIX: pay attention: is only admissible with chain-finite package to be added to
   704           adm test and Finite f x admissibility *)
   704           adm test and Finite f x admissibility *)
   705   apply (rule_tac x="y" in Seq_induct)
   705   apply (rule_tac x="y" in Seq_induct)
   706   apply (simp add: adm_subst [OF _ adm_Finite])
   706   apply (simp add: adm_subst [OF _ adm_Finite])
   707   apply simp
   707   apply simp
   711    apply blast
   711    apply blast
   712   text \<open>\<open>\<not> P a\<close>\<close>
   712   text \<open>\<open>\<not> P a\<close>\<close>
   713   apply simp
   713   apply simp
   714   done
   714   done
   715 
   715 
   716 lemma divide_Seq: "(x \<leadsto> xs) \<sqsubseteq> Filter P $ y \<Longrightarrow>
   716 lemma divide_Seq: "(x \<leadsto> xs) \<sqsubseteq> Filter P \<cdot> y \<Longrightarrow>
   717   y = ((Takewhile (\<lambda>a. \<not> P a) $ y) @@ (x \<leadsto> TL $ (Dropwhile (\<lambda>a. \<not> P a) $ y))) \<and>
   717   y = ((Takewhile (\<lambda>a. \<not> P a) \<cdot> y) @@ (x \<leadsto> TL \<cdot> (Dropwhile (\<lambda>a. \<not> P a) \<cdot> y))) \<and>
   718   Finite (Takewhile (\<lambda>a. \<not> P a) $ y) \<and> P x"
   718   Finite (Takewhile (\<lambda>a. \<not> P a) \<cdot> y) \<and> P x"
   719   apply (rule divide_Seq_lemma [THEN mp])
   719   apply (rule divide_Seq_lemma [THEN mp])
   720   apply (drule_tac f="HD" and x="x \<leadsto> xs" in  monofun_cfun_arg)
   720   apply (drule_tac f="HD" and x="x \<leadsto> xs" in  monofun_cfun_arg)
   721   apply simp
   721   apply simp
   722   done
   722   done
   723 
   723 
   724 
   724 
   725 lemma nForall_HDFilter: "\<not> Forall P y \<longrightarrow> (\<exists>x. HD $ (Filter (\<lambda>a. \<not> P a) $ y) = Def x)"
   725 lemma nForall_HDFilter: "\<not> Forall P y \<longrightarrow> (\<exists>x. HD \<cdot> (Filter (\<lambda>a. \<not> P a) \<cdot> y) = Def x)"
   726   unfolding not_Undef_is_Def [symmetric]
   726   unfolding not_Undef_is_Def [symmetric]
   727   apply (induct y rule: Seq_induct)
   727   apply (induct y rule: Seq_induct)
   728   apply (simp add: Forall_def sforall_def)
   728   apply (simp add: Forall_def sforall_def)
   729   apply simp_all
   729   apply simp_all
   730   done
   730   done
   731 
   731 
   732 
   732 
   733 lemma divide_Seq2:
   733 lemma divide_Seq2:
   734   "\<not> Forall P y \<Longrightarrow>
   734   "\<not> Forall P y \<Longrightarrow>
   735     \<exists>x. y = Takewhile P$y @@ (x \<leadsto> TL $ (Dropwhile P $ y)) \<and> Finite (Takewhile P $ y) \<and> \<not> P x"
   735     \<exists>x. y = Takewhile P\<cdot>y @@ (x \<leadsto> TL \<cdot> (Dropwhile P \<cdot> y)) \<and> Finite (Takewhile P \<cdot> y) \<and> \<not> P x"
   736   apply (drule nForall_HDFilter [THEN mp])
   736   apply (drule nForall_HDFilter [THEN mp])
   737   apply safe
   737   apply safe
   738   apply (rule_tac x="x" in exI)
   738   apply (rule_tac x="x" in exI)
   739   apply (cut_tac P1="\<lambda>x. \<not> P x" in divide_Seq_lemma [THEN mp])
   739   apply (cut_tac P1="\<lambda>x. \<not> P x" in divide_Seq_lemma [THEN mp])
   740   apply auto
   740   apply auto
   750 lemmas [simp] = FilterPQ FilterConc Conc_cong
   750 lemmas [simp] = FilterPQ FilterConc Conc_cong
   751 
   751 
   752 
   752 
   753 subsection \<open>Take-lemma\<close>
   753 subsection \<open>Take-lemma\<close>
   754 
   754 
   755 lemma seq_take_lemma: "(\<forall>n. seq_take n $ x = seq_take n $ x') \<longleftrightarrow> x = x'"
   755 lemma seq_take_lemma: "(\<forall>n. seq_take n \<cdot> x = seq_take n \<cdot> x') \<longleftrightarrow> x = x'"
   756   apply (rule iffI)
   756   apply (rule iffI)
   757   apply (rule seq.take_lemma)
   757   apply (rule seq.take_lemma)
   758   apply auto
   758   apply auto
   759   done
   759   done
   760 
   760 
   761 lemma take_reduction1:
   761 lemma take_reduction1:
   762   "\<forall>n. ((\<forall>k. k < n \<longrightarrow> seq_take k $ y1 = seq_take k $ y2) \<longrightarrow>
   762   "\<forall>n. ((\<forall>k. k < n \<longrightarrow> seq_take k \<cdot> y1 = seq_take k \<cdot> y2) \<longrightarrow>
   763     seq_take n $ (x @@ (t \<leadsto> y1)) =  seq_take n $ (x @@ (t \<leadsto> y2)))"
   763     seq_take n \<cdot> (x @@ (t \<leadsto> y1)) =  seq_take n \<cdot> (x @@ (t \<leadsto> y2)))"
   764   apply (rule_tac x="x" in Seq_induct)
   764   apply (rule_tac x="x" in Seq_induct)
   765   apply simp_all
   765   apply simp_all
   766   apply (intro strip)
   766   apply (intro strip)
   767   apply (case_tac "n")
   767   apply (case_tac "n")
   768   apply auto
   768   apply auto
   769   apply (case_tac "n")
   769   apply (case_tac "n")
   770   apply auto
   770   apply auto
   771   done
   771   done
   772 
   772 
   773 lemma take_reduction:
   773 lemma take_reduction:
   774   "x = y \<Longrightarrow> s = t \<Longrightarrow> (\<And>k. k < n \<Longrightarrow> seq_take k $ y1 = seq_take k $ y2)
   774   "x = y \<Longrightarrow> s = t \<Longrightarrow> (\<And>k. k < n \<Longrightarrow> seq_take k \<cdot> y1 = seq_take k \<cdot> y2)
   775     \<Longrightarrow> seq_take n $ (x @@ (s \<leadsto> y1)) = seq_take n $ (y @@ (t \<leadsto> y2))"
   775     \<Longrightarrow> seq_take n \<cdot> (x @@ (s \<leadsto> y1)) = seq_take n \<cdot> (y @@ (t \<leadsto> y2))"
   776   by (auto intro!: take_reduction1 [rule_format])
   776   by (auto intro!: take_reduction1 [rule_format])
   777 
   777 
   778 
   778 
   779 text \<open>
   779 text \<open>
   780   Take-lemma and take-reduction for \<open>\<sqsubseteq>\<close> instead of \<open>=\<close>.
   780   Take-lemma and take-reduction for \<open>\<sqsubseteq>\<close> instead of \<open>=\<close>.
   781 \<close>
   781 \<close>
   782           
   782           
   783 lemma take_reduction_less1:
   783 lemma take_reduction_less1:
   784   "\<forall>n. ((\<forall>k. k < n \<longrightarrow> seq_take k $ y1 \<sqsubseteq> seq_take k$y2) \<longrightarrow>
   784   "\<forall>n. ((\<forall>k. k < n \<longrightarrow> seq_take k \<cdot> y1 \<sqsubseteq> seq_take k\<cdot>y2) \<longrightarrow>
   785     seq_take n $ (x @@ (t \<leadsto> y1)) \<sqsubseteq> seq_take n $ (x @@ (t \<leadsto> y2)))"
   785     seq_take n \<cdot> (x @@ (t \<leadsto> y1)) \<sqsubseteq> seq_take n \<cdot> (x @@ (t \<leadsto> y2)))"
   786   apply (rule_tac x="x" in Seq_induct)
   786   apply (rule_tac x="x" in Seq_induct)
   787   apply simp_all
   787   apply simp_all
   788   apply (intro strip)
   788   apply (intro strip)
   789   apply (case_tac "n")
   789   apply (case_tac "n")
   790   apply auto
   790   apply auto
   791   apply (case_tac "n")
   791   apply (case_tac "n")
   792   apply auto
   792   apply auto
   793   done
   793   done
   794 
   794 
   795 lemma take_reduction_less:
   795 lemma take_reduction_less:
   796   "x = y \<Longrightarrow> s = t \<Longrightarrow> (\<And>k. k < n \<Longrightarrow> seq_take k $ y1 \<sqsubseteq> seq_take k $ y2) \<Longrightarrow>
   796   "x = y \<Longrightarrow> s = t \<Longrightarrow> (\<And>k. k < n \<Longrightarrow> seq_take k \<cdot> y1 \<sqsubseteq> seq_take k \<cdot> y2) \<Longrightarrow>
   797     seq_take n $ (x @@ (s \<leadsto> y1)) \<sqsubseteq> seq_take n $ (y @@ (t \<leadsto> y2))"
   797     seq_take n \<cdot> (x @@ (s \<leadsto> y1)) \<sqsubseteq> seq_take n \<cdot> (y @@ (t \<leadsto> y2))"
   798   by (auto intro!: take_reduction_less1 [rule_format])
   798   by (auto intro!: take_reduction_less1 [rule_format])
   799 
   799 
   800 lemma take_lemma_less1:
   800 lemma take_lemma_less1:
   801   assumes "\<And>n. seq_take n $ s1 \<sqsubseteq> seq_take n $ s2"
   801   assumes "\<And>n. seq_take n \<cdot> s1 \<sqsubseteq> seq_take n \<cdot> s2"
   802   shows "s1 \<sqsubseteq> s2"
   802   shows "s1 \<sqsubseteq> s2"
   803   apply (rule_tac t="s1" in seq.reach [THEN subst])
   803   apply (rule_tac t="s1" in seq.reach [THEN subst])
   804   apply (rule_tac t="s2" in seq.reach [THEN subst])
   804   apply (rule_tac t="s2" in seq.reach [THEN subst])
   805   apply (rule lub_mono)
   805   apply (rule lub_mono)
   806   apply (rule seq.chain_take [THEN ch2ch_Rep_cfunL])
   806   apply (rule seq.chain_take [THEN ch2ch_Rep_cfunL])
   807   apply (rule seq.chain_take [THEN ch2ch_Rep_cfunL])
   807   apply (rule seq.chain_take [THEN ch2ch_Rep_cfunL])
   808   apply (rule assms)
   808   apply (rule assms)
   809   done
   809   done
   810 
   810 
   811 lemma take_lemma_less: "(\<forall>n. seq_take n $ x \<sqsubseteq> seq_take n $ x') \<longleftrightarrow> x \<sqsubseteq> x'"
   811 lemma take_lemma_less: "(\<forall>n. seq_take n \<cdot> x \<sqsubseteq> seq_take n \<cdot> x') \<longleftrightarrow> x \<sqsubseteq> x'"
   812   apply (rule iffI)
   812   apply (rule iffI)
   813   apply (rule take_lemma_less1)
   813   apply (rule take_lemma_less1)
   814   apply auto
   814   apply auto
   815   apply (erule monofun_cfun_arg)
   815   apply (erule monofun_cfun_arg)
   816   done
   816   done
   826   using assms by (cases "Forall Q x") (auto dest!: divide_Seq3)
   826   using assms by (cases "Forall Q x") (auto dest!: divide_Seq3)
   827 
   827 
   828 lemma take_lemma_principle2:
   828 lemma take_lemma_principle2:
   829   assumes "\<And>s. Forall Q s \<Longrightarrow> A s \<Longrightarrow> f s = g s"
   829   assumes "\<And>s. Forall Q s \<Longrightarrow> A s \<Longrightarrow> f s = g s"
   830     and "\<And>s1 s2 y. Forall Q s1 \<Longrightarrow> Finite s1 \<Longrightarrow> \<not> Q y \<Longrightarrow> A (s1 @@ y \<leadsto> s2) \<Longrightarrow>
   830     and "\<And>s1 s2 y. Forall Q s1 \<Longrightarrow> Finite s1 \<Longrightarrow> \<not> Q y \<Longrightarrow> A (s1 @@ y \<leadsto> s2) \<Longrightarrow>
   831       \<forall>n. seq_take n $ (f (s1 @@ y \<leadsto> s2)) = seq_take n $ (g (s1 @@ y \<leadsto> s2))"
   831       \<forall>n. seq_take n \<cdot> (f (s1 @@ y \<leadsto> s2)) = seq_take n \<cdot> (g (s1 @@ y \<leadsto> s2))"
   832   shows "A x \<longrightarrow> f x = g x"
   832   shows "A x \<longrightarrow> f x = g x"
   833   using assms
   833   using assms
   834   apply (cases "Forall Q x")
   834   apply (cases "Forall Q x")
   835   apply (auto dest!: divide_Seq3)
   835   apply (auto dest!: divide_Seq3)
   836   apply (rule seq.take_lemma)
   836   apply (rule seq.take_lemma)
   850 \<close>
   850 \<close>
   851 
   851 
   852 lemma take_lemma_induct:
   852 lemma take_lemma_induct:
   853   assumes "\<And>s. Forall Q s \<Longrightarrow> A s \<Longrightarrow> f s = g s"
   853   assumes "\<And>s. Forall Q s \<Longrightarrow> A s \<Longrightarrow> f s = g s"
   854     and "\<And>s1 s2 y n.
   854     and "\<And>s1 s2 y n.
   855       \<forall>t. A t \<longrightarrow> seq_take n $ (f t) = seq_take n $ (g t) \<Longrightarrow>
   855       \<forall>t. A t \<longrightarrow> seq_take n \<cdot> (f t) = seq_take n \<cdot> (g t) \<Longrightarrow>
   856       Forall Q s1 \<Longrightarrow> Finite s1 \<Longrightarrow> \<not> Q y \<Longrightarrow> A (s1 @@ y \<leadsto> s2) \<Longrightarrow>
   856       Forall Q s1 \<Longrightarrow> Finite s1 \<Longrightarrow> \<not> Q y \<Longrightarrow> A (s1 @@ y \<leadsto> s2) \<Longrightarrow>
   857       seq_take (Suc n) $ (f (s1 @@ y \<leadsto> s2)) =
   857       seq_take (Suc n) \<cdot> (f (s1 @@ y \<leadsto> s2)) =
   858       seq_take (Suc n) $ (g (s1 @@ y \<leadsto> s2))"
   858       seq_take (Suc n) \<cdot> (g (s1 @@ y \<leadsto> s2))"
   859   shows "A x \<longrightarrow> f x = g x"
   859   shows "A x \<longrightarrow> f x = g x"
   860   apply (insert assms)
   860   apply (insert assms)
   861   apply (rule impI)
   861   apply (rule impI)
   862   apply (rule seq.take_lemma)
   862   apply (rule seq.take_lemma)
   863   apply (rule mp)
   863   apply (rule mp)
   873 
   873 
   874 
   874 
   875 lemma take_lemma_less_induct:
   875 lemma take_lemma_less_induct:
   876   assumes "\<And>s. Forall Q s \<Longrightarrow> A s \<Longrightarrow> f s = g s"
   876   assumes "\<And>s. Forall Q s \<Longrightarrow> A s \<Longrightarrow> f s = g s"
   877     and "\<And>s1 s2 y n.
   877     and "\<And>s1 s2 y n.
   878       \<forall>t m. m < n \<longrightarrow> A t \<longrightarrow> seq_take m $ (f t) = seq_take m $ (g t) \<Longrightarrow>
   878       \<forall>t m. m < n \<longrightarrow> A t \<longrightarrow> seq_take m \<cdot> (f t) = seq_take m \<cdot> (g t) \<Longrightarrow>
   879       Forall Q s1 \<Longrightarrow> Finite s1 \<Longrightarrow> \<not> Q y \<Longrightarrow> A (s1 @@ y \<leadsto> s2) \<Longrightarrow>
   879       Forall Q s1 \<Longrightarrow> Finite s1 \<Longrightarrow> \<not> Q y \<Longrightarrow> A (s1 @@ y \<leadsto> s2) \<Longrightarrow>
   880       seq_take n $ (f (s1 @@ y \<leadsto> s2)) =
   880       seq_take n \<cdot> (f (s1 @@ y \<leadsto> s2)) =
   881       seq_take n $ (g (s1 @@ y \<leadsto> s2))"
   881       seq_take n \<cdot> (g (s1 @@ y \<leadsto> s2))"
   882   shows "A x \<longrightarrow> f x = g x"
   882   shows "A x \<longrightarrow> f x = g x"
   883   apply (insert assms)
   883   apply (insert assms)
   884   apply (rule impI)
   884   apply (rule impI)
   885   apply (rule seq.take_lemma)
   885   apply (rule seq.take_lemma)
   886   apply (rule mp)
   886   apply (rule mp)
   897 
   897 
   898 lemma take_lemma_in_eq_out:
   898 lemma take_lemma_in_eq_out:
   899   assumes "A UU \<Longrightarrow> f UU = g UU"
   899   assumes "A UU \<Longrightarrow> f UU = g UU"
   900     and "A nil \<Longrightarrow> f nil = g nil"
   900     and "A nil \<Longrightarrow> f nil = g nil"
   901     and "\<And>s y n.
   901     and "\<And>s y n.
   902       \<forall>t. A t \<longrightarrow> seq_take n $ (f t) = seq_take n $ (g t) \<Longrightarrow> A (y \<leadsto> s) \<Longrightarrow>
   902       \<forall>t. A t \<longrightarrow> seq_take n \<cdot> (f t) = seq_take n \<cdot> (g t) \<Longrightarrow> A (y \<leadsto> s) \<Longrightarrow>
   903       seq_take (Suc n) $ (f (y \<leadsto> s)) =
   903       seq_take (Suc n) \<cdot> (f (y \<leadsto> s)) =
   904       seq_take (Suc n) $ (g (y \<leadsto> s))"
   904       seq_take (Suc n) \<cdot> (g (y \<leadsto> s))"
   905   shows "A x \<longrightarrow> f x = g x"
   905   shows "A x \<longrightarrow> f x = g x"
   906   apply (insert assms)
   906   apply (insert assms)
   907   apply (rule impI)
   907   apply (rule impI)
   908   apply (rule seq.take_lemma)
   908   apply (rule seq.take_lemma)
   909   apply (rule mp)
   909   apply (rule mp)
   926 
   926 
   927 (*In general: How to do this case without the same adm problems
   927 (*In general: How to do this case without the same adm problems
   928   as for the entire proof?*)
   928   as for the entire proof?*)
   929 lemma Filter_lemma1:
   929 lemma Filter_lemma1:
   930   "Forall (\<lambda>x. \<not> (P x \<and> Q x)) s \<longrightarrow>
   930   "Forall (\<lambda>x. \<not> (P x \<and> Q x)) s \<longrightarrow>
   931     Filter P $ (Filter Q $ s) = Filter (\<lambda>x. P x \<and> Q x) $ s"
   931     Filter P \<cdot> (Filter Q \<cdot> s) = Filter (\<lambda>x. P x \<and> Q x) \<cdot> s"
   932   apply (rule_tac x="s" in Seq_induct)
   932   apply (rule_tac x="s" in Seq_induct)
   933   apply (simp add: Forall_def sforall_def)
   933   apply (simp add: Forall_def sforall_def)
   934   apply simp_all
   934   apply simp_all
   935   done
   935   done
   936 
   936 
   937 lemma Filter_lemma2: "Finite s \<Longrightarrow>
   937 lemma Filter_lemma2: "Finite s \<Longrightarrow>
   938   Forall (\<lambda>x. \<not> P x \<or> \<not> Q x) s \<longrightarrow> Filter P $ (Filter Q $ s) = nil"
   938   Forall (\<lambda>x. \<not> P x \<or> \<not> Q x) s \<longrightarrow> Filter P \<cdot> (Filter Q \<cdot> s) = nil"
   939   by (erule Seq_Finite_ind) simp_all
   939   by (erule Seq_Finite_ind) simp_all
   940 
   940 
   941 lemma Filter_lemma3: "Finite s \<Longrightarrow>
   941 lemma Filter_lemma3: "Finite s \<Longrightarrow>
   942   Forall (\<lambda>x. \<not> P x \<or> \<not> Q x) s \<longrightarrow> Filter (\<lambda>x. P x \<and> Q x) $ s = nil"
   942   Forall (\<lambda>x. \<not> P x \<or> \<not> Q x) s \<longrightarrow> Filter (\<lambda>x. P x \<and> Q x) \<cdot> s = nil"
   943   by (erule Seq_Finite_ind) simp_all
   943   by (erule Seq_Finite_ind) simp_all
   944 
   944 
   945 lemma FilterPQ_takelemma: "Filter P $ (Filter Q $ s) = Filter (\<lambda>x. P x \<and> Q x) $ s"
   945 lemma FilterPQ_takelemma: "Filter P \<cdot> (Filter Q \<cdot> s) = Filter (\<lambda>x. P x \<and> Q x) \<cdot> s"
   946   apply (rule_tac A1="\<lambda>x. True" and Q1="\<lambda>x. \<not> (P x \<and> Q x)" and x1="s" in
   946   apply (rule_tac A1="\<lambda>x. True" and Q1="\<lambda>x. \<not> (P x \<and> Q x)" and x1="s" in
   947     take_lemma_induct [THEN mp])
   947     take_lemma_induct [THEN mp])
   948   (*better support for A = \<lambda>x. True*)
   948   (*better support for A = \<lambda>x. True*)
   949   apply (simp add: Filter_lemma1)
   949   apply (simp add: Filter_lemma1)
   950   apply (simp add: Filter_lemma2 Filter_lemma3)
   950   apply (simp add: Filter_lemma2 Filter_lemma3)
   954 declare FilterPQ [simp]
   954 declare FilterPQ [simp]
   955 
   955 
   956 
   956 
   957 subsubsection \<open>Alternative Proof of \<open>MapConc\<close>\<close>
   957 subsubsection \<open>Alternative Proof of \<open>MapConc\<close>\<close>
   958 
   958 
   959 lemma MapConc_takelemma: "Map f $ (x @@ y) = (Map f $ x) @@ (Map f $ y)"
   959 lemma MapConc_takelemma: "Map f \<cdot> (x @@ y) = (Map f \<cdot> x) @@ (Map f \<cdot> y)"
   960   apply (rule_tac A1="\<lambda>x. True" and x1="x" in take_lemma_in_eq_out [THEN mp])
   960   apply (rule_tac A1="\<lambda>x. True" and x1="x" in take_lemma_in_eq_out [THEN mp])
   961   apply auto
   961   apply auto
   962   done
   962   done
   963 
   963 
   964 ML \<open>
   964 ML \<open>
  1015 method_setup pair_induct =
  1015 method_setup pair_induct =
  1016   \<open>Scan.lift Args.embedded --
  1016   \<open>Scan.lift Args.embedded --
  1017     Scan.optional ((Scan.lift (Args.$$$ "simp" -- Args.colon) |-- Attrib.thms)) []
  1017     Scan.optional ((Scan.lift (Args.$$$ "simp" -- Args.colon) |-- Attrib.thms)) []
  1018     >> (fn (s, rws) => fn ctxt => SIMPLE_METHOD' (pair_induct_tac ctxt s rws))\<close>
  1018     >> (fn (s, rws) => fn ctxt => SIMPLE_METHOD' (pair_induct_tac ctxt s rws))\<close>
  1019 
  1019 
  1020 lemma Mapnil: "Map f $ s = nil \<longleftrightarrow> s = nil"
  1020 lemma Mapnil: "Map f \<cdot> s = nil \<longleftrightarrow> s = nil"
  1021   by (Seq_case_simp s)
  1021   by (Seq_case_simp s)
  1022 
  1022 
  1023 lemma MapUU: "Map f $ s = UU \<longleftrightarrow> s = UU"
  1023 lemma MapUU: "Map f \<cdot> s = UU \<longleftrightarrow> s = UU"
  1024   by (Seq_case_simp s)
  1024   by (Seq_case_simp s)
  1025 
  1025 
  1026 lemma MapTL: "Map f $ (TL $ s) = TL $ (Map f $ s)"
  1026 lemma MapTL: "Map f \<cdot> (TL \<cdot> s) = TL \<cdot> (Map f \<cdot> s)"
  1027   by (Seq_induct s)
  1027   by (Seq_induct s)
  1028 
  1028 
  1029 end
  1029 end