Hamiltonian vector field: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>TakuyaMurata
→‎Poisson bracket: change a sign so that f \to X_f is now a Lie alg homomorphism
en>Arcfrk
rv: wrong dab (none of the links at the dab page for skew-symmetric applies directly; better leave it as it is)
 
Line 1: Line 1:
{{other uses}}
35 years old Fashion Designer Gerry Goar from Sept-Iles, usually spends time with interests like computers, free coins fifa 14 hack and bird keeping. Finds a good amount of encouragement from life by likely to places for example Joggins Fossil Cliffs.<br><br>Here is my web blog: free fifa 14 Coins no hack; [https://youtube.com/watch?v=HSoNAvTIeEc Youtube.com],
{{unreferenced|date=August 2009}}
 
In [[computer program]]s, an important form of [[control flow]] is the ''loop''. For example, this small [[pseudo-code]] program uses two nested loops to [[iterate]] over all the entries of an ''n''&times;''n'' [[matrix (mathematics)|matrix]], changing their values so that the matrix becomes an [[identity matrix]]:
 
for a in 1..n
    for b in 1..n
        if a = b
            M[a,b] := 1
        else
            M[a,b] := 0
 
However, note that the comparison <tt>a = b</tt> is made <math>n^2</math> times, which is a lot if <math>n</math> is large. We can do better:
 
for a in 1..n
    for b in 1..n
        M[a,b] := 0
    M[a,a] := 1
 
At a first glance, one might think that the second variant of the algorithm is slower than the first, since it changes the value of some of the entries twice. But the number of extra changes is only <math>n</math>, and the number of comparisons that don't have to be done is <math>n^2</math>; clearly, for large enough values of <math>n</math>, the second algorithm will be faster no matter the relative cost of comparisons and [[assignment (computer science)|assignments]], since we do less work in the innermost loop.
 
Here's a second example:
 
for a in 1..10000
    do_something_A
    for b in 1..10000
        do_something_B
 
Assume that <tt>do_something_A</tt> takes 100 μs to run, and <tt>do_something_B</tt> takes 1 μs. The entire program then takes <math>10000*100</math> μs <math>+ 10000^2*1</math> μs <math>= 101</math> s. We will spend one day optimizing this program, and during that day we can either make <tt>do_something_A</tt> 50 times faster, or <tt>do_something_B</tt> 10% faster. Which should we choose? Well, the first option will bring down the total execution time to <math>10000*2</math> μs <math>+ 10000^2*1</math> μs <math>= 100.02</math> s, and the second option will make it <math>10000*100</math> μs <math>+ 10000^2*0.9</math> μs <math>= 91</math> s &ndash; clearly, optimizing the innermost loop is the better choice. But what if we could make <tt>do_something_A</tt> 500 times faster? Or 5000? The answer is still the same, because of those initial 101 seconds, 100 seconds are spent in <tt>do_something_B</tt>, and just one second in <tt>do_something_A</tt>. Even if we could make <tt>do_something_A</tt> take no time at all, making <tt>do_something_B</tt> 10% faster would still be the better choice!
 
So: since almost all the program's time is spent in the innermost loops, optimizations there will have a big effect on the total time it takes to run the program. In contrast, optimizing anything ''but'' the innermost loops is often a waste of the programmer's time since it speeds up a part of the program that never did take much time.
 
[[Category:Control flow]]
[[Category:Software optimization]]

Latest revision as of 07:03, 22 November 2014

35 years old Fashion Designer Gerry Goar from Sept-Iles, usually spends time with interests like computers, free coins fifa 14 hack and bird keeping. Finds a good amount of encouragement from life by likely to places for example Joggins Fossil Cliffs.

Here is my web blog: free fifa 14 Coins no hack; Youtube.com,