An addition form of factorial? Also, automating such.

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

An addition form of factorial? Also, automating such.

Postby King Author » Mon Jan 16, 2012 12:32 am UTC

5! is the same as 5 x 4 x 3 x 2 x 1. Is there any such function for 5 + 4 + 3 + 2 + 1?

See, because I mess with math for gaming purposes, and I recently found a graphing calculator, and I'd like to automate the following...

(nCr) + (nC(r-1)) + (nC(r-2)) etc. while r > 0 and where the initial r = n.

For example, when I plug a 4 into the program, I want it to return 15 (4C4 + 4C3 + 4C2 + 4C1).

Now, I don't know how to write programs with this kakkalater (it's a Casio fx-9750GII), Imma have to figure that one out on my own, however, even if I did, I wouldn't know how to express "(nCr) + (nC(r-1)) + (nC(r-2)) etc. while r > 0 and where the initial r = n" in a format a graphic calculator could understand.

Any help?
In 01, electric sheep dream of you!
User avatar
King Author
 
Posts: 525
Joined: Sun Apr 12, 2009 12:30 pm UTC
Location: Pennsylvania, USA

Re: An addition form of factorial? Also, automating such.

Postby Qaanol » Mon Jan 16, 2012 12:41 am UTC

The sum of the integers from 1 through n equals n(n+1)/2. The sum of the choose functions nC0 through nCn equals 2n. Since nC0=1, the sum of the choose functions nC1 through nCn equals 2n-1.

Edit: D’oh! Silly minus sign. Fixed now, thanks Skep.
Last edited by Qaanol on Mon Jan 16, 2012 12:46 am UTC, edited 3 times in total.
Small Government Liberal
User avatar
Qaanol
 
Posts: 2233
Joined: Sat May 09, 2009 11:55 pm UTC

Re: An addition form of factorial? Also, automating such.

Postby skeptical scientist » Mon Jan 16, 2012 12:42 am UTC

There's a simple formula: n(n+1)/2. See http://en.wikipedia.org/wiki/Triangular_number.

Edit: I'd say I was ninja'd by Qaanol, but he got the formula wrong.
I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson
User avatar
skeptical scientist
closed-minded spiritualist
 
Posts: 5920
Joined: Tue Nov 28, 2006 6:09 am UTC
Location: Madison, Wisconsin

Re: An addition form of factorial? Also, automating such.

Postby mr-mitch » Mon Jan 16, 2012 9:40 am UTC

You can, of course, extend this to the sum of any arithmetic series/progression, starting at a and ending at b with a constant step d.

The idea is sum twice as much, and then divide by two.

4 + 7 + 10 + 13
13 + 10 + 7 + 4

Each pair adds up to 17, and you have four pairs.

Hence the total is 17x4/2 = 34.

In general, it's [(b-a+d)/d] . [(a+b) / 2]
Or, if you know your starting point a, the number of terms n, and the step size d:
Image
mr-mitch
 
Posts: 449
Joined: Sun Jul 05, 2009 6:56 pm UTC

Re: An addition form of factorial? Also, automating such.

Postby King Author » Thu Apr 05, 2012 4:01 pm UTC

Just found this topic in my "View your posts," know it's old but wanted to say thanks for your help, guys. However, I figured out a simpler way to get what I was looking for, and you're all gonna laugh at me for how moronic I was.

4C4 + 4C3 + 4C2 + 4C1 = 2^4

"(nCr) + (nC(r-1)) + (nC(r-2)) etc. while r > 0 and where the initial r = n" is the exact same thing as "2^n"

And I shoulda known that, because I'm always thinking in terms of bits and bytes because when I design my videogames for fun, I try to make them as computationally efficient as possible, so I'm always fussing over getting as much out of each individual bit as possible.

I did not know that 5 + 4 + 3 + 2 + 1 or whatever were "triangular numbers," though. That's useful, thanks.

mr-mitch wrote:You can, of course, extend this to the sum of any arithmetic series/progression, starting at a and ending at b with a constant step d.

The idea is sum twice as much, and then divide by two.

4 + 7 + 10 + 13
13 + 10 + 7 + 4

Each pair adds up to 17, and you have four pairs.

Hence the total is 17x4/2 = 34.

In general, it's [(b-a+d)/d] . [(a+b) / 2]
Or, if you know your starting point a, the number of terms n, and the step size d:
Image

"Sum twice as much then divide by two." Okay, lemme see if I can get your sequence from that.
Start with 4.
Twice 4 is 8.
Summed with 4 is 12.
Half of which is 6.

Hmm. Lost. If I divided that 6 again, I'd get 3, which fits the sequence (4 + 3 = 7). Lemme keep going with that.

7.
Twice is 14.
Added to 7 is 21.
Half of which is 10.5.
Another half of which is 5.25.

No, I'm lost. Wait, what numbers are a, b and d above? Can you explain how you got that sequence of numbers (4 + 7 + 10 + 13) from [(b-a+d)/d] . [(a+b) / 2]?
In 01, electric sheep dream of you!
User avatar
King Author
 
Posts: 525
Joined: Sun Apr 12, 2009 12:30 pm UTC
Location: Pennsylvania, USA

Re: An addition form of factorial? Also, automating such.

Postby Xanthir » Thu Apr 05, 2012 5:17 pm UTC

King Author wrote:Just found this topic in my "View your posts," know it's old but wanted to say thanks for your help, guys. However, I figured out a simpler way to get what I was looking for, and you're all gonna laugh at me for how moronic I was.

4C4 + 4C3 + 4C2 + 4C1 = 2^4

Not quite. That's equal to (2^4)-1. You have to add in the last term, 4C0, to make it a power of 2.

King Author wrote:No, I'm lost. Wait, what numbers are a, b and d above? Can you explain how you got that sequence of numbers (4 + 7 + 10 + 13) from [(b-a+d)/d] . [(a+b) / 2]?

He explained at the top of his quote. a is the start number, b is the end number, and d is the step.

The "4 + 7 + 10 + 13" bit was the arithmetic sequence he was talking about. In this, a=4, b=13, and d=3. Plug them all into the equation.

Don't just take one line like "sum twice as much then divide by two" and interpret it arbitrarily. ^_^
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 3987
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: An addition form of factorial? Also, automating such.

Postby Meteoric » Thu Apr 05, 2012 5:25 pm UTC

The "Sum twice as much and divide by two" thing is a trick that lets you pair things up even when you have an odd number of things. If I want to add the numbers from 1 through 100, no problem, I pair up 1 and 100, 2 and 99, 3 and 98, etc, for a total of 50 pairs, each totaling 101, so 50x101 = 5050. But if I want all the numbers from 1 through 101, there will be one number left unpaired, which doesn't fit as nicely into a formula. So we take our
1+2+3+...+100+101
flip it around, and add it again:
101+100+...+3+2+1
Then pair up the numbers vertically: 1+101, 2+100, 3+99, and so on, making 101 pairs, each totaling 102. 101x102 = 10302. Since we added each number twice, though, you then cut that in half to get the actual answer, which is 10302/2 = 5151.

You don't have to work through this process every time, you can just plug directly into the formula. This just explains how we derive the formula so that it works whether we're summing an even or odd number of terms.
No, even in theory, you cannot build a rocket more massive than the visible universe.
Meteoric
 
Posts: 175
Joined: Wed Nov 23, 2011 4:43 am UTC

Re: An addition form of factorial? Also, automating such.

Postby King Author » Thu Apr 05, 2012 11:39 pm UTC

Xanthir wrote:
King Author wrote:Just found this topic in my "View your posts," know it's old but wanted to say thanks for your help, guys. However, I figured out a simpler way to get what I was looking for, and you're all gonna laugh at me for how moronic I was.

4C4 + 4C3 + 4C2 + 4C1 = 2^4

Not quite. That's equal to (2^4)-1. You have to add in the last term, 4C0, to make it a power of 2.

Er, yeah, I forgot the -1. Which, to continue with the bits example, negates the all-zeroes state, which while possible in bits, isn't in combinatorics. At least not for the stuff I'm calculating (combinations of stuff like stat boosts, elemental types, etc.).

Xanthir wrote:
King Author wrote:No, I'm lost. Wait, what numbers are a, b and d above? Can you explain how you got that sequence of numbers (4 + 7 + 10 + 13) from [(b-a+d)/d] . [(a+b) / 2]?

He explained at the top of his quote. a is the start number, b is the end number, and d is the step.

The "4 + 7 + 10 + 13" bit was the arithmetic sequence he was talking about. In this, a=4, b=13, and d=3. Plug them all into the equation.

Don't just take one line like "sum twice as much then divide by two" and interpret it arbitrarily. ^_^

Oh, whoops. Yeah, I see that now. I thought he got 4/7/10/13 from entering some other numbers into the equation, I didn't realize from his wording what he was saying.

Meteoric wrote:The "Sum twice as much and divide by two" thing is a trick that lets you pair things up even when you have an odd number of things. If I want to add the numbers from 1 through 100, no problem, I pair up 1 and 100, 2 and 99, 3 and 98, etc, for a total of 50 pairs, each totaling 101, so 50x101 = 5050. But if I want all the numbers from 1 through 101, there will be one number left unpaired, which doesn't fit as nicely into a formula. So we take our
1+2+3+...+100+101
flip it around, and add it again:
101+100+...+3+2+1
Then pair up the numbers vertically: 1+101, 2+100, 3+99, and so on, making 101 pairs, each totaling 102. 101x102 = 10302. Since we added each number twice, though, you then cut that in half to get the actual answer, which is 10302/2 = 5151.

You don't have to work through this process every time, you can just plug directly into the formula. This just explains how we derive the formula so that it works whether we're summing an even or odd number of terms.

Oh, cool. Is that what mr-mitch was talking about? I totally didn't get that. Thanks for explaining it.

And hey, I recognize 5050 and 5151 as triangular numbers! </feels undeservedly smart for realizing that>
In 01, electric sheep dream of you!
User avatar
King Author
 
Posts: 525
Joined: Sun Apr 12, 2009 12:30 pm UTC
Location: Pennsylvania, USA


Return to Mathematics

Who is online

Users browsing this forum: ingdu50A and 4 guests