Is your belly showing off an unflattering… curve… after the holidays?
While crypto remains a bit quiet, we’re opting to step outside our usual Curve Finance beat, and instead LARP as health guru. Maybe we can lose you weight like we lost you money! Let’s make sure we’re all alive to see the end of the $CRV emissions in about 300 years!
(NOTE: Just like we never offer financial advice, this is also not health advice!)
In truth, we’ve spent so much time building out our various nutrition tracking scripts in Python, we wanted to share them in the hope it could aid some of your New Years resolutions. Many of you might be adopting whatever the new fad diet, and our work may be of use. We’re trying to solve the problem…
If you make a major dietary change, how can you know if it’s healthy???
Unfortunately, nutrition science is a horrible science. Once you dig into the numbers at the granularity this blog post gets into, you see how the utility of the RDA recommendations might be as shaky as the largely discredited “food pyramid.”
A lot of the nutritionists’ CYA statements ring very true though… there really is a ton of variance among people. There is no such thing as a perfect diet for everybody. All nutritional data is itself extremely flaky. The best you can do is hope to do science experiments on yourself… run trials, create hypotheses, and test results. It turns out no nutritionist could possibly understand your quirks like you can.
All that said, whatever you’re doing, we hope you’re taking regular blood tests! Fortunately it’s available inexpensively outside the awful US healthcare system, we use OYL on the regular. Expect at least a month between any dietary changes and to begin see any changes on blood test results.
People wishing to throw some money at the problem can pick up some cheap and helpful home equipment. We often use: (NOTE: these are affiliate links!)
Otherwise, all the technology you need to take control of your diet at a granular level exists for free.
Easy Mode
A lot of people rely on dieting apps that allow them to log their food and pull out data. If this works for you, great. In my experience, I’ve found nothing works as well as weighing every raw ingredient I consume on a scale and feeding the numbers periodically into your favorite AI chatbot.
Prompt:
Task: Using the raw ingredient data provided, create two outputs:
A Raw Ingredient Breakdown Table detailing each item's weight, calories, fats (total and saturated), carbs (total, sugars, and dietary fiber), and proteins. Use standardized nutritional values for calculations, and state any assumptions if needed.
A Summary Table aggregating total calories, fats (saturated and unsaturated), carbs (sugars and dietary fiber), and proteins, while identifying key vitamins likely to meet the RDA and any important vitamins or minerals missing.
Instructions:
Extract Data: Separate each entry into the item and weight (in grams). If weight is not specified, make reasonable assumptions based on typical portion sizes and state these assumptions clearly.
Standardize Names: Correct any misspellings or variations in ingredient names (e.g., "Mix hearts" → "Mixed Nuts").
Perform Calculations: Use standard nutritional values for calculations. For multi-component entries (e.g., "Latte"), include breakdowns of each component (e.g., milk content).
Output: Present two tables:
Raw Ingredient Breakdown Table: Item-by-item breakdown including weight, calories, fats, saturated fats, carbs, sugars, fiber, proteins, and other key vitamins/minerals.
Summary Table: Aggregated totals for calories, fats, carbs, and proteins, along with % of calories from fats/carbs/proteins, and notes on key vitamins and minerals.
Do not try to run this in python, or your script will exceed the size of your output and error out.
Paste Ingredients Below This Line:
[Paste your raw ingredients here]
This gives an output like the following…
For my sake, my basic daily intake is mostly unvaried, so I have a pretty decent sense of my macros and don’t have too much need for robust tracking in most cases. This script suffices for any occasional needs, and I mostly just use this to eyeball a few things. Based on your situation, of course, this may be different:
Minimize total caloric intake
Protein minimum of 1g / 1 lb body weight
<30% of calories from carbs
Any major deficiencies in vitamins/nutrients.
From here, you can do whatever prompt you like in ChatGPT… ask for recommendations, charts, et al. You can have it evaluate your intake and make recommendations. It’s the quickest and dirtiest way to keep an eye on your targets.
Of course, LLM-based AI has major limitations. It often hallucinates, so you might need to run it a few times and average out the results.
More crucially, if you’re a data nerd and want more, it’s tough to get more granular details out of ChatGPT.
For instance, look at the data returned by the USDA’s nutrition API:
If you want to get into this level of detail, you have to multiply a lot of ingredients times a lot of nutrients you want to track. Lots of ingredients, lots of rows… AI gets screwy and starts to choke. ChatGPT in particular gets sloppy with its arithmetic.
If you’re using AI, you might be able to adjust the prompt for one or two things you might be worried about… maybe you have an iron deficiency… or worry you’re not getting enough magnesium… it works just fine for small tweaks.
If your diet is pretty fixed, this works just fine. Over time you’ll get a sense of small changes you might need to make if certain vitamins are high or low. But what if you’re changing your diet radically for the New Year?
Beast Mode
Fortunately, the method is easy in principle, most diets can be analyzed as a Linear Programming problem. The concept is simple:
Collect nutritional info for raw ingredients
Declare a variable for optimization (ie minimize total calories)
Slowly add in constraints as you see fit
The first is done via a script in the repo that searches data from the USDA and prompts you to select the data to populate a json file, though it is missing a lot of nutrients and likely requires supplementing for some values it’s missing (Claude AI is helpful on this).
Once you get through this tough work, the rest can be done easily in Python using the Pulp Linear Programming Problem library! We provide an example in this Jupyter Notebook.
After a few setup cells, you see a function with several sample constraints added sequentially… this is the heart of where you play with it. For instance, here we add only one constraint, to make sure our protein hits 160g
If it works, you’ll see a basic optimization run without choking.
If you’ve added too many constraints, you’ll see it complain that the solution was infeasible. Just keep adding constraints until you hit this and go back.
Once it works, you’ll see your daily nutrition plan to get your target nutrients. For our case of maximizing protein… while minimizing calories with just the ingredients we have in our pantry, we arrive at a healthy diet of…
Yum… just chug a whole canister of nutritional yeast. Is this really part of a balanced diet? Check the next cell.
So… we’re nailing our protein, only at about 1000 calories… maxxing out a lot of B vitamins, but not quite where we want to be.
Which means you might go back and add constraints. We added a constraint for saying… maybe no more than two servings of any ingredient…
AI can help you craft constraints if you are confused…
By adding this constraint, and your diet starts to get a bit more varied…
Further caloric breakdown can be used to debug the outputs, to make sure you entered the ingredients right…
Looks about right… but we’re still not quite where we’d like to be.
Enough nerding out… what exactly is the perfect diet?