Wikifunctions:Catalogue/List operations
Appearance
- Typed list (Z881): A list containing items of the same type
Basic list/iterable functions
- length of a list (Z12681): number of objects on a list
- List equality (Z889): lists are exactly the same elements in the same order (whether or not either list is explicitly typed)
- same list (Z18646): returns True if all the elements in two lists are equal and both lists have the same Type
- first element (Z811): returns the first element of the input list (labelled “Item 1”)
- second element (Z16360): returns the second element from a list
- last element (Z12964): the final element of a list
- Is empty list (Z813): returns true if and only if the list has zero elements
- is non-empty list (Z23120): returns true if the list has a length greater than 0
- contains (Z12696): test whether a list contains a certain element
- are all true (Z12684): returns true if every list item is true
- all meet criteria (Z12735): every item on the list, when evaluated by the criteria function, evaluates to true
- is any true (Z12698): checks whether in a list of Boolean any is true
- any meet criteria (Z12738): return true if one the items of a list meets criteria given by a function, otherwise false
- is single element list (Z12755): returns true if the list has exactly one element
- is two element list (Z12759): returns true if and only if the list has exactly two elements
- is longer list (Z12851): true if first list is longer than the second, false when equal or shorter
- lists have equal length (Z12864): true if the lists have an equal number of elements, false otherwise
- lists have unequal length (Z13310): Returns true if lists have different length
- index of first listing (1...N) (Z13708): returns the position on a list of the element tested (1...N)
- get the nth element of a list (Z13397): When given a valid index (1-based) return the object at that position in the list
Complex list/iterable functions
- is permutation (Z12741): tests if one list is a permutation of another
- contains whole list (Z12846): test whether the first list contains all elements of the second (and contains at least as many of any repeated elements)
- is there a common element on these lists? (Z13752): returns true if the two lists share at least one common element
- index of element on list with metric value (Z19536): returns the index (1...N) of the first element on the list which when passed to the metric function has a given natural number metric value. Returns 0 if none of the list satisfy.
Linear Algebra
Since we don't have specific types for vectors or matrices, vectors are represented as a list and matrixes as a list of lists (to be interpreted as a list of rows).
- add vectors (containing natural numbers) (Z17670): vectors must have equal length
- average vectors (containing natural numbers) (Z17675): Vectors must be equal length. Uses integer division, so (a[i]+b[i])//2 will round down if (a[i]+b[i]) is odd
- get dot product (integer vectors) (Z20659): Finds the dot product of two integer vectors
- get cross product (Z21903): Finds the cross product of two integer vectors
Rational vector operations
- same list of rationals (Z24166): no description
- add vectors (rational) (Z24055): no description
- rational times vector (Z24060): no description
- dot product (rational vectors) (Z24185): Restituisce la somma dei prodotti a 2 a 2 delle componenti
- prepend 0 to vector (Z24285): no description
- squared norm of a vector (rational) (Z24342): returns the sum of the squares of the elements of a vector
- norm of a vector (Z24346): no description
Rational matrix operations
Lists of lists don't work, so expect most of these functions to be unusable.
- list of list of single object (Z24291): Returns a list containing a list containing the object (useful for creating 1x1 matrixes)
- create 2x2 matrix (Z24251): no description
- identity matrix (Z24290): Returns the identity matrix, given the dimension
- same rational matrix (Z24171): no description
- transpose rational matrix (Z24176): no description
- sum rational matrices (Z24162): no description
- multiply rational and matrix (Z24436): no description
- matrix multiplication (Z24239): no description
- prepend column to matrix (Z24299): no description
Rational matrixes and vectors operations
- vector in row matrix (Z24177): no description
- vector in column matrix (Z24182): no description
- right product of matrix with vector (Z24191)
- left multiplication between vector and matrix (Z24236): no description
Functions expecting a list argument
Functions with list outputs
- If a function specifies an output list with a type other than Z1 (that is, it specifies a "properly typed" list), mismatched elements cause an error if the implementation is in code.
- If all objects in an output list have the same type, the list takes that type instead of being Z1-typed. This only happens if the implementation is in code. For compositions, you can use return Typed list (Z18475) to get the same result.
- If a code implementation needs converted objects (provided by a Type converter to code (Z46)), any list input must be properly typed (objects in a Z1-typed list are not converted). Similarly, any list output must be properly typed (not Z1 in the function specification) or else conversion into a Wikifunctions object will fail.
- If a code implementation does not need converted objects, you can use untype a list (Z17895) to convert a properly typed list to Z1-typed (but this is not officially supported).
- return Typed list (Z18475): returns a Typed list with the correct Type if all elements have the same Type, otherwise untyped (Z1-typed)
- type untyped list as natural number (Z24855): Take an untyped list containing only natural numbers and return a typed list of natural numbers
- filter list for natural numbers (Z24849): Takes an untyped list and returns only the elements that are natural numbers
- untype a list (Z17895): takes a typed list and returns the same objects in an untyped (Z1-typed) list (returns a Z1-typed list unchanged)
- return Typed or untyped list (Z18729): according to the option chosen, returns an heuristically Typed list or an untyped (Z1-Typed) list
- reverse list preserving list typing/untyping (Z18759): deals with either typed or untyped lists, and preserves the typing
- generate untyped list of length (Z21821): calls the given function for each index 1..=n, appending the results into a list (zero-indexed version at Z24387)
- generate list of [f(0) to f(n)] (Z24387): Calls the given function for each index 0..=n, appending the results into a list (length n+1). Index 1 version at Z21821. Reversed inputs of Z23921.
- generate list from function, index 0..=n (Z23921): calls the given function for each index 0..=n, appending the results into a list. Reversed inputs of Z24387.
- generate list of powers of q from 0 to n (Z24382): no description
- replicate object n times (Z21389): no description
- element to list (Z14046): makes a single-element list from the given element
- append element to Typed list (Z12961): adds the supplied element to the end of the supplied list
- list without last element (Z12967): returns a list without the last element
- get the first n elements of an untyped list (Z13366): return a list of the first n elements of a supplied list
- remove first N elements of list (Z13369): returns the supplied list without the first N elements (an empty list if the number of items to be removed is greater than the length of the list or the number of items to be removed is invalid)
- remove last n elements of a list (Z13373): returns the supplied list without the last n elements. if the number of items to be remove is higher than length of the list or number of items to be remove is invalid it removes all items from list
- remove the nth element from a list (Z13429): When given a valid index remove the element at the position and return the supplied list otherwise return nothing
- get the last n elements of a list (Z13362): return a list of the last n elements of a supplied list .
- discard tail of Typed list after first match (Z24203): returns the list up to the first element matching the specified, or the whole list if it is not present
- concatenate two untyped lists (Z12767): appends two lists together and preserves the order of elements
- flatten untyped list (Z12676): flatten an (untyped) list to limited depth
- interleave lists (Z13155): interleave lists of same length together such that [A..Z], [1..26]...n return [A, 1, B, 2 .. n] and if there are uneven list of same size or if this list doesnt contain lists throughout it returns an empty list
- split list into a list of two ~equal length lists (Z13224): Keeps the order of elements, first half on first list. If odd length, the first list will have just over half.
- faro out-shuffle (Z13247): a perfect riffle shuffle see https://en.wikipedia.org/wiki/Faro_shuffle
- remove first matching element from list (Z12856): returns a list equal to the original list with the first matching element removed
- remove all matching elements from list (Z13081): returns a list equal to the original list with all matching element removed
- remove duplicates from untyped list (Z13078): remove second and subsequent duplicate items without changing the order of the list
- Sort ascending
- add vectors (containing natural numbers) (Z17670): vectors must have equal length
- average vectors (containing natural numbers) (Z17675): Vectors must be equal length. Uses integer division, so (a[i]+b[i])//2 will round down if (a[i]+b[i]) is odd
In-built functions with list outputs
These operate on object-typed lists, so may not need a different version for each type. However, code implementations cannot currently generate lists of objects (other than string/boolean). So code implementations will not work on these functions.
- map function (Z873): return a list of elements processed by a given function
- map to natural number (Z24846): A map function that returns a typed list of natural numbers.
- Filter Function (Z872): return elements meeting criteria given by a function
- filter list for natural numbers (Z24849): Takes an untyped list and returns only the elements that are natural numbers
- Reduce Function (Z876) (actually left-associative fold)
- left fold (Z12781) (actually left-associative reduce)
- reduce (list only) (Z20089) w/ initial empty check
- right fold (Z12753) (actually right-associative reduce)
- left fold (Z12781) (actually left-associative reduce)
- prepend element to list (Z810): adds the supplied element to the start of the supplied list
- list without first element (Z812): returns a list without the first element