Free Variables in First-Order Logic: A well-formed formula (wff) in first-order logic is defined as follows: An atomic formula, p(a1,...,an), is a wff, where p is a predicate symbol (ID token) and a1,...,an (n > 0) are arguments that can be numbers (NUMBER token), or strings enclosed within single quotation marks (STRING token), or variables (ID token). We shall assume that the ID token begins with a lower-case letter and is followed zero or more letters or digits. Even though the variables are made up of lower and upper-case letters, these should be considered case-insensitive. For example, value1, vALUE1, vAlue1, etc all should be treated as the same variable. For simplicity, we may assume that the STRING tokens are made up of letters and digits. If F1 and F2 are wffs, then F1 and F2, F1 or F2, and not F1 are wffs. (Note that we do not enforce parentheses!) If F is a wff and x1,...,xn are variables (n > 0), then (exists x1,...,xn)(F), (forall x1,...,xn)(F), and (F) are wffs. (Note that here we enforce parentheses!) Since we do not enforce parentheses while using "and", "or", and "not", we will assume that "and" and "or" have lower precedence compared to "not". So, in a formula such as:A and B or not C and D the "not" will be applied to C and then the "and"s and "or"s will be applied with left associativity. Some examples of wffs are:employee('John','B','Smith',t,u,v,w,x,y,z) projects(h,20,'Stafford',k) (exists t,w,x,y,z)( employee('John','B','Smith',t,u,v,w,x,y,z) ) (exists r,t,u,v,w,x,y,z)( employee(q,r,s,t,u,v,w,x,y,z) and not ((exists m,n,o,p)(dependent(t,m,n,o,p)) ) ) Recall the definition of "free variables" in wffs from your Discrete Math (CSC 2510/MATH 2420) class. Write a CFG for wffs as defined above. Make sure to enforce precedence rules and left associativity on the logical operators. Then, using PLY define the tokens in WFFLexer.py and the parser specfication in WFFParser.py. Using p[0] assignment statements construct an expression tree data structure similar to homework 1. Then, in the main program write a function, free_variables(tree), that computes the list of free variables in the expression denoted by tree. A sample run is shown below: Mac-mini:wff raj$ python3 WFF.py WFF: p(x,20,'aa'); OPEN WFF with Free Variables: ['X'] WFF: (exists x,y)(p(x,u) and not q(y,v)); OPEN WFF with Free Variables: ['U', 'V'] WFF: (exists x,y)(p(x,y)); CLOSED WFF WFF: employee('John','B','Smith',t,u,v,w,x,y,z); OPEN WFF with Free Variables: ['T', 'U', 'V', 'W', 'X', 'Y', 'Z'] WFF: projects(h,20,'Stafford',k); OPEN WFF with Free Variables: ['H', 'K'] WFF: (exists t,w,x,y,z)( employee('John','B','Smith',t,u,v,w,x,y,z) ); OPEN WFF with Free Variables: ['U', 'V'] WFF: (exists r,t,u,v,w,x,y,z)( employee(q,r,s,t,u,v,w,x,y,z) and not ((exists m,n,o,p)(dependent(t,m,n,o,p)) ) ); OPEN WFF with Free Variables: ['Q', 'S'] WFF: exit;

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

Free Variables in First-Order Logic: A well-formed formula (wff) in first-order logic is defined as follows:

  • An atomic formula, p(a1,...,an), is a wff, where p is a predicate symbol (ID token) and a1,...,an (n > 0) are arguments that can be numbers (NUMBER token), or strings enclosed within single quotation marks (STRING token), or variables (ID token). We shall assume that the ID token begins with a lower-case letter and is followed zero or more letters or digits. Even though the variables are made up of lower and upper-case letters, these should be considered case-insensitive. For example, value1, vALUE1, vAlue1, etc all should be treated as the same variable. For simplicity, we may assume that the STRING tokens are made up of letters and digits.
  • If F1 and F2 are wffs, then F1 and F2F1 or F2, and not F1 are wffs. (Note that we do not enforce parentheses!)
  • If F is a wff and x1,...,xn are variables (n > 0), then (exists x1,...,xn)(F)(forall x1,...,xn)(F), and (F) are wffs. (Note that here we enforce parentheses!)

Since we do not enforce parentheses while using "and", "or", and "not", we will assume that "and" and "or" have lower precedence compared to "not". So, in a formula such as:A and B or not C and D the "not" will be applied to C and then the "and"s and "or"s will be applied with left associativity. Some examples of wffs are:employee('John','B','Smith',t,u,v,w,x,y,z) projects(h,20,'Stafford',k) (exists t,w,x,y,z)( employee('John','B','Smith',t,u,v,w,x,y,z) ) (exists r,t,u,v,w,x,y,z)( employee(q,r,s,t,u,v,w,x,y,z) and not ((exists m,n,o,p)(dependent(t,m,n,o,p)) ) )

Recall the definition of "free variables" in wffs from your Discrete Math (CSC 2510/MATH 2420) class.

Write a CFG for wffs as defined above. Make sure to enforce precedence rules and left associativity on the logical operators. Then, using PLY define the tokens in WFFLexer.py and the parser specfication in WFFParser.py. Using p[0] assignment statements construct an expression tree data structure similar to homework 1. Then, in the main program write a function, free_variables(tree), that computes the list of free variables in the expression denoted by tree. A sample run is shown below:

Mac-mini:wff raj$ python3 WFF.py WFF: p(x,20,'aa'); OPEN WFF with Free Variables: ['X'] WFF: (exists x,y)(p(x,u) and not q(y,v)); OPEN WFF with Free Variables: ['U', 'V'] WFF: (exists x,y)(p(x,y)); CLOSED WFF WFF: employee('John','B','Smith',t,u,v,w,x,y,z); OPEN WFF with Free Variables: ['T', 'U', 'V', 'W', 'X', 'Y', 'Z'] WFF: projects(h,20,'Stafford',k); OPEN WFF with Free Variables: ['H', 'K'] WFF: (exists t,w,x,y,z)( employee('John','B','Smith',t,u,v,w,x,y,z) ); OPEN WFF with Free Variables: ['U', 'V'] WFF: (exists r,t,u,v,w,x,y,z)( employee(q,r,s,t,u,v,w,x,y,z) and not ((exists m,n,o,p)(dependent(t,m,n,o,p)) ) ); OPEN WFF with Free Variables: ['Q', 'S'] WFF: exit;

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Inference
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT