7 kyu

Two definitions of Fibonacci words

31 of 68lambda-fairy

Description:

A Fibonacci word is a string of binary digits that follows specific rules.

The rules are:

  • The first Fibonacci word S0=0 S_0 = 0 .
  • Each subsequent word is computed by mapping each symbol with ϕ \phi , where:
    ϕ(0)=01ϕ(1)=0\phi(0) = 01 \\ \phi(1) = 0

Here are the first few Fibonacci words:

S0=0S1=01S2=010S3=01001S4=01001010S5=0100101001001S_0 = 0 \\ S_1 = 01 \\ S_2 = 010 \\ S_3 = 01001 \\ S_4 = 01001010 \\ S_5 = 0100101001001

An interesting fact – which gives us the name "Fibonacci word" – is that each word is the concatenation of the previous two:

Sn+2=Sn+1Sn .S_{n+2} = S_{n+1}S_{n}\ .

Prove that this is the case.

A note about Lean

In Lean, the symbols 0 and 1 are represented by ff and tt respectively.

Preloaded

import data.list
import data.stream.defs

def phi : bool  list bool
| ff := [ff, tt]
| tt := [ff]

def fword_aux (s : list bool) := list.bind s phi

def fword : list bool := stream.iterate fword_aux [ff]

def SUBMISSION :=  n, fword (n + 2) = fword (n + 1) ++ fword n
From Coq Require Import Lists.List.
Import ListNotations.

Definition phi (b : bool) : list bool :=
  match b with
  | false => [false; true]
  | true => [false]
  end.

Definition fword_aux (l : list bool) : list bool :=
  flat_map phi l.

Definition fword (n : nat) : list bool :=
  Nat.iter n fword_aux [false].
Theorem Proving
Fundamentals

Stats:

CreatedApr 30, 2020
PublishedMay 1, 2020
Warriors Trained251
Total Skips17
Total Code Submissions91
Total Times Completed68
Lean Completions31
Coq Completions42
Total Stars7
% of votes with a positive feedback rating96% of 12
Total "Very Satisfied" Votes11
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • lambda-fairy Avatar
  • donaldsebleung Avatar
  • Madjosz Avatar
  • monadius Avatar
Ad