src/HOL/Data_Structures/Define_Time_Function.thy
author nipkow
Thu, 18 Jan 2024 14:30:27 +0100
changeset 79494 c7536609bb9b
parent 79490 b287510a4202
child 79969 4aeb25ba90f3
permissions -rw-r--r--
translation to time functions now with canonical let.
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
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    11
  keywords "define_time_fun" :: thy_decl
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    12
    and    "define_time_function" :: thy_goal
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    13
    and    "equations"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    14
    and    "define_time_0" :: thy_decl
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    15
begin
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    16
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    17
ML_file Define_Time_0.ML
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    18
ML_file Define_Time_Function.ML
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    19
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    20
declare [[time_prefix = "T_"]]
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    21
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    22
text \<open>The pre-defined functions below are assumed to have constant running time.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    23
In fact, we make that constant 0.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    24
This does not change the asymptotic running time of user-defined functions using the
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    25
pre-defined functions because 1 is added for every user-defined function call.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    26
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    27
Note: Many of the functions below are polymorphic and reside in type classes.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    28
The constant-time assumption is justified only for those types where the hardware offers
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    29
suitable support, e.g. numeric types. The argument size is implicitly bounded, too.
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    30
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    31
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
    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>
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    33
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    34
define_time_0 "(+)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    35
define_time_0 "(-)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    36
define_time_0 "(*)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    37
define_time_0 "(/)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    38
define_time_0 "(div)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    39
define_time_0 "(<)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    40
define_time_0 "(\<le>)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    41
define_time_0 "Not"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    42
define_time_0 "(\<and>)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    43
define_time_0 "(\<or>)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    44
define_time_0 "Num.numeral_class.numeral"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    45
define_time_0 "(=)"
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    46
b287510a4202 Added time function automation
nipkow
parents:
diff changeset
    47
end