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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab436e97ff76821f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.227.67 with SMTP id ry3mr24352846pbc.8.1341913843811; Tue, 10 Jul 2012 02:50:43 -0700 (PDT) Path: l9ni11304pbj.0!nntp.google.com!news2.google.com!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Does Ada need elemental functions to make it suitable for scientific work? Date: Tue, 10 Jul 2012 11:50:38 +0200 Organization: cbb software GmbH Message-ID: References: <18c77859-480c-41f5-bb1c-df7ad067f4f3@googlegroups.com> <637de084-0e71-4077-a1c5-fc4200cad3cf@googlegroups.com> <1wqz1wr8wto96.1fwpyip6ct1z9.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-07-10T11:50:38+02:00 List-Id: On Tue, 10 Jul 2012 04:21:17 -0500, Nasser M. Abbasi wrote: > On 7/10/2012 4:07 AM, Dmitry A. Kazakov wrote: >> On Tue, 10 Jul 2012 03:39:58 -0500, Nasser M. Abbasi wrote: >> >>> That is a start. But not enough by any means. All functions should be >>> vectorized. >> >> It is ill-defined. E.g. exp(A), where A is a matrix. Is exp(A) a matrix of >> exponents or exponent matrix? [...] > Just like when I read a paper, I first look for the definitions > of symbols and terms used by the author. Exactly. This is how you define it, it is not how LaTeX or TeX does. Since there is no unambiguous semantics of f(), the language shall not introduce them. If you want scalar f() to apply to a matrix in some certain way, just define that in Ada. You can even do it in generic way: 1. Using generics: generic with function Scalar_F (X : Float) return Float; function Generic_Vector_F (X : Vector) return Vector; function Generic_Vector_F (X : Vector) return Vector is begin return Result : Vector (X'Range) do for I in X'Range loop Result (I) := Scalar_F (X (I)); end loop; end return; end Generic_Vector_F; function Sin is new Generic_Vector_F (Sin); function Cos is new Generic_Vector_F (Cos); ... ------------------------------------------------------------- 2. Using functional composition: function "*" ( F : not null access function (X : Float) return Float; X : Vector ) return Vector is begin return Result : Vector (X'Range) do for I in X'Range loop Result (I) := F (X (I)); end loop; end return; end "*"; Used as: sin'Access * V -- Applies sin to V -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de