In: Computer Science
Define the subtraction predicate: set_difference(Set1,Set2,SetDifference) where all the three sets are represented as lists. For example, set_difference([a,b,c,d],[b,d,e,f],[a,c]). should return true. Also, the predicate should terminate as soon as the first solution is found when unifying variables for these arguments. That is, set_difference([a,b,c,d],[b,d,e,f],X). should terminate immediately after finding the first solution, X = [a,c].
Explanation:
Predicate logic:
In mathematical logic, a predicate is commonly understood to be a Boolean-valued function F, such that X→ {true, false}, called a predicate on X. However, predicates have many different uses and interpretations in mathematics and logic, and their precise definition, meaning and use varies from one theory to another. When a theory defines the concept of a relation, a predicate simply becomes the characteristic function or the indicator function of the relation.
In the light of the above discussion, the given subtraction predicate is discussed as follows:
The Subtraction Predicate:
The given subtraction predicate : set_difference(Set1,Set2,SetDifference) where all the three sets are represented as lists.
Therefore, the subtraction predicate can be defined as the differece between the first two arguments of the set_difference function, viz Set1 and Set2 and the difference of the subtraction is compared to the thrid argument, viz SetDifference. If the values of the result of the subtraction and the argument SetDifference are found to be the same, atleast til finding the first solution, then the function returns a boolean TRUE and otherwise, if the values are unequal, then the returned value is a boolean FALSE. Mathematically, this can be denoted as follows:
FindDifference = Set1 - Set2;
If FindDifference = SetDifference, then return TRUE else return FALSE.
The Example Given:
In accordance to the given definition, the given example is analysed as follows:
Given: Set1 = [a,b,c,d] , Set2 = [b,d,e,f], SetDifference = [a,c]
FindDifference = Set1 - Set2 = [a,b,c,d] - [b,d,e,f] = elements of Set1 - elements of Set2 that are in Set1
= [a,b,c,d] - [b,d] = [a,c] = SetDifference
Since, FindDifference = SetDifference, therefore it returns TRUE.
This defines the subtraction predicate set_difference(Set1,Set2,SetDifference) along with the necessary explanations and analysis of the given example. Please like the answer if it serves your purpse. Thank you.