-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
First Order Logic #7608
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
base: master
Are you sure you want to change the base?
First Order Logic #7608
Conversation
sd-biswas
commented
Jun 18, 2014
- Make sure tests pass
- Use Symbol everywhere, not strings (or Constant or Variable or whatever)
- Add docstring with doctest to every class and function (including and especially abstract classes, although the abstract classes do not need to have doctests if that does not make sense). Major methods of classes should have this as well.
- Address First Order Logic #7608 (comment)
- Address First Order Logic #7608 (comment)
- Use a single to_cnf and to_dnf and use dispatching to distinguish the two.
- Change name for Functions.
- Improve FOL_KB to handle multiple recursive clauses.
- Implement Answer Extraction with the new ask.
- Add description to Exceptions
- Fix error in rst doc and add KB to it
self._func = func | ||
self._args = tuple(args) | ||
|
||
def _sympystr(self, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second argument should be the printer, I think. You should use it to recursively print the arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the printers here are purely for my personal convenience at this moment. All of the printer code will go into the respective file soon.
I think you'll need to override |
>>> from sympy.logic.FOL import Predicate | ||
>>> Knows = Predicate('Knows') | ||
>>> Knows('John', 'Jack') | ||
Knows(John, Jack) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are 'John'
and 'Jack'
implicitly converted to Symbol('John')
and Symbol('Jack')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The are intended to be constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that SymPy objects don't really play with with non-SymPy objects such as strings as part of their expression tree. In this case, I would just only use Symbol everywhere, since that is the standard way to have a 'name' in SymPy.
I think it would be cleaner to just use symbols in place of strings. Most actual usage will be with symbols, I think. It's just a matter of using |
self._name = name | ||
|
||
def __call__(self, *args): | ||
return self.apply()(self, *args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be some apply
on this class, even if it just raises NotImplementedError.
The class structure here is still a little confusing to me. Can you add a docstring to each class that just explains what it is for, especially the abstract base classes. It also should be made clear for each class if it is designed to be used on its own or if it is only a designed to be subclassed. |
I don't think it's a good idea to have multiple to_cnf functions. I would just have the one function, and use dispatching to have it do the right thing on different kinds of objects (i.e., have |
return expr.func(*args) | ||
|
||
|
||
def standardize(expr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably add a keyword argument to pass in a custom iterator of symbols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the symbols
argument to cse()
.
I am going to put a checklist at the top of the pull request, so that we can keep track of what needs to be done. |
raise ValueError("Use a constant instead of %s()" % func) | ||
args = [arg if isinstance(arg, (Boolean, Symbol)) | ||
else Constant(arg) for arg in args] | ||
self._func = func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this at all related to self.func
(which will be the class, Applied
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with using a property is that it leads to confusion to people reading the code from here, as you can see from this comment of mine.
I was hoping for more than just "abstract base class" in the docstrings of the abstract base classes. For someone coming to this module for the first time, it can be quite unclear what all the abstract classes are supposed to represent. It would be helpful to give a higher level idea of why they are there. |
I think the Python 3 test failures are coming from using strings instead of SymPy objects in the doctests. |
|
Good. I like this better. CNF and DNF should be only about propositional logic, and should treat quantifiers basic terms. |
Is there any progress with this? Thanks. |
I'm also interested in this, it appears to be halted now. Is there currently any plans for first-order logic in the future? |
@naiveaiguy Please speak to the maintainers. I have been away for a very long time and don't know the current state of things here. If there is still interest in having FOL then I can help you with modifying and/or rewriting this code. |
Mechanistic port of sympy/sympy#7608 for Diofant by @skirpichev.
Mechanistic port of sympy/sympy#7608 for Diofant by @skirpichev.
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage.
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage.
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage.
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage.
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage.
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage.
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage.
This should be there in SymPy. |
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com> - FOL class
Mechanistic port of sympy/sympy#7608 for Diofant // edited by @skirpichev 100% test coverage. XXX cleanup FOL.py XXX cleanup test_FOL.py XXX adapt code Function -> UndefinedBooleanFunction AppliedFunction -> AppliedUndefinedBooleanFunction Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com> - FOL class