Hi!
I would like to share some interesting programs related to the number theory. Here I am posting a Oracle PL/SQL program to generate the Catalan Series. This procedure takes an input parameter IN_UPPER_BOUND. This denotes the 'n' th term of the Catalan Series, where n is a integer number. By default, the lower bound is taken as 1.
I would like to share some interesting programs related to the number theory. Here I am posting a Oracle PL/SQL program to generate the Catalan Series. This procedure takes an input parameter IN_UPPER_BOUND. This denotes the 'n' th term of the Catalan Series, where n is a integer number. By default, the lower bound is taken as 1.
Briefly, Catalan Series is defined as follows "A sequence of natural numbers which are named after the Beligian mathematician Eugène Charles Catalan".
Please follow the following link: http://en.wikipedia.org/wiki/Catalan_number for more information about the Catalan series.
Source Code:
CREATE OR REPLACE PROCEDURE GENERATE_CATALAN_SERIES(IN_UPPER_BOUND IN NUMBER) IS
lvCatalanSeries VARCHAR2(32767):=NULL;
FUNCTION CATALAN(IN_NUMBER IN NUMBER) RETURN NUMBER IS
lnCatalan NUMBER:=0;
lnCatalanBound NUMBER:=0;
BEGIN
IF IN_NUMBER=0 OR IN_NUMBER=1 THEN
lnCatalan:=1;
ELSE
lnCatalanBound:=IN_NUMBER-1;
lnCatalan:= ((((lnCatalanBound*2)+1)*2)/(lnCatalanBound+2)) * CATALAN(lnCatalanBound);
IF TO_NUMBER(SUBSTR(TO_CHAR(lnCatalan),INSTR(TO_CHAR(lnCatalan),'.')+1,LENGTH(TO_CHAR(lnCatalan)))) > 50 THEN
lnCatalan:=CEIL(lnCatalan);
ELSE
lnCatalan:=FLOOR(lnCatalan);
END IF;
END IF;
RETURN lnCatalan;
END CATALAN;
BEGIN
FOR i IN 0..IN_UPPER_BOUND LOOP
IF lvCatalanSeries IS NULL THEN
lvCatalanSeries:=CATALAN(I);
ELSE
lvCatalanSeries:=lvCatalanSeries'->' CATALAN(I);
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Catalan Series upto 'IN_UPPER_BOUND' is : 'CHR(10)lvCatalanSeries);
END GENERATE_CATALAN_SERIES;
Here the function CATALAN is a recursive function.