quinta-feira, março 29, 2007

DynDNS

the fortune teller forecasts :
Your mode of life will be changed to ASCII.


helga.homelinux.com up and running hihihi hurray to ssh!! God I'm loving this semester. And my group is all curious and intelligent people, that actually want to explore things. I'm in wonderland. ;)

Maibe I find time these vacations to configure APACHE ;) then I'll post a link to my web page lol

Keep loving linux ;)


Dynamic DNSSM

Actions

*

Create Hosts
*

Manage Hosts

The free Dynamic DNS service allows you to alias a dynamic IP address to a static hostname in any of the many domains we offer, allowing your computer to be more easily accessed from various locations on the Internet. We provide this service, for up to five (5) hostnames, free to the Internet community.

The Dynamic DNS service is ideal for a home website, file server, or just to keep a pointer back to your home PC so you can access those important documents while you're at work. Using one of the available third-party update clients you can keep your hostname always pointing to your IP address, no matter how often your ISP changes it. No more fumbling to find that piece of paper where you wrote down your IP address, or e-mailing all your friends every time it changes. Just tell them to visit yourname.dyndns.org instead!

http://www.dyndns.com/services/dns/dyndns/
http://ddclient.sourceforge.net/

segunda-feira, março 26, 2007

My god!! I just smoked the peace pipe with pointers!!

Few things in life (right now lol) bring me more pleasure then saving a line of code, or a variable. And a pointer does just that! Because it's a variable and an iterator all in one! ;) Well sort of, you can use it both ways.

As an iterator, because it's really a memory index so... if you increase it you go to the next memory index, same if you decrease it , or add a given quantity to it etc. (search for pointer arithmetic) Great to arrays!!

And as a variable, because using the operator * you can access whatever the pointer points to.


Anyway, the hole reason for my excitement is not in pointers. It's I've been looking arround for a magical function that would transform an integer to a char array,but I couldn't find the code!! So I made one :P After stretching my brain a while I came up with this.

char * itc(char *d, int n){ /*int to char binary*/
    char *init;
    int i;
    init = d;
     for(i=sizeof(int)*8 -1; i>=0; i-- , d++ )
       *d= ((n>>i)&1 ) + '0';

    *d='\0';
    return init;
}


itc receives a pointer to a char array (one assumes big enough!! Easy peasy say you declare it like : char myLovelyCharArray[sizeof(int)*8]; Remenber: 1 byte == 8 bits) :P

We need to return the beginning of the string so we save it in init.

Then the brilliant Idea is to go bit by bit. But, but ohh my god! How am I gonna do that? int is bytes in memory but how am I going to access that? [that was my reaction when it stroke me anyway]. So then I reminded the bitwise operator. But never really got how to use it and Ritchie wasn't much of a help because the example was way to complicated for strike one :P so I experimented a little till I finally got it.

Do you have your boolean algebra up to date?
say 6 => 011 0
now shift right is an interesting concept if one considers it this way : what's the value of bit in position 1 ? Meaning if I divide 6 by 2^1 what do I get? 2=11 = 0011 .
Here's a visual example:

shift    (0110)>>nBits)&1

0110>>0 => 0
0110>>1 => 1
0110>>2 => 1
0110>>3 => 0

So our task becomes as simple as to translate this int value in to correspondent char. So we take advantage of the ASCII code ;) and just add the shift to it. If zero then = '0' otherwise = '0' +1; meaning 48 or 49. (6) ohh lovely. :P

sábado, março 24, 2007

Linux!! Linux!! linux!!

The goods make the bads worthwhile.

System up!! ;)

Has promised first time hole went for the system. Ended up breaking my pride and formating the system partition... 'cause actually it was the only thing I had to lose.
My strategy of moving all non system files, and some configuration files to a different partition worked like a charm. Saved me days of Google searching, and naturally all of my "sensitive data".
Still took me a couple of hours to get things my way, which tells me the next step is to do a script to do all this for me every time I format the disk. But that's a little more complicated than it seems 'cause there are versions, and kernel stuff to take care of for it to be perfect.
And... that would be a little out of reach for me at the moment.

Still, I'm rather pleased today ;)

sexta-feira, março 23, 2007

Rainlendar

Great utility. Perfect for all organization freaks around the world and for busy folks with bad "event memory" like my self. :P



Great layout. Pretty easy to install && use. Available for Linux and windows OS.

love it!! love it!! love it!!

segunda-feira, março 19, 2007

domingo, março 11, 2007

break;

NewH(){
    while(energy())
      if(dayofweek==weekend)
         break;
      else
         bangHead();

    reset();
    NewH();
}

É fim de semana. Parece-me legitimo fazer uma pausa :P


será que um dia vou acabar assim?


just reminded someone I shouldn't. Must go running back to hide inside C.

segunda-feira, março 05, 2007

Yet another C experiment

My weekend flew in between trains and a weeding. Got home with an incremented flue and a huge head ache. Fortunately a few ours Zombie[ing] where enough to get me back on track.

Thought I'd share this with ya just because I'm amazed at how much mental effort can be in three lines of code . The exercise was:

/* write the function any(s1,s2), which return the first location in the string s1 where any character from the string s2 occurs, or -1 if s1 contains no characters from s2. (The standard library function strpbrk does the same job but returns a pointer to the location)*/

now what most students would write should be something like
int any(char[] s1, char s2[]) {
for(i=0; s1[i]!='\0'; ++i)
for(int j=0; s2[j]!='\0';++j)
if(s1[i]==s2[j])
return i;

return -1;
}

direct reasoning:
go through firstString, if any char in string 2 == current char in string 1 ,return this index.
If no index is found return -1.

and that's what I wrote at frist. Two hours later at 3 am I had 3 lines of code less.

int any(char s1[], char s2[]){
int i, j;

for(i=j=0; s1[i]!='\0' && s1[i-1]!=s2[j]; ++i)
for(j=0; s1[i]!=s2[j] && s2[j]!='\0'; ++j)
;

return s1[i-1]==s2[j] ? i-1 : -1;
}

indirect resoning:
go trough first string only while there are chars in the firstSTring and the last one in frist string is different from the current in second string. This is important because the second cicle interropts if it finds an equal char in the second string and when it returns to test s1, it must stop all cicles.

Finally if last index was an equal char, return it. Else return -1; meaning no equal chars where found.


Deception comes with a much simpler code from standard library... as expected
you can find it together with your sources at:
~/glibc-build/sysdeps/generic/strpbrk.c

strpbrk (s, accept)
const char *s;
const char *accept;
{
while (*s != '\0')
{
const char *a = accept;
while (*a != '\0')
if (*a++ == *s)
return (char *) s;
++s;
}

return NULL;
}


This code uses pointers. In fact originally, as stated before: it returns one!
Pointers are the next curve on my so green C path. I'm hopping to be able to explain this one this afternoon. hihihi
It's been fun so far. Let's hope practice makes perfect. ;)

Better than Valium... try it out.

sábado, março 03, 2007

Who framed calculus?

It's 3 Am and I can't sleep... thought I'd do something useful like sharing with you guys this book I just found “Foundations of Differential Calculus” by Euler L. [on good old 1755 ] Translated by: John D. Blanton


can you tell why the hell do you write d/dx , do you know what a diferential is? well... read mister Euler.. never read or heard a better explanation quite honestly. The reasoning that leads to it is so simple it's quite frightening, mostly because no one ever mentioned it out loud in classes before.


Let's go smell the preface:

“What differential calculus, and, in general, analysis of the infinite, might be can hardly be explained to those innocent of any knowledge of it. Nor can we here offer a definition at the beginning of this dissertations as is sometimes done in other disciplines. It is not that there is no clear definition of this calculus; rather, the fact is that in order to understand the definition there are concepts that must first be understood. Besides those ideas in a common usage, there are also other from finite analysis that are much less common and are usually explained in the course of the development of the differential calculus. For this reason, it is not possible to understand a definition before it's principles are sufficiently clearly seen.

In the first place this calculus is concerned with variable quantities. Although every quantity can naturally be increased or decreased without limit, still, since calculus is directed to a certain purpose, we think some quantities as bring constantly the same magnitude, while others change through all the stages of increasing and decreasing. We note this distinction and call the former constant quantities and the latter variables. This characteristic difference is not required by the nature of things,but rather because of the special question addressed by the calculus.

In order that this difference between constant quantities and variables might be clearly illustrated, let us consider a shot fired from a cannon with a charge of gunpowder; then, the angle of elevation of the cannon above the horizon; third, the distance traveled by the shot; and, fourth, the length of time the shot is in the air. Unless the same cannon is used throughout the experiment, we must also bring in to our calculations the length of the barrel and the weight of the shot. Here, we will not consider variations in the cannon or the shot, lest we become entailed in very complicated questions. Hence, if we always keep the same quantity of powder, the elevation of the barrel will vary continuously with the distance traveled and the shot's duration of time in the air. In this case, the amount of powder, or the force of the explosion, will be the constant quantity. The elevation of the barrel, the distance traveled, and the time in the air should be the variable quantities. If for each degree of elevation we were to define these things, so that they may be noted for future reference, the changes in distance and duration of the flight arise from all of the different elevations. There is another question: Suppose the elevation of the barrel is kept the same, but the quantity of powder is continuously changed. Then the changes that occur in the flight need to be defined. In this case, the elevation will be the constant, while the quantity of powder, the distance, and duration are the variable quantities. Hence, it is clear that when the question is changed, the quantities that are constant and those that are variables need to be noted. At the same time, it must be understood from this that in this business the thing that requires the most attention is how the variable quantities depend on each other. When one variable changes, the others necessarily are changed. For example, in the former case considered, the quantity of powder remains the same, and the elevation is changed; then the distance and duration of the flight are changed. Hence, the distance and duration are variables that depend on the elevation; if this changes, then the others also change at the same time. In the latter case, the distance and duration depend on the quantity of charge of powder, so that a change in the charge must result in certain changes in the other variables.

Those quantities that depend on others in this way, namely, those that undergo a change when others change, are called functions of these quantities. This definition applies rather widely and includes all ways in which one quantity can be determined by others. Hence, if x designates the variable quantity, all other quantities that in any way depend on x are determined by it are called it's functions. Examples are x^2, the square of x, or any other powers of x, and indeed, even quantities that are composed with the powers in any way, even transcendentals, in general, whatever depends on x in such a way that when x increases or decreases, the function changes. From this fact there arises a question; namely, if the quantity x is increased or decreased, by how much is the function changed, whether it increases or decreases? For the more simples cases, this question is easily answered. If the quantity x is increased by the quantity w, it's square x^2 receives an increase of 2xw + x^2. Hence, the increase in x is to the increase of x^2 as w is to 2xw + w^2, that is, as 1 is to 2x + w. In a similar way, we consider the ratio of the increase of x to the increase or decrease that any function of x receives. Indeed, the investigation of this kind of ratio of increments is not only very important, but it is in fact the foundations of the whole of analysis of the infinite. in order that this may become even clearer, let us take up again the example of the square x^2 with its increment of 2xw + w^2, which it receives then x itself is increased by w. We have seen that the ration here is 2x +w to 1. From this it should be perfectly clear that the smaller the increment is taken to be, the closer this ratio comes to the ratio of 2x to 1. However , it does not arrive at this ratio before the increment itself, w, completely vanishes. From this we understand that if the increment of the variable x goes to zero, then the increment of x^2 also vanishes. However, the ratio holds as 2x to 1. What we have said here about the square is to be understood of all other functions of x; that is, when their increments vanish as the increment of x vanishes, they have a certain and determinable ration. In this way, we are led to a definition of differential calculus: It is a method for determining the ratio of the vanishing increments that any function take on when the variable, of which they are functions, is given a vanishing increment. It is clearly manifest to those who are not strangers to this subject that the true character of differential calculus is contained in this definition and can be adequately deduced from it.

Therefore, differential calculus is concerned not so much with vanishing increments, which indeed are nothing, but with the ratio and mutual proportion. Since these ratios are expressed as finite quantities, we must think of calculus as being concerned with finite quantities. Although the values seem to be popularly discussed as defined by these vanishing increments, still from a higher point of view, it is always from their ratio that conclusions are deduced. In a similar way, the idea of integral calculus can most conveniently be defined to be a method fro finding those functions from the knowledge of the ratio of their vanishing increments.

In order that these ratios might be more easily gathered together and represented in calculations, the vanishing increments themselves, although they are really noting, are still usually represented by certain symbols. Along with these symbols, there is no reason not to give them a certain name. Thy are called differentials, and since they are without quantity they are also said to be infinitely small. Hence, by their nature they are to be so interpreted as absolutely nothing, or they are considered to be equal to nothing. Thus, if the quantity x is given an increment w, so that it becomes x+w, its square x^e becomes x^2 + 2x^2w + w^2, and it takes the increment 2xw+w^2. Hence, the increment of x itself, which is w, has the ratio to the increment of the square, which is 2xw + w^2, as 1 to 2x + w. This ratio reduces to 1 to 2x, at least when w vanishes. Let w=0, and the ratio of these vanishing increments, which is the main concern of differential calculus, is a 1 to 2x. On the other hand, this ratio would not be true unless that increment w vanishes and becomes absolutely equal to zero. Hence, if this nothing that is indicated by w refers to the increment of the quantity x, since this has the ratio to the increment of the square x^2 as 1 to 2x, the increment of the square x^2 is equal to 2xw and for this reason is also equal to zero. Although both of these increments vanish simultaneously, this is no obstacle to their ratios being determined as 1 to 2x. With respect to this nothing that so far has been represented by the letter w, in differential calculus we use the symbol dx and call it the differential of x, since it is the increment of the quantity x. When we put dx for w, the differential of x^2 becomes 2x dx. In a similar way, it is shown that the differential of the cube x^3 will be equal to 2x^2 dx. In general, the differential of any quantity x^n will be equal to nx^(n-1) dx. No matter what other functions of x might be proposed, differential calculus gives rules for finding its differential. Nevertheless, we must constantly keep in mind that since these differentials are absolutely nothing, we can conclude nothing from them except that their mutual ratios reduce to finite quantities. This, it is in this way that the principles of differential calculus, which are in agreement with proper reasoning, are established, and all of the objections that are wont to be brought against it crumble spontaneously; but these arguments retain their full rigor if the differentials,that is, the infinitely small, are not completely annihilated.
To many who have discussed the rules of differential calculus, it has seemed that there is a distinction between absolutely nothing and a special order of quantities infinitely small, which do not quite vanish completely but retain a certain quantity that is indeed less than any assignable quantity. Concerning these, it is correctly objected that geometric rigor has been neglected. Because these infinitely small quantities have been neglected, the conclusions that have been drawn are rightly suspected. Although these infinitely small quantities are conceived to be few in number, when a few, or many, or even an innumerable number of these are neglected, an enormous error may result. There is an attempt wrongfully to refute this objection with examples of this kind, whereby conclusions are drawn from differential calculus in the same way as from elementary geometry. Indeed, if these infinitely small quantities, which are neglected in calculus, are not quite nothing, then necessarily an error must result that will be greater the more these quantities are heaped up. If it should happen that the error is less, this must be attributed to a fault in the calculation whereby certain error are compensated by other errors, rather then freeing the calculation from suspicion of error. In order that there be no compensating one error by a new one, let me fix firmly the point I want to make with clear examples. Those quantities that shall be neglected must surely be held to be absolutely nothing. Nor can the infinitely small that is discussed in differential calculus differ in any way from nothing. Even less should this business be ended when the infinitely small is described by some with the example wherein tiniest mote of dust is compared to a huge mountain or even the whole terrestrial globe. If someone undertakes to calculate the magnitude of the whole terrestrial globe, it is the custom easily to grant hum an error of a single grain of dust, but even many thousands of these. However, geometric rigor shrinks from even so small an error, and this objection would be simply to great were any force granted to it. Then it is difficult to say what possible advantage might be hoped for in distinguishing the infinitely small from absolutely nothing. Perhaps they fear the if they vanish completely, then will be taken away their ratio, to which they feel this whole business leads. It is avowed that it is impossible to conceive how two absolutely nothings can be compared. They think that some magnitude must be left for them that can be compared. They are forced to admit that this magnitude is so small that it is seen as it it were nothing and can be neglected in calculations without error. Neither do they dare to assign any certain and definite magnitude, even though incomprehensibly small. Even if they where assumed to be two or thee times smaller, the comparisons are always made in the same way. From this it is clear that this magnitude gives nothing necessary for undertaking a comparison, and so the comparison is not taken away even though that magnitude vanishes completely.

Now from what has been said above, it is clear that comparison, which is the concern of differential calculus, would not be valid unless the increments vanish completely. The increment of the quantity x, which we have been symbolizing by w, has a ration to the increment of the square x^2 which is 2xw + w^2, as 1 to 2x +w. But this always differs from the ratio of 1 to 2x unless w=0, and if we do require that w=0, then we can truly say that this ratio is exactly as 1 to 2x. In the meantime, it must be understood that the smaller the increment w becomes, the closer this ratio is approached. It follows that not only is it valid, but quite natural, that these increments be at first considered to be finite and even in drawings, if it necessary to give illustrations, that they be finitely represented. However, then these increments must be conceived to become continuously smaller, and in this way, their ratio is represented as continuously approaching a certain limit, which is, as it were, the final ratio of those increments, is the true object of differential calculus. Hence, this ration must be considered to have laid the very foundation of differential calculus for anyone who has a mind to contemplate these final ratios to which the increments of the variable quantities, as they continuous are more diminished, approach and at which they finally arrive. ”

We find among some ancient authors some trace of these ideas, so that we cannot deny to them at least some conception of the analysis of the infinite. Then gradually this knowledge grew, but it was not all of a sudden that it has arrived at the summit to which it has now come. Even now, there is more that remains obscure than what we see clearly. As differential calculus is extended to all kinds of functions, no matter how they are produced, it is not immediately know what method is to be used to compare the vanishing increments of absolutely all kinds of functions. For example, for the rational functions, the ultimate ration that the vanishing increments attain could be assigned along before the time of Newton and Leibniz, so that the differential calculus applied to only these rational functions must be held to have been invented long before that time. However, there is no doubt that Newton must be given credit for that part of differential calculus concerned with irrational functions. This was nicely deduced from his wonderful theorem concerning the general evolution of powers of a binomial. By this outstanding discovery, the limits of differential calculus have been marvelously extended. We are no less indebted to Leibniz insofar as this calculus at that time was viewed as individual tricks, while he put it into the form of a discipline, collected its rules into a system, and gave a crystal-clear explanation. From this there followed great aids in the further development of this calculus, and some of the open questions whose answers were sought were pursued through certain definite principles. Soon, through the studies of both Leibniz and Bernoulli's, the bounds of differential calculus were extended even to transcendental functions, which had in part already been discussed. Then, too, the foundations of integral calculus were firmly established. Those who followed in the elaboration of this field continued to make progress. ............................................................... blá blá history of calculus..................
No matter what name the mathematicians of different nations are wont to give to this calculus, it all comes to this, that they all agree on this outstanding definition. Whether they call the vanishing increments whose ratios are under consideration by the name differentials or fluxions, these are always understood to be equal to zero, and this must be the true notion of the infinitely small. From this it follows that everything that has been debated about differentials of the second and higher orders, and this has been more out of curiosity then usefulness, comes back to something very clear, namely, that when everything vanishes together we must consider the mutual ratio rather than the individual quantities. Since the ratio between the vanishing increments of the functions is itself expressed by some function, and if the vanishing increment of this function is compared with others, the result must be considered as the second differential. In this way, we must understand the development of differentials of higher order in such a way that they always are seen to be truly finite quantities and that this is the only proper way for them to be represented. At first sight, this description of analysis of the infinite may seem, for the most part, both shallow and extremely sterile, although that obscure notion of the infinitely small hardly offers more. In truth, if the rations that connect the vanishing increments of any functions are clearly know, then this knowledge very often is of the utmost importance and frequently is so important in extremely arduous investigations that without it almost nothing can be clearly understood. For instance, if the question concerns the motion of a shot fired from a cannon, the air resistance must be known in order to know what the motion will be through a finite distance, as well as both the direction of the path at the beginning and also the velocity, on which the resistance depends. But this changes with time... However, the less distance the shot travels, the less the variation, so that it is possible more easily to come to knowledge of true relationship. In fact, it we let the distance vanish, since in that case both the difference in the direction and change in velocity also are removed, the effect of resistance produced at a single point in time, as well as the change in the path, can be defined exactly. When we know these instantaneous changes or, rather, since these are actually nothing, their mutual relationship, we have gained a great deal. Furthermore, the work of integral calculus is to study changing motion in a finite space. It is my opinion that it is hardly necessary to show further the uses of differential calculus and analysis of the infinite, since it is now sufficiently noted, if even a cursory investigation is made. If we want to study more carefully the motion of either solids or fluids, it cannot be accomplished without analysis of the infinite. _Indeed, this science has frequently not been sufficiently cultivated in order that the matter can be accurately explained. Throughout all the branches of mathematics, this higher analysis has penetrated to such an extent that anything that can be explained without it's intervention must be esteemed as next to nothing.

I have establish in this book the whole of differential calculus, deriving it from true principles and developing it copiously in such a way that nothing pertain to it that has been discovered so far has been omitted. The work is divided in to two parts. In the first part, after laying the foundations of differential calculus, I have presented the method for differentiating every kind of function, for finding not only differentials of the first order, but also those of higher order, and those for functions of a single variable as well as those involving two or more variables. In the second part, I have the study of series. In that part, I have also given a very clear explanation of the theorem concerning maxima and minima. As to the application of this calculus to the geometry of plane curves, I have nothing new to offer, and this is all the less to be required, since in other works I have treated this subject so fully. Even with the greatest care, the first principles of differential calculus are hardly sufficiently developed that I should bring them, as it where drawn from geometry, to this science. Here, everything is kept within the bounds of pure analysis, so that in the explanation of the rules of this calculus there is no need for any geometric figures.

sexta-feira, março 02, 2007

C experiments

Alguma vez pensaram em ler um numero da esquerda para a direita? É completamente anti-intuitivo!! Mas um computador é capaz de lhe achar bastante piada.

A ideia base é a seguinte:
o primeiro digito é o das unidades. x1
há mais?
entao o primeiro digito é o das dezenas e o segundo é o das unidades [ x1 * 10 + x2 ]
há mais?
entao o primeiro digito é o das centenas o segundo é o das unidades e o terceiro é o das unidades [ 10(x1*10 + x2) +x3] ...

and in C this would come has simple as

int atoi(char s[]){
int i , n ;
n=0;
for(i=0; s[i]>='0' && s[i]<='9';++i)
n = n*10 + (s[i]-'0');
return n;
}


s[i]-'0', justifica-se pelo facto de os caracteres '0','1','2'.. etc terem valores incrementalmente superiores. no meu caso '0'=48, '1'=49...etc


A vantagem?? bom para começar dispensa o uso de uma segunda funçao power, para computar as potencias de 10. Suponto o raciocinio mais comum de x = x1 + x2*10 + x3 * 10^2.... etc
Consequentemente o tempo de execução é menor porque o numero de "contas" que o cpu faz é menor.

Estou deliciada!

more to come soon lol or otherwise get Richie's "The C programing language" and go for it your self. It's fun!! ;)