home.social

#continuedfractions β€” Public Fediverse posts

Live and recent posts from across the Fediverse tagged #continuedfractions, aggregated by home.social.

  1. In (canonical, simple) Continued Fraction (CFs) representation, every real number is a list starting with an integer π‘Žβ‚€ and followed by some number (possibly none) of positive integers [π‘Žβ‚, π‘Žβ‚‚, ...]. In strictly typed programming languages, this is essentially a non-empty list; for example, in Haskell, one can use Data.List.NonEmpty and the CF becomes (π‘Žβ‚€ :| [π‘Žβ‚, π‘Žβ‚‚, ...]) = (π‘Žβ‚€ :| tail).

    Haskell's strict typing enforces the non-empty aspect of CFs. The CF list must be non-empty, so we can think of it as a head (the π‘Žβ‚€ term) and a (possibly empty) tail (the [π‘Žβ‚, π‘Žβ‚‚, ...] terms). If the tail is empty, then the number is an integer. So the natural numbers 0, 1, 2, ... become (0 :| []), (1 :| []), (2 :| []) and so on in CF representation.

    Now, taking reciprocal in CF representation involves either removing π‘Žβ‚€ if it is 0, or prepending 0 to the whole list. Focusing on the first case, if π‘Žβ‚€ is 0, then we remove that from the list and keep only the tail terms. This step combined with strict typing shows why there is no reciprocal of 0.

    If we start with (0 :| []), remove 0 and only keep the tail then we are left with just the empty list []. However, every real number corresponds to a non-empty list and CFs don't allow empty lists.

    Therefore the reciprocal of 0 is not a real number.

    #math #ContinuedFractions #type #theory #haskell #FunctionalPrograming

  2. CW: Rosetta Code

    I translated, from #Mercury to #Haskell, the #ContinuedFractions #RosettaCode draft task:

    Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2) - Rosetta Code rosettacode.org/wiki/Continued

    I have decided there isn’t a single thing I like about Haskell syntax. I do not care how one writes a thing, I hate it. There is no reason whatsoever for Haskell not to have had a more ML-like syntax. None whatsoever, except to encourage breakage.

  3. CW: Rosetta Code

    An implementation of the #RosettaCode #ContinuedFractions arithmetic draft task, in #Mercury, based very loosely on the #StandardML (that is based on the #Scheme and the #Python:

    Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2) - Rosetta Code rosettacode.org/wiki/Continued

    The implementation uses #LazyLists to represent continued fractions.

  4. CW: Rosetta Code

    I have now done the #RosettaCode #ContinuedFractions arithmetic draft task in #Ada --

    Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2) - Rosetta Code rosettacode.org/wiki/Continued

    I credit my own Python implementation as the original, although the Ada is quite different. Interestingly, I use β€˜inheritance’ in the Ada but not in the Python! One might ask why ...

    #adalang

  5. CW: Rosetta Code

    This took a few days of overwork and obsessive overexcitement to write. A #Fortran port of my #RosettaCode for #ContinuedFractions, including a primitive #MultiplePrecision module:

    Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2) - Rosetta Code rosettacode.org/wiki/Continued

    Part of the problem, as I have mentioned before, is that gfortran is not especially helpful in tracking down bugs. But I see gdb has gotten better with Fortran.

  6. @[email protected] (gdaymath.com/) writes (twitter.com/jamestanton/status):
    β€œIt is impossible to draw an equilateral triangle on a square lattice of dots with each vertex on a dot. (Why?) But can we get close?

    Is it possible to have two vertices on a dot and the third within 0.00000001 units from a dot?

    (The picture is not equilateral.)”

    #geometry #math #ContinuedFractions #ApproximateInteger #PicksTheorem

  7. Last few nights I've been working on another mental calculation. In this episode of #CountingSheep, I bring you #PellsEquation and #ContinuedFractions.