<html> <head> <title>Contents</title> <!– Generated on Mon Mar 14 17:52:01 2022 by LaTeXML (version 0.8.5) http://dlmf.nist.gov/LaTeXML/. –>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> <!– autoinlined `/Volumes/Users/sbs/tex/sacdoc/tutorial/html/LaTeXML.css' –> <style type='text/css'> .ltx_page_header, .ltx_page_footer { font-size:0.8em; } .ltx_page_header *[rel~=“prev”], .ltx_page_footer *[rel~=“prev”] { float:left; } .ltx_page_header *[rel~=“up”], .ltx_page_footer *[rel~=“up”] { display:block; text-align:center; } .ltx_page_header *[rel~=“next”], .ltx_page_footer *[rel~=“next”] { float:right; } .ltx_page_header li {
padding:0.1em 0.2em 0.1em 1em;}
.ltx_page_content { clear:both; } .ltx_page_header { border-bottom:1px solid; margin-bottom:5px; } .ltx_page_footer { clear:both; border-top:1px solid; margin-top:5px; }
.ltx_page_header:after, .ltx_page_footer:after, .ltx_page_content:after {
content:"."; display:block; height:0; clear:both; visibility:hidden; }
.ltx_page_footer:before {
content:"."; display:block; height:0; clear:both; visibility:hidden; }
.ltx_page_logo { font-size:80%; margin-top: 5px; clear:both; float:right; } .ltx_page_logo a { font-variant: small-caps; } .ltx_page_logo img { vertical-align:-3px; } .ltx_page_navbar li { white-space:nowrap; display:block; overflow:hidden; } .ltx_page_navbar li span.ltx_ref { white-space:normal; overflow:visible; } .ltx_pagination.ltx_role_newpage { height:2em; } .ltx_title { font-size:100%; font-weight:normal; } .ltx_runin { display:inline; } .ltx_runin:after { content:“ ”; } .ltx_runin + .ltx_para, .ltx_runin + .ltx_para p, .ltx_runin + p { display:inline; }
.ltx_outdent { margin-left: -2em; } .ltx_page_main { margin:0px; padding:1em 3em 1em 2em; } .ltx_tocentry { list-style-type:none; } .ltx_authors_1line .ltx_creator, .ltx_authors_1line .ltx_author_before, .ltx_authors_1line .ltx_author_after { display:inline;} .ltx_authors_1line .ltx_author_notes { display:inline-block; } .ltx_authors_1line .ltx_author_notes:before { content:“*”; color:blue;} .ltx_authors_1line .ltx_author_notes span { display:none; } .ltx_authors_1line .ltx_author_notes:hover span {
display:block; position:absolute; z-index:10; background:white; text-align:left; border: 1px solid black; border-radius: 0 5px 5px 5px; box-shadow: 5px 5px 10px gray; }
.ltx_authors_multiline .ltx_creator, .ltx_authors_multiline .ltx_author_before, .ltx_authors_multiline .ltx_author_after, .ltx_authors_multiline .ltx_author_notes, .ltx_authors_multiline .ltx_author_notes .ltx_contact {
display:block; }
.ltx_float {
margin: 1ex 3em 1ex 3em; }
td.ltx_subfigure, td.ltx_subtable, td.ltx_subfloat { width:50%; } .ltx_p, .ltx_quote, .ltx_block, .ltx_para {
display: block; }
.ltx_align_left { text-align:left; } .ltx_align_right { text-align:right; } .ltx_align_center { text-align:center; } .ltx_align_justify { text-align:justify; } .ltx_align_top { vertical-align:top; } .ltx_align_bottom { vertical-align:bottom; } .ltx_align_middle { vertical-align:middle; } .ltx_align_baseline { vertical-align:baseline; }
.ltx_align_floatleft { float:left; } .ltx_align_floatright { float:right; }
.ltx_td.ltx_align_left, .ltx_th.ltx_align_left, .ltx_td.ltx_align_right, .ltx_th.ltx_align_right, .ltx_td.ltx_align_center, .ltx_th.ltx_align_center { white-space:nowrap; } .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_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_norightpad { padding-right:0!important; } .ltx_noleftpad { padding-left:0!important; } .ltx_eqn_div { display:block; width:95%; text-align:center; } .ltx_eqn_table { display:table; width:100%; border-collapse:collapse; } .ltx_eqn_row { display:table-row; } .ltx_eqn_cell { display:table-cell; width:auto; } table.ltx_eqn_align tr.ltx_equation td.ltx_align_left + td.ltx_align_right, table.ltx_eqn_align tr.ltx_equation td.ltx_align_left + td.ltx_align_center, 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_eqnarray tr.ltx_eqn_lefteqn + tr td.ltx_align_right { min-width:2em; }
.ltx_eqn_eqno { max-width:0em; overflow:visible; white-space: nowrap; } .ltx_eqn_eqno.ltx_align_right .ltx_tag { float:right; }
.ltx_eqn_center_padleft, .ltx_eqn_center_padright { width:50%; min-width:2em;} .ltx_eqn_left_padleft, .ltx_eqn_right_padright { min-width:2em; } .ltx_eqn_left_padright, .ltx_eqn_right_padleft { width:100%; } .ltx_itemize, .ltx_enumerate, .ltx_description {
display:block; }
.ltx_itemize .ltx_item, .ltx_enumerate .ltx_item {
display: list-item; }
li.ltx_item > .ltx_tag {
display:inline-block; margin-left:-1.5em; min-width:1.5em; text-align:right; }
.ltx_item .ltx_tag + .ltx_para, .ltx_item .ltx_tag + .ltx_para .ltx_p { display:inline; } dl.ltx_description dt { margin-right:0.5em; float:left;
font-weight:bold; font-size:95%; }
dl.ltx_description dd { margin-left:5em; } dl.ltx_description dl.ltx_description dd { margin-left:3em; } .ltx_theorem {margin:1em 0em 1em 0em; } .ltx_title_theorem { font-size:100%; } .ltx_bibliography dt { margin-right:0.5em; float:left; } .ltx_bibliography dd { margin-left:3em; } .ltx_bibitem { list-style-type:none; } .ltx_bibitem .ltx_tag { font-weight:bold; margin-left:-2em; width:3em; } .ltx_bib_title { font-style:italic; } .ltx_bib_article .bib-title { font-style:normal !important; } .ltx_bib_journal { font-style:italic; } .ltx_bib_volume { font-weight:bold; } .ltx_indexlist li { list-style-type:none; } .ltx_indexlist { margin-left:1em; padding-left:1em;} .ltx_listing {
display:block; margin: 1ex 3em 1ex 0em; overflow-x:auto; text-align: left; }
.ltx_float .ltx_listing {
margin: 0; }
.ltx_listingline { white-space:nowrap; min-height:1em; } .ltx_lst_numbers_left .ltx_listingline .ltx_tag {
background-color:transparent; margin-left:-3em; width:2.5em; position:absolute; text-align:right; }
.ltx_lst_numbers_right .ltx_listingline .ltx_tag {
background-color:transparent; width:2.5em; position:absolute; right:3em; text-align:right; }
/ .ltx_parbox {text-indent:0em; } .ltx_transformed_outer {
position:relative; bottom:0pt;left:0pt; overflow:visible; }
.ltx_transformed_inner {
display:block; position:absolute;bottom:0pt;left:0pt; }
.ltx_transformed_inner > .ltx_p {text-indent:0em; margin:0; padding:0; } span.ltx_rowspan { position:absolute; top:0; bottom:0; } .ltx_p { text-indent:0em; white-space:normal; } .ltx_indent > .ltx_p:first-child { text-indent:2em!important; } .ltx_noindent > .ltx_p:first-child { text-indent:0em!important; } .ltx_page_column1 {
width:44%; float:left; } /* IE uses % of wrong container*/
.ltx_page_column2 {
width:44%; float:right; }
.ltx_page_columns > .ltx_page_column1 {
width:48%; float:left; }
.ltx_page_columns > .ltx_page_column2 {
width:48%; float:right; }
.ltx_page_columns:after {
content:"."; display:block; height:0; clear:both; visibility:hidden; }
.ltx_tabular { display:inline-table; border-collapse:collapse; } .ltx_tabular.ltx_centering { display:table; } .ltx_thead, .ltx_tfoot, .ltx_tbody { display:table-row-group; } .ltx_tr { display:table-row; } .ltx_td, .ltx_th { display:table-cell; }
.ltx_framed { border:1px solid black;} .ltx_tabular .ltx_td, .ltx_tabular .ltx_th { padding:0.1em 0.5em; } .ltx_border_t { border-top:1px solid black; } .ltx_border_r { border-right:1px solid black; } .ltx_border_b { border-bottom:1px solid black; } .ltx_border_l { border-left:1px solid black; } .ltx_border_tt { border-top:3px double black; } .ltx_border_rr { border-right:3px double black; } .ltx_border_bb { border-bottom:3px double black; } .ltx_border_ll { border-left:3px double black; } .ltx_border_T { border-top:1px solid gray; } .ltx_border_R { border-right:1px solid gray; } .ltx_border_B { border-bottom:1px solid gray; } .ltx_border_L { border-left:1px solid gray; } .ltx_framed_rectangle { border-style:solid; border-width:1px; } .ltx_framed_top { border-top-style:solid; border-top-width:1px; } .ltx_framed_left { border-left-style:solid; border-left-width:1px; } .ltx_framed_right { border-right-style:solid; border-right-width:1px; } .ltx_framed_bottom, .ltx_framed_underline { border-bottom-style:solid; border-bottom-width:1px; } .ltx_framed_topbottom { border-top-style:solid; border-top-width:1px;
border-bottom-style:solid; border-bottom-width:1px; }
.ltx_framed_leftright { border-left-style:solid; border-left-width:1px;
border-right-style:solid; border-right-width:1px; }
.ltx_verbatim { text-align:left; } .ltx_note_content { display:none; } .ltx_note_content {
max-width: 70%; font-size:90%; left:15%; text-align:left; background-color: white; padding: 0.5em 1em 0.5em 1.5em; border: 1px solid black; border-radius: 0 5px 5px 5px; box-shadow: 5px 5px 10px gray; }
.ltx_note_mark { color:blue; } .ltx_note_type { font-weight: bold; } .ltx_note { display:inline-block; text-indent:0; } .ltx_note_content .ltx_note_mark { position:absolute; left:0.2em; top:-0.1em; } .ltx_note:hover .ltx_note_content, .ltx_note .ltx_note_content:hover {
display:block; position:absolute; z-index:10; }
.ltx_ERROR { color:red; } .ltx_rdf { display:none; } .ltx_missing { color:red;} .ltx_nounicode { color:red; } .ltx_svg_fog foreignObject { margin:0; padding:0; overflow:visible; } .ltx_svg_fog foreignObject > p { margin:0; padding:0; display:block; } .ltx_font_serif { font-family: serif; } .ltx_font_sansserif { font-family: sans-serif; } .ltx_font_typewriter { font-family: monospace; } .ltx_font_bold { font-weight: bold; } .ltx_font_medium { font-weight: normal; } .ltx_font_italic { font-style: italic; font-variant:normal; } .ltx_font_upright { font-style: normal; font-variant:normal; } .ltx_font_slanted { font-style: oblique; font-variant:normal; } .ltx_font_smallcaps { font-variant: small-caps; font-style:normal; } .ltx_font_oldstyle { font-variant: oldstyle-nums;
font-style:normal; -moz-font-feature-settings: "onum"; -ms-font-feature-settings: "onum"; -webkit-font-feature-settings: "onum"; font-variant-numeric: oldstyle-nums; }
.ltx_font_mathcaligraphic { font-family: “Lucida Calligraphy”, “Zapf Chancery”,“URW Chancery L”; } cite { font-style: normal; }
.ltx_red { color:red; } .ltx_centering { display:block; margin:auto; text-align:center; } .ltx_hflipped {
display:inline-block; -moz-transform: scaleX(-1); -o-transform: scaleX(-1); -webkit-transform: scaleX(-1); transform: scaleX(-1); filter: FlipH; -ms-fliter: "FlipH"; }
.ltx_vflipped {
display:inline-block; -moz-transform: scaleY(-1); -o-transform: scaleY(-1); -webkit-transform: scaleY(-1); transform: scaleY(-1); filter: FlipV; -ms-fliter: "FlipV"; }
</style>
<!– autoinlined `/Volumes/Users/sbs/tex/sacdoc/tutorial/html/ltx-report.css' –> <style type='text/css'>
.ltx_title_document { font-size:170%; text-align:center; margin:1em 0 1em 0; } .ltx_dates, .ltx_authors, .ltx_role_author { text-align:center; margin:1em 0 1em 0; } .ltx_role_author .ltx_personname { font-size: 120%; } .ltx_date { text-align:center; font-size: 120%; margin:1em 0 1em 0; } .ltx_subtitle { text-align:center; font-size: 120%; padding-left:0.2em; margin-left:-0.5em; }
.ltx_title_abstract { text-align:center; font-size: 100%; font-weight:bold; } .ltx_abstract { margin-left:4em; margin-right:4em; }
.ltx_appendix, .ltx_part, .ltx_chapter, .ltx_section, .ltx_subsection, .ltx_subsubsection { margin-top:1.5em; } .ltx_paragraph, .ltx_subparagraph { margin-top:1.0em; }
.ltx_title_part { font-size:200%; font-weight:bold; margin-bottom:1em; } .ltx_title_appendix, .ltx_title_bibliography, .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_section { font-size:140%; font-weight:bold; margin-bottom:1em; } .ltx_title_subsection { font-size:120%; font-weight:bold; margin-bottom:1em; } .ltx_title_subsubsection { font-size:100%; font-weight:bold; margin-bottom:1em; } .ltx_title_paragraph { font-size:100%; font-weight:bold; display:inline;
margin-right:1em; }
.ltx_paragraph .ltx_title, .ltx_paragraph .ltx_title + .ltx_para, .ltx_paragraph .ltx_title + .ltx_para > .ltx_p { display:inline; }
.ltx_title_subparagraph { font-size:100%; font-weight:bold; display:inline;
margin-left:2em; margin-right:1em; }
.ltx_subparagraph .ltx_title, .ltx_subparagraph .ltx_title + .ltx_para, .ltx_subparagraph .ltx_title + .ltx_para > .ltx_p { display:inline; }
.ltx_figure { text-align:center; margin:auto; margin:0.5em; } .ltx_table { text-align:center; margin:auto; margin:0.5em; } .ltx_table, .ltx_figure { display:flex; flex-direction:column; align-items:center; } .ltx_table .ltx_caption, .ltx_figure .ltx_caption { text-align:justify; } .ltx_para > .ltx_p:first-child { text-indent:2em; } section > .ltx_title +.ltx_para > .ltx_p, section > .ltx_title +.ltx_date +.ltx_para > .ltx_p {text-indent:0em; }
.ltx_itemize, .ltx_enumerate { margin-left:1em; }
.ltx_theorem { margin-top:0.5em; margin-bottom:0.5em; } .ltx_theorem .ltx_title { margin-bottom:0.1em; font-weight:normal; } .ltx_theorem .ltx_title + .ltx_para, .ltx_theorem .ltx_title + .ltx_para .ltx_p, .ltx_theorem .ltx_title + .ltx_p { margin-top:0em; }
</style>
<!– autoinlined `/Volumes/Users/sbs/tex/sacdoc/tutorial/html/ltx-listings.css' –> <style type='text/css'>
.ltx_listing_data {
float:right; }
.ltx_listing_data a {
text-decoration:none; }
</style>
<link rel='stylesheet' href='http://www.sac-home.org/lib/tpl/bootstrap3/assets/bootstrap/journal/bootstrap.min.css' type='text/css'> <!– autoinlined `/Volumes/Users/sbs/tex/sacdoc/tutorial/html/html/tutorial.css' –> <style type='text/css'> .ltx_role_contents {
width: 300px; margin-left: 0px; overflow-y: auto; max-height: 90%; /*padding-top: 15px;*/ /*border-right: 1px solid black;*/ float: left; clear: left; top: 0; position: fixed; margin-top: 85px; padding-right: 5px;
}
.ltx_page_main {
margin-top: -30px; padding: 0;
}
.ltx_titlepage {
padding-left: 320px;
}
.ltx_part {
padding-left: 320px;
}
.ltx_role_contents h6 {
display: none;
}
.ltx_role_contents > ul {
padding: 0;
}
.ltx_page_footer {
display: none;
} figure {
display: table; width: 95%;
} figcaption {
display: table-caption; caption-side: bottom;
} .ltx_para > .ltx_p:first-child { text-indent:0em; } .ltx_listingline {
white-space:nowrap; min-height:1.42857143em;
} .ltx_theorem_theorem .ltx_font_italic {
font-style: normal;
}
.ltx_theorem_theorem {
border-left: 7px solid #ccc; /*padding: 2px 4px;*/ padding-left: 10px; margin-left: 3em;
}
.ltx_theorem_theorem h6 {
/*color: #333;*/ font-weight: normal;
}
.ltx_listing {
/* A combination of pre and code. */ font-family: Menlo, Monaco, Consolas, "Courier New", monospace; padding: 2px 4px; font-size: 90%; border-radius: 4px; display: block; line-height: 1.42857143; word-break: break-all; word-wrap: break-word; color: #333333; background-color: #f5f5f5; border: 1px solid #cccccc;
}
.ltx_caption {
padding-top: 8px; padding-bottom: 8px; color: #999999; text-align: center;
}
.ltx_framed_rectangle {
text-align: left; border: 1px solid #cccccc; font-size: 90%; border-radius: 4px; padding: 2px 4px;
}
.ltx_theorem_theorem {
font-style: normal important!;
}
</style>
</head> <body>
<article class='ltx_document'>
<p class='ltx_p'>SINGLE ASSIGNMENT C <br class='ltx_break'> TUTORIAL <br class='ltx_break'> VERSION 1.2.3</p> <p class='ltx_p'>Sven-Bodo Scholz Stephan Herhut <br class='ltx_break'>Frank Penczek Clemens Grelck <br class='ltx_break'>Artem Shinkarov Hans-Nikolai Vießmann <br class='ltx_break'></p> <p class='ltx_p'>March 14, 2022</p>
<h6>Contents</h6> <ul class='ltx_toclist'> <li class='ltx_tocentry ltx_tocentry_part'> <a href='#Pt1' title='Part I Trails Covering the Basics of SaC' class='ltx_ref'>I Trails Covering the Basics of SaC</a> <ul class='ltx_toclist ltx_toclist_part'> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch1' title='Chapter 1 Running the first program ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>1 Running the first program</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch1.S1' title='1.1 A Checklist ‣ Chapter 1 Running the first program ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>1.1 A Checklist</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch1.S2' title='1.2 Create your first SaC Source File ‣ Chapter 1 Running the first program ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>1.2 Create your first SaC Source File</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch1.S3' title='1.3 Compile the Source File and Run the Program ‣ Chapter 1 Running the first program ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>1.3 Compile the Source File and Run the Program</a></li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch2' title='Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2 Array Programming Basics</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'> <a href='#Ch2.S1' title='2.1 Lesson 1: Arrays as Data ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1 Lesson 1: Arrays as Data</a> <ul class='ltx_toclist ltx_toclist_section'> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch2.S1.SS1' title='2.1.1 Defining Arrays ‣ 2.1 Lesson 1: Arrays as Data ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1.1 Defining Arrays</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch2.S1.SS2' title='2.1.2 Arrays and Variables ‣ 2.1 Lesson 1: Arrays as Data ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1.2 Arrays and Variables</a></li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_section'> <a href='#Ch2.S2' title='2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.2 Lesson 2: Shape-Invariant Programming</a> <ul class='ltx_toclist ltx_toclist_section'> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch2.S2.SS1' title='2.2.1 Standard Array Operations ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.2.1 Standard Array Operations</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch2.S2.SS2' title='2.2.2 Axis Control Notation ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.2.2 Axis Control Notation</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch2.S2.SS3' title='2.2.3 Putting it all Together ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.2.3 Putting it all Together</a></li> </ul> </li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch3' title='Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3 Basic Program Structure</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'> <a href='#Ch3.S1' title='3.1 Lesson 3: Functions and their Types ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.1 Lesson 3: Functions and their Types</a> <ul class='ltx_toclist ltx_toclist_section'> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S1.SS1' title='3.1.1 Function Definitions ‣ 3.1 Lesson 3: Functions and their Types ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.1.1 Function Definitions</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S1.SS2' title='3.1.2 Built-in Types ‣ 3.1 Lesson 3: Functions and their Types ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.1.2 Built-in Types</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S1.SS3' title='3.1.3 Subtyping ‣ 3.1 Lesson 3: Functions and their Types ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.1.3 Subtyping</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S1.SS4' title='3.1.4 Function Overloading ‣ 3.1 Lesson 3: Functions and their Types ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.1.4 Function Overloading</a></li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_section'> <a href='#Ch3.S2' title='3.2 Lesson 4: Function Bodies ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.2 Lesson 4: Function Bodies</a> <ul class='ltx_toclist ltx_toclist_section'> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S2.SS1' title='3.2.1 Variable Declarations ‣ 3.2 Lesson 4: Function Bodies ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.2.1 Variable Declarations</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S2.SS2' title='3.2.2 Assignments ‣ 3.2 Lesson 4: Function Bodies ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.2.2 Assignments</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S2.SS3' title='3.2.3 Conditionals ‣ 3.2 Lesson 4: Function Bodies ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.2.3 Conditionals</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S2.SS4' title='3.2.4 Loops ‣ 3.2 Lesson 4: Function Bodies ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.2.4 Loops</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S2.SS5' title='3.2.5 Explicit Control Flow Manipulation ‣ 3.2 Lesson 4: Function Bodies ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.2.5 Explicit Control Flow Manipulation</a></li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_section'> <a href='#Ch3.S3' title='3.3 Lesson 5: Advanced Topics ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.3 Lesson 5: Advanced Topics</a> <ul class='ltx_toclist ltx_toclist_section'> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S3.SS1' title='3.3.1 User-defined Types ‣ 3.3 Lesson 5: Advanced Topics ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.3.1 User-defined Types</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch3.S3.SS2' title='3.3.2 Type Conversions ‣ 3.3 Lesson 5: Advanced Topics ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.3.2 Type Conversions</a></li> </ul> </li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch4' title='Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>4 With-Loops</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'> <a href='#Ch4.S1' title='4.1 Lesson 6: with-loop Basics ‣ Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>4.1 Lesson 6: with-loop Basics</a> <ul class='ltx_toclist ltx_toclist_section'> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch4.S1.SS1' title='4.1.1 Basic Components ‣ 4.1 Lesson 6: with-loop Basics ‣ Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>4.1.1 Basic Components</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch4.S1.SS2' title='4.1.2 Generator Ranges ‣ 4.1 Lesson 6: with-loop Basics ‣ Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>4.1.2 Generator Ranges</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch4.S1.SS3' title='4.1.3 Generator Expressions ‣ 4.1 Lesson 6: with-loop Basics ‣ Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>4.1.3 Generator Expressions</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch4.S1.SS4' title='4.1.4 Reductions and further with-loop Operations ‣ 4.1 Lesson 6: with-loop Basics ‣ Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>4.1.4 Reductions and further with-loop Operations</a></li> </ul> </li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch5' title='Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>5 Working with Modules</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch5.S1' title='5.1 Name Spaces ‣ Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>5.1 Name Spaces</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch5.S2' title='5.2 Use Statements ‣ Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>5.2 Use Statements</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch5.S3' title='5.3 Import statement ‣ Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>5.3 Import statement</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch5.S4' title='5.4 Putting It Together ‣ Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>5.4 Putting It Together</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch5.S5' title='5.5 Implementing Modules ‣ Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>5.5 Implementing Modules</a></li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch6' title='Chapter 6 Case Studies ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>6 Case Studies</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch6.S1' title='6.1 Lesson 7: Image Processing ‣ Chapter 6 Case Studies ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>6.1 Lesson 7: Image Processing</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch6.S2' title='6.2 Lesson 8: Computing Mandelbrot Images ‣ Chapter 6 Case Studies ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>6.2 Lesson 8: Computing Mandelbrot Images</a></li> </ul> </li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_part'> <a href='#Pt2' title='Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>II Trails Covering More Advanced Features of SaC</a> <ul class='ltx_toclist ltx_toclist_part'> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch7' title='Chapter 7 Treasures in the Standard Library ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>7 Treasures in the Standard Library</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch7.S1' title='7.1 Lesson: Benchmarking SaC Programs ‣ Chapter 7 Treasures in the Standard Library ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>7.1 Lesson: Benchmarking SaC Programs</a></li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_chapter'><a href='#Ch8' title='Chapter 8 User Defined Types ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>8 User Defined Types</a></li> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch9' title='Chapter 9 Dealing with I/O and State in General ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>9 Dealing with I/O and State in General</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'> <a href='#Ch9.S1' title='9.1 Lesson: States and Objects — the basics ‣ Chapter 9 Dealing with I/O and State in General ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>9.1 Lesson: States and Objects — the basics</a> <ul class='ltx_toclist ltx_toclist_section'> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch9.S1.SS1' title='9.1.1 Reference Parameters ‣ 9.1 Lesson: States and Objects — the basics ‣ Chapter 9 Dealing with I/O and State in General ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>9.1.1 Reference Parameters</a></li> <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch9.S1.SS2' title='9.1.2 Global Objects ‣ 9.1 Lesson: States and Objects — the basics ‣ Chapter 9 Dealing with I/O and State in General ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>9.1.2 Global Objects</a></li> </ul> </li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_chapter'> <a href='#Ch10' title='Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>10 Interfacing with Other Languages</a> <ul class='ltx_toclist ltx_toclist_chapter'> <li class='ltx_tocentry ltx_tocentry_section'> <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'>10.1 Lesson: Calling C from SaC</a> <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'>10.1.1 Using C in the small</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'>10.1.2 Dealing with non-scalar arrays</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'>10.1.3 Stateful C functions</a></li> </ul> </li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch10.S2' title='10.2 Lesson: Using SaC libraries from C ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>10.2 Lesson: Using SaC libraries from C</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch10.S3' title='10.3 Lesson: Using SaC libraries from C++ ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>10.3 Lesson: Using SaC libraries from C++</a></li> <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch10.S4' title='10.4 Lesson: Using SaC libraries from Fortran ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'>10.4 Lesson: Using SaC libraries from Fortran</a></li> </ul> </li> </ul> </li> </ul>
<section id='Pt1' class='ltx_part'> <h2 class='ltx_title ltx_title_part'> Part I Trails Covering the Basics of SaC </h2>
<section id='Ch1' class='ltx_chapter'> <h3 class='ltx_title ltx_title_chapter'> Chapter 1 Running the first program</h3>
<p class='ltx_p'>The following instructions will help you write your first SaC program.</p>
<section id='Ch1.S1' class='ltx_section'> <h4 class='ltx_title ltx_title_section'> 1.1 A Checklist</h4>
<p class='ltx_p'>To successfully write and run your first SaC program, you will need:</p> <ul id='Ch1.S1.I1' class='ltx_itemize'> <li id='Ch1.S1.I1.i1' class='ltx_item' style='list-style-type:none;'> •
<p class='ltx_p'>An ANSI C compiler, such as gcc. Though not needed directly, the SaC compiler relies on it.</p>
</li> <li id='Ch1.S1.I1.i2' class='ltx_item' style='list-style-type:none;'> •
<p class='ltx_p'>The SaC compiler sac2c. It can be downloaded at
<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>
</div>
</li>
<li id='Ch1.S1.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>The SaC standard library can be downloaded from GitHub
<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
repository.</p>
</div>
</li>
<li id='Ch1.S1.I1.i4' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>Your favorite text editor, such as vi or emacs.</p>
</li>
</ul>
</div>
</section>
<section id='Ch1.S2' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
1.2 Create your first SaC Source File</h4>
<p class='ltx_p'>Start your editor and type the following program:</p>
<figure id='LST1' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 1: Hello World</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludGYoIkhlbGxvIFdvcmxkIVxuIik7CiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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>);
<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;
<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>}
</figure>
<p class='ltx_p'>As you can see, it has a strong resemblance to C. The major difference
are the module use declarations at the beginning of the program.
For now, it suffices to keep in mind, that these two use declarations for most
experiments will do the job.</p>
<p class='ltx_p'>In order to proceed, save this program into a file named world.sac.</p>
</section>
<section id='Ch1.S3' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
1.3 Compile the Source File and Run the Program</h4>
<p class='ltx_p'>The SaC compiler invocation is similar to the standard invocation of
C compilers.
A typical shell session for compiling world.sac could be:</p>
<figure id='LST2' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 2: Typical shell session</figcaption>
<a href='data:text/plain;base64,ICQgY2QgL2hvbWUvc2JzL3NhYy8KICQgbHMKIHdvcmxkLnNhYwogJCBzYWMyYyAgd29ybGQuc2FjCiAkIGxzCiBhLm91dCAgICAgIGEub3V0LmMgICAgd29ybGQuc2FjCiAkIGEub3V0CiBIZWxsbyBXb3JsZCE='>⬇</a>
$ cd /home/sbs/sac/
$ ls
world.sac
$ sac2c world.sac
$ ls
a.out a.out.c world.sac
$ a.out
Hello World!
</figure>
<p class='ltx_p'>The compilation process consists of two steps.
First, the SaC compiler generates a C file, which then is compiled
into target code by utilizing the system’s C compiler.
If no target file name is specified, the intermediate C file is named
a.out.c so that the subsequent invocation of the C compiler
creates an executable named a.out.</p>
<p class='ltx_p'>In the same way the default target name a.out is borrowed from
standard C compilers, the -o option for specifying target names
is adopted as well.
For example, sac2c -o world world.sac results
in files world.c and world.</p>
<p class='ltx_p'>Note here, that the compiled program, depending on the operating system,
is linked either statically or dynamically.
However, it does not require any further linking or interpretation.</p>
</section>
</section>
<section id='Ch2' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 2 Array Programming Basics</h3>
<p class='ltx_p'>This trail gives an introduction to the basic concepts of array programming
in SaC.
It consists of two lessons: Arrays as Data and Shape-Invariant Programming.
In the former lesson, the major differences between arrays in SaC and arrays
in more mainstream languages are explained.
The lesson Shape-Invariant Programming gives an introduction into the most
important array operations available in SaC.
Based on these operations, several small examples demonstrate how more complex
array operations can be constructed by simply combining the basic ones.</p>
<section id='Ch2.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
2.1 Lesson 1: Arrays as Data</h4>
<p class='ltx_p'>In SaC, arrays are the only data structures available. Even scalar values
are considered arrays.
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 ltx_font_italic'>data vector</em>.
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 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>
<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 SaC, and how they can be generated via nesting.
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 ltx_font_italic'>matrices</em> is defined.</p>
<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 SaC.</p>
<section id='Ch2.S1.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
2.1.1 Defining Arrays</h5>
<p class='ltx_p'>In this section, several means for specifying arrays are explained.</p>
<p class='ltx_p'>In principle, all arrays in SaC can be defined by using the reshape operation.
reshape 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>
<p class='ltx_p'>To get started, try the following program:</p>
<figure id='LST3' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 3: Defining Arrays I</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludChyZXNoYXBlKFs1XSwgWzEsMiwzLDQsNV0pKTsKICAgcHJpbnQocmVzaGFwZShbMywyXSwgWzEsMiwzLDQsNSw2XSkpOwogICBwcmludChyZXNoYXBlKFszLDIsMV0sIFsxLDIsMyw0LDUsNl0pKTsKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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]));
<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]));
<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]));
<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;
<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>}
</figure>
<p class='ltx_p'>It prints three arrays:</p>
<ul id='Ch2.S1.I1' class='ltx_itemize'>
<li id='Ch2.S1.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>an array of dimensionality 1 with 5 elements [1,2,3,4,5]</p>
</li>
<li id='Ch2.S1.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>an array of dimensionality 2 with 3 rows and 2 columns, and</p>
</li>
<li id='Ch2.S1.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<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>
</li>
</ul>
<p class='ltx_p'>Note here, that the function print can be applied to arbitrary arrays.
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.
However, as the terminal allows for 2 dimensions only, arrays of higher
dimensionality are interpreted as nestings of 2-dimensional arrays.
Therefore, the 3-dimensional array is printed as a 2-dimensional array of vectors.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 1. </h6>
<p class='ltx_p'>In all these examples, the product of the shape vector matches the length of
the data vector.
What do you expect to happen, if this condition does not hold?</p>
<p class='ltx_p'>For reasons of convenience, we use the following terminology:</p>
<dl id='Ch2.S1.I2' class='ltx_description'>
<dt id='Ch2.S1.I2.ix1' class='ltx_item'>scalar</dt>
<dd class='ltx_item'>
<p class='ltx_p'>always denotes an array of dimensionality 0,</p>
</dd>
<dt id='Ch2.S1.I2.ix2' class='ltx_item'>vector</dt>
<dd class='ltx_item'>
<p class='ltx_p'>always denotes an array of dimensionality 1, and</p>
</dd>
<dt id='Ch2.S1.I2.ix3' class='ltx_item'>matrix</dt>
<dd class='ltx_item'>
<p class='ltx_p'>always denotes an array of dimensionality 2.</p>
</dd>
</dl>
<p class='ltx_p'>As <em class='ltx_emph ltx_font_italic'>all</em> arrays can be defined in terms of reshape, the following
program as well is perfectly legal:
</p>
<figure id='LST4' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 4: Defining Arrays II</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludChyZXNoYXBlKFsxXSwgWzFdKSk7CiAgIHByaW50KHJlc2hhcGUoW10sIFsxXSkpOwogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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]));
<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]));
<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;
<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>}
</figure>
<p class='ltx_p'>The most interesting aspect of this program is the array defined in
line 7.
The empty shape vector makes it a 0-dimensional array, i.e. a scalar.
The data vector carries the scalar’s value, which, in this example, is 1.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 2. </h6>
<p class='ltx_p'>The arguments of reshape are vectors, i.e. arrays of dimensionality 1.
Can they be specified by e expressions themselves?</p>
<p class='ltx_p'>The reshape notation is relatively clumsy, in particular, when
being used for scalars.
Therefore, scalars and vectors can alternatively be specified by
shortcut notations as well.</p>
<p class='ltx_p'>For experimenting with these, try the following:</p>
<figure id='LST5' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 5: Shortcut Notation for Arrays</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBwcmludCgxKTsKICAgcHJpbnQoWzEsMiwzLDQsNV0pOwogICBwcmludChbWzEsMl0sIFszLDRdLCBbNSw2XV0pOwogICBwcmludChnZW5hcnJheShbNCwzLDJdLCAxKSk7CiAgIHByaW50KGdlbmFycmF5KFs0LDNdLCBbMSwyXSkpOwogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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);
<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]);
<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]]);
<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));
<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]));
<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;
<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>}
</figure>
<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
reshape
in the examples above in fact is a standard abbreviation of SaC.
The example in line 8 shows that nestings of arrays are implicitly eliminated, i.e.
the resulting array is identical to:</p>
<p class='ltx_p ltx_align_center'>reshape([3,2], [1,2,3,4,5,6]).</p>
<p class='ltx_p'>For this reason, array nestings in SaC 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>
<p class='ltx_p'>Furthermore, a new function is introduced: genarray.
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.
As shown in the example of line 10, the individual array elements can be non-scalar
arrays as well, which implicitly extends the dimensionality of the result array.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 3. </h6>
<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'>
Dimension: 3
Shape : < 5, 2, 2>
< 0 0 > < 0 0 >
< 1 0 > < 0 0 >
< 0 1 > < 0 0 >
< 0 0 > < 1 0 >
< 0 0 > < 0 1 >
</pre>
<p class='ltx_p'>but whose definition does not contain the symbol ‘1’ more than once?</p>
</section>
<section id='Ch2.S1.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
2.1.2 Arrays and Variables</h5>
<p class='ltx_p'>This section explains why in SaC arrays are data and not containers for values
as found in most other languages.</p>
<p class='ltx_p'>So far, all examples were expression based, i.e. we did not use any variables.
Traditionally, there are two different ways of introducing variables.
In conventional (imperative) languages such as C, variables denote memory
locations which hold values that may change during computation.
In functional languages, similar to mathematics, variables are considered place holders for values.
As a consequence, a variable’s value can never change.
Although this difference may seem rather subtle at first glance, it has quite
some effects when operations on large data structures (in our case: large arrays)
are involved.</p>
<p class='ltx_p'>Let’s have a look at an example:</p>
<figure id='LST6' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 6: Variables as Placeholders</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gWzEsMiwzLDRdOwogICBwcmludChhKTsKCiAgIGIgPSBtb2RhcnJheShhLCBbMF0sIDkpOwogICBwcmludChiKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</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><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;'>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;'>11</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><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>}
</figure>
<p class='ltx_p'>The function modarray expects three arguments: an 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.
As we would expect, the resulting array b is almost identical to a,
only the very first element has changed into 9.</p>
<p class='ltx_p ltx_align_center'>Note here, that indexing in SaC always starts with index !</p>
<p class='ltx_p'>Referring to the container / place holder discussion, the crucial question is:
does the variable a denote a container, whose value is changed by
modarray? If this would be the case, a and b
would share the same container, and every access to a after
line 9 would
yield [9,2,3,4]. If a in fact is a place holder, it will
always denote the array [1,2,3,4], no matter what functions have
obtained a as an argument.</p>
<p class='ltx_p'>To answer this question, you may simply shift the first call of
print two lines down. As you can see, in SaC, variables are indeed
place holders.</p>
<p class='ltx_p'>
A note for efficiency freaks:
You may wonder whether this implies that modarray always copies the entire array.
In fact, it only copies a if the place-holder property would be violated otherwise.
</p>
<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.
In other words, the underlying concept <em class='ltx_emph ltx_font_italic'>guarantees</em>, that all functions are
“pure”.
Although this helps in avoiding nasty errors due to non-intended side-effects,
it sometimes seems to be an annoyance to always invent new variable names,
in particular, if arrays are to be modified successively.</p>
<p class='ltx_p'>To cope with this problem, in SaC, 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.
In a sequence of variable definitions, the scope of a variable starts with the left-hand
side of the subsequent variable definition
and either reaches down to the end of the function, or, provided at least one further
definition of a variable with the same name exists, to the right-hand side of
the next such definition.
This measure allows us to reuse variable names.
A slight modification of our example demonstrates the effect of variable scopes
in SaC:</p>
<figure id='LST7' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 7: Variable Scopes</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gWzEsMiwzLDRdOwoKICAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgIHByaW50KGEpOwogICBhID0gYjsKICAgcHJpbnQoYSk7CgogICBhID0gbW9kYXJyYXkoYSwgWzFdLCA4KTsKICAgcHJpbnQoYSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>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;'>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;'>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;'>12</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><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;'>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;'>15</span></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_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;'>17</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Here, the use of a 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
in line 10.</p>
<p class='ltx_p'>The definition in line 13 shows, how variable scopes can be used to specify
code that looks very much “imperative”.
However, you should always keep in mind, that in SaC, the place-holder property
<em class='ltx_emph ltx_font_italic'>always</em> holds!</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 4. </h6>
<p class='ltx_p'>What result do you expect from the following SaC program?</p>
<figure id='LST8' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 8: Scope Exercise</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gWzEsMiwzLDRdOwogICBiID0gW2EsYV07CgogICBhID0gbW9kYXJyYXkobW9kYXJyYXkoYSwgWzBdLCAwKSwgWzFdLCAwKTsKICAgYiA9IG1vZGFycmF5KGIsIFswXSwgYSk7CiAgIHByaW50KGIpOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<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>];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</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><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;'>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;'>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;'>12</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><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;'>14</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
</section>
</section>
<section id='Ch2.S2' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
2.2 Lesson 2: Shape-Invariant Programming</h4>
<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
are applied to entire arrays rather than to individual array elements.
In order to realize such a programming style, it is an essential
prerequisite to be able to apply functions to arbitrarily shaped arguments.
In SaC, this is the case.</p>
<p class='ltx_p'>All built-in array operations as well as all array operations supplied by the
standard library can be applied to arguments of arbitrary shapes.
However, most of the operations that require more than one argument do have
certain restrictions with respect to which array shapes can be combined as valid arguments.
If an operation is applied to a set of arguments whose shapes constitute an
illegal combination, usually, a type error message is given.
In cases where this cannot be decided statically, the compiler may accept
such a kind of domain error and produce a runtime error instead.</p>
<p class='ltx_p'>This lesson consists of three parts:
The section on Standard Array Operations introduces the most important
standard array operations provided by the current SaC compiler
release<sup class='ltx_note_mark'>1</sup><sup class='ltx_note_mark'>1</sup>
1
As of this writing, the latest SaC compiler release
is version 1.2.3..
The next section explains Axis Control Notation, a powerful but simple
way of manipulating the focus of array operations with respect to individual axes of argument arrays.
With the axis-control notation, the basic operations often can easily be combined into rather
complex operations as demonstrated in the section on Putting it all Together.</p>
<section id='Ch2.S2.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
2.2.1 Standard Array Operations</h5>
<p class='ltx_p'>In the sequel, several toy examples demonstrate the functionality of the most basic
array operations that come as part of the current SaC release.
Their design is inspired by those available in APL.
However, several aspects — in particular regarding the treatment of special
cases in APL — have
been adjusted to allow for a more favourable compilation in SaC that yields better runtime performance.</p>
<p class='ltx_p'>
A note for language design freaks:
You may have your own ideas on what primitive array operations should be available
and how the precise semantics of these should look like.
Therefore, it should be mentioned here, that all array operations introduced in the
remainder of this section are not
hard-wired into the language, but they are defined in the module Array
from the standard library.
This is to say that the advanced SaC programmer may write his own set of
standard array operations.
</p>
<p class='ltx_p'>The individual parts of this section are all organized according
to the following scheme:
first, a semi-formal introduction to the functionality of individual operations
is given. Then, several examples shed some more light on the exact semantics of each operation by
varying the argument-shape constellations and by exploring “border-line cases”
with respect to domain restrictions if these do exist‘.</p>
<section id='Ch2.S2.SS1.SSSx1' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Basic Operations</h6>
<p class='ltx_p'>The most basic operations are very close to the model of arrays in SaC.
They comprise functions for inspecting, creating, and modifying an array’s
shape and content.
If not stated otherwise, they are applicable to arbitrarily shaped arguments of
built-in element type.
Note here, that some of them have been introduced in earlier lessons
already.</p>
<dl id='Ch2.S2.I1' class='ltx_description'>
<dt id='Ch2.S2.I1.ix1' class='ltx_item'>dim(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>returns the (scalar) dimensionality of the argument array
a.
<br class='ltx_break'>Domain restrictions: none.</p>
</dd>
<dt id='Ch2.S2.I1.ix2' class='ltx_item'>shape(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>returns the shape vector of the argument array a.
<br class='ltx_break'>Domain restrictions: none.</p>
</dd>
<dt id='Ch2.S2.I1.ix3' class='ltx_item'>a[iv]</dt>
<dd class='ltx_item'>
<p class='ltx_p'>constitutes a short-cut notation for sel(iv, a).
It selects the array element of a at index position iv.
As a may be of any shape, the index position is given as an
<em class='ltx_emph ltx_font_italic'>index vector</em>. The dimensionality of the result is identical to the dimensionality of
a minus the length of iv.
Accordingly, its shape is derived from the last components of
the shape of a.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I1.ix3.I1' class='ltx_itemize'>
<li id='Ch2.S2.I1.ix3.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(iv) == 1</p>
</li>
<li id='Ch2.S2.I1.ix3.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(iv)0 ⇐ dim(a)</p>
</li>
<li id='Ch2.S2.I1.ix3.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<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_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_i}}}}\in\{0,\dots,\textrm{\lstinlinelst_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{\lstinlinelst_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>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I1.ix4' class='ltx_item'>a[iv]=expr</dt>
<dd class='ltx_item'>
<p class='ltx_p'>is a short-cut notation for an assignment of the form
a = modarray(a, iv, expr).
The result of this application is a new array which is almost identical to
a. Only the element (subarray) at index position iv
is different; it is replaced by expr.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I1.ix4.I2' class='ltx_itemize'>
<li id='Ch2.S2.I1.ix4.I2.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(iv) == 1</p>
</li>
<li id='Ch2.S2.I1.ix4.I2.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(iv)0 ⇐ dim(a)</p>
</li>
<li id='Ch2.S2.I1.ix4.I2.i3' class='ltx_item' style='list-style-type:none;'>
•
<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_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_i}}}}\in\{0,\dots,\textrm{\lstinlinelst_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{\lstinlinelst_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>
</li>
<li id='Ch2.S2.I1.ix4.I2.i4' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(expr) == shape(a[iv]).</p>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I1.ix5' class='ltx_item'>reshape(shp, expr)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>computes an array with shape vector shp
and data vector identical to that of expr.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I1.ix5.I3' class='ltx_itemize'>
<li id='Ch2.S2.I1.ix5.I3.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(shp) == 1</p>
</li>
<li id='Ch2.S2.I1.ix5.I3.i2' class='ltx_item' style='list-style-type:none;'>
•
<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_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{\lstinlinelst_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{\lstinlinelst_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>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I1.ix6' class='ltx_item'>genarray(shp, expr)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>generates an array of shape shp,
whose elements are all identical to expr.
<br class='ltx_break'>Domain restrictions: dim(shp) == 1.</p>
</dd>
</dl>
<p class='ltx_p'>Although these operations are fairly self-explaining or known from
Lesson <a href='#Ch2.S1' title='2.1 Lesson 1: Arrays as Data ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1</a> on Arrays as Data, let us have a look
at a few example applications:</p>
<figure id='LST9' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 9: Basic Operations</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzEsMiwzLDQsNSw2LDcsOCw5LDEwLDExLDEyXTsKCiAgIG1hdCA9IHJlc2hhcGUoWzMsNF0sIHZlY3QpOwogICBwcmludChtYXQpOwoKICAgcHJpbnQobWF0W1sxLDFdXSk7CiAgIHByaW50KG1hdFtbMl1dKTsKICAgcHJpbnQobWF0W1tdXSk7CgogICBtYXRbWzEsMV1dID0gMDsKICAgcHJpbnQobWF0KTsKICAgbWF0W1syXV0gPSBbMCwwLDAsMF07CiAgIHByaW50KG1hdCk7CiAgIG1hdFtbXV0gPSBnZW5hcnJheShbMyw0XSwgMCk7CiAgIHByaW50KG1hdCk7CgogICBlbXB0eV92ZWN0ID0gW107CiAgIHByaW50KGVtcHR5X3ZlY3QpOwogICBlbXB0eV9tYXQgPSByZXNoYXBlKFsyMiwwXSwgZW1wdHlfdmVjdCk7CiAgIHByaW50KGVtcHR5X21hdCk7CiAgIHByaW50KGRpbShlbXB0eV9tYXQpKTsKICAgcHJpbnQoc2hhcGUoZW1wdHlfbWF0KSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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;'>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;'>10</span></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'>mat</span>[[1,1]]);
<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]]);
<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>[[]]);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>
<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;
<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>);
<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];
<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>);
<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);
<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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></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>[];
<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>);
<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>);
<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>);
<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>));
<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>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</span></span>
<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;
<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>}
</figure>
<p class='ltx_p'>The different selections in lines 11-13 show how
the dimensionality of the selected element increases as the length of the index
vector decreases. If the index vector degenerates into an empty vector, the
entire array is selected. Similarly, the applications of modarray in
lines 15-20 demonstrate the successive replacement
of individual elements, rows, or the entire array.</p>
<p class='ltx_p'>Lines 22-27 are meant to draw the reader’s
attention to the fact that there exists an unlimited number of distinct empty
arrays in SaC!</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 5. </h6>
<p class='ltx_p'>Assuming mat to be defined as in the previous example, what results do you
expect from the following expressions:</p>
<ul id='Ch2.S2.I2' class='ltx_itemize'>
<li id='Ch2.S2.I2.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>reshape([3,0,5], [])tutorial?</p>
</li>
<li id='Ch2.S2.I2.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>reshape([3,0,5], [])1?</p>
</li>
<li id='Ch2.S2.I2.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>reshape([3,0,5], [])1,0?</p>
</li>
<li id='Ch2.S2.I2.i4' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>mat[reshape([2,0], [])]?</p>
</li>
</ul>
</section>
<section id='Ch2.S2.SS1.SSSx2' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Element-wise Extensions</h6>
<p class='ltx_p'>Most of the operations that can be found as standard operations on scalars
in other languages are applicable to entire arrays in SaC.
Their semantics are simply element-wise extensions of the well-known scalar
operations.
The binary operations in general do have some domain restrictions.
First, the element types of both arguments do have to be identical.
Furthermore, either one of the arguments has to be a scalar value,
or both arguments have to have identical shapes.
In the former case, the value of the scalar argument is combined with each element of the
(potentially non-scalar) other argument, which dictates the shape of the result.
The latter case results in an array of the same shape as both arguments are,
with the values being computed from the corresponding elements of the
argument arrays.</p>
<p class='ltx_p'>In detail, the following operations are available:</p>
<dl id='Ch2.S2.I3' class='ltx_description'>
<dt id='Ch2.S2.I3.ix1' class='ltx_item'>arithmetic operations</dt>
<dd class='ltx_item'>
<p class='ltx_p'>including addition (<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> + <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>),
subtraction (<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> - <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>), negation (-<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>), multiplication
(<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> * <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>), and division (<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> / <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>).
Furthermore, a modulo operation (<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> % <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>) is supported on integer
numbers.
<br class='ltx_break'>Domain restrictions: 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.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>
</dd>
<dt id='Ch2.S2.I3.ix2' class='ltx_item'>logical operations</dt>
<dd class='ltx_item'>
<p class='ltx_p'>including conjunction (<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> && <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>), disjunction
(<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> || <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>), and negation (!<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>).
<br class='ltx_break'>Domain restrictions: the element types have to be Boolean.</p>
</dd>
<dt id='Ch2.S2.I3.ix3' class='ltx_item'>relational operations</dt>
<dd class='ltx_item'>
<p class='ltx_p'>including less-than (<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'> <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 (<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> ⇐ <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>), equal (<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> == <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>),
not-equal (<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> != <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>),
greater-or-equal (<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> >= <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>), and greater-than
(<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> > <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>).
<br class='ltx_break'>Domain restrictions: 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>
</dd>
<dt id='Ch2.S2.I3.ix4' class='ltx_item'>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>)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>compute the element-wise maximum and
minimum, respectively.
<br class='ltx_break'>Domain restrictions: 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>
</dd>
<dt id='Ch2.S2.I3.ix5' class='ltx_item'>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>)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>is an element-wise extension of a conditional.
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
shape serves as shape of the result, whose values are taken from
<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'>Domain restrictions:</p>
<ul id='Ch2.S2.I3.ix5.I1' class='ltx_itemize'>
<li id='Ch2.S2.I3.ix5.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<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>
</li>
<li id='Ch2.S2.I3.ix5.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<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>
</li>
<li id='Ch2.S2.I3.ix5.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<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_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_shp}}}}:1)' display='inline'><mrow><mrow><mo>∃</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>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>.</p>
</li>
</ul>
</dd>
</dl>
<p class='ltx_p'>Again, these operations are fairly self-explanatory.
Nevertheless, we present a few examples:</p>
<figure id='LST10' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 10: Elementwise Extensions</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICAgcHJpbnQobWF0KTsKCiAgIG1hdDIgPSB3aGVyZShtYXQgJSAyID09IDAsIG1hdCwgLW1hdCk7CiAgIHByaW50KG1hdDIpOwoKICAgcHJpbnQobWF4KG1hdDIsIDApKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>vect</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+10,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+20];
<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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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'>mat2</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>where</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>2<span class='ltx_text ltx_lst_space'> </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'>mat</span>,<span class='ltx_text ltx_lst_space'> </span>-<span class='ltx_text ltx_lst_identifier'>mat</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat2</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>max</span>(<span class='ltx_text ltx_lst_identifier'>mat2</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_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;
<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>}
</figure>
<p class='ltx_p'>The most interesting part of this example is the definition
of the matrix mat2 in line 11.
The even numbers from the matrix mat are taken as they are, whereas
the odd numbers are negated.
Note here, that all sub expressions in predicate position are in fact non-scalar
arrays: (mat % 2) denotes a matrix of zeros and ones and
(mat % 2) == 0 denotes a matrix of boolean values.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 6. </h6>
<p class='ltx_p'>What results do you expect from the following expressions:</p>
<ul id='Ch2.S2.I4' class='ltx_itemize'>
<li id='Ch2.S2.I4.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>min(reshape([3,0,5], []), 42)?</p>
</li>
<li id='Ch2.S2.I4.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>reshape([3,0,5], []) + reshape([3,0,5], [])?</p>
</li>
<li id='Ch2.S2.I4.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>reshape([1,1], [1]) + reshape([1], [1])?</p>
</li>
</ul>
</section>
<section id='Ch2.S2.SS1.SSSx3' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Restructuring Operations</h6>
<p class='ltx_p'>The operations to be introduced here do not compute new values at all.
Instead, they are meant to create slightly differently structured arrays
from existing ones.
Therefore, they are applicable to arrays of all built-in element types.</p>
<dl id='Ch2.S2.I5' class='ltx_description'>
<dt id='Ch2.S2.I5.ix1' class='ltx_item'>take(sv, a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>takes as many elements from the array a as indicated
by the shape vector sv. Each element of sv corresponds to
one axis of a starting from the leftmost one.
For positive components of sv, the elements are taken from the
“beginning”, i.e. starting with index 0, otherwise they are taken
from the “end” including the maximum legal index of the corresponding
axis.
All axes of a where there exists no corresponding element in
sv are taken entirely.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I5.ix1.I1' class='ltx_itemize'>
<li id='Ch2.S2.I5.ix1.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(sv) == 1</p>
</li>
<li id='Ch2.S2.I5.ix1.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(sv)0 ⇐ dim(a)</p>
</li>
<li id='Ch2.S2.I5.ix1.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'><math id='Ch2.S2.I5.ix1.I1.i3.p1.m1' class='ltx_Math' alttext='forall_textrm_lstinline_lst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_i}}}}\in\{0,\dots,\textrm{\lstinlinelst_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}{sv}})0}}}}\}:\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_sv[%
[{\@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>sv</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>sv</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>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I5.ix2' class='ltx_item'>drop(sv, a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>drops as many elements from the array a as indicated
by the shape vector sv. Each element of sv corresponds to
one axis of a starting from the leftmost one.
For positive components of sv, the elements are dropped from the
“beginning”, i.e. starting with index 0, otherwise they are dropped
from the “end” starting from the maximum legal index of the corresponding
axis.
All axes of a where there exists no corresponding element in
sv are left untouched.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I5.ix2.I2' class='ltx_itemize'>
<li id='Ch2.S2.I5.ix2.I2.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(sv)= 1</p>
</li>
<li id='Ch2.S2.I5.ix2.I2.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(sv)0 ⇐ dim(a)</p>
</li>
<li id='Ch2.S2.I5.ix2.I2.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'><math id='Ch2.S2.I5.ix2.I2.i3.p1.m1' class='ltx_Math' alttext='forall_textrm_lstinline_lst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_i}}}}\in\{0,\dots,\textrm{\lstinlinelst_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}{sv}})0}}}}\}:\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_sv[%
[{\@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>sv</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>sv</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>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I5.ix3' class='ltx_item'>tile(sv, ov, a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>takes a tile of shape sv from a
starting at the index specified by the offset vector ov.
For axes where no values of sv or ov are specified
these are assumed to be identical to the extent of a along that axis or 0,
respectively.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I5.ix3.I3' class='ltx_itemize'>
<li id='Ch2.S2.I5.ix3.I3.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(sv) == dim(ov) == 1
</p>
</li>
<li id='Ch2.S2.I5.ix3.I3.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(sv)0 ⇐ dim(a)</p>
</li>
<li id='Ch2.S2.I5.ix3.I3.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(ov)0 ⇐ dim(a)</p>
</li>
<li id='Ch2.S2.I5.ix3.I3.i4' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'><math id='Ch2.S2.I5.ix3.I3.i4.p1.m1' class='ltx_Math' alttext='forall_textrm_lstinline_lst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_i}}}}\in\{0,\dots,\textrm{\lstinlinelst_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}{ov}})0}}}}\}:\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_ov[%
[{\@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>ov</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>ov</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>
</li>
<li id='Ch2.S2.I5.ix3.I3.i5' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'><math id='Ch2.S2.I5.ix3.I3.i5.p1.m1' class='ltx_Math' alttext='forall_textrm_lstinline_lst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_i}}}}\in\{0,\dots,\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_min%
({\@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{%
ltx_lst_identifier}{ov}})0,{\@listingGroup{ltx_lst_space}{~{}}}{%
\@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}%
{sv}})0)}}}}\}:\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_ov{\@listingGroup{ltx_lst_identifier}{i%
}}{\@listingGroup{ltx_lst_space}{~{}}}+{\@listingGroup{ltx_lst_space}{~{}}}{%
\@listingGroup{ltx_lst_identifier}{sv}}{\@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>min</mtext><mtext>(</mtext><mtext>shape</mtext><mtext>(</mtext><mtext>ov</mtext><mtext>)0,</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>sv</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>ov</mtext><mtext></mtext><mtext>i</mtext><mtext></mtext><mtext> </mtext><mtext>+</mtext><mtext> </mtext><mtext>sv</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>
</li>
<li id='Ch2.S2.I5.ix3.I3.i6' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'><math id='Ch2.S2.I5.ix3.I3.i6.p1.m1' class='ltx_Math' alttext='forall_textrm_lstinline_lst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_i}}}}\in\{\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_min%
({\@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{%
ltx_lst_identifier}{ov}})0,{\@listingGroup{ltx_lst_space}{~{}}}{%
\@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}%
{sv}})0)}}}},\dots,\textrm{\lstinlinelst_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}{sv}})0}}}}\}:\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_sv{\@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><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>min</mtext><mtext>(</mtext><mtext>shape</mtext><mtext>(</mtext><mtext>ov</mtext><mtext>)0,</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>sv</mtext><mtext>)0)</mtext></mrow><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>sv</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>sv</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>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I5.ix4' class='ltx_item'><math id='Ch2.S2.I5.ix4.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> ++ <math id='Ch2.S2.I5.ix4.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>2</mn></msub></math></dt>
<dd class='ltx_item'>
<p class='ltx_p'>concatenates arrays <math id='Ch2.S2.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.S2.I5.ix4.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> with respect to the leftmost axis.
As in SaC all arrays are homogeneous, this requires all but the leftmost
axis to be of identical extent.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I5.ix4.I4' class='ltx_itemize'>
<li id='Ch2.S2.I5.ix4.I4.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'><math id='Ch2.S2.I5.ix4.I4.i1.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.S2.I5.ix4.I4.i1.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of identical element type</p>
</li>
<li id='Ch2.S2.I5.ix4.I4.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>drop(1, shape(<math id='Ch2.S2.I5.ix4.I4.i2.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math>)) == drop(1, shape(<math id='Ch2.S2.I5.ix4.I4.i2.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math>)).</p>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I5.ix5' class='ltx_item'>rotate(ov, a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>rotates the array a with respect to those axes specified
by the offset vector ov.
Starting from the leftmost axis, the elements of ov specify by how many
positions the elements are rotated towards increasing indices (positive values)
or towards decreasing indices (negative values).
Domain restrictions:</p>
<ul id='Ch2.S2.I5.ix5.I5' class='ltx_itemize'>
<li id='Ch2.S2.I5.ix5.I5.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(ov) == 1</p>
</li>
<li id='Ch2.S2.I5.ix5.I5.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(ov)0 ⇐ dim(a)</p>
</li>
</ul>
</dd>
<dt id='Ch2.S2.I5.ix6' class='ltx_item'>shift(ov, expr, a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>shifts the array a with respect to those axes specified
by the offset vector ov.
The element positions that become “void” are filled by the (scalar)
default element expr.
Again, depending on the sign of the values of ov the elements
are either shifted towards increasing or decreasing indices.
<br class='ltx_break'>Domain restrictions:</p>
<ul id='Ch2.S2.I5.ix6.I6' class='ltx_itemize'>
<li id='Ch2.S2.I5.ix6.I6.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>dim(ov) == 1</p>
</li>
<li id='Ch2.S2.I5.ix6.I6.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(ov)0 ⇐ dim(a)</p>
</li>
<li id='Ch2.S2.I5.ix6.I6.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shape(expr)0 == []</p>
</li>
</ul>
</dd>
</dl>
<p class='ltx_p'>A few examples:</p>
<figure id='LST11' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 11: Restructuring Operations</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICAgcHJpbnQobWF0KTsKCiAgIHByaW50KHRha2UoWzIsLTJdLCBtYXQpKTsKICAgcHJpbnQodGFrZShbMl0sIG1hdCkpOwogICBwcmludCh0YWtlKFtdLCBtYXQpKTsKCiAgIHByaW50KHRha2UoWzBdLCBtYXQpKTsKICAgcHJpbnQodGFrZShbMiwgMF0sIG1hdCkpOwogICBwcmludCh0YWtlKFsyXSwgcmVzaGFwZShbMywwLDVdLCBbXSkpKTsKCiAgIHByaW50KGRyb3AoWzAsIC0xXSwgbWF0KSk7CgogICBwcmludChtYXQgKysgbWF0KTsKCiAgIHByaW50KHJvdGF0ZShbLTEsIDQyXSwgbWF0KSk7CiAgIHByaW50KHJvdGF0ZShbIDFdLCBtYXQpKTsKCiAgIHByaW50KHNoaWZ0KFswLCAtMl0sIDAsIG1hdCkpOwogICBwcmludChzaGlmdChbMCwgLTIyXSwgMCwgbWF0KSk7CiAgIHByaW50KHNoaWZ0KFsxXSwgMCwgbWF0KSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>vect</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+10,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+20];
<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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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'>take</span>([2,-2],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>take</span>([2],<span class='ltx_text ltx_lst_space'> </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'>take</span>([],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>take</span>([0],<span class='ltx_text ltx_lst_space'> </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'>take</span>([2,<span class='ltx_text ltx_lst_space'> </span>0],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>take</span>([2],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span>
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>drop</span>([0,<span class='ltx_text ltx_lst_space'> </span>-1],<span class='ltx_text ltx_lst_space'> </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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</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_text ltx_lst_space'> </span>++<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></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'>rotate</span>([-1,<span class='ltx_text ltx_lst_space'> </span>42],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</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'>print</span>(<span class='ltx_text ltx_lst_identifier'>rotate</span>([<span class='ltx_text ltx_lst_space'> </span>1],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></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'>shift</span>([0,<span class='ltx_text ltx_lst_space'> </span>-2],<span class='ltx_text ltx_lst_space'> </span>0,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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'>shift</span>([0,<span class='ltx_text ltx_lst_space'> </span>-22],<span class='ltx_text ltx_lst_space'> </span>0,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</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'>shift</span>([1],<span class='ltx_text ltx_lst_space'> </span>0,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</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><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;'>31</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>The applications of take in lines 11-13 demonstrate, how the
dimensionality of mat remains unaffected by the length of the
first argument.
Only the shape of the result and the “side” from which the elements
are taken is defined by it.</p>
<p class='ltx_p'>The applications in lines 15-17 demonstrate how empty arrays are dealt
with in the individual argument positions.
In particular from the example in line 17 it can be seen how well the
concept of having an unlimited number of different empty arrays available
fits nicely into the overall framework.</p>
<p class='ltx_p'>The remaining examples are rather straightforward.
The only aspect of interest here may be the “overflows” in the
rotation and shift parameters in lines 24 and 28, respectively.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 7. </h6>
<p class='ltx_p'>Which of the following expressions can be reformulated in terms
of take, ++, and the basic operations defined
in the previous parts?</p>
<ul id='Ch2.S2.I6' class='ltx_itemize'>
<li id='Ch2.S2.I6.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>drop (v, a)?</p>
</li>
<li id='Ch2.S2.I6.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>tile (v, o, a)?</p>
</li>
<li id='Ch2.S2.I6.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shift ([n], e, a)?</p>
</li>
<li id='Ch2.S2.I6.i4' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>shift ([m,n], e, a)?</p>
</li>
<li id='Ch2.S2.I6.i5' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>rotate ([n], a)?</p>
</li>
<li id='Ch2.S2.I6.i6' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>rotate ([m,n], a)?</p>
</li>
</ul>
<p class='ltx_p'>Can we define the general versions of shift and rotate
as well?</p>
</section>
<section id='Ch2.S2.SS1.SSSx4' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Reduction Operations</h6>
<p class='ltx_p'>The library of standard array operations that comes with the current SaC release also contains a set of functions
that fold all (scalar) elements of an array into a single one. The most common
ones of these are described here.</p>
<dl id='Ch2.S2.I7' class='ltx_description'>
<dt id='Ch2.S2.I7.ix1' class='ltx_item'>sum(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>sums up all elements of the array a. If a is
an empty array, is returned.
<br class='ltx_break'>Domain restrictions: the element type has to be numerical.</p>
</dd>
<dt id='Ch2.S2.I7.ix2' class='ltx_item'>prod(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>multiplies all elements of the array a. If a is
an empty array, 1 is returned.
<br class='ltx_break'>Domain restrictions: the element type has to be numerical.</p>
</dd>
<dt id='Ch2.S2.I7.ix3' class='ltx_item'>all(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>yields true, iff all elements of a are true.
If a is an empty array, true is returned.
<br class='ltx_break'>Domain restrictions: the element type has to be boolean.</p>
</dd>
<dt id='Ch2.S2.I7.ix4' class='ltx_item'>any(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>yields true, iff at least one element of a
is true. If a is an empty array, false is returned.
<br class='ltx_break'>Domain restrictions: the element type has to be boolean.</p>
</dd>
<dt id='Ch2.S2.I7.ix5' class='ltx_item'>maxval(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>computes the maximum value of a. If a is
an empty array, the minimal number of the according element type is
returned.
<br class='ltx_break'>Domain restrictions: the element type has to be numerical.</p>
</dd>
<dt id='Ch2.S2.I7.ix6' class='ltx_item'>minval(a)</dt>
<dd class='ltx_item'>
<p class='ltx_p'>computes the minimum value of a. If a is
an empty array, the maximal number of the according element type is
returned.
<br class='ltx_break'>Domain restrictions: the element type has to be numerical.</p>
</dd>
</dl>
<p class='ltx_p'>A few examples:</p>
<figure id='LST12' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 12: Reduction Operations</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKCiAgIHByaW50KHN1bShtYXQpKTsKICAgcHJpbnQocHJvZCh2ZWN0KSk7CiAgIHByaW50KGFsbChtYXQgPj0gMSkpOwogICBwcmludChhbnkobWF0ID4gMSkpOwogICBwcmludChtYXh2YWwobWF0KSk7CiAgIHByaW50KG1pbnZhbChtYXQpKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>vect</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+10,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+20];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>sum</span>(<span class='ltx_text ltx_lst_identifier'>mat</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'>prod</span>(<span class='ltx_text ltx_lst_identifier'>vect</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>all</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>1));
<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'>any</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>1));
<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'>maxval</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>));
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>minval</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_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_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;'>18</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Most of these examples, again, are fairly self explanatory.
However, you may get an idea of the specificational advantages
of shape-invariant programming when having a closer look
at lines 12 and 13. They demonstrate the rather intuitive
style of program specifications that results from it.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 8. </h6>
<p class='ltx_p'>All operations introduced in this part apply to all elements
of the array they are applied to. Given the array operations introduced
so far, can you specify row-wise or column-wise summations for matrices?
Try to specify these operations for a 2 by 3 matrix first.</p>
</section>
</section>
<section id='Ch2.S2.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
2.2.2 Axis Control Notation</h5>
<p class='ltx_p'>As can be seen from Exercise <a href='#Thmtheorem8' title='Exercise 8. ‣ Reduction Operations ‣ 2.2.1 Standard Array Operations ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>8</a>, without further
language support, it is rather difficult
to apply an array operation to certain axes of an array only.
This section introduces two language constructs of SaC which,
when taken together, can be used to that effect.
While <em class='ltx_emph ltx_font_italic'>Generalized Selections</em> are convenient for separating individual
axes of an array,
<em class='ltx_emph ltx_font_italic'>Set Notations</em> allow to recombine such axes into a result array
after applying arbitrary operations to them.
However, as the two constructs in principle are orthogonal,
we introduce them separately before showing how they can be combined
into an instrument for <em class='ltx_emph ltx_font_italic'>Axis Control</em>.</p>
<section id='Ch2.S2.SS2.SSSx1' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Generalized Selections</h6>
<p class='ltx_p'>The selection operation introduced in Section <a href='#Ch2.S2.SS1.SSSx1' title='Basic Operations ‣ 2.2.1 Standard Array Operations ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.2.1</a> does not
only allow scalar elements but entire subarrays of an array to be selected.
However, the selection of (non-scalar) subarrays always assumes the given
indices to refer to the leftmost axes, i.e. all elements with respect to the
rightmost axes are actually selected.
So far, a selection of arbitrary axes is not possible.
As an example use-case consider the selection of rows and columns of a matrix.
While the former can be done easily, the latter requires the array to be
transposed first.</p>
<p class='ltx_p'>To avoid clumsy notations, SaC provides special syntactical support for
selecting arbitrary subarrays called <em class='ltx_emph ltx_font_italic'>Generalized Selections</em>.
The basic idea is to indicate the axes whose elements are to be selected
entirely by using dot-symbols instead of numerical values within
the index vectors of a selection operation.</p>
<p class='ltx_p'>Note here, that vectors containing dot-symbols are not
first class citizens of the language, i.e. they can exclusively be specified within
selection operations directly!</p>
<p class='ltx_p'>There are two kinds of dot-symbols, single-dots which refer to a single axis
and triple-dots which refer to as many axes as they are left unspecified within
a selection.
In order to avoid ambiguities, a maximum of one triple-dot symbol per selection
expression is allowed.</p>
<p class='ltx_p'>A few examples:</p>
<figure id='LST13' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 13: Generalized Selections</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICAgcHJpbnQobWF0KTsKCiAgIHByaW50KG1hdFtbMV1dKTsKICAgcHJpbnQobWF0W1sxLC5dXSk7CiAgIHByaW50KG1hdFtbMSwuLi5dXSk7CgogICBwcmludChtYXRbWy4sMV1dKTsKICAgcHJpbnQobWF0W1suLi4sMV1dKTsKCiAgIHByaW50KG1hdFtbMSwuLi4sMV1dKTsKCiAgIGFycjNkID0gW21hdCwgbWF0XTsKICAgcHJpbnQoYXJyM2QpOwoKICAgcHJpbnQoYXJyM2RbWy4sMV1dKTsKICAgcHJpbnQoYXJyM2RbWy4uLiwxXV0pOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>vect</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+10,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+20];
<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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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'>mat</span>[[1]]);
<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>[[1,.]]);
<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>[[1,…]]);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[.,1]]);
<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>[[…,1]]);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></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>[[1,…,1]]);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></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'>arr3d</span><span class='ltx_text ltx_lst_space'> </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_identifier'>mat</span>];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</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'>arr3d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></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'>arr3d</span>[[.,1]]);
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>[[…,1]]);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></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_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;'>27</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>The examples in lines 11-13 demonstrate different versions for selecting
the second row of the matrix mat.
However, as the rightmost axis is to be selected, a dot-free version
(cf. line 11) suffices for this task.
The selection of the second column of mat is shown in lines 15 and 16.</p>
<p class='ltx_p'>line 18 demonstrates that the triple-dot notation can
also be successfully applied if no axis can be matched at all.</p>
<p class='ltx_p'>The difference between the single-dot and the
triple-dot notation is shown in lines 23 and 24.
While the selection in line 23 is identical to
arr3d.,1,., the one in line 24 is identical to arr3d.,.,1.</p>
<p class='ltx_p'>Only in cases where the number of single-dots plus the number of numerical indices
exceeds the number of axes available, an error message will be generated.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 9. </h6>
<p class='ltx_p'>How can a selection of all elements of mat be specified using
generalized selections? Try to find all 9 possible solutions!
</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 10. </h6>
<p class='ltx_p'>Referring to Exercise <a href='#Thmtheorem5' title='Exercise 5. ‣ Basic Operations ‣ 2.2.1 Standard Array Operations ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>5</a>, can this new notation
be used for selecting “over” empty axis?
For example, can you specify a selection vector <math id='Thmtheorem10.p1.m1' class='ltx_Math' alttext='{\langle\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_vec}}}}\rangle' display='inline'><mrow><mo stretchy='false'>⟨</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>vec</mtext><mo stretchy='false'>⟩</mo></mrow></math>, so that
reshape([3,0,5], [])[vec] == reshape ([3,0], [])
holds?</p>
</section>
<section id='Ch2.S2.SS2.SSSx2' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Set Notation</h6>
<p class='ltx_p'>The means for composing arrays that have been described so far are rather restricted.
Apart from element-wise definitions all other operations treat all elements
uniformly.
As a consequence, it is difficult to define arrays whose elements differ
depending on their position within the array.
The so-called <em class='ltx_emph ltx_font_italic'>set notation</em> facilitates such position dependent array
definitions.
Essentially, it consists of a mapping from index vectors to elements, taking
the general form</p>
<table id='Ch2.Ex1' class='ltx_equation ltx_eqn_table'>
<tr class='ltx_equation ltx_eqn_row ltx_align_baseline'>
<td class='ltx_eqn_cell ltx_eqn_center_padleft'></td>
<td class='ltx_eqn_cell ltx_align_center'><math id='Ch2.Ex1.m1' class='ltx_Math' alttext='langle_textrm_lstinline_lst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_index_textunderscore_vector}}}}\rangle\ %
\mathop{\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers-_textgreater}}}\ \langle\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_expression}}}}\rangle' display='block'><mrow><mrow><mo stretchy='false'>⟨</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>index_vector</mtext><mo rspace='7.5pt' stretchy='false'>⟩</mo></mrow><mo></mo><mrow><mpadded class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting' width='+5pt'><mtext>→</mtext></mpadded><mrow><mo stretchy='false'>⟨</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expression</mtext><mo stretchy='false'>⟩</mo></mrow></mrow></mrow></math></td>
<td class='ltx_eqn_cell ltx_eqn_center_padright'></td>
</tr>
</table>
<p class='ltx_p'>where <math id='Ch2.S2.SS2.SSSx2.p1.m1' class='ltx_Math' alttext='{\langle\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_index_textunderscore_vector}}}}\rangle' display='inline'><mrow><mo stretchy='false'>⟨</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>index_vector</mtext><mo stretchy='false'>⟩</mo></mrow></math> either is a variable or a vector of variables
and <math id='Ch2.S2.SS2.SSSx2.p1.m2' class='ltx_Math' alttext='{\langle\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_expression}}}}\rangle' display='inline'><mrow><mo stretchy='false'>⟨</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expression</mtext><mo stretchy='false'>⟩</mo></mrow></math> is a SaC expression that refers to
the index vector or its components and defines the
individual array elements.
The range of indices this mapping operation is applied to usually can be determined
by the expression given and, thus, it is not specified explicitly.</p>
<p class='ltx_p'>
A note for language design freaks:
You may wonder why we restrict the expressiveness of the set notation
by relying on compiler driven range detection rather than an explicit
range specification.
The reason for this decision is the observation that in many situations
the capabilities of the set notation suffice whereas an explicit specification
of ranges would obfuscate the code.
Furthermore, as you will see in Chapter <a href='#Ch4' title='Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>4</a>, SaC provides a
more versatile language construct for defining arrays.
However, the expressiveness of that construct comes for quite some
specificational overhead.
</p>
<p class='ltx_p'>Let us have a look at some examples:</p>
<figure id='LST14' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 14: Basic Set Notation</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzAsMSwyLDMsNCw1LDYsNyw4LDldOwoKICAgbWF0ID0ge1tpXSAtPiB2ZWN0W1tpXV0qMTArdmVjdH07CiAgIHByaW50KG1hdCk7CgogICBtYXRfaW5jID0ge2l2IC0+IG1hdFtpdl0gKyAxfTsKICAgcHJpbnQobWF0X2luYyk7CgogICBtYXRfdHJhbnMgPSB7W2ksal0gLT4gbWF0W1tqLGldXX07CiAgIHByaW50KG1hdF90cmFucyk7CgogICBtYXRfZGlhZyA9IHtbaSxqXSAtPiB3aGVyZShpID09IGogLCBtYXRbW2ksal1dICwgMCl9OwogICBwcmludChtYXRfZGlhZyk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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>[0,1,2,3,4,5,6,7,8,9];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*10+<span class='ltx_text ltx_lst_identifier'>vect</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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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'>mat_inc</span><span class='ltx_text ltx_lst_space'> </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_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</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 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_inc</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_identifier'>mat_trans</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[<span class='ltx_text ltx_lst_identifier'>j</span>,<span class='ltx_text ltx_lst_identifier'>i</span>]]};
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat_trans</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</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><span class='ltx_text ltx_lst_identifier'>mat_diag</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>where</span>(<span class='ltx_text ltx_lst_identifier'>i</span><span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>j</span><span class='ltx_text ltx_lst_space'> </span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]]<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;'>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_diag</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></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_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;'>21</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>The set notation in line 8 defines a vector whose components
at position [i] are vectors that are computed from adding
a multiple of 10 to the vector vect.
The legal range of i is derived from the selection
vect<span class='ltx_text ltx_lst_identifier'>i</span> yielding in fact a matrix with shape [10,10].
An explicit element-wise increment operation is specified in line 11.
Since the operation does not need to refer to individual axes a
variable iv is used for the entire index vector rather than
having variables for individual index components.
Line 14 shows how the matrix can be transposed, and line 17
changes all non-diagonal elements to .</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 11. </h6>
<p class='ltx_p'>Which of these operations can be expressed in terms of the array operations
defined so far?</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 12. </h6>
<p class='ltx_p'>What results do you expect if mat is an empty matrix, e.g. reshape([10,0], [])?</p>
<p class='ltx_p'>As we can see from the set notation in line 8, non-scalar expressions
within the set notation per default constitute the inner axes of the
result array.
This can be changed by using ‘.’ symbols for indicating those
axes that should constitute the result axis.</p>
<p class='ltx_p'>A few examples:</p>
<figure id='LST15' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 15: Advanced Set Notation</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzAsMSwyLDNdOwoKICAgbWF0ID0ge1suLGldIC0+IHZlY3RbW2ldXSo0ICsgdmVjdH07CiAgIHByaW50KG1hdCk7CgogICBhcnIzZCA9IHtbaV0gLT4gdmVjdFtbaV1dKjE2ICsgbWF0fTsKICAgcHJpbnQoYXJyM2QpOwoKICAgYXJyM2QgPSB7Wy4sLixpXSAtPiB2ZWN0W1tpXV0qMTYgKyBtYXR9OwogICBwcmludChhcnIzZCk7CgogICBhcnIzZCA9IHtbLixpXSAtPiB2ZWN0W1tpXV0qMTYgKyBtYXR9OwogICBwcmludChhcnIzZCk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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>[0,1,2,3];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*4<span class='ltx_text ltx_lst_space'> </span>+<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;'>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;'>10</span></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'>arr3d</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*16<span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_identifier'>arr3d</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[.,.,<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*16<span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>};
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</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><span class='ltx_text ltx_lst_identifier'>arr3d</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[.,<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*16<span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </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'>arr3d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></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_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;'>21</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>These examples show how the result of evaluating the expression on the right of the arrow can be directed into any axes of the overall result array.
As can be seen in line 17, the axes of the expressions can even be put into
non-adjacent axes of the result.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 13. </h6>
<p class='ltx_p'>The ‘.’ symbol in the set notation allows us to direct a computation
to any axes of the result. This is identical to first putting the result
into the innermost axes and then transposing the result.
Can you come up with a general scheme that translates set notations
containing ‘.’ symbols into set notations that do without?</p>
</section>
<section id='Ch2.S2.SS2.SSSx3' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Axis Control</h6>
<p class='ltx_p'>Although generalized selections and the set notation per se can be useful,
their real potential shows when they are used in combination.
Together, they constitute means to control the axes a given operation
is applied to.
The basic idea is to use generalized selections to extract the axes of interest,
apply the desired operation to the extracted subarrays and then recombine
the results to the overall array.</p>
<p class='ltx_p'>For example, we can now easily sum up the individual rows or columns
of a matrix:</p>
<figure id='LST16' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 16: Axis Control: sum</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzAsMSwyLDMsNCw1LDYsNyw4LDldOwoKICAgbWF0ID0ge1suLGldIC0+IHZlY3RbW2ldXSoxMCt2ZWN0fTsKICAgcHJpbnQobWF0KTsKCiAgIHN1bV9yb3dzID0ge1tpXSAtPiBzdW0obWF0W1tpXV0pfTsKICAgcHJpbnQoc3VtX3Jvd3MpOwoKICAgc3VtX2NvbHMgPSB7W2ldIC0+IHN1bSggbWF0W1suLGldXSl9OwogICBwcmludChzdW1fY29scyk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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>[0,1,2,3,4,5,6,7,8,9];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*10+<span class='ltx_text ltx_lst_identifier'>vect</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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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'>sum_rows</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sum</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[<span class='ltx_text ltx_lst_identifier'>i</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>sum_rows</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_identifier'>sum_cols</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sum</span>(<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[.,<span class='ltx_text ltx_lst_identifier'>i</span>]])};
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>sum_cols</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</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><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;'>18</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Reduction operations, in general, are prone to axis control, as they
often need to be applied to certain
particular axes rather than entire arrays.
Other popular examples are the maximum (maxval) and
minimum (minval) operations:</p>
<figure id='LST17' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 17: Axis Control: max</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzAsMSwyLDNdOwoKICAgYXJyM2QgPSB7W2ksal0gLT4gdmVjdFtbaV1dKjQgKyB2ZWN0W1tqXV0qMTYgKyB2ZWN0fTsKICAgcHJpbnQoYXJyM2QpOwoKICAgbWF4X2lubmVyX3ZlY3RzID0ge1tpLGpdIC0+IG1heHZhbChhcnIzZFtbaSxqXV0pfTsKICAgcHJpbnQobWF4X2lubmVyX3ZlY3RzKTsKCiAgIG1heF9pbm5lcl9hcnJheXMgPSB7W2ldIC0+IG1heHZhbChhcnIzZFtbaV1dKX07CiAgIHByaW50KG1heF9pbm5lcl9hcnJheXMpOwoKICAgbWF4X291dGVyX2FycmF5cyA9IHtbaV0gLT4gbWF4dmFsKGFycjNkW1suLC4saV1dKX07CiAgIHByaW50KG1heF9vdXRlcl9hcnJheXMpOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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>[0,1,2,3];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><span class='ltx_text ltx_lst_identifier'>arr3d</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*4<span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>j</span>]]*16<span class='ltx_text ltx_lst_space'> </span>+<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;'>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'>arr3d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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'>max_inner_vects</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>maxval</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>max_inner_vects</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_identifier'>max_inner_arrays</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>maxval</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]])};
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>max_inner_arrays</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</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><span class='ltx_text ltx_lst_identifier'>max_outer_arrays</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>maxval</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>[[.,.,<span class='ltx_text ltx_lst_identifier'>i</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'>max_outer_arrays</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></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_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;'>21</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>In line 8, we directly generate a 3 dimensional array from the vector vect.
Lines 11, 14, and 17 compute maxima within different slices of that array.
max_inner_vects is a matrix containing the maxima within the innermost vectors,
i.e. the 3-dimensional array is considered a matrix of vectors whose maximum
values are computed.
For max_inner_arrays, the array is considered a vector of matrices; it contains
the maximum values of these subarrays.
The last example demonstrates, that outer dimensions can be considered for
reduction as well.</p>
<p class='ltx_p'>Further demand for axis control arises in the context of array operations
that are dedicated to one fixed axis (usually the outermost one) and that need
to be applied to another one.
Examples for this situation are the concatenation operation (++)
and reverse:</p>
<figure id='LST18' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 18: Axis Control: ++, reverse</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB2ZWN0ID0gWzAsMSwyLDNdOwoKICAgYXJyM2QgPSB7W2ksal0gLT4gdmVjdFtbaV1dKjQgKyB2ZWN0W1tqXV0qMTYgKyB2ZWN0fTsKICAgcHJpbnQoYXJyM2QpOwoKICAgcHJpbnQoYXJyM2QgKysgYXJyM2QpOwogICBwcmludCh7W2ldIC0+IGFycjNkW1tpXV0gKysgYXJyM2RbW2ldXX0pOwogICBwcmludCh7W2ksal0gLT4gYXJyM2RbW2ksal1dICsrIGFycjNkW1tpLGpdXX0pOwoKICAgcHJpbnQocmV2ZXJzZSggYXJyM2QpKTsKICAgcHJpbnQoeyBbaV0gLT4gcmV2ZXJzZShhcnIzZFtbaV1dKX0pOwogICBwcmludCh7IFtpLGpdIC0+IHJldmVyc2UoYXJyM2RbW2ksal1dKX0pOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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>[0,1,2,3];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><span class='ltx_text ltx_lst_identifier'>arr3d</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]*4<span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>j</span>]]*16<span class='ltx_text ltx_lst_space'> </span>+<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;'>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'>arr3d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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'>arr3d</span><span class='ltx_text ltx_lst_space'> </span>++<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>arr3d</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><span class='ltx_text ltx_lst_identifier'>print</span>({[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]<span class='ltx_text ltx_lst_space'> </span>++<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</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'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]]<span class='ltx_text ltx_lst_space'> </span>++<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]]});
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>
<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'>print</span>(<span class='ltx_text ltx_lst_identifier'>reverse</span>(<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>arr3d</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_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reverse</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</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><span class='ltx_text ltx_lst_identifier'>print</span>({<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reverse</span>(<span class='ltx_text ltx_lst_identifier'>arr3d</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]])});
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span>
<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_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;'>20</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Line 11 shows a standard application of the concatenation of two arrays.
It affects the outermost axis only, resulting in an array of shape
[8, 4, 4].
The two subsequent lines show, how to apply concatenation to other axis.
Essentially, the selections on the right hand sides select the sub expressions to
be concatenated and the surrounding set notation glues the concatenated
subarrays back together again.</p>
<p class='ltx_p'>The examples in lines 15-17 show the same exercise for the operation
reverse which reverses the order of the elements within an array
with respect to the outermost axis.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 14. </h6>
<p class='ltx_p'>The operation take is defined in a way that ensures inner axes
to be taken completely in case the take vector does not provide enough
entities for all axes.
How can take be applied to an array so that the outermost axis
remains untouched and the selections are applied to inner axes, starting at the
second one? (You may assume, that the take vector has fewer elements
than the array axes!)
Can you specify a term that — according to a take vector of length 1 —
takes from the innermost axis only?</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 15. </h6>
<p class='ltx_p'>Can you merge two vectors of identical length element-wise?
Extend your solution in a way that permits merging <math id='Thmtheorem15.p1.m1' class='ltx_Math' alttext='n' display='inline'><mi>n</mi></math>-dimensional
arrays on the outermost axis.</p>
</section>
</section>
<section id='Ch2.S2.SS3' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
2.2.3 Putting it all Together</h5>
<p class='ltx_p'>The array operations presented so far constitute a substantial
subset of the functionality that is provided by array programming
languages such as APL.
When orchestrated properly, these suffice to express rather complex
array operations very concisely.
In the sequel, we present two examples that make use of this combined expressive
power: matrix product and relaxation.</p>
<section id='Ch2.S2.SS3.SSSx1' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Matrix Product</h6>
<p class='ltx_p'>The matrix product of two matrices <math id='Ch2.S2.SS3.SSSx1.p1.m1' class='ltx_Math' alttext='A' display='inline'><mi>A</mi></math> and <math id='Ch2.S2.SS3.SSSx1.p1.m2' class='ltx_Math' alttext='B' display='inline'><mi>B</mi></math> (denoted by <math id='Ch2.S2.SS3.SSSx1.p1.m3' class='ltx_Math' alttext='A\odot B' display='inline'><mrow><mi>A</mi><mo>⊙</mo><mi>B</mi></mrow></math>) is defined
as follows:</p>
<p class='ltx_p'>Provided <math id='Ch2.S2.SS3.SSSx1.p2.m1' class='ltx_Math' alttext='A' display='inline'><mi>A</mi></math> has as many columns as <math id='Ch2.S2.SS3.SSSx1.p2.m2' class='ltx_Math' alttext='B' display='inline'><mi>B</mi></math> has rows, the result of <math id='Ch2.S2.SS3.SSSx1.p2.m3' class='ltx_Math' alttext='A\odot B' display='inline'><mrow><mi>A</mi><mo>⊙</mo><mi>B</mi></mrow></math>
has as many rows as <math id='Ch2.S2.SS3.SSSx1.p2.m4' class='ltx_Math' alttext='A' display='inline'><mi>A</mi></math> and as many columns as <math id='Ch2.S2.SS3.SSSx1.p2.m5' class='ltx_Math' alttext='B' display='inline'><mi>B</mi></math>. Each element
<math id='Ch2.S2.SS3.SSSx1.p2.m6' class='ltx_Math' alttext='{(A\odot B)}_{i,j}' display='inline'><msub><mrow><mo stretchy='false'>(</mo><mrow><mi>A</mi><mo>⊙</mo><mi>B</mi></mrow><mo stretchy='false'>)</mo></mrow><mrow><mi>i</mi><mo>,</mo><mi>j</mi></mrow></msub></math> is defined as the scalar product of the <math id='Ch2.S2.SS3.SSSx1.p2.m7' class='ltx_Math' alttext='i' display='inline'><mi>i</mi></math>-th row of <math id='Ch2.S2.SS3.SSSx1.p2.m8' class='ltx_Math' alttext='A' display='inline'><mi>A</mi></math>
and the <math id='Ch2.S2.SS3.SSSx1.p2.m9' class='ltx_Math' alttext='j' display='inline'><mi>j</mi></math>-th column of <math id='Ch2.S2.SS3.SSSx1.p2.m10' class='ltx_Math' alttext='B' display='inline'><mi>B</mi></math>, i.e. we have
<math id='Ch2.S2.SS3.SSSx1.p2.m11' class='ltx_Math' alttext='{(A\odot B)}_{i,j}=\sum_{k}A_{i,k}*B_{k,j}' display='inline'><mrow><msub><mrow><mo stretchy='false'>(</mo><mrow><mi>A</mi><mo>⊙</mo><mi>B</mi></mrow><mo stretchy='false'>)</mo></mrow><mrow><mi>i</mi><mo>,</mo><mi>j</mi></mrow></msub><mo>=</mo><mrow><msub><mo largeop='true' symmetric='true'>∑</mo><mi>k</mi></msub><mrow><msub><mi>A</mi><mrow><mi>i</mi><mo>,</mo><mi>k</mi></mrow></msub><mo>*</mo><msub><mi>B</mi><mrow><mi>k</mi><mo>,</mo><mi>j</mi></mrow></msub></mrow></mrow></mrow></math>.</p>
<p class='ltx_p'>This definition can directly be translated into the following SaC code:</p>
<figure id='LST19' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 19: Matrix Product</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBpZCA9IFtbMWQsIDBkLCAwZF0sIFswZCwgMWQsIDBkXSwgWzBkLCAwZCwgMWRdXTsKCiAgIHZlY3QgPSBbMWQsIDJkLCAzZCwgNGRdOwogICBtYXQgPSBbdmVjdCwgdmVjdCs0ZCwgdmVjdCs4ZF07CiAgIHByaW50KG1hdCk7CgogICByZXMgPSB7W2ksal0gLT4gc3VtKGlkW1tpLC5dXSAqIG1hdFtbLixqXV0pfTsKICAgcHJpbnQocmVzKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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'>id</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[[1<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>0<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>0<span class='ltx_text ltx_lst_identifier'>d</span>],<span class='ltx_text ltx_lst_space'> </span>[0<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>0<span class='ltx_text ltx_lst_identifier'>d</span>],<span class='ltx_text ltx_lst_space'> </span>[0<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>0<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_identifier'>d</span>]];
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>2<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>3<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>4<span class='ltx_text ltx_lst_identifier'>d</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'>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'>vect</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+4<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+8<span class='ltx_text ltx_lst_identifier'>d</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'>mat</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</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><span class='ltx_text ltx_lst_identifier'>res</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>{[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sum</span>(<span class='ltx_text ltx_lst_identifier'>id</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>,.]]<span class='ltx_text ltx_lst_space'> </span>*<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[.,<span class='ltx_text ltx_lst_identifier'>j</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'>res</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>
<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_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>}
</figure>
<p class='ltx_p'>After defining two matrices id and mat in
lines 6 and 8, respectively,
the matrix product id <math id='Ch2.S2.SS3.SSSx1.p4.m1' class='ltx_Math' alttext='\odot' display='inline'><mo>⊙</mo></math> mat is specified in line 12.
id<span class='ltx_text ltx_lst_identifier'>i</span>,. selects the i-th row of id and
mat.,<span class='ltx_text ltx_lst_identifier'>j</span> refers to the j-th column of mat.
The index ranges for i and j are deduced from the accesses
into id and mat, respectively.
A variable <math id='Ch2.S2.SS3.SSSx1.p4.m2' class='ltx_Math' alttext='k' display='inline'><mi>k</mi></math> as used in the mathematical specification is not required
as we can make use of the array operations * and sum.</p>
</section>
<section id='Ch2.S2.SS3.SSSx2' class='ltx_subsubsection'>
<h6 class='ltx_title ltx_title_subsubsection'>Relaxation</h6>
<p class='ltx_p'>Numerical approximations to the solution of partial differential equations
are often made by applying so-called relaxation methods.
These require large arrays to be iteratively modified by so-called
stencil operations until a certain convergence criterion is met.
Fig. <a href='#Ch2.F1' title='Figure 2.1 ‣ Relaxation ‣ 2.2.3 Putting it all Together ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1</a> illustrates such a stencil operation.</p>
<figure id='Ch2.F1' class='ltx_figure'><img src='data:image/png;base64,b'iVBORw0KGgoAAAANSUhEUgAAANEAAACCEAYAAACIsPH1AAAJJmlDQ1BpY2MAAEiJlZVnUJNZF8fv8zzphUASQodQQ5EqJYCUEFoo0quoQOidUEVsiLgCK4qINEWQRQEXXJUia0UUC4uCAhZ0gywCyrpxFVFBWXDfGZ33HT+8/5l7z2/+c+bec8/5cAEgiINlwct7YlK6wNvJjhkYFMwE3yiMn5bC8fR0A9/VuxEArcR7ut/P+a4IEZFp/OW4uLxy+SmCdACg7GXWzEpPWeGjy0wPjCZ1dYsFzgMt9Y4eh/eexLzr8s+pLj681dfhUKABwp+hsO/4b/c++KVDiC9NioyGymT3JUelaYIJKZttIJHpfL9BQkR8UmRH5T8P+V/B2lR2anr0RucsomQWx0TDrzfw41MjA0BF9n8cbrS48hRv9/z2dFX73kegDYcwAg+7564ZUAdO4CQPrRV09tua+UfAA67vAzBJn/eqiVDQ0IgALoQAYoAlWgCXSBETADlsAWOAAX4AF8QRDYAPggBiQCAcgCuWAHKABFYB84CKpALWgATaAVnAad4Dy4Aq6D2+AuGAaPgRBMgpdABN6BBQiCsBAZokEykBKkDulARhAbsoYcIDfIGwqCQqFoKAnKgHKhnVARVApVQXVQE/QLdA66At2EBqGH0Dg0A/0NfYQRmATTYQVYA9aH2TAHdoV94fVwNJwK58D58F64Aq6HT8Id8BX4NjwMC+GX8BwCECLCQJQRXYSNcBEPJBiJQgTIVqQQKUfqkVakG+lD7iFCZBb5g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g3ZEZd2EX/B/IeuzDoPjkaktVSTftCuB/wsppVSMvdijCywZAUOPwG2JG3ossnJb3kGLGQ8gFuh6SoFdemh0S/hjDzQC29kIexvDPtT1eeoJe15yP7bC/9MV2a1XbNL2vOwWj/hqLdeoIAiC8Ayd0WJyHqLtfrpfMfZ/Ju8RCYIgZAu2ouXbrK1G4WAwPvxu7P9MKrQKgiBkC6KQlV7BWJ8DZtNFHTPM9l2Ws4ZJXBAEQRBehT3GlnoaOPNBE9Qfyt1PfCwIgiC8AR3RInI1UHbs3iXFp4IgCMJbYIH3jPpjdiRlcJabOWYTdncTnwqCIAgZoAbeIyu/LGO/r4Lp/T4XxJeCIAhCRkDdoP7IvWiz8Q1/h/fJPhoiLhQEQRAMgB3e/xmKTB6KxavXL9mItf4p8Z0gCIJgQPKvYR3YhtWyWtrvHZE5Y9BPWcViSfEjCILwTuKInIjtMasuaTWrOZKaroEmbTe1pf8H2lKNOJ76hsQAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjItMDMtMTRUMTY6NTI6MDIrMDA6MDAN2v3iAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIyLTAzLTE0VDE2OjUyOjAyKzAwOjAwfIdFXgAAAC10RVh0aWNjOmNvcHlyaWdodABDb3B5cmlnaHQgQXJ0aWZleCBTb2Z0d2FyZSAyMDExCLrFtAAAADF0RVh0aWNjOmRlc2NyaXB0aW9uAEFydGlmZXggU29mdHdhcmUgc1JHQiBJQ0MgUHJvZmlsZRMMAYYAAAAgdEVYdHBkZjpIaVJlc0JvdW5kaW5nQm94ADY2N3g0MTUrMCswWE1ngQAAABN0RVh0cGRmOlZlcnNpb24AUERGLTEuM7pVQAAAAASUVORK5CYII=
id='Ch2.F1.g1' class='ltx_graphics ltx_centering' width='209' height='130' alt='A 5-point-stencil relaxation with cyclic boundaries'>
<figcaption class='ltx_caption ltx_centering'>Figure 2.1: A 5-point-stencil relaxation with cyclic boundaries</figcaption>
</figure>
<p class='ltx_p'>A stencil operation re-computes all elements of an array by computing a weighted
sum of all neighbor elements.
The weights that are used solely depend on the positions relative to the element
to be computed rather than the position in the result array.
Therefore, we can conveniently specify these weights by a single matrix of weights
as shown on the left side of Fig. <a href='#Ch2.F1' title='Figure 2.1 ‣ Relaxation ‣ 2.2.3 Putting it all Together ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1</a>.</p>
<p class='ltx_p'>In this example, only 4 direct neighbor elements and the old value itself
are taken into account for computing a new value.
(Hence its name: 5-point-stencil operation).
As can be seen from the weights, a new value is computed from old ones by adding
an eight-th each of the values of the upper, lower, left, and right neighbors
to half of the old value.</p>
<p class='ltx_p'>As demonstrated on the right side of Fig. <a href='#Ch2.F1' title='Figure 2.1 ‣ Relaxation ‣ 2.2.3 Putting it all Together ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1</a> our example assumes
so-called cyclic boundary conditions.
This means that the missing neighbor elements at the boundaries of the matrix
are taken from the opposite sides as indicated by the elliptic curves.
</p>
<p class='ltx_p'>In the sequel, we concentrate on the specification of a single relaxation
step, i.e. on one re-computation of the entire array.
This can be specified as a single line of SaC code:</p>
<figure id='LST20' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 20: Relaxation with Cyclic Boundaries</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICB3ZWlnaHRzID0gW1swZCwgMWQsIDBkXSwgWzFkLCA0ZCwgMWRdLCBbIDBkLCAxZCwgMGRdXSAvIDhkOwoKICAgdmVjdCA9IFsxZCwgMmQsIDNkLCA0ZF07CiAgIG1hdCA9IFt2ZWN0LCB2ZWN0KzRkLCB2ZWN0KzhkLCB2ZWN0KzEyZF07CiAgIHByaW50KG1hdCk7CgogICBtYXQgPSB7W2ksal0gLT4gc3VtKHsgaXYgLT4gd2VpZ2h0c1tpdl0gKiByb3RhdGUoaXYtMSwgbWF0KX1bWy4uLixpLGpdXSl9OwogICBwcmludChtYXQpOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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'>weights</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[[0<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>0<span class='ltx_text ltx_lst_identifier'>d</span>],<span class='ltx_text ltx_lst_space'> </span>[1<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>4<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_identifier'>d</span>],<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_space'> </span>0<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>0<span class='ltx_text ltx_lst_identifier'>d</span>]]<span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_space'> </span>8<span class='ltx_text ltx_lst_identifier'>d</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>2<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>3<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span>4<span class='ltx_text ltx_lst_identifier'>d</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'>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'>vect</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+4<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+8<span class='ltx_text ltx_lst_identifier'>d</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>+12<span class='ltx_text ltx_lst_identifier'>d</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'>mat</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</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><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'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span>-><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sum</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_space'> </span><span class='ltx_text ltx_lst_identifier'>weights</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><span class='ltx_text ltx_lst_identifier'>rotate</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>-1,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>)}[[…,<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</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>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>
<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_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>}
</figure>
<p class='ltx_p'>Line 6 defines the array of weights as given on the left side of Fig. <a href='#Ch2.F1' title='Figure 2.1 ‣ Relaxation ‣ 2.2.3 Putting it all Together ‣ 2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1</a>.
Our example array is initialized in lines 8–9.
The relaxation step is specified in line 12.
At its core, all elements are re-computed by operations on the entire array
rather than individual elements.
This is achieved by applying rotate for each legal index position iv
into the array of weights weights.
Since the expression {iv → weights[iv] * rotate(iv-1, mat)}
computes a 3 by 3 array of matrices; the reduction operation sum
needs to be directed towards the outer two axes of that expression only.
This is achieved through axis control using a selection index [\dots,i,j]
within a set notation over i and j.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 16. </h6>
<p class='ltx_p'>Another variant of relaxation problems requires the boundary elements to have
a fixed value.
Can you modify the above solution in a way that causes all boundary elements
to be 0? [Hint: You may consider the boundary elements to actually be
located outside the matrix]</p>
</section>
</section>
</section>
</section>
<section id='Ch3' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 3 Basic Program Structure</h3>
<p class='ltx_p'>This trail gives a brief introduction into the main language
constructs most of which have been adopted from standard C.
We assume some familiarity with standard C and, therefore,
only give a quick overview and highlight the differences
between SaC and C.</p>
<section id='Ch3.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
3.1 Lesson 3: Functions and their Types</h4>
<section id='Ch3.S1.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.1.1 Function Definitions</h5>
<p class='ltx_p'>Like in other modern programming languages functions
constitute the main form of structuring programs in SaC.
SaC functions very much resemble their C counterparts.
The most prominent difference is that SaC functions can have
multiple return values, as illustrated in the following example.</p>
<figure id='LST21' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 21: Function definitions</figcaption>
<a href='data:text/plain;base64,IHVzZSBTY2FsYXJBcml0aDogYWxsOwoKIGludCwgaW50IGRpdm1vZChpbnQgeCwgaW50IHkpCiB7CiAgIHJldHVybiAoeCAvIHksIHggJSB5KTsKIH0KCiBpbnQgbWFpbigpCiB7CiAgIGQsIG0gPSBkaXZtb2QoOCwgMyk7CiAgIHJldHVybiBkOwogfQ=='>⬇</a>
<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'>ScalarArith</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>divmod</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'>x</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'>y</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</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>(<span class='ltx_text ltx_lst_identifier'>x</span><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</span><span class='ltx_text ltx_lst_space'> </span>%<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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;'>9</span></span>
<span class='ltx_text ltx_lst_space'> </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'>d</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>m</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>divmod</span>(8,<span class='ltx_text ltx_lst_space'> </span>3);
<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><span class='ltx_text ltx_lst_identifier'>d</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>}
</figure>
<p class='ltx_p'>A function with multiple return values, like divmod
in the above example, has a comma-separated list of return
types in front of the function name and the
return-statement likewise contains a comma-separated list
of expressions.
Obviously both lists must coincide in length to make up a
well-formed program.
Functions with multiple return values cannot appear in expression
positions in SaC, but their results need to be directly assigned to
identifiers as illustrated above.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 17. </h6>
<p class='ltx_p'>Extend the above example program to compute the greatest common
denominator of two numbers using Euclid’s algorithm.
In particular, use the function divmod.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 18. </h6>
<p class='ltx_p'>What happens, if you use the same variable name for both results
of divmod?</p>
</section>
<section id='Ch3.S1.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.1.2 Built-in Types</h5>
<p class='ltx_p'>SaC supports all basic types of standard C such as
int, float, double, char etc.</p>
<p class='ltx_p'>
A note for bit freaks:
All basic types are mapped one-to-one to their C counterparts
and, hence, the same rules apply to them in SaC as in C.
As a consequence of this, the concrete bit widths used for representation
and, hence, the range of values for integer types are
platform-dependent. Although this may be considered undesirable
we find it acceptable from a compatibility-with-C perspective.
</p>
<p class='ltx_p'>In addition to the C-inhereted types, SaC supports three more basic types:
the boolean type bool and the integer type byte, both
signed and unsigned.
Although these are internally mapped to the same C type, on the level
of SaC, there is a strict separation between them.
Neither can be used in places where the other is expected.
This separation also applies to the standard C types which rules out
tacit coercions as one would find them in C or Java.</p>
<p class='ltx_p'>
A note for language design freaks:
The reader may wonder why we enforced this strict separation.
The reason is two-fold: First, it prevents from accidental coercions
and second, it makes type-inference more accessible for the user
in the absence of explicit type declarations.
Just imagine an overloading of a function foo for integer and
double arguments which would yield different results depending on the type
of argument.
If we had implicit coercions in place it would be completely
unclear how the result of foo(0) would be computed!
</p>
<p class='ltx_p'>As a consequence of this strict separation,
programmers need to apply some rigor when it comes to specifying
constant values.
They have to be attributed with the appropriate suffixes to indicate
the desired runtime representation.
Note here, that we adopted the suffixes and default rules from C.
Here a few examples:</p>
<figure id='LST22' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 22: Element-Type segregation</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogYm9vbCBmb28oZG91YmxlIHgpCiB7CiAgIHJldHVybiB0cnVlOwogfQoKIGJvb2wgYmFyKGZsb2F0IHgpCiB7CiAgIHJldHVybiBmYWxzZTsKIH0KCiBpbnQgbWFpbigpCiB7CiAgIC8qIFR5cGUgZXJyb3I6IGZvbyBpcyBub3QgZGVmaW5lZCBvbiBpbnQhICAqLwogICBhID0gZm9vKDApOwoKICAgLyogQ29ycmVjdCBjYWxsczogICovCiAgIGEgPSBmb28oMC4wKTsKICAgYSA9IGZvbygwZCk7CgogICAvKiBUeXBlIGVycm9yOiBiYXIgaXMgbm90IGRlZmluZWQgb24gZG91YmxlISAgKi8KICAgYSA9IGJhcigwLjApOwoKICAgLyogQ29ycmVjdCBjYWxsczogICAqLwogICBhID0gYmFyKDBmKTsKICAgYSA9IGJhcigwLjBmKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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'>bool</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>foo</span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</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>{
<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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>true</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>bool</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>bar</span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>float</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</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_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><span class='ltx_text ltx_lst_identifier'>false</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>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><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;'>15</span></span>
<span class='ltx_text ltx_lst_space'> </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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Type<span class='ltx_text ltx_lst_space'> </span>error:<span class='ltx_text ltx_lst_space'> </span>foo<span class='ltx_text ltx_lst_space'> </span>is<span class='ltx_text ltx_lst_space'> </span>not<span class='ltx_text ltx_lst_space'> </span>defined<span class='ltx_text ltx_lst_space'> </span>on<span class='ltx_text ltx_lst_space'> </span>int!<span class='ltx_text ltx_lst_space'> </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><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'>foo</span>(0);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span>
<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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Correct<span class='ltx_text ltx_lst_space'> </span>calls:<span class='ltx_text ltx_lst_space'> </span>*/</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'>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'>foo</span>(0.0);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</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'>foo</span>(0<span class='ltx_text ltx_lst_identifier'>d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Type<span class='ltx_text ltx_lst_space'> </span>error:<span class='ltx_text ltx_lst_space'> </span>bar<span class='ltx_text ltx_lst_space'> </span>is<span class='ltx_text ltx_lst_space'> </span>not<span class='ltx_text ltx_lst_space'> </span>defined<span class='ltx_text ltx_lst_space'> </span>on<span class='ltx_text ltx_lst_space'> </span>double!<span class='ltx_text ltx_lst_space'> </span>*/</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'>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'>bar</span>(0.0);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Correct<span class='ltx_text ltx_lst_space'> </span>calls:<span class='ltx_text ltx_lst_space'> </span>*/</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'>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'>bar</span>(0<span class='ltx_text ltx_lst_identifier'>f</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</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'>bar</span>(0.0<span class='ltx_text ltx_lst_identifier'>f</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</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><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;'>31</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 19. </h6>
<p class='ltx_p'>How can you modify the above program in a way that allows the programmer by
a simple define to switch the argument type of foo between float
and double and all the calls to foo accordingly?</p>
<p class='ltx_p'>[Hint: Use the C preprocessor to make the necessary modifications]</p>
</section>
<section id='Ch3.S1.SS3' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.1.3 Subtyping</h5>
<p class='ltx_p'>For each basic type there is an entire hierarchy of array types
that specify the shape of an array (remember that any expression
in SaC denotes an array) at different levels of accurateness.
Using type int as a running example, int
itself denotes an integer array with rank zero, the empty
vector [] as shape vector and a single element,
in other words the equivalent of a scalar value.
Then, there are (real) array types denoting arrays of rank
greater than zero, e.g. int[4] denotes a 4-element
vector while int[10,20] denotes a 10 by 20 element
matrix.</p>
<p class='ltx_p'>Whereas all these types specify exact shapes, SaC also features
types that solely denote the rank of some array, but leave the
concrete shape open, e.g. int[.] describes the type
of all integer vectors (of any length) and int[.,.]
is the type of all integer matrices.
In order to support rank-invariant programming,
SaC, furthermore, has types that not only abstract from concrete
shapes but even from concrete ranks.
These are int[*] which is the type of all integer arrays
of any rank and shape, including rank-zero arrays (usually referred
to as scalars) and int[+], the type of all “true” integer
arrays, i.e. arrays of rank greater than zero.</p>
<p class='ltx_p'>SaC defines a subtype relationship between array types in the obvious
way.
Figure <a href='#Ch3.F1' title='Figure 3.1 ‣ 3.1.3 Subtyping ‣ 3.1 Lesson 3: Functions and their Types ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>3.1</a> shows this relationship for arrays of
integer elements in a graphical form.</p>
<figure id='Ch3.F1' class='ltx_figure'>{tikzpicture}\node
<p class='ltx_p ltx_align_center'>(star) at (0,3) int[*];
\node(plus) at (1.5,2) int[+];
\node(akd1) at (1.5,1) int[.];
\node(akd2) at (5,1) int[.,.];
\node(akd3) at (9,1) int[.,.,.];
\node(akd4) at (10.1,1) <math id='Ch3.F1.m1' class='ltx_Math' alttext='\cdots' display='inline'><mi mathvariant='normal'>⋯</mi></math>;
\node(aks11) at (1.5,0) int[1];
\node(aks12) at (2.7,0) int[4];
\node(aks13) at (3.5,0) <math id='Ch3.F1.m2' class='ltx_Math' alttext='\cdots' display='inline'><mi mathvariant='normal'>⋯</mi></math>;
\node(aks21) at (5,0) int[7,2];
\node(aks22) at (6.5,0) int[2,9];
\node(aks23) at (7.4,0) <math id='Ch3.F1.m3' class='ltx_Math' alttext='\cdots' display='inline'><mi mathvariant='normal'>⋯</mi></math>;
\node(aks31) at (9,0) int[9,8,11];
\node(aks32) at (10.2,0) <math id='Ch3.F1.m4' class='ltx_Math' alttext='\cdots' display='inline'><mi mathvariant='normal'>⋯</mi></math>;
\node(aks00) at (0,0) int;
<a href='star)edge' title= class='ltx_ref ltx_path ltx_font_typewriter'>star)edge</a>aks00);
<a href='star)edge' title=
class='ltx_ref ltx_path ltx_font_typewriter'>star)edge</a>plus);
<a href='plus)edge' title= class='ltx_ref ltx_path ltx_font_typewriter'>plus)edge</a>akd1);
<a href='plus)edge' title=
class='ltx_ref ltx_path ltx_font_typewriter'>plus)edge</a>akd2);
<a href='plus)edge' title= class='ltx_ref ltx_path ltx_font_typewriter'>plus)edge</a>akd3);
<a href='akd1)edge' title=
class='ltx_ref ltx_path ltx_font_typewriter'>akd1)edge</a>aks11);
<a href='akd1)edge' title= class='ltx_ref ltx_path ltx_font_typewriter'>akd1)edge</a>aks12);
<a href='akd2)edge' title=
class='ltx_ref ltx_path ltx_font_typewriter'>akd2)edge</a>aks21);
<a href='akd2)edge' title= class='ltx_ref ltx_path ltx_font_typewriter'>akd2)edge</a>aks22);
<a href='akd3)edge' title=
class='ltx_ref ltx_path ltx_font_typewriter'>akd3)edge</a>aks31);
</p>
<figcaption class='ltx_caption ltx_centering'>Figure 3.1: The hierarchy of array types of integer elements.</figcaption>
</figure>
<p class='ltx_p'>Whenever two types are in subtype relationship they are connected by a line.
For example, int[+] is a subtype of int[*],
int[.] and int[.,.] are both subtypes of int[+]
and int[12] and int[42] are subtypes of int[.].
As we can see, the subtyping hierarchy of SaC has exactly four levels.</p>
</section>
<section id='Ch3.S1.SS4' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.1.4 Function Overloading</h5>
<p class='ltx_p'>The real power of subtyping unfolds when it is combined with function
overloading.
It allows programmers to specify
multiple functions of the same name, as long as
they differ in the types or their arguments.
Which definition is chosen for any given application of such a function
depends on the type of the actual arguments.
This combines a high degree of code reuse with the ability to
later add special definitions for a few special cases.</p>
<p class='ltx_p'>
A note for OO-freaks:
This can be seen as a more general form of inheritance. If you restrict
overloading to one argument only, say the first one, it equates
to inheritance in OO languages. However, the overloading of SaC is much more powerful.
Not only does it support inheritance on all arguments but it also
supports overloading across different types.
These features render several of the well-known OO programming pattern
such as the visitor pattern superfluous in SaC.
Instead, the desired overloading can be specified directly.
</p>
<p class='ltx_p'>Here, an example for element-type overloading:</p>
<figure id='LST23' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 23: Function overloading</figcaption>
<a href='data:text/plain;base64,IHVzZSBTY2FsYXJBcml0aDogYWxsOwogdXNlIFN0ZElPOiBhbGw7CgogaW50IHR3aWNlKGludCB4KQogewogICByZXR1cm4gMiAqIHg7CiB9CgogZG91YmxlIHR3aWNlKGRvdWJsZSB4KQogewogICByZXR1cm4gMi4wICogeDsKIH0KCiBpbnQgbWFpbigpCiB7CiAgIGEgPSB0d2ljZSg1KTsKICAgcHJpbnQoYSk7CgogICBiID0gdHdpY2UoNS45KTsKICAgcHJpbnQoYik7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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'>ScalarArith</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'>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;'>3</span></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'>twice</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'>x</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>{
<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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>2<span class='ltx_text ltx_lst_space'> </span>*<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>twice</span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</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_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>2.0<span class='ltx_text ltx_lst_space'> </span>*<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</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>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><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;'>15</span></span>
<span class='ltx_text ltx_lst_space'> </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'>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'>twice</span>(5);
<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'>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;'>18</span></span>
<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'>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'>twice</span>(5.9);
<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'>b</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></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_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;'>23</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>When utilising the overloading on our hierarchy of array types
we can even achieve a pattern matching like programming style as
demonstrated in the next example.
Here, we have three instances of the function quicksort,
one for vectors of any length, one for vectors of length one
and one for empty vectors.
The latter two boil down to the identity function.
As a result we can safely access the first element of the argument
vector v in the general instance because any argument vector
is guaranteed to have at least two elements.</p>
<figure id='LST24' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 24: Overloading as pattern matching.</figcaption>
<a href='data:text/plain;base64,IGludFsuXSBxdWlja3NvcnQoaW50Wy5dIHYpCiB7CiAgICBwaXZvdCA9IHZbWzFdXTsKICAgIC8qIC4uLiAgKi8KIH0KCiBpbnRbMV0gcXVpY2tzb3J0KGludFsxXSB2KQogewogICByZXR1cm4gdjsKIH0KCiBpbnRbMF0gcXVpY2tzb3J0KGludFswXSB2KQogewogICByZXR1cm4gdjsKIH0='>⬇</a>
<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'>int</span>[.]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>quicksort</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'>v</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>pivot</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>v</span>[[1]];
<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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </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>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></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_keyword ltx_font_bold'>int</span>[1]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>quicksort</span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[1]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>v</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_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><span class='ltx_text ltx_lst_identifier'>v</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[0]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>quicksort</span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[0]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>v</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_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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>v</span>;
<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>}
</figure>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 20. </h6>
<p class='ltx_p'>In a C program, functions like + can be applied to arbitrary
combinations of integer and double arguments.
Try to mimic that behaviour in SaC by defining a function cPlus
and by overloading it appropriately.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 21. </h6>
<p class='ltx_p'>In OO languages inheritance cannot always be statically resolved.
This leads to what is referred to as dynamic dispatch, i.e. the disambiguation
of function calls at runtime.
Is that required in SaC too?
If so, can you come up with an example program that demonstrates this?</p>
</section>
</section>
<section id='Ch3.S2' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
3.2 Lesson 4: Function Bodies</h4>
<section id='Ch3.S2.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.2.1 Variable Declarations</h5>
<p class='ltx_p'>Local variables within bodies of SaC functions are typically not
declared (in contrast to C), but the SaC compiler infers proper
types for local variables or yields an appropriate error message.
Nevertheless, it is syntactically legal to add explicit variable
declarations in SaC in exactly the same way as in C.</p>
<p class='ltx_p'>There is one difference to C, however: While C allows local
variable declarations at the beginning of each code block and
in the latest C99 standard instructions and declarations can
even be interleaved, SaC only supports variable declarations on
the level of function bodies, and they must precede any instruction.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 22. </h6>
<p class='ltx_p'>Rewrite your solution to computing the greatest common denominator
of two numbers from the previous exercise such that each subexpression
is assigned to an identifier, i.e. flatten any nested expression.
Then add explicit variable declarations for each local variable
used.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 23. </h6>
<p class='ltx_p'>The previous exercise only used scalar types, more precisely int.
What happens if you replace int in all variable declarations
by its supertype int[*]?</p>
</section>
<section id='Ch3.S2.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.2.2 Assignments</h5>
<p class='ltx_p'>As we have already seen in the previous trails, SaC allows for
C-style assignments to variables.
In contrast to C,
assignments cannot be placed within expression positions and
the comma-operator of C is not supported.
However, the combinations of operators and assignment are
the same in SaC as in C</p>
<figure id='LST25' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 25: Operator assignments in SaC</figcaption>
<a href='data:text/plain;base64,IHVzZSBBcnJheTogYWxsOwogdXNlIFN0ZElPOiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gNDI7CiAgIHByaW50KGEpOwogICBhKys7CiAgIHByaW50KGEpOwogICBhICs9IDU7CiAgIHByaW50KGEpOwogICBhIC09IGE7CiAgIHByaW50KGEpOwoKICAgdiA9IFsxLDIsMyw0LDVdOwogICBwcmludCh2KTsKICAgdiArPSAxOwogICBwcmludCh2KTsKICAgdlswXSA9IDA7CiAgIHByaW50KHYpOwoKICAgbSA9IFt2LHYsdl07CiAgIHByaW50KG0pOwogICBtKys7CiAgIHByaW50KG0pOwoKICAgcmV0dXJuIGE7CiB9'>⬇</a>
<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'>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'>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;'>3</span></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>()
<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>{
<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>42;
<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>);
<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'>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>);
<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>5;
<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>);
<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'>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'>a</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'>a</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span>
<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'>v</span><span class='ltx_text ltx_lst_space'> </span>=<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;'>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'>v</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><span class='ltx_text ltx_lst_identifier'>v</span><span class='ltx_text ltx_lst_space'> </span>+=<span class='ltx_text ltx_lst_space'> </span>1;
<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'>v</span>);
<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'>v</span>[0]<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;'>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'>v</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></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'>m</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>v</span>,<span class='ltx_text ltx_lst_identifier'>v</span>,<span class='ltx_text ltx_lst_identifier'>v</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'>m</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'>m</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'>m</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></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_keyword ltx_font_bold'>return</span><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;'>28</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Note that despite the term “Single Assignment” in the name of SaC,
the language actually supports repeated assignment of values to the
same variable as in the above example.
This seeming contradiction can be explained as follows: Each assignment
opens up a new scope of an identifier bound to some value.
Accordingly, the second assignmnent to a in the above example
opens up a new scope for a new identifier a that only
coincidentally carries the same name as the identifier introduced
in the code line before.
However, because these two variables do carry the same name, the
second assignment shadows the scope of the first assignment meaning
that no access to the first a is possible any more.</p>
<p class='ltx_p'>Another aspect to notice here is that these operator-assignment
combinations in SaC can be used on arbitrary types.
Line 17 is an example for this flexibility.
The variable v is of type int[5] and thus
+= works on vectors. The way this works is that
all these operator assignment cases are considered syntactic sugar
for assignements with function applications on the righ hand side.</p>
<p class='ltx_p'>This syntactic-sugar trick also enables very C-like notations when
denoting applications of the function modarray.
Line 19 shows an example.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 24. </h6>
<p class='ltx_p'>Starting from the code in Listing <a href='#LST25' title='Listing 25 ‣ 3.2.2 Assignments ‣ 3.2 Lesson 4: Function Bodies ‣ Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>25</a>, what happens when you
combine the above shortcut notations?
Try operator assignments such as v[0]++ or
m[0][0] = 42;.</p>
<p class='ltx_p'>Can you define a function f that makes the following
operator assignment legal SaC code: v[1], m[1] +=f();?</p>
</section>
<section id='Ch3.S2.SS3' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.2.3 Conditionals</h5>
<p class='ltx_p'>In SaC, we support three forms of conditionals:</p>
<ul id='Ch3.S2.I1' class='ltx_itemize'>
<li id='Ch3.S2.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>branching with consequence only (if-then),</p>
</li>
<li id='Ch3.S2.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>branching with consequence and alternative (if-then-else) and</p>
</li>
<li id='Ch3.S2.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>conditional expressions.</p>
</li>
</ul>
<p class='ltx_p'>All three forms use a syntax that is identical to that of C, as the
following listing illustrates.
Similarity with C extends to the use of curly brackets to build
blocks of multiple statements and their potential absence if the
condition covers a single statement only
</p>
<figure id='LST26' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 26: Conditionals in SaC</figcaption>
<a href='data:text/plain;base64,IHVzZSBTY2FsYXJBcml0aDogYWxsOwogdXNlIFN0ZElPOiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gNTsKICAgYiA9IDc7CiAgIHByaW50ZigiYT0lZCwgYj0lZFxuIiwgYSwgYik7CgogICBpZiAoYSA8IGIpIGEgPSBiOwogICBwcmludGYoImE9JWQsIGI9JWRcbiIsIGEsIGIpOwoKICAgaWYgKGEgPj0gYikgewogICAgIGEgPSBiOwogICB9IGVsc2UgewogICAgIGIgPSBhOwogICB9CiAgIHByaW50ZigiYT0lZCwgYj0lZFxuIiwgYSwgYik7CgogICBiID0gYSA8IGIgPyBhIDogYjsKICAgcHJpbnRmKCJhPSVkLCBiPSVkXG4iLCBhLCBiKTsKCiAgIHJldHVybiBiOwogfQ=='>⬇</a>
<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'>ScalarArith</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'>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;'>3</span></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>()
<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>{
<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>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'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>7;
<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'>printf</span>(<span class='ltx_text ltx_lst_string'>”a=%d,<span class='ltx_text ltx_lst_space'> </span>b=%d\n”</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_identifier'>b</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>if</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_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;'>11</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'>”a=%d,<span class='ltx_text ltx_lst_space'> </span>b=%d\n”</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_identifier'>b</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>if</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_text ltx_lst_space'> </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'>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;'>15</span></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'>else</span><span class='ltx_text ltx_lst_space'> </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'>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_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_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'>printf</span>(<span class='ltx_text ltx_lst_string'>”a=%d,<span class='ltx_text ltx_lst_space'> </span>b=%d\n”</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_identifier'>b</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></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'>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_space'> </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_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;'>21</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'>”a=%d,<span class='ltx_text ltx_lst_space'> </span>b=%d\n”</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_identifier'>b</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></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_keyword ltx_font_bold'>return</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;'>24</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>As in C all forms of conditionals can be nested in any way, and the
dangling else ambiguity is resolved as in C proper.</p>
<p class='ltx_p'>A small difference to standard C is that the predicate expression
of any conditional must be of type bool.
There is no implicit treatment of integer values as predicates.
Another subtle difference to C stems from the functional nature of
SaC: a variable defined only in one branch of a conditional, will
cause the SaC compiler to raise an error because the value may be
undefined.</p>
<p class='ltx_p'>The switch-statement of C is currently not supported by SaC.
This is not so much motivated by conceptual concerns, but rather by
pragmatic considerations like the ratio between expressiveness gained
and implementation effort caused.</p>
</section>
<section id='Ch3.S2.SS4' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.2.4 Loops</h5>
<p class='ltx_p'>SaC supports all three loop constructs of standard C: while,
do and for with the familiar syntax, as illustrated
by the following code fragment.
</p>
<figure id='LST27' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 27: Loops in SaC</figcaption>
<a href='data:text/plain;base64,IHVzZSBTY2FsYXJBcml0aDogYWxsOwogdXNlIFN0ZElPOiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gMTA7CgogICB3aGlsZSAoYSA+IDApIHsKICAgICBhID0gYSAtIDI7CiAgICAgcHJpbnQoYSk7CiAgIH0KCiAgIGRvIHsKICAgICBwcmludChhKTsKICAgICBhID0gYSArIDE7CiAgIH0gd2hpbGUgKGEgPCA3KTsKCiAgIGZvciAoaSA9IDEsIGogPSAyOyBpICsgaiA8IDQyIDsgaSsrLCBqKyspIHsKICAgICBhICo9IDI7CiAgICAgcHJpbnQoYSk7CiAgIH0KCiAgIHJldHVybiBhOwogfQ=='>⬇</a>
<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'>ScalarArith</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'>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;'>3</span></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>()
<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>{
<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>10;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>while</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>0)<span class='ltx_text ltx_lst_space'> </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'>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'>a</span><span class='ltx_text ltx_lst_space'> </span>-<span class='ltx_text ltx_lst_space'> </span>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'>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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>do</span><span class='ltx_text ltx_lst_space'> </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>);
<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'>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'>a</span><span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span>1;
<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_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>while</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>7);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></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_keyword ltx_font_bold'>for</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>i</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>1,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>j</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>2;<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>i</span><span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>j</span><span class='ltx_text ltx_lst_space'> </span><<span class='ltx_text ltx_lst_space'> </span>42<span class='ltx_text ltx_lst_space'> </span>;<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>i</span>++,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>j</span>++)<span class='ltx_text ltx_lst_space'> </span>{
<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'>a</span><span class='ltx_text ltx_lst_space'> </span>*=<span class='ltx_text ltx_lst_space'> </span>2;
<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'>a</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></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_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_keyword ltx_font_bold'>return</span><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;'>24</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>In analogy to conditionals, the loop predicate expression must be
of type bool.
Note that SaC does even support the comma operator in for-loops
(though not in general terms as pointed out before).</p>
<p class='ltx_p'>These C-style loop constructs can make code look very imperative.
Despite these syntactic similarities, always bear in mind that SaC loops
are (only) syntactic sugar for equivalent tail-end recursive functions.
While the functional semantics almost completely coincides with the
pragmatic expectations of a C programmer, some subtle issues may
arise concerning the definedness of variables.
For example, the SaC compiler would complain about the above example
saying that the variable b in the while-loop may be
used uninitialised if it is not defined before.
This is because the compiler assumes that the body of a while-loop
may not be executed at all.
Of course, you may know better, but the SaC compiler at the moment makes
no particular effort to prove this fact when it analyses the definedness
of variables.</p>
</section>
<section id='Ch3.S2.SS5' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.2.5 Explicit Control Flow Manipulation</h5>
<p class='ltx_p'>The control flow manipulation statements of C, i.e. goto,
break and continue, as well as labels are not
supported by SaC.
This is due to the fact that SaC is indeed a functional language
and as such there is actually no control flow, even though the
C-like syntax suggests one.</p>
</section>
</section>
<section id='Ch3.S3' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
3.3 Lesson 5: Advanced Topics</h4>
<section id='Ch3.S3.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.3.1 User-defined Types</h5>
<p class='ltx_p'>SaC allows programmers to define their own types using a syntax
that is identical to C.</p>
<figure id='LST28' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 28: User-defined types</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwoKIHR5cGVkZWYgaW50IG15aW50OwogdHlwZWRlZiBmbG9hdFsxMDAsMTAwXSByZWFsX21hdHJpeDsKIHR5cGVkZWYgZG91YmxlWzJdIGNvbXBsZXg7CgogaW50IG1haW4oKQogewogICBjb21wbGV4ICAgYzsKICAgZG91YmxlWzJdIGQ7CgogICBjID0gKGNvbXBsZXgpIFsxLjIsMi4zXTsKICAgZCA9IChkb3VibGVbMl0pIGM7CiAgIHByaW50KGQpOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>typedef</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'>myint</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_identifier'>typedef</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>float</span>[100,100]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>real_matrix</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><span class='ltx_text ltx_lst_identifier'>typedef</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span>[2]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>complex</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></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_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;'>8</span></span>
<span class='ltx_text ltx_lst_space'> </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'>complex</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>c</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_keyword ltx_font_bold'>double</span>[2]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>d</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</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><span class='ltx_text ltx_lst_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>complex</span>)<span class='ltx_text ltx_lst_space'> </span>[1.2,2.3];
<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'>d</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'>double</span>[2])<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>c</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'>d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></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_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;'>17</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Following the keyword typedef we have the defining type
followed by the defined type name.
Note that in contrast to C, defining type and defined type are
not considered synonyms.
Types like double[2] and complex are distinguished
properly and a function that expects a value of type double[2]
as an argument will not accept a value of type complex instead.</p>
<p class='ltx_p'>SaC requires explicit type casts to change the type of a value from the
defining type to the defined type or vice versa as in the following
example.</p>
<p class='ltx_p'>Note that for the time being any defining type in a type definition
must exactly specify some shape; the various less specific types are
not supported.
While this looks incomplete at first glance, it is noteworthy that
such type definitions would immediately lead to arrays of non-uniform
shape, e.g. a matrix whose rows have different length.
There is no doubt that this would be an extremely powerful extension
to the homogeneously shaped arrays that SaC supports today, but it
would likewise require a non-trivial extension of the code generator
and runtime system that we leave for future research.</p>
</section>
<section id='Ch3.S3.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
3.3.2 Type Conversions</h5>
<p class='ltx_p'>SaC uses C-like cast expressions to change the type of an
expression whenever the data representation remains unaffected,
i.e. between user-defined types and their defining types or
vice versa.
In contrast to C, SaC does not use cast expressions to actually
change data representations, e.g. when converting from an integer
type to a floating point type, between floating point types of
different precision or between integer types of different bit
width.
For all these purposes SaC uses dedicated conversion functions
to express the fact that such conversions actually require an
operation performed at runtime rather than just changing the
type interpretation of a value.</p>
<p class='ltx_p'>These conversion functions are named tobool and tochar
for converting into non-numerical values.
For all numerical types these functions are named “to” plus an
optional “u” for unsigned integer types followed by the
first letter of the type name (“ll” in the case of long long int).
The following example illustrates type conversions in SaC.</p>
<figure id='LST29' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 29: Type conversions</figcaption>
<a href='data:text/plain;base64,IHVzZSBTY2FsYXJBcml0aDogYWxsOwogdXNlIFN0ZElPOiBhbGw7CgogaW50IG1haW4oKQogewogICBkb3VibGUgeDsKICAgZmxvYXQgeTsKICAgaW50IHo7CgogICB4ID0gMi4zOwogICBwcmludCh4KTsKCiAgIHkgPSB0b2YoeCk7CiAgIHByaW50KHkpOwoKICAgeiA9IHRvaSh5KTsKICAgcHJpbnQoeik7CgogICByZXR1cm4gejsKIH0='>⬇</a>
<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'>ScalarArith</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'>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;'>3</span></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>()
<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>{
<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_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</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_keyword ltx_font_bold'>float</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>z</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</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><span class='ltx_text ltx_lst_identifier'>x</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>2.3;
<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'>x</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</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><span class='ltx_text ltx_lst_identifier'>y</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>tof</span>(<span class='ltx_text ltx_lst_identifier'>x</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'>y</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></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'>z</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>toi</span>(<span class='ltx_text ltx_lst_identifier'>y</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><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>z</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span>
<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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>z</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>}
</figure>
</section>
</section>
</section>
<section id='Ch4' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 4 With-Loops</h3>
<p class='ltx_p'>This trail aims at providing a hands-on introduction to the
key language construct of SaC: the with-loop.
It constitutes the generalisation of the
set-expression as introduced in the lesson <a href='#Ch2.S2' title='2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.2</a> on
Shape-Invariant Programming
and can be seen as a shape-invariant form of the map-reduce template or
the array comprehensions found in other functional languages.
However, in contrast to these, the with-loop was carefully designed
to enable radical code optimisations as well as compilation
into high-performance, concurrently executable code.</p>
<p class='ltx_p'>
A note for language design freaks:
In fact, almost all array operations introduced in earlier
trails are defined by with-loops within the standard library.
This design combines two major advantages:
•
<em class='ltx_emph'>better performance</em>, as the conformity enables optimisations to be more generally applicable, and
•
<em class='ltx_emph'>increased flexibility</em>, as the user can modify the definition
of all standard operations.
<br class='ltx_break'>
</p>
<p class='ltx_p'>The introduction of with-loops comes in a single lesson which step-wise
introduces all features and variants of with-loops in SaC.</p>
<section id='Ch4.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
4.1 Lesson 6: with-loop Basics</h4>
<section id='Ch4.S1.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
4.1.1 Basic Components</h5>
<p class='ltx_p'>Generally, with-loops are composed of three different components:</p>
<ul id='Ch4.S1.I1' class='ltx_itemize'>
<li id='Ch4.S1.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>sets of index vectors (referred to as <em class='ltx_emph ltx_font_italic'>generator-ranges</em>),</p>
</li>
<li id='Ch4.S1.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>functions that map index vectors to arbitrary values
(<em class='ltx_emph ltx_font_italic'>generator-expressions</em>), and</p>
</li>
<li id='Ch4.S1.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>combining operations (<em class='ltx_emph ltx_font_italic'>with-loop operators</em>) that take such
values and construct arrays from them.</p>
</li>
</ul>
<p class='ltx_p'>In its simplest form, a with-loop contains one component of each kind.
It then maps the function defined by the generator-expression to all
index vectors from the generator-range in a data-parallel
fashion. This leads to a set of index-value-pairs which are combined into
a result array by means of the given with-loop operator.
Let’s have a look at a simple example:</p>
<figure id='LST30' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 30: Simple with-loop</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gd2l0aCB7CiAgICAgICAgIChbMF0gPD0gaXYgPCBbNV0pOiA0MjsKICAgICAgIH06IGdlbmFycmF5KFs3XSwgMCk7CgogICBwcmludChhKTsKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>with</span><span class='ltx_text ltx_lst_space'> </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>([0]<span class='ltx_text ltx_lst_space'> </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_space'> </span>[5]):<span class='ltx_text ltx_lst_space'> </span>42;
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([7],<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_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'>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_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>}
</figure>
<p class='ltx_p'>Here, the with-loop in lines 6–8 computes
the vector [42, 42, 42, 42, 42, 0, 0].
The generator-range is specified by the code snippet in round
brackets in line 7: ([0] ⇐ iv «span class='ltx_text ltx_lst_space'> [5])</span>.
It denotes the set of vectors
<math id='Ch4.S1.SS1.p4.m1' class='ltx_Math' alttext='{\{\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_0_listinggroup_ltx_lst_space}[1],{\@listingGroup{ltx_lst_space}{~{}}}…,{%
\@listingGroup{ltx_lst_space}{~{}}}[4]}}}}\}' display='inline'><mrow><mo stretchy='false'>{</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>[0],</mtext><mtext> </mtext><mtext>[1],</mtext><mtext> </mtext><mtext>…,</mtext><mtext> </mtext><mtext>[4]</mtext></mrow><mo stretchy='false'>}</mo></mrow></math>.
The generator-expression here is the constant 42.
Hence, the mapping function <math id='Ch4.S1.SS1.p4.m2' class='ltx_Math' alttext='f_{\text{map}}' display='inline'><msub><mi>f</mi><mtext>map</mtext></msub></math> maps any index vector iv
into 42, i.e. we have <math id='Ch4.S1.SS1.p4.m3' class='ltx_Math' alttext='{f_{\text{map}}\textrm{\lstinlinelst_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_space}{~{}}}={%
\@listingGroup{ltx_lst_space}{~{}}}42}}}}' display='inline'><mrow><msub><mi>f</mi><mtext>map</mtext></msub><mo></mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>(</mtext><mtext>iv</mtext><mtext>)</mtext><mtext> </mtext><mtext>=</mtext><mtext> </mtext><mtext>42</mtext></mrow></mrow></math>.
Finally, the with-loop operation is specified as
genarray([7], 0).
This operation computes an array of shape [7] where:
</p>
<table id='Ch4.Ex1' class='ltx_equation ltx_eqn_table'>
<tr class='ltx_equation ltx_eqn_row ltx_align_baseline'>
<td class='ltx_eqn_cell ltx_eqn_center_padleft'></td>
<td class='ltx_eqn_cell ltx_align_center'><math id='Ch4.Ex1.m1' class='ltx_Math' alttext='textrm_lstinline_lst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_a[{\@listingGroup{ltx_lst_identifier}{iv}}]}}}}=\begin{%
cases}f_{\text{map}}\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_iv)}}}}&\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_listinggroup_ltx_lst_identifier_iv}%
}}}\in\{\textrm{\lstinlinelst_set_language_lst_set_numbers_lst_set_frame_lst_set_rulecolor_lst_set_language_lst_set_numbers_0_listinggroup_ltx_lst_space}[1],{\@listingGroup{ltx_lst_space}{~{}}}…%
,{\@listingGroup{ltx_lst_space}{~{}}}[4]}}}}\}
0&\text{otherwise.}\end{cases}' display='block'><mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>a</mtext><mtext>[</mtext><mtext>iv</mtext><mtext>]</mtext></mrow><mo>=</mo><mrow><mo>{</mo><mtable columnspacing='5pt' displaystyle='true' rowspacing='0pt'><mtr><mtd columnalign='left'><mrow><msub><mi>f</mi><mtext>map</mtext></msub><mo></mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>(</mtext><mtext>iv</mtext><mtext>)</mtext></mrow></mrow></mtd><mtd columnalign='left'><mrow><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</mtext><mo>∈</mo><mrow><mo stretchy='false'>{</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>[0],</mtext><mtext> </mtext><mtext>[1],</mtext><mtext> </mtext><mtext>…,</mtext><mtext> </mtext><mtext>[4]</mtext></mrow><mo stretchy='false'>}</mo></mrow></mrow></mtd></mtr><mtr><mtd columnalign='left'><mn>0</mn></mtd><mtd columnalign='left'><mtext>otherwise.</mtext></mtd></mtr></mtable></mrow></mrow></math></td>
<td class='ltx_eqn_cell ltx_eqn_center_padright'></td>
</tr>
</table>
<p class='ltx_p'>Generator-ranges and generator-expressions always occur
in pairs. Jointly they
form a syntactical unit, which we refer-to as generator.
As we will see later, with-loops can contain arbitrary numbers of
generators. They are enclosed in curly brackets.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 25. </h6>
<p class='ltx_p'>What result do you expect if we eliminate the generator from the above example?</p>
<p class='ltx_p'>What results do you expect if we modify the generator-range
in the above example into:</p>
<ul id='Ch4.S1.I2' class='ltx_itemize'>
<li id='Ch4.S1.I2.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>([-2] ⇐ iv «span class='ltx_text ltx_lst_space'> [3])</span>?</p>
</li>
<li id='Ch4.S1.I2.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>([0] ⇐ iv «span class='ltx_text ltx_lst_space'> [8])</span>?
</p>
</li>
<li id='Ch4.S1.I2.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>([6] ⇐ iv «span class='ltx_text ltx_lst_space'> [5])</span>?</p>
</li>
<li id='Ch4.S1.I2.i4' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>([8] ⇐ iv «span class='ltx_text ltx_lst_space'> [5])</span>?</p>
</li>
<li id='Ch4.S1.I2.i5' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>([6] ⇐ iv «span class='ltx_text ltx_lst_space'> [0])</span>?</p>
</li>
</ul>
<p class='ltx_p'>[Hint: You should compile these examples with the option -check c
being enabled]</p>
</section>
<section id='Ch4.S1.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
4.1.2 Generator Ranges</h5>
<p class='ltx_p'>SaC offers quite some flexibility when it comes to specifying
generator ranges.
First of all, the use of index vectors in the bounds enables
the convenient specification of <math id='Ch4.S1.SS2.p1.m1' class='ltx_Math' alttext='n' display='inline'><mi>n</mi></math>-dimensional index ranges.
Let us look at a few examples for the 2-dimensional case:</p>
<figure id='LST31' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 31: Generator Range Specifications</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gd2l0aCB7CiAgICAgICAgIChbMCwyXSA8PSBbaSxqXSA8IFs1LDZdKTogNDI7CiAgICAgICB9OiBnZW5hcnJheShbNSw2XSwgMCk7CiAgIHByaW50KGEpOwoKICAgc2hwID0gWzUsNl07CiAgIGEgPSB3aXRoIHsKICAgICAgICAgKDAqc2hwIDw9IGl2IDwgc2hwKTogNDI7CiAgICAgICB9OiBnZW5hcnJheShzaHAsIDApOwogICBwcmludChhKTsKCiAgIGEgPSB3aXRoIHsKICAgICAgICAgKC4gPCBpdiA8IC4pOiA0MjsKICAgICAgIH06IGdlbmFycmF5KFs1LDZdLCAwKTsKICAgcHJpbnQoYSk7CgogICBhID0gd2l0aCB7CiAgICAgICAgICguIDw9IGp2PVt4LHldIDw9IFs0LDVdKTogNDI7CiAgICAgICB9OiBnZW5hcnJheSggWzUsNl0sIDApOwogICBwcmludChhKTsKCiAgIGEgPSB3aXRoIHsKICAgICAgICAgKC4gPD0gW2ksal0gPD0gLiBzdGVwIFsxLDRdKTogNDI7CiAgICAgICB9OiBnZW5hcnJheShbNSw2XSwgMCk7CiAgIHByaW50KGEpOwoKICAgYSA9IHdpdGggewogICAgICAgICAoLiA8PSBbaSxqXSA8PSAuIHN0ZXAgWzIsNF0gd2lkdGggWzEsMl0pOiA0MjsKICAgICAgIH06IGdlbmFycmF5KFs1LDZdLCAwKTsKICAgcHJpbnQoYSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>with</span><span class='ltx_text ltx_lst_space'> </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>([0,2]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span><<span class='ltx_text ltx_lst_space'> </span>[5,6]):<span class='ltx_text ltx_lst_space'> </span>42;
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([5,6],<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'>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;'>10</span></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'>shp</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[5,6];
<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'>a</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'>with</span><span class='ltx_text ltx_lst_space'> </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>(0*<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><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><span class='ltx_text ltx_lst_identifier'>shp</span>):<span class='ltx_text ltx_lst_space'> </span>42;
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>(<span class='ltx_text ltx_lst_identifier'>shp</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'>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;'>16</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><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_keyword ltx_font_bold'>with</span><span class='ltx_text ltx_lst_space'> </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_space'> </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_space'> </span>.):<span class='ltx_text ltx_lst_space'> </span>42;
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([5,6],<span class='ltx_text ltx_lst_space'> </span>0);
<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'>a</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></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'>a</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'>with</span><span class='ltx_text ltx_lst_space'> </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_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>jv</span>=[<span class='ltx_text ltx_lst_identifier'>x</span>,<span class='ltx_text ltx_lst_identifier'>y</span>]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[4,5]):<span class='ltx_text ltx_lst_space'> </span>42;
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>(<span class='ltx_text ltx_lst_space'> </span>[5,6],<span class='ltx_text ltx_lst_space'> </span>0);
<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'>a</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></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'>a</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'>with</span><span class='ltx_text ltx_lst_space'> </span>{
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</span></span>
<span class='ltx_text ltx_lst_space'> </span>(.<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>.<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>step</span><span class='ltx_text ltx_lst_space'> </span>[1,4]):<span class='ltx_text ltx_lst_space'> </span>42;
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([5,6],<span class='ltx_text ltx_lst_space'> </span>0);
<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><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;'>31</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>32</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_keyword ltx_font_bold'>with</span><span class='ltx_text ltx_lst_space'> </span>{
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>33</span></span>
<span class='ltx_text ltx_lst_space'> </span>(.<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>.<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>step</span><span class='ltx_text ltx_lst_space'> </span>[2,4]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>width</span><span class='ltx_text ltx_lst_space'> </span>[1,2]):<span class='ltx_text ltx_lst_space'> </span>42;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>34</span></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>([5,6],<span class='ltx_text ltx_lst_space'> </span>0);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>35</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;'>36</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>37</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;'>38</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>As we can see from the first with-loop in
lines 6–8, a vector
of scalar indices can be used where we previously used the
variable iv to denote the entire index vector.
In cases where the dimensionality of the with-loop is statically
fixed, this sometimes comes in handy.
However, if we want to adopt a more generic, shape-invariant programming
style, it becomes mandatory to use vectors for the index variable
as well as for the bounds.</p>
<p class='ltx_p'>
Note here, that the ability to use vectors rather than
componentised indices and bounds is absolutely crucial here!
It constitutes the enabling
factor for specifying with-loops in a shape-invariant style as
the length of those vectors may remain unknown until runtime.
It is this particular feature that sets the with-loops apart
from most conventional language
constructs for data-parallel array operations.
</p>
<p class='ltx_p'>The with-loop in lines 12–14
demonstrates a typical case where
the dimensionality of the resulting array is solely determined
by a vector (here shp).
A slightly more elegant way for the most frequent case is the use
of a syntactical shortcut supported by SaC. The symbol “.” can
be used in the position for the lower and upper bound, denoting the
lowest legal index and the highest legal index into the array to be
created, respectively.
This is examplified in the with-loop in
lines 17–19. Note here,
that this generator-range does <em class='ltx_emph ltx_font_italic'>not</em> cover the entire legal
index space of the resulting array!
As the “.” always represents legal indices, we have to make sure
that we use ⇐ on both sides if we want to cover the entire
range. The example presented here, excludes the extreme cases and, thus,
covers all inner elements of the resulting array only.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 26. </h6>
<p class='ltx_p'>What happens if the length of the vectors within the generator-range
or the shape expression in the genarray-operation do not match?
[Hint: You should compile these example with the option -check c
being enabled]</p>
<p class='ltx_p'>The with-loop in lines 22–24
demonstrates how both, a vector version
of the index vector and scalarised versions can be made available
for the generator-expression. It also examplifies that a mix of
the .-symbol and explicit expressions can be used for the bounds.</p>
<p class='ltx_p'>The remaining two with-loops demonstrate the ability to specify
rectangular grids of indices.
The vector that follows the keyword step specifies the stride
of the reoccurence pattern per axis.
As a consequence, the with-loop in lines 27–29
computes an array
whose every fourth column is 42 starting with the very first one.</p>
<p class='ltx_p'>The use of the vector after the keyword width enables the programmer
to denote more than one index per stepping period.
The with-loop in lines 27–29
computes a matrix where <math id='Ch4.S1.SS2.p7.m1' class='ltx_Math' alttext='1\times 2' display='inline'><mrow><mn>1</mn><mo>×</mo><mn>2</mn></mrow></math> blocks of the value
42 are placed in the upper left corner of each <math id='Ch4.S1.SS2.p7.m2' class='ltx_Math' alttext='2\times 4' display='inline'><mrow><mn>2</mn><mo>×</mo><mn>4</mn></mrow></math> grid of the
resulting array.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 27. </h6>
<p class='ltx_p'>Can you achieve the same result array as the last with-loop of the above
examples without using the step/width facility?
[Hint: The solution may be surprisingly short!]</p>
</section>
<section id='Ch4.S1.SS3' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
4.1.3 Generator Expressions</h5>
<p class='ltx_p'>As we have seen in the previous sections, each generator expression
implicitly defines a mapping function from indices to expressions.
The parameters of these functions are derived from the index variables
introduced in the associated generator range specifications.
More complex generator expressions can be specified by
assignment blocks that can be inserted between a generator range and the
associated generator expression. Here a few examples:</p>
<figure id='LST32' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 32: Non-trivial generator expressions</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50LCBpbnQgZGl2bW9kKGludCB4LCBpbnQgeSkKIHsKICAgcmV0dXJuICh4IC8geSwgeCAlIHkpOwogfQoKIGludCBtYWluKCkKIHsKICAgYSA9IHdpdGggewogICAgICAgICAoWzAsMV0gPD0gW2ksal0gPCBbNiw2XSkgewogICAgICAgICAgIGRpdiwgbW9kID0gZGl2bW9kKCBpLCBqKTsKICAgICAgICAgfTogbW9kOwogICAgICAgfTogZ2VuYXJyYXkoWzYsNl0sIDApOwogICBwcmludChhKTsKCiAgIGEgPSB3aXRoIHsKICAgICAgICAgKC4gPD0gW2ksal0gPD0gLik6IChpPT1qID8gMTogMCkgOwogICAgICAgfTogZ2VuYXJyYXkoWzYsNl0sIDApOwogICBwcmludChhKTsKCiAgIGEgPSB3aXRoIHsKICAgICAgICAgKC4gPD0gW2ldIDw9IC4pIHsKICAgICAgICAgICBtdmFsID0gaTsKICAgICAgICAgICB2YWwgPSBzdW0od2l0aCB7CiAgICAgICAgICAgICAgICAgICAgICAgICguIDw9IFtpXSA8PSAuKTogaTsKICAgICAgICAgICAgICAgICAgICAgfTogZ2VuYXJyYXkoW212YWxdLCAwKSk7CiAgICAgICAgIH06IHZhbDsKICAgICAgIH06IGdlbmFycmF5KFs2XSwgMCk7CiAgIHByaW50KGEpOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>divmod</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'>x</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'>y</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>{
<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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>x</span><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</span><span class='ltx_text ltx_lst_space'> </span>%<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</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><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;'>10</span></span>
<span class='ltx_text ltx_lst_space'> </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'>a</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'>with</span><span class='ltx_text ltx_lst_space'> </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>([0,1]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span><<span class='ltx_text ltx_lst_space'> </span>[6,6])<span class='ltx_text ltx_lst_space'> </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'>div</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mod</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>divmod</span>(<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>j</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_space'> </span><span class='ltx_text ltx_lst_identifier'>mod</span>;
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([6,6],<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_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;'>17</span></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'>a</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'>with</span><span class='ltx_text ltx_lst_space'> </span>{
<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_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>.):<span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>i</span>==<span class='ltx_text ltx_lst_identifier'>j</span><span class='ltx_text ltx_lst_space'> </span>?<span class='ltx_text ltx_lst_space'> </span>1:<span class='ltx_text ltx_lst_space'> </span>0)<span class='ltx_text ltx_lst_space'> </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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([6,6],<span class='ltx_text ltx_lst_space'> </span>0);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</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;'>22</span></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'>a</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'>with</span><span class='ltx_text ltx_lst_space'> </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_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </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;'>25</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mval</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>i</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'>val</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sum</span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>with</span><span class='ltx_text ltx_lst_space'> </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_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>.):<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>i</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</span></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>([<span class='ltx_text ltx_lst_identifier'>mval</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_space'> </span><span class='ltx_text ltx_lst_identifier'>val</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>}:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([6],<span class='ltx_text ltx_lst_space'> </span>0);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>31</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;'>32</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>33</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;'>34</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>The first with-loop in lines 11–15
shows a typical scenario.
The function divmod returns two values rather than just one.
Rather than defining an explicit mapping function that passes
on the desired return value, we can specify this selection
directly.</p>
<p class='ltx_p'>The with-loop in lines 18–20
demonstrates how non-trivial expressions
can be used even without necessitating the introduction of an
assignment block.
</p>
<p class='ltx_p'>The scope of variables that are defined in such an assignment block is
strictly local
to that block. Such a variable can neither be referenced within other generators
of the same with-loop nor outside of the with-loop.
Note, however, that with-loops can be arbitrarily nested.
An example for such a nesting is shown in the with-loop in
lines 23–30
of the examples above.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 28. </h6>
<p class='ltx_p'>What do you expect to happen, if a variable that is defined
in such an assignment block has the same name as the index variable?
Where is the “modified” version observable?</p>
<p class='ltx_p'>Why can the variable mval in the example above be safely replaced by
i?</p>
</section>
<section id='Ch4.S1.SS4' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
4.1.4 Reductions and further with-loop Operations</h5>
<p class='ltx_p'>Besides the genarray with-loop operator described so far, SaC supports
a few more. These are:</p>
<ul id='Ch4.S1.I3' class='ltx_itemize'>
<li id='Ch4.S1.I3.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>a modarray operator which “modifies” an existing array, and</p>
</li>
<li id='Ch4.S1.I3.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>two fold operators that enable the specification of reduction
operations</p>
</li>
</ul>
<p class='ltx_p'>The modarray variant is very similar to the genarray variant.
The only difference is that neither the shape of the result
nor a default element for unspecified index positions
are explicit. Both of these are taken from a specified
array that serves as a template. The second with-loop in
lines 11–13
of the example below demonstrates this.
Here, a new array b is computed from the array a
by negating each second element of a.
As in lesson <a href='#Ch2.S1' title='2.1 Lesson 1: Arrays as Data ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.1</a> on arrays as data, printing
a in line 15 shows that in fact two different arrays have
been created.</p>
<figure id='LST33' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 33: Further with-loop operators</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogdXNlIEFycmF5OiBhbGw7CgogaW50IG1haW4oKQogewogICBhID0gd2l0aCB7CiAgICAgICAgICguIDw9IFtpXSA8PSAuKTogaTsKICAgICAgIH06IGdlbmFycmF5KCBbNl0sIDApOwogICBwcmludChhKTsKCiAgIGIgPSB3aXRoIHsKICAgICAgICAgKC4gPD0gaXYgPD0gLiBzdGVwIFsyXSk6IC1hW2l2XTsKICAgICAgIH06IG1vZGFycmF5KGEpOwogICBwcmludChiKTsKICAgcHJpbnQoYSk7CgogICBjID0gd2l0aCB7CiAgICAgICAgKFswXSA8PSBpdiA8PSBbNV0pOiBhW2l2XTsKICAgICAgIH06IGZvbGQoKiwgMSk7CiAgIHByaW50KGMpOwoKICAgZCA9IHdpdGggewogICAgICAgIChbMF0gPD0gaXYgPD0gWzVdKTogYVtpdl07CiAgICAgICB9OiBmb2xkZml4KCosIDEsIDApOwogICBwcmludChkKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>with</span><span class='ltx_text ltx_lst_space'> </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_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>i</span>]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>.):<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>i</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_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>(<span class='ltx_text ltx_lst_space'> </span>[6],<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'>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;'>10</span></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'>b</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'>with</span><span class='ltx_text ltx_lst_space'> </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>(.<span class='ltx_text ltx_lst_space'> </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_space'> </span>.<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>step</span><span class='ltx_text ltx_lst_space'> </span>[2]):<span class='ltx_text ltx_lst_space'> </span>-<span class='ltx_text ltx_lst_identifier'>a</span>[<span class='ltx_text ltx_lst_identifier'>iv</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_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</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'>b</span>);
<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'>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;'>16</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><span class='ltx_text ltx_lst_identifier'>c</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'>with</span><span class='ltx_text ltx_lst_space'> </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>([0]<span class='ltx_text ltx_lst_space'> </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_space'> </span>[5]):<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>[<span class='ltx_text ltx_lst_identifier'>iv</span>];
<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_space'> </span><span class='ltx_text ltx_lst_identifier'>fold</span>(*,<span class='ltx_text ltx_lst_space'> </span>1);
<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'>c</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></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'>d</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'>with</span><span class='ltx_text ltx_lst_space'> </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>([0]<span class='ltx_text ltx_lst_space'> </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_space'> </span>[5]):<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>[<span class='ltx_text ltx_lst_identifier'>iv</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_space'> </span><span class='ltx_text ltx_lst_identifier'>foldfix</span>(*,<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;'>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'>d</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></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_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;'>28</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>The two final examples demonstrate how reduction operations can be specified
in SaC.
The first variant (lines 17–19)
is the standard variant for reductions.
It requires the specification of a folding function (* in this case)
and of a neutral element (1 here).
As with the earlier variants, all index vectors from the generator range are mapped
according to the generator expression. Subsequently all computed
values are folded using the specified folding function.
Note here, that no particular folding order is guaranteed!
In order to obtain deterministic results on a multicore machine
this requires the specified folding operation to be both,
associative and commutative.</p>
<p class='ltx_p'>The final with-loop in lines 22–24
is a slight variant of the fold version.
It stems from the observation that some reductions can be shortcut
when a certain fixpoint value has been met. In the given example of
multiplication this is the value .
Whether the underlying implementation makes use of this extra information
or not is not specified. The computational result of both, the fold
and the foldfix variant are the same, provided that the specified fixpoint
value in fact constitutes one for the specified folding operation.</p>
</section>
</section>
</section>
<section id='Ch5' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 5 Working with Modules</h3>
<p class='ltx_p'>This chapter explains the basic principles of using modules in SaC. Prior to
modules, a short introduction into SaC name spaces is given.</p>
<section id='Ch5.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
5.1 Name Spaces</h4>
<p class='ltx_p'>In general, name spaces are used to extend the set of possible identifiers and
thus inhibit potential name clashes. SaC supports multiple name spaces, although
these are not explicitly defined by the programmer. Instead, every module and
program has its own name space. The name space of a module is denoted by its
name, a program uses main as its name space identifier. As an example of
using name spaces consider Listing <a href='#LST34' title='Listing 34 ‣ 5.1 Name Spaces ‣ Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>34</a>.</p>
<figure id='LST34' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 34: Hello world program with name spaces</figcaption>
<a href='data:text/plain;base64,IGludCBtYWluKCkKIHsKICAgU3RkSU86OnByaW50ZigiSGVsbG8gV29ybGQhXG4iKTsKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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'>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;'>2</span></span>
<span class='ltx_text ltx_lst_space'> </span>{
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</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;'>4</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;'>5</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Instead of an import statement, a qualified function name is used. A qualified
identifier always consists of a name space identifier, followed by a double
colon and the unqualified identifier, in this case a function identifier.
Besides of functions, fully qualified names may as well be used for types and
global objects.</p>
<p class='ltx_p'>As it would be bothering to precede each identifier with the name space it
belongs to, SaC supports multiple ways to automatically decide the right name
space and generate a fully qualified identifier implicitly (or internally).</p>
</section>
<section id='Ch5.S2' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
5.2 Use Statements</h4>
<p class='ltx_p'>To simplify the use of identifiers from other modules, SaC allows us to specify
a search space whose identifiers can be used in an unqualified fashion. By
default, this search space contains all identifiers from the current name space.
To add a complete name space to the current search space, you may use the
statement use <math id='Ch5.S2.p1.m1' class='ltx_Math' alttext='\alpha' display='inline'><mi>α</mi></math>: all; where <math id='Ch5.S2.p1.m2' class='ltx_Math' alttext='\alpha' display='inline'><mi>α</mi></math> gives
the name of a name space. Using this technique, the hello world example can as
well be expressed as follows:</p>
<figure id='LST35' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 35: hello world with use statement</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwoKIGludCBtYWluKCkKIHsKICAgcHJpbnRmKCJIZWxsbyBXb3JsZCFcbiIpOwogICByZXR1cm4gMDsKIH0='>⬇</a>
<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>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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>()
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</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_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>}
</figure>
<p class='ltx_p'>However, an identifier is not allowed to have multiple occurrences within the
search space as far as types and global objects are concerned. For function
symbols the same holds modulo overloading based on parameter types.</p>
<p class='ltx_p'>To further avoid name clashes, SaC supports a more specific way to define search
spaces. Instead of the keyword all, a comma separated list of
identifiers can be given. The following version of hello world uses a more
specific use statement:</p>
<figure id='LST36' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 36: hello world with specific use statement</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzoge3ByaW50Zn07CgogaW50IG1haW4oKQogewogICBwcmludGYoIkhlbGxvIFdvcmxkIVxuIik7CiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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'>printf</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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>()
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</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_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>}
</figure>
<p class='ltx_p'>In this example, only printf is made available to the search space
and can thus be used without explicitly specifying its name space. In some
occasions it can be useful to add all identifiers except a given set to the
search space. Consider a module FastIO reimplementing all functions
of StdIO. To use FastIO except the printf
function, but StdIO::printf one might write:</p>
<figure id='LST37' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 37: hello world with use all but statement</figcaption>
<a href='data:text/plain;base64,IHVzZSBGYXN0SU86IGFsbCBleGNlcHQge3ByaW50Zn07CiB1c2UgU3RkSU86IHtwcmludGZ9OwoKIGludCBtYWluKCkKIHsKICAgcHJpbnRmKCJIZWxsbyBXb3JsZCFcbiIpOwogICByZXR1cm4gMDsKIH0='>⬇</a>
<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'>FastIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>except</span><span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>printf</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'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>printf</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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>);
<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;
<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>}
</figure>
<p class='ltx_p'>This adds all identifiers from FastIO to the current search space
except FastIO::printf. This allows the function printf
to be imported from module StdIO.</p>
</section>
<section id='Ch5.S3' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
5.3 Import statement</h4>
<p class='ltx_p'>So far, we added identifiers to the search space of the SaC compiler to avoid
explicitly specifying their name spaces each time they are referenced. As
function signatures have to differ in number of arguments or their types, the
use statement prevents overloading of functions by shape across
module boundaries. In fact, SaC only supports overloading by shape within a
single name space. Otherwise, the meaning of a fully qualified identifier could
differ when being used in different scopes. To nonetheless allow for successive
overloading in separate modules, SaC provides a mechanism for cloning functions
using the import statement.</p>
<figure id='LST38' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 38: hello world with import statement</figcaption>
<a href='data:text/plain;base64,IGltcG9ydCBTdGRJTzoge3ByaW50Zn07CgogaW50IG1haW4oKQogewogICBtYWluOjpwcmludGYoIkhlbGxvIFdvcmxkIVxuIik7CiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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'>import</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'>printf</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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>()
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</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_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>}
</figure>
<p class='ltx_p'>In this example, the statement import StdIO: {printf} creates a
(conceptual) copy of the function printf in the current name space
main. Consider a module foo containing a function
int[*] bar(int[*]). This function can now be overloaded as follows:</p>
<figure id='LST39' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 39: bar overloading</figcaption>
<a href='data:text/plain;base64,IGltcG9ydCBmb286IHtiYXJ9OwoKIGludFsrXSBiYXIoaW50WytdIHgpCiB7CiAgIC8qIC4uLiAgKi8KIH0KCiBpbnQgbWFpbigpCiB7CiAgIC8qIC4uLiAgKi8KCiAgIHkgPSBiYXIoeCk7CgogICAvKiAuLi4gICovCiB9'>⬇</a>
<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'>import</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>foo</span>:<span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>bar</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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'>bar</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'>x</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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;'>9</span></span>
<span class='ltx_text ltx_lst_space'> </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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</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><span class='ltx_text ltx_lst_identifier'>y</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>bar</span>(<span class='ltx_text ltx_lst_identifier'>x</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</span>
<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>}
</figure>
<p class='ltx_p'>Within the name space main there are two instances of bar, the
one imported from foo and the one defined within main
itself. Keep in mind, that there is a conceptual copy in main, so
both are defined in main and so overloading can take place.</p>
<p class='ltx_p'>Be careful when importing types, as an imported type is regarded as different to
its origin type by the type system as they were defined in different name
spaces. However, you might still exchanges values between both types by means of
a cast expression.</p>
</section>
<section id='Ch5.S4' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
5.4 Putting It Together</h4>
<p class='ltx_p'>Both types of module statements can be mixed in any possible way, as long as no
name clash is introduced by them. Always keep in mind that an import
statement adds all identifiers to the current name space and thus to the current
search space, as well. The following example creates a name clash by using and
importing the same identifier:</p>
<figure id='LST40' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 40: name clash example</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsOwogaW1wb3J0IFN0ZElPOiB7cHJpbnRmfTsKCiBpbnQgbWFpbigpCiB7CiAgIHByaW50ZigiTmV2ZXIgc2VlIHRoaXMhXG4iKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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>;
<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'>import</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'>printf</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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'>”Never<span class='ltx_text ltx_lst_space'> </span>see<span class='ltx_text ltx_lst_space'> </span>this!\n”</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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>}
</figure>
<p class='ltx_p'>Here, printf is imported to the current name space, so there is an
identifier main::printf, which is part of the compiler search space.
Furthermore, the use statement adds the complete name space of
module StdIO to the current name space, especially the identifier
StdIO::printf. Thus there are two identifiers with the same
unqualified name within the search space. To solve this, a restriction to the
use statement can be used.</p>
<figure id='LST41' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 41: name clash example</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdGRJTzogYWxsIGV4Y2VwdCB7cHJpbnRmfTsKIGltcG9ydCBTdGRJTzoge3ByaW50Zn07CgogaW50IG1haW4oKQogewogICBwcmludGYoIkhleSwgaXQgd29ya3MhXG4iKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>except</span><span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>printf</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'>import</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'>printf</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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'>”Hey,<span class='ltx_text ltx_lst_space'> </span>it<span class='ltx_text ltx_lst_space'> </span>works!\n”</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><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>}
</figure>
<p class='ltx_p'>In this example, the identifier StdIO::printf is no longer added to
the compiler search space and thus no name clash originates.</p>
</section>
<section id='Ch5.S5' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
5.5 Implementing Modules</h4>
<p class='ltx_p'>A SaC module implementation essentially looks just like a program, being a
collection of type, global object and function definitions. Unlike a program, a
module starts with the key word module followed by the module name,
i.e. the name space, and a semicolon.
</p>
<figure id='LST42' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 42: module implementation example</figcaption>
<a href='data:text/plain;base64,IG1vZHVsZSBteW1vZDsKCiBwcm92aWRlIGFsbCBleGNlcHQge2Zvb307CiBleHBvcnQge2Zvb307CgogaW50IGZvbyhpbnQgeCkKIHsKICAgcmV0dXJuIC8qIC4uLiAgKi87CiB9CgogaW50IGJhcih4IGludCB4KQogewogICByZXR1cm4gLyogLi4uICAqLzsKIH0='>⬇</a>
<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_identifier'>module</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mymod</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>provide</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>except</span><span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>foo</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_identifier'>export</span><span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>foo</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>foo</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'>x</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_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><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </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>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>bar</span>(<span class='ltx_text ltx_lst_identifier'>x</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'>x</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>{
<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><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </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>}
</figure>
<p class='ltx_p'>The more interesting aspect of a module (name space) is the question which
symbols (types, global objects and functions) are made available outside the
module and which are merely accessible internally within the module itself. Two
kinds of statements using the key words provide and
export provide fine-grained control over the availability of symbols
outside the current module. By default any symbol defined in a module is only
accessible in the module itself. Using the provide statement all or
selected symbols can be made available to be “used” by other modules or
programs. With the export statement symbols are made available for
either use or import by other modules or programs. The
syntax of provide and export statements is very similar
to that of the corresponding use and import statements.
Either all symbols are provided/exported uniformly, or a specific list of
symbols is concerned, or all but a given list of symbols.</p>
</section>
</section>
<section id='Ch6' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 6 Case Studies</h3>
<p class='ltx_p'>This trail will illustrate how to use SaC for real-world applications. The
following exercises make use of the techniques introduced in this tutorial so
far. Working through this trail shall give you some more hands-on experience
with the language itself and at the same time show you how to employ SaC to
solve your every-day problems in an efficient way.</p>
<section id='Ch6.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
6.1 Lesson 7: Image Processing</h4>
<p class='ltx_p'>Digital image processing spans across a vast area of applications. Ranging from
digital photography over astronomy to surgery-assisting medical imaging, most
applications still share as their underlying theory some sort of basic signal
processing on two-dimensional (and potentially higher-dimensional) signals. It
is common to work with discretised signals, i.e. an approximation of the
originally analogue, continuous version of the signal.</p>
<p class='ltx_p'>In this exercise we will focus on two basic image filters on static,
two-dimensional, 8-bit gray-scale images with a resolution of <math id='Ch6.S1.p2.m1' class='ltx_Math' alttext='x_{\text{max}}\times y_{\text{max}}' display='inline'><mrow><msub><mi>x</mi><mtext>max</mtext></msub><mo>×</mo><msub><mi>y</mi><mtext>max</mtext></msub></mrow></math>, such that an image is a 2D function</p>
<table id='Ch10.S4.EGx1' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'>
<tbody id='Ch6.Ex1'><tr class='ltx_equation ltx_eqn_row ltx_align_baseline'>
<td class='ltx_eqn_cell ltx_eqn_center_padleft'></td>
<td class='ltx_td ltx_align_right ltx_eqn_cell'><math id='Ch6.Ex1.m1' class='ltx_Math' alttext='\displaystyle S:\mathbb{N}\times\mathbb{N}' display='inline'><mrow><mi>S</mi><mo>:</mo><mrow><mi>ℕ</mi><mo>×</mo><mi>ℕ</mi></mrow></mrow></math></td>
<td class='ltx_td ltx_align_center ltx_eqn_cell'><math id='Ch6.Ex1.m2' class='ltx_Math' alttext='\displaystyle\rightarrow' display='inline'><mo>→</mo></math></td>
<td class='ltx_td ltx_align_left ltx_eqn_cell'><math id='Ch6.Ex1.m3' class='ltx_Math' alttext='\displaystyle\mathbb{N}' display='inline'><mi>ℕ</mi></math></td>
<td class='ltx_eqn_cell ltx_eqn_center_padright'></td>
</tr></tbody>
<tbody id='Ch6.Ex2'><tr class='ltx_equation ltx_eqn_row ltx_align_baseline'>
<td class='ltx_eqn_cell ltx_eqn_center_padleft'></td>
<td class='ltx_td ltx_align_right ltx_eqn_cell'><math id='Ch6.Ex2.m1' class='ltx_Math' alttext='\displaystyle S(x,y)' display='inline'><mrow><mi>S</mi><mo></mo><mrow><mo stretchy='false'>(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy='false'>)</mo></mrow></mrow></math></td>
<td class='ltx_td ltx_align_center ltx_eqn_cell'><math id='Ch6.Ex2.m2' class='ltx_Math' alttext='\displaystyle=' display='inline'><mo>=</mo></math></td>
<td class='ltx_td ltx_align_left ltx_eqn_cell'><math id='Ch6.Ex2.m3' class='ltx_Math' alttext='\displaystyle\begin{cases}v_{xy},&\mbox{if }x<x_{\text{max}}\wedge y<y_{\text{%
max}}
0,&\mbox{otherwise}\end{cases}' display='inline'><mrow><mo>{</mo><mtable columnspacing='5pt' rowspacing='0pt'><mtr><mtd columnalign='left'><mrow><msub><mi>v</mi><mrow><mi>x</mi><mo></mo><mi>y</mi></mrow></msub><mo>,</mo></mrow></mtd><mtd columnalign='left'><mrow><mrow><mtext>if </mtext><mo></mo><mi>x</mi></mrow><mo>«/mo><mrow><msub><mi>x</mi><mtext>max</mtext></msub><mo>∧</mo><mi>y</mi></mrow><mo>«/mo><msub><mi>y</mi><mtext>max</mtext></msub></mrow></mtd></mtr><mtr><mtd columnalign='left'><mrow><mn>0</mn><mo>,</mo></mrow></mtd><mtd columnalign='left'><mtext>otherwise</mtext></mtd></mtr></mtable></mrow></math></td>
<td class='ltx_eqn_cell ltx_eqn_center_padright'></td>
</tr></tbody>
</table>
<p class='ltx_p'>where <math id='Ch6.S1.p2.m2' class='ltx_Math' alttext='\forall x,y:0\leq v_{xy}\leq 255' display='inline'><mrow><mrow><mrow><mo>∀</mo><mi>x</mi></mrow><mo>,</mo><mi>y</mi></mrow><mo>:</mo><mrow><mn>0</mn><mo>≤</mo><msub><mi>v</mi><mrow><mi>x</mi><mo></mo><mi>y</mi></mrow></msub><mo>≤</mo><mn>255</mn></mrow></mrow></math>. Informally speaking, the parameters
<math id='Ch6.S1.p2.m3' class='ltx_Math' alttext='x' display='inline'><mi>x</mi></math> and <math id='Ch6.S1.p2.m4' class='ltx_Math' alttext='y' display='inline'><mi>y</mi></math> determine the position within the image and <math id='Ch6.S1.p2.m5' class='ltx_Math' alttext='v_{xy}' display='inline'><msub><mi>v</mi><mrow><mi>x</mi><mo></mo><mi>y</mi></mrow></msub></math> determines the
gray-scale value of the pixel at this position.
</p>
<p class='ltx_p'>A common technique to modify an image is to apply a filter of desired
properties to it. In many cases, an image filter <math id='Ch6.S1.p3.m1' class='ltx_Math' alttext='F' display='inline'><mi>F</mi></math> again is a two dimensional
signal as the one described above. The application of a filter to an image is
expressed by the 2D (discrete) convolution <math id='Ch6.S1.p3.m2' class='ltx_Math' alttext='F\otimes S' display='inline'><mrow><mi>F</mi><mo>⊗</mo><mi>S</mi></mrow></math> of these two
signals:</p>
<table id='Ch10.S4.EGx2' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'>
<tbody id='Ch6.Ex3'><tr class='ltx_equation ltx_eqn_row ltx_align_baseline'>
<td class='ltx_eqn_cell ltx_eqn_center_padleft'></td>
<td class='ltx_td ltx_align_right ltx_eqn_cell'><math id='Ch6.Ex3.m1' class='ltx_Math' alttext='\displaystyle F(x,y)\otimes S(x,y)' display='inline'><mrow><mrow><mrow><mi>F</mi><mo></mo><mrow><mo stretchy='false'>(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy='false'>)</mo></mrow></mrow><mo>⊗</mo><mi>S</mi></mrow><mo></mo><mrow><mo stretchy='false'>(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy='false'>)</mo></mrow></mrow></math></td>
<td class='ltx_td ltx_align_center ltx_eqn_cell'><math id='Ch6.Ex3.m2' class='ltx_Math' alttext='\displaystyle=' display='inline'><mo>=</mo></math></td>
<td class='ltx_td ltx_align_left ltx_eqn_cell'><math id='Ch6.Ex3.m3' class='ltx_Math' alttext='\displaystyle\sum_{j=-\infty}^{\infty}\sum_{k=-\infty}^{\infty}F(j,k)S(x-j,y-k)' display='inline'><mrow><mstyle displaystyle='true'><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∑</mo><mrow><mi>j</mi><mo>=</mo><mrow><mo>-</mo><mi mathvariant='normal'>∞</mi></mrow></mrow><mi mathvariant='normal'>∞</mi></munderover></mstyle><mrow><mstyle displaystyle='true'><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∑</mo><mrow><mi>k</mi><mo>=</mo><mrow><mo>-</mo><mi mathvariant='normal'>∞</mi></mrow></mrow><mi mathvariant='normal'>∞</mi></munderover></mstyle><mrow><mi>F</mi><mo></mo><mrow><mo stretchy='false'>(</mo><mi>j</mi><mo>,</mo><mi>k</mi><mo stretchy='false'>)</mo></mrow><mo></mo><mi>S</mi><mo></mo><mrow><mo stretchy='false'>(</mo><mrow><mi>x</mi><mo>-</mo><mi>j</mi></mrow><mo>,</mo><mrow><mi>y</mi><mo>-</mo><mi>k</mi></mrow><mo stretchy='false'>)</mo></mrow></mrow></mrow></mrow></math></td>
<td class='ltx_eqn_cell ltx_eqn_center_padright'></td>
</tr></tbody>
</table>
<p class='ltx_p'>With this simple form of filtering, a wealth of image modifications are
expressible. Depending on the choice of the filter mask we can achieve effects
such as smoothing, sharpening, edge detection, embossing and many more.</p>
<p class='ltx_p'>In SaC we can represent these signals as 2D arrays where <math id='Ch6.S1.p4.m1' class='ltx_Math' alttext='x' display='inline'><mi>x</mi></math> and <math id='Ch6.S1.p4.m2' class='ltx_Math' alttext='y' display='inline'><mi>y</mi></math> are the
column and row indices and each element corresponds to one pixel. The
application of a filter to an image may then be expressed using a stencil
operation as it was introduced in an earlier part of this tutorial
(Section <a href='#Ch2.S2' title='2.2 Lesson 2: Shape-Invariant Programming ‣ Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>2.2</a>): The filter mask is positioned with its center point over
each pixel of the original image. At each position, the pixel value of the
image and its corresponding value of the filter mask are multiplied. The pixel
value at the same position in the result image is determined by the sum of
these products (weighed sum).
</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 29. </h6>
<p class='ltx_p'>The Sobel operator is an edge-detection filter that computes the
gradient image from an input signal. The filtering process consists of three
steps: In the first step, horizontal edges are detected, in the second step
vertical edges are detected, and in the final step, both sub-results are
combined to the resulting gradient image. The first two steps are in fact two
independent operations, each of which requires its own individual filter mask:</p>
<table id='Ch10.S4.EGx3' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'>
<tbody id='Ch6.Ex4'><tr class='ltx_equation ltx_eqn_row ltx_align_baseline'>
<td class='ltx_eqn_cell ltx_eqn_center_padleft'></td>
<td class='ltx_td ltx_align_right ltx_eqn_cell'><math id='Ch6.Ex4.m1' class='ltx_Math' alttext='\displaystyle F_{x}=\begin{pmatrix}1&0&-1
2&0&-2
1&0&-1\end{pmatrix}' display='inline'><mrow><msub><mi>F</mi><mi>x</mi></msub><mo>=</mo><mrow><mo>(</mo><mtable columnspacing='5pt' rowspacing='0pt'><mtr><mtd columnalign='center'><mn>1</mn></mtd><mtd columnalign='center'><mn>0</mn></mtd><mtd columnalign='center'><mrow><mo>-</mo><mn>1</mn></mrow></mtd></mtr><mtr><mtd columnalign='center'><mn>2</mn></mtd><mtd columnalign='center'><mn>0</mn></mtd><mtd columnalign='center'><mrow><mo>-</mo><mn>2</mn></mrow></mtd></mtr><mtr><mtd columnalign='center'><mn>1</mn></mtd><mtd columnalign='center'><mn>0</mn></mtd><mtd columnalign='center'><mrow><mo>-</mo><mn>1</mn></mrow></mtd></mtr></mtable><mo>)</mo></mrow></mrow></math></td>
<td class='ltx_td ltx_align_center ltx_eqn_cell'></td>
<td class='ltx_td ltx_align_left ltx_eqn_cell'><math id='Ch6.Ex4.m3' class='ltx_Math' alttext='\displaystyle F_{y}=\begin{pmatrix}1&2&1
0&0&0
-1&-2&-1\end{pmatrix}' display='inline'><mrow><msub><mi>F</mi><mi>y</mi></msub><mo>=</mo><mrow><mo>(</mo><mtable columnspacing='5pt' rowspacing='0pt'><mtr><mtd columnalign='center'><mn>1</mn></mtd><mtd columnalign='center'><mn>2</mn></mtd><mtd columnalign='center'><mn>1</mn></mtd></mtr><mtr><mtd columnalign='center'><mn>0</mn></mtd><mtd columnalign='center'><mn>0</mn></mtd><mtd columnalign='center'><mn>0</mn></mtd></mtr><mtr><mtd columnalign='center'><mrow><mo>-</mo><mn>1</mn></mrow></mtd><mtd columnalign='center'><mrow><mo>-</mo><mn>2</mn></mrow></mtd><mtd columnalign='center'><mrow><mo>-</mo><mn>1</mn></mrow></mtd></mtr></mtable><mo>)</mo></mrow></mrow></math></td>
<td class='ltx_eqn_cell ltx_eqn_center_padright'></td>
</tr></tbody>
</table>
<p class='ltx_p'>Applying these two masks to an input image <math id='Thmtheorem29.p1.m1' class='ltx_Math' alttext='S' display='inline'><mi>S</mi></math> yields two sub-results, one
highlighting horizontal edges (<math id='Thmtheorem29.p1.m2' class='ltx_Math' alttext='S_{x}=F_{x}\otimes S' display='inline'><mrow><msub><mi>S</mi><mi>x</mi></msub><mo>=</mo><mrow><msub><mi>F</mi><mi>x</mi></msub><mo>⊗</mo><mi>S</mi></mrow></mrow></math>), the other highlighting
vertical edges (<math id='Thmtheorem29.p1.m3' class='ltx_Math' alttext='S_{y}=F_{y}\otimes S' display='inline'><mrow><msub><mi>S</mi><mi>y</mi></msub><mo>=</mo><mrow><msub><mi>F</mi><mi>y</mi></msub><mo>⊗</mo><mi>S</mi></mrow></mrow></math>). We compute the final gradient image by
adding the two sub-results <math id='Thmtheorem29.p1.m4' class='ltx_Math' alttext='S_{xy}=S_{x}+S_{y}' display='inline'><mrow><msub><mi>S</mi><mrow><mi>x</mi><mo></mo><mi>y</mi></mrow></msub><mo>=</mo><mrow><msub><mi>S</mi><mi>x</mi></msub><mo>+</mo><msub><mi>S</mi><mi>y</mi></msub></mrow></mrow></math>. As <math id='Thmtheorem29.p1.m5' class='ltx_Math' alttext='S_{xy}' display='inline'><msub><mi>S</mi><mrow><mi>x</mi><mo></mo><mi>y</mi></mrow></msub></math> may contain
elements with a value greater than <math id='Thmtheorem29.p1.m6' class='ltx_Math' alttext='255' display='inline'><mn>255</mn></math>, we need to cap each pixel value at
the maximum allowed value of <math id='Thmtheorem29.p1.m7' class='ltx_Math' alttext='255' display='inline'><mn>255</mn></math>. See Fig. <a href='#Ch6.F1' title='Figure 6.1 ‣ 6.1 Lesson 7: Image Processing ‣ Chapter 6 Case Studies ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'>6.1</a> for an example of
how an image and its gradient image may look like.</p>
<p class='ltx_p'>Quite the opposite to edge detection, a smoothing or blurring filter is used to
make edges appear less prominent. Commonly applied filters of such kind
are the <math id='Thmtheorem29.p2.m1' class='ltx_Math' alttext='3\times 3' display='inline'><mrow><mn>3</mn><mo>×</mo><mn>3</mn></mrow></math> and <math id='Thmtheorem29.p2.m2' class='ltx_Math' alttext='25\times 25' display='inline'><mrow><mn>25</mn><mo>×</mo><mn>25</mn></mrow></math> Gaussian blurring stencils:</p>
<table id='Ch10.S4.EGx4' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'>
<tbody id='Ch6.Ex5'><tr class='ltx_equation ltx_eqn_row ltx_align_baseline'>
<td class='ltx_eqn_cell ltx_eqn_center_padleft'></td>
<td class='ltx_td ltx_align_right ltx_eqn_cell'><math id='Ch6.Ex5.m1' class='ltx_Math' alttext='\displaystyle G_{9}=\frac{1}{15}\cdot\begin{pmatrix}1&2&1
2&3&2
1&2&1\par\end{pmatrix}' display='inline'><mrow><msub><mi>G</mi><mn>9</mn></msub><mo>=</mo><mrow><mstyle displaystyle='true'><mfrac><mn>1</mn><mn>15</mn></mfrac></mstyle><mo>⋅</mo><mrow><mo>(</mo><mtable columnspacing='5pt' rowspacing='0pt'><mtr><mtd columnalign='center'><mn>1</mn></mtd><mtd columnalign='center'><mn>2</mn></mtd><mtd columnalign='center'><mn>1</mn></mtd></mtr><mtr><mtd columnalign='center'><mn>2</mn></mtd><mtd columnalign='center'><mn>3</mn></mtd><mtd columnalign='center'><mn>2</mn></mtd></mtr><mtr><mtd columnalign='center'><mn>1</mn></mtd><mtd columnalign='center'><mn>2</mn></mtd><mtd columnalign='center'><mn>1</mn></mtd></mtr></mtable><mo>)</mo></mrow></mrow></mrow></math></td>
<td class='ltx_td ltx_align_center ltx_eqn_cell'></td>
<td class='ltx_td ltx_align_left ltx_eqn_cell'><math id='Ch6.Ex5.m3' class='ltx_Math' alttext='\displaystyle G_{25}=\frac{1}{331}\begin{pmatrix}1&4&7&4&1
4&20&33&20&4
7&33&55&33&7
4&20&33&20&4
1&4&7&4&1\end{pmatrix}' display='inline'><mrow><msub><mi>G</mi><mn>25</mn></msub><mo>=</mo><mrow><mstyle displaystyle='true'><mfrac><mn>1</mn><mn>331</mn></mfrac></mstyle><mo></mo><mrow><mo>(</mo><mtable columnspacing='5pt' rowspacing='0pt'><mtr><mtd columnalign='center'><mn>1</mn></mtd><mtd columnalign='center'><mn>4</mn></mtd><mtd columnalign='center'><mn>7</mn></mtd><mtd columnalign='center'><mn>4</mn></mtd><mtd columnalign='center'><mn>1</mn></mtd></mtr><mtr><mtd columnalign='center'><mn>4</mn></mtd><mtd columnalign='center'><mn>20</mn></mtd><mtd columnalign='center'><mn>33</mn></mtd><mtd columnalign='center'><mn>20</mn></mtd><mtd columnalign='center'><mn>4</mn></mtd></mtr><mtr><mtd columnalign='center'><mn>7</mn></mtd><mtd columnalign='center'><mn>33</mn></mtd><mtd columnalign='center'><mn>55</mn></mtd><mtd columnalign='center'><mn>33</mn></mtd><mtd columnalign='center'><mn>7</mn></mtd></mtr><mtr><mtd columnalign='center'><mn>4</mn></mtd><mtd columnalign='center'><mn>20</mn></mtd><mtd columnalign='center'><mn>33</mn></mtd><mtd columnalign='center'><mn>20</mn></mtd><mtd columnalign='center'><mn>4</mn></mtd></mtr><mtr><mtd columnalign='center'><mn>1</mn></mtd><mtd columnalign='center'><mn>4</mn></mtd><mtd columnalign='center'><mn>7</mn></mtd><mtd columnalign='center'><mn>4</mn></mtd><mtd columnalign='center'><mn>1</mn></mtd></mtr></mtable><mo>)</mo></mrow></mrow></mrow></math></td>
<td class='ltx_eqn_cell ltx_eqn_center_padright'></td>
</tr></tbody>
</table>
<p class='ltx_p'>Write a program that applies these operators to a given image and outputs
the result for later use:</p>
<ul id='Ch6.S1.I1' class='ltx_itemize'>
<li id='Ch6.S1.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>Write a function apply that takes an image and a filter mask
as input and returns the convolution of the two. Use either with-loops
or axis-control notation to achieve this. Take care of boundary
conditions when implementing the convolution.</p>
</li>
<li id='Ch6.S1.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>Write a function sobel that takes an image as input and
applies <math id='Ch6.S1.I1.i2.p1.m1' class='ltx_Math' alttext='F_{x}' display='inline'><msub><mi>F</mi><mi>x</mi></msub></math> and <math id='Ch6.S1.I1.i2.p1.m2' class='ltx_Math' alttext='F_{y}' display='inline'><msub><mi>F</mi><mi>y</mi></msub></math> to the image. Furthermore, add <math id='Ch6.S1.I1.i2.p1.m3' class='ltx_Math' alttext='S_{x}' display='inline'><msub><mi>S</mi><mi>x</mi></msub></math> and <math id='Ch6.S1.I1.i2.p1.m4' class='ltx_Math' alttext='S_{y}' display='inline'><msub><mi>S</mi><mi>y</mi></msub></math>
with capping so that this function returns the final result of the Sobel
operation.</p>
</li>
<li id='Ch6.S1.I1.i3' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>Write functions gauss9 and gauss25 that take an
image as input and apply <math id='Ch6.S1.I1.i3.p1.m1' class='ltx_Math' alttext='G_{9}' display='inline'><msub><mi>G</mi><mn>9</mn></msub></math> and <math id='Ch6.S1.I1.i3.p1.m2' class='ltx_Math' alttext='G_{25}' display='inline'><msub><mi>G</mi><mn>25</mn></msub></math> to the image.</p>
</li>
<li id='Ch6.S1.I1.i4' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>Write a main function that reads in an image from
stdin, calls sobel, gaussBlur9 and
gaussBlur25 on this image and then write the results back to
stdout.</p>
</li>
</ul>
<p class='ltx_p'>You may want to use the following skeleton for your program:</p>
<figure id='LST43' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 43: Skeleton of sobel.sac</figcaption>
<a href='data:text/plain;base64,IHVzZSBTdHJ1Y3R1cmVzOiBhbGw7CiB1c2UgU3RkSU86IGFsbDsKIHVzZSBDbG9jazoge3RpbWUsIGdldHRpbWUsIGRpZmZ0aW1lfTsKCiAvKiBIZWxwZXIgdG8gd3JpdGUgbWF0cml4IHRvIHN0ZG91dCBpbiBwbGFpbiBtYXRyaXggZm9ybWF0LgogICAgVGhlIHByb2R1Y2VkIG91dHB1dCAobGV0J3Mgc2F5IG0uZGF0KSBjYW4gYmUgdXNlZCB3aXRoIGdudXBsb3QKICAgIGxpa2Ugc286CiAgICAgICAgIGdudXBsb3Q+IHBsb3QgIm0uZGF0IiBtYXRyaXggd2l0aCBpbWFnZSAgKi8KIHZvaWQgd3JpdGVNYXRyaXgoIGludFsuLC5dIG0pCiB7CiAgIGZvciAoeT0wOyB5PHNoYXBlKG0pWzFdOyB5KyspIHsKICAgICBmb3IgKHg9MDsgeDxzaGFwZShtKVswXTsgeCsrKSB7CiAgICAgICBwcmludGYoIiVkICIsIG1bW3gseV1dKTsKICAgICB9CiAgICAgcHJpbnRmKCJcb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IlxuRmluaXNoZWQgZmlsdGVyaW5nIGFmdGVyICVmc1xuIiwgZGlmZnRpbWUoZW5kLCBzdGFydCkpOwogICBmcHJpbnRmKHN0ZGVyciwgIlxuV3JpdGluZyByZXN1bHQgaW1hZ2UgLi4uXG4iKTsKICAgd3JpdGVNYXRyaXgoaW1nKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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'>Structures</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'>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;'>3</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'>Clock</span>:<span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>time</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>gettime</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>difftime</span>};
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</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><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Helper<span class='ltx_text ltx_lst_space'> </span>to<span class='ltx_text ltx_lst_space'> </span>write<span class='ltx_text ltx_lst_space'> </span>matrix<span class='ltx_text ltx_lst_space'> </span>to<span class='ltx_text ltx_lst_space'> </span>stdout<span class='ltx_text ltx_lst_space'> </span>in<span class='ltx_text ltx_lst_space'> </span>plain<span class='ltx_text ltx_lst_space'> </span>matrix<span class='ltx_text ltx_lst_space'> </span>format.</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text ltx_font_italic' style='color:#BFBFBF;'>6</span></span>
<span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>The</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>produced</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>output</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>(let’s</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>say</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>m.dat)</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>can</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>be</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>used</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>with</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>gnuplot</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text ltx_font_italic' style='color:#BFBFBF;'>7</span></span>
<span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>like</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>so:</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text ltx_font_italic' style='color:#BFBFBF;'>8</span></span>
<span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>gnuplot></span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>plot</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>”m.dat”</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>matrix</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>with</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>image</span><span class='ltx_text ltx_lst_space ltx_font_italic'> </span><span class='ltx_text ltx_font_italic'>*/</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'>void</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>writeMatrix</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'>m</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_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'>for</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>y</span>=0;<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</span><<span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>m</span>)[1];<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</span>++)<span class='ltx_text ltx_lst_space'> </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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>for</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>x</span>=0;<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</span><<span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>m</span>)[0];<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</span>++)<span class='ltx_text ltx_lst_space'> </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'>printf</span>(<span class='ltx_text ltx_lst_string'>”%d<span class='ltx_text ltx_lst_space'> </span>”</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>m</span>[[<span class='ltx_text ltx_lst_identifier'>x</span>,<span class='ltx_text ltx_lst_identifier'>y</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_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'>printf</span>(<span class='ltx_text ltx_lst_string'>”\n”</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_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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span>
<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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Convolution<span class='ltx_text ltx_lst_space'> </span>with<span class='ltx_text ltx_lst_space'> </span>given<span class='ltx_text ltx_lst_space'> </span>mask.<span class='ltx_text ltx_lst_space'> </span>*/</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'>inline</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'>apply</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'>mask</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'>img</span>)
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Implement<span class='ltx_text ltx_lst_space'> </span>convolution<span class='ltx_text ltx_lst_space'> </span>here.<span class='ltx_text ltx_lst_space'> </span>*/</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>24</span></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_keyword ltx_font_bold'>int</span>[.,.]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sobel</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'>img</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_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'>SY</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;'>28</span></span>
<span class='ltx_text ltx_lst_space'> </span>[1,<span class='ltx_text ltx_lst_space'> </span>2,<span class='ltx_text ltx_lst_space'> </span>1],<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>0],<span class='ltx_text ltx_lst_space'> </span>[-1,<span class='ltx_text ltx_lst_space'> </span>-2,<span class='ltx_text ltx_lst_space'> </span>-1]
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>30</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Complete<span class='ltx_text ltx_lst_space'> </span>this<span class='ltx_text ltx_lst_space'> </span>function<span class='ltx_text ltx_lst_space'> </span>here.<span class='ltx_text ltx_lst_space'> </span>*/</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>31</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>32</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>33</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'>gaussBlur9</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'>img</span>)
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>34</span></span>
<span class='ltx_text ltx_lst_space'> </span>{
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>35</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Complete<span class='ltx_text ltx_lst_space'> </span>this<span class='ltx_text ltx_lst_space'> </span>function<span class='ltx_text ltx_lst_space'> </span>here.<span class='ltx_text ltx_lst_space'> </span>*/</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>36</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>37</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>38</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'>gaussBlur25</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'>img</span>)
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>39</span></span>
<span class='ltx_text ltx_lst_space'> </span>{
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>40</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Complete<span class='ltx_text ltx_lst_space'> </span>this<span class='ltx_text ltx_lst_space'> </span>function<span class='ltx_text ltx_lst_space'> </span>here.<span class='ltx_text ltx_lst_space'> </span>*/</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>41</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>42</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>43</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'>time</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>timestamp</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'>img</span>)
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>44</span></span>
<span class='ltx_text ltx_lst_space'> </span>{
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>45</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>(<span class='ltx_text ltx_lst_identifier'>img</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>gettime</span>());
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>46</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>47</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>48</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>()
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>49</span></span>
<span class='ltx_text ltx_lst_space'> </span>{
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>50</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>fprintf</span>(<span class='ltx_text ltx_lst_identifier'>stderr</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”\nReading<span class='ltx_text ltx_lst_space'> </span>image<span class='ltx_text ltx_lst_space'> </span>in<span class='ltx_text ltx_lst_space'> </span>Fibre<span class='ltx_text ltx_lst_space'> </span>format…\n”</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>51</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>img</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>FibreScanIntArray</span>(<span class='ltx_text ltx_lst_identifier'>stdin</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>52</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>53</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>fprintf</span>(<span class='ltx_text ltx_lst_identifier'>stderr</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”\nApplying<span class='ltx_text ltx_lst_space'> </span>filter<span class='ltx_text ltx_lst_space'> </span>…\n”</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>54</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>img</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>start</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>timestamp</span>(<span class='ltx_text ltx_lst_identifier'>img</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>55</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>img</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sobel</span>(<span class='ltx_text ltx_lst_identifier'>img</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>56</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>img</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>end</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>timestamp</span>(<span class='ltx_text ltx_lst_identifier'>img</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>57</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>58</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>Call<span class='ltx_text ltx_lst_space'> </span>the<span class='ltx_text ltx_lst_space'> </span>other<span class='ltx_text ltx_lst_space'> </span>filters<span class='ltx_text ltx_lst_space'> </span>here.<span class='ltx_text ltx_lst_space'> </span>*/</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>59</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>60</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>fprintf</span>(<span class='ltx_text ltx_lst_identifier'>stderr</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”\nFinished<span class='ltx_text ltx_lst_space'> </span>filtering<span class='ltx_text ltx_lst_space'> </span>after<span class='ltx_text ltx_lst_space'> </span>%fs\n”</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>difftime</span>(<span class='ltx_text ltx_lst_identifier'>end</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>start</span>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>61</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>fprintf</span>(<span class='ltx_text ltx_lst_identifier'>stderr</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”\nWriting<span class='ltx_text ltx_lst_space'> </span>result<span class='ltx_text ltx_lst_space'> </span>image<span class='ltx_text ltx_lst_space'> </span>…\n”</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>62</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>writeMatrix</span>(<span class='ltx_text ltx_lst_identifier'>img</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>63</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>64</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;'>65</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Compile your source code with and without the option -t mt_pth option for
multi-threaded execution and experiment with various thread counts. On faster
machines it might be necessary to apply the filter multiple times (copy and
paste line 55 a couple of times) to see measurable speed-ups.</p>
<p class='ltx_p'>NB: The Fibre format encodes, in addition to the raw data, shape information.
By using FibreScanIntArray this program is able process 2D images of any
size and it is not fixed to statically known input sizes.</p>
<figure id='Ch6.F1' class='ltx_figure'>
<table style='width:100%;'>
<tr>
<td class='ltx_subgraphics'><img src='data:image/png;base64,b'iVBORw0KGgoAAAANSUhEUgAAASoAAAGlEAQAAAC3Ra/qAAAAAmJLR0TxSrMc0AAAAJcEhZcwAAAJAAAACQAPFFumsAAAAHdElNRQfmAw4QNAOVs17hAABEWElEQVR42u3dd5QUxdrH8W/35NkcYIEFFFAUE5hQEBMmTChmr+nqa0Yx55zFgGLWq2K6ihGzGEBRMYuKkQwSJLPLptlJ9f5R42VFZjawS3B/n3PmiDs9nfvpp6qrq0BEREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREREQkE0e7AHq8VXxV5KyNP9CekPVJwZPLDpiwy29XtIZt9epww5y5F5xXc8UOTQ/au4IzBHx9wHc7eHzgGwK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iIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiISGP9PxjJuC0GbGWrAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIyLTAzLTE0VDE2OjUyOjAzKzAwOjAwq632VgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMi0wMy0xNFQxNjo1MjowMyswMDowMNrwTuoAAAAtdEVYdGljYzpjb3B5cmlnaHQAQ29weXJpZ2h0IEFydGlmZXggU29mdHdhcmUgMjAxMQi6xbQAAAAxdEVYdGljYzpkZXNjcmlwdGlvbgBBcnRpZmV4IFNvZnR3YXJlIHNSR0IgSUNDIFByb2ZpbGUTDAGGAAAAIHRFWHRwZGY6SGlSZXNCb3VuZGluZ0JveAA1OTV4ODQyKzArMDsfVVwAAAATdEVYdHBkZjpWZXJzaW9uAFBERi0xLjO6Vf/0AAAAAElFTkSuQmCC id='Ch6.F1.g1' class='ltx_graphics ltx_centering' width='298' height='421' alt='The '></td>
<td class='ltx_subgraphics'><img src='data:image/png;base64,b'iVBORw0KGgoAAAANSUhEUgAAASoAAAGlEAQAAAC3Ra/qAAAAAmJLR0TxSrMc0AAAAJcEhZcwAAAJAAAACQAPFFumsAAAAHdElNRQfmAw4QNAOVs17hAABuXklEQVR42uzddZgdRdbH8c+4JRN3V4gTCBJcF3d3WBZYYIFFF/fFYXF2cXd3CwkSCAmQkBB3l0kmmUnGpd4/engzCSyy6C71fZ77zHR33a7uut2/Pl116hwikUgkEolEIpFIJBKJRCKRSCQSiUQikUgkEolEIpFIJBKJRCKRSCQSiUQikUgkEolEIpFIJBKJRCKRSCQSiUQikUgkEolEIpFIJBK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IHNSR0IgSUNDIFByb2ZpbGUTDAGGAAAAIHRFWHRwZGY6SGlSZXNCb3VuZGluZ0JveAA1OTV4ODQyKzArMDsfVVwAAAATdEVYdHBkZjpWZXJzaW9uAFBERi0xLjO6Vf/0AAAAAElFTkSuQmCC'' id='Ch6.F1.g2' class='ltx_graphics ltx_centering' width='298' height='421' alt='The '></td>
</tr>
</table>
<figcaption class='ltx_caption'>Figure 6.1: The SaC logo before (left) and after (right) edge detection</figcaption>
</figure>
</section>
<section id='Ch6.S2' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
6.2 Lesson 8: Computing Mandelbrot Images</h4>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 30. </h6>
<p class='ltx_p'>This exercise is about creating a basic implementation for computing mandelbrot
images.</p>
<ol id='Ch6.S2.I1' class='ltx_enumerate'>
<li id='Ch6.S2.I1.i1' class='ltx_item' style='list-style-type:none;'>
1.
<p class='ltx_p'>To get started, you may want to use the files
mandelbrot_start.sac and Fractal_tier1.sac which, in
essence, contain the IO-code for visualising the mandelbrot pictures. A
first running version can be obtained by implementing the missing
function bodies in Fractal_tier1_empty.sac:</p>
<ul id='Ch6.S2.I1.i1.I1' class='ltx_itemize'>
<li id='Ch6.S2.I1.i1.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>escapeTime which implements the iteration on
arrays of complex numbers, and</p>
</li>
<li id='Ch6.S2.I1.i1.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>genComplexArray which computes a two-dimensional
array of complex numbers that represent a descritisation of
<math id='Ch6.S2.I1.i1.I1.i2.p1.m1' class='ltx_Math' alttext='\mathbb{C}^{2}' display='inline'><msup><mi>ℂ</mi><mn>2</mn></msup></math>.</p>
</li>
</ul>
</li>
<li id='Ch6.S2.I1.i2' class='ltx_item' style='list-style-type:none;'>
2.
<p class='ltx_p'>Waiting for the final picture can be rather unpleasant if it is not
clear whether the chosen fraction of <math id='Ch6.S2.I1.i2.p1.m1' class='ltx_Math' alttext='\mathbb{C}^{2}' display='inline'><msup><mi>ℂ</mi><mn>2</mn></msup></math> yields an
interesting picture and the iteration limit is high. therefore, as a
first extension, try to modify the main function in
mandelbrot_start.sac so that it computes the mandelbrot picture
with increasing resolution without changing the overall size of the
picture.</p>
<p class='ltx_p'>Compute resolutions [5,5], [10,10],…,
[320,320] and display them consecutively in a
[320,320] display by replicating the found values
accordingly.</p>
<p class='ltx_p'>Hint: define a function stretchRgb which takes an array of
type color[.,.] and an integer stretching factor
stretch and replicates each element of the array into a
square of shape [stretch, stretch].</p>
</li>
<li id='Ch6.S2.I1.i3' class='ltx_item' style='list-style-type:none;'>
3.
<p class='ltx_p'>The function intArrayToMonochrome maps all escape values
into a color by means of a clut. Can you express this operation without
a with-loop?</p>
<p class='ltx_p'>Hint: You may find inspiration in one of the earlier tasks!</p>
</li>
<li id='Ch6.S2.I1.i4' class='ltx_item' style='list-style-type:none;'>
4.
<p class='ltx_p'>Try using the compiler option -t mt_pth to experiment with multi-core
machines!</p>
</li>
<li id='Ch6.S2.I1.i5' class='ltx_item' style='list-style-type:none;'>
5.
<p class='ltx_p'>Try using the compiler option -t cuda to experiment with graphics
cards!</p>
</li>
<li id='Ch6.S2.I1.i6' class='ltx_item' style='list-style-type:none;'>
6.
<p class='ltx_p'>Try using the compiler option -b11:cyc to inspect the
high-level, optimised intermediate code.</p>
</li>
</ol>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 31. </h6>
<p class='ltx_p'>In this exercise, we improve the way the colours are chosen in order to obtain
smoother transitions. We will use a common approach referred to as
<em class='ltx_emph ltx_font_italic'>normalized iteration counts</em>. A normalized iteration count for a point in
the complex plane <math id='Thmtheorem31.p1.m1' class='ltx_Math' alttext='z' display='inline'><mi>z</mi></math> is computed by using the iteration count <math id='Thmtheorem31.p1.m2' class='ltx_Math' alttext='t' display='inline'><mi>t</mi></math> and the value
at that position <math id='Thmtheorem31.p1.m3' class='ltx_Math' alttext='z_{t}' display='inline'><msub><mi>z</mi><mi>t</mi></msub></math> during the final iteration. Using these two values, the
normalized iteration count is defined as <math id='Thmtheorem31.p1.m4' class='ltx_Math' alttext='t_{n}:=(t+1)-\log_{2}(\log_{2}(|z_{t}|))' display='inline'><mrow><msub><mi>t</mi><mi>n</mi></msub><mo>:=</mo><mrow><mrow><mo stretchy='false'>(</mo><mrow><mi>t</mi><mo>+</mo><mn>1</mn></mrow><mo stretchy='false'>)</mo></mrow><mo>-</mo><mrow><msub><mi>log</mi><mn>2</mn></msub><mo></mo><mrow><mo stretchy='false'>(</mo><mrow><msub><mi>log</mi><mn>2</mn></msub><mo></mo><mrow><mo stretchy='false'>(</mo><mrow><mo stretchy='false'>|</mo><msub><mi>z</mi><mi>t</mi></msub><mo stretchy='false'>|</mo></mrow><mo stretchy='false'>)</mo></mrow></mrow><mo stretchy='false'>)</mo></mrow></mrow></mrow></mrow></math>
for those values that escape and as <math id='Thmtheorem31.p1.m5' class='ltx_Math' alttext='0' display='inline'><mn>0</mn></math> otherwise.</p>
<ol id='Ch6.S2.I2' class='ltx_enumerate'>
<li id='Ch6.S2.I2.i1' class='ltx_item' style='list-style-type:none;'>
1.
<p class='ltx_p'>The module Fractal_tier2.sac contains stubs for the missing
functionality required in this exercise:</p>
<ul id='Ch6.S2.I2.i1.I1' class='ltx_itemize'>
<li id='Ch6.S2.I2.i1.I1.i1' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>normalizedIterationCount which implements the
normalisation of iteration counts by taking the final computed
value into account.</p>
<p class='ltx_p'>Hint: The function escapeTime only computes the
number of iterations before the value at a given position
escapes. To normalize these, the final value at that position is
required, as well. For this, we have provided a function
escapeValue.</p>
</li>
<li id='Ch6.S2.I2.i1.I1.i2' class='ltx_item' style='list-style-type:none;'>
•
<p class='ltx_p'>doubleArrayToRGB maps the normalized iteration
counts, which are double values, to an RGB colour-triple. To
derive an RGB value, first scale all values such that they are
in the interval <math id='Ch6.S2.I2.i1.I1.i2.p1.m1' class='ltx_Math' alttext='0\leq x<360' display='inline'><mrow><mn>0</mn><mo>≤</mo><mi>x</mi><mo>«/mo><mn>360</mn></mrow></math>. This value can then be used as the
hue in the HSB model.</p>
<p class='ltx_p'>Hint: The module Color8 defines a function
Hsb2Rgb that converts a HSB color description into
its corresponding RGB representation.</p>
</li>
</ul>
</li>
</ol>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 32. </h6>
<p class='ltx_p'>In this exercise, we apply the filters from the previous case study to the
mandelbrot pictures. As before, we have provided stubs for the missing
functionality. For this exercise these can be found in the file
Stencil_tier3.sac.</p>
<ol id='Ch6.S2.I3' class='ltx_enumerate'>
<li id='Ch6.S2.I3.i1' class='ltx_item' style='list-style-type:none;'>
1.
<p class='ltx_p'>Implement the functions apply, sobelEdges,
gaussBlur and gaussBlur25 as described in the
previous case study.</p>
</li>
<li id='Ch6.S2.I3.i2' class='ltx_item' style='list-style-type:none;'>
2.
<p class='ltx_p'>The three filters described above only operate on a single channel,
e.g. a gray-scale image. To lift these to colour images, implement a
corresponding function for each filter that applies the filter to each
colour separately.</p>
</li>
</ol>
</section>
</section>
</section>
<section id='Pt2' class='ltx_part'>
<h2 class='ltx_title ltx_title_part'>
Part II Trails Covering More Advanced Features of SaC
</h2>
<section id='Ch7' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 7 Treasures in the Standard Library</h3>
<p class='ltx_p'>This trail gives the reader a tour through the main components of the standard
library. For the time being, it is merely a collection of points of interest.
We hope that this will evolve over time.</p>
<p class='ltx_p'>So far, we only have one lesson on <em class='ltx_emph ltx_font_italic'>benchmarking</em> in SaC.</p>
<section id='Ch7.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
7.1 Lesson: Benchmarking SaC Programs</h4>
<p class='ltx_p'>Following the case studies in the previous section, the question
arises what the best technique for benchmarking SaC programs
might be.
The easiest way, of course, is by utilising the Unix time
(or timex) command when starting the to be benchmarked
program on the command line of the system shell.
The disadvantage of this technique is that the whole program is benchmarked,
and run time spent in setup or shutdown parts of the code is indistinguishable
from time spent in the more relevant parts of a program.</p>
<p class='ltx_p'>For many program codes exposing in one way or another an iterative nature,
this is often still the technique of choice.
One simply measures whole program runtime for x iterations and for
y iterations and then derives the average time per iteration by
dividing the difference in runtimes by the difference in iterations computed.
Under the (likely) assumption that setup and shutdown overhead is constant
in the number of iterations, this technique allows for simple and still realistic
benchmarking without augmenting the source code for benchmarking.</p>
<p class='ltx_p'>If the above technique for one or another reason is insufficient, the SaC
standard library provides access to the system real time clock via the classes
RTClock and RTimer.
The code example below illustrates how this works.</p>
<figure id='LST44' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 44: Benchmarking with the real time clock</figcaption>
<a href='data:text/plain;base64,IHVzZSBSVENsb2NrOiBhbGw7CiB1c2UgUlRpbWVyOiBhbGw7CgogaW50IG1haW4oKQogewogICBpbnQgc2VjczsKICAgaW50IG5zZWNzOwogICBkb3VibGUgdGltZTsKCiAgIHRpbWVyID0gY3JlYXRlUlRpbWVyKCk7CgogICBzdGFydFJUaW1lcih0aW1lcik7CgogICBkb1JlbGV2YW50Q29tcHV0YXRpb24oLyogLi4uICAqLyk7CgogICBzdG9wUlRpbWVyKHRpbWVyKTsKCiAgIHNlY3MsIG5zZWNzID0gZ2V0UlRpbWVySW50cyh0aW1lcik7CiAgIHRpbWUgPSBnZXRSVGltZXJEYmwodGltZXIpOwoKICAgZGVzdHJveVJUaW1lcih0aW1lcik7CiB9'>⬇</a>
<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'>RTClock</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'>RTimer</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;'>3</span></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>()
<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>{
<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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>secs</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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>nsecs</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_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>time</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</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><span class='ltx_text ltx_lst_identifier'>timer</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>createRTimer</span>();
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</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><span class='ltx_text ltx_lst_identifier'>startRTimer</span>(<span class='ltx_text ltx_lst_identifier'>timer</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_identifier'>doRelevantComputation</span>(<span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></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'>stopRTimer</span>(<span class='ltx_text ltx_lst_identifier'>timer</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></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'>secs</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>nsecs</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>getRTimerInts</span>(<span class='ltx_text ltx_lst_identifier'>timer</span>);
<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'>time</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>getRTimerDbl</span>(<span class='ltx_text ltx_lst_identifier'>timer</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>destroyRTimer</span>(<span class='ltx_text ltx_lst_identifier'>timer</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>}
</figure>
<p class='ltx_p'>First, we make all symbols from the name spaces RTClock and RTimer
available to our program via the use statements in
lines 1 and 2.
Access to the real time clock is indirect through the creation of one or more
real clock timers.
Such a timer comes into existance through execution of the createRTimer
function.
Timers can (repeatedly) be started and stopped using the functions startRTimer
and stopRTimer, respectively.
If a timer is started and stopped multiple times, elapsed times are accumulated.
Where this is not desirable, a real clock timer can be reset using the
resetRTimer function.
While the real timers keep their information in an opaque format, two functions
support the conversion of timer information into standard SaC values.
The function getRTimerInts yields two integer values, specifying elapsed
seconds and nanoseconds, respectively;
the function getRTimerDbl yields elapsed time in seconds as a double
precision floating point value.</p>
<p class='ltx_p'>Note that starting an already running timer has no effect.
Likewise stopping a non-running timer has no effect either.
Enquiring the state of a running timer yields the timer’s value
when it was started.
Last not least, a timer should be removed when it is no longer used or needed
by calling the destroyRTimer function.</p>
<p class='ltx_p'>Benchmarking <em class='ltx_emph ltx_font_italic'>functional</em> programs through starting, stopping and
enquiring timers is not without a conceptual problem:
In the absence of any data dependency between the starting and the stopping of
the timer on the one side and the relevant computation to be benchmarked on the
other side, the compiler is free to change the order of these three parts of
the computation.
And, an aggressively optimising compiler like sac2c may actually do this,
which, of course, would render the timing completely useless.
To safely prevent the compiler from changing the order of computations, we need
to apply a little trick:</p>
<figure id='LST45' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 45: Binding function to timer</figcaption>
<a href='data:text/plain;base64,IC8qIHJldHVybi10eXBlICAqLyBkb1JlbGV2YW50Q29tcHV0YXRpb24oLyogLi4uICAqLykKIHsKICAgLyogLi4uICAqLwogICB0b3VjaChSVGNsb2NrKTsKICAgLyogLi4uICAqLwogfQ=='>⬇</a>
<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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>return-type<span class='ltx_text ltx_lst_space'> </span>*/</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>doRelevantComputation</span>(<span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</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_identifier'>touch</span>(<span class='ltx_text ltx_lst_identifier'>RTclock</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><span class='ltx_text ltx_lst_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</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>}
</figure>
<p class='ltx_p'>Somewhere in the definition of the doRelevantComputation you need
to touch the real time clock as shown above.
And, you must not declare the work function as an inline function.</p>
<p class='ltx_p'>Why this helps warrants further explanation; it is deeply connected to
the SaC I/O concept, which is based on a variant of uniqueness typing.</p>
</section>
</section>
<section id='Ch8' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 8 User Defined Types</h3>
<p class='ltx_p'>In this trail covers the definition and use of user-defined types in SaC.</p>
</section>
<section id='Ch9' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 9 Dealing with I/O and State in General</h3>
<p class='ltx_p'>SaC supports an explicit notion of stateful objects. All stateful objects need to be associated
to an explicit stateful type. Conceptually, such stateful objects need to be passed around in a
linear fashion in order to maintain the side-effect free nature of SaC.</p>
<p class='ltx_p'>
A note for Language design freaks:
Under the hood these types are uniqueness types very similar to those of Clean.
</p>
<p class='ltx_p'>To relieve programmers form the burden to pass around states explicitly whenever they are needed,
SaC offers syntactic sugar, referred-to as <em class='ltx_emph ltx_font_italic'>reference parameters</em> and <em class='ltx_emph ltx_font_italic'>global objects</em>.
These two mechanisms enable state modifications that have a rather C-like feel and touch,
as if SaC would cater for side-effects in general.
Nevertheless, they are being translated away into a purely side-effect free form.</p>
<section id='Ch9.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
9.1 Lesson: States and Objects — the basics</h4>
<p class='ltx_p'>In most languages, classes are based on special record types containing instance
variables and methods. In SaC, classes are based on modules, as they serve
the same need: A module pairs functions and types to a group. Instead of
instance variables, classes in SaC have a special class type that builds up
an instance of a class. This class type is a user-defined type similar to any other
user defined type, however, it implicitly carries a notion of being stateful, i.e.,
it is a uniqueness type.</p>
<p class='ltx_p'>The following example shows the class Counter:</p>
<figure id='LST46' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 46: class Counter</figcaption>
<a href='data:text/plain;base64,IGNsYXNzIENvdW50ZXI7CgogY2xhc3N0eXBlIGludDsKCiB1c2UgQXJyYXk6IHsrfTsKCiBleHBvcnQgYWxsOwoKIENvdW50ZXIgY3JlYXRlQ291bnRlcigpCiB7CiAgIHJldHVybiAoQ291bnRlcikoMCk7CiB9CgogQ291bnRlciBpbmNyZW1lbnQgKENvdW50ZXIgYykKIHsKICAgcmV0dXJuIChDb3VudGVyKSAoKGludCkoYykgKyAxKTsKIH0KCiBpbnQgZ2V0VmFsdWUoQ291bnRlciBjKQogewogICByZXR1cm4gKGludCljOwogfQo='>⬇</a>
<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'>class</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Counter</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>classtype</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</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><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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></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'>export</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;'>8</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><span class='ltx_text ltx_lst_identifier'>Counter</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>createCounter</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_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>(<span class='ltx_text ltx_lst_identifier'>Counter</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</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><span class='ltx_text ltx_lst_identifier'>Counter</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>increment</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>Counter</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>c</span>)
<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_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>(<span class='ltx_text ltx_lst_identifier'>Counter</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_identifier'>c</span>)<span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span>1);
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span>
<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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>getValue</span>(<span class='ltx_text ltx_lst_identifier'>Counter</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>c</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</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>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>)<span class='ltx_text ltx_lst_identifier'>c</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>}
</figure>
<p class='ltx_p'>A class file starts with the class keyword, followed by the name of the
class. Another keyword unique to classes is classtype. The statement in
line 3 defines int as the classtype of class Counter.
Other than that, a class is constructed liek any module.
It can use or import from other modules or classes, and it can provide and import its own types
and functions.</p>
<p class='ltx_p'>The function createCounter generates an object of type Counter.
Note here, that the type cast is essential. It transforms the integer value
into a stateful object of type Counter.
The function increment increments the value of Counter instance
c and returns the new, modified version.
Again, we see a cast from the stateful object c of type Counter
into an integer object for which + is defined in the module Array.
The incremented integer value subsequently is transformed into a stateful Counter
object directly thereafter.
Finally, we have a function getValue which returns the current integer value of the
provided Counter object.</p>
<p class='ltx_p'>Let us now look at a simple use of the class Counter:</p>
<figure id='LST47' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 47: using Counter</figcaption>
<a href='data:text/plain;base64,IHVzZSBDb3VudGVyOmFsbDsKCiBpbnQgbWFpbigpCiB7CiAgICBjID0gY3JlYXRlQ291bnRlciAoKTsKICAgIGMgPSBpbmNyZW1lbnQgKGMpOwogICAgU3RkSU86OnByaW50IChnZXRWYWx1ZSAoYykpOwoKICAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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'>Counter</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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>()
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>createCounter</span><span class='ltx_text ltx_lst_space'> </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'>c</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>increment</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>print</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>getValue</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</span>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</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><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;'>10</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>Now try to duplicate line 7.
The compiler needs to reject the second call to
getValue because the object c
is used more than once!</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 33. </h6>
<p class='ltx_p'>Define a new version of
getValue which returns both, the
(unmodified) Counter c and the current
integer value.</p>
<section id='Ch9.S1.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
9.1.1 Reference Parameters</h5>
<p class='ltx_p'>The function getValue from the previous exercise
shows that in most cases we want stateful objects that are passed
to functions as arguments to be returned as well, irrespective of whether
they have been modified or not.
To avoid the necessity of specifying sequences of such function calls as</p>
<figure id='LST48' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 48: explicit passing of state</figcaption>
<a href='data:text/plain;base64,IC4uLgogICAgYyA9IGluY3JlbWVudCAoYyk7CiAgICBjLCB2MSA9IGdldFZhbHVlIChjKTsKICAgIGMsIHYyID0gZ2V0VmFsdWUgKGMpOwogLi4u'>⬇</a>
<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_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_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>increment</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </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'>v1</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>getValue</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</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_identifier'>c</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>v2</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>getValue</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</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>…
</figure>
<p class='ltx_p'>SaC offers a syntactical shortcut, named <em class='ltx_emph ltx_font_italic'>Reference Parameters</em>.
The idea is that an explicit return of a stateful object can be syntactically omitted
if the formal parameter is annotated by the symbol &.
For our example, this can be done by defining
increment and getValue like this:</p>
<figure id='LST49' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 49: Reference Parameter</figcaption>
<a href='data:text/plain;base64,IC4uLgogIHZvaWQgaW5jcmVtZW50IChDb3VudGVyICZjKQogIHsKICAgICBjID0gKENvdW50ZXIpKChpbnQpYyArIDEpOwogIH0KCiAgaW50IGdldFZhbHVlKENvdW50ZXIgJmMpCiAgewogICAgIHZhbCA9IChpbnQpIGM7CiAgICAgYyA9IChDb3VudGVyKSB2YWw7CiAgICAgcmV0dXJuIHZhbDsKICB9CiAuLi4='>⬇</a>
<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_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_identifier'>void</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>increment</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>Counter</span><span class='ltx_text ltx_lst_space'> </span>&<span class='ltx_text ltx_lst_identifier'>c</span>)
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </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_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>Counter</span>)((<span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>)<span class='ltx_text ltx_lst_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span>1);
<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>}
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>getValue</span>(<span class='ltx_text ltx_lst_identifier'>Counter</span><span class='ltx_text ltx_lst_space'> </span>&<span class='ltx_text ltx_lst_identifier'>c</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_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'>val</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'>int</span>)<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>c</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'>c</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>Counter</span>)<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>val</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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>val</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>}
<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>…
</figure>
<p class='ltx_p'>With these definitions, we can now use the Counter class as follows:
</p>
<figure id='LST50' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 50: using Reference Parameters</figcaption>
<a href='data:text/plain;base64,IHVzZSBDb3VudGVyOmFsbDsKCiBpbnQgbWFpbigpCiB7CiAgICBjID0gY3JlYXRlQ291bnRlciAoKTsKICAgIGluY3JlbWVudCAoYyk7CiAgICBpbmNyZW1lbnQgKGMpOwogICAgU3RkSU86OnByaW50IChnZXRWYWx1ZSAoYykpOwogICAgU3RkSU86OnByaW50IChnZXRWYWx1ZSAoYykpOwoKICAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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'>Counter</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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>()
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>createCounter</span><span class='ltx_text ltx_lst_space'> </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'>increment</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</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'>increment</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>print</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>getValue</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>print</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>getValue</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>c</span>));
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></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_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>}
</figure>
</section>
<section id='Ch9.S1.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
9.1.2 Global Objects</h5>
<p class='ltx_p'>When looking at the previous use of the class Counter,
we can see that the introduction of reference parameters enables program
specifications that look very “imperative”.
The idea of leaving out explicit passing of state can be driven even further.
In SaC, we also have a mechanism for omitting stateful objects as parameters which are
needed within a function body. For that purpose, SaC introduces the notion of <em class='ltx_emph ltx_font_italic'>Global Objects</em>.
Global objects are stateful
objects that are generated once before the program execution starts and
that are available everywhere within the program for inspection or modification.
While this seems to finally unleash side-effects, in fact the compiler
inserts the missing passing of states throughout the program as needed.</p>
<p class='ltx_p ltx_align_center'>
A note for compiler implementation freaks:
If you want to find out what the compiler actually does,
you may want to inspect the program after all objects have been inserted by the compiler.
This can be done by looking at the output when compiling with the flag -btc.
If you want to find out about further break options, check sac2c -help.
</p>
<p class='ltx_p'>We can extend our counter example by a global counter as follows:</p>
<figure id='LST51' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 51: class Counter extended</figcaption>
<a href='data:text/plain;base64,IGNsYXNzIENvdW50ZXI7CgogLi4uCiBleHBvcnQgYWxsOwoKIG9iamRlZiBDb3VudGVyIHRoZUNvdW50ZXIgPSBjcmVhdGVDb3VudGVyKCk7Cgogdm9pZCBpbmNyZW1lbnQgKCkKIHsKICAgaW5jcmVtZW50ICh0aGVDb3VudGVyKTsKIH0KCiBpbnQgZ2V0VmFsdWUgKCkKIHsKICAgcmV0dXJuIGdldFZhbHVlICh0aGVDb3VudGVyKTsKIH0KIC4uLg=='>⬇</a>
<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'>class</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Counter</span>;
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </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_identifier'>export</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;'>5</span></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'>objdef</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Counter</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>theCounter</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>createCounter</span>();
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</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><span class='ltx_text ltx_lst_identifier'>void</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>increment</span><span class='ltx_text ltx_lst_space'> </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_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'>increment</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>theCounter</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</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><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'>getValue</span><span class='ltx_text ltx_lst_space'> </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_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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>getValue</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>theCounter</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span>
<span class='ltx_text ltx_lst_space'> </span>…
</figure>
<p class='ltx_p'>With this extension,
applications of increment () become possible within arbitrary
function bodies. For example, we can specify:</p>
<figure id='LST52' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 52: using the global counter</figcaption>
<a href='data:text/plain;base64,IHVzZSBBcnJheTogYWxsOwogdXNlIENvdW50ZXI6IGFsbDsKCiBpbnQgZm9vIChpbnQgbikKIHsKICAgIGluY3JlbWVudCAoKTsKICAgIHJldHVybiBuKzE7CiB9CgogaW50IG1haW4oKQogewogICAgc3VtID0gMDsKICAgIGZvciAoaT0wOyBpPDIwOyApCiAgICAgICBpID0gZm9vIChpKTsKCiAgICBTdGRJTzo6cHJpbnQgKGdldFZhbHVlICgpKTsKICAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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'>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'>Counter</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;'>3</span></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'>foo</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'>n</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>{
<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'>increment</span><span class='ltx_text ltx_lst_space'> </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_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>n</span>+1;
<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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</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><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;'>11</span></span>
<span class='ltx_text ltx_lst_space'> </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><span class='ltx_text ltx_lst_identifier'>sum</span><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;'>13</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>for</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>i</span>=0;<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>i</span><20;<span class='ltx_text ltx_lst_space'> </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'>i</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>foo</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>i</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>print</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_identifier'>getValue</span><span class='ltx_text ltx_lst_space'> </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><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;'>18</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
</section>
</section>
</section>
<section id='Ch10' class='ltx_chapter'>
<h3 class='ltx_title ltx_title_chapter'>
Chapter 10 Interfacing with Other Languages</h3>
<p class='ltx_p'>This trail explains on how to use SaC libraries from other languages
and how to integrate foreign libraries into SaC programs.</p>
<p class='ltx_p'>So far, we have four lessons. One that explains how to utilise
<em class='ltx_emph ltx_font_italic'>C functions and libraries in SaC</em> and three more lessons that explain how
to call SaC from the languages C, C++, and Fortran, respectively.</p>
<section id='Ch10.S1' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
10.1 Lesson: Calling C from SaC
</h4>
<section id='Ch10.S1.SS1' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
10.1.1 Using C in the small</h5>
<p class='ltx_p'>As a starting point, let us assume that you do have a C-library that you would like
to use from SaC.
Whether you do have access to the library’s sources or not does not matter at all.
All you need is an object file or a library file and knowledge about the signatures
of the functions that are contained in it.
Typically, you will have a header file containing the needed extern declarations.</p>
<p class='ltx_p'>For example, you may have a file simple.h which looks like this:</p>
<figure id='LST53' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 53: Simple example header file in C</figcaption>
<a href='data:text/plain;base64,ICNpZm5kZWYgU0lNUExFX0gKICNkZWZpbmUgU0lNUExFX0gKCiBleHRlcm4gaW50IGFkZChpbnQgeCwgaW50IHkpOwoKICNlbmRpZg=='>⬇</a>
<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_identifier'>ifndef</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>SIMPLE_H</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_identifier'>define</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>SIMPLE_H</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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_identifier'>extern</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'>add</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'>x</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'>y</span>);
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></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'>endif</span>
</figure>
<p class='ltx_p'>We furthermore assume that you have an object file simple.o that contains
an implementation of this function.
You can generate a suitable object file by putting
</p>
<figure id='LST54' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 54: add function in C</figcaption>
<a href='data:text/plain;base64,ICNpbmNsdWRlICJzaW1wbGUuaCIKCiBpbnQgYWRkKGludCB4LCBpbnQgeSkKIHsKICAgcmV0dXJuIHggKyB5OwogfQ=='>⬇</a>
<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_identifier'>include</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.h”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</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'>add</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'>x</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'>y</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</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><span class='ltx_text ltx_lst_identifier'>x</span><span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</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>}
</figure>
<p class='ltx_p'>into a file simple.c and compiling it by gcc -c simple.c or similar.</p>
<p class='ltx_p'>Now, if you want to make this function available in SaC, all you need to do is to add
an external declaration with some additional information on where to find the object file
into your SaC program. For example:</p>
<figure id='LST55' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 55: add function used by SaC</figcaption>
<a href='data:text/plain;base64,IGV4dGVybmFsIGludCBhZGQoaW50IHgsIGludCB5KTsKICAgI3ByYWdtYSBsaW5rb2JqICJzaW1wbGUubyIKCiBpbnQgbWFpbigpCiB7CiAgIFN0ZElPOjpwcmludGYoIjEgcGx1cyAxIGVxdWF0ZXMgdG8gJWRcbiIsIGFkZCggMSwgMSkpOwoKICAgcmV0dXJuIDA7CiB9'>⬇</a>
<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'>external</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'>add</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'>x</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'>y</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'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>linkobj</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.o”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></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>()
<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>{
<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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”1<span class='ltx_text ltx_lst_space'> </span>plus<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_space'> </span>equates<span class='ltx_text ltx_lst_space'> </span>to<span class='ltx_text ltx_lst_space'> </span>%d\n”</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>add</span>(<span class='ltx_text ltx_lst_space'> </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;'>7</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><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>}
</figure>
<p class='ltx_p'>If you compile this with sac2c you will obtain an executable which should yield the expected
result.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 34. </h6>
<p class='ltx_p'>Note here, that the SaC compiler has no guarantees that the signature that has been provided here
indeed matches your implementation. Try what happens if you wrongly declare both arguments of add
to be of type double.</p>
<p class='ltx_p'>To get more type safety here, you can share the C header file with the SaC compiler by
using yet another pragma:</p>
<figure id='LST56' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 56: add function used by SaC</figcaption>
<a href='data:text/plain;base64,IGV4dGVybmFsIGludCBhZGQoZG91YmxlIHgsIGRvdWJsZSB5KTsKICAgI3ByYWdtYSBsaW5rb2JqICJzaW1wbGUubyIKICAgI3ByYWdtYSBoZWFkZXIgICJzaW1wbGUuaCIKCiBpbnQgbWFpbigpCiB7CiAgIFN0ZElPOjpwcmludGYoIjEgcGx1cyAxIGlzICVkXG4iLCBhZGQoIDEsIDEpKTsKCiAgIHJldHVybiAwOwogfQ=='>⬇</a>
<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'>external</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'>add</span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>x</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</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'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>linkobj</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.o”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span>#<span class='ltx_text ltx_lst_keyword ltx_font_bold'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>header</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.h”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</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><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;'>6</span></span>
<span class='ltx_text ltx_lst_space'> </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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”1<span class='ltx_text ltx_lst_space'> </span>plus<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_space'> </span>is<span class='ltx_text ltx_lst_space'> </span>%d\n”</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>add</span>(<span class='ltx_text ltx_lst_space'> </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;'>8</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><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;'>10</span></span>
<span class='ltx_text ltx_lst_space'> </span>}
</figure>
<p class='ltx_p'>If you compile this version the compiler will point out that it expected a function which satisfies</p>
<figure id='LST57' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 57: expected type</figcaption>
<a href='data:text/plain;base64,IGludCBhZGQgKGRvdWJsZSBTQUNsX3gsIGRvdWJsZSBTQUNsX3kpOw=='>⬇</a>
<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'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>add</span><span class='ltx_text ltx_lst_space'> </span>(<span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>SACl_x</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>SACl_y</span>);
</figure>
<p class='ltx_p'>and not the actually implemented one:</p>
<figure id='LST58' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 58: actual type</figcaption>
<a href='data:text/plain;base64,IGludCBhZGQoaW50IHgsIGludCB5KTs='>⬇</a>
<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'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>add</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'>x</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'>y</span>);
</figure>
<p class='ltx_p'>
A note for proper software engineers:
You always want to include your header file here; just to make sure that you
got the interface right!
</p>
<p class='ltx_p'>Sometimes, a given C function is supposed to return more than one value or the programmer wants to allow the function
to change a value in the calling context. This is typically implemented by passing a pointer to the to-be-changed
argument or to the expected extra return value as an argument.
Let us consider a slight variant of our simple example here:</p>
<figure id='LST59' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 59: addto function in C</figcaption>
<a href='data:text/plain;base64,ICNpbmNsdWRlICJzaW1wbGUuaCIKCiB2b2lkIGFkZHRvKGludCAqeCwgaW50IHkpCiB7CiAgICp4ICs9IHk7CiB9'>⬇</a>
<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_identifier'>include</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.h”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>void</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>addto</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'>x</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'>y</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_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span>
<span class='ltx_text ltx_lst_space'> </span>*<span class='ltx_text ltx_lst_identifier'>x</span><span class='ltx_text ltx_lst_space'> </span>+=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>y</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>}
</figure>
<p class='ltx_p'>Since SaC doe not have the notion of explicit memory or even side-effects, one may think that such a function
cannot be used from SaC. The key idea for enabling the use of this function is to disentangle the memory aspect from
the purely operational one. This still is an addition operation as before. The only difference is that the result
has been ”mapped“ into the first argument.
We can model this in SaC by telling the compiler that the this mapping of the result into the first argument actually
has taken place:</p>
<figure id='LST60' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 60: addto function used by SaC</figcaption>
<a href='data:text/plain;base64,IGV4dGVybmFsIGludCBhZGR0byhpbnQgeCwgaW50IHkpOwogICAjcHJhZ21hIGxpbmtvYmogICJzaW1wbGUubyIKICAgI3ByYWdtYSBoZWFkZXIgICAic2ltcGxlLmgiCiAgICNwcmFnbWEgbGlua3NpZ24gWzEsMSwyXQoKIGludCBtYWluKCkKIHsKICAgU3RkSU86OnByaW50ZigiMSBwbHVzIDEgaXMgJWRcbiIsIGFkZHRvKCAxLCAxKSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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'>external</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'>addto</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'>x</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'>y</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'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>linkobj</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.o”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span>#<span class='ltx_text ltx_lst_keyword ltx_font_bold'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>header</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.h”</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'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>linksign</span><span class='ltx_text ltx_lst_space'> </span>[1,1,2]
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></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_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;'>7</span></span>
<span class='ltx_text ltx_lst_space'> </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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”1<span class='ltx_text ltx_lst_space'> </span>plus<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_space'> </span>is<span class='ltx_text ltx_lst_space'> </span>%d\n”</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>addto</span>(<span class='ltx_text ltx_lst_space'> </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;'>9</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><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>}
</figure>
<p class='ltx_p'>The pragma linksign tells the compiler where to map each of the return types and arguments into.
The first entry of the vector after the keyword linksign tells the compiler that the return value
will be the first argument. The next one refers to the first argument. This mapping of a return value to the
same position as one argument tells the compiler that this will require a ”pointer-construction“.</p>
<h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 35. </h6>
<p class='ltx_p'>Play around with the linksign pragma and find out what the restrictions are.
How do you have to define the linksign pragma to get the same signature as in the
add example?</p>
<p class='ltx_p'>As you have seen, the linksign pragma allows for quite some messing around with the signature.
In particular disentangling in-out-parameters like the first argument of addto often
creates the desire to change the name of the function. This also is needed when names that exist
in a given library clash with names from those of another library.
To facilitate this as well, SaC provides yet another pragma named ”linkname“.
With it, our simple example can finally be written as:</p>
<figure id='LST61' class='ltx_float ltx_lstlisting'>
<figcaption class='ltx_caption'>Listing 61: addto function used by SaC</figcaption>
<a href='data:text/plain;base64,IGV4dGVybmFsIGludCBhZGQoaW50IHgsIGludCB5KTsKICAgI3ByYWdtYSBsaW5rb2JqICAic2ltcGxlLm8iCiAgICNwcmFnbWEgaGVhZGVyICAgInNpbXBsZS5oIgogICAjcHJhZ21hIGxpbmtzaWduIFsxLDEsMl0KICAgI3ByYWdtYSBsaW5rbmFtZSAiYWRkdG8iCgogaW50IG1haW4oKQogewogICBTdGRJTzo6cHJpbnRmKCIxIHBsdXMgMSBpcyAlZFxuIiwgYWRkKCAxLCAxKSk7CgogICByZXR1cm4gMDsKIH0='>⬇</a>
<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'>external</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'>add</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'>x</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'>y</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'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>linkobj</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.o”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span>
<span class='ltx_text ltx_lst_space'> </span>#<span class='ltx_text ltx_lst_keyword ltx_font_bold'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>header</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”simple.h”</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'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>linksign</span><span class='ltx_text ltx_lst_space'> </span>[1,1,2]
<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>#<span class='ltx_text ltx_lst_keyword ltx_font_bold'>pragma</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>linkname</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_string'>”addto”</span>
<span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></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_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;'>8</span></span>
<span class='ltx_text ltx_lst_space'> </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'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”1<span class='ltx_text ltx_lst_space'> </span>plus<span class='ltx_text ltx_lst_space'> </span>1<span class='ltx_text ltx_lst_space'> </span>is<span class='ltx_text ltx_lst_space'> </span>%d\n”</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>add</span>(<span class='ltx_text ltx_lst_space'> </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;'>10</span></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_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>}
</figure>
</section>
<section id='Ch10.S1.SS2' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
10.1.2 Dealing with non-scalar arrays</h5>
<p class='ltx_p'>In principle, all the pragmas described in this lesson so far carry over to non-scalar arrays.</p>
</section>
<section id='Ch10.S1.SS3' class='ltx_subsection'>
<h5 class='ltx_title ltx_title_subsection'>
10.1.3 Stateful C functions</h5>
</section>
</section>
<section id='Ch10.S2' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
10.2 Lesson: Using SaC libraries from C
</h4>
</section>
<section id='Ch10.S3' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
10.3 Lesson: Using SaC libraries from C++
</h4>
</section>
<section id='Ch10.S4' class='ltx_section'>
<h4 class='ltx_title ltx_title_section'>
10.4 Lesson: Using SaC libraries from Fortran
</h4>
</section>
</section>
</section>
</article>
</div>
<footer class='ltx_page_footer'>
Generated on Mon Mar 14 17:52:01 2022 by <a href='http://dlmf.nist.gov/LaTeXML/'>LaTeXML <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAOCAYAAAD5YeaVAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wKExQZLWTEaOUAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAdpJREFUKM9tkL+L2nAARz9fPZNCKFapUn8kyI0e4iRHSR1Kb8ng0lJw6FYHFwv2LwhOpcWxTjeUunYqOmqd6hEoRDhtDWdA8ApRYsSUCDHNt5ul13vz4w0vWCgUnnEc975arX6ORqN3VqtVZbfbTQC4uEHANM3jSqXymFI6yWazP2KxWAXAL9zCUa1Wy2tXVxheKA9YNoR8Pt+aTqe4FVVVvz05O6MBhqUIBGk8Hn8HAOVy+T+XLJfLS4ZhTiRJgqIoVBRFIoric47jPnmeB1mW/9rr9ZpSSn3Lsmir1fJZlqWlUonKsvwWwD8ymc/nXwVBeLjf7xEKhdBut9Hr9WgmkyGEkJwsy5eHG5vN5g0AKIoCAEgkEkin0wQAfN9/cXPdheu6P33fBwB4ngcAcByHJpPJl+fn54mD3Gg0NrquXxeLRQAAwzAYj8cwTZPwPH9/sVg8PXweDAauqqr2cDjEer1GJBLBZDJBs9mE4zjwfZ85lAGg2+06hmGgXq+j3+/DsixYlgVN03a9Xu8jgCNCyIegIAgx13Vfd7vdu+FweG8YRkjXdWy329+dTgeSJD3ieZ7RNO0VAXAPwDEAO5VKndi2fWrb9jWl9Esul6PZbDY9Go1OZ7PZ9z/lyuD3OozU2wAAAABJRU5ErkJggg==' alt='[LOGO]'></a>
</footer>
</div>
</body>
</html>
1)
\textrm{\lstinlinelst_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}{p}}){\@listingGroup{ltx_lst_space}{~{}}%
}=={\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{ltx_lst_identifier}{shp%
}}}}}}\vee\textrm{\lstinlinelst_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}%
{p}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{ltx_lst_space}{~{}}%
}[]}}}})\wedge(\textrm{\lstinlinelst_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}%
{e\textunderscore 1}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{%
ltx_lst_space}{~{}}}{\@listingGroup{ltx_lst_identifier}{shp}}}}}}\vee\textrm{%
\lstinlinelst_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}{e%
\textunderscore 1}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{%
ltx_lst_space}{~{}}}[]}}}})\wedge(\textrm{\lstinlinelst_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}{e\textunderscore 2}}){\@listingGroup{ltx_lst_space}{~{}}}=%
={\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{ltx_lst_identifier}{shp}}%
}}}}\vee\textrm{\lstinlinelst_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}%
{e\textunderscore 2}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{%
ltx_lst_space}{~{}}}[]}}}}