I don't think there is an easy way. It seems that in Mathematica division by zero does not return an error, simply evaluates to infinity (http://www.wolframalpha.com/ input/?i=1%2F0), which only makes sense if you are using the limit definition of equality.
So essentially, the way to fix this in Sage would be to have units be "special" symbolic variables when evaluating limits, so that sage: limit(1 / x, x=units.length.meter.mul(0, hold=True)) Infinity would return Infinity*meter instead. I think this would be quite hard to do. The other option would be to operator overload the UnitExpression class or modify the behaviour of symbolic variables when they are detected to be units. In any case, dividing by zero would still return an error. Maybe it would be useful to have a function that just does dimensional analysis and ignores coefficients? This wouldn't be hard to write. On Aug 3, 12:40 am, Stan Schymanski <schym...@gmail.com> wrote: > Yes, this makes sense to me. Wolfram seems to treat the expression and > the units separately, which makes sense. In your example, any omitted > value is seen as 1, so the result is perfectly correct. The expression > is evaluated and the units are added after it, but they don't cancel > out by subtraction. I don't think it is sensible to treat units as > variables if this leads to results like the one I encountered. Then > nothing is gained by using the units package and I could just create > my own variables called m, K, J, W etc. Is there an easy way to get a > behaviour like in Mathematica? > > On Aug 2, 9:29 pm, Eviatar <eviatarb...@gmail.com> wrote: > > > > > > > > > It seems WolframAlpha evaluates the limit of the > > expression:http://www.wolframalpha.com/input/?i=%28calorie%2Fcentimeter%5E2%2F+m.... > > > On Aug 2, 12:21 pm, Eviatar <eviatarb...@gmail.com> wrote: > > > > I don't really see this as a bug. Units are treated as variables, so > > > it makes sense. Are you suggesting that 0 * kelvin should be left > > > unevaluated, and then not give an error when it is the denominator? > > > > On Aug 2, 7:49 am, Stan Schymanski <schym...@gmail.com> wrote: > > > > > Dear all, > > > > > This is a bug-report or feature request for the units package, taken > > > > from sage-support. Basically, the units package does not handle > > > > addition and subtraction in a sensible way, as units cancel out when > > > > variables with the same units are subtracted from each other. Sage > > > > should give an error message when adding or subtracting variables with > > > > different units, while leaving the units intact if the variables have > > > > the same units. Does anyone have an idea how this could be > > > > accomplished? Thanks already! > > > > > Below is an example of the problem posted > > > > athttp://groups.google.com/group/sage-support/browse_thread/thread/a60c... > > > > > sage: udict = {} > > > > sage: udict[H_l] = units.energy.calorie/units.length.centimeter^2/ > > > > units.time.minute > > > > sage: udict[T_a] = units.temperature.kelvin > > > > sage: udict[T_l] = units.temperature.kelvin > > > > sage: soln = solve(H_l == h_c*(T_a - T_l), h_c)[0]; soln > > > > h_c == H_l/(T_a - T_l) > > > > sage: soln.subs(udict) > > > > Traceback (most recent call last): > > > > ... > > > > RuntimeError: power::eval(): division by zero > > > > > --- > > > > This works: > > > > sage: (H_l/T_a).subs(udict) > > > > calorie/(centimeter^2*kelvin*minute) -- 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