COMP 410 Lecture 1. Kyle Dewey

Similar documents
COMP 122/L Lecture 1. Kyle Dewey

CS 64 Week 0 Lecture 1. Kyle Dewey

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

CSE 12 Abstract Syntax Trees

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Defining Functions. CSc 372. Comparative Programming Languages. 5 : Haskell Function Definitions. Department of Computer Science University of Arizona

These are notes for the third lecture; if statements and loops.

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

Complexity Classes and Polynomial-time Reductions

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Semantics of programming languages

Consider a description of arithmetic. It includes two equations that define the structural types of digit and operator:

CS 4349 Lecture August 21st, 2017

Shared Variables and Interference

Lecture 21: Other Reductions Steven Skiena

Chapter 3. Describing Syntax and Semantics

Control Structures in Java if-else and switch

Program development plan

CSCE 120: Learning To Code

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

Program Verification & Testing; Review of Propositional Logic

Steven Skiena. skiena

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

Semantics of programming languages

Semantics of programming languages

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

Shared Variables and Interference

Lecture 3: Recursion; Structural Induction

Semantic Analysis Type Checking

CS 360 Programming Languages Interpreters

CS Introduction to Data Structures How to Parse Arithmetic Expressions

Introduction to Haskell

Finite Model Generation for Isabelle/HOL Using a SAT Solver

CS112 Lecture: Primitive Types, Operators, Strings

(I m not printing out these notes! Take your own.)

CMSC th Lecture: Graph Theory: Trees.

Computational Geometry

Type Checking and Type Equality

Types and Static Type Checking (Introducing Micro-Haskell)

CS1 Lecture 3 Jan. 22, 2018

Values and Variables 1 / 30

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

An overview about DroidBasic For Android

Types and Static Type Checking (Introducing Micro-Haskell)

Propositional Logic. Andreas Klappenecker

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Vertex Cover Approximations

Lecture 2: NP-Completeness

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré

Proofwriting Checklist

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

4.1 Review - the DPLL procedure

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Chapter 3 (part 3) Describing Syntax and Semantics

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

CS162 Week 1. Kyle Dewey. Friday, January 10, 14

1 Definition of Reduction

Critical Analysis of Computer Science Methodology: Theory

CS16 Week 2 Part 2. Kyle Dewey. Thursday, July 5, 12

CSE 401 Midterm Exam Sample Solution 2/11/15

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

CS221: Algorithms and Data Structures. Asymptotic Analysis. Alan J. Hu (Borrowing slides from Steve Wolfman)

This book is licensed under a Creative Commons Attribution 3.0 License

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

CITS5501 Software Testing and Quality Assurance Formal methods

Lecture 1: Overview

Lecture 3. Input, Output and Data Types

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 161 Computer Security

Boolean Functions (Formulas) and Propositional Logic

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Computer-Aided Program Design

CS 115 Lecture 4. More Python; testing software. Neil Moore

Comparing procedure specifications

About this exam review

CS1 Lecture 3 Jan. 18, 2019

Simple Java Programming Constructs 4

Writing an Interpreter Thoughts on Assignment 6

Lecture 23: Priority Queues 10:00 AM, Mar 19, 2018

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Logic and Computation

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

CS 373: Combinatorial Algorithms, Spring 1999

Lecture 21: Other Reductions Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Lecture Notes for Chapter 2: Getting Started

Lecture 3: Constructing the Natural Numbers

Program Analysis: Lecture 02 Page 1 of 32

Lecture 10: Introduction to Correctness

Material from Recitation 1

We will show that the height of a RB tree on n vertices is approximately 2*log n. In class I presented a simple structural proof of this claim:

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Computational Complexity and Implications for Security DRAFT Notes on Infeasible Computation for MA/CS 109 Leo Reyzin with the help of Nick Benes

Algorithms and Programming I. Lecture#12 Spring 2015

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Transcription:

COMP 410 Lecture 1 Kyle Dewey

About Me I research automated testing techniques and their intersection with CS education My dissertation used logic programming extensively This is my second semester at CSUN First time dedicating a whole course to logic programming

About this Class See something wrong? Want something improved? Email me about it! (kyle.dewey@csun.edu) I generally operate based on feedback

Bad Feedback This guy sucks. This class is boring. This material is useless. -I can t do anything in response to this

Good Feedback This guy sucks, I can t read his writing. This class is boring, it s way too slow. This material is useless, I don t see how it relates to anything in reality. I can t fix anything if I don t know what s wrong -I can actually do something about this!

-Major programming paradigm - a way of thinking about problems -Emphases thinking about exactly _what_ the problem is, as opposed to exactly _how_ to solve it. This is called declarative programming. -For example: it s generally easier to say what constraints must hold for a valid Sudoku solution, as opposed to directly finding a valid Sudoku solution. -Somewhat related to functional programming - we generally lack mutable state -Unlike any other major paradigm, the distinction between inputs and outputs is intentionally blurred. You can take advantage of this. -Basis in formal logic. It s the only major paradigm where = has the same meaning as it does in math. What is Logic Programming?

-Major programming paradigm - a way of thinking about problems -Emphases thinking about exactly _what_ the problem is, as opposed to exactly _how_ to solve it. This is called declarative programming. -For example: it s generally easier to say what constraints must hold for a valid Sudoku solution, as opposed to directly finding a valid Sudoku solution. -Somewhat related to functional programming - we generally lack mutable state -Unlike any other major paradigm, the distinction between inputs and outputs is intentionally blurred. You can take advantage of this. -Basis in formal logic. It s the only major paradigm where = has the same meaning as it does in math. What is Logic Programming? What, not how No mutable state Basis in formal logic = means = Inputs/outputs are blurred

-Major programming paradigm - a way of thinking about problems -Emphases thinking about exactly _what_ the problem is, as opposed to exactly _how_ to solve it. This is called declarative programming. -For example: it s generally easier to say what constraints must hold for a valid Sudoku solution, as opposed to directly finding a valid Sudoku solution. -Somewhat related to functional programming - we generally lack mutable state -Unlike any other major paradigm, the distinction between inputs and outputs is intentionally blurred. You can take advantage of this. -Basis in formal logic. It s the only major paradigm where = has the same meaning as it does in math. What is Logic Programming? What, not how No mutable state Basis in formal logic = means = Inputs/outputs are blurred

-Major programming paradigm - a way of thinking about problems -Emphases thinking about exactly _what_ the problem is, as opposed to exactly _how_ to solve it. This is called declarative programming. -For example: it s generally easier to say what constraints must hold for a valid Sudoku solution, as opposed to directly finding a valid Sudoku solution. -Somewhat related to functional programming - we generally lack mutable state -Unlike any other major paradigm, the distinction between inputs and outputs is intentionally blurred. You can take advantage of this. -Basis in formal logic. It s the only major paradigm where = has the same meaning as it does in math. What is Logic Programming? What, not how No mutable state Basis in formal logic = means = Inputs/outputs are blurred

-Major programming paradigm - a way of thinking about problems -Emphases thinking about exactly _what_ the problem is, as opposed to exactly _how_ to solve it. This is called declarative programming. -For example: it s generally easier to say what constraints must hold for a valid Sudoku solution, as opposed to directly finding a valid Sudoku solution. -Somewhat related to functional programming - we generally lack mutable state -Unlike any other major paradigm, the distinction between inputs and outputs is intentionally blurred. You can take advantage of this. -Basis in formal logic. It s the only major paradigm where = has the same meaning as it does in math. What is Logic Programming? What, not how No mutable state Basis in formal logic = means = Line between input/output is blurry

What is this Course? -Strong emphasis on programming and using logic programming languages -I want you to think in this paradigm, not merely force Java into it -The ideas can be applied in non-logical languages, and your first assignment will force you to write in a logical way outside of a logic programming language (though you won t realize that s what you re doing yet) -Little bit of theory

What is this Course? Programming, programming, programming Thinking in a logic programming way Applying logic programming without a logic programming language Little bit of theory later on -Strong emphasis on programming and using logic programming languages -I want you to think in this paradigm, not merely force Java into it -The ideas can be applied in non-logical languages, and your first assignment will force you to write in a logical way outside of a logic programming language (though you won t realize that s what you re doing yet) -Little bit of theory

What is this Course? Programming, programming, programming Thinking in a logic programming way Applying logic programming without a logic programming language Little bit of theory later on -Strong emphasis on programming and using logic programming languages -I want you to think in this paradigm, not merely force Java into it -The ideas can be applied in non-logical languages, and your first assignment will force you to write in a logical way outside of a logic programming language (though you won t realize that s what you re doing yet) -Little bit of theory

What is this Course? Programming, programming, programming Thinking in a logic programming way Applying logic programming without a logic programming language Little bit of theory later on -Strong emphasis on programming and using logic programming languages -I want you to think in this paradigm, not merely force Java into it -The ideas can be applied in non-logical languages, and your first assignment will force you to write in a logical way outside of a logic programming language (though you won t realize that s what you re doing yet) -Little bit of theory

What is this Course? Programming, programming, programming Thinking in a logic programming way Applying logic programming without a logic programming language Little bit of theory later on -Strong emphasis on programming and using logic programming languages -I want you to think in this paradigm, not merely force Java into it -The ideas can be applied in non-logical languages, and your first assignment will force you to write in a logical way outside of a logic programming language (though you won t realize that s what you re doing yet) -Little bit of theory

What this course isn t

What this course isn t Artificial intelligence Machine learning Deeply theoretical - Artificial intelligence used to refer to search techniques, which is relevant to logic programming. Now the term largely refers to machine learning. What it means is a moving target. -Machine learning (we won t do any sort of statistics) -You can spend a career on the theory behind this stuff. I know some, but it s not my speciality.

What this course isn t Artificial intelligence Machine learning Deeply theoretical - Artificial intelligence used to refer to search techniques, which is relevant to logic programming. Now the term largely refers to machine learning. What it means is a moving target. -Machine learning (we won t do any sort of statistics) -You can spend a career on the theory behind this stuff. I know some, but it s not my speciality.

What this course isn t Artificial intelligence Machine learning Deeply theoretical - Artificial intelligence used to refer to search techniques, which is relevant to logic programming. Now the term largely refers to machine learning. What it means is a moving target. -Machine learning (we won t do any sort of statistics) -You can spend a career on the theory behind this stuff. I know some, but it s not my speciality.

Syllabus

Outline Abstract Syntax Trees and evaluation SAT and Semantic Tableau

Abstract Syntax Trees and Evaluation

Abstract Syntax Tree Abbreviation: AST Unambiguous tree-based representation of a sentence in a language Very commonly used in compilers, interpreters, and related software -Generally we work with ASTs instead of Strings or any other code representation

(1 + 2) - 3 * 4 -Key parts: we need parentheses to direct that 1 + 2 happens first. We know that the 3 * 4 should happen after the part in parentheses from PEMDAS rules

(1 + 2) - 3 * 4 - -Lowest priority thing ends up in the top of the tree

(1 + 2) - 3 * 4 - + * -Next level of priority

(1 + 2) - 3 * 4 - + * 1 2 3 4 -Next level of priority

Evaluation - + * 1 2 3 4 -Key point: bubble-up values from the leaves -This can be implemented in code via a recursive function starting from the root (code in a bit later)

Evaluation - + * 1 2 3 4 -We start evaluation from the root...

Evaluation - + * 1 2 3 4 -In order to evaluate the root, we need to evaluate the left subtree of the root (+)

Evaluation - + * 1 2 3 4 -In order to evaluate +, we need to evaluate the left subtree (as with the root)

Evaluation - + * 1 1 2 3 4 -For arithmetic, leaves are simply numbers -Evaluating a leaf returns the number held within

Evaluation - + * 1 1 2 3 4 -The left subtree of + has now been evaluated -Now + needs the value of the right subtree

Evaluation - + * 1 1 2 3 4 -The left subtree of + has now been evaluated -Now + needs the value of the right subtree

Evaluation - + * 1 2 1 2 3 4 -As before, leaves just return the value held within

Evaluation - + * 1 2 1 2 3 4 -Subtrees of + are now taken care of -Now + has two values that it needs to work with...

Evaluation 3 - + * 1 2 1 2 3 4 -+ performs the actual addition

Evaluation 3 - + * 1 2 1 2 3 4 -Now + is taken care of -Going back to -, - now has the value of the left subtree, and it needs the value of the right subtree

Evaluation 3 - + * 1 2 1 2 3 4 -Now we re on *, which needs the value of the left subtree...

Evaluation 3 - + * 1 2 1 2 3 4 -Now we re on *, which needs the value of the left subtree...

Evaluation 3 - + * 1 2 3 1 2 3 4 -Leaves again return the values held within...

Evaluation 3 - + * 1 2 3 1 2 3 4 -Left subtree done; * now needs the value of the right subtree...

Evaluation 3 - + * 1 2 3 1 2 3 4 -Left subtree done; * now needs the value of the right subtree...

Evaluation 3 - + * 1 2 3 4 1 2 3 4 -Leaf returns value held within

Evaluation 3 - + * 1 2 3 4 1 2 3 4 -Leaf is done. * now has both operands it needs...

Evaluation - 3 12 + * 1 2 3 4 1 2 3 4 -* performs the multiplication and returns the value

Evaluation - 3 12 + * 1 2 3 4 1 2 3 4 -The root - node now has both operands...

Evaluation -9-3 12 + * 1 2 3 4 1 2 3 4 -...and it returns the result of the subtraction

Evaluator Example: arithmetic_evaluator.rkt -Complete example online; we ll live-code this in class

SAT and Semantic Tableau

SAT Background

SAT Short for the Boolean satisfiability problem Given a Boolean formula with variables, is there an assignment of true/false to the variables which makes the formula true?

SAT Short for the Boolean satisfiability problem Given a Boolean formula with variables, is there an assignment of true/false to the variables which makes the formula true? (x y) ( x z)

SAT Short for the Boolean satisfiability problem Given a Boolean formula with variables, is there an assignment of true/false to the variables which makes the formula true? (x y) ( x z) Yes: x is true, z is true

SAT Short for the Boolean satisfiability problem Given a Boolean formula with variables, is there an assignment of true/false to the variables which makes the formula true? (x y) ( x z) Yes: x is true, z is true (x x)

SAT Short for the Boolean satisfiability problem Given a Boolean formula with variables, is there an assignment of true/false to the variables which makes the formula true? (x y) ( x z) Yes: x is true, z is true (x x) No

Relevance Widespread usage in hardware and software verification -Verification as in _proving_ the system does what we intend -Much stronger guarantees than testing -Testing can prove the existence of a bug (a failed test), whereas verification proves the absence of bugs (relative to the theorems proven)

Relevance Widespread usage in hardware and software verification -Circuits can be represented as Boolean formulas -Can basically phrase proofs as Circuit BadThing. If unsatisfiable, then BadThing cannot occur. If satisfiable, then the solution gives the circumstance under which BadThing occurs. -Many details omitted (entire careers are based on this stuff)

Relevance Widespread usage in hardware and software verification -(Likely) used by AirBus to verify that flight control software does the right thing -Lots of proprietary details so it s not 100% clear how this verification works, but SAT is still relevant to the problem

Relevance Widespread usage in hardware and software verification -Nasa uses software verification for a variety of tasks; SAT is relevant, though other techniques are used, too

Relevance to Logic Programming Methods for solving SAT can be used to execute logic programs Logic programming can be phrased as SAT with some additional stuff

Semantic Tableau One method for solving SAT instances Basic idea: iterate over the formula Maintain subformulas that must be true Learn which variables must be true/false Stop at conflicts (unsatisfiable), or when no subformulas remain (have solution) -There are many methods to this

Positive Literals a -As in, the input formula is simply a

Positive Literals a [a] -One subformula must be true: a -Initially, we don t know what any variables must map to

Positive Literals a [a] [] {a -> t} -For formula a to be true, it must be the case that a is true

Positive Literals a [a] [] {a -> t} -No subformulas remain, so we are done. The satisfying solution is that a must be true.

Negative Literals a -As in, the input formula is simply a

Negative Literals [ a] a -One subformula must be true: a -Initially, we don t know what any variables must map to

Negative Literals [ a] a [] {a -> f} -For subformula a to be true, it must be the case that a is false

Negative Literals [ a] a [] {a -> f} -No subformulas remain, so we are done. The satisfying solution is that a must be false.

Logical And a b

Logical And a b [a b] -Initially, one subformula must be true: a b -Initially, we don t know what any variable must map to

Logical And a b [a b] [a, b] -For a b to be true, subformulas a and b must both be true

Logical And a b [a b] [a, b] [b] {a -> t} -From the positive literal case, for formula a to be true, variable a must be true

Logical And a b [a b] [a, b] [b] {a -> t} [] {a -> t, b -> t} -From the positive literal case, for formula b to be true, variable b must be true

Logical And a b [a b] [a, b] [b] {a -> t} [] {a -> t, b -> t} -No subformulas remain, so we are done with the solution that both a and b must be true

Logical And a a -Alternative example, showing a conflict

Logical And a a [a a]

Logical And a a [a a] [ a] {a -> t}

Logical And a a [a a] [ a] {a -> t} -Now we have a problem: for formula a to be true, it must be the case that variable a is false -We ve already recorded that variable a must be true, which is the opposite of what we expect. -As such, we have a conflict - this formula is unsatisfiable

Logical Or a a

Logical Or a a [a a]

Logical Or a a [a a] [a] [ a] -World splits on or: in one world we pick the left subformula, and in another we pick the right

Logical Or a a [a a] [a] [ a] [] {a -> t} -World splits on or: in one world we pick the left subformula, and in another we pick the right

Logical Or a a [a a] [a] [ a] [] {a -> t} -World splits on or: in one world we pick the left subformula, and in another we pick the right

Logical Or a a [a a] [a] [ a] [] {a -> t} [] {a -> f} -World splits on or: in one world we pick the left subformula, and in another we pick the right

Logical Or a a [a a] [a] [ a] [] {a -> t} [] {a -> f} -World splits on or: in one world we pick the left subformula, and in another we pick the right

Examples

Example 1: ( b a) b

( b a) b

( b a) b [( b a), b]

( b a) b [( b a), b] [ b, b]

( b a) b [( b a), b] [ b, b] [b] {b -> f}

( b a) b [( b a), b] [ b, b] [b] {b -> f}

( b a) b [( b a), b] [ b, b] [a, b] [b] {b -> f}

( b a) b [( b a), b] [ b, b] [b] {b -> f} [a, b] [b] {a -> t}

( b a) b [( b a), b] [ b, b] [b] {b -> f} [a, b] [b] {a -> t} [] {a -> t, b -> t}

Example 2: (x y) ( x z)

(x y) ( x z)

(x y) ( x z) [(x y), ( x z)]

(x y) ( x z) [(x y), ( x z)] [x, ( x z)]

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [( x z)] {x -> t}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [( x z)] {x -> t} [ x] {x -> t}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [( x z)] {x -> t} [ x] {x -> t}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [( x z)] {x -> t} [ x] {x -> t} [z] {x -> t}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [( x z)] {x -> t} [ x] {x -> t} [z] {x -> t} [] {x -> t, z -> t}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [ y, ( x z)] [( x z)] {x -> t} [ x] {x -> t} [z] {x -> t} [] {x -> t, z -> t}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [ y, ( x z)] [( x z)] {x -> t} [( x z)] {y -> f} [ x] {x -> t} [z] {x -> t} [] {x -> t, z -> t}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [ y, ( x z)] [( x z)] {x -> t} [( x z)] {y -> f} [ x] [z] [ x] {x -> t} {x -> t} [] {x -> t, z -> t} {y -> f}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [ y, ( x z)] [( x z)] {x -> t} [( x z)] {y -> f} [ x] [z] [ x] {x -> t} {x -> t} [] {x -> t, z -> t} {y -> f} [] {y -> f, x -> f}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [ y, ( x z)] [( x z)] {x -> t} [( x z)] {y -> f} [ x] [z] [ x] [z] {x -> t} {x -> t} {y -> f} {y -> f} [] [] {x -> t, {y -> f, z -> t} x -> f}

(x y) ( x z) [(x y), ( x z)] [x, ( x z)] [ y, ( x z)] [( x z)] {x -> t} [( x z)] {y -> f} [ x] [z] [ x] [z] {x -> t} {x -> t} {y -> f} {y -> f} [] [] [] {x -> t, {y -> f, {y -> f, z -> t} x -> f} z -> t}