12.07.2015 Views

Discrete Mathematics..

Discrete Mathematics..

Discrete Mathematics..

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Types and Typed Set Theory 141is another part of the postcondition which says that the output should benon-negative: r 0.Putting all the pieces together gives the following specification of thesquare root operation.√ : x : Real → r : Realprecondition x 0postcondition r 0 ∧ r 2 = x.3. The following are some further specifications of operations given withsomewhat briefer explanation. In general, each specification hasa signature, precondition and postcondition although sometimes noprecondition is required.(i) square 2 : x : Real → r : Realprecondition There is no precondition since we are allowedto ‘feed in’ any real number to the ‘squareoperation’postcondition r = x × x.(ii) absolute value | |:x : Real → r : Realprecondition none (from now on we shall simply missout the precondition part if there is noprecondition)postcondition (x 0 → r = x) ∧ (x < 0 → r =−x).(iii) ‘floor’ or ‘integer part’ ⌊ ⌋:x : Real → n : Integer .The floor or integer part of a real number is the largest integerthat is less than or equal to the given real number. For example,⌊8.74⌋ =8, ⌊π⌋ =3, ⌊−2.38⌋ =−3, ⌊4⌋ =4, etc.postcondition(n x) ∧ (n + 1 > x).The postcondition uses and > each with one Integer and oneReal argument. We have defined these operations to have signatureReal , Real → Real (or Integer , Integer → Integer ). Therefore,in the postcondition, we are assuming that Integer is a subtype ofReal and that, in each operation, we are substituting a value oftype Integer for the first argument of the operation with signatureReal , Real → Real .(iv) intersection ∩ : A : Set [T ], B : Set [T ]→C : Set [T ]postcondition for all x : T , x ∈ C ↔ (x ∈ A ∧ x ∈ B).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!