src/HOL/List.thy
changeset 29856 984191be0357
parent 29829 9acb915a62fa
child 29927 ae8f42c245b2
equal deleted inserted replaced
29855:e0ab6cf95539 29856:984191be0357
   507 of those of the other list and there are fewer Cons's in one than the other.
   507 of those of the other list and there are fewer Cons's in one than the other.
   508 *)
   508 *)
   509 
   509 
   510 let
   510 let
   511 
   511 
   512 fun len (Const("List.list.Nil",_)) acc = acc
   512 fun len (Const(@{const_name Nil},_)) acc = acc
   513   | len (Const("List.list.Cons",_) $ _ $ xs) (ts,n) = len xs (ts,n+1)
   513   | len (Const(@{const_name Cons},_) $ _ $ xs) (ts,n) = len xs (ts,n+1)
   514   | len (Const("List.append",_) $ xs $ ys) acc = len xs (len ys acc)
   514   | len (Const(@{const_name append},_) $ xs $ ys) acc = len xs (len ys acc)
   515   | len (Const("List.rev",_) $ xs) acc = len xs acc
   515   | len (Const(@{const_name rev},_) $ xs) acc = len xs acc
   516   | len (Const("List.map",_) $ _ $ xs) acc = len xs acc
   516   | len (Const(@{const_name map},_) $ _ $ xs) acc = len xs acc
   517   | len t (ts,n) = (t::ts,n);
   517   | len t (ts,n) = (t::ts,n);
   518 
   518 
   519 fun list_neq _ ss ct =
   519 fun list_neq _ ss ct =
   520   let
   520   let
   521     val (Const(_,eqT) $ lhs $ rhs) = Thm.term_of ct;
   521     val (Const(_,eqT) $ lhs $ rhs) = Thm.term_of ct;
   637 *}
   637 *}
   638 
   638 
   639 ML {*
   639 ML {*
   640 local
   640 local
   641 
   641 
   642 fun last (cons as Const("List.list.Cons",_) $ _ $ xs) =
   642 fun last (cons as Const(@{const_name Cons},_) $ _ $ xs) =
   643   (case xs of Const("List.list.Nil",_) => cons | _ => last xs)
   643   (case xs of Const(@{const_name Nil},_) => cons | _ => last xs)
   644   | last (Const("List.append",_) $ _ $ ys) = last ys
   644   | last (Const(@{const_name append},_) $ _ $ ys) = last ys
   645   | last t = t;
   645   | last t = t;
   646 
   646 
   647 fun list1 (Const("List.list.Cons",_) $ _ $ Const("List.list.Nil",_)) = true
   647 fun list1 (Const(@{const_name Cons},_) $ _ $ Const(@{const_name Nil},_)) = true
   648   | list1 _ = false;
   648   | list1 _ = false;
   649 
   649 
   650 fun butlast ((cons as Const("List.list.Cons",_) $ x) $ xs) =
   650 fun butlast ((cons as Const(@{const_name Cons},_) $ x) $ xs) =
   651   (case xs of Const("List.list.Nil",_) => xs | _ => cons $ butlast xs)
   651   (case xs of Const(@{const_name Nil},_) => xs | _ => cons $ butlast xs)
   652   | butlast ((app as Const("List.append",_) $ xs) $ ys) = app $ butlast ys
   652   | butlast ((app as Const(@{const_name append},_) $ xs) $ ys) = app $ butlast ys
   653   | butlast xs = Const("List.list.Nil",fastype_of xs);
   653   | butlast xs = Const(@{const_name Nil},fastype_of xs);
   654 
   654 
   655 val rearr_ss = HOL_basic_ss addsimps [@{thm append_assoc},
   655 val rearr_ss = HOL_basic_ss addsimps [@{thm append_assoc},
   656   @{thm append_Nil}, @{thm append_Cons}];
   656   @{thm append_Nil}, @{thm append_Cons}];
   657 
   657 
   658 fun list_eq ss (F as (eq as Const(_,eqT)) $ lhs $ rhs) =
   658 fun list_eq ss (F as (eq as Const(_,eqT)) $ lhs $ rhs) =
   661     fun rearr conv =
   661     fun rearr conv =
   662       let
   662       let
   663         val lhs1 = butlast lhs and rhs1 = butlast rhs;
   663         val lhs1 = butlast lhs and rhs1 = butlast rhs;
   664         val Type(_,listT::_) = eqT
   664         val Type(_,listT::_) = eqT
   665         val appT = [listT,listT] ---> listT
   665         val appT = [listT,listT] ---> listT
   666         val app = Const("List.append",appT)
   666         val app = Const(@{const_name append},appT)
   667         val F2 = eq $ (app$lhs1$lastl) $ (app$rhs1$lastr)
   667         val F2 = eq $ (app$lhs1$lastl) $ (app$rhs1$lastr)
   668         val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (F,F2));
   668         val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (F,F2));
   669         val thm = Goal.prove (Simplifier.the_context ss) [] [] eq
   669         val thm = Goal.prove (Simplifier.the_context ss) [] [] eq
   670           (K (simp_tac (Simplifier.inherit_context ss rearr_ss) 1));
   670           (K (simp_tac (Simplifier.inherit_context ss rearr_ss) 1));
   671       in SOME ((conv RS (thm RS trans)) RS eq_reflection) end;
   671       in SOME ((conv RS (thm RS trans)) RS eq_reflection) end;