Recently in Basic Functions Category

The After Strife

As well as required arithmetic operations, such as addition, subtraction, multiplication and division, the IEEE 754 floating point standard has a number of recommended functions. For example finite determines whether its argument is neither infinite nor NaN and isnan determines whether its argument is NaN; behaviours that shouldn't be particularly surprising since they're more or less equivalent to JavaScript's isFinite and isNaN functions respectively.
One recommended function that JavaScript does not provide, and which I should like to add to the ak library, is nextafter which returns the first representable floating point number after its first argument in the direction towards its second.

Full text...  

Let's Talk About Sets

In the last couple of posts we have seen various ways to partially or fully sort data and the kinds of queries that we can run against them once they have been. Such query operations make fully sorted arrays a convenient way to represent sets, or more accurately multisets which treat repeated elements as distinct from each other, and in this post we shall exploit this fact to implement some operations that we might wish to perform upon them.

Full text...  

I Still Haven't Found What I'm Looking For

Last time we took a look at a selection of sorting operations that we can use to sort arrays, or ranges of elements within them. After defining some useful comparison functions satisfying JavaScript's requirement of returning a negative number when the first argument compares smaller than the second, zero when they compare equal and a positive number otherwise, and a function to map negative integers to indices read from the end of arrays in the same way that Array.slice does, we first implemented ak.partition which divides elements into two ranges; those elements that satisfy some given condition followed by those elements that don't. We saw how this could be used to implement the quicksort algorithm but instead defined ak.sort to sort a range of elements using Array.sort, slicing them out beforehand and splicing them back in again afterwards if they didn't represent whole arrays. We did use it, however, to implement ak.nthElement which puts a the correctly sorted element in a given position position within a range, putting before it elements that are no greater and after it elements that are no smaller. Finally, we implemented ak.partialSort which puts every element in a range up to, but not including, a given position into its correctly sorted place with all of the elements from that position onwards comparing no less than the last correctly sorted element.
This time we shall take a look at some of the ways that we can query data after we have manipulated it with these functions.

Full text...  

We're All Sorted From A To Z

Something that I miss when programming in JavaScript is the wide variety of array manipulation functions available in my primary language, C++. We have, in fact, already implemented one of them with ak.shuffle which randomly rearranges the elements of an array. We shall be needing another one of them in the not too distant future and so I have decided to take a short break from numerical computing to add those of them that I use the most frequently to the ak library, starting with a selection of sorting operations.

Full text...  

A Few Sequences More

In the last few posts we took a look at sequences and series, from the arithmetic and geometric to the Fibonacci, defined by the rules

  s0 = 0
  s1 = 1
  sn = sn-1 + sn-2

At the risk of being tedious, there are two more sequences that I'd like to cover before we move on to a new topic.

Full text...  

The Fibonacci Code

Last time we took a first look into the implementation of sequences and series, being ordered lists of terms defined by their positions and the partial sums of those terms respectively.
Whilst the implementations of arithmetic and geometric sequences and their associated series were somewhat subtle, they're not particularly interesting from a mathematical perspective and so this time we'll take a look at something a little more complicated.

Full text...  

A Sequence Of Predictable Events

With our various pseudo random number generators we have sought to create sequences of numbers that come as close as possible to having all of the properties of truly random variables, despite being entirely deterministic.
Now this behaviour is somewhat atypical, in the sense that most sequences that we bother to name have values that are self-evidently deterministic.

Full text...