Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
docs:tutorial [2016/11/30 12:34] – sbs | docs:tutorial [2021/02/04 20:56] – fix excersise 5 hnv |
---|
<!DOCTYPE html><html> | <html> |
<head> | <head> |
<title>Untitled Document</title> | <title>Contents</title> |
<!--Generated on Wed Nov 30 11:29:29 2016 by LaTeXML (version 0.8.2) http://dlmf.nist.gov/LaTeXML/.--> | <!-- Generated on Thu Feb 4 20:42:00 2021 by LaTeXML (version 0.8.5) http://dlmf.nist.gov/LaTeXML/. --> |
| |
| <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> |
| <!-- autoinlined `/home/hans/git/sac/docs/tutorial/html/LaTeXML.css' --> |
| <style type='text/css'> |
| /*====================================================================== |
| Core CSS for LaTeXML documents converted to (X)HTML */ |
| /* Generic Page layout */ |
| .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; } |
| /* What was I trying for here; need more selective rule! |
| .ltx_page_header .ltx_ref, |
| .ltx_page_footer .ltx_ref { |
| margin:0 1em; } |
| */ |
| .ltx_page_header li { |
| padding:0.1em 0.2em 0.1em 1em;} |
| |
| /* Main content */ |
| .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; } |
| |
| /* if shown */ |
| .ltx_page_navbar li { white-space:nowrap; display:block; overflow:hidden; } |
| /* If ref got turned into span, it's "this section"*/ |
| .ltx_page_navbar li span.ltx_ref { white-space:normal; overflow:visible; } |
| |
| /* Ought to be easily removable/overridable? */ |
| .ltx_pagination.ltx_role_newpage { height:2em; } |
| /*====================================================================== |
| Document Structure; Titles & Frontmatter */ |
| |
| /* undo bold here to remove the browser's native h# styling, |
| at let all other styles override it (with more specific rules)*/ |
| .ltx_title { font-size:100%; font-weight:normal; } |
| |
| /* Hack to simulate run-in! put class="ltx_runin" on a title or tag |
| for it to run-into the following text. */ |
| .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_chapter_title, etc should be in ltx-article.css etc. |
| */ |
| .ltx_page_main { margin:0px; padding:1em 3em 1em 2em; } |
| .ltx_tocentry { list-style-type:none; } |
| |
| /* support for common author block layouts.*/ |
| /* add class ltx_authors_1line to get authors in single line |
| with pop-up affiliation, etc. */ |
| .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; } |
| |
| /* add class=ltx_authors_multiline to get authors & affliations on separate lines*/ |
| .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; } |
| |
| /*====================================================================== |
| Para level */ |
| .ltx_float { |
| margin: 1ex 3em 1ex 3em; } |
| td.ltx_subfigure, |
| td.ltx_subtable, |
| td.ltx_subfloat { width:50%; } |
| /* theorems, figure, tables, floats captions.. */ |
| /*====================================================================== |
| Blocks, Lists, Floats */ |
| .ltx_p, |
| .ltx_quote, |
| .ltx_block, |
| .ltx_para { |
| display: block; } |
| |
| /* alignment within blocks */ |
| .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; } |
| |
| /* avoid padding when aligning adjacent columns, e.g. for split decimals */ |
| .ltx_norightpad { padding-right:0!important; } |
| .ltx_noleftpad { padding-left:0!important; } |
| |
| /* equations in non-aligned mode (not normally used) */ |
| .ltx_eqn_div { display:block; width:95%; text-align:center; } |
| |
| /* equations in aligned mode (aligning tags, etc as well as equations) */ |
| .ltx_eqn_table { display:table; width:100%; border-collapse:collapse; } |
| .ltx_eqn_row { display:table-row; } |
| .ltx_eqn_cell { display:table-cell; width:auto; } |
| |
| /* Padding between column pairs in ams align */ |
| 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%; } |
| |
| /* Various lists */ |
| .ltx_itemize, |
| .ltx_enumerate, |
| .ltx_description { |
| display:block; } |
| .ltx_itemize .ltx_item, |
| .ltx_enumerate .ltx_item { |
| display: list-item; } |
| |
| /* Position the tag to look like a normal item bullet. */ |
| 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; } |
| |
| /* NOTE: Need to try harder to get runin appearance? */ |
| 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; } |
| |
| /* Theorems */ |
| .ltx_theorem {margin:1em 0em 1em 0em; } |
| .ltx_title_theorem { font-size:100%; } |
| |
| /* Bibliographies */ |
| .ltx_bibliography dt { margin-right:0.5em; float:left; } |
| .ltx_bibliography dd { margin-left:3em; } |
| /*.ltx_biblist { list-style-type:none; }*/ |
| .ltx_bibitem { list-style-type:none; } |
| .ltx_bibitem .ltx_tag { font-weight:bold; margin-left:-2em; width:3em; } |
| /*.bibitem-tag + div { display:inline; }*/ |
| .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; } |
| |
| /* Indices */ |
| .ltx_indexlist li { list-style-type:none; } |
| .ltx_indexlist { margin-left:1em; padding-left:1em;} |
| |
| /* Listings */ |
| .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; } |
| /* |
| position:absolute; left:0em; |
| max-width:0em; text-align:right; } |
| */ |
| .ltx_parbox {text-indent:0em; } |
| |
| /* NOTE that it is CRITICAL to put position:relative outside & absolute inside!! |
| I wish I understood why! |
| Outer box establishes resulting size, neutralizes any outer positioning, etc; |
| inner establishes position of stuff to be rotated */ |
| .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; } |
| /* If simulating a table (html5), try to get rowspan to work...sorta? */ |
| span.ltx_rowspan { position:absolute; top:0; bottom:0; } |
| |
| /* by default, p doesn't indent */ |
| .ltx_p { text-indent:0em; white-space:normal; } |
| /* explicit control of indentation (on ltx_para) */ |
| .ltx_indent > .ltx_p:first-child { text-indent:2em!important; } |
| .ltx_noindent > .ltx_p:first-child { text-indent:0em!important; } |
| |
| /*====================================================================== |
| Columns */ |
| .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; } |
| |
| /*====================================================================== |
| Borders and such */ |
| .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; } |
| /* regular lines */ |
| .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; } |
| /* double lines */ |
| .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; } |
| /* Light lines */ |
| .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; } |
| /* Framing */ |
| .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; } |
| |
| /*====================================================================== |
| Misc */ |
| /* .ltx_verbatim*/ |
| .ltx_verbatim { text-align:left; } |
| /*====================================================================== |
| Meta stuff, footnotes */ |
| .ltx_note_content { display:none; } |
| /*right:5%; */ |
| .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; } /* So we establish containing block */ |
| .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; } |
| /*====================================================================== |
| SVG (pgf/tikz ?) basics */ |
| |
| /* Stuff appearing in svg:foreignObject */ |
| .ltx_svg_fog foreignObject { margin:0; padding:0; overflow:visible; } |
| .ltx_svg_fog foreignObject > p { margin:0; padding:0; display:block; } |
| /*.ltx_svg_fog foreignObject > p { margin:0; padding:0; display:block; white-space:nowrap; }*/ |
| |
| /*====================================================================== |
| Low-level Basics */ |
| /* Note that LaTeX(ML)'s font model doesn't map quite exactly to CSS's */ |
| /* Font Families => font-family */ |
| .ltx_font_serif { font-family: serif; } |
| .ltx_font_sansserif { font-family: sans-serif; } |
| .ltx_font_typewriter { font-family: monospace; } |
| /* dingbats should be converted to unicode? */ |
| /* Math font families handled within math: script, symbol, fraktur, blackboard ? */ |
| /* Font Series => font-weight */ |
| .ltx_font_bold { font-weight: bold; } |
| .ltx_font_medium { font-weight: normal; } |
| /* Font Shapes => font-style or font-variant */ |
| .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; /* experimental css3 ? Doesn't seem to work!*/ |
| 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"; } |
| /* |
| |
| .ltx_font_mathscript { ? } |
| */ |
| cite { font-style: normal; } |
| |
| .ltx_red { color:red; } |
| /*.ltx_centering { text-align:center; margin:auto; }*/ |
| /*.ltx_inline-block.ltx_centering,*/ |
| /* Hmm.... is this right in general? */ |
| .ltx_centering { display:block; margin:auto; text-align:center; } |
| |
| /* Dubious stuff */ |
| .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"; } |
| |
| /* .ltx_phantom handled in xslt */ |
| |
| </style> |
| |
| <!-- autoinlined `/home/hans/git/sac/docs/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; } |
| |
| /* Paragraph & Subparagraph titles should be runin! */ |
| .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; } |
| |
| /* experimental: flex model, to center short captions, justify long ones */ |
| .ltx_table, |
| .ltx_figure { display:flex; flex-direction:column; align-items:center; } |
| .ltx_table .ltx_caption, |
| .ltx_figure .ltx_caption { text-align:justify; } |
| |
| /* first p in para gets indented */ |
| .ltx_para > .ltx_p:first-child { text-indent:2em; } |
| /* except the initial in a section */ |
| 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 `/home/hans/git/sac/docs/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 `/home/hans/git/sac/docs/tutorial/html/html/tutorial.css' --> |
| <style type='text/css'> |
| /*body { |
| padding-top: 1em; |
| max-width: 50em; |
| margin: auto; |
| }*/ |
| |
| /* This section converts inline menu div into a floating menu. */ |
| .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; |
| } |
| /* end of floating-menu-related definitions. */ |
| |
| /* This places captions of the code snippets behind the snippet. |
| XXX This is a hack as currently LateXML gets confused when |
| position of a caption (as specified by lstset in tex) is |
| bottom. Therefore, we keep tex definition on top and |
| fix it via CSS. |
| |
| XXX I am not sure that changing display to 'table' is a good |
| idea, but I don't know any other way on how to move the |
| caption down. */ |
| figure { |
| display: table; |
| width: 95%; |
| } |
| figcaption { |
| display: table-caption; |
| caption-side: bottom; |
| } |
| |
| /* We don't need paragraph indentation in html. */ |
| .ltx_para > .ltx_p:first-child { text-indent:0em; } |
| |
| |
| /* This minheight needs to be adjusted to the bootstrap |
| minimum height so that the line numbers in listings |
| behave correctly. */ |
| .ltx_listingline { |
| white-space:nowrap; |
| min-height:1.42857143em; |
| } |
| |
| /* Get rid of italic inside the theorem environment. |
| This has an effect on the way excersises look. */ |
| .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!; |
| } |
| /*.ltx_framed_rectangle { |
| float: left; |
| width: 20em; |
| margin-right: 10px; |
| margin-left: -10em; |
| }*/ |
| |
| </style> |
| |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<link rel="stylesheet" href="LaTeXML.css" type="text/css"> | |
<link rel="stylesheet" href="ltx-report.css" type="text/css"> | |
<link rel="stylesheet" href="ltx-listings.css" type="text/css"> | |
<link rel="stylesheet" href="http://www.sac-home.org/dokuwiki/lib/tpl/bootstrap3/assets/bootstrap/journal/bootstrap.min.css" type="text/css"> | |
<link rel="stylesheet" href="tutorial.css" type="text/css"> | |
</head> | </head> |
<body> | <body> |
<div class="ltx_page_main"> | <div class='ltx_page_main'> |
<div class="ltx_page_content"> | <div class='ltx_page_content'> |
<article class="ltx_document"> | <article class='ltx_document'> |
<div class="ltx_titlepage"> | <div class='ltx_titlepage'> |
<p class="ltx_p"><span class="ltx_text" style="font-size:298%;">SINGLE ASSIGNMENT C | <p class='ltx_p'><span class='ltx_text' style='font-size:298%;'>SINGLE ASSIGNMENT C |
<br class="ltx_break"></span> | <br class='ltx_break'></span> |
<span class="ltx_text" style="font-size:298%;">TUTORIAL | <span class='ltx_text' style='font-size:298%;'>TUTORIAL |
<br class="ltx_break"></span> | <br class='ltx_break'></span> |
<span class="ltx_text" style="font-size:144%;">VERSION 1.2</span></p> | <span class='ltx_text' style='font-size:144%;'>VERSION 1.2.1</span></p> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps" style="font-size:144%;">Sven-Bodo Scholz<span class="ltx_text ltx_font_upright"> </span>Stephan Herhut | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps' style='font-size:144%;'>Sven-Bodo Scholz<span class='ltx_text ltx_font_upright'> </span>Stephan Herhut |
<br class="ltx_break">Frank Penczek<span class="ltx_text ltx_font_upright"> </span>Clemens Grelck | <br class='ltx_break'>Frank Penczek<span class='ltx_text ltx_font_upright'> </span>Clemens Grelck |
<br class="ltx_break">Artem Shinkarov | <br class='ltx_break'>Artem Shinkarov<span class='ltx_text ltx_font_upright'> </span>Hans-Nikolai Vießmann |
<br class="ltx_break"></span></p> | <br class='ltx_break'></span></p> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps" style="font-size:120%;">November 30, 2016</span></p> | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps' style='font-size:120%;'>February 4, 2021</span></p> |
</div> | </div> |
<div class="ltx_TOC ltx_role_contents"> | <div class='ltx_TOC ltx_role_contents'> |
<h6>Contents:</h6> | <h6>Contents</h6> |
<ul class="ltx_toclist"> | <ul class='ltx_toclist'> |
<li class="ltx_tocentry ltx_tocentry_part"> | <li class='ltx_tocentry ltx_tocentry_part'> |
<a href="#Pt1" title="Part I Trails Covering the Basics of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">I </span>Trails Covering the Basics of SaC</span></a> | <a href='#Pt1' title='Part I Trails Covering the Basics of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>I </span>Trails Covering the Basics of SaC</span></a> |
<ul class="ltx_toclist ltx_toclist_part"> | <ul class='ltx_toclist ltx_toclist_part'> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">1 </span>Running the first program</span></a> | <a href='#Ch1' title='Chapter 1 Running the first program ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>1 </span>Running the first program</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">1.1 </span>A Checklist</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>1.1 </span>A Checklist</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">1.2 </span>Create your first <span class="ltx_text ltx_font_smallcaps">SaC</span> Source File</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>1.2 </span>Create your first <span class='ltx_text ltx_font_smallcaps'>SaC</span> Source File</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">1.3 </span>Compile the Source File and Run the Program</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>1.3 </span>Compile the Source File and Run the Program</span></a></li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2 </span>Array Programming Basics</span></a> | <a href='#Ch2' title='Chapter 2 Array Programming Basics ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2 </span>Array Programming Basics</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <ul class='ltx_toclist ltx_toclist_chapter'> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2.1 </span>Lesson 1: Arrays as Data</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2.1 </span>Lesson 1: Arrays as Data</span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2.1.1 </span>Defining Arrays</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2.1.1 </span>Defining Arrays</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2.1.2 </span>Arrays and Variables</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2.1.2 </span>Arrays and Variables</span></a></li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2.2 </span>Lesson 2: Shape-Invariant Programming</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2.2 </span>Lesson 2: Shape-Invariant Programming</span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2.2.1 </span>Standard Array Operations</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2.2.1 </span>Standard Array Operations</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2.2.2 </span>Axis Control Notation</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2.2.2 </span>Axis Control Notation</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2.2.3 </span>Putting it all Together</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>2.2.3 </span>Putting it all Together</span></a></li> |
</ul> | </ul> |
</li> | </li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3 </span>Basic Program Structure</span></a> | <a href='#Ch3' title='Chapter 3 Basic Program Structure ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3 </span>Basic Program Structure</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <ul class='ltx_toclist ltx_toclist_chapter'> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.1 </span>Lesson 3: Functions and their Types</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.1 </span>Lesson 3: Functions and their Types</span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.1.1 </span>Function Definitions</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.1.1 </span>Function Definitions</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.1.2 </span>Built-in Types</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.1.2 </span>Built-in Types</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.1.3 </span>Subtyping</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.1.3 </span>Subtyping</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.1.4 </span>Function Overloading</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.1.4 </span>Function Overloading</span></a></li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.2 </span>Lesson 4: Function Bodies</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.2 </span>Lesson 4: Function Bodies</span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.2.1 </span>Variable Declarations</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.2.1 </span>Variable Declarations</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.2.2 </span>Assignments</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.2.2 </span>Assignments</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.2.3 </span>Conditionals</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.2.3 </span>Conditionals</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.2.4 </span>Loops</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.2.4 </span>Loops</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.2.5 </span>Explicit Control Flow Manipulation</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.2.5 </span>Explicit Control Flow Manipulation</span></a></li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.3 </span>Lesson 5: Advanced Topics</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.3 </span>Lesson 5: Advanced Topics</span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.3.1 </span>User-defined Types</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.3.1 </span>User-defined Types</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.3.2 </span>Type Conversions</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>3.3.2 </span>Type Conversions</span></a></li> |
</ul> | </ul> |
</li> | </li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4 </span>With-Loops</span></a> | <a href='#Ch4' title='Chapter 4 With-Loops ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>4 </span>With-Loops</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <ul class='ltx_toclist ltx_toclist_chapter'> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4.1 </span>Lesson 6: with-loop Basics</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>4.1 </span>Lesson 6: with-loop Basics</span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4.1.1 </span>Basic Components</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>4.1.1 </span>Basic Components</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4.1.2 </span>Generator Ranges</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>4.1.2 </span>Generator Ranges</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4.1.3 </span>Generator Expressions</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>4.1.3 </span>Generator Expressions</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4.1.4 </span>Reductions and further with-loop Operations</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>4.1.4 </span>Reductions and further with-loop Operations</span></a></li> |
</ul> | </ul> |
</li> | </li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">5 </span>Working with Modules</span></a> | <a href='#Ch5' title='Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>5 </span>Working with Modules</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">5.1 </span>Name Spaces</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>5.1 </span>Name Spaces</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">5.2 </span>Use Statements</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>5.2 </span>Use Statements</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">5.3 </span>Import statement</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>5.3 </span>Import statement</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">5.4 </span>Putting It Together</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>5.4 </span>Putting It Together</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">5.5 </span>Implementing Modules</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>5.5 </span>Implementing Modules</span></a></li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">6 </span>Case Studies</span></a> | <a href='#Ch6' title='Chapter 6 Case Studies ‣ Part I Trails Covering the Basics of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>6 </span>Case Studies</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">6.1 </span>Lesson 7: Image Processing</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>6.1 </span>Lesson 7: Image Processing</span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">6.2 </span>Lesson 8: Computing Mandelbrot Images</span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>6.2 </span>Lesson 8: Computing Mandelbrot Images</span></a></li> |
</ul> | </ul> |
</li> | </li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_part"> | <li class='ltx_tocentry ltx_tocentry_part'> |
<a href="#Pt2" title="Part II Trails Covering More Advanced Features of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">II </span>Trails Covering More Advanced Features of SaC</span></a> | <a href='#Pt2' title='Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>II </span>Trails Covering More Advanced Features of SaC</span></a> |
<ul class="ltx_toclist ltx_toclist_part"> | <ul class='ltx_toclist ltx_toclist_part'> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">7 </span>Treasures in the Standard Library</span></a> | <a href='#Ch7' title='Chapter 7 Treasures in the Standard Library ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>7 </span>Treasures in the Standard Library</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">7.1 </span>Lesson: Benchmarking <span class="ltx_text ltx_font_smallcaps">SaC</span> Programs</span></a></li> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>7.1 </span>Lesson: Benchmarking <span class='ltx_text ltx_font_smallcaps'>SaC</span> Programs</span></a></li> |
</ul> | </ul> |
</li> | </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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">8 </span>User Defined Types</span></a></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>8 </span>User Defined Types</span></a></li> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">9 </span>Dealing with I/O and State in General</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>9 </span>Dealing with I/O and State in General</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <ul class='ltx_toclist ltx_toclist_chapter'> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">9.1 </span>Lesson: States and Objects — the basics</span></a> | <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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>9.1 </span>Lesson: States and Objects — the basics</span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#Ch9.S1.SS1" title="9.1.1 Extending Classes ‣ 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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">9.1.1 </span>Extending Classes</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch9.S1.SS1' title='9.1.1 Extending Classes ‣ 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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>9.1.1 </span>Extending Classes</span></a></li> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#Ch9.S1.SS2" title="9.1.2 States using Classes ‣ 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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">9.1.2 </span>States using Classes</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch9.S1.SS2' title='9.1.2 States using Classes ‣ 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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>9.1.2 </span>States using Classes</span></a></li> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#Ch9.S1.SS3" title="9.1.3 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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">9.1.3 </span>Global Objects</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch9.S1.SS3' title='9.1.3 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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>9.1.3 </span>Global Objects</span></a></li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_section"><a href="#Ch9.S2" title="9.2 Lesson: Nondeterminism through Shared State in Wihth-Loops ‣ Chapter 9 Dealing with I/O and State in General ‣ Part II Trails Covering More Advanced Features of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">9.2 </span>Lesson: Nondeterminism through Shared State in Wihth-Loops</span></a></li> | <li class='ltx_tocentry ltx_tocentry_section'><a href='#Ch9.S2' title='9.2 Lesson: Nondeterminism through Shared State in Wihth-Loops ‣ Chapter 9 Dealing with I/O and State in General ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>9.2 </span>Lesson: Nondeterminism through Shared State in Wihth-Loops</span></a></li> |
</ul> | </ul> |
</li> | </li> |
<li class="ltx_tocentry ltx_tocentry_chapter"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10 </span>Interfacing with Other Languages</span></a> | <a href='#Ch10' title='Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10 </span>Interfacing with Other Languages</span></a> |
<ul class="ltx_toclist ltx_toclist_chapter"> | <ul class='ltx_toclist ltx_toclist_chapter'> |
<li class="ltx_tocentry ltx_tocentry_section"> | <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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.1 </span>Lesson: Calling <span class="ltx_text ltx_font_smallcaps">C</span> from <span class="ltx_text ltx_font_smallcaps">SaC</span></span></a> | <a href='#Ch10.S1' title='10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1 </span>Lesson: Calling <span class='ltx_text ltx_font_smallcaps'>C</span> from <span class='ltx_text ltx_font_smallcaps'>SaC</span></span></a> |
<ul class="ltx_toclist ltx_toclist_section"> | <ul class='ltx_toclist ltx_toclist_section'> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#Ch10.S1.SS1" title="10.1.1 Using C in the Small ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.1.1 </span>Using C in Small</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS1' title='10.1.1 Using C in the small ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.1 </span>Using <span class='ltx_text ltx_font_smallcaps'>C</span> in the small</span></a></li> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#Ch10.S1.SS2" title="10.1.2 Stateful C functions ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.1.2 </span>Stateful <span class="ltx_text ltx_font_smallcaps">C</span> functions</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS2' title='10.1.2 Dealing with non-scalar arrays ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.2 </span>Dealing with non-scalar arrays</span></a></li> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#Ch10.S1.SS3" title="10.1.3 Using pragma directives ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.1.3 </span>Using pragma directives</span></a></li> | <li class='ltx_tocentry ltx_tocentry_subsection'><a href='#Ch10.S1.SS3' title='10.1.3 Stateful C functions ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC' class='ltx_ref'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.1.3 </span>Stateful <span class='ltx_text ltx_font_smallcaps'>C</span> functions</span></a></li> |
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#Ch10.S1.SS4" title="10.1.4 Example TermFile ‣ 10.1 Lesson: Calling C from SaC ‣ Chapter 10 Interfacing with Other Languages ‣ Part II Trails Covering More Advanced Features of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.1.4 </span>Example TermFile</span></a></li> | |
</ul> | </ul> |
</li> | </li> |
<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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.2 </span>Lesson: Using <span class="ltx_text ltx_font_smallcaps">SaC</span> libraries from <span class="ltx_text ltx_font_smallcaps">C</span></span></a></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.2 </span>Lesson: Using <span class='ltx_text ltx_font_smallcaps'>SaC</span> libraries from <span class='ltx_text ltx_font_smallcaps'>C</span></span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.3 </span>Lesson: Using <span class="ltx_text ltx_font_smallcaps">SaC</span> libraries from <span class="ltx_text ltx_font_smallcaps">C++</span></span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.3 </span>Lesson: Using <span class='ltx_text ltx_font_smallcaps'>SaC</span> libraries from <span class='ltx_text ltx_font_smallcaps'>C++</span></span></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"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">10.4 </span>Lesson: Using <span class="ltx_text ltx_font_smallcaps">SaC</span> libraries from <span class="ltx_text ltx_font_smallcaps">Fortran</span></span></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'><span class='ltx_text ltx_ref_title'><span class='ltx_tag ltx_tag_ref'>10.4 </span>Lesson: Using <span class='ltx_text ltx_font_smallcaps'>SaC</span> libraries from <span class='ltx_text ltx_font_smallcaps'>Fortran</span></span></a></li> |
</ul> | </ul> |
</li> | </li> |
</ul> | </ul> |
</div> | </div> |
<section id="Pt1" class="ltx_part"> | <section id='Pt1' class='ltx_part'> |
<h2 class="ltx_title ltx_title_part"> | <h2 class='ltx_title ltx_title_part'> |
<span class="ltx_tag ltx_tag_part">Part I </span>Trails Covering the Basics of <span class="ltx_text ltx_font_smallcaps">SaC</span> | <span class='ltx_tag ltx_tag_part'>Part I </span>Trails Covering the Basics of <span class='ltx_text ltx_font_smallcaps'>SaC</span> |
</h2> | </h2> |
| |
<section id="Ch1" class="ltx_chapter"> | <section id='Ch1' class='ltx_chapter'> |
<h3 class="ltx_title ltx_title_chapter"> | <h3 class='ltx_title ltx_title_chapter'> |
<span class="ltx_tag ltx_tag_chapter">Chapter 1 </span>Running the first program</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 1 </span>Running the first program</h3> |
| |
<div id="Ch1.p1" class="ltx_para"> | <div id='Ch1.p1' class='ltx_para'> |
<p class="ltx_p">The following instructions will help you write your first <span class="ltx_text ltx_font_smallcaps">SaC</span> program.</p> | <p class='ltx_p'>The following instructions will help you write your first <span class='ltx_text ltx_font_smallcaps'>SaC</span> program.</p> |
</div> | </div> |
<section id="Ch1.S1" class="ltx_section"> | <section id='Ch1.S1' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">1.1 </span>A Checklist</h4> | <span class='ltx_tag ltx_tag_section'>1.1 </span>A Checklist</h4> |
| |
<div id="Ch1.S1.p1" class="ltx_para"> | <div id='Ch1.S1.p1' class='ltx_para'> |
<p class="ltx_p">To successfully write and run your first <span class="ltx_text ltx_font_smallcaps">SaC</span> program, you will need:</p> | <p class='ltx_p'>To successfully write and run your first <span class='ltx_text ltx_font_smallcaps'>SaC</span> program, you will need:</p> |
<ul id="Ch1.I1" class="ltx_itemize"> | <ul id='Ch1.S1.I1' class='ltx_itemize'> |
<li id="Ch1.I1.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch1.S1.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch1.I1.i1.p1" class="ltx_para"> | <div id='Ch1.S1.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p">An <span class="ltx_text ltx_font_bold">ANSI C compiler</span>, such as <span class="ltx_text ltx_font_typewriter">gcc</span>. Though not needed directly, | <p class='ltx_p'>An <span class='ltx_text ltx_font_bold'>ANSI C compiler</span>, such as <span class='ltx_text ltx_font_typewriter'>gcc</span>. Though not needed directly, |
the <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler relies on it.</p> | the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler relies on it.</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch1.I1.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch1.S1.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch1.I1.i2.p1" class="ltx_para"> | <div id='Ch1.S1.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p">The <span class="ltx_text ltx_font_bold">SaC compiler</span> <span class="ltx_text ltx_font_typewriter">sac2c</span>. It can be downloaded at | <p class='ltx_p'>The <span class='ltx_text ltx_font_bold'>SaC compiler</span> <span class='ltx_text ltx_font_typewriter'>sac2c</span>. It can be downloaded at |
<a href="http://www.sac-home.org" title="" class="ltx_ref ltx_url ltx_font_typewriter">http://www.sac-home.org</a>; see instructions in the Download | <a href='http://www.sac-home.org' title='' class='ltx_ref ltx_url ltx_font_typewriter'>http://www.sac-home.org</a>; see instructions in the Download |
section.</p> | section.</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch1.I1.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch1.S1.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch1.I1.i3.p1" class="ltx_para"> | <div id='Ch1.S1.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p">The <span class="ltx_text ltx_font_bold">SaC standard library</span> can be downloaded from GitHub | <p class='ltx_p'>The <span class='ltx_text ltx_font_bold'>SaC standard library</span> can be downloaded from GitHub |
<a href="http://www.github.com/SacBase/stdlib-core" title="" class="ltx_ref ltx_url ltx_font_typewriter">http://www.github.com/SacBase/stdlib-core</a>. The process | <a href='http://www.github.com/SacBase/stdlib-core' title='' class='ltx_ref ltx_url ltx_font_typewriter'>http://www.github.com/SacBase/stdlib-core</a>. The process |
of installation is described in README.md file of the stdlib | of installation is described in README.md file of the stdlib |
repository.</p> | repository.</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch1.I1.i4" class="ltx_item" style="list-style-type:none;"> | <li id='Ch1.S1.I1.i4' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch1.I1.i4.p1" class="ltx_para"> | <div id='Ch1.S1.I1.i4.p1' class='ltx_para'> |
<p class="ltx_p">Your favorite <span class="ltx_text ltx_font_bold">text editor</span>, such as <span class="ltx_text ltx_font_typewriter">vi</span> or <span class="ltx_text ltx_font_typewriter">emacs</span>.</p> | <p class='ltx_p'>Your favorite <span class='ltx_text ltx_font_bold'>text editor</span>, such as <span class='ltx_text ltx_font_typewriter'>vi</span> or <span class='ltx_text ltx_font_typewriter'>emacs</span>.</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</section> | </section> |
<section id="Ch1.S2" class="ltx_section"> | <section id='Ch1.S2' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">1.2 </span>Create your first <span class="ltx_text ltx_font_smallcaps">SaC</span> Source File</h4> | <span class='ltx_tag ltx_tag_section'>1.2 </span>Create your first <span class='ltx_text ltx_font_smallcaps'>SaC</span> Source File</h4> |
| |
<div id="Ch1.S2.p1" class="ltx_para"> | <div id='Ch1.S2.p1' class='ltx_para'> |
<p class="ltx_p">Start your editor and type the following program:</p> | <p class='ltx_p'>Start your editor and type the following program:</p> |
</div> | </div> |
<figure id="LST1" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST1' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 1: </span>Hello World</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 1: </span>Hello World</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnRmKCJI%0AZWxsbyBXb3JsZCFcbiIpOwogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnRmKCJIZWxsbyBXb3JsZCFcbiIpOwogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx1' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx2' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx3' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx4' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx5' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx6' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">printf</span>(<span class="ltx_text ltx_lst_string">”Hello<span class="ltx_text ltx_lst_space"> </span>World!\n”</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”Hello<span class='ltx_text ltx_lst_space'> </span>World!\n”</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx7' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx8' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch1.S2.p2" class="ltx_para"> | <div id='Ch1.S2.p2' class='ltx_para'> |
<p class="ltx_p">As you can see, it has a strong resemblance to C. The major difference | <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. | 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 | For now, it suffices to keep in mind, that these two use declarations for most |
experiments will do the job.</p> | experiments will do the job.</p> |
</div> | </div> |
<div id="Ch1.S2.p3" class="ltx_para"> | <div id='Ch1.S2.p3' class='ltx_para'> |
<p class="ltx_p">In order to proceed, save this program into a file named <span class="ltx_text ltx_font_typewriter">world.sac</span>.</p> | <p class='ltx_p'>In order to proceed, save this program into a file named <span class='ltx_text ltx_font_typewriter'>world.sac</span>.</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch1.S3" class="ltx_section"> | <section id='Ch1.S3' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">1.3 </span>Compile the Source File and Run the Program</h4> | <span class='ltx_tag ltx_tag_section'>1.3 </span>Compile the Source File and Run the Program</h4> |
| |
<div id="Ch1.S3.p1" class="ltx_para"> | <div id='Ch1.S3.p1' class='ltx_para'> |
<p class="ltx_p">The <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler invocation is similar to the standard invocation of | <p class='ltx_p'>The <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler invocation is similar to the standard invocation of |
<span class="ltx_text ltx_font_smallcaps">C</span> compilers. | <span class='ltx_text ltx_font_smallcaps'>C</span> compilers. |
A typical shell session for compiling <span class="ltx_text ltx_font_typewriter">world.sac</span> could be:</p> | A typical shell session for compiling <span class='ltx_text ltx_font_typewriter'>world.sac</span> could be:</p> |
</div> | </div> |
<figure id="LST2" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST2' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 2: </span>Typical shell session</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 2: </span>Typical shell session</figcaption> |
<div class="ltx_listing ltx_lst_language_bash ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_bash ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,JCBjZCAvaG9tZS9zYnMvc2FjLwokIGxzCndvcmxkLnNhYwokIHNhYzJjICB3b3JsZC5zYWMKJCBs%0AcwphLm91dCAgICAgIGEub3V0LmMgICAgd29ybGQuc2FjCiQgYS5vdXQKSGVsbG8gV29ybGQh%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,JCBjZCAvaG9tZS9zYnMvc2FjLwokIGxzCndvcmxkLnNhYwokIHNhYzJjICB3b3JsZC5zYWMKJCBscwphLm91dCAgICAgIGEub3V0LmMgICAgd29ybGQuc2FjCiQgYS5vdXQKSGVsbG8gV29ybGQh'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx9' class='ltx_listingline'>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>cd</span><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_identifier'>home</span>/<span class='ltx_text ltx_lst_identifier'>sbs</span>/<span class='ltx_text ltx_lst_identifier'>sac</span>/ |
<span class="ltx_text ltx_lst_identifier">$</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">cd</span><span class="ltx_text ltx_lst_space"> </span>/<span class="ltx_text ltx_lst_identifier">home</span>/<span class="ltx_text ltx_lst_identifier">sbs</span>/<span class="ltx_text ltx_lst_identifier">sac</span>/ | |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx10' class='ltx_listingline'>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ls</span> |
<span class="ltx_text ltx_lst_identifier">$</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">ls</span> | |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx11' class='ltx_listingline'> |
<span class="ltx_text ltx_lst_identifier">world</span>.<span class="ltx_text ltx_lst_identifier">sac</span> | <span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx12' class='ltx_listingline'>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>sac2c</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> |
<span class="ltx_text ltx_lst_identifier">$</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">sac2c</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">world</span>.<span class="ltx_text ltx_lst_identifier">sac</span> | |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx13' class='ltx_listingline'>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ls</span> |
<span class="ltx_text ltx_lst_identifier">$</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">ls</span> | |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx14' class='ltx_listingline'> |
<span class="ltx_text ltx_lst_identifier">a</span>.<span class="ltx_text ltx_lst_identifier">out</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>.<span class="ltx_text ltx_lst_identifier">out</span>.<span class="ltx_text ltx_lst_identifier">c</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">world</span>.<span class="ltx_text ltx_lst_identifier">sac</span> | <span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span>.<span class='ltx_text ltx_lst_identifier'>c</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>world</span>.<span class='ltx_text ltx_lst_identifier'>sac</span> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx15' class='ltx_listingline'>$<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>.<span class='ltx_text ltx_lst_identifier'>out</span> |
<span class="ltx_text ltx_lst_identifier">$</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>.<span class="ltx_text ltx_lst_identifier">out</span> | |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx16' class='ltx_listingline'> |
<span class="ltx_text ltx_lst_identifier">Hello</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">World</span>! | <span class='ltx_text ltx_lst_identifier'>Hello</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>World</span>! |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch1.S3.p2" class="ltx_para"> | <div id='Ch1.S3.p2' class='ltx_para'> |
<p class="ltx_p">The compilation process consists of two steps. | <p class='ltx_p'>The compilation process consists of two steps. |
First, the <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler generates a <span class="ltx_text ltx_font_smallcaps">C</span> file, which then is compiled | First, the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler generates a <span class='ltx_text ltx_font_smallcaps'>C</span> file, which then is compiled |
into target code by utilizing the system’s <span class="ltx_text ltx_font_smallcaps">C</span> compiler. | into target code by utilizing the system’s <span class='ltx_text ltx_font_smallcaps'>C</span> compiler. |
If no target file name is specified, the intermediate <span class="ltx_text ltx_font_smallcaps">C</span> file is named | If no target file name is specified, the intermediate <span class='ltx_text ltx_font_smallcaps'>C</span> file is named |
<span class="ltx_text ltx_font_typewriter">a.out.c</span> so that the subsequent invocation of the <span class="ltx_text ltx_font_smallcaps">C</span> compiler | <span class='ltx_text ltx_font_typewriter'>a.out.c</span> so that the subsequent invocation of the <span class='ltx_text ltx_font_smallcaps'>C</span> compiler |
creates an executable named <span class="ltx_text ltx_font_typewriter">a.out</span>.</p> | creates an executable named <span class='ltx_text ltx_font_typewriter'>a.out</span>.</p> |
</div> | </div> |
<div id="Ch1.S3.p3" class="ltx_para"> | <div id='Ch1.S3.p3' class='ltx_para'> |
<p class="ltx_p">In the same way the default target name <span class="ltx_text ltx_font_typewriter">a.out</span> is borrowed from | <p class='ltx_p'>In the same way the default target name <span class='ltx_text ltx_font_typewriter'>a.out</span> is borrowed from |
standard <span class="ltx_text ltx_font_smallcaps">C</span> compilers, the <span class="ltx_text ltx_font_typewriter">-o</span> option for specifying target names | standard <span class='ltx_text ltx_font_smallcaps'>C</span> compilers, the <span class='ltx_text ltx_font_typewriter'>-o</span> option for specifying target names |
is adopted as well. | is adopted as well. |
For example, <span class="ltx_text ltx_font_typewriter">sac2c -o world world.sac</span> results | For example, <span class='ltx_text ltx_font_typewriter'>sac2c -o world world.sac</span> results |
in files <span class="ltx_text ltx_font_typewriter">world.c</span> and <span class="ltx_text ltx_font_typewriter">world</span>.</p> | in files <span class='ltx_text ltx_font_typewriter'>world.c</span> and <span class='ltx_text ltx_font_typewriter'>world</span>.</p> |
</div> | </div> |
<div id="Ch1.S3.p4" class="ltx_para"> | <div id='Ch1.S3.p4' class='ltx_para'> |
<p class="ltx_p">Note here, that the compiled program, depending on the operating system, | <p class='ltx_p'>Note here, that the compiled program, depending on the operating system, |
is linked either statically or dynamically. | is linked either statically or dynamically. |
However, it does not require any further linking or interpretation.</p> | However, it does not require any further linking or interpretation.</p> |
</section> | </section> |
</section> | </section> |
<section id="Ch2" class="ltx_chapter"> | <section id='Ch2' class='ltx_chapter'> |
<h3 class="ltx_title ltx_title_chapter"> | <h3 class='ltx_title ltx_title_chapter'> |
<span class="ltx_tag ltx_tag_chapter">Chapter 2 </span>Array Programming Basics</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 2 </span>Array Programming Basics</h3> |
| |
<div id="Ch2.p1" class="ltx_para"> | <div id='Ch2.p1' class='ltx_para'> |
<p class="ltx_p">This trail gives an introduction to the basic concepts of array programming | <p class='ltx_p'>This trail gives an introduction to the basic concepts of array programming |
in <span class="ltx_text ltx_font_smallcaps">SaC</span>. | in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
It consists of two lessons: <span class="ltx_text ltx_font_italic">Arrays as Data</span> and <span class="ltx_text ltx_font_italic">Shape-Invariant Programming</span>. | It consists of two lessons: <span class='ltx_text ltx_font_italic'>Arrays as Data</span> and <span class='ltx_text ltx_font_italic'>Shape-Invariant Programming</span>. |
In the former lesson, the major differences between arrays in <span class="ltx_text ltx_font_smallcaps">SaC</span> and arrays | In the former lesson, the major differences between arrays in <span class='ltx_text ltx_font_smallcaps'>SaC</span> and arrays |
in more mainstream languages are explained. | in more mainstream languages are explained. |
The lesson <span class="ltx_text ltx_font_italic">Shape-Invariant Programming</span> gives an introduction into the most | The lesson <span class='ltx_text ltx_font_italic'>Shape-Invariant Programming</span> gives an introduction into the most |
important array operations available in <span class="ltx_text ltx_font_smallcaps">SaC</span>. | important array operations available in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
Based on these operations, several small examples demonstrate how more complex | Based on these operations, several small examples demonstrate how more complex |
array operations can be constructed by simply combining the basic ones.</p> | array operations can be constructed by simply combining the basic ones.</p> |
</div> | </div> |
<section id="Ch2.S1" class="ltx_section"> | <section id='Ch2.S1' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">2.1 </span>Lesson 1: Arrays as Data</h4> | <span class='ltx_tag ltx_tag_section'>2.1 </span>Lesson 1: Arrays as Data</h4> |
| |
<div id="Ch2.S1.p1" class="ltx_para"> | <div id='Ch2.S1.p1' class='ltx_para'> |
<p class="ltx_p">In <span class="ltx_text ltx_font_smallcaps">SaC</span>, arrays are the only data structures available. Even scalar values | <p class='ltx_p'>In <span class='ltx_text ltx_font_smallcaps'>SaC</span>, arrays are the only data structures available. Even scalar values |
are considered arrays. | are considered arrays. |
Each array is represented by two vectors, a so-called <em class="ltx_emph">shape vector</em> | Each array is represented by two vectors, a so-called <em class='ltx_emph ltx_font_italic'>shape vector</em> |
and a <em class="ltx_emph">data vector</em>. | and a <em class='ltx_emph ltx_font_italic'>data vector</em>. |
An array’s shape vector defines its <em class="ltx_emph">shape</em>, i.e. its extent within each axis, | An array’s shape vector defines its <em class='ltx_emph ltx_font_italic'>shape</em>, i.e. its extent within each axis, |
and its <em class="ltx_emph">dimensionality</em> (or <em class="ltx_emph">rank</em>), which is given implicitly by the shape vector’s | and its <em class='ltx_emph ltx_font_italic'>dimensionality</em> (or <em class='ltx_emph ltx_font_italic'>rank</em>), which is given implicitly by the shape vector’s |
length.</p> | length.</p> |
</div> | </div> |
<div id="Ch2.S1.p2" class="ltx_para"> | <div id='Ch2.S1.p2' class='ltx_para'> |
<p class="ltx_p">The section on <em class="ltx_emph">Defining Arrays</em> explains how arrays of various dimensionality | <p class='ltx_p'>The section on <em class='ltx_emph ltx_font_italic'>Defining Arrays</em> explains how arrays of various dimensionality |
can be defined in <span class="ltx_text ltx_font_smallcaps">SaC</span>, and how they can be generated via nesting. | can be defined in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, and how they can be generated via nesting. |
Furthermore, some elementary notation such as <em class="ltx_emph">scalars</em>, <em class="ltx_emph">vectors</em>, and | Furthermore, some elementary notation such as <em class='ltx_emph ltx_font_italic'>scalars</em>, <em class='ltx_emph ltx_font_italic'>vectors</em>, and |
<em class="ltx_emph">matrices</em> is defined.</p> | <em class='ltx_emph ltx_font_italic'>matrices</em> is defined.</p> |
</div> | </div> |
<div id="Ch2.S1.p3" class="ltx_para"> | <div id='Ch2.S1.p3' class='ltx_para'> |
<p class="ltx_p">The section on <em class="ltx_emph">Arrays and Variables</em> discusses the purely functional | <p class='ltx_p'>The section on <em class='ltx_emph ltx_font_italic'>Arrays and Variables</em> discusses the purely functional |
array model used in <span class="ltx_text ltx_font_smallcaps">SaC</span>.</p> | array model used in <span class='ltx_text ltx_font_smallcaps'>SaC</span>.</p> |
</div> | </div> |
<section id="Ch2.S1.SS1" class="ltx_subsection"> | <section id='Ch2.S1.SS1' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">2.1.1 </span>Defining Arrays</h5> | <span class='ltx_tag ltx_tag_subsection'>2.1.1 </span>Defining Arrays</h5> |
| |
<div id="Ch2.S1.SS1.p1" class="ltx_para"> | <div id='Ch2.S1.SS1.p1' class='ltx_para'> |
<p class="ltx_p">In this section, several means for specifying arrays are explained.</p> | <p class='ltx_p'>In this section, several means for specifying arrays are explained.</p> |
</div> | </div> |
<div id="Ch2.S1.SS1.p2" class="ltx_para"> | <div id='Ch2.S1.SS1.p2' class='ltx_para'> |
<p class="ltx_p">In principle, all arrays in <span class="ltx_text ltx_font_smallcaps">SaC</span> can be defined by using the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reshape</span> operation. | <p class='ltx_p'>In principle, all arrays in <span class='ltx_text ltx_font_smallcaps'>SaC</span> can be defined by using the <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> operation. |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reshape</span> expects two operands, a shape vector and a data vector, both of which | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> expects two operands, a shape vector and a data vector, both of which |
are specified as comma separated lists of numbers enclosed in square brackets.</p> | are specified as comma separated lists of numbers enclosed in square brackets.</p> |
</div> | </div> |
<div id="Ch2.S1.SS1.p3" class="ltx_para"> | <div id='Ch2.S1.SS1.p3' class='ltx_para'> |
<p class="ltx_p">To get started, try the following program:</p> | <p class='ltx_p'>To get started, try the following program:</p> |
</div> | </div> |
<figure id="LST3" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST3' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 3: </span>Defining Arrays I</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 3: </span>Defining Arrays I</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQocmVz%0AaGFwZShbNV0sIFsxLDIsMyw0LDVdKSk7CiAgcHJpbnQocmVzaGFwZShbMywyXSwgWzEsMiwzLDQs%0ANSw2XSkpOwogIHByaW50KHJlc2hhcGUoWzMsMiwxXSwgWzEsMiwzLDQsNSw2XSkpOwogIHJldHVy%0AbiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQocmVzaGFwZShbNV0sIFsxLDIsMyw0LDVdKSk7CiAgcHJpbnQocmVzaGFwZShbMywyXSwgWzEsMiwzLDQsNSw2XSkpOwogIHByaW50KHJlc2hhcGUoWzMsMiwxXSwgWzEsMiwzLDQsNSw2XSkpOwogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx17' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx18' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx19' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx20' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx21' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx22' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">reshape</span>([5],<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([5],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5])); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx23' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">reshape</span>([3,2],<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5,6])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([3,2],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6])); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx24' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">reshape</span>([3,2,1],<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5,6])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([3,2,1],<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6])); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx25' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx26' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S1.SS1.p4" class="ltx_para"> | <div id='Ch2.S1.SS1.p4' class='ltx_para'> |
<p class="ltx_p">It prints three arrays:</p> | <p class='ltx_p'>It prints three arrays:</p> |
<ul id="Ch2.I1" class="ltx_itemize"> | <ul id='Ch2.S1.I1' class='ltx_itemize'> |
<li id="Ch2.I1.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S1.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I1.i1.p1" class="ltx_para"> | <div id='Ch2.S1.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p">an array of dimensionality 1 with 5 elements <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[1,2,3,4,5]</span></p> | <p class='ltx_p'>an array of dimensionality 1 with 5 elements <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[1,2,3,4,5]</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I1.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S1.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I1.i2.p1" class="ltx_para"> | <div id='Ch2.S1.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p">an array of dimensionality 2 with 3 rows and 2 columns, and</p> | <p class='ltx_p'>an array of dimensionality 2 with 3 rows and 2 columns, and</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I1.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S1.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I1.i3.p1" class="ltx_para"> | <div id='Ch2.S1.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p">a 3-dimensional array with 3 elements in the leftmost axis, | <p class='ltx_p'>a 3-dimensional array with 3 elements in the leftmost axis, |
2 elements in the middle axis, and one element in the rightmost axis.</p> | 2 elements in the middle axis, and one element in the rightmost axis.</p> |
</div> | </div> |
</ul> | </ul> |
</div> | </div> |
<div id="Ch2.S1.SS1.p5" class="ltx_para"> | <div id='Ch2.S1.SS1.p5' class='ltx_para'> |
<p class="ltx_p">Note here, that the function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">print</span> can be applied to arbitrary arrays. | <p class='ltx_p'>Note here, that the function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>print</span> can be applied to arbitrary arrays. |
Besides printing its argument’s dimensionality and shape, i.e. its shape vector, | Besides printing its argument’s dimensionality and shape, i.e. its shape vector, |
a more intuitive representation of the array’s data vector is shown. | a more intuitive representation of the array’s data vector is shown. |
Therefore, the 3-dimensional array is printed as a 2-dimensional array of vectors.</p> | Therefore, the 3-dimensional array is printed as a 2-dimensional array of vectors.</p> |
</div> | </div> |
<div id="Thmtheorem1" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem1' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 1. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 1. </h6> |
<div id="Thmtheorem1.p1" class="ltx_para"> | <div id='Thmtheorem1.p1' class='ltx_para'> |
<p class="ltx_p">In all these examples, the product of the shape vector matches the length of | <p class='ltx_p'>In all these examples, the product of the shape vector matches the length of |
the data vector. | the data vector. |
What do you expect to happen, if this condition does not hold?</p> | What do you expect to happen, if this condition does not hold?</p> |
</div> | </div> |
</div> | </div> |
<div id="Ch2.S1.SS1.p6" class="ltx_para ltx_noindent"> | <div id='Ch2.S1.SS1.p6' class='ltx_para ltx_noindent'> |
<p class="ltx_p">For reasons of convenience, we use the following terminology:</p> | <p class='ltx_p'>For reasons of convenience, we use the following terminology:</p> |
<dl id="Ch2.I2" class="ltx_description"> | <dl id='Ch2.S1.I2' class='ltx_description'> |
<dt id="Ch2.I2.ix1" class="ltx_item"><span class="ltx_tag ltx_tag_description">scalar</span></dt> | <dt id='Ch2.S1.I2.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>scalar</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I2.ix1.p1" class="ltx_para"> | <div id='Ch2.S1.I2.ix1.p1' class='ltx_para'> |
<p class="ltx_p">always denotes an array of dimensionality 0,</p> | <p class='ltx_p'>always denotes an array of dimensionality 0,</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I2.ix2" class="ltx_item"><span class="ltx_tag ltx_tag_description">vector</span></dt> | <dt id='Ch2.S1.I2.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>vector</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I2.ix2.p1" class="ltx_para"> | <div id='Ch2.S1.I2.ix2.p1' class='ltx_para'> |
<p class="ltx_p">always denotes an array of dimensionality 1, and</p> | <p class='ltx_p'>always denotes an array of dimensionality 1, and</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I2.ix3" class="ltx_item"><span class="ltx_tag ltx_tag_description">matrix</span></dt> | <dt id='Ch2.S1.I2.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>matrix</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I2.ix3.p1" class="ltx_para"> | <div id='Ch2.S1.I2.ix3.p1' class='ltx_para'> |
<p class="ltx_p">always denotes an array of dimensionality 2.</p> | <p class='ltx_p'>always denotes an array of dimensionality 2.</p> |
</div> | </div> |
</dd> | </dd> |
</dl> | </dl> |
</div> | </div> |
<div id="Ch2.S1.SS1.p7" class="ltx_para"> | <div id='Ch2.S1.SS1.p7' class='ltx_para'> |
<p class="ltx_p">As <em class="ltx_emph">all</em> arrays can be defined in terms of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reshape</span>, the following | <p class='ltx_p'>As <em class='ltx_emph ltx_font_italic'>all</em> arrays can be defined in terms of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span>, the following |
program as well is perfectly legal: | program as well is perfectly legal: |
</p> | </p> |
</div> | </div> |
<figure id="LST4" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST4' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 4: </span>Defining Arrays II</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 4: </span>Defining Arrays II</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQocmVz%0AaGFwZShbMV0sIFsxXSkpOwogIHByaW50KHJlc2hhcGUoW10sIFsxXSkpOwogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQocmVzaGFwZShbMV0sIFsxXSkpOwogIHByaW50KHJlc2hhcGUoW10sIFsxXSkpOwogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx27' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx28' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx29' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx30' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx31' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx32' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">reshape</span>([1],<span class="ltx_text ltx_lst_space"> </span>[1])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([1],<span class='ltx_text ltx_lst_space'> </span>[1])); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx33' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">reshape</span>([],<span class="ltx_text ltx_lst_space"> </span>[1])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([],<span class='ltx_text ltx_lst_space'> </span>[1])); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx34' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx35' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S1.SS1.p8" class="ltx_para"> | <div id='Ch2.S1.SS1.p8' class='ltx_para'> |
<p class="ltx_p">The most interesting aspect of this program is the array defined in | <p class='ltx_p'>The most interesting aspect of this program is the array defined in |
line 7. | line 7. |
The empty shape vector makes it a 0-dimensional array, i.e. a scalar. | 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> | The data vector carries the scalar’s value, which, in this example, is 1.</p> |
</div> | </div> |
<div id="Thmtheorem2" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem2' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 2. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 2. </h6> |
<div id="Thmtheorem2.p1" class="ltx_para"> | <div id='Thmtheorem2.p1' class='ltx_para'> |
<p class="ltx_p">The arguments of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reshape</span> are vectors, i.e. arrays of dimensionality 1. | <p class='ltx_p'>The arguments of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> are vectors, i.e. arrays of dimensionality 1. |
Can they be specified by <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">e</span> expressions themselves?</p> | Can they be specified by <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>e</span> expressions themselves?</p> |
</div> | </div> |
</div> | </div> |
<div id="Ch2.S1.SS1.p9" class="ltx_para"> | <div id='Ch2.S1.SS1.p9' class='ltx_para'> |
<p class="ltx_p">The <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reshape</span> notation is relatively clumsy, in particular, when | <p class='ltx_p'>The <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> notation is relatively clumsy, in particular, when |
being used for scalars. | being used for scalars. |
Therefore, scalars and vectors can alternatively be specified by | Therefore, scalars and vectors can alternatively be specified by |
shortcut notations as well.</p> | shortcut notations as well.</p> |
</div> | </div> |
<div id="Ch2.S1.SS1.p10" class="ltx_para"> | <div id='Ch2.S1.SS1.p10' class='ltx_para'> |
<p class="ltx_p">For experimenting with these, try the following:</p> | <p class='ltx_p'>For experimenting with these, try the following:</p> |
</div> | </div> |
<figure id="LST5" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST5' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 5: </span>Shortcut Notation for Arrays</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 5: </span>Shortcut Notation for Arrays</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQoMSk7%0ACiAgcHJpbnQoWzEsMiwzLDQsNV0pOwogIHByaW50KFtbMSwyXSwgWzMsNF0sIFs1LDZdXSk7CiAg%0AcHJpbnQoZ2VuYXJyYXkoWzQsMywyXSwgMSkpOwogIHByaW50KGdlbmFycmF5KFs0LDNdLCBbMSwy%0AXSkpOwogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgcHJpbnQoMSk7CiAgcHJpbnQoWzEsMiwzLDQsNV0pOwogIHByaW50KFtbMSwyXSwgWzMsNF0sIFs1LDZdXSk7CiAgcHJpbnQoZ2VuYXJyYXkoWzQsMywyXSwgMSkpOwogIHByaW50KGdlbmFycmF5KFs0LDNdLCBbMSwyXSkpOwogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx36' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx37' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx38' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx39' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx40' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx41' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(1); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(1); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx42' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>([1,2,3,4,5]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>([1,2,3,4,5]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx43' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>([[1,2],<span class="ltx_text ltx_lst_space"> </span>[3,4],<span class="ltx_text ltx_lst_space"> </span>[5,6]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>([[1,2],<span class='ltx_text ltx_lst_space'> </span>[3,4],<span class='ltx_text ltx_lst_space'> </span>[5,6]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx44' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">genarray</span>([4,3,2],<span class="ltx_text ltx_lst_space"> </span>1)); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>genarray</span>([4,3,2],<span class='ltx_text ltx_lst_space'> </span>1)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx45' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">genarray</span>([4,3],<span class="ltx_text ltx_lst_space"> </span>[1,2])); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>genarray</span>([4,3],<span class='ltx_text ltx_lst_space'> </span>[1,2])); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx46' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx47' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S1.SS1.p11" class="ltx_para"> | <div id='Ch2.S1.SS1.p11' class='ltx_para'> |
<p class="ltx_p">From these examples, we can see that scalars can be used in the same way as in most | <p class='ltx_p'>From these examples, we can see that scalars can be used in the same way as in most |
programming languages, and that the notation used for the parameters of | programming languages, and that the notation used for the parameters of |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reshape</span> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reshape</span> |
in the examples above in fact is a standard abbreviation of <span class="ltx_text ltx_font_smallcaps">SaC</span>. | in the examples above in fact is a standard abbreviation of <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
The example in line 8 shows that nestings of arrays are implicitly eliminated, i.e. | The example in line 8 shows that nestings of arrays are implicitly eliminated, i.e. |
the resulting array is identical to:</p> | the resulting array is identical to:</p> |
</div> | </div> |
<div id="Ch2.S1.SS1.p12" class="ltx_para"> | <div id='Ch2.S1.SS1.p12' class='ltx_para'> |
<p class="ltx_p ltx_align_center"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><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>.</p> | <p class='ltx_p ltx_align_center'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><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>.</p> |
</div> | </div> |
<div id="Ch2.S1.SS1.p13" class="ltx_para ltx_noindent"> | <div id='Ch2.S1.SS1.p13' class='ltx_para ltx_noindent'> |
<p class="ltx_p">For this reason, array nestings in <span class="ltx_text ltx_font_smallcaps">SaC</span> always have to be <em class="ltx_emph">homogeneous</em>, | <p class='ltx_p'>For this reason, array nestings in <span class='ltx_text ltx_font_smallcaps'>SaC</span> always have to be <em class='ltx_emph ltx_font_italic'>homogeneous</em>, |
i.e. the inner array components have to have identical shapes.</p> | i.e. the inner array components have to have identical shapes.</p> |
</div> | </div> |
<div id="Ch2.S1.SS1.p14" class="ltx_para"> | <div id='Ch2.S1.SS1.p14' class='ltx_para'> |
<p class="ltx_p">Furthermore, a new function is introduced: <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">genarray</span>. | <p class='ltx_p'>Furthermore, a new function is introduced: <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>genarray</span>. |
It expects two arguments, a shape vector that defines the shape of the result | It expects two arguments, a shape vector that defines the shape of the result |
and a default element to be inserted at each position of the result. | and a default element to be inserted at each position of the result. |
arrays as well, which implicitly extends the dimensionality of the result array.</p> | arrays as well, which implicitly extends the dimensionality of the result array.</p> |
</div> | </div> |
<div id="Thmtheorem3" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem3' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 3. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 3. </h6> |
<div id="Thmtheorem3.p1" class="ltx_para"> | <div id='Thmtheorem3.p1' class='ltx_para'> |
<p class="ltx_p">Given the language constructs introduced so far, can you define an array that would print as</p> | <p class='ltx_p'>Given the language constructs introduced so far, can you define an array that would print as</p> |
<pre class="ltx_verbatim ltx_font_typewriter"> | <pre class='ltx_verbatim ltx_font_typewriter'> |
Dimension: 3 | Dimension: 3 |
Shape : < 5, 2, 2> | Shape : < 5, 2, 2> |
< 0 0 > < 0 1 > | < 0 0 > < 0 1 > |
</pre> | </pre> |
<p class="ltx_p">but whose definition does not contain the symbol ‘1’ more than once?</p> | <p class='ltx_p'>but whose definition does not contain the symbol ‘1’ more than once?</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch2.S1.SS2" class="ltx_subsection"> | <section id='Ch2.S1.SS2' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">2.1.2 </span>Arrays and Variables</h5> | <span class='ltx_tag ltx_tag_subsection'>2.1.2 </span>Arrays and Variables</h5> |
| |
<div id="Ch2.S1.SS2.p1" class="ltx_para"> | <div id='Ch2.S1.SS2.p1' class='ltx_para'> |
<p class="ltx_p">This section explains why in <span class="ltx_text ltx_font_smallcaps">SaC</span> arrays are data and not containers for values | <p class='ltx_p'>This section explains why in <span class='ltx_text ltx_font_smallcaps'>SaC</span> arrays are data and not containers for values |
as found in most other languages.</p> | as found in most other languages.</p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p2" class="ltx_para"> | <div id='Ch2.S1.SS2.p2' class='ltx_para'> |
<p class="ltx_p">So far, all examples were expression based, i.e. we did not use any variables. | <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. | Traditionally, there are two different ways of introducing variables. |
In conventional (imperative) languages such as <span class="ltx_text ltx_font_smallcaps">C</span>, variables denote memory | In conventional (imperative) languages such as <span class='ltx_text ltx_font_smallcaps'>C</span>, variables denote memory |
locations which hold values that may change during computation. | locations which hold values that may change during computation. |
In functional languages, similar to mathematics, variables are considered place holders for values. | In functional languages, similar to mathematics, variables are considered place holders for values. |
are involved.</p> | are involved.</p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p3" class="ltx_para"> | <div id='Ch2.S1.SS2.p3' class='ltx_para'> |
<p class="ltx_p">Let’s have a look at an example:</p> | <p class='ltx_p'>Let’s have a look at an example:</p> |
</div> | </div> |
<figure id="LST6" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST6' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 6: </span>Variables as Placeholders</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 6: </span>Variables as Placeholders</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIs%0AMyw0XTsKICBwcmludChhKTsKCiAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgcHJpbnQoYik7%0ACgogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIsMyw0XTsKICBwcmludChhKTsKCiAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgcHJpbnQoYik7CgogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx48' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx49' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx50' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx51' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx52' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx53' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx54' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx55' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx56' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">b</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">modarray</span>(<span class="ltx_text ltx_lst_identifier">a</span>,<span class="ltx_text ltx_lst_space"> </span>[0],<span class="ltx_text ltx_lst_space"> </span>9); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>9); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx57' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">b</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>b</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx58' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx59' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx60' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S1.SS2.p4" class="ltx_para"> | <div id='Ch2.S1.SS2.p4' class='ltx_para'> |
<p class="ltx_p">The function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">modarray</span> expects three arguments: an array to be “modified”, | <p class='ltx_p'>The function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span> expects three arguments: an array to be “modified”, |
an index that indicates the exact position within the array to be “modified”, | an index that indicates the exact position within the array to be “modified”, |
and the value that is to be inserted at the specified position. | and the value that is to be inserted at the specified position. |
As we would expect, the resulting array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">b</span> is almost identical to <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>, | As we would expect, the resulting array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>b</span> is almost identical to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>, |
only the very first element has changed into <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">9</span>.</p> | only the very first element has changed into <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>9</span>.</p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p5" class="ltx_para"> | <div id='Ch2.S1.SS2.p5' class='ltx_para'> |
<p class="ltx_p ltx_align_center"><span class="ltx_text ltx_font_bold">Note here, that indexing in </span><span class="ltx_text ltx_font_smallcaps">SaC</span><span class="ltx_text ltx_font_bold"> always starts with index <span class="ltx_text ltx_lstlisting"></span>!</span></p> | <p class='ltx_p ltx_align_center'><span class='ltx_text ltx_font_bold'>Note here, that indexing in </span><span class='ltx_text ltx_font_smallcaps'>SaC</span><span class='ltx_text ltx_font_bold'> always starts with index <span class='ltx_text ltx_lstlisting'></span>!</span></p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p6" class="ltx_para"> | <div id='Ch2.S1.SS2.p6' class='ltx_para'> |
<p class="ltx_p">Referring to the container / place holder discussion, the crucial question is: | <p class='ltx_p'>Referring to the container / place holder discussion, the crucial question is: |
does the variable <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> denote a container, whose value is changed by | does the variable <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> denote a container, whose value is changed by |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">modarray</span>? If this would be the case, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">b</span> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span>? If this would be the case, <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>b</span> |
would share the same container, and every access to <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> after | would share the same container, and every access to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> after |
line 9 would | line 9 would |
yield <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[9,2,3,4]</span>. If <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> in fact is a place holder, it will | yield <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[9,2,3,4]</span>. If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> in fact is a place holder, it will |
always denote the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[1,2,3,4]</span>, no matter what functions have | always denote the array <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[1,2,3,4]</span>, no matter what functions have |
obtained <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> as an argument.</p> | obtained <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> as an argument.</p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p7" class="ltx_para"> | <div id='Ch2.S1.SS2.p7' class='ltx_para'> |
<p class="ltx_p">To answer this question, you may simply shift the first call of | <p class='ltx_p'>To answer this question, you may simply shift the first call of |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">print</span> two lines down. As you can see, in <span class="ltx_text ltx_font_smallcaps">SaC</span>, variables are indeed | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>print</span> two lines down. As you can see, in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, variables are indeed |
place holders.</p> | place holders.</p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p8" class="ltx_para"> | <div id='Ch2.S1.SS2.p8' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle ltx_framed_rectangle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch2.S1.SS2.p8.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_bold">A note for efficiency freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for efficiency freaks:</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">You may wonder whether this implies that <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">modarray</span> always copies the entire array. | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>You may wonder whether this implies that <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span> always copies the entire array. |
In fact, it only copies <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> if the place-holder property would be violated otherwise.</span></span> | In fact, it only copies <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> if the place-holder property would be violated otherwise.</span></span> |
</span> | </span></span> |
</p> | </p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p9" class="ltx_para"> | <div id='Ch2.S1.SS2.p9' class='ltx_para'> |
<p class="ltx_p">As a result of this place-holder property, it is guaranteed that no function call can affect | <p class='ltx_p'>As a result of this place-holder property, it is guaranteed that no function call can affect |
the value of its arguments. | the value of its arguments. |
In other words, the underlying concept <em class="ltx_emph">guarantees</em>, that all functions are | In other words, the underlying concept <em class='ltx_emph ltx_font_italic'>guarantees</em>, that all functions are |
“pure”. | “pure”. |
Although this helps in avoiding nasty errors due to non-intended side-effects, | Although this helps in avoiding nasty errors due to non-intended side-effects, |
in particular, if arrays are to be modified successively.</p> | in particular, if arrays are to be modified successively.</p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p10" class="ltx_para"> | <div id='Ch2.S1.SS2.p10' class='ltx_para'> |
<p class="ltx_p">To cope with this problem, in <span class="ltx_text ltx_font_smallcaps">SaC</span>, variables do have a so-called <em class="ltx_emph">scope</em>, i.e. each variable definition is associated with a well-defined portion of program code | <p class='ltx_p'>To cope with this problem, in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, variables do have a so-called <em class='ltx_emph ltx_font_italic'>scope</em>, i.e. each variable definition is associated with a well-defined portion of program code |
where its definition is valid. | where its definition is valid. |
In a sequence of variable definitions, the scope of a variable starts with the left-hand | In a sequence of variable definitions, the scope of a variable starts with the left-hand |
This measure allows us to reuse variable names. | This measure allows us to reuse variable names. |
A slight modification of our example demonstrates the effect of variable scopes | A slight modification of our example demonstrates the effect of variable scopes |
in <span class="ltx_text ltx_font_smallcaps">SaC</span>:</p> | in <span class='ltx_text ltx_font_smallcaps'>SaC</span>:</p> |
</div> | </div> |
<figure id="LST7" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST7' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 7: </span>Variable Scopes</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 7: </span>Variable Scopes</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIs%0AMyw0XTsKCiAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgcHJpbnQoYSk7CiAgYSA9IGI7CiAg%0AcHJpbnQoYSk7CgogIGEgPSBtb2RhcnJheShhLCBbMV0sIDgpOwogIHByaW50KGEpOwoKICByZXR1%0Acm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIsMyw0XTsKCiAgYiA9IG1vZGFycmF5KGEsIFswXSwgOSk7CiAgcHJpbnQoYSk7CiAgYSA9IGI7CiAgcHJpbnQoYSk7CgogIGEgPSBtb2RhcnJheShhLCBbMV0sIDgpOwogIHByaW50KGEpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx61' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx62' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx63' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx64' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx65' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx66' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx67' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx68' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">b</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">modarray</span>(<span class="ltx_text ltx_lst_identifier">a</span>,<span class="ltx_text ltx_lst_space"> </span>[0],<span class="ltx_text ltx_lst_space"> </span>9); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>9); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx69' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx70' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">b</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx71' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx72' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx73' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">modarray</span>(<span class="ltx_text ltx_lst_identifier">a</span>,<span class="ltx_text ltx_lst_space"> </span>[1],<span class="ltx_text ltx_lst_space"> </span>8); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[1],<span class='ltx_text ltx_lst_space'> </span>8); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx74' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx75' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx76' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx77' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S1.SS2.p11" class="ltx_para"> | <div id='Ch2.S1.SS2.p11' class='ltx_para'> |
<p class="ltx_p">Here, the use of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> on the right-hand side of line 9 still refers | <p class='ltx_p'>Here, the use of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> on the right-hand side of line 9 still refers |
to the definition of line 6, whereas the use in line 11 refers to the definition | to the definition of line 6, whereas the use in line 11 refers to the definition |
in line 10.</p> | in line 10.</p> |
</div> | </div> |
<div id="Ch2.S1.SS2.p12" class="ltx_para"> | <div id='Ch2.S1.SS2.p12' class='ltx_para'> |
<p class="ltx_p">The definition in line 13 shows, how variable scopes can be used to specify | <p class='ltx_p'>The definition in line 13 shows, how variable scopes can be used to specify |
code that looks very much “imperative”. | code that looks very much “imperative”. |
However, you should always keep in mind, that in <span class="ltx_text ltx_font_smallcaps">SaC</span>, the place-holder property | However, you should always keep in mind, that in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, the place-holder property |
<em class="ltx_emph">always</em> holds!</p> | <em class='ltx_emph ltx_font_italic'>always</em> holds!</p> |
</div> | </div> |
<div id="Thmtheorem4" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem4' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 4. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 4. </h6> |
<div id="Thmtheorem4.p1" class="ltx_para"> | <div id='Thmtheorem4.p1' class='ltx_para'> |
<p class="ltx_p">What result do you expect from the following <span class="ltx_text ltx_font_smallcaps">SaC</span> program?</p> | <p class='ltx_p'>What result do you expect from the following <span class='ltx_text ltx_font_smallcaps'>SaC</span> program?</p> |
</div> | </div> |
</div> | </div> |
<figure id="LST8" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST8' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 8: </span>Scope Exercise</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 8: </span>Scope Exercise</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIs%0AMyw0XTsKICBiID0gW2EsYV07CgogIGEgPSBtb2RhcnJheShtb2RhcnJheShhLCBbMF0sIDApLCBb%0AMV0sIDApOwogIGIgPSBtb2RhcnJheShiLCBbMF0sIGEpOwogIHByaW50KGIpOwoKICByZXR1cm4g%0AMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IFsxLDIsMyw0XTsKICBiID0gW2EsYV07CgogIGEgPSBtb2RhcnJheShtb2RhcnJheShhLCBbMF0sIDApLCBbMV0sIDApOwogIGIgPSBtb2RhcnJheShiLCBbMF0sIGEpOwogIHByaW50KGIpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx78' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx79' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx80' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx81' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx82' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx83' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx84' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">b</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[<span class="ltx_text ltx_lst_identifier">a</span>,<span class="ltx_text ltx_lst_identifier">a</span>]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_identifier'>a</span>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx85' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx86' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">modarray</span>(<span class="ltx_text ltx_lst_identifier">modarray</span>(<span class="ltx_text ltx_lst_identifier">a</span>,<span class="ltx_text ltx_lst_space"> </span>[0],<span class="ltx_text ltx_lst_space"> </span>0),<span class="ltx_text ltx_lst_space"> </span>[1],<span class="ltx_text ltx_lst_space"> </span>0); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span>0),<span class='ltx_text ltx_lst_space'> </span>[1],<span class='ltx_text ltx_lst_space'> </span>0); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx87' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">b</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">modarray</span>(<span class="ltx_text ltx_lst_identifier">b</span>,<span class="ltx_text ltx_lst_space"> </span>[0],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>b</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>b</span>,<span class='ltx_text ltx_lst_space'> </span>[0],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx88' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">b</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>b</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx89' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx90' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx91' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</section> | </section> |
</section> | </section> |
<section id="Ch2.S2" class="ltx_section"> | <section id='Ch2.S2' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">2.2 </span>Lesson 2: Shape-Invariant Programming</h4> | <span class='ltx_tag ltx_tag_section'>2.2 </span>Lesson 2: Shape-Invariant Programming</h4> |
| |
<div id="Ch2.S2.p1" class="ltx_para"> | <div id='Ch2.S2.p1' class='ltx_para'> |
<p class="ltx_p">The term <em class="ltx_emph">shape-invariant programming</em> refers to a programming style | <p class='ltx_p'>The term <em class='ltx_emph ltx_font_italic'>shape-invariant programming</em> refers to a programming style |
where all array operations are defined in terms of operations that | where all array operations are defined in terms of operations that |
are applied to entire arrays rather than to individual array elements. | are applied to entire arrays rather than to individual array elements. |
In order to realize such a programming style, it is an essential | In order to realize such a programming style, it is an essential |
prerequisite to be able to apply functions to arbitrarily shaped arguments. | prerequisite to be able to apply functions to arbitrarily shaped arguments. |
In <span class="ltx_text ltx_font_smallcaps">SaC</span>, this is the case.</p> | In <span class='ltx_text ltx_font_smallcaps'>SaC</span>, this is the case.</p> |
</div> | </div> |
<div id="Ch2.S2.p2" class="ltx_para"> | <div id='Ch2.S2.p2' class='ltx_para'> |
<p class="ltx_p">All built-in array operations as well as all array operations supplied by the | <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. | standard library can be applied to arguments of arbitrary shapes. |
However, most of the operations that require more than one argument do have | However, most of the operations that require more than one argument do have |
such a kind of domain error and produce a runtime error instead.</p> | such a kind of domain error and produce a runtime error instead.</p> |
</div> | </div> |
<div id="Ch2.S2.p3" class="ltx_para"> | <div id='Ch2.S2.p3' class='ltx_para'> |
<p class="ltx_p">This lesson consists of three parts: | <p class='ltx_p'>This lesson consists of three parts: |
The section on <span class="ltx_text ltx_font_italic">Standard Array Operations</span> introduces the most important | The section on <span class='ltx_text ltx_font_italic'>Standard Array Operations</span> introduces the most important |
standard array operations provided by the current <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler | standard array operations provided by the current <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler |
release<span class="ltx_note ltx_role_footnote"><sup class="ltx_note_mark">1</sup><span class="ltx_note_outer"><span class="ltx_note_content"><sup class="ltx_note_mark">1</sup>As of this writing, the latest <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler release | release<span id='Ch2.footnote1' class='ltx_note ltx_role_footnote'><sup class='ltx_note_mark'>1</sup><span class='ltx_note_outer'><span class='ltx_note_content'><sup class='ltx_note_mark'>1</sup> |
is version 1.2.</span></span></span>. | <span class='ltx_tag ltx_tag_note'>1</span> |
The next section explains <span class="ltx_text ltx_font_italic">Axis Control Notation</span>, a powerful but simple | |
| |
| As of this writing, the latest <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler release |
| is version 1.2.1.</span></span></span>. |
| The next section explains <span class='ltx_text ltx_font_italic'>Axis Control Notation</span>, a powerful but simple |
way of manipulating the focus of array operations with respect to individual axes of argument arrays. | way of manipulating the focus of array operations with respect to individual axes of argument arrays. |
With the axis-control notation, the basic operations often can easily be combined into rather | With the axis-control notation, the basic operations often can easily be combined into rather |
complex operations as demonstrated in the section on <span class="ltx_text ltx_font_italic">Putting it all Together</span>.</p> | complex operations as demonstrated in the section on <span class='ltx_text ltx_font_italic'>Putting it all Together</span>.</p> |
</div> | </div> |
<section id="Ch2.S2.SS1" class="ltx_subsection"> | <section id='Ch2.S2.SS1' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">2.2.1 </span>Standard Array Operations</h5> | <span class='ltx_tag ltx_tag_subsection'>2.2.1 </span>Standard Array Operations</h5> |
| |
<div id="Ch2.S2.SS1.p1" class="ltx_para"> | <div id='Ch2.S2.SS1.p1' class='ltx_para'> |
<p class="ltx_p">In the sequel, several toy examples demonstrate the functionality of the most basic | <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 <span class="ltx_text ltx_font_smallcaps">SaC</span> release. | array operations that come as part of the current <span class='ltx_text ltx_font_smallcaps'>SaC</span> release. |
Their design is inspired by those available in <span class="ltx_text ltx_font_smallcaps">APL</span>. | Their design is inspired by those available in <span class='ltx_text ltx_font_smallcaps'>APL</span>. |
However, several aspects — in particular regarding the treatment of special | However, several aspects — in particular regarding the treatment of special |
cases in <span class="ltx_text ltx_font_smallcaps">APL</span> — have | cases in <span class='ltx_text ltx_font_smallcaps'>APL</span> — have |
been adjusted to allow for a more favourable compilation in <span class="ltx_text ltx_font_smallcaps">SaC</span> that yields better runtime performance.</p> | been adjusted to allow for a more favourable compilation in <span class='ltx_text ltx_font_smallcaps'>SaC</span> that yields better runtime performance.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.p2" class="ltx_para"> | <div id='Ch2.S2.SS1.p2' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'><span class='ltx_text ltx_framed_rectangle' style='border-color: black;'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch2.S2.SS1.p2.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_bold">A note for language design freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for language design freaks:</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">You may have your own ideas on what primitive array operations should be available | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>You may have your own ideas on what primitive array operations should be available |
and how the precise semantics of these should look like. | and how the precise semantics of these should look like. |
Therefore, it should be mentioned here, that </span><span class="ltx_text ltx_font_bold">all</span><span class="ltx_text ltx_font_italic"> array operations introduced in the | Therefore, it should be mentioned here, that </span><span class='ltx_text ltx_font_bold'>all</span><span class='ltx_text ltx_font_italic'> array operations introduced in the |
remainder of this section are not | remainder of this section are not |
hard-wired into the language, but they are defined in the module <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">Array</span> | hard-wired into the language, but they are defined in the module <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>Array</span> |
from the standard library. | from the standard library. |
This is to say that the advanced <span class="ltx_text ltx_font_smallcaps">SaC</span> programmer may write his own set of | This is to say that the advanced <span class='ltx_text ltx_font_smallcaps'>SaC</span> programmer may write his own set of |
standard array operations. | standard array operations.</span></span> |
</span></span> | </span></span> |
</span> | </span></p> |
</p> | |
</div> | </div> |
<div id="Ch2.S2.SS1.p3" class="ltx_para"> | <div id='Ch2.S2.SS1.p3' class='ltx_para'> |
<p class="ltx_p">The individual parts of this section are all organized according | <p class='ltx_p'>The individual parts of this section are all organized according |
to the following scheme: | to the following scheme: |
first, a semi-formal introduction to the functionality of individual operations | first, a semi-formal introduction to the functionality of individual operations |
with respect to domain restrictions if these do exist‘.</p> | with respect to domain restrictions if these do exist‘.</p> |
</div> | </div> |
<section id="Ch2.S2.SS1.SSSx1" class="ltx_subsubsection"> | <section id='Ch2.S2.SS1.SSSx1' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Basic Operations</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Basic Operations</h6> |
| |
<div id="Ch2.S2.SS1.SSSx1.p1" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx1.p1' class='ltx_para'> |
<p class="ltx_p">The most basic operations are very close to the model of arrays in <span class="ltx_text ltx_font_smallcaps">SaC</span>. | <p class='ltx_p'>The most basic operations are very close to the model of arrays in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
They comprise functions for inspecting, creating, and modifying an array’s | They comprise functions for inspecting, creating, and modifying an array’s |
shape and content. | shape and content. |
already.</p> | already.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx1.p2" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx1.p2' class='ltx_para'> |
<dl id="Ch2.I3" class="ltx_description"> | <dl id='Ch2.S2.I1' class='ltx_description'> |
<dt id="Ch2.I3.ix1" class="ltx_item"><span class="ltx_tag ltx_tag_description">dim(a)</span></dt> | <dt id='Ch2.S2.I1.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>dim(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I3.ix1.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix1.p1' class='ltx_para'> |
<p class="ltx_p">returns the (scalar) dimensionality of the argument array | <p class='ltx_p'>returns the (scalar) dimensionality of the argument array |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>: none.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: none.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I3.ix2" class="ltx_item"><span class="ltx_tag ltx_tag_description">shape(a)</span></dt> | <dt id='Ch2.S2.I1.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>shape(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I3.ix2.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix2.p1' class='ltx_para'> |
<p class="ltx_p">returns the shape vector of the argument array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. | <p class='ltx_p'>returns the shape vector of the argument array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>: none.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: none.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I3.ix3" class="ltx_item"><span class="ltx_tag ltx_tag_description">a[iv]</span></dt> | <dt id='Ch2.S2.I1.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>a[iv]</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I3.ix3.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix3.p1' class='ltx_para'> |
<p class="ltx_p">constitutes a short-cut notation for <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">sel</span>(<span class="ltx_text ltx_lst_identifier">iv</span>,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>)</span>. | <p class='ltx_p'>constitutes a short-cut notation for <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>sel</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>. |
It selects the array element of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> at index position <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">iv</span>. | It selects the array element of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> at index position <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span>. |
As <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> may be of any shape, the index position is given as an | As <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> may be of any shape, the index position is given as an |
<em class="ltx_emph">index vector</em>. The dimensionality of the result is identical to the dimensionality of | <em class='ltx_emph ltx_font_italic'>index vector</em>. The dimensionality of the result is identical to the dimensionality of |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> minus the length of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">iv</span>. | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> minus the length of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span>. |
Accordingly, its shape is derived from the last components of | Accordingly, its shape is derived from the last components of |
the shape of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. | the shape of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I3.I1" class="ltx_itemize"> | <ul id='Ch2.S2.I1.ix3.I1' class='ltx_itemize'> |
<li id="Ch2.I3.I1.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix3.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I1.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix3.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">iv</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I3.I1.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix3.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I1.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix3.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">iv</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I3.I1.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix3.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I1.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix3.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I3.I1.i3.p1.m1" class="ltx_Math" alttext="{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I1.ix3.I1.i3.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}" display="inline"><mrow><mrow><mrow><mo>∀</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</mtext></mrow><mo>∈</mo><mrow><mo stretchy="false">{</mo><mn>0</mn><mo>,</mo><mi mathvariant="normal">…</mi><mo>,</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy="false">}</mo></mrow></mrow><mo>:</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math>.</p> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape% |
| }}({\@listingGroup{ltx_lst_identifier}{iv}})[[0]]}}}}\}:\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{iv}}[% |
| [{\@listingGroup{ltx_lst_identifier}{i}}]]{\@listingGroup{ltx_lst_space}{~{}}}% |
| \textless{\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{% |
| ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}{a}})[[{% |
| \@listingGroup{ltx_lst_identifier}{i}}]]}}}}' display='inline'><mrow><mrow><mrow><mo>∀</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</mtext></mrow><mo>∈</mo><mrow><mo stretchy='false'>{</mo><mn>0</mn><mo>,</mo><mi mathvariant='normal'>…</mi><mo>,</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy='false'>}</mo></mrow></mrow><mo>:</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math>.</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I3.ix4" class="ltx_item"><span class="ltx_tag ltx_tag_description">a[iv]=expr</span></dt> | <dt id='Ch2.S2.I1.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>a[iv]=expr</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I3.ix4.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix4.p1' class='ltx_para'> |
<p class="ltx_p">is a short-cut notation for an assignment of the form | <p class='ltx_p'>is a short-cut notation for an assignment of the form |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">modarray</span>(<span class="ltx_text ltx_lst_identifier">a</span>,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">iv</span>,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">expr</span>)</span>. | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>modarray</span>(<span class='ltx_text ltx_lst_identifier'>a</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>iv</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>expr</span>)</span>. |
The result of this application is a new array which is almost identical to | The result of this application is a new array which is almost identical to |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. Only the element (subarray) at index position <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">iv</span> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. Only the element (subarray) at index position <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span> |
is different; it is replaced by <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">expr</span>. | is different; it is replaced by <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expr</span>. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I3.I2" class="ltx_itemize"> | <ul id='Ch2.S2.I1.ix4.I2' class='ltx_itemize'> |
<li id="Ch2.I3.I2.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix4.I2.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I2.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix4.I2.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">iv</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I3.I2.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix4.I2.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I2.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix4.I2.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">iv</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>iv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I3.I2.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix4.I2.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I2.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix4.I2.i3.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I3.I2.i3.p1.m1" class="ltx_Math" alttext="{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I1.ix4.I2.i3.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}" display="inline"><mrow><mrow><mrow><mo>∀</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</mtext></mrow><mo>∈</mo><mrow><mo stretchy="false">{</mo><mn>0</mn><mo>,</mo><mi mathvariant="normal">…</mi><mo>,</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy="false">}</mo></mrow></mrow><mo>:</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math></p> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape% |
| }}({\@listingGroup{ltx_lst_identifier}{iv}})[[0]]}}}}\}:\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{iv}}[% |
| [{\@listingGroup{ltx_lst_identifier}{i}}]]{\@listingGroup{ltx_lst_space}{~{}}}% |
| \textless{\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{% |
| ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}{a}})[[{% |
| \@listingGroup{ltx_lst_identifier}{i}}]]}}}}' display='inline'><mrow><mrow><mrow><mo>∀</mo><mtext class='ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</mtext></mrow><mo>∈</mo><mrow><mo stretchy='false'>{</mo><mn>0</mn><mo>,</mo><mi mathvariant='normal'>…</mi><mo>,</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>iv</mtext><mtext>)[[0]]</mtext></mrow><mo stretchy='false'>}</mo></mrow></mrow><mo>:</mo><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>iv</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext><mtext> </mtext><mtext><</mtext><mtext> </mtext><mtext>shape</mtext><mtext>(</mtext><mtext>a</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></math></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I3.I2.i4" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix4.I2.i4' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I2.i4.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix4.I2.i4.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">expr</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">a</span>[<span class="ltx_text ltx_lst_identifier">iv</span>])</span>.</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>expr</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>a</span>[<span class='ltx_text ltx_lst_identifier'>iv</span>])</span>.</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I3.ix5" class="ltx_item"><span class="ltx_tag ltx_tag_description">reshape(shp, expr)</span></dt> | <dt id='Ch2.S2.I1.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>reshape(shp, expr)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I3.ix5.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix5.p1' class='ltx_para'> |
<p class="ltx_p">computes an array with shape vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">shp</span> | <p class='ltx_p'>computes an array with shape vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>shp</span> |
and data vector identical to that of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">expr</span>. | and data vector identical to that of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expr</span>. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I3.I3" class="ltx_itemize"> | <ul id='Ch2.S2.I1.ix5.I3' class='ltx_itemize'> |
<li id="Ch2.I3.I3.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix5.I3.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I3.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix5.I3.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">shp</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>shp</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I3.I3.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I1.ix5.I3.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I3.I3.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix5.I3.i2.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I3.I3.i2.p1.m1" class="ltx_Math" alttext="{{{{{{{{\prod\limits_{i=0}^{{\textrm{\lstinline 1}}}}}\textrm{\lstinline 1}}}=\prod% | <p class='ltx_p'><math id='Ch2.S2.I1.ix5.I3.i2.p1.m1' class='ltx_Math' alttext='{{{{\prod\limits_{i=0}^{{\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\limits_{i=0}^{{\textrm{\lstinline 1}}}}}\textrm{\lstinline 1}}}" display="inline"><mrow><mrow><munderover><mo largeop="true" movablelimits="false" symmetric="true">∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>shp</mtext><mtext>)[[0]]-1</mtext></mrow></munderover><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shp</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow><mo>=</mo><mrow><munderover><mo largeop="true" movablelimits="false" symmetric="true">∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>dim</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)-1</mtext></mrow></munderover><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></mrow></math>.</p> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{ltx_lst_identifier}% |
| {shp}})[[0]]-1}}}}}}\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
| \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{shp}}[[{\@listingGroup{ltx_lst_identifier}{% |
| i}}]]}}}}=\prod\limits_{i=0}^{{\textrm{\lstinline{{\lst@@@set@language% |
| \lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language% |
| \lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{dim}}({\@listingGroup{% |
| ltx_lst_identifier}{expr}})-1}}}}}}\textrm{\lstinline{{\lst@@@set@language% |
| \lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language% |
| \lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape}}({\@listingGroup{% |
| ltx_lst_identifier}{expr}})[[{\@listingGroup{ltx_lst_identifier}{i}}]]}}}}' display='inline'><mrow><mrow><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>shp</mtext><mtext>)[[0]]-1</mtext></mrow></munderover><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shp</mtext><mtext>[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow><mo>=</mo><mrow><munderover><mo largeop='true' movablelimits='false' symmetric='true'>∏</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>dim</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)-1</mtext></mrow></munderover><mrow class='ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><mtext>shape</mtext><mtext>(</mtext><mtext>expr</mtext><mtext>)[[</mtext><mtext>i</mtext><mtext>]]</mtext></mrow></mrow></mrow></math>.</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I3.ix6" class="ltx_item"><span class="ltx_tag ltx_tag_description">genarray(shp, expr)</span></dt> | <dt id='Ch2.S2.I1.ix6' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>genarray(shp, expr)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I3.ix6.p1" class="ltx_para"> | <div id='Ch2.S2.I1.ix6.p1' class='ltx_para'> |
<p class="ltx_p">generates an array of shape <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">shp</span>, | <p class='ltx_p'>generates an array of shape <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>shp</span>, |
whose elements are all identical to <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">expr</span>. | whose elements are all identical to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expr</span>. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>: <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">shp</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span>.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>shp</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span>.</p> |
</div> | </div> |
</dd> | </dd> |
</dl> | </dl> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx1.p3" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx1.p3' class='ltx_para'> |
<p class="ltx_p">Although these operations are fairly self-explaining or known from | <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"><span class="ltx_text ltx_ref_tag">2.1</span></a> on <span class="ltx_text ltx_font_bold">Arrays as Data</span>, let us have a look | 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'><span class='ltx_text ltx_ref_tag'>2.1</span></a> on <span class='ltx_text ltx_font_bold'>Arrays as Data</span>, let us have a look |
at a few example applications:</p> | at a few example applications:</p> |
</div> | </div> |
<figure id="LST9" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST9' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 9: </span>Basic Operations</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 9: </span>Basic Operations</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsx%0ALDIsMyw0LDUsNiw3LDgsOSwxMCwxMSwxMl07CgogIG1hdCA9IHJlc2hhcGUoWzMsNF0sIHZlY3Qp%0AOwogIHByaW50KG1hdCk7CgogIHByaW50KG1hdFtbMSwxXV0pOwogIHByaW50KG1hdFtbMl1dKTsK%0AICBwcmludChtYXRbW11dKTsKCiAgbWF0W1sxLDFdXSA9IDA7CiAgcHJpbnQobWF0KTsKICBtYXRb%0AWzJdXSA9IFswLDAsMCwwXTsKICBwcmludChtYXQpOwogIG1hdFtbXV0gPSBnZW5hcnJheShbMyw0%0AXSwgMCk7CiAgcHJpbnQobWF0KTsKCiAgZW1wdHlfdmVjdCA9IFtdOwogIHByaW50KGVtcHR5X3Zl%0AY3QpOwogIGVtcHR5X21hdCA9IHJlc2hhcGUoWzIyLDBdLCBlbXB0eV92ZWN0KTsKICBwcmludChl%0AbXB0eV9tYXQpOwogIHByaW50KGRpbShlbXB0eV9tYXQpKTsKICBwcmludChzaGFwZShlbXB0eV9t%0AYXQpKTsKCiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsxLDIsMyw0LDUsNiw3LDgsOSwxMCwxMSwxMl07CgogIG1hdCA9IHJlc2hhcGUoWzMsNF0sIHZlY3QpOwogIHByaW50KG1hdCk7CgogIHByaW50KG1hdFtbMSwxXV0pOwogIHByaW50KG1hdFtbMl1dKTsKICBwcmludChtYXRbW11dKTsKCiAgbWF0W1sxLDFdXSA9IDA7CiAgcHJpbnQobWF0KTsKICBtYXRbWzJdXSA9IFswLDAsMCwwXTsKICBwcmludChtYXQpOwogIG1hdFtbXV0gPSBnZW5hcnJheShbMyw0XSwgMCk7CiAgcHJpbnQobWF0KTsKCiAgZW1wdHlfdmVjdCA9IFtdOwogIHByaW50KGVtcHR5X3ZlY3QpOwogIGVtcHR5X21hdCA9IHJlc2hhcGUoWzIyLDBdLCBlbXB0eV92ZWN0KTsKICBwcmludChlbXB0eV9tYXQpOwogIHByaW50KGRpbShlbXB0eV9tYXQpKTsKICBwcmludChzaGFwZShlbXB0eV9tYXQpKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx92' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx93' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx94' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx95' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx96' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx97' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5,6,7,8,9,10,11,12]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[1,2,3,4,5,6,7,8,9,10,11,12]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx98' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx99' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">reshape</span>([3,4],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,4],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>vect</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx100' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx101' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx102' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[1,1]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[1,1]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx103' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[2]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[2]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx104' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[]]); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>[[]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx105' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx106' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span>[[1,1]]<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[1,1]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx107' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx108' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span>[[2]]<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[0,0,0,0]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[2]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[0,0,0,0]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx109' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx110' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span>[[]]<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">genarray</span>([3,4],<span class="ltx_text ltx_lst_space"> </span>0); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span>[[]]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>genarray</span>([3,4],<span class='ltx_text ltx_lst_space'> </span>0); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx111' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx112' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx113' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">empty_vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_vect</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>[]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx114' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">empty_vect</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>23</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>empty_vect</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx115' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">empty_mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">reshape</span>([22,0],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">empty_vect</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>24</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_mat</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>reshape</span>([22,0],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>empty_vect</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx116' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">empty_mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx117' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">empty_mat</span>)); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx118' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">empty_mat</span>)); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>27</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>empty_mat</span>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx119' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">28</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx120' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">29</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx121' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">30</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>30</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS1.SSSx1.p4" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx1.p4' class='ltx_para'> |
<p class="ltx_p">The different selections in lines 11-13 show how | <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 | 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 | vector decreases. If the index vector degenerates into an empty vector, the |
of individual elements, rows, or the entire array.</p> | of individual elements, rows, or the entire array.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx1.p5" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx1.p5' class='ltx_para'> |
<p class="ltx_p">Lines 22-27 are meant to draw the reader’s | <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 | attention to the fact that there exists an unlimited number of distinct empty |
arrays in <span class="ltx_text ltx_font_smallcaps">SaC</span>!</p> | arrays in <span class='ltx_text ltx_font_smallcaps'>SaC</span>!</p> |
</div> | </div> |
<div id="Thmtheorem5" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem5' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 5. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 5. </h6> |
<div id="Thmtheorem5.p1" class="ltx_para"> | <div id='Thmtheorem5.p1' class='ltx_para'> |
<p class="ltx_p">Assuming <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span> to be defined as in the previous example, what results do you | <p class='ltx_p'>Assuming <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> to be defined as in the previous example, what results do you |
expect from the following expressions:</p> | expect from the following expressions:</p> |
<ul id="Ch2.I4" class="ltx_itemize"> | <ul id='Ch2.S2.I2' class='ltx_itemize'> |
<li id="Ch2.I4.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I2.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I4.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I2.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([3,0,5],<span class="ltx_text ltx_lst_space"> </span>[])[[]]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[]]</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I4.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I2.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I4.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I2.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([3,0,5],<span class="ltx_text ltx_lst_space"> </span>[])[[1]]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[1]]</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I4.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I2.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I4.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I2.i3.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([3,0,5],<span class="ltx_text ltx_lst_space"> </span>[])[[1,0]]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[[1,0]]</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I4.i4" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I2.i4' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I4.i4.p1" class="ltx_para"> | <div id='Ch2.S2.I2.i4.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">mat</span>[<span class="ltx_text ltx_lst_identifier">reshape</span>([2,0],<span class="ltx_text ltx_lst_space"> </span>[])]</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>mat</span>[<span class='ltx_text ltx_lst_identifier'>reshape</span>([2,0],<span class='ltx_text ltx_lst_space'> </span>[])]</span>?</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</section> | </section> |
<section id="Ch2.S2.SS1.SSSx2" class="ltx_subsubsection"> | <section id='Ch2.S2.SS1.SSSx2' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Element-wise Extensions</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Element-wise Extensions</h6> |
| |
<div id="Ch2.S2.SS1.SSSx2.p1" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx2.p1' class='ltx_para'> |
<p class="ltx_p">Most of the operations that can be found as standard operations on scalars | <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 <span class="ltx_text ltx_font_smallcaps">SaC</span>. | in other languages are applicable to entire arrays in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
Their semantics are simply element-wise extensions of the well-known scalar | Their semantics are simply element-wise extensions of the well-known scalar |
operations. | operations. |
argument arrays.</p> | argument arrays.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx2.p2" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx2.p2' class='ltx_para'> |
<p class="ltx_p">In detail, the following operations are available:</p> | <p class='ltx_p'>In detail, the following operations are available:</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx2.p3" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx2.p3' class='ltx_para'> |
<dl id="Ch2.I5" class="ltx_description"> | <dl id='Ch2.S2.I3' class='ltx_description'> |
<dt id="Ch2.I5.ix1" class="ltx_item"><span class="ltx_tag ltx_tag_description">arithmetic operations</span></dt> | <dt id='Ch2.S2.I3.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>arithmetic operations</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I5.ix1.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix1.p1' class='ltx_para'> |
<p class="ltx_p">including addition (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix1.p1.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>+<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix1.p1.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), | <p class='ltx_p'>including addition (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>+<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
subtraction (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix1.p1.m3" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>-<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix1.p1.m4" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), negation (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">-<math id="Ch2.I5.ix1.p1.m5" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math></span>), multiplication | subtraction (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>-<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), negation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>-<math id='Ch2.S2.I3.ix1.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math></span>), multiplication |
(<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix1.p1.m6" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>*<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix1.p1.m7" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), and division (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix1.p1.m8" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>/<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix1.p1.m9" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>). | (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m6' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>*<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m7' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and division (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m8' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>/<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m9' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>). |
Furthermore, a modulo operation (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix1.p1.m10" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>%<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix1.p1.m11" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>) is supported on integer | Furthermore, a modulo operation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix1.p1.m10' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>%<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix1.p1.m11' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>) is supported on integer |
numbers. | numbers. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>: the element types of <math id="Ch2.I5.ix1.p1.m12" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math> and | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.S2.I3.ix1.p1.m12' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and |
<math id="Ch2.I5.ix1.p1.m13" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same numerical type.</p> | <math id='Ch2.S2.I3.ix1.p1.m13' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same numerical type.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I5.ix2" class="ltx_item"><span class="ltx_tag ltx_tag_description">logical operations</span></dt> | <dt id='Ch2.S2.I3.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>logical operations</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I5.ix2.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix2.p1' class='ltx_para'> |
<p class="ltx_p">including conjunction (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix2.p1.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>&&<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix2.p1.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), disjunction | <p class='ltx_p'>including conjunction (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix2.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>&&<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix2.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), disjunction |
(<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix2.p1.m3" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>||<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix2.p1.m4" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), and negation (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">!<math id="Ch2.I5.ix2.p1.m5" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math></span>). | (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix2.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>||<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix2.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and negation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>!<math id='Ch2.S2.I3.ix2.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math></span>). |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>: the element types have to be Boolean.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types have to be Boolean.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I5.ix3" class="ltx_item"><span class="ltx_tag ltx_tag_description">relational operations</span></dt> | <dt id='Ch2.S2.I3.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>relational operations</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I5.ix3.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix3.p1' class='ltx_para'> |
<p class="ltx_p">including less-than (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix3.p1.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span><<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix3.p1.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), | <p class='ltx_p'>including less-than (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span><<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
less-or-equal (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix3.p1.m3" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix3.p1.m4" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), equal (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix3.p1.m5" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix3.p1.m6" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), | less-or-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m5' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m6' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
not-equal (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix3.p1.m7" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>!=<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix3.p1.m8" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), | not-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m7' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>!=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m8' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), |
greater-or-equal (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix3.p1.m9" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>>=<span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix3.p1.m10" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span>), and greater-than | greater-or-equal (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m9' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>>=<span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m10' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math></span>), and greater-than |
(<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><math id="Ch2.I5.ix3.p1.m11" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math><span class="ltx_text ltx_lst_space"> </span>><span class="ltx_text ltx_lst_space"> </span><math id="Ch2.I5.ix3.p1.m12" class="ltx_Math" alttext="e2" display="inline"><mrow><mi>e</mi><mo></mo><mn>2</mn></mrow></math></span>). | (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><math id='Ch2.S2.I3.ix3.p1.m11' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math><span class='ltx_text ltx_lst_space'> </span>><span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.I3.ix3.p1.m12' class='ltx_Math' alttext='e2' display='inline'><mrow><mi>e</mi><mo></mo><mn>2</mn></mrow></math></span>). |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>: the element types of <math id="Ch2.I5.ix3.p1.m13" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math> and <math id="Ch2.I5.ix3.p1.m14" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.S2.I3.ix3.p1.m13' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.S2.I3.ix3.p1.m14' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I5.ix4" class="ltx_item"><span class="ltx_tag ltx_tag_description">max (<math id="Ch2.I5.ix4.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math>, <math id="Ch2.I5.ix4.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math>), min (<math id="Ch2.I5.ix4.m3" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math>, <math id="Ch2.I5.ix4.m4" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math>)</span></dt> | <dt id='Ch2.S2.I3.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>max (<math id='Ch2.S2.I3.ix4.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>1</mn></msub></math>, <math id='Ch2.S2.I3.ix4.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>2</mn></msub></math>), min (<math id='Ch2.S2.I3.ix4.m3' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>1</mn></msub></math>, <math id='Ch2.S2.I3.ix4.m4' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>2</mn></msub></math>)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I5.ix4.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix4.p1' class='ltx_para'> |
<p class="ltx_p">compute the element-wise maximum and | <p class='ltx_p'>compute the element-wise maximum and |
minimum, respectively. | minimum, respectively. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>: the element types of <math id="Ch2.I5.ix4.p1.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math> and <math id="Ch2.I5.ix4.p1.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>: the element types of <math id='Ch2.S2.I3.ix4.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.S2.I3.ix4.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be of the same type.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I5.ix5" class="ltx_item"><span class="ltx_tag ltx_tag_description">where (p, <math id="Ch2.I5.ix5.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math>, <math id="Ch2.I5.ix5.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math>)</span></dt> | <dt id='Ch2.S2.I3.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>where (p, <math id='Ch2.S2.I3.ix5.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>1</mn></msub></math>, <math id='Ch2.S2.I3.ix5.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn mathvariant='normal'>2</mn></msub></math>)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I5.ix5.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix5.p1' class='ltx_para'> |
<p class="ltx_p">is an element-wise extension of a conditional. | <p class='ltx_p'>is an element-wise extension of a conditional. |
It expects <math id="Ch2.I5.ix5.p1.m1" class="ltx_Math" alttext="p" display="inline"><mi>p</mi></math>, <math id="Ch2.I5.ix5.p1.m2" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math>, and <math id="Ch2.I5.ix5.p1.m3" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math> either to have identical shapes | It expects <math id='Ch2.S2.I3.ix5.p1.m1' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math>, <math id='Ch2.S2.I3.ix5.p1.m2' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math>, and <math id='Ch2.S2.I3.ix5.p1.m3' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> either to have identical shapes |
or to be scalar. If at least one of the three arrays is non-scalar, that | or to be scalar. If at least one of the three arrays is non-scalar, that |
shape serves as shape of the result, whose values are taken from | shape serves as shape of the result, whose values are taken from |
<math id="Ch2.I5.ix5.p1.m4" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math> or <math id="Ch2.I5.ix5.p1.m5" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math> depending on the value (s) of <math id="Ch2.I5.ix5.p1.m6" class="ltx_Math" alttext="p" display="inline"><mi>p</mi></math>. | <math id='Ch2.S2.I3.ix5.p1.m4' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> or <math id='Ch2.S2.I3.ix5.p1.m5' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> depending on the value (s) of <math id='Ch2.S2.I3.ix5.p1.m6' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math>. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I5.I1" class="ltx_itemize"> | <ul id='Ch2.S2.I3.ix5.I1' class='ltx_itemize'> |
<li id="Ch2.I5.I1.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I3.ix5.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I5.I1.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix5.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p">the element type of <math id="Ch2.I5.I1.i1.p1.m1" class="ltx_Math" alttext="p" display="inline"><mi>p</mi></math> has to be boolean | <p class='ltx_p'>the element type of <math id='Ch2.S2.I3.ix5.I1.i1.p1.m1' class='ltx_Math' alttext='p' display='inline'><mi>p</mi></math> has to be boolean |
</p> | </p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I5.I1.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I3.ix5.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I5.I1.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix5.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p">the element types of <math id="Ch2.I5.I1.i2.p1.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math> and <math id="Ch2.I5.I1.i2.p1.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math> have to be identical</p> | <p class='ltx_p'>the element types of <math id='Ch2.S2.I3.ix5.I1.i2.p1.m1' class='ltx_Math' alttext='e_{1}' display='inline'><msub><mi>e</mi><mn>1</mn></msub></math> and <math id='Ch2.S2.I3.ix5.I1.i2.p1.m2' class='ltx_Math' alttext='e_{2}' display='inline'><msub><mi>e</mi><mn>2</mn></msub></math> have to be identical</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I5.I1.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I3.ix5.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I5.I1.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I3.ix5.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I5.I1.i3.p1.m1" class="ltx_Math" alttext="{{{{{{{{{{{{{{\exists\textrm{\lstinline 1}}}:((\textrm{\lstinline 1}}}\vee\textrm{\lstinline | <p class='ltx_p'><math id='Ch2.S2.I3.ix5.I1.i3.p1.m1' class='ltx_Math' alttext='{{{{{{{\exists\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
1% | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
}}})\wedge(\textrm{\lstinline 1}}}\vee\textrm{\lstinline 1}}})\wedge(\textrm{% | \@listingGroup{ltx_lst_identifier}{shp}}}}}}:((\textrm{\lstinline{{% |
\lstinline 1}}}\vee\textrm{\lstinline 1}}}))" display="inline"><mrow><mrow><mo>∃</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">shp</mtext></mrow><mo>:</mo><mrow><mo stretchy="false">(</mo><mrow><mrow><mo stretchy="false">(</mo><mrow><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>p</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>shp</mtext></mrow><mo>∨</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>p</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>[]</mtext></mrow></mrow><mo stretchy="false">)</mo></mrow><mo>∧</mo><mrow><mo stretchy="false">(</mo><mrow><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>e_1</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>shp</mtext></mrow><mo>∨</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>e_1</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>[]</mtext></mrow></mrow><mo stretchy="false">)</mo></mrow><mo>∧</mo><mrow><mo stretchy="false">(</mo><mrow><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>e_2</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>shp</mtext></mrow><mo>∨</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>e_2</mtext><mtext>)</mtext><mtext> </mtext><mtext>==</mtext><mtext> </mtext><mtext>[]</mtext></mrow></mrow><mo stretchy="false">)</mo></mrow></mrow><mo stretchy="false">)</mo></mrow></mrow></math>.</p> | \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}{p}}){\@listingGroup{ltx_lst_space}{~{}}% |
| }=={\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{ltx_lst_identifier}{shp% |
| }}}}}}\vee\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}% |
| {p}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{ltx_lst_space}{~{}}% |
| }[]}}}})\wedge(\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}% |
| {e\textunderscore 1}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{% |
| ltx_lst_space}{~{}}}{\@listingGroup{ltx_lst_identifier}{shp}}}}}}\vee\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}{e% |
| \textunderscore 1}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{% |
| ltx_lst_space}{~{}}}[]}}}})\wedge(\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}{e\textunderscore 2}}){\@listingGroup{ltx_lst_space}{~{}}}=% |
| ={\@listingGroup{ltx_lst_space}{~{}}}{\@listingGroup{ltx_lst_identifier}{shp}}% |
| }}}}\vee\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}% |
| {e\textunderscore 2}}){\@listingGroup{ltx_lst_space}{~{}}}=={\@listingGroup{% |
| ltx_lst_space}{~{}}}[]}}}}))' 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> |
</div> | </div> |
</li> | </li> |
</dl> | </dl> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx2.p4" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx2.p4' class='ltx_para'> |
<p class="ltx_p">Again, these operations are fairly self-explanatory. | <p class='ltx_p'>Again, these operations are fairly self-explanatory. |
Nevertheless, we present a few examples:</p> | Nevertheless, we present a few examples:</p> |
</div> | </div> |
<figure id="LST10" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST10' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 10: </span>Elementwise Extensions</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 10: </span>Elementwise Extensions</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsx%0ALDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICBw%0AcmludChtYXQpOwoKICBtYXQyID0gd2hlcmUobWF0ICUgMiA9PSAwLCBtYXQsIC1tYXQpOwogIHBy%0AaW50KG1hdDIpOwoKICBwcmludChtYXgobWF0MiwgMCkpOwoKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsxLDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICBwcmludChtYXQpOwoKICBtYXQyID0gd2hlcmUobWF0ICUgMiA9PSAwLCBtYXQsIC1tYXQpOwogIHByaW50KG1hdDIpOwoKICBwcmludChtYXgobWF0MiwgMCkpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx122' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx123' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx124' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx125' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx126' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx127' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5,6,7,8,9]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx128' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx129' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[<span class="ltx_text ltx_lst_identifier">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;'>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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx130' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx131' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx132' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx133' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat2</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx134' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx135' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx136' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx137' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx138' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS1.SSSx2.p5" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx2.p5' class='ltx_para'> |
<p class="ltx_p">The most interesting part of this example is the definition | <p class='ltx_p'>The most interesting part of this example is the definition |
of the matrix <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat2</span> in line 11. | of the matrix <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat2</span> in line 11. |
The even numbers from the matrix <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span> are taken as they are, whereas | The even numbers from the matrix <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> are taken as they are, whereas |
the odd numbers are negated. | the odd numbers are negated. |
Note here, that all sub expressions in predicate position are in fact non-scalar | Note here, that all sub expressions in predicate position are in fact non-scalar |
arrays: <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">(<span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>\%<span class="ltx_text ltx_lst_space"> </span>2)</span> denotes a matrix of zeros and ones and | arrays: <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>(<span class='ltx_text ltx_lst_identifier'>mat</span><span class='ltx_text ltx_lst_space'> </span>\%<span class='ltx_text ltx_lst_space'> </span>2)</span> denotes a matrix of zeros and ones and |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">(<span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_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></span> denotes a matrix of boolean values.</p> | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>(<span class='ltx_text ltx_lst_identifier'>mat</span><span class='ltx_text ltx_lst_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> denotes a matrix of boolean values.</p> |
</div> | </div> |
<div id="Thmtheorem6" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem6' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 6. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 6. </h6> |
<div id="Thmtheorem6.p1" class="ltx_para"> | <div id='Thmtheorem6.p1' class='ltx_para'> |
<p class="ltx_p">What results do you expect from the following expressions:</p> | <p class='ltx_p'>What results do you expect from the following expressions:</p> |
<ul id="Ch2.I6" class="ltx_itemize"> | <ul id='Ch2.S2.I4' class='ltx_itemize'> |
<li id="Ch2.I6.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I4.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I6.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I4.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">min</span>(<span class="ltx_text ltx_lst_identifier">reshape</span>([3,0,5],<span class="ltx_text ltx_lst_space"> </span>[]),<span class="ltx_text ltx_lst_space"> </span>42)</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>min</span>(<span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[]),<span class='ltx_text ltx_lst_space'> </span>42)</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I6.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I4.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I6.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I4.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">reshape</span>([3,0,5],<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">reshape</span>([3,0,5],<span class="ltx_text ltx_lst_space"> </span>[])</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])<span 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,0,5],<span class='ltx_text ltx_lst_space'> </span>[])</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I6.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I4.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I6.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I4.i3.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">reshape</span>([1,1],<span class="ltx_text ltx_lst_space"> </span>[1])<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>([1],<span class="ltx_text ltx_lst_space"> </span>[1])</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([1,1],<span class='ltx_text ltx_lst_space'> </span>[1])<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>([1],<span class='ltx_text ltx_lst_space'> </span>[1])</span>?</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</section> | </section> |
<section id="Ch2.S2.SS1.SSSx3" class="ltx_subsubsection"> | <section id='Ch2.S2.SS1.SSSx3' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Restructuring Operations</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Restructuring Operations</h6> |
| |
<div id="Ch2.S2.SS1.SSSx3.p1" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx3.p1' class='ltx_para'> |
<p class="ltx_p">The operations to be introduced here do not compute new values at all. | <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 | Instead, they are meant to create slightly differently structured arrays |
from existing ones. | from existing ones. |
Therefore, they are applicable to arrays of all built-in element types.</p> | Therefore, they are applicable to arrays of all built-in element types.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx3.p2" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx3.p2' class='ltx_para'> |
<dl id="Ch2.I7" class="ltx_description"> | <dl id='Ch2.S2.I5' class='ltx_description'> |
<dt id="Ch2.I7.ix1" class="ltx_item"><span class="ltx_tag ltx_tag_description">take(sv, a)</span></dt> | <dt id='Ch2.S2.I5.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>take(sv, a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I7.ix1.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix1.p1' class='ltx_para'> |
<p class="ltx_p">takes as many elements from the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> as indicated | <p class='ltx_p'>takes as many elements from the array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> as indicated |
by the shape vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span>. Each element of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span> corresponds to | by the shape vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span>. Each element of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span> corresponds to |
one axis of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> starting from the leftmost one. | one axis of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> starting from the leftmost one. |
For positive components of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span>, the elements are taken from the | For positive components of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span>, the elements are taken from the |
“beginning”, i.e. starting with index 0, otherwise they are taken | “beginning”, i.e. starting with index 0, otherwise they are taken |
from the “end” including the maximum legal index of the corresponding | from the “end” including the maximum legal index of the corresponding |
axis. | axis. |
All axes of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> where there exists no corresponding element in | All axes of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> where there exists no corresponding element in |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span> are taken entirely. | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span> are taken entirely. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I7.I1" class="ltx_itemize"> | <ul id='Ch2.S2.I5.ix1.I1' class='ltx_itemize'> |
<li id="Ch2.I7.I1.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix1.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I1.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix1.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">sv</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>sv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I1.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix1.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I1.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix1.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">sv</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>sv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I1.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix1.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I1.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix1.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I7.I1.i3.p1.m1" class="ltx_Math" alttext="{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I5.ix1.I1.i3.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}" display="inline"><mrow><mrow><mrow><mo>∀</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</mtext></mrow><mo>∈</mo><mrow><mo stretchy="false">{</mo><mn>0</mn><mo>,</mo><mi mathvariant="normal">…</mi><mo>,</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>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> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape% |
| }}({\@listingGroup{ltx_lst_identifier}{sv}})[[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}{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> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I7.ix2" class="ltx_item"><span class="ltx_tag ltx_tag_description">drop(sv, a)</span></dt> | <dt id='Ch2.S2.I5.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>drop(sv, a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I7.ix2.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix2.p1' class='ltx_para'> |
<p class="ltx_p">drops as many elements from the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> as indicated | <p class='ltx_p'>drops as many elements from the array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> as indicated |
by the shape vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span>. Each element of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span> corresponds to | by the shape vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span>. Each element of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span> corresponds to |
one axis of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> starting from the leftmost one. | one axis of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> starting from the leftmost one. |
For positive components of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span>, the elements are dropped from the | For positive components of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span>, the elements are dropped from the |
“beginning”, i.e. starting with index 0, otherwise they are dropped | “beginning”, i.e. starting with index 0, otherwise they are dropped |
from the “end” starting from the maximum legal index of the corresponding | from the “end” starting from the maximum legal index of the corresponding |
axis. | axis. |
All axes of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> where there exists no corresponding element in | All axes of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> where there exists no corresponding element in |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span> are left untouched. | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span> are left untouched. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I7.I2" class="ltx_itemize"> | <ul id='Ch2.S2.I5.ix2.I2' class='ltx_itemize'> |
<li id="Ch2.I7.I2.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix2.I2.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I2.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix2.I2.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">sv</span>)=<span class="ltx_text ltx_lst_space"> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>sv</span>)=<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I2.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix2.I2.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I2.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix2.I2.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">sv</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>sv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I2.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix2.I2.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I2.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix2.I2.i3.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I7.I2.i3.p1.m1" class="ltx_Math" alttext="{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I5.ix2.I2.i3.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}" display="inline"><mrow><mrow><mrow><mo>∀</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</mtext></mrow><mo>∈</mo><mrow><mo stretchy="false">{</mo><mn>0</mn><mo>,</mo><mi mathvariant="normal">…</mi><mo>,</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>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> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape% |
| }}({\@listingGroup{ltx_lst_identifier}{sv}})[[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}{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> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I7.ix3" class="ltx_item"><span class="ltx_tag ltx_tag_description">tile(sv, ov, a)</span></dt> | <dt id='Ch2.S2.I5.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>tile(sv, ov, a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I7.ix3.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix3.p1' class='ltx_para'> |
<p class="ltx_p">takes a tile of shape <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span> from <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> | <p class='ltx_p'>takes a tile of shape <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span> from <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> |
starting at the index specified by the offset vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">ov</span>. | starting at the index specified by the offset vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>ov</span>. |
For axes where no values of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sv</span> or <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">ov</span> are specified | For axes where no values of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sv</span> or <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>ov</span> are specified |
these are assumed to be identical to the extent of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> along that axis or 0, | these are assumed to be identical to the extent of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> along that axis or 0, |
respectively. | respectively. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I7.I3" class="ltx_itemize"> | <ul id='Ch2.S2.I5.ix3.I3' class='ltx_itemize'> |
<li id="Ch2.I7.I3.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix3.I3.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I3.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix3.I3.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">sv</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">ov</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>sv</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>ov</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span> |
</p> | </p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I3.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix3.I3.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I3.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix3.I3.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">sv</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>sv</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I3.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix3.I3.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I3.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix3.I3.i3.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">ov</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>ov</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I3.i4" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix3.I3.i4' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I3.i4.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix3.I3.i4.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I7.I3.i4.p1.m1" class="ltx_Math" alttext="{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I5.ix3.I3.i4.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}" display="inline"><mrow><mrow><mrow><mo>∀</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</mtext></mrow><mo>∈</mo><mrow><mo stretchy="false">{</mo><mn>0</mn><mo>,</mo><mi mathvariant="normal">…</mi><mo>,</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>shape</mtext><mtext>(</mtext><mtext>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> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{shape% |
| }}({\@listingGroup{ltx_lst_identifier}{ov}})[[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}{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> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I3.i5" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix3.I3.i5' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I3.i5.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix3.I3.i5.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I7.I3.i5.p1.m1" class="ltx_Math" alttext="{{{{{{\forall\textrm{\lstinline 1}}}\in\{0,\dots,\textrm{\lstinline 1}}}\}:\textrm{% | <p class='ltx_p'><math id='Ch2.S2.I5.ix3.I3.i5.p1.m1' class='ltx_Math' alttext='{{{\forall\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
\lstinline 1}}}" display="inline"><mrow><mrow><mrow><mo>∀</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</mtext></mrow><mo>∈</mo><mrow><mo stretchy="false">{</mo><mn>0</mn><mo>,</mo><mi mathvariant="normal">…</mi><mo>,</mo><mrow class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><mtext>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> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{0,\dots,\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{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{\lstinline{{\lst@@@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> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I3.i6" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix3.I3.i6' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I3.i6.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix3.I3.i6.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I7.I3.i6.p1.m1" class="ltx_Math" alttext="{{{{{{{{\forall\textrm{\lstinline 1}}}\in\{\textrm{\lstinline 1}}},\dots,\textrm{% | <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% |
\lstinline 1}}}\}:\textrm{\lstinline 1}}}" display="inline"><mrow><mrow><mrow><mo>∀</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</mtext></mrow><mo>∈</mo><mrow><mo stretchy="false">{</mo><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> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
| \@listingGroup{ltx_lst_identifier}{i}}}}}}\in\{\textrm{\lstinline{{% |
| \lst@@@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{\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}{sv}})[[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}{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> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I7.ix4" class="ltx_item"><span class="ltx_tag ltx_tag_description"><math id="Ch2.I7.ix4.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math> ++ <math id="Ch2.I7.ix4.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math></span></dt> | <dt id='Ch2.S2.I5.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_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><span class='ltx_text ltx_font_bold'> ++ <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></span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I7.ix4.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix4.p1' class='ltx_para'> |
<p class="ltx_p">concatenates arrays <math id="Ch2.I7.ix4.p1.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math> and <math id="Ch2.I7.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. | <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 <span class="ltx_text ltx_font_smallcaps">SaC</span> all arrays are homogeneous, this requires all but the leftmost | As in <span class='ltx_text ltx_font_smallcaps'>SaC</span> all arrays are homogeneous, this requires all but the leftmost |
axis to be of identical extent. | axis to be of identical extent. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I7.I4" class="ltx_itemize"> | <ul id='Ch2.S2.I5.ix4.I4' class='ltx_itemize'> |
<li id="Ch2.I7.I4.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix4.I4.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I4.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix4.I4.i1.p1' class='ltx_para'> |
<p class="ltx_p"><math id="Ch2.I7.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.I7.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> | <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> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I4.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix4.I4.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I4.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix4.I4.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">drop</span>(1,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">shape</span>(<math id="Ch2.I7.I4.i2.p1.m1" class="ltx_Math" alttext="e_{1}" display="inline"><msub><mi>e</mi><mn>1</mn></msub></math>))<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">drop</span>(1,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">shape</span>(<math id="Ch2.I7.I4.i2.p1.m2" class="ltx_Math" alttext="e_{2}" display="inline"><msub><mi>e</mi><mn>2</mn></msub></math>))</span>.</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>drop</span>(1,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>shape</span>(<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>))<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>drop</span>(1,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>shape</span>(<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>))</span>.</p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I7.ix5" class="ltx_item"><span class="ltx_tag ltx_tag_description">rotate(ov, a)</span></dt> | <dt id='Ch2.S2.I5.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>rotate(ov, a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I7.ix5.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix5.p1' class='ltx_para'> |
<p class="ltx_p">rotates the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> with respect to those axes specified | <p class='ltx_p'>rotates the array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> with respect to those axes specified |
by the offset vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">ov</span>. | by the offset vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>ov</span>. |
Starting from the leftmost axis, the elements of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">ov</span> specify by how many | Starting from the leftmost axis, the elements of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>ov</span> specify by how many |
positions the elements are rotated towards increasing indices (positive values) | positions the elements are rotated towards increasing indices (positive values) |
or towards decreasing indices (negative values). | or towards decreasing indices (negative values). |
<span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I7.I5" class="ltx_itemize"> | <ul id='Ch2.S2.I5.ix5.I5' class='ltx_itemize'> |
<li id="Ch2.I7.I5.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix5.I5.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I5.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix5.I5.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">ov</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>ov</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I5.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix5.I5.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I5.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix5.I5.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">ov</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>ov</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I7.ix6" class="ltx_item"><span class="ltx_tag ltx_tag_description">shift(ov, expr, a)</span></dt> | <dt id='Ch2.S2.I5.ix6' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>shift(ov, expr, a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I7.ix6.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix6.p1' class='ltx_para'> |
<p class="ltx_p">shifts the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> with respect to those axes specified | <p class='ltx_p'>shifts the array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> with respect to those axes specified |
by the offset vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">ov</span>. | by the offset vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>ov</span>. |
The element positions that become “void” are filled by the (scalar) | The element positions that become “void” are filled by the (scalar) |
default element <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">expr</span>. | default element <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>expr</span>. |
Again, depending on the sign of the values of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">ov</span> the elements | Again, depending on the sign of the values of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>ov</span> the elements |
are either shifted towards increasing or decreasing indices. | are either shifted towards increasing or decreasing indices. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions</span>:</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions</span>:</p> |
<ul id="Ch2.I7.I6" class="ltx_itemize"> | <ul id='Ch2.S2.I5.ix6.I6' class='ltx_itemize'> |
<li id="Ch2.I7.I6.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix6.I6.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I6.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix6.I6.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">ov</span>)<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>1</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>ov</span>)<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>1</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I6.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix6.I6.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I6.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix6.I6.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">ov</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">dim</span>(<span class="ltx_text ltx_lst_identifier">a</span>)</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>ov</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span><=<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>dim</span>(<span class='ltx_text ltx_lst_identifier'>a</span>)</span></p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I7.I6.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I5.ix6.I6.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_bold">–</span></span> | <span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>•</span></span> |
<div id="Ch2.I7.I6.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I5.ix6.I6.i3.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shape</span>(<span class="ltx_text ltx_lst_identifier">expr</span>)[[0]]<span class="ltx_text ltx_lst_space"> </span>==<span class="ltx_text ltx_lst_space"> </span>[]</span></p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shape</span>(<span class='ltx_text ltx_lst_identifier'>expr</span>)[[0]]<span class='ltx_text ltx_lst_space'> </span>==<span class='ltx_text ltx_lst_space'> </span>[]</span></p> |
</div> | </div> |
</li> | </li> |
</dl> | </dl> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx3.p3" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx3.p3' class='ltx_para'> |
<p class="ltx_p">A few examples:</p> | <p class='ltx_p'>A few examples:</p> |
</div> | </div> |
<figure id="LST11" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST11' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 11: </span>Restructuring Operations</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 11: </span>Restructuring Operations</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsx%0ALDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICBw%0AcmludChtYXQpOwoKICBwcmludCh0YWtlKFsyLC0yXSwgbWF0KSk7CiAgcHJpbnQodGFrZShbMl0s%0AIG1hdCkpOwogIHByaW50KHRha2UoW10sIG1hdCkpOwoKICBwcmludCh0YWtlKFswXSwgbWF0KSk7%0ACiAgcHJpbnQodGFrZShbMiwgMF0sIG1hdCkpOwogIHByaW50KHRha2UoWzJdLCByZXNoYXBlKFsz%0ALDAsNV0sIFtdKSkpOwoKICBwcmludChkcm9wKFswLCAtMV0sIG1hdCkpOwoKICBwcmludChtYXQg%0AKysgbWF0KTsKCiAgcHJpbnQocm90YXRlKFstMSwgNDJdLCBtYXQpKTsKICBwcmludChyb3RhdGUo%0AWyAxXSwgbWF0KSk7CgogIHByaW50KHNoaWZ0KFswLCAtMl0sIDAsIG1hdCkpOwogIHByaW50KHNo%0AaWZ0KFswLCAtMjJdLCAwLCBtYXQpKTsKICBwcmludChzaGlmdChbMV0sIDAsIG1hdCkpOwoKICBy%0AZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsxLDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICBwcmludChtYXQpOwoKICBwcmludCh0YWtlKFsyLC0yXSwgbWF0KSk7CiAgcHJpbnQodGFrZShbMl0sIG1hdCkpOwogIHByaW50KHRha2UoW10sIG1hdCkpOwoKICBwcmludCh0YWtlKFswXSwgbWF0KSk7CiAgcHJpbnQodGFrZShbMiwgMF0sIG1hdCkpOwogIHByaW50KHRha2UoWzJdLCByZXNoYXBlKFszLDAsNV0sIFtdKSkpOwoKICBwcmludChkcm9wKFswLCAtMV0sIG1hdCkpOwoKICBwcmludChtYXQgKysgbWF0KTsKCiAgcHJpbnQocm90YXRlKFstMSwgNDJdLCBtYXQpKTsKICBwcmludChyb3RhdGUoWyAxXSwgbWF0KSk7CgogIHByaW50KHNoaWZ0KFswLCAtMl0sIDAsIG1hdCkpOwogIHByaW50KHNoaWZ0KFswLCAtMjJdLCAwLCBtYXQpKTsKICBwcmludChzaGlmdChbMV0sIDAsIG1hdCkpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx139' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx140' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx141' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx142' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx143' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx144' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5,6,7,8,9]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx145' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx146' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[<span class="ltx_text ltx_lst_identifier">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;'>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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx147' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx148' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx149' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx150' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx151' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx152' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx153' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx154' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx155' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>[]))); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx156' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx157' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx158' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx159' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx160' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx161' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx162' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx163' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx164' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx165' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx166' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx167' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">29</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx168' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx169' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">31</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>31</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS1.SSSx3.p4" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx3.p4' class='ltx_para'> |
<p class="ltx_p">The applications of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">take</span> in lines 11-13 demonstrate, how the | <p class='ltx_p'>The applications of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>take</span> in lines 11-13 demonstrate, how the |
dimensionality of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span> remains unaffected by the length of the | dimensionality of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> remains unaffected by the length of the |
first argument. | first argument. |
Only the shape of the result and the “side” from which the elements | Only the shape of the result and the “side” from which the elements |
are taken is defined by it.</p> | are taken is defined by it.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx3.p5" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx3.p5' class='ltx_para'> |
<p class="ltx_p">The applications in lines 15-17 demonstrate how empty arrays are dealt | <p class='ltx_p'>The applications in lines 15-17 demonstrate how empty arrays are dealt |
with in the individual argument positions. | with in the individual argument positions. |
In particular from the example in line 17 it can be seen how well the | In particular from the example in line 17 it can be seen how well the |
fits nicely into the overall framework.</p> | fits nicely into the overall framework.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx3.p6" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx3.p6' class='ltx_para'> |
<p class="ltx_p">The remaining examples are rather straightforward. | <p class='ltx_p'>The remaining examples are rather straightforward. |
The only aspect of interest here may be the “overflows” in the | The only aspect of interest here may be the “overflows” in the |
rotation and shift parameters in lines 24 and 28, respectively.</p> | rotation and shift parameters in lines 24 and 28, respectively.</p> |
</div> | </div> |
<div id="Thmtheorem7" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem7' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 7. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 7. </h6> |
<div id="Thmtheorem7.p1" class="ltx_para"> | <div id='Thmtheorem7.p1' class='ltx_para'> |
<p class="ltx_p">Which of the following expressions can be reformulated in terms | <p class='ltx_p'>Which of the following expressions can be reformulated in terms |
of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">take</span>, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">++</span>, and the basic operations defined | of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>take</span>, <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>++</span>, and the basic operations defined |
in the previous parts?</p> | in the previous parts?</p> |
<ul id="Ch2.I8" class="ltx_itemize"> | <ul id='Ch2.S2.I6' class='ltx_itemize'> |
<li id="Ch2.I8.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I6.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I8.i1.p1" class="ltx_para"> | <div id='Ch2.S2.I6.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">drop</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_identifier">a</span>)</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>drop</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_identifier'>a</span>)</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I8.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I6.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I8.i2.p1" class="ltx_para"> | <div id='Ch2.S2.I6.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">tile</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_identifier">o</span>,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>)</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>tile</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_identifier'>o</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I8.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I6.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I8.i3.p1" class="ltx_para"> | <div id='Ch2.S2.I6.i3.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shift</span><span class="ltx_text ltx_lst_space"> </span>([<span class="ltx_text ltx_lst_identifier">n</span>],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">e</span>,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>)</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shift</span><span class='ltx_text ltx_lst_space'> </span>([<span class='ltx_text ltx_lst_identifier'>n</span>],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>e</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I8.i4" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I6.i4' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I8.i4.p1" class="ltx_para"> | <div id='Ch2.S2.I6.i4.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">shift</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">n</span>],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">e</span>,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>)</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>shift</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'>n</span>],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>e</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I8.i5" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I6.i5' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I8.i5.p1" class="ltx_para"> | <div id='Ch2.S2.I6.i5.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">rotate</span><span class="ltx_text ltx_lst_space"> </span>([<span class="ltx_text ltx_lst_identifier">n</span>],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>)</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>rotate</span><span class='ltx_text ltx_lst_space'> </span>([<span class='ltx_text ltx_lst_identifier'>n</span>],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch2.I8.i6" class="ltx_item" style="list-style-type:none;"> | <li id='Ch2.S2.I6.i6' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch2.I8.i6.p1" class="ltx_para"> | <div id='Ch2.S2.I6.i6.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">rotate</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">n</span>],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span>)</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>rotate</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'>n</span>],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span>)</span>?</p> |
</div> | </div> |
</li> | </li> |
</ul> | </ul> |
<p class="ltx_p">Can we define the general versions of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">shift</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">rotate</span> | <p class='ltx_p'>Can we define the general versions of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>shift</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>rotate</span> |
as well?</p> | as well?</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch2.S2.SS1.SSSx4" class="ltx_subsubsection"> | <section id='Ch2.S2.SS1.SSSx4' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Reduction Operations</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Reduction Operations</h6> |
| |
<div id="Ch2.S2.SS1.SSSx4.p1" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx4.p1' class='ltx_para'> |
<p class="ltx_p">The library of standard array operations that comes with the current <span class="ltx_text ltx_font_smallcaps">SaC</span> release also contains a set of functions | <p class='ltx_p'>The library of standard array operations that comes with the current <span class='ltx_text ltx_font_smallcaps'>SaC</span> release also contains a set of functions |
that fold all (scalar) elements of an array into a single one. The most common | that fold all (scalar) elements of an array into a single one. The most common |
ones of these are described here.</p> | ones of these are described here.</p> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx4.p2" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx4.p2' class='ltx_para'> |
<dl id="Ch2.I9" class="ltx_description"> | <dl id='Ch2.S2.I7' class='ltx_description'> |
<dt id="Ch2.I9.ix1" class="ltx_item"><span class="ltx_tag ltx_tag_description">sum(a)</span></dt> | <dt id='Ch2.S2.I7.ix1' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>sum(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I9.ix1.p1" class="ltx_para"> | <div id='Ch2.S2.I7.ix1.p1' class='ltx_para'> |
<p class="ltx_p">sums up all elements of the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. If <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> is | <p class='ltx_p'>sums up all elements of the array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> is |
an empty array, <span class="ltx_text ltx_lstlisting"></span> is returned. | an empty array, <span class='ltx_text ltx_lstlisting'></span> is returned. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions:</span> the element type has to be numerical.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions:</span> the element type has to be numerical.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I9.ix2" class="ltx_item"><span class="ltx_tag ltx_tag_description">prod(a)</span></dt> | <dt id='Ch2.S2.I7.ix2' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>prod(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I9.ix2.p1" class="ltx_para"> | <div id='Ch2.S2.I7.ix2.p1' class='ltx_para'> |
<p class="ltx_p">multiplies all elements of the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. If <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> is | <p class='ltx_p'>multiplies all elements of the array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> is |
an empty array, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">1</span> is returned. | an empty array, <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>1</span> is returned. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions:</span> the element type has to be numerical.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions:</span> the element type has to be numerical.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I9.ix3" class="ltx_item"><span class="ltx_tag ltx_tag_description">all(a)</span></dt> | <dt id='Ch2.S2.I7.ix3' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>all(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I9.ix3.p1" class="ltx_para"> | <div id='Ch2.S2.I7.ix3.p1' class='ltx_para'> |
<p class="ltx_p">yields <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">true</span>, iff all elements of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> are <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">true</span>. | <p class='ltx_p'>yields <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>true</span>, iff all elements of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> are <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>true</span>. |
If <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> is an empty array, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">true</span> is returned. | If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> is an empty array, <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>true</span> is returned. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions:</span> the element type has to be boolean.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions:</span> the element type has to be boolean.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I9.ix4" class="ltx_item"><span class="ltx_tag ltx_tag_description">any(a)</span></dt> | <dt id='Ch2.S2.I7.ix4' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>any(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I9.ix4.p1" class="ltx_para"> | <div id='Ch2.S2.I7.ix4.p1' class='ltx_para'> |
<p class="ltx_p">yields <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">true</span>, iff at least one element of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> | <p class='ltx_p'>yields <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>true</span>, iff at least one element of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> |
is <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">true</span>. If <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> is an empty array, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">false</span> is returned. | is <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>true</span>. If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> is an empty array, <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>false</span> is returned. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions:</span> the element type has to be boolean.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions:</span> the element type has to be boolean.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I9.ix5" class="ltx_item"><span class="ltx_tag ltx_tag_description">maxval(a)</span></dt> | <dt id='Ch2.S2.I7.ix5' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>maxval(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I9.ix5.p1" class="ltx_para"> | <div id='Ch2.S2.I7.ix5.p1' class='ltx_para'> |
<p class="ltx_p">computes the maximum value of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. If <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> is | <p class='ltx_p'>computes the maximum value of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> is |
an empty array, the minimal number of the according element type is | an empty array, the minimal number of the according element type is |
returned. | returned. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions:</span> the element type has to be numerical.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions:</span> the element type has to be numerical.</p> |
</div> | </div> |
</dd> | </dd> |
<dt id="Ch2.I9.ix6" class="ltx_item"><span class="ltx_tag ltx_tag_description">minval(a)</span></dt> | <dt id='Ch2.S2.I7.ix6' class='ltx_item'><span class='ltx_tag ltx_tag_item'><span class='ltx_text ltx_font_bold'>minval(a)</span></span></dt> |
<dd class="ltx_item"> | <dd class='ltx_item'> |
<div id="Ch2.I9.ix6.p1" class="ltx_para"> | <div id='Ch2.S2.I7.ix6.p1' class='ltx_para'> |
<p class="ltx_p">computes the minimum value of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. If <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> is | <p class='ltx_p'>computes the minimum value of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. If <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> is |
an empty array, the maximal number of the according element type is | an empty array, the maximal number of the according element type is |
returned. | returned. |
<br class="ltx_break"><span class="ltx_text ltx_font_italic">Domain restrictions:</span> the element type has to be numerical.</p> | <br class='ltx_break'><span class='ltx_text ltx_font_italic'>Domain restrictions:</span> the element type has to be numerical.</p> |
</div> | </div> |
</dd> | </dd> |
</dl> | </dl> |
</div> | </div> |
<div id="Ch2.S2.SS1.SSSx4.p3" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx4.p3' class='ltx_para'> |
<p class="ltx_p">A few examples:</p> | <p class='ltx_p'>A few examples:</p> |
</div> | </div> |
<figure id="LST12" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST12' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 12: </span>Reduction Operations</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 12: </span>Reduction Operations</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsx%0ALDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKCiAg%0AcHJpbnQoc3VtKG1hdCkpOwogIHByaW50KHByb2QodmVjdCkpOwogIHByaW50KGFsbChtYXQgPj0g%0AMSkpOwogIHByaW50KGFueShtYXQgPiAxKSk7CiAgcHJpbnQobWF4dmFsKG1hdCkpOwogIHByaW50%0AKG1pbnZhbChtYXQpKTsKCiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsxLDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKCiAgcHJpbnQoc3VtKG1hdCkpOwogIHByaW50KHByb2QodmVjdCkpOwogIHByaW50KGFsbChtYXQgPj0gMSkpOwogIHByaW50KGFueShtYXQgPiAxKSk7CiAgcHJpbnQobWF4dmFsKG1hdCkpOwogIHByaW50KG1pbnZhbChtYXQpKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx170' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx171' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx172' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx173' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx174' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx175' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5,6,7,8,9]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx176' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx177' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[<span class="ltx_text ltx_lst_identifier">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;'>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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx178' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx179' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx180' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx181' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx182' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx183' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx184' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx185' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx186' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx187' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS1.SSSx4.p4" class="ltx_para"> | <div id='Ch2.S2.SS1.SSSx4.p4' class='ltx_para'> |
<p class="ltx_p">Most of these examples, again, are fairly self explanatory. | <p class='ltx_p'>Most of these examples, again, are fairly self explanatory. |
However, you may get an idea of the specificational advantages | However, you may get an idea of the specificational advantages |
of shape-invariant programming when having a closer look | of shape-invariant programming when having a closer look |
style of program specifications that results from it.</p> | style of program specifications that results from it.</p> |
</div> | </div> |
<div id="Thmtheorem8" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem8' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 8. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 8. </h6> |
<div id="Thmtheorem8.p1" class="ltx_para"> | <div id='Thmtheorem8.p1' class='ltx_para'> |
<p class="ltx_p">All operations introduced in this part apply to <span class="ltx_text ltx_font_bold">all</span> elements | <p class='ltx_p'>All operations introduced in this part apply to <span class='ltx_text ltx_font_bold'>all</span> elements |
of the array they are applied to. Given the array operations introduced | 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? | so far, can you specify row-wise or column-wise summations for matrices? |
</section> | </section> |
</section> | </section> |
<section id="Ch2.S2.SS2" class="ltx_subsection"> | <section id='Ch2.S2.SS2' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">2.2.2 </span>Axis Control Notation</h5> | <span class='ltx_tag ltx_tag_subsection'>2.2.2 </span>Axis Control Notation</h5> |
| |
<div id="Ch2.S2.SS2.p1" class="ltx_para"> | <div id='Ch2.S2.SS2.p1' class='ltx_para'> |
<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"><span class="ltx_text ltx_ref_tag">8</span></a>, without further | <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'><span class='ltx_text ltx_ref_tag'>8</span></a>, without further |
language support, it is rather difficult | language support, it is rather difficult |
to apply an array operation to certain axes of an array only. | to apply an array operation to certain axes of an array only. |
This section introduces two language constructs of <span class="ltx_text ltx_font_smallcaps">SaC</span> which, | This section introduces two language constructs of <span class='ltx_text ltx_font_smallcaps'>SaC</span> which, |
when taken together, can be used to that effect. | when taken together, can be used to that effect. |
While <em class="ltx_emph">Generalized Selections</em> are convenient for separating individual | While <em class='ltx_emph ltx_font_italic'>Generalized Selections</em> are convenient for separating individual |
axes of an array, | axes of an array, |
<em class="ltx_emph">Set Notations</em> allow to recombine such axes into a result 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. | after applying arbitrary operations to them. |
However, as the two constructs in principle are orthogonal, | However, as the two constructs in principle are orthogonal, |
we introduce them separately before showing how they can be combined | we introduce them separately before showing how they can be combined |
into an instrument for <em class="ltx_emph">Axis Control</em>.</p> | into an instrument for <em class='ltx_emph ltx_font_italic'>Axis Control</em>.</p> |
</div> | </div> |
<section id="Ch2.S2.SS2.SSSx1" class="ltx_subsubsection"> | <section id='Ch2.S2.SS2.SSSx1' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Generalized Selections</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Generalized Selections</h6> |
| |
<div id="Ch2.S2.SS2.SSSx1.p1" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p1' class='ltx_para'> |
<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"><span class="ltx_text ltx_ref_tag">2.2.1</span></a> does not | <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'><span class='ltx_text ltx_ref_tag'>2.2.1</span></a> does not |
only allow scalar elements but entire subarrays of an array to be selected. | only allow scalar elements but entire subarrays of an array to be selected. |
However, the selection of (non-scalar) subarrays always assumes the given | However, the selection of (non-scalar) subarrays always assumes the given |
transposed first.</p> | transposed first.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx1.p2" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p2' class='ltx_para'> |
<p class="ltx_p">To avoid clumsy notations, <span class="ltx_text ltx_font_smallcaps">SaC</span> provides special syntactical support for | <p class='ltx_p'>To avoid clumsy notations, <span class='ltx_text ltx_font_smallcaps'>SaC</span> provides special syntactical support for |
selecting arbitrary subarrays called <em class="ltx_emph">Generalized Selections</em>. | 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 | The basic idea is to indicate the axes whose elements are to be selected |
entirely by using dot-symbols instead of numerical values within | entirely by using dot-symbols instead of numerical values within |
the index vectors of a selection operation.</p> | the index vectors of a selection operation.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx1.p3" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p3' class='ltx_para'> |
<p class="ltx_p">Note here, that vectors containing dot-symbols are not | <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 | first class citizens of the language, i.e. they can exclusively be specified within |
selection operations directly!</p> | selection operations directly!</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx1.p4" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p4' class='ltx_para'> |
<p class="ltx_p">There are two kinds of dot-symbols, single-dots which refer to a single axis | <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 | and triple-dots which refer to as many axes as they are left unspecified within |
a selection. | a selection. |
expression is allowed.</p> | expression is allowed.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx1.p5" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p5' class='ltx_para'> |
<p class="ltx_p">A few examples:</p> | <p class='ltx_p'>A few examples:</p> |
</div> | </div> |
<figure id="LST13" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST13' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 13: </span>Generalized Selections</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 13: </span>Generalized Selections</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsx%0ALDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICBw%0AcmludChtYXQpOwoKICBwcmludChtYXRbWzFdXSk7CiAgcHJpbnQobWF0W1sxLC5dXSk7CiAgcHJp%0AbnQobWF0W1sxLC4uLl1dKTsKCiAgcHJpbnQobWF0W1suLDFdXSk7CiAgcHJpbnQobWF0W1suLi4s%0AMV1dKTsKCiAgcHJpbnQobWF0W1sxLC4uLiwxXV0pOwoKICBhcnIzZCA9IFttYXQsIG1hdF07CiAg%0AcHJpbnQoYXJyM2QpOwoKICBwcmludChhcnIzZFtbLiwxXV0pOwogIHByaW50KGFycjNkW1suLi4s%0AMV1dKTsKCiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsxLDIsMyw0LDUsNiw3LDgsOV07CgogIG1hdCA9IFt2ZWN0LCB2ZWN0KzEwLCB2ZWN0KzIwXTsKICBwcmludChtYXQpOwoKICBwcmludChtYXRbWzFdXSk7CiAgcHJpbnQobWF0W1sxLC5dXSk7CiAgcHJpbnQobWF0W1sxLC4uLl1dKTsKCiAgcHJpbnQobWF0W1suLDFdXSk7CiAgcHJpbnQobWF0W1suLi4sMV1dKTsKCiAgcHJpbnQobWF0W1sxLC4uLiwxXV0pOwoKICBhcnIzZCA9IFttYXQsIG1hdF07CiAgcHJpbnQoYXJyM2QpOwoKICBwcmludChhcnIzZFtbLiwxXV0pOwogIHByaW50KGFycjNkW1suLi4sMV1dKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx188' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx189' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx190' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx191' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx192' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx193' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[1,2,3,4,5,6,7,8,9]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx194' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx195' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[<span class="ltx_text ltx_lst_identifier">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;'>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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx196' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx197' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx198' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[1]]); | <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]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx199' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[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,.]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx200' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[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,…]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx201' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx202' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx203' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[…,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]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx204' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx205' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>[[1,…,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'>mat</span>[[1,…,1]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx206' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx207' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx208' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx209' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx210' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">arr3d</span>[[.,1]]); | <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]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx211' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx212' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx213' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx214' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>27</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS2.SSSx1.p6" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p6' class='ltx_para'> |
<p class="ltx_p">The examples in lines 11-13 demonstrate different versions for selecting | <p class='ltx_p'>The examples in lines 11-13 demonstrate different versions for selecting |
the second row of the matrix <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span>. | the second row of the matrix <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span>. |
However, as the rightmost axis is to be selected, a dot-free version | However, as the rightmost axis is to be selected, a dot-free version |
(cf. line 11) suffices for this task. | (cf. line 11) suffices for this task. |
The selection of the second column of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span> is shown in lines 15 and 16.</p> | The selection of the second column of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> is shown in lines 15 and 16.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx1.p7" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p7' class='ltx_para'> |
<p class="ltx_p">line 18 demonstrates that the triple-dot notation can | <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> | also be successfully applied if no axis can be matched at all.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx1.p8" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p8' class='ltx_para'> |
<p class="ltx_p">The difference between the single-dot and the | <p class='ltx_p'>The difference between the single-dot and the |
triple-dot notation is shown in lines 23 and 24. | triple-dot notation is shown in lines 23 and 24. |
While the selection in line 23 is identical to | While the selection in line 23 is identical to |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">arr3d</span>[[.,1,.]]</span>, the one in line 24 is identical to <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">arr3d</span>[[.,.,1]]</span>.</p> | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>arr3d</span>[[.,1,.]]</span>, the one in line 24 is identical to <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>arr3d</span>[[.,.,1]]</span>.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx1.p9" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx1.p9' class='ltx_para'> |
<p class="ltx_p">Only in cases where the number of single-dots plus the number of numerical indices | <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> | exceeds the number of axes available, an error message will be generated.</p> |
</div> | </div> |
<div id="Thmtheorem9" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem9' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 9. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 9. </h6> |
<div id="Thmtheorem9.p1" class="ltx_para"> | <div id='Thmtheorem9.p1' class='ltx_para'> |
<p class="ltx_p">How can a selection of all elements of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span> be specified using | <p class='ltx_p'>How can a selection of all elements of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> be specified using |
generalized selections? Try to find all 9 possible solutions! | generalized selections? Try to find all 9 possible solutions! |
</p> | </p> |
</div> | </div> |
</div> | </div> |
<div id="Thmtheorem10" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem10' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 10. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 10. </h6> |
<div id="Thmtheorem10.p1" class="ltx_para"> | <div id='Thmtheorem10.p1' class='ltx_para'> |
<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"><span class="ltx_text ltx_ref_tag">5</span></a>, can this new notation | <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'><span class='ltx_text ltx_ref_tag'>5</span></a>, can this new notation |
be used for selecting “over” empty axis? | 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{\lstinline 1}}}\rangle" display="inline"><mrow><mo stretchy="false">⟨</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">vec</mtext><mo stretchy="false">⟩</mo></mrow></math>, so that | For example, can you specify a selection vector <math id='Thmtheorem10.p1.m1' class='ltx_Math' alttext='{\langle\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">reshape</span>([3,0,5],<span class="ltx_text ltx_lst_space"> </span>[])[<span class="ltx_text ltx_lst_identifier">vec</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><span class="ltx_text ltx_lst_space"> </span>([3,0],<span class="ltx_text ltx_lst_space"> </span>[])</span> | \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 |
| <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([3,0,5],<span class='ltx_text ltx_lst_space'> </span>[])[<span class='ltx_text ltx_lst_identifier'>vec</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><span class='ltx_text ltx_lst_space'> </span>([3,0],<span class='ltx_text ltx_lst_space'> </span>[])</span> |
holds?</p> | holds?</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch2.S2.SS2.SSSx2" class="ltx_subsubsection"> | <section id='Ch2.S2.SS2.SSSx2' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Set Notation</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Set Notation</h6> |
| |
<div id="Ch2.S2.SS2.SSSx2.p1" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx2.p1' class='ltx_para'> |
<p class="ltx_p">The means for composing arrays that have been described so far are rather restricted. | <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 | Apart from element-wise definitions all other operations treat all elements |
uniformly. | uniformly. |
As a consequence, it is difficult to define arrays whose elements differ | As a consequence, it is difficult to define arrays whose elements differ |
depending on their position within the array. | depending on their position within the array. |
The so-called <em class="ltx_emph">set notation</em> facilitates such position dependent array | The so-called <em class='ltx_emph ltx_font_italic'>set notation</em> facilitates such position dependent array |
definitions. | definitions. |
Essentially, it consists of a mapping from index vectors to elements, taking | Essentially, it consists of a mapping from index vectors to elements, taking |
the general form</p> | the general form</p> |
<table id="Ch2.Ex1" class="ltx_equation ltx_eqn_table"> | <table id='Ch2.Ex1' class='ltx_equation ltx_eqn_table'> |
| |
<tr class="ltx_equation ltx_eqn_row ltx_align_baseline"> | <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_eqn_center_padleft'></td> |
<td class="ltx_eqn_cell ltx_align_center"><math id="Ch2.Ex1.m1" class="ltx_Math" alttext="{{{{{{\langle\textrm{\lstinline 1}}}\rangle\ \mathop{\textrm{\lstinline 1}}}}\ % | <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% |
\langle\textrm{\lstinline 1}}}\rangle" display="block"><mrow><mrow><mo stretchy="false">⟨</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">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_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">expression</mtext><mo stretchy="false">⟩</mo></mrow></mrow></mrow></math></td> | \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{% |
<td class="ltx_eqn_cell ltx_eqn_center_padright"></td> | \@listingGroup{ltx_lst_identifier}{index\textunderscore vector}}}}}}\rangle\ % |
| \mathop{\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
| \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers-% |
| \textgreater}}}}}\ \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}{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> | </tr> |
</table> | </table> |
<p class="ltx_p">where <math id="Ch2.S2.SS2.SSSx2.p1.m1" class="ltx_Math" alttext="{{\langle\textrm{\lstinline 1}}}\rangle" display="inline"><mrow><mo stretchy="false">⟨</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">index_vector</mtext><mo stretchy="false">⟩</mo></mrow></math> either is a variable or a vector of variables | <p class='ltx_p'>where <math id='Ch2.S2.SS2.SSSx2.p1.m1' class='ltx_Math' alttext='{\langle\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
and <math id="Ch2.S2.SS2.SSSx2.p1.m2" class="ltx_Math" alttext="{{\langle\textrm{\lstinline 1}}}\rangle" display="inline"><mrow><mo stretchy="false">⟨</mo><mtext class="ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">expression</mtext><mo stretchy="false">⟩</mo></mrow></math> is a <span class="ltx_text ltx_font_smallcaps">SaC</span> expression that refers to | \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{\lstinline{{\lst@@@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 <span class='ltx_text ltx_font_smallcaps'>SaC</span> expression that refers to |
the index vector or its components and defines the | the index vector or its components and defines the |
individual array elements. | individual array elements. |
by the expression given and, thus, it is not specified explicitly.</p> | by the expression given and, thus, it is not specified explicitly.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx2.p2" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx2.p2' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'><span class='ltx_text ltx_framed_rectangle' style='border-color: black;'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch2.S2.SS2.SSSx2.p2.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_bold">A note for language design freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for language design freaks:</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">You may wonder why we restrict the expressiveness of the set notation | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>You may wonder why we restrict the expressiveness of the set notation |
by relying on compiler driven range detection rather than an explicit | by relying on compiler driven range detection rather than an explicit |
range specification. | range specification. |
the capabilities of the set notation suffice whereas an explicit specification | the capabilities of the set notation suffice whereas an explicit specification |
of ranges would obfuscate the code.</span></span> | of ranges would obfuscate the code.</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">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"><span class="ltx_text ltx_ref_tag">4</span></a>, <span class="ltx_text ltx_font_smallcaps">SaC</span> provides a | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>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'><span class='ltx_text ltx_ref_tag'>4</span></a>, <span class='ltx_text ltx_font_smallcaps'>SaC</span> provides a |
more versatile language construct for defining arrays. | more versatile language construct for defining arrays. |
However, the expressiveness of that construct comes for quite some | However, the expressiveness of that construct comes for quite some |
specificational overhead. | specificational overhead.</span></span> |
</span></span> | </span></span> |
</span> | </span></p> |
</p> | |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx2.p3" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx2.p3' class='ltx_para'> |
<p class="ltx_p">Let us have a look at some examples:</p> | <p class='ltx_p'>Let us have a look at some examples:</p> |
</div> | </div> |
<figure id="LST14" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST14' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 14: </span>Basic Set Notation</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 14: </span>Basic Set Notation</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsw%0ALDEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgbWF0ID0ge1tpXSAtPiB2ZWN0W1tpXV0qMTArdmVjdH07%0ACiAgcHJpbnQobWF0KTsKCiAgbWF0X2luYyA9IHtpdiAtPiBtYXRbaXZdICsgMX07CiAgcHJpbnQo%0AbWF0X2luYyk7CgogIG1hdF90cmFucyA9IHtbaSxqXSAtPiBtYXRbW2osaV1dfTsKICBwcmludCht%0AYXRfdHJhbnMpOwoKICBtYXRfZGlhZyA9IHtbaSxqXSAtPiB3aGVyZShpID09IGogLCBtYXRbW2ks%0Aal1dICwgMCl9OwogIHByaW50KG1hdF9kaWFnKTsKCiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFswLDEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgbWF0ID0ge1tpXSAtPiB2ZWN0W1tpXV0qMTArdmVjdH07CiAgcHJpbnQobWF0KTsKCiAgbWF0X2luYyA9IHtpdiAtPiBtYXRbaXZdICsgMX07CiAgcHJpbnQobWF0X2luYyk7CgogIG1hdF90cmFucyA9IHtbaSxqXSAtPiBtYXRbW2osaV1dfTsKICBwcmludChtYXRfdHJhbnMpOwoKICBtYXRfZGlhZyA9IHtbaSxqXSAtPiB3aGVyZShpID09IGogLCBtYXRbW2ksal1dICwgMCl9OwogIHByaW50KG1hdF9kaWFnKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx215' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx216' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx217' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx218' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx219' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx220' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[0,1,2,3,4,5,6,7,8,9]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx221' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx222' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>{[<span class="ltx_text ltx_lst_identifier">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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx223' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx224' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx225' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx226' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat_inc</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'>mat_inc</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx227' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx228' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>,j]<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>[[j,<span class="ltx_text ltx_lst_identifier">i</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>]]}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx229' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx230' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx231' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat_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>,j]<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>j<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>,j]]<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;'>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)}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx232' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat_diag</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_diag</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx233' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx234' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx235' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS2.SSSx2.p4" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx2.p4' class='ltx_para'> |
<p class="ltx_p">The set notation in line 8 defines a vector whose components | <p class='ltx_p'>The set notation in line 8 defines a vector whose components |
at position <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[<span class="ltx_text ltx_lst_identifier">i</span>]</span> are vectors that are computed from adding | at position <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[<span class='ltx_text ltx_lst_identifier'>i</span>]</span> are vectors that are computed from adding |
a multiple of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">1</span> to the vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">vect</span>. | a multiple of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>10</span> to the vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>vect</span>. |
The legal range of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</span> is derived from the selection | The legal range of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</span> is derived from the selection |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">vect</span>[[<span class="ltx_text ltx_lst_identifier">i</span>]]</span> yielding in fact a matrix with shape <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[10,10]</span>. | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>vect</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>]]</span> yielding in fact a matrix with shape <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[10,10]</span>. |
An explicit element-wise increment operation is specified in line 11. | An explicit element-wise increment operation is specified in line 11. |
Since the operation does not need to refer to individual axes a | Since the operation does not need to refer to individual axes a |
variable <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">iv</span> is used for the entire index vector rather than | variable <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span> is used for the entire index vector rather than |
having variables for individual index components. | having variables for individual index components. |
Line 14 shows how the matrix can be transposed, and line 17 | Line 14 shows how the matrix can be transposed, and line 17 |
changes all non-diagonal elements to <span class="ltx_text ltx_lstlisting"></span>.</p> | changes all non-diagonal elements to <span class='ltx_text ltx_lstlisting'></span>.</p> |
</div> | </div> |
<div id="Thmtheorem11" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem11' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 11. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 11. </h6> |
<div id="Thmtheorem11.p1" class="ltx_para"> | <div id='Thmtheorem11.p1' class='ltx_para'> |
<p class="ltx_p">Which of these operations can be expressed in terms of the array operations | <p class='ltx_p'>Which of these operations can be expressed in terms of the array operations |
defined so far?</p> | defined so far?</p> |
</div> | </div> |
</div> | </div> |
<div id="Thmtheorem12" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem12' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 12. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 12. </h6> |
<div id="Thmtheorem12.p1" class="ltx_para"> | <div id='Thmtheorem12.p1' class='ltx_para'> |
<p class="ltx_p">What results do you expect if <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span> is an empty matrix, e.g. <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">reshape</span>([10,0],<span class="ltx_text ltx_lst_space"> </span>[])</span>?</p> | <p class='ltx_p'>What results do you expect if <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> is an empty matrix, e.g. <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>reshape</span>([10,0],<span class='ltx_text ltx_lst_space'> </span>[])</span>?</p> |
</div> | </div> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx2.p5" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx2.p5' class='ltx_para'> |
<p class="ltx_p">As we can see from the set notation in line 8, non-scalar expressions | <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 | within the set notation per default constitute the inner axes of the |
result array. | result array. |
axes that should constitute the result axis.</p> | axes that should constitute the result axis.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx2.p6" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx2.p6' class='ltx_para'> |
<p class="ltx_p">A few examples:</p> | <p class='ltx_p'>A few examples:</p> |
</div> | </div> |
<figure id="LST15" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST15' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 15: </span>Advanced Set Notation</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 15: </span>Advanced Set Notation</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsw%0ALDEsMiwzXTsKCiAgbWF0ID0ge1suLGldIC0+IHZlY3RbW2ldXSo0ICsgdmVjdH07CiAgcHJpbnQo%0AbWF0KTsKCiAgYXJyM2QgPSB7W2ldIC0+IHZlY3RbW2ldXSoxNiArIG1hdH07CiAgcHJpbnQoYXJy%0AM2QpOwoKICBhcnIzZCA9IHtbLiwuLGldIC0+IHZlY3RbW2ldXSoxNiArIG1hdH07CiAgcHJpbnQo%0AYXJyM2QpOwoKICBhcnIzZCA9IHtbLixpXSAtPiB2ZWN0W1tpXV0qMTYgKyBtYXR9OwogIHByaW50%0AKGFycjNkKTsKCiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFswLDEsMiwzXTsKCiAgbWF0ID0ge1suLGldIC0+IHZlY3RbW2ldXSo0ICsgdmVjdH07CiAgcHJpbnQobWF0KTsKCiAgYXJyM2QgPSB7W2ldIC0+IHZlY3RbW2ldXSoxNiArIG1hdH07CiAgcHJpbnQoYXJyM2QpOwoKICBhcnIzZCA9IHtbLiwuLGldIC0+IHZlY3RbW2ldXSoxNiArIG1hdH07CiAgcHJpbnQoYXJyM2QpOwoKICBhcnIzZCA9IHtbLixpXSAtPiB2ZWN0W1tpXV0qMTYgKyBtYXR9OwogIHByaW50KGFycjNkKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx236' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx237' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx238' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx239' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx240' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx241' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[0,1,2,3]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx242' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx243' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>{[.,<span class="ltx_text ltx_lst_identifier">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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx244' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx245' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx246' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx247' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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'>arr3d</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx248' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx249' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx250' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx251' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx252' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx253' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">arr3d</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx254' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx255' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx256' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS2.SSSx2.p7" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx2.p7' class='ltx_para'> |
<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. | <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 | As can be seen in line 17, the axes of the expressions can even be put into |
non-adjacent axes of the result.</p> | non-adjacent axes of the result.</p> |
</div> | </div> |
<div id="Thmtheorem13" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem13' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 13. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 13. </h6> |
<div id="Thmtheorem13.p1" class="ltx_para"> | <div id='Thmtheorem13.p1' class='ltx_para'> |
<p class="ltx_p">The ‘.’ symbol in the set notation allows us to direct a computation | <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 | to any axes of the result. This is identical to first putting the result |
into the innermost axes and then transposing the result. | into the innermost axes and then transposing the result. |
</div> | </div> |
</section> | </section> |
<section id="Ch2.S2.SS2.SSSx3" class="ltx_subsubsection"> | <section id='Ch2.S2.SS2.SSSx3' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Axis Control</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Axis Control</h6> |
| |
<div id="Ch2.S2.SS2.SSSx3.p1" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx3.p1' class='ltx_para'> |
<p class="ltx_p">Although generalized selections and the set notation per se can be useful, | <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. | their real potential shows when they are used in combination. |
Together, they constitute means to control the axes a given operation | Together, they constitute means to control the axes a given operation |
the results to the overall array.</p> | the results to the overall array.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx3.p2" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx3.p2' class='ltx_para'> |
<p class="ltx_p">For example, we can now easily sum up the individual rows or columns | <p class='ltx_p'>For example, we can now easily sum up the individual rows or columns |
of a matrix:</p> | of a matrix:</p> |
</div> | </div> |
<figure id="LST16" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST16' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 16: </span>Axis Control: sum</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 16: </span>Axis Control: sum</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsw%0ALDEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgbWF0ID0ge1suLGldIC0+IHZlY3RbW2ldXSoxMCt2ZWN0%0AfTsKICBwcmludChtYXQpOwoKICBzdW1fcm93cyA9IHtbaV0gLT4gc3VtKG1hdFtbaV1dKX07CiAg%0AcHJpbnQoc3VtX3Jvd3MpOwoKICBzdW1fY29scyA9IHtbaV0gLT4gc3VtKCBtYXRbWy4saV1dKX07%0ACiAgcHJpbnQoc3VtX2NvbHMpOwoKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFswLDEsMiwzLDQsNSw2LDcsOCw5XTsKCiAgbWF0ID0ge1suLGldIC0+IHZlY3RbW2ldXSoxMCt2ZWN0fTsKICBwcmludChtYXQpOwoKICBzdW1fcm93cyA9IHtbaV0gLT4gc3VtKG1hdFtbaV1dKX07CiAgcHJpbnQoc3VtX3Jvd3MpOwoKICBzdW1fY29scyA9IHtbaV0gLT4gc3VtKCBtYXRbWy4saV1dKX07CiAgcHJpbnQoc3VtX2NvbHMpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx257' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx258' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx259' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx260' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx261' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx262' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[0,1,2,3,4,5,6,7,8,9]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx263' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx264' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>{[.,<span class="ltx_text ltx_lst_identifier">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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx265' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx266' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx267' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]])}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx268' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">sum_rows</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx269' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx270' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]])}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx271' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx272' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx273' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx274' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS2.SSSx3.p3" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx3.p3' class='ltx_para'> |
<p class="ltx_p">Reduction operations, in general, are prone to axis control, as they | <p class='ltx_p'>Reduction operations, in general, are prone to axis control, as they |
often need to be applied to certain | often need to be applied to certain |
particular axes rather than entire arrays. | particular axes rather than entire arrays. |
Other popular examples are the maximum (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">maxval</span>) and | Other popular examples are the maximum (<span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>maxval</span>) and |
minimum (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">minval</span>) operations:</p> | minimum (<span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>minval</span>) operations:</p> |
</div> | </div> |
<figure id="LST17" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST17' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 17: </span>Axis Control: max</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 17: </span>Axis Control: max</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsw%0ALDEsMiwzXTsKCiAgYXJyM2QgPSB7W2ksal0gLT4gdmVjdFtbaV1dKjQgKyB2ZWN0W1tqXV0qMTYg%0AKyB2ZWN0fTsKICBwcmludChhcnIzZCk7CgogIG1heF9pbm5lcl92ZWN0cyA9IHtbaSxqXSAtPiBt%0AYXh2YWwoYXJyM2RbW2ksal1dKX07CiAgcHJpbnQobWF4X2lubmVyX3ZlY3RzKTsKCiAgbWF4X2lu%0AbmVyX2FycmF5cyA9IHtbaV0gLT4gbWF4dmFsKGFycjNkW1tpXV0pfTsKICBwcmludChtYXhfaW5u%0AZXJfYXJyYXlzKTsKCiAgbWF4X291dGVyX2FycmF5cyA9IHtbaV0gLT4gbWF4dmFsKGFycjNkW1su%0ALC4saV1dKX07CiAgcHJpbnQobWF4X291dGVyX2FycmF5cyk7CgogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFswLDEsMiwzXTsKCiAgYXJyM2QgPSB7W2ksal0gLT4gdmVjdFtbaV1dKjQgKyB2ZWN0W1tqXV0qMTYgKyB2ZWN0fTsKICBwcmludChhcnIzZCk7CgogIG1heF9pbm5lcl92ZWN0cyA9IHtbaSxqXSAtPiBtYXh2YWwoYXJyM2RbW2ksal1dKX07CiAgcHJpbnQobWF4X2lubmVyX3ZlY3RzKTsKCiAgbWF4X2lubmVyX2FycmF5cyA9IHtbaV0gLT4gbWF4dmFsKGFycjNkW1tpXV0pfTsKICBwcmludChtYXhfaW5uZXJfYXJyYXlzKTsKCiAgbWF4X291dGVyX2FycmF5cyA9IHtbaV0gLT4gbWF4dmFsKGFycjNkW1suLC4saV1dKX07CiAgcHJpbnQobWF4X291dGVyX2FycmF5cyk7CgogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx275' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx276' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx277' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx278' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx279' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx280' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[0,1,2,3]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx281' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx282' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>,j]<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>[[j]]*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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx283' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">arr3d</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx284' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx285' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>,j]<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>,j]])}; | <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>]])}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx286' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">max_inner_vects</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx287' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx288' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]])}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx289' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx290' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx291' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]])}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx292' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">max_outer_arrays</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx293' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx294' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx295' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS2.SSSx3.p4" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx3.p4' class='ltx_para'> |
<p class="ltx_p">In line 8, we directly generate a 3 dimensional array from the vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">vect</span>. | <p class='ltx_p'>In line 8, we directly generate a 3 dimensional array from the vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>vect</span>. |
Lines 11, 14, and 17 compute maxima within different slices of that array. | Lines 11, 14, and 17 compute maxima within different slices of that array. |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">max_inner_vects</span> is a matrix containing the maxima within the innermost vectors, | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>max_inner_vects</span> is a matrix containing the maxima within the innermost vectors, |
i.e. the 3-dimensional array is considered a matrix of vectors whose maximum | i.e. the 3-dimensional array is considered a matrix of vectors whose maximum |
values are computed. | values are computed. |
For <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">max_inner_arrays</span>, the array is considered a vector of matrices; it contains | For <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>max_inner_arrays</span>, the array is considered a vector of matrices; it contains |
the maximum values of these subarrays. | the maximum values of these subarrays. |
The last example demonstrates, that outer dimensions can be considered for | The last example demonstrates, that outer dimensions can be considered for |
reduction as well.</p> | reduction as well.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx3.p5" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx3.p5' class='ltx_para'> |
<p class="ltx_p">Further demand for axis control arises in the context of array operations | <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 | that are dedicated to one fixed axis (usually the outermost one) and that need |
to be applied to another one. | to be applied to another one. |
Examples for this situation are the concatenation operation (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">++</span>) | Examples for this situation are the concatenation operation (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>++</span>) |
and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reverse</span>:</p> | and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reverse</span>:</p> |
</div> | </div> |
<figure id="LST18" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST18' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 18: </span>Axis Control: ++, reverse</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 18: </span>Axis Control: ++, reverse</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFsw%0ALDEsMiwzXTsKCiAgYXJyM2QgPSB7W2ksal0gLT4gdmVjdFtbaV1dKjQgKyB2ZWN0W1tqXV0qMTYg%0AKyB2ZWN0fTsKICBwcmludChhcnIzZCk7CgogIHByaW50KGFycjNkICsrIGFycjNkKTsKICBwcmlu%0AdCh7W2ldIC0+IGFycjNkW1tpXV0gKysgYXJyM2RbW2ldXX0pOwogIHByaW50KHtbaSxqXSAtPiBh%0AcnIzZFtbaSxqXV0gKysgYXJyM2RbW2ksal1dfSk7CgogIHByaW50KHJldmVyc2UoIGFycjNkKSk7%0ACiAgcHJpbnQoeyBbaV0gLT4gcmV2ZXJzZShhcnIzZFtbaV1dKX0pOwogIHByaW50KHsgW2ksal0g%0ALT4gcmV2ZXJzZShhcnIzZFtbaSxqXV0pfSk7CgogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgdmVjdCA9IFswLDEsMiwzXTsKCiAgYXJyM2QgPSB7W2ksal0gLT4gdmVjdFtbaV1dKjQgKyB2ZWN0W1tqXV0qMTYgKyB2ZWN0fTsKICBwcmludChhcnIzZCk7CgogIHByaW50KGFycjNkICsrIGFycjNkKTsKICBwcmludCh7W2ldIC0+IGFycjNkW1tpXV0gKysgYXJyM2RbW2ldXX0pOwogIHByaW50KHtbaSxqXSAtPiBhcnIzZFtbaSxqXV0gKysgYXJyM2RbW2ksal1dfSk7CgogIHByaW50KHJldmVyc2UoIGFycjNkKSk7CiAgcHJpbnQoeyBbaV0gLT4gcmV2ZXJzZShhcnIzZFtbaV1dKX0pOwogIHByaW50KHsgW2ksal0gLT4gcmV2ZXJzZShhcnIzZFtbaSxqXV0pfSk7CgogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx296' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx297' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx298' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx299' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx300' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx301' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">vect</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>[0,1,2,3]; | <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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx302' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx303' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>,j]<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>[[j]]*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;'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx304' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">arr3d</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx305' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx306' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx307' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>({[<span class="ltx_text ltx_lst_identifier">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;'>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>]]}); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx308' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>({[<span class="ltx_text ltx_lst_identifier">i</span>,j]<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>,j]]<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>,j]]}); | <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>]]}); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx309' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx310' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx311' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>({<span class="ltx_text ltx_lst_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;'>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>]])}); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx312' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>({<span class="ltx_text ltx_lst_space"> </span>[<span class="ltx_text ltx_lst_identifier">i</span>,j]<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>,j]])}); | <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>]])}); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx313' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx314' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx315' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS2.SSSx3.p6" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx3.p6' class='ltx_para'> |
<p class="ltx_p">Line 11 shows a standard application of the concatenation of two arrays. | <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 | It affects the outermost axis only, resulting in an array of shape |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[8,<span class="ltx_text ltx_lst_space"> </span>0,<span class="ltx_text ltx_lst_space"> </span>0]</span>. | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[8,<span class='ltx_text ltx_lst_space'> </span>0,<span class='ltx_text ltx_lst_space'> </span>0]</span>. |
The two subsequent lines show, how to apply concatenation to other axis. | 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 | Essentially, the selections on the right hand sides select the sub expressions to |
subarrays back together again.</p> | subarrays back together again.</p> |
</div> | </div> |
<div id="Ch2.S2.SS2.SSSx3.p7" class="ltx_para"> | <div id='Ch2.S2.SS2.SSSx3.p7' class='ltx_para'> |
<p class="ltx_p">The examples in lines 15-17 show the same exercise for the operation | <p class='ltx_p'>The examples in lines 15-17 show the same exercise for the operation |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">reverse</span> which reverses the order of the elements within an array | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>reverse</span> which reverses the order of the elements within an array |
with respect to the outermost axis.</p> | with respect to the outermost axis.</p> |
</div> | </div> |
<div id="Thmtheorem14" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem14' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 14. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 14. </h6> |
<div id="Thmtheorem14.p1" class="ltx_para"> | <div id='Thmtheorem14.p1' class='ltx_para'> |
<p class="ltx_p">The operation <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">take</span> is defined in a way that ensures inner axes | <p class='ltx_p'>The operation <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>take</span> is defined in a way that ensures inner axes |
to be taken completely in case the take vector does not provide enough | to be taken completely in case the take vector does not provide enough |
entities for all axes. | entities for all axes. |
How can <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">take</span> be applied to an array so that the outermost axis | How can <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>take</span> be applied to an array so that the outermost axis |
remains untouched and the selections are applied to inner axes, starting at the | 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 | second one? (You may assume, that the take vector has fewer elements |
</div> | </div> |
</div> | </div> |
<div id="Thmtheorem15" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem15' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 15. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 15. </h6> |
<div id="Thmtheorem15.p1" class="ltx_para"> | <div id='Thmtheorem15.p1' class='ltx_para'> |
<p class="ltx_p">Can you merge two vectors of identical length element-wise? | <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 | 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> | arrays on the outermost axis.</p> |
</div> | </div> |
</section> | </section> |
</section> | </section> |
<section id="Ch2.S2.SS3" class="ltx_subsection"> | <section id='Ch2.S2.SS3' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">2.2.3 </span>Putting it all Together</h5> | <span class='ltx_tag ltx_tag_subsection'>2.2.3 </span>Putting it all Together</h5> |
| |
<div id="Ch2.S2.SS3.p1" class="ltx_para"> | <div id='Ch2.S2.SS3.p1' class='ltx_para'> |
<p class="ltx_p">The array operations presented so far constitute a substantial | <p class='ltx_p'>The array operations presented so far constitute a substantial |
subset of the functionality that is provided by array programming | subset of the functionality that is provided by array programming |
languages such as <span class="ltx_text ltx_font_smallcaps">APL</span>. | languages such as <span class='ltx_text ltx_font_smallcaps'>APL</span>. |
When orchestrated properly, these suffice to express rather complex | When orchestrated properly, these suffice to express rather complex |
array operations very concisely. | array operations very concisely. |
power: matrix product and relaxation.</p> | power: matrix product and relaxation.</p> |
</div> | </div> |
<section id="Ch2.S2.SS3.SSSx1" class="ltx_subsubsection"> | <section id='Ch2.S2.SS3.SSSx1' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Matrix Product</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Matrix Product</h6> |
| |
<div id="Ch2.S2.SS3.SSSx1.p1" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx1.p1' class='ltx_para'> |
<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 | <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> | as follows:</p> |
</div> | </div> |
<div id="Ch2.S2.SS3.SSSx1.p2" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx1.p2' class='ltx_para'> |
<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> | <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 | 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> | <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 | 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> | <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> |
</div> | </div> |
<div id="Ch2.S2.SS3.SSSx1.p3" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx1.p3' class='ltx_para'> |
<p class="ltx_p">This definition can directly be translated into the following <span class="ltx_text ltx_font_smallcaps">SaC</span> code:</p> | <p class='ltx_p'>This definition can directly be translated into the following <span class='ltx_text ltx_font_smallcaps'>SaC</span> code:</p> |
</div> | </div> |
<figure id="LST19" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST19' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 19: </span>Matrix Product</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 19: </span>Matrix Product</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgaWQgPSBbWzFk%0ALCAwZCwgMGRdLCBbMGQsIDFkLCAwZF0sIFswZCwgMGQsIDFkXV07CgogIHZlY3QgPSBbMWQsIDJk%0ALCAzZCwgNGRdOwogIG1hdCA9IFt2ZWN0LCB2ZWN0KzRkLCB2ZWN0KzhkXTsKICBwcmludChtYXQp%0AOwoKICByZXMgPSB7W2ksal0gLT4gc3VtKGlkW1tpLC5dXSAqIG1hdFtbLixqXV0pfTsKICBwcmlu%0AdChyZXMpOwoKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgaWQgPSBbWzFkLCAwZCwgMGRdLCBbMGQsIDFkLCAwZF0sIFswZCwgMGQsIDFkXV07CgogIHZlY3QgPSBbMWQsIDJkLCAzZCwgNGRdOwogIG1hdCA9IFt2ZWN0LCB2ZWN0KzRkLCB2ZWN0KzhkXTsKICBwcmludChtYXQpOwoKICByZXMgPSB7W2ksal0gLT4gc3VtKGlkW1tpLC5dXSAqIG1hdFtbLixqXV0pfTsKICBwcmludChyZXMpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx316' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx317' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx318' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx319' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx320' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx321' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx322' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx323' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx324' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx325' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx326' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx327' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>,j]<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>[[.,j]])}; | <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>]])}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx328' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">res</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx329' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx330' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx331' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS3.SSSx1.p4" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx1.p4' class='ltx_para'> |
<p class="ltx_p">After defining two matrices <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">id</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span> in | <p class='ltx_p'>After defining two matrices <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>id</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span> in |
lines6 and 8, respectively, | lines6 and 8, respectively, |
the matrix product <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">id</span><span class="ltx_text ltx_lst_space"> </span><math id="Ch2.S2.SS3.SSSx1.p4.m1" class="ltx_Math" alttext="\odot" display="inline"><mo>⊙</mo></math><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">mat</span></span> is specified in line 12. | the matrix product <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>id</span><span class='ltx_text ltx_lst_space'> </span><math id='Ch2.S2.SS3.SSSx1.p4.m1' class='ltx_Math' alttext='\odot' display='inline'><mo>⊙</mo></math><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>mat</span></span> is specified in line 12. |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">id</span>[[<span class="ltx_text ltx_lst_identifier">i</span>,.]]</span> selects the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</span>-th row of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">id</span> and | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>id</span>[[<span class='ltx_text ltx_lst_identifier'>i</span>,.]]</span> selects the <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</span>-th row of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>id</span> and |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">mat</span>[[.,j]]</span> refers to the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">j</span>-th column of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span>. | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>mat</span>[[.,<span class='ltx_text ltx_lst_identifier'>j</span>]]</span> refers to the <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>j</span>-th column of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span>. |
The index ranges for <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">j</span> are deduced from the accesses | The index ranges for <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>j</span> are deduced from the accesses |
into <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">id</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mat</span>, respectively. | into <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>id</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mat</span>, 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 | 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 <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">*</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sum</span>.</p> | as we can make use of the array operations <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>*</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sum</span>.</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch2.S2.SS3.SSSx2" class="ltx_subsubsection"> | <section id='Ch2.S2.SS3.SSSx2' class='ltx_subsubsection'> |
<h6 class="ltx_title ltx_title_subsubsection">Relaxation</h6> | <h6 class='ltx_title ltx_title_subsubsection'>Relaxation</h6> |
| |
<div id="Ch2.S2.SS3.SSSx2.p1" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx2.p1' class='ltx_para'> |
<p class="ltx_p">Numerical approximations to the solution of partial differential equations | <p class='ltx_p'>Numerical approximations to the solution of partial differential equations |
are often made by applying so-called <span class="ltx_text ltx_font_italic">relaxation methods</span>. | are often made by applying so-called <span class='ltx_text ltx_font_italic'>relaxation methods</span>. |
These require large arrays to be iteratively modified by so-called | These require large arrays to be iteratively modified by so-called |
<span class="ltx_text ltx_font_italic">stencil operations</span> until a certain convergence criterion is met. | <span class='ltx_text ltx_font_italic'>stencil operations</span> 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"><span class="ltx_text ltx_ref_tag">2.1</span></a> illustrates such a stencil operation.</p> | 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'><span class='ltx_text ltx_ref_tag'>2.1</span></a> illustrates such a stencil operation.</p> |
</div> | </div> |
<figure id="Ch2.F1" class="ltx_figure"><img src="x1.png" id="Ch2.F1.g1" class="ltx_graphics ltx_centering" width="209" height="130" alt=""> | <figure id='Ch2.F1' class='ltx_figure'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANEAAACCCAYAAADYIC22AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAABaAAAAWgBwI7h9AAAg2UlEQVR42u2deXRVVZ7vP+fem4GbkJAEQhAQCIQpzAgIKI6oIM6gdmkpPrV0WV2vumuwrbbarlrVz9XV7eu2X3WprShlLxwQLQSbkhJlksEAQSKgJEwRQiCzmW7u/H1/3BADBMg5wdIk+8O6a3HPPeeXc8/d37N/e5/f77ctSRgM3YFgMKjly5cTDAbxer3cfvvtWJZlddSuZURk6A7U1tZq8eLF3HfffaSlpXH06FHWrFnDgw8+aERkMJyPUCik3//+9zz22GPEx8e3iCYvL08A06ZN65CQXOYSG7o6S5Ys4d577z1FQABTp06loKCgw/aNiAxdmoKCAg0ePJjevXuf0dtYlmVlZ2dz8OBBGREZDG0QiUS0efNmrrzyyrPuc/nll7N161bTExkMbbF69Wquv/76c87AxcfHEw6HjYgMhtMJBAIqKytj6NCh55w0sCzLSktLo6amRkZEBkMr3nvvPebNm9eufadMmcLOnTtNT2QwnMTv96uhoYHMzMx2TV1nZmZy/PhxIyKD4fSxUHvxeDwdClwwIjJ0KUKhkCorK+nXr5/1l/qbRkSGLsXGjRuZNWuW7eOSkpKora2VEZGhWxONRnXo0CFycnJsH5udnc2RI0dMT2To3uzdu5cxY8Y4isweNGgQhw4dMiIydG/y8vKYNm2ao2O9Xi9NTU1GRIbuS3l5udLT03G5XI4mFDweD5FIxIjI0H1Zu3Yt1113nePjOzLHbURk6PSEQiH5/X6Sk5M7NK0djUaNiAzdk08//ZSpU6d22E58fLyj4zzmJzB0diZPnozL1fH+wLIsAoGAEhISbPVopicydHrcbrd1IQqO9O3bl4qKCuPOGQxOSU9Pp6qqyojIYDA9kcHwLZGamkpNTY0RUXcgFAqpvLy8Q8U1ampqVFpa2iEbpaWlqqqq6pCNqqoqBQKBDtkoKytTOBzucO03l8vl6IGrEVEnpKGhgU2bNnXIRmVlJcXFxR2y8eWXX1JWVtYhGzt37nQ0DmnNhg0b8Pv9XAgROXlWZERkMLQSkZNipkZEnZBjwHEgAo5cGIFKmm3IoY0o6FgHbYSbz+NER1zb5vM4cQGuq2VZltvtdnBBJfPqRK/HJcX5/XLt36+5knyS7BwflvSQJE99vdxVVfqepKBNG02S5ktyV1Uprq5Ofy0pbNNGraTrJLmKi5VQX69/kBS1aaNM0nRJVmGhvIGAnrV5fFuv1157zbYN0zA70WubJOu0jb+32XBWtbFxmU0bfzhtgyVpnU0b/3raBo+kz2za+PlpG3pIOtJBIS1ZssT28Sbs5zvO3r179cknnwCwG9CCBZCS0vL5n1esIKGyst3u1BaAG2+ErKyWbSuWLqW2oaHdNj4AuOMO6NUr5s2EwyxbupSDfn+7bax1u+HOO8Hrjbl21dUsWb6c4TZcwy29e8Mtt7S899fV8eqyZfRrtjFt2jTGjBlj2fXMjDvXhV/Vkvq32hAnaYfNO+8RSemtNqRIKrJpY7ekpFYb+koqtWljo6T4VhuGSvrKpo0VklytNkyU1NTBnuj111+3fbyZWOhEpIG1AXigoYGrtm7lI2CSTRsDwVoP3Pnll9y0axfrgGE2bYwB6yPgxm3buLuwkHVAP7B1x78MeB+4dtcu/ld1NR8BqTZt3AS8C8z89FP+dyDAn4BEmzbOmDBxMMVt3LlOxlCw/m8opHXHj3O5wwYzFqx/CgZV4fMxyaGNaWA9GYkoNRJhlAMbFlhXA5GKCuVmZnKRQxs3AU3792tuTg7JNqOv2yIhIYFwOCyPx9NuW6YnMhha4fV6aWhoMM+JDIaOiKiurs6IyGBwSnJyMoFAwIjIYHBKYmIioVDIiMhgcEp8fLxx5wyGjtCzZ08aGxuNiAyGjoiow2OiwsJCdeWLJEnRaFSmuRjawuPxUF9f71xEx44d0wsvvNClL9KLL75Ifn6+aS2GNrEsC4/H41xEn3zyCTNnzuzSF2nChAl8/PHHprUYzioiuynip4hoy5YtXHrppV36Io0cOZLCwsLO646CPgcOAgGHyXCRZhtFxJLanNgIEtQe9vAFXxAh4siGH7QPKCSW5OfEhg9U1PxdnCYHni6iuLg422OEltfdd9+tSCSirhwJHY1Gde+99yoYDHa67xmV9KgkVyAgjh7VNEm1NqOWQ5LulGT5fKKuTjc4SOyrU52u0lUigKyQpbt0l4Kydz2rmxPqOH5cLp9Pj0mK2DyPUkljJPH554oLBPTkBUjKC4VCeuONN+Qon8jv96tHjx6Ol6awQyONSiLJit0VI6qiij70oZxyPHjIIMP6Brtra9CgQTpy5AhDhw7tVL3QDuC/AMXHw4AB5AEvAj+zYWMN8BZAjx4ArAYWV1UxP9L+3uR1Xmdd+jqIByGWainzK+czS7PabeO/LIut6emQlUUUeCEc5rbqasbZ6E3+2e1mT0YGjBpFCPjXSIRbq6p0cfPnycnJeL1e223Jbk5Ri4gKCgoYO3bsOXd+GeQGGoHHiEXR2vljO9mpp3mabLL5F/4FgG1sYylLaaKJ2cxmAxsYwxg9wiO2bO8Fvd98bj8Gep3j3CZMmEB+fn6nEFHrpLx9gG65BXr3bvl844oVpNlIytsBZyTl7fr0UwbaWOBqL3vhKrhhI9SnwOZL4dOdn5IQTGi/DZcLrrkGmmsaRH0+PsnLw84yW4VJSXD11S3vQ34/W/LyON78Pjc3l+zsbHvjG5fLuTv37LPPavPmzWftxvZIypIUaE4M2+Gg66xTnS7VpfqRftRy7E/0E72lt+SVV0u1VM/reT2gB2y7KFMkrZL0N5IeP8+5FRcX64knnuh07lyDpOGtNngl7XZQl2BAzG8RwaAyJB22aWO/9itDGbrzTXT9+yhb2apUpS0bOyUlt9qQK6ne5nmsPS2xb0Zz++zINY5EInrllVfkKClv9+7djB8//qxiW9c8C+ECvM1ugF160tNK4Ou7VYiQtrGNOcxhPvNZyELe5E3+mX+2ZbcMKAASgZ7Ekr3ORb9+/Th27Finm1RIak6o+2l9PbesW8dGINemjczmxL4fFBdz786dbAQG2/QohjHM2sxm7uB27ud+1rPetgs+Eax1wO15efykooIPgGSb53Fls3t6w4cf8pTPx0ogvoNJeQB2K/60uHONjY14m/Pd2+L08np1F6BRbGc7ueTixUsOOdzHffw3/80zPNPi7rWHBiDY6n3tefaPj4+34uLi1NjYqKSkJKszCakfWE+Gw1pXU8Nkhw0mG6yfSaqIRBjt0MYIRlgjuFOQCgx0ZOMSsB6tq1NuKOQ4KW8WcKK6WnOjUdsiPIs7Z/Xs2VO2RVRTU6O0tLRzLrk35NQpUgZfgAbxDu9wB3dwiEM8z/PsZz/ppPNn/mzLTu/mHujkuQ1pz9102DAOHDhwzt7X0D1xFIB6PlcOYvnsXqA+dgfgDgcnd4hDOsYxiinmOMe1jW3MZCZZZDGIQexgB/XU8wAP2LKbDswnVsDvBPCD9rgTEyeya9cu02IMZ2C3zoIHYsv1nW/p8jSw3gd9BPxPs2/tYEzEetY3q9fFv/FveIlNQa5hjQop5Gf8jIu52Ha3/jvQh8BfAVe345gxY8awbt0602IMZ5CammpfRLt37+ahhx5qx4ASa1gHTq4PfU4RXl/6tho0J1mTbNeuOXXQfYudc+nThxMnTpgWYzgDu8+JXAA+n++ckwpdkZPrcgaDQRPR7YTGRhEroQs+n7rWV7OXT+SJRCLyeDxciDUvOxv9+/entLSUwYMHG1HYZe1aePttaGqKPbidOLHb9kSeo0ePcvHFF3fLdjBs2DAOHjxoROSEkSNhxYpYGeAhQ7r1pXAVFRWRk5PTLb/88OHDKSoqMoJwwqBBsfCjnBywORDvciIqLi5mSDe9kwwePLjDq8V1W+LjLcaOhUmTYvkDXWu8bE9EJSUl9O/fv1u2g5SUFNvVLg2tmDw5JqIuRjgctiei8vJy+vbte9YdDnBAj/O4PuGTltHWq7yqFazQr/m1lrNcP+SHqqT9kcRs3Soefvjr/X/xC5GXJ556Srz+unjiCdGOWbNaarWIRXqGZ1r2LaFEP+Nn+iN/1Au8oF/yS61lbZu2vF6v7ZmYb5sQaCOQD9Q6TEILENBm12byPHk00uhsZq2xUcFoNFbUw8aSKqf/fnnksZWthAg5slEJ2g5sxfnKgWdcH5uFSvj+97+vaDSqtqOGG7Raq+WSS6u1umWf63W9XtbLGqIhalKTbtNt+oP+0L7I1/JyafZs6fLLY/vX10vXXCP94hfSzTdL4bA0aJC0e7fOv8THbl2iS06J+n5Oz+lZPatMZWq91utNvak5mnNWW/fdd1+nieYOS1pwMgK7vFwjJJXZjFr2y6+rdbUII0JoiqaoNpbad+b+NTVSQYFUe9rntbXaMmWKPgPlg3bOni35fF/vE41K1dVSfv6p21u9TuiERmqkqEL40QItUEghW9/lkKSBkigrkxUO61EHiX1tvRYtWmQvKe9cRRmSSLKmMU2uVlnkJZTIg4dLuIRyyrmDO8gii1tox6POSESsXAnTpsGGDbFtGzbAlCkwdiw88wzcey/ccw+MGHFec2MYY2WR1XL3EdIqVvE7fsdbvMVCFnI5l/MUT529K3Z9t6uG+f1++Xw+IJYLtCwlBTwe6NOHQuA/6+r4GxvLz69mNWt7rsVtwWWbwB3ZTh5PM5vZauP3gt/8Bj7/HIYPF5dcApMmUX/oEH22b29ZkuXzNWsI/Od/kpCSIvLzIT8fDh6EK66AH/0ILOsM2xtYxkXsIz0RtsyEt4Nv873S7zGBCe3+Lk97PBwdMAAyMxGwKBTirmPHGNzcI6WlpZGamvqNj9dsL63yLu9yMzczmtE8zMOsYAUFFPAET9CLXuc+eOVKmDULioshGo2J6p134LHHYrM8t94KH3wQ+//f/R3YTI4qoSQ2YcBg/p6/50meZClLmclMLqVz1o4oKSnhs88+A+ALiCWh9fr6Ou/Pz2d9TU277RVQAFeA1RMGHAVPBOIpA46eubMEoRDU1cGxY5CRAenpBEtLiT+tEUVKSmLT3cXFcPw4NDRAOAxHj0Ib8w6JVDAQaExq/lNBUXywmJ4tocTnp8LrhQEDWt5Hw2EOHjzIyTIjOTk5tkN4HLFw4cKzunOSqFGNPPK0uHOzNVvHdVxLtEQ362aVqUwDNVD/qH88fxd4880xVy01VUpIkJYtk2bNkgIB6W//Vvr1r6UdO2Kfvfdeu7rUeZrX4s49p9i/SlVqgAbomI7pQT2okRp5VlsLFy7sNO6cX9LkWKEIEQgoXdIBm+5LjWo0QiNEMOZGDdRAlcbWuTtz/8rK2O9w+HDsNzpZ66GkROsGDNAR0AHQx6NHK1pT87WNpiZp//7YsY2Nbdrep33KUEbsPCJouqbLJ5+t75J3MrEvEBDRqOZIMYfwL+3ORSIRJJ11lrKeeoTw46eEEsURR1/6kkgifvxkkMEgBjGBCedX7CuvQDAITz0Fu3fH7lAzZsSmS3v0ED4fDB8OmZmx3ug8RImqgQaSSSZKVKtYxfM8jwsXHjyECTOWsfjwndWGozU6v62pV7A+BL1YW8vejz/mH266iaE2A4F70cvayEb9R/F/UF9Rz89n/Jx+9GvbRkaGxbx5Z2y2+ve3rtiyRVVPPkli795kP/EEVq9eX9tITLQYNgyGnT3ScgQjrK1s1W83/ZZho4bxaNaj9KCHre8yFawtoP+zahWXz57NwuRkPBcgp8i2O5eamkpNTQ0ZGRlnfBgkqN3s5kVeJEqUAxzgx/wYC8u6jdsUTzxv8za/4ldc3Z7Y6Yzm7MeHHhJVVTFX4f77Y5/98pfw7ruwalXM7RsxwmqPa7KQhbhxs4c9XM/1DGAAFpa1ilXawAYu4iJe5MWzDNEicrK84LdJL7AelrQuFGKYwwaTSaa1kIWqoIKBDhPqrIEDrd7Z2WLQIMjMdGQjhxzrrvBdyo3m0otejlf9uz0U0lxiQcgX4hrbrbHg6devH2VlZW2KKJ54ay5z2x6Q47Ju4iZnZzlt2plftkcPi7/6K1tmJjLRmsjXMVvjGNfy/9GMtkYz+pzHNzU10aO56o3BATt2QEUFPPBAl/path+29u/fn5KSkm7ZBhobG+nZs6cRgxPCYVFQADt3di6fuH0zovZEdDIIsztSUlJCv379jCCcXTwoK4OiIrBZAL6r4Ro6dGinLqvbEfbv38/w4cONIJywd29sUmj4cPjyy259KTxZWVlWeXm5JKm75RQVFRVx5513GkE4G9fCI49ASgp009jLr+cHujFHjhxhQKuHdQYb9O5t4XLFKpimp3epm29SUpJ9EWVkZFBZWXnenQX6ChTtYKBfkKCifL3QViONChJUkKCqqVaY8Dc+UI1EIgoEAiQnJ1tGEYZTRGEzFMwFMGnSpPOWj4qCfkqsEuoPcRYx20CDFrNYk5nMV3zVsv0hHmINa3iER8gjj3nMo4462bONloH+p50ir66ubnNa32Cwmx7jAhg/fjwFBQXn3HEr8DowD1gFfOTg5IToRS/2sAc1t/MKKlRLLRvYQBFFzGIWRRRRSqkNu+ix5v+/B7zajmMKCwu7bUav4bxein0R5ebmsmfPnvOKyE3skXAisNnByfWkp5VG2inbVrOaq7iKm7mZPexhClP4MT9mBCPabbcKeBfIAPoAL7fjmJ07dzJhwgTTYgxn0KtVgG+7RZSQkGAFg0F0jodm/jPGNReG5SznNm6jH/24ndtJIIHf8ltbPVEVscqsJ7/Q0XYcs2/fPkaOHNnpfuAm0NuWxUduN8cdjk3rQO+63fwpPp4qhzbKKdda1rGO9bZd75McB73vdrPSsvA5PI9i0Bq3m5U4XznwlGFLNCrbJbNO/ic9PZ2qqip6t1r7pjW5MbcJASFg7AVoEBVUqJ56hjCEh3mYXHJ5mqcZznB2sIP+tG/qNBlaQvMF50vIIBKJqK6ujoyMjE41qRACzQPWpqTADTewHMgDDbQRM9YIuhrIz86G7GyWAVtAGTZsHOe4ZjKTKRymFqjiI9axTsm0f5LmS9BlQMlll4HbzR9jrrgSbJzHHtAVQPW8eSyKj+dd4I3YGlod+l1DoZAzEV1yySVs376dOXPmtLnjHGKF4vcDfYFbHJxcgID2sQ+A/eynkEKu4zrcuK2pTNUOdlBLLcMYZiv/JwuYDPiAr9pxblVVVfTp06dTCKexsVEnl4T/BFibkRHLs0pI4Djw/6qq+Gmo/anVq4D89HSIj912ioB/yc/nlkCg3Tbe5m0OTzzM+HgIxcGOyA6ey3+Oy8KXtdvGq5ZFyeTJLeexprGRxQUFtlbKezYxkepJk6A51u0dv5+3du5kULONwYMHc9FFF9kWlN0p7hYRXXrppbz11ltnFVEiWH8GfQZ8gLOI2RAhruAKPudzXLgYzWjmEPt7j/AIl3EZFVSwnvWk0v6MRDdYL4NWA/2JreJ3Lnbt2sWYMWM6hYjKy8v5/PPPATgEcNllp5SoqvziC/Jra9tt7wjA9OmQnv51o0lNJc3G3TeFFHDBezc1t1YL0nqlkRZJa7eNHpYFraeS3W5S0k4fMZ+bhPj4U95bLheprWwkJiban/xqzhFydFAkEtE999xzzgS9rvJ6+umnVVBQ0Om+Z0jStSdrLFRWaqCkYzaT0BokTT1pIxDQKElVNm2Uq1yjNVoEYnUaZmmWGtVoy8aXki4+eR6RiG5wsMrdHkm9JdHUJCIRfe8C1FgIhUJ67bXXnK2U53K5rGg0SmfLr3HC/v37O92ix81ug/UesLi+nh9v2MB2sL04VhJYHwH/fvgwv9qxg81Auk0bfehjbWELv8n/Db8r+h3v837L6h7t5WKwtgE/37SJl8vL+SP2V7nLBWsn8OjKlSzz+fhDbGKpQ+MhSc7dOYCRI0eyb98+cnNzu6yAmpqa1HyhOmWkQmJs9QulxMamjr5DMlg3giqILZnjxEYqqdY1XKNUUm0L6CR9wZodCik3GqWHw/MYCNZVoBuAuAuQlBfr2JpsHXNKfMP06dPZunVrl+6FDh8+bGpvG84pIttJea3fTJs2rWUQ21XZunUrM2bMMK3FcFYR2U3KO8WdS0lJsZ555pkuvV7PjTfe+Jcpo2TolESjUWcr5Z3SNblcXTqqOSsry0RtG85KbW0t5ypoel53zmDo7jipu2FEZDC0IhAIGBEZDB3B5/PZrjtnRGQwtMJJLUIjIoPhtJ7IuHMGQwdobGx0VqjE0HmoAT3ndvNOaipFscVPbD/XKwO97HKxxOPhiMNEtkOgxW43L7vdnHBooxD0usvFy5ZFjQMbAu0CvR0XxyJidTYuhDsXHx9v7zFIV4/Y7kovv6RJrTakSiq0vbSKNKzVhn4OIsEPScpstSFHUrVNG/sk9YqFB4hwWJOlWBy4zaVVvK02XCsp2MEo7jfeeMP28R5zb//2iUQiOnToEDk5OWfcAcvLy3WyVvoOYOfIkbHFtIBa4Jl9+3jU52v3HfgD4MDw4ZCcDMBx4On167mxqandNt4Fyi+/vMXG/kiEf1+/nuntWGf3JK+53Xx1xRUtCXX59fX8ftMmxtjoTZ5LSsI3a1bL+498Pl7ZsIGLm22MGjWKwYMHW6df6+LiYoYMGdJmYIHdRY8BI6JvC0mqq6vjgw8+oL6+nnHjxp1135OFadvy1JMtCzuFa9uyMXTUKMbZaDx7AVonvLlcjB49mnE20mg2WVZs2cyT3zExkdHjWq/rcX76nxZZ4I6PJ3fcOIY0v28rfMeyLEpLS1m/fj2ZmZm65ppr8Hq/jkJ3VATYuEl/2Vc0GlVRUZEWLVqkN998U1VVVe12HyLNCx9b4bCoqdFoSZW2Fz6WZksiHBahkKZLqrdpo1bSdEk0NMhqatKtDhLqyiSNbk7Ks5oT6kIO3MpBkqiulisc1l9LitqwUVpaqiVLlmjx4sU6evSootGo7YQ8SVhdbFWM77TLtnXrVvbu3UtOTg5XXHEFbrfb9m0vAlpdU8O2dev4+e23k+wghyYIWrp/P19VVPDQjBmOcnkCoEVbt5KWmsqdo0c7WqGuHvS7NWvIzc3lxosucmSjBvTbt97ihrlzmZWc7CgpLxAI6MMPP6SkpISamhoef/xxWzGkxp37hgkGg/roo48oLS1l6tSpPPLIIx0KgHWDNQMUAEcCglgG6aXNSXlOk+ESwJoESo01Ikc2eoI1BZTbARtpzedxCc6zWhMSEqwbb7wRSfrVr37FokWLGDlypGbMmIHH47GMiL5F8axevZqKigquvfZa5syZY6LHv+NEo1FGjRrFXXfdxb59+3jllVfIzs7WlVdeeU4xGRF9A27bhx9+yJEjR5gzZw4DBgy44OJJTExkxIgRHbKRlJTkaCbqlIF9//6OKuq0pnfv3h22MWrUKNvxbmcTUfPkgjVq1ChGjRpFUVGRXnrpJcaNG6fp06e36eaZMdEFnG3bs2cPGzdu5Lrrrmtzutrw3SYQCGjlypUsWLDAOv233bVrF1u2bGHu3LkMGTLEMiL6Bi7+m2++Sf/+/bn22muNeDopVVVV2r59OzfccIN1lp5K7733Hn6/n/nz57dMDBkRdZDKykotWbKEe++9l969exsBdWL27t2rYDDIxIkTz/k7fvnll1q+fDkPP/wwSUlJlomd6wD19fVaunQpP/zhD42AugDV1dWkt6oMezYGDRpk/eAHP+Cll14iEonIiKgDvPPOO9x///3ExcUZAX2LNFft7bBLVV5eTmZmZrv29Xq91t13383y5ctNFHdHiIuLM8tVfgfYvn07xcXFF2JsS48ePdr9e2ZlZVnBYNCIqCP4/X78fr8ZVH7LTJgwgU2bNl2IHs3W/rW1tTqlFrfBPgsWLOCFF17gxIkTRkjfIgkJCVbzTe0v8jtI0sGDB/Xqq6+yYMECMzvXUYLBoFauXEldXR1XX301F198cZev3fddpKSkRLt373YcGSJJr7/+Ovfcc491rrFXYWEhmzZt4qKLLmLu3LlYlmWZiIUOEh8fb82fP59QKKSPP/6YDRs24HK5NGbMGEaNGkVCQgKWo/h6gx369+/P6tWrkSQn1zsSieByuc4QVlNTEwUFBRQWFuJyuRg2bBgPPvjgKTdK0xN9A0QiEe3du5cvvviCUCiEJOLi4hg2bBjZ2dmkpKTgdruNuC4weXl5SkxMZPz48bauqyTV1taybNkyxo4dy8GDB4lEIrjdbjweDxMnTiQnJ+esv5cR0V+IQCCgw4cPc+DAARobG1vWBZWEx+MhMTGRzMxMMjIyyMrKwuv14na7cblcRmw2bl6LFy/moYcesk66XyfX3Kqvr+fEiRNUVVVRXl5OIBA4ZUW80tJS0tLSuPLKKxk8eLCtxxZGRN8RmpqadPJHPnHiBD6fD4ilK0vC5XIRjUZb/m9ZFi6Xi5SUFJKSklpeXq+XxMREUlNTW9yTkxps/f67Jkzp60c9J2fJWiUyUltbS1NTE01NTfh8Purr62lsbKSurq7lGEkUFBQwePBgevXqhcvlwu12I4mUlBSysrLIyMigb9++LZMRJ1m1apWmT59Oenq67etiRNSJCYfDqquro76+vqVx+f1+6urqaGhowLIsgsEgPXr0oKGhgaSkJGpra/F6vQSDQQC8Xi+RSASfz0dycjKRSIT6+nrcbjdxcXGEw2GSkpKoq6trEfK5cLlcSCI1NZXa2loSEhLw+/0t2yTh8/lISkrC5XLR0NCAx+PB5XIRDAZJSkoiEAiQmJhIKBTC5XLh8XhISkoiOTkZr9eL1+slISGB1NRUUlJSThmf+P1+vfHGGzzwwAO2xPDaa6/pXJMK58JMLHRiPB6PlZ6e3q5Qle5CYmKi1aNHD9XU1CgtLa3douhIZ2KeExm6HHPnzuVPf/qTrbFUR/6eEZGhy5GSkmJJoq6url3iqK6uJiMjw4jIYGjNLbfcwooVK9q1744dO5g8ebIRkcHQmp49e1oJCQmUlZWdtzcqKysjMzPTMiIyGE7j1ltvZfny5ZwrTSIUCsnu8pJGRIZuQ3x8vDVmzBh27tx51n3y8/MZP368EZHBcDZmzpzJtm3b8LVRr1ySPvvsM8aOHWsZERkMZ8GyLOv73/8+L730EtFo9BQhffHFF2RnZ3f4bxgRGbo8ycnJ1h133MHzzz9PIBAQxBLq1q5de0GqM5mwH0O3oba2Vu+88w7x8fGEQiHuuece+wt6tcH/B9RXhZfHd16gAAAAPHRFWHRjb21tZW50ACBJbWFnZSBnZW5lcmF0ZWQgYnkgR1BMIEdob3N0c2NyaXB0IChkZXZpY2U9cHBtcmF3KQoGgYkVAAAAAElFTkSuQmCC' 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"><span class="ltx_tag ltx_tag_figure">Figure 2.1: </span>A 5-point-stencil relaxation with cyclic boundaries</figcaption> | <figcaption class='ltx_caption ltx_centering'><span class='ltx_tag ltx_tag_figure'>Figure 2.1: </span>A 5-point-stencil relaxation with cyclic boundaries</figcaption> |
</figure> | </figure> |
<div id="Ch2.S2.SS3.SSSx2.p2" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx2.p2' class='ltx_para'> |
<p class="ltx_p">A stencil operation re-computes all elements of an array by computing a weighted | <p class='ltx_p'>A stencil operation re-computes all elements of an array by computing a weighted |
sum of all neighbor elements. | sum of all neighbor elements. |
The weights that are used solely depend on the positions relative to the element | 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. | to be computed rather than the position in the result array. |
Therefore, we can conveniently specify these weights by a single matrix of weights | 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"><span class="ltx_text ltx_ref_tag">2.1</span></a>.</p> | 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'><span class='ltx_text ltx_ref_tag'>2.1</span></a>.</p> |
</div> | </div> |
<div id="Ch2.S2.SS3.SSSx2.p3" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx2.p3' class='ltx_para'> |
<p class="ltx_p">In this example, only 4 direct neighbor elements and the old value itself | <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. | are taken into account for computing a new value. |
(Hence its name: <span class="ltx_text ltx_font_italic">5-point-stencil operation</span>). | (Hence its name: <span class='ltx_text ltx_font_italic'>5-point-stencil operation</span>). |
As can be seen from the weights, a new value is computed from old ones by adding | 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 | an eight-th each of the values of the upper, lower, left, and right neighbors |
to half of the old value.</p> | to half of the old value.</p> |
</div> | </div> |
<div id="Ch2.S2.SS3.SSSx2.p4" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx2.p4' class='ltx_para'> |
<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"><span class="ltx_text ltx_ref_tag">2.1</span></a> our example assumes | <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'><span class='ltx_text ltx_ref_tag'>2.1</span></a> our example assumes |
so-called <span class="ltx_text ltx_font_italic">cyclic boundary conditions</span>. | so-called <span class='ltx_text ltx_font_italic'>cyclic boundary conditions</span>. |
This means that the missing neighbor elements at the boundaries of the matrix | 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. | are taken from the opposite sides as indicated by the elliptic curves. |
</p> | </p> |
</div> | </div> |
<div id="Ch2.S2.SS3.SSSx2.p5" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx2.p5' class='ltx_para'> |
<p class="ltx_p">In the sequel, we concentrate on the specification of a single relaxation | <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. | step, i.e. on one re-computation of the entire array. |
This can be specified as a single line of <span class="ltx_text ltx_font_smallcaps">SaC</span> code:</p> | This can be specified as a single line of <span class='ltx_text ltx_font_smallcaps'>SaC</span> code:</p> |
</div> | </div> |
<figure id="LST20" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST20' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 20: </span>Relaxation with Cyclic Boundaries</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 20: </span>Relaxation with Cyclic Boundaries</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgd2VpZ2h0cyA9%0AIFtbMGQsIDFkLCAwZF0sIFsxZCwgNGQsIDFkXSwgWyAwZCwgMWQsIDBkXV0gLyA4ZDsKCiAgdmVj%0AdCA9IFsxZCwgMmQsIDNkLCA0ZF07CiAgbWF0ID0gW3ZlY3QsIHZlY3QrNGQsIHZlY3QrOGQsIHZl%0AY3QrMTJkXTsKICBwcmludChtYXQpOwoKICBtYXQgPSB7W2ksal0gLT4gc3VtKHsgaXYgLT4gd2Vp%0AZ2h0c1tpdl0gKiByb3RhdGUoaXYtMSwgbWF0KX1bWy4uLixpLGpdXSl9OwogIHByaW50KG1hdCk7%0ACgogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgd2VpZ2h0cyA9IFtbMGQsIDFkLCAwZF0sIFsxZCwgNGQsIDFkXSwgWyAwZCwgMWQsIDBkXV0gLyA4ZDsKCiAgdmVjdCA9IFsxZCwgMmQsIDNkLCA0ZF07CiAgbWF0ID0gW3ZlY3QsIHZlY3QrNGQsIHZlY3QrOGQsIHZlY3QrMTJkXTsKICBwcmludChtYXQpOwoKICBtYXQgPSB7W2ksal0gLT4gc3VtKHsgaXYgLT4gd2VpZ2h0c1tpdl0gKiByb3RhdGUoaXYtMSwgbWF0KX1bWy4uLixpLGpdXSl9OwogIHByaW50KG1hdCk7CgogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx332' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx333' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx334' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx335' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx336' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx337' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx338' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx339' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx340' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx341' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx342' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx343' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>,j]<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>,j]])}; | <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>]])}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx344' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">mat</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>mat</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx345' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx346' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx347' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch2.S2.SS3.SSSx2.p6" class="ltx_para"> | <div id='Ch2.S2.SS3.SSSx2.p6' class='ltx_para'> |
<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"><span class="ltx_text ltx_ref_tag">2.1</span></a>. | <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'><span class='ltx_text ltx_ref_tag'>2.1</span></a>. |
Our example array is initialized in lines 8–9. | Our example array is initialized in lines 8–9. |
The relaxation step is specified in line 12. | The relaxation step is specified in line 12. |
At its core, all elements are re-computed by operations on the entire array | At its core, all elements are re-computed by operations on the entire array |
rather than individual elements. | rather than individual elements. |
This is achieved by applying <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">rotate</span> for each legal index position <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">iv</span> | This is achieved by applying <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>rotate</span> for each legal index position <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span> |
into the array of weights <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">weights</span>. | into the array of weights <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>weights</span>. |
Since the expression <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">{<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> | Since the expression <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>{<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> |
computes a 3 by 3 array of matrices; the reduction operation <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sum</span> | computes a 3 by 3 array of matrices; the reduction operation <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sum</span> |
needs to be directed towards the outer two axes of that expression only. | needs to be directed towards the outer two axes of that expression only. |
This is achieved through axis control using a selection index <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[\<span class="ltx_text ltx_lst_identifier">dots</span>,<span class="ltx_text ltx_lst_identifier">i</span>,j]</span> | This is achieved through axis control using a selection index <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[\<span class='ltx_text ltx_lst_identifier'>dots</span>,<span class='ltx_text ltx_lst_identifier'>i</span>,<span class='ltx_text ltx_lst_identifier'>j</span>]</span> |
within a set notation over <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">j</span>.</p> | within a set notation over <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>j</span>.</p> |
</div> | </div> |
<div id="Thmtheorem16" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem16' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 16. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 16. </h6> |
<div id="Thmtheorem16.p1" class="ltx_para"> | <div id='Thmtheorem16.p1' class='ltx_para'> |
<p class="ltx_p">Another variant of relaxation problems requires the boundary elements to have | <p class='ltx_p'>Another variant of relaxation problems requires the boundary elements to have |
a fixed value. | a fixed value. |
Can you modify the above solution in a way that causes all boundary elements | Can you modify the above solution in a way that causes all boundary elements |
to be 0? [<span class="ltx_text ltx_font_bold">Hint:</span> You may consider the boundary elements to actually be | to be 0? [<span class='ltx_text ltx_font_bold'>Hint:</span> You may consider the boundary elements to actually be |
located <span class="ltx_text ltx_font_bold">outside</span> the matrix]</p> | located <span class='ltx_text ltx_font_bold'>outside</span> the matrix]</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
</section> | </section> |
<section id="Ch3" class="ltx_chapter"> | <section id='Ch3' class='ltx_chapter'> |
<h3 class="ltx_title ltx_title_chapter"> | <h3 class='ltx_title ltx_title_chapter'> |
<span class="ltx_tag ltx_tag_chapter">Chapter 3 </span>Basic Program Structure</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 3 </span>Basic Program Structure</h3> |
| |
<div id="Ch3.p1" class="ltx_para"> | <div id='Ch3.p1' class='ltx_para'> |
<p class="ltx_p">This trail gives a brief introduction into the main language | <p class='ltx_p'>This trail gives a brief introduction into the main language |
constructs most of which have been adopted from standard <span class="ltx_text ltx_font_smallcaps">C</span>. | constructs most of which have been adopted from standard <span class='ltx_text ltx_font_smallcaps'>C</span>. |
We assume some familiarity with standard <span class="ltx_text ltx_font_smallcaps">C</span> and, therefore, | We assume some familiarity with standard <span class='ltx_text ltx_font_smallcaps'>C</span> and, therefore, |
only give a quick overview and highlight the differences | only give a quick overview and highlight the differences |
between <span class="ltx_text ltx_font_smallcaps">SaC</span> and <span class="ltx_text ltx_font_smallcaps">C</span>.</p> | between <span class='ltx_text ltx_font_smallcaps'>SaC</span> and <span class='ltx_text ltx_font_smallcaps'>C</span>.</p> |
</div> | </div> |
<section id="Ch3.S1" class="ltx_section"> | <section id='Ch3.S1' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">3.1 </span>Lesson 3: Functions and their Types</h4> | <span class='ltx_tag ltx_tag_section'>3.1 </span>Lesson 3: Functions and their Types</h4> |
| |
<section id="Ch3.S1.SS1" class="ltx_subsection"> | <section id='Ch3.S1.SS1' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.1.1 </span>Function Definitions</h5> | <span class='ltx_tag ltx_tag_subsection'>3.1.1 </span>Function Definitions</h5> |
| |
<div id="Ch3.S1.SS1.p1" class="ltx_para"> | <div id='Ch3.S1.SS1.p1' class='ltx_para'> |
<p class="ltx_p">Like in other modern programming languages functions | <p class='ltx_p'>Like in other modern programming languages functions |
constitute the main form of structuring programs in <span class="ltx_text ltx_font_smallcaps">SaC</span>. | constitute the main form of structuring programs in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
<span class="ltx_text ltx_font_smallcaps">SaC</span> functions very much resemble their <span class="ltx_text ltx_font_smallcaps">C</span> counterparts. | <span class='ltx_text ltx_font_smallcaps'>SaC</span> functions very much resemble their <span class='ltx_text ltx_font_smallcaps'>C</span> counterparts. |
The most prominent difference is that <span class="ltx_text ltx_font_smallcaps">SaC</span> functions can have | The most prominent difference is that <span class='ltx_text ltx_font_smallcaps'>SaC</span> functions can have |
multiple return values, as illustrated in the following example.</p> | multiple return values, as illustrated in the following example.</p> |
</div> | </div> |
<figure id="LST21" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST21' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 21: </span>Function definitions</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 21: </span>Function definitions</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CgppbnQsIGludCBkaXZtb2QoaW50IHgsIGludCB5KQp7CiAg%0AcmV0dXJuICh4IC8geSwgeCAlIHkpOwp9CgppbnQgbWFpbigpCnsKICBkLCBtID0gZGl2bW9kKDgs%0AIDMpOwogIHJldHVybiBkOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CgppbnQsIGludCBkaXZtb2QoaW50IHgsIGludCB5KQp7CiAgcmV0dXJuICh4IC8geSwgeCAlIHkpOwp9CgppbnQgbWFpbigpCnsKICBkLCBtID0gZGl2bW9kKDgsIDMpOwogIHJldHVybiBkOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx348' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ScalarArith</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx349' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx350' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>,<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>3</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>,<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx351' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx352' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx353' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx354' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx355' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx356' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx357' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx358' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span><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_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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx359' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch3.S1.SS1.p2" class="ltx_para"> | <div id='Ch3.S1.SS1.p2' class='ltx_para'> |
<p class="ltx_p">A function with multiple return values, like <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">divmod</span> | <p class='ltx_p'>A function with multiple return values, like <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>divmod</span> |
in the above example, has a comma-separated list of return | in the above example, has a comma-separated list of return |
types in front of the function name and the | types in front of the function name and the |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">return</span>-statement likewise contains a comma-separated list | <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>return</span>-statement likewise contains a comma-separated list |
of expressions. | of expressions. |
Obviously both lists must coincide in length to make up a | Obviously both lists must coincide in length to make up a |
well-formed program. | well-formed program. |
Functions with multiple return values cannot appear in expression | Functions with multiple return values cannot appear in expression |
positions in <span class="ltx_text ltx_font_smallcaps">SaC</span>, but their results need to be directly assigned to | positions in <span class='ltx_text ltx_font_smallcaps'>SaC</span>, but their results need to be directly assigned to |
identifiers as illustrated above.</p> | identifiers as illustrated above.</p> |
</div> | </div> |
<div id="Thmtheorem17" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem17' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 17. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 17. </h6> |
<div id="Thmtheorem17.p1" class="ltx_para"> | <div id='Thmtheorem17.p1' class='ltx_para'> |
<p class="ltx_p">Extend the above example program to compute the greatest common | <p class='ltx_p'>Extend the above example program to compute the greatest common |
denominator of two numbers using Euclid’s algorithm. | denominator of two numbers using Euclid’s algorithm. |
In particular, use the function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">divmod</span>.</p> | In particular, use the function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>divmod</span>.</p> |
</div> | </div> |
</div> | </div> |
<div id="Thmtheorem18" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem18' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 18. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 18. </h6> |
<div id="Thmtheorem18.p1" class="ltx_para"> | <div id='Thmtheorem18.p1' class='ltx_para'> |
<p class="ltx_p">What happens, if you use the same variable name for both results | <p class='ltx_p'>What happens, if you use the same variable name for both results |
of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">divmod</span>?</p> | of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>divmod</span>?</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S1.SS2" class="ltx_subsection"> | <section id='Ch3.S1.SS2' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.1.2 </span>Built-in Types</h5> | <span class='ltx_tag ltx_tag_subsection'>3.1.2 </span>Built-in Types</h5> |
| |
<div id="Ch3.S1.SS2.p1" class="ltx_para"> | <div id='Ch3.S1.SS2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps">SaC</span> supports all basic types of standard <span class="ltx_text ltx_font_smallcaps">C</span> such as | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps'>SaC</span> supports all basic types of standard <span class='ltx_text ltx_font_smallcaps'>C</span> such as |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">int</span>, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">float</span>, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">double</span>, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">char</span> etc.</p> | <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>int</span>, <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>float</span>, <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>double</span>, <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>char</span> etc.</p> |
</div> | </div> |
<div id="Ch3.S1.SS2.p2" class="ltx_para"> | <div id='Ch3.S1.SS2.p2' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle ltx_framed_rectangle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch3.S1.SS2.p2.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_bold">A note for bit freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for bit freaks:</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">All basic types are mapped one-to-one to their <span class="ltx_text ltx_font_smallcaps">C</span> counterparts | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>All basic types are mapped one-to-one to their <span class='ltx_text ltx_font_smallcaps'>C</span> counterparts |
and, hence, the same rules apply to them in <span class="ltx_text ltx_font_smallcaps">SaC</span> as in <span class="ltx_text ltx_font_smallcaps">C</span>. | and, hence, the same rules apply to them in <span class='ltx_text ltx_font_smallcaps'>SaC</span> as in <span class='ltx_text ltx_font_smallcaps'>C</span>. |
As a consequence of this, the concrete bit widths used for representation | As a consequence of this, the concrete bit widths used for representation |
and, hence, the range of values for integer types are | and, hence, the range of values for integer types are |
platform-dependent. Although this may be considered undesirable | platform-dependent. Although this may be considered undesirable |
we find it acceptable from a compatibility-with-<span class="ltx_text ltx_font_smallcaps">C</span> perspective.</span></span> | we find it acceptable from a compatibility-with-<span class='ltx_text ltx_font_smallcaps'>C</span> perspective.</span></span> |
</span> | </span></span> |
</p> | </p> |
</div> | </div> |
<div id="Ch3.S1.SS2.p3" class="ltx_para"> | <div id='Ch3.S1.SS2.p3' class='ltx_para'> |
<p class="ltx_p">In addition to the <span class="ltx_text ltx_font_smallcaps">C</span>-inhereted types, <span class="ltx_text ltx_font_smallcaps">SaC</span> supports three more basic types: | <p class='ltx_p'>In addition to the <span class='ltx_text ltx_font_smallcaps'>C</span>-inhereted types, <span class='ltx_text ltx_font_smallcaps'>SaC</span> supports three more basic types: |
the boolean type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">bool</span> and the integer type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">byte</span>, both | the boolean type <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>bool</span> and the integer type <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>byte</span>, both |
signed and unsigned. | signed and unsigned. |
Although these are internally mapped to the same <span class="ltx_text ltx_font_smallcaps">C</span> type, on the level | Although these are internally mapped to the same <span class='ltx_text ltx_font_smallcaps'>C</span> type, on the level |
of <span class="ltx_text ltx_font_smallcaps">SaC</span>, there is a strict separation between them. | of <span class='ltx_text ltx_font_smallcaps'>SaC</span>, there is a strict separation between them. |
Neither can be used in places where the other is expected. | Neither can be used in places where the other is expected. |
This separation also applies to the standard <span class="ltx_text ltx_font_smallcaps">C</span> types which rules out | This separation also applies to the standard <span class='ltx_text ltx_font_smallcaps'>C</span> types which rules out |
tacit coercions as one would find them in <span class="ltx_text ltx_font_smallcaps">C</span> or <span class="ltx_text ltx_font_smallcaps">Java</span>.</p> | tacit coercions as one would find them in <span class='ltx_text ltx_font_smallcaps'>C</span> or <span class='ltx_text ltx_font_smallcaps'>Java</span>.</p> |
</div> | </div> |
<div id="Ch3.S1.SS2.p4" class="ltx_para"> | <div id='Ch3.S1.SS2.p4' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle ltx_framed_rectangle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch3.S1.SS2.p4.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_bold">A note for language design freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for language design freaks:</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">The reader may wonder why we enforced this strict separation. | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>The reader may wonder why we enforced this strict separation. |
The reason is two-fold: First, it prevents from accidental coercions | The reason is two-fold: First, it prevents from accidental coercions |
and second, it makes type-inference more accessible for the user | and second, it makes type-inference more accessible for the user |
in the absence of explicit type declarations. | in the absence of explicit type declarations. |
Just imagine an overloading of a function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">foo</span> for integer and | Just imagine an overloading of a function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>foo</span> for integer and |
double arguments which would yield different results depending on the type | double arguments which would yield different results depending on the type |
of argument. | of argument. |
If we had implicit coercions in place it would be completely | If we had implicit coercions in place it would be completely |
unclear how the result of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">foo</span>(0)</span> would be computed!</span></span> | unclear how the result of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>foo</span>(0)</span> would be computed!</span></span> |
</span> | </span></span> |
| |
</p> | </p> |
</div> | </div> |
<div id="Ch3.S1.SS2.p5" class="ltx_para"> | <div id='Ch3.S1.SS2.p5' class='ltx_para'> |
<p class="ltx_p">As a consequence of this strict separation, | <p class='ltx_p'>As a consequence of this strict separation, |
programmers need to apply some rigor when it comes to specifying | programmers need to apply some rigor when it comes to specifying |
constant values. | constant values. |
They have to be attributed with the appropriate suffixes to indicate | They have to be attributed with the appropriate suffixes to indicate |
the desired runtime representation. | the desired runtime representation. |
Note here, that we adopted the suffixes and default rules from <span class="ltx_text ltx_font_smallcaps">C</span>. | Note here, that we adopted the suffixes and default rules from <span class='ltx_text ltx_font_smallcaps'>C</span>. |
Here a few examples:</p> | Here a few examples:</p> |
</div> | </div> |
<figure id="LST22" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST22' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 22: </span>Element-Type segregation</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 22: </span>Element-Type segregation</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKYm9vbCBmb28oZG91YmxlIHgpCnsKICBy%0AZXR1cm4gdHJ1ZTsKfQoKYm9vbCBiYXIoZmxvYXQgeCkKewogIHJldHVybiBmYWxzZTsKfQoKaW50%0AIG1haW4oKQp7CiAgLyogVHlwZSBlcnJvcjogZm9vIGlzIG5vdCBkZWZpbmVkIG9uIGludCEgICov%0ACiAgYSA9IGZvbygwKTsKCiAgLyogQ29ycmVjdCBjYWxsczogICovCiAgYSA9IGZvbygwLjApOwog%0AIGEgPSBmb28oMGQpOwoKICAvKiBUeXBlIGVycm9yOiBiYXIgaXMgbm90IGRlZmluZWQgb24gZG91%0AYmxlISAgKi8KICBhID0gYmFyKDAuMCk7CgogIC8qIENvcnJlY3QgY2FsbHM6ICAgKi8KICBhID0g%0AYmFyKDBmKTsKICBhID0gYmFyKDAuMGYpOwoKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKYm9vbCBmb28oZG91YmxlIHgpCnsKICByZXR1cm4gdHJ1ZTsKfQoKYm9vbCBiYXIoZmxvYXQgeCkKewogIHJldHVybiBmYWxzZTsKfQoKaW50IG1haW4oKQp7CiAgLyogVHlwZSBlcnJvcjogZm9vIGlzIG5vdCBkZWZpbmVkIG9uIGludCEgICovCiAgYSA9IGZvbygwKTsKCiAgLyogQ29ycmVjdCBjYWxsczogICovCiAgYSA9IGZvbygwLjApOwogIGEgPSBmb28oMGQpOwoKICAvKiBUeXBlIGVycm9yOiBiYXIgaXMgbm90IGRlZmluZWQgb24gZG91YmxlISAgKi8KICBhID0gYmFyKDAuMCk7CgogIC8qIENvcnJlY3QgY2FsbHM6ICAgKi8KICBhID0gYmFyKDBmKTsKICBhID0gYmFyKDAuMGYpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx360' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx361' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx362' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx363' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>4</span></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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx364' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx365' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx366' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx367' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx368' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_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;'>9</span></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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx369' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx370' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">false</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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx371' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx372' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx373' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_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;'>14</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx374' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx375' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx376' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx377' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx378' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx379' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx380' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx381' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx382' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx383' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx384' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>25</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx385' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx386' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx387' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx388' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">29</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx389' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx390' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">31</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>31</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Thmtheorem19" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem19' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 19. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 19. </h6> |
<div id="Thmtheorem19.p1" class="ltx_para"> | <div id='Thmtheorem19.p1' class='ltx_para'> |
<p class="ltx_p">How can you modify the above program in a way that allows the programmer by | <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 <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">foo</span> between float | a simple define to switch the argument type of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>foo</span> between float |
and double and all the calls to <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">foo</span> accordingly?</p> | and double and all the calls to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>foo</span> accordingly?</p> |
</div> | </div> |
<div id="Thmtheorem19.p2" class="ltx_para"> | <div id='Thmtheorem19.p2' class='ltx_para'> |
<p class="ltx_p">[<span class="ltx_text ltx_font_bold">Hint:</span> Use the <span class="ltx_text ltx_font_smallcaps">C</span> preprocessor to make the necessary modifications]</p> | <p class='ltx_p'>[<span class='ltx_text ltx_font_bold'>Hint:</span> Use the <span class='ltx_text ltx_font_smallcaps'>C</span> preprocessor to make the necessary modifications]</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S1.SS3" class="ltx_subsection"> | <section id='Ch3.S1.SS3' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.1.3 </span>Subtyping</h5> | <span class='ltx_tag ltx_tag_subsection'>3.1.3 </span>Subtyping</h5> |
| |
<div id="Ch3.S1.SS3.p1" class="ltx_para"> | <div id='Ch3.S1.SS3.p1' class='ltx_para'> |
<p class="ltx_p">For each basic type there is an entire hierarchy of array types | <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 | that specify the shape of an array (remember that any expression |
in <span class="ltx_text ltx_font_smallcaps">SaC</span> denotes an array) at different levels of accurateness. | in <span class='ltx_text ltx_font_smallcaps'>SaC</span> denotes an array) at different levels of accurateness. |
Using type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">int</span> as a running example, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">int</span> | Using type <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>int</span> as a running example, <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>int</span> |
itself denotes an integer array with rank zero, the empty | itself denotes an integer array with rank zero, the empty |
vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[]</span> as shape vector and a single element, | vector <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[]</span> as shape vector and a single element, |
in other words the equivalent of a scalar value. | in other words the equivalent of a scalar value. |
Then, there are (real) array types denoting arrays of rank | Then, there are (real) array types denoting arrays of rank |
greater than zero, e.g. <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[4]</span> denotes a 4-element | greater than zero, e.g. <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[4]</span> denotes a 4-element |
vector while <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[10,20]</span> denotes a 10 by 20 element | vector while <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[10,20]</span> denotes a 10 by 20 element |
matrix.</p> | matrix.</p> |
</div> | </div> |
<div id="Ch3.S1.SS3.p2" class="ltx_para"> | <div id='Ch3.S1.SS3.p2' class='ltx_para'> |
<p class="ltx_p">Whereas all these types specify exact shapes, <span class="ltx_text ltx_font_smallcaps">SaC</span> also features | <p class='ltx_p'>Whereas all these types specify exact shapes, <span class='ltx_text ltx_font_smallcaps'>SaC</span> also features |
types that solely denote the rank of some array, but leave the | types that solely denote the rank of some array, but leave the |
concrete shape open, e.g. <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[.]</span> describes the type | concrete shape open, e.g. <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.]</span> describes the type |
of all integer vectors (of any length) and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[.,.]</span> | of all integer vectors (of any length) and <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.,.]</span> |
is the type of all integer matrices. | is the type of all integer matrices. |
In order to support rank-invariant programming, | In order to support rank-invariant programming, |
<span class="ltx_text ltx_font_smallcaps">SaC</span>, furthermore, has types that not only abstract from concrete | <span class='ltx_text ltx_font_smallcaps'>SaC</span>, furthermore, has types that not only abstract from concrete |
shapes but even from concrete ranks. | shapes but even from concrete ranks. |
These are <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[*]</span> which is the type of all integer arrays | These are <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[*]</span> which is the type of all integer arrays |
of any rank and shape, including rank-zero arrays (usually referred | of any rank and shape, including rank-zero arrays (usually referred |
to as scalars) and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[+]</span>, the type of all “true” integer | to as scalars) and <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[+]</span>, the type of all “true” integer |
arrays, i.e. arrays of rank greater than zero.</p> | arrays, i.e. arrays of rank greater than zero.</p> |
</div> | </div> |
<div id="Ch3.S1.SS3.p3" class="ltx_para"> | <div id='Ch3.S1.SS3.p3' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps">SaC</span> defines a subtype relationship between array types in the obvious | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps'>SaC</span> defines a subtype relationship between array types in the obvious |
way. | 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"><span class="ltx_text ltx_ref_tag">3.1</span></a> shows this relationship for arrays of | 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'><span class='ltx_text ltx_ref_tag'>3.1</span></a> shows this relationship for arrays of |
integer elements in a graphical form.</p> | integer elements in a graphical form.</p> |
</div> | </div> |
<figure id="Ch3.F1" class="ltx_figure"><svg id="Ch3.F1.pic1" class="ltx_picture ltx_centering" height="144.08" overflow="visible" version="1.1" viewBox="-35.4 -12.98 449.02 144.08" width="449.02"><g transform="matrix(1 0 0 -1 0 118.12)"><g stroke="#000000"><g fill="#000000"><g color="#000000" stroke-width="0.4pt"><g transform="matrix(1 0 0 1 -28.02 115)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="56.04"> | <figure id='Ch3.F1' class='ltx_figure'><svg id='Ch3.F1.pic1' class='ltx_picture ltx_centering' style='width:324.5pt;height:104.1pt;' height='144.08' overflow='visible' version='1.1' viewbox='-35.4 -12.98 449.02 144.08' width='449.02'><g color='#000000' fill='#000000' stroke='#000000' stroke-width='0.4pt' transform='matrix(1 0 0 -1 0 118.12)'><g transform='matrix(1 0 0 1 -28.02 115)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='40.5pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[*]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 31.04 75.63)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='40.5pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[+]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 31.04 36.26)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='40.5pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[.]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 159.49 36.26)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='54.0pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[.,.]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 307.63 36.26)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='67.5pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[.,.,.]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 392.97 36.26)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='6.7pt' y='-1.8pt'><math id='Ch3.F1.pic1.m1' class='ltx_Math' alttext='\cdots' display='inline'><mi mathsize='90%' mathvariant='normal'>⋯</mi></math></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 31.04 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='40.5pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[1]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 78.28 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='40.5pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[4]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 133.13 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='6.7pt' y='-1.8pt'><math id='Ch3.F1.pic1.m2' class='ltx_Math' alttext='\cdots' display='inline'><mi mathsize='90%' mathvariant='normal'>⋯</mi></math></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 159.49 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='54.0pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[7,2]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 218.55 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='54.0pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[2,9]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 286.67 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='6.7pt' y='-1.8pt'><math id='Ch3.F1.pic1.m3' class='ltx_Math' alttext='\cdots' display='inline'><mi mathsize='90%' mathvariant='normal'>⋯</mi></math></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 302.96 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='74.2pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int[9,8,11]</span></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 396.9 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='6.7pt' y='-1.8pt'><math id='Ch3.F1.pic1.m4' class='ltx_Math' alttext='\cdots' display='inline'><mi mathsize='90%' mathvariant='normal'>⋯</mi></math></foreignobject></switch></g></g><g transform='matrix(1 0 0 1 -14.01 -3.11)'><g class='ltx_svg_fog' fill='#000000' stroke='#000000' transform='matrix(1 0 0 -1 0 11.21)'><switch><foreignobject height='8.1pt' overflow='visible' width='20.2pt' y='-1.8pt'><span class='ltx_text ltx_font_typewriter' style='font-size:90%;'>int</span></foreignobject></switch></g></g><path d='M 0 107.62 L 0 10.49' style='fill:none'></path><path d='M 15.74 107.62 L 43.32 89.23' style='fill:none'></path><path d='M 59.06 68.25 L 59.06 49.86' style='fill:none'></path><path d='M 91.96 69.34 L 160.13 49.86' style='fill:none'></path><path d='M 91.96 74.35 L 302.74 46.25' style='fill:none'></path><path d='M 59.06 28.88 L 59.06 10.49' style='fill:none'></path><path d='M 71.65 28.88 L 93.71 10.49' style='fill:none'></path><path d='M 196.85 28.88 L 196.85 10.49' style='fill:none'></path><path d='M 212.59 28.88 L 240.17 10.49' style='fill:none'></path><path d='M 354.33 28.88 L 354.33 10.49' style='fill:none'></path></g></svg> |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[*]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 31.04 75.63)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="56.04"> | <figcaption class='ltx_caption ltx_centering'><span class='ltx_tag ltx_tag_figure'>Figure 3.1: </span>The hierarchy of array types of integer elements.</figcaption> |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[+]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 31.04 36.26)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="56.04"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[.]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 159.49 36.26)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="74.72"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[.,.]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 307.63 36.26)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="93.4"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[.,.,.]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 392.97 36.26)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="9.34"> | |
<p class="ltx_p"><math id="Ch3.F1.pic1.m1" class="ltx_Math" alttext="\cdots" display="inline"><mi mathsize="90%" mathvariant="normal">⋯</mi></math></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 31.04 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="56.04"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[1]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 78.28 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="56.04"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[4]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 133.13 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="9.34"> | |
<p class="ltx_p"><math id="Ch3.F1.pic1.m2" class="ltx_Math" alttext="\cdots" display="inline"><mi mathsize="90%" mathvariant="normal">⋯</mi></math></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 159.49 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="74.72"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[7,2]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 218.55 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="74.72"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[2,9]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 286.67 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="9.34"> | |
<p class="ltx_p"><math id="Ch3.F1.pic1.m3" class="ltx_Math" alttext="\cdots" display="inline"><mi mathsize="90%" mathvariant="normal">⋯</mi></math></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 302.96 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="102.74"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int[9,8,11]</span></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 396.9 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="9.34"> | |
<p class="ltx_p"><math id="Ch3.F1.pic1.m4" class="ltx_Math" alttext="\cdots" display="inline"><mi mathsize="90%" mathvariant="normal">⋯</mi></math></p></foreignObject></switch></g></g><g transform="matrix(1 0 0 1 -14.01 -3.11)"><g class="ltx_svg_fog" transform="matrix(1 0 0 -1 0 11.21)"><switch><foreignObject color="#000000" height="100%" overflow="visible" width="28.02"> | |
<p class="ltx_p"><span class="ltx_text ltx_font_typewriter" style="font-size:90%;">int</span></p></foreignObject></switch></g></g><path d="M 0 107.62 L 0 10.49" style="fill:none"></path><path d="M 15.74 107.62 L 43.32 89.23" style="fill:none"></path><path d="M 59.06 68.25 L 59.06 49.86" style="fill:none"></path><path d="M 91.96 69.34 L 160.13 49.86" style="fill:none"></path><path d="M 91.96 74.35 L 302.74 46.25" style="fill:none"></path><path d="M 59.06 28.88 L 59.06 10.49" style="fill:none"></path><path d="M 71.65 28.88 L 93.71 10.49" style="fill:none"></path><path d="M 196.85 28.88 L 196.85 10.49" style="fill:none"></path><path d="M 212.59 28.88 L 240.17 10.49" style="fill:none"></path><path d="M 354.33 28.88 L 354.33 10.49" style="fill:none"></path></g></g></g></g></svg> | |
<figcaption class="ltx_caption ltx_centering"><span class="ltx_tag ltx_tag_figure">Figure 3.1: </span>The hierarchy of array types of integer elements.</figcaption> | |
</figure> | </figure> |
<div id="Ch3.S1.SS3.p4" class="ltx_para"> | <div id='Ch3.S1.SS3.p4' class='ltx_para'> |
<p class="ltx_p">Whenever two types are in subtype relationship they are connected by a line. | <p class='ltx_p'>Whenever two types are in subtype relationship they are connected by a line. |
For example, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[+]</span> is a subtype of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[*]</span>, | For example, <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[+]</span> is a subtype of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[*]</span>, |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[.]</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[.,.]</span> are both subtypes of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[+]</span> | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.]</span> and <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.,.]</span> are both subtypes of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[+]</span> |
and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[12]</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[42]</span> are subtypes of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[.]</span>. | and <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[12]</span> and <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[42]</span> are subtypes of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.]</span>. |
As we can see, the subtyping hierarchy of <span class="ltx_text ltx_font_smallcaps">SaC</span> has exactly four levels.</p> | As we can see, the subtyping hierarchy of <span class='ltx_text ltx_font_smallcaps'>SaC</span> has exactly four levels.</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S1.SS4" class="ltx_subsection"> | <section id='Ch3.S1.SS4' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.1.4 </span>Function Overloading</h5> | <span class='ltx_tag ltx_tag_subsection'>3.1.4 </span>Function Overloading</h5> |
| |
<div id="Ch3.S1.SS4.p1" class="ltx_para"> | <div id='Ch3.S1.SS4.p1' class='ltx_para'> |
<p class="ltx_p">The real power of subtyping unfolds when it is combined with function | <p class='ltx_p'>The real power of subtyping unfolds when it is combined with function |
overloading. | overloading. |
It allows programmers to specify | It allows programmers to specify |
later add special definitions for a few special cases.</p> | later add special definitions for a few special cases.</p> |
</div> | </div> |
<div id="Ch3.S1.SS4.p2" class="ltx_para"> | <div id='Ch3.S1.SS4.p2' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'><span class='ltx_text ltx_framed_rectangle' style='border-color: black;'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch3.S1.SS4.p2.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_bold">A note for OO-freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for OO-freaks:</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">This can be seen as a more general form of inheritance. If you restrict | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>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 | overloading to one argument only, say the first one, it equates |
to inheritance in OO languages. However, the overloading of <span class="ltx_text ltx_font_smallcaps">SaC</span> is much more powerful. | to inheritance in OO languages. However, the overloading of <span class='ltx_text ltx_font_smallcaps'>SaC</span> is much more powerful. |
Not only does it support inheritance on </span><span class="ltx_text ltx_font_bold">all</span><span class="ltx_text ltx_font_italic"> arguments but it also | Not only does it support inheritance on </span><span class='ltx_text ltx_font_bold'>all</span><span class='ltx_text ltx_font_italic'> arguments but it also |
supports overloading across different types. | supports overloading across different types. |
These features render several of the well-known OO programming pattern | These features render several of the well-known OO programming pattern |
such as the visitor pattern superfluous in <span class="ltx_text ltx_font_smallcaps">SaC</span>. | such as the visitor pattern superfluous in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
Instead, the desired overloading can be specified directly. | Instead, the desired overloading can be specified directly.</span></span> |
</span></span> | </span></span> |
</span> | </span></p> |
</p> | |
</div> | </div> |
<div id="Ch3.S1.SS4.p3" class="ltx_para"> | <div id='Ch3.S1.SS4.p3' class='ltx_para'> |
<p class="ltx_p">Here, an example for element-type overloading:</p> | <p class='ltx_p'>Here, an example for element-type overloading:</p> |
</div> | </div> |
<figure id="LST23" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST23' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 23: </span>Function overloading</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 23: </span>Function overloading</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IHR3aWNlKGludCB4KQp7%0ACiAgcmV0dXJuIDIgKiB4Owp9Cgpkb3VibGUgdHdpY2UoZG91YmxlIHgpCnsKICByZXR1cm4gMi4w%0AICogeDsKfQoKaW50IG1haW4oKQp7CiAgYSA9IHR3aWNlKDUpOwogIHByaW50KGEpOwoKICBiID0g%0AdHdpY2UoNS45KTsKICBwcmludChiKTsKCiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IHR3aWNlKGludCB4KQp7CiAgcmV0dXJuIDIgKiB4Owp9Cgpkb3VibGUgdHdpY2UoZG91YmxlIHgpCnsKICByZXR1cm4gMi4wICogeDsKfQoKaW50IG1haW4oKQp7CiAgYSA9IHR3aWNlKDUpOwogIHByaW50KGEpOwoKICBiID0gdHdpY2UoNS45KTsKICBwcmludChiKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx391' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ScalarArith</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx392' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx393' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx394' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx395' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx396' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx397' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx398' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx399' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_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;'>9</span></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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx400' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx401' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx402' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx403' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx404' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_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;'>14</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx405' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx406' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx407' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx408' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx409' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx410' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">b</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>b</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx411' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx412' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx413' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>23</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch3.S1.SS4.p4" class="ltx_para"> | <div id='Ch3.S1.SS4.p4' class='ltx_para'> |
<p class="ltx_p">When utilising the overloading on our hierarchy of array types | <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 | we can even achieve a pattern matching like programming style as |
demonstrated in the next example. | demonstrated in the next example. |
Here, we have three instances of the function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">quicksort</span>, | Here, we have three instances of the function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>quicksort</span>, |
one for vectors of any length, one for vectors of length one | one for vectors of any length, one for vectors of length one |
and one for empty vectors. | and one for empty vectors. |
The latter two boil down to the identity function. | The latter two boil down to the identity function. |
As a result we can safely access the first element of the argument | As a result we can safely access the first element of the argument |
vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">v</span> in the general instance because any argument vector | vector <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>v</span> in the general instance because any argument vector |
is guaranteed to have at least two elements.</p> | is guaranteed to have at least two elements.</p> |
</div> | </div> |
<figure id="LST24" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST24' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 24: </span>Overloading as pattern matching.</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 24: </span>Overloading as pattern matching.</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,aW50Wy5dIHF1aWNrc29ydChpbnRbLl0gdikKewogICBwaXZvdCA9IHZbWzFdXTsKICAgLyogLi4u%0AICAqLwp9CgppbnRbMV0gcXVpY2tzb3J0KGludFsxXSB2KQp7CiAgcmV0dXJuIHY7Cn0KCmludFsw%0AXSBxdWlja3NvcnQoaW50WzBdIHYpCnsKICByZXR1cm4gdjsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,aW50Wy5dIHF1aWNrc29ydChpbnRbLl0gdikKewogICBwaXZvdCA9IHZbWzFdXTsKICAgLyogLi4uICAqLwp9CgppbnRbMV0gcXVpY2tzb3J0KGludFsxXSB2KQp7CiAgcmV0dXJuIHY7Cn0KCmludFswXSBxdWlja3NvcnQoaW50WzBdIHYpCnsKICByZXR1cm4gdjsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx414' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx415' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx416' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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]]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx417' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_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_comment ltx_font_italic'>/*<span class='ltx_text ltx_lst_space'> </span>…<span class='ltx_text ltx_lst_space'> </span>*/</span> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx418' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx419' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx420' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_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;'>7</span></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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx421' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx422' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">v</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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx423' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx424' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx425' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_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;'>12</span></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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx426' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx427' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx428' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Thmtheorem20" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem20' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 20. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 20. </h6> |
<div id="Thmtheorem20.p1" class="ltx_para"> | <div id='Thmtheorem20.p1' class='ltx_para'> |
<p class="ltx_p">In a <span class="ltx_text ltx_font_smallcaps">C</span> program, functions like <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">+</span> can be applied to arbitrary | <p class='ltx_p'>In a <span class='ltx_text ltx_font_smallcaps'>C</span> program, functions like <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>+</span> can be applied to arbitrary |
combinations of integer and double arguments. | combinations of integer and double arguments. |
Try to mimic that behaviour in <span class="ltx_text ltx_font_smallcaps">SaC</span> by defining a function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">cPlus</span> | Try to mimic that behaviour in <span class='ltx_text ltx_font_smallcaps'>SaC</span> by defining a function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>cPlus</span> |
and by overloading it appropriately.</p> | and by overloading it appropriately.</p> |
</div> | </div> |
</div> | </div> |
<div id="Thmtheorem21" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem21' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 21. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 21. </h6> |
<div id="Thmtheorem21.p1" class="ltx_para"> | <div id='Thmtheorem21.p1' class='ltx_para'> |
<p class="ltx_p">In OO languages inheritance cannot always be statically resolved. | <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 | This leads to what is referred to as dynamic dispatch, i.e. the disambiguation |
of function calls at runtime. | of function calls at runtime. |
Is that required in <span class="ltx_text ltx_font_smallcaps">SaC</span> too? | Is that required in <span class='ltx_text ltx_font_smallcaps'>SaC</span> too? |
If so, can you come up with an example program that demonstrates this?</p> | If so, can you come up with an example program that demonstrates this?</p> |
</div> | </div> |
</section> | </section> |
</section> | </section> |
<section id="Ch3.S2" class="ltx_section"> | <section id='Ch3.S2' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">3.2 </span>Lesson 4: Function Bodies</h4> | <span class='ltx_tag ltx_tag_section'>3.2 </span>Lesson 4: Function Bodies</h4> |
| |
<section id="Ch3.S2.SS1" class="ltx_subsection"> | <section id='Ch3.S2.SS1' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.2.1 </span>Variable Declarations</h5> | <span class='ltx_tag ltx_tag_subsection'>3.2.1 </span>Variable Declarations</h5> |
| |
<div id="Ch3.S2.SS1.p1" class="ltx_para"> | <div id='Ch3.S2.SS1.p1' class='ltx_para'> |
<p class="ltx_p">Local variables within bodies of <span class="ltx_text ltx_font_smallcaps">SaC</span> functions are typically not | <p class='ltx_p'>Local variables within bodies of <span class='ltx_text ltx_font_smallcaps'>SaC</span> functions are typically not |
declared (in contrast to <span class="ltx_text ltx_font_smallcaps">C</span>), but the <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler infers proper | declared (in contrast to <span class='ltx_text ltx_font_smallcaps'>C</span>), but the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler infers proper |
types for local variables or yields an appropriate error message. | types for local variables or yields an appropriate error message. |
Nevertheless, it is syntactically legal to add explicit variable | Nevertheless, it is syntactically legal to add explicit variable |
declarations in <span class="ltx_text ltx_font_smallcaps">SaC</span> in exactly the same way as in <span class="ltx_text ltx_font_smallcaps">C</span>.</p> | declarations in <span class='ltx_text ltx_font_smallcaps'>SaC</span> in exactly the same way as in <span class='ltx_text ltx_font_smallcaps'>C</span>.</p> |
</div> | </div> |
<div id="Ch3.S2.SS1.p2" class="ltx_para"> | <div id='Ch3.S2.SS1.p2' class='ltx_para'> |
<p class="ltx_p">There is one difference to <span class="ltx_text ltx_font_smallcaps">C</span>, however: While <span class="ltx_text ltx_font_smallcaps">C</span> allows local | <p class='ltx_p'>There is one difference to <span class='ltx_text ltx_font_smallcaps'>C</span>, however: While <span class='ltx_text ltx_font_smallcaps'>C</span> allows local |
variable declarations at the beginning of each code block and | variable declarations at the beginning of each code block and |
in the latest C99 standard instructions and declarations can | in the latest C99 standard instructions and declarations can |
even be interleaved, <span class="ltx_text ltx_font_smallcaps">SaC</span> only supports variable declarations on | even be interleaved, <span class='ltx_text ltx_font_smallcaps'>SaC</span> only supports variable declarations on |
the level of function bodies, and they must precede any instruction.</p> | the level of function bodies, and they must precede any instruction.</p> |
</div> | </div> |
<div id="Thmtheorem22" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem22' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 22. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 22. </h6> |
<div id="Thmtheorem22.p1" class="ltx_para"> | <div id='Thmtheorem22.p1' class='ltx_para'> |
<p class="ltx_p">Rewrite your solution to computing the greatest common denominator | <p class='ltx_p'>Rewrite your solution to computing the greatest common denominator |
of two numbers from the previous exercise such that each subexpression | of two numbers from the previous exercise such that each subexpression |
is assigned to an identifier, i.e. flatten any nested expression. | is assigned to an identifier, i.e. flatten any nested expression. |
</div> | </div> |
</div> | </div> |
<div id="Thmtheorem23" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem23' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 23. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 23. </h6> |
<div id="Thmtheorem23.p1" class="ltx_para"> | <div id='Thmtheorem23.p1' class='ltx_para'> |
<p class="ltx_p">The previous exercise only used scalar types, more precisely <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">int</span>. | <p class='ltx_p'>The previous exercise only used scalar types, more precisely <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>int</span>. |
What happens if you replace <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">int</span> in all variable declarations | What happens if you replace <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>int</span> in all variable declarations |
by its supertype <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[*]</span>?</p> | by its supertype <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[*]</span>?</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S2.SS2" class="ltx_subsection"> | <section id='Ch3.S2.SS2' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.2.2 </span>Assignments</h5> | <span class='ltx_tag ltx_tag_subsection'>3.2.2 </span>Assignments</h5> |
| |
<div id="Ch3.S2.SS2.p1" class="ltx_para"> | <div id='Ch3.S2.SS2.p1' class='ltx_para'> |
<p class="ltx_p">As we have already seen in the previous trails, <span class="ltx_text ltx_font_smallcaps">SaC</span> allows for | <p class='ltx_p'>As we have already seen in the previous trails, <span class='ltx_text ltx_font_smallcaps'>SaC</span> allows for |
<span class="ltx_text ltx_font_smallcaps">C</span>-style assignments to variables. | <span class='ltx_text ltx_font_smallcaps'>C</span>-style assignments to variables. |
In contrast to <span class="ltx_text ltx_font_smallcaps">C</span>, | In contrast to <span class='ltx_text ltx_font_smallcaps'>C</span>, |
assignments cannot be placed within expression positions and | assignments cannot be placed within expression positions and |
the comma-operator of <span class="ltx_text ltx_font_smallcaps">C</span> is not supported. | the comma-operator of <span class='ltx_text ltx_font_smallcaps'>C</span> is not supported. |
However, the combinations of operators and assignment are | However, the combinations of operators and assignment are |
the same in <span class="ltx_text ltx_font_smallcaps">SaC</span> as in <span class="ltx_text ltx_font_smallcaps">C</span></p> | the same in <span class='ltx_text ltx_font_smallcaps'>SaC</span> as in <span class='ltx_text ltx_font_smallcaps'>C</span></p> |
</div> | </div> |
<figure id="LST25" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST25' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 25: </span>Operator assignments in SaC</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 25: </span>Operator assignments in SaC</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIEFycmF5OiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IDQyOwog%0AIHByaW50KGEpOwogIGErKzsKICBwcmludChhKTsKICBhICs9IDU7CiAgcHJpbnQoYSk7CiAgYSAt%0APSBhOwogIHByaW50KGEpOwoKICB2ID0gWzEsMiwzLDQsNV07CiAgcHJpbnQodik7CiAgdiArPSAx%0AOwogIHByaW50KHYpOwogIHZbMF0gPSAwOwogIHByaW50KHYpOwoKICBtID0gW3Ysdix2XTsKICBw%0AcmludChtKTsKICBtKys7CiAgcHJpbnQobSk7CgogIHJldHVybiBhOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIEFycmF5OiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IDQyOwogIHByaW50KGEpOwogIGErKzsKICBwcmludChhKTsKICBhICs9IDU7CiAgcHJpbnQoYSk7CiAgYSAtPSBhOwogIHByaW50KGEpOwoKICB2ID0gWzEsMiwzLDQsNV07CiAgcHJpbnQodik7CiAgdiArPSAxOwogIHByaW50KHYpOwogIHZbMF0gPSAwOwogIHByaW50KHYpOwoKICBtID0gW3Ysdix2XTsKICBwcmludChtKTsKICBtKys7CiAgcHJpbnQobSk7CgogIHJldHVybiBhOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx429' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx430' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx431' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx432' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx433' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx434' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>42; | <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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx435' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx436' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>++; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx437' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx438' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>+=<span class="ltx_text ltx_lst_space"> </span>5; | <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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx439' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx440' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx441' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx442' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx443' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx444' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">v</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'>v</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx445' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx446' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">v</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'>v</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx447' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx448' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">v</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>v</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx449' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx450' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx451' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">m</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx452' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>++; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx453' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx454' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx455' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx456' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">28</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch3.S2.SS2.p2" class="ltx_para"> | <div id='Ch3.S2.SS2.p2' class='ltx_para'> |
<p class="ltx_p">Note that despite the term “Single Assignment” in the name of <span class="ltx_text ltx_font_smallcaps">SaC</span>, | <p class='ltx_p'>Note that despite the term “Single Assignment” in the name of <span class='ltx_text ltx_font_smallcaps'>SaC</span>, |
the language actually supports repeated assignment of values to the | the language actually supports repeated assignment of values to the |
same variable as in the above example. | same variable as in the above example. |
This seeming contradiction can be explained as follows: Each assignment | This seeming contradiction can be explained as follows: Each assignment |
opens up a new scope of an identifier bound to some value. | opens up a new scope of an identifier bound to some value. |
Accordingly, the second assignmnent to <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> in the above example | Accordingly, the second assignmnent to <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> in the above example |
opens up a new scope for a new identifier <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> that only | opens up a new scope for a new identifier <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> that only |
coincidentally carries the same name as the identifier introduced | coincidentally carries the same name as the identifier introduced |
in the code line before. | in the code line before. |
However, because these two variables do carry the same name, the | However, because these two variables do carry the same name, the |
second assignment shadows the scope of the first assignment meaning | second assignment shadows the scope of the first assignment meaning |
that no access to the first <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> is possible any more.</p> | that no access to the first <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> is possible any more.</p> |
</div> | </div> |
<div id="Ch3.S2.SS2.p3" class="ltx_para"> | <div id='Ch3.S2.SS2.p3' class='ltx_para'> |
<p class="ltx_p">Another aspect to notice here is that these operator-assignment | <p class='ltx_p'>Another aspect to notice here is that these operator-assignment |
combinations in <span class="ltx_text ltx_font_smallcaps">SaC</span> can be used on arbitrary types. | combinations in <span class='ltx_text ltx_font_smallcaps'>SaC</span> can be used on arbitrary types. |
Line 17 is an example for this flexibility. | Line 17 is an example for this flexibility. |
The variable <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">v</span> is of type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[5]</span> and thus | The variable <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>v</span> is of type <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[5]</span> and thus |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">+=</span> works on vectors. The way this works is that | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>+=</span> works on vectors. The way this works is that |
all these operator assignment cases are considered syntactic sugar | all these operator assignment cases are considered syntactic sugar |
for assignements with function applications on the righ hand side.</p> | for assignements with function applications on the righ hand side.</p> |
</div> | </div> |
<div id="Ch3.S2.SS2.p4" class="ltx_para"> | <div id='Ch3.S2.SS2.p4' class='ltx_para'> |
<p class="ltx_p">This syntactic-sugar trick also enables very <span class="ltx_text ltx_font_smallcaps">C</span>-like notations when | <p class='ltx_p'>This syntactic-sugar trick also enables very <span class='ltx_text ltx_font_smallcaps'>C</span>-like notations when |
denoting applications of the function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">modarray</span>. | denoting applications of the function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span>. |
Line 19 shows an example.</p> | Line 19 shows an example.</p> |
</div> | </div> |
<div id="Thmtheorem24" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem24' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 24. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 24. </h6> |
<div id="Thmtheorem24.p1" class="ltx_para"> | <div id='Thmtheorem24.p1' class='ltx_para'> |
<p class="ltx_p">Starting from the code in Listing <a href="#LST25" title="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"><span class="ltx_text ltx_ref_tag">25</span></a>, what happens when you | <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'><span class='ltx_text ltx_ref_tag'>25</span></a>, what happens when you |
combine the above shortcut notations? | combine the above shortcut notations? |
Try operator assignments such as <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">v</span>[0]++</span> or | Try operator assignments such as <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>v</span>[0]++</span> or |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">m</span>[0][0]<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>42;</span>.</p> | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>m</span>[0][0]<span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>42;</span>.</p> |
</div> | </div> |
<div id="Thmtheorem24.p2" class="ltx_para"> | <div id='Thmtheorem24.p2' class='ltx_para ltx_noindent'> |
<p class="ltx_p">Can you define a function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">f</span> that makes the following | <p class='ltx_p'>Can you define a function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>f</span> that makes the following |
operator assignment legal <span class="ltx_text ltx_font_smallcaps">SaC</span> code: <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">v</span>[1],<span class="ltx_text ltx_lst_space"> </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">f</span>();</span>?</p> | operator assignment legal <span class='ltx_text ltx_font_smallcaps'>SaC</span> code: <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>v</span>[1],<span class='ltx_text ltx_lst_space'> </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'>f</span>();</span>?</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S2.SS3" class="ltx_subsection"> | <section id='Ch3.S2.SS3' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.2.3 </span>Conditionals</h5> | <span class='ltx_tag ltx_tag_subsection'>3.2.3 </span>Conditionals</h5> |
| |
<div id="Ch3.S2.SS3.p1" class="ltx_para"> | <div id='Ch3.S2.SS3.p1' class='ltx_para'> |
<p class="ltx_p">In <span class="ltx_text ltx_font_smallcaps">SaC</span>, we support three forms of conditionals:</p> | <p class='ltx_p'>In <span class='ltx_text ltx_font_smallcaps'>SaC</span>, we support three forms of conditionals:</p> |
<ul id="Ch3.I1" class="ltx_itemize"> | <ul id='Ch3.S2.I1' class='ltx_itemize'> |
<li id="Ch3.I1.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch3.S2.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch3.I1.i1.p1" class="ltx_para"> | <div id='Ch3.S2.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p">branching with consequence only (if-then),</p> | <p class='ltx_p'>branching with consequence only (if-then),</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch3.I1.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch3.S2.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch3.I1.i2.p1" class="ltx_para"> | <div id='Ch3.S2.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p">branching with consequence and alternative (if-then-else) and</p> | <p class='ltx_p'>branching with consequence and alternative (if-then-else) and</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch3.I1.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch3.S2.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch3.I1.i3.p1" class="ltx_para"> | <div id='Ch3.S2.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p">conditional expressions.</p> | <p class='ltx_p'>conditional expressions.</p> |
</div> | </div> |
</li> | </li> |
</ul> | </ul> |
<p class="ltx_p">All three forms use a syntax that is identical to that of <span class="ltx_text ltx_font_smallcaps">C</span>, as the | <p class='ltx_p'>All three forms use a syntax that is identical to that of <span class='ltx_text ltx_font_smallcaps'>C</span>, as the |
following listing illustrates. | following listing illustrates. |
Similarity with <span class="ltx_text ltx_font_smallcaps">C</span> extends to the use of curly brackets to build | Similarity with <span class='ltx_text ltx_font_smallcaps'>C</span> extends to the use of curly brackets to build |
blocks of multiple statements and their potential absence if the | blocks of multiple statements and their potential absence if the |
condition covers a single statement only | condition covers a single statement only |
</p> | </p> |
</div> | </div> |
<figure id="LST26" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST26' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 26: </span>Conditionals in SaC</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 26: </span>Conditionals in SaC</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9%0AIDU7CiAgYiA9IDc7CiAgcHJpbnRmKCJhPSVkLCBiPSVkXG4iLCBhLCBiKTsKCiAgaWYgKGEgPCBi%0AKSBhID0gYjsKICBwcmludGYoImE9JWQsIGI9JWRcbiIsIGEsIGIpOwoKICBpZiAoYSA+PSBiKSB7%0ACiAgICBhID0gYjsKICB9IGVsc2UgewogICAgYiA9IGE7CiAgfQogIHByaW50ZigiYT0lZCwgYj0l%0AZFxuIiwgYSwgYik7CgogIGIgPSBhIDwgYiA/IGEgOiBiOwogIHByaW50ZigiYT0lZCwgYj0lZFxu%0AIiwgYSwgYik7CgogIHJldHVybiBiOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IDU7CiAgYiA9IDc7CiAgcHJpbnRmKCJhPSVkLCBiPSVkXG4iLCBhLCBiKTsKCiAgaWYgKGEgPCBiKSBhID0gYjsKICBwcmludGYoImE9JWQsIGI9JWRcbiIsIGEsIGIpOwoKICBpZiAoYSA+PSBiKSB7CiAgICBhID0gYjsKICB9IGVsc2UgewogICAgYiA9IGE7CiAgfQogIHByaW50ZigiYT0lZCwgYj0lZFxuIiwgYSwgYik7CgogIGIgPSBhIDwgYiA/IGEgOiBiOwogIHByaW50ZigiYT0lZCwgYj0lZFxuIiwgYSwgYik7CgogIHJldHVybiBiOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx457' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ScalarArith</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx458' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx459' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx460' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx461' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx462' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>5; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>a</span><span class='ltx_text ltx_lst_space'> </span>=<span class='ltx_text ltx_lst_space'> </span>5; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx463' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">b</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>7; | <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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx464' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx465' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx466' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx467' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx468' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx469' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx470' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx471' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span>}<span class="ltx_text ltx_lst_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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx472' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx473' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx474' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx475' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>19</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx476' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx477' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx478' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx479' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx480' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>24</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch3.S2.SS3.p2" class="ltx_para"> | <div id='Ch3.S2.SS3.p2' class='ltx_para'> |
<p class="ltx_p">As in <span class="ltx_text ltx_font_smallcaps">C</span> all forms of conditionals can be nested in any way, and the | <p class='ltx_p'>As in <span class='ltx_text ltx_font_smallcaps'>C</span> all forms of conditionals can be nested in any way, and the |
dangling else ambiguity is resolved as in <span class="ltx_text ltx_font_smallcaps">C</span> proper.</p> | dangling else ambiguity is resolved as in <span class='ltx_text ltx_font_smallcaps'>C</span> proper.</p> |
</div> | </div> |
<div id="Ch3.S2.SS3.p3" class="ltx_para"> | <div id='Ch3.S2.SS3.p3' class='ltx_para'> |
<p class="ltx_p">A small difference to standard <span class="ltx_text ltx_font_smallcaps">C</span> is that the predicate expression | <p class='ltx_p'>A small difference to standard <span class='ltx_text ltx_font_smallcaps'>C</span> is that the predicate expression |
of any conditional must be of type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">bool</span>. | of any conditional must be of type <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>bool</span>. |
There is no implicit treatment of integer values as predicates. | There is no implicit treatment of integer values as predicates. |
Another subtle difference to <span class="ltx_text ltx_font_smallcaps">C</span> stems from the functional nature of | Another subtle difference to <span class='ltx_text ltx_font_smallcaps'>C</span> stems from the functional nature of |
<span class="ltx_text ltx_font_smallcaps">SaC</span>: a variable defined only in one branch of a conditional, will | <span class='ltx_text ltx_font_smallcaps'>SaC</span>: a variable defined only in one branch of a conditional, will |
cause the <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler to raise an error because the value may be | cause the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler to raise an error because the value may be |
undefined.</p> | undefined.</p> |
</div> | </div> |
<div id="Ch3.S2.SS3.p4" class="ltx_para"> | <div id='Ch3.S2.SS3.p4' class='ltx_para'> |
<p class="ltx_p">The <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">switch</span>-statement of <span class="ltx_text ltx_font_smallcaps">C</span> is currently not supported by <span class="ltx_text ltx_font_smallcaps">SaC</span>. | <p class='ltx_p'>The <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>switch</span>-statement of <span class='ltx_text ltx_font_smallcaps'>C</span> is currently not supported by <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
This is not so much motivated by conceptual concerns, but rather by | This is not so much motivated by conceptual concerns, but rather by |
pragmatic considerations like the ratio between expressiveness gained | pragmatic considerations like the ratio between expressiveness gained |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S2.SS4" class="ltx_subsection"> | <section id='Ch3.S2.SS4' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.2.4 </span>Loops</h5> | <span class='ltx_tag ltx_tag_subsection'>3.2.4 </span>Loops</h5> |
| |
<div id="Ch3.S2.SS4.p1" class="ltx_para"> | <div id='Ch3.S2.SS4.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps">SaC</span> supports all three loop constructs of standard <span class="ltx_text ltx_font_smallcaps">C</span>: <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">while</span>, | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps'>SaC</span> supports all three loop constructs of standard <span class='ltx_text ltx_font_smallcaps'>C</span>: <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>while</span>, |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">do</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">for</span> with the familiar syntax, as illustrated | <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>do</span> and <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>for</span> with the familiar syntax, as illustrated |
by the following code fragment. | by the following code fragment. |
</p> | </p> |
</div> | </div> |
<figure id="LST27" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST27' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 27: </span>Loops in SaC</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 27: </span>Loops in SaC</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9%0AIDEwOwoKICB3aGlsZSAoYSA+IDApIHsKICAgIGEgPSBhIC0gMjsKICAgIHByaW50KGEpOwogIH0K%0ACiAgZG8gewogICAgcHJpbnQoYSk7CiAgICBhID0gYSArIDE7CiAgfSB3aGlsZSAoYSA8IDcpOwoK%0AICBmb3IgKGkgPSAxLCBqID0gMjsgaSArIGogPCA0MiA7IGkrKywgaisrKSB7CiAgICBhICo9IDI7%0ACiAgICBwcmludChhKTsKICB9CgogIHJldHVybiBhOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IDEwOwoKICB3aGlsZSAoYSA+IDApIHsKICAgIGEgPSBhIC0gMjsKICAgIHByaW50KGEpOwogIH0KCiAgZG8gewogICAgcHJpbnQoYSk7CiAgICBhID0gYSArIDE7CiAgfSB3aGlsZSAoYSA8IDcpOwoKICBmb3IgKGkgPSAxLCBqID0gMjsgaSArIGogPCA0MiA7IGkrKywgaisrKSB7CiAgICBhICo9IDI7CiAgICBwcmludChhKTsKICB9CgogIHJldHVybiBhOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx481' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ScalarArith</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx482' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx483' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx484' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx485' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx486' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>10; | <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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx487' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx488' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx489' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx490' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx491' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx492' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx493' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">do</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'>do</span><span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx494' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx495' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx496' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span>}<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx497' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx498' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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>j<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>j<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>j++)<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_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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx499' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx500' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx501' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>21</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx502' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>22</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx503' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx504' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>24</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch3.S2.SS4.p2" class="ltx_para"> | <div id='Ch3.S2.SS4.p2' class='ltx_para'> |
<p class="ltx_p">In analogy to conditionals, the loop predicate expression must be | <p class='ltx_p'>In analogy to conditionals, the loop predicate expression must be |
of type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">bool</span>. | of type <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>bool</span>. |
Note that <span class="ltx_text ltx_font_smallcaps">SaC</span> does even support the comma operator in <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">for</span>-loops | Note that <span class='ltx_text ltx_font_smallcaps'>SaC</span> does even support the comma operator in <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>for</span>-loops |
(though not in general terms as pointed out before).</p> | (though not in general terms as pointed out before).</p> |
</div> | </div> |
<div id="Ch3.S2.SS4.p3" class="ltx_para"> | <div id='Ch3.S2.SS4.p3' class='ltx_para'> |
<p class="ltx_p">These <span class="ltx_text ltx_font_smallcaps">C</span>-style loop constructs can make code look very imperative. | <p class='ltx_p'>These <span class='ltx_text ltx_font_smallcaps'>C</span>-style loop constructs can make code look very imperative. |
Despite these syntactic similarities, always bear in mind that <span class="ltx_text ltx_font_smallcaps">SaC</span> loops | Despite these syntactic similarities, always bear in mind that <span class='ltx_text ltx_font_smallcaps'>SaC</span> loops |
are (only) syntactic sugar for equivalent tail-end recursive functions. | are (only) syntactic sugar for equivalent tail-end recursive functions. |
While the functional semantics almost completely coincides with the | While the functional semantics almost completely coincides with the |
pragmatic expectations of a <span class="ltx_text ltx_font_smallcaps">C</span> programmer, some subtle issues may | pragmatic expectations of a <span class='ltx_text ltx_font_smallcaps'>C</span> programmer, some subtle issues may |
arise concerning the definedness of variables. | arise concerning the definedness of variables. |
For example, the <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler would complain about the above example | For example, the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler would complain about the above example |
saying that the variable <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">b</span> in the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">while</span>-loop may be | saying that the variable <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>b</span> in the <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>while</span>-loop may be |
used uninitialised if it is not defined before. | used uninitialised if it is not defined before. |
This is because the compiler assumes that the body of a <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">while</span>-loop | This is because the compiler assumes that the body of a <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>while</span>-loop |
may not be executed at all. | may not be executed at all. |
Of course, you may know better, but the <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler at the moment makes | Of course, you may know better, but the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler at the moment makes |
no particular effort to prove this fact when it analyses the definedness | no particular effort to prove this fact when it analyses the definedness |
of variables.</p> | of variables.</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S2.SS5" class="ltx_subsection"> | <section id='Ch3.S2.SS5' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.2.5 </span>Explicit Control Flow Manipulation</h5> | <span class='ltx_tag ltx_tag_subsection'>3.2.5 </span>Explicit Control Flow Manipulation</h5> |
| |
<div id="Ch3.S2.SS5.p1" class="ltx_para"> | <div id='Ch3.S2.SS5.p1' class='ltx_para'> |
<p class="ltx_p">The control flow manipulation statements of <span class="ltx_text ltx_font_smallcaps">C</span>, i.e. <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">goto</span>, | <p class='ltx_p'>The control flow manipulation statements of <span class='ltx_text ltx_font_smallcaps'>C</span>, i.e. <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>goto</span>, |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">break</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">continue</span>, as well as labels are not | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>break</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>continue</span>, as well as labels are not |
supported by <span class="ltx_text ltx_font_smallcaps">SaC</span>. | supported by <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
This is due to the fact that <span class="ltx_text ltx_font_smallcaps">SaC</span> is indeed a functional language | This is due to the fact that <span class='ltx_text ltx_font_smallcaps'>SaC</span> is indeed a functional language |
and as such there is actually no control flow, even though the | and as such there is actually no control flow, even though the |
<span class="ltx_text ltx_font_smallcaps">C</span>-like syntax suggests one.</p> | <span class='ltx_text ltx_font_smallcaps'>C</span>-like syntax suggests one.</p> |
</div> | </div> |
</section> | </section> |
</section> | </section> |
<section id="Ch3.S3" class="ltx_section"> | <section id='Ch3.S3' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">3.3 </span>Lesson 5: Advanced Topics</h4> | <span class='ltx_tag ltx_tag_section'>3.3 </span>Lesson 5: Advanced Topics</h4> |
| |
<section id="Ch3.S3.SS1" class="ltx_subsection"> | <section id='Ch3.S3.SS1' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.3.1 </span>User-defined Types</h5> | <span class='ltx_tag ltx_tag_subsection'>3.3.1 </span>User-defined Types</h5> |
| |
<div id="Ch3.S3.SS1.p1" class="ltx_para"> | <div id='Ch3.S3.SS1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps">SaC</span> allows programmers to define their own types using a syntax | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps'>SaC</span> allows programmers to define their own types using a syntax |
that is identical to <span class="ltx_text ltx_font_smallcaps">C</span>.</p> | that is identical to <span class='ltx_text ltx_font_smallcaps'>C</span>.</p> |
</div> | </div> |
<figure id="LST28" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST28' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 28: </span>User-defined types</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 28: </span>User-defined types</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7Cgp0eXBlZGVmIGludCBteWludDsKdHlwZWRlZiBmbG9hdFsxMDAsMTAw%0AXSByZWFsX21hdHJpeDsKdHlwZWRlZiBkb3VibGVbMl0gY29tcGxleDsKCmludCBtYWluKCkKewog%0AIGNvbXBsZXggICBjOwogIGRvdWJsZVsyXSBkOwoKICBjID0gKGNvbXBsZXgpIFsxLjIsMi4zXTsK%0AICBkID0gKGRvdWJsZVsyXSkgYzsKICBwcmludChkKTsKCiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7Cgp0eXBlZGVmIGludCBteWludDsKdHlwZWRlZiBmbG9hdFsxMDAsMTAwXSByZWFsX21hdHJpeDsKdHlwZWRlZiBkb3VibGVbMl0gY29tcGxleDsKCmludCBtYWluKCkKewogIGNvbXBsZXggICBjOwogIGRvdWJsZVsyXSBkOwoKICBjID0gKGNvbXBsZXgpIFsxLjIsMi4zXTsKICBkID0gKGRvdWJsZVsyXSkgYzsKICBwcmludChkKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx505' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx506' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx507' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></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;'>3</span></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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx508' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_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;'>4</span></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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx509' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></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;'>5</span></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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx510' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx511' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx512' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx513' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx514' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx515' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx516' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx517' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx518' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">d</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx519' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx520' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx521' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch3.S3.SS1.p2" class="ltx_para"> | <div id='Ch3.S3.SS1.p2' class='ltx_para'> |
<p class="ltx_p">Following the keyword <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">typedef</span> we have the defining type | <p class='ltx_p'>Following the keyword <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>typedef</span> we have the defining type |
followed by the defined type name. | followed by the defined type name. |
Note that in contrast to <span class="ltx_text ltx_font_smallcaps">C</span>, defining type and defined type are | Note that in contrast to <span class='ltx_text ltx_font_smallcaps'>C</span>, defining type and defined type are |
not considered synonyms. | not considered synonyms. |
Types like <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">double</span>[2]</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">complex</span> are distinguished | Types like <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span>[2]</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>complex</span> are distinguished |
properly and a function that expects a value of type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">double</span>[2]</span> | properly and a function that expects a value of type <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>double</span>[2]</span> |
as an argument will not accept a value of type <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">complex</span> instead.</p> | as an argument will not accept a value of type <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>complex</span> instead.</p> |
</div> | </div> |
<div id="Ch3.S3.SS1.p3" class="ltx_para"> | <div id='Ch3.S3.SS1.p3' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps">SaC</span> requires explicit type casts to change the type of a value from the | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps'>SaC</span> 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 | defining type to the defined type or vice versa as in the following |
example.</p> | example.</p> |
</div> | </div> |
<div id="Ch3.S3.SS1.p4" class="ltx_para"> | <div id='Ch3.S3.SS1.p4' class='ltx_para'> |
<p class="ltx_p">Note that for the time being any defining type in a type definition | <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 | must exactly specify some shape; the various less specific types are |
not supported. | not supported. |
shape, e.g. a matrix whose rows have different length. | shape, e.g. a matrix whose rows have different length. |
There is no doubt that this would be an extremely powerful extension | There is no doubt that this would be an extremely powerful extension |
to the homogeneously shaped arrays that <span class="ltx_text ltx_font_smallcaps">SaC</span> supports today, but it | to the homogeneously shaped arrays that <span class='ltx_text ltx_font_smallcaps'>SaC</span> supports today, but it |
would likewise require a non-trivial extension of the code generator | would likewise require a non-trivial extension of the code generator |
and runtime system that we leave for future research.</p> | and runtime system that we leave for future research.</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch3.S3.SS2" class="ltx_subsection"> | <section id='Ch3.S3.SS2' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">3.3.2 </span>Type Conversions</h5> | <span class='ltx_tag ltx_tag_subsection'>3.3.2 </span>Type Conversions</h5> |
| |
<div id="Ch3.S3.SS2.p1" class="ltx_para"> | <div id='Ch3.S3.SS2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps">SaC</span> uses <span class="ltx_text ltx_font_smallcaps">C</span>-like cast expressions to change the type of an | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps'>SaC</span> uses <span class='ltx_text ltx_font_smallcaps'>C</span>-like cast expressions to change the type of an |
expression whenever the data representation remains unaffected, | expression whenever the data representation remains unaffected, |
i.e. between user-defined types and their defining types or | i.e. between user-defined types and their defining types or |
vice versa. | vice versa. |
In contrast to <span class="ltx_text ltx_font_smallcaps">C</span>, <span class="ltx_text ltx_font_smallcaps">SaC</span> does not use cast expressions to actually | In contrast to <span class='ltx_text ltx_font_smallcaps'>C</span>, <span class='ltx_text ltx_font_smallcaps'>SaC</span> does not use cast expressions to actually |
change data representations, e.g. when converting from an integer | change data representations, e.g. when converting from an integer |
type to a floating point type, between floating point types of | type to a floating point type, between floating point types of |
different precision or between integer types of different bit | different precision or between integer types of different bit |
width. | width. |
For all these purposes <span class="ltx_text ltx_font_smallcaps">SaC</span> uses dedicated conversion functions | For all these purposes <span class='ltx_text ltx_font_smallcaps'>SaC</span> uses dedicated conversion functions |
to express the fact that such conversions actually require an | to express the fact that such conversions actually require an |
operation performed at runtime rather than just changing the | operation performed at runtime rather than just changing the |
type interpretation of a value.</p> | type interpretation of a value.</p> |
</div> | </div> |
<div id="Ch3.S3.SS2.p2" class="ltx_para"> | <div id='Ch3.S3.SS2.p2' class='ltx_para'> |
<p class="ltx_p">These conversion functions are named <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">tobool</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">tochar</span> | <p class='ltx_p'>These conversion functions are named <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>tobool</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>tochar</span> |
for converting into non-numerical values. | for converting into non-numerical values. |
For all numerical types these functions are named “to” plus an | For all numerical types these functions are named “to” plus an |
optional “u” for unsigned integer types followed by the | optional “u” for unsigned integer types followed by the |
first letter of the type name (“ll” in the case of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">long</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">long</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span></span>). | first letter of the type name (“ll” in the case of <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>long</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>long</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span></span>). |
The following example illustrates type conversions in <span class="ltx_text ltx_font_smallcaps">SaC</span>.</p> | The following example illustrates type conversions in <span class='ltx_text ltx_font_smallcaps'>SaC</span>.</p> |
</div> | </div> |
<figure id="LST29" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST29' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 29: </span>Type conversions</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 29: </span>Type conversions</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgZG91%0AYmxlIHg7CiAgZmxvYXQgeTsKICBpbnQgejsKCiAgeCA9IDIuMzsKICBwcmludCh4KTsKCiAgeSA9%0AIHRvZih4KTsKICBwcmludCh5KTsKCiAgeiA9IHRvaSh5KTsKICBwcmludCh6KTsKCiAgcmV0dXJu%0AIHo7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFNjYWxhckFyaXRoOiBhbGw7CnVzZSBTdGRJTzogYWxsOwoKaW50IG1haW4oKQp7CiAgZG91YmxlIHg7CiAgZmxvYXQgeTsKICBpbnQgejsKCiAgeCA9IDIuMzsKICBwcmludCh4KTsKCiAgeSA9IHRvZih4KTsKICBwcmludCh5KTsKCiAgeiA9IHRvaSh5KTsKICBwcmludCh6KTsKCiAgcmV0dXJuIHo7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx522' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>ScalarArith</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx523' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx524' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx525' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx526' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx527' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx528' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx529' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx530' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx531' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx532' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">x</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'>x</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx533' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx534' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx535' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>y</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx536' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx537' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx538' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx539' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx540' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx541' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</section> | </section> |
</section> | </section> |
<section id="Ch4" class="ltx_chapter"> | <section id='Ch4' class='ltx_chapter'> |
<h3 class="ltx_title ltx_title_chapter"> | <h3 class='ltx_title ltx_title_chapter'> |
<span class="ltx_tag ltx_tag_chapter">Chapter 4 </span>With-Loops</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 4 </span>With-Loops</h3> |
| |
<div id="Ch4.p1" class="ltx_para"> | <div id='Ch4.p1' class='ltx_para'> |
<p class="ltx_p">This trail aims at providing a hands-on introduction to the | <p class='ltx_p'>This trail aims at providing a hands-on introduction to the |
key language construct of <span class="ltx_text ltx_font_smallcaps">SaC</span>: the with-loop. | key language construct of <span class='ltx_text ltx_font_smallcaps'>SaC</span>: the with-loop. |
It constitutes the generalisation of the | 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"><span class="ltx_text ltx_ref_tag">2.2</span></a> on | 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'><span class='ltx_text ltx_ref_tag'>2.2</span></a> on |
<span class="ltx_text ltx_font_bold">Shape-Invariant Programming</span> | <span class='ltx_text ltx_font_bold'>Shape-Invariant Programming</span> |
and can be seen as a shape-invariant form of the map-reduce template or | and can be seen as a shape-invariant form of the map-reduce template or |
the array comprehensions found in other functional languages. | the array comprehensions found in other functional languages. |
into high-performance, concurrently executable code.</p> | into high-performance, concurrently executable code.</p> |
</div> | </div> |
<div id="Ch4.p2" class="ltx_para"> | <div id='Ch4.p2' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'><span class='ltx_text ltx_framed_rectangle' style='border-color: black;'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch4.p2.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_bold">A note for language design freaks:</span></span> | <span class='ltx_p'><span class='ltx_text ltx_font_bold'>A note for language design freaks:</span></span> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">In fact, almost all array operations introduced in earlier | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>In fact, almost all array operations introduced in earlier |
trails are defined by with-loops within the standard library. | trails are defined by with-loops within the standard library. |
This design combines two major advantages:</span></span> | This design combines two major advantages:</span></span> |
<span id="Ch4.I1" class="ltx_itemize"> | <span id='Ch4.S0.I1' class='ltx_itemize'> |
<span id="Ch4.I1.i1" class="ltx_item" style="list-style-type:none;"><span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_italic">•</span></span> | <span id='Ch4.S0.I1.i1' class='ltx_item' style='list-style-type:none;'><span class='ltx_tag ltx_tag_item'>•</span> |
<span id="Ch4.I1.i1.p1" class="ltx_para"> | <span id='Ch4.S0.I1.i1.p1' class='ltx_para'> |
<span class="ltx_p"><em class="ltx_emph ltx_font_italic">better performance</em><span class="ltx_text ltx_font_italic">, as the conformity enables optimisations to be more generally applicable, and</span></span> | <span class='ltx_p'><em class='ltx_emph'>better performance</em><span class='ltx_text ltx_font_italic'>, as the conformity enables optimisations to be more generally applicable, and</span></span> |
</span></span> | </span></span> |
<span id="Ch4.I1.i2" class="ltx_item" style="list-style-type:none;"><span class="ltx_tag ltx_tag_itemize"><span class="ltx_text ltx_font_italic">•</span></span> | <span id='Ch4.S0.I1.i2' class='ltx_item' style='list-style-type:none;'><span class='ltx_tag ltx_tag_item'>•</span> |
<span id="Ch4.I1.i2.p1" class="ltx_para"> | <span id='Ch4.S0.I1.i2.p1' class='ltx_para'> |
<span class="ltx_p"><em class="ltx_emph ltx_font_italic">increased flexibility</em><span class="ltx_text ltx_font_italic">, as the user can modify the definition | <span class='ltx_p'><em class='ltx_emph'>increased flexibility</em><span class='ltx_text ltx_font_italic'>, as the user can modify the definition |
of all standard operations.</span></span> | of all standard operations.</span></span> |
</span></span> | </span></span> |
</span> | </span> |
</span> | <br class='ltx_break'> |
</p> | </span></span> |
| </span></p> |
</div> | </div> |
<div id="Ch4.p3" class="ltx_para"> | <div id='Ch4.p3' class='ltx_para'> |
<p class="ltx_p">The introduction of with-loops comes in a single lesson which step-wise | <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 <span class="ltx_text ltx_font_smallcaps">SaC</span>.</p> | introduces all features and variants of with-loops in <span class='ltx_text ltx_font_smallcaps'>SaC</span>.</p> |
</div> | </div> |
<section id="Ch4.S1" class="ltx_section"> | <section id='Ch4.S1' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">4.1 </span>Lesson 6: with-loop Basics</h4> | <span class='ltx_tag ltx_tag_section'>4.1 </span>Lesson 6: with-loop Basics</h4> |
| |
<section id="Ch4.S1.SS1" class="ltx_subsection"> | <section id='Ch4.S1.SS1' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">4.1.1 </span>Basic Components</h5> | <span class='ltx_tag ltx_tag_subsection'>4.1.1 </span>Basic Components</h5> |
| |
<div id="Ch4.S1.SS1.p1" class="ltx_para"> | <div id='Ch4.S1.SS1.p1' class='ltx_para'> |
<p class="ltx_p">Generally, with-loops are composed of three different components:</p> | <p class='ltx_p'>Generally, with-loops are composed of three different components:</p> |
</div> | </div> |
<div id="Ch4.S1.SS1.p2" class="ltx_para"> | <div id='Ch4.S1.SS1.p2' class='ltx_para'> |
<ul id="Ch4.I2" class="ltx_itemize"> | <ul id='Ch4.S1.I1' class='ltx_itemize'> |
<li id="Ch4.I2.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I2.i1.p1" class="ltx_para"> | <div id='Ch4.S1.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p">sets of index vectors (referred to as <em class="ltx_emph">generator-ranges</em>),</p> | <p class='ltx_p'>sets of index vectors (referred to as <em class='ltx_emph ltx_font_italic'>generator-ranges</em>),</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch4.I2.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I2.i2.p1" class="ltx_para"> | <div id='Ch4.S1.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p">functions that map index vectors to arbitrary values | <p class='ltx_p'>functions that map index vectors to arbitrary values |
(<em class="ltx_emph">generator-expressions</em>), and</p> | (<em class='ltx_emph ltx_font_italic'>generator-expressions</em>), and</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch4.I2.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I2.i3.p1" class="ltx_para"> | <div id='Ch4.S1.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p">combining operations (<em class="ltx_emph">with-loop operators</em>) that take such | <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> | values and construct arrays from them.</p> |
</div> | </div> |
</ul> | </ul> |
</div> | </div> |
<div id="Ch4.S1.SS1.p3" class="ltx_para"> | <div id='Ch4.S1.SS1.p3' class='ltx_para'> |
<p class="ltx_p">In its simplest form, a with-loop contains one component of each kind. | <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 | It then maps the function defined by the generator-expression to all |
index vectors from the generator-range in a data-parallel | index vectors from the generator-range in a data-parallel |
Let’s have a look at a simple example:</p> | Let’s have a look at a simple example:</p> |
</div> | </div> |
<figure id="LST30" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST30' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 30: </span>Simple with-loop</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 30: </span>Simple with-loop</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGgg%0AewogICAgICAgIChbMF0gPD0gaXYgPCBbNV0pOiA0MjsKICAgICAgfTogZ2VuYXJyYXkoWzddLCAw%0AKTsKCiAgcHJpbnQoYSk7CiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGggewogICAgICAgIChbMF0gPD0gaXYgPCBbNV0pOiA0MjsKICAgICAgfTogZ2VuYXJyYXkoWzddLCAwKTsKCiAgcHJpbnQoYSk7CiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx542' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx543' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx544' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx545' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx546' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx547' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx548' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span>([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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx549' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx550' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx551' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx552' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx553' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch4.S1.SS1.p4" class="ltx_para"> | <div id='Ch4.S1.SS1.p4' class='ltx_para'> |
<p class="ltx_p">Here, the with-loop in lines 6–8 computes | <p class='ltx_p'>Here, the with-loop in lines 6–8 computes |
the vector <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[42,<span class="ltx_text ltx_lst_space"> </span>42,<span class="ltx_text ltx_lst_space"> </span>42,<span class="ltx_text ltx_lst_space"> </span>42,<span class="ltx_text ltx_lst_space"> </span>42,<span class="ltx_text ltx_lst_space"> </span>0,<span class="ltx_text ltx_lst_space"> </span>0]</span>. | the vector <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[42,<span class='ltx_text ltx_lst_space'> </span>42,<span class='ltx_text ltx_lst_space'> </span>42,<span class='ltx_text ltx_lst_space'> </span>42,<span class='ltx_text ltx_lst_space'> </span>42,<span class='ltx_text ltx_lst_space'> </span>0,<span class='ltx_text ltx_lst_space'> </span>0]</span>. |
The generator-range is specified by the code snippet in round | The generator-range is specified by the code snippet in round |
brackets in line 7: <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([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>. | brackets in line 7: <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([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>. |
It denotes the set of vectors | It denotes the set of vectors |
<math id="Ch4.S1.SS1.p4.m1" class="ltx_Math" alttext="{{\{\textrm{\lstinline 1}}}\}" 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>. | <math id='Ch4.S1.SS1.p4.m1' class='ltx_Math' alttext='{\{\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers\lst@@@set@frame% |
The generator-expression here is the constant <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">42</span>. | \lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers[0],{\@listingGroup{% |
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 <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">iv</span> | ltx_lst_space}{~{}}}[1],{\@listingGroup{ltx_lst_space}{~{}}}...,{% |
into <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">42</span>, i.e. we have <math id="Ch4.S1.SS1.p4.m3" class="ltx_Math" alttext="{{f_{\text{map}}\textrm{\lstinline 1}}}" 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>. | \@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 <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>42</span>. |
| 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 <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span> |
| into <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>42</span>, i.e. we have <math id='Ch4.S1.SS1.p4.m3' class='ltx_Math' alttext='{f_{\text{map}}\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
| \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers({% |
| \@listingGroup{ltx_lst_identifier}{iv}}){\@listingGroup{ltx_lst_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 | Finally, the with-loop operation is specified as |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">genarray</span>([7],<span class="ltx_text ltx_lst_space"> </span>0)</span>. | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>genarray</span>([7],<span class='ltx_text ltx_lst_space'> </span>0)</span>. |
This operation computes an array of shape <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">[7]</span> where: | This operation computes an array of shape <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>[7]</span> where: |
</p> | </p> |
</div> | </div> |
<div id="Ch4.S1.SS1.p5" class="ltx_para"> | <div id='Ch4.S1.SS1.p5' class='ltx_para'> |
<table id="Ch4.Ex1" class="ltx_equation ltx_eqn_table"> | <table id='Ch4.Ex1' class='ltx_equation ltx_eqn_table'> |
| |
<tr class="ltx_equation ltx_eqn_row ltx_align_baseline"> | <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_eqn_center_padleft'></td> |
<td class="ltx_eqn_cell ltx_align_center"><math id="Ch4.Ex1.m1" class="ltx_Math" alttext="{{{{{{{{\textrm{\lstinline 1}}}=\begin{cases}f_{\text{map}}\textrm{\lstinline 1}}}&% | <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% |
\textrm{\lstinline 1}}}\in\{\textrm{\lstinline 1}}}\}\\ | \lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers{\@listingGroup{% |
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_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">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> | ltx_lst_identifier}{a}}[{\@listingGroup{ltx_lst_identifier}{iv}}]}}}}=\begin{% |
<td class="ltx_eqn_cell ltx_eqn_center_padright"></td> | cases}f_{\text{map}}\textrm{\lstinline{{\lst@@@set@language\lst@@@set@numbers% |
| \lst@@@set@frame\lst@@@set@rulecolor\lst@@@set@language\lst@@@set@numbers({% |
| \@listingGroup{ltx_lst_identifier}{iv}})}}}}&\textrm{\lstinline{{% |
| \lst@@@set@language\lst@@@set@numbers\lst@@@set@frame\lst@@@set@rulecolor% |
| \lst@@@set@language\lst@@@set@numbers{\@listingGroup{ltx_lst_identifier}{iv}}}% |
| }}}\in\{\textrm{\lstinline{{\lst@@@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> | </tr> |
</table> | </table> |
</div> | </div> |
<div id="Ch4.S1.SS1.p6" class="ltx_para"> | <div id='Ch4.S1.SS1.p6' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_bold">Generator-ranges</span> and <span class="ltx_text ltx_font_bold">generator-expressions</span> always occur | <p class='ltx_p'><span class='ltx_text ltx_font_bold'>Generator-ranges</span> and <span class='ltx_text ltx_font_bold'>generator-expressions</span> always occur |
in pairs. Jointly they | in pairs. Jointly they |
form a syntactical unit, which we refer-to as <span class="ltx_text ltx_font_bold">generator</span>. | form a syntactical unit, which we refer-to as <span class='ltx_text ltx_font_bold'>generator</span>. |
As we will see later, with-loops can contain arbitrary numbers of | As we will see later, with-loops can contain arbitrary numbers of |
generators. They are enclosed in curly brackets.</p> | generators. They are enclosed in curly brackets.</p> |
</div> | </div> |
<div id="Thmtheorem25" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem25' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 25. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 25. </h6> |
<div id="Thmtheorem25.p1" class="ltx_para"> | <div id='Thmtheorem25.p1' class='ltx_para'> |
<p class="ltx_p">What result do you expect if we eliminate the generator from the above example?</p> | <p class='ltx_p'>What result do you expect if we eliminate the generator from the above example?</p> |
</div> | </div> |
<div id="Thmtheorem25.p2" class="ltx_para"> | <div id='Thmtheorem25.p2' class='ltx_para'> |
<p class="ltx_p">What results do you expect if we modify the generator-range | <p class='ltx_p'>What results do you expect if we modify the generator-range |
in the above example into:</p> | in the above example into:</p> |
<ul id="Ch4.I3" class="ltx_itemize"> | <ul id='Ch4.S1.I2' class='ltx_itemize'> |
<li id="Ch4.I3.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I2.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I3.i1.p1" class="ltx_para"> | <div id='Ch4.S1.I2.i1.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([-2]<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>[3])</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([-2]<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>[3])</span>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch4.I3.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I2.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I3.i2.p1" class="ltx_para"> | <div id='Ch4.S1.I2.i2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([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>[8])</span>? | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([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>[8])</span>? |
</p> | </p> |
</div> | </div> |
</li> | </li> |
<li id="Ch4.I3.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I2.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I3.i3.p1" class="ltx_para"> | <div id='Ch4.S1.I2.i3.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([6]<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>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([6]<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>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch4.I3.i4" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I2.i4' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I3.i4.p1" class="ltx_para"> | <div id='Ch4.S1.I2.i4.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([8]<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>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([8]<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>?</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch4.I3.i5" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I2.i5' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I3.i5.p1" class="ltx_para"> | <div id='Ch4.S1.I2.i5.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">([6]<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>[0])</span>?</p> | <p class='ltx_p'><span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>([6]<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>[0])</span>?</p> |
</div> | </div> |
</li> | </li> |
</ul> | </ul> |
<p class="ltx_p">[<span class="ltx_text ltx_font_bold">Hint:</span> You should compile these examples with the option <span class="ltx_text ltx_font_typewriter">-check c</span> | <p class='ltx_p'>[<span class='ltx_text ltx_font_bold'>Hint:</span> You should compile these examples with the option <span class='ltx_text ltx_font_typewriter'>-check c</span> |
being enabled]</p> | being enabled]</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch4.S1.SS2" class="ltx_subsection"> | <section id='Ch4.S1.SS2' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">4.1.2 </span>Generator Ranges</h5> | <span class='ltx_tag ltx_tag_subsection'>4.1.2 </span>Generator Ranges</h5> |
| |
<div id="Ch4.S1.SS2.p1" class="ltx_para"> | <div id='Ch4.S1.SS2.p1' class='ltx_para'> |
<p class="ltx_p"><span class="ltx_text ltx_font_smallcaps">SaC</span> offers quite some flexibility when it comes to specifying | <p class='ltx_p'><span class='ltx_text ltx_font_smallcaps'>SaC</span> offers quite some flexibility when it comes to specifying |
generator ranges. | generator ranges. |
First of all, the use of index vectors in the bounds enables | 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. | 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> | Let us look at a few examples for the 2-dimensional case:</p> |
</div> | </div> |
<figure id="LST31" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST31' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 31: </span>Generator Range Specifications</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 31: </span>Generator Range Specifications</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGgg%0AewogICAgICAgIChbMCwyXSA8PSBbaSxqXSA8IFs1LDZdKTogNDI7CiAgICAgIH06IGdlbmFycmF5%0AKFs1LDZdLCAwKTsKICBwcmludChhKTsKCiAgc2hwID0gWzUsNl07CiAgYSA9IHdpdGggewogICAg%0AICAgICgwKnNocCA8PSBpdiA8IHNocCk6IDQyOwogICAgICB9OiBnZW5hcnJheShzaHAsIDApOwog%0AIHByaW50KGEpOwoKICBhID0gd2l0aCB7CiAgICAgICAgKC4gPCBpdiA8IC4pOiA0MjsKICAgICAg%0AfTogZ2VuYXJyYXkoWzUsNl0sIDApOwogIHByaW50KGEpOwoKICBhID0gd2l0aCB7CiAgICAgICAg%0AKC4gPD0ganY9W3gseV0gPD0gWzQsNV0pOiA0MjsKICAgICAgfTogZ2VuYXJyYXkoIFs1LDZdLCAw%0AKTsKICBwcmludChhKTsKCiAgYSA9IHdpdGggewogICAgICAgICguIDw9IFtpLGpdIDw9IC4gc3Rl%0AcCBbMSw0XSk6IDQyOwogICAgICB9OiBnZW5hcnJheShbNSw2XSwgMCk7CiAgcHJpbnQoYSk7Cgog%0AIGEgPSB3aXRoIHsKICAgICAgICAoLiA8PSBbaSxqXSA8PSAuIHN0ZXAgWzIsNF0gd2lkdGggWzEs%0AMl0pOiA0MjsKICAgICAgfTogZ2VuYXJyYXkoWzUsNl0sIDApOwogIHByaW50KGEpOwoKICByZXR1%0Acm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGggewogICAgICAgIChbMCwyXSA8PSBbaSxqXSA8IFs1LDZdKTogNDI7CiAgICAgIH06IGdlbmFycmF5KFs1LDZdLCAwKTsKICBwcmludChhKTsKCiAgc2hwID0gWzUsNl07CiAgYSA9IHdpdGggewogICAgICAgICgwKnNocCA8PSBpdiA8IHNocCk6IDQyOwogICAgICB9OiBnZW5hcnJheShzaHAsIDApOwogIHByaW50KGEpOwoKICBhID0gd2l0aCB7CiAgICAgICAgKC4gPCBpdiA8IC4pOiA0MjsKICAgICAgfTogZ2VuYXJyYXkoWzUsNl0sIDApOwogIHByaW50KGEpOwoKICBhID0gd2l0aCB7CiAgICAgICAgKC4gPD0ganY9W3gseV0gPD0gWzQsNV0pOiA0MjsKICAgICAgfTogZ2VuYXJyYXkoIFs1LDZdLCAwKTsKICBwcmludChhKTsKCiAgYSA9IHdpdGggewogICAgICAgICguIDw9IFtpLGpdIDw9IC4gc3RlcCBbMSw0XSk6IDQyOwogICAgICB9OiBnZW5hcnJheShbNSw2XSwgMCk7CiAgcHJpbnQoYSk7CgogIGEgPSB3aXRoIHsKICAgICAgICAoLiA8PSBbaSxqXSA8PSAuIHN0ZXAgWzIsNF0gd2lkdGggWzEsMl0pOiA0MjsKICAgICAgfTogZ2VuYXJyYXkoWzUsNl0sIDApOwogIHByaW50KGEpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx554' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx555' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx556' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx557' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx558' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx559' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx560' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span>([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>,j]<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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx561' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx562' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx563' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx564' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx565' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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><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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx566' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span>(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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx567' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx568' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx569' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx570' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx571' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span>(.<span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx572' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx573' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>20</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx574' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx575' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx576' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span>(.<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span>j<span class="ltx_text ltx_lst_identifier">v</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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx577' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx578' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</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'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx579' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx580' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx581' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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>,j]<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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx582' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">29</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx583' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx584' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">31</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>31</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx585' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx586' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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>,j]<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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx587' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx588' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx589' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">36</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>36</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx590' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx591' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">38</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>38</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch4.S1.SS2.p2" class="ltx_para"> | <div id='Ch4.S1.SS2.p2' class='ltx_para'> |
<p class="ltx_p">As we can see from the first with-loop in | <p class='ltx_p'>As we can see from the first with-loop in |
lines 6–8, a vector | lines 6–8, a vector |
of scalar indices can be used where we previously used the | of scalar indices can be used where we previously used the |
variable <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">iv</span> to denote the entire index vector. | variable <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>iv</span> to denote the entire index vector. |
In cases where the dimensionality of the with-loop is statically | In cases where the dimensionality of the with-loop is statically |
fixed, this sometimes comes in handy. | fixed, this sometimes comes in handy. |
as well as for the bounds.</p> | as well as for the bounds.</p> |
</div> | </div> |
<div id="Ch4.S1.SS2.p3" class="ltx_para"> | <div id='Ch4.S1.SS2.p3' class='ltx_para ltx_align_center'> |
<p class="ltx_p ltx_align_center"> | <p class='ltx_p'><span class='ltx_text ltx_framed_rectangle' style='border-color: black;'> |
| <span class='ltx_inline-para ltx_minipage ltx_align_middle' style='width:390.3pt;'> |
<span class="ltx_inline-block ltx_minipage ltx_align_middle ltx_framed_rectangle" style="width:390.3pt;"> | <span id='Ch4.S1.SS2.p3.p1' class='ltx_para'> |
<span class="ltx_p"><span class="ltx_text ltx_font_italic">Note here, that the ability to use vectors rather than | <span class='ltx_p'><span class='ltx_text ltx_font_italic'>Note here, that the ability to use vectors rather than |
componentised indices and bounds is absolutely crucial here! | componentised indices and bounds is absolutely crucial here! |
It constitutes </span><span class="ltx_text ltx_font_bold">the</span><span class="ltx_text ltx_font_italic"> enabling | It constitutes </span><span class='ltx_text ltx_font_bold'>the</span><span class='ltx_text ltx_font_italic'> enabling |
factor for specifying with-loops in a shape-invariant style as | factor for specifying with-loops in a shape-invariant style as |
the length of those vectors may remain unknown until runtime. | the length of those vectors may remain unknown until runtime. |
from most conventional language | from most conventional language |
constructs for data-parallel array operations.</span></span> | constructs for data-parallel array operations.</span></span> |
</span> | </span></span> |
</p> | </span></p> |
</div> | </div> |
<div id="Ch4.S1.SS2.p4" class="ltx_para"> | <div id='Ch4.S1.SS2.p4' class='ltx_para'> |
<p class="ltx_p">The with-loop in lines 12–14 | <p class='ltx_p'>The with-loop in lines 12–14 |
demonstrates a typical case where | demonstrates a typical case where |
the dimensionality of the resulting array is solely determined | the dimensionality of the resulting array is solely determined |
by a vector (here <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">shp</span>). | by a vector (here <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>shp</span>). |
A slightly more elegant way for the most frequent case is the use | A slightly more elegant way for the most frequent case is the use |
of a syntactical shortcut supported by <span class="ltx_text ltx_font_smallcaps">SaC</span>. The symbol “<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">.</span>” can | of a syntactical shortcut supported by <span class='ltx_text ltx_font_smallcaps'>SaC</span>. The symbol “<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>.</span>” can |
be used in the position for the lower and upper bound, denoting the | 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 | lowest legal index and the highest legal index into the array to be |
This is examplified in the with-loop in | This is examplified in the with-loop in |
lines 17–19. Note here, | lines 17–19. Note here, |
that this generator-range does <em class="ltx_emph">not</em> cover the entire legal | that this generator-range does <em class='ltx_emph ltx_font_italic'>not</em> cover the entire legal |
index space of the resulting array! | index space of the resulting array! |
As the “<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">.</span>” always represents legal indices, we have to make sure | As the “<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>.</span>” always represents legal indices, we have to make sure |
that we use <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><=</span> on both sides if we want to cover the entire | that we use <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><=</span> on both sides if we want to cover the entire |
range. The example presented here, excludes the extreme cases and, thus, | range. The example presented here, excludes the extreme cases and, thus, |
covers all inner elements of the resulting array only.</p> | covers all inner elements of the resulting array only.</p> |
</div> | </div> |
<div id="Thmtheorem26" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem26' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 26. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 26. </h6> |
<div id="Thmtheorem26.p1" class="ltx_para"> | <div id='Thmtheorem26.p1' class='ltx_para'> |
<p class="ltx_p">What happens if the length of the vectors within the generator-range | <p class='ltx_p'>What happens if the length of the vectors within the generator-range |
or the shape expression in the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">genarray</span>-operation do not match? | or the shape expression in the <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>genarray</span>-operation do not match? |
[<span class="ltx_text ltx_font_bold">Hint:</span> You should compile these example with the option <span class="ltx_text ltx_font_typewriter">-check c</span> | [<span class='ltx_text ltx_font_bold'>Hint:</span> You should compile these example with the option <span class='ltx_text ltx_font_typewriter'>-check c</span> |
being enabled]</p> | being enabled]</p> |
</div> | </div> |
</div> | </div> |
<div id="Ch4.S1.SS2.p5" class="ltx_para"> | <div id='Ch4.S1.SS2.p5' class='ltx_para'> |
<p class="ltx_p">The with-loop in lines 22–24 | <p class='ltx_p'>The with-loop in lines 22–24 |
demonstrates how both, a vector version | demonstrates how both, a vector version |
of the index vector and scalarised versions can be made available | of the index vector and scalarised versions can be made available |
for the generator-expression. It also examplifies that a mix of | for the generator-expression. It also examplifies that a mix of |
the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">.</span>-symbol and explicit expressions can be used for the bounds.</p> | the <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>.</span>-symbol and explicit expressions can be used for the bounds.</p> |
</div> | </div> |
<div id="Ch4.S1.SS2.p6" class="ltx_para"> | <div id='Ch4.S1.SS2.p6' class='ltx_para'> |
<p class="ltx_p">The remaining two with-loops demonstrate the ability to specify | <p class='ltx_p'>The remaining two with-loops demonstrate the ability to specify |
rectangular grids of indices. | rectangular grids of indices. |
The vector that follows the keyword <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">step</span> specifies the stride | The vector that follows the keyword <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>step</span> specifies the stride |
of the reoccurence pattern per axis. | of the reoccurence pattern per axis. |
As a consequence, the with-loop in lines 27–29 | As a consequence, the with-loop in lines 27–29 |
computes an array | computes an array |
whose every fourth column is <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">42</span> starting with the very first one.</p> | whose every fourth column is <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>42</span> starting with the very first one.</p> |
</div> | </div> |
<div id="Ch4.S1.SS2.p7" class="ltx_para"> | <div id='Ch4.S1.SS2.p7' class='ltx_para'> |
<p class="ltx_p">The use of the vector after the keyword <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">width</span> enables the programmer | <p class='ltx_p'>The use of the vector after the keyword <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>width</span> enables the programmer |
to denote more than one index per stepping period. | to denote more than one index per stepping period. |
The with-loop in lines 27–29 | 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 | 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 |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">42</span> 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 | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>42</span> 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> | resulting array.</p> |
</div> | </div> |
<div id="Thmtheorem27" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem27' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 27. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 27. </h6> |
<div id="Thmtheorem27.p1" class="ltx_para"> | <div id='Thmtheorem27.p1' class='ltx_para'> |
<p class="ltx_p">Can you achieve the same result array as the last with-loop of the above | <p class='ltx_p'>Can you achieve the same result array as the last with-loop of the above |
examples <span class="ltx_text ltx_font_bold">without</span> using the step/width facility? | examples <span class='ltx_text ltx_font_bold'>without</span> using the step/width facility? |
[<span class="ltx_text ltx_font_bold">Hint:</span> The solution may be surprisingly short!]</p> | [<span class='ltx_text ltx_font_bold'>Hint:</span> The solution may be surprisingly short!]</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch4.S1.SS3" class="ltx_subsection"> | <section id='Ch4.S1.SS3' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">4.1.3 </span>Generator Expressions</h5> | <span class='ltx_tag ltx_tag_subsection'>4.1.3 </span>Generator Expressions</h5> |
| |
<div id="Ch4.S1.SS3.p1" class="ltx_para"> | <div id='Ch4.S1.SS3.p1' class='ltx_para'> |
<p class="ltx_p">As we have seen in the previous sections, each generator expression | <p class='ltx_p'>As we have seen in the previous sections, each generator expression |
implicitly defines a mapping function from indices to expressions. | implicitly defines a mapping function from indices to expressions. |
The parameters of these functions are derived from the index variables | The parameters of these functions are derived from the index variables |
associated generator expression. Here a few examples:</p> | associated generator expression. Here a few examples:</p> |
</div> | </div> |
<figure id="LST32" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST32' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 32: </span>Non-trivial generator expressions</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 32: </span>Non-trivial generator expressions</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGgg%0AewogICAgICAgIChbMCwxXSA8PSBbaSxqXSA8IFs2LDZdKSB7CiAgICAgICAgICBkaXYsIG1vZCA9%0AIGRpdm1vZCggaSwgaik7CiAgICAgICAgfTogbW9kOwogICAgICB9OiBnZW5hcnJheShbNiw2XSwg%0AMCk7CiAgcHJpbnQoYSk7CgogIGEgPSB3aXRoIHsKICAgICAgICAoLiA8PSBbaSxqXSA8PSAuKTog%0AKGk9PWogPyAxOiAwKSA7CiAgICAgIH06IGdlbmFycmF5KFs2LDZdLCAwKTsKICBwcmludChhKTsK%0ACiAgYSA9IHdpdGggewogICAgICAgICguIDw9IFtpXSA8PSAuKSB7CiAgICAgICAgICBtdmFsID0g%0AaTsKICAgICAgICAgIHZhbCA9IHN1bSh3aXRoIHsKICAgICAgICAgICAgICAgICAgICAgICAoLiA8%0APSBbaV0gPD0gLik6IGk7CiAgICAgICAgICAgICAgICAgICAgfTogZ2VuYXJyYXkoW212YWxdLCAw%0AKSk7CiAgICAgICAgfTogdmFsOwogICAgICB9OiBnZW5hcnJheShbNl0sIDApOwogIHByaW50KGEp%0AOwoKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGggewogICAgICAgIChbMCwxXSA8PSBbaSxqXSA8IFs2LDZdKSB7CiAgICAgICAgICBkaXYsIG1vZCA9IGRpdm1vZCggaSwgaik7CiAgICAgICAgfTogbW9kOwogICAgICB9OiBnZW5hcnJheShbNiw2XSwgMCk7CiAgcHJpbnQoYSk7CgogIGEgPSB3aXRoIHsKICAgICAgICAoLiA8PSBbaSxqXSA8PSAuKTogKGk9PWogPyAxOiAwKSA7CiAgICAgIH06IGdlbmFycmF5KFs2LDZdLCAwKTsKICBwcmludChhKTsKCiAgYSA9IHdpdGggewogICAgICAgICguIDw9IFtpXSA8PSAuKSB7CiAgICAgICAgICBtdmFsID0gaTsKICAgICAgICAgIHZhbCA9IHN1bSh3aXRoIHsKICAgICAgICAgICAgICAgICAgICAgICAoLiA8PSBbaV0gPD0gLik6IGk7CiAgICAgICAgICAgICAgICAgICAgfTogZ2VuYXJyYXkoW212YWxdLCAwKSk7CiAgICAgICAgfTogdmFsOwogICAgICB9OiBnZW5hcnJheShbNl0sIDApOwogIHByaW50KGEpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx592' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx593' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx594' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx595' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx596' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx597' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx598' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span>([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>,j]<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;'>7</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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx599' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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>j); | <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'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx600' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>9</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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx601' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>10</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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx602' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx603' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx604' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx605' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span>(.<span class="ltx_text ltx_lst_space"> </span><=<span class="ltx_text ltx_lst_space"> </span>[<span class="ltx_text ltx_lst_identifier">i</span>,j]<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>==j<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;'>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_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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx606' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx607' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</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'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx608' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx609' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx610' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span>(.<span class="ltx_text ltx_lst_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;'>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_space'> </span><=<span class='ltx_text ltx_lst_space'> </span>.)<span class='ltx_text ltx_lst_space'> </span>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx611' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>20</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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx612' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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">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;'>21</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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx613' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span><span class="ltx_text ltx_lst_space"> </span>(.<span class="ltx_text ltx_lst_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;'>22</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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx614' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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_identifier'>genarray</span>([<span class='ltx_text ltx_lst_identifier'>mval</span>],<span class='ltx_text ltx_lst_space'> </span>0)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx615' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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'>val</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx616' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>25</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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx617' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</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'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx618' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>27</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx619' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">28</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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx620' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">29</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch4.S1.SS3.p2" class="ltx_para"> | <div id='Ch4.S1.SS3.p2' class='ltx_para'> |
<p class="ltx_p">The first with-loop in lines 6–10 | <p class='ltx_p'>The first with-loop in lines 6–10 |
shows a typical scenario. | shows a typical scenario. |
The function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">divmod</span> returns two values rather than just one. | The function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>divmod</span> returns two values rather than just one. |
Rather than defining an explicit mapping function that passes | Rather than defining an explicit mapping function that passes |
on the desired return value, we can specify this selection | on the desired return value, we can specify this selection |
directly.</p> | directly.</p> |
</div> | </div> |
<div id="Ch4.S1.SS3.p3" class="ltx_para"> | <div id='Ch4.S1.SS3.p3' class='ltx_para'> |
<p class="ltx_p">The with-loop in lines 13–15 | <p class='ltx_p'>The with-loop in lines 13–15 |
demonstrates how non-trivial expressions | demonstrates how non-trivial expressions |
can be used even without necessitating the introduction of an | can be used even without necessitating the introduction of an |
assignment block.</p> | assignment block.</p> |
</div> | </div> |
<div id="Ch4.S1.SS3.p4" class="ltx_para"> | <div id='Ch4.S1.SS3.p4' class='ltx_para'> |
<p class="ltx_p">The scope of variables that are defined in such an assignment block is | <p class='ltx_p'>The scope of variables that are defined in such an assignment block is |
strictly local | strictly local |
to that block. Such a variable can neither be referenced within other generators | to that block. Such a variable can neither be referenced within other generators |
of the examples above.</p> | of the examples above.</p> |
</div> | </div> |
<div id="Thmtheorem28" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem28' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 28. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 28. </h6> |
<div id="Thmtheorem28.p1" class="ltx_para"> | <div id='Thmtheorem28.p1' class='ltx_para'> |
<p class="ltx_p">What do you expect to happen, if a variable that is defined | <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? | in such an assignment block has the same name as the index variable? |
Where is the “modified” version observable?</p> | Where is the “modified” version observable?</p> |
</div> | </div> |
<div id="Thmtheorem28.p2" class="ltx_para"> | <div id='Thmtheorem28.p2' class='ltx_para'> |
<p class="ltx_p">Why can the variable <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">mval</span> in the example above be safely replaced by | <p class='ltx_p'>Why can the variable <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>mval</span> in the example above be safely replaced by |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">i</span>?</p> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>i</span>?</p> |
</div> | </div> |
</div> | </div> |
</section> | </section> |
<section id="Ch4.S1.SS4" class="ltx_subsection"> | <section id='Ch4.S1.SS4' class='ltx_subsection'> |
<h5 class="ltx_title ltx_title_subsection"> | <h5 class='ltx_title ltx_title_subsection'> |
<span class="ltx_tag ltx_tag_subsection">4.1.4 </span>Reductions and further with-loop Operations</h5> | <span class='ltx_tag ltx_tag_subsection'>4.1.4 </span>Reductions and further with-loop Operations</h5> |
| |
<div id="Ch4.S1.SS4.p1" class="ltx_para"> | <div id='Ch4.S1.SS4.p1' class='ltx_para'> |
<p class="ltx_p">Besides the genarray with-loop operator described so far, <span class="ltx_text ltx_font_smallcaps">SaC</span> supports | <p class='ltx_p'>Besides the genarray with-loop operator described so far, <span class='ltx_text ltx_font_smallcaps'>SaC</span> supports |
a few more. These are: | a few more. These are: |
</p> | </p> |
</div> | </div> |
<div id="Ch4.S1.SS4.p2" class="ltx_para"> | <div id='Ch4.S1.SS4.p2' class='ltx_para'> |
<ul id="Ch4.I4" class="ltx_itemize"> | <ul id='Ch4.S1.I3' class='ltx_itemize'> |
<li id="Ch4.I4.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I3.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I4.i1.p1" class="ltx_para"> | <div id='Ch4.S1.I3.i1.p1' class='ltx_para'> |
<p class="ltx_p">a <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">modarray</span> operator which “modifies” an existing array, and</p> | <p class='ltx_p'>a <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>modarray</span> operator which “modifies” an existing array, and</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch4.I4.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch4.S1.I3.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch4.I4.i2.p1" class="ltx_para"> | <div id='Ch4.S1.I3.i2.p1' class='ltx_para'> |
<p class="ltx_p">two <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">fold</span> operators that enable the specification of reduction | <p class='ltx_p'>two <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>fold</span> operators that enable the specification of reduction |
operations</p> | operations</p> |
</div> | </div> |
</ul> | </ul> |
</div> | </div> |
<div id="Ch4.S1.SS4.p3" class="ltx_para"> | <div id='Ch4.S1.SS4.p3' class='ltx_para'> |
<p class="ltx_p">The modarray variant is very similar to the genarray variant. | <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 | The only difference is that neither the shape of the result |
nor a default element for unspecified index positions | nor a default element for unspecified index positions |
lines 11–13 | lines 11–13 |
of the example below demonstrates this. | of the example below demonstrates this. |
Here, a new array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">b</span> is computed from the array <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> | Here, a new array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>b</span> is computed from the array <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> |
by negating each second element of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span>. | by negating each second element of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span>. |
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"><span class="ltx_text ltx_ref_tag">2.1</span></a> on arrays as data, printing | 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'><span class='ltx_text ltx_ref_tag'>2.1</span></a> on arrays as data, printing |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">a</span> in line 15 shows that in fact two different arrays have | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>a</span> in line 15 shows that in fact two different arrays have |
been created.</p> | been created.</p> |
</div> | </div> |
<figure id="LST33" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST33' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 33: </span>Further with-loop operators</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 33: </span>Further with-loop operators</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGgg%0AewogICAgICAgICguIDw9IFtpXSA8PSAuKTogaTsKICAgICAgfTogZ2VuYXJyYXkoIFs2XSwgMCk7%0ACiAgcHJpbnQoYSk7CgogIGIgPSB3aXRoIHsKICAgICAgICAoLiA8PSBpdiA8PSAuIHN0ZXAgWzJd%0AKTogLWFbaXZdOwogICAgICB9OiBtb2RhcnJheShhKTsKICBwcmludChiKTsKICBwcmludChhKTsK%0ACiAgYyA9IHdpdGggewogICAgICAgKFswXSA8PSBpdiA8PSBbNV0pOiBhW2l2XTsKICAgICAgfTog%0AZm9sZCgqLCAxKTsKICBwcmludChjKTsKCiAgZCA9IHdpdGggewogICAgICAgKFswXSA8PSBpdiA8%0APSBbNV0pOiBhW2l2XTsKICAgICAgfTogZm9sZGZpeCgqLCAxLCAwKTsKICBwcmludChkKTsKCiAg%0AcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CnVzZSBBcnJheTogYWxsOwoKaW50IG1haW4oKQp7CiAgYSA9IHdpdGggewogICAgICAgICguIDw9IFtpXSA8PSAuKTogaTsKICAgICAgfTogZ2VuYXJyYXkoIFs2XSwgMCk7CiAgcHJpbnQoYSk7CgogIGIgPSB3aXRoIHsKICAgICAgICAoLiA8PSBpdiA8PSAuIHN0ZXAgWzJdKTogLWFbaXZdOwogICAgICB9OiBtb2RhcnJheShhKTsKICBwcmludChiKTsKICBwcmludChhKTsKCiAgYyA9IHdpdGggewogICAgICAgKFswXSA8PSBpdiA8PSBbNV0pOiBhW2l2XTsKICAgICAgfTogZm9sZCgqLCAxKTsKICBwcmludChjKTsKCiAgZCA9IHdpdGggewogICAgICAgKFswXSA8PSBpdiA8PSBbNV0pOiBhW2l2XTsKICAgICAgfTogZm9sZGZpeCgqLCAxLCAwKTsKICBwcmludChkKTsKCiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx621' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx622' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">Array</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Array</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx623' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx624' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx625' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx626' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">a</span><span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span><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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx627' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span>(.<span class="ltx_text ltx_lst_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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx628' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx629' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">a</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx630' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx631' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx632' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span>(.<span class="ltx_text ltx_lst_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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx633' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx634' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">b</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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx635' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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'>print</span>(<span class='ltx_text ltx_lst_identifier'>a</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx636' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx637' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx638' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span><span class="ltx_text ltx_lst_space"> </span>([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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx639' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx640' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">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_text ltx_lst_identifier'>print</span>(<span class='ltx_text ltx_lst_identifier'>c</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx641' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx642' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx643' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span><span class="ltx_text ltx_lst_space"> </span>([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;'>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>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx644' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span><span class="ltx_text ltx_lst_space"> </span>}:<span class="ltx_text ltx_lst_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;'>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); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx645' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">print</span>(<span class="ltx_text ltx_lst_identifier">d</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'>d</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx646' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx647' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx648' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">28</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>28</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch4.S1.SS4.p4" class="ltx_para"> | <div id='Ch4.S1.SS4.p4' class='ltx_para'> |
<p class="ltx_p">The two final examples demonstrate how reduction operations can be specified | <p class='ltx_p'>The two final examples demonstrate how reduction operations can be specified |
in <span class="ltx_text ltx_font_smallcaps">SaC</span>. | in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. |
The first variant (lines 17–19) | The first variant (lines 17–19) |
is the standard variant for reductions. | is the standard variant for reductions. |
It requires the specification of a folding function (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">*</span> in this case) | It requires the specification of a folding function (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>*</span> in this case) |
and of a neutral element (<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting">1</span> here). | and of a neutral element (<span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>1</span> here). |
As with the earlier variants, all index vectors from the generator range are mapped | As with the earlier variants, all index vectors from the generator range are mapped |
according to the generator expression. Subsequently all computed | according to the generator expression. Subsequently all computed |
associative and commutative.</p> | associative and commutative.</p> |
</div> | </div> |
<div id="Ch4.S1.SS4.p5" class="ltx_para"> | <div id='Ch4.S1.SS4.p5' class='ltx_para'> |
<p class="ltx_p">The final with-loop in lines 22–24 | <p class='ltx_p'>The final with-loop in lines 22–24 |
is a slight variant of the fold version. | is a slight variant of the fold version. |
It stems from the observation that some reductions can be shortcut | It stems from the observation that some reductions can be shortcut |
when a certain fixpoint value has been met. In the given example of | when a certain fixpoint value has been met. In the given example of |
multiplication this is the value <span class="ltx_text ltx_lstlisting"></span>. | multiplication this is the value <span class='ltx_text ltx_lstlisting'></span>. |
Whether the underlying implementation makes use of this extra information | Whether the underlying implementation makes use of this extra information |
or not is not specified. The computational result of both, the fold | or not is not specified. The computational result of both, the fold |
</section> | </section> |
</section> | </section> |
<section id="Ch5" class="ltx_chapter"> | <section id='Ch5' class='ltx_chapter'> |
<h3 class="ltx_title ltx_title_chapter"> | <h3 class='ltx_title ltx_title_chapter'> |
<span class="ltx_tag ltx_tag_chapter">Chapter 5 </span>Working with Modules</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 5 </span>Working with Modules</h3> |
| |
<div id="Ch5.p1" class="ltx_para"> | <div id='Ch5.p1' class='ltx_para'> |
<p class="ltx_p">This chapter explains the basic principles of using modules in <span class="ltx_text ltx_font_smallcaps">SaC</span>. Prior to | <p class='ltx_p'>This chapter explains the basic principles of using modules in <span class='ltx_text ltx_font_smallcaps'>SaC</span>. Prior to |
modules, a short introduction into <span class="ltx_text ltx_font_smallcaps">SaC</span> name spaces is given.</p> | modules, a short introduction into <span class='ltx_text ltx_font_smallcaps'>SaC</span> name spaces is given.</p> |
</div> | </div> |
<section id="Ch5.S1" class="ltx_section"> | <section id='Ch5.S1' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">5.1 </span>Name Spaces</h4> | <span class='ltx_tag ltx_tag_section'>5.1 </span>Name Spaces</h4> |
| |
<div id="Ch5.S1.p1" class="ltx_para"> | <div id='Ch5.S1.p1' class='ltx_para'> |
<p class="ltx_p">In general, name spaces are used to extend the set of possible identifiers and | <p class='ltx_p'>In general, name spaces are used to extend the set of possible identifiers and |
thus inhibit potential name clashes. <span class="ltx_text ltx_font_smallcaps">SaC</span> supports multiple name spaces, although | thus inhibit potential name clashes. <span class='ltx_text ltx_font_smallcaps'>SaC</span> supports multiple name spaces, although |
these are not explicitly defined by the programmer. Instead, every module and | 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 | program has its own name space. The name space of a module is denoted by its |
name, a program uses <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">main</span> as its name space identifier. As an example of | name, a program uses <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>main</span> as its name space identifier. As an example of |
using name spaces consider Listing <a href="#LST34" title="34 ‣ 5.1 Name Spaces ‣ Chapter 5 Working with Modules ‣ Part I Trails Covering the Basics of SaC" class="ltx_ref"><span class="ltx_text ltx_ref_tag">34</span></a>.</p> | 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'><span class='ltx_text ltx_ref_tag'>34</span></a>.</p> |
</div> | </div> |
<figure id="LST34" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST34' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 34: </span>Hello world program with name spaces</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 34: </span>Hello world program with name spaces</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,aW50IG1haW4oKQp7CiAgU3RkSU86OnByaW50ZigiSGVsbG8gV29ybGQhXG4iKTsKICByZXR1cm4g%0AMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,aW50IG1haW4oKQp7CiAgU3RkSU86OnByaW50ZigiSGVsbG8gV29ybGQhXG4iKTsKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx649' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx650' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx651' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx652' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx653' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S1.p2" class="ltx_para"> | <div id='Ch5.S1.p2' class='ltx_para'> |
<p class="ltx_p">Instead of an import statement, a qualified function name is used. A qualified | <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 | identifier always consists of a name space identifier, followed by a double |
colon and the unqualified identifier, in this case a function identifier. | colon and the unqualified identifier, in this case a function identifier. |
global objects.</p> | global objects.</p> |
</div> | </div> |
<div id="Ch5.S1.p3" class="ltx_para"> | <div id='Ch5.S1.p3' class='ltx_para'> |
<p class="ltx_p">As it would be bothering to precede each identifier with the name space it | <p class='ltx_p'>As it would be bothering to precede each identifier with the name space it |
belongs to, <span class="ltx_text ltx_font_smallcaps">SaC</span> supports multiple ways to automatically decide the right name | belongs to, <span class='ltx_text ltx_font_smallcaps'>SaC</span> supports multiple ways to automatically decide the right name |
space and generate a fully qualified identifier implicitly (or internally).</p> | space and generate a fully qualified identifier implicitly (or internally).</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch5.S2" class="ltx_section"> | <section id='Ch5.S2' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">5.2 </span>Use Statements</h4> | <span class='ltx_tag ltx_tag_section'>5.2 </span>Use Statements</h4> |
| |
<div id="Ch5.S2.p1" class="ltx_para"> | <div id='Ch5.S2.p1' class='ltx_para'> |
<p class="ltx_p">To simplify the use of identifiers from other modules, <span class="ltx_text ltx_font_smallcaps">SaC</span> allows us to specify | <p class='ltx_p'>To simplify the use of identifiers from other modules, <span class='ltx_text ltx_font_smallcaps'>SaC</span> allows us to specify |
a search space whose identifiers can be used in an unqualified fashion. By | 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. | 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 | To add a complete name space to the current search space, you may use the |
statement <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><math id="Ch5.S2.p1.m1" class="ltx_Math" alttext="\alpha" display="inline"><mi>α</mi></math>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>;</span> where <math id="Ch5.S2.p1.m2" class="ltx_Math" alttext="\alpha" display="inline"><mi>α</mi></math> gives | statement <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><math id='Ch5.S2.p1.m1' class='ltx_Math' alttext='\alpha' display='inline'><mi>α</mi></math>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>;</span> 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 | the name of a name space. Using this technique, the hello world example can as |
well be expressed as follows:</p> | well be expressed as follows:</p> |
</div> | </div> |
<figure id="LST35" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST35' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 35: </span>hello world with use statement</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 35: </span>hello world with use statement</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CgppbnQgbWFpbigpCnsKICBwcmludGYoIkhlbGxvIFdvcmxkIVxuIik7%0ACiAgcmV0dXJuIDA7Cn0=%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CgppbnQgbWFpbigpCnsKICBwcmludGYoIkhlbGxvIFdvcmxkIVxuIik7CiAgcmV0dXJuIDA7Cn0='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx654' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx655' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx656' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx657' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx658' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx659' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx660' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S2.p2" class="ltx_para"> | <div id='Ch5.S2.p2' class='ltx_para'> |
<p class="ltx_p">However, an identifier is not allowed to have multiple occurrences within the | <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 | search space as far as types and global objects are concerned. For function |
symbols the same holds modulo overloading based on parameter types.</p> | symbols the same holds modulo overloading based on parameter types.</p> |
</div> | </div> |
<div id="Ch5.S2.p3" class="ltx_para"> | <div id='Ch5.S2.p3' class='ltx_para'> |
<p class="ltx_p">To further avoid name clashes, <span class="ltx_text ltx_font_smallcaps">SaC</span> supports a more specific way to define search | <p class='ltx_p'>To further avoid name clashes, <span class='ltx_text ltx_font_smallcaps'>SaC</span> supports a more specific way to define search |
spaces. Instead of the keyword <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">all</span>, a comma separated list of | spaces. Instead of the keyword <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>all</span>, a comma separated list of |
identifiers can be given. The following version of hello world uses a more | identifiers can be given. The following version of hello world uses a more |
specific use statement:</p> | specific use statement:</p> |
</div> | </div> |
<figure id="LST36" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST36' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 36: </span>hello world with specific use statement</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 36: </span>hello world with specific use statement</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiB7cHJpbnRmfTsKCmludCBtYWluKCkKewogIHByaW50ZigiSGVsbG8gV29ybGQh%0AXG4iKTsKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiB7cHJpbnRmfTsKCmludCBtYWluKCkKewogIHByaW50ZigiSGVsbG8gV29ybGQhXG4iKTsKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx661' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span>{<span class="ltx_text ltx_lst_identifier">printf</span>}; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span>{<span class='ltx_text ltx_lst_identifier'>printf</span>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx662' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx663' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx664' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx665' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx666' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx667' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S2.p4" class="ltx_para"> | <div id='Ch5.S2.p4' class='ltx_para'> |
<p class="ltx_p">In this example, only <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">printf</span> is made available to the search space | <p class='ltx_p'>In this example, only <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>printf</span> is made available to the search space |
and can thus be used without explicitly specifying its name space. In some | 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 | occasions it can be useful to add all identifiers except a given set to the |
search space. Consider a module <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">FastIO</span> reimplementing all functions | search space. Consider a module <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>FastIO</span> reimplementing all functions |
of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">StdIO</span>. To use <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">FastIO</span> except the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">printf</span> | of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>StdIO</span>. To use <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>FastIO</span> except the <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>printf</span> |
function, but <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">StdIO</span>::<span class="ltx_text ltx_lst_identifier">printf</span></span> one might write:</p> | function, but <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span></span> one might write:</p> |
</div> | </div> |
<figure id="LST37" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST37' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 37: </span>hello world with use all but statement</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 37: </span>hello world with use all but statement</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIEZhc3RJTzogYWxsIGV4Y2VwdCB7cHJpbnRmfTsKdXNlIFN0ZElPOiB7cHJpbnRmfTsKCmlu%0AdCBtYWluKCkKewogIHByaW50ZigiSGVsbG8gV29ybGQhXG4iKTsKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIEZhc3RJTzogYWxsIGV4Y2VwdCB7cHJpbnRmfTsKdXNlIFN0ZElPOiB7cHJpbnRmfTsKCmludCBtYWluKCkKewogIHByaW50ZigiSGVsbG8gV29ybGQhXG4iKTsKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx668' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx669' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx670' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx671' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx672' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx673' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">printf</span>(<span class="ltx_text ltx_lst_string">”Hello<span class="ltx_text ltx_lst_space"> </span>World!\n”</span>); | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>printf</span>(<span class='ltx_text ltx_lst_string'>”Hello<span class='ltx_text ltx_lst_space'> </span>World!\n”</span>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx674' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx675' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S2.p5" class="ltx_para"> | <div id='Ch5.S2.p5' class='ltx_para'> |
<p class="ltx_p">This adds all identifiers from <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">FastIO</span> to the current search space | <p class='ltx_p'>This adds all identifiers from <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>FastIO</span> to the current search space |
except <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">FastIO</span>::<span class="ltx_text ltx_lst_identifier">printf</span></span>. This allows the function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">printf</span> | except <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>FastIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span></span>. This allows the function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>printf</span> |
to be imported from module <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">StdIO</span>.</p> | to be imported from module <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>StdIO</span>.</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch5.S3" class="ltx_section"> | <section id='Ch5.S3' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">5.3 </span>Import statement</h4> | <span class='ltx_tag ltx_tag_section'>5.3 </span>Import statement</h4> |
| |
<div id="Ch5.S3.p1" class="ltx_para"> | <div id='Ch5.S3.p1' class='ltx_para'> |
<p class="ltx_p">So far, we added identifiers to the search space of the <span class="ltx_text ltx_font_smallcaps">SaC</span> compiler to avoid | <p class='ltx_p'>So far, we added identifiers to the search space of the <span class='ltx_text ltx_font_smallcaps'>SaC</span> compiler to avoid |
explicitly specifying their name spaces each time they are referenced. As | explicitly specifying their name spaces each time they are referenced. As |
function signatures have to differ in number of arguments or their types, the | function signatures have to differ in number of arguments or their types, the |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">use</span> statement prevents overloading of functions by shape across | <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>use</span> statement prevents overloading of functions by shape across |
module boundaries. In fact, <span class="ltx_text ltx_font_smallcaps">SaC</span> only supports overloading by shape within a | module boundaries. In fact, <span class='ltx_text ltx_font_smallcaps'>SaC</span> only supports overloading by shape within a |
single name space. Otherwise, the meaning of a fully qualified identifier could | single name space. Otherwise, the meaning of a fully qualified identifier could |
differ when being used in different scopes. To nonetheless allow for successive | differ when being used in different scopes. To nonetheless allow for successive |
overloading in separate modules, <span class="ltx_text ltx_font_smallcaps">SaC</span> provides a mechanism for cloning functions | overloading in separate modules, <span class='ltx_text ltx_font_smallcaps'>SaC</span> provides a mechanism for cloning functions |
using the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">import</span> statement.</p> | using the <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>import</span> statement.</p> |
</div> | </div> |
<figure id="LST38" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST38' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 38: </span>hello world with import statement</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 38: </span>hello world with import statement</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,aW1wb3J0IFN0ZElPOiB7cHJpbnRmfTsKCmludCBtYWluKCkKewogIG1haW46OnByaW50ZigiSGVs%0AbG8gV29ybGQhXG4iKTsKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,aW1wb3J0IFN0ZElPOiB7cHJpbnRmfTsKCmludCBtYWluKCkKewogIG1haW46OnByaW50ZigiSGVsbG8gV29ybGQhXG4iKTsKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx676' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>1</span></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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx677' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx678' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx679' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx680' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx681' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx682' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S3.p2" class="ltx_para"> | <div id='Ch5.S3.p2' class='ltx_para'> |
<p class="ltx_p">In this example, the statement <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><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> creates a | <p class='ltx_p'>In this example, the statement <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><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> creates a |
(conceptual) copy of the function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">printf</span> in the current name space | (conceptual) copy of the function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>printf</span> in the current name space |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">main</span>. Consider a module <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">foo</span> containing a function | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>main</span>. Consider a module <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>foo</span> containing a function |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><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>. This function can now be overloaded as follows:</p> | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><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>. This function can now be overloaded as follows:</p> |
</div> | </div> |
<figure id="LST39" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST39' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 39: </span>bar overloading</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 39: </span>bar overloading</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,aW1wb3J0IGZvbzoge2Jhcn07CgppbnRbK10gYmFyKGludFsrXSB4KQp7CiAgLyogLi4uICAqLwp9%0ACgppbnQgbWFpbigpCnsKICAvKiAuLi4gICovCgogIHkgPSBiYXIoeCk7CgogIC8qIC4uLiAgKi8K%0AfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,aW1wb3J0IGZvbzoge2Jhcn07CgppbnRbK10gYmFyKGludFsrXSB4KQp7CiAgLyogLi4uICAqLwp9CgppbnQgbWFpbigpCnsKICAvKiAuLi4gICovCgogIHkgPSBiYXIoeCk7CgogIC8qIC4uLiAgKi8KfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx683' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>1</span></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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx684' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx685' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[+]<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>3</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[+]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx686' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx687' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx688' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>6</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx689' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx690' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_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_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx691' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx692' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx693' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>11</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx694' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx695' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>13</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx696' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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><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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx697' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>15</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S3.p3" class="ltx_para"> | <div id='Ch5.S3.p3' class='ltx_para'> |
<p class="ltx_p">Within the name space <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">main</span> there are two instances of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">bar</span>, the | <p class='ltx_p'>Within the name space <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>main</span> there are two instances of <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>bar</span>, the |
one imported from <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">foo</span> and the one defined within <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">main</span> | one imported from <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>foo</span> and the one defined within <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>main</span> |
itself. Keep in mind, that there is a conceptual copy in <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">main</span>, so | itself. Keep in mind, that there is a conceptual copy in <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>main</span>, so |
both are defined in <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">main</span> and so overloading can take place.</p> | both are defined in <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>main</span> and so overloading can take place.</p> |
</div> | </div> |
<div id="Ch5.S3.p4" class="ltx_para"> | <div id='Ch5.S3.p4' class='ltx_para'> |
<p class="ltx_p">Be careful when importing types, as an imported type is regarded as different to | <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 | 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 | spaces. However, you might still exchanges values between both types by means of |
</div> | </div> |
</section> | </section> |
<section id="Ch5.S4" class="ltx_section"> | <section id='Ch5.S4' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">5.4 </span>Putting It Together</h4> | <span class='ltx_tag ltx_tag_section'>5.4 </span>Putting It Together</h4> |
| |
<div id="Ch5.S4.p1" class="ltx_para"> | <div id='Ch5.S4.p1' class='ltx_para'> |
<p class="ltx_p">Both types of module statements can be mixed in any possible way, as long as no | <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 <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">import</span> | name clash is introduced by them. Always keep in mind that an <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>import</span> |
statement adds all identifiers to the current name space and thus to the current | 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 | search space, as well. The following example creates a name clash by using and |
importing the same identifier:</p> | importing the same identifier:</p> |
</div> | </div> |
<figure id="LST40" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST40' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 40: </span>name clash example</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 40: </span>name clash example</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CmltcG9ydCBTdGRJTzoge3ByaW50Zn07CgppbnQgbWFpbigpCnsKICBw%0AcmludGYoIk5ldmVyIHNlZSB0aGlzIVxuIik7CgogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGw7CmltcG9ydCBTdGRJTzoge3ByaW50Zn07CgppbnQgbWFpbigpCnsKICBwcmludGYoIk5ldmVyIHNlZSB0aGlzIVxuIik7CgogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx698' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span>; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx699' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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_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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx700' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx701' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx702' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx703' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">printf</span>(<span class="ltx_text ltx_lst_string">”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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx704' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx705' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx706' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S4.p2" class="ltx_para"> | <div id='Ch5.S4.p2' class='ltx_para'> |
<p class="ltx_p">Here, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">printf</span> is imported to the current name space, so there is an | <p class='ltx_p'>Here, <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>printf</span> is imported to the current name space, so there is an |
identifier <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">main</span>::<span class="ltx_text ltx_lst_identifier">printf</span></span>, which is part of the compiler search space. | identifier <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>main</span>::<span class='ltx_text ltx_lst_identifier'>printf</span></span>, which is part of the compiler search space. |
Furthermore, the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">use</span> statement adds the complete name space of | Furthermore, the <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>use</span> statement adds the complete name space of |
module <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">StdIO</span> to the current name space, especially the identifier | module <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>StdIO</span> to the current name space, especially the identifier |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">StdIO</span>::<span class="ltx_text ltx_lst_identifier">printf</span></span>. Thus there are two identifiers with the same | <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span></span>. Thus there are two identifiers with the same |
unqualified name within the search space. To solve this, a restriction to the | unqualified name within the search space. To solve this, a restriction to the |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">use</span> statement can be used.</p> | <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>use</span> statement can be used.</p> |
</div> | </div> |
<figure id="LST41" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST41' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 41: </span>name clash example</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 41: </span>name clash example</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0ZElPOiBhbGwgZXhjZXB0IHtwcmludGZ9OwppbXBvcnQgU3RkSU86IHtwcmludGZ9OwoK%0AaW50IG1haW4oKQp7CiAgcHJpbnRmKCJIZXksIGl0IHdvcmtzIVxuIik7CgogIHJldHVybiAwOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0ZElPOiBhbGwgZXhjZXB0IHtwcmludGZ9OwppbXBvcnQgU3RkSU86IHtwcmludGZ9OwoKaW50IG1haW4oKQp7CiAgcHJpbnRmKCJIZXksIGl0IHdvcmtzIVxuIik7CgogIHJldHVybiAwOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx707' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">StdIO</span>:<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">all</span><span class="ltx_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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span><span class='ltx_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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx708' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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_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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx709' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>3</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx710' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx711' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx712' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">printf</span>(<span class="ltx_text ltx_lst_string">”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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx713' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx714' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span>0; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>8</span></span> |
| <span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_keyword ltx_font_bold'>return</span><span class='ltx_text ltx_lst_space'> </span>0; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx715' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S4.p3" class="ltx_para"> | <div id='Ch5.S4.p3' class='ltx_para'> |
<p class="ltx_p">In this example, the identifier <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting"><span class="ltx_text ltx_lst_identifier">StdIO</span>::<span class="ltx_text ltx_lst_identifier">printf</span></span> is no longer added to | <p class='ltx_p'>In this example, the identifier <span class='ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'><span class='ltx_text ltx_lst_identifier'>StdIO</span>::<span class='ltx_text ltx_lst_identifier'>printf</span></span> is no longer added to |
the compiler search space and thus no name clash originates.</p> | the compiler search space and thus no name clash originates.</p> |
</div> | </div> |
</section> | </section> |
<section id="Ch5.S5" class="ltx_section"> | <section id='Ch5.S5' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">5.5 </span>Implementing Modules</h4> | <span class='ltx_tag ltx_tag_section'>5.5 </span>Implementing Modules</h4> |
| |
<div id="Ch5.S5.p1" class="ltx_para"> | <div id='Ch5.S5.p1' class='ltx_para'> |
<p class="ltx_p">A <span class="ltx_text ltx_font_smallcaps">SaC</span> module implementation essentially looks just like a program, being a | <p class='ltx_p'>A <span class='ltx_text ltx_font_smallcaps'>SaC</span> module implementation essentially looks just like a program, being a |
collection of type, global object and function definitions. Unlike a program, a | collection of type, global object and function definitions. Unlike a program, a |
module starts with the key word <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">module</span> followed by the module name, | module starts with the key word <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>module</span> followed by the module name, |
i.e. the name space, and a semicolon. | i.e. the name space, and a semicolon. |
</p> | </p> |
</div> | </div> |
<figure id="LST42" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST42' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 42: </span>module implementation example</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 42: </span>module implementation example</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,bW9kdWxlIG15bW9kOwoKcHJvdmlkZSBhbGwgZXhjZXB0IHtmb299OwpleHBvcnQge2Zvb307Cgpp%0AbnQgZm9vKGludCB4KQp7CiAgcmV0dXJuIC8qIC4uLiAgKi87Cn0KCmludCBiYXIoeCBpbnQgeCkK%0AewogIHJldHVybiAvKiAuLi4gICovOwp9%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,bW9kdWxlIG15bW9kOwoKcHJvdmlkZSBhbGwgZXhjZXB0IHtmb299OwpleHBvcnQge2Zvb307CgppbnQgZm9vKGludCB4KQp7CiAgcmV0dXJuIC8qIC4uLiAgKi87Cn0KCmludCBiYXIoeCBpbnQgeCkKewogIHJldHVybiAvKiAuLi4gICovOwp9'>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx716' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_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;'>1</span></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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx717' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>2</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx718' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></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;'>3</span></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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx719' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span><span class="ltx_text ltx_lst_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;'>4</span></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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx720' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>5</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx721' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">6</span></span><span class="ltx_text ltx_lst_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;'>6</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx722' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">7</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>7</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx723' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">8</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span><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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx724' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>9</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx725' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx726' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_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;'>11</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx727' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>12</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx728' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">return</span><span class="ltx_text ltx_lst_space"> </span><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;'>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>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx729' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Ch5.S5.p2" class="ltx_para"> | <div id='Ch5.S5.p2' class='ltx_para'> |
<p class="ltx_p">The more interesting aspect of a module (name space) is the question which | <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 | symbols (types, global objects and functions) are made available outside the |
module and which are merely accessible internally within the module itself. Two | module and which are merely accessible internally within the module itself. Two |
kinds of statements using the key words <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">provide</span> and | kinds of statements using the key words <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>provide</span> and |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">export</span> provide fine-grained control over the availability of symbols | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>export</span> provide fine-grained control over the availability of symbols |
outside the current module. By default any symbol defined in a module is only | outside the current module. By default any symbol defined in a module is only |
accessible in the module itself. Using the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">provide</span> statement all or | accessible in the module itself. Using the <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>provide</span> statement all or |
selected symbols can be made available to be “used” by other modules or | selected symbols can be made available to be “used” by other modules or |
programs. With the <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">export</span> statement symbols are made available for | programs. With the <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>export</span> statement symbols are made available for |
either <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">use</span> or <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">import</span> by other modules or programs. The | either <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>use</span> or <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>import</span> by other modules or programs. The |
syntax of <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">provide</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">export</span> statements is very similar | syntax of <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>provide</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>export</span> statements is very similar |
to that of the corresponding <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">use</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_keyword ltx_font_bold">import</span> statements. | to that of the corresponding <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>use</span> and <span class='ltx_text ltx_lst_keyword ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_font_bold'>import</span> statements. |
Either all symbols are provided/exported uniformly, or a specific list of | Either all symbols are provided/exported uniformly, or a specific list of |
symbols is concerned, or all but a given list of symbols.</p> | symbols is concerned, or all but a given list of symbols.</p> |
</section> | </section> |
</section> | </section> |
<section id="Ch6" class="ltx_chapter"> | <section id='Ch6' class='ltx_chapter'> |
<h3 class="ltx_title ltx_title_chapter"> | <h3 class='ltx_title ltx_title_chapter'> |
<span class="ltx_tag ltx_tag_chapter">Chapter 6 </span>Case Studies</h3> | <span class='ltx_tag ltx_tag_chapter'>Chapter 6 </span>Case Studies</h3> |
| |
<div id="Ch6.p1" class="ltx_para"> | <div id='Ch6.p1' class='ltx_para'> |
<p class="ltx_p">This trail will illustrate how to use <span class="ltx_text ltx_font_smallcaps">SaC</span> for real-world applications. The | <p class='ltx_p'>This trail will illustrate how to use <span class='ltx_text ltx_font_smallcaps'>SaC</span> for real-world applications. The |
following exercises make use of the techniques introduced in this tutorial so | 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 | 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 <span class="ltx_text ltx_font_smallcaps">SaC</span> to | with the language itself and at the same time show you how to employ <span class='ltx_text ltx_font_smallcaps'>SaC</span> to |
solve your every-day problems in an efficient way.</p> | solve your every-day problems in an efficient way.</p> |
</div> | </div> |
<section id="Ch6.S1" class="ltx_section"> | <section id='Ch6.S1' class='ltx_section'> |
<h4 class="ltx_title ltx_title_section"> | <h4 class='ltx_title ltx_title_section'> |
<span class="ltx_tag ltx_tag_section">6.1 </span>Lesson 7: Image Processing</h4> | <span class='ltx_tag ltx_tag_section'>6.1 </span>Lesson 7: Image Processing</h4> |
| |
<div id="Ch6.S1.p1" class="ltx_para"> | <div id='Ch6.S1.p1' class='ltx_para'> |
<p class="ltx_p">Digital image processing spans across a vast area of applications. Ranging from | <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 | digital photography over astronomy to surgery-assisting medical imaging, most |
applications still share as their underlying theory some sort of basic signal | applications still share as their underlying theory some sort of basic signal |
originally analogue, continuous version of the signal.</p> | originally analogue, continuous version of the signal.</p> |
</div> | </div> |
<div id="Ch6.S1.p2" class="ltx_para"> | <div id='Ch6.S1.p2' class='ltx_para'> |
<p class="ltx_p">In this exercise we will focus on two basic image filters on static, | <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> | 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"> | <table id='Ch10.S4.EGx1' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'> |
| |
<tr id="Ch6.Ex1" class="ltx_equation ltx_eqn_row ltx_align_baseline"> | <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_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_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_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_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> | <td class='ltx_eqn_cell ltx_eqn_center_padright'></td> |
</tr> | </tr></tbody> |
<tr id="Ch6.Ex2" class="ltx_equation ltx_eqn_row ltx_align_baseline"> | <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_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_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_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{% | <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}}\\ | 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> | 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> | <td class='ltx_eqn_cell ltx_eqn_center_padright'></td> |
</tr> | </tr></tbody> |
</table> | </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 | <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 | <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 <span class="ltx_text ltx_font_italic">pixel</span> at this position. | gray-scale value of the <span class='ltx_text ltx_font_italic'>pixel</span> at this position. |
</p> | </p> |
</div> | </div> |
<div id="Ch6.S1.p3" class="ltx_para"> | <div id='Ch6.S1.p3' class='ltx_para'> |
<p class="ltx_p">A common technique to modify an image is to apply a <span class="ltx_text ltx_font_italic">filter</span> of desired | <p class='ltx_p'>A common technique to modify an image is to apply a <span class='ltx_text ltx_font_italic'>filter</span> 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 | 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 | signal as the one described above. The application of a filter to an image is |
expressed by the 2D (discrete) <span class="ltx_text ltx_font_italic">convolution</span> <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 | expressed by the 2D (discrete) <span class='ltx_text ltx_font_italic'>convolution</span> <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> | signals:</p> |
<table id="Ch10.S4.EGx2" class="ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table"> | <table id='Ch10.S4.EGx2' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'> |
| |
<tr id="Ch6.Ex3" class="ltx_equation ltx_eqn_row ltx_align_baseline"> | <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_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_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_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_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> | <td class='ltx_eqn_cell ltx_eqn_center_padright'></td> |
</tr> | </tr></tbody> |
</table> | </table> |
<p class="ltx_p">With this simple form of filtering, a wealth of image modifications are | <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 | expressible. Depending on the choice of the filter mask we can achieve effects |
such as smoothing, sharpening, edge detection, embossing and many more.</p> | such as smoothing, sharpening, edge detection, embossing and many more.</p> |
</div> | </div> |
<div id="Ch6.S1.p4" class="ltx_para"> | <div id='Ch6.S1.p4' class='ltx_para'> |
<p class="ltx_p">In <span class="ltx_text ltx_font_smallcaps">SaC</span> 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 | <p class='ltx_p'>In <span class='ltx_text ltx_font_smallcaps'>SaC</span> 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 | 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 | 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 | 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"><span class="ltx_text ltx_ref_tag">2.2</span></a>): The filter mask is positioned with its center point over | (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'><span class='ltx_text ltx_ref_tag'>2.2</span></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 | 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 | image and its corresponding value of the filter mask are multiplied. The pixel |
</p> | </p> |
</div> | </div> |
<div id="Thmtheorem29" class="ltx_theorem ltx_theorem_theorem"> | <div id='Thmtheorem29' class='ltx_theorem ltx_theorem_theorem'> |
<h6 class="ltx_title ltx_runin ltx_font_bold ltx_title_theorem">Exercise 29. </h6> | <h6 class='ltx_title ltx_runin ltx_font_bold ltx_title_theorem'>Exercise 29. </h6> |
<div id="Thmtheorem29.p1" class="ltx_para"> | <div id='Thmtheorem29.p1' class='ltx_para'> |
<p class="ltx_p">The <span class="ltx_text ltx_font_italic">Sobel operator</span> is an edge-detection filter that computes the | <p class='ltx_p'>The <span class='ltx_text ltx_font_italic'>Sobel operator</span> is an edge-detection filter that computes the |
gradient image from an input signal. The filtering process consists of three | 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 | steps: In the first step, horizontal edges are detected, in the second step |
combined to the resulting gradient image. The first two steps are in fact two | 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> | 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"> | <table id='Ch10.S4.EGx3' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'> |
| |
<tr id="Ch6.Ex4" class="ltx_equation ltx_eqn_row ltx_align_baseline"> | <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_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\\ | <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\\ | 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> | 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_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\\ | <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\\ | 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> | -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> | <td class='ltx_eqn_cell ltx_eqn_center_padright'></td> |
</tr> | </tr></tbody> |
</table> | </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 | <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 | 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 | 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 | 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 | 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"><span class="ltx_text ltx_ref_tag">6.1</span></a> for an example of | 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'><span class='ltx_text ltx_ref_tag'>6.1</span></a> for an example of |
how an image and its gradient image may look like.</p> | how an image and its gradient image may look like.</p> |
</div> | </div> |
<div id="Thmtheorem29.p2" class="ltx_para"> | <div id='Thmtheorem29.p2' class='ltx_para'> |
<p class="ltx_p">Quite the opposite to edge detection, a smoothing or blurring filter is used to | <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 | 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> <span class="ltx_text ltx_font_italic">Gaussian blurring</span> stencils:</p> | 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> <span class='ltx_text ltx_font_italic'>Gaussian blurring</span> stencils:</p> |
<table id="Ch10.S4.EGx4" class="ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table"> | <table id='Ch10.S4.EGx4' class='ltx_equationgroup ltx_eqn_eqnarray ltx_eqn_table'> |
| |
<tr id="Ch6.Ex5" class="ltx_equation ltx_eqn_row ltx_align_baseline"> | <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_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\\ | <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\\ | 2&3&2\\ |
1&2&1\par | 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> |
\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_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\\ |
<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\\ |
4&20&33&20&4\\ | 7&33&55&33&7\\ |
7&33&55&33&7\\ | 4&20&33&20&4\\ |
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> |
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> |
<td class="ltx_eqn_cell ltx_eqn_center_padright"></td> | </tr></tbody> |
</tr> | |
</table> | </table> |
</div> | </div> |
<div id="Thmtheorem29.p3" class="ltx_para"> | <div id='Thmtheorem29.p3' class='ltx_para'> |
<p class="ltx_p">Write a program that applies these operators to a given image and outputs | <p class='ltx_p'>Write a program that applies these operators to a given image and outputs |
the result for later use:</p> | the result for later use:</p> |
<ul id="Ch6.I1" class="ltx_itemize"> | <ul id='Ch6.S1.I1' class='ltx_itemize'> |
<li id="Ch6.I1.i1" class="ltx_item" style="list-style-type:none;"> | <li id='Ch6.S1.I1.i1' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch6.I1.i1.p1" class="ltx_para"> | <div id='Ch6.S1.I1.i1.p1' class='ltx_para'> |
<p class="ltx_p">Write a function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">apply</span> that takes an image and a filter mask | <p class='ltx_p'>Write a function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>apply</span> that takes an image and a filter mask |
as input and returns the convolution of the two. Use either with-loops | as input and returns the convolution of the two. Use either with-loops |
or axis-control notation to achieve this. Take care of boundary | or axis-control notation to achieve this. Take care of boundary |
</div> | </div> |
</li> | </li> |
<li id="Ch6.I1.i2" class="ltx_item" style="list-style-type:none;"> | <li id='Ch6.S1.I1.i2' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch6.I1.i2.p1" class="ltx_para"> | <div id='Ch6.S1.I1.i2.p1' class='ltx_para'> |
<p class="ltx_p">Write a function <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sobel</span> that takes an image as input and | <p class='ltx_p'>Write a function <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sobel</span> that takes an image as input and |
applies <math id="Ch6.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.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.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.I1.i2.p1.m4" class="ltx_Math" alttext="S_{y}" display="inline"><msub><mi>S</mi><mi>y</mi></msub></math> | 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 | with capping so that this function returns the final result of the Sobel |
operation.</p> | operation.</p> |
</div> | </div> |
</li> | </li> |
<li id="Ch6.I1.i3" class="ltx_item" style="list-style-type:none;"> | <li id='Ch6.S1.I1.i3' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch6.I1.i3.p1" class="ltx_para"> | <div id='Ch6.S1.I1.i3.p1' class='ltx_para'> |
<p class="ltx_p">Write functions <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">gauss9</span> and <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">gauss25</span> that take an | <p class='ltx_p'>Write functions <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>gauss9</span> and <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>gauss25</span> that take an |
image as input and apply <math id="Ch6.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.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> | 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> |
</div> | </div> |
</li> | </li> |
<li id="Ch6.I1.i4" class="ltx_item" style="list-style-type:none;"> | <li id='Ch6.S1.I1.i4' class='ltx_item' style='list-style-type:none;'> |
<span class="ltx_tag ltx_tag_itemize">•</span> | <span class='ltx_tag ltx_tag_item'>•</span> |
<div id="Ch6.I1.i4.p1" class="ltx_para"> | <div id='Ch6.S1.I1.i4.p1' class='ltx_para'> |
<p class="ltx_p">Write a <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">main</span> function that reads in an image from | <p class='ltx_p'>Write a <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>main</span> function that reads in an image from |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">stdin</span>, calls <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">sobel</span>, <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">gaussBlur9</span> and | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>stdin</span>, calls <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>sobel</span>, <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>gaussBlur9</span> and |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">gaussBlur25</span> on this image and then write the results back to | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>gaussBlur25</span> on this image and then write the results back to |
<span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">stdout</span>.</p> | <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>stdout</span>.</p> |
</div> | </div> |
</li> | </li> |
</ul> | </ul> |
<p class="ltx_p">You may want to use the following skeleton for your program:</p> | <p class='ltx_p'>You may want to use the following skeleton for your program:</p> |
</div> | </div> |
<figure id="LST43" class="ltx_float ltx_lstlisting ltx_role_listing"> | <figure id='LST43' class='ltx_float ltx_lstlisting'> |
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_float">Listing 43: </span>Skeleton of sobel.sac</figcaption> | <figcaption class='ltx_caption'><span class='ltx_tag ltx_tag_float'>Listing 43: </span>Skeleton of sobel.sac</figcaption> |
<div class="ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing"> | <div class='ltx_listing ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_listing'> |
<div class="ltx_listing_data"><a href="data:text/plain;base64,dXNlIFN0cnVjdHVyZXM6IGFsbDsKdXNlIFN0ZElPOiBhbGw7CnVzZSBDbG9jazoge3RpbWUsIGdl%0AdHRpbWUsIGRpZmZ0aW1lfTsKCi8qIEhlbHBlciB0byB3cml0ZSBtYXRyaXggdG8gc3Rkb3V0IGlu%0AIHBsYWluIG1hdHJpeCBmb3JtYXQuCiAgIFRoZSBwcm9kdWNlZCBvdXRwdXQgKGxldCdzIHNheSBt%0ALmRhdCkgY2FuIGJlIHVzZWQgd2l0aCBnbnVwbG90CiAgIGxpa2Ugc286CiAgICAgICAgZ251cGxv%0AdD4gcGxvdCAibS5kYXQiIG1hdHJpeCB3aXRoIGltYWdlICAqLwp2b2lkIHdyaXRlTWF0cml4KCBp%0AbnRbLiwuXSBtKQp7CiAgZm9yICh5PTA7IHk8c2hhcGUobSlbMV07IHkrKykgewogICAgZm9yICh4%0APTA7IHg8c2hhcGUobSlbMF07IHgrKykgewogICAgICBwcmludGYoIiVkICIsIG1bW3gseV1dKTsK%0AICAgIH0KICAgIHByaW50ZigiXG4iKTsKICB9Cn0KCi8qIENvbnZvbHV0aW9uIHdpdGggZ2l2ZW4g%0AbWFzay4gICovCmlubGluZSBpbnRbLiwuXSBhcHBseShpbnRbLiwuXSBtYXNrLCBpbnRbLiwuXSBp%0AbWcpCnsKICAvKiBJbXBsZW1lbnQgY29udm9sdXRpb24gaGVyZS4gICovCn0KCmludFsuLC5dIHNv%0AYmVsKGludFsuLC5dIGltZykKewogIFNZID0gWwogICAgICAgICBbMSwgMiwgMV0sIFswLCAwLCAw%0AXSwgWy0xLCAtMiwgLTFdCiAgICAgICBdOwogIC8qIENvbXBsZXRlIHRoaXMgZnVuY3Rpb24gaGVy%0AZS4gICovCn0KCmludFsuLC5dIGdhdXNzQmx1cjkoaW50Wy4sLl0gaW1nKQp7CiAgLyogQ29tcGxl%0AdGUgdGhpcyBmdW5jdGlvbiBoZXJlLiAgKi8KfQoKaW50Wy4sLl0gZ2F1c3NCbHVyMjUoaW50Wy4s%0ALl0gaW1nKQp7CiAgLyogQ29tcGxldGUgdGhpcyBmdW5jdGlvbiBoZXJlLiAgKi8KfQoKaW50Wypd%0ALCB0aW1lIHRpbWVzdGFtcChpbnRbKl0gaW1nKQp7CiAgcmV0dXJuIChpbWcsIGdldHRpbWUoKSk7%0ACn0KCmludCBtYWluKCkKewogIGZwcmludGYoc3RkZXJyLCAiXG5SZWFkaW5nIGltYWdlIGluIEZp%0AYnJlIGZvcm1hdC4uLlxuIik7CiAgaW1nID0gRmlicmVTY2FuSW50QXJyYXkoc3RkaW4pOwoKICBm%0AcHJpbnRmKHN0ZGVyciwgIlxuQXBwbHlpbmcgZmlsdGVyIC4uLlxuIik7CiAgaW1nLCBzdGFydCA9%0AIHRpbWVzdGFtcChpbWcpOwogIGltZyA9IHNvYmVsKGltZyk7CiAgaW1nLCBlbmQgPSB0aW1lc3Rh%0AbXAoaW1nKTsKCiAgLyogQ2FsbCB0aGUgb3RoZXIgZmlsdGVycyBoZXJlLiAgKi8KCiAgZnByaW50%0AZihzdGRlcnIsICJcbkZpbmlzaGVkIGZpbHRlcmluZyBhZnRlciAlZnNcbiIsIGRpZmZ0aW1lKGVu%0AZCwgc3RhcnQpKTsKICBmcHJpbnRmKHN0ZGVyciwgIlxuV3JpdGluZyByZXN1bHQgaW1hZ2UgLi4u%0AXG4iKTsKICB3cml0ZU1hdHJpeChpbWcpOwoKICByZXR1cm4gMDsKfQ==%0A">⬇</a></div> | <div class='ltx_listing_data'><a href='data:text/plain;base64,dXNlIFN0cnVjdHVyZXM6IGFsbDsKdXNlIFN0ZElPOiBhbGw7CnVzZSBDbG9jazoge3RpbWUsIGdldHRpbWUsIGRpZmZ0aW1lfTsKCi8qIEhlbHBlciB0byB3cml0ZSBtYXRyaXggdG8gc3Rkb3V0IGluIHBsYWluIG1hdHJpeCBmb3JtYXQuCiAgIFRoZSBwcm9kdWNlZCBvdXRwdXQgKGxldCdzIHNheSBtLmRhdCkgY2FuIGJlIHVzZWQgd2l0aCBnbnVwbG90CiAgIGxpa2Ugc286CiAgICAgICAgZ251cGxvdD4gcGxvdCAibS5kYXQiIG1hdHJpeCB3aXRoIGltYWdlICAqLwp2b2lkIHdyaXRlTWF0cml4KCBpbnRbLiwuXSBtKQp7CiAgZm9yICh5PTA7IHk8c2hhcGUobSlbMV07IHkrKykgewogICAgZm9yICh4PTA7IHg8c2hhcGUobSlbMF07IHgrKykgewogICAgICBwcmludGYoIiVkICIsIG1bW3gseV1dKTsKICAgIH0KICAgIHByaW50ZigiXG4iKTsKICB9Cn0KCi8qIENvbnZvbHV0aW9uIHdpdGggZ2l2ZW4gbWFzay4gICovCmlubGluZSBpbnRbLiwuXSBhcHBseShpbnRbLiwuXSBtYXNrLCBpbnRbLiwuXSBpbWcpCnsKICAvKiBJbXBsZW1lbnQgY29udm9sdXRpb24gaGVyZS4gICovCn0KCmludFsuLC5dIHNvYmVsKGludFsuLC5dIGltZykKewogIFNZID0gWwogICAgICAgICBbMSwgMiwgMV0sIFswLCAwLCAwXSwgWy0xLCAtMiwgLTFdCiAgICAgICBdOwogIC8qIENvbXBsZXRlIHRoaXMgZnVuY3Rpb24gaGVyZS4gICovCn0KCmludFsuLC5dIGdhdXNzQmx1cjkoaW50Wy4sLl0gaW1nKQp7CiAgLyogQ29tcGxldGUgdGhpcyBmdW5jdGlvbiBoZXJlLiAgKi8KfQoKaW50Wy4sLl0gZ2F1c3NCbHVyMjUoaW50Wy4sLl0gaW1nKQp7CiAgLyogQ29tcGxldGUgdGhpcyBmdW5jdGlvbiBoZXJlLiAgKi8KfQoKaW50WypdLCB0aW1lIHRpbWVzdGFtcChpbnRbKl0gaW1nKQp7CiAgcmV0dXJuIChpbWcsIGdldHRpbWUoKSk7Cn0KCmludCBtYWluKCkKewogIGZwcmludGYoc3RkZXJyLCAiXG5SZWFkaW5nIGltYWdlIGluIEZpYnJlIGZvcm1hdC4uLlxuIik7CiAgaW1nID0gRmlicmVTY2FuSW50QXJyYXkoc3RkaW4pOwoKICBmcHJpbnRmKHN0ZGVyciwgIlxuQXBwbHlpbmcgZmlsdGVyIC4uLlxuIik7CiAgaW1nLCBzdGFydCA9IHRpbWVzdGFtcChpbWcpOwogIGltZyA9IHNvYmVsKGltZyk7CiAgaW1nLCBlbmQgPSB0aW1lc3RhbXAoaW1nKTsKCiAgLyogQ2FsbCB0aGUgb3RoZXIgZmlsdGVycyBoZXJlLiAgKi8KCiAgZnByaW50ZihzdGRlcnIsICJcbkZpbmlzaGVkIGZpbHRlcmluZyBhZnRlciAlZnNcbiIsIGRpZmZ0aW1lKGVuZCwgc3RhcnQpKTsKICBmcHJpbnRmKHN0ZGVyciwgIlxuV3JpdGluZyByZXN1bHQgaW1hZ2UgLi4uXG4iKTsKICB3cml0ZU1hdHJpeChpbWcpOwoKICByZXR1cm4gMDsKfQ=='>⬇</a></div> |
<div class="ltx_listingline"> | <div id='lstnumberx730' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">1</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>1</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>Structures</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx731' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">2</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>StdIO</span>:<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>all</span>; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx732' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">3</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">use</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>3</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>use</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>}; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx733' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">4</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>4</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx734' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">5</span></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' style='color:#BFBFBF;'>5</span></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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx735' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx736' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx737' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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 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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx738' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">9</span></span><span class="ltx_text ltx_lst_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;'>9</span></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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx739' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">10</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>10</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx740' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">11</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx741' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">12</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_keyword ltx_font_bold">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;'>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>{ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx742' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">13</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>]]); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx743' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">14</span></span><span class="ltx_text ltx_lst_space"> </span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>14</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx744' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">15</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx745' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">16</span></span><span class="ltx_text ltx_lst_space"> </span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>16</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>} |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx746' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">17</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>17</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx747' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">18</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>18</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx748' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">19</span></span><span class="ltx_text ltx_lst_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;'>19</span></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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx749' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">20</span></span><span class="ltx_text ltx_lst_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;'>20</span></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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx750' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">21</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>21</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx751' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">22</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx752' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">23</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>23</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx753' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">24</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>24</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx754' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">25</span></span><span class="ltx_text ltx_lst_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;'>25</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.,.]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx755' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">26</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>26</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx756' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">27</span></span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>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>[ |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx757' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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] |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx758' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">29</span></span><span class="ltx_text ltx_lst_space"> </span>]; | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>29</span></span> |
| <span class='ltx_text ltx_lst_space'> </span>]; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx759' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx760' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">31</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>31</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx761' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">32</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>32</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx762' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">33</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[.,.]<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>33</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.,.]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx763' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">34</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>34</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx764' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx765' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">36</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>36</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx766' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">37</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>37</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx767' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">38</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[.,.]<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>38</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[.,.]<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx768' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">39</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>39</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx769' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx770' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">41</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>41</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx771' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">42</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>42</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx772' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">43</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span>[*],<span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">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;'>43</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span>[*],<span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>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>) |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx773' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">44</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>44</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx774' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>()); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx775' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">46</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>46</span></span> |
| } |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx776' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">47</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>47</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx777' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">48</span></span><span class="ltx_text ltx_lst_keyword ltx_font_bold">int</span><span class="ltx_text ltx_lst_space"> </span><span class="ltx_text ltx_lst_identifier">main</span>() | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>48</span></span> |
| <span class='ltx_text ltx_lst_keyword ltx_font_bold'>int</span><span class='ltx_text ltx_lst_space'> </span><span class='ltx_text ltx_lst_identifier'>main</span>() |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx778' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">49</span></span>{ | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>49</span></span> |
| { |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx779' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx780' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx781' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">52</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>52</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx782' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx783' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx784' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx785' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx786' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">57</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>57</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx787' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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> |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx788' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">59</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>59</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx789' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>)); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx790' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx791' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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>); |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx792' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">63</span></span> | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>63</span></span> |
| |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx793' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><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;'>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; |
</div> | </div> |
<div class="ltx_listingline"> | <div id='lstnumberx794' class='ltx_listingline'> |
<span class="ltx_tag ltx_tag_listing"><span class="ltx_text" style="color:#BFBFBF;">65</span></span>} | <span class='ltx_tag ltx_tag_listingline'><span class='ltx_text' style='color:#BFBFBF;'>65</span></span> |
| } |
</div> | </div> |
</div> | </div> |
</figure> | </figure> |
<div id="Thmtheorem29.p4" class="ltx_para"> | <div id='Thmtheorem29.p4' class='ltx_para'> |
<p class="ltx_p">Compile your source code with and without the <span class="ltx_text ltx_font_typewriter">-mt</span> option for | <p class='ltx_p'>Compile your source code with and without the option <span class='ltx_text ltx_font_typewriter'>-t mt_pth</span> option for |
multi-threaded execution and experiment with various thread counts. On faster | multi-threaded execution and experiment with various thread counts. On faster |
machines it might be necessary to apply the filter multiple times (copy and | 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> | paste line 55 a couple of times) to see measurable speed-ups.</p> |
</div> | </div> |
<div id="Thmtheorem29.p5" class="ltx_para"> | <div id='Thmtheorem29.p5' class='ltx_para'> |
<p class="ltx_p">NB: The Fibre format encodes, in addition to the raw data, shape information. | <p class='ltx_p'>NB: The Fibre format encodes, in addition to the raw data, shape information. |
By using <span class="ltx_text ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting ltx_lst_identifier">FibreScanIntArray</span> this program is able process 2D images of any | By using <span class='ltx_text ltx_lst_identifier ltx_lst_language_SaC ltx_lst_numbers_left ltx_lstlisting'>FibreScanIntArray</span> this program is able process 2D images of any |
size and it is not fixed to statically known input sizes.</p> | size and it is not fixed to statically known input sizes.</p> |
</div> | </div> |
</div> | </div> |
<figure id="Ch6.F1" class="ltx_figure"> | <figure id='Ch6.F1' class='ltx_figure'> |
<table style="width:100%;"> | <table style='width:100%;'> |
<tr> | <tr> |
<td class="ltx_subgraphics"><img src="x2.png" id="Ch6.F1.g1" class="ltx_graphics ltx_centering" width="298" height="421" alt=""></td> | <td class='ltx_subgraphics'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASoAAAGlCAYAAABN3LsiAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAACQAAAAkADxRbprAAA2pUlEQVR42u2daYxd51nH/+cu5y7n7nfuLPZ4G4+dZhw7IQmRQtIKqiLSDxEFVLUplRpAQZX4glQEokKVKiEEEkU4pARo05amjVpBKKAiaEjTpEntLiGtnQXb8W7P2LPd/Z6738OH5Hk5c+euM3c23/9PGo1m7nL2//u8z/ssmmVZIISQ7YyDp4AQQqEihBAKFSGEQkUIIRQqQgihUBFCKFSEEEKhIoRQqAghhEJFCCEUKkIIhYoQQihUhBBCoSKEUKgIIYRCRQihUBFCCIWKEEIoVIQQChUhhFCoCCGEQkUIoVARQgiFihBCoSKEEAoVIYRQqAghFCpCCKFQEUIIhYoQQqEihBAKFSGEQkUIIRQqQgihUBFCKFSEEEKhIoQQChUhhEJFCCEUKkIIhYoQQihUhBBCoSKEUKgIIYRCRQghFCpCCIWKEEIoVIQQChUhhFCoCCGEQkUIoVARQgiFihBCKFSEEAoVIYRQqAghFCpCCKFQEUIIhYoQQqEihBAKFSGEUKgIIRQqQgihUBFCKFSEEEKhIoQQChUhhEJFCCEUKkIIoVARQihUhBBCoSKEUKgIIYRCRQghFCpCCIWKEEIoVIQQQqEihFCoCCGEQkUIoVARQgiFihBCKFSEEAoVIYRQqAghhEJFCKFQEUIIhYoQQqEihBAKFSGEUKgIIRQqQgihUBFCCIWKEEKhIoQQChUhhEJFCCEUKkIIoVARQihUhBBCoSKEEAoVIYRCRQghFCpCCIWKEEIoVIQQQqEihFCoCCGEQkUIIRQqQgiFihBCKFSEEAoVIYRQqAghhEJFCKFQEUIIhYoQQihUhBAKFSGEUKgIIRQqQgihUBFCCIWKEEKhIoQQChUhhFCoCCEUKkIIoVARQihUhBBCoSKEEAoVIYRCRQghFCpCCIWKEEIoVIQQQqEihFCoCCFka3HxFADJZNK6dOkSTwTZUcRiMRw4cECjUA0Jx48fx4kTJ9Z/Ml0uOJ1OOBwOuN1uOJ1OuFwuOBwOaJqGpaUlhMNhNBoNNBoN1Ot11Ot1WJaFer2u/m9Z1rr2w7IsFItF+P3+DT931WoVjUYDHo9nw7dlmia8Xi8cDsembMvn80HT+tMBTdNW/dj3V657o9EAANTrdVQqFfh8vr73sdFo4Lvf/S4tqmHBNE08//zz6/oOTdPg8Xjg8Xjgcrng8/lW/O10OrG8vAyv14t6vY5qtYpKpYJqtar+rlarqNVq6iYmOw+Hw6EGK/lxOp3QNA2WZaFWq6lrvV4OHz7MqR/pzYIKBAIIBALw+XzqxpRR1P63mOqWZakfsZ7sP2JlmaYJ0zRRKpUGclNvFzRNg9PpVJbkTsbtdsPr9cIwDPj9fnW95TjtFpbd2pXr3mg0UK1WUSwWUSwW1eC1088LhWobjp66rsPv9yMQCPT0kHZDhKrRaKBSqfQ99dhKAer1AXM4HAOZ4m6H628XK7GkekWmfZZlqSk0oVANBKfTiUAggGg0inA4DKfTOfDvdzqdiMfjiMfjym+Vy+WQzWZRKBRQLpe39CHXNA0f/vCH8eCDD2JiYgLRaBSXLl3CU089hbNnzyKVSrX83MzMDGZmZvCbv/mbCAaDWFhYwOXLl/Htb38bJ0+e3PbC5fF4EAwGEQqFEAgEVlhQa73WPp8PPp8PiURCWVnZbBbz8/OoVCqo1Wp86MDwhL4Q68nn88Hlcm2KtSNTB5fLBa/Xq6y3zXIqt3q4QqEQdu3ahUAgAF3X4XA44Pf7sX//fuzfvx9ut3vV58LhMPbs2YPJyUm43W44HA54PB6Ew2Hs3bsXbrd721qPTqcTfr8ffr9f+Rybp3SDdinIfabr+o6xqmlRbYNpjcPhQCKRQDgchsfj2bSbR3w6wWAQwWBQ+bJyuRzm5uZQKpU21RIJBAK444478Gu/9msrHta9e/fit37rt/Dmm2/iL/7iLzA/P7/ic3feeSceeeQRHDx4UP1vdHQUsVgM+/fvxwsvvIBUKrXt/HEiwiKwLpdrU651IBBAuVxGJpPBwsLCLeWnpEW1QTeP2+2G3+9XlsB2GeV9Pt+mWyJerxd79uzp6LNptdQeCARaTpPl4dy1a9emhDj0e469Xq9aKNlsy0bOp9/vh9fr3VCRpFDtdJPT5VLTk2g0uuWmuFh3gUAAu3btQiQS2dQbeGxsDB/96EdbPrherxehUKilkB0+fLhlXJfT6YRhGHj44YeRSCS21QBlGAbGx8cxOTkJj8czcH9kt+3ruo5oNIoDBw5gdHQUoVBo2wyUnPptM59UKBRCMBjc1Ju0X6uqWq22dWAPEr/fj2Aw2DE4UYS9mVgs1tJ3JUxMTMDr9W4LgdJ1HeFwGF6vd9vsk9/vh9PphNvtRjabRalUolCRdxBnbzAY3JYjmUxNLMvaFKEyDAPBYLBjxLvT6WwpVPF4vKNQbZepn6Zp8Hq9GBkZUdkFW70/MkhIGES1WkW5XKZQDTviGxgfH19TGoUgAX0SGyUR6vIzqH3dLBHdvXs3du3a1fE99XoduVxu1f8XFxcxOTnZ9nOhUAixWAzhcBiZTGZLrrvX60UkEhnoFF8WOizLWvdKoaz+jo2NoVqtbksrn0K1yaOYWCvr8f9IXEy9XketVlP+pZ0a6Ojz+bpOhSRNpJlSqdQxoNHtdkPX9Y5W12ZYqB6PZ015d73eD+sVKhFUySGlUA0xfr8fiUSi7xGrUCigUCigUqmoYD17mkxzoqrL5VI3nEQ493sTihhuF4uqVCrhwoULq/5/8eJFHDt2rONnJyYmsHv3biwtLW36NRdfZCgUWtNgVCgUVDqMRJnbU6PsFrDL5VKiLKuKkg/YK/F4fMMElUK1U07Ku0nF/Y5+9Xod5XIZpVKpa46ehD2IH6TRaMDpdELX9TVNLTbLour2cNTrdRQKhVX/z+fzqNfr6/7+jWK9Fl2tVkO5XEaxWESlUllRDaN5qq7runpdLPd+rSpd1zn1u1U5ceKE9Qu/8Avam2++ab344ov4+Mc/jnA4vEKNYrEY4vF4z45d0zSRyWSQTqf7Cr60LEtZXq38ThLgGQgE2i6Nl0olLC0tIZlMbsr5m56extTUVNvXs9ksFhcXcf369VWvnTp1Cg8//HDH75+amkIul8MPf/jDTbsnHA4HDMPA7t27+3rwU6kUisUicrlcS2FuR6PRUANZs0UnqVm93HvDVmVjaCa5s7Oz1t/93d8BAL7+9a/jAx/4AJ566qlVo5U4vLuJjGVZ6oaTEXRQ1o34ecrlMkzTRD6fh2maKJfLStzEctusiGX7dKUdxWKx7bJ5uVxWZWzaIdOgzcLui+zFepbqFlLVQq77IBBrXL672/3UPKWkRXWLsHv3bm1qasoC3gk7OHjwIIrF4irzPxAIdC04JzfJ/Pw8stnswMXCsizl7xKCwaDK0Bchy2azm1YWJBwOq1W5dszNzWFubq7la0tLS8hkMigWiwgGg219VJvpn5I4tF27dvUUed5oNFAsFjE3N4dCoTDQ8y7XO5VKIRaLIZFItE3ZKZfLSKfTQ+WjGsow11KphK997Ws4cODAKquhmxNbRMI0TVSr1U0b1Wq1mrKkxKrazFIpIpKdkLpKa31d13WV9LsZSGHDXqhUKiiVSjBNc0NraUnJF9M0lb/Lbj3Joky/zndaVDuIRx99FADw6U9/Gv/7v/+Le+65Z8XrgUCg60MiJVfm5+c3tdxKt4d8o6dI09PTXZ2+c3NzmJ2d7fj6+Pg4RkdHW74eiUQQj8cRCASQTqc33DcVj8cRCoV68k1lMhnkcrkN3y/LspDJZJDJZODz+RCNRpFIJNQA2mg0kMlksLS01PcKJYVqh7B//37t3WmUdt9997UcYXuxGkzTRK1WGyofwdjYWNcVyWQy2TFCPpVKdXX867qOsbExZDKZDT2/oVCop+stAazZbHbTo8Gr1SpyuRzq9fqKqWk+nx+6InsMT+hTqEzTRKFQGKqCZpqmYWxsrOvSfTch6kWoJCPg3LlzG3pM/QhVJpNBNpvd9IGpVqshl8shl8utKG89jCVfWD0B/7/a1y02RXwUw5YQCgAHDx5sO/WTrjfz8/MdneHdpobAOyt/Bw8e3FD/iyyadJvml0olpNPpDbfuep0SSobDMEKhsvksujkoG43G0HaJaVdPyn5uyuVyx+lRL342KfW8UUIllkkvtcWkbv12EodhbfzAqd+7N28vkegSDjBMSCG8qampjufn9ddfRz6f7/hds7OziEajHXvm+f1+3HnnnRta5ndsbKyna51Op7cknYfQoiKEUKhubYrF4tD5CMbHx3HHHXd0DYg8ffp0V4sKeCew8fXXX2/7utfrxfT0NAzDGHh1AGkoEY/H2x6LTGGvXLmC5eVl3vQUKrIT0HW9p56FvS6Z1+t15PP5rr6WXgJM1zLt6+ZAtyxLxcexESiFatvRa67XsBGLxTomIgsXLlzoKSC1XRkY+3VwOBw4cOBA11SmfgkEAgiHwx0L2NXrdSSTyYHl8BEK1aaKVD/vu5UIBAIYGxvrKN71eh2Li4s9xfdUKpVVrbRaMTo62nfJm250S5mRVd1isUhrapvBVb8+RGgjm05uV4LBYE9CtbS01JP/rlqtYn5+vqsQjI6ODryGuq7rHdOAJI9zq1KVCC2qrlO6Xkx96Qo8TOJtGAZGRkY6Cs/S0lLPibrVahWLi4td399Lyk5fI/K75Xs6XT+p0EkoVNuWXioRbIeuJJt6c7zbP7AXoeo1CFaEqtv5HhsbG6hF1YtQ0ZqiUG05169ftz73uc9Zp06dst58803r85//vJXJZCyxqMQv0enhkdrWw8LExASi0WjHYy4Wix2d4+2mV1evXu2YirR3796BhihIX7xO+1Uul1t20CEUqk3jueeew8c//nF89atfXVXhUwr0d7Oouo3Itxper7frdFfCDfqdaktdp07C4nK5BuYT7KV+kzjTCYVqy3jkkUfw9NNP46677mpZ4dOyLGSz2Y43qs/ng9vtHhqH+sGDB9vWjhLy+TxOnTrV93d3S7nRdR379u3D/v37B3IswWCwYwxVoVDoq+Y9oVBtCJ/73OewZ88eHD58uG2Fz2Ga1hFCodqG/Pqv/7paZv/0pz+NmZkZfOQjH1k1qnaLBfL7/QMPRNyuHDp0qKNFJdVO33jjjb6/u5eUmwMHDuDQoUPrPg5ZvexkUeXz+aFrk76TGJo4qpmZGW1mZkb93arCZy9L7L2kYdwqiI+qHVLDfS1lb/L5vKqS2m4qPag+f734FaXPHqFQbXt6SToOBAKqROytfGNrmobdu3cjEom0fc/S0hIWFxfXVEjw4sWLME2zo1BNTExgcXFx3cfh8Xi6JlWbpjl0JXw49duh2FtxdxqdvV4vYrHYLe3TisVi8Hq9Ha2RZDK55uan1WoV2Wy2YzhAJBJBLBZbt1B1C0uQzi/M76NQ7QhqtVrX6d+wCVWnY+zWzKGbUOVyuY5+qkgkgmg0uq5VVikz3QkKFYVqx2GaJkzT7PgeaVw5OTnZV/v3nTTt61QjXejUcLQX5ubmWrZ/F3RdRzAYxMTExLqFqp3YWZbFKR+FaudaVR1P2rv11X0+3y2Z/6dpGgKBQNfjWm+vwW6fdzqdcLlcPZWJ7na9ullUZHtDZ3oT+Xwebre7p8hot9uNWCwGwzBQLpdV77darbajI5x7tahmZ2fXbVF1CyiV4NxLly6tSVC6Tf1k2kexolDtOIuq1+aiUtrW6XTC6XSiWCyiWq3eEpHr3brODMKiKpVKPXelWde0gRYVhepWpFAo4Pr169izZ0/XppvA/8dWGYahbvx6va7SMmq1GkqlEkqlklpZ3O4W1Z133qmOp9WDPTc3h6WlpXUl8V64cKHtNgTpSvPv//7vazpvmqZB13X6qChUtx6SnFqtVpU/aq1TDrsPy+l0rlhZlCDDRqOxbVacnE4nPB5P12lvPp9f9z7X63VUq1WUy+W2YuJ0OruKWS/Xotv1JhSqHTn9y+fzSCaTiMfjfUdHS+yOYRirHjKJ0yqXy2qFsVwuo1AobIsHxjAMxGIxBIPBrtbQejtGm6aJdDqN5eXltit7Ho8H09PTa16w6MVH1WvRP0Kh2pbIaO9yuXqaAvb64FiWpbr1SlClpmkrrK2t6sis63pXC8ayrIFYVCLcnWKp7JYpnd4UKtKCVCqlLKBoNDowoRLne/OqmmmaKBaLagVxK5oMxOPxgXad6YZ0pZmenm45RXO5XAiHw4jH42rgIMPH0MRRLS8vW2+++abVaDSsQqFgvfHGG5bVgwqUSiXkcjlkMpmeVwPXirRPDwaDGBkZQSwW2/SqooFAoGvIAADMz8/31HWmG5VKBTdv3ux6XtdTmphWGC2qHcNnP/tZ7Nu3D3Nzc3j++ecxPT2NV199FY8++mjHz8kIrmnaimnaRgmVTDGDwaCqXLCZzvZu7bHsQjWI1TLpStONsbExXLx4kU8sLapbm8cff1y7evUq3G43AoEAHn30UVy7dq3nUT+dTuPKlStYWFhAoVDYlE66fr8fY2Nj2Ldvn7IoNjpGKx6P4+DBg21fr9VqyOVyPffx68ViPX/+fNdzOTU1te7VP0Kh2vY88cQT1h//8R/j5MmTKBaLuHbtGuLxeM9Th2q1CtM0VVzUppi7Lhe8Xi/8fv+GW3NCN2e6nAtpe75eJN6sGxvR4l0YxsaynPptU+666y585StfwW//9m9jYWEBzz77LB577LG+vqPRaKiKAS6XC6OjowgGg13Loax7NHE4EI/HEYvFkM/nUSgUMD8/P/DpYCgUwtjYGHbv3t32Pfl8HqdPnx7YNiuVCq5fv45UKoVIJNJ2dfXo0aP4j//4jzVto5ugUqgoVNuGBx98UHvwwQeVv+Po0aO8+oRQqG5dZPozOzurLB5d11XpXJk+ud3ugVpamqYhGAwiEAggHA7jypUrAw1hmJ6e7rril8vlBmpRCadPn8bP/dzPtS2UNzk5iUQigWAw2HfaTqfzI+EiEt9GKFS3NJJ2Y68hLkKladqq3+JvWeu0w+FwwOfzqVSfQTxkIrKdWEsfv17oJYDU6/XC5/P1JVTSs5FTPwoVRarRQKVSWbVcLwmx4hTXdR0ej0eVkVlPWojH48H4+DgcDgdSqdRAHPyTk5Mda6QD/XdG7pVLly7hrrvu6vie8fFx7N69GwsLC30JVacmEpqmDSzrgFCoduwUUVJhGo0GyuUyisUiHA4HstksdF2H2+1WKSL9NjeVEiiapvX18LZDamu1o1qtolgsrrlOeid6icuKRqM9r9Ta6Sbi7OdIoRp66vW6qhLQaqrl9/vh8XgQCAT6bmHucrkQCASg6/rAhKpT7adarbahQtUtPSYajfbd7EGSjjtZp4NsHU8oVLccEpsl/fEKhQJ8Ph88Hk/P6SIOhwMulwt+vx+lUmnNicxutxvhcLhjVc9UKoV0Or0h5yKZTKoYtXbVDtZiUYlV20moaFFRqEiXKYn9IdJ1XSU/9ypUsmJlGAYqlcqahUrXdYRCoS0TquXlZdVXsZ1QRSKRNU39upVxGZaGsjsZNnfYZhZWMpnE7Owsrl69ilwu15OTXNM0xOPxvn1c9s8fOHCga92t9dZI78bNmzc7fv/IyAhGR0f7Sk7utYKnCD6hRUV6eKiq1aqqLBoMBnu2kKQb8FqRGumdHtb11kjvhpRr7mT1des12Oqcdoujkt+MpaJFRfqkUCjg0qVLuHz5sgos7fSwOZ3Orj6mtjeBw4E777wTfr+/4/suXLiwoRUMLl68iLfffrvjfhqGgaNHj/Ysyr1aVBJGQihUhBBCoboVyefzWFhYwOzsbNeyKj6fb03Bi5qm4dixY20tKpmSXrp0CVeuXNlQi+r8+fMd3+P3+3Hs2LG+prkSy9ZpWicNLQiFiqwDWdHr9LCttQyMw+GA3+/v6PsxTXPDK5xKn79OxynTv37ZqHNHNoehGkJeeeUVS+qR/+QnP8EnPvEJ3Hbbbdv+7rQsC6lUCvF4HC6Xq62grMUqkDisvXv3dvzs1atXlYhsFPPz8xgZGUG9Xm+7L16vd01daarVasfjkwwBQotqSykUCtbf//3fY35+HqdPn8Yf/dEf4Z//+Z931DF0a17qdDr7tgwMw8DIyEjHFT/LsnDz5s0Nb9QpOZNLS0vtR1aXS+1vP3SLpfJ6vRQqCtXWc/z4cczMzODy5cuwLEulruwkpJ3WZguVWDuDKD3czXIsl8tYXl5uKyoulwuJRKLvuKdu7cckWZxQqLaUD33oQ5icnATwTuOET33qU7j77rt31DGUy+WupVCcTmdfD1wv7bEsy8L58+c3NIZK6FZDXXLz9uzZ01dj2GKx2PHc6brOEIVtzNBclZmZGW1mZmZHH4NUYeiEBC72iq7rHRORbVPnTWmI2mg0OtZQl+Pr5vzvd+rncDjUD6FFRdZBr63H+xGqeDyOAwcOdLSmGo0GLl68uO4W7oOwqISpqamuAarNQtvNGnW73ex0Q6Ei62UjQgN66TpjWVZPD/qgxLjXrjT9TNO6+ajEqmIlBQoVGYBQ9dJRpZ/py9jYGI4cOdL29VQqhUuXLm3a1M80TZw+fbprzNaRI0cQDAb7EqpuuYo+nw/xeJzTPwoV2Wj6DVrsVliuUqlsSI30bvvTrbZWr9Pg5s90q00ljToIhYqsQ4R6EaJ+xErKC7djeXl5Q2qkdxKqUqmEmzdvdqz4aZpm31PRUqkE0zQ7nje3202rikJF1nWxeoiR6rfVvHTO6SQaG1UsrxPLy8sdA0y7hRu0O1aZUnY6R/buQYRCRfpE1/Wuzl5p29UruVwO8/PzbYVqdnYWp06d2vRjPXnyZEeBvHbtWt9xXcViEfl8vqNIOZ1ORCIReDweOtYpVGQtuN3ujg+PhBL0I1Rzc3M4depUy6nUmTNncP78+bZCtpGcOXMGly9fXrXtarWKhYUFXL58uW+hkvrp3XxumqYhHA73Ff5AKFSkaUrS6UGUrjdrEapm5/WZM2fw9ttvb4lQnT17FpcvX17VXccuVJ38TZ3OTyerSvyAkUiEQrWNYL7ADsHn83Utw1sul/tuRJpKpWCaJv78z/8c999/v2oSsbi4iJMnT+LatWtbdsz//d//jdOnT+PIkSPYvXu3ygP8wQ9+gGQyuaamq/V6HclkUtWYbyf8uq4jGAyiWq1ieXmZNyCFivR0od4t79LJoupWc6kVUqP97Nmz2LdvH4LBIMrlMq5fv44bN270bbUMkvn5eRSLRZUuUywWsbCwgLfffnvNwa9SBLCX4E+3281QBQoV6QWph55IJLpGYq/FohLy+Ty+973vwel0qioGvUSIbySVSgXpdBo/+9nPcPbsWTQaDVSr1XVH6FuWpayqTjXmdV1HOByGaZrIZrNb1vjB5/OtGKRyudzQNaGgUO0QsfJ4PF2Xy9diUQm1Wg2Li4vb6rjF+slkMshkMgMXwV6tqq0s/yIDlX2aOozdcoZGqL7zne9YL730Eu6//37UarWWFT5dLhcMw1CtpySTv1QqbUqeW6sRfXR0FJFIpOMURG7aTCbTd+KwYRjw+Xwdi9VtJ6QUcTgcxtLS0poTpVOpFDweDxqNRsfqEW63G3v37oVhGMjlchvSzr6dFWUYBuLx+IpcTMuyMDY2hitXrgxVUOrQHOlrr72GQCCAAwcOtK3w6fV64fV64fF4oOs6PB4P/H4/DMOA3++HruubdnO4XC7VrKGXwMNqtdp3WonH48HExATe8573YM+ePdveH+N0OhEIBHDo0CEcOnQI0Wh0XcUPK5UKyuVyT5ao2+2Gx+NR07CNFGKv1wu/3w+v19vyfpM0n2GK8xoai+rDH/4wotEo/uzP/gzBYHBFhU/J8RodHUUwGFx1A9RqNeUvyeVyG25haZqGYDCIiYmJnqZ8lmUhl8uph65XRkdH8fDDD+P9738/XnnlFTz99NMb2gl5vfj9fhw8eBC///u/j0gkgi9+8Yt47bXXcP369TV9XzqdRqlUQigU6ur/C4VCatC6efMmCoXCwKdfDocDPp8PY2NjLe9D+7Rv2LrmDM2RPv/887h48SImJyfRaDTwqU99Ch/60IfUDRKJROD1eluKgvgqgsEgdF1HpVJBtVpFpVJR5YH7jV9qvvlcLpdaZXK73QgEAj3diJIOksvl+hKpkZERvPe978Xhw4fh9Xpx+PBh3H///fjxj3+8pSEJnaao999/P26//XZ1re677z4Eg0F85zvfWdPUVQJAU6kURkZGug4IDocDHo8H8XgcPp8P1WoV5XIZpVJpzaKlaRp0XYff74fb7VZWfad98Xg8CIVCQ7UiOTRC9clPflLrdAOKH6idqW0XK7lBxX9VLpdRqVTWJFQSYOh2u+H3+xEIBJTp388Dl8vlet6+pmlIJBJ43/veh0OHDkHXdRw+fBjJZBI3b97clkIVCARw//33484770Q0GgUA3HfffUgkEvif//mfjnXWuwlVOp1GPB7vyeLxeDzweDwwDAPFYhGZTGbN116uhcfjUdPYXssrD1suIlf9bBe+n/fKaObxeJQ1JX4i8XnYk1/lt0wznU6nalAgLavEourHpC+Xyz3VUrc/8KFQCA899NCqbi6Tk5O45557oOs6XnrppU2pP9XLuTYMAw899BD27t27QsClI81DDz2EbDaLpaWlvjvlSMv3XC6nrJlefYhi+Xi9XmVZy2/79bYLSvP1dzqd8Hg8XYN521nSFKohot9ic3KDNZvetVoN1WpVVZOUH/tNJTepdD1Zb53uSqXSV1G7YDCIXbt24YMf/KBa3bQL1b333ot4PI6XX355WwiV0+lEKBTCr/zKr2B0dHSF81xKsjz00EN4+eWXkcvl1ixUkv/Xj1DJgocMGLVaTVnYzQNTs0jJ9e91saTVfg8TFCr8fzLvIB4qmcY130zNI2y/4tiKVCqlUmB6Ye/evfjlX/5l3HfffdB1veUDMj4+jnA4jMceewz/9m//hhs3bmzZQxGNRrFv3z587GMfQyKRaBnPJKtkv/u7v4tvfetbeOutt3D16tU1nctKpQLLshCJRNS16hVpYKrr+qp7qfl75NqvVaDq9ToWFxeHqr0XhWrAltlmLhmLQ79XK8Lv92NiYgJTU1Nt99Pn88Hj8WBqago+n29LgwslMvzw4cNtVz/lnE9NTSEej685kVj8jmttsiqDzmZcf8kcWGsWwo50zVBe3klUnZ2d7Xt5fyuQNJILFy5gbm6ur1y8X/zFX8TMzEzX6Y2mabj77rsxMzPTk5N5Iy2qRCLRU210r9eL8fFxTExMrHl7xWIRc3NzOHfuHEql0rYTgmq1inQ6jXPnzqFYLA7V9I9CRQjh1G8n0Gg0UCwWcfHiRSQSia4pK1uFlF9Jp9Md64m34wtf+AKuXr2K973vfXjggQc6ToH+5E/+BGfOnNnSxOQzZ87g2rVruHr1Kj772c+2jAoXq+L48eN45ZVX1l07S1qDnT17FsFgEIlEAqFQaEvvTakhXyqVNqW3Ii2qHSBY5XIZpmmiUCgoP8BWTgdlxbBSqaBYLPaUTNvpu5LJJC5duoRUKrVqalOv17G0tIQLFy70FZe10dPybDaLixcvrlrdlPNy9erVNYUmdENabJmmuaYUpfUed7VaVQ0ptvo+pEW1zXwAi4uLWF5ehtvtRjgcRigUgs/n29IE0EajgUwmg4WFBbUytdbv+dGPfoTXXnsNExMTuPfeexEOh9Xr5XIZr7zyCr773e/i3Llz2+KalEolnDlzBl/4whfwO7/zO7j99ttViIJlWVhaWsIzzzyDV155ZaDCKgnppmnCMAyMjIzA6/X2HJC5XmTATKfTyGaznPpRnlpbHrVaDYVCAbVaTaW1SOyLxNAA2JDoYFmClvSMarWKfD7ftSlnP9/94osvwu/347bbbkM0GkWlUsHJkydx+vTpVeV/twM3b97EiRMnkEql8MADD8DlcuGNN97AuXPn8Pbbb2+YtSFWWzqdVveAPWF4UANYo9FAvV5XlrNYcWuZ4lOohkiopLV4oVBQwZ2SmCpRxBuZwlCr1WCaJjKZjDL9BzmteOmll7Bv3z6Mjo4qoTpx4gROnz69aaVM+hWqH/zgB0ilUvj5n/95OBwOvP7663jttdfw9ttvb+i2JQREMhJisdiaAzW7DY6maWJ5eXnoVvUoVAN6sMvlMpLJJDKZzIrcP7G2dF1XpTfsAX1yM8vIKz6n5ih2+VvyxsQnslG+Ccuy8F//9V/I5XI4cuQIfvzjH+PUqVPbepoxPz+PcrmM48ePIx6P49VXX93Uag+NRgOVSgVLS0tIp9OqoJ1ce0mDcrvdq1Ko5BrK/yTtqlKpKKtZrKpBVDGlUA0pkg5TrVbV/3RdV7l9EngoImW/0ewjr9yo9ptSfttv2s1wZM/Pz2Nubg4jIyM4f/480un0tg4iLJfLSKfTOH/+PLLZLBYWFpDL5Tb9PrBbWG63W4lQo9FQKTL26yyv2cVLmqGKs5xTPAqV3CjW6dOnsX//frjdbly6dAlHjhyBtg77XQSlWCwqK0u+rjkRVX7bb1a5kZv/3szVnbfeegtXrlxRKSTbnUqlgtnZWSwsLGxp4wm7aNXrdZim2TI1plUaVasBi1CoAABf+9rXUKlU8MILL2B+fh7T09N49dVX8eijj67bl7WTb7RsNrujVpUsy0KxWOy7+ehG7s8wpbJsFUMTR3Xq1ClVmTEQCODRRx/dlnWXCCFDLFSxWAy/93u/B9M0USwWce3atS3NYyOEcOq3ik9+8pN46qmn8LGPfQwA8Oyzz+Kxxx7jHUAIhWr7EI/HtT/4gz9Qfx89epRXnxBO/QghhEJFCKFQEUIIhYoMEVNTUwiFQkNV55tQqMgOwzAM1XWHEAoVIYRCRQghmw2rJ/SArusIBALIZrMqr8vhcKxo7y75fn6/H7quI5vNwuv1qiRjSfj1er3QdV2VubUsC5qmwTCMFeU9PB7PitK7Pp8PbrcbpVJJfZeUFXE6naqBZjNSP0s6Osvnpfa2lCUxDAMOh0Nl9WcymdY3jMul2s5L1Qcp6tcL0lDU6/WqShGt8vb8fr+qkV6v15FOp1fkVDqdTtXOq1AoIBKJwOl0qmqotVoNPp8Puq7D5/OhUCigWCyu2k9N0+Dz+WAYBoB3SvrkcrkVVTJ6OR6ppFEqlVZcC/l+ewPaYDCIbDaryvx4vV4EAoEVzVCDwaAq3khoUfV2kt4t5+F0OlV2vNPpVKIjDQc0TVO1iSzLUvWK7A5kXdeVcNiz7D0ez4oyMdIu3P69Xq93xXfJd7frJSfbcblcShBln+zCY98XKRJo3759H0Uw231fJ6RCpsvlgqZp8Hg86m/7gy3bl/PhdDrh9/vV5+Sa6Lqu2qFLeRXpXmyvxirnovlcybHLsdq31UthRNmWbEP2yd6OTNO0FduRpiFyneU7mu+r5mtNi4p0xePxIBqNolarIZfLwbIs+P1+jI6OolAoqJFQ6qwbhoGFhQUlFNLZBADC4TDi8TiKxSIKhYKqazQ+Po65uTmUy2U4HA5MTEwgm82iXq9D0zQkEgkYhoGbN2+iWCyi0WggGAyqekitLKCxsTElmtlsFg6HQ9X8ljpOgUAA0WgUuVwOjUYDPp9PjfCyP/IQjo+PK0sql8upksxOp7OnagbhcFgVCKxWq4jFYrAsC/Pz80ilUurhj8fjiMViyoL1eDwYHR3F7OwscrkcarUa3G43otGossxM01TF60ZGRpBOp5XjvlarYXx8HEtLS8jlcsriCQQCMAwDkUhkxfbHx8dx8eLFrk0+g8EgxsbGlOXjdrvh8/lUwwm5duFwWDVGlcqxImq6rmNychLLy8toNBrweDwYGRmBYRhIpVJIp9N8AClUvSEVPl0ul7r5PR6PeohlRBVRkKlZpVJZMTKKJVKpVNSILaOow+FQD7CM+i6XC5VKRbWJl+/VdR2lUkm1D29VR0pG8kqloqY99oqjgkwvy+Wy6sBbKBQwMjKiPm9ZFgKBABwOByqVCjKZjBJUAD3Xz5KuKoVCAfV6fYUFlEql1HEGAgEkk0mYpqnqfYk1ZhdlKVCYyWRQKpXgdDqV1edwOFTdcRFgsVTz+byaOuq6jqWlJVXbSoTXMAxomtZxSi3TvWQyqa5puVxGNBqFx+NZ1YijXC4jm82qwnterxd+vx+ZTEYNFGJZrbXjM4VqiBExsC+vy40oD5tdqMS/ISIj5r79dXlw5MfpdCprw14xVLan67qyyuxCZfdZNQuV2+1WnUzaWQamaa4qQOdwOLB7924lpiJUmqapksxrQRoXiNCIWAQCAbVd8YFdu3ZNiadYLzJFlc/LvsnDL7688fFxaJqmKmU0++rs29Z1HdeuXVPnR6ayhmGgXq/3LFR2MRofH1eiavd1NZ87v98Pv9+PxcXFFUIl9wkZQqF66623rIWFBfh8Ptxxxx19VfgUiyoYDCprR9d15HI5GIah/me3mMSCsCxLCZFYQOVyWQmc3fJpHn2lHreIW7lcVr4d+c52FpV8xuv1YmRkRE0zRQjtfha7n8Re612EstFoQNf1rl1RxM9mFyZ7xVIRYvt5lYfTvi9SK775fBiGscKfJd9rd7JLMcPm/ocyDbMLv1x6wzDUe8UfKZZVJ3+b7FfzoCbWt9PpXDFoNQ8Wcg3tgixWLYVqiC2qxcVF/OQnP8G//Mu/9FXhU4QqHo+retgejwcifGJ5yAgrwiEPm12oRMjs/h2Xy7Vixc/+HhG3Wq2mplu6rvckVJVKBYZhKOdwPp9fVerY5XLB6/UiFoupqa1dqORhlpXMTuWK7c5iu1jahcr+sMq+iCA4nU61ytdcNbVcLiMQCKwQqnYVVuWc2I+zVqutECrpIiMrrmKhiSXaaZHCPt1vPh+y7WahkxU+u8Ur+2MfpChUbRa0huVAZ2ZmtCtXruAP//AP+67wKX4SERsRikqlom4qn88Hv9+v2sPbb9ByuazMfGlsWSgU4PF4YBgGvF4vTNNc0anENE3VQ06W18UJK/+TB7/dTb2wsIAbN25gYWEBmqZhZGQEu3btwsTEhLKAIpEIEokEkskkbty4oVqoy8Pfrv53u4dXHnJ50Fs1tmiHvLfde5qN31bva65F3+79Mm0UC0h6KBaLReTzeTUdW+u+Nu9vq/0htKhWUSqVrFqthpGREa1YLFr9VPiUkVvMdfEhiUUgoQhibdlHcnmPjLB2K8DeXqt5FK3X68pn02w5iDXW7eaXaYllWco/Y/ez2YXXHg8mD3G/D2ZzQ85WzvteBGgzab5e9mvGWugUqk2nWCzigx/ |