Recursion Induction Duality

Posted on October 1, 2019
Tags: induction

Recursion is informally the Computational Dual of Induction.
Induction tells us some chain of increasing P(n) is true.
Recursion uses that knowledge of induction to safely climb down that chain of truths to the base case.
-me

Induction comes from your thoughts and algorithm design.
Recursion comes from the code being executed.

def identity(k):
    if k == 0:
        return 0
    if k == 1:
        return 1
    else:
        return 1+identity(k-1)

Induction can be thought as a meta-level confirmation that computable recursion will work.


0.0.1 Diagrams

The lifelines of the Sequence diagram(the rectangular boxes) stacked on each other indicates a recursive function.
We can take advantage of this stacking behavior to implement recursion using stacks.

1 examples

Below is the associated code for this structure.

flowchart TD o[Start] --> A1["A"] o[Start] --> B1["B"] A1 --> A2["A"] A1 --> B2["B"] A2 --> A3["A"] A2 --> B3["B"] A3 --> An[".."]
let x = "aababa"

const fun = (input) => {
    if(input.length != 0){
        let consumed = input[0]
        let rest = input.slice(1)
        if(consumed == 'b' && input.length == 1){
            return true 
        }else if(consumed == 'b' && input.length != 1){
            return false
        }else if(consumed == 'a'){
            return true && fun(rest)
        }
        else{
            return false
        }
    }else{
        return true
    }
}

console.log(fun(x));