Download Palo Alto 2016 - Stanford Introduction to Logic

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

History of the function concept wikipedia , lookup

Argument wikipedia , lookup

Modal logic wikipedia , lookup

History of logic wikipedia , lookup

Natural deduction wikipedia , lookup

Boolean satisfiability problem wikipedia , lookup

Intuitionistic logic wikipedia , lookup

Propositional calculus wikipedia , lookup

Truth-bearer wikipedia , lookup

Catuṣkoṭi wikipedia , lookup

Law of thought wikipedia , lookup

Propositional formula wikipedia , lookup

Laws of Form wikipedia , lookup

Principia Mathematica wikipedia , lookup

Transcript
Logic for Secondary Education: Experience at Palo Alto High School
Chris Kuszmaul introduced logic as part of his Fall 2015 AP Computer Science Course. He
covered propositional logic based on the first three chapters from the Logic textbook
(http://logic.stanford.edu/intrologic/). These chapters were taught over a period of 10 days.
The programming assignments asked the students to implement a java class to represent a
logical sentence, and provide methods to support different logical inferences. An actual
description of the assignment is shown below.
Create an Interface LogicalExpression that requires:
 A constructor that takes a String that represents a logical
sentence. (You may, for extra credit, create a Sentence
abstraction and use that instead of a String)
 3 methods that return boolean values:
o valid()
o satisfiable()
o contingent()
 And two methods that return 1 to represent True, -1 to
represent False, and 0 to represent that the truth value cannot
be determined
o equivalent(LogicalExpression)
o entails(LogicalExpression)
(For extra credit you may do two things:
You may add methods that allow you to evaluate the truth value of a
logical expression (represented as a String) for a given set of variable
values.
You may create an ThreeValuedVariable that represents true, false, and
maybe -- in place of the int that would be returned by equivalent() and
entails())
For some students, the material on propositional logic in chapters 1-3 of the Logic textbook was
too easy, and the programming task gave them a challenge to stay engaged with the material.
For the students who found the material in the first three chapters challenging, the
programming assignment gave them some time to catch up and improve their understanding.
During the final exam, the students were given a piece of code implementing an aspect of
logical reasoning and were asked to critique it. The following code snippet that generates all
possible truth values for variables in a logical expression, and is an example of code that
appeared on the final exam.
public class StudentWork {
private int[] tokens;
private int count;
//Method: count
//Input: string
//Output: int
//Effect: counts how many variables are in the string and returns
that number
public int count(String s){
parseString(s);
int count1 = 0;
for(int i = 0; i < tokens.length; i++){
count1 = count1 + 1;
}
System.out.println("Count: " + count1);
return count1;
}
private void parseString(String s) {
// TODO Auto-generated method stub
}
//Method: truthValues
//Input: string
//Output: returns an integer value
//Effect: goes through all of the possible truth values for each
variable
public int truthValues(String s){
count(s);
//Assigning truth values:
int variable;
for(int truthv = 0; truthv < (1<<count); truthv++){
for (int i = 0; i < (1<<count); i++){
if(((truthv >> i) % 2) == 1){
variable = 1;
System.out.println("Count: " + count +
"=" + variable);
return variable;
}
else{
variable = 0;
System.out.println("Count: " + count +
"=" + variable);
return variable;
}
}
}
//return count;
return 1;
}
}
The above code checks to see if the first logical expression in the input string is satisfiable. If it is
satisfiable, it adds that index (or the set of truth assignments that work) to an array for later
use. The second for loop goes through the satisfied array, and checks if all those are
satisfiable. If it is satisfiable, that means the first expression must entail the second expression.
Here is an example of a student response based on the analysis of the above code:
This method returns a boolean(T/F) when it is supposed to return an int, either 1 for true,
-1 for false, or 0 for unable to tell. If a row in the truth table of the first logical expression
returns true, and the same row in the second logical expression returns true, then this
program returns true EVEN THOUGH it has not tested any of the other rows yet! Also,
this program messes up the ordering of the rows. By sticking everything from the first
expression that evaluates to true (presumably) into an arraylist, and then iterating
through that arraylist of "true" rows when comparing to ALL the second logical
expression's rows, a lot of the rows in the second logical expression's truth table are
skipped, and the wrong rows are compared with each other.
To give the response shown above, the student would need a solid understanding of Java
programming as well as underlying concepts of logic used in the program. For some students,
the above problem was too difficult and produced mostly incorrect answers of the sort shown
below.
The first line of code ArrayList<Integer> satisfied = new ArrayList<>() is incorrect due to
the second ArrayList<>. It should be ArrayList<Integer>() instead. In the first for loop, the
command variables.size() is incorrect because variables has not been initialized yet and
is of a null value. The evaluate method is an instance method, so calling evaluate alone is
incorrect. This code currently has an efficiency of O(2n) because of the 2 for loops. It is
currently inefficient because it is first adding the elements to the array, then going back
through the array again and evaluating the elements. Instead, the e.evaluate(i)
command should be called inside the first for loop. In order to keep track of the index i
properly, we can create another variable called index that only increments when the
satisfied.add(i) command is run. This would eliminate the need for the second for loop
and make the program have an efficiency of O(n).
As a result of this exercise, the students were able to draw connections to different parts of
their course. For example, some students clearly recognized the value of the above code for
processing any expression that could be transformed into prefix notation. (This approach is
more generally known as Shunting Yard algorithm.)
The overall student response to the material was enthusiastic, and they were interested
to see more of it. They also found that some of the code they wrote for the course could be
easily re-purposed for their robot programming class.
The success rate on the final exam for logic problems was approximately 40%. Chris
thought it was a good challenge for students as many of them walk into the course already
knowing the material traditionally taught in the course.
Chris has continued to follow this model during his Fall’2016 AP Computer Science class.
He changed the assignment and asked the students to implement rules of precedence in
simplifying logical expressions. The success rate was similar to the experience of Fall’2015.