Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Sequences: New Definition

Silvia Takahashi
17 de noviembre de 2016

1. Sequences as inductive structures


We modify our definition of sequences of elements of type T so that the basic constructor operation is append
(.) instead preppend (/) which is now derived
Basis Clause The empty sequence represented by the symbol  is a sequence.
Inductive Clause If n ∈ T , and S es a sequence, S . n (pronounced S append n) denotes the sequence
obtained by adding n at the end of sequence S.
The following table shows recursive definitions of sequence operations:

F Basis Case F. Inductive case: F (S . n)


Length 1 : Long(S) Long() = 0 Long(S . n) = 1 + Long(S)

Sum 2 : Suma(S) Sum() = 0 Sum(S . n) = n + Sum(S)


(
count(y, S) + 1 if x = y
Number occurrences of y: count(y, S) count(y, ) = 0 count(y, S . x) =
count(y, S) otherwise

Concatenation: S @ T S @=S S @ (T . x) = (S @ T ) . x

Preppend: x / S x/=.x y / (S . x) = (y / S) . x

Reverse3 : rev(S) rev() =  rev(S . x) = x / rev(S)

Máximum: maxs (S) max() = −∞ maxs (S . x) = max(x, maxs (S))

Mı́nimum: mins (S) min() = ∞ mins (S . x) = min(x, mins (S))

Last element: last(S) last() = ⊥4 last(S . x) = x

S without its last element dlast(S) dlast() = ⊥ dlast(S . x) = S

Tabla 1: Sequence Operations


We can define functions that require two base cases:

Function For  For x /  For x / y / S

f irst(S) f irst() = ⊥ f irst( . x) = x f irst(S . y . x) = f irst(S . y)


(S’s first element)

rest(S) rest() = ⊥ rest( . x) =  rest(S . y . x) = rest(S . y) . x


(rest(S)
S without its first element)

asc(S) asc() ≡ true asc( . x) ≡ true asc(S . y . x) ≡ (x ≥ y ∧ asc(S . y))


(asc(S) = true iff S
is sorted in ascending order)

desc(S) desc() ≡ true desc( . x) ≡ true desc(S . y . x) ≡ (x ≤ y ∧ desc(S . y))


(desc(S) = true iff S
is sorted in descending order)

Tabla 2: Sequence Operations Defined with Two Base Cases

Equality is a very important concept.

(S = T ) ≡ (T = S)
( = ) ≡ true
(S . x = ) ≡ f alse
( = T . x) ≡ f alse
(S . x = T . y) ≡ (x = y ∧ S = T )

2. Proof Pattern
In this case, this would be the proof pattern:
Basis Case: P ()
Inductive Case: P (S) ⇒ P (S . y)
I.H. P (S)
Prove: P (S . y)
1 Can also be denoted: #.S
2 IfS is a squence of numbers
3 Can also be denoted: S −1
4 (⊥ is “undefined”

You might also like