Section 5.6 Relations in Action
Imagine you are shopping for clothing online and want color scheme suggestions for the outfit you are creating. The website you are shopping on has many color options and far too many potential combinations to evaluate on your own. Sage can solve this by narrowing down the options for your preferred color scheme rules.
Python’s
colour
package has a dictionary of color values and names that will be used as a stand-in for the color information provided by the website. We will use a dictionary because it allows for us to see outputs as color names as opposed to RGB values.The dictionary is very large and it would force sage to calculate many irrelevant pairs in a relation. Personal preferences are necessary to narrow down the set sage works with.
For this example, you will be creating an outfit out of a tee-shirt, over-shirt, and bottoms. Each clothing item will be represented by a set of the colors, as strings, that are available for that clothing item. With this we can now create the set of colors that we want to work with.
Subsection 5.6.1 Color Complements
Complementary colors are two colors, who’s hues are \(180^\circ\) away from each other on the color wheel. RGB values do not let us compare hues easily so we will use the
rgb2hsl
command, from the colour
package, and the hue values it generates to compute which colors are complements. The rgb2hsl
command outputs in the format (hue, saturation, lightness)
with all values, \(v\text{,}\) in the range \(0 \leq v \leq 1\text{,}\) so instead of checking for complements with increments of \(180^\circ\text{,}\) we will use increments of 0.5
.Here is a relation, on \(C\text{,}\) that maps colors to their complements.
It may appear as if the
Complement
relation can be categorized as an equivalence relation, but this is not the case; colors do not complement themselves therefore the relation is not reflexive.Subsubsection 5.6.1.1 Complementary Outfits
If you wanted the over-shirt and bottoms to match, you could have your outfit consist of two complementary colors. The colors available for the over-shirt are different from the colors available for the bottoms, so a new set of both clothing items’ colors must be made.
The
Complement
relation does not describe all complementary outfits with the given restraints. This can be fixed by intersecting the relation with over_bottom
\(\times\)Tee
because this imparts the restraints of complements and website inventory.Subsection 5.6.2 Triadic Schemes
If you want each component of your outfit to be of a differ color, you can use a triadic color scheme. Triadic color schemes consist of three different colors, where each color is \(120^\circ\) or \(240^\circ\) away on the color wheel.
Here is a relation that maps a color to the colors with the hue \(120^\circ\) to its right.
Composing this relation with itself causes it will map one color to other colors with hues \(120^\circ\) away on the color wheel. This may miss some color pairs, in C, but these pairs lack a third color and thus do not constitute a triadic scheme. These pairs are therefore omitted.
Subsubsection 5.6.2.1 Triadic Outfits
With triadic outfits we can not intersect (or union for that matter) two sets of clothes because all pieces of clothing should be in different colors. We can still combine two sets in order to streamline the creation of relations by remembering that a relation is itself a set, and therefore we can create a relation from a set onto a relation.
Now that you have a relation that describes all triadic schemes in \(C\text{,}\) you need to now narrow it down to the color combinations allowed by the website’s stock.