# B A question about Greatest common factor (GCF) ?

#### awholenumber

When we try to find the Greatest common factor (GCF) of two numbers , does it only involve prime factorization ?

#### FactChecker

Gold Member
2018 Award
Yes. The GCF is a product of primes but is not usually a prime itself. Prime factorization of both numbers is the way to find out what the GCF is. If you have the prime factorization of both numbers, it is easy to calculate the GCF.

#### awholenumber

Ok , so the same prime factorization is used to find the LCM too , right ?

#### FactChecker

Gold Member
2018 Award
Ok , so the same prime factorization is used to find the LCM too , right ?
Yes.

Ok , Thanks

#### SlowThinker

I dare to disagree, Euclid's algorithm or binary GCD are used to find GCD, then LCM(a, b)=a*b/GCD(a, b).

#### FactChecker

Gold Member
2018 Award
I stand corrected. I was not familiar with these algorithms. The binary GCD algorithm and Euclidean_algorithm are interesting.

#### awholenumber

Ok, i have one more doubt .
The GCF of two numbers involves prime factorization of those two numbers , then multiply those factors both numbers have in common

Isnt LCM about finding the least common multiple of two numbers ?

What does that have anything to do with prime numbers ?

#### mfb

Mentor
You can find the LCM via LCM(a, b)=a*b/GCD(a, b), if you have the GCD first.
That is often the most practical way to find the LCM.

Prime factorization is just one possible way to find the GCD. For large numbers, it can be very time-consuming, and different algorithms can be more efficient.

#### awholenumber

Thanks for the information mfb , i am just trying to cover the algebra 1 for dummies book .
It doesn't have a method like this LCM(a, b)=a*b/GCD(a, b) mentioned in it .

#### PeroK

Homework Helper
Gold Member
2018 Award
Thanks for the information mfb , i am just trying to cover the algebra 1 for dummies book .
It doesn't have a method like this LCM(a, b)=a*b/GCD(a, b) mentioned in it .
You'll find that in an "algebra for intelligent students" textbook!

#### awholenumber

lol ok , first let me somehow finish this one book properly

#### PeroK

Homework Helper
Gold Member
2018 Award
lol ok , first let me somehow finish this one book properly
It's still worth understanding why the two are related. The basic argument is:

$a = a'g, b = b'g$

Where $g$ is the GCD of $a$ and $b$ and $a', b'$ are how much bigger $a$ and $b$ are than $g$.

For example: if $a = 42$ and $b = 15$, then $g = 3$ and $a=14 \times 3, b = 5 \times 3$, hence $a' = 14, b' = 5$

Now, the LCM of $a$ and $b$ must have as factors simply $a', b'$ and $g$, so $l = a'b'g = a'b = a'gb/g = ab/g$

You can now see that the LCM is the product of $a$ and $b$, divided by the GCD.

In our example:

$LCM(42, 15) = \frac{42 \times 15}{3} = 210$

mfb

#### awholenumber

Thanks for sharing , i will keep this in my mind and maybe someday i will be able to use this advanced method .

#### Michael Hardy

Yes. The GCF is a product of primes but is not usually a prime itself. Prime factorization of both numbers is the way to find out what the GCF is. If you have the prime factorization of both numbers, it is easy to calculate the GCF.
But you don't need to know anything about prime factorizations to find the GCD; you can use Euclid's algorithm, which is very efficient.

#### Michael Hardy

You don't need prime factorizations to find GCDs. There is an efficient method not requiring any knowledge of prime numbers: Euclid's algorithm. This is the oldest algorithm still in standard use, dating back to Euclid's writings in the 3rd century BC, and it is very efficient.
\begin{align*} \gcd(1989,867) & = \gcd(255,867) & & \text{since 255 is the remainder} \\ & & & \text{when 1989 is divided by 867} \\[10pt] & = \gcd(255,102) & & \text{since 102 is the remainder} \\ & & & \text{when 867 is divided by 255} \\[10pt] & = \gcd(51,102) & & \text{since 51 is the remainder} \\ & & & \text{when 255 is divided by 102} \\[10pt] & = \gcd(51,0) & & \text{since 0 is the remainder} \\ & & & \text{when 102 is divided by 51} \\[10pt] & = 51. \end{align*}
Thus we have $\dfrac{1989}{867} = \dfrac{51\times39}{51\times17} = \dfrac{39}{17}.$

#### Michael Hardy

Yes. The GCF is a product of primes but is not usually a prime itself. Prime factorization of both numbers is the way to find out what the GCF is. If you have the prime factorization of both numbers, it is easy to calculate the GCF.
This is wrong. Euclid's very efficient algorithm for finding GCDs does not require doing anything at all with prime numbers.

#### mfb

Mentor
But you don't need to know anything about prime factorizations to find the GCD; you can use Euclid's algorithm, which is very efficient.
Yes, that has been mentioned in post 6 for example.

This thread is from 2017, by the way.

"A question about Greatest common factor (GCF) ?"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving


# How to plot magnitude and phase response of 2 cascaded filters in Matlab?

How would I go about plotting a magnitude and phase response of a system that consists of two cascaded 2nd order Butterworth filters in Matlab? Filters are the same.

% Filter coeffs:
[B, A] = butter( 2, 1000/8000*2, 'high' ); % Cutoff at 1000 Hz, fs 8000 Hz.

% Cascade 2 filters: input -> filter -> filter -> output :
[out1, state1 ] = filter( B, A, in,   state1);
[out2, state2 ] = filter( B, A, out1, state2);

Using MATLAB/Octave as the tool, the following approach lets you plot the magnitude & phase samples of the DTFT of the cascade of the two discrete-time LTI filters using their LCCDE coefficient vectors $$b[k]$$, and $$a[k]$$, assuming they have LCCDE representations..

Since the cascade LTI system is described as: $$h[n] = h_1[n] \star h_2[n]$$ and consequently $$H(z) = H_1(z) H_2(z)$$

Where the $$h[n]$$ is the impulse response of the cascade system and $$H(z)$$ is its transfer function (Z-transform of impulse response). Those $$h_1[n]$$ and $$h_2[n]$$ refer to the impulse responses of the individual systems that make up the cascade.

Assuming that individual systems do have rational Z-transforms, then we have the following expression for the composite (cascade) system Z-transfom:
\begin{align} H(z) &=\frac{ \sum_{k=0}^{M} B[k]z^{-k} } {\sum_{k=0}^{N} A[k]z^{-k}} = H_1(z) H_2(z) \\ \\ &= \left( \frac{ \sum_{k=0}^{M_1} b_1[k]z^{-k} } {\sum_{k=0}^{N_1} a_1[k]z^{-k}} \right) \left( \frac{ \sum_{k=0}^{M_2} b_2[k]z^{-k} } {\sum_{k=0}^{N_2} a_1[k]z^{-k}} \right) \end{align}

Where individual coefficients $$b_1[k],a_1[k],b_2[k],a_2[k]$$ are those that represent the cascaded systems.

We want $$B[k]$$ and $$A[k]$$ that represent the cascade system, from which we can use the following Matlab/Octave function to plot the DTFT magnitude and phase responses, assumimg that the cascade is a stable LTI system so that it will have a frequency response function:

figure,freqz(B,A);

Now it can be shown by polynomial manipulations that the coefficients $$B[k]$$ and$$A[k]$$ are related to the individual coefficients $$b_1[k],a_1[k],b_2[k],a_2[k]$$ as the following: $$B[k] = b_1[k] \star b_2[k]$$ and $$A[k] = a_1[k] \star a_2[k]$$

Hence the required frequency response plot can be obtained in the combined call as follows:

figure,freqz(conv(b1,b2),conv(a1,a2));

where b1,a1 and b2,a2 are the coefficient vectors that represent the individual systems. The method can be generalised to N systems in cascade.

When you pass a signal from two cascaded filters, what happens is that the magnitude response of the whole chain is the product of individual filters, and the phase response is the sum of individual phase responses. This is because the transfer functions are multiplied in the cascade implementation.

So if the frequency response of the single filters are $$H_A(w)=|H_A(w)|e^{j\angle H_A(w)}$$ $$H_B(w)=|H_B(w)|e^{j\angle H_B(w)}$$ then the frequency response of the two cascaded filters (overall) is \begin{align} H_{AB}(w)&=H_A(w)H_B(w)\\ &=\left(|H_A(w)|e^{j\angle H_A(w)}\right)\left(|H_B(w)|e^{j\angle H_B(w)}\right)\\ &=|H_A(w)||H_B(w)|e^{j(\angle H_A(w)+\angle H_B(w))} \end{align}

You can use [h,w] = freqz(b,a) in Matlab to get the frequency response of your desired filters. Use abs and angle to find the magnitude and phase:

...
[hA,w] = freqz(bA,aA);
[hB,w] = freqz(bB,aB);
hAB = hA.*hB;
MagResp = 20*log10(abs(hAB));
PhaseResp = angle(hAB);
plot(w,MagResp)
...

when the two filters are identical, then the overall magnitude is squared and the overall phase is scaled by two: \begin{align} H_{AA}(w)&=\left(|H_A(w)|e^{j\angle H_A(w)}\right)\left(|H_A(w)|e^{j\angle H_A(w)}\right)\\ &=|H_A(w)|^2e^{j2\angle H_A(w)} \end{align}

• Yes, filter is the same. – Danijel Mar 27 '17 at 11:51
• Yes, I added the general case at the beginning, then the identical case at the end. – msm Mar 27 '17 at 12:09
• Shouldn't it be wAB = w + w, and then plot(wAB)? Is angle(hAB) necessary? – Danijel Mar 27 '17 at 12:43
• w is the frequency axis and remains fix. We should just add function values at given w values. – msm Mar 27 '17 at 20:03
• angle(hAB) gives you the phase of the complex array hAB. Without that, you just have a bunch of complex values of size legth(w). – msm Mar 28 '17 at 1:42


# Complex integration with Cauchy's Integral Formula

Calculate$$\int_\gamma \frac{(z+27i)(z+16)}{z(z+81)^2}dz$$ where $\gamma$ is the triangle whose vertices are the third roots of $z = -8i$, oriented counterclockwise.

Answer:

I calculated the third roots of $-8i$ and they all have modulus $2$. This tells me that the maximum distance of $\gamma$ from the origin will be $2$.

There are singularities at $z=0, z=-81$. As $81 > 2$, this singularity falls outside $\gamma$ so the only one that matters is $z = 0.$

I then applied Cauchy's Integral Formula $$\int_\gamma \frac{(z+27i)(z+16)}{z(z+81)^2}dz = 2\pi i [\frac{(z+27i)(z+16)}{(z+81)^2}] |_{z=0}$$

And I got a final result of $\displaystyle\frac{-32\pi}{243}$.

Is my analysis and final result correct?

-
Yep, completely spot on! Only thing I can see you could have improved slightly was to notice the cube roots of $-8i$ should have modulus 2 without calculating them, saves you some work. –  Ragib Zaman Apr 18 '12 at 14:00
(+1) for showing work. –  The Chaz 2.0 Apr 18 '12 at 14:01
You should copy this to an answer and accept it :) –  Neal Apr 18 '12 at 15:34
@Jim_CS If you require further feedback it might help to elaborate more specifically on any doubts. If not, please post an answer and accept it so that we know it is resolved. –  Bill Dubuque May 17 '12 at 15:54

## 2 Answers

Answering my own question as Neal advised me to.

I calculated the third roots of −8i and they all have modulus 2. This tells me that the maximum distance of γ from the origin will be 2.

There are singularities at z=0,z=−81. As 81>2, this singularity falls outside γ so the only one that matters is z=0. I then applied Cauchy's Integral Formula ∫γ(z+27i)(z+16)z(z+81)2dz=2πi[(z+27i)(z+16)(z+81)2]|z=0 And I got a final result of −32π243.

Is my analysis and final result correct?

-

Nothing wrong with your analysis and answer.

-


IntMath Home » Forum home » Infinite Series Expansion » Taylor's series question

# Taylor's series question [Solved!]

### My question

my question is in Taylor's series: Derive Tayor's series for x^(1/2) at x=1 up to the first four non-zero terms.hence estimate square root of 1.1 correct to 4 d.p

1. Taylor Series

### What I've done so far

I think I need to differentiate it several times.

Here it is:

f(x) = x^(1/2)

f'(x) = 1/2 x^(-1/2) = 1/(2 x^(1/2))

f''(x) = - 1/4 x^(-3/2) = -1/(4 x^(3/2))

f'''(x) = 3/8 x^(-5/2) = 3/(8 x^(5/2))

But I'm stuck then

X

my question is in Taylor's series: Derive Tayor's series for x^(1/2) at x=1 up to the first four non-zero terms.hence estimate square root of 1.1 correct to 4 d.p
Relevant page

1. Taylor Series

What I've done so far

I think I need to differentiate it several times.

Here it is:

f(x) = x^(1/2)

f'(x) = 1/2 x^(-1/2) = 1/(2 x^(1/2))

f''(x) = - 1/4 x^(-3/2) = -1/(4 x^(3/2))

f'''(x) =  3/8 x^(-5/2) = 3/(8 x^(5/2))

But I'm stuck then

## Re: Taylor's series question

Hello Snowboy

Your problem is very similar to the example on the page you came from:

1. Taylor Series

Now that you've differentiated, you need to substitute the necessary values, just like I did in that example.

Or is you problem with the square root approximation?

Regards

X

Hello Snowboy

Your problem is very similar to the example on the page you came from:

1. Taylor Series

Now that you've differentiated, you need to substitute the necessary values, just like I did in that example.

Or is you problem with the square root approximation?

Regards

## Re: Taylor's series question

So a=1, right?

f(1) = 1

f'(1) = 1/2

f''(1) = -1/4

f'''(1) = 3/8

Plugging it into the formula:

1 + 1/2 (x-1)  -1/4(x-1)^2  + 3/8(x-1)^3-...

How many steps do we have to do?

X

So a=1, right?

f(1) = 1

f'(1) = 1/2

f''(1) = -1/4

f'''(1) = 3/8

Plugging it into the formula:

1 + 1/2 (x-1)  -1/4(x-1)^2  + 3/8(x-1)^3-...

How many steps do we have to do?

## Re: Taylor's series question

The question says you need 4 d.p. accuracy.

So you just keep finding approximations at the specific value given until there is no difference in the number in the 4th d.p. after you have rounded it.

X

The question says you need 4 d.p. accuracy.

So you just keep finding approximations at the specific value given until there is no difference in the number in the 4th d.p. after you have rounded it.

## Re: Taylor's series question

It says "at 1.1".

Is this OK?

sqrt(1.1) = 1 + 1/2(0.1) - 1/4(0.1)^2 + 3/8(0.1)^3

 = 1 + 0.05 - 0.0025 + 0.000375  = 1.047875

I can see that 4th term is small and the next one will be even smaller, I think. So maybe there's no need to do any more steps because it won't affect the 4th d.p.

Maybe I should do another step to make sure.

f''''(x) = -15/16 x^(-7/2)

f''''(1) = -15/16

So the 5th term is -15/16(x-1)^4

Plugging in 1.1 gives -0.00009375

Adding this gives 1.047875-0.00009375 = 1.04778125

To 4 d.p. it's still 1.0478.

But checking on my calculator, I get sqrt(1.1) = 1.04880884817

To 4 d.p., that's 1.0488. Is my answer wrong?

X

It says "at 1.1".

Is this OK?

sqrt(1.1) = 1 + 1/2(0.1) - 1/4(0.1)^2 + 3/8(0.1)^3

= 1 + 0.05 - 0.0025 + 0.000375  = 1.047875

I can see that 4th term is small and the next one will be even smaller, I think. So maybe there's no need to do any more steps because it won't affect the 4th d.p.

Maybe I should do another step to make sure.

f''''(x) = -15/16 x^(-7/2)

f''''(1) = -15/16

So the 5th term is -15/16(x-1)^4

Plugging in 1.1 gives -0.00009375

Adding this gives 1.047875-0.00009375 = 1.04778125

To 4 d.p. it's still 1.0478.

But checking on my calculator, I get sqrt(1.1) = 1.04880884817

To 4 d.p., that's 1.0488. Is my answer wrong?

## Re: Taylor's series question

Your thinking process is very good. Your working is correct. The difference with the calculator answer is they are using a better algorithm.

Our Taylor's Series approximation is only "good" right near the number we expand about (in your case, x=1).

To see why they are different, let's compare the actual square root graph with the Taylor's Series expansion:

The green one is y=sqrt(x) and the magenta curve is y=1 + 1/2 (x-1) -1/4(x-1)^2 + 3/8(x-1)^3.

You can see it's not a very good approximation as we get away from x=1.

X

Your thinking process is very good. Your working is correct. The difference with the calculator answer is they are using a better algorithm.

Our Taylor's Series approximation is only "good" right near the number we expand about (in your case, x=1).

To see why they are different, let's compare the actual square root graph with the Taylor's Series expansion:

[graph]310,250;-0.3,2.5;-0.5,2,0.5,0.5;sqrt(x),1 + 1/2 (x-1) -1/4(x-1)^2 + 3/8(x-1)^3[/graph]

The green one is y=sqrt(x) and the magenta curve is y=1 + 1/2 (x-1) -1/4(x-1)^2 + 3/8(x-1)^3.

You can see it's not a very good approximation as we get away from x=1.

## Re: Taylor's series question

Thanks a lot!

X

Thanks a lot!


# Linear, second-order differential equation?

1. Sep 27, 2011

### Raen

One of my homework problems this week was:

Verify that y = sin(4t) + 2cos(4t) is a solution to the following initial value problem.

2y'' + 32y=0; y(0)=2, y'(0)=4

Find the maximum of |y(t)| for -infinity< t < infinity.

Verifying that the given y equation is a solution is easy, all there is to do is derive twice, plug in the new equations, and show that 0 = 0. I have no trouble with that. My question is with the second part, about finding the maximum positive value of y(t).

I would think that no matter how large t gets, sin and cos will always oscillate between -1 and 1. When cos is 1, obviously sin is 0. Putting in sin(4t) = 0 and cos(4t) = 1 gives me a maximum value of 2 for any y(t) as t approaches infinity. I graphed the function on a calculator to confirm this, just in case, and the graph appears to agree with me.

My confusion is that 2 isn't the correct answer. According to the website we do our homework on, the answer should be sqrt(5). There are no questions like this worked out in the book and I can't find anything online. Can anybody explain to me why y(t) has a maximum value of sqrt(5) as t approaches infinity?

Thank you!

2. Sep 27, 2011

### LCKurtz

Generally, when you have something like acos(θ) + bsin(θ) you can write it as a single trig function. You multiply and divide by the square root of the sum of the squares of the coefficients:

$$a\cos\theta + b\sin\theta = \sqrt{a^2+b^2} \left(\frac a {\sqrt{a^2+b^2}}\cos\theta + \frac b {\sqrt{a^2+b^2}}\sin\theta\right)$$

Now, since the sum of the squares of the new coefficients of the sine and cosine add up to one, they can be used as the sin(β) and cos(β) of some angle β. You then have an addition formula for a sine or cosine function with amplitude $\sqrt{a^2+b^2}$. In your example that gives amplitude $\sqrt 5$.

3. Sep 28, 2011

### HallsofIvy

Staff Emeritus
LCKurtz's response is, as always, excellent.

Raen, you seem to be assuming that a maximum of f+ g must occur where either f or g has a maximum (since you looked immediately at cos(x)= 1) and that is not correct.

Another way to find a maximum or minimum for a function is (as I am sure you know) is to look where the derivative is 0. If f(x)= sin(4x)+ 2cos(4x), then f'(x)= 4cos(4x)- 8sin(4x)= 0 when 4 cos(4x)= 8 sin(4x) or cos(4x)= 2sin(4x). Rather than solve for x directly, note that $cos^2(4x)= 4 sin^2(4x)$ so $sin^2(4x)+ cos^2(4x)= 5 sin^2(4x)= 1$ so that $sin^2(4x)= 1/5$ and $sin(4x)= 1/\sqrt{5}= \sqrt{5}/5$. And, of course, $cos^2(4x)= 1- sin^2(x)= 4/5$ so $cos(4x)= 2/\sqrt{5}= 2\sqrt{5}/5$.

Putting those back into the original formula, $sin(4x)+ 2cos(4x)= \sqrt{5}/5+ 4\sqrt{5}/5= 5/\sqrt{5}= \sqrt{5}$

Last edited: Sep 28, 2011
4. Sep 28, 2011

### Raen

Oh, I think I understand now. Thank you both for your detailed explanations!


# Gaussian elimination, inconsistent or infinite solutions?

I have this system

$\left[ \begin{array}{ccc|c} -3&0&-1&0\\ 2&0&0&0\\ 2&0&0&0\\ \end{array} \right]$ Is there something you can tell from looking at this straight away?

When I reduce it I get this:

$\left[ \begin{array}{ccc|c} 1&0&-1&0\\ 0&0&1&0\\ 0&0&0&0\\ \end{array} \right]$

I thought I read that if you get a statement that does not make sense, then the system is inconsistent, so $1 = 0$ does not make sense to me. Does that not mean it's inconsistent?
However, I thought that $x_3$ could equal $0$, and so could $x_1$ and basically, $x_2$ could equal anything. Still not sure, i reduced it further to:
$\left[ \begin{array}{ccc|c} 1&0&0&0\\ 0&0&1&0\\ 0&0&0&0\\ \end{array} \right]$

From this, am I correct now in thinking that:
$x_1 = r\\ x_2 = s \\ x_3 = t$

I am not sure of why I'm thinking like this, in terms of free variables etc. If I'm right, I wouldn't mind some reasoning as to why this is so, or being correct if I am wrong. Thanks.

• How did you do the final step of reduction? – platty Aug 2 '17 at 23:17
• Opps, I see where you are going with this. The 1 should remain in the second row. Sorry about that. Let me think for a minute. – Bucephalus Aug 2 '17 at 23:20
• Now that I have corrected my last reduction, I'm still not really sure what this means. it looks like $x_2$ can equal anything, Therefore, $x_1$ and $x_3$ can equal anything? Is that correct? – Bucephalus Aug 2 '17 at 23:24

Remember that the entries on the left are coefficients of variables. So from your final reduction, we would end up with the RREF: $$\left[\begin{array}{ccc|c} 1&0&0&0\\ 0&0&1&0\\ 0&0&0&0\\ \end{array}\right]$$

The first line tells us that $1x + 0y + 0z = 0$, so $x = 0$. The second line tells us that $0x + 0y + 1z = 0$, i.e. $z=0$. But we have $y$ as a free variable, so our solution is $(0,y,0)$.

Note that we can tell that $y$ is free by observing the original matrix - there is no coefficient in its column, so its value doesn't affect our final solution.

• Oh, yes I see now. Thanks for your explanation @S.Ong. – Bucephalus Aug 2 '17 at 23:27
• Say it did just turn out to be like I originally had it, with a single 1 in the first column of the first row. That would then mean that $x_1=0, x_2=r$ and $x_3=s$. Would that be right? – Bucephalus Aug 2 '17 at 23:29
• Yep, that's it! :) – platty Aug 2 '17 at 23:32
• Ok, thankyou @S.Ong. – Bucephalus Aug 2 '17 at 23:32

$\left[ \begin{array}{ccc|c} -3&0&-1&0\\ 2&0&0&0\\ 2&0&0&0\\ \end{array} \right]$

What do you know straight away?

$(0,0,0)$ is in the solution set. The right column being all $0$ tells you this.

With the second row and the 3rd row identical or the right part of the matrix, this matrix is singular.

In fact the rank is 2, the nullity is 1, and there is a "line" of solutions.

The second column all zero's tells you the very same thing. Furthermore, $x_2$ can be anything.

And the structure of rows 2 and 3 tells you that $x_1$ must equal $0.$

this is more than enough information to let you know the solution set is $(0,t,0)$

• Aaah, very insightful. This is the kind of thing I was looking for also. Do you mean by "line" that the solutions form a line in 3-space? @DougM – Bucephalus Aug 3 '17 at 0:30
• yes, with the rank of the kernel equal to 1, (and the information that at least one solution exists), then all of the solutions will lie on a line in $\mathbb R^3.$ If the nullity equaled 2, then we might say that there is a plane of solutions. – Doug M Aug 3 '17 at 0:36
• Thanks @DougM. I will keep an eye out for you next time. – Bucephalus Aug 3 '17 at 0:43


Adding very small probabilities - How to compute?

In some problems, probabilities are so small that they are best represented in computational facilities as log-probabilities. Computational problems can arise when you try to add these small probabilities together, since some computational facilities (e.g., base R) can't distinguish very small probabilities from zero. In these cases it is necessary to solve the problem either by finding a workaround that avoids the small numbers, or by using a computational facility that can deal with very small numbers.

The archetypal problem of this kind is as follows. Suppose you have log-probabilities $$\ell_1$$ and $$\ell_2$$, where the corresponding probabilities $$\exp(\ell_1)$$ and $$\exp(\ell_2)$$ are too small to be distinguished from zero in the initial computational facility being used (e.g., base R). We want to find the log-sum of these probabilities, which we denote by:

$$\ell_+ \equiv \ln \big( \exp(\ell_1) + \exp(\ell_2) \big)$$

Assume that we are ---at least initially--- working in an environment where $$\exp(\ell_1)$$ and $$\exp(\ell_2)$$ cannot be computed, since they are so small that they are indistinguishable from zero.

Questions: How can you effectively compute this log-sum? Can this be done in the base R? If not, what is the simplest way to do it with package extensions?

• the "log-sum-exp" trick can help – Taylor Nov 29 '18 at 3:44

Some preliminary mathematics: As a preliminary matter it is worth noting that this function is the LogSumExp (LSE) function, which is often encountered when performing computation on values that are represented in the log-scale. To see how to deal with sums of this kind, we first note a useful mathematical result concerning sums of exponentials:

\begin{aligned} \exp(\ell_1) + \exp(\ell_2) &= \exp(\max(\ell_1,\ell_2)) + \exp(\min(\ell_1,\ell_2)) \\[6pt] &= \exp(\max(\ell_1,\ell_2)) (1 + \exp(\min(\ell_1,\ell_2)-\max(\ell_1,\ell_2)) \\[6pt] &= \exp(\max(\ell_1,\ell_2)) (1 + \exp(-|\ell_1 - \ell_2|)). \\[6pt] \end{aligned}

This result converts the sum to a product, which allows us to present the log-sum as:

\begin{aligned} \ell_+ &= \ln \big( \exp(\ell_1) + \exp(\ell_2) \big) \\[6pt] &= \ln \big( \exp(\max(\ell_1,\ell_2)) (1 + \exp(-|\ell_1 - \ell_2|)) \big) \\[6pt] &= \max(\ell_1, \ell_2) + \ln (1 + \exp(-|\ell_1 - \ell_2|)). \\[6pt] \end{aligned}

In the case where $$\ell_1 = \ell_2$$ we obtain the expression $$\ell_+ = \ell_1 + \ln 2 = \ell_2 + \ln 2$$, so the log-sum is easily computed. In the case where $$\ell_1 \neq \ell_2$$ this expression still reduces the problem to a simpler case, where we need to find the log-sum of one and $$\exp(-|\ell_1 - \ell_2|)$$.$$^\dagger$$

Now, using the Maclaurin series expansion for $$\ln(1+x)$$ we obtain the formula:

\begin{aligned} \ell_+ &= \max(\ell_1, \ell_2) + \sum_{k=1}^\infty (-1)^{k+1} \frac{\exp(-k|\ell_1 - \ell_2|)}{k} \quad \quad \quad \text{for } \ell_1 \neq \ell_2. \\[6pt] \end{aligned}

Since $$\exp(-|\ell_1 - \ell_2|) < 1$$ the terms in this expansion diminish rapidly (faster than exponential decay). If $$|\ell_1 - \ell_2|$$ is large then the terms diminish particularly rapid. In any case, this expression allows us to compute the log-sum to any desired level of accuracy by truncating the infinite sum to a desired number of terms.

Implementation in base R: It is actually possible to compute this log-sum accurately in base R through creative use of the log1p function. This is a primitive function in the base package that computes the value of $$\ln(1+x)$$ for an argument $$x$$ (with accurate computation even for $$x \ll 1$$). This primitive function can be used to give a simple function for the log-sum:

logsum <- function(l1, l2) { max(l1, l2) + log1p(exp(-abs(l1-l2))); }

Implementation of this function succeeds in finding the log-sum of probabilities that are too small for the base package to deal with directly. Moreover, it is able to calculate the log-sum to a high level of accuracy:

l1 <- -3006;
l2 <- -3012;

logsum(l1, l2);
[1] -3005.998

sprint("%.50f", logsum(l1, l2));
[1] "-3005.99752431486240311642177402973175048828125000000000"

As can be seen, this method gives a computation with 41 decimal places for the log-sum. It only uses the functions in the base package, and does not involve any changes to the default calculation settings. It gives as high a level of accuracy as you are likely to need in most cases.

It is also worth noting that there are many packages in R that extend the computational facilities of the base program, and can be used to deal with sums of very small numbers. It is possible to find the log-sum of small probabilities using packages such as gmp or Brobdingnag, but this requires some investment in learning their particular syntax.

$$^\dagger$$ From this result we can also see that if $$|\ell_1 - \ell_2|$$ is itself large (i.e., if one of the probabilities is very small compared to the other) then the exponential term in this equation will be near zero, and we will then have $$\ell_+ \approx \max(\ell_1, \ell_2)$$ to a very high degree of accuracy.

• A number of posts on site discuss related issues. – Glen_b Nov 29 '18 at 4:53
• Sorry, I must have missed these. – Ben Nov 29 '18 at 5:05
• There's at least some material here that I don't think is anywhere else, and the exposition is quite clear so I don't think there's a problem, but it's worth being aware of the other posts. (A lot crop up in discussions of underflow and overflow in various calculations, for example) – Glen_b Nov 29 '18 at 5:29
• I have added the underflow tag to the post to link to other questions on this subject. – Ben Nov 29 '18 at 6:31


# Simple question related to the Fundamental theorem of arithmetic

Given a number $b$, which we write as a product of prime numbers:

$$b = p_1 \cdots p_s$$

Can I then deduce that a number, which divides $b$ then has to be a product of the above primes in the factorization of $b$?

-
Yes and that follows by writing out another factorization for the number that divides $b = p_1 \cdots p_s$ and using unique factorization to dedude that the factors must be some of the primes in the factorization of $b$. – Adrián Barquero Apr 7 '12 at 15:34
More explicitly, if $b = p_{1}^{e_1} \cdots p_{s}^{e_s}$ is the prime factorization of $b$ where the $p_i$'s are different primes, then you can prove that any divisor of $b$ is a product of the form $p_{1}^{a_1} \cdots p_{s}^{a_s}$ where the exponents $a_i$ satisfy that $0 \leq a_i \leq e_i$ for $i = 1, \dots , s$. – Adrián Barquero Apr 7 '12 at 15:38

Essentially yes: If $p_1,\ldots,p_s$ are primes (possibly repeated), then every divisor of $$b = p_1p_2\cdots p_s$$ must be a (possibly empty) product of some (possibly all) of the $p_i$, times $1$ or $-1$.

-
And why the downvote? – Arturo Magidin Apr 11 '12 at 6:05

A divisor of $b$ has to be a product of some of the prime factors of $b$, but "some" may mean $0$ of them (if the divisor is $1$). The divisor can have no prime factors that are not prime factors if $b$.

If the divisor in question is $c$, then for some number $d$ we have $b=cd$. If a prime number $p$ divides $b$, then $p$ must divide either $c$ or $d$ (or both). The foregoing sentence is Euclid's lemma.

-

Hint $\rm\ p\ |\ d\ |\ p_1\cdots p_n\ \Rightarrow\ p\ |\ p_j\:$ for some $\rm\:j\:$ by the Prime Divisor Property. Cancelling $\rm\:p\:$ from $\rm\:d\:$ and $\rm\:p_1\cdots p_n\:$ and inducting yields that the prime factors of $\rm\:d\:$ are a sub-multiset of $\rm\{p_1,\ldots,p_n\}.$

Generally $\rm\:d\ |\ b_1\cdots b_n\ \Rightarrow\ d = d_1\cdots d_n,\ \ d_j\ |\ b_j,\:$ i.e. a divisor of a product is a product of divisors. This is a useful generalization of the Prime Divisor Property from atoms to composite numbers. Yours is the special case when all $\rm\:b_j = p_j\:$ prime, so $\rm\:d_j = 1\:$ or $\rm\:p_j\:$ (modulo a unit factor $\pm1$).

-
@Downvoter If something is not clear, please feel free to ask questions and I will be happy to elaborate. – Bill Dubuque Apr 27 '12 at 19:13


# Math Help - Pascal's Triangle

1. ## Pascal's Triangle

Being naturally curious, i was thinking by myself whether there might not be a way to determine the sum of all the numbers in this triangle by some method, depending on the number of rows it has. And also the sum of the numbers in the n-th row.

This is what i've discovered so far.

Row 1 = 1 ; Sum = 1
Row 2 = 1 1 ; Sum = 2
Row 3 = 1 2 1 ; Sum = 4
Row 4 = 1 3 3 1 ; Sum = 8
Row 5 = 1 4 6 4 1 ; Sum = 16

So the sum of these numbers in each row, are multiples of 2.

2. Originally Posted by janvdl
Now i know this might sound silly...

Being naturally curious, i was thinking by myself whether there might not be a way to determine the sum of all the numbers in this triangle by some method, depending on the number of rows it has. And also the sum of the numbers in the n-th row.

This is what i've discovered so far.

Row 1 = 1 ; Sum = 1
Row 2 = 1 1 ; Sum = 2
Row 3 = 1 2 1 ; Sum = 4
Row 4 = 1 3 3 1 ; Sum = 8
Row 5 = 1 4 6 4 1 ; Sum = 16

So the sum of these numbers in each row, are multiples of 2.
seems to be $2^{n-1}$, where $n$ is the number of the row we are at from what you have there

3. Originally Posted by Jhevon
seems to be $2^{n-1}$, where $n$ is the number of the row we are at from what you have there
Ah ok, i wonder why i didnt notice that. And the sum of all the numbers up to an n-th row?

4. Originally Posted by janvdl
Ah ok, i wonder why i didnt notice that. And the sum of all the numbers up to an n-th row?
seems to be $2^n - 1$ where $n$ is the number of the row we are at

5. Originally Posted by Jhevon
seems to be $2^n - 1$ where $n$ is the number of the row we are at
I was thinking in that line. cant believe i was so blind

6. Hello, janvdl!

Being naturally curious . . .
Good for you!

I made some amazing "discoveries" while exploring on my own.
Of course, anything I found was proved centuries ago,
. . but it was still very satisfying.

What you discovered is a stunning pattern.

Consider the coefficients of the expansion of $(a + b)^n$

. . . $\begin{array}{ccc}n & \text{coefficients} & \text{sum} \\ \hline 0 & 1 & 1 = 2^0\\ 1 & 1\;\;1 & 2 = 2^1 \\ 2 & 1\;\;2\;\;1 & 4 = 2^2 \\ 3 & 1\;\;3\;\;3\;\;1 & 8 =2^3 \\ 4 & 1\;\;4\;\;6\;\;4\;\;1 & 16 = 2^4 \\ 5 & 1\;\;5\;\;10\;\;10\;\;5\;\;1 & 32 = 2^5 \\ 6 & 1\;\;6\;\;15\;\;20\;\;15\;\;6\;\;1 & 64 = 2^6 \\ \vdots & \vdots & \vdots \end{array}$

The sum of the $n^{th}$ row is $2^n$.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

I "discovered" this pattern while in college.

$\begin{array}{ccc}1 + 2 & = & 3 \\ 4 + 5 + 6 & = & 7 + 8 \\ 9 + 10 + 11 + 12 & = & 13 + 14 + 15 \\ 16 + 17 + 18 + 19 + 20 & = & 21 + 22 + 23 + 24 \\
\vdots & & \vdots\end{array}$

I found these in a book . . .

$\begin{array}{ccc}1 & = & 1 = 1^3 \\ 3 + 5 & = & 8 = 2^3 \\ 7 + 9 + 11 & = & 27 = 3^3 \\ 13 + 15 + 17 + 19 & = & 64 = 4^3 \\ 21 + 23 + 25 + 27 + 29 & = & 125 = 5^3 \\ \vdots & & \vdots \end{array}$

$\begin{array}{ccc}3^2 + 4^2 & = & 5^2 \\ 10^2 + 11^2 + 12^2 & = &13^2 + 14^2 \\ 21^2 + 22^2 + 23^2 + 24^2 & = & 25^2 + 26^2 + 27^2 \\ 36^2 + 37^2 + 38^2 + 39^2 + 40^2 & = & 41^2 + 42^2 + 43^2 + 44^2 \\ 55^2 + 56^2 + 57^2 + 58^2 + 59^2 + 60^2 & = & 61^2 + 62^2 + 63^2 + 64^2 + 65^2 \\ \vdots & &\vdots\end{array}$

7. I've found something else too...

I was actually trying to find another type of formula when i noticed this...

I attached a picture, i know its badly drawn but at least it gives you the idea...

The white triangles are the normal figures of Pascal's Triangle. But look at those red triangles. They interest me a lot. There must be a lot more patterns involved in this triangle than i ever thought.

What if every red triangle is the product of the 3 white triangles around it? Or the sum of the 3 white ones around it? We can make lots of new patterns using this...

8. Hello, janvdl!

That's fascinating . . . Thank you!

What if every red triangle is the sum of the 3 white ones around it?

Then we have:

. . $\begin{array}{c}3\\
4\;\;4\\
5\;\;8\;\;5 \\
6\;\;13\;\;13\;\;6 \\
7\;\;19\;\;26\;\;19\;\;7
\end{array}$

I finally saw where it came from . . .

Consider a "Pascal's Triangle" whose third line is: .1 - 3 - 1.

. . $\begin{array}{c}1 \\ 1\;\;1 \\ 1\;\;3\;\;1 \\
1\;\;4\;\;4\;\;1 \\ 1\;\;5\;\;8\;\;5\;\;1 \\ 1\;\;6\;\;13\;\;13\;\;6\;\;1 \\ 1\;\;7\;\;19\;\;26\;\;19\;\;7\;\;1
\end{array}$

See it?

This opens up a world of possibilities, doesn't it?

9. Originally Posted by Soroban
Hello, janvdl!

That's fascinating . . . Thank you!

Then we have:

. . $\begin{array}{c}3\\
4\;\;4\\
5\;\;8\;\;5 \\
6\;\;13\;\;13\;\;6 \\
7\;\;19\;\;26\;\;19\;\;7
\end{array}$

I finally saw where it came from . . .

Consider a "Pascal's Triangle" whose third line is: .1 - 3 - 1.

. . $\begin{array}{c}1 \\ 1\;\;1 \\ 1\;\;3\;\;1 \\
1\;\;4\;\;4\;\;1 \\ 1\;\;5\;\;8\;\;5\;\;1 \\ 1\;\;6\;\;13\;\;13\;\;6\;\;1 \\ 1\;\;7\;\;19\;\;26\;\;19\;\;7\;\;1
\end{array}$

See it?

This opens up a world of possibilities, doesn't it?

So have i actually kind of discovered something here?

And what can we actually do with my "discovery"? A world of possibilities has been opened? You're clearly seeing things that i cant...

10. Here's another of my "discoveries", made years and years ago.

We know the Binomial Theorem is based on Pascal's Triangle.
We use Pascal's Triangle for expanding $(a + b)^n$.

I wondered if there was a "Trinomial Theorem" for expanding $(a + b + c)^n$.

I cranked out the first few cases . . . and got into an awful mess.

. . $\begin{array}{ccc}(a + b + c)^0 & = & 1 \\
(a + b + c)^1 & = & a + b + c \\
(a + b + c)^2 & = & a^2 + b^2 + c^2 + 2ab + 2bc + 2ac \\
(a + b + c)^3 & = & a^3 + b^3 + c^3 + 3a^2b + 3ab^2 + 3b^2c + 3bc^2 + 3a^2c + 3ac^2 + 6abc
\end{array}$

How do we make sense out of these terms and coefficients?

It took me the longest time to see what to do:
. . arrange the terms in triangular arrays.
$\begin{array}{ccccc} & & & & a^4 \\ & & &a^3 & 4a^3b\;\;4a^3c \\& & a^2 & 3a^2b\;\;3a^2c & 6a^2b^2\;\;12a^2bc\;\;6a^2c^2 \\& a & 2ab\;\;2ac & 3ab^2\;\;6abc\;\;3ac^2 & 4ab^3\;\;12ab^2c\;\;12abc^2\;\;4ac^3 \\1\quad &\;\; b\;\;c\quad & b^2\;\;2ab\;\;c^2\quad & b^3\quad3b^2c\quad3bc^2\quad c^3\quad & b^4\quad4b^3c\quad6b^2c^2\quad 4bc^3\quad c^4\end{array}$

Look at the coefficients:
$\begin{array}{ccccc} & & & & 1 \\& & & 1 & 4\;\;4 \\& & 1 & 3\;\;3 & 6\;\;12\;\;6 \\& 1 & 2\;\;2 & 3\;\;6\;\;3 & 4\;\;12\;\;12\;\;4 \\1\quad & \;\;\;1\;\;1\quad & \;\;1\;\;2\;\;1\quad & \;\;1\;\;3\;\;3\;\;1\quad & 1\;\;\;4\;\;\;6\;\;\;4\;\;\;1\end{array}$

If we "stack" these triangles, we get a tetrahedron.
. . Each number is the sum of the three numbers above it.

I seriously doubt that I'm the first to notice all this.
But you can feel free to call it "Soroban's Tetrahedron".

11. I'm just going to try and get some formulas out of my triangle Im busy writing a small book on my discoveries in this triangle. Just for the fun of it


+0

# Assigning var

0
232
4
+4

Is there a way to define a variable to use an equation? E.x.: 3x^2-2x+5=y, and I want to assign x a value without changing it out. Is it possible?

CatBoy13  Dec 12, 2014

#3
+91479
+10

Welcome to web2.0calc forum Catboy13

Umm - Interesting question.

$$\begin{array}{rll} 3x^2-2x+5&=&y\\\\ 3x^2-2x&=&y-5\\\\ x^2-\frac{2}{3}x&=&\frac{y-5}{3}\\\\ x^2-\frac{2}{3}x+\left(\frac{2}{6}\right)^2&=&\frac{y-5}{3}+\left(\frac{2}{6}\right)^2\\\\ x^2-\frac{2}{3}x+\left(\frac{1}{3}\right)^2&=&\frac{y-5}{3}+\left(\frac{1}{3}\right)^2\\\\ x^2-\frac{2}{3}x+\left(\frac{1}{3}\right)^2&=&\frac{3(y-5)}{9}+\frac{1}{9}\\\\ \left(x-\frac{1}{3}\right)^2&=&\frac{3y-15+1}{9}\\\\ \left(x-\frac{1}{3}\right)^2&=&\frac{3y-14}{9}\\\\ x-\frac{1}{3}&=&\pm\sqrt{\frac{3y-14}{9}}\\\\ x&=&\frac{1}{3}\pm\sqrt{\frac{3y-14}{9}}\\\\ x&=&\frac{1\pm\sqrt{3y-14}}{3}}\\ \end{array}$$

Melody  Dec 13, 2014
Sort:

#1
+7188
0

I believe it is possible....but I might be wrong...

happy7  Dec 12, 2014
#2
0

If you first define a function f as

$${f}{\left({\mathtt{x}}\right)} = {\mathtt{3}}{\mathtt{\,\times\,}}{{\mathtt{x}}}^{{\mathtt{2}}}{\mathtt{\,-\,}}{\mathtt{2}}{\mathtt{\,\times\,}}{\mathtt{x}}{\mathtt{\,\small\textbf+\,}}{\mathtt{5}}$$

then for any particular x the function f(x) has a value and you can write things such as

f(2) + f(0) - 4 = 14

Guest Dec 12, 2014
#3
+91479
+10

Welcome to web2.0calc forum Catboy13

Umm - Interesting question.

$$\begin{array}{rll} 3x^2-2x+5&=&y\\\\ 3x^2-2x&=&y-5\\\\ x^2-\frac{2}{3}x&=&\frac{y-5}{3}\\\\ x^2-\frac{2}{3}x+\left(\frac{2}{6}\right)^2&=&\frac{y-5}{3}+\left(\frac{2}{6}\right)^2\\\\ x^2-\frac{2}{3}x+\left(\frac{1}{3}\right)^2&=&\frac{y-5}{3}+\left(\frac{1}{3}\right)^2\\\\ x^2-\frac{2}{3}x+\left(\frac{1}{3}\right)^2&=&\frac{3(y-5)}{9}+\frac{1}{9}\\\\ \left(x-\frac{1}{3}\right)^2&=&\frac{3y-15+1}{9}\\\\ \left(x-\frac{1}{3}\right)^2&=&\frac{3y-14}{9}\\\\ x-\frac{1}{3}&=&\pm\sqrt{\frac{3y-14}{9}}\\\\ x&=&\frac{1}{3}\pm\sqrt{\frac{3y-14}{9}}\\\\ x&=&\frac{1\pm\sqrt{3y-14}}{3}}\\ \end{array}$$

Melody  Dec 13, 2014
#4
+91479
0

I have added this to the Sticky Topic - "Great Answers to Learn From"

Melody  Dec 14, 2014

### 4 Online Users

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.  See details


# Calculation puzzle 010

Find the missing number in the sequence.

2   9   28   65   ?   217

Source: This question is taken from YTU YOS 2018 exam. I have mentioned them in other posts.

It's simply just

$$n^3 + 1$$

So

$$1^3 + 1 = 1 + 1 = 2$$
$$2^3 + 1 = 8 + 1 = 9$$
$$3^3 + 1 = 27 + 1 = 28$$
$$4^3 + 1 = 64 + 1 = 65$$
$$5^3 + 1 = 125 + 1 = 126$$
$$6^3 + 1 = 216 + 1 = 217$$

Therefore the missing number is

$$126$$

• Gz mate nice one Jul 27, 2020 at 12:51

The answer is 126 because of the pattern 1cubed +1, 2cubed+1, 3 cubed +1,4cubed +1, 5cubed+1,6cubed+1

• By the way I did not copy this answer Jul 27, 2020 at 12:47
• There was no answer as I was typing it Jul 27, 2020 at 12:47
• Don't worry, people will be able to see that you didnt from the timestamp, as you can see we both answered at almost the same time Jul 27, 2020 at 12:52
• Yesterday I answered the question 3 minutes before another guy and he still got the credit😂 I don't have good luck here Jul 27, 2020 at 12:54
• Sometimes a later answer will be accepted if the OP thinks that it's more correct or explains it better, it's not always first to get it is accepted :) Jul 27, 2020 at 12:55


# If $n$ is a positive integer, does $n^3-1$ always have a prime factor that's 1 more than a multiple of 3?

It appears to be true for all $n$ from 1 to 100. Can anyone help me find a proof or a counterexample?

If it's true, my guess is that it follows from known classical results, but I'm having trouble seeing it.

In some cases, the prime factors congruent to 1 mod 3 are relatively large, so it's not as simple as "they're all divisible by 7" or anything like that.

It's interesting if one can prove that an integer of a certain form must have a prime factor of a certain form without necessarily being able to find it explicitly.

EDITED TO ADD: It appears that there might be more going on here!

$n^2-1$ usually has a prime factor congruent to 1 mod 2 (not if n=3, though!)

$n^3-1$ always has a prime factor congruent to 1 mod 3

$n^4-1$ always has a prime factor congruent to 1 mod 4

$n^5-1$ appears to always have a prime factor congruent to 1 mod 5.

Regarding $n^2-1$: If $n>3$, then $n^2-1=(n-1)(n+1)$ is a product of two numbers that differ by 2, which cannot both be powers of 2 if they are bigger than 2 and 4. Therefore at least one of $n-1,n+1$ is divisible by an odd prime.

Regarding $n^4-1$: If $n>1$, we factor $n^4-1$ as $(n+1)(n-1)(n^2+1)$. We claim that in fact, every prime factor of $n^2+1$ is either 2 or is congruent to 1 mod 4. If $p$ is an odd prime that divides $n^2+1$, then $-1$ is a square mod $p$, but the odd primes for which $-1$ is a square mod $p$ are precisely the primes congruent to 1 mod 4. It remains just to show that $n^2+1$ cannot be a power of 2. If $n$ is even this is obvious, and if $n=2k+1$ is odd, then $n^2+1=(2k+1)^2+1=4k^2+4k+2$ is 2 more than a multiple of 4.

Regarding $n^5-1$, I don't have a proof, but based on experimenting with a few dozen numbers, I conjecture that in fact, every prime factor of $n^4+n^3+n^2+n+1$ is either 5 or is 1 more than a multiple of 5.

• From the factorization you can get a factor that's $\equiv 1 \mod 3$, but not necessarily a prime one – MCT Apr 1 '16 at 15:38
• Ran a code for the for all such numbers less than $10^7$. Seems ok. I am addin a list of the first few numbers and their prime factors. (7, 7) (26, 13) (63, 7) (124, 31) (215, 43) (342, 19) (511, 7) (728, 7) (999, 37) (1330, 7) (1727, 157) (2196, 61) (2743, 13) (3374, 7) (4095, 7) (4912, 307) (5831, 7) (6858, 127) (7999, 19) (9260, 463) (10647, 7) (12166, 7) (13823, 601) (15624, 7) (17575, 19) (19682, 13) (21951, 271) (24388, 7) (26999, 7) (29790, 331) (32767, 7) (35936, 1123) (39303, 397) (42874, 13) (46655, 7) (50652, 7) (54871, 37) (59318, 7) (63999, 13) (68920, 1723) (74087, 13) (79506, 7) – Banach Tarski Apr 1 '16 at 15:49
• Ran the code again. This statement seems to be true for all such numbers smaller than $2 * 10^8$ – Banach Tarski Apr 1 '16 at 15:56
• @idmercer: For prime powers $p>2$, you can generalize it neatly. Define $$F(n) = \frac{n^p-1}{n-1}$$ Conjecture: "If $F(n)$ is not divisible by $p$, then every odd prime factor of $F(n)$ is $1\mod 2p$." I'm not sure this is a proven result though, because otherwise the guys who answered would have used it. Maybe you can ask the general case for primes separately. – Tito Piezas III Apr 1 '16 at 22:01

The case $n=1$ is uninteresting, so let $n\gt 1$. We show that $n^2+n+1$ has a prime factor congruent to $1$ modulo $3$, by showing that $4(n^2+n+1)$ has such a prime factor.

Note that $n^2+n+1$ is odd. We first show that $3$ is not the only odd prime that divides $n^2+n+1$. For suppose to the contrary that $(2n+1)^2+3=4\cdot 3^k$ where $k\gt 1$. Then $2n+1$ is divisible by $3$, so $(2n+1)^2+3\equiv 3\pmod{9}$, contradiction.

Now let $p\gt 3$ be a prime divisor of $(2n+1)^2+3$. Then $-3$ is a quadratic residue of $p$. A straightforward quadratic reciprocity argument shows that $p$ cannot be congruent to $2$ modulo $3$.

Remark: By considering $n$ of the form $q!$ for possibly large $q$, we can use the above result to show that there are infinitely many primes of the form $6k+1$.

• Is there a general result for the odd prime factors of $\displaystyle F(n)=\frac{n^p-1}{n-1}$ for prime $p$? (The OP was just focusing on the case $p=3$.) In other words, is every odd prime factor of $F(n)$ either $p$ or $1\mod p$? – Tito Piezas III Apr 2 '16 at 18:51
• Analysis is pretty simple (Fermat's Theorem) for $n$ and $p$ such that $n$ is not congruent to $1$ mod $p$. But there can be funny prime divisors otherwise. There should be a complete easy answer in general, but I looked and am missing something. That's why the appeal to reciprocity in the answer. – André Nicolas Apr 2 '16 at 18:54
• Yes, Fermat's little theorem occurred to me as well. I may ask the general prime case in the forum. Do you think you'll figure out the answer to the general case? :) – Tito Piezas III Apr 2 '16 at 18:57
• @TitoPiezasIII: Someone will. Conceivably me, but probably not. Would likely not be in any case, but also today is a massive cooking day. – André Nicolas Apr 2 '16 at 19:00
• Ok, Bon appetit. (P.S. The question is here.) – Tito Piezas III Apr 2 '16 at 19:20

For $p\equiv 1\pmod 3$, there exist three distinct solutions of $x^3\equiv 1\pmod p$, and if $n$ is congruent modulo $p$ to such $x$ then $n^3-1$ is a multiple of $p$. Heuristically, this solves the problem affirmatively for a fraction $\frac 3p$ of all possible $n$.

Let's make this a bit less hand-wavy: Let $p_1=7, p_2=13, p_3=19,\ldots$ denote the sequence of prime $\equiv 1\pmod 3$. Then of the $M:=p_1p_2\cdots p_m$ residue classes modulo $M$, there are only $(1-\frac3{p_1})(1-\frac3{p_2})\cdots(1-\frac3{p_m})M=(p_1-3)(p_2-3)\cdots(p_m-3)$ residue classes $x$ for which $n\equiv x\pmod M$ does not imply that $n^3-1$ has a prime factor $\in\{p_1,\ldots,p_m\}$. As we let $m\to \infty$, the product $(1-\frac3{p_1})(1-\frac3{p_2})\cdots(1-\frac3{p_m})$ can be shown to tend to $0$. So at least the density of $n$ that do not work must be zero.


# Find a simple formula for $\binom{n}{0}\binom{n}{1}+\binom{n}{1}\binom{n}{2}+…+\binom{n}{n-1}\binom{n}{n}$

$$\binom{n}{0}\binom{n}{1}+\binom{n}{1}\binom{n}{2}+...+\binom{n}{n-1}\binom{n}{n}$$

All I could think of so far is to turn this expression into a sum. But that does not necessarily simplify the expression. Please, I need your help.

First note that $\dbinom{n}k = \dbinom{n}{n-k}$. Hence, your sum can be written as $$\sum_{k=0}^{n-1} \dbinom{n}k \dbinom{n}{k+1} = \sum_{k=0}^{n-1} \dbinom{n}k \dbinom{n}{n-k-1}$$ Now consider a bag with $n$ red balls and $n$ blue balls. We want to choose a total of $n-1$ bals. The total number of ways of doing this is given by $$\dbinom{2n}{n-1} \tag{\star}$$ However, we can also count this differently. Any choice of $n-1$ balls will involve choosing $k$ blue balls and $n-k-1$ red balls. Hence, the number of ways of choose $n-1$ balls with $k$ blue balls is $$\color{blue}{\dbinom{n}k} \color{red}{\dbinom{n}{n-1-k}}$$ Now to count all possible ways of choosing $n-1$ balls, we need to let our $k$ run from $0$ to $n-1$. Hence, the total number of ways is $$\sum_{k=0}^{n-1} \color{blue}{\dbinom{n}k} \color{red}{\dbinom{n}{n-k-1}} \tag{\dagger}$$ Now since $(\star)$ and $(\dagger)$ count the same thing, they must be equal and hence, we get that $$\sum_{k=0}^{n-1} \color{blue}{\dbinom{n}k} \color{red}{\dbinom{n}{n-k-1}} = \dbinom{2n}{n-1}$$

EDIT As Brian points out in the comments, the above is a special case of the more general Vandermonde's identity. $$\sum_{k=0}^r \dbinom{m}k \dbinom{n}{r-k} = \dbinom{m+n}r$$ The proof for this is essentially the same as above. Consider a bag with $m$ blue balls and $n$ red balls and count the number of ways of choosing $r$ balls from these $m+n$ balls in two different ways as discussed above.

• Love the formatting! +1 – Macavity Apr 4 '13 at 18:32
• (+1) Nicely explained. You might want to mention that it’s a case of Vandermonde’s identity, which has essentially the same proof. – Brian M. Scott Apr 4 '13 at 18:43
• Thanks so much!!!! Your explanation was great!!!! – Dome Apr 4 '13 at 18:49

We have $$\sum_{k=0}^{n-1}\dbinom{n}{k}\dbinom{n}{k+1}=\sum_{k=0}^{n}\dbinom{n}{k}\dbinom{n}{k+1}=\sum_{k=0}^{n}\dbinom{n}{k}\dbinom{n}{n+1-k}=\color{red}{\dbinom{2n}{n+1}}$$ by the Chu-Vandermonde identity and since $\dbinom{n}{n}\dbinom{n}{n+1}=0$. Another way is to use the integral representation of the binomial coefficient $$\dbinom{n}{k}=\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{n}}{z^{k+1}}dz$$ and get $$\sum_{k=0}^{n}\dbinom{n}{k}\dbinom{n}{k+1}=\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{n}}{z^{2}}\sum_{k=0}^{n}\dbinom{n}{k}z^{-k}dz$$ $$=\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{n}}{z^{2}}\left(1+\frac{1}{z}\right)^{n}dz=\frac{1}{2\pi i}\oint_{\left|z\right|=1}\frac{\left(1+z\right)^{2n}}{z^{n+2}}dz=\color{blue}{\dbinom{2n}{n+1}}.$$

There is a simple combinatorial interpretation. Assume that you have a parliament with $n$ politicians in the left wing and $n$ politicians in the right wing. If you want to select a committee made by $n-1$ politicians, you obviously have $\binom{2n}{n-1}=\binom{2n}{n+1}$ ways for doing it. On the other hand, by classifying the possible committees according to the number of politicians of the left wing in them, you have: $$\binom{2n}{n-1}=\sum_{l=0}^{n-1}\binom{n}{l}\binom{n}{n-1-l} = \sum_{l=0}^{n-1}\binom{n}{l}\binom{n}{l+1}$$ as wanted.

Hint: it's the coefficient of $T$ in the binomial expansion of $(1+T)^n(1+T^{-1})^n$, which is equivalent to saying that it's the coefficient of $T^{n+1}$ in the expansion of $(1+T)^n(1+T^{-1})^nT^n=(1+T)^{2n}$.

Note that $\ds{{n \choose k} + {n \choose k + 1} = {n + 1 \choose k + 1}}$

\begin{align} \sum_{k = 0}^{n - 1}{n \choose k}{n \choose k + 1} & = \sum_{k = 0}^{n - 1} {\bracks{{n \choose k} + {n \choose k + 1}}^{\,2} - {n \choose k}^{2} - {n \choose k + 1}^{2}\over 2} \\[5mm] & = {1 \over 2}\sum_{k = 0}^{n - 1}{n + 1 \choose k + 1}^{2} - {1 \over 2}\sum_{k = 0}^{n - 1}{n \choose k}^{2} - {1 \over 2}\sum_{k = 0}^{n - 1}{n \choose k + 1}^{2} \\[5mm] & = {1 \over 2}\sum_{k = 1}^{n}{n + 1 \choose k}^{2} - {1 \over 2}\sum_{k = 0}^{n - 1}{n \choose k}^{2} - {1 \over 2}\sum_{k = 1}^{n}{n \choose k}^{2} \\[5mm] & = {1 \over 2}\bracks{\sum_{k = 0}^{n + 1}{n + 1 \choose k}^{2} -2} - {1 \over 2}\bracks{\sum_{k = 0}^{n}{n \choose k}^{2} - 1} - {1 \over 2}\bracks{\sum_{k = 0}^{n}{n \choose k}^{2} - 1} \\[5mm] & = {1 \over 2}{2n + 2 \choose n + 1} - {2n \choose n} \end{align} where I used the well known result $\bbx{\ds{\quad\sum_{i = 0}^{m}{m \choose i}^{2} = {2m \choose m}}}$. Moreover, \begin{align} \sum_{k = 0}^{n - 1}{n \choose k}{n \choose k + 1} & = {1 \over 2}\,{\pars{2n + 2}\pars{2n + 1}\pars{2n}! \over \pars{n + 1}n!\pars{n + 1}n!} - {2n \choose n} = \pars{{2n + 1 \over n + 1} - 1}{2n \choose n} \\[5mm] & = {n \over n + 1}{2n \choose n} = {n \over n + 1}{\pars{2n}! \over n!\,n!} = {\pars{2n}! \over \pars{n + 1}!\pars{n - 1}!} = \bbx{\ds{2n \choose n + 1}} \end{align}

• It is not easy to add a new perspective to a popular sum like this one. Upvoted for originality of the approach. (+1): – Marko Riedel Feb 1 '17 at 23:24
• @MarkoRiedel Thanks. Cross terms always suggest this approach. It's useful too for products of $\log$'s, etc... – Felix Marin Feb 2 '17 at 0:14

Rewrite the sum as $\displaystyle\sum_0^{n-1}\binom{n}{k}\binom{n}{k+1}$, then by combinatorial interpretation, this is: $$\sum_{0}^{n-1}\binom{n}{k}\binom{n}{k+1}=\binom{2n}{2k+1}$$

The right hand side $\binom{2n}{2k+1}$ is the number of ways to choose $2k+1$ from a total of $2n$. For the left hand side, divide $2n$ into two groups of size $n$ of each, then if choose $k$ from one group, then must choose $2k+1-k=k+1$ from another group, sum over all possible $k$, then you get $\sum_0^{n-1}\binom{n}{k}\binom{n}{k+1}$

• What is $k$ in the rhs? – Julien Apr 4 '13 at 18:28
• I have downvoted this answer for being (mathematically) unintelligible. – anon Apr 5 '13 at 0:51

Using the estimate derived in this answer, we get \begin{align} \sum^{n-1}_{j=0}\binom{n}{j}\binom{n}{j+1} &=\sum^{n-1}_{j=0}\binom{n}{n-j}\binom{n}{j+1}\\ &=\binom{2n}{n+1}\\ &=\binom{2n}{n}\frac{n}{n+1}\\[3pt] &\sim\frac{4^n}{\sqrt{\pi n}}\left(1-\frac9{8n}\right) \end{align}


# Orthonormal Eigenbasis

I am a little apprehensive to ask this question because I have a feeling it's a "duh" question but I guess that's the beauty of sites like this (anonymity):

I need to find an orthonormal eigenbasis for the $2 \times 2$ matrix $\left(\begin{array}{cc}1&1\\ 1&1\end{array}\right)$. I calculated that the eigenvalues were $x=0$ and $x=2$ and the corresponding eigenvectors were $E(0) = \mathrm{span}\left(\begin{array}{r}-1\\1\end{array}\right)$ and $E(2) = \mathrm{span}\left(\begin{array}{c}1\\1\end{array}\right)$. Therefore, an orthonormal eigenbasis would be: $$\frac{1}{\sqrt{2}}\left(\begin{array}{r}-1\\1\end{array}\right), \frac{1}{\sqrt{2}}\left(\begin{array}{c}1\\1\end{array}\right).$$

Here my question: Could the eigenvalues for $E(0)$ been $\mathrm{span}\left(\begin{array}{r}1\\-1\end{array}\right)$?? This would make the final answer $\frac{1}{\sqrt{2}}\left(\begin{array}{r}1\\-1\end{array}\right), \frac{1}{\sqrt{2}}\left(\begin{array}{c}1\\1\end{array}\right)$. Is one answer more correct than the other (or are they both wrong)?

Thanks!

-
I don't quite understand the question as written, but if it's what I think it is, then yes, orthonormal eigenbases are not unique; you can multiply any eigenvector by a complex number of absolute value 1. –  Qiaochu Yuan Jan 6 '11 at 13:28
Or by a real number or whatever the field is that you are working over. One more thing: professional mathematicians have "duh" moments all the time. It's part of the job description, so to speak. There is absolutely no need to hide behind anonymity. On the contrary, it is important for a mathematician to learn to live with those "duh" moments. Otherwise he will never be able to freely talk with his colleagues, which would greatly hinder his progress. –  Alex B. Jan 6 '11 at 13:32
@Alex: the absolute value 1 condition is important for orthonormality, which doesn't make sense over an arbitrary field. –  Qiaochu Yuan Jan 6 '11 at 13:55
@Qiaochu You are right. Read that as "real or complex, depending on..." –  Alex B. Jan 6 '11 at 14:38

0 and 2 are the correct eigenvalues to your matrix; (1, -1) is one eigenvector, (1, 1) the other. Your solution is correct.

Span is the set of all linear combinations, so if you consider a vector space over $\mathbb{R}$, it absolutely doesn't matter what scalar in $\mathbb{R}$ you multiply your vectors with inside Span. This does not affect the set Span at all. So the solution is the same.

-

There is no such thing as the eigenvector of a matrix, or the orthonormal basis of eigenvectors. There are usually many choices.

Remember that an eigenvector $\mathbf{v}$ of eigenvalue $\lambda$ is a nonzero vector $\mathbf{v}$ such that $T\mathbf{v}=\lambda\mathbf{v}$. That means that if you take any nonzero multiple of $\mathbf{v}$, say $\alpha\mathbf{v}$, then we will have $$T(\alpha\mathbf{v}) = \alpha T\mathbf{v} = \alpha(\lambda\mathbf{v}) = \alpha\lambda\mathbf{v}=\lambda(\alpha\mathbf{v}),$$ so $\alpha\mathbf{v}$ is also an eigenvector corresponding to $\lambda$. More generally, if $\mathbf{v}_1,\ldots,\mathbf{v}_k$ are all eigenvectors of $\lambda$, then any nonzero linear combination $\alpha_1\mathbf{v}_1+\cdots+\alpha_k\mathbf{v}_k\neq \mathbf{0}$ is also an eigenvector corresponding to $\lambda$.

So, of course, since $\left(\begin{array}{r}-1\\1\end{array}\right)$ is an eigenvector (corresponding to $x=0$), then so is $\alpha\left(\begin{array}{r}-1\\1\end{array}\right)$ for any $\alpha\neq 0$, in particular, for $\alpha=-1$ as you take.

Now, a set of vectors $\mathbf{w}_1,\ldots,\mathbf{w}_k$ is orthogonal if and only if $\langle \mathbf{w}_i,\mathbf{w}_j\rangle = 0$ if $i\neq j$. If you have an orthogonal set, and you replace, say, $\mathbf{w}_i$ by $\alpha\mathbf{w}_i$ with $\alpha$ any scalar, then the result is still an orthogonal set: because $\langle\mathbf{w}_k,\mathbf{w}_j\rangle=0$ if $k\neq j$ and neither is equal to $i$, and for $j\neq i$, we have $$\langle \alpha\mathbf{w}_i,\mathbf{w}_j\rangle = \alpha\langle\mathbf{w}_i,\mathbf{w}_j\rangle = \alpha 0 = 0$$ by the properties of the inner product. As a consequence, if you take an orthogonal set, and you take any scalars $\alpha_1,\ldots,\alpha_k$, then $\alpha_1\mathbf{w}_1,\ldots,\alpha_k\mathbf{w}_k$ is also an orthogonal set.

A vector $\mathbf{n}$ is normal if $||\mathbf{n}||=1$. If $\alpha$ is any scalar, then $||\alpha\mathbf{n}|| = |\alpha|\,||\mathbf{n}|| = |\alpha|$. So if you multiply any normal vector $\mathbf{n}$ by a scalar $\alpha$ of absolute value $1$ (or of complex norm $1$), then the vector $\alpha\mathbf{n}$ is also a normal vector.

A set of vectors is orthonormal if it is both orthogonal, and every vector is normal. By the above, if you have a set of orthonormal vectors, and you multiply each vector by a scalar of absolute value $1$, then the resulting set is also orthonormal.

In summary: you have an orthonormal set of two eigenvectors. You multiply one of them by $-1$; this does not affect the fact that the two are eigenvectors. The set was orthogonal, so multiplying one of them by a scalar does not affect the fact that the set is orthogonal. And the vectors were normal, and you multiplied one by a scalar of absolute value $1$, so the resulting vectors are still normal. So you still have an orthonormal set of two eigenvectors. I leave it to you to verify that if you have a linearly independent set, and you multiply each vector by a nonzero scalar, the result is still linearly independent.

-