Search code examples
mathfunctional-programminglambda-calculusmarkov-chainsmarkov

Are Functional Programming & Markov Chains related somehow?


David Silver describes a property of Markov Chains as:

The future is independent of the past given the present

https://www.youtube.com/watch?v=lfHX2hHRMVQ (4 mins into video)

This struck a chord with me because I am currently learning about functional programming(FP).

In FP you can also ignore the past because your functions only need the current state in order to perform some action and output a new state. THis isn't necessarily true with Object Oriented because your output might depend on several states in different places.

Is there some deeper connection between FP and Markov chains that I am unaware of?

Is it accurate to say, for example, that functions written in FP are deterministic Markov chains?


Solution

  • There is indeed a connection between a Markov chain and Functional Programming. A Markov chain is a type of a non-deterministic Finite-State Machine (FSM), whereas chaining pure functions would produce a deterministic FSM. The caveat here is that in the real-world (e.g., Web applications) you often need also functions that are not pure (e.g., modify or query an external database).

    I have found it very useful to model program state as a Finite-State Machine (FSM), both as a metaphor and as a concrete way to model states and transitions. For example, a FSM represents nicely which actions are allowed at which state when implementing (Web) user interfaces.