180 likes | 281 Views
Predicate Logic for software Engineers. Sagnik Bhattacharya Siddharth Dalal. Why logic in software engineering?. Engineers need mathematical tools. Theoretical, yet quantitative study of software. Parnas says so….
E N D
Predicate Logic for software Engineers Sagnik Bhattacharya Siddharth Dalal
Why logic in software engineering? • Engineers need mathematical tools. • Theoretical, yet quantitative study of software. • Parnas says so…. From a drop of water a logician could infer the possibility of an Atlantic or a Niagara without having seen or heard of one or the other. - Sir Arthur Conan Doyle
Problems with existing logic • Logicians are conservative? • Lacks precise meaning for logical expression. (* values) • Complexity of expressions. • Assumption of total functions. There can never be surprises in logic.
Parnas Proposes…. • Get rid of *(maybe) values. • Use partial functions. • Make use of bounded quantification optional. 'Contrariwise', continued Tweedledee, 'if it was so, it might be, and if it were so, it would be; but as it isn't, it ain't. That's logic!' - Lewis Carroll - Alice in Wonderland
Basics • Predicate – A predicate is a feature which we can use to make a statement about something. “Peter is tall” • The property that an animal is a dog can be expressed by the predicate: dog(x) This predicate holds for all animals x which are dogs. For other animals, the predicate is false Logic is the art of going wrong with confidence.
Propositional Logic • A proposition is a language construct which can be assigned a truth value • More complex propositions can be formed by applying the logical operators (¬, , , etc..) • Propositional logic formula • Eg. ¬((a b) c) Against logic there is no armor like ignorance.
Predicate Logic • Predicate logic is a more powerful formalism which is obtained by extending propositional logic with • “Predicates” which describe properties or relations of objects in a certain domain ; • “variables” ranging over arbitrary domains; • the possibility to quantify over “variables”. Logic: The art of thinking and reasoning in strict accordance with the limitations and incapacities of the human misunderstanding.
Quantifiers • We distinguish two quantifiers: • universal quantifier: • existential quantifier: The grand aim of all science is to cover the greatest number of empirical facts by logical deduction from the smallest number of hypotheses or axioms.
Quantifiers • We distinguish two quantifiers: • universal quantifier: • existential quantifier: • Example: • There exists an integer x divisible by 5. x | divisible_by(x,5) • All integers y are divisible by 1. y | divisible_by(y,1) The grand aim of all science is to cover the greatest number of empirical facts by logical deduction from the smallest number of hypotheses or axioms.
Tuples • U = {true, false} • Simple n-tuple • Ordered list of n members of U Eg. <true, false, true, true> • n-tuple • Ordered list of n simple tuples • Eg. <<true, false>, true, <false, true>> Logic works, metaphysics contemplates.
Exercise • <<true, false, <true, false>>, true, <true, <false, true>>> • 3-tuple (not simple) • “true”, “<true>”, “<<true>>” • Equivalent simple 1-tuple!! The fact that logic cannot satisfy us awakens an almost insatiable hunger for the irrational.
Relations and Functions • Difference? • Function can’t be one-to-many. • Partial vs. Total Functions • Partial functions not defined for all values in domain e.g. Division over integer domain not defined for 0 The want of logic annoys. Too much logic bores. Life eludes logic, and everything that logic alone constructs remains artificial and forced.
Predicates Revisited • Predicate – function whose range contains no member other than true and false • Characteristic Predicate (R) • X=set of simple tuples • Sk=set of all simple k-tuples • S=S1S2 …….. Su • u=length of largest tuple in X • R is a predicate whose domain is S and for every b X the value of R is true There can never be surprises in logic.
Primitive Expressions • Primitive Expression is a string of the form R(V) • R is a characteristic predicate • V is a list of comma separated terms (called arguments) e.g. divisible_by(x, 5) Logic is like the sword--those who appeal to it, shall perish by it.
Predicate Expressions • All primitive expressions are predicate expressions. • If P, Q: predicate expressions, x: variable, then following are also predicate expressions: • (x , P) – (P) • (P) (Q) – (P) (Q) • ¬(P) • There are no other predicate expressions. • What about (x , P) ??? Logic is neither a science or an art, but a dodge.
Use in Documentation Logic merely enables one to be wrong with authority.
Use in Documentation • What next after simple search? • Palindrome • (m, (i, 0<=i<n B[m+i]=N[m+n-1-i])) • A7E?? • Where in Documentation? • What about non-inspection operations? Logic, like whiskey, loses its beneficial effect when taken in too large quantities.
Conclusion • Keep it Simple • Was the use of this type of logic useful? • What about more complicated programs? • Was it more precise? • Was it easier to understand? You can only find truth with logic if you have already found truth without it.