osaka university knowledge archive : ouka · (1) [presburger sort bool, op true not and, 0, +1' =0...

119
Title プログラムの代数的仕様記述法に関する研究 Author(s) 杉山, 裕二 Citation Issue Date Text Version ETD URL http://hdl.handle.net/11094/1175 DOI rights Note Osaka University Knowledge Archive : OUKA Osaka University Knowledge Archive : OUKA https://ir.library.osaka-u.ac.jp/ Osaka University

Upload: others

Post on 30-Jan-2021

10 views

Category:

Documents


0 download

TRANSCRIPT

  • Title プログラムの代数的仕様記述法に関する研究

    Author(s) 杉山, 裕二

    Citation

    Issue Date

    Text Version ETD

    URL http://hdl.handle.net/11094/1175

    DOI

    rights

    Note

    Osaka University Knowledge Archive : OUKAOsaka University Knowledge Archive : OUKA

    https://ir.library.osaka-u.ac.jp/

    Osaka University

  • I

    SPEC Table;

    BASE Integer, Boolean, String; SORT table;

    OP initial-table: table,

    put : int, string, table table, delete: int, table table,

    in : int, table bool, access: int, table string;

    VAR t SORT table, i, i- SORT int, s SORT string;

    Axl: in(i, initial-table) false; Ax2: in (i, put (i' , s, t) )

    if i = i' then true else in (i , t) Ax3: in(i, delete(i', t)) ==

    if i = i' then false else in(i, t);

    Ax4: access(i, put(i', s, t)) == if i = i' then s else access (i, t)

    Ax5: access(i, delete(i', t))

    if i ~ i' then access(i, t);

    END;

    I _]'Y / , /

    -24 -

  • (1) [Presburger

    SORT bool,

    OP true

    not

    and,

    0,

    +1'

    =0

    Arithmetic]

    int;

    f alse: bool

    or bool,

    int int

    int -

    bool

    int

    ->

    ->

    ->

    ->

    ->

    ->

    ->

    bool,

    bool,

    bool,

    int,

    int .

    bool,

    bool;

    (2) [identifiers]

    SORT fid, rid,

    OP FOR EACH

    = " 74: S'

    bid;

    S IN

    S ->

    Ifid,

    bool;

    rid, bid I I

    (3) [character strings]

    SORT string;

    OP "OP/PT", "R/W", "CL11, "WT'1

    , 11 AC 'I :

    =' ~: string, string

    ->

    ->

    string,

    bool;

    (4) [records and

    SORT record,

    OP nullR

    select: length:

    "eof" :

    record

    seqREC;

    seqREC,

    seqREC,

    seqREC

    sequences]

    record

    int

    seqREC,

    seqREC,

    record,

    int,

    record;

    (5) A: B:

    C:

    if

    if

    if

    true

    f alse

    true

    then x

    then x

    then x

    else

    else

    y X;

    y Y;

    X;

    10 2,1 At P S ?-~ t~ W "6")~ 0, 'K IT

  • (1)

    (2) (3)

    (4)

    (5)

    (6)

    (7)

    (8)

    (9)

    (10)

    (11)

    (12)

    (13)

    (14)

    SPEC Requests-and-user-operations;

    BASE Base-Algebra; SORT uop;

    CONSTRUCTOR OPENW, OPENR: fid, rid uopf

    WRITE, READ : rid, bid uopr CLOSE, WAIT : rid uopf PUTB : bid, record uop;

    OP [0-function] type : uop string,

    refID : uop rid;

    Tl: type(OPENW(f,r)) "OP/PT"; T2: type(OPENR(f,r)) "OP/PT"; T3: type (WRITE (r , b) ) "R/W"; T4: type(READ (r,b)) "R/W"; T5: type(CLOSE(r)) "CL"; T6: type(WAIT (r)) "WT"; T7: type(PUTB(b,rec)) "OP/PT";

    RF1*: FOR EACH Q IN JOPENW(f,r) OPENR(f,r) WRITE(r,b) READ(r,b) CLOSE(r) WAIT(r)j,

    refID(Q) == r;

    END;

    10 2. 2 1) 7 1 ? ~ 13 0-" ~'l III A TOt F_ r~ M.- 7 3 11 4

    - ~Ll-

  • SPEC System-0;

    INCLUDE Buffers, Files, File-directory, Dataset-control-blocks;

    SORT Sys;

    CONSTRUCTOR

    InitialS: sysr Execute : uop, sys -> sys;

    OP [0-function]

    invalid : uop, sys bool, stateB : sys bf,

    stateF : Sys fl,

    stateFD : sys fdr stateDCB: sys dcb;

    LET sB stateB(s); LET sFD stateFD (s); LET sF stateF(s); LET sDCB stateDCB(s);

    Vl: invalid(OPENW(f,r),, s) ==

    exist(f, sFD) or used(r, sDCB); V2: invalid(OPENR(f,r), s) ==

    if not exist(f, sFD) then true

    else used(r,, sDCB) or openedW(f. sFD);

    V3: invalid(WRITE(r,b), S) == if not used(r, sDCB) then true

    else not openedW(fname(r, sDCB), sFD);

    V4: invalid(READ(rb),. s) == if not used(r, sDCB) then true

    else openedW (f name (r , sDCB) , sFD) V5: invalid(CLOSE(r), s) == not used(r, sDCB);

    -1 2 (CA it 4-41.~ I I-St Q M - 0 ( i ') I )

    '~_D -

  • BO: stateB(InitialS) == initialB; Bl: stateB(Execute(PUTB(b,rec), s))

    putB(b, rec, sB) ; B2: stateB(Execute(READ(r,b), s))

    if invalid (READ (r b) , s) then sB else putB(b, READREC, sB)

    WHERE READREC := if count(r, sDCB) >= length(FILE) then "eof"

    else select(FILE, count(r, sDCB))

    WHERE FILE := file(fname(r, sDCB), sF); B3*: FOR EACH Q IN JOPENW(f,r) OPENR(f,r)

    WRITE (r b) CLOSE (r) 1, stateB(Execute(Qr s)) == sB;

    FO: stateF(InitialS) == initialF;

    Fl: stateF(Execute(WRITE(r,b), s)) if invalid (WRITE (r b) , s) then sF

    else appendF(fname(r,sDCB), contentB(b,sB), sF);

    F2*: FOR EACH Q IN JOPENW(f,r) OPENR(f,r) READ(r,b) CLOSE(r) PUTB(b,rec)l,

    stateF(Execute(Q, s)) == sF;

    FDO: stateFD(InitialS) == initialFD;

    FD1: stateFD(Execute(OPENW(f,r), s))

    if invalid (OPENW(f,r) , s) then sFD else openFD(f, sFD);

    FD2: stateFD(Execute(CLOSE(r), s)) if invalid(CLOSE(r), s) then sPD

    else if openedW (f name (r , sDCB) , sFD) then closeFD(f name (r , sDCB) , sFD)

    else sFD;

    FD3*: FOR EACH Q IN JOPENR(f,r) WRITE(r,b) READ (r , b) PUTB (b, r ec) I,

    stateFD(Execute(Qr s)) == sFD;

    DCBO: stateDCB(InitialS) == initialDCB;

    DCB1*: FOR EACH Q IN JOPENW(f,r) OPENR(f,r) WRITE(r,b) READ(r,b) CLOSE(r)j,

    stateDCB(Execute(Q, s)) ==

    if invalid(Q,s) then sDCB else execDCB(Q,sDCB); DCB6: stateDCB(Execute(PUTB(b,rec), s)) == SDCB;

    END;

    Mil 2 , ~ ( 6 ) ~ t A ~y 4 t e 'A - o ( 1 0 Z )

  • SPEC Buffers;

    BASE Base-Algebra;

    SORT bf;

    CONSTRUCTOR initialR: record,

    initialB: bf,

    putB : bid, record, bf bf;

    OP [0-function]

    contentB: bid, bf record;

    CO: contentB(b, initialB) == initialR; Cl: contentB(b, putB(b', rec, s)) ==

    if b = b' then rec else contentB(b, s);

    END;

    SPEC Files;

    BASE Base-Algebra;

    SORT fl;

    CONSTRUCTOR

    initialF: appendF : fid, record, fl

    OP [0-function] file fid, fl

    FO: file(f, initialF) == nullR; Fl: file(f, appendF(f', rec, s))

    if f = f' then file(f,s).rec

    END;

    f 1 1

    fl;

    seqREC;

    else f ile (f s) ;

    1. ZI 2 . 4 i -t J& B,~+Q rA , 'F ' ke "~

    _S2__

  • SPEC File-directory;

    BASE Base-Algebra;

    SORT fd;

    CONSTRUCTOR initialFD fd,

    openFD, closeFD: fid, fd fd;

    OP [0-function]

    exist, openedW: fid, fd bool;

    EXO: exist(f, initialFD) == false;

    EX1: exist(f, openFD(f', s)) == if f = f' then true else exist(f, s);

    EX2: exist(f, closeFD(f', s)) exist(f, s);

    OW1: openedW(f, openFD(f', s))

    if f = f' then true else openedW(f, s); OW2: openedW(f, closeFD(f', s)) ==

    if f = f' then false else openedW(f, s);

    END;

    10 2, 3 I t J'j, -p ~' I " -01, , 11~ec to Y*I

    _ '~3 -

  • SPEC Dataset-control-blocks;

    INCLUDE Requests-and-user-operations; SORT dcb;

    CONSTRUCTOR

    initialDCB: dcb, execDCB : uop, dcb dcb;

    OP [0-function] used : rid, dcb bool,

    fname: rid, dcb fid, count: rid, dcb int;

    INI: used(r, initialDCB) == false;

    OP1*: FOR EACH Q IN JOPENW OPENRI, fused(r, execDCB(Q(f,r), s)) ==

    if r = r' then true else used(r, s);

    fname(r, execDCB(Q(f,r'),, s)) == if r = r' then f else fname(r, s);

    count(r, execDCB(Q(f,,r)r s)) == if r = r' then 0 else count(r, s)j;

    WR1*: FOR EACH Q IN JWRITE READI, fused (r, execDCB(Q(r',b), s)) used (r, s);

    fname(r, execDCB(Q(r',b), s)) fname(r, s);

    count(r, execDCB(Q(r',,b), s)) if r = r' then count(r,s)+l else count(r,s)j;

    CL1: used(r, execDCB(CLOSE(r~), s)) ==

    if r = r' then false else used(r, s); CL2*: FOR EACH F IN Ifname countl,

    F(r, execDCB(CLOSE(r'), s))

    if r :;,' r' then F(r, s);

    END;

    Y-1 2 6 - 6 1 0C ~4

    - 1~q --

  • SPEC File-system;

    INCLUDE System-1;

    SORT fsys;

    CONSTRUCTOR

    InitialFS: fsys' Issue : uop, fsys fsys'

    Complete: rid, fsys fsys;

    OP [0-function] stateS1 fsys Sys,

    UP-executing: fsys bool, last-uop : fsys uop;

    LET sSl := stateSl(s);

    STO: stateSl(InitialFS) InitialS;

    ST1: stateSl(Issue(q, s)) if UP-executing(s) then

    (if type(q) = "OP/PT" then Execute(q, sSl) else if busyR(refID(q), sSI) or

    (type(q) = "WT") then sSl else if type(q)="R/W" then Initiate(q, sSl)

    else Execute(q, sSl)); ST2: stateSl(Complete(r, s))

    if busyR(r, sSl) then

    (if UP-executing(s) then Execute(Q, sSl) else if (refID(Q') ~ r) or (type(Q') = "WT")

    then Execute(Q, sSl)

    else if type(Q') = "R/W" then Initiate(Q~, Execute(Q, sSl))

    else Execute(Q', Execute(Q, sSl))) WHERE Q initiated-uop(r, sSl) AND

    Q' las t-uop (s) ;

    UEO: UP-executing(InitialFS) == true;

    UEl: UP-executing(Issue(q, s)) if UP-executing(s) then

    (if type(q) = "OP/PT" then true else not busyR(refID(q), sSl));

    UE2: UP-executing(Complete(r, s)) if busyR(r, sSl) then

    (if UP-executing(s) then true else (refID(last-uop(s)) r));

    LUl: last-uop(Issue (q, s))

    if not UP-executing(Issue(q, s)) then q; LU2: last-uop(Complete(r, s)) == last-uop(s);

    END;

    1Y_1 2 7

  • SPEC System-1;

    INCLUDE System-0;

    CONSTRUCTOR Initiate : uop, Sys Sys;

    OP [0-function] busyR : rid, sys bool,

    initiated-uop: rid, sys uop;

    BSO: busyR(r, InitialS) == false; BS1: busyR(r, Initiate(q, s)) ==

    if invalid(q, s) or (type(q) 3~ "R/W") then busyR(r, s)

    else if r = refID(q) then -true else busyR(r, s);

    BS2: busyR(r, Execute(q, s)) if type(q) "R/W" then busyR(r, s)

    else if r refID(q) then false else busyR(r, s);

    IOP1: initiated-uop(r, Initiate(q, s)) if invalid(q, s) or (type(q) r-' "R/W") then

    initiated-uop(r, s) else if r = refID(q) then q

    else initiated-uop(r, s); IOP2: initiated-uop(r, Execute(q, s))

    if busyR(r, Execute(q, s)) then ini ti ated-uop (r , s) ;

    WT1*: FOR EACH X IN JB F FD DCBj,

    stateX(Initiate(q, s)) == stateX(s);

    END;

    2 I t q, '~ y /a t,2 m - I

    - ~_R

  • SPEC Sequence-of-UOP

    INCLUDE Requests-and-user-operations;

    SORT seqUOP;

    CONSTRUCTOR nullUOP: seqUOP,

    : uop, seqUOP seqUOP,

    ACCB : bid u0p;

    OP [0-function]

    eqUOP : uopf uop bool;

    LET BINARY-UOP JOPENW OPENR WRITE READ LET UNARY-UOP fCLOSE WAIT ACCBJ;

    EQ1*: FOR EACH Q IN BINARY-UOP,

    JeqUOP(Q(i,j), Q(iA,j')) == (i=i') and FOR EACH Q- IN BINARY-UOP - 1Q1,

    eqUOP(Q(i,j), Q'(i',j')) == false; FOR EACH Q' IN UNARY-UOP,

    eqUOP(Q(i,j), QA(i')) == falseh EQ41*: FOR EACH Q IN UNARY-UOP,

    jeqUOP(Q(i), Q(iA)) == (i iA); FOR EACH QA IN UNARY-UOP fQJ,

    eqUOP(Q(i), QA(iA)) == false; FOR EACH Q- IN BINARY-UOP,

    eqUOP(Q(i), QA(iA,jA)) == falsel;

    T8: type(ACCB(b)) == "AC";

    END;

    PUTB I ;

    lil 2 . ~ v 7 1- 7, ~ + i, I q It 4

    - ~,2 --

  • SPEC Relations-between-SeqUOP-and-SystemO;

    INCLUDE Sequence-of-UOP, System-0;

    OP stateO: seqUOP -> sys;

    SOO: stateO(nullUOP) == InitialS; S01: stateO(q.seq) ==

    if (type (q) = "WT") or (type (q) = "AC")

    then stateO(seq) else Execute(q, stateO(seq));

    END;

    (01) ?4 tz ,, ~Ct, 0 A ~ -k

    SPEC Relations-between-SeqUOP-and-FileSystem;

    INCLUDE Sequence-of-UOP, File-system;

    OP reachable: seqUOP, fsys -> bool;

    RCO: reachable(nullUOP, InitialFS) true;

    RCI: reachable(nullUOP, Issue(q, s)) false; RC2: reachable(nullUOP, Complete(r, s)) false;

    RC3*: FOR EACH Q IN JOPENW(f,r) OPENR(f,r) WAIT(r) WRITE(r,b) READ(r,b) CLOSE(r) PUTB(b,rec)j,

    freachable(Q.seq, InitialFS) == false; reachable(Q.seq, Issue(q, s)) ==

    UP-executing(s) and eqUOP(Q, q) and reachable(seq, s);

    reachable(Q.seq, Complete(r, s))

    - busyR(r,stateSl(s)) and reachable(Q.seq,s)l; RC24*: reachable(ACCB(b).seq, s) ==

    UP-executing(s) and reachable(seq, s);

    END;

    (6) 4q v Y -"'- 0, C ~ 0, ~ I -,

    I'XI 2, / 0 , ~ ~ L_ 4t 9 7 S'l ~ ; ' k ~ "\ 4] rt,

    69

  • SPEC How-to-use-buffers;

    INCLUDE Sequence-of-UOP;

    OP wellB: seqUOP bool, freeB: bid, seqUOP bool, rname: bid, seqUOP rid;

    WBO: wellB(nullUOP) == true; WB1*: FOR EACH Q IN JWRITE(r,b) READ(r,b)

    PUTB(b,rec) ACCB(b)j, wellB(Q.seq) == wellB(seq) and freeB(b, seq); WB5*: FOR EACH Q IN fOPENW(f,r) OPENR(f,r) WAIT(r)

    CLOSE(r)j, wellB(Q.seq) == wellB(seq);

    LET FREED (b, r, seq) := if freeB(b, seq) then true

    else (r = rname (b, seq) ) ;-

    FRO: freeB(b, nullUOP) == true; FR1*: FOR EACH Q IN IWRITE(r,b') READ(r,bA)I, freeB(b, Q.seq) ==

    if b = b' then false else FREED(b, r, seq);

    FR3*: FOR EACH Q IN JCLOSE(r) WAIT(r)j, freeB(b, Q.seq) == FREED(b, r, seq);

    FR5*: FOR EACH Q IN fOPENW(f,r) OPENR(f,r) PUTB(b,rec) ACCB(b)j,

    freeB(b, Q.seq) == freeB(b, seq);

    RN1*: FOR EACH Q IN IWRITE(r,b) READ(r,b-)J, rname(b, Q.seq) ==

    if b = b' then r else rname (b, seq)

    RN3*: FOR EACH Q IN fOPENW(f,r) OPENR(f,r) CLOSE(r) WAIT(r) PUTB(b,rec) ACCB(b)j,

    rname(b, Q.seq) == rname(b, seq);

    END;

    ilz( 2 , / / L.,r -e 1113 at ~ A

    -- 7/ --

  • SPEC Sequential-state-of-FS;

    INCLUDE Sequence-of-UOP, File-system;

    OP stateFS: seqUOP -> fsys;

    FSO: stateFS(nullUOP) == InitialFS;

    FS1: stateFS(q.seq) == if type (q) = "AC" then stateFS (seq)

    else if type(q) = "R/W" then

    Complete(refID(q), Issue(q, stateFS(seq))) else Issue(q, stateFS(seq));

    END;

    Qz 2 , / :2 M t~ /ot,t-e FS A )z -k-

  • function FVO(P)~

    begin

    (1) Pt'V2 EVAL(Pt-v2);

    (2) Pt-VI (Pt-V2 = 0);

    (3) if Pt.v, then FV0 I

    else FV0 FV5 (P)

    end

    111 .3. S 1~ 9 % n 9 6-) -71 a ?- ~ 1~1

    - lot

  • (1)

    (2)

    (3)

    (4)

    (5)

    ( 16, )

    (7)

    (8)

    Goguen, J.A., Thatcher, J.W. and Wagner, E.G.: "An

    initial algebra approach to the specification, correct-

    ness, and implementation of abstract data types," IBM

    Research Report, RC-6487 (1976).

    Guttag, J.V.: "The specification and application to

    programming of abstract data types," Univ. of Tront,

    Technical Report, CSRG-59 (Sep. 1975).

    Wand, M.: "Final algebra semantics and data type exten-

    sions,"Indiana Univ., Computer Science Dept., Technical

    Report, No. 65 (July 1978).

    Hoffmann, C.M. and O'Donnell,M.J.: "Programming with

    equations," ACM Trans. on Programming Languages and

    Systems, Vol. 4, No. 1, pp.83-112 (Jan. 1982).

    A?, (T ffl, -,.:- rz

    - A k , , A~ AL 7q- I(I 02)

    TTR ipf ef-a T-5

    7 " I t Z _1C

    4 `827 A L ?0 ( I Y,00 OS-)

    13

    AL 77 qj

    ;F JL~ A4- 0 4 7-

    AL 7~ 41 6 Of 7 8

    __ //2

  • (11)

    D L C j "I 0~ 4

    j3 Z 1`~ X22,' Q2` D 364 - D 2

    24 1 ?i 1 0 2

    Rosen, B.K.: "Tree-manipulating systems and Church-

    Rosser theorems," J. Assoc. Comput. Mach., Vol. 20,

    No. 1, pp. 160-187 (Jan. 1973).

    Huet, G.: "Confluent reductions: abstract properties

    and applications to term rewriting systems," J. Assoc.

    Comput. Mach., Vol. 27, No. 4, pp. 797-821 (Oct. 1980).

    Huetl G. and L6vy, J-J.: "Call by need computations in

    non-ambiguous linear term rewriting systems," IRIA

    Research Report, No. 359 (Aug. 1979) .

    Ehrich, H-D. and Lipeck, U.: "Proving implementations

    correct - two alternative approaches," Information

    Processing 80, pp. 83-88 (1980).

    M v/ ~, , ~ Alk 4~ U

    -Z

    AL 70 7q l17?

    ? el

    Backus, J.: "Can programming be liberated from the von

    Neumann style? A functional style and its algebra of

    programs;'Commun. ACM, Vol. 21, No. 8, pp. 613-641

    (Aug. 1978).

  • (17)

    (18)

    (19)

    (20)

    (21)

    (22)

    23)

    24

    Hoffman, C.M. and O'Donell, M.J.: "An interpreter

    generator using tree pattern matching," Proc. 6th Ann.

    Sympo. on Principles of Programming Languages, pp. 169-

    179 (Jan. 1979).

    O'Donnell,M.J.: "Computing in systems described by

    equations," Lecture Notes in Computer Science, No. 58

    (1977).

    Burstall, R.M.: "Design considerations for a functional

    programming language," Proc. Infotech State of the Art

    Conf., pp. 45-57 (1977).

    Berry, G. and L6vy, J-J.: "Minimal and optimal computa-

    tions of recursive programs," J. Assoc. Comput. Mach.,

    Vol. 26, No. 1, pp. 148-175 (Jan. 1979).

    Vuillemin, J.: "Correct and optimal implementations of

    recursion in a simple programming language," J. Comput.

    & Syst. Sci., Vol. 9, No. 3, pp. 332-354 (Dec. 1974).

    Raoult, J-C. and Vuillemin, J.: "Operational and

    semantic equivalence between recursive programs," J.

    Assoc. Comput. Mach., Vol. 27, No. 4, pp. 772-796

    (Oct. 1980).

    %*7

    1~ A L 1 9 5

    j9e2 01)

    7 -70 D 0% ti IT

    f If Vo 1. 20 No~ 1 22 43 B~ 94 01