src/Tools/isac/Knowledge/InsSort.thy
author Mathias Lehnfeld <s1210629013@students.fh-hagenberg.at>
Sat, 01 Feb 2014 16:44:45 +0100
changeset 55373 4f3f530f3cf6
parent 55363 d78bc1342183
child 55380 7be2ad0e4acb
permissions -rw-r--r--
ad 967c8a1eb6b1 (2): add functions accessing Theory_Data in parallel to those accessing 'mets = Unsynchronized.ref'
     1 (* 6.8.02 change to Isabelle2002 caused error -- thy excluded !
     2 
     3 Proving equations for primrec function(s) "InsSort.foldr" ...
     4 GC #1.17.30.54.345.21479:   (10 ms)
     5 *** Definition of InsSort.ins :: "['a::ord list, 'a::ord] => 'a::ord list"
     6 *** imposes additional sort constraints on the declared type of the constant
     7 *** The error(s) above occurred in definition "InsSort.ins.ins_list_def (@@@)"
     8 *)
     9 
    10 (* insertion sort, would need lists different from script-lists WN.11.00
    11 WN.7.5.03: -"- started with someList :: 'a list => unl, fun dest_list
    12 WN.8.5.03: error (@@@) remained with outcommenting foldr ?!?
    13 
    14 *)
    15 
    16 theory InsSort imports "../ProgLang/Script" begin
    17 
    18 consts
    19 
    20 (*foldr      :: [['a,'b] => 'a, 'b list, 'a] => 'a
    21 WN.8.5.03: already defined in Isabelle2002 (instantiated by Typefix):
    22      "[[real, real] => real, real list, real] => real") : term
    23 
    24  val t = str2term "foldr";
    25 val t =
    26   Const
    27     ("List.foldr",
    28      "[[RealDef.real, RealDef.real] => RealDef.real, RealDef.real List.list,
    29       RealDef.real] => RealDef.real") : term
    30  *)
    31   ins        :: ['a list,'a] => 'a list
    32   sort       :: 'a list => 'a list
    33 
    34 (*descriptions, script-id*)
    35   unsorted   :: 'a list => unl
    36   sorted     :: 'a list => unl
    37 
    38 (*subproblem and script-name*)
    39   Ins'_sort  :: "['a list,  
    40 		    'a list] => 'a list"
    41                ("((Script Ins'_sort (_ =))//  
    42 		    (_))" 9)
    43   Sort       :: "['a list,  
    44 		    'a list] => 'a list"
    45                ("((Script Sort (_ =))//  
    46 		    (_))" 9)
    47 
    48 (*primrec
    49   foldr_base "foldr f [] a = a"
    50   foldr_rec  "foldr f (x#xs) a = foldr f xs (f a x)"
    51 *)
    52 
    53 rules
    54 
    55 (*primrec .. outcommented analoguous to ListC.thy*)
    56   ins_base   "ins [] a = [a]"
    57   ins_rec    "ins (x#xs) a = (if x < a then x#(ins xs a) else a#(x#xs))" 
    58  
    59   sort_def   "sort ls = foldr ins ls []"
    60 
    61 (** problem type **)
    62 setup {* KEStore_Elems.add_pbts
    63   [(prep_pbt @{theory "InsSort"}
    64       (["functional"]:pblID,
    65         [("#Given" ,["unsorted u_"]), ("#Find"  ,["sorted s_"])], [])),
    66     (prep_pbt @{theory "InsSort"}
    67       (["inssort","functional"]:pblID,
    68         [("#Given" ,["unsorted u_"]), ("#Find"  ,["sorted s_"])], []))] *}
    69 
    70 ML {*
    71 (** method, 
    72     todo: implementation needs extra object-level lists **)
    73 
    74 store_met
    75  (prep_met @{theory "Diff"}
    76  (["InsSort"],
    77    [],
    78    {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
    79     crls = Atools_rls, errpats = [], nrls = norm_Rational
    80     (*, asm_rls=[],asm_thm=[]*)}, "empty_script"));
    81 store_met
    82  (prep_met @{theory "InsSort"} (*test-version for [#1,#3,#2] only: see *.sml*)
    83  (["InsSort","sort"]:metID,
    84    [("#Given" ,["unsorted u_"]),
    85     ("#Find"  ,["sorted s_"])
    86     ],
    87    {rew_ord'="tless_true",rls'=eval_rls,calc = [], srls = e_rls, prls=e_rls,
    88     crls = eval_rls, errpats = [], nrls = norm_Rational},
    89    "Script Sort (u_::'a list) = (Rewrite_Set ins_sort False) u_"
    90   ));
    91 *}
    92 setup {* KEStore_Elems.add_mets
    93   [prep_met @{theory "Diff"}
    94       (["InsSort"], [],
    95         {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
    96           crls = Atools_rls, errpats = [], nrls = norm_Rational (*, asm_rls=[],asm_thm=[]*)},
    97         "empty_script"),
    98     prep_met @{theory "InsSort"} (*test-version for [#1,#3,#2] only: see *.sml*)
    99       (["InsSort","sort"]:metID,
   100         [("#Given" ,["unsorted u_"]), ("#Find"  ,["sorted s_"])],
   101       {rew_ord'="tless_true",rls'=eval_rls,calc = [], srls = e_rls, prls=e_rls, crls = eval_rls,
   102         errpats = [], nrls = norm_Rational},
   103       "Script Sort (u_::'a list) = (Rewrite_Set ins_sort False) u_")]
   104 *}
   105 setup {* KEStore_Elems.add_rlss [("ins_sort", (Context.theory_name @{theory}, ins_sort))] *}
   106 
   107 end