110 likes | 117 Views
This article introduces the formalization of an oscilloscope, providing a high-level, implementation-independent specification and formal semantics using the Z notation. It emphasizes the importance of formal methods for precise, consistent, and complete analysis. The article covers sets, functions, first-order logic, schemas, and their application to modeling an oscilloscope.
E N D
On Formalism • High-level (implementation-independent) specification • Recall: Larch – An Algebraic Formal Spec. Lang. • Why formal? Precise, consistent, and complete • Formal semantics: Formal = grammar, e.g., syllogism All persons die. Adam is a person ------------------------ Adam dies. Semantics?
Introduction to Z • Based on typed set theory and first order logic • Sets: • oneTwoThree == {1, 2, 3} • Person == {Adam, Eve} S: P X == 2 X--- S is a set of X’s powerset, i.e., the set of all subsets of X • oneTwoThreeSet == P oneTwoThree == P {1, 2, 3} == ? • personSet == P person == P {Adam, Eve} == ? • |P X| == ?
Introduction to Z • Sets (cont’d) • x memberOf S ? 1 memberOf {1, 2, 3} ? 1 memberof P {1, 2, 3} ? {1} memberof P {1, 2, 3} ? Adam memberOf P Person ? Adam memberOf Person ? {Adam, Eve} memberOf P Person
Introduction to Z • Sets (cont’d) • S subsetOf S’ ? 1 subsetOf {1, 2, 3} ? {1, 2} subsetOf P {1, 2, 3} ? {{1, 2}} subsetOf P {1, 2, 3} ? Adam subsetOf P Person ? Adam subsetOf Person ? Person subsetOf Person ? {Person} subsetOf P Person
Introduction to Z • Sets (cont’d) • S X S’ (cross/cartesian product) oneTwoThree X person == {1, 2, 3} X {Adam, Eve} == {{1, Adam}, {1, Eve}, {2, Adam}, {2, Eve}, {3, Adam}, {3, Eve}} ? {1, 2} subsetOf {1, 2} X {1, 2} • S U S’, S intersect S’, S\S’, etc. (skip)
Introduction to Z • Functions • dom f --- The set of values x for which f(x) is defined f(x) = x 2 , dom f = {n memberOf N| 1 <= n <= 5} • ran f --- The set of values taken by f(x), where x memberOf dom f ran f = ? • f: X -> Y --- f is a total function from X to Y i.e., f is defined for all x memberOf dom(f), i.e., dom(f) = X • f: X -|-> Y --- f is a partial function from X to Y i.e., f is defined for some values in X if f(x) = 1/x, ? dom(f) = Z ? spouse: Person -> Person
Introduction to Z • Functions (cont’d) • (lambda x: T . t) returns the value of the term t (lambda x: N . X 2 ) 5 == 25 (lambda x: N . (X 2 , 1/x) == ? (lambda x, y: N . (X 2 + y, y -1/x) 5 1 == ?
Introduction to Z • First Order Logic • Logical connectives: AND, OR, NOT, =>, <=> • Quantifiers ? Exists n: N . n = n 2 ? Exists p: Person . P == father (Adam) ? Forall i: N . I 2 >= I ? Forall I, j: N . I > j => I 2 > j 2 ? Forall x, y: Person, x == spouse(y) <=> y == spouse(x)
Introduction to Z • Schemas A schema consists of a set of declarations olf variables and a predicate constraining these variables (i.e., state space and operations) ----- BirthdayBook ---------------------------------------- | known: P Person | birthday: Person -|-> Date ----------------------------------------------------------------- | known = dom birthday ----------------------------------------------------------------- One possible state: known = {Adam, Eve} birthday = {Adam |-> Apr/01, Eve |-> Apr/01}
A Simple Oscilloscope • Overview