Zulip Chat Archive

Stream: new members

Topic: mutual recursion vs pairs


Horatiu Cheval (Mar 08 2021 at 08:11):

Is mutual recursion more expressive than defining single pair-valued functions? For instance, I can redefine this:

mutual def f, g
with f :   
| 0 := 1
| (n + 1) := n + g n
with g :   
| 0 := 0
| (n + 1) := n * f n

as this:

def h :    × 
| 0 := (1, 0)
| (n + 1) := (n + (h n).snd, n * (h n).fst)

Are there situations when such a translation would not be possible? Or maybe mutual is actually syntactic sugar for the second form?

Alistair Tucker (Mar 08 2021 at 09:50):

I believe your mutual def is syntactic sugar for something like

def fg : bool    
| tt 0       := 1
| tt (n + 1) := n + fg ff n
| ff 0       := 0
| ff (n + 1) := n * fg tt n

Last updated: Dec 20 2023 at 11:08 UTC