Booleans

Comprehension Questions

Math 250 - Mathematical Computing
Christopher Hanusa

7-1. Look at the following commands.  Before you evaluate each of them, determine what you think the output of each of these commands will be.  Then evaluate each command and see if you were correct.  If you were incorrect, then ask a classmate and discuss.

!True

5!

If[x==2,3,5]

If[5>10,"Ra Ra Ra"]

If[IntegerQ[Pi],4,100]

Table[!OddQ[n],{n,1,10}]

Table[If[PrimeQ[n],1,0],{n,1,10}]

Table[If[PrimeQ[n],Print[n]],{n,1,10}];

7-2. Define the function collatz that takes as input an integer x and then outputs one of two things.  If x is even, then output x/2.  If x is odd, then output 3x+1.

7-3. Use the NestList function on the collatz function from Question 7-2 for different integer inputs.  What do you notice?  What do you wonder?