CAS CS 235 Lecture Notes - Lecture 3: If And Only If

62 views3 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents