{"action":"created","comment":{"url":"https://api.github.com/repos/pysmt/pysmt/pulls/comments/26006897","id":26006897,"diff_hunk":"@@ -0,0 +1,217 @@\n+#\n+# This file is part of pySMT.\n+#\n+#   Copyright 2014 Andrea Micheli and Marco Gario\n+#\n+#   Licensed under the Apache License, Version 2.0 (the \"License\");\n+#   you may not use this file except in compliance with the License.\n+#   You may obtain a copy of the License at\n+#\n+#       http://www.apache.org/licenses/LICENSE-2.0\n+#\n+#   Unless required by applicable law or agreed to in writing, software\n+#   distributed under the License is distributed on an \"AS IS\" BASIS,\n+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+#   See the License for the specific language governing permissions and\n+#   limitations under the License.\n+#\n+import pysmt.shortcuts as shortcuts\n+from pysmt.walkers import DagWalker\n+from pysmt.typing import BOOL\n+\n+class CNFizer(DagWalker):\n+\n+    THEORY_PLACEHOLDER = \"__Placeholder__\"\n+\n+    TRUE_CNF = frozenset()\n+    FALSE_CNF = frozenset([frozenset()])\n+\n+    def __init__(self, environment=None):\n+        DagWalker.__init__(self)\n+        self.env = environment if environment else shortcuts.get_env()\n+        self.mgr = self.env.formula_manager\n+        self._introduced_variables = {}\n+        self._cnf_pieces = {}\n+\n+    def _key_var(self, formula):\n+        if formula in self._introduced_variables:\n+            res = self._introduced_variables[formula]\n+        else:\n+            res = self.mgr.FreshSymbol()\n+            self._introduced_variables[formula] = res\n+        return res\n+\n+    def convert(self, formula):\n+        tl, cnf = self.walk(formula)\n+        res = [frozenset([tl])]\n+        for clause in cnf:\n+            if len(clause) == 0:\n+                return CNFizer.FALSE_CNF\n+            simp = []\n+            for lit in clause:\n+                if lit.is_true():\n+                    simp = None\n+                    break\n+                elif not lit.is_false():\n+                    simp.append(lit)\n+            if simp:\n+                res.append(frozenset(simp))\n+        return frozenset(res)\n+\n+    def convert_as_formula(self, formula):\n+        lsts = self.convert(formula)\n+\n+        conj = []\n+        for clause in lsts:\n+            if len(clause) == 0:\n+                return self.mgr.FALSE()\n+            elif len(clause) == 1:\n+                conj.append(next(iter(clause)))\n+            else:\n+                conj.append(self.mgr.Or(clause))\n+\n+        if len(conj) == 0:\n+            return self.mgr.TRUE()\n+        elif len(conj) == 1:\n+            return conj[0]\n+        else:\n+            return self.mgr.And(conj)\n+\n+    def printer(self, cnf):\n+        print \"{\",\n+        for clause in cnf:\n+            print \" {\",\n+            for lit in clause:\n+                print \"\",lit,\n+            print \"}\",\n+        print \" }\"\n+\n+\n+    def walk_forall(self, formula, args):\n+        raise NotImplementedError(\"CNFizer does not support quantifiers\")\n+\n+    def walk_exists(self, formula, args):\n+        raise NotImplementedError(\"CNFizer does not support quantifiers\")\n+\n+    def walk_and(self, formula, args):\n+        if len(args) == 1:\n+            return args[0]\n+\n+        k = self._key_var(formula)\n+        cnf = [frozenset([k] + [self.mgr.Not(a).simplify() for a,_ in args])]\n+        for a,c in args:\n+            cnf.append(frozenset([a, self.mgr.Not(k)]))\n+            for clause in c:\n+                cnf.append(clause)\n+        return k, frozenset(cnf)\n+\n+    def walk_or(self, formula, args):\n+        if len(args) == 1:\n+            return args[0]\n+        k = self._key_var(formula)\n+        cnf = [frozenset([self.mgr.Not(k)] + [a for a,_ in args])]\n+        for a,c in args:\n+            cnf.append(frozenset([k, self.mgr.Not(a)]))\n+            for clause in c:\n+                cnf.append(clause)\n+        return k, frozenset(cnf)\n+\n+    def walk_not(self, formula, args):\n+        a, cnf = args[0]\n+        if a.is_true():\n+            return self.mgr.FALSE(), CNFizer.TRUE_CNF\n+        elif a.is_false():","path":"pysmt/cnf.py","position":137,"original_position":123,"commit_id":"1fb7b1256ce3eaab54a6c69bde9f1cc486e92c84","original_commit_id":"b63ea8be05ef0fd47dda8867a737e4102536e5c3","user":{"login":"mikand","id":2255972,"avatar_url":"https://avatars.githubusercontent.com/u/2255972?v=3","gravatar_id":"","url":"https://api.github.com/users/mikand","html_url":"https://github.com/mikand","followers_url":"https://api.github.com/users/mikand/followers","following_url":"https://api.github.com/users/mikand/following{/other_user}","gists_url":"https://api.github.com/users/mikand/gists{/gist_id}","starred_url":"https://api.github.com/users/mikand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikand/subscriptions","organizations_url":"https://api.github.com/users/mikand/orgs","repos_url":"https://api.github.com/users/mikand/repos","events_url":"https://api.github.com/users/mikand/events{/privacy}","received_events_url":"https://api.github.com/users/mikand/received_events","type":"User","site_admin":false},"body":"No, the contract of walk is the following: \r\nit returns a pair (v, cnf) such that the input formula is equivalent to v & cnf. v can be either a variable or a boolean constant and cnf is a set of clauses that are needed to explain v.\r\n\r\nIn this case I'm returning False, True that is logically false. The reason why I use TRUE_CNF instead of FALSE_CNF is that I need nothing to \"explain\" false. It would be incorrect to use FALSE_CNF. \r\n\r\nFor this reason, ","created_at":"2015-03-08T17:07:39Z","updated_at":"2015-03-08T17:07:39Z","html_url":"https://github.com/pysmt/pysmt/pull/31#discussion_r26006897","pull_request_url":"https://api.github.com/repos/pysmt/pysmt/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/pysmt/pysmt/pulls/comments/26006897"},"html":{"href":"https://github.com/pysmt/pysmt/pull/31#discussion_r26006897"},"pull_request":{"href":"https://api.github.com/repos/pysmt/pysmt/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/pysmt/pysmt/pulls/31","id":30649927,"html_url":"https://github.com/pysmt/pysmt/pull/31","diff_url":"https://github.com/pysmt/pysmt/pull/31.diff","patch_url":"https://github.com/pysmt/pysmt/pull/31.patch","issue_url":"https://api.github.com/repos/pysmt/pysmt/issues/31","number":31,"state":"open","locked":false,"title":"Picosat Integration","user":{"login":"mikand","id":2255972,"avatar_url":"https://avatars.githubusercontent.com/u/2255972?v=3","gravatar_id":"","url":"https://api.github.com/users/mikand","html_url":"https://github.com/mikand","followers_url":"https://api.github.com/users/mikand/followers","following_url":"https://api.github.com/users/mikand/following{/other_user}","gists_url":"https://api.github.com/users/mikand/gists{/gist_id}","starred_url":"https://api.github.com/users/mikand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikand/subscriptions","organizations_url":"https://api.github.com/users/mikand/orgs","repos_url":"https://api.github.com/users/mikand/repos","events_url":"https://api.github.com/users/mikand/events{/privacy}","received_events_url":"https://api.github.com/users/mikand/received_events","type":"User","site_admin":false},"body":"Added support for PicoSAT solver with dedicated wrapper\r\n","created_at":"2015-03-06T14:49:44Z","updated_at":"2015-03-08T17:07:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f75d309cc6acf9a752aa1e2cfb3b576b377261cf","assignee":{"login":"marcogario","id":1058447,"avatar_url":"https://avatars.githubusercontent.com/u/1058447?v=3","gravatar_id":"","url":"https://api.github.com/users/marcogario","html_url":"https://github.com/marcogario","followers_url":"https://api.github.com/users/marcogario/followers","following_url":"https://api.github.com/users/marcogario/following{/other_user}","gists_url":"https://api.github.com/users/marcogario/gists{/gist_id}","starred_url":"https://api.github.com/users/marcogario/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcogario/subscriptions","organizations_url":"https://api.github.com/users/marcogario/orgs","repos_url":"https://api.github.com/users/marcogario/repos","events_url":"https://api.github.com/users/marcogario/events{/privacy}","received_events_url":"https://api.github.com/users/marcogario/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/pysmt/pysmt/pulls/31/commits","review_comments_url":"https://api.github.com/repos/pysmt/pysmt/pulls/31/comments","review_comment_url":"https://api.github.com/repos/pysmt/pysmt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pysmt/pysmt/issues/31/comments","statuses_url":"https://api.github.com/repos/pysmt/pysmt/statuses/1fb7b1256ce3eaab54a6c69bde9f1cc486e92c84","head":{"label":"pysmt:picosat","ref":"picosat","sha":"1fb7b1256ce3eaab54a6c69bde9f1cc486e92c84","user":{"login":"pysmt","id":10014498,"avatar_url":"https://avatars.githubusercontent.com/u/10014498?v=3","gravatar_id":"","url":"https://api.github.com/users/pysmt","html_url":"https://github.com/pysmt","followers_url":"https://api.github.com/users/pysmt/followers","following_url":"https://api.github.com/users/pysmt/following{/other_user}","gists_url":"https://api.github.com/users/pysmt/gists{/gist_id}","starred_url":"https://api.github.com/users/pysmt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pysmt/subscriptions","organizations_url":"https://api.github.com/users/pysmt/orgs","repos_url":"https://api.github.com/users/pysmt/repos","events_url":"https://api.github.com/users/pysmt/events{/privacy}","received_events_url":"https://api.github.com/users/pysmt/received_events","type":"Organization","site_admin":false},"repo":{"id":27359780,"name":"pysmt","full_name":"pysmt/pysmt","owner":{"login":"pysmt","id":10014498,"avatar_url":"https://avatars.githubusercontent.com/u/10014498?v=3","gravatar_id":"","url":"https://api.github.com/users/pysmt","html_url":"https://github.com/pysmt","followers_url":"https://api.github.com/users/pysmt/followers","following_url":"https://api.github.com/users/pysmt/following{/other_user}","gists_url":"https://api.github.com/users/pysmt/gists{/gist_id}","starred_url":"https://api.github.com/users/pysmt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pysmt/subscriptions","organizations_url":"https://api.github.com/users/pysmt/orgs","repos_url":"https://api.github.com/users/pysmt/repos","events_url":"https://api.github.com/users/pysmt/events{/privacy}","received_events_url":"https://api.github.com/users/pysmt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pysmt/pysmt","description":"pySMT: A library for SMT formulae manipulation and solving","fork":false,"url":"https://api.github.com/repos/pysmt/pysmt","forks_url":"https://api.github.com/repos/pysmt/pysmt/forks","keys_url":"https://api.github.com/repos/pysmt/pysmt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pysmt/pysmt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pysmt/pysmt/teams","hooks_url":"https://api.github.com/repos/pysmt/pysmt/hooks","issue_events_url":"https://api.github.com/repos/pysmt/pysmt/issues/events{/number}","events_url":"https://api.github.com/repos/pysmt/pysmt/events","assignees_url":"https://api.github.com/repos/pysmt/pysmt/assignees{/user}","branches_url":"https://api.github.com/repos/pysmt/pysmt/branches{/branch}","tags_url":"https://api.github.com/repos/pysmt/pysmt/tags","blobs_url":"https://api.github.com/repos/pysmt/pysmt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pysmt/pysmt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pysmt/pysmt/git/refs{/sha}","trees_url":"https://api.github.com/repos/pysmt/pysmt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pysmt/pysmt/statuses/{sha}","languages_url":"https://api.github.com/repos/pysmt/pysmt/languages","stargazers_url":"https://api.github.com/repos/pysmt/pysmt/stargazers","contributors_url":"https://api.github.com/repos/pysmt/pysmt/contributors","subscribers_url":"https://api.github.com/repos/pysmt/pysmt/subscribers","subscription_url":"https://api.github.com/repos/pysmt/pysmt/subscription","commits_url":"https://api.github.com/repos/pysmt/pysmt/commits{/sha}","git_commits_url":"https://api.github.com/repos/pysmt/pysmt/git/commits{/sha}","comments_url":"https://api.github.com/repos/pysmt/pysmt/comments{/number}","issue_comment_url":"https://api.github.com/repos/pysmt/pysmt/issues/comments{/number}","contents_url":"https://api.github.com/repos/pysmt/pysmt/contents/{+path}","compare_url":"https://api.github.com/repos/pysmt/pysmt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pysmt/pysmt/merges","archive_url":"https://api.github.com/repos/pysmt/pysmt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pysmt/pysmt/downloads","issues_url":"https://api.github.com/repos/pysmt/pysmt/issues{/number}","pulls_url":"https://api.github.com/repos/pysmt/pysmt/pulls{/number}","milestones_url":"https://api.github.com/repos/pysmt/pysmt/milestones{/number}","notifications_url":"https://api.github.com/repos/pysmt/pysmt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pysmt/pysmt/labels{/name}","releases_url":"https://api.github.com/repos/pysmt/pysmt/releases{/id}","created_at":"2014-12-01T02:52:26Z","updated_at":"2015-03-08T17:01:17Z","pushed_at":"2015-03-08T17:01:17Z","git_url":"git://github.com/pysmt/pysmt.git","ssh_url":"git@github.com:pysmt/pysmt.git","clone_url":"https://github.com/pysmt/pysmt.git","svn_url":"https://github.com/pysmt/pysmt","homepage":"http://www.pysmt.org","size":1569,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":6,"default_branch":"master"}},"base":{"label":"pysmt:master","ref":"master","sha":"de87075c8396525d6a0b280c2521e2df2fe38bf8","user":{"login":"pysmt","id":10014498,"avatar_url":"https://avatars.githubusercontent.com/u/10014498?v=3","gravatar_id":"","url":"https://api.github.com/users/pysmt","html_url":"https://github.com/pysmt","followers_url":"https://api.github.com/users/pysmt/followers","following_url":"https://api.github.com/users/pysmt/following{/other_user}","gists_url":"https://api.github.com/users/pysmt/gists{/gist_id}","starred_url":"https://api.github.com/users/pysmt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pysmt/subscriptions","organizations_url":"https://api.github.com/users/pysmt/orgs","repos_url":"https://api.github.com/users/pysmt/repos","events_url":"https://api.github.com/users/pysmt/events{/privacy}","received_events_url":"https://api.github.com/users/pysmt/received_events","type":"Organization","site_admin":false},"repo":{"id":27359780,"name":"pysmt","full_name":"pysmt/pysmt","owner":{"login":"pysmt","id":10014498,"avatar_url":"https://avatars.githubusercontent.com/u/10014498?v=3","gravatar_id":"","url":"https://api.github.com/users/pysmt","html_url":"https://github.com/pysmt","followers_url":"https://api.github.com/users/pysmt/followers","following_url":"https://api.github.com/users/pysmt/following{/other_user}","gists_url":"https://api.github.com/users/pysmt/gists{/gist_id}","starred_url":"https://api.github.com/users/pysmt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pysmt/subscriptions","organizations_url":"https://api.github.com/users/pysmt/orgs","repos_url":"https://api.github.com/users/pysmt/repos","events_url":"https://api.github.com/users/pysmt/events{/privacy}","received_events_url":"https://api.github.com/users/pysmt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pysmt/pysmt","description":"pySMT: A library for SMT formulae manipulation and solving","fork":false,"url":"https://api.github.com/repos/pysmt/pysmt","forks_url":"https://api.github.com/repos/pysmt/pysmt/forks","keys_url":"https://api.github.com/repos/pysmt/pysmt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pysmt/pysmt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pysmt/pysmt/teams","hooks_url":"https://api.github.com/repos/pysmt/pysmt/hooks","issue_events_url":"https://api.github.com/repos/pysmt/pysmt/issues/events{/number}","events_url":"https://api.github.com/repos/pysmt/pysmt/events","assignees_url":"https://api.github.com/repos/pysmt/pysmt/assignees{/user}","branches_url":"https://api.github.com/repos/pysmt/pysmt/branches{/branch}","tags_url":"https://api.github.com/repos/pysmt/pysmt/tags","blobs_url":"https://api.github.com/repos/pysmt/pysmt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pysmt/pysmt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pysmt/pysmt/git/refs{/sha}","trees_url":"https://api.github.com/repos/pysmt/pysmt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pysmt/pysmt/statuses/{sha}","languages_url":"https://api.github.com/repos/pysmt/pysmt/languages","stargazers_url":"https://api.github.com/repos/pysmt/pysmt/stargazers","contributors_url":"https://api.github.com/repos/pysmt/pysmt/contributors","subscribers_url":"https://api.github.com/repos/pysmt/pysmt/subscribers","subscription_url":"https://api.github.com/repos/pysmt/pysmt/subscription","commits_url":"https://api.github.com/repos/pysmt/pysmt/commits{/sha}","git_commits_url":"https://api.github.com/repos/pysmt/pysmt/git/commits{/sha}","comments_url":"https://api.github.com/repos/pysmt/pysmt/comments{/number}","issue_comment_url":"https://api.github.com/repos/pysmt/pysmt/issues/comments{/number}","contents_url":"https://api.github.com/repos/pysmt/pysmt/contents/{+path}","compare_url":"https://api.github.com/repos/pysmt/pysmt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pysmt/pysmt/merges","archive_url":"https://api.github.com/repos/pysmt/pysmt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pysmt/pysmt/downloads","issues_url":"https://api.github.com/repos/pysmt/pysmt/issues{/number}","pulls_url":"https://api.github.com/repos/pysmt/pysmt/pulls{/number}","milestones_url":"https://api.github.com/repos/pysmt/pysmt/milestones{/number}","notifications_url":"https://api.github.com/repos/pysmt/pysmt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pysmt/pysmt/labels{/name}","releases_url":"https://api.github.com/repos/pysmt/pysmt/releases{/id}","created_at":"2014-12-01T02:52:26Z","updated_at":"2015-03-08T17:01:17Z","pushed_at":"2015-03-08T17:01:17Z","git_url":"git://github.com/pysmt/pysmt.git","ssh_url":"git@github.com:pysmt/pysmt.git","clone_url":"https://github.com/pysmt/pysmt.git","svn_url":"https://github.com/pysmt/pysmt","homepage":"http://www.pysmt.org","size":1569,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pysmt/pysmt/pulls/31"},"html":{"href":"https://github.com/pysmt/pysmt/pull/31"},"issue":{"href":"https://api.github.com/repos/pysmt/pysmt/issues/31"},"comments":{"href":"https://api.github.com/repos/pysmt/pysmt/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/pysmt/pysmt/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/pysmt/pysmt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pysmt/pysmt/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/pysmt/pysmt/statuses/1fb7b1256ce3eaab54a6c69bde9f1cc486e92c84"}}}}