Duplicated instances in sets - inconsistency with set theory? #425
Replies: 3 comments
-
Yes, you are exactly right, non-aggregating predicates define multisets. As for sets, those are defined by aggregating predicates. In particular Predicate Level Aggregation says
For the
Please let me know if you have further questions. |
Beta Was this translation helpful? Give feedback.
-
Thanks @EvgSkv , I learned something new! The equivalence to loops from the docs is very interesting, does it have any practical application, e.g. when is it the most efficient way to achieve something? |
Beta Was this translation helpful? Give feedback.
-
In practice the data that you work with is often a muliset. Even the input data can have duplicate rows and the duplication has the information. And if your input is guaranteed to be the set, then you still may end up with a multiset as intermediate data. Of course, mathematics is built on sets and you can encode a multiset as a set, but it is in fact more natural to operate on multisets directly. Here is an example. We have invited people to a party, for each person we know what fruit they like and what style of cooking they like, so we want to prepare their favorite fruit in their favorite style. All we want to know is how many dishes of each type to cook. Here is a Logica program to calculate it.
All the input predicates are sets, but the intermediate predicate |
Beta Was this translation helpful? Give feedback.
-
When I noticed this initially, I thought it might be a bug but then I saw that it is also included in the documentation under Multiset-semantincs
The result of the above code is table with values ["apple", "apple", "orange"]
If Fruit is a predicate defined by 1 arg and we have 2 instances with the same value of this arg, then why these instances aren't considered the same thing and should be duplicated? From predicate point of view these instances are completely undistinguishable.
The set method in Python confirms this:
set({"apple", "apple", "orange"}) -> {'apple', 'orange'}
I guess the goal is to allow for the multiset generalisation but is there an option to revert to standard sets, if someone doesn't want this behaviour?
When working predicate logic it is useful to know that accidental data duplications are not possible since there should be at least one predicate argument which differs between any two instances, and this value explains the difference.
Beta Was this translation helpful? Give feedback.
All reactions