#![allow(dead_code)] mod common; use rand::prelude::*; use wmath::*; fn rand_f64_matrix(row: usize, col: usize) -> Matrix { let mut rng = rand::thread_rng(); let mut vec: Vec = Vec::with_capacity(row * col); for _ in 0..(row * col) { vec.push(rng.gen::() * 10.0 - 5.0); } mat!(&vec, row, col) } fn rand_cplx_matrix(row: usize, col: usize) -> Matrix { let mut rng = rand::thread_rng(); let mut vec: Vec = Vec::with_capacity(row * col); for _ in 0..(row * col) { vec.push(cplx!(rng.gen::() * 10.0 - 5.0, rng.gen::() * 10.0 - 5.0)); } mat!(&vec, row, col) } fn rand_frac_matrix(row: usize, col: usize) -> Matrix { let mut rng = rand::thread_rng(); let mut vec: Vec = Vec::with_capacity(row * col); for _ in 0..(row * col) { vec.push(frac!((rng.gen::() * 5.0 - 2.5) as i128, (rng.gen::() * 4.0 + 1.0) as i128)); } mat!(&vec, row, col) } #[test] fn test_matrix() { let m1 = mat!(&vec![1i128, 2, 3, 4, 5, 6, 7, 8, 9], 3, 3); print_expr!(m1); print_expr!(m1.latex()); print_expr!(m1.get_one()); print_expr!(m1.get_one().eq_one()); print_expr!(m1.get_one().similar_one(1e-100)); print_expr!(m1.get_zero()); print_expr!(m1.get_zero().eq_zero()); print_expr!(m1.get_zero().similar_zero(1e-100)); print_expr!(m1.neg()); print_expr!(m1.con()); let m2 = mat!(&vec![2i128, 4, 6, 8, 10, 12, 14, 16, 18], 3, 3); let m3 = m1.clone() + m2.clone(); let m4 = m1.clone() - m2.clone(); let m5 = m1.clone() * m2.clone(); let m6 = m1.pow(10); print_expr!(m3, m4, m5, m6); /* inverse */ let m1 = mat!(&vec![-4.807059042153524, 2.6440161217657714, -3.3018541913680686, -1.77515797426142, 1.0034940641370707, 4.430025212808948, -4.618416544286587, -3.3296402924416957, 4.73429068635877, 2.0692920085115007, 3.809761274848217, 4.589896097030765, -1.3760632755332471, 1.0001026360690517, -3.9763484727651988, 0.9722129097416747, 0.1821375827325724, 3.9386321046787955, 2.5113351374260056, -1.0665332588561371, -3.9975343300158226, 1.4372163194087015, 3.050723402082191, -0.5192321711129297, 1.228226928104946, 2.7888025749351204, 0.432170024863777, -3.874360341509778, 1.079672937446741, -4.899114773775132, -4.04300918703311, 0.34603347071128887, -3.497683293889886, -3.4231447855596775, -1.115945293830054, 4.045525923121913, -4.848009210361598, 3.513782719709077, 3.1477280794270825, -2.4075525264395745, -1.748762922303687, -3.6925023636865295, 4.741563352698076, -4.695034835303869, -4.666913315691586, -3.9276560619746004, -1.0650816605293012, 3.4867634302550687, 1.0839222444688037, 1.1329879444439506, 3.9400335184533137, -3.7425892318838194, 4.3900133425329315, 1.7528475426916525, -0.5811275098574944, 0.14374014555173975, -4.754564891488103, -0.05889734509742617, -4.222039581317691, -3.200906387312019, 3.029407138371445, -4.359456849188922, 1.1455590989364905, 2.354455219056182, 1.0820750563887263, 4.0385945922179225, 4.842735607395799, -4.864520180921101, -2.0270351069212333, -4.527142892373419, -3.8951721595456967, -1.9321960980318407, 4.869586661326206, 1.676301127312822, 1.2612561190773146, 1.1470933952987856, -3.4295236879780076, 2.0619495235177085, -3.477333797168126, -2.9312906683167537, 2.6008650315441066], 9, 9); if let Some(m2) = m1.inverse() { print_expr!(m1, m2); print_expr!((m1.clone() * m2.clone()).similar_one(1e-10)); print_expr!((m2.clone() * m1.clone()).similar_one(1e-10)); } let m1 = mat!(&vec![cplx!(1.0068825387541125, 2.865808012667042), cplx!(2.3311149255189347, -1.2379198719857865), cplx!(-2.0033401309251064, 4.77091405994072), cplx!(1.408820119844016, -4.20726284874941), cplx!(3.936022214509583, -4.1110991035337765), cplx!(1.6911494629200057, 3.1163076501445914), cplx!(-1.6421912085264734, -2.5728668518427233), cplx!(3.8106295709942977, 0.3899585330015265), cplx!(0.640686897790685, -3.364967451185646), cplx!(4.813632430830221, -0.35061917658083175), cplx!(-0.13847571507776735, -4.416077742636509), cplx!(-0.5612984997460249, -3.679968227550403), cplx!(-4.07576709918184, -2.0779767239559033), cplx!(-2.4273891246169677, -4.592842720764177), cplx!(3.6333098756889797, -2.26266412635045), cplx!(-2.9741014708950484, -3.751710311916163), cplx!(-4.674713522954085, -3.622080125410101), cplx!(-4.441837693247388, 3.2212543840666044), cplx!(-3.810545052351592, -3.4574948269472374), cplx!(4.837198438867384, 2.551823349024546), cplx!(-1.321945731647526, -2.1041908814444343), cplx!(1.1407620573685406, 3.0319972788811196), cplx!(-3.295421879616247, 1.8997182213768973), cplx!(1.0880629076267665, -4.7279880654161115), cplx!(2.332780837032397, -4.460135529581143), cplx!(-4.997210949231495, -2.424119219184341), cplx!(2.751274091606656, 2.2684073402650125), cplx!(-3.4577836931181416, 3.834533728272909), cplx!(2.7515368503786197, 2.186602093899306), cplx!(-1.5203665823606305, -0.46548227360550243), cplx!(4.66434090974721, 0.6360243519596365), cplx!(-1.9592584139214706, -2.7539861882726004), cplx!(0.5184406441204912, 1.0117056087945517), cplx!(3.935566458362178, 2.156842575590642), cplx!(4.757147601494594, 0.2024090534376679), cplx!(-4.511650150507874, -0.7399574371577602), cplx!(0.8278028978189926, 0.6813772148984221), cplx!(-4.523614444745007, 1.148204899093309), cplx!(4.246794583346784, -0.26065968601208844), cplx!(3.8026489983317475, 0.1634713616819603), cplx!(1.7282490323508313, 4.194208636044317), cplx!(1.966577698363884, -1.037006554799106), cplx!(-2.296819066082876, 0.8678570729138455), cplx!(-4.6402094861232, -3.5217813709443657), cplx!(0.988016440320969, -1.3619377500186278), cplx!(-4.250060877734697, 0.9499912188624879), cplx!(3.5417290955933716, 0.005252485130181839), cplx!(-3.126296249450652, 3.5109194930482754), cplx!(0.005403456312413013, -1.4044969621128143), cplx!(4.115051158300451, -3.8292934503221607), cplx!(4.4780863869299665, -2.186605157172705), cplx!(-3.1754575622714007, -0.17595669133102643), cplx!(3.8137261178839257, -2.205811451223618), cplx!(-2.175070585468204, 3.4722480599738113), cplx!(4.742890156015326, 3.07356970415411), cplx!(3.6010012813205794, -3.222765104505606), cplx!(4.6462954469045705, 4.739916697301961), cplx!(0.7918918070704422, 1.950871861614166), cplx!(1.903985423115925, -0.4766652096464128), cplx!(-1.8680073506185613, -0.7029545182136365), cplx!(4.592615483682874, 4.187244282717447), cplx!(-4.024901938938749, -1.3079173844455627), cplx!(0.45597942174928185, -0.02556539344151698), cplx!(4.036623684609539, -2.801110594001117), cplx!(-3.6257977937991748, -4.462089633118001), cplx!(-0.7366857148534924, -1.8965263759287962), cplx!(-4.060543747221218, -4.699664500813121), cplx!(-0.15477220369645028, 0.2244696433898019), cplx!(0.6075826627647043, 2.355874906391157), cplx!(-1.056046819744867, 3.0800374790854192), cplx!(2.3853671646309547, -4.522188156453604), cplx!(0.04886837972277114, -0.6549112213474251), cplx!(-4.640178019871005, -2.294604475846006), cplx!(1.0106688019865997, -4.677036103692237), cplx!(-2.0270490640346384, 2.420420337067199), cplx!(-2.1517391338829017, 3.3289128642339136), cplx!(3.6838833061962433, -4.812300660599456), cplx!(-2.5186031041998524, 2.476292083764367), cplx!(-4.973996280740768, -1.885370324185831), cplx!(-3.6058592475741524, -3.4434093586706203), cplx!(2.106879328910778, -1.3276534100045625)], 9, 9); if let Some(m2) = m1.inverse() { print_expr!(m1, m2); print_expr!((m1.clone() * m2.clone()).similar_one(1e-10)); print_expr!((m2.clone() * m1.clone()).similar_one(1e-10)); } let m1 = mat!(&vec![frac!(4, 3), frac!(8, 9), frac!(-9, 4), frac!(-10, 6), frac!(-5, 10), frac!(9, 5), frac!(-3, 7), frac!(-9, 3), frac!(5, 2), frac!(-6, 3), frac!(1, 1), frac!(-7, 3), frac!(-8, 9), frac!(3, 6), frac!(-5, 1), frac!(1, 5), frac!(-6, 2), frac!(3, 4), frac!(6, 4), frac!(4, 8), frac!(2, 4), frac!(10, 4), frac!(2, 5), frac!(1, 4), frac!(-2, 6), frac!(-6, 10), frac!(5, 7), frac!(4, 3), frac!(-2, 6), frac!(-9, 5), frac!(6, 2), frac!(-9, 5), frac!(-1, 7), frac!(0, 1), frac!(6, 6), frac!(5, 1)], 6, 6); if let Some(m2) = m1.inverse() { print_expr!(m1, m2); print_expr!((m1.clone() * m2.clone()).eq_one()); print_expr!((m2.clone() * m1.clone()).eq_one()); } /* Mul for poly */ let m1 = mat!(&vec![poly_from!(0.25809800062624966, -2.50796210202176, -4.455563019658002, -2.6459774496197275), poly_from!(3.084823571224053, 0.5736459084331171, 3.4926078047813505, 0.9403152158134143), poly_from!(-4.905740446336728, 1.271227818533597, 4.263668971990297, -3.056126255460143), poly_from!(3.8688765956870217, -2.396520195028655, 2.8011018967542176, -4.4732470713992445), poly_from!(-0.44756923078355726, -2.025900475411655, -1.9734577281803292, 2.595702268897414), poly_from!(4.119867533754384, -1.5112808538705869, -3.38097645024812, 4.625241870570569), poly_from!(-2.8605817945802214, 4.291492543660041, -1.153927804113486, -1.7112074931583185), poly_from!(3.4468690748034465, 0.632273090697586, 3.0125315110058324, 0.40253909251709175), poly_from!(1.724290193150571, 4.046420929859542, -1.5832249947633081, -4.768877298838219), poly_from!(-1.922633042479279, -3.1489830399596697, 4.7317936344550215, 2.220038268988686), poly_from!(2.359338101119981, 2.097652538437882, 1.5061440568260842, -4.955796336947257), poly_from!(-3.5791488552032282, 0.25336212443081596, -1.298526648317062, -1.4075074321072032), poly_from!(-2.9430637989128194, 1.9858858039241865, 0.5669815814197667, -3.4054603182099963), poly_from!(1.5297802622084964, 1.689729542266189, -4.051111703324933, -1.0749822703485936), poly_from!(3.3266888051324806, 0.25889390806589496, 1.07032648439516, -3.6398372133306456), poly_from!(-1.2992756793333893, 2.8176140497117146, 1.7088560584759263, -2.6917065176085564), poly_from!(2.081980651656192, 0.8895301538624478, 4.037578416354515, 0.7046925789916596), poly_from!(0.19088338644875869, -4.535159833442128, -1.661250490180135, 1.4751799299824206), poly_from!(-2.075161690335471, -2.672488335228941, -1.552997903418233, 4.8049649550611235), poly_from!(0.17373035148827043, 3.9385841030240876, -4.26566264935105, -3.0861564271053696), poly_from!(4.810986608801695, -0.0357601125318201, -1.6081934687657906, -1.458560652401466), poly_from!(-3.545299826145066, 2.7684685202293267, -0.7416116586249286, 2.6113619779408292), poly_from!(3.1519431503470052, -3.140442734012867, 4.51080557024825, 3.9397338914273767), poly_from!(-1.3476262758435373, -1.6735306765324531, -0.41135895387924926, -1.0290042865725821), poly_from!(1.8920100528507415, -0.17389301633778853, -2.243446124853936, 4.599688479354812), poly_from!(3.4260863274168543, -2.2583078983961125, 1.2262485109889294, 0.3125664214355828), poly_from!(2.9408982638794647, 4.355728833056688, 4.246055273571386, 1.97872630217379), poly_from!(1.5139141862239889, 4.9583253341099045, 3.8263120891846167, 1.1763434549638374), poly_from!(3.390457276501621, 0.9295151762190743, -0.33059077407982773, -4.26971530767973), poly_from!(-1.6181398687819848, 3.3494473094417447, -0.8800923749314826, -0.6141190467988524), poly_from!(3.996458302341388, 2.745541168050817, 4.217990711332805, 2.777072370202289), poly_from!(-3.5921865653275686, -0.390164760573219, -1.8314867442071003, 1.9237717982152738), poly_from!(-3.846445770647705, -2.453253852890356, 3.1949834058742255, -4.174200902064933), poly_from!(-3.213303088677643, -3.966324282413595, -1.6058129667919707, -0.5032777805853943), poly_from!(-4.251364487160175, -3.114622498564291, -0.13109062178294373, -2.390766044823801), poly_from!(-1.8294652021424707, 4.679487794159579, 1.97081143998658, 0.8189770899664106), poly_from!(-2.6938275799581235, 3.876073756360629, -3.209763593383148, 2.7621521965526608), poly_from!(-1.0410721541046932, -3.4620427408923407, -4.406326264379285, -0.4978905460866443), poly_from!(2.623514855856829, 4.899893730040702, 2.6931358863045674, 0.39544072114616835), poly_from!(-2.093497084472824, -4.40160962732009, -0.7437103824879046, -2.9539841411624845), poly_from!(1.4937221837472503, -1.28847903486324, 2.885164498799072, -4.785900132712854), poly_from!(-4.634059679300066, -0.8381040918980798, 2.141771600864325, -0.2950648799495257), poly_from!(-4.637042354959753, -2.4963014645440285, 1.2616070349548822, 4.507035503776459), poly_from!(-0.9359806524951395, -1.768229178933436, 2.518574913755238, -4.729720211418238), poly_from!(0.960107894333686, 2.6141141049471317, -0.4755512711305876, 4.443728086786654), poly_from!(4.1106099849307185, 0.7997873673797216, 2.731584510600376, -1.6828426882280887), poly_from!(-1.950080063527937, 2.715088374765471, 0.5551012670095812, 3.741798373329379), poly_from!(2.690234294334557, -1.9888913469431122, 3.069600100378892, 4.492912853915884), poly_from!(-4.351914767240728, 2.7525765267232476, 2.600832793526239, -4.564625289587564), poly_from!(-1.5594407917226052, -2.11879049080276, -2.3656906695309643, -0.2865081404048109), poly_from!(-2.828366410365626, -4.705861278468239, -1.7566082171229103, 3.158868014229334), poly_from!(4.033985363448011, -3.531659272970397, -4.923256277188138, -0.09009050520322415), poly_from!(-3.6827366235408343, -1.240489987790736, -0.8497035270958779, 4.30288316874041), poly_from!(-2.789435696673145, 3.16587315077021, -4.340853075353395, 2.5945548202180744), poly_from!(-1.5426112967227068, 1.6873901871997452, 4.8246775761182885, 2.8434367251215473), poly_from!(-0.14203005808220848, 0.7334426970975114, 0.5250844402201889, -3.1493523649730104), poly_from!(1.319368144334648, -2.7202925340233843, 4.765925316825413, -4.927518869545306), poly_from!(4.281379148680395, 1.146688533019459, 2.0368331299041023, -0.610516843075164), poly_from!(-3.948546590103427, -0.5810735130637115, -0.645245554594867, -2.250345594818489), poly_from!(4.041353725180839, -0.3981808507519302, -1.7789179894372231, -3.1571619439637653), poly_from!(2.086351386708177, -1.2971534112537029, -2.162010357945876, -1.9511579297043324), poly_from!(0.09018400763364465, -3.8513068974665696, 4.921000758410321, 0.6808514594996717), poly_from!(-3.5673934827836695, 3.3425134060046595, -1.229742194542116, 1.3280743877336834), poly_from!(-0.7881538786811753, 0.34229858275279135, -2.1783305717317356, -4.370833363260705), poly_from!(2.4540328367818995, -3.699820122376419, 2.4606615037409796, 3.7308601601669693), poly_from!(1.349777066171935, -4.2904220135948705, -0.47456810909560687, 0.28574467670160786), poly_from!(-0.9449205280933191, 3.7581604119299357, 0.0912076357315259, -2.70521261334262), poly_from!(-4.063752273608477, 0.23666446129272778, 3.615983739173071, 1.9069782770611177), poly_from!(2.054852102977481, -4.476958261656877, -1.3607434522281379, 1.830578239593378), poly_from!(2.5111337197479653, -2.2574845437288324, -1.0888304346434028, -3.5619563277290736), poly_from!(-4.6409257486673905, 2.2096993947503094, -1.1814779715226198, 2.415836872819388), poly_from!(-4.220564278400408, -3.315437885824725, -2.079044626803499, 0.936825120183161), poly_from!(-3.380319729066655, 4.963415493721403, 2.6722640254789436, 0.1301887474309087), poly_from!(-4.387659076508474, 2.1210080178481086, -3.3039003804503886, -4.079549346662807), poly_from!(1.1934070288234153, 0.3899005408157974, 3.6207256974179494, -3.836614353854894), poly_from!(-2.6252238393663765, -3.058681746501816, -1.5032980547731656, 2.9577063120662856), poly_from!(-2.1527984044529225, 2.95033327777295, 2.5549636161500295, -3.941044489406027), poly_from!(-1.2927732331400668, 3.2451959238018144, 3.1189487018153734, 0.07542971819497701), poly_from!(3.3406159388558194, 0.6658473074911289, -2.103653181914776, -4.521269404021436), poly_from!(3.411925934253782, -0.31429189088408194, -0.3162796883995247, -0.6113491651144853), poly_from!(1.966916149668978, -3.3164113871294507, 4.752254555778535, 2.964184920323727)], 9, 9); let m2 = mat!(&vec![poly_from!(0.37755475169830266, 4.073731480363348, 2.5684518757080967, 1.6598800240631162), poly_from!(4.945322414104044, 1.074465394141317, -2.873387686240383, 3.5184934460039834), poly_from!(-3.083239115801354, -4.873127308660369, -2.2532663036858525, 4.549850145499585), poly_from!(-0.42081206372348134, 0.3554082565602492, 2.368980745023287, -4.684495957795564), poly_from!(-4.722193427809095, -4.684981473921992, -2.734135259772531, -4.11653557704552), poly_from!(2.161915242320803, 4.982823409142018, 0.30562400509273147, 3.3426502613492506), poly_from!(0.3543241910784207, -1.8955671407590557, 3.1868686358837497, -3.0579927705309586), poly_from!(-2.429086063968752, 1.6630748016653643, 1.2074183524120148, 0.5393582240553325), poly_from!(-3.1314606503997733, -3.6333027726210476, 1.4923038809001374, 4.239935437553683), poly_from!(1.076008824436606, 2.117239111315291, -0.7470629718011255, -2.3922341451442266), poly_from!(4.318228188114748, -3.3456564474120967, 4.4179250070988925, 2.4941925597931984), poly_from!(2.137465619010709, -3.365659690185897, -2.981955082438912, 4.723970069324356), poly_from!(-3.910535150101854, -3.2252527788314245, 0.6624947026544916, -1.6876106359973275), poly_from!(0.5489935237941799, -3.384506099501383, 0.2651352915960947, -0.16758676455102073), poly_from!(4.914251316773926, -2.9880598609665587, -4.834973435759071, 2.593880686983301), poly_from!(1.3381858815893688, -1.229002733314041, -4.194963116852154, -0.2711545319566566), poly_from!(-2.585585473679167, -3.0631627889602098, -3.580526829383733, 0.0980592428951379), poly_from!(-2.8726025226135388, -0.6450719869830941, -2.104663356303267, 2.9952530304010576), poly_from!(1.0692788303286394, -3.5317904210098527, -4.352689749150349, 4.077960937635446), poly_from!(-4.102656615741766, 4.3553095188134705, -1.2136155176892673, -1.570508463443728), poly_from!(3.1196397163910454, 2.249845412596563, -2.0509429020341354, -0.42926926490042394), poly_from!(0.8103737127408763, -0.9946367218042527, -3.264154189937, 2.06961448029406), poly_from!(-0.13500080195952524, -4.979985875331032, -1.2880820622522249, -4.956097587859948), poly_from!(-1.6849662218248995, 0.9497988123579333, 2.8297951367857372, 1.2096540191664111), poly_from!(3.429556142456791, -1.1616957890345603, 2.1235115774737743, -3.1515056688150747), poly_from!(0.003208095624477103, -0.08529174190712929, 1.6944210133265516, 1.5360447226397245), poly_from!(0.11478995137798798, -2.622793499178173, 1.6794265566155655, 3.2240057483839024), poly_from!(2.3310426797173562, 0.9526293337139302, 0.431792541933417, -0.468996697998735), poly_from!(4.333314019488899, 4.636771045025483, -0.2387236859990871, 2.867266582843647), poly_from!(4.919400330657709, 1.762361108669669, 2.8727196156401016, -0.4969040593298937), poly_from!(2.2084158464952175, 3.7494109875056143, 0.9722391074457963, 0.5418773009505937), poly_from!(-4.437543829120751, -0.8686766751568467, -3.2566299245226906, 0.9496680394166468), poly_from!(4.732835534444135, -0.39096082917086417, -3.1439365277640565, -2.6223683819126595), poly_from!(3.0446283397054916, 3.7949717759168777, 2.456951314722855, -2.7555399862431207), poly_from!(4.912651248379856, 0.21346130387711248, 1.3136765394260363, -4.121884831669547), poly_from!(-0.633614224325461, 0.38022305265004697, -2.913447681780367, 4.21864903279136), poly_from!(-3.3043202331023203, -4.391444694360127, 2.085513902776918, 2.646089427195929), poly_from!(-3.704767138129581, -2.3469834794189524, 2.4154677588799682, -1.9544292419806784), poly_from!(-2.169743428155612, 3.4667307683701907, 3.7958400328185, -0.3224187243250123), poly_from!(4.916894662107277, 2.783751017230581, 3.257530602168826, -2.9962540409177265), poly_from!(4.635043683884438, -2.81798762230266, 4.149335686421576, -4.9090301160924055), poly_from!(-0.14492589186081517, 3.503424918827731, 3.9701890164333413, 0.8610423114535726), poly_from!(2.3582130461552406, -4.03902416502834, -4.4526925278483995, 1.2914077097957568), poly_from!(-0.5934457074614752, 1.4307892262424158, 0.7823343124305557, -2.7230452538561134), poly_from!(-3.0367313913457874, 0.2695161074532404, 2.0992962897346032, 4.81889530375391), poly_from!(3.9905685367673556, -4.355622451430698, -4.496834713372227, 2.663570990566666), poly_from!(-0.7971365148570575, -1.0653716182468207, -2.00745628666077, 2.0187219337199824), poly_from!(1.9655038036890033, -2.6062983310451826, 2.9555147213974395, -3.6528066213489896), poly_from!(-1.474743443147355, -2.4978999688286, 0.7651531173807546, -1.933160394604685), poly_from!(-0.2500036698424637, -4.60494396661884, -2.1537621272788456, -3.8579239943109878), poly_from!(2.34368235316441, -2.4486662391939804, -3.265076301449005, -2.941393337612417), poly_from!(-1.5286645461723367, -4.532859103564637, 4.5546580334742774, -0.15263452548986933), poly_from!(3.3826058190265194, -0.6394252828471236, 2.3838076220663496, 3.1002182712973916), poly_from!(-2.9610771244647838, 4.070667773403864, 0.09876485686055858, -1.5554805793668578), poly_from!(-1.606404502279629, -1.400952177367274, 0.5161241729990271, 3.951653518689831), poly_from!(1.1763509203410312, -2.2887562791574254, 0.8754581378201776, 2.4042591970839355), poly_from!(0.44686488700637295, -3.7380443636367886, 0.6827748603288395, -4.351690749779707), poly_from!(-3.233127730211862, 0.5116286831760251, -4.00180823016527, -3.621724412456999), poly_from!(-0.8423680173546222, 3.4222368921996864, 1.1984657608575802, 2.7090424104081663), poly_from!(3.5926330822156736, -4.984744642734428, 1.108278466140968, 3.3615929709965258), poly_from!(-2.401923770922089, 3.4544543666086884, 4.76046795811008, -2.5091873533318063), poly_from!(-4.3022451845272585, 4.2579826829116225, 1.1465470727232283, -4.852661409478323), poly_from!(0.4858280540890645, -4.470200743144891, -4.687673629865591, 2.5638680792842337), poly_from!(-2.118992271329734, 1.2746745875173904, -0.9893012567665203, 2.191901255591456), poly_from!(-4.955540320633172, 1.2286404442573229, -4.294270154950678, -3.101082906240239), poly_from!(0.9075197095683762, 3.1928866191838985, -3.555924672124587, 4.072983416359403), poly_from!(-3.262166634589031, -4.089857477436735, 4.078366996177413, 2.94784193503218), poly_from!(3.5622984948448426, -0.6107845934921379, -4.709209667481078, -0.9625551596574216), poly_from!(-1.0135598381629265, 1.8479472604462703, -0.8192465128775623, 0.4197921587439071), poly_from!(2.325936991036185, 2.022011362226311, -1.2714979901162948, -4.564502364772366), poly_from!(-1.7440992817164611, 3.6249202130612304, 4.787114708604136, 4.114121781477616), poly_from!(-2.4348603152338377, 1.6117127359387382, 2.9187199200065708, 3.764538632661308), poly_from!(-4.75345504241805, -3.4077851300635764, 4.5885870084109115, 0.511717540996389), poly_from!(3.435733663525138, -4.569862769602812, 4.521571234614623, -1.3146678730559556), poly_from!(1.2393967327572577, -4.369990840060872, -3.1686602994125335, -3.661639332816976), poly_from!(-4.911279343056261, -1.245431216956585, -4.945882278461103, -1.3609819387052848), poly_from!(4.788504647756513, -4.857150497531613, 2.6285819328670934, -4.189405316900686), poly_from!(2.4223405419522637, 3.609621366996789, -4.6281104390441, -1.393167425341523), poly_from!(4.420996577065589, 2.7939165142669715, 3.915926756575967, -4.949502338084306), poly_from!(0.8702960104038526, -0.7407967998084652, -1.887825699102239, -0.25958692299719743), poly_from!(-2.2055802600706134, -2.5430049369811036, -2.6494454381378163, 2.073329001415387)], 9, 9); let m3 = m1 * m2; print_expr!(m3.latex()); /* inverse_left inverse_right */ let m1 = rand_f64_matrix(20, 5); let m2 = rand_f64_matrix(5, 20); let m3 = m1.inverse_left().unwrap(); let m4 = m2.inverse_right().unwrap(); print_expr!((m3 * m1).similar_one(1e-10), (m2 * m4).similar_one(1e-10)); let m1 = rand_cplx_matrix(20, 5); let m2 = rand_cplx_matrix(5, 20); let m3 = m1.inverse_left().unwrap(); let m4 = m2.inverse_right().unwrap(); print_expr!((m3 * m1).similar_one(1e-10), (m2 * m4).similar_one(1e-10)); let m1 = rand_frac_matrix(8, 5); let m2 = rand_frac_matrix(5, 8); let m3 = m1.inverse_left().unwrap(); let m4 = m2.inverse_right().unwrap(); print_expr!((m3 * m1).eq_one(), (m2 * m4).eq_one()); /* step */ let m1 = rand_f64_matrix(4, 4); let (m2, independent_cols, neg) = m1.step(true, true); print_expr!(m1, m2); println!("{:?}, {}", independent_cols, neg); // if independent_cols.len() == 100 { // print_expr!(m2.similar_one(1e-10)); // } let m1 = rand_cplx_matrix(5, 10); let (m2, independent_cols, neg) = m1.step(true, true); print_expr!(m1, m2); println!("{:?}, {}", independent_cols, neg); let m1 = rand_frac_matrix(4, 6); let (m2, independent_cols, neg) = m1.step(true, true); print_expr!(m1, m2); println!("{:?}, {}", independent_cols, neg); /* det det_def */ let m1 = rand_f64_matrix(10, 10); let (m1_, _, neg) = m1.step(false, false); let mut det = if neg { -1.0 } else { 1.0 }; for i in 0..*m1_.get_row() { det *= m1_.get_kernel()[i * *m1_.get_col() + i]; } print_expr!(det); let m2 = m1.det(); let m3 = m1.det_def(); print_expr!(m1_, m2, m3); let m1 = rand_cplx_matrix(10, 10); let m2 = m1.det(); let m3 = m1.det_def(); print_expr!(m2, m3); let m1 = rand_frac_matrix(10, 10); let m2 = m1.det(); let m3 = m1.det_def(); print_expr!(m2, m3); let m1 = mat!(&vec![poly_from!(0.25809800062624966, -2.50796210202176, -4.455563019658002, -2.6459774496197275), poly_from!(3.084823571224053, 0.5736459084331171, 3.4926078047813505, 0.9403152158134143), poly_from!(-4.905740446336728, 1.271227818533597, 4.263668971990297, -3.056126255460143), poly_from!(3.8688765956870217, -2.396520195028655, 2.8011018967542176, -4.4732470713992445), poly_from!(-0.44756923078355726, -2.025900475411655, -1.9734577281803292, 2.595702268897414), poly_from!(4.119867533754384, -1.5112808538705869, -3.38097645024812, 4.625241870570569), poly_from!(-2.8605817945802214, 4.291492543660041, -1.153927804113486, -1.7112074931583185), poly_from!(3.4468690748034465, 0.632273090697586, 3.0125315110058324, 0.40253909251709175), poly_from!(1.724290193150571, 4.046420929859542, -1.5832249947633081, -4.768877298838219), poly_from!(-1.922633042479279, -3.1489830399596697, 4.7317936344550215, 2.220038268988686), poly_from!(2.359338101119981, 2.097652538437882, 1.5061440568260842, -4.955796336947257), poly_from!(-3.5791488552032282, 0.25336212443081596, -1.298526648317062, -1.4075074321072032), poly_from!(-2.9430637989128194, 1.9858858039241865, 0.5669815814197667, -3.4054603182099963), poly_from!(1.5297802622084964, 1.689729542266189, -4.051111703324933, -1.0749822703485936), poly_from!(3.3266888051324806, 0.25889390806589496, 1.07032648439516, -3.6398372133306456), poly_from!(-1.2992756793333893, 2.8176140497117146, 1.7088560584759263, -2.6917065176085564), poly_from!(2.081980651656192, 0.8895301538624478, 4.037578416354515, 0.7046925789916596), poly_from!(0.19088338644875869, -4.535159833442128, -1.661250490180135, 1.4751799299824206), poly_from!(-2.075161690335471, -2.672488335228941, -1.552997903418233, 4.8049649550611235), poly_from!(0.17373035148827043, 3.9385841030240876, -4.26566264935105, -3.0861564271053696), poly_from!(4.810986608801695, -0.0357601125318201, -1.6081934687657906, -1.458560652401466), poly_from!(-3.545299826145066, 2.7684685202293267, -0.7416116586249286, 2.6113619779408292), poly_from!(3.1519431503470052, -3.140442734012867, 4.51080557024825, 3.9397338914273767), poly_from!(-1.3476262758435373, -1.6735306765324531, -0.41135895387924926, -1.0290042865725821), poly_from!(1.8920100528507415, -0.17389301633778853, -2.243446124853936, 4.599688479354812), poly_from!(3.4260863274168543, -2.2583078983961125, 1.2262485109889294, 0.3125664214355828), poly_from!(2.9408982638794647, 4.355728833056688, 4.246055273571386, 1.97872630217379), poly_from!(1.5139141862239889, 4.9583253341099045, 3.8263120891846167, 1.1763434549638374), poly_from!(3.390457276501621, 0.9295151762190743, -0.33059077407982773, -4.26971530767973), poly_from!(-1.6181398687819848, 3.3494473094417447, -0.8800923749314826, -0.6141190467988524), poly_from!(3.996458302341388, 2.745541168050817, 4.217990711332805, 2.777072370202289), poly_from!(-3.5921865653275686, -0.390164760573219, -1.8314867442071003, 1.9237717982152738), poly_from!(-3.846445770647705, -2.453253852890356, 3.1949834058742255, -4.174200902064933), poly_from!(-3.213303088677643, -3.966324282413595, -1.6058129667919707, -0.5032777805853943), poly_from!(-4.251364487160175, -3.114622498564291, -0.13109062178294373, -2.390766044823801), poly_from!(-1.8294652021424707, 4.679487794159579, 1.97081143998658, 0.8189770899664106), poly_from!(-2.6938275799581235, 3.876073756360629, -3.209763593383148, 2.7621521965526608), poly_from!(-1.0410721541046932, -3.4620427408923407, -4.406326264379285, -0.4978905460866443), poly_from!(2.623514855856829, 4.899893730040702, 2.6931358863045674, 0.39544072114616835), poly_from!(-2.093497084472824, -4.40160962732009, -0.7437103824879046, -2.9539841411624845), poly_from!(1.4937221837472503, -1.28847903486324, 2.885164498799072, -4.785900132712854), poly_from!(-4.634059679300066, -0.8381040918980798, 2.141771600864325, -0.2950648799495257), poly_from!(-4.637042354959753, -2.4963014645440285, 1.2616070349548822, 4.507035503776459), poly_from!(-0.9359806524951395, -1.768229178933436, 2.518574913755238, -4.729720211418238), poly_from!(0.960107894333686, 2.6141141049471317, -0.4755512711305876, 4.443728086786654), poly_from!(4.1106099849307185, 0.7997873673797216, 2.731584510600376, -1.6828426882280887), poly_from!(-1.950080063527937, 2.715088374765471, 0.5551012670095812, 3.741798373329379), poly_from!(2.690234294334557, -1.9888913469431122, 3.069600100378892, 4.492912853915884), poly_from!(-4.351914767240728, 2.7525765267232476, 2.600832793526239, -4.564625289587564), poly_from!(-1.5594407917226052, -2.11879049080276, -2.3656906695309643, -0.2865081404048109), poly_from!(-2.828366410365626, -4.705861278468239, -1.7566082171229103, 3.158868014229334), poly_from!(4.033985363448011, -3.531659272970397, -4.923256277188138, -0.09009050520322415), poly_from!(-3.6827366235408343, -1.240489987790736, -0.8497035270958779, 4.30288316874041), poly_from!(-2.789435696673145, 3.16587315077021, -4.340853075353395, 2.5945548202180744), poly_from!(-1.5426112967227068, 1.6873901871997452, 4.8246775761182885, 2.8434367251215473), poly_from!(-0.14203005808220848, 0.7334426970975114, 0.5250844402201889, -3.1493523649730104), poly_from!(1.319368144334648, -2.7202925340233843, 4.765925316825413, -4.927518869545306), poly_from!(4.281379148680395, 1.146688533019459, 2.0368331299041023, -0.610516843075164), poly_from!(-3.948546590103427, -0.5810735130637115, -0.645245554594867, -2.250345594818489), poly_from!(4.041353725180839, -0.3981808507519302, -1.7789179894372231, -3.1571619439637653), poly_from!(2.086351386708177, -1.2971534112537029, -2.162010357945876, -1.9511579297043324), poly_from!(0.09018400763364465, -3.8513068974665696, 4.921000758410321, 0.6808514594996717), poly_from!(-3.5673934827836695, 3.3425134060046595, -1.229742194542116, 1.3280743877336834), poly_from!(-0.7881538786811753, 0.34229858275279135, -2.1783305717317356, -4.370833363260705), poly_from!(2.4540328367818995, -3.699820122376419, 2.4606615037409796, 3.7308601601669693), poly_from!(1.349777066171935, -4.2904220135948705, -0.47456810909560687, 0.28574467670160786), poly_from!(-0.9449205280933191, 3.7581604119299357, 0.0912076357315259, -2.70521261334262), poly_from!(-4.063752273608477, 0.23666446129272778, 3.615983739173071, 1.9069782770611177), poly_from!(2.054852102977481, -4.476958261656877, -1.3607434522281379, 1.830578239593378), poly_from!(2.5111337197479653, -2.2574845437288324, -1.0888304346434028, -3.5619563277290736), poly_from!(-4.6409257486673905, 2.2096993947503094, -1.1814779715226198, 2.415836872819388), poly_from!(-4.220564278400408, -3.315437885824725, -2.079044626803499, 0.936825120183161), poly_from!(-3.380319729066655, 4.963415493721403, 2.6722640254789436, 0.1301887474309087), poly_from!(-4.387659076508474, 2.1210080178481086, -3.3039003804503886, -4.079549346662807), poly_from!(1.1934070288234153, 0.3899005408157974, 3.6207256974179494, -3.836614353854894), poly_from!(-2.6252238393663765, -3.058681746501816, -1.5032980547731656, 2.9577063120662856), poly_from!(-2.1527984044529225, 2.95033327777295, 2.5549636161500295, -3.941044489406027), poly_from!(-1.2927732331400668, 3.2451959238018144, 3.1189487018153734, 0.07542971819497701), poly_from!(3.3406159388558194, 0.6658473074911289, -2.103653181914776, -4.521269404021436), poly_from!(3.411925934253782, -0.31429189088408194, -0.3162796883995247, -0.6113491651144853), poly_from!(1.966916149668978, -3.3164113871294507, 4.752254555778535, 2.964184920323727)], 9, 9); let m2 = m1.det_def(); print_expr!(m2.latex()); } fn main() {}