diff -r 5cb9fd414e92 -r a424accf705d src/HOL/Data_Structures/Sorting.thy --- a/src/HOL/Data_Structures/Sorting.thy Mon Jun 03 20:56:41 2024 +0100 +++ b/src/HOL/Data_Structures/Sorting.thy Tue Jun 04 11:21:04 2024 +0200 @@ -6,6 +6,7 @@ imports Complex_Main "HOL-Library.Multiset" + Define_Time_Function begin hide_const List.insort @@ -45,26 +46,8 @@ subsubsection "Time Complexity" -text \We count the number of function calls.\ - -text\ -\insort1 x [] = [x]\ -\insort1 x (y#ys) = - (if x \ y then x#y#ys else y#(insort1 x ys))\ -\ -fun T_insort1 :: "'a::linorder \ 'a list \ nat" where - "T_insort1 x [] = 1" | - "T_insort1 x (y#ys) = - (if x \ y then 0 else T_insort1 x ys) + 1" - -text\ -\insort [] = []\ -\insort (x#xs) = insort1 x (insort xs)\ -\ -fun T_insort :: "'a::linorder list \ nat" where - "T_insort [] = 1" | - "T_insort (x#xs) = T_insort xs + T_insort1 x (insort xs) + 1" - +time_fun insort1 +time_fun insort lemma T_insort1_length: "T_insort1 x xs \ length xs + 1" by (induction xs) auto