CS代写 5. Write a function equivs of the type (‘a

5. Write a function equivs of the type (‘a
-› ‘a list list, which par-
titions a list into equivalence classes according to the equivalence function.
equivs (=) [1;2;3;4] ;;

Copyright By PowCoder代写 加微信 powcoder

: int list list
= [1]; [2]; [3]; [4]]
equivs (fun x y
-> (=) (x mod 2) (y mod 2)) [1; 2; 3; 4; 5; 6; 7; 8];;
: int list list = ([1; 3; 5; 7]; [2; 4; 6; 8]]

6. Goldbach’s conjecture states that every positive even number greater than 2 is the sum of two prime
numbers. E.g., 18 = 5 + 13, or 42 = 19 + 23. It is one of the most famous conjectures in number theory.
It is unproven, but verified for all integers up to 4 × 1018. Write a function goldbachpair
int * int to find two prime numbers that sum up to a given even integer. The returned pair must have
a non-decreasing order.
# goldbachpair 10; ;
(* must return (3, 7) and not (7, 3) *)
int * int = (3, 7)
Note that the decomposition is not always unique. E.g., 10 can be written as 3+7 or as 5+5, so both
(3, 7) and (5, 5) are correct answers.

9. Write the polynomial function, which takes a list of tuples and returns the polynomial function corre-
sponding to that list. Each tuple in the input list consists of (i) the coefficient, and (i) the exponent
# (* below is the polynomial function f(x) = 3x^3
– 2x + 5 *)
= polynomial [3, 3;
-2, 1; 5, 0];;
• int, = 25

10. The power set of a set S is the set of all subsets of S (including the empty set and the entire set).
Write a function powerset of the type ‘a list
a list list, which treats lists as unordered sets,
and returns the powerset of its input list. You may assume that the input list has no duplicates.
# powerset [3; 4; 10];; (* for sets, the item order does not matter *)
int list list = (C]; [3]; [4]; [10]; [3; 4]; [3; 10]; [4; 10]; [3; 4; 10]]

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com