Few days ago I recalled an interesting inequality I used in my PhD work. It looks like, for any integrable function $f(x) > 0$, $\forall x\in [a,b]$
$$e^{\frac{1}{b-a}\int\limits_{a}^{b}\ln{f(x)}dx}\leq \frac{1}{b-a}\int\limits_{a}^{b}f(x)dx$$
This is, more or less, a generalised form of the inequality of arithmetic and geometric means. E.g. for any $x_i \in[a,b]$, $\forall i=1..n$, $a=x_1$, $b=x_n$
$$\sqrt[n]{\prod\limits_{i=1}^n f(x_i)}\leq \frac{1}{n} \left(\sum\limits_{i=1}^n f(x_i)\right)$$
The natural logarithm is monotonically increasing function:
$$\frac{1}{n}\left(\sum\limits_{i=1}^n \ln{f(x_i)}\right)\leq \ln{\left(\frac{1}{n} \left(\sum\limits_{i=1}^n f(x_i)\right)\right)}$$
Let's consider $h=\frac{b-a}{n}$
$$\frac{1}{b-a}\cdot\frac{b-a}{n}\left(\sum\limits_{i=1}^n \ln{f(x_i)}\right)\leq \ln{\left(\frac{1}{b-a} \left(\sum\limits_{i=1}^n f(x_i)\cdot\frac{b-a}{n}\right)\right)}$$
Or
$$\frac{1}{b-a} \left(\sum\limits_{i=1}^n h\cdot\ln{f(x_i)}\right)\leq \ln{\left(\frac{1}{b-a} \left(\sum\limits_{i=1}^n f(x_i)\cdot h\right)\right)}$$
Now let's consider $\lim\limits_{h\to 0}$ and the fact that the limit keeps the inequality:
$$\lim\limits_{h\to 0} \frac{1}{b-a} \left(\sum\limits_{i=1}^n h\cdot\ln{f(x_i)}\right) = \frac{1}{b-a}\int\limits_{a}^{b}\ln{f(x)} dx$$
The natural logarithm function is continuous, so:
$$\lim\limits_{h\to 0} \ln{\left(\frac{1}{b-a} \left(\sum\limits_{i=1}^n f(x_i)\cdot h\right)\right)}=\\
\ln{\left(\frac{1}{b-a} \cdot \lim\limits_{h\to 0} \left(\sum\limits_{i=1}^n f(x_i)\cdot h\right)\right)}=
\ln{\left(\frac{1}{b-a} \cdot \int\limits_{a}^{b}f(x)dx\right)}$$
As a result
$$\frac{1}{b-a}\int\limits_{a}^{b}\ln{f(x)} dx \leq \ln{\left(\frac{1}{b-a} \cdot \int\limits_{a}^{b}f(x)dx\right)}$$
Considering that the natural exponential function is also monotonically increasing function we receive the original inequality.
Another proof is the fact that the natural logarithm function is concave, i.e. for $\forall \alpha_i$ such that $\sum\limits_{i} \alpha_i=1$
$$\sum\limits_{i} \alpha_i \cdot \ln{f(x_i)} \leq \ln{\left(\sum\limits_{i} \alpha_i \cdot f(x_i)\right)}$$
Now, if we consider $\alpha_i=\frac{Δx_i}{b-a}=\frac{h}{b-a}$ we will receive the same result.
Monday, October 4, 2010
Tuesday, March 23, 2010
Re boxed primitives in Java and .NET
One of my colleges posted the following question once "why <i = i++> expression returns different results in C++ and Java/.NET?". For instance try this:
Many C++ developers will argue that <i = i++> is left undefined in C++ (i.e. it is up to compiler implementers to return whatever they think it is most appropriate). However, at a more practical level <i = i++> against a primitive int type, in C/C++, is a simple (optimized ASM code, avoiding all the formalities with moving to/from registers):
at the same "address location" (in a simplistic way). So the result is 2.
Now, let's look what C++ suggests about operator++(int). It suggests making a copy of the current instance, increasing current instance and returning the copy. Following this rule, the result is:
But it is exactly what Java/.NET returns. From this, it is logical to conclude that Java/.NET primitives are boxed (which seems to be logical, otherwise it is hard to imagine how to support platform independence in Java/.NET, for example replacing the above class with a structure like "struct MyInt { int i : 32; };" in order to support 32 bits integers). Also this means that C/C++ works faster with primitives :)
http://www.codeproject.com/Articles/67392/Re-boxed-primitives-in-Java-and-NET.aspx
C/C++ int i = 1; i = i++; printf("%d\n", i); result is 2 Java int i = 1; i = i++; System.out.println(i); result is 1
Many C++ developers will argue that <i = i++> is left undefined in C++ (i.e. it is up to compiler implementers to return whatever they think it is most appropriate). However, at a more practical level <i = i++> against a primitive int type, in C/C++, is a simple (optimized ASM code, avoiding all the formalities with moving to/from registers):
mov i, i inc i
at the same "address location" (in a simplistic way). So the result is 2.
Now, let's look what C++ suggests about operator++(int). It suggests making a copy of the current instance, increasing current instance and returning the copy. Following this rule, the result is:
class MyInt { private: int i; public: MyInt(int iVal) { i = iVal; }; int val() const { return i; }; MyInt(const MyInt& t) { i = t.val(); }; MyInt& operator=(const MyInt& t) { i = t.val(); return *this; }; MyInt operator++(int) { MyInt t = *this; i++; return t; }; }; MyInt func() { MyInt i = MyInt(1); i = i++; return i; } int _tmain(int argc, _TCHAR* argv[]) { int i = 1; i = i++; _tprintf(_T("%d\n"), i); MyInt t = func(); _tprintf(_T("%d\n"), t.val()); return 0; } Result is 2 1
But it is exactly what Java/.NET returns. From this, it is logical to conclude that Java/.NET primitives are boxed (which seems to be logical, otherwise it is hard to imagine how to support platform independence in Java/.NET, for example replacing the above class with a structure like "struct MyInt { int i : 32; };" in order to support 32 bits integers). Also this means that C/C++ works faster with primitives :)
http://www.codeproject.com/Articles/67392/Re-boxed-primitives-in-Java-and-NET.aspx
Friday, February 19, 2010
Re Microsoft HPC Server 2008
Microsoft is targeting Financial Markets with its new, I could say, product Microsoft HPC (High Performance Computing) Server 2008.
http://www.microsoft.com/hpc/en/us/financial-services.aspx
It is indeed new, because it is in “beta” and the latest news from Microsoft HPC Server 2008 team’s blog dates with Nov 2009:
http://blogs.technet.com/WindowsHPC/
It is also free for evaluation from Microsoft web site:
http://www.microsoft.com/hpc/en/us/default.aspx
I also heard that, while most of the financial market providers use Real Time Linux based systems, London Stock Exchange (together with Microsoft) is trying (http://www.theregister.co.uk/2009/11/26/lse_crash_again/) to achieve the desired real time/latency related requirements with Windows based solutions and I guess they will switch to using Microsoft HPC Server 2008 soon.
In the meantime, Wikipedia suggests that some configurations using Microsoft HPC Server 2008 succeeded to rank the 23rd position in the list of top 500 fastest super-computers:
http://en.wikipedia.org/wiki/Windows_HPC_Server_2008
http://www.microsoft.com/hpc/en/us/financial-services.aspx
It is indeed new, because it is in “beta” and the latest news from Microsoft HPC Server 2008 team’s blog dates with Nov 2009:
http://blogs.technet.com/WindowsHPC/
It is also free for evaluation from Microsoft web site:
http://www.microsoft.com/hpc/en/us/default.aspx
I also heard that, while most of the financial market providers use Real Time Linux based systems, London Stock Exchange (together with Microsoft) is trying (http://www.theregister.co.uk/2009/11/26/lse_crash_again/) to achieve the desired real time/latency related requirements with Windows based solutions and I guess they will switch to using Microsoft HPC Server 2008 soon.
In the meantime, Wikipedia suggests that some configurations using Microsoft HPC Server 2008 succeeded to rank the 23rd position in the list of top 500 fastest super-computers:
http://en.wikipedia.org/wiki/Windows_HPC_Server_2008
Thursday, February 18, 2010
Re DirectCompute API (high speed calculations)
This is just a brief introduction to the subject. Few years ago programmers realized that GPU (graphical processor unit, those on NVIDIA and ATI) can be used for various (Float Point, Matrix/Vector, etc.) calculations. So NVIDIA started its CUDA project:
http://www.ddj.com/cpp/207200659
Recently (almost), Microsoft decided to continue this idea in a more standard way, by defining DirectCompute API, as part of DirectX:
http://www.nvidia.com/object/directcompute.html
And Microsoft decided to develop Windows 7 based on this addition to DirectX:
http://www.ditii.com/2009/08/22/gpu-computing-via-directcompute-in-windows-7/
So, it seems that DirectCompute is going to become standard API for super fast calculations in Windows, especially in finance for real time pricing computation.
http://www.ddj.com/cpp/207200659
Recently (almost), Microsoft decided to continue this idea in a more standard way, by defining DirectCompute API, as part of DirectX:
http://www.nvidia.com/object/directcompute.html
And Microsoft decided to develop Windows 7 based on this addition to DirectX:
http://www.ditii.com/2009/08/22/gpu-computing-via-directcompute-in-windows-7/
So, it seems that DirectCompute is going to become standard API for super fast calculations in Windows, especially in finance for real time pricing computation.
Friday, October 30, 2009
MP3 Recorder
A few years ago I wrote an article about MP3 recording, check this link for more details. It also included a console application as a demo project. That application allows recording sound from, literally, any source provided by the sound card driver. For example, it could be a microphone for recording the voices of your children or sound mix for recording webinars. A few days ago I added a proper (kind of) user interface to it, so I quickly compiled a new version. It looks something like this:
Download it from my public folder (it's free!) and give it a go. It runs well under Windows 2000, XP, Vista, 7 and (update) 10. Let me know if you like it. In case you like it, consider donating for further development ;-)
Download it from my public folder (it's free!) and give it a go. It runs well under Windows 2000, XP, Vista, 7 and (update) 10. Let me know if you like it. In case you like it, consider donating for further development ;-)
Subscribe to:
Posts (Atom)