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,ab436e97ff76821f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.241.162 with SMTP id wj2mr24147980pbc.2.1341909600275; Tue, 10 Jul 2012 01:40:00 -0700 (PDT) Path: l9ni11278pbj.0!nntp.google.com!news1.google.com!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: Does Ada need elemental functions to make it suitable for scientific work? Date: Tue, 10 Jul 2012 03:39:58 -0500 Organization: Aioe.org NNTP Server Message-ID: References: <18c77859-480c-41f5-bb1c-df7ad067f4f3@googlegroups.com> <637de084-0e71-4077-a1c5-fc4200cad3cf@googlegroups.com> 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-07-10T03:39:58-05:00 List-Id: On 7/10/2012 3:02 AM, gautier.de.montmollin@gmail.com wrote: > Le mardi 10 juillet 2012 07:22:58 UTC+2, Ada novice a �crit : > >> Believe me, for someone who do numerical computations on a daily basis, an operation >like V**2 is a NECESSITY. It's a pity that Ada does not offer such a facility. >I do not blame those who stick to Matlab (or Fortran?) for doing numerical computations. > > Wait... There are *such* facilities and several built-in operations *like* that: > http://www.ada-auth.org/standards/12rm/html/RM-G-3-1.html > > Apparently it is not enough. But it is possible to make a proposal for > the next standard (and short term for the next GNAT version). > That is a start. But not enough by any means. All functions should be vectorized. Even user defined ones. In Ada, I can't even take the sin of a vector ---------------------- with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions; procedure foo3 is type array_t is array(1..5) OF float; D : constant array_t :=(0.1,0.2,0.3,0.4,0.5); V : array_t; begin -- V := sin(D); -- ERROR for I in D'Range loop -- must use a LOOP V(I) := sin(D(I)); end loop; end foo3; -------------------- I can ofcourse overload sin, hide the loop inside my own sine and then do V:= myPackage.sin(D); All of this is possible in Ada. It is just a little (alot?) more effort compared to what is out there. octave/Matlab: -------------------------- D=[0.1,0.2,0.3,0.4,0.5]; sin(D) ans = 0.0998 0.1987 0.2955 0.3894 0.4794 --------------------------- > The snag with that *specific* operation, v**2 meaning "v(i)**2 for each i", >is that it is counter-intuitive from a linear algebra point of view. You >would rather expect v**2 = v*v. Now another snag is should "*" be the >dot or the cross product ?... > > These kind of things are thought-out carefully before landing into an Ada standard... > But these issue have been solved long time time. (like maybe 30 years ago? and are well defined for all cases: http://www.mathworks.com/help/techdoc/ref/arithmeticoperators.html There are element-wise operators, and operators that work on the whole vector or matrix. In octave/Matlab world, V.^2 means element-wise. (notice the ".") ------------------------- octave:3> V=[1 2 3 4]; octave:4> v.^2 ans = 1 4 9 16 -------------------------- Otherwise, it becomes standard matrix operation. A^2 means A*A ------------------------ octave:17> A=[1 2;3 4] A = 1 2 3 4 octave:18> A^2 ans = 7 10 15 22 octave:19> A*A ans = 7 10 15 22 --------------------- To do dot product, it has its own operator, called dot() ! ---------------------- octave:5> dot(V,V) ans = 30 ------------------------- To do cross product, it has its own operator, called cross() ! ----------------------- octave:9> D=[1 2 3]; V=[3 4 5]; cross(D,V) ans = -2 4 -2 ------------------- btw, in Mathematica, it is the other way around. V*V does element by element multiplication, and V.V does matrix product. It has also Dot[] and Cross[] and all functions are vectorized, and all user defined functions can be vectorized by simply giving them the attribute Listable. --Nasser