1 Logic Our ability to state invariants, record preconditions and post- conditions, and the ability to reason about a formal model depend on the logic.

Slides:



Advertisements
Similar presentations
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Advertisements

Agents That Reason Logically Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2004.
L41 Lecture 2: Predicates and Quantifiers.. L42 Agenda Predicates and Quantifiers –Existential Quantifier  –Universal Quantifier 
F22H1 Logic and Proof Week 7 Clausal Form and Resolution.
Knowledge Representation Methods
Computability and Complexity 8-1 Computability and Complexity Andrei Bulatov Logic Reminder.
Logic in general Logics are formal languages for representing information such that conclusions can be drawn Syntax defines the sentences in the language.
Propositional Logic. Negation Given a proposition p, negation of p is the ‘not’ of p.
From Chapter 4 Formal Specification using Z David Lightfoot
Discrete Mathematics Math 6A Instructor: M. Welling.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Logical Agents Chapter 7 Feb 26, Knowledge and Reasoning Knowledge of action outcome enables problem solving –a reflex agent can only find way from.
CSE115/ENGR160 Discrete Mathematics 01/20/11 Ming-Hsuan Yang UC Merced 1.
Propositional Calculus Math Foundations of Computer Science.
Adapted from Discrete Math
Predicates and Quantifiers
True or False Unit 3 Lesson 7 Building Blocks of Decision Making With Additions & Modifications by Mr. Dave Clausen True or False.
2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of Proofs.
Discrete Mathematics and Its Applications
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
Copyright © Curt Hill Truth Tables A way to show Boolean Operations.
Theoretical basis of GUHA Definition 1. A (simplified) observational predicate language L n consists of (i) (unary) predicates P 1,…,P n, and an infinite.
Formal Methods in SE Lecture 20. Agenda 2  Relations in Z Specification Formal Methods in SE.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Chapter 1, Part II: Predicate Logic With Question/Answer Animations.
1 Logical Agents CS 171/271 (Chapter 7) Some text and images in these slides were drawn from Russel & Norvig’s published material.
TIVDM1Modelling unordered collections1 Peter Gorm Larsen.
TIVDM1VDMTools and Logic1 Peter Gorm Larsen. TIVDM1VDMTools and Logic2 Agenda  Overview of VDMTools ® Functionality Demonstration of VDMTools ® and Rational.
TIVDM1Development process, Logic and VDMTools and Eclipse 1 RT development process, Logic and VDMTools and Eclipse support Peter Gorm Larsen.
First-Order Logic Introduction Syntax and Semantics Using First-Order Logic Summary.
Nesting Quantifiers And Their Manipulation Copyright © Curt Hill.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
1 Logical Agents CS 171/271 (Chapter 7) Some text and images in these slides were drawn from Russel & Norvig’s published material.
Logical Agents Chapter 7. Outline Knowledge-based agents Logic in general Propositional (Boolean) logic Equivalence, validity, satisfiability.
TIVDM1RT Development process, Abstract Syntax Trees and Logic 1 RT development process, Abstract Syntax Trees and Logic Peter Gorm Larsen
Thinking Mathematically
Fall 2008/2009 I. Arwa Linjawi & I. Asma’a Ashenkity 1 The Foundations: Logic and Proofs Predicates and Quantifiers.
CS 285- Discrete Mathematics Lecture 4. Section 1.3 Predicate logic Predicate logic is an extension of propositional logic that permits concisely reasoning.
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
Restrictions Objectives of the Lecture : To consider the algebraic Restrict operator; To consider the Restrict operator and its comparators in SQL.
Discrete Mathematics Mathematical reasoning: think logically; know how to prove Combinatorial analysis: know how to count Discrete structures: represent.
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
PREDICATES AND QUANTIFIERS COSC-1321 Discrete Structures 1.
Section 1.4. Propositional Functions Propositional functions become propositions (and have truth values) when their variables are each replaced by a value.
Propositional Logic. Assignment Write any five rules each from two games which you like by using propositional logic notations.
Propositional and predicate logic
Chapter 1. Chapter Summary  Propositional Logic  The Language of Propositions (1.1)  Logical Equivalences (1.3)  Predicate Logic  The Language of.
Logical Agents. Inference : Example 1 How many variables? 3 variables A,B,C How many models? 2 3 = 8 models.
CENG 424-Logic for CS Introduction Based on the Lecture Notes of Konstantin Korovin, Valentin Goranko, Russel and Norvig, and Michael Genesereth.
Chapter 7. Propositional and Predicate Logic
Formal Methods in SE Lecture 21.
CSE15 Discrete Mathematics 01/23/17
Bool operators and, or, not
Niu Kun Discrete Mathematics Chapter 1 The Foundations: Logic and Proof, Sets, and Functions Niu Kun 离散数学.
EA C461 – Artificial Intelligence Logical Agent
Chapter 4: Decision Structures and Boolean Logic
The Foundations: Logic and Proofs
Principles of Computing – UFCFA3-30-1
CLASSICAL LOGIC and FUZZY LOGIC
Chapter 8 Logic Topics
Chapter 4: Decision Structures and Boolean Logic
Discrete Mathematics and Its Applications Kenneth H
Discrete Mathematics Lecture 2: Propositional Logic
Chapter 7. Propositional and Predicate Logic
Predicates and Quantifiers
Logic Logic is a discipline that studies the principles and methods used to construct valid arguments. An argument is a related sequence of statements.
Chapter 4: Decision Structures and Boolean Logic
Logical Agents Prof. Dr. Widodo Budiharto 2018
Presentation transcript:

1 Logic Our ability to state invariants, record preconditions and post- conditions, and the ability to reason about a formal model depend on the logic on which the modelling language is based. Classical logical propositions and predicates Connectives Quantifiers Handling undefinedness: the logic of partial functions

2 The temperature monitor example Temperature (C) Time (s) The monitor records the last five temperature readings

3 The temperature monitor example The following conditions are to be detected by the monitor: Rising: the last reading in the sample is greater than the first Over limit: there is a reading in the sample in excess of 400 C Continually over limit: all the readings in the sample exceed 400 C Safe: If readings do not exceed 400 C by the middle of the sample, the reactor is safe. If readings exceed 400 C by the middle of the sample, the reactor is still safe provided that the reading at the end of the sample is less than 400 C. Alarm: The alarm is to be raised if and only if the reactor is not safe Formal Model of the monitor: Monitor :: temps : seq of int alarm : bool inv m == len m.temps = 5

4 Predicates Propositions Predicates are simply logical expressions. The simplest kind of logical predicate is a proposition. A proposition is a logical assertion about a particular value or values, usually involving a Boolean operator to compare the values, e.g. 3 < 275 = 9 Propositions are normally either true or false … but in VDM they can also be undefined.

5 Predicates General predicates A predicate is a logical expression that is not specific to particular values but contains variables which can stand for one of a range of possible values, e.g. x < 27 (x**2) + x - 6 = 0 The truth or falsehood of a predicate depends on the value taken by the variables.

6 Predicates Predicates in the monitor example Monitor :: temps : seq of int alarm : bool inv m == len m.temps = 5 Consider a monitor m. m.temps is a sequence so we can index into it: First reading in m : m.temps(1) Last reading in m : m.temps(5) Predicate stating that the first reading in m is strictly less than the last reading: m.temps(1) < m.temps(5) The truth of the predicate depends on the value of m.

7 Predicates The rising condition The last reading in the sample is greater than the first Monitor :: temps : seq of int alarm : bool inv m == len m.temps = 5 We can express the rising condition as a Boolean function: Rising: Monitor -> bool Rising(m) == m.temps(1) < m.temps(5) For any monitor m, the expression Rising(m) evaluates to true iff the last reading in the sample in m is higher than the first, e.g. Rising( mk_Monitor([233,45,677,650,900], false) )

8 Basic logical operators We build more complex logical expressions out of simple ones using logical connectives: not negation and conjunction or disjunction => implication (if … then …) biimplication (if and only if)

9 Basic logical operators Negation Negation allows us to state that the opposite of some logical expression is true, e.g. The temperature in the monitor m is not rising: not Rising(m) A true false not A false true Truth table for negation:

10 Basic logical operators Disjunction Disjunction allows us to express alternatives that are not necessarily exclusive: Over limit: There is a reading in the sample in excess of 400 C OverLimit: Monitor -> bool OverLimit(m) == m.temp(1)>400 or m.temp(2)>400 or m.temp(3)>400 or m.temp(4)>400 or m.tempt(5)>400 A true false B true false true false A or B true false

11 Basic logical operators Conjunction Conjunction allows us to express the fact that all of a collection of facts are true. Continually over limit: all the readings in the sample exceed 400 C COverLimit: Monitor -> bool COverLimit(m) == m.temps(1) > 400 and m.temps(2) > 400 and m.temps(3) > 400 and m.temps(4) > 400 and m.temps(5) > 400 A true false B true false true false A and B true false

12 Basic logical operators Implication Implication allows us to express facts which are only true under certain conditions (“if … then …”): Safe: If readings do not exceed 400 C by the middle of the sample, the reactor is safe. If readings exceed 400 C by the middle of the sample, the reactor is still safe provided that the reading at the end of the sample is less than 400 C. Safe: Monitor -> bool Safe(m) == m.temp(3)>400 => m.temp(5)<400 A true false B true false true false A => B true false true

13 Basic logical operators Biimplication Biimplication allows us to express equivalence (“if and only if”). Alarm: The alarm is to be raised if and only if the reactor is not safe This can be recorded as an invariant property: Monitor :: temps : seq of int alarm : bool inv m == len m.temps = 5 and not Safe(m.temp) m.alarm A true false B true false true false A B true false true

14 Quantifiers For large collections of values, using a variable makes more sense than dealing with each case separately. inds m.temps represents indices (1-5) of the sample The “over limit” condition can then be expressed more economically as: exists i in set inds m.temps & temps(i) > 400 The “continually over limit” condition can then be expressed using “ forall ”: forall i in set inds m.temps & temps(i) > 400

15 Quantifiers Syntax: forall binding & predicate exists binding & predicate There are two types of binding: Type Binding, e.g. x:nat n: seq of char Set Binding, e.g. i in set inds m x in set {1,…,20} A type binding lets the bound variable range over a type (a possibly infinite collection of values). A set binding lets the bound variable range over a finite set of values.

16 Quantifiers Several variables may be bound at once by a single quantifier, e.g. forall x,y in set {1,…,5} & not m.temp(x) = m.temp(y) Would this predicate be true for the following value of m.temp ? [320, 220, 105, 119, 150]

17 Quantifiers Exercises All the readings in the sample are less than 400 and greater than 50. forall i in set inds m.temps & m.temps(i) 50 Each reading in the sample is up to 10 greater than its predecessor. forall i in set inds m.temps & m.temps(i+1) >= (m.temps(i) + 10)

18 Quantifiers Exercises There are two distinct readings in the sample which are over 400. exists i,j in set inds m.temps & i <> j => m.temps(i)>400 and m.temps(j)>400

19 Quantifiers Suppose we have to formalise the following property: There is a “single minimum” in the sequence of readings, i.e. there is a reading which is strictly smaller than any of the other readings. Suppose the order of the quantifiers is reversed. exists min in set inds m.temps & forall i in set inds m.temps & i <> min => m.temps(i) > m.temps(min)

20 Summary Propositions Predicates involve free variables Predicates may be combined using connectives Free variables can range over collections of values, using quantifiers Quantifiers can be mixed forall n in set {10, …, 20} & exists p:nat & 2*p = n

21 LPF: coping with undefinedness Suppose sensors can fail in such a way that they generate the value Error instead of a valid temperature. In this case we can not make comparisons like Error < 400 The logic in VDM is equipped with facilities for handling undefined applications of operators (e.g. if division by zero could occur). Truth tables are extended to deal with the possibility that undefined values can occur, e.g. A true false * not A false true * * represents the undefined value

22 Disjunction in LPF A true false * B true false * true false * true false * A or B true false * true * If one disjunct is true, we know that the whole disjunction is true, regardless of whether the other disjunct is true, false or undefined.

23 Conjunction in LPF A true false * B true false * true false * true false * A and B true false * false * false * If one conjunct is false, we know that the whole conjunction is false, regardless of whether the other disjunct is true, false or undefined.

24 Implication and Biimplication in LPF A true false * B true false * true false * true false * A => B true false * true * A true false * B true false * true false * true false * A B true false * false true *