-
Notifications
You must be signed in to change notification settings - Fork 42
add True, False #292
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?
add True, False #292
Conversation
One option for
It adds some allocations, but isn't too costly performance wise. |
Add a specialized |
That is here, it is when a BooleanAtom is part of an expression (like Basic(2)+True) that |
Oops, I hadn't pushed all the changes I had locally. What is there now is one way that booleans could be handled. |
src/numerics.jl
Outdated
m = CMapBasicBasic() | ||
m[True] = ONE; m[False] = ZERO |
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.
Can we make this map a global variable instead of creating it every time?
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.
I need your help with that. I was trying, but kept getting segfaults. The construction of Basic
objects is a bit different than that of CMapBasicBasic
, so I was having issue initializing the map in __init__
.
One thing about what I have here that bothers me is I'd like to cheaply test if an expression has a BooleanAtom
and then try to evaluate that expression after substitution with evalf
, but it seemed easier to do the substitution and then compare the result to the original. I wasn't sure if substituting in a map with no matches would always return the original expression, as the test has that assumption.
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.
I just checked in what I thought I'd tried earlier and it seems to not cause an issue. I'll add a direct test to be sure.
In #260 a promote rule for
true
orfalse
is setup. Currently this would promotetrue
to a symbolic1
andfalse
to a symbolic0
asBool <: Integer
. This provides an alternatative by promoting to a symbolicTrue
and symbolicFalse
.I don't know which is a better choice, this is just meant to provide an option.
If this option is better, it might be nice to have some means to convert
True
orFalse
to 1 or 0 with theN
function.