Skyrim equation to calculate if ingredient A and ingredient B can make a potion

I am making a Skyrim potion program in emacs lisp. The program will take a list of ingredients and returns a list of potions that can be created from the ingredients. However, I am having issues in finding a formula that explains what dictates if a potion can be created from ingredient A and ingredient B. I've thought of simply hard-coding all the possible recipes, however I believe there are (factorial(num_of_ingredients))/3 possibilities; give or take a few. That is a very, very large number.

Can anyone help me out with this? To reiterate: what is the formula that determines if ingredient a b and c and be combined to create potion d.


Each ingredient has 4 effects, and the only combinations of ingredients that create potions are those where effects are shared between ingredients. The ingredients and their effects are deterministic and constant in an unmodded game. You can see the full list on this page. Alternatively, you can learn the effects by experimentation or through the use tasting with the help of Alchemy perks.

For instance, Wheat and Blue Mountain Flower both have Restore Health as one of their four effects. That means they can be combined. They also both have Fortify Health, so a potion containing these two ingredients will both Fortify and Restore health.

It only takes 2 ingredients with the same effect to add an effect to a potion, so you can mix a third ingredient that has an effect in common with Wheat but not Blue Mountain Flower and that will create a valid potion that has the effects that are shared by at least two ingredients.

Do note that almost all ingredients have negative effects as well as positive effects - an alchemy mix with strictly negative effects creates a Poison instead of a Potion. A mixture of positive and negative effects will create a Potion that has negative side effects unless you've got the Purity perk from the Alchemy tree.