src/HOL/Boogie/Tools/boogie_loader.ML
changeset 47155 ade3fc826af3
parent 44241 7943b69f0188
equal deleted inserted replaced
47154:2c357e2b8436 47155:ade3fc826af3
    60   end
    60   end
    61 
    61 
    62 
    62 
    63 datatype attribute_value = StringValue of string | TermValue of term
    63 datatype attribute_value = StringValue of string | TermValue of term
    64 
    64 
       
    65 
       
    66 fun mk_distinct [] = @{const HOL.True}
       
    67   | mk_distinct [_] = @{const HOL.True}
       
    68   | mk_distinct (t :: ts) =
       
    69       let
       
    70         fun mk_noteq u u' =
       
    71           HOLogic.mk_conj (HOLogic.mk_not (HOLogic.mk_eq (t, u)), u')
       
    72       in fold_rev mk_noteq ts (mk_distinct ts) end
    65 
    73 
    66 
    74 
    67 local
    75 local
    68   fun lookup_type_name thy name arity =
    76   fun lookup_type_name thy name arity =
    69     let val intern = Sign.intern_type thy name
    77     let val intern = Sign.intern_type thy name
   189       fun is_unique (name, (([], _), atts)) =
   197       fun is_unique (name, (([], _), atts)) =
   190             (case AList.lookup (op =) atts "unique" of
   198             (case AList.lookup (op =) atts "unique" of
   191               SOME _ => Symtab.lookup fds name
   199               SOME _ => Symtab.lookup fds name
   192             | NONE => NONE)
   200             | NONE => NONE)
   193         | is_unique _ = NONE
   201         | is_unique _ = NONE
   194       fun mk_unique_axiom T ts =
       
   195         Const (@{const_name distinct}, HOLogic.listT T --> @{typ bool}) $
       
   196           HOLogic.mk_list T ts
       
   197     in
   202     in
   198       map_filter is_unique fns
   203       map_filter is_unique fns
   199       |> map (swap o Term.dest_Const)
   204       |> map (swap o Term.dest_Const)
   200       |> AList.group (op =)
   205       |> AList.group (op =)
   201       |> map (fn (T, ns) => mk_unique_axiom T (map (Const o rpair T) ns))
   206       |> map (fn (T, ns) => mk_distinct (map (Const o rpair T) ns))
   202     end
   207     end
   203 in
   208 in
   204 fun declare_functions verbose fns =
   209 fun declare_functions verbose fns =
   205   fold_map declare fns #>> split_list #-> (fn (fds, logs) =>
   210   fold_map declare fns #>> split_list #-> (fn (fds, logs) =>
   206   log verbose "Loaded constants:" logs #>
   211   log verbose "Loaded constants:" logs #>
   382   fun mk_nary _ t [] = t
   387   fun mk_nary _ t [] = t
   383     | mk_nary f _ ts = uncurry (fold_rev f) (split_last ts)
   388     | mk_nary f _ ts = uncurry (fold_rev f) (split_last ts)
   384 
   389 
   385   fun mk_list T = HOLogic.mk_list T
   390   fun mk_list T = HOLogic.mk_list T
   386 
   391 
   387   fun mk_distinct T ts =
       
   388     Const (@{const_name distinct}, HOLogic.listT T --> @{typ bool}) $
       
   389       mk_list T ts
       
   390 
       
   391   fun quant name f = scan_line name (num -- num -- num) >> pair f
   392   fun quant name f = scan_line name (num -- num -- num) >> pair f
   392   val quants =
   393   val quants =
   393     quant "forall" HOLogic.all_const ||
   394     quant "forall" HOLogic.all_const ||
   394     quant "exists" HOLogic.exists_const ||
   395     quant "exists" HOLogic.exists_const ||
   395     scan_fail "illegal quantifier kind"
   396     scan_fail "illegal quantifier kind"
   504         let val T = Term.fastype_of t1
   505         let val T = Term.fastype_of t1
   505         in
   506         in
   506           Const (@{const_name If}, [@{typ bool}, T, T] ---> T) $ c $ t1 $ t2
   507           Const (@{const_name If}, [@{typ bool}, T, T] ---> T) $ c $ t1 $ t2
   507         end) ||
   508         end) ||
   508       binexp "implies" (binop @{term HOL.implies}) ||
   509       binexp "implies" (binop @{term HOL.implies}) ||
   509       scan_line "distinct" num :|-- scan_count exp >>
   510       scan_line "distinct" num :|-- scan_count exp >> mk_distinct ||
   510         (fn [] => @{term True}
       
   511           | ts as (t :: _) => mk_distinct (Term.fastype_of t) ts) ||
       
   512       binexp "=" HOLogic.mk_eq ||
   511       binexp "=" HOLogic.mk_eq ||
   513       scan_line "var" var_name -- typ tds >> Free ||
   512       scan_line "var" var_name -- typ tds >> Free ||
   514       scan_line "fun" (str -- num) :|-- (fn (name, arity) =>
   513       scan_line "fun" (str -- num) :|-- (fn (name, arity) =>
   515         scan_lookup "constant" fds name -- scan_count exp arity >>
   514         scan_lookup "constant" fds name -- scan_count exp arity >>
   516         Term.list_comb) ||
   515         Term.list_comb) ||