Termination {#termination} ==========================
7: module Termination where 8: 9: import Prelude hiding (gcd, mod, map) 10: fib :: Int -> Int 11: gcd :: Int -> Int -> Int 12: infixr `C` 13: 14: data L a = N | C a (L a) 15: 16: {-@ invariant {v: (L a) | 0 <= (llen v)} @-} 17: 18: mod :: Int -> Int -> Int 19: x1:{VV : (Int) | (VV >= 0)} -> x2:{VV : (Int) | (VV >= 0) && (0 < VV) && (VV < x1)} -> {VV : (Int) | (VV >= 0) && (VV < x2)}mod {VV : (Int) | (VV >= 0)}a {VV : (Int) | (VV >= 0) && (0 < VV) && (VV < a)}b | {x3 : (Int) | (x3 == a) && (x3 >= 0)}a x1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 - x2))}- {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b x1:{x10 : (Int) | (x10 > 0) && (0 < x10) && (x10 < a)} -> x2:{x10 : (Int) | (x10 > 0) && (0 < x10) && (x10 < a)} -> {x2 : (Bool) | (((Prop x2)) <=> (x1 > x2))}> {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b = x1:{VV : (Int) | (VV >= 0)} -> x2:{VV : (Int) | (VV >= 0) && (0 < VV) && (VV < x1)} -> {VV : (Int) | (VV >= 0) && (VV < x2)}mod ({x3 : (Int) | (x3 == a) && (x3 >= 0)}a x1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 - x2))}- {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b) {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b 20: | {x3 : (Int) | (x3 == a) && (x3 >= 0)}a x1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 - x2))}- {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b x1:{x12 : (Int) | (x12 > 0) && (0 < x12) && (x12 < a) && (x12 <= b)} -> x2:{x12 : (Int) | (x12 > 0) && (0 < x12) && (x12 < a) && (x12 <= b)} -> {x2 : (Bool) | (((Prop x2)) <=> (x1 < x2))}< {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b = {x3 : (Int) | (x3 == a) && (x3 >= 0)}a x1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 - x2))}- {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b 21: | {x3 : (Int) | (x3 == a) && (x3 >= 0)}a x1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 - x2))}- {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b x1:{x12 : (Int) | (x12 == b) && (x12 > 0) && (0 < x12) && (x12 < a)} -> x2:{x12 : (Int) | (x12 == b) && (x12 > 0) && (0 < x12) && (x12 < a)} -> {x2 : (Bool) | (((Prop x2)) <=> (x1 == x2))}== {x5 : (Int) | (x5 == b) && (x5 >= 0) && (0 < x5) && (x5 < a)}b = x1:(Int#) -> {x2 : (Int) | (x2 == (x1 : int))}0 22: 23: merge :: Ord a => L a -> L a -> L a
69: foo :: Nat -> T 70: foo x = body
93: {-@ fib :: Nat -> Nat @-} 94: {VV : (Int) | (VV >= 0)} -> {VV : (Int) | (VV >= 0)}fib 0 = x1:(Int#) -> {x2 : (Int) | (x2 == (x1 : int))}1 95: fib 1 = x1:(Int#) -> {x2 : (Int) | (x2 == (x1 : int))}1 96: fib n = {VV : (Int) | (VV >= 0)} -> {VV : (Int) | (VV >= 0)}fib ({x2 : (Int) | (x2 >= 0)}nx1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 - x2))}-{x2 : (Int) | (x2 == (1 : int))}1) x1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 + x2))}+ {VV : (Int) | (VV >= 0)} -> {VV : (Int) | (VV >= 0)}fib ({x2 : (Int) | (x2 >= 0)}nx1:(Int) -> x2:(Int) -> {x4 : (Int) | (x4 == (x1 - x2))}-{x2 : (Int) | (x2 == (2 : int))}2)
115: {-@ gcd :: a:Nat -> {b:Nat | b < a} -> Int @-} 116: x1:{VV : (Int) | (VV >= 0)} -> {VV : (Int) | (VV >= 0) && (VV < x1)} -> (Int)gcd {VV : (Int) | (VV >= 0)}a 0 = {x3 : (Int) | (x3 == a) && (x3 >= 0)}a 117: gcd a b = x1:{VV : (Int) | (VV >= 0)} -> {VV : (Int) | (VV >= 0) && (VV < x1)} -> (Int)gcd {x3 : (Int) | (x3 >= 0) && (x3 < a)}b ({x3 : (Int) | (x3 == a) && (x3 >= 0)}a x1:{x9 : (Int) | (x9 >= 0)} -> x2:{x7 : (Int) | (x7 >= 0) && (0 < x7) && (x7 < x1)} -> {x3 : (Int) | (x3 >= 0) && (x3 < x2)}`mod` {x3 : (Int) | (x3 >= 0) && (x3 < a)}b)
130: {-@ mod :: a:Nat 131: -> b:{v:Nat|(0 < v && v < a)} 132: -> {v:Nat| v < b} @-}
142: foo :: S -> T 143: foo x = body
160: foo :: S -> T 161: foo x = body
181: forall a b. (a -> b) -> (L a) -> (L b)map a -> bf N = forall a. {x2 : (L a) | ((llen x2) == 0)}N 182: map f (C x xs) = (a -> bf {VV : a | (VV == x)}x) a -> x2:(L a) -> {x2 : (L a) | ((llen x2) == (1 + (llen x2)))}`C` (forall a b. (a -> b) -> (L a) -> (L b)map a -> bf {x3 : (L a) | (x3 == xs) && (0 <= (llen x3))}xs)
191: {-@ data L [llen] a = N 192: | C (x::a) (xs :: L a) @-} 193: {-@ measure llen :: L a -> Int 194: llen (N) = 0 195: llen (C x xs) = 1 + (llen xs) @-}
208: forall a. (Ord a) => (L a) -> (L a) -> (L a)merge (L a)xs@(x `C` xs') (L a)ys@(y `C` ys') 209: | {VV : a | (VV == x)}x x1:a -> x2:a -> {x2 : (Bool) | (((Prop x2)) <=> (x1 < x2))}< {VV : a | (VV == y)}y = {VV : a | (VV == x)}x a -> x2:(L a) -> {x2 : (L a) | ((llen x2) == (1 + (llen x2)))}`C` forall a. (Ord a) => (L a) -> (L a) -> (L a)merge {x3 : (L a) | (x3 == xs') && (0 <= (llen x3))}xs' {x5 : (L a) | (x5 == ys) && (x5 == (Termination.C y ys')) && ((llen x5) == (1 + (llen ys'))) && (0 <= (llen x5))}ys 210: | otherwise = {VV : a | (VV == y)}y a -> x2:(L a) -> {x2 : (L a) | ((llen x2) == (1 + (llen x2)))}`C` forall a. (Ord a) => (L a) -> (L a) -> (L a)merge {x5 : (L a) | (x5 == xs) && (x5 == (Termination.C x xs')) && ((llen x5) == (1 + (llen xs'))) && (0 <= (llen x5))}xs {x3 : (L a) | (x3 == ys') && (0 <= (llen x3))}ys'
227: {-@ merge :: Ord a => xs:_ -> ys:_ -> _ 228: / [(llen xs) + (llen ys)] @-}