meatbag Posted November 19, 2008 Posted November 19, 2008 I know this is a stupid question but Im going to ask it anyway Ive written an iterative algorithm in C (programming language) and wondered how to represent this in maths. For example, int main(void) { int x; for(x=40; x>0; x/=2) { process(x); } return 0; } So each of the following is put into the equation... 40 20 10 5 2 1 Basically all I want to know is what do you use in maths to represent equating a formula with a range of input values?
Shadow Posted November 19, 2008 Posted November 19, 2008 Well, there isn't exactly anything like that (by the way, it's called looping) in math that I know of. The closest one can get (to my limited knowledge) is with the Product or Sum. But then again, there may be other methods I'm not aware of. Quite frankly, I'm curious myself, I've often wondered about this. Cheers, Gabe
Shadow Posted November 21, 2008 Posted November 21, 2008 Doesn't that require you to define [math]a_0[/math] in advance?
Bignose Posted November 21, 2008 Posted November 21, 2008 Doesn't that require you to define [math]a_0[/math] in advance? Ok, so what? The point is that the series I gave follows exactly what the OP wants. You can take any [math]a_0[/math] you want, it is will still halve the number every step in the series. It performs exactly what the OP wanted.
Shadow Posted November 22, 2008 Posted November 22, 2008 Not exactly. You have to state that [math]a \in N[/math]. I'm not sure how you do that with an entire series, since we haven't covered series at school yet, but you get the point. Also, apart from the fact that I believe the OP wanted to know how to represent a loop in math, in the OP's example, [math]a_0=40[/math], not one. So while your series will hold the same numbers, it will hold them in the wrong order. I don't know the solutions to these problems, I'm just pointing out the problems themselves. Cheers, Gabe
the tree Posted November 22, 2008 Posted November 22, 2008 (edited) Well if you want to be really fussy then: [math]a_{n+1} = \begin{cases} \frac{1}{2} a_n & a_n \in \mathbb{N}_{\mbox{even}} \\ a_{n+1} \uparrow & \mbox{otherwise} \end{cases}[/math] Which never did give the sequence in the wrong order. Edited November 22, 2008 by the tree
Shadow Posted November 22, 2008 Posted November 22, 2008 I can only guess at what that means But thanks anyway
the tree Posted November 22, 2008 Posted November 22, 2008 It says, a[n+1] equals half a[n] if a[n] is in the even naturals, a[n+1] is undefined otherwise. (I would have written undefined instead of the silly arrow notation but typing def throws up an error in these forums)
Shadow Posted November 22, 2008 Posted November 22, 2008 I see, thanks for the clarification. But the OP uses integer division, so if [math]a_n[/math] is not an even natural, [math]a_{n+1}[/math] shouldn't be undefined. For example, if [math]a_n=5[/math], then [math]a_{n+1}=2[/math]...how would you write that? Does 5/2 equal 2 in N? Cheers, Gabe
the tree Posted November 22, 2008 Posted November 22, 2008 Oh, so he does, sorry. an+1 = quotient(an,2) then.
Shadow Posted November 22, 2008 Posted November 22, 2008 How would you write quotient in math? Just "quotient"? But thanks anyway. Now, shouldn't we get back to the OP's question? That being how to represent a loop in math? Cheers, Gabe
the tree Posted November 22, 2008 Posted November 22, 2008 All my notes involving looping algorithms are just written in pseudo code. Iterative formulae seem more obvious but neither is really more mathsy than the other. Maths, contrary to popular belief, isn't a language. While there's specific mathematical notation for a lot of things, there isn't for most and it's perfectly acceptable to write in English or use pseudocode or a formal programming language.
Shadow Posted November 22, 2008 Posted November 22, 2008 Wow...I never knew it was acceptable to use a programming language in math I'll be sure to inform my maths teacher that from now on I'm doing all my homework in C++ Cheers, Gabe
meatbag Posted November 27, 2008 Author Posted November 27, 2008 Thanks for the input guys. It seems I wasn't being silly
the tree Posted November 27, 2008 Posted November 27, 2008 One is never silly by being curious. With the significant exception of being curious about what happens when you stick a fork into toaster shortly after having showered and holding a copper wire that is wrapped around everyone you've ever loved. That would be silly.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now