On 22 ago, 06:20, Oscar Lazo <estadisticame...@gmail.com> wrote: > I will check this as soon as I can. I too was not very satisfied with > the units module. In particular, I did not like the way SI prefixes > are handled. Also, this: > > sage: m=units.length.m > sage: sqrt(m^2) > sqrt(meter^2) > > When I'd expect to get "meter".
I'm sorry to say that this has a similar behavior. This is because Sage doesn't automatically simplify variables in things like sqrt(). Example: sage: x=var('x') sage: A = x^2 sage: sqrt(A) sqrt(x^2) sage: B = sqrt(A) sage: B.simplify() # takes a while loading Maxima sqrt(x^2) # ouch sage: B.simplify_radical() abs(x) # ouch^2 Since the representation of the units uses Sage variables, the behavior is the same: sage: import metrology sage: from metrology import U sage: a = U('9 m2') sage: a 9 m^2 sage: sqrt(a) 3 sqrt(m^2) sage: sqrt(a).to() # convert to SI base units 3 m > Some features I'd like to see in a units module: > > * Type recognition. Doing something like > > sage: 2.5 * m/s^2 * 2 * kg > 5.0 Newton > instead of > 5.0 kg*m*s^2 I guess I could make a function that, parting from a list of SI units, tries to get a unit as the simplest combination of SI units. > * Use SI prefixes instead of scientific notation: > > sage: c= 300000 m/s > sage: 0.9 kg *c > 81.0 mega Joule > instead of > 8.10000000000000e10*gram*meter^2/second^2 Well, the program Qalculate! does that, but this feature sometimes makes you get results like "512.47 mK" (millikelvin) or 213651.6 YJ (yottajoules) that aren't easy to understand. Also, in derivated units such as J*s there are 2 options to add the prefix to. I personally prefer something like sage: U('0.9 ug c^2') 8.08879660863136e16 m^2*ug/s^2 sage: U('0.9 ug c^2').to('MJ') 80.8879660863136 MJ (BTW, c=300000 km/s, not m/s; actually, c = 299 792 458 m/s exactly, from the definition of meter) > * To make units more easily accesible I suggest make a function that > gets units in certain unit systems available > > sage: import_units(system='SI',only_base=False) #Imports all SI units > sage: import_units(system='SI',only_base=True) #Imports all SI base > units > sage: import_units(system='SI',types='length time mass > electric_charge') #imports only metre second kilogram and coulomb I think it's easier to just use U('...') each time you need a unit, but it may be possible to make a function that creates certain variables with unit values. Anyway, I don't like units to be represented as variables, it's what makes impossible to comvert 0 celsius to fahrenheit in the current "units" module. > Would you want to include a metrology module if this replacement is > not accepted? Well, I called the module "metrology" to be able to distinguish it from the already existing "units" one, although metrology involves some other aspects such as precision handling that are out of the scope of my module. Maybe a name like "units2" or "physical_quantities" would have been more accurate. I don't see the module I wrote as a replacement of the current "units" module, but more as a different one with a different scope. -- 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