Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PropKB Ask. Added function to check validity. #2830

Merged
merged 3 commits into from
Jul 6, 2014

Conversation

sd-biswas
Copy link

  1. Added function to check for validity of propositional sentences
  2. Fixed bug where all queries on an empty KB would return False
  3. Fixed PropKB Ask function to correctly give the logical entailment
  4. Added Tests for the above

@srjoglekar246
Copy link
Member

Is there a reason I am unable to give line by line comments? @asmeurer

Anyways, some technical stuff-

  1. The format you have used for the Examples section is not quite correct. Do have a look at the way the heading is given in other docs and follow it strictly.

  2. Avoid writing long statements like the second return statement for the 'valid' function. Its better, and more in agreement with the rest of the codebase, to do it the indentation way.

  3. Follow PEP8 conventions for the tests and other places too. (Like A >> B instead of A>>B)

@asmeurer
Copy link
Member

I can't do it either. I think GitHub's javascript must be broken right now.

@sd-biswas
Copy link
Author

  1. I looked at satisfiable function docs for reference. Apparently even that is not in tune with the docs elsewhere. Will fix both.
  2. Will convert all the conditional expressions to standard if, else.
  3. My bad, will fix it immediately

s = set()
for q in query_conjuncts:
s = s.union(q.atoms(C.Symbol))
return bool(dpll(query_conjuncts, list(s), {}))
return True if dpll(query_conjuncts, list(s), {}) is False else False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to add an inline comment explaining why this is so. We don't want any confusion about the algorithms and logic behind our code, as is the case for most of the logic module as of now.

@srjoglekar246
Copy link
Member

You may want to bring your function into the sympy.logic namespace by entering it into the init file in sympy.logic folder.

Also, I think one of the tests in test_PropKB is failing. Please look into that and fix the issue.

@sd-biswas
Copy link
Author

  1. Fixed the coding convention issues
  2. Added valid function to the logic init file
  3. Fixed the failing test case (left over from old test cases) and deleted redundant test cases.

@srjoglekar246
Copy link
Member

This seems to be fine now. I am assuming you have tested all the test cases by hand and confirmed their validity.
I am +1.
@asmeurer unless you have something to add, I guess you could merge this.





Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, 2 newlines enough...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. @SDB1323 , have one newline between methods of a class, and two newlines between module-level functions/classes.

@sd-biswas
Copy link
Author

Travis seems to be giving the following error:
"No output has been received in the last 10 minutes, this potentially indicates a stalled build or something wrong with the build itself. The build has been terminated"

Could someone please indicate whether some action is required from my side, or it is normal to get this message and the PR will be merged?

@srjoglekar246
Copy link
Member

Ping @skirpichev

@moorepants
Copy link
Member

Travis is timing out a lot these days. I'm not sure what the major issue is.

@skirpichev
Copy link
Contributor

timeouts in test_gruntz.py/test_wester.py should be rare after merging #2851

@asmeurer
Copy link
Member

I haven't reviewed it, but if you are OK with the changes, then please merge.

@sd-biswas
Copy link
Author

Could this PR be merged? I need the valid function for a future PR. Travis passes all but one test, which times out.
Ping @skirpichev

@sd-biswas
Copy link
Author

I am really sorry. But all my ways to make Travis rebuild failed. And since most of the tests had timed out there was no way to know whether the build was correct or not. Hence the desperate attempt. I apologize.

@skirpichev
Copy link
Contributor

@SDB1323, can you rebase this pr to get rid of meaningless commits?
e.g. test commit, dummy commit, formatting fixes...

@@ -92,6 +93,30 @@ def satisfiable(expr, algorithm="dpll2"):
raise NotImplementedError


def valid(expr):
"""
Check validity of a propositional sentence.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does valid mean tautological? If so, I think that "tautological" is a better word to use here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess "valid" is more used in logic, though https://en.wikipedia.org/wiki/Valid. It should be made clear in the docstring what this means, though, in case someone isn't familiar with the logic terminology.

@asmeurer
Copy link
Member

I think Travis failed because of some old test failure from two months ago. Once you push commits addressing my comments, that should go away.

if isinstance(expr, bool):
return expr

if satisfiable(Not(expr)) is False:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return not satisfiable(Not(expr))

@asmeurer
Copy link
Member

My main concern here is the changed test cases for kb.ask. What does that function do? Can you explain why the previous test cases were wrong?

@asmeurer
Copy link
Member

This needs to be merged with master.

@sd-biswas
Copy link
Author

@asmeurer I have fixed the merge conflicts as well as added a couple of pending things. Please review.

.. [1] en.wikipedia.org/wiki/Validity

"""
if isinstance(expr, bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed.

@sd-biswas
Copy link
Author

@asmeurer : This seems to have passed the Travis build. Please review and merge if no further changes are required. The last commit should fix the {false: true} mapping problem, along with the python 2.6 compatibility fix.

@asmeurer
Copy link
Member

asmeurer commented Jul 1, 2014

Did you add a test for the {false: true} issue?

asmeurer added a commit that referenced this pull request Jul 6, 2014
Fixed PropKB Ask. Added function to check validity.
@asmeurer asmeurer merged commit 6aa63b5 into sympy:master Jul 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants