1 / 20

Múlt alkalommal: - Adattípus leírása, mint univerzális algebra: -algebra.

Múlt alkalommal: - Adattípus leírása, mint univerzális algebra: -algebra. - Adattípusok absztrakciója: izomorfizmus. - Adattípusok konkretizálása: homomorfizmus. - Az adattípus leírásának formalizmusa. Példa izomorfizmusra.

adonis
Download Presentation

Múlt alkalommal: - Adattípus leírása, mint univerzális algebra: -algebra.

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. Múlt alkalommal: - Adattípus leírása, mint univerzális algebra: -algebra. - Adattípusok absztrakciója: izomorfizmus. - Adattípusok konkretizálása: homomorfizmus. - Az adattípus leírásának formalizmusa.

  2. Példa izomorfizmusra.  =(S,OP); OP = { k1:  S, k2:  S, N1: S  S; N2: S S S}) A = (bool, { T:  bool, F:  bool, ~_ : bool  bool, : bool bool  bool [infix]}); B = (bit, { 1:  bit, 0:  bit, ch : bit  bit, : bit bit  bit [infix]}); Egy adott  szignatúrához tartozó absztrakt adattípus a -algebrák egy olyan osztálya, amely az izomorfizmusra zárt: azaz C  Alg (  ); A  C; A  B  B  C.

  3. Adattípus specifikációja. (A, F, E); A = {A0, A1, ... , An} A0: típusobjektumok halmaza; A1, ... , An: paraméter objektumok halmaza; Adattípus specifikációja = paraméter specifikációja+típus specifikációja e par exp par: specifikáció; e: tartalmazás; (a morfizmus speciális esete); exp: kitüntetett szortú specifikáció.

  4. nat is a type specification = sorts: nat oprs: 0:  nat _+1: nat  nat _ -1: nat  nat + : nat nat  nat[infix] eqns: n,m  nat; 0 - 1 = " undefined " (n + 1) - 1 = n n + m = m + n n + 0 = n n + (n+1) = (n+n) + 1 end nat;

  5. bool is a type specification = sorts: bool oprs: true :  bool false :  bool  : bool  bool  : bool bool  bool [infix] eqns: a, b  bool; true = false (b) = b (a  b) = (b  a) (b  true) = b (b  false) = false end bool;

  6. natbool is a type specification = nat + bool + sorts: natbool = nat oprs: = : natbool natbool  bool [infix]  : natbool natbool  bool [infix] eqns: a,b natbool; a = a = "true" (a = b) = (b = a) (a = b)  (b = c)  (a = c) (0  0) = "false" (a+1  a) = "true" (a  b)  (b  c)  (a  c) end natbool;

  7. string(alphabet) is a type specification = parameters = sorts: alphabet oprs: a:  alphabet, . . . ,z:  alphabet exports = sorts: string oprs: empty:  string make: alphabet  string concat: string string  string ladd: alphabet string  string radd: string alphabet  string

  8. string(alphabet) is a type specification =    eqns: xalphabet, s,s1,s2,s3string; concat(s,empty) = s concat(empty,s) = s concat(concat(s1,s2),s3)= concat(s1,concat(s2,s3)) ladd(x,s)= concat(make(x),s) radd(s,x)= concat(s,make(x)) end string;

  9. string(data, n: natbool) is a type specification = parameters = data + natbool + exports = type sort: string oprs: empty:  string make: data  string concat: string string  string ladd: data string  string radd: string data  string size: string  natbool eqns: ddata, s,s1,s2,s3string; concat(s,empty) = s concat(empty,s) = s ladd(n,s)= concat(make(n),s) radd(s,n)= concat(s,make(n)) size(empty) = zerus size(ladd(n,s)) = succ(size(s)) size(ladd(n,s))  n  ladd(n,s) = " undefined "

  10. Probléma: specifikáció újrafelhasználása típusspecifikáció1 típusspecifikáció2; Specifikáció morfizmus. spec = (, E); specifikáció morfizmus = szignatúra morfizmus + szemantikai egyenletek morfizmusa; (termek morfizmusa). Speciális esetei: Identitás: 1  2; Átnevezés: régi név új név. Benne foglaltatás, tartalmazás, bővítés: 1  2;

  11. Specifikáció morfizmus speciális esetei: - Identitás: spec1 spec2; - Átnevezés: régi név új név. - Benne foglaltatás, tartalmazás, bővítés: spec1  spec2; - Ábrázolás, reprezentáció: a = (c). - Paraméter átadás: spec(spec1)  spec(spec2). - Speciálisan, formális paraméterek helyettesítése aktuális paraméterekkel (parameter passing): spec(formpar)  spec(actualpar).

  12. Kitüntetett szortú szignatúra morfizmus: h: spec spec'; pt(') = h(pt()) Példa kitüntetett sortú szignatúra morfizmusra: h: speca specc pt(speca) = stack; pt(specc) = vector  nat;

  13. Átnevezés (renaming). Adott típusspecifikációban a - szortok, - operációs szimbólumok nevének a megváltozását jelenti, a szemantika változatlanul hagyása mellett. new type is a type specification = old type specification + sorts =  new sort1 = old sort1 .  new sortn = old sortn oprs =  new opname1 = old opname1 .  new opnamen = old opnamen end new type;

  14. Példa: line(symbol,n: natbool) is a type specification = string(data,n: natbool) + sorts = symbol = data line = string oprs = empty-line = empty make-line = make _ . _ = concat _ . _ = Ladd _ . _ = Radd end line(symbol); új eqns: eqns = d  symbol, s  line, d . s = make-line(d),s régi eqns: eqns = d  data, s  string; Ladd(d,s) = concat(make(d),s)

  15. Adva a szövegszerkesztő következő informális leírása: generate-LINE : üres sor előállítása és a kurzornak a sor elejére állítása. LINE : két adott stringet egymás után elhelyezve előállítja a sort és a kurzort a két string között helyezi el. insert : adott elem elhelyezése az adott sorban a kurzor által mutatott helyre és a kurzor áthelyezése a behelyezett elem jobb oldalára. delete : a kurzor helyétől jobbra lévő elem kitörlése a sorból. move-left : a kurzor áthelyezése egy pozícióval balra, ha nem a sor elején áll. move-right : a kurzor áthelyezése egy pozícióval jobbra, ha nem a sor végén áll. begin: a kurzor sor elejére történő állítása. end: a kurzor sor végére történő állítása. clear: a teljes sor kiűrítése.

  16. generate-LINE:  line :generate- LINE = LINE(empty,empty); insert : alphabet line  line: adott elem elhelyezése az adott sorban a kurzor által mutatott helyre és a kurzor áthelyezése a behelyezett elem jobb oldalára; insert(a, LINE (s1,s2)) = LINE (radd(s1,a),s2) delete: line  line : a kurzor helyétől jobbra lévő elem kitörlése a sorból: delete(LINE (s1,empty)) = LINE (s1,empty) delete(LINE (s1,ladd(a,s2))) = LINE (s1,s2) move-left: line  line : a kurzor áthelyezése egy pozícióval balra, ha nem a sor elején áll: move-left(LINE (empty,s)) = LINE (empty,s) move-left(LINE (radd(s1,a),s2)) = LINE(s1,ladd(a,s2)) move-right: line  line : a kurzor áthelyezése egy pozícióval jobbra, ha nem a sor végén áll: move-right(LINE (s,empty)) = LINE (s,empty) move-right(LINE(a1,ladd(a ,s2))) = LINE (radd(s1,a), s2) begin: line  line : a kurzor sor elejére történő állítása: begin(LINE (s1,s2)) = LINE (empty, concat(s1,s2)) end: line  line : a kurzor sor végére történő állítása: end(LINE (s1,s2)) = LINE (concat(s1,s2),empty) clear: line  line : a teljes sor kiűrítése: clear( / ) = LINE (empty,empty)

  17. line-editor is a type specification = string + type sort: line; oprs: LINE: string string  line generate-LINE:  line insert: alphabet line  line delete: line  line move-left: line  line move-right: line  line begin: line  line end: line  line clear: line  line eqns: a  alphabet; s, s1, s2, s3  string; /  line; generate-LINE = LINE(empty,empty) insert(a, LINE(s1,s2)) = LINE (radd(s1,a),s2) delete(LINE(s1,empty)) = LINE (s1,empty) delete(LINE(s1,ladd(a,s2))) = LINE (s1,s2) move-left(LINE (empty,s)) = LINE (empty,s)

  18. generate-LINE = LINE(empty,empty); insert(a, LINE (s1,s2)) = LINE (radd(s1,a),s2) delete(LINE (s1,empty)) = LINE (s1,empty) delete(LINE (s1,ladd(a,s2))) = LINE (s1,s2) move-left(LINE (empty,s)) = LINE (empty,s) move-left(LINE (radd(s1,a),s2)) = LINE(s1,ladd(a,s2)) move-right(LINE (s,empty)) = LINE (s,empty) move-right(LINE(s1,ladd(a s2))) = LINE (radd(s1,a),s2) begin(LINE (s1,s2)) = LINE (empty, concat(s1,s2)) end(LINE (s1,s2)) = LINE (concat(s1,s2),empty) clear( / ) = LINE (empty,empty) end line editor;

  19. boolalg is a type specification = sorts: boolalg oprs: T:  boolalg ~_ : boolalg  boolalg : boolalg boolalg  boolalg [infix] : boolalg boolalg  boolalg [infix] eqns: a, b, c  boolalg; a  a = a | a  a = a idempotencia a  b = b  a | a  b = b  a kommutativitás (a  b)  c = a  (b  c) | (a  b)  c = a  (b  c) asszociativitás a  (a  b) = a | a  (a  b) = a abszorció a  T = a | a  F = a egységiség a  ~a = F | a  ~a = T komplementaritás end boolalg;

  20. Ha n2 akkor az "n" négyzetének kiszámítása: oprs: _2 : natsq  natsq eqns: n natsq 02 = 0 suc(n)2 = succ(n2 + (n+n))

More Related