Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Defining Propositions With Maple

Over the course of this chapter, we have dealt with a wide variety of propositions. While a lot of propositions we’ve dealt with were constructed from elements of modern popular culture, such propositions (usually) are of little mathematical interest. Instead, a small number of propositions we’ve dealt with involved comparing numerical values, and finding certain solutions to given equations, applications that are heavily used in mathematics.

We continue leveraging the power of Maple to handle mathematical logic by defining the aforementioned types of propositions. By this, we no longer consider general propositions represented by symbols like p and q, but instead focus on specific examples of propositions such as

13 < 17

or like

3(2)2 – (2) + 1 = 0.

Here, we’ll examine how to define such propositions in Maple.

Relational Operators

While evaluating a proposition such as

“Charles Dickens wrote the novel Great Expectations”

is outside the capabilities of Maple (unless otherwise told), a proposition such as

12 ≥ 17

is straight forward for Maple to evaluate. This is because Maple knows how to compare numbers using the greater-than-or-equal-to operator ≥.

Maple knows how to deal with a wide variety of mathematical operators, of which the most commonly used are shown below:

OperatorName
=is-equal-to
is-not-equal-to
<less-than
less-than-or-equal
>greater-than
greater-than-or-equal
not-less-than
not-less-than-or-equal
not-greater-than
not-greater-than-or-equal

Access to these operators are either provided on a standard keyboard, or are available in the “Common Symbols” pane in the left-hand column.

However, it is not enough to simply type something like

-5 > -12.2

into a Maple worksheet and have Maple output either true or false. This happens because “-5 > -12.2” is an expression, and Maple does not automatically evaluate expressions.

Maple (Worksheet): Expressions Are Not Automatically Evaluated

> restart:

> -5 > -12.2

-5 > -12.2

Getting Maple to Evaluate Expressions

Maple does not automatically know what to do with a given expression, so it will usually just spit it back out. Instead, we have to tell Maple what to do with a given expression.

Figure 1.B.1: The evalb command takes in a proposition, and evaluates it as true or false. However, it will not automatically evaluate all expressions given to it. For example, square roots of non-square numbers will not be evaluated.

The first way we’ll tell Maple to evaluate a proposition is with the evalb command. This command takes in a proposition, and evaluates it as either true or false. Note that it does not output 0s or 1s, but instead will write out the words false or true respectively.

Maple (Worksheet): Using evalb on Simple Propositions

> restart:

> evalb(17 > 0)

true

> evalb(17 < √25)

false

Figure 1.B.2: The evalf command can take a symbolic expression and output a number that is numerically equivalent to the given expression (assuming the expression can be evaluated numerically.)

Before continuing on, note that Maple will automatically calculate square roots of perfect squares, since those are integers. Maple will not automatically evaluate the square root of a number that is not a perfect square. Hence, we’ll need to numerically evaluate square roots of non-perfect squares when using the evalb command. Another related command called evalf will numerically evaluate any expression given to it, as long as that expression can be evaluated numerically.

Maple (Worksheet): Using evalf With evalb

> restart:

> evalb(17 > √300)

10√3 < 17

> evalf(√300)

17.32050808

> evalb(17 > evalf(√300))

false

Figure 1.B.3: The is command will numerically evaluate parts of an expression as needed when deciding if the given proposition is true or false, and so is a bit more robust than the evalb command. The linked page for the evalb command makes note of the is command, so that page is linked here as well.

Similar to the evalb command is the is command. Instead of having to manually call the evalf command on certain parts of a given expression, the is command will go ahead and numerically evaluate whatever part of the expression is needed in order to determine if the proposition is true or false.

Maple (Worksheet): Using the is Command

> restart:

> evalb(17 > √300)

10√3 < 17

> is(17 > √300)

false

Turning Propositions Into Propositional Functions

Now that we’ve discussed how to get Maple to evaluate certain kinds of propositions, it’s now time to figure out how to get Maple to evaluate propositional functions.

First, we must learn how to define a function in Maple. The basic syntax for defining a function in Maple is as follows:

f := x → expression

Let’s color code each distinct part of the syntax and describe what each part is:

f := x expression

fThe name used to reference the function.
:=The assignment operator which assigns everything to it’s right to the name supplied on it’s left.
xThe variable on which the function is being defined.
The functional operator. This operator will take whatever symbol is supplied on it’s left side, and convert it to a number defined by the expression given on it’s right side.
expressionThe expression used to define the function.

After we define a function, we can invoke that function on supplied inputs using the following syntax:

f(x).

Again, let’s color code each part of the syntax, so it’s clear what’s going on:

f(x)

fThe name of the function.
()The parenthesis enclose whatever number is going to be substituted in for the function’s variable.
xThe number that is going to be substituted in for the function’s variable.

Let’s take a look at a couple of examples.

Maple (Worksheet): Defining Functions in Maple

> restart:

> p := a → evalb((a + 1) < 100)

p := a ↦ evalb(a < 99)

> p(1)

true

> p(100)

false

> d := n → 2n

d := n ↦ 2·n

> d(1)

2

> d(10)

20

Notice that when defining function p, Maple went ahead and simplified the expression

(a + 1) < 100

to the expression

a < 99.

We still have all of the normal logical operators at our disposal when crafting propositional functions.

Maple (Worksheet): More Complicated Propositional Functions

> restart:

> p := a → evalb(5 ≤ a ∧ a < 9)

p := a evalb(5 ≤ a < 9)

> p(4)

false

> p(5)

true

> p(8)

true

> p(10)

false

> q := a → evalb((a ≠ 1) ∨ (a ≤ 5) ⇔ (a – 2 < 3))

q := a evalb((a ≠ 1 or a ≤ 5 ⇒ a < 5) and (a < 5 ⇒ a ≠ 1 or a ≤ 5))

> q(0)

true

> q(1)

true

> q(4)

true

> q(5)

false

> q(6)

false

Functions With Multiple Variables

As discussed in Section 7 of Chapter 1, a propositional function can have more than one variable. The syntax for defining a function with multiple variables in Maple is not too different from defining a function with one variable.

Let’s define a propositional function with two variables:

f := (x, y) → expression

The only real difference is that we specify two variables enclosed in parenthesis. We’ll color code the additional syntax in green so it’s clear:

f := x → expressionf := (x, y) → expression

Naturally, the expression provided to the function should involve both x and y, instead of just x or just y.

Maple (Worksheet): Functions With Two Variables

> restart:

> q := (x, y) → is(x · y > 5.2)

q := (x, y) ↦ is(5.2 < y · x)

> q(6, 7)

true

> q(2.1, 2.4)

false

Defining a function with three variables is easily done by simply adding another variable enclosed in parenthesis. Let’s revisit Example 1.7.3 where we defined a propositional function to determine if the U.S. Postal Service would ship a package based on that package’s dimensions:

Maple (Worksheet): Functions With Three Variables

> restart:

> s := (ℓ, w, h) → is(ℓ + 2·w + 2·h ≤ 108)

s := (ℓ, w, h) ↦ is(ℓ + 2·w + 2·h ≤ 108)

> s(32, 16, 18)

true

> s(20, 18, 30)

false

The answers obtained here are exactly the same we got from the associated example.

Outputting Numbers Instead of Words

When we were working with truth tables in the Maple section on mathematical logic, we could specify a MOD2 format that would display the numbers 0 and 1 in place of false and true respectively. There is a way to do the same thing with logical functions, but there is one more command to discuss in order to achieve such functionality.

Figure 1.B.4: The subs command can be used to replace one list of sub-expressions in for another list of sub-expressions.

The way to to do this in Maple is to replace, or substitute, the words false and true with the numbers 0 and 1 respectively when the desired propositional function is called. Since we are dealing with propositional functions, there are only two values we need to worry about. As demonstrated in Figure 1.B.4, the first thing we can supply to the subs is a list of replacements. For propositional functions, the list will be the following:

[false = 0, true = 1].

This list says that false will be replaced by 0, and true will be replaced by 1. Basically, the left-hand-side of each equals sign is the original output, and the right-hand-side of the equals sign is the replacement or desired output.

We’ll take some care in preparing the functionality we want.

Maple (Worksheet): Using Numbers Instead of Words

> restart:

> p := n → evalb(n ≥ 0)

p := n ↦ evalb(0 ≤ n)

> p(-1)

false

> p(1)

true

> q := n → subs([false = 0, true = 1], p(n))

q := n ↦ subs([false = 0, true = 1], p(n))

> q(-1)

0

> q(1)

1

Notice in the above script that when we defined the function q, all we did was simply pass the input n directly into the previously defined function p, which uses the evalb command. By doing it this way, we can still have a function spit out the words true or false, while having a new function spit out the numbers 0 and 1.

This also cuts down on the complexity of the definition for function q. Imagine having to type in all of the necessary stuff into a single line. It would be error-prone. By splitting the commands evalb and subs across two functions, each function is easier to type out, and thus get correct.