Write a Lisp function ‘powerset(lst)’ that takes a list ‘lst’ as input and retur
ID: 672390 • Letter: W
Question
Write a Lisp function ‘powerset(lst)’ that takes a list ‘lst’ as input and returns the power set of the lst. Assume the input lst to be a set which is used to generate the power set of the input set. A power set is defined as a set of all subsets of a set.
Power set of {a, b, c, d, …} is equal to the union of power set of {b, c, d,…} and ‘a’ appended to each element of power set of {b, ,c, d,…}
Question1.Write a Lisp function ‘addx(x pset)’ that appends an element x to each element of a power set. Sample output of addx: >(addx ‘3 ‘(nil) )
( (3) NIL)
>(addx ‘2 ‘( (3) nil))
( (2 3) (2) (3) NIL)
>(addx ‘1 ‘( (2 3) (3) (2) nil))
( (1 2 3) (1 3) (1 2) (1) (2 3) (3) (2) NIL)
Question2.Use ‘addx’ to complete the Lisp function ‘powerset’. Use the ‘remove-duplicates’ function to remove duplicate elements in the powerset.
The following functions are NOT ALLOWED: mapc, mapcar, maplist, do, do*, dolist, setq, and when. Loops are also NOT ALLOWED. I know how to remove the duplicates. I am just having a hard time understanding how to write the 'addx' function. Any help would be greatly appreciated.