mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
2 lines • 600 kB
JavaScript
/*! For license information please see mathjslab.node.cjs2022.js.LICENSE.txt */
(()=>{var __webpack_modules__={5(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LAPACKunused=t.LAPACKConfigKeyTable=void 0;const n=r(845),i=r(679),o=r(115),s=r(554),a=r(610),l=r(152),c=r(227);t.LAPACKConfigKeyTable=["maxIterationFactor"];const u={maxIterationFactor:1e3};class m{static defaultSettings=Object.assign({},u);static settings=m.defaultSettings;static set=e=>{Object.entries(e).forEach(e=>{if(!t.LAPACKConfigKeyTable.includes(e[0]))throw new Error(`LAPACK.set: invalid configuration parameter: ${e[0]}`);c.LAPACK.settings[e[0]]=e[1]})};static laswp=(e,t,r,n,i,o,s)=>{const a=e.dimension[0],l=e.dimension[1],c=2===e.dimension.length?1:e.dimension.slice(2).reduce((e,t)=>e*t,1),u=void 0===o?0:o,m=void 0===s?l-1:s;if(!n||0===n.length)return;const p=0===Math.min(...n);if(i>0)for(let o=t;o<=r;o+=i){const t=o-1,r=n[o-1],i=p?r:r-1;if(i!==t)for(let r=0;r<c;r++){const n=r*a+t,o=r*a+i;for(let t=u;t<=m;t++){const r=e.array[n][t];e.array[n][t]=e.array[o][t],e.array[o][t]=r}}}else for(let o=t;o>=r;o+=i){const t=o-1,r=n[o-1],i=p?r:r-1;if(i!==t)for(let r=0;r<c;r++){const n=r*a+t,o=r*a+i;for(let t=u;t<=m;t++){const r=e.array[n][t];e.array[n][t]=e.array[o][t],e.array[o][t]=r}}}};static laswp_rows=(e,t,r)=>{const n=t+1,i=n,o=[];o[n-1]=r+1,m.laswp(e,n,i,o,1)};static laswp_cols=(e,t,r)=>{const n=e.dimension,i=n[0]*(2===n.length?1:n.slice(2).reduce((e,t)=>e*t,1));for(let n=0;n<i;n++){const i=e.array[n][t];e.array[n][t]=e.array[n][r],e.array[n][r]=i}};static eye=(...e)=>{const t=e.flat(),r=t[0],i=t[1];if(2===t.length)return Array.from({length:r},(e,t)=>Array.from({length:i},(e,r)=>t===r?n.Complex.one():n.Complex.zero()));{const e=t.slice(2).reduce((e,t)=>e*t,1);return Array.from({length:r*e},(e,t)=>{const o=t%r;return Array.from({length:i},(e,t)=>o===t?n.Complex.one():n.Complex.zero())})}};static zeros=(...e)=>{const t=e.flat();return Array.from({length:t[0]*t.slice(2).reduce((e,t)=>e*t,1)},e=>Array.from({length:t[1]},e=>n.Complex.zero()))};static lassq=e=>{const t=e.dimension[0],r=e.dimension[1];let i=n.Complex.zero(),o=n.Complex.one();for(let s=0;s<t;s++)for(let t=0;t<r;t++){const r=e.array[s][t];if(!n.Complex.realIsZero(r)){const e=n.Complex.abs(r);if(n.Complex.lt(i,e)){if(!n.Complex.realIsZero(i)){const t=n.Complex.rdiv(i,e);n.Complex.mulAndSumTo(o,o,n.Complex.mul(t,t))}i=e}else{const t=n.Complex.rdiv(e,i);n.Complex.mulAndSumTo(o,t,t)}}}return{scale:i,sumsq:o}};static lange=(e,t)=>{const r=t.dimension[0],i=t.dimension[1];switch(e){case"F":{const{scale:e,sumsq:r}=c.LAPACK.lassq(t);return n.Complex.realIsZero(e)?n.Complex.zero():n.Complex.mul(e,n.Complex.sqrt(r))}case"M":{let e=n.Complex.zero();for(let o=0;o<r;o++)for(let r=0;r<i;r++){const i=n.Complex.abs(t.array[o][r]);n.Complex.lt(e,i)&&(e=i)}return e}default:throw new Error(`lange: norm '${e}' not implemented`)}};static triu_inplace=e=>{const t=e.dimension.length>2?e.dimension.slice(2).reduce((e,t)=>e*t,1):1,r=e.dimension[0];for(let i=0;i<t;i++){const t=i*r;for(let r=0;r<e.dimension[0];r++){const i=e.array[t+r];for(let t=0;t<Math.min(r,e.dimension[1]);t++)i[t]=n.Complex.zero()}}i.MultiArray.setType(e)};static tril_inplace=e=>{const t=e.dimension.length>2?e.dimension.slice(2).reduce((e,t)=>e*t,1):1,r=e.dimension[0];for(let i=0;i<t;i++){const t=i*r;for(let r=0;r<e.dimension[0];r++){const i=e.array[t+r];for(let t=r+1;t<e.dimension[1];t++)i[t]=n.Complex.zero()}}i.MultiArray.setType(e)};static trsm_left_upper_block=(e,t,r)=>{const i=e.dimension[1];for(let o=t+r;o<i;o++)for(let i=r-1;i>=0;i--){const s=t+i;let a=e.array[s][o];for(let l=i+1;l<r;l++){const r=e.array[s][t+l],i=e.array[t+l][o];a=n.Complex.sub(a,n.Complex.mul(r,i))}const l=e.array[s][t+i];e.array[s][o]=n.Complex.rdiv(a,l)}};static lapmt_matrix=e=>{const t=e.length,r=new i.MultiArray([t,t]);for(let i=0;i<t;i++){const t=e[i];r.array[t][i]=n.Complex.one()}return i.MultiArray.setType(r),r};static larfg_vector=e=>{const t=e.length;if(0===t)return{tau:n.Complex.zero(),v:[],phi:n.Complex.one(),alpha:n.Complex.zero()};const r=e[0];let i=n.Complex.zero();for(let r=1;r<t;r++){const t=n.Complex.abs(e[r]);n.Complex.mulAndSumTo(i,t,t)}const o=n.Complex.abs(r),s=n.Complex.realIsZero(o)?n.Complex.one():n.Complex.rdiv(r,o);if(1===t||n.Complex.realIsZero(n.Complex.abs(i))){const e=n.Complex.zero(),i=new Array(t);i[0]=n.Complex.one();for(let e=1;e<t;e++)i[e]=n.Complex.zero();return{tau:e,v:i,phi:s,alpha:r}}{const o=n.Complex.sqrt(n.Complex.add(n.Complex.mul(r,n.Complex.conj(r)),i)),a=n.Complex.mul(n.Complex.neg(s),o),l=n.Complex.rdiv(n.Complex.sub(a,r),a),c=n.Complex.sub(r,a),u=new Array(t);u[0]=n.Complex.one();for(let r=1;r<t;r++)u[r]=n.Complex.rdiv(e[r],c);return{tau:l,v:u,phi:s,alpha:a}}};static larfg_apply=(e,t,r)=>{let i;i="L"===e?t.dimension[0]:t.dimension[1];const{tau:o,v:s,alpha:a}=c.LAPACK.larfg(e,t,i,r);return n.Complex.realIsZero(n.Complex.abs(o))||c.LAPACK.larf(e,t,s,o,r,r),{tau:o,v:s,alpha:a}};static larfg_left_nd=(e,t)=>{const r=e.dimension,o=r.length>2?r.slice(2).reduce((e,t)=>e*t,1):1,s=r[0],a=r[0],{tau:l,v:u,alpha:m}=c.LAPACK.larfg("L",e,s,t);if(n.Complex.realIsZero(n.Complex.abs(l)))return{tau:l,v:u,alpha:m};for(let i=0;i<o;i++){const o=i*a;for(let i=0;i<r[1];i++){let r=n.Complex.zero();for(let a=t;a<s;a++){const s=o+a;r=n.Complex.add(r,n.Complex.mul(n.Complex.conj(u[a-t]),e.array[s][i]))}r=n.Complex.mul(l,r);for(let a=t;a<s;a++){const s=o+a;e.array[s][i]=n.Complex.sub(e.array[s][i],n.Complex.mul(u[a-t],r))}}}return i.MultiArray.setType(e),{tau:l,v:u,alpha:m}};static larfg_right_nd=(e,t)=>{const r=e.dimension,o=r.length>2?r.slice(2).reduce((e,t)=>e*t,1):1,s=r[1],a=r[0],{tau:l,v:u,alpha:m}=c.LAPACK.larfg("R",e,s,t);if(n.Complex.realIsZero(n.Complex.abs(l)))return{tau:l,v:u,alpha:m};for(let i=0;i<o;i++){const o=i*a;for(let i=0;i<r[0];i++){const r=e.array[o+i];let a=n.Complex.zero();for(let e=t;e<s;e++)a=n.Complex.add(a,n.Complex.mul(r[e],u[e-t]));a=n.Complex.mul(l,a);for(let e=t;e<s;e++)r[e]=n.Complex.sub(r[e],n.Complex.mul(a,n.Complex.conj(u[e-t])))}}return i.MultiArray.setType(e),{tau:l,v:u,alpha:m}};static larfg_nd=(e,t,r)=>"L"===e?m.larfg_left_nd(t,r):m.larfg_right_nd(t,r);static larf_left_block_anterior=(e,t,r,i,o,s)=>{if(n.Complex.realIsZero(n.Complex.abs(r)))return;const a=e.dimension[0],l=e.dimension[1],c="number"==typeof s?Math.min(s,l):l,u=t.length,m=Math.max(0,Math.min(u,a-i));for(let s=o;s<c;s++){let o=n.Complex.zero();for(let r=0;r<m;r++)n.Complex.mulAndSumTo(o,n.Complex.conj(t[r]),e.array[i+r][s]);if(o=n.Complex.mul(r,o),!n.Complex.realIsZero(n.Complex.abs(o)))for(let r=0;r<m;r++){const a=n.Complex.mul(t[r],o);e.array[i+r][s]=n.Complex.sub(e.array[i+r][s],a)}}};static larf_left_block=(e,t,r,s,a,l)=>{if(n.Complex.realIsZero(n.Complex.abs(r)))return;const c=e.dimension[0],u=e.dimension[1],m=t.length;if(s<0||s>=c)throw new Error("larf_left_block: invalid rowStart");if(a<0||a>=u)throw new Error("larf_left_block: invalid colStart");if(m!==c-s)throw new Error("larf_left_block: v length must equal m - rowStart");const p=Math.max(1,Math.floor(l??o.BLAS.settings.blockSize)),h=new i.MultiArray([m,1]);for(let e=0;e<m;e++)h.array[e][0]=t[e];const d=new i.MultiArray([1,m]);for(let e=0;e<m;e++)d.array[0][e]=n.Complex.conj(t[e]);for(let t=a;t<u;t+=p){const a=Math.min(t+p,u)-t,l=new i.MultiArray([m,a]);for(let r=0;r<m;r++)for(let n=0;n<a;n++)l.array[r][n]=e.array[s+r][t+n];const c=new i.MultiArray([1,a]);o.BLAS.gemm_block(d.array,l.array,c.array,n.Complex.one(),n.Complex.zero(),p);for(let e=0;e<a;e++)c.array[0][e]=n.Complex.mul(r,c.array[0][e]);for(let e=0;e<m;e++){const t=h.array[e][0];if(!n.Complex.realIsZero(n.Complex.abs(t)))for(let r=0;r<a;r++){const i=n.Complex.mul(t,c.array[0][r]);l.array[e][r]=n.Complex.sub(l.array[e][r],i)}}for(let r=0;r<m;r++)for(let n=0;n<a;n++)e.array[s+r][t+n]=l.array[r][n]}};static larf_right_conj_block=(e,t,r,s,a,l)=>{if(n.Complex.realIsZero(n.Complex.abs(r)))return;const c=e.dimension[0],u=e.dimension[1],m=t.length;if(s<0||s>=c)throw new Error("larf_right_conj_block: invalid rowStart");if(a<0||a>=u)throw new Error("larf_right_conj_block: invalid colStart");if(a+m>u)throw new Error("larf_right_conj_block: block exceeds matrix columns");const p=Math.max(1,Math.floor(l??o.BLAS.settings.blockSize)),h=new i.MultiArray([m,1]);for(let e=0;e<m;e++)h.array[e][0]=n.Complex.conj(t[e]);for(let l=s;l<c;l+=p){const s=Math.min(l+p,c)-l,u=new i.MultiArray([s,m]);for(let t=0;t<s;t++)for(let r=0;r<m;r++)u.array[t][r]=e.array[l+t][a+r];const d=new i.MultiArray([s,1]);o.BLAS.gemm_block(u.array,h.array,d.array,n.Complex.one(),n.Complex.zero(),p);const x=n.Complex.conj(r);for(let e=0;e<s;e++)d.array[e][0]=n.Complex.mul(x,d.array[e][0]);for(let e=0;e<s;e++){const r=d.array[e][0];if(!n.Complex.realIsZero(n.Complex.abs(r)))for(let i=0;i<m;i++){const o=n.Complex.mul(r,t[i]);u.array[e][i]=n.Complex.sub(u.array[e][i],o)}}for(let t=0;t<s;t++)for(let r=0;r<m;r++)e.array[l+t][a+r]=u.array[t][r]}};static larf_right_conj=(e,t,r,i,o)=>{if(n.Complex.realIsZero(n.Complex.abs(r)))return;const s=e.dimension[0],a=(e.dimension[1],t.length);for(let l=i;l<s;l++){let i=n.Complex.zero();for(let r=0;r<a;r++)n.Complex.mulAndSumTo(i,e.array[l][o+r],n.Complex.conj(t[r]));const s=n.Complex.mul(i,n.Complex.conj(r));if(!n.Complex.realIsZero(n.Complex.abs(s)))for(let r=0;r<a;r++)e.array[l][o+r]=n.Complex.sub(e.array[l][o+r],n.Complex.mul(s,t[r]))}};static larf_right_conj_return=(e,t,r,o,s)=>{if(n.Complex.realIsZero(n.Complex.abs(r)))return i.MultiArray.copy(e);const a=e.dimension[0],l=(e.dimension[1],t.length),c=i.MultiArray.copy(e);for(let i=o;i<a;i++){let o=n.Complex.zero();for(let r=0;r<l;r++)n.Complex.mulAndSumTo(o,e.array[i][s+r],n.Complex.conj(t[r]));const a=n.Complex.mul(o,n.Complex.conj(r));if(!n.Complex.realIsZero(n.Complex.abs(a)))for(let r=0;r<l;r++)c.array[i][s+r]=n.Complex.sub(e.array[i][s+r],n.Complex.mul(a,t[r]))}return i.MultiArray.setType(c),c};static larf_left_nd=(e,t,r,o,s)=>{if(n.Complex.realIsZero(n.Complex.abs(r)))return;const a=e.dimension,l=a.length>2?a.slice(2).reduce((e,t)=>e*t,1):1,c=a[0];for(let i=0;i<l;i++){const l=i*c;for(let i=s;i<a[1];i++){let s=n.Complex.zero();for(let r=0;r<t.length;r++){const a=l+o+r;s=n.Complex.add(s,n.Complex.mul(n.Complex.conj(t[r]),e.array[a][i]))}s=n.Complex.mul(r,s);for(let r=0;r<t.length;r++){const a=l+o+r;e.array[a][i]=n.Complex.sub(e.array[a][i],n.Complex.mul(t[r],s))}}}i.MultiArray.setType(e)};static larf_right_nd=(e,t,r,o,s)=>{if(n.Complex.realIsZero(n.Complex.abs(r)))return;const a=e.dimension,l=a.length>2?a.slice(2).reduce((e,t)=>e*t,1):1,c=a[0];for(let i=0;i<l;i++){const l=i*c;for(let i=o;i<a[0];i++){const o=l+i,a=e.array[o];let c=n.Complex.zero();for(let e=0;e<t.length;e++)c=n.Complex.add(c,n.Complex.mul(a[s+e],t[e]));c=n.Complex.mul(r,c);for(let e=0;e<t.length;e++)a[s+e]=n.Complex.sub(a[s+e],n.Complex.mul(c,n.Complex.conj(t[e])))}}i.MultiArray.setType(e)};static larf_nd=(e,t,r,n,i,o)=>"L"===e?m.larf_left_nd(t,r,n,i,o):m.larf_right_nd(t,r,n,i,o);static getf2=(e,t,r,i)=>{const o=e.dimension[0],s=e.dimension[1],a=Math.min(t+r,Math.min(o,s));for(let r=t;r<a;r++){let t=r,a=n.Complex.abs(e.array[r][r]);for(let i=r+1;i<o;i++){const o=n.Complex.abs(e.array[i][r]);n.Complex.toBoolean(n.Complex.gt(o,a))&&(a=o,t=i)}i[r]=t,t!==r&&m.laswp_rows(e,r,t);const l=e.array[r][r];if(!n.Complex.toBoolean(n.Complex.eq(n.Complex.abs(l),n.Complex.zero()))){for(let t=r+1;t<o;t++)e.array[t][r]=n.Complex.rdiv(e.array[t][r],l);for(let t=r+1;t<o;t++){const i=e.array[t][r],o=e.array[t],a=e.array[r];for(let e=r+1;e<s;e++)o[e]=n.Complex.sub(o[e],n.Complex.mul(i,a[e]))}}}};static getrf=(e,t)=>{const r=e.dimension[0],s=e.dimension[1],a=Math.min(r,s),l=new Array(a);for(let e=0;e<a;e++)l[e]=e;let u=0;for(let i=0;i<a;i+=t??o.BLAS.settings.blockSize){const m=Math.min(t??o.BLAS.settings.blockSize,a-i);c.LAPACK.getf2(e.array,i,m,l);for(let t=i;t<i+m&&t<a;t++){const r=l[t];if(r!==t&&u++,r!==t&&i>0)for(let n=0;n<i;n++){const i=e.array[t][n];e.array[t][n]=e.array[r][n],e.array[r][n]=i}}const p=m,h=r-(i+p),d=s-(i+p);if(i+p<s){const t=e.array,r=[];for(let e=0;e<h;e++){const n=i+p+e,o=new Array(p);for(let e=0;e<p;e++)o[e]=t[n][i+e];r.push(o)}const s=[];for(let e=0;e<p;e++){const r=i+e,n=new Array(d);for(let e=0;e<d;e++)n[e]=t[r][i+p+e];s.push(n)}const a=[];for(let e=0;e<h;e++){const r=i+p+e,n=new Array(d);for(let e=0;e<d;e++)n[e]=t[r][i+p+e];a.push(n)}o.BLAS.gemm(n.Complex.neg(n.Complex.one()),r,h,p,s,d,n.Complex.one(),a);for(let e=0;e<h;e++){const r=i+p+e;for(let n=0;n<d;n++)t[r][i+p+n]=a[e][n]}for(let e=0;e<p;e++){const r=i+e;for(let n=0;n<d;n++)t[r][i+p+n]=s[e][n]}for(let e=0;e<h;e++){const n=i+p+e;for(let o=0;o<p;o++)t[n][i+o]=r[e][o]}}}return i.MultiArray.setType(e),{LU:e,piv:l,swaps:u}};static gemm_blocked=(e,t,r,i=64)=>{const o=t+r,s=t+r,a=e.dimension[0]-(t+r),l=e.dimension[1]-(t+r);if(a<=0||l<=0)return;const c=r,u=i;for(let r=0;r<a;r+=u){const i=Math.min(r+u,a);for(let a=0;a<l;a+=u){const m=Math.min(a+u,l);for(let l=r;l<i;l++){const r=o+l,i=e.array[r];for(let r=a;r<m;r++){let a=n.Complex.zero();for(let i=0;i<c;i++){const c=e.array[o+l][t+i],u=e.array[t+i][s+r];a=n.Complex.add(a,n.Complex.mul(c,u))}i[s+r]=n.Complex.sub(i[s+r],a)}}}}};static getrf_blocked=(e,t)=>{const r=e.dimension[0],n=e.dimension[1],i=Math.min(r,n),s=new Array(i);for(let e=0;e<i;e++)s[e]=e;const a={swaps:0},l={info:0};for(let u=0;u<i;u+=t??o.BLAS.settings.blockSize){const m=Math.min(t??o.BLAS.settings.blockSize,i-u);c.LAPACK.getf2(e.array,u,m,s,a,l),u+m<n&&c.LAPACK.trsm_left_upper_block(e.array,u,m),u+m<r&&u+m<n&&c.LAPACK.gemm_blocked(e.array,u,m)}return{LU:e,piv:s,info:l.info,swaps:a.swaps}};static getrs=(e,t,r)=>{const o=e.dimension[0],s=e.dimension[1],a=r.dimension[1]??1,l=i.MultiArray.copy(r);for(let e=0;e<t.length;e++){const r=t[e];if(r!==e)if("function"==typeof i.MultiArray.swapRows)i.MultiArray.swapRows(l,e,r);else{const t=l.array[e];l.array[e]=l.array[r],l.array[r]=t}}for(let t=0;t<a;t++)for(let r=0;r<o;r++){let i=l.array[r][t];for(let o=0;o<r&&o<s;o++)i=n.Complex.sub(i,n.Complex.mul(e.array[r][o],l.array[o][t]));l.array[r][t]=i}for(let t=0;t<a;t++)for(let r=Math.min(s,o)-1;r>=0;r--){let i=l.array[r][t];for(let o=r+1;o<s;o++)i=n.Complex.sub(i,n.Complex.mul(e.array[r][o],l.array[o][t]));const o=e.array[r][r];l.array[r][t]=n.Complex.rdiv(i,o)}return i.MultiArray.setType(l),l};static sytrd=(e,t)=>{const r=e.dimension[0],i=new Array(r),o=new Array(r-1),s=new Array(r-1);for(let a=0;a<r-1;a++){const l=r-a-1,u=new Array(l);for(let t=0;t<l;t++)u[t]=n.Complex.copy(e.array[a+1+t][a]);const{alpha:m,v:p,tau:h}=c.LAPACK.larfg_original(u);s[a]=h,o[a]=m,e.array[a+1][a]=m;for(let t=1;t<l;t++)e.array[a+1+t][a]=p[t];n.Complex.realIsZero(n.Complex.abs(h))||t(e,p,n.Complex.conj(h),a+1,a+1),i[a]=n.Complex.copy(e.array[a][a])}return i[r-1]=n.Complex.copy(e.array[r-1][r-1]),{diag:i,offdiag:o,taus:s}};static ungtr0=(e,t)=>{const r=e.dimension[0],o=new i.MultiArray([r,r]);o.array=c.LAPACK.eye([r,r]);for(let i=r-2;i>=0;i--){const s=t[i];if(n.Complex.realIsZero(n.Complex.abs(s)))continue;const a=r-i-1,l=new Array(a);l[0]=n.Complex.one();for(let t=1;t<a;t++)l[t]=n.Complex.copy(e.array[i+1+t][i]);const c=new Array(r);for(let e=0;e<r;e++){let t=n.Complex.zero();for(let r=0;r<a;r++)n.Complex.mulAndSumTo(t,n.Complex.conj(l[r]),o.array[i+1+r][e]);c[e]=t}for(let e=0;e<a;e++){const t=n.Complex.mul(s,l[e]);for(let s=0;s<r;s++)o.array[i+1+e][s]=n.Complex.sub(o.array[i+1+e][s],n.Complex.mul(t,c[s]))}}return o};static ungtr=(e,t)=>{const r=e.dimension[0],o=new i.MultiArray([r,r]);o.array=c.LAPACK.eye([r,r]);for(let i=r-2;i>=0;i--){const s=t[i];if(n.Complex.realIsZero(n.Complex.abs(s)))continue;const a=r-i-1,l=new Array(a);l[0]=n.Complex.one();for(let t=1;t<a;t++)l[t]=n.Complex.copy(e.array[i+1+t][i]);const c=new Array(r);for(let e=0;e<r;e++){let t=n.Complex.zero();for(let r=0;r<a;r++)n.Complex.mulAndSumTo(t,n.Complex.conj(l[r]),o.array[i+1+r][e]);c[e]=t}for(let e=0;e<a;e++){const t=n.Complex.mul(s,l[e]);for(let s=0;s<r;s++)o.array[i+1+e][s]=n.Complex.sub(o.array[i+1+e][s],n.Complex.mul(t,c[s]))}}return o};static sytrd_debug=e=>{console.log("\n===== DEBUG: LAPACK.sytrd_debug =====\n");const t=e.dimension[0],r=i.MultiArray.copy(e),{diag:o,offdiag:u,taus:m}=c.LAPACK.sytrd(e,c.LAPACK.her2_zhtrd_update);console.log("Diag D ="),console.log("Offdiag E ="),console.log("Taus =");let p=new i.MultiArray([t,t]);p.array=c.LAPACK.eye(t,t);for(let r=t-2;r>=0;r--){const i=t-r-1,o=new Array(i);for(let t=0;t<i;t++)o[t]=e.array[r+1+t][r];const s=m[r];n.Complex.realIsZero(n.Complex.abs(s))||c.LAPACK.larf_left(p,o,s,r+1,0)}const h=new i.MultiArray([t,t]);for(let e=0;e<t;e++)h.array[e][e]=o[e],e<t-1&&(h.array[e][e+1]=u[e],h.array[e+1][e]=u[e]);console.log("\nMatriz T reconstruída:");const d=l.Evaluator.Create();console.log(i.MultiArray.unparse(h,d));const x=s.MathOperation.mtimes(a.LinearAlgebra.transpose(p),s.MathOperation.mtimes(r,p));console.log("\nMatriz Qᵀ * A * Q ="),console.log(i.MultiArray.unparse(x,d)),console.log("\nElementos fora da banda tridiagonal (devem ≈ 0):");for(let e=0;e<t;e++)for(let r=0;r<t;r++)Math.abs(n.Complex.realToNumber(x.array[e][r]))>1e-7&&Math.abs(e-r)>1&&console.log("\n===== FIM DEBUG SYTRD =====\n");return{diag:o,offdiag:u,taus:m,Q:p,T:h,QtA:x}};static sytrd_blocked=(e,t)=>{const r=e.dimension[0];if(r!==e.dimension[1])throw new Error("sytrd_blocked: A must be square");const i=new Array(r),s=new Array(r),a=new Array(r);if(0===r)return{diag:i,offdiag:s,taus:a};if(1===r)return i[0]=e.array[0][0],s[0]=n.Complex.zero(),a[0]=n.Complex.zero(),{diag:i,offdiag:s,taus:a};const l=Math.max(1,Math.floor(t??o.BLAS.settings.blockSize));for(let t=0;t<r-1;t+=l){const o=Math.min(l,r-1-t);for(let u=0;u<o;u++){const o=t+u,p=r-o-1,h=new Array(p);for(let t=0;t<p;t++)h[t]=e.array[o+1+t][o];const d=c.LAPACK.larfg_original(h),x=d.v,f=d.tau,C=d.alpha;a[o]=f,i[o]=e.array[o][o],s[o]=C;for(let t=0;t<p;t++)e.array[o+1+t][o]=x[t];if(n.Complex.realIsZero(n.Complex.abs(f)))continue;const g=o+1,y=o+1;m.larf_left_block(e,x,f,g,y,l),m.larf_right_conj_block(e,x,f,g,y,l)}}return i[r-1]=e.array[r-1][r-1],s[r-1]=n.Complex.zero(),a[r-1]=n.Complex.zero(),{diag:i,offdiag:s,taus:a}};static sytrd_blocked_w=(e,t)=>{const r=e.dimension[0];if(r!==e.dimension[1])throw new Error("sytrd_blocked_w: A must be square");const i=new Array(r),s=new Array(r),a=new Array(r);if(0===r)return{diag:i,offdiag:s,taus:a};if(1===r)return i[0]=e.array[0][0],s[0]=n.Complex.zero(),a[0]=n.Complex.zero(),{diag:i,offdiag:s,taus:a};const l=Math.max(1,Math.floor(t??o.BLAS.settings.blockSize));for(let t=0;t<r-1;t+=l){const o=Math.min(l,r-1-t),u=new Array(r-t-1),m=new Array(r-t-1);for(let e=0;e<r-t-1;e++)u[e]=new Array(o).fill(n.Complex.zero()),m[e]=new Array(o).fill(n.Complex.zero());for(let l=0;l<o;l++){const o=t+l,p=r-o-1,h=new Array(p);for(let t=0;t<p;t++)h[t]=e.array[o+1+t][o];const d=c.LAPACK.larfg_original(h),x=d.v,f=d.tau,C=d.alpha;a[o]=f,i[o]=e.array[o][o],s[o]=C;for(let t=0;t<p;t++)e.array[o+1+t][o]=x[t],u[t][l]=x[t];if(!n.Complex.realIsZero(n.Complex.abs(f)))for(let t=0;t<p;t++){let r=n.Complex.zero();for(let i=0;i<=t;i++)r=n.Complex.add(r,n.Complex.mul(u[i][l],n.Complex.conj(e.array[o+1+i][o+1+t])));m[t][l]=n.Complex.mul(f,r)}}for(let i=0;i<r-t-1;i++)for(let s=i;s<r-t-1;s++){let r=n.Complex.zero(),a=n.Complex.zero();for(let e=0;e<o;e++)r=n.Complex.add(r,n.Complex.mul(u[i][e],n.Complex.conj(m[s][e]))),a=n.Complex.add(a,n.Complex.mul(m[i][e],n.Complex.conj(u[s][e])));e.array[t+1+i][t+1+s]=n.Complex.sub(e.array[t+1+i][t+1+s],n.Complex.add(r,a)),i!==s&&(e.array[t+1+s][t+1+i]=n.Complex.conj(e.array[t+1+i][t+1+s]))}}return i[r-1]=e.array[r-1][r-1],s[r-1]=n.Complex.zero(),a[r-1]=n.Complex.zero(),{diag:i,offdiag:s,taus:a}};static steqr_values=(e,t,r)=>{const{D:n}=c.LAPACK.steqr_vectors(e,t,r);return n};static steqr_vectors_1=(e,t,r)=>{const o=e.length,s=r??1e3*o,a=e.slice(),l=t.slice();let u=o-1,m=0;const p=new i.MultiArray([o,o]);for(p.array=c.LAPACK.eye(o,o);u>0&&m<s;){let e=u-1;for(;e>=0&&n.Complex.realIsZero(n.Complex.abs(l[e]));)e--;if(e<0){u--;continue}const t=a[u-1],r=a[u],i=l[u-1],s=n.Complex.mul(n.Complex.sub(t,r),n.Complex.onediv2()),c=n.Complex.add(r,n.Complex.rdiv(n.Complex.mul(i,i),n.Complex.add(s,n.Complex.sign(s))));let h=n.Complex.sub(a[0],c),d=l[0];for(let e=0;e<u;e++){const t=n.Complex.sqrt(n.Complex.add(n.Complex.mul(h,h),n.Complex.mul(d,d))),r=n.Complex.rdiv(h,t),i=n.Complex.rdiv(d,t);for(let t=0;t<o;t++){const o=p.array[e][t],s=p.array[e+1][t];p.array[e][t]=n.Complex.add(n.Complex.mul(r,o),n.Complex.mul(i,s)),p.array[e+1][t]=n.Complex.sub(n.Complex.mul(r,s),n.Complex.mul(i,o))}e>0&&(l[e-1]=n.Complex.mul(t,n.Complex.sign(l[e-1])));const s=a[e],c=a[e+1],m=l[e];a[e]=n.Complex.add(n.Complex.add(n.Complex.mul(n.Complex.mul(r,r),s),n.Complex.mul(n.Complex.mul(i,i),c)),n.Complex.mul(n.Complex.mul(n.Complex.mul(r,i),m),n.Complex.two())),a[e+1]=n.Complex.add(n.Complex.add(n.Complex.mul(n.Complex.mul(i,i),s),n.Complex.mul(n.Complex.mul(r,r),c)),n.Complex.mul(n.Complex.mul(n.Complex.mul(r,i),m),n.Complex.create(-2))),l[e]=n.Complex.sub(n.Complex.mul(n.Complex.mul(r,i),n.Complex.sub(c,s)),m),e<u-1&&(h=l[e],d=n.Complex.mul(i,l[e+1]),l[e+1]=n.Complex.mul(r,l[e+1]))}m++}const h=i.MultiArray.toColumnVector(a);return i.MultiArray.setType(h),i.MultiArray.setType(p),{D:h,V:p}};static steqr_vectors_0=(e,t,r)=>{const o=e.length,s=r??Math.max(c.LAPACK.settings.maxIterationFactor,o*c.LAPACK.settings.maxIterationFactor),a=new Array(o),l=new Array(o);for(let t=0;t<o;t++)a[t]=n.Complex.realToNumber(e[t]);for(let e=0;e<o-1;e++)l[e]=n.Complex.realToNumber(t[e]);l[o-1]=0;const u=new i.MultiArray([o,o]),m=c.LAPACK.eye(o,o);u.array=m;const p=Number.EPSILON||2220446049250313e-31,h=a.slice(),d=l.slice();let x=o-1,f=0;const C=Array.from({length:o},(e,t)=>Array.from({length:o},(e,r)=>t===r?n.Complex.create(1):n.Complex.create(0)));let g=!1;try{for(;x>0&&f<s;){let e=x-1;for(;e>=0;){if(Math.abs(d[e])<=100*p*(Math.abs(h[e])+Math.abs(h[e+1]))){d[e]=0;break}e--}if(e<0&&(e=0),e===x){x--;continue}let t=0;for(;e<x&&t<s&&f<s;){t++,f++;const e=h[x],r=h[x-1],i=d[x-1],s=(r-e)/2,a=Math.hypot(s,i),l=s+(s>=0?a:-a),c=0===l?e-Math.abs(i):e+i*i/l;let u=h[0]-c,m=d[0],g=0;for(let e=0;e<x;e++){const t=Math.hypot(u,m);if(0===t){e<x-1&&(u=d[e],m=0);continue}const r=u/t,i=m/t,s=n.Complex.create(r),a=n.Complex.create(i);for(let t=0;t<o;t++){const r=C[e][t],i=C[e+1][t],o=n.Complex.add(n.Complex.mul(s,r),n.Complex.mul(a,i)),l=n.Complex.sub(n.Complex.mul(s,i),n.Complex.mul(a,r));C[e][t]=o,C[e+1][t]=l}e>0&&(d[e-1]=g);const l=h[e],c=h[e+1],p=d[e],f=r*p-i*((c-l)/2),y=l+2*i*r*p,_=c-2*i*r*p;if(h[e]=y,h[e+1]=_,d[e]=f,e<x-1){const t=d[e+1];g=i*t,d[e+1]=r*t,u=d[e],m=g}else g=0*i,u=d[e],m=0}x-1>=0&&(d[x-1]=g);for(let e=0;e<x;e++){const t=100*p*(Math.abs(h[e])+Math.abs(h[e+1]));Math.abs(d[e])<=t&&(d[e]=0)}for(;x>0&&0===d[x-1];)x--}}}catch(e){g=!0}const y=h.slice(),_=new i.MultiArray([o,o]);for(let e=0;e<o;e++)for(let t=0;t<o;t++)_.array[e][t]=C[e][t];i.MultiArray.setType(_);const A=(()=>{const e=Array.from({length:o},()=>Array(o).fill(0));for(let t=0;t<o;t++)e[t][t]=a[t],t<o-1&&(e[t][t+1]=l[t],e[t+1][t]=l[t]);const t=Array.from({length:o},(e,t)=>Array(o).fill(0));for(let e=0;e<o;e++)for(let r=0;r<o;r++)t[e][r]=n.Complex.realToNumber(_.array[e][r]);const r=Array.from({length:o},()=>Array(o).fill(0));for(let n=0;n<o;n++)for(let i=0;i<o;i++)if(0!==e[n][i])for(let s=0;s<o;s++)r[n][s]+=e[n][i]*t[i][s];const i=Array.from({length:o},()=>Array(o).fill(0));for(let e=0;e<o;e++)for(let r=0;r<o;r++)i[e][r]=t[e][r]*y[r];let s=0;for(let e=0;e<o;e++)for(let t=0;t<o;t++){const n=r[e][t]-i[e][t];s+=n*n}return Math.sqrt(s)})(),T=1e-8*Math.max(1,A);if(g||!(A<=T)){const e=Array.from({length:o},()=>Array(o).fill(0));for(let t=0;t<o;t++)e[t][t]=a[t],t<o-1&&(e[t][t+1]=l[t],e[t+1][t]=l[t]);const t=Array.from({length:o},(e,t)=>Array.from({length:o},(e,r)=>t===r?1:0)),r=1e-12,c=Math.max(50,Math.floor(s/Math.max(1,o))),m=e=>{let t=0;for(let r=0;r<o;r++)for(let n=r+1;n<o;n++)t+=e[r][n]*e[r][n];return Math.sqrt(t)};for(let n=0;n<c;n++){let n=!1;for(let i=0;i<o-1;i++)for(let s=i+1;s<o;s++){const a=e[i][s];if(Math.abs(a)<=r)continue;const l=e[i][i],c=e[s][s],u=.5*Math.atan2(2*a,c-l),m=Math.cos(u),p=Math.sin(u);for(let t=0;t<o;t++)if(t!==i&&t!==s){const r=e[t][i],n=e[t][s];e[t][i]=m*r-p*n,e[i][t]=e[t][i],e[t][s]=p*r+m*n,e[s][t]=e[t][s]}const h=m*m*l-2*p*m*a+p*p*c,d=p*p*l+2*p*m*a+m*m*c;e[i][i]=h,e[s][s]=d,e[i][s]=0,e[s][i]=0;for(let e=0;e<o;e++){const r=t[e][i],n=t[e][s];t[e][i]=m*r-p*n,t[e][s]=p*r+m*n}n=!0}if(!n)break;if(m(e)<=r)break}const p=new i.MultiArray([o,1]);for(let t=0;t<o;t++)p.array[t][0]=n.Complex.create(e[t][t]);for(let e=0;e<o;e++)for(let r=0;r<o;r++)u.array[e][r]=n.Complex.create(t[e][r]);return i.MultiArray.setType(p),i.MultiArray.setType(u),{D:p,V:u}}const E=y.map((e,t)=>({val:e,i:t})).sort((e,t)=>e.val-t.val),L=E.map(e=>e.val),b=Array.from({length:o},()=>Array(o).fill(n.Complex.create(0)));for(let e=0;e<o;e++){const t=E[e].i;for(let r=0;r<o;r++)b[r][e]=_.array[r][t]}const M=new i.MultiArray([o,1]);for(let e=0;e<o;e++)M.array[e][0]=n.Complex.create(L[e]);return u.array=b,i.MultiArray.setType(M),i.MultiArray.setType(u),{D:M,V:u}};static steqr_vectors_2=(e,t,r)=>{const o=e.length,s=r??Math.max(c.LAPACK.settings.maxIterationFactor,o*c.LAPACK.settings.maxIterationFactor),a=e.map(e=>n.Complex.real(e)),l=t.map(e=>n.Complex.real(e));l[o-1]=n.Complex.zero();const u=new i.MultiArray([o,o]);u.array=c.LAPACK.eye(o,o);const m=n.Complex.epsilon(),p=n.Complex.create(100),h=a.slice(),d=l.slice();let x=o-1,f=0;const C=c.LAPACK.eye(o,o);let g=!1;try{for(;x>0&&f<s;){let e=x-1;for(;e>=0;){const t=n.Complex.abs(d[e]),r=n.Complex.mul(n.Complex.mul(m,p),n.Complex.add(n.Complex.abs(h[e]),n.Complex.abs(h[e+1])));if(n.Complex.toBoolean(n.Complex.le(t,r))){d[e]=n.Complex.zero();break}e--}if(e<0&&(e=0),e===x){x--;continue}let t=0;for(;e<x&&t<s&&f<s;){t++,f++;const e=h[x],r=h[x-1],i=d[x-1],s=n.Complex.rdiv(n.Complex.sub(r,e),n.Complex.two()),a=n.Complex.hypot(s,i),l=n.Complex.add(s,n.Complex.toBoolean(n.Complex.ge(s,n.Complex.zero()))?a:n.Complex.neg(a)),c=n.Complex.toBoolean(n.Complex.eq(l,n.Complex.zero()))?n.Complex.sub(e,n.Complex.abs(i)):n.Complex.add(e,n.Complex.rdiv(n.Complex.mul(i,i),l));let u=n.Complex.sub(h[0],c),g=d[0],y=n.Complex.zero();for(let e=0;e<x;e++){const t=n.Complex.hypot(u,g);if(n.Complex.toBoolean(n.Complex.eq(t,n.Complex.zero()))){e<x-1&&(u=d[e],g=n.Complex.zero());continue}const r=n.Complex.rdiv(u,t),i=n.Complex.rdiv(g,t),s=r,a=i;for(let t=0;t<o;t++){const r=C[e][t],i=C[e+1][t],o=n.Complex.add(n.Complex.mul(s,r),n.Complex.mul(a,i)),l=n.Complex.sub(n.Complex.mul(s,i),n.Complex.mul(a,r));C[e][t]=o,C[e+1][t]=l}e>0&&(d[e-1]=y);const l=h[e],c=h[e+1],m=d[e],p=n.Complex.sub(n.Complex.mul(r,m),n.Complex.mul(i,n.Complex.rdiv(n.Complex.sub(c,l),n.Complex.two()))),f=n.Complex.add(l,n.Complex.mul(n.Complex.two(),n.Complex.mul(i,n.Complex.mul(r,m)))),_=n.Complex.sub(c,n.Complex.mul(n.Complex.two(),n.Complex.mul(i,n.Complex.mul(r,m))));if(h[e]=f,h[e+1]=_,d[e]=p,e<x-1){const t=d[e+1];y=n.Complex.mul(i,t),d[e+1]=n.Complex.mul(r,t),u=d[e],g=y}else y=n.Complex.mul(i,n.Complex.zero()),u=d[e],g=n.Complex.zero()}x-1>=0&&(d[x-1]=y);for(let e=0;e<x;e++){const t=n.Complex.mul(m,n.Complex.mul(p,n.Complex.add(n.Complex.abs(h[e]),n.Complex.abs(h[e+1]))));n.Complex.toBoolean(n.Complex.le(n.Complex.abs(d[e]),t))&&(d[e]=n.Complex.zero())}for(;x>0&&n.Complex.toBoolean(n.Complex.eq(d[x-1],n.Complex.zero()));)x--}}}catch(e){g=!0}const y=h.slice(),_=new i.MultiArray([o,o]);for(let e=0;e<o;e++)for(let t=0;t<o;t++)_.array[e][t]=C[e][t];i.MultiArray.setType(_);const A=(()=>{const e=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let t=0;t<o;t++)e[t][t]=a[t],t<o-1&&(e[t][t+1]=l[t],e[t+1][t]=l[t]);const t=Array.from({length:o},(e,t)=>Array(o).fill(n.Complex.zero()));for(let e=0;e<o;e++)for(let r=0;r<o;r++)t[e][r]=_.array[e][r];const r=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let i=0;i<o;i++)for(let s=0;s<o;s++)if(n.Complex.toBoolean(n.Complex.ne(e[i][s],n.Complex.zero())))for(let a=0;a<o;a++)n.Complex.mulAndSumTo(r[i][a],e[i][s],t[s][a]);const i=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let e=0;e<o;e++)for(let r=0;r<o;r++)i[e][r]=n.Complex.mul(t[e][r],y[r]);let s=n.Complex.zero();for(let e=0;e<o;e++)for(let t=0;t<o;t++){const o=n.Complex.sub(r[e][t],i[e][t]);n.Complex.mulAndSumTo(s,o,o)}return n.Complex.sqrt(s)})(),T=n.Complex.mul(n.Complex.create(1e-8),n.Complex.max(n.Complex.one(),A));if(g||!n.Complex.toBoolean(n.Complex.le(A,T))){const e=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let t=0;t<o;t++)e[t][t]=a[t],t<o-1&&(e[t][t+1]=l[t],e[t+1][t]=l[t]);const t=Array.from({length:o},(e,t)=>Array.from({length:o},(e,r)=>t===r?n.Complex.one():n.Complex.zero())),r=n.Complex.create(1e-12),c=Math.max(50,Math.floor(s/Math.max(1,o))),m=e=>{let t=n.Complex.zero();for(let r=0;r<o;r++)for(let i=r+1;i<o;i++)n.Complex.mulAndSumTo(t,e[r][i],e[r][i]);return n.Complex.sqrt(t)};for(let i=0;i<c;i++){let i=!1;for(let s=0;s<o-1;s++)for(let a=s+1;a<o;a++){const l=e[s][a];if(n.Complex.toBoolean(n.Complex.le(n.Complex.abs(l),r)))continue;const c=e[s][s],u=e[a][a],m=n.Complex.mul(n.Complex.onediv2(),n.Complex.atan2(n.Complex.mul(n.Complex.two(),l),n.Complex.sub(u,c))),p=n.Complex.cos(m),h=n.Complex.sin(m);for(let t=0;t<o;t++)if(t!==s&&t!==a){const r=e[t][s],i=e[t][a];e[t][s]=n.Complex.sub(n.Complex.mul(p,r),n.Complex.mul(h,i)),e[s][t]=e[t][s],e[t][a]=n.Complex.add(n.Complex.mul(h,r),n.Complex.mul(p,i)),e[a][t]=e[t][a]}const d=n.Complex.add(n.Complex.sub(n.Complex.mul(n.Complex.mul(p,p),c),n.Complex.mul(n.Complex.mul(n.Complex.mul(n.Complex.two(),h),p),l)),n.Complex.mul(n.Complex.mul(h,h),u)),x=n.Complex.add(n.Complex.add(n.Complex.mul(n.Complex.mul(h,h),c),n.Complex.mul(n.Complex.mul(n.Complex.mul(n.Complex.two(),h),p),l)),n.Complex.mul(n.Complex.mul(p,p),u));e[s][s]=d,e[a][a]=x,e[s][a]=n.Complex.zero(),e[a][s]=n.Complex.zero();for(let e=0;e<o;e++){const r=t[e][s],i=t[e][a];t[e][s]=n.Complex.sub(n.Complex.mul(p,r),n.Complex.mul(h,i)),t[e][a]=n.Complex.add(n.Complex.mul(h,r),n.Complex.mul(p,i))}i=!0}if(!i)break;if(m(e)<=r)break}const p=new i.MultiArray([o,1]);for(let t=0;t<o;t++)p.array[t][0]=e[t][t];for(let e=0;e<o;e++)for(let r=0;r<o;r++)u.array[e][r]=t[e][r];return i.MultiArray.setType(p),i.MultiArray.setType(u),{D:p,V:u}}const E=y.map((e,t)=>({val:e,i:t})).sort((e,t)=>n.Complex.realToNumber(n.Complex.sub(e.val,t.val))),L=E.map(e=>e.val),b=Array.from({length:o},()=>Array(o).fill(n.Complex.create(0)));for(let e=0;e<o;e++){const t=E[e].i;for(let r=0;r<o;r++)b[r][e]=_.array[r][t]}const M=new i.MultiArray([o,1]);for(let e=0;e<o;e++)M.array[e][0]=L[e];return u.array=b,i.MultiArray.setType(M),i.MultiArray.setType(u),{D:M,V:u}};static numeric_jacobi_symmetric_dense=(e,t,r)=>{const i=e.length;if(0===i)return{Dnum:[],Vnum:[]};if(1===i)return{Dnum:[e[0]],Vnum:[[n.Complex.one()]]};const o=Array.from({length:i},()=>Array(i).fill(0));for(let r=0;r<i;r++)if(o[r][r]=e[r],r<i-1){const e=t[r];o[r][r+1]=e,o[r+1][r]=e}const s=Array.from({length:i},(e,t)=>Array.from({length:i},(e,r)=>t===r?1:0)),a=Number.EPSILON||2220446049250313e-31,l=Math.max(50,Math.min(5e3,Math.floor(r/Math.max(1,i)))),c=e=>{let t=0;for(let r=0;r<i;r++)for(let n=r+1;n<i;n++)t+=e[r][n]*e[r][n];return Math.sqrt(t)};for(let e=0;e<l;e++){let e=!1;for(let t=0;t<i-1;t++)for(let r=t+1;r<i;r++){const n=o[t][r],l=1e-15*(Math.abs(o[t][t])+Math.abs(o[r][r]))+a;if(Math.abs(n)<=l)continue;const c=o[t][t],u=o[r][r],m=2*n;if(0===m)continue;const p=(u-c)/m,h=(p>=0?1:-1)/(Math.abs(p)+Math.sqrt(1+p*p)),d=1/Math.sqrt(1+h*h),x=h*d;for(let e=0;e<i;e++)if(e!==t&&e!==r){const n=o[e][t],i=o[e][r];o[e][t]=d*n-x*i,o[t][e]=o[e][t],o[e][r]=x*n+d*i,o[r][e]=o[e][r]}const f=d*d*c-2*x*d*n+x*x*u,C=x*x*c+2*x*d*n+d*d*u;o[t][t]=f,o[r][r]=C,o[t][r]=0,o[r][t]=0;for(let e=0;e<i;e++){const n=s[e][t],i=s[e][r];s[e][t]=d*n-x*i,s[e][r]=x*n+d*i}e=!0}if(!e)break;if(c(o)<=1e-14)break}const u=new Array(i);for(let e=0;e<i;e++)u[e]=o[e][e];return{Dnum:u,Vnum:Array.from({length:i},(e,t)=>Array.from({length:i},(e,r)=>n.Complex.create(s[t][r])))}};static tridiag_her_to_dense=(e,t)=>{const r=e.length,i=Array.from({length:r},()=>Array.from({length:r},()=>n.Complex.zero()));for(let o=0;o<r;o++)i[o][o]=n.Complex.copy(e[o]),o<r-1&&(i[o][o+1]=n.Complex.copy(t[o]),i[o+1][o]=n.Complex.conj(t[o]));return i};static compute_residual_numeric=(e,t,r)=>{const i=e.length,o=Array.from({length:i},()=>Array(i).fill(0));for(let e=0;e<i;e++)for(let r=0;r<i;r++)o[e][r]=n.Complex.realToNumber(t.array[e][r]);const s=Array.from({length:i},()=>Array(i).fill(0));for(let t=0;t<i;t++)s[t][t]=n.Complex.realToNumber(n.Complex.real(e[t][t])),t<i-1&&(s[t][t+1]=n.Complex.realToNumber(n.Complex.real(e[t][t+1])),s[t+1][t]=s[t][t+1]);const a=Array.from({length:i},()=>Array(i).fill(0));for(let e=0;e<i;e++)for(let t=0;t<i;t++){const r=s[e][t];if(0!==r)for(let n=0;n<i;n++)a[e][n]+=r*o[t][n]}const l=Array.from({length:i},()=>Array(i).fill(0));for(let e=0;e<i;e++)for(let t=0;t<i;t++)l[e][t]=o[e][t]*r[t];let c=0;for(let e=0;e<i;e++)for(let t=0;t<i;t++){const r=a[e][t]-l[e][t];c+=r*r}return Math.sqrt(c)};static compute_residual_complex=(e,t,r)=>{const i=e.length;let o=0;for(let s=0;s<i;s++)for(let a=0;a<i;a++){let l=n.Complex.zero();for(let r=0;r<i;r++)n.Complex.mulAndSumTo(l,e[s][r],t.array[r][a]);const c="number"==typeof r[0]?n.Complex.create(r[a]):r[a],u=n.Complex.mul(t.array[s][a],c),m=n.Complex.sub(l,u),p=n.Complex.realToNumber(n.Complex.abs(m));o+=p*p}return Math.sqrt(o)};static column_pivot=(e,t,r=0,i=e.length)=>{const o=e.slice(r,i).map(e=>n.Complex.abs(e[t])),s=o.reduce((e,t,r,i)=>n.Complex.toBoolean(n.Complex.gt(t,i[e]))?r:e,0);return{pivotRow:s,pivotAbs:o[s],pivotIsZero:n.Complex.realIsZero(o[s])}};static normalize_eigenvector_phases=(e,t=!0)=>{const r=e.length,i=e[0].length;for(let o=0;o<i;o++){const{pivotRow:i,pivotAbs:s,pivotIsZero:a}=c.LAPACK.column_pivot(e,o);if(a)continue;const l=e[i][o];let u=n.Complex.rdiv(n.Complex.conj(l),s);t&&n.Complex.realLessThan(n.Complex.mul(l,u),0)&&(u=n.Complex.neg(u));for(let t=0;t<r;t++)e[t][o]=n.Complex.mul(e[t][o],u)}};static test_orthonormality=e=>{const t=e.dimension[0],r=Array.from({length:t},()=>Array(t).fill(0));for(let i=0;i<t;i++)for(let o=0;o<t;o++){let s=0;for(let r=0;r<t;r++)s+=n.Complex.realToNumber(n.Complex.mul(n.Complex.conj(e.array[r][i]),e.array[r][o]));r[i][o]=s}let i=0,o=0;for(let e=0;e<t;e++)for(let n=0;n<t;n++)e===n?o=Math.max(o,Math.abs(1-r[e][e])):i=Math.max(i,Math.abs(r[e][n]));return{maxOffDiag:i,maxDiagDeviation:o}};static test_residual=(e,t,r)=>{const n=e.length,i=new Array(n);for(let e=0;e<n;e++)i[e]=r.array[e][0];return m.compute_residual_complex(e,t,i)};static diag_eigenpairs=(e,t,r)=>{const i=e.length,o=[];for(let s=0;s<i;s++){const a=new Array(i);for(let e=0;e<i;e++)a[e]=t.array[e][s];const l=new Array(i).fill(n.Complex.zero());for(let t=0;t<i;t++){let r=n.Complex.zero();for(let o=0;o<i;o++)r=n.Complex.add(r,n.Complex.mul(e[t][o],a[o]));l[t]=r}let c=n.Complex.zero();for(let e=0;e<i;e++)c=n.Complex.add(c,n.Complex.mul(n.Complex.conj(a[e]),l[e]));let u=n.Complex.zero();for(let e=0;e<i;e++)u=n.Complex.add(u,n.Complex.mul(n.Complex.conj(a[e]),a[e]));const m=n.Complex.rdiv(c,u),p=r.array[s][0],h=n.Complex.sub(p,m),d=n.Complex.realToNumber(n.Complex.abs(h));let x=0;for(let e=0;e<i;e++){const t=l[e],r=n.Complex.mul(p,a[e]),i=n.Complex.sub(t,r),o=n.Complex.realToNumber(n.Complex.abs(i));x+=o*o}const f=Math.sqrt(x);o.push({j:s,lambda:p,rq:m,abs_lambda_minus_rq:d,resnorm:f})}return o.forEach(e=>{}),o};static match_evals_to_rayleighs=(e,t)=>{const r=e.length,i=(e.map((e,t)=>({val:e,i:t,re:n.Complex.realToNumber(n.Complex.real(e))})),t.map((e,t)=>({val:e,i:t,re:n.Complex.realToNumber(n.Complex.real(e))})),Array(r).fill(!1)),o=[];for(let s=0;s<r;s++){let a=-1,l=1/0;for(let o=0;o<r;o++){if(i[o])continue;const r=n.Complex.sub(e[s],t[o]),c=n.Complex.realToNumber(n.Complex.abs(r));c<l&&(l=c,a=o)}a>=0&&(i[a]=!0,o.push({evalIndex:s,rqIndex:a,diff:l}))}return console.log("match_evals_to_rayleighs mapping:"),o.forEach(r=>{const i=n.Complex.realToNumber(n.Complex.real(e[r.evalIndex])),o=n.Complex.realToNumber(n.Complex.real(t[r.rqIndex]));console.log(`eval idx=${r.evalIndex} (val=${i}) -> rq idx=${r.rqIndex} (val=${o}) diff=${r.diff}`)}),o};static steqr_vectors_original=(e,t,r)=>{const o=e.length,s=r??Math.max(1e3,1e3*o),a=new Array(o),l=new Array(o);for(let r=0;r<o-1;r++)a[r]=n.Complex.copy(e[r]),l[r]=n.Complex.copy(t[r]);a[o-1]=n.Complex.copy(e[o-1]),l[o-1]=n.Complex.zero();let u=!1;for(let e=0;e<o;e++){if(n.Complex.isComplexValue(a[e])){u=!0;break}if(e<o-1&&n.Complex.isComplexValue(l[e])){u=!0;break}}console.log("----- State of tridiagonal about to be solved -----"),console.log("# Arguments:"),console.log("# Prepare Dwork and Ework:"),console.log("# Input is complex?:"),console.log(" needComplexPath =",u??!1);const p=new Array(o),h=new Array(o),d=new Array(o);if(u){p[0]=n.Complex.one();for(let e=0;e<o-1;e++){const t=l[e],r=n.Complex.abs(t);if(n.Complex.realIsZero(r))p[e+1]=n.Complex.copy(p[e]);else{const i=n.Complex.mul(n.Complex.conj(p[e]),t);p[e+1]=n.Complex.rdiv(r,i);const o=n.Complex.realToNumber(n.Complex.abs(p[e+1]));0!==o&&Math.abs(o-1)>1e-12&&(p[e+1]=n.Complex.rdiv(p[e+1],n.Complex.abs(p[e+1])))}}console.log("# Phases u[] for Hermitian -> real-offdiag transform");for(let e=0;e<o;e++)h[e]=n.Complex.realToNumber(a[e]);for(let e=0;e<o-1;e++){const t=n.Complex.mul(n.Complex.conj(p[e]),n.Complex.mul(l[e],p[e+1]));d[e]=n.Complex.realToNumber(n.Complex.abs(t))}}else{for(let e=0;e<o;e++)h[e]=n.Complex.realToNumber(a[e]);for(let e=0;e<o-1;e++)d[e]=n.Complex.realToNumber(l[e])}d[o-1]=0,console.log(" Dnum = [",h.map(e=>e.toString()).join(", "),"]"),console.log(" Enum = [",d.map(e=>e.toString()).join(", "),"]");const x=new i.MultiArray([o,o]);x.array=c.LAPACK.eye(o,o);const f=m.numeric_jacobi_symmetric_dense(h,d,s);console.log("# LAPACK.numeric_jacobi_symmetric_dense(Dnum, Enum, maxIts)"),console.log(" core.Dnum:",JSON.stringify(f.Dnum));const C=f.Dnum.slice(),g=f.Vnum.map(e=>e.map(e=>n.Complex.copy(e)));if(u)for(let e=0;e<o;e++){const t=p[e];for(let r=0;r<o;r++)g[e][r]=n.Complex.mul(t,g[e][r])}const y=new i.MultiArray([o,o]);for(let e=0;e<o;e++)for(let t=0;t<o;t++)y.array[e][t]=n.Complex.copy(g[e][t]);i.MultiArray.setType(y);const _=C.map(e=>n.Complex.create(e));c.LAPACK.normalize_eigenvector_phases(y.array);const A=m.tridiag_her_to_dense(a,l),T=_.slice(),E=m.compute_residual_complex(A,y,T);if(E>1e-8*Math.max(1,E)){const e=c.LAPACK.jacobi_symmetric_hermitian(A,Math.max(50,Math.floor(s/Math.max(1,o))),1e-12),t=new i.MultiArray([o,1]);for(let r=0;r<o;r++)t.array[r][0]=e.D[r];for(let t=0;t<o;t++)for(let r=0;r<o;r++)x.array[t][r]=e.V[t][r];const r=e.D.map((e,t)=>({val:e,i:t})).sort((e,t)=>n.Complex.realToNumber(n.Complex.sub(e.val,t.val))),a=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let t=0;t<o;t++){const n=r[t].i;for(let r=0;r<o;r++)a[r][t]=e.V[r][n]}for(let e=0;e<o;e++)for(let t=0;t<o;t++)x.array[e][t]=a[e][t];c.LAPACK.normalize_eigenvector_phases(x.array);const l=new i.MultiArray([o,1]);for(let e=0;e<o;e++)l.array[e][0]=r[e].val;return i.MultiArray.setType(l),i.MultiArray.setType(x),{D:l,V:x,complex:u}}const L=_.map((e,t)=>({val:e,i:t})).sort((e,t)=>n.Complex.realToNumber(e.val)-n.Complex.realToNumber(t.val)),b=L.map(e=>e.val),M=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let e=0;e<o;e++){const t=L[e].i;for(let r=0;r<o;r++)M[r][e]=n.Complex.copy(y.array[r][t])}for(let e=0;e<o;e++)for(let t=0;t<o;t++)x.array[e][t]=n.Complex.copy(M[e][t]);c.LAPACK.normalize_eigenvector_phases(x.array);const N=new i.MultiArray([o,1]);for(let e=0;e<o;e++)N.array[e][0]=n.Complex.copy(b[e]);return i.MultiArray.setType(N),i.MultiArray.setType(x),{D:N,V:x,complex:u}};static steqr_vectors=(e,t,r)=>{const o=e.length,s=r??Math.max(1e3,1e3*o),a=new Array(o),l=new Array(o);for(let r=0;r<o-1;r++)a[r]=n.Complex.copy(e[r]),l[r]=n.Complex.copy(t[r]);a[o-1]=n.Complex.copy(e[o-1]),l[o-1]=n.Complex.zero();let u=!1;for(let e=0;e<o;e++){if(n.Complex.isComplexValue(a[e])){u=!0;break}if(e<o-1&&n.Complex.isComplexValue(l[e])){u=!0;break}}const p=new Array(o),h=new Array(o),d=new Array(o);if(u){p[0]=n.Complex.one();for(let e=0;e<o-1;e++){const t=l[e],r=n.Complex.abs(t);if(n.Complex.realIsZero(r))p[e+1]=n.Complex.copy(p[e]);else{const i=n.Complex.rdiv(n.Complex.conj(t),r);p[e+1]=n.Complex.mul(p[e],i);const o=n.Complex.realToNumber(n.Complex.abs(p[e+1]));0!==o&&Math.abs(o-1)>1e-12&&(p[e+1]=n.Complex.rdiv(p[e+1],n.Complex.abs(p[e+1])))}}for(let e=0;e<o;e++)h[e]=n.Complex.realToNumber(a[e]);for(let e=0;e<o-1;e++){const t=n.Complex.mul(n.Complex.conj(p[e]),n.Complex.mul(l[e],p[e+1]));d[e]=n.Complex.realToNumber(n.Complex.abs(t))}}else{for(let e=0;e<o;e++)h[e]=n.Complex.realToNumber(a[e]);for(let e=0;e<o-1;e++)d[e]=n.Complex.realToNumber(l[e])}d[o-1]=0;const x=c.LAPACK.eye(o,o),f=m.numeric_jacobi_symmetric_dense(h,d,s),C=f.Dnum.slice(),g=f.Vnum.map(e=>e.map(e=>n.Complex.copy(e)));if(u)for(let e=0;e<o;e++){const t=p[e];for(let r=0;r<o;r++)g[e][r]=n.Complex.mul(t,g[e][r])}const y=new i.MultiArray([o,o]);for(let e=0;e<o;e++)for(let t=0;t<o;t++)y.array[e][t]=n.Complex.copy(g[e][t]);i.MultiArray.setType(y);const _=C.map(e=>n.Complex.create(e));c.LAPACK.normalize_eigenvector_phases(y.array);const A=m.tridiag_her_to_dense(a,l),T=_.slice(),E=m.compute_residual_complex(A,y,T);if(E>1e-8*Math.max(1,E)){const e=c.LAPACK.jacobi_symmetric_hermitian(A,Math.max(50,Math.floor(s/Math.max(1,o))),1e-12),t=new i.MultiArray([o,1]);for(let r=0;r<o;r++)t.array[r][0]=e.D[r];for(let t=0;t<o;t++)for(let r=0;r<o;r++)x[t][r]=e.V[t][r];const r=e.D.map((e,t)=>({val:e,i:t})).sort((e,t)=>n.Complex.realToNumber(n.Complex.sub(e.val,t.val))),a=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let t=0;t<o;t++){const n=r[t].i;for(let r=0;r<o;r++)a[r][t]=e.V[r][n]}for(let e=0;e<o;e++)for(let t=0;t<o;t++)x[e][t]=a[e][t];return c.LAPACK.normalize_eigenvector_phases(x),{D:r.map(e=>e.val),V:x,complex:u}}const L=_.map((e,t)=>({val:e,i:t})).sort((e,t)=>n.Complex.realToNumber(e.val)-n.Complex.realToNumber(t.val)),b=L.map(e=>e.val),M=Array.from({length:o},()=>Array(o).fill(n.Complex.zero()));for(let e=0;e<o;e++){const t=L[e].i;for(let r=0;r<o;r++)M[r][e]=n.Complex.copy(y.array[r][t])}for(let e=0;e<o;e++)for(let t=0;t<o;t++)x[e][t]=n.Complex.copy(M[e][t]);c.LAPACK.normalize_eigenvector_phases(x);const N=new i.MultiArray([o,1]);for(let e=0;e<o;e++)N.array[e][0]=n.Complex.copy(b[e]);return i.MultiArray.setType(N),{D:b,V:x,complex:u}};static orgtr_blocked_w=(e,t,r)=>{const s=e.dimension[0];if(s!==e.dimension[1])throw new Error("orgtr_blocked_w: A must be square");const a=new i.MultiArray([s,s]);a.array=c.LAPACK.eye(s,s);const l=Math.max(1,Math.floor(r??o.BLAS.settings.blockSize));for(let r=s-2;r>=0;r-=l){const i=Math.min(l,r+1),o=new Array(s-r-1),c=new Array(s-r-1);for(let e=0;e<s-r-1;e++)o[e]=new Array(i).fill(n.Complex.zero()),c[e]=new Array(i).fill(n.Complex.zero());for(let t=0;t<i;t++){const n=r-i+1+t,a=s-n-1;for(let r=0;r<a;r++)o[r][t]=e.array[n+1+r][n]}for(let e=0;e<i;e++){const l=r-i+1+e,u=t[l],m=s-l-1;if(!n.Complex.realIsZero(n.Complex.abs(u)))for(let t=0;t<m;t++){let r=n.Complex.zero();for(let i=0;i<=t;i++)r=n.Complex.add(r,n.Complex.mul(o[i][e],n.Complex.conj(a.array[l+1+i][l+1+t])));c[t][e]=n.Complex.mul(u,r)}}for(let e=0;e<s-r-1;e++)for(let t=0;t<s;t++){let s=n.Complex.zero(),l=n.Complex.zero();for(let a=0;a<i;a++)s=n.Complex.add(s,n.Complex.mul(o[e][a],n.Complex.conj(c[t-r-1+e]?.[a]??n.Complex.zero()))),l=n.Complex.add(l,n.Complex.mul(c[e][a],n.Complex.conj(o[t-r-1+e]?.[a]??n.Complex.zero())));a.array[r+1+e][t]=n.Complex.sub(a.array[r+1+e][t],n.Complex.add(s,l))}}return a};static eig_symmetric=(e,t=!1)=>{e.dimension[0];const r=i.MultiArray.copy(e),{diag:n,offdiag:o,taus:a}=c.LAPACK.sytrd(r,c.LAPACK.her2_zhtrd_update);if(t){let e=c.LAPACK.ungtr(r,a);const{D:t,V:l}=c.LAPACK.steqr_vectors(n,o),u=new i.MultiArray([l.length,l[0].length]);return u.array=l,e=s.MathOperation.mtimes(e,u),{D:i.MultiArray.toDiagonalMatrix(t),V:e}}return{D:i.MultiArray.toColumnVector(c.LAPACK.steqr_vectors(n,o).D)}};static eig_symmetric0=(e,t=!1,r)=>{const s=e.dimension[0],a=i.MultiArray.copy(e),{diag:l,offdiag:u,taus:m}=c.LAPACK.sytrd(a,c.LAPACK.her2_zhtrd_update);if(!t){const e=c.LAPACK.steqr_vectors(l,u,r);return{D:i.MultiArray.toColumnVector(e.D)}}const p=c.LAPACK.steqr_vectors(l,u,r),h=new i.MultiArray([s,s]);h.array=c.LAPACK.eye(s,s);for(let e=s-2;e>=0;e--){const t=s-e-1,r=[n.Complex.one()];for(let n=1;n<t;n++)r[n]=a.array[e+1+n][e];const i=m[e];n.Complex.realIsZero(n.Complex.abs(i))||c.LAPACK.larf_left(h,r,i,e+1,0)}const d=new i.MultiArray([h.dimension[0],p.V[0].length]);return o.BLAS.gemm(n.Complex.one(),h.array,h.dimension[0],h.dimension[1],p.V,p.V[0].length,n.Complex.zero(),d.array),c.LAPACK.normalize_eigenvector_phases(d.array),i.MultiArray.setType(d),{D:i.MultiArray.toDiagonalMatrix(p.D),V:d}};static eig_symmetric1=(e,t=!1,r=1e4)=>{const o=e.dimension[0];if(o!==e.dimension[1])throw new Error("eig_symmetric: matrix must be square.");const s=i.MultiArray.copy(e),{diag:a,offdiag:l,taus:u}=c.LAPACK.sytrd(s,c.LAPACK.her2_zhtrd_update),p=new Array(o),h=new Array(o);for(let e=0;e<o;e++)p[e]=n.Complex.realToNumber(a[e]),h[e]=e<o-1?n.Complex.realToNumber(l[e]):0;const d=m.numeric_jacobi_symmetric_dense(p,h,r),x=d.Dnum.slice(),f=d.Vnum.map(e=>e.map(e=>n.Complex.realToNumber(e))),C=c.LAPACK.ungtr(s,u),g=new i.MultiArray([o,o]);for(let e=0;e<o;e++)for(let t=0;t<o;t++){let r=n.Complex.zero();for(let i=0;i<o;i++)n.Complex.mulAndSumTo(r,C.array[t][i],n.Complex.create(f[i][e]));g.array[t][e]=r}return console.log(x.map(e=>e.toString()).join()),{D:x,V:g}};static eig_symmetric2=(e,t=!1,r)=>{const s=e.dimension[0],a=i.MultiArray.copy(e),{diag:l,offdiag:u,taus:m}=c.LAPACK.sytrd(a,c.LAPACK.larf_left);if(!t){const e=c.LAPACK.steqr_vectors(l,u,r);return{D:i.MultiArray.toColumnVector(e.D)}}const p=c.LAPACK.steqr_vectors(l,u,r),h=new i.MultiArray([s,s]);h.array=c.LAPACK.eye(s,s);for(let e=s-2;e>=0;e--){const t=s-e-1,r=[n.Complex.one()];for(let n=1;n<t;n++)r[n]=a.array[e+1+n][e];const i=m[e];n.Complex.realIsZero(n.Complex.abs(i))||c.LAPACK.larf_left(h,r,i,e+1,0)}const d=new i.MultiArray([h.dimension[0],p.V[0].length]);return o.BLAS.gemm(n.Complex.one(),h.array,h.dimension[0],h.dimension[1],p.V,p.V[0].length,n.Complex.zero(),d.array),c.LAPACK.normalize_eigenvector_phases(d.array),i.MultiArray.setType(d),{D:i.MultiArray.toDiagonalMatrix(p.D),V:d}};static eig_symmetric3=(e,t="asc")=>{const r=e.dimension[0];if(r!==e.dimension[1])throw new Error("eig_symmetric: A must be square");const o=i.MultiArray.copy(e),{diag:s,offdiag:a,taus:l}=c.LAPACK.sytrd(o,c.LAPACK.larf_left),u=c.LAPACK.steqr_vectors(s,a),m=new Array(r);for(let e=0;e<r;e++)m[e]=u.D[e];const p=u.V,h=c.LAPACK.orgtr(o,l),d=new i.MultiArray([r,r]);for(let e=0;e<r;e++)for(let t=0;t<r;t++)d.array[e][t]=n.Complex.zero();for(let e=0;e<r;e++)for(let t=0;t<r;t++){const i=h.array[e][t];for(let o=0;o<r;o++)d.array[e][o]=n.Complex.add(d.array[e][o],n.Complex.mul(i,p[t][o]))}const x=Array.from({length:r},(e,t)=>t);"none"!==t&&x.sort((e,r)=>{const i=Math.abs(n.Complex.realToNumber(m[e])),o=Math.abs(n.Complex.realToNumber(m[r]));return"asc"===t?i-o:o-i});const f=x.map(e=>m[e]),C=new i.MultiArray([r,r]);for(let e=0;e<r;e++)for(let t=0;t<r;t++)C.array[e][t]=d.array[e][x[t]];i.MultiArray.setType(C);const g=new i.MultiArray([r,r]);for(let e=0;e<r;e++)for(let t=0;t<r;t++)g.array[e][t]=n.Complex.zero();for(let e=0;e<r;e++)g.array[e][e]=f[e];return i.MultiArray.setType(g),{V:C,D:g,evals:f}};static eig_symmetric4=(e,t=!1,r=1e4)=>{const o=e.dimension[0];if(o!==e.dimension[1])throw new Error("eig_symmetric: matrix must be square.");const s=i.MultiArray.copy(e),{diag:a,offdiag:u,taus:p}=c.LAPACK.sytrd(s,c.LAPACK.her2_zhtrd_update),h=new Array(o),d=new Array(o);for(let e=0;e<o;e++)h[e]=n.Complex.realToNumber(a[e]),d[e]=e<o-1?n.Complex.realToNumber(u[e]):0;const x=m.numeric_jacobi_symmetric_dense(h,d,r);console.log("# LAPACK.numeric_jacobi_symmetric_dense(Dnum, Enum, maxIts)"),console.log(" core.Dnum:",JSON.stringify(x.Dnum));const f=x.Dnum.slice();if(!t)return{D:i.MultiArray.toColumnVector(f.map(e=>n.Complex.create(e)))};const C=new i.MultiArray([o,o]);C.array=x.Vnum;const g=c.LAPACK.ungtr(s,p),y=new i.MultiArray([o,o]);for(let e=0;e<o;e++)for(let t=0;t<o;t++){let r=n.Complex.zero();for(let i=0;i<o;i++)r=n.Complex.add(r,n.Complex.mul(g.array[t][i],C.array[i][e]));y.array[t][e]=r}c.LAPACK.normalize_eigenvector_phases(y.array),i.MultiArray.setType(y);const _=l.Evaluator.Create();return console.log(i.MultiArray.unparse(e,_)),console.log(`eigenvalues: [${f.map(e=>e.toString()).join(", ")}]`),{D:i.MultiArray.toDiagonalMatrix(f.map(e=>n.Complex.create(e))),V:y}};static eig_symmetric5=(e,t=!1,r=1e4)=>{const s=e.dimension[0],a=i.MultiArray.copy(e),{diag:l,offdiag:u,taus:p}=c.LAPACK.sytrd(a,c.LAPACK.her2_zhtrd_update);if(!t){const e=c.LAPACK.steqr_vectors(l,u,r);return{D:i.MultiArray.toColumnVector(e.D)}}const h=new Array(s),d=new Array(s);for(let e=0;e<s;e++)h[e]=n.Complex.realToNumber(n.Complex.real(l[e])),d[e]=e<s-1?n.Complex.realToNumber(n.Complex.real(u[e])):0;const x=m.numeric_jacobi_symmetric_dense(h,d,r),f=x.Dnum.slice(),C=x.Vnum.map(e=>e.slice());if(!t){const e=new i.MultiArray([s,1]);for(let t=0;t<s;t++)e.array[t][0]=n.Complex.create(f[t]);return i.MultiArray.setType(e),{D:e}}const g=c.LAPACK.ungtr(a,p),y=new i.MultiArray([s,s]);for(let e=0;e<s;e++)for(let t=0;t<s;t++){const r=C[e][t];y.array[e][t]=n.Complex.create(n.Complex.realToNumber(r))}i.MultiArray.setType(y);const _=new i.MultiArray([s,s]);o.BLAS.gemm(n.Complex.one(),g.array,g.dimension[0],g.dimension[1],y.array,y.dimension[1],n.Complex.zero(),_.array);const A=f.map((e,t)=>({val:e,i:t})).sort((e,t)=>e.val-t.val),T=A.map(e=>e.val),E=new i.MultiArray([s,s]);for(let e=0;e<s;e++){const t=A[e].i;for(let r=0;r<s;r++){const i=_.array[r][t];E.array[r][e]=n.Complex.copy(i)}}i.MultiAr