Set Equality (individual problem)

Recall that in languages like Scheme and Prolog, sets can be represented as lists.

However, unlike lists, the order of values in a set is not significant. Thus both

[1,2,3] and [3,2,1] represent the same set.

(a) Write facts and rules that define a Prolog relation setEq(S1,S2) that tests whether sets S1 and S2 (represented as lists) are equal. Two sets are equal if they contain exactly the same members, ignoring ordering. In this part you may assume that sets contain only atomic values (numbers, and symbols). You may also assume that S1 and S2 are ground (that is, they are constants or are bound to fixed values). For example

setEq([1,2,3], [3,2,1]). => yes
setEq([1,2], [3,2,1]). => no
setEq([susan, john, lyta], [lyta, john, susan]). => yes

(b) In general sets can contain other sets. Extend your solution to part (a) to allow sets to contain other sets. For example,

setEq([1,[2,3]], [[3,2],1]). => yes
setEq([1,2,3], [[3,2],1]). => no
setEq([1,2,3], [[1,2,3]]). => no

You may assume that all sets used as input to these predicates contain no duplicates.

Submit your code in a file called setequality.prolog.