Skip to main content
12 votes
Accepted

Efficient deletion of specific list entries

This is a solution that reorders elements. ...
Henrik Schumacher's user avatar
12 votes
Accepted

Maps between finite sets

alist = {3, 4, 5}; blist = {"a", "b"}; mapfs = Tuples@Outer[Rule, blist, alist] $$\begin{array}{l} \{\text{a}\to 3,\text{b}\to 3\} \\ \{\text{...
Syed's user avatar
  • 56.2k
11 votes

How can I define operators that implement the algebra of sets?

Here is one idea. Convert the set expression into an equivalent boolean expression, use BooleanMinimize to simplify the boolean expression, and then convert back to ...
Carl Woll's user avatar
  • 131k
11 votes
Accepted

Is there a simple way to perform the opposite of intersection on two lists?

There is probably a build-in command for this, but with over 6,000 commands, hard to search now. But you could try ...
Nasser's user avatar
  • 149k
11 votes

How to stretch this Venn diagram?

I get a decent looking result with: ...
Brett Champion's user avatar
11 votes
Accepted

Delete sublist when sub-sublists contain same element

Select+ ContainsNone Select[Apply[ContainsNone]]@lis {{{a}, {b, c, d}}, {{b}, {d}}, {{a, b}...
kglr's user avatar
  • 400k
11 votes
Accepted

Can Solve[...] be used for set math? If so, how? If not, how else?

The tedious part of this is writing all the equations ...
mikado's user avatar
  • 16.8k
10 votes

Delete sublist when sub-sublists contain same element

I am sure there are many ways to do this. One possible way is to take the union of both sublists, and check if its length is same as sum of length of both sublists. Since when making union, duplicates ...
Nasser's user avatar
  • 149k
10 votes

Delete sublist when sub-sublists contain same element

Another method with DuplicateFreeQ, where @* is shorthand/infix notation for Composition. <...
NonDairyNeutrino's user avatar
10 votes
Accepted

What Does Compile`SetIterate Do?

It sets an iterator: cfun = Compile[{{n, _Integer}}, Table[If[x == 2, Compile`SetIterate[x, 4]]; x, {x, n}] ] Note that 2 ...
Michael E2's user avatar
  • 241k
8 votes
Accepted

Non-flat partitions of a set

Why not use Quotient to figure out what row each element belongs to, and then make sure there are no duplicates? For example: ...
Carl Woll's user avatar
  • 131k
8 votes

How to stretch this Venn diagram?

...
Bob Hanlon's user avatar
  • 161k
8 votes
Accepted

How can I remove and keep the elements of this set?

Edit According to the comment, we should divide the 8 element to 4 pairs. Select[list, And @@ (GCD @@@ Partition[#, 2] == 1 // Thread) &] Original ...
cvgmt's user avatar
  • 79.8k
7 votes

How to select minimal subsets?

Since @DanielLichtblau used Internal`ListMin in an answer to a recent question, I will use it in an answer to this question. Given the following partial order on ...
Carl Woll's user avatar
  • 131k
7 votes

Efficient deletion of specific list entries

This will maintain order but is notably slower than the method provided by @HenrikSchumacher. The idea is to create down values of counts for the second list, then decrement said counts when they ...
Daniel Lichtblau's user avatar
7 votes

How to find the positions of replaced elements in a list

Position[MapThread[Greater, {a, b}], True] (* {{1}, {2}, {4}, {7}, {8}} *)
Roman's user avatar
  • 49.3k
7 votes

Mathematica code for q-Stirling numbers

On second thought, it is much more convenient to use Theorem 4.5 of the paper as a definition, so ...
Hausdorff's user avatar
  • 3,535
7 votes
Accepted

How to generate Venn diagram from a universe and 3 random sets?

There is an answer about how to create Venn diagrams here: Create a Venn Diagram. I'm using VennDiagram[] function from Method 2. Let's firstly create the sets. <...
mszynisz's user avatar
  • 834
7 votes

Maps between finite sets

There's no built-in function but the following constructs the mappings: ...
Michael E2's user avatar
  • 241k
7 votes
Accepted

Displaying Hasse diagram (directed edges in graph pointing upwards)

There are two separate issues here: How to get Mathematica to choose the root properly? How to flip the plot so arrow point up? The default layout for trees is ...
Szabolcs's user avatar
  • 236k
7 votes
Accepted

How to plot this set of complex numbers?

The domain of the mapping 1/z is ...
herbertfederer's user avatar
6 votes
Accepted

How to pick elements from a list with variable condition

How about: Pick[M, LessEqualThan[1] /@ Max /@ Abs[M.Transpose[A]]] {{0, 0, 0, 1}, {-(1/2), -(1/2), -(1/2), 1/2}, {-(1/2), 1/2, 1/2, 1/2}, {1/ 2, -(1/2), 1/...
Carl Woll's user avatar
  • 131k
6 votes

Finding largest Range in a list

...
kglr's user avatar
  • 400k
6 votes

Efficient deletion of specific list entries

Short but not efficient: f = Fold[DeleteCases[##, 1, 1] &]; {a, b} = {{1, 2, 1, 3, 1, 3, 4, 5}, {6, 1, 3, 1, 5}}; f[a, b] {2, 1, 3, 4} Slightly longer ...
kglr's user avatar
  • 400k
6 votes
Accepted

How to find the positions of replaced elements in a list

A few additional alternatives: ...
kglr's user avatar
  • 400k
6 votes

Why doesn't DeleteDuplicates do what I want

You need to use DeleteDuplicates after you Flatten the list, otherwise it will not work properly (if duplicates are in different ...
Lukas Lang's user avatar
  • 34.4k
6 votes
Accepted

ArgMin over intervals and discrete sets

...
Bob Hanlon's user avatar
  • 161k
6 votes

Delete sublist when sub-sublists contain same element

(1) Pick, IntersectingQ lis//Pick[#,MapApply[IntersectingQ,#],False]& (* {{{a}, {b, c, d}}, {{b}, {d}}, {{a, b}, {c, d}}} *) (2) Pick, Intersection Syed has ...
user1066's user avatar
  • 21k
6 votes
Accepted

Decompose set into elements?

...
kglr's user avatar
  • 400k
6 votes
Accepted

How to draw 3D sets in Mathematica given inqualities

RegionPlot3D[x + 2 y - 1 <= z, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]
David G. Stork's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible