leonardpunt / software-testing Goto Github PK
View Code? Open in Web Editor NEWUvA course: Software Specification and Testing
UvA course: Software Specification and Testing
.
This is good-looking, clear, concise report, you did he bonus, and
used the right definition of Carmichael numbers (++).
A few remarks:
I don't believe your remark. Factorisation of large numbers is very expensive.
I bet that on the large run compositesAlternative wins.
composites :: [Integer]
composites = composite_sieve [2..]
-- Get all composite numbers from an inputted integer list.
composite_sieve :: [Integer] -> [Integer]
composite_sieve xs = [i | i <- xs, head (factors i) /= i]
-- Credits to Ferry for optimalisation.
-- This function is implemented according the hints in the assignment, but the function above is much faster
compositesAlternative :: [Integer]
compositesAlternative = [x | (x,False) <- sieveComposites [(i,True) | i <- [2..]]]
sieveComposites :: [(Integer,Bool)] -> [(Integer,Bool)]
sieveComposites ((i,False):ibs) = (i,False) : sieveComposites ibs
sieveComposites ((i,True):ibs) = (i,True) : sieveComposites (map (\ (n,b) -> (n, b && rem n i /= 0)) ibs)
This is very good observatiion.
- Results of testing:
-- testF 1 carmichael -> seems to return all CarMicheal numbers
-- testF 2 carmichael -> seems to return all CarMicheal numbers
-- testF 5 carmichael -> does not return the first CarMicheal number (294409) as a number that fools Fermat's little theory
-- So if 'k' gets higher, not all CarMicheal numbers are returned as numbers that fool Fermat's little theory. This is because
-- Fermat's little theory states that prime numbers have the property a^p = a (mod p). CarMicheal numbers have the property
-- a^p = a (mod p) too, however 'a' and 'p' have to be relatively prime (i.e. gcd has to be 1). So if we find an 'a' that is
-- not relatively prime with 'p', is does not pass Fermat's prime check. The higher 'k' gets, the higher the probability we
-- find such an 'a'.
This routine doesn't terminate. Why not testing from which primes
are connected to Mersenne Primes (see Answers Week 6).
-- Precondition: input is a prime number
mersennePrimes :: Integer -> IO ()
mersennePrimes p = do
print(show p)
let p1 = (2^p - 1) in
do
r <- primeMR 5 p1
when r $ mersennePrimes p1
-- 3.1
Opg 3
intersectSet :: Ord a => Set a -> Set a -> Set a
intersectSet (Set xs) (Set ys) = list2set (intersect xs ys)
-- 3.3
differenceSet :: Ord a => Set a -> Set a -> Set a
differenceSet (Set xs) (Set ys) = list2set (xs \\ ys)
Better not use the internal representation of Set
Opg 4
- Written code (as lambda)
trClos :: Ord a => Rel a -> Rel a
trClos x = lfp (\ x -> nub (x ++ (x @@ x))) x
-- Alternative implementation of trClos
trClosAlternative :: Ord a => Rel a -> Rel a
trClosAlternative [] = []
trClosAlternative r | uhm == r = r
| otherwise = trClosAlternative uhm
where uhm = nub (r ++ (r @@ r))
{-|
Exercise 5
-}
-- Properties
-- A relation R is transitive if R^2 is subset of R
transitiveProp1 :: Ord a => Rel a -> Bool
transitiveProp1 r = containsSubSet r (r @@ r)
containsSubSet :: Eq a => Rel a -> Rel a -> Bool
containsSubSet r = all (\ x -> elem x r)
OK!!!!
Opg 5
1. Properties:
-- - a relation R is transitive if R^2 is subset of R
transitiveProp1 :: Ord a => Rel a -> Bool
transitiveProp1 r = containsSubSet r (r @@ r)
containsSubSet :: Eq a => Rel a -> Rel a -> Bool
containsSubSet r = all (\x -> elem x r)
The is also a property called minimality: There exists a tuple in trClos(R) at which the trClos minus that tuple
is not transitive any more.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.