MappingInversion » History » Version 1
M. Rolf, 10/18/2011 01:45 PM
1 | 1 | M. Rolf | h1. Mapping Inversion |
---|---|---|---|
2 | 1 | M. Rolf | |
3 | 1 | M. Rolf | Mapping objects can (in certain limits) return their own inverse-functions. |
4 | 1 | M. Rolf | See for instance source:trunk/nemomath/examples/ExampleMappingArithmetics.cpp |
5 | 1 | M. Rolf | Custom mappings need to define the @getInverse()@ function for this functionality. |
6 | 1 | M. Rolf | |
7 | 1 | M. Rolf | |
8 | 1 | M. Rolf | h1. Inversion of operators |
9 | 1 | M. Rolf | |
10 | 1 | M. Rolf | A rather special aspect is the inversion of Mappings that are defined by operators such as |
11 | 1 | M. Rolf | <pre> |
12 | 1 | M. Rolf | RealMapping m = 2.0 * arg<double>(); |
13 | 1 | M. Rolf | </pre> |
14 | 1 | M. Rolf | Mappings like this are invertible: |
15 | 1 | M. Rolf | <pre> |
16 | 1 | M. Rolf | RealMapping mInv = m.inverse(); // divide by two |
17 | 1 | M. Rolf | </pre> |
18 | 1 | M. Rolf | For this to be possible, NemoMath defines *Inverse elements* for datatypes like @double@. |
19 | 1 | M. Rolf | Therefore the above statement does not actually evaluate to @arg<double>() / 2.0@. Instead, |
20 | 1 | M. Rolf | NemoMath uses a method @leftMultInverse<double>(const double&)@ to see that left-multiplication |
21 | 1 | M. Rolf | with 2.0 can be reverted by left-multiplication with 0.5. Hence, the concrete inversion evaluates |
22 | 1 | M. Rolf | to @0.5 * arg<double>()@. |
23 | 1 | M. Rolf | |
24 | 1 | M. Rolf | h3. But why shouldn't NemoMath use @arg<double>() / 2.0@? |
25 | 1 | M. Rolf | |
26 | 1 | M. Rolf | The reason for that detour is that not all |
27 | 1 | M. Rolf | types define operators like @*@ and @/@ in pairs: |
28 | 1 | M. Rolf | * NemoMath's Vector and Matrix clases only provide @*@, but not @/@. |
29 | 1 | M. Rolf | * @std::string@ defines @+@, but not @-@. |
30 | 1 | M. Rolf | * Timestamps like Boost's @ptime@ define @-@, but not @+@. |
31 | 1 | M. Rolf | |
32 | 1 | M. Rolf | If NemoMath would try to use *inverse operators*, like inverting @+@ with @-@, the Mappings |
33 | 1 | M. Rolf | could not be used for such types. It simply wouldn't compile. |