@zushah/chalkboard 2.4.0 → 3.0.2
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.
- package/CHANGELOG.md +315 -249
- package/LICENSE.md +328 -21
- package/README.md +113 -98
- package/dist/Chalkboard.d.ts +239 -53
- package/dist/Chalkboard.d.ts.map +1 -1
- package/dist/Chalkboard.js +7711 -4666
- package/dist/Chalkboard.js.map +1 -1
- package/dist/Chalkboard.min.js +1 -0
- package/package.json +24 -28
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Chalkboard;!function(e){e.APPLY=(t,r)=>{if(t&&"number"==typeof t.a&&"number"==typeof t.b&&void 0===t.c){const n=t;return e.comp.init(r(n.a),r(n.b))}if(t&&"number"==typeof t.a&&"number"==typeof t.b&&"number"==typeof t.c&&"number"==typeof t.d){const n=t;return e.quat.init(r(n.a),r(n.b),r(n.c),r(n.d))}if(t&&"number"==typeof t.x&&"number"==typeof t.y){const n=t;return"number"==typeof n.w&&"number"==typeof n.z?e.vect.init(r(n.x),r(n.y),r(n.z),r(n.w)):"number"==typeof n.z?e.vect.init(r(n.x),r(n.y),r(n.z)):e.vect.init(r(n.x),r(n.y))}if(Array.isArray(t)){let n=!0;for(let e=0;e<t.length;e++)if(!Array.isArray(t[e])||t[e].length>0&&"number"!=typeof t[e][0]){n=!1;break}if(n){const n=t,o=e.matr.rows(n),i=e.matr.cols(n),a=e.matr.fill(0,o,i);for(let e=0;e<o;e++)for(let t=0;t<i;t++)a[e][t]=r(n[e][t]);return a}{const n=[];for(let o=0;o<t.length;o++)n.push(e.APPLY(t[o],r));return n}}if("number"==typeof t)return r(t);if(t&&"function"==typeof t.contains&&void 0===t.set){const e=t;if(Array.isArray(e.elements)){const t=[];for(let n=0;n<e.elements.length;n++)t.push(r(e.elements[n]));return t}throw new TypeError('Chalkboard.APPLY cannot operate on an infinite "ChalkboardSet".')}if(t&&"function"==typeof t.set?.contains){const e=t;if(Array.isArray(e.set.elements)){const t=[];for(let n=0;n<e.set.elements.length;n++)t.push(r(e.set.elements[n]));return t}throw new TypeError('Chalkboard.APPLY cannot operate on an infinite "ChalkboardStructure".')}throw new TypeError('Chalkboard.APPLY can only operate on a "ChalkboardComplex", "ChalkboardMatrix", "ChalkboardQuaternion", "ChalkboardTensor", "ChalkboardVector", "ChalkboardSet", or "ChalkboardStructure".')},e.CONTEXT="undefined"!=typeof window?"ctx":"0",e.E=(e=1)=>{if(0===e)return 1;if(1===e)return 2.718281828459045;const t=Math.round(1.4426950408889634*e),r=e-.6931471805599453*t,n=r*r,o=n*r,i=o*r,a=i*r,s=a*r,l=s*r,u=l*r,m=u*r;return(1+r+n/2+o/6+i/24+a/120+s/720+l/5040+u/40320+m/362880+m*r/3628800)*2**t},e.I=(t=1)=>t%4==0?e.comp.init(1,0):t%4==1?e.comp.init(0,1):t%4==2?e.comp.init(-1,0):t%4==3?e.comp.init(0,-1):e.comp.init(0,0),e.PI=(e=1)=>{let t=1,r=Math.sqrt(.5),n=.25,o=1,i=.5*(t+r),a=Math.sqrt(t*r);return n-=o*(t-i)*(t-i),t=i,r=a,o*=2,i=.5*(t+r),a=Math.sqrt(t*r),n-=o*(t-i)*(t-i),t=i,r=a,o*=2,i=.5*(t+r),a=Math.sqrt(t*r),n-=o*(t-i)*(t-i),t=i,r=a,o*=2,i=.5*(t+r),a=Math.sqrt(t*r),n-=o*(t-i)*(t-i),t=i,r=a,e*((t+r)*(t+r)/(4*n))},e.REGISTER=(t,r)=>{e.REGISTRY[t]=r},e.REGISTRY={},e.VERSION="3.0.1",e.VERSIONALIAS="Euler"}(Chalkboard||(Chalkboard={})),"undefined"==typeof window?module.exports=Chalkboard:window.Chalkboard=Chalkboard,function(e){let t;!function(t){const r=JSON.stringify;t.A=t=>{if(!Number.isInteger(t)||t<=0)throw new Error('The parameter "n" must be a positive integer.');const n=(e.abal.S(t).elements||[]).filter(e=>{let t=0;for(let r=0;r<e.length;r++)for(let n=r+1;n<e.length;n++)e[r]>e[n]&&t++;return t%2==0});return{contains:e=>n.some(t=>r(t)===r(e)),elements:n,id:`A${t}`}},t.automorphism=(t,r)=>{const n=e.abal.homomorphism(t,t,r);if(!e.abal.isHomomorphism(n))throw new Error("The mapping is not a homomorphism, so it cannot be an automorphism.");if(!e.abal.isBijective(n))throw new Error("The mapping is not bijective, so it cannot be an automorphism.");return n},t.C=t=>{if(void 0===t)return{contains:e=>"number"==typeof e.a&&"number"==typeof e.b,id:"C"};{if(!Number.isInteger(t)||t<=0)throw new Error('The parameter "n" must be a positive integer.');const r=[];for(let n=0;n<t;n++){const o=2*Math.PI*n/t;r.push(e.comp.init(e.numb.roundTo(Math.cos(o),1e-4),e.numb.roundTo(Math.sin(o),1e-4)))}return{contains:e=>r.some(t=>t.a===e.a&&t.b===e.b),elements:r,id:`C${t}`}}},t.cardinality=e=>{const t="set"in e&&e.set?e.set.id:"id"in e?e.id:void 0;if(t?.startsWith("M(")||t?.startsWith("GL")||["Z","Q","R","C","P"].includes(t||""))return 1/0;if("elements"in e&&e.elements)return e.elements.length;if("set"in e&&e.set.elements)return e.set.elements.length;throw new Error("The inputted structure does not have a finite cardinality or is missing elements.")},t.Cartesian=(t,r)=>{const n=[];for(const e of t.elements||[])for(const t of r.elements||[])n.push([e,t]);return e.abal.set(n)},t.Cayley=(t,r="add")=>{if(!t.set.elements)throw new Error("The structure must have a finite set of elements.");const n=t.set.elements;if("operation"in t&&t.operation){if("add"===r){let r=e.matr.fill(0,n.length);for(let e=0;e<n.length;e++)for(let o=0;o<n.length;o++)r[e][o]=t.operation(n[e],n[o]);return r}throw new Error('The "type" parameter for groups should remain as the default "add" since there is no distinction between their additive and multiplicative Cayley tables.')}if("add"in t&&t.add&&"mul"in t&&t.mul){if("add"===r){let r=e.matr.fill(0,n.length);for(let e=0;e<n.length;e++)for(let o=0;o<n.length;o++)r[e][o]=t.add(n[e],n[o]);return r}let o=e.matr.fill(0,n.length);for(let e=0;e<n.length;e++)for(let r=0;r<n.length;r++)o[e][r]=t.mul(n[e],n[r]);return o}throw new Error("Invalid algebraic structure for Cayley table.")},t.center=t=>{const{set:r,operation:n}=t;if(!r.elements||!n)return e.abal.set([]);const o=r.elements.filter(e=>(r.elements??[]).every(t=>n(e,t)===n(t,e)));return e.abal.set(o)},t.complement=(t,r)=>e.abal.set((r.elements||[]).filter(e=>!t.contains(e))),t.compose=(t,r)=>{if(!e.abal.isHomomorphism(t)||!e.abal.isHomomorphism(r))throw new Error("Both morphisms of the morphism composition must be homomorphisms.");if(!e.abal.isEqual(t.struc2,r.struc1))throw new Error("The codomain of the first morphism and the domain of the second morphism must be equal to calculate the composition morphism.");return e.abal.homomorphism(t.struc1,r.struc2,e=>r.mapping(t.mapping(e)))},t.copy=t=>{if((r=t)&&"function"==typeof r.contains&&!r.set&&!r.struc1&&!r.base){return{contains:t.contains,...t.id&&{id:t.id},...t.elements&&{elements:[...t.elements]}}}var r;if((e=>e&&e.set&&(e.operation||e.add||e.mul))(t)){return{set:e.abal.copy(t.set),...t.operation&&{operation:t.operation},...void 0!==t.identity&&{identity:t.identity},...t.inverter&&{inverter:t.inverter},...t.add&&{add:t.add},...t.mul&&{mul:t.mul},...void 0!==t.addIdentity&&{addIdentity:t.addIdentity},...void 0!==t.mulIdentity&&{mulIdentity:t.mulIdentity},...t.addInverter&&{addInverter:t.addInverter},...t.mulInverter&&{mulInverter:t.mulInverter}}}if((e=>e&&e.base&&e.extension&&"number"==typeof e.degree)(t)){return{base:e.abal.copy(t.base),extension:e.abal.copy(t.extension),degree:t.degree,basis:t.basis?[...t.basis]:[],isFinite:t.isFinite,isSimple:t.isSimple,isAlgebraic:t.isAlgebraic}}if((e=>e&&e.struc1&&e.struc2&&"function"==typeof e.mapping)(t)){return{struc1:e.abal.copy(t.struc1),struc2:e.abal.copy(t.struc2),mapping:t.mapping}}throw new Error('The "struc" must be a set, structure, structure extension, or morphism.')},t.coset=(t,n)=>{if("operation"in t&&!e.abal.isSubgroup(t,n.set))throw new Error('The "substruc" must be a subgroup of the "struc".');if("add"in t&&!e.abal.isIdeal(t,n.set))throw new Error('The "substruc" must be an ideal of the "struc".');const o=e.abal.toArray(t.set),i=e.abal.toArray(n.set),a=new Map;return o.forEach(n=>{const o=i.map(e=>"operation"in t?t.operation(n,e):t.add(n,e)),s=[...o].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:r(e).localeCompare(r(t))),l=r(s);if(!a.has(l)){const t=e.abal.set(o);a.set(l,t)}}),e.abal.set(Array.from(a.values()))},t.cyclicSubgroup=(t,r)=>{if(t.set.id&&["Z","Q","R","C"].includes(t.set.id))throw new Error('The "group" must be finite.');const n=[];let o=r;if(!t.operation)return e.abal.set([]);do{n.push(o),o=t.operation(o,r)}while(!n.includes(o));return e.abal.set(n)},t.D=e=>{if(!Number.isInteger(e)||e<=0)throw new Error('The parameter "n" must be a positive integer.');const t=[];for(let r=0;r<e;r++)t.push(`r${r}`);for(let r=0;r<e;r++)t.push(`s${r}`);return{contains:e=>t.includes(e),elements:t,id:`D${e}`}},t.difference=(t,r)=>{const n=(t.elements||[]).filter(e=>!r.contains(e));return e.abal.set(n)},t.direct=(t,r,n="product")=>{const o=e.abal.Cartesian(t.set,r.set),i=(e,n)=>[t.add(e[0],n[0]),r.add(e[1],n[1])],a=(e,n)=>[t.mul(e[0],n[0]),r.mul(e[1],n[1])],s=[t.addIdentity,r.addIdentity],l=[t.mulIdentity,r.mulIdentity],u=e=>[t.addInverter(e[0]),r.addInverter(e[1])],m=e=>[t.mulInverter(e[0]),r.mulInverter(e[1])];if("operation"in t&&"operation"in r){const i=(e,n)=>[t.operation(e[0],n[0]),r.operation(e[1],n[1])],a=[t.identity,r.identity];if("inverter"in t&&"inverter"in r){const s=e=>[t.inverter(e[0]),r.inverter(e[1])];if(!("sum"!==n||t.set.elements&&r.set.elements))throw new Error("Direct sum is only defined for finite groups.");return e.abal.group(o,i,a,s)}if(!("sum"!==n||t.set.elements&&r.set.elements))throw new Error("Direct sum is only defined for finite structures.");return e.abal.monoid(o,i,a)}if("add"in t&&"add"in r&&"mul"in t&&"mul"in r){if(!("sum"!==n||t.set.elements&&r.set.elements))throw new Error("Direct sum is only defined for finite rings.");return e.abal.ring(o,i,a,s,l,u)}if("add"in t&&"add"in r&&"mul"in t&&"mul"in r&&"mulInverter"in t&&"mulInverter"in r){if(!("sum"!==n||t.set.elements&&r.set.elements))throw new Error("Direct sum is only defined for finite fields.");return e.abal.field(o,i,a,s,l,u,m)}throw new Error("Invalid algebraic structures for direct product or sum.")},t.endomorphism=(t,r)=>{const n=e.abal.homomorphism(t,t,r);if(!e.abal.isHomomorphism(n))throw new Error("The mapping is not a homomorphism, so it cannot be an endomorphism.");return n},t.field=(t,r,n,o,i,a,s)=>{const l=void 0===o||void 0===i||void 0===a||void 0===s?(()=>{if(!t.id)throw new Error('The "set" must have a valid "id" property, or you must input "addIdentity", "mulIdentity", "addInverter", and "mulInverter" explicitly.');if("Q"===t.id||"R"===t.id)return{addIdentity:0,mulIdentity:1,addInverter:e=>-e,mulInverter:e=>1/e};if("C"===t.id)return{addIdentity:e.comp.init(0,0),mulIdentity:e.comp.init(1,0),addInverter:t=>e.comp.negate(t),mulInverter:t=>e.comp.invert(t)};throw new Error('Automatic configuration of the "addIdentity", "mulIdentity", "addInverter", and "mulInverter" properties is not available for the inputted "set".')})():{addIdentity:o,mulIdentity:i,addInverter:a,mulInverter:s},u={set:t,add:r,mul:n,addIdentity:l.addIdentity,mulIdentity:l.mulIdentity,addInverter:l.addInverter,mulInverter:l.mulInverter};if(!e.abal.isField(u))throw new Error('The inputted "set", "add", "mul", "addIdentity", "mulIdentity", "addInverter", and "mulInverter" do not form a field.');return u},t.fieldExtension=(t,r,n,o,i,a,s)=>{if(!e.abal.isSubfield(t,r.set))throw new Error('The "base" must be a subfield of the "extension".');const l=void 0===n||void 0===o||void 0===i||void 0===a||void 0===s?(()=>{if(!t.set.id)throw new Error('The "set" property of the "base" must have a valid "id" property, or you must input "degree", "basis", "isFinite", "isSimple", and "isAlgebraic" explicitly.');if("Q"===t.set.id&&"R"===r.set.id)return{degree:1/0,basis:[],isFinite:!1,isSimple:!1,isAlgebraic:!1};if("R"===t.set.id&&"C"===r.set.id)return{degree:2,basis:[e.vect.init(1,0),e.vect.init(0,1)],isFinite:!0,isSimple:!0,isAlgebraic:!0};throw new Error('Automatic configuration of the "degree", "basis", "isFinite", "isSimple", and "isAlgebraic" properties is not available for the inputted "base".')})():{degree:n,basis:o,isFinite:i,isSimple:a,isAlgebraic:s};return{base:t,extension:r,degree:l.degree,basis:l.basis,isFinite:l.isFinite,isSimple:l.isSimple,isAlgebraic:l.isAlgebraic}},t.GL=t=>({contains:r=>Array.isArray(r)&&e.matr.isSizeOf(r,t)&&e.matr.isInvertible(r),id:`GL${t}`}),t.group=(t,r,n,o)=>{const i=void 0===n||void 0===o?(()=>{if(!t.id)throw new Error('The "set" must have a valid "id" property, or you must input "identity" and "inverter" explicitly.');if("Z"===t.id||"Q"===t.id||"R"===t.id)return{identity:0,inverter:e=>-e};if("C"===t.id)return{identity:e.comp.init(0,0),inverter:t=>e.comp.negate(t)};if(t.id.startsWith("Z")&&t.id.length>1){const e=parseInt(t.id.slice(1),10);return{identity:0,inverter:t=>(e-t%e)%e}}if(t.id.startsWith("C")&&t.id.length>1)return{identity:e.comp.init(1,0),inverter:t=>e.comp.conjugate(t)};if(t.id.startsWith("M(")){const r=t.rows,n=t.cols;return{identity:e.matr.fill(0,r,n),inverter:t=>e.matr.negate(t)}}if(t.id.startsWith("GL")){const r=parseInt(t.id.slice(2),10);return{identity:e.matr.identity(r),inverter:t=>e.matr.invert(t)}}if(t.id.match(/^[SA]\d+$/)){const e=parseInt(t.id.slice(1),10);return{identity:Array.from({length:e},(e,t)=>t),inverter:e=>{const t=e,r=new Array(t.length);for(let e=0;e<t.length;e++)r[t[e]]=e;return r}}}throw new Error('Automatic configuration of the "identity" and "inverter" properties is not available for the inputted "set".')})():{identity:n,inverter:o},a={set:t,operation:r,identity:i.identity,inverter:i.inverter};if(!e.abal.isGroup(a))throw new Error('The inputted "set", "operation", "identity", and "inverter" do not form a group.');return a},t.homomorphism=(t,r,n)=>{const o={struc1:t,struc2:r,mapping:n};if(!e.abal.isHomomorphism(o))throw new Error('The inputted "struc1", "struc2", and "mapping" do not form a homomorphism.');return o},t.idmorphism=t=>e.abal.automorphism(t,e=>e),t.image=(t,n)=>{const{struc1:o,mapping:i}=t;if(!o.set.elements)throw new Error('The domain of the "morph" must have a finite set of elements to calculate the image.');const a=n||o.set;if(!a.elements)throw new Error('The domain of the "morph" or the subset of it must have a finite set of elements to calculate the image.');const s=a.elements.map(i),l=Array.from(new Set(s.map(e=>r(e)))).map(e=>JSON.parse(e));return e.abal.set(l)},t.intersection=(t,r)=>{const n=(t.elements||[]).filter(e=>r.contains(e));return e.abal.set(n)},t.invmorphism=t=>{if(t.struc1.set.id&&["Z","Q","R","C"].includes(t.struc1.set.id))throw new Error("Inverse morphisms cannot be defined for morphisms with infinite domains.");if(!e.abal.isIsomorphism(t))throw new Error("The morphism is not an isomorphism, so it does not have an inverse.");return e.abal.homomorphism(t.struc2,t.struc1,e=>{const n=t.struc1.set.elements||[];for(const o of n)if(r(t.mapping(o))===r(e))return o;throw new Error(`The inverse morphism failed to be defined because no element in the domain maps to the element "${r(e)}" in the codomain.`)})},t.isAutomorphism=t=>e.abal.isHomomorphism(t)&&e.abal.isEndomorphism(t)&&e.abal.isIsomorphism(t),t.isBijective=t=>["Z","Q","R","C"].includes(t.struc1.set.id||"")||["Z","Q","R","C"].includes(t.struc2.set.id||"")?t.struc1.set.id===t.struc2.set.id:e.abal.isInjective(t)&&e.abal.isSurjective(t),t.isClosed=(t,r)=>{if(t.id&&["Z","Q","R","C"].includes(t.id))return!0;if(t.id?.startsWith("M(")){if(r===e.matr.add)return!0;if(r===e.matr.mul){const e=t.id.match(/\d+/g)?.map(Number);if(e&&e.length>=2)return e[0]===e[1]}return!1}if("C"===t.id)return r===e.comp.add||r===e.comp.mul;if("object"==typeof t&&"elements"in t&&t.elements){for(const e of t.elements)for(const n of t.elements){const o=r(e,n);if(!t.contains(o))return!1}return!0}return!0},t.isCommutative=e=>{const{set:t}=e;if(t.id&&["Z","Q","R","C"].includes(t.id))return!0;if(!t.elements)return!1;if("operation"in e&&e.operation){const{operation:n}=e;for(const e of t.elements)for(const o of t.elements)if(r(n(e,o))!==r(n(o,e)))return!1;return!0}if("add"in e&&"mul"in e&&e.add&&e.mul){const{add:n,mul:o}=e;for(const e of t.elements)for(const o of t.elements)if(r(n(e,o))!==r(n(o,e)))return!1;if("mulIdentity"in e)for(const e of t.elements)for(const n of t.elements)if(r(o(e,n))!==r(o(n,e)))return!1;return!0}return!1},t.isCyclicSubgroup=(t,r)=>{if(!e.abal.isSubgroup(t,r)||!t.operation)return!1;const{operation:n}=t;for(const t of r.elements||[]){const o=[];let i=t;do{o.push(i),i=n(i,t)}while(!o.includes(i));const a=e.abal.set(o);if(e.abal.isSubset(r,a))return!0}return!1},t.isEmpty=e=>{const t="set"in e&&e.set?e.set.id:"id"in e?e.id:void 0;return"Z"!==t&&"Q"!==t&&"R"!==t&&"C"!==t&&!t?.startsWith("M(")&&("elements"in e&&e.elements?0===e.elements.length:!("set"in e)||!e.set.elements||0===e.set.elements.length)},t.isEndomorphism=t=>e.abal.isHomomorphism(t)&&e.abal.isEqual(t.struc1,t.struc2),t.isEqual=(t,r)=>{if(t.constructor!==r.constructor)return!1;if("elements"in t&&"elements"in r){if("id"in t&&"id"in r&&t.id===r.id)return!0;const e=t.elements||[],n=r.elements||[];return e.length===n.length&&(e.every(e=>r.contains(e))&&n.every(e=>t.contains(e)))}if("operation"in t&&"operation"in r){const n=t,o=r,i=e.abal.isEqual(n.set,o.set)&&n.identity===o.identity&&(n.operation===o.operation||n.operation.toString()===o.operation.toString());return"inverter"in n&&"inverter"in o?i&&(n.inverter===o.inverter||n.inverter.toString()===o.inverter.toString()):"inverter"in n=="inverter"in o&&i}if("add"in t&&"add"in r&&"mul"in t&&"mul"in r){const n=t,o=r;return e.abal.isEqual(n.set,o.set)&&n.addIdentity===o.addIdentity&&n.mulIdentity===o.mulIdentity&&(n.add===o.add||n.add.toString()===o.add.toString())&&(n.mul===o.mul||n.mul.toString()===o.mul.toString())&&(n.addInverter===o.addInverter||n.addInverter.toString()===o.addInverter.toString())}if("mulInverter"in t&&"mulInverter"in r){const n=t,o=r;return e.abal.isEqual(n.set,o.set)&&n.addIdentity===o.addIdentity&&n.mulIdentity===o.mulIdentity&&(n.add===o.add||n.add.toString()===o.add.toString())&&(n.mul===o.mul||n.mul.toString()===o.mul.toString())&&(n.addInverter===o.addInverter||n.addInverter.toString()===o.addInverter.toString())&&(n.mulInverter===o.mulInverter||n.mulInverter.toString()===o.mulInverter.toString())}if("mapping"in t&&"mapping"in r){const n=t,o=r;return e.abal.isEqual(n.struc1,o.struc1)&&e.abal.isEqual(n.struc2,o.struc2)&&(n.mapping===o.mapping||n.mapping.toString()===o.mapping.toString()||e.abal.isEqual(e.abal.image(n),e.abal.image(o))&&e.abal.isEqual(e.abal.preimage(n),e.abal.preimage(o))&&e.abal.isEqual(e.abal.kernel(n),e.abal.kernel(o)))}return!1},t.isExact=(t,r)=>e.abal.isEqual(e.abal.image(t),e.abal.kernel(r)),t.isField=t=>{const{set:n,add:o,mul:i,addIdentity:a,mulIdentity:s,addInverter:l,mulInverter:u}=t;if("Q"===n.id||"R"===n.id||"C"===n.id)return!0;if(void 0===o||void 0===i||void 0===a||void 0===s||void 0===l||void 0===u)return!1;const m={set:n,operation:o,identity:a,inverter:l};if(!e.abal.isGroup(m)||!e.abal.isCommutative(m))return!1;if(!e.abal.isClosed(n,i))return!1;for(const e of n.elements||[])for(const t of n.elements||[])for(const o of n.elements||[])if(r(i(i(e,t),o))!==r(i(e,i(t,o))))return!1;for(const e of n.elements||[])if(e!==a&&(!n.contains(u(e))||r(i(e,u(e)))!==r(s)))return!1;if(!e.abal.isCommutative(t))return!1;for(const e of t.set.elements||[])for(const n of t.set.elements||[])for(const o of t.set.elements||[])if(r(t.mul(e,t.add(n,o)))!==r(t.add(t.mul(e,n),t.mul(e,o))))return!1;return!0},t.isGroup=t=>{const{set:n,operation:o,identity:i,inverter:a}=t;if("Z"===n.id||"Q"===n.id||"R"===n.id||"C"===n.id||"GL"===n.id)return!0;if(void 0===n.elements)return!1;if(void 0===o||void 0===i||void 0===a)return!1;if(!e.abal.isClosed(n,o))return!1;for(const e of n.elements)if(r(o(e,i))!==r(e)||r(o(i,e))!==r(e))return!1;for(const e of n.elements)if(!n.contains(a(e))||r(o(e,a(e)))!==r(i))return!1;for(const e of n.elements)for(const t of n.elements)for(const i of n.elements)if(r(o(o(e,t),i))!==r(o(e,o(t,i))))return!1;return!0},t.isHomomorphism=e=>{const{struc1:t,struc2:n,mapping:o}=e;if("operation"in t&&"operation"in n&&t.operation&&n.operation){const{operation:e}=t,{operation:i}=n;for(const n of t.set.elements||[])for(const a of t.set.elements||[])if(r(i(o(n),o(a)))!==r(o(e(n,a))))return!1;return!0}if("add"in t&&"add"in n&&"mul"in t&&"mul"in n&&t.add&&n.add&&t.mul&&n.mul){const{add:e,mul:i}=t,{add:a,mul:s}=n;for(const n of t.set.elements||[])for(const l of t.set.elements||[]){if(r(a(o(n),o(l)))!==r(o(e(n,l))))return!1;if(r(s(o(n),o(l)))!==r(o(i(n,l))))return!1}return!0}throw new Error("The algebraic structures of the homomorphism may have missing operations or incompatible types.")},t.isIdeal=(t,r)=>{const{add:n,mul:o,addIdentity:i,addInverter:a}=t;if(void 0===n||void 0===o||void 0===i||void 0===a)return!1;if(!e.abal.isClosed(r,n))return!1;if(!r.contains(i))return!1;for(const e of r.elements||[])if(!r.contains(a(e)))return!1;for(const e of t.set.elements||[])for(const t of r.elements||[])if(!r.contains(o(e,t))||!r.contains(o(t,e)))return!1;return!0},t.isIdentity=(e,t,r="add")=>"add"===r&&e.add&&e.addIdentity?"add"in e&&e.add(t,e.addIdentity)===t&&e.add(e.addIdentity,t)===t:!("mul"!==r||!e.mul||!e.mulIdentity)&&("mul"in e&&"mulIdentity"in e&&e.mul?.(t,e.mulIdentity)===t&&e.mul?.(e.mulIdentity,t)===t),t.isInjective=e=>{if(["Z","Q","R","C"].includes(e.struc1.set.id||"")||["Z","Q","R","C"].includes(e.struc2.set.id||""))return e.struc1.set.id===e.struc2.set.id;const{struc1:t,mapping:n}=e,o=t.set.elements||[],i=o.map(n);return new Set(i.map(e=>r(e))).size===o.length},t.isInverse=(e,t,r,n="add")=>"add"===n?"add"in e&&e.add?.(t,r)===e.addIdentity&&e.add?.(r,t)===e.addIdentity:"mul"===n&&"mul"in e&&"mulIdentity"in e&&(e.mul?.(t,r)===e.mulIdentity&&e.mul?.(r,t)===e.mulIdentity),t.isIsomorphism=t=>e.abal.isHomomorphism(t)&&e.abal.isBijective(t),t.isMonoid=t=>{const{set:n,operation:o,identity:i}=t;if("Z"===n.id||"Q"===n.id||"R"===n.id||"C"===n.id||"GL"===n.id)return!0;if(void 0===n.elements)return!1;if(void 0===o||void 0===i)return!1;if(!e.abal.isClosed(n,o))return!1;for(const e of n.elements)if(r(o(e,i))!==r(e)||r(o(i,e))!==r(e))return!1;for(const e of n.elements)for(const t of n.elements)for(const i of n.elements)if(r(o(o(e,t),i))!==r(o(e,o(t,i))))return!1;return!0},t.isNormalSubgroup=(t,r)=>{const{set:n,operation:o,inverter:i}=t;if(!o||!i)return!1;if(!e.abal.isSubgroup(t,r))return!1;for(const e of n.elements||[])for(const t of r.elements||[]){const n=o(o(e,t),i(e));if(!r.contains(n))return!1}return!0},t.isomorphism=(t,r,n)=>{const o=e.abal.homomorphism(t,r,n);if(!e.abal.isHomomorphism(o))throw new Error("The mapping is not a homomorphism, so it cannot be an isomorphism.");if(!e.abal.isBijective(o))throw new Error("The mapping is not bijective, so it cannot be an isomorphism.");return o},t.isPrincipalIdeal=(t,r)=>{for(const n of r.elements||[]){const o=e.abal.principalIdeal(t,n);if(e.abal.isSubset(r,o)&&e.abal.isSubset(o,r))return!0}return!1},t.isRing=t=>{const{set:n,add:o,mul:i,addIdentity:a,addInverter:s}=t;if("Z"===n.id||"Q"===n.id||"R"===n.id||"C"===n.id)return!0;if(void 0===o||void 0===i||void 0===a||void 0===s)return!1;const l={set:n,operation:o,identity:a,inverter:s};if(!e.abal.isGroup(l)||!e.abal.isCommutative(l))return!1;if(!e.abal.isClosed(n,i))return!1;for(const e of n.elements||[])for(const t of n.elements||[])for(const o of n.elements||[])if(r(i(i(e,t),o))!==r(i(e,i(t,o))))return!1;return!0},t.isSubfield=(t,n)=>{const{add:o,mul:i,addIdentity:a,mulIdentity:s,addInverter:l,mulInverter:u}=t;if(t.set.id&&n.id){if(n.id===t.set.id&&["Q","R","C"].includes(n.id))return!0;if("Q"===n.id&&["R","C"].includes(t.set.id))return!0;if("R"===n.id&&"C"===t.set.id)return!0;if("Z"===n.id)return!1}if(void 0===o||void 0===i||void 0===a||void 0===s||void 0===l||void 0===u)return!1;if(!n.contains(a)||!n.contains(s))return!1;if(!e.abal.isClosed(n,o)||!e.abal.isClosed(n,i))return!1;for(const e of n.elements||[])if(!n.contains(l(e)))return!1;for(const e of n.elements||[])if(r(e)!==r(a)&&!n.contains(u(e)))return!1;return!0},t.isSubgroup=(t,r)=>{const{operation:n,identity:o,inverter:i}=t;if(t.set.id&&r.id){if("Z"===r.id&&["Z","Q","R","C"].includes(t.set.id))return!0;if("Q"===r.id&&["Q","R","C"].includes(t.set.id))return!0;if("R"===r.id&&["R","C"].includes(t.set.id))return!0;if("C"===r.id&&"C"===t.set.id)return!0;if(r.id.startsWith("Z")&&t.set.id.startsWith("Z")){const e=parseInt(r.id.slice(1),10),n=parseInt(t.set.id.slice(1),10);if(!isNaN(e)&&!isNaN(n))return n%e===0}if(r.id?.startsWith("GL")&&r.id===t.set.id)return!0}if(void 0===n||void 0===o||void 0===i)return!1;if(!r.contains(o))return!1;if(!e.abal.isClosed(r,n))return!1;for(const e of r.elements||[])if(!r.contains(i(e)))return!1;return!0},t.isSubmonoid=(t,r)=>{const{operation:n,identity:o}=t;if(t.set.id&&r.id){if(r.id===t.set.id)return!0;if("Z"===r.id&&["Z","Q","R","C"].includes(t.set.id))return!0;if("Q"===r.id&&["Q","R","C"].includes(t.set.id))return!0;if("R"===r.id&&["R","C"].includes(t.set.id))return!0}return void 0!==n&&void 0!==o&&(!!r.contains(o)&&!!e.abal.isClosed(r,n))},t.isSubring=(t,r)=>{const{add:n,mul:o,addIdentity:i,addInverter:a}=t;if(t.set.id&&r.id){if(r.id===t.set.id)return!0;if("Z"===r.id&&["Z","Q","R","C"].includes(t.set.id))return!0;if("Q"===r.id&&["Q","R","C"].includes(t.set.id))return!0;if("R"===r.id&&["R","C"].includes(t.set.id))return!0;if(r.id.startsWith("Z")&&t.set.id.startsWith("Z")){const e=parseInt(r.id.slice(1),10),n=parseInt(t.set.id.slice(1),10);if(!isNaN(e)&&!isNaN(n))return n%e===0}}if(void 0===n||void 0===o||void 0===i||void 0===a)return!1;if(!r.contains(i))return!1;if(!e.abal.isClosed(r,n)||!e.abal.isClosed(r,o))return!1;for(const e of r.elements||[])if(!r.contains(a(e)))return!1;return!0},t.isSubset=(e,t)=>{if(e.id&&t.id){if(e.id===t.id)return!0;if("Z"===e.id)return["Z","Q","R","C"].includes(t.id);if("Q"===e.id)return["Q","R","C"].includes(t.id);if("R"===e.id)return["R","C"].includes(t.id);if("N"===e.id)return["N","Z","Q","R","C"].includes(t.id);if(e.id.startsWith("Z")&&t.id.startsWith("Z")){const r=parseInt(e.id.slice(1),10),n=parseInt(t.id.slice(1),10);if(!isNaN(r)&&!isNaN(n))return n%r===0}}return(e.elements||[]).every(e=>t.contains(e))},t.isSuperset=(t,r)=>e.abal.isSubset(r,t),t.isSurjective=e=>{const{struc1:t,struc2:n,mapping:o}=e;if(["Z","Q","R","C","P"].includes(n.set.id||""))return!("C"!==n.set.id||!["R","C"].includes(t.set.id||""))||("R"!==n.set.id||"Q"!==t.set.id)&&t.set.id===n.set.id;const i=t.set.elements||[],a=n.set.elements||[],s=i.map(o);return a.every(e=>s.some(t=>r(t)===r(e)))},t.kernel=(t,n)=>{const{struc1:o,struc2:i,mapping:a}=t;if(!o.set.elements)throw new Error('The domain of the "morph" must have a finite set of elements to calculate the kernel.');const s=n?.elements||o.set.elements;let l;if("identity"in i)l=i.identity;else{if(!("addIdentity"in i))throw new Error('The codomain of the "morph" must have an identity element to calculate the kernel.');l=i.addIdentity}const u=s.filter(e=>r(a(e))===r(l));return e.abal.set(u)},t.Lagrange=(t,r)=>{if(t.set.id&&["Z","Q","R","C"].includes(t.set.id))throw new Error("Lagrange's Theorem only applies to finite groups");return e.abal.cardinality(t)%e.abal.cardinality(r)===0},t.M=(t,r=t)=>({contains:n=>Array.isArray(n)&&e.matr.isSizeOf(n,t,r),id:`M(${t}, ${r})`}),t.monoid=(t,r,n)=>{const o=void 0===n?(()=>{if(!t.id)throw new Error('The "set" must have a valid "id" property, or you must input "identity" explicitly.');if("Z"===t.id||"Q"===t.id||"R"===t.id)return{identity:0};if("C"===t.id)return{identity:e.comp.init(0,0)};if(t.id.startsWith("Z")&&t.id.length>1)return{identity:0};if(t.id.startsWith("C")&&t.id.length>1)return{identity:e.comp.init(1,0)};if(t.id.startsWith("M(")){const r=t.rows,n=t.cols;return{identity:e.matr.fill(0,r,n)}}if(t.id.startsWith("GL")){const r=parseInt(t.id.slice(2),10);return{identity:e.matr.identity(r)}}if(t.id.match(/^[SA]\d+$/)){const e=parseInt(t.id.slice(1),10);return{identity:Array.from({length:e},(e,t)=>t)}}throw new Error('Automatic configuration of the "identity" property is not available for the inputted "set".')})():{identity:n},i={set:t,operation:r,identity:o.identity};if(!e.abal.isMonoid(i))throw new Error('The inputted "set", "operation", and "identity" do not form a monoid.');return i},t.N=()=>({contains:e=>Number.isInteger(e)&&e>0,id:"N"}),t.order=(e,t)=>{if(!e.operation)throw new Error('The "group" must have an "operation" property to calculate the order of an element.');let n=1,o=t;for(;r(o)!==r(e.identity);)if(o=e.operation(o,t),n++,n>(e.set.elements?.length||1/0))throw new Error('The "group" might not be finite because an infinite loop was detected.');return n},t.P=()=>({contains:t=>e.numb.isPrime(t),id:"P"}),t.powerSet=t=>{const r=[],n=t.elements||[],o=1<<n.length;for(let t=0;t<o;t++){const o=[];for(let e=0;e<n.length;e++)t&1<<e&&o.push(n[e]);r.push(e.abal.set(o))}return e.abal.set(r)},t.preimage=(t,r)=>{const{struc1:n,struc2:o,mapping:i}=t;if(!n.set.elements)throw new Error('The domain of the "morph" must have a finite set of elements to calculate the preimage.');const a=r||o.set;if(!a.elements)throw new Error('The codomain of the "morph" or the subset of it must have a finite set of elements to calculate the preimage.');const s=n.set.elements.filter(e=>a.contains(i(e)));return e.abal.set(s)},t.principalIdeal=(t,r)=>{if(t.set.id&&["Z","Q","R","C"].includes(t.set.id))throw new Error('The "ring" must be finite.');const n=[],{mul:o,add:i}=t;if(!i||!o)throw new Error('The "ring" must have "mul" and "add" properties to generate a principal ideal.');for(const e of t.set.elements||[]){const t=o(r,e),i=o(e,r);n.includes(t)||n.push(t),n.includes(i)||n.push(i)}for(let e=0;e<n.length;e++)for(let t=0;t<n.length;t++){const r=i(n[e],n[t]);n.includes(r)||n.push(r)}return e.abal.set(n)},t.print=t=>{console.log(e.abal.toString(t))},t.Q=()=>({contains:t=>Number.isFinite(t)&&e.numb.isRational(t),id:"Q"}),t.quotient=(t,r)=>{if("operation"in t&&!e.abal.isNormalSubgroup(t,r.set))throw new Error('The "substruc" must be a normal subgroup of the "struc".');if("add"in t&&!e.abal.isIdeal(t,r.set))throw new Error('The "substruc" must be an ideal of the "struc".');const n=e.abal.coset(t,r),o=(e,t,r)=>{const o=r(e.elements[0],t.elements[0]);return n.elements.find(e=>e.contains(o))};return{set:n,..."operation"in t?{operation:(e,r)=>o(e,r,t.operation),identity:n.elements.find(e=>e.contains(t.identity)),inverter:e=>o(e,e,e=>t.inverter(e))}:{add:(e,r)=>o(e,r,t.add),mul:(e,r)=>o(e,r,t.mul),addIdentity:n.elements.find(e=>e.contains(t.addIdentity)),addInverter:e=>o(e,e,e=>t.addInverter(e))}}},t.R=()=>({contains:e=>Number.isFinite(e),id:"R"}),t.ring=(t,r,n,o,i,a)=>{const s=void 0===o||void 0===i||void 0===a?(()=>{if(!t.id)throw new Error('The "set" must have a valid "id" property, or you must input "addIdentity", "mulIdentity", and "addInverter" explicitly.');if("Z"===t.id||"Q"===t.id||"R"===t.id)return{addIdentity:0,mulIdentity:1,addInverter:e=>-e};if("C"===t.id)return{addIdentity:e.comp.init(0,0),mulIdentity:e.comp.init(1,0),addInverter:t=>e.comp.negate(t)};if(t.id.startsWith("Z")&&t.id.length>1){const e=parseInt(t.id.slice(1),10);if(isNaN(e)||e<=0)throw new Error(`Invalid modulus in set "${t.id}".`);return{addIdentity:0,mulIdentity:1,addInverter:t=>(e-t%e)%e}}if(t.id.startsWith("M(")){const r=t.rows,n=t.cols;if(r!==n)throw new Error("Only square matrices can form a ring.");return{addIdentity:e.matr.fill(0,r,n),mulIdentity:e.matr.identity(r),addInverter:t=>e.matr.negate(t)}}throw new Error('Automatic configuration of the "addIdentity", "mulIdentity", and "addInverter" properties is not available for the inputted "set".')})():{addIdentity:o,mulIdentity:i,addInverter:a},l={set:t,add:r,mul:n,addIdentity:s.addIdentity,mulIdentity:s.mulIdentity,addInverter:s.addInverter};if(!e.abal.isRing(l))throw new Error('The inputted "set", "add", "mul", "addIdentity", "mulIdentity", and "addInverter" do not form a ring.');return l},t.ringExtension=(t,r,n,o,i,a,s)=>{if(!e.abal.isSubring(t,r.set))throw new Error('The "base" must be a subring of the "extension".');const l=void 0===n||void 0===o||void 0===i||void 0===a||void 0===s?(()=>{if(!t.set.id)throw new Error('The "set" property of the "base" must have a valid "id" property, or you must input "degree", "basis", "isFinite", "isSimple", and "isAlgebraic" explicitly.');if("Z"===t.set.id&&"Q"===r.set.id)return{degree:1/0,basis:[],isFinite:!1,isSimple:!1,isAlgebraic:!1};if("Q"===t.set.id&&"R"===r.set.id)return{degree:1/0,basis:[],isFinite:!1,isSimple:!1,isAlgebraic:!1};if("R"===t.set.id&&"C"===r.set.id)return{degree:2,basis:[e.vect.init(1,0),e.vect.init(0,1)],isFinite:!0,isSimple:!0,isAlgebraic:!0};throw new Error('Automatic configuration of the "degree", "basis", "isFinite", "isSimple", and "isAlgebraic" properties is not available for the inputted "base".')})():{degree:n,basis:o,isFinite:i,isSimple:a,isAlgebraic:s};return{base:t,extension:r,degree:l.degree,basis:l.basis,isFinite:l.isFinite,isSimple:l.isSimple,isAlgebraic:l.isAlgebraic}},t.S=e=>{if(!Number.isInteger(e)||e<=0)throw new Error('The parameter "n" must be a positive integer.');const t=e=>{if(0===e.length)return[[]];const r=[];for(let n=0;n<e.length;n++){const o=[...e.slice(0,n),...e.slice(n+1)],i=t(o);for(const t of i)r.push([e[n],...t])}return r},n=t(Array.from({length:e},(e,t)=>t));return{contains:e=>n.some(t=>r(t)===r(e)),elements:n,id:`S${e}`}},t.set=t=>{const n=e.stat.unique(t);return{contains:e=>n.some(t=>r(t)===r(e)),elements:n}},t.symmetricDifference=(t,r)=>{const n=e.abal.difference(t,r).elements||[],o=e.abal.difference(r,t).elements||[];return e.abal.set([...n,...o])},t.toArray=e=>{const t="set"in e?e.set:e;if(!t.elements)throw new Error("Cannot convert infinite set to array.");return[...t.elements]},t.toMatrix=(t,r,n=r)=>{const o="set"in t?t.set:t;if(!o.elements)throw new Error("Cannot convert infinite set to matrix.");return e.stat.toMatrix(o.elements,r,n)},t.toObject=t=>{const r="set"in t?t.set:t;if(!r.elements)throw new Error("Cannot convert infinite set to object.");return e.stat.toObject(r.elements)},t.toString=t=>{const r="set"in t?t.set:t;if(!r.elements)throw new Error("Cannot convert infinite set to string.");return e.stat.toString(r.elements)},t.toTensor=(t,...r)=>{const n="set"in t?t.set:t;if(!n.elements)throw new Error("Cannot convert infinite set to tensor.");return Array.isArray(r[0])&&(r=r[0]),e.tens.resize(n.elements,...r)},t.toTypedArray=(t,r="float32")=>{const n="set"in t?t.set:t;if(!n.elements)throw new Error("Cannot convert infinite set to typed array.");const o=e.abal.toArray(n);if("int8"===r)return new Int8Array(o);if("int16"===r)return new Int16Array(o);if("int32"===r)return new Int32Array(o);if("float32"===r)return new Float32Array(o);if("float64"===r)return new Float64Array(o);if("bigint64"===r)return new BigInt64Array(o.map(e=>BigInt(Math.floor(e))));throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".')},t.toVector=(t,r,n=0)=>{const o="set"in t?t.set.elements:t.elements;if(!o)throw new Error("Cannot convert infinite set to vector.");if(2===r)return e.vect.init(o[n],o[n+1]);if(3===r)return e.vect.init(o[n],o[n+1],o[n+2]);if(4===r)return e.vect.init(o[n],o[n+1],o[n+2],o[n+3]);throw new RangeError('Parameter "dimension" must be 2, 3, or 4.')},t.union=(t,r)=>{const n=Array.from(new Set([...t.elements||[],...r.elements||[]]));return e.abal.set(n)},t.Z=e=>{if(void 0===e)return{contains:e=>Number.isInteger(e),id:"Z"};if(!Number.isInteger(e)||e<=0)throw new Error('The modulus "n" must be a positive integer.');return{contains:t=>Number.isInteger(t)&&t>=0&&t<e,elements:Array.from({length:e},(e,t)=>t),id:`Z${e}`}}}(t=e.abal||(e.abal={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){const r=e=>"boolean"===n?e:e?1:0;t.AND=(...e)=>{let t=!0;for(let r=0;r<e.length;r++){if(!(!0===e[r]||1===e[r])){t=!1;break}}return r(t)},t.BICOND=(...e)=>{if(0===e.length)return r(!0);const t=!0===e[0]||1===e[0];for(let n=1;n<e.length;n++){if(t!==(!0===e[n]||1===e[n]))return r(!1)}return r(!0)},t.COND=(...e)=>{if(e.length<2)return r(!0);for(let t=0;t<e.length-1;t++){const n=!0===e[t]||1===e[t],o=!0===e[t+1]||1===e[t+1];if(n&&!o)return r(!1)}return r(!0)},t.CONV=(...e)=>{if(e.length<2)return r(!0);for(let t=0;t<e.length-1;t++){const n=!0===e[t]||1===e[t];if((!0===e[t+1]||1===e[t+1])&&!n)return r(!1)}return r(!0)},t.isEqual=(t,n)=>{const o=[],i=t=>{const r=e.bool.parse(t,{returnAST:!0}),n=e=>{"var"!==e.type||o.includes(e.name)?"not"===e.type?n(e.expr):"and"!==e.type&&"or"!==e.type||(n(e.left),n(e.right)):o.push(e.name)};n(r)};i(t),i(n);const a=(e,t=0,r={})=>{if(t>=e.length)return[r];const n={...r,[e[t]]:!0},o={...r,[e[t]]:!1};return[...a(e,t+1,n),...a(e,t+1,o)]},s=a(o);for(const o of s){if(e.bool.parse(t,{values:o})!==e.bool.parse(n,{values:o}))return r(!1)}return r(!0)},t.Karnaugh=(t,n)=>{const o=n.length;if(2!==o&&3!==o&&4!==o)throw new Error("Chalkboard.bool.Karnaugh only supports 2, 3, or 4 variables.");let i,a,s,l;const u=e=>{if(0===e)return[""];const t=u(e-1),r=[];for(let e of t)r.push("0"+e);for(let e of t.slice().reverse())r.push("1"+e);return r};2===o?(i=[n[0]],a=[n[1]],s=u(1),l=u(1)):3===o?(i=[n[0]],a=n.slice(1),s=u(1),l=u(2)):(i=n.slice(0,2),a=n.slice(2),s=u(2),l=u(2));const m=[];for(let n of s){const o=[];for(let s of l){const l={};for(let e=0;e<i.length;e++)l[i[e]]="1"===n[e];for(let e=0;e<a.length;e++)l[a[e]]="1"===s[e];const u=e.bool.parse(t,{values:l}),m=!0===u||1===u;o.push(r(m))}m.push(o)}return m},t.mapping=(t,n)=>{if(t.length!==n.length)throw new Error('Parameter "inputs" and "outputs" must have the same length.');if(0===t.length)throw new Error('Parameter "inputs" and "outputs" cannot be empty.');const o=t[0].length,i=n[0].length;for(const e of t)if(e.length!==o)throw new Error('Parameter "inputs" must have the same length for each row.');for(const e of n)if(e.length!==i)throw new Error('Parameter "outputs" must have the same length for each row.');const a=Array.from({length:o},(e,t)=>String.fromCharCode(97+t)),s=[];for(let r=0;r<i;r++){const i=[];for(let e=0;e<t.length;e++)!0!==n[e][r]&&1!==n[e][r]||i.push(e);if(0===i.length){s.push("false");continue}if(i.length===t.length){s.push("true");continue}const l=[];for(const e of i){const r=[];for(let n=0;n<o;n++){const o=!0===t[e][n]||1===t[e][n];r.push(o?a[n]:`!${a[n]}`)}l.push(`(${r.join(" & ")})`)}const u=l.join(" | ");o<=4?s.push(e.bool.minimize(u,a)):s.push(u)}return(...t)=>{if(t.length!==o)throw new Error(`Expected ${o} arguments, but got ${t.length}.`);const n={};for(let e=0;e<o;e++)n[a[e]]=t[e];return s.map(t=>{const o=e.bool.parse(t,{values:n});return r(!0===o||1===o)})}},t.minimize=(t,r)=>{if(0===r.length){return e.bool.parse(t)?"true":"false"}if(2!==r.length&&3!==r.length&&4!==r.length)throw new Error("Chalkboard.bool.minimize only supports 2, 3, or 4 variables.");try{const n=e.bool.primeImplicants(t,r);return 0===n.length?"false":n.some(e=>"true"===e)?"true":e.bool.parse(n.join(" | "))}catch(e){throw e instanceof Error?new Error(`Error minimizing expression: ${e.message}`):new Error(`Error minimizing expression: ${String(e)}`)}};let n="boolean";t.modeConfig=e=>{const t=e.toLowerCase();if("boolean"!==t&&"binary"!==t)throw new Error('The mode must be either "boolean" or "binary".');n=t},t.NAND=(...e)=>{const n=t.AND(...e);return r(!(!0===n||1===n))},t.NBICOND=(...e)=>{const n=t.BICOND(...e);return r(!(!0===n||1===n))},t.NCOND=(...e)=>{if(e.length<2)return r(!1);for(let t=0;t<e.length-1;t++){const n=!0===e[t]||1===e[t],o=!0===e[t+1]||1===e[t+1];if(!n||o)return r(!1)}return r(!0)},t.NCONV=(...e)=>{if(e.length<2)return r(!1);for(let t=0;t<e.length-1;t++){const n=!0===e[t]||1===e[t];if(!(!0===e[t+1]||1===e[t+1])||n)return r(!1)}return r(!0)},t.NOR=(...e)=>{for(let t=0;t<e.length;t++){if(!0===e[t]||1===e[t])return r(!1)}return r(!0)},t.NOT=(...e)=>{if(0===e.length)return r(!0);let t=!0;for(let r=0;r<e.length;r++){const n=!0===e[r]||1===e[r];t=t&&!n}return r(t)},t.OR=(...e)=>{let t=!1;for(let r=0;r<e.length;r++){if(!0===e[r]||1===e[r]){t=!0;break}}return r(t)},t.parse=(e,t={returnAST:!1,returnJSON:!1,returnLaTeX:!1})=>{const n=e=>{const t=[];let r=0;for(;r<e.length;){const n=e[r];if(/\s/.test(n))r++;else if(-1!=="!&|()".indexOf(n))t.push(n),r++;else{let n="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)n+=e[r++];t.push(n)}}return t},o=e=>{let t=0;const r=()=>e[t],n=r=>{if(r&&e[t]!==r)throw new Error(`Expected token ${r} but found ${e[t]}`);return e[t++]},o=()=>i(),i=()=>{let e=a();for(;"|"===r();)n("|"),e={type:"or",left:e,right:a()};return e},a=()=>{let e=s();for(;"&"===r();)n("&"),e={type:"and",left:e,right:s()};return e},s=()=>"!"===r()?(n("!"),{type:"not",expr:s()}):l(),l=()=>{const e=r();if("("===e){n("(");const e=o();return n(")"),e}return"true"===e?(n(),{type:"bool",value:!0}):"false"===e?(n(),{type:"bool",value:!1}):(n(),{type:"var",name:e})},u=o();if(t<e.length)throw new Error("Unexpected tokens at end");return u},i=(e,t)=>{if(e.type!==t.type)return!1;switch(e.type){case"bool":return e.value===t.value;case"var":return e.name===t.name;case"not":return i(e.expr,t.expr);case"and":case"or":return i(e.left,t.left)&&i(e.right,t.right)}return!1},a=e=>{switch(e.type){case"bool":return e.value?"true":"false";case"var":return e.name;case"not":return`!${"var"===e.expr.type?a(e.expr):`(${a(e.expr)})`}`;case"and":return`${"or"===e.left.type?`(${a(e.left)})`:a(e.left)} & ${"or"===e.right.type?`(${a(e.right)})`:a(e.right)}`;case"or":return`${a(e.left)} | ${a(e.right)}`}return""},s=e=>{switch(e.type){case"bool":return e.value?"1":"0";case"var":return e.name;case"not":return`\\neg ${"var"===e.expr.type||"bool"===e.expr.type?s(e.expr):`\\left(${s(e.expr)}\\right)`}`;case"and":return`${"or"===e.left.type?`\\left(${s(e.left)}\\right)`:s(e.left)} \\land ${"or"===e.right.type?`\\left(${s(e.right)}\\right)`:s(e.right)}`;case"or":return`${"and"===e.left.type?`\\left(${s(e.left)}\\right)`:s(e.left)} \\lor ${"and"===e.right.type?`\\left(${s(e.right)}\\right)`:s(e.right)}`;default:throw new Error(`Chalkboard.bool.parse: Unknown node type ${e.type}`)}},l=e=>"and"===e.type?[...l(e.left),...l(e.right)]:[e],u=(e,t)=>!("not"!==e.type||"var"!==t.type||!i(e.expr,t))||!("not"!==t.type||"var"!==e.type||!i(t.expr,e)),m=e=>{switch(e.type){case"bool":case"var":return e;case"not":{const t=m(e.expr);return"not"===t.type?m(t.expr):"bool"===t.type?{type:"bool",value:!t.value}:{type:"not",expr:t}}case"and":{const t=m(e.left),r=m(e.right);return"bool"===t.type&&!1===t.value||"bool"===r.type&&!1===r.value?{type:"bool",value:!1}:"bool"===t.type&&!0===t.value?r:"bool"===r.type&&!0===r.value||i(t,r)?t:"not"===t.type&&i(t.expr,r)||"not"===r.type&&i(r.expr,t)?{type:"bool",value:!1}:{type:"and",left:t,right:r}}case"or":return(e=>{if("or"!==e.type)return e;const t=m(e.left),r=m(e.right);if(u(t,r))return{type:"bool",value:!0};if("bool"===t.type&&!0===t.value)return{type:"bool",value:!0};if("bool"===r.type&&!0===r.value)return{type:"bool",value:!0};if("bool"===t.type&&!1===t.value)return r;if("bool"===r.type&&!1===r.value)return t;const n="and"===t.type?l(t):[t],o="and"===r.type?l(r):[r],a=[];n.forEach(e=>{o.some(t=>i(e,t))&&!a.some(t=>i(t,e))&&a.push(e)});const s=n.filter(e=>!a.some(t=>i(t,e))),f=o.filter(e=>!a.some(t=>i(t,e)));if(1===s.length&&1===f.length&&u(s[0],f[0]))return 0===a.length?{type:"bool",value:!0}:a.reduce((e,t)=>({type:"and",left:e,right:t}));if(a.length>0){const e=e=>{const t=e.filter(e=>!a.some(t=>i(t,e)));return 0===t.length?{type:"bool",value:!0}:1===t.length?t[0]:t.reduce((e,t)=>({type:"and",left:e,right:t}))},t=e(n),r=e(o);let s;return s="bool"===t.type&&!0===t.value||"bool"===r.type&&!0===r.value?{type:"bool",value:!0}:{type:"or",left:t,right:r},a.reduce((e,t)=>({type:"and",left:e,right:t}),s)}return{type:"or",left:t,right:r}})(e)}return e},f=(e,t)=>{switch(e.type){case"bool":return e.value;case"var":{const r=e.name;if(!(r in t))throw new Error(`Variable "${r}" not defined in values`);const n=t[r];return!0===n||1===n}case"not":return!f(e.expr,t);case"and":return f(e.left,t)&&f(e.right,t);case"or":return f(e.left,t)||f(e.right,t)}throw new Error(`Unknown node type: ${e.type}`)};try{const i=o(n(e));if(t.returnAST)return i;if(t.returnJSON)return JSON.stringify(i);if(t.values&&Object.keys(t.values).length>0)return r(f(i,t.values));let l=m(i),u=o(n(a(l)));return l=m(u),l=m(l),t.returnLaTeX?s(l):a(l)}catch(e){throw e instanceof Error?new Error(`Error parsing expression: ${e.message}`):new Error(`Error parsing expression: ${String(e)}`)}},t.primeImplicants=(t,r)=>{if(2!==r.length&&3!==r.length&&4!==r.length)throw new Error("Chalkboard.bool.primeImplicants only supports 2, 3, or 4 variables.");const n=e.bool.Karnaugh(t,r),o=e=>{if(0===e)return[""];const t=o(e-1),r=[];for(let e of t)r.push("0"+e);for(let e of t.slice().reverse())r.push("1"+e);return r};let i,a,s,l;2===r.length?(i=1,a=1,s=[r[0]],l=[r[1]]):3===r.length?(i=1,a=2,s=[r[0]],l=r.slice(1)):(i=2,a=2,s=r.slice(0,2),l=r.slice(2));const u=o(i),m=o(a),f=[];for(let e=0;e<u.length;e++)for(let t=0;t<m.length;t++)!0!==n[e][t]&&1!==n[e][t]||f.push({row:e,col:t,rowcode:u[e],colcode:m[t]});const c=(e,t)=>{const r=e.row===u.length-1&&0===t.row||t.row===u.length-1&&0===e.row?1:Math.abs(e.row-t.row),n=e.col===m.length-1&&0===t.col||t.col===m.length-1&&0===e.col?1:Math.abs(e.col-t.col);return 1===r&&0===n||0===r&&1===n},p=e=>{const t=e.length;if(t&t-1)return!1;if(1===t)return!0;const r=new Set(e.map(e=>e.row)).size,n=new Set(e.map(e=>e.col)).size;if(!(t===(e.some(e=>0===e.row)&&e.some(e=>e.row===u.length-1)?1:r)*(e.some(e=>0===e.col)&&e.some(e=>e.col===m.length-1)?1:n)&&(1===t||2===t||4===t||8===t||16===t)))return!1;const o=new Set,i=[e[0]];for(o.add(`${e[0].row},${e[0].col}`);i.length>0;){const t=i.shift();for(const r of e){const e=`${r.row},${r.col}`;!o.has(e)&&c(t,r)&&(o.add(e),i.push(r))}}return o.size===t},d=(()=>{const t=[],n=e.stat.min([16,e.real.pow(2,r.length)]);for(const e of f)t.push({cells:[e],size:1,term:""});for(let e=2;e<=n;e*=2){const r=t.filter(t=>t.size===e/2);for(let n=0;n<r.length;n++)for(let o=n+1;o<r.length;o++){const i=r[n],a=r[o],s=[...i.cells,...a.cells];new Set(s.map(e=>`${e.row},${e.col}`)).size===e&&p(s)&&t.push({cells:s,size:e,term:""})}}return t})(),h=[];d.sort((e,t)=>t.size-e.size);const y=new Set;for(const e of d){e.cells.some(e=>!y.has(`${e.row},${e.col}`))&&(h.push(e),e.cells.forEach(e=>y.add(`${e.row},${e.col}`)))}return h.forEach(e=>{const t={};r.forEach(e=>{t[e]=!0});for(let r=0;r<s.length;r++){const n=s[r];new Set(e.cells.map(e=>e.rowcode[r])).size>1&&(t[n]=!1)}for(let r=0;r<l.length;r++){const n=l[r];new Set(e.cells.map(e=>e.colcode[r])).size>1&&(t[n]=!1)}const n=[];for(const[r,o]of Object.entries(t))if(o){const t=e.cells[0];let o;const i=s.indexOf(r);if(i>=0)o="1"===t.rowcode[i];else{const e=l.indexOf(r);o="1"===t.colcode[e]}n.push(o?r:`!${r}`)}e.term=n.length>0?n.join(" & "):"true"}),h.map(e=>e.term)},t.toCNF=t=>{const r=e.bool.parse(t);if(r.includes(" & ")&&!r.includes(" | "))return r;const n=e.bool.parse(t,{returnAST:!0}),o=e=>{switch(e.type){case"bool":case"var":return e;case"not":return"not"===e.expr.type?o(e.expr.expr):"and"===e.expr.type?o({type:"or",left:{type:"not",expr:e.expr.left},right:{type:"not",expr:e.expr.right}}):"or"===e.expr.type?o({type:"and",left:{type:"not",expr:e.expr.left},right:{type:"not",expr:e.expr.right}}):{type:"not",expr:o(e.expr)};case"and":return{type:"and",left:o(e.left),right:o(e.right)};case"or":const t=o(e.left),r=o(e.right);return"and"===r.type?o({type:"and",left:{type:"or",left:t,right:r.left},right:{type:"or",left:t,right:r.right}}):"and"===t.type?o({type:"and",left:{type:"or",left:t.left,right:r},right:{type:"or",left:t.right,right:r}}):{type:"or",left:t,right:r}}return e},i=o(n),a=e=>{switch(e.type){case"bool":return e.value?"true":"false";case"var":return e.name;case"not":return`!${"var"===e.expr.type?a(e.expr):`(${a(e.expr)})`}`;case"and":return`${a(e.left)} & ${a(e.right)}`;case"or":return`(${a(e.left)} | ${a(e.right)})`}return""};return a(i)},t.toDNF=t=>{const r=e.bool.parse(t);if(r.includes(" | ")&&!r.includes(" & "))return r;const n=e.bool.parse(t,{returnAST:!0}),o=e=>{switch(e.type){case"bool":case"var":return e;case"not":return"not"===e.expr.type?o(e.expr.expr):"and"===e.expr.type?o({type:"or",left:{type:"not",expr:e.expr.left},right:{type:"not",expr:e.expr.right}}):"or"===e.expr.type?o({type:"and",left:{type:"not",expr:e.expr.left},right:{type:"not",expr:e.expr.right}}):{type:"not",expr:o(e.expr)};case"or":return{type:"or",left:o(e.left),right:o(e.right)};case"and":const t=o(e.left),r=o(e.right);return"or"===r.type?o({type:"or",left:{type:"and",left:t,right:r.left},right:{type:"and",left:t,right:r.right}}):"or"===t.type?o({type:"or",left:{type:"and",left:t.left,right:r},right:{type:"and",left:t.right,right:r}}):{type:"and",left:t,right:r}}return e},i=o(n),a=e=>{switch(e.type){case"bool":return e.value?"true":"false";case"var":return e.name;case"not":return`!${"var"===e.expr.type?a(e.expr):`(${a(e.expr)})`}`;case"and":return`(${a(e.left)} & ${a(e.right)})`;case"or":return`${a(e.left)} | ${a(e.right)}`}return""};return a(i)},t.truthTable=(...e)=>{const t=[],n=[!1,!0];for(let o of n)for(let i of n){const n=[r(!0===o),r(!0===i)];for(let t of e){const e=t(o,i);n.push(r(!0===e||1===e))}t.push(n)}return t},t.XOR=(...e)=>{let t=0;for(let r=0;r<e.length;r++){(!0===e[r]||1===e[r])&&t++}return r(t%2==1)}}(t=e.bool||(e.bool={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){t.autocorrelation=(t,r)=>{if("real"!==t.field||"scalar2d"!==t.type)throw new TypeError("Chalkboard.calc.autocorrelation: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");return e.calc.correlation(t,t,r)},t.binormal=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.binormal: Property 'field' of 'func' must be 'real'.");if(t.type.startsWith("curve"))return e.vect.cross(e.calc.tangent(t,r),e.calc.normal(t,r));throw new TypeError("Chalkboard.real.binormal: Property 'type' of 'func' must be 'curve2d' or 'curve3d'.")},t.convolution=(t,r,n)=>{if("real"!==t.field||"real"!==r.field||"scalar2d"!==t.type||"scalar2d"!==r.type)throw new TypeError("Chalkboard.calc.convolution: Properties 'field' of 'func1' and 'func2' must be 'real' and properties 'type' of 'func1' and 'func2' must be 'scalar2d'.");const o=t.rule,i=r.rule;return e.calc.fxdx(e.real.define(e=>o(e)*i(n-e)),-100,100)},t.correlation=(t,r,n)=>{if("real"!==t.field||"real"!==r.field||"scalar2d"!==t.type||"scalar2d"!==r.type)throw new TypeError("Chalkboard.calc.correlation: Properties 'field' of 'func1' and 'func2' must be 'real' and properties 'type' of 'func1' and 'func2' must be 'scalar2d'.");const o=t.rule,i=r.rule;return e.calc.fxdx(e.real.define(e=>o(e)*i(n+e)),-100,100)},t.curl=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.curl: Property 'field' of 'vectfield' must be 'real'.");const n=t.rule,o=r,i=1e-9;if("vector2d"===t.type){const t=(n[0](o.x,o.y+i)-n[0](o.x,o.y))/i,r=(n[1](o.x+i,o.y)-n[1](o.x,o.y))/i;return e.vect.init(0,0,r-t)}if("vector3d"===t.type){const t=(n[0](o.x,o.y+i,o.z)-n[0](o.x,o.y,o.z))/i,r=(n[0](o.x,o.y,o.z+i)-n[0](o.x,o.y,o.z))/i,a=(n[1](o.x+i,o.y,o.z)-n[1](o.x,o.y,o.z))/i,s=(n[1](o.x,o.y,o.z+i)-n[1](o.x,o.y,o.z))/i,l=(n[2](o.x+i,o.y,o.z)-n[2](o.x,o.y,o.z))/i,u=(n[2](o.x,o.y+i,o.z)-n[2](o.x,o.y,o.z))/i;return e.vect.init(u-s,r-l,a-t)}throw new TypeError("Chalkboard.real.curl: Property 'type' of 'vectfield' must be 'vector2d' or 'vector3d'.")},t.curvature=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.curvature: Property 'field' of 'func' must be 'real'.");if("curve2d"===t.type){const n=e.calc.dfdx(t,r),o=e.calc.d2fdx2(t,r);return Math.abs(n.x*o.y-n.y*o.x)/Math.sqrt((n.x*n.x+n.y*n.y)*(n.x*n.x+n.y*n.y)*(n.x*n.x+n.y*n.y))}if("curve3d"===t.type)return e.vect.mag(e.calc.normal(t,r))/e.vect.mag(e.calc.dfdx(t,r));throw new TypeError("Chalkboard.real.curvature: Property 'type' of 'func' must be 'curve2d' or 'curve3d'.")},t.dfdv=(t,r,n)=>{if("real"!==t.field)throw new TypeError('Chalkboard.calc.dfdv: Property "field" of "func" must be "real".');if("scalar3d"===t.type){const o=e.calc.grad(t,r),i=e.vect.normalize(n);return e.vect.dot(o,i)}throw new TypeError("Chalkboard.real.dfdv: Property 'type' of 'func' must be 'scalar3d'.")},t.dfdx=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.dfdx: Property 'field' of 'func' must be 'real'.");const n=1e-9;if("scalar2d"===t.type){const e=t.rule;return(e(r+n)-e(r))/n}if("curve2d"===t.type){const o=t.rule;return e.vect.init((o[0](r+n)-o[0](r))/n,(o[1](r+n)-o[1](r))/n)}if("curve3d"===t.type){const o=t.rule;return e.vect.init((o[0](r+n)-o[0](r))/n,(o[1](r+n)-o[1](r))/n,(o[2](r+n)-o[2](r))/n)}throw new TypeError("Chalkboard.real.dfdx: Property 'type' of 'func' must be 'scalar2d', 'curve2d', or 'curve3d'.")},t.d2fdx2=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.d2fdx2: Property 'field' of 'func' must be 'real'.");const n=1e-5;if("scalar2d"===t.type){const e=t.rule;return(e(r+n)-2*e(r)+e(r-n))/(n*n)}if("curve2d"===t.type){const o=t.rule;return e.vect.init((o[0](r+n)-2*o[0](r)+o[0](r-n))/(n*n),(o[1](r+n)-2*o[1](r)+o[1](r-n))/(n*n))}if("curve3d"===t.type){const o=t.rule;return e.vect.init((o[0](r+n)-2*o[0](r)+o[0](r-n))/(n*n),(o[1](r+n)-2*o[1](r)+o[1](r-n))/(n*n),(o[2](r+n)-2*o[2](r)+o[2](r-n))/(n*n))}throw new TypeError("Chalkboard.real.d2fdx2: Property 'type' of 'func' must be 'scalar2d', 'curve2d', or 'curve3d'.")},t.dfdz=(t,r)=>{if("comp"!==t.field)throw new TypeError("Chalkboard.calc.dfdz: Property 'field' of 'func' must be 'comp'.");const n=1e-9;if("vector2d"===t.type){const o=t.rule,i=(o[0](r.a+n,r.b)-o[0](r.a,r.b))/n,a=(o[0](r.a,r.b+n)-o[0](r.a,r.b))/n,s=(o[1](r.a+n,r.b)-o[1](r.a,r.b))/n,l=(o[1](r.a,r.b+n)-o[1](r.a,r.b))/n;return[e.comp.init(i,s),e.comp.init(a,l)]}throw new TypeError("Chalkboard.real.dfdz: Property 'type' of 'func' must be 'vector2d'.")},t.d2fdz2=(t,r)=>{if("comp"!==t.field)throw new TypeError("Chalkboard.calc.d2fdz2: Property 'field' of 'func' must be 'comp'.");const n=1e-5;if("vector2d"===t.type){const o=t.rule,i=(o[0](r.a+n,r.b)-2*o[0](r.a,r.b)+o[0](r.a-n,r.b))/(n*n),a=(o[0](r.a,r.b+n)-2*o[0](r.a,r.b)+o[0](r.a,r.b-n))/(n*n),s=(o[1](r.a+n,r.b)-2*o[1](r.a,r.b)+o[1](r.a-n,r.b))/(n*n),l=(o[1](r.a,r.b+n)-2*o[1](r.a,r.b)+o[1](r.a,r.b-n))/(n*n);return[e.comp.init(i,s),e.comp.init(a,l)]}throw new TypeError("Chalkboard.real.d2fdz2: Property 'type' of 'func' must be 'vector2d'.")},t.dfrdt=(t,r,n)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.calc.dfrdt: Properties 'field' of 'func1' and 'func2' must be 'real'.");if("scalar3d"!==t.type)throw new TypeError("Chalkboard.calc.dfrdt: Property 'type' of 'func1' must be 'scalar3d'.");const o=e.calc.grad(t,e.real.val(r,n)),i=e.calc.dfdx(r,n);if("curve2d"===r.type)return o.x*i.x+o.y*i.y;if("curve3d"===r.type)return o.x*i.x+o.y*i.y+o.z*i.z;throw new TypeError("Chalkboard.calc.dfrdt: Property 'type' of 'func2' must be 'curve2d' or 'curve3d'.")},t.dft=t=>{if(!Array.isArray(t))throw new TypeError("Chalkboard.calc.dft: Parameter 'arr' must be an array.");const r=t.length,n=new Array(r);for(let o=0;o<r;o++){let i=0,a=0;for(let n=0;n<r;n++){const s=t[n],l="number"==typeof s?s:s.a,u="number"==typeof s?0:s.b,m=e.PI(2*o*n)/r,f=e.trig.cos(m),c=e.trig.sin(m);i+=l*f+u*c,a+=u*f-l*c}n[o]=e.comp.init(i,a)}return n},t.div=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.div: Property 'field' of 'vectfield' must be 'real'.");if("vector2d"===t.type||"vector3d"===t.type||"vector4d"===t.type)return e.matr.trace(e.calc.grad(t,r));throw new TypeError("Chalkboard.calc.div: Property 'type' of 'vectfield' must be 'vector2d', 'vector3d', or 'vector4d'.")},t.extrema=(t,r)=>{if("real"!==t.field||"scalar2d"!==t.type)throw new TypeError("Chalkboard.calc.extrema: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");const n=[];for(let o=r[0];o<=r[1];o++)0===Math.round(e.calc.dfdx(t,o))&&n.push(o);return n},t.fds=(t,r,n,o,i)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.fds: Property 'field' of 'func' must be 'real'.");let a,s,l=0;if("curve2d"===t.type||"curve3d"===t.type){const o=(n-r)/1e4;for(let i=r;i<=n;i+=o)a=e.calc.dfdx(t,i),l+=e.vect.mag(a);return l*o}if("surface3d"===t.type){const u=(n-r)/100,m=(i-o)/100;for(let f=o;f<=i;f+=m)for(let o=r;o<=n;o+=u)s=e.matr.toVector(e.calc.grad(t,e.vect.init(f,o)),3,0,0),a=e.matr.toVector(e.calc.grad(t,e.vect.init(f,o)),3,1,0),l+=e.vect.mag(e.vect.cross(s,a));return l*m*u}throw new TypeError("Chalkboard.calc.fds: Property 'type' of 'func' must be 'curve2d', 'curve3d', or 'surface3d'.")},t.fft=t=>{if(!Array.isArray(t))throw new TypeError("Chalkboard.calc.fft: Parameter 'arr' must be an array.");const r=t.length;if(!Number.isInteger(r)||r<=0)throw new TypeError("Chalkboard.calc.fft: Input length must be a positive integer.");if(r&r-1)throw new TypeError("Chalkboard.calc.fft: Input length must be a power of two.");const n=new Array(r),o=new Array(r);for(let e=0;e<r;e++){const r=t[e];n[e]="number"==typeof r?r:r.a,o[e]="number"==typeof r?0:r.b}let i=0;for(let e=r;e>1;e>>=1)i++;for(let e=0;e<r;e++){let t=e,r=0;for(let e=0;e<i;e++)r=r<<1|1&t,t>>=1;if(r>e){let t=n[e];n[e]=n[r],n[r]=t,t=o[e],o[e]=o[r],o[r]=t}}for(let t=2;t<=r;t<<=1){const i=e.PI(-2)/t,a=e.trig.cos(i),s=e.trig.sin(i);for(let e=0;e<r;e+=t){let r=1,i=0;const l=t>>1;for(let t=0;t<l;t++){const u=n[e+t],m=o[e+t],f=n[e+t+l],c=o[e+t+l],p=f*r-c*i,d=f*i+c*r;n[e+t]=u+p,o[e+t]=m+d,n[e+t+l]=u-p,o[e+t+l]=m-d;const h=r*s+i*a;r=r*a-i*s,i=h}}}const a=new Array(r);for(let t=0;t<r;t++)a[t]=e.comp.init(n[t],o[t]);return a},t.fftfreq=(e,t=1)=>{if(!Number.isInteger(e)||e<=0)throw new TypeError("Chalkboard.calc.fftfreq: Parameter 'n' must be a positive integer.");if("number"!=typeof t||!Number.isFinite(t)||t<=0)throw new TypeError("Chalkboard.calc.fftfreq: Parameter 'd' must be a positive finite number.");const r=new Array(e),n=1/(e*t);if(e%2==0){const t=e/2;for(let o=0;o<e;o++){const i=o<t?o:o-e;r[o]=i*n}}else{const t=(e-1)/2;for(let o=0;o<e;o++){const i=o<=t?o:o-e;r[o]=i*n}}return r},t.fftshift=e=>{if(!Array.isArray(e))throw new TypeError("Chalkboard.calc.fftshift: Parameter 'arr' must be an array.");const t=e.length;if(0===t)return[];const r=Math.floor((t+1)/2);return e.slice(r).concat(e.slice(0,r))},t.fnds=(t,r,n,o,i,a)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.calc.fnds: Properties 'field' of 'vectfield' and 'func' must be 'real'.");let s,l,u=0;if("vector2d"===t.type&&"curve2d"===r.type){const i=(o-n)/1e4;for(let a=n;a<=o;a+=i)s=e.calc.dfdx(r,a),u+=e.vect.dot(e.vect.fromField(t,e.real.val(r,a)),e.vect.init(-s.y,s.x))*e.vect.mag(s);return u*i}if("vector3d"===t.type&&"curve3d"===r.type){const i=(o-n)/1e4;for(let a=n;a<=o;a+=i)s=e.calc.dfdx(r,a),u+=e.vect.dot(e.vect.fromField(t,e.real.val(r,a)),e.calc.normal(r,a))*e.vect.mag(s);return u*i}if("vector3d"===t.type&&"surface3d"===r.type){const m=(o-n)/100,f=(a-i)/100;for(let c=i;c<=a;c+=f)for(let i=n;i<=o;i+=m)l=e.matr.toVector(e.calc.grad(r,e.vect.init(c,i)),3,0,0),s=e.matr.toVector(e.calc.grad(r,e.vect.init(c,i)),3,1,0),u+=e.vect.scalarTriple(e.vect.fromField(t,e.real.val(r,e.vect.init(c,i))),l,s);return u*f*m}throw new TypeError("Chalkboard.calc.fnds: Property 'type' of 'vectfield' must be 'vector2d' or 'vector3d' and property 'type' of 'func' must be 'curve2d', 'curve3d', or 'surface3d'.")},t.Fourier=(t,r,n=0,o=10,i=1e4)=>{if("real"!==t.field||"scalar2d"!==t.type)throw new TypeError("Chalkboard.calc.Fourier: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");const a=t.rule;if(!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(i))throw new TypeError("Chalkboard.calc.Fourier: Parameters 'inf', 'sup', and 'steps' must be finite.");if(i<=0||!Number.isInteger(i))throw new TypeError("Chalkboard.calc.Fourier: Parameter 'steps' must be a positive integer.");if(o===n)return 0;const s=(o-n)/i;let l=0;for(let e=0;e<=i;e++){const t=n+e*s;l+=(0===e||e===i?.5:1)*(a(t)*Math.cos(r*t))}return 2*l*s/e.PI()},t.frds=(t,r,n,o)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.calc.frds: Properties 'field' of 'funcORvectfield' and 'func' must be 'real'.");const i=t.rule;if("curve2d"===r.type||"curve3d"===r.type){let a=0;const s=(o-n)/1e4;if("scalar2d"===t.type){for(let t=n;t<=o;t+=s){const n=e.real.val(r,t);a+=i(n.x,n.y)*e.vect.mag(e.calc.dfdx(r,t))}return a*s}if("vector2d"===t.type){for(let i=n;i<=o;i+=s){const n=e.real.val(r,i);a+=e.vect.dot(e.vect.fromField(t,n),e.calc.dfdx(r,i))}return a*s}if("vector3d"===t.type){for(let i=n;i<=o;i+=s){const n=e.real.val(r,i);a+=e.vect.dot(e.vect.fromField(t,n),e.calc.dfdx(r,i))}return a*s}throw new TypeError("Chalkboard.calc.frds: Property 'type' of 'funcORvectfield' must be 'scalar2d', 'vector2d', or 'vector3d'.")}throw new TypeError("Chalkboard.calc.frds: Property 'type' of 'func' must be 'curve2d' or 'curve3d'.")},t.fxdx=(t,r,n)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.fxdx: Property 'field' of 'func' must be 'real'.");const o=(e,t,r,n=1e-6)=>{const o=(t,r,n,i,a,s,l,u)=>{const m=(t+r)/2,f=(r-t)/2,c=(m+r)/2,p=e((t+m)/2),d=e(c),h=f/6*(n+4*p+i),y=f/6*(i+4*d+a),b=h+y-s;return u>=50||Math.abs(b)<=15*l?h+y+b/15:o(t,m,n,p,i,h,l/2,u+1)+o(m,r,i,d,a,y,l/2,u+1)},i=(t+r)/2,a=e(t),s=e(i),l=e(r);return o(t,r,a,s,l,(r-t)/6*(a+4*s+l),n,0)};if("scalar2d"===t.type){return o(t.rule,r,n)}if("curve2d"===t.type){const i=t.rule;return e.vect.init(o(i[0],r,n),o(i[1],r,n))}if("curve3d"===t.type){const i=t.rule;return e.vect.init(o(i[0],r,n),o(i[1],r,n),o(i[2],r,n))}throw new TypeError("Chalkboard.calc.fxdx: Property 'type' of 'func' must be 'scalar2d', 'curve2d', or 'curve3d'.")},t.fxydxdy=(e,t,r,n,o)=>{if("real"!==e.field)throw new TypeError("Chalkboard.calc.fxydxdy: Property 'field' of 'func' must be 'real'.");if("scalar3d"===e.type){const i=e.rule,a=(e,t,r,n)=>{const o=(t,r,n,i,a,s,l,u)=>{const m=(t+r)/2,f=(r-t)/2,c=(m+r)/2,p=e((t+m)/2),d=e(c),h=f/6*(n+4*p+i),y=f/6*(i+4*d+a),b=h+y-s;return u>=50||Math.abs(b)<=15*l?h+y+b/15:o(t,m,n,p,i,h,l/2,u+1)+o(m,r,i,d,a,y,l/2,u+1)},i=(t+r)/2,a=e(t),s=e(i),l=e(r);return o(t,r,a,s,l,(r-t)/6*(a+4*s+l),n,0)},s=e=>a(t=>i(e,t),n,o,1e-5);return a(s,t,r,1e-5)}throw new TypeError("Chalkboard.calc.fxydxdy: Property 'type' of 'func' must be 'scalar3d'.")},t.fzdz=(t,r,n,o)=>{if("comp"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.calc.fzdz: Property 'field' of 'func1' must be 'comp' and property 'field' of 'func2' must be 'real'.");if("vector2d"===t.type&&"curve2d"===r.type){let i=e.comp.init(0,0);const a=(o-n)/1e4;for(let s=n;s<=o;s+=a){const n=e.comp.val(t,e.vect.toComplex(e.real.val(r,s))),o=e.calc.dfdx(r,s);i=e.comp.add(i,e.comp.init(n.a*o.x-n.b*o.y,n.b*o.x+n.a*o.y))}return e.comp.scl(i,a)}throw new TypeError("Chalkboard.calc.fzdz: Property 'type' of 'func1' must be 'vector2d' and property 'type' of 'func2' must be 'curve2d'.")},t.grad=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.grad: Property 'field' of 'funcORvectfield' must be 'real'.");const n=t.rule,o=t.rule,i=t.rule,a=r,s=1e-9;if("scalar3d"===t.type){const t=(n(a.x+s,a.y)-n(a.x,a.y))/s,r=(n(a.x,a.y+s)-n(a.x,a.y))/s;return e.vect.init(t,r)}if("surface3d"===t.type){const t=(o[0](a.x+s,a.y)-o[0](a.x,a.y))/s,r=(o[0](a.x,a.y+s)-o[0](a.x,a.y))/s,n=(o[1](a.x+s,a.y)-o[1](a.x,a.y))/s,i=(o[1](a.x,a.y+s)-o[1](a.x,a.y))/s,l=(o[2](a.x+s,a.y)-o[2](a.x,a.y))/s,u=(o[2](a.x,a.y+s)-o[2](a.x,a.y))/s;return e.matr.init([t,r],[n,i],[l,u])}if("vector2d"===t.type){const t=(i[0](a.x+s,a.y)-i[0](a.x,a.y))/s,r=(i[0](a.x,a.y+s)-i[0](a.x,a.y))/s,n=(i[1](a.x+s,a.y)-i[1](a.x,a.y))/s,o=(i[1](a.x,a.y+s)-i[1](a.x,a.y))/s;return e.matr.init([t,r],[n,o])}if("vector3d"===t.type){const t=(i[0](a.x+s,a.y,a.z)-i[0](a.x,a.y,a.z))/s,r=(i[0](a.x,a.y+s,a.z)-i[0](a.x,a.y,a.z))/s,n=(i[0](a.x,a.y,a.z+s)-i[0](a.x,a.y,a.z))/s,o=(i[1](a.x+s,a.y,a.z)-i[1](a.x,a.y,a.z))/s,l=(i[1](a.x,a.y+s,a.z)-i[1](a.x,a.y,a.z))/s,u=(i[1](a.x,a.y,a.z+s)-i[1](a.x,a.y,a.z))/s,m=(i[2](a.x+s,a.y,a.z)-i[2](a.x,a.y,a.z))/s,f=(i[2](a.x,a.y+s,a.z)-i[2](a.x,a.y,a.z))/s,c=(i[2](a.x,a.y,a.z+s)-i[2](a.x,a.y,a.z))/s;return e.matr.init([t,r,n],[o,l,u],[m,f,c])}if("vector4d"===t.type){const t=(i[0](a.x+s,a.y,a.z,a.w)-i[0](a.x,a.y,a.z,a.w))/s,r=(i[0](a.x,a.y+s,a.z,a.w)-i[0](a.x,a.y,a.z,a.w))/s,n=(i[0](a.x,a.y,a.z+s,a.w)-i[0](a.x,a.y,a.z,a.w))/s,o=(i[0](a.x,a.y,a.z,a.w+s)-i[0](a.x,a.y,a.z,a.w))/s,l=(i[1](a.x+s,a.y,a.z,a.w)-i[1](a.x,a.y,a.z,a.w))/s,u=(i[1](a.x,a.y+s,a.z,a.w)-i[1](a.x,a.y,a.z,a.w))/s,m=(i[1](a.x,a.y,a.z+s,a.w)-i[1](a.x,a.y,a.z,a.w))/s,f=(i[1](a.x,a.y,a.z,a.w+s)-i[1](a.x,a.y,a.z,a.w))/s,c=(i[2](a.x+s,a.y,a.z,a.w)-i[2](a.x,a.y,a.z,a.w))/s,p=(i[2](a.x,a.y+s,a.z,a.w)-i[2](a.x,a.y,a.z,a.w))/s,d=(i[2](a.x,a.y,a.z+s,a.w)-i[2](a.x,a.y,a.z,a.w))/s,h=(i[2](a.x,a.y,a.z,a.w+s)-i[2](a.x,a.y,a.z,a.w))/s,y=(i[3](a.x+s,a.y,a.z,a.w)-i[3](a.x,a.y,a.z,a.w))/s,b=(i[3](a.x,a.y+s,a.z,a.w)-i[3](a.x,a.y,a.z,a.w))/s,g=(i[3](a.x,a.y,a.z+s,a.w)-i[3](a.x,a.y,a.z,a.w))/s,w=(i[3](a.x,a.y,a.z,a.w+s)-i[3](a.x,a.y,a.z,a.w))/s;return e.matr.init([t,r,n,o],[l,u,m,f],[c,p,d,h],[y,b,g,w])}throw new TypeError("Chalkboard.calc.grad: Property 'type' of 'funcORvectfield' must be 'scalar3d', 'surface3d', 'vector2d', 'vector3d', or 'vector4d'.")},t.grad2=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.calc.grad2: Property 'field' of 'funcORvectfield' must be 'real'.");const n=t.rule,o=t.rule,i=t.rule,a=r,s=1e-5;if("scalar3d"===t.type){const t=(n(a.x+s,a.y)-2*n(a.x,a.y)+n(a.x-s,a.y))/(s*s),r=(n(a.x,a.y+s)-2*n(a.x,a.y)+n(a.x,a.y-s))/(s*s),o=(n(a.x+s,a.y+s)-n(a.x+s,a.y)-n(a.x,a.y+s)+n(a.x,a.y))/(s*s),i=(n(a.x+s,a.y+s)-n(a.x,a.y+s)-n(a.x+s,a.y)+n(a.x,a.y))/(s*s);return e.matr.init([t,o],[i,r])}if("surface3d"===t.type){const t=(o[0](a.x+s,a.y)-2*o[0](a.x,a.y)+o[0](a.x-s,a.y))/(s*s),r=(o[0](a.x,a.y+s)-2*o[0](a.x,a.y)+o[0](a.x,a.y-s))/(s*s),n=(o[1](a.x+s,a.y)-2*o[1](a.x,a.y)+o[1](a.x-s,a.y))/(s*s),i=(o[1](a.x,a.y+s)-2*o[1](a.x,a.y)+o[1](a.x,a.y-s))/(s*s),l=(o[2](a.x+s,a.y)-2*o[2](a.x,a.y)+o[2](a.x-s,a.y))/(s*s),u=(o[2](a.x,a.y+s)-2*o[2](a.x,a.y)+o[2](a.x,a.y-s))/(s*s);return e.matr.init([t,r],[n,i],[l,u])}if("vector2d"===t.type){const t=(i[0](a.x+s,a.y)-2*i[0](a.x,a.y)+i[0](a.x-s,a.y))/(s*s),r=(i[0](a.x,a.y+s)-2*i[0](a.x,a.y)+i[0](a.x,a.y-s))/(s*s),n=(i[1](a.x+s,a.y)-2*i[1](a.x,a.y)+i[1](a.x-s,a.y))/(s*s),o=(i[1](a.x,a.y+s)-2*i[1](a.x,a.y)+i[1](a.x,a.y-s))/(s*s);return e.matr.init([t,r],[n,o])}if("vector3d"===t.type){const t=(i[0](a.x+s,a.y,a.z)-2*i[0](a.x,a.y,a.z)+i[0](a.x-s,a.y,a.z))/(s*s),r=(i[0](a.x,a.y+s,a.z)-2*i[0](a.x,a.y,a.z)+i[0](a.x,a.y-s,a.z))/(s*s),n=(i[0](a.x,a.y,a.z+s)-2*i[0](a.x,a.y,a.z)+i[0](a.x,a.y,a.z-s))/(s*s),o=(i[1](a.x+s,a.y,a.z)-2*i[1](a.x,a.y,a.z)+i[1](a.x-s,a.y,a.z))/(s*s),l=(i[1](a.x,a.y+s,a.z)-2*i[1](a.x,a.y,a.z)+i[1](a.x,a.y-s,a.z))/(s*s),u=(i[1](a.x,a.y,a.z+s)-2*i[1](a.x,a.y,a.z)+i[1](a.x,a.y,a.z-s))/(s*s),m=(i[2](a.x+s,a.y,a.z)-2*i[2](a.x,a.y,a.z)+i[2](a.x-s,a.y,a.z))/(s*s),f=(i[2](a.x,a.y+s,a.z)-2*i[2](a.x,a.y,a.z)+i[2](a.x,a.y-s,a.z))/(s*s),c=(i[2](a.x,a.y,a.z+s)-2*i[2](a.x,a.y,a.z)+i[2](a.x,a.y,a.z-s))/(s*s);return e.matr.init([t,r,n],[o,l,u],[m,f,c])}if("vector4d"===t.type){const t=(i[0](a.x+s,a.y,a.z,a.w)-2*i[0](a.x,a.y,a.z,a.w)+i[0](a.x-s,a.y,a.z,a.w))/(s*s),r=(i[0](a.x,a.y+s,a.z,a.w)-2*i[0](a.x,a.y,a.z,a.w)+i[0](a.x,a.y-s,a.z,a.w))/(s*s),n=(i[0](a.x,a.y,a.z+s,a.w)-2*i[0](a.x,a.y,a.z,a.w)+i[0](a.x,a.y,a.z-s,a.w))/(s*s),o=(i[0](a.x,a.y,a.z,a.w+s)-2*i[0](a.x,a.y,a.z,a.w)+i[0](a.x,a.y,a.z,a.w-s))/(s*s),l=(i[1](a.x+s,a.y,a.z,a.w)-2*i[1](a.x,a.y,a.z,a.w)+i[1](a.x-s,a.y,a.z,a.w))/(s*s),u=(i[1](a.x,a.y+s,a.z,a.w)-2*i[1](a.x,a.y,a.z,a.w)+i[1](a.x,a.y-s,a.z,a.w))/(s*s),m=(i[1](a.x,a.y,a.z+s,a.w)-2*i[1](a.x,a.y,a.z,a.w)+i[1](a.x,a.y,a.z-s,a.w))/(s*s),f=(i[1](a.x,a.y,a.z,a.w+s)-2*i[1](a.x,a.y,a.z,a.w)+i[1](a.x,a.y,a.z,a.w-s))/(s*s),c=(i[2](a.x+s,a.y,a.z,a.w)-2*i[2](a.x,a.y,a.z,a.w)+i[2](a.x-s,a.y,a.z,a.w))/(s*s),p=(i[2](a.x,a.y+s,a.z,a.w)-2*i[2](a.x,a.y,a.z,a.w)+i[2](a.x,a.y-s,a.z,a.w))/(s*s),d=(i[2](a.x,a.y,a.z+s,a.w)-2*i[2](a.x,a.y,a.z,a.w)+i[2](a.x,a.y,a.z-s,a.w))/(s*s),h=(i[2](a.x,a.y,a.z,a.w+s)-2*i[2](a.x,a.y,a.z,a.w)+i[2](a.x,a.y,a.z,a.w-s))/(s*s),y=(i[3](a.x+s,a.y,a.z,a.w)-2*i[3](a.x,a.y,a.z,a.w)+i[3](a.x-s,a.y,a.z,a.w))/(s*s),b=(i[3](a.x,a.y+s,a.z,a.w)-2*i[3](a.x,a.y,a.z,a.w)+i[3](a.x,a.y-s,a.z,a.w))/(s*s),g=(i[3](a.x,a.y,a.z+s,a.w)-2*i[3](a.x,a.y,a.z,a.w)+i[3](a.x,a.y,a.z-s,a.w))/(s*s),w=(i[3](a.x,a.y,a.z,a.w+s)-2*i[3](a.x,a.y,a.z,a.w)+i[3](a.x,a.y,a.z,a.w-s))/(s*s);return e.matr.init([t,r,n,o],[l,u,m,f],[c,p,d,h],[y,b,g,w])}throw new TypeError("Chalkboard.calc.grad: Property 'type' of 'funcORvectfield' must be 'scalar3d', 'surface3d', 'vector2d', 'vector3d', or 'vector4d'.")},t.idft=t=>{if(!Array.isArray(t))throw new TypeError("Chalkboard.calc.idft: Parameter 'arr' must be an array.");const r=t.length,n=new Array(r);for(let o=0;o<r;o++){let i=0,a=0;for(let n=0;n<r;n++){const s=t[n],l="number"==typeof s?s:s.a,u="number"==typeof s?0:s.b,m=e.PI(2*n*o)/r,f=e.trig.cos(m),c=e.trig.sin(m);i+=l*f-u*c,a+=l*c+u*f}n[o]=e.comp.init(i/r,a/r)}return n},t.ifft=t=>{if(!Array.isArray(t))throw new TypeError("Chalkboard.calc.ifft: Parameter 'arr' must be an array.");const r=t.length;if(!Number.isInteger(r)||r<=0)throw new TypeError("Chalkboard.calc.ifft: Input length must be a positive integer.");if(r&r-1)throw new TypeError("Chalkboard.calc.ifft: Input length must be a power of two.");const n=new Array(r);for(let o=0;o<r;o++){const r=t[o],i="number"==typeof r?r:r.a,a="number"==typeof r?0:r.b;n[o]=e.comp.init(i,-a)}const o=e.calc.fft(n),i=new Array(r);for(let t=0;t<r;t++)i[t]=e.comp.init(o[t].a/r,-o[t].b/r);return i},t.ifftshift=e=>{if(!Array.isArray(e))throw new TypeError("Chalkboard.calc.ifftshift: Parameter 'arr' must be an array.");const t=e.length;if(0===t)return[];const r=Math.floor(t/2);return e.slice(r).concat(e.slice(0,r))},t.iFourier=(e,t,r=0,n=10,o=1e4)=>{if("real"!==e.field||"scalar2d"!==e.type)throw new TypeError("Chalkboard.calc.iFourier: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");const i=e.rule;if(!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(o))throw new TypeError("Chalkboard.calc.iFourier: Parameters 'inf', 'sup', and 'steps' must be finite.");if(o<=0||!Number.isInteger(o))throw new TypeError("Chalkboard.calc.iFourier: Parameter 'steps' must be a positive integer.");if(n===r)return 0;const a=(n-r)/o;let s=0;for(let e=0;e<=o;e++){const n=r+e*a;s+=(0===e||e===o?.5:1)*(i(n)*Math.cos(n*t))}return s*a},t.irfft=(t,r)=>{if(!Array.isArray(t))throw new TypeError("Chalkboard.calc.irfft: Parameter 'arr' must be an array.");if(0===t.length)return[];const n="number"==typeof r?r:2*(t.length-1);if(!Number.isInteger(n)||n<=0)throw new TypeError("Chalkboard.calc.irfft: Parameter 'n' must be a positive integer.");const o=Math.floor(n/2)+1;if(t.length!==o)throw new RangeError("Chalkboard.calc.irfft: Input spectrum length must be floor(n/2)+1.");const i=new Array(n);{const r=t[0],n="number"==typeof r?r:r.a,o="number"==typeof r?0:r.b;i[0]=e.comp.init(n,o)}const a=Math.floor(n/2);for(let r=1;r<=a;r++){const n=t[r],o="number"==typeof n?n:n.a,a="number"==typeof n?0:n.b;i[r]=e.comp.init(o,a)}if(n%2==0)for(let t=1;t<a;t++)i[n-t]=e.comp.init(i[t].a,-i[t].b);else for(let t=1;t<=a;t++)i[n-t]=e.comp.init(i[t].a,-i[t].b);const s=!(n&n-1)?e.calc.ifft(i):e.calc.idft(i),l=new Array(n);for(let e=0;e<n;e++)l[e]=s[e].a;return l},t.Laplace=(t,r)=>{if("real"!==t.field||"scalar2d"!==t.type)throw new TypeError("Chalkboard.calc.Laplace: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");if(r>0){const n=t.rule,o=e=>n(e)*Math.exp(-r*e);return e.calc.fxdx(e.real.define(o),0,10)}throw new RangeError("Chalkboard.calc.Laplace: 'val' must be greater than 0.")},t.lim=(e,t)=>{if("real"!==e.field||"scalar2d"!==e.type)throw new TypeError("Chalkboard.calc.lim: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");const r=e.rule;return t===1/0?r(101)>r(100)?1/0:r(101)<r(100)?-1/0:r(100):t===-1/0?r(-101)>r(-100)?1/0:r(-101)<r(-100)?-1/0:r(-100):r(t-1e-6).toFixed(4)===r(t+1e-6).toFixed(4)&&r(t)!==1/0&&r(t)!==-1/0?r(t):void 0},t.mean=(t,r,n)=>{if("real"!==t.field||"scalar2d"!==t.type)throw new TypeError("Chalkboard.calc.mean: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");return e.calc.fxdx(t,r,n)/(n-r)},t.Newton=(t,r=[-1,1])=>{if("real"!==t.field||"scalar2d"!==t.type)throw new TypeError("Chalkboard.calc.Newton: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");const n=t.rule;let o=e.numb.random(r[0],r[1]);for(let r=0;r<10;r++)o-=n(o)/e.calc.dfdx(t,o);return o},t.normal=(t,r)=>{if("real"!==t.field||!t.type.startsWith("curve"))throw new TypeError("Chalkboard.calc.normal: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'curve2d' or 'curve3d'.");return e.vect.normalize(e.calc.d2fdx2(t,r))},t.rfft=t=>{if(!Array.isArray(t))throw new TypeError("Chalkboard.calc.rfft: Parameter 'arr' must be an array.");const r=t.length;if(!Number.isInteger(r)||r<=0)throw new TypeError("Chalkboard.calc.rfft: Input length must be a positive integer.");return(r&r-1?e.calc.dft(t):e.calc.fft(t)).slice(0,Math.floor(r/2)+1)},t.tangent=(t,r)=>{if("real"!==t.field||!t.type.startsWith("curve"))throw new TypeError("Chalkboard.calc.tangent: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'curve2d' or 'curve3d'.");return e.vect.normalize(e.calc.dfdx(t,r))},t.Taylor=(t,r,n,o)=>{if("real"!==t.field||"scalar2d"!==t.type)throw new TypeError("Chalkboard.calc.Taylor: Property 'field' of 'func' must be 'real' and property 'type' of 'func' must be 'scalar2d'.");const i=t.rule,a=r;if(0===n)return i(a);if(1===n)return i(a)+e.calc.dfdx(t,o)*(a-o);if(2===n)return i(a)+e.calc.dfdx(t,o)*(a-o)+e.calc.d2fdx2(t,o)*(a-o)*(a-o)/2;throw new RangeError("Chalkboard.calc.Taylor: 'n' must be 0, 1, or 2.")}}(t=e.calc||(e.calc={}))}(Chalkboard||(Chalkboard={})),function(e){let t;var r;(r=t=e.comp||(e.comp={})).absolute=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(Math.abs(r.a),Math.abs(r.b))}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.absolute: Property 'field' of 'comp' must be 'comp'.");const r=t.rule,n=[(e,t)=>Math.abs(r[0](e,t)),(e,t)=>Math.abs(r[1](e,t))];return e.comp.define(...n)}throw new TypeError("Chalkboard.comp.absolute: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.add=(t,r)=>{if("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")&&r.hasOwnProperty("a")&&r.hasOwnProperty("b")){const n=t,o=r;return e.comp.init(n.a+o.a,n.b+o.b)}if(t.hasOwnProperty("rule")&&r.hasOwnProperty("rule")){if("comp"!==t.field||"comp"!==r.field)throw new TypeError("Chalkboard.comp.add: Properties 'field' of 'comp1' and 'comp2' must be 'comp'.");const n=t.rule,o=r.rule,i=[(e,t)=>n[0](e,t)+o[0](e,t),(e,t)=>n[1](e,t)+o[1](e,t)];return e.comp.define(...i)}throw new TypeError("Chalkboard.comp.add: Parameters 'comp1' and 'comp2' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.arg=t=>e.trig.arctan2(t.b,t.a),r.argBetween=(t,r)=>e.vect.angBetween(e.comp.toVector(t),e.comp.toVector(r)),r.conjugate=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(r.a,-r.b)}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.conjugate: Property 'field' of 'comp' must be 'comp'.");const r=t.rule,n=[(e,t)=>r[0](e,t),(e,t)=>-r[1](e,t)];return e.comp.define(...n)}throw new TypeError("Chalkboard.comp.conjugate: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.constrain=(t,r=[0,1])=>e.comp.init(e.numb.constrain(t.a,r),e.numb.constrain(t.b,r)),r.copy=e=>Object.create(Object.getPrototypeOf(e),Object.getOwnPropertyDescriptors(e)),r.cos=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(e.trig.cos(r.a)*e.trig.cosh(r.b),-e.trig.sin(r.a)*e.trig.sinh(r.b))}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.cos: Property 'field' of 'comp' must be 'comp'.");const r=t.rule;return e.comp.define((t,n)=>{const o=r[0](t,n),i=r[1](t,n);return e.trig.cos(o)*e.trig.cosh(i)},(t,n)=>{const o=r[0](t,n),i=r[1](t,n);return-e.trig.sin(o)*e.trig.sinh(i)})}throw new TypeError("Chalkboard.comp.cos: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.define=(...t)=>{let r;if(r=1===t.length&&Array.isArray(t[0])?t[0]:t.length>1?t:t[0],Array.isArray(r)){if(2!==r.length||2!==r[0].length||2!==r[1].length)throw new TypeError("Chalkboard.comp.define: If 'rule' is an array, it must be an array of two functions of two variables.");if("number"!=typeof r[0](0,0)||"number"!=typeof r[1](0,0))throw new TypeError("Chalkboard.comp.define: If 'rule' is an array, the functions in it must return real numbers.");return{rule:r,field:"comp",type:"vector2d"}}{if(1!==r.length)throw new TypeError("Chalkboard.comp.define: If 'rule' is a function, it must be a function of one variable.");const t=r;if(!t(e.comp.init(0,0)).hasOwnProperty("a")||!t(e.comp.init(0,0)).hasOwnProperty("b"))throw new TypeError("Chalkboard.comp.define: If 'rule' is a function, it must return a complex number.");return{rule:[(r,n)=>t(e.comp.init(r,n)).a,(r,n)=>t(e.comp.init(r,n)).b],field:"comp",type:"vector2d"}}},r.dist=(t,r)=>("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),e.real.sqrt((r.a-t.a)*(r.a-t.a)+(r.b-t.b)*(r.b-t.b))),r.distsq=(t,r)=>("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),(r.a-t.a)*(r.a-t.a)+(r.b-t.b)*(r.b-t.b)),r.div=(t,r)=>{if("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")&&r.hasOwnProperty("a")&&r.hasOwnProperty("b")){const n=t,o=r,i=o.a*o.a+o.b*o.b;return e.comp.init((n.a*o.a+n.b*o.b)/i,(n.b*o.a-n.a*o.b)/i)}if(t.hasOwnProperty("rule")||r.hasOwnProperty("rule")){if("comp"!==t.field||"comp"!==r.field)throw new TypeError("Chalkboard.comp.div: Properties 'field' of 'comp1' and 'comp2' must be 'comp'.");const n=t.rule,o=r.rule,i=[(e,t)=>{const r=o[0](e,t)*o[0](e,t)+o[1](e,t)*o[1](e,t);return(n[0](e,t)*o[0](e,t)+n[1](e,t)*o[1](e,t))/r},(e,t)=>{const r=o[0](e,t)*o[0](e,t)+o[1](e,t)*o[1](e,t);return(n[1](e,t)*o[0](e,t)-n[0](e,t)*o[1](e,t))/r}];return e.comp.define(...i)}throw new TypeError("Chalkboard.comp.div: Parameters 'comp1' and 'comp2' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.Euler=t=>e.comp.init(e.trig.cos(t),e.trig.sin(t)),r.exp=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t,n=Math.exp(r.a);return e.comp.init(n*Math.cos(r.b),n*Math.sin(r.b))}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.exp: Property 'field' of 'comp' must be 'comp'.");const r=t.rule;return e.comp.define((e,t)=>Math.exp(r[0](e,t))*Math.cos(r[1](e,t)),(e,t)=>Math.exp(r[0](e,t))*Math.sin(r[1](e,t)))}throw new TypeError("Chalkboard.comp.exp: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.Im=e=>e.hasOwnProperty("rule")?e.rule[1]:e.b,r.init=(e,t=0)=>({a:e,b:t}),r.invert=t=>e.comp.init(t.a/e.comp.magsq(t),-t.b/e.comp.magsq(t)),r.isApproxEqual=(t,r,n=1e-6)=>("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),e.numb.isApproxEqual(t.a,r.a,n)&&e.numb.isApproxEqual(t.b,r.b,n)),r.isEqual=(t,r)=>("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),t.a===r.a&&t.b===r.b),r.isInverse=(t,r,n=1e-6)=>("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),e.comp.isApproxEqual(e.comp.mul(t,r),e.comp.init(1,0),n)),r.isNormalized=t=>e.numb.isApproxEqual(e.comp.magsq(t),1),r.isZero=t=>("number"==typeof t&&(t=e.comp.init(t,0)),e.comp.isApproxEqual(t,e.comp.init(0,0))),r.ln=t=>e.comp.init(e.real.ln(e.comp.mag(t)),e.trig.arctan2(t.b,t.a)),r.mag=t=>e.real.sqrt(t.a*t.a+t.b*t.b),r.magset=(t,r)=>e.comp.scl(e.comp.normalize(t),r),r.magsq=e=>e.a*e.a+e.b*e.b,r.mul=(t,r)=>{if("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")&&r.hasOwnProperty("a")&&r.hasOwnProperty("b")){const n=t,o=r;return e.comp.init(n.a*o.a-n.b*o.b,n.a*o.b+n.b*o.a)}if(t.hasOwnProperty("rule")||r.hasOwnProperty("rule")){if("comp"!==t.field||"comp"!==r.field)throw new TypeError("Chalkboard.comp.mul: Properties 'field' of 'comp1' and 'comp2' must be 'comp'.");const n=t.rule,o=r.rule,i=[(e,t)=>n[0](e,t)*o[0](e,t)-n[1](e,t)*o[1](e,t),(e,t)=>n[0](e,t)*o[1](e,t)+n[1](e,t)*o[0](e,t)];return e.comp.define(...i)}throw new TypeError("Chalkboard.comp.mul: Parameters 'comp1' and 'comp2' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.negate=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(-r.a,-r.b)}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.negate: Property 'field' of 'comp' must be 'comp'.");const r=t.rule,n=[(e,t)=>-r[0](e,t),(e,t)=>-r[1](e,t)];return e.comp.define(...n)}throw new TypeError("Chalkboard.comp.negate: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.normalize=t=>e.comp.init(t.a/e.comp.mag(t),t.b/e.comp.mag(t)),r.parse=(t,r={returnAST:!1,returnJSON:!1,returnLaTeX:!1})=>{const n=(t,r)=>{switch(t.type){case"num":return e.comp.init(t.value,0);case"complex":return e.comp.init(t.a,t.b);case"var":{const e=t.name;if(e in r)return r[e];throw new Error(`Chalkboard.comp.parse: Variable '${e}' not defined in values`)}case"add":return e.comp.add(n(t.left,r),n(t.right,r));case"sub":return e.comp.sub(n(t.left,r),n(t.right,r));case"mul":return e.comp.mul(n(t.left,r),n(t.right,r));case"div":return e.comp.div(n(t.left,r),n(t.right,r));case"pow":{const o=n(t.base,r),i=n(t.exponent,r);if(0===i.b)return e.comp.pow(o,i.a);throw new Error("Chalkboard.comp.parse: Complex exponentiation with complex exponent not supported")}case"neg":return e.comp.negate(n(t.expr,r));case"func":{const o=t.name.toLowerCase(),i=t.args.map(e=>n(e,r));if(e.REGISTRY&&e.REGISTRY[o])try{const t=i.map(e=>{if(0!==e.b)throw new Error("Complex argument in real function");return e.a}),r=e.REGISTRY[o](...t);return e.comp.init(r,0)}catch(e){}switch(o){case"abs":return e.comp.absolute(i[0]);case"conj":case"conjugate":return e.comp.conjugate(i[0]);case"mag":return e.comp.init(e.comp.mag(i[0]),0);case"arg":return e.comp.init(e.comp.arg(i[0]),0);case"re":return e.comp.init(e.comp.Re(i[0]),0);case"im":return e.comp.init(e.comp.Im(i[0]),0);case"ln":return e.comp.ln(i[0]);case"sin":return e.comp.sin(i[0]);case"cos":return e.comp.cos(i[0]);case"tan":return e.comp.tan(i[0]);case"exp":return e.comp.exp(i[0]);case"invert":return e.comp.invert(i[0]);case"sq":return e.comp.sq(i[0]);case"sqrt":return e.comp.sqrt(i[0]);case"pow":if(i.length<2)throw new Error("Chalkboard.comp.parse: Function pow requires two arguments");return e.comp.pow(i[0],i[1].a);case"root":{if(i.length<2)throw new Error("Chalkboard.comp.parse: Function root requires two arguments");const t=i[1].a;if(!Number.isInteger(t)||t<=0)throw new Error("Chalkboard.comp.parse: Root index must be a positive integer");return e.comp.root(i[0],t)[0]}default:throw new Error(`Chalkboard.comp.parse: Unknown function ${t.name}`)}}}throw new Error(`Chalkboard.comp.parse: Unknown node type ${t.type}`)},o=e=>{switch(e.type){case"num":return e.value.toString();case"complex":return 0===e.a&&1===e.b?"i":0===e.a&&-1===e.b?"-i":0===e.a?`${e.b}i`:0===e.b?e.a.toString():1===e.b?`${e.a} + i`:-1===e.b?`${e.a} - i`:e.b>0?`${e.a} + ${e.b}i`:`${e.a} - ${-e.b}i`;case"var":return e.name;case"add":{const t=o(e.right);return t.startsWith("-")?`${o(e.left)} - ${t.slice(1)}`:`${o(e.left)} + ${t}`}case"sub":{const t="add"===e.right.type||"sub"===e.right.type?`(${o(e.right)})`:o(e.right);return`${o(e.left)} - ${t}`}case"mul":{if("num"===e.left.type&&1===e.left.value)return o(e.right);if("num"===e.right.type&&1===e.right.value)return o(e.left);const t="add"===e.left.type||"sub"===e.left.type?`(${o(e.left)})`:o(e.left),r="add"===e.right.type||"sub"===e.right.type?`(${o(e.right)})`:o(e.right);return"num"===e.left.type&&-1===e.left.value&&"var"===e.right.type||"num"===e.left.type&&-1===e.left.value&&"pow"===e.right.type?`-${o(e.right)}`:"num"!==e.left.type&&"complex"!==e.left.type||"var"!==e.right.type&&("complex"!==e.right.type||0!==e.right.a||1!==e.right.b)?`${t} * ${r}`:`${t}${r}`}case"div":{const t={type:"pow",base:e.right,exponent:{type:"num",value:-1}},r={type:"mul",left:e.left,right:t};return o(r)}case"pow":{const r="complex"===e.base?.type,n=o(e.base);return`${r&&0!==(t=e.base).b&&(0!==t.a||1!==t.b&&-1!==t.b)||"num"!==e.base.type&&"var"!==e.base.type&&"complex"!==e.base.type?`(${n})`:n}^${"num"!==e.exponent.type&&"var"!==e.exponent.type&&"complex"!==e.exponent.type?`(${o(e.exponent)})`:o(e.exponent)}`}case"neg":return`-${"num"!==e.expr.type&&"var"!==e.expr.type&&"complex"!==e.expr.type?`(${o(e.expr)})`:o(e.expr)}`;case"func":return`${e.name}(${e.args.map(e=>o(e)).join(", ")})`}var t;return""},i=e=>{switch(e.type){case"num":return e.value.toString();case"complex":{const t=0!==e.a?e.a.toString():"",r=0!==e.b?1===e.b?"i":-1===e.b?"-i":`${e.b}i`:"";return t&&r?e.b>0?`${t} + ${r}`:`${t} - ${r.slice(1)}`:t||r||"0"}case"var":return e.name;case"add":{const t=i(e.right);return t.startsWith("-")?`${i(e.left)} - ${t.slice(1)}`:`${i(e.left)} + ${t}`}case"sub":{const t=i(e.right);return t.startsWith("-")?`${i(e.left)} + ${t.slice(1)}`:`${i(e.left)} - ${t}`}case"mul":{const t=e=>"num"===e.type||"var"===e.type||"complex"===e.type||"pow"===e.type||"func"===e.type,r=e=>{const t=i(e);return"add"===e.type||"sub"===e.type?`\\left(${t}\\right)`:t},n=r(e.left),o=r(e.right);return t(e.left)&&t(e.right)?`${n}${o}`:`${n} \\cdot ${o}`}case"div":return`\\frac{${i(e.left)}}{${i(e.right)}}`;case"pow":return`${i(e.base)}^{${i(e.exponent)}}`;case"neg":return`-${i(e.expr)}`;case"func":return`\\mathrm{${e.name}}\\left(${e.args.map(i).join(", ")}\\right)`;default:throw new Error(`Chalkboard.comp.parse: Unknown node type ${e.type}`)}},a=(e,t)=>"var"===e.type&&"var"===t.type?e.name===t.name:"complex"===e.type&&"complex"===t.type?e.a===t.a&&e.b===t.b:JSON.stringify(e)===JSON.stringify(t),s=e=>{switch(e.type){case"num":return{type:"complex",a:e.value,b:0};case"complex":case"var":return e;case"add":{const t=s(e.left),r=s(e.right);return"complex"===t.type&&"complex"===r.type?{type:"complex",a:t.a+r.a,b:t.b+r.b}:"complex"===t.type&&0===t.a&&0===t.b?r:"complex"===r.type&&0===r.a&&0===r.b?t:a(t,r)?{type:"mul",left:{type:"num",value:2},right:t}:{type:"add",left:t,right:r}}case"sub":{const t=s(e.left),r=s(e.right);return"complex"===t.type&&"complex"===r.type?{type:"complex",a:t.a-r.a,b:t.b-r.b}:"complex"===r.type&&0===r.a&&0===r.b?t:"complex"===t.type&&0===t.a&&0===t.b?{type:"neg",expr:r}:a(t,r)?{type:"complex",a:0,b:0}:{type:"sub",left:t,right:r}}case"mul":{const t=s(e.left),r=s(e.right);if(!("add"!==t.type&&"sub"!==t.type||"add"!==r.type&&"sub"!==r.type)){const e=t=>{if("add"===t.type)return[...e(t.left),...e(t.right)];if("sub"===t.type){const r=e(t.right).map(e=>({type:"neg",expr:e}));return[...e(t.left),...r]}return[t]},n=e(t),o=e(r),i=[];for(const e of n)for(const t of o)"neg"===e.type&&"neg"===t.type?i.push(s({type:"mul",left:e.expr,right:t.expr})):"neg"===e.type?i.push(s({type:"neg",expr:{type:"mul",left:e.expr,right:t}})):"neg"===t.type?i.push(s({type:"neg",expr:{type:"mul",left:e,right:t.expr}})):i.push(s({type:"mul",left:e,right:t}));let a=i[0];for(let e=1;e<i.length;e++)a={type:"add",left:a,right:i[e]};return s(a)}return"complex"===t.type&&"complex"===r.type?{type:"complex",a:t.a*r.a-t.b*r.b,b:t.a*r.b+t.b*r.a}:"complex"===t.type&&0===t.a&&0===t.b||"complex"===r.type&&0===r.a&&0===r.b?{type:"complex",a:0,b:0}:"complex"===t.type&&1===t.a&&0===t.b?r:"complex"===r.type&&1===r.a&&0===r.b?t:"complex"===t.type&&0===t.a&&1===t.b&&"complex"===r.type?{type:"complex",a:-r.b,b:r.a}:{type:"mul",left:t,right:r}}case"div":{const t=s(e.left),r=s(e.right);if("add"===t.type||"sub"===t.type){const e={type:"div",left:t.left,right:JSON.parse(JSON.stringify(r))},n={type:"div",left:t.right,right:JSON.parse(JSON.stringify(r))};return{type:t.type,left:s(e),right:s(n)}}if("complex"===t.type&&"complex"===r.type){const e=r.a*r.a+r.b*r.b;if(0===e)throw new Error("Chalkboard.comp.parse: Division by zero.");return{type:"complex",a:(t.a*r.a+t.b*r.b)/e,b:(t.b*r.a-t.a*r.b)/e}}return"complex"===r.type&&1===r.a&&0===r.b?t:"complex"===t.type&&0===t.a&&0===t.b?{type:"complex",a:0,b:0}:{type:"div",left:t,right:r}}case"pow":return{type:"pow",base:s(e.base),exponent:s(e.exponent)};case"neg":{const t=s(e.expr);return"complex"===t.type?{type:"complex",a:-t.a,b:-t.b}:"neg"===t.type?t.expr:{type:"neg",expr:t}}case"func":{const t=e.args.map(e=>s(e));return{type:"func",name:e.name,args:t}}}return e},l=e=>{switch(e.type){case"num":case"var":return!0;case"complex":return 0===e.b;case"neg":return l(e.expr);case"add":case"sub":case"mul":case"div":return l(e.left)&&l(e.right);case"pow":return l(e.base)&&l(e.exponent);case"func":return e.args.every(l);default:return!1}},u=e=>({type:"num",value:e}),m=(e,t)=>({type:"add",left:e,right:t}),f=(e,t)=>({type:"sub",left:e,right:t}),c=(e,t)=>({type:"mul",left:e,right:t}),p=(e,t)=>({type:"div",left:e,right:t}),d=(e,t)=>({type:"pow",base:e,exponent:t}),h=e=>({type:"neg",expr:e}),y=e=>{switch(e.type){case"num":return e.value.toString();case"var":return e.name;case"add":return`${y(e.left)} + ${y(e.right)}`;case"sub":return`${y(e.left)} - ${y(e.right)}`;case"mul":return`${"add"===e.left.type||"sub"===e.left.type?`(${y(e.left)})`:y(e.left)} * ${"add"===e.right.type||"sub"===e.right.type?`(${y(e.right)})`:y(e.right)}`;case"div":return`${"add"===e.left.type||"sub"===e.left.type?`(${y(e.left)})`:y(e.left)} / ${"add"===e.right.type||"sub"===e.right.type?`(${y(e.right)})`:y(e.right)}`;case"pow":return`${"num"===e.base.type||"var"===e.base.type?y(e.base):`(${y(e.base)})`}^${"num"===e.exponent.type||"var"===e.exponent.type?y(e.exponent):`(${y(e.exponent)})`}`;case"neg":return`-${"num"===e.expr.type||"var"===e.expr.type?y(e.expr):`(${y(e.expr)})`}`;default:throw new Error(`Chalkboard.comp.parse: Unsupported real-node type ${e.type}`)}},b=t=>e.real.parse(t,{roundTo:r.roundTo,returnAST:!1,returnJSON:!1,returnLaTeX:!1}),g=e=>{switch(e.type){case"num":return{re:u(e.value),im:u(0)};case"var":return"i"===e.name?{re:u(0),im:u(1)}:{re:{type:"var",name:e.name},im:u(0)};case"complex":return{re:u(e.a),im:u(e.b)};case"neg":{const t=g(e.expr);return{re:h(t.re),im:h(t.im)}}case"add":{const t=g(e.left),r=g(e.right);return{re:m(t.re,r.re),im:m(t.im,r.im)}}case"sub":{const t=g(e.left),r=g(e.right);return{re:f(t.re,r.re),im:f(t.im,r.im)}}case"mul":{const t=g(e.left),r=g(e.right),n=c(t.re,r.re),o=c(t.im,r.im),i=c(t.re,r.im),a=c(t.im,r.re);return{re:f(n,o),im:m(i,a)}}case"div":{const t=g(e.left),r=g(e.right),n=d(r.re,u(2)),o=d(r.im,u(2)),i=m(n,o),a=c(t.re,r.re),s=c(t.im,r.im),l=c(t.im,r.re),h=c(t.re,r.im),y=m(a,s),b=f(l,h);return{re:p(y,i),im:p(b,i)}}case"pow":{const t=g(e.exponent);if("0"!==b(y(t.im)))throw new Error("Chalkboard.comp.parse: Complex exponent not supported in symbolic splitting.");const r=b(y(t.re)),n=Number(r);if(!Number.isInteger(n))throw new Error("Chalkboard.comp.parse: Non-integer exponent not supported in symbolic splitting.");const o=g(e.base);let i=u(1),a=u(0);const s=Math.abs(n);for(let e=0;e<s;e++){const e=i,t=a,r=o.re,n=o.im;i=f(c(e,r),c(t,n)),a=m(c(e,n),c(t,r))}if(n<0){const e=m(d(i,u(2)),d(a,u(2)));return{re:p(i,e),im:h(p(a,e))}}return{re:i,im:a}}case"func":throw new Error(`Chalkboard.comp.parse: Symbolic splitting for function '${e.name}' not supported.`)}throw new Error(`Chalkboard.comp.parse: Unsupported node type '${e.type}' in symbolic splitting.`)};try{const a=(e=>{let t=0;const r=()=>e[t]||"",n=r=>{if(r&&e[t]!==r)throw new Error(`Chalkboard.comp.parse: Expected token '${r}' but found '${e[t]}'`);return e[t++]},o=()=>i(),i=()=>{let e=a();for(;"+"===r()||"-"===r();)e={type:"+"===n()?"add":"sub",left:e,right:a()};return e},a=()=>{let e=s();for(;"*"===r()||"/"===r();)e={type:"*"===n()?"mul":"div",left:e,right:s()};return e},s=()=>"-"===r()?(n("-"),{type:"neg",expr:l()}):"+"===r()?(n("+"),l()):l(),l=()=>{let e=m();return"^"===r()&&(n("^"),e={type:"pow",base:e,exponent:u()}),e},u=()=>"-"===r()?(n("-"),{type:"neg",expr:u()}):"+"===r()?(n("+"),u()):l(),m=()=>{const e=r();if(/^-?[0-9]/.test(e)||/^-?\.[0-9]/.test(e))return n(),{type:"num",value:parseFloat(e)};if("i"===e)return n(),{type:"complex",a:0,b:1};if(/^[a-zA-Z_]/.test(e)){const e=n();if("("===r()){n("(");const t=[];if(")"!==r())for(t.push(o());","===r();)n(","),t.push(o());return n(")"),{type:"func",name:e,args:t}}return{type:"var",name:e}}if("("===e){n("(");const e=o();return n(")"),e}throw new Error(`Chalkboard.comp.parse: Unexpected token ${e}`)},f=o();if(t<e.length)throw new Error(`Chalkboard.comp.parse: Unexpected token ${e[t]}`);return f})((t=>{const r=[];let n=0;const o=["sin","cos","tan","abs","sq","sqrt","root","ln","exp","conj","conjugate","invert","mag","arg","re","im"],i=t=>o.includes(t)||void 0!==e.REGISTRY[t];for(;n<t.length;){const e=t[n];if(/\s/.test(e))n++;else if(-1!=="+-*/(),^".indexOf(e))r.push(e),n++,")"===e&&n<t.length&&/[a-zA-Z0-9_i(]/.test(t[n])&&"*"!==r[r.length-1]&&r.push("*");else if("i"!==e||0!==n&&/[a-zA-Z0-9_]/.test(t[n-1]))if(/[0-9]/.test(e)||"."===e&&/[0-9]/.test(t[n+1])){let e="",o=!1;for(;n<t.length&&(/[0-9]/.test(t[n])||"."===t[n]&&!o);)"."===t[n]&&(o=!0),e+=t[n++];r.push(e),n<t.length&&"i"===t[n]&&("*"!==r[r.length-1]&&r.push("*"),r.push("i"),n++),n<t.length&&(/[a-zA-Z_]/.test(t[n])||"("===t[n])&&"*"!==r[r.length-1]&&r.push("*")}else{if(!/[a-zA-Z_]/.test(e))throw new Error(`Chalkboard.comp.parse: Unexpected character ${e}`);{let e="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)e+=t[n++];if(/^[a-zA-Z]+$/.test(e)&&e.length>1&&!i(e))for(let t=0;t<e.length;t++)r.push(e[t]),t<e.length-1&&r.push("*");else r.push(e);n<t.length&&"("===t[n]?i(e)||"*"!==r[r.length-1]&&r.push("*"):n<t.length&&/[a-zA-Z_]/.test(t[n])&&"*"!==r[r.length-1]&&r.push("*")}}else r.push("i"),n++,n<t.length&&/[a-zA-Z0-9_(]/.test(t[n])&&"*"!==r[r.length-1]&&r.push("*")}return r})(t)),u=e=>{switch(e.type){case"var":return!0;case"num":case"complex":default:return!1;case"neg":return u(e.expr);case"add":case"sub":case"mul":case"div":return u(e.left)||u(e.right);case"pow":return u(e.base)||u(e.exponent);case"func":return e.args.some(u)}};if(!r.returnAST&&!r.returnJSON){const t=r.values||{};if(r.values&&Object.keys(r.values).length>0||!u(a))try{let o=n(a,t);return void 0!==r.roundTo&&(o=e.comp.init(e.numb.roundTo(o.a,r.roundTo),e.numb.roundTo(o.b,r.roundTo))),r.returnLaTeX?i({type:"complex",a:o.a,b:o.b}):o}catch(e){}}if(l(a))return e.real.parse(t,{roundTo:r.roundTo,returnAST:r.returnAST,returnJSON:r.returnJSON,returnLaTeX:r.returnLaTeX});if(!r.returnAST&&!r.returnJSON)try{const t=g(a),n=y(t.re),o=y(t.im);if(n.includes("i")||o.includes("i"))throw new Error("Chalkboard.comp.parse: Internal error: 'i' leaked into real split.");const i=b(n),s=b(o);if(r.returnLaTeX){const t=e.real.parse(n,{returnLaTeX:!0,roundTo:r.roundTo}),i=e.real.parse(o,{returnLaTeX:!0,roundTo:r.roundTo});return"0"===i.trim()?t:"0"===t.trim()?`${i}i`:`${t} + ${String.raw`\left(${i}\right)`}i`}return((e,t)=>{const r=e.trim(),n=t.trim(),o=e=>"0"===e||"0.0"===e,i=e=>e.includes(" + ")||e.includes(" - ");if(o(n))return r;if(o(r))return"1"===n?"i":"-1"===n?"-i":i(n)?`(${n})i`:`${n}i`;const a="1"===n?"i":"-1"===n?"-i":i(n)?`(${n})i`:`${n}i`;if(!i(n)&&n.startsWith("-")){const e=n.slice(1);return"1"===e?`${r} - i`:`${r} - ${e}i`}return a.startsWith("-")?`${r} - ${a.slice(1)}`:`${r} + ${a}`})(i,s)}catch(e){}let m=s(a);if(m=s(m),void 0!==r.roundTo){const t=n=>{if("num"===n.type)return{...n,value:e.numb.roundTo(n.value,r.roundTo)};if("complex"===n.type)return{...n,a:e.numb.roundTo(n.a,r.roundTo),b:e.numb.roundTo(n.b,r.roundTo)};const o=Object.keys(n).length;for(let e=0;e<o;e++){const r=Object.keys(n)[e];"type"!==r&&n[r]&&"object"==typeof n[r]&&"type"in n[r]&&(n[r]=t(n[r]))}return n};m=t(m)}return r.returnAST?m:r.returnJSON?JSON.stringify(m):r.returnLaTeX?i(m):o(m)}catch(e){throw e instanceof Error?new Error(`Chalkboard.comp.parse: Error parsing complex expression ${e.message}`):new Error(`Chalkboard.comp.parse: Error parsing complex expression ${String(e)}`)}},r.pow=(t,r)=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const n=t,o=e.comp.mag(n),i=e.comp.arg(n);return e.comp.init(e.real.pow(o,r)*e.trig.cos(r*i),e.real.pow(o,r)*e.trig.sin(r*i))}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.pow: Property 'field' of 'comp' must be 'comp'.");const n=t.rule,o=[(t,o)=>{const i=e.real.sqrt(n[0](t,o)*n[0](t,o)+n[1](t,o)*n[1](t,o)),a=e.trig.arctan2(n[1](t,o),n[0](t,o));return e.real.pow(i,r)*e.trig.cos(r*a)},(t,o)=>{const i=e.real.sqrt(n[0](t,o)*n[0](t,o)+n[1](t,o)*n[1](t,o)),a=e.trig.arctan2(n[1](t,o),n[0](t,o));return e.real.pow(i,r)*e.trig.sin(r*a)}];return e.comp.define(...o)}throw new TypeError("Chalkboard.comp.pow: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.print=t=>{console.log(e.comp.toString(t))},r.random=(t=0,r=1)=>e.comp.init(e.numb.random(t,r),e.numb.random(t,r)),r.Re=e=>e.hasOwnProperty("rule")?e.rule[0]:e.a,r.reciprocate=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(1/r.a,1/r.b)}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.reciprocate: Property 'field' of 'comp' must be 'comp'.");const r=t.rule,n=[(e,t)=>1/r[0](e,t),(e,t)=>1/r[1](e,t)];return e.comp.define(...n)}throw new TypeError("Chalkboard.comp.reciprocate: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.root=(t,r=3)=>{const n=[],o=e.comp.mag(t),i=e.comp.arg(t);for(let t=0;t<r;t++)n.push(e.comp.init(e.real.root(o,r)*e.trig.cos((i+e.PI(2*t))/r),e.real.root(o,r)*e.trig.sin((i+e.PI(2*t))/r)));return n},r.rotate=(t,r)=>e.comp.init(e.comp.mag(t)*e.trig.cos(e.comp.arg(t)+r),e.comp.mag(t)*e.trig.sin(e.comp.arg(t)+r)),r.round=t=>e.comp.init(Math.round(t.a),Math.round(t.b)),r.scl=(t,r)=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const n=t;return e.comp.init(n.a*r,n.b*r)}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.scl: Property 'field' of 'comp' must be 'comp'.");const n=t.rule,o=[(e,t)=>n[0](e,t)*r,(e,t)=>n[1](e,t)*r];return e.comp.define(...o)}throw new TypeError("Chalkboard.comp.scl: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.sin=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(e.trig.sin(r.a)*e.trig.cosh(r.b),e.trig.cos(r.a)*e.trig.sinh(r.b))}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.sin: Property 'field' of 'comp' must be 'comp'.");const r=t.rule;return e.comp.define((t,n)=>{const o=r[0](t,n),i=r[1](t,n);return e.trig.sin(o)*e.trig.cosh(i)},(t,n)=>{const o=r[0](t,n),i=r[1](t,n);return e.trig.cos(o)*e.trig.sinh(i)})}throw new TypeError("Chalkboard.comp.sin: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.slope=e=>e.b/e.a,r.sq=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(r.a*r.a-r.b*r.b,2*r.a*r.b)}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.sq: Property 'field' of 'comp' must be 'comp'.");const r=t.rule,n=[(e,t)=>r[0](e,t)*r[0](e,t)-r[1](e,t)*r[1](e,t),(e,t)=>2*r[0](e,t)*r[1](e,t)];return e.comp.define(...n)}throw new TypeError("Chalkboard.comp.sq: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.sqrt=t=>{if("number"==typeof t&&(t=e.comp.init(t,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")){const r=t;return e.comp.init(e.real.sqrt((r.a+e.real.sqrt(r.a*r.a+r.b*r.b))/2),e.numb.sgn(r.b)*e.real.sqrt((-r.a+e.real.sqrt(r.a*r.a+r.b*r.b))/2))}if(t.hasOwnProperty("rule")){if("comp"!==t.field)throw new TypeError("Chalkboard.comp.sqrt: Property 'field' of 'comp' must be 'comp'.");const r=t.rule,n=[(t,n)=>{const o=r[0](t,n),i=r[1](t,n);return e.real.sqrt((o+e.real.sqrt(o*o+i*i))/2)},(t,n)=>{const o=r[0](t,n),i=r[1](t,n);return e.numb.sgn(i)*e.real.sqrt((-o+e.real.sqrt(o*o+i*i))/2)}];return e.comp.define(...n)}throw new TypeError("Chalkboard.comp.sqrt: Parameter 'comp' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.sub=(t,r)=>{if("number"==typeof t&&(t=e.comp.init(t,0)),"number"==typeof r&&(r=e.comp.init(r,0)),t.hasOwnProperty("a")&&t.hasOwnProperty("b")&&r.hasOwnProperty("a")&&r.hasOwnProperty("b")){const n=t,o=r;return e.comp.init(n.a-o.a,n.b-o.b)}if(t.hasOwnProperty("rule")||r.hasOwnProperty("rule")){if("comp"!==t.field||"comp"!==r.field)throw new TypeError("Chalkboard.comp.sub: Properties 'field' of 'comp1' and 'comp2' must be 'comp'.");const n=t.rule,o=r.rule,i=[(e,t)=>n[0](e,t)-o[0](e,t),(e,t)=>n[1](e,t)-o[1](e,t)];return e.comp.define(...i)}throw new TypeError("Chalkboard.comp.sub: Parameters 'comp1' and 'comp2' must be of type ChalkboardComplex, number, or ChalkboardFunction.")},r.tan=t=>e.comp.div(e.comp.sin(t),e.comp.cos(t)),r.toArray=e=>[e.a,e.b],r.toMatrix=t=>e.matr.init([t.a,-t.b],[t.b,t.a]),r.toString=e=>1===e.a&&0===e.b?"1":0===e.a&&1===e.b?"i":-1===e.a&&0===e.b?"-1":0===e.a&&-1===e.b?"-i":e.b>=0?e.a.toString()+" + "+(1===e.b?"i":e.b.toString()+"i"):e.a.toString()+" - "+(-1===e.b?"i":Math.abs(e.b).toString()+"i"),r.toTypedArray=(t,r="float32")=>{const n=e.comp.toArray(t);if("int8"===r)return new Int8Array(n);if("int16"===r)return new Int16Array(n);if("int32"===r)return new Int32Array(n);if("float32"===r)return new Float32Array(n);if("float64"===r)return new Float64Array(n);if("bigint64"===r)return new BigInt64Array(n.map(e=>BigInt(Math.floor(e))));throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".')},r.toVector=t=>e.vect.init(t.a,t.b),r.val=(t,r)=>{if("comp"!==t.field)throw new TypeError("Chalkboard.comp.val: Property 'field' of 'func' must be 'comp'.");const n=t.rule;return e.comp.init(n[0](r.a,r.b),n[1](r.a,r.b))}}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){t.at=(e,t)=>{if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.diff.at: Parameter "time" must be a finite number.');const r=e.t,n=e.y;if(r.length!==n.length||0===r.length)throw new Error("Chalkboard.diff.at: Invalid solution object.");if(t<=r[0])return n[0].slice();if(t>=r[r.length-1])return n[n.length-1].slice();let o=0;for(;o<r.length-1&&!(r[o]<=t&&t<=r[o+1]);)o++;const i=r[o],a=(t-i)/(r[o+1]-i),s=[];for(let e=0;e<n[o].length;e++)s.push((1-a)*n[o][e]+a*n[o+1][e]);return s},t.Bernoulli=(t,r,n)=>{if("number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.Bernoulli: Parameter "n" must be a finite number.');const o="number"==typeof t?e=>t:t,i="number"==typeof r?e=>r:r;return e.diff.init((e,t)=>-o(e)*t+i(e)*Math.pow(t,n))},t.BesselI=(t=0)=>{if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.diff.BesselI: Parameter "nu" must be a finite number.');return e.diff.init((e,r,n)=>{if(0===e)throw new Error("Chalkboard.diff.BesselI: Singular at t = 0.");return-1/e*n+(1+t*t/(e*e))*r})},t.BesselJ=(t=0)=>{if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.diff.BesselJ: Parameter "nu" must be a finite number.');return e.diff.init((e,r,n)=>{if(0===e)throw new Error("Chalkboard.diff.BesselJ: Singular at t = 0.");return-1/e*n-(1-t*t/(e*e))*r})},t.closestIndex=(e,t)=>{if(!Array.isArray(e)||0===e.length)throw new Error('Chalkboard.diff.closestIndex: Parameter "t" must be a non-empty array.');if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.diff.closestIndex: Parameter "target" must be a finite number.');let r=0,n=Math.abs(e[0]-t);for(let o=1;o<e.length;o++){const i=Math.abs(e[o]-t);i<n&&(n=i,r=o)}return r},t.component=(e,t)=>{if(!Number.isInteger(t)||t<0)throw new Error('Chalkboard.diff.component: Parameter "index" must be an integer >= 0.');const r=[];for(let n=0;n<e.y.length;n++){if(t>=e.y[n].length)throw new Error('Chalkboard.diff.component: "index" out of range for solution dimension.');r.push(e.y[n][t])}return r},t.derivative=e=>{if(!e||!Array.isArray(e.t)||!Array.isArray(e.y))throw new Error("Chalkboard.diff.derivative: Invalid solution object.");const t=e.t,r=e.y;if(t.length!==r.length||t.length<2)throw new Error("Chalkboard.diff.derivative: Need at least 2 samples.");const n=r[0].length,o=new Array(r.length);for(let e=0;e<r.length;e++)o[e]=new Array(n).fill(0);for(let e=0;e<r.length;e++)if(0===e){const i=t[1]-t[0];for(let t=0;t<n;t++)o[e][t]=(r[1][t]-r[0][t])/i}else if(e===r.length-1){const i=t[t.length-1]-t[t.length-2];for(let t=0;t<n;t++)o[e][t]=(r[r.length-1][t]-r[r.length-2][t])/i}else{const i=t[e+1]-t[e-1];for(let t=0;t<n;t++)o[e][t]=(r[e+1][t]-r[e-1][t])/i}return o},t.Duffing=(t,r,n,o,i)=>{if(![t,r,n,o,i].every(e=>"number"==typeof e&&Number.isFinite(e)))throw new Error("Chalkboard.diff.Duffing: Parameters must be finite numbers.");return e.diff.init((e,a,s)=>-t*s-r*a-n*a*a*a+o*Math.cos(i*e))},t.error=(t,r,n="L2")=>{if(!t||!Array.isArray(t.t)||!Array.isArray(t.y))throw new Error("Chalkboard.diff.error: Invalid solution object.");if(t.t.length!==t.y.length)throw new Error('Chalkboard.diff.error: "sol.t" and "sol.y" must have the same length.');if(t.t.length<2)throw new Error("Chalkboard.diff.error: Need at least 2 samples to estimate derivative.");if(!r||"object"!=typeof r||"function"!=typeof r.rule)throw new Error('Chalkboard.diff.error: Parameter "ode" must be a ChalkboardODE.');if(-1===["L1","L2","LInfinity"].indexOf(n))throw new Error("Chalkboard.diff.error: Unknown norm type.");const o=t.t,i=t.y,a=i[0].length;if(!Number.isInteger(r.dimension)||r.dimension!==a)throw new Error('Chalkboard.diff.error: "ode.dimension" must match solution dimension.');const s=e.diff.derivative(t),l=[];let u=0,m=0,f=0;for(let e=0;e<o.length;e++){const t=r.rule(o[e],i[e]);if(!Array.isArray(t)||t.length!==a)throw new Error(`Chalkboard.diff.error: ODE rule returned invalid derivative at sample ${e}.`);const c=new Array(a);for(let r=0;r<a;r++)if(c[r]=s[e][r]-t[r],"number"!=typeof c[r]||!Number.isFinite(c[r]))throw new Error(`Chalkboard.diff.error: Non-finite residual at sample ${e}, index ${r}.`);let p;if("L1"===n){let e=0;for(let t=0;t<a;t++)e+=Math.abs(c[t]);p=e}else if("LInfinity"===n){let e=0;for(let t=0;t<a;t++)e=Math.max(e,Math.abs(c[t]));p=e}else{let e=0;for(let t=0;t<a;t++)e+=c[t]*c[t];p=Math.sqrt(e)}l.push(p),u=Math.max(u,p),m+=p,f+=p*p}const c=m/l.length,p=Math.sqrt(f/l.length);return{t:o.slice(),e:l,max:u,mean:c,rmse:p}},t.exponential=(t=1)=>{if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.diff.exponential: Parameter "k" must be a finite number.');return e.diff.init((e,r)=>t*r)},t.Gompertz=(t=1,r=1)=>{if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.diff.Gompertz: Parameter "a" must be a finite number.');if("number"!=typeof r||!Number.isFinite(r)||r<=0)throw new Error('Chalkboard.diff.Gompertz: Parameter "K" must be greater than 0.');return e.diff.init((e,n)=>t*n*Math.log(r/n))},t.harmonic=(t=1)=>{if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new Error('Chalkboard.diff.harmonic: Parameter "w" must be a finite number greater than or equal to 0.');return e.diff.init((e,r,n)=>-t*t*r)},t.harmonicDamped=(t=1,r=.1)=>{if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new Error('Chalkboard.diff.harmonicDamped: Parameter "w" must be a finite number greater than or equal to 0.');if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new Error('Chalkboard.diff.harmonicDamped: Parameter "zeta" must be a finite number greater than or equal to 0.');return e.diff.init((e,n,o)=>-2*r*t*o-t*t*n)},t.harmonicForced=(t,r,n)=>{if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new Error('Chalkboard.diff.harmonicForced: Parameter "w" must be a finite number greater than or equal to 0.');if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new Error('Chalkboard.diff.harmonicForced: Parameter "zeta" must be a finite number greater than or equal to 0.');if("function"!=typeof n)throw new Error('Chalkboard.diff.harmonicForced: Parameter "F" must be a function.');return e.diff.init((e,o,i)=>n(e)-2*r*t*i-t*t*o)},t.init=(e,t)=>{if("function"!=typeof e)throw new Error('Chalkboard.diff.init: Parameter "rule" must be a function.');if("number"==typeof t){if(!Number.isInteger(t)||t<1)throw new Error('Chalkboard.diff.init: Parameter "dimension" must be an integer >= 1.');const r=e;return{rule:(e,n)=>{const o=r(e,n);if(!Array.isArray(o))throw new Error("Chalkboard.diff.init: System rule must return an array of numbers.");if(o.length!==t)throw new Error(`Chalkboard.diff.init: System rule must return an array of length ${t}.`);for(let e=0;e<o.length;e++)if("number"!=typeof o[e]||!Number.isFinite(o[e]))throw new Error(`Chalkboard.diff.init: System rule output must be finite numbers (index ${e}).`);return o},type:"system",order:1,dimension:t}}const r=e.length;if(2===r){const t=e;return{rule:(e,r)=>{if(1!==r.length)throw new Error("Chalkboard.diff.init: Internal error (expected dimension 1).");const n=t(e,r[0]);if("number"!=typeof n||!Number.isFinite(n))throw new Error("Chalkboard.diff.init: Scalar rule must return a finite number.");return[n]},type:"single",order:1,dimension:1}}if(3===r){const t=e;return{rule:(e,r)=>{if(2!==r.length)throw new Error("Chalkboard.diff.init: Internal error (expected dimension 2 for second-order scalar).");const n=t(e,r[0],r[1]);if("number"!=typeof n||!Number.isFinite(n))throw new Error("Chalkboard.diff.init: Second-order scalar rule must return a finite number.");return[r[1],n]},type:"single",order:2,dimension:2}}throw new Error('Chalkboard.diff.init: Invalid "rule" arity. Expected (t,y) or (t,y,dy), or provide dimension for systems.')},t.Kepler2D=(t=1)=>{if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new Error('Chalkboard.diff.Kepler2D: Parameter "mu" must be a finite number >= 0.');return e.diff.init((e,r)=>{const n=r[0],o=r[1],i=r[2],a=r[3],s=n*n+o*o,l=Math.sqrt(s);if(0===l)throw new Error("Chalkboard.diff.Kepler2D: Encountered r=0 singularity.");const u=1/(s*l);return[i,a,-t*n*u,-t*o*u]},4)},t.Kepler3D=(t=1)=>{if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new Error('Chalkboard.diff.Kepler3D: Parameter "mu" must be a finite number >= 0.');return e.diff.init((e,r)=>{const n=r[0],o=r[1],i=r[2],a=r[3],s=r[4],l=r[5],u=n*n+o*o+i*i,m=Math.sqrt(u);if(0===m)throw new Error("Chalkboard.diff.Kepler3D: Encountered r=0 singularity.");const f=1/(u*m);return[a,s,l,-t*n*f,-t*o*f,-t*i*f]},6)},t.linear1=(t,r)=>{const n="number"==typeof t?()=>t:t,o="number"==typeof r?()=>r:r;return e.diff.init((e,t)=>n(e)*t+o(e))},t.linear2=(t,r,n)=>{const o="number"==typeof t?()=>t:t,i="number"==typeof r?()=>r:r,a="number"==typeof n?()=>n:n;return e.diff.init((e,t,r)=>o(e)*r+i(e)*t+a(e))},t.logistic=(t=1,r=1)=>{if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.diff.logistic: Parameter "r" must be a finite number.');if("number"!=typeof r||!Number.isFinite(r)||0===r)throw new Error('Chalkboard.diff.logistic: Parameter "K" must be a finite non-zero number.');return e.diff.init((e,n)=>t*n*(1-n/r))},t.Lorenz=(t=10,r=28,n=8/3)=>{if(![t,r,n].every(e=>"number"==typeof e&&Number.isFinite(e)))throw new Error("Chalkboard.diff.Lorenz: Parameters must be finite numbers.");return e.diff.init((e,o)=>{const i=o[0],a=o[1],s=o[2];return[t*(a-i),i*(r-s)-a,i*a-n*s]},3)},t.LotkaVolterra=(t=1,r=1,n=1,o=1)=>{if(![t,r,n,o].every(e=>"number"==typeof e&&Number.isFinite(e)))throw new Error("Chalkboard.diff.LotkaVolterra: Parameters must be finite numbers.");return e.diff.init((e,i)=>{const a=i[0],s=i[1];return[t*a-r*a*s,o*a*s-n*s]},2)},t.massSpringDamper=(t,r,n)=>{if("number"!=typeof t||!Number.isFinite(t)||0===t)throw new Error('Chalkboard.diff.massSpringDamper: Parameter "m" must be finite and non-zero.');if("number"!=typeof r||!Number.isFinite(r))throw new Error('Chalkboard.diff.massSpringDamper: Parameter "c" must be a finite number.');if("number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.massSpringDamper: Parameter "k" must be a finite number.');return e.diff.init((e,o,i)=>-r/t*i-n/t*o)},t.pendulum=(t={})=>{const r=t.g??9.81,n=t.L??1,o=t.b??0,i=t.tau??(()=>0);if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new Error('Chalkboard.diff.pendulum: "g" must be a finite number greater than or equal to 0.');if("number"!=typeof n||!Number.isFinite(n)||0===n)throw new Error('Chalkboard.diff.pendulum: "L" must be a finite non-zero number.');if("number"!=typeof o||!Number.isFinite(o))throw new Error('Chalkboard.diff.pendulum: "b" must be a finite number.');if("function"!=typeof i)throw new Error('Chalkboard.diff.pendulum: "tau" must be a function.');return e.diff.init((e,t,a)=>i(e)-o*a-r/n*Math.sin(t))},t.pendulumDrag=(t={})=>{const r=t.g??9.81,n=t.L??1,o=t.b??0,i=t.c??0,a=t.tau??(()=>0);if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new Error('Chalkboard.diff.pendulumDrag: "g" must be a finite number greater than or equal to 0.');if("number"!=typeof n||!Number.isFinite(n)||0===n)throw new Error('Chalkboard.diff.pendulumDrag: "L" must be a finite non-zero number.');if("number"!=typeof o||!Number.isFinite(o))throw new Error('Chalkboard.diff.pendulumDrag: "b" must be a finite number.');if("number"!=typeof i||!Number.isFinite(i))throw new Error('Chalkboard.diff.pendulumDrag: "c" must be a finite number.');if("function"!=typeof a)throw new Error('Chalkboard.diff.pendulumDrag: "tau" must be a function.');return e.diff.init((e,t,s)=>{const l=i*Math.abs(s)*s;return a(e)-o*s-l-r/n*Math.sin(t)})},t.pendulumDriven=(t=.5,r=1.2,n=2/3)=>{if(![t,r,n].every(e=>"number"==typeof e&&Number.isFinite(e)))throw new Error("Chalkboard.diff.pendulumDriven: Parameters must be finite numbers.");return e.diff.init((e,o,i)=>r*Math.cos(n*e)-t*i-Math.sin(o))},t.phase=(e,t,r)=>{if(!e||!Array.isArray(e.t)||!Array.isArray(e.y))throw new Error("Chalkboard.diff.phase: Invalid solution object.");if(e.t.length!==e.y.length)throw new Error('Chalkboard.diff.phase: "sol.t" and "sol.y" must have the same length.');if(0===e.y.length)throw new Error("Chalkboard.diff.phase: Solution has no samples.");if(!Number.isInteger(t)||t<0)throw new Error('Chalkboard.diff.phase: Parameter "i" must be an integer >= 0.');if(!Number.isInteger(r)||r<0)throw new Error('Chalkboard.diff.phase: Parameter "j" must be an integer >= 0.');if(t===r)throw new Error('Chalkboard.diff.phase: Parameters "i" and "j" must be different indices.');if(t>=e.y[0].length||r>=e.y[0].length)throw new Error("Chalkboard.diff.phase: Indices out of bounds for solution dimension.");const n=[];for(let o=0;o<e.y.length;o++){const i=e.y[o];n.push([i[t],i[r]])}return n},t.sample=(t,r)=>{if(!t||!Array.isArray(t.t)||!Array.isArray(t.y))throw new Error("Chalkboard.diff.sample: Invalid solution object.");if(!Array.isArray(r))throw new Error('Chalkboard.diff.sample: Parameter "times" must be an array.');const n=[];for(let o=0;o<r.length;o++){if("number"!=typeof r[o]||!Number.isFinite(r[o]))throw new Error(`Chalkboard.diff.sample: "times"[${o}] must be a finite number.`);n.push(e.diff.at(t,r[o]))}return n},t.separable=(t,r)=>{if("function"!=typeof t||"function"!=typeof r)throw new Error("Chalkboard.diff.separable: Parameters must be functions.");return e.diff.init((e,n)=>t(e)*r(n))},t.SEIR=(t=1,r=1,n=1)=>{if(![t,r,n].every(e=>"number"==typeof e&&Number.isFinite(e)))throw new Error("Chalkboard.diff.SEIR: Parameters must be finite numbers.");return e.diff.init((e,o)=>{const i=o[0],a=o[1],s=o[2],l=(o[3],t*i*s);return[-l,l-r*a,r*a-n*s,n*s]},4)},t.SIR=(t=1,r=1)=>{if(![t,r].every(e=>"number"==typeof e&&Number.isFinite(e)))throw new Error("Chalkboard.diff.SIR: Parameters must be finite numbers.");return e.diff.init((e,n)=>{const o=n[0],i=n[1];n[2];return[-t*o*i,t*o*i-r*i,r*i]},3)},t.SIS=(t=1,r=.5)=>{if(![t,r].every(e=>"number"==typeof e&&Number.isFinite(e)))throw new Error("Chalkboard.diff.SIS: Parameters must be finite numbers.");return e.diff.init((e,n)=>t*n*(1-n)-r*n)},t.solve=(t,r)=>{if(!t||"object"!=typeof t)throw new Error('Chalkboard.diff.solve: Parameter "ode" must be a ChalkboardODE.');if("function"!=typeof t.rule)throw new Error('Chalkboard.diff.solve: "ode.rule" must be a function.');if(!Number.isInteger(t.dimension)||t.dimension<1)throw new Error('Chalkboard.diff.solve: "ode.dimension" must be an integer >= 1.');if("object"!=typeof r||null===r)throw new Error('Chalkboard.diff.solve: Parameter "config" must be an object.');if("number"!=typeof r.t1||!Number.isFinite(r.t1))throw new Error('Chalkboard.diff.solve: "config.t1" must be a finite number.');const n=r.t0??0;if("number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.solve: "config.t0" must be a finite number.');if(r.t1===n)throw new Error('Chalkboard.diff.solve: "config.t1" must be different from "config.t0".');const o=(r.method??"rk4").toLowerCase();if(-1===["euler","midpoint","heun","ralston","rk4"].indexOf(o))throw new Error("Chalkboard.diff.solve: Unknown method.");let i,a,s,l;if("number"==typeof r.y0&&Number.isFinite(r.y0)){if(1!==t.dimension)throw new Error('Chalkboard.diff.solve: Scalar "y0" is only allowed when "ode.dimension" === 1.');i=[r.y0]}else if(Array.isArray(r.y0)){if(r.y0.length!==t.dimension)throw new Error(`Chalkboard.diff.solve: Array "y0" must have length ${t.dimension}.`);for(let e=0;e<r.y0.length;e++)if("number"!=typeof r.y0[e]||!Number.isFinite(r.y0[e]))throw new Error(`Chalkboard.diff.solve: "y0"[${e}] must be a finite number.`);i=r.y0.slice()}else{if("object"!=typeof r.y0||null===r.y0)throw new Error('Chalkboard.diff.solve: "y0" must be of type number, number[], or object.');const e=r.y0;if("single"===t.type&&2===t.order)if("y0"in e&&"dy0"in e){const t=e.y0,n=e.dy0;if("number"!=typeof t||!Number.isFinite(t)||"number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.solve: For second-order scalar, "y0.y0" and "y0.dy0" must be finite numbers.');i=[t,n],r.returnObject&&(a=["y","dy"])}else{if(!("y"in e)||!("dy"in e))throw new Error("Chalkboard.diff.solve: For second-order scalar, provide initial conditions as { y0, dy0 } or { y, dy }.");{const t=e.y,n=e.dy;if("number"!=typeof t||!Number.isFinite(t)||"number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.solve: For second-order scalar, "y0.y" and "y0.dy" must be finite numbers.');i=[t,n],r.returnObject&&(a=["y","dy"])}}else if(1===t.dimension&&"y0"in e&&"number"==typeof e.y0&&Number.isFinite(e.y0))i=[e.y0],r.returnObject&&(a=["y"]);else if(1===t.dimension&&"y"in e&&"number"==typeof e.y&&Number.isFinite(e.y))i=[e.y],r.returnObject&&(a=["y"]);else if("y0"in e&&Array.isArray(e.y0)){const r=e.y0;if(r.length!==t.dimension)throw new Error(`Chalkboard.diff.solve: Object "y0.y0" must have length ${t.dimension}.`);for(let e=0;e<r.length;e++)if("number"!=typeof r[e]||!Number.isFinite(r[e]))throw new Error(`Chalkboard.diff.solve: y0.y0[${e}] must be a finite number.`);i=r.slice()}else{if(a=Object.keys(r.y0).sort(),a.length!==t.dimension)throw new Error(`Chalkboard.diff.solve: Object "y0" must have exactly ${t.dimension} numeric properties (got ${a.length}).`);const e=[];for(let t=0;t<a.length;t++){const n=r.y0[a[t]];if("number"!=typeof n||!Number.isFinite(n))throw new Error(`Chalkboard.diff.solve: y0.${a[t]} must be a finite number.`);e.push(n)}i=e}}if(r.returnObject&&!a&&(a="single"===t.type&&2===t.order&&2===t.dimension?["y","dy"]:1===t.dimension?["y"]:Array.from({length:t.dimension},(e,t)=>`y${t+1}`)),"number"==typeof r.h){if("number"!=typeof r.h||!Number.isFinite(r.h)||0===r.h)throw new Error('Chalkboard.diff.solve: "config.h" must be a finite non-zero number.');s=r.h,l=Math.max(1,Math.floor(Math.abs((r.t1-n)/s))),s=(r.t1-n)/l}else{if("number"!=typeof r.steps)throw new Error('Chalkboard.diff.solve: Provide either "config.h" or "config.steps".');if(!Number.isInteger(r.steps)||r.steps<1)throw new Error('Chalkboard.diff.solve: "config.steps" must be an integer greater than or equal to 1.');l=r.steps,s=(r.t1-n)/l}const u=(t,r)=>e.stat.add(t,r),m=(t,r)=>e.stat.scl(t,r),f=t.rule,c=new Array(l+1),p=new Array(l+1);c[0]=n,p[0]=i.slice();const d="euler"===o?(e,t,r,n)=>{const o=e(t,r);return u(r,m(o,n))}:"midpoint"===o?(e,t,r,n)=>{const o=e(t,r),i=e(t+n/2,u(r,m(o,n/2)));return u(r,m(i,n))}:"heun"===o?(e,t,r,n)=>{const o=e(t,r),i=e(t+n,u(r,m(o,n)));return u(r,m(u(o,i),n/2))}:"ralston"===o?(e,t,r,n)=>{const o=e(t,r),i=e(t+2/3*n,u(r,m(o,2/3*n)));return u(r,m(u(m(o,1/4),m(i,3/4)),n))}:(e,t,r,n)=>{const o=e(t,r),i=e(t+n/2,u(r,m(o,n/2))),a=e(t+n/2,u(r,m(i,n/2))),s=e(t+n,u(r,m(a,n))),l=u(m(i,2),m(a,2)),f=u(u(o,l),s);return u(r,m(f,n/6))};for(let e=0;e<l;e++){const r=c[e],n=d(f,r,p[e],s);if(!Array.isArray(n)||n.length!==t.dimension)throw new Error(`Chalkboard.diff.solve: Internal step produced invalid state length (expected ${t.dimension}).`);for(let t=0;t<n.length;t++)if("number"!=typeof n[t]||!Number.isFinite(n[t]))throw new Error(`Chalkboard.diff.solve: State became non-finite at step ${e+1}, index ${t}.`);c[e+1]=r+s,p[e+1]=n}const h={t:c,y:p};return r.returnObject&&a&&a.length===t.dimension&&(h.yObj=p.map(e=>{const t={};for(let r=0;r<a.length;r++)t[a[r]]=e[r];return t})),h},t.solveAdaptive=(t,r)=>{if(!t||"object"!=typeof t)throw new Error('Chalkboard.diff.solveAdaptive: Parameter "ode" must be a ChalkboardODE.');if("function"!=typeof t.rule)throw new Error('Chalkboard.diff.solveAdaptive: "ode.rule" must be a function.');if(!Number.isInteger(t.dimension)||t.dimension<1)throw new Error('Chalkboard.diff.solveAdaptive: "ode.dimension" must be an integer >= 1.');if("object"!=typeof r||null===r)throw new Error('Chalkboard.diff.solveAdaptive: Parameter "config" must be an object.');if("number"!=typeof r.t1||!Number.isFinite(r.t1))throw new Error('Chalkboard.diff.solveAdaptive: "config.t1" must be a finite number.');const n=r.t0??0;if("number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.solveAdaptive: "config.t0" must be a finite number.');if(r.t1===n)throw new Error('Chalkboard.diff.solveAdaptive: "config.t1" must be different from "config.t0".');const o=r.rtol??1e-6,i=r.atol??1e-9;if("number"!=typeof o||!Number.isFinite(o)||o<=0)throw new Error('Chalkboard.diff.solveAdaptive: "rtol" must be > 0.');if("number"!=typeof i||!Number.isFinite(i)||i<0)throw new Error('Chalkboard.diff.solveAdaptive: "atol" must be >= 0.');const a=r.maxSteps??1e5;if(!Number.isInteger(a)||a<1)throw new Error('Chalkboard.diff.solveAdaptive: "maxSteps" must be an integer >= 1.');let s,l;if("number"==typeof r.y0&&Number.isFinite(r.y0)){if(1!==t.dimension)throw new Error('Chalkboard.diff.solveAdaptive: Scalar "y0" is only allowed when "ode.dimension" === 1.');s=[r.y0]}else if(Array.isArray(r.y0)){if(r.y0.length!==t.dimension)throw new Error(`Chalkboard.diff.solveAdaptive: Array "y0" must have length ${t.dimension}.`);for(let e=0;e<r.y0.length;e++)if("number"!=typeof r.y0[e]||!Number.isFinite(r.y0[e]))throw new Error(`Chalkboard.diff.solveAdaptive: "y0"[${e}] must be a finite number.`);s=r.y0.slice()}else{if("object"!=typeof r.y0||null===r.y0)throw new Error('Chalkboard.diff.solveAdaptive: "y0" must be of type number, number[], or object.');const e=r.y0;if("single"===t.type&&2===t.order)if("y0"in e&&"dy0"in e){const t=e.y0,n=e.dy0;if("number"!=typeof t||!Number.isFinite(t)||"number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.solveAdaptive: For second-order scalar, "y0.y0" and "y0.dy0" must be finite numbers.');s=[t,n],r.returnObject&&(l=["y","dy"])}else{if(!("y"in e)||!("dy"in e))throw new Error("Chalkboard.diff.solveAdaptive: For second-order scalar, provide initial conditions as { y0, dy0 } or { y, dy }.");{const t=e.y,n=e.dy;if("number"!=typeof t||!Number.isFinite(t)||"number"!=typeof n||!Number.isFinite(n))throw new Error('Chalkboard.diff.solveAdaptive: For second-order scalar, "y0.y" and "y0.dy" must be finite numbers.');s=[t,n],r.returnObject&&(l=["y","dy"])}}else if(1===t.dimension&&"y0"in e&&"number"==typeof e.y0&&Number.isFinite(e.y0))s=[e.y0],r.returnObject&&(l=["y"]);else if(1===t.dimension&&"y"in e&&"number"==typeof e.y&&Number.isFinite(e.y))s=[e.y],r.returnObject&&(l=["y"]);else if("y0"in e&&Array.isArray(e.y0)){const r=e.y0;if(r.length!==t.dimension)throw new Error(`Chalkboard.diff.solveAdaptive: Object "y0.y0" must have length ${t.dimension}.`);for(let e=0;e<r.length;e++)if("number"!=typeof r[e]||!Number.isFinite(r[e]))throw new Error(`Chalkboard.diff.solveAdaptive: y0.y0[${e}] must be a finite number.`);s=r.slice()}else{if(l=Object.keys(r.y0).sort(),l.length!==t.dimension)throw new Error(`Chalkboard.diff.solveAdaptive: Object "y0" must have exactly ${t.dimension} numeric properties (got ${l.length}).`);const e=[];for(let t=0;t<l.length;t++){const n=r.y0[l[t]];if("number"!=typeof n||!Number.isFinite(n))throw new Error(`Chalkboard.diff.solveAdaptive: y0.${l[t]} must be a finite number.`);e.push(n)}s=e}}r.returnObject&&!l&&(l="single"===t.type&&2===t.order&&2===t.dimension?["y","dy"]:1===t.dimension?["y"]:Array.from({length:t.dimension},(e,t)=>`y${t+1}`));const u=Math.sign(r.t1-n);let m=r.h0??(r.t1-n)/100;if("number"!=typeof m||!Number.isFinite(m)||0===m)throw new Error('Chalkboard.diff.solveAdaptive: "h0" must be a finite non-zero number (or omitted).');m=Math.abs(m)*u;const f=r.hMin??1e-12,c=r.hMax??Math.abs(r.t1-n);if("number"!=typeof f||!Number.isFinite(f)||f<=0)throw new Error('Chalkboard.diff.solveAdaptive: "hMin" must be > 0.');if("number"!=typeof c||!Number.isFinite(c)||c<=0)throw new Error('Chalkboard.diff.solveAdaptive: "hMax" must be > 0.');const p=(e,t,r)=>(Math.sign(e)||1)*Math.min(r,Math.max(t,Math.abs(e))),d=(t,r)=>e.stat.add(t,r),h=(t,r)=>e.stat.scl(t,r),y=t.rule,b=[n],g=[s.slice()],w=8/9,v=44/45,x=-56/15,E=32/9,k=19372/6561,C=-25360/2187,z=64448/6561,P=-212/729,A=9017/3168,S=-355/33,T=46732/5247,M=49/176,I=-5103/18656,O=35/384,q=500/1113,N=125/192,$=-2187/6784,F=11/84,D=35/384,j=500/1113,R=125/192,W=-2187/6784,L=11/84,Z=5179/57600,V=7571/16695,Q=-92097/339200,G=187/2100,B=(e,t,r)=>{let n=0;for(let o=0;o<e.length;o++){const i=Math.abs(e[o]-t[o])/r[o];i>n&&(n=i)}return n},J=(e,t)=>{const r=[];for(let n=0;n<e.length;n++)r.push(i+o*Math.max(Math.abs(e[n]),Math.abs(t[n])));return r};let U=0;for(;U<a;){U++;const e=b[b.length-1],t=g[g.length-1];if(u>0&&e>=r.t1||u<0&&e<=r.t1)break;const n=r.t1-e;Math.abs(m)>Math.abs(n)&&(m=n),m=p(m,f,c);const o=y(e,t),i=y(e+.2*m,d(t,h(o,.2*m))),a=y(e+.3*m,d(d(t,h(o,.075*m)),h(i,.225*m))),s=y(e+.8*m,d(d(d(t,h(o,m*v)),h(i,m*x)),h(a,m*E))),l=y(e+w*m,d(d(d(d(t,h(o,m*k)),h(i,m*C)),h(a,m*z)),h(s,m*P))),K=y(e+1*m,d(d(d(d(d(t,h(o,m*A)),h(i,m*S)),h(a,m*T)),h(s,m*M)),h(l,m*I))),H=y(e+1*m,d(d(d(d(d(d(t,h(o,m*O)),h(i,0*m)),h(a,m*q)),h(s,m*N)),h(l,m*$)),h(K,m*F))),Y=d(t,h(d(d(d(h(o,D),h(i,0)),d(h(a,j),h(s,R))),d(d(h(l,W),h(K,L)),h(H,0))),m)),X=B(Y,d(t,h(d(d(d(h(o,Z),h(i,0)),d(h(a,V),h(s,.6140625))),d(d(h(l,Q),h(K,G)),h(H,.025))),m)),J(t,Y)),_=.9,ee=.2,te=5;if(X<=1){const t=e+m;b.push(t),g.push(Y);m*=0===X?te:Math.min(te,Math.max(ee,_*Math.pow(1/X,.2)))}else{if(m*=Math.min(1,Math.max(ee,_*Math.pow(1/X,.2))),Math.abs(m)<f)throw new Error("Chalkboard.diff.solveAdaptive: Step size underflow (h < hMin).")}}if(U>=a)throw new Error(`Chalkboard.diff.solveAdaptive: Exceeded maxSteps=${a}.`);const K={t:b,y:g};return r.returnObject&&l&&l.length===t.dimension&&(K.yObj=g.map(e=>{const t={};for(let r=0;r<l.length;r++)t[l[r]]=e[r];return t})),K},t.toScalarSeries=e=>{const t=[];for(let r=0;r<e.y.length;r++)t.push(e.y[r][0]);return t}}(t=e.diff||(e.diff={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){t.circleA=t=>e.PI()*t*t,t.circleP=t=>2*e.PI()*t,t.coneA=(t,r)=>e.PI()*t*(t+e.real.sqrt(r*r+t*t)),t.coneV=(t,r)=>e.PI()*t*t*r/3,t.cubeA=e=>6*e*e,t.cubeV=e=>e*e*e,t.cylinderA=(t,r)=>2*e.PI()*t*t+2*e.PI()*t*r,t.cylinderV=(t,r)=>e.PI()*t*t*r,t.dist=(t,r)=>{if(t.length===r.length){let n=0;for(let e=0;e<t.length;e++)n+=(t[e]-r[e])*(t[e]-r[e]);return e.real.sqrt(n)}throw new RangeError('Parameters "p1" and "p2" must be of type "number[]" with the same "length" property.')},t.distsq=(e,t)=>{if(e.length===t.length){let r=0;for(let n=0;n<e.length;n++)r+=(e[n]-t[n])*(e[n]-t[n]);return r}throw new RangeError('Parameters "p1" and "p2" must be of type "number[]" with the same "length" property.')},t.ellipseA=(t,r)=>e.PI()*t*r,t.ellipseP=(t,r)=>{const n=(t-r)*(t-r)/((t+r)*(t+r));return e.PI()*(t+r)*(1+3*n/(10+Math.sqrt(4-3*n)))},t.Euler=(e,t,r)=>e-t+r,t.line3D=(t,r,n,o,i,a,s=Function('"use strict"; return ('+e.CONTEXT+")")())=>{s.beginPath(),s.moveTo(t/(.0025*n+1),r/(.0025*n+1)),s.lineTo(o/(.0025*a+1),i/(.0025*a+1)),s.stroke()},t.mid=(e,t)=>{if(e.length===t.length){const r=[];for(let n=0;n<e.length;n++)r[n]=(e[n]+t[n])/2;return r}throw new RangeError('Parameters "p1" and "p2" must be of type "number[]" with the same "length" property.')},t.parallelogramA=(e,t)=>e*t,t.parallelogramP=(e,t)=>2*(e+t),t.polygonA=(e,t,r)=>e*t*r/2,t.polygonP=(e,t)=>e*t,t.Pythagorean=(e,t,r="hyp")=>"hyp"===r?Math.sqrt(e*e+t*t):Math.sqrt(t*t-e*e),t.PythagoreanTriple=(t,r)=>{const n=2*Math.round(e.numb.random(t,r))-1;return[n,n*n/2-.5,n*n/2+.5]},t.rectangularprismA=(e,t,r)=>2*(e*r+e*t+t*r),t.rectangularprismV=(e,t,r)=>e*t*r,t.sectorA=(e,t)=>e*e*t/2,t.sectorP=(e,t)=>e*t,t.sphereA=t=>4*e.PI()*t*t,t.sphereV=t=>4*e.PI()*t*t*t/3,t.squareA=e=>e*e,t.squareP=e=>4*e,t.trapezoidA=(e,t,r)=>(e+t)/2*r,t.trapezoidP=(e,t,r,n)=>e+t+r+n,t.triangleA=(e,t)=>e*t/2,t.triangleP=(e,t,r)=>e+t+r,t.trianglesidesA=(t,r,n)=>{const o=(t+r+n)/2;return e.real.sqrt(o*((o-t)*(o-r)*(o-n)))},t.triangularprismA=(t,r,n,o)=>{const i=(t+r+n)/2;return 2*e.real.sqrt(i*((i-t)*(i-r)*(i-n)))+o*(t+r+n)},t.triangularprismV=(t,r,n,o)=>o*e.real.sqrt(-t*t*t*t+t*r*2*(t*r)+t*n*2*(t*n)-r*r*r*r+r*n*2*(r*n)-n*n*n*n)/4}(t=e.geom||(e.geom={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){const r=t=>{const r=t;if(r&&"number"==typeof r.x&&"number"==typeof r.y)return t;if(Array.isArray(t))if(t.length>0&&Array.isArray(t[0])){const r=t,n=e.matr.rows(r),o=e.matr.cols(r);if(1===o){if(2===n)return e.vect.init(r[0][0],r[1][0]);if(3===n)return e.vect.init(r[0][0],r[1][0],r[2][0]);if(4===n)return e.vect.init(r[0][0],r[1][0],r[2][0],r[3][0])}else if(1===n){if(2===o)return e.vect.init(r[0][0],r[0][1]);if(3===o)return e.vect.init(r[0][0],r[0][1],r[0][2]);if(4===o)return e.vect.init(r[0][0],r[0][1],r[0][2],r[0][3])}}else{const r=t;if(2===r.length)return e.vect.init(r[0],r[1]);if(3===r.length)return e.vect.init(r[0],r[1],r[2]);if(4===r.length)return e.vect.init(r[0],r[1],r[2],r[3])}if(t instanceof Float32Array||t instanceof Float64Array){const r=t;if(2===r.length)return e.vect.init(r[0],r[1]);if(3===r.length)return e.vect.init(r[0],r[1],r[2]);if(4===r.length)return e.vect.init(r[0],r[1],r[2],r[3])}if("string"==typeof t)try{const r=JSON.parse(t);if(r&&"object"==typeof r&&"number"==typeof r.x&&"number"==typeof r.y)return e.vect.init(r.x,r.y,void 0!==r.z?r.z:void 0,void 0!==r.w?r.w:void 0)}catch(r){const n=t.trim();if(n.startsWith("(")&&n.endsWith(")")){const t=n.substring(1,n.length-1).split(",").map(e=>parseFloat(e.trim()));if(t.length>=2&&t.every(e=>!isNaN(e))){if(2===t.length)return e.vect.init(t[0],t[1]);if(3===t.length)return e.vect.init(t[0],t[1],t[2]);if(4===t.length)return e.vect.init(t[0],t[1],t[2],t[3])}}}throw new TypeError(`Invalid ChalkboardVector input: ${JSON.stringify(t)}`)};t.absolute=t=>{if(e.matr.isSizeOf(t,2))return e.matr.init([Math.abs(t[0][0]),Math.abs(t[0][1])],[Math.abs(t[1][0]),Math.abs(t[1][1])]);if(e.matr.isSizeOf(t,3))return e.matr.init([Math.abs(t[0][0]),Math.abs(t[0][1]),Math.abs(t[0][2])],[Math.abs(t[1][0]),Math.abs(t[1][1]),Math.abs(t[1][2])],[Math.abs(t[2][0]),Math.abs(t[2][1]),Math.abs(t[2][2])]);if(e.matr.isSizeOf(t,4))return e.matr.init([Math.abs(t[0][0]),Math.abs(t[0][1]),Math.abs(t[0][2]),Math.abs(t[0][3])],[Math.abs(t[1][0]),Math.abs(t[1][1]),Math.abs(t[1][2]),Math.abs(t[1][3])],[Math.abs(t[2][0]),Math.abs(t[2][1]),Math.abs(t[2][2]),Math.abs(t[2][3])],[Math.abs(t[3][0]),Math.abs(t[3][1]),Math.abs(t[3][2]),Math.abs(t[3][3])]);{const r=e.matr.init();for(let n=0;n<e.matr.rows(t);n++){r[n]=[];for(let o=0;o<e.matr.cols(t);o++)r[n][o]=Math.abs(t[n][o])}return r}},t.add=(t,r)=>{if(e.matr.isSizeEqual(t,r)){if(e.matr.isSizeOf(t,2))return e.matr.init([t[0][0]+r[0][0],t[0][1]+r[0][1]],[t[1][0]+r[1][0],t[1][1]+r[1][1]]);if(e.matr.isSizeOf(t,3))return e.matr.init([t[0][0]+r[0][0],t[0][1]+r[0][1],t[0][2]+r[0][2]],[t[1][0]+r[1][0],t[1][1]+r[1][1],t[1][2]+r[1][2]],[t[2][0]+r[2][0],t[2][1]+r[2][1],t[2][2]+r[2][2]]);if(e.matr.isSizeOf(t,4))return e.matr.init([t[0][0]+r[0][0],t[0][1]+r[0][1],t[0][2]+r[0][2],t[0][3]+r[0][3]],[t[1][0]+r[1][0],t[1][1]+r[1][1],t[1][2]+r[1][2],t[1][3]+r[1][3]],[t[2][0]+r[2][0],t[2][1]+r[2][1],t[2][2]+r[2][2],t[2][3]+r[2][3]],[t[3][0]+r[3][0],t[3][1]+r[3][1],t[3][2]+r[3][2],t[3][3]+r[3][3]]);{const n=e.matr.init();for(let o=0;o<e.matr.rows(t);o++){n[o]=[];for(let i=0;i<e.matr.cols(t);i++)n[o][i]=t[o][i]+r[o][i]}return n}}throw new TypeError('Parameters "matr1" and "matr2" must be of type "ChalkboardMatrix" with equivalent numbers of rows and columns.')},t.addKronecker=(t,r)=>{if(e.matr.isSquare(t)&&e.matr.isSquare(r))return e.matr.add(e.matr.mulKronecker(t,e.matr.identity(e.matr.rows(t))),e.matr.mulKronecker(e.matr.identity(e.matr.rows(r)),r));throw new TypeError('Parameters "matr1" and "matr2" must be of type "ChalkboardMatrix" that are square.')},t.adjugate=(t,r,n)=>e.matr.transpose(e.matr.cofactor(t,r,n)),t.Cholesky=t=>{if(!e.matr.isSquare(t))throw new TypeError('Chalkboard.matr.Cholesky: Parameter "matr" must be a square matrix.');if(!e.matr.isSymmetric(t))throw new TypeError('Chalkboard.matr.Cholesky: Parameter "matr" must be symmetric.');const r=e.matr.rows(t),n=e.matr.fill(0,r);for(let o=0;o<r;o++)for(let r=0;r<=o;r++){let i=t[o][r];for(let e=0;e<r;e++)i-=n[o][e]*n[r][e];if(o===r){if(i<=0)throw new RangeError("Chalkboard.matr.Cholesky: Matrix is not positive definite.");n[o][r]=e.real.sqrt(i)}else n[o][r]=i/n[r][r]}return{L:n,U:e.matr.transpose(n)}},t.cofactor=(e,t,r)=>e.slice(0,t).concat(e.slice(t+1)).map(e=>e.slice(0,r).concat(e.slice(r+1))),t.cols=e=>e[0].length,t.colspace=t=>e.matr.transpose(e.matr.rowspace(e.matr.transpose(t))),t.concat=(t,r,n=0)=>{if(0===n){if(e.matr.cols(t)===e.matr.cols(r))return e.matr.isSizeOf(t,2)&&2===e.matr.rows(r)?e.matr.init([t[0][0],t[0][1]],[t[1][0],t[1][1]],[r[0][0],r[0][1]],[r[1][0],r[1][1]]):e.matr.isSizeOf(t,3)&&3===e.matr.rows(r)?e.matr.init([t[0][0],t[0][1],t[0][2]],[t[1][0],t[1][1],t[1][2]],[t[2][0],t[2][1],t[2][2]],[r[0][0],r[0][1],r[0][2]],[r[1][0],r[1][1],r[1][2]],[r[2][0],r[2][1],r[2][2]]):e.matr.isSizeOf(t,4)&&4===e.matr.rows(r)?e.matr.init([t[0][0],t[0][1],t[0][2],t[0][3]],[t[1][0],t[1][1],t[1][2],t[1][3]],[t[2][0],t[2][1],t[2][2],t[2][3]],[t[3][0],t[3][1],t[3][2],t[3][3]],[r[0][0],r[0][1],r[0][2],r[0][3]],[r[1][0],r[1][1],r[1][2],r[1][3]],[r[2][0],r[2][1],r[2][2],r[2][3]],[r[3][0],r[3][1],r[3][2],r[3][3]]):e.matr.init(t.concat(r));throw new TypeError('Parameters "matr1" and "matr2" must be of type "ChalkboardMatrix" with equivalent numbers of columns.')}if(1===n){if(e.matr.rows(t)===e.matr.rows(r)){if(e.matr.isSizeOf(t,2)&&2===e.matr.cols(r))return e.matr.init([t[0][0],t[0][1],r[0][0],r[0][1]],[t[1][0],t[1][1],r[1][0],r[1][1]]);if(e.matr.isSizeOf(t,3)&&3===e.matr.cols(r))return e.matr.init([t[0][0],t[0][1],t[0][2],r[0][0],r[0][1],r[0][2]],[t[1][0],t[1][1],t[1][2],r[1][0],r[1][1],r[1][2]],[t[2][0],t[2][1],t[2][2],r[2][0],r[2][1],r[2][2]]);if(e.matr.isSizeOf(t,4)&&4===e.matr.cols(r))return e.matr.init([t[0][0],t[0][1],t[0][2],t[0][3],r[0][0],r[0][1],r[0][2],r[0][3]],[t[1][0],t[1][1],t[1][2],t[1][3],r[1][0],r[1][1],r[1][2],r[1][3]],[t[2][0],t[2][1],t[2][2],t[2][3],r[2][0],r[2][1],r[2][2],r[2][3]],[t[3][0],t[3][1],t[3][2],t[3][3],r[3][0],r[3][1],r[3][2],r[3][3]]);{const n=e.matr.init();for(let o=0;o<e.matr.rows(t);o++)n.push(t[o].concat(r[o]));return n}}throw new TypeError('Parameters "matr1" and "matr2" must be of type "ChalkboardMatrix" with equivalent numbers of rows.')}throw new TypeError('Parameter "axis" must be 0 or 1.')},t.constrain=(t,r=[0,1])=>{if(e.matr.isSizeOf(t,2))return e.matr.init([e.numb.constrain(t[0][0],r),e.numb.constrain(t[0][1],r)],[e.numb.constrain(t[1][0],r),e.numb.constrain(t[1][1],r)]);if(e.matr.isSizeOf(t,3))return e.matr.init([e.numb.constrain(t[0][0],r),e.numb.constrain(t[0][1],r),e.numb.constrain(t[0][2],r)],[e.numb.constrain(t[1][0],r),e.numb.constrain(t[1][1],r),e.numb.constrain(t[1][2],r)],[e.numb.constrain(t[2][0],r),e.numb.constrain(t[2][1],r),e.numb.constrain(t[2][2],r)]);if(e.matr.isSizeOf(t,4))return e.matr.init([e.numb.constrain(t[0][0],r),e.numb.constrain(t[0][1],r),e.numb.constrain(t[0][2],r),e.numb.constrain(t[0][3],r)],[e.numb.constrain(t[1][0],r),e.numb.constrain(t[1][1],r),e.numb.constrain(t[1][2],r),e.numb.constrain(t[1][3],r)],[e.numb.constrain(t[2][0],r),e.numb.constrain(t[2][1],r),e.numb.constrain(t[2][2],r),e.numb.constrain(t[2][3],r)],[e.numb.constrain(t[3][0],r),e.numb.constrain(t[3][1],r),e.numb.constrain(t[3][2],r),e.numb.constrain(t[3][3],r)]);{const n=e.matr.init();for(let o=0;o<e.matr.rows(t);o++){n[o]=[];for(let i=0;i<e.matr.cols(t);i++)n[o][i]=e.numb.constrain(t[o][i],r)}return n}},t.copy=t=>{if(e.matr.isSizeOf(t,2))return e.matr.init([t[0][0],t[0][1]],[t[1][0],t[1][1]]);if(e.matr.isSizeOf(t,3))return e.matr.init([t[0][0],t[0][1],t[0][2]],[t[1][0],t[1][1],t[1][2]],[t[2][0],t[2][1],t[2][2]]);if(e.matr.isSizeOf(t,4))return e.matr.init([t[0][0],t[0][1],t[0][2],t[0][3]],[t[1][0],t[1][1],t[1][2],t[1][3]],[t[2][0],t[2][1],t[2][2],t[2][3]],[t[3][0],t[3][1],t[3][2],t[3][3]]);{const r=e.matr.init();for(let n=0;n<e.matr.rows(t);n++){r.push([]);for(let o=0;o<e.matr.cols(t);o++)r[n].push(t[n][o])}return r}},t.det=t=>{if(e.matr.isSquare(t)){if(1===e.matr.rows(t))return t[0][0];if(2===e.matr.rows(t))return t[0][0]*t[1][1]-t[0][1]*t[1][0];if(3===e.matr.rows(t))return t[0][0]*(t[1][1]*t[2][2]-t[1][2]*t[2][1])-t[0][1]*(t[1][0]*t[2][2]-t[1][2]*t[2][0])+t[0][2]*(t[1][0]*t[2][1]-t[1][1]*t[2][0]);if(4===e.matr.rows(t))return t[0][0]*(t[1][1]*(t[2][2]*t[3][3]-t[2][3]*t[3][2])-t[1][2]*(t[2][1]*t[3][3]-t[2][3]*t[3][1])+t[1][3]*(t[2][1]*t[3][2]-t[2][2]*t[3][1]))-t[0][1]*(t[1][0]*(t[2][2]*t[3][3]-t[2][3]*t[3][2])-t[1][2]*(t[2][0]*t[3][3]-t[2][3]*t[3][0])+t[1][3]*(t[2][0]*t[3][2]-t[2][2]*t[3][0]))+t[0][2]*(t[1][0]*(t[2][1]*t[3][3]-t[2][3]*t[3][1])-t[1][1]*(t[2][0]*t[3][3]-t[2][3]*t[3][0])+t[1][3]*(t[2][0]*t[3][1]-t[2][1]*t[3][0]))-t[0][3]*(t[1][0]*(t[2][1]*t[3][2]-t[2][2]*t[3][1])-t[1][1]*(t[2][0]*t[3][2]-t[2][2]*t[3][0])+t[1][2]*(t[2][0]*t[3][1]-t[2][1]*t[3][0]));{let r=0;for(let n=0;n<e.matr.rows(t);n++){const o=t[0][n]*e.matr.det(e.matr.cofactor(t,0,n));r+=n%2==0?o:-o}return r}}throw new TypeError('Parameter "matr" must be of type "ChalkboardMatrix" that is square.')},t.diagonal=(t,...r)=>{if(2===t)return e.matr.init([r[0]||0,0],[0,r[1]||0]);if(3===t)return e.matr.init([r[0]||0,0,0],[0,r[1]||0,0],[0,0,r[2]||0]);if(4===t)return e.matr.init([r[0]||0,0,0,0],[0,r[1]||0,0,0],[0,0,r[2]||0,0],[0,0,0,r[3]||0]);{r=Array.isArray(r[0])?r[0]:r;const n=e.matr.init();for(let e=0;e<t;e++)n.push(Array(t).fill(0)),n[e][e]=r[e]||0;return n}},t.eigenvalue=(t,r=100)=>{let n=e.matr.fill(1,e.matr.rows(t),1);for(let o=0;o<r;o++){const r=e.matr.mul(t,n),o=e.stat.max(e.matr.toArray(e.matr.absolute(r)));n=e.stat.toMatrix(e.matr.toArray(r).map(e=>e/o),e.matr.rows(t),1)}const o=function(e,t){let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r};return o(e.matr.toArray(e.matr.transpose(n)),e.matr.toArray(e.matr.mul(t,n)))/o(e.matr.toArray(e.matr.transpose(n)),e.matr.toArray(n))},t.eigenvector=(t,r=100)=>{let n=e.matr.fill(1,e.matr.rows(t),1);for(let o=0;o<r;o++){const r=e.matr.mul(t,n),o=e.stat.max(e.matr.toArray(e.matr.absolute(r)));n=e.stat.toMatrix(e.matr.toArray(r).map(e=>e/o),e.matr.rows(t),1)}return e.matr.toArray(n)},t.empty=(t,r=t)=>{const n=null;if(2===t&&2===r)return e.matr.init([n,n],[n,n]);if(3===t&&3===r)return e.matr.init([n,n,n],[n,n,n],[n,n,n]);if(4===t&&4===r)return e.matr.init([n,n,n,n],[n,n,n,n],[n,n,n,n],[n,n,n,n]);{const o=e.matr.init();for(let e=0;e<t;e++){o.push([]);for(let t=0;t<r;t++)o[e].push(n)}return o}},t.exchange=t=>{if(2===t)return e.matr.init([0,1],[1,0]);if(3===t)return e.matr.init([0,0,1],[0,1,0],[1,0,0]);if(4===t)return e.matr.init([0,0,0,1],[0,0,1,0],[0,1,0,0],[1,0,0,0]);{const r=e.matr.fill(0,t,t);for(let e=0;e<t;e++)for(let n=0;n<t;n++)e+n===t-1&&(r[e][n]=1);return r}},t.fill=(t,r,n=r)=>{if(2===r&&2===n)return e.matr.init([t,t],[t,t]);if(3===r&&3===n)return e.matr.init([t,t,t],[t,t,t],[t,t,t]);if(4===r&&4===n)return e.matr.init([t,t,t,t],[t,t,t,t],[t,t,t,t],[t,t,t,t]);{const o=e.matr.init();for(let e=0;e<r;e++){o.push([]);for(let r=0;r<n;r++)o[e].push(t)}return o}},t.Gaussian=t=>{let r=0;for(let n=0;n<e.matr.rows(t)&&!(r>=e.matr.cols(t));n++){let o=n;for(;0===t[o][r];)if(o++,o===e.matr.rows(t)&&(o=n,r++,e.matr.cols(t)===r))return t;const i=t[o];t[o]=t[n],t[n]=i;const a=t[n][r];for(let r=0;r<e.matr.cols(t);r++)t[n][r]/=a;for(let o=0;o<e.matr.rows(t);o++)if(o!==n){const i=t[o][r];for(let r=0;r<e.matr.cols(t);r++)t[o][r]-=i*t[n][r]}r++}return t},t.Hilbert=t=>{if(2===t)return e.matr.init([1,.5],[.5,1/3]);if(3===t)return e.matr.init([1,.5,1/3],[.5,1/3,1/4],[1/3,1/4,.2]);if(4===t)return e.matr.init([1,.5,1/3,1/4],[.5,1/3,1/4,.2],[1/3,1/4,.2,1/6],[1/4,.2,1/6,1/7]);{const r=e.matr.init();for(let e=0;e<t;e++){r.push([]);for(let n=0;n<t;n++)r[e].push(1/(e+n+1))}return r}},t.identity=t=>{if(2===t)return e.matr.init([1,0],[0,1]);if(3===t)return e.matr.init([1,0,0],[0,1,0],[0,0,1]);if(4===t)return e.matr.init([1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]);{const r=e.matr.init();for(let e=0;e<t;e++)r.push(Array(t).fill(0)),r[e][e]=1;return r}},t.init=(...e)=>0===e.length?[]:Array.isArray(e[0])&&Array.isArray(e[0][0])?e[0]:e,t.invert=t=>{if(e.matr.isInvertible(t)){if(2===e.matr.rows(t)){const r=e.matr.det(t);return e.matr.init([t[1][1]/r,-t[0][1]/r],[-t[1][0]/r,t[0][0]/r])}if(3===e.matr.rows(t)){const r=e.matr.det(t);return e.matr.init([(t[1][1]*t[2][2]-t[1][2]*t[2][1])/r,(t[0][2]*t[2][1]-t[0][1]*t[2][2])/r,(t[0][1]*t[1][2]-t[0][2]*t[1][1])/r],[(t[1][2]*t[2][0]-t[1][0]*t[2][2])/r,(t[0][0]*t[2][2]-t[0][2]*t[2][0])/r,(t[0][2]*t[1][0]-t[0][0]*t[1][2])/r],[(t[1][0]*t[2][1]-t[1][1]*t[2][0])/r,(t[0][1]*t[2][0]-t[0][0]*t[2][1])/r,(t[0][0]*t[1][1]-t[0][1]*t[1][0])/r])}if(4===e.matr.rows(t)){const r=e.matr.det(t),n=t[0][0]*t[1][1]-t[0][1]*t[1][0],o=t[0][0]*t[1][2]-t[0][2]*t[1][0],i=t[0][0]*t[1][3]-t[0][3]*t[1][0],a=t[0][1]*t[1][2]-t[0][2]*t[1][1],s=t[0][1]*t[1][3]-t[0][3]*t[1][1],l=t[0][2]*t[1][3]-t[0][3]*t[1][2],u=t[2][0]*t[3][1]-t[2][1]*t[3][0],m=t[2][0]*t[3][2]-t[2][2]*t[3][0],f=t[2][0]*t[3][3]-t[2][3]*t[3][0],c=t[2][1]*t[3][2]-t[2][2]*t[3][1],p=t[2][1]*t[3][3]-t[2][3]*t[3][1],d=t[2][2]*t[3][3]-t[2][3]*t[3][2];return e.matr.init([(t[1][1]*d-t[1][2]*p+t[1][3]*c)/r,(t[0][2]*p-t[0][1]*d-t[0][3]*c)/r,(t[3][1]*l-t[3][2]*s+t[3][3]*a)/r,(t[2][2]*s-t[2][1]*l-t[2][3]*a)/r],[(t[1][2]*f-t[1][0]*d-t[1][3]*m)/r,(t[0][0]*d-t[0][2]*f+t[0][3]*m)/r,(t[3][2]*i-t[3][0]*l-t[3][3]*o)/r,(t[2][0]*l-t[2][2]*i+t[2][3]*o)/r],[(t[1][0]*p-t[1][1]*f+t[1][3]*u)/r,(t[0][1]*f-t[0][0]*p-t[0][3]*u)/r,(t[3][0]*s-t[3][1]*i+t[3][3]*n)/r,(t[2][1]*i-t[2][0]*s-t[2][3]*n)/r],[(t[1][1]*m-t[1][0]*c-t[1][2]*u)/r,(t[0][0]*c-t[0][1]*m+t[0][2]*u)/r,(t[3][1]*o-t[3][0]*a-t[3][2]*n)/r,(t[2][0]*a-t[2][1]*o+t[2][2]*n)/r])}{const r=e.matr.init(),n=e.matr.init();for(let r=0;r<e.matr.rows(t);r++)n.push(t[r].concat(Array(e.matr.rows(t)).fill(0))),n[r][e.matr.cols(t)+r]=1;for(let r=0;r<e.matr.rows(t);r++){let o=n[r][r];if(0===o){let i=r;for(let o=r+1;o<e.matr.rows(t);o++)Math.abs(n[o][r])>Math.abs(n[i][r])&&(i=o);const a=n[r];n[r]=n[i],n[i]=a,o=n[r][r]}for(let i=0;i<2*e.matr.cols(t);i++)n[r][i]/=o;for(let o=0;o<e.matr.rows(t);o++)if(o!==r){const i=n[o][r];for(let a=0;a<2*e.matr.cols(t);a++)n[o][a]-=i*n[r][a]}}for(let o=0;o<e.matr.rows(t);o++)r.push(n[o].slice(e.matr.cols(t),2*e.matr.cols(t)));return r}}throw new TypeError('Parameter "matr" must be of type "ChalkboardMatrix" that is square and has a non-zero determinant.')},t.isApproxEqual=(t,r,n=1e-6)=>{if(e.matr.isSizeEqual(t,r)){for(let o=0;o<e.matr.rows(t);o++)for(let i=0;i<e.matr.cols(t);i++)if(!e.numb.isApproxEqual(t[o][i],r[o][i],n))return!1;return!0}return!1},t.isDiagonal=t=>{if(e.matr.isSquare(t)){if(e.matr.isSizeOf(t,2))return e.numb.isApproxEqual(t[0][1],0)&&e.numb.isApproxEqual(t[1][0],0);if(e.matr.isSizeOf(t,3))return e.numb.isApproxEqual(t[0][1],0)&&e.numb.isApproxEqual(t[0][2],0)&&e.numb.isApproxEqual(t[1][0],0)&&e.numb.isApproxEqual(t[1][2],0)&&e.numb.isApproxEqual(t[2][0],0)&&e.numb.isApproxEqual(t[2][1],0);if(e.matr.isSizeOf(t,4))return e.numb.isApproxEqual(t[0][1],0)&&e.numb.isApproxEqual(t[0][2],0)&&e.numb.isApproxEqual(t[0][3],0)&&e.numb.isApproxEqual(t[1][0],0)&&e.numb.isApproxEqual(t[1][2],0)&&e.numb.isApproxEqual(t[1][3],0)&&e.numb.isApproxEqual(t[2][0],0)&&e.numb.isApproxEqual(t[2][1],0)&&e.numb.isApproxEqual(t[2][3],0)&&e.numb.isApproxEqual(t[3][0],0)&&e.numb.isApproxEqual(t[3][1],0)&&e.numb.isApproxEqual(t[3][2],0);for(let r=0;r<e.matr.rows(t);r++)for(let n=0;n<e.matr.cols(t);n++)if(r!==n&&!e.numb.isApproxEqual(t[r][n],0))return!1;return!0}return!1},t.isEqual=(t,r)=>{if(e.matr.isSizeEqual(t,r)){if(e.matr.isSizeOf(t,2))return t[0][0]===r[0][0]&&t[0][1]===r[0][1]&&t[1][0]===r[1][0]&&t[1][1]===r[1][1];if(e.matr.isSizeOf(t,3))return t[0][0]===r[0][0]&&t[0][1]===r[0][1]&&t[0][2]===r[0][2]&&t[1][0]===r[1][0]&&t[1][1]===r[1][1]&&t[1][2]===r[1][2]&&t[2][0]===r[2][0]&&t[2][1]===r[2][1]&&t[2][2]===r[2][2];if(e.matr.isSizeOf(t,4))return t[0][0]===r[0][0]&&t[0][1]===r[0][1]&&t[0][2]===r[0][2]&&t[0][3]===r[0][3]&&t[1][0]===r[1][0]&&t[1][1]===r[1][1]&&t[1][2]===r[1][2]&&t[1][3]===r[1][3]&&t[2][0]===r[2][0]&&t[2][1]===r[2][1]&&t[2][2]===r[2][2]&&t[2][3]===r[2][3]&&t[3][0]===r[3][0]&&t[3][1]===r[3][1]&&t[3][2]===r[3][2]&&t[3][3]===r[3][3];for(let n=0;n<e.matr.rows(t);n++)for(let o=0;o<e.matr.cols(r);o++)if(t[n][o]!==r[n][o])return!1;return!0}return!1},t.isIdentity=t=>!!e.matr.isDiagonal(t)&&(e.matr.isSizeOf(t,2)?e.matr.isApproxEqual(t,e.matr.identity(2)):e.matr.isSizeOf(t,3)?e.matr.isApproxEqual(t,e.matr.identity(3)):e.matr.isSizeOf(t,4)?e.matr.isApproxEqual(t,e.matr.identity(4)):e.matr.isApproxEqual(t,e.matr.identity(e.matr.rows(t)))),t.isInvertible=t=>e.matr.isSquare(t)&&0!==e.matr.det(t),t.isLowerTriangular=t=>{if(e.matr.isSquare(t)){if(e.matr.isSizeOf(t,2))return e.matr.isApproxEqual(t,e.matr.init([t[0][0],0],[t[1][0],t[1][1]]));if(e.matr.isSizeOf(t,3))return e.matr.isApproxEqual(t,e.matr.init([t[0][0],0,0],[t[1][0],t[1][1],0],[t[2][0],t[2][1],t[2][2]]));if(e.matr.isSizeOf(t,4))return e.matr.isApproxEqual(t,e.matr.init([t[0][0],0,0,0],[t[1][0],t[1][1],0,0],[t[2][0],t[2][1],t[2][2],0],[t[3][0],t[3][1],t[3][2],t[3][3]]));{let r=0;for(let n=0;n<e.matr.rows(t);n++)for(let o=n+1;o<e.matr.cols(t);o++)0!==t[n][o]&&r++;return 0===r}}return!1},t.isOrthogonal=t=>!!e.matr.isInvertible(t)&&e.matr.isApproxEqual(e.matr.transpose(t),e.matr.invert(t)),t.isSizeEqual=(t,r)=>e.matr.rows(t)===e.matr.rows(r)&&e.matr.cols(t)===e.matr.cols(r),t.isSizeOf=(t,r,n=r)=>e.matr.rows(t)===r&&e.matr.cols(t)===n,t.isSkewSymmetric=t=>e.matr.isEqual(e.matr.transpose(t),e.matr.negate(t)),t.isSquare=t=>e.matr.rows(t)===e.matr.cols(t),t.isSymmetric=t=>e.matr.isEqual(t,e.matr.transpose(t)),t.isUpperTriangular=t=>{if(e.matr.isSquare(t)){if(e.matr.isSizeOf(t,2))return e.matr.isApproxEqual(t,e.matr.init([t[0][0],t[0][1]],[0,t[1][1]]));if(e.matr.isSizeOf(t,3))return e.matr.isApproxEqual(t,e.matr.init([t[0][0],t[0][1],t[0][2]],[0,t[1][1],t[1][2]],[0,0,t[2][2]]));if(e.matr.isSizeOf(t,4))return e.matr.isApproxEqual(t,e.matr.init([t[0][0],t[0][1],t[0][2],t[0][3]],[0,t[1][1],t[1][2],t[1][3]],[0,0,t[2][2],t[2][3]],[0,0,0,t[3][3]]));{let r=0;for(let n=0;n<e.matr.rows(t);n++)for(let e=0;e<n;e++)0!==t[n][e]&&r++;return 0===r}}return!1},t.isZero=t=>e.matr.isApproxEqual(t,e.matr.zero(e.matr.rows(t),e.matr.cols(t))),t.Lehmer=t=>{if(2===t)return e.matr.init([1,.5],[.5,1]);if(3===t)return e.matr.init([1,.5,1/3],[.5,1,2/3],[1/3,2/3,1]);if(4===t)return e.matr.init([1,.5,1/3,1/4],[.5,1,2/3,.5],[1/3,2/3,1,3/4],[1/4,1,3/4,1]);{const r=e.matr.init();for(let e=0;e<t;e++){r.push([]);for(let n=0;n<t;n++)r[e].push(Math.min(e+1,n+1)/Math.max(e+1,n+1))}return r}},t.lowerBinomial=t=>{if(2===t)return e.matr.init([1,0],[1,1]);if(3===t)return e.matr.init([1,0,0],[1,1,0],[1,2,1]);if(4===t)return e.matr.init([1,0,0,0],[1,1,0,0],[1,2,1,0],[1,3,3,1]);{const r=e.matr.init();for(let n=0;n<t;n++){r.push([]);for(let o=0;o<t;o++)r[n].push(e.numb.binomial(n,o))}return r}},t.lowerShift=t=>{if(2===t)return e.matr.init([0,0],[1,0]);if(3===t)return e.matr.init([0,0,0],[1,0,0],[0,1,0]);if(4===t)return e.matr.init([0,0,0,0],[1,0,0,0],[0,1,0,0],[0,0,1,0]);{const r=e.matr.init();for(let n=0;n<t;n++){r[n]=[];for(let o=0;o<t;o++)r[n][o]=e.numb.Kronecker(n,o+1)}return r}},t.lowerTriangular=(t,...r)=>{if(2===t)return e.matr.init([r[0]||0,0],[r[1]||0,r[2]||0]);if(3===t)return e.matr.init([r[0]||0,0,0],[r[1]||0,r[2]||0,0],[r[3]||0,r[4]||0,r[5]||0]);if(4===t)return e.matr.init([r[0]||0,0,0,0],[r[1]||0,r[2]||0,0,0],[r[3]||0,r[4]||0,r[5]||0,0],[r[6]||0,r[7]||0,r[8]||0,r[9]||0]);{r=Array.isArray(r[0])?r[0]:r;const n=e.matr.init();let o=0;for(let e=0;e<t;e++){n[e]=[];for(let i=0;i<t;i++)n[e][i]=i<=e&&r[o++]||0}return n}},t.LUdecomp=t=>{if(e.matr.isSquare(t)){const r=e.matr.identity(e.matr.rows(t)),n=e.matr.fill(0,e.matr.rows(t));for(let o=0;o<e.matr.cols(t);o++){for(let e=0;e<=o;e++){let i=0;for(let t=0;t<e;t++)i+=r[e][t]*n[t][o];n[e][o]=t[e][o]-i}for(let i=o+1;i<e.matr.rows(t);i++){let e=0;for(let t=0;t<o;t++)e+=r[i][t]*n[t][o];r[i][o]=(t[i][o]-e)/n[o][o]}}return{L:r,U:n}}throw new TypeError('Parameter "matr" must be of type "ChalkboardMatrix" that is square.')},t.mul=(t,r)=>{if(e.matr.cols(t)===e.matr.rows(r)){if(e.matr.isSizeOf(t,2)&&e.matr.isSizeOf(r,2,1))return e.matr.init([t[0][0]*r[0][0]+t[0][1]*r[1][0]],[t[1][0]*r[0][0]+t[1][1]*r[1][0]]);if(e.matr.isSizeOf(t,2)&&e.matr.isSizeOf(r,2))return e.matr.init([t[0][0]*r[0][0]+t[0][1]*r[1][0],t[0][0]*r[0][1]+t[0][1]*r[1][1]],[t[1][0]*r[0][0]+t[1][1]*r[1][0],t[1][0]*r[0][1]+t[1][1]*r[1][1]]);if(e.matr.isSizeOf(t,3)&&e.matr.isSizeOf(r,3,1))return e.matr.init([t[0][0]*r[0][0]+t[0][1]*r[1][0]+t[0][2]*r[2][0]],[t[1][0]*r[0][0]+t[1][1]*r[1][0]+t[1][2]*r[2][0]],[t[2][0]*r[0][0]+t[2][1]*r[1][0]+t[2][2]*r[2][0]]);if(e.matr.isSizeOf(t,3)&&e.matr.isSizeOf(r,3))return e.matr.init([t[0][0]*r[0][0]+t[0][1]*r[1][0]+t[0][2]*r[2][0],t[0][0]*r[0][1]+t[0][1]*r[1][1]+t[0][2]*r[2][1],t[0][0]*r[0][2]+t[0][1]*r[1][2]+t[0][2]*r[2][2]],[t[1][0]*r[0][0]+t[1][1]*r[1][0]+t[1][2]*r[2][0],t[1][0]*r[0][1]+t[1][1]*r[1][1]+t[1][2]*r[2][1],t[1][0]*r[0][2]+t[1][1]*r[1][2]+t[1][2]*r[2][2]],[t[2][0]*r[0][0]+t[2][1]*r[1][0]+t[2][2]*r[2][0],t[2][0]*r[0][1]+t[2][1]*r[1][1]+t[2][2]*r[2][1],t[2][0]*r[0][2]+t[2][1]*r[1][2]+t[2][2]*r[2][2]]);if(e.matr.isSizeOf(t,4)&&e.matr.isSizeOf(r,4,1))return e.matr.init([t[0][0]*r[0][0]+t[0][1]*r[1][0]+t[0][2]*r[2][0]+t[0][3]*r[3][0]],[t[1][0]*r[0][0]+t[1][1]*r[1][0]+t[1][2]*r[2][0]+t[1][3]*r[3][0]],[t[2][0]*r[0][0]+t[2][1]*r[1][0]+t[2][2]*r[2][0]+t[2][3]*r[3][0]],[t[3][0]*r[0][0]+t[3][1]*r[1][0]+t[3][2]*r[2][0]+t[3][3]*r[3][0]]);if(e.matr.isSizeOf(t,4)&&e.matr.isSizeOf(r,4))return e.matr.init([t[0][0]*r[0][0]+t[0][1]*r[1][0]+t[0][2]*r[2][0]+t[0][3]*r[3][0],t[0][0]*r[0][1]+t[0][1]*r[1][1]+t[0][2]*r[2][1]+t[0][3]*r[3][1],t[0][0]*r[0][2]+t[0][1]*r[1][2]+t[0][2]*r[2][2]+t[0][3]*r[3][2],t[0][0]*r[0][3]+t[0][1]*r[1][3]+t[0][2]*r[2][3]+t[0][3]*r[3][3]],[t[1][0]*r[0][0]+t[1][1]*r[1][0]+t[1][2]*r[2][0]+t[1][3]*r[3][0],t[1][0]*r[0][1]+t[1][1]*r[1][1]+t[1][2]*r[2][1]+t[1][3]*r[3][1],t[1][0]*r[0][2]+t[1][1]*r[1][2]+t[1][2]*r[2][2]+t[1][3]*r[3][2],t[1][0]*r[0][3]+t[1][1]*r[1][3]+t[1][2]*r[2][3]+t[1][3]*r[3][3]],[t[2][0]*r[0][0]+t[2][1]*r[1][0]+t[2][2]*r[2][0]+t[2][3]*r[3][0],t[2][0]*r[0][1]+t[2][1]*r[1][1]+t[2][2]*r[2][1]+t[2][3]*r[3][1],t[2][0]*r[0][2]+t[2][1]*r[1][2]+t[2][2]*r[2][2]+t[2][3]*r[3][2],t[2][0]*r[0][3]+t[2][1]*r[1][3]+t[2][2]*r[2][3]+t[2][3]*r[3][3]],[t[3][0]*r[0][0]+t[3][1]*r[1][0]+t[3][2]*r[2][0]+t[3][3]*r[3][0],t[3][0]*r[0][1]+t[3][1]*r[1][1]+t[3][2]*r[2][1]+t[3][3]*r[3][1],t[3][0]*r[0][2]+t[3][1]*r[1][2]+t[3][2]*r[2][2]+t[3][3]*r[3][2],t[3][0]*r[0][3]+t[3][1]*r[1][3]+t[3][2]*r[2][3]+t[3][3]*r[3][3]]);{const n=e.matr.init();for(let o=0;o<e.matr.rows(t);o++){n[o]=[];for(let i=0;i<e.matr.cols(r);i++){n[o][i]=0;for(let a=0;a<e.matr.cols(t);a++)n[o][i]+=t[o][a]*r[a][i]}}return n}}throw new TypeError('Parameters "matr1" and "matr2" must be of type "ChalkboardMatrix" where the numbers of columns of "matr1" must be equivalent to the number of rows of "matr2".')},t.mulKronecker=(t,r)=>{if(e.matr.isSizeOf(t,2)&&e.matr.isSizeOf(r,2))return e.matr.init([t[0][0]*r[0][0],t[0][0]*r[0][1],t[0][1]*r[0][0],t[0][1]*r[0][1]],[t[0][0]*r[1][0],t[0][0]*r[1][1],t[0][1]*r[1][0],t[0][1]*r[1][1]],[t[1][0]*r[0][0],t[1][0]*r[0][1],t[1][1]*r[0][0],t[1][1]*r[0][1]],[t[1][0]*r[1][0],t[1][0]*r[1][1],t[1][1]*r[1][0],t[1][1]*r[1][1]]);if(e.matr.isSizeOf(t,3)&&e.matr.isSizeOf(r,3))return e.matr.init([t[0][0]*r[0][0],t[0][0]*r[0][1],t[0][0]*r[0][2],t[0][1]*r[0][0],t[0][1]*r[0][1],t[0][1]*r[0][2],t[0][2]*r[0][0],t[0][2]*r[0][1],t[0][2]*r[0][2]],[t[0][0]*r[1][0],t[0][0]*r[1][1],t[0][0]*r[1][2],t[0][1]*r[1][0],t[0][1]*r[1][1],t[0][1]*r[1][2],t[0][2]*r[1][0],t[0][2]*r[1][1],t[0][2]*r[1][2]],[t[0][0]*r[2][0],t[0][0]*r[2][1],t[0][0]*r[2][2],t[0][1]*r[2][0],t[0][1]*r[2][1],t[0][1]*r[2][2],t[0][2]*r[2][0],t[0][2]*r[2][1],t[0][2]*r[2][2]],[t[1][0]*r[0][0],t[1][0]*r[0][1],t[1][0]*r[0][2],t[1][1]*r[0][0],t[1][1]*r[0][1],t[1][1]*r[0][2],t[1][2]*r[0][0],t[1][2]*r[0][1],t[1][2]*r[0][2]],[t[1][0]*r[1][0],t[1][0]*r[1][1],t[1][0]*r[1][2],t[1][1]*r[1][0],t[1][1]*r[1][1],t[1][1]*r[1][2],t[1][2]*r[1][0],t[1][2]*r[1][1],t[1][2]*r[1][2]],[t[1][0]*r[2][0],t[1][0]*r[2][1],t[1][0]*r[2][2],t[1][1]*r[2][0],t[1][1]*r[2][1],t[1][1]*r[2][2],t[1][2]*r[2][0],t[1][2]*r[2][1],t[1][2]*r[2][2]],[t[2][0]*r[0][0],t[2][0]*r[0][1],t[2][0]*r[0][2],t[2][1]*r[0][0],t[2][1]*r[0][1],t[2][1]*r[0][2],t[2][2]*r[0][0],t[2][2]*r[0][1],t[2][2]*r[0][2]],[t[2][0]*r[1][0],t[2][0]*r[1][1],t[2][0]*r[1][2],t[2][1]*r[1][0],t[2][1]*r[1][1],t[2][1]*r[1][2],t[2][2]*r[1][0],t[2][2]*r[1][1],t[2][2]*r[1][2]],[t[2][0]*r[2][0],t[2][0]*r[2][1],t[2][0]*r[2][2],t[2][1]*r[2][0],t[2][1]*r[2][1],t[2][1]*r[2][2],t[2][2]*r[2][0],t[2][2]*r[2][1],t[2][2]*r[2][2]]);if(e.matr.isSizeOf(t,4)&&e.matr.isSizeOf(r,4))return e.matr.init([t[0][0]*r[0][0],t[0][0]*r[0][1],t[0][0]*r[0][2],t[0][0]*r[0][3],t[0][1]*r[0][0],t[0][1]*r[0][1],t[0][1]*r[0][2],t[0][1]*r[0][3],t[0][2]*r[0][0],t[0][2]*r[0][1],t[0][2]*r[0][2],t[0][2]*r[0][3],t[0][3]*r[0][0],t[0][3]*r[0][1],t[0][3]*r[0][2],t[0][3]*r[0][3]],[t[0][0]*r[1][0],t[0][0]*r[1][1],t[0][0]*r[1][2],t[0][0]*r[1][3],t[0][1]*r[1][0],t[0][1]*r[1][1],t[0][1]*r[1][2],t[0][1]*r[1][3],t[0][2]*r[1][0],t[0][2]*r[1][1],t[0][2]*r[1][2],t[0][2]*r[1][3],t[0][3]*r[1][0],t[0][3]*r[1][1],t[0][3]*r[1][2],t[0][3]*r[1][3]],[t[0][0]*r[2][0],t[0][0]*r[2][1],t[0][0]*r[2][2],t[0][0]*r[2][3],t[0][1]*r[2][0],t[0][1]*r[2][1],t[0][1]*r[2][2],t[0][1]*r[2][3],t[0][2]*r[2][0],t[0][2]*r[2][1],t[0][2]*r[2][2],t[0][2]*r[2][3],t[0][3]*r[2][0],t[0][3]*r[2][1],t[0][3]*r[2][2],t[0][3]*r[2][3]],[t[0][0]*r[3][0],t[0][0]*r[3][1],t[0][0]*r[3][2],t[0][0]*r[3][3],t[0][1]*r[3][0],t[0][1]*r[3][1],t[0][1]*r[3][2],t[0][1]*r[3][3],t[0][2]*r[3][0],t[0][2]*r[3][1],t[0][2]*r[3][2],t[0][2]*r[3][3],t[0][3]*r[3][0],t[0][3]*r[3][1],t[0][3]*r[3][2],t[0][3]*r[3][3]],[t[1][0]*r[0][0],t[1][0]*r[0][1],t[1][0]*r[0][2],t[1][0]*r[0][3],t[1][1]*r[0][0],t[1][1]*r[0][1],t[1][1]*r[0][2],t[1][1]*r[0][3],t[1][2]*r[0][0],t[1][2]*r[0][1],t[1][2]*r[0][2],t[1][2]*r[0][3],t[1][3]*r[0][0],t[1][3]*r[0][1],t[1][3]*r[0][2],t[1][3]*r[0][3]],[t[1][0]*r[1][0],t[1][0]*r[1][1],t[1][0]*r[1][2],t[1][0]*r[1][3],t[1][1]*r[1][0],t[1][1]*r[1][1],t[1][1]*r[1][2],t[1][1]*r[1][3],t[1][2]*r[1][0],t[1][2]*r[1][1],t[1][2]*r[1][2],t[1][2]*r[1][3],t[1][3]*r[1][0],t[1][3]*r[1][1],t[1][3]*r[1][2],t[1][3]*r[1][3]],[t[1][0]*r[2][0],t[1][0]*r[2][1],t[1][0]*r[2][2],t[1][0]*r[2][3],t[1][1]*r[2][0],t[1][1]*r[2][1],t[1][1]*r[2][2],t[1][1]*r[2][3],t[1][2]*r[2][0],t[1][2]*r[2][1],t[1][2]*r[2][2],t[1][2]*r[2][3],t[1][3]*r[2][0],t[1][3]*r[2][1],t[1][3]*r[2][2],t[1][3]*r[2][3]],[t[1][0]*r[3][0],t[1][0]*r[3][1],t[1][0]*r[3][2],t[1][0]*r[3][3],t[1][1]*r[3][0],t[1][1]*r[3][1],t[1][1]*r[3][2],t[1][1]*r[3][3],t[1][2]*r[3][0],t[1][2]*r[3][1],t[1][2]*r[3][2],t[1][2]*r[3][3],t[1][3]*r[3][0],t[1][3]*r[3][1],t[1][3]*r[3][2],t[1][3]*r[3][3]],[t[2][0]*r[0][0],t[2][0]*r[0][1],t[2][0]*r[0][2],t[2][0]*r[0][3],t[2][1]*r[0][0],t[2][1]*r[0][1],t[2][1]*r[0][2],t[2][1]*r[0][3],t[2][2]*r[0][0],t[2][2]*r[0][1],t[2][2]*r[0][2],t[2][2]*r[0][3],t[2][3]*r[0][0],t[2][3]*r[0][1],t[2][3]*r[0][2],t[2][3]*r[0][3]],[t[2][0]*r[1][0],t[2][0]*r[1][1],t[2][0]*r[1][2],t[2][0]*r[1][3],t[2][1]*r[1][0],t[2][1]*r[1][1],t[2][1]*r[1][2],t[2][1]*r[1][3],t[2][2]*r[1][0],t[2][2]*r[1][1],t[2][2]*r[1][2],t[2][2]*r[1][3],t[2][3]*r[1][0],t[2][3]*r[1][1],t[2][3]*r[1][2],t[2][3]*r[1][3]],[t[2][0]*r[2][0],t[2][0]*r[2][1],t[2][0]*r[2][2],t[2][0]*r[2][3],t[2][1]*r[2][0],t[2][1]*r[2][1],t[2][1]*r[2][2],t[2][1]*r[2][3],t[2][2]*r[2][0],t[2][2]*r[2][1],t[2][2]*r[2][2],t[2][2]*r[2][3],t[2][3]*r[2][0],t[2][3]*r[2][1],t[2][3]*r[2][2],t[2][3]*r[2][3]],[t[2][0]*r[3][0],t[2][0]*r[3][1],t[2][0]*r[3][2],t[2][0]*r[3][3],t[2][1]*r[3][0],t[2][1]*r[3][1],t[2][1]*r[3][2],t[2][1]*r[3][3],t[2][2]*r[3][0],t[2][2]*r[3][1],t[2][2]*r[3][2],t[2][2]*r[3][3],t[2][3]*r[3][0],t[2][3]*r[3][1],t[2][3]*r[3][2],t[2][3]*r[3][3]],[t[3][0]*r[0][0],t[3][0]*r[0][1],t[3][0]*r[0][2],t[3][0]*r[0][3],t[3][1]*r[0][0],t[3][1]*r[0][1],t[3][1]*r[0][2],t[3][1]*r[0][3],t[3][2]*r[0][0],t[3][2]*r[0][1],t[3][2]*r[0][2],t[3][2]*r[0][3],t[3][3]*r[0][0],t[3][3]*r[0][1],t[3][3]*r[0][2],t[3][3]*r[0][3]],[t[3][0]*r[1][0],t[3][0]*r[1][1],t[3][0]*r[1][2],t[3][0]*r[1][3],t[3][1]*r[1][0],t[3][1]*r[1][1],t[3][1]*r[1][2],t[3][1]*r[1][3],t[3][2]*r[1][0],t[3][2]*r[1][1],t[3][2]*r[1][2],t[3][2]*r[1][3],t[3][3]*r[1][0],t[3][3]*r[1][1],t[3][3]*r[1][2],t[3][3]*r[1][3]],[t[3][0]*r[2][0],t[3][0]*r[2][1],t[3][0]*r[2][2],t[3][0]*r[2][3],t[3][1]*r[2][0],t[3][1]*r[2][1],t[3][1]*r[2][2],t[3][1]*r[2][3],t[3][2]*r[2][0],t[3][2]*r[2][1],t[3][2]*r[2][2],t[3][2]*r[2][3],t[3][3]*r[2][0],t[3][3]*r[2][1],t[3][3]*r[2][2],t[3][3]*r[2][3]],[t[3][0]*r[3][0],t[3][0]*r[3][1],t[3][0]*r[3][2],t[3][0]*r[3][3],t[3][1]*r[3][0],t[3][1]*r[3][1],t[3][1]*r[3][2],t[3][1]*r[3][3],t[3][2]*r[3][0],t[3][2]*r[3][1],t[3][2]*r[3][2],t[3][2]*r[3][3],t[3][3]*r[3][0],t[3][3]*r[3][1],t[3][3]*r[3][2],t[3][3]*r[3][3]]);{const n=e.matr.init();for(let o=0;o<e.matr.rows(t);o++)for(let i=0;i<e.matr.cols(t);i++)for(let a=0;a<e.matr.rows(r);a++)for(let s=0;s<e.matr.cols(r);s++)n[o*e.matr.rows(r)+a]||(n[o*e.matr.rows(r)+a]=[]),n[o*e.matr.rows(r)+a][i*e.matr.cols(r)+s]=t[o][i]*r[a][s];return n}},t.mulVector=(t,n)=>{if(n=r(n),e.vect.isDimensionOf(n,2))return 2===e.matr.rows(t)?e.matr.toVector(e.matr.mul(t,e.vect.toMatrix(n)),2):e.matr.mul(t,e.vect.toMatrix(n));if(e.vect.isDimensionOf(n,3))return 3===e.matr.rows(t)?e.matr.toVector(e.matr.mul(t,e.vect.toMatrix(n)),3):e.matr.mul(t,e.vect.toMatrix(n));if(e.vect.isDimensionOf(n,4))return 4===e.matr.rows(t)?e.matr.toVector(e.matr.mul(t,e.vect.toMatrix(n)),4):e.matr.mul(t,e.vect.toMatrix(n));throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.negate=t=>{if(e.matr.isSizeOf(t,2))return e.matr.init([-t[0][0],-t[0][1]],[-t[1][0],-t[1][1]]);if(e.matr.isSizeOf(t,3))return e.matr.init([-t[0][0],-t[0][1],-t[0][2]],[-t[1][0],-t[1][1],-t[1][2]],[-t[2][0],-t[2][1],-t[2][2]]);if(e.matr.isSizeOf(t,4))return e.matr.init([-t[0][0],-t[0][1],-t[0][2],-t[0][3]],[-t[1][0],-t[1][1],-t[1][2],-t[1][3]],[-t[2][0],-t[2][1],-t[2][2],-t[2][3]],[-t[3][0],-t[3][1],-t[3][2],-t[3][3]]);{const r=e.matr.init();for(let n=0;n<e.matr.rows(t);n++){r[n]=[];for(let o=0;o<e.matr.cols(t);o++)r[n][o]=-t[n][o]}return r}},t.norm=(t,r=2,n=2)=>{if(e.matr.isSizeOf(t,2)&&2===r&&2===n)return e.real.sqrt(t[0][0]*t[0][0]+t[0][1]*t[0][1]+t[1][0]*t[1][0]+t[1][1]*t[1][1]);if(e.matr.isSizeOf(t,3)&&2===r&&2===n)return e.real.sqrt(t[0][0]*t[0][0]+t[0][1]*t[0][1]+t[0][2]*t[0][2]+t[1][0]*t[1][0]+t[1][1]*t[1][1]+t[1][2]*t[1][2]+t[2][0]*t[2][0]+t[2][1]*t[2][1]+t[2][2]*t[2][2]);if(e.matr.isSizeOf(t,4)&&2===r&&2===n)return e.real.sqrt(t[0][0]*t[0][0]+t[0][1]*t[0][1]+t[0][2]*t[0][2]+t[0][3]*t[0][3]+t[1][0]*t[1][0]+t[1][1]*t[1][1]+t[1][2]*t[1][2]+t[1][3]*t[1][3]+t[2][0]*t[2][0]+t[2][1]*t[2][1]+t[2][2]*t[2][2]+t[2][3]*t[2][3]+t[3][0]*t[3][0]+t[3][1]*t[3][1]+t[3][2]*t[3][2]+t[3][3]*t[3][3]);{let o=0;for(let i=0;i<e.matr.rows(t);i++){let a=0;for(let n=0;n<e.matr.cols(t);n++)a+=e.real.pow(t[i][n],r);o+=e.real.pow(a,n/r)}return e.real.pow(o,1/n)}},t.normalize=(t,r=2,n=2)=>{if(e.matr.isSizeOf(t,2))return e.matr.init([t[0][0]/e.matr.norm(t,r,n),t[0][1]/e.matr.norm(t,r,n)],[t[1][0]/e.matr.norm(t,r,n),t[1][1]/e.matr.norm(t,r,n)]);if(e.matr.isSizeOf(t,3))return e.matr.init([t[0][0]/e.matr.norm(t,r,n),t[0][1]/e.matr.norm(t,r,n),t[0][2]/e.matr.norm(t,r,n)],[t[1][0]/e.matr.norm(t,r,n),t[1][1]/e.matr.norm(t,r,n),t[1][2]/e.matr.norm(t,r,n)],[t[2][0]/e.matr.norm(t,r,n),t[2][1]/e.matr.norm(t,r,n),t[2][2]/e.matr.norm(t,r,n)]);if(e.matr.isSizeOf(t,4))return e.matr.init([t[0][0]/e.matr.norm(t,r,n),t[0][1]/e.matr.norm(t,r,n),t[0][2]/e.matr.norm(t,r,n),t[0][3]/e.matr.norm(t,r,n)],[t[1][0]/e.matr.norm(t,r,n),t[1][1]/e.matr.norm(t,r,n),t[1][2]/e.matr.norm(t,r,n),t[1][3]/e.matr.norm(t,r,n)],[t[2][0]/e.matr.norm(t,r,n),t[2][1]/e.matr.norm(t,r,n),t[2][2]/e.matr.norm(t,r,n),t[2][3]/e.matr.norm(t,r,n)],[t[3][0]/e.matr.norm(t,r,n),t[3][1]/e.matr.norm(t,r,n),t[3][2]/e.matr.norm(t,r,n),t[3][3]/e.matr.norm(t,r,n)]);{const o=e.matr.init();for(let i=0;i<e.matr.rows(t);i++){o[i]=[];for(let a=0;a<e.matr.cols(t);a++)o[i][a]=t[i][a]/e.matr.norm(t,r,n)}return o}},t.normsq=(t,r=2,n=2)=>{if(e.matr.isSizeOf(t,2)&&2===r&&2===n)return t[0][0]*t[0][0]+t[0][1]*t[0][1]+t[1][0]*t[1][0]+t[1][1]*t[1][1];if(e.matr.isSizeOf(t,3)&&2===r&&2===n)return t[0][0]*t[0][0]+t[0][1]*t[0][1]+t[0][2]*t[0][2]+t[1][0]*t[1][0]+t[1][1]*t[1][1]+t[1][2]*t[1][2]+t[2][0]*t[2][0]+t[2][1]*t[2][1]+t[2][2]*t[2][2];if(e.matr.isSizeOf(t,4)&&2===r&&2===n)return t[0][0]*t[0][0]+t[0][1]*t[0][1]+t[0][2]*t[0][2]+t[0][3]*t[0][3]+t[1][0]*t[1][0]+t[1][1]*t[1][1]+t[1][2]*t[1][2]+t[1][3]*t[1][3]+t[2][0]*t[2][0]+t[2][1]*t[2][1]+t[2][2]*t[2][2]+t[2][3]*t[2][3]+t[3][0]*t[3][0]+t[3][1]*t[3][1]+t[3][2]*t[3][2]+t[3][3]*t[3][3];{let o=0;for(let i=0;i<e.matr.rows(t);i++){let a=0;for(let n=0;n<e.matr.cols(t);n++)a+=e.real.pow(t[i][n],r);o+=e.real.pow(a,n/r)}return o}},t.nullspace=t=>{const r=t.map(r=>r.slice().concat(Array(e.matr.rows(t)).fill(0)));return e.matr.Gaussian(r).filter(r=>r.slice(0,e.matr.rows(t)).every(e=>0===e)).map(r=>r.slice(e.matr.rows(t)))},t.perm=t=>{if(e.matr.isSquare(t)){if(1===e.matr.rows(t))return t[0][0];if(2===e.matr.rows(t))return t[0][0]*t[1][1]+t[0][1]*t[1][0];if(3===e.matr.rows(t))return t[0][0]*(t[1][1]*t[2][2]+t[1][2]*t[2][1])+t[0][1]*(t[1][0]*t[2][2]+t[1][2]*t[2][0])+t[0][2]*(t[1][0]*t[2][1]+t[1][1]*t[2][0]);if(4===e.matr.rows(t))return t[0][0]*(t[1][1]*(t[2][2]*t[3][3]+t[2][3]*t[3][2])+t[1][2]*(t[2][1]*t[3][3]+t[2][3]*t[3][1])+t[1][3]*(t[2][1]*t[3][2]+t[2][2]*t[3][1]))+t[0][1]*(t[1][0]*(t[2][2]*t[3][3]+t[2][3]*t[3][2])+t[1][2]*(t[2][0]*t[3][3]+t[2][3]*t[3][0])+t[1][3]*(t[2][0]*t[3][2]+t[2][2]*t[3][0]))+t[0][2]*(t[1][0]*(t[2][1]*t[3][3]+t[2][3]*t[3][1])+t[1][1]*(t[2][0]*t[3][3]+t[2][3]*t[3][0])+t[1][3]*(t[2][0]*t[3][1]+t[2][1]*t[3][0]))+t[0][3]*(t[1][0]*(t[2][1]*t[3][2]+t[2][2]*t[3][1])+t[1][1]*(t[2][0]*t[3][2]+t[2][2]*t[3][0])+t[1][2]*(t[2][0]*t[3][1]+t[2][1]*t[3][0]));{let r=0;for(let n=0;n<e.matr.rows(t);n++){const o=t[0][n]*e.matr.perm(e.matr.cofactor(t,0,n));r+=Math.abs(o)}return r}}throw new TypeError('Parameter "matr" must be of type "ChalkboardMatrix" that is square.')},t.pow=(t,r)=>{if(e.matr.isSquare(t)){if(0===r)return e.matr.identity(e.matr.rows(t));{let n=t;for(let o=1;o<r;o++)n=e.matr.mul(t,n);return n}}throw new TypeError('Parameter "matr" must be of type "ChalkboardMatrix" that is square.')},t.print=t=>{console.log(e.matr.toString(t))},t.pull=(t,r,n)=>{if(0===n)return t.splice(r,1),t;if(1===n){for(let n=0;n<e.matr.rows(t);n++)t[n].splice(r,1);return t}throw new TypeError('Parameter "axis" must be 0 or 1.')},t.push=(t,r,n,o)=>{if(0===n)return t.splice(r,0,o),t;if(1===n){for(let n=0;n<e.matr.rows(t);n++)t[n].splice(r,0,o[n]);return t}throw new TypeError('Parameter "axis" must be 0 or 1.')},t.QRdecomp=t=>{const r=e.matr.identity(e.matr.rows(t)),n=e.matr.copy(t);for(let o=0;o<Math.min(e.matr.rows(t),e.matr.cols(t))-(e.matr.rows(t)>e.matr.cols(t)?0:1);o++){let i=0;for(let r=o;r<e.matr.rows(t);r++)i+=n[r][o]*n[r][o];i=e.real.sqrt(i);const a=[];a[0]=i-n[o][o];let s=a[0]*a[0];for(let r=1;r<e.matr.rows(t)-o;r++)a[r]=-n[r+o][o],s+=a[r]*a[r];s=1/e.real.sqrt(s);for(let e=0;e<a.length;e++)a[e]*=s;n[o][o]=i;for(let t=o+1;t<e.matr.rows(n);t++)n[t][o]=0;for(let t=o+1;t<e.matr.cols(n);t++){let e=0;for(let r=0;r<a.length;r++)e+=a[r]*n[r+o][t];e*=2;for(let r=0;r<a.length;r++)n[r+o][t]-=e*a[r]}for(let t=0;t<e.matr.cols(r);t++){let e=0;for(let n=0;n<a.length;n++)e+=a[n]*r[t][n+o];e*=2;for(let n=0;n<a.length;n++)r[t][n+o]-=e*a[n]}}return{Q:r,R:n}},t.random=(t,r=t,n=0,o=1)=>{if(2===t&&2===r)return e.matr.init([e.numb.random(n,o),e.numb.random(n,o)],[e.numb.random(n,o),e.numb.random(n,o)]);if(3===t&&3===r)return e.matr.init([e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o)],[e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o)],[e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o)]);if(4===t&&4===r)return e.matr.init([e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o)],[e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o)],[e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o)],[e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o),e.numb.random(n,o)]);{const i=e.matr.init();for(let a=0;a<t;a++){i.push([]);for(let t=0;t<r;t++)i[a].push(e.numb.random(n,o))}return i}},t.rank=t=>e.matr.Gaussian(t).filter(e=>e.some(e=>0!==e)).length,t.reciprocate=t=>{if(e.matr.isSizeOf(t,2))return e.matr.init([1/t[0][0],1/t[0][1]],[1/t[1][0],1/t[1][1]]);if(e.matr.isSizeOf(t,3))return e.matr.init([1/t[0][0],1/t[0][1],1/t[0][2]],[1/t[1][0],1/t[1][1],1/t[1][2]],[1/t[2][0],1/t[2][1],1/t[2][2]]);if(e.matr.isSizeOf(t,4))return e.matr.init([1/t[0][0],1/t[0][1],1/t[0][2],1/t[0][3]],[1/t[1][0],1/t[1][1],1/t[1][2],1/t[1][3]],[1/t[2][0],1/t[2][1],1/t[2][2],1/t[2][3]],[1/t[3][0],1/t[3][1],1/t[3][2],1/t[3][3]]);{const r=e.matr.init();for(let n=0;n<e.matr.rows(t);n++){r[n]=[];for(let o=0;o<e.matr.cols(t);o++)r[n][o]=1/t[n][o]}return r}},t.resize=(t,r,n=r)=>{const o=e.matr.init(),i=e.matr.rows(t),a=e.matr.cols(t);for(let e=0;e<r;e++){o.push([]);for(let r=0;r<n;r++)o[e].push(e<i&&r<a?t[e][r]:0)}return o},t.rotator=(t,r,n)=>{if(void 0===r&&void 0===n)return e.matr.init([Math.cos(t),-Math.sin(t)],[Math.sin(t),Math.cos(t)]);{const o=e.matr.init([1,0,0],[0,Math.cos(t),-Math.sin(t)],[0,Math.sin(t),Math.cos(t)]),i=e.matr.init([Math.cos(r),0,Math.sin(r)],[0,1,0],[-Math.sin(r),0,Math.cos(r)]),a=e.matr.init([Math.cos(n),-Math.sin(n),0],[Math.sin(n),Math.cos(n),0],[0,0,1]);return e.matr.mul(e.matr.mul(a,i),o)}},t.round=t=>{if(e.matr.isSizeOf(t,2))return e.matr.init([Math.round(t[0][0]),Math.round(t[0][1])],[Math.round(t[1][0]),Math.round(t[1][1])]);if(e.matr.isSizeOf(t,3))return e.matr.init([Math.round(t[0][0]),Math.round(t[0][1]),Math.round(t[0][2])],[Math.round(t[1][0]),Math.round(t[1][1]),Math.round(t[1][2])],[Math.round(t[2][0]),Math.round(t[2][1]),Math.round(t[2][2])]);if(e.matr.isSizeOf(t,4))return e.matr.init([Math.round(t[0][0]),Math.round(t[0][1]),Math.round(t[0][2]),Math.round(t[0][3])],[Math.round(t[1][0]),Math.round(t[1][1]),Math.round(t[1][2]),Math.round(t[1][3])],[Math.round(t[2][0]),Math.round(t[2][1]),Math.round(t[2][2]),Math.round(t[2][3])],[Math.round(t[3][0]),Math.round(t[3][1]),Math.round(t[3][2]),Math.round(t[3][3])]);{const r=e.matr.init();for(let n=0;n<e.matr.rows(t);n++){r[n]=[];for(let o=0;o<e.matr.cols(t);o++)r[n][o]=Math.round(t[n][o])}return r}},t.rows=e=>e.length,t.rowspace=t=>e.matr.Gaussian(t).filter(e=>e.some(e=>0!==e)),t.scaler=t=>{if("number"==typeof(t=r(t)).x&&"number"==typeof t.y&&void 0===t.z&&void 0===t.w)return e.matr.init([t.x,0],[0,t.y]);if("number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.z&&void 0===t.w)return e.matr.init([t.x,0,0],[0,t.y,0],[0,0,t.z]);if("number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.z&&"number"==typeof t.w)return e.matr.init([t.x,0,0,0],[0,t.y,0,0],[0,0,t.z,0],[0,0,0,t.w]);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.scl=(t,r)=>{if(e.matr.isSizeOf(t,2,1))return e.matr.init([t[0][0]*r],[t[1][0]*r]);if(e.matr.isSizeOf(t,2))return e.matr.init([t[0][0]*r,t[0][1]*r],[t[1][0]*r,t[1][1]*r]);if(e.matr.isSizeOf(t,3,1))return e.matr.init([t[0][0]*r],[t[1][0]*r],[t[2][0]*r]);if(e.matr.isSizeOf(t,3))return e.matr.init([t[0][0]*r,t[0][1]*r,t[0][2]*r],[t[1][0]*r,t[1][1]*r,t[1][2]*r],[t[2][0]*r,t[2][1]*r,t[2][2]*r]);if(e.matr.isSizeOf(t,4,1))return e.matr.init([t[0][0]*r],[t[1][0]*r],[t[2][0]*r],[t[3][0]*r]);if(e.matr.isSizeOf(t,4))return e.matr.init([t[0][0]*r,t[0][1]*r,t[0][2]*r,t[0][3]*r],[t[1][0]*r,t[1][1]*r,t[1][2]*r,t[1][3]*r],[t[2][0]*r,t[2][1]*r,t[2][2]*r,t[2][3]*r],[t[3][0]*r,t[3][1]*r,t[3][2]*r,t[3][3]*r]);{const n=e.matr.init();for(let o=0;o<e.matr.rows(t);o++){n[o]=[];for(let i=0;i<e.matr.cols(t);i++)n[o][i]=t[o][i]*r}return n}},t.solve=(t,r)=>{if(e.matr.isSquare(t)){if(e.matr.rows(t)===e.matr.rows(r)){if(0!==e.matr.det(t))return e.matr.mul(e.matr.invert(t),r);throw new TypeError('Parameter "matrA" must be of type "ChalkboardMatrix" that has a non-zero determinant.')}throw new TypeError('Parameters "matrA" and "matrB" must be of type "ChalkboardMatrix" with equivalent numbers of rows.')}throw new TypeError('Parameter "matrA" must be of type "ChalkboardMatrix" that is square.')},t.sub=(t,r)=>{if(e.matr.isSizeEqual(t,r)){if(e.matr.isSizeOf(t,2))return e.matr.init([t[0][0]-r[0][0],t[0][1]-r[0][1]],[t[1][0]-r[1][0],t[1][1]-r[1][1]]);if(e.matr.isSizeOf(t,3))return e.matr.init([t[0][0]-r[0][0],t[0][1]-r[0][1],t[0][2]-r[0][2]],[t[1][0]-r[1][0],t[1][1]-r[1][1],t[1][2]-r[1][2]],[t[2][0]-r[2][0],t[2][1]-r[2][1],t[2][2]-r[2][2]]);if(e.matr.isSizeOf(t,4))return e.matr.init([t[0][0]-r[0][0],t[0][1]-r[0][1],t[0][2]-r[0][2],t[0][3]-r[0][3]],[t[1][0]-r[1][0],t[1][1]-r[1][1],t[1][2]-r[1][2],t[1][3]-r[1][3]],[t[2][0]-r[2][0],t[2][1]-r[2][1],t[2][2]-r[2][2],t[2][3]-r[2][3]],[t[3][0]-r[3][0],t[3][1]-r[3][1],t[3][2]-r[3][2],t[3][3]-r[3][3]]);{const n=e.matr.init();for(let o=0;o<e.matr.rows(t);o++){n[o]=[];for(let i=0;i<e.matr.cols(t);i++)n[o][i]=t[o][i]-r[o][i]}return n}}throw new TypeError('Parameters "matr1" and "matr2" must be of type "ChalkboardMatrix" with equivalent numbers of rows and columns.')},t.symmetricBinomial=t=>2===t?e.matr.init([1,1],[1,2]):3===t?e.matr.init([1,1,1],[1,2,3],[1,3,6]):4===t?e.matr.init([1,1,1,1],[1,2,3,4],[1,3,6,10],[1,4,10,20]):e.matr.mul(e.matr.lowerBinomial(t),e.matr.upperBinomial(t)),t.toArray=t=>{if(e.matr.isSizeOf(t,2))return[t[0][0],t[0][1],t[1][0],t[1][1]];if(e.matr.isSizeOf(t,3))return[t[0][0],t[0][1],t[0][2],t[1][0],t[1][1],t[1][2],t[2][0],t[2][1],t[2][2]];if(e.matr.isSizeOf(t,4))return[t[0][0],t[0][1],t[0][2],t[0][3],t[1][0],t[1][1],t[1][2],t[1][3],t[2][0],t[2][1],t[2][2],t[2][3],t[3][0],t[3][1],t[3][2],t[3][3]];{const r=[];for(let n=0;n<e.matr.rows(t);n++)for(let o=0;o<e.matr.cols(t);o++)r.push(t[n][o]);return r}},t.toObject=t=>{if(e.matr.isSizeOf(t,2))return{i1:{j1:t[0][0],j2:t[0][1]},i2:{j1:t[1][0],j2:t[1][1]}};if(e.matr.isSizeOf(t,3))return{i1:{j1:t[0][0],j2:t[0][1],j3:t[0][2]},i2:{j1:t[1][0],j2:t[1][1],j3:t[1][2]},i3:{j1:t[2][0],j2:t[2][1],j3:t[2][2]}};if(e.matr.isSizeOf(t,4))return{i1:{j1:t[0][0],j2:t[0][1],j3:t[0][2],j4:t[0][3]},i2:{j1:t[1][0],j2:t[1][1],j3:t[1][2],j4:t[1][3]},i3:{j1:t[2][0],j2:t[2][1],j3:t[2][2],j4:t[2][3]},i4:{j1:t[3][0],j2:t[3][1],j3:t[3][2],j4:t[3][3]}};{const r={};for(let n=0;n<e.matr.rows(t);n++){r["i"+(n+1)]={};for(let o=0;o<e.matr.cols(t);o++)r["i"+(n+1)]["j"+(o+1)]=t[n][o]}return r}},t.toSet=t=>e.abal.set(e.matr.toArray(t)),t.toString=t=>{if(e.matr.isSizeOf(t,2))return"[ "+t[0][0].toString()+" "+t[0][1].toString()+" ]\n[ "+t[1][0].toString()+" "+t[1][1].toString()+" ]";if(e.matr.isSizeOf(t,3))return"[ "+t[0][0].toString()+" "+t[0][1].toString()+" "+t[0][2].toString()+" ]\n[ "+t[1][0].toString()+" "+t[1][1].toString()+" "+t[1][2].toString()+" ]\n[ "+t[2][0].toString()+" "+t[2][1].toString()+" "+t[2][2].toString()+" ]";if(e.matr.isSizeOf(t,4))return"[ "+t[0][0].toString()+" "+t[0][1].toString()+" "+t[0][2].toString()+" "+t[0][3].toString()+" ]\n[ "+t[1][0].toString()+" "+t[1][1].toString()+" "+t[1][2].toString()+" "+t[1][3].toString()+" ]\n[ "+t[2][0].toString()+" "+t[2][1].toString()+" "+t[2][2].toString()+" "+t[2][3].toString()+" ]\n[ "+t[3][0].toString()+" "+t[3][1].toString()+" "+t[3][2].toString()+" "+t[3][3].toString()+" ]";{let r="";for(let n=0;n<e.matr.rows(t);n++){r+="[ ";for(let o=0;o<e.matr.cols(t);o++)r+=t[n][o].toString()+" ";r=r.trimEnd()+" ]\n"}return r}},t.toTensor=(t,...r)=>(r=Array.isArray(r[0])?r[0]:r,e.tens.resize(t,...r)),t.toTypedArray=(t,r="float32")=>{const n=e.matr.toArray(t);if("int8"===r)return new Int8Array(n);if("int16"===r)return new Int16Array(n);if("int32"===r)return new Int32Array(n);if("float32"===r)return new Float32Array(n);if("float64"===r)return new Float64Array(n);if("bigint64"===r)return new BigInt64Array(n.map(e=>BigInt(Math.floor(e))));throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".')},t.toVector=(t,r,n=0,o=0)=>{if(2===r){if(0===o)return e.vect.init(t[0][n],t[1][n]);if(1===o)return e.vect.init(t[n][0],t[n][1]);throw new TypeError('Parameter "axis" must be 0 or 1.')}if(3===r){if(0===o)return e.vect.init(t[0][n],t[1][n],t[2][n]);if(1===o)return e.vect.init(t[n][0],t[n][1],t[n][2]);throw new TypeError('Parameter "axis" must be 0 or 1.')}if(4===r){if(0===o)return e.vect.init(t[0][n],t[1][n],t[2][n],t[3][n]);if(1===o)return e.vect.init(t[n][0],t[n][1],t[n][2],t[n][3]);throw new TypeError('Parameter "axis" must be 0 or 1.')}throw new TypeError('Parameter "dimension" must be 2, 3, or 4.')},t.trace=t=>{if(e.matr.isSquare(t)){if(2===e.matr.rows(t))return t[0][0]+t[1][1];if(3===e.matr.rows(t))return t[0][0]+t[1][1]+t[2][2];if(4===e.matr.rows(t))return t[0][0]+t[1][1]+t[2][2]+t[3][3];{let r=0;for(let n=0;n<e.matr.rows(t);n++)r+=t[n][n];return r}}throw new TypeError('Parameter "matr" must be of type "ChalkboardMatrix" that is square.')},t.transpose=t=>{if(e.matr.isSizeOf(t,2))return e.matr.init([t[0][0],t[1][0]],[t[0][1],t[1][1]]);if(e.matr.isSizeOf(t,3))return e.matr.init([t[0][0],t[1][0],t[2][0]],[t[0][1],t[1][1],t[2][1]],[t[0][2],t[1][2],t[2][2]]);if(e.matr.isSizeOf(t,4))return e.matr.init([t[0][0],t[1][0],t[2][0],t[3][0]],[t[0][1],t[1][1],t[2][1],t[3][1]],[t[0][2],t[1][2],t[2][2],t[3][2]],[t[0][3],t[1][3],t[2][3],t[3][3]]);{const r=e.matr.init();for(let n=0;n<e.matr.cols(t);n++){r[n]=[];for(let o=0;o<e.matr.rows(t);o++)r[n][o]=t[o][n]}return r}},t.translator=t=>{if("number"==typeof(t=r(t)).x&&"number"==typeof t.y&&void 0===t.z&&void 0===t.w)return e.matr.init([1,0,t.x],[0,1,t.y],[0,0,1]);if("number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.z&&void 0===t.w)return e.matr.init([1,0,0,t.x],[0,1,0,t.y],[0,0,1,t.z],[0,0,0,1]);if("number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.z&&"number"==typeof t.w)return e.matr.init([1,0,0,0,t.x],[0,1,0,0,t.y],[0,0,1,0,t.z],[0,0,0,1,t.w],[0,0,0,0,1]);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.upperBinomial=t=>{if(2===t)return e.matr.init([1,1],[0,1]);if(3===t)return e.matr.init([1,2,1],[0,1,1],[0,0,1]);if(4===t)return e.matr.init([1,3,3,1],[0,1,2,1],[0,0,1,1],[0,0,0,1]);{const r=e.matr.init();for(let n=0;n<t;n++){r.push([]);for(let o=0;o<t;o++)r[n].push(e.numb.binomial(o,n))}return r}},t.upperShift=t=>{if(2===t)return e.matr.init([0,1],[0,0]);if(3===t)return e.matr.init([0,1,0],[0,0,1],[0,0,0]);if(4===t)return e.matr.init([0,1,0,0],[0,0,1,0],[0,0,0,1],[0,0,0,0]);{const r=e.matr.init();for(let n=0;n<t;n++){r[n]=[];for(let o=0;o<t;o++)r[n][o]=e.numb.Kronecker(n+1,o)}return r}},t.upperTriangular=(t,...r)=>{if(2===t)return e.matr.init([r[0]||0,r[1]||0],[0,r[2]||0]);if(3===t)return e.matr.init([r[0]||0,r[1]||0,r[2]||0],[0,r[3]||0,r[4]||0],[0,0,r[5]||0]);if(4===t)return e.matr.init([r[0]||0,r[1]||0,r[2]||0,r[3]||0],[0,r[4]||0,r[5]||0,r[6]||0],[0,0,r[7]||0,r[8]||0],[0,0,0,r[9]||0]);{r=Array.isArray(r[0])?r[0]:r;const n=e.matr.init();let o=0;for(let e=0;e<t;e++){n[e]=[];for(let i=0;i<t;i++)n[e][i]=i>=e&&r[o++]||0}return n}},t.zero=(t,r=t)=>{if(2===t&&2===r)return e.matr.init([0,0],[0,0]);if(3===t&&3===r)return e.matr.init([0,0,0],[0,0,0],[0,0,0]);if(4===t&&4===r)return e.matr.init([0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]);{const n=e.matr.init();for(let e=0;e<t;e++){n[e]=[];for(let t=0;t<r;t++)n[e][t]=0}return n}}}(t=e.matr||(e.matr={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){t.Bernoullian=(e=.5)=>{if("number"!=typeof e||!Number.isFinite(e)||e<0||e>1)throw new Error('Chalkboard.numb.Bernoullian: Parameter "p" must be a finite number between 0 and 1.');return Math.random()<e?1:0},t.binomial=(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t)||e<0||t<0)throw new Error('Chalkboard.numb.binomial: Parameters "n" and "k" must be non-negative integers.');if(t<0||t>e)return 0;if(0===t||t===e)return 1;if(1===t||t===e-1)return e;e-t<t&&(t=e-t);let r=e;for(let n=2;n<=t;n++)r*=(e-n+1)/n;return Math.round(r)},t.change=(e,t)=>{if("number"!=typeof e||"number"!=typeof t||!Number.isFinite(e)||!Number.isFinite(t))throw new Error('Chalkboard.numb.change: Parameters "initial" and "final" must be finite numbers.');if(0===e)throw new Error('Chalkboard.numb.change: Parameter "initial" must be non-zero.');return(t-e)/e},t.combination=(t,r)=>{if(!Number.isInteger(t)||!Number.isInteger(r)||t<0||r<0||r>t)throw new Error('Chalkboard.numb.combination: Parameters "n" and "r" must be integers with 0 <= r <= n.');return e.numb.binomial(t,r)},t.compositeArr=(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t))throw new Error('Chalkboard.numb.compositeArr: Parameters "inf" and "sup" must be integers.');if(e>t)throw new Error('Chalkboard.numb.compositeArr: Parameter "inf" must be less than or equal to "sup".');if(t<4)return[];const r=new Uint8Array(t+1);for(let e=2;e*e<=t;e++)if(0===r[e])for(let n=e*e;n<=t;n+=e)r[n]=1;const n=[];for(let o=Math.max(4,e);o<=t;o++)1===r[o]&&n.push(o);return n},t.compositeCount=(t,r)=>{if(!Number.isInteger(t)||!Number.isInteger(r))throw new Error('Chalkboard.numb.compositeCount: Parameters "inf" and "sup" must be integers.');if(t>r)throw new Error('Chalkboard.numb.compositeCount: Parameter "inf" must be less than or equal to "sup".');return e.numb.compositeArr(t,r).length},t.constrain=(e,t=[0,1])=>{if("number"!=typeof e||!Number.isFinite(e))throw new Error('Chalkboard.numb.constrain: Parameter "num" must be a finite number.');if(!Array.isArray(t)||2!==t.length||"number"!=typeof t[0]||"number"!=typeof t[1]||!Number.isFinite(t[0])||!Number.isFinite(t[1])||t[0]>t[1])throw new Error('Chalkboard.numb.constrain: Parameter "range" must be an array of two finite numbers [min, max] with min <= max.');return Math.max(Math.min(e,t[1]),t[0])},t.convert=(e,t,r)=>{if("string"!=typeof t||"string"!=typeof r)throw new Error('Chalkboard.numb.convert: Parameters "from" and "to" must be strings.');if(Array.isArray(e)){for(let t=0;t<e.length;t++)if("number"!=typeof e[t]||!Number.isFinite(e[t]))throw new Error(`Chalkboard.numb.convert: Parameter "num[${t}]" must be a finite number.`)}else if("number"!=typeof e||!Number.isFinite(e))throw new Error('Chalkboard.numb.convert: Parameter "num" must be a finite number.');const n=e=>(e=>e.trim().replace(/\s+/g," "))(e).replace(/\u00B5/g,"μ"),o={NM:"nm",Nm:"nm","µm":"μm",CM:"cm",Cm:"cm",M:"m",KM:"km",Km:"km",IN:"in",In:"in",FT:"ft",Ft:"ft",YD:"yd",Yd:"yd",MI:"mi",Mi:"mi",NMI:"nmi",Nmi:"nmi",M2:"m2",CM2:"cm2",MM2:"mm2",KM2:"km2",FT2:"ft2",IN2:"in2",YD2:"yd2",MI2:"mi2",NG:"ng","µg":"μg",MG:"mg",G:"g",KG:"kg",Kg:"kg",LB:"lb",Lb:"lb",l:"L",ml:"mL",cl:"cL",dl:"dL",dal:"daL",hl:"hL",kl:"kL",ul:"uL","μl":"μL","µl":"μL","fl. oz":"fl oz","fl.oz":"fl oz",floz:"fl oz",OZ:"oz",Oz:"oz",pa:"Pa",hpa:"hPa",kpa:"kPa",mpa:"MPa",gpa:"GPa",ATM:"atm",Atm:"atm",Torr:"torr",mmhg:"mmHg",NS:"ns",US:"μs",Us:"μs","µS":"μs",MS:"ms",Ms:"ms",HR:"h",Hr:"h",HRS:"h",Hrs:"h",YR:"yr",Yr:"yr",WK:"wk",Wk:"wk",c:"C","°c":"C","°C":"C",celsius:"C",f:"F","°f":"F","°F":"F",fahrenheit:"F",k:"K","°k":"K","°K":"K",kelvin:"K",r:"R","°r":"R","°R":"R",rankine:"R"},i={K:{a:1,b:0,key:"K"},C:{a:1,b:273.15,key:"C"},F:{a:5/9,b:273.15-160/9,key:"F"},R:{a:5/9,b:0,key:"R"}},a=[["length",{fm:1e-15,femtometer:1e-15,femtometers:1e-15,pm:1e-12,picometer:1e-12,picometers:1e-12,nm:1e-9,nanometer:1e-9,nanometers:1e-9,"μm":1e-6,um:1e-6,micrometer:1e-6,micrometers:1e-6,mm:.001,millimeter:.001,millimeters:.001,cm:.01,centimeter:.01,centimeters:.01,dm:.1,decimeter:.1,decimeters:.1,m:1,meter:1,meters:1,dam:10,decameter:10,decameters:10,hm:100,hectometer:100,hectometers:100,km:1e3,kilometer:1e3,kilometers:1e3,Mm:1e6,megameter:1e6,megameters:1e6,Gm:1e9,gigameter:1e9,gigameters:1e9,Tm:1e12,terameter:1e12,terameters:1e12,Pm:1e15,petameter:1e15,petameters:1e15,in:.0254,inch:.0254,inches:.0254,ft:.3048,foot:.3048,feet:.3048,yd:.9144,yard:.9144,yards:.9144,mi:1609.344,mile:1609.344,miles:1609.344,nmi:1852,"nautical mile":1852,"nautical miles":1852,ly:94607e11,lyr:94607e11,"light year":94607e11,"light years":94607e11}],["area",{"mm²":1e-6,mm2:1e-6,"square millimeter":1e-6,"square millimeters":1e-6,"cm²":1e-4,cm2:1e-4,"square centimeter":1e-4,"square centimeters":1e-4,"dm²":.01,dm2:.01,"square decimeter":.01,"square decimeters":.01,"m²":1,m2:1,"square meter":1,"square meters":1,a:100,are:100,ares:100,ha:1e4,hectare:1e4,hectares:1e4,"km²":1e6,km2:1e6,"square kilometer":1e6,"square kilometers":1e6,"in²":64516e-8,in2:64516e-8,"square inch":64516e-8,"square inches":64516e-8,"ft²":.09290304,ft2:.09290304,"square foot":.09290304,"square feet":.09290304,"yd²":.83612736,yd2:.83612736,"square yard":.83612736,"square yards":.83612736,acre:4046.8564224,acres:4046.8564224,"mi²":2589988.110336,mi2:2589988.110336,"square mile":2589988.110336,"square miles":2589988.110336}],["mass",{fg:1e-15,femtogram:1e-15,femtograms:1e-15,pg:1e-12,picogram:1e-12,picograms:1e-12,ng:1e-9,nanogram:1e-9,nanograms:1e-9,"μg":1e-6,ug:1e-6,microgram:1e-6,micrograms:1e-6,mg:.001,milligram:.001,milligrams:.001,cg:.01,centigram:.01,centigrams:.01,dg:.1,decigram:.1,decigrams:.1,g:1,gram:1,grams:1,dag:10,decagram:10,decagrams:10,hg:100,hectogram:100,hectograms:100,kg:1e3,kilogram:1e3,kilograms:1e3,Mg:1e6,megagram:1e6,megagrams:1e6,Gg:1e9,gigagram:1e9,gigagrams:1e9,Tg:1e12,teragram:1e12,teragrams:1e12,Pg:1e15,petagram:1e15,petagrams:1e15,oz:28.349523125,ounce:28.349523125,ounces:28.349523125,lb:453.59237,lbs:453.59237,pound:453.59237,pounds:453.59237,st:6350.29318,stone:6350.29318,stones:6350.29318,tn:907184.74,ton:907184.74,tons:907184.74,t:1e6,"metric ton":1e6,"metric tons":1e6}],["volume",{fL:1e-15,femtoliter:1e-15,femtoliters:1e-15,pL:1e-12,picoliter:1e-12,picoliters:1e-12,nL:1e-9,nanoliter:1e-9,nanoliters:1e-9,"μL":1e-6,uL:1e-6,microliter:1e-6,microliters:1e-6,mL:.001,milliliter:.001,milliliters:.001,cL:.01,centiliter:.01,centiliters:.01,dL:.1,deciliter:.1,deciliters:.1,L:1,l:1,liter:1,liters:1,daL:10,decaliter:10,decaliters:10,hL:100,hectoliter:100,hectoliters:100,kL:1e3,kiloliter:1e3,kiloliters:1e3,ML:1e6,megaliter:1e6,megaliters:1e6,GL:1e9,gigaliter:1e9,gigaliters:1e9,TL:1e12,teraliter:1e12,teraliters:1e12,PL:1e15,petaliter:1e15,petaliters:1e15,tsp:.00492892159,teaspoon:.00492892159,teaspoons:.00492892159,tbsp:.0147867648,Tbsp:.0147867648,tablespoon:.0147867648,tablespoons:.0147867648,"fl oz":.0295735296,"fluid ounce":.0295735296,"fluid ounces":.0295735296,cp:.2365882365,cup:.2365882365,cups:.2365882365,pt:.473176473,pint:.473176473,pints:.473176473,qt:.946352946,quart:.946352946,quarts:.946352946,gal:3.785411784,gallon:3.785411784,gallons:3.785411784}],["pressure",{Pa:1,pascal:1,pascals:1,hPa:100,hectopascal:100,hectopascals:100,kPa:1e3,kilopascal:1e3,kilopascals:1e3,MPa:1e6,megapascal:1e6,megapascals:1e6,GPa:1e9,gigapascal:1e9,gigapascals:1e9,bar:1e5,bars:1e5,mbar:100,millibar:100,millibars:100,atm:101325,atmosphere:101325,atmospheres:101325,torr:133.32236842105263,mmHg:133.32236842105263,"millimeter of mercury":133.32236842105263,"millimeters of mercury":133.32236842105263,psi:6894.757293168,"pound per square inch":6894.757293168,"pounds per square inch":6894.757293168}],["time",{ns:1e-9,nanosecond:1e-9,nanoseconds:1e-9,"μs":1e-6,us:1e-6,microsecond:1e-6,microseconds:1e-6,ms:.001,millisecond:.001,milliseconds:.001,s:1,sec:1,secs:1,second:1,seconds:1,min:60,mins:60,minute:60,minutes:60,h:3600,hr:3600,hrs:3600,hour:3600,hours:3600,d:86400,day:86400,days:86400,w:604800,wk:604800,wks:604800,week:604800,weeks:604800,yr:31557600,yrs:31557600,year:31557600,years:31557600}]],s=e=>{const t=n(e),r=o[t]??o[t.toLowerCase()],i=[];i.push(t),r&&i.push(r);(t.length>2||t.includes(" "))&&i.push(t.toLowerCase());const s=new Set,l=i.filter(e=>!s.has(e)&&(s.add(e),!0));for(const[e,t]of a)for(const r of l)if(Object.prototype.hasOwnProperty.call(t,r))return{category:e,factor:t[r],key:r}},l=e=>{const t=n(e),r=o[t]??o[t.toLowerCase()],a=[t];r&&a.push(r);const s=new Set,l=a.filter(e=>!s.has(e)&&(s.add(e),!0));for(const e of l)if(Object.prototype.hasOwnProperty.call(i,e))return i[e]},u=t=>Array.isArray(e)?e.map(t):t(e),m=l(t),f=l(r);if(m||f){if(!m)throw new Error(`Chalkboard.numb.convert: Unknown temperature unit: "${t}".`);if(!f)throw new Error(`Chalkboard.numb.convert: Unknown temperature unit: "${r}".`);const e=e=>m.a*e+m.b,n=e=>(e-f.b)/f.a;return u(t=>n(e(t)))}const c=s(t),p=s(r);if(!c)throw new Error(`Chalkboard.numb.convert: Unknown unit: "${t}".`);if(!p)throw new Error(`Chalkboard.numb.convert: Unknown unit: "${r}".`);if(c.category!==p.category)throw new Error(`Chalkboard.numb.convert: Incompatible unit conversion: "${t}" (${c.category}) -> "${r}" (${p.category}).`);const d=c.factor/p.factor;return u(e=>e*d)},t.divisors=e=>{if(!Number.isInteger(e)||e<=0)throw new Error('Chalkboard.numb.divisors: Parameter "num" must be a positive integer.');const t=[],r=Math.floor(Math.sqrt(e));for(let n=1;n<=r;n++)e%n===0&&(t.push(n),n!==e/n&&t.push(e/n));return t.sort((e,t)=>e-t)},t.Euler=t=>{if(!Number.isInteger(t)||t<=0)throw new Error('Chalkboard.numb.Euler: Parameter "num" must be a positive integer.');const r=e.numb.factors(t),n=[];for(let e=0;e<r.length;e++){const t=r[e];-1===n.indexOf(t)&&n.push(t)}let o=t;for(const e of n)o*=(e-1)/e;return Math.round(o)},t.exponential=(e=1)=>{if("number"!=typeof e||!Number.isFinite(e))throw new Error('Chalkboard.numb.exponential: Parameter "l" must be a finite number.');if(e<=0)throw new Error('Chalkboard.numb.exponential: Parameter "l" must be positive.');const t=1-Math.random();return-Math.log(t)/e},t.factorial=e=>{if(!Number.isInteger(e)||e<0)throw new Error('Chalkboard.numb.factorial: Parameter "num" must be a non-negative integer.');let t=1;for(let r=2;r<=e;r++)t*=r;return t},t.factors=t=>{if(!Number.isInteger(t))throw new Error('Chalkboard.numb.factors: Parameter "num" must be an integer.');if(0===t)throw new Error('Chalkboard.numb.factors: Parameter "num" must be non-zero.');const r=[];for(t<0&&(r.push(-1),t=Math.abs(t));t%2==0;)r.push(2),t/=2;for(let n=3;n<=e.real.sqrt(t);n+=2)for(;t%n===0;)r.push(n),t/=n;return t>1&&r.push(t),r},t.Fibonacci=e=>{if(!Number.isInteger(e)||e<0)throw new Error('Chalkboard.numb.Fibonacci: Parameter "num" must be a non-negative integer.');if(0===e)return 0;if(1===e)return 1;let t=0,r=1;for(let n=2;n<=e;n++){const e=t+r;t=r,r=e}return r},t.Gaussian=(t,r)=>{if(!Number.isFinite(t)||!Number.isFinite(r))throw new Error('Chalkboard.numb.Gaussian: Parameters "mean" and "deviation" must be finite numbers.');if(r<=0)throw new Error('Chalkboard.numb.Gaussian: Parameter "deviation" must be positive.');let n=0;for(;0===n;)n=Math.random();const o=Math.random();return t+e.real.sqrt(-2*e.real.ln(n))*e.trig.cos(e.PI(2)*o)*r},t.gcd=(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t))throw new Error('Chalkboard.numb.gcd: Parameters "a" and "b" must be integers.');for(e=Math.abs(e),t=Math.abs(t);0!==t;){const r=e%t;e=t,t=r}return e},t.Goldbach=t=>{if(!Number.isInteger(t)||t<4||t%2!=0)throw new Error('Chalkboard.numb.Goldbach: Parameter "num" must be an even integer greater than or equal to 4.');if(4!==t){let r=t/2,n=t/2;for(r%2==0&&(r--,n++);r>=3;){if(e.numb.isPrime(r)&&e.numb.isPrime(n))return[r,n];r-=2,n+=2}return}return[2,2]},t.isApproxEqual=(e,t,r=1e-6)=>{if("number"!=typeof e||"number"!=typeof t||"number"!=typeof r||!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||r<=0)throw new Error('Chalkboard.numb.isApproxEqual: Parameters "a", "b", and "precision" must be finite numbers, and "precision" must be positive.');return Math.abs(e-t)<r},t.isPrime=e=>{if("number"!=typeof e||!Number.isInteger(e)||e<2)return!1;if(2===e)return!0;if(e%2==0)return!1;for(let t=3;t*t<=e;t+=2)if(e%t===0)return!1;return!0},t.isRational=(t,r=1e-8)=>{if("number"!=typeof t||!Number.isFinite(t)||"number"!=typeof r||!Number.isFinite(r)||r<=0)return!1;const n=t/e.PI();if(0!==n&&Math.abs(Math.round(n)-n)<r)return!1;if(t>0){const n=Math.log(t);if(0!==n&&Math.abs(Math.round(n)-n)<r){const o=e.E(Math.round(n));if(Math.abs(t-o)<r)return!1}}for(let n=2;n<=6;n++){const o=e.PI()/n;for(let e=1;e<=4*n;e++)if(e%n!==0&&Math.abs(t-e*o)<r)return!1}const o=[e.E(-1),e.E(.5),e.real.sqrt(e.PI()),e.E(),e.PI(),e.E(2)];for(let t=2;t<=100;t++)Number.isInteger(Math.sqrt(t))||o.push(e.real.sqrt(t));for(const e of o)if(Math.abs(t-e)<r)return!1;try{const[n,o]=e.numb.toFraction(t,r);return Math.abs(t-n/o)<r&&Math.abs(o)<=1e5}catch{return!1}},t.Kronecker=(e,t)=>{if("number"!=typeof e||"number"!=typeof t||!Number.isFinite(e)||!Number.isFinite(t))throw new Error('Chalkboard.numb.Kronecker: Parameters "a" and "b" must be finite numbers.');return e===t?1:0},t.lcm=(t,r)=>{if(!Number.isInteger(t)||!Number.isInteger(r))throw new Error('Chalkboard.numb.lcm: Parameters "a" and "b" must be integers.');return 0===t||0===r?0:Math.abs(t/e.numb.gcd(t,r)*r)},t.map=(e,t,r)=>{if(!Array.isArray(t)||!Array.isArray(r))throw new Error('Chalkboard.numb.map: Parameters "range1" and "range2" must be arrays.');if(2!==t.length||2!==r.length)throw new Error('Chalkboard.numb.map: Parameters "range1" and "range2" must be arrays of length 2.');if("number"!=typeof e||!Number.isFinite(e))throw new Error('Chalkboard.numb.map: Parameter "num" must be a finite number.');if("number"!=typeof t[0]||"number"!=typeof t[1]||!Number.isFinite(t[0])||!Number.isFinite(t[1])||t[0]>=t[1])throw new Error('Chalkboard.numb.map: Parameter "range1" must be an array of two finite numbers [min, max] with min < max.');if("number"!=typeof r[0]||"number"!=typeof r[1]||!Number.isFinite(r[0])||!Number.isFinite(r[1])||r[0]>r[1])throw new Error('Chalkboard.numb.map: Parameter "range2" must be an array of two finite numbers [min, max] with min <= max.');return r[0]+(r[1]-r[0])*((e-t[0])/(t[1]-t[0]))},t.mod=(e,t)=>{if("number"!=typeof e||"number"!=typeof t||!Number.isFinite(e)||!Number.isFinite(t))throw new Error('Chalkboard.numb.mod: Parameters "a" and "b" must be finite numbers.');if(0===t)throw new Error('Chalkboard.numb.mod: Parameter "b" must be non-zero.');return(e%t+t)%t},t.mul=(e,t,r)=>{if("function"!=typeof e)throw new Error('Chalkboard.numb.mul: Parameter "formula" must be a function.');if(!Number.isInteger(t)||!Number.isInteger(r))throw new Error('Chalkboard.numb.mul: Parameters "inf" and "sup" must be integers.');if(t>r)throw new Error('Chalkboard.numb.mul: Parameter "inf" must be less than or equal to "sup".');let n=1;for(let o=t;o<=r;o++)n*=e(o);return n},t.nextPrime=t=>{if(!Number.isFinite(t))throw new Error('Chalkboard.numb.nextPrime: Parameter "num" must be finite.');let r=Math.floor(t)+1;if(r<=2)return 2;for(r%2==0&&r++;!e.numb.isPrime(r);)r+=2;return r},t.permutation=(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t)||e<0||t<0||t>e)throw new Error('Chalkboard.numb.permutation: Parameters "n" and "r" must be integers with 0 <= r <= n.');let r=1;for(let n=e;n>e-t;n--)r*=n;return Math.round(r)},t.Poissonian=(t=1)=>{if("number"!=typeof t||!Number.isFinite(t))throw new Error('Chalkboard.numb.Poissonian: Parameter "l" must be a finite number.');if(t<=0)throw new Error('Chalkboard.numb.Poissonian: Parameter "l" must be positive.');const r=e.E(-t);let n=1,o=0;for(;n>r;++o)n*=Math.random();return o-1},t.prime=t=>{if(!Number.isInteger(t)||t<1)throw new Error('Chalkboard.numb.prime: Parameter "num" must be a positive integer.');if(1===t)return 2;let r=1,n=3;for(;;){if(e.numb.isPrime(n)&&(r++,r===t))return n;n+=2}},t.primeArr=(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t))throw new Error('Chalkboard.numb.primeArr: Parameters "inf" and "sup" must be integers.');if(e>t)throw new Error('Chalkboard.numb.primeArr: Parameter "inf" must be less than or equal to "sup".');if(t<2)return[];const r=new Uint8Array(t+1);r[0]=1,r[1]=1;for(let e=2;e*e<=t;e++)if(0===r[e])for(let n=e*e;n<=t;n+=e)r[n]=1;const n=[];for(let o=Math.max(2,e);o<=t;o++)0===r[o]&&n.push(o);return n},t.primeCount=(t,r)=>{if(!Number.isInteger(t)||!Number.isInteger(r))throw new Error('Chalkboard.numb.primeCount: Parameters "inf" and "sup" must be integers.');if(t>r)throw new Error('Chalkboard.numb.primeCount: Parameter "inf" must be less than or equal to "sup".');return e.numb.primeArr(t,r).length},t.primeGap=(t,r)=>{if(!Number.isInteger(t)||!Number.isInteger(r))throw new Error('Chalkboard.numb.primeGap: Parameters "inf" and "sup" must be integers.');if(t>r)throw new Error('Chalkboard.numb.primeGap: Parameter "inf" must be less than or equal to "sup".');let n=null,o=0;for(let i=t;i<=r;i++)if(e.numb.isPrime(i)){if(null!==n){const e=i-n;e>o&&(o=e)}n=i}return o},t.random=(e=0,t=1)=>{if("number"!=typeof e||"number"!=typeof t||!Number.isFinite(e)||!Number.isFinite(t))throw new Error('Chalkboard.numb.random: Parameters "inf" and "sup" must be finite numbers.');if(e>t)throw new Error('Chalkboard.numb.random: Parameter "inf" must be less than or equal to "sup".');return e+(t-e)*Math.random()},t.roundTo=(e,t)=>{if(!Number.isFinite(e)||!Number.isFinite(t))throw new Error("Chalkboard.numb.roundTo: Parameters must be finite numbers.");if(0===t)throw new Error('Chalkboard.numb.roundTo: Parameter "positionalIndex" must be non-zero.');return Math.round(e/t)*t},t.sgn=e=>{if(!Number.isNaN(e)){if(!Number.isFinite(e))throw new Error('Chalkboard.numb.sgn: Parameter "num" must be a finite number.');return e>0?1:e<0?-1:0}},t.sum=(e,t,r)=>{if("function"!=typeof e)throw new Error('Chalkboard.numb.sum: Parameter "formula" must be a function.');if(!Number.isInteger(t)||!Number.isInteger(r))throw new Error('Chalkboard.numb.sum: Parameters "inf" and "sup" must be integers.');if(t>r)throw new Error('Chalkboard.numb.sum: Parameter "inf" must be less than or equal to "sup".');let n=0;for(let o=t;o<=r;o++)n+=e(o);return n},t.toBinary=(e,t=!1)=>{if(!Number.isInteger(e))throw new Error('Chalkboard.numb.toBinary: Parameter "num" must be an integer.');return(e<0?"-":"")+(t?"0b":"")+Math.abs(e).toString(2)},t.toDecimal=(e,t)=>{if("string"!=typeof e)throw new Error('Chalkboard.numb.toDecimal: Parameter "num" must be a string.');if(!Number.isInteger(t)||t<2||t>36)throw new Error('Chalkboard.numb.toDecimal: Parameter "base" must be an integer between 2 and 36.');const r=(e=e.toLowerCase().trim()).startsWith("-");if(r&&(e=e.substring(1)),2===t&&e.startsWith("0b")&&(e=e.substring(2)),8===t&&e.startsWith("0o")&&(e=e.substring(2)),16===t&&e.startsWith("0x")&&(e=e.substring(2)),0===e.length)throw new Error('Chalkboard.numb.toDecimal: Parameter "num" must contain digits.');const n="0123456789abcdefghijklmnopqrstuvwxyz".substring(0,t);for(const r of e)if(!n.includes(r))throw new Error(`Chalkboard.numb.toDecimal: Invalid character "${r}" for base ${t}.`);const o=parseInt(e,t);if(!Number.isFinite(o))throw new Error('Chalkboard.numb.toDecimal: Failed to parse "num".');return r?-o:o},t.toFraction=(t,r=1e-8)=>{if("number"!=typeof t||"number"!=typeof r)throw new Error('Chalkboard.numb.toFraction: Parameters "num" and "tolerance" must be numbers.');if(!Number.isFinite(t))throw new Error('Chalkboard.numb.toFraction: The parameter "num" must be finite to be converted to a fraction.');if(!Number.isFinite(r)||r<=0)throw new Error('Chalkboard.numb.toFraction: The parameter "tolerance" must be a positive finite number.');const n=e.numb.sgn(t);if(void 0===n)throw new Error('Chalkboard.numb.toFraction: The parameter "num" must be a valid number to be converted to a fraction.');const o=Math.abs(t);if(Number.isInteger(o))return[n*o,1];let i=1,a=0,s=0,l=1,u=o;for(let t=0;t<1e4;t++){const t=Math.floor(u),m=t*i+a,f=t*s+l;if(0===f)break;const c=m/f;if(Math.abs(o-c)<r){const t=e.numb.gcd(m,f);return[n*(m/t),f/t]}a=i,i=m,l=s,s=f;const p=u-t;if(Math.abs(p)<=Number.EPSILON){const t=e.numb.gcd(m,f);return[n*(m/t),f/t]}if(u=1/p,!Number.isFinite(u)){const t=e.numb.gcd(m,f);return[n*(m/t),f/t]}}throw new Error("Chalkboard.numb.toFraction: Failed to converge to a fraction within the iteration limit.")},t.toHexadecimal=(e,t=!1,r=!1)=>{if(!Number.isInteger(e))throw new Error('Chalkboard.numb.toHexadecimal: The parameter "num" must be an integer.');const n=e<0?"-":"";let o=Math.abs(e).toString(16);return r&&(o=o.toUpperCase()),n+(t?"0x":"")+o},t.toOctal=(e,t=!1)=>{if(!Number.isInteger(e))throw new Error('Chalkboard.numb.toOctal: The parameter "num" must be an integer.');return(e<0?"-":"")+(t?"0o":"")+Math.abs(e).toString(8)}}(t=e.numb||(e.numb={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){const r=()=>{try{return Function('"use strict"; return ('+e.CONTEXT+")")()}catch(e){throw new Error("Cannot initialize canvas context. Make sure an HTML <canvas> element exists in the webpage before using Chalkboard.plot functions.")}},n=(e,t)=>{const n=e?.context??t?.context??r(),o=e??{},i={x:n.canvas.width/2,y:n.canvas.height/2,size:1,strokeStyle:"black",lineWidth:2,context:n,...t??{}},a={},s=new Set([...Object.keys(i),...Object.keys(o)]);for(const e of s)a[e]=o[e]??i[e];return a.context=n,a.x=a.x??n.canvas.width/2,a.y=a.y??n.canvas.height/2,a.size=(a.size??1)/100,a};t.autocorrelation=(t,r)=>{const o=n(r,{domain:[-10,10],res:25}),i=[];o.context.save(),o.context.translate(o.x,o.y),o.context.lineWidth=o.lineWidth,o.context.strokeStyle=o.strokeStyle,o.context.beginPath();const a=o.context.canvas.height/o.size*1.5;let s=null;for(let r=o.domain[0]/o.size;r<=o.domain[1]/o.size;r+=o.res){const n=-e.calc.autocorrelation(t,r*o.size)/o.size;null===s||Math.abs(n-s)>a?o.context.moveTo(r,n):o.context.lineTo(r,n),s=n,i.push([r,e.calc.autocorrelation(t,r)])}return o.context.stroke(),o.context.restore(),i},t.barplot=(t,r,o)=>{const i=n(o,{fillStyle:"white"});i.context.save(),i.context.translate(i.x,i.y),i.context.lineWidth=i.lineWidth,i.context.strokeStyle=i.strokeStyle,i.context.fillStyle=i.fillStyle;const a=[];for(let n=1;n<r.length;n++)a.push(e.stat.ineq(t,r[n-1],r[n],1===n,!0));const s=[];for(let e=0;e<a.length;e++)s.push(a[e].length);for(let e=0;e<s.length;e++){const t=r[e]/i.size,n=r[e+1]/i.size-t;i.context.fillRect(t,0,n,-s[e]/i.size),i.context.strokeRect(t,0,n,-s[e]/i.size)}return i.context.restore(),a},t.comp=(t,r)=>{const o=n(r,{fillStyle:"black",lineWidth:5});return o.context.fillStyle=o.fillStyle,o.context.save(),o.context.translate(o.x,o.y),o.context.beginPath(),o.context.ellipse(t.a/o.size,-t.b/o.size,o.lineWidth,o.lineWidth,0,0,e.PI(2)),o.context.fill(),o.context.restore(),[[t.a],[t.b]]},t.convolution=(t,r,o)=>{const i=n(o,{domain:[-10,10],res:25}),a=[];i.context.save(),i.context.translate(i.x,i.y),i.context.lineWidth=i.lineWidth,i.context.strokeStyle=i.strokeStyle,i.context.beginPath();const s=i.context.canvas.height/i.size*1.5;let l=null;for(let n=i.domain[0]/i.size;n<=i.domain[1]/i.size;n+=i.res){const o=-e.calc.convolution(t,r,n*i.size)/i.size;null===l||Math.abs(o-l)>s?i.context.moveTo(n,o):i.context.lineTo(n,o),l=o,a.push([n,e.calc.convolution(t,r,n)])}return i.context.stroke(),i.context.restore(),a},t.correlation=(t,r,o)=>{const i=n(o,{domain:[-10,10],res:25}),a=[];i.context.save(),i.context.translate(i.x,i.y),i.context.lineWidth=i.lineWidth,i.context.strokeStyle=i.strokeStyle,i.context.beginPath();const s=i.context.canvas.height/i.size*1.5;let l=null;for(let n=i.domain[0]/i.size;n<=i.domain[1]/i.size;n+=i.res){const o=-e.calc.correlation(t,r,n*i.size)/i.size;null===l||Math.abs(o-l)>s?i.context.moveTo(n,o):i.context.lineTo(n,o),l=o,a.push([n,e.calc.correlation(t,r,n)])}return i.context.stroke(),i.context.restore(),a},t.definition=(t,r)=>{const o=n(r,{domain:"comp"===t.field?[[-10,10],[-10,10]]:[-10,10],res:"comp"===t.field?5:1,isInverse:!1,isPolar:!1}),i=o.domain,a=o.domain,s=[];o.context.save(),o.context.translate(o.x,o.y),o.context.lineWidth=o.lineWidth,o.context.strokeStyle=o.strokeStyle,o.context.beginPath();const l=o.context.canvas.height/o.size*1.5;let u=null,m=null;if("scalar2d"!==t.type||o.isInverse||o.isPolar)if("scalar2d"===t.type&&o.isInverse&&!o.isPolar){const e=t.rule;for(let t=i[0]/o.size;t<=i[1]/o.size;t+=o.res){const r=e(t*o.size)/o.size,n=-t;null===m||Math.abs(r-m)>l?o.context.moveTo(r,n):o.context.lineTo(r,n),m=r,s.push([e(t),t])}}else if("scalar2d"===t.type&&!o.isInverse&&o.isPolar){const r=t.rule;for(let t=i[0]/o.size;t<=i[1]/o.size;t+=o.res){const n=r(t*o.size)/o.size*e.trig.cos(t*o.size),i=-r(t*o.size)/o.size*e.trig.sin(t*o.size);null===u||Math.abs(i-u)>l?o.context.moveTo(n,i):o.context.lineTo(n,i),u=i,s.push([t,r(t)])}}else if("curve2d"===t.type){const e=t.rule;for(let t=i[0]/o.size;t<=i[1]/o.size;t+=o.res){const r=e[0](t*o.size)/o.size,n=-e[1](t*o.size)/o.size;null===u||Math.abs(n-u)>l?o.context.moveTo(r,n):o.context.lineTo(r,n),u=n,s.push([e[0](t),e[1](t)])}}else{if("comp"!==t.field)throw new TypeError('Parameter "func" must be of type "ChalkboardFunction" with a property "type" of "expl", "inve", "pola", "curv", or "comp".');{const r=t.rule;for(let t=a[0][0]/o.size;t<=a[0][1]/o.size;t+=o.res)for(let n=a[1][0]/o.size;n<=a[1][1]/o.size;n+=o.res){const i=e.comp.init(r[0](t*o.size,n*o.size)/o.size,r[1](t*o.size,n*o.size)/o.size);0===i.a&&0===i.b?o.context.fillStyle="rgb(0, 0, 0)":i.a===1/0&&i.b===1/0?o.context.fillStyle="rgb(255, 255, 255)":o.context.fillStyle="hsl("+e.trig.toDeg(e.comp.arg(i))+", 100%, "+100*(e.trig.tanh(e.comp.mag(i)/e.real.pow(10,20))+.5)+"%)",o.context.fillRect(t,n,5,5),s.push([r[0](t,n),r[1](t,n)])}}}else{const e=t.rule;for(let t=i[0]/o.size;t<=i[1]/o.size;t+=o.res){const r=-e(t*o.size)/o.size;null===u||Math.abs(r-u)>l?o.context.moveTo(t,r):o.context.lineTo(t,r),u=r,s.push([t,e(t)])}}return o.context.stroke(),o.context.restore(),s},t.dfdx=(t,r)=>{const o=n(r,{domain:[-10,10],res:25,isInverse:!1}),i=[];o.context.save(),o.context.translate(o.x,o.y),o.context.lineWidth=o.lineWidth,o.context.strokeStyle=o.strokeStyle,o.context.beginPath();const a=o.context.canvas.height/o.size*1.5;let s=null,l=null;for(let r=o.domain[0]/o.size;r<=o.domain[1]/o.size;r+=o.res)if("scalar2d"!==t.type||o.isInverse){if("scalar2d"===t.type&&o.isInverse){const n=e.calc.dfdx(t,r*o.size)/o.size,s=-r;null===l||Math.abs(n-l)>a?o.context.moveTo(n,s):o.context.lineTo(n,s),l=n,i.push([e.calc.dfdx(t,r),r])}}else{const n=-e.calc.dfdx(t,r*o.size)/o.size;null===s||Math.abs(n-s)>a?o.context.moveTo(r,n):o.context.lineTo(r,n),s=n,i.push([r,e.calc.dfdx(t,r)])}return o.context.stroke(),o.context.restore(),i},t.d2fdx2=(t,r)=>{const o=n(r,{domain:[-10,10],res:25,isInverse:!1}),i=[];o.context.save(),o.context.translate(o.x,o.y),o.context.lineWidth=o.lineWidth,o.context.strokeStyle=o.strokeStyle,o.context.beginPath();const a=o.context.canvas.height/o.size*1.5;let s=null,l=null;for(let r=o.domain[0]/o.size;r<=o.domain[1]/o.size;r+=o.res)if("scalar2d"!==t.type||o.isInverse){if("scalar2d"===t.type&&o.isInverse){const n=e.calc.d2fdx2(t,r*o.size)/o.size,s=-r;null===l||Math.abs(n-l)>a?o.context.moveTo(n,s):o.context.lineTo(n,s),l=n,i.push([e.calc.d2fdx2(t,r),r])}}else{const n=-e.calc.d2fdx2(t,r*o.size)/o.size;null===s||Math.abs(n-s)>a?o.context.moveTo(r,n):o.context.lineTo(r,n),s=n,i.push([r,e.calc.d2fdx2(t,r)])}return o.context.stroke(),o.context.restore(),i},t.field=(t,r)=>{const o=n(r,{domain:[[-10,10],[-10,10]],res:25}),i=[];o.context.strokeStyle=o.strokeStyle,o.context.lineWidth=o.lineWidth,o.context.save(),o.context.translate(o.x,o.y);for(let r=o.domain[0][0]/o.size;r<=o.domain[0][1]/o.size;r+=o.res)for(let n=o.domain[1][0]/o.size;n<=o.domain[1][1]/o.size;n+=o.res){const a=e.vect.fromField(t,e.vect.init(r,n));o.context.beginPath(),o.context.moveTo(r,n),o.context.lineTo(r+a.x,n+a.y),o.context.stroke(),i.push([r+a.x,n+a.y])}return o.context.restore(),i},t.Fourier=(t,r)=>{const o=n(r,{domain:[-10,10],res:25}),i=[];o.context.save(),o.context.translate(o.x,o.y),o.context.lineWidth=o.lineWidth,o.context.strokeStyle=o.strokeStyle,o.context.beginPath();const a=o.context.canvas.height/o.size*1.5;let s=null;for(let r=o.domain[0]/o.size;r<=o.domain[1]/o.size;r+=o.res){const n=-e.calc.Fourier(t,r*o.size)/o.size;null===s||Math.abs(n-s)>a?o.context.moveTo(r,n):o.context.lineTo(r,n),s=n,i.push([r,e.calc.Fourier(t,r)])}return o.context.stroke(),o.context.restore(),i},t.fxdx=(t,r)=>{const o=n(r,{domain:[-10,10],res:25,isInverse:!1}),i=[];o.context.save(),o.context.translate(o.x,o.y),o.context.lineWidth=o.lineWidth,o.context.strokeStyle=o.strokeStyle,o.context.beginPath();const a=o.context.canvas.height/o.size*1.5;let s=null,l=null;for(let r=o.domain[0]/o.size;r<=o.domain[1]/o.size;r+=o.res)if("scalar2d"!==t.type||o.isInverse){if("scalar2d"===t.type&&o.isInverse){const n=e.calc.fxdx(t,0,r*o.size)/o.size,s=-r;null===l||Math.abs(n-l)>a?o.context.moveTo(n,s):o.context.lineTo(n,s),l=n,i.push([e.calc.fxdx(t,0,r),r])}}else{const n=-e.calc.fxdx(t,0,r*o.size)/o.size;null===s||Math.abs(n-s)>a?o.context.moveTo(r,n):o.context.lineTo(r,n),s=n,i.push([r,e.calc.fxdx(t,0,r)])}return o.context.stroke(),o.context.restore(),i},t.Laplace=(t,r)=>{const o=n(r,{domain:[-10,10],res:25}),i=[];o.context.save(),o.context.translate(o.x,o.y),o.context.lineWidth=o.lineWidth,o.context.strokeStyle=o.strokeStyle,o.context.beginPath();const a=o.context.canvas.height/o.size*1.5;let s=null;if(o.domain[0]>=0)for(let r=o.domain[0]/o.size;r<=o.domain[1]/o.size;r+=o.res){const n=-e.calc.Laplace(t,r*o.size)/o.size;null===s||Math.abs(n-s)>a?o.context.moveTo(r,n):o.context.lineTo(r,n),s=n,i.push([r,e.calc.Laplace(t,r)])}else for(let r=0;r<=o.domain[1]/o.size;r+=o.res){const n=-e.calc.Laplace(t,r*o.size)/o.size;null===s||Math.abs(n-s)>a?o.context.moveTo(r,n):o.context.lineTo(r,n),s=n,i.push([r,e.calc.Laplace(t,r)])}return o.context.stroke(),o.context.restore(),i},t.lineplot=(t,r,o)=>{const i=n(o);i.context.save(),i.context.translate(i.x,i.y),i.context.lineWidth=i.lineWidth,i.context.strokeStyle=i.strokeStyle;const a=[];for(let n=1;n<r.length;n++)a.push(e.stat.ineq(t,r[n-1],r[n],1===n,!0));const s=[];for(let e=0;e<a.length;e++)s.push(a[e].length);i.context.beginPath(),i.context.moveTo(r[0]/i.size,0);for(let e=0;e<s.length;e++){const t=(r[e]+r[e+1])/2/i.size;i.context.lineTo(t,-s[e]/i.size)}return i.context.lineTo(r[r.length-1]/i.size,0),i.context.stroke(),i.context.restore(),a},t.matr=(t,r)=>{const o=n(r,{domain:[-10,10]});for(let r=o.domain[0];r<=o.domain[1];r++)e.plot.vect(e.vect.init(t[0][0],t[1][0]),{x:o.x,y:o.y+r/o.size*t[1][1],size:o.size,strokeStyle:o.strokeStyle,lineWidth:o.lineWidth/4,context:o.context}),e.plot.vect(e.vect.init(-t[0][0],-t[1][0]),{x:o.x,y:o.y+r/o.size*t[1][1],size:o.size,strokeStyle:o.strokeStyle,lineWidth:o.lineWidth/4,context:o.context}),e.plot.vect(e.vect.init(t[0][1],t[1][1]),{x:o.x+r/o.size*t[0][0],y:o.y,size:o.size,strokeStyle:o.strokeStyle,lineWidth:o.lineWidth/4,context:o.context}),e.plot.vect(e.vect.init(-t[0][1],-t[1][1]),{x:o.x+r/o.size*t[0][0],y:o.y,size:o.size,strokeStyle:o.strokeStyle,lineWidth:o.lineWidth/4,context:o.context});return e.plot.vect(e.vect.init(t[0][0],t[1][0]),o),e.plot.vect(e.vect.init(-t[0][0],-t[1][0]),o),e.plot.vect(e.vect.init(t[0][1],t[1][1]),o),e.plot.vect(e.vect.init(-t[0][1],-t[1][1]),o),t},t.ode=(e,t={})=>{const r=n(t,{phase:!1,i:0,j:1});if(!e||!Array.isArray(e.t)||!Array.isArray(e.y))throw new Error('Chalkboard.plot.ode: Parameter "sol" must have properties "t" and "y" as arrays.');if(e.t.length!==e.y.length||0===e.t.length)throw new Error("Chalkboard.plot.ode: Invalid solution object (length mismatch or empty).");const o=e.y[0].length;if(!Number.isInteger(r.i)||r.i<0)throw new Error('Chalkboard.plot.ode: "i" must be an integer >= 0.');if(r.i>=o)throw new Error('Chalkboard.plot.ode: "i" is out of range for solution dimension.');if(r.phase){if(!Number.isInteger(r.j)||r.j<0)throw new Error('Chalkboard.plot.ode: "j" must be an integer >= 0.');if(r.j>=o)throw new Error('Chalkboard.plot.ode: "j" is out of range for solution dimension.');if(r.i===r.j)throw new Error('Chalkboard.plot.ode: For phase plots, "i" and "j" must be different.')}const i=[];if(r.context.save(),r.context.translate(r.x,r.y),r.context.lineWidth=r.lineWidth,r.context.strokeStyle=r.strokeStyle,r.context.beginPath(),r.phase)for(let t=0;t<e.y.length;t++){const n=e.y[t][r.i]/r.size,o=-e.y[t][r.j]/r.size;0===t?r.context.moveTo(n,o):r.context.lineTo(n,o),i.push([e.y[t][r.i],e.y[t][r.j]])}else for(let t=0;t<e.t.length;t++){const n=e.t[t]/r.size,o=-e.y[t][r.i]/r.size;0===t?r.context.moveTo(n,o):r.context.lineTo(n,o),i.push([e.t[t],e.y[t][r.i]])}return r.context.stroke(),r.context.restore(),i},t.rOplane=t=>{const o=n(t),i=r().canvas.width;o.context.save(),o.context.translate(o.x,o.y),o.context.strokeStyle=o.strokeStyle,o.context.lineWidth=o.lineWidth/4,o.context.beginPath();for(let t=0;t<=o.size*i/2;t++)o.context.ellipse(0,0,t/o.size,t/o.size,0,0,e.PI(2));o.context.stroke(),o.context.lineWidth=o.lineWidth,o.context.beginPath(),o.context.moveTo(-o.x,0),o.context.lineTo(i-o.x,0),o.context.stroke(),o.context.beginPath(),o.context.moveTo(0,-o.y),o.context.lineTo(0,i-o.y),o.context.stroke(),o.context.restore()},t.scatterplot=(t,r,o)=>{const i=n(o,{fillStyle:"black",lineWidth:5}),a=[];if(i.context.save(),i.context.translate(i.x,i.y),i.context.fillStyle=i.fillStyle,t.length===r.length)for(let n=0;n<t.length;n++)i.context.beginPath(),i.context.ellipse(t[n]/i.size,-r[n]/i.size,i.lineWidth,i.lineWidth,0,0,e.PI(2)),i.context.fill(),a.push([t[n],r[n]]);return i.context.restore(),a},t.Taylor=(t,r,o,i)=>{const a=n(i,{domain:[-10,10],res:25}),s=[];a.context.save(),a.context.translate(a.x,a.y),a.context.lineWidth=a.lineWidth,a.context.strokeStyle=a.strokeStyle,a.context.beginPath();const l=a.context.canvas.height/a.size*1.5;let u=null;for(let n=a.domain[0]/a.size;n<=a.domain[1]/a.size;n+=a.res){const i=-e.calc.Taylor(t,n*a.size,r,o)/a.size;null===u||Math.abs(i-u)>l?a.context.moveTo(n,i):a.context.lineTo(n,i),u=i,s.push([n,e.calc.Taylor(t,n,r,o)])}return a.context.stroke(),a.context.restore(),s},t.vect=(e,t)=>{const r=n(t,{lineWidth:5});return r.context.strokeStyle=r.strokeStyle,r.context.lineWidth=r.lineWidth,r.context.save(),r.context.translate(r.x,r.y),r.context.beginPath(),r.context.moveTo(0,0),r.context.lineTo(e.x/r.size,-e.y/r.size),r.context.stroke(),r.context.restore(),[[e.x],[e.y]]},t.xyplane=e=>{const t=n(e),o=r().canvas.width;t.context.save(),t.context.translate(t.x,t.y),t.context.strokeStyle=t.strokeStyle,t.context.lineWidth=t.lineWidth/4,t.context.beginPath();for(let e=Math.floor(-t.x/t.size);e<=(o-t.x)/t.size;e++)t.context.moveTo(e/t.size,-t.y),t.context.lineTo(e/t.size,o-t.y);t.context.stroke(),t.context.beginPath();for(let e=Math.floor(-t.y/t.size);e<=(o-t.y)/t.size;e++)t.context.moveTo(-t.x,e/t.size),t.context.lineTo(o-t.x,e/t.size);t.context.stroke(),t.context.lineWidth=t.lineWidth,t.context.beginPath(),t.context.moveTo(-t.x,0),t.context.lineTo(o-t.x,0),t.context.stroke(),t.context.beginPath(),t.context.moveTo(0,-t.y),t.context.lineTo(0,o-t.y),t.context.stroke(),t.context.restore()}}(t=e.plot||(e.plot={}))}(Chalkboard||(Chalkboard={})),function(e){let t;var r;(r=t=e.quat||(e.quat={})).absolute=t=>e.quat.init(Math.abs(t.a),Math.abs(t.b),Math.abs(t.c),Math.abs(t.d)),r.add=(t,r)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),e.quat.init(t.a+r.a,t.b+r.b,t.c+r.c,t.d+r.d)),r.conjugate=t=>e.quat.init(t.a,-t.b,-t.c,-t.d),r.constrain=(t,r=[0,1])=>e.quat.init(e.numb.constrain(t.a,r),e.numb.constrain(t.b,r),e.numb.constrain(t.c,r),e.numb.constrain(t.d,r)),r.copy=e=>Object.create(Object.getPrototypeOf(e),Object.getOwnPropertyDescriptors(e)),r.dist=(t,r)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),e.real.sqrt((r.a-t.a)*(r.a-t.a)+(r.b-t.b)*(r.b-t.b)+(r.c-t.c)*(r.c-t.c)+(r.d-t.d)*(r.d-t.d))),r.distsq=(t,r)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),(r.a-t.a)*(r.a-t.a)+(r.b-t.b)*(r.b-t.b)+(r.c-t.c)*(r.c-t.c)+(r.d-t.d)*(r.d-t.d)),r.div=(t,r)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),e.quat.init((t.a*r.a+t.b*r.b+t.c*r.c+t.d*r.d)/e.quat.magsq(r),(t.b*r.a-t.a*r.b-t.d*r.c+t.c*r.d)/e.quat.magsq(r),(t.c*r.a+t.d*r.b-t.a*r.c-t.b*r.d)/e.quat.magsq(r),(t.d*r.a-t.c*r.b+t.b*r.c-t.a*r.d)/e.quat.magsq(r))),r.fromAxis=(t,r)=>{if(void 0!==t.z)return e.quat.init(e.trig.cos(r/2),t.x*e.trig.sin(r/2),t.y*e.trig.sin(r/2),t.z*e.trig.sin(r/2));throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 3 dimensions.')},r.init=(e,t=0,r=0,n=0)=>({a:e,b:t,c:r,d:n}),r.invert=t=>e.quat.init(t.a/e.quat.magsq(t),-t.b/e.quat.magsq(t),-t.c/e.quat.magsq(t),-t.d/e.quat.magsq(t)),r.isApproxEqual=(t,r,n=1e-6)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),e.numb.isApproxEqual(t.a,r.a,n)&&e.numb.isApproxEqual(t.b,r.b,n)&&e.numb.isApproxEqual(t.c,r.c,n)&&e.numb.isApproxEqual(t.d,r.d,n)),r.isEqual=(t,r)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),t.a===r.a&&t.b===r.b&&t.c===r.c&&t.d===r.d),r.isInverse=(t,r,n=1e-6)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),e.quat.isApproxEqual(e.quat.mul(t,r),e.quat.init(1,0,0,0),n)),r.isNormalized=t=>e.numb.isApproxEqual(e.quat.magsq(t),1),r.isZero=t=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),e.quat.isApproxEqual(t,e.quat.init(0,0,0,0))),r.mag=t=>e.real.sqrt(t.a*t.a+t.b*t.b+t.c*t.c+t.d*t.d),r.magset=(t,r)=>e.quat.scl(e.quat.normalize(t),r),r.magsq=e=>e.a*e.a+e.b*e.b+e.c*e.c+e.d*e.d,r.mul=(t,r)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),e.quat.init(t.a*r.a-t.b*r.b-t.c*r.c-t.d*r.d,t.a*r.b+t.b*r.a+t.c*r.d-t.d*r.c,t.a*r.c-t.b*r.d+t.c*r.a+t.d*r.b,t.a*r.d+t.b*r.c-t.c*r.b+t.d*r.a)),r.negate=t=>e.quat.init(-t.a,-t.b,-t.c,-t.d),r.normalize=t=>e.quat.init(t.a/e.quat.mag(t),t.b/e.quat.mag(t),t.c/e.quat.mag(t),t.d/e.quat.mag(t)),r.print=t=>{console.log(e.quat.toString(t))},r.random=(t=0,r=1)=>e.quat.init(e.numb.random(t,r),e.numb.random(t,r),e.numb.random(t,r),e.numb.random(t,r)),r.reciprocate=t=>e.quat.init(1/t.a,1/t.b,1/t.c,1/t.d),r.round=t=>e.quat.init(Math.round(t.a),Math.round(t.b),Math.round(t.c),Math.round(t.d)),r.scl=(t,r)=>e.quat.init(t.a*r,t.b*r,t.c*r,t.d*r),r.sub=(t,r)=>("number"==typeof t&&(t=e.quat.init(t,0,0,0)),"number"==typeof r&&(r=e.quat.init(r,0,0,0)),e.quat.init(t.a-r.a,t.b-r.b,t.c-r.c,t.d-r.d)),r.toArray=e=>[e.a,e.b,e.c,e.d],r.toMatrix=t=>e.matr.init([t.a,-t.b,-t.c,-t.d],[t.b,t.a,-t.d,t.c],[t.c,t.d,t.a,-t.b],[t.d,-t.c,t.b,t.a]),r.toRotation=(t,r)=>{const n=e.vect.toQuaternion(r),o=e.quat.invert(t),i=e.quat.mul(t,e.quat.mul(n,o));return e.vect.init(i.b,i.c,i.d)},r.toString=e=>{let t=e.a.toString();return e.b>=0?t+=" + "+(1===e.b?"i":e.b.toString()+"i"):t+=" - "+(-1===e.b?"i":Math.abs(e.b).toString()+"i"),e.c>=0?t+=" + "+(1===e.c?"j":e.c.toString()+"j"):t+=" - "+(-1===e.c?"j":Math.abs(e.c).toString()+"j"),e.d>=0?t+=" + "+(1===e.d?"k":e.d.toString()+"k"):t+=" - "+(-1===e.d?"k":Math.abs(e.d).toString()+"k"),t},r.toTypedArray=(t,r="float32")=>{const n=e.quat.toArray(t);if("int8"===r)return new Int8Array(n);if("int16"===r)return new Int16Array(n);if("int32"===r)return new Int32Array(n);if("float32"===r)return new Float32Array(n);if("float64"===r)return new Float64Array(n);if("bigint64"===r)return new BigInt64Array(n.map(e=>BigInt(Math.floor(e))));throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".')},r.toVector=t=>e.vect.init(t.a,t.b,t.c,t.d)}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){t.absolute=t=>{if("real"!==t.field)throw new TypeError("Chalkboard.real.absolute: Property 'field' of 'func' must be 'real'.");if(t.type.startsWith("scalar")){const r=t.rule,n=(...e)=>Math.abs(r(...e));return e.real.define(n)}if(t.type.startsWith("vector")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push((...t)=>Math.abs(r[e](...t)));return e.real.define(n)}if(t.type.startsWith("curve")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push(t=>Math.abs(r[e](t)));return e.real.define(n)}if(t.type.startsWith("surface")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push((t,n)=>Math.abs(r[e](t,n)));return e.real.define(n)}throw new TypeError("Chalkboard.real.absolute: Property 'type' of 'func' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.add=(t,r)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.real.add: Properties 'field' of 'func1' and 'func2' must be 'real'.");if(t.type!==r.type)throw new TypeError("Chalkboard.real.add: Properties 'type' of 'func1' and 'func2' must be the same.");if(t.type.startsWith("scalar")){const n=t.rule,o=r.rule,i=(...e)=>n(...e)+o(...e);return e.real.define(i)}if(t.type.startsWith("vector")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((...t)=>n[e](...t)+o[e](...t));return e.real.define(i)}if(t.type.startsWith("curve")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push(t=>n[e](t)+o[e](t));return e.real.define(i)}if(t.type.startsWith("surface")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((t,r)=>n[e](t,r)+o[e](t,r));return e.real.define(i)}throw new TypeError("Chalkboard.real.add: Properties 'type' of 'func1' and 'func2' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.compose=(t,r)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.real.compose: Properties 'field' of 'func1' and 'func2' must be 'real'.");if(t.type!==r.type)throw new TypeError("Chalkboard.real.compose: Properties 'type' of 'func1' and 'func2' must be the same.");if(t.type.startsWith("scalar")){const n=t.rule,o=r.rule,i=(...e)=>n(o(...e));return e.real.define(i)}if(t.type.startsWith("vector")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((...t)=>n[e](o[e](...t)));return e.real.define(i)}throw new TypeError("Chalkboard.real.compose: Properties 'type' of 'func1' and 'func2' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', or 'vector4d'.")},t.define=(...e)=>{let t,r="scalar2d";if(t=1===e.length&&Array.isArray(e[0])?e[0]:e.length>1?e:e[0],Array.isArray(t)){if(2===t.length)if(1===t[0].length)r="curve2d";else{if(2!==t[0].length)throw new TypeError("Chalkboard.real.define: Functions in array 'rule' must have one variable to define a parametric curve or two variables to define a vector field.");r="vector2d"}else if(3===t.length)if(1===t[0].length)r="curve3d";else if(2===t[0].length)r="surface3d";else{if(3!==t[0].length)throw new TypeError("Chalkboard.real.define: Functions in array 'rule' must have one variable to define a parametric curve, two variables to define a parametric surface, or three variables to define a vector field.");r="vector3d"}else if(4===t.length)if(1===t[0].length)r="curve4d";else{if(4!==t[0].length)throw new TypeError("Chalkboard.real.define: Functions in array 'rule' must have one variable to define a parametric curve or four variables to define a vector field.");r="vector4d"}}else if(1===t.length)r="scalar2d";else if(2===t.length)r="scalar3d";else{if(3!==t.length)throw new TypeError("Chalkboard.real.define: Function 'rule' must have one, two, or three variables to define a scalar function.");r="scalar4d"}return{rule:t,field:"real",type:r}},t.Dirac=(e,t=0,r=1)=>e===t?r:0,t.discriminant=(e,t,r,n="standard")=>{if("standard"===n)return t*t-4*e*r;if("vertex"===n)return 2*e*t*(2*e*t)-4*e*r;throw new TypeError("Chalkboard.real.discriminant: String 'form' must be 'standard' or 'vertex'.")},t.div=(t,r)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.real.div: Properties 'field' of 'func1' and 'func2' must be 'real'.");if(t.type!==r.type)throw new TypeError("Chalkboard.real.div: Properties 'type' of 'func1' and 'func2' must be the same.");if(t.type.startsWith("scalar")){const n=t.rule,o=r.rule,i=(...e)=>n(...e)/o(...e);return e.real.define(i)}if(t.type.startsWith("vector")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((...t)=>n[e](...t)/o[e](...t));return e.real.define(i)}if(t.type.startsWith("curve")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push(t=>n[e](t)/o[e](t));return e.real.define(i)}if(t.type.startsWith("surface")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((t,r)=>n[e](t,r)/o[e](t,r));return e.real.define(i)}throw new TypeError("Chalkboard.real.div: Properties 'type' of 'func1' and 'func2' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.erf=t=>{if("number"!=typeof t||!Number.isFinite(t))throw new TypeError("Chalkboard.real.erf: Parameter 'num' must be a finite number.");const r=t<0?-1:1,n=Math.abs(t),o=1/(1+.3275911*n);return r*(1-((((1.061405429*o-1.453152027)*o+1.421413741)*o-.284496736)*o+.254829592)*o*e.E(-n*n))},t.Gamma=t=>{if("number"!=typeof t||!Number.isFinite(t))throw new TypeError("Chalkboard.real.Gamma: Parameter 'num' must be a finite number.");if(Number.isInteger(t)&&t<=0)return NaN;if(t<.5)return e.PI()/(e.trig.sin(e.PI(t))*e.real.Gamma(1-t));let r=t-1,n=.9999999999998099;n+=676.5203681218851/(r+1),n+=-1259.1392167224028/(r+2),n+=771.3234287776531/(r+3),n+=-176.6150291621406/(r+4),n+=12.507343278686905/(r+5),n+=-.13857109526572012/(r+6),n+=9984369578019572e-21/(r+7),n+=1.5056327351493116e-7/(r+8);const o=r+7+.5;return e.real.sqrt(e.PI(2))*e.real.pow(o,r+.5)*e.E(-o)*n},t.Heaviside=(e,t=0,r=1)=>e>=t?r:0,t.lerp=(e,t)=>(e[1]-e[0])*t+e[0],t.linear=(t,r,n,o)=>e.real.define(i=>e.real.slope(t,r,n,o)*(i-n)+o),t.linearFormula=(t,r,n,o)=>void 0===n&&void 0===o?-r/t:"number"==typeof n&&void 0===o?n/t:-r/e.real.slope(t,r,n,o)+t,t.ln=e=>{if(e<=0)return NaN;if(1===e)return 0;if(e===1/0)return 1/0;let t=0,r=e;for(;r>1.414213562373095;)r*=.5,t++;for(;r<.7071067811865475;)r*=2,t--;const n=(r-1)/(r+1),o=n*n,i=o*n,a=i*o,s=a*o,l=s*o,u=l*o,m=u*o,f=m*o,c=f*o;return 2*(n+i/3+a/5+s/7+l/9+u/11+m/13+f/15+c/17+c*o/19)+.6931471805599453*t},t.log=(t,r)=>e.real.ln(r)/e.real.ln(t),t.log10=t=>e.real.log(10,t),t.mul=(t,r)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.real.mul: Properties 'field' of 'func1' and 'func2' must be 'real'.");if(t.type!==r.type)throw new TypeError("Chalkboard.real.mul: Properties 'type' of 'func1' and 'func2' must be the same.");if(t.type.startsWith("scalar")){const n=t.rule,o=r.rule,i=(...e)=>n(...e)*o(...e);return e.real.define(i)}if(t.type.startsWith("vector")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((...t)=>n[e](...t)*o[e](...t));return e.real.define(i)}if(t.type.startsWith("curve")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push(t=>n[e](t)*o[e](t));return e.real.define(i)}if(t.type.startsWith("surface")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((t,r)=>n[e](t,r)*o[e](t,r));return e.real.define(i)}throw new TypeError("Chalkboard.real.mul: Properties 'type' of 'func1' and 'func2' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.negate=t=>{if("real"!==t.field)throw new TypeError("Chalkboard.real.negate: Property 'field' of 'func' must be 'real'.");if(t.type.startsWith("scalar")){const r=t.rule,n=(...e)=>-r(...e);return e.real.define(n)}if(t.type.startsWith("vector")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push((...t)=>-r[e](...t));return e.real.define(n)}if(t.type.startsWith("curve")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push(t=>-r[e](t));return e.real.define(n)}if(t.type.startsWith("surface")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push((t,n)=>-r[e](t,n));return e.real.define(n)}throw new TypeError("Chalkboard.real.negate: Property 'type' of 'func' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.parse=(t,r={returnAST:!1,returnJSON:!1,returnLaTeX:!1})=>{if(""===t)return"";const n=t=>{const r=[];let n=0;const o=["sin","cos","tan","abs","sqrt","log","ln","exp","min","max"],i=t=>o.includes(t)||void 0!==e.REGISTRY[t];for(;n<t.length;){const e=t[n];if(/\s/.test(e))n++;else if(-1!=="+-*/(),^".indexOf(e))r.push(e),n++,")"===e&&n<t.length&&/[a-zA-Z0-9_(]/.test(t[n])&&"*"!==r[r.length-1]&&r.push("*");else if(/[0-9]/.test(e)||"."===e&&/[0-9]/.test(t[n+1])){let e="",o=!1;for(;n<t.length&&(/[0-9]/.test(t[n])||"."===t[n]&&!o);)"."===t[n]&&(o=!0),e+=t[n++];r.push(e),n<t.length&&/[a-zA-Z_(]/.test(t[n])&&"*"!==r[r.length-1]&&r.push("*")}else{if(!/[a-zA-Z_]/.test(e))throw new Error(`Chalkboard.real.parse: Unexpected character ${e}`);{let e="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)e+=t[n++];if(/^[a-zA-Z]+$/.test(e)&&e.length>1&&!i(e))for(let t=0;t<e.length;t++)r.push(e[t]),t<e.length-1&&r.push("*");else r.push(e);n<t.length&&"("===t[n]?i(e)||"*"!==r[r.length-1]&&r.push("*"):n<t.length&&/[a-zA-Z_]/.test(t[n])&&"*"!==r[r.length-1]&&r.push("*")}}}return r},o=e=>{let t=0;const r=()=>e[t]||"",n=r=>{if(r&&e[t]!==r)throw new Error(`Chalkboard.real.parse: Expected token '${r}' but found '${e[t]}'`);return e[t++]},o=()=>i(),i=()=>{let e=a();for(;"+"===r()||"-"===r();){e={type:"+"===n()?"add":"sub",left:e,right:a()}}return e},a=()=>{let e=s();for(;"*"===r()||"/"===r();){e={type:"*"===n()?"mul":"div",left:e,right:s()}}return e},s=()=>"-"===r()?(n("-"),{type:"neg",expr:l()}):"+"===r()?(n("+"),l()):l(),l=()=>{let e=m();if("^"===r()){n("^");e={type:"pow",base:e,exponent:u()}}return e},u=()=>"-"===r()?(n("-"),{type:"neg",expr:u()}):"+"===r()?(n("+"),u()):l(),m=()=>{const e=r();if(/^-?[0-9]/.test(e)||/^-?\.[0-9]/.test(e))return n(),{type:"num",value:parseFloat(e)};if(/^[a-zA-Z_]/.test(e)){const e=n();if("("===r()){n("(");const t=[];if(")"!==r())for(t.push(o());","===r();)n(","),t.push(o());return n(")"),{type:"func",name:e,args:t}}return{type:"var",name:e}}if("("===e){n("(");const e=o();return n(")"),e}throw new Error(`Chalkboard.real.parse: Unexpected token ${e}`)},f=o();if(t<e.length)throw new Error(`Chalkboard.real.parse: Unexpected token ${e[t]}`);return f},i=(t,r)=>{switch(t.type){case"num":return t.value;case"var":{const e=t.name;if(e in r)return r[e];throw new Error(`Chalkboard.real.parse: Variable '${e}' not defined in values`)}case"add":return i(t.left,r)+i(t.right,r);case"sub":return i(t.left,r)-i(t.right,r);case"mul":return i(t.left,r)*i(t.right,r);case"div":{const e=i(t.left,r),n=i(t.right,r);if(0===n)throw new Error("Chalkboard.real.parse: Division by zero");return e/n}case"pow":return Math.pow(i(t.base,r),i(t.exponent,r));case"neg":return-i(t.expr,r);case"func":{const n=t.name.toLowerCase(),o=t.args.map(e=>i(e,r));if(void 0!==e.REGISTRY[n])return e.REGISTRY[n](...o);switch(n){case"sin":return Math.sin(o[0]);case"cos":return Math.cos(o[0]);case"tan":return Math.tan(o[0]);case"abs":return Math.abs(o[0]);case"sqrt":return Math.sqrt(o[0]);case"log":return o.length>1?Math.log(o[0])/Math.log(o[1]):Math.log(o[0]);case"ln":return Math.log(o[0]);case"exp":return Math.exp(o[0]);case"min":return Math.min(...o);case"max":return Math.max(...o);default:throw new Error(`Chalkboard.real.parse: Unknown function ${t.name}`)}}}throw new Error(`Chalkboard.real.parse: Unknown node type ${t.type}`)},a=e=>{switch(e.type){case"num":return e.value.toString();case"var":return e.name;case"add":return"mul"===e.right.type&&"num"===e.right.left?.type&&-1===e.right.left.value&&"neg"===e.right.right?.type?`${a(e.left)} + ${a(e.right.right.expr)}`:"num"===e.right.type&&e.right.value<0?`${a(e.left)} - ${a({type:"num",value:-e.right.value})}`:"neg"===e.right.type?`${a(e.left)} - ${a(e.right.expr)}`:"mul"===e.right.type&&"num"===e.right.left.type&&e.right.left.value<0?`${a(e.left)} - ${a({type:"mul",left:{type:"num",value:-e.right.left.value},right:e.right.right})}`:"mul"===e.right.type&&"num"===e.right.right.type&&e.right.right.value<0?`${a(e.left)} - ${a({type:"mul",left:e.right.left,right:{type:"num",value:-e.right.right.value}})}`:a(e.right).startsWith("-")?`${a(e.left)} - ${a(e.right).slice(1)}`:`${a(e.left)} + ${a(e.right)}`;case"sub":{if("neg"===e.right.type)return`${a(e.left)} + ${a(e.right.expr)}`;if("mul"===e.right.type&&"num"===e.right.left?.type&&1===e.right.left.value&&"neg"===e.right.right?.type)return`${a(e.left)} + ${a(e.right.right.expr)}`;if("mul"===e.right.type&&"num"===e.right.left?.type&&-1===e.right.left.value)return`${a(e.left)} + ${a(e.right.right)}`;if("mul"===e.right.type&&"num"===e.right.left?.type&&1===e.right.left.value&&"mul"===e.right.right?.type&&"num"===e.right.right.left?.type&&-1===e.right.right.left.value)return`${a(e.left)} + ${a(e.right.right.right)}`;const t="add"===e.right.type||"sub"===e.right.type?`(${a(e.right)})`:a(e.right);return`${a(e.left)} - ${t}`}case"mul":return"num"===e.left.type&&1===e.left.value?a(e.right):"num"===e.right.type&&1===e.right.value?a(e.left):"num"===e.left.type&&-1===e.left.value&&"var"===e.right.type||"num"===e.left.type&&-1===e.left.value&&"pow"===e.right.type?`-${a(e.right)}`:"num"!==e.left.type||"var"!==e.right.type&&"pow"!==e.right.type?"pow"===e.left.type&&"pow"===e.right.type||"pow"===e.left.type&&"var"===e.right.type||"var"===e.left.type&&"pow"===e.right.type||"var"===e.left.type&&"var"===e.right.type?`${a(e.left)}${a(e.right)}`:`${a(e.left)} * ${a(e.right)}`:`${a(e.left)}${a(e.right)}`;case"div":{const t={type:"pow",base:e.right,exponent:{type:"num",value:-1}},r={type:"mul",left:e.left,right:t};return a(r)}case"pow":return`${"num"!==e.base.type&&"var"!==e.base.type?`(${a(e.base)})`:a(e.base)}^${"num"!==e.exponent.type&&"var"!==e.exponent.type?`(${a(e.exponent)})`:a(e.exponent)}`;case"neg":if("add"===e.expr.type||"sub"===e.expr.type)return`-(${a(e.expr)})`;if("pow"===e.expr.type)return`-${a(e.expr)}`;return`-${"num"!==e.expr.type&&"var"!==e.expr.type?`(${a(e.expr)})`:a(e.expr)}`;case"func":return`${e.name}(${e.args.map(e=>a(e)).join(", ")})`}return""},s=e=>{switch(e.type){case"num":return e.value.toString();case"var":return e.name;case"add":return s(e.right).startsWith("-")?`${s(e.left)} - ${s(e.right).slice(1)}`:`${s(e.left)} + ${s(e.right)}`;case"sub":{const t=s(e.right);return t.startsWith("-")?`${s(e.left)} + ${t.slice(1)}`:`${s(e.left)} - ${t}`}case"mul":{const t=e=>"num"===e.type||"var"===e.type||"pow"===e.type||"func"===e.type,r=e=>{const t=s(e);return"add"===e.type||"sub"===e.type?`\\left(${t}\\right)`:t},n=r(e.left),o=r(e.right);return t(e.left)&&t(e.right)?`${n}${o}`:`${n} \\cdot ${o}`}case"div":return`\\frac{${s(e.left)}}{${s(e.right)}}`;case"pow":return`${s(e.base)}^{${s(e.exponent)}}`;case"neg":return`-${s(e.expr)}`;case"func":return`\\mathrm{${e.name}}\\left(${e.args.map(s).join(", ")}\\right)`;default:throw new Error(`Chalkboard.real.parse: Unknown node type ${e.type}`)}},l=(e,t)=>"var"===e.type&&"var"===t.type?e.name===t.name:JSON.stringify(e)===JSON.stringify(t),u=t=>{switch(t.type){case"num":case"var":return t;case"add":{const e=u(t.left),r=u(t.right),n=e=>"add"===e.type?[...n(e.left),...n(e.right)]:[e],o=n({type:"add",left:e,right:r}),i={};let a=0;const s=[],l=[];for(let e=0;e<o.length;e++){const t=o[e];if("num"===t.type)a+=t.value;else if("mul"===t.type&&"num"===t.left.type&&"var"===t.right.type){const e=t.right.name;i[e]=(i[e]||0)+t.left.value}else if("var"===t.type){const e=t.name;i[e]=(i[e]||0)+1}else if("pow"===t.type&&"var"===t.base.type&&"num"===t.exponent.type){const e=t.base.name+"^"+t.exponent.value;i[e]=(i[e]||0)+1,l.push({pow:t.exponent.value,name:e})}else if("mul"===t.type&&"num"===t.left.type&&"pow"===t.right.type&&"var"===t.right.base.type&&"num"===t.right.exponent.type){const e=t.right.base.name+"^"+t.right.exponent.value;i[e]=(i[e]||0)+t.left.value,l.push({pow:t.right.exponent.value,name:e})}else s.push(t)}const m=[];for(let e=0;e<l.length;e++){let t=!1;for(let r=0;r<m.length;r++)if(m[r]===l[e].name){t=!0;break}t||m.push(l[e].name)}for(let e=0;e<m.length-1;e++)for(let t=e+1;t<m.length;t++){const r=l.find(t=>t.name===m[e])?.pow??1;if((l.find(e=>e.name===m[t])?.pow??1)>r){const r=m[e];m[e]=m[t],m[t]=r}}const f=Object.keys(i).filter(e=>-1===e.indexOf("^"));let c=null;for(let e=0;e<m.length;e++){const t=m[e];if(0===i[t])continue;const r=t.split("^"),n=r[0],o=r[1],a={type:"pow",base:{type:"var",name:n},exponent:{type:"num",value:Number(o)}},s=1===i[t]?a:{type:"mul",left:{type:"num",value:i[t]},right:a};c=c?{type:"add",left:c,right:s}:s}for(let e=0;e<f.length;e++){const t=f[e];if(0===i[t])continue;const r=1===i[t]?{type:"var",name:t}:{type:"mul",left:{type:"num",value:i[t]},right:{type:"var",name:t}};c=c?{type:"add",left:c,right:r}:r}0!==a&&(c=c?{type:"add",left:c,right:{type:"num",value:a}}:{type:"num",value:a});for(let e=0;e<s.length;e++)c=c?{type:"add",left:c,right:s[e]}:s[e];return c||{type:"num",value:0}}case"sub":{const e=u(t.left),r=u(t.right);return u({type:"add",left:e,right:{type:"mul",left:{type:"num",value:-1},right:r}})}case"mul":{const e=u(t.left),r=u(t.right);if("add"===r.type||"sub"===r.type)return u({type:r.type,left:{type:"mul",left:e,right:r.left},right:{type:"mul",left:e,right:r.right}});if("add"===e.type||"sub"===e.type)return u({type:e.type,left:{type:"mul",left:r,right:e.left},right:{type:"mul",left:r,right:e.right}});if(!("add"!==e.type&&"sub"!==e.type||"add"!==r.type&&"sub"!==r.type)){const t=e=>{if("add"===e.type)return[...t(e.left),...t(e.right)];if("sub"===e.type){const r=t(e.right).map(e=>({type:"neg",expr:e}));return[...t(e.left),...r]}return[e]},n=t(e),o=t(r),i=[];for(const e of n)for(const t of o)"neg"===e.type&&"neg"===t.type?i.push(u({type:"mul",left:e.expr,right:t.expr})):"neg"===e.type?i.push(u({type:"neg",expr:{type:"mul",left:e.expr,right:t}})):"neg"===t.type?i.push(u({type:"neg",expr:{type:"mul",left:e,right:t.expr}})):i.push(u({type:"mul",left:e,right:t}));let a=i[0];for(let e=1;e<i.length;e++)a={type:"add",left:a,right:i[e]};return u(a)}const n=e=>"mul"===e.type?[...n(e.left),...n(e.right)]:[e],o=n({type:"mul",left:e,right:r});let i=1;const a={},s=[];for(let e=0;e<o.length;e++){const t=o[e];"num"===t.type?i*=t.value:"var"===t.type?a[t.name]=(a[t.name]||0)+1:"pow"===t.type&&"var"===t.base.type&&"num"===t.exponent.type?a[t.base.name]=(a[t.base.name]||0)+t.exponent.value:s.push(t)}const l=[],m=[];for(const e in a)a.hasOwnProperty(e)&&(l.push(e),m.push(a[e]));for(let e=0;e<l.length-1;e++)for(let t=e+1;t<l.length;t++)if(m[t]>m[e]){const r=l[e],n=m[e];l[e]=l[t],m[e]=m[t],l[t]=r,m[t]=n}let f=null;(1!==i||0===l.length&&0===s.length)&&(f={type:"num",value:i});for(let e=0;e<l.length;e++){const t=l[e],r=m[e];0!==r&&(f=1===r?f?{type:"mul",left:f,right:{type:"var",name:t}}:{type:"var",name:t}:f?{type:"mul",left:f,right:{type:"pow",base:{type:"var",name:t},exponent:{type:"num",value:r}}}:{type:"pow",base:{type:"var",name:t},exponent:{type:"num",value:r}})}for(let e=0;e<s.length;e++)f=f?{type:"mul",left:f,right:s[e]}:s[e];return f}case"div":{const e=u(t.left),r=u(t.right);if("num"===e.type&&1===e.value&&("add"===r.type||"sub"===r.type))return{type:"pow",base:r,exponent:{type:"num",value:-1}};if("add"===e.type||"sub"===e.type){const t={type:"div",left:e.left,right:JSON.parse(JSON.stringify(r))},n={type:"div",left:e.right,right:JSON.parse(JSON.stringify(r))};return{type:e.type,left:u(t),right:u(n)}}if("num"===e.type&&0===e.value)return{type:"num",value:0};if("num"===r.type&&1===r.value)return e;if("num"===e.type&&"num"===r.type)return{type:"num",value:e.value/r.value};if(l(e,r))return{type:"num",value:1};if("num"===e.type&&1===e.value&&("add"===r.type||"sub"===r.type))return{type:"pow",base:r,exponent:{type:"num",value:-1}};if("mul"===e.type&&l(e.right,r))return u(e.left);if("mul"===e.type&&l(e.left,r))return u(e.right);if("pow"===e.type&&"pow"===r.type&&l(e.base,r.base))return{type:"pow",base:e.base,exponent:{type:"sub",left:u(e.exponent),right:u(r.exponent)}};if("pow"===e.type&&l(e.base,r))return{type:"pow",base:r,exponent:{type:"sub",left:u(e.exponent),right:{type:"num",value:1}}};if("pow"===r.type&&l(e,r.base))return{type:"pow",base:e,exponent:{type:"sub",left:{type:"num",value:1},right:u(r.exponent)}};const n=(e,t)=>e?e.type===t?[...n(e.left,t),...n(e.right,t)]:[e]:[],o=n(e,"mul"),i=n(r,"mul");let a=1,s=1;const m={},f={},c=[],p=[];for(let e=0;e<o.length;e++){const t=o[e];"num"===t.type?a*=t.value:"var"===t.type?m[t.name]=(m[t.name]||0)+1:"pow"===t.type&&"var"===t.base.type&&"num"===t.exponent.type?m[t.base.name]=(m[t.base.name]||0)+t.exponent.value:c.push(t)}for(let e=0;e<i.length;e++){const t=i[e];"num"===t.type?s*=t.value:"var"===t.type?f[t.name]=(f[t.name]||0)+1:"pow"===t.type&&"var"===t.base.type&&"num"===t.exponent.type?f[t.base.name]=(f[t.base.name]||0)+t.exponent.value:p.push(t)}let d=null;const h=a/s;(1!==h||0===Object.keys(m).length&&0===Object.keys(f).length&&0===c.length&&0===p.length)&&(d={type:"num",value:h});const y=[];for(const e in m)-1===y.indexOf(e)&&y.push(e);for(const e in f)-1===y.indexOf(e)&&y.push(e);for(let e=0;e<y.length-1;e++)for(let t=e+1;t<y.length;t++){const r=(m[y[e]]||0)-(f[y[e]]||0);if((m[y[t]]||0)-(f[y[t]]||0)>r){const r=y[e];y[e]=y[t],y[t]=r}}for(let e=0;e<y.length;e++){const t=y[e],r=(m[t]||0)-(f[t]||0);0!==r&&(d=1===r?d?{type:"mul",left:d,right:{type:"var",name:t}}:{type:"var",name:t}:d?{type:"mul",left:d,right:{type:"pow",base:{type:"var",name:t},exponent:{type:"num",value:r}}}:{type:"pow",base:{type:"var",name:t},exponent:{type:"num",value:r}})}for(let e=0;e<c.length;e++)d=d?{type:"mul",left:d,right:c[e]}:c[e];for(let e=0;e<p.length;e++)d={type:"div",left:d,right:p[e]};return d}case"pow":{const r=u(t.base),n=u(t.exponent);if(("add"===r.type||"sub"===r.type)&&"num"===n.type&&Number.isInteger(n.value)){if(n.value<0){const e=Math.abs(n.value);if(1===e)return{type:"pow",base:r,exponent:{type:"num",value:-1}};return{type:"pow",base:u({type:"pow",base:r,exponent:{type:"num",value:e}}),exponent:{type:"num",value:-1}}}if(n.value>0){const t=n.value,o=r.left,i=r.right,a="add"===r.type?1:-1;let s=null;for(let r=0;r<=t;r++){const n=e.numb.binomial(t,r),l=t-r===0?{type:"num",value:1}:t-r===1?o:u({type:"pow",base:o,exponent:{type:"num",value:t-r}}),m=0===r?{type:"num",value:1}:1===r?1===a?i:{type:"neg",expr:i}:u({type:"pow",base:i,exponent:{type:"num",value:r}}),f=-1===a&&r%2==1?-1:1;let c;c=0===r?l:t-r===0?m:u({type:"mul",left:l,right:m}),1!==n?c=u({type:"mul",left:{type:"num",value:f*n},right:c}):-1===f&&(c={type:"neg",expr:c}),s=null===s?c:u({type:"add",left:s,right:c})}return s}}return"num"===n.type&&0===n.value?{type:"num",value:1}:"num"===n.type&&1===n.value?r:"num"===r.type&&0===r.value&&"num"===n.type&&n.value>0?{type:"num",value:0}:"num"===r.type&&1===r.value?{type:"num",value:1}:"num"===r.type&&"num"===n.type?{type:"num",value:Math.pow(r.value,n.value)}:"pow"===r.type?{type:"pow",base:r.base,exponent:{type:"mul",left:u(r.exponent),right:n}}:"mul"===r.type&&"num"===n.type?u({type:"mul",left:{type:"pow",base:r.left,exponent:n},right:{type:"pow",base:r.right,exponent:n}}):{type:"pow",base:r,exponent:n}}case"neg":{const e=u(t.expr);return"neg"===e.type?e.expr:"num"===e.type?{type:"num",value:-e.value}:"add"===e.type?u({type:"add",left:u({type:"neg",expr:e.left}),right:u({type:"neg",expr:e.right})}):"sub"===e.type?u({type:"add",left:u({type:"neg",expr:e.left}),right:e.right}):{type:"neg",expr:e}}case"func":{const r=t.args.map(e=>u(e));if(r.every(e=>"num"===e.type))try{const n=t.name.toLowerCase();if(void 0!==e.REGISTRY[n]){const t=r.map(e=>e.value);return{type:"num",value:e.REGISTRY[n](...t)}}return{type:"num",value:i({type:"func",name:t.name,args:r},{})}}catch(e){return{type:"func",name:t.name,args:r}}return{type:"func",name:t.name,args:r}}}return t};try{const l=o(n(t));if(r.returnAST)return l;if(r.returnJSON)return JSON.stringify(l);if(r.values&&Object.keys(r.values).length>0){const t=i(l,r.values);return void 0!==r.roundTo?e.numb.roundTo(t,r.roundTo):t}let m=u(l),f=o(n(a(m)));if(m=u(f),m=u(m),void 0!==r.roundTo){const t=n=>{if("num"===n.type)return{...n,value:e.numb.roundTo(n.value,r.roundTo)};const o=Object.keys(n).length;for(let e=0;e<o;e++){const r=Object.keys(n)[e];"type"!==r&&n[r]&&"object"==typeof n[r]&&"type"in n[r]&&(n[r]=t(n[r]))}return n};m=t(m)}return r.returnLaTeX?s(m):a(m)}catch(e){throw e instanceof Error?new Error(`Chalkboard.real.parse: Error parsing real expression ${e.message}`):new Error(`Chalkboard.real.parse: Error parsing real expression ${String(e)}`)}},t.pingpong=(e,t=0,r=1)=>(e+t)%(2*r)<r?(e+t)%r:r-(e+t)%r,t.polynomial=(...t)=>{let r;for(r=1===t.length&&Array.isArray(t[0])?t[0]:t;r.length>1&&0===r[0];)r.shift();return e.real.define(e=>{if(0===r.length)return 0;let t=r[0];for(let n=1;n<r.length;n++)t=t*e+r[n];return t})},t.pow=(t,r)=>{if("number"==typeof t){if(0===t&&0===r)return 1;if(0===t)return 0;if(0===r)return 1;if(1===r)return t;if(Number.isInteger(r)){let e=1,n=t,o=Math.abs(r);for(;o>0;)o%2==1&&(e*=n),n*=n,o=Math.floor(o/2);return r<0?1/e:e}return t<0?NaN:e.E(r*e.real.ln(t))}{const n=t;if("real"!==n.field)throw new TypeError("Chalkboard.real.pow: Property 'field' of 'func' must be 'real'.");if(n.type.startsWith("scalar")){const t=n.rule,o=(...e)=>t(...e)**r;return e.real.define(o)}if(n.type.startsWith("vector")){const t=n.rule,o=[];for(let e=0;e<t.length;e++)o.push((...n)=>t[e](...n)**r);return e.real.define(o)}if(n.type.startsWith("curve")){const t=n.rule,o=[];for(let e=0;e<t.length;e++)o.push(n=>t[e](n)**r);return e.real.define(o)}if(n.type.startsWith("surface")){const t=n.rule,o=[];for(let e=0;e<t.length;e++)o.push((n,o)=>t[e](n,o)**r);return e.real.define(o)}throw new TypeError("Chalkboard.real.pow: Property 'type' of 'func' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")}},t.qerp=(e,t,r,n)=>(e[1]/((e[0]-t[0])*(e[0]-r[0]))+t[1]/((t[0]-e[0])*(t[0]-r[0]))+r[1]/((r[0]-e[0])*(r[0]-t[0])))*n*n+(-e[1]*(t[0]+r[0])/((e[0]-t[0])*(e[0]-r[0]))-t[1]*(e[0]+r[0])/((t[0]-e[0])*(t[0]-r[0]))-r[1]*(e[0]+t[0])/((r[0]-e[0])*(r[0]-t[0])))*n+(e[1]*t[0]*r[0]/((e[0]-t[0])*(e[0]-r[0]))+t[1]*e[0]*r[0]/((t[0]-e[0])*(t[0]-r[0]))+r[1]*e[0]*t[0]/((r[0]-e[0])*(r[0]-t[0]))),t.quadratic=(t,r,n,o="standard")=>{if("standard"===o)return e.real.define(e=>t*e*e+r*e+n);if("vertex"===o)return e.real.define(e=>t*(e-r)*(e-r)+n);throw new TypeError("Chalkboard.real.quadratic: String 'form' must be 'standard' or 'vertex'.")},t.quadraticFormula=(t,r,n,o="standard")=>{if("standard"===o)return[(-r+e.real.sqrt(e.real.discriminant(t,r,n,"standard")))/(2*t),(-r-e.real.sqrt(e.real.discriminant(t,r,n,"standard")))/(2*t)];if("vertex"===o)return[r+e.real.sqrt(-n/t),r-e.real.sqrt(-n/t)];throw new TypeError("Chalkboard.real.quadraticFormula: String 'form' must be 'standard' or 'vertex'.")},t.ramp=(e,t=0,r=1)=>e>=t?e*r:0,t.randomPolynomial=(t,r=0,n=1)=>e.real.polynomial(...e.stat.random(t+1,r,n)),t.reciprocate=t=>{if("real"!==t.field)throw new TypeError("Chalkboard.real.reciprocate: Property 'field' of 'func' must be 'real'.");if(t.type.startsWith("scalar")){const r=t.rule,n=(...e)=>1/r(...e);return e.real.define(n)}if(t.type.startsWith("vector")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push((...t)=>1/r[e](...t));return e.real.define(n)}if(t.type.startsWith("curve")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push(t=>1/r[e](t));return e.real.define(n)}if(t.type.startsWith("surface")){const r=t.rule,n=[];for(let e=0;e<r.length;e++)n.push((t,n)=>1/r[e](t,n));return e.real.define(n)}throw new TypeError("Chalkboard.real.reciprocate: Property 'type' of 'func' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.rect=(e,t=0,r=2,n=1)=>e>t+r/2||e<t-r/2?0:n,t.root=(t,r=3)=>0===t?0:t<0?Number.isInteger(r)&&Math.abs(r)%2==1?-e.E(e.real.ln(-t)/r):NaN:e.E(e.real.ln(t)/r),t.scl=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.real.scl: Property 'field' of 'func' must be 'real'.");if(t.type.startsWith("scalar")){const n=t.rule,o=(...e)=>n(...e)*r;return e.real.define(o)}if(t.type.startsWith("vector")){const n=t.rule,o=[];for(let e=0;e<n.length;e++)o.push((...t)=>n[e](...t)*r);return e.real.define(o)}if(t.type.startsWith("curve")){const n=t.rule,o=[];for(let e=0;e<n.length;e++)o.push(t=>n[e](t)*r);return e.real.define(o)}if(t.type.startsWith("surface")){const n=t.rule,o=[];for(let e=0;e<n.length;e++)o.push((t,o)=>n[e](t,o)*r);return e.real.define(o)}throw new TypeError("Chalkboard.real.scl: Property 'type' of 'func' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.slope=(e,t,r,n)=>(n-t)/(r-e),t.sqrt=e=>{if(e<0)return NaN;if(0===e||1===e||e===1/0)return e;let t=e,r=0;for(;t>=1;)t*=.25,r++;for(;t<.25;)t*=4,r--;let n=.5*(t+1);return n=.5*(n+t/n),n=.5*(n+t/n),n=.5*(n+t/n),n=.5*(n+t/n),n=.5*(n+t/n),n*2**r},t.sub=(t,r)=>{if("real"!==t.field||"real"!==r.field)throw new TypeError("Chalkboard.real.sub: Properties 'field' of 'func1' and 'func2' must be 'real'.");if(t.type!==r.type)throw new TypeError("Chalkboard.real.sub: Properties 'type' of 'func1' and 'func2' must be the same.");if(t.type.startsWith("scalar")){const n=t.rule,o=r.rule,i=(...e)=>n(...e)-o(...e);return e.real.define(i)}if(t.type.startsWith("vector")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((...t)=>n[e](...t)-o[e](...t));return e.real.define(i)}if(t.type.startsWith("curve")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push(t=>n[e](t)-o[e](t));return e.real.define(i)}if(t.type.startsWith("surface")){const n=t.rule,o=r.rule,i=[];for(let e=0;e<n.length;e++)i.push((t,r)=>n[e](t,r)-o[e](t,r));return e.real.define(i)}throw new TypeError("Chalkboard.real.sub: Properties 'type' of 'func1' and 'func2' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")},t.tetration=(t,r)=>{if(!Number.isInteger(r)||r<0)return NaN;if(0===r)return 1;if(1===r)return t;let n=t;for(let o=1;o<r;o++)if(n=e.real.pow(t,n),n===1/0)return 1/0;return n},t.translate=(t,r=0,n=0)=>{if("real"!==t.field)throw new TypeError("Chalkboard.real.translate: Property 'field' of 'func' must be 'real'.");if("scalar2d"===t.type){const o=t.rule,i=e=>o(e-r)+n;return e.real.define(i)}throw new TypeError("Chalkboard.real.translate: Property 'type' of 'func' must be 'scalar2d'.")},t.val=(t,r)=>{if("real"!==t.field)throw new TypeError("Chalkboard.real.val: Property 'field' of 'func' must be 'real'.");if("scalar2d"===t.type){return(0,t.rule)(r)}if("scalar3d"===t.type){const e=r;return(0,t.rule)(e.x,e.y)}if("scalar4d"===t.type){const e=r;return(0,t.rule)(e.x,e.y,e.z)}if("vector2d"===t.type){const n=t.rule,o=r;return e.vect.init(n[0](o.x,o.y),n[1](o.x,o.y))}if("vector3d"===t.type){const n=t.rule,o=r;return e.vect.init(n[0](o.x,o.y,o.z),n[1](o.x,o.y,o.z),n[2](o.x,o.y,o.z))}if("vector4d"===t.type){const n=t.rule,o=r;return e.vect.init(n[0](o.x,o.y,o.z,o.w),n[1](o.x,o.y,o.z,o.w),n[2](o.x,o.y,o.z,o.w),n[3](o.x,o.y,o.z,o.w))}if("curve2d"===t.type){const n=t.rule,o=r;return e.vect.init(n[0](o),n[1](o))}if("curve3d"===t.type){const n=t.rule,o=r;return e.vect.init(n[0](o),n[1](o),n[2](o))}if("curve4d"===t.type){const n=t.rule,o=r;return e.vect.init(n[0](o),n[1](o),n[2](o),n[3](o))}if("surface3d"===t.type){const n=t.rule,o=r;return e.vect.init(n[0](o.x,o.y),n[1](o.x,o.y),n[2](o.x,o.y))}throw new TypeError("Chalkboard.real.val: Property 'type' of 'func' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'")},t.zero=(t="scalar2d")=>{if("scalar2d"===t)return e.real.define(e=>0);if("scalar3d"===t)return e.real.define((e,t)=>0);if("scalar4d"===t)return e.real.define((e,t,r)=>0);if("vector2d"===t)return e.real.define((e,t)=>0,(e,t)=>0);if("vector3d"===t)return e.real.define((e,t,r)=>0,(e,t,r)=>0,(e,t,r)=>0);if("vector4d"===t)return e.real.define((e,t,r,n)=>0,(e,t,r,n)=>0,(e,t,r,n)=>0,(e,t,r,n)=>0);if("curve2d"===t)return e.real.define(e=>0,e=>0);if("curve3d"===t)return e.real.define(e=>0,e=>0,e=>0);if("curve4d"===t)return e.real.define(e=>0,e=>0,e=>0,e=>0);if("surface3d"===t)return e.real.define((e,t)=>0,(e,t)=>0,(e,t)=>0);throw new TypeError("Chalkboard.real.zero: String 'type' must be 'scalar2d', 'scalar3d', 'scalar4d', 'vector2d', 'vector3d', 'vector4d', 'curve2d', 'curve3d', 'curve4d', or 'surface3d'.")}}(t=e.real||(e.real={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){const r=(e,t)=>{const r=(t,n,o)=>{if(t===n)return e[t];let i=Math.floor(Math.random()*(n-t+1))+t;const a=e[i];e[i]=e[n],e[n]=a;let s=t;for(let r=t;r<n;r++)if(e[r]<a){const t=e[s];e[s]=e[r],e[r]=t,s++}return e[n]=e[s],e[s]=a,o===s?e[o]:o<s?r(t,s-1,o):r(s+1,n,o)};return r(0,e.length-1,t)};t.absolute=e=>{const t=[];for(let r=0;r<e.length;r++)t.push(Math.abs(e[r]));return t},t.add=(e,t)=>{if(e.length!==t.length)throw new RangeError('Parameters "arr1" and "arr2" must have the same length.');const r=[];for(let n=0;n<e.length;n++)r.push(e[n]+t[n]);return r},t.array=(e,t,r=t-e+1)=>{const n=[],o=(t-e)/(r-1);for(let t=0;t<r;t++)n.push(e+o*t);return n},t.autocorrelation=t=>e.stat.correlation(t,t),t.Bayes=(e,t,r)=>{if(e<0||e>1||t<0||t>1||r<0||r>1)throw new RangeError("All probabilities must be between 0 and 1.");return t*e/(t*e+r*(1-e))},t.change=(t,r)=>{if(t.length!==r.length)throw new RangeError('Parameters "arr1" and "arr2" must have the same length.');const n=[];for(let o=0;o<t.length;o++)n.push(e.numb.change(t[o],r[o]));return n},t.chiSquared=(e,t)=>{if(e.length!==t.length)throw new RangeError('Parameters "arr1" and "arr2" must have the same length.');const r=[];for(let n=0;n<e.length;n++)r.push((e[n]-t[n])*(e[n]-t[n])/t[n]);return r},t.confidenceInterval=(t,r=.95)=>{if(r<=0||r>=1)throw new RangeError('Parameter "confidence" must be between 0 and 1 (exclusive).');const n=e.stat.inormal(1-(1-r)/2),o=e.stat.mean(t),i=e.stat.error(t);return[o-n*i,o+n*i]},t.constrain=(t,r=[0,1])=>{const n=[];for(let o=0;o<t.length;o++)n.push(e.numb.constrain(t[o],r));return n},t.convolution=(e,t)=>{const r=[];for(let n=0;n<e.length+t.length-1;n++){let o=0;for(let r=Math.max(0,n-t.length+1);r<Math.min(e.length,n+1);r++)o+=e[r]*t[n-r];r.push(o)}return r},t.correlation=(e,t)=>{const r=[];for(let n=0;n<e.length+t.length-1;n++){let o=0;for(let r=Math.max(0,n-t.length+1);r<Math.min(e.length,n+1);r++)o+=e[r]*t[t.length-1-n+r];r.push(o)}return r},t.correlationCoefficient=(t,r)=>e.stat.covariance(t,r)/(e.stat.deviation(t)*e.stat.deviation(r)),t.covariance=(t,r)=>{if(t.length!==r.length)throw new RangeError('Parameters "arr1" and "arr2" must have the same length.');const n=e.stat.mean(t),o=e.stat.mean(r);let i=0;for(let e=0;e<t.length;e++)i+=(t[e]-n)*(r[e]-o);return i/t.length},t.cummax=e=>{const t=[];let r=-1/0;for(const n of e)r=Math.max(r,n),t.push(r);return t},t.cummin=e=>{const t=[];let r=1/0;for(const n of e)r=Math.min(r,n),t.push(r);return t},t.cummul=e=>{const t=[];let r=1;for(let n=0;n<e.length;n++)r*=e[n],t.push(r);return t},t.cumsum=e=>{const t=[];let r=0;for(let n=0;n<e.length;n++)r+=e[n],t.push(r);return t},t.deviation=t=>{let r=0;for(let n=0;n<t.length;n++)r+=(t[n]-e.stat.mean(t))*(t[n]-e.stat.mean(t));return e.real.sqrt(r/t.length)},t.dot=(e,t)=>{if(e.length!==t.length)throw new RangeError('Parameters "arr1" and "arr2" must have the same length.');let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r},t.error=t=>e.stat.deviation(t)/e.real.sqrt(t.length),t.eq=(e,t)=>{const r=[];if(Array.isArray(t)){if(e.length===t.length)for(let n=0;n<e.length;n++)e[n]===t[n]&&r.push(e[n])}else for(let n=0;n<e.length;n++)e[n]===t&&r.push(e[n]);return r},t.expected=(e,t)=>{if(t||(t=Array(e.length).fill(1/e.length)),e.length!==t.length)throw new RangeError('Parameters "values" and "probabilities" must have the same length.');let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r},t.Gaussian=(t,r,n)=>e.real.define(e=>t*Math.exp(-(e-r)*(e-r)/(2*n*n))),t.gt=(e,t,r=!1)=>{const n=[];if(Array.isArray(t)){if(e.length===t.length)for(let o=0;o<e.length;o++)r?e[o]>=t[o]&&n.push(e[o]):e[o]>t[o]&&n.push(e[o])}else for(let o=0;o<e.length;o++)r?e[o]>=t&&n.push(e[o]):e[o]>t&&n.push(e[o]);return n},t.ineq=(e,t,r,n=!1,o=!1)=>{const i=[];if(Array.isArray(t)&&Array.isArray(r)){if(e.length===t.length&&e.length===r.length)for(let a=0;a<e.length;a++)n?o?e[a]>=t[a]&&e[a]<=r[a]&&i.push(e[a]):e[a]>=t[a]&&e[a]<r[a]&&i.push(e[a]):o?e[a]>t[a]&&e[a]<=r[a]&&i.push(e[a]):e[a]>t[a]&&e[a]<r[a]&&i.push(e[a])}else for(let a=0;a<e.length;a++)n?o?e[a]>=t&&e[a]<=r&&i.push(e[a]):e[a]>=t&&e[a]<r&&i.push(e[a]):o?e[a]>t&&e[a]<=r&&i.push(e[a]):e[a]>t&&e[a]<r&&i.push(e[a]);return i},t.inormal=e=>{if(e<=0||e>=1)throw new RangeError('Parameter "p" must be between 0 and 1 (exclusive).');const t=[2.50662823884,-18.61500062529,41.39119773534,-25.44106049637],r=[-8.4735109309,23.08336743743,-21.06224101826,3.13082909833],n=[.3374754822726147,.9761690190917186,.1607979714918209,.0276438810333863,.0038405729373609,.0003951896511919,321767881768e-16,2.888167364e-7,3.960315187e-7];let o=e-.5;if(Math.abs(o)<.42){const e=o*o;return o*(((t[3]*e+t[2])*e+t[1])*e+t[0])/((((r[3]*e+r[2])*e+r[1])*e+r[0])*e+1)}{const t=e<.5?e:1-e,r=Math.log(-Math.log(t));let o=n[0];for(let e=1;e<n.length;e++)o+=n[e]*Math.pow(r,e);return e<.5?-o:o}},t.interpolate=(t,r="linear")=>{const n=t.slice();for(let t=0;t<n.length;t++)if(null==n[t]){let o=t-1,i=t+1;for(;o>=0&&null==n[o];)o--;for(;i<n.length&&null==n[i];)i++;const a=o>=0?n[o]:0,s=i<n.length?n[i]:0;if("linear"===r){const r=(t-o)/(i-o);n[t]=e.real.lerp([a,s],r)}else if("quadratic"===r&&o>0&&i<n.length){const r=o-1,l=r>=0?n[r]:a,u=(t-o)/(i-o);n[t]=e.real.qerp([r,l],[o,a],[i,s],o+u*(i-o))}else{const r=(t-o)/(i-o);n[t]=e.real.lerp([a,s],r)}}return n},t.interquartileRange=t=>e.stat.quartile(t,"Q3")-e.stat.quartile(t,"Q1"),t.kurtosis=t=>{let r=0;const n=e.stat.mean(t),o=e.stat.deviation(t);for(let e=0;e<t.length;e++)r+=(t[e]-n)*(t[e]-n)*(t[e]-n)*(t[e]-n);return r/(o*o*o*o)-3},t.lt=(e,t,r=!1)=>{const n=[];if(Array.isArray(t)){if(e.length===t.length)for(let o=0;o<e.length;o++)r?e[o]<=t[o]&&n.push(e[o]):e[o]<t[o]&&n.push(e[o])}else for(let o=0;o<e.length;o++)r?e[o]<=t&&n.push(e[o]):e[o]<t&&n.push(e[o]);return n},t.mad=t=>{let r=0;for(let n=0;n<t.length;n++)r+=Math.abs(t[n]-e.stat.mean(t));return r/t.length},t.max=e=>{let t=e[0];for(let r=0;r<e.length;r++)e[r]>t&&(t=e[r]);return t},t.mean=(t,r="arithmetic")=>{let n=0;if("arithmetic"===r){for(let e=0;e<t.length;e++)n+=t[e];return n/t.length}if("geometric"===r){n=1;for(let e=0;e<t.length;e++)n*=t[e];return e.real.root(Math.abs(n),t.length)}if("harmonic"===r){for(let e=0;e<t.length;e++)n+=1/t[e];return t.length/n}throw new TypeError('Parameter "type" must be "arithmetic", "geometric", or "harmonic".')},t.meanMoving=(t,r)=>{if(r<=0||r>t.length)throw new RangeError('Parameter "windowSize" must be greater than 0 and less than or equal to the array length.');const n=[];for(let o=0;o<=t.length-r;o++){const i=t.slice(o,o+r);n.push(e.stat.sum(i)/r)}return n},t.meanWeighted=(e,t)=>{if(e.length!==t.length)throw new RangeError('Parameters "values" and "weights" must have the same length.');let r=0,n=0;for(let o=0;o<e.length;o++)r+=e[o]*t[o],n+=t[o];return r/n},t.median=e=>{if(0===e.length)return NaN;const t=e.slice(),n=Math.floor(t.length/2);return t.length%2==1?r(t,n):(r(t,n-1)+r(t,n))/2},t.min=e=>{let t=e[0];for(let r=0;r<e.length;r++)e[r]<t&&(t=e[r]);return t},t.mode=e=>{if(0===e.length)return NaN;const t=new Map;let r=0,n=e[0];for(let o=0;o<e.length;o++){const i=e[o],a=(t.get(i)||0)+1;t.set(i,a),a>r&&(r=a,n=i)}return n},t.mul=e=>{let t=1;for(let r=0;r<e.length;r++)t*=e[r];return t},t.negate=e=>{const t=[];for(let r=0;r<e.length;r++)t.push(-e[r]);return t},t.norm=(t,r="L2")=>{let n=0;if("L0"===r){for(let e=0;e<t.length;e++)0!==t[e]&&(n+=1);return n}if("L1"===r){for(let e=0;e<t.length;e++)n+=Math.abs(t[e]);return n}if("L2"===r){for(let e=0;e<t.length;e++)n+=t[e]*t[e];return e.real.sqrt(n)}if("LInfinity"===r)return Math.abs(e.stat.max(t));throw new TypeError('Parameter "type" must be "L0", "L1", "L2", or "LInfinity".')},t.normal=t=>{const r=e.real.define(e=>1/Math.sqrt(2*Math.PI)*Math.exp(-.5*e*e));return(0,r.rule)(t)},t.normalize=(t,r="L2")=>{const n=[],o=e.stat.norm(t,r);for(let e=0;e<t.length;e++)n.push(t[e]/o);return n},t.normsq=(t,r="L2")=>{let n=0;if("L0"===r){for(let e=0;e<t.length;e++)0!==t[e]&&(n+=1);return n*n}if("L1"===r){for(let e=0;e<t.length;e++)n+=Math.abs(t[e]);return n*n}if("L2"===r){for(let e=0;e<t.length;e++)n+=t[e]*t[e];return n}if("LInfinity"===r)return Math.abs(e.stat.max(t))*Math.abs(e.stat.max(t));throw new TypeError('Parameter "type" must be "L0", "L1", "L2", or "LInfinity".')},t.pad=(e,t,r=0)=>{const n=e.slice();for(;n.length<t;)n.push(r);return n},t.percentile=(e,t)=>{let r=0;for(let n=0;n<e.length;n++)t>=e[n]&&r++;return r/e.length*100},t.print=t=>{console.log(e.stat.toString(t))},t.quartile=(t,n)=>{if(0===t.length)return NaN;const o=t.slice();if("Q2"===n)return e.stat.median(o);const i=Math.floor(o.length/2);if("Q1"===n){const e=Math.floor(i/2);return i%2==1?r(o,e):(r(o,e-1)+r(o,e))/2}if("Q3"===n){const e=(o.length%2==0?i:i+1)+Math.floor(i/2);return i%2==1?r(o,e):(r(o,e-1)+r(o,e))/2}throw new TypeError('Parameter "type" must be "Q1", "Q2", or "Q3".')},t.random=(t,r=0,n=1)=>{const o=[];for(let i=0;i<t;i++)o.push(e.numb.random(r,n));return o},t.range=t=>e.stat.max(t)-e.stat.min(t),t.regression=(t,r="linear",n=2)=>{if("linear"===r){let r=0,n=0,o=0,i=0;for(let e=0;e<t.length;e++)r+=t[e][0],n+=t[e][1],o+=t[e][0]*t[e][0],i+=t[e][0]*t[e][1];const a=(t.length*i-r*n)/(t.length*o-r*r),s=n/t.length-a*r/t.length;return e.real.define(e=>a*e+s)}if("polynomial"===r){const r=e.matr.init();for(let o=0;o<t.length;o++){r.push([]);for(let i=0;i<=n;i++)r[o].push(e.real.pow(t[o][0],i))}const o=e.matr.transpose(r),i=e.matr.init();for(let e=0;e<t.length;e++)i.push([t[e][1]]);const a=e.matr.mul(o,r),s=e.matr.invert(a),l=e.matr.mul(e.matr.mul(s,o),i),u=[];for(let e=0;e<l.length;e++)u.push(l[e][0]);return e.real.define(e=>{let t=u[0];t+=u[1]*e;for(let r=2;r<=n;r++)t+=u[r]*Math.pow(e,r);return t})}if("power"===r){const r=[0,0,0,0];for(let e=0;e<t.length;e++)r[0]+=Math.log(t[e][0]),r[1]+=Math.log(t[e][1])*Math.log(t[e][0]),r[2]+=Math.log(t[e][1]),r[3]+=Math.log(t[e][0])*Math.log(t[e][0]);const n=e.E((r[2]-(t.length*r[1]-r[2]*r[0])/(t.length*r[3]-r[0]*r[0])*r[0])/t.length),o=(t.length*r[1]-r[2]*r[0])/(t.length*r[3]-r[0]*r[0]);return e.real.define(e=>n*Math.pow(e,o))}if("exponential"===r){const r=[0,0,0,0,0,0];for(let e=0;e<t.length;e++)r[0]+=t[e][0],r[1]+=t[e][1],r[2]+=t[e][0]*t[e][0]*t[e][1],r[3]+=t[e][1]*Math.log(t[e][1]),r[4]+=t[e][0]*(t[e][1]*Math.log(t[e][1])),r[5]+=t[e][0]*t[e][1];const n=e.E((r[2]*r[3]-r[5]*r[4])/(r[1]*r[2]-r[5]*r[5])),o=(r[1]*r[4]-r[5]*r[3])/(r[1]*r[2]-r[5]*r[5]);return e.real.define(e=>n*Math.exp(o*e))}if("logarithmic"===r){const r=[0,0,0,0];for(let e=0;e<t.length;e++)r[0]+=Math.log(t[e][0]),r[1]+=t[e][1]*Math.log(t[e][0]),r[2]+=t[e][1],r[3]+=Math.log(t[e][0])*Math.log(t[e][0]);const n=(r[2]-(t.length*r[1]-r[2]*r[0])/(t.length*r[3]-r[0]*r[0])*r[0])/t.length,o=(t.length*r[1]-r[2]*r[0])/(t.length*r[3]-r[0]*r[0]);return e.real.define(e=>n+o*Math.log(e))}throw new TypeError('Parameter "type" must be "linear", "polynomial", "power", "exponential", or "logarithmic".')},t.resampling=(e,t,r="bootstrap")=>{if("bootstrap"===r){const r=t??100,n=[];for(let t=0;t<r;t++){const t=[];for(let r=0;r<e.length;r++)t.push(e[Math.floor(Math.random()*e.length)]);n.push(t)}return n}if("jackknife"===r){const r=t??e.length,n=[];for(let t=0;t<e.length;t++)n.push(e.slice(0,t).concat(e.slice(t+1)));if(r<n.length){const e=[],t=new Set;for(;e.length<r;){const r=Math.floor(Math.random()*n.length);t.has(r)||(t.add(r),e.push(n[r]))}return e}return n}throw new TypeError('Parameter "type" must be "bootstrap" or "jackknife".')},t.reverse=e=>{const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t},t.scl=(e,t)=>{const r=[];for(let n=0;n<e.length;n++)r.push(e[n]*t);return r},t.shuffle=t=>{let r,n,o;for(r=t.length-1;r>0;r--)o=Math.floor(e.numb.random(0,r+1)),n=t[r],t[r]=t[o],t[o]=n;return t},t.skewness=t=>{let r=0;const n=e.stat.mean(t),o=e.stat.deviation(t);for(let e=0;e<t.length;e++)r+=(t[e]-n)*(t[e]-n)*(t[e]-n);return r/((t.length-1)*(o*o*o))},t.sub=(e,t)=>{if(e.length!==t.length)throw new RangeError('Parameters "arr1" and "arr2" must have the same length.');const r=[];for(let n=0;n<e.length;n++)r.push(e[n]-t[n]);return r},t.subsets=e=>{let t=[[]];e.sort();for(let r=0;r<e.length;r++)if(0===r||e[r]!==e[r-1]){const n=e[r],o=[];for(let e=0;e<t.length;e++){const r=t[e].slice();r.push(n),o.push(r)}t=t.concat(o)}return t},t.sum=e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t},t.toMatrix=(t,r,n=r)=>{const o=e.matr.init();let i=0;for(let e=0;e<r;e++){o[e]=[];for(let r=0;r<n;r++)i<t.length?o[e].push(t[i]):o[e].push(0),i++}return o},t.toObject=e=>{const t={};for(let r=0;r<e.length;r++)t["_"+r.toString()]=e[r];return t},t.toSet=t=>e.abal.set(t),t.toString=e=>"["+e.join(", ")+"]",t.toTensor=(t,...r)=>(Array.isArray(r[0])&&(r=r[0]),e.tens.resize(t,...r)),t.toVector=(t,r,n=0)=>{if(2===r)return e.vect.init(t[n],t[n+1]);if(3===r)return e.vect.init(t[n],t[n+1],t[n+2]);if(4===r)return e.vect.init(t[n],t[n+1],t[n+2],t[n+3]);throw new RangeError('Parameter "dimension" must be 2, 3, or 4.')},t.unique=e=>{if(0===e.length)return[];const t=typeof e[0];if("number"===t||"string"===t||"boolean"===t)return Array.from(new Set(e));const r=e=>JSON.stringify(e,(e,t)=>{if(null!==t&&"object"==typeof t&&!Array.isArray(t)){const e={};return Object.keys(t).sort().forEach(r=>{e[r]=t[r]}),e}return t}),n=new Map;for(const t of e){const e=null===t?"null":typeof t,o=`${e}:${"undefined"===e||Number.isNaN(t)?"":r(t)}`;n.has(o)||n.set(o,t)}return Array.from(n.values())},t.variance=t=>{let r=0;for(let n=0;n<t.length;n++)r+=(t[n]-e.stat.mean(t))*(t[n]-e.stat.mean(t));return r/t.length},t.zscored=t=>{let r=[];const n=e.stat.mean(t),o=e.stat.deviation(t);for(let e=0;e<t.length;e++)r.push((t[e]-n)/o);return r}}(t=e.stat||(e.stat={}))}(Chalkboard||(Chalkboard={})),function(e){let t;var r;(r=t=e.tens||(e.tens={})).absolute=t=>{const r=e.tens.init();if(Array.isArray(t)){for(let n=0;n<t.length;n++)r[n]=e.tens.absolute(t[n]);return r}return Math.abs(t)},r.add=(t,r)=>{const n=e.tens.init();if(Array.isArray(t)&&Array.isArray(r)){for(let o=0;o<Math.max(t.length,r.length);o++)n[o]=e.tens.add(void 0!==t[o]?t[o]:0,void 0!==r[o]?r[o]:0);return n}return t+r},r.concat=(t,r,n=1)=>{const o=function(t,r,i){return i===n?e.tens.init(t.concat(r)):t.map(function(e,t){return o(e,r[t],i)})};return o(t,r,1)},r.constrain=(t,r=[0,1])=>{const n=e.tens.init();if(Array.isArray(t)){for(let o=0;o<t.length;o++)n[o]=e.tens.constrain(t[o],r);return n}return e.numb.constrain(t,r)},r.contract=t=>e.tens.rank(t)>2?e.tens.resize(t,e.tens.size(t)[0],e.tens.size(t).slice(1).reduce(function(e,t){return e*t})/e.tens.size(t)[0]):2===e.tens.rank(t)?e.matr.trace(t):t,r.copy=t=>{if(Array.isArray(t)){const r=e.tens.init();for(let n=0;n<t.length;n++)r[n]=e.tens.copy(t[n]);return r}return t},r.empty=(...e)=>{e=Array.isArray(e[0])?e[0]:e;const t=function(e){if(0===e.length)return null;const r=e[0],n=e.slice(1),o=[];for(let e=0;e<r;e++)o[e]=t(n);return o};return t(e)},r.fill=(e,...t)=>{t=Array.isArray(t[0])?t[0]:t;const r=function(t){if(0===t.length)return e;const n=t[0],o=t.slice(1),i=[];for(let e=0;e<n;e++)i[e]=r(o);return i};return r(t)},r.init=(...e)=>{if(0===e.length)return[];1===e.length&&Array.isArray(e[0])&&(e=e[0]);const t=function(e){return e.map(function(e){return Array.isArray(e)?t(e):e})};return t(e)},r.isApproxEqual=(t,r,n=1e-6)=>{if(e.tens.isSizeEqual(t,r)){for(let o=0;o<t.length;o++)if(Array.isArray(t[o])&&Array.isArray(r[o])){if(!e.tens.isApproxEqual(t[o],r[o],n))return!1}else if(!e.numb.isApproxEqual(t[o],r[o],n))return!1;return!0}return!1},r.isEqual=(t,r)=>{if(e.tens.isSizeEqual(t,r)){for(let n=0;n<t.length;n++)if(Array.isArray(t[n])&&Array.isArray(r[n])){if(!e.tens.isEqual(t[n],r[n]))return!1}else if(t[n]!==r[n])return!1;return!0}return!1},r.isRankEqual=(t,r)=>e.tens.rank(t)===e.tens.rank(r),r.isRankOf=(t,r)=>e.tens.rank(t)===r,r.isSizeEqual=(t,r)=>{if(e.tens.isRankEqual(t,r)){let n=0;for(let o=0;o<e.tens.rank(t);o++)e.tens.size(t)[o]!==e.tens.size(r)[o]&&n++;return 0===n}return!1},r.isSizeOf=(t,...r)=>(r=Array.isArray(r[0])?r[0]:r,e.tens.isSizeEqual(t,e.tens.empty(...r))),r.isSizeUniform=t=>{let r=0;for(let n=0;n<e.tens.rank(t);n++)e.tens.size(t)[n]!==e.tens.size(t)[0]&&r++;return 0===r},r.isZero=t=>{if(Array.isArray(t)){for(let r=0;r<t.length;r++)if(!e.tens.isZero(t[r]))return!1;return!0}return e.numb.isApproxEqual(t,0)},r.mul=(t,r)=>{const n=e.tens.init();if(Array.isArray(t)&&Array.isArray(r)){for(let o=0;o<t.length;o++){const i=e.tens.init();for(let n=0;n<r.length;n++)i[n]=e.tens.mul(t[o],r[n]);n.push(i)}return n}return t*r},r.negate=t=>{const r=e.tens.init();if(Array.isArray(t)){for(let n=0;n<t.length;n++)r[n]=e.tens.negate(t[n]);return r}return-t},r.print=t=>{console.log(e.tens.toString(t))},r.pull=(t,r,n)=>{if(0===r)return t.splice(n,1),t;for(let o=0;o<t.length;o++)e.tens.pull(t[o],r-1,n);return t},r.push=(t,r,n,o)=>{if(0===r)return t.splice(n,0,o),t;for(let i=0;i<t.length;i++)e.tens.push(t[i],r-1,n,o[i]);return t},r.random=(t,r,...n)=>{n=Array.isArray(n[0])?n[0]:n;const o=function(n){if(0===n.length)return e.numb.random(t,r);const i=n[0],a=n.slice(1),s=[];for(let e=0;e<i;e++)s[e]=o(a);return s};return o(n)},r.rank=t=>e.tens.size(t).length,r.reciprocate=t=>{const r=e.tens.init();if(Array.isArray(t)){for(let n=0;n<t.length;n++)r[n]=e.tens.reciprocate(t[n]);return r}return 1/t},r.resize=(t,...r)=>{r=Array.isArray(r[0])?r[0]:r;const n=e.tens.fill(0,...r),o=function(e,t){for(let r=0;r<t.length;r++)Array.isArray(t[r])?o(e,t[r]):t[r]=e.length>0?e.shift():0};return o(e.tens.toArray(t),n),n},r.round=t=>{const r=e.tens.init();if(Array.isArray(t)){for(let n=0;n<t.length;n++)r[n]=e.tens.round(t[n]);return r}return Math.round(t)},r.scl=(t,r)=>{const n=e.tens.init();if(Array.isArray(t)){for(let o=0;o<t.length;o++)n[o]=e.tens.scl(t[o],r);return n}return t*r},r.size=t=>{if(Array.isArray(t)){let r=[t.length];return Array.isArray(t[0])&&(r=r.concat(e.tens.size(t[0]))),r}return[]},r.sub=(t,r)=>{const n=e.tens.init();if(Array.isArray(t)&&Array.isArray(r)){for(let o=0;o<Math.max(t.length,r.length);o++)n[o]=e.tens.sub(void 0!==t[o]?t[o]:0,void 0!==r[o]?r[o]:0);return n}return t-r},r.toArray=e=>{const t=[],r=function(e){for(let n=0;n<e.length;n++)Array.isArray(e[n])?r(e[n]):t.push(e[n])};return r(e),t},r.toMatrix=t=>{const r=e.matr.init(),n=function(e,t){for(let r=0;r<e.length;r++)Array.isArray(e[r])?n(e[r],t):t.push(e[r])},o=e.matr.init();n(t,o);const i=t.length||1;for(let e=0;e<i;e++)r.push(o.slice(e*o.length/i,(e+1)*o.length/i));return r},r.toObject=t=>{if(Array.isArray(t)){const r={};for(let n=0;n<t.length;n++)r["_"+(n+1)]=e.tens.toObject(t[n]);return r}return t},r.toSet=t=>e.abal.set(e.tens.toArray(t)),r.toString=(t,r=0)=>{if(Array.isArray(t[0])){let n="\t".repeat(r)+"[\n";for(let o=0;o<t.length;o++)n+=e.tens.toString(t[o],r+1);return n+="\t".repeat(r)+"]\n",n}{let e="\t".repeat(r)+"[ ";for(let r=0;r<t.length;r++)e+=t[r].toString()+" ";return e+="]\n",e}},r.toTypedArray=(t,r="float32")=>{const n=e.tens.toArray(t);if("int8"===r)return new Int8Array(n);if("int16"===r)return new Int16Array(n);if("int32"===r)return new Int32Array(n);if("float32"===r)return new Float32Array(n);if("float64"===r)return new Float64Array(n);if("bigint64"===r)return new BigInt64Array(n.map(e=>BigInt(Math.floor(e))));throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".')},r.toVector=(t,r,n=0)=>{const o=e.tens.toArray(t);if(2===r)return e.vect.init(o[n],o[n+1]);if(3===r)return e.vect.init(o[n],o[n+1],o[n+2]);if(4===r)return e.vect.init(o[n],o[n+1],o[n+2],o[n+3]);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},r.transpose=t=>e.tens.resize(t,...e.tens.size(t).reverse()),r.zero=(...e)=>{e=Array.isArray(e[0])?e[0]:e;const t=function(e){if(0===e.length)return 0;const r=e[0],n=e.slice(1),o=[];for(let e=0;e<r;e++)o[e]=t(n);return o};return t(e)}}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){t.arccos=t=>1===t?0:-1===t?e.PI():t>-1&&t<1?t>=0?2*e.trig.arctan(e.real.sqrt((1-t)/(1+t))):e.PI()-2*e.trig.arctan(e.real.sqrt((1+t)/(1-t))):void 0,t.arccosh=e=>e>=1?Math.log(e+Math.sqrt(e*e-1)):void 0,t.arccot=t=>e.PI(.5)-e.trig.arctan(t),t.arccoth=e=>e<-1||e>1?Math.log((e+1)/(e-1))/2:void 0,t.arccsc=t=>1===t?e.PI(.5):-1===t?e.PI(-.5):t>1||t<-1?e.trig.arcsin(1/t):void 0,t.arccsch=e=>0!==e?Math.log(1/e+Math.sqrt(1/(e*e)+1)):void 0,t.arcsec=t=>1===t?0:-1===t?e.PI():t>1||t<-1?e.trig.arccos(1/t):void 0,t.arcsech=e=>e>0&&e<=1?Math.log(1/e+Math.sqrt(1/(e*e)-1)):void 0,t.arcsin=t=>{if(t>-1&&t<1){const r=1-t*t,n=e.real.sqrt(r<0?0:r);return 2*e.trig.arctan(t/(1+n))}return 1===t?e.PI(.5):-1===t?e.PI(-.5):void 0},t.arcsinh=e=>Math.log(e+Math.sqrt(e*e+1)),t.arctan=t=>{const r=e=>{const t=e*e,r=t*e,n=r*t,o=n*t,i=o*t,a=i*t,s=a*t,l=s*t,u=l*t,m=u*t,f=m*t,c=f*t,p=c*t,d=p*t,h=d*t,y=h*t,b=y*t,g=b*t,w=g*t;return e-r/3+n/5-o/7+i/9-a/11+s/13-l/15+u/17-m/19+f/21-c/23+p/25-d/27+h/29-y/31+b/33-g/35+w/37-w*t/39};if(0===t)return 0;if(!Number.isFinite(t))return t>0?e.PI(.5):e.PI(-.5);const n=t<0?-1:1,o=Math.abs(t),i=Math.SQRT2-1,a=Math.SQRT2+1,s=.25*Math.PI,l=.5*Math.PI;let u;return u=o<=i?r(o):o<=a?s+r((o-1)/(o+1)):l-r(1/o),n*u},t.arctanh=e=>e>-1&&e<1?Math.log((1+e)/(1-e))/2:void 0,t.arctan2=(t,r)=>0===r?t>0?e.PI(.5):t<0?e.PI(-.5):0:r>0&&t>=0?e.trig.arctan(t/r):r<0&&t>=0?e.trig.arctan(t/r)+e.PI():r<0&&t<0?e.trig.arctan(t/r)-e.PI():e.trig.arctan(t/r),t.cos=t=>{const r=e.trig.coterminal(t),n=r*r,o=n*n,i=o*n,a=o*o,s=i*o,l=a*o,u=a*i;return 1-n/2+o/24-i/720+a/40320-s/3628800+l/479001600-u/87178291200+a*a/20922789888e3-s*a/6402373705728e3+s*s/243290200817664e4-l*s/11240007277776077e5+l*l/6204484017332394e8-u*l/40329146112660565e10+u*u/30488834461171384e13},t.cosh=t=>(Math.pow(e.E(),t)+Math.pow(e.E(),-t))/2,t.cot=t=>1/e.trig.tan(t),t.coth=t=>1/e.trig.tanh(t),t.coterminal=t=>t%(2*e.PI()),t.csc=t=>1/e.trig.sin(t),t.csch=t=>1/e.trig.sinh(t),t.sec=t=>1/e.trig.cos(t),t.sech=t=>1/e.trig.cosh(t),t.sin=t=>{const r=e.trig.coterminal(t),n=r*r,o=n*r,i=o*n,a=i*n,s=a*n,l=s*n,u=l*n,m=u*n,f=m*n,c=f*n,p=c*n,d=p*n,h=d*n,y=h*n;return r-o/6+i/120-a/5040+s/362880-l/39916800+u/6227020800-m/1307674368e3+f/355687428096e3-c/0x1b02b9306890000+p/5109094217170944e4-d/2585201673888498e7+h/15511210043330986e9-y/10888869450418352e12+y*n/8.841761993739701e30},t.sinh=t=>(Math.pow(e.E(),t)-Math.pow(e.E(),-t))/2,t.tan=t=>e.trig.sin(t)/e.trig.cos(t),t.tanh=t=>e.trig.sinh(t)/e.trig.cosh(t),t.toDeg=t=>t*(180/e.PI()),t.toRad=t=>t*(e.PI()/180)}(t=e.trig||(e.trig={}))}(Chalkboard||(Chalkboard={})),function(e){let t;!function(t){const r=t=>{const r=(e,t,r,n)=>void 0===r&&void 0===n?{x:e,y:t}:void 0===n?{x:e,y:t,z:r}:{x:e,y:t,z:r,w:n},n=t;if(n&&"number"==typeof n.x&&"number"==typeof n.y)return t;if(Array.isArray(t))if(t.length>0&&Array.isArray(t[0])){const n=t,o=e.matr.rows(n),i=e.matr.cols(n);if(1===i){if(2===o)return r(n[0][0],n[1][0]);if(3===o)return r(n[0][0],n[1][0],n[2][0]);if(4===o)return r(n[0][0],n[1][0],n[2][0],n[3][0])}else if(1===o){if(2===i)return r(n[0][0],n[0][1]);if(3===i)return r(n[0][0],n[0][1],n[0][2]);if(4===i)return r(n[0][0],n[0][1],n[0][2],n[0][3])}}else{const e=t;if(2===e.length)return r(e[0],e[1]);if(3===e.length)return r(e[0],e[1],e[2]);if(4===e.length)return r(e[0],e[1],e[2],e[3])}if(t instanceof Float32Array||t instanceof Float64Array){const e=t;if(2===e.length)return r(e[0],e[1]);if(3===e.length)return r(e[0],e[1],e[2]);if(4===e.length)return r(e[0],e[1],e[2],e[3])}if("string"==typeof t)try{const e=JSON.parse(t);if(e&&"object"==typeof e&&"number"==typeof e.x&&"number"==typeof e.y)return r(e.x,e.y,void 0!==e.z?e.z:void 0,void 0!==e.w?e.w:void 0)}catch(e){const n=t.trim();if(n.startsWith("(")&&n.endsWith(")")){const e=n.substring(1,n.length-1).split(",").map(e=>parseFloat(e.trim()));if(e.length>=2&&e.every(e=>!isNaN(e))){if(2===e.length)return r(e[0],e[1]);if(3===e.length)return r(e[0],e[1],e[2]);if(4===e.length)return r(e[0],e[1],e[2],e[3])}}}throw new TypeError(`Invalid ChalkboardVector input: ${JSON.stringify(t)}`)};t.absolute=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.vect.init(Math.abs(t.x),Math.abs(t.y));if(e.vect.isDimensionOf(t,3))return e.vect.init(Math.abs(t.x),Math.abs(t.y),Math.abs(t.z));if(e.vect.isDimensionOf(t,4))return e.vect.init(Math.abs(t.x),Math.abs(t.y),Math.abs(t.z),Math.abs(t.w));throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.add=(t,n)=>{if(t=r(t),n=r(n),e.vect.isDimensionOf(t,2)&&e.vect.isDimensionOf(n,2))return e.vect.init(t.x+n.x,t.y+n.y);if(e.vect.isDimensionOf(t,3)&&e.vect.isDimensionOf(n,3))return e.vect.init(t.x+n.x,t.y+n.y,t.z+n.z);if(e.vect.isDimensionOf(t,4)&&e.vect.isDimensionOf(n,4))return e.vect.init(t.x+n.x,t.y+n.y,t.z+n.z,t.w+n.w);throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.ang=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.trig.arctan2(t.y,t.x);if(e.vect.isDimensionOf(t,3)){const r=e.vect.mag(t);return[Math.acos(t.x/r),Math.acos(t.y/r),Math.acos(t.z/r)]}if(e.vect.isDimensionOf(t,4)){const r=e.vect.mag(t);return[Math.acos(t.x/r),Math.acos(t.y/r),Math.acos(t.z/r),Math.acos(t.w/r)]}throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.angBetween=(t,r)=>Math.acos(e.vect.dot(t,r)/(e.vect.mag(t)*e.vect.mag(r))),t.constrain=(t,n=[0,1])=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.vect.init(e.numb.constrain(t.x,n),e.numb.constrain(t.y,n));if(e.vect.isDimensionOf(t,3))return e.vect.init(e.numb.constrain(t.x,n),e.numb.constrain(t.y,n),e.numb.constrain(t.z,n));if(e.vect.isDimensionOf(t,4))return e.vect.init(e.numb.constrain(t.x,n),e.numb.constrain(t.y,n),e.numb.constrain(t.z,n),e.numb.constrain(t.w,n));throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.copy=t=>{t=r(t);const o=Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t));return"vector"===n?o:"array"===n?e.vect.toArray(o):"float32array"===n?new Float32Array(e.vect.toArray(o)):"float64array"===n?new Float64Array(e.vect.toArray(o)):"matrix"===n?e.vect.toMatrix(o):"string"===n?e.vect.toString(o):"json"===n?JSON.stringify(o):o},t.cross=(t,n)=>{if(t=r(t),n=r(n),e.vect.isDimensionOf(t,2)&&e.vect.isDimensionOf(n,2))return e.vect.init(0,0,t.x*n.y-t.y*n.x);if(e.vect.isDimensionOf(t,3)&&e.vect.isDimensionOf(n,3))return e.vect.init(t.y*n.z-t.z*n.y,t.z*n.x-t.x*n.z,t.x*n.y-t.y*n.x);throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2 or 3 dimensions.')},t.dimension=e=>{try{const t=r(e);if("number"==typeof t.x&&"number"==typeof t.y&&void 0===t.z&&void 0===t.w)return 2;if("number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.z&&void 0===t.w)return 3;if("number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.z&&"number"==typeof t.w)return 4}catch{const t=e;if("vector2d"===t.type)return 2;if("vector3d"===t.type)return 3;if("vector4d"===t.type)return 4}throw new TypeError('Parameter "vectORvectfield" must be a vector or vector field with 2, 3, or 4 dimensions.')},t.dist=(t,n)=>{if(t=r(t),n=r(n),e.vect.isDimensionOf(t,2)&&e.vect.isDimensionOf(n,2))return e.real.sqrt((n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y));if(e.vect.isDimensionOf(t,3)&&e.vect.isDimensionOf(n,3))return e.real.sqrt((n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)+(n.z-t.z)*(n.z-t.z));if(e.vect.isDimensionOf(t,4)&&e.vect.isDimensionOf(n,4))return e.real.sqrt((n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)+(n.z-t.z)*(n.z-t.z)+(n.w-t.w)*(n.w-t.w));throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.distsq=(t,n)=>{if(t=r(t),n=r(n),e.vect.isDimensionOf(t,2)&&e.vect.isDimensionOf(n,2))return(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y);if(e.vect.isDimensionOf(t,3)&&e.vect.isDimensionOf(n,3))return(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)+(n.z-t.z)*(n.z-t.z);if(e.vect.isDimensionOf(t,4)&&e.vect.isDimensionOf(n,4))return(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)+(n.z-t.z)*(n.z-t.z)+(n.w-t.w)*(n.w-t.w);throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.dot=(t,n)=>{if(t=r(t),n=r(n),e.vect.isDimensionOf(t,2)&&e.vect.isDimensionOf(n,2))return t.x*n.x+t.y*n.y;if(e.vect.isDimensionOf(t,3)&&e.vect.isDimensionOf(n,3))return t.x*n.x+t.y*n.y+t.z*n.z;if(e.vect.isDimensionOf(t,4)&&e.vect.isDimensionOf(n,4))return t.x*n.x+t.y*n.y+t.z*n.z+t.w*n.w;throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.empty=t=>{const r=null;if(2===t)return e.vect.init(r,r);if(3===t)return e.vect.init(r,r,r);if(4===t)return e.vect.init(r,r,r,r);throw new TypeError('Parameter "dimension" must be 2, 3, or 4.')},t.field=(e,t,r,n)=>void 0===r&&void 0===n?{rule:[e,t],field:"real",type:"vector2d"}:void 0===n?{rule:[e,t,r],field:"real",type:"vector3d"}:{rule:[e,t,r,n],field:"real",type:"vector4d"},t.fill=(t,r)=>{if(2===r)return e.vect.init(t,t);if(3===r)return e.vect.init(t,t,t);if(4===r)return e.vect.init(t,t,t,t);throw new TypeError('Parameter "dimension" must be 2, 3, or 4.')},t.fromAlternateToCartesian=(t,n)=>{if(t=r(t),"polar"===n&&e.vect.isDimensionOf(t,2))return e.vect.init(t.x*e.trig.cos(t.y),t.y*e.trig.sin(t.y));if("bipolar"===n&&e.vect.isDimensionOf(t,2))return e.vect.init((t.x*t.x-t.y*t.y)/4,e.real.sqrt(16*t.x*t.x-(t.x*t.x-t.y*t.y+4)*(t.x*t.x-t.y*t.y+4)));if("cylindrical"===n&&e.vect.isDimensionOf(t,3))return e.vect.init(t.x*e.trig.cos(t.y),t.x*e.trig.sin(t.y),t.z);if("spherical"===n&&e.vect.isDimensionOf(t,3))return e.vect.init(t.x*e.trig.sin(t.z)*e.trig.cos(t.y),t.x*e.trig.sin(t.z)*e.trig.sin(t.y),t.x*e.trig.cos(t.z));throw new TypeError('Parameter "type" must be "polar", "bipolar", "cylindrical", or "spherical".')},t.fromAngle=(t,r)=>void 0===r?e.vect.init(e.trig.cos(t),e.trig.sin(t)):e.vect.init(e.trig.cos(t)*e.trig.cos(r),e.trig.sin(t)*e.trig.cos(r),e.trig.sin(r)),t.fromCartesianToAlternate=(t,n)=>{if(t=r(t),"polar"===n&&e.vect.isDimensionOf(t,2))return e.vect.init(e.vect.mag(t),e.vect.ang(t));if("bipolar"===n&&e.vect.isDimensionOf(t,2))return e.vect.init((t.x+1)*(t.x+1)+t.y*t.y,(t.x-1)*(t.x-1)+t.y*t.y);if("cylindrical"===n&&e.vect.isDimensionOf(t,3))return e.vect.init(e.vect.mag(e.vect.init(t.x,t.y)),e.vect.ang(e.vect.init(t.x,t.y)),t.z);if("spherical"===n&&e.vect.isDimensionOf(t,3))return e.vect.init(e.vect.mag(t),e.vect.ang(e.vect.init(t.x,t.y)),e.vect.ang(t)[2]);throw new TypeError('Parameter "type" must be "polar", "bipolar", "cylindrical", or "spherical".')},t.fromField=(t,n)=>{const o=t.rule,i=n=r(n);if("vector2d"===t.type)return e.vect.init(o[0](i.x,i.y),o[1](i.x,i.y));if("vector3d"===t.type)return e.vect.init(o[0](i.x,i.y,i.z),o[1](i.x,i.y,i.z),o[2](i.x,i.y,i.z));if("vector4d"===t.type)return e.vect.init(o[0](i.x,i.y,i.z,i.w),o[1](i.x,i.y,i.z,i.w),o[2](i.x,i.y,i.z,i.w),o[3](i.x,i.y,i.z,i.w));throw new TypeError("Chalkboard.vect.fromField: Property 'type' of 'vectfield' must be 'vector2d', 'vector3d', or 'vector4d'.")},t.fromVector=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.vect.init(t.x,t.y,0);if(e.vect.isDimensionOf(t,3))return e.vect.init(t.x,t.y,t.z,0);if(e.vect.isDimensionOf(t,4))return e.vect.init(t.x,t.y);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.init=(t,r,o,i)=>{let a;return a=void 0===o&&void 0===i?{x:t,y:r}:void 0===i?{x:t,y:r,z:o}:{x:t,y:r,z:o,w:i},"vector"===n?a:"array"===n?e.vect.toArray(a):"float32array"===n?new Float32Array(e.vect.toArray(a)):"float64array"===n?new Float64Array(e.vect.toArray(a)):"matrix"===n?e.vect.toMatrix(a):"string"===n?e.vect.toString(a):"json"===n?JSON.stringify(a):a},t.interpolate=(t,n,o,i,a)=>{if(t=r(t),e.vect.isDimensionOf(t,2)&&void 0===i&&void 0===a)return e.vect.init((n*t.x+o*t.y)/(n+o),(n*t.x+o*t.y)/(n+o));if(e.vect.isDimensionOf(t,3)&&"number"==typeof i&&void 0===a)return e.vect.init((n*t.x+o*t.y+i*t.z)/(n+o+i),(n*t.x+o*t.y+i*t.z)/(n+o+i),(n*t.x+o*t.y+i*t.z)/(n+o+i));if(e.vect.isDimensionOf(t,4)&&"number"==typeof i&&"number"==typeof a)return e.vect.init((n*t.x+o*t.y+i*t.z+a*t.w)/(n+o+i+a),(n*t.x+o*t.y+i*t.z+a*t.w)/(n+o+i+a),(n*t.x+o*t.y+i*t.z+a*t.w)/(n+o+i+a),(n*t.x+o*t.y+i*t.z+a*t.w)/(n+o+i+a));throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.isApproxEqual=(t,n,o=1e-6)=>{if(t=r(t),n=r(n),e.vect.isDimensionEqual(t,n)){if(e.vect.isDimensionOf(t,2))return e.numb.isApproxEqual(t.x,n.x,o)&&e.numb.isApproxEqual(t.y,n.y,o);if(e.vect.isDimensionOf(t,3))return e.numb.isApproxEqual(t.x,n.x,o)&&e.numb.isApproxEqual(t.y,n.y,o)&&e.numb.isApproxEqual(t.z,n.z,o);if(e.vect.isDimensionOf(t,4))return e.numb.isApproxEqual(t.x,n.x,o)&&e.numb.isApproxEqual(t.y,n.y,o)&&e.numb.isApproxEqual(t.z,n.z,o)&&e.numb.isApproxEqual(t.w,n.w,o);throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')}return!1},t.isDimensionEqual=(t,r)=>e.vect.dimension(t)===e.vect.dimension(r),t.isDimensionOf=(t,n)=>{try{const o=r(t);if(2===n)return 2===e.vect.dimension(o);if(3===n)return 3===e.vect.dimension(o);if(4===n)return 4===e.vect.dimension(o)}catch{const r=t;if(2===n)return 2===e.vect.dimension(r);if(3===n)return 3===e.vect.dimension(r);if(4===n)return 4===e.vect.dimension(r)}throw new TypeError('Parameter "dimension" must be 2, 3, or 4.')},t.isEqual=(t,n)=>{if(t=r(t),n=r(n),e.vect.isDimensionEqual(t,n)){if(e.vect.isDimensionOf(t,2))return t.x===n.x&&t.y===n.y;if(e.vect.isDimensionOf(t,3))return t.x===n.x&&t.y===n.y&&t.z===n.z;if(e.vect.isDimensionOf(t,4))return t.x===n.x&&t.y===n.y&&t.z===n.z&&t.w===n.w;throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')}return!1},t.isNormalized=t=>e.numb.isApproxEqual(e.vect.magsq(t),1),t.isOrthogonal=(t,r)=>e.numb.isApproxEqual(e.vect.dot(t,r),0),t.isParallel=(t,r)=>e.numb.isApproxEqual(e.vect.dot(t,r),e.vect.mag(t)*e.vect.mag(r)),t.isZero=t=>e.vect.isApproxEqual(t,e.vect.zero(e.vect.dimension(t))),t.mag=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.real.sqrt(t.x*t.x+t.y*t.y);if(e.vect.isDimensionOf(t,3))return e.real.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);if(e.vect.isDimensionOf(t,4))return e.real.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.magset=(t,r)=>e.vect.scl(e.vect.normalize(t),r),t.magsq=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return t.x*t.x+t.y*t.y;if(e.vect.isDimensionOf(t,3))return t.x*t.x+t.y*t.y+t.z*t.z;if(e.vect.isDimensionOf(t,4))return t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w;throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')};let n="vector";t.modeConfig=e=>{const t=e.toLowerCase();if(-1===["vector","array","float32array","float64array","matrix","string","json"].indexOf(t))throw new Error('The mode must be "vector", "array", "float32array", "float64array", "matrix", "string", or "json".');n=t},t.negate=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.vect.init(-t.x,-t.y);if(e.vect.isDimensionOf(t,3))return e.vect.init(-t.x,-t.y,-t.z);if(e.vect.isDimensionOf(t,4))return e.vect.init(-t.x,-t.y,-t.z,-t.w);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.normalize=t=>{t=r(t);const n=e.vect.mag(t);if(e.vect.isDimensionOf(t,2))return e.vect.init(t.x/n,t.y/n);if(e.vect.isDimensionOf(t,3))return e.vect.init(t.x/n,t.y/n,t.z/n);if(e.vect.isDimensionOf(t,4))return e.vect.init(t.x/n,t.y/n,t.z/n,t.w/n);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.oproj=(t,r)=>e.vect.sub(t,e.vect.proj(t,r)),t.print=t=>{console.log(e.vect.toString(t))},t.proj=(t,r)=>e.vect.scl(r,e.vect.dot(t,r)/e.vect.dot(r,r)),t.random=(t,r=0,n=1)=>{if(2===t)return e.vect.init(e.numb.random(r,n),e.numb.random(r,n));if(3===t)return e.vect.init(e.numb.random(r,n),e.numb.random(r,n),e.numb.random(r,n));if(4===t)return e.vect.init(e.numb.random(r,n),e.numb.random(r,n),e.numb.random(r,n),e.numb.random(r,n));throw new TypeError('Parameter "dimension" must be 2, 3, or 4.')},t.reciprocate=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.vect.init(1/t.x,1/t.y);if(e.vect.isDimensionOf(t,3))return e.vect.init(1/t.x,1/t.y,1/t.z);if(e.vect.isDimensionOf(t,4))return e.vect.init(1/t.x,1/t.y,1/t.z,1/t.w);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.reflect=(t,r)=>e.vect.sub(t,e.vect.scl(r,2*e.vect.dot(t,r))),t.refract=(t,r,n)=>{if(n>0){const o=e.vect.scl(e.vect.sub(t,e.vect.scl(r,e.vect.dot(t,r))),n),i=e.vect.scl(r,-e.real.sqrt(1-n*n*(1-e.vect.dot(t,r)*e.vect.dot(t,r))));return e.vect.add(o,i)}throw new RangeError('Parameter "refractiveIndex" must be of type "number" greater than 0.')},t.round=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.vect.init(Math.round(t.x),Math.round(t.y));if(e.vect.isDimensionOf(t,3))return e.vect.init(Math.round(t.x),Math.round(t.y),Math.round(t.z));if(e.vect.isDimensionOf(t,4))return e.vect.init(Math.round(t.x),Math.round(t.y),Math.round(t.z),Math.round(t.w));throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.scalarQuadruple=(t,r,n,o)=>e.vect.dot(e.vect.cross(t,r),e.vect.cross(n,o)),t.scalarTriple=(t,r,n)=>e.vect.dot(t,e.vect.cross(r,n)),t.scl=(t,n)=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.vect.init(t.x*n,t.y*n);if(e.vect.isDimensionOf(t,3))return e.vect.init(t.x*n,t.y*n,t.z*n);if(e.vect.isDimensionOf(t,4))return e.vect.init(t.x*n,t.y*n,t.z*n,t.w*n);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.slope=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return t.y/t.x;if(e.vect.isDimensionOf(t,3))return t.z/e.real.sqrt(t.x*t.x+t.y*t.y);if(e.vect.isDimensionOf(t,4))return t.w/e.real.sqrt(t.x*t.x+t.y*t.y+t.z*t.z);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.sub=(t,n)=>{if(t=r(t),n=r(n),e.vect.isDimensionOf(t,2)&&e.vect.isDimensionOf(n,2))return e.vect.init(t.x-n.x,t.y-n.y);if(e.vect.isDimensionOf(t,3)&&e.vect.isDimensionOf(n,3))return e.vect.init(t.x-n.x,t.y-n.y,t.z-n.z);if(e.vect.isDimensionOf(t,4)&&e.vect.isDimensionOf(n,4))return e.vect.init(t.x-n.x,t.y-n.y,t.z-n.z,t.w-n.w);throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.toArray=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return[t.x,t.y];if(e.vect.isDimensionOf(t,3))return[t.x,t.y,t.z];if(e.vect.isDimensionOf(t,4))return[t.x,t.y,t.z,t.w];throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.toComplex=t=>(t=r(t),e.comp.init(t.x,t.y)),t.toMatrix=(t,n=0)=>{if(t=r(t),e.vect.isDimensionOf(t,2)){if(0===n)return e.matr.init([t.x],[t.y]);if(1===n)return e.matr.init([t.x,t.y]);throw new TypeError('Parameter "axis" must be 0 or 1.')}if(e.vect.isDimensionOf(t,3)){if(0===n)return e.matr.init([t.x],[t.y],[t.z]);if(1===n)return e.matr.init([t.x,t.y,t.z]);throw new TypeError('Parameter "axis" must be 0 or 1.')}if(e.vect.isDimensionOf(t,4)){if(0===n)return e.matr.init([t.x],[t.y],[t.z],[t.w]);if(1===n)return e.matr.init([t.x,t.y,t.z,t.w]);throw new TypeError('Parameter "axis" must be 0 or 1.')}throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.toQuaternion=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return e.quat.init(t.x,t.y,0,0);if(e.vect.isDimensionOf(t,3))return e.quat.init(0,t.x,t.y,t.z);if(e.vect.isDimensionOf(t,4))return e.quat.init(t.x,t.y,t.z,t.w);throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.toString=t=>{if(t=r(t),e.vect.isDimensionOf(t,2))return"("+t.x.toString()+", "+t.y.toString()+")";if(e.vect.isDimensionOf(t,3))return"("+t.x.toString()+", "+t.y.toString()+", "+t.z.toString()+")";if(e.vect.isDimensionOf(t,4))return"("+t.x.toString()+", "+t.y.toString()+", "+t.z.toString()+", "+t.w.toString()+")";throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.')},t.toTensor=(t,...n)=>(t=r(t),Array.isArray(n[0])&&(n=n[0]),e.tens.resize(e.vect.toMatrix(t),...n)),t.toTypedArray=(t,n="float32")=>{t=r(t);const o=e.vect.toArray(t);if("int8"===n)return new Int8Array(o);if("int16"===n)return new Int16Array(o);if("int32"===n)return new Int32Array(o);if("float32"===n)return new Float32Array(o);if("float64"===n)return new Float64Array(o);if("bigint64"===n)return new BigInt64Array(o.map(e=>BigInt(Math.floor(e))));throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".')},t.vectorQuadruple=(t,r,n,o)=>e.vect.cross(e.vect.cross(t,r),e.vect.cross(n,o)),t.vectorTriple=(t,r,n)=>e.vect.cross(t,e.vect.cross(r,n)),t.zero=t=>{if(2===t)return e.vect.init(0,0);if(3===t)return e.vect.init(0,0,0);if(4===t)return e.vect.init(0,0,0,0);throw new TypeError('Parameter "dimension" must be either 2, 3, or 4.')}}(t=e.vect||(e.vect={}))}(Chalkboard||(Chalkboard={}));
|