ERGOAI Reasoner User's Manual
Total Page:16
File Type:pdf, Size:1020Kb
ERGOAI Reasoner User’s Manual Version 2.0 (Myia) Edited by Michael Kifer Coherent Knowledge October 2018 Portions Copyright © 2013–2018 Coherent Knowledge CONTENTS Contents 1 Introduction 1 2 Installation 1 3 Running ERGO 2 4 ERGO Shell Commands 3 5 F-logic and ERGO by Example 10 6 Main Syntactic Elements of ERGO 10 7 Basic ERGO Syntax 13 7.1 F-logic Vocabulary ..................................... 13 7.2 Symbols, Strings, and Comments ............................. 18 7.3 Operators .......................................... 21 7.4 Logical Expressions ..................................... 23 7.5 Arithmetic (and related) Expressions ........................... 23 7.6 Quasi-constants and Quasi-variables ........................... 30 7.7 Synonyms .......................................... 31 7.8 Reserved Symbols ..................................... 31 8 Path Expressions 31 9 Set Notation 33 10 Typed Variables 34 11 Truth Values and Object Values 36 12 Boolean Methods 38 Portions Copyright © 2013–2018 Coherent Knowledge i CONTENTS 12.1 Boolean Signatures ..................................... 39 13 Skolem Symbols 39 14 Testing Meta-properties of Symbols and Variables 46 15 Lists, Sets, Ranges. The Operators \in, \subset, \sublist 50 16 Multifile Knowledge Bases 51 16.1 ERGO Modules ....................................... 52 16.2 Calling Methods and Predicates Defined in User Modules ............... 53 16.3 Finding the Current Module Name ............................ 55 16.4 Finding the Module That Invoked A Rule ........................ 55 16.5 Loading Files into User Modules ............................. 55 16.6 Adding Rule Bases to Existing Modules ......................... 58 16.7 Module References in Rule Heads ............................. 59 16.8 Calling Prolog Subgoals from ERGO ........................... 60 16.9 Calling ERGO from Prolog ................................. 62 16.9.1 Importing ERGO Predicates into Prolog ..................... 62 16.9.2 Passing Arbitrary Queries to ERGO ....................... 64 16.10ERGO System Modules ................................... 67 16.11Including Files into ERGO Knowledge Bases ....................... 67 16.12More on Variables as Module Specifications ....................... 67 16.13Module Encapsulation ................................... 68 16.14Importing Modules ..................................... 71 16.15Persistent Modules ..................................... 72 16.16Fast Loading Vast Amounts of Data ........................... 73 17 Truth about Relative File Names and Current Directories 74 18 HiLog and Meta-programming 76 Portions Copyright © 2013–2018 Coherent Knowledge ii CONTENTS 18.1 Meta-programming, Meta-unification ........................... 78 18.2 Reification .......................................... 80 18.3 Meta-decomposition .................................... 83 18.4 Passing Parameters between ERGO and Prolog ..................... 85 19 Negation 87 19.1 Default Negation \naf vs. Prolog Negation \+ ..................... 87 19.2 Default Negation for Non-ground Subgoals ........................ 88 19.3 Non-ground Subgoals Under \+ .............................. 90 19.4 True vs. Undefined Formulas ............................... 90 19.5 Explicit Negation ...................................... 91 20 General Formulas in Rule Bodies 93 20.1 Quantification of Free and Anonymous Variables .................... 95 20.2 The Difference Between ~~>, ==> (or, <~~, <==), and :- ................ 96 20.3 Unsafe Negation ...................................... 97 21 Omniformity: General Formulas in Rule Heads 98 21.1 Omniformity of <==, ==>, and <===> ...........................100 21.2 Omniformity and Builtins .................................102 22 Inheritance of Default Properties and Types 103 22.1 Introduction to Inheritance ................................104 22.2 Monotonic Behavioral Inheritance ............................107 22.3 Non-monotonic Behavioral Inheritance ..........................108 22.4 Inheritance of Negative Information ...........................112 22.4.1 Negative Monotonic Behavioral Inheritance ...................113 22.4.2 Negative Structural Inheritance ..........................113 22.4.3 Negative Non-monotonic Behavioral Non-Inheritance ..............114 22.5 Code Inheritance ......................................116 Portions Copyright © 2013–2018 Coherent Knowledge iii CONTENTS 23 Custom Module Semantics 118 23.1 Equality Maintenance ...................................119 23.2 Choosing a Semantics for Inheritance ...........................122 23.3 Choosing a Semantics for the Subclass Relationship ..................122 23.4 Choosing a Semantics for Tabling .............................123 23.5 Class Expressions ......................................123 23.6 Ad Hoc Custom Semantics ................................125 23.7 Querying the Module Semantics ..............................125 24 ERGO and Tabling 126 24.1 Tabling in a Nutshell ....................................126 24.2 Transactional Methods ...................................129 24.3 One-answer Queries ....................................130 24.4 Examining Query Results: The peek{...} primitive ...................130 24.5 Operational Semantics of ERGO ..............................132 24.6 Tabling and Performance .................................133 24.7 Cuts .............................................133 25 User Defined Functions 135 25.1 Syntax ............................................135 25.2 Higher-order UDFs .....................................140 25.3 User-defined Functions and Multifile Modules ......................140 25.4 Semantics ..........................................141 25.5 Representing equality with user defined functions ....................142 26 Controlling Context of Symbols 144 27 Updating the Knowledge Base 146 27.1 Non-transactional (Non-logical) Updates .........................147 27.2 Transactional (Logical) Updates .............................152 Portions Copyright © 2013–2018 Coherent Knowledge iv CONTENTS 27.3 Updates and Tabling ....................................153 27.4 Updates and Meta-programming .............................157 27.5 Updates and Negation ...................................158 27.6 Stealth Updates .......................................159 27.7 Counter Support ......................................160 28 Insertion and Deletion of Rules 161 28.1 Creation of a New Module and Module Erasure at Run-time ..............161 28.2 Insertion of Rules ......................................161 28.3 Deletion of Rules ......................................162 29 Querying the Rule Base 164 29.1 Basic Querying of Rules via clause{...} ........................164 29.2 Querying Rules via the Rule Structure Database ....................167 30 Aggregate Operations 171 30.1 Syntax of Aggregate Operators ..............................171 30.2 Evaluation of Aggregates .................................173 30.3 Scope for Variables in Aggregate Operators .......................174 30.4 Aggregation and Sorting of Results ............................175 30.5 Aggregation and Set-Valued Methods ..........................177 31 Control Flow Statements 178 31.1 If-Then-Else .........................................178 31.2 Yet another If-Then-Else ..................................179 31.3 Loops ............................................180 31.3.1 The while-do and do-until Loops .........................180 31.3.2 The while-loop and loop-until Loops .......................182 32 Constraint Solving 183 Portions Copyright © 2013–2018 Coherent Knowledge v CONTENTS 33 Random Numbers 184 34 Low-level Predicates 184 35 Sensors: Predicates with Restricted Invocation Patterns 186 36 Rearranging the Order of Subgoals at Run Time 189 37 Rule Ids and Meta-information about Rules 192 37.1 The Current Rule Id Quasi-constant ...........................195 37.2 Enabling and Disabling Rules ...............................196 37.3 Changing the Defeasibility at Run Time .........................197 37.4 Querying Rule Descriptors .................................198 37.5 Reserved Properties in Rule Descriptors .........................199 38 Latent Queries 200 39 Integrity Constraints 202 40 Alerts 207 41 Defeasible Reasoning 210 41.1 Concepts of Defeasible Reasoning .............................212 41.2 Specifying an Argumentation Theory to Use .......................213 41.3 Rule Overriding and Conflicts ...............................214 41.4 Cancellation of Rules ....................................215 41.5 Changing the Default Defeasibility Status ........................218 41.6 Supported Argumentation Theories ............................219 41.6.1 The Cautious, Original, and Strong Courteous Argumentation Theories . 219 41.6.2 Courteous Logic with Exclusion Constraints ...................220 41.7 Defeasible Rules Must Be Purely Logical .........................221 Portions Copyright © 2013–2018 Coherent Knowledge vi CONTENTS 41.8 Debugging Defeasible Knowledge Bases .........................223 42 Primitive Data Types 224 42.1 The ERGO \symbol Data Type ..............................226 42.2 The \iri Data Type .....................................228 42.2.1 Scope of IRI Prefixes ................................230 42.2.2 IRI Prefix Querying and Decomposition .....................232 42.2.3 Class \iri ......................................233 42.3 The Primitive Type \dateTime ..............................235 42.4 The Primitive Type \date ................................237