r/ProgrammingLanguages • u/revannld • 1d ago
Discussion Compact notational/numeral-system-like representations for polynomials, series, simple programs and iterating terms?
Good evening!
Recently I've stumbled onto the notation [a; b, c, d, e...] for continued fractions "a + 1/(b + 1/(c + 1/...)..)". I have a gut feeling this can be a very useful representation and maybe some clever algebra may be defined over it, turning it effectively into an alternative "numeral-like" system.
I tried searching for such similar compact representations for other finitely and infinitely iterating terms/series in mathematics as well as normal forms for them and rewriting algorithms but I've didn't manage to find anything.
There are series that, if you abstract away the concrete operations and base sets/algebras, seem to have a very similar structure throughout analysis; they almost feel like a very definite class of programs. That would feel amenable for a more abstract characterization in category theory but I've never seen that.
From my intuition most of these series seem to rely a bit on fold), maybe streams, initial algebras and other structures commonly studied in functional programming, but if any of you have other ideas to suggest, I would appreciate :))
I wish everyone a great weekend!
4
u/reflexive-polytope 1d ago edited 21h ago
If you fix a monomial order, then you can represent a polynomial as the list of its nonzero terms, listed according to the monomial order.
If your language has first-class procedures, then you can represent a power series as a procedure that maps monomials to the respective coefficients. But, if you're doing computer algebra, then chances are you don't want to work with completely arbitrary power series. I'm sure there has to be a power series representation that's more convenient for manipulating, say, hypergeometric functions, even if it comes at the expense of representing all power series.
EDIT: (One day later) The class of holonomic functions contains all hypergeometric functions and has good properties for computer algebra.
3
u/pauseless 1d ago
Not sure if I misunderstood, but here is an example in APL
{⍺+÷⍵}\3 7 15 1 292
3 3.142857143 3.141509434 3.14159292 3.141592653
/ will just get the final value.
2
u/categorical-girl 22h ago
You might find Generalized hypergeometric functions interesting. They are sums over a series where the ratios a_n/a_(n+1) between successive terms is a rational function of n. There is some connection to finding closed forms of certain sums (see eg A=B by Wilf and Zeilberger).
There are some general results for general sums, products, continued fractions, etc, when viewed as infinite compositions of functions.
Continued fractions connect to the theory of the Farey sequence and Stern-Brocot/Calkin-Wilf trees
By the way, I'm not sure if you are already familiar with the idea of generating functions or the Z-transform, but those are based around representing a sequence of numbers as a function (and one can typically go the other way too). I'm not sure if you are interested in ways to represent numbers, sequences of numbers, or functions, or all three.
1
u/TreborHuang 1d ago
You may be interested in the list of references here: https://wiki.haskell.org/index.php?title=Exact_real_arithmetic . Exact real arithmetic studies how computers can represent real numbers without the fear of accumulating rounding errors (or to put it another way, to automatically manage rounding errors). Continued fraction is one way of doing this.
1
u/WittyStick 1d ago edited 17h ago
Cauchy sequences are sometimes used for this purpose.
A recent development which is really interesting is EML, or exp-minus-log. All numbers and basic functions can be expressed as a binary tree - a bit like S-expressions where you have just null or a cons cell
For EML you just have the constant 1 and the binary function eml.
You can nest these trees arbitrarily to denote a mathematical expression, and compute its result using just
exp(),log(), and subtraction. You shouldn't need to use these for every branch of the tree though - because any sub-tree which is known to represent a certain expression can be replaced with that expression. The problem becomes one of pattern matching over trees.That obviously needs more research before it could be usable, but I can show a demo of it when I get home if you'd like to see a bit more.