Caching F# using Memoization

In bioinformatics (dynamic programming algorithms) and molecular modelling (large amount of states/molecule collisions to be calculated), it is handy to be able to speed this up by not repeating computationally heavy calculations. Molecular modelling currently takes far to long to simulate folding even a small peptide (see protein folding).
Functional languages such as F# can be optimized by remembering a functions result given some input. The application will effectively get “smarter and quicker” as it builds up a database of results.

let add a b =
//check if this function with
//same inputs has been run
set value = lookUpValue a b
if value = false then
//compute function
a + b
else
//return cache version
value

Obviously these functions need to be quite long processing (at least 2x the time for a lookup). A large amount of space is required to store all the data as this will grow quite quickly as the data store builds up (the system will also get quicker and quicker during this time).

Leave a comment