How to resolve the algorithm Padovan sequence step by step in the Mathematica / Wolfram Language programming language
Published on 22 June 2024 08:30 PM
How to resolve the algorithm Padovan sequence step by step in the Mathematica / Wolfram Language programming language
Table of Contents
Problem Statement
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Show output here, on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Padovan sequence step by step in the Mathematica / Wolfram Language programming language
Explanation:
The Wolfram code you provided defines two functions: Padovan1
and Padovan2
, which generate the Padoban sequence. The Padoban sequence is a sequence of natural numbers defined by the recurrence relation:
P(n) = P(n-2) + P(n-3)
with initial values P(0) = 1
, P(1) = 1
, and P(2) = 1
.
Function Padovan1
:
- Defines a recurrence table for the sequence
a[n]
, wherea[n]
represents the n-th term of the Padoban sequence. - The recurrence relation is defined as
a[n+1] == a[n-1] + a[n-2]
, with initial valuesa[0] == 1
,a[1] == 1
, anda[2] == 1
. - The function generates the Padoban sequence up to the specified maximum index
nmax
.
Function Padovan2
:
- Involves two constants:
p
ands
. p
is an irrational number defined as the sum of the cube roots of ((9+Sqrt[69])/18) and ((9-Sqrt[69])/18).s
is another irrational number with a specific value.- The function calculates the terms of the Padoban sequence using the following formula:
Floor[p^Range[-1,nmax-2]/s+1/2]
.
Example Usage:
- The code generates the first 20 terms of the Padoban sequence using both
Padovan1
andPadovan2
functions and verifies that they produce identical results. - It also demonstrates the use of
SubstitutionSystem
, which is analogous to the Fibonacci sequence. The result of applying the substitution system to "A" for 31 iterations matches the terms of the Padoban sequence generated byPadovan2
.
Source code in the wolfram programming language
ClearAll[Padovan1,a,p,s]
p=N[Surd[((9+Sqrt[69])/18),3]+Surd[((9-Sqrt[69])/18),3],200];
s=1.0453567932525329623;
Padovan1[nmax_Integer]:=RecurrenceTable[{a[n+1]==a[n-1]+a[n-2],a[0]==1,a[1]==1,a[2]==1},a,{n,0,nmax-1}]
Padovan2[nmax_Integer]:=With[{},Floor[p^Range[-1,nmax-2]/s+1/2]]
Padovan1[20]
Padovan2[20]
Padovan1[64]===Padovan2[64]
SubstitutionSystem[{"A"->"B","B"->"C","C"->"AB"},"A",10]//Column
(StringLength/@SubstitutionSystem[{"A"->"B","B"->"C","C"->"AB"},"A",31])==Padovan2[32]
You may also check:How to resolve the algorithm Create an object at a given address step by step in the Tcl programming language
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the R programming language
You may also check:How to resolve the algorithm Set step by step in the Perl programming language
You may also check:How to resolve the algorithm Sorting algorithms/Permutation sort step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm MD5/Implementation step by step in the Phix programming language