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

Make count_ops() work with logic operations by creating a binary tree. #7303

Merged
merged 26 commits into from Apr 12, 2014
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cefd428
Make count_ops() work with logic operations by creating a binary tree…
sahilshekhawat Mar 19, 2014
5389065
Added tests of the logic functions for count_ops() function.
sahilshekhawat Mar 19, 2014
7000d9e
Fixed a test case of Xor(x,y) = 2*AND + OR
sahilshekhawat Mar 19, 2014
3c5ba38
Fixed the test case for Nand(x,y).count_ops(visual=True) = OR and Nor…
sahilshekhawat Mar 19, 2014
07168de
Removed the obsolete test case which was addressing the bug.
sahilshekhawat Mar 19, 2014
25a9686
Included the case of logic function in the "else" case.
sahilshekhawat Mar 19, 2014
d5abbd7
removed the XXX comment to report bug.
sahilshekhawat Mar 19, 2014
366f864
Removed the case for logic functions because it was contradicting wit…
sahilshekhawat Mar 19, 2014
00604b1
Final commit, added the logic function to be counted in count_ops()
sahilshekhawat Mar 19, 2014
d374ed5
remove the else condition and added the is.Boolean condition to gener…
sahilshekhawat Mar 22, 2014
d277512
Removed redundant tests count_ops(Basic()) = S.zero
sahilshekhawat Mar 22, 2014
dc6cf28
Removed trailing whitespaces, will always check them first.
sahilshekhawat Mar 22, 2014
ee126ac
Added the cases to handle the exception of True and False, who were b…
sahilshekhawat Mar 23, 2014
b49c02c
Fixed the bug.
sahilshekhawat Mar 23, 2014
2f7d1de
Merge branch 'master' of https://github.com/sympy/sympy
sahilshekhawat Mar 23, 2014
e1c8ea4
Fix the bug due to which `Basic()` was counted as an operation and us…
sahilshekhawat Mar 28, 2014
7adde66
Added more tests which also include some complex ones.
sahilshekhawat Mar 28, 2014
cc74cd8
removed extra spaces
sahilshekhawat Mar 28, 2014
80fd37a
removed ``true`` and ``false`` and used ``not a.args is ()`` instead …
sahilshekhawat Mar 29, 2014
912c0fd
Replace "is" with "==" to check the conditions.
sahilshekhawat Mar 29, 2014
9549f0b
replaced 'is' with '=='
sahilshekhawat Apr 4, 2014
37ba49b
Added tests to include cases of logic functions given less arguments …
sahilshekhawat Apr 5, 2014
4fbde7b
removed Basic and Tuple check
sahilshekhawat Apr 10, 2014
9771a86
Added more test related to Basic()
sahilshekhawat Apr 10, 2014
5d3950d
Added logical test for TUPLE and removed duplicate tests
sahilshekhawat Apr 11, 2014
189c659
removed some tests which were showing bugs in logical functions.
sahilshekhawat Apr 11, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions sympy/core/function.py
Expand Up @@ -2323,6 +2323,18 @@ def count_ops(expr, visual=False):
ops = [count_ops(i, visual=visual) for i in expr]
elif not isinstance(expr, Basic):
ops = []
elif expr.is_Boolean:
Copy link
Member

Choose a reason for hiding this comment

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

Why not just do this in the else block.

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 think it should be. should i?

ops = []
args = [expr]
while args:
a = args.pop()
o = C.Symbol(a.func.__name__.upper())
Copy link

Choose a reason for hiding this comment

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

I may not wonder if args.pop() will return whole the expr you import regardless how larger that is. Something like a = expr.args() would do the trick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its for the condition when two or more args of the expr are also logic functions( something like binary tree), in that case they will be appended to args and args.pop() will run the loop for each of them.
yes! you are right, initially it will return the whole expression regardless of how large it is.

ops.append(o*(len(a.args)-1))
args_len = len(a.args)
aargs = list(a.args)
for i in range(args_len):
if aargs[i].is_Boolean:
args.append(aargs[i])
else: # it's Basic not isinstance(expr, Expr):
if not isinstance(expr, Basic):
raise TypeError("Invalid type of expr")
Expand Down