set-theory

Is there a way to remove the nested query in this type of SQL SELECT?

≯℡__Kan透↙ 提交于 2019-12-04 19:08:03
Given this table structure and example data (t3 should not be used in the query, it is only here to show the relation between t1 and t2): t1 t2 t3 -------------- ----------------- -------------------------------- | id | value | | t1key | t3key | | id | value | | 1 | 2008 | | 3 | 1 | | 1 | "New intel cpu in 2010" | | 2 | 2009 | | 4 | 1 | | 2 | "New amd cpu in 2008" | | 3 | 2010 | | 6 | 1 | | | ... | | 4 | intel | | 1 | 2 | -------------------------------- | 5 | amd | | 5 | 2 | | 6 | cpu | | 6 | 2 | | | ... | | | ... | -------------- ----------------- How would you build a SQL query that would

Fastest way to perform subset test operation on a large collection of sets with same domain

一个人想着一个人 提交于 2019-12-04 13:14:04
问题 Assume we have trillions of sets stored somewhere. The domain for each of these sets is the same. It is also finite and discrete. So each set may be stored as a bit field (eg: 0000100111...) of a relatively short length (eg: 1024). That is, bit X in the bitfield indicates whether item X (of 1024 possible items) is included in the given set or not. Now, I want to devise a storage structure and an algorithm to efficiently answer the query: what sets in the data store have set Y as a subset. Set

efficient algorithm to compare similarity between sets of numbers?

自闭症网瘾萝莉.ら 提交于 2019-12-03 06:06:29
问题 I have a large number of sets of numbers. Each set contains 10 numbers and I need to remove all sets that have 5 or more number (unordered) matches with any other set. For example: set 1: {12,14,222,998,1,89,43,22,7654,23} set 2: {44,23,64,76,987,3,2345,443,431,88} set 3: {998,22,7654,345,112,32,89,9842,31,23} Given the 3 sets of 10 numbers above sets 1 and sets 3 would be considered duplicates because they have 5 matching numbers. So, in this case I would remove set 3 (because it's

efficient algorithm to compare similarity between sets of numbers?

不想你离开。 提交于 2019-12-02 18:39:44
I have a large number of sets of numbers. Each set contains 10 numbers and I need to remove all sets that have 5 or more number (unordered) matches with any other set. For example: set 1: {12,14,222,998,1,89,43,22,7654,23} set 2: {44,23,64,76,987,3,2345,443,431,88} set 3: {998,22,7654,345,112,32,89,9842,31,23} Given the 3 sets of 10 numbers above sets 1 and sets 3 would be considered duplicates because they have 5 matching numbers. So, in this case I would remove set 3 (because it's considered similar to set 1). I have over 10000 sets to compare and I want to do this very efficiently. I've

Python: frozensets comparison

橙三吉。 提交于 2019-12-02 05:30:20
consider the following script: # multipleSmallFrozensets is a list of 7 frozensets of differenet number of string objects multipleSmallFrozensets = [ frozenset({'YHR007C', 'YHR042W'}), frozenset({'YPL274W'}), frozenset({'YCL064C'}), frozenset({'YBR166C'}), frozenset({'YEL041W', 'YJR049C'}), frozenset({'YGL142C'}), frozenset({'YJL134W', 'YKR053C'})] # singleFrozenset is a frozenset of 3410 string objects singleFrozenset = frozenset({'YIL140W','YLR268W','YLR357W','YJL155C','YHR067W', 'YAL008W','YBR255W','YFR027W','YGR148C','YJR122W','YJL204C','YJL093C','YLR244C', 'YNL003C','YBR111W-A', ...}) #

Logic to select a specific set from Cartesian set

南笙酒味 提交于 2019-12-02 03:13:19
I'm making a password brute forcing tool as a learning exercise, and I want it to be resumable. So, what I want is to be able to say, this is the set of possible characters, if I computed the Cartesian set of every possible combination of this set up to length n, what is the set at point x? However, I want to do this without computing the entire set. I've seen similar logic in one place online but I was unable to generalise this to fit. Any help would be fantastic, thanks! I'm fluent in C# if that helps. Edit: Here's the question I mentioned earlier: How to select specific item from cartesian

Prolog list difference routine

我只是一个虾纸丫 提交于 2019-11-29 06:50:19
I am trying to implement a list difference routine in prolog. For some reason the following fails: difference(Xs,Ys,D) :- difference(Xs,Ys,[],D). difference([],_,A,D) :- D is A, !. difference([X|Xs],Ys,A,D) :- not(member(X,Ys)), A1 is [X|A], difference(Xs,Ys,A1,D). When trying: ?- difference([1,2],[],D). I get this error: ERROR: '.'/2: Type error: `[]' expected, found `1' ("x" must hold one character) ^ Exception: (10) _L161 is [2|1] ? Your usage A1 is [X|A] is incorrect. Predicate is is used only for arithmetics. Btw, SWI-Prolog has built-in subtract predicate: 1 ?- subtract([1,2,3,a,b],[2,a]

Prolog list difference routine

廉价感情. 提交于 2019-11-28 00:22:44
问题 I am trying to implement a list difference routine in prolog. For some reason the following fails: difference(Xs,Ys,D) :- difference(Xs,Ys,[],D). difference([],_,A,D) :- D is A, !. difference([X|Xs],Ys,A,D) :- not(member(X,Ys)), A1 is [X|A], difference(Xs,Ys,A1,D). When trying: ?- difference([1,2],[],D). I get this error: ERROR: '.'/2: Type error: `[]' expected, found `1' ("x" must hold one character) ^ Exception: (10) _L161 is [2|1] ? 回答1: Your usage A1 is [X|A] is incorrect. Predicate is is

Finding symmetric difference with LINQ

拈花ヽ惹草 提交于 2019-11-27 21:16:31
I have two collections a and b . I would like to compute the set of items in either a or b , but not in both (a logical exclusive or). With LINQ, I can come up with this: IEnumerable<T> Delta<T>(IEnumerable<T> a, IEnumerable<T> b) { return a.Except (b).Union (b.Except (a)); } I wonder if there are other more efficient or more compact ways of producing the difference between the two collections. Edit 1: Jon Skeet posted a first solution which does not preserve the order of the items by relying on a HashSet . I wonder if there are other approaches which would preserve the order of a and b in the

Finding symmetric difference with LINQ

喜你入骨 提交于 2019-11-26 20:35:39
问题 I have two collections a and b . I would like to compute the set of items in either a or b , but not in both (a logical exclusive or). With LINQ, I can come up with this: IEnumerable<T> Delta<T>(IEnumerable<T> a, IEnumerable<T> b) { return a.Except (b).Union (b.Except (a)); } I wonder if there are other more efficient or more compact ways of producing the difference between the two collections. Edit 1: Jon Skeet posted a first solution which does not preserve the order of the items by relying