<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Even with cancellation, the number of bits required to represent the exact terms involved in computing the inverse grow like O(n log n) in the typical case, IIRC. &nbsp;So exact arithmetic rapidly becomes unfeasible for even modestly large matrices.</div><div class=""><br class=""></div><div class="">Aside from purely symbolic matrices that come up in theoretical physics and matrices over finite fields, the entries of a matrix are rarely known exactly, so the rich set of approximate-rank-revealing and numerically stable methods that we have for floating-point turn out to be much more useful anyway.</div><div class=""><br class=""></div><div class="">That’s not to say that it isn’t fun to play around with these concepts, of course =)</div><div class=""><br class=""></div><div class="">– Steve</div><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 13, 2016, at 11:27 PM, Matt Whiteside &lt;<a href="mailto:mwhiteside.dev@gmail.com" class="">mwhiteside.dev@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 13, 2016, at 11:16, Stephen Canon &lt;<a href="mailto:scanon@apple.com" class="">scanon@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">… in exact arithmetic, not in floating-point, which is what people tend to actually use for matrices. &nbsp;For that matter, the entire notion of “invertible” as a binary attribute is problematic when dealing with approximate arithmetic; a matrix may be formally invertible but so ill-conditioned that the result is effectively meaningless.</div><div class=""><br class=""></div><div class="">Not really trying to shoot you down, just observing that this is an extremely subtle example with lots of hidden sharp edges.</div><div class=""><br class=""></div><div class="">– Steve</div></div></div></blockquote></div><br class=""></div><div class="">That’s a good point. &nbsp;So then I wonder if exact arithmetic wouldn’t be good enough for a lot of entry level math &amp; science applications, especially the ones where this type of approach would come to mind in the first place.</div><div class=""><br class=""></div><div class="">Something like,</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Rational:</span><span style="font-variant-ligatures: no-common-ligatures;" class="">CustomDebugStringConvertible</span><span style="font-variant-ligatures: no-common-ligatures;" class="">{</span></div></div></blockquote><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">let</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class=""> numerator, denominator: </span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><br class=""><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">var</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class=""> debugDescription:</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">String</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">{</span><br class=""><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp;&nbsp;</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">get</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">{</span><br class=""><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">return</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">"</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">\</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">(</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Double</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(79, 129, 135); font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">numerator</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">)/</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Double</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(79, 129, 135); font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">denominator</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">)</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">)"</span><br class=""><span class="Apple-tab-span" style="font-family: Menlo; white-space: pre;">        </span>&nbsp; &nbsp;&nbsp;<span style="font-family: Menlo;" class="">}</span><br class=""><span class="Apple-tab-span" style="font-family: Menlo; white-space: pre;">        </span><span style="font-family: Menlo;" class="">}</span><br class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> *(lhs:</span><span style="font-variant-ligatures: no-common-ligatures" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures;" class="">,rhs:</span><span style="font-variant-ligatures: no-common-ligatures" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures;" class="">{</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures" class="">(numerator: lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">numerator</span><span style="font-variant-ligatures: no-common-ligatures" class="">*rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">numerator</span><span style="font-variant-ligatures: no-common-ligatures" class="">,&nbsp;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; denominator: lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">denominator</span><span style="font-variant-ligatures: no-common-ligatures" class=""> * rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">denominator</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *(lhs:</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">,rhs:</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures" class="">(numerator: lhs*rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">numerator</span><span style="font-variant-ligatures: no-common-ligatures" class="">,&nbsp;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; denominator: rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">denominator</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> π = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Rational</span><span style="font-variant-ligatures: no-common-ligatures" class="">(numerator: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">355</span><span style="font-variant-ligatures: no-common-ligatures" class="">, denominator: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">113</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> two_π = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">*</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">π</span></div><div class=""><br class=""></div></div></blockquote><div class=""><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class="">might get you pretty far with 64 bits.</div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class="">Matt</div></div></div></div></blockquote></div></body></html>