Question: Part B: Evaluate Prop Given a proposition p over atomic propositions P1, P2, Prn 9, and a truth value assigned to each atomic proposition, evaluate

 Part B: Evaluate Prop Given a proposition p over atomic propositions

P1, P2, Prn 9, and a truth value assigned to each atomic

Part B: Evaluate Prop Given a proposition p over atomic propositions P1, P2, Prn 9, and a truth value assigned to each atomic proposition, evaluate whether p is true or false under this assignment. The proposition will be given to you in the same form as Part A. Assume that the values of atomic propositions are given as a Python list of length n where each element is 0 or 1. For example if we have p = 0.p2 = 1.ps = 0 the corresponding list is: valuea - to, 1, 0] Your python function eval.prop should take 2 arguments prop, a proposition in the list representation, and values, values of atomic propositions. It should return for False and 1 for True (not the Boolean value itself) det eral_prop(prop. Teles): your code return Integer er 1, for True/Pala) Guidelines/Hints: Again, you will have to use recursion for this part. We have laid out the basic structure of the recursion in the skeleton code; it is up to you to fill in the details. As in Part A, if you have a solution that doesn't adhere to the structure we've placed down to help you start, you're free to delete any of that starting code. Just make sure you are returning either or 1 in the end. . The base case is similar to Part A, but you will now have to se standard logic ruless in Python to evaluate truth values. These include: and, or, etc. Python has these binary operators already built-in exactly as they are in English. Refer to this documentation for the full list: https://www.w3schools. con/python/python operators.asp . You will likely continue running into 'list index out of range. Always make sure you are index- ing into values correctly. You can do this by: (1) Checking that you are correctly taking the integer value from the proposition string (2) Making sure your values list is exactly the size you need to fit your proposition . You may index into any string like it is a list of characters. This will allow you to extract the position/index in the values list you want from each prop string def eval_prop(prop, values) : # BASE CASE: ##################################### if # fill in here #: # fill in here # atomic_prop_id = # ignore the first character of your proposition variable return # fill in here # ######################################## ######### # UNARY OPERATOR (not): ########################## elif 2 == len(prop): # the following two variable declarations are missing LHS # = prop[0] # missing LHS = prop[1] # missing LHS if "not" == op: return # fill in here # else: raise ValueError("Unary proposition is not not.") ################################################## # BINARY OPERATOR (and, or, if, iff, xor): ####### elif 3 == len(prop) : # the following three variable declarations are missing LHS # = prop[0] # missing LHS = prop[1] # missing LHS = prop[2] # missing LHS if op not in ("if", "iff", "or", "and", "xor"): raise ValueError("Binary proposition does not have valid connectives.") # evaluate left and right sides of a binary operation left = # fill in here # right = # fill in here # # the line here is an example, fill in the rest. if "and" == op: return int(left and right) elif # fill in : return # fill in here # elif # fill in : return # fill in here # elif # fill in : return # fill in here # else: # fill in : return # fill in here # # INVALID LENGTH ############ ##################### else: raise ValueError("Proposition incorrect length.") ####################### ###########################

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!