Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
docs:tutorial [2017/03/24 20:39] – tema | docs:tutorial [2021/04/09 12:03] – fixed some things hnv |
---|
<html> | <html> |
<head> | <head> |
<title>Untitled Document</title> | <title>Contents</title> |
<!-- Generated on Fri Mar 24 19:34:06 2017 by LaTeXML (version 0.8.2) http://dlmf.nist.gov/LaTeXML/. --> | <!-- Generated on Fri Apr 9 11:53:42 2021 by LaTeXML (version 0.8.5) http://dlmf.nist.gov/LaTeXML/. --> |
| |
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> | <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> |
<!-- autoinlined `/tmp/docs/tutorial/html/LaTeXML.css' --> | <!-- autoinlined `/home/hans/git/sac/docs/tutorial/html/LaTeXML.css' --> |
<style type='text/css'> | <style type='text/css'> |
/*====================================================================== | /*====================================================================== |
Para level */ | Para level */ |
.ltx_float { | .ltx_float { |
margin: 1ex 3em 1ex 3em; } | margin: 1ex 3em 1ex 3em; } |
td.ltx_subfigure, | td.ltx_subfigure, |
td.ltx_subtable, | td.ltx_subtable, |
.ltx_td.ltx_align_left.ltx_wrap, .ltx_th.ltx_align_left.ltx_wrap, | .ltx_td.ltx_align_left.ltx_wrap, .ltx_th.ltx_align_left.ltx_wrap, |
.ltx_td.ltx_align_right.ltx_wrap, .ltx_th.ltx_align_right.ltx_wrap, | .ltx_td.ltx_align_right.ltx_wrap, .ltx_th.ltx_align_right.ltx_wrap, |
.ltx_td.ltx_align_center.ltx_wrap, .ltx_th.ltx_align_center.ltx_wrap { white-space:normal; } | .ltx_td.ltx_align_center.ltx_wrap, .ltx_th.ltx_align_center.ltx_wrap, |
| .ltx_td.ltx_align_justify, .ltx_th.ltx_align_justify { white-space:normal; } |
| |
| .ltx_tabular .ltx_tabular { width:100%; } |
.ltx_inline-block { display:inline-block; } | .ltx_inline-block { display:inline-block; } |
| |
| /* avoid padding when aligning adjacent columns, e.g. for split decimals */ |
| .ltx_norightpad { padding-right:0!important; } |
| .ltx_noleftpad { padding-left:0!important; } |
| |
/* equations in non-aligned mode (not normally used) */ | /* equations in non-aligned mode (not normally used) */ |
.ltx_eqn_cell { display:table-cell; width:auto; } | .ltx_eqn_cell { display:table-cell; width:auto; } |
| |
.ltx_tag_equationgroup.ltx_align_left, | /* Padding between column pairs in ams align */ |
.ltx_tag_equation.ltx_align_left{ position:absolute; left:3em; } | table.ltx_eqn_align tr.ltx_equation td.ltx_align_left + td.ltx_align_right, |
.ltx_tag_equationgroup.ltx_align_right, | table.ltx_eqn_align tr.ltx_equation td.ltx_align_left + td.ltx_align_center, |
.ltx_tag_equation.ltx_align_right{ position:absolute; right:3em; } | table.ltx_eqn_align tr.ltx_equation td.ltx_align_center + td.ltx_align_right, |
| table.ltx_eqn_align tr.ltx_equation td.ltx_align_center + td.ltx_align_center { padding-left:3em; } |
| |
table.ltx_eqn_align tr.ltx_equation td.ltx_align_left + td.ltx_align_right { padding-left:3em; } | |
table.ltx_eqn_eqnarray tr.ltx_eqn_lefteqn + tr td.ltx_align_right { min-width:2em; } | table.ltx_eqn_eqnarray tr.ltx_eqn_lefteqn + tr td.ltx_align_right { min-width:2em; } |
| |
.ltx_eqn_eqno { max-width:0em; overflow:visible; } | .ltx_eqn_eqno { max-width:0em; overflow:visible; white-space: nowrap; } |
.ltx_eqn_eqno.ltx_align_right .ltx_tag { float:right; } | .ltx_eqn_eqno.ltx_align_right .ltx_tag { float:right; } |
| |
/*.ltx_biblist { list-style-type:none; }*/ | /*.ltx_biblist { list-style-type:none; }*/ |
.ltx_bibitem { list-style-type:none; } | .ltx_bibitem { list-style-type:none; } |
.ltx_bibtag { font-weight:bold; margin-left:-2em; width:3em; } | .ltx_bibitem .ltx_tag { font-weight:bold; margin-left:-2em; width:3em; } |
/*.bibitem-tag + div { display:inline; }*/ | /*.bibitem-tag + div { display:inline; }*/ |
.ltx_bib_title { font-style:italic; } | .ltx_bib_title { font-style:italic; } |
.ltx_listing { | .ltx_listing { |
display:block; | display:block; |
margin: 1ex 3em 1ex 3em; | margin: 1ex 3em 1ex 0em; |
overflow-x:auto; } | overflow-x:auto; |
| text-align: left; } |
.ltx_float .ltx_listing { | .ltx_float .ltx_listing { |
margin: 0; } | margin: 0; } |
background-color:transparent; | background-color:transparent; |
margin-left:-3em; width:2.5em; | margin-left:-3em; width:2.5em; |
position:absolute; | position:absolute; |
text-align:right; } | text-align:right; } |
.ltx_lst_numbers_right .ltx_listingline .ltx_tag { | .ltx_lst_numbers_right .ltx_listingline .ltx_tag { |
max-width: 70%; font-size:90%; left:15%; | max-width: 70%; font-size:90%; left:15%; |
text-align:left; | text-align:left; |
background-color: white; | background-color: white; |
padding: 0.5em 1em 0.5em 1.5em; | padding: 0.5em 1em 0.5em 1.5em; |
border: 1px solid black; border-radius: 0 5px 5px 5px; box-shadow: 5px 5px 10px gray; } | border: 1px solid black; border-radius: 0 5px 5px 5px; box-shadow: 5px 5px 10px gray; } |
.ltx_ERROR { color:red; } | .ltx_ERROR { color:red; } |
.ltx_rdf { display:none; } | .ltx_rdf { display:none; } |
.ltx_missing { color:red;} | .ltx_missing { color:red;} |
.ltx_nounicode { color:red; } | .ltx_nounicode { color:red; } |
/*====================================================================== | /*====================================================================== |
.ltx_font_smallcaps { font-variant: small-caps; font-style:normal; } | .ltx_font_smallcaps { font-variant: small-caps; font-style:normal; } |
.ltx_font_oldstyle { font-variant: oldstyle-nums; /* experimental css3 ? Doesn't seem to work!*/ | .ltx_font_oldstyle { font-variant: oldstyle-nums; /* experimental css3 ? Doesn't seem to work!*/ |
font-style:normal; | font-style:normal; |
-moz-font-feature-settings: "onum"; | -moz-font-feature-settings: "onum"; |
-ms-font-feature-settings: "onum"; | -ms-font-feature-settings: "onum"; |
| |
/* .ltx_phantom handled in xslt */ | /* .ltx_phantom handled in xslt */ |
| |
| |
</style> | </style> |
| |
<!-- autoinlined `/tmp/docs/tutorial/html/ltx-report.css' --> | <!-- autoinlined `/home/hans/git/sac/docs/tutorial/html/ltx-report.css' --> |
<style type='text/css'> | <style type='text/css'> |
| |
.ltx_title_document { font-size:170%; text-align:center; margin:1em 0 1em 0; } | .ltx_title_document { font-size:170%; text-align:center; margin:1em 0 1em 0; } |
| .ltx_dates, |
.ltx_authors, | .ltx_authors, |
.ltx_role_author { text-align:center; margin:1em 0 1em 0; } | .ltx_role_author { text-align:center; margin:1em 0 1em 0; } |
.ltx_title_part { font-size:200%; font-weight:bold; margin-bottom:1em; } | .ltx_title_part { font-size:200%; font-weight:bold; margin-bottom:1em; } |
.ltx_title_appendix, | .ltx_title_appendix, |
| .ltx_title_bibliography, |
.ltx_title_chapter { font-size:200%; font-weight:bold; margin-bottom:1em; } | .ltx_title_chapter { font-size:200%; font-weight:bold; margin-bottom:1em; } |
| .ltx_title_appendix .ltx_tag, |
.ltx_title_chapter .ltx_tag { display:block; font-size:90%; margin-bottom:0.5em; } | .ltx_title_chapter .ltx_tag { display:block; font-size:90%; margin-bottom:0.5em; } |
.ltx_title_section { font-size:140%; font-weight:bold; margin-bottom:1em; } | .ltx_title_section { font-size:140%; font-weight:bold; margin-bottom:1em; } |
section > .ltx_title +.ltx_date +.ltx_para > .ltx_p {text-indent:0em; } | section > .ltx_title +.ltx_date +.ltx_para > .ltx_p {text-indent:0em; } |
| |
.ltx_itemize { margin-left:1em; } | .ltx_itemize, |
| .ltx_enumerate { margin-left:1em; } |
| |
.ltx_theorem { margin-top:0.5em; margin-bottom:0.5em; } | .ltx_theorem { margin-top:0.5em; margin-bottom:0.5em; } |
</style> | </style> |
| |
<!-- autoinlined `/tmp/docs/tutorial/html/ltx-listings.css' --> | <!-- autoinlined `/home/hans/git/sac/docs/tutorial/html/ltx-listings.css' --> |
<style type='text/css'> | <style type='text/css'> |
| |
| |
<link rel='stylesheet' href='http://www.sac-home.org/lib/tpl/bootstrap3/assets/bootstrap/journal/bootstrap.min.css' type='text/css'> | <link rel='stylesheet' href='http://www.sac-home.org/lib/tpl/bootstrap3/assets/bootstrap/journal/bootstrap.min.css' type='text/css'> |
<!-- autoinlined `/tmp/docs/tutorial/html/tutorial.css' --> | <!-- autoinlined `/home/hans/git/sac/docs/tutorial/html/html/tutorial.css' --> |
<style type='text/css'> | <style type='text/css'> |
/*body { | /*body { |
<span class='ltx_text' style='font-size:298%;'>TUTORIAL | <span class='ltx_text' style='font-size:298%;'>TUTORIAL |
<br class='ltx_break'></span> | <br class='ltx_break'></span> |
<span class='ltx_text' style='font-size:144%;'>VERSION 1.2</span></p> | <span class='ltx_text' style='font-size:144%;'>VERSION 1.2.3</span></p> |
<p class='ltx_p'><span class='ltx_text ltx_font_smallcaps' style='font-size:144%;'>Sven-Bodo Scholz<span class='ltx_text ltx_font_upright'> </span>Stephan Herhut | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps' style='font-size:144%;'>Sven-Bodo Scholz<span class='ltx_text ltx_font_upright'> </span>Stephan Herhut |
<br class='ltx_break'>Frank Penczek<span class='ltx_text ltx_font_upright'> </span>Clemens Grelck | <br class='ltx_break'>Frank Penczek<span class='ltx_text ltx_font_upright'> </span>Clemens Grelck |
<br class='ltx_break'>Artem Shinkarov | <br class='ltx_break'>Artem Shinkarov<span class='ltx_text ltx_font_upright'> </span>Hans-Nikolai Vießmann |
<br class='ltx_break'></span></p> | <br class='ltx_break'></span></p> |
<p class='ltx_p'><span class='ltx_text ltx_font_smallcaps' style='font-size:120%;'>March 24, 2017</span></p> | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps' style='font-size:120%;'>April 9, 2021</span></p> |
</div> | </div> |
<div class='ltx_TOC ltx_role_contents'> | <div class='ltx_TOC ltx_role_contents'> |
<h6>Contents:</h6> | <h6>Contents</h6> |
<ul class='ltx_toclist'> | <ul class='ltx_toclist'> |
<li class='ltx_tocentry ltx_tocentry_part'> | <li class='ltx_tocentry ltx_tocentry_part'> |
<a href='#Ch10.S1' title='10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1 </span>Lesson: Calling <span class='ltx_text ltx_font_smallcaps'>C</span> from <span class='ltx_text ltx_font_smallcaps'>SaC</span></span></a> | <a href='#Ch10.S1' title='10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1 </span>Lesson: Calling <span class='ltx_text ltx_font_smallcaps'>C</span> from <span class='ltx_text ltx_font_smallcaps'>SaC</span></span></a> |
<ul class='ltx_toclist ltx_toclist_section'> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS1' title='10.1.1 Using C in the Small ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.1 </span>Using C in Small</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS1' title='10.1.1 Using C in the small ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.1 </span>Using <span class='ltx_text ltx_font_smallcaps'>C</span> in the small</span></a></li> |
<li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS2' title='10.1.2 Stateful C functions ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.2 </span>Stateful <span class='ltx_text ltx_font_smallcaps'>C</span> functions</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS2' title='10.1.2 Dealing with non-scalar arrays ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.2 </span>Dealing with non-scalar arrays</span></a></li> |
<li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS3' title='10.1.3 Using pragma directives ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.3 </span>Using pragma directives</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS3' title='10.1.3 Stateful C functions ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.3 </span>Stateful <span class='ltx_text ltx_font_smallcaps'>C</span> functions</span></a></li> |
<li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS4' title='10.1.4 Example TermFile ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.4 </span>Example TermFile</span></a></li> | |
</ul> | </ul> |
</li> | </li> |
<section id='Pt1' class='ltx_part'> | <section id='Pt1' class='ltx_part'> |
<h2 class='ltx_title ltx_title_part'> | <h2 class='ltx_title ltx_title_part'> |
<span class='ltx_tag ltx_tag_part'>Part I </span>Trails Covering the Basics of <span class='ltx_text ltx_font_smallcaps'>SaC</span> | <span class='ltx_tag ltx_tag_part'>Part I </span>Trails Covering the Basics of <span class='ltx_text ltx_font_smallcaps'>SaC</span> |
</h2> | </h2> |
| |
<section id='Ch1' class='ltx_chapter'> | <section id='Ch1' class='ltx_chapter'> |
<h3 class='ltx_title ltx_title_chapter'> | <h3 class='ltx_title ltx_title_chapter'> |
<span class='ltx_tag ltx_tag_chapter'>Chapter 1 </span>Running the first program</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 1 </span>Running the first program</h3> |
| |
<div id='Ch1.p1' class='ltx_para'> | <div id='Ch1.p1' class='ltx_para'> |
<div id='Ch1.S1.p1' class='ltx_para'> | <div id='Ch1.S1.p1' class='ltx_para'> |
<p class='ltx_p'>To successfully write and run your first <span class='ltx_text ltx_font_smallcaps'>SaC</span> program, you will need:</p> | <p class='ltx_p'>To successfully write and run your first <span class='ltx_text ltx_font_smallcaps'>SaC</span> program, you will need:</p> |
<ul id='Ch1.I1' class='ltx_itemize'> | <ul id='Ch1.S1.I1' class='ltx_itemize'> |
<li id='Ch1.I1.i1' class='ltx_item' style='list-style-type:none;'> | <li id='Ch1.S1.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch1.I1.i1.p1' class='ltx_para'> | <div id='Ch1.S1.I1.i1.p1' class='ltx_para'> |
<p class='ltx_p'>An <span class='ltx_text ltx_font_bold'>ANSI C compiler</span>, such as <span class='ltx_text ltx_font_typewriter'>gcc</span>. Though not needed directly, | <p class='ltx_p'>An <span class='ltx_text ltx_font_bold'>ANSI C compiler</span>, such as <span class='ltx_text ltx_font_typewriter'>gcc</span>. Though not needed directly, |
the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler relies on it.</p> | the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler relies on it.</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch1.I1.i2' class='ltx_item' style='list-style-type:none;'> | <li id='Ch1.S1.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch1.I1.i2.p1' class='ltx_para'> | <div id='Ch1.S1.I1.i2.p1' class='ltx_para'> |
<p class='ltx_p'>The <span class='ltx_text ltx_font_bold'>SaC compiler</span> <span class='ltx_text ltx_font_typewriter'>sac2c</span>. It can be downloaded at | <p class='ltx_p'>The <span class='ltx_text ltx_font_bold'>SaC compiler</span> <span class='ltx_text ltx_font_typewriter'>sac2c</span>. It can be downloaded at |
<a href='http://www.sac-home.org' title='' class='ltx_ref ltx_url ltx_font_typewriter'>http://www.sac-home.org</a>; see instructions in the Download | <a href='https://www.sac-home.org' title='' class='ltx_ref ltx_url ltx_font_typewriter'>https://www.sac-home.org</a>; see instructions in the Download |
section.</p> | section.</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch1.I1.i3' class='ltx_item' style='list-style-type:none;'> | <li id='Ch1.S1.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch1.I1.i3.p1' class='ltx_para'> | <div id='Ch1.S1.I1.i3.p1' class='ltx_para'> |
<p class='ltx_p'>The <span class='ltx_text ltx_font_bold'>SaC standard library</span> can be downloaded from GitHub | <p class='ltx_p'>The <span class='ltx_text ltx_font_bold'>SaC standard library</span> can be downloaded from GitHub |
<a href='http://www.github.com/SacBase/stdlib-core' title='' class='ltx_ref ltx_url ltx_font_typewriter'>http://www.github.com/SacBase/stdlib-core</a>. The process | <a href='https://www.github.com/SacBase/Stdlib' title='' class='ltx_ref ltx_url ltx_font_typewriter'>https://www.github.com/SacBase/Stdlib</a>. The process |
of installation is described in README.md file of the stdlib | of installation is described in README.md file of the stdlib |
repository.</p> | repository.</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch1.I1.i4' class='ltx_item' style='list-style-type:none;'> | <li id='Ch1.S1.I1.i4' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch1.I1.i4.p1' class='ltx_para'> | <div id='Ch1.S1.I1.i4.p1' class='ltx_para'> |
<p class='ltx_p'>Your favorite <span class='ltx_text ltx_font_bold'>text editor</span>, such as <span class='ltx_text ltx_font_typewriter'>vi</span> or <span class='ltx_text ltx_font_typewriter'>emacs</span>.</p> | <p class='ltx_p'>Your favorite <span class='ltx_text ltx_font_bold'>text editor</span>, such as <span class='ltx_text ltx_font_typewriter'>vi</span> or <span class='ltx_text ltx_font_typewriter'>emacs</span>.</p> |
</div> | </div> |
<p class='ltx_p'>Start your editor and type the following program:</p> | <p class='ltx_p'>Start your editor and type the following program:</p> |
</div> | </div> |
<figure id='LST1' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST1' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 1: </span>Hello World</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 1: </span>Hello World</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnRmKCJI%0AZWxsbyBXb3JsZCFcbiIpOwogIHJldHVybiAwOwp9%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludGYoIkhlbGxvIFdvcmxkIVxuIik7CiAgIHJldHVybiAwOwogfQ=='>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx1' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx2' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx3' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx4' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx5' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx6' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”Hello<span class='ltx_text ltx_lst_space'> </span>World!\n”</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”Hello<span class='ltx_text ltx_lst_space'> </span>World!\n”</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx7' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx8' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
A typical shell session for compiling <span class='ltx_text ltx_font_typewriter'>world.sac</span> could be:</p> | A typical shell session for compiling <span class='ltx_text ltx_font_typewriter'>world.sac</span> could be:</p> |
</div> | </div> |
<figure id='LST2' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST2' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 2: </span>Typical shell session</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 2: </span>Typical shell session</figcaption> |
<div class='ltx_listing ltx_lst_language_bash ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_bash ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,JCBjZCAvaG9tZS9zYnMvc2FjLwokIGxzCndvcmxkLnNhYwokIHNhYzJjICB3b3JsZC5zYWMKJCBs%0AcwphLm91dCAgICAgIGEub3V0LmMgICAgd29ybGQuc2FjCiQgYS5vdXQKSGVsbG8gV29ybGQh%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,ICQgY2QgL2hvbWUvc2JzL3NhYy8KICQgbHMKIHdvcmxkLnNhYwogJCBzYWMyYyAgd29ybGQuc2FjCiAkIGxzCiBhLm91dCAgICAgIGEub3V0LmMgICAgd29ybGQuc2FjCiAkIGEub3V0CiBIZWxsbyBXb3JsZCE='>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx9' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>$</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>cd</span><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_identifier'>home</span>/<span class='ltx_text ltx_lst_identifier'>sbs</span>/<span class='ltx_text ltx_lst_identifier'>sac</span>/ | <span class='ltx_text ltx_lst_space'> </span>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>cd</span><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_identifier'>home</span>/<span class='ltx_text ltx_lst_identifier'>sbs</span>/<span class='ltx_text ltx_lst_identifier'>sac</span>/ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx10' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>$</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ls</span> | <span class='ltx_text ltx_lst_space'> </span>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ls</span> |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx11' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> | <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx12' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>$</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sac2c</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> | <span class='ltx_text ltx_lst_space'> </span>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sac2c</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx13' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>$</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ls</span> | <span class='ltx_text ltx_lst_space'> </span>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ls</span> |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx14' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span>.<span class='ltx_text ltx_lst_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> | <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span>.<span class='ltx_text ltx_lst_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx15' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>$</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span> | <span class='ltx_text ltx_lst_space'> </span>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span> |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx16' class='ltx_listingline'> |
<span class='ltx_text ltx_lst_identifier'>Hello</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>World</span>! | <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Hello</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>World</span>! |
</div> | </div> |
</div> | </div> |
<section id='Ch2' class='ltx_chapter'> | <section id='Ch2' class='ltx_chapter'> |
<h3 class='ltx_title ltx_title_chapter'> | <h3 class='ltx_title ltx_title_chapter'> |
<span class='ltx_tag ltx_tag_chapter'>Chapter 2 </span>Array Programming Basics</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 2 </span>Array Programming Basics</h3> |
| |
<div id='Ch2.p1' class='ltx_para'> | <div id='Ch2.p1' class='ltx_para'> |
<p class='ltx_p'>In <span class='ltx_text ltx_font_smallcaps'>SaC</span>, arrays are the only data structures available. Even scalar values | <p class='ltx_p'>In <span class='ltx_text ltx_font_smallcaps'>SaC</span>, arrays are the only data structures available. Even scalar values |
are considered arrays. | are considered arrays. |
Each array is represented by two vectors, a so-called <em class='ltx_emph'>shape vector</em> | Each array is represented by two vectors, a so-called <em class='ltx_emph ltx_font_italic'>shape vector</em> |
and a <em class='ltx_emph'>data vector</em>. | and a <em class='ltx_emph ltx_font_italic'>data vector</em>. |
An array’s shape vector defines its <em class='ltx_emph'>shape</em>, i.e. its extent within each axis, | An array’s shape vector defines its <em class='ltx_emph ltx_font_italic'>shape</em>, i.e. its extent within each axis, |
and its <em class='ltx_emph'>dimensionality</em> (or <em class='ltx_emph'>rank</em>), which is given implicitly by the shape vector’s | and its <em class='ltx_emph ltx_font_italic'>dimensionality</em> (or <em class='ltx_emph ltx_font_italic'>rank</em>), which is given implicitly by the shape vector’s |
length.</p> | length.</p> |
</div> | </div> |
<div id='Ch2.S1.p2' class='ltx_para'> | <div id='Ch2.S1.p2' class='ltx_para'> |
<p class='ltx_p'>The section on <em class='ltx_emph'>Defining Arrays</em> explains how arrays of various dimensionality | <p class='ltx_p'>The section on <em class='ltx_emph ltx_font_italic'>Defining Arrays</em> explains how arrays of various dimensionality |
can be defined in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, and how they can be generated via nesting. | can be defined in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, and how they can be generated via nesting. |
Furthermore, some elementary notation such as <em class='ltx_emph'>scalars</em>, <em class='ltx_emph'>vectors</em>, and | Furthermore, some elementary notation such as <em class='ltx_emph ltx_font_italic'>scalars</em>, <em class='ltx_emph ltx_font_italic'>vectors</em>, and |
<em class='ltx_emph'>matrices</em> is defined.</p> | <em class='ltx_emph ltx_font_italic'>matrices</em> is defined.</p> |
</div> | </div> |
<div id='Ch2.S1.p3' class='ltx_para'> | <div id='Ch2.S1.p3' class='ltx_para'> |
<p class='ltx_p'>The section on <em class='ltx_emph'>Arrays and Variables</em> discusses the purely functional | <p class='ltx_p'>The section on <em class='ltx_emph ltx_font_italic'>Arrays and Variables</em> discusses the purely functional |
array model used in <span class='ltx_text ltx_font_smallcaps'>SaC</span>.</p> | array model used in <span class='ltx_text ltx_font_smallcaps'>SaC</span>.</p> |
</div> | </div> |
</div> | </div> |
<div id='Ch2.S1.SS1.p2' class='ltx_para'> | <div id='Ch2.S1.SS1.p2' class='ltx_para'> |
<p class='ltx_p'>In principle, all arrays in <span class='ltx_text ltx_font_smallcaps'>SaC</span> can be defined by using the <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>reshape</span> operation. | <p class='ltx_p'>In principle, all arrays in <span class='ltx_text ltx_font_smallcaps'>SaC</span> can be defined by using the <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> operation. |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>reshape</span> expects two operands, a shape vector and a data vector, both of which | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> expects two operands, a shape vector and a data vector, both of which |
are specified as comma separated lists of numbers enclosed in square brackets.</p> | are specified as comma separated lists of numbers enclosed in square brackets.</p> |
</div> | </div> |
<p class='ltx_p'>To get started, try the following program:</p> | <p class='ltx_p'>To get started, try the following program:</p> |
</div> | </div> |
<figure id='LST3' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST3' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 3: </span>Defining Arrays I</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 3: </span>Defining Arrays I</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQocmVz%0AaGFwZShbNV0sIFsxLDIsMyw0LDVdKSk7CiAgcHJpbnQocmVzaGFwZShbMywyXSwgWzEsMiwzLDQs%0ANSw2XSkpOwogIHByaW50KHJlc2hhcGUoWzMsMiwxXSwgWzEsMiwzLDQsNSw2XSkpOwogIHJldHVy%0AbiAwOwp9%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludChyZXNoYXBlKFs1XSwgWzEsMiwzLDQsNV0pKTsKICAgcHJpbnQocmVzaGFwZShbMywyXSwgWzEsMiwzLDQsNSw2XSkpOwogICBwcmludChyZXNoYXBlKFszLDIsMV0sIFsxLDIsMyw0LDUsNl0pKTsKICAgcmV0dXJuIDA7CiB9'>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx17' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx18' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx19' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx20' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx21' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx22' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([5],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([5],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5])); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx23' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([3,2],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([3,2],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6])); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx24' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([3,2,1],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([3,2,1],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6])); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx25' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx26' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
<div id='Ch2.S1.SS1.p4' class='ltx_para'> | <div id='Ch2.S1.SS1.p4' class='ltx_para'> |
<p class='ltx_p'>It prints three arrays:</p> | <p class='ltx_p'>It prints three arrays:</p> |
<ul id='Ch2.I1' class='ltx_itemize'> | <ul id='Ch2.S1.I1' class='ltx_itemize'> |
<li id='Ch2.I1.i1' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S1.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch2.I1.i1.p1' class='ltx_para'> | <div id='Ch2.S1.I1.i1.p1' class='ltx_para'> |
<p class='ltx_p'>an array of dimensionality 1 with 5 elements <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[1,2,3,4,5]</span></p> | <p class='ltx_p'>an array of dimensionality 1 with 5 elements <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[1,2,3,4,5]</span></p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I1.i2' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S1.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch2.I1.i2.p1' class='ltx_para'> | <div id='Ch2.S1.I1.i2.p1' class='ltx_para'> |
<p class='ltx_p'>an array of dimensionality 2 with 3 rows and 2 columns, and</p> | <p class='ltx_p'>an array of dimensionality 2 with 3 rows and 2 columns, and</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I1.i3' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S1.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch2.I1.i3.p1' class='ltx_para'> | <div id='Ch2.S1.I1.i3.p1' class='ltx_para'> |
<p class='ltx_p'>a 3-dimensional array with 3 elements in the leftmost axis, | <p class='ltx_p'>a 3-dimensional array with 3 elements in the leftmost axis, |
2 elements in the middle axis, and one element in the rightmost axis.</p> | 2 elements in the middle axis, and one element in the rightmost axis.</p> |
</div> | </div> |
<div id='Ch2.S1.SS1.p5' class='ltx_para'> | <div id='Ch2.S1.SS1.p5' class='ltx_para'> |
<p class='ltx_p'>Note here, that the function <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>print</span> can be applied to arbitrary arrays. | <p class='ltx_p'>Note here, that the function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>print</span> can be applied to arbitrary arrays. |
Besides printing its argument’s dimensionality and shape, i.e. its shape vector, | Besides printing its argument’s dimensionality and shape, i.e. its shape vector, |
a more intuitive representation of the array’s data vector is shown. | a more intuitive representation of the array’s data vector is shown. |
<div id='Ch2.S1.SS1.p6' class='ltx_para ltx_noindent'> | <div id='Ch2.S1.SS1.p6' class='ltx_para ltx_noindent'> |
<p class='ltx_p'>For reasons of convenience, we use the following terminology:</p> | <p class='ltx_p'>For reasons of convenience, we use the following terminology:</p> |
<dl id='Ch2.I2' class='ltx_description'> | <dl id='Ch2.S1.I2' class='ltx_description'> |
<dt id='Ch2.I2.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_description'>scalar</span></dt> | <dt id='Ch2.S1.I2.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>scalar</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I2.ix1.p1' class='ltx_para'> | <div id='Ch2.S1.I2.ix1.p1' class='ltx_para'> |
<p class='ltx_p'>always denotes an array of dimensionality 0,</p> | <p class='ltx_p'>always denotes an array of dimensionality 0,</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I2.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_description'>vector</span></dt> | <dt id='Ch2.S1.I2.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>vector</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I2.ix2.p1' class='ltx_para'> | <div id='Ch2.S1.I2.ix2.p1' class='ltx_para'> |
<p class='ltx_p'>always denotes an array of dimensionality 1, and</p> | <p class='ltx_p'>always denotes an array of dimensionality 1, and</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I2.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_description'>matrix</span></dt> | <dt id='Ch2.S1.I2.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>matrix</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I2.ix3.p1' class='ltx_para'> | <div id='Ch2.S1.I2.ix3.p1' class='ltx_para'> |
<p class='ltx_p'>always denotes an array of dimensionality 2.</p> | <p class='ltx_p'>always denotes an array of dimensionality 2.</p> |
</div> | </div> |
</div> | </div> |
<div id='Ch2.S1.SS1.p7' class='ltx_para'> | <div id='Ch2.S1.SS1.p7' class='ltx_para'> |
<p class='ltx_p'>As <em class='ltx_emph'>all</em> arrays can be defined in terms of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>reshape</span>, the following | <p class='ltx_p'>As <em class='ltx_emph ltx_font_italic'>all</em> arrays can be defined in terms of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span>, the following |
program as well is perfectly legal: | program as well is perfectly legal: |
</p> | </p> |
</div> | </div> |
<figure id='LST4' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST4' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 4: </span>Defining Arrays II</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 4: </span>Defining Arrays II</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQocmVz%0AaGFwZShbMV0sIFsxXSkpOwogIHByaW50KHJlc2hhcGUoW10sIFsxXSkpOwogIHJldHVybiAwOwp9%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludChyZXNoYXBlKFsxXSwgWzFdKSk7CiAgIHByaW50KHJlc2hhcGUoW10sIFsxXSkpOwogICByZXR1cm4gMDsKIH0='>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx27' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx28' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx29' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx30' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx31' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx32' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([1],<span class='ltx_text ltx_lst_space'> </span>[1])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([1],<span class='ltx_text ltx_lst_space'> </span>[1])); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx33' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([],<span class='ltx_text ltx_lst_space'> </span>[1])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([],<span class='ltx_text ltx_lst_space'> </span>[1])); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx34' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx35' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 2. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 2. </h6> |
<div id='Thmtheorem2.p1' class='ltx_para'> | <div id='Thmtheorem2.p1' class='ltx_para'> |
<p class='ltx_p'>The arguments of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>reshape</span> are vectors, i.e. arrays of dimensionality 1. | <p class='ltx_p'>The arguments of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> are vectors, i.e. arrays of dimensionality 1. |
Can they be specified by <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>e</span> expressions themselves?</p> | Can they be specified by <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>e</span> expressions themselves?</p> |
</div> | </div> |
</div> | </div> |
<div id='Ch2.S1.SS1.p9' class='ltx_para'> | <div id='Ch2.S1.SS1.p9' class='ltx_para'> |
<p class='ltx_p'>The <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>reshape</span> notation is relatively clumsy, in particular, when | <p class='ltx_p'>The <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> notation is relatively clumsy, in particular, when |
being used for scalars. | being used for scalars. |
Therefore, scalars and vectors can alternatively be specified by | Therefore, scalars and vectors can alternatively be specified by |
<p class='ltx_p'>For experimenting with these, try the following:</p> | <p class='ltx_p'>For experimenting with these, try the following:</p> |
</div> | </div> |
<figure id='LST5' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST5' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 5: </span>Shortcut Notation for Arrays</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 5: </span>Shortcut Notation for Arrays</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQoMSk7%0ACiAgcHJpbnQoWzEsMiwzLDQsNV0pOwogIHByaW50KFtbMSwyXSwgWzMsNF0sIFs1LDZdXSk7CiAg%0AcHJpbnQoZ2VuYXJyYXkoWzQsMywyXSwgMSkpOwogIHByaW50KGdlbmFycmF5KFs0LDNdLCBbMSwy%0AXSkpOwogIHJldHVybiAwOwp9%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludCgxKTsKICAgcHJpbnQoWzEsMiwzLDQsNV0pOwogICBwcmludChbWzEsMl0sIFszLDRdLCBbNSw2XV0pOwogICBwcmludChnZW5hcnJheShbNCwzLDJdLCAxKSk7CiAgIHByaW50KGdlbmFycmF5KFs0LDNdLCBbMSwyXSkpOwogICByZXR1cm4gMDsKIH0='>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx36' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx37' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx38' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx39' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx40' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx41' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(1); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(1); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx42' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>([1,2,3,4,5]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>([1,2,3,4,5]); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx43' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>([[1,2],<span class='ltx_text ltx_lst_space'> </span>[3,4],<span class='ltx_text ltx_lst_space'> </span>[5,6]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>([[1,2],<span class='ltx_text ltx_lst_space'> </span>[3,4],<span class='ltx_text ltx_lst_space'> </span>[5,6]]); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx44' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>genarray</span>([4,3,2],<span class='ltx_text ltx_lst_space'> </span>1)); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>genarray</span>([4,3,2],<span class='ltx_text ltx_lst_space'> </span>1)); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx45' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>genarray</span>([4,3],<span class='ltx_text ltx_lst_space'> </span>[1,2])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>genarray</span>([4,3],<span class='ltx_text ltx_lst_space'> </span>[1,2])); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx46' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx47' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
<p class='ltx_p'>From these examples, we can see that scalars can be used in the same way as in most | <p class='ltx_p'>From these examples, we can see that scalars can be used in the same way as in most |
programming languages, and that the notation used for the parameters of | programming languages, and that the notation used for the parameters of |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>reshape</span> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> |
in the examples above in fact is a standard abbreviation of <span class='ltx_text ltx_font_smallcaps'>SaC</span>. | in the examples above in fact is a standard abbreviation of <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
The example in line 8 shows that nestings of arrays are implicitly eliminated, i.e. | The example in line 8 shows that nestings of arrays are implicitly eliminated, i.e. |
</div> | </div> |
<div id='Ch2.S1.SS1.p13' class='ltx_para ltx_noindent'> | <div id='Ch2.S1.SS1.p13' class='ltx_para ltx_noindent'> |
<p class='ltx_p'>For this reason, array nestings in <span class='ltx_text ltx_font_smallcaps'>SaC</span> always have to be <em class='ltx_emph'>homogeneous</em>, | <p class='ltx_p'>For this reason, array nestings in <span class='ltx_text ltx_font_smallcaps'>SaC</span> always have to be <em class='ltx_emph ltx_font_italic'>homogeneous</em>, |
i.e. the inner array components have to have identical shapes.</p> | i.e. the inner array components have to have identical shapes.</p> |
</div> | </div> |
<div id='Ch2.S1.SS1.p14' class='ltx_para'> | <div id='Ch2.S1.SS1.p14' class='ltx_para'> |
<p class='ltx_p'>Furthermore, a new function is introduced: <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>genarray</span>. | <p class='ltx_p'>Furthermore, a new function is introduced: <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>genarray</span>. |
It expects two arguments, a shape vector that defines the shape of the result | It expects two arguments, a shape vector that defines the shape of the result |
and a default element to be inserted at each position of the result. | and a default element to be inserted at each position of the result. |
<p class='ltx_p'>Given the language constructs introduced so far, can you define an array that would print as</p> | <p class='ltx_p'>Given the language constructs introduced so far, can you define an array that would print as</p> |
<pre class='ltx_verbatim ltx_font_typewriter'> | <pre class='ltx_verbatim ltx_font_typewriter'> |
Dimension: 3 | Dimension: 3 |
Shape : < 5, 2, 2> | Shape : < 5, 2, 2> |
< 0 0 > < 0 0 > | < 0 0 > < 0 0 > |
< 1 0 > < 0 0 > | < 1 0 > < 0 0 > |
< 0 1 > < 0 0 > | < 0 1 > < 0 0 > |
< 0 0 > < 1 0 > | < 0 0 > < 1 0 > |
< 0 0 > < 0 1 > | < 0 0 > < 0 1 > |
| |
</pre> | </pre> |
<p class='ltx_p'>but whose definition does not contain the symbol ‘1’ more than once?</p> | <p class='ltx_p'>but whose definition does not contain the symbol ‘1’ more than once?</p> |
<p class='ltx_p'>Let’s have a look at an example:</p> | <p class='ltx_p'>Let’s have a look at an example:</p> |
</div> | </div> |
<figure id='LST6' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST6' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 6: </span>Variables as Placeholders</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 6: </span>Variables as Placeholders</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIs%0AMyw0XTsKICBwcmludChhKTsKCiAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgcHJpbnQoYik7%0ACgogIHJldHVybiAwOwp9%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gWzEsMiwzLDRdOwogICBwcmludChhKTsKCiAgIGIgPSBtb2RhcnJheShhLCBbMF0sIDkpOwogICBwcmludChiKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx48' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx49' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx50' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx51' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx52' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx53' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx54' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx55' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx56' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>9); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>9); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx57' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>b</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>b</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx58' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx59' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx60' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id='Ch2.S1.SS2.p4' class='ltx_para'> | <div id='Ch2.S1.SS2.p4' class='ltx_para'> |
<p class='ltx_p'>The function <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>modarray</span> expects three arguments: an array to be “modified”, | <p class='ltx_p'>The function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span> expects three arguments: an array to be “modified”, |
an index that indicates the exact position within the array to be “modified”, | an index that indicates the exact position within the array to be “modified”, |
and the value that is to be inserted at the specified position. | and the value that is to be inserted at the specified position. |
As we would expect, the resulting array <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>b</span> is almost identical to <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span>, | As we would expect, the resulting array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>b</span> is almost identical to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>, |
only the very first element has changed into <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>9</span>.</p> | only the very first element has changed into <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>9</span>.</p> |
</div> | </div> |
<div id='Ch2.S1.SS2.p6' class='ltx_para'> | <div id='Ch2.S1.SS2.p6' class='ltx_para'> |
<p class='ltx_p'>Referring to the container / place holder discussion, the crucial question is: | <p class='ltx_p'>Referring to the container / place holder discussion, the crucial question is: |
does the variable <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> denote a container, whose value is changed by | does the variable <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> denote a container, whose value is changed by |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>modarray</span>? If this would be the case, <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> and <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>b</span> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span>? If this would be the case, <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>b</span> |
would share the same container, and every access to <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> after | would share the same container, and every access to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> after |
line 9 would | line 9 would |
yield <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[9,2,3,4]</span>. If <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> in fact is a place holder, it will | yield <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[9,2,3,4]</span>. If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> in fact is a place holder, it will |
always denote the array <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[1,2,3,4]</span>, no matter what functions have | always denote the array <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[1,2,3,4]</span>, no matter what functions have |
obtained <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> as an argument.</p> | obtained <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> as an argument.</p> |
</div> | </div> |
<div id='Ch2.S1.SS2.p7' class='ltx_para'> | <div id='Ch2.S1.SS2.p7' class='ltx_para'> |
<p class='ltx_p'>To answer this question, you may simply shift the first call of | <p class='ltx_p'>To answer this question, you may simply shift the first call of |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>print</span> two lines down. As you can see, in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, variables are indeed | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>print</span> two lines down. As you can see, in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, variables are indeed |
place holders.</p> | place holders.</p> |
</div> | </div> |
<div id='Ch2.S1.SS2.p8' class='ltx_para'> | <div id='Ch2.S1.SS2.p8' class='ltx_para ltx_align_center'> |
<p class='ltx_p ltx_align_center'> | <p class='ltx_p'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle ltx_framed_rectangle' style='width:390.3pt;'> |
<span class='ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle' style='width:390.3pt;'> | <span id='Ch2.S1.SS2.p8.p1' class='ltx_para'> |
<span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for efficiency freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for efficiency freaks:</span></span> |
<span class='ltx_p'><span class='ltx_text ltx_font_italic'>You may wonder whether this implies that <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>modarray</span> always copies the entire array. | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>You may wonder whether this implies that <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span> always copies the entire array. |
In fact, it only copies <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> if the place-holder property would be violated otherwise.</span></span> | In fact, it only copies <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> if the place-holder property would be violated otherwise.</span></span> |
</span> | </span></span> |
</p> | </p> |
</div> | </div> |
<p class='ltx_p'>As a result of this place-holder property, it is guaranteed that no function call can affect | <p class='ltx_p'>As a result of this place-holder property, it is guaranteed that no function call can affect |
the value of its arguments. | the value of its arguments. |
In other words, the underlying concept <em class='ltx_emph'>guarantees</em>, that all functions are | In other words, the underlying concept <em class='ltx_emph ltx_font_italic'>guarantees</em>, that all functions are |
“pure”. | “pure”. |
Although this helps in avoiding nasty errors due to non-intended side-effects, | Although this helps in avoiding nasty errors due to non-intended side-effects, |
</div> | </div> |
<div id='Ch2.S1.SS2.p10' class='ltx_para'> | <div id='Ch2.S1.SS2.p10' class='ltx_para'> |
<p class='ltx_p'>To cope with this problem, in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, variables do have a so-called <em class='ltx_emph'>scope</em>, i.e. each variable definition is associated with a well-defined portion of program code | <p class='ltx_p'>To cope with this problem, in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, variables do have a so-called <em class='ltx_emph ltx_font_italic'>scope</em>, i.e. each variable definition is associated with a well-defined portion of program code |
where its definition is valid. | where its definition is valid. |
In a sequence of variable definitions, the scope of a variable starts with the left-hand | In a sequence of variable definitions, the scope of a variable starts with the left-hand |
in <span class='ltx_text ltx_font_smallcaps'>SaC</span>:</p> | in <span class='ltx_text ltx_font_smallcaps'>SaC</span>:</p> |
</div> | </div> |
<figure id='LST7' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST7' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 7: </span>Variable Scopes</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 7: </span>Variable Scopes</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIs%0AMyw0XTsKCiAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgcHJpbnQoYSk7CiAgYSA9IGI7CiAg%0AcHJpbnQoYSk7CgogIGEgPSBtb2RhcnJheShhLCBbMV0sIDgpOwogIHByaW50KGEpOwoKICByZXR1%0Acm4gMDsKfQ==%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gWzEsMiwzLDRdOwoKICAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgIHByaW50KGEpOwogICBhID0gYjsKICAgcHJpbnQoYSk7CgogICBhID0gbW9kYXJyYXkoYSwgWzFdLCA4KTsKICAgcHJpbnQoYSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx61' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx62' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx63' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx64' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx65' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx66' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx67' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx68' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>9); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>9); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx69' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx70' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx71' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx72' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx73' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[1],<span class='ltx_text ltx_lst_space'> </span>8); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[1],<span class='ltx_text ltx_lst_space'> </span>8); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx74' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx75' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx76' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx77' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id='Ch2.S1.SS2.p11' class='ltx_para'> | <div id='Ch2.S1.SS2.p11' class='ltx_para'> |
<p class='ltx_p'>Here, the use of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> on the right-hand side of line 9 still refers | <p class='ltx_p'>Here, the use of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> on the right-hand side of line 9 still refers |
to the definition of line 6, whereas the use in line 11 refers to the definition | to the definition of line 6, whereas the use in line 11 refers to the definition |
in line 10.</p> | in line 10.</p> |
code that looks very much “imperative”. | code that looks very much “imperative”. |
However, you should always keep in mind, that in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, the place-holder property | However, you should always keep in mind, that in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, the place-holder property |
<em class='ltx_emph'>always</em> holds!</p> | <em class='ltx_emph ltx_font_italic'>always</em> holds!</p> |
</div> | </div> |
<div id='Thmtheorem4' class='ltx_theorem ltx_theorem_theorem'> | <div id='Thmtheorem4' class='ltx_theorem ltx_theorem_theorem'> |
</div> | </div> |
</div> | </div> |
<figure id='LST8' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST8' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 8: </span>Scope Exercise</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 8: </span>Scope Exercise</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIs%0AMyw0XTsKICBiID0gW2EsYV07CgogIGEgPSBtb2RhcnJheShtb2RhcnJheShhLCBbMF0sIDApLCBb%0AMV0sIDApOwogIGIgPSBtb2RhcnJheShiLCBbMF0sIGEpOwogIHByaW50KGIpOwoKICByZXR1cm4g%0AMDsKfQ==%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gWzEsMiwzLDRdOwogICBiID0gW2EsYV07CgogICBhID0gbW9kYXJyYXkobW9kYXJyYXkoYSwgWzBdLCAwKSwgWzFdLCAwKTsKICAgYiA9IG1vZGFycmF5KGIsIFswXSwgYSk7CiAgIHByaW50KGIpOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx78' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx79' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx80' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx81' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx82' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx83' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx84' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_identifier'>a</span>]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_identifier'>a</span>]; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx85' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx86' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>0),<span class='ltx_text ltx_lst_space'> </span>[1],<span class='ltx_text ltx_lst_space'> </span>0); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>0),<span class='ltx_text ltx_lst_space'> </span>[1],<span class='ltx_text ltx_lst_space'> </span>0); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx87' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>b</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>b</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx88' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>b</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>b</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx89' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx90' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx91' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
| |
<div id='Ch2.S2.p1' class='ltx_para'> | <div id='Ch2.S2.p1' class='ltx_para'> |
<p class='ltx_p'>The term <em class='ltx_emph'>shape-invariant programming</em> refers to a programming style | <p class='ltx_p'>The term <em class='ltx_emph ltx_font_italic'>shape-invariant programming</em> refers to a programming style |
where all array operations are defined in terms of operations that | where all array operations are defined in terms of operations that |
are applied to entire arrays rather than to individual array elements. | are applied to entire arrays rather than to individual array elements. |
The section on <span class='ltx_text ltx_font_italic'>Standard Array Operations</span> introduces the most important | The section on <span class='ltx_text ltx_font_italic'>Standard Array Operations</span> introduces the most important |
standard array operations provided by the current <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler | standard array operations provided by the current <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler |
release<span class='ltx_note ltx_role_footnote'><sup class='ltx_note_mark'>1</sup><span class='ltx_note_outer'><span class='ltx_note_content'><sup class='ltx_note_mark'>1</sup>As of this writing, the latest <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler release | release<span id='Ch2.footnote1' class='ltx_note ltx_role_footnote'><sup class='ltx_note_mark'>1</sup><span class='ltx_note_outer'><span class='ltx_note_content'><sup class='ltx_note_mark'>1</sup> |
is version 1.2.</span></span></span>. | <span class='ltx_tag ltx_tag_note'>1</span> |
| |
| |
| As of this writing, the latest <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler release |
| is version 1.2.3.</span></span></span>. |
The next section explains <span class='ltx_text ltx_font_italic'>Axis Control Notation</span>, a powerful but simple | The next section explains <span class='ltx_text ltx_font_italic'>Axis Control Notation</span>, a powerful but simple |
way of manipulating the focus of array operations with respect to individual axes of argument arrays. | way of manipulating the focus of array operations with respect to individual axes of argument arrays. |
been adjusted to allow for a more favourable compilation in <span class='ltx_text ltx_font_smallcaps'>SaC</span> that yields better runtime performance.</p> | been adjusted to allow for a more favourable compilation in <span class='ltx_text ltx_font_smallcaps'>SaC</span> that yields better runtime performance.</p> |
</div> | </div> |
<div id='Ch2.S2.SS1.p2' class='ltx_para'> | <div id='Ch2.S2.SS1.p2' class='ltx_para ltx_align_center'> |
<p class='ltx_p ltx_align_center'> | <p class='ltx_p'><span class='ltx_text ltx_framed_rectangle' style='border-color: black;'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle' style='width:390.3pt;'> |
<span class='ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle' style='width:390.3pt;'> | <span id='Ch2.S2.SS1.p2.p1' class='ltx_para'> |
<span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for language design freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for language design freaks:</span></span> |
<span class='ltx_p'><span class='ltx_text ltx_font_italic'>You may have your own ideas on what primitive array operations should be available | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>You may have your own ideas on what primitive array operations should be available |
Therefore, it should be mentioned here, that </span><span class='ltx_text ltx_font_bold'>all</span><span class='ltx_text ltx_font_italic'> array operations introduced in the | Therefore, it should be mentioned here, that </span><span class='ltx_text ltx_font_bold'>all</span><span class='ltx_text ltx_font_italic'> array operations introduced in the |
remainder of this section are not | remainder of this section are not |
hard-wired into the language, but they are defined in the module <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>Array</span> | hard-wired into the language, but they are defined in the module <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>Array</span> |
from the standard library. | from the standard library. |
This is to say that the advanced <span class='ltx_text ltx_font_smallcaps'>SaC</span> programmer may write his own set of | This is to say that the advanced <span class='ltx_text ltx_font_smallcaps'>SaC</span> programmer may write his own set of |
standard array operations. | standard array operations.</span></span> |
</span></span> | </span></span> |
</span> | </span></p> |
</p> | |
</div> | </div> |
<div id='Ch2.S2.SS1.p3' class='ltx_para'> | <div id='Ch2.S2.SS1.p3' class='ltx_para'> |
</div> | </div> |
<div id='Ch2.S2.SS1.SSSx1.p2' class='ltx_para'> | <div id='Ch2.S2.SS1.SSSx1.p2' class='ltx_para'> |
<dl id='Ch2.I3' class='ltx_description'> | <dl id='Ch2.S2.I1' class='ltx_description'> |
<dt id='Ch2.I3.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_description'>dim(a)</span></dt> | <dt id='Ch2.S2.I1.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>dim(a)</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I3.ix1.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix1.p1' class='ltx_para'> |
<p class='ltx_p'>returns the (scalar) dimensionality of the argument array | <p class='ltx_p'>returns the (scalar) dimensionality of the argument array |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span>. | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: none.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: none.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I3.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_description'>shape(a)</span></dt> | <dt id='Ch2.S2.I1.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>shape(a)</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I3.ix2.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix2.p1' class='ltx_para'> |
<p class='ltx_p'>returns the shape vector of the argument array <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span>. | <p class='ltx_p'>returns the shape vector of the argument array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: none.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: none.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I3.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_description'>a[iv]</span></dt> | <dt id='Ch2.S2.I1.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>a[iv]</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I3.ix3.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix3.p1' class='ltx_para'> |
<p class='ltx_p'>constitutes a short-cut notation for <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>sel</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>. | <p class='ltx_p'>constitutes a short-cut notation for <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>sel</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>. |
It selects the array element of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> at index position <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>iv</span>. | It selects the array element of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> at index position <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span>. |
As <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> may be of any shape, the index position is given as an | As <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> may be of any shape, the index position is given as an |
<em class='ltx_emph'>index vector</em>. The dimensionality of the result is identical to the dimensionality of | <em class='ltx_emph ltx_font_italic'>index vector</em>. The dimensionality of the result is identical to the dimensionality of |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span> minus the length of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>iv</span>. | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> minus the length of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span>. |
Accordingly, its shape is derived from the last components of | Accordingly, its shape is derived from the last components of |
the shape of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span>. | the shape of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id='Ch2.I3.I1' class='ltx_itemize'> | <ul id='Ch2.S2.I1.ix3.I1' class='ltx_itemize'> |
<li id='Ch2.I3.I1.i1' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix3.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I1.i1.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix3.I1.i1.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I3.I1.i2' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix3.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I1.i2.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix3.I1.i2.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I3.I1.i3' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix3.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I1.i3.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix3.I1.i3.p1' class='ltx_para'> |
<p class='ltx_p'><math id='Ch2.I3.I1.i3.p1.m1' class='ltx_Math' alttext='{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I1.ix3.I1.i3.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}' display='inline'><mrow><mrow><mrow><mo>∀</mo><mtext class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>i</mtext></mrow><mo>∈</mo><mrow><mo stretchy='false'>{</mo><mn>0</mn><mo>,</mo><mi mathvariant='normal'>…</mi><mo>,</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy='false'>}</mo></mrow></mrow><mo>:</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math>.</p> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape% |
| }}({\@listingGroup{ltx_lst_identifier}{iv}})[[0]]}}}}\}:\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{iv}}[% |
| [{\@listingGroup{ltx_lst_identifier}{i}}]]{\@listingGroup{ltx_lst_space}{~{}}}% |
| \textless{\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{% |
| ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}{a}})[[{% |
| \@listingGroup{ltx_lst_identifier}{i}}]]}}}}' display='inline'><mrow><mrow><mrow><mo>∀</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</mtext></mrow><mo>∈</mo><mrow><mo stretchy='false'>{</mo><mn>0</mn><mo>,</mo><mi mathvariant='normal'>…</mi><mo>,</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy='false'>}</mo></mrow></mrow><mo>:</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math>.</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I3.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_description'>a[iv]=expr</span></dt> | <dt id='Ch2.S2.I1.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>a[iv]=expr</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I3.ix4.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix4.p1' class='ltx_para'> |
<p class='ltx_p'>is a short-cut notation for an assignment of the form | <p class='ltx_p'>is a short-cut notation for an assignment of the form |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>iv</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>expr</span>)</span>. | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>iv</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>expr</span>)</span>. |
The result of this application is a new array which is almost identical to | The result of this application is a new array which is almost identical to |
<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>a</span>. Only the element (subarray) at index position <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>iv</span> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. Only the element (subarray) at index position <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span> |
is different; it is replaced by <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>expr</span>. | is different; it is replaced by <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expr</span>. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id='Ch2.I3.I2' class='ltx_itemize'> | <ul id='Ch2.S2.I1.ix4.I2' class='ltx_itemize'> |
<li id='Ch2.I3.I2.i1' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix4.I2.i1' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I2.i1.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix4.I2.i1.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I3.I2.i2' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix4.I2.i2' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I2.i2.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix4.I2.i2.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I3.I2.i3' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix4.I2.i3' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I2.i3.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix4.I2.i3.p1' class='ltx_para'> |
<p class='ltx_p'><math id='Ch2.I3.I2.i3.p1.m1' class='ltx_Math' alttext='{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I1.ix4.I2.i3.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}' display='inline'><mrow><mrow><mrow><mo>∀</mo><mtext class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>i</mtext></mrow><mo>∈</mo><mrow><mo stretchy='false'>{</mo><mn>0</mn><mo>,</mo><mi mathvariant='normal'>…</mi><mo>,</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy='false'>}</mo></mrow></mrow><mo>:</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math></p> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape% |
| }}({\@listingGroup{ltx_lst_identifier}{iv}})[[0]]}}}}\}:\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{iv}}[% |
| [{\@listingGroup{ltx_lst_identifier}{i}}]]{\@listingGroup{ltx_lst_space}{~{}}}% |
| \textless{\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{% |
| ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}{a}})[[{% |
| \@listingGroup{ltx_lst_identifier}{i}}]]}}}}' display='inline'><mrow><mrow><mrow><mo>∀</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</mtext></mrow><mo>∈</mo><mrow><mo stretchy='false'>{</mo><mn>0</mn><mo>,</mo><mi mathvariant='normal'>…</mi><mo>,</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy='false'>}</mo></mrow></mrow><mo>:</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math></p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I3.I2.i4' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix4.I2.i4' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I2.i4.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix4.I2.i4.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>expr</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>a</span>[<span class='ltx_text ltx_lst_identifier'>iv</span>])</span>.</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>expr</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>a</span>[<span class='ltx_text ltx_lst_identifier'>iv</span>])</span>.</p> |
</div> | </div> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I3.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_description'>reshape(shp, expr)</span></dt> | <dt id='Ch2.S2.I1.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>reshape(shp, expr)</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I3.ix5.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix5.p1' class='ltx_para'> |
<p class='ltx_p'>computes an array with shape vector <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>shp</span> | <p class='ltx_p'>computes an array with shape vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>shp</span> |
and data vector identical to that of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>expr</span>. | and data vector identical to that of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expr</span>. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id='Ch2.I3.I3' class='ltx_itemize'> | <ul id='Ch2.S2.I1.ix5.I3' class='ltx_itemize'> |
<li id='Ch2.I3.I3.i1' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix5.I3.i1' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I3.i1.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix5.I3.i1.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>shp</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>shp</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I3.I3.i2' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I1.ix5.I3.i2' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I3.I3.i2.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix5.I3.i2.p1' class='ltx_para'> |
<p class='ltx_p'><math id='Ch2.I3.I3.i2.p1.m1' class='ltx_Math' alttext='{{{{{{{{\prod\limits_{i=0}^{{\textrm{\lstinline 1}}}}}\textrm{\lstinline 1}}}=\prod% | <p class='ltx_p'><math id='Ch2.S2.I1.ix5.I3.i2.p1.m1' class='ltx_Math' alttext='{{{{\prod\limits_{i=0}^{{\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\limits_{i=0}^{{\textrm{\lstinline 1}}}}}\textrm{\lstinline 1}}}' display='inline'><mrow><mrow><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>shp</mtext><mtext>)[[0]]-1</mtext></mrow></munderover><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shp</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow><mo>=</mo><mrow><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>dim</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)-1</mtext></mrow></munderover><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></mrow></math>.</p> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}% |
| {shp}})[[0]]-1}}}}}}\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
| \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{shp}}[[{\@listingGroup{ltx_lst_identifier}{% |
| i}}]]}}}}=\prod\limits_{i=0}^{{\textrm{\lstinline{{\lst@@@set@language% |
| \lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language% |
| \lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{dim}}({\@listingGroup{% |
| ltx_lst_identifier}{expr}})-1}}}}}}\textrm{\lstinline{{\lst@@@set@language% |
| \lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language% |
| \lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{% |
| ltx_lst_identifier}{expr}})[[{\@listingGroup{ltx_lst_identifier}{i}}]]}}}}' display='inline'><mrow><mrow><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>shp</mtext><mtext>)[[0]]-1</mtext></mrow></munderover><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shp</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow><mo>=</mo><mrow><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>dim</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)-1</mtext></mrow></munderover><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></mrow></math>.</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I3.ix6' class='ltx_item'><span class='ltx_tag ltx_tag_description'>genarray(shp, expr)</span></dt> | <dt id='Ch2.S2.I1.ix6' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>genarray(shp, expr)</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I3.ix6.p1' class='ltx_para'> | <div id='Ch2.S2.I1.ix6.p1' class='ltx_para'> |
<p class='ltx_p'>generates an array of shape <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>shp</span>, | <p class='ltx_p'>generates an array of shape <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>shp</span>, |
whose elements are all identical to <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>expr</span>. | whose elements are all identical to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expr</span>. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>shp</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span>.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>shp</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span>.</p> |
</div> | </div> |
at a few example applications:</p> | at a few example applications:</p> |
</div> | </div> |
<figure id='LST9' class='ltx_float ltx_lstlisting ltx_role_listing'> | <figure id='LST9' class='ltx_float ltx_lstlisting'> |
<figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 9: </span>Basic Operations</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 9: </span>Basic Operations</figcaption> |
<div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsx%0ALDIsMyw0LDUsNiw3LDgsOSwxMCwxMSwxMl07CgogIG1hdCA9IHJlc2hhcGUoWzMsNF0sIHZlY3Qp%0AOwogIHByaW50KG1hdCk7CgogIHByaW50KG1hdFtbMSwxXV0pOwogIHByaW50KG1hdFtbMl1dKTsK%0AICBwcmludChtYXRbW11dKTsKCiAgbWF0W1sxLDFdXSA9IDA7CiAgcHJpbnQobWF0KTsKICBtYXRb%0AWzJdXSA9IFswLDAsMCwwXTsKICBwcmludChtYXQpOwogIG1hdFtbXV0gPSBnZW5hcnJheShbMyw0%0AXSwgMCk7CiAgcHJpbnQobWF0KTsKCiAgZW1wdHlfdmVjdCA9IFtdOwogIHByaW50KGVtcHR5X3Zl%0AY3QpOwogIGVtcHR5X21hdCA9IHJlc2hhcGUoWzIyLDBdLCBlbXB0eV92ZWN0KTsKICBwcmludChl%0AbXB0eV9tYXQpOwogIHByaW50KGRpbShlbXB0eV9tYXQpKTsKICBwcmludChzaGFwZShlbXB0eV9t%0AYXQpKTsKCiAgcmV0dXJuIDA7Cn0=%0A'>⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzEsMiwzLDQsNSw2LDcsOCw5LDEwLDExLDEyXTsKCiAgIG1hdCA9IHJlc2hhcGUoWzMsNF0sIHZlY3QpOwogICBwcmludChtYXQpOwoKICAgcHJpbnQobWF0W1sxLDFdXSk7CiAgIHByaW50KG1hdFtbMl1dKTsKICAgcHJpbnQobWF0W1tdXSk7CgogICBtYXRbWzEsMV1dID0gMDsKICAgcHJpbnQobWF0KTsKICAgbWF0W1syXV0gPSBbMCwwLDAsMF07CiAgIHByaW50KG1hdCk7CiAgIG1hdFtbXV0gPSBnZW5hcnJheShbMyw0XSwgMCk7CiAgIHByaW50KG1hdCk7CgogICBlbXB0eV92ZWN0ID0gW107CiAgIHByaW50KGVtcHR5X3ZlY3QpOwogICBlbXB0eV9tYXQgPSByZXNoYXBlKFsyMiwwXSwgZW1wdHlfdmVjdCk7CiAgIHByaW50KGVtcHR5X21hdCk7CiAgIHByaW50KGRpbShlbXB0eV9tYXQpKTsKICAgcHJpbnQoc2hhcGUoZW1wdHlfbWF0KSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a></div> |
<div class='ltx_listingline'> | <div id='lstnumberx92' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx93' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx94' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx95' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx96' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx97' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6,7,8,9,10,11,12]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6,7,8,9,10,11,12]; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx98' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx99' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,4],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,4],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx100' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx101' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx102' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[1,1]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[1,1]]); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx103' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[2]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[2]]); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx104' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[]]); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx105' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx106' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[1,1]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[1,1]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx107' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx108' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[2]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[0,0,0,0]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[2]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[0,0,0,0]; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx109' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx110' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([3,4],<span class='ltx_text ltx_lst_space'> </span>0); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([3,4],<span class='ltx_text ltx_lst_space'> </span>0); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx111' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx112' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx113' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_vect</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_vect</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[]; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx114' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>23</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>empty_vect</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>23</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>empty_vect</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx115' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>24</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_mat</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reshape</span>([22,0],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_vect</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>24</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_mat</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reshape</span>([22,0],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_vect</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx116' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>25</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx117' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>26</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>)); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>)); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx118' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>27</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>)); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>27</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>)); |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx119' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>28</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</span></span> |
| |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx120' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>29</span></span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class='ltx_listingline'> | <div id='lstnumberx121' class='ltx_listingline'> |
<span class='ltx_tag ltx_tag_listing'><span class='ltx_text' style='color:#BFBFBF;'>30</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>30</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
</div> | </div> |
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 5. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 5. </h6> |
<div id='Thmtheorem5.p1' class='ltx_para'> | <div id='Thmtheorem5.p1' class='ltx_para'> |
<p class='ltx_p'>Assuming <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>mat</span> to be defined as in the previous example, what results do you | <p class='ltx_p'>Assuming <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> to be defined as in the previous example, what results do you |
expect from the following expressions:</p> | expect from the following expressions:</p> |
<ul id='Ch2.I4' class='ltx_itemize'> | <ul id='Ch2.S2.I2' class='ltx_itemize'> |
<li id='Ch2.I4.i1' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I2.i1' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch2.I4.i1.p1' class='ltx_para'> | <div id='Ch2.S2.I2.i1.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[]]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[]]</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I4.i2' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I2.i2' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch2.I4.i2.p1' class='ltx_para'> | <div id='Ch2.S2.I2.i2.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[1]]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[1]]</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I4.i3' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I2.i3' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch2.I4.i3.p1' class='ltx_para'> | <div id='Ch2.S2.I2.i3.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[1,0]]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[1,0]]</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I4.i4' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I2.i4' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'>•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id='Ch2.I4.i4.p1' class='ltx_para'> | <div id='Ch2.S2.I2.i4.p1' class='ltx_para'> |
<p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>mat</span>[<span class='ltx_text ltx_lst_identifier'>reshape</span>([2,0],<span class='ltx_text ltx_lst_space'> </span>[])]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>mat</span>[<span class='ltx_text ltx_lst_identifier'>reshape</span>([2,0],<span class='ltx_text ltx_lst_space'> </span>[])]</span>?</p> |
</div> | </div> |
</div> | </div> |
<div id='Ch2.S2.SS1.SSSx2.p3' class='ltx_para'> | <div id='Ch2.S2.SS1.SSSx2.p3' class='ltx_para'> |
<dl id='Ch2.I5' class='ltx_description'> | <dl id='Ch2.S2.I3' class='ltx_description'> |
<dt id='Ch2.I5.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_description'>arithmetic operations</span></dt> | <dt id='Ch2.S2.I3.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>arithmetic operations</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I5.ix1.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix1.p1' class='ltx_para'> |
<p class='ltx_p'>including addition (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix1.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix1.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), | <p class='ltx_p'>including addition (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
subtraction (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix1.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>-<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix1.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), negation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>-<math id='Ch2.I5.ix1.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math></span>), multiplication | subtraction (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>-<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), negation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>-<math id='Ch2.S2.I3.ix1.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math></span>), multiplication |
(<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix1.p1.m6' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>*<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix1.p1.m7' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and division (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix1.p1.m8' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix1.p1.m9' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>). | (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m6' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>*<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m7' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and division (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m8' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m9' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>). |
Furthermore, a modulo operation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix1.p1.m10' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>%<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix1.p1.m11' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>) is supported on integer | Furthermore, a modulo operation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m10' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>%<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m11' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>) is supported on integer |
numbers. | numbers. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.I5.ix1.p1.m12' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.S2.I3.ix1.p1.m12' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and |
<math id='Ch2.I5.ix1.p1.m13' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same numerical type.</p> | <math id='Ch2.S2.I3.ix1.p1.m13' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same numerical type.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I5.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_description'>logical operations</span></dt> | <dt id='Ch2.S2.I3.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>logical operations</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I5.ix2.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix2.p1' class='ltx_para'> |
<p class='ltx_p'>including conjunction (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix2.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>&&<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix2.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), disjunction | <p class='ltx_p'>including conjunction (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix2.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>&&<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix2.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), disjunction |
(<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix2.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>||<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix2.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and negation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>!<math id='Ch2.I5.ix2.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math></span>). | (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix2.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>||<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix2.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and negation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>!<math id='Ch2.S2.I3.ix2.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math></span>). |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types have to be Boolean.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types have to be Boolean.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I5.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_description'>relational operations</span></dt> | <dt id='Ch2.S2.I3.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>relational operations</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I5.ix3.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix3.p1' class='ltx_para'> |
<p class='ltx_p'>including less-than (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix3.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span><<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix3.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), | <p class='ltx_p'>including less-than (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span><<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
less-or-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix3.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix3.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix3.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix3.p1.m6' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), | less-or-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m6' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
not-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix3.p1.m7' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>!=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix3.p1.m8' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), | not-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m7' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>!=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m8' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
greater-or-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix3.p1.m9' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>>=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix3.p1.m10' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and greater-than | greater-or-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m9' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>>=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m10' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and greater-than |
(<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.I5.ix3.p1.m11' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>><span class='ltx_text ltx_lst_space'> </span><math id='Ch2.I5.ix3.p1.m12' class='ltx_Math' alttext='e2' display='inline'><mrow><mi>e</mi><mo></mo><mn>2</mn></mrow></math></span>). | (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m11' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>><span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m12' class='ltx_Math' alttext='e2' display='inline'><mrow><mi>e</mi><mo></mo><mn>2</mn></mrow></math></span>). |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.I5.ix3.p1.m13' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.I5.ix3.p1.m14' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.S2.I3.ix3.p1.m13' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.S2.I3.ix3.p1.m14' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I5.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_description'>max (<math id='Ch2.I5.ix4.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math>, <math id='Ch2.I5.ix4.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math>), min (<math id='Ch2.I5.ix4.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math>, <math id='Ch2.I5.ix4.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math>)</span></dt> | <dt id='Ch2.S2.I3.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>max (<math id='Ch2.S2.I3.ix4.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>1</mn></msub></math>, <math id='Ch2.S2.I3.ix4.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>2</mn></msub></math>), min (<math id='Ch2.S2.I3.ix4.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>1</mn></msub></math>, <math id='Ch2.S2.I3.ix4.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>2</mn></msub></math>)</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I5.ix4.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix4.p1' class='ltx_para'> |
<p class='ltx_p'>compute the element-wise maximum and | <p class='ltx_p'>compute the element-wise maximum and |
minimum, respectively. | minimum, respectively. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.I5.ix4.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.I5.ix4.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.S2.I3.ix4.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.S2.I3.ix4.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id='Ch2.I5.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_description'>where (p, <math id='Ch2.I5.ix5.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math>, <math id='Ch2.I5.ix5.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math>)</span></dt> | <dt id='Ch2.S2.I3.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>where (p, <math id='Ch2.S2.I3.ix5.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>1</mn></msub></math>, <math id='Ch2.S2.I3.ix5.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>2</mn></msub></math>)</span></span></dt> |
<dd class='ltx_item'> | <dd class='ltx_item'> |
<div id='Ch2.I5.ix5.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix5.p1' class='ltx_para'> |
<p class='ltx_p'>is an element-wise extension of a conditional. | <p class='ltx_p'>is an element-wise extension of a conditional. |
It expects <math id='Ch2.I5.ix5.p1.m1' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math>, <math id='Ch2.I5.ix5.p1.m2' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math>, and <math id='Ch2.I5.ix5.p1.m3' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> either to have identical shapes | It expects <math id='Ch2.S2.I3.ix5.p1.m1' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math>, <math id='Ch2.S2.I3.ix5.p1.m2' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math>, and <math id='Ch2.S2.I3.ix5.p1.m3' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> either to have identical shapes |
or to be scalar. If at least one of the three arrays is non-scalar, that | or to be scalar. If at least one of the three arrays is non-scalar, that |
shape serves as shape of the result, whose values are taken from | shape serves as shape of the result, whose values are taken from |
<math id='Ch2.I5.ix5.p1.m4' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> or <math id='Ch2.I5.ix5.p1.m5' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> depending on the value (s) of <math id='Ch2.I5.ix5.p1.m6' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math>. | <math id='Ch2.S2.I3.ix5.p1.m4' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> or <math id='Ch2.S2.I3.ix5.p1.m5' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> depending on the value (s) of <math id='Ch2.S2.I3.ix5.p1.m6' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math>. |
<br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id='Ch2.I5.I1' class='ltx_itemize'> | <ul id='Ch2.S2.I3.ix5.I1' class='ltx_itemize'> |
<li id='Ch2.I5.I1.i1' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I3.ix5.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I5.I1.i1.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix5.I1.i1.p1' class='ltx_para'> |
<p class='ltx_p'>the element type of <math id='Ch2.I5.I1.i1.p1.m1' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math> has to be boolean | <p class='ltx_p'>the element type of <math id='Ch2.S2.I3.ix5.I1.i1.p1.m1' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math> has to be boolean |
</p> | </p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I5.I1.i2' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I3.ix5.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I5.I1.i2.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix5.I1.i2.p1' class='ltx_para'> |
<p class='ltx_p'>the element types of <math id='Ch2.I5.I1.i2.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.I5.I1.i2.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be identical</p> | <p class='ltx_p'>the element types of <math id='Ch2.S2.I3.ix5.I1.i2.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.S2.I3.ix5.I1.i2.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be identical</p> |
</div> | </div> |
</li> | </li> |
<li id='Ch2.I5.I1.i3' class='ltx_item' style='list-style-type:none;'> | <li id='Ch2.S2.I3.ix5.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class='ltx_tag ltx_tag_itemize'><span class='ltx_text ltx_font_bold'>–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id='Ch2.I5.I1.i3.p1' class='ltx_para'> | <div id='Ch2.S2.I3.ix5.I1.i3.p1' class='ltx_para'> |
<p class='ltx_p'><math id='Ch2.I5.I1.i3.p1.m1' class='ltx_Math' alttext='{{{{{{{{{{{{{{\exists\textrm{\lstinline 1}}}:((\textrm{\lstinline 1}}}\vee\textrm{\lstinline | <p class='ltx_p'><math id='Ch2.S2.I3.ix5.I1.i3.p1.m1' class='ltx_Math' alttext='{{{{{{{\exists\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
1% | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
}}})\wedge(\textrm{\lstinline 1}}}\vee\textrm{\lstinline 1}}})\wedge(\textrm{% | \@listingGroup{ltx_lst_identifier}{shp}}}}}}:((\textrm{\lstinline{{% |
\lstinline 1}}}\vee\textrm{\lstinline 1}}}))' display='inline'><mrow><mrow><mo>∃</mo><mtext class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier'>shp</mtext></mrow><mo>:</mo><mrow><mo stretchy='false'>(</mo><mrow><mrow><mo stretchy='false'>(</mo><mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>p</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>shp</mtext></mrow><mo>∨</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>p</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>[]</mtext></mrow></mrow><mo stretchy='false'>)</mo></mrow><mo>∧</mo><mrow><mo stretchy='false'>(</mo><mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>e_1</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>shp</mtext></mrow><mo>∨</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>e_1</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>[]</mtext></mrow></mrow><mo stretchy='false'>)</mo></mrow><mo>∧</mo><mrow><mo stretchy='false'>(</mo><mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>e_2</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>shp</mtext></mrow><mo>∨</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>e_2</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>[]</mtext></mrow></mrow><mo stretchy='false'>)</mo></mrow></mrow><mo stretchy='false'>)</mo></mrow></mrow></math>.</ |