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

add xor,xnor and tests #1206

Merged
merged 3 commits into from Feb 28, 2017
Merged

add xor,xnor and tests #1206

merged 3 commits into from Feb 28, 2017

Conversation

ranjithkumar007
Copy link
Contributor

No description provided.

if (eq(*a, *boolTrue)) {
cnttrue++;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This function only checks for trues and false. logical_xor(x, y) would give false.

Copy link
Member

@isuruf isuruf left a comment

Choose a reason for hiding this comment

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

Please don't do git add .. There's a binary file commited here, symengine/stap7FQc

@@ -352,6 +404,43 @@ RCP<const Boolean> logical_not(const RCP<const Boolean> &s)
}
}

RCP<const Boolean> logical_xor(const set_boolean &s)
Copy link
Member

Choose a reason for hiding this comment

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

If you use a set here, how would you pass x, x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to change this....Same problem is with all other gates!

Copy link
Member

Choose a reason for hiding this comment

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

Or and And is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

symbols can be used as parameters if set_boolean is replaced by set_basic.

Copy link
Member

Choose a reason for hiding this comment

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

From x I meant the same boolean. for example, y < 0, y < 0 where y is a symbol.

@ranjithkumar007
Copy link
Contributor Author

@isuruf ,any idea why this job is failing?
Based on exec time 0.65s , i feel that the cause might be an infinite recursion but unable to figure out exactly...!

for (auto &a : s) {
if (is_a<BooleanAtom>(*a)) {
auto val = down_cast<const BooleanAtom &>(*a).get_val();
if (val == false) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is false ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because Xor(args,false) = Xor(args)

if (is_a<BooleanAtom>(*a)) {
SYMENGINE_ASSERT(a == boolTrue)
args.erase(a);
return logical_xnor(get_vec_from_set(args));
Copy link
Member

Choose a reason for hiding this comment

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

For performance reasons, these type of recursion should be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.. i would convert it to iterative way..

for (auto &a : args) {
if (is_a<BooleanAtom>(*a)) {
SYMENGINE_ASSERT(a == boolTrue)
args.erase(a);
return logical_xnor(get_vec_from_set(args));
cantsimplify = false;
nots++;
} else if (args.find(logical_not(a)) != args.end()) {
Copy link
Member

Choose a reason for hiding this comment

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

This can be checked in Line 447 and don't need to do this here.

for (auto &a : args) {
if (is_a<BooleanAtom>(*a)) {
SYMENGINE_ASSERT(a == boolTrue)
args.erase(a);
return logical_xnor(get_vec_from_set(args));
cantsimplify = false;
nots++;
Copy link
Member

Choose a reason for hiding this comment

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

You can do this in the if condition in line 429

} else if (args.size() == 1) {
return *args.begin();
} else {
while (args.size() > 1 and not cantsimplify) {
Copy link
Member

Choose a reason for hiding this comment

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

why is this run multiple times?

return *args.begin();
} else {
while (args.size() > 1 and not cantsimplify) {
cantsimplify = true;
for (auto &a : args) {
if (is_a<BooleanAtom>(*a)) {
SYMENGINE_ASSERT(a == boolTrue)
args.erase(a);
Copy link
Member

Choose a reason for hiding this comment

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

You are erasing from the vector while iterating it. Segfaults can happen if you do that.

@ranjithkumar007
Copy link
Contributor Author

ping @isuruf

args.erase(aa);
} else {
args.insert(aa);
if (args.find(logical_not(aa)) != args.end()) {
Copy link
Member

Choose a reason for hiding this comment

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

Store args.find(logical_not(aa)) so that you don't have to call this below as wel.

if (args.find(aa) != args.end()) {
args.erase(aa);
} else {
args.insert(aa);
Copy link
Member

Choose a reason for hiding this comment

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

Insert this only if the following if command is not true

args.erase(a);
} else {
args.insert(a);
if (args.find(logical_not(a)) != args.end()) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here

if (args.find(a) != args.end()) {
args.erase(a);
} else {
args.insert(a);
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@ranjithkumar007
Copy link
Contributor Author

ping @isuruf

@isuruf isuruf merged commit ed643cb into symengine:master Feb 28, 2017
isuruf added a commit to isuruf/symengine that referenced this pull request Aug 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants