Message Boards Message Boards

0
|
3880 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How to extract cases from a Piecewise expression

How do we extract all the cases of Equal expressions from a Piecewise expression output? (here for example: looking for the support of the random variable Y)

I'll be happy to include your solutions/contributions in my book.

POSTED BY: Raspi Rascal
5 Replies

Thanks everyone, you guys made my day!

True ... omg that was too funny. I wouldn't have figured that one out. Definitely made it into the book and for further use in there. Next week I'm learning the basics of Bernoulli trials and binomial distribution yay!

POSTED BY: Raspi Rascal

Hi Raspi, interesting things you are doing! Regarding your question - maybe like so:

Sort@Cases[expr, Equal[_, val_] :> val, Infinity]
POSTED BY: Henrik Schachner

I swear, when i tried this earlier today, it hadn't worked ("my attempts failed"). Obviously, i must have done something wrong. I am wondering why this doesn't work:

Cases[expr, Equal[_, _], Infinity]

while this works:

Cases[expr, Equal[_, a_], Infinity]

But yes, that's exactly it, thank you very much @Henrik !

btw not very interesting, just trying to pick up some basic Stochastik knowledge and figuring out how to make Mathematica do all the work haha. Today, for example, i learned that game's pretty much over fast, as soon as the random variables $X$ and $Y$ are dependent. Or, when $X$ is something non-trivial, M. can't be helpful either because it doesn't know the distribution ... which is the thing that you're looking for in the first place lol. So one must calculate the distribution "manually" with combinatorics, programming, tree diagram, or random numbers simulation. Just in the case, when you know the joint distribution beforehand and feed it as input, then M. becomes an unstoppable power house. Anyway, i am still at the beginning of all of it. I barely understand the difference between EmpiricalDistribution and HistogramDistribution, two very similar functions, so confusing :D

POSTED BY: Raspi Rascal

Hi Raspi, I always enjoy reading your questions! Here it took me a while to understand why your first attempt fails: Equal[_, _] evaluates to True before anything else is happening ...

POSTED BY: Henrik Schachner
Posted 3 years ago

To prevent early evaluation

Cases[expr, HoldPattern[Equal[_, _]], Infinity]
(* {y == 2, y == 12, y == 3, y == 11, y == 4, y == 10, y == 5, y == 9, 
 y == 6, y == 8, y == 7} *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract