[Tutor] Lotka-Volterra Model Simulation Questions

Alan Gauld alan.gauld at btinternet.com
Mon Oct 1 01:24:24 CEST 2012

On 30/09/12 11:50, Oscar Benjamin wrote:

>>>         ...I'm sure that the equations you're refering to would have
>>>         already been using lots of symbols
>>     Yes which made them even more difficult to understand.
> Quantum mechanics is hard for anyone. I don't think that an alternative
> notation will make it any easier for people in the business of
> learning/teaching/using quantum mechanics

Possibly (although see below), but I'm not arguing for changing the 
notation where a standard exists but where the standard is not known.
In the original post I suggested renaming the variables precisely 
because I did not know the standard equation and would understand the 
algorithm better if the variables had meaningful names. Someone who knew 
the equation had no need of such because they did the translation 
mentally using prior knowledge.

> think that it is possible to find a notation that will make quantum
> mechanics intelligible to a layperson:

It doesn't need to be intelligible to a lay person but QM is made up of 
different communities: researchers, academics, practitioners, consumers 
etc. I am a consumer of QM and used it in my work even though I could 
not have derived the equations from scratch. But I understood them once 
they were explained to me. But to really use them I had to go and 
rewrite them as pseudo code functions (momentum_of_electon_shell(), 
energy_of_photon() etc) Now, a pure physicist or mathematician would, 
I'm sure, have found many faults in my translation but I had to do that 
to understand the concepts for my own benefit.

But the mathematician/physicist in writing those same functions would 
probably have used the technical terms and the code would have looked a 
lot like the equations... but for me I had to translate the math 'code'
into quantities I understood - and yes that included 'h' for Plank's 
constant because that one I already knew, so I freely admit it is all 

>      > Now imagine replacing each of those single letter symbols
>      > with English underscore-separated words so instead of letter
>      > capital psi you would have 'time_dependent_wave_function'
>      > and instead of hbar you would have 'planks_constant_over_twopi'
>      > and so on. Your equation would go from three lines to thirty

But this is where it gets interesting. One of the first programming jobs 
I had after university was working in a team who industrialised the code 
coming out of our research labs. Most of that work was taking domain 
specific code written in Fortran, Basic or Forth and translating it into 
C or Pascal (this was in the 80's...). We never used the pure math forms 
given us by the researchers but translated it into much more verbose 
"laymans" code (with the help of the researcher) because we knew that we 
would have to maintain it not the eggheads. We couldn't become domain 
experts in all of the fields we serviced so we had to make the research 
code readable and maintainable by general purpose programmers.

> While I can write a script like the OP's in less than 5 minutes, in
> practise it takes longer to convince myself that the code is correct (if
> it is important for it to be so). I spend most of the time when
> developing such a script simply looking at the code and comparing it
> with the mathematical problem I was trying to solve.

Which is great if you understand the problem domain and the math 
involved. If you don't you have to rely on getting the algorithm from 
the experts and then translating it into something you can work with 
after the expert has moved on.

> code diverges from the original problem statement the harder it becomes
> to really convince yourself that the code is correct. Renaming all of
> your variables (any more than you need to) so that cross-referencing
> always requires a mental table would be a waste of time and would
> increase the likelihood of bugs.

But for the non domain expert the mental table occurs when the technical 
term is used. technical jargon in math as elsewhere is still jargon and 
as such only understandable to the select few with the inside knowledge. 
So while code is restricted to that closed community technical jargon is 
fine. If it must be shared with a non technical audience then decisions 
need to be taken, either to provide the mapping in 
documentation/comments or to provide non technical names.

> In any case I guess you won't be pleased by my discovery that, thanks to
> PEP 3131, the following is valid code in Python 3 (I've attached the
> code in case it doesn't display properly):

Not at all, I'd rather see real Greek characters being used than 
Anglicised spellings (especially many variants of same!). As I
say, where a generally understood symbology exists it makes sense to use 
it. (A good example is in the use of complex numbers. These are not 
generally understood outside the math/science fraternity but they are 
nigh essential within that community. To try to reinvent the symbology 
there would be foolish) It is only where the code must spill out to non 
cognisant users that care needs to be taken.

> # Lotka-Volterra derivative
> def f(Z, t):

Although I would argue that 'f' is still a rotten name
for any function!

def lotka_volterra(Z,t):

might be better. :-)

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list