text:
## Thursday, 22 August 2013

### FIFOs and Mapping with Bowtie using Gzipped Fastq files

So this will be a short one, but I didn't find any good solution to this problem online. I have compressed Fastqs that need Bowtie mapping for the genotyping of CNVs (Copy Number Variations) using CNVer. CNVer is a nice genotyping algorithm for CNVs that uses information from the read-depth and  paired-end mappings, but it needs a very specific mapping of the reads using the Bowtie aligner.  A minor technical difficulty arises from the fact that Bowtie doesn't understand gzipped files and requires vanilly Fastq files. Instead of running a gunzip, then Bowtie, then gzip, thus writing lots of stuff on the disk and suffering from the associated IO overhead, I wanted to do all this in a single step.

Another complication comes from the fact that Bowtie can't read data from the stdin, which prevents me from doing something like zcat my_compressed_fastq.fastq.gz | bowtie.
So the simple solution to this problem is to use named pipes, also known as FIFOs (First In First Out). Conceptually, they are the same as queues in real life. Let's say I'm waiting to pay for groceries at the store. If I was the first in line, I will be the first out of the line, unless someone cuts the line, but bytes never do that because they are respectful little creatures.

Concretely, this is done by using the mkfifo name_of_the_queue.fifo command in Linux or Mac OS. This command will create a queue on the filesystem that acts just like a regular file: we can write to it and read from it, but with the constraint of not being able to seek generic positions from it. In our case, we will create a queue, write the decompressed Fastq, and tell the second process in the pipeline (Bowtie) to read it's input from the previously create file-like-thingy (file-like-thingy == queue == FIFO).

mkfifo my_queue.fifo

zcat my_compressed_file.fastq.gz > my_queue.fifo &
bowtie reference.fasta my_queue.fifo
rm my_queue.fifo

The amperstand on line 2 is meant to start the zcat in a process without blocking the terminal. This way, Bowtie can start streaming from the queue as it is getting written.

To conclude, this method is efficient for two reasons. The first one is that there is no need to recompress the file using gzip as it would've been necessary to do if gunzip had been used. The second is that the decompression occurs concurrently with the mapping.
It is also important to note that since we're using a queue, it is impossible to "go back" in the file. This will only work if the file is read from start to end without ever looking back (you should never look back).

This was a simple article, but I hope it helps some of you saving some time and space.

## Sunday, 27 January 2013

### Computing Fibonacci

The Fibonacci sequence is often used to introduce the concept of recursion to new programmers. It has also been given a lot of interest because of his relationship to φ (phi), the mathematical constant that has often been observed in nature such as a ratio describing the arrangement of a pine cone, the spiral of snail's shells and other natural phenomena. Here, I will share an experiment I made where different algorithms computing the Fibonacci sequence were implemented in Python and compared.

## The Naive recursion

The mathematical definition of Fibonacci is the following:

$f(n)=\begin{cases} 0 & if\ n=0\\ 1 & if\ n=1\\ f(n-1)+ f(n-2) & if\ n\text{>1} \end{cases}$

The first terms of the sequence are: $$0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...$$

To compute this beautiful sequence, a programmer will be tempted to write a naive implementation that is very similar to the mathematical definition of the sequence. I wrote a sample implementation of this algorithm in Python:

def fibo_rec(n):
"""Naive implementation using the mathematical definition of
Fibonacci numbers. This is by far the slowest method.

"""
if n <= 1:
return n
else:
return fibo_rec(n - 1) + fibo_rec(n - 2)

As you can see, this implementation has the advantage of being really close to it's mathematical English counterpart and the code is an elegant recursion.

EDIT.Some people suggested an implementation similar to the one on the Python tutorial (except for the fact that the one on the tutorial is iterative). According to a comment from Reddit, the "more Pythonic" recursive implementation (see comments) might even be twice as fast. I chose the implementation presented here because it felt more readable to non Pythonists. It is also interesting to note that, in theory, the difference in speed is asymptotically negligible as $$O(n) \in O(2 \cdot n)$$.

Unfortunately, this is pretty much the worst implementation one could write. Some even argue that it shouldn't be the de facto standard for teaching recursion in programming or computer science classes, as it currently is the case [1].
The following Figure representing the recursive calls to fibo_rec when fibo_rec(5) is called. It is easy to notice the problem with this solution: the same Fibonacci numbers are computed again and again.
Figure 1. The recursion tree with fibo_rec(5) as the initial call.
In fact, the number of recursive calls for this example is described in Table I.

Table I. Number of recursive calls to various fibo_rec(n).
n Number of calls
0 3*
1 5
2 3
3 2
4 1
5 1
* Note that if f(1) called f(0), as it is the case in a similar recursive implementation of this algorithm, we would count a total of 5 + 3 = 8 calls for f(0).

As the careful reader will notice, the number of recursive calls to different values of n follows a Fibonacci sequence. In this case, this results in a 9 redundant calls, but this number would quickly grow as we compute larger numbers. Nobody likes redundant calls, so we will look into a better solution.

EDIT. Some people were curious about a recursive implementation that memorised the previously generated numbers to avoid call redundancy. I quickly implemented an algorithm exploiting this idea:
def fibo_rec_mem(n, i = 0, j = 1):
"""Recursive version using tail-recursion

"""
if n <= 1:
return j
else:
return fibo_rec_mem(n - 1, j, i + j)
This algorithm's performance is probably very similar to the iterative version that will be discussed shortly. The only problem is that it reaches the maximum recursion depth at n = 994, which makes it very impractical to generate Fibonacci numbers. Also note that the bitbucket repo has been updated with this version.

## The intuitive iteration

To improve the previous algorithm's performance, we will memorize the 2 previously generated Fibonacci numbers and compute the sum at every iteration, until we end up with the desired number. The algorithm is the following:
def fibo_iter(n):
i = 1
j = 0
for k in xrange(n):
j = i + j
i = j - i
return j

I chose this elegantly written implementation even if it could be harder to understand. The first statement of the loop computes the Fibonacci number (j) and the second statement memorizes the previous number (i). After n iterations, we return j which is the desired number. This method apparently runs in O(n), but no formal proof will be attempted here. We will now show another interesting property that will allow O(log n) time complexity.

EDIT. Some comments mentioned the dynamic programming solution. This solution, from what I read about it, fills an array (e.g. Python list) with the Fibonacci numbers iteratively using the previously generated values to compute every subsequent number. This solution is very similar to the one presented here, but instead of using O(n) space to store the values in an array, I store what is needed for the computations (i and j) which is O(1) space. The dynamic programming versions is probably more useful if you need to memorize all of the numbers for later use. Jeff Erickson's interesting discussion on the subject is available online [6].

## Fun with matrices

The interesting mathematical property we are all so excited about is the following:
$\left({ \begin{array}{c} {1} & {1} \\ {1} & {0} \\ \end{array} }\right)^n = \left({ \begin{array}{c} {f_{n+1}} & {f_n} \\ {f_n} & {f_{n-1}} \\ \end{array} }\right)$
The proof of this identity probably requires mathematical knowledge that is beyond my current capacity, but you can empirically see for yourself using WolframAlpha:
or see fancy maths in Ly et al. [2].

EDIT. Some people mentioned an easy proof by induction of the aforementioned property. I attempted such a proof:
The basis of induction, for n = 1 is the following:
$\left(\begin{array}{cc} 1 & 1\\ 1 & 0 \end{array}\right)^{1}=\left(\begin{array}{cc} f_{\text{1+1}} & f_{1}\\ f_{1} & f_{1-1} \end{array}\right)=\left(\begin{array}{cc} f_{\text{2}} & f_{1}\\ f_{1} & f_{0} \end{array}\right)$
Which does not invalidate our hypothesis.
Let's assume, for all n that our induction hypothesis is true and prove for n + 1:
$\left(\begin{array}{cc} 1 & 1\\ 1 & 0 \end{array}\right)^{n+1}=\left(\begin{array}{cc} 1 & 1\\ 1 & 0 \end{array}\right)^{n}\left(\begin{array}{cc} 1 & 1\\ 1 & 0 \end{array}\right) =\left(\begin{array}{cc} f_{\text{n+1}} & f_{n}\\ f_{n} & f_{n-1} \end{array}\right)\left(\begin{array}{cc} 1 & 1\\ 1 & 0 \end{array}\right)$
by the induction hypothesis
$=\left(\begin{array}{cc} 1\cdot f_{n+1}+1\cdot f_{n} & 1\cdot f_{n}+1\cdot f_{n-1}\\ 1\cdot f_{n+1}+0\cdot f_{n} & 1\cdot f_{n}+0\cdot f_{n-1} \end{array}\right)=\left(\begin{array}{cc} f_{n}+f_{n+1} & f_{n-1}+f_{n}\\ f_{n+1} & f_{n} \end{array}\right)$
by matrix multiplication
$=\left(\begin{array}{cc} f_{n+2} & f_{n+1}\\ f_{n+1} & f_{n} \end{array}\right)$ by the definition of the Fibonacci sequence.
Since the final matrix corresponds to what would be expected for n + 1, our induction hypothesis holds and the proof is complete.

For us, that means that a better algorithm can be implemented using these properties:
def fibo_log(n):
"""This method uses interesting algorithmic strategies
and is supposed to be O(log n).

"""
i = 1
j = 0
k = 0
h = 1
while n > 0:
if n % 2 != 0:
t = j * h
j = i * h + j * k + t
i = i * k + t
t = h ** 2
h = 2 * k * h + t
k = k ** 2 + t
n = int( n / 2 )
return j

I won't go in the details of this method, as it is visibly more complex than the previous solutions, but I will compare the performance of my different implementations empirically.

## Empirical comparison of those beautiful algorithms

In order to compare the algorithms, I wrote a Python function that uses the cProfile module (available in the standard library). The function that allowed me to do so takes a function as an argument, and passes the other arguments and named arguments to the given function.
def time_call(f, *args, **kwargs):
"""Function that measures execution time of a given function f
with args and kwargs as arguments.

"""

code = "{0}(".format(f.__name__)
if args:
for i in xrange(len(args)):
if i != 0:
code += ", "
if type(args[i]) is str:
code += "\"{0}\"".format(args[i])
else:
code += "{0}".format(str(args[i]))

if kwargs:
base = ", " if args else ""
i = 0
for k, v in kwargs.iteritems():
if i != 0:
base = ", "
if type(v) is str:
code += "{0}{1}=\"{2}\"".format(base, k, v)
else:
code += "{0}{1}={2}".format(base, k, str(v))
i += 1

code += ")"
cProfile.run(code)

This can be used to easily (but probably not optimally) compare different implementations. In this case, it allowed me to compile execution time, denoted T(n) for different Fibonacci numbers fn. The result is shown in Figure 2.
Figure 2. Graph comparing the execution time T(n) in seconds of different implementations of algorithms that compute Fibonacci numbers at different indexes n (notice the log-scale). The observation of Figure 2 show that the first algorithm that was described, the naive recursion is by far the slowest. It becomes unusable (in reasonable time) around n=30 where T(n) = 15.255s. The second slowest algorithm is the iterative version, but still is a better choice than the first implementation. It takes around 37s to compute the 786 432th Fibonacci number. Finally, the best implementation (shown here) is the one based on the matrix identity. This final implementation took 32s to compute the 9 000 000th Fibonacci number. Note that tests were ran on a virtual machine (using VirtualBox with 2048MB of RAM and 4 accessible CPU cores.

Finally, I just wanted to briefly mention another method that is really fast, but was too complicated to implement correctly for this brief article. The Fibonacci recurrence can be expressed as a simple expression known as Binet's formula: $f_n=\frac{1}{\sqrt{5}}(\varphi^n-\varphi'^n)$ where $$\varphi=\frac{1+\sqrt{5}}{2},\ \varphi'=\frac{-1}{\varphi}$$.
A variation of this formula can be used to compute Fibonacci numbers:
SQRT5 = 5 ** 0.5
PHI = (1 + SQRT5) * 0.5
def fibo_lin(n):
"""This method uses Binet's formula, which is mathematically
correct and very fast, but is not easily implemented
because of overflow errors at the PHI ** n step.

Also, floating number arithmetic seems to introduce
errors when n > 70.
(http://bosker.wordpress.com/2011/07/27/computing-fibonacci-numbers-using-binet%E2%80%99s-formula/)

"""
if n == 0: return n
return round(PHI ** n / SQRT5)

This is actually very, very fast. The only problem comes from the handling of large floating point numbers, which makes it hard to compute numbers over n ≥ 70 without rounding errors. A solution to this problem exists, as described in Robin Houston's blog [3]. This is probably the best way to compute the Fibonacci numbers.

To conclude, I wrote this article to give a real-life perspective on different approaches to the computation of the Fibonacci sequence. If you're interested in reading more about Fibonacci, you can look at the Cited Works section, or these excellent Wikipedia articles on the subject [4, 5]. I hope it helped some of you and, I'm open to your feedback or suggestions. Also note that all the code that is described here is available on my Bitbucket page.


text:
its an extremely long cryptography equation for encoding messages, i've been working on it for the last two hours, and everytime i come to a conclusion close to this:

(C⊞K)⊕(V⊞K) = 0
i know both C and V, now i need to know K, what can i do? i don't really know how to interact with the XOR and the addition mod togather

2. Well, you can take it this way:

If $(C\otimes K)\oplus(V\otimes K)=0,$ then it must be that both $C\otimes K=0$ and $V\otimes K=0.$

Also, note that the XOR function is its own inverse. That is,

$a\otimes a=0.$ Moreover, if $a\otimes b=c,$ then you can left-multiply by $a$ as follows:

$a\otimes(a\otimes b)=a\otimes c$

$(a\otimes a)\otimes b=a\otimes c$ (associativity of XOR)

$0\otimes b=a\otimes c$

$b=a\otimes c$.

Hence, you must have

$V\otimes(V\otimes K)=V\otimes 0=V$

$K=V.$

3. Note: first post was entirely incorrect. Sorry about that.

4. i know that XOR is its own inverse, however, in there there are 2 operators ... and one of the is an addition mod

okay, if this is too far fetched, is it possible to solve this :
(C+K)⊕(V+K) = 0
⊕ : XOR

5. no problem mate, i appreciate you trying to help, i'll take whatever i can get

6. Did you check my edited post # 2?

i didnt really think enough about the 0, and i see where your going at, i should have mentioned earlier that this is the equation:
P = (C⊟K )⊕(V⊟K )

⊟ : Modular Subtraction
⊕ : XOR
the right hand side was quite long but i can simplify it to a 64 bit block P, now i need to tell K (which is the key)

8. Define modular subtraction. If it's subtraction modulo 2 (as in normal boolean logic), then it is the same as addition modulo 2. Is that correct?

9. subtraction modulo 2^64

also all of the variables here are blocks of 64 bit data

10. And the XOR is bitwise XOR?

11. yes, bitwise xor . i apologize for not being more specific

12. Well, let's assume a distributive property:

$(C-K)\oplus(V-K)=(C\oplus V)-(C\oplus K)-(K\oplus V)+(K\oplus K)=(C\oplus V)-(C\oplus K)-(K\oplus V).$

Here you can see that I've got an inverse for the modular subtraction, which is modular addition.

Then $P-(C\oplus V)=-K\oplus(C+V),$ or

$(C\oplus V)-P=K\oplus(C+V),$ and hence

$(C+V)\oplus((C\oplus V)-P)=K.$

This is probably too simple-minded, but maybe it'll give you an idea. What do you think?

13. i am not really certain the the distributive property works here, and that is precisely the problem, i have nothing to work on here ... how about this:
given these two equations, do you think there is a different approach to solve for X,Y:
X=(V⊟Y)⊕P
X=(D⊟Y)⊕P

again, all data here are 64 bit data, ⊕ is bitwise XOR, and ⊟ is subtraction mod 2^64

14. Hmm. A preliminary computation yields that we don't have the distributive property. At least, not exactly. Take $A = 1010_{2}$, $B = 0011_{2}$, $C = 0001_{2}$. Then

$A\otimes(B-C)=A\otimes(0010_{2})=1000_{2},$ whereas

$(A\otimes B)-(A\otimes C)=1001_{2}-1011_{2}=-2_{10}=14_{10}=1110_{2}\not=1000_{2}.$

I think I'm out of my league now. Let me ask some of our gurus for help. Perhaps undefined or emakarov could help out.

15. Originally Posted by hamzeeco

i didnt really think enough about the 0, and i see where your going at, i should have mentioned earlier that this is the equation:
P = (C⊟K )⊕(V⊟K )

⊟ : Modular Subtraction
⊕ : XOR
the right hand side was quite long but i can simplify it to a 64 bit block P, now i need to tell K (which is the key)
Interesting discussion on this thread, and I certainly don't claim to be an expert on any of this, but I see a problem that I'll explain by example.

Consider 6-bit data, where our operations are mod 2^6.

Let C = 101010
Let V = 011110

Now consider K1 = 001000 and K2 = 000010

So

A1 = C - K1 = 100010
B1 = V - K1 = 010110

P1 = A1 XOR B1 = 110100

A2 = C - K2 = 101000
B2 = V - K2 = 011100

P2 = A2 XOR B2 = 110100

So as you can see two different values of K yielded the same P. From this I am led to believe that we cannot determine K in general without guesswork.

Originally Posted by Ackbeet
Let me ask some of our gurus for help. Perhaps undefined or emakarov could help out.
Didn't see this until after I made my post. Very flattered but I think guru is too strong of a word in my case!

Page 1 of 2 12 Last

format: plain


text:
## top of the top

Posted in Statistics with tags , , , on August 19, 2021 by xi'an

An easy-peasy riddle from The Riddler about the probability that a random variable is the largest among ten iid variates, conditional on the event that this random variable is larger than the upper decile. This writes down easily as

$10\int_{q_{90}}^\infty F^9(x) f(x)\,\text d x$

if F and f are the cdf and pmf, respectively, which is equal to 1-.9¹⁰, approximately 1-e⁻¹, no matter what F is….

## multinomial but unique

Posted in Kids, R, Statistics with tags , , , , , , on July 16, 2021 by xi'an

A quick riddle from the Riddler, where the multinomial M(n¹,n²,100-n¹-n²) probability of getting three different labels out of three possible ones out of three draws is 20%, inducing a single possible value for (n¹,n²) up to a permutation.

Since this probability is n¹n²(100-n¹-n²)/161,700, there indeed happens to be only one decomposition of 32,340 as 21 x 35 x 44. The number of possible values for the probability is actually 796, with potential large gaps between successive values of n¹n²(100-n¹-n²) as shown by the above picture.

## fun sums

Posted in Books, Kids, Statistics with tags , , , , , , on May 26, 2021 by xi'an

Some sums and limits found from a [vacation] riddle by The Riddler:

For the first method, Friend 1 takes half of the cake, Friend 2 takes a third of what remains, and so on. After  infinitely many friends take their respective pieces, you get whatever is left.

$\lim_{k\to\infty}\prod_{i=2}^k\left(1-\dfrac{1}{i}\right) = \lim_{k\to\infty} \dfrac{1}{k} = 0$

For the second method, Friend 1 takes ½² of the cake, Friend 2 takes ⅓² of what remains, and so on. After infinitely many friends take their respective pieces, you get whatever is left.

$\lim_{k\to\infty}\prod_{i=2}^k\left(1-\dfrac{1}{i^2}\right) = \lim_{k\to\infty}\dfrac{k+1}{2k} = \dfrac{1}{2}$

For the third method, Friend 1 takes ½² of the cake, Friend 2 takes ¼² of what remains, Friend 3 takes ⅙² of what remains after Friend 2, and so on. After your infinitely many friends take their respective pieces, you get whatever is left.

$\lim_{k\to\infty}\prod_{i=2}^k\left(1-\dfrac{1}{4i^2}\right) = \lim_{k\to\infty}\dfrac{4(2k+1)}{3\pi k} = \dfrac{2}{\pi}$

## you said that I said that you said that…

Posted in Books, Kids, pictures, Statistics with tags , , , on May 25, 2021 by xi'an

A riddle from The Riddler on limited information decision making, which I tought I failed to understand:

Two players, Martina and Olivia, are each secretly given realisations, m and u. Starting with Martina, they must state to the other player whom they think probably has the greater number until they agree. They are playing as a team, hoping to maximize the chances they correctly predict who has the greater number. For a given round, what is the probability that the person they agree on really does have the bigger number?

A logical strategy is as follows: If m>.5, P(U>m)<.5, hence Martina should state her number is probably bigger, which conveys to Olivia that M>.5. If u<.5, Olivia can agree for certain, else, if u>.75, P(M>u)<.5 and she can state a probably larger number, while if 0.5<u<.75, Olivia can state (truthfully) that her number us probably smaller, although there is a ½ probability she is wrong. As detailed in the solution, the probability of finishing on a false statement is ¼²+¼³+…, equal to 1/12.

## Georgia on my mind

Posted in Books, Kids, Statistics, Travel with tags , , , , , , , , on May 12, 2021 by xi'an

The riddle of this week was inspired by the latest presidential elections when one State after another flipped the winner from Trump to Biden. Incl. Georgia.

On election night, the results of the 80 percent who voted on Election Day are reported out. Over the next several days, the remaining 20 percent of the votes are then tallied. What is the probability that the candidate who had fewer votes tallied on election night ultimately wins the race?

Assuming many votes, perfect balance between both candidates (p=½), and homogeneity between early and late ballots, the question boils down to the probability of a sum of two normals, X+Y, ending up being of the opposite sign from X, when the variances of X and Y are α and 1-α. Which writes as the expectation

$2 \mathbb{E}_\alpha[\Phi(-X/\sqrt{1-\alpha})]$

equal to

$\frac{2}{2\pi}\left(\frac{\pi}{2} + \arctan\{\sqrt{\alpha/(1-\alpha)|}\}\right)$

which returns a probability of about 0.14 when α=0.8. When looking at the actual data for Georgia, out of 5 million voters, at some point 235,000 ballots remained to be counted with Trump on the lead. This means an α about 0.05 and implies a probability of 7% (not accounting for the fact that the remaining mail-in-ballots were more favourable to Biden.)


text:
## Filters

Sort by :
Clear All
Q

4.  Three coins are tossed once. Let A denote the event ‘three heads show”, B denote the event “two heads and one tail show”, C denote the event” three tails show and D denote the event ‘a head shows on the first coin”. Which events are

(ii)  simple?

Sample space when three coins are tossed = [Sample space when a coin is tossed thrice!] S = {HHH, HHT, HTH, HTT, THH, TTH, THT, TTT} Now,  A = Event that three heads show up = {HHH}  B = Event that two heads and one tail show up = {HHT, HTH, THH}  C = Event that three tails show up = {TTT} D = Event that a head shows on the first coin = {HHH, HHT, HTH, HTT} (ii).If an event X has only one...

4.  Three coins are tossed once. Let A denote the event ‘three heads show”, B denote the event “two heads and one tail show”, C denote the event” three tails show and D denote the event ‘a head shows on the first coin”. Which events are

(i)  mutually exclusive?

Sample space when three coins are tossed = [Sample space when a coin is tossed thrice!] S = {HHH, HHT, HTH, HTT, THH, TTH, THT, TTT} Now,  A = Event that three heads show up = {HHH}  B = Event that two heads and one tail show up = {HHT, HTH, THH}  C = Event that three tails show up = {TTT} D = Event that a head shows on the first coin = {HHH, HHT, HTH, HTT} (i).  For two elements X and Y to be...

3.     An experiment involves rolling a pair of dice and recording the numbers that come up. Describe the following events:

Which pairs of these events are mutually exclusive?

For two elements to be mutually exclusive, there should not be any common element amongst them. Also, A = {(3,6), (4,5), (5, 4), (6,3), (4,6), (5,5), (6,4), (5,6), (6,5), (6,6)} B = {(1,2), (2,2), (3, 2), (4,2), (5,2), (6,2), (2,1), (2,3), (2,4), (2,5), (2,6)} C = {(3,6), (6,3), (5, 4), (4,5), (6,6)}  Now,  A  B =       (no common element in A and B) Hence, A and B are mutually...

3.     An experiment involves rolling a pair of dice and recording the numbers that come up. Describe the following events:

C: the sum is at least $7$ and a multiple of $3$

Sample space when a die is rolled: S = {1, 2, 3, 4, 5, 6} Let E = Event of rolling a pair of dice (= Event that a die is rolled twice!) [6x6 = 36 possible outcomes] E = [ {(x,y): x,y  S } ] = {(1,1), (1,2)...(1,6),(2,1).....(6,5),(6,6)} Now, C: the sum is at least 7 and a multiple of 3 The sum can only be 9 or 12. C = [ {(a,b): (a,b)  E, a+b>6 & a+b = 3k, k  I} ]= {(3,6), (6,3), (5, 4), (4,5), (6,6)}

3.    An experiment involves rolling a pair of dice and recording the numbers that come up. Describe the following events:

B: $2$ occurs on either die

Sample space when a die is rolled: S = {1, 2, 3, 4, 5, 6} Let E = Event of rolling a pair of dice (= Event that a die is rolled twice!) [6x6 = 36 possible outcomes] E = [ {(x,y): x,y  S } ] = {(1,1), (1,2)...(1,6),(2,1).....(6,5),(6,6)} Now, B: 2 occurs on either die Hence the number 2 can come on first die or second die or on both the die simultaneously. B = [ {(a,b): (a,b)  E, a or b = 2 } ]=...

3.    An experiment involves rolling a pair of dice and recording the numbers that come up. Describe the following events:

A: the sum is greater than $8$

Sample space when a die is rolled: S = {1, 2, 3, 4, 5, 6} Let E = Event of rolling a pair of dice (= Event that a die is rolled twice!) [6x6 = 36 possible outcomes] E = [ {(x,y): x,y  S } ] = {(1,1), (1,2)...(1,6),(2,1).....(6,5),(6,6)} Now, A : the sum is greater than 8 Possible sum greater than 8 are 9, 10, 11 and 12 A = [ {(a,b): (a,b)  E, a+b>8 } ]= {(3,6), (4,5), (5, 4), (6,3), (4,6),...

2.(vi)    A die is thrown. Describe the following events:

Also find (i)  ${F}'$

F = {3, 4, 5, 6}  F' = {3, 4, 5, 6}' = S - F = {1, 2}

2.(vi)     A die is thrown. Describe the following events:

Also find (h) $E\cap F'$

E = {6} F = {3, 4, 5, 6}  F' = {3, 4, 5, 6}' = S - F = {1, 2}  E  F' = {6}  {1, 2} =

2.(vi)     A die is thrown. Describe the following events:

Also find (g)  $D-E$

D = {1, 2, 3} E = {6}  D - E = {1, 2, 3} - {6}  = {1, 2, 3}

2.(vi)         A die is thrown. Describe the following events:

Also find  (f)  $A-C$

A = {1, 2, 3, 4, 5, 6} C = {3, 6}  A - C = {1, 2, 3, 4, 5, 6} - {3, 6}  = {1, 2, 4, 5}

2.(vi)      A die is thrown. Describe the following events:

Also find (e) $D\cap E$

D = {1, 2, 3} E = {6}  D  E = {1, 2, 3}   {6} =  (As nothing is common in these sets)

2.(vi)     A die is thrown. Describe the following events:

(d)    Also find  $E\cap F$

E = {6} F = {3, 4, 5, 6}  E  F = {6}   {3, 4, 5, 6} = {6}

2.(vi)     A die is thrown. Describe the following events:

Also find (c)  $B\cup C$

B= C= {3, 6}  B  C =   {3, 6} = {3, 6}

2.(vi)        A die is thrown. Describe the following events:

Also find (b) $A\cap B$.

A = {1, 2, 3, 4, 5, 6} B=  A  B = {1, 2, 3, 4, 5, 6}   =

2.(vi)  A die is thrown. Describe the following events:

Also find  (a)  $A\cup B$

A = {1, 2, 3, 4, 5, 6} B=  A  B = {1, 2, 3, 4, 5, 6}   = {1, 2, 3, 4, 5, 6}

2.   A die is thrown. Describe the following events:

(vi)  F: a number not less than 3

When a die is rolled, the sample space of possible outcomes: S = {1, 2, 3, 4, 5, 6} or {x : x  N, x<7} Given, F : a number not less than 3  F = {x: x  S, x  3 } = {3, 4, 5, 6}

2.  A die is thrown. Describe the following events:

(v)   E: an even multiple greater than 4

When a die is rolled, the sample space of possible outcomes: S = {1, 2, 3, 4, 5, 6} or {x : x  N, x<7} Given, E : an even number greater than 4 S1 = Subset of S containing even numbers = {2,4,6} Therefore , E = {6}

2.   A die is thrown. Describe the following events:

(iv)   D: a number less than 4

When a die is rolled, the sample space of possible outcomes: S = {1, 2, 3, 4, 5, 6} or {x : x  N, x<7} Given, D : a number less than 4 D = {1, 2, 3}

2.    A die is thrown. Describe the following events:

(iii) C: a multiple of 3.

When a die is rolled, the sample space of possible outcomes: S = {1, 2, 3, 4, 5, 6} or {x : x  N, x<7} Given, C : a multiple of 3 C = {3, 6}

2.     A die is thrown. Describe the following events:

(ii) B: a number greater than 7

When a die is rolled, the sample space of possible outcomes: S = {1, 2, 3, 4, 5, 6} or {x : x  N, x<7} Given, B: a number greater than 7 As no number on the die is greater than 7 B =
Exams
Articles
Questions


text:
# 16   Find the shortest distance between the lines whose vector equations are $\overrightarrow{r}=(\widehat{i}+2\widehat{j}+3\widehat{k})+ \lambda (\widehat{i}-3\widehat{j}+2\widehat{k})$ and              $\overrightarrow{r}=(4\widehat{i}+5\widehat{j}+6\widehat{k})+ \mu (2\widehat{i}+3\widehat{j}+\widehat{k})$.

D Divya Prakash Singh

Given two equations of line

$\overrightarrow{r}=(\widehat{i}+2\widehat{j}+3\widehat{k})+ \lambda (\widehat{i}-3\widehat{j}+2\widehat{k})$ $\overrightarrow{r}=(4\widehat{i}+5\widehat{j}+6\widehat{k})+ \mu (2\widehat{i}+3\widehat{j}+\widehat{k})$ in the vector form.

So, we will apply the distance formula  for knowing the distance between two lines $\vec{r} =\vec{a_{1}}+\lambda{b_{1}}$   and   $\vec{r} =\vec{a_{2}}+\lambda{b_{2}}$

$d= \left | \frac{\left ( \vec{b_{1}}\times\vec{b_{2}} \right ).\left ( \vec{a_{2}}-\vec{a_{1}} \right )}{\left | \vec{b_{1}}\times \vec{b_{2}} \right |} \right |$

After comparing the given equations, we obtain

$\vec{a_{1}} = \widehat{i}+2\widehat{j}+3\widehat{k}$                $\vec{b_{1}} = \widehat{i}-3\widehat{j}+2\widehat{k}$

$\vec{a_{2}} = 4\widehat{i}+5\widehat{j}+6\widehat{k}$             $\vec{b_{2}} = 2\widehat{i}+3\widehat{j}+\widehat{k}$

$\vec{a_{2}}-\vec{a_{1}} = (4\widehat{i}+5\widehat{j}+6\widehat{k}) - (\widehat{i}+2\widehat{j}+3\widehat{k})$

$= 3\widehat{i}+3\widehat{j}+3\widehat{k}$

Then calculating the determinant value numerator.

$\vec{b_{1}}\times\vec{b_{2}} = \begin{vmatrix} \widehat{i} &\widehat{j} &\widehat{k} \\ 1& -3 &2 \\ 2& 3& 1 \end{vmatrix}$

$= (-3-6)\widehat{i}-(1-4)\widehat{j}+(3+6)\widehat{k} = -9\widehat{i}+3\widehat{j}+9\widehat{k}$

That implies, $\left | \vec{b_{1}}\times\vec{b_{2}} \right | = \sqrt{(-9)^2+(3)^2+(9)^2}$

$= \sqrt{81+9+81} = \sqrt{171} =3\sqrt{19}$

$\left ( \vec{b_{1}}\times\vec{b_{2}} \right ).\left ( \vec{a_{2}}-\vec{a_{1}} \right )=(-9\widehat{i}+3\widehat{j}+9\widehat{k})(3\widehat{i}+3\widehat{j}+3\widehat{k})$

$= (-9\times3)+(3\times3)+(9\times3) = 9$

Now, after substituting the value in the above formula we get,

$d= \left | \frac{9}{3\sqrt{19}} \right | = \frac{3}{\sqrt{19}}$

Therefore,$\frac{3}{\sqrt{19}}$ is the shortest distance between the two given lines.

Exams
Articles
Questions