Function Repository Resource:

LimitingIngredient

Source Notebook

Find the limiting ingredient in something similar to a chemical reaction

Contributed by: Peter Burbery

ResourceFunction["LimitingIngredient"][relation,available]

finds the limiting ingredient given relation and available.

ResourceFunction["LimitingIngredient"][relation,available,properties]

finds the values of the properties in the list properties given relation and available.

ResourceFunction["LimitingIngredient"][relation,available,All]

finds the values for all the properties.

Details

The relation should be given in the form <|input1quantity1,|><|output1quantity1,|>. For example <|"tire"4,"headlight"2|><|"car"1|>.
The available should be an Association with the inputs as keys and the number of inputs as values like <|"bread" 28, "cheese" 11|>.
ResourceFunction["LimitingIngredient"] assumes that only one of the ingredients is limiting. This assumption is not valid all of the time. However, by assuming there is only one limiting ingredient, we can simplify the calculations and programming logic.
The output contains the following keys:
LimitingItemlimiting item
ExcessItemsitems that are in excess with some left over
LimitingItemRelationassociation representing how the limiting item is consumed
LeftOverassociation detailing how many items are not consumed
Relationsassociation representing how each item is consumed for each item
Factorsinformation on what you would multiply the input "reaction" by to get a reaction for each item.

Examples

Basic Examples (4) 

Find the limiting ingredient for the construction of a car modeled as a reaction (as shown in Chem Libretexts).

In[1]:=
ResourceFunction[
 "LimitingIngredient"][<|"tire" -> 4, "headlight" -> 2|> -> <|
   "car" -> 1|>, <|"tire" -> 20, "headlight" -> 14|>]
Out[1]=

Lists of properties are supported:

In[2]:=
ResourceFunction[
 "LimitingIngredient"][<|"tire" -> 4, "headlight" -> 2|> -> <|
   "car" -> 1|>, <|"tire" -> 20, "headlight" -> 14|>, {"LimitingItemRelation", "LeftOver"}]
Out[2]=

Get all available properties:

In[3]:=
ResourceFunction[
 "LimitingIngredient"][<|"tire" -> 4, "headlight" -> 2|> -> <|
   "car" -> 1|>, <|"tire" -> 20, "headlight" -> 14|>, All]
Out[3]=

See the same reaction with different supplies:

In[4]:=
ResourceFunction[
 "LimitingIngredient"][<|"tire" -> 4, "headlight" -> 2|> -> <|
   "car" -> 1|>, <|"tire" -> 124, "headlight" -> 70|>, All]
Out[4]=

Applications (3) 

Consider the sandwich example from OpenStax Chemistry Atoms First Second Edition Section 7.4 Reaction Yields:

For the reaction 1 slice of cheese+2 slices of bread⟶1 sandwich, how many sandwiches can we make with 28 slices of bread and 11 slices of cheese:

In[5]:=
sandwich = ResourceFunction[
  "LimitingIngredient"][<|"cheese" -> 1, "bread" -> 2|> -> <|"sandwich" -> 1|>, <|"bread" -> 28, "cheese" -> 11|>, All]
Out[5]=

We can make 11 sandwiches with 11 slides of cheese and 22 slices of bread:

In[6]:=
sandwich["LimitingItemRelation"]
Out[6]=

The cheese is the limiting item (or ingredient). The excess item is the bread:

In[7]:=
sandwich["LimitingItem"]
Out[7]=

2 laser printers, 14 desks, and 30 chairs are needed for 10 full-time faculty members and 20 full-time staff. We are given 201 laser printers, 1400 desks, and 3000 chairs. Compute the limiting resource:

In[8]:=
office = ResourceFunction[
  "LimitingIngredient"][<|"laser-printer" -> 2, "desks" -> 10 + 4, "chairs" -> 30|> -> <|"full-time faculty members" -> 10, "full-time-staff" -> 20|>, <|"laser-printer" -> 201, "desks" -> 1400, "chairs" -> 3000|>, All]
Out[8]=

In this case there are actually two limiting reagents: desks and chairs:

In[9]:=
office["LeftOver"]
Out[9]=

How many big pancakes can we make given a set of ingredients:

In[10]:=
ResourceFunction[
 "LimitingIngredient"][<|"pancake-mix" -> 6, "egg" -> 7, "milk" -> 8|> -> <|"pancake" -> 5|>, <|"pancake-mix" -> 22, "egg" -> 25, "milk" -> 32|>, All]
Out[10]=

Publisher

Peter Burbery

Requirements

Wolfram Language 13.1 (June 2022) or above

Version History

  • 1.0.0 – 06 December 2023

Related Resources

License Information