ArticleslgStudy

mathematics

K (programming language)

K (programming language) is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand K (programming language) rather than just read about it. In short: K is a proprietary array processing programming language developed by Arthur Whitney and commercialized by KX Systems. The language serves as the foundation for kdb+, an in-memory, column-based database, and other related financial products.

Key takeaways

  • K (programming language) belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect K (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of K (programming language) from memory before moving on to harder problems.

Reference excerpt

K is a proprietary array processing programming language developed by Arthur Whitney and commercialized by KX Systems. The language serves as the foundation for kdb+, an in-memory, column-based database, and other related financial products. The language, originally developed in 1993, is a variant of APL and contains elements of Scheme. Advocates of the language emphasize its speed, facility in handling arrays, and expressive syntax.

History Before developing K, Arthur Whitney had worked extensively with APL, first at I. P. Sharp Associates alongside Ken Iverson and Roger Hui, and later at Morgan Stanley developing financial applications. At Morgan Stanley, Whitney helped to develop A+, a variant of APL, to facilitate migrating APL applications from IBM mainframe computers to a network of Sun workstations. A+ had a smaller set of primitive functions and was designed for speed and to handle large sets of time series data. In 1993, Whitney left Morgan Stanley and developed the first version of the K language. At the same time he formed KX Systems to commercialize the product and signed an exclusive contract with Union Bank of Switzerland (UBS). For the next four years he developed various financial and trading applications using K for UBS. The contract ended in 1997 when UBS merged with Swiss Bank. In 1998, KX Systems released kdb+, a database built on K. kdb was an in-memory, column-oriented database and included ksql, a query language with an SQL-like syntax. Since then, several financial products have been developed with K and kdb+. kdb+/tick and kdb+/taq were developed in 2001. kdb+, a 64-bit version of kdb+ was released in 2003 and kdb+/tick and kdb+/taq were released in 2004. kdb+ included Q, a language that merged the functions of the underlying K language and ksql. Whitney released a derivative of K called Shakti in 2018.

Overview K shares key features with APL. They are both interpreted, interactive languages noted for concise and expressive syntax. They have simple rules of precedence based on right to left evaluation. The languages contain a rich set of primitive functions designed for processing arrays. These primitive functions include mathematical operations that work on arrays as whole data objects, and array operations, such as sorting or reversing the order of an array. Also, the language contains special operators that combine with primitive functions to perform types of iteration and recursion. Therefore, complex and extended transformations of a dataset can be expressed as a chain of sub-expressions, with each link performing a segment of the calculation and passing the results to the next link in the chain. Like APL, the primitive functions and operators are represented by single or double characters; however, unlike APL, K restricts itself to the ASCII character set (as does another APL variant, J). To allow for this, the set of primitive functions for K is smaller and heavily overloaded, with each of the ASCII symbols representing two or more distinct functions or operations. In a given expression, the actual function referenced is determined by the context. Therefore, K expressions can be opaque and difficult to parse for humans. For example, in the following contrived expression the exclamation point ! refers to three distinct functions:

2!!7!4 Reading from right to left the first ! is modulo division that is performed on 7 and 4 resulting in 3. The next ! is enumeration and lists the integers less than 3, resulting in the list 0 1 2. The final ! is rotation where the list on the right is rotated two times to the left producing the final result of 2 0 1. The second core distinction of K is that functions are first-class objects, a concept borrowed from Scheme. First-class functions can be used in the same contexts where a data value can be used. Functions can be specified as anonymous expressions and used directly with other expressions. Function expressions are specified in K using curly brackets. For example, in the following expression a quadratic expression is defined as a function and applied to the values 0 1 2 and 3:

In K, named functions are simply function expressions stored to a variable in the same way any data value is stored to a variable.

Functions can be passed as an argument to another function or returned as a result from a function.

Examples K is an interpreted language where every statement is evaluated and its results displayed immediately. Literal expressions such as strings evaluate to themselves. Therefore, the "Hello, World!" program is trivial:

"Hello world!"

The following expression sorts a list of strings by their lengths:

The expression is evaluated from right to left as follows:

#:'x returns the length of each word in the list x. > returns the indices that would sort a list of values in descending order. @ uses the integer values on the right to index into the original list of strings. A function to determine if a number is prime can be written as:

The function is evaluated from right to left:

!x enumerate the positive integers less than x. 2_ drops the first two elements of the enumeration (0 and 1). x!/: performs modulo division between the original integer and each value in the truncated list. &/ find the minimum value of the list of modulo result. If x is not prime then one of the values returned by the modulo operation will be 0 and consequently the minimal value of the list. If x is prime then the minimal value will be 1, because x mod 2 is 1 for any prime greater than 2. The function below can be used to list all of the prime numbers between 1 and R with:

The expression is evaluated from right to left

!R enumerate the integers less than R. ' apply each value of the enumeration to the prime number function on the left. This will return a list of 0's and 1's. & return the indices of the list where the value is 1. 2_ drop the first two elements of the enumeration (0 and 1)

K financial products K is the foundation for a family of financial products. Kdb+ is an in-memory, column-based database with much of the same functions of a relational database management system. The database supports SQL, SQL-92 and ksql, a query language with a syntax similar to SQL and designed for column based queries and array analysis. Kdb+ is available for several operating systems, including Solaris, Linux, macOS, and Windows (32-bit or 64-bit).

See also J, another APL-inspired language Q, the language of kdb+ and a new merged version of K and ksql.

References

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with K (programming language)

Start with the simplest possible case. Write down what K (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to K (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about K (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of K (programming language)

In research
K (programming language) appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses K (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
K (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1993 software, APL programming language family, Array programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for K (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study K (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what K (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain K (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is K (programming language) in simple terms?

K is a proprietary array processing programming language developed by Arthur Whitney and commercialized by KX Systems. The language serves as the foundation for kdb+, an in-memory, column-based database, and other related financial products.

Why does K (programming language) matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study K (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on K (programming language).

Tags

  • 1993 software
  • APL programming language family
  • Array programming languages
  • Data-centric programming languages
  • Dynamic programming languages
  • Dynamically typed programming languages
  • Function-level languages
  • High-level programming languages
  • Programming languages
  • Programming languages created in 1993
  • Proprietary database management systems

Keep exploring