Skip to the content of the web site.

Decision making

When you have a choice, there are often multiple choices that you can make and what you do will depend on your choice:

What do I want to make for dinner?

The actions and costs depend on your choice:

  • Kraft Dinner takes ten minutes to make, at best.
  • Pasta requires you to watch more carefully as the pasta must be al dente, you must heat up the pasta sauce as well, and you must grate the Parmigiano cheese.
  • If you decide make a pizza, this requires more initial work, but after the pizza goes in the oven, your labour is finished.
  • Rice is straight-forward enough prepare, but you must then decide on the complement to the meal: chicken fried rice, tomato-basil chicken, beef-and-broccoli, honey-garlic shrimp, roasted eggplant?

How much will I study for the ECE 150 examination?

  • I won't, I know all this already.
  • I've already submitted an edit to the Linux kernel.
  • I don't know, I'll just sit down and study until I feel I know the material or I get bored or tired.
  • I've devoted the next two hours to studying for ECE 150, after which I will move on to calculus for another hour, after which I will give myself a break watching SEAL Team.

Almost no decision you ever make has a simple yes-no answer. "Are you going to class?" You could answer this with "yes" or "no", but you could also answer it with "yes, but I'll be 10 minutes late" or "I'll go for five minutes, but if I know the material, I'll leave."

For example, there is always the question: "Are you a hipster?". For this, Sunny Nihilist created the following flow chart:

For a computer, it would be too difficult to create a mechanism whereby multiple different blocks of code could be run based on specific responses to particular problems. Instead, a computer reduces each possible question to one of "yes" or "no", or "true" or "false".

For example, consider the following engineering solution:

At each point, there is a yes-no question being answered, and depending on the response, a different path is followed. In this case, each path has two questions.

Going back to the hipster question, we could require a yes-no answer to each, in which case:

For a computer, rather than referring to yes-no questions, we refer to these as a Boolean-valued statement or a conditional statement. All conditional operators return either true (1) or false (0).

Now, in C++, we have already seen that the result of a conditional statement is either 1 or 0; however, for clarity of reading, the C++ programming language includes two additional keywords, true, which evaluates to 1, and false, which evaluates to 0. You can try this out at repl.it:

// Pre-processor include directives
#include <iostream>

// Function declarations
int main();

// Function definitions
int main() {
	std::cout << " true = " <<  true << std::endl;
	std::cout << "false = " << false << std::endl;

	return 0;
}

Thus, from here on in, when we are discussing Boolean-valued operators or Boolean-valued functions (functions that return true or false), we will use true and false and you must remember to remember that true is 1 and false is 0.

The sine function is a real-valued function, for it always returns a real value. The greatest-common divisor function is an integer-valued function, for it always returns an integer. A Boolean value is either true or false, and thus a Boolean-valued function is a function that returns either true or false.

A statement is an expression in C++ that evaluates to some type of value. Thus, in each of the following:

  • If x, y and z are of type double, then x*(y + 3.0*z*z) is a real-valued statement.
  • If m and n are of type int, then m*m - 2*m*n + n*n is an integer-valued statement.
  • All Boolean operators are Boolean-valued expressions; for example, x < (y + z) or n >= m.

Definition: Boolean-valued
Taking on a value of either true or false; some times denoted as 1 or 0 or yes or no.

Definition: Boolean-valued statement
A statement in C++ that evaluates to a Boolean value. A Boolean-valued variable is a Boolean-valued statement, but so is the result of any other Boolean-valued operator, including: ==, !=, >=, <=, > and <.

Another fun example

Another game is Pictionary, a game where one player is given a word and is required draw that word. The player wins if the other players guess that word. A naive way of playing Pictionary is quite straight-forward:

This is not very good, as it really doesn't allow for significant hope to get a better solution:

Let's change the decision to keep going if the question is true:

Now, if you've made five improvements to your image and they still have not guessed it, perhaps it's a good idea to start from scratch: