Difference between revisions of "Tc"
m (→Operator overloading) |
|||
Line 1: | Line 1: | ||
− | + | A tc is a data structure encoding a complex number and a variation of this number. The operations I define on these numbers are the same as most operations on complex numbers. | |
+ | The corresponding C++ library of functions that I designed really made writing my programs easier, especially for [[distance estimator|distance estimator methods]]. | ||
− | A tc is a complex number z together with a complex vector dz attached | + | == Overview == |
+ | |||
+ | A tc is a complex number z together with a complex vector dz attached. | ||
The notation dz is probably not the best but it is to mimic physicist notation, like | The notation dz is probably not the best but it is to mimic physicist notation, like | ||
\[(z+dz)\times(w+dw)=w\,z+(w\,dz+z\,dw)+\text{neglected}\] | \[(z+dz)\times(w+dw)=w\,z+(w\,dz+z\,dw)+\text{neglected}\] | ||
or | or | ||
\[\cos(z+dz)=\cos(z)-\sin(z)dz.\] | \[\cos(z+dz)=\cos(z)-\sin(z)dz.\] | ||
+ | A mathematical reinterpretation in terms of ''jets'' is given below. | ||
== Operator overloading == | == Operator overloading == | ||
Line 32: | Line 36: | ||
== Operations == | == Operations == | ||
− | One defines | + | One defines operations on tc objects as follows: |
\[(z,dz) + (w,dw) = (z+w,dz+dw)\] | \[(z,dz) + (w,dw) = (z+w,dz+dw)\] | ||
\[(z,dz) \times (w,dw) = (z\,w,w\,dz+z\,dw)\] | \[(z,dz) \times (w,dw) = (z\,w,w\,dz+z\,dw)\] | ||
Line 48: | Line 52: | ||
In other words it is an element in the tangent space TC of the complex numbers field C. | In other words it is an element in the tangent space TC of the complex numbers field C. | ||
This is why I chose the name tc for the C++ class. | This is why I chose the name tc for the C++ class. | ||
− | It can also be considered as 1-jets (can be generalized to higher degree power series expansions, like $(z,b,c)$ representing $z(t)=z+b\,t+c\,t^2+o(t^2)$). | + | It can also be considered as 1-jets (can be generalized to higher degree power series expansions, like the $(z,b,c)$ being a 2-jet representing $z(t)=z+b\,t+c\,t^2+o(t^2)$). |
+ | Jets are differential geometry object, i.e. there are specific formulae for computing how their expression (coordinates) changes when changing variables. | ||
== Derivatives == | == Derivatives == | ||
− | + | The tc objects compute derivatives for you! | |
Say you defined Z=(z,1), computed W=cos(Z×Z) and got W=(a,b). Then a=cos(z×z) and b=the derivative ∂a/∂z at z: you did not need to determine that $\partial \cos(z^2)/\partial z=-2z\sin(z^2)$, the class computed b iteratively for you. | Say you defined Z=(z,1), computed W=cos(Z×Z) and got W=(a,b). Then a=cos(z×z) and b=the derivative ∂a/∂z at z: you did not need to determine that $\partial \cos(z^2)/\partial z=-2z\sin(z^2)$, the class computed b iteratively for you. |
Revision as of 21:51, 18 December 2015
A tc is a data structure encoding a complex number and a variation of this number. The operations I define on these numbers are the same as most operations on complex numbers. The corresponding C++ library of functions that I designed really made writing my programs easier, especially for distance estimator methods.
Contents
Overview
A tc is a complex number z together with a complex vector dz attached. The notation dz is probably not the best but it is to mimic physicist notation, like \[(z+dz)\times(w+dw)=w\,z+(w\,dz+z\,dw)+\text{neglected}\] or \[\cos(z+dz)=\cos(z)-\sin(z)dz.\] A mathematical reinterpretation in terms of jets is given below.
Operator overloading
C++ allows operator overloading. In other words, you can use instructions like d=c+a*b in your programs, with any kind type of objects for a,b,c,d.
This is why it is much easier to program with complex numbers in C++ than in many other languages. Compare C++
z=u*z*(z*z+cos(c*z)+d);
with Java (no operator overloading)
z=mul(u,mul(z,add(mul(z,z),add(cos(mul(c,z)),d))));
or worse, with C
mul(w,c,z);
cos(w,w);
add(w,w,d);
mul(v,z,z);
add(w,w,v);
mul(w,z,w);
mul(z,u,w);
Operations
One defines operations on tc objects as follows: \[(z,dz) + (w,dw) = (z+w,dz+dw)\] \[(z,dz) \times (w,dw) = (z\,w,w\,dz+z\,dw)\] \[-(z,dz) = (-z,-dz)\] \[1/(z,dz) = (1/z,-dz/zˆ2)\] \[\overline{(z,dz)} = (\overline{z},\overline{dz})\] \[\exp(z,dz)=(\exp(z),\exp(z)dz)\] \[\cos(z,dz)=(\cos(z),-\sin(z)dz)\] \[etc...\]
Tangent space and jets
One can imagine that a tc pair (z,dz) represents a moving point, starting from z and moving at speed dz: $z(t)=z+dz\,t+o(t)$ . In other words it is an element in the tangent space TC of the complex numbers field C. This is why I chose the name tc for the C++ class. It can also be considered as 1-jets (can be generalized to higher degree power series expansions, like the $(z,b,c)$ being a 2-jet representing $z(t)=z+b\,t+c\,t^2+o(t^2)$). Jets are differential geometry object, i.e. there are specific formulae for computing how their expression (coordinates) changes when changing variables.
Derivatives
The tc objects compute derivatives for you!
Say you defined Z=(z,1), computed W=cos(Z×Z) and got W=(a,b). Then a=cos(z×z) and b=the derivative ∂a/∂z at z: you did not need to determine that $\partial \cos(z^2)/\partial z=-2z\sin(z^2)$, the class computed b iteratively for you.
Implementation
Either I will put code here or a link to download code.