Logic Taking a Step Back Some Modeling Paradigms Outline
Total Page:16
File Type:pdf, Size:1020Kb
Help Taking a step back Logic query Languages and expressiveness Propositional logic Specification of propositional logic data Learning model Inference Inference algorithms for propositional logic Inference in propositional logic with only definite clauses Inference in full propositional logic predictions Firstorder logic Specification of firstorder logic Models describe how the world works (relevant to some task) Inference algorithms for firstorder logic Inference in firstorder logic with only definite clauses What type of models? Inference in full firstorder logic Other logics Logic and probability CS221: Artificial Intelligence (Autumn 2012) Percy Liang CS221: Artificial Intelligence (Autumn 2012) Percy Liang 1 Some modeling paradigms Outline State space models: search problems, MDPs, games Languages and expressiveness Applications: route finding, game playing, etc. Propositional logic Specification of propositional logic Think in terms of states, actions, and costs Inference algorithms for propositional logic Variablebased models: CSPs, Markov networks, Bayesian Inference in propositional logic with only definite networks clauses Applications: scheduling, object tracking, medical diagnosis, etc. Inference in full propositional logic Think in terms of variables and factors Firstorder logic Specification of firstorder logic Logical models: propositional logic, firstorder logic Inference algorithms for firstorder logic Applications: proving theorems, program verification, reasoning Inference in firstorder logic with only definite clauses Think in terms of logical formulas and inference rules Inference in full firstorder logic Other logics Logic and probability CS221: Artificial Intelligence (Autumn 2012) Percy Liang 2 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 3 Language Language is a mechanism for expressing models/knowledge/ideas. Natural languages: Desiderata: want a language than can represent complex facts English: even numbers about the world and allows for sophisticated reasoning about those German: geraden Zahlen facts... Programming languages: Python: def even(x): return x % 2 == 0 C++: bool even(int x) { return x % 2 == 0; } CS221: Artificial Intelligence (Autumn 2012) Percy Liang 4 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 5 Procedural programming languages Variablebased models Procedural languages represent knowledge using data structures, Variablebased models are a declarative language: define algorithms manipulates data structures. constraints/factors over variables; ask any query over variables. Implicit representation? def f(positions): All students work hard. distances = [dist(pos, me) for pos in positions] John is a student. minDistance = min(distances) Therefore, John works hard. return minDistance Variablebased models would explictly represent all the students — intuitively shouldn't be necessary. Easy query: Given positions, what is minDistance? Higherorder reasoning? Hard query: Given minDistance, what are positions? John believes it will rain. Will it rain? Need a declarative language ( ) Does John believe it will not rain (assuming John is logical)? Need something more expressive to represent... CS221: Artificial Intelligence (Autumn 2012) Percy Liang 6 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 7 Natural languages A puzzle A dime is better than a nickel. If John likes probability, then John likes logic. A nickel is better than a penny. Therefore, a dime is better than penny. If it is Thursday, then John likes probability or John likes logic. General rule (transitivity): if and , then . It is Thursday. A penny is better than nothing. Nothing is better than world peace. Does John like probability? Therefore, a penny is better than world peace??? Does John like logic? Natural language is not formal, can be slippery... CS221: Artificial Intelligence (Autumn 2012) Percy Liang 8 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 9 Notes A puzzle Propositional logic chat demo You get extra credit if you write a paper and you solve the Tell me some something or ask me something. I will try to convert your utterance into propositional logic and apply resolution to carry out your request. I have no personality. problems. Example: "If it rained, then the ground is wet.", "It rained.", "Is the ground wet?" Example: "(implies (or rain snow) wet)", "rain", "(or wet cold)?" You didn't get extra credit. You solve the problems. Did you write a paper? CS221: Artificial Intelligence (Autumn 2012) Percy Liang 10 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 11 Ingredients Syntax versus semantics Syntax: defines a set of valid formulas ( ) Syntax: what are valid expressions in the language? Semantics: Semantics: what do these expressions mean? A model describes a possible situation in the world An interpretation function mapping each Different syntax, same semantics: and model to a truth value x + y y + x Inference rules: what new formulas can be added without changing semantics ( )? Same syntax, different semantics: Inference algorithm: apply inference rules in some clever order to 3 / 2 (Python) 3 / 2 (Javascript) answer queries (is true?) CS221: Artificial Intelligence (Autumn 2012) Percy Liang 12 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 13 Outline Outline Languages and expressiveness Languages and expressiveness Propositional logic Propositional logic Specification of propositional logic Specification of propositional logic Inference algorithms for propositional logic Inference algorithms for propositional logic Inference in propositional logic with only definite Inference in propositional logic with only definite clauses clauses Inference in full propositional logic Inference in full propositional logic Firstorder logic Firstorder logic Specification of firstorder logic Specification of firstorder logic Inference algorithms for firstorder logic Inference algorithms for firstorder logic Inference in firstorder logic with only definite clauses Inference in firstorder logic with only definite clauses Inference in full firstorder logic Inference in full firstorder logic Other logics Other logics Logic and probability Logic and probability CS221: Artificial Intelligence (Autumn 2012) Percy Liang 14 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 15 Syntax of propositional logic Syntax of propositional logic Propositional symbols: (think variables in CSPs); these are Formula: formulas Nonformula: Logical connectives: Build up formulas recursively—if and are formulas, so are the following: Negation: Note: formulas are just symbols — no meaning yet! Conjunction: Disjunction: Implication: Biconditional: CS221: Artificial Intelligence (Autumn 2012) Percy Liang 16 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 17 Model Interpretation function A model in propositional logic is an assignment of truth values Given a formula and a model , interpretation function to propositional symbols returns either true (1) or false (0). Example: Base case: 3 propositional symbols: For a propositional symbol (e.g., ): possible models : Recursive case: For any two formulas and : 0 0 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 0 1 0 0 1 1 0 1 1 1 1 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 18 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 19 Example Formulas represent sets of models Formula: Fach formula and model has an interpretation Model: Formula: Interpretation: Models with true interpretation : Point: formula is symbols that compactly represent a set of models. Think of formula as putting constraints on the world. CS221: Artificial Intelligence (Autumn 2012) Percy Liang 20 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 21 Types of formulas Knowledge base Validity: for all models (tautologies that provide no Let . information, e.g., ) Unsatisfiability: for all models (contradictions, e.g., ) Definition: Knowledge base A knowledge base is a set of formulas with . Contingent: neither valid nor unsatisfiable (provides information, e.g., ) Note: think conjunction: CS221: Artificial Intelligence (Autumn 2012) Percy Liang 22 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 23 Entailment Contradiction Intuition: contradicts what we know (captured in ). Intuition: added no information/constraints (it was already known). Example: contradicts Definition: Entailment entails (written ) iff . Relationship between entailment and contradiction: Example: entails ( ) iff is unsatisfiable CS221: Artificial Intelligence (Autumn 2012) Percy Liang 24 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 25 Contingency Interacting with a knowledge base or response Tell: It rained. ( ) Possible responses: Already knew that: entailment ( ) Don't believe that: contradiction ( ) Intuition: adds nontrivial information to Learned something new (update knowledge base): contingent Ask: Did it rain? ( ) Possible responses: Yes: entailment ( ) No: contradiction ( ) Example: and I don't know: contingent Everything boils down to entailment (checking satisfiability)... CS221: Artificial Intelligence (Autumn 2012) Percy Liang 26 CS221: Artificial Intelligence (Autumn 2012) Percy Liang 27 Model checking Outline Checking satisfiability (SAT) is special case of solving CSPs Languages and expressiveness propositional symbol variable Propositional logic formula constraint Specification of propositional logic model assignment Inference algorithms for propositional logic