Wednesday, December 21, 2011

Why 1 ≠ 2 (and how divide by zero can work)

So, the argument is posed that:

0 * 1 = 0
0 * 2 = 0


0 * 1 = 0 * 2

So far so good, but according to the rules of algebra, you can add any operation to 1 side as long as you do it to the other side so let's add a division by 0:

(0 * 1)/0 = (0 * 2)/0


0 * (1/0) = 0 * (2/0)


(0/0) * 1 = (0/0) * 2

and through simplification of x/x = 1:
(1) * 1 = (1) * 2

Obviously this is not correct...

As I talked about in my last blog entry, x/0 = {}, the answer to a division by zero is actually a set. Now the question is, what is returned in the set? Is it always -inf to inf? Or is there a relevance factor that has to be taken into account that returns a subset?

Let's say for a moment that 0/0 = {-inf, inf}.

the the above proof actually translates to:

{-inf, inf} * 1 = {-inf, inf} * 2

which is true. All numbers multiplied by 2 results in the same numbers as all numbers multiplied by 1.

But let's try breaking it by dividing both sides by {-inf, inf}:

({-inf, inf}/{-inf, inf}) * 1 = ({-inf, inf}/{-inf, inf}) * 2

Well, now we're back in trouble.

Or are we? If we treat these sets as matrices with an infinite number of values ranging from -inf to inf then we can almost do this! The only problem we face is that the matrices are all in the same dimension. What if we made a rule that said if the matrices are in the same dimension, that one (perhaps the bottom one) should always be transposed? From there we simply invert and multiply.

The result would simply become:
inf * 1 = inf * 2

Which is again true since infinity is as big as you can get. OK, it is said that some infinities are bigger than others, but really? Infinity literally means "boundless" or "without limit". You can get an equation that solves to 2*inf, but like any x*0=0, any x*inf really is just inf.

x / 0 = {}

It has been a very long time since I posted here, but I have just had a Eureka! moment.

Since I have started this blog, I have contemplated what 0^0 means, and what x/0 means, and I have been stumped by the lack of a truly real world example that has a neat mathematical equation to go with it. Sure pies are nice, but they leave room for debate.

Lately, I have been working with geometry for 3D image rendering, and I cam across an interesting problem: How do I get the Z coordinate of a point in a triangle when given the X and Y coordinates?

That's easy enough; Use the 3 vertices of the triangle to determine the plane the triangle sets on, and then solve the plane equation:

Ax + By + Cz + D = 0

for the Z coordinate:

z = (-Ax-By-D) / C = x(-A/C) + y(-B/C) + (-D/C)

So here is an obvious situation of x/0, and when you are programming, you need to define the answer so your program doesn't crash.

What does x/0 mean here?
It means you are looking at a plane parallel to the Z axis is what it means. And this is a very real world situation that has a very clear mathematical expression.

A real world example would be, say you are standing on a street corner and you point at the side of a building. Your finger (or what ever pointing apparatus you might be using) points at a single spot on the wall. You can clearly establish one answer. You are pointing at a spot that is 5feet above the side walk and 20feet from the front of the building and that spot is 150feet away from you. Your example may differ, but this illustrates the point.

Now, say you moved yourself so you were in perfect alignment with the wall (so you are on the same plane as it is) and you point at that same spot on the wall. What you will likely think is that you are now actually pointing at the front corner of the building, and you would be right. But imagine the line your finger (or pointing apparatus) makes. It goes through that front corner and extends all the way along the wall. By pointing at the wall, you are actually pointing at many points on that wall at the same time!

You are pointing at that spot on the wall, so that spot is real, and is a valid answer to the question "What are you pointing at?" But you should also realize that you are pointing at every spot on the line that is formed by you pointing at that one spot. This means that there is actually a whole set of correct answers. Remember how you were thinking you were pointing at the front corner of the building? That was ALSO a valid answer!

This proves that what divide by zero represents is multiple answers at once! It's not necessarily infinity, and it's not necessarily 0 or 1 or anything.

In the pure plane equation, for any given X and Y pair that looks down a plain parallel to the Z axis, all the answers from -infinity to +infinity are valid answers.

C = 0 therefore z = (-Ax-By-D) / C = {-inf, inf}

Now, my notation may not be perfect but I wasn't a math major, but this is clear enough to state the point.

In the case of our wall, only a subset of those answers are correct. We have stated that we are pointing at a point ON the wall. The wall does not extend for forever, so the answers are only valid from one side of the wall to the other.

Say you are the reference point so our wall starts 5 feet away and ends 100 feet away. We can say that the range of valid answers are between 5 and 100 feet.
C = 0 therefore z = (-Ax-By-D) / C = {5, 100}

You could even reduce the set to exactly one answer if you defined the parameters well enough. For instance you could just say you are pointing at the front corner of the building. Then our answer is simply:
C = 0 therefore z = (-Ax-By-D) / C = {5}

The whole set of the possible answers is made up of only 1 answer.

And thus x/0 IS defined as a set.

Thursday, August 20, 2009

Proofs of of div-by-zero and 0^0

Ok. I'm refreshed and I've had a few new thoughts on how to pursue this topic. I have been noticing that people seem to use patterns as proof that 2^0 = 1. Defining exponents as repetitive multiplication, and multiplication as repetitive addition, it would seem that 2^0 is undefined:

2^3 = 2 * 2 * 2 = (2+2)+(2+2) = 8
2^2 = 2 * 2 = (2+2) = 4
2^1 = 2 = 2 = 2
2^0 = = = ???
2^-1= 1/2 = 1/2 = 1/2

Although the empty product would explain it as:

2^3 = 1 * 2 * 2 * 2 = 1*((2+2)+(2+2)) = 8
2^2 = 1 * 2 * 2 = 1* (2+2) = 4
2^1 = 1 * 2 = 1* (2) = 2
2^0 = 1 = 1 = 1
2^-1= 1 * 1/2 = 1* (1/2) = 1/2

But when considering 0^0, the empty product would say:
0^3 = 1 * 0 * 0 * 0 = 1*0 = 0
0^2 = 1 * 0 * 0 = 1*0 = 0
0^1 = 1 * 0 = 1*0 = 0
0^0 = 1 = 1 = 1
0^-1= 1 * 1/0 = 1*0 = 0 <-- ?

Also defining 0^0 as equal to 1.

Now, the 0^-1 leads to the div-by-0 question, especially 0/0?
Using the pattern, x/x = 1 for all x, why wouldn't 0/0 be 1? x/x, for every number, even those infinitely close to 0 (Lim x->0), yields 1, yet not 0, which leaves an undefined point on the graph.

The same argument is used for z^0 = 1(where z not equal 0). I use z here since I'm talking about a graph and want the exponent to be the x axis for clarification. The graph of z^x looks like it would go right through 1 (except for z=0) there for it must go through 1, right? Well, we know that, just because something seems like it should be, doesn't make it so, but let's go with it for the time being.

If that is the case, then let's consider all z for z^x from inf as it approaches 0. When z = inf, z^x = inf for all positive x and infinitely close to 0 for all negative x. Does it equal 1 when x = 0?

As z falls from inf and approaches 1, the exponential curve broadens until, at z=1, it becomes a perfectly horizontal line at y=1. As z continues down from 1 towards 0, the curve changes so that the negative exponents increase towards infinity, and the positives fall towards 0. When we are infinitely close to z=0, we have the mirror of z=inf, so what about when z = 0?

0^x represents the true impulse function. It is 0 for all x's except x=0 where it equals 1.

0^0 is 1, unless all other x^0 are also considered undefined. We have a choice to either use the empty product or not.

Now, going back to div-by-zero; 0 can divide 0 into 0 parts evenly. My friend Mal made the next logical leap: 0 can not divide 1 evenly into 0 parts, there for the answer is 0 remainder 1. Here's a few examples:

3/0 = 0 reaminder 3
2/0 = 0 reaminder 2
1/0 = 0 reaminder 1
0/0 = 0 reaminder 0 or 1 remainder 0
-1/0 = 0 reaminder -1

This is supported by the long division process:
0 ) 10

Let's follow the procedure in words:
The first question can be phrased a couple of ways: "How many times can 0 go into 1?", but also "How many parts can 0 divide 1 into evenly?"
One might think the answer is infinity, or 0, but 0 is the only correct answer, and here's why. Zero represents nothing. Even if you chopped 1 into an infinite number of pieces, there would still be pieces, not nothing, so the answer is simply, you can not divide 1 into 0 parts which means that the answer to put above the 1, is 0.
Doing the remainder for the first part, we subtract off 0*0, which leaves 1. Bring down the next most significant digit, the 0, and now we have to divide 10, in its entirety, by zero. Well, the same logic applies as before. 10 can not be divided by 0, so a 0 goes above the 0 also. That completes the quotient part of the process, and now we have to determine how we want to handle the remainder. The remainder is 10, so we can either put that into fraction form (10/0) or we can continue the division process into the decimal places, which would yield infinite 0's.

Let's look at it a different way. Mal described div-by-zero as removing pennies from a pile on a table. I would like to use the examples of pies. When you serve pie, you divide it up and put it onto plates to be served. If you have one pie, and 3 people want it, each plate will get 1/3 of the pie put on their plate. If two people wanted the pie divided between them, then 1/2 the pie would be removed from the pie pan and placed on 1 plate and the other 1/2 would be put on a second plate.

Now here is were an interesting concept get's introduced, the remainder. If only 1 person wanted 1/2 the pie, then 1/2 the pie would be taken out of the pie pan and placed on the plate, leaving 1/2 remaining in the pan. What ever is left in the pan after the pie is divided represents the remainder.

So next comes the idea that no one wants any pie. No pie will be removed from the pie pan and put onto 0 plates. The answer to 1 pie divided for zero servings is 0 servings with 1 whole pie remaining, thus 1/0 = 0 remainder 1. This applies to 2 pies, three pie and even x number of pies divided into 0 servings.

The debatable point to this pattern of x/0 = 0 remainder x, is that of the infamous 0/0. 0*0 = 0 therefore 0/0 = 0, but x/x = 1 therefore 0/0=1. Is one right, is neither right, or are both right? The rules of math must evenly apply to all aspects of math, ultimately, without exception. This then says that the rules of multiplication and division must be followed, and the statement x/x = 1 is a pattern, not a rule. This ultimately tells us that 0/0 = 0 remainder 0, and that x/x is an inverse impulse function. It is 1, everywhere except x=0.

But what does that remainder do for math? Well, let's look at another principle of math:

2/4 = 1/(4/2)

This is provable. I'm using easily divisible numbers so the proof to follow doesn't get huge:
2/4 = 1/4 = 0.5

1/(4/2) = 1/(2/1) = 1/2 = 0.5

so what about 0/1?
0/1 = 1/(1/0) = 1/(0 remainder 1) = 0

This tells us that the remainder is meaningless. Perhaps this falls into the realm of imaginary numbers, or something very much like it.

So, if x/0 is now defined, then 0^x is defined for all x's, even negatives:
0^1 = 1 * 0 = 1*0 = 0
0^0 = 1 = 1 = 1
0^-1= 1 * 1/0 = 1*(0+1/0) = 0
0^-2= 1 * 1/(0*0) = 1*(0+1/0) = 0
0^-3= 1 * 1/(0*0*0) = 1*(0+1/0) = 0

Monday, August 17, 2009

The foundations of math or "Bunches of something different than nothing"

I'm taking a quick detour to explore the foundations of math. It seems that there is something that isn't settling right, and I have to make sure I understand it before I go on.

I'll just tell you this came from 0^0 debate. Is it 0, 1, undefined, indefinite, or what?

So I started to work through what exponents are. Seems easy enough; exponentiation is the multiplication of multiplication. So:

2^3 = 2 * 2 * 2 = (2 * 2) * 2 = 8

To sum it up better, x^y says multiply x against itself y times. Like in the example, you multiplied two against two and then again against two.

OK, but then what does multiplication mean? Well, multiplication is short hand notation for adding a number to itself so many times, right?

2 * 3 = 2 + 2 + 2 = 6

so we can expand our exponent example (above) to be:

2^3 = 2 * 2 * 2 = (2 * 2) * 2 = (2 + 2) + (2 + 2) = 8

Wow, That's so neat. But what is addition?


Um, OK, that's a little harder to explain. It's like making something more than it was, right?

2 + 2 = 4

So 4 is 2 more that 2. But 2 is pretty abstract. What is 2? Well, 2 is 2. This is why they teach kindergartners about apples. :(

But using apples, we can say that 2 apples is 2 more than no apples. That would insinuate that 1 apple is 1 more than no apples and no apples is just no apples. So, numbers, such as 2, are the change from nothing. (i.e. there was nothing and now there is 2 is more than nothing)

Now, what about -1 apples? Well, then that would mean you have less than nothing or a hole has formed in the universe and made a trans dimensional/temporal crack and the whole thing is going to collapse in on itself!


Or, it means that 0 isn't always really nothing. Maybe 0 can just be the status quo, and when there isn't anything to relate the status quo to, them 0 is actually nothing. So I guess that would mean that numbers are a change from 0, which is a change from the status quo, which may be nothing.

That would define numbers to have the following format:


That says 2 more than nothing and:

0+2 -1 = 0+1

says 2 more than nothing is the status quo, and there is 1 less than that.

Seems like boring stuff, but really, this is going some place. There is a raging debate about what 0^0 means, and if I want to know what the answer is, we have to understand the very fundamentals of math.

So now we have a good understanding of numbers, and numbers them selves are addition, as we saw in the last example. Next on the list is to understand multiplication:

2*2 = (0+2) * 2 = (0+2) + (0+2) = 4

What does that mean? The parenthesis makes them look like groups, kinda like what we learned in kindergarten. 2 apples and 2 more apples is a total of 4 apples. So that's saying 1 group of 2 apples was combined with another group of 2 apples to make 4 apples. so the multiplier is really just saying how many groups of the same size/content we have. Like this:

2*2 + 3*2 = (0+2) * 2 + (0+3) * 2 = (0+2) + (0+2) + (0+3) + (0+3) = 10

Imagine if that were 2 groups of 2 apples and 2 groups of 3 sticks. Well, you would have 10 things, but you would still have 4 apples and 6 sticks, so we have to group things that are the same, and bunched the same way. This leads to a new form for numbers:


which says "There is 1 group of 2 things". Addition works on changing the contents of a group, and multiplication works on grouping groups.

So let's look at the special cases:

1*(0+0) = 1 bunch of nothing:
How can you have a bunch of nothing? Let's do an experiment. Actually go and get me 1 bunch of apples that have no apples more than nothing in them. You can't, but conceptually, you brain is capable of conjuring into existence a bunch of something that has nothing in it. Your brain is capable of storing part of a fact and waiting for the rest to be filled in, and this skill has granted us the ability to abstract nothing into something.

Example: If I tell you you have a bunch of apples, you brain might draw up the mental image of a wicker basket full of apples. Now, when I tell you your bunch of apples has no apples in it, your brain suddenly empties the basket and you can see to the bottom of the basket. Your brain still holds onto the basket as the symbol for the bunch of apples that doesn't exist.

1*(0+1) = 1 bunches of 1 more than nothing:
One bunch of a thing is easy to physically manifest. You have 1 bunches of 1 more than 0 keyboards connected to your computer. That makes sense; you have 1 thing that actually exists as a single group.

0*(0+0) = 0 bunches of nothing:
This is also pretty easy; You have no groups of nothing. It simply doesn't exist in any fashion.

0*(0+1) = 0 bunches of 1 more than nothing:
This a bit odder again. Let's play that little mental game like we did before. So, I tell you to group the apples into groups of 1 (set them by themselves), but then I tell you there are zero groups. Well, how can you group nothing together? It's like the first special case. Your brain can abstract the idea, but it would be an impossible task to actually do.

So what do we do from here? Do we let our brains play these games, or do we stick to what we can physically accomplish? We could call these odd ball cases undefined, but the math community has decided to accept them as equal to nothing, making the answer to 3 out of the 4 cases 0. But that's OK, because it seems reasonable. 0 groups of any size still means the group never existed, which means there is nothing.

Additionally, multiple groups of nothing makes some sense. If I have nothing and you have nothing, then there are 2 nothings, right? That would make 2 bunches of nothing, and nothing is nothing more than nothing.

So what about exponential and 0^0?

2^3 = 2*(2*(0+2)) = 1*(1*(0+2) + 1*(0+2)) + 1*(1*(0+2) + 1*(0+2)) = 1*(1*(0+2) + 1*(0+2) + 1*(0+2) + 1*(0+2)) = 8

(I have to admit. I'm getting tired, so the writing may not be as good).

This is saying to do a lot of adding. Take a bunch of 2 more than nothing and double it, and then double it again. As the equation was expanded, parenthesis were added to show grouping.

Now imagine 1^3, That says you have 1 group of 1 bunch of 1 more than 0. How about 0^3? That says you have 0 groups of 0 groups of nothing more than nothing.

So here comes the million dollar question: What about 0^0? That would say, following the convention that multiplication is compounded addition and exponents are compounded multiplications, I don't know what to say here.

As far as this would suggest, 0^0 is simply 0, but we will keep exploring...

Friday, August 14, 2009


As promised, I have returned to reveal the mystical secrets of the math universe. Yes, step right up, step right up!

So, now that we have the FLOOR(x) function, now we are going to build on that to create the CEIL(x) function.

FLOOR(x) = x- (arccos(cos(x*2pi))/2pi)*IS_POS - (1-arccos(cos(x*2pi))/2pi)*(NOT(IS_POS))

IS_POS was our switch function that equaled 1 when sin(x*2pi) was positive or 0. Using the fact that 0^0 = 1 and 0^(any other positive number) = 0, it went like this:
IS_POS = 0^abs(sin(x*2pi)-abs(sin(x*2pi)))

And the NOT(x) function there could be implemented a few ways. In the floor function post, I again used the properies of 0 raised to flip the IS_POS switch like this:

IS_POS = 1
0^abs(IS_POS) = 0^1 = 0

IS_POS = 0
0^abs(IS_POS) = 0^0 = 1

Perdy neat!

But this time, and for no real particular reason except to be explorative, we'll redefine the NOT(x) function.

Using the constraint of IS_POS (it can only be 0 or 1), we can make the function:

IS_POS = 1
NOT(IS_POS) = 1 - IS_POS1 = 1-1 = 0

IS_POS = 0
NOT(IS_POS) = 1 - IS_POS1 = 1-0 = 1

This is an old computer programming trick.

Anyway, back from the tangent to the task at hand; Developing a working CEIL(x) function! I just wanted to get everybody back on the same page.

So looking at FLOOR(x) again:
FLOOR(x) = x- (arccos(cos(x*2pi))/2pi)*IS_POS - (1-arccos(cos(x*2pi))/2pi)*(NOT(IS_POS))

we have these switches on two very similar looking chunks of the equations-


Well, the first is "active" (multiplied by 1) when the IS_POS function is true and "deactivated" (multiplied by 0) when the IS_POS function is returning 0. Conversely the second is activated and deactivated oppositely, thanks to the NOT(x) function.

The reason for this is (explained by the following exaples of flooring 3.r were r is the decimal or fractional part of the number):
arccos(cos(3.00*2pi))/2pi = 0.00
arccos(cos(3.25*2pi))/2pi = 0.25
arccos(cos(3.50*2pi))/2pi = 0.50

so our neat little equation there returns just the fractional part of the number for us but, because the cos function is cyclical, after 3.5 up to 4.0, the result reverses:
arccos(cos(3.60*2pi))/2pi = 0.40, but +1-0.40 = 0.60
arccos(cos(3.75*2pi))/2pi = 0.25, but +1-0.25 = 0.75
arccos(cos(3.90*2pi))/2p) = 0.10, but +1-0.10 = 0.90

So, you see, for 3.0 to 3.5, we want to just straight subtract off the result, but once we are past 3.5 but less than 4 (when the IS_POS is false), we need to subtract off the difference between 1 to make the floor function work.

Ok, so we are all caught up on how it works, so let's use these blocks to make the CEIL function!

CEIL(x) = x+what?

Well, let's see what CEIL(x) should return (using 3.r again):
CEIL(3.00) = 3.00
CEIL(3.25) = 4.00
CEIL(3.50) = 4.00
CEIL(3.75) = 4.00
CEIL(4.00) = 4.00

So now, we need to add, but let's lookj at what we need to add:
CEIL(3.00) = 3.00, add 0.00
CEIL(3.25) = 4.00, add 0.75
CEIL(3.50) = 4.00, add 0.50
CEIL(3.75) = 4.00, add 0.25
CEIL(4.00) = 4.00, add 0.00

Well, it looks like we are adding 1-r (remember that r was the fractional part) so:
CEIL(x) = x+(1-(arccos(cos(x*2pi))/2pi))

Let's test it and make sure:
CEIL(3.25) = 3.25+(1-(arccos(cos(3.25*2pi))/2pi)) = 3.25+0.75 = 4.0, Good
CEIL(3.50) = 3.50+(1-(arccos(cos(3.50*2pi))/2pi)) = 3.50+0.50 = 4.0, Good
CEIL(3.75) = 3.75+(1-(arccos(cos(3.75*2pi))/2pi)) = 3.75+0.75 = 4.5, oops!
CEIL(4.00) = 4.00+(1-(arccos(cos(5.00*2pi))/2pi)) = 4.00+1.00 = 5.0, oops!

So what went wrong? Well, 2 things:
1) Integers (like 3.0 and 4.0) should stay as they are, not have 1 added to them
2) In the CEIL(3.75) example, the old cos function being cyclical thing got us again.

so, for 3.5 to 4.0 and on the integers(3.00 and 4.00 for example) we want to add just the fractional part, not the 1-fractional. This is very much the opposite of what we were seing before. Ofcourse that makes sence in that the FLOOR(x) and the CEIL(x) are opposites.
So let's go crazy and create an IS_NEG function that is equal to 1 when sin(x*2pi) is negative or 0!

IS_NEG = 0^abs(-sin(x*2pi)-abs(sin(x*2pi)))

What's the difference from IS_POS? I multiplied the first sin * -1. Now, if sin(x*2pi) is positive, then it becomes a negative and then subtracting off the abs value will not be 0, and because 0 raised to anything but 0 equals 0, IS_NEG will be False ( or 0).

This means that IS_NEG will equal 1 when sin(x*2pi) equals 0 or is negative. Perfect.

So let's work the rest of the peices out:

CEIL(x) = x+ (arccos(cos(x*2pi))/2pi)*IS_NEG + (1-arccos(cos(x*2pi))/2pi)*(NOT(IS_NEG))

And there we go. A working CEIL(x) function.

Wednesday, August 12, 2009

FLOOR(X) - And so the saga continues...

So, the ultimate answer to the ultimate question of life, the universe and everything is...

Oops, wrong story.

But in the last episode, I was looking for a signal that would tell me if I was greater that half way around the circle, so I could signal the arccos function to keep increasing, and that answer is sin.

Sin, being the y axis vector, is positive while traversing the circle's circumference counterclockwise for half the journey, and then becomes negative. That is exactly the indicator I need, but how can i make it work for me?

Well, there is an odd, and little known, fact about exponents, that goes something like this:

x^0=1 (any number raised to the 0th power is 1)
0^x = 0 (0 raised to any power is zero)

putting these two equations at conflict. To solve this, it was determined that exponents actually take the form:

that says, recursively, start with 1, and then multiply x to it, y times. Here's an example:

5^3 = 1 * 5 *5 * 5 = 125
5^2 = 1 * 5 * 5 = 25
5^1 = 1 * 5 = 5
5^0 = 1

or for 0:

0^3 = 1 * 0 * 0 * 0 = 0
0^2 = 1 * 0 * 0 = 0
0^1 = 1 * 0 = 0
0^0 = 1

Very interesting, but more importantly, this acts like a built in mathematical switch! In order to use this switch, we write an equation for the power applied to 0, and we know that the total result will be 0, until the equation is equal to 0, thus making 0^0 = 1.

Let me use an example to clarify:

Say I revisited my original goal to find an equation that would indicate if a number is an integer or not:

Well, thinking about the trig functions and the unit circle,

sin(n*pi) = 0

n representing only integers. Non integers will return a number other than 0. Again, an example to clarify:

sin( 0.0 * pi) = 0
sin( 0.5 * pi) = 1
sin( 1.0 * pi) = 0
sin( 1.5 * pi) = -1
sin( 2.0 * pi) = 0

this seems to meet our conditions for this switch. We wanted 0^0 only when there is an integer, so a true integer detection equation would be:


well, almost. You can't have a negative power (remember, roots are fractional powers, not negative) with 0^x or you would get div-by-zero, so an easy solution to this is the absolute value function, which basically removes the negative sign from all negative numbers. So, we really need:



So you get the jist of how this switch thingy-ma-bobber works, right? So back to the FLOOR(X) function. I currently have:

FLOOR(x) = x - (arccos(cos(2pi*x))/(2pi))

which works as long as the fractional part of x is 1/2 or less. So, using my switch and knowing the sin funxtion becomes negative when the fractional part of x is greater that 1/2, i can use a switch like:


to tell me if sin(x*2pi) >= 0.

This works because:

arccos(cos(3.2*2pi))/2pi = 0.2 which requires us to subtract this result from the 3.2 to floor it.
arccos(cos(3.5*2pi))/2pi = 0.5 which requires us to subtract this result from the 3.5 to floor it.


arccos(cos(3.6*2pi))/2pi = 0.4
arccos(cos(3.7*2pi))/2pi = 0.3
arccos(cos(3.8*2pi))/2pi = 0.2
arccos(cos(3.9*2pi))/2pi = 0.1

we now have to subtract 1-this result from the number we entered to floor it:

1-arccos(cos(3.6*2pi))/2pi = 0.6 and 3.6 - 0.6 = 3
1-arccos(cos(3.7*2pi))/2pi = 0.7 and 3.7 - 0.7 = 3
1-arccos(cos(3.8*2pi))/2pi = 0.8 and 3.8 - 0.8 = 3
1-arccos(cos(3.9*2pi))/2pi = 0.9 and 3.9 - 0.9 = 3

This new development is why we need the mathematical switch; without it, we have a piecewise function that isn't subject to all of the normal algebreaic motions. We can't reduce in a more complex equation, or apply commutative properties, etc. With the switch in place, however, it's game on.

So now we need the switch implimented:

x-arccos(cos(x*2pi))/2pi or x+1-arccos(cos(x*2pi))/2pi

to make it readable, I'm going to substitute the label IS_POS for the switch:

IS_POS = 0^abs(sin(x*2pi)-abs(sin(x*2pi)))

so we getsomething roughly like:

x- (arccos(cos(x*2pi))/2pi)*IS_POS - (1-arccos(cos(x*2pi))/2pi)*(NOT(IS_POS))

Ok, ok. I slipped one in there on ya. The not function basically says if IS_POS is 0, make it a 1, otherwise, make it a 0. Hmm, kinda like a switch...

NOT(a) = 0^abs(a)

so you see, the equation can be written:

x- (arccos(cos(x*2pi))/2pi)*IS_POS - (1-arccos(cos(x*2pi))/2pi)*0^abs(IS_POS)

but NOT is more human readable.

Enough for now, in the next post, I will make the CEIL(x) function work from these same blocks and then later I will write up the various MOD(x,y) functions.


Monday, just before I left work, an old problem that had been swirling around in my head decided to surface. Mal and i worked on the RSA challenges (trying to factor really large numbers that are the product of two primes).

So, we found tons of solutions that would get us the answers quickly if we could put our equations into a non-recursive form. Unfortunately, they all used modulo or floor functions, which are conceptual, piecewise functions.

So, back to Monday; As I was packing up to go home, the thought that had occurred to me several times came to the front of my brain again, Integers are periodic. Numbers can be represented in many ways, but fractions make this Integers very clear.

Here is an example:
1.333333333333333(...) is a hard number to write. It could literally take for ever to write it out completely without using fractions. As a fraction though:

1+1/3 is all you need.

so I can talk about parts of it, I will use the following generic format for fractions:


q is the "whole" number or the biggest possible number than n/d will allow
n is the numerator and has only the left overs (or remainder)
d is the denominator

What I mean by all of that is, say you had:


Then you are not really in the right form. You would want to simplify the (n/d) or fractional part as much as possible:


Is the best answer. But I do digress to my real point, that integers are periodic, or, as the thought actually came to me, cyclical. Integers are special numbers whose fractional part (n/d) is equal to 0.

If integers are cyclical, and the only mathematically cyclical thing I know of is trig functions (specifically sin and cos functions), then maybe I can use them.

I thought, I need to write an equation that is true only when I have hit some point on the unit circle, as i traverse the circumference. So I started looking at the circle and noticed the same thing probably a billion other people have, cos starts at 1 and goes to -1. There had to be something there, so i dropped my victim number into the cos function (with 2pi) and that didn't help me to much.

What did help me was remembering that the cos function always returned a number 1 to -1, no matter how many times you went around the circle. It, in effect, chopped of the whole number (the "q" in my form above) and left a wierd number, that was consistent base on my fractional part, but didn't directly match or seem to directly correlate.

Well, duh! cos is the x axis vector for where you are on the circumference of the unit circle. drop that result back into arccos and it should return how far around the circle my fractional part has taken me.

For instance:

cos(2pi*3.25) = 0
arccos(0) = pi/2

Well, that's not exactly returning just the fractional part of 3.25 (3+1/4) or the 0.25 (0+1.4), but that's because it's scaled by 2pi!

(pi/2)/(2pi) = 0.25

So, now, what if I take my 3.25 - (arccos(cos(2pi*3.25))/(2pi))?

3.25 - (arccos(cos(2pi*3.25))/(2pi)) = 3

Good stuff. I'm well on my way to being able for the equation to tell me if it is an integer or... Wait a second. Didn't that just separate the fractional part from the whole part? Did I just FLOOR that with a real equation? Friggin' wholly grails!

Upon testing there turns out to be a problem though. It works, returning q from q+(0/2) to q+(1/2), but then it sudenly breaks and ramps with a slope of 2 from ther on up to q+(2/2) (or q+1).

Now the problem with this solution emerges. cos is cyclical and get's to -1 half way around the circle, but then starts increasing back towards 1 there after. The arccos function can't tell the difference between the the -0.9 just before we get half way around the circle or just after. The slope of 2 is due to the fact that the rate in change in the number we are testing (3.4, 3.5, 3.6, 3.7, etc) is the same rate of change that is coming out of the arccos function, thusly doubling.

I'm sure I'm rambling and not making a ton of sense, but the important thing that occured to me was that, if I had some sort of indicator that I could use to tell the arccos function to just keep going up, it would work.

Now a few hours after I should have left work, I had developed some imperfect solutions, but the answer was in my grasp.

And with that I leave you with the thrilling cliffhanger of how I developed working equations of the FLOOR(x), CEIL(x), MOD(x,n) functions and much, much more! Untill next time, be sure to drink your Ovaltine!