130 likes | 155 Views
Learn how to formalize ADT specifications, including types, functions, axioms, and preconditions. Ensure completeness, correctness, and consistency in ADT specifications.
E N D
ADT • Formalizing the specifications • The need to know precisely how operations can be used by clients and what they will do • The ADT specification consists of • Types • Functions • Axioms • Preconditions
ADT (cont.) • An ADT specification is a formal, mathematical description rather than a software text. • The axioms and preconditions express the semantics of a type and are essential to a full, unambiguous description
Types • Indicates the types being specified • Simply lists the types introduced in the specification
Functions • Lists operations applicable to instances of the ADT • Each line introduces a mathematical function modeling one of the operations on the ADT • We may have • Operation which may modify objects • Creators • queries
Partial functions • The domain of a partial function is the subset containing those elements for which the function yields a value • partial functions may reflect that not every operation is applicable to every object
Axioms • A way of implicit definition (free of representation) • State the properties of function values(and not giving the value itself) • We may have • predicates (expressing that a property is always true for every possible value) • Definition of ADT behavior
Preconditions • An ADT specification which includes partial functions must specify the domain of each of them • For each function, the require clause indicates what conditions the function’s arguments must satisfy to belong to the function’s domain • Every partial function has a precondition
Is the specification complete? • Is there any way to be sure that a specification describes all relevant properties of the objects it is intend to cover? • A “well formed” expression simply indicates whether all functions in an expression have the right number and types of arguments
Correctness • In case there are no preconditions, every well formed expression is correct • Otherwise … we shall prove (in a recursive way) that for any expression of the form f(x1,…,xn) all xj are correct, and their values satisfy the precondition of f
Sufficient completeness • Checks if all axioms of the theory make it possible to solve the following problems for any well-formed expression e: • Determines whether e is correct • If e is a query expression and has been shown to be correct, express e’s value under a form not involving any value of the ADT type(i.e. use other types such as booleans and literals)
Sufficient completeness (cont.) • A useful practical guideline to check that no important property has left out of a specification • Some steps: • Any query expression must have the form q(e), where q is one of the query functions, and e is an expression of our ADT • We will treat each query function separately, and will prove the claim by induction on the structure of the ADT expression e • The base case is the creator expression of the ADT • Prove that all defined and deduced queries can be computed
Consistency • For any well formed query expression e, the axioms make it possible to infer at most one value for e