Created
September 23, 2021 11:53
-
-
Save Announcement/6c454b984fb19198e3b2715eb6220b80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generate integers ranging from the lower limit to the upper limit as an iterator. | |
* | |
* @param m? - Optional, Integer lower limit of generator. Defaults to 0. | |
* @param M - Required, Integer upper limit of generator. | |
*/ | |
function δ (minimum: number, maximum: number): IterableIterator<number>; | |
function δ (Δ: number): IterableIterator<number>; | |
function * δ (h: number, k?: number?): IterableIterator<number> | |
{ | |
// Normalize input,... | |
// set minimum to 0 if not defined. | |
const [ m, M ] = k === null || k === undefined ? [ 0, h ] : [ h, k ]; | |
// Dampen the moisture a little bit (Keep it D.R.Y.) | |
const d = M - m; | |
// phi is the direction that the generator should be moving towards. | |
const φ = Math.sign(d); | |
// delta is the magnitude of the generator's occurence. | |
const Δ = Math.abs(d); | |
// given i starts at 0, and ends at delta, | |
// while i is approaching, arrived, but not surpassed delta, | |
// continue iterating and advancing i towards the desired magnitude; | |
// since the direction is phi, the current magnitude is i, multiply them and offset by the starting point. | |
for (let i = 0, I = Δ; i <= I; i++) | |
yield i * φ + m; | |
} | |
// Xi <specific "generic" object type T>, | |
// x: T | |
// lambda0, lambda1, lambda2, lambdaN[]: function (y: T): T {} | |
// lambda0(x_initial) => x_0 | |
// lambda1(x_0) => x_1 | |
// lambda2(x_1) => x_2 | |
// lambdaN(x_previous)=> x_next | |
// return x_final; | |
/** | |
* Colloquially defined as a number that can be written without a fractional component. | |
* @typedef {number} Integer | |
*/ | |
/** | |
* @function | |
* @template T | |
* @param {T} x | |
* @param {...ξ~λcallback} Λ - List of | |
* @returns {T} | |
*/ | |
function ξ<T> (x: T, ...Λ: Array<(x: T) => T>): T | |
{ | |
return Λ.reduce((x, λ) => λ(x), x) | |
} | |
/** | |
* Takes a parameter of a specific type and modifies it in such a way that also is of that type. | |
* @callback ξ~λcallback | |
* @param {T} x | |
* @returns {T} | |
*/ | |
// Sigma <specific "generic" object type T> | |
function Σ<T> (δ: Iterable<number>, ...Λ: ((x: number) => number)[]): number | |
{ | |
return [...δ] | |
.map(x => ξ(x, ...Λ)) | |
.reduce((α, x) => α + x); | |
} | |
function MMM ( | |
a: Array<Array<number> & { length: number, 0: number }> & { length: number, 0: Array<number> & { length: number, 0: number }}, | |
b: Array<Array<number> & { length: number, 0: number }> & { length: (typeof a)[0]["length"], 0: Array<number> & { length: number, 0: number }} | |
): Array<Array<number> & { length: (typeof b)[0]["length"], 0: number }> & { length: (typeof a)["length"], 0: Array<number> & { length: (typeof b)[0]["length"], 0: number }} { | |
// return [ [ ] ] | |
let c: Array<Array<number>> = []; | |
// iεm | |
// kεn | |
// jεp | |
let m = a.length; | |
let n = a[0].length & b.length; | |
let p = b[0].length; | |
for (let i = 0; i < m; i++) | |
c[i] = []; | |
for (let i = 0; i < m; i++) | |
for (let j = 0; j < p; j++) | |
c[i][j] = Σ(δ(n), k => a[i][k] * b[k][j]); | |
return c as Array<Array<number> & { length: (typeof b)[0]["length"], 0: number }> & { length: (typeof a)["length"], 0: Array<number> & { length: (typeof b)[0]["length"], 0: number }}; | |
} | |
function MSM ( | |
m: Array<Array<number> & { length: number, 0: number }> & { length: number, 0: Array<number> & { length: number, 0: number }}, | |
s: number | |
): Array<Array<number> & { length: (typeof m)[0]["length"], 0: number }> & { length: (typeof m)["length"], 0: Array<number> & { length: (typeof m)[0]["length"], 0: number }} { | |
{ | |
return m.map(_ => _.map($ => $ * s)) as Array<Array<number> & { length: (typeof m)[0]["length"], 0: number}> & { length: (typeof m)["length"], 0: Array<number> & { length: (typeof m)[0]["length"], 0: number }}; | |
} | |
function MVM ( | |
m: Array<Array<number> & { length: number, 0: number }> & { length: number, 0: Array<number> & { length: number, 0: number }}, | |
v: Array<number> & { length: number, 0: number } | |
): Array<[ number ]> & { length: (typeof v)["length"], 0: [ number ] } | |
{ | |
return MMM(m, v.map(s => ([s])) as Array<Array<number> & { length: 1, 0: number }> & { length: (typeof v)["length"], 0: [ number ]}) as Array<[ number ]> & { length: (typeof v)["length"], 0: [ number ]}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment