src/HOL/Data_Structures/Define_Time_Function.ML
changeset 81358 91b008474f1b
parent 81289 1eddc169baea
child 81519 cdc43c0fdbfc
equal deleted inserted replaced
81357:21a493abde0f 81358:91b008474f1b
   249       constc {ctxt = ctxt, origins = origin, f = walk ctxt origin conv} c
   249       constc {ctxt = ctxt, origins = origin, f = walk ctxt origin conv} c
   250 fun Ifunc (wctxt: term wctxt) t args = list_comb (#f wctxt t,map (#f wctxt) args)
   250 fun Ifunc (wctxt: term wctxt) t args = list_comb (#f wctxt t,map (#f wctxt) args)
   251 val Iconst = K I
   251 val Iconst = K I
   252 fun Iif (wctxt: term wctxt) T cond tt tf =
   252 fun Iif (wctxt: term wctxt) T cond tt tf =
   253   Const (@{const_name "HOL.If"}, T) $ (#f wctxt cond) $ (#f wctxt tt) $ (#f wctxt tf)
   253   Const (@{const_name "HOL.If"}, T) $ (#f wctxt cond) $ (#f wctxt tt) $ (#f wctxt tf)
   254 fun Icase (wctxt: term wctxt) t cs = list_comb (#f wctxt t,map (#f wctxt) cs)
   254 fun Icase (wctxt: term wctxt) t cs = list_comb
       
   255   (#f wctxt t,map (fn c => c |> Term.strip_abs_eta (c |> fastype_of |> strip_type |> fst |> length) ||> #f wctxt |> list_abs) cs)
   255 fun Ilet (wctxt: term wctxt) lT exp abs t =
   256 fun Ilet (wctxt: term wctxt) lT exp abs t =
   256   Const (@{const_name "HOL.Let"},lT) $ (#f wctxt exp) $ list_abs (abs, #f wctxt t)
   257   Const (@{const_name "HOL.Let"}, lT) $ (#f wctxt exp) $ list_abs (abs, #f wctxt t)
   257 
   258 
   258 (* 1. Fix all terms *)
   259 (* 1. Fix all terms *)
   259 (* Exchange Var in types and terms to Free *)
   260 (* Exchange Var in types and terms to Free *)
   260 fun freeTerms (Var(ixn,T)) = Free (fst ixn, T)
   261 fun freeTerms (Var(ixn,T)) = Free (fst ixn, T)
   261   | freeTerms t = t
   262   | freeTerms t = t
   287 fun fixTerms ctxt (term: term list) (fixedNum: int) (t as pT $ (eq $ l $ r)) =
   288 fun fixTerms ctxt (term: term list) (fixedNum: int) (t as pT $ (eq $ l $ r)) =
   288   let
   289   let
   289     val _ = check_args "args" (strip_comb (get_l t))
   290     val _ = check_args "args" (strip_comb (get_l t))
   290     val l' = shortApp fixedNum (strip_comb l) |> list_comb
   291     val l' = shortApp fixedNum (strip_comb l) |> list_comb
   291     val shortOriginFunc' = shortOriginFunc (term |> map (fst o strip_comb)) fixedNum
   292     val shortOriginFunc' = shortOriginFunc (term |> map (fst o strip_comb)) fixedNum
       
   293     val consts = Proof_Context.consts_of ctxt
       
   294     val net = Consts.revert_abbrevs consts ["internal"] |> hd |> Item_Net.content
       
   295                 (* filter out consts *)
       
   296               |> filter (is_Const o fst o strip_comb o fst)
       
   297                 (* filter out abbreviations for locales *)
       
   298               |> filter (fn n => "local"
       
   299                   = (n |> snd |> strip_comb |> fst |> dest_Const_name |> split_name |> hd))
       
   300               |> filter (fn n => (n |> fst |> strip_comb |> fst |> dest_Const_name |> split_name |> List.last) =
       
   301                 (n |> snd |> strip_comb |> fst |> dest_Const_name |> split_name |> List.last))
       
   302               |> map (fst #> strip_comb #>> dest_Const_name ##> length)
       
   303     fun n_abbrev (Const (nm,_)) =
       
   304     let
       
   305       val f = filter (fn n => fst n = nm) net
       
   306     in
       
   307       if length f >= 1 then f |> hd |> snd else 0
       
   308     end
       
   309       | n_abbrev _ = 0
   292     val r' = walk ctxt term {
   310     val r' = walk ctxt term {
   293           funcc = (fn wctxt => fn t => fn args =>
   311           funcc = (fn wctxt => fn t => fn args =>
   294               (check_args "func" (t,args); (#f wctxt t, map (#f wctxt) args) |> shortOriginFunc' |> list_comb)),
   312             let
       
   313               val n_abb = n_abbrev t
       
   314               val t = case t of Const (nm,T) => Const (nm, T |> strip_type |>> drop n_abb |> (op --->))
       
   315                               | t => t
       
   316               val args = drop n_abb args           
       
   317             in
       
   318               (check_args "func" (t,args);
       
   319                (#f wctxt t, map (#f wctxt) args) |> shortOriginFunc' |> list_comb)
       
   320             end),
   295           constc = fn wctxt => map_abs (#f wctxt),
   321           constc = fn wctxt => map_abs (#f wctxt),
   296           ifc = Iif,
   322           ifc = Iif,
   297           casec = fixCasec,
   323           casec = fixCasec,
   298           letc = (fn wctxt => fn expT => fn exp => fn abs => fn t =>
   324           letc = (fn wctxt => fn expT => fn exp => fn abs => fn t =>
   299               (Const (@{const_name "HOL.Let"},expT) $ (#f wctxt exp) $ list_abs (abs, #f wctxt t)))
   325               (Const (@{const_name "HOL.Let"},expT) $ (#f wctxt exp) $ list_abs (abs, #f wctxt t)))
   726             handle (ERROR _) => NONE
   752             handle (ERROR _) => NONE
   727         of SOME _ => error ("Timing function already declared: " ^ (Term.term_name (hd term)))
   753         of SOME _ => error ("Timing function already declared: " ^ (Term.term_name (hd term)))
   728          | NONE => ()
   754          | NONE => ()
   729 
   755 
   730     (* Number of terms fixed by locale *)
   756     (* Number of terms fixed by locale *)
   731     val fixedNum = term
   757     val fixedNum = term |> hd
   732       |> hd
       
   733       |> strip_comb |> snd
   758       |> strip_comb |> snd
   734       |> length
   759       |> length
   735 
   760 
   736     (* 1. Fix all terms *)
   761     (* 1. Fix all terms *)
   737     (* Exchange Var in types and terms to Free and check constraints *)
   762     (* Exchange Var in types and terms to Free and check constraints *)