@mojir/dvala 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cli/cli.js +71 -23
  2. package/dist/cli/src/evaluator/effectTypes.d.ts +19 -1
  3. package/dist/cli/src/evaluator/suspension.d.ts +6 -0
  4. package/dist/cli/src/evaluator/trampoline.d.ts +5 -0
  5. package/dist/debug.esm.js +1 -1
  6. package/dist/debug.esm.js.map +1 -1
  7. package/dist/debug.js +1 -1
  8. package/dist/debug.js.map +1 -1
  9. package/dist/dvala.iife.js +1 -1
  10. package/dist/dvala.iife.js.map +1 -1
  11. package/dist/full.esm.js +1 -1
  12. package/dist/full.esm.js.map +1 -1
  13. package/dist/full.js +1 -1
  14. package/dist/full.js.map +1 -1
  15. package/dist/index.esm.js +1 -1
  16. package/dist/index.esm.js.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/mcp-server/server.js +116 -69
  20. package/dist/mcp-server/src/evaluator/effectTypes.d.ts +19 -1
  21. package/dist/mcp-server/src/evaluator/suspension.d.ts +6 -0
  22. package/dist/mcp-server/src/evaluator/trampoline.d.ts +5 -0
  23. package/dist/modules/src/evaluator/effectTypes.d.ts +19 -1
  24. package/dist/modules/src/evaluator/suspension.d.ts +6 -0
  25. package/dist/modules/src/evaluator/trampoline.d.ts +5 -0
  26. package/dist/modules/src/index.d.ts +2 -0
  27. package/dist/modules/src/retrigger.d.ts +39 -0
  28. package/dist/src/evaluator/effectTypes.d.ts +19 -1
  29. package/dist/src/evaluator/suspension.d.ts +6 -0
  30. package/dist/src/evaluator/trampoline.d.ts +5 -0
  31. package/dist/src/index.d.ts +2 -0
  32. package/dist/src/retrigger.d.ts +39 -0
  33. package/dist/testFramework.esm.js +1 -1
  34. package/dist/testFramework.esm.js.map +1 -1
  35. package/dist/testFramework.js +1 -1
  36. package/dist/testFramework.js.map +1 -1
  37. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- import e from"node:fs";import t from"node:path";function r(e){if(!e.position||!e.code)return"";const t=e.position.column-1,r=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(r,0))}`}class n extends Error{params;constructor(e){super(`recur, params: ${e}`),Object.setPrototypeOf(this,n.prototype),this.name="RecurSignal",this.params=e}}class o extends Error{sourceCodeInfo;shortMessage;constructor(e,t){const n=e instanceof Error?e.message:`${e}`;super(function(e,t){if(!t)return e;const n=`${t.position.line}:${t.position.column}`;return`${e}${t.filePath?`\n${t.filePath}:${n}`:`\nLocation ${n}`}\n${t.code}\n${r(t)}`}(n,t)),this.shortMessage=n,this.sourceCodeInfo=t,Object.setPrototypeOf(this,o.prototype),this.name="DvalaError"}getCodeMarker(){return this.sourceCodeInfo&&r(this.sourceCodeInfo)}}class a extends o{userMessage;constructor(e,t){super(e,t),this.userMessage=e,Object.setPrototypeOf(this,a.prototype),this.name="UserDefinedError"}}class i extends o{constructor(e,t){super(e,t),Object.setPrototypeOf(this,i.prototype),this.name="AssertionError"}}class s extends o{symbol;constructor(e,t){super(`Undefined symbol '${e}'.`,t),this.symbol=e,Object.setPrototypeOf(this,s.prototype),this.name="UndefinedSymbolError"}}const l={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},c=new Set(Object.values(l));function u(e){return Object.keys(l).find(t=>l[t]===e)}const m=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","EffectMatcher","Builtin","SpecialBuiltin","Module"]);const p="^^fn^^",d="^^re^^",h="^^ef^^";function g(e){return null!==e&&"object"==typeof e&&(p in e&&"functionType"in e&&function(e){return"string"==typeof e&&m.has(e)}(e.functionType))}function f(e){return!(!Array.isArray(e)||e.length<2)&&function(e){return"number"==typeof e&&c.has(e)}(e[0])}function y(e){return g(e)?`<function ${e.name||"λ"}>`:f(e)?`${u(e[0])}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e)}function v(e,t){return e?.sourceCodeInfo??t}function b(e,t,r){return new o(`Expected ${e}, got ${y(t)}.`,v(t,r))}function w(e,t){return x(e,t),e}function x(e,t){if(!function(e){return void 0!==e}(e))throw new o("Unexpected undefined",v(e,t))}function k(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function q(e){return null!==e&&"object"==typeof e&&!!e[p]}function A(e){return q(e)&&"UserDefined"===e.functionType}function N(e){return void 0!==e}function $(e,t){return E(e,t),e}function E(e,t){if(!N(e))throw b("not undefined",e,t)}function T(e){return Array.isArray(e)||"string"==typeof e}function S(e,t){return z(e,t),e}function z(e,t){if(!T(e))throw b("string or array",e,t)}function j(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||q(e)||M(e)||V(e))}function C(e,t){if(!j(e))throw b("object",e,t)}function I(e){return T(e)||j(e)}function R(e,t){return P(e,t),e}function P(e,t){if(!I(e))throw b("string, array or object",e,t)}function M(e){return null!==e&&"object"==typeof e&&!!e[d]}function O(e,t){if(!function(e){return M(e)||"string"==typeof e}(e))throw b("string or RegularExpression",e,t)}function V(e){return null!==e&&"object"==typeof e&&!!e[h]}function D(e,t){if(!V(e))throw b("Effect",e,t)}function U(e,t){return F(e,t),e}function F(e,t){if(!function(e){return"number"==typeof e||!!I(e)||!!q(e)}(e))throw b("FunctionLike",e,t)}function W(e,t={}){return"string"==typeof e&&((!t.nonEmpty||0!==e.length)&&(!t.char||1===e.length))}function G(e,t,r={}){if(!W(e,r))throw b(""+(r.nonEmpty?"non empty string":r.char?"character":"string"),e,t)}function B(e,t,r={}){return G(e,t,r),e}function L(e){return"string"==typeof e||"number"==typeof e}function _(e,t){return K(e,t),e}function K(e,t){if(!L(e))throw b("string or number",e,t)}const J={assert:{evaluate:(e,t)=>{const r=e[0],n=2===e.length?e[1]:`${r}`;if(G(n,t),!r)throw new i(n,t);return $(r,t)},arity:{min:1,max:2},docs:{category:"assertion",description:"If $value is falsy it throws `AssertionError` with $message. If no $message is provided, message is set to $value.",returns:{type:"any"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['do assert(0, "Expected a positive value") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-truthy","assertion.assert-true"],hideOperatorForm:!0}}};function H(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function Y(e,t,r={}){if(!H(e,r))throw new o(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),r=e.integer?"integer":"number",n=e.finite?"finite":"",o=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,n,r,o].filter(e=>!!e).join(" ")}(r)}, got ${y(e)}.`,v(e,t))}function X(e,t,r={}){return Y(e,t,r),e}function Q(e,t){const{min:r}=e;return!("number"==typeof r&&t<r)}function Z(e){return"number"==typeof e||I(e)?te(1):e.arity}function ee(e,t,r){const{min:n,max:a}=e;if("number"==typeof n&&t<n)throw new o(`Wrong number of arguments, expected at least ${n}, got ${y(t)}.`,r);if("number"==typeof a&&t>a)throw new o(`Wrong number of arguments, expected at most ${a}, got ${y(t)}.`,r)}function te(e){return{min:e,max:e}}function re(e,t){return{a:{type:e},b:{type:t}}}const ne={"<<":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0}),e<<t),arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Shifts $a arithmetically left by $b bit positions.",seeAlso:[">>",">>>"],examples:["1 << 10","<<(1, 10)","<<(-4, 2)"]}},">>":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0}),e>>t),arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Shifts $a arithmetically right by $b bit positions.",seeAlso:["<<",">>>"],examples:["2048 >> 10",">>(2048, 10)",">>>(-16, 2)",">>(4, 10)"]}},">>>":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0}),e>>>t),arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Shifts $a arithmetically right by $b bit positions without sign extension.",seeAlso:["<<",">>"],examples:["-16 >>> 2",">>>(2048, 10)",">>>(-16, 2)",">>>(4, 10)",">>>(-1, 10)"]}},"&":{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e&t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `and` of all arguments.",seeAlso:["|","xor","bitwise.bit-not","bitwise.bit-and-not"],examples:["0b0011 & 0b0110","&(0b0011, 0b0110)","&(0b0011, 0b0110, 0b1001)"]}},"|":{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e|t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `or` of all arguments.",seeAlso:["&","xor","bitwise.bit-not","bitwise.bit-and-not"],examples:["0b0011 | 0b0110","|(0b0011, 0b0110)","|(0b1000, 0b0100, 0b0010)"]}},xor:{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e^t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `xor` of all arguments.",seeAlso:["&","|","bitwise.bit-not","bitwise.bit-and-not"],examples:["0b0011 xor 0b0110","xor(0b0011, 0b0110)","xor(0b11110000, 0b00111100, 0b10101010)"]}}};function oe(e,t){return!!I(e)&&("string"==typeof e||Array.isArray(e)?!!H(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function ae(e,t,r){if(K(e,r),K(t,r),"string"==typeof e&&"string"==typeof t)return e<t?-1:e>t?1:0;if("number"==typeof e&&"number"==typeof t)return Math.sign(e-t);throw new o(`Cannot compare values of different types: ${typeof e} and ${typeof t}`,r)}function ie(e,t,r){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return he(e,t);if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(!ie($(e[n],r),$(t[n],r),r))return!1;return!0}if(M(e)&&M(t))return e.s===t.s&&e.f===t.f;if(k(e)&&k(t)){const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const a=B(n[o],r);if(!ie(e[a],t[a],r))return!1}return!0}return!1}function se(e){return Math.max(0,Math.ceil(e))}function le(e){return e??null}function ce(e){return j(e)?Object.entries(e).reduce((e,t)=>{const[r,n]=t;return e[r]=ce(n),e},{}):Array.isArray(e)?e.map(e=>ce(e)):e}function ue(e){return ce(e)}function me(...e){const t=new Set;for(const r of e)r.forEach(e=>t.add(e));return t}function pe(e,t){t.forEach(t=>e.add(t))}const de=1e-10;function he(e,t,r=de){if(e===t)return!0;const n=Math.abs(e-t);if(0===e||0===t||n<r)return n<r;return n/(Math.abs(e)+Math.abs(t))<r}function ge(e){return Math.abs(e)<de}function fe(e,t=0){const r=e.split("\n");for(;r[0]?.match(/^\s*$/);)r.shift();for(;r[r.length-1]?.match(/^\s*$/);)r.pop();const n=r.reduce((e,t)=>{if(t.match(/^\s*$/))return e;const r=t.match(/^\s*/)[0].length;return Math.min(e,r)},1/0);return r.map(e=>" ".repeat(t)+e.slice(n)).join("\n").trimEnd()}function ye(e,t){if(!Array.isArray(e))throw b("array",e,t)}function ve(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}(e))throw b("array of strings",e,t)}function be(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e&&1===e.length)}(e))throw b("array of strings",e,t)}const we={filter:{evaluate:()=>{throw new Error("filter is implemented in Dvala")},arity:te(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function"},coll:{type:"collection"},fun:{type:"function"}},variants:[{argumentNames:["coll","fun"]}],description:"Creates a new collection with all elements that pass the test implemented by $fun.",seeAlso:["collection.filteri","map","sequence.remove"],examples:['\nfilter(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)","\nfilter(\n { a: 1, b: 2 },\n odd?\n)"]}},map:{evaluate:()=>{throw new Error("map is implemented in Dvala")},arity:{min:2},docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function"},colls:{type:"collection",rest:!0,description:"At least one."},fun:{type:"function"}},variants:[{argumentNames:["colls","fun"]}],description:"Creates a new collection populated with the results of calling $fun on every element in $colls.",seeAlso:["collection.mapi","filter","reduce","mapcat","grid.cell-map","grid.cell-mapi"],examples:["[1, 2, 3] map -","[1, 2, 3] map -> -($)",'map(["Albert", "Mojir", 42], str)',"map([1, 2, 3], inc)","map([1, 2, 3], [1, 10, 100], *)","map({ a: 1, b: 2 }, inc)","map({ a: 1, b: 2 }, { a: 10, b: 20 }, +)"]}},reduce:{evaluate:()=>{throw new Error("reduce is implemented in Dvala")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.",seeAlso:["collection.reduce-right","collection.reducei","collection.reductions","map","grid.cell-reduce","grid.cell-reducei"],examples:["reduce([1, 2, 3], +, 0)","reduce([], +, 0)","reduce({ a: 1, b: 2 }, +, 0)","\nreduce(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + (even?(value) ? value : 0),\n 0)"]}},get:{evaluate:(e,t)=>{const[r,n]=e,o=le(e[2]);if(K(n,t),null===r)return o;P(r,t);const a=function(e,t){if(j(e)){if("string"==typeof t&&oe(e,t))return le(e[t])}else if(H(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return le(e[t])}(r,n);return void 0===a?o:a},arity:{min:2,max:3},docs:{category:"collection",returns:{type:"any"},args:{a:{type:"collection"},b:{type:["string","integer"]},"not-found":{type:"any",description:"Default value to return if $b is not found."}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","not-found"]}],description:"Returns value in $a mapped at $b.",seeAlso:["collection.get-in","contains?","find","nth"],examples:["[1, 2, 3] get 1",'{ a: 1 } get "a"','"Albert" get "3"',"\nget(\n [1, 2, 3],\n 1, // Optional comma after last argument\n)","\nget(\n [],\n 1\n)",'\nget(\n [],\n 1,\n "default"\n)','\nget(\n { a: 1 },\n "a"\n)','\nget(\n { a: 1 },\n "b"\n)','\nget(\n { a: 1 },\n "b",\n "default"\n)','\nget(\n null,\n "a"\n)','\nget(\n null,\n "b",\n "default"\n)']}},count:{evaluate:([e],t)=>null===e?0:"string"==typeof e?e.length:(P(e,t),Array.isArray(e)?e.length:Object.keys(e).length),arity:te(1),docs:{category:"collection",returns:{type:"number"},args:{coll:{type:["collection","null"]}},variants:[{argumentNames:["coll"]}],description:"Returns number of elements in $coll.",seeAlso:["empty?"],examples:["count([1, 2, 3])","count([])","count({ a: 1 })",'count("")','count("Albert")',"count(null)"]}},"contains?":{evaluate:([e,t],r)=>null!==e&&(P(e,r),W(e)?(G(t,r),e.includes(t)):T(e)?(E(t,r),!!e.find(e=>ie($(e),t,r))):(G(t,r),t in e)),arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:["collection","null"]},b:{type:["string","integer"]}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if $a contains $b, otherwise returns `false`. For strings, it checks if substring is included.",seeAlso:["get","find","index-of"],examples:["[1, 2, 3] contains? 1","null contains? 1",'{ a: 1, b: 2 } contains? "a"',"\ncontains?(\n [],\n 1\n)","\ncontains?(\n [1],\n 1\n)","\ncontains?(\n [1, 2, 3],\n 1\n)",'\ncontains?(\n {},\n "a"\n)','\ncontains?(\n { a: 1, b: 2 },\n "a"\n)']}},assoc:{evaluate:([e,t,r],n)=>(P(e,n),K(t,n),E(r,n),function(e,t,r,n){if(P(e,n),K(t,n),Array.isArray(e)||"string"==typeof e){if(Y(t,n,{integer:!0}),Y(t,n,{gte:0}),Y(t,n,{lte:e.length}),"string"==typeof e)return G(r,n,{char:!0}),`${e.slice(0,t)}${r}${e.slice(t+1)}`;const o=[...e];return o[t]=r,o}G(t,n);const o={...e};return o[t]=r,o}(e,t,r,n)),arity:te(3),docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},key:{type:["string","number"]},value:{type:"any"},kvs:{type:"any",description:"Key-value pairs to associate.",rest:!0}},variants:[{argumentNames:["coll","key","value"]},{argumentNames:["coll","key","value","kvs"]}],description:"\nAdd or replace the value of element $key to $value in $coll. Repeated for all key-value pairs in $kvs.\nIf $coll is an 'array', $key must be `number` satisfying `0 <=` $key `<= length`.",seeAlso:["collection.assoc-in","dissoc","merge","collection.update"],examples:['\nassoc(\n [1, 2, 3],\n 1,\n "Two"\n)','\nassoc(\n [1, 2, 3],\n 3,\n "Four"\n)','\nassoc(\n { a: 1, b: 2 },\n "a",\n "One")','\nassoc(\n { a: 1, b: 2 },\n "c",\n "Three")','\nassoc(\n "Albert",\n 6,\n "a")']}},"++":{evaluate:(e,t)=>(H(e[0])||P(e[0],t),Array.isArray(e[0])?e.reduce((e,r)=>(ye(r,t),e.concat(r)),[]):L(e[0])?e.reduce((e,r)=>(K(r,t),`${e}${r}`),""):e.reduce((e,r)=>(C(r,t),Object.assign(e,r)),{})),arity:{min:1},docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"collection"},colls:{type:"collection",rest:!0}},variants:[{argumentNames:["a"]},{argumentNames:["a","colls"]}],description:"Concatenates collections into one collection.",seeAlso:["mapcat","str","join","push","sequence.unshift"],examples:['"Albert" ++ " " ++ "Mojir"','"Albert" ++ "Mojir"','++("Albert", "-", "Mojir")','++("Albert")','++("A", "l", "b", "e", "r", "t")',"++([1, 2], [3, 4])","++([], [3, 4])","++([1, 2], [])","++([1, 2], [3, 4], [5, 6])","++([])","++({ a: 1, b: 2 }, { b: 1, c: 2 })","++({}, { a: 1 })"]}}},xe={range:{evaluate:(e,t)=>{const[r,n,o]=e;let a,i,s;Y(r,t,{finite:!0}),1===e.length?(a=0,i=r,s=i>=0?1:-1):2===e.length?(Y(n,t,{finite:!0}),a=r,i=n,s=i>=a?1:-1):(Y(n,t,{finite:!0}),Y(o,t,{finite:!0}),a=r,i=n,s=o,Y(s,t,i>a?{positive:!0}:i<a?{negative:!0}:{nonZero:!0}));const l=[];for(let e=a;s<0?e>i:e<i;e+=s)l.push(e);return l},arity:{min:1,max:3},docs:{category:"array",returns:{type:"number",array:!0},args:{a:{type:"number"},b:{type:"number"},step:{type:"number"}},variants:[{argumentNames:["b"]},{argumentNames:["a","b"]},{argumentNames:["a","b","step"]}],description:"$range creates an array with a range of numbers from $a to $b (exclusive), by $step.\n\n$a defaults to 0.\n$step defaults to 1.",seeAlso:["repeat","vector.linspace"],examples:["range(4)","range(1, 4)","1 range 10","range(0.4, 4.9)","\nrange(\n 0.25, // start value\n 1, // end value (exclusive)\n 0.25, // step value\n)"]}},repeat:{evaluate:([e,t],r)=>{Y(t,r,{integer:!0,nonNegative:!0});const n=[];for(let r=0;r<t;r+=1)n.push(e);return n},arity:te(2),docs:{category:"array",returns:{type:"any",array:!0},args:{a:{type:"any"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],description:"Returns an array with $a repeated $b times.",seeAlso:["range","string.string-repeat"],examples:["repeat(10, 3)","repeat(10, 0)",'"Albert" repeat 5']}},flatten:{evaluate:([e,t],r)=>{ye(e,r);const n=void 0===t||t===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:X(t,r,{integer:!0,nonNegative:!0});return e.flat(n)},arity:{min:1,max:2},docs:{category:"array",returns:{type:"any",array:!0},args:{x:{type:["array","any"],description:"If $x is not an array, `[ ]` is returned."},depth:{type:"integer",description:"The depth level specifying how deep a nested array structure should be flattened. Defaults to `Infinity`."}},variants:[{argumentNames:["x"]},{argumentNames:["x","depth"]}],description:"Takes a nested array $x and flattens it.",seeAlso:["mapcat"],examples:["flatten([1, 2, [3, 4], 5])","flatten([1, [2, [3, [4]]]], 1)","flatten([1, [2, [3, [4]]]], 2)",'\nlet foo = "bar";\nflatten([\n 1,\n " 2 A ",\n [foo, [4, ["ABC"]]],\n 6,\n])'],hideOperatorForm:!0}},mapcat:{evaluate:()=>{throw new Error("mapcat is implemented in Dvala")},arity:te(2),docs:{category:"array",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function"},colls:{type:"collection",array:!0},fun:{type:"function"}},variants:[{argumentNames:["colls","fun"]}],description:"Returns the result of applying concat to the result of applying map to $fun and $colls.",seeAlso:["flatten","map","++"],examples:["[[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]] mapcat reverse","mapcat([[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]], reverse)","[[3, 2, 1, 0,], [6, 5, 4,], [9, 8, 7]] mapcat reverse","\nlet foo = (n) -> do\n [n - 1, n, n + 1]\nend;\n[1, 2, 3] mapcat foo","\nmapcat(\n [[1, 2], [2, 2], [2, 3]],\n -> $ filter odd?\n)"]}},"moving-fn":{evaluate:()=>{throw new Error("moving-fn is implemented in Dvala")},arity:te(3),docs:{category:"array",returns:{type:"array"},args:{arr:{type:"array"},windowSize:{type:"number",description:"The size of the moving window."},fn:{type:"function"}},variants:[{argumentNames:["arr","windowSize","fn"]}],description:"Returns the result of applying $fn to each moving window of size $windowSize in $arr.",seeAlso:["running-fn","vector.moving-mean"],examples:["moving-fn([1, 2, 3], 2, sum)","moving-fn([1, 2, 3], 1, sum)","moving-fn([1, 2, 3], 3, sum)"]}},"running-fn":{evaluate:()=>{throw new Error("running-fn is implemented in Dvala")},arity:te(2),docs:{category:"array",returns:{type:"array"},args:{a:{type:"array"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns the result of applying $b to each element of $a.",seeAlso:["moving-fn","vector.running-mean"],examples:["running-fn([1, 2, 3], sum)","running-fn([1, 2, 3], max)","running-fn([1, 2, 3], min)"]}}},ke={nth:{evaluate:(e,t)=>{const[r,n]=e,o=le(e[2]);if(Y(n,t,{integer:!0}),null===r)return o;if(z(r,t),n>=0&&n<r.length){return le(r[n])}return o},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"any"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:["sequence","null"]},n:{type:"integer"},"not-found":{type:"any"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","not-found"]}],description:"Accesses element $n of $seq. Accessing out-of-bounds indices returns $not-found, if present, else `null`.",seeAlso:["first","second","last","get","slice"],examples:["[1, 2, 3] nth 1",'"A string" nth 3',"nth([1, 2, 3], 1)","nth([1, 2, 3], 3)","nth([1, 2, 3], -1)","nth([1, 2, 3], 3, 99)",'nth("A string", 1)','nth("A string", 3)','nth("A string", -3)','nth("A string", 30, "X")',"nth(null, 1)",'nth(null, 1, "Default value")']}},first:{evaluate:([e],t)=>{if(null===e)return null;z(e,t);return le(e[0])},arity:te(1),docs:{category:"sequence",returns:{type:"any"},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"Returns the first element of $seq. If $seq is empty or `null`, `null` is returned.",seeAlso:["second","last","nth","rest","next"],examples:['first(["Albert", "Mojir", 160, [1, 2]])',"first([])","first(null)"]}},last:{evaluate:([e],t)=>{if(null===e)return null;z(e,t);return le(e.at(-1))},arity:te(1),docs:{category:"sequence",returns:{type:"any"},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"Returns the last element of $seq. If $seq is empty, `null` is returned.",seeAlso:["first","second","nth","pop"],examples:['last(["Albert", "Mojir", 160, [1, 2]])',"last([1, 2])","last([1])","last([])","last(null)"]}},pop:{evaluate:([e],t)=>(z(e,t),"string"==typeof e?e.substring(0,e.length-1):e.slice(0,e.length-1)),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"],rest:!0},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns a copy of $seq with last element removed. If $seq is empty `null` is returned.",seeAlso:["push","last"],examples:["pop([1, 2, 3])","pop([])"]}},"index-of":{evaluate:([e,t],r)=>{if(E(t,r),null===e)return null;if(z(e,r),"string"==typeof e){G(t,r);const n=e.indexOf(t);return-1!==n?n:null}{const n=e.findIndex(e=>ie($(e,r),t),r);return-1!==n?n:null}},arity:te(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:["sequence","null"]},x:{type:"any"}},variants:[{argumentNames:["seq","x"]}],description:"Returns the index of $x in $seq. If element is not present in $seq `null` is returned.",seeAlso:["sequence.last-index-of","sequence.position","contains?"],examples:["[[1], [2], [1], [2]] index-of [1]",'index-of(["Albert", "Mojir", 160, [1, 2]], "Mojir")',"index-of([5, 10, 15, 20], 15)","index-of([5, 10, 15, 20], 1)","index-of(null, 1)"]}},push:{evaluate:([e,...t],r)=>(z(e,r),"string"==typeof e?(be(t,r),[e,...t].join("")):[...e,...t]),arity:{min:2},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},values:{type:"any",rest:!0,description:"At least one."}},variants:[{argumentNames:["seq","values"]}],description:"Returns copy of $seq with $values added to the end of it.",seeAlso:["sequence.unshift","pop","++"],examples:["[1, 2, 3] push 4",'"Albert" push "!"',"push([1, 2, 3], 4)","push([1, 2, 3], 4, 5, 6)","\nlet l = [1, 2, 3];\npush(l, 4);\nl"]}},rest:{evaluate:([e],t)=>(z(e,t),Array.isArray(e)?e.length<=1?[]:e.slice(1):e.substring(1)),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"]},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"If $seq is an array, returns a new array with all but the first element from $seq.\nIf $seq has less than two elements, an empty array is returned.\nFor string $seq returns all but the first characters in $seq.",seeAlso:["next","first"],examples:['rest(["Albert", "Mojir", 160, [1, 2]])','rest(["Albert"])',"rest([])",'rest("Albert")','rest("A",)','rest("")']}},next:{evaluate:([e],t)=>(z(e,t),Array.isArray(e)?e.length<=1?null:e.slice(1):e.length<=1?null:e.substring(1)),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"]},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"If $seq is an array, returns a new array with all but the first element from $seq. If $seq has less than two elements, `null` is returned. For string $seq returns all but the first characters in $seq. If length of string $seq is less than two, `null` is returned.",seeAlso:["rest","first"],examples:['next(["Albert", "Mojir", 160, [1, 2]])','next(["Albert"])',"next([])",'next("Albert")','next("A",)','next("")']}},reverse:{evaluate:([e],t)=>null===e?null:(z(e,t),Array.isArray(e)?[...e].reverse():e.split("").reverse().join("")),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"]},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"If $seq is an array, creates a new array with the elements from $seq in reversed order. If $seq is a string, returns new reversed string.",seeAlso:["sort"],examples:['reverse(["Albert", "Mojir", 160, [1, 2]])',"reverse([])",'reverse("Albert")',"reverse(null)"]}},second:{evaluate:([e],t)=>null===e?null:(z(e,t),le(e[1])),arity:te(1),docs:{category:"sequence",returns:{type:"any"},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"Returns the second element of $seq. If $seq has less than two elements or is `null`, `null` is returned.",seeAlso:["first","last","nth"],examples:['second(["Albert", "Mojir", 160, [1, 2]])',"second([1])","second([])","second(null)"]}},slice:{evaluate:(e,t)=>{const[r,n,o]=e;return z(r,t),Y(n,t,{integer:!0}),2===e.length?(Array.isArray(r),r.slice(n)):(Y(o,t,{integer:!0}),Array.isArray(r),r.slice(n,o))},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},start:{type:"integer",description:"Defaults to `0`."},stop:{type:"integer",description:"Defaults to length of sequence + 1."}},variants:[{argumentNames:["seq","start"]},{argumentNames:["seq","start","stop"]}],description:"Returns a copy of a portion of $seq from index $start (inclusive) to $stop (exclusive).",seeAlso:["take","drop","sequence.splice","nth"],examples:["[1, 2, 3, 4, 5] slice 2","slice([1, 2, 3, 4, 5], 2, 4)","slice([1, 2, 3, 4, 5], 2)"]}},some:{evaluate:()=>{throw new Error("some is implemented in Dvala")},arity:te(2),docs:{category:"sequence",returns:{type:"any"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:["sequence","null"]},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the first element that passes the test implemented by $fun. I no element was found, `null` is returned.",seeAlso:["sequence.position","collection.any?","find"],examples:['\nsome(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nsome(\n [5, 10, 15, 20],\n -> $ > 10\n)","\nsome(\n [1, 2, 3, 4],\n -> $ > 10\n)","\nsome(\n [],\n -> $ > 10\n)","\nsome(\n null,\n -> $ > 10\n)"]}},sort:{evaluate:()=>{throw new Error("sort is implemented in Dvala")},arity:{min:1,max:2},docs:{category:"sequence",returns:{type:"any",rest:!0},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq"]},{argumentNames:["seq","fun"]}],description:"Returns a new sequence with the elements from $seq sorted according to $fun. If no $fun is supplied, builtin `compare` will be used.",seeAlso:["sequence.sort-by","compare","reverse","vector.sort-indices"],examples:["[3, 1, 2] sort (a, b) -> b - a","sort([3, 1, 2])","\nsort(\n [3, 1, 2],\n (a, b) -> cond case a < b then -1 case a > b then 1 case true then -1 end\n)","\nsort(\n [3, 1, 2],\n (a, b) -> cond case a > b then -1 case a < b then 1 case true then -1 end\n)"]}},take:{evaluate:([e,t],r)=>{Y(t,r),z(e,r);const n=Math.max(Math.ceil(t),0);return e.slice(0,n)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},n:{type:"integer"},seq:{type:"sequence"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array/string with the $n first elements from $seq.",seeAlso:["take-last","take-while","drop","slice","sequence.split-at"],examples:["take([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] take 3","take([1, 2, 3, 4, 5], 0)",'take("Albert", 2)','take("Albert", 50)']}},"take-last":{evaluate:([e,t],r)=>{z(e,r),Y(t,r);const n=Math.max(Math.ceil(t),0),o=e.length-n;return e.slice(o)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},n:{type:"integer"},seq:{type:"sequence"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array with the $n last elements from $seq.",seeAlso:["take","drop-last"],examples:["take-last([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] take-last 3","take-last([1, 2, 3, 4, 5], 0)"]}},drop:{evaluate:([e,t],r)=>{Y(t,r);const n=Math.max(Math.ceil(t),0);return z(e,r),e.slice(n)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"integer"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array/string with the $n first elements dropped from $seq.",seeAlso:["drop-last","drop-while","take","slice","sequence.split-at"],examples:["drop([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] drop 0",'drop("Albert", 2)','drop("Albert", 50)']}},"drop-last":{evaluate:([e,t],r)=>{z(e,r),Y(t,r);const n=Math.max(Math.ceil(t),0),o=e.length-n;return e.slice(0,o)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"integer"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array with the $n last elements dropped from $seq.",seeAlso:["drop","take-last"],examples:["drop-last([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] drop-last 3","drop-last([1, 2, 3, 4, 5], 0)"]}},"take-while":{evaluate:()=>{throw new Error("take-while is implemented in Dvala")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the members of $seq in order, stopping before the first one for which `predicate` returns a falsy value.",seeAlso:["take","drop-while","sequence.split-with"],examples:["take-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)","take-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)"]}},"drop-while":{evaluate:()=>{throw new Error("drop-while is implemented in Dvala")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the members of $seq in order, skipping the fist elements for witch the `predicate` returns a truethy value.",seeAlso:["drop","take-while","sequence.split-with"],examples:["drop-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)","drop-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)"]}}},qe=new WeakSet,Ae=new WeakSet,Ne=new WeakSet,$e=new WeakSet,Ee=new WeakSet,Te=new WeakSet,Se=new WeakSet;function ze(e){return Array.isArray(e)?(qe.has(e)||(je(e),Ve(e)||Me(e)),e):e}function je(e){return!!Array.isArray(e)&&(!!Ae.has(e)||!Ne.has(e)&&(e.every(e=>H(e))?(qe.add(e),Ae.add(e),!0):(Ne.add(e),!1)))}function Ce(e,t){if(!je(e))throw new o(`Expected a vector, but got ${e}`,t)}function Ie(e,t){if(!function(e){return!!je(e)&&2===e.length}(e))throw new o(`Expected a 2d vector, but got ${e}`,t)}function Re(e,t){if(!function(e){return!!je(e)&&3===e.length}(e))throw new o(`Expected a 3d vector, but got ${e}`,t)}function Pe(e,t){if(Ce(e,t),0===e.length)throw new o(`Expected a non empty vector, but got ${e}`,t)}function Me(e,t){if(!Array.isArray(e))return!1;if(Te.has(e))return!0;if(Se.has(e))return!1;if(0===e.length)return Se.add(e),!1;if(!Array.isArray(e[0]))return Se.add(e),!1;const r=e[0].length;if(0===r)return Se.add(e),!1;for(const n of e){if(!Array.isArray(n))return Se.add(e),!1;if(n.length!==r)return Se.add(e),!1;if(t&&n.some(e=>!t(e)))return!1}return qe.add(e),Te.add(e),!0}function Oe(e,t){if(!Me(e))throw new o(`Expected a grid, but got ${e}`,t)}function Ve(e){return Me(e,H)?($e.add(e),!0):(Array.isArray(e)&&Ee.add(e),!1)}function De(e,t){if(!Ve(e))throw new o(`Expected a matrix, but got ${e}`,t)}function Ue(e,t){if(!Ve(e))throw new o(`Expected a matrix, but got ${e}`,t);if(e.length!==e[0].length)throw new o(`Expected square matrix, but got ${e.length} and ${e[0].length}`,t)}function Fe(e,t){let r=!1,n=!1;for(const a of e)if(je(a))r=!0;else if(Ve(a))n=!0;else if(!H(a))throw new o("Invalid parameter type: "+typeof a,t);if(n){if(r)throw new o("Cannot mix vector and matrix types",t);let n=null,a=null;for(const r of e)if(Ve(r))if(null===n)n=r.length,a=r[0].length;else if(r.length!==n||r[0].length!==a)throw new o("Matrix dimensions do not match",t);return["matrix",e.map(e=>Ve(e)?e:Array.from({length:n},()=>Array.from({length:a},()=>e)))]}if(r){let r=null;for(const n of e)if(je(n))if(null===r)r=n.length;else if(n.length!==r)throw new o("Vector lengths do not match",t);return["vector",e.map(e=>je(e)?e:Array.from({length:r},()=>e))]}return["number",e]}function We(e){return(t,r)=>{const[n,o]=Fe(t,r);return"number"===n?e(o[0]):"vector"===n?o[0].map(t=>e(t)):o[0].map(t=>t.map(t=>e(t)))}}function Ge(e){return(t,r)=>{const[n,o]=Fe(t,r);return"number"===n?e(o[0],o[1]):"vector"===n?o[0].map((t,r)=>e(t,o[1][r])):o[0].map((t,r)=>t.map((t,n)=>e(t,o[1][r][n])))}}function Be(e,t){return(r,n)=>{if(0===r.length)return e;const[o,a]=Fe(r,n);if("number"===o)return a.reduce((e,r)=>t(e,r),e);if("vector"===o){const[e,...r]=a;return r.reduce((e,r)=>e.map((e,n)=>t(e,r[n])),e)}{const[e,...r]=a;return r.reduce((e,r)=>e.map((e,n)=>e.map((e,o)=>t(e,r[n][o]))),e)}}}const Le={inc:{evaluate:We(e=>e+1),arity:te(1),docs:{category:"math",returns:{type:"number"},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `inc` function increments its argument by 1, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it increases each element by 1 while preserving the original structure.",seeAlso:["dec","+"],examples:["inc(0)","inc(1)","inc(100.1)","inc([1, 2, 3])","inc([[1, 2], [3, 4]])"]}},dec:{evaluate:We(e=>e-1),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `dec` function decrements its argument by 1, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it decreases each element by 1 while preserving the original structure.",seeAlso:["inc","-"],examples:["dec(0)","dec(1)","dec(100.1)","dec([1, 2, 3])","dec([[1, 2], [3, 4]])"]}},"+":{evaluate:Be(0,(e,t)=>e+t),arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"The `+` function performs addition of numbers and element-wise addition of `vectors` and `matrices` of compatible dimensions, returning the same type as its inputs. When used with mixed types, it adds the scalar to each element of the collection.",seeAlso:["-","*","/","inc"],examples:["1 + 2","1 + 20 + 30","+(1, 2, 3, 4)","+()","+(1)","[1, 2, 3] + 2","[1, 2, 3] + [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] + [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] + 2"]}},"*":{evaluate:Be(1,(e,t)=>e*t),arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"The `*` function performs multiplication of `numbers` and element-wise multiplication of `vectors` and `matrices` of compatible dimensions, returning the same type as its inputs. When used with mixed types, it multiplies each element of the collection by the scalar.",seeAlso:["/","+","-","^"],examples:["6 * 7","-1 * 4","*(4, 7)","*(1, 2, 3, 4, 5)","*()","*(8)","[1, 2, 3] * 2","[1, 2, 3] * [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] * [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] * 2"]}},"/":{evaluate:(e,t)=>{if(0===e.length)return 1;const[r,n]=Fe(e,t);if("number"===r){const[e,...t]=n;return 0===t.length?1/e:t.reduce((e,t)=>e/t,e)}if("vector"===r){const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e/t[r]),e)}{const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e.map((e,n)=>e/t[r][n])),e)}},arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"The `/` function performs division of `numbers` and element-wise division of `vectors` and `matrices` of compatible dimensions, returning the same type as its inputs. When used with mixed types, it divides each element of the collection by the scalar.",seeAlso:["*","+","-","quot","mod","%"],examples:["12 / 100","-1 / 4","/(7, 4)","/(1, 2, 4, 8)","/()","/(8)","[1, 2, 3] / 2","[1, 2, 3] / [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] / [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] / 2"]}},"-":{evaluate:(e,t)=>{if(0===e.length)return 0;const[r,n]=Fe(e,t);if("number"===r){const[e,...t]=n;return 0===t.length?-e:t.reduce((e,t)=>e-t,e)}if("vector"===r){const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e-t[r]),e)}{const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e.map((e,n)=>e-t[r][n])),e)}},arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"Computes difference between first value and sum of the rest. When called with only one argument, it does negation.",seeAlso:["+","*","/","dec","abs"],examples:["50 - 8","1 - 1 - 1","-()","-(4, 2)","-(4, 3, 2, 1,)","[1, 2, 3] - 2","[1, 2, 3] - [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] - [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] - 2"]}},quot:{evaluate:Ge((e,t)=>Math.trunc(e/t)),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The `quot` function performs integer division truncated toward zero, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies integer division between each element of the collection and the scalar.",seeAlso:["mod","%","/","trunc"],examples:["quot(5, 3)","quot(5.2, 3.1)","quot(-5, 3)","5 quot -3","-5 quot -3","quot(5, 0)","quot(0, 5)","[1, 2, 3] quot 2","2 quot [1, 2, 3]","quot([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] quot [[7, 8, 9], [10, 11, 12]]","quot([[1, 2, 3], [4, 5, 6]], 2)","[[1, 2, 3], [4, 5, 6]] quot [[7, 8, 9], [10, 11, 12]]"]}},mod:{evaluate:Ge((e,t)=>e-t*Math.floor(e/t)),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The `mod` function computes the modulo of division with the same sign as the divisor, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies the modulo operation between each element of the collection and the scalar.",seeAlso:["%","quot","/"],examples:["mod(5, 3)","mod(5.2, 3.1)","mod(-5, 3)","5 mod -3","-5 mod -3","[1, 2, 3] mod 2","2 mod [1, 2, 3]","mod([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] mod [[7, 8, 9], [10, 11, 12]]","mod([[1, 2, 3], [4, 5, 6]], 2)"]}},"%":{evaluate:Ge((e,t)=>e%t),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The `%` function computes the remainder of division with the same sign as the dividend, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies the remainder operation between each element of the collection and the scalar.",seeAlso:["mod","quot","/"],examples:["5 % 3","5.2 % 3.1","-5 % 3","%(5, -3)","%(-5, -3)","[1, 2, 3] % 2","2 % [1, 2, 3]","%([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] % [[7, 8, 9], [10, 11, 12]]","%([[1, 2, 3], [4, 5, 6]], 2)"]}},sqrt:{evaluate:We(e=>Math.sqrt(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sqrt` function calculates the square root of `numbers` and computes element-wise square roots of `vectors` and `matrices`. When applied to collections, it returns the square root of each element while preserving the original structure.",seeAlso:["cbrt","^"],examples:["sqrt(0)","sqrt(9)","sqrt(2)","sqrt(0)","sqrt(9)","sqrt(2)","sqrt([1, 4, 9])","sqrt([[1, 4], [9, 16]])"]}},cbrt:{evaluate:We(e=>Math.cbrt(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cbrt` function calculates the cube root of `numbers` and computes element-wise cube roots of `vectors` and `matrices`. When applied to collections, it returns the cube root of each element while preserving the original structure.",seeAlso:["sqrt","^"],examples:["cbrt(0)","cbrt(27)","cbrt(2)","cbrt(1)","cbrt(0)","cbrt(27)","cbrt(2)","cbrt(1)","cbrt([1, 8, 27])","cbrt([[1, 8], [27, 64]])"]}},"^":{evaluate:Ge((e,t)=>e**t),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The ^ function computes exponentiation, raising the first argument to the power of the second, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies the power operation between each element of the collection and the scalar.",seeAlso:["sqrt","cbrt","*","math.ln"],examples:["2 ^ 3","2 ^ 0","2 ^ -3","^(-2, 3)","^(-2, -3)","[1, 2, 3] ^ 2","2 ^ [1, 2, 3]","^([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] ^ [[7, 8, 9], [10, 11, 12]]","^([[1, 2, 3], [4, 5, 6]], 2)"]}},round:{evaluate:([e,t],r)=>{const[n,o]=Fe([e],r);if("number"===n){if(void 0===t||0===t)return Math.round(o[0]);{Y(t,r,{integer:!0,positive:!0});const e=10**t;return Math.round(o[0]*e)/e}}if("vector"===n){const e=o[0];if(void 0===t||0===t)return e.map(e=>Math.round(e));{Y(t,r,{integer:!0,positive:!0});const n=10**t;return e.map(e=>Math.round(e*n)/n)}}{const e=o[0];if(void 0===t||0===t)return e.map(e=>e.map(e=>Math.round(e)));{Y(t,r,{integer:!0,positive:!0});const n=10**t;return e.map(e=>e.map(e=>Math.round(e*n)/n))}}},arity:{min:1,max:2},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:"integer"}},variants:[{argumentNames:["a"]},{argumentNames:["a","b"]}],description:"The `round` function rounds a `number` to the nearest `integer` or to a specified number of `decimal` places, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it rounds each element while preserving the original structure.",seeAlso:["floor","ceil","trunc"],examples:["round(2)","round(2.49)","round(2.5)","round(-2.49)","round(-2.5)","round(-2.501)","round(1.23456789, 4)","1.123456789 round 2","round([1.23456789, 2.3456789], 1)","[1.23456789, 2.3456789] round 4","[[1.23456789, 2.3456789], [3.456789, 4.56789]] round 4","round([[1.23456789, 2.3456789], [3.456789, 4.56789]], 2)"]}},trunc:{evaluate:We(e=>Math.trunc(e)),arity:te(1),docs:{category:"math",returns:{type:["integer","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `trunc` function truncates `numbers` toward zero (removing decimal portions without rounding), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it truncates each element while preserving the original structure.",seeAlso:["round","floor","ceil","quot"],examples:["trunc(2)","trunc(2.49)","trunc(2.5)","trunc(-2.49)","trunc(-2.5)","trunc(-2.501)","trunc([1.23456789, 2.3456789])","trunc([[1.23456789, 2.3456789], [3.456789, 4.56789]])"]}},floor:{evaluate:We(e=>Math.floor(e)),arity:te(1),docs:{category:"math",returns:{type:["integer","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `floor` function returns the largest `integer` less than or equal to a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the floor of each element while preserving the original structure.",seeAlso:["ceil","round","trunc"],examples:["floor(2)","floor(2.49)","floor(2.5)","floor(-2.49)","floor(-2.5)","floor(-2.501)","floor([1.23456789, 2.3456789])","floor([[1.23456789, 2.3456789], [3.456789, 4.56789]])"]}},ceil:{evaluate:We(e=>Math.ceil(e)),arity:te(1),docs:{category:"math",returns:{type:["integer","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `ceil` function returns the smallest `integer` greater than or equal to a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the ceiling of each element while preserving the original structure.",seeAlso:["floor","round","trunc"],examples:["ceil(2)","ceil(2.49)","ceil(2.5)","ceil(-2.49)","ceil(-2.5)","ceil(-2.501)","ceil([1.23456789, 2.3456789])","ceil([[1.23456789, 2.3456789], [3.456789, 4.56789]])"]}},min:{evaluate:(e,t)=>{if(1===e.length&&je(e[0])){const r=e[0];return Pe(r,t),r.reduce((e,t)=>Math.min(e,t),1/0)}const[r,...n]=e;return Y(r,t),n.reduce((e,r)=>(Y(r,t),Math.min(e,r)),r)},arity:{min:1},docs:{category:"math",returns:{type:"number"},args:{a:{type:"number"},b:{type:"number"},xs:{type:"number",rest:!0},vector:{type:"vector"}},variants:[{argumentNames:["xs"]},{argumentNames:["vector"]}],description:"Returns the smallest value. Accepts either multiple numbers or a single vector of numbers.",seeAlso:["max","vector.span","vector.min-index"],examples:["2 min 3","min(2, 0, 1)","min(2, -1, 1)","min([2, 0, -1])","12 min 14"]}},max:{evaluate:(e,t)=>{if(1===e.length&&je(e[0])){const r=e[0];return Pe(r,t),r.reduce((e,t)=>Math.max(e,t),-1/0)}const[r,...n]=e;return Y(r,t),n.reduce((e,r)=>(Y(r,t),Math.max(e,r)),r)},arity:{min:1},docs:{category:"math",returns:{type:"number"},args:{a:{type:"number"},b:{type:"number"},xs:{type:"number",rest:!0},vector:{type:"vector"}},variants:[{argumentNames:["xs"]},{argumentNames:["vector"]}],description:"Returns the largest value. Accepts either multiple numbers or a single vector of numbers.",seeAlso:["min","vector.span","vector.max-index"],examples:["2 max 3","max(2, 0, 1)","max(2, -1, 1)","max([2, 0, -1])","4 max 2"]}},abs:{evaluate:We(e=>Math.abs(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The abs function returns the absolute value (magnitude) of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the absolute value of each element while preserving the original structure.",seeAlso:["sign","-"],examples:["abs(-2.3)","abs(0)","abs(2.5)","abs([1, -2, 3])","abs([[1, -2], [3, -4]])"]}},sign:{evaluate:We(e=>Math.sign(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sign` function returns the `sign` of a `number` (-1 for negative, 0 for zero, 1 for positive), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the sign of each element while preserving the original structure.",seeAlso:["abs"],examples:["sign(-2.3)","sign(-0)","sign(0)","sign(12312)","sign([1, -2, 3])","sign([[1, -2], [3, -4]])"]}}};function _e([e,...t],r){const n=$(e,r);for(const e of t)if(!ie(n,$(e,r),r))return!1;return!0}const Ke={"==":{evaluate:(e,t)=>_e(e,t),arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"},x:{type:"any"},ys:{type:"any",rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if all `values` are structaul equal to each other, otherwise result is `false`.",seeAlso:["!=","identical?"],examples:["1 == 1","[1, 2] == [1, 2]","\n{\n a: 1,\n b: 2,\n} == {\n b: 2,\n a: 1,\n}","==(1, 1)","==(1.01, 1)",'==("1", 1)','==("2", "2", "2", "2")',"==(2, 2, 1, 2)","==([1, 2], [1, 2])","==({ a: 1, b: 2 }, { b: 2, a: 1 })"]}},"!=":{evaluate:(e,t)=>!_e(e,t),arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"},x:{type:"any"},ys:{type:"any",rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if all `values` are not equal to each other, otherwise result is `false`. `(!= a b c)` is same as `(not (== a b c))`.",seeAlso:["==","identical?"],examples:["1 != 2","3 != 3","!=(3)","!=(3, 3, 2)",'!=("3", "2", "1", "0",)',"!=(0, -0)"]}},"identical?":{evaluate:e=>function([e,...t]){for(const r of t)if(r!==e)return!1;return!0}(e),arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"}},variants:[{argumentNames:["a","b"]}],description:"Returns true if $a and $b are referential equal.",seeAlso:["==","!="],examples:["identical?({ a: 10, b: 20 }, { b: 20, a: 10 })","identical?([1, true, null], [1, true, null])","identical?(0.3, 0.1 + 0.2)"]}},">":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)<=0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in decreasing order, `false` otherwise.",seeAlso:["<",">=","<=","compare"],examples:[">(1, 0)",">(1.01, 1)",">(1, 1)",">(4, 3, 2, 1)",">(3, 2, 2, 1)"]}},"<":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)>=0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in increasing order, `false` otherwise.",seeAlso:[">",">=","<=","compare"],examples:["<(0, 1)","<(1, 1.01)","<(1, 1)","<(1, 2, 2, 3)",'<("a", "b")']}},">=":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)<0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in non increasing order, `false` otherwise.",seeAlso:[">","<","<=","compare"],examples:["1 >= 1","0 >= 1",">=(1, 0)",">=(1.01, 1)",">=(1, 1)",">=(4, 3, 2, 1)",">=(3, 2, 2, 1)"]}},"<=":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)>0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in non decreasing order, `false` otherwise.",seeAlso:[">","<",">=","compare"],examples:["1 <= 1","<=(0, 1)","<=(1, 1.01)","<=(1, 1)","<=(1, 2, 3, 4)","<=(1, 2, 2, 3)"]}},not:{evaluate:([e])=>!e,arity:te(1),docs:{category:"misc",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Computes logical negation. Note that any other $x than `false`, `0`, `null` and `''` is truthy.",seeAlso:["boolean"],examples:["not(3)","not(true)",'not("A string")',"not(0)","not(false)","not(null)",'not("")']}},"epoch->iso-date":{evaluate:([e],t)=>(Y(e,t),new Date(e).toISOString()),arity:te(1),docs:{category:"misc",returns:{type:"string"},args:{ms:{type:"number"}},variants:[{argumentNames:["ms"]}],description:"Returns IOS date time string from `ms` (milliseconds elapsed since the UNIX epoch).",seeAlso:["iso-date->epoch"],examples:["epoch->iso-date(1649756230899)","epoch->iso-date(0)"]}},"iso-date->epoch":{evaluate:([e],t)=>{G(e,t);const r=new Date(e).valueOf();return Y(r,t,{finite:!0}),r},arity:te(1),docs:{category:"misc",returns:{type:"number"},args:{iso:{type:"string"}},variants:[{argumentNames:["iso"]}],description:"Returns milliseconds elapsed since the UNIX epoch to `iso`.",seeAlso:["epoch->iso-date"],examples:['iso-date->epoch("2022-04-12T09:37:10.899Z")','iso-date->epoch("1980-01-01")']}},boolean:{evaluate:([e])=>!!e,arity:te(1),docs:{category:"misc",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Coerces $x to boolean.",seeAlso:["not","boolean?","true?","false?"],examples:["boolean(0)","boolean(1)","boolean(null)",'boolean("Albert")']}},compare:{evaluate:([e,t],r)=>(K(e,r),K(t,r),ae(e,t,r)),arity:te(2),docs:{category:"misc",returns:{type:"number"},args:{a:{type:["number","string"]},b:{type:["number","string"]}},variants:[{argumentNames:["a","b"]}],description:"Compares two values. Returns `-1` if $a < $b, `1` if $a > $b and `0` if $a and $b have the same sort order.",seeAlso:["<",">","<=",">=","sort","sequence.sort-by"],examples:["compare(0, 1)","compare(0, 0)","compare(1, 0)",'compare("Albert", "Mojir")']}},"json-parse":{evaluate:([e],t)=>(G(e,t),JSON.parse(e)),arity:te(1),docs:{category:"misc",returns:{type:"any"},args:{x:{type:"string"}},variants:[{argumentNames:["x"]}],description:"Returns `JSON.parse(`$x`)`.",seeAlso:["json-stringify"],examples:['json-parse("[1, 2, 3]")']}},"json-stringify":{evaluate:([e,t],r)=>(E(e,r),void 0===t?JSON.stringify(e):(Y(t,r),JSON.stringify(e,null,t))),arity:{min:1,max:2},docs:{category:"misc",returns:{type:"string"},args:{x:{type:"any"},indent:{type:"integer",description:"Number of spaces to use for indentation."}},variants:[{argumentNames:["x"]},{argumentNames:["x","indent"]}],description:"Returns `JSON.stringify(`$x`)`. If second argument is provided, returns `JSON.stringify(`$x`, null, `$indent`)`.",seeAlso:["json-parse"],examples:["json-stringify([1, 2, 3])","json-stringify({ a: { b: 10 }}, 2)"],hideOperatorForm:!0}},"effect-name":{evaluate:([e],t)=>function(e,t){return D(e,t),e}(e,t).name,arity:te(1),docs:{category:"meta",returns:{type:"string"},args:{e:{type:"any",description:"An effect reference."}},variants:[{argumentNames:["e"]}],description:"Returns the name of an effect reference as a string.",seeAlso:["effect-matcher","effect?"],examples:["effect-name(effect(dvala.error))","effect-name(effect(llm.complete))"]}},"effect-matcher":{evaluate:([e],t)=>{if("string"==typeof e)return{[p]:!0,sourceCodeInfo:t,functionType:"EffectMatcher",matchType:"string",pattern:e,flags:"",arity:te(1)};if(M(e))return{[p]:!0,sourceCodeInfo:t,functionType:"EffectMatcher",matchType:"regexp",pattern:e.s,flags:e.f,arity:te(1)};throw new o("effect-matcher expects a string or regexp pattern",t)},arity:te(1),docs:{category:"meta",returns:{type:"function"},args:{pattern:{type:["string","regexp"],description:"A wildcard pattern or regexp to match against effect names."}},variants:[{argumentNames:["pattern"]}],description:"Returns a predicate function that matches effects by name. If $pattern is a string, uses wildcard matching: no wildcard means exact match, `.*` suffix matches the prefix and all descendants (dot boundary enforced), and `*` alone matches everything. If $pattern is a regexp, tests the effect name against the regexp.",seeAlso:["effect-name","effect?"],examples:['let pred = effect-matcher("dvala.*"); pred(effect(dvala.error))','let pred = effect-matcher("dvala.*"); pred(effect(custom.foo))','let pred = effect-matcher("*"); pred(effect(anything))']}},"type-of":{evaluate:([e])=>null==e?"null":"boolean"==typeof e?"boolean":"number"==typeof e?"number":"string"==typeof e?"string":V(e)?"effect":M(e)?"regexp":q(e)?"function":Array.isArray(e)?"array":"object",arity:te(1),docs:{category:"misc",returns:{type:"string"},args:{x:{type:"any",description:"The value to inspect."}},variants:[{argumentNames:["x"]}],description:'Returns a string representing the type of $x. Possible return values are `"number"`, `"string"`, `"boolean"`, `"null"`, `"array"`, `"object"`, `"function"`, `"regexp"`, and `"effect"`.',seeAlso:["number?","string?","boolean?","null?","array?","object?","function?","regexp?","effect?"],examples:["type-of(42)",'type-of("hello")',"type-of(true)","type-of(null)","type-of([1, 2, 3])","type-of({ a: 1 })","type-of((x) -> x + 1)",'type-of(regexp("^start"))',"type-of(effect(dvala.io.println))"]}}},Je={keys:{evaluate:([e],t)=>(C(e,t),Object.keys(e)),arity:te(1),docs:{category:"object",returns:{type:"any",array:!0},args:{obj:{type:"object"}},variants:[{argumentNames:["obj"]}],description:"Returns array of all keys in $obj.",seeAlso:["vals","entries","zipmap","select-keys"],examples:["keys({})",'keys({ x: 10, y: true, z: "A string" })','keys(object("x", 10, "y", true, "z", "A string"))']}},vals:{evaluate:([e],t)=>(C(e,t),Object.values(e)),arity:te(1),docs:{category:"object",returns:{type:"any",array:!0},args:{obj:{type:"object"}},variants:[{argumentNames:["obj"]}],description:"Returns array of all values in $obj.",seeAlso:["keys","entries","zipmap"],examples:["vals({})",'vals({ x: 10, y: true, z: "A string" })','vals(object("x", 10, "y", true, "z", "A string"))']}},entries:{evaluate:([e],t)=>(C(e,t),Object.entries(e)),arity:te(1),docs:{category:"object",returns:{type:"array"},args:{obj:{type:"object"}},variants:[{argumentNames:["obj"]}],description:"Returns nested array of all key - value pairs in $obj.",seeAlso:["keys","vals","zipmap","find"],examples:["entries({})",'entries({ x: 10, y: true, z: "A string" })','entries(object("x", 10, "y", true, "z", "A string"))']}},find:{evaluate:([e,t],r)=>(C(e,r),G(t,r),oe(e,t)?[t,e[t]]:null),arity:te(2),docs:{category:"object",returns:{type:["array","null"]},args:{a:{type:"object"},b:{type:"string"},obj:{type:"object"},key:{type:"string"}},variants:[{argumentNames:["obj","key"]}],description:"Returns entry (key-value pair) for $key, or `null` if $key not present in $obj.",seeAlso:["get","contains?","entries","sequence.position","some"],examples:['{ a: 1, "b": 2 } find "a"','find(object("a", 1, "b", 2), "b")','find(object("a", 1, "b", 2), "c")']}},dissoc:{evaluate:([e,t],r)=>{C(e,r),G(t,r);const n={...e};return delete n[t],n},arity:te(2),docs:{category:"object",returns:{type:"object"},args:{a:{type:"object"},b:{type:"string"},obj:{type:"object"},key:{type:"string"}},variants:[{argumentNames:["obj","key"]}],description:"Return shallow copy of $obj with $key deleted.",seeAlso:["assoc","select-keys"],examples:['{ x: 10, y: 20 } dissoc "y"','dissoc({ x: 10, y: 20 }, "x")','dissoc({ x: 10 }, "y")','\nlet o = { a: 5 };\ndissoc(o, "a");\no']}},merge:{evaluate:(e,t)=>{if(0===e.length)return null;const[r,...n]=e;return C(r,t),n.reduce((e,r)=>(C(r,t),{...e,...r}),{...r})},arity:{min:0},docs:{category:"object",returns:{type:"object"},args:{a:{type:"object"},b:{type:"object"},objs:{type:"object",rest:!0}},variants:[{argumentNames:["objs"]}],description:"Returns a new object created by merging together all arguments.\n\nIf two keys appears in more than one object the value from the last object is used.\nIf no arguments are provided `null` is returned.",seeAlso:["merge-with","assoc"],examples:["{ x: 10 } merge { y: 20 }",'merge(object("x", 10), object("y", 20))','merge(object("x", 10), object("x", 15, "y", 20))']}},"merge-with":{evaluate:()=>{throw new Error("merge-with is implemented in Dvala")},arity:{min:2},docs:{category:"object",returns:{type:"object"},args:{objs:{type:"object",rest:!0},fun:{type:"function"}},variants:[{argumentNames:["objs","fun"]}],description:"\nReturns a new object created by merging together all arguments.\nIf two keys appears in more than one object $fun is used to calculate the new value.\n\nIf no arguments are provided `null` is returned.",seeAlso:["merge"],examples:['merge-with(object("x", 10), object("y", 20), +)','merge-with(object("x", 10), object("x", 15, "y", 20), +)',"merge-with({ x: 10 }, { x: 20 }, { x: 30 }, { x: 40 }, -)"],hideOperatorForm:!0}},zipmap:{evaluate:([e,t],r)=>{ve(e,r),ye(t,r);const n=Math.min(e.length,t.length),o={};for(let a=0;a<n;a+=1){o[B(e[a],r)]=le(t[a])}return o},arity:te(2),docs:{category:"object",returns:{type:"object"},args:{a:{type:"array"},b:{type:"array"}},variants:[{argumentNames:["a","b"]}],description:"Returns a new object created by mapping $a to $b.",seeAlso:["entries","keys","vals","sequence.interleave"],examples:['["a", "b", "c"] zipmap [1, 2, 3]','zipmap(["a", "b", "c"], [10, null, [1, 2, 3]])','zipmap(["a", "b", "c"], [1])',"zipmap([], [10, null, [1, 2, 3]])"]}},"select-keys":{evaluate:([e,t],r)=>(ve(t,r),C(e,r),t.reduce((t,r)=>(oe(e,r)&&(t[r]=le(e[r])),t),{})),arity:te(2),docs:{category:"object",returns:{type:"object"},args:{a:{type:"object"},b:{type:"array"}},variants:[{argumentNames:["a","b"]}],description:"Returns an object containing only those entries in $a whose key is in $b.",seeAlso:["dissoc","keys"],examples:['{ a: 1, b: 2, c: 3 } select-keys ["a", "b"]','select-keys({ a: 1, b: 2, c: 3 }, ["a", "b"])','select-keys({ a: 1 }, ["a", "b"])']}}},He={"function?":{evaluate:([e])=>q(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a function, otherwise `false`.",seeAlso:["string?","number?","boolean?","null?","array?","object?","regexp?","type-of"],examples:["function?(+)","function?(/)","function?((x, y) -> x + y)","function?(false)",'function?("false")',"function?([1, 2, 3])"]}},"string?":{evaluate:([e])=>"string"==typeof e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a string, otherwise `false`.",seeAlso:["blank?","number?","boolean?","null?","array?","object?","regexp?","function?","collection?","sequence?","type-of"],examples:['string?("")','string?("A string")','string?(true ? "A string" : false)',"string?(false)","string?([1, 2, 3])","string?(100)"]}},"number?":{evaluate:([e])=>"number"==typeof e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a number, otherwise `false`.",seeAlso:["integer?","zero?","pos?","neg?","finite?","number","string?","boolean?","null?","function?","type-of"],examples:["number?(0)","number?(2)","number?(-0.12)","number?(false)","number?([1, 2, 3])",'number?("A string")']}},"integer?":{evaluate:([e])=>"number"==typeof e&&H(e,{integer:!0}),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an integer, otherwise `false`.",seeAlso:["number?","number","even?","odd?"],examples:["integer?(0)","integer?(-12)","integer?(42)","integer?(10.1)","integer?((x, y) -> x + y)","integer?(false)",'integer?("false")',"integer?([1, 2, 3])"]}},"boolean?":{evaluate:([e])=>"boolean"==typeof e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a `boolean`, otherwise `false`.",seeAlso:["true?","false?","boolean","string?","number?","null?","function?","type-of"],examples:["boolean?(true)","boolean?(false)","boolean?([1, 2, 3])","boolean?(0)",'boolean?("A string")']}},"null?":{evaluate:([e])=>null==e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `null`, otherwise `false`.",seeAlso:["empty?","not-empty?","string?","number?","boolean?","function?","type-of"],examples:["null?(null)","null?(false)","null?([1, 2, 3])","null?(0)",'null?("A string")']}},"zero?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),Math.abs(e)<de),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `0`, otherwise `false`.",seeAlso:["pos?","neg?","even?","number?"],examples:["zero?(0)","zero?(-0.0)","zero?(1)","zero?(0.1)"]}},"pos?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),e>0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is greater than `0`, otherwise `false`.",seeAlso:["neg?","zero?","number?"],examples:["pos?(0)","pos?(-0.0)","pos?(1)","pos?(-0.1)"]}},"neg?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),e<0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is less than `0`, otherwise `false`.",seeAlso:["pos?","zero?","number?"],examples:["neg?(0)","neg?(-0.0)","neg?(1)","neg?(-0.1)"]}},"even?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),e%2==0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is even, otherwise `false`.",seeAlso:["odd?","integer?","zero?"],examples:["even?(0)","even?(-0.0)","even?(-1)","even?(2.1)"]}},"odd?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),H(e,{integer:!0})&&e%2!=0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is odd, otherwise `false`.",seeAlso:["even?","integer?"],examples:["odd?(1.0)","odd?(1.001)","odd?(-1)","odd?(2.1)"]}},"array?":{evaluate:([e])=>Array.isArray(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an array, otherwise `false`.",seeAlso:["sequence?","collection?","object?","string?","vector?","matrix?","grid?","function?","type-of"],examples:["array?([])","array?([1, 2, 3])",'array?(object("a", 10))',"array?(42)","array?(10.1)","array?((x, y) -> x + y)"]}},"collection?":{evaluate:([e])=>I(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a collection i.e. an array, an object or a string, otherwise `false`.",seeAlso:["sequence?","array?","object?","string?"],examples:["collection?([])","collection?([1, 2, 3])",'collection?(object("a", 10))','collection?("Albert")',"collection?(42)","collection?(10.1)","collection?((x, y) -> x + y)"]}},"sequence?":{evaluate:([e])=>T(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a sequence i.e. an array or a string, otherwise `false`.",seeAlso:["collection?","array?","string?"],examples:["sequence?([])","sequence?([1, 2, 3])",'sequence?(object("a", 10))','sequence?("Albert")',"sequence?(42)","sequence?(10.1)","sequence?((x, y) -> x + y)"]}},"object?":{evaluate:([e])=>j(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an object, otherwise `false`.",seeAlso:["collection?","array?","string?","function?","type-of"],examples:['object?(object("a", 10))',"object?(42)","object?(10.1)","object?((x, y) -> x + y)",'object?(#"^start")','object?("false")',"object?([1, 2, 3])"]}},"regexp?":{evaluate:([e])=>M(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a regexp, otherwise `false`.",seeAlso:["regexp","re-match","string?","function?","type-of"],examples:['regexp?(regexp("^start"))','regexp?(#"^start")',"regexp?(-12)","regexp?({})","regexp?(10.1)","regexp?((x, y) -> x + y)","regexp?(false)",'regexp?("false")',"regexp?([1, 2, 3])"]}},"effect?":{evaluate:([e])=>V(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an effect, otherwise `false`.",seeAlso:["effect","effect-name","effect-matcher","perform","type-of"],examples:["effect?(effect(dvala.io.println))","effect?(42)",'effect?("hello")',"effect?(null)","effect?({})","effect?([1, 2, 3])"]}},"finite?":{evaluate:([e],t)=>(Y(e,t),Number.isFinite(e)),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is finite, otherwise `false`.",seeAlso:["positive-infinity?","negative-infinity?","number?"],examples:["finite?(1.0)","finite?(1 / 0)","finite?(-1 / 0)"]}},"positive-infinity?":{evaluate:([e],t)=>(Y(e,t),e===Number.POSITIVE_INFINITY),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x equals positive infinity, otherwise `false`.",seeAlso:["negative-infinity?","finite?"],examples:["positive-infinity?(1.0)","positive-infinity?(1 / 0)","positive-infinity?(-1 / 0)"]}},"negative-infinity?":{evaluate:([e],t)=>(Y(e,t),e===Number.NEGATIVE_INFINITY),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x equals negative infinity, otherwise `false`.",seeAlso:["positive-infinity?","finite?"],examples:["negative-infinity?(1.0)","negative-infinity?(1 / 0)","negative-infinity?(-1 / 0)"]}},"true?":{evaluate:([e])=>!0===e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `true`, otherwise `false`.",seeAlso:["false?","boolean?","boolean"],examples:["true?(false)","true?(true)","true?(1)","true?(0)"]}},"false?":{evaluate:([e])=>!1===e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `true`, otherwise `false`.",seeAlso:["true?","boolean?","boolean"],examples:["false?(false)","false?(true)","false?(1)","false?(0)"]}},"empty?":{evaluate:([e],t)=>null===e||(P(e,t),"string"==typeof e||Array.isArray(e)?0===e.length:0===Object.keys(e).length),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:["collection","string","null"]}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is empty or `null`, otherwise `false`.",seeAlso:["not-empty?","collection.not-empty","null?","blank?","count"],examples:["empty?([])","empty?([1, 2, 3])","empty?({})","empty?({ a: 2 })",'empty?("")','empty?("Albert")',"empty?(null)"]}},"not-empty?":{evaluate:([e],t)=>null!==e&&(P(e,t),"string"==typeof e||Array.isArray(e)?e.length>0:Object.keys(e).length>0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:["collection","string","null"]}},variants:[{argumentNames:["x"]}],description:"Returns `false` if $x is empty or `null`, otherwise `true`.",seeAlso:["empty?","collection.not-empty","null?"],examples:["not-empty?([])","not-empty?([1, 2, 3])","not-empty?({})","not-empty?({ a: 2 })",'not-empty?("")','not-empty?("Albert")',"not-empty?(null)"]}},"vector?":{evaluate:([e])=>je(e),arity:te(1),docs:{category:"predicate",description:"Checks if a value is a `vector`. A `vector` is an array of `numbers`.",seeAlso:["matrix?","grid?","array?"],returns:{type:"boolean"},args:{value:{type:"any",description:"The value to check."}},variants:[{argumentNames:["value"]}],examples:["vector?(1)","vector?([1, 2, 3])",'vector?([1, 2, "3"])']}},"matrix?":{evaluate:([e])=>Ve(e),arity:te(1),docs:{category:"predicate",description:"Checks if a value is a `matrix`. A `matrix` is an array of arrays of `numbers`.",seeAlso:["vector?","grid?","array?"],returns:{type:"boolean"},args:{value:{type:"any",description:"The value to check."}},variants:[{argumentNames:["value"]}],examples:["matrix?(1)","matrix?([1, 2, 3])","matrix?([[1, 2], [3, 4]])",'matrix?([[1, 2], [3, "4"]])',"matrix?([[1, 2], [3]])"]}},"grid?":{evaluate:([e])=>Me(e),arity:te(1),docs:{category:"predicate",description:"Checks if a `value` is a `grid`. A `grid` is an `array` of `arrays` where all inner `arrays` have the same length.",seeAlso:["vector?","matrix?","array?"],returns:{type:"boolean"},args:{value:{type:"any",description:"The value to check."}},variants:[{argumentNames:["value"]}],examples:['grid?("1")','grid?(["1", 2, 3])','grid?([["1", 2], [3, 4]])','grid?([["1", 2], [3, "4"]])','grid?([["1", 2], [3]])']}}},Ye={regexp:{evaluate:([e,t],r)=>{G(e,r);const n=e||"(?:)",a="string"==typeof t?t:"";try{new RegExp(n,a)}catch(e){throw new o(`Invalid regular expression: ${n} ${a}`,r)}return{[d]:!0,sourceCodeInfo:r,s:n,f:a}},arity:{min:1,max:2},docs:{category:"regular-expression",returns:{type:"regexp"},args:{pattern:{type:"string"},flags:{type:"string",description:"Optional flags for the regular expression. Possible values are the same as Javascript RegExp takes."}},variants:[{argumentNames:["pattern"]},{argumentNames:["pattern","flags"]}],description:"Creates a RegExp from $pattern and $flags.",examples:['regexp("^\\s*(.*)$")','#"^\\s*(.*)$"','regexp("albert", "ig")','#"albert"ig'],seeAlso:["-short-regexp","re-match","replace","replace-all","regexp?"],hideOperatorForm:!0}},"re-match":{evaluate:([e,t],r)=>{if(function(e,t){if(!M(e))throw b("RegularExpression",e,t)}(t,r),!W(e))return null;const n=new RegExp(t.s,t.f).exec(e);return n?[...n]:null},arity:te(2),docs:{category:"regular-expression",returns:{type:"any"},args:{a:{type:"regexp"},b:{type:"string"}},variants:[{argumentNames:["a","b"]}],description:"Matches $b against regular expression $a.\nIf $b is a string and matches the regular expression, a `re-match`-array is returned, otherwise `null` is returned.",seeAlso:["regexp","replace","replace-all","-short-regexp","regexp?"],examples:['re-match(" A string", regexp("^\\\\s*(.*)$"))','re-match(" A string", #"^\\s*(.*)$")','re-match("My name is Albert", #"albert"i)','re-match("My name is Ben", #"albert"i)','re-match(null, #"albert"i)','re-match(1, #"albert"i)','re-match({}, #"albert"i)']}},replace:{evaluate:([e,t,r],n)=>{G(e,n),O(t,n),G(r,n);const o=M(t)?new RegExp(t.s,`${t.f}`):t;return e.replace(o,r)},arity:te(3),docs:{category:"regular-expression",returns:{type:"string"},args:{a:{type:"string"},b:{type:["regexp","string"]},x:{type:"string"}},variants:[{argumentNames:["a","b","x"]}],description:"Returns a new string with first match of regular expression $b replaced by $x.",seeAlso:["replace-all","regexp","re-match","-short-regexp"],examples:['replace("Duck duck", "u", "i")','replace("Duck duck", #"u", "i")','replace("abcABC", regexp("a", "i"), "-")','replace("abcABC", regexp("a", "gi"), "-")','replace("abcABC", #"a"i, "-")','replace("abcABC", #"a"gi, "-")']}},"replace-all":{evaluate:([e,t,r],n)=>{G(e,n),O(t,n),G(r,n);const o=M(t)?new RegExp(t.s,`${t.f.includes("g")?t.f:`${t.f}g`}`):t;return e.replaceAll(o,r)},arity:te(3),docs:{category:"regular-expression",returns:{type:"string"},args:{a:{type:"string"},b:{type:["regexp","string"]},x:{type:"string"}},variants:[{argumentNames:["a","b","x"]}],description:"Returns a new string with all matches of regular expression $b replaced by $x.",seeAlso:["replace","regexp","re-match","-short-regexp"],examples:['replace-all("Duck duck", "u", "i")','replace-all("Duck duck", regexp("u"), "i")','replace-all("abcABC", regexp("a", "i"), "-")','replace-all("abcABC", regexp("a", "gi"), "-")','replace-all("abcABC", #"a"i, "-")','replace-all("abcABC", #"a"gi, "-")']}}},Xe=/^\s*$/,Qe={str:{evaluate:e=>e.reduce((e,t)=>e+(null==t?"":j(t)||Array.isArray(t)?JSON.stringify(t):`${t}`),""),arity:{},docs:{category:"string",returns:{type:"string"},args:{values:{type:"any",rest:!0}},variants:[{argumentNames:["values"]}],description:"Concatenats $values into one string. If `value` equals `null` empty string is returned.",seeAlso:["++","join","string.template","string.string-repeat","number"],examples:['str("A string", ", and another string", " ...and more")','str("Just one string")',"str()",'str(0, false, true, null, #"^kalle", [1, 2, 3], {a: "a"})'],hideOperatorForm:!0}},number:{evaluate:([e],t)=>{G(e,t);const r=Number(e);if(Number.isNaN(r))throw new o(`Could not convert '${e}' to a number.`,t);return r},arity:te(1),docs:{category:"string",returns:{type:"number"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Parses $s to a number.",seeAlso:["str","number?","integer?"],examples:['number("10")','number("010")','number("-1.01")']}},"lower-case":{evaluate:([e],t)=>(G(e,t),e.toLowerCase()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns $s converted to lower case.",seeAlso:["upper-case","string.capitalize"],examples:['lower-case("Albert")','lower-case("")']}},"upper-case":{evaluate:([e],t)=>(G(e,t),e.toUpperCase()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns $s converted to upper case.",seeAlso:["lower-case","string.capitalize"],examples:['upper-case("Albert")','upper-case("")']}},trim:{evaluate:([e],t)=>(G(e,t),e.trim()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a new string with leading and trailing whitespaces removed.",seeAlso:["string.trim-left","string.trim-right","blank?"],examples:['trim(" Albert ")','trim(" ")','trim("")']}},join:{evaluate:([e,t],r)=>(ye(e,r),e.forEach(e=>K(e,r)),G(t,r),e.join(t)),arity:te(2),docs:{category:"string",returns:{type:"string"},args:{a:{type:"array"},b:{type:"string"},arr:{type:"array"},delimiter:{type:"string"}},variants:[{argumentNames:["arr","delimiter"]}],description:"Returns a new string by concatenating all of the elements in $arr, separated by $delimiter.",seeAlso:["split","str","++","sequence.interpose"],examples:['map([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], str) join ", "','([0, 1, 2, 3, 4, 5, 6, 7, 8, 9] map str) join ", "','join(["Albert", 10], ", ")','join(["Albert", "Mojir"], " ")','join(map([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], str), ", ")']}},split:{evaluate:([e,t,r],n)=>{G(e,n),O(t,n),void 0!==r&&Y(r,n,{integer:!0,nonNegative:!0});const o="string"==typeof t?t:new RegExp(t.s,t.f);return e.split(o,r)},arity:{min:2,max:3},docs:{category:"string",returns:{type:"string",array:!0},args:{a:{type:"string"},b:{type:"string"},s:{type:"string"},delimiter:{type:"string"},limit:{type:"integer"}},variants:[{argumentNames:["s","delimiter"]},{argumentNames:["s","delimiter","limit"]}],description:"Divides $s into an array of substrings. The division is done by searching for `delimiter`. If `limit` as provided, at most `limit` number of substrings are returned.",seeAlso:["join","string.split-lines"],examples:['"Albert Mojir" split " "','split("Albert Mojir", " ")','split("abcdefghijklmnopqrstuvw", #"[aoueiy]")','split("0123456789", "")','split("0123456789", "", 5) map number']}},"blank?":{evaluate:([e],t)=>null===e||(G(e,t),Xe.test(e)),arity:te(1),docs:{category:"string",returns:{type:"boolean"},args:{s:{type:["string","null"]}},variants:[{argumentNames:["s"]}],description:"Returns true if $s is null or only contains whitespace characters.",seeAlso:["trim","empty?","string?"],examples:['blank?("")',"blank?(null)",'blank?("\n")','blank?(" ")','blank?(".")']}}},Ze={"|>":{evaluate:()=>{throw new Error("|> is implemented in Dvala")},arity:te(2),docs:{category:"functional",returns:{type:"any"},args:{a:{type:"any"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Takes a value $a and a function $b, and returns the result of applying $b to $a.",seeAlso:["apply","comp"],examples:["\n1 |> inc |> inc","range(10)\n |> map(_, -> $ ^ 2) // [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n |> filter(_, odd?) // [1, 9, 25, 49, 81]\n |> reduce(_, +, 0) // 165\n |> sqrt // 12.84523257866513\n |> round(_, 2)"]}},apply:{evaluate:()=>{throw new Error("apply is implemented in Dvala")},arity:{min:2},docs:{category:"functional",returns:{type:"any"},args:{a:{type:"function"},b:{type:"array"},fun:{type:"function"},args:{type:"array"}},variants:[{argumentNames:["fun","args"]}],description:"Call supplied function $fun with specified arguments $args.",seeAlso:["|>"],examples:["\napply(+, [1, 2, 3])","\napply(\n (x, y) -> sqrt(x ^ 2 + y ^ 2),\n [3, 4]\n)","\n(x, y) -> sqrt(x ^ 2 + y ^ 2) apply [3, 4]"]}},identity:{evaluate:([e])=>le(e),arity:te(1),docs:{category:"functional",returns:{type:"any"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns $x.",seeAlso:["constantly","functional.fnull"],examples:["identity(1)",'identity("Albert")',"identity({ a: 1 })","identity(null)"]}},comp:{evaluate:(e,t)=>(e.forEach(e=>F(e,t)),{[p]:!0,sourceCodeInfo:t,functionType:"Comp",params:e,arity:e.length>0?Z(e.at(-1)):{min:1,max:1}}),arity:{},docs:{category:"functional",returns:{type:"function"},args:{a:{type:"function"},b:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fns"]}],description:"Takes a variable number of functions and returns a function that is the composition of those.\n\n The returned function takes a variable number of arguments,\n applies the rightmost function to the args,\n the next function (right-to-left) to the result, etc.",seeAlso:["|>","functional.juxt","functional.complement"],examples:["\nlet negative-quotient = comp(-, /);\nnegative-quotient(9, 3)",'\nlet x = { bar: { foo: 42 } };\ncomp("foo", "bar")(x)']}},constantly:{evaluate:([e],t)=>({[p]:!0,sourceCodeInfo:t,functionType:"Constantly",value:le(e),arity:{}}),arity:te(1),docs:{category:"functional",returns:{type:"function"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns a function that takes any number of arguments and always returns $x.",seeAlso:["identity","functional.fnull"],examples:["\nlet always-true = constantly(true);\nalways-true(9, 3)"]}}};function et(e){return fe(`\n ${e.title}\n\n ${e.description.replace(/`(.+?)`/g,"$1").replace(/\$(\w+)/g,"$1").replace(/\*\*\*(.+)\*\*\*/g,"$1").replace(/\*\*(.+)\*\*/g,"$1")}\n\n Signature:\n ${function(e){const{title:t,variants:r,args:n,returns:o}=e,a=!tt(e)&&e._isOperator,i=r.map(r=>{if(tt(e)){const e=r.argumentNames.length>0?`, ${r.argumentNames.map(e=>{let t="";return n[e].rest&&(t+="..."),t+=e,t}).join(", ")}`:"";return` perform(effect(${t})${e}) -> ${rt(o)}`}return`${` ${t}(${r.argumentNames.map(e=>{let t="";return n[e].rest&&(t+="..."),t+=e,t}).join(", ")})`} -> ${rt(o)}`}),s=a?["","Operator:",` a ${t} b -> ${rt(o)}`]:[];return[...i,...s]}(e).join("\n ")}\n\n Arguments:\n ${function(e){return Object.entries(e.args).map(([e,t])=>`${e}: ${rt(t)}`)}(e).join("\n ")}\n\n Examples:\n${e.examples.map(e=>fe(e,4)).join("\n\n")}`)}function tt(e){return"effect"in e}function rt(e){const t=e.type,r=(Array.isArray(t)?t:[t]).join(" | ");return e.array||e.rest?`Array<${r}>`:r}const nt={sum:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>e+t,0)),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to sum."}},variants:[{argumentNames:["vector"]}],description:"Returns the **sum** of all elements in the `vector`. Returns `0` for an empty vector.",seeAlso:["prod","mean","median","vector.moving-sum","vector.centered-moving-sum","vector.running-sum","vector.cumsum"],examples:["sum([1, 2, 3, 4, 5])","sum([1, -2, 3])","sum([])"]}},prod:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>e*t,1)),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to multiply."}},variants:[{argumentNames:["vector"]}],description:"Returns the **product** of all elements in the `vector`. Returns `1` for an empty vector.",seeAlso:["sum","mean","median","vector.moving-prod","vector.centered-moving-prod","vector.running-prod","vector.cumprod"],examples:["prod([1, 2, 3, 4, 5])","prod([1, -2, 3])","prod([])"]}},mean:{evaluate:([e],t)=>(Pe(e,t),e.reduce((e,t)=>e+t,0)/e.length),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to calculate the mean of."}},variants:[{argumentNames:["vector"]}],description:"Returns the arithmetic **mean** of all elements in the `vector`. Throws for an empty vector.",seeAlso:["median","sum","prod","vector.moving-mean","vector.centered-moving-mean","vector.running-mean","vector.geometric-mean","vector.harmonic-mean","vector.rms","vector.mode"],examples:["mean([1, 2, 3, 4, 5])","mean([1, -2, 3])"]}},median:{evaluate:([e],t)=>(Pe(e,t),function(e){const t=[...e].sort((e,t)=>e-t),r=Math.floor(t.length/2);return t.length%2==0?(t[r-1]+t[r])/2:t[r]}(e)),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to calculate the median of."}},variants:[{argumentNames:["vector"]}],description:"Returns the **median** of all elements in the `vector`. For even-length vectors, returns the average of the two middle values. Throws for an empty vector.",seeAlso:["mean","sum","prod","vector.moving-median","vector.centered-moving-median","vector.running-median","vector.mode","vector.quartiles","vector.percentile","vector.iqr","vector.medad"],examples:["median([1, 2, 3, 4, 5])","median([1, 2, 3, 4])","median([3, 1, 4, 1, 5])"]}}},ot={...J,...ne,...we,...xe,...ke,...Le,...function(e,t){return{doc:{evaluate:([r],n)=>{if(x(e),V(r)){const e=`-effect-${r.name}`,n=t[e];return n?et(n):""}if(F(r,n),!q(r))return"";if("Builtin"===r.functionType){const t=e[r.name];return t?et(t):""}return"UserDefined"===r.functionType?r.docString:""},arity:te(1),docs:{category:"meta",returns:{type:"string"},args:{value:{type:["function","effect"]}},variants:[{argumentNames:["value"]}],description:"Returns documentation string of the $value. Works on functions and effects.",seeAlso:["arity","with-doc"],examples:["doc(+)","doc(effect(dvala.io.println))",'let add = (x, y) -> x + y with-doc "Adds two numbers.";\ndoc(add)']}},"with-doc":{evaluate:([e,t],r)=>{if(F(e,r),G(t,r),!q(e)||"UserDefined"!==e.functionType)throw new Error("with-doc can only be used with user-defined functions");return{...e,[p]:!0,docString:t}},arity:te(2),docs:{category:"meta",returns:{type:"function"},args:{a:{type:"function"},b:{type:"string"}},variants:[{argumentNames:["a","b"]}],description:"Returns a new function with the documentation string $b attached. The original function is not modified.",seeAlso:["doc"],examples:['((x, y) -> x + y) with-doc "Adds two numbers."','let add = (x, y) -> x + y;\nadd with-doc "Adds x and y."']}},arity:{evaluate:([e],r)=>{if(V(e)){const r=`-effect-${e.name}`,n=t[r];if(!n)return{};const o=n.variants.map(e=>e.argumentNames.length);return{min:Math.min(...o),max:Math.max(...o)}}return F(e,r),q(e)?e.arity:te(1)},arity:te(1),docs:{category:"meta",returns:{type:"object"},args:{value:{type:["function","effect"]}},variants:[{argumentNames:["value"]}],description:"Returns arity of the $value. The arity is an object with the properties: `min` and `max`. If the function has fixed arity, `min` and `max` are equal to the number of required parameters. If no restrictions apply, empty object is returned. Also works on effects.",seeAlso:["doc"],examples:["arity(+)","arity(defined?)","arity(effect(dvala.random.int))","\nlet add = (x, y = 0) -> do\n x + y;\nend;\n\narity(add)","\nlet foo = (k, ...x) -> do\n k + x;\nend;\n arity(foo)"]}}}}({},{}),...Ke,...Je,...He,...Ye,...Qe,...Ze,...nt};Object.entries(ot).forEach(([e,t])=>{t.name=e});const at={...ot},it={},st=[];Object.entries(at).forEach(([e,t],r)=>{it[e]=r,st.push(t)});const lt={arity:{},docs:{category:"special-expression",returns:{type:"any"},args:{a:{type:"any"},b:{type:"any"},c:{type:"any",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"\nComputes logical `and`. Evaluation of expressions starts from left.\nAs soon as an `expression` evaluates to a falsy value, the result is returned.\n\nIf all expressions evaluate to truthy values, the value of the last expression is returned.",examples:["true && 1","&&(1, 1)",'&&(3 > 2, "string")','&&(3 < 2, "string")',"&&(true, true, true, true)","&&(true, true, 0, true)"]},evaluateAsNormalExpression:(e,t)=>{let r=!0;for(const n of e)if(r=$(n,t),!r)break;return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},ct={arity:{},docs:{category:"special-expression",customVariants:["cond cond-branch cond-branch ... end"],details:[["cond-branch","case test then body","A branch of the cond expression."],["test","expression","The condition to test."],["body","expressions","The expressions to evaluate if the test is truthy."]],description:"Used for branching. `cond-branches` are tested sequentially from the top. If no branch is tested truthy, `null` is returned.",examples:['\ncond\n case false then "FALSE"\n case true then "TRUE"\nend','\ncond\n case false then "FALSE"\n case null then "null"\nend ?? "TRUE"','\ncond\n case false then "FALSE"\n case null then "null"\nend ?? "TRUE"']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1].flat(),t,n,o)},ut=11,mt=12,pt=13,dt=14,ht=15,gt=16;function ft(e,t){return e instanceof Promise?e.then(t):t(e)}async function yt(e,t,r,n,o){t.push(await e);for(let e=o+1;e<r.length;e++)t.push(await n(r[e],e));return t}function vt(e,t,r){let n=r;for(let r=0;r<e.length;r++){const o=t(n,e[r],r);if(o instanceof Promise)return bt(o,e,t,r);n=o}return n}async function bt(e,t,r,n){let o=await e;for(let e=n+1;e<t.length;e++)o=await r(o,t[e],e);return o}function wt(e,t){for(let r=0;r<e.length;r++){const n=t(e[r],r);if(n instanceof Promise)return xt(n,e,t,r)}}async function xt(e,t,r,n){await e;for(let e=n+1;e<t.length;e++)await r(t[e],e)}function kt(e,t){try{const r=e();return r instanceof Promise?r.catch(t):r}catch(e){return t(e)}}function qt(e,t){if(e[0]===pt)Object.values(e[1][0]).forEach(e=>{e[1][1]&&t(e[1][1]),qt(e,t)});else if(e[0]===dt)for(let r=0;r<e[1][0].length;r+=1){const n=e[1][0][r]??null;null!==n&&(n[1][1]&&t(n[1][1]),qt(n,t))}}function At(e,t,r){const n=e[2],o={};return ft(Nt(e,t,r,n,o),()=>o)}function Nt(e,t,r,n,a){if(e[0]===pt){!function(e,t){if(!k(e))throw new o(`Expected UnknownRecord, got ${y(e)}.`,v(e,t))}(t,n);const i=new Set;let s;return ft(wt(Object.entries(e[1][0]),([e,o])=>{if(o[0]===mt)return void(s=o);i.add(e);const l=t[e];return ft(void 0!==l?l:o[1][1]?r(o[1][1]):null,e=>{const t=e??null;return E(t,n),Nt(o,t,r,n,a)})}),()=>{if(s){const e=Object.entries(t).filter(([e])=>!i.has(e)).reduce((e,[t,r])=>(e[t]=$(r),e),{});a[s[1][0]]=e}})}if(e[0]===dt){let o=null;ye(t,n);const i=[];for(let t=0;t<e[1][0].length;t+=1){const r=e[1][0][t]??null;if(null!==r){if(r[0]===mt){o=t;break}i.push({element:r,index:t})}}return ft(wt(i,({element:e,index:o})=>{const i=t[o];return ft(void 0!==i?i:e[1][1]?r(e[1][1]):null,t=>{const o=t??null;return E(o,n),Nt(e,o,r,n,a)})}),()=>{if(null!==o){const r=t.slice(o),n=e[1][0][o];a[n[1][0]]=r}})}e[0]===mt?a[e[1][0]]=$(t):a[e[1][0][1]]=$(t)}function $t(e){const t={};return Et(e,t),t}function Et(e,t){if(null!==e)if(e[0]===dt)for(const r of e[1][0])Et(r,t);else if(e[0]===pt)for(const r of Object.values(e[1][0]))Et(r,t);else if(e[0]===mt){if(t[e[1][0]])throw new o(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0]]=!0}else if(e[0]===ut){if(t[e[1][0][1]])throw new o(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0][1]]=!0}}function Tt(e,t,r){const n={};return ft(St(e,t,r,n),e=>e?n:null)}function St(e,t,r,n){if(e[0]===gt)return!0;if(e[0]===ht){const n=e[1][0];return ft(r(n),e=>ie(t,e))}if(e[0]===ut){const o=e[1][0],a=e[1][1];if(null==t){if(a)return ft(r(a),e=>(n[o[1]]=$(e),!0));n[o[1]]=t??null}else n[o[1]]=$(t);return!0}if(e[0]===pt){if(!k(t))return!1;const o=new Set;let a;const i=Object.entries(e[1][0]);let s=!0;for(const[e,l]of i)s=ft(s,i=>{if(!i)return!1;if(l[0]===mt)return a=l,!0;o.add(e);const s=t[e];if(void 0===s&&l[0]===ht)return ft(r(l[1][0]),e=>ie(void 0,e));return ft(void 0!==s?s:l[1]&&l[1][1]?r(l[1][1]):null,e=>St(l,e??null,r,n))});return ft(s,e=>{if(!e)return!1;if(a){const e=Object.entries(t).filter(([e])=>!o.has(e)).reduce((e,[t,r])=>(e[t]=$(r),e),{});n[a[1][0]]=e}return!0})}{const o=e;if(!Array.isArray(t))return!1;const a=o[1][0];let i=null;for(let e=0;e<a.length;e+=1){const t=a[e];if(null!==t&&t[0]===mt){i=e;break}}if(null===i&&t.length!==a.length)return!1;if(null!==i&&t.length<i)return!1;let s=!0;for(let e=0;e<a.length;e+=1){const o=a[e];if(null===o)continue;if(o[0]===mt){n[o[1][0]]=t.slice(e);break}const i=o;s=ft(s,o=>!!o&&St(i,$(t[e]),r,n))}return s}}const zt={arity:{},docs:{category:"special-expression",customVariants:["match value match-branch match-branch ... end"],details:[["value","any","The value to match against patterns."],["match-branch","case pattern [when guard] then body","A branch of the match expression."],["pattern","pattern","A pattern to match: literal, variable, array destructuring, object destructuring, or wildcard (_)."],["guard","expression","An optional guard expression that must be truthy for the match to succeed."],["body","expressions","The expressions to evaluate if the pattern matches."]],description:"Pattern matching expression. Matches `value` against each `pattern` sequentially. If a pattern matches (and the optional `when` guard is truthy), the corresponding `body` is evaluated and its result returned. Bound variables from the pattern are available in the guard and body. If no pattern matches, `null` is returned.",examples:['\nmatch 1\n case 1 then "One"\n case 2 then "Two"\nend','\nmatch [1, 2, 3]\n case [x] then "one element"\n case [x, y] then "two elements"\n case [x, ...xs] then "first: " ++ str(x) ++ " rest: " ++ str(xs)\nend','\nmatch { type: "click", x: 10, y: 20 }\n case { type: "click", x, y } then "Click at " ++ str(x) ++ ", " ++ str(y)\n case { type: "keydown", key } then "Key: " ++ key\n case _ then "unknown event"\nend','\nmatch { role: "admin", name: "Alice" }\n case { role: "admin", name } then "Admin: " ++ name\n case { role, name } when role == "user" then "User: " ++ name\n case _ then "Unknown role"\nend']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=new Set;r([e[1][1]],t,n,o).forEach(e=>a.add(e));for(const[i,s,l]of e[1][2]){const e={};Object.assign(e,$t(i));const c=t.create(e);l&&r([l],c,n,o).forEach(e=>a.add(e)),r([s],c,n,o).forEach(e=>a.add(e))}return a}},jt={category:"special-expression",returns:{type:"boolean"},args:{symbol:{type:"any"}},variants:[{argumentNames:["symbol"]}],description:"Returns `true` if `symbol` is defined, `false` otherwise.\n\nBuilt-in symbols are always considered defined. For user-defined symbols, checks if the symbol exists in the current scope.",examples:["let x = 42; defined?(x)","defined?(x)","defined?(+)"]},Ct={arity:te(1),docs:jt,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r([e[1][1]],t,n,o)},It={arity:{},docs:{category:"special-expression",customVariants:["do body end","do body with case effect(name) then handler end"],details:[["body","expressions","The expressions to evaluate."],["effect(name)","expression","An expression evaluating to an effect value."],["handler","expression","A function (args) -> result that handles the effect. Its return value resumes the perform call."]],description:"Evaluates `body`. Resulting value is the value of the last expression. Effect handlers can be installed via `with` to intercept `perform` calls.",examples:["\ndo\n let a = 1 + 2 + 3 + 4;\n let b = -> $ * ( $ + 1 );\n b(a)\nend",'\ndo\n perform(effect(dvala.io.println), "hello")\nwith\n case effect(dvala.io.println) then ([msg]) -> null\nend']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=r(e[1][1],t.create({}),n,o),i=e[1][2];if(!i||0===i.length)return a;let s=new Set;for(const[e,a]of i){s=me(s,r([e],t,n,o),r([a],t,n,o))}return me(a,s)}},Rt={arity:{},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>function(e,t,r,n,o){const a=new Set,i={self:{value:null}};e[0].forEach(e=>{Object.assign(i,$t(e)),qt(e,e=>{pe(a,r([e],t,n,o))})});const s=t.create(i),l=r(e[1],s,n,o);return pe(a,l),a}(e[1][1],t,r,n,o)};const Pt={arity:{min:2,max:3},docs:{category:"special-expression",customVariants:["if test then true-expr else false-expr","if test then true-expr"],details:[["test","expression","The condition to test."],["true-expr","expression","The expression to evaluate if the test is truthy."],["false-expr","expression","The expression to evaluate if the test is falsy."]],description:"Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is truthy. If $test is falsy `false-expr` is executed, if no `false-expr` exists, `null` is returned.",examples:['\nif true then\n "TRUE"\nelse\n "FALSE"\nend','if false then "TRUE" else "FALSE" end','if true then "TRUE" end','if false then "TRUE" end']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1].filter(e=>!!e),t,n,o)},Mt={arity:{},docs:{category:"special-expression",customVariants:["unless test then true-expr else false-expr end","unless test true-expr end"],details:[["test","expression","The condition to test."],["true-expr","expression","The expressions to evaluate if the test is falsy."],["false-expr","expression","The expressions to evaluate if the test is truthy."]],description:"Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is falsy. If $test is truthy `false-expr` is executed, if no `false-expr` exists, `null` is returned.",examples:['\nunless true then\n "TRUE"\nelse\n "FALSE"\nend','unless false then "TRUE" else "FALSE" end','unless true then "TRUE" end','unless false then "TRUE" end']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1].filter(e=>!!e),t,n,o)},Ot={category:"special-expression",customVariants:["let s = value;"],details:[["s","symbol","The name of the variable to bind."],["value","any","The value to bind to the variable."]],description:"\n Binds local variables s to `value`. `value` can be any expression. The scope of the variables is the body of the let expression.",examples:["\nlet a = 1 + 2 + 3 + 4;\nlet b = -> $ * ( $ + 1 );\nb(a)"]},Vt={arity:te(0),docs:Ot,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=e[1][1],i=a[1][0],s=a[1][1],l=r([s],t,n,o);return qt(i,e=>{pe(l,r([e],t,n,o))}),t.addValues($t(i),i[2]),l}},Dt={arity:{},docs:{category:"special-expression",customVariants:["loop (bindings) -> body"],details:[["bindings","binding pairs","Comma-separated bindings with initial values, e.g. `n = 10, acc = 0`."],["body","expression","The expression to evaluate repeatedly. Use `recur` to loop back with new values."]],description:"Creates a loop with initial bindings. Use `recur` inside the body to jump back to the loop head with new binding values.\n\nIf `recur` is not called, the loop terminates and returns the value of the body expression.",examples:["loop (n = 10, acc = 0) -> do\n if n == 0 then\n acc\n else\n recur(n - 1, acc + n)\n end\nend","loop (n = 5, acc = 1) -> do\n if n <= 1 then\n acc\n else\n recur(n - 1, acc * n)\n end\nend"]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=e[1][1],i=a.reduce((e,t)=>{const r=$t(t[1][0]);return Object.keys(r).forEach(t=>{e[t]={value:!0}}),e},{});return me(r(a.map(e=>e[1][1]),t,n,o),r([e[1][2]],t.create(i),n,o))}};function Ut(e,t,r,n,o){const a=new Set,i={},[,s,l]=e[1];return s.forEach(e=>{const[s,l,c,u]=e,[m,p]=s[1];r([p],t.create(i),n,o).forEach(e=>a.add(e)),Object.assign(i,$t(m)),l&&l.forEach(e=>{const[s,l]=e[1];r([l],t.create(i),n,o).forEach(e=>a.add(e)),Object.assign(i,$t(s))}),c&&r([c],t.create(i),n,o).forEach(e=>a.add(e)),u&&r([u],t.create(i),n,o).forEach(e=>a.add(e))}),r([l],t.create(i),n,o).forEach(e=>a.add(e)),a}const Ft={category:"special-expression",customVariants:["for (...binding) -> body"],details:[["binding","loop-var in collection [...let-binding] [where whereExpr] [while whileExp]","A for loop binding"],["loop-var","symbol","The name of the loop variable."],["collection","any","The collection to iterate over."],["let-binding","let binding","A let binding to create a local variable."],["whereExpr","expression","An expression that must evaluate to truthy for the loop body to be executed."],["whileExp","expression","An expression that must evaluate to truthy for the loop to continue."],["body","expressions","The expressions to evaluate for each iteration of the loop."]],returns:{type:"any",array:!0},description:"Iterates over `bindings`, evaluates `body` for each `binding` and returns an `array` of results.",examples:["\nfor (i in [1, 2, 3]) -> i * 2\n ","\nfor (\n i in range(10) let ii = i ^ 2 while ii < 40 when ii % 3 == 0,\n j in range(10) when j % 2 == 1\n) -> ii + j\n "]},Wt={arity:te(1),docs:Ft,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>Ut(e,t,r,n,o)},Gt={category:"special-expression",customVariants:["doseq (...binding) -> body"],details:[["binding","loop-var in collection [...let-binding] [where whereExpr] [while whileExp]","A doseq loop binding"],["loop-var","symbol","The name of the loop variable."],["collection","any","The collection to iterate over."],["let-binding","let binding","A let binding to create a local variable."],["whereExpr","expression","An expression that must evaluate to truthy for the loop body to be executed."],["whileExp","expression","An expression that must evaluate to truthy for the loop to continue."],["body","expressions","The expressions to evaluate for each iteration of the loop."]],returns:{type:"null"},description:"Iterates over `bindings`, evaluates `body` for each `binding` and returns `null`. This is useful for side effects.",examples:["\ndoseq (i in [1, 2, 3]) -> perform(effect(dvala.io.println), i * 2)\n "]},Bt={arity:te(1),docs:Gt,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>Ut(e,t,r,n,o)},Lt={arity:{},docs:{category:"special-expression",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"},c:{type:"any",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"\n Computes logical `or`. Evaluation of expressions evaluation starts from left.\n As soon as a `expression` evaluates to a truthy value, the result is returned.\n\n If all expressions evaluate to falsy values, the value of the last expression is returned.",examples:["false || 1","||(1, 1)",'||(3 > 2, "string")','||(3 < 2, "string")',"||(false, false, false, true)","||(1, 2, 3, 4)"]},evaluateAsNormalExpression:(e,t)=>{let r=!1;for(const n of e)if(r=$(n,t),r)break;return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},_t={arity:{min:1},docs:{category:"special-expression",returns:{type:"any"},args:{a:{type:"any"},b:{type:"any"},c:{type:"any",rest:!0}},variants:[{argumentNames:["a"]},{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Nullish coalescing operator. Returns the first non-`null` value.\n\nEvaluation is short-circuited — as soon as a non-`null` value is found, the remaining expressions are not evaluated.\n\nIf all values are `null`, returns `null`.\n\nAlso works with undefined symbols — if a symbol is undefined, it is treated as `null`.",examples:["1 ?? 2","null ?? 2","??(null)",'??(null, "default")','??(1, "default")','false ?? "default"',"??(null, null, 3)"]},evaluateAsNormalExpression:(e,t)=>{for(const r of e){const e=$(r,t);if(null!==e)return e}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Kt={arity:{},docs:{category:"special-expression",customVariants:["recur(...recur-args)"],description:"Recursevly calls enclosing function or loop with its evaluated `recur-args`.",examples:["\nlet foo = (n) -> do\n if zero?(n) then\n 0\n else\n n + recur(n - 1)\n end\nend;\nfoo(3)","\n((n) -> do\n if zero?(n) then\n 0\n else\n n + recur(n - 1)\n end\nend)(3)","\nloop (n = 3, acc = 0) -> do\n if zero?(n) then\n acc\n else\n recur(n - 1, acc + n)\n end\nend"]},evaluateAsNormalExpression:e=>{throw new n(e)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Jt={arity:{},docs:{category:"special-expression",returns:{type:"any",array:!0},args:{values:{type:"any",rest:!0}},variants:[{argumentNames:["values"]}],description:"Makes new array from $values.",examples:["array(1, 2, 3)","array(array(null, false, true))","[]","[1, 2, 3]","[1, 2, ...[3, 4, 5], 6]","[[null, false, true]]","[1, 2, 3][1]"],hideOperatorForm:!0},evaluateAsNormalExpression:(e,t)=>{const r=[];for(const n of e)r.push($(n,t));return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Ht={arity:{},docs:{category:"special-expression",customVariants:["effect(name)"],details:[["name","dotted identifier","The effect name, e.g. `llm.complete` or `dvala.io.println`."]],description:"Returns the unique effect reference for the given name. Calling `effect` with the same name always returns the same reference. Effect references are first-class values that can be stored, passed, and compared with `==`.",examples:["effect(dvala.io.println)","==(effect(llm.complete), effect(llm.complete))"],seeAlso:["effect?"]},getUndefinedSymbols:()=>new Set},Yt={arity:{},docs:{category:"special-expression",returns:{type:"object"},args:{kvps:{type:"any",rest:!0,description:"key - value pairs, where key is a string"}},variants:[{argumentNames:["kvps"]}],description:"Constructs a new object. Object members are created from the $kvps key-value pairs. Requires an even number of arguments.",examples:["object()",'\nlet default = {\n type: "Person",\n name: "John Doe",\n age: 42\n};\n\n{\n ...default,\n name: "Lisa"\n}','object("x", 10, "y", true, "z", "A string")',"{}","{ a: 1, b: 2 }"],hideOperatorForm:!0},evaluateAsNormalExpression:(e,t)=>{const r={};for(let n=0;n<e.length;n+=2){const o=e[n],a=e[n+1];G(o,t),r[o]=a??null}return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Xt={arity:te(1),docs:{category:"special-expression",description:"Imports all functions from a module as an object. Use destructuring to pick specific functions.",customVariants:["import(module-name)"],returns:{type:"object"},examples:["let v = import(vector); v.stdev([1, 2, 3, 4])","let { linspace } = import(vector); linspace(0, 10, 5)","let g = import(grid); g.row([[1, 2], [3, 4]], 0)"]},getUndefinedSymbols:()=>new Set},Qt={arity:{min:1},docs:{category:"special-expression",customVariants:["parallel(expr1, expr2, ...)"],details:[["expr1, expr2, ...","expressions","Expressions to evaluate concurrently. Typically `perform(...)` calls."]],description:"Evaluates all branch expressions concurrently and returns an array of results in order. Each branch runs as an independent trampoline invocation. If any branch suspends, the entire `parallel` suspends with a composite blob. On resume, branches are resumed one at a time. Only available in async mode (`run()`). Requires at least one branch.",examples:[]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>me(...e[1][1].map(e=>r([e],t,n,o)))},Zt={arity:{min:1},docs:{category:"special-expression",customVariants:["perform(eff)","perform(eff, arg1)","perform(eff, arg1, arg2, ...)"],details:[["eff","expression","An expression evaluating to an effect value (from `effect(name)`)."],["arg1, arg2, ...","expressions","Arguments passed to the effect handler."]],description:"Invokes an effect. The nearest enclosing `do/with` handler matching the effect intercepts the call. The handler receives the arguments as an array and its return value becomes the result of `perform`. If no local handler matches, the effect is dispatched to the host.",examples:['\ndo\n perform(effect(dvala.io.println), "hello")\nwith\n case effect(dvala.io.println) then ([msg]) -> msg\nend\n'],seeAlso:["effect?"]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const[,a,i]=e[1];return me(r([a],t,n,o),r(i,t,n,o))}},er={arity:{min:1},docs:{category:"special-expression",customVariants:["race(expr1, expr2, ...)"],details:[["expr1, expr2, ...","expressions","Expressions to race concurrently. Typically `perform(...)` calls."]],description:"Races all branch expressions concurrently. The first branch to complete wins — its value becomes the result. Losing branches are cancelled via AbortSignal. Errored branches are silently dropped. If all branches error, throws an aggregate error. If no branch completes but some suspend, the race suspends. On resume, the host provides the winner value directly. Only available in async mode (`run()`). Requires at least one branch.",examples:[]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>me(...e[1][1].map(e=>r([e],t,n,o)))},tr={"??":0,"&&":1,"||":2,array:3,cond:4,"defined?":5,block:6,doseq:7,"0_lambda":8,for:9,if:10,let:11,loop:12,object:13,recur:14,match:15,unless:16,import:17,effect:18,perform:19,parallel:20,race:21},rr={normalExpressions:at,specialExpressions:[_t,lt,Lt,Jt,ct,Ct,It,Bt,Rt,Wt,Pt,Vt,Dt,Yt,Kt,zt,Mt,Xt,Ht,Zt,Qt,er],allNormalExpressions:st},nr=Object.keys(at),or=Object.keys(tr),ar=["^","*","/","%","+","-","<<",">>",">>>","++","<","<=","≤",">",">=","≥","==","!=","!=","&","xor","|","&&","||","??","|>"],ir=[...ar,"?",":","->","...",".",",","=",":",";"],sr=new Set(["comment","cond","defined?","block","doseq","if","let","loop","recur","unless","while"]);function lr(e){return!sr.has(e)}const cr=new Set(ar);function ur(e){return cr.has(e)}const mr=new Set(ir);function pr(e){return mr.has(e)}const dr=(1+Math.sqrt(5))/2,hr={E:Math.E,"-E":-Math.E,"ε":Math.E,"-ε":-Math.E,PI:Math.PI,"-PI":-Math.PI,"π":Math.PI,"-π":-Math.PI,PHI:dr,"-PHI":-dr,"φ":dr,"-φ":-dr,POSITIVE_INFINITY:Number.POSITIVE_INFINITY,"∞":Number.POSITIVE_INFINITY,NEGATIVE_INFINITY:Number.NEGATIVE_INFINITY,"-∞":Number.NEGATIVE_INFINITY,MAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,MIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,MAX_VALUE:Number.MAX_VALUE,MIN_VALUE:Number.MIN_VALUE,NaN:Number.NaN},gr={true:!0,false:!1,null:null,do:null,else:null,case:null,each:null,in:null,when:null,while:null,function:null,as:null,then:null,end:null,with:null,_:null,...hr};const fr=["(",")","[","]","{","}","'",'"',"`",",",".",";"," ","\n","\r","\t"],yr=["0","1","2","3","4","5","6","7","8","9",...fr],vr=new Set(fr),br=new Set(yr),wr=/\s/,xr=[0],kr=(e,t)=>{if('"'!==e[t])return xr;let r='"',n=1,o=e[t+n],a=!1;for(;o&&('"'!==o||a);)n+=1,a?(a=!1,r+=o):("\\"===o&&(a=!0),r+=o),o=e[t+n];return o?(r+='"',[n+1,["string",r]]):[n,["Error",r,void 0,`Unclosed string at position ${t}`]]};function qr(e,t,r,n){return t===r.slice(n,n+t.length)?[t.length,[e,t]]:xr}const Ar=/\d/,Nr=/[0-7]/,$r=/[0-9a-f]/i,Er=/[01]/,Tr=/[\s)\]}(,;]/,Sr=(e,t)=>{let r=e[t];if("'"===r){let n=1,o=e[t+n],a=!1;for(;"'"!==o||a;){if(void 0===o)return[n,["Error",r,void 0,`Unclosed quoted symbol at position ${t}`]];n+=1,a?(a=!1,r+=o):("\\"===o&&(a=!0),r+=o),o=e[t+n]}return r+="'",[n+1,["Symbol",r]]}if(!br.has(r)){const n=t;let o=e[t+=1];for(;o&&!vr.has(o);)r+=o,o=e[t+=1];return r.endsWith(":")?[t-n-1,["Symbol",r.slice(0,-1)]]:[t-n,["Symbol",r]]}return xr},zr=[(e,t)=>{let r=e[t];if(!r||!wr.test(r))return xr;let n=r;for(r=e[t+=1];r&&wr.test(r);)n+=r,r=e[t+=1];return[n.length,["Whitespace",n]]},(e,t)=>{if("/"===e[t]&&"*"===e[t+1]){let r=2,n="/*";for(;("*"!==e[t+r]||"/"!==e[t+r+1])&&t+r+1<e.length;)n+=e[t+r],r+=1;return t+r+1>=e.length?[r,["Error",n,void 0,`Unclosed multi-line comment at position ${t}`]]:(n+="*/",r+=2,[r,["MultiLineComment",n]])}return xr},(e,t)=>{if("/"===e[t]&&"/"===e[t+1]){let r=2,n="//";for(;"\n"!==e[t+r]&&t+r<e.length;)n+=e[t+r],r+=1;return[r,["SingleLineComment",n]]}return xr},(e,t)=>{const r=Sr(e,t);if(0===r[0]||!r[1])return xr;let n=r[1][1];n=n.startsWith("'")?n.slice(1,n.length-1):n;return void 0===gr[n]?xr:[r[0],["ReservedSymbol",n]]},(e,t)=>qr("LParen","(",e,t),(e,t)=>qr("RParen",")",e,t),(e,t)=>qr("LBracket","[",e,t),(e,t)=>qr("RBracket","]",e,t),(e,t)=>qr("LBrace","{",e,t),(e,t)=>qr("RBrace","}",e,t),kr,(e,t)=>{if("#"!==e[t])return xr;const[r,n]=kr(e,t+1);if(!n)return xr;if("Error"===n[0]){return[r+1,["Error",`#${n[1]}`,void 0,`Unclosed regexp at position ${t}`]]}t+=r+1;let o=r+1,a="";for(;"g"===e[t]||"i"===e[t];)if(a+=e[t],o+=1,t+=1,a.includes(e[t]))return[o,["Error",`#${n[1]}${a}`,void 0,`Duplicated regexp option "${e[t]}"`]];return[o,["RegexpShorthand",`#${n[1]}${a}`]]},(e,t)=>{if("0"!==e[t])return xr;const r=e[t+1],n="b"===r||"B"===r?"binary":"o"===r||"O"===r?"octal":"x"===r||"X"===r?"hex":null;if(null===n)return xr;let o;for(o=t+2;o<e.length;o+=1){const t=e[o];if("binary"===n&&!Er.test(t))break;if("octal"===n&&!Nr.test(t))break;if("hex"===n&&!$r.test(t))break}const a=o-t;if(a<=2)return xr;const i=e[o];return i&&!Tr.test(i)?xr:[a,["BasePrefixedNumber",e.substring(t,o)]]},(e,t)=>{let r;const n="-"===e[t],o="+"===e[t],a=n||o?t+1:t;let i=!1,s=!1;for(r=a;r<e.length;r+=1){const n=e[r];if("_"===n){if(!Ar.test(e[r-1])||!Ar.test(e[r+1]))return r===a?xr:[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]]}else if("."===n){if(r===a)return xr;if(i||s)return[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]];i=!0}else if("e"===n||"E"===n){if(r===a)return xr;if(s)return[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]];if("."===e[r-1]||"+"===e[r-1]||"-"===e[r-1])return[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]];"+"!==e[r+1]&&"-"!==e[r+1]||(r+=1),s=!0}else if(!Ar.test(n))break}if((n||o)&&r===a)return xr;const l=r-t;if(0===l)return xr;const c=e[r];return c&&":"!==c&&!Tr.test(c)?[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]]:[l,["Number",e.substring(t,r)]]},(e,t)=>{const r=e.slice(t,t+3);if(t+2<e.length&&pr(r))return[3,["Operator",r]];const n=e.slice(t,t+2);if(t+1<e.length&&pr(n))return[2,["Operator",n]];const o=e[t]??"";return pr(o)?[1,["Operator",o]]:xr},Sr];function jr(e,t,r){let n=0;const o={tokens:[],filePath:r,hasDebugData:t};for(;n<e.length;){const a=t?Cr(e,n,r):void 0,i=Ir(e,n),[s,l]=i;n+=s,l&&(a&&(l[2]=a),o.tokens.push(l))}return o}function Cr(e,t,r){const n=e.substring(0,t+1).split(/\r\n|\r|\n/),o=n[n.length-1],a=function(e,t){return e.split(/\r\n|\r|\n/)[t]}(e,n.length-1);return{code:a,position:{line:n.length,column:o.length},filePath:r}}function Ir(e,t){const r=t;if(0===t){const[n,o]=((e,t)=>{if("#"===e[t]&&"!"===e[t+1]){let r=2,n="#!";for(;"\n"!==e[t+r]&&t+r<e.length;)n+=e[t+r],r+=1;return[r,["SingleLineComment",n]]}return xr})(e,t);if(t+=n,n>0)return[t-r,o]}for(const n of zr){const[o,a]=n(e,t);if(t+=o,0!==o)return[t-r,a]}return[1,["Error",e[r],void 0,"Unrecognized character"]]}const Rr=new Set([...nr,...or,...Object.keys(gr)]);class Pr{originalProgram;originalPosition;prefixProgram="";suffixProgram="";searchString="";suggestions=[];suggestionIndex=null;constructor(e,t,r={}){this.originalProgram=e,this.originalPosition=t;const n=jr(this.originalProgram.slice(0,this.originalPosition),!1,void 0).tokens.at(-1);n&&"Error"!==n[0]&&(this.searchString=n[1],this.prefixProgram=this.originalProgram.slice(0,this.originalPosition-this.searchString.length),this.suffixProgram=this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.suggestions=this.generateSuggestions(r))}getNextSuggestion(){return this.getAutoCompleteSuggestionResult(this.getNextSuggestionSymbol())}getPreviousSuggestion(){return this.getAutoCompleteSuggestionResult(this.getPreviousSuggestionSymbol())}getAutoCompleteSuggestionResult(e){return null===e?null:{program:this.prefixProgram+e+this.suffixProgram,position:this.prefixProgram.length+e.length}}getNextSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=0:(this.suggestionIndex+=1,this.suggestionIndex>=this.suggestions.length&&(this.suggestionIndex=0)),this.suggestions[this.suggestionIndex])}getPreviousSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=this.suggestions.length-1:(this.suggestionIndex-=1,this.suggestionIndex<0&&(this.suggestionIndex=this.suggestions.length-1)),this.suggestions[this.suggestionIndex])}getSuggestions(){return[...this.suggestions]}getSearchString(){return this.searchString}generateSuggestions(e){const t=new Set(["0_defn","0_lambda"]),r=this.generateWithPredicate(e,e=>!t.has(e)&&e.startsWith(this.searchString));r.forEach(e=>t.add(e));const n=this.generateWithPredicate(e,e=>!t.has(e)&&e.toLowerCase().startsWith(this.searchString.toLowerCase()));n.forEach(e=>t.add(e));const o=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString));o.forEach(e=>t.add(e));const a=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString.toLowerCase()));return a.forEach(e=>t.add(e)),[...r,...n,...o,...a]}generateWithPredicate(e,t){const r=new Set;return Rr.forEach(e=>{t(e)&&r.add(e)}),Object.keys(e.bindings??{}).filter(t).forEach(e=>r.add(e)),[...r].sort((e,t)=>e.localeCompare(t))}}function Mr(e){return l.UserDefinedSymbol===e[0]}function Or(e,t){return function(e,t){if(!Mr(e))throw b("UserDefinedSymbolNode",e,t)}(e,t),e}function Vr(e){return l.NormalBuiltinSymbol===e[0]}function Dr(e){return l.SpecialBuiltinSymbol===e[0]}function Ur(e){return!!function(e){return e[0]===l.NormalExpression}(e)&&function(e){const t=e[0];return l.UserDefinedSymbol===t||l.NormalBuiltinSymbol===t||l.SpecialBuiltinSymbol===t}(e[1][0])}function Fr(e){return e[0]===l.Spread}class Wr{_contexts;globalContext;values;modules;valueModules;pure;constructor({contexts:e,values:t,modules:r,valueModules:n,pure:o}){this.globalContext=w(e[0]),this._contexts=e,this.values=t,this.modules=r??new Map,this.valueModules=n??new Map,this.pure=o??!1}getContextsRaw(){return this._contexts}getHostValues(){return this.values}getModuleScopeBindings(){const e=this._contexts[0],t={};for(const[r,n]of Object.entries(e))t[r]=n.value;return t}getGlobalContextIndex(){return this._contexts.indexOf(this.globalContext)}static fromDeserialized(e){const t=new Wr({contexts:e.contexts,values:e.values,modules:e.modules,pure:e.pure});return e.globalContextIndex>=0&&e.globalContextIndex<e.contexts.length&&(t.globalContext=e.contexts[e.globalContextIndex]),t}setContextsFromDeserialized(e,t){this._contexts=e,t>=0&&t<e.length&&(this.globalContext=e[t])}getModule(e){return this.modules.get(e)}getValueModule(e){return this.valueModules.has(e)?{value:this.valueModules.get(e),found:!0}:{value:void 0,found:!1}}registerValueModule(e,t){this.valueModules.set(e,t)}create(e){const t=this.globalContext,r=new Wr({contexts:[e,...this._contexts],values:this.values,modules:this.modules,valueModules:this.valueModules,pure:this.pure});return r.globalContext=t,r}new(e){return new Wr({contexts:[{},e],modules:this.modules,valueModules:this.valueModules,pure:this.pure})}addValues(e,t){const r=this._contexts[0];for(const[n,a]of Object.entries(e)){if(r[n])throw new o(`Cannot redefine value "${n}"`,t);const e=Gr(n);if(e)throw new o(`Cannot shadow ${e}`,t);r[n]={value:le(a)}}}getValue(e){for(const t of this._contexts){const r=t[e];if(r)return r.value}return this.values?.[e]}lookUp(e){const t=e[1];for(const e of this._contexts){const r=e[t];if(r)return r}const r=this.values?.[t];return void 0!==r?{value:le(r)}:null}evaluateSymbol(e){if(Dr(e)){const t=e[1];switch(t){case tr["&&"]:case tr["||"]:case tr.array:case tr.object:case tr["defined?"]:case tr.recur:case tr["??"]:{const r=w(rr.specialExpressions[t],e[2]);return{[p]:!0,functionType:"SpecialBuiltin",specialBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:r.arity}}default:throw new o(`Unknown special builtin symbol type: ${t}`,e[2])}}if(Vr(e)){const t=e[1],r=st[t],n=r.name;return{[p]:!0,functionType:"Builtin",normalBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:r.arity,name:n}}const t=this.lookUp(e);if(k(r=t)&&void 0!==r.value)return t.value;var r;throw new s(e[1],e[2])}}function Gr(e){return or.includes(e)?`special expression "${e}"`:nr.includes(e)?`builtin function "${e}"`:"self"===e?`builtin value "${e}"`:null}function Br(e){const t=Gr(e);if(t)throw new o(`Cannot shadow ${t}`,void 0)}function Lr(e={},t,r){const n=e.globalContext??{},a=e.contexts?[n,...e.contexts]:[n];let i;if(e.bindings)for(const[t,r]of Object.entries(e.bindings)){if(t.includes("."))throw new o(`Dots are not allowed in binding keys: "${t}"`,void 0);Br(t),i||(i={}),i[t]=r}const s=new Wr({contexts:a,values:i,modules:t,pure:r});return e.globalModuleScope?s:s.create({})}const _r=(e,t,r,n)=>{const o=Array.isArray(e)?e:[[l.SpecialExpression,[tr.block,e.body,void 0]]],a=new Set;for(const e of o)Kr(e,t,r,n)?.forEach(e=>a.add(e));return a};function Kr(e,t,r,n){const a=e[0];switch(a){case l.UserDefinedSymbol:{const r=e;return null===t.lookUp(r)?new Set([r[1]]):null}case l.NormalBuiltinSymbol:case l.SpecialBuiltinSymbol:case l.String:case l.Number:case l.ReservedSymbol:case l.Binding:return null;case l.NormalExpression:{const o=e,a=new Set;if(Ur(o)){const[,[e]]=o;if(Mr(e)){null===t.lookUp(e)&&a.add(e[1])}}else{const[,[e]]=o;Kr(e,t,r,n)?.forEach(e=>a.add(e))}for(const e of o[1][1])Kr(e,t,r,n)?.forEach(e=>a.add(e));return a}case l.SpecialExpression:{const o=e,a=o[1][0];return(0,r.specialExpressions[a].getUndefinedSymbols)(o,t,{getUndefinedSymbols:_r,builtin:r,evaluateNode:n})}case l.Spread:return Kr(e[1],t,r,n);default:throw new o(`Unhandled node type: ${a}`,e[2])}}function Jr(e,t){return"Symbol"===e?.[0]&&(!t||e[1]===t)}function Hr(e,t){return function(e,t){Jr(e,t)||yn("Symbol",void 0,e)}(e,t),e}function Yr(e,t){return"ReservedSymbol"===e?.[0]&&(!t||e[1]===t)}function Xr(e,t){Yr(e,t)||yn("ReservedSymbol",t,e)}function Qr(e,t){return Xr(e,t),e}function Zr(e,t){return"Operator"===e?.[0]&&(!t||e[1]===t)}function en(e,t){Zr(e,t)||yn("Operator",t,e)}function tn(e){return"Number"===e?.[0]}function rn(e){return"BasePrefixedNumber"===e?.[0]}function nn(e){return"LParen"===e?.[0]}function on(e){nn(e)||yn("LParen",void 0,e)}function an(e){return"RParen"===e?.[0]}function sn(e){an(e)||yn("RParen",void 0,e)}function ln(e){return"LBracket"===e?.[0]}function cn(e){return function(e){ln(e)||yn("LBracket",void 0,e)}(e),e}function un(e){return"RBracket"===e?.[0]}function mn(e){un(e)||yn("RBracket",void 0,e)}function pn(e){return"LBrace"===e?.[0]}function dn(e){return function(e){pn(e)||yn("LBrace",void 0,e)}(e),e}function hn(e){return"RBrace"===e?.[0]}function gn(e){return"string"===e?.[0]}function fn(e){return"Operator"===e?.[0]&&ur(e[1])}function yn(e,t,r){const n=r?`${r[0]} '${r[1]}'`:"end of input";throw new o(`Unexpected token: ${n}, expected ${e}${t?` '${t}'`:""}`,r?.[2])}function vn(e,t){return t&&(e[2]=t),e}function bn(e,t){return void 0!==tr[e]&&"fn"!==e&&"defn"!==e?vn([l.SpecialBuiltinSymbol,tr[e]],t):void 0!==it[e]?vn([l.NormalBuiltinSymbol,it[e]],t):vn([l.UserDefinedSymbol,e],t)}function wn(e){return e.substring(1,e.length-1).replace(/(\\{2})|(\\')|\\(.)/g,(e,t,r,n)=>t?"\\":r?"'":`\\${n}`)}const xn=Object.entries(it).reduce((e,[t,r])=>(e[r]=t,e),[]),kn=Object.entries(tr).reduce((e,[t,r])=>(e[r]=t,e),[]);function qn(e){return Mr(e)?e[1]:Vr(e)?xn[e[1]]:kn[e[1]]}function An(e,t,r){const n=vn([l.NormalExpression,[e,t]],r);return Vr(e)&&ee(st[e[1]].arity,n[1][1].length,r),n}function Nn(e){if(e.isAtEnd())return!0;const t=e.tryPeek();return Zr(t)?[";",",",":"].includes(t[1]):!!Yr(t)&&["else","when","while","case","let","then","end","do"].includes(t[1])}function $n(e,t,r,n,a){const i=e[1];switch(i){case"^":case"*":case"/":case"%":case"+":case"-":case"<<":case">>":case">>>":case"++":case"<":case"<=":case"≤":case">":case">=":case"≥":case"==":case"!=":case"&":case"xor":case"|":case"|>":return An(t,[r,n],a);case"&&":case"||":case"??":return vn([l.SpecialExpression,[tr[i],[r,n]]],a);default:throw new o(`Unknown binary operator: ${i}`,a)}}class En{tokens;position;storedPosition=0;parseExpression;constructor(e){this.tokens=e.tokens,this.position=0}advance(){this.position+=1}tryPeek(){return this.tokens[this.position]}peek(){const e=this.tokens[this.position];if(!e){const e=this.tokens.at(-1),t=e?e[2]:void 0;throw new o("Unexpected end of input",t)}return e}isAtEnd(){return this.position>=this.tokens.length}peekSourceCodeInfo(){const e=this.tryPeek();return e?e[2]:this.tokens.at(-1)?.[2]}storePosition(){return this.storedPosition=this.position}restorePosition(){this.position=this.storedPosition}peekAhead(e){return this.tokens[this.position+e]}getPosition(){return this.position}getTokenAt(e){return this.tokens[e]}}function Tn(e,t){switch(e){case"^":return 12;case"*":case"/":case"%":return 11;case"+":case"-":return 10;case"<<":case">>":case">>>":return 9;case"++":return 8;case"<":case"<=":case"≤":case">":case">=":case"≥":return 7;case"==":case"!=":return 6;case"&":case"xor":case"|":return 5;case"&&":case"||":case"??":return 4;case"|>":return 2;default:throw new o(`Unknown binary operator: ${e}`,t)}}function Sn(e,t){const r=[];for(;!e.isAtEnd()&&!zn(e,t);)Zr(e.tryPeek(),";")?e.advance():r.push(e.parseExpression());if(function(e,t){if(!zn(e,t))throw new o(`Expected ${t.map(e=>e[1]).join(" or ")}`,e.peekSourceCodeInfo())}(e,t),0===r.length)throw new o("Expected expression",e.peekSourceCodeInfo());return 1===r.length?r[0]:vn([l.SpecialExpression,[tr.block,r,void 0]],e.peekSourceCodeInfo())}function zn(e,t){for(const r of t)if(Yr(e.tryPeek(),r))return!0;return!1}function jn(e){const t=Qr(e.tryPeek(),"do");e.advance();const r=[];for(;!e.isAtEnd()&&!Yr(e.tryPeek(),"end")&&!Yr(e.tryPeek(),"with");)if(r.push(e.parseExpression()),Zr(e.tryPeek(),";"))e.advance();else if(!Yr(e.tryPeek(),"end")&&!Yr(e.tryPeek(),"with"))throw new o("Expected end",e.peekSourceCodeInfo());let n;if(Yr(e.tryPeek(),"with"))for(e.advance(),n=[];!e.isAtEnd()&&!Yr(e.tryPeek(),"end");){Xr(e.tryPeek(),"case"),e.advance();const t=e.parseExpression();Xr(e.tryPeek(),"then"),e.advance();const r=Sn(e,["case","end"]);n.push([t,r])}return Xr(e.tryPeek(),"end"),e.advance(),vn([l.SpecialExpression,[tr.block,r,n]],t[2])}function Cn(e){const t=e.peek();if(e.advance(),!Jr(t))throw new o(`Expected symbol token, got ${t[0]}`,t[2]);return"'"===t[1][0]?bn(wn(t[1]),t[2]):bn(t[1],t[2])}function In(e,t){e.advance();const r=t[1].substring(1,t[1].length-1).replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g,(e,t,r,n,o,a,i,s,l)=>t?"\\":n?"\n":o?"\t":a?"\r":i?"\b":s?"\f":r?'"':l);return vn([l.String,r],t[2])}function Rn(e){const t=e.peek();e.advance();const r=t[1],n="-"===r[0],o=(n?r.substring(1):r).replace(/_/g,"");return vn([l.Number,n?-Number(o):Number(o)],t[2])}function Pn(e,{requireDefaultValue:t,noRest:r,allowLiteralPatterns:n}={}){const a=e.tryPeek();if(n&&Yr(a,"_"))return e.advance(),vn([gt,[]],a[2]);if(n&&On(a)){if(tn(a)||rn(a)){const t=Rn(e);return vn([ht,[t]],a[2])}if(gn(a)){const t=In(e,a);return vn([ht,[t]],a[2])}if(Yr(a,"true")){e.advance();const t=vn([l.ReservedSymbol,"true"],a[2]);return vn([ht,[t]],a[2])}if(Yr(a,"false")){e.advance();const t=vn([l.ReservedSymbol,"false"],a[2]);return vn([ht,[t]],a[2])}if(Yr(a,"null")){e.advance();const t=vn([l.ReservedSymbol,"null"],a[2]);return vn([ht,[t]],a[2])}}if(Jr(a)){const r=Cn(e);if(!Mr(r))throw new o("Expected user defined symbol",a[2]);const n=Mn(e);if(t&&!n)throw new o("Expected assignment",e.peekSourceCodeInfo());return vn([ut,[r,n]],a[2])}if(Zr(a,"...")){if(r)throw new o("Rest element not allowed",a[2]);e.advance();const t=Or(Cn(e));if(Zr(e.tryPeek(),"="))throw new o("Rest argument can not have default value",e.peekSourceCodeInfo());return vn([mt,[t[1],void 0]],a[2])}if(ln(a)){e.advance();const r=[];let i=e.peek(),s=!1;for(;!un(i);){if(s)throw new o("Rest argument must be last",i[2]);if(Zr(i,",")){r.push(null),e.advance(),i=e.peek();continue}const t=Pn(e,{allowLiteralPatterns:n});t[0]===mt&&(s=!0),r.push(t),i=e.peek(),un(i)||(en(i,","),e.advance()),i=e.peek()}e.advance();const l=Mn(e);if(t&&!l)throw new o("Expected assignment",e.peekSourceCodeInfo());return vn([dt,[r,l]],a[2])}if(pn(a)){e.advance();const r={};let i=e.peek(),s=!1;for(;!hn(i);){if(s)throw new o("Rest argument must be last",i[2]);Zr(i,"...")&&(s=!0,e.advance());const t=Cn(e),l=qn(t);if(i=e.peek(),Yr(i,"as")){if(s)throw new o("Rest argument can not have alias",i[2]);e.advance();const t=Or(Cn(e));if(r[t[1]])throw new o(`Duplicate binding name: ${t}`,i[2]);r[l]=vn([ut,[t,Mn(e)]],a[2])}else if(hn(i)||Zr(i,",")||Zr(i,"=")){const n=Or(t,t[2]);if(r[n[1]])throw new o(`Duplicate binding name: ${n}`,i[2]);if(s&&Zr(e.tryPeek(),"="))throw new o("Rest argument can not have default value",e.peekSourceCodeInfo());r[n[1]]=vn(s?[mt,[n[1],Mn(e)]]:[ut,[n,Mn(e)]],a[2])}else if(Zr(i,":")){if(e.advance(),i=e.peek(),n){if(!pn(i)&&!ln(i)&&!On(i))throw new o("Expected literal, object or array pattern",i[2])}else if(!pn(i)&&!ln(i))throw new o("Expected object or array",i[2]);r[l]=Pn(e,{allowLiteralPatterns:n})}hn(e.peek())||(en(e.peek(),","),e.advance()),i=e.peek()}e.advance(),i=e.peek();const l=Mn(e);if(t&&!l)throw new o("Expected assignment",i[2]);return vn([pt,[r,l]],a[2])}throw new o("Expected symbol",e.peekSourceCodeInfo())}function Mn(e){if(Zr(e.tryPeek(),"="))return e.advance(),e.parseExpression()}function On(e){return tn(e)||rn(e)||gn(e)||Yr(e,"true")||Yr(e,"false")||Yr(e,"null")}function Vn(e,t){e.advance();const r=Pn(e,{requireDefaultValue:!0,noRest:!0}),n=r[1][1];r[1][1]=void 0;const o=vn([l.Binding,[r,n]],t[2]);return vn([l.SpecialExpression,[tr.let,o]],t[2])}function Dn(e){const t=function(e){const t=Hr(e.tryPeek()),r=Or(Cn(e));Xr(e.tryPeek(),"in"),e.advance();const n=e.parseExpression();return vn([l.Binding,[vn([ut,[r,void 0]],t[2]),n]],t[2])}(e),r=[];let n=e.peek();Un(n,["let","when","while"]);const a=[];if("let"===n[1])for(r.push("&let");Jr(n,"let");){const t=Vn(e,n),r=a.flatMap(e=>Object.keys($t(e[1][0])));if(Object.keys($t(t[1][1][1][0])).some(e=>r.includes(e)))throw new o("Duplicate binding",t[1][1][2]);a.push(t[1][1]),n=e.peek(),Un(n,["let","when","while"]),n=e.peek()}let i,s;for(;Yr(n,"when")||Yr(n,"while");){e.advance(),"when"===n[1]?(r.push("&when"),i=e.parseExpression()):(r.push("&while"),s=e.parseExpression()),n=e.peek();Un(n,r.includes("&when")&&r.includes("&while")?[]:r.includes("&when")?["while"]:["when"]),n=e.peek()}return Un(n,[]),[t,a,i,s]}function Un(e,t){if(!function(e,t){if(Zr(e,",")||an(e))return!0;for(const r of t){if("let"===r&&Jr(e,"let"))return!0;if(["when","while"].includes(r)&&Yr(e,r))return!0}return!1}(e,t)){const r=`${[...t,","].map(e=>`"${e}"`).join(", ")} or ")"`;throw new o(`Expected symbol ${r}`,e[2])}}function Fn(e){const t=Qr(e.tryPeek());e.advance();const r=t[1];return function(e){return e in hr}(r)?vn([l.Number,hr[r]],t[2]):vn([l.ReservedSymbol,t[1]],t[2])}const Wn=/^\$([1-9]\d?)?$/;function Gn(e){const t=e.peek();if(nn(t)&&Jr(e.peekAhead(1))&&Zr(e.peekAhead(2),"->"))return null;try{const r=function(e){const t=e.peek();if(Jr(t))return[vn([ut,[Cn(e),void 0]],t[2])];on(t),e.advance();let r=!1,n=!1;const a=[];for(;!e.isAtEnd()&&!an(e.peek())&&!Jr(e.peek(),"let");){if(r)throw new o("Rest argument must be last",e.peekSourceCodeInfo());const t=Pn(e);if(void 0!==t[1][1]&&(n=!0),t[0]===mt&&(r=!0),n&&!t[1][1])throw new o("Default arguments must be last",e.peekSourceCodeInfo());if(a.push(t),!Zr(e.peek(),",")&&!an(e.peek())&&!Jr(e.peek(),"let"))throw new o("Expected comma or closing parenthesis",e.peekSourceCodeInfo());Zr(e.peek(),",")&&e.advance()}if(!an(e.peek()))throw new o("Expected closing parenthesis",e.peekSourceCodeInfo());return e.advance(),a}(e);if(!Zr(e.peek(),"->"))return null;let n;if(e.advance(),Yr(e.peek(),"do")){const t=jn(e),r=t[1][2];n=r&&r.length>0?[t]:t[1][1]}else n=[e.parseExpression()];return vn([l.SpecialExpression,[tr["0_lambda"],[r,n]]],t[2])}catch{return null}}function Bn(e,t){if(e.advance(),Dr(t)&&t[1]===tr.effect)return function(e,t){const r=t[2],n=e.peek();if(!Jr(n))throw new o("effect expects a dotted name identifier",n[2]);let a=n[1];e.advance();for(;Zr(e.tryPeek(),".");){e.advance();const t=e.peek();if(!Jr(t))throw new o("Expected identifier after dot in effect name",t[2]);a+=`.${t[1]}`,e.advance()}if(!an(e.tryPeek()))throw new o("Expected closing parenthesis after effect name",e.peekSourceCodeInfo());return e.advance(),vn([l.SpecialExpression,[tr.effect,a]],r)}(e,t);const r=[];for(;!e.isAtEnd()&&!an(e.tryPeek());){Zr(e.tryPeek(),"...")?(e.advance(),r.push(vn([l.Spread,e.parseExpression()],e.peekSourceCodeInfo()))):r.push(e.parseExpression());const t=e.tryPeek();if(!Zr(t,",")&&!an(t))throw new o("Expected comma or closing parenthesis",e.tryPeek()?.[2]);Zr(t,",")&&e.advance()}if(!an(e.tryPeek()))throw new o("Expected closing parenthesis",e.peekSourceCodeInfo());if(e.advance(),!Dr(t))return Vr(t)||Mr(t)?An(t,r,t[2]):vn([l.NormalExpression,[t,r]],t[2]);{const e=t[1];if(e===tr.import){if(1!==r.length)throw new o(`import expects exactly 1 argument, got ${r.length}`,t[2]);const n=r[0];if(!Mr(n))throw new o("import expects a module name (symbol), got a non-symbol argument",n[2]??t[2]);const a=n[1];return vn([l.SpecialExpression,[e,a]],t[2])}const n=e;switch(ee(rr.specialExpressions[n].arity,r.length,t[2]),n){case tr["||"]:case tr["&&"]:case tr.recur:case tr.array:case tr.object:case tr["??"]:return vn([l.SpecialExpression,[n,r]],t[2]);case tr["defined?"]:{const[e]=r;return vn([l.SpecialExpression,[n,e]],t[2])}case tr.perform:{const[e,...o]=r;return vn([l.SpecialExpression,[n,e,o]],t[2])}case tr.parallel:case tr.race:return vn([l.SpecialExpression,[n,r]],t[2]);case tr["0_lambda"]:throw new o(`${n} is not allowed`,t[2]);default:throw new o(`Unknown special expression: ${n}`,t[2])}}}function Ln(e){const t=dn(e.tryPeek());e.advance();const r=[];for(;!e.isAtEnd()&&!hn(e.tryPeek());){if(Zr(e.tryPeek(),"..."))e.advance(),r.push(vn([l.Spread,e.parseExpression()],e.peekSourceCodeInfo()));else{const t=e.tryPeek();if(gn(t)){const n=In(e,t);r.push(vn([l.String,n[1]],t[2]))}else if(Jr(t)){const n=t[1].startsWith("'")?wn(t[1]):t[1];r.push(vn([l.String,n],t[2])),e.advance()}else{if(!ln(t))throw new o("Expected key to be a symbol or a string",e.peekSourceCodeInfo());e.advance(),r.push(e.parseExpression()),mn(e.tryPeek()),e.advance()}en(e.tryPeek(),":"),e.advance(),r.push(e.parseExpression())}const t=e.tryPeek();if(!Zr(t,",")&&!hn(t))throw new o("Expected comma or closing brace",e.peekSourceCodeInfo());Zr(t,",")&&e.advance()}var n;return hn(n=e.tryPeek())||yn("RBrace",void 0,n),e.advance(),vn([l.SpecialExpression,[tr.object,r]],t[2])}function _n(e){let t=function(e){const t=e.peek();if(nn(t)){e.storePosition();const t=Gn(e);if(t)return t;e.restorePosition(),e.advance();const r=e.parseExpression();if(!an(e.peek()))throw new o("Expected closing parenthesis",e.peekSourceCodeInfo());return e.advance(),r}if(Zr(t)){const r=t[1];if(ur(r))return e.advance(),vn(void 0!==tr[r]?[l.SpecialBuiltinSymbol,tr[r]]:[l.NormalBuiltinSymbol,it[r]],t[2]);if("->"===r)return function(e){const t=e.peek();e.advance();const r=e.getPosition();let n;if(Yr(e.peek(),"do")){const t=jn(e),r=t[1][2];n=r&&r.length>0?[t]:t[1][1]}else n=[e.parseExpression()];const a=e.getPosition()-1;let i=0,s="NOT_SET";for(let n=r;n<=a;n+=1){const r=e.getTokenAt(n);if(Jr(r)){const e=Wn.exec(r[1]);if(e){const r=e[1]??"1";if("1"===r){if(!e[1]&&"WITH_1"===s||e[1]&&"NAKED"===s)throw new o("Please make up your mind, either use $ or $1",t[2]);s=e[1]?"WITH_1":"NAKED"}if(i=Math.max(i,Number(r)),i>20)throw new o("Can't specify more than 20 arguments",t[2])}}}const c=[];for(let e=1;e<=i;e+=1)1===e&&"NAKED"===s?c.push(vn([ut,[[l.UserDefinedSymbol,"$"],void 0]],t[2])):c.push(vn([ut,[[l.UserDefinedSymbol,`$${e}`],void 0]],t[2]));return vn([l.SpecialExpression,[tr["0_lambda"],[c,n]]],t[2])}(e);throw new o(`Illegal operator: ${r}`,t[2])}if(pn(t))return Ln(e);if(ln(t))return function(e){const t=cn(e.tryPeek());e.advance();const r=[];for(;!e.isAtEnd()&&!un(e.tryPeek());){Zr(e.tryPeek(),"...")?(e.advance(),r.push(vn([l.Spread,e.parseExpression()],e.peekSourceCodeInfo()))):r.push(e.parseExpression());const t=e.tryPeek();if(!Zr(t,",")&&!un(t))throw new o("Expected comma or closing parenthesis",e.peekSourceCodeInfo());Zr(t,",")&&e.advance()}return mn(e.tryPeek()),e.advance(),vn([l.SpecialExpression,[tr.array,r]],t[2])}(e);const r=t[0];switch(r){case"Number":case"BasePrefixedNumber":return Rn(e);case"string":return In(e,t);case"Symbol":{e.storePosition();const t=Gn(e);return t||(e.restorePosition(),Cn(e))}case"ReservedSymbol":return Fn(e);case"RegexpShorthand":return function(e){const t=e.peek();e.advance();const r=t[1].lastIndexOf('"'),n=t[1].substring(2,r),o=t[1].substring(r+1),a=vn([l.String,n],t[2]),i=vn([l.String,o],t[2]);return vn([l.NormalExpression,[vn([l.NormalBuiltinSymbol,it.regexp],t[2]),[a,i]]],t[2])}(e);default:throw new o(`Unknown token type: ${r}`,t[2])}}(e),r=e.tryPeek();for(;Zr(r,".")||ln(r)||nn(r);)if("."===r[1]){e.advance();const n=e.tryPeek();if(!Jr(n))throw new o("Expected symbol",e.peekSourceCodeInfo());t=Kn(t,vn([l.String,n[1]],n[2]),r[2]),e.advance(),r=e.tryPeek()}else if(ln(r)){e.advance();const n=e.parseExpression();if(!un(e.tryPeek()))throw new o("Expected closing bracket",e.peekSourceCodeInfo());t=Kn(t,n,r[2]),e.advance(),r=e.tryPeek()}else nn(r)&&(t=Bn(e,t),r=e.tryPeek());return t}function Kn(e,t,r){return vn([l.NormalExpression,[[l.NormalBuiltinSymbol,it.get],[e,t]]],r)}function Jn(e,t=0){const r=e.tryPeek();let n;if(Jr(r))switch(r[1]){case"let":return Vn(e,r);case"if":case"unless":n=function(e,t){const r="unless"===t[1];e.advance();const n=e.parseExpression();Xr(e.tryPeek(),"then"),e.advance();const o=Sn(e,["else","end"]);let a;return Yr(e.tryPeek(),"else")&&(e.advance(),a=Sn(e,["end"])),e.advance(),vn(r?[l.SpecialExpression,[tr.unless,[n,o,a]]]:[l.SpecialExpression,[tr.if,[n,o,a]]],t[2])}(e,r);break;case"cond":n=function(e,t){e.advance();const r=[];for(;!e.isAtEnd()&&!Yr(e.tryPeek(),"end");){Xr(e.tryPeek(),"case"),e.advance();const t=e.parseExpression();Xr(e.tryPeek(),"then"),e.advance();const n=Sn(e,["case","end"]);if(r.push([t,n]),Yr(e.tryPeek(),"end"))break}return Xr(e.tryPeek()),e.advance(),vn([l.SpecialExpression,[tr.cond,r]],t[2])}(e,r);break;case"match":n=function(e,t){e.advance();const r=e.parseExpression(),n=[];for(;!e.isAtEnd()&&!Yr(e.tryPeek(),"end");){Xr(e.tryPeek(),"case"),e.advance();const t=Pn(e,{allowLiteralPatterns:!0});let r;Yr(e.tryPeek(),"when")&&(e.advance(),r=e.parseExpression()),Xr(e.tryPeek(),"then"),e.advance();const o=Sn(e,["case","end"]);if(n.push([t,o,r]),Yr(e.tryPeek(),"end"))break}return Xr(e.tryPeek(),"end"),e.advance(),vn([l.SpecialExpression,[tr.match,r,n]],t[2])}(e,r);break;case"for":case"doseq":n=function(e,t){const r="doseq"===t[1];e.advance(),on(e.tryPeek()),e.advance();const n=[];for(;!e.isAtEnd()&&!an(e.tryPeek());){const t=Dn(e),r=n.flatMap(e=>Object.keys($t(e[0][1][0]))),a=$t(t[0][1][0]);if(Object.keys(a).some(e=>r.includes(e)))throw new o("Duplicate binding",t[0][2]);n.push(t),Zr(e.tryPeek(),",")&&e.advance()}sn(e.tryPeek()),e.advance(),en(e.tryPeek(),"->"),e.advance();const a=e.parseExpression();return vn(r?[l.SpecialExpression,[tr.doseq,n,a]]:[l.SpecialExpression,[tr.for,n,a]],t[2])}(e,r);break;case"loop":n=function(e,t){e.advance(),on(e.tryPeek()),e.advance();const r=[];let n=e.tryPeek();for(;!e.isAtEnd()&&!an(n);){const t=Pn(e,{requireDefaultValue:!0,noRest:!0}),o=t[1][1];t[1][1]=void 0,r.push(vn([l.Binding,[t,o]],t[2])),Zr(e.tryPeek(),",")&&e.advance(),n=e.tryPeek()}if(0===r.length)throw new o("Expected binding",e.peekSourceCodeInfo());sn(n),e.advance(),en(e.tryPeek(),"->"),e.advance();const a=e.parseExpression();return vn([l.SpecialExpression,[tr.loop,r,a]],t[2])}(e,r)}else Yr(r,"do")&&(n=jn(e));n||=_n(e);let a=e.tryPeek();for(;!Nn(e);){if(fn(a)){const r=a[1],o=Tn(r,a[2]);if(o<=t&&(12!==o||12!==t))break;const i=vn(tr[r]?[l.SpecialBuiltinSymbol,tr[r]]:[l.NormalBuiltinSymbol,it[r]],a[2]);e.advance();n=$n(a,i,n,Jn(e,o),a[2])}else if(Jr(a)){if(!lr(a[1]))break;const r=3;if(r<=t)break;const i=Cn(e),s=Jn(e,r);if(Dr(i))throw new o("Special expressions are not allowed in binary functional operators",i[2]);n=An(i,[n,s],a[2])}else{if("?"!==a?.[1])break;{if(1<=t)break;e.advance();const r=Jn(e);if(!Zr(e.tryPeek(),":"))throw new o("Expected :",e.peekSourceCodeInfo());e.advance();const a=Jn(e);n=vn([l.SpecialExpression,[tr.if,[n,r,a]]],n[2])}}a=e.tryPeek()}return n}function Hn(e){e.tokens.forEach(e=>{if("Error"===e[0])throw new o(e[3],e[2])});const t=[],r=function(e){const t=new En(e);return t.parseExpression=(e=0)=>Jn(t,e),t}(e);for(;!r.isAtEnd();)if(t.push(Jn(r,0)),Zr(r.tryPeek(),";"))r.advance();else if(!r.isAtEnd())throw new o("Expected ;",r.peekSourceCodeInfo());return t}function Yn(e,{removeWhiteSpace:t}){const r=e.tokens.filter(e=>!(function(e){return"SingleLineComment"===e?.[0]}(e)||function(e){return"MultiLineComment"===e?.[0]}(e)||function(e){return"Shebang"===e?.[0]}(e)||t&&function(e){return"Whitespace"===e?.[0]}(e)));return{...e,tokens:r}}function Xn(e,t){if("*"===t)return!0;if(t.endsWith(".*")){const r=t.slice(0,-2);return e===r||e.startsWith(`${r}.`)}return e===t}function Qn(e,t){if(!t)return[];const r=[];for(const[n,o]of Object.entries(t))Xn(e,n)&&r.push([n,o]);return r}class Zn{k;snapshots;nextSnapshotIndex;meta;_brand="SuspensionSignal";constructor(e,t,r,n){this.k=e,this.snapshots=t,this.nextSnapshotIndex=r,this.meta=n}}function eo(e){return e instanceof Zn}class to{continuation;value;trimToIndex;_brand="ResumeFromSignal";constructor(e,t,r){this.continuation=e,this.value=t,this.trimToIndex=r}}function ro(e){return e instanceof to}const no=new Map;function oo(e){let t=no.get(e);return t||(t={[h]:!0,name:e},no.set(e,t)),t}function ao(e,t){return Math.imul(e^255&t,16777619)}function io(e,t){return e=ao(e,t),e=ao(e,t>>>8),e=ao(e,t>>>16),e=ao(e,t>>>24)}function so(e,t){for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);e=ao(e,n),e=ao(e,n>>>8)}return e}function lo(e){let t=2166136261;if(null===e)return t=ao(t,0),t>>>0;if(void 0===e)return t=ao(t,7),t>>>0;const r=typeof e;if("boolean"===r)return t=ao(t,e?1:2),t>>>0;if("number"===r)return t=ao(t,3),t=so(t,Object.is(e,-0)?"-0":String(e)),t>>>0;if("string"===r)return t=ao(t,4),t=so(t,e),t>>>0;if(Array.isArray(e)){t=ao(t,5),t=io(t,e.length);for(let r=0;r<e.length;r++)t=io(t,lo(e[r]));return t>>>0}t=ao(t,6);const n=Object.keys(e).sort();t=io(t,n.length);for(const r of n)t=so(t,r),t=io(t,lo(e[r]));return t>>>0}function co(e,t){if(e===t)return!0;if(null===e||null===t)return!1;if(typeof e!=typeof t)return!1;if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!co(e[r],t[r]))return!1;return!0}if("object"!=typeof e)return!1;const r=e,n=t,o=Object.keys(r),a=Object.keys(n);if(o.length!==a.length)return!1;for(const e of o){if(!(e in n))return!1;if(!co(r[e],n[e]))return!1}return!0}function uo(e){if(null===e)return 4;if(void 0===e)return 9;const t=typeof e;if("boolean"===t)return e?4:5;if("number"===t)return String(e).length;if("string"===t)return e.length+2;if(Array.isArray(e)){let t=2;for(let r=0;r<e.length;r++)t+=uo(e[r])+1;return t}const r=e,n=Object.keys(r);let o=2;for(const e of n)o+=e.length+2+1+uo(r[e])+1;return o}function mo(e,t,r,n){if(null===e||"object"!=typeof e)return lo(e);if(Array.isArray(e))for(let r=0;r<e.length;r++)mo(e[r],t,{parent:e,key:r});else{const r=e;for(const e of Object.keys(r))mo(r[e],t,{parent:r,key:e})}const o=lo(e),a=uo(e);if(r&&a>=1){let n,i=t.get(o);i||(i=[],t.set(o,i));for(const t of i)if(co(t.value,e)){n=t;break}n?n.locations.push(r):i.push({hash:o,value:ho(e),size:a,locations:[r]})}return o}function po(e,t){if(null===e||"object"!=typeof e)return e;if(function(e){return null!==e&&"object"==typeof e&&"__poolRef"in e&&"number"==typeof e.__poolRef&&1===Object.keys(e).length}(e)){const r=e.__poolRef;if(!(r in t))throw new Error(`Unknown pool ref: ${r}`);return po(t[r],t)}if(Array.isArray(e))return e.map(e=>po(e,t));const r=e,n={};for(const e of Object.keys(r))n[e]=po(r[e],t);return n}function ho(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(e=>ho(e));const t=e,r={};for(const e of Object.keys(t))r[e]=ho(t[e]);return r}function go(e,t){const r=new Map;let n=0;function o(e){if(e instanceof Wr){if(r.has(e))return;r.set(e,n++);for(const t of e.getContextsRaw())for(const e of Object.values(t))o(e.value)}else if(Array.isArray(e))for(const t of e)o(t);else if(null!==e&&"object"==typeof e)for(const t of Object.values(e))o(t)}function a(e,t){if(e instanceof Wr)return{__csRef:r.get(e)};if(Array.isArray(e))return e.map((e,t)=>a(e));if(null!==e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))t[r]=a(n);return t}return e}o(e),void 0!==t&&o(t);const i=Array.from(r.entries()).map(([e,t])=>({id:t,contexts:e.getContextsRaw().map((e,t)=>{const r={};for(const[t,n]of Object.entries(e))r[t]={value:a(n.value)};return r}),globalContextIndex:e.getGlobalContextIndex(),pure:e.pure})),s=a(e),l=void 0!==t?a(t):void 0;return{version:2,contextStacks:i,k:s,...void 0!==l?{meta:l}:{}}}function fo(e,t,r,n){const o=go(e,n);t.length>0&&(o.snapshots=t),o.nextSnapshotIndex=r;const a=[o.contextStacks,o.k];if(void 0!==o.meta&&a.push(o.meta),o.snapshots)for(const e of o.snapshots)a.push(e);const{roots:i,pool:s}=function(e,t=200){const r=e.map(e=>ho(e)),n=new Map;for(let e=0;e<r.length;e++)mo(r[e],n,null);const o={};let a=0;const i=Array.from(n.values()).flat().filter(e=>e.locations.length>1&&e.size>=t).sort((e,t)=>t.size-e.size),s=new Map;for(const e of i){if(s.has(e))continue;const t=a++;o[t]=e.value,s.set(e,t);for(const r of e.locations)Array.isArray(r.parent),r.parent[r.key]={__poolRef:t}}return{roots:r,pool:o}}(a,200);let l=0;if(o.contextStacks=i[l++],o.k=i[l++],void 0!==o.meta&&(o.meta=i[l++]),o.snapshots)for(let e=0;e<o.snapshots.length;e++)o.snapshots[e]=i[l++];return Object.keys(s).length>0&&(o.pool=s),o}function yo(e,t){let r=e;if(2!==r.version)throw new o(`Unsupported suspension blob version: ${r.version} (expected 2)`,void 0);if(r.pool&&Object.keys(r.pool).length>0){const e=r.pool;r={...r,contextStacks:po(r.contextStacks,e),k:po(r.k,e),...void 0!==r.meta?{meta:po(r.meta,e)}:{},...r.snapshots?{snapshots:r.snapshots.map(t=>po(t,e))}:{}},delete r.pool}const n=new Map;for(const e of r.contextStacks){const r=e.contexts.map(()=>({})),o=Wr.fromDeserialized({contexts:r,globalContextIndex:e.globalContextIndex,values:t?.values,modules:t?.modules,pure:e.pure});n.set(e.id,o)}function a(e){if(function(e){return null!==e&&"object"==typeof e&&"__csRef"in e&&"number"==typeof e.__csRef}(e)){const t=n.get(e.__csRef);if(!t)throw new o(`Invalid suspension blob: unknown context stack ref ${e.__csRef}`,void 0);return t}if(Array.isArray(e))return e.map(a);if(null!==e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))t[r]=a(n);return t}return e}for(const e of r.contextStacks){const t=n.get(e.id),r=e.contexts.map(e=>{const t=e,r={};for(const[e,n]of Object.entries(t))r[e]={value:a(n.value)};return r});t.setContextsFromDeserialized(r,e.globalContextIndex)}return{k:a(r.k),meta:void 0!==r.meta?a(r.meta):void 0,snapshots:r.snapshots??[],nextSnapshotIndex:r.nextSnapshotIndex??0}}function vo(){return"undefined"!=typeof process&&"function"==typeof process.stdout?.write}function bo(e){return"string"==typeof e?e:null===e?"null":"number"==typeof e||"boolean"==typeof e?String(e):q(e)?"Builtin"===e.functionType?`<builtin function ${e.normalBuiltinSymbolType}>`:`<function ${e.n??"λ"}>`:V(e)?`<effect ${e.name}>`:M(e)?`/${e.s}/${e.f}`:"object"==typeof e&&e instanceof RegExp?`${e}`:JSON.stringify(wo(e),null,2)}function wo(e){if(e===Number.POSITIVE_INFINITY)return"∞";if(e===Number.NEGATIVE_INFINITY)return"-∞";if(q(e))return bo(e);if(V(e))return bo(e);if(M(e))return bo(e);if(Array.isArray(e))return e.map(wo);if("object"==typeof e&&null!==e){const t={};for(const[r,n]of Object.entries(e))t[r]=wo(n);return t}return e}const xo={"dvala.io.print":{handler:function(e,t){const r=e[0],n=bo(r);return vo()?process.stdout.write(n):console.log(n),{type:"Value",value:r,k:t}},arity:te(1),docs:{category:"effect",description:"Writes a value to stdout without a trailing newline. Accepts any value — strings are printed as-is, other values are auto-formatted. In Node.js uses `process.stdout.write(str)`, in browsers uses `console.log(str)`. Resumes with the original value (identity).",returns:{type:"any"},args:{value:{type:"any",description:"Value to print."}},variants:[{argumentNames:["value"]}],examples:['perform(effect(dvala.io.print), "hello")',"perform(effect(dvala.io.print), 42)"],seeAlso:["-effect-dvala.io.println","-effect-dvala.io.error","-effect-dvala.io.read-line","perform","effect"]}},"dvala.io.println":{handler:function(e,t){const r=e[0],n=bo(r);return vo()?process.stdout.write(`${n}\n`):"function"==typeof globalThis.alert?globalThis.alert(n):console.log(n),{type:"Value",value:r,k:t}},arity:te(1),docs:{category:"effect",description:'Writes a value to stdout followed by a newline. Accepts any value — strings are printed as-is, other values are auto-formatted. In Node.js uses `process.stdout.write(str + "\\n")`, in browsers uses `alert(str)`. Resumes with the original value (identity).',returns:{type:"any"},args:{value:{type:"any",description:"Value to print."}},variants:[{argumentNames:["value"]}],examples:['perform(effect(dvala.io.println), "hello")',"perform(effect(dvala.io.println), [1, 2, 3])"],seeAlso:["-effect-dvala.io.print","-effect-dvala.io.error","-effect-dvala.io.read-line","perform","effect"]}},"dvala.io.error":{handler:(e,t)=>{const r=e[0],n=bo(r);return vo()?process.stderr.write(`${n}\n`):console.error(n),{type:"Value",value:r,k:t}},arity:te(1),docs:{category:"effect",description:'Writes a value to stderr followed by a newline. Accepts any value — strings are printed as-is, other values are auto-formatted. In Node.js uses `process.stderr.write(str + "\\n")`, in browsers uses `console.error(str)`. Resumes with the original value (identity).',returns:{type:"any"},args:{value:{type:"any",description:"Value to write to stderr."}},variants:[{argumentNames:["value"]}],examples:['perform(effect(dvala.io.error), "something went wrong")'],seeAlso:["-effect-dvala.io.print","-effect-dvala.io.println","perform","effect"]}},"dvala.io.read-line":{handler:(e,t,r)=>{const n="string"==typeof e[0]?e[0]:"";if("function"==typeof globalThis.prompt){return{type:"Value",value:globalThis.prompt(n)??null,k:t}}throw new o('dvala.io.read-line is not supported in this environment. In Node.js, register a "dvala.io.read-line" host handler.',r)},arity:{min:0,max:1},docs:{category:"effect",description:"Reads one line of user input. In browsers uses `window.prompt()`. In Node.js uses `readline`. Resumes with the user's input string, or `null` on cancel.",returns:{type:["string","null"]},args:{message:{type:"string",description:"Optional prompt message to display."}},variants:[{argumentNames:[]},{argumentNames:["message"]}],examples:["effect(dvala.io.read-line)"],seeAlso:["-effect-dvala.io.read-stdin","-effect-dvala.io.print","-effect-dvala.io.println","perform","effect"]}},"dvala.io.read-stdin":{handler:(e,t,r)=>{if(!vo()||!process.stdin)throw new o("dvala.io.read-stdin is not supported in this environment. Node.js is required.",r);return new Promise((e,r)=>{const n=[];process.stdin.setEncoding("utf-8"),process.stdin.on("data",e=>n.push(e)),process.stdin.on("end",()=>e({type:"Value",value:n.join(""),k:t})),process.stdin.on("error",e=>r(e)),process.stdin.resume()})},arity:te(0),docs:{category:"effect",description:"Reads all of stdin until EOF (Node.js only). Resumes with the full stdin content as a string.",returns:{type:"string"},args:{},variants:[{argumentNames:[]}],examples:["effect(dvala.io.read-stdin)"],seeAlso:["-effect-dvala.io.read-line","perform","effect"]}},"dvala.random":{handler:(e,t)=>({type:"Value",value:Math.random(),k:t}),arity:te(0),docs:{category:"effect",description:"Returns a random floating-point number in the range [0, 1). Equivalent to `Math.random()` in JavaScript.",returns:{type:"number"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.random))"],seeAlso:["-effect-dvala.random.int","-effect-dvala.random.uuid","-effect-dvala.random.item","-effect-dvala.random.shuffle","perform","effect"]}},"dvala.random.uuid":{handler:(e,t)=>({type:"Value",value:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),k:t}),arity:te(0),docs:{category:"effect",description:"Generates a UUID v4 string.",returns:{type:"string"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.random.uuid))"],seeAlso:["-effect-dvala.random","perform","effect"]}},"dvala.random.int":{handler:(e,t,r)=>{const n=e[0],a=e[1];if("number"!=typeof n||!Number.isInteger(n))throw new o(`dvala.random.int: min must be an integer, got ${"number"==typeof n?n:typeof n}`,r);if("number"!=typeof a||!Number.isInteger(a))throw new o(`dvala.random.int: max must be an integer, got ${"number"==typeof a?a:typeof a}`,r);if(a<=n)throw new o(`dvala.random.int: max (${a}) must be greater than min (${n})`,r);return{type:"Value",value:Math.floor(Math.random()*(a-n))+n,k:t}},arity:te(2),docs:{category:"effect",description:"Returns a random integer in the range [min, max).",returns:{type:"integer"},args:{min:{type:"integer",description:"Minimum value (inclusive)."},max:{type:"integer",description:"Maximum value (exclusive). Must be greater than min."}},variants:[{argumentNames:["min","max"]}],examples:["perform(effect(dvala.random.int), 1, 100)"],seeAlso:["-effect-dvala.random","-effect-dvala.random.item","perform","effect"]}},"dvala.random.item":{handler:(e,t,r)=>{const n=e[0];if(!Array.isArray(n))throw new o("dvala.random.item: argument must be an array, got "+typeof n,r);if(0===n.length)throw new o("dvala.random.item: cannot pick from an empty array",r);return{type:"Value",value:n[Math.floor(Math.random()*n.length)],k:t}},arity:te(1),docs:{category:"effect",description:"Picks a random element from a non-empty array.",returns:{type:"any"},args:{array:{type:"array",description:"Non-empty array to pick from."}},variants:[{argumentNames:["array"]}],examples:['perform(effect(dvala.random.item), ["a", "b", "c"])'],seeAlso:["-effect-dvala.random","-effect-dvala.random.shuffle","-effect-dvala.random.int","perform","effect"]}},"dvala.random.shuffle":{handler:(e,t,r)=>{const n=e[0];if(!Array.isArray(n))throw new o("dvala.random.shuffle: argument must be an array, got "+typeof n,r);const a=Array.from(n);for(let e=a.length-1;e>0;e--){const t=Math.floor(Math.random()*(e+1)),r=a[e];a[e]=a[t],a[t]=r}return{type:"Value",value:a,k:t}},arity:te(1),docs:{category:"effect",description:"Returns a new array with the elements of the input array in random order. Uses the Fisher-Yates shuffle algorithm.",returns:{type:"array"},args:{array:{type:"array",description:"Array to shuffle."}},variants:[{argumentNames:["array"]}],examples:["perform(effect(dvala.random.shuffle), [1, 2, 3, 4, 5])"],seeAlso:["-effect-dvala.random","-effect-dvala.random.item","perform","effect"]}},"dvala.time.now":{handler:(e,t)=>({type:"Value",value:Date.now(),k:t}),arity:te(0),docs:{category:"effect",description:"Returns the current timestamp in milliseconds since the Unix epoch. Equivalent to `Date.now()` in JavaScript.",returns:{type:"number"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.time.now))"],seeAlso:["-effect-dvala.time.zone","-effect-dvala.sleep","perform","effect"]}},"dvala.time.zone":{handler:(e,t)=>({type:"Value",value:Intl.DateTimeFormat().resolvedOptions().timeZone,k:t}),arity:te(0),docs:{category:"effect",description:'Returns the current IANA timezone string, e.g. `"Europe/Stockholm"` or `"America/New_York"`.',returns:{type:"string"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.time.zone))"],seeAlso:["-effect-dvala.time.now","perform","effect"]}},"dvala.checkpoint":{handler:(e,t)=>({type:"Value",value:null,k:t}),arity:{min:0,max:1},docs:{category:"effect",description:"Captures a snapshot of the current program state (continuation stack). The snapshot is stored in an in-memory list accessible via `ctx.snapshots` in host handlers. Optionally accepts a metadata value for domain context (e.g., step labels, timestamps). The standard fallback resumes with `null`, but host handlers can override the resume value. The snapshot is always captured regardless of whether a handler intercepts.",returns:{type:"null"},args:{meta:{type:"any",description:"Optional metadata to attach to the snapshot."}},variants:[{argumentNames:[]},{argumentNames:["meta"]}],examples:["perform(effect(dvala.checkpoint))",'perform(effect(dvala.checkpoint), { step: "analysis-done" })'],seeAlso:["perform","effect"]}},"dvala.sleep":{handler:(e,t,r)=>{const n=e[0];if("number"!=typeof n||n<0)throw new o(`dvala.sleep requires a non-negative number argument, got ${"number"==typeof n?n:typeof n}`,r);return new Promise(e=>{setTimeout(()=>e({type:"Value",value:null,k:t}),n)})},arity:te(1),docs:{category:"effect",description:"Waits for the specified number of milliseconds before resuming. Resumes with `null`. Only works in async execution (`run`) — `runSync` will throw when a Promise surfaces.",returns:{type:"null"},args:{ms:{type:"number",description:"The number of milliseconds to sleep. Must be a non-negative number."}},variants:[{argumentNames:["ms"]}],examples:["effect(dvala.sleep)"],seeAlso:["-effect-dvala.time.now","perform","effect"]}}};function ko(e,t){switch(e[0]){case l.Number:case l.String:return e[1];case l.NormalBuiltinSymbol:case l.SpecialBuiltinSymbol:case l.UserDefinedSymbol:return t.evaluateSymbol(e);case l.ReservedSymbol:return zo(e);case l.NormalExpression:{const r=function(e,t){const r=e[2];return ft(function(e,t){const r=[],n=[],a=wt(e,(e,a)=>Fr(e)?ft(ko(e[1],t),t=>{if(!Array.isArray(t))throw new o(`Spread operator requires an array, got ${y(e)}`,e[2]);r.push(...t)}):e[0]!==l.ReservedSymbol||"_"!==e[1]?ft(ko(e,t),e=>{r.push(e)}):void n.push(a));return ft(a,()=>({params:r,placeholders:n}))}(e[1][1],t),({params:n,placeholders:a})=>{if(Ur(e)){const i=e[1][0];if(a.length>0){return ft(ko(i,t),e=>({[p]:!0,function:U(e,r),functionType:"Partial",params:n,placeholders:a,sourceCodeInfo:r,arity:te(a.length)}))}if(Vr(i)){const r=i[1],a=rr.allNormalExpressions[r];if(t.pure&&!1===a.pure)throw new o(`Cannot call impure function '${a.name}' in pure mode`,e[2]);return a.dvalaImpl?No(a.dvalaImpl,n,t,e[2]):a.evaluate(n,e[2],t,{executeFunction:qo})}{const o=t.getValue(i[1]);if(void 0!==o)return qo(U(o,r),n,t,r);throw new s(i[1],e[2])}}return ft(ko(e[1][0],t),e=>{const o=U(e,r);if(a.length>0){return{[p]:!0,function:o,functionType:"Partial",params:n,placeholders:a,sourceCodeInfo:r,arity:te(a.length)}}return qo(o,n,t,r)})})}(e,t);return ft(r,t=>{if("number"==typeof t&&Number.isNaN(t))throw new o("Number is NaN",e[2]);return ze(t)})}case l.SpecialExpression:{const r={type:"Eval",node:e,env:t,k:[]};try{return ze(ea(r))}catch(r){if(r instanceof o&&r.message.includes("Unexpected async operation")){return ta({type:"Eval",node:e,env:t,k:[]}).then(e=>ze(e))}throw r}}default:throw new o(`${u(e[0])}-node cannot be evaluated`,e[2])}}function qo(e,t,r,n){if(q(e))return Ao(e,t,r,n);if(Array.isArray(e))return Eo(e,t,n);if(j(e))return $o(e,t,n);if("string"==typeof e)return To(e,t,n);if(H(e))return So(e,t,n);throw new o("Unexpected function type",n)}function Ao(e,t,r,n){switch(e.functionType){case"UserDefined":return No(e,t,r,n);case"Partial":return function(e,t,r,n){const a=[...e.params];if(t.length!==e.placeholders.length)throw new o(`(partial) expects ${e.placeholders.length} arguments, got ${t.length}.`,n);const i=[...t];for(const t of e.placeholders)a.splice(t,0,i.shift());return qo(e.function,a,r,n)}(e,t,r,n);case"Comp":return function(e,t,r,n){const{params:a}=e;if(0===a.length){if(1!==t.length)throw new o(`(comp) expects one argument, got ${y(t.length)}.`,n);return $(t[0],n)}let i=t;for(let e=a.length-1;e>=0;e--){const t=a[e];i=ft(i,e=>ft(qo(U(t,n),e,r,n),e=>[e]))}return ft(i,e=>$(e[0],n))}(e,t,r,n);case"Constantly":return e.value;case"Juxt":return function(e,t,r,n){return function(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return yt(o,r,e,t,n);r.push(o)}return r}(e.params,e=>qo(U(e,n),t,r,n))}(e,t,r,n);case"Complement":return ft(qo(e.function,t,r,n),e=>!e);case"EveryPred":return function(e,t,r,n){const o=[];for(const a of e.params)for(const e of t)o.push(()=>qo(U(a,n),[e],r,n));return vt(o,(e,t)=>!!e&&ft(t(),e=>!!e),!0)}(e,t,r,n);case"SomePred":return function(e,t,r,n){const o=[];for(const a of e.params)for(const e of t)o.push(()=>qo(U(a,n),[e],r,n));return vt(o,(e,t)=>!!e||ft(t(),e=>!!e),!1)}(e,t,r,n);case"Fnull":return function(e,t,r,n){const o=t.map((t,r)=>null===t?le(e.params[r]):t);return qo(U(e.function,n),o,r,n)}(e,t,r,n);case"EffectMatcher":return function(e,t,r){ee({min:1,max:1},t.length,e.sourceCodeInfo??r);const n=t[0];D(n,r);const o=n.name;if("string"===e.matchType)return Xn(o,e.pattern);const a=new RegExp(e.pattern,e.flags);return a.test(o)}(e,t,n);case"Builtin":{const a=rr.allNormalExpressions[e.normalBuiltinSymbolType];return a.dvalaImpl?No(a.dvalaImpl,t,r,n):function(e,t,r,n){const a=w(rr.allNormalExpressions[e.normalBuiltinSymbolType],n);if(r.pure&&!1===a.pure)throw new o(`Cannot call impure function '${e.name}' in pure mode`,n);if(a.dvalaImpl)return No(a.dvalaImpl,t,r,n);return a.evaluate(t,n,r,{executeFunction:qo})}(e,t,r,n)}case"SpecialBuiltin":return function(e,t,r,n){const a=w(rr.specialExpressions[e.specialBuiltinSymbolType],n);if(a.evaluateAsNormalExpression)return a.evaluateAsNormalExpression(t,n,r,{executeFunction:qo});throw new o(`Special builtin function ${e.specialBuiltinSymbolType} is not supported as normal expression.`,n)}(e,t,r,n);case"Module":return function(e,t,r,n){const a=r.getModule(e.moduleName);if(!a)throw new o(`Module '${e.moduleName}' not found.`,n);const i=a.functions[e.functionName];if(!i)throw new o(`Function '${e.functionName}' not found in module '${e.moduleName}'.`,n);if(r.pure&&!1===i.pure)throw new o(`Cannot call impure function '${e.functionName}' in pure mode`,n);if(ee(i.arity,t.length,n),i.dvalaImpl)return No(i.dvalaImpl,t,r,n);return i.evaluate(t,n,r,{executeFunction:qo})}(e,t,r,n)}}function No(e,t,r,a){function i(t){if(!Q(e.arity,t.length))throw new o(`Expected ${e.arity} arguments, got ${t.length}.`,a);const s=e.evaluatedfunction,l=s[0],c=l.filter(e=>e[0]!==mt).length,u=r.create(e.evaluatedfunction[2]),m={self:{value:e}},p=[];let d,h;for(let e=0;e<t.length;e+=1)if(e<c){const r=e;d=ft(d,()=>{const e=le(t[r]);return ft(At(l[r],e,e=>ko(e,u.create(m))),e=>{Object.entries(e).forEach(([e,t])=>{m[e]={value:t}})})})}else p.push(le(t[e]));for(let e=t.length;e<c;e++){const t=e;h=ft(h,()=>{const e=l[t];return ft(ko(e[1][1],r.create(m)),t=>ft(At(e,t,e=>ko(e,r.create(m))),e=>{Object.entries(e).forEach(([e,t])=>{m[e]={value:t}})}))})}return ft(d,()=>ft(h,()=>{const e=l.find(e=>e[0]===mt),t=void 0!==e?ft(At(e,p,e=>ko(e,r.create(m))),e=>{Object.entries(e).forEach(([e,t])=>{m[e]={value:t}})}):void 0;return ft(t,()=>{const e=u.create(m),t=vt(s[1],(t,r)=>ko(r,e),null);return t instanceof Promise?t.catch(e=>{if(e instanceof n)return i(e.params);throw e}):t})}))}for(;;)try{return i(t)}catch(e){if(e instanceof n){t=e.params;continue}throw e}}function $o(e,t,r){if(1!==t.length)throw new o("Object as function requires one string parameter.",r);const n=t[0];return G(n,r),le(e[n])}function Eo(e,t,r){if(1!==t.length)throw new o("Array as function requires one non negative integer parameter.",r);const n=t[0];return Y(n,r,{integer:!0,nonNegative:!0}),le(e[n])}function To(e,t,r){if(1!==t.length)throw new o("String as function requires one Obj parameter.",r);const n=le(t[0]);if(j(n))return le(n[e]);if(H(n,{integer:!0}))return le(e[n]);throw new o(`string as function expects Obj or integer parameter, got ${y(n)}`,r)}function So(e,t,r){if(Y(e,void 0,{integer:!0}),1!==t.length)throw new o("Number as function requires one Arr parameter.",r);const n=t[0];return z(n,r),le(n[e])}function zo(e){const t=e[1];if(!["true","false","null"].includes(t))throw new o(`Reserved symbol ${t} cannot be evaluated`,e[2]);return w(gr[t],e[2])}function jo(e,t,r){switch(e[0]){case l.Number:case l.String:return{type:"Value",value:e[1],k:r};case l.NormalBuiltinSymbol:case l.SpecialBuiltinSymbol:case l.UserDefinedSymbol:return{type:"Value",value:t.evaluateSymbol(e),k:r};case l.ReservedSymbol:return{type:"Value",value:zo(e),k:r};case l.NormalExpression:return function(e,t,r){const n=e[1][1],o=e[2],a={type:"NanCheck",sourceCodeInfo:o},i={type:"EvalArgs",node:e,index:0,params:[],placeholders:[],env:t,sourceCodeInfo:o};let s=0;for(;s<n.length;){const e=n[s];if(e[0]!==l.ReservedSymbol||"_"!==e[1])break;i.placeholders.push(i.params.length),s++}if(i.index=s,s>=n.length)return Co(i,[a,...r]);const c=n[s],u=[i,a,...r];if(Fr(c))return{type:"Eval",node:c[1],env:t,k:u};return{type:"Eval",node:c,env:t,k:u}}(e,t,r);case l.SpecialExpression:return function(e,t,r){const n=e[2],a=e[1][0];switch(a){case tr.if:case tr.unless:{const[o,i,s]=e[1][1];return{type:"Eval",node:o,env:t,k:[{type:"IfBranch",thenNode:i,elseNode:s,inverted:a===tr.unless,env:t,sourceCodeInfo:n},...r]}}case tr["&&"]:{const o=e[1][1];if(0===o.length)return{type:"Value",value:!0,k:r};const a={type:"And",nodes:o,index:1,env:t,sourceCodeInfo:n};return 1===o.length?{type:"Eval",node:o[0],env:t,k:r}:{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr["||"]:{const o=e[1][1];if(0===o.length)return{type:"Value",value:!1,k:r};const a={type:"Or",nodes:o,index:1,env:t,sourceCodeInfo:n};return 1===o.length?{type:"Eval",node:o[0],env:t,k:r}:{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr["??"]:{const o=e[1][1];if(0===o.length)return{type:"Value",value:null,k:r};const a=o[0];if(Mr(a)&&null===t.lookUp(a)){if(1===o.length)return{type:"Value",value:null,k:r};const e={type:"Qq",nodes:o,index:2,env:t,sourceCodeInfo:n},a=o[1];return Mr(a)&&null===t.lookUp(a)?function(e,t){return Oo(e,t)}(e,r):2===o.length?{type:"Eval",node:a,env:t,k:r}:{type:"Eval",node:a,env:t,k:[e,...r]}}const i={type:"Qq",nodes:o,index:1,env:t,sourceCodeInfo:n};return 1===o.length?{type:"Eval",node:a,env:t,k:r}:{type:"Eval",node:a,env:t,k:[i,...r]}}case tr.cond:{const o=e[1][1];if(0===o.length)return{type:"Value",value:null,k:r};const a={type:"Cond",phase:"test",cases:o,index:0,env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0][0],env:t,k:[a,...r]}}case tr.match:{const o=e[1][1],a=e[1][2];return{type:"Eval",node:o,env:t,k:[{type:"Match",phase:"matchValue",matchValue:null,cases:a,index:0,bindings:{},env:t,sourceCodeInfo:n},...r]}}case tr.block:{const o=e[1][1],a=e[1][2],i={},s=t.create(i);let l=r;if(a&&a.length>0){l=[{type:"TryWith",handlers:a.map(([e,r])=>({effectRef:ko(e,t),handlerNode:r})),env:t,sourceCodeInfo:n},...r]}if(0===o.length)return{type:"Value",value:null,k:l};if(1===o.length)return{type:"Eval",node:o[0],env:s,k:l};const c={type:"Sequence",nodes:o,index:1,env:s,sourceCodeInfo:n};return{type:"Eval",node:o[0],env:s,k:[c,...l]}}case tr.let:{const o=e[1][1],a=o[1][0];return{type:"Eval",node:o[1][1],env:t,k:[{type:"LetBind",target:a,env:t,sourceCodeInfo:n},...r]}}case tr.loop:{const o=e[1][1],a=e[1][2];if(0===o.length){const e={},i={type:"LoopIterate",bindingNodes:o,bindingContext:e,body:a,env:t.create(e),sourceCodeInfo:n};return{type:"Eval",node:a,env:t.create(e),k:[i,...r]}}const i={type:"LoopBind",phase:"value",bindingNodes:o,index:0,context:{},body:a,env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0][1][1],env:t,k:[i,...r]}}case tr.for:case tr.doseq:{const o=e[1][1],i=e[1][2],s=a===tr.for;if(0===o.length)return{type:"Value",value:s?[]:null,k:r};const l={},c=t.create(l),u={type:"ForLoop",returnResult:s,bindingNodes:o,body:i,result:[],phase:"evalCollection",bindingLevel:0,levelStates:[],context:l,env:c,sourceCodeInfo:n};return{type:"Eval",node:o[0][0][1][1],env:c,k:[u,...r]}}case tr.recur:{const o=e[1][1];if(0===o.length)return Bo([],r,n);const a={type:"Recur",nodes:o,index:1,params:[],env:t,sourceCodeInfo:n};if(1===o.length){const e={...a,index:1};return{type:"Eval",node:o[0],env:t,k:[e,...r]}}return{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr.array:{const o=e[1][1];if(0===o.length)return{type:"Value",value:[],k:r};const a=o[0],i=Fr(a),s={type:"ArrayBuild",nodes:o,index:0,result:[],isSpread:i,env:t,sourceCodeInfo:n};return{type:"Eval",node:i?a[1]:a,env:t,k:[s,...r]}}case tr.object:{const o=e[1][1];if(0===o.length)return{type:"Value",value:{},k:r};const a=o[0],i=Fr(a),s={type:"ObjectBuild",nodes:o,index:0,result:{},currentKey:null,isSpread:i,env:t,sourceCodeInfo:n};return{type:"Eval",node:i?a[1]:a,env:t,k:[s,...r]}}case tr["0_lambda"]:{const n=function(e,t){const r={},n=e[0].reduce((e,t)=>(Object.keys($t(t)).forEach(t=>{e[t]={value:null}}),e),{});return _r(e[1],t.new(n),rr,ko).forEach(e=>{const n=t.getValue(e);N(n)&&(r[e]={value:n})}),[e[0],e[1],r]}(e[1][1],t),o=n[0].filter(e=>e[0]!==mt&&void 0===e[1][1]).length,a={min:o>0?o:void 0,max:n[0].some(e=>e[0]===mt)?void 0:n[0].length};return{type:"Value",value:{[p]:!0,sourceCodeInfo:e[2],functionType:"UserDefined",name:void 0,evaluatedfunction:n,arity:a,docString:""},k:r}}case tr["defined?"]:{const n=e[1][1];if(!Mr(n))return{type:"Value",value:!0,k:r};return{type:"Value",value:null!==t.lookUp(n),k:r}}case tr.import:{const a=e[1][1],i=t.getValueModule(a);if(i.found)return{type:"Value",value:i.value,k:r};const s=t.getModule(a);if(!s)throw new o(`Unknown module: '${a}'`,n);const l={};for(const[e,t]of Object.entries(s.functions))l[e]={[p]:!0,sourceCodeInfo:n,functionType:"Module",moduleName:a,functionName:e,arity:t.arity};if(s.source){const e=Hn(Yn(jr(s.source,!1,void 0),{removeWhiteSpace:!0})),o=t.create({}),i={type:"ImportMerge",tsFunctions:l,moduleName:a,module:s,env:t,sourceCodeInfo:n};if(1===e.length)return{type:"Eval",node:e[0],env:o,k:[i,...r]};const c={type:"Sequence",nodes:e,index:1,env:o};return{type:"Eval",node:e[0],env:o,k:[c,i,...r]}}return t.registerValueModule(a,l),{type:"Value",value:l,k:r}}case tr.effect:return{type:"Value",value:oo(e[1][1]),k:r};case tr.perform:{const o=[e[1][1],...e[1][2]];if(1===o.length){const e={type:"PerformArgs",argNodes:o,index:1,params:[],env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0],env:t,k:[e,...r]}}const a={type:"PerformArgs",argNodes:o,index:1,params:[],env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr.parallel:return{type:"Parallel",branches:e[1][1],env:t,k:r};case tr.race:return{type:"Race",branches:e[1][1],env:t,k:r};default:throw new o(`Unknown special expression type: ${a}`,n)}}(e,t,r);default:throw new o(`${u(e[0])}-node cannot be evaluated`,e[2])}}function Co(e,t){const{node:r,params:n,placeholders:a,env:i,sourceCodeInfo:l}=e;if(Ur(r)){const e=r[1][0];if(a.length>0){const r=i.evaluateSymbol(e);return{type:"Value",value:{[p]:!0,function:U(r,l),functionType:"Partial",params:n,placeholders:a,sourceCodeInfo:l,arity:te(a.length)},k:t}}if(Vr(e)){const r=e[1],a=rr.allNormalExpressions[r];if(i.pure&&!1===a.pure)throw new o(`Cannot call impure function '${a.name}' in pure mode`,l);if(a.dvalaImpl)return Ro(a.dvalaImpl,n,i,l,t);return Qo(a.evaluate(n,l,i,{executeFunction:qo}),t)}const c=i.getValue(e[1]);if(void 0!==c)return Io(U(c,l),n,a,i,l,t);throw new s(e[1],l)}return{type:"Eval",node:r[1][0],env:i,k:[{type:"CallFn",params:n,placeholders:a,env:i,sourceCodeInfo:l},...t]}}function Io(e,t,r,n,a,i){if(r.length>0){return{type:"Value",value:{[p]:!0,function:e,functionType:"Partial",params:t,placeholders:r,sourceCodeInfo:a,arity:te(r.length)},k:i}}if(q(e))return function(e,t,r,n,o){switch(e.functionType){case"UserDefined":return Ro(e,t,r,n,o);case"Partial":case"Comp":case"Constantly":case"Juxt":case"Complement":case"EveryPred":case"SomePred":case"Fnull":case"EffectMatcher":case"SpecialBuiltin":return Qo(Ao(e,t,r,n),o);case"Module":{const a=r.getModule(e.moduleName),i=a?.functions[e.functionName];if(i?.dvalaImpl)return ee(i.arity,t.length,n),Ro(i.dvalaImpl,t,r,n,o);return Qo(Ao(e,t,r,n),o)}case"Builtin":{const a=rr.allNormalExpressions[e.normalBuiltinSymbolType];if(a.dvalaImpl)return Ro(a.dvalaImpl,t,r,n,o);return Qo(Ao(e,t,r,n),o)}}}(e,t,n,a,i);if(Array.isArray(e))return{type:"Value",value:Eo(e,t,a),k:i};if(j(e))return{type:"Value",value:$o(e,t,a),k:i};if("string"==typeof e)return{type:"Value",value:To(e,t,a),k:i};if(H(e))return{type:"Value",value:So(e,t,a),k:i};throw new o("Unexpected function type",a)}function Ro(e,t,r,n,a){if(!Q(e.arity,t.length))throw new o(`Expected ${e.arity} arguments, got ${t.length}.`,n);const i=e.evaluatedfunction,s=i[0],l=s.filter(e=>e[0]!==mt).length,c=r.create(e.evaluatedfunction[2]),u={self:{value:e}},m=[];for(let o=0;o<t.length;o+=1)if(o<l){const i=le(t[o]),l=At(s[o],i,e=>ko(e,c.create(u)));if(l instanceof Promise){return Qo(No(e,t,r,n),a)}Object.entries(l).forEach(([e,t])=>{u[e]={value:t}})}else m.push(le(t[o]));for(let o=t.length;o<l;o++){const i=s[o],l=ko(i[1][1],c.create(u));if(l instanceof Promise){return Qo(No(e,t,r,n),a)}const m=At(i,l,e=>ko(e,c.create(u)));if(m instanceof Promise){return Qo(No(e,t,r,n),a)}Object.entries(m).forEach(([e,t])=>{u[e]={value:t}})}const p=s.find(e=>e[0]===mt);if(p){const o=At(p,m,e=>ko(e,c.create(u)));if(o instanceof Promise){return Qo(No(e,t,r,n),a)}Object.entries(o).forEach(([e,t])=>{u[e]={value:t}})}const d=i[1],h=c.create(u);if(0===d.length)return{type:"Value",value:null,k:a};const g={type:"FnBody",fn:e,bodyIndex:1,env:h,outerEnv:r,sourceCodeInfo:n};return d.length,{type:"Eval",node:d[0],env:h,k:[g,...a]}}function Po(e,t,r){switch(e.type){case"Sequence":return function(e,t,r){const{nodes:n,index:o,env:a}=e;if(o>=n.length)return{type:"Value",value:t,k:r};const i={...e,index:o+1};if(o===n.length-1)return{type:"Eval",node:n[o],env:a,k:r};return{type:"Eval",node:n[o],env:a,k:[i,...r]}}(e,t,r);case"IfBranch":return function(e,t,r){const{thenNode:n,elseNode:o,inverted:a,env:i}=e,s=a?!t:t;if(s)return{type:"Eval",node:n,env:i,k:r};if(o)return{type:"Eval",node:o,env:i,k:r};return{type:"Value",value:null,k:r}}(e,t,r);case"Cond":return function(e,t,r){const{cases:n,index:o,env:a}=e;if("test"===e.phase){if(t)return{type:"Eval",node:n[o][1],env:a,k:r};const i=o+1;if(i>=n.length)return{type:"Value",value:null,k:r};const s={...e,index:i};return{type:"Eval",node:n[i][0],env:a,k:[s,...r]}}return{type:"Value",value:t,k:r}}(e,t,r);case"Match":return function(e,t,r){const{cases:n,env:o}=e;if("matchValue"===e.phase){const n=t;return Mo({...e,matchValue:n,phase:"guard"},r)}if("guard"===e.phase){if(!t){return Mo({...e,index:e.index+1,bindings:{}},r)}const a={};for(const[t,r]of Object.entries(e.bindings))a[t]={value:r};const i=o.create(a);return{type:"Eval",node:n[e.index][1],env:i,k:r}}return{type:"Value",value:t,k:r}}(e,t,r);case"And":return function(e,t,r){if(!t)return{type:"Value",value:t,k:r};const{nodes:n,index:o,env:a}=e;if(o>=n.length)return{type:"Value",value:t,k:r};if(o===n.length-1)return{type:"Eval",node:n[o],env:a,k:r};const i={...e,index:o+1};return{type:"Eval",node:n[o],env:a,k:[i,...r]}}(e,t,r);case"Or":return function(e,t,r){if(t)return{type:"Value",value:t,k:r};const{nodes:n,index:o,env:a}=e;if(o>=n.length)return{type:"Value",value:t,k:r};if(o===n.length-1)return{type:"Eval",node:n[o],env:a,k:r};const i={...e,index:o+1};return{type:"Eval",node:n[o],env:a,k:[i,...r]}}(e,t,r);case"Qq":return function(e,t,r){if(null!==t)return{type:"Value",value:t,k:r};return Oo(e,r)}(e,t,r);case"ArrayBuild":return function(e,t,r){const{nodes:n,result:a,env:i,sourceCodeInfo:s}=e;if(e.isSpread){if(!Array.isArray(t))throw new o("Spread value is not an array",s);a.push(...t)}else a.push(t);const l=e.index+1;if(l>=n.length)return{type:"Value",value:a,k:r};const c=n[l],u=Fr(c),m={...e,index:l,isSpread:u};return{type:"Eval",node:u?c[1]:c,env:i,k:[m,...r]}}(e,t,r);case"ObjectBuild":return function(e,t,r){const{nodes:n,result:a,env:i,sourceCodeInfo:s}=e;if(e.isSpread){if(!k(t))throw new o("Spread value is not an object",s);Object.assign(a,t);const l=e.index+1;if(l>=n.length)return{type:"Value",value:a,k:r};const c=n[l],u=Fr(c),m={...e,index:l,currentKey:null,isSpread:u};return{type:"Eval",node:u?c[1]:c,env:i,k:[m,...r]}}if(null===e.currentKey){G(t,s);const a=n[e.index+1];if(void 0===a)throw new o("Missing value for key",s);return{type:"Eval",node:a,env:i,k:[{...e,currentKey:t},...r]}}{a[e.currentKey]=t;const o=e.index+2;if(o>=n.length)return{type:"Value",value:a,k:r};const s=n[o],l=Fr(s),c={...e,index:o,currentKey:null,isSpread:l};return{type:"Eval",node:l?s[1]:s,env:i,k:[c,...r]}}}(e,t,r);case"LetBind":return function(e,t,r){const{target:n,env:o,sourceCodeInfo:a}=e,i=At(n,t,e=>ko(e,o));return ft(i,e=>(o.addValues(e,a),{type:"Value",value:t,k:r}))}(e,t,r);case"LoopBind":return function(e,t,r){const{bindingNodes:n,index:o,context:a,body:i,env:s,sourceCodeInfo:l}=e,c=n[o],u=At(c[1][0],t,e=>ko(e,s.create(a)));return ft(u,t=>{Object.entries(t).forEach(([e,t])=>{a[e]={value:t}});const c=o+1;if(c>=n.length){const e=s.create(a);return{type:"Eval",node:i,env:e,k:[{type:"LoopIterate",bindingNodes:n,bindingContext:a,body:i,env:e,sourceCodeInfo:l},...r]}}const u={...e,index:c};return{type:"Eval",node:n[c][1][1],env:s.create(a),k:[u,...r]}})}(e,t,r);case"LoopIterate":return function(e,t,r){return{type:"Value",value:t,k:r}}(0,t,r);case"ForLoop":return function(e,t,r){const{returnResult:n,bindingNodes:a,result:i,env:s,sourceCodeInfo:l,context:c}=e,{asColl:u,isSeq:m}={asColl:(e,t)=>{if("string"==typeof e||Array.isArray(e)||j(e))return e;throw new o(`Expected collection, got ${y(e)}`,t)},isSeq:e=>"string"==typeof e||Array.isArray(e)};switch(e.phase){case"evalCollection":{const n=u(t,l),o=m(n)?n:Object.entries(n);if(0===o.length)return Vo(e,r);const i=[...e.levelStates];i[e.bindingLevel]={collection:o,index:0};const p=a[e.bindingLevel];return ft(At(p[0][1][0],$(o[0],l),e=>ko(e,s)),t=>{Object.entries(t).forEach(([e,t])=>{c[e]={value:t}});const n=p[1];return n.length>0?Uo(e,i,n,0,r):Fo(e,i,r)})}case"evalLet":throw new o("ForLoop evalLet should not reach applyFrame",l);case"evalWhen":{if(!t)return Do(e,r);const n=a[e.bindingLevel][3];if(n){const t={...e,phase:"evalWhile"};return{type:"Eval",node:n,env:s,k:[t,...r]}}return Wo(e,r)}case"evalWhile":if(!t){const t=[...e.levelStates];return t[e.bindingLevel]={...t[e.bindingLevel],index:Number.POSITIVE_INFINITY},Do({...e,levelStates:t},r)}return Wo(e,r);case"evalBody":return n&&i.push(t),Do(e,r);case"evalElement":throw new o(`Unexpected ForLoop phase: ${e.phase}`,l)}return{type:"Value",value:null,k:r}}(e,t,r);case"Recur":return function(e,t,r){const{nodes:n,index:o,params:a,env:i}=e;if(a.push(t),o>=n.length)return Bo(a,r,e.sourceCodeInfo);const s={...e,index:o+1};return{type:"Eval",node:n[o],env:i,k:[s,...r]}}(e,t,r);case"PerformArgs":return function(e,t,r){const{argNodes:n,index:o,params:a,env:i}=e;if(a.push(t),o>=n.length){const t=a[0];D(t,e.sourceCodeInfo);return{type:"Perform",effect:t,args:a.slice(1),k:r,sourceCodeInfo:e.sourceCodeInfo}}const s={...e,index:o+1};return{type:"Eval",node:n[o],env:i,k:[s,...r]}}(e,t,r);case"TryWith":return function(e,t){return{type:"Value",value:e,k:t}}(t,r);case"EffectResume":return function(e,t){return{type:"Value",value:t,k:e.resumeK}}(e,t);case"ParallelResume":return function(e,t,r){return{type:"ParallelResume",value:t,branchCount:e.branchCount,completedBranches:e.completedBranches,suspendedBranches:e.suspendedBranches,k:r}}(e,t,r);case"EvalArgs":return function(e,t,r){const{node:n,params:a,placeholders:i,env:s}=e,c=n[1][1],u=c[e.index];if(Fr(u)){if(!Array.isArray(t))throw new o(`Spread operator requires an array, got ${y(t)}`,u[2]);a.push(...t)}else a.push(t);let m=e.index+1;for(;m<c.length;){const e=c[m];if(e[0]!==l.ReservedSymbol||"_"!==e[1])break;i.push(a.length),m++}if(m>=c.length)return Co({...e,index:m},r);const p={...e,index:m},d=c[m];if(Fr(d))return{type:"Eval",node:d[1],env:s,k:[p,...r]};return{type:"Eval",node:d,env:s,k:[p,...r]}}(e,t,r);case"CallFn":return function(e,t,r){const n=U(t,e.sourceCodeInfo);return Io(n,e.params,e.placeholders,e.env,e.sourceCodeInfo,r)}(e,t,r);case"FnBody":return function(e,t,r){const{fn:n,bodyIndex:o,env:a}=e,i=n.evaluatedfunction[1];if(o>=i.length)return{type:"Value",value:t,k:r};const s={...e,bodyIndex:o+1};return{type:"Eval",node:i[o],env:a,k:[s,...r]}}(e,t,r);case"BindingDefault":return function(e,t,r){const{target:n,record:a,env:i,sourceCodeInfo:s}=e,l=At(n,t,e=>ko(e,i));if(l instanceof Promise)throw new o("Async binding default evaluation not supported in trampoline yet",s);return Object.assign(a,l),{type:"Value",value:t,k:r}}(e,t,r);case"NanCheck":return function(e,t,r){if("number"==typeof t&&Number.isNaN(t))throw new o("Number is NaN",e.sourceCodeInfo);return{type:"Value",value:ze(t),k:r}}(e,t,r);case"DebugStep":return function(e,t,r){if("awaitValue"===e.phase){const n={expression:e.sourceCodeInfo?.code??"",value:t,location:e.sourceCodeInfo?{line:e.sourceCodeInfo.position.line,column:e.sourceCodeInfo.position.column}:{line:0,column:0},env:Xo(e.env)},o={type:"DebugStep",phase:"awaitPerform",sourceCodeInfo:e.sourceCodeInfo,env:e.env};return{type:"Perform",effect:oo("dvala.debug.step"),args:[n],k:[o,...r]}}return{type:"Value",value:t,k:r}}(e,t,r);case"ImportMerge":{const n=j(t)?t:{};for(const[t,r]of Object.entries(n)){const n=e.module.functions[t];n&&A(r)&&(n.dvalaImpl=r)}const o={};for(const[t,r]of Object.entries(n))e.module.functions[t]||(o[t]=r);const a={...e.tsFunctions,...o};return e.env.registerValueModule(e.moduleName,a),{type:"Value",value:a,k:r}}default:throw new o(`Unhandled frame type: ${e.type}`,void 0)}}function Mo(e,t){const{matchValue:r,cases:n,index:a,env:i,sourceCodeInfo:s}=e;for(let l=a;l<n.length;l++){const[a,c,u]=n[l],m=Tt(a,r,e=>ko(e,i));if(m instanceof Promise)throw new o("Async pattern matching not supported in trampoline yet",s);if(null===m)continue;if(u){const r={};for(const[e,t]of Object.entries(m))r[e]={value:t};return{type:"Eval",node:u,env:i.create(r),k:[{...e,phase:"guard",index:l,bindings:m},...t]}}const p={};for(const[e,t]of Object.entries(m))p[e]={value:t};return{type:"Eval",node:c,env:i.create(p),k:t}}return{type:"Value",value:null,k:t}}function Oo(e,t){const{nodes:r,env:n}=e;let{index:o}=e;for(;o<r.length;){const e=r[o];if(!Mr(e)||null!==n.lookUp(e))break;o++}if(o>=r.length)return{type:"Value",value:null,k:t};if(o===r.length-1)return{type:"Eval",node:r[o],env:n,k:t};const a={...e,index:o+1};return{type:"Eval",node:r[o],env:n,k:[a,...t]}}function Vo(e,t){return{type:"Value",value:e.returnResult?e.result:null,k:t}}function Do(e,t){const{bindingNodes:r,env:n,sourceCodeInfo:o,context:a}=e,i=[...e.levelStates],s=e.bindingLevel,l=i[s],c=l.index+1;if(c>=l.collection.length)return 0===s?Vo(e,t):Do({...e,bindingLevel:s-1},t);i[s]={...l,index:c};const u=r[s];return ft(At(u[0][1][0],$(l.collection[c],o),e=>ko(e,n)),r=>{Object.entries(r).forEach(([e,t])=>{a[e]={value:t}});const n=u[1];return n.length>0?Uo({...e,levelStates:i,bindingLevel:s},i,n,0,t):Fo({...e,levelStates:i,bindingLevel:s},i,t)})}function Uo(e,t,r,n,o){const{env:a,context:i}=e;let s;for(let e=n;e<r.length;e++){const t=e;s=ft(s,()=>{const e=r[t],[n,o]=e[1];return ft(ko(o,a),e=>ft(At(n,e,e=>ko(e,a)),e=>{Object.entries(e).forEach(([e,t])=>{i[e]={value:t}})}))})}return ft(s,()=>Fo({...e,levelStates:t},t,o))}function Fo(e,t,r){const{bindingNodes:n,env:o}=e,a=n[e.bindingLevel],i=a[2],s=a[3];if(i){return{type:"Eval",node:i,env:o,k:[{...e,levelStates:t,phase:"evalWhen"},...r]}}if(s){return{type:"Eval",node:s,env:o,k:[{...e,levelStates:t,phase:"evalWhile"},...r]}}return Wo({...e,levelStates:t},r)}function Wo(e,t){const{bindingNodes:r,body:n,env:o}=e,a=e.bindingLevel+1;if(a<r.length){return{type:"Eval",node:r[a][0][1][1],env:o,k:[{...e,phase:"evalCollection",bindingLevel:a},...t]}}const i={...e,phase:"evalBody"};return{type:"Eval",node:n,env:o.create(e.context),k:[i,...t]}}function Go(e,t,r,n,o){const a=oo("dvala.error"),i=[e.shortMessage];for(let r=0;r<t.length;r++){const n=t[r];if("TryWith"===n.type)for(const o of n.handlers)if(Lo(o,a,n.env,e.sourceCodeInfo))return _o(o,n,i,t,r,e.sourceCodeInfo)}const s=Qn("dvala.error",r);return s.length>0?Jo("dvala.error",s,i,t,n,e.sourceCodeInfo,o):null}function Bo(e,t,r){for(let n=0;n<t.length;n++){const a=t[n];if("LoopIterate"===a.type){const{bindingNodes:i,bindingContext:s,body:l,env:c}=a,u=t.slice(n+1);if(e.length!==i.length)throw new o(`recur expected ${i.length} parameters, got ${e.length}`,r);const m=wt(i,(t,r)=>ft(At(t[1][0],le(e[r]),e=>ko(e,c)),e=>{Object.entries(e).forEach(([e,t])=>{s[e]={value:t}})}));return ft(m,()=>{const e=c.getContextsRaw()[0];if(e!==s)for(const[t,r]of Object.entries(s))e[t]=r;const t={type:"LoopIterate",bindingNodes:i,bindingContext:s,body:l,env:c,sourceCodeInfo:a.sourceCodeInfo};return{type:"Eval",node:l,env:c,k:[t,...u]}})}if("FnBody"===a.type){const{fn:r,outerEnv:o}=a,i=t.slice(n+1);return Ro(r,e,o,a.sourceCodeInfo,i)}}throw new o("recur called outside of loop or function body",r)}function Lo(e,t,r,n){if(V(e.effectRef))return e.effectRef.name===t.name;if(q(e.effectRef)){const a=qo(e.effectRef,[t],r,n);if(a instanceof Promise)throw new o("Effect handler predicates must be synchronous",n);return!!a}return!1}function _o(e,t,r,n,o,a){const i=[{type:"EffectResume",resumeK:n,sourceCodeInfo:a},...n.slice(o+1)];return Io(U(ko(e.handlerNode,t.env),t.sourceCodeInfo),[r],[],t.env,a,i)}function Ko(e,t,r,n,i,s,l){if("dvala.checkpoint"===e.name&&l){const e=t[0],n={continuation:go(r),timestamp:Date.now(),index:l.nextSnapshotIndex++,runId:l.runId,...void 0!==e?{meta:e}:{}};l.snapshots.push(n),void 0!==l.maxSnapshots&&l.snapshots.length>l.maxSnapshots&&l.snapshots.shift()}for(let o=0;o<r.length;o++){const a=r[o];if("TryWith"===a.type)for(const i of a.handlers)if(Lo(i,e,a.env,n))return _o(i,a,t,r,o,n)}const c=Qn(e.name,i);if(c.length>0)return Jo(e.name,c,t,r,s,n,l);const u=function(e){const t=xo[e];if(t)return(e,r,n)=>(ee(t.arity,e.length,n),t.handler(e,r,n))}(e.name);if(u)return u(t,r,n);if("dvala.error"===e.name){const e="string"==typeof t[0]?t[0]:String(t[0]??"Unknown error");throw new a(e,n)}throw new o(`Unhandled effect: '${e.name}'`,n)}function Jo(e,t,r,n,i,s,l){const c=i??(new AbortController).signal,u=Array.from(r);function m(e,t){switch(e.kind){case"step":return e.step;case"asyncResume":return e.promise.then(e=>({type:"Value",value:e,k:n}),e=>({type:"Error",error:e instanceof o?e:new o(e instanceof Error?e:`${e}`,s),k:n}));case"throw":throw e.error;case"next":return p(t)}}function p(r){if(r>=t.length){if("dvala.error"===e){const e="string"==typeof u[0]?u[0]:String(u[0]??"Unknown error");throw new a(e,s)}throw new o(`Unhandled effect: '${e}'`,s)}const[,i]=t[r];let p,d=!1;function h(e){if(d)throw new o(`Effect handler called ${e}() after already calling another operation`,s);d=!0}const g=i({effectName:e,args:u,signal:c,resume:e=>{h("resume"),p=e instanceof Promise?{kind:"asyncResume",promise:e}:{kind:"step",step:{type:"Value",value:e,k:n}}},fail:t=>{h("fail");p={kind:"step",step:{type:"Error",error:new o(t??`Effect handler failed for '${e}'`,s),k:n}}},suspend:e=>{h("suspend"),p={kind:"throw",error:new Zn(n,l?l.snapshots:[],l?l.nextSnapshotIndex:0,e)}},next:()=>{h("next"),p={kind:"next"}},get snapshots(){return l?[...l.snapshots]:[]},checkpoint:e=>{if(!l)throw new o("checkpoint is not available outside effect-enabled execution",s);const t={continuation:go(n),timestamp:Date.now(),index:l.nextSnapshotIndex++,runId:l.runId,...void 0!==e?{meta:e}:{}};return l.snapshots.push(t),void 0!==l.maxSnapshots&&l.snapshots.length>l.maxSnapshots&&l.snapshots.shift(),t},resumeFrom:(e,t)=>{if(d)throw new o("Effect handler called resumeFrom() after already calling another operation",s);if(!l)throw new o("resumeFrom is not available outside effect-enabled execution",s);const r=l.snapshots.find(t=>t.index===e.index&&t.runId===e.runId);if(!r)throw new o(`Invalid snapshot: no snapshot with index ${e.index} found in current run`,s);d=!0,p={kind:"throw",error:new to(r.continuation,t,r.index)}}});if(!(g instanceof Promise)){if(!p)throw new o(`Effect handler for '${e}' did not call resume(), fail(), suspend(), or next()`,s);return m(p,r+1)}return p?(g.catch(()=>{}),m(p,r+1)):g.then(()=>{if(!p)throw new o(`Effect handler for '${e}' did not call resume(), fail(), suspend(), or next()`,s);return m(p,r+1)},e=>{if(p)return m(p,r+1);if(eo(e)||ro(e))throw e;return{type:"Error",error:e instanceof o?e:new o(e instanceof Error?e:`${e}`,s),k:n}})}return p(0)}function Ho(e,t){throw new Zn(e,[],0,t)}async function Yo(e,t,r,n){return aa({type:"Eval",node:e,env:t,k:[]},r,n)}function Xo(e){const t={},r=e.getHostValues();if(r)for(const[e,n]of Object.entries(r))t[e]=n;const n=e.getContextsRaw();for(let e=n.length-1;e>=0;e--)for(const[r,o]of Object.entries(n[e]))t[r]=o.value;return t}function Qo(e,t){return e instanceof Promise?e.then(e=>({type:"Value",value:e,k:t}),e=>({type:"Error",error:e instanceof o?e:new o(`${e}`,void 0),k:t})):{type:"Value",value:e,k:t}}function Zo(e,t,r,n){try{switch(e.type){case"Value":{if(0===e.k.length)return e;const[t,...r]=e.k;return Po(t,e.value,r)}case"Eval":return jo(e.node,e.env,e.k);case"Apply":return Po(e.frame,e.value,e.k);case"Perform":return Ko(e.effect,e.args,e.k,e.sourceCodeInfo,t,r,n);case"Parallel":return async function(e,t,r,n,a){const i=a??(new AbortController).signal,s=e.map(e=>Yo(e,t,n,i)),l=await Promise.allSettled(s),c=[],u=[],m=[];for(let e=0;e<l.length;e++){const t=l[e];if("rejected"===t.status)m.push(new o(`${t.reason}`,void 0));else{const r=t.value;switch(r.type){case"completed":c.push({index:e,value:r.value});break;case"suspended":u.push({index:e,snapshot:r.snapshot});break;case"error":m.push(r.error)}}}if(m.length>0)throw m[0];if(u.length>0)return Ho([{type:"ParallelResume",branchCount:e.length,completedBranches:c,suspendedBranches:u.slice(1)},...r],u[0].snapshot.meta);const p=Array.from({length:e.length});for(const{index:e,value:t}of c)p[e]=t;return{type:"Value",value:p,k:r}}(e.branches,e.env,e.k,t,r);case"Race":return async function(e,t,r,n,a){const i=a??(new AbortController).signal,s=e.map(()=>new AbortController),l=()=>{for(const e of s)e.abort(i.reason)};i.addEventListener("abort",l,{once:!0});try{let a=-1,i=null;const l=e.map(async(e,r)=>{const o=s[r].signal,l=await Yo(e,t,n,o);if("completed"===l.type&&a<0){a=r,i=l.value;for(let e=0;e<s.length;e++)e!==r&&s[e].abort("race: branch lost")}return l}),c=await Promise.allSettled(l);if(a>=0)return{type:"Value",value:i,k:r};const u=[],m=[];for(let e=0;e<c.length;e++){const t=c[e];if("rejected"===t.status)m.push(new o(`${t.reason}`,void 0));else{const e=t.value;switch(e.type){case"suspended":u.push(e.snapshot.meta??null);break;case"error":m.push(e.error)}}}u.length>0&&Ho(r,{type:"race",branches:u});const p=m.map(e=>e.message).join("; ");throw new o(`race: all branches failed: ${p}`,void 0)}finally{i.removeEventListener("abort",l)}}(e.branches,e.env,e.k,t,r);case"ParallelResume":return function(e){const{value:t,branchCount:r,completedBranches:n,suspendedBranches:o,k:a}=e,i=new Set(n.map(e=>e.index)),s=new Set(o.map(e=>e.index));let l=-1;for(let e=0;e<r;e++)if(!i.has(e)&&!s.has(e)){l=e;break}const c=[...n,{index:l,value:t}];if(o.length>0){const e=o[0];return Ho([{type:"ParallelResume",branchCount:r,completedBranches:c,suspendedBranches:o.slice(1)},...a],e.snapshot.meta)}const u=Array.from({length:r});for(const{index:e,value:t}of c)u[e]=t;return{type:"Value",value:u,k:a}}(e);case"Error":{const o=Go(e.error,e.k,t,r,n);if(null!==o)return o;throw e.error}}}catch(a){if(eo(a))throw a;if(a instanceof o){const o=Go(a,"Value"===e.type?e.k.slice(1):e.k,t,r,n);if(null!==o)return o}throw a}}function ea(e,t){let r=e;for(;;){if(r instanceof Promise)throw new o("Unexpected async operation in synchronous context. Use async.run() for async operations.",void 0);if("Value"===r.type&&0===r.k.length)return r.value;r=Zo(r,t)}}async function ta(e){let t=e;for(;;){if(t instanceof Promise&&(t=await t),"Value"===t.type&&0===t.k.length)return t.value;t=Zo(t)}}function ra(e,t){if(0===e.length)return{type:"Value",value:null,k:[]};if(1===e.length)return{type:"Eval",node:e[0],env:t,k:[]};const r={type:"Sequence",nodes:e,index:1,env:t};return{type:"Eval",node:e[0],env:t,k:[r]}}function na(e,t){const r=ra(e.body,t);try{return ea(r)}catch(r){if(r instanceof o&&r.message.includes("Unexpected async operation")){return ta(ra(e.body,t))}throw r}}function oa(e,t){const r={type:"Eval",node:e,env:t,k:[]};try{return ea(r)}catch(r){if(r instanceof o&&r.message.includes("Unexpected async operation")){return ta({type:"Eval",node:e,env:t,k:[]})}throw r}}async function aa(e,t,r,n,a,i){const s=null!=t&&"dvala.debug.step"in t,c={snapshots:[],nextSnapshotIndex:0,runId:"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),...void 0!==a?{maxSnapshots:a}:{}};let u=e;for(;;)try{for(;;){if(u instanceof Promise&&(u=await u),"Value"===u.type&&0===u.k.length)return{type:"completed",value:u.value};if(s&&"Eval"===u.type&&u.node[2]){const e=u.node[0];if(e===l.NormalExpression||e===l.SpecialExpression){const e={type:"DebugStep",phase:"awaitValue",sourceCodeInfo:u.node[2],env:u.env};u={...u,k:[e,...u.k]}}}u=Zo(u,t,r,c)}}catch(e){if(ro(e)){const{k:t}=yo(e.continuation,i),r=c.snapshots.findIndex(t=>t.index>e.trimToIndex);-1!==r&&c.snapshots.splice(r),u={type:"Value",value:e.value,k:t};continue}if(eo(e)){return{type:"suspended",snapshot:{continuation:fo(e.k,e.snapshots,e.nextSnapshotIndex,e.meta),timestamp:Date.now(),index:c.nextSnapshotIndex++,runId:c.runId,meta:e.meta}}}return e instanceof o?{type:"error",error:e}:{type:"error",error:new o(`${e}`,void 0)}}}new Set(Object.keys(xo));const ia={collection:'{\n map: (first-coll, ...args) -> do\n let fn = last(args);\n let other-colls = slice(args, 0, count(args) - 1);\n let all-colls = [first-coll, ...other-colls];\n\n cond\n case object?(first-coll) then do\n let expected-keys = keys(first-coll) |> sort;\n doseq (obj in other-colls) -> do\n if not(object?(obj)) then\n perform(effect(dvala.error), "Expected object")\n end;\n let obj-keys = keys(obj) |> sort;\n if not(obj-keys == expected-keys) then\n perform(effect(dvala.error), ++(\n "All objects must have the same keys. Expected: ",\n join(expected-keys, ", "),\n ". Found: ",\n join(obj-keys, ", ")\n ))\n end\n end;\n reduce(keys(first-coll), (acc, k) -> do\n let a = for (coll in all-colls) -> coll(k);\n assoc(acc, k, apply(fn, a))\n end, {})\n end\n\n case string?(first-coll) then do\n doseq (s in other-colls) -> do\n if not(string?(s)) then\n perform(effect(dvala.error), "Expected string")\n end\n end;\n let len = reduce(other-colls, (m, s) -> min(m, count(s)), count(first-coll));\n let mapped = for (i in range(len)) -> do\n let a = for (coll in all-colls) -> nth(coll, i);\n apply(fn, a)\n end;\n reduce(mapped, (acc, ch) -> do\n if not(string?(ch)) then\n perform(effect(dvala.error), "Expected string")\n end;\n ++(acc, ch)\n end, "")\n end\n\n case true then do\n doseq (x in other-colls) -> do\n if not(array?(x)) then\n perform(effect(dvala.error), "Expected array")\n end\n end;\n let len = reduce(other-colls, (m, x) -> min(m, count(x)), count(first-coll));\n for (i in range(len)) -> do\n let a = for (coll in all-colls) -> nth(coll, i);\n apply(fn, a)\n end\n end\n end\n end,\n\n filter: (coll, fn) -> do\n cond\n case array?(coll) then\n reduce(coll, (acc, elem) -> if fn(elem) then [...acc, elem] else acc end, [])\n\n case string?(coll) then\n reduce(coll, (acc, ch) -> if fn(ch) then ++(acc, ch) else acc end, "")\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) -> do\n if fn(coll(k)) then\n assoc(acc, k, coll(k))\n else\n acc\n end\n end, {})\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reduce: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i)), i + 1)\n end\n end\n\n case array?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i)), i + 1)\n end\n end\n\n case object?(coll) then do\n let values = vals(coll);\n loop (acc = initial, i = 0) -> do\n if i >= count(values) then\n acc\n else\n recur(fn(acc, nth(values, i)), i + 1)\n end\n end\n end\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end\n}',sequence:'{\n some: (seq, fn) -> do\n if null?(seq) then null\n else do\n loop (i = 0) -> do\n if i >= count(seq) then\n null\n else do\n let elem = nth(seq, i);\n if fn(elem) then elem\n else recur(i + 1)\n end\n end\n end\n end\n end\n end\n end,\n\n take-while: (seq, fn) -> do\n let is-str = string?(seq);\n let len = count(seq);\n let idx = loop (i = 0) -> do\n if i >= len then\n len\n else if fn(nth(seq, i)) then\n recur(i + 1)\n else\n i\n end\n end\n end;\n slice(seq, 0, idx)\n end,\n\n drop-while: (seq, fn) -> do\n let is-str = string?(seq);\n let len = count(seq);\n let idx = loop (i = 0) -> do\n if i >= len then\n len\n else if fn(nth(seq, i)) then\n recur(i + 1)\n else\n i\n end\n end\n end;\n slice(seq, idx)\n end,\n\n sort: (seq, ...args) -> do\n let cmp = if count(args) == 0 then compare else first(args) end;\n let is-str = string?(seq);\n let arr = if is-str then split(seq, "") else seq end;\n let len = count(arr);\n\n // merge two sorted arrays\n let merge-arrays = (left, right) -> do\n let left-len = count(left);\n let right-len = count(right);\n loop (result = [], li = 0, ri = 0) -> do\n if li >= left-len then\n ++(result, slice(right, ri))\n else if ri >= right-len then\n ++(result, slice(left, li))\n else do\n let l = nth(left, li);\n let r = nth(right, ri);\n if cmp(l, r) <= 0 then\n recur(push(result, l), li + 1, ri)\n else\n recur(push(result, r), li, ri + 1)\n end\n end\n end\n end\n end\n end;\n\n // recursive merge-sort\n let merge-sort = (a) -> do\n let n = count(a);\n if n <= 1 then a\n else do\n let mid = floor(n / 2);\n let left = merge-sort(slice(a, 0, mid));\n let right = merge-sort(slice(a, mid));\n merge-arrays(left, right)\n end\n end\n end;\n\n let sorted = merge-sort(arr);\n if is-str then join(sorted, "") else sorted end\n end\n}\n',array:'{\n mapcat: (arr, fn) -> do\n flatten(map(arr, fn), 1)\n end,\n\n moving-fn: (arr, window-size, fn) -> do\n if window-size > count(arr) then\n perform(effect(dvala.error), "Expected window-size <= array length")\n end;\n for (i in range(count(arr) - window-size + 1)) -> do\n fn(slice(arr, i, i + window-size))\n end\n end,\n\n running-fn: (arr, fn) -> do\n for (i in range(count(arr))) -> do\n fn(slice(arr, 0, i + 1))\n end\n end\n}\n',functional:'{\n "|>": (a, b) -> b(a),\n\n apply: (fn, ...args) -> do\n let arr = last(args);\n let leading = slice(args, 0, count(args) - 1);\n fn(...leading, ...arr)\n end\n}\n',object:'{\n merge-with: (...args) -> do\n let fn = last(args);\n let objs = slice(args, 0, count(args) - 1);\n if not(function?(fn)) then\n perform(effect(dvala.error), str("Expected function, got: ", type(fn)))\n end;\n if count(objs) == 0 then\n perform(effect(dvala.error), "Expected at least one object argument")\n end;\n reduce(rest(objs), (result, obj) -> do\n if not(object?(obj)) then\n perform(effect(dvala.error), str("Expected object, got: ", type(obj)))\n end;\n reduce(keys(obj), (res, key) -> do\n if contains?(res, key) then\n assoc(res, key, fn(get(res, key), get(obj, key)))\n else\n assoc(res, key, get(obj, key))\n end\n end, result)\n end, do\n let f = first(objs);\n if not(object?(f)) then\n perform(effect(dvala.error), str("Expected object, got: ", type(f)))\n end;\n f\n end)\n end\n}\n'};let sa=!1;class la{cache={};firstEntry=void 0;lastEntry=void 0;_size=0;maxSize;constructor(e){if(this.maxSize=null===e?null:se(e),"number"==typeof this.maxSize&&this.maxSize<1)throw new Error(`1 is the minimum maxSize, got ${y(e)}`)}getContent(){return Object.entries(this.cache).reduce((e,[t,r])=>(e[t]=r.value,e),{})}get size(){return this._size}get(e){return this.cache[e]?.value}clear(){this.cache={},this.firstEntry=void 0,this.lastEntry=void 0,this._size=0}has(e){return!!this.cache[e]}set(e,t){if(this.has(e))throw new Error(`AstCache - key already present: ${e}`);const r={value:t,nextEntry:void 0,key:e};for(this.cache[e]=r,this._size+=1,this.lastEntry&&(this.lastEntry.nextEntry=r),this.lastEntry=r,this.firstEntry||(this.firstEntry=this.lastEntry);null!==this.maxSize&&this.size>this.maxSize;)this.dropFirstEntry()}dropFirstEntry(){const e=this.firstEntry;delete this.cache[e.key],this._size-=1,this.firstEntry=e.nextEntry}}function ca(e){return"object"==typeof e&&null!==e&&"string"==typeof e.program&&Array.isArray(e.fileModules)}function ua(e){if(e)for(const[t,r]of Object.entries(e))ma(r,`bindings["${t}"]`)}function ma(e,t){if(null!=e&&"boolean"!=typeof e&&"string"!=typeof e)if("number"!=typeof e){if("function"==typeof e)throw new TypeError(`${t} is not serializable (function)`);if("object"!=typeof e)throw new TypeError(`${t} is not serializable`);if(p in e||d in e||h in e)return;if(Array.isArray(e))return void e.forEach((e,r)=>ma(e,`${t}[${r}]`));if(Object.getPrototypeOf(e)!==Object.prototype)throw new TypeError(`${t} is not serializable (not a plain object)`);for(const[r,n]of Object.entries(e))ma(n,`${t}.${r}`)}else if(!Number.isFinite(e))throw new TypeError(`${t} is not serializable (${e})`)}function pa(e){!function(){if(!sa){sa=!0;for(const[,e]of Object.entries(ia)){const t=na({body:Hn(Yn(jr(e,!1,void 0),{removeWhiteSpace:!0})),hasDebugData:!1},Lr());if(t instanceof Promise)throw new TypeError("Core dvala sources must be synchronous");if(!j(t))continue;const r=t;for(const[e,t]of Object.entries(r)){const r=at[e];r&&q(t)&&"UserDefined"===t.functionType&&(r.dvalaImpl=t)}}}}();const t=e?.modules?new Map(e.modules.map(e=>[e.name,e])):void 0,r=e?.bindings,n=e?.effectHandlers,a=e?.debug??!1,i=e?.cache?new la(e.cache):null;function s(e,t){if(!t&&i){const t=i.get(e);if(t)return t}const r={body:Hn(Yn(jr(e,a,t),{removeWhiteSpace:!0})),hasDebugData:a};return t||i?.set(e,r),r}function l(e){if(r||e)return{...r,...e}}function c(e){if(!n&&!e)return;const t={...e};if(n)for(const[e,r]of Object.entries(n))e in t||(t[e]=r);return t}function u(e,t){if(!e)return;if(t&&Object.keys(t).length>0)throw new TypeError("Cannot use pure mode with effect handlers")}return{run(e,r){ua(r?.bindings);const n=l(r?.bindings),a=c(r?.effectHandlers),i=r?.pure??!1;u(i,a);const m=Lr({bindings:n},t,i);if(ca(e)){const t=m.pure;m.pure=!0;for(const[t,r]of e.fileModules){const e=s(r),n=m.create({});m.registerValueModule(t,na(e,n))}m.pure=t;const r=na(s(e.program),m);if(r instanceof Promise)throw new TypeError("Unexpected async result in run(). Use runAsync() for async operations.");return r}const p=s(e,r?.filePath);if(a)return function(e,t,r){const n=ra(e.body,t);try{return ea(n,r)}catch(n){if(n instanceof o&&n.message.includes("Unexpected async operation"))return ea(ra(e.body,t),r);throw n}}(p,m,a);const d=na(p,m);if(d instanceof Promise)throw new TypeError("Unexpected async result in run(). Use runAsync() for async operations.");return d},async runAsync(e,r){ua(r?.bindings);const n=l(r?.bindings),a=c(r?.effectHandlers),i=r?.pure??!1;u(i,a);try{const o=Lr({bindings:n},t,i);if(ca(e)){const t=o.pure;o.pure=!0;for(const[t,r]of e.fileModules){const e=s(r),n=o.create({});o.registerValueModule(t,na(e,n))}o.pure=t}const l=s(ca(e)?e.program:e),c=await async function(e,t,r,n,o){const a=(new AbortController).signal;return aa(ra(e.body,t),r,a,0,n,o)}(l,o,a,r?.maxSnapshots,{values:n,modules:t});return"completed"===c.type?{...c,definedBindings:o.getModuleScopeBindings()}:c}catch(e){if(e instanceof o)return{type:"error",error:e};if(e instanceof TypeError)throw e;return{type:"error",error:new o(`${e}`,void 0)}}},getUndefinedSymbols(e){const n=t?[...t.values()]:void 0;return function(e,t){const r=t?.modules?new Map(t.modules.map(e=>[e.name,e])):void 0,n=Lr({bindings:t?.bindings},r),o={body:Hn(Yn(jr(e,!1,void 0),{removeWhiteSpace:!0})),hasDebugData:!1};return _r(o,n,rr,oa)}(e,{bindings:r,modules:n})},getAutoCompleter:(e,t)=>new Pr(e,t,{bindings:r})}}const da={"assert!=":{category:"assertion",description:"If $a is the same as $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert!= } = import(assertion);\ndo assert!=(0, 0, "Expected different values") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert!= } = import(assertion);\ndo assert!=(0, 0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert!= } = import(assertion);\ndo 0 assert!= 0 with case effect(dvala.error) then ([msg]) -> msg end","let { assert!= } = import(assertion);\ndo assert!=(0, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert="],hideOperatorForm:!0},"assert=":{category:"assertion",description:"If $a is not structural equal to $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert= } = import(assertion);\ndo assert=({ "a": 1 }, { "a": 2 }, "Expected equal values") with case effect(dvala.error) then ([msg]) -> msg end','let { assert= } = import(assertion);\ndo assert=({ "a": 1 }, { "a": 2 }) with case effect(dvala.error) then ([msg]) -> msg end','let { assert= } = import(assertion);\ndo assert=({ "a": 1 }, { "a": 1 }) with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert!="],hideOperatorForm:!0},"assert-gt":{category:"assertion",description:"If $a is not greater than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-gt } = import(assertion);\ndo assert-gt(0, 1, "Expected greater value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-gt } = import(assertion);\ndo assert-gt(0, 0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-gt } = import(assertion);\ndo assert-gt(1, 0) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-lt","assertion.assert-gte","assertion.assert-lte"],hideOperatorForm:!0},"assert-lt":{category:"assertion",description:"If $a is not less than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-lt } = import(assertion);\ndo assert-lt(1, 0, "Expected smaller value value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-lt } = import(assertion);\ndo assert-lt(1, 1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-lt } = import(assertion);\ndo assert-lt(0, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-gt","assertion.assert-lte","assertion.assert-gte"],hideOperatorForm:!0},"assert-gte":{category:"assertion",description:"If $a is less than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-gte } = import(assertion);\ndo assert-gte(0, 1, "Expected greater value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-gte } = import(assertion);\ndo assert-gte(0, 1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-gte } = import(assertion);\ndo assert-gte(1, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-lte","assertion.assert-gt","assertion.assert-lt"],hideOperatorForm:!0},"assert-lte":{category:"assertion",description:"If $a is grater than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-lte } = import(assertion);\ndo assert-lte(1, 0, "Expected smaller value value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-lte } = import(assertion);\ndo assert-lte(1, 0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-lte } = import(assertion);\ndo assert-lte(1, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-gte","assertion.assert-lt","assertion.assert-gt"],hideOperatorForm:!0},"assert-true":{category:"assertion",description:"If $value is not `true` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-true } = import(assertion);\ndo assert-true(false, "Expected true") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-true } = import(assertion);\ndo assert-true(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-true } = import(assertion);\ndo assert-true(true) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-false","assertion.assert-truthy","assertion.assert-falsy","assert","assertion.assert-boolean"],hideOperatorForm:!0},"assert-false":{category:"assertion",description:"If $value is not `false` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-false } = import(assertion);\ndo assert-false(true, "Expected false") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-false } = import(assertion);\ndo assert-false(true) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-false } = import(assertion);\ndo assert-false(false) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-true","assertion.assert-falsy","assertion.assert-truthy","assertion.assert-boolean"],hideOperatorForm:!0},"assert-truthy":{category:"assertion",description:"If $value is not `truthy` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-truthy } = import(assertion);\ndo assert-truthy(false, "Expected truthy") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-truthy } = import(assertion);\ndo assert-truthy(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(null) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-truthy } = import(assertion);\ndo assert-truthy("") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-truthy } = import(assertion);\ndo assert-truthy(true) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(1) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-truthy } = import(assertion);\ndo assert-truthy("x") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-truthy } = import(assertion);\ndo assert-truthy([]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(nd) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-falsy","assertion.assert-true","assertion.assert-false","assert","assertion.assert-null"],hideOperatorForm:!0},"assert-falsy":{category:"assertion",description:"If $value is not `falsy` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-falsy } = import(assertion);\ndo assert-falsy(true, "Expected falsy") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-falsy } = import(assertion);\ndo assert-falsy("x") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-falsy } = import(assertion);\ndo assert-falsy([]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(nd) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(null) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-falsy } = import(assertion);\ndo assert-falsy("") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-truthy","assertion.assert-false","assertion.assert-true","assertion.assert-null"],hideOperatorForm:!0},"assert-null":{category:"assertion",description:"If $value is not `null` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-null } = import(assertion);\ndo assert-null(null) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-null } = import(assertion);\ndo assert-null(true, "Expected null") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-null } = import(assertion);\ndo assert-null("x") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-null } = import(assertion);\ndo assert-null([]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(nd) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(0) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-null } = import(assertion);\ndo assert-null("") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-truthy","assertion.assert-falsy"],hideOperatorForm:!0},"assert-throws":{category:"assertion",description:"If $fun does not throw, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},message:{type:"string"}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","message"]}],examples:['let { assert-throws } = import(assertion);\nassert-throws(-> perform(effect(dvala.error), "Error"))','let { assert-throws } = import(assertion);\ndo assert-throws(-> identity("Error")) with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-throws-error","assertion.assert-not-throws"],hideOperatorForm:!0},"assert-throws-error":{category:"assertion",description:"If $fun does not throw $error-message, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},"error-message":{type:"string"},message:{type:"string"}},variants:[{argumentNames:["fun","error-message"]},{argumentNames:["fun","error-message","message"]}],examples:['let { assert-throws-error } = import(assertion);\ndo assert-throws-error(-> perform(effect(dvala.error), "Error"), "Error") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-throws-error } = import(assertion);\ndo assert-throws-error(-> identity("Error"), "Error") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-throws","assertion.assert-not-throws"],hideOperatorForm:!0},"assert-not-throws":{category:"assertion",description:"If $fun throws, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},message:{type:"string"}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","message"]}],examples:['let { assert-not-throws } = import(assertion);\ndo assert-not-throws(-> identity("Error")) with case effect(dvala.error) then ([msg]) -> msg end','let { assert-not-throws } = import(assertion);\ndo assert-not-throws(-> perform(effect(dvala.error), "Error")) with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-throws","assertion.assert-throws-error"],hideOperatorForm:!0},"assert-array":{category:"assertion",description:"If $value is not an `array` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-array } = import(assertion);\ndo assert-array([1, 2, 3]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-array } = import(assertion);\ndo assert-array("string") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-array } = import(assertion);\ndo assert-array(42, "Expected an array") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-object","assertion.assert-collection","assertion.assert-sequence"],hideOperatorForm:!0},"assert-boolean":{category:"assertion",description:"If $value is not a `boolean` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-boolean } = import(assertion);\ndo assert-boolean(true) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-boolean } = import(assertion);\ndo assert-boolean(false) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-boolean } = import(assertion);\ndo assert-boolean(1, "Expected a boolean") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-true","assertion.assert-false","assertion.assert-number","assertion.assert-string"],hideOperatorForm:!0},"assert-collection":{category:"assertion",description:"If $value is not a `collection` (array, object, or string) it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-collection } = import(assertion);\ndo assert-collection([1, 2]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-collection } = import(assertion);\ndo assert-collection({ a: 1 }) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-collection } = import(assertion);\ndo assert-collection("hello") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-collection } = import(assertion);\ndo assert-collection(42, "Expected a collection") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-sequence","assertion.assert-array","assertion.assert-object"],hideOperatorForm:!0},"assert-function":{category:"assertion",description:"If $value is not a `function` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-function } = import(assertion);\ndo assert-function(-> $ + 1) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-function } = import(assertion);\ndo assert-function(42, "Expected a function") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-number","assertion.assert-string"],hideOperatorForm:!0},"assert-grid":{category:"assertion",description:"If $value is not a `grid` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-grid } = import(assertion);\ndo assert-grid([[1, 2], [3, 4]]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-grid } = import(assertion);\ndo assert-grid([1, 2], "Expected a grid") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-matrix","assertion.assert-vector"],hideOperatorForm:!0},"assert-integer":{category:"assertion",description:"If $value is not an `integer` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-integer } = import(assertion);\ndo assert-integer(42) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-integer } = import(assertion);\ndo assert-integer(3.14, "Expected an integer") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-number"],hideOperatorForm:!0},"assert-matrix":{category:"assertion",description:"If $value is not a `matrix` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-matrix } = import(assertion);\ndo assert-matrix([[1, 2], [3, 4]]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-matrix } = import(assertion);\ndo assert-matrix([1, 2], "Expected a matrix") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-vector","assertion.assert-grid"],hideOperatorForm:!0},"assert-number":{category:"assertion",description:"If $value is not a `number` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-number } = import(assertion);\ndo assert-number(42) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-number } = import(assertion);\ndo assert-number("hello", "Expected a number") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-integer","assertion.assert-boolean","assertion.assert-string","assertion.assert-function"],hideOperatorForm:!0},"assert-object":{category:"assertion",description:"If $value is not an `object` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-object } = import(assertion);\ndo assert-object({ a: 1 }) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-object } = import(assertion);\ndo assert-object([1, 2], "Expected an object") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-array","assertion.assert-collection"],hideOperatorForm:!0},"assert-regexp":{category:"assertion",description:"If $value is not a `regexp` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-regexp } = import(assertion);\ndo assert-regexp(#"^start") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-regexp } = import(assertion);\ndo assert-regexp("hello", "Expected a regexp") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-string"],hideOperatorForm:!0},"assert-sequence":{category:"assertion",description:"If $value is not a `sequence` (array or string) it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-sequence } = import(assertion);\ndo assert-sequence([1, 2]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-sequence } = import(assertion);\ndo assert-sequence("hello") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-sequence } = import(assertion);\ndo assert-sequence({ a: 1 }, "Expected a sequence") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-collection","assertion.assert-array"],hideOperatorForm:!0},"assert-string":{category:"assertion",description:"If $value is not a `string` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-string } = import(assertion);\ndo assert-string("hello") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-string } = import(assertion);\ndo assert-string(42, "Expected a string") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-number","assertion.assert-boolean","assertion.assert-regexp","assertion.assert-function"],hideOperatorForm:!0},"assert-vector":{category:"assertion",description:"If $value is not a `vector` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-vector } = import(assertion);\ndo assert-vector([1, 2, 3]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-vector } = import(assertion);\ndo assert-vector(["a", "b"], "Expected a vector") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-matrix","assertion.assert-grid"],hideOperatorForm:!0}},ha={"assert=":{evaluate:([e,t,r],n)=>{if(void 0!==r&&(G(r,n),r=` ${r}`),r??="",!ie($(e,n),$(t,n),n))throw new i(`Expected ${JSON.stringify(e,null,2)} to deep equal ${JSON.stringify(t,null,2)}.${r}`,n);return null},arity:{min:2,max:3}},"assert!=":{evaluate:([e,t,r],n)=>{if(void 0!==r&&(G(r,n),r=` ${r}`),r??="",ie($(e,n),$(t,n),n))throw new i(`Expected ${JSON.stringify(e)} not to deep equal ${JSON.stringify(t)}.${r}`,n);return null},arity:{min:2,max:3}},"assert-gt":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)<=0)throw new i(`Expected ${e} to be grater than ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-gte":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)<0)throw new i(`Expected ${e} to be grater than or equal to ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-lt":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)>=0)throw new i(`Expected ${e} to be less than ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-lte":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)>0)throw new i(`Expected ${e} to be less than or equal to ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-true":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!0!==e)throw new i(`Expected ${e} to be true.${t}`,r);return null},arity:{min:1,max:2}},"assert-false":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!1!==e)throw new i(`Expected ${e} to be false.${t}`,r);return null},arity:{min:1,max:2}},"assert-truthy":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!e)throw new i(`Expected ${e} to be truthy.${t}`,r);return null},arity:{min:1,max:2}},"assert-falsy":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",e)throw new i(`Expected ${e} to be falsy.${t}`,r);return null},arity:{min:1,max:2}},"assert-null":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",null!==e)throw new i(`Expected ${e} to be null.${t}`,r);return null},arity:{min:1,max:2}},"assert-throws":{evaluate:([e,t],r,n,{executeFunction:o})=>(void 0!==t&&(G(t,r),t=` ${t}`),t??="",F(e,r),kt(()=>ft(o(e,[],n,r),()=>{throw new i(`Expected function to throw.${t}`,r)}),()=>null)),arity:{min:1,max:2}},"assert-throws-error":{evaluate:([e,t,r],n,o,{executeFunction:a})=>(void 0!==r&&(G(r,n),r=` ${r}`),r??="",G(t,n),F(e,n),kt(()=>ft(a(e,[],o,n),()=>{throw new i(`Expected function to throw "${t}".${r}`,n)}),e=>{const o=e.shortMessage;if(o!==t)throw new i(`Expected function to throw "${t}", but thrown "${o}".${r}`,n);return null})),arity:{min:2,max:3}},"assert-not-throws":{evaluate:([e,t],r,n,{executeFunction:o})=>(void 0!==t&&(G(t,r),t=` ${t}`),t??="",F(e,r),kt(()=>ft(o(e,[],n,r),()=>null),()=>{throw new i(`Expected function not to throw.${t}`,r)})),arity:{min:1,max:2}},"assert-array":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!Array.isArray(e))throw new i(`Expected ${JSON.stringify(e)} to be an array.${t}`,r);return null},arity:{min:1,max:2}},"assert-boolean":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","boolean"!=typeof e)throw new i(`Expected ${JSON.stringify(e)} to be a boolean.${t}`,r);return null},arity:{min:1,max:2}},"assert-collection":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!I(e))throw new i(`Expected ${JSON.stringify(e)} to be a collection.${t}`,r);return null},arity:{min:1,max:2}},"assert-function":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!q(e))throw new i(`Expected ${JSON.stringify(e)} to be a function.${t}`,r);return null},arity:{min:1,max:2}},"assert-grid":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!Me(e))throw new i(`Expected ${JSON.stringify(e)} to be a grid.${t}`,r);return null},arity:{min:1,max:2}},"assert-integer":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","number"!=typeof e||!H(e,{integer:!0}))throw new i(`Expected ${JSON.stringify(e)} to be an integer.${t}`,r);return null},arity:{min:1,max:2}},"assert-matrix":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!Ve(e))throw new i(`Expected ${JSON.stringify(e)} to be a matrix.${t}`,r);return null},arity:{min:1,max:2}},"assert-number":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","number"!=typeof e)throw new i(`Expected ${JSON.stringify(e)} to be a number.${t}`,r);return null},arity:{min:1,max:2}},"assert-object":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!j(e))throw new i(`Expected ${JSON.stringify(e)} to be an object.${t}`,r);return null},arity:{min:1,max:2}},"assert-regexp":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!M(e))throw new i(`Expected ${JSON.stringify(e)} to be a regexp.${t}`,r);return null},arity:{min:1,max:2}},"assert-sequence":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!T(e))throw new i(`Expected ${JSON.stringify(e)} to be a sequence.${t}`,r);return null},arity:{min:1,max:2}},"assert-string":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","string"!=typeof e)throw new i(`Expected ${JSON.stringify(e)} to be a string.${t}`,r);return null},arity:{min:1,max:2}},"assert-vector":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!je(e))throw new i(`Expected ${JSON.stringify(e)} to be a vector.${t}`,r);return null},arity:{min:1,max:2}}};for(const[e,t]of Object.entries(da))ha[e]&&(ha[e].docs=t);const ga={name:"assertion",functions:ha,source:"{}",docs:da};const fa={"cell-every?":{category:"grid",description:"Checks if all elements in a grid satisfy a predicate. Returns true only if the predicate returns true for every element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-every? } = import(grid);\ncell-every?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { cell-every? } = import(grid);\ncell-every?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)',"let { cell-every? } = import(grid);\ncell-every?([\n [1, 2],\n [3, 4],\n], string?)"],seeAlso:["collection.every?","grid.some?","grid.every-row?","grid.every-col?"]},"some?":{category:"grid",description:"Checks if any element in a grid satisfies a predicate. Returns true if the predicate returns true for at least one element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some? } = import(grid);\nsome?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { some? } = import(grid);\nsome?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)',"let { some? } = import(grid);\nsome?([\n [1, 2],\n [3, 4],\n], string?)"],seeAlso:["collection.any?","grid.cell-every?","grid.some-row?","grid.some-col?"]},"every-row?":{category:"grid",description:"Checks if all rows in a grid satisfy a predicate. Returns true only if the predicate returns true for every row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-row? } = import(grid);\nevery-row?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-row?","grid.every-col?","grid.cell-every?"]},"some-row?":{category:"grid",description:"Checks if any row in a grid satisfies a predicate. Returns true if the predicate returns true for at least one row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-row?","grid.some-col?","grid.some?"]},"every-col?":{category:"grid",description:"Checks if all columns in a grid satisfy a predicate. Returns true only if the predicate returns true for every column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-col? } = import(grid);\nevery-col?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-col?","grid.every-row?","grid.cell-every?"]},"some-col?":{category:"grid",description:"Checks if any column in a grid satisfies a predicate. Returns true if the predicate returns true for at least one column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-col?","grid.some-row?","grid.some?"]},row:{category:"grid",description:"Returns the row at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.col","grid.shape"]},col:{category:"grid",description:"Returns the column at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.row","grid.shape"]},shape:{category:"grid",description:"Returns the shape of the grid `g` as a `vector` of two numbers, where the first number is the number of rows and the second number is the number of columns.",returns:{type:"vector"},args:{g:{type:"grid",description:"The grid to get the shape of."}},variants:[{argumentNames:["g"]}],examples:['let { shape } = import(grid);\nshape([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { shape } = import(grid);\nshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { shape } = import(grid);\nshape([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.row","grid.col","grid.reshape"]},fill:{category:"grid",description:"Creates a grid of the specified size, filled with the specified value.",returns:{type:"grid"},args:{rows:{type:"integer",description:"The number of rows in the grid."},cols:{type:"integer",description:"The number of columns in the grid."},value:{type:"any",description:"The value to fill the grid with."}},variants:[{argumentNames:["rows","cols","value"]}],examples:["let { fill } = import(grid);\nfill(2, 3, 0)",'let { fill } = import(grid);\nfill(2, 3, "x")'],seeAlso:["grid.generate","grid.from-array"]},generate:{category:"grid",description:"Generates a grid of the specified size, where each element is generated by the provided function.",returns:{type:"grid"},args:{rows:{type:"number",description:"The number of rows in the grid."},cols:{type:"number",description:"The number of columns in the grid."},generator:{type:"function",description:"The function to generate the grid. It takes two arguments: the row index and the column index."}},variants:[{argumentNames:["rows","cols","generator"]}],examples:["let { generate } = import(grid);\ngenerate(3, 3, (i, j) -> i + j)"],seeAlso:["grid.fill","grid.from-array"]},reshape:{category:"grid",description:"Reshapes the grid `a` into a new grid with the specified number of rows `b`. The number of columns is automatically calculated based on the total number of elements in the grid.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { reshape } = import(grid);\nreshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], 2)'],seeAlso:["grid.shape","grid.from-array"]},transpose:{category:"grid",description:"Transposes the grid `g`, swapping its rows and columns.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to transpose."}},variants:[{argumentNames:["g"]}],examples:['let { transpose } = import(grid);\ntranspose([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { transpose } = import(grid);\ntranspose([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { transpose } = import(grid);\ntranspose([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.flip-v","grid.rotate"]},"flip-h":{category:"grid",description:"Flips the grid `g` horizontally.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip horizontally."}},variants:[{argumentNames:["g"]}],examples:['let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-h } = import(grid);\nflip-h([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-v","grid.transpose","grid.rotate"]},"flip-v":{category:"grid",description:"Flips the grid `g` vertically.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip vertically."}},variants:[{argumentNames:["g"]}],examples:['let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-v } = import(grid);\nflip-v([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.transpose","grid.rotate"]},rotate:{category:"grid",description:"Rotates the grid `g` by the specified angle. The angle is given in terms of 90-degree rotations. Positive values rotate the grid clockwise, while negative values rotate it counterclockwise.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 3)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 4)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -3)"],seeAlso:["grid.transpose","grid.flip-h","grid.flip-v"]},crop:{category:"grid",description:"Crops the grid `g` from the starting index `begin` to the optional ending index `stop`. The crop is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"vector",description:"The starting index of the slice as a vector of two numbers: `[row, col]`."},stop:{type:"vector",description:"Optional ending index of the slice as a vector of two numbers: `[row, col]`."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { crop } = import(grid);\ncrop([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1], [2, 2])','let { crop } = import(grid);\ncrop([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1])'],hideOperatorForm:!0,seeAlso:["grid.slice-rows","grid.slice-cols"]},"slice-rows":{category:"grid",description:"Slices rows of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.crop","grid.slice-cols","grid.splice-rows"]},"slice-cols":{category:"grid",description:"Slices columns of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.crop","grid.slice-rows","grid.splice-cols"]},"splice-rows":{category:"grid",description:"Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of rows to delete."},items:{type:"array",rest:!0,description:"The rows to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.splice-cols","grid.slice-rows"]},"splice-cols":{category:"grid",description:"Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of columns to delete."},items:{type:"array",rest:!0,description:"The columns to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.splice-rows","grid.slice-cols"]},"concat-rows":{category:"grid",description:"Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-rows } = import(grid);\nconcat-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], [\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.concat-cols","grid.push-rows"]},"concat-cols":{category:"grid",description:"Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-cols } = import(grid);\nconcat-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])'],seeAlso:["grid.concat-rows","grid.push-cols"]},"cell-map":{category:"grid",description:"Maps a function `a` over each element of the grid `b`, returning a new grid with the results.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-map } = import(grid);\ncell-map([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], str)'],seeAlso:["map","grid.cell-mapi","grid.cell-reduce"]},"cell-mapi":{category:"grid",description:"Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-mapi } = import(grid);\ncell-mapi([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $1 ++ "(" ++ $2 ++ ", " ++ $3 ++ ")")'],seeAlso:["grid.cell-map","grid.cell-reducei","map"]},"cell-reduce":{category:"grid",description:"Reduces the grid `a` using the function `b`, returning a single value.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},f:{type:"function",description:"The function to reduce the grid. It takes two arguments: the accumulator and the current element."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","f","initial-value"]}],examples:['// Using "as" alias because "reduce" shadows a builtin function\nlet { cell-reduce } = import(grid);\ncell-reduce([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["reduce","grid.cell-reducei","grid.cell-map"]},"cell-reducei":{category:"grid",description:"Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},f:{type:"function",description:"The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","f","initial-value"]}],examples:['// Using "as" alias because "reducei" shadows a builtin function\nlet { cell-reducei } = import(grid);\ncell-reducei([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["grid.cell-reduce","grid.cell-mapi","reduce"]},"push-rows":{category:"grid",description:"Pushes the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push rows into."},rows:{type:"array",rest:!0,description:"The rows to push into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { push-rows } = import(grid);\npush-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.unshift-rows","grid.pop-row","grid.shift-row","grid.concat-rows"]},"unshift-rows":{category:"grid",description:"Unshifts the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift rows into."},rows:{type:"array",rest:!0,description:"The rows to unshift into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { unshift-rows } = import(grid);\nunshift-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.push-rows","grid.shift-row","grid.pop-row"]},"pop-row":{category:"grid",description:"Pops the last row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a row from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-row } = import(grid);\npop-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-row","grid.push-rows","grid.unshift-rows"]},"shift-row":{category:"grid",description:"Shifts the first row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a row from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-row } = import(grid);\nshift-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-row","grid.push-rows","grid.unshift-rows"]},"push-cols":{category:"grid",description:"Pushes the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push columns into."},cols:{type:"array",rest:!0,description:"The columns to push into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { push-cols } = import(grid);\npush-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.unshift-cols","grid.pop-col","grid.shift-col","grid.concat-cols"]},"unshift-cols":{category:"grid",description:"Unshifts the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift columns into."},cols:{type:"array",rest:!0,description:"The columns to unshift into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { unshift-cols } = import(grid);\nunshift-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.push-cols","grid.shift-col","grid.pop-col"]},"pop-col":{category:"grid",description:"Pops the last column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a column from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-col } = import(grid);\npop-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-col","grid.push-cols","grid.unshift-cols"]},"shift-col":{category:"grid",description:"Shifts the first column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a column from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-col } = import(grid);\nshift-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-col","grid.push-cols","grid.unshift-cols"]},"from-array":{category:"grid",description:"Creates a grid from a flat array with specified dimensions. The array is reshaped into the specified number of rows, and the number of columns is automatically calculated based on the total number of elements in the array.",returns:{type:"grid"},args:{a:{type:"array"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:["let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 2)","let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 4)"],seeAlso:["grid.fill","grid.generate","grid.reshape"]}};function ya(e){const t=[];for(let r=0;r<e[0].length;r+=1){const n=[];for(let t=0;t<e.length;t+=1)n.push(e[t][r]);t.push(n)}return t}const va={"cell-every?":{evaluate:()=>{throw new Error("cell-every?: Dvala implementation should be used instead")},arity:te(2)},"some?":{evaluate:()=>{throw new Error("some?: Dvala implementation should be used instead")},arity:te(2)},"every-row?":{evaluate:()=>{throw new Error("every-row?: Dvala implementation should be used instead")},arity:te(2)},"some-row?":{evaluate:()=>{throw new Error("some-row?: Dvala implementation should be used instead")},arity:te(2)},"every-col?":{evaluate:()=>{throw new Error("every-col?: Dvala implementation should be used instead")},arity:te(2)},"some-col?":{evaluate:()=>{throw new Error("some-col?: Dvala implementation should be used instead")},arity:te(2)},row:{evaluate:([e,t],r)=>(Oe(e,r),Y(t,r,{integer:!0,nonNegative:!0,lt:e.length}),e[t]),arity:te(2)},col:{evaluate:([e,t],r)=>(Oe(e,r),Y(t,r,{integer:!0,nonNegative:!0,lt:e[0].length}),e.map(e=>e[t])),arity:te(2)},shape:{evaluate:([e],t)=>(Oe(e,t),[e.length,e[0].length]),arity:te(1)},fill:{evaluate:([e,t,r],n)=>{Y(e,n,{integer:!0,positive:!0}),Y(t,n,{integer:!0,positive:!0}),E(r,n);const o=[];for(let n=0;n<e;n+=1){const e=[];for(let n=0;n<t;n+=1)e.push(r);o.push(e)}return o},arity:te(3)},generate:{evaluate:()=>{throw new Error("generate: Dvala implementation should be used instead")},arity:te(3)},reshape:{evaluate:([e,t],r)=>{Oe(e,r),Y(t,r,{integer:!0,positive:!0});const n=e.flat();if(n.length%t!==0)throw new o(`The number of elements in the grid must be divisible by rows, but got ${n.length} and ${t}`,r);const a=n.length/t,i=[];for(let e=0;e<t;e+=1){const t=[];for(let r=0;r<a;r+=1)t.push(n[e*a+r]);i.push(t)}return i},arity:te(2)},transpose:{evaluate:([e],t)=>(Oe(e,t),ya(e)),arity:te(1)},"flip-h":{evaluate:([e],t)=>(Oe(e,t),e.map(e=>e.reverse())),arity:te(1)},"flip-v":{evaluate:([e],t)=>(Oe(e,t),e.reverse()),arity:te(1)},rotate:{evaluate:([e,t],r)=>{if(Oe(e,r),Y(t,r,{integer:!0}),0===(t=(t%4+4)%4)||0===e.length)return e.map(e=>[...e]);const n=e.length,o=e[0].length;let a;switch(t){case 1:a=Array(o).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<o;r++)a[r][n-1-t]=e[t][r];break;case 2:a=Array(n).fill(null).map(()=>Array(o).fill(null));for(let t=0;t<n;t++)for(let r=0;r<o;r++)a[n-1-t][o-1-r]=e[t][r];break;case 3:a=Array(o).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<o;r++)a[o-1-r][t]=e[t][r]}return a},arity:te(2)},crop:{evaluate:([e,t,r],n)=>{if(Oe(e,n),Ce(t,n),2!==t.length)throw new o(`The start vector must have 2 elements, but got ${t.length}`,n);const[a,i]=t;if(Y(a,n,{integer:!0,nonNegative:!0,lt:e.length}),Y(i,n,{integer:!0,nonNegative:!0,lt:e[0].length}),r??=[e.length,e[0].length],Ce(r,n),2!==r.length)throw new o(`The end vector must have 2 elements, but got ${r.length}`,n);const[s,l]=r;Y(s,n,{gt:a,lte:e.length}),Y(l,n,{gt:i,lte:e[0].length});const c=[];for(let t=a;t<s;t+=1){const r=[];for(let n=i;n<l;n+=1)r.push(e[t][n]);c.push(r)}return c},arity:{min:2,max:3}},"slice-rows":{evaluate:([e,t,r],n)=>(Oe(e,n),void 0===r?(Y(t,n,{integer:!0,lte:e.length,gte:-e.length}),t<0?e.slice(e.length+t):e.slice(t)):(Y(t,n,{integer:!0,nonNegative:!0,lte:e.length}),Y(r,n,{integer:!0}),Y(r=r<0?e.length+r:r,n,{gt:t,lte:e.length}),e.slice(t,r))),arity:{min:2,max:3}},"slice-cols":{evaluate:([e,t,r],n)=>{Oe(e,n);const o=ya(e);return void 0===r?(Y(t,n,{integer:!0,lte:o.length,gte:-o.length}),ya(t<0?o.slice(o.length+t):o.slice(t))):(Y(t,n,{integer:!0,nonNegative:!0,lte:o.length}),Y(r,n,{integer:!0}),Y(r=r<0?o.length+r:r,n,{gt:t,lte:o.length}),ya(o.slice(t,r)))},arity:{min:2,max:3}},"splice-rows":{evaluate:([e,t,r,...n],a)=>{Oe(e,a),Y(t,a,{integer:!0,nonNegative:!0,lte:e.length}),Y(r,a,{integer:!0,nonNegative:!0}),0!==n.length&&(Oe(n,a),n.every(t=>{if(ye(t,a),e[0].length!==t.length)throw new o(`All rows must have the same length as the number of columns in grid, but got ${t.length}`,a);return!0}));const i=[];for(let r=0;r<t;r+=1)i.push(e[r]);n.length>0&&i.push(...n);for(let n=t+r;n<e.length;n+=1)i.push(e[n]);return i},arity:{min:3}},"splice-cols":{evaluate:([e,t,r,...n],a)=>{Oe(e,a);const i=ya(e);Y(t,a,{integer:!0,nonNegative:!0,lte:i.length}),Y(r,a,{integer:!0,nonNegative:!0}),0!==n.length&&(Oe(n,a),n.every(e=>{if(ye(e,a),i[0].length!==e.length)throw new o(`All rows must have the same length as the number of rows in grid, but got ${e.length}`,a);return!0}));const s=[];for(let e=0;e<t;e+=1)s.push(i[e]);s.push(...n);for(let e=t+r;e<i.length;e+=1)s.push(i[e]);return ya(s)},arity:{min:3}},"concat-rows":{evaluate:(e,t)=>{ye(e,t),e.every(e=>Oe(e,t));const r=e[0][0].length;e.slice(1).every(e=>{if(e[0].length!==r)throw new o(`All grids must have the same number of columns, but got ${r} and ${e[0].length}`,t);return!0});const n=[];return e.forEach(e=>{e.forEach(e=>{n.push(e)})}),n},arity:{min:1}},"concat-cols":{evaluate:(e,t)=>{ye(e,t),e.every(e=>Oe(e,t));const r=e[0].length;e.slice(1).every(e=>{if(e.length!==r)throw new o(`All grids must have the same number of rows, but got ${r} and ${e.length}`,t);return!0});const n=[];for(let t=0;t<r;t+=1){const r=[];e.forEach(e=>{r.push(...e[t])}),n.push(r)}return n},arity:{min:1}},"cell-map":{evaluate:()=>{throw new Error("cell-map: Dvala implementation should be used instead")},arity:{min:2}},"cell-mapi":{evaluate:()=>{throw new Error("cell-mapi: Dvala implementation should be used instead")},arity:te(2)},"cell-reduce":{evaluate:()=>{throw new Error("cell-reduce: Dvala implementation should be used instead")},arity:te(3)},"cell-reducei":{evaluate:()=>{throw new Error("cell-reducei: Dvala implementation should be used instead")},arity:te(3)},"push-rows":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e[0].length!==t[0].length)throw new o(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,r);return[...e,...t]},arity:{min:2}},"unshift-rows":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e[0].length!==t[0].length)throw new o(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,r);return[...t,...e]},arity:{min:2}},"pop-row":{evaluate:([e],t)=>(Oe(e,t),1===e.length?null:e.slice(0,-1)),arity:te(1)},"shift-row":{evaluate:([e],t)=>(Oe(e,t),1===e.length?null:e.slice(1)),arity:te(1)},"push-cols":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e.length!==t[0].length)throw new o(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,r);const n=[];for(let r=0;r<e.length;r+=1){const o=[];o.push(...e[r]),t.forEach(e=>{o.push(e[r])}),n.push(o)}return n},arity:{min:2}},"unshift-cols":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e.length!==t[0].length)throw new o(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,r);const n=[];for(let r=0;r<e.length;r+=1){const o=[];t.forEach(e=>{o.push(e[r])}),o.push(...e[r]),n.push(o)}return n},arity:{min:2}},"pop-col":{evaluate:([e],t)=>(Oe(e,t),1===e[0].length?null:e.map(e=>e.slice(0,-1))),arity:te(1)},"shift-col":{evaluate:([e],t)=>(Oe(e,t),1===e[0].length?null:e.map(e=>e.slice(1))),arity:te(1)},"from-array":{evaluate:([e,t],r)=>{if(ye(e,r),Y(t,r,{integer:!0,positive:!0}),e.length%t!==0)throw new o(`The number of elements in the array must be divisible by rows, but got ${e.length} and ${t}`,r);return function(e,t){const r=[],n=e.length/t;for(let o=0;o<t;o++){const t=o*n,a=t+n;r.push(e.slice(t,a))}return r}(e,t)},arity:te(2)}};for(const[e,t]of Object.entries(fa))va[e]&&(va[e].docs=t);const ba={name:"grid",functions:va,source:'do\nlet _transpose = (g) ->\n map(range(count(first(g))), (i) ->\n map(range(count(g)), (j) -> nth(nth(g, j), i))\n );\n{\n "cell-every?": (grid, predicate) -> do\n let cells = flatten(grid, 1);\n loop(i = 0) ->\n cond\n case i >= count(cells) then true\n case not(predicate(nth(cells, i))) then false\n case true then recur(i + 1)\n end\n end,\n "some?": (grid, predicate) -> do\n let cells = flatten(grid, 1);\n loop(i = 0) ->\n cond\n case i >= count(cells) then false\n case predicate(nth(cells, i)) then true\n case true then recur(i + 1)\n end\n end,\n\n "every-row?": (grid, predicate) ->\n loop(i = 0) ->\n cond\n case i >= count(grid) then true\n case not(predicate(nth(grid, i))) then false\n case true then recur(i + 1)\n end,\n\n "some-row?": (grid, predicate) ->\n loop(i = 0) ->\n cond\n case i >= count(grid) then false\n case predicate(nth(grid, i)) then true\n case true then recur(i + 1)\n end,\n\n "every-col?": (grid, predicate) -> do\n let cols = _transpose(grid);\n loop(i = 0) ->\n cond\n case i >= count(cols) then true\n case not(predicate(nth(cols, i))) then false\n case true then recur(i + 1)\n end\n end,\n\n "some-col?": (grid, predicate) -> do\n let cols = _transpose(grid);\n loop(i = 0) ->\n cond\n case i >= count(cols) then false\n case predicate(nth(cols, i)) then true\n case true then recur(i + 1)\n end\n end,\n\n "generate": (rows, cols, generator) ->\n map(range(rows), (i) -> map(range(cols), (j) -> generator(i, j))),\n\n "cell-map": (...params) -> do\n let fn = last(params);\n let grids = drop-last(params, 1);\n let rows = count(first(grids));\n let cols = count(first(first(grids)));\n map(range(rows), (i) ->\n map(range(cols), (j) ->\n apply(fn, map(grids, (g) -> nth(nth(g, i), j)))\n )\n )\n end,\n\n "cell-mapi": (grid, fn) -> do\n let rows = count(grid);\n let cols = count(first(grid));\n map(range(rows), (i) ->\n map(range(cols), (j) ->\n fn(nth(nth(grid, i), j), i, j)\n )\n )\n end,\n\n "cell-reduce": (grid, fn, initial-value) ->\n reduce(flatten(grid, 1), fn, initial-value),\n\n "cell-reducei": (grid, fn, initial-value) -> do\n let rows = count(grid);\n let cols = count(first(grid));\n loop(acc = initial-value, i = 0, j = 0) ->\n cond\n case i >= rows then acc\n case j >= cols then recur(acc, i + 1, 0)\n case true then recur(fn(acc, nth(nth(grid, i), j), i, j), i, j + 1)\n end\n end\n}\nend;',docs:fa},wa={"moving-mean":{category:"vector",description:"Returns the **moving mean** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving mean** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-mean } = import(vector);\nmoving-mean([1, 2, 3, 4, 5], 3)","let { moving-mean } = import(vector);\nmoving-mean([1, 2, 3, 4, 5], 5)"],seeAlso:["moving-fn","mean","vector.centered-moving-mean","vector.running-mean"]},"centered-moving-mean":{category:"vector",description:"Returns the **centered moving mean** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving mean** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-mean } = import(vector);\ncentered-moving-mean([1, 2, 3, 4, 5], 3)","let { centered-moving-mean } = import(vector);\ncentered-moving-mean([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-mean } = import(vector);\ncentered-moving-mean([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["mean","vector.moving-mean","vector.running-mean"]},"running-mean":{category:"vector",description:"Returns the **running mean** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-mean } = import(vector);\nrunning-mean([1, 2, 3, 4, 5])"],seeAlso:["running-fn","mean","vector.moving-mean","vector.centered-moving-mean"]},"geometric-mean":{category:"vector",description:"Returns the **geometric mean** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **geometric mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { geometric-mean } = import(vector);\ngeometric-mean([1, 2, 3])","let { geometric-mean } = import(vector);\ngeometric-mean([1, 2, 9])"],seeAlso:["vector.moving-geometric-mean","vector.centered-moving-geometric-mean","vector.running-geometric-mean","mean","vector.harmonic-mean"]},"moving-geometric-mean":{category:"vector",description:"Returns the **moving geometric mean** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving geometric mean** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-geometric-mean } = import(vector);\nmoving-geometric-mean([1, 2, 3, 4, 5], 3)","let { moving-geometric-mean } = import(vector);\nmoving-geometric-mean([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.geometric-mean","vector.centered-moving-geometric-mean","vector.running-geometric-mean"]},"centered-moving-geometric-mean":{category:"vector",description:"Returns the **centered moving geometric mean** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving geometric mean** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-geometric-mean } = import(vector);\ncentered-moving-geometric-mean([1, 2, 3, 4, 5], 3)","let { centered-moving-geometric-mean } = import(vector);\ncentered-moving-geometric-mean([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-geometric-mean } = import(vector);\ncentered-moving-geometric-mean([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["vector.geometric-mean","vector.moving-geometric-mean","vector.running-geometric-mean"]},"running-geometric-mean":{category:"vector",description:"Returns the **running geometric mean** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running geometric mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-geometric-mean } = import(vector);\nrunning-geometric-mean([1, 2, 3, 4, 5])"],seeAlso:["vector.geometric-mean","vector.moving-geometric-mean","vector.centered-moving-geometric-mean"]},"harmonic-mean":{category:"vector",description:"Returns the **harmonic mean** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **harmonic mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { harmonic-mean } = import(vector);\nharmonic-mean([1, 2, 3])","let { harmonic-mean } = import(vector);\nharmonic-mean([1, 2, 9])"],seeAlso:["vector.moving-harmonic-mean","vector.centered-moving-harmonic-mean","vector.running-harmonic-mean","mean","vector.geometric-mean"]},"moving-harmonic-mean":{category:"vector",description:"Returns the **moving harmonic mean** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving harmonic mean** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-harmonic-mean } = import(vector);\nmoving-harmonic-mean([1, 2, 3, 4, 5], 3)","let { moving-harmonic-mean } = import(vector);\nmoving-harmonic-mean([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.harmonic-mean","vector.centered-moving-harmonic-mean","vector.running-harmonic-mean"]},"centered-moving-harmonic-mean":{category:"vector",description:"Returns the **centered moving harmonic mean** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving harmonic mean** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-harmonic-mean } = import(vector);\ncentered-moving-harmonic-mean([1, 2, 3, 4, 5], 3)","let { centered-moving-harmonic-mean } = import(vector);\ncentered-moving-harmonic-mean([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-harmonic-mean } = import(vector);\ncentered-moving-harmonic-mean([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["vector.harmonic-mean","vector.moving-harmonic-mean","vector.running-harmonic-mean"]},"running-harmonic-mean":{category:"vector",description:"Returns the **running harmonic mean** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running harmonic mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-harmonic-mean } = import(vector);\nrunning-harmonic-mean([1, 2, 3, 4, 5])"],seeAlso:["vector.harmonic-mean","vector.moving-harmonic-mean","vector.centered-moving-harmonic-mean"]},"moving-median":{category:"vector",description:"Returns the **moving median** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving median** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-median } = import(vector);\nmoving-median([1, 2, 3, 4, 5], 3)","let { moving-median } = import(vector);\nmoving-median([1, 2, 3, 4, 5], 5)"],seeAlso:["median","vector.centered-moving-median","vector.running-median"]},"centered-moving-median":{category:"vector",description:"Returns the **centered moving median** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving median** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-median } = import(vector);\ncentered-moving-median([1, 2, 3, 4, 5], 3)","let { centered-moving-median } = import(vector);\ncentered-moving-median([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-median } = import(vector);\ncentered-moving-median([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["median","vector.moving-median","vector.running-median"]},"running-median":{category:"vector",description:"Returns the **running median** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running median** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-median } = import(vector);\nrunning-median([1, 2, 3, 4, 5])"],seeAlso:["median","vector.moving-median","vector.centered-moving-median"]},variance:{category:"vector",description:"Returns the **variance** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **variance** of."}},variants:[{argumentNames:["vector"]}],examples:["let { variance } = import(vector);\nvariance([1, 2, 3])","let { variance } = import(vector);\nvariance([1, 2, -3])"],seeAlso:["linear-algebra.cov","vector.moving-variance","vector.centered-moving-variance","vector.running-variance","vector.stdev","vector.sample-variance","vector.mad"]},"moving-variance":{category:"vector",description:"Returns the **moving variance** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving variance** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-variance } = import(vector);\nmoving-variance([1, 2, 3, 4, 5], 3)","let { moving-variance } = import(vector);\nmoving-variance([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.variance","vector.centered-moving-variance","vector.running-variance"]},"centered-moving-variance":{category:"vector",description:"Returns the **centered moving variance** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving variance** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3)","let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.variance","vector.moving-variance","vector.running-variance"]},"running-variance":{category:"vector",description:"Returns the **running variance** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running variance** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-variance } = import(vector);\nrunning-variance([1, 2, 3, 4, 5])"],seeAlso:["vector.variance","vector.moving-variance","vector.centered-moving-variance"]},"sample-variance":{category:"vector",description:"Returns the sample variance of all elements in the vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the sample variance of."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-variance } = import(vector);\nsample-variance([1, 2, 3])","let { sample-variance } = import(vector);\nsample-variance([1, 2, -3])","let { sample-variance } = import(vector);\nsample-variance([1, 2, 3, 4])","let { sample-variance } = import(vector);\nsample-variance([1, 2, -3, 4])","let { sample-variance } = import(vector);\nsample-variance([1, 2, 3, 40, 50])"],seeAlso:["vector.moving-sample-variance","vector.centered-moving-sample-variance","vector.running-sample-variance","vector.variance","vector.sample-stdev"]},"moving-sample-variance":{category:"vector",description:"Returns the **moving sample variance** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample variance** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-variance } = import(vector);\nmoving-sample-variance([1, 2, 3, 4, 5], 3)","let { moving-sample-variance } = import(vector);\nmoving-sample-variance([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.sample-variance","vector.centered-moving-sample-variance","vector.running-sample-variance"]},"centered-moving-sample-variance":{category:"vector",description:"Returns the **centered moving sample variance** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample variance** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3)","let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.sample-variance","vector.moving-sample-variance","vector.running-sample-variance"]},"running-sample-variance":{category:"vector",description:"Returns the **running sample variance** of the `vector`.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample variance** of. First element in result is `null` since **sample variance** is not defined for a single element."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-variance } = import(vector);\nrunning-sample-variance([1, 2, 3, 4, 5])"],seeAlso:["vector.sample-variance","vector.moving-sample-variance","vector.centered-moving-sample-variance"]},stdev:{category:"vector",description:"Returns the standard deviation of all elements in the vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the standard deviation of."}},variants:[{argumentNames:["vector"]}],examples:["let { stdev } = import(vector);\nstdev([1, 2, 3])","let { stdev } = import(vector);\nstdev([1, 2, -3])","let { stdev } = import(vector);\nstdev([1, 2, 3, 4])","let { stdev } = import(vector);\nstdev([1, 2, -3, 4])","let { stdev } = import(vector);\nstdev([1, 2, 3, 40, 50])"],seeAlso:["vector.moving-stdev","vector.centered-moving-stdev","vector.running-stdev","vector.variance","vector.sample-stdev","vector.rms","vector.mad"]},"moving-stdev":{category:"vector",description:"Returns the **moving standard deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving standard deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-stdev } = import(vector);\nmoving-stdev([1, 2, 3, 4, 5], 3)","let { moving-stdev } = import(vector);\nmoving-stdev([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.stdev","vector.centered-moving-stdev","vector.running-stdev"]},"centered-moving-stdev":{category:"vector",description:"Returns the **centered moving standard deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving standard deviation** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3)","let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.stdev","vector.moving-stdev","vector.running-stdev"]},"running-stdev":{category:"vector",description:"Returns the **running standard deviation** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running standard deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-stdev } = import(vector);\nrunning-stdev([1, 2, 3, 4, 5])"],seeAlso:["vector.stdev","vector.moving-stdev","vector.centered-moving-stdev"]},"sample-stdev":{category:"vector",description:"Returns the sample standard deviation of all elements in the vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the sample standard deviation of."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-stdev } = import(vector);\nsample-stdev([1, 2, 3])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, -3])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, 3, 4])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, -3, 4])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, 3, 40, 50])"],seeAlso:["vector.moving-sample-stdev","vector.centered-moving-sample-stdev","vector.running-sample-stdev","vector.stdev","vector.sample-variance"]},"moving-sample-stdev":{category:"vector",description:"Returns the **moving sample standard deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample standard deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-stdev } = import(vector);\nmoving-sample-stdev([1, 2, 3, 4, 5], 3)","let { moving-sample-stdev } = import(vector);\nmoving-sample-stdev([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.sample-stdev","vector.centered-moving-sample-stdev","vector.running-sample-stdev"]},"centered-moving-sample-stdev":{category:"vector",description:"Returns the **centered moving sample standard deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample standard deviation** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3)","let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.sample-stdev","vector.moving-sample-stdev","vector.running-sample-stdev"]},"running-sample-stdev":{category:"vector",description:"Returns the **running sample standard deviation** of the `vector`.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample standard deviation** of. First element in result is `null` since **sample standard deviation** is not defined for a single element."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-stdev } = import(vector);\nrunning-sample-stdev([1, 2, 3, 4, 5])"],seeAlso:["vector.sample-stdev","vector.moving-sample-stdev","vector.centered-moving-sample-stdev"]},iqr:{category:"vector",description:"Calculates the **interquartile range** of a `vector`. Returns the difference between the third and first quartiles.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **interquartile range** of. Minimum length is 4."}},variants:[{argumentNames:["vector"]}],examples:["let { iqr } = import(vector);\niqr([1, 2, 3, 4])","let { iqr } = import(vector);\niqr([5, 4, 3, 2, 1, 2, 3, 4, 5])","let { iqr } = import(vector);\niqr(range(1, 1000))","let { iqr } = import(vector);\niqr(map(range(1000), -> 1e6 / ($ + 1) ^ 2))","let { iqr } = import(vector);\nlet { ln } = import(math);\niqr(map(range(1000), -> ln($ + 1)))"],seeAlso:["vector.moving-iqr","vector.centered-moving-iqr","vector.running-iqr","vector.quartiles","median","vector.mad","vector.medad","vector.outliers?","vector.outliers"]},"moving-iqr":{category:"vector",description:"Calculates the **moving interquartile range** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving interquartile range** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-iqr } = import(vector);\nmoving-iqr([1, 2, 4, 7, 11, 16], 4)","let { moving-iqr } = import(vector);\nmoving-iqr([1, 2, 4, 7, 11, 16], 5)","let { moving-iqr } = import(vector);\nmoving-iqr([1, 2, 4, 7, 11, 16], 6)"],seeAlso:["vector.iqr","vector.centered-moving-iqr","vector.running-iqr"]},"centered-moving-iqr":{category:"vector",description:"Calculates the **centered moving interquartile range** of a `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving interquartile range** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-iqr } = import(vector);\ncentered-moving-iqr([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-iqr } = import(vector);\ncentered-moving-iqr([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.iqr","vector.moving-iqr","vector.running-iqr"]},"running-iqr":{category:"vector",description:"Calculates the **running interquartile range** of a `vector`. First three element in result is `null` since **running interquartile range** is not defined for less than four elements.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to calculate the **running interquartile range** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-iqr } = import(vector);\nrunning-iqr([1, 2, 3, 4, 5, 6])","let { running-iqr } = import(vector);\nrunning-iqr([-1, -2, -3, 1, 2, 3])"],seeAlso:["vector.iqr","vector.moving-iqr","vector.centered-moving-iqr"]},"moving-sum":{category:"vector",description:"Returns the **moving sum** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sum** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sum } = import(vector);\nmoving-sum([1, 2, 3, 4, 5], 3)","let { moving-sum } = import(vector);\nmoving-sum([1, 2, 3, 4, 5], 5)"],seeAlso:["sum","vector.centered-moving-sum","vector.running-sum"]},"centered-moving-sum":{category:"vector",description:"Returns the **centered moving sum** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sum** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sum } = import(vector);\ncentered-moving-sum([1, 2, 3, 4, 5], 3)","let { centered-moving-sum } = import(vector);\ncentered-moving-sum([1, 2, 3, 4, 5], 3, 0, 0)","let { centered-moving-sum } = import(vector);\ncentered-moving-sum([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["sum","vector.moving-sum","vector.running-sum"]},"running-sum":{category:"vector",description:"Returns the **running sum** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sum** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sum } = import(vector);\nrunning-sum([1, 2, 3])","let { running-sum } = import(vector);\nrunning-sum([1, -2, -3])"],seeAlso:["sum","vector.moving-sum","vector.centered-moving-sum","vector.cumsum"]},"moving-prod":{category:"vector",description:"Returns the **moving product** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving product** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-prod } = import(vector);\nmoving-prod([1, 2, 3, 4, 5], 3)","let { moving-prod } = import(vector);\nmoving-prod([1, 2, 3, 4, 5], 5)"],seeAlso:["prod","vector.centered-moving-prod","vector.running-prod"]},"centered-moving-prod":{category:"vector",description:"Returns the **centered moving product** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving product** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-prod } = import(vector);\ncentered-moving-prod([1, 2, 3, 4, 5], 3)","let { centered-moving-prod } = import(vector);\ncentered-moving-prod([1, 2, 3, 4, 5], 3, 0, 0)"],seeAlso:["prod","vector.moving-prod","vector.running-prod"]},"running-prod":{category:"vector",description:"Returns the **running product** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running product** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-prod } = import(vector);\nrunning-prod([1, 2, 3, 4, 5])","let { running-prod } = import(vector);\nrunning-prod([1, -2, -3])"],seeAlso:["prod","vector.moving-prod","vector.centered-moving-prod","vector.cumprod"]},span:{category:"vector",description:"Returns the difference between the maximum and minimum values in a vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to calculate the span of."}},variants:[{argumentNames:["vector"]}],examples:["let { span } = import(vector);\nspan([1, 2, 3])","let { span } = import(vector);\nspan([1, 1, 2, 3, 3])","let { span } = import(vector);\nspan([1, 2, -3])"],seeAlso:["vector.moving-span","vector.centered-moving-span","vector.running-span","min","max"]},"moving-span":{category:"vector",description:"Calculates the **moving span** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving span** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-span } = import(vector);\nmoving-span([1, 2, 4, 7, 11, 16], 4)","let { moving-span } = import(vector);\nmoving-span([1, 2, 4, 7, 11, 16], 5)","let { moving-span } = import(vector);\nmoving-span([1, 2, 4, 7, 11, 16], 6)"],seeAlso:["vector.span","vector.centered-moving-span","vector.running-span"]},"centered-moving-span":{category:"vector",description:"Calculates the **centered moving span** of a `vector` with a given window size. The result is padded with `leftPadding` on the left and right.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving span** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"The value to pad the result with on the left."},rightPadding:{type:"number",description:"The value to pad the result with on the right."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-span } = import(vector);\ncentered-moving-span([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-span } = import(vector);\ncentered-moving-span([1, 2, 4, 7, 11, 16], 3, 0, 100)"],seeAlso:["vector.span","vector.moving-span","vector.running-span"]},"running-span":{category:"vector",description:"Calculates the **running span** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running span** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-span } = import(vector);\nrunning-span([1, 2, 4])"],seeAlso:["vector.span","vector.moving-span","vector.centered-moving-span"]},skewness:{category:"vector",description:"Calculates the **skewness** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **skewness** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { skewness } = import(vector);\nskewness([1, 2, 3, 6, 20])","let { skewness } = import(vector);\nskewness([1, 2, 2, 3])"],seeAlso:["vector.moving-skewness","vector.centered-moving-skewness","vector.running-skewness","vector.kurtosis","vector.sample-skewness","vector.excess-kurtosis"]},"moving-skewness":{category:"vector",description:"Calculates the **moving skewness** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-skewness } = import(vector);\nmoving-skewness([1, 2, 4, 7, 11, 16], 4)","let { moving-skewness } = import(vector);\nmoving-skewness([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.skewness","vector.centered-moving-skewness","vector.running-skewness"]},"centered-moving-skewness":{category:"vector",description:"Calculates the **centered moving skewness** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-skewness } = import(vector);\ncentered-moving-skewness([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-skewness } = import(vector);\ncentered-moving-skewness([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.skewness","vector.moving-skewness","vector.running-skewness"]},"running-skewness":{category:"vector",description:"Calculates the **running skewness** of a `vector` with a given window size. First two element in result is `null` since **running skewness** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running skewness** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-skewness } = import(vector);\nrunning-skewness([1, 2, 4, 7, 11])"],seeAlso:["vector.skewness","vector.moving-skewness","vector.centered-moving-skewness"]},"sample-skewness":{category:"vector",description:"Calculates the **sample skewness** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **sample skewness** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-skewness } = import(vector);\nsample-skewness([1, 2, 3, 6, 20])","let { sample-skewness } = import(vector);\nsample-skewness([1, 2, 2, 3])"],seeAlso:["vector.moving-sample-skewness","vector.centered-moving-sample-skewness","vector.running-sample-skewness","vector.skewness","vector.sample-kurtosis"]},"moving-sample-skewness":{category:"vector",description:"Calculates the **moving sample skewness** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-skewness } = import(vector);\nmoving-sample-skewness([1, 2, 4, 7, 11, 16], 4)","let { moving-sample-skewness } = import(vector);\nmoving-sample-skewness([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.sample-skewness","vector.centered-moving-sample-skewness","vector.running-sample-skewness"]},"centered-moving-sample-skewness":{category:"vector",description:"Calculates the **centered moving sample skewness** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-skewness } = import(vector);\ncentered-moving-sample-skewness([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-sample-skewness } = import(vector);\ncentered-moving-sample-skewness([1, 2, 4, 7, 11, 16], 3, 0, 100)"],seeAlso:["vector.sample-skewness","vector.moving-sample-skewness","vector.running-sample-skewness"]},"running-sample-skewness":{category:"vector",description:"Calculates the **running sample skewness** of a `vector` with a given window size. First two element in result is `null` since **running sample skewness** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample skewness** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-skewness } = import(vector);\nrunning-sample-skewness([1, 2, 4, 7, 11])"],seeAlso:["vector.sample-skewness","vector.moving-sample-skewness","vector.centered-moving-sample-skewness"]},"excess-kurtosis":{category:"vector",description:"Calculates the **excess kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **excess kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { excess-kurtosis } = import(vector);\nexcess-kurtosis([1, 2, 3, 6, 20])","let { excess-kurtosis } = import(vector);\nexcess-kurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-excess-kurtosis","vector.centered-moving-excess-kurtosis","vector.running-excess-kurtosis","vector.kurtosis","vector.sample-excess-kurtosis","vector.skewness"]},"moving-excess-kurtosis":{category:"vector",description:"Calculates the **moving excess kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-excess-kurtosis } = import(vector);\nmoving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-excess-kurtosis } = import(vector);\nmoving-excess-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.excess-kurtosis","vector.centered-moving-excess-kurtosis","vector.running-excess-kurtosis"]},"centered-moving-excess-kurtosis":{category:"vector",description:"Calculates the **centered moving excess kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-excess-kurtosis } = import(vector);\ncentered-moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-excess-kurtosis } = import(vector);\ncentered-moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.excess-kurtosis","vector.moving-excess-kurtosis","vector.running-excess-kurtosis"]},"running-excess-kurtosis":{category:"vector",description:"Calculates the **running excess kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running excess kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running excess kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-excess-kurtosis } = import(vector);\nrunning-excess-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.excess-kurtosis","vector.moving-excess-kurtosis","vector.centered-moving-excess-kurtosis"]},kurtosis:{category:"vector",description:"Calculates the **kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { kurtosis } = import(vector);\nkurtosis([1, 2, 3, 6, 20])","let { kurtosis } = import(vector);\nkurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-kurtosis","vector.centered-moving-kurtosis","vector.running-kurtosis","vector.excess-kurtosis","vector.sample-kurtosis","vector.skewness"]},"moving-kurtosis":{category:"vector",description:"Calculates the **moving kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-kurtosis } = import(vector);\nmoving-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-kurtosis } = import(vector);\nmoving-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.kurtosis","vector.centered-moving-kurtosis","vector.running-kurtosis"]},"centered-moving-kurtosis":{category:"vector",description:"Calculates the **centered moving kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-kurtosis } = import(vector);\ncentered-moving-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-kurtosis } = import(vector);\ncentered-moving-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.kurtosis","vector.moving-kurtosis","vector.running-kurtosis"]},"running-kurtosis":{category:"vector",description:"Calculates the **running kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-kurtosis } = import(vector);\nrunning-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.kurtosis","vector.moving-kurtosis","vector.centered-moving-kurtosis"]},"sample-excess-kurtosis":{category:"vector",description:"Calculates the **sample excess kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **sample excess kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-excess-kurtosis } = import(vector);\nsample-excess-kurtosis([1, 2, 3, 6, 20])","let { sample-excess-kurtosis } = import(vector);\nsample-excess-kurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-sample-excess-kurtosis","vector.centered-moving-sample-excess-kurtosis","vector.running-sample-excess-kurtosis","vector.sample-kurtosis","vector.excess-kurtosis"]},"moving-sample-excess-kurtosis":{category:"vector",description:"Calculates the **moving sample excess kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-excess-kurtosis } = import(vector);\nmoving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-sample-excess-kurtosis } = import(vector);\nmoving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.sample-excess-kurtosis","vector.centered-moving-sample-excess-kurtosis","vector.running-sample-excess-kurtosis"]},"centered-moving-sample-excess-kurtosis":{category:"vector",description:"Calculates the **centered moving sample excess kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-excess-kurtosis } = import(vector);\ncentered-moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-sample-excess-kurtosis } = import(vector);\ncentered-moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 100)"],seeAlso:["vector.sample-excess-kurtosis","vector.moving-sample-excess-kurtosis","vector.running-sample-excess-kurtosis"]},"running-sample-excess-kurtosis":{category:"vector",description:"Calculates the **running sample excess kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running sample excess kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample excess kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-excess-kurtosis } = import(vector);\nrunning-sample-excess-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.sample-excess-kurtosis","vector.moving-sample-excess-kurtosis","vector.centered-moving-sample-excess-kurtosis"]},"sample-kurtosis":{category:"vector",description:"Calculates the **sample kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **sample kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-kurtosis } = import(vector);\nsample-kurtosis([1, 2, 3, 6, 20])","let { sample-kurtosis } = import(vector);\nsample-kurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-sample-kurtosis","vector.centered-moving-sample-kurtosis","vector.running-sample-kurtosis","vector.sample-excess-kurtosis","vector.kurtosis","vector.sample-skewness"]},"moving-sample-kurtosis":{category:"vector",description:"Calculates the **moving sample kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-kurtosis } = import(vector);\nmoving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-sample-kurtosis } = import(vector);\nmoving-sample-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.sample-kurtosis","vector.centered-moving-sample-kurtosis","vector.running-sample-kurtosis"]},"centered-moving-sample-kurtosis":{category:"vector",description:"Calculates the **centered moving sample kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-kurtosis } = import(vector);\ncentered-moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-sample-kurtosis } = import(vector);\ncentered-moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 100)"],seeAlso:["vector.sample-kurtosis","vector.moving-sample-kurtosis","vector.running-sample-kurtosis"]},"running-sample-kurtosis":{category:"vector",description:"Calculates the **running sample kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running sample kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-kurtosis } = import(vector);\nrunning-sample-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.sample-kurtosis","vector.moving-sample-kurtosis","vector.centered-moving-sample-kurtosis"]},rms:{category:"vector",description:"Calculates the **root mean square** of a `vector`. Returns the square root of the average of the squares of the elements.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **root mean square** of. Minimum length is 1."}},variants:[{argumentNames:["vector"]}],examples:["let { rms } = import(vector);\nrms([1, 2, 3, 4])","let { rms } = import(vector);\nrms([5, 4, 3, 2, 1])","let { rms } = import(vector);\nrms(range(1, 1000))","let { rms } = import(vector);\nrms(map(range(1000), -> 1e6 / ($ + 1) ^ 2))","let { rms } = import(vector);\nlet { ln } = import(math);\nrms(map(range(1000), -> ln($ + 1)))"],seeAlso:["vector.moving-rms","vector.centered-moving-rms","vector.running-rms","mean","vector.stdev"]},"moving-rms":{category:"vector",description:"Calculates the **moving root mean square** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving root mean square** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-rms } = import(vector);\nmoving-rms([1, 2, 4, 7, 11, 16], 4)","let { moving-rms } = import(vector);\nmoving-rms([1, 2, 4, 7, 11, 16], 5)","let { moving-rms } = import(vector);\nmoving-rms([1, 2, 4, 7, 11, 16], 6)"],seeAlso:["vector.rms","vector.centered-moving-rms","vector.running-rms"]},"centered-moving-rms":{category:"vector",description:"Calculates the **centered moving root mean square** of a `vector` with a given window size and padding value.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving root mean square** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-rms } = import(vector);\ncentered-moving-rms([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-rms } = import(vector);\ncentered-moving-rms([1, 2, 4, 7, 11, 16], 5, 0)","let { centered-moving-rms } = import(vector);\ncentered-moving-rms([1, 2, 4, 7, 11, 16], 6, 0, 0)"],seeAlso:["vector.rms","vector.moving-rms","vector.running-rms"]},"running-rms":{category:"vector",description:"Calculates the **running root mean square** of a `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running root mean square** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-rms } = import(vector);\nrunning-rms([1, 2, 3, 4, 5, 6])","let { running-rms } = import(vector);\nrunning-rms([1, -3, 2])","let { running-rms } = import(vector);\nrunning-rms([-1, -2, -3])","let { running-rms } = import(vector);\nrunning-rms([0])"],seeAlso:["vector.rms","vector.moving-rms","vector.centered-moving-rms"]},mad:{category:"vector",description:"Returns the **mean absolute deviation** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **mean absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { mad } = import(vector);\nmad([1, 2, 3])","let { mad } = import(vector);\nmad([1, 2, -3])"],seeAlso:["vector.moving-mad","vector.centered-moving-mad","vector.running-mad","vector.medad","vector.stdev","vector.variance","vector.iqr"]},"moving-mad":{category:"vector",description:"Returns the **moving mean absolute deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving mean absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-mad } = import(vector);\nmoving-mad([1, 2, 3, 4, 5], 3)","let { moving-mad } = import(vector);\nmoving-mad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.mad","vector.centered-moving-mad","vector.running-mad"]},"centered-moving-mad":{category:"vector",description:"Returns the **centered moving mean absolute deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving mean absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-mad } = import(vector);\ncentered-moving-mad([1, 2, 3, 4, 5], 3)","let { centered-moving-mad } = import(vector);\ncentered-moving-mad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.mad","vector.moving-mad","vector.running-mad"]},"running-mad":{category:"vector",description:"Returns the **running mean absolute deviation** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running mean absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-mad } = import(vector);\nrunning-mad([1, 2, 3])","let { running-mad } = import(vector);\nrunning-mad([1, 2, -3])"],seeAlso:["vector.mad","vector.moving-mad","vector.centered-moving-mad"]},medad:{category:"vector",description:"Returns the **median absolute deviation** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **median absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { medad } = import(vector);\nmedad([1, 2, 3])","let { medad } = import(vector);\nmedad([1, 2, -3])"],seeAlso:["vector.moving-medad","vector.centered-moving-medad","vector.running-medad","vector.mad","median","vector.iqr"]},"moving-medad":{category:"vector",description:"Returns the **moving median absolute deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving median absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-medad } = import(vector);\nmoving-medad([1, 2, 3, 4, 5], 3)","let { moving-medad } = import(vector);\nmoving-medad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.medad","vector.centered-moving-medad","vector.running-medad"]},"centered-moving-medad":{category:"vector",description:"Returns the **centered moving median absolute deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving median absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-medad } = import(vector);\ncentered-moving-medad([1, 2, 3, 4, 5], 3)","let { centered-moving-medad } = import(vector);\ncentered-moving-medad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.medad","vector.moving-medad","vector.running-medad"]},"running-medad":{category:"vector",description:"Returns the **running median absolute deviation** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running median absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-medad } = import(vector);\nrunning-medad([1, 2, 3])","let { running-medad } = import(vector);\nrunning-medad([1, 2, -3])"],seeAlso:["vector.medad","vector.moving-medad","vector.centered-moving-medad"]},"gini-coefficient":{category:"vector",description:"Returns the **gini coefficient** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **gini coefficient** of."}},variants:[{argumentNames:["vector"]}],examples:["let { gini-coefficient } = import(vector);\ngini-coefficient([1, 2, 3])","let { gini-coefficient } = import(vector);\ngini-coefficient([1, 1, 3])"],seeAlso:["vector.moving-gini-coefficient","vector.centered-moving-gini-coefficient","vector.running-gini-coefficient","vector.entropy"]},"moving-gini-coefficient":{category:"vector",description:"Returns the **moving gini coefficient** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving gini coefficient** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-gini-coefficient } = import(vector);\nmoving-gini-coefficient([1, 2, 3], 2)","let { moving-gini-coefficient } = import(vector);\nmoving-gini-coefficient([1, 1, 3], 2)"],seeAlso:["vector.gini-coefficient","vector.centered-moving-gini-coefficient","vector.running-gini-coefficient"]},"centered-moving-gini-coefficient":{category:"vector",description:"Returns the **centered moving gini coefficient** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving gini coefficient** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-gini-coefficient } = import(vector);\ncentered-moving-gini-coefficient([1, 2, 3], 2)","let { centered-moving-gini-coefficient } = import(vector);\ncentered-moving-gini-coefficient([1, 1, 3], 2)"],seeAlso:["vector.gini-coefficient","vector.moving-gini-coefficient","vector.running-gini-coefficient"]},"running-gini-coefficient":{category:"vector",description:"Returns the **running gini coefficient** of the `vector`.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running gini coefficient** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-gini-coefficient } = import(vector);\nrunning-gini-coefficient([1, 2, 3])","let { running-gini-coefficient } = import(vector);\nrunning-gini-coefficient([1, 1, 3])"],seeAlso:["vector.gini-coefficient","vector.moving-gini-coefficient","vector.centered-moving-gini-coefficient"]},entropy:{category:"vector",description:"Calculates the **entropy** of a `vector`. The entropy is a measure of the uncertainty associated with a random variable.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **entropy** of. Minimum length is 1."}},variants:[{argumentNames:["vector"]}],examples:["let { entropy } = import(vector);\nentropy([1, 1, 2, 3, 3, 3])","let { entropy } = import(vector);\nentropy([1, 2, 3])","let { entropy } = import(vector);\nentropy([1, 2, 2, 3])","let { entropy } = import(vector);\nentropy([0])","let { entropy } = import(vector);\nentropy([1])","let { entropy } = import(vector);\nentropy([1, 2])"],seeAlso:["vector.moving-entropy","vector.centered-moving-entropy","vector.running-entropy","vector.gini-coefficient"]},"moving-entropy":{category:"vector",description:"Calculates the **moving entropy** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving entropy** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-entropy } = import(vector);\nmoving-entropy([1, 1, 2, 3, 3, 3], 4)","let { moving-entropy } = import(vector);\nmoving-entropy([1, 1, 2, 3, 3, 3], 3)","let { moving-entropy } = import(vector);\nmoving-entropy([1, 2], 2)"],seeAlso:["vector.entropy","vector.centered-moving-entropy","vector.running-entropy"]},"centered-moving-entropy":{category:"vector",description:"Calculates the **centered moving entropy** of a `vector` with a given window size.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving entropy** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-entropy } = import(vector);\ncentered-moving-entropy([1, 1, 2, 3, 3, 3], 4)","let { centered-moving-entropy } = import(vector);\ncentered-moving-entropy([1, 1, 2, 3, 3, 3], 3)","let { centered-moving-entropy } = import(vector);\ncentered-moving-entropy([1, 2], 2)"],seeAlso:["vector.entropy","vector.moving-entropy","vector.running-entropy"]},"running-entropy":{category:"vector",description:"Calculates the **running entropy** of a `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running entropy** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-entropy } = import(vector);\nrunning-entropy([1, 1, 2, 3, 3, 3])","let { running-entropy } = import(vector);\nrunning-entropy([1, 2])"],seeAlso:["vector.entropy","vector.moving-entropy","vector.centered-moving-entropy"]},"monotonic?":{category:"vector",description:"Checks if a vector is monotonic.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { monotonic? } = import(vector);\nmonotonic?([1, 2, 3])","let { monotonic? } = import(vector);\nmonotonic?([1, 2, 2, 3])","let { monotonic? } = import(vector);\nmonotonic?([3, 2, 1])","let { monotonic? } = import(vector);\nmonotonic?([3, 2, 1, 1])","let { monotonic? } = import(vector);\nmonotonic?([3, 2, 1, 2])","let { monotonic? } = import(vector);\nmonotonic?([1])","let { monotonic? } = import(vector);\nmonotonic?([])"],seeAlso:["vector.strictly-monotonic?","vector.increasing?","vector.decreasing?"]},"strictly-monotonic?":{category:"vector",description:"Checks if a vector is strictly monotonic.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([1, 2, 3])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([1, 2, 2, 3])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([3, 2, 1])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([3, 2, 1, 1])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([3, 2, 1, 2])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([1])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([])"],seeAlso:["vector.monotonic?","vector.strictly-increasing?","vector.strictly-decreasing?"]},"increasing?":{category:"vector",description:"Checks if a vector is increasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { increasing? } = import(vector);\nincreasing?([1, 2, 3])","let { increasing? } = import(vector);\nincreasing?([1, 2, 2, 3])","let { increasing? } = import(vector);\nincreasing?([3, 2, 1])","let { increasing? } = import(vector);\nincreasing?([3, 2, 1, 1])","let { increasing? } = import(vector);\nincreasing?([3, 2, 1, 2])","let { increasing? } = import(vector);\nincreasing?([1])","let { increasing? } = import(vector);\nincreasing?([])"],seeAlso:["vector.strictly-increasing?","vector.decreasing?","vector.strictly-decreasing?","vector.monotonic?"]},"decreasing?":{category:"vector",description:"Checks if a vector is decreasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { decreasing? } = import(vector);\ndecreasing?([1, 2, 3])","let { decreasing? } = import(vector);\ndecreasing?([1, 2, 2, 3])","let { decreasing? } = import(vector);\ndecreasing?([3, 2, 1])","let { decreasing? } = import(vector);\ndecreasing?([3, 2, 1, 1])","let { decreasing? } = import(vector);\ndecreasing?([3, 2, 1, 2])","let { decreasing? } = import(vector);\ndecreasing?([1])","let { decreasing? } = import(vector);\ndecreasing?([])"],seeAlso:["vector.strictly-decreasing?","vector.increasing?","vector.strictly-increasing?","vector.monotonic?"]},"strictly-increasing?":{category:"vector",description:"Checks if a vector is strictly increasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { strictly-increasing? } = import(vector);\nstrictly-increasing?([1, 2, 3])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([1, 2, 2, 3])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([3, 2, 1])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([3, 2, 1, 1])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([3, 2, 1, 2])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([1])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([])"],seeAlso:["vector.increasing?","vector.decreasing?","vector.strictly-decreasing?","vector.strictly-monotonic?"]},"strictly-decreasing?":{category:"vector",description:"Checks if a vector is strictly decreasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([1, 2, 3])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([1, 2, 2, 3])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([3, 2, 1])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([3, 2, 1, 1])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([3, 2, 1, 2])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([1])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([])"],seeAlso:["vector.increasing?","vector.strictly-increasing?","vector.decreasing?","vector.strictly-monotonic?"]},mode:{category:"vector",description:"Returns the mode of all elements in the vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the mode of."}},variants:[{argumentNames:["vector"]}],examples:["let { mode } = import(vector);\nmode([1, 2, 3])","let { mode } = import(vector);\nmode([1, 2, -3, 1])","let { mode } = import(vector);\nmode([2, 2, 3, 3, 4])","let { mode } = import(vector);\nmode([2, 2, 3, 3])","let { mode } = import(vector);\nmode([1, 2, 3, 2, 1, 2])"],seeAlso:["mean","median"]},"min-index":{category:"vector",description:"Returns the index of the minimum value of all elements in the vector.",returns:{type:"integer"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the minimum index of."}},variants:[{argumentNames:["vector"]}],examples:["let { min-index } = import(vector);\nmin-index([1, 2, 3])","let { min-index } = import(vector);\nmin-index([1, 1, 2, 3, 3])","let { min-index } = import(vector);\nmin-index([1, 2, -3])","let { min-index } = import(vector);\nmin-index([1, 2, 3, 4])","let { min-index } = import(vector);\nmin-index([1, 2, -3, 4])"],seeAlso:["vector.max-index","min"]},"max-index":{category:"vector",description:"Returns the index of the maximum value of all elements in the vector.",returns:{type:"integer"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the maximum index of."}},variants:[{argumentNames:["vector"]}],examples:["let { max-index } = import(vector);\nmax-index([1, 2, 3])","let { max-index } = import(vector);\nmax-index([1, 1, 2, 3, 3])","let { max-index } = import(vector);\nmax-index([1, 2, -3])","let { max-index } = import(vector);\nmax-index([1, 2, 3, 4])","let { max-index } = import(vector);\nmax-index([1, 2, -3, 4])"],seeAlso:["vector.min-index","max"]},"sort-indices":{category:"vector",description:"Returns the indices of the elements in the vector sorted in ascending order.",returns:{type:"vector"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the sorted indices of."}},variants:[{argumentNames:["vector"]}],examples:["let { sort-indices } = import(vector);\nsort-indices([1, 2, 3])","let { sort-indices } = import(vector);\nsort-indices([1, 1, 2, 3, 3])","let { sort-indices } = import(vector);\nsort-indices([1, 2, -3])","let { sort-indices } = import(vector);\nsort-indices([1, 2, 3, 4])","let { sort-indices } = import(vector);\nsort-indices([1, 2, -3, 4])"],seeAlso:["sort"]},"count-values":{category:"vector",description:"Counts the number of occurrences of each value in the vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"Vector to count the values of."}},variants:[{argumentNames:["vector"]}],examples:["let { count-values } = import(vector);\ncount-values([1, 2, 3])","let { count-values } = import(vector);\ncount-values([1, 1, 2, 3, 3])","let { count-values } = import(vector);\ncount-values([1, 2, -3])","let { count-values } = import(vector);\ncount-values([1, 2, 2, 1, 3, 2, 4, 2, 1, 2, 2, 1, 3, 2, 4])"],seeAlso:["sequence.frequencies","vector.bincount"]},linspace:{category:"vector",description:"Generates a vector of evenly spaced numbers between two values.",returns:{type:"number",array:!0},args:{start:{type:"number",description:"The starting value."},stop:{type:"number",description:"The ending value."},n:{type:"integer",description:"The number of values to generate."}},variants:[{argumentNames:["start","stop","n"]}],examples:["let { linspace } = import(vector);\nlinspace(0, 10, 6)","let { linspace } = import(vector);\nlinspace(10, 20, 25)"],seeAlso:["range"]},cumsum:{category:"vector",description:"Calculates the cumulative sum of a vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the cumulative sum of."}},variants:[{argumentNames:["vector"]}],examples:["let { cumsum } = import(vector);\ncumsum([1, 2, 3])","let { cumsum } = import(vector);\ncumsum([1, 2, -3])","let { cumsum } = import(vector);\ncumsum([])"],seeAlso:["vector.cumprod","sum","vector.running-sum"]},cumprod:{category:"vector",description:"Calculates the cumulative product of a vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the cumulative product of."}},variants:[{argumentNames:["vector"]}],examples:["let { cumprod } = import(vector);\ncumprod([1, 2, 3])","let { cumprod } = import(vector);\ncumprod([1, 2, -3, 0, 10])","let { cumprod } = import(vector);\ncumprod([])"],seeAlso:["vector.cumsum","prod","vector.running-prod"]},quartiles:{category:"vector",description:"Calculates the quartiles of a vector. Returns an array containing the first, second (median), and third quartiles.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the quartiles of. Minimum length is 4."}},variants:[{argumentNames:["vector"]}],examples:["let { quartiles } = import(vector);\nquartiles([1, 2, 3, 4])","let { quartiles } = import(vector);\nquartiles([5, 4, 3, 2, 1, 2, 3, 4, 5])","let { quartiles } = import(vector);\nquartiles(range(1, 1000))","let { quartiles } = import(vector);\nquartiles(map(range(1000), -> 1e6 / ($ + 1) ^ 2))","let { quartiles } = import(vector);\nlet { ln } = import(math);\nquartiles(map(range(1000), -> ln($ + 1)))"],seeAlso:["vector.percentile","vector.quantile","median","vector.iqr"]},percentile:{category:"vector",description:"Calculates the percentile of a vector. Returns the value at the specified percentile.",returns:{type:"number"},args:{vector:{type:"vector",description:"The non empty vector to calculate the percentile of."},percentile:{type:"number",description:"The percentile to calculate. Must be between 0 and 1."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","percentile"]}],examples:["let { percentile } = import(vector);\npercentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 35)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 0)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 10)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 20)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 30)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 40)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 50)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 60)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 70)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 80)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 90)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 100)"],seeAlso:["vector.quantile","vector.quartiles","median","vector.ecdf","vector.winsorize"]},quantile:{category:"vector",description:"Calculates the quantile of a vector. Returns the value at the specified quantile.",returns:{type:"number"},args:{vector:{type:"vector",description:"The non empty vector to calculate the quantile of."},quantile:{type:"number",description:"The quantile to calculate. Must be between 0 and 1."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","quantile"]}],examples:["let { quantile } = import(vector);\nquantile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0.35)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.1)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.2)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.3)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.4)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.5)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.6)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.7)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.8)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.9)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 1)"],seeAlso:["vector.percentile","vector.quartiles","vector.ecdf"]},histogram:{category:"vector",description:"Creates a histogram from a numeric `array` by dividing the data range into the specified number of bins. Returns an `array` of `[binStart, binEnd, count]` tuples representing each bin's range and the number of values within it. Handles empty arrays, identical values, and properly places maximum values in the last bin.",returns:{type:"array",array:!0},args:{vector:{type:"vector",description:"The numeric array to create a histogram from."},bins:{type:"integer",description:"The number of bins to divide the data range into."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","bins"]}],examples:["let { histogram } = import(vector);\nhistogram([1, 2, 2, 3, 2, 6, 4, 3, 2, 4, 1, 3, 2, 9], 3)","let { histogram } = import(vector);\nhistogram([1, 2, 3, 4, 5], 5)","let { histogram } = import(vector);\nhistogram([1, 2, 3, 4, 5], 10)","let { histogram } = import(vector);\nhistogram([1, 2, 3, 4, 5], 1)"],seeAlso:["vector.bincount","vector.ecdf"]},ecdf:{category:"vector",description:"Calculates the empirical cumulative distribution function value for a given threshold in a non empty dataset. Returns the proportion of values in the `array` that are less than or equal to the specified threshold.",returns:{type:"number"},args:{vector:{type:"vector",description:"The numeric array to calculate the ECDF from."},threshold:{type:"number",description:"The threshold value to calculate the ECDF for."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","threshold"]}],examples:["let { ecdf } = import(vector);\necdf([1, 2, 2, 3, 2, 6, 4, 3, 2, 4, 1, 3, 2, 9, 10, 12], 5)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 3)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 0)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 10)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 2)"],seeAlso:["vector.histogram","vector.percentile","vector.quantile"]},"outliers?":{category:"vector",description:"Checks if the `vector` contains outliers based on the interquartile range (IQR) method. Returns `true` if outliers are present, `false` otherwise.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The `vector` to check for outliers."}},variants:[{argumentNames:["vector"]}],examples:["let { outliers? } = import(vector);\noutliers?([1, 2, 3])","let { outliers? } = import(vector);\noutliers?([1, 2, -3])","let { outliers? } = import(vector);\noutliers?([1, 2, 3, 2, 4, 120])"],seeAlso:["vector.outliers","vector.winsorize","vector.iqr"]},outliers:{category:"vector",description:"Identifies outliers in the `vector` based on the interquartile range (IQR) method. Returns an array of outlier values.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to check for outliers."}},variants:[{argumentNames:["vector"]}],examples:["let { outliers } = import(vector);\noutliers([1, 2, 3])","let { outliers } = import(vector);\noutliers([1, 2, -3])","let { outliers } = import(vector);\noutliers([1, 2, 3, 2, 4, 120])"],seeAlso:["vector.outliers?","vector.winsorize","vector.iqr"]},bincount:{category:"vector",description:"counts occurrences of each `integer` in a vector, returning an array where index `i` contains the count of value `i`, with optional **minimum size** and **weights parameters**.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The vector to count occurrences in."},minSize:{type:"integer",description:"Optional minimum size of the output array."},weights:{type:"number",array:!0,description:"Optional weights for each element in the vector."}},variants:[{argumentNames:["vector"]},{argumentNames:["vector","minSize"]},{argumentNames:["vector","minSize","weights"]}],examples:["let { bincount } = import(vector);\nbincount([1, 2, 3])","let { bincount } = import(vector);\nbincount([1, 2, 2, 3, 3])"],seeAlso:["vector.count-values","vector.histogram"],hideOperatorForm:!0},winsorize:{category:"vector",description:"Limits extreme values in a `vector` by replacing values below the **lower quantile** and above the **upper quantile** with the values at those quantiles. The function takes a `vector` of values and **quantile thresholds** (between 0 and 1), with the upper quantile. Winsorization reduces the influence of outliers while preserving the overall distribution shape, making statistical analyses more robust.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The vector to winsorize."},"lower-quantile":{type:"number",description:"The lower quantile threshold (between 0 and 1)."},"upper-quantile":{type:"number",description:"Optional Upper quantile threshold (between 0 and 1). Defaults to `(1 - lower-quantile)` if `lower-quantile <= 0.5` otherwise `1`."}},variants:[{argumentNames:["vector","lower-quantile"]},{argumentNames:["vector","lower-quantile","upper-quantile"]}],examples:["let { winsorize } = import(vector);\nwinsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25)","let { winsorize } = import(vector);\nwinsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25, 0.75)","let { winsorize } = import(vector);\nwinsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25, 0.5)"],seeAlso:["vector.outliers","vector.outliers?","vector.percentile"],hideOperatorForm:!0},mse:{category:"vector",description:"Calculates the **Mean Squared Error (MSE)** between two vectors. Returns the average of the squared differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { mse } = import(vector);\nmse([1, 2, 3], [1, 2, 3])","let { mse } = import(vector);\nmse([1, 2, 3], [4, 5, 6])","let { mse } = import(vector);\nmse([1, 2, 3], [2, 2, 2])","let { mse } = import(vector);\nmse([1, 2], [3, 3])","let { mse } = import(vector);\nmse([1], [3])"],seeAlso:["vector.rmse","vector.mae","vector.smape"]},rmse:{category:"vector",description:"Calculates the **Root Mean Squared Error (RMSE)** between two vectors. Returns the square root of the average of the squared differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { rmse } = import(vector);\nrmse([1, 2, 3], [1, 2, 3])","let { rmse } = import(vector);\nrmse([1, 2, 3], [4, 5, 6])","let { rmse } = import(vector);\nrmse([1, 2, 3], [2, 2, 2])","let { rmse } = import(vector);\nrmse([1, 2], [3, 3])","let { rmse } = import(vector);\nrmse([1], [3])"],seeAlso:["vector.mse","vector.mae","vector.smape"]},mae:{category:"vector",description:"Calculates the **Mean Absolute Error (MAE)** between two vectors. Returns the average of the absolute differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { mae } = import(vector);\nmae([1, 2, 3], [1, 2, 3])","let { mae } = import(vector);\nmae([1, 2, 3], [4, 5, 6])","let { mae } = import(vector);\nmae([1, 2, 3], [2, 2, 2])","let { mae } = import(vector);\nmae([1, 2], [3, 3])","let { mae } = import(vector);\nmae([1], [3])"],seeAlso:["vector.mse","vector.rmse","vector.smape"]},smape:{category:"vector",description:"Calculates the **Symmetric Mean Absolute Percentage Error (SMAPE)** between two vectors. Returns the average of the absolute percentage differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { smape } = import(vector);\nsmape([1, 2, 3], [1, 2, 3])","let { smape } = import(vector);\nsmape([1, 2, 3], [4, 5, 6])","let { smape } = import(vector);\nsmape([1, 2, 3], [2, 2, 2])","let { smape } = import(vector);\nsmape([1, 2], [3, 3])","let { smape } = import(vector);\nsmape([1], [3])"],seeAlso:["vector.mse","vector.rmse","vector.mae"]}};function xa(e){if(e.length<=1)return[];const t=[...e].sort((e,t)=>e-t),r=Math.floor(.25*t.length),n=t.length%4==0?(t[r-1]+t[r])/2:t[r],o=Math.floor(.75*t.length),a=t.length%4==0?(t[o-1]+t[o])/2:t[o],i=a-n,s=n-1.5*i,l=a+1.5*i;return e.filter(e=>e<s||e>l)}function ka(e,t){const r=[...e].sort((e,t)=>e-t);if(0===t)return r[0];if(100===t)return r[r.length-1];const n=t/100*(r.length-1);if(Number.isInteger(n))return r[n];const o=Math.floor(n),a=Math.ceil(n),i=n-o;return r[o]*(1-i)+r[a]*i}function qa(e){const t=[...e].sort((e,t)=>e-t),r=t.length/2;let n;n=t.length%2==0?(t[r-1]+t[r])/2:t[Math.floor(r)];const o=t.slice(0,Math.floor(t.length/2)),a=t.slice(Math.ceil(t.length/2));let i,s;if(o.length%2==0){const e=o.length/2;i=(o[e-1]+o[e])/2}else i=o[Math.floor(o.length/2)];if(a.length%2==0){const e=a.length/2;s=(a[e-1]+a[e])/2}else s=a[Math.floor(a.length/2)];return[i,n,s]}function Aa(e){if(0===e.length)return 0;return e.reduce((e,t)=>e+t,0)/e.length}const Na={"geometric-mean":e=>{if(e.some(e=>e<0))throw new Error("Geometric mean is not defined for non-positive numbers");return Math.exp(e.reduce((e,t)=>e+Math.log(t),0)/e.length)}};function $a(e){const t=[...e].sort((e,t)=>e-t),r=Math.floor(t.length/2);return t.length%2==0?(t[r-1]+t[r])/2:t[r]}const Ea={median:e=>$a(e)};function Ta(e,t){const r=t??Aa(e);return e.reduce((e,t)=>e+(t-r)**2,0)/e.length}const Sa={variance:e=>Ta(e)},za={"sample-variance":e=>function(e){const t=Aa(e);return e.reduce((e,r)=>e+(r-t)**2,0)/(e.length-1)}(e),minLength:2};function ja(e,t){const r=Ta(e,t);return Math.sqrt(r)}const Ca={stdev:e=>ja(e)},Ia={"sample-stdev":e=>function(e,t){const r=Ta(e,t);return Math.sqrt(r*(e.length/(e.length-1)))}(e),minLength:2},Ra={iqr:e=>{const[t,,r]=qa(e);return r-t},minLength:4},Pa={span:e=>0===e.length?0:Math.max(...e)-Math.min(...e),minLength:0};const Ma={skewness:e=>function(e){const t=Aa(e),r=ja(e);if(0===r)throw new Error("Standard deviation is zero, skewness is undefined");return e.reduce((e,r)=>e+(r-t)**3,0)/(e.length*r**3)}(e),minLength:3},Oa={"sample-skewness":e=>function(e){const t=e.length,r=e.reduce((e,t)=>e+t,0)/t;let n=0,o=0;for(const t of e){const e=t-r;n+=e*e,o+=e*e*e}const a=n/(t-1),i=Math.sqrt(a);if(0===i)throw new Error("Cannot calculate sample skewness when standard deviation is 0");return t/((t-1)*(t-2))*o/i**3}(e),minLength:3};function Va(e){const t=Aa(e),r=ja(e);if(0===r)throw new Error("Standard deviation is zero, kurtosis is undefined");return e.reduce((e,r)=>e+(r-t)**4,0)/(e.length*r**4)}const Da={kurtosis:e=>Va(e),minLength:4},Ua={"excess-kurtosis":e=>function(e){return Va(e)-3}(e),minLength:4},Fa={"sample-kurtosis":e=>function(e){const t=e.length,r=e.reduce((e,t)=>e+t,0)/t,n=e.reduce((e,t)=>e+(t-r)**2,0)/(t-1);if(0===n)throw new Error("Variance is zero, kurtosis is undefined");return t*(t+1)*e.reduce((e,t)=>e+(t-r)**4,0)/((t-1)*(t-2)*(t-3)*n**2)}(e),minLength:4},Wa={"sample-excess-kurtosis":e=>function(e){const t=e.length,r=e.reduce((e,t)=>e+t,0)/t,n=e.reduce((e,t)=>e+(t-r)**2,0)/(t-1);if(0===n)throw new Error("Variance is zero, kurtosis is undefined");return t*(t+1)*e.reduce((e,t)=>e+(t-r)**4,0)/((t-1)*(t-2)*(t-3)*n**2)-3*(t-1)*(t-1)/((t-2)*(t-3))}(e),minLength:4},Ga={rms:e=>Math.sqrt(e.reduce((e,t)=>e+t**2,0)/e.length)};const Ba={mad:e=>function(e){const t=$a(e);return e.reduce((e,r)=>e+Math.abs(r-t),0)/e.length}(e)};function La(e){const t=$a(e);return 1.4826*$a(e.map(e=>Math.abs(e-t)))}const _a={medad:e=>La(e)},Ka={"gini-coefficient":e=>{if(e.some(e=>e<0))throw new Error("Gini coefficient is not defined for negative values");const t=[...e].sort((e,t)=>e-t),r=t.length,n=t.reduce((e,t)=>e+t,0);if(0===n)return 0;return 2*t.reduce((e,t,r)=>e+(r+1)*t,0)/(r*n)-(r+1)/r},minLength:1};const Ja={entropy:e=>function(e){const t=new Map;for(const r of e)t.set(r,(t.get(r)||0)+1);const r=e.length;let n=0;for(const e of t.values()){const t=e/r;t>0&&(n-=t*Math.log2(t))}return n}(e),minLength:1},Ha={};function Ya(e){for(const[t,r]of Object.entries(e)){if(Ha[t])throw new Error(`Duplicate normal expression key found: ${t}`);if("minLength"!==t&&"padding"!==t&&"function"==typeof r){const n=r,o=t.replace(/^/,""),a=`moving-${o}`,i=`centered-moving-${o}`,s=`running-${o}`,l=e.minLength??1;Y(l,void 0,{integer:!0,finite:!0,gte:0}),Ha[t]=Xa(n,l),Ha[a]=Qa(n,l),Ha[i]=Za(n,l,e.padding??null),Ha[s]=ei(n,l)}}}function Xa(e,t){return{evaluate:([r],n)=>{if(Ce(r,n),r.length<t)throw new o(`Vector length must be at least ${t}`,n);try{return e(r)}catch(e){throw new o(e,n)}},arity:te(1)}}function Qa(e,t){return{evaluate:([r,n],a)=>{if(Ce(r,a),Y(n,a,{integer:!0,finite:!0,gte:t,lte:r.length}),0===r.length)return[];try{if(n>=r.length)return[e(r)];const t=[];for(let o=0;o<r.length-n+1;o+=1)t.push(e(r.slice(o,o+n)));return t}catch(e){throw new o(e,a)}},arity:te(2)}}function Za(e,t,r){return{evaluate:([n,a,i,s],l)=>{if(Ce(n,l),n.length<t)throw new o(`Vector length must be at least ${t}`,l);if(Y(a,l,{integer:!0,finite:!0,gte:t,lte:n.length}),null!==(i=i??r)&&Y(i,l,{finite:!0}),null!==(s=s??r)&&Y(s,l,{finite:!0}),0===n.length)return[];const c=Math.floor(a/2),u=[...Array(c).fill(i),...n,...Array(c).fill(s)],m="number"==typeof i?0:c,p=n.length-("number"==typeof s?0:a-c-1),d=[...Array(m).fill(null)];try{for(let t=m;t<p;t+=1)d.push(e(u.slice(t,t+a)))}catch(e){throw new o(e,l)}return d.push(...Array(n.length-p).fill(null)),d},arity:{min:2,max:4}}}function ei(e,t){return{evaluate:([r],n)=>{if(Ce(r,n),r.length<t)throw new o(`Vector length must be at least ${t}`,n);if(0===r.length)return[];try{const n=Math.max(t-1,0),o=Array(n).fill(null);for(let t=n;t<r.length;t+=1)o.push(e(r.slice(0,t+1)));return o}catch(e){throw new o(e,n)}},arity:te(1)}}Ya({mean:e=>Aa(e)}),Ya(Na),Ya({"harmonic-mean":e=>e.length/e.reduce((e,t)=>e+1/t,0)}),Ya(Ea),Ya({sum:e=>e.reduce((e,t)=>e+t,0),minLength:0}),Ya({prod:e=>e.reduce((e,t)=>e*t,1),padding:1,minLength:0}),Ya(Sa),Ya(za),Ya(Ca),Ya(Ia),Ya(Ra),Ya(Pa),Ya(Ma),Ya(Oa),Ya(Ua),Ya(Da),Ya(Wa),Ya(Fa),Ya(Ga),Ya(Ba),Ya(_a),Ya(Ka),Ya(Ja),delete Ha.sum,delete Ha.prod,delete Ha.mean,delete Ha.median;const ti={"monotonic?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>=e[r-1])||e.every((t,r)=>0===r||t<=e[r-1])),arity:te(1)},"strictly-monotonic?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>e[r-1])||e.every((t,r)=>0===r||t<e[r-1])),arity:te(1)},"increasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>=e[r-1])),arity:te(1)},"decreasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t<=e[r-1])),arity:te(1)},"strictly-increasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>e[r-1])),arity:te(1)},"strictly-decreasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t<e[r-1])),arity:te(1)},mode:{evaluate:([e],t)=>(Pe(e,t),function(e){const t=new Map;for(const r of e)t.set(r,(t.get(r)||0)+1);let r=0;for(const e of t.values())e>r&&(r=e);if(1===r)return e;const n=[];for(const[e,o]of t.entries())o===r&&n.push(e);return n}(e)),arity:te(1)},"min-index":{evaluate:([e],t)=>(Pe(e,t),e.reduce((t,r,n)=>r<e[t]?n:t,0)),arity:te(1)},"max-index":{evaluate:([e],t)=>(Pe(e,t),e.reduce((t,r,n)=>r>e[t]?n:t,0)),arity:te(1)},"sort-indices":{evaluate:([e],t)=>(Ce(e,t),[...e.keys()].sort((t,r)=>e[t]-e[r])),arity:te(1)},"count-values":{evaluate:([e],t)=>{Ce(e,t);const r=new Map;for(const t of e)r.set(t,(r.get(t)||0)+1);return[...r.entries()].sort((e,t)=>{const r=t[1]-e[1];return 0!==r?r:e[0]-t[0]})},arity:te(1)},linspace:{evaluate:([e,t,r],n)=>{if(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,nonNegative:!0}),0===r)return[];if(1===r)return[e];const o=(t-e)/(r-1);return Array.from({length:r},(t,r)=>e+r*o)},arity:te(3)},cumsum:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>{const r=e[e.length-1]??0;return e.push(r+t),e},[])),arity:te(1)},cumprod:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>{const r=e[e.length-1]??1;return e.push(r*t),e},[])),arity:te(1)},quartiles:{evaluate:([e],t)=>{if(Ce(e,t),e.length<4)throw new o("Quartiles require at least four values",t);return qa(e)},arity:te(1)},percentile:{evaluate:([e,t],r)=>(Pe(e,r),Y(t,r,{finite:!0,nonNegative:!0,lte:100}),ka(e,t)),arity:te(2)},quantile:{evaluate:([e,t],r)=>(Ce(e,r),Y(t,r,{finite:!0,nonNegative:!0,lte:1}),ka(e,100*t)),arity:te(2)},histogram:{evaluate:([e,t],r)=>(Ce(e,r),Y(t,r,{integer:!0,positive:!0}),function(e,t){if(0===e.length){const e=[];for(let r=0;r<t;r++)e.push([0,0,0]);return e}const r=Math.min(...e),n=Math.max(...e);if(r===n){const n=[];for(let e=0;e<t;e++)n.push([r,r,0]);return n[0][2]=e.length,n}const o=(n-r)/t,a=[];for(let e=0;e<t;e++){const i=r+e*o,s=e===t-1?n:r+(e+1)*o;a.push([i,s,0])}for(const i of e)i===n?a[t-1][2]+=1:a[Math.min(Math.floor((i-r)/o),t-1)][2]+=1;return a}(e,t)),arity:te(2)},ecdf:{evaluate:([e,t],r)=>{Pe(e,r),Y(t,r,{finite:!0});const n=[...e].sort((e,t)=>e-t),o=n.findIndex(e=>e>t);return-1===o?1:o/n.length},arity:te(2)},"outliers?":{evaluate:([e],t)=>(Ce(e,t),function(e){return xa(e).length>0}(e)),arity:te(1)},outliers:{evaluate:([e],t)=>(Ce(e,t),xa(e)),arity:te(1)},bincount:{evaluate:(e,t)=>{const r=e[0];Ce(r,t),r.forEach(e=>Y(e,t,{finite:!0,integer:!0,nonNegative:!0}));const n=e[1]??0;Y(n,t,{integer:!0,nonNegative:!0});const a=e[2]??void 0;if(void 0!==a){if(Ce(a,t),a.length!==r.length)throw new o("Weights vector must be the same length as the input vector",t);a.forEach(e=>Y(e,t,{finite:!0}))}return function(e,t=0,r){if(0===e.length)return Array.from({length:t},()=>0);const n=Math.max(...e),o=Math.max(n+1,t),a=Array.from({length:o},()=>0);for(let t=0;t<e.length;t++){const n=Math.floor(e[t]);n<o&&(a[n]+=r?r[t]:1)}return a}(r,n,a)},arity:{min:1,max:3}},winsorize:{evaluate:([e,t,r],n)=>{if(Ce(e,n),Y(t,n,{finite:!0,gte:0,lte:1}),r??=t>.5?1:1-t,Y(r,n,{finite:!0,gte:t,lte:1}),0===e.length)return[];const o=[...e].sort((e,t)=>e-t),a=Math.max(0,Math.floor(t*e.length)),i=Math.min(e.length-1,Math.max(0,Math.floor(r*e.length)-1)),s=o[a],l=o[i];return e.map(e=>Math.max(s,Math.min(e,l)))},arity:{min:2,max:3}},mse:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+(r-t[n])**2,0)/e.length},arity:te(2)},rmse:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return Math.sqrt(e.reduce((e,r,n)=>e+(r-t[n])**2,0)/e.length)},arity:te(2)},mae:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+Math.abs(r-t[n]),0)/e.length},arity:te(2)},smape:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>{const o=Math.abs(r-t[n]),a=(Math.abs(r)+Math.abs(t[n]))/2;return e+(0===a?0:o/a)},0)/e.length},arity:te(2)}};!function(e){for(const[t,r]of Object.entries(e)){if(ti[t])throw new Error(`Duplicate normal expression key found: ${t}`);ti[t]=r}}(Ha);for(const[e,t]of Object.entries(wa))ti[e]&&(ti[e].docs=t);const ri={name:"vector",functions:ti,source:"{}",docs:wa},ni={reflect:{category:"linear-algebra",description:"Reflects a vector across a given axis.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to reflect."},b:{type:"vector",description:"Axis of reflection."}},variants:[{argumentNames:["a","b"]}],examples:["let { reflect } = import(linear-algebra);\nreflect([1, 2], [0, 1])","let { reflect } = import(linear-algebra);\nreflect([1, 2, 3], [0, 0, 1])"],seeAlso:["linear-algebra.refract","linear-algebra.projection"]},refract:{category:"linear-algebra",description:"Refracts a vector across a given axis.",returns:{type:"vector"},args:{vector:{type:"vector",description:"Vector to refract."},axis:{type:"vector",description:"Axis of refraction."},eta:{type:"number",description:"Refraction index."}},variants:[{argumentNames:["vector","axis","eta"]}],examples:["let { refract } = import(linear-algebra);\nrefract([1, 2], [0, 1], 1.5)","let { refract } = import(linear-algebra);\nrefract([1, 2, 3], [0, 0, 1], 1.5)"],seeAlso:["linear-algebra.reflect"]},lerp:{category:"linear-algebra",description:"Performs linear interpolation between two vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"Start vector."},b:{type:"vector",description:"End vector."},t:{type:"number",description:"Interpolation factor (0 to 1)."}},variants:[{argumentNames:["a","b","t"]}],examples:["let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 0.5)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 2)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], -1)","let { lerp } = import(linear-algebra);\nlerp([1, 2, 3], [4, 5, 6], 0.25)"],seeAlso:["linear-algebra.projection"]},rotate2d:{category:"linear-algebra",description:"Rotates a 2D vector by a given angle in radians.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to rotate."},b:{type:"number",description:"Angle in b."}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate2d } = import(linear-algebra);\nrotate2d([1, 0], PI / 2)","let { rotate2d } = import(linear-algebra);\nrotate2d([0, 1], PI)"],seeAlso:["linear-algebra.rotate3d","linear-algebra.angle"]},rotate3d:{category:"linear-algebra",description:"Rotates a 3D vector around a given axis by a given angle in radians.",returns:{type:"vector"},args:{v:{type:"vector",description:"Vector to rotate."},axis:{type:"vector",description:"Axis of rotation."},radians:{type:"number",description:"Angle in radians."}},variants:[{argumentNames:["v","axis","radians"]}],examples:["let { rotate3d } = import(linear-algebra);\nrotate3d([1, 0, 0], [0, 1, 0], PI / 2)","let { rotate3d } = import(linear-algebra);\nrotate3d([0, 1, 0], [1, 0, 0], PI)"],seeAlso:["linear-algebra.rotate2d","linear-algebra.angle"]},dot:{category:"linear-algebra",description:"Calculates the dot product of two vectors. The result is a scalar.",returns:{type:"number"},args:{a:{type:"vector",description:"First vector."},b:{type:"vector",description:"Second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { dot } = import(linear-algebra);\ndot([1, 2], [3, 4])","let { dot } = import(linear-algebra);\ndot([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.cross","linear-algebra.cosine-similarity","linear-algebra.angle","linear-algebra.projection","linear-algebra.orthogonal?"]},cross:{category:"linear-algebra",description:"Calculates the cross product of two 3D vectors. The result is a vector perpendicular to both input vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"First vector (3D)."},b:{type:"vector",description:"Second vector (3D)."}},variants:[{argumentNames:["a","b"]}],examples:["let { cross } = import(linear-algebra);\ncross([1, 2, 3], [4, 5, 6])","let { cross } = import(linear-algebra);\ncross([1, 0, 0], [0, 1, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 1], [1, 0, 0])","let { cross } = import(linear-algebra);\ncross([1, 2, 3], [0, 0, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 0], [1, 2, 3])"],seeAlso:["linear-algebra.dot"]},"normalize-minmax":{category:"linear-algebra",description:"Normalizes the vector using min-max normalization. The result is a vector with values between 0 and 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-zscore","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-zscore":{category:"linear-algebra",description:"Normalizes the vector using z-score normalization. The result is a vector with mean 0 and standard deviation 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-robust":{category:"linear-algebra",description:"Normalizes the vector using robust normalization. The result is a vector with median 0 and median absolute deviation 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},"normalize-l1":{category:"linear-algebra",description:"Normalizes the vector using L1 normalization. The result is a vector with L1 norm equal to 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l2","linear-algebra.normalize-minmax","linear-algebra.manhattan-norm","linear-algebra.normalize-zscore"]},"normalize-l2":{category:"linear-algebra",description:"Normalizes the vector using L2 normalization. The result is a vector with L2 norm equal to 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l1","linear-algebra.normalize-minmax","linear-algebra.euclidean-norm","linear-algebra.normalize-zscore"]},"normalize-log":{category:"linear-algebra",description:"Normalizes the vector using natural log normalization. The result is a vector with log-transformed values.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 4])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},angle:{category:"linear-algebra",description:"Calculates the **angle** between two vectors in radians.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { angle } = import(linear-algebra);\nangle([1, 0], [0, 1])","let { angle } = import(linear-algebra);\nangle([1, 0, 1], [0, 1, 0])"],seeAlso:["linear-algebra.dot","linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.rotate2d","linear-algebra.rotate3d","linear-algebra.parallel?","linear-algebra.cosine-similarity","linear-algebra.to-polar"]},projection:{category:"linear-algebra",description:"Calculates the **projection** of vector `a` onto vector `b`.",returns:{type:"vector"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { projection } = import(linear-algebra);\nprojection([1, 2], [3, 4])","let { projection } = import(linear-algebra);\nprojection([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.dot","linear-algebra.reflect","linear-algebra.lerp"]},"collinear?":{category:"linear-algebra",description:"Checks if two vectors are **collinear**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [2, 4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [-2, -4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2, 3], [2, 4, 6])"],seeAlso:["linear-algebra.parallel?","linear-algebra.orthogonal?","linear-algebra.angle"]},"parallel?":{category:"linear-algebra",description:"Checks if two vectors are **parallel**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [2, 4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [-2, -4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2, 3], [2, 4, 6])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [3, 4])"],seeAlso:["linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.angle"]},"orthogonal?":{category:"linear-algebra",description:"Checks if two vectors are **orthogonal**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0], [0, 1])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0, 1], [0, 1, 0])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 2], [2, -1])"],seeAlso:["linear-algebra.collinear?","linear-algebra.parallel?","linear-algebra.dot","matrix.orthogonal-matrix?","linear-algebra.angle"]},"cosine-similarity":{category:"linear-algebra",description:"Calculates the **cosine similarity** between two vectors. The result is a value between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2], [3, 4])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2, 3], [4, 5, 6])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 0], [0, 1])"],seeAlso:["linear-algebra.dot","linear-algebra.angle","linear-algebra.euclidean-distance"]},"euclidean-distance":{category:"linear-algebra",description:"Calculates the **Euclidean distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2], [3, 4])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2, 3], [4, 5, 6])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.euclidean-norm","linear-algebra.cosine-similarity","linear-algebra.hamming-distance"]},"euclidean-norm":{category:"linear-algebra",description:"Calculates the **Euclidean norm** (L2 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([3, 4])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2, 3])"],seeAlso:["linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.euclidean-distance","linear-algebra.normalize-l2","linear-algebra.hamming-norm"]},"manhattan-distance":{category:"linear-algebra",description:"Calculates the **Manhattan distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2], [3, 4])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2, 3], [4, 5, 6])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"manhattan-norm":{category:"linear-algebra",description:"Calculates the **Manhattan norm** (L1 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([3, 4])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.manhattan-distance","linear-algebra.normalize-l1","linear-algebra.hamming-norm"]},"hamming-distance":{category:"linear-algebra",description:"Calculates the **Hamming distance** between two vectors. The result is a non-negative integer.",returns:{type:"integer"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2], [3, 4])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2, 3], [4, 5, 6])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.hamming-norm"]},"hamming-norm":{category:"linear-algebra",description:"Calculates the **Hamming norm** of a vector. The result is a non-negative integer.",returns:{type:"integer"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([3, 4])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"chebyshev-distance":{category:"linear-algebra",description:"Calculates the **Chebyshev distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2], [3, 4])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2, 3], [4, 5, 6])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.minkowski-distance","linear-algebra.chebyshev-norm"]},"chebyshev-norm":{category:"linear-algebra",description:"Calculates the **Chebyshev norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([3, 4])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.minkowski-norm","linear-algebra.chebyshev-distance"]},"minkowski-distance":{category:"linear-algebra",description:"Calculates the **Minkowski distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"},p:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b","p"]}],examples:["let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2], [3, 4], 2)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2, 3], [4, 5, 6], 3)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 0], [0, 1], 1)"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-norm"]},"minkowski-norm":{category:"linear-algebra",description:"Calculates the **Minkowski norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector",description:"Vector to calculate the norm for."},b:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b"]}],examples:["let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2], 2)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([3, 4], 3)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2, 3], 4)"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-distance"]},cov:{category:"linear-algebra",description:"Calculates the **covariance** between two vectors. The result is a number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cov } = import(linear-algebra);\ncov([1, 2], [3, 4])","let { cov } = import(linear-algebra);\ncov([1, 2, 3], [4, 5, 6])","let { cov } = import(linear-algebra);\ncov([1, 0], [0, 1])"],seeAlso:["linear-algebra.corr","linear-algebra.pearson-corr","vector.variance"]},corr:{category:"linear-algebra",description:"Calculates the **correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { corr } = import(linear-algebra);\ncorr([1, 2], [3, 4])","let { corr } = import(linear-algebra);\ncorr([1, 2, 3], [4, 5, 6])","let { corr } = import(linear-algebra);\ncorr([1, 0], [0, 1])"],seeAlso:["linear-algebra.cov","linear-algebra.pearson-corr","linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.autocorrelation","linear-algebra.cross-correlation"]},"spearman-corr":{category:"linear-algebra",description:"Calculates the **Spearman rank correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2], [3, 4])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2, 3], [4, 5, 6])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.pearson-corr","linear-algebra.kendall-tau","linear-algebra.corr"]},"pearson-corr":{category:"linear-algebra",description:"Calculates the **Pearson correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2], [3, 4])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2, 3], [4, 5, 6])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.corr","linear-algebra.cov"]},"kendall-tau":{category:"linear-algebra",description:"Calculates the **Kendall Tau** rank correlation coefficient between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2], [3, 4])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2, 3], [4, 5, 6])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.pearson-corr","linear-algebra.corr"]},autocorrelation:{category:"linear-algebra",description:"Calculates the **autocorrelation** of a vector. The result is a vector of autocorrelation coefficients.",returns:{type:"number"},args:{a:{type:"vector",description:"Vector to calculate the autocorrelation for."},b:{type:"integer",description:"Lag value for the autocorrelation."}},variants:[{argumentNames:["a","b"]}],examples:["let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -2)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 0)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 2)"],seeAlso:["linear-algebra.cross-correlation","linear-algebra.corr"]},"cross-correlation":{category:"linear-algebra",description:"Calculates the **cross-correlation** between two vectors. The result is a vector of cross-correlation coefficients.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"},lag:{type:"integer",description:"Lag value for the cross-correlation."}},variants:[{argumentNames:["a","b","lag"]}],examples:["let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -2)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 0)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 2)"],seeAlso:["linear-algebra.autocorrelation","linear-algebra.corr"]},rref:{category:"linear-algebra",description:"Calculates the **Reduced Row Echelon Form** (RREF) of a matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"Matrix to calculate the RREF for."}},variants:[{argumentNames:["m"]}],examples:["let { rref } = import(linear-algebra);\nrref([[1, 2], [3, 4]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [7, 8, 9], [4, 5, 7]])"],seeAlso:["linear-algebra.solve","matrix.rank"]},solve:{category:"linear-algebra",description:"Solves a system of linear equations represented by a matrix and a vector.",returns:{type:"vector"},args:{a:{type:"matrix"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { solve } = import(linear-algebra);\nsolve([\n [2, 1, -1, 1], \n [4, 5, -3, 2], \n [6, -2, 5, -3], \n [8, 3, 2, 4]\n], [5, 10, 2, 17])","let { solve } = import(linear-algebra);\nsolve([[2, 0, 0], [3, 1, 0], [4, 5, 6]], [4, 5, 38])","let { solve } = import(linear-algebra);\nsolve([[2, 3], [1, -1]], [8, 2])"],seeAlso:["linear-algebra.rref","matrix.inv"]},"to-polar":{category:"linear-algebra",description:"Converts a 2D vector to polar coordinates.",returns:{type:"vector"},args:{vector:{type:"vector",description:"2D Vector to convert."}},variants:[{argumentNames:["vector"]}],examples:["let { to-polar } = import(linear-algebra);\nto-polar([1, 2])","let { to-polar } = import(linear-algebra);\nto-polar([3, 4])"],seeAlso:["linear-algebra.from-polar","linear-algebra.angle"]},"from-polar":{category:"linear-algebra",description:"Converts polar coordinates to a 2D vector.",returns:{type:"vector"},args:{polar:{type:"vector",description:"Polar coordinates to convert."}},variants:[{argumentNames:["polar"]}],examples:["let { from-polar } = import(linear-algebra);\nfrom-polar([1, PI / 4])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, 0])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, -PI / 2])"],seeAlso:["linear-algebra.to-polar"]}};function oi(e){const t=e.map(e=>[...e]),r=t.length,n=t[0].length;let o=0,a=0;for(let e=0;e<n;e++){let i=-1;for(let n=a;n<r;n++)if(!ge(t[n][e])){i=n;break}if(-1===i)continue;o+=1,i!==a&&([t[i],t[a]]=[t[a],t[i]]);const s=t[a][e];for(let r=e;r<n;r++)t[a][r]/=s;for(let o=0;o<r;o++)if(o!==a&&!ge(t[o][e])){const r=t[o][e];for(let i=e;i<n;i++)t[o][i]-=r*t[a][i]}if(a++,a===r)break}return[t,o]}function ai(e,t){const r=e=>e.every(e=>ge(e));if(r(e)||r(t))return!0;let n=0;for(;n<e.length&&ge(e[n]);)n++;const o=t[n]/e[n];for(let r=0;r<e.length;r++)if(!ge(e[r])||!ge(t[r])){if(ge(e[r]))return!1;if(!he(t[r]/e[r],o))return!1}return!0}function ii(e){return e.every(e=>ge(e))}function si(e,t){const r=Aa(e),n=Aa(t);let o=0,a=0,i=0;for(let s=0;s<e.length;s++){const l=e[s]-r,c=t[s]-n;o+=l*c,a+=l*l,i+=c*c}if(0===a||0===i)throw new Error("Cannot calculate Pearson correlation coefficient: one of the vectors has zero variance.");return o/(Math.sqrt(a)*Math.sqrt(i))}function li(e){const t=[...e.keys()].sort((t,r)=>e[t]-e[r]),r=Array.from({length:e.length}).fill(0);let n=1,o=0;for(;o<t.length;){const a=e[t[o]];let i=o;for(;i<t.length&&e[t[i]]===a;)i++;const s=n+(i-o-1)/2;for(let e=o;e<i;e++)r[t[e]]=s;n+=i-o,o=i}return r}function ci(e,t){const r=Aa(e),n=Aa(t);let o=0;for(let a=0;a<e.length;a++)o+=(e[a]-r)*(t[a]-n);return o/e.length}function ui(e,t){if(0===e.length)return e;const r=Math.sqrt(e.reduce((e,t)=>e+t**2,0));if(ge(r))throw new o("The vector must not be zero",t);return e.map(e=>e/r)}function mi(e,t){return e.reduce((e,r,n)=>e+r*t[n],0)}function pi(e,t){return e.map((e,r)=>e-t[r])}function di(e,t){return e.map(e=>e*t)}const hi={rotate2d:{evaluate:([e,t],r)=>{if(Ie(e,r),ii(e))return e;Y(t,r,{finite:!0});const n=Math.cos(t),o=Math.sin(t);return[e[0]*n-e[1]*o,e[0]*o+e[1]*n]},arity:te(2)},rotate3d:{evaluate:([e,t,r],n)=>{if(Re(e,n),ii(e))return e;if(Y(r,n,{finite:!0}),Re(t,n),ii(t))throw new o("Rotation axis must not be zero",n);const a=Math.cos(r),i=Math.sin(r),[s,l,c]=ui(t,n),u=e[0]*s+e[1]*l+e[2]*c;return[u*s*(1-a)+e[0]*a+(-c*e[1]+l*e[2])*i,u*l*(1-a)+e[1]*a+(c*e[0]-s*e[2])*i,u*c*(1-a)+e[2]*a+(-l*e[0]+s*e[1])*i]},arity:te(3)},reflect:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);if(ii(t))throw new o("Reflection normal must not be zero",r);if(ii(e))return e;const n=ui(t,r);return pi(e,di(n,2*mi(e,n)))},arity:te(2)},refract:{evaluate:([e,t,r],n)=>{if(Ce(e,n),Ce(t,n),Y(r,n,{finite:!0,positive:!0}),e.length!==t.length)throw new o("Vectors must be of the same length",n);if(ii(t))throw new o("Refraction normal must not be zero",n);if(ii(e))return e;const a=ui(e,n),i=ui(t,n),s=mi(a,i),l=1-r*r*(1-s*s);if(l<0)return e;return pi(di(a,r),di(i,r*s+Math.sqrt(l)))},arity:te(3)},lerp:{evaluate:([e,t,r],n)=>{if(Ce(e,n),Ce(t,n),Y(r,n,{finite:!0}),e.length!==t.length)throw new o("Vectors must be of the same length",n);return e.map((e,n)=>e+(t[n]-e)*r)},arity:te(3)},dot:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return mi(e,t)},arity:te(2)},cross:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),3!==e.length||3!==t.length)throw new o("Cross product is only defined for 3D vectors",r);return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]},arity:te(2)},"normalize-minmax":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=e.reduce((e,t)=>t<e?t:e,e[0]),n=e.reduce((e,t)=>t>e?t:e,e[0]);return r===n?e.map(()=>0):e.map(e=>(e-r)/(n-r))},arity:te(1)},"normalize-robust":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=$a(e),n=La(e);return 0===n?e.map(e=>e-r):e.map(e=>(e-r)/n)},arity:te(1)},"normalize-zscore":{evaluate:([e],t)=>{Ce(e,t);const r=Aa(e),n=ja(e);return 0===n?e.map(()=>0):e.map(e=>(e-r)/n)},arity:te(1)},"normalize-l1":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=e.reduce((e,t)=>e+Math.abs(t),0);return 0===r?e.map(()=>0):e.map(e=>e/r)},arity:te(1)},"normalize-l2":{evaluate:([e],t)=>(Ce(e,t),ui(e,t)),arity:te(1)},"normalize-log":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=Math.min(...e);if(r<=0)throw new o("Log normalization requires all values to be positive",t);return e.map(e=>Math.log(e/r))},arity:te(1)},angle:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),ii(e)||ii(t))throw new o("Cannot calculate angle with zero-length vector",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=e.reduce((e,r,n)=>e+r*t[n],0),a=Math.sqrt(e.reduce((e,t)=>e+t*t,0)),i=Math.sqrt(t.reduce((e,t)=>e+t*t,0));return Math.acos(n/(a*i))},arity:te(2)},projection:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),ii(t))throw new o("Cannot project onto zero-length vector",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=e.reduce((e,r,n)=>e+r*t[n],0),a=Math.sqrt(t.reduce((e,t)=>e+t*t,0));return t.map(e=>n/a**2*e)},arity:te(2)},"orthogonal?":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return 0===e.reduce((e,r,n)=>e+r*t[n],0)},arity:te(2)},"parallel?":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return function(e,t){if(!ai(e,t))return!1;for(let r=0;r<e.length;r++)if(!ge(e[r])&&!ge(t[r]))return Math.sign(e[r])===Math.sign(t[r]);return!0}(e,t)},arity:te(2)},"collinear?":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return ai(e,t)},arity:te(2)},"cosine-similarity":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),ii(e)||ii(t))throw new o("Cannot calculate cosine similarity with zero-length vector",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+r*t[n],0)/(Math.sqrt(e.reduce((e,t)=>e+t*t,0))*Math.sqrt(t.reduce((e,t)=>e+t*t,0)))},arity:te(2)},"euclidean-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return Math.sqrt(e.reduce((e,r,n)=>e+(r-t[n])**2,0))},arity:te(2)},"euclidean-norm":{evaluate:([e],t)=>(Pe(e,t),function(e){return Math.sqrt(e.reduce((e,t)=>e+t**2,0))}(e)),arity:te(1)},"manhattan-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+Math.abs(r-t[n]),0)},arity:te(2)},"manhattan-norm":{evaluate:([e],t)=>(Pe(e,t),e.reduce((e,t)=>e+Math.abs(t),0)),arity:te(1)},"hamming-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+(r!==t[n]?1:0),0)},arity:te(2)},"hamming-norm":{evaluate:([e],t)=>(Pe(e,t),e.reduce((e,t)=>e+(0!==t?1:0),0)),arity:te(1)},"chebyshev-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return Math.max(...e.map((e,r)=>Math.abs(e-t[r])))},arity:te(2)},"chebyshev-norm":{evaluate:([e],t)=>(Pe(e,t),Math.max(...e.map(e=>Math.abs(e)))),arity:te(1)},"minkowski-distance":{evaluate:([e,t,r],n)=>{if(Pe(e,n),Pe(t,n),Y(r,n,{finite:!0,positive:!0}),e.length!==t.length)throw new o("Vectors must be of the same length",n);return e.reduce((e,n,o)=>e+Math.abs(n-t[o])**r,0)**(1/r)},arity:te(3)},"minkowski-norm":{evaluate:([e,t],r)=>(Pe(e,r),Y(t,r,{finite:!0,positive:!0}),e.reduce((e,r)=>e+Math.abs(r)**t,0)**(1/t)),arity:te(2)},cov:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return 1===e.length?0:ci(e,t)},arity:te(2)},corr:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<=1)throw new o("Vectors must have at least 2 elements for corr",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=Aa(e),a=Aa(t);return e.reduce((e,r,o)=>e+(r-n)*(t[o]-a),0)/Math.sqrt(e.reduce((e,t)=>e+(t-n)**2,0)*t.reduce((e,t)=>e+(t-a)**2,0))},arity:te(2)},"spearman-corr":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<=1)throw new o("Vectors must have at least 2 elements for corr",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=li(e),a=li(t);try{return si(n,a)}catch(e){throw new o(e,r)}},arity:te(2)},"pearson-corr":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<=1)throw new o("Vectors must have at least 2 elements for pearson-corr",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);try{return si(e,t)}catch(e){throw new o(e,r)}},arity:te(2)},"kendall-tau":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<2)throw new o("Vectors must have at least 2 elements for kendall-tau",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);try{return function(e,t,r=1e-10){let n=0,o=0,a=0,i=0;for(let s=0;s<e.length;s++)for(let l=s+1;l<e.length;l++){const c=e[s]-e[l],u=t[s]-t[l],m=Math.abs(c)<r,p=Math.abs(u)<r;m&&p||(m?a+=1:p?i+=1:c*u>0?n+=1:o+=1)}const s=n+o+a,l=n+o+i;if(0===s||0===l)throw new Error("Not enough data to calculate Kendall's Tau");return(n-o)/Math.sqrt(s*l)}(e,t)}catch(e){throw new o(e,r)}},arity:te(2)},autocorrelation:{evaluate:([e,t],r)=>{if(Ce(e,r),e.length<2)throw new o("Vector must have at least 2 elements for autocorrelation",r);if(Y(t,r,{integer:!0,lt:e.length,gt:-e.length}),0===t)return 1;const n=Math.abs(t),a=Aa(e);let i=0;const s=e.length;for(let r=0;r<s-n;r++){const o=t<0?r:r+n;i+=(e[t<0?r+n:r]-a)*(e[o]-a)}let l=0;for(let t=0;t<s;t++)l+=(e[t]-a)**2;return 0===l?0:i/l},arity:te(2)},"cross-correlation":{evaluate:([e,t,r],n)=>{if(Ce(e,n),Ce(t,n),e.length<2)throw new o("Vectors must have at least 2 elements",n);if(e.length!==t.length)throw new o("Vectors must be of the same length",n);if(Y(r,n,{integer:!0,lt:e.length,gt:-e.length}),0===r&&e.length===t.length&&e.every((e,r)=>e===t[r]))return 1;const[a,i]=function(e,t,r){const n=Math.abs(r),o=e.length-n;let a=[],i=[];return r>=0?(a=e.slice(0,o),i=t.slice(r,r+o)):(a=e.slice(n),i=t.slice(0,o)),[a,i]}(e,t,r);return function(e,t){const r=Aa(e),n=Aa(t),o=ja(e,r),a=ja(t,n);return 0===o||0===a?0===o&&0===a&&r===n?1:0:ci(e,t)/(o*a)}(a,i)},arity:te(3)},rref:{evaluate:([e],t)=>{De(e,t);const[r]=oi(e);return r},arity:te(1)},solve:{evaluate:([e,t],r)=>{if(Ue(e,r),Ce(t,r),e.length!==t.length)throw new o(`The number of rows in the matrix must be equal to the length of the vector, but got ${e.length} and ${t.length}`,r);return function(e,t){const r=e.length,n=e.map((e,r)=>[...e,t[r]]),[o]=oi(n);for(let e=0;e<r;e+=1)if(ge(o[e][e]))return null;const a=Array.from({length:r},()=>0);for(let e=r-1;e>=0;e--){let t=0;for(let n=e+1;n<r;n++)t+=o[e][n]*a[n];a[e]=(o[e][r]-t)/o[e][e]}return a}(e,t)},arity:te(2)},"to-polar":{evaluate:([e],t)=>{if(Ie(e,t),ii(e))return[0,0];return[Math.sqrt(e[0]**2+e[1]**2),Math.atan2(e[1],e[0])]},arity:te(1)},"from-polar":{evaluate:([e],t)=>{Ie(e,t);const[r,n]=e;return 0===r?[0,0]:[r*Math.cos(n),r*Math.sin(n)]},arity:te(1)}};for(const[e,t]of Object.entries(ni))hi[e]&&(hi[e].docs=t);const gi={name:"linear-algebra",functions:hi,source:"{}",docs:ni},fi={mul:{category:"matrix",description:"Multiplies two `matrices` using standard `matrix` multiplication based on **dot products** of rows and columns.",returns:{type:"matrix"},args:{a:{type:"matrix"},b:{type:"matrix"}},variants:[{argumentNames:["a","b"]}],examples:["let { mul } = import(matrix);\nmul([[1, 2], [3, 4]], [[5, 6], [7, 8]])","let { mul } = import(matrix);\nmul([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]])"],seeAlso:["matrix.det","matrix.inv"]},det:{category:"matrix",description:"Calculates the **determinant** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the determinant of."}},variants:[{argumentNames:["m"]}],examples:["let { det } = import(matrix);\ndet([[1, 2], [3, 4]])","let { det } = import(matrix);\ndet([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.inv","matrix.cofactor","matrix.adj","matrix.trace","matrix.rank","matrix.invertible?","matrix.mul","matrix.minor"]},inv:{category:"matrix",description:"Calculates the **inverse** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the inverse of."}},variants:[{argumentNames:["m"]}],examples:["let { inv } = import(matrix);\ninv([[1, 2], [3, 4]])","let { inv } = import(matrix);\ninv([[1, 2, 3], [4, 5, 7], [7, 8, 10]])"],seeAlso:["matrix.det","matrix.adj","matrix.invertible?","linear-algebra.solve","matrix.mul","matrix.orthogonal-matrix?"]},adj:{category:"matrix",description:"Calculates the **adjugate** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the adjugate of."}},variants:[{argumentNames:["m"]}],examples:["let { adj } = import(matrix);\nadj([[1, 2], [3, 4]])","let { adj } = import(matrix);\nadj([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { adj } = import(matrix);\nadj([[1, 2, 3], [7, 8, 9], [4, 5, 6]])"],seeAlso:["matrix.cofactor","matrix.det","matrix.inv"]},cofactor:{category:"matrix",description:"Calculates the **cofactor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the cofactor of."}},variants:[{argumentNames:["m"]}],examples:["let { cofactor } = import(matrix);\ncofactor([[1, 2], [3, 4]])","let { cofactor } = import(matrix);\ncofactor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { cofactor } = import(matrix);\ncofactor([[1, 2, 3], [7, 8, 9], [4, 5, 6]])"],seeAlso:["matrix.adj","matrix.minor","matrix.det"]},minor:{category:"matrix",description:"Calculates the **minor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the minor of."},row:{type:"integer",description:"The row index of the element to calculate the minor for."},col:{type:"integer",description:"The column index of the element to calculate the minor for."}},variants:[{argumentNames:["m","row","col"]}],examples:["let { minor } = import(matrix);\nminor([[1, 2], [3, 4]], 0, 1)","let { minor } = import(matrix);\nminor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1)"],seeAlso:["matrix.cofactor","matrix.det"]},trace:{category:"matrix",description:"Calculates the **trace** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the trace of."}},variants:[{argumentNames:["m"]}],examples:["let { trace } = import(matrix);\ntrace([[1, 2], [3, 4]])","let { trace } = import(matrix);\ntrace([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.det","matrix.diagonal?"]},"symmetric?":{category:"matrix",description:"Checks if a `matrix` is **symmetric**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for symmetry."}},variants:[{argumentNames:["m"]}],examples:["let { symmetric? } = import(matrix);\nsymmetric?([[1, 2], [2, 1]])","let { symmetric? } = import(matrix);\nsymmetric?([[1, 2, 3], [2, 1, 4], [3, 4, 1]])"],seeAlso:["matrix.orthogonal-matrix?","matrix.diagonal?","matrix.square?","matrix.hilbert"]},"triangular?":{category:"matrix",description:"Checks if a `matrix` is **triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { triangular? } = import(matrix);\ntriangular?([[2, 0], [0, 1]])","let { triangular? } = import(matrix);\ntriangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])"],seeAlso:["matrix.upper-triangular?","matrix.lower-triangular?","matrix.diagonal?","matrix.banded?"]},"upper-triangular?":{category:"matrix",description:"Checks if a `matrix` is **upper triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for upper triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { upper-triangular? } = import(matrix);\nupper-triangular?([[1, 2], [0, 3]])","let { upper-triangular? } = import(matrix);\nupper-triangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])"],seeAlso:["matrix.lower-triangular?","matrix.triangular?","matrix.diagonal?"]},"lower-triangular?":{category:"matrix",description:"Checks if a `matrix` is **lower triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for lower triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { lower-triangular? } = import(matrix);\nlower-triangular?([[1, 0], [2, 3]])","let { lower-triangular? } = import(matrix);\nlower-triangular?([[1, 0, 0], [2, 3, 0], [4, 5, 6]])"],seeAlso:["matrix.upper-triangular?","matrix.triangular?","matrix.diagonal?"]},"diagonal?":{category:"matrix",description:"Checks if a `matrix` is **diagonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for diagonal property."}},variants:[{argumentNames:["m"]}],examples:["let { diagonal? } = import(matrix);\ndiagonal?([[1, 0], [0, 2]])","let { diagonal? } = import(matrix);\ndiagonal?([[1, 0, 0], [0, 2, 0], [0, 0, 3]])","let { diagonal? } = import(matrix);\ndiagonal?([[1, 0, 0], [2, 2, 2], [0, 0, 3]])"],seeAlso:["matrix.identity?","matrix.symmetric?","matrix.triangular?","matrix.trace","matrix.upper-triangular?","matrix.lower-triangular?","matrix.band","matrix.banded?"]},"square?":{category:"matrix",description:"Checks if a `matrix` is **square**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for square property."}},variants:[{argumentNames:["m"]}],examples:["let { square? } = import(matrix);\nsquare?([[1, 2], [3, 4]])","let { square? } = import(matrix);\nsquare?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { square? } = import(matrix);\nsquare?([[1, 2, 3], [4, 5, 6]])"],seeAlso:["matrix.symmetric?","matrix.identity?","matrix.invertible?"]},"orthogonal-matrix?":{category:"matrix",description:"Checks if a `matrix` is **orthogonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **orthogonality**."}},variants:[{argumentNames:["m"]}],examples:["let { orthogonal-matrix? } = import(matrix);\northogonal-matrix?([[1, 0], [0, 1]])","let { orthogonal-matrix? } = import(matrix);\northogonal-matrix?([[1, 0], [0, -1]])","let { orthogonal-matrix? } = import(matrix);\northogonal-matrix?([[1, 2], [3, 4]])"],seeAlso:["matrix.symmetric?","matrix.inv","matrix.identity?","linear-algebra.orthogonal?"]},"identity?":{category:"matrix",description:"Checks if a `matrix` is an **identity matrix**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for identity property."}},variants:[{argumentNames:["m"]}],examples:["let { identity? } = import(matrix);\nidentity?([[1, 0], [0, 1]])","let { identity? } = import(matrix);\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 1]])","let { identity? } = import(matrix);\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 0]])"],seeAlso:["matrix.diagonal?","matrix.square?","matrix.orthogonal-matrix?"]},"invertible?":{category:"matrix",description:"Checks if a `matrix` is **invertible**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for invertibility."}},variants:[{argumentNames:["m"]}],examples:["let { invertible? } = import(matrix);\ninvertible?([[1, 2], [3, 4]])","let { invertible? } = import(matrix);\ninvertible?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { invertible? } = import(matrix);\ninvertible?([[1, 2], [2, 4]])"],seeAlso:["matrix.det","matrix.inv","matrix.rank","matrix.square?"]},hilbert:{category:"matrix",description:"Generates a **Hilbert matrix** of size `n`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the Hilbert matrix."}},variants:[{argumentNames:["n"]}],examples:["let { hilbert } = import(matrix);\nhilbert(3)","let { hilbert } = import(matrix);\nhilbert(4)"],seeAlso:["matrix.vandermonde","matrix.symmetric?"]},vandermonde:{category:"matrix",description:"Generates a **Vandermonde matrix** from a vector.",returns:{type:"matrix"},args:{v:{type:"vector",description:"The vector to generate the Vandermonde matrix from."}},variants:[{argumentNames:["v"]}],examples:["let { vandermonde } = import(matrix);\nvandermonde([1, 2, 3])","let { vandermonde } = import(matrix);\nvandermonde([1, 0, 1])"],seeAlso:["matrix.hilbert","matrix.band"]},band:{category:"matrix",description:"Generates a **banded matrix** of size `n` with lower band index `lband` and upper band index `uband`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the banded matrix."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["n","lband","uband"]}],examples:["let { band } = import(matrix);\nband(3, 1, 1)","let { band } = import(matrix);\nband(4, 1, 2)"],seeAlso:["matrix.banded?","matrix.diagonal?","matrix.vandermonde"]},"banded?":{category:"matrix",description:"Checks if a `matrix` is **banded** with lower band index `lband` and upper band index `uband`.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **banded** property."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["m","lband","uband"]}],examples:["let { banded? } = import(matrix);\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 2, 2)","let { banded? } = import(matrix);\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 1, 1)"],seeAlso:["matrix.band","matrix.triangular?","matrix.diagonal?"]},rank:{category:"matrix",description:"Calculates the **rank** of a matrix using **Gaussian elimination**.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the rank of."}},variants:[{argumentNames:["m"]}],examples:["let { rank } = import(matrix);\nrank([[1, 0, 0], [0, 1, 0], [0, 0, 1]])","let { rank } = import(matrix);\nrank([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { rank } = import(matrix);\nrank([[2, 4, 6], [3, 6, 9], [4, 8, 12]])"],seeAlso:["matrix.det","matrix.invertible?","linear-algebra.rref"]},"frobenius-norm":{category:"matrix",description:"Calculates the **Frobenius norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the Frobenius norm of."}},variants:[{argumentNames:["m"]}],examples:["let { frobenius-norm } = import(matrix);\nfrobenius-norm([[1, 2], [3, 4]])","let { frobenius-norm } = import(matrix);\nfrobenius-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.one-norm","matrix.inf-norm","matrix.max-norm"]},"one-norm":{category:"matrix",description:"Calculates the **one-norm** (column norm) of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the one-norm of."}},variants:[{argumentNames:["m"]}],examples:["let { one-norm } = import(matrix);\none-norm([[1, 2], [3, 4]])","let { one-norm } = import(matrix);\none-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.inf-norm","matrix.max-norm"]},"inf-norm":{category:"matrix",description:"Calculates the **infinity norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the infinity norm of."}},variants:[{argumentNames:["m"]}],examples:["let { inf-norm } = import(matrix);\ninf-norm([[1, 2], [3, 4]])","let { inf-norm } = import(matrix);\ninf-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.max-norm"]},"max-norm":{category:"matrix",description:"Calculates the **max norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the max norm of."}},variants:[{argumentNames:["m"]}],examples:["let { max-norm } = import(matrix);\nmax-norm([[1, 2], [3, 4]])","let { max-norm } = import(matrix);\nmax-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.inf-norm"]}};function yi(e){const t=e.length,r=[];for(let n=0;n<t;n++)r[n]=[...e[n]];if(1===t)return r[0][0];if(2===t)return r[0][0]*r[1][1]-r[0][1]*r[1][0];let n=1;for(let e=0;e<t-1;e+=1){let o=e;for(let n=e+1;n<t;n+=1)Math.abs(r[n][e])>Math.abs(r[o][e])&&(o=n);if(ge(r[o][e]))return 0;o!==e&&([r[e],r[o]]=[r[o],r[e]],n=-n);for(let n=e+1;n<t;n+=1){const o=r[n][e]/r[e][e];for(let a=e;a<t;a++)r[n][a]-=o*r[e][a]}}let o=n;for(let e=0;e<t;e++)o*=r[e][e];return o}function vi(e,t,r){const n=e.length,o=[];for(let a=0;a<n;a++)if(a!==t){const t=[];for(let o=0;o<n;o++)o!==r&&t.push(e[a][o]);o.push(t)}return o}function bi(e){const t=e.length,r=[];for(let n=0;n<t;n++){r[n]=[];for(let o=0;o<t;o++){const t=(-1)**(n+o)*yi(vi(e,o,n));r[n][o]=t}}return r}function wi(e){return e.length===e[0].length}function xi(e){if(!wi(e))return!1;const t=e.length;for(let r=0;r<t;r++)for(let n=0;n<t;n++)if(r===n){if(!he(e[r][n],1))return!1}else if(!ge(e[r][n]))return!1;return!0}function ki(e,t){if(0===e.length||0===t.length||e[0].length!==t.length)throw new Error("Matrix dimensions do not match for multiplication");const r=e.length,n=e[0].length,o=t[0].length,a=Array(r).fill(0).map(()=>Array(o).fill(0));for(let i=0;i<r;i++)for(let r=0;r<n;r++){const n=e[i][r];for(let e=0;e<o;e++)a[i][e]+=n*t[r][e]}return a}const qi={mul:{evaluate:([e,t],r)=>{De(e,r),De(t,r);try{return ki(e,t)}catch(n){throw new o(`The number of columns in the first matrix must be equal to the number of rows in the second matrix, but got ${e[0].length} and ${t.length}`,r)}},arity:te(2)},det:{evaluate:([e],t)=>(Ue(e,t),yi(e)),arity:te(1)},inv:{evaluate:([e],t)=>{Ue(e,t);const r=function(e){const t=e.length;if(1===t){const t=e[0][0];return ge(t)?null:[[1/t]]}const r=yi(e);if(ge(r))return null;const n=bi(e),o=[];for(let e=0;e<t;e++){o[e]=[];for(let a=0;a<t;a++)o[e][a]=n[e][a]/r}return o}(e);if(null===r)throw new o("The matrix must be invertible",t);return r},arity:te(1)},adj:{evaluate:([e],t)=>(Ue(e,t),bi(e)),arity:te(1)},cofactor:{evaluate:([e],t)=>(Ue(e,t),function(e){const t=e.length,r=[];for(let n=0;n<t;n++){r[n]=[];for(let o=0;o<t;o++){const t=vi(e,n,o),a=(-1)**(n+o);r[n][o]=a*yi(t)}}return r}(e)),arity:te(1)},minor:{evaluate:([e,t,r],n)=>(De(e,n),Y(t,n,{integer:!0,nonNegative:!0,lte:e.length}),Y(r,n,{integer:!0,nonNegative:!0,lte:e[0].length}),vi(e,t,r)),arity:te(3)},trace:{evaluate:([e],t)=>(Ue(e,t),function(e){return e.reduce((e,t,r)=>e+t[r],0)}(e)),arity:te(1)},"symmetric?":{evaluate:([e],t)=>(De(e,t),function(e){const t=e.length;if(!wi(e))return!1;for(let r=0;r<t;r+=1)for(let t=0;t<r;t+=1)if(e[r][t]!==e[t][r])return!1;return!0}(e)),arity:te(1)},"triangular?":{evaluate:([e],t)=>(De(e,t),function(e){if(!wi(e))return!1;const t=e.length;let r=!0,n=!0;for(let o=0;o<t;o++)for(let a=0;a<t;a++){if(o>a&&0!==e[o][a]&&(r=!1,!n))return!1;o<a&&0!==e[o][a]&&(n=!1)}return r||n}(e)),arity:te(1)},"upper-triangular?":{evaluate:([e],t)=>(De(e,t),function(e){if(!wi(e))return!1;const t=e.length;for(let r=0;r<t;r++)for(let t=0;t<r;t++)if(0!==e[r][t])return!1;return!0}(e)),arity:te(1)},"lower-triangular?":{evaluate:([e],t)=>(De(e,t),function(e){if(!wi(e))return!1;const t=e.length;if(!e.every(e=>e.length===t))return!1;for(let r=0;r<t;r++)for(let n=r+1;n<t;n++)if(0!==e[r][n])return!1;return!0}(e)),arity:te(1)},"diagonal?":{evaluate:([e],t)=>(De(e,t),function(e){if(!wi(e))return!1;const t=e.length;for(let r=0;r<t;r+=1)for(let n=0;n<t;n+=1)if(r!==n&&0!==e[r][n])return!1;return!0}(e)),arity:te(1)},"square?":{evaluate:([e],t)=>(De(e,t),wi(e)),arity:te(1)},"orthogonal-matrix?":{evaluate:([e],t)=>(De(e,t),function(e){return!!wi(e)&&xi(ki(e,ya(e)))}(e)),arity:te(1)},"identity?":{evaluate:([e],t)=>(De(e,t),xi(e)),arity:te(1)},"invertible?":{evaluate:([e],t)=>(De(e,t),!!function(e){return!!Ve(e)&&e.length===e[0].length}(e)&&!ge(yi(e))),arity:te(1)},hilbert:{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});const r=[];for(let t=0;t<e;t+=1){const n=[];for(let r=0;r<e;r+=1)n.push(1/(t+r+1));r.push(n)}return r},arity:te(1)},vandermonde:{evaluate:([e],t)=>{Ce(e,t);const r=[];for(let t=0;t<e.length;t+=1){const n=[];for(let r=0;r<e.length;r+=1)n.push(e[t]**r);r.push(n)}return r},arity:te(1)},band:{evaluate:([e,t,r],n)=>(Y(e,n,{integer:!0,positive:!0}),Y(t,n,{integer:!0,nonNegative:!0,lt:e}),Y(r,n,{integer:!0,nonNegative:!0,lte:e}),function(e,t,r){const n=Array.from({length:e},()=>Array.from({length:e},()=>0));for(let o=0;o<e;o++)for(let a=Math.max(0,o-t);a<=Math.min(e-1,o+r);a++)n[o][a]=1;return n}(e,t,r)),arity:te(3)},"banded?":{evaluate:([e,t,r],n)=>{De(e,n);const o=Math.max(e.length,e[0].length);return Y(t,n,{integer:!0,nonNegative:!0,lt:o}),Y(r,n,{integer:!0,nonNegative:!0,lt:o}),function(e,t,r){const n=e.length,o=e[0].length;for(let a=0;a<n;a++)for(let n=0;n<o;n++)if(0!==e[a][n]&&(a-n>t||n-a>r))return!1;return!0}(e,t,r)},arity:te(3)},rank:{evaluate:([e],t)=>{De(e,t);const[,r]=oi(e);return r},arity:te(1)},"frobenius-norm":{evaluate:([e],t)=>(De(e,t),Math.sqrt(e.reduce((e,t)=>e+t.reduce((e,t)=>e+t*t,0),0))),arity:te(1)},"one-norm":{evaluate:([e],t)=>(De(e,t),function(e){const t=e.length,r=e[0].length;let n=0;for(let o=0;o<r;o+=1){let r=0;for(let n=0;n<t;n+=1)r+=Math.abs(e[n][o]);n=Math.max(n,r)}return n}(e)),arity:te(1)},"inf-norm":{evaluate:([e],t)=>(De(e,t),e.reduce((e,t)=>Math.max(e,t.reduce((e,t)=>e+Math.abs(t),0)),0)),arity:te(1)},"max-norm":{evaluate:([e],t)=>(De(e,t),e.reduce((e,t)=>{const r=t.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return Math.max(e,r)},0)),arity:te(1)}};for(const[e,t]of Object.entries(fi))qi[e]&&(qi[e].docs=t);const Ai={name:"matrix",functions:qi,source:"{}",docs:fi},Ni={"abundant-seq":{category:"number-theory",description:"Generates the abundant numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { abundant-seq } = import(number-theory);\nabundant-seq(1)","let { abundant-seq } = import(number-theory);\nabundant-seq(5)"],seeAlso:["number-theory.abundant-nth","number-theory.abundant-take-while","number-theory.abundant?","number-theory.deficient-seq","number-theory.perfect-seq"]},"abundant-take-while":{category:"number-theory",description:"Generates the abundant numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { abundant-take-while } = import(number-theory);\nabundant-take-while(-> $ < 100)"],seeAlso:["number-theory.abundant-seq","number-theory.abundant-nth","number-theory.abundant?"]},"abundant-nth":{category:"number-theory",description:"Generates the nth term of the abundant numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the number in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { abundant-nth } = import(number-theory);\nabundant-nth(1)","let { abundant-nth } = import(number-theory);\nabundant-nth(5)"],seeAlso:["number-theory.abundant-seq","number-theory.abundant-take-while","number-theory.abundant?"]},"abundant?":{category:"number-theory",description:"Checks if a number is abundant.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { abundant? } = import(number-theory);\nabundant?(12)","let { abundant? } = import(number-theory);\nabundant?(15)"],seeAlso:["number-theory.abundant-seq","number-theory.abundant-nth","number-theory.deficient?","number-theory.perfect?","number-theory.sigma","number-theory.divisors","number-theory.abundant-take-while"]},"arithmetic-seq":{category:"number-theory",description:"Generates the arithmetic sequence for a given $start, $step, and $length.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["start","step","length"]}],examples:["let { arithmetic-seq } = import(number-theory);\narithmetic-seq(3, 2, 2)","let { arithmetic-seq } = import(number-theory);\narithmetic-seq(2, 3, 2)","let { arithmetic-seq } = import(number-theory);\narithmetic-seq(1, 2, 2)","let { arithmetic-seq } = import(number-theory);\narithmetic-seq(1, 1.5, 12)"],seeAlso:["number-theory.arithmetic-nth","number-theory.arithmetic-take-while","number-theory.arithmetic?","number-theory.geometric-seq"]},"arithmetic-take-while":{category:"number-theory",description:"Generates the arithmetic sequence while a condition is met.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},takeWhile:{type:"function",description:"A function that takes a number and an index and returns a boolean."}},variants:[{argumentNames:["start","step","takeWhile"]}],examples:["let { arithmetic-take-while } = import(number-theory);\narithmetic-take-while(1, 0.25, -> $ < 3)"],seeAlso:["number-theory.arithmetic-seq","number-theory.arithmetic-nth","number-theory.arithmetic?"]},"arithmetic-nth":{category:"number-theory",description:"Generates the nth term of the arithmetic sequence.",returns:{type:"number"},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["start","step","n"]}],examples:["let { arithmetic-nth } = import(number-theory);\narithmetic-nth(3, 2, 2)","let { arithmetic-nth } = import(number-theory);\narithmetic-nth(2, 3, 2)","let { arithmetic-nth } = import(number-theory);\narithmetic-nth(1, 2, 2)","let { arithmetic-nth } = import(number-theory);\narithmetic-nth(1, 1.5, 12)"],seeAlso:["number-theory.arithmetic-seq","number-theory.arithmetic-take-while","number-theory.arithmetic?"]},"arithmetic?":{category:"number-theory",description:"Checks if a number is part of the arithmetic sequence.",returns:{type:"boolean"},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["start","step","n"]}],examples:["let { arithmetic? } = import(number-theory);\narithmetic?(3, 2, 2)","let { arithmetic? } = import(number-theory);\narithmetic?(2, 3, 2)","let { arithmetic? } = import(number-theory);\narithmetic?(1, 2, 2)","let { arithmetic? } = import(number-theory);\narithmetic?(1, 1.5, 12)"],seeAlso:["number-theory.arithmetic-seq","number-theory.arithmetic-nth","number-theory.geometric?","number-theory.arithmetic-take-while"]},"bell-seq":{category:"number-theory",description:"Generates the Bell sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 22 (the maximum length of the pre-calculated bell numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { bell-seq } = import(number-theory);\nbell-seq(5)","let { bell-seq } = import(number-theory);\nbell-seq(10)","let { bell-seq } = import(number-theory);\nbell-seq()"],seeAlso:["number-theory.bell-nth","number-theory.bell-take-while","number-theory.bell?","number-theory.catalan-seq","number-theory.stirling-second","number-theory.stirling-first"]},"bell-take-while":{category:"number-theory",description:"Generates the Bell sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { bell-take-while } = import(number-theory);\nbell-take-while(-> $ < 1000)"],seeAlso:["number-theory.bell-seq","number-theory.bell-nth","number-theory.bell?"]},"bell-nth":{category:"number-theory",description:"Generates the nth term of the Bell sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { bell-nth } = import(number-theory);\nbell-nth(5)","let { bell-nth } = import(number-theory);\nbell-nth(10)"],seeAlso:["number-theory.bell-seq","number-theory.bell-take-while","number-theory.bell?"]},"bell?":{category:"number-theory",description:"Checks if a number is in the Bell sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { bell? } = import(number-theory);\nbell?(1)","let { bell? } = import(number-theory);\nbell?(27644437)","let { bell? } = import(number-theory);\nbell?(27644436)"],seeAlso:["number-theory.bell-seq","number-theory.bell-nth","number-theory.catalan?","number-theory.bell-take-while"]},"bernoulli-seq":{category:"number-theory",description:"Generates the Bernoulli sequence up to a specified length.",returns:{type:"number",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { bernoulli-seq } = import(number-theory);\nbernoulli-seq(5)","let { bernoulli-seq } = import(number-theory);\nbernoulli-seq(10)"],seeAlso:["number-theory.bernoulli-nth","number-theory.bernoulli-take-while"]},"bernoulli-take-while":{category:"number-theory",description:"Generates the Bernoulli sequence while a condition is met.",returns:{type:"number",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { bernoulli-take-while } = import(number-theory);\nbernoulli-take-while(-> abs($) < 100)"],seeAlso:["number-theory.bernoulli-seq","number-theory.bernoulli-nth"]},"bernoulli-nth":{category:"number-theory",description:"Generates the nth term of the Bernoulli sequence.",returns:{type:"number"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { bernoulli-nth } = import(number-theory);\nbernoulli-nth(5)","let { bernoulli-nth } = import(number-theory);\nbernoulli-nth(10)","let { bernoulli-nth } = import(number-theory);\nbernoulli-nth(23)"],seeAlso:["number-theory.bernoulli-seq","number-theory.bernoulli-take-while"]},"catalan-seq":{category:"number-theory",description:"Generates the Catalan sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 30 (the maximum length of the pre-calculated catalan numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { catalan-seq } = import(number-theory);\ncatalan-seq(5)","let { catalan-seq } = import(number-theory);\ncatalan-seq(10)","let { catalan-seq } = import(number-theory);\ncatalan-seq()"],seeAlso:["number-theory.catalan-nth","number-theory.catalan-take-while","number-theory.catalan?","number-theory.bell-seq"]},"catalan-take-while":{category:"number-theory",description:"Generates the Catalan sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { catalan-take-while } = import(number-theory);\ncatalan-take-while(-> $ < 1000)"],seeAlso:["number-theory.catalan-seq","number-theory.catalan-nth","number-theory.catalan?"]},"catalan-nth":{category:"number-theory",description:"Generates the nth term of the Catalan sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { catalan-nth } = import(number-theory);\ncatalan-nth(5)","let { catalan-nth } = import(number-theory);\ncatalan-nth(10)"],seeAlso:["number-theory.catalan-seq","number-theory.catalan-take-while","number-theory.catalan?"]},"catalan?":{category:"number-theory",description:"Determines if a number is in the Catalan sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { catalan? } = import(number-theory);\ncatalan?(5)","let { catalan? } = import(number-theory);\ncatalan?(10)"],seeAlso:["number-theory.catalan-seq","number-theory.catalan-nth","number-theory.bell?","number-theory.catalan-take-while"]},"collatz-seq":{category:"number-theory",description:"Generates the collatz sequence starting from a given integer.",returns:{type:"integer",array:!0},args:{start:{type:"integer",description:"The starting integer for the collatz sequence."}},variants:[{argumentNames:["start"]}],examples:["let { collatz-seq } = import(number-theory);\ncollatz-seq(3)","let { collatz-seq } = import(number-theory);\ncollatz-seq(11)"],seeAlso:["number-theory.juggler-seq"]},"composite-seq":{category:"number-theory",description:"Generates the composite sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { composite-seq } = import(number-theory);\ncomposite-seq(1)","let { composite-seq } = import(number-theory);\ncomposite-seq(2)","let { composite-seq } = import(number-theory);\ncomposite-seq(10)"],seeAlso:["number-theory.composite-nth","number-theory.composite-take-while","number-theory.composite?","number-theory.prime-seq"]},"composite-take-while":{category:"number-theory",description:"Generates the composite sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { composite-take-while } = import(number-theory);\ncomposite-take-while(-> $ < 50)"],seeAlso:["number-theory.composite-seq","number-theory.composite-nth","number-theory.composite?"]},"composite-nth":{category:"number-theory",description:"Generates the nth term of the composite sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the composite number to retrieve."}},variants:[{argumentNames:["n"]}],examples:["let { composite-nth } = import(number-theory);\ncomposite-nth(1)","let { composite-nth } = import(number-theory);\ncomposite-nth(2)","let { composite-nth } = import(number-theory);\ncomposite-nth(10)"],seeAlso:["number-theory.composite-seq","number-theory.composite-take-while","number-theory.composite?"]},"composite?":{category:"number-theory",description:"Determines if a number is composite.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { composite? } = import(number-theory);\ncomposite?(4)","let { composite? } = import(number-theory);\ncomposite?(5)","let { composite? } = import(number-theory);\ncomposite?(11)"],seeAlso:["number-theory.composite-seq","number-theory.composite-nth","number-theory.prime?","number-theory.prime-factors","number-theory.composite-take-while"]},"deficient-seq":{category:"number-theory",description:"Generates the deficient numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { deficient-seq } = import(number-theory);\ndeficient-seq(1)","let { deficient-seq } = import(number-theory);\ndeficient-seq(5)"],seeAlso:["number-theory.deficient-nth","number-theory.deficient-take-while","number-theory.deficient?","number-theory.abundant-seq","number-theory.perfect-seq"]},"deficient-take-while":{category:"number-theory",description:"Generates the deficient numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { deficient-take-while } = import(number-theory);\ndeficient-take-while(-> $ < 100)"],seeAlso:["number-theory.deficient-seq","number-theory.deficient-nth","number-theory.deficient?"]},"deficient-nth":{category:"number-theory",description:"Generates the nth term of the deficient numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the number in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { deficient-nth } = import(number-theory);\ndeficient-nth(5)","let { deficient-nth } = import(number-theory);\ndeficient-nth(12)"],seeAlso:["number-theory.deficient-seq","number-theory.deficient-take-while","number-theory.deficient?"]},"deficient?":{category:"number-theory",description:"Checks if a number is deficient.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { deficient? } = import(number-theory);\ndeficient?(12)","let { deficient? } = import(number-theory);\ndeficient?(15)"],seeAlso:["number-theory.deficient-seq","number-theory.deficient-nth","number-theory.abundant?","number-theory.perfect?","number-theory.sigma","number-theory.divisors","number-theory.deficient-take-while"]},"factorial-seq":{category:"number-theory",description:"Generates the factorial sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 19 (the maximum length of the pre-calculated factorial numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { factorial-seq } = import(number-theory);\nfactorial-seq(1)","let { factorial-seq } = import(number-theory);\nfactorial-seq(2)","let { factorial-seq } = import(number-theory);\nfactorial-seq(3)","let { factorial-seq } = import(number-theory);\nfactorial-seq(4)","let { factorial-seq } = import(number-theory);\nfactorial-seq(5)","let { factorial-seq } = import(number-theory);\nfactorial-seq(10)"],seeAlso:["number-theory.factorial-nth","number-theory.factorial-take-while","number-theory.factorial?","number-theory.factorial"]},"factorial-take-while":{category:"number-theory",description:"Generates the factorial sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { factorial-take-while } = import(number-theory);\nfactorial-take-while(-> $ < 1000)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-nth","number-theory.factorial?"]},"factorial-nth":{category:"number-theory",description:"Generates the nth term of the factorial sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { factorial-nth } = import(number-theory);\nfactorial-nth(1)","let { factorial-nth } = import(number-theory);\nfactorial-nth(2)","let { factorial-nth } = import(number-theory);\nfactorial-nth(3)","let { factorial-nth } = import(number-theory);\nfactorial-nth(4)","let { factorial-nth } = import(number-theory);\nfactorial-nth(5)","let { factorial-nth } = import(number-theory);\nfactorial-nth(10)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-take-while","number-theory.factorial?","number-theory.factorial"]},"factorial?":{category:"number-theory",description:"Checks if a number is in the factorial sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { factorial? } = import(number-theory);\nfactorial?(1)","let { factorial? } = import(number-theory);\nfactorial?(2)","let { factorial? } = import(number-theory);\nfactorial?(3)","let { factorial? } = import(number-theory);\nfactorial?(4)","let { factorial? } = import(number-theory);\nfactorial?(5)","let { factorial? } = import(number-theory);\nfactorial?(6)","let { factorial? } = import(number-theory);\nfactorial?(7)","let { factorial? } = import(number-theory);\nfactorial?(8)","let { factorial? } = import(number-theory);\nfactorial?(9)","let { factorial? } = import(number-theory);\nfactorial?(3628800)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-nth","number-theory.factorial","number-theory.factorial-take-while"]},"fibonacci-seq":{category:"number-theory",description:"Generates the fibonacci sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 79 (the maximum length of the pre-calculated Fibonacci numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { fibonacci-seq } = import(number-theory);\nfibonacci-seq(1)","let { fibonacci-seq } = import(number-theory);\nfibonacci-seq(2)","let { fibonacci-seq } = import(number-theory);\nfibonacci-seq()"],seeAlso:["number-theory.fibonacci-nth","number-theory.fibonacci-take-while","number-theory.fibonacci?","number-theory.lucas-seq","number-theory.tribonacci-seq","number-theory.pell-seq","number-theory.padovan-seq"]},"fibonacci-take-while":{category:"number-theory",description:"Generates the fibonacci sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { fibonacci-take-while } = import(number-theory);\nfibonacci-take-while(-> $ < 100)"],seeAlso:["number-theory.fibonacci-seq","number-theory.fibonacci-nth","number-theory.fibonacci?"]},"fibonacci-nth":{category:"number-theory",description:"Generates the nth term of the fibonacci sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { fibonacci-nth } = import(number-theory);\nfibonacci-nth(5)","let { fibonacci-nth } = import(number-theory);\nfibonacci-nth(50)"],seeAlso:["number-theory.fibonacci-seq","number-theory.fibonacci-take-while","number-theory.fibonacci?"]},"fibonacci?":{category:"number-theory",description:"Determines if a number is in the fibonacci sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { fibonacci? } = import(number-theory);\nfibonacci?(0)","let { fibonacci? } = import(number-theory);\nfibonacci?(1)","let { fibonacci? } = import(number-theory);\nfibonacci?(2)","let { fibonacci? } = import(number-theory);\nfibonacci?(3)","let { fibonacci? } = import(number-theory);\nfibonacci?(4)","let { fibonacci? } = import(number-theory);\nfibonacci?(5)","let { fibonacci? } = import(number-theory);\nfibonacci?(6)","let { fibonacci? } = import(number-theory);\nfibonacci?(7)","let { fibonacci? } = import(number-theory);\nfibonacci?(8)","let { fibonacci? } = import(number-theory);\nfibonacci?(9)"],seeAlso:["number-theory.fibonacci-seq","number-theory.fibonacci-nth","number-theory.lucas?","number-theory.fibonacci-take-while","number-theory.tribonacci?","number-theory.padovan?","number-theory.pell?"]},"geometric-seq":{category:"number-theory",description:"Generates the geometric sequence for a given $start, $ratio, and $length.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["start","ratio","length"]}],examples:["let { geometric-seq } = import(number-theory);\ngeometric-seq(3, 2, 2)","let { geometric-seq } = import(number-theory);\ngeometric-seq(2, 3, 2)","let { geometric-seq } = import(number-theory);\ngeometric-seq(1, 2, 2)","let { geometric-seq } = import(number-theory);\ngeometric-seq(1, 1.5, 12)"],seeAlso:["number-theory.geometric-nth","number-theory.geometric-take-while","number-theory.geometric?","number-theory.arithmetic-seq"]},"geometric-take-while":{category:"number-theory",description:"Generates the geometric sequence while a condition is met.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},takeWhile:{type:"function",description:"A function that takes a number and an index and returns a boolean."}},variants:[{argumentNames:["start","ratio","takeWhile"]}],examples:["let { geometric-take-while } = import(number-theory);\ngeometric-take-while(1, 1.5, -> $ < 10)"],seeAlso:["number-theory.geometric-seq","number-theory.geometric-nth","number-theory.geometric?"]},"geometric-nth":{category:"number-theory",description:"Generates the nth term of the geometric sequence.",returns:{type:"number"},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["start","ratio","n"]}],examples:["let { geometric-nth } = import(number-theory);\ngeometric-nth(3, 2, 2)","let { geometric-nth } = import(number-theory);\ngeometric-nth(2, 3, 2)","let { geometric-nth } = import(number-theory);\ngeometric-nth(1, 2, 2)","let { geometric-nth } = import(number-theory);\ngeometric-nth(1, 1.5, 4)"],seeAlso:["number-theory.geometric-seq","number-theory.geometric-take-while","number-theory.geometric?"]},"geometric?":{category:"number-theory",description:"Checks if a number is in the geometric sequence.",returns:{type:"boolean"},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},n:{type:"number",description:"The number to check."}},variants:[{argumentNames:["start","ratio","n"]}],examples:["let { geometric? } = import(number-theory);\ngeometric?(1, 2, 1)","let { geometric? } = import(number-theory);\ngeometric?(2, 3, 2)","let { geometric? } = import(number-theory);\ngeometric?(3, 2, 2)","let { geometric? } = import(number-theory);\ngeometric?(1, 1.5, 2.25)","let { geometric? } = import(number-theory);\ngeometric?(1, 1.5, -4)"],seeAlso:["number-theory.geometric-seq","number-theory.geometric-nth","number-theory.arithmetic?","number-theory.geometric-take-while"]},"golomb-seq":{category:"number-theory",description:"Generates the Golomb sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { golomb-seq } = import(number-theory);\ngolomb-seq(5)","let { golomb-seq } = import(number-theory);\ngolomb-seq(20)"],seeAlso:["number-theory.golomb-nth","number-theory.golomb-take-while","number-theory.golomb?","number-theory.recaman-seq"]},"golomb-take-while":{category:"number-theory",description:"Generates the Golomb sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { golomb-take-while } = import(number-theory);\ngolomb-take-while(-> $ <= 10)"],seeAlso:["number-theory.golomb-seq","number-theory.golomb-nth","number-theory.golomb?"]},"golomb-nth":{category:"number-theory",description:"Generates the nth term of the Golomb sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { golomb-nth } = import(number-theory);\ngolomb-nth(5)","let { golomb-nth } = import(number-theory);\ngolomb-nth(1000)"],seeAlso:["number-theory.golomb-seq","number-theory.golomb-take-while","number-theory.golomb?"]},"golomb?":{category:"number-theory",description:"Checks if a number is in the Golomb sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { golomb? } = import(number-theory);\ngolomb?(1)","let { golomb? } = import(number-theory);\ngolomb?(2)","let { golomb? } = import(number-theory);\ngolomb?(3345)","let { golomb? } = import(number-theory);\ngolomb?(67867864)"],seeAlso:["number-theory.golomb-seq","number-theory.golomb-nth","number-theory.golomb-take-while"]},"happy-seq":{category:"number-theory",description:"Generates the happy sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { happy-seq } = import(number-theory);\nhappy-seq(1)","let { happy-seq } = import(number-theory);\nhappy-seq(2)","let { happy-seq } = import(number-theory);\nhappy-seq(20)"],seeAlso:["number-theory.happy-nth","number-theory.happy-take-while","number-theory.happy?","number-theory.lucky-seq"]},"happy-take-while":{category:"number-theory",description:"Generates the happy sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { happy-take-while } = import(number-theory);\nhappy-take-while(-> $ < 100)"],seeAlso:["number-theory.happy-seq","number-theory.happy-nth","number-theory.happy?"]},"happy-nth":{category:"number-theory",description:"Generates the nth term of the happy sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the happy number to return."}},variants:[{argumentNames:["n"]}],examples:["let { happy-nth } = import(number-theory);\nhappy-nth(1)","let { happy-nth } = import(number-theory);\nhappy-nth(2)","let { happy-nth } = import(number-theory);\nhappy-nth(20)"],seeAlso:["number-theory.happy-seq","number-theory.happy-take-while","number-theory.happy?"]},"happy?":{category:"number-theory",description:"Determines if a number is a happy number.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { happy? } = import(number-theory);\nhappy?(1)","let { happy? } = import(number-theory);\nhappy?(2)","let { happy? } = import(number-theory);\nhappy?(100)"],seeAlso:["number-theory.happy-seq","number-theory.happy-nth","number-theory.happy-take-while"]},"juggler-seq":{category:"number-theory",description:"Generates the Juggler sequence starting from a given integer.",returns:{type:"integer",array:!0},args:{start:{type:"integer",description:"The starting integer for the Juggler sequence."}},variants:[{argumentNames:["start"]}],examples:["let { juggler-seq } = import(number-theory);\njuggler-seq(3)","let { juggler-seq } = import(number-theory);\njuggler-seq(5)"],seeAlso:["number-theory.collatz-seq"]},"look-and-say-seq":{category:"number-theory",description:"Generates the Look-and-Say sequence up to a specified length.",returns:{type:"string",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { look-and-say-seq } = import(number-theory);\nlook-and-say-seq(5)"],seeAlso:["number-theory.look-and-say-nth","number-theory.look-and-say-take-while","number-theory.look-and-say?"]},"look-and-say-take-while":{category:"number-theory",description:"Generates the Look-and-Say sequence while a condition is met.",returns:{type:"string",array:!0},args:{takeWhile:{type:"function",description:"A function that takes a string and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { look-and-say-take-while } = import(number-theory);\nlook-and-say-take-while((term, index) -> count(term) < 10)","let { look-and-say-take-while } = import(number-theory);\nlook-and-say-take-while(-> $2 <= 10)"],seeAlso:["number-theory.look-and-say-seq","number-theory.look-and-say-nth","number-theory.look-and-say?"]},"look-and-say-nth":{category:"number-theory",description:"Generates the nth term of the Look-and-Say sequence.",returns:{type:"string"},args:{n:{type:"integer",description:"The index of the term in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { look-and-say-nth } = import(number-theory);\nlook-and-say-nth(5)"],seeAlso:["number-theory.look-and-say-seq","number-theory.look-and-say-take-while","number-theory.look-and-say?"]},"look-and-say?":{category:"number-theory",description:"Checks if a string is a valid Look-and-Say term.",returns:{type:"boolean"},args:{term:{type:"string",description:"The term to check."}},variants:[{argumentNames:["term"]}],examples:['let { look-and-say? } = import(number-theory);\nlook-and-say?("111221")','let { look-and-say? } = import(number-theory);\nlook-and-say?("123")'],seeAlso:["number-theory.look-and-say-seq","number-theory.look-and-say-nth","number-theory.look-and-say-take-while"]},"lucas-seq":{category:"number-theory",description:"Generates the lucas sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 77 (the maximum length of the pre-calculated Lucas numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { lucas-seq } = import(number-theory);\nlucas-seq(1)","let { lucas-seq } = import(number-theory);\nlucas-seq(2)","let { lucas-seq } = import(number-theory);\nlucas-seq()"],seeAlso:["number-theory.lucas-nth","number-theory.lucas-take-while","number-theory.lucas?","number-theory.fibonacci-seq"]},"lucas-take-while":{category:"number-theory",description:"Generates the lucas sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { lucas-take-while } = import(number-theory);\nlucas-take-while(-> $ < 100)"],seeAlso:["number-theory.lucas-seq","number-theory.lucas-nth","number-theory.lucas?"]},"lucas-nth":{category:"number-theory",description:"Generates the nth term of the lucas sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { lucas-nth } = import(number-theory);\nlucas-nth(1)","let { lucas-nth } = import(number-theory);\nlucas-nth(2)","let { lucas-nth } = import(number-theory);\nlucas-nth(10)"],seeAlso:["number-theory.lucas-seq","number-theory.lucas-take-while","number-theory.lucas?"]},"lucas?":{category:"number-theory",description:"Determines if a number is in the lucas sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { lucas? } = import(number-theory);\nlucas?(1)","let { lucas? } = import(number-theory);\nlucas?(2)","let { lucas? } = import(number-theory);\nlucas?(10)"],seeAlso:["number-theory.lucas-seq","number-theory.lucas-nth","number-theory.fibonacci?","number-theory.lucas-take-while"]},"lucky-seq":{category:"number-theory",description:"Generates the lucky sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { lucky-seq } = import(number-theory);\nlucky-seq(1)","let { lucky-seq } = import(number-theory);\nlucky-seq(2)","let { lucky-seq } = import(number-theory);\nlucky-seq(20)"],seeAlso:["number-theory.lucky-nth","number-theory.lucky-take-while","number-theory.lucky?","number-theory.happy-seq","number-theory.prime-seq"]},"lucky-take-while":{category:"number-theory",description:"Generates the lucky sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { lucky-take-while } = import(number-theory);\nlucky-take-while(-> $ < 100)"],seeAlso:["number-theory.lucky-seq","number-theory.lucky-nth","number-theory.lucky?"]},"lucky-nth":{category:"number-theory",description:"Generates the nth term of the lucky sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The position in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { lucky-nth } = import(number-theory);\nlucky-nth(1)","let { lucky-nth } = import(number-theory);\nlucky-nth(2)","let { lucky-nth } = import(number-theory);\nlucky-nth(20)"],seeAlso:["number-theory.lucky-seq","number-theory.lucky-take-while","number-theory.lucky?"]},"lucky?":{category:"number-theory",description:"Checks if a number is a lucky number.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { lucky? } = import(number-theory);\nlucky?(4)","let { lucky? } = import(number-theory);\nlucky?(7)","let { lucky? } = import(number-theory);\nlucky?(33)"],seeAlso:["number-theory.lucky-seq","number-theory.lucky-nth","number-theory.prime?","number-theory.lucky-take-while"]},"mersenne-seq":{category:"number-theory",description:"Generates the Mersenne sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 9 (the maximum length of the pre-calculated mersenne numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { mersenne-seq } = import(number-theory);\nmersenne-seq(1)","let { mersenne-seq } = import(number-theory);\nmersenne-seq(5)","let { mersenne-seq } = import(number-theory);\nmersenne-seq()"],seeAlso:["number-theory.mersenne-nth","number-theory.mersenne-take-while","number-theory.mersenne?","number-theory.prime-seq"]},"mersenne-take-while":{category:"number-theory",description:"Generates the Mersenne sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { mersenne-take-while } = import(number-theory);\nmersenne-take-while(-> $ < 1000)"],seeAlso:["number-theory.mersenne-seq","number-theory.mersenne-nth","number-theory.mersenne?"]},"mersenne-nth":{category:"number-theory",description:"Generates the nth term of the Mersenne sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { mersenne-nth } = import(number-theory);\nmersenne-nth(1)","let { mersenne-nth } = import(number-theory);\nmersenne-nth(5)"],seeAlso:["number-theory.mersenne-seq","number-theory.mersenne-take-while","number-theory.mersenne?"]},"mersenne?":{category:"number-theory",description:"Checks if a number is in the Mersenne sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { mersenne? } = import(number-theory);\nmersenne?(3)","let { mersenne? } = import(number-theory);\nmersenne?(4)","let { mersenne? } = import(number-theory);\nmersenne?(7)"],seeAlso:["number-theory.mersenne-seq","number-theory.mersenne-nth","number-theory.prime?","number-theory.mersenne-take-while"]},"padovan-seq":{category:"number-theory",description:"Generates the Padovan sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { padovan-seq } = import(number-theory);\npadovan-seq(5)","let { padovan-seq } = import(number-theory);\npadovan-seq(10)","let { padovan-seq } = import(number-theory);\npadovan-seq(20)"],seeAlso:["number-theory.padovan-nth","number-theory.padovan-take-while","number-theory.padovan?","number-theory.fibonacci-seq"]},"padovan-take-while":{category:"number-theory",description:"Generates the Padovan sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { padovan-take-while } = import(number-theory);\npadovan-take-while(-> $ < 1000)"],seeAlso:["number-theory.padovan-seq","number-theory.padovan-nth","number-theory.padovan?"]},"padovan-nth":{category:"number-theory",description:"Generates the nth term of the Padovan sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { padovan-nth } = import(number-theory);\npadovan-nth(5)","let { padovan-nth } = import(number-theory);\npadovan-nth(10)","let { padovan-nth } = import(number-theory);\npadovan-nth(20)"],seeAlso:["number-theory.padovan-seq","number-theory.padovan-take-while","number-theory.padovan?"]},"padovan?":{category:"number-theory",description:"Checks if a number is in the Padovan sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { padovan? } = import(number-theory);\npadovan?(1)","let { padovan? } = import(number-theory);\npadovan?(265)","let { padovan? } = import(number-theory);\npadovan?(6)"],seeAlso:["number-theory.padovan-seq","number-theory.padovan-nth","number-theory.fibonacci?","number-theory.padovan-take-while"]},"partition-seq":{category:"number-theory",description:"Generates the partition numbers up to a specified length. If no length is provided, it defaults to 299 (the maximum length of the pre-calculated partition numbers).",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { partition-seq } = import(number-theory);\npartition-seq(1)","let { partition-seq } = import(number-theory);\npartition-seq(10)","let { partition-seq } = import(number-theory);\npartition-seq()"],seeAlso:["number-theory.partition-nth","number-theory.partition-take-while","number-theory.partition?","number-theory.partitions","number-theory.count-partitions"]},"partition-take-while":{category:"number-theory",description:"Generates the partition numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { partition-take-while } = import(number-theory);\npartition-take-while(-> $ < 1000)"],seeAlso:["number-theory.partition-seq","number-theory.partition-nth","number-theory.partition?"]},"partition-nth":{category:"number-theory",description:"Generates the nth term of the partition numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the partition number to generate."}},variants:[{argumentNames:["n"]}],examples:["let { partition-nth } = import(number-theory);\npartition-nth(1)","let { partition-nth } = import(number-theory);\npartition-nth(5)"],seeAlso:["number-theory.partition-seq","number-theory.partition-take-while","number-theory.partition?"]},"partition?":{category:"number-theory",description:"Checks if a number is in the partition numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { partition? } = import(number-theory);\npartition?(0)","let { partition? } = import(number-theory);\npartition?(1)","let { partition? } = import(number-theory);\npartition?(2)","let { partition? } = import(number-theory);\npartition?(3)","let { partition? } = import(number-theory);\npartition?(4)","let { partition? } = import(number-theory);\npartition?(5)"],seeAlso:["number-theory.partition-seq","number-theory.partition-nth","number-theory.partitions","number-theory.partition-take-while"]},"pell-seq":{category:"number-theory",description:"Generates the Pell sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 42 (the maximum length of the pre-calculated Pell numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { pell-seq } = import(number-theory);\npell-seq(5)","let { pell-seq } = import(number-theory);\npell-seq(10)","let { pell-seq } = import(number-theory);\npell-seq()"],seeAlso:["number-theory.pell-nth","number-theory.pell-take-while","number-theory.pell?","number-theory.fibonacci-seq"]},"pell-take-while":{category:"number-theory",description:"Generates the Pell sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { pell-take-while } = import(number-theory);\npell-take-while(-> $ < 1000)"],seeAlso:["number-theory.pell-seq","number-theory.pell-nth","number-theory.pell?"]},"pell-nth":{category:"number-theory",description:"Generates the nth term of the Pell sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { pell-nth } = import(number-theory);\npell-nth(5)","let { pell-nth } = import(number-theory);\npell-nth(10)","let { pell-nth } = import(number-theory);\npell-nth(20)"],seeAlso:["number-theory.pell-seq","number-theory.pell-take-while","number-theory.pell?"]},"pell?":{category:"number-theory",description:"Checks if a number is a Pell number.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { pell? } = import(number-theory);\npell?(1)","let { pell? } = import(number-theory);\npell?(470832)","let { pell? } = import(number-theory);\npell?(10)"],seeAlso:["number-theory.pell-seq","number-theory.pell-nth","number-theory.fibonacci?","number-theory.pell-take-while"]},"perfect-seq":{category:"number-theory",description:"Generates the perfect numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If no length is provided, it defaults to 7 (the maximum length of the pre-calculated perfect numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { perfect-seq } = import(number-theory);\nperfect-seq(1)","let { perfect-seq } = import(number-theory);\nperfect-seq(5)","let { perfect-seq } = import(number-theory);\nperfect-seq()"],seeAlso:["number-theory.perfect-nth","number-theory.perfect-take-while","number-theory.perfect?","number-theory.abundant-seq","number-theory.deficient-seq","number-theory.amicable?"]},"perfect-take-while":{category:"number-theory",description:"Generates the perfect numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-take-while } = import(number-theory);\nperfect-take-while(-> $ < 1000)"],seeAlso:["number-theory.perfect-seq","number-theory.perfect-nth","number-theory.perfect?"]},"perfect-nth":{category:"number-theory",description:"Generates the nth term of the perfect numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the perfect number to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-nth } = import(number-theory);\nperfect-nth(1)","let { perfect-nth } = import(number-theory);\nperfect-nth(5)"],seeAlso:["number-theory.perfect-seq","number-theory.perfect-take-while","number-theory.perfect?"]},"perfect?":{category:"number-theory",description:"Checks if a number is in the perfect numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect? } = import(number-theory);\nperfect?(0)","let { perfect? } = import(number-theory);\nperfect?(1)","let { perfect? } = import(number-theory);\nperfect?(2)","let { perfect? } = import(number-theory);\nperfect?(3)","let { perfect? } = import(number-theory);\nperfect?(4)","let { perfect? } = import(number-theory);\nperfect?(5)","let { perfect? } = import(number-theory);\nperfect?(6)","let { perfect? } = import(number-theory);\nperfect?(7)","let { perfect? } = import(number-theory);\nperfect?(8)","let { perfect? } = import(number-theory);\nperfect?(9)"],seeAlso:["number-theory.perfect-seq","number-theory.perfect-nth","number-theory.abundant?","number-theory.deficient?","number-theory.sigma","number-theory.perfect-take-while","number-theory.amicable?","number-theory.proper-divisors"]},"perfect-square-seq":{category:"number-theory",description:"Generates the perfect square numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { perfect-square-seq } = import(number-theory);\nperfect-square-seq(5)","let { perfect-square-seq } = import(number-theory);\nperfect-square-seq(20)"],seeAlso:["number-theory.perfect-square-nth","number-theory.perfect-square-take-while","number-theory.perfect-square?","number-theory.perfect-cube-seq","number-theory.perfect-power-seq","number-theory.polygonal-seq"]},"perfect-square-take-while":{category:"number-theory",description:"Generates the perfect square numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-square-take-while } = import(number-theory);\nperfect-square-take-while(-> $ <= 100)"],seeAlso:["number-theory.perfect-square-seq","number-theory.perfect-square-nth","number-theory.perfect-square?"]},"perfect-square-nth":{category:"number-theory",description:"Generates the nth term of the perfect square numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-square-nth } = import(number-theory);\nperfect-square-nth(1)","let { perfect-square-nth } = import(number-theory);\nperfect-square-nth(5)"],seeAlso:["number-theory.perfect-square-seq","number-theory.perfect-square-take-while","number-theory.perfect-square?"]},"perfect-square?":{category:"number-theory",description:"Checks if a number is a perfect square.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-square? } = import(number-theory);\nperfect-square?(16)","let { perfect-square? } = import(number-theory);\nperfect-square?(20)"],seeAlso:["number-theory.perfect-square-seq","number-theory.perfect-square-nth","number-theory.perfect-cube?","number-theory.perfect-power?","number-theory.perfect-square-take-while","number-theory.perfect-power","number-theory.polygonal?"]},"perfect-cube-seq":{category:"number-theory",description:"Generates the perfect cube numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { perfect-cube-seq } = import(number-theory);\nperfect-cube-seq(5)","let { perfect-cube-seq } = import(number-theory);\nperfect-cube-seq(20)"],seeAlso:["number-theory.perfect-cube-nth","number-theory.perfect-cube-take-while","number-theory.perfect-cube?","number-theory.perfect-square-seq","number-theory.perfect-power-seq"]},"perfect-cube-take-while":{category:"number-theory",description:"Generates the perfect cube numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-cube-take-while } = import(number-theory);\nperfect-cube-take-while(-> $ <= 100)"],seeAlso:["number-theory.perfect-cube-seq","number-theory.perfect-cube-nth","number-theory.perfect-cube?"]},"perfect-cube-nth":{category:"number-theory",description:"Generates the nth term of the perfect cube numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-cube-nth } = import(number-theory);\nperfect-cube-nth(1)","let { perfect-cube-nth } = import(number-theory);\nperfect-cube-nth(5)"],seeAlso:["number-theory.perfect-cube-seq","number-theory.perfect-cube-take-while","number-theory.perfect-cube?"]},"perfect-cube?":{category:"number-theory",description:"Checks if a number is in the perfect cube numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-cube? } = import(number-theory);\nperfect-cube?(7)","let { perfect-cube? } = import(number-theory);\nperfect-cube?(8)","let { perfect-cube? } = import(number-theory);\nperfect-cube?(9)"],seeAlso:["number-theory.perfect-cube-seq","number-theory.perfect-cube-nth","number-theory.perfect-square?","number-theory.perfect-power?","number-theory.perfect-cube-take-while","number-theory.perfect-power"]},"perfect-power-seq":{category:"number-theory",description:"Generates the perfect power numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { perfect-power-seq } = import(number-theory);\nperfect-power-seq(5)","let { perfect-power-seq } = import(number-theory);\nperfect-power-seq(20)"],seeAlso:["number-theory.perfect-power-nth","number-theory.perfect-power-take-while","number-theory.perfect-power?","number-theory.perfect-power","number-theory.perfect-square-seq","number-theory.perfect-cube-seq"]},"perfect-power-take-while":{category:"number-theory",description:"Generates the perfect power numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-power-take-while } = import(number-theory);\nperfect-power-take-while(-> $ <= 100)"],seeAlso:["number-theory.perfect-power-seq","number-theory.perfect-power-nth","number-theory.perfect-power?"]},"perfect-power-nth":{category:"number-theory",description:"Generates the nth term of the perfect power numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-power-nth } = import(number-theory);\nperfect-power-nth(3)","let { perfect-power-nth } = import(number-theory);\nperfect-power-nth(15)"],seeAlso:["number-theory.perfect-power-seq","number-theory.perfect-power-take-while","number-theory.perfect-power?"]},"perfect-power?":{category:"number-theory",description:"Checks if a number is in the perfect power numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-power? } = import(number-theory);\nperfect-power?(7)","let { perfect-power? } = import(number-theory);\nperfect-power?(8)","let { perfect-power? } = import(number-theory);\nperfect-power?(9)","let { perfect-power? } = import(number-theory);\nperfect-power?(10)"],seeAlso:["number-theory.perfect-power-seq","number-theory.perfect-power-nth","number-theory.perfect-power","number-theory.perfect-square?","number-theory.perfect-cube?","number-theory.perfect-power-take-while"]},"polygonal-seq":{category:"number-theory",description:"Generates the polygonal sequence for a given number of sides and length.",returns:{type:"integer",array:!0},args:{sides:{type:"integer",description:"The number of sides of the polygon."},length:{type:"integer",description:"The length of the sequence to generate."},a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["sides","length"]}],examples:["let { polygonal-seq } = import(number-theory);\npolygonal-seq(3, 2)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(4, 2)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(5, 3)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(6, 5)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(100, 10)"],seeAlso:["number-theory.polygonal-nth","number-theory.polygonal-take-while","number-theory.polygonal?","number-theory.perfect-square-seq"]},"polygonal-take-while":{category:"number-theory",description:"Generates the polygonal sequence while a condition is met.",returns:{type:"integer",array:!0},args:{sides:{type:"integer",description:"The number of sides of the polygon."},takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."},a:{type:"integer"},b:{type:"function"}},variants:[{argumentNames:["sides","takeWhile"]}],examples:["let { polygonal-take-while } = import(number-theory);\npolygonal-take-while(15, -> $ < 1000)"],seeAlso:["number-theory.polygonal-seq","number-theory.polygonal-nth","number-theory.polygonal?"]},"polygonal-nth":{category:"number-theory",description:"Generates the nth term of the polygonal sequence.",returns:{type:"integer"},args:{sides:{type:"integer",description:"The number of sides of the polygon."},n:{type:"integer",description:"The index of the term to generate."},a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["sides","n"]}],examples:["let { polygonal-nth } = import(number-theory);\npolygonal-nth(3, 9)","let { polygonal-nth } = import(number-theory);\npolygonal-nth(4, 5)","let { polygonal-nth } = import(number-theory);\npolygonal-nth(5, 5)"],seeAlso:["number-theory.polygonal-seq","number-theory.polygonal-take-while","number-theory.polygonal?"]},"polygonal?":{category:"number-theory",description:"Checks if a number is in the polygonal sequence.",returns:{type:"boolean"},args:{sides:{type:"integer",description:"The number of sides of the polygon."},n:{type:"integer",description:"The number to check."},a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["sides","n"]}],examples:["let { polygonal? } = import(number-theory);\npolygonal?(3, 10)","let { polygonal? } = import(number-theory);\npolygonal?(3, 9)","let { polygonal? } = import(number-theory);\npolygonal?(4, 10000)","let { polygonal? } = import(number-theory);\npolygonal?(4, 1000)","let { polygonal? } = import(number-theory);\npolygonal?(6, 45)"],seeAlso:["number-theory.polygonal-seq","number-theory.polygonal-nth","number-theory.perfect-square?","number-theory.polygonal-take-while"]},"prime-seq":{category:"number-theory",description:"Generates the prime sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { prime-seq } = import(number-theory);\nprime-seq(1)","let { prime-seq } = import(number-theory);\nprime-seq(2)","let { prime-seq } = import(number-theory);\nprime-seq(10)"],seeAlso:["number-theory.prime-nth","number-theory.prime-take-while","number-theory.prime?","number-theory.composite-seq","number-theory.mersenne-seq","number-theory.lucky-seq"]},"prime-take-while":{category:"number-theory",description:"Generates the prime sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { prime-take-while } = import(number-theory);\nprime-take-while(-> $ < 50)"],seeAlso:["number-theory.prime-seq","number-theory.prime-nth","number-theory.prime?"]},"prime-nth":{category:"number-theory",description:"Generates the nth term of the prime sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { prime-nth } = import(number-theory);\nprime-nth(1)","let { prime-nth } = import(number-theory);\nprime-nth(2)","let { prime-nth } = import(number-theory);\nprime-nth(10)"],seeAlso:["number-theory.prime-seq","number-theory.prime-take-while","number-theory.prime?"]},"prime?":{category:"number-theory",description:"Determines if a number is prime.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { prime? } = import(number-theory);\nprime?(1)","let { prime? } = import(number-theory);\nprime?(2)","let { prime? } = import(number-theory);\nprime?(3)","let { prime? } = import(number-theory);\nprime?(4)","let { prime? } = import(number-theory);\nprime?(997)","let { prime? } = import(number-theory);\nprime?(1001)"],seeAlso:["number-theory.prime-seq","number-theory.prime-nth","number-theory.composite?","number-theory.prime-factors","number-theory.mersenne?","number-theory.prime-take-while","number-theory.lucky?"]},"recaman-seq":{category:"number-theory",description:"Generates the Recaman sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { recaman-seq } = import(number-theory);\nrecaman-seq(5)","let { recaman-seq } = import(number-theory);\nrecaman-seq(10)","let { recaman-seq } = import(number-theory);\nrecaman-seq(20)"],seeAlso:["number-theory.recaman-nth","number-theory.recaman-take-while","number-theory.recaman?","number-theory.golomb-seq"]},"recaman-take-while":{category:"number-theory",description:"Generates the Recaman sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { recaman-take-while } = import(number-theory);\nrecaman-take-while(-> $ < 10)"],seeAlso:["number-theory.recaman-seq","number-theory.recaman-nth","number-theory.recaman?"]},"recaman-nth":{category:"number-theory",description:"Generates the nth term of the Recaman sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { recaman-nth } = import(number-theory);\nrecaman-nth(5)","let { recaman-nth } = import(number-theory);\nrecaman-nth(10)","let { recaman-nth } = import(number-theory);\nrecaman-nth(20)"],seeAlso:["number-theory.recaman-seq","number-theory.recaman-take-while","number-theory.recaman?"]},"recaman?":{category:"number-theory",description:"Checks if a number is in the Recaman sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { recaman? } = import(number-theory);\nrecaman?(5)","let { recaman? } = import(number-theory);\nrecaman?(10)","let { recaman? } = import(number-theory);\nrecaman?(20)"],seeAlso:["number-theory.recaman-seq","number-theory.recaman-nth","number-theory.recaman-take-while"]},"sylvester-seq":{category:"number-theory",description:"Generates the Sylvester sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 6 (the maximum length of the pre-calculated Sylvester numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { sylvester-seq } = import(number-theory);\nsylvester-seq(5)","let { sylvester-seq } = import(number-theory);\nsylvester-seq()","let { sylvester-seq } = import(number-theory);\nsylvester-seq()"],seeAlso:["number-theory.sylvester-nth","number-theory.sylvester-take-while","number-theory.sylvester?"]},"sylvester-take-while":{category:"number-theory",description:"Generates the Sylvester sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { sylvester-take-while } = import(number-theory);\nsylvester-take-while(-> $ < 100000)"],seeAlso:["number-theory.sylvester-seq","number-theory.sylvester-nth","number-theory.sylvester?"]},"sylvester-nth":{category:"number-theory",description:"Generates the nth term of the Sylvester sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { sylvester-nth } = import(number-theory);\nsylvester-nth(1)","let { sylvester-nth } = import(number-theory);\nsylvester-nth(5)"],seeAlso:["number-theory.sylvester-seq","number-theory.sylvester-take-while","number-theory.sylvester?"]},"sylvester?":{category:"number-theory",description:"Checks if a number is in the Sylvester sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { sylvester? } = import(number-theory);\nsylvester?(2)","let { sylvester? } = import(number-theory);\nsylvester?(3)","let { sylvester? } = import(number-theory);\nsylvester?(6)"],seeAlso:["number-theory.sylvester-seq","number-theory.sylvester-nth","number-theory.sylvester-take-while"]},"thue-morse-seq":{category:"number-theory",description:"Generates the Thue-Morse sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { thue-morse-seq } = import(number-theory);\nthue-morse-seq(5)","let { thue-morse-seq } = import(number-theory);\nthue-morse-seq(10)","let { thue-morse-seq } = import(number-theory);\nthue-morse-seq(20)"],seeAlso:["number-theory.thue-morse-nth","number-theory.thue-morse-take-while","number-theory.thue-morse?"]},"thue-morse-take-while":{category:"number-theory",description:"Generates the Thue-Morse sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { thue-morse-take-while } = import(number-theory);\nthue-morse-take-while(-> $2 < 10)"],seeAlso:["number-theory.thue-morse-seq","number-theory.thue-morse-nth","number-theory.thue-morse?"]},"thue-morse-nth":{category:"number-theory",description:"Generates the nth term of the Thue-Morse sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { thue-morse-nth } = import(number-theory);\nthue-morse-nth(5)","let { thue-morse-nth } = import(number-theory);\nthue-morse-nth(10)","let { thue-morse-nth } = import(number-theory);\nthue-morse-nth(20)"],seeAlso:["number-theory.thue-morse-seq","number-theory.thue-morse-take-while","number-theory.thue-morse?"]},"thue-morse?":{category:"number-theory",description:"Checks if a number is part of the Thue-Morse sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { thue-morse? } = import(number-theory);\nthue-morse?(1)","let { thue-morse? } = import(number-theory);\nthue-morse?(2)"],seeAlso:["number-theory.thue-morse-seq","number-theory.thue-morse-nth","number-theory.thue-morse-take-while"]},"tribonacci-seq":{category:"number-theory",description:"Generates the tribonacci sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { tribonacci-seq } = import(number-theory);\ntribonacci-seq(1)","let { tribonacci-seq } = import(number-theory);\ntribonacci-seq(2)","let { tribonacci-seq } = import(number-theory);\ntribonacci-seq(10)"],seeAlso:["number-theory.tribonacci-nth","number-theory.tribonacci-take-while","number-theory.tribonacci?","number-theory.fibonacci-seq"]},"tribonacci-take-while":{category:"number-theory",description:"Generates the tribonacci sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { tribonacci-take-while } = import(number-theory);\ntribonacci-take-while(-> $ < 100)"],seeAlso:["number-theory.tribonacci-seq","number-theory.tribonacci-nth","number-theory.tribonacci?"]},"tribonacci-nth":{category:"number-theory",description:"Generates the nth term of the tribonacci sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { tribonacci-nth } = import(number-theory);\ntribonacci-nth(1)","let { tribonacci-nth } = import(number-theory);\ntribonacci-nth(2)","let { tribonacci-nth } = import(number-theory);\ntribonacci-nth(10)"],seeAlso:["number-theory.tribonacci-seq","number-theory.tribonacci-take-while","number-theory.tribonacci?"]},"tribonacci?":{category:"number-theory",description:"Determines if a number is in the tribonacci sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { tribonacci? } = import(number-theory);\ntribonacci?(0)","let { tribonacci? } = import(number-theory);\ntribonacci?(1)","let { tribonacci? } = import(number-theory);\ntribonacci?(2)","let { tribonacci? } = import(number-theory);\ntribonacci?(3)","let { tribonacci? } = import(number-theory);\ntribonacci?(4)","let { tribonacci? } = import(number-theory);\ntribonacci?(5)","let { tribonacci? } = import(number-theory);\ntribonacci?(6)","let { tribonacci? } = import(number-theory);\ntribonacci?(7)","let { tribonacci? } = import(number-theory);\ntribonacci?(8)","let { tribonacci? } = import(number-theory);\ntribonacci?(9)","let { tribonacci? } = import(number-theory);\ntribonacci?(10)"],seeAlso:["number-theory.tribonacci-seq","number-theory.tribonacci-nth","number-theory.fibonacci?","number-theory.tribonacci-take-while"]},"count-combinations":{category:"number-theory",description:"Calculates the number of combinations of n items taken k at a time.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { count-combinations } = import(number-theory);\ncount-combinations(5, 3)","let { count-combinations } = import(number-theory);\ncount-combinations(10, 2)"],seeAlso:["number-theory.combinations","number-theory.count-permutations","number-theory.factorial","number-theory.multinomial","number-theory.stirling-second","number-theory.count-partitions","number-theory.count-power-set"]},combinations:{category:"number-theory",description:"Generates all possible combinations of a specified size from a collection.",returns:{type:"array",array:!0},args:{set:{type:"array",array:!0,description:"The input collection to generate combinations from."},n:{type:"integer",description:"The size of each combination."},a:{type:"array"},b:{type:"integer"}},variants:[{argumentNames:["set","n"]}],examples:["let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 2)",'let { combinations } = import(number-theory);\ncombinations(["a", "b", "c"], 2)',"let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 0)","let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 1)","let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 3)"],seeAlso:["number-theory.count-combinations","number-theory.permutations","number-theory.power-set","number-theory.cartesian-product","number-theory.partitions"]},"count-derangements":{category:"number-theory",description:"Calculates the number of derangements (permutations where no element appears in its original position) of n items.",returns:{type:"integer"},args:{n:{type:"integer",description:"The total number of items."}},variants:[{argumentNames:["n"]}],examples:["let { count-derangements } = import(number-theory);\ncount-derangements(4)","let { count-derangements } = import(number-theory);\ncount-derangements(5)"],seeAlso:["number-theory.derangements","number-theory.count-permutations","number-theory.factorial"]},derangements:{category:"number-theory",description:"Generates all derangements (permutations where no element appears in its original position) of a set.",returns:{type:"array",array:!0},args:{set:{type:"array",array:!0,description:"The input collection to generate derangements from."}},variants:[{argumentNames:["set"]}],examples:["let { derangements } = import(number-theory);\nderangements([1, 2, 3, 4])",'let { derangements } = import(number-theory);\nderangements(["a", "b", "c"])'],seeAlso:["number-theory.count-derangements","number-theory.permutations"]},divisors:{category:"number-theory",description:"Returns the divisors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to find divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { divisors } = import(number-theory);\ndivisors(12)","let { divisors } = import(number-theory);\ndivisors(100)","let { divisors } = import(number-theory);\ndivisors(37)"],seeAlso:["number-theory.count-divisors","number-theory.proper-divisors","number-theory.sigma","number-theory.prime-factors","number-theory.divisible-by?","number-theory.lcm","number-theory.abundant?","number-theory.deficient?","number-theory.count-proper-divisors"]},"count-divisors":{category:"number-theory",description:"Returns the number of divisors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-divisors } = import(number-theory);\ncount-divisors(12)","let { count-divisors } = import(number-theory);\ncount-divisors(100)","let { count-divisors } = import(number-theory);\ncount-divisors(37)"],seeAlso:["number-theory.divisors","number-theory.count-proper-divisors","number-theory.sigma"]},"proper-divisors":{category:"number-theory",description:"Returns the proper divisors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to find proper divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { proper-divisors } = import(number-theory);\nproper-divisors(12)","let { proper-divisors } = import(number-theory);\nproper-divisors(100)","let { proper-divisors } = import(number-theory);\nproper-divisors(37)"],seeAlso:["number-theory.count-proper-divisors","number-theory.divisors","number-theory.amicable?","number-theory.perfect?"]},"count-proper-divisors":{category:"number-theory",description:"Returns the number of proper divisors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count proper divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-proper-divisors } = import(number-theory);\ncount-proper-divisors(12)","let { count-proper-divisors } = import(number-theory);\ncount-proper-divisors(100)","let { count-proper-divisors } = import(number-theory);\ncount-proper-divisors(37)"],seeAlso:["number-theory.proper-divisors","number-theory.count-divisors","number-theory.divisors"]},factorial:{category:"number-theory",description:"Calculates the factorial of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the factorial for."}},variants:[{argumentNames:["n"]}],examples:["let { factorial } = import(number-theory);\nfactorial(5)","let { factorial } = import(number-theory);\nfactorial(0)","let { factorial } = import(number-theory);\nfactorial(10)","let { factorial } = import(number-theory);\nfactorial(20)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-nth","number-theory.factorial?","number-theory.count-combinations","number-theory.count-permutations","number-theory.multinomial","number-theory.count-derangements"]},partitions:{category:"number-theory",description:"Generates all partitions of a number.",returns:{type:"array",array:!0},args:{n:{type:"integer",description:"The number to partition."}},variants:[{argumentNames:["n"]}],examples:["let { partitions } = import(number-theory);\npartitions(4)","let { partitions } = import(number-theory);\npartitions(8)"],seeAlso:["number-theory.count-partitions","number-theory.partition-seq","number-theory.combinations","number-theory.partition?"]},"count-partitions":{category:"number-theory",description:"Returns the number of partitions of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count partitions for."}},variants:[{argumentNames:["n"]}],examples:["let { count-partitions } = import(number-theory);\ncount-partitions(4)","let { count-partitions } = import(number-theory);\ncount-partitions(8)","let { count-partitions } = import(number-theory);\ncount-partitions(15)"],seeAlso:["number-theory.partitions","number-theory.partition-seq","number-theory.count-combinations"]},permutations:{category:"number-theory",description:"Generates all permutations of a collection.",returns:{type:"array",array:!0},args:{set:{type:"array",array:!0,description:"The input collection to generate permutations from."}},variants:[{argumentNames:["set"]}],examples:["let { permutations } = import(number-theory);\npermutations([1, 2, 3])",'let { permutations } = import(number-theory);\npermutations(["a", "b", "c"])',"let { permutations } = import(number-theory);\npermutations([1, 2, 3, 4])","let { permutations } = import(number-theory);\npermutations([1, 2])","let { permutations } = import(number-theory);\npermutations([1])","let { permutations } = import(number-theory);\npermutations([])"],seeAlso:["number-theory.count-permutations","number-theory.combinations","number-theory.derangements","number-theory.cartesian-product"]},"count-permutations":{category:"number-theory",description:"Returns the number of permutations of n items taken k at a time.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { count-permutations } = import(number-theory);\ncount-permutations(5, 3)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 2)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 10)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 0)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 1)"],seeAlso:["number-theory.permutations","number-theory.count-combinations","number-theory.factorial","number-theory.multinomial","number-theory.stirling-first","number-theory.count-derangements"]},"power-set":{category:"number-theory",description:"Generates the power set of a collection.",returns:{type:"array",array:!0},args:{set:{type:"any",array:!0,description:"The input collection to generate the power set from."}},variants:[{argumentNames:["set"]}],examples:['let { power-set } = import(number-theory);\npower-set(["a", "b", "c"])',"let { power-set } = import(number-theory);\npower-set([1, 2])","let { power-set } = import(number-theory);\npower-set([1])","let { power-set } = import(number-theory);\npower-set([])"],seeAlso:["number-theory.count-power-set","number-theory.combinations","number-theory.cartesian-product"]},"count-power-set":{category:"number-theory",description:"Returns the number of subsets of a set.",returns:{type:"integer"},args:{n:{type:"integer",description:"The size of the set."}},variants:[{argumentNames:["n"]}],examples:["let { count-power-set } = import(number-theory);\ncount-power-set(3)","let { count-power-set } = import(number-theory);\ncount-power-set(5)","let { count-power-set } = import(number-theory);\ncount-power-set(10)"],seeAlso:["number-theory.power-set","number-theory.count-combinations"]},"prime-factors":{category:"number-theory",description:"Returns the prime factors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to factor."}},variants:[{argumentNames:["n"]}],examples:["let { prime-factors } = import(number-theory);\nprime-factors(12)","let { prime-factors } = import(number-theory);\nprime-factors(100)","let { prime-factors } = import(number-theory);\nprime-factors(37)"],seeAlso:["number-theory.count-prime-factors","number-theory.distinct-prime-factors","number-theory.prime?","number-theory.divisors","number-theory.euler-totient","number-theory.mobius","number-theory.composite?","number-theory.count-distinct-prime-factors"]},"count-prime-factors":{category:"number-theory",description:"Returns the number of prime factors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count prime factors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-prime-factors } = import(number-theory);\ncount-prime-factors(12)","let { count-prime-factors } = import(number-theory);\ncount-prime-factors(100)","let { count-prime-factors } = import(number-theory);\ncount-prime-factors(37)"],seeAlso:["number-theory.prime-factors","number-theory.distinct-prime-factors","number-theory.count-distinct-prime-factors"]},"distinct-prime-factors":{category:"number-theory",description:"Returns the distinct prime factors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to find distinct prime factors for."}},variants:[{argumentNames:["n"]}],examples:["let { distinct-prime-factors } = import(number-theory);\ndistinct-prime-factors(12)","let { distinct-prime-factors } = import(number-theory);\ndistinct-prime-factors(100)","let { distinct-prime-factors } = import(number-theory);\ndistinct-prime-factors(37)"],seeAlso:["number-theory.prime-factors","number-theory.count-distinct-prime-factors","number-theory.count-prime-factors"]},"count-distinct-prime-factors":{category:"number-theory",description:"Returns the number of distinct prime factors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count distinct prime factors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-distinct-prime-factors } = import(number-theory);\ncount-distinct-prime-factors(12)","let { count-distinct-prime-factors } = import(number-theory);\ncount-distinct-prime-factors(100)","let { count-distinct-prime-factors } = import(number-theory);\ncount-distinct-prime-factors(37)"],seeAlso:["number-theory.distinct-prime-factors","number-theory.prime-factors","number-theory.count-prime-factors"]},"coprime?":{category:"number-theory",description:"Checks if two numbers are coprime (i.e., their GCD is 1).",returns:{type:"boolean"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { coprime? } = import(number-theory);\ncoprime?(12, 8)","let { coprime? } = import(number-theory);\ncoprime?(12, 5)","let { coprime? } = import(number-theory);\ncoprime?(37, 1)","let { coprime? } = import(number-theory);\ncoprime?(0, 0)","let { coprime? } = import(number-theory);\ncoprime?(0, 5)","let { coprime? } = import(number-theory);\ncoprime?(5, 0)","let { coprime? } = import(number-theory);\ncoprime?(1, 0)","let { coprime? } = import(number-theory);\ncoprime?(0, 1)","let { coprime? } = import(number-theory);\ncoprime?(1, 1)","let { coprime? } = import(number-theory);\ncoprime?(2, 3)"],seeAlso:["number-theory.gcd","number-theory.euler-totient","number-theory.divisible-by?","number-theory.lcm","number-theory.carmichael-lambda"]},"divisible-by?":{category:"number-theory",description:"Checks if a number is divisible by another number.",returns:{type:"boolean"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { divisible-by? } = import(number-theory);\ndivisible-by?(12, 4)","let { divisible-by? } = import(number-theory);\ndivisible-by?(12, 5)","let { divisible-by? } = import(number-theory);\ndivisible-by?(37, 1)","let { divisible-by? } = import(number-theory);\ndivisible-by?(0, 0)","let { divisible-by? } = import(number-theory);\ndivisible-by?(0, 5)","let { divisible-by? } = import(number-theory);\ndivisible-by?(5, 0)"],seeAlso:["number-theory.divisors","number-theory.gcd","number-theory.coprime?"]},gcd:{category:"number-theory",description:"Calculates the greatest common divisor (GCD) of two numbers.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { gcd } = import(number-theory);\ngcd(100, 25)","let { gcd } = import(number-theory);\ngcd(37, 1)","let { gcd } = import(number-theory);\ngcd(0, 0)","let { gcd } = import(number-theory);\ngcd(0, 5)","let { gcd } = import(number-theory);\ngcd(5, 0)"],seeAlso:["number-theory.lcm","number-theory.extended-gcd","number-theory.coprime?","number-theory.divisible-by?"]},lcm:{category:"number-theory",description:"Calculates the least common multiple (LCM) of two numbers.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { lcm } = import(number-theory);\nlcm(100, 25)","let { lcm } = import(number-theory);\nlcm(37, 1)","let { lcm } = import(number-theory);\nlcm(0, 5)","let { lcm } = import(number-theory);\nlcm(5, 0)"],seeAlso:["number-theory.gcd","number-theory.divisors","number-theory.coprime?"]},multinomial:{category:"number-theory",description:"Calculates the multinomial coefficient from of a list of numbers representing the sizes of each group.",returns:{type:"integer"},args:{args:{type:"integer",rest:!0,description:"The numbers representing the sizes of each group."}},variants:[{argumentNames:["args"]}],examples:["let { multinomial } = import(number-theory);\nmultinomial(5, 2, 3)","let { multinomial } = import(number-theory);\nmultinomial(10, 2, 3, 5)"],seeAlso:["number-theory.count-combinations","number-theory.factorial","number-theory.count-permutations"],hideOperatorForm:!0},"amicable?":{category:"number-theory",description:"Checks if two numbers are amicable (i.e., the sum of the proper divisors of each number equals the other number).",returns:{type:"boolean"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { amicable? } = import(number-theory);\namicable?(220, 284)","let { amicable? } = import(number-theory);\namicable?(1184, 1210)","let { amicable? } = import(number-theory);\namicable?(2620, 2924)","let { amicable? } = import(number-theory);\namicable?(5020, 5564)","let { amicable? } = import(number-theory);\namicable?(6232, 6368)"],seeAlso:["number-theory.proper-divisors","number-theory.perfect?","number-theory.sigma","number-theory.perfect-seq"]},"euler-totient":{category:"number-theory",description:"Calculates the Euler's totient function (φ(n)) of a number, which counts the integers up to n that are coprime to n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the totient for."}},variants:[{argumentNames:["n"]}],examples:["let { euler-totient } = import(number-theory);\neuler-totient(1)","let { euler-totient } = import(number-theory);\neuler-totient(2)","let { euler-totient } = import(number-theory);\neuler-totient(10)","let { euler-totient } = import(number-theory);\neuler-totient(20)"],seeAlso:["number-theory.coprime?","number-theory.carmichael-lambda","number-theory.mobius","number-theory.prime-factors","number-theory.mertens"]},mobius:{category:"number-theory",description:"Calculates the Möbius function (μ(n)) of a number, which is used in number theory.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the Möbius function for."}},variants:[{argumentNames:["n"]}],examples:["let { mobius } = import(number-theory);\nmobius(1)","let { mobius } = import(number-theory);\nmobius(2)","let { mobius } = import(number-theory);\nmobius(3)","let { mobius } = import(number-theory);\nmobius(4)","let { mobius } = import(number-theory);\nmobius(6)","let { mobius } = import(number-theory);\nmobius(12)","let { mobius } = import(number-theory);\nmobius(30)"],seeAlso:["number-theory.mertens","number-theory.euler-totient","number-theory.prime-factors"]},mertens:{category:"number-theory",description:"Calculates the Mertens function (M(n)) of a number, which is the sum of the Möbius function up to n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the Mertens function for."}},variants:[{argumentNames:["n"]}],examples:["let { mobius } = import(number-theory);\nmobius(1)","let { mobius } = import(number-theory);\nmobius(2)","let { mobius } = import(number-theory);\nmobius(3)","let { mobius } = import(number-theory);\nmobius(4)","let { mobius } = import(number-theory);\nmobius(6)","let { mobius } = import(number-theory);\nmobius(12)","let { mobius } = import(number-theory);\nmobius(30)"],seeAlso:["number-theory.mobius","number-theory.euler-totient"]},sigma:{category:"number-theory",description:"Calculates the sum of divisors function (σ(n)) of a number, which is the sum of all positive divisors of n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the sum of divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { sigma } = import(number-theory);\nsigma(1)","let { sigma } = import(number-theory);\nsigma(2)","let { sigma } = import(number-theory);\nsigma(3)","let { sigma } = import(number-theory);\nsigma(4)","let { sigma } = import(number-theory);\nsigma(6)","let { sigma } = import(number-theory);\nsigma(12)","let { sigma } = import(number-theory);\nsigma(30)"],seeAlso:["number-theory.divisors","number-theory.perfect?","number-theory.abundant?","number-theory.deficient?","number-theory.amicable?","number-theory.count-divisors"]},"carmichael-lambda":{category:"number-theory",description:"Calculates the Carmichael function (λ(n)) of a number, which is the smallest positive integer m such that a^m ≡ 1 (mod n) for all integers a coprime to n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the Carmichael function for."}},variants:[{argumentNames:["n"]}],examples:["let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(1)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(2)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(3)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(4)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(6)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(12)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(30)"],seeAlso:["number-theory.euler-totient","number-theory.mod-exp","number-theory.coprime?"]},"cartesian-product":{category:"number-theory",description:"Calculates the Cartesian product of two or more sets.",returns:{type:"array",array:!0},args:{sets:{type:"array",array:!0,description:"The input collections to calculate the Cartesian product from."},a:{type:"array"},b:{type:"array"}},variants:[{argumentNames:["sets"]}],examples:['let { cartesian-product } = import(number-theory);\ncartesian-product([1, 2], ["a", "b"])','let { cartesian-product } = import(number-theory);\ncartesian-product([1, 2], ["a", "b"], [true, false])','let { cartesian-product } = import(number-theory);\ncartesian-product([1, 2, 3], ["x", "y", "z"])'],seeAlso:["number-theory.combinations","number-theory.power-set","number-theory.permutations"]},"perfect-power":{category:"number-theory",description:"Returns a tuple of the base and exponent if the number is a perfect power, otherwise returns null.",returns:{type:["array","null"]},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-power } = import(number-theory);\nperfect-power(1)","let { perfect-power } = import(number-theory);\nperfect-power(2)","let { perfect-power } = import(number-theory);\nperfect-power(4)","let { perfect-power } = import(number-theory);\nperfect-power(8)","let { perfect-power } = import(number-theory);\nperfect-power(9)","let { perfect-power } = import(number-theory);\nperfect-power(16)","let { perfect-power } = import(number-theory);\nperfect-power(19)"],seeAlso:["number-theory.perfect-power?","number-theory.perfect-power-seq","number-theory.perfect-square?","number-theory.perfect-cube?"]},"mod-exp":{category:"number-theory",description:"Calculates the modular exponentiation of a base raised to an exponent modulo a modulus.",returns:{type:"integer"},args:{base:{type:"integer"},exponent:{type:"integer"},modulus:{type:"integer"}},variants:[{argumentNames:["base","exponent","modulus"]}],examples:["let { mod-exp } = import(number-theory);\nmod-exp(2, 3, 5)","let { mod-exp } = import(number-theory);\nmod-exp(3, 4, 7)","let { mod-exp } = import(number-theory);\nmod-exp(5, 6, 11)","let { mod-exp } = import(number-theory);\nmod-exp(7, 8, 13)"],seeAlso:["number-theory.mod-inv","number-theory.carmichael-lambda","number-theory.chinese-remainder"]},"mod-inv":{category:"number-theory",description:"Calculates the modular multiplicative inverse of a number modulo another number.",returns:{type:"integer"},args:{a:{type:"integer"},m:{type:"integer"}},variants:[{argumentNames:["a","m"]}],examples:["let { mod-inv } = import(number-theory);\nmod-inv(3, 11)","let { mod-inv } = import(number-theory);\nmod-inv(10, 17)","let { mod-inv } = import(number-theory);\nmod-inv(5, 13)","let { mod-inv } = import(number-theory);\nmod-inv(7, 19)"],seeAlso:["number-theory.mod-exp","number-theory.extended-gcd","number-theory.chinese-remainder"]},"extended-gcd":{category:"number-theory",description:"Calculates the extended greatest common divisor (GCD) of two numbers, returning the GCD and the coefficients of Bézout's identity.",returns:{type:"integer",array:!0},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { extended-gcd } = import(number-theory);\nextended-gcd(30, 12)","let { extended-gcd } = import(number-theory);\nextended-gcd(56, 98)","let { extended-gcd } = import(number-theory);\nextended-gcd(101, 10)","let { extended-gcd } = import(number-theory);\nextended-gcd(17, 13)"],seeAlso:["number-theory.gcd","number-theory.mod-inv","number-theory.chinese-remainder"]},"chinese-remainder":{category:"number-theory",description:"Solves a system of simultaneous congruences using the Chinese Remainder Theorem.",returns:{type:"integer"},args:{remainders:{type:"integer",array:!0,description:"The remainders of the congruences."},moduli:{type:"integer",array:!0,description:"The moduli of the congruences."},a:{type:"array"},b:{type:"array"}},variants:[{argumentNames:["remainders","moduli"]}],examples:["let { chinese-remainder } = import(number-theory);\nchinese-remainder([2, 3], [3, 5])","let { chinese-remainder } = import(number-theory);\nchinese-remainder([1, 2], [3, 4])","let { chinese-remainder } = import(number-theory);\nchinese-remainder([0, 1], [2, 3])","let { chinese-remainder } = import(number-theory);\nchinese-remainder([1, 2, 3], [4, 5, 7])"],seeAlso:["number-theory.mod-exp","number-theory.mod-inv","number-theory.extended-gcd"]},"stirling-first":{category:"number-theory",description:"Calculates the Stirling numbers of the first kind, which count the number of permutations of n elements with k cycles.",returns:{type:"integer"},args:{a:{type:"integer",description:"The number of elements."},b:{type:"integer",description:"The number of cycles."}},variants:[{argumentNames:["a","b"]}],examples:["let { stirling-first } = import(number-theory);\nstirling-first(5, 2)","let { stirling-first } = import(number-theory);\nstirling-first(4, 3)","let { stirling-first } = import(number-theory);\nstirling-first(6, 1)","let { stirling-first } = import(number-theory);\nstirling-first(7, 4)","let { stirling-first } = import(number-theory);\nstirling-first(8, 5)"],seeAlso:["number-theory.stirling-second","number-theory.bell-seq","number-theory.count-permutations"]},"stirling-second":{category:"number-theory",description:"Calculates the Stirling numbers of the second kind, which count the number of ways to partition n elements into k non-empty subsets.",returns:{type:"integer"},args:{a:{type:"integer",description:"The number of elements."},b:{type:"integer",description:"The number of subsets."}},variants:[{argumentNames:["a","b"]}],examples:["let { stirling-second } = import(number-theory);\nstirling-second(5, 2)","let { stirling-second } = import(number-theory);\nstirling-second(4, 3)","let { stirling-second } = import(number-theory);\nstirling-second(6, 1)","let { stirling-second } = import(number-theory);\nstirling-second(7, 4)","let { stirling-second } = import(number-theory);\nstirling-second(8, 5)"],seeAlso:["number-theory.stirling-first","number-theory.bell-seq","number-theory.count-combinations"]}};function $i(e,t){if(0===t||t===e)return 1;let r=1;for(let n=0;n<t;n++)r*=(e-n)/(n+1);return r}function Ei(e,t){if(1===t)return e.map(e=>[e]);const r=[];for(let n=0;n<=e.length-t;n++){const o=e[n],a=Ei(e.slice(n+1),t-1);for(const e of a)r.push([o,...e])}return r}const Ti={combinations:{evaluate:([e,t],r)=>(ye(e,r),Y(t,r,{integer:!0,nonNegative:!0,lte:e.length}),0===t?[[]]:Ei(e,t)),arity:te(2)},"count-combinations":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0,nonNegative:!0}),Y(t,r,{integer:!0,nonNegative:!0,lte:e}),$i(e,t)),arity:te(2)}};const Si={derangements:{evaluate:([e],t)=>(ye(e,t),function(e){const t=e.length,r=[],n=Array.from({length:t},()=>!1),o=Array.from({length:t});return function a(i){if(i!==t)for(let r=0;r<t;r++)n[r]||r===i||(n[r]=!0,o[i]=e[r],a(i+1),n[r]=!1);else r.push([...o])}(0),r}(e)),arity:te(1)},"count-derangements":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),function(e){if(1===e)return 0;let t=1,r=0,n=0;for(let o=2;o<=e;o++)n=(o-1)*(t+r),t=r,r=n;return n}(e)),arity:te(1)}};function zi(e){const t=[];for(let r=1;r<=Math.sqrt(e);r++)e%r===0&&(t.push(r),r!==e/r&&t.push(e/r));return t}function ji(e){return zi(e).sort((e,t)=>e-t)}function Ci(e){return ji(e).slice(0,-1)}const Ii={divisors:{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),ji(e)),arity:te(1)},"count-divisors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),zi(e).length),arity:te(1)},"proper-divisors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),Ci(e)),arity:te(1)},"count-proper-divisors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),zi(e).length-1),arity:te(1)}},Ri=[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368e3,20922789888e3,355687428096e3,6402373705728e3];function Pi(e){if(e<0)throw new Error("Factorial is not defined for negative numbers");if(0===e||1===e)return 1;if(e<=18)return Ri[e];let t=Ri[18];for(let r=19;r<=e;r++)t*=r;return t}const Mi={factorial:{evaluate:([e],t)=>(Y(e,t,{integer:!0,nonNegative:!0,lte:170}),Pi(e)),arity:te(1)}},Oi=[1,2,3,5,7,11,15,22,30,42,56,77,101,135,176,231,297,385,490,627,792,1002,1255,1575,1958,2436,3010,3718,4565,5604,6842,8349,10143,12310,14883,17977,21637,26015,31185,37338,44583,53174,63261,75175,89134,105558,124754,147273,173525,204226,239943,281589,329931,386155,451276,526823,614154,715220,831820,966467,1121505,1300156,1505499,1741630,2012558,2323520,2679689,3087735,3554345,4087968,4697205,5392783,6185689,7089500,8118264,9289091,10619863,12132164,13848650,15796476,18004327,20506255,23338469,26543660,30167357,34262962,38887673,44108109,49995925,56634173,64112359,72533807,82010177,92669720,104651419,118114304,133230930,150198136,169229875,190569292,214481126,241265379,271248950,304801365,342325709,384276336,431149389,483502844,541946240,607163746,679903203,761002156,851376628,952050665,1064144451,1188908248,1327710076,1482074143,1653668665,1844349560,2056148051,2291320912,2552338241,2841940500,3163127352,3519222692,3913864295,4351078600,4835271870,5371315400,5964539504,6620830889,7346629512,8149040695,9035836076,10015581680,11097645016,12292341831,13610949895,15065878135,16670689208,18440293320,20390982757,22540654445,24908858009,27517052599,30388671978,33549419497,37027355200,40853235313,45060624582,49686288421,54770336324,60356673280,66493182097,73232243759,80630964769,88751778802,97662728555,107438159466,118159068427,129913904637,142798995930,156919475295,172389800255,189334822579,207890420102,228204732751,250438925115,274768617130,301384802048,330495499613,362326859895,397125074750,435157697830,476715857290,522115831195,571701605655,625846753120,684957390936,749474411781,819876908323,896684817527,980462880430,0xf98dace281,1171432692373,1280011042268,1398341745571,1527273599625,1667727404093,1820701100652,1987276856363,2168627105469,2366022741845,2580840212973,2814570987591,3068829878530,3345365983698,3646072432125,3972999029388,4328363658647,4714566886083,5134205287973,5590088317495,6085253859260,6622987708040,7206841706490,7840656226137,8528581302375,9275102575355,0x92c1cc50847,0x9f8afdf968b,0xad6918d4f36,0xbc72dde1287,0xccc0de0d1d7,0xde6da02b061,0xf195c5ba10a,18028182516671,19573856161145,21248279009367,23061871173849,25025873760111,27152408925615,29454549941750,31946390696157,34643126322519,37561133582570,40718063627362,44132934884255,47826239745920,51820051838712,56138148670947,60806135438329,65851585970275,71304185514919,77195892663512,83561103925871,90436839668817,97862933703585,0x604ca1b434ad,0x682ca0bc6d4e,0x70ad06a4328b,0x79da3e8e4df8,0x83c1a359c63d,0x8e7190d8114a,0x99f976fff202,0xa669edb53a4a,0xb3d4caca1bc8,0xc24d38b78151,0xd1e7cfd30909,0xe2bab064772f,0xf4dd9f8523e3,290726957916112,313891991306665,338854264248680,365749566870782,394723676655357,425933084409356,459545750448675,495741934760846,534715062908609,576672674947168,621837416509615,670448123060170,722760953690372,779050629562167,839611730366814,904760108316360,974834369944625,0x3bb262854d36d,0x404dafd2efa2e,0x4541ae2536f6d,0x4a94ddd83ba57,0x504e363fd1eca,0x56752ddfc97e7,0x5d11c356f6b53,0x642c86bff69f5,0x6bcea3db036a0,0x7401ecbfdbd63,0x7cd0e571c49d4,0x8646d010a1b6f,0x906fba0855202,0x9b5889f52508f,0xa70f0ea631153,0xb3a20ef033ec5,0xc1215ac210755,0xcf9ddd28cfa8d,0xdf29afbd9f60e,0xefd82f26a7157,4534253126900886,4872038056472084,5234371069753672,5622992691950605,6039763882095515,6486674127079088,6965850144195831,7479565078510584,8030248384943040,8620496275465025];const Vi={partitions:{evaluate:([e],t)=>(Y(e,t,{integer:!0,nonNegative:!0}),function(e){if(e<=0)return[[]];if(1===e)return[[1]];const t=[];return function e(r,n,o){if(0!==r)for(let t=Math.min(n,r);t>=1;t--)o.push(t),e(r-t,t,o),o.pop();else t.push([...o])}(e,e,[]),t}(e)),arity:te(1)},"count-partitions":{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,nonNegative:!0}),0===e)return 1;if(e>Oi.length)throw new o(`n is too large. The maximum value is ${Oi.length-1}.`,t);return Oi[e-1]},arity:te(1)}};function Di(e){if(0===e.length)return[[]];const t=[];for(let r=0;r<e.length;r++){const n=e[r],o=Di([...e.slice(0,r),...e.slice(r+1)]);for(const e of o)t.push([n,...e])}return t}const Ui={permutations:{evaluate:([e],t)=>(ye(e,t),Di(e)),arity:te(1)},"count-permutations":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0,nonNegative:!0}),Y(t,r,{integer:!0,nonNegative:!0,lte:e}),Pi(e)/Pi(e-t)),arity:te(2)}};const Fi={"power-set":{evaluate:([e],t)=>(ye(e,t),function(e){const t=[[]];for(const r of e){const e=t.map(e=>[...e,r]);t.push(...e)}return t}(e)),arity:te(1)},"count-power-set":{evaluate:([e],t)=>(Y(e,t,{integer:!0,nonNegative:!0}),e>=53?1/0:2**e),arity:te(1)}};function Wi(e){if(1===e)return[];const t=[];let r=2;for(;e>1;)e%r===0?(t.push(r),e/=r):r++;return t}const Gi={"prime-factors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),Wi(e)),arity:te(1)},"distinct-prime-factors":{evaluate:([e],t)=>{Y(e,t,{finite:!0,integer:!0,positive:!0});const r=Wi(e),n=new Set(r);return Array.from(n)},arity:te(1)},"count-prime-factors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),Wi(e).length),arity:te(1)},"count-distinct-prime-factors":{evaluate:([e],t)=>{Y(e,t,{finite:!0,integer:!0,positive:!0});const r=Wi(e);return new Set(r).size},arity:te(1)}};function Bi(e){return Ci(e).reduce((e,t)=>e+t,0)>e}const Li={"abundant-seq":e=>{const t=[];let r=2;for(;t.length<e;)Bi(r)&&t.push(r),r+=1;return t},"abundant?":e=>Bi(e),"abundant-take-while":e=>{const t=[];return function r(n){return Bi(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(2)}};const _i={"arithmetic-seq":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),Array.from({length:r},(r,n)=>e+n*t)),arity:te(3)},"arithmetic-take-while":{evaluate:([e,t,r],n,o,{executeFunction:a})=>{Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),F(r,n);const i=e,s=t,l=r,c=[];return function e(t){const r=i+t*s;return ft(a(l,[r,t],o,n),n=>n?(c.push(r),e(t+1)):c)}(0)},arity:te(3)},"arithmetic-nth":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),e+(r-1)*t),arity:te(3)},"arithmetic?":{evaluate:([e,t,r],n)=>(Y(r,n),Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),function(e,t,r){if(0===t)return he(r,e);const n=(r-e)/t;if(n<0)return!1;const o=Math.round(n),a=e+t*o;return he(n,o)&&he(a,r)}(e,t,r)),arity:te(3)}};function Ki(e){const t=[1];for(let r=1;r<e;r+=1){let e=0;for(let n=0;n<r;n+=1)e+=$i(r+1,n)*t[n];t[r]=r>1&&r%2==1?0:-e/(r+1)}return t}const Ji={"bernoulli-seq":{evaluate:([e],t)=>(Y(e,t,{integer:!0,positive:!0}),Ki(e)),arity:te(1)},"bernoulli-nth":{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});return Ki(e)[e-1]},arity:te(1)},"bernoulli-take-while":{evaluate:([e],t,r,{executeFunction:n})=>{F(e,t);const o=e;return function(e){const t=[1];return function r(n){let o=0;for(let e=0;e<n;e++)o+=$i(n+1,e)*t[e];const a=n>1&&n%2==1?0:-o/(n+1);return ft(e(a,n),e=>e?(t.push(a),r(n+1)):t)}(1)}((e,t)=>ft(n(o,[e,t],r),e=>!!e))},arity:te(1)}};function Hi(e){if(e<=1)return!1;if(e<=3)return!0;if(e%2==0||e%3==0)return!1;for(let t=5;t*t<=e;t+=6)if(e%t===0||e%(t+2)===0)return!1;return!0}const Yi={"prime-seq":e=>{const t=[];let r=2;for(;t.length<e;)Hi(r)&&t.push(r),r+=1;return t},"prime?":e=>Hi(e),"prime-take-while":e=>{const t=[];return function r(n){return Hi(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(2)}};function Xi(e){return!(e<=1)&&!Hi(e)}const Qi={"composite-seq":e=>{const t=[];let r=2;for(;t.length<e;)Xi(r)&&t.push(r),r+=1;return t},"composite?":e=>Xi(e),"composite-take-while":e=>{const t=[];return function r(n){return Xi(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(4)}};function Zi(e){return Ci(e).reduce((e,t)=>e+t,0)<e}const es={"deficient-seq":e=>{const t=[];let r=1;for(;t.length<e;)Zi(r)&&t.push(r),r+=1;return t},"deficient?":e=>Zi(e),"deficient-take-while":e=>{const t=[];return function r(n){return Zi(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(1)}};const ts={"geometric-seq":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),Array.from({length:r},(r,n)=>e*t**n)),arity:te(3)},"geometric-take-while":{evaluate:([e,t,r],n,o,{executeFunction:a})=>{Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),F(r,n);const i=e,s=t,l=r,c=[];return function e(t){const r=i*s**t;return ft(a(l,[r,t],o,n),n=>n?(c.push(r),e(t+1)):c)}(0)},arity:te(3)},"geometric-nth":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),e*t**(r-1)),arity:te(3)},"geometric?":{evaluate:([e,t,r],n)=>(Y(r,n),Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),function(e,t,r){if(he(e,0))return he(r,0);if(he(t,1))return he(r,e);if(he(t,0))return he(r,0)||he(r,e);if(he(r,e))return!0;if(he(t,-1))return he(r,e)||he(r,-e);if(t<0){const n=Math.log(Math.abs(r/e))/Math.log(Math.abs(t)),o=Math.round(n);if(!he(o,n)||o<0)return!1;const a=o%2==0?Math.sign(e):Math.sign(e)*Math.sign(t);return Math.sign(r)===a}if(t>1&&r<e||t<1&&r>e)return!1;const n=Math.log(r/e)/Math.log(t),o=Math.round(n);return!(!he(o,n)||o<0)&&he(e*t**o,r)}(e,t,r)),arity:te(3)}};const rs={"golomb-seq":e=>function(e){const t=[0,1];for(let r=2;r<=e;r+=1)t.push(1+t[r-t[t[r-1]]]);return t.slice(1)}(e),"golomb?":()=>!0,"golomb-take-while":e=>function(e){const t=[0,1];return ft(e(1,0),r=>r?function r(n){const o=1+t[n-t[t[n-1]]];return ft(e(o,n-1),e=>e?(t.push(o),r(n+1)):t.slice(1))}(2):[])}(e)};function ns(e){if(e<=0)return!1;const t=new Set;for(;1!==e&&!t.has(e);)t.add(e),e=os(e);return 1===e}function os(e){let t=0;for(;e>0;){const r=e%10;t+=r*r,e=Math.floor(e/10)}return t}const as={"happy-seq":e=>{const t=[];for(let r=1;t.length<e;r++){let e=r;const n=new Set;for(;1!==e&&!n.has(e);)n.add(e),e=String(e).split("").reduce((e,t)=>e+Number(t)**2,0);1===e&&t.push(r)}return t},"happy?":e=>ns(e),"happy-take-while":e=>{const t=[];return function r(n){return ns(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(1)}},is={"juggler-seq":e=>{let t=e;const r=[t];for(;t>1;)t=t%2==0?Math.floor(Math.sqrt(t)):Math.floor(t**1.5),r.push(t);return r},noNth:!0};function ss(e){let t="",r=1;for(let n=0;n<e.length;n++)n+1<e.length&&e[n]===e[n+1]?r++:(t+=r.toString()+e[n],r=1);return t}const ls={string:!0,"look-and-say-seq":e=>{const t=["1"];for(let r=1;r<e;r+=1){const e=t[r-1].replace(/(\d)\1*/g,e=>`${e.length}${e[0]}`);t[r]=e}return t},"look-and-say-take-while":e=>{const t=[];return ft(e("1",0),r=>{if(!r)return t;return t.push("1"),function r(n){const o=t[n-1].replace(/(\d)\1*/g,e=>`${e.length}${e[0]}`);return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(1)})},"look-and-say?":e=>function(e){let t="1";if(t===e)return!0;for(;;){if(t=ss(t),t===e)return!0;if(t.length>e.length)return!1}}(e)};function cs(e){const t=[];for(let e=1;e<=2e3;e++)t.push(e);let r=[1];for(let e=1;e<t.length;e++)t[e]%2!=0&&r.push(t[e]);const n=[1];let o=1;return ft(e(1,0),t=>{if(!t)return[];let a=1;return function t(){const i=r[a];return ft(e(i,o),e=>{if(!e)return n;n.push(i),o++;const s=i,l=[];for(let e=0;e<r.length;e++)(e+1)%s!==0&&l.push(r[e]);if(r=l,a++,a>=r.length-5){let e=r[r.length-1]+2;for(;r.length<a+1e3;)r.push(e),e+=2}return t()})}()})}const us={"lucky-seq":e=>function(e){const t=[];let r=1;const n=e*(e<100?20:30);for(;t.length<n;)t.push(r),r+=2;let o=1;for(;o<t.length&&o<e;){const e=t[o];let r=0;for(let n=0;n<t.length;n++)(n+1)%e!==0&&(t[r++]=t[n]);t.length=r,o<t.length&&o++}return t.slice(0,e)}(e),"lucky?":e=>cs(t=>t<=e).includes(e),"lucky-take-while":e=>cs(e)};const ms={"padovan-seq":e=>{const t=[1,1,1];for(let r=3;r<e;r+=1)t[r]=t[r-2]+t[r-3];return t.slice(0,e)},"padovan?":e=>function(e){if(!Number.isInteger(e)||e<=0)return!1;if(1===e)return!0;const t=[1,1,1,2,2,3,4,5,7,9,12,16,21,28,37,49,65,86,114,151,200,265,351,465,616,816,1081,1432,1897,2513,3329,4410,5842,7739,10252,13581,17991,23833,31572,41824,55405,73396,97229];if(t.includes(e))return!0;if(e>t[t.length-1]&&e<=Number.MAX_SAFE_INTEGER){let r,n=t[t.length-3],o=t[t.length-2],a=t[t.length-1];for(;a<e;){if(r=n+o,n=o,o=a,a=r,a===e)return!0;if(!Number.isSafeInteger(a))return!1}}return!1}(e),"padovan-take-while":e=>{const t=[];return ft(e(1,0),r=>r?(t.push(1),ft(e(1,1),r=>r?(t.push(1),ft(e(1,2),r=>{if(!r)return t;t.push(1);let n=1,o=1,a=1;return function r(i){const s=n+o;return n=o,o=a,a=s,ft(e(a,i),e=>e?(t.push(a),r(i+1)):t)}(4)})):t)):t)}},ps={"perfect-cube-seq":e=>{const t=[];for(let r=1;r<=e;r++)t.push(r**3);return t},"perfect-cube?":e=>e>0&&Number.isInteger(Math.cbrt(e)),"perfect-cube-take-while":e=>{const t=[];return function r(n){const o=n**3;return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(1)}};function ds(e){if(e<2)return 1===e?[1,2]:null;const t=Math.floor(Math.log2(e))+1;for(let r=2;r<=t;r++){const t=e**(1/r),n=Math.round(t);if(he(n**r,e))return[n,r]}return null}const hs={"perfect-power-seq":e=>{const t=[];for(let r=1;t.length<e;r++)ds(r)&&t.push(r);return t},"perfect-power?":e=>null!==ds(e),"perfect-power-take-while":e=>{const t=[];return function r(n){return ds(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(1)}},gs={"perfect-square-seq":e=>{const t=[];for(let r=1;r<=e;r++)t.push(r**2);return t},"perfect-square?":e=>e>0&&Number.isInteger(Math.sqrt(e)),"perfect-square-take-while":e=>{const t=[];return function r(n){const o=n**2;return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(1)}},fs={"polygonal-seq":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,gte:3}),Y(t,r,{integer:!0,positive:!0});const n=[];for(let r=1;r<=t;r+=1)n[r-1]=(r*r*(e-2)-r*(e-4))/2;return n},arity:te(2)},"polygonal-take-while":{evaluate:([e,t],r,n,{executeFunction:o})=>{Y(e,r,{integer:!0,gte:3}),F(t,r);const a=e,i=t,s=[];return function e(t){const l=(t*t*(a-2)-t*(a-4))/2;return ft(o(i,[l,t],n,r),r=>r?(s.push(l),e(t+1)):s)}(1)},arity:te(2)},"polygonal-nth":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0,gte:3}),Y(t,r,{integer:!0,positive:!0}),(t*t*(e-2)-t*(e-4))/2),arity:te(2)},"polygonal?":{evaluate:([e,t],r)=>{if(Y(t,r,{integer:!0}),Y(e,r,{integer:!0,gte:3}),t<=0)return!1;const n=e-2,o=e-4,a=8*n*t+o*o,i=Math.sqrt(a);if(!Number.isInteger(i))return!1;const s=i+o;if(s%(2*n)!=0)return!1;const l=s/(2*n);return Number.isInteger(l)&&l>0},arity:te(2)}};const ys={"recaman-seq":e=>function(e){if(1===e)return[0];const t=[0],r=new Set([0]);for(let n=1;n<e;n++){let e=t[n-1]-n;(e<=0||r.has(e))&&(e=t[n-1]+n),t.push(e),r.add(e)}return t}(e),"recaman-take-while":e=>{const t=[],r=new Set([0]);return ft(e(0,0),n=>{if(!n)return t;return t.push(0),function n(o){let a=t[o-1]-o;return(a<=0||r.has(a))&&(a=t[o-1]+o),ft(e(a,o),e=>e?(t.push(a),r.add(a),n(o+1)):t)}(1)})},"recaman?":()=>!0},vs={"thue-morse-seq":e=>{const t=[];for(let r=0;r<e;r+=1)t[r]=bs(r)%2;return t},"thue-morse-take-while":e=>{const t=[];return function r(n){const o=bs(n)%2;return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(0)},"thue-morse?":e=>1===e||0===e};function bs(e){let t=0;for(;e;)t+=1&e,e>>=1;return t}const ws={};function xs(e){for(const[t,r]of Object.entries(e)){if(ws[t])throw new Error(`Duplicate normal expression key found: ${t}`);ws[t]=r}}function ks(e,t){return{[`${e}-seq`]:As(e=>t.slice(0,e),t.length),[`${e}-take-while`]:Ns(e=>function r(n){return n>=t.length?t.slice(0,n):ft(e(t[n],n),e=>e?r(n+1):t.slice(0,n))}(0),t.length),[`${e}-nth`]:$s(()=>t,t.length),[`${e}?`]:Es(e=>t.includes(e))}}function qs(e){for(const[t,r]of Object.entries(e)){if(ws[t])throw new Error(`Duplicate normal expression key found: ${t}`);t.endsWith("seq")?(ws[t]=As(r,e.maxLength),e.noNth||(ws[t.replace(/seq$/,"nth")]=$s(r,e.maxLength))):t.endsWith("take-while")?ws[t]=Ns(r,e.maxLength):t.endsWith("?")&&(e.string?ws[t]=Ts(r):ws[t]=Es(r))}}function As(e,t){return{evaluate:(r,n)=>{const a=r[0]??t;Y(a,n,{integer:!0,positive:!0,lte:t});const i=e(a,n);if("number"==typeof i[0]&&i.some(e=>e>Number.MAX_SAFE_INTEGER))throw new o("Result exceeds maximum safe integer",n);return i},arity:"number"==typeof t?{max:1}:te(1)}}function Ns(e,t){return{evaluate:(t,r,n,{executeFunction:a})=>{const i=t[0];F(i,r);const s=e((e,t)=>ft(a(i,[e,t],n),e=>!!e),r);return ft(s,e=>{if("number"==typeof e[0]&&e.some(e=>e>Number.MAX_SAFE_INTEGER))throw new o("Result exceeds maximum safe integer",r);return e})},arity:"number"==typeof t?{max:1}:te(1)}}function $s(e,t){return{evaluate:(r,n)=>{const a=r[0];Y(a,n,{integer:!0,positive:!0,lte:t});const i=e(a,n);if("number"==typeof i[0]&&i.some(e=>e>Number.MAX_SAFE_INTEGER))throw new o("Result exceeds maximum safe integer",n);return i[a-1]},arity:te(1)}}function Es(e){return{evaluate:(t,r)=>{const n=t[0];return Y(n,r),e(n,r)},arity:te(1)}}function Ts(e){return{evaluate:(t,r)=>{const n=t[0];return G(n,r),e(n,r)},arity:te(1)}}function Ss(e,t){for(;0!==t;){const r=t;t=e%t,e=r}return Math.abs(e)}function zs(e,t){return Math.floor(e*t/Ss(e,t))}function js(e){if(1===e)return 1;const t=Wi(e);return new Set(t).size!==t.length?0:t.length%2==0?1:-1}function Cs(e,t){if(0===t)return[e,1,0];const[r,n,o]=Cs(t,e%t);return[r,o,n-Math.floor(e/t)*o]}function Is(e,t){const[r,n]=Cs(e,t);if(1!==r)throw new Error(`Modular inverse does not exist (gcd(${e}, ${t}) = ${r})`);return(n%t+t)%t}qs(Li),qs({"collatz-seq":e=>{let t=e;const r=[t];for(;1!==t;)t%2==0?t/=2:t=3*t+1,r.push(t);return r},noNth:!0}),qs(Qi),qs(es),qs(rs),qs(as),qs(is),qs(ls),qs(us),qs(ms),qs(gs),qs(ps),qs(hs),qs(Yi),qs(ys),qs(vs),xs(ks("tribonacci",[0,1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136,5768,10609,19513,35890,66012,121415,223317,410744,755476,1389537,2555757,4700770,8646064,15902591,29249425,53798080,98950096,181997601,334745777,615693474,1132436852,2082876103,3831006429,7046319384,12960201916,23837527729,43844049029,80641778674,148323355432,272809183135,501774317241,922906855808,1697490356184,3122171529233,5742568741225,0x99b36012952,19426970897100,35731770264967,65720971788709,0x6df08059d9f8,0xca35cf00a924,408933139743937,752145307699165,0x4ea34736b35c2,0x90a3317d5c260,4680045560037375,8607945812375585])),xs(ks("catalan",[1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790,477638700,1767263190,6564120420,24466267020,91482563640,343059613650,1289904147324,4861946401452,18367353072152,69533550916004,0xefe09af96cd8,0x38f88b34d6a68,0xd8db5c347b610])),xs(ks("factorial",Ri)),xs(ks("fibonacci",[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,0x9a661ca20bb,0xf9d297a859d,27777890035288,44945570212853,72723460248141,0x6b04f4c2fe42,0xad2934c6d08f,308061521170129,498454011879264,806515533049393,0x4a2dce62b0d91,0x780626e057bc2,0xc233f54308953,5527939700884757,8944394323791464])),xs(ks("lucas",[2,1,3,4,7,11,18,29,47,76,123,199,322,521,843,1364,2207,3571,5778,9349,15127,24476,39603,64079,103682,167761,271443,439204,710647,1149851,1860498,3010349,4870847,7881196,12752043,20633239,33385282,54018521,87403803,141422324,228826127,370248451,599074578,969323029,1568397607,2537720636,4106118243,6643838879,10749957122,17393796001,28143753123,45537549124,73681302247,119218851371,192900153618,312119004989,505019158607,817138163596,1322157322203,2139295485799,3461452808002,5600748293801,9062201101803,0xd55fbe3dc94,23725150497407,38388099893011,62113250390418,0x5b67cb4878a5,0x93e5a9822a37,0xef4d74caa2dc,425730551631123,688846502588399,0x3f5b3b1643d02,0x66834447bacf1,0xa5de7f5dfe9f3,4721424167835364,7639424778862807])),xs(ks("mersenne",[3,7,31,127,2047,8191,131071,524287,2147483647])),xs(ks("partition",Oi)),xs(ks("pell",[1,2,5,12,29,70,169,408,985,2378,5741,13860,33461,80782,195025,470832,1136689,2744210,6625109,15994428,38613965,93222358,225058681,543339720,1311738121,3166815962,7645370045,18457556052,44560482149,107578520350,259717522849,627013566048,1513744654945,3654502875938,8822750406821,21300003689580,51422757785981,0x70e8e1937766,299713796309065,723573111879672,0x634c28af7f039,0xefb9b143d586a])),xs(ks("perfect",[6,28,496,8128,33550336,8589869056,137438691328])),xs(ks("sylvester",[2,6,42,1806,3263442,0x9afa8dc8416])),xs(ks("bell",[1,2,5,15,52,203,877,4140,21147,115975,678570,4213597,27644437,190899322,1382958545,10480142147,82864869804,682076806159,5832742205057,51724158235372,474869816156751,4506715738447323])),xs(_i),xs(Ji),xs(ts),xs(fs);const Rs={"coprime?":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0}),1===Ss(e,t)),arity:te(2)},"divisible-by?":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0}),0!==t&&e%t===0),arity:te(2)},gcd:{evaluate:([e,t],r)=>(Y(e,r),Y(t,r),Ss(e,t)),arity:te(2)},lcm:{evaluate:([e,t],r)=>(Y(e,r),Y(t,r),zs(e,t)),arity:te(2)},multinomial:{evaluate:([...e],t)=>{Ce(e,t);return Pi(e.reduce((e,r)=>(Y(r,t,{integer:!0,nonNegative:!0}),e+r),0))/e.reduce((e,t)=>e*Pi(t),1)},arity:{min:1}},"amicable?":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0});const n=Ci(e).reduce((e,t)=>e+t,0),o=Ci(t).reduce((e,t)=>e+t,0);return n===t&&o===e&&e!==t},arity:te(2)},"euler-totient":{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});let r=e;for(let t=2;t*t<=e;t+=1)if(e%t===0){for(;e%t===0;)e/=t;r-=r/t}return e>1&&(r-=r/e),r},arity:te(1)},mobius:{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,positive:!0}),1===e)return 1;const r=Wi(e);return new Set(r).size!==r.length?0:r.length%2==0?1:-1},arity:te(1)},mertens:{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,positive:!0}),1===e)return 1;let r=0;for(let t=1;t<=e;t++){r+=js(t)}return r},arity:te(1)},sigma:{evaluate:([e],t)=>(Y(e,t,{integer:!0,positive:!0}),ji(e).reduce((e,t)=>e+t,0)),arity:te(1)},"carmichael-lambda":{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,positive:!0}),1===e)return 1;const r=Wi(e),n=new Map;for(const e of r)n.set(e,(n.get(e)||0)+1);const o=[];for(const[e,t]of n.entries())2===e?1===t?o.push(1):2===t?o.push(2):o.push(2**(t-2)):o.push((e-1)*e**(t-1));return o.reduce((e,t)=>zs(e,t),1)},arity:te(1)},"cartesian-product":{evaluate:(e,t)=>{e.forEach(e=>{ye(e,t)});return e.reduce((e,t)=>{const r=[];return e.forEach(e=>{t.forEach(t=>{r.push([...e,t])})}),r},[[]])},arity:{min:1}},"perfect-power":{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});return ds(e)||null},arity:te(1)},"mod-exp":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{integer:!0,positive:!0}),Y(r,n,{integer:!0,positive:!0}),function(e,t,r){if(1===r)return 0;let n=1;for(e%=r;t>0;)t%2==1&&(n=n*e%r),t>>=1,e=e*e%r;return n}(e,t,r)),arity:te(3)},"mod-inv":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0});try{return Is(e,t)}catch(e){throw new o(e,r)}},arity:te(2)},"extended-gcd":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0}),Cs(e,t)),arity:te(2)},"chinese-remainder":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length!==t.length)throw new o("Remainders and moduli must have the same length.",r);try{return function(e,t){for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++){const n=Cs(t[e],t[r])[0];if(1!==n)throw new Error(`Moduli must be pairwise coprime, but gcd(${t[e]}, ${t[r]}) = ${n}`)}const r=t.reduce((e,t)=>e*t,1);let n=0;for(let o=0;o<e.length;o++){const a=e[o],i=t[o],s=r/i;n=(n+a*s*Is(s,i))%r}return n}(e,t)}catch(e){throw new o(e.message,r)}},arity:te(2)},"stirling-first":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0,lte:e});const n=Array.from({length:e+1},()=>Array(t+1).fill(0));n[0][0]=1;for(let r=1;r<=e;r++)for(let e=1;e<=Math.min(r,t);e++)n[r][e]=n[r-1][e-1]+(r-1)*n[r-1][e];return n[e][t]},arity:te(2)},"stirling-second":{evaluate:([e,t],r)=>{if(Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0,lte:e}),1===t)return 1;if(t===e)return 1;const n=Array.from({length:e+1},()=>Array(t+1).fill(0));n[0][0]=1;for(let r=1;r<=e;r++)for(let e=1;e<=Math.min(r,t);e++)n[r][e]=e*n[r-1][e]+n[r-1][e-1];return n[e][t]},arity:te(2)}};function Ps(e){for(const[t,r]of Object.entries(e)){if(Rs[t])throw new Error(`Duplicate normal expression key found: ${t}`);Rs[t]=r}}!function(e){for(const[t,r]of Object.entries(e)){if(Rs[t])throw new Error(`Duplicate normal expression key found: ${t}`);Rs[t]=r}}(ws),Ps(Mi),Ps(Ii),Ps(Ti),Ps(Ui),Ps(Vi),Ps(Gi),Ps(Si),Ps(Fi);for(const[e,t]of Object.entries(Ni))Rs[e]&&(Rs[e].docs=t);const Ms={name:"number-theory",functions:Rs,source:"{}",docs:Ni};function Os(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{if(!t.docs)throw new Error(`Missing docs for function "${e}"`);return[e,t.docs]}))}function Vs(e){return([t],r)=>{const[n,a]=function(e,t){if(je(e))return["vector",e];if(Ve(e))return["matrix",e];if(!H(e))throw new o("Invalid parameter type: "+typeof e,t);return["number",e]}(t,r);return"number"===n?e(a):"vector"===n?a.map(t=>e(t)):a.map(t=>t.map(t=>e(t)))}}const Ds={sin:{evaluate:Vs(e=>Math.sin(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sin` function computes the sine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the sine of each element while preserving the original structure.",seeAlso:["math.asin","math.sinh","math.cos","math.tan","math.to-rad"],examples:["let { sin } = import(math);\nsin(0)","let { sin } = import(math);\nsin(1)","let { sin } = import(math);\nsin(PI)","let { sin } = import(math);\nsin(-0.5)","let { sin } = import(math);\nsin([1, 2, 3])","let { sin } = import(math);\nsin([[1, 2], [3, 4]])"]}},asin:{evaluate:Vs(e=>Math.asin(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `asin` function computes the arcsine (inverse sine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arcsine of each element while preserving the original structure.",seeAlso:["math.sin","math.asinh","math.acos","math.atan"],examples:["let { asin } = import(math);\nasin(0)","let { asin } = import(math);\nasin(1)","let { asin } = import(math);\nasin(-0.5)","let { asin } = import(math);\nasin([1, 2, 3])","let { asin } = import(math);\nasin([[1, 2], [3, 4]])"]}},sinh:{evaluate:Vs(e=>Math.sinh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sinh` function computes the hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic sine of each element while preserving the original structure.",seeAlso:["math.asinh","math.sin","math.cosh","math.tanh"],examples:["let { sinh } = import(math);\nsinh(0)","let { sinh } = import(math);\nsinh(1)","let { sinh } = import(math);\nsinh(-0.5)","let { sinh } = import(math);\nsinh([0.1, 0.2, 0.3])","let { sinh } = import(math);\nsinh([[0.1, 0.2], [0.3, 0.4]])"]}},asinh:{evaluate:Vs(e=>Math.asinh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `asinh` function computes the inverse hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic sine of each element while preserving the original structure.",seeAlso:["math.sinh","math.asin","math.acosh","math.atanh"],examples:["let { asinh } = import(math);\nasinh(10)","let { asinh } = import(math);\nasinh(90)","let { asinh } = import(math);\nasinh(50)","let { asinh } = import(math);\nasinh([10, 20, 30])","let { asinh } = import(math);\nasinh([[10, 20], [30, 40]])"]}},cos:{evaluate:Vs(e=>Math.cos(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cos` function computes the cosine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the cosine of each element while preserving the original structure.",seeAlso:["math.acos","math.cosh","math.sin","math.tan","math.to-rad"],examples:["let { cos } = import(math);\ncos(0)","let { cos } = import(math);\ncos(1)","let { cos } = import(math);\ncos(PI)","let { cos } = import(math);\ncos(-0.5)","let { cos } = import(math);\ncos([1, 2, 3])","let { cos } = import(math);\ncos([[1, 2], [3, 4]])"]}},acos:{evaluate:Vs(e=>Math.acos(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `acos` function computes the arccosine (inverse cosine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arccosine of each element while preserving the original structure.",seeAlso:["math.cos","math.acosh","math.asin","math.atan"],examples:["let { acos } = import(math);\nacos(0)","let { acos } = import(math);\nacos(1)","let { acos } = import(math);\nacos(-0.5)","let { acos } = import(math);\nacos([0.1, 0.2, 0.3])","let { acos } = import(math);\nacos([[0.1, 0.2], [0.3, 0.4]])"]}},cosh:{evaluate:Vs(e=>Math.cosh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cosh` function computes the hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic cosine of each element while preserving the original structure.",seeAlso:["math.acosh","math.cos","math.sinh","math.tanh"],examples:["let { cosh } = import(math);\ncosh(0)","let { cosh } = import(math);\ncosh(1)","let { cosh } = import(math);\ncosh(-0.5)","let { cosh } = import(math);\ncosh([0.1, 0.2, 0.3])","let { cosh } = import(math);\ncosh([[0.1, 0.2], [0.3, 0.4]])"]}},acosh:{evaluate:Vs(e=>Math.acosh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `acosh` function computes the inverse hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic cosine of each element while preserving the original structure.",seeAlso:["math.cosh","math.acos","math.asinh","math.atanh"],examples:["let { acosh } = import(math);\nacosh(1)","let { acosh } = import(math);\nacosh(2)","let { acosh } = import(math);\nacosh(100)","let { acosh } = import(math);\nacosh(50)","let { acosh } = import(math);\nacosh([1, 2, 3])","let { acosh } = import(math);\nacosh([[1, 2], [3, 4]])"]}},tan:{evaluate:Vs(e=>Math.tan(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `tan` function computes the tangent of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the tangent of each element while preserving the original structure.",seeAlso:["math.atan","math.tanh","math.sin","math.cos","math.to-rad"],examples:["let { tan } = import(math);\ntan(0)","let { tan } = import(math);\ntan(1)","let { tan } = import(math);\ntan(PI)","let { tan } = import(math);\ntan(-0.5)","let { tan } = import(math);\ntan([1, 2, 3])","let { tan } = import(math);\ntan([[1, 2], [3, 4]])"]}},atan:{evaluate:Vs(e=>Math.atan(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `atan` function computes the arctangent (inverse tangent) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arctangent of each element while preserving the original structure.",seeAlso:["math.tan","math.atanh","math.asin","math.acos"],examples:["let { atan } = import(math);\natan(0)","let { atan } = import(math);\natan(1)","let { atan } = import(math);\natan(-0.5)","let { atan } = import(math);\natan([0.1, 0.2, 0.3])","let { atan } = import(math);\natan([[0.1, 0.2], [0.3, 0.4]])"]}},tanh:{evaluate:Vs(e=>Math.tanh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `tanh` function computes the hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic tangent of each element while preserving the original structure.",seeAlso:["math.atanh","math.tan","math.sinh","math.cosh"],examples:["let { tanh } = import(math);\ntanh(0)","let { tanh } = import(math);\ntanh(1)","let { tanh } = import(math);\ntanh(-0.5)","let { tanh } = import(math);\ntanh(50)"]}},atanh:{evaluate:Vs(e=>Math.atanh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `atanh` function computes the inverse hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic tangent of each element while preserving the original structure.",seeAlso:["math.tanh","math.atan","math.asinh","math.acosh"],examples:["let { atanh } = import(math);\natanh(0)","let { atanh } = import(math);\natanh(0.9)","let { atanh } = import(math);\natanh(-0.5)","let { atanh } = import(math);\natanh([0.1, 0.2, 0.3])","let { atanh } = import(math);\natanh([[0.1, 0.2], [0.3, 0.4]])"]}},ln:{evaluate:Vs(e=>Math.log(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `ln` function computes the natural logarithm (base `e`) of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the natural logarithm of each element while preserving the original structure.",seeAlso:["math.log2","math.log10","^"],examples:["let { ln } = import(math);\nln(0.01)","let { ln } = import(math);\nln(2.5)","let { ln } = import(math);\nln(E)","let { ln } = import(math);\nln([1, 2, 3])","let { ln } = import(math);\nln([[1, 2], [3, 4]])"]}},log2:{evaluate:Vs(e=>Math.log2(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `log2` function computes the base `2` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-2 logarithm of each element while preserving the original structure.",seeAlso:["math.ln","math.log10"],examples:["let { log2 } = import(math);\nlog2(0.01)","let { log2 } = import(math);\nlog2(2 ^ 12)","let { log2 } = import(math);\nlog2(2.5)","let { log2 } = import(math);\nlog2([1, 2, 3])","let { log2 } = import(math);\nlog2([[1, 2], [3, 4]])"]}},log10:{evaluate:Vs(e=>Math.log10(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `log10` function computes the base `10` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-10 logarithm of each element while preserving the original structure.",seeAlso:["math.ln","math.log2"],examples:["let { log10 } = import(math);\nlog10(0.01)","let { log10 } = import(math);\nlog10(10 ^ 12)","let { log10 } = import(math);\nlog10(2.5)","let { log10 } = import(math);\nlog10([1, 2, 3])","let { log10 } = import(math);\nlog10([[1, 2], [3, 4]])"]}},"to-rad":{evaluate:Vs(e=>e*Math.PI/180),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `to-rad` function converts an angle from degrees to radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.",seeAlso:["math.to-deg","math.sin","math.cos","math.tan"],examples:["let { to-rad } = import(math);\nto-rad(0)","let { to-rad } = import(math);\nto-rad(90)","let { to-rad } = import(math);\nto-rad(180)","let { to-rad } = import(math);\nto-rad(360)","let { to-rad } = import(math);\nto-rad([0, 90, 180])","let { to-rad } = import(math);\nto-rad([[0, 90], [180, 360]])"]}},"to-deg":{evaluate:Vs(e=>180*e/Math.PI),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `to-deg` function converts an angle from radians to degrees, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.",seeAlso:["math.to-rad"],examples:["let { to-deg } = import(math);\nto-deg(0)","let { to-deg } = import(math);\nto-deg(PI)","let { to-deg } = import(math);\nto-deg(PI / 2)","let { to-deg } = import(math);\nto-deg(3 * PI / 2)","let { to-deg } = import(math);\nto-deg([0, PI, PI / 2])","let { to-deg } = import(math);\nto-deg([[0, PI], [PI / 2, 3 * PI / 2]])"]}}},Us={name:"math",functions:Ds,source:"{}",docs:Os(Ds)};const Fs={juxt:{evaluate:(e,t)=>{e.forEach(e=>F(e,t));const r=function(e){return e.reduce((e,t)=>{if(null===e)return null;const r="number"==typeof t||I(t)?te(1):t.arity,{min:n,max:o}=r,{min:a,max:i}=e,s="number"==typeof n&&"number"==typeof a?Math.max(n,a):"number"==typeof n?n:"number"==typeof a?a:void 0,l="number"==typeof o&&"number"==typeof i?Math.min(o,i):"number"==typeof o?o:"number"==typeof i?i:void 0;return"number"==typeof s&&"number"==typeof l&&s>l?null:{min:s,max:l}},{})}(e);if(null===r)throw new o("All functions must accept the same number of arguments",t);return{[p]:!0,sourceCodeInfo:t,functionType:"Juxt",params:e,arity:r}},arity:{min:1},docs:{category:"functional",returns:{type:"function"},args:{a:{type:"function"},b:{type:"function"},fun:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","fns"]}],description:"Takes one or many function and returns a function that is the juxtaposition of those functions.\nThe returned function takes a variable number of args,\nand returns a vector containing the result of applying each function to the args (left-to-right).",seeAlso:["comp"],examples:["let { juxt } = import(functional);\njuxt(+, *, min, max)(\n 3,\n 4,\n 6,\n)",'let { juxt } = import(functional);\njuxt("a", "b")(\n {\n a: 1,\n b: 2,\n c: 3,\n d: 4\n }\n)',"let { juxt } = import(functional);\njuxt(+, *, min, max) apply range(1, 11)"]}},complement:{evaluate:([e],t)=>{const r=U(e,t);return{[p]:!0,sourceCodeInfo:t,functionType:"Complement",function:r,arity:Z(r)}},arity:te(1),docs:{category:"functional",returns:{type:"function"},args:{fun:{type:"function"}},variants:[{argumentNames:["fun"]}],description:"Takes a function $fun and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.",seeAlso:["comp","functional.every-pred","functional.some-pred"],examples:["let { complement } = import(functional);\ncomplement(>)(1, 3)","let { complement } = import(functional);\ncomplement(<)(1, 3)","let { complement } = import(functional);\ncomplement(+)(1, 3)","let { complement } = import(functional);\ncomplement(+)(0, 0)"]}},"every-pred":{evaluate:(e,t)=>({[p]:!0,sourceCodeInfo:t,functionType:"EveryPred",params:e,arity:{min:1,max:1}}),arity:{min:1},docs:{category:"functional",returns:{type:"function"},args:{fun:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","fns"]}],description:"\nTakes a number of predicates and returns a function that returns `true` if all predicates\nreturn a truthy value against all of its arguments, else it returns `false`.",seeAlso:["functional.some-pred","functional.complement","collection.every?"],examples:['let { every-pred } = import(functional);\nevery-pred(string?, -> count($) > 3)(\n "Albert",\n "Mojir"\n)','let { every-pred } = import(functional);\n(string? every-pred -> count($) > 3)(\n "Albert",\n "M"\n)'],hideOperatorForm:!0}},"some-pred":{evaluate:(e,t)=>({[p]:!0,sourceCodeInfo:t,functionType:"SomePred",params:e,arity:{min:1,max:1}}),arity:{min:1},docs:{category:"functional",returns:{type:"function"},args:{fun:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","fns"]}],description:"Takes a number of `predicates` and returns a function that returns `true` if at least one of the `predicates` return a truthy `true` value against at least one of its arguments, else it returns `false`.",seeAlso:["functional.every-pred","functional.complement","collection.any?"],examples:['let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)("Albert", "Mojir")','let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)("a", "M")','let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)("a", [1, 2, 3])',"let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)([1, 2, 3], [2])"],hideOperatorForm:!0}},fnull:{evaluate:([e,...t],r)=>{const n=U(e,r);return{[p]:!0,sourceCodeInfo:r,functionType:"Fnull",function:n,params:t,arity:Z(n)}},arity:{min:2},docs:{category:"functional",returns:{type:"function"},args:{a:{type:"function"},b:{type:"any"},fun:{type:"function"},arg:{type:"any"},args:{type:"any",rest:!0}},variants:[{argumentNames:["fun","arg"]},{argumentNames:["fun","arg","args"]}],description:"Takes a function $fun, and returns a function that calls $fun, replacing a null argument to the corresponding argument.",seeAlso:["identity","constantly"],examples:["let { fnull } = import(functional);\nfnull(inc, 0)(1)","let { fnull } = import(functional);\nfnull(inc, 0)(null)","let { fnull } = import(functional);\n(inc fnull 0)(null)","let { fnull } = import(functional);\nfnull(+, 1, 2)(null, 0)","let { fnull } = import(functional);\nfnull(+, 1, 2)(0, null)","let { fnull } = import(functional);\nfnull(+, 1, 2)(null, null)","let { fnull } = import(functional);\nfnull(+, 1, 2)(null, null, 3, 4)"]}}},Ws={name:"functional",functions:Fs,source:"{}",docs:Os(Fs)};const Gs={"string-repeat":{evaluate:([e,t],r)=>(G(e,r),Y(t,r,{integer:!0,nonNegative:!0}),e.repeat(t)),arity:te(2),docs:{category:"string",returns:{type:"string"},args:{a:{type:"string"},b:{type:"integer"},s:{type:"string"},n:{type:"integer"}},variants:[{argumentNames:["s","n"]}],description:"Repeates $s $n times.",seeAlso:["str","repeat"],examples:['let { string-repeat } = import(string);\n"*" string-repeat 10','let { string-repeat } = import(string);\nstring-repeat("*", 10)','let { string-repeat } = import(string);\nstring-repeat("***", 0)']}},"from-char-code":{evaluate:([e],t)=>{Y(e,t,{finite:!0});const r=se(e);try{return String.fromCodePoint(r)}catch(e){throw new o(e,t)}},arity:te(1),docs:{category:"string",returns:{type:"string"},args:{code:{type:"number"}},variants:[{argumentNames:["code"]}],description:"Return character for code point $code.",seeAlso:["string.to-char-code"],examples:["let { from-char-code } = import(string);\nfrom-char-code(65)","let { from-char-code } = import(string);\nfrom-char-code(0)"]}},"to-char-code":{evaluate:([e],t)=>(G(e,t,{nonEmpty:!0}),w(e.codePointAt(0),t)),arity:te(1),docs:{category:"string",returns:{type:"number"},args:{c:{type:"string"}},variants:[{argumentNames:["c"]}],description:"Return code point for first character in $c.",seeAlso:["string.from-char-code"],examples:['let { to-char-code } = import(string);\nto-char-code("A")','let { to-char-code } = import(string);\nto-char-code("Albert")']}},"trim-left":{evaluate:([e],t)=>(G(e,t),e.replace(/^\s+/,"")),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a new string with leading whitespaces removed.",seeAlso:["trim","string.trim-right"],examples:['let { trim-left } = import(string);\ntrim-left(" Albert ")','let { trim-left } = import(string);\ntrim-left(" ")','let { trim-left } = import(string);\ntrim-left("")']}},"trim-right":{evaluate:([e],t)=>(G(e,t),e.replace(/\s+$/,"")),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a new string with trailing whitespaces removed.",seeAlso:["trim","string.trim-left"],examples:['let { trim-right } = import(string);\ntrim-right(" Albert ")','let { trim-right } = import(string);\ntrim-right(" ")','let { trim-right } = import(string);\ntrim-right("")']}},"split-lines":{evaluate:([e],t)=>(G(e,t),e.split(/\r\n|\n|\r/).filter(e=>""!==e)),arity:te(1),docs:{category:"string",returns:{type:"string",array:!0},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Divides $s into an array of substrings, each representing a line.",seeAlso:["split"],examples:['let { split-lines } = import(string);\nsplit-lines("Albert\nMojir\n")','let { split-lines } = import(string);\nsplit-lines("Albert\n\nMojir")','let { split-lines } = import(string);\nsplit-lines("Albert\nMojir\n\n")','let { split-lines } = import(string);\nsplit-lines("")']}},"pad-left":{evaluate:([e,t,r],n)=>(G(e,n),Y(t,n,{integer:!0}),void 0!==r&&G(r,n),e.padStart(t,r)),arity:{min:2,max:3},docs:{category:"string",returns:{type:"string"},args:{a:{type:"string"},b:{type:"integer"},s:{type:"string"},length:{type:"integer"},padString:{type:"string"}},variants:[{argumentNames:["s","length"]},{argumentNames:["s","length","padString"]}],description:"Pads from the start of $s with `padString` (multiple times, if needed) until the resulting string reaches the given $length.",seeAlso:["string.pad-right"],examples:['let { pad-left } = import(string);\n"Albert" pad-left 20','let { pad-left } = import(string);\npad-left("Albert", 20)','let { pad-left } = import(string);\npad-left("Albert", 20, "-*-")','let { pad-left } = import(string);\npad-left("Albert", 5)','let { pad-left } = import(string);\npad-left("Albert", -1)']}},"pad-right":{evaluate:([e,t,r],n)=>(G(e,n),Y(t,n,{integer:!0}),void 0!==r&&G(r,n),e.padEnd(t,r)),arity:{min:2,max:3},docs:{category:"string",returns:{type:"string"},args:{a:{type:"string"},b:{type:"integer"},s:{type:"string"},length:{type:"integer"},padString:{type:"string"}},variants:[{argumentNames:["s","length"]},{argumentNames:["s","length","padString"]}],description:"Pads from the start of $s with `padString` (multiple times, if needed) until the resulting string reaches the given `length`.",seeAlso:["string.pad-left"],examples:['let { pad-right } = import(string);\n"Albert" pad-right 20','let { pad-right } = import(string);\npad-right("Albert", 20)','let { pad-right } = import(string);\npad-right("Albert", 20, "-*-")','let { pad-right } = import(string);\npad-right("Albert", 5)','let { pad-right } = import(string);\npad-right("Albert", -1)']}},template:{evaluate:([e,...t],r)=>{G(e,r),ye(t,r);const n=e.split("||||");if(n.length<=1)return Ls(n[0],t,r);{const e=t[0];Y(e,r,{integer:!0,nonNegative:!0});const o=[`${e}`,...t.slice(1)];if(2===n.length){return Ls(n[1===e?0:1],o,r)}return Ls(n[Math.min(e,n.length-1)],o,r)}},arity:{min:1,max:10},docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"},params:{type:"any",rest:!0}},variants:[{argumentNames:["s","params"]}],description:"Applies placeholders to a string. Support for basic pluralization - see examples. If pluralization is used, first placeholder must be a number.",seeAlso:["str"],examples:['let { template } = import(string);\ntemplate("Hi, $1 and $2", "Carl", "Larry")','let { template } = import(string);\ntemplate("Hi $1, $2, $3, $4, $5, $6, $7, $8 and $9", "A", "B", "C", "D", "E", "F", "G", "H", "I")','let { template } = import(string);\ntemplate("$1 book||||$1 books", 0)','let { template } = import(string);\ntemplate("$1 book||||$1 books", 1)','let { template } = import(string);\ntemplate("$1 book||||$1 books", 2)','let { template } = import(string);\ntemplate("No book||||$1 book||||$1 books", 0)','let { template } = import(string);\ntemplate("No book||||$1 book||||$1 books", 1)','let { template } = import(string);\ntemplate("No book||||$1 book||||$1 books", 10)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 0)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 1)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 2)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 3)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 4)'],hideOperatorForm:!0}},"encode-base64":{evaluate:([e],t)=>(G(e,t),btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16))))),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a Base64 encoded string from $s.",seeAlso:["string.decode-base64"],examples:['let { encode-base64 } = import(string);\nencode-base64("Albert")']}},"decode-base64":{evaluate:([e],t)=>{G(e,t);try{return decodeURIComponent(Array.prototype.map.call(atob(e),e=>`%${`00${e.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""))}catch(e){throw new o(e,t)}},arity:te(1),docs:{category:"string",returns:{type:"string"},args:{base64string:{type:"string"}},variants:[{argumentNames:["base64string"]}],description:"Returns a Base64 decoded string from $base64string.",seeAlso:["string.encode-base64"],examples:['let { decode-base64 } = import(string);\ndecode-base64("QWxiZXJ0IPCfkLs=")']}},"encode-uri-component":{evaluate:([e],t)=>(G(e,t),encodeURIComponent(e)),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns an escaped `URI` string.",seeAlso:["string.decode-uri-component"],examples:['let { encode-uri-component } = import(string);\nencode-uri-component("Hi everyone!?")']}},"decode-uri-component":{evaluate:([e],t)=>{G(e,t);try{return decodeURIComponent(e)}catch(e){throw new o(e,t)}},arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns an un-escaped `URI` string.",seeAlso:["string.encode-uri-component"],examples:['let { decode-uri-component } = import(string);\ndecode-uri-component("Hi%20everyone!%3F%20%F0%9F%91%8D")']}},capitalize:{evaluate:([e],t)=>(G(e,t),e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns $s with the first character converted to uppercase and the rest to lowercase.",seeAlso:["lower-case","upper-case"],examples:['let { capitalize } = import(string);\ncapitalize("albert")','let { capitalize } = import(string);\ncapitalize("ALBERT")','let { capitalize } = import(string);\ncapitalize("aLBERT")','let { capitalize } = import(string);\ncapitalize("")']}}},Bs=/\$\$/g;function Ls(e,t,r){for(let n=0;n<9;n+=1){const o=new RegExp(`(\\$\\$|[^$]|^)\\$${n+1}`,"g");if(o.test(e)){const a=_(t[n],r);e=e.replace(o,`$1${a}`)}}return e=e.replace(Bs,"$")}const _s={name:"string",functions:Gs,source:"{}",docs:Os(Gs)};function Ks(e,t){if(j(e)){if("string"==typeof t&&oe(e,t))return le(e[t])}else if(H(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return le(e[t])}function Js(e,t,r,n){if(P(e,n),Array.isArray(e)||"string"==typeof e){if(Y(t,n,{integer:!0}),Y(t,n,{gte:0}),Y(t,n,{lte:e.length}),"string"==typeof e)return G(r,n,{char:!0}),`${e.slice(0,t)}${r}${e.slice(t+1)}`;const o=[...e];return o[t]=r,o}G(t,n);const o={...e};return o[t]=r,o}const Hs={"get-in":{evaluate:(e,t)=>{let r=le(e[0]);const n=e[1]??[],o=le(e[2]);ye(n,t);for(const e of n){if(K(e,t),!I(r))return o;{const t=Ks(r,e);if(void 0===t)return o;r=t}}return r},arity:{min:2,max:3},docs:{category:"collection",returns:{type:"any"},args:{a:{type:"collection"},b:{type:"array"},"not-found":{type:"any"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","not-found"]}],description:"Returns the value in a nested collection, where $b is an array of keys. Returns $not-found if the key is not present. If $not-found is not set, `null` is returned.",seeAlso:["get","collection.assoc-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "a", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0],\n "Lisa"\n)']}},"assoc-in":{evaluate:([e,t,r],n)=>{if(P(e,n),ye(t,n),E(r,n),1===t.length)return K(t[0],n),Js(e,t[0],r,n);const{coll:o,innerCollMeta:a}=function(e,t,r){const n=ue(e);return{coll:n,innerCollMeta:t.slice(0,t.length-1).reduce((e,t)=>{const n=e.coll;let o;return Array.isArray(n)?(Y(t,r),o=R(n[t],r)):(C(n,r),G(t,r),oe(e.coll,t)||(n[t]={}),o=R(n[t],r)),{coll:o,parent:n}},{coll:n,parent:{}})}}(e,t,n),i=_(t[t.length-1],n),s=_(t[t.length-2],n);return Array.isArray(a.parent)?(Y(s,n),a.parent[s]=Js(a.coll,i,r,n)):(G(s,n),a.parent[s]=Js(a.coll,i,r,n)),o},arity:te(3),docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:["number","string"],array:!0},value:{type:"any"}},variants:[{argumentNames:["coll","ks","value"]}],description:"\nAssociates a value in the nested collection $coll, where $ks is an array of keys and $value is the new value.\n\nIf any levels do not exist, objects will be created - and the corresponding keys must be of type string.",seeAlso:["assoc","collection.get-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.assoc-in(\n {},\n ["a", "b", "c"],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, [1, 2, 3]],\n [2, 1],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, { name: "albert" }],\n [2, "name", 0],\n "A"\n)']}},update:{evaluate:()=>{throw new Error("update: Dvala implementation should be used instead")},arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},key:{type:["string","number"]},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","key","fun"]},{argumentNames:["coll","key","fun","fun-args"]}],description:"\nUpdates a value in the $coll collection, where $key is a key. $fun is a function\nthat will take the old value and any supplied $fun-args and\nreturn the new value.\nIf the key does not exist, `null` is passed as the old value.",seeAlso:["collection.update-in","assoc"],examples:['\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(x, "a", inc)','\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(\n x,\n "c",\n val -> null?(val) ? 0 : inc(val)\n)']}},"update-in":{evaluate:()=>{throw new Error("update-in: Dvala implementation should be used instead")},arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:"array"},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","ks","fun"]},{argumentNames:["coll","ks","fun","fun-args"]}],description:"Updates a value in the $coll collection, where $ks is an array of\nkeys and $fun is a function that will take the old value and\nany supplied $fun-args and return the new value. If any levels do not exist,\nobjects will be created - and the corresponding keys must be of type string.",seeAlso:["collection.update","collection.assoc-in","collection.get-in"],examples:['\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n -> null?($) ? 0 : inc($)\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "foo"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "baz"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n *,\n 10,\n 10,\n 10,\n)']}},filteri:{evaluate:()=>{throw new Error("filteri: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection with all elements that pass the test implemented by $b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["filter","collection.mapi"],examples:["let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> i % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x + i > 3)"]}},mapi:{evaluate:()=>{throw new Error("mapi: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection populated with the results of calling $b on every element in $a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["map","collection.filteri"],examples:["let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x + i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x * i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x - i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x / i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x % inc(i))"]}},reducei:{evaluate:()=>{throw new Error("reducei: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["reduce","collection.reducei-right","collection.reductionsi"],examples:["let cu = import(collection); cu.reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"reduce-right":{evaluate:()=>{throw new Error("reduce-right: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.",seeAlso:["reduce","collection.reducei-right"],examples:['let cu = import(collection); cu.reduce-right(["A", "B", "C"], str, "")',"let cu = import(collection); cu.reduce-right({ a: 1, b: 2 }, +, 0)"]}},"reducei-right":{evaluate:()=>{throw new Error("reducei-right: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reducei","collection.reduce-right"],examples:["let cu = import(collection); cu.reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei-right({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},reductions:{evaluate:()=>{throw new Error("reductions: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.",seeAlso:["reduce","collection.reductionsi"],examples:["let cu = import(collection); cu.reductions([1, 2, 3], +, 0)","let cu = import(collection); cu.reductions([1, 2, 3], +, 10)","let cu = import(collection); cu.reductions([], +, 0)","let cu = import(collection); cu.reductions({ a: 1, b: 2 }, +, 0)","\nlet cu = import(collection);\ncu.reductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + (even?(value) ? value : 0),\n 0\n)"]}},reductionsi:{evaluate:()=>{throw new Error("reductionsi: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reductions","collection.reducei"],examples:["let cu = import(collection); cu.reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reductionsi({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"not-empty":{evaluate:([e],t)=>null===e?null:(P(e,t),"string"==typeof e||Array.isArray(e)?e.length>0?e:null:Object.keys(e).length>0?e:null),arity:te(1),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:["collection","null"]}},variants:[{argumentNames:["coll"]}],description:"Returns `null` if $coll is empty or `null`, otherwise $coll.",seeAlso:["empty?","not-empty?"],examples:["let cu = import(collection); cu.not-empty([])","let cu = import(collection); cu.not-empty([1, 2, 3])","let cu = import(collection); cu.not-empty({})","let cu = import(collection); cu.not-empty({ a: 2 })",'let cu = import(collection); cu.not-empty("")','let cu = import(collection); cu.not-empty("Albert")',"let cu = import(collection); cu.not-empty(null)"]}},"every?":{evaluate:()=>{throw new Error("every?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if all entries in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.any?","collection.not-every?","collection.not-any?","functional.every-pred","grid.cell-every?"],examples:["let cu = import(collection); cu.every?([1, 2, 3], number?)","let cu = import(collection); cu.every?([1, 2, 3], even?)",'\nlet cu = import(collection);\ncu.every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?,\n)',"\nlet cu = import(collection);\ncu.every?(\n [50, 100, 150, 200],\n -> $ > 10,\n)","let cu = import(collection); cu.every?([], number?)",'let cu = import(collection); cu.every?("", number?)',"let cu = import(collection); cu.every?({}, number?)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 4},\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}},"any?":{evaluate:()=>{throw new Error("any?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if any element in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.not-any?","collection.not-every?","functional.some-pred","some","grid.some?"],examples:['\nlet cu = import(collection);\ncu.any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.any?([], number?)",'let cu = import(collection); cu.any?("", number?)',"let cu = import(collection); cu.any?({}, number?)","\nlet cu = import(collection);\ncu.any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-any?":{evaluate:()=>{throw new Error("not-any?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `false` if any element in $a pass the test implemented by $b, otherwise returns `true`.",seeAlso:["collection.any?","collection.every?","collection.not-every?"],examples:['\nlet cu = import(collection);\ncu.not-any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-any?([], number?)",'let cu = import(collection); cu.not-any?("", number?)',"let cu = import(collection); cu.not-any?({}, number?)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-every?":{evaluate:()=>{throw new Error("not-every?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if at least one element in $a does not pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.any?","collection.not-any?"],examples:['\nlet cu = import(collection);\ncu.not-every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-every?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-every?([], number?)",'let cu = import(collection); cu.not-every?("", number?)',"let cu = import(collection); cu.not-every?({}, number?)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 4 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}}},Ys={name:"collection",functions:Hs,source:'{\n update: (coll, key, fn, ...extra-params) ->\n assoc(coll, key, apply(fn, [get(coll, key), ...extra-params])),\n\n update-in: (coll, ks, fn, ...extra-params) -> do\n let k = first(ks);\n if count(ks) == 1 then\n assoc(coll, k, apply(fn, [get(coll, k), ...extra-params]))\n else\n let inner = get(coll, k);\n let inner-coll = null?(inner) ? {} : inner;\n assoc(coll, k, apply(self, [inner-coll, slice(ks, 1), fn, ...extra-params]))\n end\n end,\n\n filteri: (coll, fn) -> do\n cond\n case array?(coll) then\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> if fn(first(pair), second(pair)) then [...acc, first(pair)] else acc end,\n []\n )\n\n case string?(coll) then\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> if fn(first(pair), second(pair)) then ++(acc, first(pair)) else acc end,\n ""\n )\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) ->\n if fn(coll(k), k) then assoc(acc, k, coll(k)) else acc end,\n {}\n )\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n mapi: (coll, fn) -> do\n cond\n case array?(coll) then\n for (i in range(count(coll))) -> fn(nth(coll, i), i)\n\n case string?(coll) then\n reduce(\n for (i in range(count(coll))) -> fn(nth(coll, i), i),\n (acc, ch) -> ++(acc, ch),\n ""\n )\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) ->\n assoc(acc, k, fn(coll(k), k)),\n {}\n )\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reducei: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i + 1)\n end\n end\n\n case array?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i + 1)\n end\n end\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) -> fn(acc, coll(k), k), initial)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reduce-right: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n reduce(reverse(coll), fn, initial)\n\n case array?(coll) then\n reduce(reverse(coll), fn, initial)\n\n case object?(coll) then\n reduce(reverse(keys(coll)), (acc, k) -> fn(acc, coll(k)), initial)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reducei-right: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n let len = count(coll);\n loop (acc = initial, i = len - 1) -> do\n if i < 0 then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i - 1)\n end\n end\n\n case array?(coll) then\n let len = count(coll);\n loop (acc = initial, i = len - 1) -> do\n if i < 0 then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i - 1)\n end\n end\n\n case object?(coll) then\n reduce(reverse(keys(coll)), (acc, k) -> fn(acc, coll(k), k), initial)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reductions: (coll, fn, initial) -> do\n let items = cond\n case string?(coll) then\n if count(coll) == 0 then [] else for (i in range(count(coll))) -> nth(coll, i) end\n\n case array?(coll) then coll\n\n case object?(coll) then\n for (k in keys(coll)) -> coll(k)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end;\n if count(items) == 0 then\n [initial]\n else\n reduce(items, (acc, elem) -> do\n let prev = last(acc);\n [...acc, fn(prev, elem)]\n end, [initial])\n end\n end,\n\n reductionsi: (coll, fn, initial) -> do\n cond\n case string?(coll) then do\n if count(coll) == 0 then\n [initial]\n else\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> do\n let prev = last(acc);\n [...acc, fn(prev, first(pair), second(pair))]\n end,\n [initial]\n )\n end\n end\n\n case array?(coll) then do\n if count(coll) == 0 then\n [initial]\n else\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> do\n let prev = last(acc);\n [...acc, fn(prev, first(pair), second(pair))]\n end,\n [initial]\n )\n end\n end\n\n case object?(coll) then do\n let ks = keys(coll);\n if count(ks) == 0 then\n [initial]\n else\n reduce(ks, (acc, k) -> do\n let prev = last(acc);\n [...acc, fn(prev, coll(k), k)]\n end, [initial])\n end\n end\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n "every?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then true\n case not(fn(nth(items, i))) then false\n case true then recur(i + 1)\n end\n end,\n\n "any?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then false\n case fn(nth(items, i)) then true\n case true then recur(i + 1)\n end\n end,\n\n "not-any?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then true\n case fn(nth(items, i)) then false\n case true then recur(i + 1)\n end\n end,\n\n "not-every?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then false\n case not(fn(nth(items, i))) then true\n case true then recur(i + 1)\n end\n end\n}',docs:Os(Hs)};const Xs={position:{evaluate:()=>{throw new Error("position: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:["sequence","null"]},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the index of the first elements that passes the test implemented by $fun. If no element was found, `null` is returned.",seeAlso:["index-of","some","find"],examples:['\nlet su = import(sequence);\nsu.position(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet su = import(sequence);\nsu.position(\n [5, 10, 15, 20],\n -> $ > 10\n)","\nlet su = import(sequence);\nsu.position(\n [5, 10, 15, 20],\n -> $ > 100\n)","\nlet su = import(sequence);\nsu.position(\n null,\n -> $ > 100\n)"]}},"last-index-of":{evaluate:([e,t],r)=>{if(E(t,r),null===e)return null;if(z(e,r),"string"==typeof e){G(t,r);const n=e.lastIndexOf(t);return-1!==n?n:null}{const n=e.findLastIndex(e=>ie($(e,r),t),r);return-1!==n?n:null}},arity:te(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:["sequence","null"]},x:{type:"any"}},variants:[{argumentNames:["seq","x"]}],description:"Returns the last index of $x in $seq. If element is not present in $seq `null` is returned.",seeAlso:["index-of"],examples:["let su = import(sequence); su.last-index-of([[1], [2], [1], [2]], [1])",'let su = import(sequence); su.last-index-of(["Albert", "Mojir", 160, [1, 2]], "Mojir")',"let su = import(sequence); su.last-index-of([5, 10, 15, 20, 15], 15)","let su = import(sequence); su.last-index-of([5, 10, 15, 20], 1)","let su = import(sequence); su.last-index-of(null, 1)"]}},splice:{evaluate:(e,t)=>{const[r,n,o,...a]=e;z(r,t),Y(n,t,{integer:!0}),Y(o,t,{integer:!0,nonNegative:!0});const i=n<0?r.length+n:n;return Array.isArray(r)?[...r.slice(0,i),...a,...r.slice(i+o)]:(a.forEach(e=>G(e,t)),`${r.substring(0,i)}${a.join("")}${r.substring(i+o)}`)},arity:{min:3},docs:{category:"sequence",returns:{type:"sequence"},args:{seq:{type:"sequence",rest:!0},start:{type:"integer"},deleteCount:{type:"integer"},items:{type:"any",rest:!0}},variants:[{argumentNames:["seq","start","deleteCount"]},{argumentNames:["seq","start","deleteCount","items"]}],description:"Returns a a spliced array. Removes $deleteCount elements from $seq starting at $start and replaces them with $items. If $start is negative, it is counting from the end of the array.",seeAlso:["slice","sequence.remove-at"],examples:['let su = import(sequence); su.splice([1, 2, 3, 4, 5], 2, 2, "x")','let su = import(sequence); su.splice([1, 2, 3, 4, 5], -2, 1, "x")','let su = import(sequence); su.splice("Albert", 2, 2, "fo")']}},"sort-by":{evaluate:()=>{throw new Error("sort-by: Dvala implementation should be used instead")},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"any",rest:!0},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},keyfn:{type:"function"},comparer:{type:"function"}},variants:[{argumentNames:["seq","keyfn"]},{argumentNames:["seq","keyfn","comparer"]}],description:"Returns a sorted sequence of the items in $seq, where the sort order is determined by comparing `(keyfn item)`. If no $comparer is supplied, uses builtin `compare`.",seeAlso:["sort","compare"],examples:['let su = import(sequence); su.sort-by(["Albert", "Mojir", "Nina"], count)','let su = import(sequence); su.sort-by(["Albert", "Mojir", "Nina"], count)','let su = import(sequence); su.sort-by("Albert", lower-case, -> $2 compare $1)']}},unshift:{evaluate:([e,...t],r)=>{if(z(e,r),"string"==typeof e)return be(t,r),[...t,e].join("");const n=[...e];return n.unshift(...t),n},arity:{min:2},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},values:{type:"any",rest:!0}},variants:[{argumentNames:["seq","values"]}],description:"Returns copy of $seq with $values added to the beginning.",seeAlso:["push","++"],examples:["let su = import(sequence); su.unshift([1, 2, 3], 4)","let su = import(sequence); su.unshift([1, 2, 3], 4)","let su = import(sequence); su.unshift([1, 2, 3], 4, 5, 6)","\nlet su = import(sequence);\nlet l = [1, 2, 3];\nsu.unshift(l, 4);\nl"]}},distinct:{evaluate:([e],t)=>{if(z(e,t),Array.isArray(e)){const r=[];for(const n of e)E(n,t),r.some(e=>ie(e,n,t))||r.push(n);return r}return Array.from(new Set(e.split(""))).join("")},arity:te(1),docs:{category:"sequence",returns:{type:"sequence"},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns a copy of $seq with no duplicates.",seeAlso:["sequence.frequencies"],examples:["let su = import(sequence); su.distinct([[1], [2], [3], [1], [3], [5]])","let su = import(sequence); su.distinct([1, 2, 3, 1, 3, 5])",'let su = import(sequence); su.distinct("Albert Mojir")',"let su = import(sequence); su.distinct([])",'let su = import(sequence); su.distinct("")']}},remove:{evaluate:()=>{throw new Error("remove: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns a new sequence of items in $seq for witch `pred(item)` returns a falsy value.",seeAlso:["filter","sequence.remove-at"],examples:["let su = import(sequence); su.remove([1, 2, 3, 1, 3, 5], odd?)","let su = import(sequence); su.remove([1, 2, 3, 1, 3, 5], even?)",'let su = import(sequence); su.remove("Albert Mojir", -> "aoueiyAOUEIY" contains? $)']}},"remove-at":{evaluate:([e,t],r)=>{Y(t,r,{integer:!0}),z(e,r);const n=t<0?e.length+t:t;return n<0||n>=e.length?e:Array.isArray(e)?e.filter((e,t)=>t!==n):`${e.substring(0,n)}${e.substring(n+1)}`},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"number"}},variants:[{argumentNames:["seq","n"]}],description:"Returns a new sequence of all items in $seq except item at position $n. If $n is negative, it is counting from the end of the sequence.",seeAlso:["sequence.remove","sequence.splice"],examples:["let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], 2)",'let su = import(sequence); su.remove-at("Albert", -2)',"let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], 0)","let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], -1)",'let su = import(sequence); su.remove-at("Albert Mojir", 6)']}},"split-at":{evaluate:([e,t],r)=>{Y(t,r,{integer:!0}),z(e,r);const n=t<0?e.length+t:t;return[e.slice(0,n),e.slice(n)]},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"number"}},variants:[{argumentNames:["seq","n"]}],description:"Returns a pair of sequence `[take(pos input), drop(pos input)]`.",seeAlso:["sequence.split-with","take","drop"],examples:["let su = import(sequence); su.split-at([1, 2, 3, 4, 5], 2)",'let su = import(sequence); su.split-at("Albert", -2)',"let su = import(sequence); su.split-at([1, 2, 3, 4, 5], -2)",'let su = import(sequence); su.split-at("Albert", 2)']}},"split-with":{evaluate:()=>{throw new Error("split-with: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns a pair of sequences `[take-while(input, fun), drop-while(input, fun)]`.",seeAlso:["sequence.split-at","take-while","drop-while"],examples:["let su = import(sequence); su.split-with([1, 2, 3, 4, 5], odd?)","let su = import(sequence); su.split-with([1, 2, 3, 4, 5], -> $ > 3)",'let su = import(sequence); su.split-with("Albert", -> $ <= "o")']}},frequencies:{evaluate:([e],t)=>{z(e,t);return("string"==typeof e?e.split(""):e).reduce((e,r)=>(G(r,t),oe(e,r)?e[r]=e[r]+1:e[r]=1,e),{})},arity:te(1),docs:{category:"sequence",returns:{type:"object"},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns an object from distinct items in $seq to the number of times they appear. Note that all items in $seq must be valid object keys i.e. strings.",seeAlso:["sequence.group-by","sequence.distinct","vector.count-values"],examples:['let su = import(sequence); su.frequencies(["Albert", "Mojir", "Nina", "Mojir"])','let su = import(sequence); su.frequencies("Pneumonoultramicroscopicsilicovolcanoconiosis")']}},"group-by":{evaluate:()=>{throw new Error("group-by: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"object"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns an object of the elements of $seq keyed by the result of $fun on each element. The value at each key will be an array of the corresponding elements.",seeAlso:["sequence.frequencies","sequence.partition-by"],examples:['let su = import(sequence); su.group-by([{ name: "Albert" }, { name: "Albert" }, { name: "Mojir" }], "name")','let su = import(sequence); su.group-by([{name: "Albert"}, {name: "Albert"}, {name: "Mojir"}], "name")','let su = import(sequence); su.group-by("Albert Mojir", -> "aoueiAOUEI" contains? $ ? "vowel" : "other")']}},partition:{evaluate:(e,t)=>{const r=S(e[0],t),n=se(X(e[1],t)),o=e.length>=3?se(X(e[2],t)):n,a=4===e.length?null===e[3]?[]:function(e,t){return ye(e,t),e}(e[3],t):void 0;return Qs(n,o,r,a,t)},arity:{min:2,max:4},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"number"},seq:{type:"sequence"},n:{type:"number"},step:{type:"number"},pad:{type:"array"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","step"]},{argumentNames:["seq","n","step","pad"]}],description:"Returns an array of sequences of $n items each, at offsets $step apart. If $step is not supplied, defaults to $n. If a $pad array is supplied, use its elements as necessary to complete last partition upto $n items. In case there are not enough padding elements, return a partition with less than $n items.",seeAlso:["sequence.partition-all","sequence.partition-by"],examples:["let su = import(sequence); su.partition(range(20), 4)","let su = import(sequence); su.partition(range(20), 4)","let su = import(sequence); su.partition(range(22), 4)","let su = import(sequence); su.partition(range(20), 4, 6)","let su = import(sequence); su.partition(range(20), 4, 3)",'let su = import(sequence); su.partition(range(20), 3, 6, ["a"])','let su = import(sequence); su.partition(range(20), 4, 6, ["a"])','let su = import(sequence); su.partition(range(20), 4, 6, ["a", "b", "c", "d"])','let su = import(sequence); su.partition(["a", "b", "c", "d", "e", "f"], 3, 1)',"let su = import(sequence); su.partition([1, 2, 3, 4], 10)","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10)","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10, [])","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10, null)",'let su = import(sequence); su.partition("superfragilistic", 5)','let su = import(sequence); su.partition("superfragilistic", 5, 5, null)',"let su = import(sequence); let foo = [5, 6, 7, 8]; su.partition(foo, 2, 1, foo)"]}},"partition-all":{evaluate:(e,t)=>{const r=S(e[0],t),n=se(X(e[1],t));return Qs(n,3===e.length?se(X(e[2],t)):n,r,[],t)},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"number"},seq:{type:"sequence"},n:{type:"number"},step:{type:"number"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","step"]}],description:"Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.",seeAlso:["sequence.partition","sequence.partition-by"],examples:["let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 4)"]}},"partition-by":{evaluate:()=>{throw new Error("partition-by: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Applies $fun to each value in $seq, splitting it each time $fun returns a new value. Returns an array of sequences.",seeAlso:["sequence.partition","sequence.partition-all","sequence.group-by"],examples:["let su = import(sequence); su.partition-by([1, 2, 3, 4, 5], odd?)","let su = import(sequence); su.partition-by([1, 2, 3, 4, 5], -> $ == 3)","let su = import(sequence); su.partition-by([1, 1, 1, 2, 2, 3, 3], odd?)",'let su = import(sequence); su.partition-by("Leeeeeerrroyyy", identity)']}},"ends-with?":{evaluate:([e,t],r)=>(z(e,r),"string"==typeof e?(G(t,r),e.endsWith(t)):ie($(e.at(-1),r),$(t,r),r)),arity:te(2),docs:{category:"sequence",returns:{type:"boolean"},args:{a:{type:"sequence"},b:{type:"sequence"},seq:{type:"sequence"},suffix:{type:"sequence"}},variants:[{argumentNames:["seq","suffix"]}],description:"Returns `true` if $seq ends with $suffix, otherwise `false`.",seeAlso:["sequence.starts-with?"],examples:["let su = import(sequence); su.ends-with?([[1], [2], [3], [4], [5]], [5])","let su = import(sequence); su.ends-with?([[1], [2], [3], [4], [5]], 5)","let su = import(sequence); su.ends-with?([1, 2, 3, 4, 5], 5)","let su = import(sequence); su.ends-with?([1, 2, 3, 4, 5], [5])",'let su = import(sequence); su.ends-with?("Albert", "rt")','let su = import(sequence); su.ends-with?("Albert", "RT")']}},"starts-with?":{evaluate:([e,t],r)=>(z(e,r),"string"==typeof e?(G(t,r),e.startsWith(t)):ie($(e[0],r),$(t,r),r)),arity:te(2),docs:{category:"sequence",returns:{type:"boolean"},args:{a:{type:"sequence"},b:{type:"sequence"},seq:{type:"sequence"},prefix:{type:"sequence"}},variants:[{argumentNames:["seq","prefix"]}],description:"Returns `true` if $seq starts with $prefix, otherwise `false`.",seeAlso:["sequence.ends-with?"],examples:["let su = import(sequence); su.starts-with?([[1], [2], [3], [4], [5]], [1])","let su = import(sequence); su.starts-with?([1, 2, 3, 4, 5], 1)","let su = import(sequence); su.starts-with?([1, 2, 3, 4, 5], [1])",'let su = import(sequence); su.starts-with?("Albert", "Al")','let su = import(sequence); su.starts-with?("Albert", "al")']}},interleave:{evaluate:([...e],t)=>{const r="string"==typeof e[0],n=r?e.map(e=>(G(e,t),e.split(""))):e.map(e=>(ye(e,t),e)),o=Math.min(...n.map(e=>e.length)),a=[];for(let e=0;e<o;e+=1)for(const t of n)e<t.length&&a.push(t[e]);return r?a.join(""):a},arity:{min:1},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"sequence"},seqs:{type:"sequence",rest:!0}},variants:[{argumentNames:["seqs"]}],description:"Returns a sequence of the first item from each of the $seqs, then the second item from each of the $seqs, until all items from the shortest seq are exhausted.",seeAlso:["sequence.interpose","zipmap"],examples:["let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6])",'let su = import(sequence); su.interleave("Albert", ".,.,.,")',"let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7, 8, 9])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7, 8])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [])","let su = import(sequence); su.interleave([1, 2, 3], [])","let su = import(sequence); su.interleave([])"]}},interpose:{evaluate:([e,t],r)=>{if(z(e,r),"string"==typeof e)return G(t,r),e.split("").join(t);if(0===e.length)return[];const n=[];for(let r=0;r<e.length-1;r+=1)n.push(e[r],t);return n.push(e[e.length-1]),n},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},separator:{type:"any"}},variants:[{argumentNames:["seq","separator"]}],description:"Returns a sequence of the elements of $seq separated by $separator. If $seq is a string, the separator must be a string.",seeAlso:["sequence.interleave","join"],examples:['let su = import(sequence); su.interpose("Albert", "-")','let su = import(sequence); su.interpose([1, 2, 3, 4, 5], "a")','let su = import(sequence); su.interpose(["Albert", "Mojir", "Nina"], ", ")','let su = import(sequence); su.interpose("Albert", ".")']}}};function Qs(e,t,r,n,o){Y(t,o,{positive:!0});const a="string"==typeof r,i=[];let s=0;e:for(;s<r.length;){const o=[];for(let a=s;a<s+e;a+=1)if(a>=r.length){const e=a-r.length;if(!n){s+=t;continue e}if(e>=n.length)break;o.push(n[e])}else o.push(r[a]);i.push(o),s+=t}return a?i.map(e=>e.join("")):i}const Zs={name:"sequence",functions:Xs,source:'{\n position: (seq, fn) -> do\n let items = cond\n case null?(seq) then null\n case string?(seq) then for (i in range(count(seq))) -> nth(seq, i)\n case true then seq\n end;\n if null?(items) then null\n else\n loop (i = 0) ->\n cond\n case i >= count(items) then null\n case fn(nth(items, i)) then i\n case true then recur(i + 1)\n end\n end\n end,\n\n sort-by: (seq, keyfn, ...args) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else [...seq] end;\n let keyed = map(items, (elem) -> [keyfn(elem), elem]);\n let sorted = if count(args) == 0 then\n sort(keyed, (a, b) -> compare(first(a), first(b)))\n else\n sort(keyed, (a, b) -> first(args)(first(a), first(b)))\n end;\n let result = map(sorted, second);\n if string?(seq) then join(result, "") else result end\n end,\n\n remove: (seq, fn) -> do\n let result = filter(\n if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end,\n (elem) -> not(fn(elem))\n );\n if string?(seq) then join(result, "") else result end\n end,\n\n split-with: (seq, fn) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end;\n let idx = loop (i = 0) ->\n cond\n case i >= count(items) then -1\n case not(fn(nth(items, i))) then i\n case true then recur(i + 1)\n end;\n if idx == -1 then\n [seq, if array?(seq) then [] else "" end]\n else\n [slice(seq, 0, idx), slice(seq, idx)]\n end\n end,\n\n group-by: (seq, fn) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end;\n reduce(items, (result, val) -> do\n let key = fn(val);\n let existing = get(result, key);\n assoc(result, key, if null?(existing) then [val] else [...existing, val] end)\n end, {})\n end,\n\n partition-by: (seq, fn) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end;\n if count(items) == 0 then\n []\n else\n do\n let result = reduce(rest(items), (acc, elem) -> do\n let value = fn(elem);\n if value != first(acc) then\n [value, [...second(acc), [elem]]]\n else\n [value, [...slice(second(acc), 0, count(second(acc)) - 1), [...last(second(acc)), elem]]]\n end\n end, [fn(first(items)), [[first(items)]]]);\n let groups = second(result);\n if string?(seq) then\n map(groups, (group) -> join(group, ""))\n else\n groups\n end\n end\n end\n end\n}',docs:Os(Xs)};function el(e,t){return{a:{type:e},b:{type:t}}}const tl={"bit-not":{evaluate:([e],t)=>(Y(e,t,{integer:!0}),~e),arity:te(1),docs:{category:"bitwise",returns:{type:"integer"},args:{a:{type:"integer"}},variants:[{argumentNames:["a"]}],description:"Returns bitwise `not` of $a.",seeAlso:["&","|","xor","bitwise.bit-and-not"],examples:["let { bit-not } = import(bitwise);\nbit-not(0)","let { bit-not } = import(bitwise);\nbit-not(255)"]}},"bit-and-not":{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e&~t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...el("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `and` with complement.",seeAlso:["&","|","xor","bitwise.bit-not"],examples:["let { bit-and-not } = import(bitwise);\n0b0011 bit-and-not 0b0110","let { bit-and-not } = import(bitwise);\nbit-and-not(0b0011, 0b0110)","let { bit-and-not } = import(bitwise);\nbit-and-not(0b0011, 0b0110, 0b1001)"]}},"bit-flip":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return e^1<<t},arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...el("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Flips bit number $b.",seeAlso:["bitwise.bit-set","bitwise.bit-clear","bitwise.bit-test"],examples:["let { bit-flip } = import(bitwise);\n0b0011 bit-flip 1","let { bit-flip } = import(bitwise);\nbit-flip(0b0011, 1)","let { bit-flip } = import(bitwise);\nbit-flip(0b1100, 1)"]}},"bit-set":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return e|1<<t},arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...el("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Sets bit number $b.",seeAlso:["bitwise.bit-flip","bitwise.bit-clear","bitwise.bit-test"],examples:["let { bit-set } = import(bitwise);\n0b0010 bit-set 1","let { bit-set } = import(bitwise);\nbit-set(0b0011, 1)","let { bit-set } = import(bitwise);\nbit-set(0b1100, 1)"]}},"bit-clear":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return e&~(1<<t)},arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...el("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Clears bit number $b.",seeAlso:["bitwise.bit-flip","bitwise.bit-set","bitwise.bit-test"],examples:["let { bit-clear } = import(bitwise);\n0b0011 bit-clear 1","let { bit-clear } = import(bitwise);\nbit-clear(0b0011, 1)","let { bit-clear } = import(bitwise);\nbit-clear(0b1100, 1)"]}},"bit-test":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return!!(e&1<<t)},arity:te(2),docs:{category:"bitwise",returns:{type:"boolean"},args:{...el("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Checks if bit number $b is set.",seeAlso:["bitwise.bit-flip","bitwise.bit-set","bitwise.bit-clear"],examples:["let { bit-test } = import(bitwise);\n0b0011 bit-test 1","let { bit-test } = import(bitwise);\nbit-test(0b0011, 1)","let { bit-test } = import(bitwise);\nbit-test(0b1100, 1)"]}}},rl={name:"bitwise",functions:tl,source:"{}",docs:Os(tl)};const nl={baseUnit:"rad",description:"angle",units:{deg:Math.PI/180,rad:1,grad:Math.PI/200,turn:2*Math.PI}};function ol(e,t){switch(e){case"c":return t;case"f":return 9*t/5+32;case"k":return t+273.15}}function al(e,t){switch(e){case"c":return t;case"f":return 5*(t-32)/9;case"k":return t-273.15}}const il=["c","f","k"],sl={angstrom:"ångströms",um:"micrometers",mm:"millimeters",cm:"centimeters",m:"meters",km:"kilometers",in:"inches",ft:"feet",yd:"yards",mi:"miles",nmi:"nautical miles",mg:"milligrams",g:"grams",kg:"kilograms",t:"metric tons",oz:"ounces",lb:"pounds",st:"stones",ml:"milliliters",cl:"centiliters",dl:"deciliters",l:"liters",tsp:"teaspoons",tbsp:"tablespoons","fl-oz":"fluid ounces",cup:"cups",pt:"pints",qt:"quarts",gal:"gallons",ms:"milliseconds",s:"seconds",min:"minutes",h:"hours",day:"days",week:"weeks",mm2:"square millimeters",cm2:"square centimeters",m2:"square meters",km2:"square kilometers",in2:"square inches",ft2:"square feet",yd2:"square yards",acre:"acres",hectare:"hectares","m/s":"meters per second","km/h":"kilometers per hour",mph:"miles per hour",kn:"knots","ft/s":"feet per second",b:"bytes",kb:"kilobytes",mb:"megabytes",gb:"gigabytes",tb:"terabytes",pb:"petabytes",pa:"pascals",kpa:"kilopascals",bar:"bars",atm:"atmospheres",psi:"pounds per square inch",mmhg:"millimeters of mercury",j:"joules",kj:"kilojoules",cal:"calories",kcal:"kilocalories",wh:"watt-hours",kwh:"kilowatt-hours",btu:"British thermal units",w:"watts",kw:"kilowatts",mw:"megawatts",hp:"horsepower",hz:"hertz",khz:"kilohertz",mhz:"megahertz",ghz:"gigahertz",deg:"degrees",rad:"radians",grad:"gradians",turn:"turns",c:"Celsius",f:"Fahrenheit",k:"Kelvin"};function ll(e){const t={},r=Object.keys(e.units);for(const n of r)for(const o of r){if(n===o)continue;const a=e.units[n]/e.units[o],i=`${n}->${o}`,s=sl[n],l=sl[o],c=[`convert.${o}->${n}`,...r.filter(e=>e!==n&&e!==o).map(e=>`convert.${n}->${e}`)];t[i]={evaluate:([e],t)=>(Y(e,t),e*a),arity:te(1),docs:{category:"convert",returns:{type:"number"},args:{value:{type:"number",description:`Value in ${s}`}},variants:[{argumentNames:["value"]}],description:`Converts a value from ${s} (\`${n}\`) to ${l} (\`${o}\`).`,seeAlso:c,examples:[`let { ${i} } = import(convert);\n${i}(1)`]}}}return t}const cl={...ll({baseUnit:"m",description:"length",units:{angstrom:1e-10,um:1e-6,mm:.001,cm:.01,m:1,km:1e3,in:.0254,ft:.3048,yd:.9144,mi:1609.344,nmi:1852}}),...ll({baseUnit:"kg",description:"weight",units:{mg:1e-6,g:.001,kg:1,t:1e3,oz:.028349523125,lb:.45359237,st:6.35029318}}),...ll({baseUnit:"l",description:"volume",units:{ml:.001,cl:.01,dl:.1,l:1,tsp:.00492892159375,tbsp:.01478676478125,"fl-oz":.0295735295625,cup:.2365882365,pt:.473176473,qt:.946352946,gal:3.785411784}}),...ll({baseUnit:"s",description:"time",units:{ms:.001,s:1,min:60,h:3600,day:86400,week:604800}}),...ll({baseUnit:"m2",description:"area",units:{mm2:1e-6,cm2:1e-4,m2:1,km2:1e6,in2:64516e-8,ft2:.09290304,yd2:.83612736,acre:4046.8564224,hectare:1e4}}),...ll({baseUnit:"m/s",description:"speed",units:{"m/s":1,"km/h":1/3.6,mph:.44704,kn:.514444,"ft/s":.3048}}),...ll({baseUnit:"b",description:"data",units:{b:1,kb:1e3,mb:1e6,gb:1e9,tb:1e12,pb:1e15}}),...ll({baseUnit:"pa",description:"pressure",units:{pa:1,kpa:1e3,bar:1e5,atm:101325,psi:6894.757293168,mmhg:133.322387415}}),...ll({baseUnit:"j",description:"energy",units:{j:1,kj:1e3,cal:4.184,kcal:4184,wh:3600,kwh:36e5,btu:1055.06}}),...ll({baseUnit:"w",description:"power",units:{w:1,kw:1e3,mw:1e6,hp:745.7}}),...ll({baseUnit:"hz",description:"frequency",units:{hz:1,khz:1e3,mhz:1e6,ghz:1e9}}),...ll(nl),...function(){const e={};for(const t of il)for(const r of il){if(t===r)continue;const n=`${t}->${r}`,o=sl[t],a=sl[r],i=[`convert.${r}->${t}`,...il.filter(e=>e!==t&&e!==r).map(e=>`convert.${t}->${e}`)];e[n]={evaluate:([e],n)=>{Y(e,n);const o=al(t,e);return ol(r,o)},arity:te(1),docs:{category:"convert",returns:{type:"number"},args:{value:{type:"number",description:`Value in ${o}`}},variants:[{argumentNames:["value"]}],description:`Converts a temperature from ${o} (\`${t}\`) to ${a} (\`${r}\`).`,seeAlso:i,examples:[`let { ${n} } = import(convert);\n${n}(100)`]}}}return e}()},ul=[ga,ba,ri,gi,Ai,Ms,Us,Ws,_s,Ys,Zs,rl,{name:"convert",functions:cl,source:"{}",docs:Os(cl)}];function ml({testPath:e,testNamePattern:r}){const n=function(e){const r=[];return n(e,r),r.reduce((e,t)=>(e.includes(t)||e.push(t),e),[]);function n(e,r){const o=function(e){const r=pl(e),n=t.dirname(e);let o=!0;return r.split("\n").reduce((r,a)=>{const i=a.match(/^\s*\/{2}\s*@include\s*(\S+)\s*$/);if(i){if(!o)throw new Error(`@include must be in the beginning of file: ${e}:${a+1}`);const s=i[1];r.push(t.resolve(n,s))}return a.match(/^\s*\/.*$/)||(o=!1),r},[])}(e);o.forEach(e=>{n(e,r),r.push(e)})}}(e),o={tap:"TAP version 13\n",success:!0};try{const t=function(e){const t=pl(e);let r,n="";return t.split("\n").reduce((e,t,o)=>{const a=o+1,i=t.match(/^\s*\/{2}\s*@(?:(skip)-)?test\s*(.*)$/);if(i){const t=(i[1]??"").toUpperCase(),o=i[2];if(!o)throw new Error(`Missing test name on line ${a}`);if(e.find(e=>e.name===o))throw new Error(`Duplicate test name ${o}`);return r={directive:t||null,name:o,program:n+[...Array(a+2-n.split("\n").length).keys()].map(()=>"").join("\n")},e.push(r),e}return r?r.program+=`${t}\n`:n+=`${t}\n`,e},[])}(e);o.tap+=`1..${t.length}\n`,t.forEach((t,a)=>{const i=a+1;if(r&&!r.test(t.name))o.tap+=`ok ${i} ${t.name} # skip - Not matching testNamePattern ${r}\n`;else if("SKIP"===t.directive)o.tap+=`ok ${i} ${t.name} # skip\n`;else try{const r=pa({debug:!0,modules:ul}),a=function(e,t){return e.reduce((e,r)=>{const n=pl(r),o=t.run(n,{filePath:r,bindings:e});if(null!==o&&"object"==typeof o&&!Array.isArray(o))for(const[t,r]of Object.entries(o))t in e||(e[t]=r);return e},{})}(n,r);r.run(t.program,{bindings:a,filePath:e}),o.tap+=`ok ${i} ${t.name}\n`}catch(e){o.success=!1,o.tap+=`not ok ${i} ${t.name}${dl(e)}`}})}catch(e){o.tap+=`Bail out! ${hl(e)}\n`,o.success=!1}return o}function pl(t){if(!t.endsWith(".dvala"))throw new Error(`Expected .dvala file, got ${t}`);return e.readFileSync(t,{encoding:"utf-8"})}function dl(e){const t=hl(e);if(!gl(e))return`\n ---\n message: ${JSON.stringify(t)}\n ...\n`;const n=e.sourceCodeInfo;if(!n||"string"==typeof n)return`\n ---\n message: ${JSON.stringify(t)}\n error: ${JSON.stringify(e.name)}\n ...\n`;const o=t.includes("\n")?`|\n ${t.split(/\r?\n/).join("\n ")}`:JSON.stringify(t);return`\n ---\n error: ${JSON.stringify(e.name)}\n message: ${o}\n location: ${JSON.stringify(function(e){const t=[];e.filePath&&t.push(e.filePath);e.position&&(t.push(`${e.position.line}`),t.push(`${e.position.column}`));return t.join(":")}(n))}\n code:\n - "${n.code}"\n - "${r(n)}"\n ...\n`}function hl(e){return gl(e)?e.shortMessage:"string"==typeof e?e:e instanceof Error?e.message:"Unknown error"}function gl(e){return e instanceof o}export{dl as getErrorYaml,ml as runTest};
1
+ import e from"node:fs";import t from"node:path";function r(e){if(!e.position||!e.code)return"";const t=e.position.column-1,r=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(r,0))}`}class n extends Error{params;constructor(e){super(`recur, params: ${e}`),Object.setPrototypeOf(this,n.prototype),this.name="RecurSignal",this.params=e}}class o extends Error{sourceCodeInfo;shortMessage;constructor(e,t){const n=e instanceof Error?e.message:`${e}`;super(function(e,t){if(!t)return e;const n=`${t.position.line}:${t.position.column}`;return`${e}${t.filePath?`\n${t.filePath}:${n}`:`\nLocation ${n}`}\n${t.code}\n${r(t)}`}(n,t)),this.shortMessage=n,this.sourceCodeInfo=t,Object.setPrototypeOf(this,o.prototype),this.name="DvalaError"}getCodeMarker(){return this.sourceCodeInfo&&r(this.sourceCodeInfo)}}class a extends o{userMessage;constructor(e,t){super(e,t),this.userMessage=e,Object.setPrototypeOf(this,a.prototype),this.name="UserDefinedError"}}class i extends o{constructor(e,t){super(e,t),Object.setPrototypeOf(this,i.prototype),this.name="AssertionError"}}class s extends o{symbol;constructor(e,t){super(`Undefined symbol '${e}'.`,t),this.symbol=e,Object.setPrototypeOf(this,s.prototype),this.name="UndefinedSymbolError"}}const l={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},c=new Set(Object.values(l));function u(e){return Object.keys(l).find(t=>l[t]===e)}const m=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","EffectMatcher","Builtin","SpecialBuiltin","Module"]);const p="^^fn^^",d="^^re^^",h="^^ef^^";function g(e){return null!==e&&"object"==typeof e&&(p in e&&"functionType"in e&&function(e){return"string"==typeof e&&m.has(e)}(e.functionType))}function f(e){return!(!Array.isArray(e)||e.length<2)&&function(e){return"number"==typeof e&&c.has(e)}(e[0])}function y(e){return g(e)?`<function ${e.name||"λ"}>`:f(e)?`${u(e[0])}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e)}function v(e,t){return e?.sourceCodeInfo??t}function b(e,t,r){return new o(`Expected ${e}, got ${y(t)}.`,v(t,r))}function w(e,t){return x(e,t),e}function x(e,t){if(!function(e){return void 0!==e}(e))throw new o("Unexpected undefined",v(e,t))}function k(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function q(e){return null!==e&&"object"==typeof e&&!!e[p]}function A(e){return q(e)&&"UserDefined"===e.functionType}function N(e){return void 0!==e}function $(e,t){return E(e,t),e}function E(e,t){if(!N(e))throw b("not undefined",e,t)}function T(e){return Array.isArray(e)||"string"==typeof e}function S(e,t){return z(e,t),e}function z(e,t){if(!T(e))throw b("string or array",e,t)}function j(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||q(e)||M(e)||V(e))}function C(e,t){if(!j(e))throw b("object",e,t)}function I(e){return T(e)||j(e)}function R(e,t){return P(e,t),e}function P(e,t){if(!I(e))throw b("string, array or object",e,t)}function M(e){return null!==e&&"object"==typeof e&&!!e[d]}function O(e,t){if(!function(e){return M(e)||"string"==typeof e}(e))throw b("string or RegularExpression",e,t)}function V(e){return null!==e&&"object"==typeof e&&!!e[h]}function D(e,t){if(!V(e))throw b("Effect",e,t)}function U(e,t){return F(e,t),e}function F(e,t){if(!function(e){return"number"==typeof e||!!I(e)||!!q(e)}(e))throw b("FunctionLike",e,t)}function W(e,t={}){return"string"==typeof e&&((!t.nonEmpty||0!==e.length)&&(!t.char||1===e.length))}function G(e,t,r={}){if(!W(e,r))throw b(""+(r.nonEmpty?"non empty string":r.char?"character":"string"),e,t)}function B(e,t,r={}){return G(e,t,r),e}function L(e){return"string"==typeof e||"number"==typeof e}function _(e,t){return K(e,t),e}function K(e,t){if(!L(e))throw b("string or number",e,t)}const J={assert:{evaluate:(e,t)=>{const r=e[0],n=2===e.length?e[1]:`${r}`;if(G(n,t),!r)throw new i(n,t);return $(r,t)},arity:{min:1,max:2},docs:{category:"assertion",description:"If $value is falsy it throws `AssertionError` with $message. If no $message is provided, message is set to $value.",returns:{type:"any"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['do assert(0, "Expected a positive value") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-truthy","assertion.assert-true"],hideOperatorForm:!0}}};function H(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function Y(e,t,r={}){if(!H(e,r))throw new o(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),r=e.integer?"integer":"number",n=e.finite?"finite":"",o=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,n,r,o].filter(e=>!!e).join(" ")}(r)}, got ${y(e)}.`,v(e,t))}function X(e,t,r={}){return Y(e,t,r),e}function Q(e,t){const{min:r}=e;return!("number"==typeof r&&t<r)}function Z(e){return"number"==typeof e||I(e)?te(1):e.arity}function ee(e,t,r){const{min:n,max:a}=e;if("number"==typeof n&&t<n)throw new o(`Wrong number of arguments, expected at least ${n}, got ${y(t)}.`,r);if("number"==typeof a&&t>a)throw new o(`Wrong number of arguments, expected at most ${a}, got ${y(t)}.`,r)}function te(e){return{min:e,max:e}}function re(e,t){return{a:{type:e},b:{type:t}}}const ne={"<<":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0}),e<<t),arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Shifts $a arithmetically left by $b bit positions.",seeAlso:[">>",">>>"],examples:["1 << 10","<<(1, 10)","<<(-4, 2)"]}},">>":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0}),e>>t),arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Shifts $a arithmetically right by $b bit positions.",seeAlso:["<<",">>>"],examples:["2048 >> 10",">>(2048, 10)",">>>(-16, 2)",">>(4, 10)"]}},">>>":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0}),e>>>t),arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Shifts $a arithmetically right by $b bit positions without sign extension.",seeAlso:["<<",">>"],examples:["-16 >>> 2",">>>(2048, 10)",">>>(-16, 2)",">>>(4, 10)",">>>(-1, 10)"]}},"&":{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e&t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `and` of all arguments.",seeAlso:["|","xor","bitwise.bit-not","bitwise.bit-and-not"],examples:["0b0011 & 0b0110","&(0b0011, 0b0110)","&(0b0011, 0b0110, 0b1001)"]}},"|":{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e|t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `or` of all arguments.",seeAlso:["&","xor","bitwise.bit-not","bitwise.bit-and-not"],examples:["0b0011 | 0b0110","|(0b0011, 0b0110)","|(0b1000, 0b0100, 0b0010)"]}},xor:{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e^t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...re("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `xor` of all arguments.",seeAlso:["&","|","bitwise.bit-not","bitwise.bit-and-not"],examples:["0b0011 xor 0b0110","xor(0b0011, 0b0110)","xor(0b11110000, 0b00111100, 0b10101010)"]}}};function oe(e,t){return!!I(e)&&("string"==typeof e||Array.isArray(e)?!!H(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function ae(e,t,r){if(K(e,r),K(t,r),"string"==typeof e&&"string"==typeof t)return e<t?-1:e>t?1:0;if("number"==typeof e&&"number"==typeof t)return Math.sign(e-t);throw new o(`Cannot compare values of different types: ${typeof e} and ${typeof t}`,r)}function ie(e,t,r){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return he(e,t);if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(!ie($(e[n],r),$(t[n],r),r))return!1;return!0}if(M(e)&&M(t))return e.s===t.s&&e.f===t.f;if(k(e)&&k(t)){const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const a=B(n[o],r);if(!ie(e[a],t[a],r))return!1}return!0}return!1}function se(e){return Math.max(0,Math.ceil(e))}function le(e){return e??null}function ce(e){return j(e)?Object.entries(e).reduce((e,t)=>{const[r,n]=t;return e[r]=ce(n),e},{}):Array.isArray(e)?e.map(e=>ce(e)):e}function ue(e){return ce(e)}function me(...e){const t=new Set;for(const r of e)r.forEach(e=>t.add(e));return t}function pe(e,t){t.forEach(t=>e.add(t))}const de=1e-10;function he(e,t,r=de){if(e===t)return!0;const n=Math.abs(e-t);if(0===e||0===t||n<r)return n<r;return n/(Math.abs(e)+Math.abs(t))<r}function ge(e){return Math.abs(e)<de}function fe(e,t=0){const r=e.split("\n");for(;r[0]?.match(/^\s*$/);)r.shift();for(;r[r.length-1]?.match(/^\s*$/);)r.pop();const n=r.reduce((e,t)=>{if(t.match(/^\s*$/))return e;const r=t.match(/^\s*/)[0].length;return Math.min(e,r)},1/0);return r.map(e=>" ".repeat(t)+e.slice(n)).join("\n").trimEnd()}function ye(e,t){if(!Array.isArray(e))throw b("array",e,t)}function ve(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}(e))throw b("array of strings",e,t)}function be(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e&&1===e.length)}(e))throw b("array of strings",e,t)}const we={filter:{evaluate:()=>{throw new Error("filter is implemented in Dvala")},arity:te(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function"},coll:{type:"collection"},fun:{type:"function"}},variants:[{argumentNames:["coll","fun"]}],description:"Creates a new collection with all elements that pass the test implemented by $fun.",seeAlso:["collection.filteri","map","sequence.remove"],examples:['\nfilter(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)","\nfilter(\n { a: 1, b: 2 },\n odd?\n)"]}},map:{evaluate:()=>{throw new Error("map is implemented in Dvala")},arity:{min:2},docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function"},colls:{type:"collection",rest:!0,description:"At least one."},fun:{type:"function"}},variants:[{argumentNames:["colls","fun"]}],description:"Creates a new collection populated with the results of calling $fun on every element in $colls.",seeAlso:["collection.mapi","filter","reduce","mapcat","grid.cell-map","grid.cell-mapi"],examples:["[1, 2, 3] map -","[1, 2, 3] map -> -($)",'map(["Albert", "Mojir", 42], str)',"map([1, 2, 3], inc)","map([1, 2, 3], [1, 10, 100], *)","map({ a: 1, b: 2 }, inc)","map({ a: 1, b: 2 }, { a: 10, b: 20 }, +)"]}},reduce:{evaluate:()=>{throw new Error("reduce is implemented in Dvala")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.",seeAlso:["collection.reduce-right","collection.reducei","collection.reductions","map","grid.cell-reduce","grid.cell-reducei"],examples:["reduce([1, 2, 3], +, 0)","reduce([], +, 0)","reduce({ a: 1, b: 2 }, +, 0)","\nreduce(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + (even?(value) ? value : 0),\n 0)"]}},get:{evaluate:(e,t)=>{const[r,n]=e,o=le(e[2]);if(K(n,t),null===r)return o;P(r,t);const a=function(e,t){if(j(e)){if("string"==typeof t&&oe(e,t))return le(e[t])}else if(H(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return le(e[t])}(r,n);return void 0===a?o:a},arity:{min:2,max:3},docs:{category:"collection",returns:{type:"any"},args:{a:{type:"collection"},b:{type:["string","integer"]},"not-found":{type:"any",description:"Default value to return if $b is not found."}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","not-found"]}],description:"Returns value in $a mapped at $b.",seeAlso:["collection.get-in","contains?","find","nth"],examples:["[1, 2, 3] get 1",'{ a: 1 } get "a"','"Albert" get "3"',"\nget(\n [1, 2, 3],\n 1, // Optional comma after last argument\n)","\nget(\n [],\n 1\n)",'\nget(\n [],\n 1,\n "default"\n)','\nget(\n { a: 1 },\n "a"\n)','\nget(\n { a: 1 },\n "b"\n)','\nget(\n { a: 1 },\n "b",\n "default"\n)','\nget(\n null,\n "a"\n)','\nget(\n null,\n "b",\n "default"\n)']}},count:{evaluate:([e],t)=>null===e?0:"string"==typeof e?e.length:(P(e,t),Array.isArray(e)?e.length:Object.keys(e).length),arity:te(1),docs:{category:"collection",returns:{type:"number"},args:{coll:{type:["collection","null"]}},variants:[{argumentNames:["coll"]}],description:"Returns number of elements in $coll.",seeAlso:["empty?"],examples:["count([1, 2, 3])","count([])","count({ a: 1 })",'count("")','count("Albert")',"count(null)"]}},"contains?":{evaluate:([e,t],r)=>null!==e&&(P(e,r),W(e)?(G(t,r),e.includes(t)):T(e)?(E(t,r),!!e.find(e=>ie($(e),t,r))):(G(t,r),t in e)),arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:["collection","null"]},b:{type:["string","integer"]}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if $a contains $b, otherwise returns `false`. For strings, it checks if substring is included.",seeAlso:["get","find","index-of"],examples:["[1, 2, 3] contains? 1","null contains? 1",'{ a: 1, b: 2 } contains? "a"',"\ncontains?(\n [],\n 1\n)","\ncontains?(\n [1],\n 1\n)","\ncontains?(\n [1, 2, 3],\n 1\n)",'\ncontains?(\n {},\n "a"\n)','\ncontains?(\n { a: 1, b: 2 },\n "a"\n)']}},assoc:{evaluate:([e,t,r],n)=>(P(e,n),K(t,n),E(r,n),function(e,t,r,n){if(P(e,n),K(t,n),Array.isArray(e)||"string"==typeof e){if(Y(t,n,{integer:!0}),Y(t,n,{gte:0}),Y(t,n,{lte:e.length}),"string"==typeof e)return G(r,n,{char:!0}),`${e.slice(0,t)}${r}${e.slice(t+1)}`;const o=[...e];return o[t]=r,o}G(t,n);const o={...e};return o[t]=r,o}(e,t,r,n)),arity:te(3),docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},key:{type:["string","number"]},value:{type:"any"},kvs:{type:"any",description:"Key-value pairs to associate.",rest:!0}},variants:[{argumentNames:["coll","key","value"]},{argumentNames:["coll","key","value","kvs"]}],description:"\nAdd or replace the value of element $key to $value in $coll. Repeated for all key-value pairs in $kvs.\nIf $coll is an 'array', $key must be `number` satisfying `0 <=` $key `<= length`.",seeAlso:["collection.assoc-in","dissoc","merge","collection.update"],examples:['\nassoc(\n [1, 2, 3],\n 1,\n "Two"\n)','\nassoc(\n [1, 2, 3],\n 3,\n "Four"\n)','\nassoc(\n { a: 1, b: 2 },\n "a",\n "One")','\nassoc(\n { a: 1, b: 2 },\n "c",\n "Three")','\nassoc(\n "Albert",\n 6,\n "a")']}},"++":{evaluate:(e,t)=>(H(e[0])||P(e[0],t),Array.isArray(e[0])?e.reduce((e,r)=>(ye(r,t),e.concat(r)),[]):L(e[0])?e.reduce((e,r)=>(K(r,t),`${e}${r}`),""):e.reduce((e,r)=>(C(r,t),Object.assign(e,r)),{})),arity:{min:1},docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"collection"},colls:{type:"collection",rest:!0}},variants:[{argumentNames:["a"]},{argumentNames:["a","colls"]}],description:"Concatenates collections into one collection.",seeAlso:["mapcat","str","join","push","sequence.unshift"],examples:['"Albert" ++ " " ++ "Mojir"','"Albert" ++ "Mojir"','++("Albert", "-", "Mojir")','++("Albert")','++("A", "l", "b", "e", "r", "t")',"++([1, 2], [3, 4])","++([], [3, 4])","++([1, 2], [])","++([1, 2], [3, 4], [5, 6])","++([])","++({ a: 1, b: 2 }, { b: 1, c: 2 })","++({}, { a: 1 })"]}}},xe={range:{evaluate:(e,t)=>{const[r,n,o]=e;let a,i,s;Y(r,t,{finite:!0}),1===e.length?(a=0,i=r,s=i>=0?1:-1):2===e.length?(Y(n,t,{finite:!0}),a=r,i=n,s=i>=a?1:-1):(Y(n,t,{finite:!0}),Y(o,t,{finite:!0}),a=r,i=n,s=o,Y(s,t,i>a?{positive:!0}:i<a?{negative:!0}:{nonZero:!0}));const l=[];for(let e=a;s<0?e>i:e<i;e+=s)l.push(e);return l},arity:{min:1,max:3},docs:{category:"array",returns:{type:"number",array:!0},args:{a:{type:"number"},b:{type:"number"},step:{type:"number"}},variants:[{argumentNames:["b"]},{argumentNames:["a","b"]},{argumentNames:["a","b","step"]}],description:"$range creates an array with a range of numbers from $a to $b (exclusive), by $step.\n\n$a defaults to 0.\n$step defaults to 1.",seeAlso:["repeat","vector.linspace"],examples:["range(4)","range(1, 4)","1 range 10","range(0.4, 4.9)","\nrange(\n 0.25, // start value\n 1, // end value (exclusive)\n 0.25, // step value\n)"]}},repeat:{evaluate:([e,t],r)=>{Y(t,r,{integer:!0,nonNegative:!0});const n=[];for(let r=0;r<t;r+=1)n.push(e);return n},arity:te(2),docs:{category:"array",returns:{type:"any",array:!0},args:{a:{type:"any"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],description:"Returns an array with $a repeated $b times.",seeAlso:["range","string.string-repeat"],examples:["repeat(10, 3)","repeat(10, 0)",'"Albert" repeat 5']}},flatten:{evaluate:([e,t],r)=>{ye(e,r);const n=void 0===t||t===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:X(t,r,{integer:!0,nonNegative:!0});return e.flat(n)},arity:{min:1,max:2},docs:{category:"array",returns:{type:"any",array:!0},args:{x:{type:["array","any"],description:"If $x is not an array, `[ ]` is returned."},depth:{type:"integer",description:"The depth level specifying how deep a nested array structure should be flattened. Defaults to `Infinity`."}},variants:[{argumentNames:["x"]},{argumentNames:["x","depth"]}],description:"Takes a nested array $x and flattens it.",seeAlso:["mapcat"],examples:["flatten([1, 2, [3, 4], 5])","flatten([1, [2, [3, [4]]]], 1)","flatten([1, [2, [3, [4]]]], 2)",'\nlet foo = "bar";\nflatten([\n 1,\n " 2 A ",\n [foo, [4, ["ABC"]]],\n 6,\n])'],hideOperatorForm:!0}},mapcat:{evaluate:()=>{throw new Error("mapcat is implemented in Dvala")},arity:te(2),docs:{category:"array",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function"},colls:{type:"collection",array:!0},fun:{type:"function"}},variants:[{argumentNames:["colls","fun"]}],description:"Returns the result of applying concat to the result of applying map to $fun and $colls.",seeAlso:["flatten","map","++"],examples:["[[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]] mapcat reverse","mapcat([[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]], reverse)","[[3, 2, 1, 0,], [6, 5, 4,], [9, 8, 7]] mapcat reverse","\nlet foo = (n) -> do\n [n - 1, n, n + 1]\nend;\n[1, 2, 3] mapcat foo","\nmapcat(\n [[1, 2], [2, 2], [2, 3]],\n -> $ filter odd?\n)"]}},"moving-fn":{evaluate:()=>{throw new Error("moving-fn is implemented in Dvala")},arity:te(3),docs:{category:"array",returns:{type:"array"},args:{arr:{type:"array"},windowSize:{type:"number",description:"The size of the moving window."},fn:{type:"function"}},variants:[{argumentNames:["arr","windowSize","fn"]}],description:"Returns the result of applying $fn to each moving window of size $windowSize in $arr.",seeAlso:["running-fn","vector.moving-mean"],examples:["moving-fn([1, 2, 3], 2, sum)","moving-fn([1, 2, 3], 1, sum)","moving-fn([1, 2, 3], 3, sum)"]}},"running-fn":{evaluate:()=>{throw new Error("running-fn is implemented in Dvala")},arity:te(2),docs:{category:"array",returns:{type:"array"},args:{a:{type:"array"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns the result of applying $b to each element of $a.",seeAlso:["moving-fn","vector.running-mean"],examples:["running-fn([1, 2, 3], sum)","running-fn([1, 2, 3], max)","running-fn([1, 2, 3], min)"]}}},ke={nth:{evaluate:(e,t)=>{const[r,n]=e,o=le(e[2]);if(Y(n,t,{integer:!0}),null===r)return o;if(z(r,t),n>=0&&n<r.length){return le(r[n])}return o},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"any"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:["sequence","null"]},n:{type:"integer"},"not-found":{type:"any"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","not-found"]}],description:"Accesses element $n of $seq. Accessing out-of-bounds indices returns $not-found, if present, else `null`.",seeAlso:["first","second","last","get","slice"],examples:["[1, 2, 3] nth 1",'"A string" nth 3',"nth([1, 2, 3], 1)","nth([1, 2, 3], 3)","nth([1, 2, 3], -1)","nth([1, 2, 3], 3, 99)",'nth("A string", 1)','nth("A string", 3)','nth("A string", -3)','nth("A string", 30, "X")',"nth(null, 1)",'nth(null, 1, "Default value")']}},first:{evaluate:([e],t)=>{if(null===e)return null;z(e,t);return le(e[0])},arity:te(1),docs:{category:"sequence",returns:{type:"any"},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"Returns the first element of $seq. If $seq is empty or `null`, `null` is returned.",seeAlso:["second","last","nth","rest","next"],examples:['first(["Albert", "Mojir", 160, [1, 2]])',"first([])","first(null)"]}},last:{evaluate:([e],t)=>{if(null===e)return null;z(e,t);return le(e.at(-1))},arity:te(1),docs:{category:"sequence",returns:{type:"any"},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"Returns the last element of $seq. If $seq is empty, `null` is returned.",seeAlso:["first","second","nth","pop"],examples:['last(["Albert", "Mojir", 160, [1, 2]])',"last([1, 2])","last([1])","last([])","last(null)"]}},pop:{evaluate:([e],t)=>(z(e,t),"string"==typeof e?e.substring(0,e.length-1):e.slice(0,e.length-1)),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"],rest:!0},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns a copy of $seq with last element removed. If $seq is empty `null` is returned.",seeAlso:["push","last"],examples:["pop([1, 2, 3])","pop([])"]}},"index-of":{evaluate:([e,t],r)=>{if(E(t,r),null===e)return null;if(z(e,r),"string"==typeof e){G(t,r);const n=e.indexOf(t);return-1!==n?n:null}{const n=e.findIndex(e=>ie($(e,r),t),r);return-1!==n?n:null}},arity:te(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:["sequence","null"]},x:{type:"any"}},variants:[{argumentNames:["seq","x"]}],description:"Returns the index of $x in $seq. If element is not present in $seq `null` is returned.",seeAlso:["sequence.last-index-of","sequence.position","contains?"],examples:["[[1], [2], [1], [2]] index-of [1]",'index-of(["Albert", "Mojir", 160, [1, 2]], "Mojir")',"index-of([5, 10, 15, 20], 15)","index-of([5, 10, 15, 20], 1)","index-of(null, 1)"]}},push:{evaluate:([e,...t],r)=>(z(e,r),"string"==typeof e?(be(t,r),[e,...t].join("")):[...e,...t]),arity:{min:2},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},values:{type:"any",rest:!0,description:"At least one."}},variants:[{argumentNames:["seq","values"]}],description:"Returns copy of $seq with $values added to the end of it.",seeAlso:["sequence.unshift","pop","++"],examples:["[1, 2, 3] push 4",'"Albert" push "!"',"push([1, 2, 3], 4)","push([1, 2, 3], 4, 5, 6)","\nlet l = [1, 2, 3];\npush(l, 4);\nl"]}},rest:{evaluate:([e],t)=>(z(e,t),Array.isArray(e)?e.length<=1?[]:e.slice(1):e.substring(1)),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"]},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"If $seq is an array, returns a new array with all but the first element from $seq.\nIf $seq has less than two elements, an empty array is returned.\nFor string $seq returns all but the first characters in $seq.",seeAlso:["next","first"],examples:['rest(["Albert", "Mojir", 160, [1, 2]])','rest(["Albert"])',"rest([])",'rest("Albert")','rest("A",)','rest("")']}},next:{evaluate:([e],t)=>(z(e,t),Array.isArray(e)?e.length<=1?null:e.slice(1):e.length<=1?null:e.substring(1)),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"]},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"If $seq is an array, returns a new array with all but the first element from $seq. If $seq has less than two elements, `null` is returned. For string $seq returns all but the first characters in $seq. If length of string $seq is less than two, `null` is returned.",seeAlso:["rest","first"],examples:['next(["Albert", "Mojir", 160, [1, 2]])','next(["Albert"])',"next([])",'next("Albert")','next("A",)','next("")']}},reverse:{evaluate:([e],t)=>null===e?null:(z(e,t),Array.isArray(e)?[...e].reverse():e.split("").reverse().join("")),arity:te(1),docs:{category:"sequence",returns:{type:["sequence","null"]},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"If $seq is an array, creates a new array with the elements from $seq in reversed order. If $seq is a string, returns new reversed string.",seeAlso:["sort"],examples:['reverse(["Albert", "Mojir", 160, [1, 2]])',"reverse([])",'reverse("Albert")',"reverse(null)"]}},second:{evaluate:([e],t)=>null===e?null:(z(e,t),le(e[1])),arity:te(1),docs:{category:"sequence",returns:{type:"any"},args:{seq:{type:["sequence","null"]}},variants:[{argumentNames:["seq"]}],description:"Returns the second element of $seq. If $seq has less than two elements or is `null`, `null` is returned.",seeAlso:["first","last","nth"],examples:['second(["Albert", "Mojir", 160, [1, 2]])',"second([1])","second([])","second(null)"]}},slice:{evaluate:(e,t)=>{const[r,n,o]=e;return z(r,t),Y(n,t,{integer:!0}),2===e.length?(Array.isArray(r),r.slice(n)):(Y(o,t,{integer:!0}),Array.isArray(r),r.slice(n,o))},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},start:{type:"integer",description:"Defaults to `0`."},stop:{type:"integer",description:"Defaults to length of sequence + 1."}},variants:[{argumentNames:["seq","start"]},{argumentNames:["seq","start","stop"]}],description:"Returns a copy of a portion of $seq from index $start (inclusive) to $stop (exclusive).",seeAlso:["take","drop","sequence.splice","nth"],examples:["[1, 2, 3, 4, 5] slice 2","slice([1, 2, 3, 4, 5], 2, 4)","slice([1, 2, 3, 4, 5], 2)"]}},some:{evaluate:()=>{throw new Error("some is implemented in Dvala")},arity:te(2),docs:{category:"sequence",returns:{type:"any"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:["sequence","null"]},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the first element that passes the test implemented by $fun. I no element was found, `null` is returned.",seeAlso:["sequence.position","collection.any?","find"],examples:['\nsome(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nsome(\n [5, 10, 15, 20],\n -> $ > 10\n)","\nsome(\n [1, 2, 3, 4],\n -> $ > 10\n)","\nsome(\n [],\n -> $ > 10\n)","\nsome(\n null,\n -> $ > 10\n)"]}},sort:{evaluate:()=>{throw new Error("sort is implemented in Dvala")},arity:{min:1,max:2},docs:{category:"sequence",returns:{type:"any",rest:!0},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq"]},{argumentNames:["seq","fun"]}],description:"Returns a new sequence with the elements from $seq sorted according to $fun. If no $fun is supplied, builtin `compare` will be used.",seeAlso:["sequence.sort-by","compare","reverse","vector.sort-indices"],examples:["[3, 1, 2] sort (a, b) -> b - a","sort([3, 1, 2])","\nsort(\n [3, 1, 2],\n (a, b) -> cond case a < b then -1 case a > b then 1 case true then -1 end\n)","\nsort(\n [3, 1, 2],\n (a, b) -> cond case a > b then -1 case a < b then 1 case true then -1 end\n)"]}},take:{evaluate:([e,t],r)=>{Y(t,r),z(e,r);const n=Math.max(Math.ceil(t),0);return e.slice(0,n)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},n:{type:"integer"},seq:{type:"sequence"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array/string with the $n first elements from $seq.",seeAlso:["take-last","take-while","drop","slice","sequence.split-at"],examples:["take([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] take 3","take([1, 2, 3, 4, 5], 0)",'take("Albert", 2)','take("Albert", 50)']}},"take-last":{evaluate:([e,t],r)=>{z(e,r),Y(t,r);const n=Math.max(Math.ceil(t),0),o=e.length-n;return e.slice(o)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},n:{type:"integer"},seq:{type:"sequence"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array with the $n last elements from $seq.",seeAlso:["take","drop-last"],examples:["take-last([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] take-last 3","take-last([1, 2, 3, 4, 5], 0)"]}},drop:{evaluate:([e,t],r)=>{Y(t,r);const n=Math.max(Math.ceil(t),0);return z(e,r),e.slice(n)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"integer"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array/string with the $n first elements dropped from $seq.",seeAlso:["drop-last","drop-while","take","slice","sequence.split-at"],examples:["drop([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] drop 0",'drop("Albert", 2)','drop("Albert", 50)']}},"drop-last":{evaluate:([e,t],r)=>{z(e,r),Y(t,r);const n=Math.max(Math.ceil(t),0),o=e.length-n;return e.slice(0,o)},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"integer"}},variants:[{argumentNames:["seq","n"]}],description:"Constructs a new array with the $n last elements dropped from $seq.",seeAlso:["drop","take-last"],examples:["drop-last([1, 2, 3, 4, 5], 3)","[1, 2, 3, 4, 5] drop-last 3","drop-last([1, 2, 3, 4, 5], 0)"]}},"take-while":{evaluate:()=>{throw new Error("take-while is implemented in Dvala")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the members of $seq in order, stopping before the first one for which `predicate` returns a falsy value.",seeAlso:["take","drop-while","sequence.split-with"],examples:["take-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)","take-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)"]}},"drop-while":{evaluate:()=>{throw new Error("drop-while is implemented in Dvala")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the members of $seq in order, skipping the fist elements for witch the `predicate` returns a truethy value.",seeAlso:["drop","take-while","sequence.split-with"],examples:["drop-while(\n [1, 2, 3, 2, 1],\n -> $ < 3\n)","drop-while(\n [1, 2, 3, 2, 1],\n -> $ > 3\n)"]}}},qe=new WeakSet,Ae=new WeakSet,Ne=new WeakSet,$e=new WeakSet,Ee=new WeakSet,Te=new WeakSet,Se=new WeakSet;function ze(e){return Array.isArray(e)?(qe.has(e)||(je(e),Ve(e)||Me(e)),e):e}function je(e){return!!Array.isArray(e)&&(!!Ae.has(e)||!Ne.has(e)&&(e.every(e=>H(e))?(qe.add(e),Ae.add(e),!0):(Ne.add(e),!1)))}function Ce(e,t){if(!je(e))throw new o(`Expected a vector, but got ${e}`,t)}function Ie(e,t){if(!function(e){return!!je(e)&&2===e.length}(e))throw new o(`Expected a 2d vector, but got ${e}`,t)}function Re(e,t){if(!function(e){return!!je(e)&&3===e.length}(e))throw new o(`Expected a 3d vector, but got ${e}`,t)}function Pe(e,t){if(Ce(e,t),0===e.length)throw new o(`Expected a non empty vector, but got ${e}`,t)}function Me(e,t){if(!Array.isArray(e))return!1;if(Te.has(e))return!0;if(Se.has(e))return!1;if(0===e.length)return Se.add(e),!1;if(!Array.isArray(e[0]))return Se.add(e),!1;const r=e[0].length;if(0===r)return Se.add(e),!1;for(const n of e){if(!Array.isArray(n))return Se.add(e),!1;if(n.length!==r)return Se.add(e),!1;if(t&&n.some(e=>!t(e)))return!1}return qe.add(e),Te.add(e),!0}function Oe(e,t){if(!Me(e))throw new o(`Expected a grid, but got ${e}`,t)}function Ve(e){return Me(e,H)?($e.add(e),!0):(Array.isArray(e)&&Ee.add(e),!1)}function De(e,t){if(!Ve(e))throw new o(`Expected a matrix, but got ${e}`,t)}function Ue(e,t){if(!Ve(e))throw new o(`Expected a matrix, but got ${e}`,t);if(e.length!==e[0].length)throw new o(`Expected square matrix, but got ${e.length} and ${e[0].length}`,t)}function Fe(e,t){let r=!1,n=!1;for(const a of e)if(je(a))r=!0;else if(Ve(a))n=!0;else if(!H(a))throw new o("Invalid parameter type: "+typeof a,t);if(n){if(r)throw new o("Cannot mix vector and matrix types",t);let n=null,a=null;for(const r of e)if(Ve(r))if(null===n)n=r.length,a=r[0].length;else if(r.length!==n||r[0].length!==a)throw new o("Matrix dimensions do not match",t);return["matrix",e.map(e=>Ve(e)?e:Array.from({length:n},()=>Array.from({length:a},()=>e)))]}if(r){let r=null;for(const n of e)if(je(n))if(null===r)r=n.length;else if(n.length!==r)throw new o("Vector lengths do not match",t);return["vector",e.map(e=>je(e)?e:Array.from({length:r},()=>e))]}return["number",e]}function We(e){return(t,r)=>{const[n,o]=Fe(t,r);return"number"===n?e(o[0]):"vector"===n?o[0].map(t=>e(t)):o[0].map(t=>t.map(t=>e(t)))}}function Ge(e){return(t,r)=>{const[n,o]=Fe(t,r);return"number"===n?e(o[0],o[1]):"vector"===n?o[0].map((t,r)=>e(t,o[1][r])):o[0].map((t,r)=>t.map((t,n)=>e(t,o[1][r][n])))}}function Be(e,t){return(r,n)=>{if(0===r.length)return e;const[o,a]=Fe(r,n);if("number"===o)return a.reduce((e,r)=>t(e,r),e);if("vector"===o){const[e,...r]=a;return r.reduce((e,r)=>e.map((e,n)=>t(e,r[n])),e)}{const[e,...r]=a;return r.reduce((e,r)=>e.map((e,n)=>e.map((e,o)=>t(e,r[n][o]))),e)}}}const Le={inc:{evaluate:We(e=>e+1),arity:te(1),docs:{category:"math",returns:{type:"number"},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `inc` function increments its argument by 1, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it increases each element by 1 while preserving the original structure.",seeAlso:["dec","+"],examples:["inc(0)","inc(1)","inc(100.1)","inc([1, 2, 3])","inc([[1, 2], [3, 4]])"]}},dec:{evaluate:We(e=>e-1),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `dec` function decrements its argument by 1, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it decreases each element by 1 while preserving the original structure.",seeAlso:["inc","-"],examples:["dec(0)","dec(1)","dec(100.1)","dec([1, 2, 3])","dec([[1, 2], [3, 4]])"]}},"+":{evaluate:Be(0,(e,t)=>e+t),arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"The `+` function performs addition of numbers and element-wise addition of `vectors` and `matrices` of compatible dimensions, returning the same type as its inputs. When used with mixed types, it adds the scalar to each element of the collection.",seeAlso:["-","*","/","inc"],examples:["1 + 2","1 + 20 + 30","+(1, 2, 3, 4)","+()","+(1)","[1, 2, 3] + 2","[1, 2, 3] + [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] + [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] + 2"]}},"*":{evaluate:Be(1,(e,t)=>e*t),arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"The `*` function performs multiplication of `numbers` and element-wise multiplication of `vectors` and `matrices` of compatible dimensions, returning the same type as its inputs. When used with mixed types, it multiplies each element of the collection by the scalar.",seeAlso:["/","+","-","^"],examples:["6 * 7","-1 * 4","*(4, 7)","*(1, 2, 3, 4, 5)","*()","*(8)","[1, 2, 3] * 2","[1, 2, 3] * [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] * [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] * 2"]}},"/":{evaluate:(e,t)=>{if(0===e.length)return 1;const[r,n]=Fe(e,t);if("number"===r){const[e,...t]=n;return 0===t.length?1/e:t.reduce((e,t)=>e/t,e)}if("vector"===r){const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e/t[r]),e)}{const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e.map((e,n)=>e/t[r][n])),e)}},arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"The `/` function performs division of `numbers` and element-wise division of `vectors` and `matrices` of compatible dimensions, returning the same type as its inputs. When used with mixed types, it divides each element of the collection by the scalar.",seeAlso:["*","+","-","quot","mod","%"],examples:["12 / 100","-1 / 4","/(7, 4)","/(1, 2, 4, 8)","/()","/(8)","[1, 2, 3] / 2","[1, 2, 3] / [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] / [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] / 2"]}},"-":{evaluate:(e,t)=>{if(0===e.length)return 0;const[r,n]=Fe(e,t);if("number"===r){const[e,...t]=n;return 0===t.length?-e:t.reduce((e,t)=>e-t,e)}if("vector"===r){const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e-t[r]),e)}{const e=n[0];return n.slice(1).reduce((e,t)=>e.map((e,r)=>e.map((e,n)=>e-t[r][n])),e)}},arity:{},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]},xs:{type:["number","vector","matrix"],rest:!0}},variants:[{argumentNames:["xs"]}],description:"Computes difference between first value and sum of the rest. When called with only one argument, it does negation.",seeAlso:["+","*","/","dec","abs"],examples:["50 - 8","1 - 1 - 1","-()","-(4, 2)","-(4, 3, 2, 1,)","[1, 2, 3] - 2","[1, 2, 3] - [4, 5, 6]","[[1, 2, 3], [4, 5, 6]] - [[7, 8, 9], [10, 11, 12]]","[[1, 2, 3], [4, 5, 6]] - 2"]}},quot:{evaluate:Ge((e,t)=>Math.trunc(e/t)),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The `quot` function performs integer division truncated toward zero, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies integer division between each element of the collection and the scalar.",seeAlso:["mod","%","/","trunc"],examples:["quot(5, 3)","quot(5.2, 3.1)","quot(-5, 3)","5 quot -3","-5 quot -3","quot(5, 0)","quot(0, 5)","[1, 2, 3] quot 2","2 quot [1, 2, 3]","quot([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] quot [[7, 8, 9], [10, 11, 12]]","quot([[1, 2, 3], [4, 5, 6]], 2)","[[1, 2, 3], [4, 5, 6]] quot [[7, 8, 9], [10, 11, 12]]"]}},mod:{evaluate:Ge((e,t)=>e-t*Math.floor(e/t)),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The `mod` function computes the modulo of division with the same sign as the divisor, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies the modulo operation between each element of the collection and the scalar.",seeAlso:["%","quot","/"],examples:["mod(5, 3)","mod(5.2, 3.1)","mod(-5, 3)","5 mod -3","-5 mod -3","[1, 2, 3] mod 2","2 mod [1, 2, 3]","mod([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] mod [[7, 8, 9], [10, 11, 12]]","mod([[1, 2, 3], [4, 5, 6]], 2)"]}},"%":{evaluate:Ge((e,t)=>e%t),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The `%` function computes the remainder of division with the same sign as the dividend, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies the remainder operation between each element of the collection and the scalar.",seeAlso:["mod","quot","/"],examples:["5 % 3","5.2 % 3.1","-5 % 3","%(5, -3)","%(-5, -3)","[1, 2, 3] % 2","2 % [1, 2, 3]","%([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] % [[7, 8, 9], [10, 11, 12]]","%([[1, 2, 3], [4, 5, 6]], 2)"]}},sqrt:{evaluate:We(e=>Math.sqrt(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sqrt` function calculates the square root of `numbers` and computes element-wise square roots of `vectors` and `matrices`. When applied to collections, it returns the square root of each element while preserving the original structure.",seeAlso:["cbrt","^"],examples:["sqrt(0)","sqrt(9)","sqrt(2)","sqrt(0)","sqrt(9)","sqrt(2)","sqrt([1, 4, 9])","sqrt([[1, 4], [9, 16]])"]}},cbrt:{evaluate:We(e=>Math.cbrt(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cbrt` function calculates the cube root of `numbers` and computes element-wise cube roots of `vectors` and `matrices`. When applied to collections, it returns the cube root of each element while preserving the original structure.",seeAlso:["sqrt","^"],examples:["cbrt(0)","cbrt(27)","cbrt(2)","cbrt(1)","cbrt(0)","cbrt(27)","cbrt(2)","cbrt(1)","cbrt([1, 8, 27])","cbrt([[1, 8], [27, 64]])"]}},"^":{evaluate:Ge((e,t)=>e**t),arity:te(2),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:["number","vector","matrix"]}},variants:[{argumentNames:["a","b"]}],description:"The ^ function computes exponentiation, raising the first argument to the power of the second, working on `numbers` and element-wise on `vectors` and `matrices` of compatible dimensions. When used with mixed types, it applies the power operation between each element of the collection and the scalar.",seeAlso:["sqrt","cbrt","*","math.ln"],examples:["2 ^ 3","2 ^ 0","2 ^ -3","^(-2, 3)","^(-2, -3)","[1, 2, 3] ^ 2","2 ^ [1, 2, 3]","^([1, 2, 3], [4, 5, 6])","[[1, 2, 3], [4, 5, 6]] ^ [[7, 8, 9], [10, 11, 12]]","^([[1, 2, 3], [4, 5, 6]], 2)"]}},round:{evaluate:([e,t],r)=>{const[n,o]=Fe([e],r);if("number"===n){if(void 0===t||0===t)return Math.round(o[0]);{Y(t,r,{integer:!0,positive:!0});const e=10**t;return Math.round(o[0]*e)/e}}if("vector"===n){const e=o[0];if(void 0===t||0===t)return e.map(e=>Math.round(e));{Y(t,r,{integer:!0,positive:!0});const n=10**t;return e.map(e=>Math.round(e*n)/n)}}{const e=o[0];if(void 0===t||0===t)return e.map(e=>e.map(e=>Math.round(e)));{Y(t,r,{integer:!0,positive:!0});const n=10**t;return e.map(e=>e.map(e=>Math.round(e*n)/n))}}},arity:{min:1,max:2},docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{a:{type:["number","vector","matrix"]},b:{type:"integer"}},variants:[{argumentNames:["a"]},{argumentNames:["a","b"]}],description:"The `round` function rounds a `number` to the nearest `integer` or to a specified number of `decimal` places, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it rounds each element while preserving the original structure.",seeAlso:["floor","ceil","trunc"],examples:["round(2)","round(2.49)","round(2.5)","round(-2.49)","round(-2.5)","round(-2.501)","round(1.23456789, 4)","1.123456789 round 2","round([1.23456789, 2.3456789], 1)","[1.23456789, 2.3456789] round 4","[[1.23456789, 2.3456789], [3.456789, 4.56789]] round 4","round([[1.23456789, 2.3456789], [3.456789, 4.56789]], 2)"]}},trunc:{evaluate:We(e=>Math.trunc(e)),arity:te(1),docs:{category:"math",returns:{type:["integer","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `trunc` function truncates `numbers` toward zero (removing decimal portions without rounding), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it truncates each element while preserving the original structure.",seeAlso:["round","floor","ceil","quot"],examples:["trunc(2)","trunc(2.49)","trunc(2.5)","trunc(-2.49)","trunc(-2.5)","trunc(-2.501)","trunc([1.23456789, 2.3456789])","trunc([[1.23456789, 2.3456789], [3.456789, 4.56789]])"]}},floor:{evaluate:We(e=>Math.floor(e)),arity:te(1),docs:{category:"math",returns:{type:["integer","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `floor` function returns the largest `integer` less than or equal to a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the floor of each element while preserving the original structure.",seeAlso:["ceil","round","trunc"],examples:["floor(2)","floor(2.49)","floor(2.5)","floor(-2.49)","floor(-2.5)","floor(-2.501)","floor([1.23456789, 2.3456789])","floor([[1.23456789, 2.3456789], [3.456789, 4.56789]])"]}},ceil:{evaluate:We(e=>Math.ceil(e)),arity:te(1),docs:{category:"math",returns:{type:["integer","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `ceil` function returns the smallest `integer` greater than or equal to a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the ceiling of each element while preserving the original structure.",seeAlso:["floor","round","trunc"],examples:["ceil(2)","ceil(2.49)","ceil(2.5)","ceil(-2.49)","ceil(-2.5)","ceil(-2.501)","ceil([1.23456789, 2.3456789])","ceil([[1.23456789, 2.3456789], [3.456789, 4.56789]])"]}},min:{evaluate:(e,t)=>{if(1===e.length&&je(e[0])){const r=e[0];return Pe(r,t),r.reduce((e,t)=>Math.min(e,t),1/0)}const[r,...n]=e;return Y(r,t),n.reduce((e,r)=>(Y(r,t),Math.min(e,r)),r)},arity:{min:1},docs:{category:"math",returns:{type:"number"},args:{a:{type:"number"},b:{type:"number"},xs:{type:"number",rest:!0},vector:{type:"vector"}},variants:[{argumentNames:["xs"]},{argumentNames:["vector"]}],description:"Returns the smallest value. Accepts either multiple numbers or a single vector of numbers.",seeAlso:["max","vector.span","vector.min-index"],examples:["2 min 3","min(2, 0, 1)","min(2, -1, 1)","min([2, 0, -1])","12 min 14"]}},max:{evaluate:(e,t)=>{if(1===e.length&&je(e[0])){const r=e[0];return Pe(r,t),r.reduce((e,t)=>Math.max(e,t),-1/0)}const[r,...n]=e;return Y(r,t),n.reduce((e,r)=>(Y(r,t),Math.max(e,r)),r)},arity:{min:1},docs:{category:"math",returns:{type:"number"},args:{a:{type:"number"},b:{type:"number"},xs:{type:"number",rest:!0},vector:{type:"vector"}},variants:[{argumentNames:["xs"]},{argumentNames:["vector"]}],description:"Returns the largest value. Accepts either multiple numbers or a single vector of numbers.",seeAlso:["min","vector.span","vector.max-index"],examples:["2 max 3","max(2, 0, 1)","max(2, -1, 1)","max([2, 0, -1])","4 max 2"]}},abs:{evaluate:We(e=>Math.abs(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The abs function returns the absolute value (magnitude) of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the absolute value of each element while preserving the original structure.",seeAlso:["sign","-"],examples:["abs(-2.3)","abs(0)","abs(2.5)","abs([1, -2, 3])","abs([[1, -2], [3, -4]])"]}},sign:{evaluate:We(e=>Math.sign(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sign` function returns the `sign` of a `number` (-1 for negative, 0 for zero, 1 for positive), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the sign of each element while preserving the original structure.",seeAlso:["abs"],examples:["sign(-2.3)","sign(-0)","sign(0)","sign(12312)","sign([1, -2, 3])","sign([[1, -2], [3, -4]])"]}}};function _e([e,...t],r){const n=$(e,r);for(const e of t)if(!ie(n,$(e,r),r))return!1;return!0}const Ke={"==":{evaluate:(e,t)=>_e(e,t),arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"},x:{type:"any"},ys:{type:"any",rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if all `values` are structaul equal to each other, otherwise result is `false`.",seeAlso:["!=","identical?"],examples:["1 == 1","[1, 2] == [1, 2]","\n{\n a: 1,\n b: 2,\n} == {\n b: 2,\n a: 1,\n}","==(1, 1)","==(1.01, 1)",'==("1", 1)','==("2", "2", "2", "2")',"==(2, 2, 1, 2)","==([1, 2], [1, 2])","==({ a: 1, b: 2 }, { b: 2, a: 1 })"]}},"!=":{evaluate:(e,t)=>!_e(e,t),arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"},x:{type:"any"},ys:{type:"any",rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if all `values` are not equal to each other, otherwise result is `false`. `(!= a b c)` is same as `(not (== a b c))`.",seeAlso:["==","identical?"],examples:["1 != 2","3 != 3","!=(3)","!=(3, 3, 2)",'!=("3", "2", "1", "0",)',"!=(0, -0)"]}},"identical?":{evaluate:e=>function([e,...t]){for(const r of t)if(r!==e)return!1;return!0}(e),arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"}},variants:[{argumentNames:["a","b"]}],description:"Returns true if $a and $b are referential equal.",seeAlso:["==","!="],examples:["identical?({ a: 10, b: 20 }, { b: 20, a: 10 })","identical?([1, true, null], [1, true, null])","identical?(0.3, 0.1 + 0.2)"]}},">":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)<=0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in decreasing order, `false` otherwise.",seeAlso:["<",">=","<=","compare"],examples:[">(1, 0)",">(1.01, 1)",">(1, 1)",">(4, 3, 2, 1)",">(3, 2, 2, 1)"]}},"<":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)>=0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in increasing order, `false` otherwise.",seeAlso:[">",">=","<=","compare"],examples:["<(0, 1)","<(1, 1.01)","<(1, 1)","<(1, 2, 2, 3)",'<("a", "b")']}},">=":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)<0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in non increasing order, `false` otherwise.",seeAlso:[">","<","<=","compare"],examples:["1 >= 1","0 >= 1",">=(1, 0)",">=(1.01, 1)",">=(1, 1)",">=(4, 3, 2, 1)",">=(3, 2, 2, 1)"]}},"<=":{evaluate:([e,...t],r)=>{let n=_(e);for(const e of t){if(ae(n,_(e),r)>0)return!1;n=_(e)}return!0},arity:{min:1},docs:{category:"misc",returns:{type:"boolean"},args:{a:{type:["number","string"]},b:{type:["number","string"]},x:{type:["number","string"]},ys:{type:["number","string"],rest:!0}},variants:[{argumentNames:["x"]},{argumentNames:["x","ys"]}],description:"Returns `true` if $x and $ys are in non decreasing order, `false` otherwise.",seeAlso:[">","<",">=","compare"],examples:["1 <= 1","<=(0, 1)","<=(1, 1.01)","<=(1, 1)","<=(1, 2, 3, 4)","<=(1, 2, 2, 3)"]}},not:{evaluate:([e])=>!e,arity:te(1),docs:{category:"misc",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Computes logical negation. Note that any other $x than `false`, `0`, `null` and `''` is truthy.",seeAlso:["boolean"],examples:["not(3)","not(true)",'not("A string")',"not(0)","not(false)","not(null)",'not("")']}},"epoch->iso-date":{evaluate:([e],t)=>(Y(e,t),new Date(e).toISOString()),arity:te(1),docs:{category:"misc",returns:{type:"string"},args:{ms:{type:"number"}},variants:[{argumentNames:["ms"]}],description:"Returns IOS date time string from `ms` (milliseconds elapsed since the UNIX epoch).",seeAlso:["iso-date->epoch"],examples:["epoch->iso-date(1649756230899)","epoch->iso-date(0)"]}},"iso-date->epoch":{evaluate:([e],t)=>{G(e,t);const r=new Date(e).valueOf();return Y(r,t,{finite:!0}),r},arity:te(1),docs:{category:"misc",returns:{type:"number"},args:{iso:{type:"string"}},variants:[{argumentNames:["iso"]}],description:"Returns milliseconds elapsed since the UNIX epoch to `iso`.",seeAlso:["epoch->iso-date"],examples:['iso-date->epoch("2022-04-12T09:37:10.899Z")','iso-date->epoch("1980-01-01")']}},boolean:{evaluate:([e])=>!!e,arity:te(1),docs:{category:"misc",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Coerces $x to boolean.",seeAlso:["not","boolean?","true?","false?"],examples:["boolean(0)","boolean(1)","boolean(null)",'boolean("Albert")']}},compare:{evaluate:([e,t],r)=>(K(e,r),K(t,r),ae(e,t,r)),arity:te(2),docs:{category:"misc",returns:{type:"number"},args:{a:{type:["number","string"]},b:{type:["number","string"]}},variants:[{argumentNames:["a","b"]}],description:"Compares two values. Returns `-1` if $a < $b, `1` if $a > $b and `0` if $a and $b have the same sort order.",seeAlso:["<",">","<=",">=","sort","sequence.sort-by"],examples:["compare(0, 1)","compare(0, 0)","compare(1, 0)",'compare("Albert", "Mojir")']}},"json-parse":{evaluate:([e],t)=>(G(e,t),JSON.parse(e)),arity:te(1),docs:{category:"misc",returns:{type:"any"},args:{x:{type:"string"}},variants:[{argumentNames:["x"]}],description:"Returns `JSON.parse(`$x`)`.",seeAlso:["json-stringify"],examples:['json-parse("[1, 2, 3]")']}},"json-stringify":{evaluate:([e,t],r)=>(E(e,r),void 0===t?JSON.stringify(e):(Y(t,r),JSON.stringify(e,null,t))),arity:{min:1,max:2},docs:{category:"misc",returns:{type:"string"},args:{x:{type:"any"},indent:{type:"integer",description:"Number of spaces to use for indentation."}},variants:[{argumentNames:["x"]},{argumentNames:["x","indent"]}],description:"Returns `JSON.stringify(`$x`)`. If second argument is provided, returns `JSON.stringify(`$x`, null, `$indent`)`.",seeAlso:["json-parse"],examples:["json-stringify([1, 2, 3])","json-stringify({ a: { b: 10 }}, 2)"],hideOperatorForm:!0}},"effect-name":{evaluate:([e],t)=>function(e,t){return D(e,t),e}(e,t).name,arity:te(1),docs:{category:"meta",returns:{type:"string"},args:{e:{type:"any",description:"An effect reference."}},variants:[{argumentNames:["e"]}],description:"Returns the name of an effect reference as a string.",seeAlso:["effect-matcher","effect?"],examples:["effect-name(effect(dvala.error))","effect-name(effect(llm.complete))"]}},"effect-matcher":{evaluate:([e],t)=>{if("string"==typeof e)return{[p]:!0,sourceCodeInfo:t,functionType:"EffectMatcher",matchType:"string",pattern:e,flags:"",arity:te(1)};if(M(e))return{[p]:!0,sourceCodeInfo:t,functionType:"EffectMatcher",matchType:"regexp",pattern:e.s,flags:e.f,arity:te(1)};throw new o("effect-matcher expects a string or regexp pattern",t)},arity:te(1),docs:{category:"meta",returns:{type:"function"},args:{pattern:{type:["string","regexp"],description:"A wildcard pattern or regexp to match against effect names."}},variants:[{argumentNames:["pattern"]}],description:"Returns a predicate function that matches effects by name. If $pattern is a string, uses wildcard matching: no wildcard means exact match, `.*` suffix matches the prefix and all descendants (dot boundary enforced), and `*` alone matches everything. If $pattern is a regexp, tests the effect name against the regexp.",seeAlso:["effect-name","effect?"],examples:['let pred = effect-matcher("dvala.*"); pred(effect(dvala.error))','let pred = effect-matcher("dvala.*"); pred(effect(custom.foo))','let pred = effect-matcher("*"); pred(effect(anything))']}},"type-of":{evaluate:([e])=>null==e?"null":"boolean"==typeof e?"boolean":"number"==typeof e?"number":"string"==typeof e?"string":V(e)?"effect":M(e)?"regexp":q(e)?"function":Array.isArray(e)?"array":"object",arity:te(1),docs:{category:"misc",returns:{type:"string"},args:{x:{type:"any",description:"The value to inspect."}},variants:[{argumentNames:["x"]}],description:'Returns a string representing the type of $x. Possible return values are `"number"`, `"string"`, `"boolean"`, `"null"`, `"array"`, `"object"`, `"function"`, `"regexp"`, and `"effect"`.',seeAlso:["number?","string?","boolean?","null?","array?","object?","function?","regexp?","effect?"],examples:["type-of(42)",'type-of("hello")',"type-of(true)","type-of(null)","type-of([1, 2, 3])","type-of({ a: 1 })","type-of((x) -> x + 1)",'type-of(regexp("^start"))',"type-of(effect(dvala.io.println))"]}}},Je={keys:{evaluate:([e],t)=>(C(e,t),Object.keys(e)),arity:te(1),docs:{category:"object",returns:{type:"any",array:!0},args:{obj:{type:"object"}},variants:[{argumentNames:["obj"]}],description:"Returns array of all keys in $obj.",seeAlso:["vals","entries","zipmap","select-keys"],examples:["keys({})",'keys({ x: 10, y: true, z: "A string" })','keys(object("x", 10, "y", true, "z", "A string"))']}},vals:{evaluate:([e],t)=>(C(e,t),Object.values(e)),arity:te(1),docs:{category:"object",returns:{type:"any",array:!0},args:{obj:{type:"object"}},variants:[{argumentNames:["obj"]}],description:"Returns array of all values in $obj.",seeAlso:["keys","entries","zipmap"],examples:["vals({})",'vals({ x: 10, y: true, z: "A string" })','vals(object("x", 10, "y", true, "z", "A string"))']}},entries:{evaluate:([e],t)=>(C(e,t),Object.entries(e)),arity:te(1),docs:{category:"object",returns:{type:"array"},args:{obj:{type:"object"}},variants:[{argumentNames:["obj"]}],description:"Returns nested array of all key - value pairs in $obj.",seeAlso:["keys","vals","zipmap","find"],examples:["entries({})",'entries({ x: 10, y: true, z: "A string" })','entries(object("x", 10, "y", true, "z", "A string"))']}},find:{evaluate:([e,t],r)=>(C(e,r),G(t,r),oe(e,t)?[t,e[t]]:null),arity:te(2),docs:{category:"object",returns:{type:["array","null"]},args:{a:{type:"object"},b:{type:"string"},obj:{type:"object"},key:{type:"string"}},variants:[{argumentNames:["obj","key"]}],description:"Returns entry (key-value pair) for $key, or `null` if $key not present in $obj.",seeAlso:["get","contains?","entries","sequence.position","some"],examples:['{ a: 1, "b": 2 } find "a"','find(object("a", 1, "b", 2), "b")','find(object("a", 1, "b", 2), "c")']}},dissoc:{evaluate:([e,t],r)=>{C(e,r),G(t,r);const n={...e};return delete n[t],n},arity:te(2),docs:{category:"object",returns:{type:"object"},args:{a:{type:"object"},b:{type:"string"},obj:{type:"object"},key:{type:"string"}},variants:[{argumentNames:["obj","key"]}],description:"Return shallow copy of $obj with $key deleted.",seeAlso:["assoc","select-keys"],examples:['{ x: 10, y: 20 } dissoc "y"','dissoc({ x: 10, y: 20 }, "x")','dissoc({ x: 10 }, "y")','\nlet o = { a: 5 };\ndissoc(o, "a");\no']}},merge:{evaluate:(e,t)=>{if(0===e.length)return null;const[r,...n]=e;return C(r,t),n.reduce((e,r)=>(C(r,t),{...e,...r}),{...r})},arity:{min:0},docs:{category:"object",returns:{type:"object"},args:{a:{type:"object"},b:{type:"object"},objs:{type:"object",rest:!0}},variants:[{argumentNames:["objs"]}],description:"Returns a new object created by merging together all arguments.\n\nIf two keys appears in more than one object the value from the last object is used.\nIf no arguments are provided `null` is returned.",seeAlso:["merge-with","assoc"],examples:["{ x: 10 } merge { y: 20 }",'merge(object("x", 10), object("y", 20))','merge(object("x", 10), object("x", 15, "y", 20))']}},"merge-with":{evaluate:()=>{throw new Error("merge-with is implemented in Dvala")},arity:{min:2},docs:{category:"object",returns:{type:"object"},args:{objs:{type:"object",rest:!0},fun:{type:"function"}},variants:[{argumentNames:["objs","fun"]}],description:"\nReturns a new object created by merging together all arguments.\nIf two keys appears in more than one object $fun is used to calculate the new value.\n\nIf no arguments are provided `null` is returned.",seeAlso:["merge"],examples:['merge-with(object("x", 10), object("y", 20), +)','merge-with(object("x", 10), object("x", 15, "y", 20), +)',"merge-with({ x: 10 }, { x: 20 }, { x: 30 }, { x: 40 }, -)"],hideOperatorForm:!0}},zipmap:{evaluate:([e,t],r)=>{ve(e,r),ye(t,r);const n=Math.min(e.length,t.length),o={};for(let a=0;a<n;a+=1){o[B(e[a],r)]=le(t[a])}return o},arity:te(2),docs:{category:"object",returns:{type:"object"},args:{a:{type:"array"},b:{type:"array"}},variants:[{argumentNames:["a","b"]}],description:"Returns a new object created by mapping $a to $b.",seeAlso:["entries","keys","vals","sequence.interleave"],examples:['["a", "b", "c"] zipmap [1, 2, 3]','zipmap(["a", "b", "c"], [10, null, [1, 2, 3]])','zipmap(["a", "b", "c"], [1])',"zipmap([], [10, null, [1, 2, 3]])"]}},"select-keys":{evaluate:([e,t],r)=>(ve(t,r),C(e,r),t.reduce((t,r)=>(oe(e,r)&&(t[r]=le(e[r])),t),{})),arity:te(2),docs:{category:"object",returns:{type:"object"},args:{a:{type:"object"},b:{type:"array"}},variants:[{argumentNames:["a","b"]}],description:"Returns an object containing only those entries in $a whose key is in $b.",seeAlso:["dissoc","keys"],examples:['{ a: 1, b: 2, c: 3 } select-keys ["a", "b"]','select-keys({ a: 1, b: 2, c: 3 }, ["a", "b"])','select-keys({ a: 1 }, ["a", "b"])']}}},He={"function?":{evaluate:([e])=>q(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a function, otherwise `false`.",seeAlso:["string?","number?","boolean?","null?","array?","object?","regexp?","type-of"],examples:["function?(+)","function?(/)","function?((x, y) -> x + y)","function?(false)",'function?("false")',"function?([1, 2, 3])"]}},"string?":{evaluate:([e])=>"string"==typeof e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a string, otherwise `false`.",seeAlso:["blank?","number?","boolean?","null?","array?","object?","regexp?","function?","collection?","sequence?","type-of"],examples:['string?("")','string?("A string")','string?(true ? "A string" : false)',"string?(false)","string?([1, 2, 3])","string?(100)"]}},"number?":{evaluate:([e])=>"number"==typeof e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a number, otherwise `false`.",seeAlso:["integer?","zero?","pos?","neg?","finite?","number","string?","boolean?","null?","function?","type-of"],examples:["number?(0)","number?(2)","number?(-0.12)","number?(false)","number?([1, 2, 3])",'number?("A string")']}},"integer?":{evaluate:([e])=>"number"==typeof e&&H(e,{integer:!0}),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an integer, otherwise `false`.",seeAlso:["number?","number","even?","odd?"],examples:["integer?(0)","integer?(-12)","integer?(42)","integer?(10.1)","integer?((x, y) -> x + y)","integer?(false)",'integer?("false")',"integer?([1, 2, 3])"]}},"boolean?":{evaluate:([e])=>"boolean"==typeof e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a `boolean`, otherwise `false`.",seeAlso:["true?","false?","boolean","string?","number?","null?","function?","type-of"],examples:["boolean?(true)","boolean?(false)","boolean?([1, 2, 3])","boolean?(0)",'boolean?("A string")']}},"null?":{evaluate:([e])=>null==e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `null`, otherwise `false`.",seeAlso:["empty?","not-empty?","string?","number?","boolean?","function?","type-of"],examples:["null?(null)","null?(false)","null?([1, 2, 3])","null?(0)",'null?("A string")']}},"zero?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),Math.abs(e)<de),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `0`, otherwise `false`.",seeAlso:["pos?","neg?","even?","number?"],examples:["zero?(0)","zero?(-0.0)","zero?(1)","zero?(0.1)"]}},"pos?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),e>0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is greater than `0`, otherwise `false`.",seeAlso:["neg?","zero?","number?"],examples:["pos?(0)","pos?(-0.0)","pos?(1)","pos?(-0.1)"]}},"neg?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),e<0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is less than `0`, otherwise `false`.",seeAlso:["pos?","zero?","number?"],examples:["neg?(0)","neg?(-0.0)","neg?(1)","neg?(-0.1)"]}},"even?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),e%2==0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is even, otherwise `false`.",seeAlso:["odd?","integer?","zero?"],examples:["even?(0)","even?(-0.0)","even?(-1)","even?(2.1)"]}},"odd?":{evaluate:([e],t)=>(Y(e,t,{finite:!0}),H(e,{integer:!0})&&e%2!=0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is odd, otherwise `false`.",seeAlso:["even?","integer?"],examples:["odd?(1.0)","odd?(1.001)","odd?(-1)","odd?(2.1)"]}},"array?":{evaluate:([e])=>Array.isArray(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an array, otherwise `false`.",seeAlso:["sequence?","collection?","object?","string?","vector?","matrix?","grid?","function?","type-of"],examples:["array?([])","array?([1, 2, 3])",'array?(object("a", 10))',"array?(42)","array?(10.1)","array?((x, y) -> x + y)"]}},"collection?":{evaluate:([e])=>I(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a collection i.e. an array, an object or a string, otherwise `false`.",seeAlso:["sequence?","array?","object?","string?"],examples:["collection?([])","collection?([1, 2, 3])",'collection?(object("a", 10))','collection?("Albert")',"collection?(42)","collection?(10.1)","collection?((x, y) -> x + y)"]}},"sequence?":{evaluate:([e])=>T(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a sequence i.e. an array or a string, otherwise `false`.",seeAlso:["collection?","array?","string?"],examples:["sequence?([])","sequence?([1, 2, 3])",'sequence?(object("a", 10))','sequence?("Albert")',"sequence?(42)","sequence?(10.1)","sequence?((x, y) -> x + y)"]}},"object?":{evaluate:([e])=>j(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an object, otherwise `false`.",seeAlso:["collection?","array?","string?","function?","type-of"],examples:['object?(object("a", 10))',"object?(42)","object?(10.1)","object?((x, y) -> x + y)",'object?(#"^start")','object?("false")',"object?([1, 2, 3])"]}},"regexp?":{evaluate:([e])=>M(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is a regexp, otherwise `false`.",seeAlso:["regexp","re-match","string?","function?","type-of"],examples:['regexp?(regexp("^start"))','regexp?(#"^start")',"regexp?(-12)","regexp?({})","regexp?(10.1)","regexp?((x, y) -> x + y)","regexp?(false)",'regexp?("false")',"regexp?([1, 2, 3])"]}},"effect?":{evaluate:([e])=>V(e),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is an effect, otherwise `false`.",seeAlso:["effect","effect-name","effect-matcher","perform","type-of"],examples:["effect?(effect(dvala.io.println))","effect?(42)",'effect?("hello")',"effect?(null)","effect?({})","effect?([1, 2, 3])"]}},"finite?":{evaluate:([e],t)=>(Y(e,t),Number.isFinite(e)),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is finite, otherwise `false`.",seeAlso:["positive-infinity?","negative-infinity?","number?"],examples:["finite?(1.0)","finite?(1 / 0)","finite?(-1 / 0)"]}},"positive-infinity?":{evaluate:([e],t)=>(Y(e,t),e===Number.POSITIVE_INFINITY),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x equals positive infinity, otherwise `false`.",seeAlso:["negative-infinity?","finite?"],examples:["positive-infinity?(1.0)","positive-infinity?(1 / 0)","positive-infinity?(-1 / 0)"]}},"negative-infinity?":{evaluate:([e],t)=>(Y(e,t),e===Number.NEGATIVE_INFINITY),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"number"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x equals negative infinity, otherwise `false`.",seeAlso:["positive-infinity?","finite?"],examples:["negative-infinity?(1.0)","negative-infinity?(1 / 0)","negative-infinity?(-1 / 0)"]}},"true?":{evaluate:([e])=>!0===e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `true`, otherwise `false`.",seeAlso:["false?","boolean?","boolean"],examples:["true?(false)","true?(true)","true?(1)","true?(0)"]}},"false?":{evaluate:([e])=>!1===e,arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is `true`, otherwise `false`.",seeAlso:["true?","boolean?","boolean"],examples:["false?(false)","false?(true)","false?(1)","false?(0)"]}},"empty?":{evaluate:([e],t)=>null===e||(P(e,t),"string"==typeof e||Array.isArray(e)?0===e.length:0===Object.keys(e).length),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:["collection","string","null"]}},variants:[{argumentNames:["x"]}],description:"Returns `true` if $x is empty or `null`, otherwise `false`.",seeAlso:["not-empty?","collection.not-empty","null?","blank?","count"],examples:["empty?([])","empty?([1, 2, 3])","empty?({})","empty?({ a: 2 })",'empty?("")','empty?("Albert")',"empty?(null)"]}},"not-empty?":{evaluate:([e],t)=>null!==e&&(P(e,t),"string"==typeof e||Array.isArray(e)?e.length>0:Object.keys(e).length>0),arity:te(1),docs:{category:"predicate",returns:{type:"boolean"},args:{x:{type:["collection","string","null"]}},variants:[{argumentNames:["x"]}],description:"Returns `false` if $x is empty or `null`, otherwise `true`.",seeAlso:["empty?","collection.not-empty","null?"],examples:["not-empty?([])","not-empty?([1, 2, 3])","not-empty?({})","not-empty?({ a: 2 })",'not-empty?("")','not-empty?("Albert")',"not-empty?(null)"]}},"vector?":{evaluate:([e])=>je(e),arity:te(1),docs:{category:"predicate",description:"Checks if a value is a `vector`. A `vector` is an array of `numbers`.",seeAlso:["matrix?","grid?","array?"],returns:{type:"boolean"},args:{value:{type:"any",description:"The value to check."}},variants:[{argumentNames:["value"]}],examples:["vector?(1)","vector?([1, 2, 3])",'vector?([1, 2, "3"])']}},"matrix?":{evaluate:([e])=>Ve(e),arity:te(1),docs:{category:"predicate",description:"Checks if a value is a `matrix`. A `matrix` is an array of arrays of `numbers`.",seeAlso:["vector?","grid?","array?"],returns:{type:"boolean"},args:{value:{type:"any",description:"The value to check."}},variants:[{argumentNames:["value"]}],examples:["matrix?(1)","matrix?([1, 2, 3])","matrix?([[1, 2], [3, 4]])",'matrix?([[1, 2], [3, "4"]])',"matrix?([[1, 2], [3]])"]}},"grid?":{evaluate:([e])=>Me(e),arity:te(1),docs:{category:"predicate",description:"Checks if a `value` is a `grid`. A `grid` is an `array` of `arrays` where all inner `arrays` have the same length.",seeAlso:["vector?","matrix?","array?"],returns:{type:"boolean"},args:{value:{type:"any",description:"The value to check."}},variants:[{argumentNames:["value"]}],examples:['grid?("1")','grid?(["1", 2, 3])','grid?([["1", 2], [3, 4]])','grid?([["1", 2], [3, "4"]])','grid?([["1", 2], [3]])']}}},Ye={regexp:{evaluate:([e,t],r)=>{G(e,r);const n=e||"(?:)",a="string"==typeof t?t:"";try{new RegExp(n,a)}catch(e){throw new o(`Invalid regular expression: ${n} ${a}`,r)}return{[d]:!0,sourceCodeInfo:r,s:n,f:a}},arity:{min:1,max:2},docs:{category:"regular-expression",returns:{type:"regexp"},args:{pattern:{type:"string"},flags:{type:"string",description:"Optional flags for the regular expression. Possible values are the same as Javascript RegExp takes."}},variants:[{argumentNames:["pattern"]},{argumentNames:["pattern","flags"]}],description:"Creates a RegExp from $pattern and $flags.",examples:['regexp("^\\s*(.*)$")','#"^\\s*(.*)$"','regexp("albert", "ig")','#"albert"ig'],seeAlso:["-short-regexp","re-match","replace","replace-all","regexp?"],hideOperatorForm:!0}},"re-match":{evaluate:([e,t],r)=>{if(function(e,t){if(!M(e))throw b("RegularExpression",e,t)}(t,r),!W(e))return null;const n=new RegExp(t.s,t.f).exec(e);return n?[...n]:null},arity:te(2),docs:{category:"regular-expression",returns:{type:"any"},args:{a:{type:"regexp"},b:{type:"string"}},variants:[{argumentNames:["a","b"]}],description:"Matches $b against regular expression $a.\nIf $b is a string and matches the regular expression, a `re-match`-array is returned, otherwise `null` is returned.",seeAlso:["regexp","replace","replace-all","-short-regexp","regexp?"],examples:['re-match(" A string", regexp("^\\\\s*(.*)$"))','re-match(" A string", #"^\\s*(.*)$")','re-match("My name is Albert", #"albert"i)','re-match("My name is Ben", #"albert"i)','re-match(null, #"albert"i)','re-match(1, #"albert"i)','re-match({}, #"albert"i)']}},replace:{evaluate:([e,t,r],n)=>{G(e,n),O(t,n),G(r,n);const o=M(t)?new RegExp(t.s,`${t.f}`):t;return e.replace(o,r)},arity:te(3),docs:{category:"regular-expression",returns:{type:"string"},args:{a:{type:"string"},b:{type:["regexp","string"]},x:{type:"string"}},variants:[{argumentNames:["a","b","x"]}],description:"Returns a new string with first match of regular expression $b replaced by $x.",seeAlso:["replace-all","regexp","re-match","-short-regexp"],examples:['replace("Duck duck", "u", "i")','replace("Duck duck", #"u", "i")','replace("abcABC", regexp("a", "i"), "-")','replace("abcABC", regexp("a", "gi"), "-")','replace("abcABC", #"a"i, "-")','replace("abcABC", #"a"gi, "-")']}},"replace-all":{evaluate:([e,t,r],n)=>{G(e,n),O(t,n),G(r,n);const o=M(t)?new RegExp(t.s,`${t.f.includes("g")?t.f:`${t.f}g`}`):t;return e.replaceAll(o,r)},arity:te(3),docs:{category:"regular-expression",returns:{type:"string"},args:{a:{type:"string"},b:{type:["regexp","string"]},x:{type:"string"}},variants:[{argumentNames:["a","b","x"]}],description:"Returns a new string with all matches of regular expression $b replaced by $x.",seeAlso:["replace","regexp","re-match","-short-regexp"],examples:['replace-all("Duck duck", "u", "i")','replace-all("Duck duck", regexp("u"), "i")','replace-all("abcABC", regexp("a", "i"), "-")','replace-all("abcABC", regexp("a", "gi"), "-")','replace-all("abcABC", #"a"i, "-")','replace-all("abcABC", #"a"gi, "-")']}}},Xe=/^\s*$/,Qe={str:{evaluate:e=>e.reduce((e,t)=>e+(null==t?"":j(t)||Array.isArray(t)?JSON.stringify(t):`${t}`),""),arity:{},docs:{category:"string",returns:{type:"string"},args:{values:{type:"any",rest:!0}},variants:[{argumentNames:["values"]}],description:"Concatenats $values into one string. If `value` equals `null` empty string is returned.",seeAlso:["++","join","string.template","string.string-repeat","number"],examples:['str("A string", ", and another string", " ...and more")','str("Just one string")',"str()",'str(0, false, true, null, #"^kalle", [1, 2, 3], {a: "a"})'],hideOperatorForm:!0}},number:{evaluate:([e],t)=>{G(e,t);const r=Number(e);if(Number.isNaN(r))throw new o(`Could not convert '${e}' to a number.`,t);return r},arity:te(1),docs:{category:"string",returns:{type:"number"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Parses $s to a number.",seeAlso:["str","number?","integer?"],examples:['number("10")','number("010")','number("-1.01")']}},"lower-case":{evaluate:([e],t)=>(G(e,t),e.toLowerCase()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns $s converted to lower case.",seeAlso:["upper-case","string.capitalize"],examples:['lower-case("Albert")','lower-case("")']}},"upper-case":{evaluate:([e],t)=>(G(e,t),e.toUpperCase()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns $s converted to upper case.",seeAlso:["lower-case","string.capitalize"],examples:['upper-case("Albert")','upper-case("")']}},trim:{evaluate:([e],t)=>(G(e,t),e.trim()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a new string with leading and trailing whitespaces removed.",seeAlso:["string.trim-left","string.trim-right","blank?"],examples:['trim(" Albert ")','trim(" ")','trim("")']}},join:{evaluate:([e,t],r)=>(ye(e,r),e.forEach(e=>K(e,r)),G(t,r),e.join(t)),arity:te(2),docs:{category:"string",returns:{type:"string"},args:{a:{type:"array"},b:{type:"string"},arr:{type:"array"},delimiter:{type:"string"}},variants:[{argumentNames:["arr","delimiter"]}],description:"Returns a new string by concatenating all of the elements in $arr, separated by $delimiter.",seeAlso:["split","str","++","sequence.interpose"],examples:['map([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], str) join ", "','([0, 1, 2, 3, 4, 5, 6, 7, 8, 9] map str) join ", "','join(["Albert", 10], ", ")','join(["Albert", "Mojir"], " ")','join(map([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], str), ", ")']}},split:{evaluate:([e,t,r],n)=>{G(e,n),O(t,n),void 0!==r&&Y(r,n,{integer:!0,nonNegative:!0});const o="string"==typeof t?t:new RegExp(t.s,t.f);return e.split(o,r)},arity:{min:2,max:3},docs:{category:"string",returns:{type:"string",array:!0},args:{a:{type:"string"},b:{type:"string"},s:{type:"string"},delimiter:{type:"string"},limit:{type:"integer"}},variants:[{argumentNames:["s","delimiter"]},{argumentNames:["s","delimiter","limit"]}],description:"Divides $s into an array of substrings. The division is done by searching for `delimiter`. If `limit` as provided, at most `limit` number of substrings are returned.",seeAlso:["join","string.split-lines"],examples:['"Albert Mojir" split " "','split("Albert Mojir", " ")','split("abcdefghijklmnopqrstuvw", #"[aoueiy]")','split("0123456789", "")','split("0123456789", "", 5) map number']}},"blank?":{evaluate:([e],t)=>null===e||(G(e,t),Xe.test(e)),arity:te(1),docs:{category:"string",returns:{type:"boolean"},args:{s:{type:["string","null"]}},variants:[{argumentNames:["s"]}],description:"Returns true if $s is null or only contains whitespace characters.",seeAlso:["trim","empty?","string?"],examples:['blank?("")',"blank?(null)",'blank?("\n")','blank?(" ")','blank?(".")']}}},Ze={"|>":{evaluate:()=>{throw new Error("|> is implemented in Dvala")},arity:te(2),docs:{category:"functional",returns:{type:"any"},args:{a:{type:"any"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Takes a value $a and a function $b, and returns the result of applying $b to $a.",seeAlso:["apply","comp"],examples:["\n1 |> inc |> inc","range(10)\n |> map(_, -> $ ^ 2) // [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n |> filter(_, odd?) // [1, 9, 25, 49, 81]\n |> reduce(_, +, 0) // 165\n |> sqrt // 12.84523257866513\n |> round(_, 2)"]}},apply:{evaluate:()=>{throw new Error("apply is implemented in Dvala")},arity:{min:2},docs:{category:"functional",returns:{type:"any"},args:{a:{type:"function"},b:{type:"array"},fun:{type:"function"},args:{type:"array"}},variants:[{argumentNames:["fun","args"]}],description:"Call supplied function $fun with specified arguments $args.",seeAlso:["|>"],examples:["\napply(+, [1, 2, 3])","\napply(\n (x, y) -> sqrt(x ^ 2 + y ^ 2),\n [3, 4]\n)","\n(x, y) -> sqrt(x ^ 2 + y ^ 2) apply [3, 4]"]}},identity:{evaluate:([e])=>le(e),arity:te(1),docs:{category:"functional",returns:{type:"any"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns $x.",seeAlso:["constantly","functional.fnull"],examples:["identity(1)",'identity("Albert")',"identity({ a: 1 })","identity(null)"]}},comp:{evaluate:(e,t)=>(e.forEach(e=>F(e,t)),{[p]:!0,sourceCodeInfo:t,functionType:"Comp",params:e,arity:e.length>0?Z(e.at(-1)):{min:1,max:1}}),arity:{},docs:{category:"functional",returns:{type:"function"},args:{a:{type:"function"},b:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fns"]}],description:"Takes a variable number of functions and returns a function that is the composition of those.\n\n The returned function takes a variable number of arguments,\n applies the rightmost function to the args,\n the next function (right-to-left) to the result, etc.",seeAlso:["|>","functional.juxt","functional.complement"],examples:["\nlet negative-quotient = comp(-, /);\nnegative-quotient(9, 3)",'\nlet x = { bar: { foo: 42 } };\ncomp("foo", "bar")(x)']}},constantly:{evaluate:([e],t)=>({[p]:!0,sourceCodeInfo:t,functionType:"Constantly",value:le(e),arity:{}}),arity:te(1),docs:{category:"functional",returns:{type:"function"},args:{x:{type:"any"}},variants:[{argumentNames:["x"]}],description:"Returns a function that takes any number of arguments and always returns $x.",seeAlso:["identity","functional.fnull"],examples:["\nlet always-true = constantly(true);\nalways-true(9, 3)"]}}};function et(e){return fe(`\n ${e.title}\n\n ${e.description.replace(/`(.+?)`/g,"$1").replace(/\$(\w+)/g,"$1").replace(/\*\*\*(.+)\*\*\*/g,"$1").replace(/\*\*(.+)\*\*/g,"$1")}\n\n Signature:\n ${function(e){const{title:t,variants:r,args:n,returns:o}=e,a=!tt(e)&&e._isOperator,i=r.map(r=>{if(tt(e)){const e=r.argumentNames.length>0?`, ${r.argumentNames.map(e=>{let t="";return n[e].rest&&(t+="..."),t+=e,t}).join(", ")}`:"";return` perform(effect(${t})${e}) -> ${rt(o)}`}return`${` ${t}(${r.argumentNames.map(e=>{let t="";return n[e].rest&&(t+="..."),t+=e,t}).join(", ")})`} -> ${rt(o)}`}),s=a?["","Operator:",` a ${t} b -> ${rt(o)}`]:[];return[...i,...s]}(e).join("\n ")}\n\n Arguments:\n ${function(e){return Object.entries(e.args).map(([e,t])=>`${e}: ${rt(t)}`)}(e).join("\n ")}\n\n Examples:\n${e.examples.map(e=>fe(e,4)).join("\n\n")}`)}function tt(e){return"effect"in e}function rt(e){const t=e.type,r=(Array.isArray(t)?t:[t]).join(" | ");return e.array||e.rest?`Array<${r}>`:r}const nt={sum:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>e+t,0)),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to sum."}},variants:[{argumentNames:["vector"]}],description:"Returns the **sum** of all elements in the `vector`. Returns `0` for an empty vector.",seeAlso:["prod","mean","median","vector.moving-sum","vector.centered-moving-sum","vector.running-sum","vector.cumsum"],examples:["sum([1, 2, 3, 4, 5])","sum([1, -2, 3])","sum([])"]}},prod:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>e*t,1)),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to multiply."}},variants:[{argumentNames:["vector"]}],description:"Returns the **product** of all elements in the `vector`. Returns `1` for an empty vector.",seeAlso:["sum","mean","median","vector.moving-prod","vector.centered-moving-prod","vector.running-prod","vector.cumprod"],examples:["prod([1, 2, 3, 4, 5])","prod([1, -2, 3])","prod([])"]}},mean:{evaluate:([e],t)=>(Pe(e,t),e.reduce((e,t)=>e+t,0)/e.length),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to calculate the mean of."}},variants:[{argumentNames:["vector"]}],description:"Returns the arithmetic **mean** of all elements in the `vector`. Throws for an empty vector.",seeAlso:["median","sum","prod","vector.moving-mean","vector.centered-moving-mean","vector.running-mean","vector.geometric-mean","vector.harmonic-mean","vector.rms","vector.mode"],examples:["mean([1, 2, 3, 4, 5])","mean([1, -2, 3])"]}},median:{evaluate:([e],t)=>(Pe(e,t),function(e){const t=[...e].sort((e,t)=>e-t),r=Math.floor(t.length/2);return t.length%2==0?(t[r-1]+t[r])/2:t[r]}(e)),arity:te(1),docs:{category:"vector",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to calculate the median of."}},variants:[{argumentNames:["vector"]}],description:"Returns the **median** of all elements in the `vector`. For even-length vectors, returns the average of the two middle values. Throws for an empty vector.",seeAlso:["mean","sum","prod","vector.moving-median","vector.centered-moving-median","vector.running-median","vector.mode","vector.quartiles","vector.percentile","vector.iqr","vector.medad"],examples:["median([1, 2, 3, 4, 5])","median([1, 2, 3, 4])","median([3, 1, 4, 1, 5])"]}}},ot={...J,...ne,...we,...xe,...ke,...Le,...function(e,t){return{doc:{evaluate:([r],n)=>{if(x(e),V(r)){const e=`-effect-${r.name}`,n=t[e];return n?et(n):""}if(F(r,n),!q(r))return"";if("Builtin"===r.functionType){const t=e[r.name];return t?et(t):""}return"UserDefined"===r.functionType?r.docString:""},arity:te(1),docs:{category:"meta",returns:{type:"string"},args:{value:{type:["function","effect"]}},variants:[{argumentNames:["value"]}],description:"Returns documentation string of the $value. Works on functions and effects.",seeAlso:["arity","with-doc"],examples:["doc(+)","doc(effect(dvala.io.println))",'let add = (x, y) -> x + y with-doc "Adds two numbers.";\ndoc(add)']}},"with-doc":{evaluate:([e,t],r)=>{if(F(e,r),G(t,r),!q(e)||"UserDefined"!==e.functionType)throw new Error("with-doc can only be used with user-defined functions");return{...e,[p]:!0,docString:t}},arity:te(2),docs:{category:"meta",returns:{type:"function"},args:{a:{type:"function"},b:{type:"string"}},variants:[{argumentNames:["a","b"]}],description:"Returns a new function with the documentation string $b attached. The original function is not modified.",seeAlso:["doc"],examples:['((x, y) -> x + y) with-doc "Adds two numbers."','let add = (x, y) -> x + y;\nadd with-doc "Adds x and y."']}},arity:{evaluate:([e],r)=>{if(V(e)){const r=`-effect-${e.name}`,n=t[r];if(!n)return{};const o=n.variants.map(e=>e.argumentNames.length);return{min:Math.min(...o),max:Math.max(...o)}}return F(e,r),q(e)?e.arity:te(1)},arity:te(1),docs:{category:"meta",returns:{type:"object"},args:{value:{type:["function","effect"]}},variants:[{argumentNames:["value"]}],description:"Returns arity of the $value. The arity is an object with the properties: `min` and `max`. If the function has fixed arity, `min` and `max` are equal to the number of required parameters. If no restrictions apply, empty object is returned. Also works on effects.",seeAlso:["doc"],examples:["arity(+)","arity(defined?)","arity(effect(dvala.random.int))","\nlet add = (x, y = 0) -> do\n x + y;\nend;\n\narity(add)","\nlet foo = (k, ...x) -> do\n k + x;\nend;\n arity(foo)"]}}}}({},{}),...Ke,...Je,...He,...Ye,...Qe,...Ze,...nt};Object.entries(ot).forEach(([e,t])=>{t.name=e});const at={...ot},it={},st=[];Object.entries(at).forEach(([e,t],r)=>{it[e]=r,st.push(t)});const lt={arity:{},docs:{category:"special-expression",returns:{type:"any"},args:{a:{type:"any"},b:{type:"any"},c:{type:"any",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"\nComputes logical `and`. Evaluation of expressions starts from left.\nAs soon as an `expression` evaluates to a falsy value, the result is returned.\n\nIf all expressions evaluate to truthy values, the value of the last expression is returned.",examples:["true && 1","&&(1, 1)",'&&(3 > 2, "string")','&&(3 < 2, "string")',"&&(true, true, true, true)","&&(true, true, 0, true)"]},evaluateAsNormalExpression:(e,t)=>{let r=!0;for(const n of e)if(r=$(n,t),!r)break;return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},ct={arity:{},docs:{category:"special-expression",customVariants:["cond cond-branch cond-branch ... end"],details:[["cond-branch","case test then body","A branch of the cond expression."],["test","expression","The condition to test."],["body","expressions","The expressions to evaluate if the test is truthy."]],description:"Used for branching. `cond-branches` are tested sequentially from the top. If no branch is tested truthy, `null` is returned.",examples:['\ncond\n case false then "FALSE"\n case true then "TRUE"\nend','\ncond\n case false then "FALSE"\n case null then "null"\nend ?? "TRUE"','\ncond\n case false then "FALSE"\n case null then "null"\nend ?? "TRUE"']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1].flat(),t,n,o)},ut=11,mt=12,pt=13,dt=14,ht=15,gt=16;function ft(e,t){return e instanceof Promise?e.then(t):t(e)}async function yt(e,t,r,n,o){t.push(await e);for(let e=o+1;e<r.length;e++)t.push(await n(r[e],e));return t}function vt(e,t,r){let n=r;for(let r=0;r<e.length;r++){const o=t(n,e[r],r);if(o instanceof Promise)return bt(o,e,t,r);n=o}return n}async function bt(e,t,r,n){let o=await e;for(let e=n+1;e<t.length;e++)o=await r(o,t[e],e);return o}function wt(e,t){for(let r=0;r<e.length;r++){const n=t(e[r],r);if(n instanceof Promise)return xt(n,e,t,r)}}async function xt(e,t,r,n){await e;for(let e=n+1;e<t.length;e++)await r(t[e],e)}function kt(e,t){try{const r=e();return r instanceof Promise?r.catch(t):r}catch(e){return t(e)}}function qt(e,t){if(e[0]===pt)Object.values(e[1][0]).forEach(e=>{e[1][1]&&t(e[1][1]),qt(e,t)});else if(e[0]===dt)for(let r=0;r<e[1][0].length;r+=1){const n=e[1][0][r]??null;null!==n&&(n[1][1]&&t(n[1][1]),qt(n,t))}}function At(e,t,r){const n=e[2],o={};return ft(Nt(e,t,r,n,o),()=>o)}function Nt(e,t,r,n,a){if(e[0]===pt){!function(e,t){if(!k(e))throw new o(`Expected UnknownRecord, got ${y(e)}.`,v(e,t))}(t,n);const i=new Set;let s;return ft(wt(Object.entries(e[1][0]),([e,o])=>{if(o[0]===mt)return void(s=o);i.add(e);const l=t[e];return ft(void 0!==l?l:o[1][1]?r(o[1][1]):null,e=>{const t=e??null;return E(t,n),Nt(o,t,r,n,a)})}),()=>{if(s){const e=Object.entries(t).filter(([e])=>!i.has(e)).reduce((e,[t,r])=>(e[t]=$(r),e),{});a[s[1][0]]=e}})}if(e[0]===dt){let o=null;ye(t,n);const i=[];for(let t=0;t<e[1][0].length;t+=1){const r=e[1][0][t]??null;if(null!==r){if(r[0]===mt){o=t;break}i.push({element:r,index:t})}}return ft(wt(i,({element:e,index:o})=>{const i=t[o];return ft(void 0!==i?i:e[1][1]?r(e[1][1]):null,t=>{const o=t??null;return E(o,n),Nt(e,o,r,n,a)})}),()=>{if(null!==o){const r=t.slice(o),n=e[1][0][o];a[n[1][0]]=r}})}e[0]===mt?a[e[1][0]]=$(t):a[e[1][0][1]]=$(t)}function $t(e){const t={};return Et(e,t),t}function Et(e,t){if(null!==e)if(e[0]===dt)for(const r of e[1][0])Et(r,t);else if(e[0]===pt)for(const r of Object.values(e[1][0]))Et(r,t);else if(e[0]===mt){if(t[e[1][0]])throw new o(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0]]=!0}else if(e[0]===ut){if(t[e[1][0][1]])throw new o(`Duplicate binding name: ${e[1][0]}`,e[2]);t[e[1][0][1]]=!0}}function Tt(e,t,r){const n={};return ft(St(e,t,r,n),e=>e?n:null)}function St(e,t,r,n){if(e[0]===gt)return!0;if(e[0]===ht){const n=e[1][0];return ft(r(n),e=>ie(t,e))}if(e[0]===ut){const o=e[1][0],a=e[1][1];if(null==t){if(a)return ft(r(a),e=>(n[o[1]]=$(e),!0));n[o[1]]=t??null}else n[o[1]]=$(t);return!0}if(e[0]===pt){if(!k(t))return!1;const o=new Set;let a;const i=Object.entries(e[1][0]);let s=!0;for(const[e,l]of i)s=ft(s,i=>{if(!i)return!1;if(l[0]===mt)return a=l,!0;o.add(e);const s=t[e];if(void 0===s&&l[0]===ht)return ft(r(l[1][0]),e=>ie(void 0,e));return ft(void 0!==s?s:l[1]&&l[1][1]?r(l[1][1]):null,e=>St(l,e??null,r,n))});return ft(s,e=>{if(!e)return!1;if(a){const e=Object.entries(t).filter(([e])=>!o.has(e)).reduce((e,[t,r])=>(e[t]=$(r),e),{});n[a[1][0]]=e}return!0})}{const o=e;if(!Array.isArray(t))return!1;const a=o[1][0];let i=null;for(let e=0;e<a.length;e+=1){const t=a[e];if(null!==t&&t[0]===mt){i=e;break}}if(null===i&&t.length!==a.length)return!1;if(null!==i&&t.length<i)return!1;let s=!0;for(let e=0;e<a.length;e+=1){const o=a[e];if(null===o)continue;if(o[0]===mt){n[o[1][0]]=t.slice(e);break}const i=o;s=ft(s,o=>!!o&&St(i,$(t[e]),r,n))}return s}}const zt={arity:{},docs:{category:"special-expression",customVariants:["match value match-branch match-branch ... end"],details:[["value","any","The value to match against patterns."],["match-branch","case pattern [when guard] then body","A branch of the match expression."],["pattern","pattern","A pattern to match: literal, variable, array destructuring, object destructuring, or wildcard (_)."],["guard","expression","An optional guard expression that must be truthy for the match to succeed."],["body","expressions","The expressions to evaluate if the pattern matches."]],description:"Pattern matching expression. Matches `value` against each `pattern` sequentially. If a pattern matches (and the optional `when` guard is truthy), the corresponding `body` is evaluated and its result returned. Bound variables from the pattern are available in the guard and body. If no pattern matches, `null` is returned.",examples:['\nmatch 1\n case 1 then "One"\n case 2 then "Two"\nend','\nmatch [1, 2, 3]\n case [x] then "one element"\n case [x, y] then "two elements"\n case [x, ...xs] then "first: " ++ str(x) ++ " rest: " ++ str(xs)\nend','\nmatch { type: "click", x: 10, y: 20 }\n case { type: "click", x, y } then "Click at " ++ str(x) ++ ", " ++ str(y)\n case { type: "keydown", key } then "Key: " ++ key\n case _ then "unknown event"\nend','\nmatch { role: "admin", name: "Alice" }\n case { role: "admin", name } then "Admin: " ++ name\n case { role, name } when role == "user" then "User: " ++ name\n case _ then "Unknown role"\nend']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=new Set;r([e[1][1]],t,n,o).forEach(e=>a.add(e));for(const[i,s,l]of e[1][2]){const e={};Object.assign(e,$t(i));const c=t.create(e);l&&r([l],c,n,o).forEach(e=>a.add(e)),r([s],c,n,o).forEach(e=>a.add(e))}return a}},jt={category:"special-expression",returns:{type:"boolean"},args:{symbol:{type:"any"}},variants:[{argumentNames:["symbol"]}],description:"Returns `true` if `symbol` is defined, `false` otherwise.\n\nBuilt-in symbols are always considered defined. For user-defined symbols, checks if the symbol exists in the current scope.",examples:["let x = 42; defined?(x)","defined?(x)","defined?(+)"]},Ct={arity:te(1),docs:jt,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r([e[1][1]],t,n,o)},It={arity:{},docs:{category:"special-expression",customVariants:["do body end","do body with case effect(name) then handler end"],details:[["body","expressions","The expressions to evaluate."],["effect(name)","expression","An expression evaluating to an effect value."],["handler","expression","A function (args) -> result that handles the effect. Its return value resumes the perform call."]],description:"Evaluates `body`. Resulting value is the value of the last expression. Effect handlers can be installed via `with` to intercept `perform` calls.",examples:["\ndo\n let a = 1 + 2 + 3 + 4;\n let b = -> $ * ( $ + 1 );\n b(a)\nend",'\ndo\n perform(effect(dvala.io.println), "hello")\nwith\n case effect(dvala.io.println) then ([msg]) -> null\nend']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=r(e[1][1],t.create({}),n,o),i=e[1][2];if(!i||0===i.length)return a;let s=new Set;for(const[e,a]of i){s=me(s,r([e],t,n,o),r([a],t,n,o))}return me(a,s)}},Rt={arity:{},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>function(e,t,r,n,o){const a=new Set,i={self:{value:null}};e[0].forEach(e=>{Object.assign(i,$t(e)),qt(e,e=>{pe(a,r([e],t,n,o))})});const s=t.create(i),l=r(e[1],s,n,o);return pe(a,l),a}(e[1][1],t,r,n,o)};const Pt={arity:{min:2,max:3},docs:{category:"special-expression",customVariants:["if test then true-expr else false-expr","if test then true-expr"],details:[["test","expression","The condition to test."],["true-expr","expression","The expression to evaluate if the test is truthy."],["false-expr","expression","The expression to evaluate if the test is falsy."]],description:"Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is truthy. If $test is falsy `false-expr` is executed, if no `false-expr` exists, `null` is returned.",examples:['\nif true then\n "TRUE"\nelse\n "FALSE"\nend','if false then "TRUE" else "FALSE" end','if true then "TRUE" end','if false then "TRUE" end']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1].filter(e=>!!e),t,n,o)},Mt={arity:{},docs:{category:"special-expression",customVariants:["unless test then true-expr else false-expr end","unless test true-expr end"],details:[["test","expression","The condition to test."],["true-expr","expression","The expressions to evaluate if the test is falsy."],["false-expr","expression","The expressions to evaluate if the test is truthy."]],description:"Either `true-expr` or `false-expr` branch is taken. `true-expr` is selected when $test is falsy. If $test is truthy `false-expr` is executed, if no `false-expr` exists, `null` is returned.",examples:['\nunless true then\n "TRUE"\nelse\n "FALSE"\nend','unless false then "TRUE" else "FALSE" end','unless true then "TRUE" end','unless false then "TRUE" end']},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1].filter(e=>!!e),t,n,o)},Ot={category:"special-expression",customVariants:["let s = value;"],details:[["s","symbol","The name of the variable to bind."],["value","any","The value to bind to the variable."]],description:"\n Binds local variables s to `value`. `value` can be any expression. The scope of the variables is the body of the let expression.",examples:["\nlet a = 1 + 2 + 3 + 4;\nlet b = -> $ * ( $ + 1 );\nb(a)"]},Vt={arity:te(0),docs:Ot,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=e[1][1],i=a[1][0],s=a[1][1],l=r([s],t,n,o);return qt(i,e=>{pe(l,r([e],t,n,o))}),t.addValues($t(i),i[2]),l}},Dt={arity:{},docs:{category:"special-expression",customVariants:["loop (bindings) -> body"],details:[["bindings","binding pairs","Comma-separated bindings with initial values, e.g. `n = 10, acc = 0`."],["body","expression","The expression to evaluate repeatedly. Use `recur` to loop back with new values."]],description:"Creates a loop with initial bindings. Use `recur` inside the body to jump back to the loop head with new binding values.\n\nIf `recur` is not called, the loop terminates and returns the value of the body expression.",examples:["loop (n = 10, acc = 0) -> do\n if n == 0 then\n acc\n else\n recur(n - 1, acc + n)\n end\nend","loop (n = 5, acc = 1) -> do\n if n <= 1 then\n acc\n else\n recur(n - 1, acc * n)\n end\nend"]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const a=e[1][1],i=a.reduce((e,t)=>{const r=$t(t[1][0]);return Object.keys(r).forEach(t=>{e[t]={value:!0}}),e},{});return me(r(a.map(e=>e[1][1]),t,n,o),r([e[1][2]],t.create(i),n,o))}};function Ut(e,t,r,n,o){const a=new Set,i={},[,s,l]=e[1];return s.forEach(e=>{const[s,l,c,u]=e,[m,p]=s[1];r([p],t.create(i),n,o).forEach(e=>a.add(e)),Object.assign(i,$t(m)),l&&l.forEach(e=>{const[s,l]=e[1];r([l],t.create(i),n,o).forEach(e=>a.add(e)),Object.assign(i,$t(s))}),c&&r([c],t.create(i),n,o).forEach(e=>a.add(e)),u&&r([u],t.create(i),n,o).forEach(e=>a.add(e))}),r([l],t.create(i),n,o).forEach(e=>a.add(e)),a}const Ft={category:"special-expression",customVariants:["for (...binding) -> body"],details:[["binding","loop-var in collection [...let-binding] [where whereExpr] [while whileExp]","A for loop binding"],["loop-var","symbol","The name of the loop variable."],["collection","any","The collection to iterate over."],["let-binding","let binding","A let binding to create a local variable."],["whereExpr","expression","An expression that must evaluate to truthy for the loop body to be executed."],["whileExp","expression","An expression that must evaluate to truthy for the loop to continue."],["body","expressions","The expressions to evaluate for each iteration of the loop."]],returns:{type:"any",array:!0},description:"Iterates over `bindings`, evaluates `body` for each `binding` and returns an `array` of results.",examples:["\nfor (i in [1, 2, 3]) -> i * 2\n ","\nfor (\n i in range(10) let ii = i ^ 2 while ii < 40 when ii % 3 == 0,\n j in range(10) when j % 2 == 1\n) -> ii + j\n "]},Wt={arity:te(1),docs:Ft,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>Ut(e,t,r,n,o)},Gt={category:"special-expression",customVariants:["doseq (...binding) -> body"],details:[["binding","loop-var in collection [...let-binding] [where whereExpr] [while whileExp]","A doseq loop binding"],["loop-var","symbol","The name of the loop variable."],["collection","any","The collection to iterate over."],["let-binding","let binding","A let binding to create a local variable."],["whereExpr","expression","An expression that must evaluate to truthy for the loop body to be executed."],["whileExp","expression","An expression that must evaluate to truthy for the loop to continue."],["body","expressions","The expressions to evaluate for each iteration of the loop."]],returns:{type:"null"},description:"Iterates over `bindings`, evaluates `body` for each `binding` and returns `null`. This is useful for side effects.",examples:["\ndoseq (i in [1, 2, 3]) -> perform(effect(dvala.io.println), i * 2)\n "]},Bt={arity:te(1),docs:Gt,getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>Ut(e,t,r,n,o)},Lt={arity:{},docs:{category:"special-expression",returns:{type:"boolean"},args:{a:{type:"any"},b:{type:"any"},c:{type:"any",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"\n Computes logical `or`. Evaluation of expressions evaluation starts from left.\n As soon as a `expression` evaluates to a truthy value, the result is returned.\n\n If all expressions evaluate to falsy values, the value of the last expression is returned.",examples:["false || 1","||(1, 1)",'||(3 > 2, "string")','||(3 < 2, "string")',"||(false, false, false, true)","||(1, 2, 3, 4)"]},evaluateAsNormalExpression:(e,t)=>{let r=!1;for(const n of e)if(r=$(n,t),r)break;return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},_t={arity:{min:1},docs:{category:"special-expression",returns:{type:"any"},args:{a:{type:"any"},b:{type:"any"},c:{type:"any",rest:!0}},variants:[{argumentNames:["a"]},{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Nullish coalescing operator. Returns the first non-`null` value.\n\nEvaluation is short-circuited — as soon as a non-`null` value is found, the remaining expressions are not evaluated.\n\nIf all values are `null`, returns `null`.\n\nAlso works with undefined symbols — if a symbol is undefined, it is treated as `null`.",examples:["1 ?? 2","null ?? 2","??(null)",'??(null, "default")','??(1, "default")','false ?? "default"',"??(null, null, 3)"]},evaluateAsNormalExpression:(e,t)=>{for(const r of e){const e=$(r,t);if(null!==e)return e}return null},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Kt={arity:{},docs:{category:"special-expression",customVariants:["recur(...recur-args)"],description:"Recursevly calls enclosing function or loop with its evaluated `recur-args`.",examples:["\nlet foo = (n) -> do\n if zero?(n) then\n 0\n else\n n + recur(n - 1)\n end\nend;\nfoo(3)","\n((n) -> do\n if zero?(n) then\n 0\n else\n n + recur(n - 1)\n end\nend)(3)","\nloop (n = 3, acc = 0) -> do\n if zero?(n) then\n acc\n else\n recur(n - 1, acc + n)\n end\nend"]},evaluateAsNormalExpression:e=>{throw new n(e)},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Jt={arity:{},docs:{category:"special-expression",returns:{type:"any",array:!0},args:{values:{type:"any",rest:!0}},variants:[{argumentNames:["values"]}],description:"Makes new array from $values.",examples:["array(1, 2, 3)","array(array(null, false, true))","[]","[1, 2, 3]","[1, 2, ...[3, 4, 5], 6]","[[null, false, true]]","[1, 2, 3][1]"],hideOperatorForm:!0},evaluateAsNormalExpression:(e,t)=>{const r=[];for(const n of e)r.push($(n,t));return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Ht={arity:{},docs:{category:"special-expression",customVariants:["effect(name)"],details:[["name","dotted identifier","The effect name, e.g. `llm.complete` or `dvala.io.println`."]],description:"Returns the unique effect reference for the given name. Calling `effect` with the same name always returns the same reference. Effect references are first-class values that can be stored, passed, and compared with `==`.",examples:["effect(dvala.io.println)","==(effect(llm.complete), effect(llm.complete))"],seeAlso:["effect?"]},getUndefinedSymbols:()=>new Set},Yt={arity:{},docs:{category:"special-expression",returns:{type:"object"},args:{kvps:{type:"any",rest:!0,description:"key - value pairs, where key is a string"}},variants:[{argumentNames:["kvps"]}],description:"Constructs a new object. Object members are created from the $kvps key-value pairs. Requires an even number of arguments.",examples:["object()",'\nlet default = {\n type: "Person",\n name: "John Doe",\n age: 42\n};\n\n{\n ...default,\n name: "Lisa"\n}','object("x", 10, "y", true, "z", "A string")',"{}","{ a: 1, b: 2 }"],hideOperatorForm:!0},evaluateAsNormalExpression:(e,t)=>{const r={};for(let n=0;n<e.length;n+=2){const o=e[n],a=e[n+1];G(o,t),r[o]=a??null}return r},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>r(e[1][1],t,n,o)},Xt={arity:te(1),docs:{category:"special-expression",description:"Imports all functions from a module as an object. Use destructuring to pick specific functions.",customVariants:["import(module-name)"],returns:{type:"object"},examples:["let v = import(vector); v.stdev([1, 2, 3, 4])","let { linspace } = import(vector); linspace(0, 10, 5)","let g = import(grid); g.row([[1, 2], [3, 4]], 0)"]},getUndefinedSymbols:()=>new Set},Qt={arity:{min:1},docs:{category:"special-expression",customVariants:["parallel(expr1, expr2, ...)"],details:[["expr1, expr2, ...","expressions","Expressions to evaluate concurrently. Typically `perform(...)` calls."]],description:"Evaluates all branch expressions concurrently and returns an array of results in order. Each branch runs as an independent trampoline invocation. If any branch suspends, the entire `parallel` suspends with a composite blob. On resume, branches are resumed one at a time. Only available in async mode (`run()`). Requires at least one branch.",examples:[]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>me(...e[1][1].map(e=>r([e],t,n,o)))},Zt={arity:{min:1},docs:{category:"special-expression",customVariants:["perform(eff)","perform(eff, arg1)","perform(eff, arg1, arg2, ...)"],details:[["eff","expression","An expression evaluating to an effect value (from `effect(name)`)."],["arg1, arg2, ...","expressions","Arguments passed to the effect handler."]],description:"Invokes an effect. The nearest enclosing `do/with` handler matching the effect intercepts the call. The handler receives the arguments as an array and its return value becomes the result of `perform`. If no local handler matches, the effect is dispatched to the host.",examples:['\ndo\n perform(effect(dvala.io.println), "hello")\nwith\n case effect(dvala.io.println) then ([msg]) -> msg\nend\n'],seeAlso:["effect?"]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>{const[,a,i]=e[1];return me(r([a],t,n,o),r(i,t,n,o))}},er={arity:{min:1},docs:{category:"special-expression",customVariants:["race(expr1, expr2, ...)"],details:[["expr1, expr2, ...","expressions","Expressions to race concurrently. Typically `perform(...)` calls."]],description:"Races all branch expressions concurrently. The first branch to complete wins — its value becomes the result. Losing branches are cancelled via AbortSignal. Errored branches are silently dropped. If all branches error, throws an aggregate error. If no branch completes but some suspend, the race suspends. On resume, the host provides the winner value directly. Only available in async mode (`run()`). Requires at least one branch.",examples:[]},getUndefinedSymbols:(e,t,{getUndefinedSymbols:r,builtin:n,evaluateNode:o})=>me(...e[1][1].map(e=>r([e],t,n,o)))},tr={"??":0,"&&":1,"||":2,array:3,cond:4,"defined?":5,block:6,doseq:7,"0_lambda":8,for:9,if:10,let:11,loop:12,object:13,recur:14,match:15,unless:16,import:17,effect:18,perform:19,parallel:20,race:21},rr={normalExpressions:at,specialExpressions:[_t,lt,Lt,Jt,ct,Ct,It,Bt,Rt,Wt,Pt,Vt,Dt,Yt,Kt,zt,Mt,Xt,Ht,Zt,Qt,er],allNormalExpressions:st},nr=Object.keys(at),or=Object.keys(tr),ar=["^","*","/","%","+","-","<<",">>",">>>","++","<","<=","≤",">",">=","≥","==","!=","!=","&","xor","|","&&","||","??","|>"],ir=[...ar,"?",":","->","...",".",",","=",":",";"],sr=new Set(["comment","cond","defined?","block","doseq","if","let","loop","recur","unless","while"]);function lr(e){return!sr.has(e)}const cr=new Set(ar);function ur(e){return cr.has(e)}const mr=new Set(ir);function pr(e){return mr.has(e)}const dr=(1+Math.sqrt(5))/2,hr={E:Math.E,"-E":-Math.E,"ε":Math.E,"-ε":-Math.E,PI:Math.PI,"-PI":-Math.PI,"π":Math.PI,"-π":-Math.PI,PHI:dr,"-PHI":-dr,"φ":dr,"-φ":-dr,POSITIVE_INFINITY:Number.POSITIVE_INFINITY,"∞":Number.POSITIVE_INFINITY,NEGATIVE_INFINITY:Number.NEGATIVE_INFINITY,"-∞":Number.NEGATIVE_INFINITY,MAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,MIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,MAX_VALUE:Number.MAX_VALUE,MIN_VALUE:Number.MIN_VALUE,NaN:Number.NaN},gr={true:!0,false:!1,null:null,do:null,else:null,case:null,each:null,in:null,when:null,while:null,function:null,as:null,then:null,end:null,with:null,_:null,...hr};const fr=["(",")","[","]","{","}","'",'"',"`",",",".",";"," ","\n","\r","\t"],yr=["0","1","2","3","4","5","6","7","8","9",...fr],vr=new Set(fr),br=new Set(yr),wr=/\s/,xr=[0],kr=(e,t)=>{if('"'!==e[t])return xr;let r='"',n=1,o=e[t+n],a=!1;for(;o&&('"'!==o||a);)n+=1,a?(a=!1,r+=o):("\\"===o&&(a=!0),r+=o),o=e[t+n];return o?(r+='"',[n+1,["string",r]]):[n,["Error",r,void 0,`Unclosed string at position ${t}`]]};function qr(e,t,r,n){return t===r.slice(n,n+t.length)?[t.length,[e,t]]:xr}const Ar=/\d/,Nr=/[0-7]/,$r=/[0-9a-f]/i,Er=/[01]/,Tr=/[\s)\]}(,;]/,Sr=(e,t)=>{let r=e[t];if("'"===r){let n=1,o=e[t+n],a=!1;for(;"'"!==o||a;){if(void 0===o)return[n,["Error",r,void 0,`Unclosed quoted symbol at position ${t}`]];n+=1,a?(a=!1,r+=o):("\\"===o&&(a=!0),r+=o),o=e[t+n]}return r+="'",[n+1,["Symbol",r]]}if(!br.has(r)){const n=t;let o=e[t+=1];for(;o&&!vr.has(o);)r+=o,o=e[t+=1];return r.endsWith(":")?[t-n-1,["Symbol",r.slice(0,-1)]]:[t-n,["Symbol",r]]}return xr},zr=[(e,t)=>{let r=e[t];if(!r||!wr.test(r))return xr;let n=r;for(r=e[t+=1];r&&wr.test(r);)n+=r,r=e[t+=1];return[n.length,["Whitespace",n]]},(e,t)=>{if("/"===e[t]&&"*"===e[t+1]){let r=2,n="/*";for(;("*"!==e[t+r]||"/"!==e[t+r+1])&&t+r+1<e.length;)n+=e[t+r],r+=1;return t+r+1>=e.length?[r,["Error",n,void 0,`Unclosed multi-line comment at position ${t}`]]:(n+="*/",r+=2,[r,["MultiLineComment",n]])}return xr},(e,t)=>{if("/"===e[t]&&"/"===e[t+1]){let r=2,n="//";for(;"\n"!==e[t+r]&&t+r<e.length;)n+=e[t+r],r+=1;return[r,["SingleLineComment",n]]}return xr},(e,t)=>{const r=Sr(e,t);if(0===r[0]||!r[1])return xr;let n=r[1][1];n=n.startsWith("'")?n.slice(1,n.length-1):n;return void 0===gr[n]?xr:[r[0],["ReservedSymbol",n]]},(e,t)=>qr("LParen","(",e,t),(e,t)=>qr("RParen",")",e,t),(e,t)=>qr("LBracket","[",e,t),(e,t)=>qr("RBracket","]",e,t),(e,t)=>qr("LBrace","{",e,t),(e,t)=>qr("RBrace","}",e,t),kr,(e,t)=>{if("#"!==e[t])return xr;const[r,n]=kr(e,t+1);if(!n)return xr;if("Error"===n[0]){return[r+1,["Error",`#${n[1]}`,void 0,`Unclosed regexp at position ${t}`]]}t+=r+1;let o=r+1,a="";for(;"g"===e[t]||"i"===e[t];)if(a+=e[t],o+=1,t+=1,a.includes(e[t]))return[o,["Error",`#${n[1]}${a}`,void 0,`Duplicated regexp option "${e[t]}"`]];return[o,["RegexpShorthand",`#${n[1]}${a}`]]},(e,t)=>{if("0"!==e[t])return xr;const r=e[t+1],n="b"===r||"B"===r?"binary":"o"===r||"O"===r?"octal":"x"===r||"X"===r?"hex":null;if(null===n)return xr;let o;for(o=t+2;o<e.length;o+=1){const t=e[o];if("binary"===n&&!Er.test(t))break;if("octal"===n&&!Nr.test(t))break;if("hex"===n&&!$r.test(t))break}const a=o-t;if(a<=2)return xr;const i=e[o];return i&&!Tr.test(i)?xr:[a,["BasePrefixedNumber",e.substring(t,o)]]},(e,t)=>{let r;const n="-"===e[t],o="+"===e[t],a=n||o?t+1:t;let i=!1,s=!1;for(r=a;r<e.length;r+=1){const n=e[r];if("_"===n){if(!Ar.test(e[r-1])||!Ar.test(e[r+1]))return r===a?xr:[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]]}else if("."===n){if(r===a)return xr;if(i||s)return[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]];i=!0}else if("e"===n||"E"===n){if(r===a)return xr;if(s)return[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]];if("."===e[r-1]||"+"===e[r-1]||"-"===e[r-1])return[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]];"+"!==e[r+1]&&"-"!==e[r+1]||(r+=1),s=!0}else if(!Ar.test(n))break}if((n||o)&&r===a)return xr;const l=r-t;if(0===l)return xr;const c=e[r];return c&&":"!==c&&!Tr.test(c)?[r-t+1,["Error",e.substring(t,r+1),void 0,`Invalid number format at position ${r+1}`]]:[l,["Number",e.substring(t,r)]]},(e,t)=>{const r=e.slice(t,t+3);if(t+2<e.length&&pr(r))return[3,["Operator",r]];const n=e.slice(t,t+2);if(t+1<e.length&&pr(n))return[2,["Operator",n]];const o=e[t]??"";return pr(o)?[1,["Operator",o]]:xr},Sr];function jr(e,t,r){let n=0;const o={tokens:[],filePath:r,hasDebugData:t};for(;n<e.length;){const a=t?Cr(e,n,r):void 0,i=Ir(e,n),[s,l]=i;n+=s,l&&(a&&(l[2]=a),o.tokens.push(l))}return o}function Cr(e,t,r){const n=e.substring(0,t+1).split(/\r\n|\r|\n/),o=n[n.length-1],a=function(e,t){return e.split(/\r\n|\r|\n/)[t]}(e,n.length-1);return{code:a,position:{line:n.length,column:o.length},filePath:r}}function Ir(e,t){const r=t;if(0===t){const[n,o]=((e,t)=>{if("#"===e[t]&&"!"===e[t+1]){let r=2,n="#!";for(;"\n"!==e[t+r]&&t+r<e.length;)n+=e[t+r],r+=1;return[r,["SingleLineComment",n]]}return xr})(e,t);if(t+=n,n>0)return[t-r,o]}for(const n of zr){const[o,a]=n(e,t);if(t+=o,0!==o)return[t-r,a]}return[1,["Error",e[r],void 0,"Unrecognized character"]]}const Rr=new Set([...nr,...or,...Object.keys(gr)]);class Pr{originalProgram;originalPosition;prefixProgram="";suffixProgram="";searchString="";suggestions=[];suggestionIndex=null;constructor(e,t,r={}){this.originalProgram=e,this.originalPosition=t;const n=jr(this.originalProgram.slice(0,this.originalPosition),!1,void 0).tokens.at(-1);n&&"Error"!==n[0]&&(this.searchString=n[1],this.prefixProgram=this.originalProgram.slice(0,this.originalPosition-this.searchString.length),this.suffixProgram=this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.originalProgram.slice(this.prefixProgram.length+this.searchString.length),this.suggestions=this.generateSuggestions(r))}getNextSuggestion(){return this.getAutoCompleteSuggestionResult(this.getNextSuggestionSymbol())}getPreviousSuggestion(){return this.getAutoCompleteSuggestionResult(this.getPreviousSuggestionSymbol())}getAutoCompleteSuggestionResult(e){return null===e?null:{program:this.prefixProgram+e+this.suffixProgram,position:this.prefixProgram.length+e.length}}getNextSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=0:(this.suggestionIndex+=1,this.suggestionIndex>=this.suggestions.length&&(this.suggestionIndex=0)),this.suggestions[this.suggestionIndex])}getPreviousSuggestionSymbol(){return 0===this.suggestions.length?null:(null===this.suggestionIndex?this.suggestionIndex=this.suggestions.length-1:(this.suggestionIndex-=1,this.suggestionIndex<0&&(this.suggestionIndex=this.suggestions.length-1)),this.suggestions[this.suggestionIndex])}getSuggestions(){return[...this.suggestions]}getSearchString(){return this.searchString}generateSuggestions(e){const t=new Set(["0_defn","0_lambda"]),r=this.generateWithPredicate(e,e=>!t.has(e)&&e.startsWith(this.searchString));r.forEach(e=>t.add(e));const n=this.generateWithPredicate(e,e=>!t.has(e)&&e.toLowerCase().startsWith(this.searchString.toLowerCase()));n.forEach(e=>t.add(e));const o=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString));o.forEach(e=>t.add(e));const a=this.generateWithPredicate(e,e=>!t.has(e)&&e.includes(this.searchString.toLowerCase()));return a.forEach(e=>t.add(e)),[...r,...n,...o,...a]}generateWithPredicate(e,t){const r=new Set;return Rr.forEach(e=>{t(e)&&r.add(e)}),Object.keys(e.bindings??{}).filter(t).forEach(e=>r.add(e)),[...r].sort((e,t)=>e.localeCompare(t))}}function Mr(e){return l.UserDefinedSymbol===e[0]}function Or(e,t){return function(e,t){if(!Mr(e))throw b("UserDefinedSymbolNode",e,t)}(e,t),e}function Vr(e){return l.NormalBuiltinSymbol===e[0]}function Dr(e){return l.SpecialBuiltinSymbol===e[0]}function Ur(e){return!!function(e){return e[0]===l.NormalExpression}(e)&&function(e){const t=e[0];return l.UserDefinedSymbol===t||l.NormalBuiltinSymbol===t||l.SpecialBuiltinSymbol===t}(e[1][0])}function Fr(e){return e[0]===l.Spread}class Wr{_contexts;globalContext;values;modules;valueModules;pure;constructor({contexts:e,values:t,modules:r,valueModules:n,pure:o}){this.globalContext=w(e[0]),this._contexts=e,this.values=t,this.modules=r??new Map,this.valueModules=n??new Map,this.pure=o??!1}getContextsRaw(){return this._contexts}getHostValues(){return this.values}getModuleScopeBindings(){const e=this._contexts[0],t={};for(const[r,n]of Object.entries(e))t[r]=n.value;return t}getGlobalContextIndex(){return this._contexts.indexOf(this.globalContext)}static fromDeserialized(e){const t=new Wr({contexts:e.contexts,values:e.values,modules:e.modules,pure:e.pure});return e.globalContextIndex>=0&&e.globalContextIndex<e.contexts.length&&(t.globalContext=e.contexts[e.globalContextIndex]),t}setContextsFromDeserialized(e,t){this._contexts=e,t>=0&&t<e.length&&(this.globalContext=e[t])}getModule(e){return this.modules.get(e)}getValueModule(e){return this.valueModules.has(e)?{value:this.valueModules.get(e),found:!0}:{value:void 0,found:!1}}registerValueModule(e,t){this.valueModules.set(e,t)}create(e){const t=this.globalContext,r=new Wr({contexts:[e,...this._contexts],values:this.values,modules:this.modules,valueModules:this.valueModules,pure:this.pure});return r.globalContext=t,r}new(e){return new Wr({contexts:[{},e],modules:this.modules,valueModules:this.valueModules,pure:this.pure})}addValues(e,t){const r=this._contexts[0];for(const[n,a]of Object.entries(e)){if(r[n])throw new o(`Cannot redefine value "${n}"`,t);const e=Gr(n);if(e)throw new o(`Cannot shadow ${e}`,t);r[n]={value:le(a)}}}getValue(e){for(const t of this._contexts){const r=t[e];if(r)return r.value}return this.values?.[e]}lookUp(e){const t=e[1];for(const e of this._contexts){const r=e[t];if(r)return r}const r=this.values?.[t];return void 0!==r?{value:le(r)}:null}evaluateSymbol(e){if(Dr(e)){const t=e[1];switch(t){case tr["&&"]:case tr["||"]:case tr.array:case tr.object:case tr["defined?"]:case tr.recur:case tr["??"]:{const r=w(rr.specialExpressions[t],e[2]);return{[p]:!0,functionType:"SpecialBuiltin",specialBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:r.arity}}default:throw new o(`Unknown special builtin symbol type: ${t}`,e[2])}}if(Vr(e)){const t=e[1],r=st[t],n=r.name;return{[p]:!0,functionType:"Builtin",normalBuiltinSymbolType:t,sourceCodeInfo:e[2],arity:r.arity,name:n}}const t=this.lookUp(e);if(k(r=t)&&void 0!==r.value)return t.value;var r;throw new s(e[1],e[2])}}function Gr(e){return or.includes(e)?`special expression "${e}"`:nr.includes(e)?`builtin function "${e}"`:"self"===e?`builtin value "${e}"`:null}function Br(e){const t=Gr(e);if(t)throw new o(`Cannot shadow ${t}`,void 0)}function Lr(e={},t,r){const n=e.globalContext??{},a=e.contexts?[n,...e.contexts]:[n];let i;if(e.bindings)for(const[t,r]of Object.entries(e.bindings)){if(t.includes("."))throw new o(`Dots are not allowed in binding keys: "${t}"`,void 0);Br(t),i||(i={}),i[t]=r}const s=new Wr({contexts:a,values:i,modules:t,pure:r});return e.globalModuleScope?s:s.create({})}const _r=(e,t,r,n)=>{const o=Array.isArray(e)?e:[[l.SpecialExpression,[tr.block,e.body,void 0]]],a=new Set;for(const e of o)Kr(e,t,r,n)?.forEach(e=>a.add(e));return a};function Kr(e,t,r,n){const a=e[0];switch(a){case l.UserDefinedSymbol:{const r=e;return null===t.lookUp(r)?new Set([r[1]]):null}case l.NormalBuiltinSymbol:case l.SpecialBuiltinSymbol:case l.String:case l.Number:case l.ReservedSymbol:case l.Binding:return null;case l.NormalExpression:{const o=e,a=new Set;if(Ur(o)){const[,[e]]=o;if(Mr(e)){null===t.lookUp(e)&&a.add(e[1])}}else{const[,[e]]=o;Kr(e,t,r,n)?.forEach(e=>a.add(e))}for(const e of o[1][1])Kr(e,t,r,n)?.forEach(e=>a.add(e));return a}case l.SpecialExpression:{const o=e,a=o[1][0];return(0,r.specialExpressions[a].getUndefinedSymbols)(o,t,{getUndefinedSymbols:_r,builtin:r,evaluateNode:n})}case l.Spread:return Kr(e[1],t,r,n);default:throw new o(`Unhandled node type: ${a}`,e[2])}}function Jr(e,t){return"Symbol"===e?.[0]&&(!t||e[1]===t)}function Hr(e,t){return function(e,t){Jr(e,t)||yn("Symbol",void 0,e)}(e,t),e}function Yr(e,t){return"ReservedSymbol"===e?.[0]&&(!t||e[1]===t)}function Xr(e,t){Yr(e,t)||yn("ReservedSymbol",t,e)}function Qr(e,t){return Xr(e,t),e}function Zr(e,t){return"Operator"===e?.[0]&&(!t||e[1]===t)}function en(e,t){Zr(e,t)||yn("Operator",t,e)}function tn(e){return"Number"===e?.[0]}function rn(e){return"BasePrefixedNumber"===e?.[0]}function nn(e){return"LParen"===e?.[0]}function on(e){nn(e)||yn("LParen",void 0,e)}function an(e){return"RParen"===e?.[0]}function sn(e){an(e)||yn("RParen",void 0,e)}function ln(e){return"LBracket"===e?.[0]}function cn(e){return function(e){ln(e)||yn("LBracket",void 0,e)}(e),e}function un(e){return"RBracket"===e?.[0]}function mn(e){un(e)||yn("RBracket",void 0,e)}function pn(e){return"LBrace"===e?.[0]}function dn(e){return function(e){pn(e)||yn("LBrace",void 0,e)}(e),e}function hn(e){return"RBrace"===e?.[0]}function gn(e){return"string"===e?.[0]}function fn(e){return"Operator"===e?.[0]&&ur(e[1])}function yn(e,t,r){const n=r?`${r[0]} '${r[1]}'`:"end of input";throw new o(`Unexpected token: ${n}, expected ${e}${t?` '${t}'`:""}`,r?.[2])}function vn(e,t){return t&&(e[2]=t),e}function bn(e,t){return void 0!==tr[e]&&"fn"!==e&&"defn"!==e?vn([l.SpecialBuiltinSymbol,tr[e]],t):void 0!==it[e]?vn([l.NormalBuiltinSymbol,it[e]],t):vn([l.UserDefinedSymbol,e],t)}function wn(e){return e.substring(1,e.length-1).replace(/(\\{2})|(\\')|\\(.)/g,(e,t,r,n)=>t?"\\":r?"'":`\\${n}`)}const xn=Object.entries(it).reduce((e,[t,r])=>(e[r]=t,e),[]),kn=Object.entries(tr).reduce((e,[t,r])=>(e[r]=t,e),[]);function qn(e){return Mr(e)?e[1]:Vr(e)?xn[e[1]]:kn[e[1]]}function An(e,t,r){const n=vn([l.NormalExpression,[e,t]],r);return Vr(e)&&ee(st[e[1]].arity,n[1][1].length,r),n}function Nn(e){if(e.isAtEnd())return!0;const t=e.tryPeek();return Zr(t)?[";",",",":"].includes(t[1]):!!Yr(t)&&["else","when","while","case","let","then","end","do"].includes(t[1])}function $n(e,t,r,n,a){const i=e[1];switch(i){case"^":case"*":case"/":case"%":case"+":case"-":case"<<":case">>":case">>>":case"++":case"<":case"<=":case"≤":case">":case">=":case"≥":case"==":case"!=":case"&":case"xor":case"|":case"|>":return An(t,[r,n],a);case"&&":case"||":case"??":return vn([l.SpecialExpression,[tr[i],[r,n]]],a);default:throw new o(`Unknown binary operator: ${i}`,a)}}class En{tokens;position;storedPosition=0;parseExpression;constructor(e){this.tokens=e.tokens,this.position=0}advance(){this.position+=1}tryPeek(){return this.tokens[this.position]}peek(){const e=this.tokens[this.position];if(!e){const e=this.tokens.at(-1),t=e?e[2]:void 0;throw new o("Unexpected end of input",t)}return e}isAtEnd(){return this.position>=this.tokens.length}peekSourceCodeInfo(){const e=this.tryPeek();return e?e[2]:this.tokens.at(-1)?.[2]}storePosition(){return this.storedPosition=this.position}restorePosition(){this.position=this.storedPosition}peekAhead(e){return this.tokens[this.position+e]}getPosition(){return this.position}getTokenAt(e){return this.tokens[e]}}function Tn(e,t){switch(e){case"^":return 12;case"*":case"/":case"%":return 11;case"+":case"-":return 10;case"<<":case">>":case">>>":return 9;case"++":return 8;case"<":case"<=":case"≤":case">":case">=":case"≥":return 7;case"==":case"!=":return 6;case"&":case"xor":case"|":return 5;case"&&":case"||":case"??":return 4;case"|>":return 2;default:throw new o(`Unknown binary operator: ${e}`,t)}}function Sn(e,t){const r=[];for(;!e.isAtEnd()&&!zn(e,t);)Zr(e.tryPeek(),";")?e.advance():r.push(e.parseExpression());if(function(e,t){if(!zn(e,t))throw new o(`Expected ${t.map(e=>e[1]).join(" or ")}`,e.peekSourceCodeInfo())}(e,t),0===r.length)throw new o("Expected expression",e.peekSourceCodeInfo());return 1===r.length?r[0]:vn([l.SpecialExpression,[tr.block,r,void 0]],e.peekSourceCodeInfo())}function zn(e,t){for(const r of t)if(Yr(e.tryPeek(),r))return!0;return!1}function jn(e){const t=Qr(e.tryPeek(),"do");e.advance();const r=[];for(;!e.isAtEnd()&&!Yr(e.tryPeek(),"end")&&!Yr(e.tryPeek(),"with");)if(r.push(e.parseExpression()),Zr(e.tryPeek(),";"))e.advance();else if(!Yr(e.tryPeek(),"end")&&!Yr(e.tryPeek(),"with"))throw new o("Expected end",e.peekSourceCodeInfo());let n;if(Yr(e.tryPeek(),"with"))for(e.advance(),n=[];!e.isAtEnd()&&!Yr(e.tryPeek(),"end");){Xr(e.tryPeek(),"case"),e.advance();const t=e.parseExpression();Xr(e.tryPeek(),"then"),e.advance();const r=Sn(e,["case","end"]);n.push([t,r])}return Xr(e.tryPeek(),"end"),e.advance(),vn([l.SpecialExpression,[tr.block,r,n]],t[2])}function Cn(e){const t=e.peek();if(e.advance(),!Jr(t))throw new o(`Expected symbol token, got ${t[0]}`,t[2]);return"'"===t[1][0]?bn(wn(t[1]),t[2]):bn(t[1],t[2])}function In(e,t){e.advance();const r=t[1].substring(1,t[1].length-1).replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g,(e,t,r,n,o,a,i,s,l)=>t?"\\":n?"\n":o?"\t":a?"\r":i?"\b":s?"\f":r?'"':l);return vn([l.String,r],t[2])}function Rn(e){const t=e.peek();e.advance();const r=t[1],n="-"===r[0],o=(n?r.substring(1):r).replace(/_/g,"");return vn([l.Number,n?-Number(o):Number(o)],t[2])}function Pn(e,{requireDefaultValue:t,noRest:r,allowLiteralPatterns:n}={}){const a=e.tryPeek();if(n&&Yr(a,"_"))return e.advance(),vn([gt,[]],a[2]);if(n&&On(a)){if(tn(a)||rn(a)){const t=Rn(e);return vn([ht,[t]],a[2])}if(gn(a)){const t=In(e,a);return vn([ht,[t]],a[2])}if(Yr(a,"true")){e.advance();const t=vn([l.ReservedSymbol,"true"],a[2]);return vn([ht,[t]],a[2])}if(Yr(a,"false")){e.advance();const t=vn([l.ReservedSymbol,"false"],a[2]);return vn([ht,[t]],a[2])}if(Yr(a,"null")){e.advance();const t=vn([l.ReservedSymbol,"null"],a[2]);return vn([ht,[t]],a[2])}}if(Jr(a)){const r=Cn(e);if(!Mr(r))throw new o("Expected user defined symbol",a[2]);const n=Mn(e);if(t&&!n)throw new o("Expected assignment",e.peekSourceCodeInfo());return vn([ut,[r,n]],a[2])}if(Zr(a,"...")){if(r)throw new o("Rest element not allowed",a[2]);e.advance();const t=Or(Cn(e));if(Zr(e.tryPeek(),"="))throw new o("Rest argument can not have default value",e.peekSourceCodeInfo());return vn([mt,[t[1],void 0]],a[2])}if(ln(a)){e.advance();const r=[];let i=e.peek(),s=!1;for(;!un(i);){if(s)throw new o("Rest argument must be last",i[2]);if(Zr(i,",")){r.push(null),e.advance(),i=e.peek();continue}const t=Pn(e,{allowLiteralPatterns:n});t[0]===mt&&(s=!0),r.push(t),i=e.peek(),un(i)||(en(i,","),e.advance()),i=e.peek()}e.advance();const l=Mn(e);if(t&&!l)throw new o("Expected assignment",e.peekSourceCodeInfo());return vn([dt,[r,l]],a[2])}if(pn(a)){e.advance();const r={};let i=e.peek(),s=!1;for(;!hn(i);){if(s)throw new o("Rest argument must be last",i[2]);Zr(i,"...")&&(s=!0,e.advance());const t=Cn(e),l=qn(t);if(i=e.peek(),Yr(i,"as")){if(s)throw new o("Rest argument can not have alias",i[2]);e.advance();const t=Or(Cn(e));if(r[t[1]])throw new o(`Duplicate binding name: ${t}`,i[2]);r[l]=vn([ut,[t,Mn(e)]],a[2])}else if(hn(i)||Zr(i,",")||Zr(i,"=")){const n=Or(t,t[2]);if(r[n[1]])throw new o(`Duplicate binding name: ${n}`,i[2]);if(s&&Zr(e.tryPeek(),"="))throw new o("Rest argument can not have default value",e.peekSourceCodeInfo());r[n[1]]=vn(s?[mt,[n[1],Mn(e)]]:[ut,[n,Mn(e)]],a[2])}else if(Zr(i,":")){if(e.advance(),i=e.peek(),n){if(!pn(i)&&!ln(i)&&!On(i))throw new o("Expected literal, object or array pattern",i[2])}else if(!pn(i)&&!ln(i))throw new o("Expected object or array",i[2]);r[l]=Pn(e,{allowLiteralPatterns:n})}hn(e.peek())||(en(e.peek(),","),e.advance()),i=e.peek()}e.advance(),i=e.peek();const l=Mn(e);if(t&&!l)throw new o("Expected assignment",i[2]);return vn([pt,[r,l]],a[2])}throw new o("Expected symbol",e.peekSourceCodeInfo())}function Mn(e){if(Zr(e.tryPeek(),"="))return e.advance(),e.parseExpression()}function On(e){return tn(e)||rn(e)||gn(e)||Yr(e,"true")||Yr(e,"false")||Yr(e,"null")}function Vn(e,t){e.advance();const r=Pn(e,{requireDefaultValue:!0,noRest:!0}),n=r[1][1];r[1][1]=void 0;const o=vn([l.Binding,[r,n]],t[2]);return vn([l.SpecialExpression,[tr.let,o]],t[2])}function Dn(e){const t=function(e){const t=Hr(e.tryPeek()),r=Or(Cn(e));Xr(e.tryPeek(),"in"),e.advance();const n=e.parseExpression();return vn([l.Binding,[vn([ut,[r,void 0]],t[2]),n]],t[2])}(e),r=[];let n=e.peek();Un(n,["let","when","while"]);const a=[];if("let"===n[1])for(r.push("&let");Jr(n,"let");){const t=Vn(e,n),r=a.flatMap(e=>Object.keys($t(e[1][0])));if(Object.keys($t(t[1][1][1][0])).some(e=>r.includes(e)))throw new o("Duplicate binding",t[1][1][2]);a.push(t[1][1]),n=e.peek(),Un(n,["let","when","while"]),n=e.peek()}let i,s;for(;Yr(n,"when")||Yr(n,"while");){e.advance(),"when"===n[1]?(r.push("&when"),i=e.parseExpression()):(r.push("&while"),s=e.parseExpression()),n=e.peek();Un(n,r.includes("&when")&&r.includes("&while")?[]:r.includes("&when")?["while"]:["when"]),n=e.peek()}return Un(n,[]),[t,a,i,s]}function Un(e,t){if(!function(e,t){if(Zr(e,",")||an(e))return!0;for(const r of t){if("let"===r&&Jr(e,"let"))return!0;if(["when","while"].includes(r)&&Yr(e,r))return!0}return!1}(e,t)){const r=`${[...t,","].map(e=>`"${e}"`).join(", ")} or ")"`;throw new o(`Expected symbol ${r}`,e[2])}}function Fn(e){const t=Qr(e.tryPeek());e.advance();const r=t[1];return function(e){return e in hr}(r)?vn([l.Number,hr[r]],t[2]):vn([l.ReservedSymbol,t[1]],t[2])}const Wn=/^\$([1-9]\d?)?$/;function Gn(e){const t=e.peek();if(nn(t)&&Jr(e.peekAhead(1))&&Zr(e.peekAhead(2),"->"))return null;try{const r=function(e){const t=e.peek();if(Jr(t))return[vn([ut,[Cn(e),void 0]],t[2])];on(t),e.advance();let r=!1,n=!1;const a=[];for(;!e.isAtEnd()&&!an(e.peek())&&!Jr(e.peek(),"let");){if(r)throw new o("Rest argument must be last",e.peekSourceCodeInfo());const t=Pn(e);if(void 0!==t[1][1]&&(n=!0),t[0]===mt&&(r=!0),n&&!t[1][1])throw new o("Default arguments must be last",e.peekSourceCodeInfo());if(a.push(t),!Zr(e.peek(),",")&&!an(e.peek())&&!Jr(e.peek(),"let"))throw new o("Expected comma or closing parenthesis",e.peekSourceCodeInfo());Zr(e.peek(),",")&&e.advance()}if(!an(e.peek()))throw new o("Expected closing parenthesis",e.peekSourceCodeInfo());return e.advance(),a}(e);if(!Zr(e.peek(),"->"))return null;let n;if(e.advance(),Yr(e.peek(),"do")){const t=jn(e),r=t[1][2];n=r&&r.length>0?[t]:t[1][1]}else n=[e.parseExpression()];return vn([l.SpecialExpression,[tr["0_lambda"],[r,n]]],t[2])}catch{return null}}function Bn(e,t){if(e.advance(),Dr(t)&&t[1]===tr.effect)return function(e,t){const r=t[2],n=e.peek();if(!Jr(n))throw new o("effect expects a dotted name identifier",n[2]);let a=n[1];e.advance();for(;Zr(e.tryPeek(),".");){e.advance();const t=e.peek();if(!Jr(t))throw new o("Expected identifier after dot in effect name",t[2]);a+=`.${t[1]}`,e.advance()}if(!an(e.tryPeek()))throw new o("Expected closing parenthesis after effect name",e.peekSourceCodeInfo());return e.advance(),vn([l.SpecialExpression,[tr.effect,a]],r)}(e,t);const r=[];for(;!e.isAtEnd()&&!an(e.tryPeek());){Zr(e.tryPeek(),"...")?(e.advance(),r.push(vn([l.Spread,e.parseExpression()],e.peekSourceCodeInfo()))):r.push(e.parseExpression());const t=e.tryPeek();if(!Zr(t,",")&&!an(t))throw new o("Expected comma or closing parenthesis",e.tryPeek()?.[2]);Zr(t,",")&&e.advance()}if(!an(e.tryPeek()))throw new o("Expected closing parenthesis",e.peekSourceCodeInfo());if(e.advance(),!Dr(t))return Vr(t)||Mr(t)?An(t,r,t[2]):vn([l.NormalExpression,[t,r]],t[2]);{const e=t[1];if(e===tr.import){if(1!==r.length)throw new o(`import expects exactly 1 argument, got ${r.length}`,t[2]);const n=r[0];if(!Mr(n))throw new o("import expects a module name (symbol), got a non-symbol argument",n[2]??t[2]);const a=n[1];return vn([l.SpecialExpression,[e,a]],t[2])}const n=e;switch(ee(rr.specialExpressions[n].arity,r.length,t[2]),n){case tr["||"]:case tr["&&"]:case tr.recur:case tr.array:case tr.object:case tr["??"]:return vn([l.SpecialExpression,[n,r]],t[2]);case tr["defined?"]:{const[e]=r;return vn([l.SpecialExpression,[n,e]],t[2])}case tr.perform:{const[e,...o]=r;return vn([l.SpecialExpression,[n,e,o]],t[2])}case tr.parallel:case tr.race:return vn([l.SpecialExpression,[n,r]],t[2]);case tr["0_lambda"]:throw new o(`${n} is not allowed`,t[2]);default:throw new o(`Unknown special expression: ${n}`,t[2])}}}function Ln(e){const t=dn(e.tryPeek());e.advance();const r=[];for(;!e.isAtEnd()&&!hn(e.tryPeek());){if(Zr(e.tryPeek(),"..."))e.advance(),r.push(vn([l.Spread,e.parseExpression()],e.peekSourceCodeInfo()));else{const t=e.tryPeek();if(gn(t)){const n=In(e,t);r.push(vn([l.String,n[1]],t[2]))}else if(Jr(t)){const n=t[1].startsWith("'")?wn(t[1]):t[1];r.push(vn([l.String,n],t[2])),e.advance()}else{if(!ln(t))throw new o("Expected key to be a symbol or a string",e.peekSourceCodeInfo());e.advance(),r.push(e.parseExpression()),mn(e.tryPeek()),e.advance()}en(e.tryPeek(),":"),e.advance(),r.push(e.parseExpression())}const t=e.tryPeek();if(!Zr(t,",")&&!hn(t))throw new o("Expected comma or closing brace",e.peekSourceCodeInfo());Zr(t,",")&&e.advance()}var n;return hn(n=e.tryPeek())||yn("RBrace",void 0,n),e.advance(),vn([l.SpecialExpression,[tr.object,r]],t[2])}function _n(e){let t=function(e){const t=e.peek();if(nn(t)){e.storePosition();const t=Gn(e);if(t)return t;e.restorePosition(),e.advance();const r=e.parseExpression();if(!an(e.peek()))throw new o("Expected closing parenthesis",e.peekSourceCodeInfo());return e.advance(),r}if(Zr(t)){const r=t[1];if(ur(r))return e.advance(),vn(void 0!==tr[r]?[l.SpecialBuiltinSymbol,tr[r]]:[l.NormalBuiltinSymbol,it[r]],t[2]);if("->"===r)return function(e){const t=e.peek();e.advance();const r=e.getPosition();let n;if(Yr(e.peek(),"do")){const t=jn(e),r=t[1][2];n=r&&r.length>0?[t]:t[1][1]}else n=[e.parseExpression()];const a=e.getPosition()-1;let i=0,s="NOT_SET";for(let n=r;n<=a;n+=1){const r=e.getTokenAt(n);if(Jr(r)){const e=Wn.exec(r[1]);if(e){const r=e[1]??"1";if("1"===r){if(!e[1]&&"WITH_1"===s||e[1]&&"NAKED"===s)throw new o("Please make up your mind, either use $ or $1",t[2]);s=e[1]?"WITH_1":"NAKED"}if(i=Math.max(i,Number(r)),i>20)throw new o("Can't specify more than 20 arguments",t[2])}}}const c=[];for(let e=1;e<=i;e+=1)1===e&&"NAKED"===s?c.push(vn([ut,[[l.UserDefinedSymbol,"$"],void 0]],t[2])):c.push(vn([ut,[[l.UserDefinedSymbol,`$${e}`],void 0]],t[2]));return vn([l.SpecialExpression,[tr["0_lambda"],[c,n]]],t[2])}(e);throw new o(`Illegal operator: ${r}`,t[2])}if(pn(t))return Ln(e);if(ln(t))return function(e){const t=cn(e.tryPeek());e.advance();const r=[];for(;!e.isAtEnd()&&!un(e.tryPeek());){Zr(e.tryPeek(),"...")?(e.advance(),r.push(vn([l.Spread,e.parseExpression()],e.peekSourceCodeInfo()))):r.push(e.parseExpression());const t=e.tryPeek();if(!Zr(t,",")&&!un(t))throw new o("Expected comma or closing parenthesis",e.peekSourceCodeInfo());Zr(t,",")&&e.advance()}return mn(e.tryPeek()),e.advance(),vn([l.SpecialExpression,[tr.array,r]],t[2])}(e);const r=t[0];switch(r){case"Number":case"BasePrefixedNumber":return Rn(e);case"string":return In(e,t);case"Symbol":{e.storePosition();const t=Gn(e);return t||(e.restorePosition(),Cn(e))}case"ReservedSymbol":return Fn(e);case"RegexpShorthand":return function(e){const t=e.peek();e.advance();const r=t[1].lastIndexOf('"'),n=t[1].substring(2,r),o=t[1].substring(r+1),a=vn([l.String,n],t[2]),i=vn([l.String,o],t[2]);return vn([l.NormalExpression,[vn([l.NormalBuiltinSymbol,it.regexp],t[2]),[a,i]]],t[2])}(e);default:throw new o(`Unknown token type: ${r}`,t[2])}}(e),r=e.tryPeek();for(;Zr(r,".")||ln(r)||nn(r);)if("."===r[1]){e.advance();const n=e.tryPeek();if(!Jr(n))throw new o("Expected symbol",e.peekSourceCodeInfo());t=Kn(t,vn([l.String,n[1]],n[2]),r[2]),e.advance(),r=e.tryPeek()}else if(ln(r)){e.advance();const n=e.parseExpression();if(!un(e.tryPeek()))throw new o("Expected closing bracket",e.peekSourceCodeInfo());t=Kn(t,n,r[2]),e.advance(),r=e.tryPeek()}else nn(r)&&(t=Bn(e,t),r=e.tryPeek());return t}function Kn(e,t,r){return vn([l.NormalExpression,[[l.NormalBuiltinSymbol,it.get],[e,t]]],r)}function Jn(e,t=0){const r=e.tryPeek();let n;if(Jr(r))switch(r[1]){case"let":return Vn(e,r);case"if":case"unless":n=function(e,t){const r="unless"===t[1];e.advance();const n=e.parseExpression();Xr(e.tryPeek(),"then"),e.advance();const o=Sn(e,["else","end"]);let a;return Yr(e.tryPeek(),"else")&&(e.advance(),a=Sn(e,["end"])),e.advance(),vn(r?[l.SpecialExpression,[tr.unless,[n,o,a]]]:[l.SpecialExpression,[tr.if,[n,o,a]]],t[2])}(e,r);break;case"cond":n=function(e,t){e.advance();const r=[];for(;!e.isAtEnd()&&!Yr(e.tryPeek(),"end");){Xr(e.tryPeek(),"case"),e.advance();const t=e.parseExpression();Xr(e.tryPeek(),"then"),e.advance();const n=Sn(e,["case","end"]);if(r.push([t,n]),Yr(e.tryPeek(),"end"))break}return Xr(e.tryPeek()),e.advance(),vn([l.SpecialExpression,[tr.cond,r]],t[2])}(e,r);break;case"match":n=function(e,t){e.advance();const r=e.parseExpression(),n=[];for(;!e.isAtEnd()&&!Yr(e.tryPeek(),"end");){Xr(e.tryPeek(),"case"),e.advance();const t=Pn(e,{allowLiteralPatterns:!0});let r;Yr(e.tryPeek(),"when")&&(e.advance(),r=e.parseExpression()),Xr(e.tryPeek(),"then"),e.advance();const o=Sn(e,["case","end"]);if(n.push([t,o,r]),Yr(e.tryPeek(),"end"))break}return Xr(e.tryPeek(),"end"),e.advance(),vn([l.SpecialExpression,[tr.match,r,n]],t[2])}(e,r);break;case"for":case"doseq":n=function(e,t){const r="doseq"===t[1];e.advance(),on(e.tryPeek()),e.advance();const n=[];for(;!e.isAtEnd()&&!an(e.tryPeek());){const t=Dn(e),r=n.flatMap(e=>Object.keys($t(e[0][1][0]))),a=$t(t[0][1][0]);if(Object.keys(a).some(e=>r.includes(e)))throw new o("Duplicate binding",t[0][2]);n.push(t),Zr(e.tryPeek(),",")&&e.advance()}sn(e.tryPeek()),e.advance(),en(e.tryPeek(),"->"),e.advance();const a=e.parseExpression();return vn(r?[l.SpecialExpression,[tr.doseq,n,a]]:[l.SpecialExpression,[tr.for,n,a]],t[2])}(e,r);break;case"loop":n=function(e,t){e.advance(),on(e.tryPeek()),e.advance();const r=[];let n=e.tryPeek();for(;!e.isAtEnd()&&!an(n);){const t=Pn(e,{requireDefaultValue:!0,noRest:!0}),o=t[1][1];t[1][1]=void 0,r.push(vn([l.Binding,[t,o]],t[2])),Zr(e.tryPeek(),",")&&e.advance(),n=e.tryPeek()}if(0===r.length)throw new o("Expected binding",e.peekSourceCodeInfo());sn(n),e.advance(),en(e.tryPeek(),"->"),e.advance();const a=e.parseExpression();return vn([l.SpecialExpression,[tr.loop,r,a]],t[2])}(e,r)}else Yr(r,"do")&&(n=jn(e));n||=_n(e);let a=e.tryPeek();for(;!Nn(e);){if(fn(a)){const r=a[1],o=Tn(r,a[2]);if(o<=t&&(12!==o||12!==t))break;const i=vn(tr[r]?[l.SpecialBuiltinSymbol,tr[r]]:[l.NormalBuiltinSymbol,it[r]],a[2]);e.advance();n=$n(a,i,n,Jn(e,o),a[2])}else if(Jr(a)){if(!lr(a[1]))break;const r=3;if(r<=t)break;const i=Cn(e),s=Jn(e,r);if(Dr(i))throw new o("Special expressions are not allowed in binary functional operators",i[2]);n=An(i,[n,s],a[2])}else{if("?"!==a?.[1])break;{if(1<=t)break;e.advance();const r=Jn(e);if(!Zr(e.tryPeek(),":"))throw new o("Expected :",e.peekSourceCodeInfo());e.advance();const a=Jn(e);n=vn([l.SpecialExpression,[tr.if,[n,r,a]]],n[2])}}a=e.tryPeek()}return n}function Hn(e){e.tokens.forEach(e=>{if("Error"===e[0])throw new o(e[3],e[2])});const t=[],r=function(e){const t=new En(e);return t.parseExpression=(e=0)=>Jn(t,e),t}(e);for(;!r.isAtEnd();)if(t.push(Jn(r,0)),Zr(r.tryPeek(),";"))r.advance();else if(!r.isAtEnd())throw new o("Expected ;",r.peekSourceCodeInfo());return t}function Yn(e,{removeWhiteSpace:t}){const r=e.tokens.filter(e=>!(function(e){return"SingleLineComment"===e?.[0]}(e)||function(e){return"MultiLineComment"===e?.[0]}(e)||function(e){return"Shebang"===e?.[0]}(e)||t&&function(e){return"Whitespace"===e?.[0]}(e)));return{...e,tokens:r}}function Xn(e,t){if("*"===t)return!0;if(t.endsWith(".*")){const r=t.slice(0,-2);return e===r||e.startsWith(`${r}.`)}return e===t}function Qn(e,t){if(!t)return[];const r=[];for(const[n,o]of Object.entries(t))Xn(e,n)&&r.push([n,o]);return r}class Zn{k;snapshots;nextSnapshotIndex;meta;effectName;effectArgs;_brand="SuspensionSignal";constructor(e,t,r,n,o,a){this.k=e,this.snapshots=t,this.nextSnapshotIndex=r,this.meta=n,this.effectName=o,this.effectArgs=a}}function eo(e){return e instanceof Zn}class to{continuation;value;trimToIndex;_brand="ResumeFromSignal";constructor(e,t,r){this.continuation=e,this.value=t,this.trimToIndex=r}}function ro(e){return e instanceof to}const no=new Map;function oo(e){let t=no.get(e);return t||(t={[h]:!0,name:e},no.set(e,t)),t}function ao(e,t){return Math.imul(e^255&t,16777619)}function io(e,t){return e=ao(e,t),e=ao(e,t>>>8),e=ao(e,t>>>16),e=ao(e,t>>>24)}function so(e,t){for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);e=ao(e,n),e=ao(e,n>>>8)}return e}function lo(e){let t=2166136261;if(null===e)return t=ao(t,0),t>>>0;if(void 0===e)return t=ao(t,7),t>>>0;const r=typeof e;if("boolean"===r)return t=ao(t,e?1:2),t>>>0;if("number"===r)return t=ao(t,3),t=so(t,Object.is(e,-0)?"-0":String(e)),t>>>0;if("string"===r)return t=ao(t,4),t=so(t,e),t>>>0;if(Array.isArray(e)){t=ao(t,5),t=io(t,e.length);for(let r=0;r<e.length;r++)t=io(t,lo(e[r]));return t>>>0}t=ao(t,6);const n=Object.keys(e).sort();t=io(t,n.length);for(const r of n)t=so(t,r),t=io(t,lo(e[r]));return t>>>0}function co(e,t){if(e===t)return!0;if(null===e||null===t)return!1;if(typeof e!=typeof t)return!1;if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!co(e[r],t[r]))return!1;return!0}if("object"!=typeof e)return!1;const r=e,n=t,o=Object.keys(r),a=Object.keys(n);if(o.length!==a.length)return!1;for(const e of o){if(!(e in n))return!1;if(!co(r[e],n[e]))return!1}return!0}function uo(e){if(null===e)return 4;if(void 0===e)return 9;const t=typeof e;if("boolean"===t)return e?4:5;if("number"===t)return String(e).length;if("string"===t)return e.length+2;if(Array.isArray(e)){let t=2;for(let r=0;r<e.length;r++)t+=uo(e[r])+1;return t}const r=e,n=Object.keys(r);let o=2;for(const e of n)o+=e.length+2+1+uo(r[e])+1;return o}function mo(e,t,r,n){if(null===e||"object"!=typeof e)return lo(e);if(Array.isArray(e))for(let r=0;r<e.length;r++)mo(e[r],t,{parent:e,key:r});else{const r=e;for(const e of Object.keys(r))mo(r[e],t,{parent:r,key:e})}const o=lo(e),a=uo(e);if(r&&a>=1){let n,i=t.get(o);i||(i=[],t.set(o,i));for(const t of i)if(co(t.value,e)){n=t;break}n?n.locations.push(r):i.push({hash:o,value:ho(e),size:a,locations:[r]})}return o}function po(e,t){if(null===e||"object"!=typeof e)return e;if(function(e){return null!==e&&"object"==typeof e&&"__poolRef"in e&&"number"==typeof e.__poolRef&&1===Object.keys(e).length}(e)){const r=e.__poolRef;if(!(r in t))throw new Error(`Unknown pool ref: ${r}`);return po(t[r],t)}if(Array.isArray(e))return e.map(e=>po(e,t));const r=e,n={};for(const e of Object.keys(r))n[e]=po(r[e],t);return n}function ho(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(e=>ho(e));const t=e,r={};for(const e of Object.keys(t))r[e]=ho(t[e]);return r}function go(e,t){const r=new Map;let n=0;function o(e){if(e instanceof Wr){if(r.has(e))return;r.set(e,n++);for(const t of e.getContextsRaw())for(const e of Object.values(t))o(e.value)}else if(Array.isArray(e))for(const t of e)o(t);else if(null!==e&&"object"==typeof e)for(const t of Object.values(e))o(t)}function a(e,t){if(e instanceof Wr)return{__csRef:r.get(e)};if(Array.isArray(e))return e.map((e,t)=>a(e));if(null!==e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))t[r]=a(n);return t}return e}o(e),void 0!==t&&o(t);const i=Array.from(r.entries()).map(([e,t])=>({id:t,contexts:e.getContextsRaw().map((e,t)=>{const r={};for(const[t,n]of Object.entries(e))r[t]={value:a(n.value)};return r}),globalContextIndex:e.getGlobalContextIndex(),pure:e.pure})),s=a(e),l=void 0!==t?a(t):void 0;return{version:2,contextStacks:i,k:s,...void 0!==l?{meta:l}:{}}}function fo(e,t,r,n){const o=go(e,n);t.length>0&&(o.snapshots=t),o.nextSnapshotIndex=r;const a=[o.contextStacks,o.k];if(void 0!==o.meta&&a.push(o.meta),o.snapshots)for(const e of o.snapshots)a.push(e);const{roots:i,pool:s}=function(e,t=200){const r=e.map(e=>ho(e)),n=new Map;for(let e=0;e<r.length;e++)mo(r[e],n,null);const o={};let a=0;const i=Array.from(n.values()).flat().filter(e=>e.locations.length>1&&e.size>=t).sort((e,t)=>t.size-e.size),s=new Map;for(const e of i){if(s.has(e))continue;const t=a++;o[t]=e.value,s.set(e,t);for(const r of e.locations)Array.isArray(r.parent),r.parent[r.key]={__poolRef:t}}return{roots:r,pool:o}}(a,200);let l=0;if(o.contextStacks=i[l++],o.k=i[l++],void 0!==o.meta&&(o.meta=i[l++]),o.snapshots)for(let e=0;e<o.snapshots.length;e++)o.snapshots[e]=i[l++];return Object.keys(s).length>0&&(o.pool=s),o}function yo(e,t){let r=e;if(2!==r.version)throw new o(`Unsupported suspension blob version: ${r.version} (expected 2)`,void 0);if(r.pool&&Object.keys(r.pool).length>0){const e=r.pool;r={...r,contextStacks:po(r.contextStacks,e),k:po(r.k,e),...void 0!==r.meta?{meta:po(r.meta,e)}:{},...r.snapshots?{snapshots:r.snapshots.map(t=>po(t,e))}:{}},delete r.pool}const n=new Map;for(const e of r.contextStacks){const r=e.contexts.map(()=>({})),o=Wr.fromDeserialized({contexts:r,globalContextIndex:e.globalContextIndex,values:t?.values,modules:t?.modules,pure:e.pure});n.set(e.id,o)}function a(e){if(function(e){return null!==e&&"object"==typeof e&&"__csRef"in e&&"number"==typeof e.__csRef}(e)){const t=n.get(e.__csRef);if(!t)throw new o(`Invalid suspension blob: unknown context stack ref ${e.__csRef}`,void 0);return t}if(Array.isArray(e))return e.map(a);if(null!==e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))t[r]=a(n);return t}return e}for(const e of r.contextStacks){const t=n.get(e.id),r=e.contexts.map(e=>{const t=e,r={};for(const[e,n]of Object.entries(t))r[e]={value:a(n.value)};return r});t.setContextsFromDeserialized(r,e.globalContextIndex)}return{k:a(r.k),meta:void 0!==r.meta?a(r.meta):void 0,snapshots:r.snapshots??[],nextSnapshotIndex:r.nextSnapshotIndex??0}}function vo(){return"undefined"!=typeof process&&"function"==typeof process.stdout?.write}function bo(e){return"string"==typeof e?e:null===e?"null":"number"==typeof e||"boolean"==typeof e?String(e):q(e)?"Builtin"===e.functionType?`<builtin function ${e.normalBuiltinSymbolType}>`:`<function ${e.n??"λ"}>`:V(e)?`<effect ${e.name}>`:M(e)?`/${e.s}/${e.f}`:"object"==typeof e&&e instanceof RegExp?`${e}`:JSON.stringify(wo(e),null,2)}function wo(e){if(e===Number.POSITIVE_INFINITY)return"∞";if(e===Number.NEGATIVE_INFINITY)return"-∞";if(q(e))return bo(e);if(V(e))return bo(e);if(M(e))return bo(e);if(Array.isArray(e))return e.map(wo);if("object"==typeof e&&null!==e){const t={};for(const[r,n]of Object.entries(e))t[r]=wo(n);return t}return e}const xo={"dvala.io.print":{handler:function(e,t){const r=e[0],n=bo(r);return vo()?process.stdout.write(n):console.log(n),{type:"Value",value:r,k:t}},arity:te(1),docs:{category:"effect",description:"Writes a value to stdout without a trailing newline. Accepts any value — strings are printed as-is, other values are auto-formatted. In Node.js uses `process.stdout.write(str)`, in browsers uses `console.log(str)`. Resumes with the original value (identity).",returns:{type:"any"},args:{value:{type:"any",description:"Value to print."}},variants:[{argumentNames:["value"]}],examples:['perform(effect(dvala.io.print), "hello")',"perform(effect(dvala.io.print), 42)"],seeAlso:["-effect-dvala.io.println","-effect-dvala.io.error","-effect-dvala.io.read-line","perform","effect"]}},"dvala.io.println":{handler:function(e,t){const r=e[0],n=bo(r);return vo()?process.stdout.write(`${n}\n`):"function"==typeof globalThis.alert?globalThis.alert(n):console.log(n),{type:"Value",value:r,k:t}},arity:te(1),docs:{category:"effect",description:'Writes a value to stdout followed by a newline. Accepts any value — strings are printed as-is, other values are auto-formatted. In Node.js uses `process.stdout.write(str + "\\n")`, in browsers uses `alert(str)`. Resumes with the original value (identity).',returns:{type:"any"},args:{value:{type:"any",description:"Value to print."}},variants:[{argumentNames:["value"]}],examples:['perform(effect(dvala.io.println), "hello")',"perform(effect(dvala.io.println), [1, 2, 3])"],seeAlso:["-effect-dvala.io.print","-effect-dvala.io.error","-effect-dvala.io.read-line","perform","effect"]}},"dvala.io.error":{handler:(e,t)=>{const r=e[0],n=bo(r);return vo()?process.stderr.write(`${n}\n`):console.error(n),{type:"Value",value:r,k:t}},arity:te(1),docs:{category:"effect",description:'Writes a value to stderr followed by a newline. Accepts any value — strings are printed as-is, other values are auto-formatted. In Node.js uses `process.stderr.write(str + "\\n")`, in browsers uses `console.error(str)`. Resumes with the original value (identity).',returns:{type:"any"},args:{value:{type:"any",description:"Value to write to stderr."}},variants:[{argumentNames:["value"]}],examples:['perform(effect(dvala.io.error), "something went wrong")'],seeAlso:["-effect-dvala.io.print","-effect-dvala.io.println","perform","effect"]}},"dvala.io.read-line":{handler:(e,t,r)=>{const n="string"==typeof e[0]?e[0]:"";if("function"==typeof globalThis.prompt){return{type:"Value",value:globalThis.prompt(n)??null,k:t}}throw new o('dvala.io.read-line is not supported in this environment. In Node.js, register a "dvala.io.read-line" host handler.',r)},arity:{min:0,max:1},docs:{category:"effect",description:"Reads one line of user input. In browsers uses `window.prompt()`. In Node.js uses `readline`. Resumes with the user's input string, or `null` on cancel.",returns:{type:["string","null"]},args:{message:{type:"string",description:"Optional prompt message to display."}},variants:[{argumentNames:[]},{argumentNames:["message"]}],examples:["effect(dvala.io.read-line)"],seeAlso:["-effect-dvala.io.read-stdin","-effect-dvala.io.print","-effect-dvala.io.println","perform","effect"]}},"dvala.io.read-stdin":{handler:(e,t,r)=>{if(!vo()||!process.stdin)throw new o("dvala.io.read-stdin is not supported in this environment. Node.js is required.",r);return new Promise((e,r)=>{const n=[];process.stdin.setEncoding("utf-8"),process.stdin.on("data",e=>n.push(e)),process.stdin.on("end",()=>e({type:"Value",value:n.join(""),k:t})),process.stdin.on("error",e=>r(e)),process.stdin.resume()})},arity:te(0),docs:{category:"effect",description:"Reads all of stdin until EOF (Node.js only). Resumes with the full stdin content as a string.",returns:{type:"string"},args:{},variants:[{argumentNames:[]}],examples:["effect(dvala.io.read-stdin)"],seeAlso:["-effect-dvala.io.read-line","perform","effect"]}},"dvala.random":{handler:(e,t)=>({type:"Value",value:Math.random(),k:t}),arity:te(0),docs:{category:"effect",description:"Returns a random floating-point number in the range [0, 1). Equivalent to `Math.random()` in JavaScript.",returns:{type:"number"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.random))"],seeAlso:["-effect-dvala.random.int","-effect-dvala.random.uuid","-effect-dvala.random.item","-effect-dvala.random.shuffle","perform","effect"]}},"dvala.random.uuid":{handler:(e,t)=>({type:"Value",value:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),k:t}),arity:te(0),docs:{category:"effect",description:"Generates a UUID v4 string.",returns:{type:"string"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.random.uuid))"],seeAlso:["-effect-dvala.random","perform","effect"]}},"dvala.random.int":{handler:(e,t,r)=>{const n=e[0],a=e[1];if("number"!=typeof n||!Number.isInteger(n))throw new o(`dvala.random.int: min must be an integer, got ${"number"==typeof n?n:typeof n}`,r);if("number"!=typeof a||!Number.isInteger(a))throw new o(`dvala.random.int: max must be an integer, got ${"number"==typeof a?a:typeof a}`,r);if(a<=n)throw new o(`dvala.random.int: max (${a}) must be greater than min (${n})`,r);return{type:"Value",value:Math.floor(Math.random()*(a-n))+n,k:t}},arity:te(2),docs:{category:"effect",description:"Returns a random integer in the range [min, max).",returns:{type:"integer"},args:{min:{type:"integer",description:"Minimum value (inclusive)."},max:{type:"integer",description:"Maximum value (exclusive). Must be greater than min."}},variants:[{argumentNames:["min","max"]}],examples:["perform(effect(dvala.random.int), 1, 100)"],seeAlso:["-effect-dvala.random","-effect-dvala.random.item","perform","effect"]}},"dvala.random.item":{handler:(e,t,r)=>{const n=e[0];if(!Array.isArray(n))throw new o("dvala.random.item: argument must be an array, got "+typeof n,r);if(0===n.length)throw new o("dvala.random.item: cannot pick from an empty array",r);return{type:"Value",value:n[Math.floor(Math.random()*n.length)],k:t}},arity:te(1),docs:{category:"effect",description:"Picks a random element from a non-empty array.",returns:{type:"any"},args:{array:{type:"array",description:"Non-empty array to pick from."}},variants:[{argumentNames:["array"]}],examples:['perform(effect(dvala.random.item), ["a", "b", "c"])'],seeAlso:["-effect-dvala.random","-effect-dvala.random.shuffle","-effect-dvala.random.int","perform","effect"]}},"dvala.random.shuffle":{handler:(e,t,r)=>{const n=e[0];if(!Array.isArray(n))throw new o("dvala.random.shuffle: argument must be an array, got "+typeof n,r);const a=Array.from(n);for(let e=a.length-1;e>0;e--){const t=Math.floor(Math.random()*(e+1)),r=a[e];a[e]=a[t],a[t]=r}return{type:"Value",value:a,k:t}},arity:te(1),docs:{category:"effect",description:"Returns a new array with the elements of the input array in random order. Uses the Fisher-Yates shuffle algorithm.",returns:{type:"array"},args:{array:{type:"array",description:"Array to shuffle."}},variants:[{argumentNames:["array"]}],examples:["perform(effect(dvala.random.shuffle), [1, 2, 3, 4, 5])"],seeAlso:["-effect-dvala.random","-effect-dvala.random.item","perform","effect"]}},"dvala.time.now":{handler:(e,t)=>({type:"Value",value:Date.now(),k:t}),arity:te(0),docs:{category:"effect",description:"Returns the current timestamp in milliseconds since the Unix epoch. Equivalent to `Date.now()` in JavaScript.",returns:{type:"number"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.time.now))"],seeAlso:["-effect-dvala.time.zone","-effect-dvala.sleep","perform","effect"]}},"dvala.time.zone":{handler:(e,t)=>({type:"Value",value:Intl.DateTimeFormat().resolvedOptions().timeZone,k:t}),arity:te(0),docs:{category:"effect",description:'Returns the current IANA timezone string, e.g. `"Europe/Stockholm"` or `"America/New_York"`.',returns:{type:"string"},args:{},variants:[{argumentNames:[]}],examples:["perform(effect(dvala.time.zone))"],seeAlso:["-effect-dvala.time.now","perform","effect"]}},"dvala.checkpoint":{handler:(e,t)=>({type:"Value",value:null,k:t}),arity:{min:0,max:1},docs:{category:"effect",description:"Captures a snapshot of the current program state (continuation stack). The snapshot is stored in an in-memory list accessible via `ctx.snapshots` in host handlers. Optionally accepts a metadata value for domain context (e.g., step labels, timestamps). The standard fallback resumes with `null`, but host handlers can override the resume value. The snapshot is always captured regardless of whether a handler intercepts.",returns:{type:"null"},args:{meta:{type:"any",description:"Optional metadata to attach to the snapshot."}},variants:[{argumentNames:[]},{argumentNames:["meta"]}],examples:["perform(effect(dvala.checkpoint))",'perform(effect(dvala.checkpoint), { step: "analysis-done" })'],seeAlso:["perform","effect"]}},"dvala.sleep":{handler:(e,t,r)=>{const n=e[0];if("number"!=typeof n||n<0)throw new o(`dvala.sleep requires a non-negative number argument, got ${"number"==typeof n?n:typeof n}`,r);return new Promise(e=>{setTimeout(()=>e({type:"Value",value:null,k:t}),n)})},arity:te(1),docs:{category:"effect",description:"Waits for the specified number of milliseconds before resuming. Resumes with `null`. Only works in async execution (`run`) — `runSync` will throw when a Promise surfaces.",returns:{type:"null"},args:{ms:{type:"number",description:"The number of milliseconds to sleep. Must be a non-negative number."}},variants:[{argumentNames:["ms"]}],examples:["effect(dvala.sleep)"],seeAlso:["-effect-dvala.time.now","perform","effect"]}}};function ko(e){const t=xo[e];if(t)return(e,r,n)=>(ee(t.arity,e.length,n),t.handler(e,r,n))}function qo(e,t){switch(e[0]){case l.Number:case l.String:return e[1];case l.NormalBuiltinSymbol:case l.SpecialBuiltinSymbol:case l.UserDefinedSymbol:return t.evaluateSymbol(e);case l.ReservedSymbol:return jo(e);case l.NormalExpression:{const r=function(e,t){const r=e[2];return ft(function(e,t){const r=[],n=[],a=wt(e,(e,a)=>Fr(e)?ft(qo(e[1],t),t=>{if(!Array.isArray(t))throw new o(`Spread operator requires an array, got ${y(e)}`,e[2]);r.push(...t)}):e[0]!==l.ReservedSymbol||"_"!==e[1]?ft(qo(e,t),e=>{r.push(e)}):void n.push(a));return ft(a,()=>({params:r,placeholders:n}))}(e[1][1],t),({params:n,placeholders:a})=>{if(Ur(e)){const i=e[1][0];if(a.length>0){return ft(qo(i,t),e=>({[p]:!0,function:U(e,r),functionType:"Partial",params:n,placeholders:a,sourceCodeInfo:r,arity:te(a.length)}))}if(Vr(i)){const r=i[1],a=rr.allNormalExpressions[r];if(t.pure&&!1===a.pure)throw new o(`Cannot call impure function '${a.name}' in pure mode`,e[2]);return a.dvalaImpl?$o(a.dvalaImpl,n,t,e[2]):a.evaluate(n,e[2],t,{executeFunction:Ao})}{const o=t.getValue(i[1]);if(void 0!==o)return Ao(U(o,r),n,t,r);throw new s(i[1],e[2])}}return ft(qo(e[1][0],t),e=>{const o=U(e,r);if(a.length>0){return{[p]:!0,function:o,functionType:"Partial",params:n,placeholders:a,sourceCodeInfo:r,arity:te(a.length)}}return Ao(o,n,t,r)})})}(e,t);return ft(r,t=>{if("number"==typeof t&&Number.isNaN(t))throw new o("Number is NaN",e[2]);return ze(t)})}case l.SpecialExpression:{const r={type:"Eval",node:e,env:t,k:[]};try{return ze(ta(r))}catch(r){if(r instanceof o&&r.message.includes("Unexpected async operation")){return ra({type:"Eval",node:e,env:t,k:[]}).then(e=>ze(e))}throw r}}default:throw new o(`${u(e[0])}-node cannot be evaluated`,e[2])}}function Ao(e,t,r,n){if(q(e))return No(e,t,r,n);if(Array.isArray(e))return To(e,t,n);if(j(e))return Eo(e,t,n);if("string"==typeof e)return So(e,t,n);if(H(e))return zo(e,t,n);throw new o("Unexpected function type",n)}function No(e,t,r,n){switch(e.functionType){case"UserDefined":return $o(e,t,r,n);case"Partial":return function(e,t,r,n){const a=[...e.params];if(t.length!==e.placeholders.length)throw new o(`(partial) expects ${e.placeholders.length} arguments, got ${t.length}.`,n);const i=[...t];for(const t of e.placeholders)a.splice(t,0,i.shift());return Ao(e.function,a,r,n)}(e,t,r,n);case"Comp":return function(e,t,r,n){const{params:a}=e;if(0===a.length){if(1!==t.length)throw new o(`(comp) expects one argument, got ${y(t.length)}.`,n);return $(t[0],n)}let i=t;for(let e=a.length-1;e>=0;e--){const t=a[e];i=ft(i,e=>ft(Ao(U(t,n),e,r,n),e=>[e]))}return ft(i,e=>$(e[0],n))}(e,t,r,n);case"Constantly":return e.value;case"Juxt":return function(e,t,r,n){return function(e,t){const r=[];for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return yt(o,r,e,t,n);r.push(o)}return r}(e.params,e=>Ao(U(e,n),t,r,n))}(e,t,r,n);case"Complement":return ft(Ao(e.function,t,r,n),e=>!e);case"EveryPred":return function(e,t,r,n){const o=[];for(const a of e.params)for(const e of t)o.push(()=>Ao(U(a,n),[e],r,n));return vt(o,(e,t)=>!!e&&ft(t(),e=>!!e),!0)}(e,t,r,n);case"SomePred":return function(e,t,r,n){const o=[];for(const a of e.params)for(const e of t)o.push(()=>Ao(U(a,n),[e],r,n));return vt(o,(e,t)=>!!e||ft(t(),e=>!!e),!1)}(e,t,r,n);case"Fnull":return function(e,t,r,n){const o=t.map((t,r)=>null===t?le(e.params[r]):t);return Ao(U(e.function,n),o,r,n)}(e,t,r,n);case"EffectMatcher":return function(e,t,r){ee({min:1,max:1},t.length,e.sourceCodeInfo??r);const n=t[0];D(n,r);const o=n.name;if("string"===e.matchType)return Xn(o,e.pattern);const a=new RegExp(e.pattern,e.flags);return a.test(o)}(e,t,n);case"Builtin":{const a=rr.allNormalExpressions[e.normalBuiltinSymbolType];return a.dvalaImpl?$o(a.dvalaImpl,t,r,n):function(e,t,r,n){const a=w(rr.allNormalExpressions[e.normalBuiltinSymbolType],n);if(r.pure&&!1===a.pure)throw new o(`Cannot call impure function '${e.name}' in pure mode`,n);if(a.dvalaImpl)return $o(a.dvalaImpl,t,r,n);return a.evaluate(t,n,r,{executeFunction:Ao})}(e,t,r,n)}case"SpecialBuiltin":return function(e,t,r,n){const a=w(rr.specialExpressions[e.specialBuiltinSymbolType],n);if(a.evaluateAsNormalExpression)return a.evaluateAsNormalExpression(t,n,r,{executeFunction:Ao});throw new o(`Special builtin function ${e.specialBuiltinSymbolType} is not supported as normal expression.`,n)}(e,t,r,n);case"Module":return function(e,t,r,n){const a=r.getModule(e.moduleName);if(!a)throw new o(`Module '${e.moduleName}' not found.`,n);const i=a.functions[e.functionName];if(!i)throw new o(`Function '${e.functionName}' not found in module '${e.moduleName}'.`,n);if(r.pure&&!1===i.pure)throw new o(`Cannot call impure function '${e.functionName}' in pure mode`,n);if(ee(i.arity,t.length,n),i.dvalaImpl)return $o(i.dvalaImpl,t,r,n);return i.evaluate(t,n,r,{executeFunction:Ao})}(e,t,r,n)}}function $o(e,t,r,a){function i(t){if(!Q(e.arity,t.length))throw new o(`Expected ${e.arity} arguments, got ${t.length}.`,a);const s=e.evaluatedfunction,l=s[0],c=l.filter(e=>e[0]!==mt).length,u=r.create(e.evaluatedfunction[2]),m={self:{value:e}},p=[];let d,h;for(let e=0;e<t.length;e+=1)if(e<c){const r=e;d=ft(d,()=>{const e=le(t[r]);return ft(At(l[r],e,e=>qo(e,u.create(m))),e=>{Object.entries(e).forEach(([e,t])=>{m[e]={value:t}})})})}else p.push(le(t[e]));for(let e=t.length;e<c;e++){const t=e;h=ft(h,()=>{const e=l[t];return ft(qo(e[1][1],r.create(m)),t=>ft(At(e,t,e=>qo(e,r.create(m))),e=>{Object.entries(e).forEach(([e,t])=>{m[e]={value:t}})}))})}return ft(d,()=>ft(h,()=>{const e=l.find(e=>e[0]===mt),t=void 0!==e?ft(At(e,p,e=>qo(e,r.create(m))),e=>{Object.entries(e).forEach(([e,t])=>{m[e]={value:t}})}):void 0;return ft(t,()=>{const e=u.create(m),t=vt(s[1],(t,r)=>qo(r,e),null);return t instanceof Promise?t.catch(e=>{if(e instanceof n)return i(e.params);throw e}):t})}))}for(;;)try{return i(t)}catch(e){if(e instanceof n){t=e.params;continue}throw e}}function Eo(e,t,r){if(1!==t.length)throw new o("Object as function requires one string parameter.",r);const n=t[0];return G(n,r),le(e[n])}function To(e,t,r){if(1!==t.length)throw new o("Array as function requires one non negative integer parameter.",r);const n=t[0];return Y(n,r,{integer:!0,nonNegative:!0}),le(e[n])}function So(e,t,r){if(1!==t.length)throw new o("String as function requires one Obj parameter.",r);const n=le(t[0]);if(j(n))return le(n[e]);if(H(n,{integer:!0}))return le(e[n]);throw new o(`string as function expects Obj or integer parameter, got ${y(n)}`,r)}function zo(e,t,r){if(Y(e,void 0,{integer:!0}),1!==t.length)throw new o("Number as function requires one Arr parameter.",r);const n=t[0];return z(n,r),le(n[e])}function jo(e){const t=e[1];if(!["true","false","null"].includes(t))throw new o(`Reserved symbol ${t} cannot be evaluated`,e[2]);return w(gr[t],e[2])}function Co(e,t,r){switch(e[0]){case l.Number:case l.String:return{type:"Value",value:e[1],k:r};case l.NormalBuiltinSymbol:case l.SpecialBuiltinSymbol:case l.UserDefinedSymbol:return{type:"Value",value:t.evaluateSymbol(e),k:r};case l.ReservedSymbol:return{type:"Value",value:jo(e),k:r};case l.NormalExpression:return function(e,t,r){const n=e[1][1],o=e[2],a={type:"NanCheck",sourceCodeInfo:o},i={type:"EvalArgs",node:e,index:0,params:[],placeholders:[],env:t,sourceCodeInfo:o};let s=0;for(;s<n.length;){const e=n[s];if(e[0]!==l.ReservedSymbol||"_"!==e[1])break;i.placeholders.push(i.params.length),s++}if(i.index=s,s>=n.length)return Io(i,[a,...r]);const c=n[s],u=[i,a,...r];if(Fr(c))return{type:"Eval",node:c[1],env:t,k:u};return{type:"Eval",node:c,env:t,k:u}}(e,t,r);case l.SpecialExpression:return function(e,t,r){const n=e[2],a=e[1][0];switch(a){case tr.if:case tr.unless:{const[o,i,s]=e[1][1];return{type:"Eval",node:o,env:t,k:[{type:"IfBranch",thenNode:i,elseNode:s,inverted:a===tr.unless,env:t,sourceCodeInfo:n},...r]}}case tr["&&"]:{const o=e[1][1];if(0===o.length)return{type:"Value",value:!0,k:r};const a={type:"And",nodes:o,index:1,env:t,sourceCodeInfo:n};return 1===o.length?{type:"Eval",node:o[0],env:t,k:r}:{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr["||"]:{const o=e[1][1];if(0===o.length)return{type:"Value",value:!1,k:r};const a={type:"Or",nodes:o,index:1,env:t,sourceCodeInfo:n};return 1===o.length?{type:"Eval",node:o[0],env:t,k:r}:{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr["??"]:{const o=e[1][1];if(0===o.length)return{type:"Value",value:null,k:r};const a=o[0];if(Mr(a)&&null===t.lookUp(a)){if(1===o.length)return{type:"Value",value:null,k:r};const e={type:"Qq",nodes:o,index:2,env:t,sourceCodeInfo:n},a=o[1];return Mr(a)&&null===t.lookUp(a)?function(e,t){return Vo(e,t)}(e,r):2===o.length?{type:"Eval",node:a,env:t,k:r}:{type:"Eval",node:a,env:t,k:[e,...r]}}const i={type:"Qq",nodes:o,index:1,env:t,sourceCodeInfo:n};return 1===o.length?{type:"Eval",node:a,env:t,k:r}:{type:"Eval",node:a,env:t,k:[i,...r]}}case tr.cond:{const o=e[1][1];if(0===o.length)return{type:"Value",value:null,k:r};const a={type:"Cond",phase:"test",cases:o,index:0,env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0][0],env:t,k:[a,...r]}}case tr.match:{const o=e[1][1],a=e[1][2];return{type:"Eval",node:o,env:t,k:[{type:"Match",phase:"matchValue",matchValue:null,cases:a,index:0,bindings:{},env:t,sourceCodeInfo:n},...r]}}case tr.block:{const o=e[1][1],a=e[1][2],i={},s=t.create(i);let l=r;if(a&&a.length>0){l=[{type:"TryWith",handlers:a.map(([e,r])=>({effectRef:qo(e,t),handlerNode:r})),env:t,sourceCodeInfo:n},...r]}if(0===o.length)return{type:"Value",value:null,k:l};if(1===o.length)return{type:"Eval",node:o[0],env:s,k:l};const c={type:"Sequence",nodes:o,index:1,env:s,sourceCodeInfo:n};return{type:"Eval",node:o[0],env:s,k:[c,...l]}}case tr.let:{const o=e[1][1],a=o[1][0];return{type:"Eval",node:o[1][1],env:t,k:[{type:"LetBind",target:a,env:t,sourceCodeInfo:n},...r]}}case tr.loop:{const o=e[1][1],a=e[1][2];if(0===o.length){const e={},i={type:"LoopIterate",bindingNodes:o,bindingContext:e,body:a,env:t.create(e),sourceCodeInfo:n};return{type:"Eval",node:a,env:t.create(e),k:[i,...r]}}const i={type:"LoopBind",phase:"value",bindingNodes:o,index:0,context:{},body:a,env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0][1][1],env:t,k:[i,...r]}}case tr.for:case tr.doseq:{const o=e[1][1],i=e[1][2],s=a===tr.for;if(0===o.length)return{type:"Value",value:s?[]:null,k:r};const l={},c=t.create(l),u={type:"ForLoop",returnResult:s,bindingNodes:o,body:i,result:[],phase:"evalCollection",bindingLevel:0,levelStates:[],context:l,env:c,sourceCodeInfo:n};return{type:"Eval",node:o[0][0][1][1],env:c,k:[u,...r]}}case tr.recur:{const o=e[1][1];if(0===o.length)return Lo([],r,n);const a={type:"Recur",nodes:o,index:1,params:[],env:t,sourceCodeInfo:n};if(1===o.length){const e={...a,index:1};return{type:"Eval",node:o[0],env:t,k:[e,...r]}}return{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr.array:{const o=e[1][1];if(0===o.length)return{type:"Value",value:[],k:r};const a=o[0],i=Fr(a),s={type:"ArrayBuild",nodes:o,index:0,result:[],isSpread:i,env:t,sourceCodeInfo:n};return{type:"Eval",node:i?a[1]:a,env:t,k:[s,...r]}}case tr.object:{const o=e[1][1];if(0===o.length)return{type:"Value",value:{},k:r};const a=o[0],i=Fr(a),s={type:"ObjectBuild",nodes:o,index:0,result:{},currentKey:null,isSpread:i,env:t,sourceCodeInfo:n};return{type:"Eval",node:i?a[1]:a,env:t,k:[s,...r]}}case tr["0_lambda"]:{const n=function(e,t){const r={},n=e[0].reduce((e,t)=>(Object.keys($t(t)).forEach(t=>{e[t]={value:null}}),e),{});return _r(e[1],t.new(n),rr,qo).forEach(e=>{const n=t.getValue(e);N(n)&&(r[e]={value:n})}),[e[0],e[1],r]}(e[1][1],t),o=n[0].filter(e=>e[0]!==mt&&void 0===e[1][1]).length,a={min:o>0?o:void 0,max:n[0].some(e=>e[0]===mt)?void 0:n[0].length};return{type:"Value",value:{[p]:!0,sourceCodeInfo:e[2],functionType:"UserDefined",name:void 0,evaluatedfunction:n,arity:a,docString:""},k:r}}case tr["defined?"]:{const n=e[1][1];if(!Mr(n))return{type:"Value",value:!0,k:r};return{type:"Value",value:null!==t.lookUp(n),k:r}}case tr.import:{const a=e[1][1],i=t.getValueModule(a);if(i.found)return{type:"Value",value:i.value,k:r};const s=t.getModule(a);if(!s)throw new o(`Unknown module: '${a}'`,n);const l={};for(const[e,t]of Object.entries(s.functions))l[e]={[p]:!0,sourceCodeInfo:n,functionType:"Module",moduleName:a,functionName:e,arity:t.arity};if(s.source){const e=Hn(Yn(jr(s.source,!1,void 0),{removeWhiteSpace:!0})),o=t.create({}),i={type:"ImportMerge",tsFunctions:l,moduleName:a,module:s,env:t,sourceCodeInfo:n};if(1===e.length)return{type:"Eval",node:e[0],env:o,k:[i,...r]};const c={type:"Sequence",nodes:e,index:1,env:o};return{type:"Eval",node:e[0],env:o,k:[c,i,...r]}}return t.registerValueModule(a,l),{type:"Value",value:l,k:r}}case tr.effect:return{type:"Value",value:oo(e[1][1]),k:r};case tr.perform:{const o=[e[1][1],...e[1][2]];if(1===o.length){const e={type:"PerformArgs",argNodes:o,index:1,params:[],env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0],env:t,k:[e,...r]}}const a={type:"PerformArgs",argNodes:o,index:1,params:[],env:t,sourceCodeInfo:n};return{type:"Eval",node:o[0],env:t,k:[a,...r]}}case tr.parallel:return{type:"Parallel",branches:e[1][1],env:t,k:r};case tr.race:return{type:"Race",branches:e[1][1],env:t,k:r};default:throw new o(`Unknown special expression type: ${a}`,n)}}(e,t,r);default:throw new o(`${u(e[0])}-node cannot be evaluated`,e[2])}}function Io(e,t){const{node:r,params:n,placeholders:a,env:i,sourceCodeInfo:l}=e;if(Ur(r)){const e=r[1][0];if(a.length>0){const r=i.evaluateSymbol(e);return{type:"Value",value:{[p]:!0,function:U(r,l),functionType:"Partial",params:n,placeholders:a,sourceCodeInfo:l,arity:te(a.length)},k:t}}if(Vr(e)){const r=e[1],a=rr.allNormalExpressions[r];if(i.pure&&!1===a.pure)throw new o(`Cannot call impure function '${a.name}' in pure mode`,l);if(a.dvalaImpl)return Po(a.dvalaImpl,n,i,l,t);return Zo(a.evaluate(n,l,i,{executeFunction:Ao}),t)}const c=i.getValue(e[1]);if(void 0!==c)return Ro(U(c,l),n,a,i,l,t);throw new s(e[1],l)}return{type:"Eval",node:r[1][0],env:i,k:[{type:"CallFn",params:n,placeholders:a,env:i,sourceCodeInfo:l},...t]}}function Ro(e,t,r,n,a,i){if(r.length>0){return{type:"Value",value:{[p]:!0,function:e,functionType:"Partial",params:t,placeholders:r,sourceCodeInfo:a,arity:te(r.length)},k:i}}if(q(e))return function(e,t,r,n,o){switch(e.functionType){case"UserDefined":return Po(e,t,r,n,o);case"Partial":case"Comp":case"Constantly":case"Juxt":case"Complement":case"EveryPred":case"SomePred":case"Fnull":case"EffectMatcher":case"SpecialBuiltin":return Zo(No(e,t,r,n),o);case"Module":{const a=r.getModule(e.moduleName),i=a?.functions[e.functionName];if(i?.dvalaImpl)return ee(i.arity,t.length,n),Po(i.dvalaImpl,t,r,n,o);return Zo(No(e,t,r,n),o)}case"Builtin":{const a=rr.allNormalExpressions[e.normalBuiltinSymbolType];if(a.dvalaImpl)return Po(a.dvalaImpl,t,r,n,o);return Zo(No(e,t,r,n),o)}}}(e,t,n,a,i);if(Array.isArray(e))return{type:"Value",value:To(e,t,a),k:i};if(j(e))return{type:"Value",value:Eo(e,t,a),k:i};if("string"==typeof e)return{type:"Value",value:So(e,t,a),k:i};if(H(e))return{type:"Value",value:zo(e,t,a),k:i};throw new o("Unexpected function type",a)}function Po(e,t,r,n,a){if(!Q(e.arity,t.length))throw new o(`Expected ${e.arity} arguments, got ${t.length}.`,n);const i=e.evaluatedfunction,s=i[0],l=s.filter(e=>e[0]!==mt).length,c=r.create(e.evaluatedfunction[2]),u={self:{value:e}},m=[];for(let o=0;o<t.length;o+=1)if(o<l){const i=le(t[o]),l=At(s[o],i,e=>qo(e,c.create(u)));if(l instanceof Promise){return Zo($o(e,t,r,n),a)}Object.entries(l).forEach(([e,t])=>{u[e]={value:t}})}else m.push(le(t[o]));for(let o=t.length;o<l;o++){const i=s[o],l=qo(i[1][1],c.create(u));if(l instanceof Promise){return Zo($o(e,t,r,n),a)}const m=At(i,l,e=>qo(e,c.create(u)));if(m instanceof Promise){return Zo($o(e,t,r,n),a)}Object.entries(m).forEach(([e,t])=>{u[e]={value:t}})}const p=s.find(e=>e[0]===mt);if(p){const o=At(p,m,e=>qo(e,c.create(u)));if(o instanceof Promise){return Zo($o(e,t,r,n),a)}Object.entries(o).forEach(([e,t])=>{u[e]={value:t}})}const d=i[1],h=c.create(u);if(0===d.length)return{type:"Value",value:null,k:a};const g={type:"FnBody",fn:e,bodyIndex:1,env:h,outerEnv:r,sourceCodeInfo:n};return d.length,{type:"Eval",node:d[0],env:h,k:[g,...a]}}function Mo(e,t,r){switch(e.type){case"Sequence":return function(e,t,r){const{nodes:n,index:o,env:a}=e;if(o>=n.length)return{type:"Value",value:t,k:r};const i={...e,index:o+1};if(o===n.length-1)return{type:"Eval",node:n[o],env:a,k:r};return{type:"Eval",node:n[o],env:a,k:[i,...r]}}(e,t,r);case"IfBranch":return function(e,t,r){const{thenNode:n,elseNode:o,inverted:a,env:i}=e,s=a?!t:t;if(s)return{type:"Eval",node:n,env:i,k:r};if(o)return{type:"Eval",node:o,env:i,k:r};return{type:"Value",value:null,k:r}}(e,t,r);case"Cond":return function(e,t,r){const{cases:n,index:o,env:a}=e;if("test"===e.phase){if(t)return{type:"Eval",node:n[o][1],env:a,k:r};const i=o+1;if(i>=n.length)return{type:"Value",value:null,k:r};const s={...e,index:i};return{type:"Eval",node:n[i][0],env:a,k:[s,...r]}}return{type:"Value",value:t,k:r}}(e,t,r);case"Match":return function(e,t,r){const{cases:n,env:o}=e;if("matchValue"===e.phase){const n=t;return Oo({...e,matchValue:n,phase:"guard"},r)}if("guard"===e.phase){if(!t){return Oo({...e,index:e.index+1,bindings:{}},r)}const a={};for(const[t,r]of Object.entries(e.bindings))a[t]={value:r};const i=o.create(a);return{type:"Eval",node:n[e.index][1],env:i,k:r}}return{type:"Value",value:t,k:r}}(e,t,r);case"And":return function(e,t,r){if(!t)return{type:"Value",value:t,k:r};const{nodes:n,index:o,env:a}=e;if(o>=n.length)return{type:"Value",value:t,k:r};if(o===n.length-1)return{type:"Eval",node:n[o],env:a,k:r};const i={...e,index:o+1};return{type:"Eval",node:n[o],env:a,k:[i,...r]}}(e,t,r);case"Or":return function(e,t,r){if(t)return{type:"Value",value:t,k:r};const{nodes:n,index:o,env:a}=e;if(o>=n.length)return{type:"Value",value:t,k:r};if(o===n.length-1)return{type:"Eval",node:n[o],env:a,k:r};const i={...e,index:o+1};return{type:"Eval",node:n[o],env:a,k:[i,...r]}}(e,t,r);case"Qq":return function(e,t,r){if(null!==t)return{type:"Value",value:t,k:r};return Vo(e,r)}(e,t,r);case"ArrayBuild":return function(e,t,r){const{nodes:n,result:a,env:i,sourceCodeInfo:s}=e;if(e.isSpread){if(!Array.isArray(t))throw new o("Spread value is not an array",s);a.push(...t)}else a.push(t);const l=e.index+1;if(l>=n.length)return{type:"Value",value:a,k:r};const c=n[l],u=Fr(c),m={...e,index:l,isSpread:u};return{type:"Eval",node:u?c[1]:c,env:i,k:[m,...r]}}(e,t,r);case"ObjectBuild":return function(e,t,r){const{nodes:n,result:a,env:i,sourceCodeInfo:s}=e;if(e.isSpread){if(!k(t))throw new o("Spread value is not an object",s);Object.assign(a,t);const l=e.index+1;if(l>=n.length)return{type:"Value",value:a,k:r};const c=n[l],u=Fr(c),m={...e,index:l,currentKey:null,isSpread:u};return{type:"Eval",node:u?c[1]:c,env:i,k:[m,...r]}}if(null===e.currentKey){G(t,s);const a=n[e.index+1];if(void 0===a)throw new o("Missing value for key",s);return{type:"Eval",node:a,env:i,k:[{...e,currentKey:t},...r]}}{a[e.currentKey]=t;const o=e.index+2;if(o>=n.length)return{type:"Value",value:a,k:r};const s=n[o],l=Fr(s),c={...e,index:o,currentKey:null,isSpread:l};return{type:"Eval",node:l?s[1]:s,env:i,k:[c,...r]}}}(e,t,r);case"LetBind":return function(e,t,r){const{target:n,env:o,sourceCodeInfo:a}=e,i=At(n,t,e=>qo(e,o));return ft(i,e=>(o.addValues(e,a),{type:"Value",value:t,k:r}))}(e,t,r);case"LoopBind":return function(e,t,r){const{bindingNodes:n,index:o,context:a,body:i,env:s,sourceCodeInfo:l}=e,c=n[o],u=At(c[1][0],t,e=>qo(e,s.create(a)));return ft(u,t=>{Object.entries(t).forEach(([e,t])=>{a[e]={value:t}});const c=o+1;if(c>=n.length){const e=s.create(a);return{type:"Eval",node:i,env:e,k:[{type:"LoopIterate",bindingNodes:n,bindingContext:a,body:i,env:e,sourceCodeInfo:l},...r]}}const u={...e,index:c};return{type:"Eval",node:n[c][1][1],env:s.create(a),k:[u,...r]}})}(e,t,r);case"LoopIterate":return function(e,t,r){return{type:"Value",value:t,k:r}}(0,t,r);case"ForLoop":return function(e,t,r){const{returnResult:n,bindingNodes:a,result:i,env:s,sourceCodeInfo:l,context:c}=e,{asColl:u,isSeq:m}={asColl:(e,t)=>{if("string"==typeof e||Array.isArray(e)||j(e))return e;throw new o(`Expected collection, got ${y(e)}`,t)},isSeq:e=>"string"==typeof e||Array.isArray(e)};switch(e.phase){case"evalCollection":{const n=u(t,l),o=m(n)?n:Object.entries(n);if(0===o.length)return Do(e,r);const i=[...e.levelStates];i[e.bindingLevel]={collection:o,index:0};const p=a[e.bindingLevel];return ft(At(p[0][1][0],$(o[0],l),e=>qo(e,s)),t=>{Object.entries(t).forEach(([e,t])=>{c[e]={value:t}});const n=p[1];return n.length>0?Fo(e,i,n,0,r):Wo(e,i,r)})}case"evalLet":throw new o("ForLoop evalLet should not reach applyFrame",l);case"evalWhen":{if(!t)return Uo(e,r);const n=a[e.bindingLevel][3];if(n){const t={...e,phase:"evalWhile"};return{type:"Eval",node:n,env:s,k:[t,...r]}}return Go(e,r)}case"evalWhile":if(!t){const t=[...e.levelStates];return t[e.bindingLevel]={...t[e.bindingLevel],index:Number.POSITIVE_INFINITY},Uo({...e,levelStates:t},r)}return Go(e,r);case"evalBody":return n&&i.push(t),Uo(e,r);case"evalElement":throw new o(`Unexpected ForLoop phase: ${e.phase}`,l)}return{type:"Value",value:null,k:r}}(e,t,r);case"Recur":return function(e,t,r){const{nodes:n,index:o,params:a,env:i}=e;if(a.push(t),o>=n.length)return Lo(a,r,e.sourceCodeInfo);const s={...e,index:o+1};return{type:"Eval",node:n[o],env:i,k:[s,...r]}}(e,t,r);case"PerformArgs":return function(e,t,r){const{argNodes:n,index:o,params:a,env:i}=e;if(a.push(t),o>=n.length){const t=a[0];D(t,e.sourceCodeInfo);return{type:"Perform",effect:t,args:a.slice(1),k:r,sourceCodeInfo:e.sourceCodeInfo}}const s={...e,index:o+1};return{type:"Eval",node:n[o],env:i,k:[s,...r]}}(e,t,r);case"TryWith":return function(e,t){return{type:"Value",value:e,k:t}}(t,r);case"EffectResume":return function(e,t){return{type:"Value",value:t,k:e.resumeK}}(e,t);case"ParallelResume":return function(e,t,r){return{type:"ParallelResume",value:t,branchCount:e.branchCount,completedBranches:e.completedBranches,suspendedBranches:e.suspendedBranches,k:r}}(e,t,r);case"EvalArgs":return function(e,t,r){const{node:n,params:a,placeholders:i,env:s}=e,c=n[1][1],u=c[e.index];if(Fr(u)){if(!Array.isArray(t))throw new o(`Spread operator requires an array, got ${y(t)}`,u[2]);a.push(...t)}else a.push(t);let m=e.index+1;for(;m<c.length;){const e=c[m];if(e[0]!==l.ReservedSymbol||"_"!==e[1])break;i.push(a.length),m++}if(m>=c.length)return Io({...e,index:m},r);const p={...e,index:m},d=c[m];if(Fr(d))return{type:"Eval",node:d[1],env:s,k:[p,...r]};return{type:"Eval",node:d,env:s,k:[p,...r]}}(e,t,r);case"CallFn":return function(e,t,r){const n=U(t,e.sourceCodeInfo);return Ro(n,e.params,e.placeholders,e.env,e.sourceCodeInfo,r)}(e,t,r);case"FnBody":return function(e,t,r){const{fn:n,bodyIndex:o,env:a}=e,i=n.evaluatedfunction[1];if(o>=i.length)return{type:"Value",value:t,k:r};const s={...e,bodyIndex:o+1};return{type:"Eval",node:i[o],env:a,k:[s,...r]}}(e,t,r);case"BindingDefault":return function(e,t,r){const{target:n,record:a,env:i,sourceCodeInfo:s}=e,l=At(n,t,e=>qo(e,i));if(l instanceof Promise)throw new o("Async binding default evaluation not supported in trampoline yet",s);return Object.assign(a,l),{type:"Value",value:t,k:r}}(e,t,r);case"NanCheck":return function(e,t,r){if("number"==typeof t&&Number.isNaN(t))throw new o("Number is NaN",e.sourceCodeInfo);return{type:"Value",value:ze(t),k:r}}(e,t,r);case"DebugStep":return function(e,t,r){if("awaitValue"===e.phase){const n={expression:e.sourceCodeInfo?.code??"",value:t,location:e.sourceCodeInfo?{line:e.sourceCodeInfo.position.line,column:e.sourceCodeInfo.position.column}:{line:0,column:0},env:Qo(e.env)},o={type:"DebugStep",phase:"awaitPerform",sourceCodeInfo:e.sourceCodeInfo,env:e.env};return{type:"Perform",effect:oo("dvala.debug.step"),args:[n],k:[o,...r]}}return{type:"Value",value:t,k:r}}(e,t,r);case"ImportMerge":{const n=j(t)?t:{};for(const[t,r]of Object.entries(n)){const n=e.module.functions[t];n&&A(r)&&(n.dvalaImpl=r)}const o={};for(const[t,r]of Object.entries(n))e.module.functions[t]||(o[t]=r);const a={...e.tsFunctions,...o};return e.env.registerValueModule(e.moduleName,a),{type:"Value",value:a,k:r}}default:throw new o(`Unhandled frame type: ${e.type}`,void 0)}}function Oo(e,t){const{matchValue:r,cases:n,index:a,env:i,sourceCodeInfo:s}=e;for(let l=a;l<n.length;l++){const[a,c,u]=n[l],m=Tt(a,r,e=>qo(e,i));if(m instanceof Promise)throw new o("Async pattern matching not supported in trampoline yet",s);if(null===m)continue;if(u){const r={};for(const[e,t]of Object.entries(m))r[e]={value:t};return{type:"Eval",node:u,env:i.create(r),k:[{...e,phase:"guard",index:l,bindings:m},...t]}}const p={};for(const[e,t]of Object.entries(m))p[e]={value:t};return{type:"Eval",node:c,env:i.create(p),k:t}}return{type:"Value",value:null,k:t}}function Vo(e,t){const{nodes:r,env:n}=e;let{index:o}=e;for(;o<r.length;){const e=r[o];if(!Mr(e)||null!==n.lookUp(e))break;o++}if(o>=r.length)return{type:"Value",value:null,k:t};if(o===r.length-1)return{type:"Eval",node:r[o],env:n,k:t};const a={...e,index:o+1};return{type:"Eval",node:r[o],env:n,k:[a,...t]}}function Do(e,t){return{type:"Value",value:e.returnResult?e.result:null,k:t}}function Uo(e,t){const{bindingNodes:r,env:n,sourceCodeInfo:o,context:a}=e,i=[...e.levelStates],s=e.bindingLevel,l=i[s],c=l.index+1;if(c>=l.collection.length)return 0===s?Do(e,t):Uo({...e,bindingLevel:s-1},t);i[s]={...l,index:c};const u=r[s];return ft(At(u[0][1][0],$(l.collection[c],o),e=>qo(e,n)),r=>{Object.entries(r).forEach(([e,t])=>{a[e]={value:t}});const n=u[1];return n.length>0?Fo({...e,levelStates:i,bindingLevel:s},i,n,0,t):Wo({...e,levelStates:i,bindingLevel:s},i,t)})}function Fo(e,t,r,n,o){const{env:a,context:i}=e;let s;for(let e=n;e<r.length;e++){const t=e;s=ft(s,()=>{const e=r[t],[n,o]=e[1];return ft(qo(o,a),e=>ft(At(n,e,e=>qo(e,a)),e=>{Object.entries(e).forEach(([e,t])=>{i[e]={value:t}})}))})}return ft(s,()=>Wo({...e,levelStates:t},t,o))}function Wo(e,t,r){const{bindingNodes:n,env:o}=e,a=n[e.bindingLevel],i=a[2],s=a[3];if(i){return{type:"Eval",node:i,env:o,k:[{...e,levelStates:t,phase:"evalWhen"},...r]}}if(s){return{type:"Eval",node:s,env:o,k:[{...e,levelStates:t,phase:"evalWhile"},...r]}}return Go({...e,levelStates:t},r)}function Go(e,t){const{bindingNodes:r,body:n,env:o}=e,a=e.bindingLevel+1;if(a<r.length){return{type:"Eval",node:r[a][0][1][1],env:o,k:[{...e,phase:"evalCollection",bindingLevel:a},...t]}}const i={...e,phase:"evalBody"};return{type:"Eval",node:n,env:o.create(e.context),k:[i,...t]}}function Bo(e,t,r,n,o){const a=oo("dvala.error"),i=[e.shortMessage];for(let r=0;r<t.length;r++){const n=t[r];if("TryWith"===n.type)for(const o of n.handlers)if(_o(o,a,n.env,e.sourceCodeInfo))return Ko(o,n,i,t,r,e.sourceCodeInfo)}const s=Qn("dvala.error",r);return s.length>0?Jo("dvala.error",s,i,t,n,e.sourceCodeInfo,o):null}function Lo(e,t,r){for(let n=0;n<t.length;n++){const a=t[n];if("LoopIterate"===a.type){const{bindingNodes:i,bindingContext:s,body:l,env:c}=a,u=t.slice(n+1);if(e.length!==i.length)throw new o(`recur expected ${i.length} parameters, got ${e.length}`,r);const m=wt(i,(t,r)=>ft(At(t[1][0],le(e[r]),e=>qo(e,c)),e=>{Object.entries(e).forEach(([e,t])=>{s[e]={value:t}})}));return ft(m,()=>{const e=c.getContextsRaw()[0];if(e!==s)for(const[t,r]of Object.entries(s))e[t]=r;const t={type:"LoopIterate",bindingNodes:i,bindingContext:s,body:l,env:c,sourceCodeInfo:a.sourceCodeInfo};return{type:"Eval",node:l,env:c,k:[t,...u]}})}if("FnBody"===a.type){const{fn:r,outerEnv:o}=a,i=t.slice(n+1);return Po(r,e,o,a.sourceCodeInfo,i)}}throw new o("recur called outside of loop or function body",r)}function _o(e,t,r,n){if(V(e.effectRef))return e.effectRef.name===t.name;if(q(e.effectRef)){const a=Ao(e.effectRef,[t],r,n);if(a instanceof Promise)throw new o("Effect handler predicates must be synchronous",n);return!!a}return!1}function Ko(e,t,r,n,o,a){const i=[{type:"EffectResume",resumeK:n,sourceCodeInfo:a},...n.slice(o+1)];return Ro(U(qo(e.handlerNode,t.env),t.sourceCodeInfo),[r],[],t.env,a,i)}function Jo(e,t,r,n,i,s,l){const c=i??(new AbortController).signal,u=Array.from(r);function m(e,t){switch(e.kind){case"step":return e.step;case"asyncResume":return e.promise.then(e=>({type:"Value",value:e,k:n}),e=>({type:"Error",error:e instanceof o?e:new o(e instanceof Error?e:`${e}`,s),k:n}));case"throw":throw e.error;case"next":return p(t)}}function p(i){if(i>=t.length){if("dvala.error"===e){const e="string"==typeof u[0]?u[0]:String(u[0]??"Unknown error");throw new a(e,s)}if("dvala.checkpoint"===e)return{type:"Value",value:null,k:n};throw new o(`Unhandled effect: '${e}'`,s)}const[p,d]=t[i];if("*"===p){const t=ko(e);if(t)return t(r,n,s)}let h,g=!1;function f(e){if(g)throw new o(`Effect handler called ${e}() after already calling another operation`,s);g=!0}const y=d({effectName:e,args:u,signal:c,resume:e=>{f("resume"),h=e instanceof Promise?{kind:"asyncResume",promise:e}:{kind:"step",step:{type:"Value",value:e,k:n}}},fail:t=>{f("fail");h={kind:"step",step:{type:"Error",error:new o(t??`Effect handler failed for '${e}'`,s),k:n}}},suspend:t=>{f("suspend"),h={kind:"throw",error:new Zn(n,l?l.snapshots:[],l?l.nextSnapshotIndex:0,t,e,u)}},next:()=>{f("next"),h={kind:"next"}},get snapshots(){return l?[...l.snapshots]:[]},checkpoint:e=>{if(!l)throw new o("checkpoint is not available outside effect-enabled execution",s);const t={continuation:go(n),timestamp:Date.now(),index:l.nextSnapshotIndex++,runId:l.runId,...void 0!==e?{meta:e}:{}};return l.snapshots.push(t),void 0!==l.maxSnapshots&&l.snapshots.length>l.maxSnapshots&&l.snapshots.shift(),t},resumeFrom:(e,t)=>{if(g)throw new o("Effect handler called resumeFrom() after already calling another operation",s);if(!l)throw new o("resumeFrom is not available outside effect-enabled execution",s);const r=l.snapshots.find(t=>t.index===e.index&&t.runId===e.runId);if(!r)throw new o(`Invalid snapshot: no snapshot with index ${e.index} found in current run`,s);g=!0,h={kind:"throw",error:new to(r.continuation,t,r.index)}}});if(!(y instanceof Promise)){if(!h)throw new o(`Effect handler for '${e}' did not call resume(), fail(), suspend(), or next()`,s);return m(h,i+1)}return h?(y.catch(()=>{}),m(h,i+1)):y.then(()=>{if(!h)throw new o(`Effect handler for '${e}' did not call resume(), fail(), suspend(), or next()`,s);return m(h,i+1)},e=>{if(h)return m(h,i+1);if(eo(e)||ro(e))throw e;return{type:"Error",error:e instanceof o?e:new o(e instanceof Error?e:`${e}`,s),k:n}})}return c.aborted&&Ho(n,void 0,e,u),p(0)}function Ho(e,t,r,n){throw new Zn(e,[],0,t,r,n)}async function Yo(e,t,r,n){return ia({type:"Eval",node:e,env:t,k:[]},r,n)}async function Xo(e,t,r,n,a){const i=new AbortController,s=a?function(e,t){const r=new AbortController;return e.aborted||t.aborted?(r.abort(),r.signal):(e.addEventListener("abort",()=>r.abort(),{once:!0}),t.addEventListener("abort",()=>r.abort(),{once:!0}),r.signal)}(a,i.signal):i.signal,l=e.map(async(e,r)=>{const o=await Yo(e,t,n,s);return"suspended"===o.type&&i.abort(),{index:r,result:o}}),c=await Promise.allSettled(l),u=[],m=[],p=[];for(const e of c)if("rejected"===e.status)p.push(new o(`${e.reason}`,void 0));else{const{index:t,result:r}=e.value;switch(r.type){case"completed":u.push({index:t,value:r.value});break;case"suspended":m.push({index:t,snapshot:r.snapshot});break;case"error":p.push(r.error)}}if(p.length>0)throw p[0];if(m.length>0){const t=[{type:"ParallelResume",branchCount:e.length,completedBranches:u,suspendedBranches:m.slice(1)},...r],n=m[0];return Ho(t,n.snapshot.meta,n.snapshot.effectName,n.snapshot.effectArgs)}const d=Array.from({length:e.length});for(const{index:e,value:t}of u)d[e]=t;return{type:"Value",value:d,k:r}}function Qo(e){const t={},r=e.getHostValues();if(r)for(const[e,n]of Object.entries(r))t[e]=n;const n=e.getContextsRaw();for(let e=n.length-1;e>=0;e--)for(const[r,o]of Object.entries(n[e]))t[r]=o.value;return t}function Zo(e,t){return e instanceof Promise?e.then(e=>({type:"Value",value:e,k:t}),e=>({type:"Error",error:e instanceof o?e:new o(`${e}`,void 0),k:t})):{type:"Value",value:e,k:t}}function ea(e,t,r,n){try{switch(e.type){case"Value":{if(0===e.k.length)return e;const[t,...r]=e.k;return Mo(t,e.value,r)}case"Eval":return Co(e.node,e.env,e.k);case"Apply":return Mo(e.frame,e.value,e.k);case"Perform":return function(e,t,r,n,i,s,l){if("dvala.checkpoint"===e.name&&l){const e=t[0],n={continuation:go(r),timestamp:Date.now(),index:l.nextSnapshotIndex++,runId:l.runId,...void 0!==e?{meta:e}:{}};l.snapshots.push(n),void 0!==l.maxSnapshots&&l.snapshots.length>l.maxSnapshots&&l.snapshots.shift()}for(let o=0;o<r.length;o++){const a=r[o];if("TryWith"===a.type)for(const i of a.handlers)if(_o(i,e,a.env,n))return Ko(i,a,t,r,o,n)}const c=Qn(e.name,i);if(c.length>0)return Jo(e.name,c,t,r,s,n,l);const u=ko(e.name);if(u)return u(t,r,n);if("dvala.error"===e.name){const e="string"==typeof t[0]?t[0]:String(t[0]??"Unknown error");throw new a(e,n)}throw new o(`Unhandled effect: '${e.name}'`,n)}(e.effect,e.args,e.k,e.sourceCodeInfo,t,r,n);case"Parallel":return Xo(e.branches,e.env,e.k,t,r);case"Race":return async function(e,t,r,n,a){const i=a??(new AbortController).signal,s=e.map(()=>new AbortController),l=()=>{for(const e of s)e.abort(i.reason)};i.addEventListener("abort",l,{once:!0});try{let a=-1,i=null;const l=e.map(async(e,r)=>{const o=s[r].signal,l=await Yo(e,t,n,o);if("completed"===l.type&&a<0){a=r,i=l.value;for(let e=0;e<s.length;e++)e!==r&&s[e].abort("race: branch lost")}return l}),c=await Promise.allSettled(l);if(a>=0)return{type:"Value",value:i,k:r};const u=[],m=[];for(let e=0;e<c.length;e++){const t=c[e];if("rejected"===t.status)m.push(new o(`${t.reason}`,void 0));else{const e=t.value;switch(e.type){case"suspended":u.push(e.snapshot.meta??null);break;case"error":m.push(e.error)}}}u.length>0&&Ho(r,{type:"race",branches:u});const p=m.map(e=>e.message).join("; ");throw new o(`race: all branches failed: ${p}`,void 0)}finally{i.removeEventListener("abort",l)}}(e.branches,e.env,e.k,t,r);case"ParallelResume":return function(e){const{value:t,branchCount:r,completedBranches:n,suspendedBranches:o,k:a}=e,i=new Set(n.map(e=>e.index)),s=new Set(o.map(e=>e.index));let l=-1;for(let e=0;e<r;e++)if(!i.has(e)&&!s.has(e)){l=e;break}const c=[...n,{index:l,value:t}];if(o.length>0){const e=o[0];return Ho([{type:"ParallelResume",branchCount:r,completedBranches:c,suspendedBranches:o.slice(1)},...a],e.snapshot.meta,e.snapshot.effectName,e.snapshot.effectArgs)}const u=Array.from({length:r});for(const{index:e,value:t}of c)u[e]=t;return{type:"Value",value:u,k:a}}(e);case"Error":{const o=Bo(e.error,e.k,t,r,n);if(null!==o)return o;throw e.error}}}catch(a){if(eo(a))throw a;if(a instanceof o){const o=Bo(a,"Value"===e.type?e.k.slice(1):e.k,t,r,n);if(null!==o)return o}throw a}}function ta(e,t){let r=e;for(;;){if(r instanceof Promise)throw new o("Unexpected async operation in synchronous context. Use async.run() for async operations.",void 0);if("Value"===r.type&&0===r.k.length)return r.value;r=ea(r,t)}}async function ra(e){let t=e;for(;;){if(t instanceof Promise&&(t=await t),"Value"===t.type&&0===t.k.length)return t.value;t=ea(t)}}function na(e,t){if(0===e.length)return{type:"Value",value:null,k:[]};if(1===e.length)return{type:"Eval",node:e[0],env:t,k:[]};const r={type:"Sequence",nodes:e,index:1,env:t};return{type:"Eval",node:e[0],env:t,k:[r]}}function oa(e,t){const r=na(e.body,t);try{return ta(r)}catch(r){if(r instanceof o&&r.message.includes("Unexpected async operation")){return ra(na(e.body,t))}throw r}}function aa(e,t){const r={type:"Eval",node:e,env:t,k:[]};try{return ta(r)}catch(r){if(r instanceof o&&r.message.includes("Unexpected async operation")){return ra({type:"Eval",node:e,env:t,k:[]})}throw r}}async function ia(e,t,r,n,a,i){const s=null!=t&&"dvala.debug.step"in t,c={snapshots:[],nextSnapshotIndex:0,runId:"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),...void 0!==a?{maxSnapshots:a}:{}};let u=e;for(;;)try{for(;;){if(u instanceof Promise&&(u=await u),"Value"===u.type&&0===u.k.length)return{type:"completed",value:u.value};if(s&&"Eval"===u.type&&u.node[2]){const e=u.node[0];if(e===l.NormalExpression||e===l.SpecialExpression){const e={type:"DebugStep",phase:"awaitValue",sourceCodeInfo:u.node[2],env:u.env};u={...u,k:[e,...u.k]}}}u=ea(u,t,r,c)}}catch(e){if(ro(e)){const{k:t}=yo(e.continuation,i),r=c.snapshots.findIndex(t=>t.index>e.trimToIndex);-1!==r&&c.snapshots.splice(r),u={type:"Value",value:e.value,k:t};continue}if(eo(e)){return{type:"suspended",snapshot:{continuation:fo(e.k,e.snapshots,e.nextSnapshotIndex,e.meta),timestamp:Date.now(),index:c.nextSnapshotIndex++,runId:c.runId,meta:e.meta,effectName:e.effectName,effectArgs:e.effectArgs}}}return e instanceof o?{type:"error",error:e}:{type:"error",error:new o(`${e}`,void 0)}}}new Set(Object.keys(xo));const sa={collection:'{\n map: (first-coll, ...args) -> do\n let fn = last(args);\n let other-colls = slice(args, 0, count(args) - 1);\n let all-colls = [first-coll, ...other-colls];\n\n cond\n case object?(first-coll) then do\n let expected-keys = keys(first-coll) |> sort;\n doseq (obj in other-colls) -> do\n if not(object?(obj)) then\n perform(effect(dvala.error), "Expected object")\n end;\n let obj-keys = keys(obj) |> sort;\n if not(obj-keys == expected-keys) then\n perform(effect(dvala.error), ++(\n "All objects must have the same keys. Expected: ",\n join(expected-keys, ", "),\n ". Found: ",\n join(obj-keys, ", ")\n ))\n end\n end;\n reduce(keys(first-coll), (acc, k) -> do\n let a = for (coll in all-colls) -> coll(k);\n assoc(acc, k, apply(fn, a))\n end, {})\n end\n\n case string?(first-coll) then do\n doseq (s in other-colls) -> do\n if not(string?(s)) then\n perform(effect(dvala.error), "Expected string")\n end\n end;\n let len = reduce(other-colls, (m, s) -> min(m, count(s)), count(first-coll));\n let mapped = for (i in range(len)) -> do\n let a = for (coll in all-colls) -> nth(coll, i);\n apply(fn, a)\n end;\n reduce(mapped, (acc, ch) -> do\n if not(string?(ch)) then\n perform(effect(dvala.error), "Expected string")\n end;\n ++(acc, ch)\n end, "")\n end\n\n case true then do\n doseq (x in other-colls) -> do\n if not(array?(x)) then\n perform(effect(dvala.error), "Expected array")\n end\n end;\n let len = reduce(other-colls, (m, x) -> min(m, count(x)), count(first-coll));\n for (i in range(len)) -> do\n let a = for (coll in all-colls) -> nth(coll, i);\n apply(fn, a)\n end\n end\n end\n end,\n\n filter: (coll, fn) -> do\n cond\n case array?(coll) then\n reduce(coll, (acc, elem) -> if fn(elem) then [...acc, elem] else acc end, [])\n\n case string?(coll) then\n reduce(coll, (acc, ch) -> if fn(ch) then ++(acc, ch) else acc end, "")\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) -> do\n if fn(coll(k)) then\n assoc(acc, k, coll(k))\n else\n acc\n end\n end, {})\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reduce: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i)), i + 1)\n end\n end\n\n case array?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i)), i + 1)\n end\n end\n\n case object?(coll) then do\n let values = vals(coll);\n loop (acc = initial, i = 0) -> do\n if i >= count(values) then\n acc\n else\n recur(fn(acc, nth(values, i)), i + 1)\n end\n end\n end\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end\n}',sequence:'{\n some: (seq, fn) -> do\n if null?(seq) then null\n else do\n loop (i = 0) -> do\n if i >= count(seq) then\n null\n else do\n let elem = nth(seq, i);\n if fn(elem) then elem\n else recur(i + 1)\n end\n end\n end\n end\n end\n end\n end,\n\n take-while: (seq, fn) -> do\n let is-str = string?(seq);\n let len = count(seq);\n let idx = loop (i = 0) -> do\n if i >= len then\n len\n else if fn(nth(seq, i)) then\n recur(i + 1)\n else\n i\n end\n end\n end;\n slice(seq, 0, idx)\n end,\n\n drop-while: (seq, fn) -> do\n let is-str = string?(seq);\n let len = count(seq);\n let idx = loop (i = 0) -> do\n if i >= len then\n len\n else if fn(nth(seq, i)) then\n recur(i + 1)\n else\n i\n end\n end\n end;\n slice(seq, idx)\n end,\n\n sort: (seq, ...args) -> do\n let cmp = if count(args) == 0 then compare else first(args) end;\n let is-str = string?(seq);\n let arr = if is-str then split(seq, "") else seq end;\n let len = count(arr);\n\n // merge two sorted arrays\n let merge-arrays = (left, right) -> do\n let left-len = count(left);\n let right-len = count(right);\n loop (result = [], li = 0, ri = 0) -> do\n if li >= left-len then\n ++(result, slice(right, ri))\n else if ri >= right-len then\n ++(result, slice(left, li))\n else do\n let l = nth(left, li);\n let r = nth(right, ri);\n if cmp(l, r) <= 0 then\n recur(push(result, l), li + 1, ri)\n else\n recur(push(result, r), li, ri + 1)\n end\n end\n end\n end\n end\n end;\n\n // recursive merge-sort\n let merge-sort = (a) -> do\n let n = count(a);\n if n <= 1 then a\n else do\n let mid = floor(n / 2);\n let left = merge-sort(slice(a, 0, mid));\n let right = merge-sort(slice(a, mid));\n merge-arrays(left, right)\n end\n end\n end;\n\n let sorted = merge-sort(arr);\n if is-str then join(sorted, "") else sorted end\n end\n}\n',array:'{\n mapcat: (arr, fn) -> do\n flatten(map(arr, fn), 1)\n end,\n\n moving-fn: (arr, window-size, fn) -> do\n if window-size > count(arr) then\n perform(effect(dvala.error), "Expected window-size <= array length")\n end;\n for (i in range(count(arr) - window-size + 1)) -> do\n fn(slice(arr, i, i + window-size))\n end\n end,\n\n running-fn: (arr, fn) -> do\n for (i in range(count(arr))) -> do\n fn(slice(arr, 0, i + 1))\n end\n end\n}\n',functional:'{\n "|>": (a, b) -> b(a),\n\n apply: (fn, ...args) -> do\n let arr = last(args);\n let leading = slice(args, 0, count(args) - 1);\n fn(...leading, ...arr)\n end\n}\n',object:'{\n merge-with: (...args) -> do\n let fn = last(args);\n let objs = slice(args, 0, count(args) - 1);\n if not(function?(fn)) then\n perform(effect(dvala.error), str("Expected function, got: ", type(fn)))\n end;\n if count(objs) == 0 then\n perform(effect(dvala.error), "Expected at least one object argument")\n end;\n reduce(rest(objs), (result, obj) -> do\n if not(object?(obj)) then\n perform(effect(dvala.error), str("Expected object, got: ", type(obj)))\n end;\n reduce(keys(obj), (res, key) -> do\n if contains?(res, key) then\n assoc(res, key, fn(get(res, key), get(obj, key)))\n else\n assoc(res, key, get(obj, key))\n end\n end, result)\n end, do\n let f = first(objs);\n if not(object?(f)) then\n perform(effect(dvala.error), str("Expected object, got: ", type(f)))\n end;\n f\n end)\n end\n}\n'};let la=!1;class ca{cache={};firstEntry=void 0;lastEntry=void 0;_size=0;maxSize;constructor(e){if(this.maxSize=null===e?null:se(e),"number"==typeof this.maxSize&&this.maxSize<1)throw new Error(`1 is the minimum maxSize, got ${y(e)}`)}getContent(){return Object.entries(this.cache).reduce((e,[t,r])=>(e[t]=r.value,e),{})}get size(){return this._size}get(e){return this.cache[e]?.value}clear(){this.cache={},this.firstEntry=void 0,this.lastEntry=void 0,this._size=0}has(e){return!!this.cache[e]}set(e,t){if(this.has(e))throw new Error(`AstCache - key already present: ${e}`);const r={value:t,nextEntry:void 0,key:e};for(this.cache[e]=r,this._size+=1,this.lastEntry&&(this.lastEntry.nextEntry=r),this.lastEntry=r,this.firstEntry||(this.firstEntry=this.lastEntry);null!==this.maxSize&&this.size>this.maxSize;)this.dropFirstEntry()}dropFirstEntry(){const e=this.firstEntry;delete this.cache[e.key],this._size-=1,this.firstEntry=e.nextEntry}}function ua(e){return"object"==typeof e&&null!==e&&"string"==typeof e.program&&Array.isArray(e.fileModules)}function ma(e){if(e)for(const[t,r]of Object.entries(e))pa(r,`bindings["${t}"]`)}function pa(e,t){if(null!=e&&"boolean"!=typeof e&&"string"!=typeof e)if("number"!=typeof e){if("function"==typeof e)throw new TypeError(`${t} is not serializable (function)`);if("object"!=typeof e)throw new TypeError(`${t} is not serializable`);if(p in e||d in e||h in e)return;if(Array.isArray(e))return void e.forEach((e,r)=>pa(e,`${t}[${r}]`));if(Object.getPrototypeOf(e)!==Object.prototype)throw new TypeError(`${t} is not serializable (not a plain object)`);for(const[r,n]of Object.entries(e))pa(n,`${t}.${r}`)}else if(!Number.isFinite(e))throw new TypeError(`${t} is not serializable (${e})`)}function da(e){!function(){if(!la){la=!0;for(const[,e]of Object.entries(sa)){const t=oa({body:Hn(Yn(jr(e,!1,void 0),{removeWhiteSpace:!0})),hasDebugData:!1},Lr());if(t instanceof Promise)throw new TypeError("Core dvala sources must be synchronous");if(!j(t))continue;const r=t;for(const[e,t]of Object.entries(r)){const r=at[e];r&&q(t)&&"UserDefined"===t.functionType&&(r.dvalaImpl=t)}}}}();const t=e?.modules?new Map(e.modules.map(e=>[e.name,e])):void 0,r=e?.bindings,n=e?.effectHandlers,a=e?.debug??!1,i=e?.cache?new ca(e.cache):null;function s(e,t){if(!t&&i){const t=i.get(e);if(t)return t}const r={body:Hn(Yn(jr(e,a,t),{removeWhiteSpace:!0})),hasDebugData:a};return t||i?.set(e,r),r}function l(e){if(r||e)return{...r,...e}}function c(e){if(!n&&!e)return;const t={...e};if(n)for(const[e,r]of Object.entries(n))e in t||(t[e]=r);return t}function u(e,t){if(!e)return;if(t&&Object.keys(t).length>0)throw new TypeError("Cannot use pure mode with effect handlers")}return{run(e,r){ma(r?.bindings);const n=l(r?.bindings),a=c(r?.effectHandlers),i=r?.pure??!1;u(i,a);const m=Lr({bindings:n},t,i);if(ua(e)){const t=m.pure;m.pure=!0;for(const[t,r]of e.fileModules){const e=s(r),n=m.create({});m.registerValueModule(t,oa(e,n))}m.pure=t;const r=oa(s(e.program),m);if(r instanceof Promise)throw new TypeError("Unexpected async result in run(). Use runAsync() for async operations.");return r}const p=s(e,r?.filePath);if(a)return function(e,t,r){const n=na(e.body,t);try{return ta(n,r)}catch(n){if(n instanceof o&&n.message.includes("Unexpected async operation"))return ta(na(e.body,t),r);throw n}}(p,m,a);const d=oa(p,m);if(d instanceof Promise)throw new TypeError("Unexpected async result in run(). Use runAsync() for async operations.");return d},async runAsync(e,r){ma(r?.bindings);const n=l(r?.bindings),a=c(r?.effectHandlers),i=r?.pure??!1;u(i,a);try{const o=Lr({bindings:n},t,i);if(ua(e)){const t=o.pure;o.pure=!0;for(const[t,r]of e.fileModules){const e=s(r),n=o.create({});o.registerValueModule(t,oa(e,n))}o.pure=t}const l=s(ua(e)?e.program:e),c=await async function(e,t,r,n,o){const a=(new AbortController).signal;return ia(na(e.body,t),r,a,0,n,o)}(l,o,a,r?.maxSnapshots,{values:n,modules:t});return"completed"===c.type?{...c,definedBindings:o.getModuleScopeBindings()}:c}catch(e){if(e instanceof o)return{type:"error",error:e};if(e instanceof TypeError)throw e;return{type:"error",error:new o(`${e}`,void 0)}}},getUndefinedSymbols(e){const n=t?[...t.values()]:void 0;return function(e,t){const r=t?.modules?new Map(t.modules.map(e=>[e.name,e])):void 0,n=Lr({bindings:t?.bindings},r),o={body:Hn(Yn(jr(e,!1,void 0),{removeWhiteSpace:!0})),hasDebugData:!1};return _r(o,n,rr,aa)}(e,{bindings:r,modules:n})},getAutoCompleter:(e,t)=>new Pr(e,t,{bindings:r})}}const ha={"assert!=":{category:"assertion",description:"If $a is the same as $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert!= } = import(assertion);\ndo assert!=(0, 0, "Expected different values") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert!= } = import(assertion);\ndo assert!=(0, 0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert!= } = import(assertion);\ndo 0 assert!= 0 with case effect(dvala.error) then ([msg]) -> msg end","let { assert!= } = import(assertion);\ndo assert!=(0, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert="],hideOperatorForm:!0},"assert=":{category:"assertion",description:"If $a is not structural equal to $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert= } = import(assertion);\ndo assert=({ "a": 1 }, { "a": 2 }, "Expected equal values") with case effect(dvala.error) then ([msg]) -> msg end','let { assert= } = import(assertion);\ndo assert=({ "a": 1 }, { "a": 2 }) with case effect(dvala.error) then ([msg]) -> msg end','let { assert= } = import(assertion);\ndo assert=({ "a": 1 }, { "a": 1 }) with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert!="],hideOperatorForm:!0},"assert-gt":{category:"assertion",description:"If $a is not greater than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-gt } = import(assertion);\ndo assert-gt(0, 1, "Expected greater value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-gt } = import(assertion);\ndo assert-gt(0, 0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-gt } = import(assertion);\ndo assert-gt(1, 0) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-lt","assertion.assert-gte","assertion.assert-lte"],hideOperatorForm:!0},"assert-lt":{category:"assertion",description:"If $a is not less than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-lt } = import(assertion);\ndo assert-lt(1, 0, "Expected smaller value value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-lt } = import(assertion);\ndo assert-lt(1, 1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-lt } = import(assertion);\ndo assert-lt(0, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-gt","assertion.assert-lte","assertion.assert-gte"],hideOperatorForm:!0},"assert-gte":{category:"assertion",description:"If $a is less than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-gte } = import(assertion);\ndo assert-gte(0, 1, "Expected greater value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-gte } = import(assertion);\ndo assert-gte(0, 1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-gte } = import(assertion);\ndo assert-gte(1, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-lte","assertion.assert-gt","assertion.assert-lt"],hideOperatorForm:!0},"assert-lte":{category:"assertion",description:"If $a is grater than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-lte } = import(assertion);\ndo assert-lte(1, 0, "Expected smaller value value") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-lte } = import(assertion);\ndo assert-lte(1, 0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-lte } = import(assertion);\ndo assert-lte(1, 1) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-gte","assertion.assert-lt","assertion.assert-gt"],hideOperatorForm:!0},"assert-true":{category:"assertion",description:"If $value is not `true` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-true } = import(assertion);\ndo assert-true(false, "Expected true") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-true } = import(assertion);\ndo assert-true(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-true } = import(assertion);\ndo assert-true(true) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-false","assertion.assert-truthy","assertion.assert-falsy","assert","assertion.assert-boolean"],hideOperatorForm:!0},"assert-false":{category:"assertion",description:"If $value is not `false` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-false } = import(assertion);\ndo assert-false(true, "Expected false") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-false } = import(assertion);\ndo assert-false(true) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-false } = import(assertion);\ndo assert-false(false) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-true","assertion.assert-falsy","assertion.assert-truthy","assertion.assert-boolean"],hideOperatorForm:!0},"assert-truthy":{category:"assertion",description:"If $value is not `truthy` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-truthy } = import(assertion);\ndo assert-truthy(false, "Expected truthy") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-truthy } = import(assertion);\ndo assert-truthy(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(null) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-truthy } = import(assertion);\ndo assert-truthy("") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-truthy } = import(assertion);\ndo assert-truthy(true) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(1) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-truthy } = import(assertion);\ndo assert-truthy("x") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-truthy } = import(assertion);\ndo assert-truthy([]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-truthy } = import(assertion);\ndo assert-truthy(nd) with case effect(dvala.error) then ([msg]) -> msg end"],seeAlso:["assertion.assert-falsy","assertion.assert-true","assertion.assert-false","assert","assertion.assert-null"],hideOperatorForm:!0},"assert-falsy":{category:"assertion",description:"If $value is not `falsy` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-falsy } = import(assertion);\ndo assert-falsy(true, "Expected falsy") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-falsy } = import(assertion);\ndo assert-falsy("x") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-falsy } = import(assertion);\ndo assert-falsy([]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(nd) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(0) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-falsy } = import(assertion);\ndo assert-falsy(null) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-falsy } = import(assertion);\ndo assert-falsy("") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-truthy","assertion.assert-false","assertion.assert-true","assertion.assert-null"],hideOperatorForm:!0},"assert-null":{category:"assertion",description:"If $value is not `null` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-null } = import(assertion);\ndo assert-null(null) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-null } = import(assertion);\ndo assert-null(true, "Expected null") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-null } = import(assertion);\ndo assert-null("x") with case effect(dvala.error) then ([msg]) -> msg end',"let { assert-null } = import(assertion);\ndo assert-null([]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(nd) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(1) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(false) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-null } = import(assertion);\ndo assert-null(0) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-null } = import(assertion);\ndo assert-null("") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-truthy","assertion.assert-falsy"],hideOperatorForm:!0},"assert-throws":{category:"assertion",description:"If $fun does not throw, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},message:{type:"string"}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","message"]}],examples:['let { assert-throws } = import(assertion);\nassert-throws(-> perform(effect(dvala.error), "Error"))','let { assert-throws } = import(assertion);\ndo assert-throws(-> identity("Error")) with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-throws-error","assertion.assert-not-throws"],hideOperatorForm:!0},"assert-throws-error":{category:"assertion",description:"If $fun does not throw $error-message, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},"error-message":{type:"string"},message:{type:"string"}},variants:[{argumentNames:["fun","error-message"]},{argumentNames:["fun","error-message","message"]}],examples:['let { assert-throws-error } = import(assertion);\ndo assert-throws-error(-> perform(effect(dvala.error), "Error"), "Error") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-throws-error } = import(assertion);\ndo assert-throws-error(-> identity("Error"), "Error") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-throws","assertion.assert-not-throws"],hideOperatorForm:!0},"assert-not-throws":{category:"assertion",description:"If $fun throws, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},message:{type:"string"}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","message"]}],examples:['let { assert-not-throws } = import(assertion);\ndo assert-not-throws(-> identity("Error")) with case effect(dvala.error) then ([msg]) -> msg end','let { assert-not-throws } = import(assertion);\ndo assert-not-throws(-> perform(effect(dvala.error), "Error")) with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-throws","assertion.assert-throws-error"],hideOperatorForm:!0},"assert-array":{category:"assertion",description:"If $value is not an `array` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-array } = import(assertion);\ndo assert-array([1, 2, 3]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-array } = import(assertion);\ndo assert-array("string") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-array } = import(assertion);\ndo assert-array(42, "Expected an array") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-object","assertion.assert-collection","assertion.assert-sequence"],hideOperatorForm:!0},"assert-boolean":{category:"assertion",description:"If $value is not a `boolean` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-boolean } = import(assertion);\ndo assert-boolean(true) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-boolean } = import(assertion);\ndo assert-boolean(false) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-boolean } = import(assertion);\ndo assert-boolean(1, "Expected a boolean") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-true","assertion.assert-false","assertion.assert-number","assertion.assert-string"],hideOperatorForm:!0},"assert-collection":{category:"assertion",description:"If $value is not a `collection` (array, object, or string) it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-collection } = import(assertion);\ndo assert-collection([1, 2]) with case effect(dvala.error) then ([msg]) -> msg end","let { assert-collection } = import(assertion);\ndo assert-collection({ a: 1 }) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-collection } = import(assertion);\ndo assert-collection("hello") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-collection } = import(assertion);\ndo assert-collection(42, "Expected a collection") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-sequence","assertion.assert-array","assertion.assert-object"],hideOperatorForm:!0},"assert-function":{category:"assertion",description:"If $value is not a `function` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-function } = import(assertion);\ndo assert-function(-> $ + 1) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-function } = import(assertion);\ndo assert-function(42, "Expected a function") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-number","assertion.assert-string"],hideOperatorForm:!0},"assert-grid":{category:"assertion",description:"If $value is not a `grid` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-grid } = import(assertion);\ndo assert-grid([[1, 2], [3, 4]]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-grid } = import(assertion);\ndo assert-grid([1, 2], "Expected a grid") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-matrix","assertion.assert-vector"],hideOperatorForm:!0},"assert-integer":{category:"assertion",description:"If $value is not an `integer` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-integer } = import(assertion);\ndo assert-integer(42) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-integer } = import(assertion);\ndo assert-integer(3.14, "Expected an integer") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-number"],hideOperatorForm:!0},"assert-matrix":{category:"assertion",description:"If $value is not a `matrix` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-matrix } = import(assertion);\ndo assert-matrix([[1, 2], [3, 4]]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-matrix } = import(assertion);\ndo assert-matrix([1, 2], "Expected a matrix") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-vector","assertion.assert-grid"],hideOperatorForm:!0},"assert-number":{category:"assertion",description:"If $value is not a `number` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-number } = import(assertion);\ndo assert-number(42) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-number } = import(assertion);\ndo assert-number("hello", "Expected a number") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-integer","assertion.assert-boolean","assertion.assert-string","assertion.assert-function"],hideOperatorForm:!0},"assert-object":{category:"assertion",description:"If $value is not an `object` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-object } = import(assertion);\ndo assert-object({ a: 1 }) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-object } = import(assertion);\ndo assert-object([1, 2], "Expected an object") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-array","assertion.assert-collection"],hideOperatorForm:!0},"assert-regexp":{category:"assertion",description:"If $value is not a `regexp` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-regexp } = import(assertion);\ndo assert-regexp(#"^start") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-regexp } = import(assertion);\ndo assert-regexp("hello", "Expected a regexp") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-string"],hideOperatorForm:!0},"assert-sequence":{category:"assertion",description:"If $value is not a `sequence` (array or string) it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-sequence } = import(assertion);\ndo assert-sequence([1, 2]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-sequence } = import(assertion);\ndo assert-sequence("hello") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-sequence } = import(assertion);\ndo assert-sequence({ a: 1 }, "Expected a sequence") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-collection","assertion.assert-array"],hideOperatorForm:!0},"assert-string":{category:"assertion",description:"If $value is not a `string` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-string } = import(assertion);\ndo assert-string("hello") with case effect(dvala.error) then ([msg]) -> msg end','let { assert-string } = import(assertion);\ndo assert-string(42, "Expected a string") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-number","assertion.assert-boolean","assertion.assert-regexp","assertion.assert-function"],hideOperatorForm:!0},"assert-vector":{category:"assertion",description:"If $value is not a `vector` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-vector } = import(assertion);\ndo assert-vector([1, 2, 3]) with case effect(dvala.error) then ([msg]) -> msg end",'let { assert-vector } = import(assertion);\ndo assert-vector(["a", "b"], "Expected a vector") with case effect(dvala.error) then ([msg]) -> msg end'],seeAlso:["assertion.assert-matrix","assertion.assert-grid"],hideOperatorForm:!0}},ga={"assert=":{evaluate:([e,t,r],n)=>{if(void 0!==r&&(G(r,n),r=` ${r}`),r??="",!ie($(e,n),$(t,n),n))throw new i(`Expected ${JSON.stringify(e,null,2)} to deep equal ${JSON.stringify(t,null,2)}.${r}`,n);return null},arity:{min:2,max:3}},"assert!=":{evaluate:([e,t,r],n)=>{if(void 0!==r&&(G(r,n),r=` ${r}`),r??="",ie($(e,n),$(t,n),n))throw new i(`Expected ${JSON.stringify(e)} not to deep equal ${JSON.stringify(t)}.${r}`,n);return null},arity:{min:2,max:3}},"assert-gt":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)<=0)throw new i(`Expected ${e} to be grater than ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-gte":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)<0)throw new i(`Expected ${e} to be grater than or equal to ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-lt":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)>=0)throw new i(`Expected ${e} to be less than ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-lte":{evaluate:([e,t,r],n)=>{if(K(e,n),K(t,n),void 0!==r&&(G(r,n),r=` ${r}`),r??="",ae(e,t,n)>0)throw new i(`Expected ${e} to be less than or equal to ${t}.${r}`,n);return null},arity:{min:2,max:3}},"assert-true":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!0!==e)throw new i(`Expected ${e} to be true.${t}`,r);return null},arity:{min:1,max:2}},"assert-false":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!1!==e)throw new i(`Expected ${e} to be false.${t}`,r);return null},arity:{min:1,max:2}},"assert-truthy":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!e)throw new i(`Expected ${e} to be truthy.${t}`,r);return null},arity:{min:1,max:2}},"assert-falsy":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",e)throw new i(`Expected ${e} to be falsy.${t}`,r);return null},arity:{min:1,max:2}},"assert-null":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",null!==e)throw new i(`Expected ${e} to be null.${t}`,r);return null},arity:{min:1,max:2}},"assert-throws":{evaluate:([e,t],r,n,{executeFunction:o})=>(void 0!==t&&(G(t,r),t=` ${t}`),t??="",F(e,r),kt(()=>ft(o(e,[],n,r),()=>{throw new i(`Expected function to throw.${t}`,r)}),()=>null)),arity:{min:1,max:2}},"assert-throws-error":{evaluate:([e,t,r],n,o,{executeFunction:a})=>(void 0!==r&&(G(r,n),r=` ${r}`),r??="",G(t,n),F(e,n),kt(()=>ft(a(e,[],o,n),()=>{throw new i(`Expected function to throw "${t}".${r}`,n)}),e=>{const o=e.shortMessage;if(o!==t)throw new i(`Expected function to throw "${t}", but thrown "${o}".${r}`,n);return null})),arity:{min:2,max:3}},"assert-not-throws":{evaluate:([e,t],r,n,{executeFunction:o})=>(void 0!==t&&(G(t,r),t=` ${t}`),t??="",F(e,r),kt(()=>ft(o(e,[],n,r),()=>null),()=>{throw new i(`Expected function not to throw.${t}`,r)})),arity:{min:1,max:2}},"assert-array":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!Array.isArray(e))throw new i(`Expected ${JSON.stringify(e)} to be an array.${t}`,r);return null},arity:{min:1,max:2}},"assert-boolean":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","boolean"!=typeof e)throw new i(`Expected ${JSON.stringify(e)} to be a boolean.${t}`,r);return null},arity:{min:1,max:2}},"assert-collection":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!I(e))throw new i(`Expected ${JSON.stringify(e)} to be a collection.${t}`,r);return null},arity:{min:1,max:2}},"assert-function":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!q(e))throw new i(`Expected ${JSON.stringify(e)} to be a function.${t}`,r);return null},arity:{min:1,max:2}},"assert-grid":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!Me(e))throw new i(`Expected ${JSON.stringify(e)} to be a grid.${t}`,r);return null},arity:{min:1,max:2}},"assert-integer":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","number"!=typeof e||!H(e,{integer:!0}))throw new i(`Expected ${JSON.stringify(e)} to be an integer.${t}`,r);return null},arity:{min:1,max:2}},"assert-matrix":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!Ve(e))throw new i(`Expected ${JSON.stringify(e)} to be a matrix.${t}`,r);return null},arity:{min:1,max:2}},"assert-number":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","number"!=typeof e)throw new i(`Expected ${JSON.stringify(e)} to be a number.${t}`,r);return null},arity:{min:1,max:2}},"assert-object":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!j(e))throw new i(`Expected ${JSON.stringify(e)} to be an object.${t}`,r);return null},arity:{min:1,max:2}},"assert-regexp":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!M(e))throw new i(`Expected ${JSON.stringify(e)} to be a regexp.${t}`,r);return null},arity:{min:1,max:2}},"assert-sequence":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!T(e))throw new i(`Expected ${JSON.stringify(e)} to be a sequence.${t}`,r);return null},arity:{min:1,max:2}},"assert-string":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="","string"!=typeof e)throw new i(`Expected ${JSON.stringify(e)} to be a string.${t}`,r);return null},arity:{min:1,max:2}},"assert-vector":{evaluate:([e,t],r)=>{if(void 0!==t&&(G(t,r),t=` ${t}`),t??="",!je(e))throw new i(`Expected ${JSON.stringify(e)} to be a vector.${t}`,r);return null},arity:{min:1,max:2}}};for(const[e,t]of Object.entries(ha))ga[e]&&(ga[e].docs=t);const fa={name:"assertion",functions:ga,source:"{}",docs:ha};const ya={"cell-every?":{category:"grid",description:"Checks if all elements in a grid satisfy a predicate. Returns true only if the predicate returns true for every element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-every? } = import(grid);\ncell-every?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { cell-every? } = import(grid);\ncell-every?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)',"let { cell-every? } = import(grid);\ncell-every?([\n [1, 2],\n [3, 4],\n], string?)"],seeAlso:["collection.every?","grid.some?","grid.every-row?","grid.every-col?"]},"some?":{category:"grid",description:"Checks if any element in a grid satisfies a predicate. Returns true if the predicate returns true for at least one element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some? } = import(grid);\nsome?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { some? } = import(grid);\nsome?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)',"let { some? } = import(grid);\nsome?([\n [1, 2],\n [3, 4],\n], string?)"],seeAlso:["collection.any?","grid.cell-every?","grid.some-row?","grid.some-col?"]},"every-row?":{category:"grid",description:"Checks if all rows in a grid satisfy a predicate. Returns true only if the predicate returns true for every row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-row? } = import(grid);\nevery-row?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-row?","grid.every-col?","grid.cell-every?"]},"some-row?":{category:"grid",description:"Checks if any row in a grid satisfies a predicate. Returns true if the predicate returns true for at least one row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-row?","grid.some-col?","grid.some?"]},"every-col?":{category:"grid",description:"Checks if all columns in a grid satisfy a predicate. Returns true only if the predicate returns true for every column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-col? } = import(grid);\nevery-col?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-col?","grid.every-row?","grid.cell-every?"]},"some-col?":{category:"grid",description:"Checks if any column in a grid satisfies a predicate. Returns true if the predicate returns true for at least one column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-col?","grid.some-row?","grid.some?"]},row:{category:"grid",description:"Returns the row at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.col","grid.shape"]},col:{category:"grid",description:"Returns the column at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.row","grid.shape"]},shape:{category:"grid",description:"Returns the shape of the grid `g` as a `vector` of two numbers, where the first number is the number of rows and the second number is the number of columns.",returns:{type:"vector"},args:{g:{type:"grid",description:"The grid to get the shape of."}},variants:[{argumentNames:["g"]}],examples:['let { shape } = import(grid);\nshape([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { shape } = import(grid);\nshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { shape } = import(grid);\nshape([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.row","grid.col","grid.reshape"]},fill:{category:"grid",description:"Creates a grid of the specified size, filled with the specified value.",returns:{type:"grid"},args:{rows:{type:"integer",description:"The number of rows in the grid."},cols:{type:"integer",description:"The number of columns in the grid."},value:{type:"any",description:"The value to fill the grid with."}},variants:[{argumentNames:["rows","cols","value"]}],examples:["let { fill } = import(grid);\nfill(2, 3, 0)",'let { fill } = import(grid);\nfill(2, 3, "x")'],seeAlso:["grid.generate","grid.from-array"]},generate:{category:"grid",description:"Generates a grid of the specified size, where each element is generated by the provided function.",returns:{type:"grid"},args:{rows:{type:"number",description:"The number of rows in the grid."},cols:{type:"number",description:"The number of columns in the grid."},generator:{type:"function",description:"The function to generate the grid. It takes two arguments: the row index and the column index."}},variants:[{argumentNames:["rows","cols","generator"]}],examples:["let { generate } = import(grid);\ngenerate(3, 3, (i, j) -> i + j)"],seeAlso:["grid.fill","grid.from-array"]},reshape:{category:"grid",description:"Reshapes the grid `a` into a new grid with the specified number of rows `b`. The number of columns is automatically calculated based on the total number of elements in the grid.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { reshape } = import(grid);\nreshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], 2)'],seeAlso:["grid.shape","grid.from-array"]},transpose:{category:"grid",description:"Transposes the grid `g`, swapping its rows and columns.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to transpose."}},variants:[{argumentNames:["g"]}],examples:['let { transpose } = import(grid);\ntranspose([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { transpose } = import(grid);\ntranspose([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { transpose } = import(grid);\ntranspose([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.flip-v","grid.rotate"]},"flip-h":{category:"grid",description:"Flips the grid `g` horizontally.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip horizontally."}},variants:[{argumentNames:["g"]}],examples:['let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-h } = import(grid);\nflip-h([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-v","grid.transpose","grid.rotate"]},"flip-v":{category:"grid",description:"Flips the grid `g` vertically.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip vertically."}},variants:[{argumentNames:["g"]}],examples:['let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-v } = import(grid);\nflip-v([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.transpose","grid.rotate"]},rotate:{category:"grid",description:"Rotates the grid `g` by the specified angle. The angle is given in terms of 90-degree rotations. Positive values rotate the grid clockwise, while negative values rotate it counterclockwise.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 3)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 4)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -3)"],seeAlso:["grid.transpose","grid.flip-h","grid.flip-v"]},crop:{category:"grid",description:"Crops the grid `g` from the starting index `begin` to the optional ending index `stop`. The crop is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"vector",description:"The starting index of the slice as a vector of two numbers: `[row, col]`."},stop:{type:"vector",description:"Optional ending index of the slice as a vector of two numbers: `[row, col]`."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { crop } = import(grid);\ncrop([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1], [2, 2])','let { crop } = import(grid);\ncrop([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1])'],hideOperatorForm:!0,seeAlso:["grid.slice-rows","grid.slice-cols"]},"slice-rows":{category:"grid",description:"Slices rows of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.crop","grid.slice-cols","grid.splice-rows"]},"slice-cols":{category:"grid",description:"Slices columns of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.crop","grid.slice-rows","grid.splice-cols"]},"splice-rows":{category:"grid",description:"Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of rows to delete."},items:{type:"array",rest:!0,description:"The rows to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.splice-cols","grid.slice-rows"]},"splice-cols":{category:"grid",description:"Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of columns to delete."},items:{type:"array",rest:!0,description:"The columns to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.splice-rows","grid.slice-cols"]},"concat-rows":{category:"grid",description:"Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-rows } = import(grid);\nconcat-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], [\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.concat-cols","grid.push-rows"]},"concat-cols":{category:"grid",description:"Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-cols } = import(grid);\nconcat-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])'],seeAlso:["grid.concat-rows","grid.push-cols"]},"cell-map":{category:"grid",description:"Maps a function `a` over each element of the grid `b`, returning a new grid with the results.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-map } = import(grid);\ncell-map([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], str)'],seeAlso:["map","grid.cell-mapi","grid.cell-reduce"]},"cell-mapi":{category:"grid",description:"Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-mapi } = import(grid);\ncell-mapi([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $1 ++ "(" ++ $2 ++ ", " ++ $3 ++ ")")'],seeAlso:["grid.cell-map","grid.cell-reducei","map"]},"cell-reduce":{category:"grid",description:"Reduces the grid `a` using the function `b`, returning a single value.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},f:{type:"function",description:"The function to reduce the grid. It takes two arguments: the accumulator and the current element."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","f","initial-value"]}],examples:['// Using "as" alias because "reduce" shadows a builtin function\nlet { cell-reduce } = import(grid);\ncell-reduce([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["reduce","grid.cell-reducei","grid.cell-map"]},"cell-reducei":{category:"grid",description:"Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},f:{type:"function",description:"The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","f","initial-value"]}],examples:['// Using "as" alias because "reducei" shadows a builtin function\nlet { cell-reducei } = import(grid);\ncell-reducei([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["grid.cell-reduce","grid.cell-mapi","reduce"]},"push-rows":{category:"grid",description:"Pushes the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push rows into."},rows:{type:"array",rest:!0,description:"The rows to push into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { push-rows } = import(grid);\npush-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.unshift-rows","grid.pop-row","grid.shift-row","grid.concat-rows"]},"unshift-rows":{category:"grid",description:"Unshifts the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift rows into."},rows:{type:"array",rest:!0,description:"The rows to unshift into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { unshift-rows } = import(grid);\nunshift-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.push-rows","grid.shift-row","grid.pop-row"]},"pop-row":{category:"grid",description:"Pops the last row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a row from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-row } = import(grid);\npop-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-row","grid.push-rows","grid.unshift-rows"]},"shift-row":{category:"grid",description:"Shifts the first row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a row from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-row } = import(grid);\nshift-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-row","grid.push-rows","grid.unshift-rows"]},"push-cols":{category:"grid",description:"Pushes the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push columns into."},cols:{type:"array",rest:!0,description:"The columns to push into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { push-cols } = import(grid);\npush-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.unshift-cols","grid.pop-col","grid.shift-col","grid.concat-cols"]},"unshift-cols":{category:"grid",description:"Unshifts the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift columns into."},cols:{type:"array",rest:!0,description:"The columns to unshift into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { unshift-cols } = import(grid);\nunshift-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.push-cols","grid.shift-col","grid.pop-col"]},"pop-col":{category:"grid",description:"Pops the last column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a column from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-col } = import(grid);\npop-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-col","grid.push-cols","grid.unshift-cols"]},"shift-col":{category:"grid",description:"Shifts the first column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a column from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-col } = import(grid);\nshift-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-col","grid.push-cols","grid.unshift-cols"]},"from-array":{category:"grid",description:"Creates a grid from a flat array with specified dimensions. The array is reshaped into the specified number of rows, and the number of columns is automatically calculated based on the total number of elements in the array.",returns:{type:"grid"},args:{a:{type:"array"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:["let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 2)","let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 4)"],seeAlso:["grid.fill","grid.generate","grid.reshape"]}};function va(e){const t=[];for(let r=0;r<e[0].length;r+=1){const n=[];for(let t=0;t<e.length;t+=1)n.push(e[t][r]);t.push(n)}return t}const ba={"cell-every?":{evaluate:()=>{throw new Error("cell-every?: Dvala implementation should be used instead")},arity:te(2)},"some?":{evaluate:()=>{throw new Error("some?: Dvala implementation should be used instead")},arity:te(2)},"every-row?":{evaluate:()=>{throw new Error("every-row?: Dvala implementation should be used instead")},arity:te(2)},"some-row?":{evaluate:()=>{throw new Error("some-row?: Dvala implementation should be used instead")},arity:te(2)},"every-col?":{evaluate:()=>{throw new Error("every-col?: Dvala implementation should be used instead")},arity:te(2)},"some-col?":{evaluate:()=>{throw new Error("some-col?: Dvala implementation should be used instead")},arity:te(2)},row:{evaluate:([e,t],r)=>(Oe(e,r),Y(t,r,{integer:!0,nonNegative:!0,lt:e.length}),e[t]),arity:te(2)},col:{evaluate:([e,t],r)=>(Oe(e,r),Y(t,r,{integer:!0,nonNegative:!0,lt:e[0].length}),e.map(e=>e[t])),arity:te(2)},shape:{evaluate:([e],t)=>(Oe(e,t),[e.length,e[0].length]),arity:te(1)},fill:{evaluate:([e,t,r],n)=>{Y(e,n,{integer:!0,positive:!0}),Y(t,n,{integer:!0,positive:!0}),E(r,n);const o=[];for(let n=0;n<e;n+=1){const e=[];for(let n=0;n<t;n+=1)e.push(r);o.push(e)}return o},arity:te(3)},generate:{evaluate:()=>{throw new Error("generate: Dvala implementation should be used instead")},arity:te(3)},reshape:{evaluate:([e,t],r)=>{Oe(e,r),Y(t,r,{integer:!0,positive:!0});const n=e.flat();if(n.length%t!==0)throw new o(`The number of elements in the grid must be divisible by rows, but got ${n.length} and ${t}`,r);const a=n.length/t,i=[];for(let e=0;e<t;e+=1){const t=[];for(let r=0;r<a;r+=1)t.push(n[e*a+r]);i.push(t)}return i},arity:te(2)},transpose:{evaluate:([e],t)=>(Oe(e,t),va(e)),arity:te(1)},"flip-h":{evaluate:([e],t)=>(Oe(e,t),e.map(e=>e.reverse())),arity:te(1)},"flip-v":{evaluate:([e],t)=>(Oe(e,t),e.reverse()),arity:te(1)},rotate:{evaluate:([e,t],r)=>{if(Oe(e,r),Y(t,r,{integer:!0}),0===(t=(t%4+4)%4)||0===e.length)return e.map(e=>[...e]);const n=e.length,o=e[0].length;let a;switch(t){case 1:a=Array(o).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<o;r++)a[r][n-1-t]=e[t][r];break;case 2:a=Array(n).fill(null).map(()=>Array(o).fill(null));for(let t=0;t<n;t++)for(let r=0;r<o;r++)a[n-1-t][o-1-r]=e[t][r];break;case 3:a=Array(o).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<o;r++)a[o-1-r][t]=e[t][r]}return a},arity:te(2)},crop:{evaluate:([e,t,r],n)=>{if(Oe(e,n),Ce(t,n),2!==t.length)throw new o(`The start vector must have 2 elements, but got ${t.length}`,n);const[a,i]=t;if(Y(a,n,{integer:!0,nonNegative:!0,lt:e.length}),Y(i,n,{integer:!0,nonNegative:!0,lt:e[0].length}),r??=[e.length,e[0].length],Ce(r,n),2!==r.length)throw new o(`The end vector must have 2 elements, but got ${r.length}`,n);const[s,l]=r;Y(s,n,{gt:a,lte:e.length}),Y(l,n,{gt:i,lte:e[0].length});const c=[];for(let t=a;t<s;t+=1){const r=[];for(let n=i;n<l;n+=1)r.push(e[t][n]);c.push(r)}return c},arity:{min:2,max:3}},"slice-rows":{evaluate:([e,t,r],n)=>(Oe(e,n),void 0===r?(Y(t,n,{integer:!0,lte:e.length,gte:-e.length}),t<0?e.slice(e.length+t):e.slice(t)):(Y(t,n,{integer:!0,nonNegative:!0,lte:e.length}),Y(r,n,{integer:!0}),Y(r=r<0?e.length+r:r,n,{gt:t,lte:e.length}),e.slice(t,r))),arity:{min:2,max:3}},"slice-cols":{evaluate:([e,t,r],n)=>{Oe(e,n);const o=va(e);return void 0===r?(Y(t,n,{integer:!0,lte:o.length,gte:-o.length}),va(t<0?o.slice(o.length+t):o.slice(t))):(Y(t,n,{integer:!0,nonNegative:!0,lte:o.length}),Y(r,n,{integer:!0}),Y(r=r<0?o.length+r:r,n,{gt:t,lte:o.length}),va(o.slice(t,r)))},arity:{min:2,max:3}},"splice-rows":{evaluate:([e,t,r,...n],a)=>{Oe(e,a),Y(t,a,{integer:!0,nonNegative:!0,lte:e.length}),Y(r,a,{integer:!0,nonNegative:!0}),0!==n.length&&(Oe(n,a),n.every(t=>{if(ye(t,a),e[0].length!==t.length)throw new o(`All rows must have the same length as the number of columns in grid, but got ${t.length}`,a);return!0}));const i=[];for(let r=0;r<t;r+=1)i.push(e[r]);n.length>0&&i.push(...n);for(let n=t+r;n<e.length;n+=1)i.push(e[n]);return i},arity:{min:3}},"splice-cols":{evaluate:([e,t,r,...n],a)=>{Oe(e,a);const i=va(e);Y(t,a,{integer:!0,nonNegative:!0,lte:i.length}),Y(r,a,{integer:!0,nonNegative:!0}),0!==n.length&&(Oe(n,a),n.every(e=>{if(ye(e,a),i[0].length!==e.length)throw new o(`All rows must have the same length as the number of rows in grid, but got ${e.length}`,a);return!0}));const s=[];for(let e=0;e<t;e+=1)s.push(i[e]);s.push(...n);for(let e=t+r;e<i.length;e+=1)s.push(i[e]);return va(s)},arity:{min:3}},"concat-rows":{evaluate:(e,t)=>{ye(e,t),e.every(e=>Oe(e,t));const r=e[0][0].length;e.slice(1).every(e=>{if(e[0].length!==r)throw new o(`All grids must have the same number of columns, but got ${r} and ${e[0].length}`,t);return!0});const n=[];return e.forEach(e=>{e.forEach(e=>{n.push(e)})}),n},arity:{min:1}},"concat-cols":{evaluate:(e,t)=>{ye(e,t),e.every(e=>Oe(e,t));const r=e[0].length;e.slice(1).every(e=>{if(e.length!==r)throw new o(`All grids must have the same number of rows, but got ${r} and ${e.length}`,t);return!0});const n=[];for(let t=0;t<r;t+=1){const r=[];e.forEach(e=>{r.push(...e[t])}),n.push(r)}return n},arity:{min:1}},"cell-map":{evaluate:()=>{throw new Error("cell-map: Dvala implementation should be used instead")},arity:{min:2}},"cell-mapi":{evaluate:()=>{throw new Error("cell-mapi: Dvala implementation should be used instead")},arity:te(2)},"cell-reduce":{evaluate:()=>{throw new Error("cell-reduce: Dvala implementation should be used instead")},arity:te(3)},"cell-reducei":{evaluate:()=>{throw new Error("cell-reducei: Dvala implementation should be used instead")},arity:te(3)},"push-rows":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e[0].length!==t[0].length)throw new o(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,r);return[...e,...t]},arity:{min:2}},"unshift-rows":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e[0].length!==t[0].length)throw new o(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,r);return[...t,...e]},arity:{min:2}},"pop-row":{evaluate:([e],t)=>(Oe(e,t),1===e.length?null:e.slice(0,-1)),arity:te(1)},"shift-row":{evaluate:([e],t)=>(Oe(e,t),1===e.length?null:e.slice(1)),arity:te(1)},"push-cols":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e.length!==t[0].length)throw new o(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,r);const n=[];for(let r=0;r<e.length;r+=1){const o=[];o.push(...e[r]),t.forEach(e=>{o.push(e[r])}),n.push(o)}return n},arity:{min:2}},"unshift-cols":{evaluate:([e,...t],r)=>{if(Oe(e,r),Oe(t,r),e.length!==t[0].length)throw new o(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,r);const n=[];for(let r=0;r<e.length;r+=1){const o=[];t.forEach(e=>{o.push(e[r])}),o.push(...e[r]),n.push(o)}return n},arity:{min:2}},"pop-col":{evaluate:([e],t)=>(Oe(e,t),1===e[0].length?null:e.map(e=>e.slice(0,-1))),arity:te(1)},"shift-col":{evaluate:([e],t)=>(Oe(e,t),1===e[0].length?null:e.map(e=>e.slice(1))),arity:te(1)},"from-array":{evaluate:([e,t],r)=>{if(ye(e,r),Y(t,r,{integer:!0,positive:!0}),e.length%t!==0)throw new o(`The number of elements in the array must be divisible by rows, but got ${e.length} and ${t}`,r);return function(e,t){const r=[],n=e.length/t;for(let o=0;o<t;o++){const t=o*n,a=t+n;r.push(e.slice(t,a))}return r}(e,t)},arity:te(2)}};for(const[e,t]of Object.entries(ya))ba[e]&&(ba[e].docs=t);const wa={name:"grid",functions:ba,source:'do\nlet _transpose = (g) ->\n map(range(count(first(g))), (i) ->\n map(range(count(g)), (j) -> nth(nth(g, j), i))\n );\n{\n "cell-every?": (grid, predicate) -> do\n let cells = flatten(grid, 1);\n loop(i = 0) ->\n cond\n case i >= count(cells) then true\n case not(predicate(nth(cells, i))) then false\n case true then recur(i + 1)\n end\n end,\n "some?": (grid, predicate) -> do\n let cells = flatten(grid, 1);\n loop(i = 0) ->\n cond\n case i >= count(cells) then false\n case predicate(nth(cells, i)) then true\n case true then recur(i + 1)\n end\n end,\n\n "every-row?": (grid, predicate) ->\n loop(i = 0) ->\n cond\n case i >= count(grid) then true\n case not(predicate(nth(grid, i))) then false\n case true then recur(i + 1)\n end,\n\n "some-row?": (grid, predicate) ->\n loop(i = 0) ->\n cond\n case i >= count(grid) then false\n case predicate(nth(grid, i)) then true\n case true then recur(i + 1)\n end,\n\n "every-col?": (grid, predicate) -> do\n let cols = _transpose(grid);\n loop(i = 0) ->\n cond\n case i >= count(cols) then true\n case not(predicate(nth(cols, i))) then false\n case true then recur(i + 1)\n end\n end,\n\n "some-col?": (grid, predicate) -> do\n let cols = _transpose(grid);\n loop(i = 0) ->\n cond\n case i >= count(cols) then false\n case predicate(nth(cols, i)) then true\n case true then recur(i + 1)\n end\n end,\n\n "generate": (rows, cols, generator) ->\n map(range(rows), (i) -> map(range(cols), (j) -> generator(i, j))),\n\n "cell-map": (...params) -> do\n let fn = last(params);\n let grids = drop-last(params, 1);\n let rows = count(first(grids));\n let cols = count(first(first(grids)));\n map(range(rows), (i) ->\n map(range(cols), (j) ->\n apply(fn, map(grids, (g) -> nth(nth(g, i), j)))\n )\n )\n end,\n\n "cell-mapi": (grid, fn) -> do\n let rows = count(grid);\n let cols = count(first(grid));\n map(range(rows), (i) ->\n map(range(cols), (j) ->\n fn(nth(nth(grid, i), j), i, j)\n )\n )\n end,\n\n "cell-reduce": (grid, fn, initial-value) ->\n reduce(flatten(grid, 1), fn, initial-value),\n\n "cell-reducei": (grid, fn, initial-value) -> do\n let rows = count(grid);\n let cols = count(first(grid));\n loop(acc = initial-value, i = 0, j = 0) ->\n cond\n case i >= rows then acc\n case j >= cols then recur(acc, i + 1, 0)\n case true then recur(fn(acc, nth(nth(grid, i), j), i, j), i, j + 1)\n end\n end\n}\nend;',docs:ya},xa={"moving-mean":{category:"vector",description:"Returns the **moving mean** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving mean** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-mean } = import(vector);\nmoving-mean([1, 2, 3, 4, 5], 3)","let { moving-mean } = import(vector);\nmoving-mean([1, 2, 3, 4, 5], 5)"],seeAlso:["moving-fn","mean","vector.centered-moving-mean","vector.running-mean"]},"centered-moving-mean":{category:"vector",description:"Returns the **centered moving mean** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving mean** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-mean } = import(vector);\ncentered-moving-mean([1, 2, 3, 4, 5], 3)","let { centered-moving-mean } = import(vector);\ncentered-moving-mean([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-mean } = import(vector);\ncentered-moving-mean([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["mean","vector.moving-mean","vector.running-mean"]},"running-mean":{category:"vector",description:"Returns the **running mean** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-mean } = import(vector);\nrunning-mean([1, 2, 3, 4, 5])"],seeAlso:["running-fn","mean","vector.moving-mean","vector.centered-moving-mean"]},"geometric-mean":{category:"vector",description:"Returns the **geometric mean** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **geometric mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { geometric-mean } = import(vector);\ngeometric-mean([1, 2, 3])","let { geometric-mean } = import(vector);\ngeometric-mean([1, 2, 9])"],seeAlso:["vector.moving-geometric-mean","vector.centered-moving-geometric-mean","vector.running-geometric-mean","mean","vector.harmonic-mean"]},"moving-geometric-mean":{category:"vector",description:"Returns the **moving geometric mean** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving geometric mean** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-geometric-mean } = import(vector);\nmoving-geometric-mean([1, 2, 3, 4, 5], 3)","let { moving-geometric-mean } = import(vector);\nmoving-geometric-mean([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.geometric-mean","vector.centered-moving-geometric-mean","vector.running-geometric-mean"]},"centered-moving-geometric-mean":{category:"vector",description:"Returns the **centered moving geometric mean** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving geometric mean** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-geometric-mean } = import(vector);\ncentered-moving-geometric-mean([1, 2, 3, 4, 5], 3)","let { centered-moving-geometric-mean } = import(vector);\ncentered-moving-geometric-mean([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-geometric-mean } = import(vector);\ncentered-moving-geometric-mean([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["vector.geometric-mean","vector.moving-geometric-mean","vector.running-geometric-mean"]},"running-geometric-mean":{category:"vector",description:"Returns the **running geometric mean** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running geometric mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-geometric-mean } = import(vector);\nrunning-geometric-mean([1, 2, 3, 4, 5])"],seeAlso:["vector.geometric-mean","vector.moving-geometric-mean","vector.centered-moving-geometric-mean"]},"harmonic-mean":{category:"vector",description:"Returns the **harmonic mean** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **harmonic mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { harmonic-mean } = import(vector);\nharmonic-mean([1, 2, 3])","let { harmonic-mean } = import(vector);\nharmonic-mean([1, 2, 9])"],seeAlso:["vector.moving-harmonic-mean","vector.centered-moving-harmonic-mean","vector.running-harmonic-mean","mean","vector.geometric-mean"]},"moving-harmonic-mean":{category:"vector",description:"Returns the **moving harmonic mean** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving harmonic mean** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-harmonic-mean } = import(vector);\nmoving-harmonic-mean([1, 2, 3, 4, 5], 3)","let { moving-harmonic-mean } = import(vector);\nmoving-harmonic-mean([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.harmonic-mean","vector.centered-moving-harmonic-mean","vector.running-harmonic-mean"]},"centered-moving-harmonic-mean":{category:"vector",description:"Returns the **centered moving harmonic mean** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving harmonic mean** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-harmonic-mean } = import(vector);\ncentered-moving-harmonic-mean([1, 2, 3, 4, 5], 3)","let { centered-moving-harmonic-mean } = import(vector);\ncentered-moving-harmonic-mean([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-harmonic-mean } = import(vector);\ncentered-moving-harmonic-mean([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["vector.harmonic-mean","vector.moving-harmonic-mean","vector.running-harmonic-mean"]},"running-harmonic-mean":{category:"vector",description:"Returns the **running harmonic mean** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running harmonic mean** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-harmonic-mean } = import(vector);\nrunning-harmonic-mean([1, 2, 3, 4, 5])"],seeAlso:["vector.harmonic-mean","vector.moving-harmonic-mean","vector.centered-moving-harmonic-mean"]},"moving-median":{category:"vector",description:"Returns the **moving median** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving median** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-median } = import(vector);\nmoving-median([1, 2, 3, 4, 5], 3)","let { moving-median } = import(vector);\nmoving-median([1, 2, 3, 4, 5], 5)"],seeAlso:["median","vector.centered-moving-median","vector.running-median"]},"centered-moving-median":{category:"vector",description:"Returns the **centered moving median** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving median** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-median } = import(vector);\ncentered-moving-median([1, 2, 3, 4, 5], 3)","let { centered-moving-median } = import(vector);\ncentered-moving-median([1, 2, 3, 4, 5], 3, 0, 10)","let { centered-moving-median } = import(vector);\ncentered-moving-median([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["median","vector.moving-median","vector.running-median"]},"running-median":{category:"vector",description:"Returns the **running median** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running median** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-median } = import(vector);\nrunning-median([1, 2, 3, 4, 5])"],seeAlso:["median","vector.moving-median","vector.centered-moving-median"]},variance:{category:"vector",description:"Returns the **variance** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **variance** of."}},variants:[{argumentNames:["vector"]}],examples:["let { variance } = import(vector);\nvariance([1, 2, 3])","let { variance } = import(vector);\nvariance([1, 2, -3])"],seeAlso:["linear-algebra.cov","vector.moving-variance","vector.centered-moving-variance","vector.running-variance","vector.stdev","vector.sample-variance","vector.mad"]},"moving-variance":{category:"vector",description:"Returns the **moving variance** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving variance** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-variance } = import(vector);\nmoving-variance([1, 2, 3, 4, 5], 3)","let { moving-variance } = import(vector);\nmoving-variance([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.variance","vector.centered-moving-variance","vector.running-variance"]},"centered-moving-variance":{category:"vector",description:"Returns the **centered moving variance** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving variance** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3)","let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-variance } = import(vector);\ncentered-moving-variance([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.variance","vector.moving-variance","vector.running-variance"]},"running-variance":{category:"vector",description:"Returns the **running variance** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running variance** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-variance } = import(vector);\nrunning-variance([1, 2, 3, 4, 5])"],seeAlso:["vector.variance","vector.moving-variance","vector.centered-moving-variance"]},"sample-variance":{category:"vector",description:"Returns the sample variance of all elements in the vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the sample variance of."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-variance } = import(vector);\nsample-variance([1, 2, 3])","let { sample-variance } = import(vector);\nsample-variance([1, 2, -3])","let { sample-variance } = import(vector);\nsample-variance([1, 2, 3, 4])","let { sample-variance } = import(vector);\nsample-variance([1, 2, -3, 4])","let { sample-variance } = import(vector);\nsample-variance([1, 2, 3, 40, 50])"],seeAlso:["vector.moving-sample-variance","vector.centered-moving-sample-variance","vector.running-sample-variance","vector.variance","vector.sample-stdev"]},"moving-sample-variance":{category:"vector",description:"Returns the **moving sample variance** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample variance** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-variance } = import(vector);\nmoving-sample-variance([1, 2, 3, 4, 5], 3)","let { moving-sample-variance } = import(vector);\nmoving-sample-variance([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.sample-variance","vector.centered-moving-sample-variance","vector.running-sample-variance"]},"centered-moving-sample-variance":{category:"vector",description:"Returns the **centered moving sample variance** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample variance** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3)","let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-sample-variance } = import(vector);\ncentered-moving-sample-variance([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.sample-variance","vector.moving-sample-variance","vector.running-sample-variance"]},"running-sample-variance":{category:"vector",description:"Returns the **running sample variance** of the `vector`.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample variance** of. First element in result is `null` since **sample variance** is not defined for a single element."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-variance } = import(vector);\nrunning-sample-variance([1, 2, 3, 4, 5])"],seeAlso:["vector.sample-variance","vector.moving-sample-variance","vector.centered-moving-sample-variance"]},stdev:{category:"vector",description:"Returns the standard deviation of all elements in the vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the standard deviation of."}},variants:[{argumentNames:["vector"]}],examples:["let { stdev } = import(vector);\nstdev([1, 2, 3])","let { stdev } = import(vector);\nstdev([1, 2, -3])","let { stdev } = import(vector);\nstdev([1, 2, 3, 4])","let { stdev } = import(vector);\nstdev([1, 2, -3, 4])","let { stdev } = import(vector);\nstdev([1, 2, 3, 40, 50])"],seeAlso:["vector.moving-stdev","vector.centered-moving-stdev","vector.running-stdev","vector.variance","vector.sample-stdev","vector.rms","vector.mad"]},"moving-stdev":{category:"vector",description:"Returns the **moving standard deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving standard deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-stdev } = import(vector);\nmoving-stdev([1, 2, 3, 4, 5], 3)","let { moving-stdev } = import(vector);\nmoving-stdev([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.stdev","vector.centered-moving-stdev","vector.running-stdev"]},"centered-moving-stdev":{category:"vector",description:"Returns the **centered moving standard deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving standard deviation** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3)","let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-stdev } = import(vector);\ncentered-moving-stdev([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.stdev","vector.moving-stdev","vector.running-stdev"]},"running-stdev":{category:"vector",description:"Returns the **running standard deviation** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running standard deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-stdev } = import(vector);\nrunning-stdev([1, 2, 3, 4, 5])"],seeAlso:["vector.stdev","vector.moving-stdev","vector.centered-moving-stdev"]},"sample-stdev":{category:"vector",description:"Returns the sample standard deviation of all elements in the vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the sample standard deviation of."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-stdev } = import(vector);\nsample-stdev([1, 2, 3])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, -3])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, 3, 4])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, -3, 4])","let { sample-stdev } = import(vector);\nsample-stdev([1, 2, 3, 40, 50])"],seeAlso:["vector.moving-sample-stdev","vector.centered-moving-sample-stdev","vector.running-sample-stdev","vector.stdev","vector.sample-variance"]},"moving-sample-stdev":{category:"vector",description:"Returns the **moving sample standard deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample standard deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-stdev } = import(vector);\nmoving-sample-stdev([1, 2, 3, 4, 5], 3)","let { moving-sample-stdev } = import(vector);\nmoving-sample-stdev([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.sample-stdev","vector.centered-moving-sample-stdev","vector.running-sample-stdev"]},"centered-moving-sample-stdev":{category:"vector",description:"Returns the **centered moving sample standard deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample standard deviation** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3)","let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 1)","let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 1, 5)","let { centered-moving-sample-stdev } = import(vector);\ncentered-moving-sample-stdev([1, 2, 3, 4, 5], 3, 0, 6)"],seeAlso:["vector.sample-stdev","vector.moving-sample-stdev","vector.running-sample-stdev"]},"running-sample-stdev":{category:"vector",description:"Returns the **running sample standard deviation** of the `vector`.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample standard deviation** of. First element in result is `null` since **sample standard deviation** is not defined for a single element."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-stdev } = import(vector);\nrunning-sample-stdev([1, 2, 3, 4, 5])"],seeAlso:["vector.sample-stdev","vector.moving-sample-stdev","vector.centered-moving-sample-stdev"]},iqr:{category:"vector",description:"Calculates the **interquartile range** of a `vector`. Returns the difference between the third and first quartiles.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **interquartile range** of. Minimum length is 4."}},variants:[{argumentNames:["vector"]}],examples:["let { iqr } = import(vector);\niqr([1, 2, 3, 4])","let { iqr } = import(vector);\niqr([5, 4, 3, 2, 1, 2, 3, 4, 5])","let { iqr } = import(vector);\niqr(range(1, 1000))","let { iqr } = import(vector);\niqr(map(range(1000), -> 1e6 / ($ + 1) ^ 2))","let { iqr } = import(vector);\nlet { ln } = import(math);\niqr(map(range(1000), -> ln($ + 1)))"],seeAlso:["vector.moving-iqr","vector.centered-moving-iqr","vector.running-iqr","vector.quartiles","median","vector.mad","vector.medad","vector.outliers?","vector.outliers"]},"moving-iqr":{category:"vector",description:"Calculates the **moving interquartile range** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving interquartile range** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-iqr } = import(vector);\nmoving-iqr([1, 2, 4, 7, 11, 16], 4)","let { moving-iqr } = import(vector);\nmoving-iqr([1, 2, 4, 7, 11, 16], 5)","let { moving-iqr } = import(vector);\nmoving-iqr([1, 2, 4, 7, 11, 16], 6)"],seeAlso:["vector.iqr","vector.centered-moving-iqr","vector.running-iqr"]},"centered-moving-iqr":{category:"vector",description:"Calculates the **centered moving interquartile range** of a `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving interquartile range** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-iqr } = import(vector);\ncentered-moving-iqr([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-iqr } = import(vector);\ncentered-moving-iqr([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.iqr","vector.moving-iqr","vector.running-iqr"]},"running-iqr":{category:"vector",description:"Calculates the **running interquartile range** of a `vector`. First three element in result is `null` since **running interquartile range** is not defined for less than four elements.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to calculate the **running interquartile range** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-iqr } = import(vector);\nrunning-iqr([1, 2, 3, 4, 5, 6])","let { running-iqr } = import(vector);\nrunning-iqr([-1, -2, -3, 1, 2, 3])"],seeAlso:["vector.iqr","vector.moving-iqr","vector.centered-moving-iqr"]},"moving-sum":{category:"vector",description:"Returns the **moving sum** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sum** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sum } = import(vector);\nmoving-sum([1, 2, 3, 4, 5], 3)","let { moving-sum } = import(vector);\nmoving-sum([1, 2, 3, 4, 5], 5)"],seeAlso:["sum","vector.centered-moving-sum","vector.running-sum"]},"centered-moving-sum":{category:"vector",description:"Returns the **centered moving sum** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sum** of."},windowSize:{type:"integer",description:"The size of the centered moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sum } = import(vector);\ncentered-moving-sum([1, 2, 3, 4, 5], 3)","let { centered-moving-sum } = import(vector);\ncentered-moving-sum([1, 2, 3, 4, 5], 3, 0, 0)","let { centered-moving-sum } = import(vector);\ncentered-moving-sum([1, 2, 3, 4, 5], 3, 10)"],seeAlso:["sum","vector.moving-sum","vector.running-sum"]},"running-sum":{category:"vector",description:"Returns the **running sum** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sum** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sum } = import(vector);\nrunning-sum([1, 2, 3])","let { running-sum } = import(vector);\nrunning-sum([1, -2, -3])"],seeAlso:["sum","vector.moving-sum","vector.centered-moving-sum","vector.cumsum"]},"moving-prod":{category:"vector",description:"Returns the **moving product** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving product** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-prod } = import(vector);\nmoving-prod([1, 2, 3, 4, 5], 3)","let { moving-prod } = import(vector);\nmoving-prod([1, 2, 3, 4, 5], 5)"],seeAlso:["prod","vector.centered-moving-prod","vector.running-prod"]},"centered-moving-prod":{category:"vector",description:"Returns the **centered moving product** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving product** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-prod } = import(vector);\ncentered-moving-prod([1, 2, 3, 4, 5], 3)","let { centered-moving-prod } = import(vector);\ncentered-moving-prod([1, 2, 3, 4, 5], 3, 0, 0)"],seeAlso:["prod","vector.moving-prod","vector.running-prod"]},"running-prod":{category:"vector",description:"Returns the **running product** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running product** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-prod } = import(vector);\nrunning-prod([1, 2, 3, 4, 5])","let { running-prod } = import(vector);\nrunning-prod([1, -2, -3])"],seeAlso:["prod","vector.moving-prod","vector.centered-moving-prod","vector.cumprod"]},span:{category:"vector",description:"Returns the difference between the maximum and minimum values in a vector.",returns:{type:"number"},args:{vector:{type:"vector",description:"The vector to calculate the span of."}},variants:[{argumentNames:["vector"]}],examples:["let { span } = import(vector);\nspan([1, 2, 3])","let { span } = import(vector);\nspan([1, 1, 2, 3, 3])","let { span } = import(vector);\nspan([1, 2, -3])"],seeAlso:["vector.moving-span","vector.centered-moving-span","vector.running-span","min","max"]},"moving-span":{category:"vector",description:"Calculates the **moving span** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving span** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-span } = import(vector);\nmoving-span([1, 2, 4, 7, 11, 16], 4)","let { moving-span } = import(vector);\nmoving-span([1, 2, 4, 7, 11, 16], 5)","let { moving-span } = import(vector);\nmoving-span([1, 2, 4, 7, 11, 16], 6)"],seeAlso:["vector.span","vector.centered-moving-span","vector.running-span"]},"centered-moving-span":{category:"vector",description:"Calculates the **centered moving span** of a `vector` with a given window size. The result is padded with `leftPadding` on the left and right.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving span** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"The value to pad the result with on the left."},rightPadding:{type:"number",description:"The value to pad the result with on the right."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-span } = import(vector);\ncentered-moving-span([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-span } = import(vector);\ncentered-moving-span([1, 2, 4, 7, 11, 16], 3, 0, 100)"],seeAlso:["vector.span","vector.moving-span","vector.running-span"]},"running-span":{category:"vector",description:"Calculates the **running span** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running span** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-span } = import(vector);\nrunning-span([1, 2, 4])"],seeAlso:["vector.span","vector.moving-span","vector.centered-moving-span"]},skewness:{category:"vector",description:"Calculates the **skewness** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **skewness** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { skewness } = import(vector);\nskewness([1, 2, 3, 6, 20])","let { skewness } = import(vector);\nskewness([1, 2, 2, 3])"],seeAlso:["vector.moving-skewness","vector.centered-moving-skewness","vector.running-skewness","vector.kurtosis","vector.sample-skewness","vector.excess-kurtosis"]},"moving-skewness":{category:"vector",description:"Calculates the **moving skewness** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-skewness } = import(vector);\nmoving-skewness([1, 2, 4, 7, 11, 16], 4)","let { moving-skewness } = import(vector);\nmoving-skewness([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.skewness","vector.centered-moving-skewness","vector.running-skewness"]},"centered-moving-skewness":{category:"vector",description:"Calculates the **centered moving skewness** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-skewness } = import(vector);\ncentered-moving-skewness([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-skewness } = import(vector);\ncentered-moving-skewness([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.skewness","vector.moving-skewness","vector.running-skewness"]},"running-skewness":{category:"vector",description:"Calculates the **running skewness** of a `vector` with a given window size. First two element in result is `null` since **running skewness** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running skewness** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-skewness } = import(vector);\nrunning-skewness([1, 2, 4, 7, 11])"],seeAlso:["vector.skewness","vector.moving-skewness","vector.centered-moving-skewness"]},"sample-skewness":{category:"vector",description:"Calculates the **sample skewness** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **sample skewness** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-skewness } = import(vector);\nsample-skewness([1, 2, 3, 6, 20])","let { sample-skewness } = import(vector);\nsample-skewness([1, 2, 2, 3])"],seeAlso:["vector.moving-sample-skewness","vector.centered-moving-sample-skewness","vector.running-sample-skewness","vector.skewness","vector.sample-kurtosis"]},"moving-sample-skewness":{category:"vector",description:"Calculates the **moving sample skewness** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-skewness } = import(vector);\nmoving-sample-skewness([1, 2, 4, 7, 11, 16], 4)","let { moving-sample-skewness } = import(vector);\nmoving-sample-skewness([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.sample-skewness","vector.centered-moving-sample-skewness","vector.running-sample-skewness"]},"centered-moving-sample-skewness":{category:"vector",description:"Calculates the **centered moving sample skewness** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample skewness** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-skewness } = import(vector);\ncentered-moving-sample-skewness([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-sample-skewness } = import(vector);\ncentered-moving-sample-skewness([1, 2, 4, 7, 11, 16], 3, 0, 100)"],seeAlso:["vector.sample-skewness","vector.moving-sample-skewness","vector.running-sample-skewness"]},"running-sample-skewness":{category:"vector",description:"Calculates the **running sample skewness** of a `vector` with a given window size. First two element in result is `null` since **running sample skewness** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample skewness** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-skewness } = import(vector);\nrunning-sample-skewness([1, 2, 4, 7, 11])"],seeAlso:["vector.sample-skewness","vector.moving-sample-skewness","vector.centered-moving-sample-skewness"]},"excess-kurtosis":{category:"vector",description:"Calculates the **excess kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **excess kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { excess-kurtosis } = import(vector);\nexcess-kurtosis([1, 2, 3, 6, 20])","let { excess-kurtosis } = import(vector);\nexcess-kurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-excess-kurtosis","vector.centered-moving-excess-kurtosis","vector.running-excess-kurtosis","vector.kurtosis","vector.sample-excess-kurtosis","vector.skewness"]},"moving-excess-kurtosis":{category:"vector",description:"Calculates the **moving excess kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-excess-kurtosis } = import(vector);\nmoving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-excess-kurtosis } = import(vector);\nmoving-excess-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.excess-kurtosis","vector.centered-moving-excess-kurtosis","vector.running-excess-kurtosis"]},"centered-moving-excess-kurtosis":{category:"vector",description:"Calculates the **centered moving excess kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-excess-kurtosis } = import(vector);\ncentered-moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-excess-kurtosis } = import(vector);\ncentered-moving-excess-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.excess-kurtosis","vector.moving-excess-kurtosis","vector.running-excess-kurtosis"]},"running-excess-kurtosis":{category:"vector",description:"Calculates the **running excess kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running excess kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running excess kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-excess-kurtosis } = import(vector);\nrunning-excess-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.excess-kurtosis","vector.moving-excess-kurtosis","vector.centered-moving-excess-kurtosis"]},kurtosis:{category:"vector",description:"Calculates the **kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { kurtosis } = import(vector);\nkurtosis([1, 2, 3, 6, 20])","let { kurtosis } = import(vector);\nkurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-kurtosis","vector.centered-moving-kurtosis","vector.running-kurtosis","vector.excess-kurtosis","vector.sample-kurtosis","vector.skewness"]},"moving-kurtosis":{category:"vector",description:"Calculates the **moving kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-kurtosis } = import(vector);\nmoving-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-kurtosis } = import(vector);\nmoving-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.kurtosis","vector.centered-moving-kurtosis","vector.running-kurtosis"]},"centered-moving-kurtosis":{category:"vector",description:"Calculates the **centered moving kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-kurtosis } = import(vector);\ncentered-moving-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-kurtosis } = import(vector);\ncentered-moving-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 0)"],seeAlso:["vector.kurtosis","vector.moving-kurtosis","vector.running-kurtosis"]},"running-kurtosis":{category:"vector",description:"Calculates the **running kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-kurtosis } = import(vector);\nrunning-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.kurtosis","vector.moving-kurtosis","vector.centered-moving-kurtosis"]},"sample-excess-kurtosis":{category:"vector",description:"Calculates the **sample excess kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **sample excess kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-excess-kurtosis } = import(vector);\nsample-excess-kurtosis([1, 2, 3, 6, 20])","let { sample-excess-kurtosis } = import(vector);\nsample-excess-kurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-sample-excess-kurtosis","vector.centered-moving-sample-excess-kurtosis","vector.running-sample-excess-kurtosis","vector.sample-kurtosis","vector.excess-kurtosis"]},"moving-sample-excess-kurtosis":{category:"vector",description:"Calculates the **moving sample excess kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-excess-kurtosis } = import(vector);\nmoving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-sample-excess-kurtosis } = import(vector);\nmoving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.sample-excess-kurtosis","vector.centered-moving-sample-excess-kurtosis","vector.running-sample-excess-kurtosis"]},"centered-moving-sample-excess-kurtosis":{category:"vector",description:"Calculates the **centered moving sample excess kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample excess kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-excess-kurtosis } = import(vector);\ncentered-moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-sample-excess-kurtosis } = import(vector);\ncentered-moving-sample-excess-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 100)"],seeAlso:["vector.sample-excess-kurtosis","vector.moving-sample-excess-kurtosis","vector.running-sample-excess-kurtosis"]},"running-sample-excess-kurtosis":{category:"vector",description:"Calculates the **running sample excess kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running sample excess kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample excess kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-excess-kurtosis } = import(vector);\nrunning-sample-excess-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.sample-excess-kurtosis","vector.moving-sample-excess-kurtosis","vector.centered-moving-sample-excess-kurtosis"]},"sample-kurtosis":{category:"vector",description:"Calculates the **sample kurtosis** of a `vector`. Returns the third standardized moment.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **sample kurtosis** of. Minimum length is 3."}},variants:[{argumentNames:["vector"]}],examples:["let { sample-kurtosis } = import(vector);\nsample-kurtosis([1, 2, 3, 6, 20])","let { sample-kurtosis } = import(vector);\nsample-kurtosis([1, 2, 2, 3])"],seeAlso:["vector.moving-sample-kurtosis","vector.centered-moving-sample-kurtosis","vector.running-sample-kurtosis","vector.sample-excess-kurtosis","vector.kurtosis","vector.sample-skewness"]},"moving-sample-kurtosis":{category:"vector",description:"Calculates the **moving sample kurtosis** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving sample kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-sample-kurtosis } = import(vector);\nmoving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { moving-sample-kurtosis } = import(vector);\nmoving-sample-kurtosis([1, 2, 4, 7, 11, 16], 5)"],seeAlso:["vector.sample-kurtosis","vector.centered-moving-sample-kurtosis","vector.running-sample-kurtosis"]},"centered-moving-sample-kurtosis":{category:"vector",description:"Calculates the **centered moving sample kurtosis** of a `vector` with a given window size and padding.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving sample kurtosis** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-sample-kurtosis } = import(vector);\ncentered-moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-sample-kurtosis } = import(vector);\ncentered-moving-sample-kurtosis([1, 2, 4, 7, 11, 16], 4, 0, 100)"],seeAlso:["vector.sample-kurtosis","vector.moving-sample-kurtosis","vector.running-sample-kurtosis"]},"running-sample-kurtosis":{category:"vector",description:"Calculates the **running sample kurtosis** of a `vector` with a given window size. First two element in result is `null` since **running sample kurtosis** is not defined for less than three elements.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running sample kurtosis** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-sample-kurtosis } = import(vector);\nrunning-sample-kurtosis([1, 2, 4, 7, 11])"],seeAlso:["vector.sample-kurtosis","vector.moving-sample-kurtosis","vector.centered-moving-sample-kurtosis"]},rms:{category:"vector",description:"Calculates the **root mean square** of a `vector`. Returns the square root of the average of the squares of the elements.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **root mean square** of. Minimum length is 1."}},variants:[{argumentNames:["vector"]}],examples:["let { rms } = import(vector);\nrms([1, 2, 3, 4])","let { rms } = import(vector);\nrms([5, 4, 3, 2, 1])","let { rms } = import(vector);\nrms(range(1, 1000))","let { rms } = import(vector);\nrms(map(range(1000), -> 1e6 / ($ + 1) ^ 2))","let { rms } = import(vector);\nlet { ln } = import(math);\nrms(map(range(1000), -> ln($ + 1)))"],seeAlso:["vector.moving-rms","vector.centered-moving-rms","vector.running-rms","mean","vector.stdev"]},"moving-rms":{category:"vector",description:"Calculates the **moving root mean square** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving root mean square** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-rms } = import(vector);\nmoving-rms([1, 2, 4, 7, 11, 16], 4)","let { moving-rms } = import(vector);\nmoving-rms([1, 2, 4, 7, 11, 16], 5)","let { moving-rms } = import(vector);\nmoving-rms([1, 2, 4, 7, 11, 16], 6)"],seeAlso:["vector.rms","vector.centered-moving-rms","vector.running-rms"]},"centered-moving-rms":{category:"vector",description:"Calculates the **centered moving root mean square** of a `vector` with a given window size and padding value.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving root mean square** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-rms } = import(vector);\ncentered-moving-rms([1, 2, 4, 7, 11, 16], 4)","let { centered-moving-rms } = import(vector);\ncentered-moving-rms([1, 2, 4, 7, 11, 16], 5, 0)","let { centered-moving-rms } = import(vector);\ncentered-moving-rms([1, 2, 4, 7, 11, 16], 6, 0, 0)"],seeAlso:["vector.rms","vector.moving-rms","vector.running-rms"]},"running-rms":{category:"vector",description:"Calculates the **running root mean square** of a `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running root mean square** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-rms } = import(vector);\nrunning-rms([1, 2, 3, 4, 5, 6])","let { running-rms } = import(vector);\nrunning-rms([1, -3, 2])","let { running-rms } = import(vector);\nrunning-rms([-1, -2, -3])","let { running-rms } = import(vector);\nrunning-rms([0])"],seeAlso:["vector.rms","vector.moving-rms","vector.centered-moving-rms"]},mad:{category:"vector",description:"Returns the **mean absolute deviation** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **mean absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { mad } = import(vector);\nmad([1, 2, 3])","let { mad } = import(vector);\nmad([1, 2, -3])"],seeAlso:["vector.moving-mad","vector.centered-moving-mad","vector.running-mad","vector.medad","vector.stdev","vector.variance","vector.iqr"]},"moving-mad":{category:"vector",description:"Returns the **moving mean absolute deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving mean absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-mad } = import(vector);\nmoving-mad([1, 2, 3, 4, 5], 3)","let { moving-mad } = import(vector);\nmoving-mad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.mad","vector.centered-moving-mad","vector.running-mad"]},"centered-moving-mad":{category:"vector",description:"Returns the **centered moving mean absolute deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving mean absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-mad } = import(vector);\ncentered-moving-mad([1, 2, 3, 4, 5], 3)","let { centered-moving-mad } = import(vector);\ncentered-moving-mad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.mad","vector.moving-mad","vector.running-mad"]},"running-mad":{category:"vector",description:"Returns the **running mean absolute deviation** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running mean absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-mad } = import(vector);\nrunning-mad([1, 2, 3])","let { running-mad } = import(vector);\nrunning-mad([1, 2, -3])"],seeAlso:["vector.mad","vector.moving-mad","vector.centered-moving-mad"]},medad:{category:"vector",description:"Returns the **median absolute deviation** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **median absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { medad } = import(vector);\nmedad([1, 2, 3])","let { medad } = import(vector);\nmedad([1, 2, -3])"],seeAlso:["vector.moving-medad","vector.centered-moving-medad","vector.running-medad","vector.mad","median","vector.iqr"]},"moving-medad":{category:"vector",description:"Returns the **moving median absolute deviation** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving median absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-medad } = import(vector);\nmoving-medad([1, 2, 3, 4, 5], 3)","let { moving-medad } = import(vector);\nmoving-medad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.medad","vector.centered-moving-medad","vector.running-medad"]},"centered-moving-medad":{category:"vector",description:"Returns the **centered moving median absolute deviation** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving median absolute deviation** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-medad } = import(vector);\ncentered-moving-medad([1, 2, 3, 4, 5], 3)","let { centered-moving-medad } = import(vector);\ncentered-moving-medad([1, 2, 3, 4, 5], 5)"],seeAlso:["vector.medad","vector.moving-medad","vector.running-medad"]},"running-medad":{category:"vector",description:"Returns the **running median absolute deviation** of the `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running median absolute deviation** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-medad } = import(vector);\nrunning-medad([1, 2, 3])","let { running-medad } = import(vector);\nrunning-medad([1, 2, -3])"],seeAlso:["vector.medad","vector.moving-medad","vector.centered-moving-medad"]},"gini-coefficient":{category:"vector",description:"Returns the **gini coefficient** of all elements in the `vector`.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **gini coefficient** of."}},variants:[{argumentNames:["vector"]}],examples:["let { gini-coefficient } = import(vector);\ngini-coefficient([1, 2, 3])","let { gini-coefficient } = import(vector);\ngini-coefficient([1, 1, 3])"],seeAlso:["vector.moving-gini-coefficient","vector.centered-moving-gini-coefficient","vector.running-gini-coefficient","vector.entropy"]},"moving-gini-coefficient":{category:"vector",description:"Returns the **moving gini coefficient** of the `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving gini coefficient** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-gini-coefficient } = import(vector);\nmoving-gini-coefficient([1, 2, 3], 2)","let { moving-gini-coefficient } = import(vector);\nmoving-gini-coefficient([1, 1, 3], 2)"],seeAlso:["vector.gini-coefficient","vector.centered-moving-gini-coefficient","vector.running-gini-coefficient"]},"centered-moving-gini-coefficient":{category:"vector",description:"Returns the **centered moving gini coefficient** of the `vector` with a given window size.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving gini coefficient** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-gini-coefficient } = import(vector);\ncentered-moving-gini-coefficient([1, 2, 3], 2)","let { centered-moving-gini-coefficient } = import(vector);\ncentered-moving-gini-coefficient([1, 1, 3], 2)"],seeAlso:["vector.gini-coefficient","vector.moving-gini-coefficient","vector.running-gini-coefficient"]},"running-gini-coefficient":{category:"vector",description:"Returns the **running gini coefficient** of the `vector`.",returns:{type:"array"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running gini coefficient** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-gini-coefficient } = import(vector);\nrunning-gini-coefficient([1, 2, 3])","let { running-gini-coefficient } = import(vector);\nrunning-gini-coefficient([1, 1, 3])"],seeAlso:["vector.gini-coefficient","vector.moving-gini-coefficient","vector.centered-moving-gini-coefficient"]},entropy:{category:"vector",description:"Calculates the **entropy** of a `vector`. The entropy is a measure of the uncertainty associated with a random variable.",returns:{type:"number"},args:{vector:{type:"vector",description:"The `vector` to calculate the **entropy** of. Minimum length is 1."}},variants:[{argumentNames:["vector"]}],examples:["let { entropy } = import(vector);\nentropy([1, 1, 2, 3, 3, 3])","let { entropy } = import(vector);\nentropy([1, 2, 3])","let { entropy } = import(vector);\nentropy([1, 2, 2, 3])","let { entropy } = import(vector);\nentropy([0])","let { entropy } = import(vector);\nentropy([1])","let { entropy } = import(vector);\nentropy([1, 2])"],seeAlso:["vector.moving-entropy","vector.centered-moving-entropy","vector.running-entropy","vector.gini-coefficient"]},"moving-entropy":{category:"vector",description:"Calculates the **moving entropy** of a `vector` with a given window size.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **moving entropy** of."},windowSize:{type:"integer",description:"The size of the moving window."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]}],examples:["let { moving-entropy } = import(vector);\nmoving-entropy([1, 1, 2, 3, 3, 3], 4)","let { moving-entropy } = import(vector);\nmoving-entropy([1, 1, 2, 3, 3, 3], 3)","let { moving-entropy } = import(vector);\nmoving-entropy([1, 2], 2)"],seeAlso:["vector.entropy","vector.centered-moving-entropy","vector.running-entropy"]},"centered-moving-entropy":{category:"vector",description:"Calculates the **centered moving entropy** of a `vector` with a given window size.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to calculate the **centered moving entropy** of."},windowSize:{type:"integer",description:"The size of the moving window."},leftPadding:{type:"number",description:"Optional value to use for padding. Default is `null`."},rightPadding:{type:"number",description:"Optional value to use for right padding. Default is `null`."},a:{type:"vector"},b:{type:"integer"}},variants:[{argumentNames:["vector","windowSize"]},{argumentNames:["vector","windowSize","leftPadding"]},{argumentNames:["vector","windowSize","leftPadding","rightPadding"]}],examples:["let { centered-moving-entropy } = import(vector);\ncentered-moving-entropy([1, 1, 2, 3, 3, 3], 4)","let { centered-moving-entropy } = import(vector);\ncentered-moving-entropy([1, 1, 2, 3, 3, 3], 3)","let { centered-moving-entropy } = import(vector);\ncentered-moving-entropy([1, 2], 2)"],seeAlso:["vector.entropy","vector.moving-entropy","vector.running-entropy"]},"running-entropy":{category:"vector",description:"Calculates the **running entropy** of a `vector`.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The `vector` to calculate the **running entropy** of."}},variants:[{argumentNames:["vector"]}],examples:["let { running-entropy } = import(vector);\nrunning-entropy([1, 1, 2, 3, 3, 3])","let { running-entropy } = import(vector);\nrunning-entropy([1, 2])"],seeAlso:["vector.entropy","vector.moving-entropy","vector.centered-moving-entropy"]},"monotonic?":{category:"vector",description:"Checks if a vector is monotonic.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { monotonic? } = import(vector);\nmonotonic?([1, 2, 3])","let { monotonic? } = import(vector);\nmonotonic?([1, 2, 2, 3])","let { monotonic? } = import(vector);\nmonotonic?([3, 2, 1])","let { monotonic? } = import(vector);\nmonotonic?([3, 2, 1, 1])","let { monotonic? } = import(vector);\nmonotonic?([3, 2, 1, 2])","let { monotonic? } = import(vector);\nmonotonic?([1])","let { monotonic? } = import(vector);\nmonotonic?([])"],seeAlso:["vector.strictly-monotonic?","vector.increasing?","vector.decreasing?"]},"strictly-monotonic?":{category:"vector",description:"Checks if a vector is strictly monotonic.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([1, 2, 3])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([1, 2, 2, 3])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([3, 2, 1])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([3, 2, 1, 1])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([3, 2, 1, 2])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([1])","let { strictly-monotonic? } = import(vector);\nstrictly-monotonic?([])"],seeAlso:["vector.monotonic?","vector.strictly-increasing?","vector.strictly-decreasing?"]},"increasing?":{category:"vector",description:"Checks if a vector is increasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { increasing? } = import(vector);\nincreasing?([1, 2, 3])","let { increasing? } = import(vector);\nincreasing?([1, 2, 2, 3])","let { increasing? } = import(vector);\nincreasing?([3, 2, 1])","let { increasing? } = import(vector);\nincreasing?([3, 2, 1, 1])","let { increasing? } = import(vector);\nincreasing?([3, 2, 1, 2])","let { increasing? } = import(vector);\nincreasing?([1])","let { increasing? } = import(vector);\nincreasing?([])"],seeAlso:["vector.strictly-increasing?","vector.decreasing?","vector.strictly-decreasing?","vector.monotonic?"]},"decreasing?":{category:"vector",description:"Checks if a vector is decreasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { decreasing? } = import(vector);\ndecreasing?([1, 2, 3])","let { decreasing? } = import(vector);\ndecreasing?([1, 2, 2, 3])","let { decreasing? } = import(vector);\ndecreasing?([3, 2, 1])","let { decreasing? } = import(vector);\ndecreasing?([3, 2, 1, 1])","let { decreasing? } = import(vector);\ndecreasing?([3, 2, 1, 2])","let { decreasing? } = import(vector);\ndecreasing?([1])","let { decreasing? } = import(vector);\ndecreasing?([])"],seeAlso:["vector.strictly-decreasing?","vector.increasing?","vector.strictly-increasing?","vector.monotonic?"]},"strictly-increasing?":{category:"vector",description:"Checks if a vector is strictly increasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { strictly-increasing? } = import(vector);\nstrictly-increasing?([1, 2, 3])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([1, 2, 2, 3])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([3, 2, 1])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([3, 2, 1, 1])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([3, 2, 1, 2])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([1])","let { strictly-increasing? } = import(vector);\nstrictly-increasing?([])"],seeAlso:["vector.increasing?","vector.decreasing?","vector.strictly-decreasing?","vector.strictly-monotonic?"]},"strictly-decreasing?":{category:"vector",description:"Checks if a vector is strictly decreasing.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The vector to check."}},variants:[{argumentNames:["vector"]}],examples:["let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([1, 2, 3])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([1, 2, 2, 3])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([3, 2, 1])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([3, 2, 1, 1])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([3, 2, 1, 2])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([1])","let { strictly-decreasing? } = import(vector);\nstrictly-decreasing?([])"],seeAlso:["vector.increasing?","vector.strictly-increasing?","vector.decreasing?","vector.strictly-monotonic?"]},mode:{category:"vector",description:"Returns the mode of all elements in the vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the mode of."}},variants:[{argumentNames:["vector"]}],examples:["let { mode } = import(vector);\nmode([1, 2, 3])","let { mode } = import(vector);\nmode([1, 2, -3, 1])","let { mode } = import(vector);\nmode([2, 2, 3, 3, 4])","let { mode } = import(vector);\nmode([2, 2, 3, 3])","let { mode } = import(vector);\nmode([1, 2, 3, 2, 1, 2])"],seeAlso:["mean","median"]},"min-index":{category:"vector",description:"Returns the index of the minimum value of all elements in the vector.",returns:{type:"integer"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the minimum index of."}},variants:[{argumentNames:["vector"]}],examples:["let { min-index } = import(vector);\nmin-index([1, 2, 3])","let { min-index } = import(vector);\nmin-index([1, 1, 2, 3, 3])","let { min-index } = import(vector);\nmin-index([1, 2, -3])","let { min-index } = import(vector);\nmin-index([1, 2, 3, 4])","let { min-index } = import(vector);\nmin-index([1, 2, -3, 4])"],seeAlso:["vector.max-index","min"]},"max-index":{category:"vector",description:"Returns the index of the maximum value of all elements in the vector.",returns:{type:"integer"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the maximum index of."}},variants:[{argumentNames:["vector"]}],examples:["let { max-index } = import(vector);\nmax-index([1, 2, 3])","let { max-index } = import(vector);\nmax-index([1, 1, 2, 3, 3])","let { max-index } = import(vector);\nmax-index([1, 2, -3])","let { max-index } = import(vector);\nmax-index([1, 2, 3, 4])","let { max-index } = import(vector);\nmax-index([1, 2, -3, 4])"],seeAlso:["vector.min-index","max"]},"sort-indices":{category:"vector",description:"Returns the indices of the elements in the vector sorted in ascending order.",returns:{type:"vector"},args:{vector:{type:"vector",description:"Non emtpy vector to calculate the sorted indices of."}},variants:[{argumentNames:["vector"]}],examples:["let { sort-indices } = import(vector);\nsort-indices([1, 2, 3])","let { sort-indices } = import(vector);\nsort-indices([1, 1, 2, 3, 3])","let { sort-indices } = import(vector);\nsort-indices([1, 2, -3])","let { sort-indices } = import(vector);\nsort-indices([1, 2, 3, 4])","let { sort-indices } = import(vector);\nsort-indices([1, 2, -3, 4])"],seeAlso:["sort"]},"count-values":{category:"vector",description:"Counts the number of occurrences of each value in the vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"Vector to count the values of."}},variants:[{argumentNames:["vector"]}],examples:["let { count-values } = import(vector);\ncount-values([1, 2, 3])","let { count-values } = import(vector);\ncount-values([1, 1, 2, 3, 3])","let { count-values } = import(vector);\ncount-values([1, 2, -3])","let { count-values } = import(vector);\ncount-values([1, 2, 2, 1, 3, 2, 4, 2, 1, 2, 2, 1, 3, 2, 4])"],seeAlso:["sequence.frequencies","vector.bincount"]},linspace:{category:"vector",description:"Generates a vector of evenly spaced numbers between two values.",returns:{type:"number",array:!0},args:{start:{type:"number",description:"The starting value."},stop:{type:"number",description:"The ending value."},n:{type:"integer",description:"The number of values to generate."}},variants:[{argumentNames:["start","stop","n"]}],examples:["let { linspace } = import(vector);\nlinspace(0, 10, 6)","let { linspace } = import(vector);\nlinspace(10, 20, 25)"],seeAlso:["range"]},cumsum:{category:"vector",description:"Calculates the cumulative sum of a vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the cumulative sum of."}},variants:[{argumentNames:["vector"]}],examples:["let { cumsum } = import(vector);\ncumsum([1, 2, 3])","let { cumsum } = import(vector);\ncumsum([1, 2, -3])","let { cumsum } = import(vector);\ncumsum([])"],seeAlso:["vector.cumprod","sum","vector.running-sum"]},cumprod:{category:"vector",description:"Calculates the cumulative product of a vector.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the cumulative product of."}},variants:[{argumentNames:["vector"]}],examples:["let { cumprod } = import(vector);\ncumprod([1, 2, 3])","let { cumprod } = import(vector);\ncumprod([1, 2, -3, 0, 10])","let { cumprod } = import(vector);\ncumprod([])"],seeAlso:["vector.cumsum","prod","vector.running-prod"]},quartiles:{category:"vector",description:"Calculates the quartiles of a vector. Returns an array containing the first, second (median), and third quartiles.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The vector to calculate the quartiles of. Minimum length is 4."}},variants:[{argumentNames:["vector"]}],examples:["let { quartiles } = import(vector);\nquartiles([1, 2, 3, 4])","let { quartiles } = import(vector);\nquartiles([5, 4, 3, 2, 1, 2, 3, 4, 5])","let { quartiles } = import(vector);\nquartiles(range(1, 1000))","let { quartiles } = import(vector);\nquartiles(map(range(1000), -> 1e6 / ($ + 1) ^ 2))","let { quartiles } = import(vector);\nlet { ln } = import(math);\nquartiles(map(range(1000), -> ln($ + 1)))"],seeAlso:["vector.percentile","vector.quantile","median","vector.iqr"]},percentile:{category:"vector",description:"Calculates the percentile of a vector. Returns the value at the specified percentile.",returns:{type:"number"},args:{vector:{type:"vector",description:"The non empty vector to calculate the percentile of."},percentile:{type:"number",description:"The percentile to calculate. Must be between 0 and 1."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","percentile"]}],examples:["let { percentile } = import(vector);\npercentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 35)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 0)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 10)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 20)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 30)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 40)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 50)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 60)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 70)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 80)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 90)","let { percentile } = import(vector);\npercentile(range(100) ^ 0.5, 100)"],seeAlso:["vector.quantile","vector.quartiles","median","vector.ecdf","vector.winsorize"]},quantile:{category:"vector",description:"Calculates the quantile of a vector. Returns the value at the specified quantile.",returns:{type:"number"},args:{vector:{type:"vector",description:"The non empty vector to calculate the quantile of."},quantile:{type:"number",description:"The quantile to calculate. Must be between 0 and 1."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","quantile"]}],examples:["let { quantile } = import(vector);\nquantile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0.35)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.1)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.2)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.3)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.4)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.5)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.6)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.7)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.8)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 0.9)","let { quantile } = import(vector);\nquantile(range(100) ^ 0.5, 1)"],seeAlso:["vector.percentile","vector.quartiles","vector.ecdf"]},histogram:{category:"vector",description:"Creates a histogram from a numeric `array` by dividing the data range into the specified number of bins. Returns an `array` of `[binStart, binEnd, count]` tuples representing each bin's range and the number of values within it. Handles empty arrays, identical values, and properly places maximum values in the last bin.",returns:{type:"array",array:!0},args:{vector:{type:"vector",description:"The numeric array to create a histogram from."},bins:{type:"integer",description:"The number of bins to divide the data range into."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","bins"]}],examples:["let { histogram } = import(vector);\nhistogram([1, 2, 2, 3, 2, 6, 4, 3, 2, 4, 1, 3, 2, 9], 3)","let { histogram } = import(vector);\nhistogram([1, 2, 3, 4, 5], 5)","let { histogram } = import(vector);\nhistogram([1, 2, 3, 4, 5], 10)","let { histogram } = import(vector);\nhistogram([1, 2, 3, 4, 5], 1)"],seeAlso:["vector.bincount","vector.ecdf"]},ecdf:{category:"vector",description:"Calculates the empirical cumulative distribution function value for a given threshold in a non empty dataset. Returns the proportion of values in the `array` that are less than or equal to the specified threshold.",returns:{type:"number"},args:{vector:{type:"vector",description:"The numeric array to calculate the ECDF from."},threshold:{type:"number",description:"The threshold value to calculate the ECDF for."},a:{type:"number"},b:{type:"integer"}},variants:[{argumentNames:["vector","threshold"]}],examples:["let { ecdf } = import(vector);\necdf([1, 2, 2, 3, 2, 6, 4, 3, 2, 4, 1, 3, 2, 9, 10, 12], 5)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 3)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 0)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 10)","let { ecdf } = import(vector);\necdf([1, 2, 3, 4, 5], 2)"],seeAlso:["vector.histogram","vector.percentile","vector.quantile"]},"outliers?":{category:"vector",description:"Checks if the `vector` contains outliers based on the interquartile range (IQR) method. Returns `true` if outliers are present, `false` otherwise.",returns:{type:"boolean"},args:{vector:{type:"vector",description:"The `vector` to check for outliers."}},variants:[{argumentNames:["vector"]}],examples:["let { outliers? } = import(vector);\noutliers?([1, 2, 3])","let { outliers? } = import(vector);\noutliers?([1, 2, -3])","let { outliers? } = import(vector);\noutliers?([1, 2, 3, 2, 4, 120])"],seeAlso:["vector.outliers","vector.winsorize","vector.iqr"]},outliers:{category:"vector",description:"Identifies outliers in the `vector` based on the interquartile range (IQR) method. Returns an array of outlier values.",returns:{type:"number",array:!0},args:{vector:{type:"vector",description:"The `vector` to check for outliers."}},variants:[{argumentNames:["vector"]}],examples:["let { outliers } = import(vector);\noutliers([1, 2, 3])","let { outliers } = import(vector);\noutliers([1, 2, -3])","let { outliers } = import(vector);\noutliers([1, 2, 3, 2, 4, 120])"],seeAlso:["vector.outliers?","vector.winsorize","vector.iqr"]},bincount:{category:"vector",description:"counts occurrences of each `integer` in a vector, returning an array where index `i` contains the count of value `i`, with optional **minimum size** and **weights parameters**.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The vector to count occurrences in."},minSize:{type:"integer",description:"Optional minimum size of the output array."},weights:{type:"number",array:!0,description:"Optional weights for each element in the vector."}},variants:[{argumentNames:["vector"]},{argumentNames:["vector","minSize"]},{argumentNames:["vector","minSize","weights"]}],examples:["let { bincount } = import(vector);\nbincount([1, 2, 3])","let { bincount } = import(vector);\nbincount([1, 2, 2, 3, 3])"],seeAlso:["vector.count-values","vector.histogram"],hideOperatorForm:!0},winsorize:{category:"vector",description:"Limits extreme values in a `vector` by replacing values below the **lower quantile** and above the **upper quantile** with the values at those quantiles. The function takes a `vector` of values and **quantile thresholds** (between 0 and 1), with the upper quantile. Winsorization reduces the influence of outliers while preserving the overall distribution shape, making statistical analyses more robust.",returns:{type:"vector"},args:{vector:{type:"vector",description:"The vector to winsorize."},"lower-quantile":{type:"number",description:"The lower quantile threshold (between 0 and 1)."},"upper-quantile":{type:"number",description:"Optional Upper quantile threshold (between 0 and 1). Defaults to `(1 - lower-quantile)` if `lower-quantile <= 0.5` otherwise `1`."}},variants:[{argumentNames:["vector","lower-quantile"]},{argumentNames:["vector","lower-quantile","upper-quantile"]}],examples:["let { winsorize } = import(vector);\nwinsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25)","let { winsorize } = import(vector);\nwinsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25, 0.75)","let { winsorize } = import(vector);\nwinsorize([2, 5, 8, 10, 15, 18, 20, 35, 60, 100], 0.25, 0.5)"],seeAlso:["vector.outliers","vector.outliers?","vector.percentile"],hideOperatorForm:!0},mse:{category:"vector",description:"Calculates the **Mean Squared Error (MSE)** between two vectors. Returns the average of the squared differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { mse } = import(vector);\nmse([1, 2, 3], [1, 2, 3])","let { mse } = import(vector);\nmse([1, 2, 3], [4, 5, 6])","let { mse } = import(vector);\nmse([1, 2, 3], [2, 2, 2])","let { mse } = import(vector);\nmse([1, 2], [3, 3])","let { mse } = import(vector);\nmse([1], [3])"],seeAlso:["vector.rmse","vector.mae","vector.smape"]},rmse:{category:"vector",description:"Calculates the **Root Mean Squared Error (RMSE)** between two vectors. Returns the square root of the average of the squared differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { rmse } = import(vector);\nrmse([1, 2, 3], [1, 2, 3])","let { rmse } = import(vector);\nrmse([1, 2, 3], [4, 5, 6])","let { rmse } = import(vector);\nrmse([1, 2, 3], [2, 2, 2])","let { rmse } = import(vector);\nrmse([1, 2], [3, 3])","let { rmse } = import(vector);\nrmse([1], [3])"],seeAlso:["vector.mse","vector.mae","vector.smape"]},mae:{category:"vector",description:"Calculates the **Mean Absolute Error (MAE)** between two vectors. Returns the average of the absolute differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { mae } = import(vector);\nmae([1, 2, 3], [1, 2, 3])","let { mae } = import(vector);\nmae([1, 2, 3], [4, 5, 6])","let { mae } = import(vector);\nmae([1, 2, 3], [2, 2, 2])","let { mae } = import(vector);\nmae([1, 2], [3, 3])","let { mae } = import(vector);\nmae([1], [3])"],seeAlso:["vector.mse","vector.rmse","vector.smape"]},smape:{category:"vector",description:"Calculates the **Symmetric Mean Absolute Percentage Error (SMAPE)** between two vectors. Returns the average of the absolute percentage differences between corresponding elements.",returns:{type:"number"},args:{a:{type:"vector",description:"The first vector."},b:{type:"vector",description:"The second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { smape } = import(vector);\nsmape([1, 2, 3], [1, 2, 3])","let { smape } = import(vector);\nsmape([1, 2, 3], [4, 5, 6])","let { smape } = import(vector);\nsmape([1, 2, 3], [2, 2, 2])","let { smape } = import(vector);\nsmape([1, 2], [3, 3])","let { smape } = import(vector);\nsmape([1], [3])"],seeAlso:["vector.mse","vector.rmse","vector.mae"]}};function ka(e){if(e.length<=1)return[];const t=[...e].sort((e,t)=>e-t),r=Math.floor(.25*t.length),n=t.length%4==0?(t[r-1]+t[r])/2:t[r],o=Math.floor(.75*t.length),a=t.length%4==0?(t[o-1]+t[o])/2:t[o],i=a-n,s=n-1.5*i,l=a+1.5*i;return e.filter(e=>e<s||e>l)}function qa(e,t){const r=[...e].sort((e,t)=>e-t);if(0===t)return r[0];if(100===t)return r[r.length-1];const n=t/100*(r.length-1);if(Number.isInteger(n))return r[n];const o=Math.floor(n),a=Math.ceil(n),i=n-o;return r[o]*(1-i)+r[a]*i}function Aa(e){const t=[...e].sort((e,t)=>e-t),r=t.length/2;let n;n=t.length%2==0?(t[r-1]+t[r])/2:t[Math.floor(r)];const o=t.slice(0,Math.floor(t.length/2)),a=t.slice(Math.ceil(t.length/2));let i,s;if(o.length%2==0){const e=o.length/2;i=(o[e-1]+o[e])/2}else i=o[Math.floor(o.length/2)];if(a.length%2==0){const e=a.length/2;s=(a[e-1]+a[e])/2}else s=a[Math.floor(a.length/2)];return[i,n,s]}function Na(e){if(0===e.length)return 0;return e.reduce((e,t)=>e+t,0)/e.length}const $a={"geometric-mean":e=>{if(e.some(e=>e<0))throw new Error("Geometric mean is not defined for non-positive numbers");return Math.exp(e.reduce((e,t)=>e+Math.log(t),0)/e.length)}};function Ea(e){const t=[...e].sort((e,t)=>e-t),r=Math.floor(t.length/2);return t.length%2==0?(t[r-1]+t[r])/2:t[r]}const Ta={median:e=>Ea(e)};function Sa(e,t){const r=t??Na(e);return e.reduce((e,t)=>e+(t-r)**2,0)/e.length}const za={variance:e=>Sa(e)},ja={"sample-variance":e=>function(e){const t=Na(e);return e.reduce((e,r)=>e+(r-t)**2,0)/(e.length-1)}(e),minLength:2};function Ca(e,t){const r=Sa(e,t);return Math.sqrt(r)}const Ia={stdev:e=>Ca(e)},Ra={"sample-stdev":e=>function(e,t){const r=Sa(e,t);return Math.sqrt(r*(e.length/(e.length-1)))}(e),minLength:2},Pa={iqr:e=>{const[t,,r]=Aa(e);return r-t},minLength:4},Ma={span:e=>0===e.length?0:Math.max(...e)-Math.min(...e),minLength:0};const Oa={skewness:e=>function(e){const t=Na(e),r=Ca(e);if(0===r)throw new Error("Standard deviation is zero, skewness is undefined");return e.reduce((e,r)=>e+(r-t)**3,0)/(e.length*r**3)}(e),minLength:3},Va={"sample-skewness":e=>function(e){const t=e.length,r=e.reduce((e,t)=>e+t,0)/t;let n=0,o=0;for(const t of e){const e=t-r;n+=e*e,o+=e*e*e}const a=n/(t-1),i=Math.sqrt(a);if(0===i)throw new Error("Cannot calculate sample skewness when standard deviation is 0");return t/((t-1)*(t-2))*o/i**3}(e),minLength:3};function Da(e){const t=Na(e),r=Ca(e);if(0===r)throw new Error("Standard deviation is zero, kurtosis is undefined");return e.reduce((e,r)=>e+(r-t)**4,0)/(e.length*r**4)}const Ua={kurtosis:e=>Da(e),minLength:4},Fa={"excess-kurtosis":e=>function(e){return Da(e)-3}(e),minLength:4},Wa={"sample-kurtosis":e=>function(e){const t=e.length,r=e.reduce((e,t)=>e+t,0)/t,n=e.reduce((e,t)=>e+(t-r)**2,0)/(t-1);if(0===n)throw new Error("Variance is zero, kurtosis is undefined");return t*(t+1)*e.reduce((e,t)=>e+(t-r)**4,0)/((t-1)*(t-2)*(t-3)*n**2)}(e),minLength:4},Ga={"sample-excess-kurtosis":e=>function(e){const t=e.length,r=e.reduce((e,t)=>e+t,0)/t,n=e.reduce((e,t)=>e+(t-r)**2,0)/(t-1);if(0===n)throw new Error("Variance is zero, kurtosis is undefined");return t*(t+1)*e.reduce((e,t)=>e+(t-r)**4,0)/((t-1)*(t-2)*(t-3)*n**2)-3*(t-1)*(t-1)/((t-2)*(t-3))}(e),minLength:4},Ba={rms:e=>Math.sqrt(e.reduce((e,t)=>e+t**2,0)/e.length)};const La={mad:e=>function(e){const t=Ea(e);return e.reduce((e,r)=>e+Math.abs(r-t),0)/e.length}(e)};function _a(e){const t=Ea(e);return 1.4826*Ea(e.map(e=>Math.abs(e-t)))}const Ka={medad:e=>_a(e)},Ja={"gini-coefficient":e=>{if(e.some(e=>e<0))throw new Error("Gini coefficient is not defined for negative values");const t=[...e].sort((e,t)=>e-t),r=t.length,n=t.reduce((e,t)=>e+t,0);if(0===n)return 0;return 2*t.reduce((e,t,r)=>e+(r+1)*t,0)/(r*n)-(r+1)/r},minLength:1};const Ha={entropy:e=>function(e){const t=new Map;for(const r of e)t.set(r,(t.get(r)||0)+1);const r=e.length;let n=0;for(const e of t.values()){const t=e/r;t>0&&(n-=t*Math.log2(t))}return n}(e),minLength:1},Ya={};function Xa(e){for(const[t,r]of Object.entries(e)){if(Ya[t])throw new Error(`Duplicate normal expression key found: ${t}`);if("minLength"!==t&&"padding"!==t&&"function"==typeof r){const n=r,o=t.replace(/^/,""),a=`moving-${o}`,i=`centered-moving-${o}`,s=`running-${o}`,l=e.minLength??1;Y(l,void 0,{integer:!0,finite:!0,gte:0}),Ya[t]=Qa(n,l),Ya[a]=Za(n,l),Ya[i]=ei(n,l,e.padding??null),Ya[s]=ti(n,l)}}}function Qa(e,t){return{evaluate:([r],n)=>{if(Ce(r,n),r.length<t)throw new o(`Vector length must be at least ${t}`,n);try{return e(r)}catch(e){throw new o(e,n)}},arity:te(1)}}function Za(e,t){return{evaluate:([r,n],a)=>{if(Ce(r,a),Y(n,a,{integer:!0,finite:!0,gte:t,lte:r.length}),0===r.length)return[];try{if(n>=r.length)return[e(r)];const t=[];for(let o=0;o<r.length-n+1;o+=1)t.push(e(r.slice(o,o+n)));return t}catch(e){throw new o(e,a)}},arity:te(2)}}function ei(e,t,r){return{evaluate:([n,a,i,s],l)=>{if(Ce(n,l),n.length<t)throw new o(`Vector length must be at least ${t}`,l);if(Y(a,l,{integer:!0,finite:!0,gte:t,lte:n.length}),null!==(i=i??r)&&Y(i,l,{finite:!0}),null!==(s=s??r)&&Y(s,l,{finite:!0}),0===n.length)return[];const c=Math.floor(a/2),u=[...Array(c).fill(i),...n,...Array(c).fill(s)],m="number"==typeof i?0:c,p=n.length-("number"==typeof s?0:a-c-1),d=[...Array(m).fill(null)];try{for(let t=m;t<p;t+=1)d.push(e(u.slice(t,t+a)))}catch(e){throw new o(e,l)}return d.push(...Array(n.length-p).fill(null)),d},arity:{min:2,max:4}}}function ti(e,t){return{evaluate:([r],n)=>{if(Ce(r,n),r.length<t)throw new o(`Vector length must be at least ${t}`,n);if(0===r.length)return[];try{const n=Math.max(t-1,0),o=Array(n).fill(null);for(let t=n;t<r.length;t+=1)o.push(e(r.slice(0,t+1)));return o}catch(e){throw new o(e,n)}},arity:te(1)}}Xa({mean:e=>Na(e)}),Xa($a),Xa({"harmonic-mean":e=>e.length/e.reduce((e,t)=>e+1/t,0)}),Xa(Ta),Xa({sum:e=>e.reduce((e,t)=>e+t,0),minLength:0}),Xa({prod:e=>e.reduce((e,t)=>e*t,1),padding:1,minLength:0}),Xa(za),Xa(ja),Xa(Ia),Xa(Ra),Xa(Pa),Xa(Ma),Xa(Oa),Xa(Va),Xa(Fa),Xa(Ua),Xa(Ga),Xa(Wa),Xa(Ba),Xa(La),Xa(Ka),Xa(Ja),Xa(Ha),delete Ya.sum,delete Ya.prod,delete Ya.mean,delete Ya.median;const ri={"monotonic?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>=e[r-1])||e.every((t,r)=>0===r||t<=e[r-1])),arity:te(1)},"strictly-monotonic?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>e[r-1])||e.every((t,r)=>0===r||t<e[r-1])),arity:te(1)},"increasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>=e[r-1])),arity:te(1)},"decreasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t<=e[r-1])),arity:te(1)},"strictly-increasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t>e[r-1])),arity:te(1)},"strictly-decreasing?":{evaluate:([e],t)=>(Ce(e,t),e.every((t,r)=>0===r||t<e[r-1])),arity:te(1)},mode:{evaluate:([e],t)=>(Pe(e,t),function(e){const t=new Map;for(const r of e)t.set(r,(t.get(r)||0)+1);let r=0;for(const e of t.values())e>r&&(r=e);if(1===r)return e;const n=[];for(const[e,o]of t.entries())o===r&&n.push(e);return n}(e)),arity:te(1)},"min-index":{evaluate:([e],t)=>(Pe(e,t),e.reduce((t,r,n)=>r<e[t]?n:t,0)),arity:te(1)},"max-index":{evaluate:([e],t)=>(Pe(e,t),e.reduce((t,r,n)=>r>e[t]?n:t,0)),arity:te(1)},"sort-indices":{evaluate:([e],t)=>(Ce(e,t),[...e.keys()].sort((t,r)=>e[t]-e[r])),arity:te(1)},"count-values":{evaluate:([e],t)=>{Ce(e,t);const r=new Map;for(const t of e)r.set(t,(r.get(t)||0)+1);return[...r.entries()].sort((e,t)=>{const r=t[1]-e[1];return 0!==r?r:e[0]-t[0]})},arity:te(1)},linspace:{evaluate:([e,t,r],n)=>{if(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,nonNegative:!0}),0===r)return[];if(1===r)return[e];const o=(t-e)/(r-1);return Array.from({length:r},(t,r)=>e+r*o)},arity:te(3)},cumsum:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>{const r=e[e.length-1]??0;return e.push(r+t),e},[])),arity:te(1)},cumprod:{evaluate:([e],t)=>(Ce(e,t),e.reduce((e,t)=>{const r=e[e.length-1]??1;return e.push(r*t),e},[])),arity:te(1)},quartiles:{evaluate:([e],t)=>{if(Ce(e,t),e.length<4)throw new o("Quartiles require at least four values",t);return Aa(e)},arity:te(1)},percentile:{evaluate:([e,t],r)=>(Pe(e,r),Y(t,r,{finite:!0,nonNegative:!0,lte:100}),qa(e,t)),arity:te(2)},quantile:{evaluate:([e,t],r)=>(Ce(e,r),Y(t,r,{finite:!0,nonNegative:!0,lte:1}),qa(e,100*t)),arity:te(2)},histogram:{evaluate:([e,t],r)=>(Ce(e,r),Y(t,r,{integer:!0,positive:!0}),function(e,t){if(0===e.length){const e=[];for(let r=0;r<t;r++)e.push([0,0,0]);return e}const r=Math.min(...e),n=Math.max(...e);if(r===n){const n=[];for(let e=0;e<t;e++)n.push([r,r,0]);return n[0][2]=e.length,n}const o=(n-r)/t,a=[];for(let e=0;e<t;e++){const i=r+e*o,s=e===t-1?n:r+(e+1)*o;a.push([i,s,0])}for(const i of e)i===n?a[t-1][2]+=1:a[Math.min(Math.floor((i-r)/o),t-1)][2]+=1;return a}(e,t)),arity:te(2)},ecdf:{evaluate:([e,t],r)=>{Pe(e,r),Y(t,r,{finite:!0});const n=[...e].sort((e,t)=>e-t),o=n.findIndex(e=>e>t);return-1===o?1:o/n.length},arity:te(2)},"outliers?":{evaluate:([e],t)=>(Ce(e,t),function(e){return ka(e).length>0}(e)),arity:te(1)},outliers:{evaluate:([e],t)=>(Ce(e,t),ka(e)),arity:te(1)},bincount:{evaluate:(e,t)=>{const r=e[0];Ce(r,t),r.forEach(e=>Y(e,t,{finite:!0,integer:!0,nonNegative:!0}));const n=e[1]??0;Y(n,t,{integer:!0,nonNegative:!0});const a=e[2]??void 0;if(void 0!==a){if(Ce(a,t),a.length!==r.length)throw new o("Weights vector must be the same length as the input vector",t);a.forEach(e=>Y(e,t,{finite:!0}))}return function(e,t=0,r){if(0===e.length)return Array.from({length:t},()=>0);const n=Math.max(...e),o=Math.max(n+1,t),a=Array.from({length:o},()=>0);for(let t=0;t<e.length;t++){const n=Math.floor(e[t]);n<o&&(a[n]+=r?r[t]:1)}return a}(r,n,a)},arity:{min:1,max:3}},winsorize:{evaluate:([e,t,r],n)=>{if(Ce(e,n),Y(t,n,{finite:!0,gte:0,lte:1}),r??=t>.5?1:1-t,Y(r,n,{finite:!0,gte:t,lte:1}),0===e.length)return[];const o=[...e].sort((e,t)=>e-t),a=Math.max(0,Math.floor(t*e.length)),i=Math.min(e.length-1,Math.max(0,Math.floor(r*e.length)-1)),s=o[a],l=o[i];return e.map(e=>Math.max(s,Math.min(e,l)))},arity:{min:2,max:3}},mse:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+(r-t[n])**2,0)/e.length},arity:te(2)},rmse:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return Math.sqrt(e.reduce((e,r,n)=>e+(r-t[n])**2,0)/e.length)},arity:te(2)},mae:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+Math.abs(r-t[n]),0)/e.length},arity:te(2)},smape:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>{const o=Math.abs(r-t[n]),a=(Math.abs(r)+Math.abs(t[n]))/2;return e+(0===a?0:o/a)},0)/e.length},arity:te(2)}};!function(e){for(const[t,r]of Object.entries(e)){if(ri[t])throw new Error(`Duplicate normal expression key found: ${t}`);ri[t]=r}}(Ya);for(const[e,t]of Object.entries(xa))ri[e]&&(ri[e].docs=t);const ni={name:"vector",functions:ri,source:"{}",docs:xa},oi={reflect:{category:"linear-algebra",description:"Reflects a vector across a given axis.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to reflect."},b:{type:"vector",description:"Axis of reflection."}},variants:[{argumentNames:["a","b"]}],examples:["let { reflect } = import(linear-algebra);\nreflect([1, 2], [0, 1])","let { reflect } = import(linear-algebra);\nreflect([1, 2, 3], [0, 0, 1])"],seeAlso:["linear-algebra.refract","linear-algebra.projection"]},refract:{category:"linear-algebra",description:"Refracts a vector across a given axis.",returns:{type:"vector"},args:{vector:{type:"vector",description:"Vector to refract."},axis:{type:"vector",description:"Axis of refraction."},eta:{type:"number",description:"Refraction index."}},variants:[{argumentNames:["vector","axis","eta"]}],examples:["let { refract } = import(linear-algebra);\nrefract([1, 2], [0, 1], 1.5)","let { refract } = import(linear-algebra);\nrefract([1, 2, 3], [0, 0, 1], 1.5)"],seeAlso:["linear-algebra.reflect"]},lerp:{category:"linear-algebra",description:"Performs linear interpolation between two vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"Start vector."},b:{type:"vector",description:"End vector."},t:{type:"number",description:"Interpolation factor (0 to 1)."}},variants:[{argumentNames:["a","b","t"]}],examples:["let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 0.5)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 2)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], -1)","let { lerp } = import(linear-algebra);\nlerp([1, 2, 3], [4, 5, 6], 0.25)"],seeAlso:["linear-algebra.projection"]},rotate2d:{category:"linear-algebra",description:"Rotates a 2D vector by a given angle in radians.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to rotate."},b:{type:"number",description:"Angle in b."}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate2d } = import(linear-algebra);\nrotate2d([1, 0], PI / 2)","let { rotate2d } = import(linear-algebra);\nrotate2d([0, 1], PI)"],seeAlso:["linear-algebra.rotate3d","linear-algebra.angle"]},rotate3d:{category:"linear-algebra",description:"Rotates a 3D vector around a given axis by a given angle in radians.",returns:{type:"vector"},args:{v:{type:"vector",description:"Vector to rotate."},axis:{type:"vector",description:"Axis of rotation."},radians:{type:"number",description:"Angle in radians."}},variants:[{argumentNames:["v","axis","radians"]}],examples:["let { rotate3d } = import(linear-algebra);\nrotate3d([1, 0, 0], [0, 1, 0], PI / 2)","let { rotate3d } = import(linear-algebra);\nrotate3d([0, 1, 0], [1, 0, 0], PI)"],seeAlso:["linear-algebra.rotate2d","linear-algebra.angle"]},dot:{category:"linear-algebra",description:"Calculates the dot product of two vectors. The result is a scalar.",returns:{type:"number"},args:{a:{type:"vector",description:"First vector."},b:{type:"vector",description:"Second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { dot } = import(linear-algebra);\ndot([1, 2], [3, 4])","let { dot } = import(linear-algebra);\ndot([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.cross","linear-algebra.cosine-similarity","linear-algebra.angle","linear-algebra.projection","linear-algebra.orthogonal?"]},cross:{category:"linear-algebra",description:"Calculates the cross product of two 3D vectors. The result is a vector perpendicular to both input vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"First vector (3D)."},b:{type:"vector",description:"Second vector (3D)."}},variants:[{argumentNames:["a","b"]}],examples:["let { cross } = import(linear-algebra);\ncross([1, 2, 3], [4, 5, 6])","let { cross } = import(linear-algebra);\ncross([1, 0, 0], [0, 1, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 1], [1, 0, 0])","let { cross } = import(linear-algebra);\ncross([1, 2, 3], [0, 0, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 0], [1, 2, 3])"],seeAlso:["linear-algebra.dot"]},"normalize-minmax":{category:"linear-algebra",description:"Normalizes the vector using min-max normalization. The result is a vector with values between 0 and 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-zscore","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-zscore":{category:"linear-algebra",description:"Normalizes the vector using z-score normalization. The result is a vector with mean 0 and standard deviation 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-robust":{category:"linear-algebra",description:"Normalizes the vector using robust normalization. The result is a vector with median 0 and median absolute deviation 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},"normalize-l1":{category:"linear-algebra",description:"Normalizes the vector using L1 normalization. The result is a vector with L1 norm equal to 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l2","linear-algebra.normalize-minmax","linear-algebra.manhattan-norm","linear-algebra.normalize-zscore"]},"normalize-l2":{category:"linear-algebra",description:"Normalizes the vector using L2 normalization. The result is a vector with L2 norm equal to 1.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l1","linear-algebra.normalize-minmax","linear-algebra.euclidean-norm","linear-algebra.normalize-zscore"]},"normalize-log":{category:"linear-algebra",description:"Normalizes the vector using natural log normalization. The result is a vector with log-transformed values.",returns:{type:"number",array:!0},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 4])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},angle:{category:"linear-algebra",description:"Calculates the **angle** between two vectors in radians.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { angle } = import(linear-algebra);\nangle([1, 0], [0, 1])","let { angle } = import(linear-algebra);\nangle([1, 0, 1], [0, 1, 0])"],seeAlso:["linear-algebra.dot","linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.rotate2d","linear-algebra.rotate3d","linear-algebra.parallel?","linear-algebra.cosine-similarity","linear-algebra.to-polar"]},projection:{category:"linear-algebra",description:"Calculates the **projection** of vector `a` onto vector `b`.",returns:{type:"vector"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { projection } = import(linear-algebra);\nprojection([1, 2], [3, 4])","let { projection } = import(linear-algebra);\nprojection([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.dot","linear-algebra.reflect","linear-algebra.lerp"]},"collinear?":{category:"linear-algebra",description:"Checks if two vectors are **collinear**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [2, 4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [-2, -4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2, 3], [2, 4, 6])"],seeAlso:["linear-algebra.parallel?","linear-algebra.orthogonal?","linear-algebra.angle"]},"parallel?":{category:"linear-algebra",description:"Checks if two vectors are **parallel**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [2, 4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [-2, -4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2, 3], [2, 4, 6])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [3, 4])"],seeAlso:["linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.angle"]},"orthogonal?":{category:"linear-algebra",description:"Checks if two vectors are **orthogonal**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0], [0, 1])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0, 1], [0, 1, 0])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 2], [2, -1])"],seeAlso:["linear-algebra.collinear?","linear-algebra.parallel?","linear-algebra.dot","matrix.orthogonal-matrix?","linear-algebra.angle"]},"cosine-similarity":{category:"linear-algebra",description:"Calculates the **cosine similarity** between two vectors. The result is a value between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2], [3, 4])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2, 3], [4, 5, 6])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 0], [0, 1])"],seeAlso:["linear-algebra.dot","linear-algebra.angle","linear-algebra.euclidean-distance"]},"euclidean-distance":{category:"linear-algebra",description:"Calculates the **Euclidean distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2], [3, 4])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2, 3], [4, 5, 6])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.euclidean-norm","linear-algebra.cosine-similarity","linear-algebra.hamming-distance"]},"euclidean-norm":{category:"linear-algebra",description:"Calculates the **Euclidean norm** (L2 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([3, 4])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2, 3])"],seeAlso:["linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.euclidean-distance","linear-algebra.normalize-l2","linear-algebra.hamming-norm"]},"manhattan-distance":{category:"linear-algebra",description:"Calculates the **Manhattan distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2], [3, 4])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2, 3], [4, 5, 6])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"manhattan-norm":{category:"linear-algebra",description:"Calculates the **Manhattan norm** (L1 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([3, 4])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.manhattan-distance","linear-algebra.normalize-l1","linear-algebra.hamming-norm"]},"hamming-distance":{category:"linear-algebra",description:"Calculates the **Hamming distance** between two vectors. The result is a non-negative integer.",returns:{type:"integer"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2], [3, 4])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2, 3], [4, 5, 6])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.hamming-norm"]},"hamming-norm":{category:"linear-algebra",description:"Calculates the **Hamming norm** of a vector. The result is a non-negative integer.",returns:{type:"integer"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([3, 4])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"chebyshev-distance":{category:"linear-algebra",description:"Calculates the **Chebyshev distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2], [3, 4])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2, 3], [4, 5, 6])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.minkowski-distance","linear-algebra.chebyshev-norm"]},"chebyshev-norm":{category:"linear-algebra",description:"Calculates the **Chebyshev norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([3, 4])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.minkowski-norm","linear-algebra.chebyshev-distance"]},"minkowski-distance":{category:"linear-algebra",description:"Calculates the **Minkowski distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"},p:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b","p"]}],examples:["let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2], [3, 4], 2)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2, 3], [4, 5, 6], 3)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 0], [0, 1], 1)"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-norm"]},"minkowski-norm":{category:"linear-algebra",description:"Calculates the **Minkowski norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector",description:"Vector to calculate the norm for."},b:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b"]}],examples:["let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2], 2)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([3, 4], 3)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2, 3], 4)"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-distance"]},cov:{category:"linear-algebra",description:"Calculates the **covariance** between two vectors. The result is a number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cov } = import(linear-algebra);\ncov([1, 2], [3, 4])","let { cov } = import(linear-algebra);\ncov([1, 2, 3], [4, 5, 6])","let { cov } = import(linear-algebra);\ncov([1, 0], [0, 1])"],seeAlso:["linear-algebra.corr","linear-algebra.pearson-corr","vector.variance"]},corr:{category:"linear-algebra",description:"Calculates the **correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { corr } = import(linear-algebra);\ncorr([1, 2], [3, 4])","let { corr } = import(linear-algebra);\ncorr([1, 2, 3], [4, 5, 6])","let { corr } = import(linear-algebra);\ncorr([1, 0], [0, 1])"],seeAlso:["linear-algebra.cov","linear-algebra.pearson-corr","linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.autocorrelation","linear-algebra.cross-correlation"]},"spearman-corr":{category:"linear-algebra",description:"Calculates the **Spearman rank correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2], [3, 4])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2, 3], [4, 5, 6])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.pearson-corr","linear-algebra.kendall-tau","linear-algebra.corr"]},"pearson-corr":{category:"linear-algebra",description:"Calculates the **Pearson correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2], [3, 4])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2, 3], [4, 5, 6])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.corr","linear-algebra.cov"]},"kendall-tau":{category:"linear-algebra",description:"Calculates the **Kendall Tau** rank correlation coefficient between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2], [3, 4])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2, 3], [4, 5, 6])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.pearson-corr","linear-algebra.corr"]},autocorrelation:{category:"linear-algebra",description:"Calculates the **autocorrelation** of a vector. The result is a vector of autocorrelation coefficients.",returns:{type:"number"},args:{a:{type:"vector",description:"Vector to calculate the autocorrelation for."},b:{type:"integer",description:"Lag value for the autocorrelation."}},variants:[{argumentNames:["a","b"]}],examples:["let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -2)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 0)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 2)"],seeAlso:["linear-algebra.cross-correlation","linear-algebra.corr"]},"cross-correlation":{category:"linear-algebra",description:"Calculates the **cross-correlation** between two vectors. The result is a vector of cross-correlation coefficients.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"},lag:{type:"integer",description:"Lag value for the cross-correlation."}},variants:[{argumentNames:["a","b","lag"]}],examples:["let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -2)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 0)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 2)"],seeAlso:["linear-algebra.autocorrelation","linear-algebra.corr"]},rref:{category:"linear-algebra",description:"Calculates the **Reduced Row Echelon Form** (RREF) of a matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"Matrix to calculate the RREF for."}},variants:[{argumentNames:["m"]}],examples:["let { rref } = import(linear-algebra);\nrref([[1, 2], [3, 4]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [7, 8, 9], [4, 5, 7]])"],seeAlso:["linear-algebra.solve","matrix.rank"]},solve:{category:"linear-algebra",description:"Solves a system of linear equations represented by a matrix and a vector.",returns:{type:"vector"},args:{a:{type:"matrix"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { solve } = import(linear-algebra);\nsolve([\n [2, 1, -1, 1], \n [4, 5, -3, 2], \n [6, -2, 5, -3], \n [8, 3, 2, 4]\n], [5, 10, 2, 17])","let { solve } = import(linear-algebra);\nsolve([[2, 0, 0], [3, 1, 0], [4, 5, 6]], [4, 5, 38])","let { solve } = import(linear-algebra);\nsolve([[2, 3], [1, -1]], [8, 2])"],seeAlso:["linear-algebra.rref","matrix.inv"]},"to-polar":{category:"linear-algebra",description:"Converts a 2D vector to polar coordinates.",returns:{type:"vector"},args:{vector:{type:"vector",description:"2D Vector to convert."}},variants:[{argumentNames:["vector"]}],examples:["let { to-polar } = import(linear-algebra);\nto-polar([1, 2])","let { to-polar } = import(linear-algebra);\nto-polar([3, 4])"],seeAlso:["linear-algebra.from-polar","linear-algebra.angle"]},"from-polar":{category:"linear-algebra",description:"Converts polar coordinates to a 2D vector.",returns:{type:"vector"},args:{polar:{type:"vector",description:"Polar coordinates to convert."}},variants:[{argumentNames:["polar"]}],examples:["let { from-polar } = import(linear-algebra);\nfrom-polar([1, PI / 4])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, 0])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, -PI / 2])"],seeAlso:["linear-algebra.to-polar"]}};function ai(e){const t=e.map(e=>[...e]),r=t.length,n=t[0].length;let o=0,a=0;for(let e=0;e<n;e++){let i=-1;for(let n=a;n<r;n++)if(!ge(t[n][e])){i=n;break}if(-1===i)continue;o+=1,i!==a&&([t[i],t[a]]=[t[a],t[i]]);const s=t[a][e];for(let r=e;r<n;r++)t[a][r]/=s;for(let o=0;o<r;o++)if(o!==a&&!ge(t[o][e])){const r=t[o][e];for(let i=e;i<n;i++)t[o][i]-=r*t[a][i]}if(a++,a===r)break}return[t,o]}function ii(e,t){const r=e=>e.every(e=>ge(e));if(r(e)||r(t))return!0;let n=0;for(;n<e.length&&ge(e[n]);)n++;const o=t[n]/e[n];for(let r=0;r<e.length;r++)if(!ge(e[r])||!ge(t[r])){if(ge(e[r]))return!1;if(!he(t[r]/e[r],o))return!1}return!0}function si(e){return e.every(e=>ge(e))}function li(e,t){const r=Na(e),n=Na(t);let o=0,a=0,i=0;for(let s=0;s<e.length;s++){const l=e[s]-r,c=t[s]-n;o+=l*c,a+=l*l,i+=c*c}if(0===a||0===i)throw new Error("Cannot calculate Pearson correlation coefficient: one of the vectors has zero variance.");return o/(Math.sqrt(a)*Math.sqrt(i))}function ci(e){const t=[...e.keys()].sort((t,r)=>e[t]-e[r]),r=Array.from({length:e.length}).fill(0);let n=1,o=0;for(;o<t.length;){const a=e[t[o]];let i=o;for(;i<t.length&&e[t[i]]===a;)i++;const s=n+(i-o-1)/2;for(let e=o;e<i;e++)r[t[e]]=s;n+=i-o,o=i}return r}function ui(e,t){const r=Na(e),n=Na(t);let o=0;for(let a=0;a<e.length;a++)o+=(e[a]-r)*(t[a]-n);return o/e.length}function mi(e,t){if(0===e.length)return e;const r=Math.sqrt(e.reduce((e,t)=>e+t**2,0));if(ge(r))throw new o("The vector must not be zero",t);return e.map(e=>e/r)}function pi(e,t){return e.reduce((e,r,n)=>e+r*t[n],0)}function di(e,t){return e.map((e,r)=>e-t[r])}function hi(e,t){return e.map(e=>e*t)}const gi={rotate2d:{evaluate:([e,t],r)=>{if(Ie(e,r),si(e))return e;Y(t,r,{finite:!0});const n=Math.cos(t),o=Math.sin(t);return[e[0]*n-e[1]*o,e[0]*o+e[1]*n]},arity:te(2)},rotate3d:{evaluate:([e,t,r],n)=>{if(Re(e,n),si(e))return e;if(Y(r,n,{finite:!0}),Re(t,n),si(t))throw new o("Rotation axis must not be zero",n);const a=Math.cos(r),i=Math.sin(r),[s,l,c]=mi(t,n),u=e[0]*s+e[1]*l+e[2]*c;return[u*s*(1-a)+e[0]*a+(-c*e[1]+l*e[2])*i,u*l*(1-a)+e[1]*a+(c*e[0]-s*e[2])*i,u*c*(1-a)+e[2]*a+(-l*e[0]+s*e[1])*i]},arity:te(3)},reflect:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);if(si(t))throw new o("Reflection normal must not be zero",r);if(si(e))return e;const n=mi(t,r);return di(e,hi(n,2*pi(e,n)))},arity:te(2)},refract:{evaluate:([e,t,r],n)=>{if(Ce(e,n),Ce(t,n),Y(r,n,{finite:!0,positive:!0}),e.length!==t.length)throw new o("Vectors must be of the same length",n);if(si(t))throw new o("Refraction normal must not be zero",n);if(si(e))return e;const a=mi(e,n),i=mi(t,n),s=pi(a,i),l=1-r*r*(1-s*s);if(l<0)return e;return di(hi(a,r),hi(i,r*s+Math.sqrt(l)))},arity:te(3)},lerp:{evaluate:([e,t,r],n)=>{if(Ce(e,n),Ce(t,n),Y(r,n,{finite:!0}),e.length!==t.length)throw new o("Vectors must be of the same length",n);return e.map((e,n)=>e+(t[n]-e)*r)},arity:te(3)},dot:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return pi(e,t)},arity:te(2)},cross:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),3!==e.length||3!==t.length)throw new o("Cross product is only defined for 3D vectors",r);return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]},arity:te(2)},"normalize-minmax":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=e.reduce((e,t)=>t<e?t:e,e[0]),n=e.reduce((e,t)=>t>e?t:e,e[0]);return r===n?e.map(()=>0):e.map(e=>(e-r)/(n-r))},arity:te(1)},"normalize-robust":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=Ea(e),n=_a(e);return 0===n?e.map(e=>e-r):e.map(e=>(e-r)/n)},arity:te(1)},"normalize-zscore":{evaluate:([e],t)=>{Ce(e,t);const r=Na(e),n=Ca(e);return 0===n?e.map(()=>0):e.map(e=>(e-r)/n)},arity:te(1)},"normalize-l1":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=e.reduce((e,t)=>e+Math.abs(t),0);return 0===r?e.map(()=>0):e.map(e=>e/r)},arity:te(1)},"normalize-l2":{evaluate:([e],t)=>(Ce(e,t),mi(e,t)),arity:te(1)},"normalize-log":{evaluate:([e],t)=>{if(Ce(e,t),0===e.length)return[];const r=Math.min(...e);if(r<=0)throw new o("Log normalization requires all values to be positive",t);return e.map(e=>Math.log(e/r))},arity:te(1)},angle:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),si(e)||si(t))throw new o("Cannot calculate angle with zero-length vector",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=e.reduce((e,r,n)=>e+r*t[n],0),a=Math.sqrt(e.reduce((e,t)=>e+t*t,0)),i=Math.sqrt(t.reduce((e,t)=>e+t*t,0));return Math.acos(n/(a*i))},arity:te(2)},projection:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),si(t))throw new o("Cannot project onto zero-length vector",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=e.reduce((e,r,n)=>e+r*t[n],0),a=Math.sqrt(t.reduce((e,t)=>e+t*t,0));return t.map(e=>n/a**2*e)},arity:te(2)},"orthogonal?":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return 0===e.reduce((e,r,n)=>e+r*t[n],0)},arity:te(2)},"parallel?":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return function(e,t){if(!ii(e,t))return!1;for(let r=0;r<e.length;r++)if(!ge(e[r])&&!ge(t[r]))return Math.sign(e[r])===Math.sign(t[r]);return!0}(e,t)},arity:te(2)},"collinear?":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return ii(e,t)},arity:te(2)},"cosine-similarity":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),si(e)||si(t))throw new o("Cannot calculate cosine similarity with zero-length vector",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+r*t[n],0)/(Math.sqrt(e.reduce((e,t)=>e+t*t,0))*Math.sqrt(t.reduce((e,t)=>e+t*t,0)))},arity:te(2)},"euclidean-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return Math.sqrt(e.reduce((e,r,n)=>e+(r-t[n])**2,0))},arity:te(2)},"euclidean-norm":{evaluate:([e],t)=>(Pe(e,t),function(e){return Math.sqrt(e.reduce((e,t)=>e+t**2,0))}(e)),arity:te(1)},"manhattan-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+Math.abs(r-t[n]),0)},arity:te(2)},"manhattan-norm":{evaluate:([e],t)=>(Pe(e,t),e.reduce((e,t)=>e+Math.abs(t),0)),arity:te(1)},"hamming-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return e.reduce((e,r,n)=>e+(r!==t[n]?1:0),0)},arity:te(2)},"hamming-norm":{evaluate:([e],t)=>(Pe(e,t),e.reduce((e,t)=>e+(0!==t?1:0),0)),arity:te(1)},"chebyshev-distance":{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return Math.max(...e.map((e,r)=>Math.abs(e-t[r])))},arity:te(2)},"chebyshev-norm":{evaluate:([e],t)=>(Pe(e,t),Math.max(...e.map(e=>Math.abs(e)))),arity:te(1)},"minkowski-distance":{evaluate:([e,t,r],n)=>{if(Pe(e,n),Pe(t,n),Y(r,n,{finite:!0,positive:!0}),e.length!==t.length)throw new o("Vectors must be of the same length",n);return e.reduce((e,n,o)=>e+Math.abs(n-t[o])**r,0)**(1/r)},arity:te(3)},"minkowski-norm":{evaluate:([e,t],r)=>(Pe(e,r),Y(t,r,{finite:!0,positive:!0}),e.reduce((e,r)=>e+Math.abs(r)**t,0)**(1/t)),arity:te(2)},cov:{evaluate:([e,t],r)=>{if(Pe(e,r),Pe(t,r),e.length!==t.length)throw new o("Vectors must be of the same length",r);return 1===e.length?0:ui(e,t)},arity:te(2)},corr:{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<=1)throw new o("Vectors must have at least 2 elements for corr",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=Na(e),a=Na(t);return e.reduce((e,r,o)=>e+(r-n)*(t[o]-a),0)/Math.sqrt(e.reduce((e,t)=>e+(t-n)**2,0)*t.reduce((e,t)=>e+(t-a)**2,0))},arity:te(2)},"spearman-corr":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<=1)throw new o("Vectors must have at least 2 elements for corr",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);const n=ci(e),a=ci(t);try{return li(n,a)}catch(e){throw new o(e,r)}},arity:te(2)},"pearson-corr":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<=1)throw new o("Vectors must have at least 2 elements for pearson-corr",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);try{return li(e,t)}catch(e){throw new o(e,r)}},arity:te(2)},"kendall-tau":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length<2)throw new o("Vectors must have at least 2 elements for kendall-tau",r);if(e.length!==t.length)throw new o("Vectors must be of the same length",r);try{return function(e,t,r=1e-10){let n=0,o=0,a=0,i=0;for(let s=0;s<e.length;s++)for(let l=s+1;l<e.length;l++){const c=e[s]-e[l],u=t[s]-t[l],m=Math.abs(c)<r,p=Math.abs(u)<r;m&&p||(m?a+=1:p?i+=1:c*u>0?n+=1:o+=1)}const s=n+o+a,l=n+o+i;if(0===s||0===l)throw new Error("Not enough data to calculate Kendall's Tau");return(n-o)/Math.sqrt(s*l)}(e,t)}catch(e){throw new o(e,r)}},arity:te(2)},autocorrelation:{evaluate:([e,t],r)=>{if(Ce(e,r),e.length<2)throw new o("Vector must have at least 2 elements for autocorrelation",r);if(Y(t,r,{integer:!0,lt:e.length,gt:-e.length}),0===t)return 1;const n=Math.abs(t),a=Na(e);let i=0;const s=e.length;for(let r=0;r<s-n;r++){const o=t<0?r:r+n;i+=(e[t<0?r+n:r]-a)*(e[o]-a)}let l=0;for(let t=0;t<s;t++)l+=(e[t]-a)**2;return 0===l?0:i/l},arity:te(2)},"cross-correlation":{evaluate:([e,t,r],n)=>{if(Ce(e,n),Ce(t,n),e.length<2)throw new o("Vectors must have at least 2 elements",n);if(e.length!==t.length)throw new o("Vectors must be of the same length",n);if(Y(r,n,{integer:!0,lt:e.length,gt:-e.length}),0===r&&e.length===t.length&&e.every((e,r)=>e===t[r]))return 1;const[a,i]=function(e,t,r){const n=Math.abs(r),o=e.length-n;let a=[],i=[];return r>=0?(a=e.slice(0,o),i=t.slice(r,r+o)):(a=e.slice(n),i=t.slice(0,o)),[a,i]}(e,t,r);return function(e,t){const r=Na(e),n=Na(t),o=Ca(e,r),a=Ca(t,n);return 0===o||0===a?0===o&&0===a&&r===n?1:0:ui(e,t)/(o*a)}(a,i)},arity:te(3)},rref:{evaluate:([e],t)=>{De(e,t);const[r]=ai(e);return r},arity:te(1)},solve:{evaluate:([e,t],r)=>{if(Ue(e,r),Ce(t,r),e.length!==t.length)throw new o(`The number of rows in the matrix must be equal to the length of the vector, but got ${e.length} and ${t.length}`,r);return function(e,t){const r=e.length,n=e.map((e,r)=>[...e,t[r]]),[o]=ai(n);for(let e=0;e<r;e+=1)if(ge(o[e][e]))return null;const a=Array.from({length:r},()=>0);for(let e=r-1;e>=0;e--){let t=0;for(let n=e+1;n<r;n++)t+=o[e][n]*a[n];a[e]=(o[e][r]-t)/o[e][e]}return a}(e,t)},arity:te(2)},"to-polar":{evaluate:([e],t)=>{if(Ie(e,t),si(e))return[0,0];return[Math.sqrt(e[0]**2+e[1]**2),Math.atan2(e[1],e[0])]},arity:te(1)},"from-polar":{evaluate:([e],t)=>{Ie(e,t);const[r,n]=e;return 0===r?[0,0]:[r*Math.cos(n),r*Math.sin(n)]},arity:te(1)}};for(const[e,t]of Object.entries(oi))gi[e]&&(gi[e].docs=t);const fi={name:"linear-algebra",functions:gi,source:"{}",docs:oi},yi={mul:{category:"matrix",description:"Multiplies two `matrices` using standard `matrix` multiplication based on **dot products** of rows and columns.",returns:{type:"matrix"},args:{a:{type:"matrix"},b:{type:"matrix"}},variants:[{argumentNames:["a","b"]}],examples:["let { mul } = import(matrix);\nmul([[1, 2], [3, 4]], [[5, 6], [7, 8]])","let { mul } = import(matrix);\nmul([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]])"],seeAlso:["matrix.det","matrix.inv"]},det:{category:"matrix",description:"Calculates the **determinant** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the determinant of."}},variants:[{argumentNames:["m"]}],examples:["let { det } = import(matrix);\ndet([[1, 2], [3, 4]])","let { det } = import(matrix);\ndet([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.inv","matrix.cofactor","matrix.adj","matrix.trace","matrix.rank","matrix.invertible?","matrix.mul","matrix.minor"]},inv:{category:"matrix",description:"Calculates the **inverse** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the inverse of."}},variants:[{argumentNames:["m"]}],examples:["let { inv } = import(matrix);\ninv([[1, 2], [3, 4]])","let { inv } = import(matrix);\ninv([[1, 2, 3], [4, 5, 7], [7, 8, 10]])"],seeAlso:["matrix.det","matrix.adj","matrix.invertible?","linear-algebra.solve","matrix.mul","matrix.orthogonal-matrix?"]},adj:{category:"matrix",description:"Calculates the **adjugate** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the adjugate of."}},variants:[{argumentNames:["m"]}],examples:["let { adj } = import(matrix);\nadj([[1, 2], [3, 4]])","let { adj } = import(matrix);\nadj([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { adj } = import(matrix);\nadj([[1, 2, 3], [7, 8, 9], [4, 5, 6]])"],seeAlso:["matrix.cofactor","matrix.det","matrix.inv"]},cofactor:{category:"matrix",description:"Calculates the **cofactor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the cofactor of."}},variants:[{argumentNames:["m"]}],examples:["let { cofactor } = import(matrix);\ncofactor([[1, 2], [3, 4]])","let { cofactor } = import(matrix);\ncofactor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { cofactor } = import(matrix);\ncofactor([[1, 2, 3], [7, 8, 9], [4, 5, 6]])"],seeAlso:["matrix.adj","matrix.minor","matrix.det"]},minor:{category:"matrix",description:"Calculates the **minor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the minor of."},row:{type:"integer",description:"The row index of the element to calculate the minor for."},col:{type:"integer",description:"The column index of the element to calculate the minor for."}},variants:[{argumentNames:["m","row","col"]}],examples:["let { minor } = import(matrix);\nminor([[1, 2], [3, 4]], 0, 1)","let { minor } = import(matrix);\nminor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1)"],seeAlso:["matrix.cofactor","matrix.det"]},trace:{category:"matrix",description:"Calculates the **trace** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the trace of."}},variants:[{argumentNames:["m"]}],examples:["let { trace } = import(matrix);\ntrace([[1, 2], [3, 4]])","let { trace } = import(matrix);\ntrace([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.det","matrix.diagonal?"]},"symmetric?":{category:"matrix",description:"Checks if a `matrix` is **symmetric**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for symmetry."}},variants:[{argumentNames:["m"]}],examples:["let { symmetric? } = import(matrix);\nsymmetric?([[1, 2], [2, 1]])","let { symmetric? } = import(matrix);\nsymmetric?([[1, 2, 3], [2, 1, 4], [3, 4, 1]])"],seeAlso:["matrix.orthogonal-matrix?","matrix.diagonal?","matrix.square?","matrix.hilbert"]},"triangular?":{category:"matrix",description:"Checks if a `matrix` is **triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { triangular? } = import(matrix);\ntriangular?([[2, 0], [0, 1]])","let { triangular? } = import(matrix);\ntriangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])"],seeAlso:["matrix.upper-triangular?","matrix.lower-triangular?","matrix.diagonal?","matrix.banded?"]},"upper-triangular?":{category:"matrix",description:"Checks if a `matrix` is **upper triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for upper triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { upper-triangular? } = import(matrix);\nupper-triangular?([[1, 2], [0, 3]])","let { upper-triangular? } = import(matrix);\nupper-triangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])"],seeAlso:["matrix.lower-triangular?","matrix.triangular?","matrix.diagonal?"]},"lower-triangular?":{category:"matrix",description:"Checks if a `matrix` is **lower triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for lower triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { lower-triangular? } = import(matrix);\nlower-triangular?([[1, 0], [2, 3]])","let { lower-triangular? } = import(matrix);\nlower-triangular?([[1, 0, 0], [2, 3, 0], [4, 5, 6]])"],seeAlso:["matrix.upper-triangular?","matrix.triangular?","matrix.diagonal?"]},"diagonal?":{category:"matrix",description:"Checks if a `matrix` is **diagonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for diagonal property."}},variants:[{argumentNames:["m"]}],examples:["let { diagonal? } = import(matrix);\ndiagonal?([[1, 0], [0, 2]])","let { diagonal? } = import(matrix);\ndiagonal?([[1, 0, 0], [0, 2, 0], [0, 0, 3]])","let { diagonal? } = import(matrix);\ndiagonal?([[1, 0, 0], [2, 2, 2], [0, 0, 3]])"],seeAlso:["matrix.identity?","matrix.symmetric?","matrix.triangular?","matrix.trace","matrix.upper-triangular?","matrix.lower-triangular?","matrix.band","matrix.banded?"]},"square?":{category:"matrix",description:"Checks if a `matrix` is **square**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for square property."}},variants:[{argumentNames:["m"]}],examples:["let { square? } = import(matrix);\nsquare?([[1, 2], [3, 4]])","let { square? } = import(matrix);\nsquare?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { square? } = import(matrix);\nsquare?([[1, 2, 3], [4, 5, 6]])"],seeAlso:["matrix.symmetric?","matrix.identity?","matrix.invertible?"]},"orthogonal-matrix?":{category:"matrix",description:"Checks if a `matrix` is **orthogonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **orthogonality**."}},variants:[{argumentNames:["m"]}],examples:["let { orthogonal-matrix? } = import(matrix);\northogonal-matrix?([[1, 0], [0, 1]])","let { orthogonal-matrix? } = import(matrix);\northogonal-matrix?([[1, 0], [0, -1]])","let { orthogonal-matrix? } = import(matrix);\northogonal-matrix?([[1, 2], [3, 4]])"],seeAlso:["matrix.symmetric?","matrix.inv","matrix.identity?","linear-algebra.orthogonal?"]},"identity?":{category:"matrix",description:"Checks if a `matrix` is an **identity matrix**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for identity property."}},variants:[{argumentNames:["m"]}],examples:["let { identity? } = import(matrix);\nidentity?([[1, 0], [0, 1]])","let { identity? } = import(matrix);\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 1]])","let { identity? } = import(matrix);\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 0]])"],seeAlso:["matrix.diagonal?","matrix.square?","matrix.orthogonal-matrix?"]},"invertible?":{category:"matrix",description:"Checks if a `matrix` is **invertible**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for invertibility."}},variants:[{argumentNames:["m"]}],examples:["let { invertible? } = import(matrix);\ninvertible?([[1, 2], [3, 4]])","let { invertible? } = import(matrix);\ninvertible?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { invertible? } = import(matrix);\ninvertible?([[1, 2], [2, 4]])"],seeAlso:["matrix.det","matrix.inv","matrix.rank","matrix.square?"]},hilbert:{category:"matrix",description:"Generates a **Hilbert matrix** of size `n`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the Hilbert matrix."}},variants:[{argumentNames:["n"]}],examples:["let { hilbert } = import(matrix);\nhilbert(3)","let { hilbert } = import(matrix);\nhilbert(4)"],seeAlso:["matrix.vandermonde","matrix.symmetric?"]},vandermonde:{category:"matrix",description:"Generates a **Vandermonde matrix** from a vector.",returns:{type:"matrix"},args:{v:{type:"vector",description:"The vector to generate the Vandermonde matrix from."}},variants:[{argumentNames:["v"]}],examples:["let { vandermonde } = import(matrix);\nvandermonde([1, 2, 3])","let { vandermonde } = import(matrix);\nvandermonde([1, 0, 1])"],seeAlso:["matrix.hilbert","matrix.band"]},band:{category:"matrix",description:"Generates a **banded matrix** of size `n` with lower band index `lband` and upper band index `uband`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the banded matrix."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["n","lband","uband"]}],examples:["let { band } = import(matrix);\nband(3, 1, 1)","let { band } = import(matrix);\nband(4, 1, 2)"],seeAlso:["matrix.banded?","matrix.diagonal?","matrix.vandermonde"]},"banded?":{category:"matrix",description:"Checks if a `matrix` is **banded** with lower band index `lband` and upper band index `uband`.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **banded** property."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["m","lband","uband"]}],examples:["let { banded? } = import(matrix);\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 2, 2)","let { banded? } = import(matrix);\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 1, 1)"],seeAlso:["matrix.band","matrix.triangular?","matrix.diagonal?"]},rank:{category:"matrix",description:"Calculates the **rank** of a matrix using **Gaussian elimination**.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the rank of."}},variants:[{argumentNames:["m"]}],examples:["let { rank } = import(matrix);\nrank([[1, 0, 0], [0, 1, 0], [0, 0, 1]])","let { rank } = import(matrix);\nrank([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { rank } = import(matrix);\nrank([[2, 4, 6], [3, 6, 9], [4, 8, 12]])"],seeAlso:["matrix.det","matrix.invertible?","linear-algebra.rref"]},"frobenius-norm":{category:"matrix",description:"Calculates the **Frobenius norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the Frobenius norm of."}},variants:[{argumentNames:["m"]}],examples:["let { frobenius-norm } = import(matrix);\nfrobenius-norm([[1, 2], [3, 4]])","let { frobenius-norm } = import(matrix);\nfrobenius-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.one-norm","matrix.inf-norm","matrix.max-norm"]},"one-norm":{category:"matrix",description:"Calculates the **one-norm** (column norm) of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the one-norm of."}},variants:[{argumentNames:["m"]}],examples:["let { one-norm } = import(matrix);\none-norm([[1, 2], [3, 4]])","let { one-norm } = import(matrix);\none-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.inf-norm","matrix.max-norm"]},"inf-norm":{category:"matrix",description:"Calculates the **infinity norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the infinity norm of."}},variants:[{argumentNames:["m"]}],examples:["let { inf-norm } = import(matrix);\ninf-norm([[1, 2], [3, 4]])","let { inf-norm } = import(matrix);\ninf-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.max-norm"]},"max-norm":{category:"matrix",description:"Calculates the **max norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the max norm of."}},variants:[{argumentNames:["m"]}],examples:["let { max-norm } = import(matrix);\nmax-norm([[1, 2], [3, 4]])","let { max-norm } = import(matrix);\nmax-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.inf-norm"]}};function vi(e){const t=e.length,r=[];for(let n=0;n<t;n++)r[n]=[...e[n]];if(1===t)return r[0][0];if(2===t)return r[0][0]*r[1][1]-r[0][1]*r[1][0];let n=1;for(let e=0;e<t-1;e+=1){let o=e;for(let n=e+1;n<t;n+=1)Math.abs(r[n][e])>Math.abs(r[o][e])&&(o=n);if(ge(r[o][e]))return 0;o!==e&&([r[e],r[o]]=[r[o],r[e]],n=-n);for(let n=e+1;n<t;n+=1){const o=r[n][e]/r[e][e];for(let a=e;a<t;a++)r[n][a]-=o*r[e][a]}}let o=n;for(let e=0;e<t;e++)o*=r[e][e];return o}function bi(e,t,r){const n=e.length,o=[];for(let a=0;a<n;a++)if(a!==t){const t=[];for(let o=0;o<n;o++)o!==r&&t.push(e[a][o]);o.push(t)}return o}function wi(e){const t=e.length,r=[];for(let n=0;n<t;n++){r[n]=[];for(let o=0;o<t;o++){const t=(-1)**(n+o)*vi(bi(e,o,n));r[n][o]=t}}return r}function xi(e){return e.length===e[0].length}function ki(e){if(!xi(e))return!1;const t=e.length;for(let r=0;r<t;r++)for(let n=0;n<t;n++)if(r===n){if(!he(e[r][n],1))return!1}else if(!ge(e[r][n]))return!1;return!0}function qi(e,t){if(0===e.length||0===t.length||e[0].length!==t.length)throw new Error("Matrix dimensions do not match for multiplication");const r=e.length,n=e[0].length,o=t[0].length,a=Array(r).fill(0).map(()=>Array(o).fill(0));for(let i=0;i<r;i++)for(let r=0;r<n;r++){const n=e[i][r];for(let e=0;e<o;e++)a[i][e]+=n*t[r][e]}return a}const Ai={mul:{evaluate:([e,t],r)=>{De(e,r),De(t,r);try{return qi(e,t)}catch(n){throw new o(`The number of columns in the first matrix must be equal to the number of rows in the second matrix, but got ${e[0].length} and ${t.length}`,r)}},arity:te(2)},det:{evaluate:([e],t)=>(Ue(e,t),vi(e)),arity:te(1)},inv:{evaluate:([e],t)=>{Ue(e,t);const r=function(e){const t=e.length;if(1===t){const t=e[0][0];return ge(t)?null:[[1/t]]}const r=vi(e);if(ge(r))return null;const n=wi(e),o=[];for(let e=0;e<t;e++){o[e]=[];for(let a=0;a<t;a++)o[e][a]=n[e][a]/r}return o}(e);if(null===r)throw new o("The matrix must be invertible",t);return r},arity:te(1)},adj:{evaluate:([e],t)=>(Ue(e,t),wi(e)),arity:te(1)},cofactor:{evaluate:([e],t)=>(Ue(e,t),function(e){const t=e.length,r=[];for(let n=0;n<t;n++){r[n]=[];for(let o=0;o<t;o++){const t=bi(e,n,o),a=(-1)**(n+o);r[n][o]=a*vi(t)}}return r}(e)),arity:te(1)},minor:{evaluate:([e,t,r],n)=>(De(e,n),Y(t,n,{integer:!0,nonNegative:!0,lte:e.length}),Y(r,n,{integer:!0,nonNegative:!0,lte:e[0].length}),bi(e,t,r)),arity:te(3)},trace:{evaluate:([e],t)=>(Ue(e,t),function(e){return e.reduce((e,t,r)=>e+t[r],0)}(e)),arity:te(1)},"symmetric?":{evaluate:([e],t)=>(De(e,t),function(e){const t=e.length;if(!xi(e))return!1;for(let r=0;r<t;r+=1)for(let t=0;t<r;t+=1)if(e[r][t]!==e[t][r])return!1;return!0}(e)),arity:te(1)},"triangular?":{evaluate:([e],t)=>(De(e,t),function(e){if(!xi(e))return!1;const t=e.length;let r=!0,n=!0;for(let o=0;o<t;o++)for(let a=0;a<t;a++){if(o>a&&0!==e[o][a]&&(r=!1,!n))return!1;o<a&&0!==e[o][a]&&(n=!1)}return r||n}(e)),arity:te(1)},"upper-triangular?":{evaluate:([e],t)=>(De(e,t),function(e){if(!xi(e))return!1;const t=e.length;for(let r=0;r<t;r++)for(let t=0;t<r;t++)if(0!==e[r][t])return!1;return!0}(e)),arity:te(1)},"lower-triangular?":{evaluate:([e],t)=>(De(e,t),function(e){if(!xi(e))return!1;const t=e.length;if(!e.every(e=>e.length===t))return!1;for(let r=0;r<t;r++)for(let n=r+1;n<t;n++)if(0!==e[r][n])return!1;return!0}(e)),arity:te(1)},"diagonal?":{evaluate:([e],t)=>(De(e,t),function(e){if(!xi(e))return!1;const t=e.length;for(let r=0;r<t;r+=1)for(let n=0;n<t;n+=1)if(r!==n&&0!==e[r][n])return!1;return!0}(e)),arity:te(1)},"square?":{evaluate:([e],t)=>(De(e,t),xi(e)),arity:te(1)},"orthogonal-matrix?":{evaluate:([e],t)=>(De(e,t),function(e){return!!xi(e)&&ki(qi(e,va(e)))}(e)),arity:te(1)},"identity?":{evaluate:([e],t)=>(De(e,t),ki(e)),arity:te(1)},"invertible?":{evaluate:([e],t)=>(De(e,t),!!function(e){return!!Ve(e)&&e.length===e[0].length}(e)&&!ge(vi(e))),arity:te(1)},hilbert:{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});const r=[];for(let t=0;t<e;t+=1){const n=[];for(let r=0;r<e;r+=1)n.push(1/(t+r+1));r.push(n)}return r},arity:te(1)},vandermonde:{evaluate:([e],t)=>{Ce(e,t);const r=[];for(let t=0;t<e.length;t+=1){const n=[];for(let r=0;r<e.length;r+=1)n.push(e[t]**r);r.push(n)}return r},arity:te(1)},band:{evaluate:([e,t,r],n)=>(Y(e,n,{integer:!0,positive:!0}),Y(t,n,{integer:!0,nonNegative:!0,lt:e}),Y(r,n,{integer:!0,nonNegative:!0,lte:e}),function(e,t,r){const n=Array.from({length:e},()=>Array.from({length:e},()=>0));for(let o=0;o<e;o++)for(let a=Math.max(0,o-t);a<=Math.min(e-1,o+r);a++)n[o][a]=1;return n}(e,t,r)),arity:te(3)},"banded?":{evaluate:([e,t,r],n)=>{De(e,n);const o=Math.max(e.length,e[0].length);return Y(t,n,{integer:!0,nonNegative:!0,lt:o}),Y(r,n,{integer:!0,nonNegative:!0,lt:o}),function(e,t,r){const n=e.length,o=e[0].length;for(let a=0;a<n;a++)for(let n=0;n<o;n++)if(0!==e[a][n]&&(a-n>t||n-a>r))return!1;return!0}(e,t,r)},arity:te(3)},rank:{evaluate:([e],t)=>{De(e,t);const[,r]=ai(e);return r},arity:te(1)},"frobenius-norm":{evaluate:([e],t)=>(De(e,t),Math.sqrt(e.reduce((e,t)=>e+t.reduce((e,t)=>e+t*t,0),0))),arity:te(1)},"one-norm":{evaluate:([e],t)=>(De(e,t),function(e){const t=e.length,r=e[0].length;let n=0;for(let o=0;o<r;o+=1){let r=0;for(let n=0;n<t;n+=1)r+=Math.abs(e[n][o]);n=Math.max(n,r)}return n}(e)),arity:te(1)},"inf-norm":{evaluate:([e],t)=>(De(e,t),e.reduce((e,t)=>Math.max(e,t.reduce((e,t)=>e+Math.abs(t),0)),0)),arity:te(1)},"max-norm":{evaluate:([e],t)=>(De(e,t),e.reduce((e,t)=>{const r=t.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return Math.max(e,r)},0)),arity:te(1)}};for(const[e,t]of Object.entries(yi))Ai[e]&&(Ai[e].docs=t);const Ni={name:"matrix",functions:Ai,source:"{}",docs:yi},$i={"abundant-seq":{category:"number-theory",description:"Generates the abundant numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { abundant-seq } = import(number-theory);\nabundant-seq(1)","let { abundant-seq } = import(number-theory);\nabundant-seq(5)"],seeAlso:["number-theory.abundant-nth","number-theory.abundant-take-while","number-theory.abundant?","number-theory.deficient-seq","number-theory.perfect-seq"]},"abundant-take-while":{category:"number-theory",description:"Generates the abundant numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { abundant-take-while } = import(number-theory);\nabundant-take-while(-> $ < 100)"],seeAlso:["number-theory.abundant-seq","number-theory.abundant-nth","number-theory.abundant?"]},"abundant-nth":{category:"number-theory",description:"Generates the nth term of the abundant numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the number in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { abundant-nth } = import(number-theory);\nabundant-nth(1)","let { abundant-nth } = import(number-theory);\nabundant-nth(5)"],seeAlso:["number-theory.abundant-seq","number-theory.abundant-take-while","number-theory.abundant?"]},"abundant?":{category:"number-theory",description:"Checks if a number is abundant.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { abundant? } = import(number-theory);\nabundant?(12)","let { abundant? } = import(number-theory);\nabundant?(15)"],seeAlso:["number-theory.abundant-seq","number-theory.abundant-nth","number-theory.deficient?","number-theory.perfect?","number-theory.sigma","number-theory.divisors","number-theory.abundant-take-while"]},"arithmetic-seq":{category:"number-theory",description:"Generates the arithmetic sequence for a given $start, $step, and $length.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["start","step","length"]}],examples:["let { arithmetic-seq } = import(number-theory);\narithmetic-seq(3, 2, 2)","let { arithmetic-seq } = import(number-theory);\narithmetic-seq(2, 3, 2)","let { arithmetic-seq } = import(number-theory);\narithmetic-seq(1, 2, 2)","let { arithmetic-seq } = import(number-theory);\narithmetic-seq(1, 1.5, 12)"],seeAlso:["number-theory.arithmetic-nth","number-theory.arithmetic-take-while","number-theory.arithmetic?","number-theory.geometric-seq"]},"arithmetic-take-while":{category:"number-theory",description:"Generates the arithmetic sequence while a condition is met.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},takeWhile:{type:"function",description:"A function that takes a number and an index and returns a boolean."}},variants:[{argumentNames:["start","step","takeWhile"]}],examples:["let { arithmetic-take-while } = import(number-theory);\narithmetic-take-while(1, 0.25, -> $ < 3)"],seeAlso:["number-theory.arithmetic-seq","number-theory.arithmetic-nth","number-theory.arithmetic?"]},"arithmetic-nth":{category:"number-theory",description:"Generates the nth term of the arithmetic sequence.",returns:{type:"number"},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["start","step","n"]}],examples:["let { arithmetic-nth } = import(number-theory);\narithmetic-nth(3, 2, 2)","let { arithmetic-nth } = import(number-theory);\narithmetic-nth(2, 3, 2)","let { arithmetic-nth } = import(number-theory);\narithmetic-nth(1, 2, 2)","let { arithmetic-nth } = import(number-theory);\narithmetic-nth(1, 1.5, 12)"],seeAlso:["number-theory.arithmetic-seq","number-theory.arithmetic-take-while","number-theory.arithmetic?"]},"arithmetic?":{category:"number-theory",description:"Checks if a number is part of the arithmetic sequence.",returns:{type:"boolean"},args:{start:{type:"number",description:"The starting term of the sequence."},step:{type:"number",description:"The common difference of the sequence."},n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["start","step","n"]}],examples:["let { arithmetic? } = import(number-theory);\narithmetic?(3, 2, 2)","let { arithmetic? } = import(number-theory);\narithmetic?(2, 3, 2)","let { arithmetic? } = import(number-theory);\narithmetic?(1, 2, 2)","let { arithmetic? } = import(number-theory);\narithmetic?(1, 1.5, 12)"],seeAlso:["number-theory.arithmetic-seq","number-theory.arithmetic-nth","number-theory.geometric?","number-theory.arithmetic-take-while"]},"bell-seq":{category:"number-theory",description:"Generates the Bell sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 22 (the maximum length of the pre-calculated bell numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { bell-seq } = import(number-theory);\nbell-seq(5)","let { bell-seq } = import(number-theory);\nbell-seq(10)","let { bell-seq } = import(number-theory);\nbell-seq()"],seeAlso:["number-theory.bell-nth","number-theory.bell-take-while","number-theory.bell?","number-theory.catalan-seq","number-theory.stirling-second","number-theory.stirling-first"]},"bell-take-while":{category:"number-theory",description:"Generates the Bell sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { bell-take-while } = import(number-theory);\nbell-take-while(-> $ < 1000)"],seeAlso:["number-theory.bell-seq","number-theory.bell-nth","number-theory.bell?"]},"bell-nth":{category:"number-theory",description:"Generates the nth term of the Bell sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { bell-nth } = import(number-theory);\nbell-nth(5)","let { bell-nth } = import(number-theory);\nbell-nth(10)"],seeAlso:["number-theory.bell-seq","number-theory.bell-take-while","number-theory.bell?"]},"bell?":{category:"number-theory",description:"Checks if a number is in the Bell sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { bell? } = import(number-theory);\nbell?(1)","let { bell? } = import(number-theory);\nbell?(27644437)","let { bell? } = import(number-theory);\nbell?(27644436)"],seeAlso:["number-theory.bell-seq","number-theory.bell-nth","number-theory.catalan?","number-theory.bell-take-while"]},"bernoulli-seq":{category:"number-theory",description:"Generates the Bernoulli sequence up to a specified length.",returns:{type:"number",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { bernoulli-seq } = import(number-theory);\nbernoulli-seq(5)","let { bernoulli-seq } = import(number-theory);\nbernoulli-seq(10)"],seeAlso:["number-theory.bernoulli-nth","number-theory.bernoulli-take-while"]},"bernoulli-take-while":{category:"number-theory",description:"Generates the Bernoulli sequence while a condition is met.",returns:{type:"number",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { bernoulli-take-while } = import(number-theory);\nbernoulli-take-while(-> abs($) < 100)"],seeAlso:["number-theory.bernoulli-seq","number-theory.bernoulli-nth"]},"bernoulli-nth":{category:"number-theory",description:"Generates the nth term of the Bernoulli sequence.",returns:{type:"number"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { bernoulli-nth } = import(number-theory);\nbernoulli-nth(5)","let { bernoulli-nth } = import(number-theory);\nbernoulli-nth(10)","let { bernoulli-nth } = import(number-theory);\nbernoulli-nth(23)"],seeAlso:["number-theory.bernoulli-seq","number-theory.bernoulli-take-while"]},"catalan-seq":{category:"number-theory",description:"Generates the Catalan sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 30 (the maximum length of the pre-calculated catalan numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { catalan-seq } = import(number-theory);\ncatalan-seq(5)","let { catalan-seq } = import(number-theory);\ncatalan-seq(10)","let { catalan-seq } = import(number-theory);\ncatalan-seq()"],seeAlso:["number-theory.catalan-nth","number-theory.catalan-take-while","number-theory.catalan?","number-theory.bell-seq"]},"catalan-take-while":{category:"number-theory",description:"Generates the Catalan sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { catalan-take-while } = import(number-theory);\ncatalan-take-while(-> $ < 1000)"],seeAlso:["number-theory.catalan-seq","number-theory.catalan-nth","number-theory.catalan?"]},"catalan-nth":{category:"number-theory",description:"Generates the nth term of the Catalan sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { catalan-nth } = import(number-theory);\ncatalan-nth(5)","let { catalan-nth } = import(number-theory);\ncatalan-nth(10)"],seeAlso:["number-theory.catalan-seq","number-theory.catalan-take-while","number-theory.catalan?"]},"catalan?":{category:"number-theory",description:"Determines if a number is in the Catalan sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { catalan? } = import(number-theory);\ncatalan?(5)","let { catalan? } = import(number-theory);\ncatalan?(10)"],seeAlso:["number-theory.catalan-seq","number-theory.catalan-nth","number-theory.bell?","number-theory.catalan-take-while"]},"collatz-seq":{category:"number-theory",description:"Generates the collatz sequence starting from a given integer.",returns:{type:"integer",array:!0},args:{start:{type:"integer",description:"The starting integer for the collatz sequence."}},variants:[{argumentNames:["start"]}],examples:["let { collatz-seq } = import(number-theory);\ncollatz-seq(3)","let { collatz-seq } = import(number-theory);\ncollatz-seq(11)"],seeAlso:["number-theory.juggler-seq"]},"composite-seq":{category:"number-theory",description:"Generates the composite sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { composite-seq } = import(number-theory);\ncomposite-seq(1)","let { composite-seq } = import(number-theory);\ncomposite-seq(2)","let { composite-seq } = import(number-theory);\ncomposite-seq(10)"],seeAlso:["number-theory.composite-nth","number-theory.composite-take-while","number-theory.composite?","number-theory.prime-seq"]},"composite-take-while":{category:"number-theory",description:"Generates the composite sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { composite-take-while } = import(number-theory);\ncomposite-take-while(-> $ < 50)"],seeAlso:["number-theory.composite-seq","number-theory.composite-nth","number-theory.composite?"]},"composite-nth":{category:"number-theory",description:"Generates the nth term of the composite sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the composite number to retrieve."}},variants:[{argumentNames:["n"]}],examples:["let { composite-nth } = import(number-theory);\ncomposite-nth(1)","let { composite-nth } = import(number-theory);\ncomposite-nth(2)","let { composite-nth } = import(number-theory);\ncomposite-nth(10)"],seeAlso:["number-theory.composite-seq","number-theory.composite-take-while","number-theory.composite?"]},"composite?":{category:"number-theory",description:"Determines if a number is composite.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { composite? } = import(number-theory);\ncomposite?(4)","let { composite? } = import(number-theory);\ncomposite?(5)","let { composite? } = import(number-theory);\ncomposite?(11)"],seeAlso:["number-theory.composite-seq","number-theory.composite-nth","number-theory.prime?","number-theory.prime-factors","number-theory.composite-take-while"]},"deficient-seq":{category:"number-theory",description:"Generates the deficient numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { deficient-seq } = import(number-theory);\ndeficient-seq(1)","let { deficient-seq } = import(number-theory);\ndeficient-seq(5)"],seeAlso:["number-theory.deficient-nth","number-theory.deficient-take-while","number-theory.deficient?","number-theory.abundant-seq","number-theory.perfect-seq"]},"deficient-take-while":{category:"number-theory",description:"Generates the deficient numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { deficient-take-while } = import(number-theory);\ndeficient-take-while(-> $ < 100)"],seeAlso:["number-theory.deficient-seq","number-theory.deficient-nth","number-theory.deficient?"]},"deficient-nth":{category:"number-theory",description:"Generates the nth term of the deficient numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the number in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { deficient-nth } = import(number-theory);\ndeficient-nth(5)","let { deficient-nth } = import(number-theory);\ndeficient-nth(12)"],seeAlso:["number-theory.deficient-seq","number-theory.deficient-take-while","number-theory.deficient?"]},"deficient?":{category:"number-theory",description:"Checks if a number is deficient.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { deficient? } = import(number-theory);\ndeficient?(12)","let { deficient? } = import(number-theory);\ndeficient?(15)"],seeAlso:["number-theory.deficient-seq","number-theory.deficient-nth","number-theory.abundant?","number-theory.perfect?","number-theory.sigma","number-theory.divisors","number-theory.deficient-take-while"]},"factorial-seq":{category:"number-theory",description:"Generates the factorial sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 19 (the maximum length of the pre-calculated factorial numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { factorial-seq } = import(number-theory);\nfactorial-seq(1)","let { factorial-seq } = import(number-theory);\nfactorial-seq(2)","let { factorial-seq } = import(number-theory);\nfactorial-seq(3)","let { factorial-seq } = import(number-theory);\nfactorial-seq(4)","let { factorial-seq } = import(number-theory);\nfactorial-seq(5)","let { factorial-seq } = import(number-theory);\nfactorial-seq(10)"],seeAlso:["number-theory.factorial-nth","number-theory.factorial-take-while","number-theory.factorial?","number-theory.factorial"]},"factorial-take-while":{category:"number-theory",description:"Generates the factorial sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { factorial-take-while } = import(number-theory);\nfactorial-take-while(-> $ < 1000)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-nth","number-theory.factorial?"]},"factorial-nth":{category:"number-theory",description:"Generates the nth term of the factorial sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { factorial-nth } = import(number-theory);\nfactorial-nth(1)","let { factorial-nth } = import(number-theory);\nfactorial-nth(2)","let { factorial-nth } = import(number-theory);\nfactorial-nth(3)","let { factorial-nth } = import(number-theory);\nfactorial-nth(4)","let { factorial-nth } = import(number-theory);\nfactorial-nth(5)","let { factorial-nth } = import(number-theory);\nfactorial-nth(10)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-take-while","number-theory.factorial?","number-theory.factorial"]},"factorial?":{category:"number-theory",description:"Checks if a number is in the factorial sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { factorial? } = import(number-theory);\nfactorial?(1)","let { factorial? } = import(number-theory);\nfactorial?(2)","let { factorial? } = import(number-theory);\nfactorial?(3)","let { factorial? } = import(number-theory);\nfactorial?(4)","let { factorial? } = import(number-theory);\nfactorial?(5)","let { factorial? } = import(number-theory);\nfactorial?(6)","let { factorial? } = import(number-theory);\nfactorial?(7)","let { factorial? } = import(number-theory);\nfactorial?(8)","let { factorial? } = import(number-theory);\nfactorial?(9)","let { factorial? } = import(number-theory);\nfactorial?(3628800)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-nth","number-theory.factorial","number-theory.factorial-take-while"]},"fibonacci-seq":{category:"number-theory",description:"Generates the fibonacci sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 79 (the maximum length of the pre-calculated Fibonacci numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { fibonacci-seq } = import(number-theory);\nfibonacci-seq(1)","let { fibonacci-seq } = import(number-theory);\nfibonacci-seq(2)","let { fibonacci-seq } = import(number-theory);\nfibonacci-seq()"],seeAlso:["number-theory.fibonacci-nth","number-theory.fibonacci-take-while","number-theory.fibonacci?","number-theory.lucas-seq","number-theory.tribonacci-seq","number-theory.pell-seq","number-theory.padovan-seq"]},"fibonacci-take-while":{category:"number-theory",description:"Generates the fibonacci sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { fibonacci-take-while } = import(number-theory);\nfibonacci-take-while(-> $ < 100)"],seeAlso:["number-theory.fibonacci-seq","number-theory.fibonacci-nth","number-theory.fibonacci?"]},"fibonacci-nth":{category:"number-theory",description:"Generates the nth term of the fibonacci sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { fibonacci-nth } = import(number-theory);\nfibonacci-nth(5)","let { fibonacci-nth } = import(number-theory);\nfibonacci-nth(50)"],seeAlso:["number-theory.fibonacci-seq","number-theory.fibonacci-take-while","number-theory.fibonacci?"]},"fibonacci?":{category:"number-theory",description:"Determines if a number is in the fibonacci sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { fibonacci? } = import(number-theory);\nfibonacci?(0)","let { fibonacci? } = import(number-theory);\nfibonacci?(1)","let { fibonacci? } = import(number-theory);\nfibonacci?(2)","let { fibonacci? } = import(number-theory);\nfibonacci?(3)","let { fibonacci? } = import(number-theory);\nfibonacci?(4)","let { fibonacci? } = import(number-theory);\nfibonacci?(5)","let { fibonacci? } = import(number-theory);\nfibonacci?(6)","let { fibonacci? } = import(number-theory);\nfibonacci?(7)","let { fibonacci? } = import(number-theory);\nfibonacci?(8)","let { fibonacci? } = import(number-theory);\nfibonacci?(9)"],seeAlso:["number-theory.fibonacci-seq","number-theory.fibonacci-nth","number-theory.lucas?","number-theory.fibonacci-take-while","number-theory.tribonacci?","number-theory.padovan?","number-theory.pell?"]},"geometric-seq":{category:"number-theory",description:"Generates the geometric sequence for a given $start, $ratio, and $length.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["start","ratio","length"]}],examples:["let { geometric-seq } = import(number-theory);\ngeometric-seq(3, 2, 2)","let { geometric-seq } = import(number-theory);\ngeometric-seq(2, 3, 2)","let { geometric-seq } = import(number-theory);\ngeometric-seq(1, 2, 2)","let { geometric-seq } = import(number-theory);\ngeometric-seq(1, 1.5, 12)"],seeAlso:["number-theory.geometric-nth","number-theory.geometric-take-while","number-theory.geometric?","number-theory.arithmetic-seq"]},"geometric-take-while":{category:"number-theory",description:"Generates the geometric sequence while a condition is met.",returns:{type:"integer",array:!0},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},takeWhile:{type:"function",description:"A function that takes a number and an index and returns a boolean."}},variants:[{argumentNames:["start","ratio","takeWhile"]}],examples:["let { geometric-take-while } = import(number-theory);\ngeometric-take-while(1, 1.5, -> $ < 10)"],seeAlso:["number-theory.geometric-seq","number-theory.geometric-nth","number-theory.geometric?"]},"geometric-nth":{category:"number-theory",description:"Generates the nth term of the geometric sequence.",returns:{type:"number"},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["start","ratio","n"]}],examples:["let { geometric-nth } = import(number-theory);\ngeometric-nth(3, 2, 2)","let { geometric-nth } = import(number-theory);\ngeometric-nth(2, 3, 2)","let { geometric-nth } = import(number-theory);\ngeometric-nth(1, 2, 2)","let { geometric-nth } = import(number-theory);\ngeometric-nth(1, 1.5, 4)"],seeAlso:["number-theory.geometric-seq","number-theory.geometric-take-while","number-theory.geometric?"]},"geometric?":{category:"number-theory",description:"Checks if a number is in the geometric sequence.",returns:{type:"boolean"},args:{start:{type:"number",description:"The starting term of the sequence."},ratio:{type:"number",description:"The common ratio of the sequence."},n:{type:"number",description:"The number to check."}},variants:[{argumentNames:["start","ratio","n"]}],examples:["let { geometric? } = import(number-theory);\ngeometric?(1, 2, 1)","let { geometric? } = import(number-theory);\ngeometric?(2, 3, 2)","let { geometric? } = import(number-theory);\ngeometric?(3, 2, 2)","let { geometric? } = import(number-theory);\ngeometric?(1, 1.5, 2.25)","let { geometric? } = import(number-theory);\ngeometric?(1, 1.5, -4)"],seeAlso:["number-theory.geometric-seq","number-theory.geometric-nth","number-theory.arithmetic?","number-theory.geometric-take-while"]},"golomb-seq":{category:"number-theory",description:"Generates the Golomb sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { golomb-seq } = import(number-theory);\ngolomb-seq(5)","let { golomb-seq } = import(number-theory);\ngolomb-seq(20)"],seeAlso:["number-theory.golomb-nth","number-theory.golomb-take-while","number-theory.golomb?","number-theory.recaman-seq"]},"golomb-take-while":{category:"number-theory",description:"Generates the Golomb sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { golomb-take-while } = import(number-theory);\ngolomb-take-while(-> $ <= 10)"],seeAlso:["number-theory.golomb-seq","number-theory.golomb-nth","number-theory.golomb?"]},"golomb-nth":{category:"number-theory",description:"Generates the nth term of the Golomb sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { golomb-nth } = import(number-theory);\ngolomb-nth(5)","let { golomb-nth } = import(number-theory);\ngolomb-nth(1000)"],seeAlso:["number-theory.golomb-seq","number-theory.golomb-take-while","number-theory.golomb?"]},"golomb?":{category:"number-theory",description:"Checks if a number is in the Golomb sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { golomb? } = import(number-theory);\ngolomb?(1)","let { golomb? } = import(number-theory);\ngolomb?(2)","let { golomb? } = import(number-theory);\ngolomb?(3345)","let { golomb? } = import(number-theory);\ngolomb?(67867864)"],seeAlso:["number-theory.golomb-seq","number-theory.golomb-nth","number-theory.golomb-take-while"]},"happy-seq":{category:"number-theory",description:"Generates the happy sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { happy-seq } = import(number-theory);\nhappy-seq(1)","let { happy-seq } = import(number-theory);\nhappy-seq(2)","let { happy-seq } = import(number-theory);\nhappy-seq(20)"],seeAlso:["number-theory.happy-nth","number-theory.happy-take-while","number-theory.happy?","number-theory.lucky-seq"]},"happy-take-while":{category:"number-theory",description:"Generates the happy sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { happy-take-while } = import(number-theory);\nhappy-take-while(-> $ < 100)"],seeAlso:["number-theory.happy-seq","number-theory.happy-nth","number-theory.happy?"]},"happy-nth":{category:"number-theory",description:"Generates the nth term of the happy sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the happy number to return."}},variants:[{argumentNames:["n"]}],examples:["let { happy-nth } = import(number-theory);\nhappy-nth(1)","let { happy-nth } = import(number-theory);\nhappy-nth(2)","let { happy-nth } = import(number-theory);\nhappy-nth(20)"],seeAlso:["number-theory.happy-seq","number-theory.happy-take-while","number-theory.happy?"]},"happy?":{category:"number-theory",description:"Determines if a number is a happy number.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { happy? } = import(number-theory);\nhappy?(1)","let { happy? } = import(number-theory);\nhappy?(2)","let { happy? } = import(number-theory);\nhappy?(100)"],seeAlso:["number-theory.happy-seq","number-theory.happy-nth","number-theory.happy-take-while"]},"juggler-seq":{category:"number-theory",description:"Generates the Juggler sequence starting from a given integer.",returns:{type:"integer",array:!0},args:{start:{type:"integer",description:"The starting integer for the Juggler sequence."}},variants:[{argumentNames:["start"]}],examples:["let { juggler-seq } = import(number-theory);\njuggler-seq(3)","let { juggler-seq } = import(number-theory);\njuggler-seq(5)"],seeAlso:["number-theory.collatz-seq"]},"look-and-say-seq":{category:"number-theory",description:"Generates the Look-and-Say sequence up to a specified length.",returns:{type:"string",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { look-and-say-seq } = import(number-theory);\nlook-and-say-seq(5)"],seeAlso:["number-theory.look-and-say-nth","number-theory.look-and-say-take-while","number-theory.look-and-say?"]},"look-and-say-take-while":{category:"number-theory",description:"Generates the Look-and-Say sequence while a condition is met.",returns:{type:"string",array:!0},args:{takeWhile:{type:"function",description:"A function that takes a string and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { look-and-say-take-while } = import(number-theory);\nlook-and-say-take-while((term, index) -> count(term) < 10)","let { look-and-say-take-while } = import(number-theory);\nlook-and-say-take-while(-> $2 <= 10)"],seeAlso:["number-theory.look-and-say-seq","number-theory.look-and-say-nth","number-theory.look-and-say?"]},"look-and-say-nth":{category:"number-theory",description:"Generates the nth term of the Look-and-Say sequence.",returns:{type:"string"},args:{n:{type:"integer",description:"The index of the term in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { look-and-say-nth } = import(number-theory);\nlook-and-say-nth(5)"],seeAlso:["number-theory.look-and-say-seq","number-theory.look-and-say-take-while","number-theory.look-and-say?"]},"look-and-say?":{category:"number-theory",description:"Checks if a string is a valid Look-and-Say term.",returns:{type:"boolean"},args:{term:{type:"string",description:"The term to check."}},variants:[{argumentNames:["term"]}],examples:['let { look-and-say? } = import(number-theory);\nlook-and-say?("111221")','let { look-and-say? } = import(number-theory);\nlook-and-say?("123")'],seeAlso:["number-theory.look-and-say-seq","number-theory.look-and-say-nth","number-theory.look-and-say-take-while"]},"lucas-seq":{category:"number-theory",description:"Generates the lucas sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 77 (the maximum length of the pre-calculated Lucas numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { lucas-seq } = import(number-theory);\nlucas-seq(1)","let { lucas-seq } = import(number-theory);\nlucas-seq(2)","let { lucas-seq } = import(number-theory);\nlucas-seq()"],seeAlso:["number-theory.lucas-nth","number-theory.lucas-take-while","number-theory.lucas?","number-theory.fibonacci-seq"]},"lucas-take-while":{category:"number-theory",description:"Generates the lucas sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { lucas-take-while } = import(number-theory);\nlucas-take-while(-> $ < 100)"],seeAlso:["number-theory.lucas-seq","number-theory.lucas-nth","number-theory.lucas?"]},"lucas-nth":{category:"number-theory",description:"Generates the nth term of the lucas sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { lucas-nth } = import(number-theory);\nlucas-nth(1)","let { lucas-nth } = import(number-theory);\nlucas-nth(2)","let { lucas-nth } = import(number-theory);\nlucas-nth(10)"],seeAlso:["number-theory.lucas-seq","number-theory.lucas-take-while","number-theory.lucas?"]},"lucas?":{category:"number-theory",description:"Determines if a number is in the lucas sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { lucas? } = import(number-theory);\nlucas?(1)","let { lucas? } = import(number-theory);\nlucas?(2)","let { lucas? } = import(number-theory);\nlucas?(10)"],seeAlso:["number-theory.lucas-seq","number-theory.lucas-nth","number-theory.fibonacci?","number-theory.lucas-take-while"]},"lucky-seq":{category:"number-theory",description:"Generates the lucky sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { lucky-seq } = import(number-theory);\nlucky-seq(1)","let { lucky-seq } = import(number-theory);\nlucky-seq(2)","let { lucky-seq } = import(number-theory);\nlucky-seq(20)"],seeAlso:["number-theory.lucky-nth","number-theory.lucky-take-while","number-theory.lucky?","number-theory.happy-seq","number-theory.prime-seq"]},"lucky-take-while":{category:"number-theory",description:"Generates the lucky sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { lucky-take-while } = import(number-theory);\nlucky-take-while(-> $ < 100)"],seeAlso:["number-theory.lucky-seq","number-theory.lucky-nth","number-theory.lucky?"]},"lucky-nth":{category:"number-theory",description:"Generates the nth term of the lucky sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The position in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { lucky-nth } = import(number-theory);\nlucky-nth(1)","let { lucky-nth } = import(number-theory);\nlucky-nth(2)","let { lucky-nth } = import(number-theory);\nlucky-nth(20)"],seeAlso:["number-theory.lucky-seq","number-theory.lucky-take-while","number-theory.lucky?"]},"lucky?":{category:"number-theory",description:"Checks if a number is a lucky number.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { lucky? } = import(number-theory);\nlucky?(4)","let { lucky? } = import(number-theory);\nlucky?(7)","let { lucky? } = import(number-theory);\nlucky?(33)"],seeAlso:["number-theory.lucky-seq","number-theory.lucky-nth","number-theory.prime?","number-theory.lucky-take-while"]},"mersenne-seq":{category:"number-theory",description:"Generates the Mersenne sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 9 (the maximum length of the pre-calculated mersenne numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { mersenne-seq } = import(number-theory);\nmersenne-seq(1)","let { mersenne-seq } = import(number-theory);\nmersenne-seq(5)","let { mersenne-seq } = import(number-theory);\nmersenne-seq()"],seeAlso:["number-theory.mersenne-nth","number-theory.mersenne-take-while","number-theory.mersenne?","number-theory.prime-seq"]},"mersenne-take-while":{category:"number-theory",description:"Generates the Mersenne sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { mersenne-take-while } = import(number-theory);\nmersenne-take-while(-> $ < 1000)"],seeAlso:["number-theory.mersenne-seq","number-theory.mersenne-nth","number-theory.mersenne?"]},"mersenne-nth":{category:"number-theory",description:"Generates the nth term of the Mersenne sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { mersenne-nth } = import(number-theory);\nmersenne-nth(1)","let { mersenne-nth } = import(number-theory);\nmersenne-nth(5)"],seeAlso:["number-theory.mersenne-seq","number-theory.mersenne-take-while","number-theory.mersenne?"]},"mersenne?":{category:"number-theory",description:"Checks if a number is in the Mersenne sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { mersenne? } = import(number-theory);\nmersenne?(3)","let { mersenne? } = import(number-theory);\nmersenne?(4)","let { mersenne? } = import(number-theory);\nmersenne?(7)"],seeAlso:["number-theory.mersenne-seq","number-theory.mersenne-nth","number-theory.prime?","number-theory.mersenne-take-while"]},"padovan-seq":{category:"number-theory",description:"Generates the Padovan sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { padovan-seq } = import(number-theory);\npadovan-seq(5)","let { padovan-seq } = import(number-theory);\npadovan-seq(10)","let { padovan-seq } = import(number-theory);\npadovan-seq(20)"],seeAlso:["number-theory.padovan-nth","number-theory.padovan-take-while","number-theory.padovan?","number-theory.fibonacci-seq"]},"padovan-take-while":{category:"number-theory",description:"Generates the Padovan sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { padovan-take-while } = import(number-theory);\npadovan-take-while(-> $ < 1000)"],seeAlso:["number-theory.padovan-seq","number-theory.padovan-nth","number-theory.padovan?"]},"padovan-nth":{category:"number-theory",description:"Generates the nth term of the Padovan sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { padovan-nth } = import(number-theory);\npadovan-nth(5)","let { padovan-nth } = import(number-theory);\npadovan-nth(10)","let { padovan-nth } = import(number-theory);\npadovan-nth(20)"],seeAlso:["number-theory.padovan-seq","number-theory.padovan-take-while","number-theory.padovan?"]},"padovan?":{category:"number-theory",description:"Checks if a number is in the Padovan sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { padovan? } = import(number-theory);\npadovan?(1)","let { padovan? } = import(number-theory);\npadovan?(265)","let { padovan? } = import(number-theory);\npadovan?(6)"],seeAlso:["number-theory.padovan-seq","number-theory.padovan-nth","number-theory.fibonacci?","number-theory.padovan-take-while"]},"partition-seq":{category:"number-theory",description:"Generates the partition numbers up to a specified length. If no length is provided, it defaults to 299 (the maximum length of the pre-calculated partition numbers).",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { partition-seq } = import(number-theory);\npartition-seq(1)","let { partition-seq } = import(number-theory);\npartition-seq(10)","let { partition-seq } = import(number-theory);\npartition-seq()"],seeAlso:["number-theory.partition-nth","number-theory.partition-take-while","number-theory.partition?","number-theory.partitions","number-theory.count-partitions"]},"partition-take-while":{category:"number-theory",description:"Generates the partition numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { partition-take-while } = import(number-theory);\npartition-take-while(-> $ < 1000)"],seeAlso:["number-theory.partition-seq","number-theory.partition-nth","number-theory.partition?"]},"partition-nth":{category:"number-theory",description:"Generates the nth term of the partition numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the partition number to generate."}},variants:[{argumentNames:["n"]}],examples:["let { partition-nth } = import(number-theory);\npartition-nth(1)","let { partition-nth } = import(number-theory);\npartition-nth(5)"],seeAlso:["number-theory.partition-seq","number-theory.partition-take-while","number-theory.partition?"]},"partition?":{category:"number-theory",description:"Checks if a number is in the partition numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { partition? } = import(number-theory);\npartition?(0)","let { partition? } = import(number-theory);\npartition?(1)","let { partition? } = import(number-theory);\npartition?(2)","let { partition? } = import(number-theory);\npartition?(3)","let { partition? } = import(number-theory);\npartition?(4)","let { partition? } = import(number-theory);\npartition?(5)"],seeAlso:["number-theory.partition-seq","number-theory.partition-nth","number-theory.partitions","number-theory.partition-take-while"]},"pell-seq":{category:"number-theory",description:"Generates the Pell sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 42 (the maximum length of the pre-calculated Pell numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { pell-seq } = import(number-theory);\npell-seq(5)","let { pell-seq } = import(number-theory);\npell-seq(10)","let { pell-seq } = import(number-theory);\npell-seq()"],seeAlso:["number-theory.pell-nth","number-theory.pell-take-while","number-theory.pell?","number-theory.fibonacci-seq"]},"pell-take-while":{category:"number-theory",description:"Generates the Pell sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { pell-take-while } = import(number-theory);\npell-take-while(-> $ < 1000)"],seeAlso:["number-theory.pell-seq","number-theory.pell-nth","number-theory.pell?"]},"pell-nth":{category:"number-theory",description:"Generates the nth term of the Pell sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { pell-nth } = import(number-theory);\npell-nth(5)","let { pell-nth } = import(number-theory);\npell-nth(10)","let { pell-nth } = import(number-theory);\npell-nth(20)"],seeAlso:["number-theory.pell-seq","number-theory.pell-take-while","number-theory.pell?"]},"pell?":{category:"number-theory",description:"Checks if a number is a Pell number.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { pell? } = import(number-theory);\npell?(1)","let { pell? } = import(number-theory);\npell?(470832)","let { pell? } = import(number-theory);\npell?(10)"],seeAlso:["number-theory.pell-seq","number-theory.pell-nth","number-theory.fibonacci?","number-theory.pell-take-while"]},"perfect-seq":{category:"number-theory",description:"Generates the perfect numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If no length is provided, it defaults to 7 (the maximum length of the pre-calculated perfect numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { perfect-seq } = import(number-theory);\nperfect-seq(1)","let { perfect-seq } = import(number-theory);\nperfect-seq(5)","let { perfect-seq } = import(number-theory);\nperfect-seq()"],seeAlso:["number-theory.perfect-nth","number-theory.perfect-take-while","number-theory.perfect?","number-theory.abundant-seq","number-theory.deficient-seq","number-theory.amicable?"]},"perfect-take-while":{category:"number-theory",description:"Generates the perfect numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-take-while } = import(number-theory);\nperfect-take-while(-> $ < 1000)"],seeAlso:["number-theory.perfect-seq","number-theory.perfect-nth","number-theory.perfect?"]},"perfect-nth":{category:"number-theory",description:"Generates the nth term of the perfect numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the perfect number to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-nth } = import(number-theory);\nperfect-nth(1)","let { perfect-nth } = import(number-theory);\nperfect-nth(5)"],seeAlso:["number-theory.perfect-seq","number-theory.perfect-take-while","number-theory.perfect?"]},"perfect?":{category:"number-theory",description:"Checks if a number is in the perfect numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect? } = import(number-theory);\nperfect?(0)","let { perfect? } = import(number-theory);\nperfect?(1)","let { perfect? } = import(number-theory);\nperfect?(2)","let { perfect? } = import(number-theory);\nperfect?(3)","let { perfect? } = import(number-theory);\nperfect?(4)","let { perfect? } = import(number-theory);\nperfect?(5)","let { perfect? } = import(number-theory);\nperfect?(6)","let { perfect? } = import(number-theory);\nperfect?(7)","let { perfect? } = import(number-theory);\nperfect?(8)","let { perfect? } = import(number-theory);\nperfect?(9)"],seeAlso:["number-theory.perfect-seq","number-theory.perfect-nth","number-theory.abundant?","number-theory.deficient?","number-theory.sigma","number-theory.perfect-take-while","number-theory.amicable?","number-theory.proper-divisors"]},"perfect-square-seq":{category:"number-theory",description:"Generates the perfect square numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { perfect-square-seq } = import(number-theory);\nperfect-square-seq(5)","let { perfect-square-seq } = import(number-theory);\nperfect-square-seq(20)"],seeAlso:["number-theory.perfect-square-nth","number-theory.perfect-square-take-while","number-theory.perfect-square?","number-theory.perfect-cube-seq","number-theory.perfect-power-seq","number-theory.polygonal-seq"]},"perfect-square-take-while":{category:"number-theory",description:"Generates the perfect square numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-square-take-while } = import(number-theory);\nperfect-square-take-while(-> $ <= 100)"],seeAlso:["number-theory.perfect-square-seq","number-theory.perfect-square-nth","number-theory.perfect-square?"]},"perfect-square-nth":{category:"number-theory",description:"Generates the nth term of the perfect square numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-square-nth } = import(number-theory);\nperfect-square-nth(1)","let { perfect-square-nth } = import(number-theory);\nperfect-square-nth(5)"],seeAlso:["number-theory.perfect-square-seq","number-theory.perfect-square-take-while","number-theory.perfect-square?"]},"perfect-square?":{category:"number-theory",description:"Checks if a number is a perfect square.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-square? } = import(number-theory);\nperfect-square?(16)","let { perfect-square? } = import(number-theory);\nperfect-square?(20)"],seeAlso:["number-theory.perfect-square-seq","number-theory.perfect-square-nth","number-theory.perfect-cube?","number-theory.perfect-power?","number-theory.perfect-square-take-while","number-theory.perfect-power","number-theory.polygonal?"]},"perfect-cube-seq":{category:"number-theory",description:"Generates the perfect cube numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { perfect-cube-seq } = import(number-theory);\nperfect-cube-seq(5)","let { perfect-cube-seq } = import(number-theory);\nperfect-cube-seq(20)"],seeAlso:["number-theory.perfect-cube-nth","number-theory.perfect-cube-take-while","number-theory.perfect-cube?","number-theory.perfect-square-seq","number-theory.perfect-power-seq"]},"perfect-cube-take-while":{category:"number-theory",description:"Generates the perfect cube numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-cube-take-while } = import(number-theory);\nperfect-cube-take-while(-> $ <= 100)"],seeAlso:["number-theory.perfect-cube-seq","number-theory.perfect-cube-nth","number-theory.perfect-cube?"]},"perfect-cube-nth":{category:"number-theory",description:"Generates the nth term of the perfect cube numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-cube-nth } = import(number-theory);\nperfect-cube-nth(1)","let { perfect-cube-nth } = import(number-theory);\nperfect-cube-nth(5)"],seeAlso:["number-theory.perfect-cube-seq","number-theory.perfect-cube-take-while","number-theory.perfect-cube?"]},"perfect-cube?":{category:"number-theory",description:"Checks if a number is in the perfect cube numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-cube? } = import(number-theory);\nperfect-cube?(7)","let { perfect-cube? } = import(number-theory);\nperfect-cube?(8)","let { perfect-cube? } = import(number-theory);\nperfect-cube?(9)"],seeAlso:["number-theory.perfect-cube-seq","number-theory.perfect-cube-nth","number-theory.perfect-square?","number-theory.perfect-power?","number-theory.perfect-cube-take-while","number-theory.perfect-power"]},"perfect-power-seq":{category:"number-theory",description:"Generates the perfect power numbers up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { perfect-power-seq } = import(number-theory);\nperfect-power-seq(5)","let { perfect-power-seq } = import(number-theory);\nperfect-power-seq(20)"],seeAlso:["number-theory.perfect-power-nth","number-theory.perfect-power-take-while","number-theory.perfect-power?","number-theory.perfect-power","number-theory.perfect-square-seq","number-theory.perfect-cube-seq"]},"perfect-power-take-while":{category:"number-theory",description:"Generates the perfect power numbers while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { perfect-power-take-while } = import(number-theory);\nperfect-power-take-while(-> $ <= 100)"],seeAlso:["number-theory.perfect-power-seq","number-theory.perfect-power-nth","number-theory.perfect-power?"]},"perfect-power-nth":{category:"number-theory",description:"Generates the nth term of the perfect power numbers.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-power-nth } = import(number-theory);\nperfect-power-nth(3)","let { perfect-power-nth } = import(number-theory);\nperfect-power-nth(15)"],seeAlso:["number-theory.perfect-power-seq","number-theory.perfect-power-take-while","number-theory.perfect-power?"]},"perfect-power?":{category:"number-theory",description:"Checks if a number is in the perfect power numbers.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-power? } = import(number-theory);\nperfect-power?(7)","let { perfect-power? } = import(number-theory);\nperfect-power?(8)","let { perfect-power? } = import(number-theory);\nperfect-power?(9)","let { perfect-power? } = import(number-theory);\nperfect-power?(10)"],seeAlso:["number-theory.perfect-power-seq","number-theory.perfect-power-nth","number-theory.perfect-power","number-theory.perfect-square?","number-theory.perfect-cube?","number-theory.perfect-power-take-while"]},"polygonal-seq":{category:"number-theory",description:"Generates the polygonal sequence for a given number of sides and length.",returns:{type:"integer",array:!0},args:{sides:{type:"integer",description:"The number of sides of the polygon."},length:{type:"integer",description:"The length of the sequence to generate."},a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["sides","length"]}],examples:["let { polygonal-seq } = import(number-theory);\npolygonal-seq(3, 2)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(4, 2)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(5, 3)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(6, 5)","let { polygonal-seq } = import(number-theory);\npolygonal-seq(100, 10)"],seeAlso:["number-theory.polygonal-nth","number-theory.polygonal-take-while","number-theory.polygonal?","number-theory.perfect-square-seq"]},"polygonal-take-while":{category:"number-theory",description:"Generates the polygonal sequence while a condition is met.",returns:{type:"integer",array:!0},args:{sides:{type:"integer",description:"The number of sides of the polygon."},takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."},a:{type:"integer"},b:{type:"function"}},variants:[{argumentNames:["sides","takeWhile"]}],examples:["let { polygonal-take-while } = import(number-theory);\npolygonal-take-while(15, -> $ < 1000)"],seeAlso:["number-theory.polygonal-seq","number-theory.polygonal-nth","number-theory.polygonal?"]},"polygonal-nth":{category:"number-theory",description:"Generates the nth term of the polygonal sequence.",returns:{type:"integer"},args:{sides:{type:"integer",description:"The number of sides of the polygon."},n:{type:"integer",description:"The index of the term to generate."},a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["sides","n"]}],examples:["let { polygonal-nth } = import(number-theory);\npolygonal-nth(3, 9)","let { polygonal-nth } = import(number-theory);\npolygonal-nth(4, 5)","let { polygonal-nth } = import(number-theory);\npolygonal-nth(5, 5)"],seeAlso:["number-theory.polygonal-seq","number-theory.polygonal-take-while","number-theory.polygonal?"]},"polygonal?":{category:"number-theory",description:"Checks if a number is in the polygonal sequence.",returns:{type:"boolean"},args:{sides:{type:"integer",description:"The number of sides of the polygon."},n:{type:"integer",description:"The number to check."},a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["sides","n"]}],examples:["let { polygonal? } = import(number-theory);\npolygonal?(3, 10)","let { polygonal? } = import(number-theory);\npolygonal?(3, 9)","let { polygonal? } = import(number-theory);\npolygonal?(4, 10000)","let { polygonal? } = import(number-theory);\npolygonal?(4, 1000)","let { polygonal? } = import(number-theory);\npolygonal?(6, 45)"],seeAlso:["number-theory.polygonal-seq","number-theory.polygonal-nth","number-theory.perfect-square?","number-theory.polygonal-take-while"]},"prime-seq":{category:"number-theory",description:"Generates the prime sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { prime-seq } = import(number-theory);\nprime-seq(1)","let { prime-seq } = import(number-theory);\nprime-seq(2)","let { prime-seq } = import(number-theory);\nprime-seq(10)"],seeAlso:["number-theory.prime-nth","number-theory.prime-take-while","number-theory.prime?","number-theory.composite-seq","number-theory.mersenne-seq","number-theory.lucky-seq"]},"prime-take-while":{category:"number-theory",description:"Generates the prime sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { prime-take-while } = import(number-theory);\nprime-take-while(-> $ < 50)"],seeAlso:["number-theory.prime-seq","number-theory.prime-nth","number-theory.prime?"]},"prime-nth":{category:"number-theory",description:"Generates the nth term of the prime sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { prime-nth } = import(number-theory);\nprime-nth(1)","let { prime-nth } = import(number-theory);\nprime-nth(2)","let { prime-nth } = import(number-theory);\nprime-nth(10)"],seeAlso:["number-theory.prime-seq","number-theory.prime-take-while","number-theory.prime?"]},"prime?":{category:"number-theory",description:"Determines if a number is prime.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { prime? } = import(number-theory);\nprime?(1)","let { prime? } = import(number-theory);\nprime?(2)","let { prime? } = import(number-theory);\nprime?(3)","let { prime? } = import(number-theory);\nprime?(4)","let { prime? } = import(number-theory);\nprime?(997)","let { prime? } = import(number-theory);\nprime?(1001)"],seeAlso:["number-theory.prime-seq","number-theory.prime-nth","number-theory.composite?","number-theory.prime-factors","number-theory.mersenne?","number-theory.prime-take-while","number-theory.lucky?"]},"recaman-seq":{category:"number-theory",description:"Generates the Recaman sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { recaman-seq } = import(number-theory);\nrecaman-seq(5)","let { recaman-seq } = import(number-theory);\nrecaman-seq(10)","let { recaman-seq } = import(number-theory);\nrecaman-seq(20)"],seeAlso:["number-theory.recaman-nth","number-theory.recaman-take-while","number-theory.recaman?","number-theory.golomb-seq"]},"recaman-take-while":{category:"number-theory",description:"Generates the Recaman sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { recaman-take-while } = import(number-theory);\nrecaman-take-while(-> $ < 10)"],seeAlso:["number-theory.recaman-seq","number-theory.recaman-nth","number-theory.recaman?"]},"recaman-nth":{category:"number-theory",description:"Generates the nth term of the Recaman sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { recaman-nth } = import(number-theory);\nrecaman-nth(5)","let { recaman-nth } = import(number-theory);\nrecaman-nth(10)","let { recaman-nth } = import(number-theory);\nrecaman-nth(20)"],seeAlso:["number-theory.recaman-seq","number-theory.recaman-take-while","number-theory.recaman?"]},"recaman?":{category:"number-theory",description:"Checks if a number is in the Recaman sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { recaman? } = import(number-theory);\nrecaman?(5)","let { recaman? } = import(number-theory);\nrecaman?(10)","let { recaman? } = import(number-theory);\nrecaman?(20)"],seeAlso:["number-theory.recaman-seq","number-theory.recaman-nth","number-theory.recaman-take-while"]},"sylvester-seq":{category:"number-theory",description:"Generates the Sylvester sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate. If not provided, the default is 6 (the maximum length of the pre-calculated Sylvester numbers)."}},variants:[{argumentNames:["length"]},{argumentNames:[]}],examples:["let { sylvester-seq } = import(number-theory);\nsylvester-seq(5)","let { sylvester-seq } = import(number-theory);\nsylvester-seq()","let { sylvester-seq } = import(number-theory);\nsylvester-seq()"],seeAlso:["number-theory.sylvester-nth","number-theory.sylvester-take-while","number-theory.sylvester?"]},"sylvester-take-while":{category:"number-theory",description:"Generates the Sylvester sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { sylvester-take-while } = import(number-theory);\nsylvester-take-while(-> $ < 100000)"],seeAlso:["number-theory.sylvester-seq","number-theory.sylvester-nth","number-theory.sylvester?"]},"sylvester-nth":{category:"number-theory",description:"Generates the nth term of the Sylvester sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { sylvester-nth } = import(number-theory);\nsylvester-nth(1)","let { sylvester-nth } = import(number-theory);\nsylvester-nth(5)"],seeAlso:["number-theory.sylvester-seq","number-theory.sylvester-take-while","number-theory.sylvester?"]},"sylvester?":{category:"number-theory",description:"Checks if a number is in the Sylvester sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { sylvester? } = import(number-theory);\nsylvester?(2)","let { sylvester? } = import(number-theory);\nsylvester?(3)","let { sylvester? } = import(number-theory);\nsylvester?(6)"],seeAlso:["number-theory.sylvester-seq","number-theory.sylvester-nth","number-theory.sylvester-take-while"]},"thue-morse-seq":{category:"number-theory",description:"Generates the Thue-Morse sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { thue-morse-seq } = import(number-theory);\nthue-morse-seq(5)","let { thue-morse-seq } = import(number-theory);\nthue-morse-seq(10)","let { thue-morse-seq } = import(number-theory);\nthue-morse-seq(20)"],seeAlso:["number-theory.thue-morse-nth","number-theory.thue-morse-take-while","number-theory.thue-morse?"]},"thue-morse-take-while":{category:"number-theory",description:"Generates the Thue-Morse sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { thue-morse-take-while } = import(number-theory);\nthue-morse-take-while(-> $2 < 10)"],seeAlso:["number-theory.thue-morse-seq","number-theory.thue-morse-nth","number-theory.thue-morse?"]},"thue-morse-nth":{category:"number-theory",description:"Generates the nth term of the Thue-Morse sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term in the sequence."}},variants:[{argumentNames:["n"]}],examples:["let { thue-morse-nth } = import(number-theory);\nthue-morse-nth(5)","let { thue-morse-nth } = import(number-theory);\nthue-morse-nth(10)","let { thue-morse-nth } = import(number-theory);\nthue-morse-nth(20)"],seeAlso:["number-theory.thue-morse-seq","number-theory.thue-morse-take-while","number-theory.thue-morse?"]},"thue-morse?":{category:"number-theory",description:"Checks if a number is part of the Thue-Morse sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { thue-morse? } = import(number-theory);\nthue-morse?(1)","let { thue-morse? } = import(number-theory);\nthue-morse?(2)"],seeAlso:["number-theory.thue-morse-seq","number-theory.thue-morse-nth","number-theory.thue-morse-take-while"]},"tribonacci-seq":{category:"number-theory",description:"Generates the tribonacci sequence up to a specified length.",returns:{type:"integer",array:!0},args:{length:{type:"integer",description:"The length of the sequence to generate."}},variants:[{argumentNames:["length"]}],examples:["let { tribonacci-seq } = import(number-theory);\ntribonacci-seq(1)","let { tribonacci-seq } = import(number-theory);\ntribonacci-seq(2)","let { tribonacci-seq } = import(number-theory);\ntribonacci-seq(10)"],seeAlso:["number-theory.tribonacci-nth","number-theory.tribonacci-take-while","number-theory.tribonacci?","number-theory.fibonacci-seq"]},"tribonacci-take-while":{category:"number-theory",description:"Generates the tribonacci sequence while a condition is met.",returns:{type:"integer",array:!0},args:{takeWhile:{type:"function",description:"A function that takes an integer and an index and returns a boolean."}},variants:[{argumentNames:["takeWhile"]}],examples:["let { tribonacci-take-while } = import(number-theory);\ntribonacci-take-while(-> $ < 100)"],seeAlso:["number-theory.tribonacci-seq","number-theory.tribonacci-nth","number-theory.tribonacci?"]},"tribonacci-nth":{category:"number-theory",description:"Generates the nth term of the tribonacci sequence.",returns:{type:"integer"},args:{n:{type:"integer",description:"The index of the term to generate."}},variants:[{argumentNames:["n"]}],examples:["let { tribonacci-nth } = import(number-theory);\ntribonacci-nth(1)","let { tribonacci-nth } = import(number-theory);\ntribonacci-nth(2)","let { tribonacci-nth } = import(number-theory);\ntribonacci-nth(10)"],seeAlso:["number-theory.tribonacci-seq","number-theory.tribonacci-take-while","number-theory.tribonacci?"]},"tribonacci?":{category:"number-theory",description:"Determines if a number is in the tribonacci sequence.",returns:{type:"boolean"},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { tribonacci? } = import(number-theory);\ntribonacci?(0)","let { tribonacci? } = import(number-theory);\ntribonacci?(1)","let { tribonacci? } = import(number-theory);\ntribonacci?(2)","let { tribonacci? } = import(number-theory);\ntribonacci?(3)","let { tribonacci? } = import(number-theory);\ntribonacci?(4)","let { tribonacci? } = import(number-theory);\ntribonacci?(5)","let { tribonacci? } = import(number-theory);\ntribonacci?(6)","let { tribonacci? } = import(number-theory);\ntribonacci?(7)","let { tribonacci? } = import(number-theory);\ntribonacci?(8)","let { tribonacci? } = import(number-theory);\ntribonacci?(9)","let { tribonacci? } = import(number-theory);\ntribonacci?(10)"],seeAlso:["number-theory.tribonacci-seq","number-theory.tribonacci-nth","number-theory.fibonacci?","number-theory.tribonacci-take-while"]},"count-combinations":{category:"number-theory",description:"Calculates the number of combinations of n items taken k at a time.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { count-combinations } = import(number-theory);\ncount-combinations(5, 3)","let { count-combinations } = import(number-theory);\ncount-combinations(10, 2)"],seeAlso:["number-theory.combinations","number-theory.count-permutations","number-theory.factorial","number-theory.multinomial","number-theory.stirling-second","number-theory.count-partitions","number-theory.count-power-set"]},combinations:{category:"number-theory",description:"Generates all possible combinations of a specified size from a collection.",returns:{type:"array",array:!0},args:{set:{type:"array",array:!0,description:"The input collection to generate combinations from."},n:{type:"integer",description:"The size of each combination."},a:{type:"array"},b:{type:"integer"}},variants:[{argumentNames:["set","n"]}],examples:["let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 2)",'let { combinations } = import(number-theory);\ncombinations(["a", "b", "c"], 2)',"let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 0)","let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 1)","let { combinations } = import(number-theory);\ncombinations([1, 2, 3], 3)"],seeAlso:["number-theory.count-combinations","number-theory.permutations","number-theory.power-set","number-theory.cartesian-product","number-theory.partitions"]},"count-derangements":{category:"number-theory",description:"Calculates the number of derangements (permutations where no element appears in its original position) of n items.",returns:{type:"integer"},args:{n:{type:"integer",description:"The total number of items."}},variants:[{argumentNames:["n"]}],examples:["let { count-derangements } = import(number-theory);\ncount-derangements(4)","let { count-derangements } = import(number-theory);\ncount-derangements(5)"],seeAlso:["number-theory.derangements","number-theory.count-permutations","number-theory.factorial"]},derangements:{category:"number-theory",description:"Generates all derangements (permutations where no element appears in its original position) of a set.",returns:{type:"array",array:!0},args:{set:{type:"array",array:!0,description:"The input collection to generate derangements from."}},variants:[{argumentNames:["set"]}],examples:["let { derangements } = import(number-theory);\nderangements([1, 2, 3, 4])",'let { derangements } = import(number-theory);\nderangements(["a", "b", "c"])'],seeAlso:["number-theory.count-derangements","number-theory.permutations"]},divisors:{category:"number-theory",description:"Returns the divisors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to find divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { divisors } = import(number-theory);\ndivisors(12)","let { divisors } = import(number-theory);\ndivisors(100)","let { divisors } = import(number-theory);\ndivisors(37)"],seeAlso:["number-theory.count-divisors","number-theory.proper-divisors","number-theory.sigma","number-theory.prime-factors","number-theory.divisible-by?","number-theory.lcm","number-theory.abundant?","number-theory.deficient?","number-theory.count-proper-divisors"]},"count-divisors":{category:"number-theory",description:"Returns the number of divisors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-divisors } = import(number-theory);\ncount-divisors(12)","let { count-divisors } = import(number-theory);\ncount-divisors(100)","let { count-divisors } = import(number-theory);\ncount-divisors(37)"],seeAlso:["number-theory.divisors","number-theory.count-proper-divisors","number-theory.sigma"]},"proper-divisors":{category:"number-theory",description:"Returns the proper divisors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to find proper divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { proper-divisors } = import(number-theory);\nproper-divisors(12)","let { proper-divisors } = import(number-theory);\nproper-divisors(100)","let { proper-divisors } = import(number-theory);\nproper-divisors(37)"],seeAlso:["number-theory.count-proper-divisors","number-theory.divisors","number-theory.amicable?","number-theory.perfect?"]},"count-proper-divisors":{category:"number-theory",description:"Returns the number of proper divisors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count proper divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-proper-divisors } = import(number-theory);\ncount-proper-divisors(12)","let { count-proper-divisors } = import(number-theory);\ncount-proper-divisors(100)","let { count-proper-divisors } = import(number-theory);\ncount-proper-divisors(37)"],seeAlso:["number-theory.proper-divisors","number-theory.count-divisors","number-theory.divisors"]},factorial:{category:"number-theory",description:"Calculates the factorial of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the factorial for."}},variants:[{argumentNames:["n"]}],examples:["let { factorial } = import(number-theory);\nfactorial(5)","let { factorial } = import(number-theory);\nfactorial(0)","let { factorial } = import(number-theory);\nfactorial(10)","let { factorial } = import(number-theory);\nfactorial(20)"],seeAlso:["number-theory.factorial-seq","number-theory.factorial-nth","number-theory.factorial?","number-theory.count-combinations","number-theory.count-permutations","number-theory.multinomial","number-theory.count-derangements"]},partitions:{category:"number-theory",description:"Generates all partitions of a number.",returns:{type:"array",array:!0},args:{n:{type:"integer",description:"The number to partition."}},variants:[{argumentNames:["n"]}],examples:["let { partitions } = import(number-theory);\npartitions(4)","let { partitions } = import(number-theory);\npartitions(8)"],seeAlso:["number-theory.count-partitions","number-theory.partition-seq","number-theory.combinations","number-theory.partition?"]},"count-partitions":{category:"number-theory",description:"Returns the number of partitions of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count partitions for."}},variants:[{argumentNames:["n"]}],examples:["let { count-partitions } = import(number-theory);\ncount-partitions(4)","let { count-partitions } = import(number-theory);\ncount-partitions(8)","let { count-partitions } = import(number-theory);\ncount-partitions(15)"],seeAlso:["number-theory.partitions","number-theory.partition-seq","number-theory.count-combinations"]},permutations:{category:"number-theory",description:"Generates all permutations of a collection.",returns:{type:"array",array:!0},args:{set:{type:"array",array:!0,description:"The input collection to generate permutations from."}},variants:[{argumentNames:["set"]}],examples:["let { permutations } = import(number-theory);\npermutations([1, 2, 3])",'let { permutations } = import(number-theory);\npermutations(["a", "b", "c"])',"let { permutations } = import(number-theory);\npermutations([1, 2, 3, 4])","let { permutations } = import(number-theory);\npermutations([1, 2])","let { permutations } = import(number-theory);\npermutations([1])","let { permutations } = import(number-theory);\npermutations([])"],seeAlso:["number-theory.count-permutations","number-theory.combinations","number-theory.derangements","number-theory.cartesian-product"]},"count-permutations":{category:"number-theory",description:"Returns the number of permutations of n items taken k at a time.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { count-permutations } = import(number-theory);\ncount-permutations(5, 3)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 2)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 10)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 0)","let { count-permutations } = import(number-theory);\ncount-permutations(10, 1)"],seeAlso:["number-theory.permutations","number-theory.count-combinations","number-theory.factorial","number-theory.multinomial","number-theory.stirling-first","number-theory.count-derangements"]},"power-set":{category:"number-theory",description:"Generates the power set of a collection.",returns:{type:"array",array:!0},args:{set:{type:"any",array:!0,description:"The input collection to generate the power set from."}},variants:[{argumentNames:["set"]}],examples:['let { power-set } = import(number-theory);\npower-set(["a", "b", "c"])',"let { power-set } = import(number-theory);\npower-set([1, 2])","let { power-set } = import(number-theory);\npower-set([1])","let { power-set } = import(number-theory);\npower-set([])"],seeAlso:["number-theory.count-power-set","number-theory.combinations","number-theory.cartesian-product"]},"count-power-set":{category:"number-theory",description:"Returns the number of subsets of a set.",returns:{type:"integer"},args:{n:{type:"integer",description:"The size of the set."}},variants:[{argumentNames:["n"]}],examples:["let { count-power-set } = import(number-theory);\ncount-power-set(3)","let { count-power-set } = import(number-theory);\ncount-power-set(5)","let { count-power-set } = import(number-theory);\ncount-power-set(10)"],seeAlso:["number-theory.power-set","number-theory.count-combinations"]},"prime-factors":{category:"number-theory",description:"Returns the prime factors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to factor."}},variants:[{argumentNames:["n"]}],examples:["let { prime-factors } = import(number-theory);\nprime-factors(12)","let { prime-factors } = import(number-theory);\nprime-factors(100)","let { prime-factors } = import(number-theory);\nprime-factors(37)"],seeAlso:["number-theory.count-prime-factors","number-theory.distinct-prime-factors","number-theory.prime?","number-theory.divisors","number-theory.euler-totient","number-theory.mobius","number-theory.composite?","number-theory.count-distinct-prime-factors"]},"count-prime-factors":{category:"number-theory",description:"Returns the number of prime factors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count prime factors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-prime-factors } = import(number-theory);\ncount-prime-factors(12)","let { count-prime-factors } = import(number-theory);\ncount-prime-factors(100)","let { count-prime-factors } = import(number-theory);\ncount-prime-factors(37)"],seeAlso:["number-theory.prime-factors","number-theory.distinct-prime-factors","number-theory.count-distinct-prime-factors"]},"distinct-prime-factors":{category:"number-theory",description:"Returns the distinct prime factors of a number.",returns:{type:"integer",array:!0},args:{n:{type:"integer",description:"The number to find distinct prime factors for."}},variants:[{argumentNames:["n"]}],examples:["let { distinct-prime-factors } = import(number-theory);\ndistinct-prime-factors(12)","let { distinct-prime-factors } = import(number-theory);\ndistinct-prime-factors(100)","let { distinct-prime-factors } = import(number-theory);\ndistinct-prime-factors(37)"],seeAlso:["number-theory.prime-factors","number-theory.count-distinct-prime-factors","number-theory.count-prime-factors"]},"count-distinct-prime-factors":{category:"number-theory",description:"Returns the number of distinct prime factors of a number.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to count distinct prime factors for."}},variants:[{argumentNames:["n"]}],examples:["let { count-distinct-prime-factors } = import(number-theory);\ncount-distinct-prime-factors(12)","let { count-distinct-prime-factors } = import(number-theory);\ncount-distinct-prime-factors(100)","let { count-distinct-prime-factors } = import(number-theory);\ncount-distinct-prime-factors(37)"],seeAlso:["number-theory.distinct-prime-factors","number-theory.prime-factors","number-theory.count-prime-factors"]},"coprime?":{category:"number-theory",description:"Checks if two numbers are coprime (i.e., their GCD is 1).",returns:{type:"boolean"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { coprime? } = import(number-theory);\ncoprime?(12, 8)","let { coprime? } = import(number-theory);\ncoprime?(12, 5)","let { coprime? } = import(number-theory);\ncoprime?(37, 1)","let { coprime? } = import(number-theory);\ncoprime?(0, 0)","let { coprime? } = import(number-theory);\ncoprime?(0, 5)","let { coprime? } = import(number-theory);\ncoprime?(5, 0)","let { coprime? } = import(number-theory);\ncoprime?(1, 0)","let { coprime? } = import(number-theory);\ncoprime?(0, 1)","let { coprime? } = import(number-theory);\ncoprime?(1, 1)","let { coprime? } = import(number-theory);\ncoprime?(2, 3)"],seeAlso:["number-theory.gcd","number-theory.euler-totient","number-theory.divisible-by?","number-theory.lcm","number-theory.carmichael-lambda"]},"divisible-by?":{category:"number-theory",description:"Checks if a number is divisible by another number.",returns:{type:"boolean"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { divisible-by? } = import(number-theory);\ndivisible-by?(12, 4)","let { divisible-by? } = import(number-theory);\ndivisible-by?(12, 5)","let { divisible-by? } = import(number-theory);\ndivisible-by?(37, 1)","let { divisible-by? } = import(number-theory);\ndivisible-by?(0, 0)","let { divisible-by? } = import(number-theory);\ndivisible-by?(0, 5)","let { divisible-by? } = import(number-theory);\ndivisible-by?(5, 0)"],seeAlso:["number-theory.divisors","number-theory.gcd","number-theory.coprime?"]},gcd:{category:"number-theory",description:"Calculates the greatest common divisor (GCD) of two numbers.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { gcd } = import(number-theory);\ngcd(100, 25)","let { gcd } = import(number-theory);\ngcd(37, 1)","let { gcd } = import(number-theory);\ngcd(0, 0)","let { gcd } = import(number-theory);\ngcd(0, 5)","let { gcd } = import(number-theory);\ngcd(5, 0)"],seeAlso:["number-theory.lcm","number-theory.extended-gcd","number-theory.coprime?","number-theory.divisible-by?"]},lcm:{category:"number-theory",description:"Calculates the least common multiple (LCM) of two numbers.",returns:{type:"integer"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { lcm } = import(number-theory);\nlcm(100, 25)","let { lcm } = import(number-theory);\nlcm(37, 1)","let { lcm } = import(number-theory);\nlcm(0, 5)","let { lcm } = import(number-theory);\nlcm(5, 0)"],seeAlso:["number-theory.gcd","number-theory.divisors","number-theory.coprime?"]},multinomial:{category:"number-theory",description:"Calculates the multinomial coefficient from of a list of numbers representing the sizes of each group.",returns:{type:"integer"},args:{args:{type:"integer",rest:!0,description:"The numbers representing the sizes of each group."}},variants:[{argumentNames:["args"]}],examples:["let { multinomial } = import(number-theory);\nmultinomial(5, 2, 3)","let { multinomial } = import(number-theory);\nmultinomial(10, 2, 3, 5)"],seeAlso:["number-theory.count-combinations","number-theory.factorial","number-theory.count-permutations"],hideOperatorForm:!0},"amicable?":{category:"number-theory",description:"Checks if two numbers are amicable (i.e., the sum of the proper divisors of each number equals the other number).",returns:{type:"boolean"},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { amicable? } = import(number-theory);\namicable?(220, 284)","let { amicable? } = import(number-theory);\namicable?(1184, 1210)","let { amicable? } = import(number-theory);\namicable?(2620, 2924)","let { amicable? } = import(number-theory);\namicable?(5020, 5564)","let { amicable? } = import(number-theory);\namicable?(6232, 6368)"],seeAlso:["number-theory.proper-divisors","number-theory.perfect?","number-theory.sigma","number-theory.perfect-seq"]},"euler-totient":{category:"number-theory",description:"Calculates the Euler's totient function (φ(n)) of a number, which counts the integers up to n that are coprime to n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the totient for."}},variants:[{argumentNames:["n"]}],examples:["let { euler-totient } = import(number-theory);\neuler-totient(1)","let { euler-totient } = import(number-theory);\neuler-totient(2)","let { euler-totient } = import(number-theory);\neuler-totient(10)","let { euler-totient } = import(number-theory);\neuler-totient(20)"],seeAlso:["number-theory.coprime?","number-theory.carmichael-lambda","number-theory.mobius","number-theory.prime-factors","number-theory.mertens"]},mobius:{category:"number-theory",description:"Calculates the Möbius function (μ(n)) of a number, which is used in number theory.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the Möbius function for."}},variants:[{argumentNames:["n"]}],examples:["let { mobius } = import(number-theory);\nmobius(1)","let { mobius } = import(number-theory);\nmobius(2)","let { mobius } = import(number-theory);\nmobius(3)","let { mobius } = import(number-theory);\nmobius(4)","let { mobius } = import(number-theory);\nmobius(6)","let { mobius } = import(number-theory);\nmobius(12)","let { mobius } = import(number-theory);\nmobius(30)"],seeAlso:["number-theory.mertens","number-theory.euler-totient","number-theory.prime-factors"]},mertens:{category:"number-theory",description:"Calculates the Mertens function (M(n)) of a number, which is the sum of the Möbius function up to n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the Mertens function for."}},variants:[{argumentNames:["n"]}],examples:["let { mobius } = import(number-theory);\nmobius(1)","let { mobius } = import(number-theory);\nmobius(2)","let { mobius } = import(number-theory);\nmobius(3)","let { mobius } = import(number-theory);\nmobius(4)","let { mobius } = import(number-theory);\nmobius(6)","let { mobius } = import(number-theory);\nmobius(12)","let { mobius } = import(number-theory);\nmobius(30)"],seeAlso:["number-theory.mobius","number-theory.euler-totient"]},sigma:{category:"number-theory",description:"Calculates the sum of divisors function (σ(n)) of a number, which is the sum of all positive divisors of n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the sum of divisors for."}},variants:[{argumentNames:["n"]}],examples:["let { sigma } = import(number-theory);\nsigma(1)","let { sigma } = import(number-theory);\nsigma(2)","let { sigma } = import(number-theory);\nsigma(3)","let { sigma } = import(number-theory);\nsigma(4)","let { sigma } = import(number-theory);\nsigma(6)","let { sigma } = import(number-theory);\nsigma(12)","let { sigma } = import(number-theory);\nsigma(30)"],seeAlso:["number-theory.divisors","number-theory.perfect?","number-theory.abundant?","number-theory.deficient?","number-theory.amicable?","number-theory.count-divisors"]},"carmichael-lambda":{category:"number-theory",description:"Calculates the Carmichael function (λ(n)) of a number, which is the smallest positive integer m such that a^m ≡ 1 (mod n) for all integers a coprime to n.",returns:{type:"integer"},args:{n:{type:"integer",description:"The number to calculate the Carmichael function for."}},variants:[{argumentNames:["n"]}],examples:["let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(1)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(2)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(3)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(4)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(6)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(12)","let { carmichael-lambda } = import(number-theory);\ncarmichael-lambda(30)"],seeAlso:["number-theory.euler-totient","number-theory.mod-exp","number-theory.coprime?"]},"cartesian-product":{category:"number-theory",description:"Calculates the Cartesian product of two or more sets.",returns:{type:"array",array:!0},args:{sets:{type:"array",array:!0,description:"The input collections to calculate the Cartesian product from."},a:{type:"array"},b:{type:"array"}},variants:[{argumentNames:["sets"]}],examples:['let { cartesian-product } = import(number-theory);\ncartesian-product([1, 2], ["a", "b"])','let { cartesian-product } = import(number-theory);\ncartesian-product([1, 2], ["a", "b"], [true, false])','let { cartesian-product } = import(number-theory);\ncartesian-product([1, 2, 3], ["x", "y", "z"])'],seeAlso:["number-theory.combinations","number-theory.power-set","number-theory.permutations"]},"perfect-power":{category:"number-theory",description:"Returns a tuple of the base and exponent if the number is a perfect power, otherwise returns null.",returns:{type:["array","null"]},args:{n:{type:"integer",description:"The number to check."}},variants:[{argumentNames:["n"]}],examples:["let { perfect-power } = import(number-theory);\nperfect-power(1)","let { perfect-power } = import(number-theory);\nperfect-power(2)","let { perfect-power } = import(number-theory);\nperfect-power(4)","let { perfect-power } = import(number-theory);\nperfect-power(8)","let { perfect-power } = import(number-theory);\nperfect-power(9)","let { perfect-power } = import(number-theory);\nperfect-power(16)","let { perfect-power } = import(number-theory);\nperfect-power(19)"],seeAlso:["number-theory.perfect-power?","number-theory.perfect-power-seq","number-theory.perfect-square?","number-theory.perfect-cube?"]},"mod-exp":{category:"number-theory",description:"Calculates the modular exponentiation of a base raised to an exponent modulo a modulus.",returns:{type:"integer"},args:{base:{type:"integer"},exponent:{type:"integer"},modulus:{type:"integer"}},variants:[{argumentNames:["base","exponent","modulus"]}],examples:["let { mod-exp } = import(number-theory);\nmod-exp(2, 3, 5)","let { mod-exp } = import(number-theory);\nmod-exp(3, 4, 7)","let { mod-exp } = import(number-theory);\nmod-exp(5, 6, 11)","let { mod-exp } = import(number-theory);\nmod-exp(7, 8, 13)"],seeAlso:["number-theory.mod-inv","number-theory.carmichael-lambda","number-theory.chinese-remainder"]},"mod-inv":{category:"number-theory",description:"Calculates the modular multiplicative inverse of a number modulo another number.",returns:{type:"integer"},args:{a:{type:"integer"},m:{type:"integer"}},variants:[{argumentNames:["a","m"]}],examples:["let { mod-inv } = import(number-theory);\nmod-inv(3, 11)","let { mod-inv } = import(number-theory);\nmod-inv(10, 17)","let { mod-inv } = import(number-theory);\nmod-inv(5, 13)","let { mod-inv } = import(number-theory);\nmod-inv(7, 19)"],seeAlso:["number-theory.mod-exp","number-theory.extended-gcd","number-theory.chinese-remainder"]},"extended-gcd":{category:"number-theory",description:"Calculates the extended greatest common divisor (GCD) of two numbers, returning the GCD and the coefficients of Bézout's identity.",returns:{type:"integer",array:!0},args:{a:{type:"integer"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { extended-gcd } = import(number-theory);\nextended-gcd(30, 12)","let { extended-gcd } = import(number-theory);\nextended-gcd(56, 98)","let { extended-gcd } = import(number-theory);\nextended-gcd(101, 10)","let { extended-gcd } = import(number-theory);\nextended-gcd(17, 13)"],seeAlso:["number-theory.gcd","number-theory.mod-inv","number-theory.chinese-remainder"]},"chinese-remainder":{category:"number-theory",description:"Solves a system of simultaneous congruences using the Chinese Remainder Theorem.",returns:{type:"integer"},args:{remainders:{type:"integer",array:!0,description:"The remainders of the congruences."},moduli:{type:"integer",array:!0,description:"The moduli of the congruences."},a:{type:"array"},b:{type:"array"}},variants:[{argumentNames:["remainders","moduli"]}],examples:["let { chinese-remainder } = import(number-theory);\nchinese-remainder([2, 3], [3, 5])","let { chinese-remainder } = import(number-theory);\nchinese-remainder([1, 2], [3, 4])","let { chinese-remainder } = import(number-theory);\nchinese-remainder([0, 1], [2, 3])","let { chinese-remainder } = import(number-theory);\nchinese-remainder([1, 2, 3], [4, 5, 7])"],seeAlso:["number-theory.mod-exp","number-theory.mod-inv","number-theory.extended-gcd"]},"stirling-first":{category:"number-theory",description:"Calculates the Stirling numbers of the first kind, which count the number of permutations of n elements with k cycles.",returns:{type:"integer"},args:{a:{type:"integer",description:"The number of elements."},b:{type:"integer",description:"The number of cycles."}},variants:[{argumentNames:["a","b"]}],examples:["let { stirling-first } = import(number-theory);\nstirling-first(5, 2)","let { stirling-first } = import(number-theory);\nstirling-first(4, 3)","let { stirling-first } = import(number-theory);\nstirling-first(6, 1)","let { stirling-first } = import(number-theory);\nstirling-first(7, 4)","let { stirling-first } = import(number-theory);\nstirling-first(8, 5)"],seeAlso:["number-theory.stirling-second","number-theory.bell-seq","number-theory.count-permutations"]},"stirling-second":{category:"number-theory",description:"Calculates the Stirling numbers of the second kind, which count the number of ways to partition n elements into k non-empty subsets.",returns:{type:"integer"},args:{a:{type:"integer",description:"The number of elements."},b:{type:"integer",description:"The number of subsets."}},variants:[{argumentNames:["a","b"]}],examples:["let { stirling-second } = import(number-theory);\nstirling-second(5, 2)","let { stirling-second } = import(number-theory);\nstirling-second(4, 3)","let { stirling-second } = import(number-theory);\nstirling-second(6, 1)","let { stirling-second } = import(number-theory);\nstirling-second(7, 4)","let { stirling-second } = import(number-theory);\nstirling-second(8, 5)"],seeAlso:["number-theory.stirling-first","number-theory.bell-seq","number-theory.count-combinations"]}};function Ei(e,t){if(0===t||t===e)return 1;let r=1;for(let n=0;n<t;n++)r*=(e-n)/(n+1);return r}function Ti(e,t){if(1===t)return e.map(e=>[e]);const r=[];for(let n=0;n<=e.length-t;n++){const o=e[n],a=Ti(e.slice(n+1),t-1);for(const e of a)r.push([o,...e])}return r}const Si={combinations:{evaluate:([e,t],r)=>(ye(e,r),Y(t,r,{integer:!0,nonNegative:!0,lte:e.length}),0===t?[[]]:Ti(e,t)),arity:te(2)},"count-combinations":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0,nonNegative:!0}),Y(t,r,{integer:!0,nonNegative:!0,lte:e}),Ei(e,t)),arity:te(2)}};const zi={derangements:{evaluate:([e],t)=>(ye(e,t),function(e){const t=e.length,r=[],n=Array.from({length:t},()=>!1),o=Array.from({length:t});return function a(i){if(i!==t)for(let r=0;r<t;r++)n[r]||r===i||(n[r]=!0,o[i]=e[r],a(i+1),n[r]=!1);else r.push([...o])}(0),r}(e)),arity:te(1)},"count-derangements":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),function(e){if(1===e)return 0;let t=1,r=0,n=0;for(let o=2;o<=e;o++)n=(o-1)*(t+r),t=r,r=n;return n}(e)),arity:te(1)}};function ji(e){const t=[];for(let r=1;r<=Math.sqrt(e);r++)e%r===0&&(t.push(r),r!==e/r&&t.push(e/r));return t}function Ci(e){return ji(e).sort((e,t)=>e-t)}function Ii(e){return Ci(e).slice(0,-1)}const Ri={divisors:{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),Ci(e)),arity:te(1)},"count-divisors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),ji(e).length),arity:te(1)},"proper-divisors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),Ii(e)),arity:te(1)},"count-proper-divisors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),ji(e).length-1),arity:te(1)}},Pi=[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368e3,20922789888e3,355687428096e3,6402373705728e3];function Mi(e){if(e<0)throw new Error("Factorial is not defined for negative numbers");if(0===e||1===e)return 1;if(e<=18)return Pi[e];let t=Pi[18];for(let r=19;r<=e;r++)t*=r;return t}const Oi={factorial:{evaluate:([e],t)=>(Y(e,t,{integer:!0,nonNegative:!0,lte:170}),Mi(e)),arity:te(1)}},Vi=[1,2,3,5,7,11,15,22,30,42,56,77,101,135,176,231,297,385,490,627,792,1002,1255,1575,1958,2436,3010,3718,4565,5604,6842,8349,10143,12310,14883,17977,21637,26015,31185,37338,44583,53174,63261,75175,89134,105558,124754,147273,173525,204226,239943,281589,329931,386155,451276,526823,614154,715220,831820,966467,1121505,1300156,1505499,1741630,2012558,2323520,2679689,3087735,3554345,4087968,4697205,5392783,6185689,7089500,8118264,9289091,10619863,12132164,13848650,15796476,18004327,20506255,23338469,26543660,30167357,34262962,38887673,44108109,49995925,56634173,64112359,72533807,82010177,92669720,104651419,118114304,133230930,150198136,169229875,190569292,214481126,241265379,271248950,304801365,342325709,384276336,431149389,483502844,541946240,607163746,679903203,761002156,851376628,952050665,1064144451,1188908248,1327710076,1482074143,1653668665,1844349560,2056148051,2291320912,2552338241,2841940500,3163127352,3519222692,3913864295,4351078600,4835271870,5371315400,5964539504,6620830889,7346629512,8149040695,9035836076,10015581680,11097645016,12292341831,13610949895,15065878135,16670689208,18440293320,20390982757,22540654445,24908858009,27517052599,30388671978,33549419497,37027355200,40853235313,45060624582,49686288421,54770336324,60356673280,66493182097,73232243759,80630964769,88751778802,97662728555,107438159466,118159068427,129913904637,142798995930,156919475295,172389800255,189334822579,207890420102,228204732751,250438925115,274768617130,301384802048,330495499613,362326859895,397125074750,435157697830,476715857290,522115831195,571701605655,625846753120,684957390936,749474411781,819876908323,896684817527,980462880430,0xf98dace281,1171432692373,1280011042268,1398341745571,1527273599625,1667727404093,1820701100652,1987276856363,2168627105469,2366022741845,2580840212973,2814570987591,3068829878530,3345365983698,3646072432125,3972999029388,4328363658647,4714566886083,5134205287973,5590088317495,6085253859260,6622987708040,7206841706490,7840656226137,8528581302375,9275102575355,0x92c1cc50847,0x9f8afdf968b,0xad6918d4f36,0xbc72dde1287,0xccc0de0d1d7,0xde6da02b061,0xf195c5ba10a,18028182516671,19573856161145,21248279009367,23061871173849,25025873760111,27152408925615,29454549941750,31946390696157,34643126322519,37561133582570,40718063627362,44132934884255,47826239745920,51820051838712,56138148670947,60806135438329,65851585970275,71304185514919,77195892663512,83561103925871,90436839668817,97862933703585,0x604ca1b434ad,0x682ca0bc6d4e,0x70ad06a4328b,0x79da3e8e4df8,0x83c1a359c63d,0x8e7190d8114a,0x99f976fff202,0xa669edb53a4a,0xb3d4caca1bc8,0xc24d38b78151,0xd1e7cfd30909,0xe2bab064772f,0xf4dd9f8523e3,290726957916112,313891991306665,338854264248680,365749566870782,394723676655357,425933084409356,459545750448675,495741934760846,534715062908609,576672674947168,621837416509615,670448123060170,722760953690372,779050629562167,839611730366814,904760108316360,974834369944625,0x3bb262854d36d,0x404dafd2efa2e,0x4541ae2536f6d,0x4a94ddd83ba57,0x504e363fd1eca,0x56752ddfc97e7,0x5d11c356f6b53,0x642c86bff69f5,0x6bcea3db036a0,0x7401ecbfdbd63,0x7cd0e571c49d4,0x8646d010a1b6f,0x906fba0855202,0x9b5889f52508f,0xa70f0ea631153,0xb3a20ef033ec5,0xc1215ac210755,0xcf9ddd28cfa8d,0xdf29afbd9f60e,0xefd82f26a7157,4534253126900886,4872038056472084,5234371069753672,5622992691950605,6039763882095515,6486674127079088,6965850144195831,7479565078510584,8030248384943040,8620496275465025];const Di={partitions:{evaluate:([e],t)=>(Y(e,t,{integer:!0,nonNegative:!0}),function(e){if(e<=0)return[[]];if(1===e)return[[1]];const t=[];return function e(r,n,o){if(0!==r)for(let t=Math.min(n,r);t>=1;t--)o.push(t),e(r-t,t,o),o.pop();else t.push([...o])}(e,e,[]),t}(e)),arity:te(1)},"count-partitions":{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,nonNegative:!0}),0===e)return 1;if(e>Vi.length)throw new o(`n is too large. The maximum value is ${Vi.length-1}.`,t);return Vi[e-1]},arity:te(1)}};function Ui(e){if(0===e.length)return[[]];const t=[];for(let r=0;r<e.length;r++){const n=e[r],o=Ui([...e.slice(0,r),...e.slice(r+1)]);for(const e of o)t.push([n,...e])}return t}const Fi={permutations:{evaluate:([e],t)=>(ye(e,t),Ui(e)),arity:te(1)},"count-permutations":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0,nonNegative:!0}),Y(t,r,{integer:!0,nonNegative:!0,lte:e}),Mi(e)/Mi(e-t)),arity:te(2)}};const Wi={"power-set":{evaluate:([e],t)=>(ye(e,t),function(e){const t=[[]];for(const r of e){const e=t.map(e=>[...e,r]);t.push(...e)}return t}(e)),arity:te(1)},"count-power-set":{evaluate:([e],t)=>(Y(e,t,{integer:!0,nonNegative:!0}),e>=53?1/0:2**e),arity:te(1)}};function Gi(e){if(1===e)return[];const t=[];let r=2;for(;e>1;)e%r===0?(t.push(r),e/=r):r++;return t}const Bi={"prime-factors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),Gi(e)),arity:te(1)},"distinct-prime-factors":{evaluate:([e],t)=>{Y(e,t,{finite:!0,integer:!0,positive:!0});const r=Gi(e),n=new Set(r);return Array.from(n)},arity:te(1)},"count-prime-factors":{evaluate:([e],t)=>(Y(e,t,{finite:!0,integer:!0,positive:!0}),Gi(e).length),arity:te(1)},"count-distinct-prime-factors":{evaluate:([e],t)=>{Y(e,t,{finite:!0,integer:!0,positive:!0});const r=Gi(e);return new Set(r).size},arity:te(1)}};function Li(e){return Ii(e).reduce((e,t)=>e+t,0)>e}const _i={"abundant-seq":e=>{const t=[];let r=2;for(;t.length<e;)Li(r)&&t.push(r),r+=1;return t},"abundant?":e=>Li(e),"abundant-take-while":e=>{const t=[];return function r(n){return Li(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(2)}};const Ki={"arithmetic-seq":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),Array.from({length:r},(r,n)=>e+n*t)),arity:te(3)},"arithmetic-take-while":{evaluate:([e,t,r],n,o,{executeFunction:a})=>{Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),F(r,n);const i=e,s=t,l=r,c=[];return function e(t){const r=i+t*s;return ft(a(l,[r,t],o,n),n=>n?(c.push(r),e(t+1)):c)}(0)},arity:te(3)},"arithmetic-nth":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),e+(r-1)*t),arity:te(3)},"arithmetic?":{evaluate:([e,t,r],n)=>(Y(r,n),Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),function(e,t,r){if(0===t)return he(r,e);const n=(r-e)/t;if(n<0)return!1;const o=Math.round(n),a=e+t*o;return he(n,o)&&he(a,r)}(e,t,r)),arity:te(3)}};function Ji(e){const t=[1];for(let r=1;r<e;r+=1){let e=0;for(let n=0;n<r;n+=1)e+=Ei(r+1,n)*t[n];t[r]=r>1&&r%2==1?0:-e/(r+1)}return t}const Hi={"bernoulli-seq":{evaluate:([e],t)=>(Y(e,t,{integer:!0,positive:!0}),Ji(e)),arity:te(1)},"bernoulli-nth":{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});return Ji(e)[e-1]},arity:te(1)},"bernoulli-take-while":{evaluate:([e],t,r,{executeFunction:n})=>{F(e,t);const o=e;return function(e){const t=[1];return function r(n){let o=0;for(let e=0;e<n;e++)o+=Ei(n+1,e)*t[e];const a=n>1&&n%2==1?0:-o/(n+1);return ft(e(a,n),e=>e?(t.push(a),r(n+1)):t)}(1)}((e,t)=>ft(n(o,[e,t],r),e=>!!e))},arity:te(1)}};function Yi(e){if(e<=1)return!1;if(e<=3)return!0;if(e%2==0||e%3==0)return!1;for(let t=5;t*t<=e;t+=6)if(e%t===0||e%(t+2)===0)return!1;return!0}const Xi={"prime-seq":e=>{const t=[];let r=2;for(;t.length<e;)Yi(r)&&t.push(r),r+=1;return t},"prime?":e=>Yi(e),"prime-take-while":e=>{const t=[];return function r(n){return Yi(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(2)}};function Qi(e){return!(e<=1)&&!Yi(e)}const Zi={"composite-seq":e=>{const t=[];let r=2;for(;t.length<e;)Qi(r)&&t.push(r),r+=1;return t},"composite?":e=>Qi(e),"composite-take-while":e=>{const t=[];return function r(n){return Qi(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(4)}};function es(e){return Ii(e).reduce((e,t)=>e+t,0)<e}const ts={"deficient-seq":e=>{const t=[];let r=1;for(;t.length<e;)es(r)&&t.push(r),r+=1;return t},"deficient?":e=>es(e),"deficient-take-while":e=>{const t=[];return function r(n){return es(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(1)}};const rs={"geometric-seq":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),Array.from({length:r},(r,n)=>e*t**n)),arity:te(3)},"geometric-take-while":{evaluate:([e,t,r],n,o,{executeFunction:a})=>{Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),F(r,n);const i=e,s=t,l=r,c=[];return function e(t){const r=i*s**t;return ft(a(l,[r,t],o,n),n=>n?(c.push(r),e(t+1)):c)}(0)},arity:te(3)},"geometric-nth":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),Y(r,n,{integer:!0,positive:!0}),e*t**(r-1)),arity:te(3)},"geometric?":{evaluate:([e,t,r],n)=>(Y(r,n),Y(e,n,{finite:!0}),Y(t,n,{finite:!0}),function(e,t,r){if(he(e,0))return he(r,0);if(he(t,1))return he(r,e);if(he(t,0))return he(r,0)||he(r,e);if(he(r,e))return!0;if(he(t,-1))return he(r,e)||he(r,-e);if(t<0){const n=Math.log(Math.abs(r/e))/Math.log(Math.abs(t)),o=Math.round(n);if(!he(o,n)||o<0)return!1;const a=o%2==0?Math.sign(e):Math.sign(e)*Math.sign(t);return Math.sign(r)===a}if(t>1&&r<e||t<1&&r>e)return!1;const n=Math.log(r/e)/Math.log(t),o=Math.round(n);return!(!he(o,n)||o<0)&&he(e*t**o,r)}(e,t,r)),arity:te(3)}};const ns={"golomb-seq":e=>function(e){const t=[0,1];for(let r=2;r<=e;r+=1)t.push(1+t[r-t[t[r-1]]]);return t.slice(1)}(e),"golomb?":()=>!0,"golomb-take-while":e=>function(e){const t=[0,1];return ft(e(1,0),r=>r?function r(n){const o=1+t[n-t[t[n-1]]];return ft(e(o,n-1),e=>e?(t.push(o),r(n+1)):t.slice(1))}(2):[])}(e)};function os(e){if(e<=0)return!1;const t=new Set;for(;1!==e&&!t.has(e);)t.add(e),e=as(e);return 1===e}function as(e){let t=0;for(;e>0;){const r=e%10;t+=r*r,e=Math.floor(e/10)}return t}const is={"happy-seq":e=>{const t=[];for(let r=1;t.length<e;r++){let e=r;const n=new Set;for(;1!==e&&!n.has(e);)n.add(e),e=String(e).split("").reduce((e,t)=>e+Number(t)**2,0);1===e&&t.push(r)}return t},"happy?":e=>os(e),"happy-take-while":e=>{const t=[];return function r(n){return os(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(1)}},ss={"juggler-seq":e=>{let t=e;const r=[t];for(;t>1;)t=t%2==0?Math.floor(Math.sqrt(t)):Math.floor(t**1.5),r.push(t);return r},noNth:!0};function ls(e){let t="",r=1;for(let n=0;n<e.length;n++)n+1<e.length&&e[n]===e[n+1]?r++:(t+=r.toString()+e[n],r=1);return t}const cs={string:!0,"look-and-say-seq":e=>{const t=["1"];for(let r=1;r<e;r+=1){const e=t[r-1].replace(/(\d)\1*/g,e=>`${e.length}${e[0]}`);t[r]=e}return t},"look-and-say-take-while":e=>{const t=[];return ft(e("1",0),r=>{if(!r)return t;return t.push("1"),function r(n){const o=t[n-1].replace(/(\d)\1*/g,e=>`${e.length}${e[0]}`);return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(1)})},"look-and-say?":e=>function(e){let t="1";if(t===e)return!0;for(;;){if(t=ls(t),t===e)return!0;if(t.length>e.length)return!1}}(e)};function us(e){const t=[];for(let e=1;e<=2e3;e++)t.push(e);let r=[1];for(let e=1;e<t.length;e++)t[e]%2!=0&&r.push(t[e]);const n=[1];let o=1;return ft(e(1,0),t=>{if(!t)return[];let a=1;return function t(){const i=r[a];return ft(e(i,o),e=>{if(!e)return n;n.push(i),o++;const s=i,l=[];for(let e=0;e<r.length;e++)(e+1)%s!==0&&l.push(r[e]);if(r=l,a++,a>=r.length-5){let e=r[r.length-1]+2;for(;r.length<a+1e3;)r.push(e),e+=2}return t()})}()})}const ms={"lucky-seq":e=>function(e){const t=[];let r=1;const n=e*(e<100?20:30);for(;t.length<n;)t.push(r),r+=2;let o=1;for(;o<t.length&&o<e;){const e=t[o];let r=0;for(let n=0;n<t.length;n++)(n+1)%e!==0&&(t[r++]=t[n]);t.length=r,o<t.length&&o++}return t.slice(0,e)}(e),"lucky?":e=>us(t=>t<=e).includes(e),"lucky-take-while":e=>us(e)};const ps={"padovan-seq":e=>{const t=[1,1,1];for(let r=3;r<e;r+=1)t[r]=t[r-2]+t[r-3];return t.slice(0,e)},"padovan?":e=>function(e){if(!Number.isInteger(e)||e<=0)return!1;if(1===e)return!0;const t=[1,1,1,2,2,3,4,5,7,9,12,16,21,28,37,49,65,86,114,151,200,265,351,465,616,816,1081,1432,1897,2513,3329,4410,5842,7739,10252,13581,17991,23833,31572,41824,55405,73396,97229];if(t.includes(e))return!0;if(e>t[t.length-1]&&e<=Number.MAX_SAFE_INTEGER){let r,n=t[t.length-3],o=t[t.length-2],a=t[t.length-1];for(;a<e;){if(r=n+o,n=o,o=a,a=r,a===e)return!0;if(!Number.isSafeInteger(a))return!1}}return!1}(e),"padovan-take-while":e=>{const t=[];return ft(e(1,0),r=>r?(t.push(1),ft(e(1,1),r=>r?(t.push(1),ft(e(1,2),r=>{if(!r)return t;t.push(1);let n=1,o=1,a=1;return function r(i){const s=n+o;return n=o,o=a,a=s,ft(e(a,i),e=>e?(t.push(a),r(i+1)):t)}(4)})):t)):t)}},ds={"perfect-cube-seq":e=>{const t=[];for(let r=1;r<=e;r++)t.push(r**3);return t},"perfect-cube?":e=>e>0&&Number.isInteger(Math.cbrt(e)),"perfect-cube-take-while":e=>{const t=[];return function r(n){const o=n**3;return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(1)}};function hs(e){if(e<2)return 1===e?[1,2]:null;const t=Math.floor(Math.log2(e))+1;for(let r=2;r<=t;r++){const t=e**(1/r),n=Math.round(t);if(he(n**r,e))return[n,r]}return null}const gs={"perfect-power-seq":e=>{const t=[];for(let r=1;t.length<e;r++)hs(r)&&t.push(r);return t},"perfect-power?":e=>null!==hs(e),"perfect-power-take-while":e=>{const t=[];return function r(n){return hs(n)?ft(e(n,t.length),e=>e?(t.push(n),r(n+1)):t):r(n+1)}(1)}},fs={"perfect-square-seq":e=>{const t=[];for(let r=1;r<=e;r++)t.push(r**2);return t},"perfect-square?":e=>e>0&&Number.isInteger(Math.sqrt(e)),"perfect-square-take-while":e=>{const t=[];return function r(n){const o=n**2;return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(1)}},ys={"polygonal-seq":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,gte:3}),Y(t,r,{integer:!0,positive:!0});const n=[];for(let r=1;r<=t;r+=1)n[r-1]=(r*r*(e-2)-r*(e-4))/2;return n},arity:te(2)},"polygonal-take-while":{evaluate:([e,t],r,n,{executeFunction:o})=>{Y(e,r,{integer:!0,gte:3}),F(t,r);const a=e,i=t,s=[];return function e(t){const l=(t*t*(a-2)-t*(a-4))/2;return ft(o(i,[l,t],n,r),r=>r?(s.push(l),e(t+1)):s)}(1)},arity:te(2)},"polygonal-nth":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0,gte:3}),Y(t,r,{integer:!0,positive:!0}),(t*t*(e-2)-t*(e-4))/2),arity:te(2)},"polygonal?":{evaluate:([e,t],r)=>{if(Y(t,r,{integer:!0}),Y(e,r,{integer:!0,gte:3}),t<=0)return!1;const n=e-2,o=e-4,a=8*n*t+o*o,i=Math.sqrt(a);if(!Number.isInteger(i))return!1;const s=i+o;if(s%(2*n)!=0)return!1;const l=s/(2*n);return Number.isInteger(l)&&l>0},arity:te(2)}};const vs={"recaman-seq":e=>function(e){if(1===e)return[0];const t=[0],r=new Set([0]);for(let n=1;n<e;n++){let e=t[n-1]-n;(e<=0||r.has(e))&&(e=t[n-1]+n),t.push(e),r.add(e)}return t}(e),"recaman-take-while":e=>{const t=[],r=new Set([0]);return ft(e(0,0),n=>{if(!n)return t;return t.push(0),function n(o){let a=t[o-1]-o;return(a<=0||r.has(a))&&(a=t[o-1]+o),ft(e(a,o),e=>e?(t.push(a),r.add(a),n(o+1)):t)}(1)})},"recaman?":()=>!0},bs={"thue-morse-seq":e=>{const t=[];for(let r=0;r<e;r+=1)t[r]=ws(r)%2;return t},"thue-morse-take-while":e=>{const t=[];return function r(n){const o=ws(n)%2;return ft(e(o,n),e=>e?(t.push(o),r(n+1)):t)}(0)},"thue-morse?":e=>1===e||0===e};function ws(e){let t=0;for(;e;)t+=1&e,e>>=1;return t}const xs={};function ks(e){for(const[t,r]of Object.entries(e)){if(xs[t])throw new Error(`Duplicate normal expression key found: ${t}`);xs[t]=r}}function qs(e,t){return{[`${e}-seq`]:Ns(e=>t.slice(0,e),t.length),[`${e}-take-while`]:$s(e=>function r(n){return n>=t.length?t.slice(0,n):ft(e(t[n],n),e=>e?r(n+1):t.slice(0,n))}(0),t.length),[`${e}-nth`]:Es(()=>t,t.length),[`${e}?`]:Ts(e=>t.includes(e))}}function As(e){for(const[t,r]of Object.entries(e)){if(xs[t])throw new Error(`Duplicate normal expression key found: ${t}`);t.endsWith("seq")?(xs[t]=Ns(r,e.maxLength),e.noNth||(xs[t.replace(/seq$/,"nth")]=Es(r,e.maxLength))):t.endsWith("take-while")?xs[t]=$s(r,e.maxLength):t.endsWith("?")&&(e.string?xs[t]=Ss(r):xs[t]=Ts(r))}}function Ns(e,t){return{evaluate:(r,n)=>{const a=r[0]??t;Y(a,n,{integer:!0,positive:!0,lte:t});const i=e(a,n);if("number"==typeof i[0]&&i.some(e=>e>Number.MAX_SAFE_INTEGER))throw new o("Result exceeds maximum safe integer",n);return i},arity:"number"==typeof t?{max:1}:te(1)}}function $s(e,t){return{evaluate:(t,r,n,{executeFunction:a})=>{const i=t[0];F(i,r);const s=e((e,t)=>ft(a(i,[e,t],n),e=>!!e),r);return ft(s,e=>{if("number"==typeof e[0]&&e.some(e=>e>Number.MAX_SAFE_INTEGER))throw new o("Result exceeds maximum safe integer",r);return e})},arity:"number"==typeof t?{max:1}:te(1)}}function Es(e,t){return{evaluate:(r,n)=>{const a=r[0];Y(a,n,{integer:!0,positive:!0,lte:t});const i=e(a,n);if("number"==typeof i[0]&&i.some(e=>e>Number.MAX_SAFE_INTEGER))throw new o("Result exceeds maximum safe integer",n);return i[a-1]},arity:te(1)}}function Ts(e){return{evaluate:(t,r)=>{const n=t[0];return Y(n,r),e(n,r)},arity:te(1)}}function Ss(e){return{evaluate:(t,r)=>{const n=t[0];return G(n,r),e(n,r)},arity:te(1)}}function zs(e,t){for(;0!==t;){const r=t;t=e%t,e=r}return Math.abs(e)}function js(e,t){return Math.floor(e*t/zs(e,t))}function Cs(e){if(1===e)return 1;const t=Gi(e);return new Set(t).size!==t.length?0:t.length%2==0?1:-1}function Is(e,t){if(0===t)return[e,1,0];const[r,n,o]=Is(t,e%t);return[r,o,n-Math.floor(e/t)*o]}function Rs(e,t){const[r,n]=Is(e,t);if(1!==r)throw new Error(`Modular inverse does not exist (gcd(${e}, ${t}) = ${r})`);return(n%t+t)%t}As(_i),As({"collatz-seq":e=>{let t=e;const r=[t];for(;1!==t;)t%2==0?t/=2:t=3*t+1,r.push(t);return r},noNth:!0}),As(Zi),As(ts),As(ns),As(is),As(ss),As(cs),As(ms),As(ps),As(fs),As(ds),As(gs),As(Xi),As(vs),As(bs),ks(qs("tribonacci",[0,1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136,5768,10609,19513,35890,66012,121415,223317,410744,755476,1389537,2555757,4700770,8646064,15902591,29249425,53798080,98950096,181997601,334745777,615693474,1132436852,2082876103,3831006429,7046319384,12960201916,23837527729,43844049029,80641778674,148323355432,272809183135,501774317241,922906855808,1697490356184,3122171529233,5742568741225,0x99b36012952,19426970897100,35731770264967,65720971788709,0x6df08059d9f8,0xca35cf00a924,408933139743937,752145307699165,0x4ea34736b35c2,0x90a3317d5c260,4680045560037375,8607945812375585])),ks(qs("catalan",[1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790,477638700,1767263190,6564120420,24466267020,91482563640,343059613650,1289904147324,4861946401452,18367353072152,69533550916004,0xefe09af96cd8,0x38f88b34d6a68,0xd8db5c347b610])),ks(qs("factorial",Pi)),ks(qs("fibonacci",[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,0x9a661ca20bb,0xf9d297a859d,27777890035288,44945570212853,72723460248141,0x6b04f4c2fe42,0xad2934c6d08f,308061521170129,498454011879264,806515533049393,0x4a2dce62b0d91,0x780626e057bc2,0xc233f54308953,5527939700884757,8944394323791464])),ks(qs("lucas",[2,1,3,4,7,11,18,29,47,76,123,199,322,521,843,1364,2207,3571,5778,9349,15127,24476,39603,64079,103682,167761,271443,439204,710647,1149851,1860498,3010349,4870847,7881196,12752043,20633239,33385282,54018521,87403803,141422324,228826127,370248451,599074578,969323029,1568397607,2537720636,4106118243,6643838879,10749957122,17393796001,28143753123,45537549124,73681302247,119218851371,192900153618,312119004989,505019158607,817138163596,1322157322203,2139295485799,3461452808002,5600748293801,9062201101803,0xd55fbe3dc94,23725150497407,38388099893011,62113250390418,0x5b67cb4878a5,0x93e5a9822a37,0xef4d74caa2dc,425730551631123,688846502588399,0x3f5b3b1643d02,0x66834447bacf1,0xa5de7f5dfe9f3,4721424167835364,7639424778862807])),ks(qs("mersenne",[3,7,31,127,2047,8191,131071,524287,2147483647])),ks(qs("partition",Vi)),ks(qs("pell",[1,2,5,12,29,70,169,408,985,2378,5741,13860,33461,80782,195025,470832,1136689,2744210,6625109,15994428,38613965,93222358,225058681,543339720,1311738121,3166815962,7645370045,18457556052,44560482149,107578520350,259717522849,627013566048,1513744654945,3654502875938,8822750406821,21300003689580,51422757785981,0x70e8e1937766,299713796309065,723573111879672,0x634c28af7f039,0xefb9b143d586a])),ks(qs("perfect",[6,28,496,8128,33550336,8589869056,137438691328])),ks(qs("sylvester",[2,6,42,1806,3263442,0x9afa8dc8416])),ks(qs("bell",[1,2,5,15,52,203,877,4140,21147,115975,678570,4213597,27644437,190899322,1382958545,10480142147,82864869804,682076806159,5832742205057,51724158235372,474869816156751,4506715738447323])),ks(Ki),ks(Hi),ks(rs),ks(ys);const Ps={"coprime?":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0}),1===zs(e,t)),arity:te(2)},"divisible-by?":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0}),0!==t&&e%t===0),arity:te(2)},gcd:{evaluate:([e,t],r)=>(Y(e,r),Y(t,r),zs(e,t)),arity:te(2)},lcm:{evaluate:([e,t],r)=>(Y(e,r),Y(t,r),js(e,t)),arity:te(2)},multinomial:{evaluate:([...e],t)=>{Ce(e,t);return Mi(e.reduce((e,r)=>(Y(r,t,{integer:!0,nonNegative:!0}),e+r),0))/e.reduce((e,t)=>e*Mi(t),1)},arity:{min:1}},"amicable?":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0});const n=Ii(e).reduce((e,t)=>e+t,0),o=Ii(t).reduce((e,t)=>e+t,0);return n===t&&o===e&&e!==t},arity:te(2)},"euler-totient":{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});let r=e;for(let t=2;t*t<=e;t+=1)if(e%t===0){for(;e%t===0;)e/=t;r-=r/t}return e>1&&(r-=r/e),r},arity:te(1)},mobius:{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,positive:!0}),1===e)return 1;const r=Gi(e);return new Set(r).size!==r.length?0:r.length%2==0?1:-1},arity:te(1)},mertens:{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,positive:!0}),1===e)return 1;let r=0;for(let t=1;t<=e;t++){r+=Cs(t)}return r},arity:te(1)},sigma:{evaluate:([e],t)=>(Y(e,t,{integer:!0,positive:!0}),Ci(e).reduce((e,t)=>e+t,0)),arity:te(1)},"carmichael-lambda":{evaluate:([e],t)=>{if(Y(e,t,{integer:!0,positive:!0}),1===e)return 1;const r=Gi(e),n=new Map;for(const e of r)n.set(e,(n.get(e)||0)+1);const o=[];for(const[e,t]of n.entries())2===e?1===t?o.push(1):2===t?o.push(2):o.push(2**(t-2)):o.push((e-1)*e**(t-1));return o.reduce((e,t)=>js(e,t),1)},arity:te(1)},"cartesian-product":{evaluate:(e,t)=>{e.forEach(e=>{ye(e,t)});return e.reduce((e,t)=>{const r=[];return e.forEach(e=>{t.forEach(t=>{r.push([...e,t])})}),r},[[]])},arity:{min:1}},"perfect-power":{evaluate:([e],t)=>{Y(e,t,{integer:!0,positive:!0});return hs(e)||null},arity:te(1)},"mod-exp":{evaluate:([e,t,r],n)=>(Y(e,n,{finite:!0}),Y(t,n,{integer:!0,positive:!0}),Y(r,n,{integer:!0,positive:!0}),function(e,t,r){if(1===r)return 0;let n=1;for(e%=r;t>0;)t%2==1&&(n=n*e%r),t>>=1,e=e*e%r;return n}(e,t,r)),arity:te(3)},"mod-inv":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0});try{return Rs(e,t)}catch(e){throw new o(e,r)}},arity:te(2)},"extended-gcd":{evaluate:([e,t],r)=>(Y(e,r,{integer:!0}),Y(t,r,{integer:!0}),Is(e,t)),arity:te(2)},"chinese-remainder":{evaluate:([e,t],r)=>{if(Ce(e,r),Ce(t,r),e.length!==t.length)throw new o("Remainders and moduli must have the same length.",r);try{return function(e,t){for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++){const n=Is(t[e],t[r])[0];if(1!==n)throw new Error(`Moduli must be pairwise coprime, but gcd(${t[e]}, ${t[r]}) = ${n}`)}const r=t.reduce((e,t)=>e*t,1);let n=0;for(let o=0;o<e.length;o++){const a=e[o],i=t[o],s=r/i;n=(n+a*s*Rs(s,i))%r}return n}(e,t)}catch(e){throw new o(e.message,r)}},arity:te(2)},"stirling-first":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0,lte:e});const n=Array.from({length:e+1},()=>Array(t+1).fill(0));n[0][0]=1;for(let r=1;r<=e;r++)for(let e=1;e<=Math.min(r,t);e++)n[r][e]=n[r-1][e-1]+(r-1)*n[r-1][e];return n[e][t]},arity:te(2)},"stirling-second":{evaluate:([e,t],r)=>{if(Y(e,r,{integer:!0,positive:!0}),Y(t,r,{integer:!0,positive:!0,lte:e}),1===t)return 1;if(t===e)return 1;const n=Array.from({length:e+1},()=>Array(t+1).fill(0));n[0][0]=1;for(let r=1;r<=e;r++)for(let e=1;e<=Math.min(r,t);e++)n[r][e]=e*n[r-1][e]+n[r-1][e-1];return n[e][t]},arity:te(2)}};function Ms(e){for(const[t,r]of Object.entries(e)){if(Ps[t])throw new Error(`Duplicate normal expression key found: ${t}`);Ps[t]=r}}!function(e){for(const[t,r]of Object.entries(e)){if(Ps[t])throw new Error(`Duplicate normal expression key found: ${t}`);Ps[t]=r}}(xs),Ms(Oi),Ms(Ri),Ms(Si),Ms(Fi),Ms(Di),Ms(Bi),Ms(zi),Ms(Wi);for(const[e,t]of Object.entries($i))Ps[e]&&(Ps[e].docs=t);const Os={name:"number-theory",functions:Ps,source:"{}",docs:$i};function Vs(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{if(!t.docs)throw new Error(`Missing docs for function "${e}"`);return[e,t.docs]}))}function Ds(e){return([t],r)=>{const[n,a]=function(e,t){if(je(e))return["vector",e];if(Ve(e))return["matrix",e];if(!H(e))throw new o("Invalid parameter type: "+typeof e,t);return["number",e]}(t,r);return"number"===n?e(a):"vector"===n?a.map(t=>e(t)):a.map(t=>t.map(t=>e(t)))}}const Us={sin:{evaluate:Ds(e=>Math.sin(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sin` function computes the sine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the sine of each element while preserving the original structure.",seeAlso:["math.asin","math.sinh","math.cos","math.tan","math.to-rad"],examples:["let { sin } = import(math);\nsin(0)","let { sin } = import(math);\nsin(1)","let { sin } = import(math);\nsin(PI)","let { sin } = import(math);\nsin(-0.5)","let { sin } = import(math);\nsin([1, 2, 3])","let { sin } = import(math);\nsin([[1, 2], [3, 4]])"]}},asin:{evaluate:Ds(e=>Math.asin(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `asin` function computes the arcsine (inverse sine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arcsine of each element while preserving the original structure.",seeAlso:["math.sin","math.asinh","math.acos","math.atan"],examples:["let { asin } = import(math);\nasin(0)","let { asin } = import(math);\nasin(1)","let { asin } = import(math);\nasin(-0.5)","let { asin } = import(math);\nasin([1, 2, 3])","let { asin } = import(math);\nasin([[1, 2], [3, 4]])"]}},sinh:{evaluate:Ds(e=>Math.sinh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sinh` function computes the hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic sine of each element while preserving the original structure.",seeAlso:["math.asinh","math.sin","math.cosh","math.tanh"],examples:["let { sinh } = import(math);\nsinh(0)","let { sinh } = import(math);\nsinh(1)","let { sinh } = import(math);\nsinh(-0.5)","let { sinh } = import(math);\nsinh([0.1, 0.2, 0.3])","let { sinh } = import(math);\nsinh([[0.1, 0.2], [0.3, 0.4]])"]}},asinh:{evaluate:Ds(e=>Math.asinh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `asinh` function computes the inverse hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic sine of each element while preserving the original structure.",seeAlso:["math.sinh","math.asin","math.acosh","math.atanh"],examples:["let { asinh } = import(math);\nasinh(10)","let { asinh } = import(math);\nasinh(90)","let { asinh } = import(math);\nasinh(50)","let { asinh } = import(math);\nasinh([10, 20, 30])","let { asinh } = import(math);\nasinh([[10, 20], [30, 40]])"]}},cos:{evaluate:Ds(e=>Math.cos(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cos` function computes the cosine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the cosine of each element while preserving the original structure.",seeAlso:["math.acos","math.cosh","math.sin","math.tan","math.to-rad"],examples:["let { cos } = import(math);\ncos(0)","let { cos } = import(math);\ncos(1)","let { cos } = import(math);\ncos(PI)","let { cos } = import(math);\ncos(-0.5)","let { cos } = import(math);\ncos([1, 2, 3])","let { cos } = import(math);\ncos([[1, 2], [3, 4]])"]}},acos:{evaluate:Ds(e=>Math.acos(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `acos` function computes the arccosine (inverse cosine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arccosine of each element while preserving the original structure.",seeAlso:["math.cos","math.acosh","math.asin","math.atan"],examples:["let { acos } = import(math);\nacos(0)","let { acos } = import(math);\nacos(1)","let { acos } = import(math);\nacos(-0.5)","let { acos } = import(math);\nacos([0.1, 0.2, 0.3])","let { acos } = import(math);\nacos([[0.1, 0.2], [0.3, 0.4]])"]}},cosh:{evaluate:Ds(e=>Math.cosh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cosh` function computes the hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic cosine of each element while preserving the original structure.",seeAlso:["math.acosh","math.cos","math.sinh","math.tanh"],examples:["let { cosh } = import(math);\ncosh(0)","let { cosh } = import(math);\ncosh(1)","let { cosh } = import(math);\ncosh(-0.5)","let { cosh } = import(math);\ncosh([0.1, 0.2, 0.3])","let { cosh } = import(math);\ncosh([[0.1, 0.2], [0.3, 0.4]])"]}},acosh:{evaluate:Ds(e=>Math.acosh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `acosh` function computes the inverse hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic cosine of each element while preserving the original structure.",seeAlso:["math.cosh","math.acos","math.asinh","math.atanh"],examples:["let { acosh } = import(math);\nacosh(1)","let { acosh } = import(math);\nacosh(2)","let { acosh } = import(math);\nacosh(100)","let { acosh } = import(math);\nacosh(50)","let { acosh } = import(math);\nacosh([1, 2, 3])","let { acosh } = import(math);\nacosh([[1, 2], [3, 4]])"]}},tan:{evaluate:Ds(e=>Math.tan(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `tan` function computes the tangent of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the tangent of each element while preserving the original structure.",seeAlso:["math.atan","math.tanh","math.sin","math.cos","math.to-rad"],examples:["let { tan } = import(math);\ntan(0)","let { tan } = import(math);\ntan(1)","let { tan } = import(math);\ntan(PI)","let { tan } = import(math);\ntan(-0.5)","let { tan } = import(math);\ntan([1, 2, 3])","let { tan } = import(math);\ntan([[1, 2], [3, 4]])"]}},atan:{evaluate:Ds(e=>Math.atan(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `atan` function computes the arctangent (inverse tangent) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arctangent of each element while preserving the original structure.",seeAlso:["math.tan","math.atanh","math.asin","math.acos"],examples:["let { atan } = import(math);\natan(0)","let { atan } = import(math);\natan(1)","let { atan } = import(math);\natan(-0.5)","let { atan } = import(math);\natan([0.1, 0.2, 0.3])","let { atan } = import(math);\natan([[0.1, 0.2], [0.3, 0.4]])"]}},tanh:{evaluate:Ds(e=>Math.tanh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `tanh` function computes the hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic tangent of each element while preserving the original structure.",seeAlso:["math.atanh","math.tan","math.sinh","math.cosh"],examples:["let { tanh } = import(math);\ntanh(0)","let { tanh } = import(math);\ntanh(1)","let { tanh } = import(math);\ntanh(-0.5)","let { tanh } = import(math);\ntanh(50)"]}},atanh:{evaluate:Ds(e=>Math.atanh(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `atanh` function computes the inverse hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic tangent of each element while preserving the original structure.",seeAlso:["math.tanh","math.atan","math.asinh","math.acosh"],examples:["let { atanh } = import(math);\natanh(0)","let { atanh } = import(math);\natanh(0.9)","let { atanh } = import(math);\natanh(-0.5)","let { atanh } = import(math);\natanh([0.1, 0.2, 0.3])","let { atanh } = import(math);\natanh([[0.1, 0.2], [0.3, 0.4]])"]}},ln:{evaluate:Ds(e=>Math.log(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `ln` function computes the natural logarithm (base `e`) of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the natural logarithm of each element while preserving the original structure.",seeAlso:["math.log2","math.log10","^"],examples:["let { ln } = import(math);\nln(0.01)","let { ln } = import(math);\nln(2.5)","let { ln } = import(math);\nln(E)","let { ln } = import(math);\nln([1, 2, 3])","let { ln } = import(math);\nln([[1, 2], [3, 4]])"]}},log2:{evaluate:Ds(e=>Math.log2(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `log2` function computes the base `2` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-2 logarithm of each element while preserving the original structure.",seeAlso:["math.ln","math.log10"],examples:["let { log2 } = import(math);\nlog2(0.01)","let { log2 } = import(math);\nlog2(2 ^ 12)","let { log2 } = import(math);\nlog2(2.5)","let { log2 } = import(math);\nlog2([1, 2, 3])","let { log2 } = import(math);\nlog2([[1, 2], [3, 4]])"]}},log10:{evaluate:Ds(e=>Math.log10(e)),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `log10` function computes the base `10` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-10 logarithm of each element while preserving the original structure.",seeAlso:["math.ln","math.log2"],examples:["let { log10 } = import(math);\nlog10(0.01)","let { log10 } = import(math);\nlog10(10 ^ 12)","let { log10 } = import(math);\nlog10(2.5)","let { log10 } = import(math);\nlog10([1, 2, 3])","let { log10 } = import(math);\nlog10([[1, 2], [3, 4]])"]}},"to-rad":{evaluate:Ds(e=>e*Math.PI/180),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `to-rad` function converts an angle from degrees to radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.",seeAlso:["math.to-deg","math.sin","math.cos","math.tan"],examples:["let { to-rad } = import(math);\nto-rad(0)","let { to-rad } = import(math);\nto-rad(90)","let { to-rad } = import(math);\nto-rad(180)","let { to-rad } = import(math);\nto-rad(360)","let { to-rad } = import(math);\nto-rad([0, 90, 180])","let { to-rad } = import(math);\nto-rad([[0, 90], [180, 360]])"]}},"to-deg":{evaluate:Ds(e=>180*e/Math.PI),arity:te(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `to-deg` function converts an angle from radians to degrees, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.",seeAlso:["math.to-rad"],examples:["let { to-deg } = import(math);\nto-deg(0)","let { to-deg } = import(math);\nto-deg(PI)","let { to-deg } = import(math);\nto-deg(PI / 2)","let { to-deg } = import(math);\nto-deg(3 * PI / 2)","let { to-deg } = import(math);\nto-deg([0, PI, PI / 2])","let { to-deg } = import(math);\nto-deg([[0, PI], [PI / 2, 3 * PI / 2]])"]}}},Fs={name:"math",functions:Us,source:"{}",docs:Vs(Us)};const Ws={juxt:{evaluate:(e,t)=>{e.forEach(e=>F(e,t));const r=function(e){return e.reduce((e,t)=>{if(null===e)return null;const r="number"==typeof t||I(t)?te(1):t.arity,{min:n,max:o}=r,{min:a,max:i}=e,s="number"==typeof n&&"number"==typeof a?Math.max(n,a):"number"==typeof n?n:"number"==typeof a?a:void 0,l="number"==typeof o&&"number"==typeof i?Math.min(o,i):"number"==typeof o?o:"number"==typeof i?i:void 0;return"number"==typeof s&&"number"==typeof l&&s>l?null:{min:s,max:l}},{})}(e);if(null===r)throw new o("All functions must accept the same number of arguments",t);return{[p]:!0,sourceCodeInfo:t,functionType:"Juxt",params:e,arity:r}},arity:{min:1},docs:{category:"functional",returns:{type:"function"},args:{a:{type:"function"},b:{type:"function"},fun:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","fns"]}],description:"Takes one or many function and returns a function that is the juxtaposition of those functions.\nThe returned function takes a variable number of args,\nand returns a vector containing the result of applying each function to the args (left-to-right).",seeAlso:["comp"],examples:["let { juxt } = import(functional);\njuxt(+, *, min, max)(\n 3,\n 4,\n 6,\n)",'let { juxt } = import(functional);\njuxt("a", "b")(\n {\n a: 1,\n b: 2,\n c: 3,\n d: 4\n }\n)',"let { juxt } = import(functional);\njuxt(+, *, min, max) apply range(1, 11)"]}},complement:{evaluate:([e],t)=>{const r=U(e,t);return{[p]:!0,sourceCodeInfo:t,functionType:"Complement",function:r,arity:Z(r)}},arity:te(1),docs:{category:"functional",returns:{type:"function"},args:{fun:{type:"function"}},variants:[{argumentNames:["fun"]}],description:"Takes a function $fun and returns a new function that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.",seeAlso:["comp","functional.every-pred","functional.some-pred"],examples:["let { complement } = import(functional);\ncomplement(>)(1, 3)","let { complement } = import(functional);\ncomplement(<)(1, 3)","let { complement } = import(functional);\ncomplement(+)(1, 3)","let { complement } = import(functional);\ncomplement(+)(0, 0)"]}},"every-pred":{evaluate:(e,t)=>({[p]:!0,sourceCodeInfo:t,functionType:"EveryPred",params:e,arity:{min:1,max:1}}),arity:{min:1},docs:{category:"functional",returns:{type:"function"},args:{fun:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","fns"]}],description:"\nTakes a number of predicates and returns a function that returns `true` if all predicates\nreturn a truthy value against all of its arguments, else it returns `false`.",seeAlso:["functional.some-pred","functional.complement","collection.every?"],examples:['let { every-pred } = import(functional);\nevery-pred(string?, -> count($) > 3)(\n "Albert",\n "Mojir"\n)','let { every-pred } = import(functional);\n(string? every-pred -> count($) > 3)(\n "Albert",\n "M"\n)'],hideOperatorForm:!0}},"some-pred":{evaluate:(e,t)=>({[p]:!0,sourceCodeInfo:t,functionType:"SomePred",params:e,arity:{min:1,max:1}}),arity:{min:1},docs:{category:"functional",returns:{type:"function"},args:{fun:{type:"function"},fns:{type:"function",rest:!0}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","fns"]}],description:"Takes a number of `predicates` and returns a function that returns `true` if at least one of the `predicates` return a truthy `true` value against at least one of its arguments, else it returns `false`.",seeAlso:["functional.every-pred","functional.complement","collection.any?"],examples:['let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)("Albert", "Mojir")','let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)("a", "M")','let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)("a", [1, 2, 3])',"let { some-pred } = import(functional);\nsome-pred(string?, -> count($) > 3)([1, 2, 3], [2])"],hideOperatorForm:!0}},fnull:{evaluate:([e,...t],r)=>{const n=U(e,r);return{[p]:!0,sourceCodeInfo:r,functionType:"Fnull",function:n,params:t,arity:Z(n)}},arity:{min:2},docs:{category:"functional",returns:{type:"function"},args:{a:{type:"function"},b:{type:"any"},fun:{type:"function"},arg:{type:"any"},args:{type:"any",rest:!0}},variants:[{argumentNames:["fun","arg"]},{argumentNames:["fun","arg","args"]}],description:"Takes a function $fun, and returns a function that calls $fun, replacing a null argument to the corresponding argument.",seeAlso:["identity","constantly"],examples:["let { fnull } = import(functional);\nfnull(inc, 0)(1)","let { fnull } = import(functional);\nfnull(inc, 0)(null)","let { fnull } = import(functional);\n(inc fnull 0)(null)","let { fnull } = import(functional);\nfnull(+, 1, 2)(null, 0)","let { fnull } = import(functional);\nfnull(+, 1, 2)(0, null)","let { fnull } = import(functional);\nfnull(+, 1, 2)(null, null)","let { fnull } = import(functional);\nfnull(+, 1, 2)(null, null, 3, 4)"]}}},Gs={name:"functional",functions:Ws,source:"{}",docs:Vs(Ws)};const Bs={"string-repeat":{evaluate:([e,t],r)=>(G(e,r),Y(t,r,{integer:!0,nonNegative:!0}),e.repeat(t)),arity:te(2),docs:{category:"string",returns:{type:"string"},args:{a:{type:"string"},b:{type:"integer"},s:{type:"string"},n:{type:"integer"}},variants:[{argumentNames:["s","n"]}],description:"Repeates $s $n times.",seeAlso:["str","repeat"],examples:['let { string-repeat } = import(string);\n"*" string-repeat 10','let { string-repeat } = import(string);\nstring-repeat("*", 10)','let { string-repeat } = import(string);\nstring-repeat("***", 0)']}},"from-char-code":{evaluate:([e],t)=>{Y(e,t,{finite:!0});const r=se(e);try{return String.fromCodePoint(r)}catch(e){throw new o(e,t)}},arity:te(1),docs:{category:"string",returns:{type:"string"},args:{code:{type:"number"}},variants:[{argumentNames:["code"]}],description:"Return character for code point $code.",seeAlso:["string.to-char-code"],examples:["let { from-char-code } = import(string);\nfrom-char-code(65)","let { from-char-code } = import(string);\nfrom-char-code(0)"]}},"to-char-code":{evaluate:([e],t)=>(G(e,t,{nonEmpty:!0}),w(e.codePointAt(0),t)),arity:te(1),docs:{category:"string",returns:{type:"number"},args:{c:{type:"string"}},variants:[{argumentNames:["c"]}],description:"Return code point for first character in $c.",seeAlso:["string.from-char-code"],examples:['let { to-char-code } = import(string);\nto-char-code("A")','let { to-char-code } = import(string);\nto-char-code("Albert")']}},"trim-left":{evaluate:([e],t)=>(G(e,t),e.replace(/^\s+/,"")),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a new string with leading whitespaces removed.",seeAlso:["trim","string.trim-right"],examples:['let { trim-left } = import(string);\ntrim-left(" Albert ")','let { trim-left } = import(string);\ntrim-left(" ")','let { trim-left } = import(string);\ntrim-left("")']}},"trim-right":{evaluate:([e],t)=>(G(e,t),e.replace(/\s+$/,"")),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a new string with trailing whitespaces removed.",seeAlso:["trim","string.trim-left"],examples:['let { trim-right } = import(string);\ntrim-right(" Albert ")','let { trim-right } = import(string);\ntrim-right(" ")','let { trim-right } = import(string);\ntrim-right("")']}},"split-lines":{evaluate:([e],t)=>(G(e,t),e.split(/\r\n|\n|\r/).filter(e=>""!==e)),arity:te(1),docs:{category:"string",returns:{type:"string",array:!0},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Divides $s into an array of substrings, each representing a line.",seeAlso:["split"],examples:['let { split-lines } = import(string);\nsplit-lines("Albert\nMojir\n")','let { split-lines } = import(string);\nsplit-lines("Albert\n\nMojir")','let { split-lines } = import(string);\nsplit-lines("Albert\nMojir\n\n")','let { split-lines } = import(string);\nsplit-lines("")']}},"pad-left":{evaluate:([e,t,r],n)=>(G(e,n),Y(t,n,{integer:!0}),void 0!==r&&G(r,n),e.padStart(t,r)),arity:{min:2,max:3},docs:{category:"string",returns:{type:"string"},args:{a:{type:"string"},b:{type:"integer"},s:{type:"string"},length:{type:"integer"},padString:{type:"string"}},variants:[{argumentNames:["s","length"]},{argumentNames:["s","length","padString"]}],description:"Pads from the start of $s with `padString` (multiple times, if needed) until the resulting string reaches the given $length.",seeAlso:["string.pad-right"],examples:['let { pad-left } = import(string);\n"Albert" pad-left 20','let { pad-left } = import(string);\npad-left("Albert", 20)','let { pad-left } = import(string);\npad-left("Albert", 20, "-*-")','let { pad-left } = import(string);\npad-left("Albert", 5)','let { pad-left } = import(string);\npad-left("Albert", -1)']}},"pad-right":{evaluate:([e,t,r],n)=>(G(e,n),Y(t,n,{integer:!0}),void 0!==r&&G(r,n),e.padEnd(t,r)),arity:{min:2,max:3},docs:{category:"string",returns:{type:"string"},args:{a:{type:"string"},b:{type:"integer"},s:{type:"string"},length:{type:"integer"},padString:{type:"string"}},variants:[{argumentNames:["s","length"]},{argumentNames:["s","length","padString"]}],description:"Pads from the start of $s with `padString` (multiple times, if needed) until the resulting string reaches the given `length`.",seeAlso:["string.pad-left"],examples:['let { pad-right } = import(string);\n"Albert" pad-right 20','let { pad-right } = import(string);\npad-right("Albert", 20)','let { pad-right } = import(string);\npad-right("Albert", 20, "-*-")','let { pad-right } = import(string);\npad-right("Albert", 5)','let { pad-right } = import(string);\npad-right("Albert", -1)']}},template:{evaluate:([e,...t],r)=>{G(e,r),ye(t,r);const n=e.split("||||");if(n.length<=1)return _s(n[0],t,r);{const e=t[0];Y(e,r,{integer:!0,nonNegative:!0});const o=[`${e}`,...t.slice(1)];if(2===n.length){return _s(n[1===e?0:1],o,r)}return _s(n[Math.min(e,n.length-1)],o,r)}},arity:{min:1,max:10},docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"},params:{type:"any",rest:!0}},variants:[{argumentNames:["s","params"]}],description:"Applies placeholders to a string. Support for basic pluralization - see examples. If pluralization is used, first placeholder must be a number.",seeAlso:["str"],examples:['let { template } = import(string);\ntemplate("Hi, $1 and $2", "Carl", "Larry")','let { template } = import(string);\ntemplate("Hi $1, $2, $3, $4, $5, $6, $7, $8 and $9", "A", "B", "C", "D", "E", "F", "G", "H", "I")','let { template } = import(string);\ntemplate("$1 book||||$1 books", 0)','let { template } = import(string);\ntemplate("$1 book||||$1 books", 1)','let { template } = import(string);\ntemplate("$1 book||||$1 books", 2)','let { template } = import(string);\ntemplate("No book||||$1 book||||$1 books", 0)','let { template } = import(string);\ntemplate("No book||||$1 book||||$1 books", 1)','let { template } = import(string);\ntemplate("No book||||$1 book||||$1 books", 10)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 0)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 1)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 2)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 3)','let { template } = import(string);\ntemplate("No book||||One book||||Two books||||Three books||||$1 books", 4)'],hideOperatorForm:!0}},"encode-base64":{evaluate:([e],t)=>(G(e,t),btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(e,t)=>String.fromCharCode(Number.parseInt(t,16))))),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns a Base64 encoded string from $s.",seeAlso:["string.decode-base64"],examples:['let { encode-base64 } = import(string);\nencode-base64("Albert")']}},"decode-base64":{evaluate:([e],t)=>{G(e,t);try{return decodeURIComponent(Array.prototype.map.call(atob(e),e=>`%${`00${e.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""))}catch(e){throw new o(e,t)}},arity:te(1),docs:{category:"string",returns:{type:"string"},args:{base64string:{type:"string"}},variants:[{argumentNames:["base64string"]}],description:"Returns a Base64 decoded string from $base64string.",seeAlso:["string.encode-base64"],examples:['let { decode-base64 } = import(string);\ndecode-base64("QWxiZXJ0IPCfkLs=")']}},"encode-uri-component":{evaluate:([e],t)=>(G(e,t),encodeURIComponent(e)),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns an escaped `URI` string.",seeAlso:["string.decode-uri-component"],examples:['let { encode-uri-component } = import(string);\nencode-uri-component("Hi everyone!?")']}},"decode-uri-component":{evaluate:([e],t)=>{G(e,t);try{return decodeURIComponent(e)}catch(e){throw new o(e,t)}},arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns an un-escaped `URI` string.",seeAlso:["string.encode-uri-component"],examples:['let { decode-uri-component } = import(string);\ndecode-uri-component("Hi%20everyone!%3F%20%F0%9F%91%8D")']}},capitalize:{evaluate:([e],t)=>(G(e,t),e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()),arity:te(1),docs:{category:"string",returns:{type:"string"},args:{s:{type:"string"}},variants:[{argumentNames:["s"]}],description:"Returns $s with the first character converted to uppercase and the rest to lowercase.",seeAlso:["lower-case","upper-case"],examples:['let { capitalize } = import(string);\ncapitalize("albert")','let { capitalize } = import(string);\ncapitalize("ALBERT")','let { capitalize } = import(string);\ncapitalize("aLBERT")','let { capitalize } = import(string);\ncapitalize("")']}}},Ls=/\$\$/g;function _s(e,t,r){for(let n=0;n<9;n+=1){const o=new RegExp(`(\\$\\$|[^$]|^)\\$${n+1}`,"g");if(o.test(e)){const a=_(t[n],r);e=e.replace(o,`$1${a}`)}}return e=e.replace(Ls,"$")}const Ks={name:"string",functions:Bs,source:"{}",docs:Vs(Bs)};function Js(e,t){if(j(e)){if("string"==typeof t&&oe(e,t))return le(e[t])}else if(H(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return le(e[t])}function Hs(e,t,r,n){if(P(e,n),Array.isArray(e)||"string"==typeof e){if(Y(t,n,{integer:!0}),Y(t,n,{gte:0}),Y(t,n,{lte:e.length}),"string"==typeof e)return G(r,n,{char:!0}),`${e.slice(0,t)}${r}${e.slice(t+1)}`;const o=[...e];return o[t]=r,o}G(t,n);const o={...e};return o[t]=r,o}const Ys={"get-in":{evaluate:(e,t)=>{let r=le(e[0]);const n=e[1]??[],o=le(e[2]);ye(n,t);for(const e of n){if(K(e,t),!I(r))return o;{const t=Js(r,e);if(void 0===t)return o;r=t}}return r},arity:{min:2,max:3},docs:{category:"collection",returns:{type:"any"},args:{a:{type:"collection"},b:{type:"array"},"not-found":{type:"any"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","not-found"]}],description:"Returns the value in a nested collection, where $b is an array of keys. Returns $not-found if the key is not present. If $not-found is not set, `null` is returned.",seeAlso:["get","collection.assoc-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "a", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0],\n "Lisa"\n)']}},"assoc-in":{evaluate:([e,t,r],n)=>{if(P(e,n),ye(t,n),E(r,n),1===t.length)return K(t[0],n),Hs(e,t[0],r,n);const{coll:o,innerCollMeta:a}=function(e,t,r){const n=ue(e);return{coll:n,innerCollMeta:t.slice(0,t.length-1).reduce((e,t)=>{const n=e.coll;let o;return Array.isArray(n)?(Y(t,r),o=R(n[t],r)):(C(n,r),G(t,r),oe(e.coll,t)||(n[t]={}),o=R(n[t],r)),{coll:o,parent:n}},{coll:n,parent:{}})}}(e,t,n),i=_(t[t.length-1],n),s=_(t[t.length-2],n);return Array.isArray(a.parent)?(Y(s,n),a.parent[s]=Hs(a.coll,i,r,n)):(G(s,n),a.parent[s]=Hs(a.coll,i,r,n)),o},arity:te(3),docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:["number","string"],array:!0},value:{type:"any"}},variants:[{argumentNames:["coll","ks","value"]}],description:"\nAssociates a value in the nested collection $coll, where $ks is an array of keys and $value is the new value.\n\nIf any levels do not exist, objects will be created - and the corresponding keys must be of type string.",seeAlso:["assoc","collection.get-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.assoc-in(\n {},\n ["a", "b", "c"],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, [1, 2, 3]],\n [2, 1],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, { name: "albert" }],\n [2, "name", 0],\n "A"\n)']}},update:{evaluate:()=>{throw new Error("update: Dvala implementation should be used instead")},arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},key:{type:["string","number"]},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","key","fun"]},{argumentNames:["coll","key","fun","fun-args"]}],description:"\nUpdates a value in the $coll collection, where $key is a key. $fun is a function\nthat will take the old value and any supplied $fun-args and\nreturn the new value.\nIf the key does not exist, `null` is passed as the old value.",seeAlso:["collection.update-in","assoc"],examples:['\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(x, "a", inc)','\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(\n x,\n "c",\n val -> null?(val) ? 0 : inc(val)\n)']}},"update-in":{evaluate:()=>{throw new Error("update-in: Dvala implementation should be used instead")},arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:"array"},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","ks","fun"]},{argumentNames:["coll","ks","fun","fun-args"]}],description:"Updates a value in the $coll collection, where $ks is an array of\nkeys and $fun is a function that will take the old value and\nany supplied $fun-args and return the new value. If any levels do not exist,\nobjects will be created - and the corresponding keys must be of type string.",seeAlso:["collection.update","collection.assoc-in","collection.get-in"],examples:['\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n -> null?($) ? 0 : inc($)\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "foo"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "baz"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n *,\n 10,\n 10,\n 10,\n)']}},filteri:{evaluate:()=>{throw new Error("filteri: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection with all elements that pass the test implemented by $b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["filter","collection.mapi"],examples:["let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> i % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x + i > 3)"]}},mapi:{evaluate:()=>{throw new Error("mapi: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection populated with the results of calling $b on every element in $a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["map","collection.filteri"],examples:["let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x + i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x * i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x - i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x / i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x % inc(i))"]}},reducei:{evaluate:()=>{throw new Error("reducei: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["reduce","collection.reducei-right","collection.reductionsi"],examples:["let cu = import(collection); cu.reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"reduce-right":{evaluate:()=>{throw new Error("reduce-right: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.",seeAlso:["reduce","collection.reducei-right"],examples:['let cu = import(collection); cu.reduce-right(["A", "B", "C"], str, "")',"let cu = import(collection); cu.reduce-right({ a: 1, b: 2 }, +, 0)"]}},"reducei-right":{evaluate:()=>{throw new Error("reducei-right: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reducei","collection.reduce-right"],examples:["let cu = import(collection); cu.reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei-right({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},reductions:{evaluate:()=>{throw new Error("reductions: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.",seeAlso:["reduce","collection.reductionsi"],examples:["let cu = import(collection); cu.reductions([1, 2, 3], +, 0)","let cu = import(collection); cu.reductions([1, 2, 3], +, 10)","let cu = import(collection); cu.reductions([], +, 0)","let cu = import(collection); cu.reductions({ a: 1, b: 2 }, +, 0)","\nlet cu = import(collection);\ncu.reductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + (even?(value) ? value : 0),\n 0\n)"]}},reductionsi:{evaluate:()=>{throw new Error("reductionsi: Dvala implementation should be used instead")},arity:te(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reductions","collection.reducei"],examples:["let cu = import(collection); cu.reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reductionsi({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"not-empty":{evaluate:([e],t)=>null===e?null:(P(e,t),"string"==typeof e||Array.isArray(e)?e.length>0?e:null:Object.keys(e).length>0?e:null),arity:te(1),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:["collection","null"]}},variants:[{argumentNames:["coll"]}],description:"Returns `null` if $coll is empty or `null`, otherwise $coll.",seeAlso:["empty?","not-empty?"],examples:["let cu = import(collection); cu.not-empty([])","let cu = import(collection); cu.not-empty([1, 2, 3])","let cu = import(collection); cu.not-empty({})","let cu = import(collection); cu.not-empty({ a: 2 })",'let cu = import(collection); cu.not-empty("")','let cu = import(collection); cu.not-empty("Albert")',"let cu = import(collection); cu.not-empty(null)"]}},"every?":{evaluate:()=>{throw new Error("every?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if all entries in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.any?","collection.not-every?","collection.not-any?","functional.every-pred","grid.cell-every?"],examples:["let cu = import(collection); cu.every?([1, 2, 3], number?)","let cu = import(collection); cu.every?([1, 2, 3], even?)",'\nlet cu = import(collection);\ncu.every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?,\n)',"\nlet cu = import(collection);\ncu.every?(\n [50, 100, 150, 200],\n -> $ > 10,\n)","let cu = import(collection); cu.every?([], number?)",'let cu = import(collection); cu.every?("", number?)',"let cu = import(collection); cu.every?({}, number?)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 4},\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}},"any?":{evaluate:()=>{throw new Error("any?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if any element in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.not-any?","collection.not-every?","functional.some-pred","some","grid.some?"],examples:['\nlet cu = import(collection);\ncu.any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.any?([], number?)",'let cu = import(collection); cu.any?("", number?)',"let cu = import(collection); cu.any?({}, number?)","\nlet cu = import(collection);\ncu.any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-any?":{evaluate:()=>{throw new Error("not-any?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `false` if any element in $a pass the test implemented by $b, otherwise returns `true`.",seeAlso:["collection.any?","collection.every?","collection.not-every?"],examples:['\nlet cu = import(collection);\ncu.not-any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-any?([], number?)",'let cu = import(collection); cu.not-any?("", number?)',"let cu = import(collection); cu.not-any?({}, number?)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-every?":{evaluate:()=>{throw new Error("not-every?: Dvala implementation should be used instead")},arity:te(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if at least one element in $a does not pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.any?","collection.not-any?"],examples:['\nlet cu = import(collection);\ncu.not-every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-every?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-every?([], number?)",'let cu = import(collection); cu.not-every?("", number?)',"let cu = import(collection); cu.not-every?({}, number?)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 4 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}}},Xs={name:"collection",functions:Ys,source:'{\n update: (coll, key, fn, ...extra-params) ->\n assoc(coll, key, apply(fn, [get(coll, key), ...extra-params])),\n\n update-in: (coll, ks, fn, ...extra-params) -> do\n let k = first(ks);\n if count(ks) == 1 then\n assoc(coll, k, apply(fn, [get(coll, k), ...extra-params]))\n else\n let inner = get(coll, k);\n let inner-coll = null?(inner) ? {} : inner;\n assoc(coll, k, apply(self, [inner-coll, slice(ks, 1), fn, ...extra-params]))\n end\n end,\n\n filteri: (coll, fn) -> do\n cond\n case array?(coll) then\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> if fn(first(pair), second(pair)) then [...acc, first(pair)] else acc end,\n []\n )\n\n case string?(coll) then\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> if fn(first(pair), second(pair)) then ++(acc, first(pair)) else acc end,\n ""\n )\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) ->\n if fn(coll(k), k) then assoc(acc, k, coll(k)) else acc end,\n {}\n )\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n mapi: (coll, fn) -> do\n cond\n case array?(coll) then\n for (i in range(count(coll))) -> fn(nth(coll, i), i)\n\n case string?(coll) then\n reduce(\n for (i in range(count(coll))) -> fn(nth(coll, i), i),\n (acc, ch) -> ++(acc, ch),\n ""\n )\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) ->\n assoc(acc, k, fn(coll(k), k)),\n {}\n )\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reducei: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i + 1)\n end\n end\n\n case array?(coll) then\n loop (acc = initial, i = 0) -> do\n if i >= count(coll) then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i + 1)\n end\n end\n\n case object?(coll) then\n reduce(keys(coll), (acc, k) -> fn(acc, coll(k), k), initial)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reduce-right: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n reduce(reverse(coll), fn, initial)\n\n case array?(coll) then\n reduce(reverse(coll), fn, initial)\n\n case object?(coll) then\n reduce(reverse(keys(coll)), (acc, k) -> fn(acc, coll(k)), initial)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reducei-right: (coll, fn, initial) -> do\n cond\n case string?(coll) then\n let len = count(coll);\n loop (acc = initial, i = len - 1) -> do\n if i < 0 then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i - 1)\n end\n end\n\n case array?(coll) then\n let len = count(coll);\n loop (acc = initial, i = len - 1) -> do\n if i < 0 then\n acc\n else\n recur(fn(acc, nth(coll, i), i), i - 1)\n end\n end\n\n case object?(coll) then\n reduce(reverse(keys(coll)), (acc, k) -> fn(acc, coll(k), k), initial)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n reductions: (coll, fn, initial) -> do\n let items = cond\n case string?(coll) then\n if count(coll) == 0 then [] else for (i in range(count(coll))) -> nth(coll, i) end\n\n case array?(coll) then coll\n\n case object?(coll) then\n for (k in keys(coll)) -> coll(k)\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end;\n if count(items) == 0 then\n [initial]\n else\n reduce(items, (acc, elem) -> do\n let prev = last(acc);\n [...acc, fn(prev, elem)]\n end, [initial])\n end\n end,\n\n reductionsi: (coll, fn, initial) -> do\n cond\n case string?(coll) then do\n if count(coll) == 0 then\n [initial]\n else\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> do\n let prev = last(acc);\n [...acc, fn(prev, first(pair), second(pair))]\n end,\n [initial]\n )\n end\n end\n\n case array?(coll) then do\n if count(coll) == 0 then\n [initial]\n else\n reduce(\n for (i in range(count(coll))) -> [nth(coll, i), i],\n (acc, pair) -> do\n let prev = last(acc);\n [...acc, fn(prev, first(pair), second(pair))]\n end,\n [initial]\n )\n end\n end\n\n case object?(coll) then do\n let ks = keys(coll);\n if count(ks) == 0 then\n [initial]\n else\n reduce(ks, (acc, k) -> do\n let prev = last(acc);\n [...acc, fn(prev, coll(k), k)]\n end, [initial])\n end\n end\n\n case true then\n perform(effect(dvala.error), "Expected collection")\n end\n end,\n\n "every?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then true\n case not(fn(nth(items, i))) then false\n case true then recur(i + 1)\n end\n end,\n\n "any?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then false\n case fn(nth(items, i)) then true\n case true then recur(i + 1)\n end\n end,\n\n "not-any?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then true\n case fn(nth(items, i)) then false\n case true then recur(i + 1)\n end\n end,\n\n "not-every?": (coll, fn) -> do\n let items = cond\n case array?(coll) then coll\n case string?(coll) then for (i in range(count(coll))) -> nth(coll, i)\n case object?(coll) then for (k in keys(coll)) -> [k, coll(k)]\n case true then perform(effect(dvala.error), "Expected collection")\n end;\n loop (i = 0) ->\n cond\n case i >= count(items) then false\n case not(fn(nth(items, i))) then true\n case true then recur(i + 1)\n end\n end\n}',docs:Vs(Ys)};const Qs={position:{evaluate:()=>{throw new Error("position: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:["sequence","null"]},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the index of the first elements that passes the test implemented by $fun. If no element was found, `null` is returned.",seeAlso:["index-of","some","find"],examples:['\nlet su = import(sequence);\nsu.position(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet su = import(sequence);\nsu.position(\n [5, 10, 15, 20],\n -> $ > 10\n)","\nlet su = import(sequence);\nsu.position(\n [5, 10, 15, 20],\n -> $ > 100\n)","\nlet su = import(sequence);\nsu.position(\n null,\n -> $ > 100\n)"]}},"last-index-of":{evaluate:([e,t],r)=>{if(E(t,r),null===e)return null;if(z(e,r),"string"==typeof e){G(t,r);const n=e.lastIndexOf(t);return-1!==n?n:null}{const n=e.findLastIndex(e=>ie($(e,r),t),r);return-1!==n?n:null}},arity:te(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:["sequence","null"]},x:{type:"any"}},variants:[{argumentNames:["seq","x"]}],description:"Returns the last index of $x in $seq. If element is not present in $seq `null` is returned.",seeAlso:["index-of"],examples:["let su = import(sequence); su.last-index-of([[1], [2], [1], [2]], [1])",'let su = import(sequence); su.last-index-of(["Albert", "Mojir", 160, [1, 2]], "Mojir")',"let su = import(sequence); su.last-index-of([5, 10, 15, 20, 15], 15)","let su = import(sequence); su.last-index-of([5, 10, 15, 20], 1)","let su = import(sequence); su.last-index-of(null, 1)"]}},splice:{evaluate:(e,t)=>{const[r,n,o,...a]=e;z(r,t),Y(n,t,{integer:!0}),Y(o,t,{integer:!0,nonNegative:!0});const i=n<0?r.length+n:n;return Array.isArray(r)?[...r.slice(0,i),...a,...r.slice(i+o)]:(a.forEach(e=>G(e,t)),`${r.substring(0,i)}${a.join("")}${r.substring(i+o)}`)},arity:{min:3},docs:{category:"sequence",returns:{type:"sequence"},args:{seq:{type:"sequence",rest:!0},start:{type:"integer"},deleteCount:{type:"integer"},items:{type:"any",rest:!0}},variants:[{argumentNames:["seq","start","deleteCount"]},{argumentNames:["seq","start","deleteCount","items"]}],description:"Returns a a spliced array. Removes $deleteCount elements from $seq starting at $start and replaces them with $items. If $start is negative, it is counting from the end of the array.",seeAlso:["slice","sequence.remove-at"],examples:['let su = import(sequence); su.splice([1, 2, 3, 4, 5], 2, 2, "x")','let su = import(sequence); su.splice([1, 2, 3, 4, 5], -2, 1, "x")','let su = import(sequence); su.splice("Albert", 2, 2, "fo")']}},"sort-by":{evaluate:()=>{throw new Error("sort-by: Dvala implementation should be used instead")},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"any",rest:!0},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},keyfn:{type:"function"},comparer:{type:"function"}},variants:[{argumentNames:["seq","keyfn"]},{argumentNames:["seq","keyfn","comparer"]}],description:"Returns a sorted sequence of the items in $seq, where the sort order is determined by comparing `(keyfn item)`. If no $comparer is supplied, uses builtin `compare`.",seeAlso:["sort","compare"],examples:['let su = import(sequence); su.sort-by(["Albert", "Mojir", "Nina"], count)','let su = import(sequence); su.sort-by(["Albert", "Mojir", "Nina"], count)','let su = import(sequence); su.sort-by("Albert", lower-case, -> $2 compare $1)']}},unshift:{evaluate:([e,...t],r)=>{if(z(e,r),"string"==typeof e)return be(t,r),[...t,e].join("");const n=[...e];return n.unshift(...t),n},arity:{min:2},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},values:{type:"any",rest:!0}},variants:[{argumentNames:["seq","values"]}],description:"Returns copy of $seq with $values added to the beginning.",seeAlso:["push","++"],examples:["let su = import(sequence); su.unshift([1, 2, 3], 4)","let su = import(sequence); su.unshift([1, 2, 3], 4)","let su = import(sequence); su.unshift([1, 2, 3], 4, 5, 6)","\nlet su = import(sequence);\nlet l = [1, 2, 3];\nsu.unshift(l, 4);\nl"]}},distinct:{evaluate:([e],t)=>{if(z(e,t),Array.isArray(e)){const r=[];for(const n of e)E(n,t),r.some(e=>ie(e,n,t))||r.push(n);return r}return Array.from(new Set(e.split(""))).join("")},arity:te(1),docs:{category:"sequence",returns:{type:"sequence"},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns a copy of $seq with no duplicates.",seeAlso:["sequence.frequencies"],examples:["let su = import(sequence); su.distinct([[1], [2], [3], [1], [3], [5]])","let su = import(sequence); su.distinct([1, 2, 3, 1, 3, 5])",'let su = import(sequence); su.distinct("Albert Mojir")',"let su = import(sequence); su.distinct([])",'let su = import(sequence); su.distinct("")']}},remove:{evaluate:()=>{throw new Error("remove: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns a new sequence of items in $seq for witch `pred(item)` returns a falsy value.",seeAlso:["filter","sequence.remove-at"],examples:["let su = import(sequence); su.remove([1, 2, 3, 1, 3, 5], odd?)","let su = import(sequence); su.remove([1, 2, 3, 1, 3, 5], even?)",'let su = import(sequence); su.remove("Albert Mojir", -> "aoueiyAOUEIY" contains? $)']}},"remove-at":{evaluate:([e,t],r)=>{Y(t,r,{integer:!0}),z(e,r);const n=t<0?e.length+t:t;return n<0||n>=e.length?e:Array.isArray(e)?e.filter((e,t)=>t!==n):`${e.substring(0,n)}${e.substring(n+1)}`},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"number"}},variants:[{argumentNames:["seq","n"]}],description:"Returns a new sequence of all items in $seq except item at position $n. If $n is negative, it is counting from the end of the sequence.",seeAlso:["sequence.remove","sequence.splice"],examples:["let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], 2)",'let su = import(sequence); su.remove-at("Albert", -2)',"let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], 0)","let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], -1)",'let su = import(sequence); su.remove-at("Albert Mojir", 6)']}},"split-at":{evaluate:([e,t],r)=>{Y(t,r,{integer:!0}),z(e,r);const n=t<0?e.length+t:t;return[e.slice(0,n),e.slice(n)]},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"number"}},variants:[{argumentNames:["seq","n"]}],description:"Returns a pair of sequence `[take(pos input), drop(pos input)]`.",seeAlso:["sequence.split-with","take","drop"],examples:["let su = import(sequence); su.split-at([1, 2, 3, 4, 5], 2)",'let su = import(sequence); su.split-at("Albert", -2)',"let su = import(sequence); su.split-at([1, 2, 3, 4, 5], -2)",'let su = import(sequence); su.split-at("Albert", 2)']}},"split-with":{evaluate:()=>{throw new Error("split-with: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns a pair of sequences `[take-while(input, fun), drop-while(input, fun)]`.",seeAlso:["sequence.split-at","take-while","drop-while"],examples:["let su = import(sequence); su.split-with([1, 2, 3, 4, 5], odd?)","let su = import(sequence); su.split-with([1, 2, 3, 4, 5], -> $ > 3)",'let su = import(sequence); su.split-with("Albert", -> $ <= "o")']}},frequencies:{evaluate:([e],t)=>{z(e,t);return("string"==typeof e?e.split(""):e).reduce((e,r)=>(G(r,t),oe(e,r)?e[r]=e[r]+1:e[r]=1,e),{})},arity:te(1),docs:{category:"sequence",returns:{type:"object"},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns an object from distinct items in $seq to the number of times they appear. Note that all items in $seq must be valid object keys i.e. strings.",seeAlso:["sequence.group-by","sequence.distinct","vector.count-values"],examples:['let su = import(sequence); su.frequencies(["Albert", "Mojir", "Nina", "Mojir"])','let su = import(sequence); su.frequencies("Pneumonoultramicroscopicsilicovolcanoconiosis")']}},"group-by":{evaluate:()=>{throw new Error("group-by: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"object"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns an object of the elements of $seq keyed by the result of $fun on each element. The value at each key will be an array of the corresponding elements.",seeAlso:["sequence.frequencies","sequence.partition-by"],examples:['let su = import(sequence); su.group-by([{ name: "Albert" }, { name: "Albert" }, { name: "Mojir" }], "name")','let su = import(sequence); su.group-by([{name: "Albert"}, {name: "Albert"}, {name: "Mojir"}], "name")','let su = import(sequence); su.group-by("Albert Mojir", -> "aoueiAOUEI" contains? $ ? "vowel" : "other")']}},partition:{evaluate:(e,t)=>{const r=S(e[0],t),n=se(X(e[1],t)),o=e.length>=3?se(X(e[2],t)):n,a=4===e.length?null===e[3]?[]:function(e,t){return ye(e,t),e}(e[3],t):void 0;return Zs(n,o,r,a,t)},arity:{min:2,max:4},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"number"},seq:{type:"sequence"},n:{type:"number"},step:{type:"number"},pad:{type:"array"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","step"]},{argumentNames:["seq","n","step","pad"]}],description:"Returns an array of sequences of $n items each, at offsets $step apart. If $step is not supplied, defaults to $n. If a $pad array is supplied, use its elements as necessary to complete last partition upto $n items. In case there are not enough padding elements, return a partition with less than $n items.",seeAlso:["sequence.partition-all","sequence.partition-by"],examples:["let su = import(sequence); su.partition(range(20), 4)","let su = import(sequence); su.partition(range(20), 4)","let su = import(sequence); su.partition(range(22), 4)","let su = import(sequence); su.partition(range(20), 4, 6)","let su = import(sequence); su.partition(range(20), 4, 3)",'let su = import(sequence); su.partition(range(20), 3, 6, ["a"])','let su = import(sequence); su.partition(range(20), 4, 6, ["a"])','let su = import(sequence); su.partition(range(20), 4, 6, ["a", "b", "c", "d"])','let su = import(sequence); su.partition(["a", "b", "c", "d", "e", "f"], 3, 1)',"let su = import(sequence); su.partition([1, 2, 3, 4], 10)","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10)","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10, [])","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10, null)",'let su = import(sequence); su.partition("superfragilistic", 5)','let su = import(sequence); su.partition("superfragilistic", 5, 5, null)',"let su = import(sequence); let foo = [5, 6, 7, 8]; su.partition(foo, 2, 1, foo)"]}},"partition-all":{evaluate:(e,t)=>{const r=S(e[0],t),n=se(X(e[1],t));return Zs(n,3===e.length?se(X(e[2],t)):n,r,[],t)},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"number"},seq:{type:"sequence"},n:{type:"number"},step:{type:"number"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","step"]}],description:"Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.",seeAlso:["sequence.partition","sequence.partition-by"],examples:["let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 4)"]}},"partition-by":{evaluate:()=>{throw new Error("partition-by: Dvala implementation should be used instead")},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Applies $fun to each value in $seq, splitting it each time $fun returns a new value. Returns an array of sequences.",seeAlso:["sequence.partition","sequence.partition-all","sequence.group-by"],examples:["let su = import(sequence); su.partition-by([1, 2, 3, 4, 5], odd?)","let su = import(sequence); su.partition-by([1, 2, 3, 4, 5], -> $ == 3)","let su = import(sequence); su.partition-by([1, 1, 1, 2, 2, 3, 3], odd?)",'let su = import(sequence); su.partition-by("Leeeeeerrroyyy", identity)']}},"ends-with?":{evaluate:([e,t],r)=>(z(e,r),"string"==typeof e?(G(t,r),e.endsWith(t)):ie($(e.at(-1),r),$(t,r),r)),arity:te(2),docs:{category:"sequence",returns:{type:"boolean"},args:{a:{type:"sequence"},b:{type:"sequence"},seq:{type:"sequence"},suffix:{type:"sequence"}},variants:[{argumentNames:["seq","suffix"]}],description:"Returns `true` if $seq ends with $suffix, otherwise `false`.",seeAlso:["sequence.starts-with?"],examples:["let su = import(sequence); su.ends-with?([[1], [2], [3], [4], [5]], [5])","let su = import(sequence); su.ends-with?([[1], [2], [3], [4], [5]], 5)","let su = import(sequence); su.ends-with?([1, 2, 3, 4, 5], 5)","let su = import(sequence); su.ends-with?([1, 2, 3, 4, 5], [5])",'let su = import(sequence); su.ends-with?("Albert", "rt")','let su = import(sequence); su.ends-with?("Albert", "RT")']}},"starts-with?":{evaluate:([e,t],r)=>(z(e,r),"string"==typeof e?(G(t,r),e.startsWith(t)):ie($(e[0],r),$(t,r),r)),arity:te(2),docs:{category:"sequence",returns:{type:"boolean"},args:{a:{type:"sequence"},b:{type:"sequence"},seq:{type:"sequence"},prefix:{type:"sequence"}},variants:[{argumentNames:["seq","prefix"]}],description:"Returns `true` if $seq starts with $prefix, otherwise `false`.",seeAlso:["sequence.ends-with?"],examples:["let su = import(sequence); su.starts-with?([[1], [2], [3], [4], [5]], [1])","let su = import(sequence); su.starts-with?([1, 2, 3, 4, 5], 1)","let su = import(sequence); su.starts-with?([1, 2, 3, 4, 5], [1])",'let su = import(sequence); su.starts-with?("Albert", "Al")','let su = import(sequence); su.starts-with?("Albert", "al")']}},interleave:{evaluate:([...e],t)=>{const r="string"==typeof e[0],n=r?e.map(e=>(G(e,t),e.split(""))):e.map(e=>(ye(e,t),e)),o=Math.min(...n.map(e=>e.length)),a=[];for(let e=0;e<o;e+=1)for(const t of n)e<t.length&&a.push(t[e]);return r?a.join(""):a},arity:{min:1},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"sequence"},seqs:{type:"sequence",rest:!0}},variants:[{argumentNames:["seqs"]}],description:"Returns a sequence of the first item from each of the $seqs, then the second item from each of the $seqs, until all items from the shortest seq are exhausted.",seeAlso:["sequence.interpose","zipmap"],examples:["let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6])",'let su = import(sequence); su.interleave("Albert", ".,.,.,")',"let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7, 8, 9])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7, 8])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [])","let su = import(sequence); su.interleave([1, 2, 3], [])","let su = import(sequence); su.interleave([])"]}},interpose:{evaluate:([e,t],r)=>{if(z(e,r),"string"==typeof e)return G(t,r),e.split("").join(t);if(0===e.length)return[];const n=[];for(let r=0;r<e.length-1;r+=1)n.push(e[r],t);return n.push(e[e.length-1]),n},arity:te(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},separator:{type:"any"}},variants:[{argumentNames:["seq","separator"]}],description:"Returns a sequence of the elements of $seq separated by $separator. If $seq is a string, the separator must be a string.",seeAlso:["sequence.interleave","join"],examples:['let su = import(sequence); su.interpose("Albert", "-")','let su = import(sequence); su.interpose([1, 2, 3, 4, 5], "a")','let su = import(sequence); su.interpose(["Albert", "Mojir", "Nina"], ", ")','let su = import(sequence); su.interpose("Albert", ".")']}}};function Zs(e,t,r,n,o){Y(t,o,{positive:!0});const a="string"==typeof r,i=[];let s=0;e:for(;s<r.length;){const o=[];for(let a=s;a<s+e;a+=1)if(a>=r.length){const e=a-r.length;if(!n){s+=t;continue e}if(e>=n.length)break;o.push(n[e])}else o.push(r[a]);i.push(o),s+=t}return a?i.map(e=>e.join("")):i}const el={name:"sequence",functions:Qs,source:'{\n position: (seq, fn) -> do\n let items = cond\n case null?(seq) then null\n case string?(seq) then for (i in range(count(seq))) -> nth(seq, i)\n case true then seq\n end;\n if null?(items) then null\n else\n loop (i = 0) ->\n cond\n case i >= count(items) then null\n case fn(nth(items, i)) then i\n case true then recur(i + 1)\n end\n end\n end,\n\n sort-by: (seq, keyfn, ...args) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else [...seq] end;\n let keyed = map(items, (elem) -> [keyfn(elem), elem]);\n let sorted = if count(args) == 0 then\n sort(keyed, (a, b) -> compare(first(a), first(b)))\n else\n sort(keyed, (a, b) -> first(args)(first(a), first(b)))\n end;\n let result = map(sorted, second);\n if string?(seq) then join(result, "") else result end\n end,\n\n remove: (seq, fn) -> do\n let result = filter(\n if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end,\n (elem) -> not(fn(elem))\n );\n if string?(seq) then join(result, "") else result end\n end,\n\n split-with: (seq, fn) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end;\n let idx = loop (i = 0) ->\n cond\n case i >= count(items) then -1\n case not(fn(nth(items, i))) then i\n case true then recur(i + 1)\n end;\n if idx == -1 then\n [seq, if array?(seq) then [] else "" end]\n else\n [slice(seq, 0, idx), slice(seq, idx)]\n end\n end,\n\n group-by: (seq, fn) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end;\n reduce(items, (result, val) -> do\n let key = fn(val);\n let existing = get(result, key);\n assoc(result, key, if null?(existing) then [val] else [...existing, val] end)\n end, {})\n end,\n\n partition-by: (seq, fn) -> do\n let items = if string?(seq) then for (i in range(count(seq))) -> nth(seq, i) else seq end;\n if count(items) == 0 then\n []\n else\n do\n let result = reduce(rest(items), (acc, elem) -> do\n let value = fn(elem);\n if value != first(acc) then\n [value, [...second(acc), [elem]]]\n else\n [value, [...slice(second(acc), 0, count(second(acc)) - 1), [...last(second(acc)), elem]]]\n end\n end, [fn(first(items)), [[first(items)]]]);\n let groups = second(result);\n if string?(seq) then\n map(groups, (group) -> join(group, ""))\n else\n groups\n end\n end\n end\n end\n}',docs:Vs(Qs)};function tl(e,t){return{a:{type:e},b:{type:t}}}const rl={"bit-not":{evaluate:([e],t)=>(Y(e,t,{integer:!0}),~e),arity:te(1),docs:{category:"bitwise",returns:{type:"integer"},args:{a:{type:"integer"}},variants:[{argumentNames:["a"]}],description:"Returns bitwise `not` of $a.",seeAlso:["&","|","xor","bitwise.bit-and-not"],examples:["let { bit-not } = import(bitwise);\nbit-not(0)","let { bit-not } = import(bitwise);\nbit-not(255)"]}},"bit-and-not":{evaluate:([e,...t],r)=>(Y(e,r,{integer:!0}),t.reduce((e,t)=>(Y(t,r,{integer:!0}),e&~t),e)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...tl("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `and` with complement.",seeAlso:["&","|","xor","bitwise.bit-not"],examples:["let { bit-and-not } = import(bitwise);\n0b0011 bit-and-not 0b0110","let { bit-and-not } = import(bitwise);\nbit-and-not(0b0011, 0b0110)","let { bit-and-not } = import(bitwise);\nbit-and-not(0b0011, 0b0110, 0b1001)"]}},"bit-flip":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return e^1<<t},arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...tl("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Flips bit number $b.",seeAlso:["bitwise.bit-set","bitwise.bit-clear","bitwise.bit-test"],examples:["let { bit-flip } = import(bitwise);\n0b0011 bit-flip 1","let { bit-flip } = import(bitwise);\nbit-flip(0b0011, 1)","let { bit-flip } = import(bitwise);\nbit-flip(0b1100, 1)"]}},"bit-set":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return e|1<<t},arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...tl("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Sets bit number $b.",seeAlso:["bitwise.bit-flip","bitwise.bit-clear","bitwise.bit-test"],examples:["let { bit-set } = import(bitwise);\n0b0010 bit-set 1","let { bit-set } = import(bitwise);\nbit-set(0b0011, 1)","let { bit-set } = import(bitwise);\nbit-set(0b1100, 1)"]}},"bit-clear":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return e&~(1<<t)},arity:te(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...tl("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Clears bit number $b.",seeAlso:["bitwise.bit-flip","bitwise.bit-set","bitwise.bit-test"],examples:["let { bit-clear } = import(bitwise);\n0b0011 bit-clear 1","let { bit-clear } = import(bitwise);\nbit-clear(0b0011, 1)","let { bit-clear } = import(bitwise);\nbit-clear(0b1100, 1)"]}},"bit-test":{evaluate:([e,t],r)=>{Y(e,r,{integer:!0}),Y(t,r,{integer:!0,nonNegative:!0});return!!(e&1<<t)},arity:te(2),docs:{category:"bitwise",returns:{type:"boolean"},args:{...tl("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Checks if bit number $b is set.",seeAlso:["bitwise.bit-flip","bitwise.bit-set","bitwise.bit-clear"],examples:["let { bit-test } = import(bitwise);\n0b0011 bit-test 1","let { bit-test } = import(bitwise);\nbit-test(0b0011, 1)","let { bit-test } = import(bitwise);\nbit-test(0b1100, 1)"]}}},nl={name:"bitwise",functions:rl,source:"{}",docs:Vs(rl)};const ol={baseUnit:"rad",description:"angle",units:{deg:Math.PI/180,rad:1,grad:Math.PI/200,turn:2*Math.PI}};function al(e,t){switch(e){case"c":return t;case"f":return 9*t/5+32;case"k":return t+273.15}}function il(e,t){switch(e){case"c":return t;case"f":return 5*(t-32)/9;case"k":return t-273.15}}const sl=["c","f","k"],ll={angstrom:"ångströms",um:"micrometers",mm:"millimeters",cm:"centimeters",m:"meters",km:"kilometers",in:"inches",ft:"feet",yd:"yards",mi:"miles",nmi:"nautical miles",mg:"milligrams",g:"grams",kg:"kilograms",t:"metric tons",oz:"ounces",lb:"pounds",st:"stones",ml:"milliliters",cl:"centiliters",dl:"deciliters",l:"liters",tsp:"teaspoons",tbsp:"tablespoons","fl-oz":"fluid ounces",cup:"cups",pt:"pints",qt:"quarts",gal:"gallons",ms:"milliseconds",s:"seconds",min:"minutes",h:"hours",day:"days",week:"weeks",mm2:"square millimeters",cm2:"square centimeters",m2:"square meters",km2:"square kilometers",in2:"square inches",ft2:"square feet",yd2:"square yards",acre:"acres",hectare:"hectares","m/s":"meters per second","km/h":"kilometers per hour",mph:"miles per hour",kn:"knots","ft/s":"feet per second",b:"bytes",kb:"kilobytes",mb:"megabytes",gb:"gigabytes",tb:"terabytes",pb:"petabytes",pa:"pascals",kpa:"kilopascals",bar:"bars",atm:"atmospheres",psi:"pounds per square inch",mmhg:"millimeters of mercury",j:"joules",kj:"kilojoules",cal:"calories",kcal:"kilocalories",wh:"watt-hours",kwh:"kilowatt-hours",btu:"British thermal units",w:"watts",kw:"kilowatts",mw:"megawatts",hp:"horsepower",hz:"hertz",khz:"kilohertz",mhz:"megahertz",ghz:"gigahertz",deg:"degrees",rad:"radians",grad:"gradians",turn:"turns",c:"Celsius",f:"Fahrenheit",k:"Kelvin"};function cl(e){const t={},r=Object.keys(e.units);for(const n of r)for(const o of r){if(n===o)continue;const a=e.units[n]/e.units[o],i=`${n}->${o}`,s=ll[n],l=ll[o],c=[`convert.${o}->${n}`,...r.filter(e=>e!==n&&e!==o).map(e=>`convert.${n}->${e}`)];t[i]={evaluate:([e],t)=>(Y(e,t),e*a),arity:te(1),docs:{category:"convert",returns:{type:"number"},args:{value:{type:"number",description:`Value in ${s}`}},variants:[{argumentNames:["value"]}],description:`Converts a value from ${s} (\`${n}\`) to ${l} (\`${o}\`).`,seeAlso:c,examples:[`let { ${i} } = import(convert);\n${i}(1)`]}}}return t}const ul={...cl({baseUnit:"m",description:"length",units:{angstrom:1e-10,um:1e-6,mm:.001,cm:.01,m:1,km:1e3,in:.0254,ft:.3048,yd:.9144,mi:1609.344,nmi:1852}}),...cl({baseUnit:"kg",description:"weight",units:{mg:1e-6,g:.001,kg:1,t:1e3,oz:.028349523125,lb:.45359237,st:6.35029318}}),...cl({baseUnit:"l",description:"volume",units:{ml:.001,cl:.01,dl:.1,l:1,tsp:.00492892159375,tbsp:.01478676478125,"fl-oz":.0295735295625,cup:.2365882365,pt:.473176473,qt:.946352946,gal:3.785411784}}),...cl({baseUnit:"s",description:"time",units:{ms:.001,s:1,min:60,h:3600,day:86400,week:604800}}),...cl({baseUnit:"m2",description:"area",units:{mm2:1e-6,cm2:1e-4,m2:1,km2:1e6,in2:64516e-8,ft2:.09290304,yd2:.83612736,acre:4046.8564224,hectare:1e4}}),...cl({baseUnit:"m/s",description:"speed",units:{"m/s":1,"km/h":1/3.6,mph:.44704,kn:.514444,"ft/s":.3048}}),...cl({baseUnit:"b",description:"data",units:{b:1,kb:1e3,mb:1e6,gb:1e9,tb:1e12,pb:1e15}}),...cl({baseUnit:"pa",description:"pressure",units:{pa:1,kpa:1e3,bar:1e5,atm:101325,psi:6894.757293168,mmhg:133.322387415}}),...cl({baseUnit:"j",description:"energy",units:{j:1,kj:1e3,cal:4.184,kcal:4184,wh:3600,kwh:36e5,btu:1055.06}}),...cl({baseUnit:"w",description:"power",units:{w:1,kw:1e3,mw:1e6,hp:745.7}}),...cl({baseUnit:"hz",description:"frequency",units:{hz:1,khz:1e3,mhz:1e6,ghz:1e9}}),...cl(ol),...function(){const e={};for(const t of sl)for(const r of sl){if(t===r)continue;const n=`${t}->${r}`,o=ll[t],a=ll[r],i=[`convert.${r}->${t}`,...sl.filter(e=>e!==t&&e!==r).map(e=>`convert.${t}->${e}`)];e[n]={evaluate:([e],n)=>{Y(e,n);const o=il(t,e);return al(r,o)},arity:te(1),docs:{category:"convert",returns:{type:"number"},args:{value:{type:"number",description:`Value in ${o}`}},variants:[{argumentNames:["value"]}],description:`Converts a temperature from ${o} (\`${t}\`) to ${a} (\`${r}\`).`,seeAlso:i,examples:[`let { ${n} } = import(convert);\n${n}(100)`]}}}return e}()},ml=[fa,wa,ni,fi,Ni,Os,Fs,Gs,Ks,Xs,el,nl,{name:"convert",functions:ul,source:"{}",docs:Vs(ul)}];function pl({testPath:e,testNamePattern:r}){const n=function(e){const r=[];return n(e,r),r.reduce((e,t)=>(e.includes(t)||e.push(t),e),[]);function n(e,r){const o=function(e){const r=dl(e),n=t.dirname(e);let o=!0;return r.split("\n").reduce((r,a)=>{const i=a.match(/^\s*\/{2}\s*@include\s*(\S+)\s*$/);if(i){if(!o)throw new Error(`@include must be in the beginning of file: ${e}:${a+1}`);const s=i[1];r.push(t.resolve(n,s))}return a.match(/^\s*\/.*$/)||(o=!1),r},[])}(e);o.forEach(e=>{n(e,r),r.push(e)})}}(e),o={tap:"TAP version 13\n",success:!0};try{const t=function(e){const t=dl(e);let r,n="";return t.split("\n").reduce((e,t,o)=>{const a=o+1,i=t.match(/^\s*\/{2}\s*@(?:(skip)-)?test\s*(.*)$/);if(i){const t=(i[1]??"").toUpperCase(),o=i[2];if(!o)throw new Error(`Missing test name on line ${a}`);if(e.find(e=>e.name===o))throw new Error(`Duplicate test name ${o}`);return r={directive:t||null,name:o,program:n+[...Array(a+2-n.split("\n").length).keys()].map(()=>"").join("\n")},e.push(r),e}return r?r.program+=`${t}\n`:n+=`${t}\n`,e},[])}(e);o.tap+=`1..${t.length}\n`,t.forEach((t,a)=>{const i=a+1;if(r&&!r.test(t.name))o.tap+=`ok ${i} ${t.name} # skip - Not matching testNamePattern ${r}\n`;else if("SKIP"===t.directive)o.tap+=`ok ${i} ${t.name} # skip\n`;else try{const r=da({debug:!0,modules:ml}),a=function(e,t){return e.reduce((e,r)=>{const n=dl(r),o=t.run(n,{filePath:r,bindings:e});if(null!==o&&"object"==typeof o&&!Array.isArray(o))for(const[t,r]of Object.entries(o))t in e||(e[t]=r);return e},{})}(n,r);r.run(t.program,{bindings:a,filePath:e}),o.tap+=`ok ${i} ${t.name}\n`}catch(e){o.success=!1,o.tap+=`not ok ${i} ${t.name}${hl(e)}`}})}catch(e){o.tap+=`Bail out! ${gl(e)}\n`,o.success=!1}return o}function dl(t){if(!t.endsWith(".dvala"))throw new Error(`Expected .dvala file, got ${t}`);return e.readFileSync(t,{encoding:"utf-8"})}function hl(e){const t=gl(e);if(!fl(e))return`\n ---\n message: ${JSON.stringify(t)}\n ...\n`;const n=e.sourceCodeInfo;if(!n||"string"==typeof n)return`\n ---\n message: ${JSON.stringify(t)}\n error: ${JSON.stringify(e.name)}\n ...\n`;const o=t.includes("\n")?`|\n ${t.split(/\r?\n/).join("\n ")}`:JSON.stringify(t);return`\n ---\n error: ${JSON.stringify(e.name)}\n message: ${o}\n location: ${JSON.stringify(function(e){const t=[];e.filePath&&t.push(e.filePath);e.position&&(t.push(`${e.position.line}`),t.push(`${e.position.column}`));return t.join(":")}(n))}\n code:\n - "${n.code}"\n - "${r(n)}"\n ...\n`}function gl(e){return fl(e)?e.shortMessage:"string"==typeof e?e:e instanceof Error?e.message:"Unknown error"}function fl(e){return e instanceof o}export{hl as getErrorYaml,pl as runTest};
2
2
  //# sourceMappingURL=testFramework.esm.js.map