I found the "sage.symbolic.units" module very promising, but there
were some features it was missing, such as an easy way to enter units
(something like "units('kg*m/s^2')"), handling of SI prefixes (you can
do "units.si_prefixes.kilo*units.length.meter", but this is very
impractical), unit representation ("2*meter*milli" isn't very nice)...
I tried to modify the source code of the units module, but it wasn't
easy to understand and it didn't seem to be compatible with the ideas
I had in mind, so I rewrote it from scratch:

    http://trac.sagemath.org/sage_trac/ticket/9763

Some features it provides:
+ Easy units input, in the form of "U('kg*m/s^2')" or "U('3600 kg m2
s-2')", which will also handle SI prefixes
+ Plain and LaTeX representation of values with units, the latter
using the "latex_name" argument
+ Self-contained: all the information of a quantity (the number, the
expression representing the units, an array containing unit type
information, and the SI conversion factor) is stored in an object
+ Working conversion between "padded" units, such as degrees Celsius
and kelvin, even if they are multiplied or divided by another unit (in
which case it assumes 1 kelvin/second = 1 celsius/second)
+ Implicit conversion when adding units of the same type

The problem with defining a new class is that it involves defining all
the "__add__", "__sub__", "__mul__", "__le__", etc... methods, which
work differently than in other Sage classes, and it might not
integrate very well with the rest of Sage. Also, the developers might
not like the idea of rewriting a module from scratch when there's
already a module with the same purpose (although this one is very
different), and might prefer to extend what they already have and
know. Anticipating this, I did a small attempt to port some of the
features to the already existing "units" module:

    http://trac.sagemath.org/sage_trac/ticket/9778

It's not such a rework as the one I did when writing the module from
scratch, but it features:
+ SI prefixes: although tab completion doesn't include them, you can
write units such as "units.length.kilometer" and that unit will be
created automatically
+ LaTeX representation: there are only a few units as an example, but
it can be easily extended by adding more entries to the "latexdict"
dictionary. Prefixed units will make the LaTeX representation from the
ones for the prefix and the unit.
= All the units, unit documentation, and everything else that was
already implemented in "units" is kept.
- Still lacks an easy way to enter units
- Conversion of temperatures behaves weirdly (example: try to convert
32 fahrenheit to celsius and then to kelvin)

I want to hear your opinions. Which one of them is the best solution?
Or none of them? Which one looks more interesting? I personally prefer
the first one.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to