1 / 14

CIA2326: WEEK ??

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). Algebras. Q1. What is an algebra?

Download Presentation

CIA2326: WEEK ??

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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; • don’t 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, totaloperations 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 : -> bool • false : -> bool • not : bool -> bool • and : bool bool -> 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 : -> nat • succ : nat -> nat • add : nat nat -> 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 : -> state S2 : -> state • S3 : -> state • a : state -> state b : state -> state • c : state -> 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 : -> stack % Signature of each Operation • push : stack nat -> stack • pop : stack -> stack • top : stack -> nat is-empty? : stack -> bool • stack-error : -> stack • nat-error : -> 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.

More Related