No logic, no move

The aim of the lesson is to show the use of concepts learned during the math lesson where we use logic. Logic is close with computer science. We will use the truth table; this is a mathematical table used in logic. A truth table has one column for each input variable (for example, P and Q), and one final column showing all of the possible results of the logical operation that the table represents.

Prerequisite

What students should know before:

No prerequisites

Time constraints:

  • 3 hrs

Preparing For This Tutorial:

  • The LEGO Mindstorm EV3 Robot that coincides with this tutorial comes from building specific sections found in the LEGO Mindstorm Education Core Set building instructions. You will need to build the main body for the robot (I’ll refer to as the Base Unit), plus touch, color sensor.

  • Lessons: Basic - Motors.

Effects

ability to tested

verify whether assumptions (hypotheses) were correct.

Exercise

  1. Write a program that will start the robot when two conditions are met simultaneously (e.g. holding down the touch sensor and the color sensor detects the red color).The choice of sensors is up to you Remember that 0 means FALSE and 1 means TRUE.

  2. Here are some logical phrases. Test all of them. Which one gives the same results?

\(\neg(p\ \land q)\), \((\neg\text{\ p\ } \vee \neg q)\), \(\neg(p \vee q),\ \)\((\neg\text{p\ } \land \neg q)\).

  1. Test the examples below:

\(\lbrack(p \land q) \vee r\rbrack \Leftrightarrow \lbrack p \land (q \vee r)\rbrack\), \(\lbrack(p \land q) \vee r\rbrack \Leftrightarrow \lbrack(p \vee r) \land (q \vee r)\rbrack\),

\(\lbrack(p \vee q)\ \land r\rbrack \Leftrightarrow \lbrack p \vee (q \land r)\rbrack\), \(\lbrack(p \vee q) \land r\rbrack \Leftrightarrow \lbrack(p \land r) \vee (q \land r)\rbrack\),

Example solution

Introduction and practical assumptions

Most often we combine robotics with students who are keen on learning math. We directed our topics to students of humanistic classes. It turned out to be particularly difficult. Why? Because students of such classes most often negatively approach activities that are associated with the technique and Queen of Sciences. Therefore, the robot was supposed to be a toy (let’s not be afraid of this word) which was to smuggle the basics of logic in the game associated with the issuing of sounds by driving balls around the table and so on. We tried to test student’s hypotheses in the fun of uncomplicated robots.

In October 2005 a conference of the Mathematics Teachers Association “Mathematics and ecology” was held in Chorzów. A participant in the same was passionate about popularizing science prof. Wacław Zawadowski. He tried to interest the book of Imre Lakatos “Evidence and Refutations”, to which he wrote an introduction. For many years this item was considered a kind of underground literature for mathematicians. In Poland (also for political reasons) it was released only in that year - 30 years after the world premiere. The title refutations are an attempt to refute views that are right, which may contain errors and omissions. Lakatos (Popper’s student) points out

that hypotheses and speculations are extremely important. As part of the proposed activities, we’ve wanted, based on student-teacher dialogue, to generate doubts (in the heat of fun, but also in discussion). Doubting can be creative, and common algorithmization, so important in external exams, can unfortunately remove the smile of discovery.

Why did we use robots?

Primarily: just for fun - it seems to us that it is better to consider something like this

image0

than something like that

image1

But not only: even in simple programming the student - whose robot will not carry out the appropriate command - will notice the significance of precision of wording. Our work is based on changing and simplifying the command string using logical rules (even in the short sequence of commands one can replace the other - perhaps better).

Of course somebody can say it’s not enough, but sometimes you need to enter 3 or 4 additional math classes for volunteers (and you don’t have a cycle of 58 programming classes)… So then, below we present the program of a few such classes directed to students who are unfamiliar with coding.

“Zero” meeting

In our practice, we used a division into 3-person groups of students - in total during classes we worked with about 12 people. Dividing students into groups, we should remember about their diverse composition - the best in our opinion is when within one group the level of student interest and activity is different. Do not create so-called master groups and on the other hand very weak ones. Let’s discuss (very briefly!) the programmable cube and sensors. Suggest building a very simple chassis that will serve further operations.

At the end of the meeting let’s ask the question what is dangerous about signs placed in stores with the following wording: alcohol is not sold to intoxicated and minor persons.

Please believe us that this question taken out of context at the end of the meeting always arouses interest in what the next classes will be devoted to. 1

Part 1 - First meeting

Let’s try to make a sound when you press the button

image2

This should not be a problem but what if the sound were to appear from two conditions (let’s use a different sensor to get to know it)?

Most often the students answered like that

image3

Does such a system produce sound when two sensors operate simultaneously or not? Let’s test it.

After this experience, we will present students with a logical block

image4

and let us suggest its use

image5

Sample code in Python, which additionally changes the color of the LEDs and the robot starts if the tested condition is true by the sensors.

#!/usr/bin/env python3

from ev3dev.ev3 import *

from time import sleep

ts = TouchSensor()

cs = ColorSensor()

cs.mode = 'COL-COLOR'

mL = LargeMotor('outB')

mR = LargeMotor('outC')

mL.reset()

mR.reset()

p = 0

q = 0

Sound.speak('Go!').wait()

sleep(1)

while **p==0 or q==0**: # while **p==0 and q==0**:

  Leds.set_color(Leds.LEFT, Leds.RED)

  Leds.set_color(Leds.RIGHT, Leds.RED)

  sleep(0.1)

  if ts.value()==0:

    p=0

  else:

    p=1

  if cs.value()==5:

    q=1

  else:

    q=0

    Leds.set_color(Leds.LEFT, Leds.GREEN)

    Leds.set_color(Leds.LEFT, Leds.GREEN)

    Sound.speak('True!').wait()

    mL.run_to_rel_pos(position_sp=200, speed_sp=400, stop_action='coast')

    mR.run_to_rel_pos(position_sp=200, speed_sp=400, stop_action='coast')

What is the difference?

Let students find the answer 2 and it’s very important to clarify it. We’re trying to distinguish the alternative from conjunction. Remember: what is obvious to the teacher may be very difficult for the student. We can refer to the unfortunate (?) use of the word and instead of or in the sentence we mentioned in earlier classes: alcohol is not sold to intoxicated and minor persons.

Part 2 - Second meeting

Let’s move on to introducing logical negation (not). It is obvious what red means and not red. Is it also obvious what the color means:

not (red and yellow) → not red and / or not yellow (?)

not (green or blue) → not green and / or not blue (?)

Let’s try to test these four cases using robots.

If in each case the off / on button and the red / other right and left motor act the same, it means that the two logical sentences are identical.

Below is one of four possible cases.

image6

Sample code in Python

#!/usr/bin/env python3

from ev3dev.ev3 import *

from time import sleep

ts = TouchSensor()

cs = ColorSensor()

cs.mode = 'COL-COLOR'

mL = LargeMotor('outB')

mR = LargeMotor('outC')

mL.reset()

mR.reset()

p = 0

q = 0

Sound.speak('Go!').wait()

sleep(1)

while True:

  if **not (p or q)**: # if **not (p and q)**:

    Leds.set_color(Leds.LEFT, Leds.RED)

  else:

    Leds.set_color(Leds.LEFT, Leds.GREEN)

    mL.run_to_rel_pos(position_sp=200, speed_sp=400, stop_action='coast')

    if **(not p) or (not q)**: # if **(not p) and (not q)**:

    Leds.set_color(Leds.RIGHT, Leds.RED)

  else:

    Leds.set_color(Leds.RIGHT, Leds.GREEN)

    mR.run_to_rel_pos(position_sp=200, speed_sp=400, stop_action='coast')

    sleep(0.1)

  if ts.value()==0:

    p=0

  else:

    p=1

  if cs.value()==5:

    q=1

  else:

    q=0

By fun students tested the following de Morgan’s laws on their own:

image7

Part 3 - Third meeting

How about adding one more sensor (ultrasonic sensor)?

We can test the examples below:

image8

These examples are similar to each other so here are the most important program codes.

The third example in the Lego block diagram.

image9

Below is a program for the first and second examples in Python

#!/usr/bin/env python3

from ev3dev.ev3 import *

from time import sleep

ts = TouchSensor()

cs = ColorSensor()

us = UltrasonicSensor()

cs.mode = 'COL-COLOR'

p = 0

q = 0

r = 0

Sound.speak('Go!').wait()

sleep(1)

while True:

  if **(p and q) or r**:

    Leds.set_color(Leds.LEFT, Leds.RED)

  else:

    Leds.set_color(Leds.LEFT, Leds.GREEN)

  if **p and (q or r)**: # if **(p or r) and (q or r)**:

    Leds.set_color(Leds.RIGHT, Leds.RED)

  else:

    Leds.set_color(Leds.RIGHT, Leds.GREEN)

    sleep(0.1)

  if ts.value()==0:

    p=0

  else:

    p=1

  if cs.value()==5:

    q=1

  else:

    q=0

  if us.value()<50:

    r=1

  else:

    r=0

Encountered problems and conclusions

The above examples lead to the distributive laws in mathematical logic. However, more important than knowing the above logical laws is the very ability to be tested by learning. He could verify himself whether his assumptions (hypotheses) were correct.

If we have the opportunity to conduct at least 4 lessons on the above topic, we can use Python programming. With fewer hours, I believe that the Lego block diagram is enough to understand the ideas (laws of logic) and the emotions involved in experimenting and testing hypotheses using robots.

1

One of the most common associations is the discussion of sobriety of drivers…

2

Hint: sometimes it is better to change the sound output into the rotation of the engine - it causes less headache…

Next Section - Acceleration Due to Gravity