Question

Check is 2-CNF satisfiable? Return one of its satisfying assignments.

The input is a Boolean formula in 2-CNF, given as a string of symbols.


Example: p /\ (p -> q) /\ (p -> ~r) /\ (~r \/ ~s) /\ (s \/ ~q)

1) check whether the given 2-CNF is satisfiable.

2) given a 2-CNF, report that it is not satisfiable or return one of its satisfying assignments.

Solution in Python3

For the first task, you should implement a function called is_satisfiable, which takes the string with the 2-CNF as an argument and returns either True (satisfiable) or False (not satisfiable). The second task should be implemented as a function called sat_assignment. This function also takes one argument (string) and returns an associative array (dictionary) with the satifying assignment (e.g., { 'p': True, 'q': False, 'r': True }) or None, if the 2-CNF is not satisfiable.

Warning: the automatic tests run several iterations of your functions, with different CNFs. If you use global variables, please make sure that their values from previous iterations do not make the next one work incorrectly.


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Check is 2-CNF satisfiable? Return one of its satisfying assignments.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 10 points (bonus) A propositional formula on n variables, P(ri,2,... ,Tn) is satisfiable if there exists...

    10 points (bonus) A propositional formula on n variables, P(ri,2,... ,Tn) is satisfiable if there exists an assignment of truth values (true or false) to its variables such that it evaluates to true. (a) Give an algorithm (pseudocode) that, given a formula P determines if it is satisfiable or not. Analyze your algorithm. b) Suppose that we are given a free" algorithm A that, given P and a partial assignment of truth values (that is, some variables are set to...

  • Make a function dict build(keys, values) which takes as argument two lists, one containing keys, one...

    Make a function dict build(keys, values) which takes as argument two lists, one containing keys, one values to be put into a dictionary (in order). If the lists are of the same length put them into a dictionary form, and return the dictionary from the function. Otherwise return the keyword None from the function. For example: Test print(di ct_build(['a', 'b' , 'c'], [1,2,3])={ 'a': 1, 'b': 2, 'c': 3 r example: Result ildCC'a', 'b', 'c'], [1,2,3])-= { 'a': 1, 'b':...

  • Vliestion (1) while make testman I will generate an executable called Testman IX to test your...

    Vliestion (1) while make testman I will generate an executable called Testman IX to test your program for Question (2). If you just issue make, then both will be generated. (1) In this question, you will re-implement the question in Assignment 1 by using vectors instead dynamic arrays. All the functionalities are the same. Of course, you need to make appropriate changes to the function declarations by using vectors instead of pointers to strings or string arrays). See below. Also...

  • Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String a...

    Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String argument. The method will return a new String by removing the logest segment that contains consequtively repeating characters. public static void main(String []args){ String s=”1111222223333311111111444455552222”; String res= removeLongestRepeatingSegment(s); will return “11112222233333444455552222” } public static String removeLongestRepeatingSegment(String s){ --------------- Q2)15p)Given a list of objects stored (in ascending order) in a sorted linked list, implement member method which performs search as efficiently as possible for an object based on a key....

  • Assignment 1 Year 2 ICTEDU term 1 2019 For question 1 and 2 the report should...

    Assignment 1 Year 2 ICTEDU term 1 2019 For question 1 and 2 the report should consist the following sections on each task: Task Description: Pseudo code / Algorithm: Testing: implementation (working program) screenshots NOTE: Question 1 and 2 Attach a well commented C source file of the program in a zipped file QUESTION 1-Simple C functions 1. Write a short C function that takes an integer (year) and checks whether the year is a Leap Year or not. If...

  • Python Programming Task 2: Leap Years   Part A - Is this a leap year? Write a...

    Python Programming Task 2: Leap Years   Part A - Is this a leap year? Write a function is leap year(year) that calculates whether a given (CE) year is a leap year. The function must: • take one argument: a positive integer representing a year (assumed to be CE) • return True if that year was a leap year; return False if not NOTE: all years that are divisible by four are leap years, unless they are also divisible by 100,...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • Make a public class called ManyExamples and in the class... Write a function named isEven which...

    Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...

  • ----JAVA IMPLEMENTATION URGENTLY NEEDED ------ //Ques 3 /** * Computes the standard Rayleigh distribution probability density...

    ----JAVA IMPLEMENTATION URGENTLY NEEDED ------ //Ques 3 /** * Computes the standard Rayleigh distribution probability density function (The mathematical function describing the standard Rayleigh distribution is given by: y = [ x / (σ)^2 ] * e ^ [ (-x^2) / (2σ^2) ] where σ =sigma is the scale variable of Rayleigh distribution. The function y is called the probability density function of the standard Rayleigh distribution. Complete the method rayleigh(double x, int sigma) that returns the value of y...

  • python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a...

    python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT