MTH4105 Week 4 Lecture 3: Piecewise Functions, Boolean Functions

MTH4105 Week 4 Lecture 3: Piecewise Functions, Boolean Functions
Piecewise Functions
A nice uncomplicated function might be something like:
(1)
which we can plot:
3
2
1
0
x
1
2
Many functions have different definitions at different parts of their domain - they are said to be defined
piecewise:
(2)
5
4
3
2
1
0
1
x
2
Actually the absolute value function is a classic example of a piecewise defined function:
(3)
By the way, when used on its own, rather than in a function definition, piecewise gets pretty-printed,
which is useful if you are typing mathematics:
(4)
Another classic example of a piecewise defined function is the step function:
(5)
The plot of this function will show a vertical line at the discontinuity unless we set 'discont' to true:
1
0
1
x
2
1
0
1
x
2
For functions of more than one variable the Boolean conditions for piecewise can combine the variables
however we like:
(6)
1
0
2
4
x
Here the vertical lines showing the discontinuities are quite useful as they indicate where curves are
overlapping each other.
Boolean Functions
We return to the discrete domain and get a list of positive integers>1:
(7)
Find the primes:
(8)
The sieve of Eratosthenes enumerates the primes by successively removing multiples of primes already
discovered.
So we start with the integers and first remove multiples of 2 (except 2). Then we remove multiples of 3,
except 3, and so on.
How do we test if a number is even?
(9)
But none of these is easy to put into select. We can extend select with extra arguments. E.g.
(10)
It means "from posints, select everything that is < 7" (but it isn't written that way round!) Applying this
idea to the type definition of even numbers:
(11)
So now we can sieve out these multiples:
(12)
Notice the set operations minus and union. We could also write this as
Common Symbols palette.
But this is a very complicated and does not clearly extend to other multiples.
using the
The smart thing to do is to create a Boolean function, specially to put into select:
(13)
(I've called it div2 but I could have given it any name ... except 'even' since Maple thinks this is a type).
Even smarter, we can incorporate the fact that 2 is not to be sieved:
(14)
(15)
Actually, when you are selecting a subset that you want to remove, you can use remove instead of select
in Maple!
(16)
Let's sieve once more:
(17)
(18)
(redefining our primelist to be what is left after another sieving).
(19)
Pretty good - the first composite number left in our list is 49 (of course - it is a multiple of 7, so that will
be sieved out next...)