Switch the screen on/off Go back to last page Go forward one page Find out more details about the advertisement
John Moores University. Main CWIS Site
  

   

Boolean Operators

The Boolean operators (and), (or), (not), (implication) and IFF (double implication ) infix operators are available in Derive.  They can be entered in text form, e.g. x AND y or they can be entered via the Math Symbol Toolbar.  Also, there are two internal Boolean constants true and false. 

 

The Boolean operators and constants can be effectively used in IF() statements within programs where multiple decisions need to be made.  For example the two statements

IF(n=0, RETURN 1), IF(n=1, RETURN 1)

can be reduced to one statement

IF(n=0 n=1 ,RETURN 1)

and the statement

IF(n<0 or FLOOR(n) n, RETURN "n must be a positive integer")

will determine if n is negative or not an integer (FLOOR(n) is Derive internal function that returns the integer part of a real number).  So we can tighten the FACT(n) program up with (Derive 5)

FACT(n, total) := PROG(IF(n < 0 FLOOR(n) n, RETURN "n must be a positive integer"), IF(n = 0 n = 1, RETURN 1), total := n, LOOP(IF(n = 2, RETURN total), total :* n - 1, n :- 1))

or in Derive unicode (DERIVE 6)

FACT(n, total) ≔PROG(IF(n < 0 ∨ FLOOR(n) ≠ n,RETURN "n must be a positive integer"),IF(n = 0 ∨ n = 1,RETURN 1) ,total ≔ n,LOOP(IF(n = 2,RETURN total),total :* n - 1,n :- 1) )

which displays as

FACT(n, total) :=
 
Prog
   If n < 0 FLOOR(n)
 
   
  RETURN n must be a positive integer  
  
If n = 0 n = 1
     RETURN 1 
   
total := n
  
loop
     
If n = 2
      
RETURN total
     
total :* n - 1
     n :- 1  

We have not covered all our bases yet as the user could enter a variable or an expression involving variables.  This will cause this program to infinitely loop.  We will touch this base later.

Move on to Vectors and Matrices