Basics Of CafeOBJ And Peano Style Natural Numbers

3y ago
34 Views
4 Downloads
2.38 MB
31 Pages
Last View : 8d ago
Last Download : 3m ago
Upload by : Lilly Kaiser
Transcription

Basics of CafeOBJ andPeano Style Natural NumbersFUTATSUGI, Kokichi二木 厚吉JAIST

Topics Basic concepts for modeling, specification,verification in CafeOBJ Basics of CafeOBJ language system: module,signature, equation, expression/term, reduce,parse Specification and verification of Peano stylenatural numbers2

Modeling, Specifying, and Verifying in CafeOBJ1. By understanding a problem to be modeled/specified, determine several sorts of objects(entities, data, agents, states) and operations(functions, actions, events) over them fordescribing the problem2. Define the meanings/functions of theoperations by declaring equations overexpressions/terms composed of the operations3. Write proof scores for properties to be verified3

Natural Numbers -- Signature -0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 s(0) s(s(0)) s(s(s(0))) s(s(s(s(0)))) objects:operations:Nat0 : returns zero without argumentss : if given a natural number n, returns thenext natural number (s n) of n-- sort[ Nat ]--constructor operatorsop 0 : - Nat {constr}op s : Nat - Nat {constr}0NatS4

Natural Number-- Expressions/terms composed of operators1. 0 is a natural number2. If n is natural number then (s n) is a naturalnumber3. An object which is to be a natural number by 1 and 2is only a natural numberPeano’s definition of natural numbers (1889), Giuseppe Peano (1858-1932)Nat {0, s(0), s(s(0)), s(s(s(0))), s(s(s(s(0)))) }Nat {0, s 0, s s 0, s s s 0, s s s s 0, }Describe a concept in expressions/terms!5

CafeOBJ module specifying PNAT-- Peano Style natural numbersmod! PNAT {[ Nat ]op 0 : - Nat {constr} .op s : Nat - Nat {constr} .--eqeqop : Nat Nat - Bool {comm} .eq (N:Nat N) true .(0 s(N2:Nat)) false .(s(N1:Nat) s(N2:Nat)) (N1 N2) .}Constructors (indicated by {constr}) define recursivelythe set of terms which constitute a sort.6

Natural numbers-- signature and expressions/terms-- sort[ Nat ]-- operationsop 0 : - Nat {constr}op s : Nat - Nat {constr}S0NatNat { 0 } { s n n Nat }7

Mathematical Induction over Natural Numbers (1)The recursive structure defined by two constructorsof sort Nat induces the following induction scheme.Goal: Prove that a property P(n) is truefor any natural number n {0, s 0, s s 0, }Induction Scheme:P(0) n N.[P(n) P(s n)] n N.P(n)Concrete Procedure: (induction with respect to n)1. Prove P(0) is true2. Assume that P(n) holds,and prove that P(s n) is true8

Mathematical Induction over Natural Numbers (2)Induction BaseInduction Step 9

Natural numbers with addition operation-- signature and expressions/terms-- sort[ Nat ]-- operationsop 0 : - Nat {constr}op s : Nat - Nat {constr}op : Nat Nat - Nat-- is a defined operatorNat { 0 } { s n n Nat }S0Nat NatExp { 0 } { s n n Nat } { n1 n2 n1 Nat n2 Nat }10

Natural numbers with addition-- equations define meaning/functionCafeOBJ module PNAT definingPeano Natural numbers with additionComputation/inferencewith the equationsmod! PNAT {pr(PNAT)op : Nat Nat - Nat .vars N1 N2 : Nat .-- equationseq 0 N2 N2 .eq (s N1) N2 s(N1 N2) .}(s s 0) (s 0) s((s 0) (s 0)) s s(0 (s 0)) s s s 0Defined operator ( ) iserased by the two equations.CafeOBJ select PNAT PNAT red s s 0 s 0 .PNAT -- reduce in PNAT :((s (s 0)) (s 0)):Nat(s (s (s 0))):Nat(0.000 sec for parse,3 rewrites(0.000 sec),5 matches)Sufficient Completeness11

Natural numbers with addition-- expressions/terms composed by operatorsNatExp {0, s 0, s s 0, s s s 0, . ,0 0, 0 (s 0), 0 (s s 0), 0 (s s s 0), .,(s 0) 0, (s 0) (s 0), (s 0) (s s 0),(s 0) (s s s 0), .,(s s 0) 0, (s s 0) (s 0), (s s 0) (s s 0),(s s 0) (s s s 0), .,. .0 (0 0), 0 (0 (s 0)), .(0 0) 0, (0 (s 0)) 0, . }Because is a defined operator, any operator issupposed to be eliminated. That is, NatExp Nat .12

Reduction of CafeOBJ ishonest to equational reasoning The basic mechanism of CafeOBJ verification isequational reasoning. Equational reasoning is todeduce an equation (a candidate of a theorem)from a given set of equations (axioms of aspecification). The CafeOBJ system supports an automaticequational reasoning based on term rewriting. “reduce” or “red” command of CafeOBJ helps todo equational reasoning by term rewriting.13

What can be done withred (reduction) command?Let us fix a context M (a module M in CafeOBJ), and let(t1 *M t2) denote that t1 is reduced to t2 in thecontext. That is, (red in M : t1 .) returns t2 .Let (t1 M t2) denote that t1 is equal to t2 in thecontext M. That is (t1 t2) can be inferred byequational reasoning in M. It is important to notice:( t1 *M t2 ) implies ( t1 M t2 )but( t1 M t2 ) does not implies ( t1 *M t2 )14

Proof score for right zero property:(N:Nat 0 N)-- proof by induction with respect to N:Nat-- induction base case:-- opening module PNAT to make use of all its contentsopen PNAT red 0 0 0 .close-- induction step case:open PNAT -- declare that the constant n stands for any Nat valueop n : - Nat .-- induction hypothesis:eq n 0 n .-- induction step proof for (s n):red s n 0 s n .close15

Declaring constants and equations then reduceWhile a module is opened, declaring constants and equationsrepresents assumptions for equational reasoning done by red.%PNAT op n : - Nat .%PNAT ** induction hypothesis:%PNAT eq n 0 n .%PNAT ** induction step proof for (s n):** induction step proof for (s n):%PNAT red s n 0 s n .*-- reduce in %PNAT : (((s n) 0) (s n)):Bool(true):BoolThis is a proof of N:Nat.[(N 0) N implies ((s N) 0) (s N) ].16

Proof score for associativity of ( )(N1:Nat N2:Nat) N3:Nat N1 (N2 N3)** induction base case:open PNAT red 0 ( n2:Nat n3:Nat) (0 n2) n3 .Close** induction step case:open PNAT ** declare that the constant n1 stands for any Nat valueop n1 : - Nat .** induction hypothesis:eq (n1 N2:Nat) N3:Nat n1 (N2 N3) .** induction step proof for (s n1):red ((s n1) n2:Nat) n3:Nat (s n1) ( n2 n3) .close17

CommentsA line beginning with “--” (or “**”) is ignored, andA line beginning with “-- ” (or “** ”) is echoed back.CafeOBJ -- this is a commentCafeOBJ CafeOBJ ** this is a commentCafeOBJ CafeOBJ -- this is a comment-- this is a commentCafeOBJ CafeOBJ ** this is a comment** this is a commentCafeOBJ It is very important to write as much appropriatecomments as possible for explaining specificationsand proof scores (verifications/proofs).18

Three kinds of modulesCafeOBJ specification is composed of modules.There are three kinds of modules.mod! module name { modlue element *}mod* module name { modlue element *}mod module name { modlue element *}mod! declares that the module denotes tight denotationmod* declares that the module denotes loose denotationmod does not declare any semantic denotation[Naming convention] module name starts with two successiveupper case characters(example:TEST, NAT, PNAT ,ACCOUNT-SYS, )19

A module is composed ofsignature and axioms/equationsmod! PNAT {[ Nat ]op 0 : - Nat {constr} .op s : Nat - Nat {constr} .op : Nat Nat - Bool {comm} .eq (N:Nat N) true .eq (0 s(N2:Nat)) false .eq (s(N1:Nat) s(N2:Nat)) (N1 N2) .signatureaxioms/equations}20

Signature:sort name, operator name, arity, co-arity, rankA signature is a pair of a set of sorts and a set of operations.Signaturemod* PNAT {[Nat]op 0 : - Nat {constr}op s : Nat - Nat {constr}op : Nat Nat - Bool {comm}. }sortsoperators[Convention] The first and second letter of a sort name is written in aupper case and lower case letter respectively. (E.g. Nat, Set)[Convention] The first letter of an operation name is written in alowerl case letter or a non-alphabet letter. (E.g. 0, s, )op : Nat Nat - Boolarityco-arityrank21

Order sorted signature and sorted terms-- Natural numbers with predecessor function-- signature-- sorts[ NzNat Nat ]-- operatorsop 0 : - Nat {constr}op s : Nat - NzNat {constr}op p : NzNat - Nateq p s N:Nat N .s0Sorted termsNzNat {s n n Nat}Nat {0} NzNat {p n n NzNat}(p 0) is handled as an error!NzNatNatp22

Recursive definition of terms- term is also called expression or treeFor a given signature, t is a term of a sort S if andonly if t is a variable X:S, a constant c declared by “op c : - S”, or a term f(t1, ,tn) for “op f : S1 Sn - S”and a term ti of a sort Si (i 1, ,n). a term of a sort S’ which is a sub-sort of S(Example: Since NzNat Nat, a term (s 0)ofsort NzNat is also a term of sort Nat)23

Several forms of function application:standard, prefix, infix, postfix, distfixop f : Nat Nat - Nat .f(2,3) standardop f : Nat Nat - Nat .(f 2 3) prefixop : Nat Nat - Nat .(2 3) infixop ! : Nat - Nat .(5 !)postfixop if then else fi : Bool Nat Nat - Nat .(if 2 3 then 4 else 5 fi) distfix“(“ and “)” are meta-charactors for grouping expressionsin CafeOBJ and can not be used for any other purpose.24

Parsing – precedence of operatorss 0 0 represents (s 0) 0, because theoperator s has high precedence than theoperator s 0 0 sThe preceedences of theoperators can be checked bythe commandss0describe op sdescribe op 00(s 0) 00s(0 0)25

EquationAn equation is a pair of terms of a same sort, andwritten as:eq l r .in CafeOBJ. Where l is called the left-handside (LHS) of the equation and r is the righthand side (RHS). An equation can have acondition (COND, a Boolean term) c like:ceq l r if c . Properties to be verified are also expressed asequations.26

Conditions for an equation to be a rewriting ruleFor an equation to be used as a rewriting rule fordoing reductions, the following conditions must besatisfied.(1) LHS is not a variable.an example violating this condition:eq N:Nat N:Nat 0 .(2) All variables in RHS are in LHS.an example violating this condition:eq 0 N:Nat * 0 .27

Two way of declaring variables- use appropriate one based on the situationVariable can be declared in an equation directly. Thescope of the variable ends at the end of the equation.mod! PNAT { [Nat] eq0 N2:Nat N2 .eq (s N1:Nat) N2:Nat s(N1 N2) . }Variables can be declared before equations. This is justabbreviation for saving many variable declarations in theequations. N2 in the first eq has nothing to do with N2 inthe second eq .mod! PNAT { [Nat]vars N1 N2 : Nateq0 N2 eq (s N1) N2 .N2 .s(N1 N2) . }28

Constant v.s. variableUsing a variable in an equation instead of a constant makes adrastic change of meaning of the proof score. Be careful! The scope of a constant is to the end of a open-closesession assuming that the declared constants are fresh. The scope of a variable is inside of the equation.open PNAT op n : - Nat .eq n 0 n .red (s n) 0 s n .closeConstant:Variable: N:Nat.open PNAT var N : Nat .eq N 0 N .red (s n:Nat) 0 s n .close[(N 0) N ((s N) 0) (s N)] N:Nat.[(N 0) N ] N:Nat.[((s N) 0) (s N)]29

Two equality predicates and Assume that ( t1 * t1’ ) and ( t2 * t2’ ) in any contextthenif ( t1’ and t2’ are the same term )then ( red t1 t2 . ) returns trueand( red t1 t2 . ) returns trueif ( t1’ and t2’ are different terms )then ( red t1 t2 . ) returns ( t1’ t2’ )but( red t1 t2 . ) returns falseIf reduction/rewriting is not complete w.r.t. a set ofequations, may returns false even if two termsmay have a possibility of being equal w.r.t. the set ofequations.30

Exercisemod! PNAT * { pr(PNAT)vars X Y Z : Nat .op : Nat Nat - Nat {prec: 30}eq 0 Y Y .eq s(X) Y s(X Y) .op * : Nat Nat - Nat {prec: 29}eq 0 * Y 0 .eq s(X) * Y Y (X * Y) .}Write proof scores to verify that binary operators and * in PNAT * are associative and commutative.Write also proof scores to verify that * distributesover , that is(N1 N2) * N3 (N1 * N3) (N2 * N3) .31

- term is also called expression or tree For a given signature, t is a term of a sort S if and only if t is a variable X:S, a constant c declared by “op c : - S”, or a term f(t 1, ,t n) for “op f : S 1 S n- S” and a term t i of a sort S i (i 1, ,n). a term of a sort S’ which is a sub-sort of S

Related Documents:

du Seuil, 1982, 226-251. Des monstres de Cantor et Peano à la géométrie fractale de la nature Benoît Mandelbrot Texte basé sur une conférence au séminaire de Philosophie et Mathématiques de l'École Normale Supérieure, le 20 juin 1977. La première étincelle de la théorie des fractales jaillit il y a cent ans, le 20

Python Basics.ipynb* Python Basics.toc* Python Basics.log* Python Basics_files/ Python Basics.out* Python_Basics_fig1.pdf* Python Basics.pdf* Python_Basics_fig1.png* Python Basics.synctex.gz* Python_Basics_figs.graffle/ If you are reading the present document in pdf format, you should consider downloading the notebook version so you can follow .

Basics 2 7.2 kV Bus 1-Line : Basics 3 4.16 kV Bus 1-Line : Basics 4 600 V 1-Line : Basics 5 480 V MCC 1-Line : Basics 6 7.2 kV 3-Line Diagram : Basics 7 4.16 kV 3-Line Diagram

Automotive Basics - Course Description "Automotive Basics includes knowledge of the basic automotive systems and the theory and principles of the components that make up each system and how to service these systems. Automotive Basics includes applicable safety and environmental rules and regulations. In Automotive Basics, students will gain

Unit 3 SQL language: basics DBMG 2 SQL language: basics Introduction The SELECT statement: basics Nested queries Set operators Update commands Table management. Databases SQL language: basics Elena Baralisand Tania Cerquitelli 2013 Politecnico

Corrado Segre (1863-1924) Guido Castelnuovo (1865-1952) Federigo Enriques (1871-1946) Tullio Levi-Civita (1873-1941) Several of them are graduates of the Scuola Normale in Pisa. All of them except Ricci, Bianchi and Peano are Jewish. Ricci and L

tions of mathematics [10, p. 254{258]. This resulted in an epochal work, Principia Mathematica, which would later be recognized as a signi cant contribution to logic and the foundations of math-ematics. In uenced by the work of Frege, Peano, and Schr oder, Russell and Whitehead developed

American Revolution has fallen into the condition that overtakes so many of the great . 4 events of the past; it is, as Professor Trevor-Roper has written in another connection, taken for granted: "By our explanations, interpretations, assumptions we gradually make it seem automatic, natural, inevitable; we remove from it the sense of wonder, the unpredictability, and therefore the freshness .