src/HOL/ex/Termination.thy
changeset 32399 4dc441c71cce
parent 29181 cc177742e607
child 33468 91ea7115da1b
equal deleted inserted replaced
32398:40a0760a00ea 32399:4dc441c71cce
     1 (* Title:       HOL/ex/Termination.thy
     1 (* Title:       HOL/ex/Termination.thy
     2    ID:          $Id$
       
     3    Author:      Lukas Bulwahn, TU Muenchen
     2    Author:      Lukas Bulwahn, TU Muenchen
     4    Author:      Alexander Krauss, TU Muenchen
     3    Author:      Alexander Krauss, TU Muenchen
     5 *)
     4 *)
     6 
     5 
     7 header {* Examples and regression tests for automated termination proofs *}
     6 header {* Examples and regression tests for automated termination proofs *}
     8  
     7  
     9 theory Termination
     8 theory Termination
    10 imports Main Multiset
     9 imports Main Multiset
    11 begin
    10 begin
    12 
    11 
       
    12 subsection {* Manually giving termination relations using @{text relation} and
       
    13 @{term measure} *}
       
    14 
       
    15 function sum :: "nat \<Rightarrow> nat \<Rightarrow> nat"
       
    16 where
       
    17   "sum i N = (if i > N then 0 else i + sum (Suc i) N)"
       
    18 by pat_completeness auto
       
    19 
       
    20 termination by (relation "measure (\<lambda>(i,N). N + 1 - i)") auto
       
    21 
       
    22 function foo :: "nat \<Rightarrow> nat \<Rightarrow> nat"
       
    23 where
       
    24   "foo i N = (if i > N 
       
    25               then (if N = 0 then 0 else foo 0 (N - 1))
       
    26               else i + foo (Suc i) N)"
       
    27 by pat_completeness auto
       
    28 
       
    29 termination by (relation "measures [\<lambda>(i, N). N, \<lambda>(i,N). N + 1 - i]") auto
       
    30 
       
    31 
       
    32 subsection {* @{text lexicographic_order}: Trivial examples *}
       
    33 
    13 text {*
    34 text {*
    14   The @{text fun} command uses the method @{text lexicographic_order} by default.
    35   The @{text fun} command uses the method @{text lexicographic_order} by default,
    15 *}
    36   so it is not explicitly invoked.
    16 
    37 *}
    17 subsection {* Trivial examples *}
       
    18 
    38 
    19 fun identity :: "nat \<Rightarrow> nat"
    39 fun identity :: "nat \<Rightarrow> nat"
    20 where
    40 where
    21   "identity n = n"
    41   "identity n = n"
    22 
    42