IBM Watson computerDecisions

Can Machines Think?

Embedded Knowledge

One of the holy grails of the field of artificial intelligence is the answer to the question: "can machines be programmed to think?". Currently, circa 2015, most computer scientists would agree that the answer to the question is no. One must realize that when programming a person is instructing the computer on how to solve a problem. Obviously one must be able to solve a problem themselves in order to be able to program a computer to solve a problem. Thus programming can be described as the embedding of one's own knowledge in a program. Perhaps the most fundamental aspects of problem solving is a person's ability to reason about a problem and make decisions regarding the factors of the problem. People make many decisions every day. Most everyone tends to believe that their decision making processes are based upon logical thinking. The majority of decision made by people is based upon intuition, feelings, incomplete information and probability (fuzzy) logic. People can easily incorporate a fact that may only be true 50% of the time into their decisions. However, in programming the majority of decisions take the form of logical assertions, i.e., true or false statements. It is these logical assertions that we will now consider.

Boolean values

Equality & Inequality

In programming, one form of  logical assertions is equality and inequality expressions. Consider the following AppInventor blocks:

The following screen capture shows the app before any buttons have been pressed.

The expression get(global numberOfStarsOnFlag = 50)  is an example of an equality expression. It is asserting that the variable numberOfStarsOnFlag is equal to fifty. The equality operator, =,  results in a value of either true or false. In the above screen capture the initial value of the validUSflag was false. The result of the equality comparison was true as evidenced by the output of the screen capture below.

The expression get(global numberOfFootbalWins ≠ 16)  is an example of an inequality expression. It is asserting that the variable numberOfFootballWins is not equal to sixteen. The inequality operator, ,  also results in a value of either true or false. In the above screen capture the initial value of the imperfectRegularNFLseason was false. The result of the inequality comparison was true as evidenced by the output of the screen capture below.

Relational

The standard arithmetic relational operators are also implemented in App Inventor and are given in the table at the right. They allow one to make range and quantity assertions as demonstrated in the following example.

English Math A I
greater than > >
greater than or equal > >
less than < <
less than or equal < <

Operators

In spoken language one often combines assertions. For example one may state: "if today is Monday and it is winter then I will wear a coat". Thus the person will only wear a coat if both of the assertions connected by "and" is true. In programming, we say that two conditions connected by an "and" results in a true statement only if both of the conditions are true. Likewise it is common to combine assertions using "or". For example one may state: "if today is Sunday or I am on vacation then there is no work to be done today". In this case since the conditions are connected by an "or" the entire statement is true if either of the conditions are true. In natural language people will often negate the meaning of a statement using the word "not". For example one might say, "if today is not Sunday then I have to work". If the word "not" is removed from the sentence then meaning of the sentence is changed to the opposite. The same ability to negate the meaning of statements also exists in App Inventor programming by using "not". Consider the following examples.

Your English teachers most likely warned you against using double negatives to prevent confusion. Heed their advice when programming as the same rule holds.

Selection

if statement

The if statement allows a programmer to embed their own decision making ability into software.  Consider the following App Inventor "if" statement.

The statements in the then block of the if statement will only be executed when the logical assertion is true. If the logical assertion is false the statements will be skipped in the program execution. This is termed conditional execution. The if statement controls whether the statements are executed. Optionally a then block may be followed by an else block which is executed only when the preceding if block is skipped. By making an else block another if block it allows one to make a decision based upon a range of categories or cases. These cases are said to be mutually exclusive since only one should be logically true as only one will execute.

Computations

Consider the following arithmetic expression that determines what day of the week a given non-January and non-February date falls upon.

   weekDayNumber = (day + 2*month + 3*(month+1)/5 + year + year/4 - year/100 + year/400 + 1) % 7

The result stored in the weekDayNumber variable will be a value between 0..6 inclusively where 0-Sunday, 1-Mon, 2-Tues, 3-Wed, 4-Thu, 5-Fri, and 6-Sat. The percent symbol in this expression represents the remainder of the division, otherwise known as the modulo result. However the divisions in the above expression are required to be performed using integer division, i.e., no fractional decimal is computed.  

The formula will actually work for January and February dates, but they must be treated as the 13 and 14 months of the preceding year. Insert an if statement  before the formula to change the values of the month and year for Jan. or Feb. dates. Be sure to also include a second if statement after the formula computation to revert the month and year back to the initial values if they were changed by the prior if statement.

Lastly,  add if and else if mutually exclusive statements to make a variable store the day of the week computed for the date and use this variable in the  at the end to produce nice output.

Now code the app to find the day of the week for a given date.


© N. Dwight Barnette 2015 Virginia Tech University, All right reserved.
http://www.copyright.gov