I want to speed up calculations with unit conversions. I suspect primarily that some units evaluate from Wolfram|Alpha. Any way to prevent this automatically, so that Mathematica throws errors/warnings instead of grabbing units from Wolfram|Alpha?

  • 4
    $\begingroup$ Set $AllowInternet to False? $\endgroup$ – rm -rf Mar 6 '14 at 15:16

If you don't want Mathematica to use Wolfram | Alpha for correcting incorrect units, you can just set $AllowInternet = False. The downside of this is that it also blocks internet access for the curated data functions such as WeatherData, FinancialData, etc. You can also use Block to disallow internet only within your function.

  • $\begingroup$ this works, but could not get any speed up $\endgroup$ – denfromufa Mar 6 '14 at 16:49
  • 1
    $\begingroup$ @denfromufa Well, you only asked about suppressing connection :) I doubt that you can speed up the Units functionality that easily... A lot of the slowdown has to do with the fact that the data with units is stored as unpacked arrays. Depending on your actual needs, you can avoid having to use any units (track them separately) and use efficient packed arrays for computations. $\endgroup$ – rm -rf Mar 6 '14 at 16:52
  • $\begingroup$ yep, removing units is the only option $\endgroup$ – denfromufa Mar 6 '14 at 17:25

A properly formatted Quantity expression should work just fine, without trying to connect to WolframAlpha servers for conversion. For example,

Quantity[1, "Feet"] + Quantity[2, "Inches"]

should run with or without internet connectivity. In contrast,

Quantity[1, "Foot"] + Quantity[2, "Inches"]

will attempt to contact WA servers in an attempt to correct the malformed Quantity[1,"Foot"] expression.

  • $\begingroup$ yes, this my current solution, but not automated, since I have to go through each unit one by one to see if it is in offline unit set $\endgroup$ – denfromufa Mar 6 '14 at 15:57

I have found it efficient to enter expressions with units using the "Inline free-form input", and then clicking the InputForm (the bottom line) to replace the entered text with a canonical input form. This gives me an easy-to-read notebook that computes without internet connectivity, at the expense of a mouse click when entering units, and a slight delay when moving away (with right-arrow) from the box.

entering units with inline free-form input

The keyboard shortcut is Ctrl-= by default, I had to remap to Ctrl-+ to fit my Norwegian layout, by editing


as described here


I gave up trying to use Quantity and the units package in version 9 because of the drop in speed and the clumsy way of incorporating units that makes long expressions difficult to read. I have therefore stuck with Jon McLoone's package that works very well. It can found at http://blog.wolfram.com/2010/12/09/automatic-physical-units-in-mathematica/#comments

  • 2
    $\begingroup$ Please don't copy-paste the same answer repeatedly. You have already written that as an answer here, which is where it really belongs. $\endgroup$ – rm -rf Mar 12 '14 at 21:55
  • $\begingroup$ this package is not updated since 2012 according to the author: "This package is now largely obsolete as similar functionality is included in Mathematica 9. wolfram.com/mathematica/new-in-9/units It has also become incompatible with 9 due to a name conflict, though there is an easy fix: Open the file AutomaticUnits.m and do a search and replace on all occurrences of “CompatibleUnitQ” change it to a different word, I suggest “DimensionCompatibleUnitQ”. Replace the file with the modified version." $\endgroup$ – denfromufa Mar 12 '14 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.