1 | initial version |

Also, a possibe feature for teaching could be that you are not allowed to add things with different units (you can use the `convert()`

function to test that):

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
```

2 | No.2 Revision |

Also, a possibe feature for teaching could be that you are not allowed to add things with different units (you can use the `convert()`

function to test that):

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule - second
TypeError: Physics do not like such additions
```

This may also help avoiding bad cancellations.

3 | No.3 Revision |

~~Also, ~~Perhaps, a possibe feature for teaching could be that you are not allowed to add things with different units (you can use the `convert()`

function to test that):

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule-joule
joule
sage: joule - second
TypeError: Physics do not like such additions
```

This may also help avoiding bad cancellations.

4 | No.4 Revision |

Perhaps, a possibe feature ~~for teaching ~~could be that you are not allowed to add things with ~~different ~~incompatible units (you can use the `convert()`

function to test that):

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule-joule
joule
sage: joule - second
TypeError: Physics do not like such additions
```

This may also help avoiding bad cancellations.

5 | No.5 Revision |

~~Perhaps, a ~~Another possibe ~~feature ~~point of view could be ~~that you are ~~not ~~allowed ~~to ~~add ~~allow adding things with incompatible units (you can use the `convert()`

function to test that):

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule-joule
joule
sage: joule - second
TypeError: Physics do not like such additions
```

This may also help avoiding bad cancellations.

6 | No.6 Revision |

Another possibe point of view could be not to allow adding things with incompatible units (you can use the `convert()`

function to test that):

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule-joule
joule
sage: joule - second
TypeError: Physics do not like such additions
```

This may also help ~~avoiding ~~to avoid bad cancellations.

7 | No.7 Revision |

Another possibe point of view could be not to allow adding things with incompatible units (you can use the `convert()`

function to test ~~that):~~that). For this, you have to modify the `.__add__()`

method in the class i defined above.

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule-joule
joule
sage: joule - second
TypeError: Physics do not like such additions
```

~~This may ~~If you also ~~help ~~define `.__pow__()`

method as of above (imitate the product), i guess you have a way to ~~avoid bad cancellations.~~test wether an expression makes sense, and in which units wil be the result.

8 | No.8 Revision |

Another possibe point of view could be not to allow adding things with incompatible units (you can use the `convert()`

function to test ~~that). ~~that: this function put your units in the international system standard). For this, you have to modify the `.__add__()`

method in the class i defined above.

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule-joule
joule
sage: joule - second
TypeError: Physics do not like such additions
```

If you also define `.__pow__()`

method as of above (imitate the product), i guess you have a way to test wether an expression makes sense, and in which units wil be the result.

9 | No.9 Revision |

~~Another ~~Now, another possibe point of view (perhaps more pedagogical) could be not to allow adding things with incompatible units (you can use the `convert()`

function to test that: this function ~~put ~~transforms your units in the international system standard). For this, you have to modify the `.__add__()`

method in the class i defined above.

```
def __add__(self,other):
if self.convert() == other.convert():
return self
else:
raise TypeError('Physics do not like such additions')
sage: (joule + second*watt)*newton
joule*newton
sage: joule-joule
joule
sage: joule - second
TypeError: Physics do not like such additions
```

If you also define `.__pow__()`

method as of above (imitate the product), i guess you have a way to test wether an expression makes sense, and in which units wil be the result.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.