Archive for February, 2008

Finding Prime Numbers

Here’s my prime number algorithm implementation that I have written in C#.


        public static bool IsPrimeNumber(double x)
        {
            if (x <= 1)
            {
                return false;
            }
            else if (!(x % 1 != 0))
            {
                double i = 2;

                bool r = true;
                while (i <= Math.Sqrt(x))
                {
                    if (!((x / i) % 1 != 0))
                    {
                        r = false;
                        break;
                    }
                    i++;
                }
                return r;
            }
            else
            {
                return false;
            }
        } 

Romance copula

This is my first article about languages. I’m going to tell you more about the origin of the romance copula (the verb ’to be’ in the romance languages). The article will be presented from a historical view and I will also bring forth different uses in  modern languages like Spanish and Italian.There are actually two words in each language (except French) that can be translated as ‘to be’. Both are derived from the latin words sum and sto, the first means ‘to be’ and the latter ‘to stand’. These are ultimately derived from Proto-European *h1es- and *steh2-. Those are the basic words. Now let us go back to the latin language and take a closer look at the evolution.

Like we said sum means ‘to be’ and sto ‘to stand’, both are also known under their infinitive forms esse and stare. Just to inform, sum (SVM in ancient times) actually means ‘I am’ rather than ‘to be’ and sto means ‘I stand’.

The uses and spelling of these two words have changed a bit since latin. Let us take a quick look at each of the romance languages and see how they use them today.

Italian

The Italian Language differs from the other Romance Languages because it has preserved the Vulgar Latin infinitives, essere and stare, as well as many other linguistical features which I won’t write about in this article.

Essere is used in almost every case in English where you use ‘to be’.

  • Sono svedese. - I am Swedish.

However the stare referes to a state rather than an essence but not like in Spanish or any of ther other languages. Therefore we are going to conenctrate on the usage of this word.

  • Stare means ‘to be’, ‘to be feeling’, or ‘to appear’ with  word like bene, male, meglio or come?. 
    • Come stai? - How are you?
    • Sto bene. - I’m well.
  • Stare is used to form the continuous forms of tenses: Sto parlando con…, Stavo studiando.
  • The participle ’stato’ has replaced the participle of essere which means ‘been’. Non è stato facile.
  • Stare can mean ‘to stand’ (stare a piedi) in some cases. But is not commonly used anymore.
  • Starci means ‘to fit’ or literally ‘to stay in it’.
  • Stare can be an alternative to ‘restare’ (to stay) which is derived from the same word.¨
  • Stare is often used as “to be located”. Mostly in southern Italy.

The Italian word ‘rimanere’ (from latin remaneo) is used like Spanish ‘quedar’ when taliking about something which is a result of something. È rimasta incinta - She became pregnant.

Spanish

In Spanish there are ser and estar:

stare -> estare -> estar

esse -> essere -> ser

There are many theories about the evolution of ’ser’ (to be). Some say that it is partially derived from sedere too, but it’s not our purpose to talk about that right now.

Usage of ’ser’

  • Ser is most commonly used as ‘to be’ refering to e.g. personality and nationality.
    • Soy sueco. - I am Swedish.
    • Ese hombre es bueno. - This man is good.
  • When the complement is a pronoun and a verb
    • Soy la víctima. - I’m the victim

Usage of ‘estar’

These are the most common uses of estar in Spanish.

  • Indicating a state.
    • Estoy aburrido. - I’m bored.
    • Estoy bien. - I’m well.
  • Forming continuous forms of a verb.
    • Está hablando sus padres. - He is talking to his parents.
  • Refering to a physical location.
    • Estoy aquí! - I’m here!
    • Están en Madrid. - They are in Madrid.

Other uses of ’ser’ and ‘estar’

Many adjectives change their meaning depending on whenever they is complemented by ser or estar.

estar aburrido - be bored
ser aburrido - be boring

estar listo - be ready
ser listo - be clever

estar bueno - be tasty/sexy
ser bueno - be good

As you may have noticed estar is almost always used together with words (mostly adjectives) that derive from past participle.
A person who is fundamentaly happy is said to ’ser feliz’.

French

In the French Language there is only one copula because somewhere along the history the two then existing copulae became one. It became être. 

  • Je suis… - I am…

Other Romance Languages

Here are the copulae of some of the other Romance Languages:

  • Catalan: (és)ser, estar
  • Romansh: esser
  • Romanian: a fi/fire (derived from ‘facere’, to make).
  • Portuguese: ser, estar
  • Sicilian: siri, stari

You can find all declensions and more to read here! http://en.wikipedia.org/wiki/Romance_copula

C Tutorial

Tutorial for beginners.

http://www.le.ac.uk/cc/tutorials/c/

Windows 7

Windows 7 Desktop

This is the first screenshots of Windows 7. Looks almost exactly like Windows Vista but with some minor visual changes. But the most significant change is that applications like Calculator and Wordpad has been upgraded. Calculator now has some new features built into it. You will appreciate the new modes, Programmers Mode and Statistics Mode. Windows 7 looks really good. Nice job so far, Microsoft. Check out the videos (the link) to see some of the new things in Windows 7.

Check it out on http://www.thinknext.net/.

Hello World! (Assembly x86)

title Hello World Program
dosseg
.model small
.stack 100h
.data
hello_message db 'Hello, World!',0dh,0ah,'$'
.code
 main  proc
    mov    ax,@data
    mov    ds,ax
    mov    ah,9
    mov    dx,offset hello_message
    int    21h
    mov    ax,4C00h
    int    21h
main  endp
end   main

Hello World in many programming languages

This is one of the best pages with “Hello World!” that I have found so far.

http://www2.latech.edu/~acm/HelloWorld.shtml

Hello World! (C++)


#include <iostream>

int main() {
  std::cout << "Hello world\n";
  return 0;
}

Hello World! (Pascal)


program hello;
begin
  writeln('Hello world!');
end.

Hello World! (Java)


public class HelloWorld {
    public static void main(String[] args){
        System.out.println("Hello, world.");
    }
}

Quadratic equations

In this post I will write about the ways of solving an quadratic equation. To solve them you also need to know how to solve an equation. If you don’t I may write a tutorial soon. Now let’s begin!

A quadratic equation is an equation written in this form:

ax² + bx + c = 0

This is an example of a quadratic equation:

x² + 10x + 2 = 0

This is the so-called “normal form” where the x² is free (times 1, not more or less). An equation of this kind has two solutions.There are a several ways to solve an quadratic equation depending on how it is written. Here are the three different types of states you are going to look for:

  1. When the product is zero (0).
  2. When it is missing the px term.
  3. When the product is not zero.

Method 1

You can use the following method when you try to solve an equation that is equal to zero and that misses a q-term.

x² + 5x = 0

Now you are going to factorize this equation into:

x(x+5)= 0

x times x is x², x times 5 is 5x and if we add those two we will get 0.

We can now find the solutions by knowing that everything is going to be equal to 0. Take a look inside the parantheses, we have x and adds 5. If we say that x is -5 and we add 5 then the expression will be equal to 0. We have found the first solution -5. And then the last x (the one outside paranthesis) will be zero because the other expression is zero.

The solutions are:

1: -5
2: 0

Method 2

It is very easy to get the solution from an equation thats misses the px-term. First you should re-order the terms (as always if needed). In this case: the x²-term on the left side and your q on the right of the equality operator.

x² - 25 = 0 x² = 25

Then you can take the square root out of the right-side term and voilà you got the solution. Well there are two actually, a negative and a positive.

1: 5
2: -5

Method 3

When you got all terms you can use the following formula, however I will not tell how this formula works (or maybe I do it in a future blogpost).

The “pq-formula”

Make sure you have the “normal form” and replace the terms in this formula with your numbers. The whole thing about this form is that you can use this form to find the solutions. Depending on if you use plus or minus (that is what +/- means) you get a solution.

That is all for now.


Pages

Categories