2

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?

COOLBEANS
  • 729
  • 3
  • 13
  • 31
  • 1
    You may simply be thinking about state machines (AKA finite automata). – Oliver Charlesworth Jun 05 '17 at 20:50
  • 2
    "different places" != "the past". Also in OOP the future state will only depend on the current state, not on previous actions. It's a fundamental property of time, which makes makes Markov Chains suitable for modelling that. It has nothing to do with FP except that both are closely related to Maths. – Bergi Jun 05 '17 at 21:18
  • Since Markov died in 1922, I'd say that his thoughts about Markov chains didn't include functional programming. – duffymo Jun 06 '17 at 09:02

1 Answers1

4

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.

Toni Vanhala
  • 1,352
  • 6
  • 16
  • Excellent - I like the idea of viewing pure functional programs as deterministic FSM's. And i think it's very cool that merely adding some stochasticity to an FSM gives a Markov Chain which seems at first completely unrelated to functional programming. – COOLBEANS Jun 07 '17 at 18:42