Algebraic Testing of Numbers Yielding Boolean Responses

Fafnir665

You just got served.
Registered Senior Member
I was just interested in an algebraic method of testing numbers for even or oddness which yields a boolean response, like 1 or 0, but it could be any two values.
 
The standard way of seeing if a number is even or odd is with modulus or remainder division by 2. If the remainder is 0, the number is even.
I just thought of another way. Although trig functions are not algebraic, it might still be useful to you. Here it is:
$$\cos^2{(\frac{\pi}{2}n)}$$
You see if n is even, you will get 1, if n is odd, you get 0.
 
That is awesome.
I spent an hour with my trig book in one of my classes today analyzing number patterns, and I got as far as realizing I needed a way to get some sort of boolean response in number format, but not in traditional boolean notation.
Heres the sequence of numbers I was trying to write a funtion for
1 3 7 9 13 15 19 21 25 etc
So, it would be, in mathlish, the sum of, k = 0 to n, 1 + ( ( 1 + whatyousaid) 2)
I could take a picture of the two pages I filled with stuff, but heres a small example
1 3 7 13 15 19 21 25
2 4 2 4 2 4 2
or
2 6 12 14 18 20 24
which are all even
then I noticed that even N add 4, while odd N add 2
which brings us to your boolean test.

This was all work that really had nothing to do with the class, the prof was just trying to demonstrate patterns or something, but it was a hell of a lot more interesting that the crap she was talking about...
Or was it a student doing some BS, I'm not entirely sure. Either way, youre awesome.
 
Only problem I see is that when the odd numbers get large, it shows that its not really 0, just incredibly small values.
 
$$\cos^2{(\frac{\pi}{2}n)}$$
Or simply $$(-1)^n$$, which gives 1 if n is even and -1 if n is odd. If you want 0 and 1 you can use:
$$\Re \left( i^n \right)^2 = \frac{1}{2}\left[ 1 + (-1)^n \right]$$​
Only problem I see is that when the odd numbers get large, it shows that its not really 0, just incredibly small values.
Those are just due to the usual numerical errors: I'd expect both $$\pi x$$ and $$\cos(x)$$ are less accurately calculated/stored for large $$x$$.

If you need to test for even/oddness of integers in a computer program, just use the modulo function.
 
$$z = 10*\lfloor \frac{x}{10} \rfloor - x $$

If z = 0, 2, 4, 6, 8 then x is even. Else, odd.

Of course, you can always do (-1)^n, but I thought it would be fun to add yet another function.
 
$$z = 10*\lfloor \frac{x}{10} \rfloor - x $$
Or work in binary:
$$z = 2*\lfloor \frac{x}{2} \rfloor - x $$​

In C you can use a bit mask to get the last binary digit (not really math, but oh well):
x & 1

(it looks like my compiler automatically substitutes expressions like "x%2" for "x&1" while optimizing)

Then I suppose there's stuff like this:
$$\int^{\infty}_{-\infty} f_n(x) \triangle_2(x) \mathrm{d}x$$
$$f_n(x) \: \equiv \: \left{ 1 \; \mathrm{if} \; x = n \\ 0 \; \mathrm{if} \; x \neq n \right.$$ (indicator function of n)

$$\triangle_2(x) \: \equiv \: \sum^{\infty}_{k = -\infty} \delta(x - 2k)$$ (Dirac comb of period 2)​
 
I was just interested in an algebraic method of testing numbers for even or oddness which yields a boolean response, like 1 or 0, but it could be any two values.
(n\2)AND(n/2)?

If the integer division isn't the same as the real division, then the division has yielded a uneven number.
 
Przyk : Whats that funky symbol mean? The one that looks kinda like an R in your original post

Cyperium: Yes, but I was looking for a boolean response, the reason for which was discussed further on.
 
Then I suppose there's stuff like this:
$$\int^{\infty}_{-\infty} f_n(x) \triangle_2(x) \mathrm{d}x$$
$$f_n(x) \: \equiv \: \left{ 1 \; \mathrm{if} \; x = n \\ 0 \; \mathrm{if} \; x \neq n \right.$$ (indicator function of n)

$$\triangle_2(x) \: \equiv \: \sum^{\infty}_{k = -\infty} \delta(x - 2k)$$ (Dirac comb of period 2)​

That integal's value is zero since f_n(x) = 0 for all but 1 value.
 
Przyk : Whats that funky symbol mean? The one that looks kinda like an R in your original post

Cyperium: Yes, but I was looking for a boolean response, the reason for which was discussed further on.
Well it would give a boolean response, since it is the logical AND, 1 AND 1 = 1, 0 AND 1 = 0

It would work in programming languages, but perhaps it wasn't what you wanted.

Like this perhaps:

(((n/2)-(n\2)) + (1 - ((n/2)-(n\2)))) * (1*((n/2)-(n\2)))

Haha, I lost track somewhere along the line lol, perhaps it works, perhaps it doesn't...
 
Przyk : Whats that funky symbol mean? The one that looks kinda like an R in your original post
$$\Re(z)$$ designates the real part of the complex number $$z$$. If you have a complex number $$z = a + b i$$ (where $$a$$ and $$b$$ are real), then $$\Re(z) = a$$.

$$i^n$$ cycles through $$i, \, -1, \, -i, \, 1$$, so $$\Re \left( i^n \right)$$ alternates between $$0$$ and $$\pm 1$$.

As it happens,
$$\Re \left( i^x \right) = \cos \left( \frac{\pi x}{2} \right)$$​
 
That integal's value is zero since f_n(x) = 0 for all but 1 value.
Unless I'm being over-sloppy somewhere,
$$\int^{\infty}_{-\infty} f_n(x) \triangle_2(x) \mathrm{d}x$$
$$= \; \sum^{\infty}_{k = -\infty} \left[ \int^{\infty}_{-\infty} f_n(x) \delta(x - 2k) \mathrm{d}x \right]$$

$$= \; \sum^{\infty}_{k = -\infty} f_n(2k)$$

$$=$$ 1 if n is a multiple of 2, and 0 otherwise.​

(not that this is what I'd call algebraic...)

*****

EDIT: Found this condition:
... for all continuous f
Ah, well, gives me an excuse to make things more complicated.

I give you:
$$\lim_{\varepsilon \rightarrow 0} \left[ \int^{\infty}_{-\infty} f_n(x, \, \varepsilon) \triangle_2(x) \mathrm{d}x \right]$$, with $$f_n(x, \, \varepsilon) \: \equiv \: \left{ 1 + \frac{x-n}{\varepsilon} \; \mathrm{if} \; -\varepsilon < x - n \leq 0 \\ 1 - \frac{x-n}{\varepsilon} \; \mathrm{if} \; 0 < x - n \leq \varepsilon \\ 0 \; \text{otherwise} \right.$$​
 
Last edited:
Well it would give a boolean response, since it is the logical AND, 1 AND 1 = 1, 0 AND 1 = 0
Are you sure it's not the equality test you're thinking of? "n\2 == n/2.0" should return "true" if n is even and "false" otherwise.
 
Are you sure it's not the equality test you're thinking of? "n\2 == n/2.0" should return "true" if n is even and "false" otherwise.
Yes, in a programming language. In a circuit the logical AND would work (if the number is translated binary of course).
 
Back
Top