CIA2326: WEEK ?? - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CIA2326: WEEK ??

Description:

CIA2326: WEEK ?? LECTURE: Introduction to Algebras SUPPORTING NOTES: See chapters 8,9,10 of my online book on my homepage TUTORIAL: hand out exercises – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 15
Provided by: COMPUTING107
Category:
Tags: week | cia2326 | types

less

Transcript and Presenter's Notes

Title: CIA2326: WEEK ??


1
CIA2326 WEEK ??
  • LECTURE
  • Introduction to Algebras
  • SUPPORTING NOTES
  • See chapters 8,9,10 of my online book on my
    homepage
  • TUTORIAL hand out exercises
  • Telescopes are to Astronomy what Computers are
    to Computer Science (Edgar Dijstra)

2
Algebras
  • Q1. What is an algebra?
  • Q2.What has it to do with computing?

3
Algebras
  • A1. Roughly, an algebra is A SET OF VALUES the
    specification of some OPERATIONS on those values
  • A2. Roughly, a data type is A SET OF VALUES the
    implementation of some OPERATIONS on those
    values.
  • Hence we can give a computer-independent meaning
    to data types using algebras.

4
Abstraction in Programming
  • Algebras inform us in both the THEORY and
    PRACTICE of programming
  • Good modularity of software is ensured to a large
    degree by procedural and data abstractions
  • Object technologies owe much of their success to
    the fact that their structure results in a high
    degree of procedural and data abstraction.
  • Data abstraction or abstract data types
    abstract away the implementation of data types
    values and operations - just like ALGEBRAS!

5
Abstract Data Types
  • A very abstract way of defining data types is as
    follows abstract away the implementation of data
    types values and operations in two ways
  • define the operations in terms of each other
  • dont represent values AT ALL except in terms of
    the operations that construct them
  • This give us an abstract algebra.

6
Homogenous algebras Formal Definition
  • (A,O) is a Homogenous algebra if
  • A is a non-empty set which contains values of the
    algebra and is known as the carrier set.
  • O is a set of closed, total operations defined
    over the carrier set which may include nullary
    operations (constants).
  • EXAMPLE (Natural Numbers, ) ,
  • EXAMPLE (True,False, and,not)
  • COUNTER-EX (Natural Numbers, -)
  • COUNTER-EX (Real Numbers, /)

7
heterogeneous algebras
  • (A,O) is a heterogeneous algebra if
  • A is a SET of carrier sets and
  • O is a set of closed and total operations over
    these sets.
  • The semantics of data types are often given by
    heterogeneous algebras as we shall see...

8
?Equational Specification of Algebras
  • The most abstract form of Presentation (ie how
    to define them) is NOT TO GIVE ANY NAMES to their
    values.
  • A very abstract way to specify a (family of)
    Algebras/Data Types is to give an Equational
    Specification.

9
Example - Equational Presentation of a Homogenous
Algebra
  • SPEC Boolean
  • SORT bool
  • OPS
  • true -gt bool
  • false -gt bool
  • not bool -gt bool
  • and bool bool -gt bool
  • AXIOMS FORALL b bool
  • (1) not(true) false (2) not(false) true
    (3) and(true,b) b
  • (4) and(b,true) b (5) and(false,b) false (6)
    and(b,false) false
  • ENDSPEC

10
Syntax for Equational Specs of Algebras (ADTs)
  • SPEC Name of Specification
  • SORT Type of interest - algebra being
    defined
  • OPS Signature of operations
  • FORALL Universally defined variables
  • AXIOMS Equations defining MEANING of
    operations
  • ENDSPEC

11
Another Example
  • SPEC Natural
  • SORT nat
  • OPS
  • zero -gt nat
  • succ nat -gt nat
  • add nat nat -gt nat
  • AXIOMS FORALL m, n nat
  • (1) add(zero, n) n (2) add(succ(m), n)
    succ(add(m, n))
  • ENDSPEC

12
  • SPEC A_State_Machine
  • SORT state
  • OPS
  • S1 -gt state S2 -gt state
  • S3 -gt state
  • a state -gt state b state -gt state
  • c state -gt state
  • AXIOMS FORALL m, n nat
  • (1) a(S1) S3 (6) c(S2) S1
  • (2) b(S1) S1 (7) a(S3) S3
  • (3) c(S1) S2 (8) b(S3) S1
  • (4) a(S2) S2 (9) c(S3) S3
  • (5) b(S2) S2
  • ENDSPEC

13
Another Example...
  • SPEC Stack USING Natural Boolean Carriers
    are Stack, Natural
  • SORT stack and Boolean
  • OPS Type of Interest Stack
  • init -gt stack Signature of each Operation
  • push stack nat -gt stack
  • pop stack -gt stack
  • top stack -gt nat is-empty? stack -gt bool
  • stack-error -gt stack
  • nat-error -gt nat
  • FORALL s stack, n nat universally
    quantified vars
  • AXIOMS for is-empty?
  • (1) is-empty?(init) true this part gives
    meaning'
  • (2) is-empty?(push(s,n)) false to each
    operation AXIOMS for pop
  • (3) pop(init) stack-error
  • (4) pop(push(s,n)) s
  • AXIOMS for top
  • (5) top(init) nat-error
  • (6) top(push(s,n)) n ENDSPEC

14
Conclusions
  • ALGEBRA gives us an ABSTRACT way to specify DATA
    TYPES
  • NEXT week we will examine how to REASON with
    algebraic expressions.
Write a Comment
User Comments (0)
About PowerShow.com