Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python finish the truthtable implementation use extract_variables method to complete # NOTE: # You must use small single letters for your variable names, for eg.

Python finish the truthtable implementation

use extract_variables method to complete

# NOTE: # You must use small single letters for your variable names, for eg. a, b, c # You may use parenthesis to group your expressions such as 'a and (b or c)'

# Implement the following four functions: # truth_table, count_satisfying, is_tautology and are_equivalent

# Submission: # Submit this file using the checkin system on the course web page.

######## Do not modify the following block of code ######## # ********************** BEGIN *******************************

from functools import partial import re

class Infix(object): def __init__(self, func): self.func = func def __or__(self, other): return self.func(other) def __ror__(self, other): return Infix(partial(self.func, other)) def __call__(self, v1, v2): return self.func(v1, v2)

@Infix def implies(p, q) : return not p or q

@Infix def iff(p, q) : return (p |implies| q) and (q |implies| p)

# You must use this function to extract variables # This function takes an expression as input and returns a sorted list of variables # Do NOT modify this function def extract_variables(expression): sorted_variable_set = sorted(set(re.findall(r'\b[a-z]\b', expression))) return sorted_variable_set

# *********************** END ***************************

############## IMPLEMENT THE FOLLOWING FUNCTIONS ############## ############## Do not modify function definitions ##############

# This function calculates a truth table for a given expression # input: expression # output: truth table as a list of lists # You must use extract_variables function to generate the list of variables from expression # return a list of lists for this function def truth_table(expression):

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

What are the advantages and disadvantages of entrepreneurship?

Answered: 1 week ago

Question

what is the most common cause of preterm birth in twin pregnancies?

Answered: 1 week ago

Question

Which diagnostic test is most commonly used to confirm PROM?

Answered: 1 week ago

Question

What is the hallmark clinical feature of a molar pregnancy?

Answered: 1 week ago