 # Propositional Logic

Logic is the foundation of all computer programming, including game development. The better you understand logic, the easier it is to make your games fun, fast, and efficient.

## What is Logic?

Mathematics, science, and computer programming are all based on logical reasoning. Logic defines a set of rules. It is a way of making sure everyone is on the same page.

Common human language is often left open to interpretation. If you tell your friend "Timmy's house is so big!", you are not telling her the exact size of Timmy's house. What you consider a big house, someone else might consider small. There is no room for this type of interpretation in game development. A computer can not interperate this type of language. Even if it could, its interpretation could lead to unexpected results.

As a programmer, your goal is telling the computer exactly what to do in any possible scenario. You do this by writing logic. Game development logic is based on mathematical logic. Propositional logic is the building block. Conditional statements such as if-statements are directly based on propositional logic.

Note: It is humanly impossible to think of every possible scenario. Why set an impossible goal? If you don't try to think of every possible scenario, you will end up ignoring many probable scenarios. We are all unique individuals with our own thought patterns. If you write your code only based on scenarios that are probable for you, you will ignore the needs and thought patterns of your users.

## What is Propositional Logic?

Propositional logic defines the rules of validity (true or false). At the end of the day, anything can be broken down to "true or false" logic. For example, say you are taking a multiple-choice test with four options: a, b, c, or d. Only one answer is correct. This can be broken down to propositional logic by evaluating each possible answer as true or false. Once each possibility is evaluated, the true answer is the answer you select.

Propositional logic is also known as "statement logic". It is the process of determining if a statement is true or false. We use propositional logic to define conditions. When will what code execute? Since logic is based on rules and definitions, let's define a proposition.

### What is a Proposition?

1. A proposition is a statement.
2. A proposition has a truth value: It is equal to true or false.
3. A proposition has one truth value. It is either true or false. It can not be both.

### Which of the Following are Propositions?

1. Commander Candy is 4'11.
2. x + y = 47
In the examples above, #1 is the only proposition. It is the only statement that evaluates true or false and only has one truth value.

## Combining Propositions

We can combine propositions to solve more complicated problems. We do this using variables, comparison operators, and logical operators. You may want to look back at GDScript Operators

let p = Kobe completed level three.
let q = Kobe got a perfect score on level three

p ⋀ q

In mathematical notation this is read "p and q". Pluging in our values, this would be read "Kobe completed level three and Kobe got a perfect score on level three."

In order for p ⋀ q to evaluate true, both conditions must be satisfied:
1) Kobe completed level three.
2) Kobe got a perfect score on level three.

Here is an example of how this might look in GDScript:
``````extends Node
var completed: bool = false
var perfect: bool = false

if (completed == true) && (perfect == true):
print("Kobe completed level three with a perfect score!")``````

p ⋁ q

In mathematical notation this is read "p or q". Pluging in our values, this would be read Kobe completed level three or Kobe got a perfect score on level three.

In order for p ⋁ q to evaluate true, only one of the statements must be true. Either Kobe completed level three or he got a perfect score on level three.

Here is an example of how this might look in GDScript:
``````extends Node
var completed: bool = false
var perfect: bool = false

if (completed == true) || (perfect == true):
print("Level Complete!")``````

p → q

In mathematical notation this is read "p implies q" or "if p than q". This means if p is true than q must also be true. Plugging in our values, this would be read "If Kobe completed level three, then Kobe got a perfect score on level three."

Here is an example of how this may look in GDScript:
``````extends Node
var completed: bool = false