src/Pure/thm.ML
changeset 46497 89ccf66aa73d
parent 46475 22eaaf4f00a3
child 47005 421760a1efe7
equal deleted inserted replaced
46496:b8920f3fd259 46497:89ccf66aa73d
    73   val dest_fun: cterm -> cterm
    73   val dest_fun: cterm -> cterm
    74   val dest_arg: cterm -> cterm
    74   val dest_arg: cterm -> cterm
    75   val dest_fun2: cterm -> cterm
    75   val dest_fun2: cterm -> cterm
    76   val dest_arg1: cterm -> cterm
    76   val dest_arg1: cterm -> cterm
    77   val dest_abs: string option -> cterm -> cterm * cterm
    77   val dest_abs: string option -> cterm -> cterm * cterm
    78   val capply: cterm -> cterm -> cterm
    78   val apply: cterm -> cterm -> cterm
    79   val cabs_name: string * cterm -> cterm -> cterm
    79   val lambda_name: string * cterm -> cterm -> cterm
    80   val cabs: cterm -> cterm -> cterm
    80   val lambda: cterm -> cterm -> cterm
    81   val adjust_maxidx_cterm: int -> cterm -> cterm
    81   val adjust_maxidx_cterm: int -> cterm -> cterm
    82   val incr_indexes_cterm: int -> cterm -> cterm
    82   val incr_indexes_cterm: int -> cterm -> cterm
    83   val match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list
    83   val match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list
    84   val first_order_match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list
    84   val first_order_match: cterm * cterm -> (ctyp * ctyp) list * (cterm * cterm) list
    85   val fold_terms: (term -> 'a -> 'a) -> thm -> 'a -> 'a
    85   val fold_terms: (term -> 'a -> 'a) -> thm -> 'a -> 'a
   257   | dest_abs _ ct = raise CTERM ("dest_abs", [ct]);
   257   | dest_abs _ ct = raise CTERM ("dest_abs", [ct]);
   258 
   258 
   259 
   259 
   260 (* constructors *)
   260 (* constructors *)
   261 
   261 
   262 fun capply
   262 fun apply
   263   (cf as Cterm {t = f, T = Type ("fun", [dty, rty]), maxidx = maxidx1, sorts = sorts1, ...})
   263   (cf as Cterm {t = f, T = Type ("fun", [dty, rty]), maxidx = maxidx1, sorts = sorts1, ...})
   264   (cx as Cterm {t = x, T, maxidx = maxidx2, sorts = sorts2, ...}) =
   264   (cx as Cterm {t = x, T, maxidx = maxidx2, sorts = sorts2, ...}) =
   265     if T = dty then
   265     if T = dty then
   266       Cterm {thy_ref = merge_thys0 cf cx,
   266       Cterm {thy_ref = merge_thys0 cf cx,
   267         t = f $ x,
   267         t = f $ x,
   268         T = rty,
   268         T = rty,
   269         maxidx = Int.max (maxidx1, maxidx2),
   269         maxidx = Int.max (maxidx1, maxidx2),
   270         sorts = Sorts.union sorts1 sorts2}
   270         sorts = Sorts.union sorts1 sorts2}
   271       else raise CTERM ("capply: types don't agree", [cf, cx])
   271       else raise CTERM ("apply: types don't agree", [cf, cx])
   272   | capply cf cx = raise CTERM ("capply: first arg is not a function", [cf, cx]);
   272   | apply cf cx = raise CTERM ("apply: first arg is not a function", [cf, cx]);
   273 
   273 
   274 fun cabs_name
   274 fun lambda_name
   275   (x, ct1 as Cterm {t = t1, T = T1, maxidx = maxidx1, sorts = sorts1, ...})
   275   (x, ct1 as Cterm {t = t1, T = T1, maxidx = maxidx1, sorts = sorts1, ...})
   276   (ct2 as Cterm {t = t2, T = T2, maxidx = maxidx2, sorts = sorts2, ...}) =
   276   (ct2 as Cterm {t = t2, T = T2, maxidx = maxidx2, sorts = sorts2, ...}) =
   277     let val t = Term.lambda_name (x, t1) t2 in
   277     let val t = Term.lambda_name (x, t1) t2 in
   278       Cterm {thy_ref = merge_thys0 ct1 ct2,
   278       Cterm {thy_ref = merge_thys0 ct1 ct2,
   279         t = t, T = T1 --> T2,
   279         t = t, T = T1 --> T2,
   280         maxidx = Int.max (maxidx1, maxidx2),
   280         maxidx = Int.max (maxidx1, maxidx2),
   281         sorts = Sorts.union sorts1 sorts2}
   281         sorts = Sorts.union sorts1 sorts2}
   282     end;
   282     end;
   283 
   283 
   284 fun cabs t u = cabs_name ("", t) u;
   284 fun lambda t u = lambda_name ("", t) u;
   285 
   285 
   286 
   286 
   287 (* indexes *)
   287 (* indexes *)
   288 
   288 
   289 fun adjust_maxidx_cterm i (ct as Cterm {thy_ref, t, T, maxidx, sorts}) =
   289 fun adjust_maxidx_cterm i (ct as Cterm {thy_ref, t, T, maxidx, sorts}) =
  1546               if clash then del_clashing false xs xs qs [] else qs
  1546               if clash then del_clashing false xs xs qs [] else qs
  1547           | del_clashing clash xs ys ((p as (x, y)) :: ps) qs =
  1547           | del_clashing clash xs ys ((p as (x, y)) :: ps) qs =
  1548               if member (op =) ys y
  1548               if member (op =) ys y
  1549               then del_clashing true (x :: xs) (x :: ys) ps qs
  1549               then del_clashing true (x :: xs) (x :: ys) ps qs
  1550               else del_clashing clash xs (y :: ys) ps (p :: qs);
  1550               else del_clashing clash xs (y :: ys) ps (p :: qs);
  1551         val al'' = del_clashing false unchanged unchanged al' [];        
  1551         val al'' = del_clashing false unchanged unchanged al' [];
  1552         fun rename (t as Var ((x, i), T)) =
  1552         fun rename (t as Var ((x, i), T)) =
  1553               (case AList.lookup (op =) al'' x of
  1553               (case AList.lookup (op =) al'' x of
  1554                  SOME y => Var ((y, i), T)
  1554                  SOME y => Var ((y, i), T)
  1555                | NONE => t)
  1555                | NONE => t)
  1556           | rename (Abs (x, T, t)) =
  1556           | rename (Abs (x, T, t)) =