Algorithm to solve for ingredients


Does anybody know of an algorithm that could be implemented into a spreadsheet to attempt to even out the ingredients? I’ve been trying to find a few with little to no luck.

I’m trying to make an all-inclusive spreadsheet that has all of the totals calculated, but I also want it to help find the right out amounts of food and update the daily values also.

So if I add a new ingredient, it interacts with existing ones if it contains much of the same nutritional data. Anybody attempt this yet?

I know there’s the old guess and check… But I’d like to implement something more hands free…


I’m working on one but haven’t had enough time lately. Fundamentally, I believe it’s a convex optimization problem, with each ingredient represented as a vector with values for each nutrient. I was making some progress with the macronutrient side of the equation, but micronutrients get really frustrating because there is so little standardization regarding quantity measuring (International Units vary significantly from vitamin to vitamin).

Another frustrating came from data entry, good luck getting accurate data for each ingredient in any reliable form. The FDA is terrible about this. As an example, compare the nutrition information of Creatine Powder with that of a T-Bone Steak. Surprised to see that creatine is completely absent from the latter? I was. Most nutrition labels are stored in image form too! So you have to manually convert the data to CSV or JSON. I hope to use mechanical turk for this soon, but haven’t gotten around to it.

Does anyone know any good nutritional supplement data APIs? Wolfram is good for data about general things like “one apple” but bad for a specific brand of protein powder, etc.

If you would like to keep in touch as this project develops, please keep this thread going or email me at



Yeah I found a few algorithms I think I can work with. One of them being the Simplex Algorithm. I’ll see if I can work on something on paper before I commit to doing it within a spreadsheet. Although I do believe there’s a built in tool that allows for this within Excel…


Not sure if this is exactly the same as what you are trying to do, but it sounds similar


I trust that you’ve seen ? It’s a relational database in CSV instead of a proper API, but one of the tables is the solution to your “what is an IU for vitamin X in metric” question. It also answers all sorts of interesting questions you never knew you had, like the nutritional contents of raw frog. Incidentally there’s close to 900 kcal in a single serving of spotted seal oil. …it’s a timesink.

For those of you who aren’t looking for something quite so programmer to programmer, you can search the same database at


hmm, maybe request all the info from choosemyplate?


the problem with optimisation is to know what you want to optimize. there are always upper and lower limits on nutrients that your algorithm need to stay within. but you can solve it easily with an bayesian network or genetic algorithm.

the bigger problem is, that most food sources are a mixture of different ingredients and besides the macronutrients, no one knows what’s really inside. also there are often very big deviations in the exact compounds. this is why soylent is made of refined ingredients rather than whole foods. however, you do not need to solve it exactly, since your body can cope with food that is not perfect.


Hello Everyone,

I am working on a similar problem. Need to identify ingredients composition using the nutritional information that is available. Any inputs on this highly appreciated. Contact me


Are the tools embedded in completefoods of any use? Explore the different tabs, esp. the Ingredients, Recipes and About tabs.

After you have an ID and log in, you pick a recipe (from the thousands of recipes) that is close to your interests. Click the Copy button, then open the Recipe Editor, and go to town. Much of the info you want is automatically generated.