new function subset
Now, rounding out one more maths piece. We already have set union in the form of union(SP1,SP2), set intersection in the form of intn(SP1,SP2), test for set membership in the form of mbr(KET,SP), and now today, test for subsetness subset(SP1,SP2). It returns |subset> if an exact subset, and c|subset> where c < 1 for not exactly subset.
Here is the python (yeah, trivial):
if one.count_sum() == 0: # prevent div by 0.
value = intersection(one,two).count_sum()/one.count_sum()
And here are some simple examples in the console:
-- full subset:
sa: subset(|b>,|a> + |b> + |c>)
-- partial subset:
-- another partial subset:
sa: subset(|a> + |d>,|a> + |b> + |c>)
-- another full subset:
sa: subset(|b> + |d> + |e> + |f>,|a> + |b> + |c> + |d> + |e> + |f> + |g> + |h>)
-- another full subset, this one with coeffs other than just 0 and 1:
sa: subset(0.8|a> + 3|b> + 7|c> + 0.2|d>,|a> + 4|b> + 7|c> + 5|d> + 37|e>)
-- not at all a subset:
sa: subset(|d> + |e> + |f>,|a> + |b> + |c>)
I guess that is it. I hope that is clear enough. Now, I don't yet know where I will use it, but presumably it will be useful!
And an observation. I guess one interpretation of subset(SP1,SP2) == 1 is that for every point of a "curve" in SP1, its value is bounded by (ie, less than or equal) the value of SP2 at that same point. I suspect this will be an interesting idea.
BTW, this post was partly motivated by multi-sets. Though multi-sets can be considered a subset of superpositions, since the latter can have non-integer coeffs.
previous: this concludes phase 3
next: new function list kets
by Garry Morrison
email: garry -at- semantic-db.org