Logic in computer science

Similar documents
Application of a Stochastic-Fuzzy Approach to Modeling Optimal Discrete Time Dynamical Systems by Using Large Scale Data Processing

Lecture 2-1 Kinematics in One Dimension Displacement, Velocity and Acceleration Everything in the world is moving. Nothing stays still.

An Excursion into Set Theory using a Constructivist Approach

EE 315 Notes. Gürdal Arslan CLASS 1. (Sections ) What is a signal?

Lecture 20: Riccati Equations and Least Squares Feedback Control

An introduction to the theory of SDDP algorithm

Lecture Notes 2. The Hilbert Space Approach to Time Series

Longest Common Prefixes

A NOTE ON THE STRUCTURE OF BILATTICES. A. Avron. School of Mathematical Sciences. Sackler Faculty of Exact Sciences. Tel Aviv University

Retrieval Models. Boolean and Vector Space Retrieval Models. Common Preprocessing Steps. Boolean Model. Boolean Retrieval Model

Expert Advice for Amateurs

Overview. COMP14112: Artificial Intelligence Fundamentals. Lecture 0 Very Brief Overview. Structure of this course

11!Hí MATHEMATICS : ERDŐS AND ULAM PROC. N. A. S. of decomposiion, properly speaking) conradics he possibiliy of defining a counably addiive real-valu

KINEMATICS IN ONE DIMENSION

2. Nonlinear Conservation Law Equations

We just finished the Erdős-Stone Theorem, and ex(n, F ) (1 1/(χ(F ) 1)) ( n

Physics 235 Chapter 2. Chapter 2 Newtonian Mechanics Single Particle

Matrix Versions of Some Refinements of the Arithmetic-Geometric Mean Inequality

Physical Limitations of Logic Gates Week 10a

Homework sheet Exercises done during the lecture of March 12, 2014

4 Sequences of measurable functions

Optimality Conditions for Unconstrained Problems

Almost Sure Degrees of Truth and Finite Model Theory of Łukasiewicz Fuzzy Logic

Notes for Lecture 17-18

CHAPTER 2 Signals And Spectra

Families with no matchings of size s

Technical Report Doc ID: TR March-2013 (Last revision: 23-February-2016) On formulating quadratic functions in optimization models.

Non-uniform circular motion *

International Journal of Scientific & Engineering Research, Volume 4, Issue 10, October ISSN

Essential Microeconomics : OPTIMAL CONTROL 1. Consider the following class of optimization problems

Solutions to Assignment 1

Basic definitions and relations

Echocardiography Project and Finite Fourier Series

Some Ramsey results for the n-cube

Rainbow saturation and graph capacities

Math-Net.Ru All Russian mathematical portal

Christos Papadimitriou & Luca Trevisan November 22, 2016

Bernoulli numbers. Francesco Chiatti, Matteo Pintonello. December 5, 2016

An Approach To Formalization of an Extension of Floyd-Hoare Logic

Traveling Waves. Chapter Introduction

Math-Net.Ru All Russian mathematical portal

Class Meeting # 10: Introduction to the Wave Equation

18 Biological models with discrete time

Query Answering over Fact Bases for Fuzzy Interval Ontologies

IB Physics Kinematics Worksheet

Zürich. ETH Master Course: L Autonomous Mobile Robots Localization II

Phys 221 Fall Chapter 2. Motion in One Dimension. 2014, 2005 A. Dzyubenko Brooks/Cole

INTRODUCTION TO MACHINE LEARNING 3RD EDITION

Approximation Algorithms for Unique Games via Orthogonal Separators

Matlab and Python programming: how to get started

4.6 One Dimensional Kinematics and Integration

t 2 B F x,t n dsdt t u x,t dxdt

Removing Useless Productions of a Context Free Grammar through Petri Net

Mean-square Stability Control for Networked Systems with Stochastic Time Delay

Electrical and current self-induction

Computer-Aided Analysis of Electronic Circuits Course Notes 3

Math From Scratch Lesson 34: Isolating Variables

arxiv: v1 [math.fa] 9 Dec 2018

Lab #2: Kinematics in 1-Dimension

5.2. The Natural Logarithm. Solution

Timed Circuits. Asynchronous Circuit Design. Timing Relationships. A Simple Example. Timed States. Timing Sequences. ({r 6 },t6 = 1.

T L. t=1. Proof of Lemma 1. Using the marginal cost accounting in Equation(4) and standard arguments. t )+Π RB. t )+K 1(Q RB

Chapter 15: Phenomena. Chapter 15 Chemical Kinetics. Reaction Rates. Reaction Rates R P. Reaction Rates. Rate Laws

I. Introduction to place/transition nets. Place/Transition Nets I. Example: a vending machine. Example: a vending machine

Finish reading Chapter 2 of Spivak, rereading earlier sections as necessary. handout and fill in some missing details!

Ordinary Differential Equations

Online Convex Optimization Example And Follow-The-Leader

On Multicomponent System Reliability with Microshocks - Microdamages Type of Components Interaction

Final Spring 2007

WEEK-3 Recitation PHYS 131. of the projectile s velocity remains constant throughout the motion, since the acceleration a x

On a Discrete-In-Time Order Level Inventory Model for Items with Random Deterioration

Roughness in ordered Semigroups. Muhammad Shabir and Shumaila Irshad

The Arcsine Distribution

Chapter 2. First Order Scalar Equations

23.5. Half-Range Series. Introduction. Prerequisites. Learning Outcomes

SOLUTIONS TO ECE 3084

Let us start with a two dimensional case. We consider a vector ( x,

This document was generated at 1:04 PM, 09/10/13 Copyright 2013 Richard T. Woodward. 4. End points and transversality conditions AGEC

Asymptotic Equipartition Property - Seminar 3, part 1

3.1.3 INTRODUCTION TO DYNAMIC OPTIMIZATION: DISCRETE TIME PROBLEMS. A. The Hamiltonian and First-Order Conditions in a Finite Time Horizon

Undetermined coefficients for local fractional differential equations

Lecture 4 Notes (Little s Theorem)

4.5 Constant Acceleration

On fuzzy normed algebras

Applying Genetic Algorithms for Inventory Lot-Sizing Problem with Supplier Selection under Storage Capacity Constraints

Decentralized Stochastic Control with Partial History Sharing: A Common Information Approach

Signal and System (Chapter 3. Continuous-Time Systems)

Symmetry and Numerical Solutions for Systems of Non-linear Reaction Diffusion Equations

Guest Lectures for Dr. MacFarlane s EE3350 Part Deux

An Introduction to Malliavin calculus and its applications

Essential Maps and Coincidence Principles for General Classes of Maps

ADDITIONAL PROBLEMS (a) Find the Fourier transform of the half-cosine pulse shown in Fig. 2.40(a). Additional Problems 91

STABILITY OF PEXIDERIZED QUADRATIC FUNCTIONAL EQUATION IN NON-ARCHIMEDEAN FUZZY NORMED SPASES

WHEN LINEAR AND WEAK DISCREPANCY ARE EQUAL

Inventory Analysis and Management. Multi-Period Stochastic Models: Optimality of (s, S) Policy for K-Convex Objective Functions

Martingales Stopping Time Processes

A New Kind of Fuzzy Sublattice (Ideal, Filter) of A Lattice

Efficient Matching for State-Persistent Publish/Subscribe Systems

BBP-type formulas, in general bases, for arctangents of real numbers

THE GEOMETRY MONOID OF AN IDENTITY

Transcription:

Logic in compuer science Logic plays an imporan role in compuer science Logic is ofen called he calculus of compuer science Logic plays a similar role in compuer science o ha played by calculus in he physical sciences and radiional engineering disciplines (M. Vardi, 2007) Logic 1

Mah vs Compuer science Mahemaicians define synax and semanics of languages sudy heir expressive power and properies Compuer scieniss apply logic combine foundaional research on logic wih applicaions Logic 2

Logic There is a variey of logic languages, depending on he level of absracion w.r.. naural language Some examples: Proposiional Logic FOL Descripion Logic Temporal Logic Logic 3

Applicaions Logic is a universal formalism I can be applied in a variey of conexs: archiecure (logic gaes) sofware engineering (specificaion and verificaion) programming languages (semanics, logic programming) daabases (relaional calculus, Daalog) arificial inelligence (auomaic heorem proving) heory of compuaion (general noion of complexiy) Logic 4

Basic applicaions Proposiional logic is used in compuer science for circui design FOL (more powerful) is used in program verificaion and in arificial inelligence Some examples: definiion of languages saing program properies specifying sysem (iming) properies Logic 5

Logic 6 Noaion In mah Funcions are denoed wih funcional leers Predicaes are denoed wih predicaive leers In compuer science generally predicaes and funcions are denoed wih meaningful names Variables in programming languages

Logic 7 Languages Languages are ses of srings on an alphabe The se conains all he srings ha are par of he language Examples: {a,b} The language of srings on wih he same number n n of a s and b s and all he a s firs is he se { a b n The language of he srings on wih he same number of a s and b s, wih all he a s firs and wih a n n leas an a is he se * {a,b} { a b n 1} * 0}

In logic FOL can help in describing a language Ses can be seen as abbreviaions of FOL formulae Some problems: Wha should we describe? How can we define he differen pars? Wha can we ake as a primiive? Logic 8

Logic 9 Example n n Consider he se { a b n 1} The se abbreviaes he formula x ( x L n ( n 1 x = a Predicaes:,, = Funcions: concaenaion and power n Wha is x? n x (( n = 0 x n = ε) ( n > 0 n x.b n n n = )) x n 1. x))

Remarks We need o define all he non-elemenary predicaes and funcions The following are assumed o be already defined: Equaliies Inequaliies Se membership ( ) The basic arihmeic operaions (+, -, *, :) Basic sring operaions (concaenaion) Logic 10

Logic 11 L 1 = a * b * L 1 is he language of he srings on {a, b} wih all he a s firs More precisely, a sring is in L 1 if i is he empy sring, or i is decomposed in he prefix a and he suffix y (also belonging o L 1 ) i is decomposed in he prefix y (also belonging o L 1 ) and he suffix b This can be expressed as x(x L1 (x = ε) y (x = ay y L 1) y (x = yb y L 1))

Logic 12 L 2 = a * b * c * (1) L 2 is he language of he srings on {a, b, c} wih all he a s firs, hen all he b s and a he end all he c s L 2 can be seen as a * b *. b * c * a * b * is L 1 b * c * has he same srucure as L 1 (le s call i L 3 ) A sring belongs o L 2 if I is in L 1 or I is in L 3 or i can be decomposed in he prefix a and he suffix y (ha belongs o L 2 or o L 3 ) or i can be decomposed in he prefix y (ha belongs o L 1 or o L 2 ) and he suffix c

Logic 13 L 2 = a * b * c * (2) In FOL: x(x L 2 (x L 1 ) (x L y ((x = ay 3 ) (y L 2 y L 3 )) (x = yc (y L 2 y L 1 )))) x is in L 1 x is in L 3 I can be decomposed in he prefix a and he suffix y (ha belongs o L2 or o L3) i can be decomposed in he prefix y (ha belongs o L1 or o L2) and he suffix c do we need all of hese?

Noes and addiional remarks A magic formula for obaining FOL descripions of ses does no exis Some remarks When he order among leers in a language is imporan, he FOL formula defines he language by decomposing i recursive definiion When we need o coun he leers an addiional funcion can be defined Logic 14

Example L 4 ={x {a,b}* he number of a s is equal o he number of b s} #(x, a) is of ariy 2 and couns he number of occurrences of he symbol a in he sring x I can be defined formally as In FOL x y((x = ε #(x,a) = 0) (x = a.y #(x,a) = #(y,a) +1) (x = b.y #(x,a) = #(y,a))) x y((x = ε #(x,b) = 0) (x = b.y #(x,b) = #(y,b) +1) (x = a.y #(x,b) = #(y,b))) The definiion depends on he alphabe x(x L4 #(x,a) = #(x, b)) Logic 15

Precondiions and poscondiions When a funcion is programmed, i is imporan o precisely define wha i accomplishes, wihou necessarily describing how i works Precondiions and poscondiions serve his purpose The precondiion saemen indicaes wha mus be rue before he funcion is called The poscondiion saemen indicaes wha should be rue when he funcion finishes is work Logic 16

Logic 17 General srucure (Hoare s noaion) {Precondiion: Pre} Program or program fragmen: P {Poscondiion: Pos} The precondiion is verified before he execuion of P, while he poscondiion is checked afer i P mus be such ha if Pre holds before he execuion, hen Pos holds afer is execuion

How o define hem? Precondiions and poscondiions can be defined in differen ways Naural language Asserion languages Ad-hoc languages FOL can be used for his purpose Logic 18

Search algorihm (1) Le P be a program implemening he search of an elemen x in an ordered array a of n elemens Precondiion: he array is ordered Poscondiion: he found logical variable mus be rue if and only if he elemen x exiss in he array a Remark: P does no necessarily implemen a binary search algorihm Bu he precondiion is needed if i is he case Logic 19

Search algorihm (2) The precondiion can be formalized as { i(1 i n -1 a[i] a[i + 1])} The poscondiion is So he overall srucure is {found i(1 i n a[i] = x)} { i(1 P i n -1 {found i(1 i a[i] a[i + 1])} n a[i] = x)} Noe ha he elemens of an array are denoed wih he usual programming noaion Logic 20

Soring (1) Le ORD be a program ha sors an array a of n elemens ha does no conain repeiions Precondiion: he array does no conain repeiions Poscondiion: he obained array is ordered (if an elemen x precedes an elemen y in he array, hen i is smaller) Formally: { i, j(1 i n 1 j n i j a[ i] = a[ j])} ORD { i(1 i n 1 a[ i] a[ i + 1])} Logic 21

Soring (2) Is he specificaion adequae? Consider he following example: a before he execuion of ORD is [7 6 2 4 22] a afer he execuion of ORD is [2 6 22] I saisfies he poscondiion! The poscondiion has o sae ha all and only he elemens in he array o be sored are conained in he sored array Logic 22

Logic 23 Soring (3) An array b (no used in ORD) is used o refer o he array a before he execuion I is necessary o add in he precondiion ha b is exacly like he array a The soluion becomes ])))} [ ] [ ( ) ((1 (1 ]))) [ ] [ ( ) ((1 (1 1]) [ ] [ (1 { ])} [ ] [ (1 ]) [ ] [ 1 (1, { j b i a n i i n j j j b i a n j j n i i i a i a n i i ORD i b i a n i i j a i a j i n j n i j i = = + < = =

Remarks A specificaion mus be considered as a conrac I mus conain all he informaion No a priori assumpion When some condiion is eliminaed from he precondiion, he specificaion can become unsaisfacory Logic 24

Wha is a specificaion? A formal specificaion is a mahemaical descripion of he sysem I describes wha he sysem should do No (necessarily) how he sysem should do i There are many differen specificaion languages Logic 25

Logic 26 Logic for specificaion FOL can be used as specificaion language Logical approach Logical specificaion languages give a descripion of he sysem behavior Conjuncion of formulae = se of requiremens They say wha o do, no how FOL can be used also for iming requiremens

Logic 27 Example Lamp behavior: If I push he buon, he ligh goes on wihin Δ ime unis We need he predicaes: P_B(): push he buon a ime L_On(): ligh is on a ime FOL for he requiremen (P_B() 1(( 1 + Δ) L_On(1 ))) Is i correc?

Logic 28 Remarks A specificaion can be correc bu no realisic I is necessary o give all he needed consrains Formulae describe a se of behaviors, i.e., he behaviors ha saisfy hem (PB() 1 (( 1 + Δ) L_On( 1 ))) The ligh can be on even if no one presses he buon

Logic 29 Refinemen of he lamp specificaion (1) Skech of behavior L_On L_Off L_Off P_B() +k If he buon is pushed he ligh is on for k ime unis and is off he res of he ime L_Off(): he ligh is off ( (L_On() L_Off()))

Logic 30 Refinemen of he lamp specificaion (2) Formally (P_B() 1 (( 2 1 < (( + k + k) 2 ) L_On( L_Off( 2 1 )) )) Bu wha happens if he buon is pushed when he ligh is on? Can he ligh be on wihou pushing he buon? Wha if he buon is pushed wice?

Logic 31 Correc (?) specificaion of he lamp P_B() L_On L_Off L_Off +k )) ( _ )) ( _ ) (( ) ( _ (, )) ( _ )) ( _ ) (( )) ( _ ) ( _ (( 4 5 4 5 3 5 3 4 3 1 1 1 Off L B P Off L k Off L On L k Off L B P + + <

Logic 32 Problems in specifying sysems Known problems in AI The frame problem: How o express a dynamical domain in logic wihou explicily specifying wha condiions are NOT affeced by an acion Even exremely simple siuaions may require complex formalizaions Several calculi developed o address his issue: Fluen calculus, even calculus, siuaion calculus, We won delve ino hese issues in his course

Logic 33 How o specify a sysem Logic can be used o describe sysem requiremens For a sysem ha has o be analyzed, we need o idenify: Needed predicaes Relaionships among hem Temporal domain I is imporan o sae NOT only he sufficien condiions, bu also he necessary ones

Temporal domain There are differen dimensions ha need o be aken ino accoun The main difference is beween Discree domains Naural or ineger numbers Dense domains Raional numbers Coninuous domains Real numbers Logic 34

Logic 35 Wha are he predicaes? In he lamp example we had: P_B() L_On() L_Off() In general, predicaes used in a sysem specificaion can be divided ino: Predicaes ha represen a sae of he sysem (L_On(), L_Off()) Predicaes ha represen an even (P_B())

Sae A sae represens a snapsho of he sysem I holds over ime I is no insananeous (if ime is a dense domain) We can inroduce abbreviaed noaions for common siuaions Logic 36

Logic 37 Abbreviaions Up_o_now_S() δ(δ> 0 ( 1( δ< 1 < ) S(1))) I does no sae ha S holds a he presen ime From_now_on_S() δ(δ> 0 ( 1( 1 < + δ) S(1))) The presen is included

Logic 38 Even An even is an insananeous occurrence ha resuls in a changed sysem sae E The following axiom can be used o sae his behavior (abbreviaed wih Even_E): (E() δ(δ> 0 ( 1 ( δ< 1 < < 1 < + δ) E(1))))

Logic 39 Example (1) Consider he lamp example L_On L_Off L_Off P_B() +k We use abbreviaions o make he specificaion clearer

Logic 40 Example (2) ) L_Off( ))) P_B( ) (( ) (L_Off(, k)) L_Off( )) L_On( k) (( Up_o_now_L_Off()) ((P_B() _ )) ( _ ) ( _ ( 4 5 4 5 3 5 3 4 3 1 1 1 + + < B Even_P Off L On L

Wha can a specificaion be used for? A specificaion can be checked hrough formal verificaion I shows ha a candidae sysem design is correc wih respec o he specificaion. Remark: i does no prove ha he sysem is correc, bu i highlighs errors in candidae sysem designs Logic 41

Logic 42 A case sudy: Simplified railroad crossing There is jus a one-way rack When he rain is crossing I, he bar has o be closed: Train behavior Gae conroller

Logic 43 Daa of he problem Ar En Ex R has lengh d I has lengh x Ar and En are he endpoins of R En and Ex are he endpoins of I

Logic 44 Train Kinemaics (1) A rain can vary is speed in he inerval [V min,v max ] The ime aken o cross he crossing region varies consequenly (δ (δ (δ 1 3 = = min d V x V min min = d V ) (δ ) (δ max 2 4 ) (δ d + x = ) Vmax = x ) V max max d + x = ) V min

Logic 45 Train Kinemaics (2) If he rain eners he region R, i exis i a leas δ min and a mos δ 1 ime unis afer, and i exis l a leas δ 2 and a mos δ max ime unis afer (Ar() 1 (En(1) ( + δmin 1 + δ 1)) 2(Ex(2) ( + δ2 2 + δ If he rain exis he region R, i enered i a leas δ min and a mos δ 1 insans before, and if i exis l, i enered region R a leas δ 2 ime insans before max ))) and a mos δ max (En() (Ex() 1 1 (Ar( (Ar( 1 1 ) ( δ 1 ) ( δ max 1 1 δ min δ ))) 2 )))

Logic 46 Train Kinemaics (3) The rain is wihin he crossing region a ime if i enered R before and afer ha momen i didn exi l (In() (En(1 ) (1 ) 2(Ex( 2) (1 2 1 )))) Abbreviaions for recurring emporal consrucions could be inroduced

The gae conroller When he rain eners R i akes a leas δ min o ener l and a mos δ 1 o exi i: in his inerval he bar has o be closed (Ar() 1(( + δmin 1 + δmax) Down( 1))) The bar is closed only if a rain enered he region (no necessarily l) ( Down( ) 1(( δmax 1 δmin ) Ar( 1))) Up is he opposie of down ( Down( ) Up( )) Logic 47

Logic 48 Propery We wan (In() Down()) o hold in he sysem we specified The safey requiremen should be proved (derived) as a heorem from he formalizaion (he whole specificaion)