## Finding if an integer is odd through Riemann or some function?

I'm trying to find if a number is odd or not, basically if X % 2 = 1.

Can this be expressed through some function? Like the sum of 1 + 2 .. +n is n(n+1) /2

Or as a Riemann sum?

I'm trying to add only the odd numbers from a random set of N integers to a sum.

 Quote by caljuice I'm trying to find if a number is odd or not, basically if X % 2 = 1. Can this be expressed through some function? Like the sum of 1 + 2 .. +n is n(n+1) /2 Or as a Riemann sum? I'm trying to add only the odd numbers from a random set of N integers to a sum.
Do you mean in some programming language? If '/' is integer division, then x is even if and only if

x = 2 * (x/2). [using '=' as equality, not assignment]

But if you already have a mod operator like % then you can just use that.
 i'm not entirely sure what you're getting at either, but 2*n+1 is always an odd number, for any value of n.

## Finding if an integer is odd through Riemann or some function?

ohh okay i think i see what you're saying, you have a set of random numbers, and you only want to add the odd ones.
yes the modulus function works well.
if(x%2 == 1){
...
}
alternatively, you can test the last bit to see if it's 1.
if(x&1 == 1){
...
}
this is slightly faster.
 Not what I meant but I did word this problem poorly. It's actually probably a bad and weird question anyway. I appreciate the help though For example Let's say the set of integers is from some function( not random anymore) $\sum \limits_{i=1}^n A[i] (A[i]\mod{2})$ is only adding odd terms but the equation is not reducible, so I was hoping the % could be expressed differently so I could solve or reduce the problem. If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.

 Quote by caljuice If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.
I fail to see how Riemann sums would be relevant in what appears to be a discrete math question.

Recognitions:
Gold Member
 Quote by caljuice Not what I meant but I did word this problem poorly. It's actually probably a bad and weird question anyway. I appreciate the help though For example Let's say the set of integers is from some function( not random anymore) $\sum \limits_{i=1}^n A[i] (A[i]\mod{2})$ is only adding odd terms but the equation is not reducible, so I was hoping the % could be expressed differently so I could solve or reduce the problem. If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.
I think he wants do something like the trick with minus signs alternating by using n for an exponent on -1. Just a guess here.

 Quote by coolul007 I think he wants do something like the trick with minus signs alternating by using n for an exponent on -1. Just a guess here.
So something like
##\frac{1 - (-1)^n}{2}##

Recognitions:
Gold Member
 Quote by pwsnafu So something like ##\frac{1 - (-1)^n}{2}##
adding all the odds would look like this:

$\sum n(\frac{1 - (-1)^n}{2})$

where n is a positive integer
 Ya that works, thanks guys. Sorry about the poor wording. I used that equation daily in my fourier series class, I'm surprised I forgot about that after one summer.

Blog Entries: 2
 Quote by caljuice Not what I meant but I did word this problem poorly. It's actually probably a bad and weird question anyway. I appreciate the help though For example Let's say the set of integers is from some function( not random anymore) $\sum \limits_{i=1}^n A[i] (A[i]\mod{2})$ is only adding odd terms but the equation is not reducible, so I was hoping the % could be expressed differently so I could solve or reduce the problem. If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.
I don't understand the problem here. All odd numbers equal 1 mod 2, so adding n odd numbers will give you the result in mod 2 the following:

$\sum \limits_{i=1}^n A[i]\mod{2}) = n$ so n odd numbers will give an even number if n is even and an odd number if n is odd. There is no need to use more complex functions.

 Quote by ramsey2879 I don't understand the problem here. All odd numbers equal 1 mod 2, so adding n odd numbers will give you the result in mod 2 the following: $\sum \limits_{i=1}^n A[i]\mod{2}) = n$ so n odd numbers will give an even number if n is even and an odd number if n is odd. There is no need to use more complex functions.
He doesn't want to count the number of odd A[i], but to sum only the odds. So if
##A = (1,2,3,5,7,8,10)##, he wants an expression which evaluates 1+3+5+7.

 Quote by pwsnafu He doesn't want to count the number of odd A[i], but to sum only the odds. So if ##A = (1,2,3,5,7,8,10)##, he wants an expression which evaluates 1+3+5+7.
Oh I see. Well then how about

x = $\displaystyle \sum_{k=1}^n a_ksin^2(a_k\pi)$

If ak is even, sin(ak$\pi$) is 0; and if it's odd, sin(ak$\pi$) is +/- 1.
 Hmm, this looks neat, so you are going to add all the odd terms in f(x)? So you need, as a function, $\displaystyle \sum_{x=a}^n f(x)\frac{1-(-1)^{f(x)}}{2}$. That looks like a really cool and useful function! I have literally filled notebooks finding sums like that, so I have a huge collection, but I've never used a power of f(x) for anything other than f(x)=c or f(x)=x. Do you mind if I play with this? The most that I can simplify this too, without any extra exploration is: $\displaystyle \sum_{x=a}^n f(x)\frac{1-(-1)^{f(x)}}{2} = \sum_{x=a}^n \frac{f(x)}{2}-\sum_{x=a}^n f(x)\frac{(-1)^{f(x)}}{2}$ For my own purposes, I will want to look at x=0, specifically. If I want to look at specific parts of (f(x), I will use f(x-c). EDIT: I realised after working through this a bit that I forgot to multiply by f(x). The formulas above are corrected (I hope). However, I do have a list of solutions that relate to the correct version (where f(x)=xa for some non-negative integer a). Typically, the first part of that sum would be calculated with the Hurwitz Zeta function and the Riemann Zeta function (though I have a different way that I prefer). The second part, I believe, can be similarly computed. For cases where f(x) is a polynomial, this should not be difficult to compute, especially as it can be expressed as a linear combination of cnxn
The content structure of the passage involves a discussion about methods to determine if a number is odd and how to sum only the odd numbers from a set of integers. The discussion includes various suggestions and mathematical expressions to achieve this, including the use of the modulus operator, bitwise operations, and a function involving the sine function.
multiple_questions_with_answers
Given a text passage, determine:
    1. If it contains a mathematical question (including word problems or calculations)
    2. If an answer to that mathematical question is provided in the text

First, describe the content structure you found in 1-2 sentences.

Then provide your analysis in the following format:
TYPE: <one of the following values>
- NO_QUESTION
- SINGLE_QUESTION
- SINGLE_QUESTION_WITH_ANSWER
- MULTIPLE_QUESTIONS
- MULTIPLE_QUESTIONS_WITH_ANSWERS
system
## Finding if an integer is odd through Riemann or some function?

I'm trying to find if a number is odd or not, basically if X % 2 = 1.

Can this be expressed through some function? Like the sum of 1 + 2 .. +n is n(n+1) /2

Or as a Riemann sum?

I'm trying to add only the odd numbers from a random set of N integers to a sum.

 Quote by caljuice I'm trying to find if a number is odd or not, basically if X % 2 = 1. Can this be expressed through some function? Like the sum of 1 + 2 .. +n is n(n+1) /2 Or as a Riemann sum? I'm trying to add only the odd numbers from a random set of N integers to a sum.
Do you mean in some programming language? If '/' is integer division, then x is even if and only if

x = 2 * (x/2). [using '=' as equality, not assignment]

But if you already have a mod operator like % then you can just use that.
 i'm not entirely sure what you're getting at either, but 2*n+1 is always an odd number, for any value of n.

## Finding if an integer is odd through Riemann or some function?

ohh okay i think i see what you're saying, you have a set of random numbers, and you only want to add the odd ones.
yes the modulus function works well.
if(x%2 == 1){
...
}
alternatively, you can test the last bit to see if it's 1.
if(x&1 == 1){
...
}
this is slightly faster.
 Not what I meant but I did word this problem poorly. It's actually probably a bad and weird question anyway. I appreciate the help though For example Let's say the set of integers is from some function( not random anymore) $\sum \limits_{i=1}^n A[i] (A[i]\mod{2})$ is only adding odd terms but the equation is not reducible, so I was hoping the % could be expressed differently so I could solve or reduce the problem. If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.

 Quote by caljuice If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.
I fail to see how Riemann sums would be relevant in what appears to be a discrete math question.

Recognitions:
Gold Member
 Quote by caljuice Not what I meant but I did word this problem poorly. It's actually probably a bad and weird question anyway. I appreciate the help though For example Let's say the set of integers is from some function( not random anymore) $\sum \limits_{i=1}^n A[i] (A[i]\mod{2})$ is only adding odd terms but the equation is not reducible, so I was hoping the % could be expressed differently so I could solve or reduce the problem. If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.
I think he wants do something like the trick with minus signs alternating by using n for an exponent on -1. Just a guess here.

 Quote by coolul007 I think he wants do something like the trick with minus signs alternating by using n for an exponent on -1. Just a guess here.
So something like
##\frac{1 - (-1)^n}{2}##

Recognitions:
Gold Member
 Quote by pwsnafu So something like ##\frac{1 - (-1)^n}{2}##
adding all the odds would look like this:

$\sum n(\frac{1 - (-1)^n}{2})$

where n is a positive integer
 Ya that works, thanks guys. Sorry about the poor wording. I used that equation daily in my fourier series class, I'm surprised I forgot about that after one summer.

Blog Entries: 2
 Quote by caljuice Not what I meant but I did word this problem poorly. It's actually probably a bad and weird question anyway. I appreciate the help though For example Let's say the set of integers is from some function( not random anymore) $\sum \limits_{i=1}^n A[i] (A[i]\mod{2})$ is only adding odd terms but the equation is not reducible, so I was hoping the % could be expressed differently so I could solve or reduce the problem. If finding the number was odd or mod or % 2 was rewritable as a function or riemann sum, then I could reduce or solve the problem.
I don't understand the problem here. All odd numbers equal 1 mod 2, so adding n odd numbers will give you the result in mod 2 the following:

$\sum \limits_{i=1}^n A[i]\mod{2}) = n$ so n odd numbers will give an even number if n is even and an odd number if n is odd. There is no need to use more complex functions.

 Quote by ramsey2879 I don't understand the problem here. All odd numbers equal 1 mod 2, so adding n odd numbers will give you the result in mod 2 the following: $\sum \limits_{i=1}^n A[i]\mod{2}) = n$ so n odd numbers will give an even number if n is even and an odd number if n is odd. There is no need to use more complex functions.
He doesn't want to count the number of odd A[i], but to sum only the odds. So if
##A = (1,2,3,5,7,8,10)##, he wants an expression which evaluates 1+3+5+7.

 Quote by pwsnafu He doesn't want to count the number of odd A[i], but to sum only the odds. So if ##A = (1,2,3,5,7,8,10)##, he wants an expression which evaluates 1+3+5+7.
Oh I see. Well then how about

x = $\displaystyle \sum_{k=1}^n a_ksin^2(a_k\pi)$

If ak is even, sin(ak$\pi$) is 0; and if it's odd, sin(ak$\pi$) is +/- 1.
 Hmm, this looks neat, so you are going to add all the odd terms in f(x)? So you need, as a function, $\displaystyle \sum_{x=a}^n f(x)\frac{1-(-1)^{f(x)}}{2}$. That looks like a really cool and useful function! I have literally filled notebooks finding sums like that, so I have a huge collection, but I've never used a power of f(x) for anything other than f(x)=c or f(x)=x. Do you mind if I play with this? The most that I can simplify this too, without any extra exploration is: $\displaystyle \sum_{x=a}^n f(x)\frac{1-(-1)^{f(x)}}{2} = \sum_{x=a}^n \frac{f(x)}{2}-\sum_{x=a}^n f(x)\frac{(-1)^{f(x)}}{2}$ For my own purposes, I will want to look at x=0, specifically. If I want to look at specific parts of (f(x), I will use f(x-c). EDIT: I realised after working through this a bit that I forgot to multiply by f(x). The formulas above are corrected (I hope). However, I do have a list of solutions that relate to the correct version (where f(x)=xa for some non-negative integer a). Typically, the first part of that sum would be calculated with the Hurwitz Zeta function and the Riemann Zeta function (though I have a different way that I prefer). The second part, I believe, can be similarly computed. For cases where f(x) is a polynomial, this should not be difficult to compute, especially as it can be expressed as a linear combination of cnxn
user
The content structure of the passage involves a discussion about methods to determine if a number is odd and how to sum only the odd numbers from a set of integers. The discussion includes various suggestions and mathematical expressions to achieve this, including the use of the modulus operator, bitwise operations, and a function involving the sine function.

TYPE: MULTIPLE_QUESTIONS_WITH_ANSWERS