HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

Can we create recursive functions only by using if-else statements?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
cancreateelsestatementsrecursiveusingfunctionsonly

Problem

I have to show whether a program containing only if-else statements but no loops is able to calculate the following type of functions: $f^n(x)$. The function $f$ is applied $n$ times to $x$, so I guess this is a recursive function.

How can I prove that formally?

Solution

If a program doesn't include any loop, recursion or equivalent construct, then it cannot express recursive computations.

In order to write a formal proof, you'd need to define your language formally. “Equivalent construct” can include some exotic things such as parallel execution, exception handlers, higher-order functions (leading to fixpoint combinators), meta-execution facilities (eval), etc. that let recursion in through a backdoor.

Suppose that a language contains only the following constructs: constants, assignments, sequence (do a then do b), functions operating on base types (but not functions taking functions as arguments), conditionals (if (x == y)), some primitives on base types (e.g. +, *). Then the execution of the program takes a time that is at most exponential, and in particular bounded, in the size of the program (the unit of time is an elementary expression, e.g. x := y takes one unit, x := y + z takes two units). In a nutshell, function application at most multiplies the complexity of the function by the complexity of the program, and the rest is linear.

Since this language can only express bounded-time computations, it cannot express all recursive programs (and in fact it cannot even express all primitive recursive programs).

Context

StackExchange Computer Science Q#12772, answer score: 5

Revisions (0)

No revisions yet.