Array programming: Difference between revisions

Content deleted Content added
Scalar languages: mentioned how vectorization shows up in C
mNo edit summary
Tags: Reverted Visual edit
Line 1:
{{Programming paradigms}}در [[Computer science|علوم کامپیوتر]] ، برنامه نویسی آرایه به راه حلهایی اطلاق می شود که اجازه می دهد اعمال را برای یک مجموعه کامل از مقادیر همزمان انجام دهید. اینگونه راه حلها معمولاً در محیطهای [[Computational science|علمی]] و [[Engineering|مهندسی]] مورد استفاده قرار می گیرند.
{{Programming paradigms}}
In [[computer science]], '''array programming''' refers to solutions which allow the application of operations to an entire set of values at once. Such solutions are commonly used in [[computational science|scientific]] and [[engineering]] settings.
 
Modernزبانهای programmingبرنامه languagesنویسی thatمدرنی supportکه arrayاز programmingبرنامه نویسی آرایه پشتیبانی می کنند (alsoهمچنین knownبه asزبانهای [[vectorVector (computing)|vectorبرداری]] orیا چند بعدی نیز '''multidimensional'''معروف languagesهستند) haveبه beenطور engineeredخاص specificallyمهندسی toشده اند generalizeتا operationsعملیات onروی [[scalarScalar (computing)|scalarمقیاس ها]]s toرا applyتعمیم transparentlyدهند toتا به طور شفاف [[vectorVector (geometric)|vectorبردارها]]s, ، [[matrixMatrix (mathematics)|matricesماتریس ها]], andو higher-dimensionalآرایه های بعدی بالاتر اعمال arraysشوند. Theseاین includeموارد شامل [[TK Solver|(به صورت لیست ها)]] [[APL (programming language)|APL]], ، [[J (programming language)|J]], ، [[Fortran 90]], ، Mata, ، [[MATLAB]], ، [[Analytica (software)|Analytica]], ، [[TK Solver]] (asای lists),پی [[GNUال، Octave|Octave]], [[، R (programming language)|R]],، [[Cilk Plus]], ، [[Julia (programming language)|Julia]], ، [[Perl Data Language|Perl Data Language (PDL)]], andو theپسوند [[NumPy]] extension toبه [[Python (programming language)|Pythonپایتون]] است. Inدر theseاین languages,زبان anها operation، thatعملیاتی operatesکه onروی entireکل arraysآرایه canها beعمل calledمی aکند ''vectorized''را operation,<ref>{{citeمی journalتوان |title=Theیک NumPyعمل array:بردار aنامید structure، forبدون efficientتوجه numericalبه computationاینکه |author=Stéfanروی van der Walt[[Vector processor|author2=S.پردازنده Chrisبرداری]] Colbertاجرا |author3=Gaëlمی Varoquauxشود |name-list-style=ampکه |journal=Computingدستورالعمل inهای Scienceبرداری andرا Engineeringاجرا |volume=13می |issue=2 |pages=22–30 |publisher=IEEE |year=2011 |doi=10.1109/mcse.2011.37|bibcode=2011CSE....13b.کند.22V |arxiv=1102.1523برنامه }}</ref>نویسی regardlessآرایه ofبه whetherطور itخلاصه isایده executedهای onگسترده aای [[vectorرا processor]], which implements vector instructions. Array programming primitives concisely expressدرباره broadدستکاری ideasداده aboutبیان dataمی manipulationکند. Theسطح levelجمع ofبندی concisionدر canموارد beخاص dramaticمی inتواند certainچشمگیر casesباشد: itیافتن isزبان notبرنامه uncommonنویسی to find array programming languageآرایه [[oneOne-liner program|one-linersیک خطی]] thatکه requireبه severalچندین pagesصفحه ofکد object-orientedشی گرا نیاز دارد ، غیرمعمول codeنیست.
 
==مفهوم آرایه ها==
==Concepts of array==
The fundamental idea behind array programming is that operations apply at once to an entire set of values. This makes it a [[high-level programming language|high-level programming]] model as it allows the programmer to think and operate on whole aggregates of data, without having to resort to explicit loops of individual scalar operations.
 
[[Kenneth E. Iverson]] described the rationale behind array programming (actually referring to APL) as follows:<ref name=":0">{{cite journal |author= Iverson, K. E. |title= Notations as a Tool of Thought. |journal= Communications of the ACM |volume= 23 |issue= 8 |pages= 444–465 |year= 1980 |url= http://www.jsoftware.com/papers/tot.htm |access-date= 2011-03-22 |doi= 10.1145/358896.358899 |archive-url= https://web.archive.org/web/20130920071911/http://www.jsoftware.com/papers/tot.htm |archive-date= 2013-09-20 |url-status= dead |author-link= Kenneth E. Iverson |doi-access= free }}</ref>
{{quote|most programming languages are decidedly inferior to mathematical notation and are little used as tools of thought in ways that would be considered significant by, say, an applied mathematician.
The thesis is that the advantages of executability and universality found in programming languages can be effectively combined, in a single coherent language, with the advantages offered by mathematical notation. it is important to distinguish the difficulty of describing and of learning a piece of notation from the difficulty of mastering its implications. For example, learning the rules for computing a matrix product is easy, but a mastery of its implications (such as its associativity, its distributivity over addition, and its ability to represent linear functions and geometric operations) is a different and much more difficult matter.
 
ایده اساسی در پشت برنامه نویسی آرایه این است که عملیات به یک باره برای کل مجموعه مقادیر اعمال می شود. این امر آن را به یک مدل [[High-level programming language|برنامه نویسی سطح بالا]] تبدیل می کند زیرا به برنامه نویس اجازه می دهد تا روی کل جمع آوری داده ها فکر کند و کار کند ، بدون اینکه به حلقه های صریح عملیات اسکالر جداگانه متوسل شود.[[Kenneth E. Iverson]] دلیل اصلی برنامه نویسی آرایه (در واقع اشاره به APL) را به شرح زیر شرح داد:<ref name=":0" />
Indeed, the very suggestiveness of a notation may make it seem harder to learn because of the many properties it suggests for explorations.
 
{{quote|اکثر زبانهای برنامه نویسی نسبت به نت ریاضی فراتر هستند و از آنها به عنوان ابزاری برای اندیشه استفاده نمی کنند ، مثلاً یک ریاضیدان کاربردی آنها را قابل توجه می داند.
تز این است که مزایای قابلیت اجرا و جهانی بودن در زبان های برنامه نویسی را می توان به طور موثر ، در یک زبان منسجم واحد با مزایای ارائه شده توسط نت ریاضی ترکیب کرد. مهم است که دشواری توصیف و یادگیری قطعه ای از نت را از دشواری تسلط بر پیامدهای آن تشخیص دهیم. به عنوان مثال ، یادگیری قوانین محاسبه یک محصول ماتریس آسان است ، اما تسلط بر پیامدهای آن (مانند ارتباط آن ، توزیع آن بر روی جمع ، و توانایی آن در نمایش توابع خطی و عملیات هندسی) یک مسئله متفاوت و بسیار دشوارتر است .
 
در واقع ، خود پیشنهادی بودن یک نت به دلیل خواص زیادی که برای اکتشافات به شما پیشنهاد می دهد ، یادگیری آن را دشوارتر نشان می دهد.
 
[...]
کاربران رایانه ها و زبان های برنامه نویسی غالباً در درجه اول به کارآیی اجرای الگوریتم ها توجه دارند و بنابراین ، ممکن است به طور خلاصه بسیاری از الگوریتم های ارائه شده در اینجا را کنار بگذارند. چنین اخراجی کوته بینانه خواهد بود زیرا معمولاً می توان از بیان صحیح الگوریتم به عنوان مبنایی استفاده کرد که می توان به راحتی الگوریتمی کارآمدتر از آن استخراج کرد.}}
Users of computers and programming languages are often concerned primarily with the efficiency of execution of algorithms, and might, therefore, summarily dismiss many of the algorithms presented here. Such dismissal would be short-sighted since a clear statement of an algorithm can usually be used as a basis from which one may easily derive a more efficient algorithm.}}
 
The basis behind array programming and thinking is to find and exploit the properties of data where individual elements are similar or adjacent. Unlike object orientation which implicitly breaks down data to its constituent parts (or [[scalar (computing)|scalar]] quantities), array orientation looks to group data and apply a uniform handling.
 
اساس برنامه نویسی و تفکر آرایه یافتن و بهره برداری از خصوصیات داده ها در جایی است که عناصر منفرد مشابه یا مجاور هستند. برخلاف جهت گیری شی object که به طور ضمنی داده ها را به قسمت های تشکیل دهنده آن تقسیم می کند (یا مقیاس های [[Scalar (computing)|مقیاس دار]]) ، جهت گیری آرایه به دنبال گروه بندی داده ها و اعمال یک دست زدن به یکنواخت است.
[[Function rank]] is an important concept to array programming languages in general, by analogy to [[tensor]] rank in mathematics: functions that operate on data may be classified by the number of dimensions they act on. Ordinary multiplication, for example, is a scalar ranked function because it operates on zero-dimensional data (individual numbers). The [[cross product]] operation is an example of a vector rank function because it operates on vectors, not scalars. [[Matrix multiplication]] is an example of a 2-rank function, because it operates on 2-dimensional objects (matrices). [[Reduce (higher-order function)|Collapse operators]] reduce the dimensionality of an input data array by one or more dimensions. For example, summing over elements collapses the input array by 1 dimension.
 
رتبه تابع یک مفهوم مهم برای زبانهای برنامه نویسی آرایه به طور کلی ، به قیاس با رتبه [[Tensor|تانسور]] در ریاضیات است: توابع که بر روی داده کار می کنند ، ممکن است براساس تعداد ابعادی که عمل می کنند ، طبقه بندی شوند. به عنوان مثال ضرب معمولی یک تابع دارای رتبه بندی مقیاسی است زیرا با داده های بعد صفر (اعداد منفرد) کار می کند. عملکرد [[Cross product|ضرب خارجی]] نمونه ای از یک تابع مرتبه برداری است زیرا از طریق بردارها عمل می کند نه مقیاس پذیرها. [[Matrix multiplication|ضرب ماتریس]] مثالی از یک تابع 2 درجه ای است ، زیرا روی اجسام 2 بعدی (ماتریس) عمل می کند. [[Reduce (higher-order function)|عملگرهای جمع آوری]] ابعاد آرایه داده ورودی را با یک یا چند بعد کاهش می دهند. به عنوان مثال ، جمع کردن عناصر ، آرایه ورودی را با 1 بعد جمع می کند.
==Uses==
Array programming is very well suited to [[implicit parallelization]]; a topic of much research nowadays. Further, [[Intel]] and compatible CPUs developed and produced after 1997 contained various instruction set extensions, starting from [[MMX (instruction set)|MMX]] and continuing through [[SSSE3]] and [[3DNow!]], which include rudimentary [[SIMD]] array capabilities. Array processing is distinct from [[parallel computing|parallel processing]] in that one physical processor performs operations on a group of items simultaneously while parallel processing aims to split a larger problem into smaller ones ([[MIMD]]) to be solved piecemeal by numerous processors. Processors with two or more cores are increasingly common today.
 
==موارد استفاده==
==Languages==
برنامه نویسی آرایه برای [[Implicit parallelization|موازی سازی ضمنی]] بسیار مناسب است. امروزه موضوع بسیاری از تحقیقات است بعلاوه ، [[Intel|اینتل]] و پردازنده های سازگار پس از 1997 تولید و تولید شدند که حاوی پسوندهای مختلف مجموعه دستورالعمل ها بودند ، از [[MMX (instruction set)|MMX]] شروع می شوند و از طریق [[SSSE3]] و [[3DNow!|3DNow]] ادامه می یابند! که شامل قابلیت های اولیه آرایه [[SIMD]] هستند. پردازش آرایه از [[Parallel computing|پردازش موازی]] متمایز است به این دلیل که یک پردازنده فیزیکی به طور همزمان بر روی گروهی از موارد کار می کند در حالی که پردازش موازی با هدف تقسیم یک مسئله بزرگتر به مشکلات کوچکتر ([[MIMD]]) انجام می شود تا توسط پردازنده های متعدد به صورت قطعه ای حل شود. پردازنده های دارای دو یا چند هسته امروزه به طور فزاینده ای رایج شده اند.
The canonical examples of array programming languages are Fortran, APL, and J. Others include: [[A+ (programming language)|A+]], [[Analytica (software)|Analytica]], [[Chapel (programming language)|Chapel]], [[IDL (programming language)|IDL]], Julia, [[K (programming language)|K]], Klong, [[Q (programming language from Kx Systems)|Q]], Mata, [[MATLAB]], [[MOLSF]], NumPy, [[GNU Octave]], [[Perl Data Language|PDL]], R, [[S-Lang (programming language)|S-Lang]], [[SAC programming language|SAC]], [[Nial programming language|Nial]], [[ZPL (programming language)|ZPL]] and [[TI-BASIC]].
 
===Scalarزبان languages=ها==
Theمثالهای canonicalمتعارف examplesزبانهای ofبرنامه arrayنویسی programmingآرایه languagesعبارتند areاز: Fortran, ، APL, andو J. Othersسایر includeموارد شامل: [[A+ (programming language)|A +]],، [[Analytica (software)|Analytica]],، [[Chapel (programming language)|Chapel]],، [[IDL (programming language)|IDL]],، Julia,Julia، [[K (programming language)|K]],، Klong,Klong، [[Q (programming language from Kx Systems)|Q]],، Mata,Mata، [[MATLAB]],، [[MOLSF]],MOLSF، NumPy, [[GNU Octave]],NumPy، [[Perl Data Language|PDL]],، R, [[S-Lang (programming language)|S -Lang]], ، [[SAC programming language|SAC]], ، [[Nial programming language|Nial]], ، [[ZPL (programming language)|ZPL]] and، [[TI-BASIC]]., [[GNU Octave]]
In scalar languages such as [[C (programming language)|C]] and [[Pascal (programming language)|Pascal]], operations apply only to single values, so ''a''+''b'' expresses the addition of two numbers. In such languages, adding one array to another requires indexing and looping, the coding of which is tedious.
 
===زبان های نرده ای (اسکالر)===
در زبانهای اسکالر مانند [[C (programming language)|C]] و [[Pascal (programming language)|Pascal]] ، اعمال فقط برای مقادیر منفرد اعمال می شوند ، بنابراین a + b بیانگر جمع دو عدد است. در چنین زبان هایی ، افزودن یک آرایه به دیگری به نمایه سازی و حلقه نیاز دارد ، کدگذاری آن خسته کننده است.
<syntaxhighlight lang="c">
for (i = 0; i < n; i++)
Line 34 ⟶ 37:
</syntaxhighlight>
 
در زبانهای مبتنی بر آرایه ، به عنوان مثال در Fortran ، حلقه تو در تو در بالا می تواند به صورت آرایه در یک خط نوشته شود.
In array-based languages, for example in Fortran, the nested for-loop above can be written in array-format in one line,
<syntaxhighlight lang="fortran">
a = a + b
</syntaxhighlight>
یا به جای آن ، برای تأکید بر ماهیت آرایه اشیا
or alternatively, to emphasize the array nature of the objects,
<syntaxhighlight lang="fortran">
a(:,:) = a(:,:) + b(:,:)
</syntaxhighlight>
 
While scalar languages like C do not have native array programming elements as part of the language proper, this does not mean programs written in these languages never take advantage of the underlying techniques of vectorization (i.e., utilizing a CPU's [[SIMD|vector-based instructions]] if it has them or by using multiple CPU cores). Some C compilers like [[GNU Compiler Collection|GCC]] at some optimization levels detect and vectorize sections of code that its heuristics determine would benefit from it. Another approach is given by the [[OpenMP]] API, which allows one to parallelize applicable sections of code by taking advantage of multiple CPU cores.
 
در حالی که زبانهای اسکالر مانند C از عناصر برنامه نویسی آرایه بومی بعنوان بخشی از زبان مناسب برخوردار نیستند ، اما این بدان معنا نیست که برنامه های نوشته شده در این زبانها هرگز از تکنیک های اساسی بردارسازی (به عنوان مثال استفاده از [[SIMD|دستورالعمل های مبتنی بر بردار]] CPU در صورت استفاده از آن) استفاده نمی کنند. یا با استفاده از چندین هسته پردازنده). برخی از کامپایلرهای C مانند GCC در برخی از سطوح بهینه سازی ، بخشهایی از کد را که از نظر ابتکار عمل تعیین می کند ، شناسایی و بردار می کنند. روش دیگری توسط [[OpenMP]] API ارائه شده است ، که به شما امکان می دهد با استفاده از چندین هسته پردازنده ، بخشهای قابل اجرا از کد را موازی سازی کند.
===Array languages===
 
In array languages, operations are generalized to apply to both scalars and arrays. Thus, ''a''+''b'' expresses the sum of two scalars if ''a'' and ''b'' are scalars, or the sum of two arrays if they are arrays.
===زبان های آرایه ای===
در زبان های آرایه ، عملکردها تعمیم داده می شوند که هم در مقیاس کش ها و هم در آرایه ها اعمال شوند. بنابراین ، a + b مجموع دو مقیاس دهنده را نشان می دهد اگر a و b مقیاس پذیر باشند ، یا مجموع دو آرایه اگر آرایه ای باشند.
 
Anزبان arrayآرایه languageبرنامه simplifiesنویسی programmingرا butساده possiblyمی atکند aاما costاحتمالاً knownبا asهزینه theای ''abstractionاست که به عنوان جریمه penalty''انتزاع شناخته می شود.<ref>{{cite journal|author=Surana P |year=2006|title=Meta-Compilation of Language Abstractions. |year=2006 |url=ftp://lispnyc.org/meeting-assets/2007-02-13_pinku/SuranaThesis.pdf |access-date=2008-03-17 |url-status=dead |archive-url=https://web.archive.org/web/20150217154926/http://lispnyc.org/meeting-assets/2007-02-13_pinku/SuranaThesis.pdf |archive-date=2015-02-17 |access-date=2008-03-17}}</ref><ref>{{cite web |last= Kuketayev |title= The Data Abstraction Penalty (DAP) Benchmark for Small Objects in Java. |url= http://www.adtmag.com/joop/article.aspx?id=4597 |accessurl-datestatus= 2008-03-17 dead|archive-url= https://web.archive.org/web/20090111091710/http://www.adtmag.com/joop/article.aspx?id=4597 |archive-date= 2009-01-11 |urlaccess-statusdate= dead 2008-03-17}}</ref><ref>{{Cite book |last= Chatzigeorgiou |last2url= Stephanides |editor-lasthttps://books.google.com/?id= Blieberger |editor2-lastQMalP1P2kAMC&dq= Strohmeier |contribution= Evaluating Performance and Power Of Object-Oriented Vs. Procedural Programming Languages %22abstraction+penalty%22|title= Proceedings - 7th International Conference on Reliable Software Technologies - Ada-Europe'2002 |yearlast2= 2002 |pages= 367 Stephanides|publisher= Springer |urlyear= https://books.google.com/?id=QMalP1P2kAMC&dq=%22abstraction+penalty%22 2002|isbn= 978-3-540-43784-0|editor-last=Blieberger|pages=367|contribution=Evaluating Performance and Power Of Object-Oriented Vs. Procedural Programming Languages|editor2-last=Strohmeier}}</ref> Becauseاز theآنجا additionsکه areاضافات performedجدا inاز isolationبقیه fromبرنامه theنویسی restانجام ofمی theشود coding,، theyممکن may not produce the optimally mostاست [[algorithmicAlgorithmic efficiency|efficientکارآمدترین]] code.کد (Forرا example,تولید additionsنکند. of(بعنوان otherمثال elements، ofاضافه theشدن sameعناصر arrayدیگر mayاز beهمان subsequentlyآرایه encounteredممکن duringاست theمتعاقباً sameدر execution,طی causingهمان unnecessaryاجرا repeatedمشاهده lookups.)شود Even، theکه mostباعث sophisticatedجستجوهای [[optimizingمکرر compiler]]غیرضروری wouldمی haveشود.) anبخشهای extremelyمختلف hardبرنامه timeیا amalgamatingروال twoفرعی or، moreحتی apparentlyاگر disparateیک functionsبرنامه whichنویس mightبتواند appearاین inکار differentرا programبه sectionsراحتی orانجام sub-routines,دهد even، thoughمبالغی aرا programmerدر couldهمان doعبور thisاز easily,آرایه aggregatingجمع sumsمی onکند the same pass over the array to minimizeتا [[Computational overhead|overheadهزینه سربار]]) را به حداقل برساند.
 
====Ada (آدا)====
The previousکد C code would become the followingقبلی inدر theزبان [[Ada (programming language)|Ada]] language,<ref>[http://www.adaic.org/standards/05rm/html/RM-TTL.html Ada Reference Manual]: [http://www.adaic.org/resources/add_content/standards/05rm/html/RM-G-3-1.html G.3.1 Real Vectors and Matrices]</ref> which supportsبه array-programmingصورت زیر در می آید که از نحو برنامه نویسی آرایه پشتیبانی می syntaxکند.
<syntaxhighlight lang="ada">
A := A + B;
</syntaxhighlight>
 
====APL (ای پی ال)====
APL از نمادهای Unicode تک کاراکتر و بدون قند نحوی استفاده می کند.
APL uses single character Unicode symbols with no syntactic sugar.
<syntaxhighlight lang="apl">
A ← A + B
</syntaxhighlight>
This operation works on arrays of any rank (including rank 0), and on a scalar and an array. Dyalog APL extends the original language with [[augmented assignment]]s:
 
این عملیات روی آرایه های با هر درجه (از جمله رتبه 0) و روی مقیاس و آرایه کار می کند. Dyalog APL زبان اصلی را با [[Augmented assignment|مقدار دهی افزوده]] گسترش می دهد:
<syntaxhighlight lang="apl">
A +← B
</syntaxhighlight>
 
====Analytica(آنالیتیکا)====
Analytica providesهمان theاقتصاد sameبیان economyAda ofرا expressionفراهم asمی Adaکند.
<pre>
A := A + B;
</pre>
 
====BASIC(بیسیک)====
[[Dartmouth BASIC|دارتموث BASIC]] در ویرایش سوم (1966) عبارات MAT برای دستکاری ماتریس و آرایه داشت.
[[Dartmouth BASIC]] had MAT statements for matrix and array manipulation in its third edition (1966).
<syntaxhighlight lang="basic">
DIM A(4),B(4),C(4)
Line 82 ⟶ 88:
</syntaxhighlight>
 
====Mata(ماتا)====
زبان برنامه نویسی ماتریس [[Stata|استاتا]] Mata از برنامه نویسی آرایه پشتیبانی می کند. در زیر ، جمع ، ضرب ، جمع ماتریس و مقیاس ، ضرب عنصر به عنصر ، اشتراک و یکی از بسیاری از توابع ماتریس معکوس ماتا را نشان می دهیم.
[[Stata]]'s matrix programming language Mata supports array programming. Below, we illustrate addition, multiplication, addition of a matrix and a scalar, element by element multiplication, subscripting, and one of Mata's many inverse matrix functions.
<syntaxhighlight lang="stata">
. mata:
Line 105 ⟶ 111:
+-------------+
 
: C = J(3,2,1) // Aیک ماتریس 3 byدر 2 matrixاز of1 onesها
 
: C
Line 151 ⟶ 157:
+-----------+
 
: H = F[(2\1), (1, 2)] // Subscriptingبرای toدریافت getزیرماتریسی a submatrix ofاز F andو
 
: // switchتعویض rowسطر 1یک andو 2دو
: H
1 2
Line 161 ⟶ 167:
+-----------+
 
: I = invsym(F'*F) // Generalizedمعکوس inverseتعمیم یافته (F * F ^ (- 1) F = F) ofاز a
 
: // symmetricمتقارن positiveماتریس semi-definiteمثبت matrixنیمه قطعی
: I
[symmetric]
Line 176 ⟶ 182:
</syntaxhighlight>
 
====MATLAB(متلب)====
Theپیاده implementationسازی inدر [[MATLAB]] allowsهمان theاقتصاد sameمجاز economyرا allowedبا byاستفاده usingاز theزبان Fortran languageفراهم می کند.
<syntaxhighlight lang="matlab">
A = A + B;
</syntaxhighlight>
 
 
A variant of the MATLAB language is the [[GNU Octave]] language, which extends the original language with augmented assignments:
نوع زبان MATLAB زبان [[GNU Octave]] است که زبان اصلی را با تکالیف افزوده گسترش می دهد:
<syntaxhighlight lang="octave">
A += B;
</syntaxhighlight>هر دو MATLAB و GNU Octave بومی عمل جبر خطی مانند ضرب ماتریس ، [[Matrix inversion|وارونگی ماتریس]] و حل عددی [[System of linear equations|سیستم معادلات خط]]ی را پشتیبانی می کنند ، حتی با استفاده از [[Moore–Penrose pseudoinverse|شبه مقبره مور-پنرو]]ز.
</syntaxhighlight>
 
Both MATLAB and GNU Octave natively support linear algebra operations such as matrix multiplication, [[matrix inversion]], and the numerical solution of [[system of linear equations]], even using the [[Moore–Penrose pseudoinverse]].<ref>{{cite web |title= GNU Octave Manual. Arithmetic Operators. |url= https://www.gnu.org/software/octave/doc/interpreter/Arithmetic-Ops.html |access-date= 2011-03-19}}</ref><ref>{{cite web |title= MATLAB documentation. Arithmetic Operators. |url= http://www.mathworks.com/help/techdoc/ref/arithmeticoperators.html |access-date= 2011-03-19}}</ref>
 
نمونه [[Nial]] از محصول داخلی دو آرایه را می توان با استفاده از عملگر ضرب ماتریس بومی پیاده سازی کرد. اگر a بردار ردیفی به اندازه [1 n] و b باشد یک بردار ستونی مربوط به اندازه [n 1] است.
The [[Nial]] example of the inner product of two arrays can be implemented using the native matrix multiplication operator. If <code>a</code> is a row vector of size [1 n] and <code>b</code> is a corresponding column vector of size [n 1].
 
a * b;
 
محصول داخلی بین دو ماتریس که تعداد عناصر یکسانی دارند را می توان با عملگر کمکی (:) ، که یک ماتریس داده شده را به بردار ستون تغییر شکل می دهد ، و عملگر [[Transpose|انتقال]] را پیاده سازی کرد ' :
The inner product between two matrices having the same number of elements can be implemented with the auxiliary operator <code>(:)</code>, which reshapes a given matrix into a column vector, and the [[transpose]] operator <code>'</code>:
 
A(:)' * B(:);
 
====rasql====
[[Rasdaman|زبان پرس و جو rasdaman]] یک زبان برنامه نویسی آرایه ای پایگاه داده است. به عنوان مثال ، می توان دو آرایه را با درخواست زیر اضافه کرد:
The [[Rasdaman#Raster Query Language|rasdaman query language]] is a database-oriented array-programming language. For example, two arrays could be added with the following query:
<syntaxhighlight lang="sql">
SELECT A + B
Line 205 ⟶ 211:
 
====R====
زبان R به طور پیش فرض از الگوی آرایه پشتیبانی می کند. مثال زیر فرایند ضرب دو ماتریس و به دنبال آن اضافه کردن یک اسکالر (که در واقع یک بردار یک عنصر است) و یک بردار را نشان می دهد:
The R language supports [[array paradigm]] by default. The following example illustrates a process of multiplication of two matrices followed by an addition of a scalar (which is, in fact, a one-element vector) and a vector:
<syntaxhighlight lang="r">
> A <- matrix(1:6, nrow=2) !!thisاین hasدارای nrow = 2 ... andو A hasدارای 2 rowsردیف است
> A
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
> B <- t( matrix(6:1, nrow=2) ) # t() is a transpose operator عملگر انتقال است !!thisthisدارای hasnrow nrow= 2 ... andو B hasدارای 3 rowsردیف است --- aاین clearیک contradictionتناقض toآشکار theبا definition ofتعریف A است
> B
[,1] [,2]
Line 228 ⟶ 234:
[1,] 29 20
[2,] 41 29
> D + c(1, 1) # c() createsیک aبردار vectorمیسازد
[,1] [,2]
[1,] 30 21
Line 234 ⟶ 240:
</syntaxhighlight>
 
== استدلال ریاضی و علامت گذاری زبان ==
==Mathematical reasoning and language notation==
The matrix left-division operator concisely expresses some semantic properties of matrices. As in the scalar equivalent, if the ([[determinant]] of the) coefficient (matrix) <code>A</code> is not null then it is possible to solve the (vectorial) equation <code>A * x = b</code> by left-multiplying both sides by the [[matrix inversion|inverse]] of <code>A</code>: <code>A<sup>−1</sup></code> (in both MATLAB and GNU Octave languages: <code>A^-1</code>). The following mathematical statements hold when <code>A</code> is a [[matrix rank#Properties|full rank]] [[square matrix#Square matrices|square matrix]]:
 
عملگر تقسیم چپ ماتریس به طور خلاصه برخی از خصوصیات معنایی ماتریس ها را بیان می کند. همانند معادل اسکالر ، اگر ضریب (تعیین کننده) ضریب (ماتریس) A صفر نباشد ، می توان معادله (بردار) A * x = b را با ضرب چپ هر دو طرف [[Matrix inversion|برعکس]] A حل کرد: A −1 (به دو زبان MATLAB و GNU Octave: A ^ -1). عبارات ریاضی زیر هنگامی که A یک [[Square matrix|ماتریس مربع]] [[Matrix rank|درجه کامل]] است ، نگهداری می شوند:
:<code>A^-1 *(A * x)==A^-1 * (b)</code>
:<code>(A^-1 * A)* x ==A^-1 * b </code> &nbsp; &nbsp; &nbsp; (matrix-multiplication [[associativityAssociativity|تداعی]] ماتریس ضرب)
:<code>x = A^-1 * b</code>
:
where <code>==</code> is the equivalence [[relational operator]].
جایی که == عملگر رابطه ای [[Relational operator|معادل]] است. عبارات قبلی همچنین عبارات معتبر MATLAB هستند اگر عبارت سوم قبل از سایر موارد اجرا شود (مقایسه عددی ممکن است نادرست باشد به دلیل خطاهای دور زدن).
The previous statements are also valid MATLAB expressions if the third one is executed before the others (numerical comparisons may be false because of round-off errors).
 
اگر سیستم بیش از حد تعیین شده باشد - به طوری که ردیف های A بیشتر از ستون ها باشد - شبه معکوس A + (به زبان MATLAB و GNU Octave: pinv (A)) می تواند معکوس A − 1 را جایگزین کند ، به شرح زیر:
If the system is overdetermined - so that <code>A</code> has more rows than columns - the pseudoinverse <code>A<sup>+</sup></code> (in MATLAB and GNU Octave languages: <code>pinv(A)</code>) can replace the inverse <code>A<sup>−1</sup></code>, as follows:
:<code>pinv(A) *(A * x)==pinv(A) * (b)</code>
:<code>(pinv(A) * A)* x ==pinv(A) * b</code> &nbsp; &nbsp; &nbsp; (matrix-multiplication[[Associativity|تداعی]] associativityماتریس ضرب)
:<code>x = pinv(A) * b</code>
 
 
However, these solutions are neither the most concise ones (e.g. still remains the need to notationally differentiate overdetermined systems) nor the most computationally efficient. The latter point is easy to understand when considering again the scalar equivalent <code>a * x = b</code>, for which the solution <code>x = a^-1 * b</code> would require two operations instead of the more efficient <code>x = b / a</code>.
با این حال ، این راه حل ها نه مختصر ترین راه حل ها هستند (به عنوان مثال هنوز نیاز به تمایز نمایی سیستم های بیش از حد تعیین شده وجود دارد) و نه کارآمدترین محاسبات. درک آخرین نکته در هنگام بررسی مجدد معادل اسکالر a * x = b آسان است ، که برای آن x = a ^ -1 * b راه حل به جای کارآمدتر x = b / a به دو عمل نیاز دارد. مسئله این است که به طور کلی ضربات ماتریس [[Commutativity|عوض نمی شوند]] زیرا گسترش محلول مقیاسی به حالت ماتریس نیاز دارد:
The problem is that generally matrix multiplications are not [[commutativity|commutative]] as the extension of the scalar solution to the matrix case would require:
:<code>(a * x)/ a ==b / a</code>
:<code>(x * a)/ a ==b / a</code> &nbsp; &nbsp; &nbsp; (commutativityاشتراکی doesبرای notماتریس holdبرقرار for matricesنیست!)
:<code>x * (a / a)==b / a</code> &nbsp; &nbsp; &nbsp; (associativityتداعی alsoگرایی holdsبرای forماتریس matricesها نیز وجود دارد)
:<code>x = b / a</code>
 
 
The MATLAB language introduces the left-division operator <code>\</code> to maintain the essential part of the analogy with the scalar case, therefore simplifying the mathematical reasoning and preserving the conciseness:
زبان MATLAB عملگر تقسیم چپ را معرفی می کند تا قسمت اصلی تشبیه را با مورد مقیاس حفظ کند ، بنابراین استدلال ریاضی را ساده می کند و خلاصه را حفظ می کند:
:<code>A \ (A * x)==A \ b</code>
:<code>(A \ A)* x ==A \ b</code> &nbsp; &nbsp; &nbsp; (associativityانجمنی alsoبرای holdsماتریس forها matrices,نیز commutativityوجود isدارد no، moreدیگر requiredنیازی به اشتراکی نیست)
:<code>x = A \ b</code>
Thisاین isنه notتنها onlyنمونه anای exampleاز ofبرنامه terseنویسی arrayآرایه programmingمختصر fromاز theنظر codingکدگذاری pointبلکه ofاز viewمنظر butکارایی alsoمحاسباتی fromنیز theمی computationalباشد efficiency، perspective,که whichدر inچندین severalزبان arrayبرنامه programmingنویسی languagesآرایه benefitsاز fromکتابخانه quiteهای efficientجبر linearخطی algebraکاملاً librariesکارآمد such asمانند [[Automatically Tuned Linear Algebra Software|ATLAS]] orیا [[LAPACK]]. سود می برد<ref>{{cite web |title= GNU Octave Manual. Appendix G Installing Octave. |url= https://www.gnu.org/software/octave/doc/interpreter/Installation.html |access-date= 2011-03-19}}</ref>
 
با بازگشت به نقل قبلی از ایورسون ، منطق موجود در آن اکنون باید مشهود باشد:{{quote|مهم است که دشواری توصیف و یادگیری قطعه ای از نت را از دشواری تسلط بر پیامدهای آن تشخیص دهیم. به عنوان مثال ، یادگیری قوانین محاسبه یک محصول ماتریس آسان است ، اما تسلط بر پیامدهای آن (مانند ارتباط آن ، توزیع آن بر روی جمع ، و توانایی آن در نمایش توابع خطی و عملیات هندسی) یک مسئله متفاوت و بسیار دشوارتر است .
 
در واقع ، خود پیشنهادی بودن یک نت به دلیل خواص زیادی که برای اکتشافات به شما پیشنهاد می دهد ، یادگیری آن را دشوارتر نشان می دهد.}}
Returning to the previous quotation of Iverson, the rationale behind it should now be evident: {{quote|it is important to distinguish the difficulty of describing and of learning a piece of notation from the difficulty of mastering its implications. For example, learning the rules for computing a matrix product is easy, but a mastery of its implications (such as its associativity, its distributivity over addition, and its ability to represent linear functions and geometric operations) is a different and much more difficult matter.
 
==کتابخانه های شخص ثالث==
Indeed, the very suggestiveness of a notation may make it seem harder to learn because of the many properties it suggests for explorations.}}
The use of specialized and efficient libraries to provide more terse abstractions is also common in other programming languages. In [[C++]] several linear algebra libraries exploit the language's ability to [[operator overloading|overload operators]]. In some cases a very terse abstraction in those languages is explicitly influenced by the array programming paradigm, as the [[Armadillo (C++ library)|Armadillo]] and [[Blitz++]] libraries do.<ref name=":1">{{cite web |title= Reference for Armadillo 1.1.8. Examples of Matlab/Octave syntax and conceptually corresponding Armadillo syntax. |url= http://arma.sourceforge.net/docs.html#syntax |access-date= 2011-03-19}}</ref><ref name=":2">{{cite web |title= Blitz++ User's Guide. 3. Array Expressions. |url= http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80 |access-date= 2011-03-19 |archive-url= https://web.archive.org/web/20110323013142/http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80 |archive-date= 2011-03-23 |url-status= dead }}</ref>
 
استفاده از کتابخانه های تخصصی و کارآمد برای ارائه تجریدات مختصر در زبانهای برنامه نویسی نیز معمول است. در C ++ چندین کتابخانه جبر خطی از توانایی زبان در اضافه بار اپراتورها سو استفاده می کنند. در بعضی موارد ، انتزاع بسیار مختصر در آن زبانها به صراحت تحت تأثیر الگوی برنامه نویسی آرایه قرار می گیرد ، همانطور که کتابخانه های [[Armadillo (C++ library)|Armadillo]] و [[Blitz++|++Blitz]] این کار را می کنند..<ref name=":1" /><ref name=":2" />
==Third-party libraries==
The use of specialized and efficient libraries to provide more terse abstractions is also common in other programming languages. In [[C++]] several linear algebra libraries exploit the language's ability to [[operator overloading|overload operators]]. In some cases a very terse abstraction in those languages is explicitly influenced by the array programming paradigm, as the [[Armadillo (C++ library)|Armadillo]] and [[Blitz++]] libraries do.<ref>{{cite web |title= Reference for Armadillo 1.1.8. Examples of Matlab/Octave syntax and conceptually corresponding Armadillo syntax. |url= http://arma.sourceforge.net/docs.html#syntax |access-date= 2011-03-19}}</ref><ref>{{cite web |title= Blitz++ User's Guide. 3. Array Expressions. |url= http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80 |access-date= 2011-03-19 |archive-url= https://web.archive.org/web/20110323013142/http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC80 |archive-date= 2011-03-23 |url-status= dead }}</ref>
 
==همچنین ببینید==
==See also==
* [[Array slicing|برش آرایه ها]]
* [[List of programming languages by type#Array languages|Listلیست ofزبان arrayهای programmingآرایه languagesای]]
 
==References==