Tuesday, 22 March 2011

Propositional logic and De Morgan's Law

Starting from now till April 6th. I will most likely be posting blogs relating to what i am doing in school. Using writing my blogs as one of the many forms i will use to study for my final exams. Now i have three final exams. One for my major(computer science), and two relating to my math classes. Discrete, and Calculus.
 //Covering (Sec 1.1 - 1.2). personal note
Propositional Logic:

what is a proposition?

A proposition is a statement that is either true or false.
Ex. This is a propositional statement.

Now that we got that covered you can do logic with propostions using logical operators.

Logical Operators:
 ~,->,^,v,⊕,<->.

where NOT is denoted by ~, implication is denoted by ->, AND is denoted by ^, OR is denoted by V,
 Exclusive OR denoted by ⊕, biconditional denoted by <->.

NOT works as a negation. If the propostion p was true. The negation of p denoted ~p would  be false.
 Implication  works as the following. If p then q. Now what this means is if p is true then q is true. Now this also works for if q is true then p must also be true. This is helpful if you have the propostional statement.

If p then dogs can bark. Well we know nothing about the statement p, but since p implies q. We know that q is true therefore p must also be true.

AND works as the following. P^Q. P is true and Q is false then the statement is not true.  P and Q are false the statement is not true. P is false and Q is true the statement is false. The only way a statement with the AND operator is true is if both P and Q are true.

OR works similar to AND. P V Q is true if either P or Q is true. The only time the statement can be false is if both P and Q are false.

Exclusive OR works a bit differently then OR. P V Q is true if only one of P or Q is true. So this proposition can only be false by having both of P and Q false, or both P and Q being true.

 Biconditional works as the opposite of the Exclusive OR. P<-> Q is only true. If both P and Q are true, or both P and Q are false.

Some examples:

Let p, q, r be the propositions:
p: you have the flu
q: you miss the final exam
r: you pass the course

Express P->Q (p implies q).

If you have the flu, then you miss the final exam.

Express Q-> ~R (Q implies the negation of R)

If you miss the final exam, then you do not pass the course.

Express (P-> ~R) V (Q -> ~R) (p implies the negation of R) or (Q implies the negation of R)

If you have the flu, then you do not pass the course or if you miss the final exam, then you do not pass the course.

Now what is the logical operator equation of:

If dogs can fly, then grass is green.

If you answered P -> Q, you were correct. 

Truth Tables:

A truth table is a nice way of keeping track of how a logical operator equation outcomes.

To create a truth table for an equation. You take the propositions.  Denote them by a letter, usually P, Q,R,....Z

Then you create a column on the far left as the following exmaple shows.

 P  ||  Q| Passing each different outcome for P and Q or how every many propositions used.
--------| These outcomes T and False are called Truth Values.
T  ||   T |
T  ||   F |
F  ||   T |
F  ||   F |

So lets make a truth table for  [(P->Q)^(~P)]

 P  ||  Q| ( P -> Q) | ~P  | [ (P -> Q) ^ (~P) ] 
--------|----------------|---------------------
T  ||   T |      T        |   F  |               F
T  ||   F |      F        |   F  |               F
F  ||   T |      T        |   T  |               T

F  ||   F |      F        |   T  |               F

So that is how a truth table works it is great for when you are trying to show that two logical equations are logically equivalent.

 Such as by looking at ( P -> Q) ^ ( P -> R) is equivalent to P -> (Q ^ R)

Now by looking at these two equations you may be able to see that they are equivalent. But for the most part creating a truth table can show and prove that these two are equivalent.


Definitions:

Tautology: A compound proposition that is always true for all truth values.
Contradiction: A compound proposition that is always false for all truth values.

De Morgans Law:
is the way in which the negation of a compound proposition can be rewritten as another equivalent compound proposition.

Examples:

p -> Q equivalent ~P V Q
P -> Q equivalent  ~P - > ~Q
P V Q equivalent ~P -> Q

~(PVQ) equivalent ~P ^ ~Q



 

Saturday, 19 March 2011

Your first program in C

Well for anyone who actually reads these, and has an interest for programming. But was never quite sure how to begin. I will go step by step and show you how to begin. Most tutorials on the internet you read shows you the coding. But never shows you anything past that in terms of how to compile(build it), and where to write it(environment).

So first off go and download any version of Visual Studio(the environment i will get you to use). This should be free off many sites.  I am using Visual Studio C++ 2008 express edition if any cares. Now once everything is installed and what not. You should run the program and come to a nice menu. Mine looks like...


Okay from here go to :

1. File/New/Project.
 
2. There will be a column project types. Click on Win32.
     Now in the Templates section. Click on Win32 Console Application.
     Now name your project anything. Lets say "First Program" .

3. It will now ask you questions. Click Next. On this screen make sure the bubble. Application type is
clicked  on Console Application. Also make sure that you click Empty project. The click Finish.

4. You should now be brought to the original menu. But now in your recent projects shows your project name. Now glance to the far right of the menu. There should be a folder named Source Files. Right click this and add new item. Under the categories select Code. In the templates body select the file that has an extension .cp or .cpp. Should be named C file or C++ file.

5. Name this file. I usually just name it the name of my project in most cases. If everything went right you should be looking at a screen similiar to this.

 6. Now to start coding. In that blank white area is where you type your code. So time to write are first program.

# include <stdio.h>

void main()
{
      printf("Hello World\n");
}

There's your first program.

7. Now it's time to build it and run it. At the top there should be a menu build. Click this and build solution. At the bottom will have a bunch of crazy writing appear and then will tell you if the build succeeded. The above code should be error free so it will say succeeded: 1 or something along those lines.

8. Now to run it go to Debug next to build. Then click start without debugging. Enjoy you now have just created a program.


Any questions or you get lost comment.

Friday, 18 March 2011

More Minecraft...sadly

Well seeing as the pyramid went well for a post. I figured this post will get similar results hopefully.
This is like a hourglass, but with lava. Behind that you can see a tower that overlooks my surrounding area. There is a floating smiley face above a barely visible roller coaster track made of sponge. Appropriately named the sponge bob express. Random igloo with a small little lookout on it. In the background you can see a wall. This is a castle wall that surrounds the perimeter of my home.

 Here is a structure i made of my guitar. Now i couldn't finish the neck all the way because i hit the sky. But the body is still similar. Behind that is a blue building that needs a logical gate combination to open the doors to get in. Those small blocks and red lines in the background are just a bunch of logic gates.

Thursday, 17 March 2011

My Minecraft Pyramid(Math Edition)

So seeing as i just can't go to bed at 4 am like a normal person and wake up for early for a class at 9:30. I figure hey i wonder how many blocks it took me to make that huge pyramid. So i determined a summation for it. First i needed to know how big the pyramid was in height measure by blocks. So starting from the base and all the way up to the top. It was 58 blocks high. Now as far as the width goes. The pyramid is not solid, but instead made of ring layers.The width is always changing by 8 blocks each time starting at the first drop down from the very top block. So as an ACII drawing.



 Layer 0                                  x  = 1
 Layer 1                                xxx = 8 ----aerial view of layer->   xxx As seen 8 blocks to make this ring layer
 Layer 2                              xxxxx = 16                                      x  x
 Layer 3                            xxxxxxx = 24                                     xxx

So starting from the top each layer below the top is 8 blocks or more. We will denote the very top of the pyramid as layer 0.  Now we know each layer is 8 blocks more than the previous layer except in the case that the previous layer is layer 0. So we can create a summation for layers  1 - 58.

 58
Σ      8n              This summation will account for all blocks below layer 0. But what about layer 0. 
n = 1

For layer 0 just add 1 to the summation equation.


       58
1 + Σ      8n     = 1 + 8+16+24+32+40+48+....+ 464        
       n = 1


Well this doesn't exactly give us our answer of how many blocks it took to make the pyramid. But at least it shows how big the base of the pyramid is. A whole 464 blocks. WOW.

Using a graphic calculator. Assuming i know how to use the summation function properly on the calculator. It accumulated a total of 13688 blocks  + 1 block for layer 0. So a grand total of 13689 blocks. KOOL.

There you go bloggers. If you want to create a crazy big pyramid of a height of 58 that reaches the sky limit. You need to have at least 13689 blocks of sandstone.

Wednesday, 16 March 2011

My Minecraft Pyramid

Now i have accomplished all kinds of huge structures that for some reason i have not posted or shown to anyone. But at the moment i am currently constructing a massive pyramid that reaches the sky boundary. Now at the moment i have the pyramid built all the way to the sky limit. But as far as the inside goes. This is where i get all hot, sweaty, and excited. I will keep you updated when i am done building the inside full of rooms and traps. Like any good Egyptian movie like the mummy. A pyramid just isn't a pyramid without traps and treasures.

Screen shot of my pyramid(made with the help of flying mods)

Tuesday, 15 March 2011

Newtons Method of Square Roots

Today i will be talking about Newtons method for finding square roots. This is somewhat important in the computing world if while programming you have no access to a direct built in function that allows you to calculate the square root of a number. This should never be the case for almost any language will have this function built into some sort of header/library for use. In my case an assignment for my computer science class wanted me to compute a square root using this method. So to start off we first need to know what Newtons Method is.

Newtons method needs your radian(the number you want to take the square root of) and an approximation of what you think the square root is. Now of course your radian has to be a non negative real number as well as your approximation. Your approximation should also logically be less than your radian. This should be a no brainer.

So now we set the equation Newton laid out for use nicely in his method.
Okay i lied to you. I will not use Newtons Method completely for i find for computing the square root we can skip some math steps if we are programming. Anyhow here is my layout.

Let a  = your approximation , x = your radian, epsilon = nothing at the moment.

1. If   a*a-x = 0 then a is obviously your square root.

2.  else  (a*a+x)/(2*a)  = e

Now a  = e. Then go back to the first step and plug away to see if you get a root. 

As an example lets try and find the square root of 5. Our approximation will be 2.

1. 2*2-5  = -1 which does not equal 0.

2. 2*2+5/(2*2) = 9/4 = 2.25. Let a  = 2.25.

 Now back to 1.

1. 2.25*2.25 - 5 = 5.0625 - 5 = .0625 which does not equal 0.

2. 2.25*2.25 +5/(2*2.25) = 10.0625/4.5 = 2.2361111.

Now we can keep doing this as many times as possible until we feel we have a close enough number to the square root of 5. As i pull out the calculator, as this was an on the spot example. The square root of 5 is 2.236067977 which rounded is 2.2361. So our answer suffices for this equation. Hooray for Newton.

Programming applications. Here is a function i wrote that will display this in terms of C++ code for viewing pleasure.


 root = squareRoot(20,radian,1); //function call
/*Function call passing the number of times i would like the formula to simplify answer or try and find it,
The radian(number we want the square root of), and just a basic approx of 1. Doesn't really matter for this.

double squareRoot(int n,double radian,double approx)
{
    if((approx*approx-25)==0)//if our root is a then we will return the root.
    {
        return approx;
    }
    else
    {
        if(n==0)
        {
            return approx;
        }
//if the root was not found above gets a new approximation to work with.
        approx = (approx*approx+radian)/(2*approx);

        return squareRoot(n-1,radian,approx);
    }
}


Now this code example is using recursion, but upon inspection we can see the formula i laid out for you in action. Now using my program that i created for my assignment with the above code being apart of it. Lets calculate some ridiculous large square root.

Lets say 696969696. My program says 26400.2.
Using a calculator we get 26400.18364. Which is just not a simplified answer. 
Thus you can see how accurate you can find the square root of a number using Newtons Method and programming.

Hope you enjoyed this.

DisposedCheese

Monday, 14 March 2011

Beat Hazard

I was reading up on my fellow followers blogs. When i read about a certain game my fellow follower was reviewing. This game was Beat Hazard. Now i must say at first glance i thought this game was just a knock off of Geometry Wars.  But no this game is awesomely unique in its own way. The game being a hybrid of geometry wars, any space shooter type game, and asteroids. The catch being. It's flashy and confusing as hell while playing making you really need to focus. But....



The whole game is played and dependent on what music. Music?! you say.Yes music. When you start up the game. The game will ask for a song track. Now a song track can be any music file on your computer or that of one already in game. Once you have selected a song. You can now play that song level. Each song level will be different of course. Now while your playing the game depending on the song. You will be armed with awesome weapons straight from the start or weak guns that leave you vulnerable, depending on how fast the tempo of the song and beat is. Other important things to take note of is the game is scored.



Whilst playing the game you will notice floating circles that you can assume are important to run over. So far upon my run through of the game. I have noticed 3 pick ups. a red on that says pow is to upgrade your weapons to something more powerful. A yellow one that says vol, is to increase the volume of your song(amplifies it). A green one increase your multiplier.Now the object is to kill as much things as possible. Get a great score, and survive the duration of your song. Which is not always easy to do. 



After each game over or survival. The above image is shown with how far you progressed on your song, and the amount of points you got on it. Now this review and explanation was done horribly for this game. But if you looked at the pictures and thought it was good enough for your next acid trip. You can buy the game off, well anything on Google. If you feel like not paying well I'm sure you know what to do. Anyhow it's a great game and everyone should try it out. EDIT: This game is available for PC, and XBLA.