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
> --
> 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 sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
Here's something that might be useful to you then: in the git master,
we there is an option to simplify() that let's you use a custom
measure function. simplify() tries various types of simplifications,
and returns the expression that gives the smallest value according to
the measure function. By default, this is count_ops(), which gives
the number of operations in the expression. But you can easily create
a custom function that penalizes branch points (or anything). See the
docstring of simplify() for an example. The feature was added fairly
recently, and is intended for experimentation, so let us know how it
works for you if you decide to use it.
By the way, if all you want to do is keep track of the fact that the
Symbol is binary, and never really symbolically use this fact, it
would probably be better to just use some naming convention. As a
simple example, you could always make binary symbols start with the
letter b. You can easily check this (b.name.startswith('b')).
Depending on what your names are, you might choose something more
complicated, and use re to programmatically parse it out.
Mod is OK too, but it might clutter things up more, especially if you
have very large expressions. You also could just use Symbol('b',
binary=True). It won't create .is_binary, but you can easily check
.assumptions0 for it. Do note though that this last option is based
on internal APIs that might (will) change in the future.
Aaron Meurer
> --
> 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/-/WbtZDllULS0J.