From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=2.0 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,32d9aa9d79729b31 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.228.227 with SMTP id sl3mr13856521pbc.5.1340645762964; Mon, 25 Jun 2012 10:36:02 -0700 (PDT) Path: l9ni18955pbj.0!nntp.google.com!news1.google.com!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: Any easy/build-in construct to extract submatrices from larger matrix? Date: Mon, 25 Jun 2012 12:36:00 -0500 Organization: Aioe.org NNTP Server Message-ID: References: <1xzo3825h9yt7$.45flobqwlel6.dlg@40tude.net> <4FE896B5.10405@obry.net> Reply-To: nma@12000.org NNTP-Posting-Host: KdJUrTuvv3Zv/s8pPxNluw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Date: 2012-06-25T12:36:00-05:00 List-Id: On 6/25/2012 11:49 AM, Pascal Obry wrote: > Le 25/06/2012 08:32, Nasser M. Abbasi a �crit : >> In Mathematica for example, I do this whole operation in one line: >> >> --------------------------- >> Table[ReplacePart[A,{{i},{i,_},{_,j}}:>Sequence[]],{i,nRow},{j,nCol}]; >> --------------------------- > > Which is just unreadable if you ask me... > > Pascal. > Well, it is just because you are not used to the syntax. I am sure. Just like when I read Perl, I do not understand it at all, but I am sure someone who knows Perl, they would be able to write in few words or lines some code to parse some strings, in what would take me pages to write. Once one gets used to the syntax and using pattern matching and functional programming, it will become easy to read and understand, and one will probably find it hard to go back to writing long imperative code to do what they can do in few lines of functional code. Here is another one: Given a square matrix, determine if the matrix is diagonal or not. The function will return true if matirx is diagonal, and false otherwise. A diagonal matrix is one which have zeros everywhere off the diagonal. In Mathematica, this one line function does it diagQ[m_] := m === DiagonalMatrix[Diagonal[m]] Hence, given a matrix such as a={{1,0,0}, {0,2,0}, {0,0,0}} diagQ[a] ----> True All what it does, is build up a diagonal matrix using the diagonal elements of the matrix, and checks if the result is identical to the matrix itself. If I have to do this in Ada (unless there is build in function to do this), I might have to use loops and check each element off the diagonal, exist loop once I find non-zero element off the diagonal, etc... and end up writing 20 lines of code at least. (also I might have to make a contract pre/post may be, not sure, may be not). And I am not sure that will be more readable or easier to maintain at the end. ps. the above function does not have checks on its arguments, but I can add these easily to make it more robust (using MatrixQ check for example, and a check for matrix being square matrix, all easy/short code to do). regards, --Nasser