text:
Conditional Probability

P(B|A) = P(A and B)/ P(A)

Estimated14 minsto complete
%
Progress
Practice Conditional Probability

MEMORY METER
This indicates how strong in your memory this concept is
Progress
Estimated14 minsto complete
%
Conditional Probability

Conditional Probability

What if the probability of a second event is affected by the probability of the first event? This type of probability calculation is known as conditional probability.

When working with events that are conditionally probable, you are working with 2 events, where the probability of the second event is conditional on the first event occurring. Say, for example, that you want to know the probability of drawing 2 kings from a deck of cards. As we have previously learned, here is how you would calculate this:

\begin{align*}P(\text{first king}) &= \frac{1}{13}\\ P(\text{second king}) &= \frac{3}{51}\\ P(\text{2 kings}) &= \frac{1}{13} \times \frac{3}{51}\\ P(\text{2 kings}) &= \frac{3}{663}\\ P(\text{2 kings}) &= \frac{1}{221}\\\end{align*}

Now let’s assume you are playing a game where you need to draw 2 kings to win. You draw the first card and get a king. What is the probability of getting a king on the second card? The probability of getting a king on the second card can be thought of as a conditional probability. The formula for calculating conditional probability is given as:

\begin{align*}P(B | A) &= \frac{P(A \cap B)}{P(A)}\\ P(A \cap B) &= P(A) \times P(B | A)\end{align*}

Another way to look at the conditional probability formula is as follows. Assuming the first event has occurred, the probability of the second event occurring is:

\begin{align*}P(\text{second event} | \text{first event})=\frac{P(\text{first event and second event})}{P(\text{first event})}\end{align*}

Let’s work through a few problems using the formula for conditional probability.

Using the Formula for Conditional Probability

1. You are playing a game of cards where the winner is determined when a player gets 2 cards of the same suit. You draw a card and get a club \begin{align*}(\clubsuit)\end{align*}. What is the probability that the second card will be a club?

Step 1: List what you know.

First event = drawing the first club

Second event = drawing the second club

\begin{align*}P(\text{first club}) &= \frac{13}{52}\\ P(\text{second club}) &= \frac{12}{51}\\ P(\text{club and club}) &= \frac{13}{52} \times \frac{12}{51}\\ P(\text{club and club}) &= \frac{156}{2,652}\\ P(\text{club and club}) &= \frac{1}{17}\end{align*}

Step 2: Calculate the probability of choosing a club as the second card when a club is chosen as the first card.

\begin{align*}\text{Probability of drawing the second club} &= \frac{P(\text{club and club})}{P(\text{first club})}\\ P(\text{club} | \text{club}) &= \frac{\frac{1}{17}}{\frac{13}{52}}\\ P(\text{club} | \text{club}) &= \frac{1}{17} \times \frac{52}{13}\\ P(\text{club} | \text{club}) &= \frac{52}{221}\\ P(\text{club} | \text{club}) &= \frac{4}{17}\end{align*}

Therefore, the probability of selecting a club as the second card when a club is chosen as the first card is 24%.

2. In the next round of the game, the first person to be dealt a black ace wins the game. You get your first card, and it is a queen. What is the probability of obtaining a black ace?

Step 1: List what you know.

First event = being dealt the queen

Second event = being dealt the black ace

\begin{align*}P(\text{queen}) &= \frac{4}{52}\\ P(\text{black ace}) &= \frac{2}{51}\\ P(\text{black ace and queen}) &= \frac{4}{52} \times \frac{2}{51}\\ P(\text{black ace and queen}) &= \frac{8}{2,652}\\ P(\text{black ace and queen}) &= \frac{2}{663}\end{align*}

Step 2: Calculate the probability of choosing black ace as a second card when a queen is chosen as a first card.

\begin{align*}P(\text{black ace}|\text{queen}) &= \frac{P(\text{black ace and queen})}{P(\text{queen})}\\ P(\text{black ace} | \text{queen}) &= \frac{\frac{2}{663}}{\frac{4}{52}}\\ P(\text{black ace} | \text{queen}) &= \frac{2}{663} \times \frac{52}{4}\\ P(\text{black ace} | \text{queen}) &= \frac{104}{2,652}\\ P(\text{black ace} | \text{queen}) &= \frac{2}{51}\end{align*}

Therefore, the probability of selecting a black ace as the second card when a queen is chosen as the first card is 3.9%.

Calculating Probability

Sandra went out for her daily run. She goes on a path that has alternate routes to give her a variety of choices to make her run more enjoyable. The path has 3 turns where she can go left or right at each turn. The probability of turning right the first time is \begin{align*}\frac{1}{2}\end{align*}. Based on past runs, the probability of turning right the second time is \begin{align*}\frac{2}{3}\end{align*}. Draw a tree diagram to represent the path. What is the probability that she will turn left the second time after turning right the first time?

Step 1: List what you know.

\begin{align*}P(\text{right the first time}) &= \frac{1}{2}\\ P(\text{right the second time}) &= \frac{2}{3}\\ P(\text{left the second time}) &= 1 - \frac{2}{3} = \frac{1}{3}\\ P(\text{right the first time and left the second time}) &= \frac{1}{2} \times \frac{1}{3}\\ P(\text{right the first time and left the second time}) &= \frac{1}{6}\end{align*}

Step 2: Calculate the probability of choosing left as the second turn when right is chosen as the first turn.

\begin{align*}P(\text{left the second time} | \text{right the first time}) &= \frac{P(\text{right the first time and left the second time})}{P(\text{right the first time})}\\ P(\text{left the second time} | \text{right the first time}) &= \frac{\frac{1}{6}}{\frac{1}{2}}\\ P(\text{left the second time} | \text{right the first time}) &= \frac{1}{6} \times \frac{2}{1}\\ P(\text{left the second time} | \text{right the first time}) &= \frac{2}{6}\\ P(\text{left the second time} | \text{right the first time}) &= \frac{1}{3}\\ P(\text{left the second time} | \text{right the first time}) &= 0.33\overline{3}\\ P(\text{left the second time} | \text{right the first time}) &= 33\%\end{align*}

Therefore, the probability of choosing left as the second turn when right was chosen as the first turn is 33%.

Example

Example 1

At Bluenose High School, 90% of the students take Physics and 35% of the students take both Physics and Statistics. What is the probability that a student from Bluenose High School who is taking Physics is also taking Statistics?

Step 1: List what you know.

\begin{align*}P(\text{physics}) &= 0.90\\ P(\text{physics and statistics}) &= 0.35\end{align*}

Step 2: Calculate the probability of choosing Statistics as a second course when Physics is chosen as a first course.

\begin{align*}P(\text{statistics} | \text{physics}) &= \frac{P(\text{physics and statistics})}{P(\text{physics})}\\ P(\text{statistics} | \text{physics}) &= \frac{0.35}{0.90}\\ P(\text{statistics} | \text{physics}) &= 0.388\\ P(\text{statistics} | \text{physics}) &= 39\%\end{align*}

Therefore, the probability that a student from Bluenose High School who is taking Physics is also taking Statistics is 39%.

Review

1. 2 fair dice are rolled. What is the probability that the sum is even given that the first die that is rolled is a 2?
2. 2 fair dice are rolled. What is the probability that the sum is even given that the first die rolled is a 5?
3. 2 fair dice are rolled. What is the probability that the sum is odd given that the first die rolled is a 5?
4. Steve and Scott are playing a game of cards with a standard deck of playing cards. Steve deals Scott a black king. What is the probability that Scott’s second card will be a red card?
5. Sandra and Karen are playing a game of cards with a standard deck of playing cards. Sandra deals Karen a red seven. What is the probability that Karen’s second card will be a black card?
6. Donna discusses with her parents the idea that she should get an allowance. She says that in her class, 55% of her classmates receive an allowance for doing chores, and 25% get an allowance for doing chores and are good to their parents. Her mom asks Donna what the probability is that a classmate will be good to his or her parents given that he or she receives an allowance for doing chores. What should Donna's answer be?
7. At a local high school, the probability that a student speaks English and French is 15%. The probability that a student speaks French is 45%. What is the probability that a student speaks English, given that the student speaks French?
8. At a local high school, the probability that a student takes statistics and art is 10%. The probability that a student takes art is 65%. What is the probability that a student takes statistics, given that the student takes art?
9. The test for a disease is accurate 80% of the time, and 2.5% of the population has the disease. What is the probability that you have the disease, given that you tested positive?
10. For question 9, what is the probability that you don't have the disease, given that you tested negative?

Notes/Highlights Having trouble? Report an issue.

Color Highlighted Text Notes

Vocabulary Language: English Spanish

TermDefinition
conditional probability The probability of a particular dependent event  given the outcome of the event on which it occurs.
conditional probability formula The conditional probability formula is P(A/B) = P(AUB)/P(B)
Dependent Events In probability situations, dependent events are events where one outcome impacts the probability of the other.
Favorable Outcome A favorable outcome is the outcome that you are looking for in an experiment.
Independent Events Two events are independent if the occurrence of one event does not impact the probability of the other event.
Multiplication Rule States that for 2 events (A and B), the probability of A and B is given by: P(A and B) = P(A) x P(B).
Mutually Exclusive Events Mutually exclusive events have no common outcomes.
Sample Space In a probability experiment, the sample space is the set of all the possible outcomes of the experiment.


text:
# Basic limits of rational functions: behavior near vertical asymptotes

1. Aug 9, 2011

### Dr. Seafood

1. The problem statement, all variables and given/known data

We are required to sketch a (reasonably accurate) picture of a rational function f(x) = P(x)/Q(x) with P, Q polynomials in x and Q nonzero. We know that the roots of Q(x) are, say, x1, x2, etc. and so f(x) is (typically) asymptotic to the vertical lines x = xk for each k.

We want $$\lim_{x \rightarrow {x_{k}}^{\pm}} f(x)$$ for each xk. Note that we need the limiting behavior of f(x) for x < xk and x > xk, separately, in order to accurately sketch the behavior of f(x) near these vertical asymptotes. That's a total of 2k limits we need to solve, though they are each very similar.

I'm a tutor and so I need to present the solution of this to my student. But it kinda sucks that I don't know how to evaluate this kind of simple one-sided limit problem off hand. I'm pretty sure that there's some algebra trick we can use to express the rational function in a different form that makes the limit easy to evaluate using the typical "limit laws".

I don't want to have to go all ϵ-δ on my student though :p He knows the formal definition of "limit", but I feel that we don't need to refer to it to evaluate limits of rational functions because we've already proven the limit laws.

For example, say $$f(x) = {x^3 - 3x^2 - 4x + 12 \over x^2 - 1}$$ Since the roots of x2 - 1 are x = ±1, we want the following limits:

$$\lim_{x \rightarrow {1}^{+}} {x^3 - 3x^2 - 4x + 12 \over x^2 - 1} \qquad \lim_{x \rightarrow {1}^{-}} {x^3 - 3x^2 - 4x + 12 \over x^2 - 1}$$
$$\lim_{x \rightarrow {(-1)}^{+}} {x^3 - 3x^2 - 4x + 12 \over x^2 - 1} \qquad \lim_{x \rightarrow {(-1)}^{-}} {x^3 - 3x^2 - 4x + 12 \over x^2 - 1}$$

3. The attempt at a solution

$$\lim_{x \rightarrow {1}^{+}} {x^3 - 3x^2 - 4x + 12 \over x^2 - 1} = \infty$$ To show this, I suppose I can argue by evaluating the expression for numbers close to (but greater than) x = 1 and observing the quantity is large and positive. So we can "plug in" x = 1.1, 1.01, 1.001, etc. into the limiting expression and see that it grows without bound. But this is not very rigorous/formal at all.

Also, this is just a "sub-problem" in the larger problem of trying to sketch the graph of this curve. I don't want to have to make these kinds of tedious numerical arguments when presenting the reasoning here; it will just get in the way of the larger problem.

Isn't there a better way to quickly have the solution here? I feel like this a pretty typical elementary limit problem.

Last edited: Aug 9, 2011
2. Aug 9, 2011

### Harrisonized

Expand it using partial fractions. To do that, first use long division.

Last edited: Aug 9, 2011
3. Aug 9, 2011

### Dr. Seafood

^ How do you do that when the degree of the P(x) is greater than that of Q(x)?

4. Aug 9, 2011

....

5. Aug 9, 2011

### Dr. Seafood

Okay I just suck at reading. I'm still stuck though, honestly your post is too vague to help. Can you be more specific to the example I gave above?

6. Aug 9, 2011

### Harrisonized

[PLAIN]http://img26.imageshack.us/img26/9818/longdivision07.gif [Broken]

Last edited by a moderator: May 5, 2017
7. Aug 9, 2011

8. Aug 9, 2011

### Dr. Seafood

@Harrisonized: Great. Why are you even posting if you're just going to be a dick?

@Bohrok: Well, I already know how to do that. I just don't see how it will help.

Anyway, it's not like I didn't try division or partial fractions before you mentioned that. I get this far:

$${x^3 - 3x^2 - 4x + 12 \over x^2 - 1} = x - 3 - {3 \over {x + 1}} + {6 \over {(x + 1)(x - 1)}}$$

Writing the last term in partial fractions and simplifying:

$${x^3 - 3x^2 - 4x + 12 \over x^2 - 1} = x - 3 + {3 \over {x - 1}} - {6 \over x + 1}$$

Now what do I write, specifically, to show

$$\lim_{x \rightarrow 1^{+}} {x^3 - 3x^2 - 4x + 12 \over x^2 - 1} = \lim_{x \rightarrow 1^{+}} (x - 3 + {3 \over {x - 1}} - {6 \over x + 1}) = \infty$$

Do I have to use a trick like, let $t = x - 1$ so that $t \rightarrow 0^+$ as $x \rightarrow 1^+$? Even then, won't I end up with an expression such as $1 - \infty$? It seems really informal to just claim that this is the same as $\infty$.

Even in a simpler example such as $\lim_{x \rightarrow 0^+} ({x^2 - 1 \over x})$, we can write ${x^2 - 1 \over x} = {x - {1 \over x}}$ and still be ****ed to write something informal like "when x is small and x > 0, we have a small number minus a large number, which is a large negative number, so $\lim_{x \rightarrow 0^+} {x - {1 \over x}} = -\infty$".

Last edited: Aug 9, 2011
9. Aug 9, 2011

### Bohrok

Well usually with problems like this, I would make intervals using zeros and points where the function is undefined as the boundaries between them, then use test points to determine whether that interval is positive or negative; I haven't tried it on this problem, but it should help.

One thing about doing the long division is that you can see that the last two terms tend to 0 as x → ∞,
$$x - 3 + {3 \over {x - 1}} - {6 \over x + 1} \approx x - 3$$
for large x, so you know the function kind of looks like x - 3.

10. Aug 9, 2011

### Harrisonized

Because you're a tutor. You're supposed to know this stuff unless you want to screw over your students. And unless my eyes deceive me, you also say you're an undergrad in pure mathematics. This is the kind of material people learn long before delta-epsilon limit definitions, and it has parallels to elementary school days.

Now listen up:

Anything + ∞ = +∞
Anything - ∞ = -∞

∞ is so large that it makes everything else negligible. Only ∞ can match itself, and when that happens, you either get ∞ again or you get an indeterminate form.

11. Aug 9, 2011

### Dr. Seafood

"Anything + infinity" = "infinity"? That's exactly the kind of informality I'm trying to avoid here. I know what you just said about "anything plus infinity" is intuitive. The question I've been asking since the OP was how to make that a little less silly.

Of course I learned this far before I learned epsilon-delta definitions. But I was presented this in its highschool-esque "anything + infinity = infinity" form, which is not the way I want to present it to my student. You don't have to tell me that I should be prepared for my students. I know that. That's why I'm asking about here, it so I can be prepared when I teach.

12. Aug 9, 2011

### Hurkyl

Staff Emeritus
It's not silly. Not only is this the way you should be thinking about it, but it's literally true. (also important is that x+y is continuous at $(x,y) = (a,+\infty)$ whenever $a \neq -\infty$)

Introducing the extended real numbers is one of the first things a real analysis text would do. (and honestly, I'm somewhat perplexed as to why they're not introduced in one's first calculus class if not before)

Even if you don't use the extended real numbers, you would still mimic them with limit laws, such as
If $\lim f(x) = a$ (for a finite a) and $\lim g(x) = +\infty$, then $\lim f(x) + g(x) = +\infty$

Honestly, how to use estimates and approximations are one of the major skills one is supposed to learn in calculus. You already split the fraction into parts and completely analyzed each term. (three are bounded, and one converges to $+\infty$) -- the rest of the argument is very short. Something like:

Let N > 0.
Choose delta so that if 1 < x < 1 + delta, then the big term is bigger than N + 100, and the other terms are each individually less than 10 in magnitude. Thus, their sum is bigger than N.

Last edited: Aug 9, 2011
13. Aug 9, 2011

### Dr. Seafood

This makes more sense. I could stop to prove this result and then move on. Still, without the hyperreals, statements like "one minus infinity" don't really make much sense, formally speaking. That's what I meant by "silly". We're talking about an elementary calculus student, and a science major at that, so there's no point introducing something like the extended reals. I've already pushed it by bothering to show him epsilon-delta definitions instead of making the limit an intuitive statement. But by that logic, an argument like "a fixed positive number minus a large positive number is a large negative number" should suffice then.

I taught epsilon-delta to this particular student, but I meant that for this one portion of the problem, I didn't want to have to break it up into small bits that each take a (relatively) long time to show, i.e. I'd have to find the limit from first definitions. A tool that makes it very simple to take the one-sided limits in this problem would be very useful.

14. Aug 10, 2011

### Hurkyl

Staff Emeritus
The hyperreals are not what I was talking about....

The extended reals are part of elementary calculus. The only question is whether you acknowledge them as a number system, or if you find ad hoc ways to talk around them -- e.g. talking about "limit forms", or replicating their arithmetic in the form of limit laws.

You're doing it wrong. You don't find the small bits from first definitions -- you find them in efficient ways. Then you use first definitions to convert that calculation into something you can use.

First, compute $\lim_{x \to 1} x - 3 - 6/(x+1) = -5$ (by your favorite means)
Now, because we have this fact, for any value A < -5 we can say there exists a $\delta$ such that
If $1 < x < 1 + \delta$, then $A < x - 3 - 6/(x+1)$

Second, compute $\lim_{x \to 1^+} 3/(x-1) = +\infty$ (by your favorite means)

Now, let N be a real number.
By the above computations, there exists $\delta > 0$ such that
• If $1 < x < 1 + \delta$, then $-10 < x - 3 - 6/(x+1)$
• If $1 < x < 1 + \delta$, then $N + 10 < 3/(x-1)$
If $1 < x < 1 + \delta$, then $N < {x^3 - 3x^2 - 4x + 12 \over x^2 - 1}$
And this is exactly what we needed to do to prove $\lim_{x \rightarrow {1}^{+}} {x^3 - 3x^2 - 4x + 12 \over x^2 - 1} = +\infty$.

format: plain


text:
# Consider the curve in the plane given in polar coordinates by r=4\sin \theta. Find t

usagirl007A 2021-08-22 Answered
Consider the curve in the plane given in polar coordinates by $$\displaystyle{r}={4}{\sin{\theta}}$$. Find the cartesian equation for the curve and identify the curve

### Expert Community at Your Service

• Live experts 24/7
• Questions are typically answered in as fast as 30 minutes
• Personalized clear answers

### Solve your problem for the price of one coffee

• Available 24/7
• Math expert for every subject
• Pay only if we can solve it

## Expert Answer

Aamina Herring
Answered 2021-08-23 Author has 15244 answers

Given information:

### Expert Community at Your Service

• Live experts 24/7
• Questions are typically answered in as fast as 30 minutes
• Personalized clear answers

### Solve your problem for the price of one coffee

• Available 24/7
• Math expert for every subject
• Pay only if we can solve it
...


text:
# The Simple Theorem of Numbers

### The Simple Theorem of Numbers

This is a simple proof that each real number undergoing a normal operation is equal to a real number.

$\sqrt{-1} = \sqrt{-(1)} = \sqrt{-(\sqrt{1})^{2}}$

Since,

$\sqrt{x^{y}} = \sqrt{x}^{y}$

Then,

$\sqrt{-(\sqrt{1})^{2}} = \sqrt{-(\sqrt{1})}^{2}$

Thus,

$\sqrt{-1} = -\sqrt{1} = -1$

Or generally,

$\sqrt{-n} = -\sqrt{n}$
lyoungb3

Posts: 1
Joined: Wed Jul 25, 2018 11:32 am
Reputation: 1


text:
#### Vol. 2, 2019

 Recent Volumes 2: ANTS XIII 1: ANTS X
 The Open Book Series About the Series Ethics Statement Other MSP Publications
Generating subgroups of ray class groups with small prime ideals

### Benjamin Wesolowski

Vol. 2 (2019), No. 1, 461–478
##### Abstract

Explicit bounds are given on the norms of prime ideals generating arbitrary subgroups of ray class groups of number fields, assuming the extended Riemann hypothesis. These are the first explicit bounds for this problem and are significantly better than previously known asymptotic bounds. Applied to the integers, they express that any subgroup of index $i$ of the multiplicative group of integers modulo $m$ is generated by prime numbers smaller than $16{\left(ilogm\right)}^{2}$, subject to the Riemann hypothesis. Two particular consequences relate to mathematical cryptology. Applied to cyclotomic fields, they provide explicit bounds on generators of the relative class group, needed in some previous work on the shortest vector problem on ideal lattices. Applied to Jacobians of hyperelliptic curves, they allow one to derive bounds on the degrees of isogenies required to make their horizontal isogeny graphs connected. Such isogeny graphs are used to study the discrete logarithm problem on said Jacobians.

##### Keywords
class group, ray class group, prime ideal, isogeny graph
##### Mathematical Subject Classification 2010
Primary: 11R29
Secondary: 11M06, 11R37, 14K02


text:
# How is multiplication in field $GF(2^{8})$ done?

I am working on AES and I am stuck on multiplication in $GF(2^{8})$ field.

In terms of polynomial it is easy; I just have to multiply polynomials modulo $(x^{8} + x^{4} + x^{3} + x + 1)$. But I do not understand multiplication with $x$, following an example given in NIST specification:

{57} • {13} = {fe}

solution:

{57} • {02} = xtime({57}) = {ae}
{57} • {04} = xtime({ae}) = {47}
{57} • {08} = xtime({47}) = {8e}
{57} • {10} = xtime({8e}) = {07},

thus

{57} • {13} = {57} • ({01} $XOR$ {02} $XOR$ {10})
= {57} $XOR$ {ae} $XOR$ {07}
= {fe}

I am unable to understand a single step in this, please also explain the x_time() function too.

Also, how is $x^{i}$ calculated? I need this for the $rcon[i]$ matrix.

Edit: this question has been marked as a possible duplicate of Understanding multiplication in the AES specification. I have already read this but the explanation is not sufficient, I am unable to understand the concept hence I have posted this question, because I need a somewhat detailed answer.Thanks.

• Possible duplicate of Understanding multiplication in the AES specification – kodlu May 17 '18 at 22:47
• @kodlu I've checked this already, the answer you mentioned. But it didn't solved the problem, I can't understand the given explanation. Hence, I posted this question here. – Nilesh May 18 '18 at 4:07
• To clarify: when you say I am unable to understand a single step in this, please also explain the x_time() function too. – do you mean you have general problems with the basic math used there and expect answers to go though it step-by-step, or are you just having problems understanding what x_time() means/does? – e-sushi May 19 '18 at 8:59
• @e-sushi, I'm having problems with both, I can implement x_time() just by it's definition but the question I mentioned in the post, I can't understand the steps, e.g. {57} • {13} = {57} • {13} = {57} • ({01} XOR XOR {02} XOR XOR {10}) how this is inferred from the steps above it. – Nilesh May 19 '18 at 10:59

Consider we want to obtain $\mathtt{0x57} \cdot \mathtt{0x02}$. First we see this one by polynomial method $$\begin{array}{lcl}\tag{3} \mathtt{0x57} \cdot \mathtt{0x02}&=&(01010111)_2 \cdot (00000010)_2\\ &=&({x}^{6}+{x}^{4}+{x}^{2}+x+1)\cdot x\\ &=&{x}^{7}+{x}^{5}+{x}^{3}+x^2+x \\ &=& (10101110)_2\\ &=& \mathtt{0xAE} \end{array}$$ The relation $(3)$ means that when an element of $\alpha \in\operatorname{GF}(2^8)$ multiplied by an element $\mathtt{0x02}$ we shift the binary mode of $\alpha$ in the left side.
Now, if the first bit (from left) of $\alpha$ is $1$ we should $\operatorname{XOR}$ the results with $\mathtt{0x1B}= (00011011)_2$ since when the first bit is $1$, it means we have $x^7$ in the representation of $\alpha$ and by multiplying by $x$ we get $x^8$ and we use the polynomial $x^4+x^3+x+1$ instead of $x^8$ in our calculation.
We call this operation x_time(). For instance, let we want to get $\mathtt{0x57} \cdot \mathtt{0x04}$. The element $\mathtt{0x04}=(00000100)_2$ is equal to $x^2$. Therefor to obtain $\mathtt{0x57} \cdot \mathtt{0x04}$ we use the function x_time() two times. In $(3)$ we got $\mathtt{0x57} \cdot \mathtt{0x02}=\mathtt{0xAE}$.
In the rest, to obtain $\mathtt{0xAE} \cdot \mathtt{0x02}$, first we shift the binary mode of $\mathtt{0xAE}=(10101110)_2$ in the left side that implying that $$(10101110)_2 \stackrel{shift\, to\, left}{\Longrightarrow} (01011100)_2 \tag{4}$$ The first bit of $\mathtt{0xAE}=(10101110)_2$ is $1$ and hence we $\operatorname{XOR}$ the result obtained in $(4)$, with $(00011011)_2$ as follows $$(01011100)_2 \quad \operatorname{XOR}\quad (00011011)_2=(01000111)_2=71=\mathtt{0x47}$$ I suggest you to obtain other cases as an exercise.


text:
# How is the atom selection going wrong when creating the collective variable?

I'm trying to create a CV for angle theta. To make this calculation, the right atom selections need to be made. The function is given below:

def theta_(traj):
angI = mdtraj_topology.select('resid ' + residA + dicACGT['A'])
angII = mdtraj_topology.select('resid ' + residA + ' and name P OP1 OP2 or resid ' + str(int(residA) - 1) + ' and name P OP1 OP2')

subIIIa = mdtraj_topology.select('resid ' + str(int(residA) - 1) + dicACGT[neighbors[0]])
subIIIb = mdtraj_topology.select('resid ' + str(int(residA) + 1) + dicACGT[neighbors[1]])
subIIIc = mdtraj_topology.select('resid ' + str(int(residT) - 1) + dicACGT[neighbors[2]])
subIIId = mdtraj_topology.select('resid ' + str(int(residT) + 1) + dicACGT[neighbors[3]])

angIII = np.concatenate((subIIIa, subIIIb, subIIIc, subIIId))
outputI = get_center_of_mass(traj, angI)
outputII = get_center_of_mass(traj, angII)
outputIII = get_center_of_mass(traj, angIII)
return(angIII)

thta=[]
for f in range(traj.n_frames):
vec1 = np.subtract(outputI[f], outputII[f])
vec2 = np.subtract(outputIII[f], outputII[f])
thta.append(angle_between_vectors(vec1,vec2))
#return(thta)

coms = paths.MDTrajFunctionCV('theta_',
theta_,
topology = engine.topology)

The atom selection (for variables angI, andII, subIIIa, subIIIb, subIIIc, subIIId), however, varies when I check with MDTraj trajectory which gives the right selection.

Selection with MDTraj trajectory

n = trajs[0].to_mdtraj()
theta_(n)

array([ 43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,
56, 107, 108, 109, 110, 111, 112, 114, 116, 120, 121, 202, 203,
204, 205, 207, 211, 212, 213, 264, 265, 266, 267, 268, 269, 270,
271, 272, 273, 274, 275, 276, 277])

Selection from OPS wrapper:

coms(trajs[0])

array([43, 44, 45, 46, 47, 48, 49, 50])

The angle calculation as a consequence fails as well when creating the CV. I think I might be missing an argument to the wrapper. How do I make the right selection?

I can't tell why you're getting that specific difference, but most likely it's related to the fact that the CV is using global variables. It's possible that something changed in those globals. OPS CVs shouldn't use global variables, and in fact, you'll get an error if you try to save a CV that uses global variables.

## CVs shouldn't use globals

The theta_ function you give uses the global variables mdtraj_topology, residA, residT, dicACGT, and neighbors. It also uses the function get_center_of_mass (and, if the early return is removed, angle_between_vectors ). There are all defined in global scope, and the OPS CVs don't save their global scope. If you somehow changed the values in the globals, that would explain the error. You would also get an error warning you about this if you tried to save your CV.

For more background, here's an article on scope in Python. The function wrapped by an OPS CV will not know about anything defined in global scope.

In general, the way to handle this is to pass these as additional variables to your theta_ function, and freeze them with keyword arguments when creating your CV:

def theta_(traj, mdtraj_topology, residA, residT, dicACGT,
neighbors, get_center_of_mass, angle_between_vectors):
...  # fill in your stuff here

coms = paths.MDTrajFunctionCV(
'theta_',
theta_,
topology=engine.topology,
mdtraj_topology=mdtraj_topology,
residA=residA,
residT=residT,
dicACGT=dicACGT,
neighbors=neighbors,
get_center_of_mass=get_center_of_mass,
angle_between_vectors=angle_between_vectors
)

For the specific case of atom index selection, however, it's probably better to do that outside the CV (although we'll use the same idea of passing additional parameters as keywords).

## Recommended approach: Do the selection outside the CV

Right now, you're doing the selection inside the CV. In most cases, that's not what you would want. Keep in mind that a given CV instance is already tied to a specific topology, so the atom indices you select will always be the same. To handle selections from different topologies, you can create multiple CV instances that wrap the same function.

So I'd recommend doing the selection outside the function, before creating your CV. This avoids problems with the different globals affecting your selections, because you provide a constant selection to your CV.

You could define your theta_ function as:

def theta_(traj, angI, angII, angIII, get_center_of_mass, angle_between_vectors):
...  # start after the selection

# fill these in, or create functions to extract them
angI = ...
angII = ...
angIII = ...

This also allows you to validate the indices you selected, so you're sure you have the right selection before you start your simulation.

Next you'll give angI, angII, and angIII as parameters that you freeze when you create the CV. Note that (just as above) you'll also need to pass functions that you'll use (such as get_center_of_mass) as parameters.

coms = paths.MDTrajFunctionCV(
'theta_',
theta_,
topology=engine.topology,
angI=angI,
angII=angII,
angIII=angIII,
get_center_of_mass=get_center_of_mass,
angle_between_vectors=angle_between_vectors
)

• It works now when I make the selection outside the function. However, I'm not able to return the theta values at the end with the wrapper but the function works when used with an MDTraj trajectory. I still think there's something missing with how I call the data with the wrapper. The error I get says: 'AttributeError: 'list' object has no attribute 'shape'' Aug 21 at 9:27


text:
QUESTION

# I'm not very good with algebra,or equations and s

I'm not very good with algebra,or equations and seek to find some help online. I don't know if equations will be on the test but i seek to find help with mostly things that will be on the test.

• @
Tutor has posted answer for $10.00. See answer's preview$10.00


text:
# Function of Maximum and Minimum Functions of Two Functions

I try to answer this question The Maximum and Minimum Functions of Two Functions

I wrote the following code

f[x_, y_] := 1 + 2*x + 3*y^3
g[x_, y_] := y + x^2
maxi[x_, y_] :=
Refine[{(f[x, y] + g[x, y])/2 + Abs[f[x, y] - g[x, y]]/2},
Assumptions -> {0 <= x <= 1, 0 <= y <= 1}]
Plot3D[maxi[x, y], {x, 0, 1}, {y, 0, 1}]

Is there any way to find function of maxi?

Try

Simplify[(f[x, y] + g[x, y])/2 + Abs[f[x, y] - g[x, y]]/2,0<=x<=1&&0<=y<=1]

which instantly returns

1+2 x+3 y^3

You can see that by inspection because f[x,y]>g[x,y] over the domain so the Abs does nothing and disappears and that leaves f[x,y]/2+g[x,y]/2+f/x,y]/2-g[x,y]/2==f[x,y]

• Many thanks. But your answer does not work for: f[x_] := x^2 and g[x_] := 1 - x, maxi1[x_] = Refine[{(f[x] + g[x])/2 + Abs[f[x] - g[x]]/2}, Assumptions -> {0 <= x <= 1}]; and Simplify[maxi1[x], 0 <= x <= 1]. Nov 14, 2019 at 20:52
• @bahram If you change the question then the answer usually changes. Try this for your new f and g: f[x_] := x^2; g[x_] := 1 - x; list={{f[x],Reduce[f[x]>=g[x]&&0<=x<=1,x]}, {g[x],Reduce[f[x]<=g[x]&&0<=x<=1,x]}}; Piecewise[list] which gives you a Piecewise function that is the maximum of f and g over the domain. The minimum can be obtained in the same way. But I suspect this answer will not be satisfactory for you either.
– Bill
Nov 15, 2019 at 7:11


text:
Thank you for visiting nature.com. You are using a browser version with limited support for CSS. To obtain the best experience, we recommend you use a more up to date browser (or turn off compatibility mode in Internet Explorer). In the meantime, to ensure continued support, we are displaying the site without styles and JavaScript.

# The epidemiological impact of the NHS COVID-19 app

## Abstract

The COVID-19 pandemic has seen the emergence of digital contact tracing to help to prevent the spread of the disease. A mobile phone app records proximity events between app users, and when a user tests positive for COVID-19, their recent contacts can be notified instantly. Theoretical evidence has supported this new public health intervention1,2,3,4,5,6, but its epidemiological impact has remained uncertain7. Here we investigate the impact of the National Health Service (NHS) COVID-19 app for England and Wales, from its launch on 24 September 2020 to the end of December 2020. It was used regularly by approximately 16.5 million users (28% of the total population), and sent approximately 1.7 million exposure notifications: 4.2 per index case consenting to contact tracing. We estimated that the fraction of individuals notified by the app who subsequently showed symptoms and tested positive (the secondary attack rate (SAR)) was 6%, similar to the SAR for manually traced close contacts. We estimated the number of cases averted by the app using two complementary approaches: modelling based on the notifications and SAR gave an estimate of 284,000 (central 95% range of sensitivity analyses 108,000–450,000), and statistical comparison of matched neighbouring local authorities gave an estimate of 594,000 (95% confidence interval 317,000–914,000). Approximately one case was averted for each case consenting to notification of their contacts. We estimated that for every percentage point increase in app uptake, the number of cases could be reduced by 0.8% (using modelling) or 2.3% (using statistical analysis). These findings support the continued development and deployment of such apps in populations that are awaiting full protection from vaccines.

## Main

The United Kingdom has been severely affected by the COVID-19 pandemic, recording one of the highest confirmed death rates in the world in 2020. The NHS COVID-19 app for England and Wales was launched on 24 September 2020 to help to reduce the spread of the virus. The app has been downloaded on 21 million unique devices, out of a population of 34.3 million eligible people with compatible smartphones, and is regularly used by at least 16.5 million people. The main function of the app is digital contact tracing1,2,3,4,5,6 using the privacy-preserving Google Apple Exposure Notification system, which is embedded in the Android and iOS operating systems8,9, supplemented with custom Bluetooth processing algorithms10. App users are notified and instructed to quarantine if they have been in contact with another user later confirmed to have COVID-19 if the exposure had characteristics that exceed a risk threshold. Digital tracing is a novel public health measure with unknown epidemiological impact7. Other functions of the NHS app include providing locally appropriate information on COVID-19 prevention, checking into venues using a custom QR-code scanner (allowing later notification if users have visited risky venues), and a symptom checker linked to the booking of tests. For tests booked through the app, the test result triggers a set of actions automatically, including notification of the tested individual through the app and digital contact tracing for positive results (upon the user’s approval).

When installing the app, users enter their postcode district (the first half of the postcode), which enables analysis of geographical variation in app use. We aggregated data at the level of lower tier local authorities (LTLAs), of which there are 338 in England and Wales, to match case data. App uptake—the fraction of active users in the population—was variable between LTLAs (Fig. 1a, c), with an interquartile range of 24.2–32.4%. We defined three phases for the analysis, annotated in Fig. 1d: phase 0 before app launch, phase 1 from 1 October to early November 2020 (first version of the app) and phase 2 from early November to 31 December 2020 (improved version of the app). These are described in greater detail in Extended Data Table 1. Phases in the app precede phases in the resulting cases: there is a lag between changes in transmission rates and changes in confirmed cases, which we assumed to be 8 days. Other factors besides the app changed during these phases, including locally targeted control measures, a national lockdown and a surge in cases in December, mostly driven by the new SARS-CoV-2 variant B.1.1.7.

Roughly 1.7 million notifications were sent as a result of 560,000 app users testing positive over the entire time period: a mean number of notifications per index case of 3.1. Seventy-two per cent of app-using index cases consented to digital tracing upon testing positive, resulting in a mean number of notifications per tracing event of 4.2. Numbers of notifications over time are shown in Extended Data Fig. 1b.

We estimated the SAR in individuals notified by the app; this is the probability that someone who is notified will report a positive test during the recommended quarantine or in the following two weeks. We estimated an SAR of 6.02%, with confidence interval 5.96–6.09%, although sensitivity analyses suggest a precision of roughly 5–7%. These results indicate that the app is functioning at a technical level, as also recently demonstrated for the Swiss and Spanish apps11,12.

To evaluate the epidemiological impact of the app, we first used a modelling approach. We estimated the number of cases averted with a model linking the number of notifications, the probability that notified individuals had COVID-19, the timing of notification relative to transmission, and the adherence to quarantine. Adherence to quarantine is critical but difficult to assess reliably. UK surveys found that only 11% of individuals in quarantine declared proper adherence to quarantine rules, but 65% of individuals intended to adhere to quarantine13, albeit imperfectly. Recent surveys found a high adherence to quarantine (greater than 80%)14, and this behaviour may be more representative of app users. We considered an intermediate scenario corresponding to 61% overall effectiveness of quarantine in preventing transmissions as our central estimate, leading to 284,000 cases averted. The estimated number of cases averted was higher in areas of high app uptake (Fig. 2). The slope of the regression in Fig. 2b indicates that the fraction of cases averted (among all cases observed or averted) increased by 0.8% for 1% increase in app uptake (Table 1).

We used a second approach to evaluate the epidemiological impact of the app, linking variation in app uptake between LTLAs with variation in cumulative cases. We addressed strong confounding factors with a stratified approach, only comparing LTLAs with similar socio-economic properties and geography. We used several different ways of grouping LTLAs into comparable units, with similar results; one method is described below (with full results in Extended Data Table 2) and the other methods are described in the Supplementary Information (their results are presented in Extended Data Fig. 2, Extended Data Tables 3, 4).

Increased app use is associated with more rural areas, less poverty and greater local gross domestic product (GDP) (Supplementary Table 4); we therefore adjusted for these measured confounding variables. Unmeasured confounders could include adherence to social distancing and face-mask use; since these factors affected transmission before app release, app uptake should have some correlation with case numbers even before app release (phase 0). To test this, we regressed phase 0 case numbers on several covariates, including later uptake of the app; app uptake was indeed associated with case numbers (pure confounding). To adjust for this confounding, we stratified LTLAs into quintiles on the basis of the number of cases in phase 0 and compared them only within these strata. This stratification removed the correlation between app uptake and pre-app cases, indicating that this at least partially adjusted for unmeasured confounders (Extended Data Table 2; details on confounding and placebo regression are in the Supplementary Information). Case numbers in an LTLA are also confounded by those in neighbouring LTLAs; we therefore compared only neighbouring (adjacent) LTLAs. We found that the difference in case numbers per capita between neighbouring LTLAs, matched by phase 0 case number quintile, was strongly and robustly associated with differences in app use, regardless of adjustment for other demographic confounders (Fig. 2, Table 1, Extended Data Table 2).

Disaggregating the effect by phase, we found that it was larger during phase 2 (Table 1). This is consistent with the increased number of notifications sent per index case implemented at the start of phase 2 (Extended Data Fig. 1b). Table 1 shows the estimated effect size replicated in different statistical analyses (described in the Supplementary Information).

We estimated the numbers of cases averted during phases 1 and 2 combined: 284,000 (108,000–450,000) using the modelling approach, and 594,000 (317,000–914,000) using the statistical approach. The ranges show a sensitivity analysis exploring 2.5–97.5% of the variability in modelling estimates, and a 95% confidence interval for the statistical one. These estimates are comparable to the number of app users who tested positive and consented for notifications to be sent: roughly 400,000. This suggests that on average, each confirmed COVID-19-positive individual who consented to notification of their contacts through the app prevented one new case; that is, the whole transmission chain following each such case was reduced by one individual. We translated these estimates to deaths averted during phases 1 and 2 using the case fatality rate observed for this period: 1.47% (Methods). This gave an estimate of 4,200 (1,600–6,600) deaths averted using the modelling approach, and 8,700 (4,700–13,500) using the statistical approach. For comparison, the total number of cases and deaths that actually occurred in this period were 1,892,000 and 32,500, respectively. Cases averted over this period are shown in Extended Data Fig. 3.

Finally, we extrapolated the findings to explore different ways in which the app could be improved, by re-running scenarios with different parameters (Table 2). These are retrospective projections; however, the expected reductions in cases are relevant when considering forward projections.

## Discussion

Our analyses suggest that a large number of cases of COVID-19 were averted by contact tracing through the NHS app, with estimates ranging from approximately 100,000 to 900,000, depending on the details of the analysis. For comparison, there were 1.9 million actual cases of COVID-19 over the same period. Averted cases were concentrated in phase 2, during November and December 2020, after a major upgrade to the app’s risk-scoring function10. This finding is similar to previous results from modelling: using our individual-based model15, a 30% app uptake was estimated to avert approximately 1 infection for every 4 infections that arose4 during 4.5 months.

Although it is informative to estimate effects on quantities such as the time-varying reproduction number16, we did not pursue such an analysis here. The dynamics of the epidemic for individual LTLAs are difficult to interpret: the period of analysis coincided with staggered introductions of locally targeted restrictions, a short national lockdown, the Christmas holiday season and the emergence of the B.1.1.7 SARS-CoV-2 variant, which is more infectious and spread rapidly across the country17,18,19,20. Future work could perhaps model all of these effects in a single hierarchical model, permitting joint estimation of the app’s effects over LTLAs with linked drivers and dynamics. Our simpler approaches have the benefit of transparency, and we hypothesize that under negative-feedback dynamics (greater local spread triggering greater local control measures), appropriately constructed comparisons of total case counts over an appropriate period may reveal the underlying propensity for disease spread.

The main limitation of our analysis is that it is an observational study: no randomized or systematic experiment resulted in different rates of app uptake in different locations. Interpreting observational analyses requires particular care owing to the risk of confounding. We therefore used two approaches: mechanistically modelling the app’s function, and a statistical approach. Our statistical approach was stratified to focus only on differences between directly comparable areas, emulating how a cluster randomized trial would have been conducted21. Our placebo analysis suggested that our adjustment for confounders largely removed their effect; however, it is still possible that changes in app use over time and across geographies reflect changes in other interventions, and that our analysis incorrectly attributes the effects to the app. Such residual confounding, if present, would mean that our statistical estimate for cases averted is too high and thus our modelling estimate is more accurate. Conversely, there could be a genuine, albeit indirect effect of the app, whereby users maintain a greater distance from others than they otherwise would have done, being aware that the app monitors distance and could later advise quarantine. This would mean that our modelling estimate (derived solely from the app’s direct effect, proportional to the SAR) is too low, and that our statistical estimate is more accurate. On balance, an effect size between the two estimates seems most likely. We discuss the expected effects of further biases in the Supplementary Information.

The app is best understood as part of a system of non-pharmaceutical interventions, and not in isolation7. It is not a substitute for social distancing or face masks: control of the epidemic requires all available interventions to work together. Isolation and quarantine can only be effective when supported financially. All contact tracing requires identification of cases, and is therefore a follow-up to effective, widespread and rapid testing. The specific role of digital tracing is to speed up tracing, and to reach more people per index case. An advantage of the NHS app compared with other digital tracing apps is its full integration with testing: tests ordered through the app trigger actions automatically, without requiring the user to enter their results in the app. Further improvement could potentially be achieved with increased use of location-specific QR-code scanning: notifications were issued for 226 venue events designated as risky as of 20 January 2021. Backwards contact tracing22 could help to identify risky venue events. The COVID-19 response policy concerning the hospitality sector—restaurants, pubs and so on—required visitors to ‘check in’ to facilitate outbreak analysis when needed. Scanning the venue QR code with the app provided a more convenient way of doing this than writing the contact details of the individual, and hence individuals visiting such venues may have been more likely than average to use the app, giving a greater epidemiological effect than expected.

Digital tracing is not a substitute for manual tracing—both are valuable. We compare the two approaches in Supplementary Table 1. In summary, the SAR of 6% that we estimated for the app is similar to the SAR of 6.9% for manual contact tracing of close contacts during December 2020 and January 202123. The mean number of contacts traced per consenting index case was 4.2 for digital tracing, compared with 1.8 for manual tracing, and a larger fraction of these traced contacts is expected to be outside of the household of the index case for the app. Contacts outside the household have a smaller probability of having already been notified informally by the index case, and so obtain greater benefit of having been traced. This increased coverage and the speed of notification by the app (Extended Data Fig. 4) suggest that the effect of digital tracing was mostly additional to that of manual tracing. We confirmed this with an analysis that included adjustment for quality of manual tracing, which did not affect our conclusions.

The surest ways to increase the effectiveness of the digital tracing programme are to increase uptake of the app and to provide material support to individuals undergoing isolation and quarantine. Special efforts may be needed to reach underserved communities. It is well established that testing should be as rapid as possible to help to prevent transmission. This could perhaps be facilitated by point-of-care antigen tests and integration of self-testing with the app, however this would need investigation to establish accuracy and usability. Widespread vaccination will eventually reduce the need for non-pharmaceutical interventions, but vaccination is unlikely to achieve global reach within the coming months, during which time improved non-pharmaceutical interventions could still prevent many infections24,25. Smartphone use is already global, and thus privacy-preserving contact-tracing apps should be further integrated into the public health toolkit.

## Methods

No statistical methods were used to predetermine sample size. The experiments were not randomized. The investigators were not blinded to allocation during experiments and outcome assessment.

### Estimating app uptake

To monitor the safe function of the app and enable its evaluation, a limited amount of data are shared with a secure NHS server. Each active app sends a single data packet daily. The fields in these packets contain no sensitive or identifying information, and are approved and publicly listed by the Information Commissioner (https://www.gov.uk/government/publications/nhs-covid-19-app-privacy-information). The raw data fields we used are described in Supplementary Table 2; further variables derived from these are described in Supplementary Table 3. A schematic illustration of data gathering is shown in Extended Data Fig. 5. For the reported numbers of downloads, repeat downloads to the same phone are counted only once. The number of active users each day is defined as the number of data packets received by the NHS server; for a single representative value of this quantity, we took the mean over all days from 1 November to 11 December 2020 (earlier data was deemed less reliable). We note that there continue to be unexplained fluctuations in reported user numbers on Android phones. To estimate uptake within an LTLA, each postcode district was mapped to the LTLA in which the majority of its population reside, and we took the ratio (number of active users in postcode districts mapped to this LTLA)/(total population in postcode districts mapped to this LTLA). The population of England and Wales is 59.4 million, of whom 48.1 million are 16 or over and thus eligible to use the app (https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/lowersuperoutputareamidyearpopulationestimates). We assumed that England and Wales are representative of the UK, in which 82% of people aged 16 years and over have smartphones (OFCOM, personal communication), and that of smartphones in circulation, 87% support the Google Apple Exposure Notification system (Department of Health and Social Care, personal communication). The denominators for measuring uptake at the national level are therefore 59.4 million (total population) and 34.3 million (eligible population with compatible phones).

### Defining numbers of cases

The COVID-19 case numbers per day we used here are those reported at https://coronavirus.data.gov.uk/, by specimen date and LTLA. We obtained per-capita case numbers at the LTLA level by dividing by LTLA populations reported by ONS. These per capita case numbers by phase are shown in Extended Data Fig. 6. Testing has been available through the NHS Test and Trace system in all areas throughout the period, with a median delay of less than 2 days from booking a test to receiving the result. Testing capacity has mostly exceeded demand, except for two weeks in early September. We assumed that case ascertainment has been relatively constant over the period of analysis, an assumption qualitatively supported by the unbiased ONS and REACT studies26,27.

### Estimating the SAR

We focused on a period in December 2020 and January 2021 when the number of positive test results in app users could be disaggregated by whether the user had been recently notified or not. Even with this data, successive data packets sent by the same device are not linked to each other. This means that when a given number of notifications are sent on a particular day, the exact number of those individuals notified who later receive a positive test result is unknown, because of the lack of linkage over time. We therefore used a probabilistic model for how many positive test results we would expect among those recently notified, as a function of the number of notifications on previous days, of the estimated delay from notification to testing positive, and of the SAR. We estimated the SAR by maximising the likelihood of this model. In detail: let  fNP(t) be the probability that an individual notified on a given day then tests positive t days later (conditional on their testing positive at some later time, that is, the function is normalized to 1). Let N(t) be the number of individuals notified on day t, and IN(t) the number of individuals reporting a positive test on day t having been notified recently (either they are currently in the quarantine period recommended by the app, or the following 14 days). The number expected for the latter is  $${\rm{S}}{\rm{A}}{\rm{R}}\times \sum _{{t}^{{\prime} }\le t}{f}_{NP}(t-{t}^{{\prime} })N({t}^{{\prime} })$$, and we maximised a Poisson likelihood for the number observed, IN(t) (shown in Extended Data Fig. 1d), given the number expected, treating observations from different days as independent. The confidence interval was obtained by likelihood profiling; however, sensitivity analyses suggested greater uncertainty (see Supplementary Information).  fNP(t) was calculated as a convolution of the distributions for times from exposure to symptoms, from symptoms to testing positive, and from exposure to notification (Supplementary Information). Our SAR calculation used only data from iPhones, excluding Android phones, for more stable daily numbers of analysis packets.

### Statistical analysis

The main statistical analysis compared statistics for each LTLA, labelled x, to those of the set comprising all of its ‘matched’ neighbours N(x) = {n1, n2, n3,…, and so on}. The matched neighbours N(x) were defined as other LTLAs that share a border with x and were in the same quintile for number of cases per capita in phase 0. Distributions showing the variability between LTLAs in the number of neighbours and number of matched neighbours are shown in Supplementary Fig. 2. Stratification into quintiles (as opposed to deciles and so on) was chosen to balance power and sufficient adjustment; no other possibility was tried, to guard against investigator bias.

Each statistic of interest was averaged over the matched neighbours, weighting by population size, to obtain the mean value in the matched neighbours of x. This was compared to the statistic for x. Linear regression was carried out using, for each statistic of interest, the difference between its value in x and in its matched neighbours N(x). The statistics we considered were: per capita number of cases in each phase; the fraction of the population using the app; a measure of rural/urban mix on a scale from 1 to 5, from the Office of National Statistics (ONS); a measure of local GDP per capita from the ONS, adjusted for rural/urban score; and a measure of the fraction of the population living in poverty before housing costs, from the ONS.

Our main regression was

log(cumulative cases per capita in x) – log(cumulative cases per capita in N(x)) =

beta_rural_urban × (rural/urban score of x − rural/urban score of N(x)) +

beta_gdp_band × (local GDP band of x − local GDP band of N(x)) +

beta_poverty × (per cent of the population living in poverty in x – per cent of the population living in poverty in N(x)) +

beta_users × (per cent of the population using the app in x − per cent of the population using the app in N(x)) +

epsilon_residual

where the different data points for the regression (the different values of x) were the set of LTLAs with at least one matched neighbour, excluding LTLAs with no matched neighbours. Cumulative cases were considered in each of the three phases separately or with phases 1 and 2, as reported in our results. The values of the beta coefficients we estimated are shown in Extended Data Table 2. We used a logarithmic transform for the response variable in our regression, because cases are generated by an exponential process (transmission) and so the rate at which the number of cases varies with the dose of a treatment (that is, the extent of an intervention) is highly confounded with the absolute number of cases. A regression with quadratic effect of uptake and intercept at 0 produced very similar findings to the above regression with linear effect of uptake (not shown). We considered additional uncertainty in the regression due to redundancy in the differences approach, for example, in comparing both LTLA x with LTLA n and LTLA n with LTLA x, described in the bootstrapping section of Supplementary Information.

Predictions for cases averted were found using the regression coefficient beta_uptake to linearly extrapolate log(cumulative cases per capita) for each LTLA to that expected for an uptake of 15% (or keeping cases counts as they were, if uptake was already less than 15%). Here we assumed that there is negligible benefit of app uptake below 15% (though this is not expected to be the case in settings where usage is clustered into high-uptake communities29). The definition of beta_users in the regression equation above means it is the expected increase in log(cumulative cases per capita) associated with a one-percentage-point increase in app uptake, when keeping constant GDP, rural/urban mix, and level of poverty. Our central estimate of beta_users in this analysis was −0.023 for phase 1 and 2 combined; this means an increase in uptake of p percentage points is expected to be associated with an increase by the factor e−0.023p in the cumulative number of cases per capita in phases 1 and 2. An increase of p = 1 percentage points in uptake means a decrease of 2.3% in cases as we reported above. We estimated the number of deaths averted by multiplying the number of cases averted by the crude case fatality rate.

Alternative regressions are described in Supplementary Information; their results are in Extended Data Tables 3 and 4, and Extended Data Fig. 2.

### Case fatality rate

The case fatality rate was estimated as the ratio of total deaths (27,922) to cases (1,891,777) for phases 1 and 2 combined. To test for heterogeneity, it was also estimated as the regression of local deaths to cases, but no substantial heterogeneity was observed (not shown). It is a lower-bound due to right censoring of the time series of deaths.

### Reporting summary

Further information on research design is available in the Nature Research Reporting Summary linked to this paper.

## Data availability

Data access is managed by the DHSC. An application is underway to make all data necessary to reproduce our analyses available to accredited researchers through the Office for National Statistics (https://www.ons.gov.uk/aboutus/whatwedo/statistics/requestingstatistics/approvedresearcherscheme). Data aggregated spatially and temporally are available at https://stats.app.covid19.nhs.uk/; note that we applied correction factors to early numbers of notifications based on analysis of data available later (see Supplementary Information, ‘Estimate of the number of notifications’).

## Code availability

The analysis was performed with custom R (version 4.0.2) code, available on GitHub at https://github.com/BDI-pathogens/nhs_covid_app_evaluation.

## References

1. 1.

Ferretti, L. et al. Quantifying SARS-CoV-2 transmission suggests epidemic control with digital contact tracing. Science 368, eabb6936 (2020).

2. 2.

Kretzschmar, M. E. et al. Impact of delays on effectiveness of contact tracing strategies for COVID-19: a modelling study. Lancet Public Health 5, e452–e459 (2020).

3. 3.

Lunz, D., Batt, G. & Ruess, J. To quarantine, or not to quarantine: a theoretical framework for disease control via contact tracing. Epidemics 34, 100428 (2021).

4. 4.

Abueg, M. et al. Modeling the combined effect of digital exposure notification and non-pharmaceutical interventions on the COVID-19 epidemic in Washington state. npj Digit. Med. 4, 49 (2021).

5. 5.

Lambert, A. A mathematically rigorous assessment of the efficiency of quarantining and contact tracing in curbing the COVID-19 epidemic. Preprint at https://doi.org/10.1101/2020.05.04.20091009 (2020).

6. 6.

Cencetti, G. et al. Digital proximity tracing in the COVID-19 pandemic on empirical contact networks. Nat. Commun. 12, 1655 (2021).

7. 7.

Colizza, V. et al. Time to evaluate COVID-19 contact-tracing apps. Nat. Med. 27, 361–362 (2021).

8. 8.

9. 9.

Troncoso, C. et al. Decentralized privacy-preserving proximity tracing. Preprint at https://arxiv.org/abs/2005.12273 (2020).

10. 10.

Lovett, T. et al. Inferring proximity from Bluetooth low energy RSSI with unscented Kalman smoothers. Preprint at https://arxiv.org/abs/2007.05057 (2020).

11. 11.

Salathé, M. et al. Early evidence of effectiveness of digital contact tracing for SARS-CoV-2 in Switzerland. Swiss Med. Wkly. 150, w20457 (2020).

12. 12.

Rodríguez, P. et al. A population-based controlled experiment assessing the epidemiological impact of digital contact tracing. Nat. Commun. 12, 587 (2021).

13. 13.

Smith, L. E. et al. Adherence to the test, trace and isolate system: results from a time series of 21 nationally representative surveys in the UK (the COVID-19 Rapid Survey of Adherence to Interventions and Responses [CORSAIR] study). https://doi.org/10.1101/2020.09.15.20191957 (2020).

14. 14.

Fancourt, D., Bu, F., Wan Mak, H. & Steptoe, A. Covid-19 Social Study: Results Release 28 (UCL, 2020); http://allcatsrgrey.org.uk/wp/download/public_health/mental_health/3d9db5_bf013154aed5484b970c0cf84ff109e9.pdf

15. 15.

Hinch, R. et al. OpenABM-Covid19—an agent-based model for non-pharmaceutical interventions against COVID-19 including contact tracing. Preprint at https://doi.org/10.1101/2020.09.16.20195925 (2020).

16. 16.

Flaxman, S. et al. Estimating the effects of non-pharmaceutical interventions on COVID-19 in Europe. Nature 584, 257–261 (2020).

17. 17.

Volz, E. et al. Assessing transmissibility of SARS-CoV-2 lineage B.1.1.7 in England. Nature 593, 266–269 (2021).

18. 18.

Davies, N. G. et al. Estimated transmissibility and impact of SARS-CoV-2 lineage B.1.1.1.7 in England. Science 372, eabg3055 (2021).

19. 19.

Vöhringer, H. et al. Lineage-Specific Growth of SARS-CoV-2 B.1.1.7 During the English National Lockdown (Virological, 2020); https://virological.org/t/lineage-specific-growth-of-sars-cov-2-b-1–1-7-during-the-english-national-lockdown/575

20. 20.

Investigation of Novel SARS-CoV-2 Variant: Variant of Concern 202012/01 Technical Briefing 2 (Public Health England, 2020); https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/959361/Technical_Briefing_VOC202012-2_Briefing_2.pdf

21. 21.

Hernán, M. A. & Robins, J. M. Using big data to emulate a target trial when a randomized trial is not available. Am. J. Epidemiol. 183, 758–764 (2016).

22. 22.

Endo, A. et al. Implication of backward contact tracing in the presence of overdispersed transmission in COVID-19 outbreaks. Wellcome Open Res. 5, 239 (2021).

23. 23.

Investigation of Novel SARS-CoV-2 Variant: Variant of Concern 202012/01 Technical Briefing 3 (Public Health England, 2020); https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/950823/Variant_of_Concern_VOC_202012_01_Technical_Briefing_3_-_England.pdf

24. 24.

Galanti, M. et al. The importance of continued non-pharmaceutical interventions during the upcoming SARS-COV-2 vaccination campaign. Preprint at https://doi.org/10.1101/2020.12.23.20248784 (2020).

25. 25.

Moore, S., Hill, E. M., Tildesley, M. J., Dyson, L. & Keeling, M. J. Vaccination and non-pharmaceutical interventions: when can the UK relax about COVID-19? Preprint at https://doi.org/10.1101/2020.12.27.20248896 (2021).

26. 26.

Steel, K. & Donnarumma, H. Coronavirus (COVID-19) Infection Survey, UK 8 January 2021 (Office For National Statistics, 2020); https://www.ons.gov.uk/peoplepopulationandcommunity/healthandsocialcare/conditionsanddiseases/bulletins/coronaviruscovid19infectionsurveypilot/8january2021

27. 27.

Riley, S. et al. REACT-1 round 7 updated report: regional heterogeneity in changes in prevalence of SARS-CoV-2 infection during the second national COVID-19 lockdown in England. Preprint at https://doi.org/10.1101/2020.12.15.20248244 (2020).

28. 28.

Ferretti, L. et al. The timing of COVID-19 transmission. Preprint at https://doi.org/10.1101/2020.09.04.20188516 (2020).

29. 29.

Farronato, C. et al. How to get people to actually use contact-tracing apps. Harvard Business Review https://hbr.org/2020/07/how-to-get-people-to-actually-use-contact-tracing-apps (2020).

## Acknowledgements

We thank R. Hayes, M. Kraemer, S. Bhatt, S. Mishra, J. Scott, S. Flaxman, A. Gandy, C. Jewell and W. Probert for helpful comments. This work was funded by a Li Ka Shing Foundation award to C.F., and by research grant funding from the UK Department of Health and Social Care (DHSC) to M.B., C.H. and C.F. The funders had no role in the design and conduct of the analysis.

## Author information

Authors

### Contributions

Contributions have been categorized according to the CRediT taxonomy (https://casrai.org/credit/). Conceptualization: C.W., L.F., M.B. and C.F. Data curation: C.W., D.T., M.C., L.M. and M.A. Formal analysis: C.W., L.F. and C.F. Funding acquisition: C.H., M.B. and C.F. Investigation: C.W., L.F., D.T., M.C., L.M. and C.F. Methodology: C.W., L.F., R.H., L.M. and C.F. Project administration: D.B., L.A.-D., C.H., M.B. and C.F. Resources: M.A., C.H., M.B. and C.F. Supervision: C.H., M.B. and C.F. Visualization: C.W., D.T. and M.K. Writing—original draft: C.W., L.F. and C.F. Writing—review and editing: all authors.

### Corresponding author

Correspondence to Christophe Fraser.

## Ethics declarations

### Competing interests

D.T., M.C. and M.A. are part of the app data analytics team. D.T. is employed by Zühlke and M.A. is employed by Accenture; Zühlke and Accenture are contracted by the DHSC for app development and analytics. M.B. is lead scientist for the app. C.W., L.F., R.H., L.A.-D., D.B., M.K., C.H. and C.F. have acted as advisors for the DHSC on the app. DHSC runs the app, and manages the secure data environment where the analyses conducted here were performed. DHSC led dissemination of the findings in the UK.

Peer review information Nature thanks Chiara Poletto, Jason Wang and the other, anonymous, reviewer(s) for their contribution to the peer review of this work.

Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

## Extended data figures and tables

### Extended Data Fig. 1 Characterizing the behaviour of the app.

a, The total number of app downloads and active users over time. Fluctuations in app users are artefactual, driven by reporting issues on Android handsets, such that the estimate of ‘active users’ is a lower bound estimate. b, The seven-day rolling mean of the total number of notifications triggered each day. c, The daily number of app users receiving a confirmed positive test. d, The daily number of app users recording a positive test result in the app, having recently received an exposure notification.

### Extended Data Fig. 2 Results for the secondary statistical analysis based on clusters.

Regression coefficients for app effect for each cluster, and aggregate variance-weighted estimate (labelled ‘meta’). Error bars show 95% confidence intervals. Panels are labelled for phase 1 and 2 combined, and phase 1 and phase 2 separately. Aggregate estimates are reported in main text Table 1.

### Extended Data Fig. 3 Estimated cases averted over time.

Plotted is the rolling 7-day average of the number of cases observed and predicted number of cases averted due to the notifications sent by the app, for different values of adherence to imperfect quarantine (25%, 50%, 75%) for the 31% of notified individuals who we assumed adhere imperfectly, in addition to 45.5% of notified individuals assumed to adhere perfectly.

### Extended Data Fig. 4 Estimated delay from exposure to notification.

The black line shows the mean, and the grey ribbon around the mean shows points within 1 standard deviation of the mean. For comparison, deciles of the generation time distribution (the probability density function for the time from becoming infected to infecting others) are shown in blue; for example the first decile (tenth percentile) is greater than the mean time to notification in December, that is, the mean time to notification comes before 90% of when transmission would normally happen.

### Extended Data Fig. 5 Summarizing app data.

We show the relationship between epidemiological events, and the data gathered about these by the app on individual phones and in the central database. The so-called circuit breaker monitors and processes in real time requests by the app to notify (our quantity N(t) in Methods, ‘Estimate of the number of notifications’.).

### Extended Data Fig. 6 Maps of per-capita numbers of cases in LTLAs over time.

a, Per-capita case numbers in phase 0 grouped into quintiles, showing the stratification used for the main statistical analysis. bd, Actual per capita case numbers are shown, using a shared colour scale (shown once), for phases 0 (b), 1 (c) and 2 (d), respectively.

## Supplementary information

### Supplementary Information

This file contains Supplementary Information, including Supplementary Figures 1-3 and Supplementary Tables 1-4.

## Rights and permissions

Reprints and Permissions

Wymant, C., Ferretti, L., Tsallis, D. et al. The epidemiological impact of the NHS COVID-19 app. Nature 594, 408–412 (2021). https://doi.org/10.1038/s41586-021-03606-z

• Accepted:

• Published:

• Issue Date:

• ### Contact-tracing app curbed the spread of COVID in England and Wales

• C. Jason Wang

Nature (2021)


text:
# Category:Linear Hydroelasticity

Problems in Linear Water-Wave theory in which there is an elastic body.

## Expansion in Modes

The basic idea is to use the same solution method as for a rigid body) except to include elastic modes. While there will be an infinite number of these modes in general, in practice only a few of the lowest modes will be important unless the body is very flexible.

## Finite Element Method

The finite element method is ideally suited to analyse flexible bodies. In the standard FEM notation the dynamic equation of motion in matrix form can be expressed as:

$\begin{bmatrix}K\end{bmatrix}\begin{bmatrix}D\end{bmatrix}+ \begin{bmatrix}S\end{bmatrix}\begin{bmatrix}\dot D\end{bmatrix}+ \begin{bmatrix}M\end{bmatrix}\begin{bmatrix}\ddot D\end{bmatrix}= \begin{bmatrix}F(t)\end{bmatrix}$

where

$\begin{bmatrix}K\end{bmatrix}$ is structural stiffness matrix,
$\begin{bmatrix}S\end{bmatrix}$ is structural damping matrix,
$\begin{bmatrix}M\end{bmatrix}$ is structural mass matrix,
$\begin{bmatrix}D\end{bmatrix}$ is generalized nodal displacements vector,
$\begin{bmatrix}F\end{bmatrix}$ is generalized force vector (fluid forces, gravity forces,...).

Left-hand side of the global FEM matrix equation represents "dry" (in vacuuo) structure, while the right-hand side includes fluid forces (and coupling between the surrounding fluid and the structure).

## Frequency Domain Problem

We consider the problem in the Frequency Domain so that $\begin{bmatrix}D\end{bmatrix}=\begin{bmatrix}w\end{bmatrix}\,e^{-i\omega t}$.

The eigenvalue problem for the "dry" natural vibrations yields:

$\left( \begin{bmatrix}K\end{bmatrix}-\lambda \begin{bmatrix}M\end{bmatrix} \right )\begin{bmatrix}w\end{bmatrix}=\begin{bmatrix}0\end{bmatrix}$

As a solution of the eigenvalue problem for each natural mode one obtains $\omega_n$, the n-th dry natural frequency and $\begin{bmatrix}w_n\end{bmatrix}$, the corresponding dry natural mode. Note that only the first modes are accurate approximations.

We expand the displacement in $N$ modes,

$w = \sum_{\nu} \xi_n \mathbf{w}_{\nu}$

Associated with each of these modes is a normal motion on the body surface given by $\mathbf{n}_{\nu}$. The first modes are the standard rigid modes.

## Equations for the Fluid

The equation for the fluid are as follows

\begin{align} \Delta\phi &=0, &-h\ltz\lt0,\,\,\mathbf{x} \in \Omega \\ \partial_z\phi &= 0, &z=-h, \\ \partial_z \phi &= \alpha \phi, &z=0,\,\,\mathbf{x} \in \partial \Omega_{\mathrm{F}}, \end{align}

(note that the last expression can be obtained from combining the expressions:

\begin{align} \partial_z \phi &= -\mathrm{i} \omega \zeta, &z=0,\,\,\mathbf{x} \in \partial \Omega_{\mathrm{F}}, \\ \mathrm{i} \omega \phi &= g\zeta, &z=0,\,\,\mathbf{x} \in \partial \Omega_{\mathrm{F}}, \end{align}

where $\alpha = \omega^2/g \,$) The body boundary condition for a radiation mode $m$ is just

$\partial_{n}\phi=\mathbf{n}_\nu,\ \ \mathbf{x}\in\partial\Omega_{\mathrm{B}},$

where $\mathbf{n}_{\nu}$ is the normal derivative of the $\nu$ mode on the body surface directed out of the fluid.

## Fluid Structure Equations

We substitute the expansion for the potential into the equations in the frequency domain and we obtain

$\sum_{\nu} K_{\mu\nu}\zeta_{\nu} -\mathrm{i}\omega\sum_{\nu} S_{\mu\nu}\zeta_{\nu} -\omega^2 \sum_{\nu} M_{\mu\nu}\zeta_{\nu}=-\mathrm{i}\omega\rho\iint_{\partial\Omega_{B}} \left(\phi^{\mathrm{I}} + \phi^{\mathrm{D}} + \sum_{\nu} \zeta_\nu \phi_{\nu}^{\mathrm{R}}\right) \mathbf{n}_{\mu}\, dS - \sum_{\nu} C_{\mu\nu}\xi_{\nu},$

We define the added mass matrix by

$A_{\mu\nu} = \mathrm{Re} \left\{\rho\iint_{\partial\Omega_{B}} \phi_{\nu}^{\mathrm{R}} \mathbf{n}_{\mu}\, dS \right\}$

and the damping matrix by

$B_{\mu\nu} = \mathrm{Im} \left\{ \omega \rho\iint_{\partial\Omega_{B}} \phi_{\nu}^{\mathrm{R}} \mathbf{n}_{\mu}\, dS \right\}$

and the forcing vector by

$f_{\mu} = \mathrm{i}\omega\rho\iint_{\partial\Omega_{B}} \left(\phi^{\mathrm{I}} + \phi^{\mathrm{D}} \right) \mathbf{n}_{\mu}\, dS$

Then the equations can be expressed as follows.

$\left[\mathbf{K} -\mathrm{i}\mathbf{S} -\omega^2 \left(\mathbf{M} + \mathbf{A} \right) + \mathrm{i}\omega \mathbf{B} + \mathbf{C} \right] \vec{\zeta} = \mathbf{f}$

where $\mathbf{K}$ is the stiffnes matrix, $\mathbf{S}$ is the structural damping matrix, $\mathbf{M}$ is the mass matrix, $\mathbf{A}$ is the added mass matrix, $\mathbf{B}$ is the damping matrix, $\mathbf{C}$ is the hydrostatic matrix, $\vec{\zeta}$ is the vector of body displacements and $\mathbf{f}$ is the force.

## Subcategories

This category has only the following subcategory.


text:
163 views
The number of ways six distinct balls be distributed into 3 distinct urns. If each urn contain at least one ball are ____
| 163 views
+3
It is equal to the no. of ONTO function from a set containing 6 elements to the set containing 3 elements.

= $3^6$  - ( 3C1 * $2^6$  - 3C2 * $1^6$ )

= $3^6$ - (189) = 729 - 189 = 540.
0
Can you please explain in much more detail @Hemant
0

Hemant Parihar please explain  - ( 3C1 * 2- 3C2 * 1)

0

Yes exactly I am unable to understand this part

(3C1 * 26  - 3C2 * 1

+1

Read this it is from Rosen.

0
check the last comment i tried distinct objects and distinct bins problem with restrictions
https://gateoverflow.in/191081/arrangement
0

36 -(3C2 * 26  - 3C1 * 1)  :-

(3C2 * 26  - 3C1 * 1):- here we are removing the case when balls are distributed only between two persone(3C2 * 26 )  ...means balls are distributed either AB,BC or CA now for all these cases ...there is a chance that balls are given two only one (for AB only A or ONLY B) ...for all A,B,C this would happen two times there for we would add this one more time.....(3C1 * 16)

+1 vote
1
2


text:
## [f]izzbuzzer

### Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

# KnightL on a chessboard challenge

Sharing is caring!

Problem statement
$KnightL$ is a chess piece that moves in an $L$ shape. We define the possible moves of $KnightL(a,b)$ as any movement from some position $(x_1, y_1)$ to some $(x_2, y_2)$ satisfying either of the following:

$x_2 = x_1 \pm a$ and $y_2 = y_1 \pm b$, or
$x_2 = x_1 \pm b$ and $y_2 = y_1 \pm a$

Note that $(a, b)$ and $(b, a)$ allow for the same exact set of movements. For example, the diagram below depicts the possible locations that $KnightL(1,2)$ or $KnightL(2,1)$ can move to from its current location at the center of a $5 \times 5$ chessboard:

Observe that for each possible movement, the Knight moves $2$ units in one direction (i.e., horizontal or vertical) and $1$ unit in the perpendicular direction.

Given the value of $n$ for an $n \times n$ chessboard, answer the following question for each pair where $1 \le a,b \textless n$:

• What is the minimum number of moves it takes for $KnightL(a,b)$ to get from position $(0,0)$ to position $(n - 1, n - 1)$? If it’s not possible for the Knight to reach that destination, the answer is $-1$ instead.

Then print the answer for each $KnightL(a,b)$ according to the Output Format specified below.

Input Format
A single integer denoting $n$.

Constraints
$5 \le n \le 25$

Output Format
Print exactly $n - 1$ lines of output in which each line $i$ (where $1 \le i \textless n$) contains $n - 1$ space-separated integers describing the minimum number of moves $KnightL(i,j)$ must make for each respective $j$ (where $1 \le j \textless n$). If some $KnightL(i,j)$ cannot reach position $(n - 1, n - 1)$, print -1 instead.

For example, if $n = 3$, we organize the answers for all the $(i, j)$ pairs in our output like this:

(1,1) (1,2)
(2,1) (2,2)

Sample Input 0

5

Sample Output 0

4 4 2 8
4 2 4 4
2 4 -1 -1
8 4 -1 1

Explanation 0

The diagram below depicts possible minimal paths for $KnightL(1,1)$, $KnightL(1,2)$, and $KnightL(1,3)$:

One minimal path for $KnightL(1,4)$ is:

$(0,0) \rightarrow (1,4) \rightarrow (2,0) \rightarrow (3,4) \rightarrow (4,0) \rightarrow (0,1) \rightarrow (4,2) \rightarrow (0,3) \rightarrow (4,4)$

We then print 4 4 2 8 as our first line of output because $KnightL(1,1)$ took $4$ moves, $KnightL(1,2)$ took $4$ moves, $KnightL(1,3)$ took $2$ moves, and $KnightL(1,4)$ took $8$ moves.

In some of the later rows of output, it’s impossible for $KnightL(i,j)$ to reach position $(4,4)$. For example, $KnightL(3,3)$ can only move back and forth between $(0,0)$ and $(3,3)$ so it will never reach $(4,4)$.

Solution
We are going to solve this problem by searching for a solution recursively for every $(i,j)$. From each current position $(r,c)$ we know which new position $(newRow, newCol)$ we can reach. The possible values of $(newRow, newCol)$ given a current position $(r,c)$ and a pair $(i,j)$ can be easily computed as follows:

int[] rows = {r + i, r + i, r - i, r - i, r + j, r + j, r - j, r - j};
int[] cols = {c + j, c - j, c + j, c - j, c + i, c - i, c + i, c - i};

We then have 8 (not necessarily valid) new positions we can reach from $(r,c)$. Example: for a given newRow = rows[1] the corresponding newCol will be cols[1]. That is, an entry at index idx in rows corresponds to an entry at cols[idx].

We then call our search function recursively for every pair $(newRow, newCol)$ we can reach from a given current position $(r,c)$.

For our recursive algorithm to work we need to have a terminating condition:

if (r == n - 1 && c == n - 1) {
return count;
}

where count is the current number of steps it took us to reach this far for a given function call.

Obviously thats not all. In order to avoid jumping between two positions indefinitely we need to store some sort of state so our algorithm will stop in case we can never reach $(n - 1, n - 1)$. That is, we are only going to jump to a new state if we haven’t visited that state already or if we may have found a shorter path to that state in case the state has been visited before.

Our state is a combination of row, column and number of steps it took us to get there. We are going to jump to $(newRow, newCol)$ only when:
– we haven’t visited $(newRow, newCol)$ before, or,
– we have visited $(newRow, newCol)$ before but the number of steps it took us to get there is larger than count + 1

Finally we need to keep track of our minimum number of steps for every $(i,j)$.

Full code

public class KnighL {
private static int brute(int n, int i, int j, int r, int c, boolean[][] visited, int[][] steps, int count) {
visited[r][c] = true;

if (r == n - 1 && c == n - 1) {
return count;
} else {
int[] rows = {r + i, r + i, r - i, r - i, r + j, r + j, r - j, r - j};
int[] cols = {c + j, c - j, c + j, c - j, c + i, c - i, c + i, c - i};
int min = Integer.MAX_VALUE;

for (int rc = 0; rc < 8; rc++) {
int newRow = rows[rc];
int newCol = cols[rc];

if (newRow >= 0 && newCol >= 0 && newRow < n && newCol < n) {
if (!visited[newRow][newCol] || (visited[newRow][newCol] && steps[newRow][newCol] > count + 1)) {
steps[newRow][newCol] = count + 1;

int ans = brute(n, i, j, newRow, newCol, visited, steps, count + 1);

if (ans != Integer.MAX_VALUE) {
if (ans < min) {
min = ans;
}
}

}
}
}

return min;
}
}

private static int solve(int n, int i, int j) {
int[][] steps = new int[n][n];
int ans = brute(n, i, j, 0, 0, new boolean[n][n], steps, 0);
return ans != Integer.MAX_VALUE ? ans : -1;
}

public static void main(String[] args) throws FileNotFoundException {
System.setIn(new FileInputStream(System.getProperty("user.home") + "/" + "in.txt"));

Scanner scanner = new Scanner(System.in);

int n = scanner.nextInt();

for (int i = 1; i < n; i++) {
for (int j = 1; j < n; j++) {
int ans = solve(n, i, j);
System.out.print(ans + " ");
}
System.out.println();
}
}
}


text:
# How to read such figures with % as “up (by) 120%” and “increased (by) 120%”. Do they mean the same?

There are now 5.7 billion euros, in notes and coins, in circulation, up 120% from December 31 2001,......

Following significant media coverage of the statistics, calls and contacts logged on the following day – 6 April – were up by 120% compared with the previous day.

Plastic bag regulation can have unintended consequences. Sales of small trash can liners increased 120% after bag bans

Rough sleeping has increased by 120% in England but has fallen in Scotland.

Such phrases describing growth rate as in the above examples are very common, but sometimes I'm confused about how to read them correctly.

My understanding is:

• If our 2019 sales are up 120% (or has increased 120%) from year 2018, it means, for instance, US$100 million in 2018, and US$ 120 million in 2019

• If our 2019 sales are up by 120% (or has increased by 120%) from year 2018, it means, for instance, US$100 million in 2018, and US$ 220 million in 2019

If the above understanding is correct, then how should I interpret "..... is up 20% from last year"? Is it different from "up 120% from last year"?

Or maybe those expressions include some ambiguities?

• @Takashi As other answers have noted, they do mean the same thing. However, one thing that is not the same is when you say X is 120% of Y. This means that X is 20% more than Y is. In other words, X is six-fifths of Y. – Joe Aug 5 '20 at 23:26

"Increased X%" or "increased by X%" or "up X%" or "up by X%" all mean the same. To increase an amount by a percentage is to take the original amount, and add to it the given percentage of that amount. Thus 'increased by 100%' means the same as 'doubled'. 100 increased by 120% is equal to 100 + (100 x 1.20) which is 220.

Percentage change calculator

It is common to use everyday fractions for some percentages, e.g. if something is increased by 25, 33.3, 50, or 75 per cent we can say it is increased by a quarter, a third, a half, or three quarters respectively.

My understanding is:

If our 2019 sales is up 120% (or has increased 120%) from year 2018, it means, for instance, US$100 million in 2018, and US$ 120 million in 2019

Your understanding is not correct. if your sales were $100 million in 2018 and$120 million in 2019, then they are up 20% (or have increased 20%) from 2018.

• I agree with this answer, but note that there are plenty of mathematically illiterate journalists writing for our newspapers. It's not uncommon to see "Increased by 20%" used to mean "Changed from 60% to 80%. – James K Aug 5 '20 at 9:38
• @JamesK is perfectly correct and the use of percentage point should be more widespread and perhaps would make a useful edit to the question. 60% to 80% is an increase of 20 percentage points or 33.3% – mdewey Aug 5 '20 at 12:33
• If you wanted to say that it was 100% and is now 120% (not 120% of 100%), you would say that it has increased to 120%, not by 120% or any of those other variants. – Darrel Hoffman Aug 5 '20 at 16:54
• I didn't say "by 20%" was wrong - I said "by 120%" is wrong in that case, but "to 120%" is correct. – Darrel Hoffman Aug 5 '20 at 17:34
• @MichaelHarvey They have: in the first bullet point, the questioner assumes that 100 becoming 120 is "increased 120%" and in this answer, you assert that "by" is equivalent to no preposition – Tim Sparkles Aug 5 '20 at 18:50

From a prescriptivist point of view, "X% increase" means "multiplied by (1+X/100)".

From a descriptivist point of view, "X% increase" is often used to mean "multiplied by X/100". Of course, if X<100, then it can only mean "multiplied by (1+X/100)". This results in the odd situation that "X% increase" suddenly means something different when X reaches 100.

Logically, "increased X times" should also mean "multiplied by 1+X", but its use to mean "multiplied by X" is even more common than "X% increase" as "multiplied by X/100".


text:
MORE IN Applied Mathematics 2
MU First Year Engineering (Semester 2)
Applied Mathematics 2
May 2015
Total marks: --
Total time: --
INSTRUCTIONS
(1) Assume appropriate data and state your reasons
(2) Marks are given to the right of every question
(3) Draw neat diagrams wherever necessary

1 (a) $Evaluate \ \int^\infty_0 \dfrac {x^4}{4^x} dx$
3 M
1 (b) Find P.I. of (D2-4D+4) y=ex+cos 2x
3 M
1 (c) Show that ∇=1-E-1.
3 M
1 (d) $Evaluate \ \int^1_0 \int^{\sqrt{1+x^2}}_0 \dfrac {dydx}{1+x^2+y^2}$
3 M
1 (e) $Solve \ \left ( 1+e^{x/y} \right )dx+e^{x/y} \left ( 1- \dfrac {x}{y} \right )dy = 0$
4 M
1 (f) Evaluate $\int^\infty_0 \int^\infty_0 e^{-(x^2+y^2)}dxdy$ by changing to polar co-ordinates
4 M

2 (a) Solve $y^4 dx = \left ( x^{-3/4} - y^{3}x \right )dy$
6 M
2 (b) Change the order of integration and evaluate $\int^1_0 \int^{1/x}_0 \dfrac {y}{(1+xy)^2 (1+y^2)}dydx$
6 M
2 (c) (i) $P.T. \ \int^\infty_0 \dfrac {x^{n=1}}{(a+bx)^{m-n}}dx = \dfrac {1}{a^n b^m} \beta (m,n)$
4 M
2 (c) (ii) $P.T. \ \int^\infty_0 \dfrac{\log (1+ax^2)}{x^2} dx = \pi \sqrt{a}, \ where \ a>0$
4 M

3 (a) Evaluate $\int^{\log 2}_0 \int^x_0 \int^{x+\log y}_0 e^{x+y+z}dzdydx$
6 M
3 (b) Find the area bounded between the paraboala
x2=4ay and x2=-4a(y-2a)
6 M
3 (c) Solve by the method of variation of parameters $\dfrac {d^2 y}{dx^2} + y = \sec x \tan x$
8 M

4 (a) Find the length of the cardioid r=a(1-cos ?) lying outside the circle r=a cos ?
6 M
4 (b) Solve $\dfrac {d^2y}{dx^2} - 4 \dfrac {dy}{dx}+3y = 2xe^{3x}+3e^x \cos 2x$
6 M
4 (c) Using R.K. Method of fourth order, solve, $\dfrac {dy}{dx} = \dfrac {y^2 - x^2}{y^2+x^2} \ given \ y(0)=1 \ at \ x=0.2, 0.4$
8 M

5 (a) Solve x sin x dy+(xycos x- ysinx -2)dx=0
6 M
5 (b) Solve $\dfrac {dy}{dx} =2 + \sqrt{xy} \ with \ x_0=1.2, y_0 =1.6403$ by moditied Euler's method, for x=1.4 correct to 4-decimal places, (taking h=0.2)
6 M
5 (c) Evaluate $\int^6_0 x f(x) dx \ by$ i) Trapezoidal rule
ii) simpson's 1/3rd rule
using the following table
 x 0 1 2 3 4 5 6 f(x) 0.146 0.161 0.176 0.19 0.204 0.217 0.23
8 M

6 (a) The charge Q on the plane of a condensor of Capacity C charged through a resistance R by a steady voltage V satisfies the differential equation $R\dfrac {dQ}{dt}+ \dfrac {Q}{c} =V, \ if \ Q=0 \ at \ t=0 , \ Show \ that \ i= \dfrac {V}{R}e^{-1/ac} \because \ i=\dfrac {dQ}{dt}$
6 M
6 (b) Evaluate $\iint_A x^2 dxdy$ where A is the region in the first qadrant bounded by the hyperbola xy=16 and the lines y=x, y=0 and x=8.
6 M
6 (c) Find the volume of the tetrahedron bounded by the planes, x=0, y=0, z=0 and x+y+z=a
8 M

More question papers from Applied Mathematics 2