SlideShare a Scribd company logo
1 of 113
Download to read offline
COMP 213 
Advanced Object-oriented Programming 
Lecture 13 
Propositional 
Logic
Task 
Develop a program that: 
allows a user to enter a string representing a term in 
propositional logic; 
prints out the term with minimal and maximal brackets; 
prints out a truth table for the term. 
(actually, we won’t have time for the third one)
Task 
Develop a program that: 
allows a user to enter a string representing a term in 
propositional logic; 
prints out the term with minimal and maximal brackets; 
prints out a truth table for the term. 
(actually, we won’t have time for the third one)
Propositional Logic 
Propositional logic is the logic of truth and reasoning. It is 
concerned with how some statements follow logically from 
other statements to form logical arguments. 
It was first systematically studied by Aristotle, and is still of 
interest in philosophical logic (mainly as one of the simplest 
non-trivial logics). 
It is also relevant to Computer Science as the basis of Boolean 
logic.
George Boole, 1815–1864 
In 1854, Boole published An 
Investigation into the Laws of 
Thought, on Which are founded the 
Mathematical Theories of Logic and 
Probabilities. 
This work related logical operators and binary arithmetic, and is 
the basis for what is now called Boolean logic 
(which is actually just another name for Propositional Logic).
Propositional Logic 
Propositional Logic is a language consisting of terms that are 
built from variables, the constants true and false, and Boolean 
operators (‘not’, ‘and’, ’or’, etc.). 
In BNF: 
hPropi ::= hVari | true | false | not hPropi | 
hPropi and hPropi | hPropi or hPropi | 
hPropi implies hPropi 
hVari ::= ’A | ’B | ’C | · · · 
There is a reason for the single quotes before the variables . . . : 
we’ll use one of Maude’s built-in types for these.
Propositional Logic 
Propositional Logic is a language consisting of terms that are 
built from variables, the constants true and false, and Boolean 
operators (‘not’, ‘and’, ’or’, etc.). 
In BNF: 
hPropi ::= hVari | true | false | not hPropi | 
hPropi and hPropi | hPropi or hPropi | 
hPropi implies hPropi 
hVari ::= ’A | ’B | ’C | · · · 
There is a reason for the single quotes before the variables . . . : 
we’ll use one of Maude’s built-in types for these.
Propositional Logic 
Propositional Logic is a language consisting of terms that are 
built from variables, the constants true and false, and Boolean 
operators (‘not’, ‘and’, ’or’, etc.). 
In BNF: 
hPropi ::= hVari | true | false | not hPropi | 
hPropi and hPropi | hPropi or hPropi | 
hPropi implies hPropi 
hVari ::= ’A | ’B | ’C | · · · 
There is a reason for the single quotes before the variables . . . : 
we’ll use one of Maude’s built-in types for these.
Propositional ADT 
Propositions also form an Abstract Data Type. 
The propositions themselves are the abstract data values. 
The operations are the constants (variables, true, false) and the 
operators (not, and, or, implies). 
We’ll specify this ADT in Maude, then implement it in Java.
Propositional ADT 
Propositions also form an Abstract Data Type. 
The propositions themselves are the abstract data values. 
The operations are the constants (variables, true, false) and the 
operators (not, and, or, implies). 
We’ll specify this ADT in Maude, then implement it in Java.
Propositional ADT 
Propositions also form an Abstract Data Type. 
The propositions themselves are the abstract data values. 
The operations are the constants (variables, true, false) and the 
operators (not, and, or, implies). 
We’ll specify this ADT in Maude, then implement it in Java.
Propositional ADT 
Propositions also form an Abstract Data Type. 
The propositions themselves are the abstract data values. 
The operations are the constants (variables, true, false) and the 
operators (not, and, or, implies). 
We’ll specify this ADT in Maude, then implement it in Java.
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
Maude, Maude, Maude 
file: PropLog.maude 
fmod PROP LOGIC is 
*** import Maude’s quoted identifiers, 
*** renaming the sort Qid to PVar (for "Propositional Variable") 
protecting QID *(sort Qid to PVar) . 
Maude’s built-in module QID declares a sort Qid of ‘quoted 
identifiers’; these are very like strings, except rather than being 
enclosed in double quotes ("), they are preceded by a single 
closing quote (’). E.g., ’a, ’aa, ’abc, etc. 
This simply means that the sort Qid is now called PVar
More Maude 
file PropLog.maude 
*** propositions 
sort Prop . 
*** every variable is a proposition 
subsort PVar < Prop . 
NB this is Maude, not Java; subsorts are not the same thing as 
inheritance — we’re not suggesting 
class Prop extends PVar { ... } 
but it does mean that PVars can be used whenever a Prop is 
expected.
More Maude 
file PropLog.maude 
*** propositions 
sort Prop . 
*** every variable is a proposition 
subsort PVar < Prop . 
NB this is Maude, not Java; subsorts are not the same thing as 
inheritance — we’re not suggesting 
class Prop extends PVar { ... } 
but it does mean that PVars can be used whenever a Prop is 
expected.
More Maude 
file PropLog.maude 
*** propositions 
sort Prop . 
*** every variable is a proposition 
subsort PVar < Prop . 
NB this is Maude, not Java; subsorts are not the same thing as 
inheritance — we’re not suggesting 
class Prop extends PVar { ... } 
but it does mean that PVars can be used whenever a Prop is 
expected.
More Maude 
file PropLog.maude 
*** propositions 
sort Prop . 
*** every variable is a proposition 
subsort PVar < Prop . 
NB this is Maude, not Java; subsorts are not the same thing as 
inheritance — we’re not suggesting 
class Prop extends PVar { ... } 
but it does mean that PVars can be used whenever a Prop is 
expected.
More Maude 
file PropLog.maude 
*** propositions 
sort Prop . 
*** every variable is a proposition 
subsort PVar < Prop . 
NB this is Maude, not Java; subsorts are not the same thing as 
inheritance — we’re not suggesting 
class Prop extends PVar { ... } 
but it does mean that PVars can be used whenever a Prop is 
expected.
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Maude 
file: PropLog.maude 
ops true false : -> Prop . 
op and : Prop Prop -> Prop . 
op or : Prop Prop -> Prop . 
op implies : Prop Prop -> Prop . 
op not : Prop -> Prop . 
Note: one underscore for each argument 
The first three operations are infix; ‘not’ is prefix 
Example propositions: 
not ’a and ’b implies ’c or true
More Examples of Terms 
’a 
true 
not ’a 
not false 
’a and true 
’a and not ’b 
’c or ’a and not ’b 
not ’c implies not ’b and not not ’a 
As we can see from the last two examples, terms can be 
ambiguous: 
(’c or ’a) and not ’b / ’c or (’a and not ’b)
More Examples of Terms 
’a 
true 
not ’a 
not false 
’a and true 
’a and not ’b 
’c or ’a and not ’b 
not ’c implies not ’b and not not ’a 
As we can see from the last two examples, terms can be 
ambiguous: 
(’c or ’a) and not ’b / ’c or (’a and not ’b)
(Brackets) 
We can use brackets to disambiguate terms; e.g., 
(’c or ’a) and not ’b 
We can also use conventions so that we sometimes don’t need 
brackets to disambiguate terms: 
we give a precedence to each operator; operations with a low 
precedence are more tightly binding. 
file: PropLog.maude 
op and : Prop Prop -> Prop [prec 40] . 
op or : Prop Prop -> Prop [prec 44] . 
op implies : Prop Prop -> Prop [prec 48] . 
op not : Prop -> Prop [prec 30] .
(Brackets) 
We can use brackets to disambiguate terms; e.g., 
(’c or ’a) and not ’b 
We can also use conventions so that we sometimes don’t need 
brackets to disambiguate terms: 
we give a precedence to each operator; operations with a low 
precedence are more tightly binding. 
file: PropLog.maude 
op and : Prop Prop -> Prop [prec 40] . 
op or : Prop Prop -> Prop [prec 44] . 
op implies : Prop Prop -> Prop [prec 48] . 
op not : Prop -> Prop [prec 30] .
(Brackets) 
We can use brackets to disambiguate terms; e.g., 
(’c or ’a) and not ’b 
We can also use conventions so that we sometimes don’t need 
brackets to disambiguate terms: 
we give a precedence to each operator; operations with a low 
precedence are more tightly binding. 
file: PropLog.maude 
op and : Prop Prop -> Prop [prec 40] . 
op or : Prop Prop -> Prop [prec 44] . 
op implies : Prop Prop -> Prop [prec 48] . 
op not : Prop -> Prop [prec 30] .
Examples 
Term Means 
’a and ’b or ’c (’a and ’b) or ’c 
not ’a and ’b implies ’c ((not ’a) and ’b) implies ’c 
not ’a and (’b implies ’c) (not ’a) and (’b implies ’c) 
’a and ’b or ’c implies ’d ((’a and ’b) or ’c) implies ’d 
This disambiguates terms with different operators 
but what about terms with the same operators, e.g. 
’a and ’b and ’c ?
Examples 
Term Means 
’a and ’b or ’c (’a and ’b) or ’c 
not ’a and ’b implies ’c ((not ’a) and ’b) implies ’c 
not ’a and (’b implies ’c) (not ’a) and (’b implies ’c) 
’a and ’b or ’c implies ’d ((’a and ’b) or ’c) implies ’d 
This disambiguates terms with different operators 
but what about terms with the same operators, e.g. 
’a and ’b and ’c ?
Associativity 
We will adopt the convention that binary operators are 
right-associative. I.e., 
Term Means 
’a or ’b or ’c or ’d or ’e ’a or (’b or (’c or (’d or ’e))) 
’a and ’b and ’c and ’d ’a and (’b and (’c and ’d)) 
’a implies ’b implies ’c ’a implies (’b implies ’c) 
etc.
Associativity 
In fact, we will use a semantic property of and and or (called 
associativity), which says that any way of bracketing 
’a and ’b and ’c and ’d 
gives the same result, so we can omit brackets entirely 
(and similarly for or). 
file: PropLog.maude 
op and : Prop Prop -> Prop [assoc prec 40] . 
op or : Prop Prop -> Prop [assoc prec 44] . 
op implies : Prop Prop -> Prop [prec 48] . 
op not : Prop -> Prop [prec 30] .
Associativity 
In fact, we will use a semantic property of and and or (called 
associativity), which says that any way of bracketing 
’a and ’b and ’c and ’d 
gives the same result, so we can omit brackets entirely 
(and similarly for or). 
file: PropLog.maude 
op and : Prop Prop -> Prop [assoc prec 40] . 
op or : Prop Prop -> Prop [assoc prec 44] . 
op implies : Prop Prop -> Prop [prec 48] . 
op not : Prop -> Prop [prec 30] .
Printing with Brackets 
We still need to specify operations to print with maximal and 
minimal bracketing. 
file: PropLog.maude 
op printAllBrackets : Prop -> String . 
We specify what this operation does by considering what its 
arguments may be: a PVar, true, false, or a term built from the 
other four operations (and, or, implies, not).
Printing with Brackets 
We still need to specify operations to print with maximal and 
minimal bracketing. 
file: PropLog.maude 
op printAllBrackets : Prop -> String . 
We specify what this operation does by considering what its 
arguments may be: a PVar, true, false, or a term built from the 
other four operations (and, or, implies, not).
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
eq printAllBrackets(true) = "(true)" . 
eq printAllBrackets(false) = "(false)" . 
var V : PVar . 
eq printAllBrackets(V) = "(" + string(V) + ")" . 
module QID 
op string : Qid -> String . 
module QID *(sort Qid to PVar) 
op string : PVar -> String . 
e.g., string(’example) = "example"
Printing with Brackets 
file: PropLog.maude 
vars P P1 P2 : Prop . 
eq printAllBrackets(P1 and P2) = 
"(" + printAllBrackets(P1) + " and " 
+ printAllBrackets(P2) + ")" . 
*** similarly for ‘or’ and ‘implies’ 
. . . 
eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
Printing with Brackets 
file: PropLog.maude 
vars P P1 P2 : Prop . 
eq printAllBrackets(P1 and P2) = 
"(" + printAllBrackets(P1) + " and " 
+ printAllBrackets(P2) + ")" . 
*** similarly for ‘or’ and ‘implies’ 
. . . 
eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
Printing with Brackets 
file: PropLog.maude 
vars P P1 P2 : Prop . 
eq printAllBrackets(P1 and P2) = 
"(" + printAllBrackets(P1) + " and " 
+ printAllBrackets(P2) + ")" . 
*** similarly for ‘or’ and ‘implies’ 
. . . 
eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
Printing with Brackets 
file: PropLog.maude 
vars P P1 P2 : Prop . 
eq printAllBrackets(P1 and P2) = 
"(" + printAllBrackets(P1) + " and " 
+ printAllBrackets(P2) + ")" . 
*** similarly for ‘or’ and ‘implies’ 
. . . 
eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
Printing with Brackets 
file: PropLog.maude 
vars P P1 P2 : Prop . 
eq printAllBrackets(P1 and P2) = 
"(" + printAllBrackets(P1) + " and " 
+ printAllBrackets(P2) + ")" . 
*** similarly for ‘or’ and ‘implies’ 
. . . 
eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
Printing with Brackets 
file: PropLog.maude 
vars P P1 P2 : Prop . 
eq printAllBrackets(P1 and P2) = 
"(" + printAllBrackets(P1) + " and " 
+ printAllBrackets(P2) + ")" . 
*** similarly for ‘or’ and ‘implies’ 
. . . 
eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
Printing with Brackets 
file: PropLog.maude 
vars P P1 P2 : Prop . 
eq printAllBrackets(P1 and P2) = 
"(" + printAllBrackets(P1) + " and " 
+ printAllBrackets(P2) + ")" . 
*** similarly for ‘or’ and ‘implies’ 
. . . 
eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
Printing with Minimal Brackets 
file: PropLog.maude 
op toString : Prop -> String . 
eq toString(true) = "true" . 
eq toString(false) = "false" . 
eq toString(V) = string(V) . 
eq toString(P1 and P2) = ? . 
If we just write 
eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . 
(and similarly for or, implies, not) 
then we’ll never get any brackets anywhere.
Printing with Minimal Brackets 
file: PropLog.maude 
op toString : Prop -> String . 
eq toString(true) = "true" . 
eq toString(false) = "false" . 
eq toString(V) = string(V) . 
eq toString(P1 and P2) = ? . 
If we just write 
eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . 
(and similarly for or, implies, not) 
then we’ll never get any brackets anywhere.
Printing with Minimal Brackets 
file: PropLog.maude 
op toString : Prop -> String . 
eq toString(true) = "true" . 
eq toString(false) = "false" . 
eq toString(V) = string(V) . 
eq toString(P1 and P2) = ? . 
If we just write 
eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . 
(and similarly for or, implies, not) 
then we’ll never get any brackets anywhere.
Printing with Minimal Brackets 
file: PropLog.maude 
op toString : Prop -> String . 
eq toString(true) = "true" . 
eq toString(false) = "false" . 
eq toString(V) = string(V) . 
eq toString(P1 and P2) = ? . 
If we just write 
eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . 
(and similarly for or, implies, not) 
then we’ll never get any brackets anywhere.
Printing with Minimal Brackets 
file: PropLog.maude 
op toString : Prop -> String . 
eq toString(true) = "true" . 
eq toString(false) = "false" . 
eq toString(V) = string(V) . 
eq toString(P1 and P2) = ? . 
If we just write 
eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . 
(and similarly for or, implies, not) 
then we’ll never get any brackets anywhere.
Printing with Minimal Brackets 
file: PropLog.maude 
op toString : Prop -> String . 
eq toString(true) = "true" . 
eq toString(false) = "false" . 
eq toString(V) = string(V) . 
eq toString(P1 and P2) = ? . 
If we just write 
eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . 
(and similarly for or, implies, not) 
then we’ll never get any brackets anywhere.
Printing with Minimal Brackets 
file: PropLog.maude 
op toString : Prop -> String . 
eq toString(true) = "true" . 
eq toString(false) = "false" . 
eq toString(V) = string(V) . 
eq toString(P1 and P2) = ? . 
If we just write 
eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . 
(and similarly for or, implies, not) 
then we’ll never get any brackets anywhere.
Printing with Minimal Brackets 
file: PropLog.maude 
eq toString(P1 and P2) = ? . 
If P1 is of the form P3 and P4, then we don’t need brackets 
around the first argument. 
E.g., 
toString(’a and ’b and ’c) = "’a and ’b and ’c" . 
But if P1 is of the form P3 or P4, then we do need brackets 
around the first argument. 
E.g., 
toString(’a or ’b and ’c) = "(’a or ’b) and ’c" .
Printing with Minimal Brackets 
file: PropLog.maude 
eq toString(P1 and P2) = ? . 
If P1 is of the form P3 and P4, then we don’t need brackets 
around the first argument. 
E.g., 
toString(’a and ’b and ’c) = "’a and ’b and ’c" . 
But if P1 is of the form P3 or P4, then we do need brackets 
around the first argument. 
E.g., 
toString(’a or ’b and ’c) = "(’a or ’b) and ’c" .
Printing with Minimal Brackets 
file: PropLog.maude 
eq toString(P1 and P2) = ? . 
If P1 is of the form P3 and P4, then we don’t need brackets 
around the first argument. 
E.g., 
toString(’a and ’b and ’c) = "’a and ’b and ’c" . 
But if P1 is of the form P3 or P4, then we do need brackets 
around the first argument. 
E.g., 
toString(’a or ’b and ’c) = "(’a or ’b) and ’c" .
Printing with Minimal Brackets 
In the second case, brackets were needed because or has 
lower precedence than and. 
We’ll add an extra parameter that represents ‘the precedence 
of the operator above a term’. 
This gives us exactly the information we need in order to decide 
whether an operand requires brackets around it. 
file: PropLog.maude 
*** put brackets around the proposition if the precedence of 
*** its main operator is greater than the given integer 
op toStringPrec : Prop Int -> String .
Printing with Minimal Brackets 
In the second case, brackets were needed because or has 
lower precedence than and. 
We’ll add an extra parameter that represents ‘the precedence 
of the operator above a term’. 
This gives us exactly the information we need in order to decide 
whether an operand requires brackets around it. 
file: PropLog.maude 
*** put brackets around the proposition if the precedence of 
*** its main operator is greater than the given integer 
op toStringPrec : Prop Int -> String .
Printing with Minimal Brackets 
In the second case, brackets were needed because or has 
lower precedence than and. 
We’ll add an extra parameter that represents ‘the precedence 
of the operator above a term’. 
This gives us exactly the information we need in order to decide 
whether an operand requires brackets around it. 
file: PropLog.maude 
*** put brackets around the proposition if the precedence of 
*** its main operator is greater than the given integer 
op toStringPrec : Prop Int -> String .
Printing with Minimal Brackets 
In the second case, brackets were needed because or has 
lower precedence than and. 
We’ll add an extra parameter that represents ‘the precedence 
of the operator above a term’. 
This gives us exactly the information we need in order to decide 
whether an operand requires brackets around it. 
file: PropLog.maude 
*** put brackets around the proposition if the precedence of 
*** its main operator is greater than the given integer 
op toStringPrec : Prop Int -> String .
Printing with Minimal Brackets 
file: PropLog.maude 
*** no operator has precedence greater than 48, 
*** so no outermost brackets 
eq toString(P) = toStringPrec(P, 48) . 
var I : Int . 
eq toStringPrec(true, I) = "true" . 
eq toStringPrec(false, I) = "false" . 
eq toStringPrec(V, I) = string(V) .
Printing with Minimal Brackets 
file: PropLog.maude 
*** no operator has precedence greater than 48, 
*** so no outermost brackets 
eq toString(P) = toStringPrec(P, 48) . 
var I : Int . 
eq toStringPrec(true, I) = "true" . 
eq toStringPrec(false, I) = "false" . 
eq toStringPrec(V, I) = string(V) .
Printing with Minimal Brackets 
file: PropLog.maude 
*** no operator has precedence greater than 48, 
*** so no outermost brackets 
eq toString(P) = toStringPrec(P, 48) . 
var I : Int . 
eq toStringPrec(true, I) = "true" . 
eq toStringPrec(false, I) = "false" . 
eq toStringPrec(V, I) = string(V) .
Printing with Minimal Brackets 
file: PropLog.maude 
*** no operator has precedence greater than 48, 
*** so no outermost brackets 
eq toString(P) = toStringPrec(P, 48) . 
var I : Int . 
eq toStringPrec(true, I) = "true" . 
eq toStringPrec(false, I) = "false" . 
eq toStringPrec(V, I) = string(V) .
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 and P2, I) = 
toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
if I >= 40 . *** no brackets needed 
cq toStringPrec(P1 and P2, I) = 
"(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) 
+ ")" 
if I < 40 . *** brackets are needed 
so P1 and P2 will have brackets if needed 
similarly for or and not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Printing with Minimal Brackets 
file: PropLog.maude 
cq toStringPrec(P1 implies P2, I) = 
toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
if I >= 48 . *** no brackets needed 
cq toStringPrec(P1 implies P2, I) = 
"(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) 
+ ")" 
if I < 48 . *** brackets are needed 
This gives us right associativity: 
P1 will have brackets round it if its main operator is ‘implies’; 
P2 will not
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Maude Interpreter 
reduce toString((’a or ’b) and ’c) . 
= 
toStringPrec((’a or ’b) and ’c, 48) 
= *** 48 >= 40; no brackets needed 
toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) 
= *** 40 < 44; brackets are needed 
"(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" 
+ " and " + toStringPrec(’c, 40) 
= 
"(" + string(’a) + " or " + string(’b) + ")" 
+ " and " + string(’c) 
= 
"(a or b) and c"
Back to Java 
public class Prop { 
public Prop and(Prop p1, Prop p2) { ... } 
// similarly for ‘or’, etc. 
public String printAllBrackets() { ...} 
public String toString() { ...} 
} 
We need a data representation.
Back to Java 
public class Prop { 
public Prop and(Prop p1, Prop p2) { ... } 
// similarly for ‘or’, etc. 
public String printAllBrackets() { ...} 
public String toString() { ...} 
} 
We need a data representation.
Back to Java 
public class Prop { 
public Prop and(Prop p1, Prop p2) { ... } 
// similarly for ‘or’, etc. 
public String printAllBrackets() { ...} 
public String toString() { ...} 
} 
We need a data representation.
That’s All, Folks! 
Summary 
sort Prop 
Maude equations 
helper functions 
Next: 
data representation

More Related Content

What's hot

String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)Anwar Hasan Shuvo
 
String handling session 5
String handling session 5String handling session 5
String handling session 5Raja Sekhar
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packagesSardar Alam
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence APIIlio Catallo
 
Lecture04 polymorphism
Lecture04 polymorphismLecture04 polymorphism
Lecture04 polymorphismHariz Mustafa
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxingGeetha Manohar
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptFu Cheng
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Anil Bapat
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)Ravi Kant Sahu
 
Strings in Java
Strings in Java Strings in Java
Strings in Java Hitesh-Java
 
How to get along with implicits
How to get along with implicits How to get along with implicits
How to get along with implicits Taisuke Oe
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 

What's hot (18)

Java Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O MechanismsJava Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O Mechanisms
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
 
Java String
Java String Java String
Java String
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
String handling session 5
String handling session 5String handling session 5
String handling session 5
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Lecture04 polymorphism
Lecture04 polymorphismLecture04 polymorphism
Lecture04 polymorphism
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
04 variables
04 variables04 variables
04 variables
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 
How to get along with implicits
How to get along with implicits How to get along with implicits
How to get along with implicits
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 

Viewers also liked

Gagnon family collage
Gagnon family collageGagnon family collage
Gagnon family collagegagnonohoh3
 
παιδεία
παιδείαπαιδεία
παιδείαnikosas
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서sunwooindia
 

Viewers also liked (7)

2012 upward celebration 031812
2012 upward celebration   0318122012 upward celebration   031812
2012 upward celebration 031812
 
Gagnon family collage
Gagnon family collageGagnon family collage
Gagnon family collage
 
Paulo freire trabajo y blog
Paulo freire trabajo y blogPaulo freire trabajo y blog
Paulo freire trabajo y blog
 
RESULTADOS DE ESTABILIDAD GLOBAL DE UN MODELO SIRS
RESULTADOS DE ESTABILIDAD GLOBAL DE UN MODELO SIRSRESULTADOS DE ESTABILIDAD GLOBAL DE UN MODELO SIRS
RESULTADOS DE ESTABILIDAD GLOBAL DE UN MODELO SIRS
 
παιδεία
παιδείαπαιδεία
παιδεία
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서
 
NTSB presents: Is your aircraft talking to you? Listen!
NTSB presents: Is your aircraft talking to you? Listen!NTSB presents: Is your aircraft talking to you? Listen!
NTSB presents: Is your aircraft talking to you? Listen!
 

Similar to L2

Lo12
Lo12Lo12
Lo12lksoo
 
Eo gaddis java_chapter_06_Classes and Objects
Eo gaddis java_chapter_06_Classes and ObjectsEo gaddis java_chapter_06_Classes and Objects
Eo gaddis java_chapter_06_Classes and ObjectsGina Bullock
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eGina Bullock
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eGina Bullock
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzJAX London
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdfvenud11
 
OOP - Java is pass-by-value
OOP - Java is pass-by-valueOOP - Java is pass-by-value
OOP - Java is pass-by-valueMudasir Qazi
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller ColumnsJonathan Fine
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ ComparatorSean McElrath
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course yoavrubin
 
Eqela Core API and Utilities
Eqela Core API and UtilitiesEqela Core API and Utilities
Eqela Core API and Utilitiesjobandesther
 
Core Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdfCore Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdfSudhanshiBakre1
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed OverviewBuddha Tree
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 

Similar to L2 (20)

01
0101
01
 
Lo12
Lo12Lo12
Lo12
 
Eo gaddis java_chapter_06_Classes and Objects
Eo gaddis java_chapter_06_Classes and ObjectsEo gaddis java_chapter_06_Classes and Objects
Eo gaddis java_chapter_06_Classes and Objects
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5e
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5e
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
 
Python modules
Python modulesPython modules
Python modules
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdf
 
OOP - Java is pass-by-value
OOP - Java is pass-by-valueOOP - Java is pass-by-value
OOP - Java is pass-by-value
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
 
Eqela Core API and Utilities
Eqela Core API and UtilitiesEqela Core API and Utilities
Eqela Core API and Utilities
 
Core Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdfCore Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdf
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 

More from lksoo

More from lksoo (20)

Lo48
Lo48Lo48
Lo48
 
Lo43
Lo43Lo43
Lo43
 
Lo39
Lo39Lo39
Lo39
 
Lo37
Lo37Lo37
Lo37
 
Lo27
Lo27Lo27
Lo27
 
Lo17
Lo17Lo17
Lo17
 
T3
T3T3
T3
 
T2
T2T2
T2
 
T1
T1T1
T1
 
T4
T4T4
T4
 
P5
P5P5
P5
 
P4
P4P4
P4
 
P3
P3P3
P3
 
P1
P1P1
P1
 
P2
P2P2
P2
 
L10
L10L10
L10
 
L9
L9L9
L9
 
L8
L8L8
L8
 
L7
L7L7
L7
 
L6
L6L6
L6
 

Recently uploaded

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Recently uploaded (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

L2

  • 1. COMP 213 Advanced Object-oriented Programming Lecture 13 Propositional Logic
  • 2. Task Develop a program that: allows a user to enter a string representing a term in propositional logic; prints out the term with minimal and maximal brackets; prints out a truth table for the term. (actually, we won’t have time for the third one)
  • 3. Task Develop a program that: allows a user to enter a string representing a term in propositional logic; prints out the term with minimal and maximal brackets; prints out a truth table for the term. (actually, we won’t have time for the third one)
  • 4. Propositional Logic Propositional logic is the logic of truth and reasoning. It is concerned with how some statements follow logically from other statements to form logical arguments. It was first systematically studied by Aristotle, and is still of interest in philosophical logic (mainly as one of the simplest non-trivial logics). It is also relevant to Computer Science as the basis of Boolean logic.
  • 5. George Boole, 1815–1864 In 1854, Boole published An Investigation into the Laws of Thought, on Which are founded the Mathematical Theories of Logic and Probabilities. This work related logical operators and binary arithmetic, and is the basis for what is now called Boolean logic (which is actually just another name for Propositional Logic).
  • 6. Propositional Logic Propositional Logic is a language consisting of terms that are built from variables, the constants true and false, and Boolean operators (‘not’, ‘and’, ’or’, etc.). In BNF: hPropi ::= hVari | true | false | not hPropi | hPropi and hPropi | hPropi or hPropi | hPropi implies hPropi hVari ::= ’A | ’B | ’C | · · · There is a reason for the single quotes before the variables . . . : we’ll use one of Maude’s built-in types for these.
  • 7. Propositional Logic Propositional Logic is a language consisting of terms that are built from variables, the constants true and false, and Boolean operators (‘not’, ‘and’, ’or’, etc.). In BNF: hPropi ::= hVari | true | false | not hPropi | hPropi and hPropi | hPropi or hPropi | hPropi implies hPropi hVari ::= ’A | ’B | ’C | · · · There is a reason for the single quotes before the variables . . . : we’ll use one of Maude’s built-in types for these.
  • 8. Propositional Logic Propositional Logic is a language consisting of terms that are built from variables, the constants true and false, and Boolean operators (‘not’, ‘and’, ’or’, etc.). In BNF: hPropi ::= hVari | true | false | not hPropi | hPropi and hPropi | hPropi or hPropi | hPropi implies hPropi hVari ::= ’A | ’B | ’C | · · · There is a reason for the single quotes before the variables . . . : we’ll use one of Maude’s built-in types for these.
  • 9. Propositional ADT Propositions also form an Abstract Data Type. The propositions themselves are the abstract data values. The operations are the constants (variables, true, false) and the operators (not, and, or, implies). We’ll specify this ADT in Maude, then implement it in Java.
  • 10. Propositional ADT Propositions also form an Abstract Data Type. The propositions themselves are the abstract data values. The operations are the constants (variables, true, false) and the operators (not, and, or, implies). We’ll specify this ADT in Maude, then implement it in Java.
  • 11. Propositional ADT Propositions also form an Abstract Data Type. The propositions themselves are the abstract data values. The operations are the constants (variables, true, false) and the operators (not, and, or, implies). We’ll specify this ADT in Maude, then implement it in Java.
  • 12. Propositional ADT Propositions also form an Abstract Data Type. The propositions themselves are the abstract data values. The operations are the constants (variables, true, false) and the operators (not, and, or, implies). We’ll specify this ADT in Maude, then implement it in Java.
  • 13. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 14. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 15. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 16. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 17. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 18. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 19. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 20. Maude, Maude, Maude file: PropLog.maude fmod PROP LOGIC is *** import Maude’s quoted identifiers, *** renaming the sort Qid to PVar (for "Propositional Variable") protecting QID *(sort Qid to PVar) . Maude’s built-in module QID declares a sort Qid of ‘quoted identifiers’; these are very like strings, except rather than being enclosed in double quotes ("), they are preceded by a single closing quote (’). E.g., ’a, ’aa, ’abc, etc. This simply means that the sort Qid is now called PVar
  • 21. More Maude file PropLog.maude *** propositions sort Prop . *** every variable is a proposition subsort PVar < Prop . NB this is Maude, not Java; subsorts are not the same thing as inheritance — we’re not suggesting class Prop extends PVar { ... } but it does mean that PVars can be used whenever a Prop is expected.
  • 22. More Maude file PropLog.maude *** propositions sort Prop . *** every variable is a proposition subsort PVar < Prop . NB this is Maude, not Java; subsorts are not the same thing as inheritance — we’re not suggesting class Prop extends PVar { ... } but it does mean that PVars can be used whenever a Prop is expected.
  • 23. More Maude file PropLog.maude *** propositions sort Prop . *** every variable is a proposition subsort PVar < Prop . NB this is Maude, not Java; subsorts are not the same thing as inheritance — we’re not suggesting class Prop extends PVar { ... } but it does mean that PVars can be used whenever a Prop is expected.
  • 24. More Maude file PropLog.maude *** propositions sort Prop . *** every variable is a proposition subsort PVar < Prop . NB this is Maude, not Java; subsorts are not the same thing as inheritance — we’re not suggesting class Prop extends PVar { ... } but it does mean that PVars can be used whenever a Prop is expected.
  • 25. More Maude file PropLog.maude *** propositions sort Prop . *** every variable is a proposition subsort PVar < Prop . NB this is Maude, not Java; subsorts are not the same thing as inheritance — we’re not suggesting class Prop extends PVar { ... } but it does mean that PVars can be used whenever a Prop is expected.
  • 26. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 27. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 28. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 29. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 30. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 31. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 32. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 33. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 34. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 35. More Maude file: PropLog.maude ops true false : -> Prop . op and : Prop Prop -> Prop . op or : Prop Prop -> Prop . op implies : Prop Prop -> Prop . op not : Prop -> Prop . Note: one underscore for each argument The first three operations are infix; ‘not’ is prefix Example propositions: not ’a and ’b implies ’c or true
  • 36. More Examples of Terms ’a true not ’a not false ’a and true ’a and not ’b ’c or ’a and not ’b not ’c implies not ’b and not not ’a As we can see from the last two examples, terms can be ambiguous: (’c or ’a) and not ’b / ’c or (’a and not ’b)
  • 37. More Examples of Terms ’a true not ’a not false ’a and true ’a and not ’b ’c or ’a and not ’b not ’c implies not ’b and not not ’a As we can see from the last two examples, terms can be ambiguous: (’c or ’a) and not ’b / ’c or (’a and not ’b)
  • 38. (Brackets) We can use brackets to disambiguate terms; e.g., (’c or ’a) and not ’b We can also use conventions so that we sometimes don’t need brackets to disambiguate terms: we give a precedence to each operator; operations with a low precedence are more tightly binding. file: PropLog.maude op and : Prop Prop -> Prop [prec 40] . op or : Prop Prop -> Prop [prec 44] . op implies : Prop Prop -> Prop [prec 48] . op not : Prop -> Prop [prec 30] .
  • 39. (Brackets) We can use brackets to disambiguate terms; e.g., (’c or ’a) and not ’b We can also use conventions so that we sometimes don’t need brackets to disambiguate terms: we give a precedence to each operator; operations with a low precedence are more tightly binding. file: PropLog.maude op and : Prop Prop -> Prop [prec 40] . op or : Prop Prop -> Prop [prec 44] . op implies : Prop Prop -> Prop [prec 48] . op not : Prop -> Prop [prec 30] .
  • 40. (Brackets) We can use brackets to disambiguate terms; e.g., (’c or ’a) and not ’b We can also use conventions so that we sometimes don’t need brackets to disambiguate terms: we give a precedence to each operator; operations with a low precedence are more tightly binding. file: PropLog.maude op and : Prop Prop -> Prop [prec 40] . op or : Prop Prop -> Prop [prec 44] . op implies : Prop Prop -> Prop [prec 48] . op not : Prop -> Prop [prec 30] .
  • 41. Examples Term Means ’a and ’b or ’c (’a and ’b) or ’c not ’a and ’b implies ’c ((not ’a) and ’b) implies ’c not ’a and (’b implies ’c) (not ’a) and (’b implies ’c) ’a and ’b or ’c implies ’d ((’a and ’b) or ’c) implies ’d This disambiguates terms with different operators but what about terms with the same operators, e.g. ’a and ’b and ’c ?
  • 42. Examples Term Means ’a and ’b or ’c (’a and ’b) or ’c not ’a and ’b implies ’c ((not ’a) and ’b) implies ’c not ’a and (’b implies ’c) (not ’a) and (’b implies ’c) ’a and ’b or ’c implies ’d ((’a and ’b) or ’c) implies ’d This disambiguates terms with different operators but what about terms with the same operators, e.g. ’a and ’b and ’c ?
  • 43. Associativity We will adopt the convention that binary operators are right-associative. I.e., Term Means ’a or ’b or ’c or ’d or ’e ’a or (’b or (’c or (’d or ’e))) ’a and ’b and ’c and ’d ’a and (’b and (’c and ’d)) ’a implies ’b implies ’c ’a implies (’b implies ’c) etc.
  • 44. Associativity In fact, we will use a semantic property of and and or (called associativity), which says that any way of bracketing ’a and ’b and ’c and ’d gives the same result, so we can omit brackets entirely (and similarly for or). file: PropLog.maude op and : Prop Prop -> Prop [assoc prec 40] . op or : Prop Prop -> Prop [assoc prec 44] . op implies : Prop Prop -> Prop [prec 48] . op not : Prop -> Prop [prec 30] .
  • 45. Associativity In fact, we will use a semantic property of and and or (called associativity), which says that any way of bracketing ’a and ’b and ’c and ’d gives the same result, so we can omit brackets entirely (and similarly for or). file: PropLog.maude op and : Prop Prop -> Prop [assoc prec 40] . op or : Prop Prop -> Prop [assoc prec 44] . op implies : Prop Prop -> Prop [prec 48] . op not : Prop -> Prop [prec 30] .
  • 46. Printing with Brackets We still need to specify operations to print with maximal and minimal bracketing. file: PropLog.maude op printAllBrackets : Prop -> String . We specify what this operation does by considering what its arguments may be: a PVar, true, false, or a term built from the other four operations (and, or, implies, not).
  • 47. Printing with Brackets We still need to specify operations to print with maximal and minimal bracketing. file: PropLog.maude op printAllBrackets : Prop -> String . We specify what this operation does by considering what its arguments may be: a PVar, true, false, or a term built from the other four operations (and, or, implies, not).
  • 48. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 49. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 50. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 51. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 52. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 53. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 54. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 55. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 56. Printing with Brackets file: PropLog.maude eq printAllBrackets(true) = "(true)" . eq printAllBrackets(false) = "(false)" . var V : PVar . eq printAllBrackets(V) = "(" + string(V) + ")" . module QID op string : Qid -> String . module QID *(sort Qid to PVar) op string : PVar -> String . e.g., string(’example) = "example"
  • 57. Printing with Brackets file: PropLog.maude vars P P1 P2 : Prop . eq printAllBrackets(P1 and P2) = "(" + printAllBrackets(P1) + " and " + printAllBrackets(P2) + ")" . *** similarly for ‘or’ and ‘implies’ . . . eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
  • 58. Printing with Brackets file: PropLog.maude vars P P1 P2 : Prop . eq printAllBrackets(P1 and P2) = "(" + printAllBrackets(P1) + " and " + printAllBrackets(P2) + ")" . *** similarly for ‘or’ and ‘implies’ . . . eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
  • 59. Printing with Brackets file: PropLog.maude vars P P1 P2 : Prop . eq printAllBrackets(P1 and P2) = "(" + printAllBrackets(P1) + " and " + printAllBrackets(P2) + ")" . *** similarly for ‘or’ and ‘implies’ . . . eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
  • 60. Printing with Brackets file: PropLog.maude vars P P1 P2 : Prop . eq printAllBrackets(P1 and P2) = "(" + printAllBrackets(P1) + " and " + printAllBrackets(P2) + ")" . *** similarly for ‘or’ and ‘implies’ . . . eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
  • 61. Printing with Brackets file: PropLog.maude vars P P1 P2 : Prop . eq printAllBrackets(P1 and P2) = "(" + printAllBrackets(P1) + " and " + printAllBrackets(P2) + ")" . *** similarly for ‘or’ and ‘implies’ . . . eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
  • 62. Printing with Brackets file: PropLog.maude vars P P1 P2 : Prop . eq printAllBrackets(P1 and P2) = "(" + printAllBrackets(P1) + " and " + printAllBrackets(P2) + ")" . *** similarly for ‘or’ and ‘implies’ . . . eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
  • 63. Printing with Brackets file: PropLog.maude vars P P1 P2 : Prop . eq printAllBrackets(P1 and P2) = "(" + printAllBrackets(P1) + " and " + printAllBrackets(P2) + ")" . *** similarly for ‘or’ and ‘implies’ . . . eq printAllBrackets(not P) = "(not " + printAllBrackets(P) + ")" .
  • 64. Printing with Minimal Brackets file: PropLog.maude op toString : Prop -> String . eq toString(true) = "true" . eq toString(false) = "false" . eq toString(V) = string(V) . eq toString(P1 and P2) = ? . If we just write eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . (and similarly for or, implies, not) then we’ll never get any brackets anywhere.
  • 65. Printing with Minimal Brackets file: PropLog.maude op toString : Prop -> String . eq toString(true) = "true" . eq toString(false) = "false" . eq toString(V) = string(V) . eq toString(P1 and P2) = ? . If we just write eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . (and similarly for or, implies, not) then we’ll never get any brackets anywhere.
  • 66. Printing with Minimal Brackets file: PropLog.maude op toString : Prop -> String . eq toString(true) = "true" . eq toString(false) = "false" . eq toString(V) = string(V) . eq toString(P1 and P2) = ? . If we just write eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . (and similarly for or, implies, not) then we’ll never get any brackets anywhere.
  • 67. Printing with Minimal Brackets file: PropLog.maude op toString : Prop -> String . eq toString(true) = "true" . eq toString(false) = "false" . eq toString(V) = string(V) . eq toString(P1 and P2) = ? . If we just write eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . (and similarly for or, implies, not) then we’ll never get any brackets anywhere.
  • 68. Printing with Minimal Brackets file: PropLog.maude op toString : Prop -> String . eq toString(true) = "true" . eq toString(false) = "false" . eq toString(V) = string(V) . eq toString(P1 and P2) = ? . If we just write eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . (and similarly for or, implies, not) then we’ll never get any brackets anywhere.
  • 69. Printing with Minimal Brackets file: PropLog.maude op toString : Prop -> String . eq toString(true) = "true" . eq toString(false) = "false" . eq toString(V) = string(V) . eq toString(P1 and P2) = ? . If we just write eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . (and similarly for or, implies, not) then we’ll never get any brackets anywhere.
  • 70. Printing with Minimal Brackets file: PropLog.maude op toString : Prop -> String . eq toString(true) = "true" . eq toString(false) = "false" . eq toString(V) = string(V) . eq toString(P1 and P2) = ? . If we just write eq toString(P1 and P2) = toString(P1) + " and " + toString(P2) . (and similarly for or, implies, not) then we’ll never get any brackets anywhere.
  • 71. Printing with Minimal Brackets file: PropLog.maude eq toString(P1 and P2) = ? . If P1 is of the form P3 and P4, then we don’t need brackets around the first argument. E.g., toString(’a and ’b and ’c) = "’a and ’b and ’c" . But if P1 is of the form P3 or P4, then we do need brackets around the first argument. E.g., toString(’a or ’b and ’c) = "(’a or ’b) and ’c" .
  • 72. Printing with Minimal Brackets file: PropLog.maude eq toString(P1 and P2) = ? . If P1 is of the form P3 and P4, then we don’t need brackets around the first argument. E.g., toString(’a and ’b and ’c) = "’a and ’b and ’c" . But if P1 is of the form P3 or P4, then we do need brackets around the first argument. E.g., toString(’a or ’b and ’c) = "(’a or ’b) and ’c" .
  • 73. Printing with Minimal Brackets file: PropLog.maude eq toString(P1 and P2) = ? . If P1 is of the form P3 and P4, then we don’t need brackets around the first argument. E.g., toString(’a and ’b and ’c) = "’a and ’b and ’c" . But if P1 is of the form P3 or P4, then we do need brackets around the first argument. E.g., toString(’a or ’b and ’c) = "(’a or ’b) and ’c" .
  • 74. Printing with Minimal Brackets In the second case, brackets were needed because or has lower precedence than and. We’ll add an extra parameter that represents ‘the precedence of the operator above a term’. This gives us exactly the information we need in order to decide whether an operand requires brackets around it. file: PropLog.maude *** put brackets around the proposition if the precedence of *** its main operator is greater than the given integer op toStringPrec : Prop Int -> String .
  • 75. Printing with Minimal Brackets In the second case, brackets were needed because or has lower precedence than and. We’ll add an extra parameter that represents ‘the precedence of the operator above a term’. This gives us exactly the information we need in order to decide whether an operand requires brackets around it. file: PropLog.maude *** put brackets around the proposition if the precedence of *** its main operator is greater than the given integer op toStringPrec : Prop Int -> String .
  • 76. Printing with Minimal Brackets In the second case, brackets were needed because or has lower precedence than and. We’ll add an extra parameter that represents ‘the precedence of the operator above a term’. This gives us exactly the information we need in order to decide whether an operand requires brackets around it. file: PropLog.maude *** put brackets around the proposition if the precedence of *** its main operator is greater than the given integer op toStringPrec : Prop Int -> String .
  • 77. Printing with Minimal Brackets In the second case, brackets were needed because or has lower precedence than and. We’ll add an extra parameter that represents ‘the precedence of the operator above a term’. This gives us exactly the information we need in order to decide whether an operand requires brackets around it. file: PropLog.maude *** put brackets around the proposition if the precedence of *** its main operator is greater than the given integer op toStringPrec : Prop Int -> String .
  • 78. Printing with Minimal Brackets file: PropLog.maude *** no operator has precedence greater than 48, *** so no outermost brackets eq toString(P) = toStringPrec(P, 48) . var I : Int . eq toStringPrec(true, I) = "true" . eq toStringPrec(false, I) = "false" . eq toStringPrec(V, I) = string(V) .
  • 79. Printing with Minimal Brackets file: PropLog.maude *** no operator has precedence greater than 48, *** so no outermost brackets eq toString(P) = toStringPrec(P, 48) . var I : Int . eq toStringPrec(true, I) = "true" . eq toStringPrec(false, I) = "false" . eq toStringPrec(V, I) = string(V) .
  • 80. Printing with Minimal Brackets file: PropLog.maude *** no operator has precedence greater than 48, *** so no outermost brackets eq toString(P) = toStringPrec(P, 48) . var I : Int . eq toStringPrec(true, I) = "true" . eq toStringPrec(false, I) = "false" . eq toStringPrec(V, I) = string(V) .
  • 81. Printing with Minimal Brackets file: PropLog.maude *** no operator has precedence greater than 48, *** so no outermost brackets eq toString(P) = toStringPrec(P, 48) . var I : Int . eq toStringPrec(true, I) = "true" . eq toStringPrec(false, I) = "false" . eq toStringPrec(V, I) = string(V) .
  • 82. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 83. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 84. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 85. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 86. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 87. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 88. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 89. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 90. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 and P2, I) = toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) if I >= 40 . *** no brackets needed cq toStringPrec(P1 and P2, I) = "(" + toStringPrec(P1, 40) + " and " + toStringPrec(P2, 40) + ")" if I < 40 . *** brackets are needed so P1 and P2 will have brackets if needed similarly for or and not
  • 91. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 92. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 93. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 94. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 95. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 96. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 97. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 98. Printing with Minimal Brackets file: PropLog.maude cq toStringPrec(P1 implies P2, I) = toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) if I >= 48 . *** no brackets needed cq toStringPrec(P1 implies P2, I) = "(" + toStringPrec(P1, 47) + " implies " + toStringPrec(P2, 48) + ")" if I < 48 . *** brackets are needed This gives us right associativity: P1 will have brackets round it if its main operator is ‘implies’; P2 will not
  • 99. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 100. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 101. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 102. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 103. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 104. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 105. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 106. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 107. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 108. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 109. Maude Interpreter reduce toString((’a or ’b) and ’c) . = toStringPrec((’a or ’b) and ’c, 48) = *** 48 >= 40; no brackets needed toStringPrec(’a or ’b, 40) + " and " + toStringPrec(’c, 40) = *** 40 < 44; brackets are needed "(" + toStringPrec(’a, 44) + " or " + toStringPrec(’b, 44) + ")" + " and " + toStringPrec(’c, 40) = "(" + string(’a) + " or " + string(’b) + ")" + " and " + string(’c) = "(a or b) and c"
  • 110. Back to Java public class Prop { public Prop and(Prop p1, Prop p2) { ... } // similarly for ‘or’, etc. public String printAllBrackets() { ...} public String toString() { ...} } We need a data representation.
  • 111. Back to Java public class Prop { public Prop and(Prop p1, Prop p2) { ... } // similarly for ‘or’, etc. public String printAllBrackets() { ...} public String toString() { ...} } We need a data representation.
  • 112. Back to Java public class Prop { public Prop and(Prop p1, Prop p2) { ... } // similarly for ‘or’, etc. public String printAllBrackets() { ...} public String toString() { ...} } We need a data representation.
  • 113. That’s All, Folks! Summary sort Prop Maude equations helper functions Next: data representation