Improved PostgreSQL Mathematics Support.

From: A Z <poweruserm(at)live(dot)com(dot)au>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Improved PostgreSQL Mathematics Support.
Date: 2021-09-19 05:42:32
Message-ID: PSXP216MB0085F21467C36F05AB9427879ADF9@PSXP216MB0085.KORP216.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I have been trying to get a reply or interest in either updating
PostgreSQL to support the following, or for there to be a public,
free for any use Extension put out there, that will support the following:

############################################################
# High Precision Numeric and Elementary Functions Support. #
############################################################

-Integer (HPZ) Z, or Rational Decimal Q (HPQ) numbers support.

-Recurring Rational Numbers and recurring Irrational Numbers can be appropriately
truncated, by a precision value, to obtain an approximating value. The latter
phenomenon is a finite Rational value, possibly with integer and/or decimal parts at the
same time. These may be positive or negative, standard number line, values.

-Forward and Inverse operations accuracy, withstanding truncation,
can be maintained by storing and normalising the expression behind a value,
(or just include pointers to the value) and displaying the evaluation.
This system will uphold any precision.

-A defaulting number of significant figures (precision), in one copy of one field
in memory that is held in there, as a filter, for all HPZ and HPQ numbers.
For example, 20 significant figures, as a default, to start by.

-A function that varies the precision filter for every HPZ and HPQ number at once.

-Value assignment to a typed variable by =.

-Base 10 Arithmetic and comparisons support on Base 10 Integer and Rational Decimal numbers.
+,-,*,/,%,^,=,!=,<>,>,<,>=,<=, ::
These include full finite division and integer only division, with no remainder.
The defaulting ability of numbers data in lower types to automatically be casted
up to HPZ or HPQ, where specified and occuring in PostgreSQL code.

-Reified support with broader syntax and operations within PostgreSQL, in all the obvious
and less than obvious places. Tables and related phenomena, Indexing, the Window type,
Record type, direct compatability with Aggregate and Window Functions, the Recursive keyword,
are all parts of a larger subset that may re-interact with HPZ or HPQ.

#############################################################################################

-Mathematical and Operational functions support:

precision(BIGINT input)

cast(TEXT as HPZ) returns HPZ;
cast(TEXT as HPQ) returns HPQ;
cast(HPQ as TEXT) returns TEXT;
cast(HPZ as TEXT) returns TEXT;
cast(HPZ as HPQ) returns HPQ;
cast(HPQ as HPZ) returns HPZ;
cast(HPZ as SMALLINT) returns SMALLINT;
cast(SMALLINT as HPQ) returns HPZ;
cast(HPZ as INTEGER) returns INTEGER;
cast(INTEGER as HPZ) returns HPZ;
cast(HPZ as BIGINT) returns BIGINT;
cast(BIGINT as HPZ) returns HPZ;
cast(HPQ as REAL) returns REAL;
cast(REAL as HPQ) returns HPQ
cast(DOUBLE PRECISION as HPQ) returns HPQ;
cast(HPQ as DOUBLE PRECISION) returns DOUBLE PRECISION;
cast(HPQ as DECIMAL) returns DECIMAL;
cast(DECIMAL as HPQ) returns HPQ;

sign(HPQ input) returns HPQ;
abs(HPQ input) returns HPQ;
ceil(HPQ input) returns HPQ;
floor(HPQ input) returns HPQ;
round(HPQ input) returns HPZ;
pi() returns HPQ;
e() returns HPQ;
power(HPQ base, HPQ exponent) returns HPQ;
sqrt(HPQ input) returns HPQ
nroot(HPZ theroot, HPQ input) returns HPQ;
log10(HPQ input) returns HPQ;
loge(HPQ input) returns HPQ;
log2(HPQ input) returns HPQ;
factorial(HPZ input) returns HPZ;
nCr(HPZ objects, HPZ selectionSize) returns HPZ
nPr(HPZ objects, HPZ selectionSize) returns HPZ

degrees(HPQ input) returns HPQ;
radians(HPQ input) returns HPQ;
sind(HPQ input) returns HPQ;
cosd(HPQ input) returns HPQ;
tand(HPQ input) returns HPQ;
asind(HPQ input) returns HPQ;
acosd(HPQ input) returns HPQ;
atand(HPQ input) returns HPQ;
sinr(HPQ input) returns HPQ;
cosr(HPQ input) returns HPQ;
tanr(HPQ input) returns HPQ;
asinr(HPQ input) returns HPQ;
acosr(HPQ input) returns HPQ;
atanr(HPQ input) returns HPQ;

##########################################################################################

-Informative articles on all these things exist at:
Comparison Operators: https://en.wikipedia.org/wiki/Relational_operator
Floor and Ceiling Functions: https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Arithmetic Operations: https://en.wikipedia.org/wiki/Arithmetic
Integer Division: https://en.wikipedia.org/wiki/Division_(mathematics)#Of_integers
Modulus Operation: https://en.wikipedia.org/wiki/Modulo_operation
Rounding (Commercial Rounding): https://en.wikipedia.org/wiki/Rounding
Factorial Operation: https://en.wikipedia.org/wiki/Factorial
Degrees: https://en.wikipedia.org/wiki/Degree_(angle)
Radians: https://en.wikipedia.org/wiki/Radian
Elementary Functions: https://en.wikipedia.org/wiki/Elementary_function

-Ease of installation support. Particularly for Windows and Linux. *.exe, *.msi or *.rpm, *.deb, *.bin installers.
With a PostgreSQL standard installation. Installation and Activation instructions included.

The following chart could be used to help test trigonometry outputs, under
Further Condsideration of the Unit Circle:
https://courses.lumenlearning.com/boundless-algebra/chapter/trigonometric-functions-and-the-unit-circle/
#############################################################################################

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2021-09-19 05:46:49 Re: Logical replication keepalive flood
Previous Message Amit Kapila 2021-09-19 05:14:46 Re: POC: Cleaning up orphaned files using undo logs