Monday, May 18, 2009

Wolfram Alpha: Nutrition Calculations

I've been testing Wolfram Alpha over the past couple days. As a general purpose search engine or tool of knowledge, it is a complete failure. It relies on customized, proprietary databases, which are full of gaps. For almost everything I wanted to find out or calculate, it was clueless.

However, there are a few things it does very well. Most of these are things that ordinary people would never care about, but one thing is useful for everybody. That is the nutritional information.

You can type in a food, with any unit of measurement, and it will give you all the nutrition information for that amount of food. Even better, you can also add together different ingredients with a plus sign. So if you have a simple recipe and you want to figure out what the nutrition label would look like, you can do so rather easily.

For example, type '8 oz yogurt + .5 cup strawberry' into Wolfram Alpha and you will get the familiar nutrition label for a dish that combines these two ingredients. It will also helpfully give you the option of choosing other types of yogurt, if you want to be more specific.

One word of warning, however: if you type '1/2 cup' instead, it will get confused and list the ingredients separately. You can fix this by putting the fraction in parentheses, like '(1/2)'. You don't need these if you are only listing one type of food.

Also, you are out of luck with exotic foods. It does not know the nutrition information for, for example, mangoes.

That is the easy part. I wanted to see how far I could push it, so I tried to get an entire recipe into the computational engine. It took some work, but I finally got it to calculate a full bread machine recipe. Here is the recipe, gotten at random from a Google search:

* 1 1/3 cups water
* 1 1/2 tablespoons dry milk powder
* 1 tablespoon molasses
* 1 tablespoon honey
* 3 tablespoons margarine
* 1 teaspoon white sugar
* 1 teaspoon salt
* 1/2 cup rye flour
* 2 cups whole wheat flour
* 1 cup bread flour
* 2 3/4 teaspoons active dry yeast

I had to convert the fractions to decimals, as mentioned earlier. I had to use abbreviations to avoid a limit on input characters. I had to drop ingredients like yeast and water with no nutritional value. I learned that the machine gets very confused by 'whole wheat flour' so I had to change it to 'whole-grain flour'. I also learned that it chokes and dies if you attempt to feed it more than eight ingredients. So I left out the sugar and replaced it with a bit more honey, which is what I would probably do in reality if I was using the recipe. After all that, this is what the recipe look like when I input it into Wolfram Alpha:

1.5 tbsp dry milk
+ 1 tbsp molasses
+ 1.5 tbsp honey
+ 3 tbsp margarine
+ 1 tsp salt
+ .5 cup rye flour
+ 2 cups whole-grain flour
+ 1 cup bread flour

Of course, this produces nutrition information for the entire loaf of bread. That's not too useful. You can fix this by dividing all the ingredients by the same number. Let's say you are planning on cutting the loaf into twelve slices and eating one slice. So I divided each amount by twelve, and re-entered it. But for some reason, it could not process this. It could only process seven ingredients when I made it do the division. So I replaced the molasses with more honey:

(1.5/12) tbsp dry milk
+ (2.5/12) tbsp honey
+ (3/12) tbsp margarine
+ (1/12) tsp salt
+ (.5/12) cup rye flour
+ (2/12) cups whole-grain flour
+ (1/12) cup bread flour

and it worked: (click on the link to go to the full Wolfram Alpha output, or click on the image to enlarge it and read the information)
One thing is different than the standard labels in the store. For really small quantities, it will give actual numbers, with a smaller prefix. Look at the amount of cholesterol. It is telling us that each serving has 287 micrograms of cholesterol. A normal label would report that as zero milligrams. And it lists 590 milligrams of saturated fat, where a normal label would list 0.5 grams.

So basically, you can calculate the full nutrition label for each serving size of any recipe with seven or fewer non-exotic ingredients. That's really cool. If you are really watching your diet, or you want to make a bake sale or something look really professional, you should learn how to use this tool. It hardly takes any time at all, once you learn how to use it and what its limitations are.

No comments: