So you want to assume that b is a number modulo 2.  To do this, you
can use the new Mod() object that was recently added.  Note that this
was added after the latest release, so you'll have to use the git
version if you want to use it.

You define b = Symbol('b', integer=True), and use Mod(b, 2) everywhere
where you have b, and that will represent that it should be either 0
or 1.  Note that this is still very new, and presently doesn't really
do much beyond evaluating with numbers.  But more is planned, e.g.,
reduction of things like Mod(2*b, 2) to 0.

Another option that might work, depending on what you are doing, is to
use the new stats code, which is so new it hasn't even been merged yet
(see https://github.com/sympy/sympy/pull/902).  There, you could do
something like b = Die(2, symbol='b'), and then b would represent a
random variable, with 50% probability of being 0 and 50% probability
of being 1. Again, though, it depends on what you are doing.  With
this, you can easily compute things like expected values and
conditional probabilities, and (I believe), substitute in random
values.

So what exact things would you want to do with the object? I think the
best answer depends on what exactly you are wanting to do.

And by the way, Symbol() does indeed accept any "assumption".  It
doesn't seem to do anything with them, though, other than put them in
.assumptions0 (it doesn't even automatically create .is_binary).  I
think this is a bug, but it might be there for a reason.  Does anyone
know if this is intentional? I created
http://code.google.com/p/sympy/issues/detail?id=2967 for this.

Aaron Meurer

On Thu, Jan 5, 2012 at 12:40 AM, Kevin Hunter <hunt...@gmail.com> wrote:
> Hullo Sympy Group,
>
> In my code, I'd like to be able to specify symbols with a binary type,
> something akin to:
>
>>>> b = symbols('b', binary=True)
>
> This would let b assume only values from the set {0, 1}.  I see the Boolean
> class from which the Symbol class derives, but I believe that's for boolean
> operations.  The symbols function appears to accept the binary keyword, but
> it appears to silently accept /any/ keyword.  What I'm currently doing for
> my uses is keeping track of this via an external object, but I'm hoping I
> can get the Sympy core to take note of it's status.
>
> Is there a way to specify a variable as binary?
>
> Thanks,
>
> Kevin
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/rrwCaYpeoyMJ.
> To post to this group, send email to sympy@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to