12
votes
Accepted
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{...
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 ...
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
...
11
votes
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}...
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
...
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 ...
10
votes
Delete sublist when sub-sublists contain same element
Another method with DuplicateFreeQ, where @* is shorthand/infix notation for Composition.
<...
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 ...
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:
...
8
votes
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
...
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 ...
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 ...
7
votes
How to find the positions of replaced elements in a list
Position[MapThread[Greater, {a, b}], True]
(* {{1}, {2}, {4}, {7}, {8}} *)
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
...
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.
<...
7
votes
Maps between finite sets
There's no built-in function but the following constructs the mappings:
...
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 ...
7
votes
Accepted
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/...
6
votes
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 ...
6
votes
Accepted
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 ...
6
votes
Accepted
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 ...
6
votes
Accepted
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}]
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sets × 129list-manipulation × 53
combinatorics × 16
subset × 13
performance-tuning × 9
equation-solving × 8
functions × 7
intersection × 6
plotting × 5
simplifying-expressions × 5
probability-or-statistics × 5
programming × 5
variable-definitions × 4
boolean-computation × 4
partitions × 4
logic × 4
calculus-and-analysis × 3
function-construction × 3
graphs-and-networks × 3
summation × 3
syntax × 3
visualization × 3
code-request × 3
map × 3
matrix × 2