src/HOL/Data_Structures/Define_Time_Function.thy
author nipkow
Sun, 24 Mar 2024 14:50:47 +0100
changeset 79969 4aeb25ba90f3
parent 79490 b287510a4202
child 79973 7bbb0d65ce72
permissions -rw-r--r--
more uniform command names
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
79490
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     1
(*
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     2
Author: Jonas Stahl
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     3
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     4
Automatic definition of running time functions from HOL functions
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     5
following the translation described in Section 1.5, Running Time, of the book
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     6
Functional Data Structures and Algorithms. A Proof Assistant Approach.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     7
*)
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     8
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
     9
theory Define_Time_Function
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    10
  imports Main
79969
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    11
  keywords "time_fun" :: thy_decl
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    12
    and    "time_function" :: thy_goal
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    13
    and    "time_definition" :: thy_goal
79490
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    14
    and    "equations"
79969
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    15
    and    "time_fun_0" :: thy_decl
79490
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    16
begin
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    17
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    18
ML_file Define_Time_0.ML
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    19
ML_file Define_Time_Function.ML
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    20
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    21
declare [[time_prefix = "T_"]]
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    22
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    23
text \<open>The pre-defined functions below are assumed to have constant running time.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    24
In fact, we make that constant 0.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    25
This does not change the asymptotic running time of user-defined functions using the
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    26
pre-defined functions because 1 is added for every user-defined function call.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    27
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    28
Note: Many of the functions below are polymorphic and reside in type classes.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    29
The constant-time assumption is justified only for those types where the hardware offers
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    30
suitable support, e.g. numeric types. The argument size is implicitly bounded, too.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    31
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    32
The constant-time assumption for \<open>(=)\<close> is justified for recursive data types such as lists and trees
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    33
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>
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    34
79969
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    35
time_fun_0 "(+)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    36
time_fun_0 "(-)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    37
time_fun_0 "(*)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    38
time_fun_0 "(/)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    39
time_fun_0 "(div)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    40
time_fun_0 "(<)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    41
time_fun_0 "(\<le>)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    42
time_fun_0 "Not"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    43
time_fun_0 "(\<and>)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    44
time_fun_0 "(\<or>)"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    45
time_fun_0 "Num.numeral_class.numeral"
4aeb25ba90f3 more uniform command names
nipkow
parents: 79490
diff changeset
    46
time_fun_0 "(=)"
79490
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    47
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    48
end