Mathematics
OpenStudy (anonymous):

Find the angle between the vectors u and v if u = (1, 2) and v = (- 4, - 2)

jimthompson5910 (jim_thompson5910):

Use the formula $\Large \theta = \arccos\left(\frac{u\cdot v}{|u||v|}\right)$ where u and v are vectors.

OpenStudy (anonymous):

which number in my points do i use for each... for example which number in (1,2) would I use for which u

jimthompson5910 (jim_thompson5910):

In the numerator of that fraction, you're computing the dot product between u and v

jimthompson5910 (jim_thompson5910):

So what is the dot product between u = (1, 2) and v = (- 4, - 2)?

OpenStudy (anonymous):

-8

jimthompson5910 (jim_thompson5910):

good

jimthompson5910 (jim_thompson5910):

now you need to find |u| and |v|

OpenStudy (anonymous):

how do I do that?

jimthompson5910 (jim_thompson5910):

use the formula |x| = sqrt(a^2+b^2) where the vector x is x = (a,b)

OpenStudy (anonymous):

so it is sqrt(1^2+2^2) for u's and then sqrt(-4^2+-2^2) for v's?

jimthompson5910 (jim_thompson5910):

yes, so what do you get?

OpenStudy (anonymous):

i think u's is sqrt(5) and v's is 2sqrt(5)

jimthompson5910 (jim_thompson5910):

You got it, nice work So what is |u||v|?

OpenStudy (anonymous):

10... so then its arccos(-8/10)?

jimthompson5910 (jim_thompson5910):

yes

OpenStudy (anonymous):

which turns out to be 143.13degrees

jimthompson5910 (jim_thompson5910):

you nailed it

OpenStudy (anonymous):

You keep helping me sooo much. Thanks, I am taking a Pre-Calculus course by myself and sometimes it can be difficult to figure out all of the questions by myself :).

jimthompson5910 (jim_thompson5910):

you're very welcome, that must be pretty crazy lol

OpenStudy (anonymous):

yep... I'm almost done though (thankfully haha)

jimthompson5910 (jim_thompson5910):

well that's good

OpenStudy (anonymous):

is there a difference between a u surrounded by two of the straight lines as opposed to the just one in the question you just helped me with?

jimthompson5910 (jim_thompson5910):

Well technically it should have been $\Large \|u\|$ since the two vertical bars denote the norm or magnitude of a vector. But the absolute value bars say the same thing (they're just used in a more general sense). So either work in my opinion.

OpenStudy (anonymous):

oh, ok... thanks for clarifying. I am working on another type of question like that and wasn's sure if there was a difference.

jimthompson5910 (jim_thompson5910):

there's not much of a difference really


# Playing roulette

Suppose we have a roulette wheel with $38$ total slots ($18$ black/red, $2$ neither). The ball lands in one slot selected uniformly at random, independent of all previous spins. An $\$x$bet on "black" pays$\$2x$ if the ball lands on black, and $\$0$otherwise. If you bet$1 on black for 100 consecutive spins, how much money will you end up with in expectation?

You walk up to the Roulette table with $\$15$and intend to walk away with$\$16$ using the following betting strategy. You will first bet $\$1$on black. If you win you have$\$16$ and walk away, otherwise you have $\$14$and bet$\$2$ on black on the next spin. If you win that bet you walk away, otherwise you bet $\$4$on the next spin. If you win that bet you walk away, otherwise you bet$\$8$ on the next spin and walk away, either with $\$16$if you win or$\$0$ if you lose.

What's the probability you will walk away with $\$16$? How much money are you expected to walk away with? My biggest problem with these kinds of questions is figuring out how to choose the random variable to calculate the expected values. I understand the formula for calculating the expected value, but translating a problem into those terms has been giving me a hard time. - ## 2 Answers Let's first look at the first question: If you bet$1 on black for 100 consecutive spins, how much money will you end up with in expectation?

So you want to know what your final return will be, at the end of 100 spins. Call this $R$. That is just giving it a name, but what is your final return? You can see that it is the sum of the returns from each bet. So let the return on the $i$th bet be $R_i$, then note that $R = R_1 + R_2 + \dots + R_{100}$. So the expected return is $E[R] = E[R_1] + E[R_2] + \dots + E[R_{100}]$ by linearity of expectation.

So to calculate $E[R]$, we'll be done if we calculate each $E[R_i]$. Let's try to calculate a particular $E[R_i]$. You bet $1$ dollar, and you get back $2$ if the ball lands on black, and $0$ if it doesn't. In other words, you gain $1$ dollar if it lands on black, and lose $1$ dollar if it doesn't. The probability of the former is $18/38$, and that of the latter is $20/38$. In other words, $R_i$ is $1$ with probability $18/38$, and $-1$ with probability $20/38$, so the expected value of $R_i$ is $E[R_i] = \frac{18}{38}(-1) + \frac{20}{38}(1) = \frac{-2}{38}$. Now, as this is the same for each $R_i$, we have $E[R] = E[R_1] + E[R_2] + \dots + E[R_{100}] = \left(\frac{-2}{38}\right)100 \approx -5.26$.

For the second question, let the amount you walk away with be $W$. Let $p = 18/38$, the probability that your bet on black succeeds. There are $5$ possible outcomes:

• you win your first bet: probability $p$
• you lose your first bet, and win your second: probability $(1-p)p$
• you lose your first two bets, and win the third: probability $(1-p)^2p$
• you lose your first three bets, and win the fourth: probability $(1-p)^3p$
• you lose all four bets: probability $(1-p)^4$

In the first four outcomes, you walk away with $16$ dollars, so the probability of that happening (let's call it $q$) is $q = p + (1-p)p + (1-p)^2p + (1-p)^3p = 1 - (1-p)^4 = 1 - (20/38)^4 \approx 0.92$.

[More simply, you could think of it as just two outcomes: (a) that you win some bet, which has probability $q = 1 - (1-p)^4$, and (b) that you win no bet (lose all bets), which has probability $(1-p)^4$.]

In other words, $W$ is $16$ with probability $q$, and $0$ with probability $1-q$. So the expected amount of money you walk away with is therefore $E[W] = q(16) + (1-q)0 = (1-(1-p)^4)16 \approx 14.77$.

[Aside: Note that this is less than the $15$ you came in with. This shows that you can't win in expectation even with your clever betting strategy; a consequence of the optional stopping theorem.]

-

Probability of getting a black on any particular spin is 18 in 38, ie $p = \frac{18}{38} = \frac{9}{19} = 0.474$. Let $X$ be the random variable 'number of blacks in 100 consecutive spins'. Then the expected value of X is $E(X) = 100p = \frac{900}{19} = 47.37$, that is, you expect to win 47.37 times in 100 spins. Since you get $\$$2 for each \$$1 bet, you will therefore expect to walk away with$\$2\times 47.37 = \$94.74$. For the second part of your question, the only way you can lose is if for four consecutive spins, you get non-blacks each time. So what is the probability of losing 4 times in a row? Well, for 1 spin, the probability of not getting black is$1-p = \frac{20}{38} = \frac{10}{19} = 0.526$so for 4 consecutive spins, the probability of not getting any black is$(\frac{10}{19})^{4} = \frac{10,000}{130,321} = 0.0767$. That is, you have about a 7.7% chance of losing with this betting strategy. That is, you have 92.3% chance of walking away with$\16.

-
Can you elaborate on why the expected value is just $100p$? Particularly, how does the linearity of expectations apply here? If we let $X_i = 1$ if we land on black and $X_i = 0$ if we don't land on black, how can we calculate the expected value then? –  user1038665 Nov 14 '12 at 10:53
Also, for the second part, how would we calculate the "amount of money you are expected to walk away with"? –  user1038665 Nov 14 '12 at 10:55
Expected value of a bet = wager x probability. –  theo Nov 14 '12 at 11:02
If you bet 1 dollar 100 times on black you will win about 47.37 times and thus leave the casino with 94.74 of your original 100 dollars. –  Hagen von Eitzen Nov 14 '12 at 11:03
The answer given is -\$(2/38)*(100), so I believe this is incorrect. –  user1038665 Nov 14 '12 at 11:20


# How to create a continuous distribution on $[a, b]$ with $\text{mean} = \text{mode} = c$?

I would like to sample from a distribution on a specific domain $$[a, b]$$ with mean $$c$$ where $$a < c < b$$. Ideally, I would also like the mode (i.e. the "peak") of the distribution to be $$c$$ as well.

How to derive this distribution?

The best I can do is a triangular distribution with my desired mean, but the peak is in the wrong place. I imagine the distribution I want is smooth and skewed.

EDIT: If $$c$$ were at the midpoint of $$a$$ and $$b$$ then I think a truncated normal distribution is roughly what I'm looking for. So something similar where the tails go smoothly to zero at the endpoints of my interval when $$c$$ is not in the middle would be nice.

EDIT 2: I'm looking to perturb some parameters in a simulation, so really anything reasonable should be fine.

• There are infinitely many possible solutions, which enables you to apply stricter criteria to narrow it down. To that end, could you explain what use you intend to make of this family of distributions? BTW, "skewed" strongly suggests the peak should not coincide with the mean.
– whuber
Jan 28 at 20:11
• Good point. I did my best to clarify. Jan 28 at 20:37
• There are still infinitely many solutions, but another way would be to generate a beta RV with parameters that give it the desired skew and unimodality, and then shift and scale the whole distribution so it lies in [a,b].
– Noah
Jan 28 at 20:50
• Thanks! That looks like it will do just fine. Jan 28 at 20:53
• @Noah That looks a lot like an acceptable answer!
– Dave
Jan 28 at 20:53

I will describe every possible solution. This gives you maximal freedom to craft distributions that meet your needs.

Basically, sketch any curve you like for the density function $$f$$ that meets your requirements. Separately scale the heights of the left and right halves of it (on either side of $$c$$) to make their masses balance, then scale the heights overall to make it a probability density.

Here are some details.

Because the distribution is continuous, it has a density function $$f$$ with finite integral. By splitting $$f$$ at $$c$$ we can construct all such functions out of two separately chosen non-negative non-decreasing, not identically zero, integrable functions $$f_1$$ and $$f_2$$ defined on $$[0,1].$$ Here, for example, are two such functions:

Set $$f$$ to agree affinely with $$f_1$$ on $$[a,c]$$ and with the reversal of $$f_2$$ on $$[c,b].$$ This means there are two positive numbers $$\pi_i$$ for which

$$f\mid_{[a,c]}(x) = \pi_1 f_1\left(\frac{x-a}{c-a}\right);\quad f\mid_{[c,b]}(x) = \pi_2 f_2\left(\frac{b-x}{b-c}\right).$$

This construction guarantees $$c$$ is the unique mode. Moreover, if you want the tails to taper to zero, just choose $$f_i$$ that approach $$0$$ continuously at the origin.

For $$f$$ to be a probability density it must integrate to unity:

$$1 = \int_a^b f(x)\,\mathrm{d}x =\pi_1(c-a) \mu_1^{(0)} + \pi_2(b-c) \mu_2^{(0)}\tag{*}$$

where

$$\mu_i^{(k)} = \int_0^1 x^k f_i(x)\,\mathrm{d}x.$$

Moreover, $$c$$ is intended to be the mean, whence

\begin{aligned} c &= \int_a^b x f(x)\,\mathrm{d}x \\ &= \pi_1(c-a)((c-a)\mu_1^{(1)} + a\mu_1^{(0)}) + \pi_2(b-c)(-(b-c)\mu_2^{(1)} + b\mu_2^{(0)}). \end{aligned}\tag{**}

$$(*)$$ and $$(**)$$ establish a system of two linear equations in the $$\pi_i.$$ You can check it has nonzero determinant and a unit positive solution $$(\pi_1,\pi_2).$$ (This checking comes down to the fact that after normalizing the $$f_i$$ to be probability densities, their means $$\mu_i^{(1)}$$ must be in the interval $$[0,1].$$)

This figure plots the solution $$f$$ for the previous two functions where $$[a,b]=[-1,3]$$ and $$c=1/2:$$

By design, $$f$$ looks like $$f_1$$ to the left of $$c$$ and like the reversal of $$f_2$$ to the right of $$c.$$

The spike at the mode might bother you, but notice that it was never assumed or required that $$f$$ must be continuous. Most examples will be discontinuous. However, every distribution $$f$$ meeting your specifications can be constructed this way (by reversing the process: split $$f$$ into two halves, which obviously determine the $$f_i$$).

To demonstrate how general the $$f_i$$ can be, here is the same construction where the $$f_i$$ are (inverse) Cantor functions (as implemented in binary.to.ternary at https://stats.stackexchange.com/a/229561/919). These are not continuous anywhere.

NB: $$f_1$$ is binary.to.ternary; $$f_2(x) = f_1(x^{2.28370312}).$$ This illustrates one way to eliminate the discontinuity at $$c:$$ $$f_2$$ was selected from the one-parameter family of functions $$f_1(x^p),$$ $$p \gt 0,$$ and a value of $$p$$ was identified to make the left and right limits of $$f$$ at $$c$$ equal. This family "pushes" the mass of $$f_1$$ left and right by a controllable amount, thereby modifying the amount by which the right tail is scaled (vertically) in constructing $$f.$$

For those who would like to experiment, here is an R function to create $$f$$ out of the $$f_i$$ and code to create the figures. Three commands at the end check whether (1) $$f$$ is a pdf, (2) its mean is $$c,$$ and (3) its mode is $$c.$$

#
# Given numbers a. < b. < c. and non-negative, non-decreasing, not identically
# zero functions f.1 and f.2 defined on [0,1], construct a density function f
# on the interval [a., b.] with mean c. and unique mode c. that behaves like f.1
# to the left of c. and like the reversal of f.2 to the right of c.
#
# ... are optional arguments passed along to integrate.
#
create <- function(a., b., c., f.1, f.2, ...) {
cat("Create\n")
p.1 <- integrate(f.1, 0, 1, ...)$$value p.2 <- integrate(f.2, 0, 1, ...)$$value
mu.1 <- integrate(function(u) u * f.1(u), 0, 1, ...)$$value mu.2 <- integrate(function(u) u * f.2(u), 0, 1, ...)$$value

A <- matrix(c(p.1 * (c.-a.), p.2 * (b.-c.),
(c.-a.) * ((c.-a.) * mu.1 + a.*p.1),
(b.-c.) * (-(b.-c.) * mu.2 + b.*p.2)),
2)
pi. <- solve(t(A), c(1, c.))
function(x) {
ifelse(a. <= x & x <= c., 1, 0) * pi.[1] * f.1((x-a.)/(c.-a.)) +
ifelse(c. < x & x <= b., 1, 0) * pi.[2] * f.2((b.-x)/(b.-c.))
}
}
#
# Example.
#
a. <- -1
b. <- 3
c. <- 1/2
f.2 <- function(x) x^(2/3)
f.1 <- function(x) exp(2 * x) - 1
f <- create(a., b., c., f.1, f.2)
#
# Display f.1 and f.2.
#
par(mfrow=c(1,2))
curve(f.1(x), 0, 1, lwd=2, ylab="", main=expression(paste(f[1], ": ", x^{2/3})))
curve(f.2(x), 0, 1, lwd=2, ylab="", main=expression(paste(f[2], ": ", e^{2*x}-1)))
#
# Display f.
#
x <- c(seq(a., c., length.out=601), seq(c.+1e-12*(b.-a.), b., length.out=601))
y <- f(x)
par(mfrow=c(1,1))
plot(c(x, b., a.), c(y, 0, 0), type="n", xlab="x", ylab="Density", main=expression(f))
polygon(c(x, b., a.), c(y, 0, 0), col="#f0f0f0", border=NA)
curve(f(x), b., a., lwd=2, n=1201, add=TRUE)
#
# Checks.
#
integrate(f, a., b.)                    # Should be 1
integrate(function(x) x * f(x), a., b.) # Should be c.
x[which.max(y)]                         # Should be close to c.

• Lovely! But a quibble: I do not think this captures distributions in which the 'left' or 'right' halves themselves contain nondifferentiable or discontinuous points—I am especially thinking of densely nondifferentiable or densely discontinuous curves—which are essentially 'undrawable' except by approximation. I am not actually convinced this is a defensible quibble, though. :) More just musing… Jan 29 at 6:28
• @Alexis I cannot see any exceptions: I made no conditions on the $f_i$ concerning differentiability or even continuity. For instance, both $f_i$ could be Cantor functions. I will add an illustration.
– whuber
Jan 29 at 15:13
• I was thinking about Cantor functions! Quibble withdrawn (and thank you for entertaining my musing :). Jan 29 at 18:32

All you need to do is come up with a two-parameter family of distributions, express the mean and mode in terms of those parameters, and then solve for them both being $$c$$. Working off your triangle idea, we can have a pentagon instead (straight lines from $$a$$ to $$c$$ and from $$c$$ to $$b$$), giving us three parameters ($$y_1$$ at $$a$$, $$y_2$$ at $$b$$, and $$y_3$$ at $$c$$), but we don't really have three degrees of freedom. We have that the total probability mass from $$a$$ to $$c$$ is $$\frac 1 2 (y_1+y_3)(c-a)$$, and the mass from $$c$$ to $$b$$ is $$\frac 1 2 (y_2+y_3)(c-b)$$, so we need to have $$\frac 1 2 (y_1+y_3)(c-a)+\frac 1 2 (y_2+y_3)(c-b)=1$$. Then you just need to make sure that the mean is $$c$$ as well.

• The problem with this approach is that it can fail even in the nicest circumstances (as I pointed out in a comment to the question). For instance, it does not work with the Beta family of distributions: there are no solutions unless the Beta parameters are equal.
– whuber
Jan 29 at 15:18


# Power series at $x=0$

$$\sum_{n=0}^∞n!x^{2n}$$

This power series has radius of convergence $R=0$ since the ratio test shows it diverges for all $x≠0$.

But what if $x=0$? Then we have $\sum_{n=0}^\infty n! \cdot 0^{2n}$

Surely this series is undefined since the first partial sum is $0!\cdot 0^{2\cdot0}$ and $0^0$ is undefined, right?

Well, my lecturer claims this series is convergent and is equal to 1.

But $\sum_{n=1}^\infty n!\cdot 0^{2n}$ clearly converges to 0, so he is claiming that $0!\cdot 0^0=1$?

So is he wrong? Or am I missing something here?

• $0^0 = 1$ by convention. – user258700 Dec 22 '15 at 2:01
• Really? I've never heard that. I've always thought it was just undefined. Why isn't $\frac00$ similarly defined by convention? – Refnom95 Dec 22 '15 at 2:08
• It's only when dealing with limits that $0^0$ is indeterminant. – Michael Burr Dec 22 '15 at 2:09
• It's done mostly in the context of power series. It's much neater to write $\sum_i \text{bla}_ix^i$ than $\text{bla}_0+\sum_{i>0}...$. – YoTengoUnLCD Dec 22 '15 at 2:20

There are a lot of situations where it is convenient to define $$0^0=1$$ and of course $0!=1$, so $0!\cdot0^0=1$.
In some situations, it's most appropriate to leave $0^0$ undefined. In particular, the function $x^y$ converges to different limits as $x\to0$ and $y\to0$ depending on which path is taken, so analysis does not yield a natural value for $0^0$ and it may not make sense to define $0^0=1$.
However, when dealing with discrete exponents (natural numbers), it's usually better to define $0^0=1$, because this is consistent with combinatorial or set-theoretic interpretations of exponentiation. For instance, the set of functions from the empty set to the empty set has cardinality $1$, so $0^0=1$ by the set-theoretic definition. Also, using the repeated multiplication definition of exponentiation, an empty product is always $1$, even when the product contains only zeroes. (For more information, see this Wikipedia article.)
It is important to consider where the $0^0$ in the expression comes from. In your case, it's the first term of a power series. A power series' notion of exponentiation is closest to the repeated multiplication interpretation, so taking $0^0$ makes sense. Consider that a power series is just a generalization of a polynomial. How would you evaluate $f(x)=x^2+x+1$ at $x=0$? What if this is written $f(x)=x^2+x^1+x^0$?


# Math Help - Help with a proof.

1. ## Help with a proof.

Hi, I'm stuck at proving the following question...

Prove that for all n>0,

1/2 + 2/2^2 + 3/2^3 + ... + n/2^n = 2 - (n+2)/2^n

I've tried all sorts of different ways of solving this, but to no avail.

Any help is appreciated

2. Originally Posted by seven.j
Hi, I'm stuck at proving the following question...

Prove that for all n>0,

1/2 + 2/2^2 + 3/2^3 + ... + n/2^n = 2 - (n+2)/2^n

I've tried all sorts of different ways of solving this, but to no avail.

Any help is appreciated
$\sum_{k=1}^{n}\frac{k}{2^k}$. Note that $\sum_{k=1}
^n x^k=\frac{x^{n+1}-x}{x-1}$
. Differentiating both sides and multiplying by $x$ gives $\sum_{k=1}^{n}k\cdot x^k=...$ figure the right side out.

3. $\sum\limits_{j=1}^{n}{\frac{j}{2^{j}}}=\sum\limits _{j=1}^{n}{\sum\limits_{k=1}^{j}{\frac{1}{2^{j}}}} =\sum\limits_{k=1}^{n}{\frac{1}{2^{k}}\left( \sum\limits_{j=0}^{n-k}{2^{-j}} \right)}=\frac{1}{2^{n}}\sum\limits_{k=1}^{n}{\fra c{1}{2^{k}}\left( 2^{n+1}-2^{k} \right)},$ you can do the rest, those are finite geometric sums.

4. Hello, seven!

Here's one way . . .

Prove that for all $n>0\!:$

. . $\frac{1}{2}+ \frac{2}{2^2} + \frac{3}{2^3} +\:\hdots\:+ \frac{n}{2^n} \; =\; 2 - \frac{n+2}{2^n}$
$\begin{array}{ccccc}
\text{We have:} &S &=& \dfrac{1}{2} + \dfrac{2}{2^2} + \dfrac{3}{2^3} + \dfrac{4}{2^4} + \:\hdots\:+\dfrac{n}{2^n}\qquad\qquad \\ \\[-3mm]

\text{Multiply by }\dfrac{1}{2}\!: & \dfrac{1}{2}S &=& \quad\;\; \dfrac{1}{2^2} + \dfrac{2}{2^3} + \dfrac{3}{2^4} + \hdots + \dfrac{n-1}{2^n} + \dfrac{n}{2^{n+1}}\end{array}$

. . . $\text{Subtract: }\quad \frac{1}{2}S \;=\;\underbrace{\frac{1}{2} + \frac{1}{2^2} + \frac{1}{2^3} + \frac{1}{2^4} + \hdots + \frac{1}{2^n}}_{\text{geometric series}} - \frac{n}{2^{n+2}}$ .[1]

The geometric series has the sum: . $\frac{1}{2}\cdot\frac{1 - \left(\frac{1}{2}\right)^n}{1-\frac{1}{2}} \;=\;1 - \frac{1}{2^n}$

Then [1] becomes: . $\frac{1}{2}S \;=\;\left(1 - \frac{1}{2^n}\right) - \frac{n}{2^{n+1}} \;=\;1 - \frac{n+2}{2^{n+1}}$

Multiply by 2: . $S \;=\;2 - \frac{n+2}{2^n}$

5. Originally Posted by seven.j
Hi, I'm stuck at proving the following question...

Prove that for all n>0,

1/2 + 2/2^2 + 3/2^3 + ... + n/2^n = 2 - (n+2)/2^n

I've tried all sorts of different ways of solving this, but to no avail.

Any help is appreciated
This problem also can be done by induction pretty easily. if you're interested, you can try it that way. to me it was the most knee-jerk approach to try, and it worked out great. but you have lots of nice approaches here to choose from


#### puremath

##### Active Member
If Miranda flips a coin twice, what is the probability that both coins will land heads up?

Solution (not my work):
Probability of coin 1 landing heads up is 1/2. Probability of second coin landing heads up is 1/2.

P(both heads up) = (1/2)(1/2) = 1/4.

Question:
What indicates in the problem that 1/2 is multiplied by 1/2? Taking a test, a student might guess that he or she must add 1/2 to itself.

#### MarkFL

##### La Villa Strangiato
Staff member
Moderator
Math Helper
We are asked to find the probability that the coin is heads on the first flip AND the coin is heads on the second flip. The "AND" tells us to multiply.

puremath

#### puremath

##### Active Member
We are asked to find the probability that the coin is heads on the first flip AND the coin is heads on the second flip. The "AND" tells us to multiply.

Staff member
Moderator
Math Helper
Yes.

#### puremath

##### Active Member
We are asked to find the probability that the coin is heads on the first flip AND the coin is heads on the second flip. The "AND" tells us to multiply.
The word AND is not in the problem. This is the way I would type the question:

If Miranda flips a coin twice, what is the probability that the coin lands heads up on the first flip and heads up on the second flip? Now the word problem makes sense to me.

#### MarkFL

##### La Villa Strangiato
Staff member
Moderator
Math Helper
When it says both that means both the first flip AND the second flip are heads.

#### MarkFL

##### La Villa Strangiato
Staff member
Moderator
Math Helper
Actually, It could be worded better, as it first implies she is flipping the same coin twice, then it speaks of both coins. If I were to author such a problem, I might state:

If Miranda flips a coin twice, what is the probability that it lands heads up both times?

puremath

#### puremath

##### Active Member
When it says both that means both the first flip AND the second flip are heads.
When reading this the first time, it is not so clear.

#### puremath

##### Active Member
Actually, It could be worded better, as it first implies she is flipping the same coin twice, then it speaks of both coins. If I were to author such a problem, I might state:

If Miranda flips a coin twice, what is the probability that it lands heads up both times?
It is ok but my wording makes it clear to the reader that this problem involves AND and thus multiplication is the operation. Back to Cohen on Monday.

#### MarkFL

##### La Villa Strangiato
Staff member
Moderator
Math Helper
What is the probability that of the two flips, at least one is heads?

#### puremath

##### Active Member
What is the probability that of the two flips, at least one is heads?
P(at least one heads up) = 1 - P(not one is heads up). At the job now. I have a probability book that I also want to learn with you later on in my self-study trek.

#### MarkFL

##### La Villa Strangiato
Staff member
Moderator
Math Helper
You're on the right track. I will give you time to complete the question.

#### puremath

##### Active Member
You're on the right track. I will give you time to complete the question.
For two flips, there are 4 possibilities, only one of which (getting tails twice) does not have any head. So, the other 3 out of 4 cases would have one or two heads. I say 75% probability. Yes?

MarkFL

Staff member


# How should one proceed in this trigonometric simplification involving non integer angles?

The problem is as follows:

Find the value of this function $$A=\left(\cos\frac{\omega}{2} +\cos\frac{\phi}{2}\right )^{2} +\left(\sin\frac{\omega}{2} -\sin\frac{\phi}{2}\right )^{2}$$ when $$\omega=33^{\circ}{20}'$$ and $$\phi=56^{\circ}{40}'$$.

Thus,

$$A=\left(\cos\frac{\omega}{2} +\cos\frac{\phi}{2}\right)^{2} +\left(\sin\frac{\omega}{2} -\sin\frac{\phi}{2}\right)^{2}$$

By solving the power I obtained the following:

$$A= \cos^{2}\frac{\omega}{2} +\cos^{2}\frac{\phi}{2} +2\cos\frac{\omega}{2}\cos\frac{\phi}{2} +\sin^{2}\frac{\omega}{2} +\sin^{2}\frac{\phi}{2} +2\sin\frac{\omega}{2}\cos\frac{\phi}{2}$$

I noticed some familiar terms and using pitagoric identities then I rearranged the equation as follows:

\begin{align} A &= \cos^{2}\frac{\omega}{2} +\sin^{2}\frac{\omega}{2} +\cos^{2}\frac{\phi}{2} +\sin^{2}\frac{\phi}{2} +2\cos\frac{\omega}{2}\cos\frac{\phi}{2} +2\sin\frac{\omega}{2}\cos\frac{\phi}{2} \\ &= 1+1+2\cos\frac{\omega}{2}cos\frac{\phi}{2} +2\sin\frac{\omega}{2}\cos\frac{\phi}{2} \end{align}

Since the latter terms are another way to write prosthapharesis formulas I did the following:

\begin{align} \cos\alpha +\cos\beta &= 2\cos\frac{\alpha+\beta}{2}\cos\frac{\alpha-\beta}{2} \\ \cos\alpha -\cos\beta &= -2\cos\frac{\alpha+\beta}{2}\cos\frac{\alpha-\beta}{2} \\ \\ \alpha+\beta &= \omega \\ \alpha-\beta &= \phi \end{align}

By solving the system I found: $$\alpha=\frac{\omega+\phi}{2}$$ and $$\beta=\frac{\omega-\phi}{2}$$.

Therefore by inserting these into the problem:

\begin{align} A &= 1+1 +2\cos\frac{\omega}{2}\cos\frac{\phi}{2} +2\sin\frac{\omega}{2}\cos\frac{\phi}{2} \\ &= 2 +2\cos\frac{\omega}{2}\cos\frac{\phi}{2} -\left(-2\sin\frac{\omega}{2}\cos\frac{\phi}{2}\right) \\ &= 2 +\cos\frac{\omega+\phi}{2} +\cos\frac{\omega-\phi}{2} -\left(\cos\frac{\omega+\phi}{2} -\cos\frac{\omega-\phi}{2}\right) \end{align}

By cancelling elements,

$$A=2 +2\cos\frac{\omega-\phi}{2}$$

However I'm stuck at trying to evaluate these values:

\begin{align} \omega &= 33^{\circ}{20}'\; \phi=56^{\circ}{40}' \\ \omega-\phi &= \left(33+\frac{20}{60}\right) -\left(56+\frac{40}{60}\right) = -23-\frac{20}{60} \end{align}

Therefore,

$$A=2+2\cos\left(\frac{-23-\frac{20}{60}}{2}\right).$$

However the latter answer does not appear in the alternative neither seems to be right. Is there something wrong on what I did?

• Just a remark: Use \cos and \sin instead of cos and sin. – MrYouMath Oct 17 '17 at 8:52
• @MrYouMath Thanks for the advise. I'll take note on that next time I post a similar question. I'm new on LaTex. – Chris Steinbeck Bell Oct 18 '17 at 2:31

There is a mistake in your expansion of the second bracket.

We should have

$A=\cos^2\frac{\omega}{2}+2\cos\frac{\omega}{2}\cos\frac{\phi}{2}+\cos^2 \frac{\phi}{2}+\sin^2\frac{\omega}{2}-2\sin\frac{\omega}{2}\sin\frac{\phi}{2}+\sin^2\frac{\phi}{2}$

$=2+2(\cos\frac{\omega}{2} \cos\frac{\phi}{2} -\sin\frac{\omega}{2}\sin\frac{\phi}{2})$ .

In the bracket we have the expansion for $\cos(\frac{\omega}{2}+\frac{\phi}{2})$ and fortunately $\omega+\phi=90^\circ$.

Thus $A=2+2\cos(45^\circ)$

$=2+\sqrt{2}$

Hint: You did a miscalculation:

$$A=\left (\cos\frac{\omega}{2}+\cos\frac{\phi}{2} \right )^{2}+\left (\sin\frac{\omega}{2}-\sin\frac{\phi}{2} \right )^{2}$$ $$=\cos ^2\frac{\omega}{2}+2\cos\frac{\omega}{2}\cos\frac{\phi}{2}+\cos^2 \frac{\phi}{2}+\sin ^2\frac{\omega}{2}-2\sin\frac{\omega}{2}\sin\frac{\phi}{2}+\sin^2 \frac{\phi}{2}$$ $$=2+2\cos\frac{\omega}{2}\cos\frac{\phi}{2}-2\sin\frac{\omega}{2}\sin\frac{\phi}{2}$$ $$=2+2\left(\cos\frac{\omega}{2}\cos\frac{\phi}{2}-\sin\frac{\omega}{2}\sin\frac{\phi}{2}\right)$$ $$=2+2\cos\left(\frac{\omega}{2}+\frac{\phi}{2}\right)$$

In the last step I used $\cos(x+y)=\cos x\cos y-\sin x \sin y$.

• Mind including the "last step" in your answer?. I mean the one involving inserting the angle values in the last formula. Usually this seems the most logical and obvious thing to do. But what to do when the angles are not "integers". Was the procedure I used correct?. I mean to decompose them into fractions. The latter part I'm not sure. – Chris Steinbeck Bell Oct 18 '17 at 2:34


Start with the binomial expansion of (k − 1) 2: (k-1)^2: (k − 1) 2: (k – roganjosh May 10 '17 at 19:49 (, Techniques for Adding the Numbers 1 to 100, Quick Insight: Intuitive Meaning of Division, Quick Insight: Subtracting Negative Numbers, Surprising Patterns in the Square Numbers (1, 4, 9, 16…), Learning How to Count (Avoiding The Fencepost Problem), Different Interpretations for the Number Zero. Now for the explanation: How many beans do we have total? (i) 2, 7, 12 , ., to 10 terms. We prove the formula 1+ 2+ ... + n = n(n+1) / 2, for n a natural number. Beginners Java program to find sum of odd numbers between 1 -100 ½n(n + 1),. Yep, you get the same formula, but for different reasons. Our math solver supports basic math, pre-algebra, algebra, trigonometry, calculus and more. Python Program to Calculate Sum of Odd Numbers from 1 to N using For Loop. my calculator seems to say 55 though, i don't get how the sum of n terms formula has failed as it's for an AP. Find all the evens, So, the sum from 50 + 52 + … 100 = (50 * 51) – (24 * 25) = 1950. There is a simple applet showing the essence of the inductive proof of this result. I like Steve's thinking, but sometimes I like to take a hammer to a thumbtack. Vandermonde convolution X k r k! We get the next biggest even number (n + 1) and take off the extra (n + 1)/2 “-1″ items: To add 1 + 3 + 5 + … 13, get the next biggest even (n + 1 = 14) and do, Let’s say you want the evens from 50 + 52 + 54 + 56 + … 100. 17 Answers 26 The main idea is that if you write all the numbers from 0 to 999999 down as six digit numbers (possibly prepending zeros) then all digits appear the same number of times. Well, we have 2 equal rows, we must have n/2 pairs. Math. The above method works, but you handle odd and even numbers differently. What is the sum of 1+1/10+1/100+1/1000... etc, where each time the denominator increases by an factor of 10 Through how many radians does it turn in one second? Each nth term of the series is the sum of the n terms i.e n*(n+1)/2. Then push the [Next] button to step through the stages of the proof. Calculate the sum … Q:-A wheel makes 360 revolutions in one minute. for(i=1;i<=n;i++) sum=sum+i; Sum of Natural Numbers using Formula. The loop structure should look like for(i=2; i<=N; i+=2). Yes. Submitted by IncludeHelp, on September 04, 2018 Given the value of N and we have to find sum of all numbers from 0 to N in C language. In case you’re wondering whether it “really” lines up, it does. Instead of writing out numbers, pretend we have beans. Output 2: Enter the value of n: 0 Enter a whole positive number! Below is the complete algorithm. What is the formula for the sum of odd numbers? How to calculate this $\sum\limits_{n=0}^{\infty}\frac{n}{2^n}e^{jwn}$ 0. 2. Python Program to Calculate Sum of Even Numbers from 1 to N using For Loop. This program to find the sum of n numbers allows the user to enter any integer value. sum = n(n+1)/2 In the above program, unlike a for loop, we have to increment the value of i inside the body of the loop. For instance the sum of the numbers from 1 to 10 is 55 whereas the sum of the digits is 46. Let’s say we mirror our pyramid (I’ll use “o” for the mirrored beans), and then topple it over: Cool, huh? home Front End HTML CSS JavaScript HTML5 Schema.org php.js Twitter Bootstrap Responsive Web Design tutorial Zurb Foundation 3 tutorials Pure CSS HTML5 Canvas JavaScript Course Icon Angular React Vue Jest Mocha NPM Yarn Back End PHP Python Java … Home Science Math History Literature Technology Health Law Business All Topics Random. The sum of all the odd integers from 1 to 50 is 625. To find sum of even numbers we need to iterate through even numbers from 1 to n. Initialize a loop from 2 to N and increment 2 on each iteration. 1. In this program, we first check number is odd or not. To add evens from 2 to 50, find 1 + 2 + 3 + 4 … + 25 and double it: So, to get the evens from 2 to 50 you’d do 25 * (25 + 1) = 650. The above formula is one core step of the idea. The partial sums of the series 1 + 2 + 3 + 4 + 5 + 6 + ⋯ are 1, 3, 6, 10, 15, etc.The nth partial sum is given by a simple formula: ∑ = = (+). = r +s n! Python Program to Sum the list with start 10; Program to Sum the list of float; Python Program to Sum the list of float with start 10.1; Program to calculate the sum of elements in a tuple. Let’s look at a small set: The average is 2. Python Program to Sum the list with start 10; Program to Sum the list of float; Python Program to Sum the list of float with start 10.1; Program to calculate the sum of elements in a tuple. We know that the even numbers are the numbers, which are completely divisible by 2. This Python program allows the user to enter the maximum limit value. Popular Questions of Class 11th mathematics. The so-called educator wanted to keep the kids busy so he could take a nap; he asked the class to add the numbers 1 to 100. You need to initialize the counter as 0 and while the loop executes you need to collect / sum them to the counter and finally outside the loop print/ echo the counter. This is demonstrated by the following code snippet. So, we can say the average of the entire set is actually just the average of 1 and n: (1 + n)/2. DESCRIPTION. In summation notation, this may be expressed as + ... Achilles could run at 10 m/s, while the tortoise only 5. The formula to find the sum of first n natural numbers is as follows. Geometric sum nX−1 k=0 ark = a 1− rn 1− r r 6= 1 Geometric series X∞ k=0 ark = a 1− r |r| < 1 3. Feb 21, 2015 . Feb 21, 2015 . Since 50 is an even number, and we want the sum of all the odd integers from 1 to 50, the number 50 won't be included in the sum. First Name. In a similar vein to the previous exercise, here is another way of deriving the formula for the sum of the first n n n positive integers. 3) Most importantly, this example shows there are many ways to understand a formula. We want to add 1 bean to 2 beans to 3 beans… all the way up to 5 beans. Thus, the sum of the integers from 1 to 100, which are divisible by 2 or 5, is 3050. 2, 7, 12, .,to 10 term We know that Sum of AP = /2 (2a + (n 1) d) Here n = 10, a = 2, & d = 7 2 = 2 Putting these in formula , Sum = /2 (2a + (n 1) d) = 10/2 (2 2 + (10 1) So we divide the formula above by 2 and get: Now this is cool (as cool as rows of numbers can be). for(i=1;i<=n;i++) sum=sum+i; Sum of Natural Numbers using Formula. 1) Adding up numbers quickly can be useful for estimation. If you can’t see any matches tap the remaining deck to turn over a new card. If we have 100 numbers (1…100), then we clearly have 100 items. 2) Compute some of digits in numbers from 1 … Output 3: Enter the value of n: -10 Enter a whole positive number! Here, we are implementing a C program that will be used to find the sum of all numbers from 0 to N without using loop. Learn more - Program to check odd numbers. Otherwise, we used the mathematical formula of Sum of Series 1 + 2+ 3+ … + N = N * (N + 1) / 2; TIP: If the function is not returning any value then used Void. C Program to Print Sum of all Even Numbers from 1 to n. This program allows the user to enter the maximum limit value. #SumOfNumbers #1to100 How can we calculate the sum of natural numbers? Well, the sum is clearly 1 + 2 + 3 + 4 + 5. 4. In mathematics, summation is the addition of a sequence of any kind of numbers, called addends or summands; the result is their sum or total. But of course, we don’t want the total area (the number of x’s and o’s), we just want the number of x’s. Interview Answers. Let’s add the numbers 1 to 9, but instead of starting from 1, let’s count from 0 instead: By counting from 0, we get an “extra item” (10 in total) so we can have an even number of rows. \sum_{k=1}^n (2k-1) = 2\sum_{k=1}^n k - \sum_{k=1}^n 1 = 2\frac{n(n+1)}2 - n = n^2.\ _\square k = 1 ∑ n (2 k − 1) = 2 k = 1 ∑ n k − k = 1 ∑ n 1 = 2 2 n (n + 1) − n = n 2. To see that, look at this oblong number, in which the base is one more than the height: case 1. please enter the maximum value: 10 The sum of Even numbers 1 to 10 = 30 The sum of odd numbers 1 to 10 = 25. case 2. please enter the maximum value: 100 The sum of Even numbers 1 to 100 = 2550 The sum of odd numbers 1 to 100 = 2500 . clear, insightful math lessons. Just make a for loop from starting 1 to 10, like given below. sum = n(n+1)/2 The program calculates the sum of numbers till the given input. By the way, there are more details about the history of this story and the technique Gauss may have used. Notice in both cases, 1 is on one side of the average and N is equally far away on the other. integer m 6= −1 5. How about even numbers, like 2 + 4 + 6 + 8 + … + n? 2. C Program to print sum of the natural numbers from 1 to 10 # include # include main( ) { int n,sum=0,i; clrscr( ); for (i=1; i<=10; i++) sum=sum+i; printf(“sum of natural numbers from 1 to 10 is %d\\n”,sum); getch( ); } The goal is to clear the tableau by matching pairs of cards that add up to ten. 0. how to find a sum of numbers in a sequence when some intermediate terms are not taken in to consideration? Ex 5.3 ,1 Find the sum of the following APs. However, our formula will look a bit different. Answer Add Tags. Though both programs are technically correct, it is better to use for loop in this case. For these examples we’ll add 1 to 10, and then see how it applies for 1 to 100 (or 1 to any number). We want to get rid of every number from 1 up to a – 1. input this case is 6. Since thousand squared = 1 million, we get million / 2 + 1000/2 = 500,500. sum of n terms= n/2 {2a(n-1)d} where n is no of terms, a is the first term and d is difference, subbed in you get 5{2x9}=90. There is a more simple way to find the sum of odd numbers from 1 to N. The first odd number is 1, then the next odd number is 3, i.e (1+2). Enter n value: 20 Sum of odd numbers from 1 to 20 is: 100. Example 1: Adding all items in a tuple, and returning the result ; Example 1: Starting with the 10, and adding all items in a tuple to this number: Example: Compute the sum and product of the numbers from 1 to 10. C programming, exercises, solution : Write a program in C to calculate the sum of numbers from 1 to n using recursion. The above formula is one core step of the idea. How about odd numbers, like 1 + 3 + 5 + 7 + … + n? I won’t. The difference between consecutive triangles increases by 1.. A formula for the triangular numbers. Telescoping sum X a≤k
sum of 1 to 10 2020


# $n$th Roots of Unity

I need to show that the product of all the $n$th roots of unity is $(−1)^{n+1}$.

Is there a way to do this by induction? If there is, I can't seem to figure it out. Are there other, perhaps more efficient, methods of proof?

-
The problem with attempting to do it "by induction" is that the $n$th roots of unity are not related to the $(n+1)$th roots of unity (except for the single one that they have in common, $1$. –  Arturo Magidin Mar 2 '12 at 4:07
If you're going to do an induction argument, it should be an induction on the number of (possibly repeated) prime divisors of $n$. I think this should actually be possible, with Wilson's Theorem stepping in as a base case. But, honestly, just about anything else seems easier....like all the answers given below. –  Pete L. Clark Mar 2 '12 at 4:28

The $n^{th}$ roots of unity are precisely the roots of the polynomial $$x^n - 1$$ Now use the fact that the product of the roots of any polynomial is $(-1)^n$ times the constant coefficient.

-
Is this fact that the product of the roots of any polynomial is $(−1)^n$ times the constant coefficient true for any polynomial? Can you elaborate on that? –  Dominick Gerard Mar 2 '12 at 4:42
@DominickGerard: Consider writing the polynomial as a product of linear factors, then multiplying it out again. What will the constant term be? Example: $(z-z_1)(z-z_2) = z^2 - (z_1 + z_2) z + z_1 z_2$. –  Antonio Vargas Mar 2 '12 at 4:58
@DominickGerard Yes, it holds for any polynomial with coefficients in an integral domain (including $\mathbb{Z}$ or any field): en.wikipedia.org/wiki/Vieta%27s_formulas –  dls Mar 2 '12 at 5:01

Note that if $\zeta$ is an $n$th root of unity, then so is $\frac{1}{\zeta}$. Moreover, the only roots of unity for which $\zeta=\frac{1}{\zeta}$ are $\zeta=1$ and $\zeta=-1$ (since $\zeta=\frac{1}{\zeta}$ implies $\zeta^2=1$, hence $\zeta=1$ or $\zeta=-1$).

So, if we take the $n$th roots of unity, then we can pair off all of them except for $1$ and perhaps $-1$ (if $n$ is even), into pairs of the form $\{\zeta,\frac{1}{\zeta}\}$. The product of these two equals $1$; so when you do the product of all roots, you end up with a bunch of pairs that multiply to $1$, and you have $1$; and if $n$ is even, then you also have $-1$ leftover. Which means the product of all of them is...

-

Well, you said "efficient" and "elementary number theory", and that triggered this in my mind: the result is a special case of

(Wilson's Theorem in a Finite Abelian Group): Let $(G,\cdot)$ be a finite abelian group, and let $P = \prod_{x \in G} x$. Then $P = 1$ (the identity element) unless $G$ has exactly one element $t$ of order $2$, in which case $P = t$.

This is something that others (in particular, Bill Dubuque) have talked about here and elsewhere before. I include a statement and proof of this in my notes/prebook on elementary(ish...) number theory: it is at the end of Appendix B.

Added: Not only is this a special case of a "generalized Wilson theorem", it's a special case that includes the classical Wilson Theorem! Since the unit group of $(\mathbb{Z}/p\mathbb{Z})^{\times}$ is cyclic of order $p-1$, computing $(p-1)! \pmod{p}$ is essentially the same as multiplying together all the $(p-1)$st roots of unity.

-
+1 See these posts for more on the group-theoretic Wilson's theorem and involutions. –  Bill Dubuque Mar 2 '12 at 4:13
You can prove it with de Moivre, on the basis that the roots are all of the form $e^{2\pi i k/n}$, so their product is $e^{2\pi i/n\sum{k}} = e^{\pi i(n-1)} = (-1)^{n-1} = (-1)^{n+1}$.
Another proof idea would be to notice that the roots of unity come in complex conjugate pairs, which is evident in the symmetry of the spacing of the roots in the complex plain. So the product of each pair is of course $\alpha \bar\alpha = |\alpha| = 1$ since all the roots fall on the unit circle. The only exceptions are $1,-1$. $1$ is always a root and won't change the product, and $-1$ is only a root when $n$ is even, so we conclude that the product is exactly $(-1)^{n+1}$.


#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Options

# Lecture 7 - Universal properties: products, coproducts and exponentials - David Spivak

edited January 21

## Comments

• Options
1.

It was interesting to learn about the relationship between currying, uncurrying, and exponentials. I'd heard people talking about currying before and handwaving, but this lecture made it very concrete. The motivation of set exponentiation (the set of maps) {1, 2, 3}^{1,2} as "3"^"2" ~ 9 maps in total was nice as well.

I also liked the motivation of Either as a pushout from two functions. I recently did a few exercises using Either in scala and ended up getting very confused! So this sort of knowledge would probably have made that experience a bit less confusing.

I noticed that it was mentioned in passing that products, co-products and exponentials are all examples of adjunctions. And I just listened to the first 10 seconds of lecture 8, and I gather that they are discussed therein, so I look forward to reviewing that lecture too in time.

Comment Source:It was interesting to learn about the relationship between currying, uncurrying, and exponentials. I'd heard people talking about currying before and handwaving, but this lecture made it very concrete. The motivation of set exponentiation (the set of maps) {1, 2, 3}^{1,2} as "3"^"2" ~ 9 maps in total was nice as well. I also liked the motivation of Either as a pushout from two functions. I recently did a few exercises using Either in scala and ended up getting very confused! So this sort of knowledge would probably have made that experience a bit less confusing. I noticed that it was mentioned in passing that products, co-products and exponentials are all examples of [adjunctions](https://en.wikipedia.org/wiki/Adjoint_functors). And I just listened to the first 10 seconds of lecture 8, and I gather that they are discussed therein, so I look forward to reviewing that lecture too in time.
• Options
2.
edited March 2020

Yes, it's a good one!

Ideas from the first five minutes (using David Spivak's terminology):

• A universal property is a "one-stop shop" for maps

• The product of sets $$A$$ and $$B$$ is the one-stop shop from maps into $$A$$ and $$B$$.

Meaning: suppose you have a set $$I$$, and maps $$f: I \rightarrow A$$ and $$g: I \rightarrow B$$, with $$f$$ in your "left-hand", and $$g$$ in your right.

These two functions are equivalent to a single function $$f \times g: I \rightarrow A \times B$$.

The set $$I$$ can be thought of as an "index" set which is used to pick out elements via the functions out of $$I$$.

When $$I$$ is a singleton, the "one-stop shop" gives you a single element in the product of $$A$$ and $$B$$, in lieu of two separate elements one from $$A$$ and the other from $$B$$.

Comment Source:Yes, it's a good one! Ideas from the first five minutes (using David Spivak's terminology): * A universal property is a "one-stop shop" for maps * The product of sets \$$A\$$ and \$$B\$$ is the one-stop shop from maps into \$$A\$$ and \$$B\$$. Meaning: suppose you have a set \$$I\$$, and maps \$$f: I \rightarrow A\$$ and \$$g: I \rightarrow B\$$, with \$$f\$$ in your "left-hand", and \$$g\$$ in your right. These two functions are equivalent to a single function \$$f \times g: I \rightarrow A \times B\$$. The set \$$I\$$ can be thought of as an "index" set which is used to pick out elements via the functions out of \$$I\$$. When \$$I\$$ is a singleton, the "one-stop shop" gives you a single element in the product of \$$A\$$ and \$$B\$$, in lieu of two separate elements one from \$$A\$$ and the other from \$$B\$$.
• Options
3.
• The coproduct of $$A$$ and $$B$$ is the "one-stop shop" for maps into $$A$$ and $$B$$.
Comment Source:* The coproduct of \$$A\$$ and \$$B\$$ is the "one-stop shop" for maps into \$$A\$$ and \$$B\$$.
• Options
4.
edited March 2020

Thinking out loud here...

The idea of the "one-stop shop for maps" generalizes nicely from the product to the limit.

Looking at the general case of the limit, which includes as special cases terminal objects, products, equalizers and pullbacks, brings clarity to the whole picture. And in the category Set, there is an explicit construction for all limits.

To review: suppose we are given a diagram D in the category C. Note: for this definition, D is not required to be a commuting diagram -- it's just a collection of objects and arrows.

The limit of D, if it exists, will be another object Lim(D) in C, along with "projection maps" from Lim(D) to each of the objects in D, which satisfies a couple of conditions. First, for every arrow $$f: X_1 \rightarrow X_2$$ in D, the triangle diagram with objects Lim(D), $$X_1$$, and $$X_2$$ and arrows $$f$$ and the two projections from Lim(D) to $$X_1$$ and $$X_2$$ -- this triangle diagram commutes.

Lim(D) along with these projections is called a cone over D. The cones over D form a category, with arrows going between the apexes of the cones, such that these arrows satisfy the following commutativity condition with respect to the cones. Suppose that $$X$$ and $$Y$$ are each the apex of a cone, and $$f: X \rightarrow Y$$. Then $$f$$ is defined to be a morphism between the two cones if for each object $$d$$ in D, the triangle formed by $$d$$, $$X$$ and $$Y$$, with arrows $$f$$ and the two projections to $$d$$ -- one projection within each cone -- commutes.

The second requirement on Lim(D) is that it be a terminal object in this category of cones.

Comment Source:Thinking out loud here... The idea of the "one-stop shop for maps" generalizes nicely from the product to the limit. Looking at the general case of the limit, which includes as special cases terminal objects, products, equalizers and pullbacks, brings clarity to the whole picture. And in the category Set, there is an explicit construction for all limits. To review: suppose we are given a diagram D in the category C. Note: for this definition, D is not required to be a _commuting_ diagram -- it's just a collection of objects and arrows. The limit of D, if it exists, will be another object Lim(D) in C, along with "projection maps" from Lim(D) to each of the objects in D, which satisfies a couple of conditions. First, for every arrow \$$f: X_1 \rightarrow X_2\$$ in D, the triangle diagram with objects Lim(D), \$$X_1\$$, and \$$X_2\$$ and arrows \$$f\$$ and the two projections from Lim(D) to \$$X_1\$$ and \$$X_2\$$ -- this triangle diagram commutes. Lim(D) along with these projections is called a cone over D. The cones over D form a category, with arrows going between the apexes of the cones, such that these arrows satisfy the following commutativity condition with respect to the cones. Suppose that \$$X\$$ and \$$Y\$$ are each the apex of a cone, and \$$f: X \rightarrow Y\$$. Then \$$f\$$ is defined to be a morphism between the two cones if for each object \$$d\$$ in D, the triangle formed by \$$d\$$, \$$X\$$ and \$$Y\$$, with arrows \$$f\$$ and the two projections to \$$d\$$ -- one projection within each cone -- commutes. The second requirement on Lim(D) is that it be a terminal object in this category of cones.
• Options
5.
edited March 2020

Now that's somewhat of an abstract story, which doesn't give you a feeling for how to actually find what this special cone Lim(D) actually is. And in general such an object may not exist at all.

But in the category Set it always exists, and can be constructed explicitly, as follows.

Comment Source:Now that's somewhat of an abstract story, which doesn't give you a feeling for how to actually find what this special cone Lim(D) actually is. And in general such an object may not exist at all. But in the category Set it always exists, and can be constructed explicitly, as follows.
• Options
6.
edited March 2020

Suppose we have a diagram $$D$$ in Set. Let the objects in $$D$$ be named $$S_1, \ldots S_n$$, where each $$S_i$$ is a set. Let the arrows in $$D$$ be $$f_1, \ldots f_k$$ -- these are functions.

Then Lim(D) consists of a subset of the Cartesian product of the set $$S_1, \ldots S_n$$ -- so it is a relation R between these sets. It consists of all tuples $$(x_1, \ldots, x_n)$$ that satisfy the all of the constraints given by the functions $$f_i$$. Suppose $$f_i: S_j \rightarrow S_k$$. Then the constraint given by $$f_i$$ stipulates that for a tuple $$(x_1, \ldots, x_n)$$, that $$f_i(x_j) = x_k$$.

The cone has relation R at its apex, and the ordinary projection functions from R to each of the sets $$S_1, \ldots, S_n$$ as the arrows from the apex R to the objects in the diagram $$D$$.

It is but an exercise to show that this cone with R at its apex is terminal within the category of cones over $$D$$.

Comment Source:Suppose we have a diagram \$$D\$$ in Set. Let the objects in \$$D\$$ be named \$$S_1, \ldots S_n\$$, where each \$$S_i\$$ is a set. Let the arrows in \$$D\$$ be \$$f_1, \ldots f_k\$$ -- these are functions. Then Lim(D) consists of a subset of the Cartesian product of the set \$$S_1, \ldots S_n\$$ -- so it is a relation R between these sets. It consists of all tuples \$$(x_1, \ldots, x_n)\$$ that satisfy the all of the constraints given by the functions \$$f_i\$$. Suppose \$$f_i: S_j \rightarrow S_k\$$. Then the constraint given by \$$f_i\$$ stipulates that for a tuple \$$(x_1, \ldots, x_n)\$$, that \$$f_i(x_j) = x_k\$$. The cone has relation R at its apex, and the ordinary projection functions from R to each of the sets \$$S_1, \ldots, S_n\$$ as the arrows from the apex R to the objects in the diagram \$$D\$$. It is but an exercise to show that this cone with R at its apex is terminal within the category of cones over \$$D\$$.
• Options
7.

The relation R = Lim(D) is a one-stop shop for cones over D, in the following sense. Suppose that we have a cone C with apex A over D. Then C consists of a bunch of separate maps from A into the objects of D. The universal property for R = Lim(D) says that there a unique map m(C) from A into R, which gives a morphism from C into the universal cone with apex Lim(D).

m(C) is a single map that contains all of the information in C. That's because the projections from C into the objects of D can be reconstructed by composing m(C) with the standard projections from R into the objects of D.

So the multiple separate maps comprising the cone C can, without loss of information, be replaced by the single map m(C).

Comment Source:The relation R = Lim(D) is a one-stop shop for cones over D, in the following sense. Suppose that we have a cone C with apex A over D. Then C consists of a bunch of separate maps from A into the objects of D. The universal property for R = Lim(D) says that there a unique map m(C) from A into R, which gives a morphism from C into the universal cone with apex Lim(D). m(C) is a single map that contains all of the information in C. That's because the projections from C into the objects of D can be reconstructed by composing m(C) with the standard projections from R into the objects of D. So the multiple separate maps comprising the cone C can, without loss of information, be replaced by the single map m(C).
• Options
8.
edited March 2020

For an illustration of this construction, let's apply it to the equalizer.

Here, the diagram D consists of two objects $$X_1, X_2$$, and two maps $$f,g: X_1 \rightarrow X_2$$.

Note: here the fact that D is not required to be a commutative diagram is significant. If it were so required, then that would imply that $$f$$ and $$g$$ are equal. But we don't require that, as we are constructing the equalizer of distinct maps $$f$$ and $$g$$.

Then, as per the general construction given above, the relation R = Lim(D) will consist of all tuples $$(x,y)$$, such that $$f(x) = y$$, and $$g(x) = y$$. Putting these together, we get that:

$equalizer(f,g) = Lim(D) = \lbrace (x,y)\ |\ y = f(x) = g(x) \rbrace = \lbrace (x,y)\ |\ x \in dom(f) \cap dom(g),\ f(x) = g(x)\rbrace = f \cap g$

Which is to say: the equalizer of functions $$f$$ and $$g$$ is the relation (the graph representation) for the partial function that is obtained by restricting both functions to the set of points where they are both defined and both produce the same value.

Comment Source:For an illustration of this construction, let's apply it to the equalizer. Here, the diagram D consists of two objects \$$X_1, X_2\$$, and two maps \$$f,g: X_1 \rightarrow X_2\$$. Note: here the fact that D is not required to be a _commutative_ diagram is significant. If it were so required, then that would imply that \$$f\$$ and \$$g\$$ are equal. But we don't require that, as we are constructing the equalizer of distinct maps \$$f\$$ and \$$g\$$. Then, as per the general construction given above, the relation R = Lim(D) will consist of all tuples \$$(x,y)\$$, such that \$$f(x) = y\$$, and \$$g(x) = y\$$. Putting these together, we get that: \$equalizer(f,g) = Lim(D) = \lbrace (x,y)\ |\ y = f(x) = g(x) \rbrace = \lbrace (x,y)\ |\ x \in dom(f) \cap dom(g),\ f(x) = g(x)\rbrace = f \cap g\$ Which is to say: the equalizer of functions \$$f\$$ and \$$g\$$ is the relation (the graph representation) for the partial function that is obtained by restricting both functions to the set of points where they are both defined and both produce the same value.
• Options
9.
edited March 2020

We get the product as a special case of a limit, where the diagram $$D$$ consists only of objects, and no arrows.

In Set, this will be a collection of sets $$S_1, \ldots, S_n$$ -- and no arrows to impose constraints on the tuples in R = Lim(D).

So Lim(D) is the unconstrained set of tuples -- i.e., the Cartesian product $$S_1 \times \cdots \times S_n$$.

Comment Source:We get the _product_ as a special case of a limit, where the diagram \$$D\$$ consists only of objects, and no arrows. In Set, this will be a collection of sets \$$S_1, \ldots, S_n\$$ -- and no arrows to impose constraints on the tuples in R = Lim(D). So Lim(D) is the unconstrained set of tuples -- i.e., the Cartesian product \$$S_1 \times \cdots \times S_n\$$.
• Options
10.

What's the limit of an empty diagram $$D$$?

It's simply a terminal object in the category, for the following reason.

A cone over the empty diagram consists just of an apex object A, along with zero "leg" morphisms.

So the category of cones over the empty diagram coincides exactly with the ambient category C.

The limit is defined to be a terminal cone, which amounts to the same thing as a terminal object in C.

Comment Source:What's the limit of an empty diagram \$$D\$$? It's simply a terminal object in the category, for the following reason. A cone over the empty diagram consists just of an apex object A, along with zero "leg" morphisms. So the category of cones over the empty diagram coincides exactly with the ambient category C. The limit is defined to be a terminal cone, which amounts to the same thing as a terminal object in C.
• Options
11.
edited March 2020

Exercise 1. Use this construction to concretely explain the meaning of pullbacks in Set.

Recall that a pullback is defined as the limit of a diagram $$D$$, consisting of three objects $$A,B,C$$, and morphims $$f: A \rightarrow C$$ and $$g: B \rightarrow C$$.

Comment Source:Exercise 1. Use this construction to concretely explain the meaning of pullbacks in Set. Recall that a pullback is defined as the limit of a diagram \$$D\$$, consisting of three objects \$$A,B,C\$$, and morphims \$$f: A \rightarrow C\$$ and \$$g: B \rightarrow C\$$.
• Options
12.
edited March 2020

\begin{CD} A \cap B @>\subseteq>>B \\@V{\subseteq}VV {}@VV{\subseteq}V \\ A @>>\subseteq> C \end{CD}

Here, $$C$$ is taken to be any set which contains both $$A$$ and $$B$$, and $$\subseteq$$ means the inclusion function.

Diagram from Example 1.8.3 of:

• Benjamin C. Pierce, Basic Category Theory for Computer Scientists, MIT Press, 1991.
• Options
13.
edited March 2020

\begin{CD} f^{-1}(A) @>\subseteq>>B \\@V{f|_{f^{-1}(A)}}VV {}@VV{f}V \\ A @>>\subseteq> C \end{CD}

Here, $$A$$ is a subset of the codomain of $$f$$. The claim made by this diagram is that inverse image of $$A$$ under $$f$$ is the pullback of $$f$$ along the inclusion function for $$A$$.

Diagram from Example 1.8.2 of:

• Benjamin C. Pierce, Basic Category Theory for Computer Scientists, MIT Press, 1991.
• Options
14.
edited March 2020

@ChrisGoddard wrote:

I noticed that it was mentioned in passing that products, co-products and exponentials are all examples of adjunctions.

Interesting! Keep us posted if you dig further into this.

Comment Source:@ChrisGoddard wrote: > I noticed that it was mentioned in passing that products, co-products and exponentials are all examples of [adjunctions](https://en.wikipedia.org/wiki/Adjoint_functors). Interesting! Keep us posted if you dig further into this.
• Options
15.
edited March 2020

Problem 1: spell out the explicit construction for colimits in the category Set.

The path of analysis is similar to that used for the explicit construction for limits. But the result is not "symmetrical." In one of the lectures Bartosz commented on the asymmetry between product and coproduct in Set. He traced it back to some asymmetries in the structure of the morphisms in Set, which as we know are total functions. The asymmetry is that whereas each point in the domain must map -- be related to -- to just one point in the codomain, each point in the codomain can be related to zero points in the domain (where the function is not onto), or multiple points in the domain (where the function is not one-to-one).

Comment Source:Problem 1: spell out the explicit construction for colimits in the category Set. The path of analysis is similar to that used for the explicit construction for limits. But the result is not "symmetrical." In one of the lectures Bartosz commented on the asymmetry between product and coproduct in Set. He traced it back to some asymmetries in the structure of the morphisms in Set, which as we know are total functions. The asymmetry is that whereas each point in the domain must map -- be related to -- to just one point in the codomain, each point in the codomain can be related to zero points in the domain (where the function is not onto), or multiple points in the domain (where the function is not one-to-one).
• Options
16.

Problem 2: use this construction to give a concrete explanation for coequalizers, coproducts, pushouts and initial objects in Set.

Comment Source:Problem 2: use this construction to give a concrete explanation for coequalizers, coproducts, pushouts and initial objects in Set.
Sign In or Register to comment.


# Math Help - Finding Riemann sums

1. ## Finding Riemann sums

The question:

An electrical signal S(t) has its amplitude |S(t)| tested (sampled) every 1/10 of a second. It is desired to estimate the energy over a period of half a second, given exactly by:

$(\int_0^\frac{1}{2} \! |S(t)|^2 \, \mathrm{d}t)^{\frac{1}{2}}$

The result of the measurement are shown in the following table:
$\begin{center}
\begin{tabular}{| l | c | c| c| c| c|}
\hline
t & .1 & .2 & .3 & .4 & .5\\ \hline
\| S(t) \| & 60 & 50 & 50 & 45 & 55 \\ \hline
e(t) & 5 & 3 & 7 & 4 & 10 \\
\hline
\end{tabular}
\end{center}$

a) Using the above data for S(t), set up the appropriate Riemann sum and compute an appropriate value for the energy.

My attempt:
The set P (set of partitions) is clearly equal to {0, 1/10, 1/5, 3/10, 4/10, 1/2} so dt is 1/10 i.e. the width of each rectangle is 1/10.

My problem is with producing lower and higher Riemann sums. I'm used to having a function defined as something like $x^2$ and producing a general sum given dx (in this case, dt). In this question, we don't know the function, we're just given values.

Does this mean I take the max/min of each interval (e.g. [0, 1/10], [1/10, 1/5] etc.) and work out the partitions by hand? I'm a bit confused.

Any help would be greatly appreciated!

2. Originally Posted by Glitch
The question:

An electrical signal S(t) has its amplitude |S(t)| tested (sampled) every 1/10 of a second. It is desired to estimate the energy over a period of half a second, given exactly by:

$(\int_0^\frac{1}{2} \! |S(t)|^2 \, \mathrm{d}t)^{\frac{1}{2}}$

The result of the measurement are shown in the following table:
$\begin{center}
\begin{tabular}{| l | c | c| c| c| c|}
\hline
t & .1 & .2 & .3 & .4 & .5\\ \hline
\| S(t) \| & 60 & 50 & 50 & 45 & 55 \\ \hline
e(t) & 5 & 3 & 7 & 4 & 10 \\
\hline
\end{tabular}
\end{center}$

a) Using the above data for S(t), set up the appropriate Riemann sum and compute an appropriate value for the energy.

My attempt:
The set P (set of partitions) is clearly equal to {0, 1/10, 1/5, 3/10, 4/10, 1/2} so dt is 1/10 i.e. the width of each rectangle is 1/10.

My problem is with producing lower and higher Riemann sums. I'm used to having a function defined as something like $x^2$ and producing a general sum given dx (in this case, dt). In this question, we don't know the function, we're just given values.

Does this mean I take the max/min of each interval (e.g. [0, 1/10], [1/10, 1/5] etc.) and work out the partitions by hand? I'm a bit confused.

Any help would be greatly appreciated!
left sum ... L = 0.1[S(0) + S(.1) + S(.2) + S(.3) + S(.4)]

right sum ... R = 0.1[S(.1) + S(.2) + S(.3) + S(.4) + S(.5)]

the table does not give a value for S(0), so it looks as though you can only compute the right sum.

3. Inside each interval you are given only two values- the values at the two endpoints. For the "lower sum" use the smaller of those two, for the "higher sum" use the larger.

In the first interval, from 0.1 to 0.2, you are given exactly two values- 60 and 50. The "lower sum" uses the smaller of those, 50, and the "higher sum" uses the higher, 60. Between .2 and .3 your two values are 50 and 50. Since those are the same, use 50 for both sums. Between .3 and .4, the two values are 50 and 45. Use 45 for the "lower sum" and 50 for the "higher sum". Finally, between .4 and .5, the two values are 45 and 55. Use 45 for the lower sum and 55 for the higher sum.

Summarizing, for the "lower sum" use 50, 50, 45, and 45. For the "higher sum" use 60, 50, 50, and 55.

4. For the lower sum I used: 0, 50, 50, 45, 45
I squared each (as per the function), and multiplied them by 1/10 to produce the area of each partition. My result was 905.

For the higher sum I used: 60, 60, 50, 50, 55
Again, I squared each, and multiplied by 1/10. My result was 1522.5

I took the average of the higher and lower sums, to get 1213.75. As per the question, the integral is to the power of 1/2, so I took the square root and got 34.84. However, the solution in my text is 36.95 (or square root of 1365).

I'm not sure where I went wrong. My answer is close, but incorrect. :/

Edit: I just realised that using '0' for the lower sum isn't correct. I used 60 instead, but I get 1393.75 which is slightly off the given solution.


# Find all pairs of $(x, y ,z)$ such that $x + y =\sqrt{z^{2} + 2018}, …$

Find all pairs of $(x,y,z)$, of real numbers, such that

$$x + y = \sqrt{z^{2} + 2018}$$ $$x + z = \sqrt{y^{2} + 2018}$$ $$y + z = \sqrt{x^{2} + 2018}$$

An attempt : Squaring we get $$(x + y)^{2} = z^{2} + 2018 \implies (x + y)^{2} - z^{2} = 2018$$ $$(x + z)^{2} = y^{2} + 2018 \implies (x + z)^{2} - y^{2} = 2018$$ $$(y + z)^{2} = x^{2} + 2018 \implies (z + y)^{2} - x^{2} = 2018$$ which also means $$(x + y - z)(x + y + z) = 2018$$ $$(x + z - y)(x + y + z) = 2018$$ $$(z + y - x)(x + y + z) = 2018$$ so $$\frac{2018}{x+y-z} = \frac{2018}{x+z-y} = \frac{2018}{y+z-x}$$

$$(x+y-z) = (x+z-y) = (y+z-x)$$ $$y-z = z-y \implies z = y$$ $$x-y= y-x \implies x=y$$ so my answer is $$(x, y, z), \:\:\: x=y=z$$ but with the 3 initial equations, we must also have $$(x+y) = \sqrt{z^{2} + 2018} \implies 4x^{2} = x^{2} + 2018$$ or $$x^{2} = 2018/3$$ so the solution is $$(x, y, z), \:\:\: x=y=z = \sqrt{2018/3}$$

Is this sufficient already? are there better techniques?

• Doesn't $x=y=z$ Imply $2x = \sqrt{x^{2} + 2018}$ from which you can solve for $x$? – Jim Haddocc Mar 30 '18 at 16:16
• The equation can be rewritten as $x + y + z = f(x) = f(y) = f(z)$ where $f(t) = t + \sqrt{t^2+2018}$. The function $f$ is strictly increasing, so $f(x) = f(y) = f(z) \implies \cdots$ – achille hui Mar 30 '18 at 16:22
• Indeed, we get $$x=y=z=\sqrt{\frac{2018}{3}}$$ – Dr. Sonnhard Graubner Mar 30 '18 at 16:25
• @PrathyushPoduval yes, thanks for that, i was meant that way. I have edited the post – Arief Anbiya Mar 30 '18 at 16:26
• Just the condition that $z^2+m$ is a square implies that$z^2+m \ge (z+1)^2$ or $z \le (m-1)/2$. – marty cohen Mar 30 '18 at 16:29

At the stage you have... $$(x + y - z)(x + y + z) = 2018$$ $$(x + z - y)(x + y + z) = 2018$$ $$(z + y - x)(x + y + z) = 2018$$ This implies... $$x+y-z=x+z-y=z+y-x=\dfrac{2018}{x+y+z}$$ ...unless $x+y+z=0$.

Notice that $x+y+z=0$ implies $x+y=-z$ and so $-z=\sqrt{z^2+2018}$ which means $z^2=z^2+2018$ and so $z=0$. Likewise, $x=y=0$ (contradiction since $(0,0,0)$ isn't a solution).

Thus $x+y-z=x+z-y=z+y-x$ and so you got that $x=y=z$. But then $x+y=\sqrt{z^2+2018}$ implies that $2z=\sqrt{z^2+2018}$ and so $4z^2=z^2+2018$ and so $x=y=z = \pm \sqrt{\dfrac{2018}{3}}$. But $x+y$ etc. are square roots (thus non negative). So there is only one solution.

• Thanks for the answer, but i think negative value of $x=y=z < 0$ is not allowed. This is because the 3 initial equations hold. – Arief Anbiya Mar 30 '18 at 16:42
• Silly me. You are correct. – Bill Cook Mar 30 '18 at 17:15


# How can I prove that the span of a subspace and its orthogonal complement is the whole vector space?

The book Linear and Geometric Algebra explains the following theorem in a way that I haven't been able to figure out:

If $\mathbf{A}$ and $\mathbf{B}$ are subspaces of a vector space $\mathbf{B}$ then the set of all combinations $\mathbf{a} + \mathbf{b}$ such that, $\mathbf{a} \in \mathbf{A}$ and $\mathbf{b} \in \mathbf{B}$ is called the span of $\mathbf{A}$ and $\mathbf{B}$, written as $\text{span}(\mathbf{A}, \mathbf{B})$.

Furthermore let $\mathbf{U}^{\bot}$ be the subspace consisting of all vectors orthogonal to a subspace $\mathbf{U}$, in the sense that $\mathbf{u} \in \mathbf{U}^{\top}$ if and only if, $\mathbf{u} \perp \mathbf{v}$ for all vectors $\mathbf{v} \in \mathbf{U}$.

I have of course been able to prove that $\mathbf{U}^{\bot}$ is indeed a subspace for all subspaces $\mathbf{U}$, if this turns out to be useful.

The theorem I want to prove is: if $\mathbf{U}$ is a subspace of $\mathbf{V}$ then $\text{span}(\mathbf{U}, \mathbf{U}^{\perp}) = \mathbf{V}$.

The book mentioned above proves it as follows: If $\text{span}(\mathbf{U}, \mathbf{U}^{\perp}) \neq \mathbf{V}$ then there is a nonzero $\mathbf{u} \perp \text{span}(\mathbf{U}, \mathbf{U}^{\perp})$ because any orthonormal basis for a subspace of an inner product space can be extended into an orthonormal basis for the entire inner product space. In particular $\mathbf{u} \perp \mathbf{U}$, i.e. $\mathbf{u} \in \mathbf{U}^{\perp}$, a contradiction.

I understand how an orthonormal basis for a subspace of an inner product space can be extended into an orthonormal basis for the whole inner product space essentially using Gram-Schmidt orthogonalisation. I don't understand how this process allows you to go from, $\text{span}(\mathbf{U}, \mathbf{U}^{\perp}) \neq \mathbf{V}$ to $\exists \mathbf{u} \in \mathbf{U} : \mathbf{u} \perp \text{span}(\mathbf{U}, \mathbf{U}^{\perp})$. So my question would be how does this implication work?

• Possible duplicate of math.stackexchange.com/questions/878438/…
– Surb
Aug 13, 2014 at 13:34
• It seems to me that such statement holds only if $U$ is closed -- this is satisfied if everything is finite dimensional, for example.. Aug 13, 2014 at 13:35
• Here's a counter-example for infinite dimensional spaces: math.stackexchange.com/questions/636517/…
– Surb
Aug 13, 2014 at 13:37
• Sure, the book I'm using is only on finite dimensional vector spaces. Aug 13, 2014 at 13:37
• I don't think this question is a duplicate of that one because the proof in question is quite different, that one is constructive, this one is a proof by contradiction. Aug 13, 2014 at 13:41

You pick an orthonormal basis for $\text{span}(\mathbf{U}, \mathbf{U}^{\perp}) \neq \mathbf{V}$, say $e_j$, $1\leq j\leq n$. Extend this to an orthonormal basis for $\mathbf{V}$, $e_j$, $1\leq j\leq m$. Since $\text{span}(\mathbf{U}, \mathbf{U}^{\perp}) \neq \mathbf{V}$, $n<m$. But then $u=e_{n+1}\perp\text{span}(\mathbf{U}, \mathbf{U}^{\perp})$, by construction, and thus $u\perp \mathbf{U}$, i.e. $u\in \mathbf{U}^\perp$, and thus $u\perp u$, i.e. $\|u\|=0$. This is a contradiction, since $\|u\|=1$.
Note that $$Null(U)=U^\perp$$ now by the rank-nullity theorem we have $$Null(U)+Rank(U)=n$$, where n is the dimension of $$\mathbb{R}^n$$. Now we can use basis extension to combine the basis for $$U$$ and $$U^\perp$$. Since $$U+U^\perp$$ is a subspace of $$\mathbb{R}^n$$, and the basis for $$U+U^\perp$$ has n vectors (by rank nullity thorem before), the same amount of vectors needed to span $$\mathbb{R}^n$$, by the $$Dimension\text{ }Theorem$$ the basis for $$U\cup U^\perp$$ is also a basis to $$\mathbb{R}^n$$ (It takes any set of n linearly independent vectors for them to span a subspace of dimension n). Therefore $$U\cup U^\perp$$=$$\mathbb{R}^n$$ I'm not sure how rigorous this proof is, I like the one above better as well. I just forgot this and looked up a proof, but also wanted to find my own after reading Jonas'. This idea definitely works and I thought I'd share it as an alternative.


## Unit10.1.1Subspace iteration with a Hermitian matrix

The idea behind subspace iteration is to perform the Power Method with more than one vector in order to converge to (a subspace spanned by) the eigenvectors associated with a set of eigenvalues.

We continue our discussion by restricting ourselves to the case where $A \in \Cmxm$ is Hermitian. Why? Because the eigenvectors associated with distinct eigenvalues of a Hermitian matrix are mutually orthogonal (and can be chosen to be orthonormal), which will simplify our discussion. Here we repeat the Power Method:

\begin{equation*} \begin{array}{lll} v_0 := \mbox{ random vector} \\ v_0^{(0)} := v_0 / \| v_0 \|_2 \amp \amp \mbox{ normalize to have length one } \\ {\bf for~} k:=0, \ldots \\ ~~~ v_0 := A v_0^{(k)} \\ ~~~ v_0^{(k+1)} := v_0 / \| v_0 \|_2 \amp \amp \mbox{ normalize to have length one } \\ {\bf endfor} \end{array} \end{equation*}

In previous discussion, we used $v^{(k)}$ for the current approximation to the eigenvector. We now add the subscript to it, $v_0^{(k)} \text{,}$ because we will shortly start iterating with multiple vectors.

###### Homework10.1.1.1.

You may want to start by executing  git pull to update your directory  Assignments.

Examine Assignments/Week10/matlab/PowerMethod.m which implements

[ lambda_0, v0 ] = PowerMethod( A, x, maxiters, illustrate, delay )

This routine implements the Power Method, starting with a vector x for a maximum number of iterations maxiters or until convergence, whichever comes first. To test it, execute the script in Assignments/Week10/matlab/test_SubspaceIteration.m which uses the Power Method to compute the largest eigenvalue (in magnitude) and corresponding eigenvector for an $m \times m$ Hermitian matrix $A$ with eigenvalues $1, \ldots, m \text{.}$

Be sure to click on "Figure 1" to see the graph that is created.

Solution

Watch the video regarding this problem on YouTube: https://youtu.be/8Bgf1tJeMmg. (embedding a video in a solution seems to cause PreTeXt trouble...)

Recall that when we analyzed the convergence of the Power Method, we commented on the fact that the method converges to an eigenvector associated with the largest eigenvalue (in magnitude) if two conditions are met:

• $\vert \lambda_0 \vert \gt \vert \lambda_1 \vert \text{.}$

• $v_0^{(0)}$ has a component in the direction of the eigenvector, $x_0 \text{,}$ associated with $\lambda_0 \text{.}$

A second initial vector, $v_1^{(0)} \text{,}$ does not have a component in the direction of $x_0$ if it is orthogonal to $x_0 \text{.}$ So, if we know $x_0 \text{,}$ then we can pick a random vector, subtract out the component in the direction of $x_0 \text{,}$ and make this our vector $v_1^{(0)}$ with which we should be able to execute the Power Method to find an eigenvector, $x_1 \text{,}$ associated with the eigenvalue that has the second largest magnitude, $\lambda_1$ . If we then start the Power Method with this new vector (and don't introduce roundoff error in a way that introduces a component in the direction of $x_0$), then the iteration will home in on a vector associated with $\lambda_1$ (provided $A$ is Hermitian, $\vert \lambda_1 \vert \gt \vert \lambda_2 \vert \text{,}$ and $v_1^{(0)}$ has a component in the direction of $x_1 \text{.}$) This iteration would look like

\begin{equation*} \begin{array}{lll} x_0 := x_0 / \| x_0 \|_2 \amp \mbox{ } \amp \mbox{ normalize known eigenvector } x_0 \mbox{ to have length one } \\ v_1 := \mbox{ random vector} \\ v_1 := v_1 - x_0^Hv_1 x_0 \amp \amp \mbox{ make sure the vector is orthogonal to } x_0 \\ v_1^{(0)} := v_1 / \| v_1 \|_2 \amp \amp \mbox{ normalize to have length one } \\ {\bf for~} k:=0, \ldots \\ ~~~ v_1 := A v_1^{(k)} \\ ~~~ v_1^{(k+1)} := v_1 / \| v_1 \|_2 \amp \amp \mbox{ normalize to have length one } \\ {\bf endfor} \end{array} \end{equation*}
###### Homework10.1.1.2.

Copy Assignments/Week10/matlab/PowerMethod.m into PowerMethodLambda1.m. Modify it by adding an input parameter x0, which is an eigenvector associated with $\lambda_0$ (the eigenvalue with largest magnitude).

[ lambda_1, v1 ] = PowerMethodLambda1( A, x, x0, maxiters, illustrate, delay )

The new function should subtract this vector from the initial random vector as in the above algorithm.

Modify the appropriate line in Assignments/Week10/matlab/test_SubspaceIteration.m, changing (0) to (1), and use it to examine the convergence of the method.

What do you observe?

Solution

Watch the video regarding this problem on YouTube: https://youtu.be/48HnBJmQhX8. (embedding a video in a solution seems to cause PreTeXt trouble...)

Because we should be concerned about the introduction of a component in the direction of $x_0$ due to roundoff error, we may want to reorthogonalize with respect to $x_0$ in each iteration:

\begin{equation*} \begin{array}{lll} x_0 := x_0 / \| x_0 \|_2 \amp \mbox{ } \amp \mbox{ normalize known eigenvector } x_0 \mbox{ to have length one } \\ v_1 := \mbox{ random vector} \\ v_1 := v_1 - x_0^Hv_1 x_0 \amp \amp \mbox{ make sure the vector is orthogonal to } x_0 \\ v_1^{(0)} := v_1 / \| v_1 \|_2 \amp \amp \mbox{ normalize to have length one } \\ {\bf for~} k:=0, \ldots \\ ~~~ v_1 := A v_1^{(k)} \\ ~~~ v_1 := v_1 - x_0^Hv_1 x_0 \amp \amp \mbox{ make sure the vector is orthogonal to } x_0 \\ ~~~ v_1^{(k+1)} := v_1 / \| v_1 \|_2 \amp \amp \mbox{ normalize to have length one } \\ {\bf endfor} \end{array} \end{equation*}
###### Homework10.1.1.3.

Copy PowerMethodLambda1.m into PowerMethodLambda1Reorth.m and modify it to reorthogonalize with respect to x0:

[ lambda_1, v1 ] = PowerMethodLambda1Reorth( A, x, v0, maxiters, illustrate, delay  );

Modify the appropriate line in Assignments/Week10/matlab/test_SubspaceIteration.m, changing (0) to (1), and use it to examine the convergence of the method.

What do you observe?

Solution

Watch the video regarding this problem on YouTube: https://youtu.be/YmZc2oq02kA. (embedding a video in a solution seems to cause PreTeXt trouble...)

We now observe that the steps that normalize $x_0$ to have unit length and then subtract out the component of $v_1$ in the direction of $x_0 \text{,}$ normalizing the result, are exactly those performed by the Gram-Schmidt process. More generally, it is is equivalent to computing the QR factorization of the matrix $\left( \begin{array}{c|c} x_0 \amp v_1 \end{array} \right).$ This suggests the algorithm

\begin{equation*} \begin{array}{l} v_1 := \mbox{ random vector} \\ ( \left( \begin{array}{c | c} x_0 \amp v_1^{(0)} \end{array} ), R \right) := {\rm QR}( \left( \begin{array}{c | c} x_0 \amp v_1 \end{array} \right) ) \\ {\bf for~} k:=0, \ldots \\ ~~~( \left( \begin{array}{c | c} x_0 \amp v_1^{(k+1)} \end{array} \right), R ) := {\rm QR}( \left( \begin{array}{c | c} x_0 \amp A v_1^{(k)} \end{array} \right) ) \\ {\bf endfor} \end{array} \end{equation*}

Obviously, this redundantly normalizes $x_0 \text{.}$ It puts us on the path of a practical algorithm for computing the eigenvectors associated with $\lambda_0$ and $\lambda_1 \text{.}$

The problem is that we typically don't know $x_0$ up front. Rather than first using the power method to compute it, we can instead iterate with two random vectors, where the first converges to a vector associated with $\lambda_0$ and the second to one associated with $\lambda_1 \text{:}$

\begin{equation*} \begin{array}{l} v_0 := \mbox{ random vector} \\ v_1 := \mbox{ random vector} \\ ( \left( \begin{array}{c | c} v_0^{(0)}\amp v_1^{(0)} \end{array} ), R \right) := {\rm QR}( \left( \begin{array}{c | c} v_0 \amp v_1 \end{array} \right) ) \\ {\bf for~} k:=0, \ldots \\ ~~~( \left( \begin{array}{c | c} v_0^{(k+1)} \amp v_1^{(k+1)} \end{array} \right), R ) := {\rm QR}( A \left( \begin{array}{c | c} v_0^{(k)} \amp v_1^{(k)} \end{array} \right) ) \\ {\bf endfor} \end{array} \end{equation*}

We observe:

• If $\vert \lambda_0 \vert \gt \vert \lambda_1 \vert \text{,}$ the vectors $v_0^{(k)}$ will converge linearly to a vector in the direction of $x_0$ at a rate dictated by the ratio $\vert \lambda_1 \vert / \vert \lambda_0 \vert \text{.}$

• If $\vert \lambda_0 \vert \gt \vert \lambda_1 \vert \gt \vert \lambda_2 \vert, \text{,}$ the vectors $v_1^{(k)}$ will converge linearly to a vector in the direction of $x_1$ at a rate dictated by the ratio $\vert \lambda_2 \vert / \vert \lambda_1 \vert \text{.}$

• If $\vert \lambda_0 \vert \geq \vert \lambda_1 \vert \gt \vert \lambda_2 \vert$ then $\Span( \{ v_0^{(k)}, v_1^{(k)} \} )$ will eventually start approximating the subspace $\Span( \{ x_0, x_1 \} ) \text{.}$

What we have described is a special case of subspace iteration. The associated eigenvalue can be approximated via the Rayleigh quotient:

\begin{equation*} \lambda_0 \approx \lambda_0^{(k)} = {v_0^{(k)}}^H A v_0^{(k)} \mbox{ and } \lambda_1 \approx \lambda_1^{(k)} = {v_1^{(k)}}^H A v_1^{(k)} \end{equation*}

Alternatively,

\begin{equation*} A^{(k)} = \left( \begin{array}{c| c} v_0^{(k)} \amp v_1^{(k)} \end{array} \right)^H A \left( \begin{array}{c| c} v_0^{(k)} \amp v_1^{(k)} \end{array} \right) \mbox{ converges to } \left( \begin{array}{c| c} \lambda_0 \amp 0 \\ \hline 0 \amp \lambda_1 \end{array} \right) \end{equation*}

if $A$ is Hermitian, $\vert \lambda_1 \vert \gt \vert \lambda_2 \vert \text{,}$ and $v^{(0)}$ and $v^{(1)}$ have components in the directions of $x_0$ and $x_1 \text{,}$ respectively.

The natural extention of these observations is to iterate with $n$ vectors:

\begin{equation*} \begin{array}{l} \widehat V := \mbox{ random } m \times n \mbox{ matrix} \\ ( \widehat V^{(0)}, R ) := {\rm QR}( \widehat V ) \\ A^{(0)} = { V^{(0)}}^H A V^{(0)} \\ {\bf for~} k:=0, \ldots \\ ~~~( \widehat V^{(k+1)}, R ) := {\rm QR}( A \widehat V^{(k)} ) \\ ~~~ A^{(k+1)} = {\widehat V^{(k+1)}~}^H A \widehat V^{(k+1)} \\ {\bf endfor} \end{array} \end{equation*}

By extending the reasoning given so far in this unit, if

• $A$ is Hermitian,

• $\vert \lambda_0 \vert \gt \vert \lambda_1 \vert \gt \cdots \gt \vert \lambda_{n-1} \vert \gt \vert \lambda_{n} \vert \text{,}$ and

• each $v_j$ has a component in the direction of $x_j \text{,}$ an eigenvector associated with $\lambda_j \text{,}$

then each $v_j^{(j)}$ will converge to a vector in the direction $x_j \text{.}$ The rate with which the component in the direction of $x_p \text{,}$ $0 \leq p \lt n \text{,}$ is removed from $v_j^{(k)} \text{,}$ $n \leq j \lt m \text{,}$ is dictated by the ratio $\vert \lambda_p \vert / \vert \lambda_j \vert \text{.}$

If some of the eigenvalues have equal magnitude, then the corresponding columns of $\widehat V^{(k)}$ will eventually form a basis for the subspace spanned by the eigenvectors associated with those eigenvalues.

###### Homework10.1.1.4.

Copy PowerMethodLambda1Reorth.m into SubspaceIteration.m and modify it to work with an $m \times n$ matrix $V \text{:}$

[ Lambda, V ] = SubspaceIteration( A, V, maxiters, illustrate, delay  );

Modify the appropriate line in Assignments/Week10/matlab/test_SubspaceIteration.m, changing (0) to (1), and use it to examine the convergence of the method.

What do you observe?

Solution

Watch the video regarding this problem on YouTube: https://youtu.be/Er7jGYs0HbE. (embedding a video in a solution seems to cause PreTeXt trouble...)


# Uniformly distributed n-dimensional probability vectors over a simplex

What's the right way to generate a random probability vector $p={p_1,\ldots,p_n} \in {(0,1)}^n$ where $\sum_i p_i=1$, uniformly distributed over the $(n-1)$-dimensional simplex?

What I have is

Intervals = Table[{0, 1}, {i, n}]
RandomPoint := Block[{a},
a = RandomVariate[UniformDistribution[Intervals]];
a/Total[a]];

But I am unsure that this is correct. In particular, I'm unsure that it's any different from:

RandomPoint := Block[{a},
a = Table[Random[], {i, n}];
a/Total[a]];

And the latter clearly will not distribute vectors uniformly. Is the first code the right one?

-
This question may be relevant. –  Sjoerd C. de Vries Oct 8 '13 at 11:21
Thanks, @SjoerdC.deVries. That question seems to suggest that my first code is also incorrect? I'm assuming that that bunch of smart guys would have stumbled upon it. –  Schiphol Oct 8 '13 at 11:42
Perhaps DirichletDistribution might help? –  chuy Oct 8 '13 at 14:03
That question involved points on a sphere. Your constraint of $\sum{p_i}=1$ is different. –  Sjoerd C. de Vries Oct 8 '13 at 14:39
I agree with chuy. From wikipedia: Dirichlet Distribution, we have: "When alpha = 1, the symmetric Dirichlet distribution is equivalent to a uniform distribution over the open standard K-1-simplex, i.e. it is uniform over all points in its support". Using DirichletDistribution is most likely then also the best implementation for most purposes. –  Jacob Akkerboom Oct 8 '13 at 15:26

#/Total[#,{2}]&@Log@RandomReal[{0,1},{m,n}] will give you a sample of m points from a uniform distribution over an n-1-dimensional regular simplex. (An equilateral triangle is a 2-dimensional regular simplex.) Here's what m = 2000, n = 3 should look like, where {x,y} = {p[[2]]-p[[1]], Sqrt@3*p[[3]]} are the barycentric coordinates of the 3-element probability vector p:
Here's what you get if you omit the Log@ and normalize Uniform(0,1) variables, which is what both of the OP's examples do:
See for yourself. Try it with n = 2 and make a histogram of p[[1]]. Or use n = 3 and ListPlot the barycentric coordinates: {x,y} = {p[[2]]-p[[1]],Sqrt@3*p[[3]]}. –  Ray Koopman Oct 9 '13 at 18:41
You can also use Mathematica's built-in DirichletDistribution: points = RandomVariate[DirichletDistribution[{1, 1, 1}], 2000] /. v_?VectorQ :> {v[[2]] - v[[1]], Sqrt[3] (1 - Total[v])}; and then ListPlot[points]. –  chuy Oct 11 '13 at 18:28


# Use of “without loss of generality”

Why do we use “without loss of generality” when writing proofs?
Is it necessary or convention? What “synonym” can be used?

I think this is great question, as the mathematical use of “without loss of generality” often varies from its literal meaning. The literal meaning is when you rephrase a general statement

$$P(x)P(x)$$ is true for all $$x∈Sx \in S$$,

using another set (which is easier to work with)

$$P(z)P(z)$$ is true for all $$z∈Tz \in T$$,

where $$PP$$ is some property of elements in $$SS$$ and $$TT$$, and it can be shown (or is known) that $$S=TS=T$$.

For example:

• We want to show that $$P(x)P(x)$$ is true for all $$x∈Zx \in \mathbb{Z}$$. Without loss of generality, we can assume that $$x=z+1x=z+1$$ for some $$z∈Zz \in \mathbb{Z}$$. [In this case, $$S=ZS=\mathbb{Z}$$ and $$T={z+1:z∈Z}T=\{z+1:z \in \mathbb{Z}\}$$.]

• We want to show that $$P(x)P(x)$$ is true for all $$x∈Zx \in \mathbb{Z}$$. Without loss of generality, we can assume that $$x=5q+rx=5q+r$$ where $$q,r∈Zq,r \in \mathbb{Z}$$ and $$0≤r. [In this case, $$S=ZS=\mathbb{Z}$$ and $$T={5q+r:q∈Z and r∈Z and 0≤r.]

In the above instances, indeed no generality has been lost, since in each case we can prove $$S=TS=T$$ (or, more likely, it would be assumed that the reader can deduce that $$S=TS=T$$). I.e., proving that $$P(z)P(z)$$ holds for $$z∈Tz \in T$$ is the same as proving that $$P(x)P(x)$$ holds for $$x∈Sx \in S$$.

The above cases are examples of clear-cut legitimate usage of "without loss of generality", but there is a widespread second use. Wikipedia writes:

The term is used before an assumption in a proof which narrows the premise to some special case; it is implied that the proof for that case can be easily applied to all others (or that all other cases are equivalent). Thus, given a proof of the conclusion in the special case, it is trivial to adapt it to prove the conclusion in all other cases.

[emphasis mine.]

So, paradoxically, "without loss of generality" is often used to highlight when the author has deliberately lost generality in order to simplify the proof. Thus, we are rephrasing a general statement:

$$P(x)P(x)$$ is true for all $$x∈Sx \in S$$,

as

$$P(z)P(z)$$ is true for all $$z∈Tz \in T$$, and

if $$x∈Sx \in S$$, then there exists $$z∈Tz \in T$$ for which $$P(x)P(x)$$ is true if $$P(z)P(z)$$ is true.

For example:

• Let $$SS$$ be a set of groups of order $$nn$$. We want to show $$P(G)P(G)$$ is true for all $$G∈SG \in S$$. Without loss of generality, assume the underlying set of $$GG$$ is $${0,1,…n−1}\{0,1,\ldots n-1\}$$ for some $$n≥1n \geq 1$$. [Here, $$TT$$ is a set of groups with underlying set $${0,1,…n−1}\{0,1,\ldots n-1\}$$ that are isomorphic to groups in $$SS$$, and the reader is assumed to be able to deduce that property $$PP$$ is preserved by isomorphism.]

My personal preference is to replace the second case with:

"It is sufficient to prove $$P(z)P(z)$$ for $$z∈Tz \in T$$, since [[for some reason]] it follows that $$P(x)P(x)$$ is true for all $$x∈Sx \in S$$."


# Integration problems: Intriguing Integrals

1. Apr 2, 2008

### BioCore

1. The problem statement, all variables and given/known data
$$\int$$x^3$$\sqrt{}a^2-x^2$$dx

2. Relevant equations

3. The attempt at a solution
I came this far with my solution:

a^5$$\sqrt{}sin^3\Theta cos^2\Theta$$d$$\Theta$$
a^5$$\sqrt{}sin^3\Theta-sin^5\Theta$$d$$\Theta$$

The answer given to me is:

-1/15(a^2 - x^2)^3/2 (2a^2 + 3x^2) + C

It seems that they used sine theta, and not cos theta. I have currently tried to do that but am not sure how I would get rid of the extra sin$$\Theta$$.

Thanks for the help.
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

Last edited by a moderator: Apr 2, 2008
2. Apr 2, 2008

### rock.freak667

$$\int x^3 \sqrt{a^2-x^2}dx$$

let $x=acos\theta \Rightarrow dx=-asin\theta$

$$\int x^3 \sqrt{a^2-x^2}dx \equiv \int (acos\theta)^3\sqrt{a^2-a^2cos^2\theta} \times -asin\theta d\theta$$

$$\int - a^4cos^3\theta \sqrt{a^2(1-cos^2\theta)} \times -asin\theta d\theta$$

$$-a^5 \int cos^3\theta sin^2\theta d\theta$$

recall that $sin^2\theta +cos^2\theta=1$

and substitute for $sin^2\theta$

3. Apr 2, 2008

### BioCore

I would assume that using your solution I would have the right answer. The only problem is that in the solutions my Professor gave us, he has an intermediate step before the final solution such as this:

$$a^5 \int sin^3\theta cos^2\theta d\theta$$

Also in explaining to us Trig Substitution he placed $$\sqrt{a^2 - x^2}$$ as the bottom portion of the right triangle. Thus he stated that

x = asin$$\Theta$$
dx = acos$$\Theta$$
$$\sqrt{a^2 - x^2}$$ = acos\theta

Last edited by a moderator: Apr 2, 2008
4. Apr 2, 2008

### rock.freak667

Your teacher used x=sin$\theta$, I used x=cos$\theta$.
So in his triangle, $sin\theta=\frac{x}{a}$ which would make the adjacent side,$\sqrt{a^2-x^2}$. At the end of that integral you would get terms involving $cos\theta$

In my substitution, the opposite side would be $\sqrt{a^2-x^2}$ and at the end of my integral I would have terms involving $sin\theta$

So in theory it should all work out the same.

5. Apr 2, 2008

### BioCore

$$-a^5 \int \sqrt{1 - sin^2\theta} (1 - sin^2\theta) (sin^2\theta)d\theta$$

= $$-a^5 \int (1 - sin^2\theta)^3/2 (sin^2\theta)d\theta$$

= $$-a^5 \int sin^3\theta - sin^6\theta d\theta$$

= $$-a^5 [1/4sin^4\theta + 1/7sin^7\theta ]$$ +C

Now I know that I should substitute for the sine function, but is this so far correct?


# Proving an algorithm's correctness in determining the number of 1 bits in a bit string

   procedure bit count(S: bit string)
count := 0
while S != 0
count := count + 1
S := S ∧ (S − 1)
return count {count is the number of 1s in S}

Here S-1 is the bit string obtained by changing the rightmost 1 bit of S to a 0 and all the 0 bits to right of this to 1s.

So I understand why this is correct, and I have write a rough explanation;

After every iteration, the rightmost 1 bit in S, as well as all the bits to the right of it, is set equal to 0. Thus, after each iteration, the next right-most 1 is accounted for and set to 0, until the entire string is 0's and the loop breaks with the count equal to the number of 1's.

I know this kind of answer won't pass in any mathematics community, so I was hoping to write a formal proof, but I don't know how to go about doing that. My proof skills are particularly shoddy, so an explanation of the techniques involved would be greatly appreciated.

-
Is ^ and or xor? – copper.hat Dec 5 '12 at 7:04
@copper.hat: It has to be $\land$ for the algorithm to work. – Brian M. Scott Dec 5 '12 at 7:05

Here’s one way to make your informal explanation a bit more formal.

Let $\sigma=b_1b_2\dots b_n$ be a bit string of length $n$. For convenience let $[n]=\{1,\dots,n\}$. If $\sigma$ is not the $0$ string, let $k=\max\{i\in[n]:b_i=1\}$, so that $b_k=1$ and $b_i=0$ for $i>k$. Then $\sigma-1$ is the bit string $a_1a_2\dots a_n$ such that for each $i\in[n]$

$$a_i=\begin{cases} b_i,&\text{if }i<k\\ 0,&\text{if }i=k\\ 1,&\text{if }i>k\;. \end{cases}$$

Then $$\sigma\land(\sigma-1)=(b_1\land a_1)(b_2\land a_2)\ldots(b_n\land a_n)\;,$$ and for $i\in[n]$ we have

$$b_i\land a_i=\begin{cases} b_i,&\text{if }i<k\\ 0,&\text{if }i\ge k\;: \end{cases}$$

$b_k\land a_k=1\land 0=0$, and $b_i\land a_i=0\land 1=0$ for each $i>k$. In other words, if $$\sigma\land(\sigma-1)=c_1c_2\dots c_n\;,$$ then

$$c_i=\begin{cases} b_i,&\text{if }i<k\\ 0,&\text{if }i\ge k\;. \end{cases}$$

Recalling that $b_k=1$ and $b_i=0$ for $i>k$, we see that $\sigma$ and $\sigma\land(\sigma-1)$ differ only in the $k$-th bit, where $\sigma$ has a $1$ and $\sigma\land(\sigma-1)$ has a $0$.

If $|\sigma|_1$ is the number of $1$’s in $\sigma$, we’ve just shown that

$$|\sigma\land(\sigma-1)|_1=|\sigma|_1-1\;.$$

Thus, each pass through the loop adds $1$ to the count and reduces the number of $1$’s in the string by $1$. (In other words, $\text{count}+|\sigma|_1$ is a loop invariant for this loop.) Since $\text{count}$ starts at $0$ and $|\sigma|_1$ at the number of $1$’s in the input bit string, it’s now clear that after $|\sigma|_1$ passes through the loop, the input string will be the zero string, and $\text{count}$ will be the number of $1$’s in the input string. And since the input is now the zero string, we exit the loop with no further change in $\text{count}$.

-

What you observed is already quite good. If you would like to argue more formal I would suggest to prove first a lemma that says.

Lemma: If $S>0$ then the binary representation of $S$ has one digit 1 more than the binary representation of $S \land (S-1)$.

$Proof.$ Let the binary representation of $S\neq 0$ be the string $s=\text{bin}(S)$. We assume that $s$ ends on $v=10^k$ and that $s=uv$. Subtracting 1 from $S$ gives in the binary representation a string $u01^k$. A bit-wise AND of $S$ and $S-1$ is therefore the string $u0^{k+1}$, which proves the lemma.

Use this lemma and a loop invariant to prove the correctness of your algorithm.

-

Actually, I think you have a very good start.

What I think is needed are these ideas:

(1) Explicit specifying of all the locations in S where the one bits are.

(2) An analysis of what the critical step S := S ∧ (S − 1) does.

Here is my take on (2).

Suppose S, at this point, has k zero bits on the right with the k+1st bit a one. Then $S = a 2^k$, with a an odd integer (if $a$ were even, the j+1st bit would be zero).

Then $S-1 = a 2^k-1 = (a-1)2^k + 2^k-1$ so S ^ (S-1) = $(a-1)2^k$ since (1) the k lower bits of S are zero, and (2) since a is odd, a-1 is even, so the k+1st bit of S-1 is zero. Furthermore, since a is odd, all the bits of a-1 are the same as the bits of a except for the low order bit.

Thus the bits of S ^ (S-1) are the same as the bits of S except that the lowest one bit has been set to zero.

This lemma (which is what it really is) allows you to set up an inductive hypothesis that each time through the loop the current low order one bit has been set to zero and count is incremented by one.

At the end, count equals the number of one bits in the original number.

I have great admiration for whoever first came up with this, and I thank John Taylor for providing me with the opportunity of doing this analysis.

I had seen this algorithm before, but had never seen a proof, and I enjoyed working this out.

Aha! I see that Brian M. Scott has answered as I was entering my answer, and that our two analyses are essentially the same with quite different notations.

-