CAS CS 235 Lecture Notes - Lecture 3: If And Only If
Document Summary
Implementation of predicates (from lapets notes) using python. Table 1: x | y, y is prime meaning: # the remainder of y/x is 0 return y % x ==0. # primality predicate code def prime(y): for x in range(2,y): return true if divides(x,y): return false. Restatement of prime property: a number is prime if no smaller number can divide it evenly, so if we find such a number that does not satisfy the property return false. # number does not divide evenly def doesnotdivide(x,y): # the remainder of y / x != 0 return y % x != 0 return false if not doesnotdivide(x,y): for x in range(2,y): return true. # checking primality for all numbers: def checkall (s,p): # module run test on python script with lambda() notation. >>> checkall(set(range(2,y)),lambda x : doesnotdivide(x,y)) for x in s: return true if not p(x): return false.