src/Tools/isac/Knowledge/InsSort.thy
author Mathias Lehnfeld <s1210629013@students.fh-hagenberg.at>
Mon, 27 Jan 2014 21:49:27 +0100
changeset 55359 73dc85c025ab
parent 55339 cccd24e959ba
child 55363 d78bc1342183
permissions -rw-r--r--
cleanup, naming: 'KEStore_Elems' in Tests now 'Test_KEStore_Elems', 'store_pbts' now 'add_pbts'
     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 ML {*
    62 (** problem type **)
    63 
    64 store_pbt
    65  (prep_pbt @{theory "InsSort"}
    66  (["functional"]:pblID,
    67   [("#Given" ,["unsorted u_"]),
    68    ("#Find"  ,["sorted s_"])
    69   ],
    70   []));
    71 
    72 store_pbt
    73  (prep_pbt @{theory "InsSort"}
    74  (["inssort","functional"]:pblID,
    75   [("#Given" ,["unsorted u_"]),
    76    ("#Find"  ,["sorted s_"])
    77   ],
    78   []));
    79 *}
    80 setup {* KEStore_Elems.add_pbts
    81   [(prep_pbt @{theory "InsSort"}
    82       (["functional"]:pblID,
    83         [("#Given" ,["unsorted u_"]), ("#Find"  ,["sorted s_"])], [])),
    84     (prep_pbt @{theory "InsSort"}
    85       (["inssort","functional"]:pblID,
    86         [("#Given" ,["unsorted u_"]), ("#Find"  ,["sorted s_"])], []))] *}
    87 
    88 ML {*
    89 (** method, 
    90     todo: implementation needs extra object-level lists **)
    91 
    92 store_met
    93  (prep_met @{theory "Diff"}
    94  (["InsSort"],
    95    [],
    96    {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
    97     crls = Atools_rls, errpats = [], nrls = norm_Rational
    98     (*, asm_rls=[],asm_thm=[]*)}, "empty_script"));
    99 store_met
   100  (prep_met @{theory "InsSort"} (*test-version for [#1,#3,#2] only: see *.sml*)
   101  (["InsSort","sort"]:metID,
   102    [("#Given" ,["unsorted u_"]),
   103     ("#Find"  ,["sorted s_"])
   104     ],
   105    {rew_ord'="tless_true",rls'=eval_rls,calc = [], srls = e_rls, prls=e_rls,
   106     crls = eval_rls, errpats = [], nrls = norm_Rational},
   107    "Script Sort (u_::'a list) = (Rewrite_Set ins_sort False) u_"
   108   ));
   109 *}
   110 setup {* KEStore_Elems.add_rlss [("ins_sort", (Context.theory_name @{theory}, ins_sort))] *}
   111 
   112 end