Skip to content

Conversation

@konstantintogoi
Copy link
Contributor

@konstantintogoi konstantintogoi commented Dec 7, 2017

  • logic
    • Added a new normal form - ANFform. Function ANFform converts a list of truth values to an expression in Algebraic Normal Form (ANF).
    • Added a new method BooleanFunction.to_anf that converts an expression to ANF by equivalent transformations.
    • Added a new function is_anf that checks if an expression is ANF.
    • Added a new function to_anf that converts an expression to ANF if it is not ANF.
    • Added a new function distribute_xor_over_and. Given a sentence s consisting of conjunction and exclusive disjunctions of literals, it returns an equivalent exclusive disjunction.
    • Added a new function bool_minterm that returns the k-th minterm of a fixed ordered set of binary variables.
    • Added a new function bool_maxterm that returns the k-th maxterm of a fixed ordered set of binary variables.
    • Added a new function bool_monomial that returns the k-th monomial of a fixed ordered set of binary variables.

Copy link
Contributor

@gxyd gxyd left a comment

Choose a reason for hiding this comment

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

I haven't duplicated comments to similar requested changes, but please make those. Ex, use https:// prefix for links but I have made this comment only in one place.

@gxyd
Copy link
Contributor

gxyd commented Dec 7, 2017 via email

@gxyd
Copy link
Contributor

gxyd commented Dec 28, 2017

I think you have mistakenly changed the mode of sympy/logic/boolalg.py from 100644 -> 100755. Please remove that.

@gxyd
Copy link
Contributor

gxyd commented Dec 28, 2017

Also for the test file, seems like you made it executable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Test case for this is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was refactored as

def to_anf(self, deep=True):
    args = range(1, len(self.args) + 1)
    args = (combinations(self.args, j) for j in args)
    args = chain.from_iterable(args)  # powerset
    args = (And(*arg) for arg in args)
    args = map(lambda x: to_anf(x, deep=deep) if deep else x, args)
    return Xor(*list(args), remove_true=False)

And covered with tests

assert to_anf(Or(x, y)) == Xor(x, y, And(x, y))
assert to_anf(Or(Implies(x, y), And(x, y), y)) == \
        Xor(x, True, x & y, remove_true=False)
assert to_anf(Or(Nand(x, y), Nor(x, y), Xnor(x, y), Implies(x, y))) == True
assert to_anf(Or(x, Not(y), Nor(x,z), And(x, y), Nand(y, z))) == \
        Xor(True, And(y, z), And(x, y, z), remove_true=False)

Copy link
Contributor

Choose a reason for hiding this comment

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

for this as well is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was refactored as

def to_anf(self, deep=True):
    args = range(1, len(self.args) + 1)
    args = (combinations(self.args, j) for j in args)
    args = chain.from_iterable(args)  # powerset
    args = (And(*arg) for arg in args)
    args = map(lambda x: to_anf(x, deep=deep) if deep else x, args)
    return Xor(*list(args), remove_true=False)

And covered with tests

assert to_anf(Or(x, y)) == Xor(x, y, And(x, y))
assert to_anf(Or(Implies(x, y), And(x, y), y)) == \
        Xor(x, True, x & y, remove_true=False)
assert to_anf(Or(Nand(x, y), Nor(x, y), Xnor(x, y), Implies(x, y))) == True
assert to_anf(Or(x, Not(y), Nor(x,z), And(x, y), Nand(y, z))) == \
        Xor(True, And(y, z), And(x, y, z), remove_true=False)

@gxyd gxyd added the PR: author's turn The PR has been reviewed and the author needs to submit more changes. label Jan 21, 2018
@Abdullahjavednesar Abdullahjavednesar added PR: sympy's turn and removed PR: author's turn The PR has been reviewed and the author needs to submit more changes. labels Apr 17, 2018
@czgdp1807
Copy link
Member

@asmeurer Please provide updates on this PR?

@czgdp1807
Copy link
Member

@konstantintogoi Please resolve conflicts in this PR, if you are still interested to work on this.

Added new features for converting boolean expression to
Algebraic Normal Form.

New functions:
- to_anf
- is_anf
- distribute_xor_over_and
- _convert_to_varsANF
- anf_coeffs
- ANFform
- minterm
- maxterm
- monomial

New instance method 'to_anf' and new class method '_to_anf'
@sympy-bot
Copy link

sympy-bot commented Feb 5, 2020

Hi, I am the SymPy bot (v150). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • logic
    • Added a new normal form - ANFform. Function ANFform converts a list of truth values to an expression in Algebraic Normal Form (ANF). (#13686 by @KonstantinTogoi)

    • Added a new method BooleanFunction.to_anf that converts an expression to ANF by equivalent transformations. (#13686 by @KonstantinTogoi)

    • Added a new function is_anf that checks if an expression is ANF. (#13686 by @KonstantinTogoi)

    • Added a new function to_anf that converts an expression to ANF if it is not ANF. (#13686 by @KonstantinTogoi)

    • Added a new function distribute_xor_over_and. Given a sentence s consisting of conjunction and exclusive disjunctions of literals, it returns an equivalent exclusive disjunction. (#13686 by @KonstantinTogoi)

    • Added a new function bool_minterm that returns the k-th minterm of a fixed ordered set of binary variables. (#13686 by @KonstantinTogoi)

    • Added a new function bool_maxterm that returns the k-th maxterm of a fixed ordered set of binary variables. (#13686 by @KonstantinTogoi)

    • Added a new function bool_monomial that returns the k-th monomial of a fixed ordered set of binary variables. (#13686 by @KonstantinTogoi)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- BEGIN RELEASE NOTES -->
* logic
  * Added a new normal form - `ANFform`. Function `ANFform` converts a list of truth values to an expression in Algebraic Normal Form (ANF).
  * Added a new method `BooleanFunction.to_anf` that converts an expression to ANF by equivalent transformations.
  * Added a new function `is_anf` that checks if an expression is ANF.
  * Added a new function `to_anf` that converts an expression to ANF if it is not ANF.
  * Added a new function `distribute_xor_over_and`. Given a sentence `s` consisting of conjunction and exclusive disjunctions of literals, it returns an equivalent exclusive disjunction.
  * Added a new function `bool_minterm` that returns the k-th minterm of a fixed ordered set of binary variables.
  * Added a new function `bool_maxterm` that returns the k-th maxterm of a fixed ordered set of binary variables.
  * Added a new function `bool_monomial` that returns the k-th monomial of a fixed ordered set of binary variables.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov
Copy link

codecov bot commented Feb 5, 2020

Codecov Report

Merging #13686 into master will increase coverage by 0.052%.
The diff coverage is 91.15%.

@@              Coverage Diff              @@
##            master    #13686       +/-   ##
=============================================
+ Coverage   75.545%   75.598%   +0.052%     
=============================================
  Files          642       644        +2     
  Lines       167277    167812      +535     
  Branches     39441     39561      +120     
=============================================
+ Hits        126371    126864      +493     
- Misses       35382     35409       +27     
- Partials      5524      5539       +15

@konstantintogoi
Copy link
Contributor Author

I think you have mistakenly changed the mode of sympy/logic/boolalg.py from 100644 -> 100755. Please remove that.

Fixed.

@konstantintogoi
Copy link
Contributor Author

Also for the test file, seems like you made it executable.

Fixed.

@konstantintogoi
Copy link
Contributor Author

@konstantintogoi Please resolve conflicts in this PR, if you are still interested to work on this.

Done.

return _convert_to_varsPOS(k, variables)


def monomial(k, variables):
Copy link
Member

Choose a reason for hiding this comment

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

monomial can be too much a common word that can be used by other disciplines.
https://en.wikipedia.org/wiki/Monomial
So I would have a suggestion to name this more specific. like prefixing bool_monimial, bool_minterm, bool_maxterm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've renamed the functions

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.

8 participants