CoreyWhite@gmail.com wrote:
[color=blue]
> I asked the question, "how do you define arithmetic?", and when I came
> to an answer I understood math in a new, much clearer way. I also
> happened upon a method of arithmetic optimization that really speeds up
> calculations on computers.
>
> If you wanted to define mathematics I would first define addition. The
> simplest way to define addition is to create a function for every
> number and say f_n(x)=x+n , where n is the number you are preforming
> addition on and x is the modifying value. The problem with this is it
> uses addition to define itself, so I decided to write it longhand:
>
> f_1(x) = if x==1 then y=2 , if x==2 then y=3, if x==3 then y=4...
> f_2(x) = if x==1 then y=3 , if x==2 then y=4, if x==3 then y=5...
> f_3(x) = if x==1 then y=4 , if x==2 then y=5, if x==3 then y=6...
> ...
>
> You could do this for every number you wished to use and define the
> scope of the numers you wished to work with. I of course have not
> created a table that goes up to infinity or one that can use infinite
> decimal places. If I need to I will just create new functions that
> work with larger numbers and more decimal places.
>
> What I found in terms of computer programming, is that when I manually
> assign values to variables I don't need to use the operators to do
> arithmetic. What I like about doing it this way is it is faster.
>
> This C++ program is an example of this kind of optimization. The lines
> commented out preform the exact same function as the lines which
> preform arithmetic on the variables, but the commented lines are much
> faster.
>
> Do you think we could optimize computer architecture to take advantage
> of this?
> Any feedback on this theory is welcome
>
> #include <cstdlib>
> #include <iostream>
> #include <ctime>
>
> using namespace std;
>
> int main(int argc, char *argv[])
> {
>
> time_t t1, t0;
> double elapsed;
>
> time(&t0); /* start time */
> for(int cnt=0; cnt<1000000000; cnt++){
> int x=0;
> int y=577;
> x=x+y;
> y=x+y;
> //if(x==0 && y==577) x=577;
> //if(x==577 && y==577) y=1154;
>
> }
> time(&t1);
> elapsed = difftime(t1, t0);
> cout<<elapsed;
> system("PAUSE");
> return EXIT_SUCCESS;
>
> }[/color]
Sounds bogus to me. Here are two routines:
typedef unsigned char u_char;
inline
u_char sum ( u_char a, u_char b ) {
if ( a == 0 && b == 0 ) return 0;
if ( a == 0 && b == 1 ) return 1;
if ( a == 0 && b == 2 ) return 2;
if ( a == 0 && b == 3 ) return 3;
if ( a == 0 && b == 4 ) return 4;
if ( a == 0 && b == 5 ) return 5;
if ( a == 0 && b == 6 ) return 6;
if ( a == 0 && b == 7 ) return 7;
if ( a == 1 && b == 0 ) return 1;
if ( a == 1 && b == 1 ) return 2;
if ( a == 1 && b == 2 ) return 3;
if ( a == 1 && b == 3 ) return 4;
if ( a == 1 && b == 4 ) return 5;
if ( a == 1 && b == 5 ) return 6;
if ( a == 1 && b == 6 ) return 7;
if ( a == 1 && b == 7 ) return 8;
if ( a == 2 && b == 0 ) return 2;
if ( a == 2 && b == 1 ) return 3;
if ( a == 2 && b == 2 ) return 4;
if ( a == 2 && b == 3 ) return 5;
if ( a == 2 && b == 4 ) return 6;
if ( a == 2 && b == 5 ) return 7;
if ( a == 2 && b == 6 ) return 8;
if ( a == 2 && b == 7 ) return 9;
if ( a == 3 && b == 0 ) return 3;
if ( a == 3 && b == 1 ) return 4;
if ( a == 3 && b == 2 ) return 5;
if ( a == 3 && b == 3 ) return 6;
if ( a == 3 && b == 4 ) return 7;
if ( a == 3 && b == 5 ) return 8;
if ( a == 3 && b == 6 ) return 9;
if ( a == 3 && b == 7 ) return 10;
if ( a == 4 && b == 0 ) return 4;
if ( a == 4 && b == 1 ) return 5;
if ( a == 4 && b == 2 ) return 6;
if ( a == 4 && b == 3 ) return 7;
if ( a == 4 && b == 4 ) return 8;
if ( a == 4 && b == 5 ) return 9 ;
if ( a == 4 && b == 6 ) return 10;
if ( a == 4 && b == 7 ) return 11;
return 0;
}
inline
u_char sum1 ( u_char a, u_char b ) {
return( a + b );
}
Would you expect sum1 to be faster? You are right that it does not add,
however it performs quite a few tests, which also cost time.
Best
Kai-Uwe Bux