Question: Implement a scheme predicate called set_equal that takes as input two lists representing sets and returns true if the lists represent the same set and
- Implement a scheme predicate called set_equal that takes as input two lists representing sets and returns true if the lists represent the same set and false otherwise. The difference between this predicate and the one predefined in Python. Thus, the call
set_equal ( [1, [2, [3, 4]]], [[[4 , 3], 2], 1] )
should return True and the call
set_equal ( [1, [2, [3, 4]]], [[4, 3 ,2], 1] )
should return False.
Note that here sets can themselves contain sets.
remember that set-equality is not primitive. To say that two sets A and B are equal is equivalent to saying that A is a subset of B and B is a subset of A. So first define a procedure set_subset roughly in this way:
set_subset (A,B)
If the first element of A is not a set, then find out if it is a member of B (use Pythons build-in in operator).
If the first element of A is a set, then find out if there is an identical set within B. Thus, if the first element of B is a set, determine whether every element of the first element of A is in the first element of B.
And if the first element of B is not a set, continue on look for the first element of A in the remainder of B.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
