MappingInversion » History » Version 3

M. Rolf, 10/18/2011 04:02 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.
34 2 M. Rolf
35 2 M. Rolf
However, using inverse elements comes with some functional restrictions, since not all data-types have inverse
36 2 M. Rolf
elements, although an inverse might be computed with inverse operators:
37 2 M. Rolf
* @int@ numbers have no inverse element with respect to multiplication. There is not element @I@ in @int@ such that @I*2*x==x@.
38 2 M. Rolf
* The same holds for @unsigned int@ values with respect to addition. 
39 2 M. Rolf
40 3 M. Rolf
A further, general restriction is that operator Mappings can only be inverted, if the argument appears only on one side of the operator.
41 2 M. Rolf
Mappings like
42 2 M. Rolf
<pre>
43 2 M. Rolf
RealMapping f = arg<double>() * someOtherFunction;
44 2 M. Rolf
</pre>
45 3 M. Rolf
are not invertible in a generic way.