79490
|
1 |
(*
|
|
2 |
Author: Jonas Stahl
|
|
3 |
|
|
4 |
Automatic definition of running time functions from HOL functions
|
|
5 |
following the translation described in Section 1.5, Running Time, of the book
|
|
6 |
Functional Data Structures and Algorithms. A Proof Assistant Approach.
|
|
7 |
*)
|
|
8 |
|
|
9 |
theory Define_Time_Function
|
|
10 |
imports Main
|
|
11 |
keywords "define_time_fun" :: thy_decl
|
|
12 |
and "define_time_function" :: thy_goal
|
|
13 |
and "equations"
|
|
14 |
and "define_time_0" :: thy_decl
|
|
15 |
begin
|
|
16 |
|
|
17 |
ML_file Define_Time_0.ML
|
|
18 |
ML_file Define_Time_Function.ML
|
|
19 |
|
|
20 |
declare [[time_prefix = "T_"]]
|
|
21 |
|
|
22 |
text \<open>The pre-defined functions below are assumed to have constant running time.
|
|
23 |
In fact, we make that constant 0.
|
|
24 |
This does not change the asymptotic running time of user-defined functions using the
|
|
25 |
pre-defined functions because 1 is added for every user-defined function call.
|
|
26 |
|
|
27 |
Note: Many of the functions below are polymorphic and reside in type classes.
|
|
28 |
The constant-time assumption is justified only for those types where the hardware offers
|
|
29 |
suitable support, e.g. numeric types. The argument size is implicitly bounded, too.
|
|
30 |
|
|
31 |
The constant-time assumption for \<open>(=)\<close> is justified for recursive data types such as lists and trees
|
|
32 |
as long as the comparison is of the form \<open>t = c\<close> where \<open>c\<close> is a constant term, for example \<open>xs = []\<close>.\<close>
|
|
33 |
|
|
34 |
define_time_0 "(+)"
|
|
35 |
define_time_0 "(-)"
|
|
36 |
define_time_0 "(*)"
|
|
37 |
define_time_0 "(/)"
|
|
38 |
define_time_0 "(div)"
|
|
39 |
define_time_0 "(<)"
|
|
40 |
define_time_0 "(\<le>)"
|
|
41 |
define_time_0 "Not"
|
|
42 |
define_time_0 "(\<and>)"
|
|
43 |
define_time_0 "(\<or>)"
|
|
44 |
define_time_0 "Num.numeral_class.numeral"
|
|
45 |
define_time_0 "(=)"
|
|
46 |
|
|
47 |
end |