How to resolve the algorithm Farey sequence step by step in the Maxima programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Farey sequence step by step in the Maxima programming language
Table of Contents
Problem Statement
The Farey sequence Fn of order n is the sequence of completely reduced fractions between 0 and 1 which, when in lowest terms, have denominators less than or equal to n, arranged in order of increasing size. The Farey sequence is sometimes incorrectly called a Farey series.
Each Farey sequence:
The Farey sequences of orders 1 to 5 are:
The length (the number of fractions) of a Farey sequence asymptotically approaches:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Farey sequence step by step in the Maxima programming language
Source code in the maxima programming language
farey(n):=if n=1 then ["0/1","1/1"] else block(
create_list([i,j],i,0,n-1,j,1,n),
map(lambda([x],if x[1]=0 and x[2]#1 then false else if x[1]=x[2] and x[1]#1 then false else if x[1]<=x[2] then x),%%),
delete(false,%%),
unique(map(lambda([x],x[1]/x[2]),%%)),
append(rest(append(["0/1"],rest(%%)),-1),["1/1"])
)$
/* Test cases */
/* Sequences from order 1 through 11 */
farey(1);
farey(2);
farey(3);
farey(4);
farey(5);
farey(6);
farey(7);
farey(8);
farey(9);
farey(10);
farey(11);
/* Length of sequences from order 100 through, 1000 by hundreds */
length(farey(100));
length(farey(200));
length(farey(300));
length(farey(400));
length(farey(500));
length(farey(600));
length(farey(700));
length(farey(800));
length(farey(900));
length(farey(1000));
You may also check:How to resolve the algorithm Guess the number/With feedback (player) step by step in the Objective-C programming language
You may also check:How to resolve the algorithm Sudoku step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the Lua programming language
You may also check:How to resolve the algorithm Synchronous concurrency step by step in the C programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Brainf*** programming language