Forgive me; I'm a coder and not a mathematician, so I'm asking this to my own stack. I'm trying to reduce an array of probabilities (0-1), let's say [.1,.3,.5] to find:
The likelihood of all of them happening (simple multiplication, let's call this function
AND:probs.reduce((m,p)=>p*m,1)),any one of them happening (one minus none of them happening
1 - probs.reduce((m,p)=>m*(1-p),1), call itOR), andXORONLY one, no more and no less, of them happening. At first I thought this was simple because if there are only two inputs, the chance of only one happening should beORminusAND. But as I'm banging my head on this as an array of more than two values, normal XOR logic seems to disintegrate.
Do I need to get the "OR" and then subtractively multiply all possible AND scenarios iteratively? Or is there a non-iterative formula to find out the total probability of exactly one probability in a list longer than two?
0,0,0 should be 0 in my case. 0,.4.0 should yield a .4 of only one happening. 1,.4,0 should yield 0.6. I know that .5,.5 should yield 0.25 chance of only one happening. But I'm really not sure how to calculate the chance of only one .5,.5,.5 without counting on my fingers. My mind is saying I have to loop through each probability, and subtract from it the chance of any others (OR the rest of the array), then OR the final results... but this is speculative. That seems very weird and inefficient. I can't believe this would be an NP-Hard problem, but it's a corner of things I'm not familiar with...
Please answer in visual, logical or programmatic terms, not pure Math if possible...
** Edit here: I don't need to clarify the exact probability of a particular element in the array being exclusive to the others; I'm trying to find the general probability of any of them being exclusive. **
** Edit. This is what I've got now. I'm excluding all other possibilities for each individual one. Is this the fastest way?... *
function And(probs) {
return (probs.reduce((m,p)=>p*m,1));
}
function Or(probs) {
return (1 - probs.reduce((m,p)=>m*(1-p),1));
}
function Xor(probs) {
let _exclusiveProbabilities = [];
for (let k=0; k < probs.length; k++) {
let _others = [];
for (let j = 0; j < probs.length; j++) {
if (j != k) {
_others.push(probs[j]);
console.log(k,'pushed',probs[j]);
}
}
const _anyOtherProb = Or(_others);
_exclusiveProbabilities.push(probs[k] * (1 - _anyOtherProb));
}
return (Or(_exclusiveProbabilities));
}
** edit. Nope, that's great for two but doesn't work for three. **


