<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://web.resource.org/cc/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
  <channel>
    <title>RSS feed for Data and processes in computing</title>
    <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-0</link>
    <description>This RSS feed contains all the sections in Data and processes in computing</description>
    <generator>Moodle</generator>
    <copyright>Copyright © 2016 The Open University</copyright>
    <image>
      <url>https://www.open.edu/openlearn/ocw/theme/image.php/_s/openlearnng/core/1626779889/i/rsssitelogo</url>
      <title>moodle</title>
      <link>https://www.open.edu/openlearn/ocw</link>
      <width>140</width>
      <height>35</height>
    </image>
    <language>en-gb</language><lastBuildDate>Thu, 26 Aug 2021 15:36:37 +0100</lastBuildDate><pubDate>Thu, 26 Aug 2021 15:36:37 +0100</pubDate><dc:date>2021-08-26T15:36:37+01:00</dc:date><dc:publisher>The Open University</dc:publisher><dc:language>en-gb</dc:language><dc:rights>Copyright © 2016 The Open University</dc:rights><cc:license>Copyright © 2016 The Open University</cc:license><item>
      <title>Introduction</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-0</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;This course provides an introduction to data and processes in software, and provides a basis that enables these fundamental ideas to be developed in a clear and precise way. It has two main aims. The first is to illustrate how we can describe ways in which data may be structured and processed. The second is to introduce you to some vocabulary and concepts that help us to do this. The material is accessible to anyone with a little experience of the use of symbols in presenting ideas.&lt;/p&gt;&lt;p&gt;Section 1 provides a brief introduction to the course. It contains some new language that will be explained more fully in later sections. Read this section without spending too much time on it. The most important material in this course is that in Sections 2 and 4. Section 3 includes some ideas that are relatively difficult. You should read this section, but do not spend a great deal of time on it. Section 5 is of a similar length to Sections 2 and 4.&lt;/p&gt;&lt;p&gt;Overall, do not allow yourself to spend too long on any section while you are studying this course. You can always come back and reread material here if you find later that you need a more thorough understanding of some point.&lt;/p&gt;&lt;p&gt;This OpenLearn course provides a sample of Level 2 study in &lt;span class="oucontent-linkwithtip"&gt;&lt;a class="oucontent-hyperlink" href="http://www.open.ac.uk/courses/find/computing-and-it?utm_source=openlearn&amp;amp;utm_campaign=ou&amp;amp;utm_medium=ebook"&gt;Computing &amp;amp; IT&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-0</guid>
    <dc:title>Introduction</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;This course provides an introduction to data and processes in software, and provides a basis that enables these fundamental ideas to be developed in a clear and precise way. It has two main aims. The first is to illustrate how we can describe ways in which data may be structured and processed. The second is to introduce you to some vocabulary and concepts that help us to do this. The material is accessible to anyone with a little experience of the use of symbols in presenting ideas.&lt;/p&gt;&lt;p&gt;Section 1 provides a brief introduction to the course. It contains some new language that will be explained more fully in later sections. Read this section without spending too much time on it. The most important material in this course is that in Sections 2 and 4. Section 3 includes some ideas that are relatively difficult. You should read this section, but do not spend a great deal of time on it. Section 5 is of a similar length to Sections 2 and 4.&lt;/p&gt;&lt;p&gt;Overall, do not allow yourself to spend too long on any section while you are studying this course. You can always come back and reread material here if you find later that you need a more thorough understanding of some point.&lt;/p&gt;&lt;p&gt;This OpenLearn course provides a sample of Level 2 study in &lt;span class="oucontent-linkwithtip"&gt;&lt;a class="oucontent-hyperlink" href="http://www.open.ac.uk/courses/find/computing-and-it?utm_source=openlearn&amp;utm_campaign=ou&amp;utm_medium=ebook"&gt;Computing &amp; IT&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Learning outcomes</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section---learningoutcomes</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;After studying this course, you should be able to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;understand ways in which data may be stored and processed&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;distinguish between different forms of data, and use notations introduced in the course to show different forms of data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;appreciate that fine details may be important when interpreting formal notation (for example, different types of brackets may be used to distinguish between different forms of data)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;interpret a given function description&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;recognise correct syntax in formal expressions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section---learningoutcomes</guid>
    <dc:title>Learning outcomes</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;After studying this course, you should be able to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;understand ways in which data may be stored and processed&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;distinguish between different forms of data, and use notations introduced in the course to show different forms of data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;appreciate that fine details may be important when interpreting formal notation (for example, different types of brackets may be used to distinguish between different forms of data)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;interpret a given function description&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;recognise correct syntax in formal expressions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Key ideas</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-1</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;In this course, we will take an introductory look at two key ideas: &lt;b&gt;forms of data&lt;/b&gt; handled by a software system, and the &lt;b&gt;processes&lt;/b&gt; that may be applied to that data. These ideas are illustrated by a particular application &amp;#x2014; a supermarket till &amp;#x2014; but they are of general relevance in designing software systems. Important terminology will be highlighted in &lt;b&gt;bold&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;In this course we will look at some commonly occurring forms of data. We start with fundamental forms, such as numbers and characters (which are symbols that may be typed at a keyboard). We then go on to look at more complicated data structures.&lt;/p&gt;&lt;p&gt;A second crucial feature of data is the processes available to handle it. The processes needed in any particular application are a particular focus in software design. Here, we shall look at how in principle we can describe a process that manipulates data. This initial description will not be concerned with how the process is executed, but only with its effect.&lt;/p&gt;&lt;p&gt;This course will introduce two important mathematical ideas that help in offering clear and precise descriptions of software components relating to data and processes. These ideas are &lt;b&gt;set&lt;/b&gt; and &lt;b&gt;function&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Section 1 gives a brief introduction to how data and processes may arise in an application situation. Section 2 is concerned with fundamental forms of data, and the mathematical idea of a set. Section 3 looks briefly at some more structured forms of data. In Section 4 we look at processes, and the mathematical idea of function. Section 5 is concerned with processes of a particular sort. Examples of these processes are the addition of numbers (as in 5 + 6) and a comparison of two numbers (as in 3&amp;#xA0;&amp;lt;&amp;#xA0;5).&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-1</guid>
    <dc:title>Key ideas</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;In this course, we will take an introductory look at two key ideas: &lt;b&gt;forms of data&lt;/b&gt; handled by a software system, and the &lt;b&gt;processes&lt;/b&gt; that may be applied to that data. These ideas are illustrated by a particular application — a supermarket till — but they are of general relevance in designing software systems. Important terminology will be highlighted in &lt;b&gt;bold&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;In this course we will look at some commonly occurring forms of data. We start with fundamental forms, such as numbers and characters (which are symbols that may be typed at a keyboard). We then go on to look at more complicated data structures.&lt;/p&gt;&lt;p&gt;A second crucial feature of data is the processes available to handle it. The processes needed in any particular application are a particular focus in software design. Here, we shall look at how in principle we can describe a process that manipulates data. This initial description will not be concerned with how the process is executed, but only with its effect.&lt;/p&gt;&lt;p&gt;This course will introduce two important mathematical ideas that help in offering clear and precise descriptions of software components relating to data and processes. These ideas are &lt;b&gt;set&lt;/b&gt; and &lt;b&gt;function&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Section 1 gives a brief introduction to how data and processes may arise in an application situation. Section 2 is concerned with fundamental forms of data, and the mathematical idea of a set. Section 3 looks briefly at some more structured forms of data. In Section 4 we look at processes, and the mathematical idea of function. Section 5 is concerned with processes of a particular sort. Examples of these processes are the addition of numbers (as in 5 + 6) and a comparison of two numbers (as in 3 &lt; 5).&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>1.1 Number sequences</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Imagine that you are at a modern supermarket and the cashier is processing the items from your basket or trolley. The electronic till (which is a form of computer) records each item that you have bought. Most items are scanned using a device that can read the barcode printed on the item.&lt;/p&gt;&lt;div class="oucontent-figure" style="width:511px;" id="fig001"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7400f745/m263_1_001i.jpg" alt="Figure 1" width="511" height="54" style="max-width:511px;" class="oucontent-figure-image oucontent-media-wide"/&gt;&lt;div class="oucontent-figure-text"&gt;&lt;div class="oucontent-caption oucontent-nonumber"&gt;&lt;span class="oucontent-figure-caption"&gt;Figure 1 An example of a barcode. Today, nearly every product has a barcode, although not all stores use them. A laser scanner is used to convert the pattern of light and dark bars into a number stored in the till. The number, printed as part of the barcode, may be entered manually if an electronic scanner is unavailable. A computerised till uses this code to look up the price that a shop wishes to charge for the item.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Items that need to be weighed (such as loose fruit and vegetables) do not have a barcode printed on them. Instead, the cashier looks up a different sort of code for these items and enters this manually at the till, together with the weight of the item purchased. If an error is made, the cashier may cancel the item just entered and try again. When all the items you have purchased have been processed, your final bill is calculated and you receive an itemised receipt (Figure 2).&lt;/p&gt;&lt;div class="oucontent-figure" style="width:511px;" id="fig002"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/62109d25/m263_1_002i.jpg" alt="Figure 2" width="511" height="584" style="max-width:511px;" class="oucontent-figure-image oucontent-media-wide"/&gt;&lt;div class="oucontent-figure-text"&gt;&lt;div class="oucontent-caption oucontent-nonumber"&gt;&lt;span class="oucontent-figure-caption"&gt;Figure 2: An example of a supermarket till receipt. (Note the two weighed items.)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Let us look a little more formally at some of the data that the supermarket computer system must store and use. As we do this, you will begin to get a flavour of the rigour that underpins the design of modern software. You will meet new vocabulary and concepts, try to get a general sense of what each new term means.&lt;/p&gt;&lt;p&gt;Each type of item stocked by the supermarket needs to be identified. As we have seen, this is done either using barcodes or, for weighed items, item codes of a different sort. Associated with each code is a variety of other item-related information. Perhaps the most obvious information is the price, and the description that appears on the receipt. (In the case of weighed items, the price is a unit price, giving the price per kilogram, for instance.) Other information associated with any item code might include the current stock level (so that new stock can be ordered as items are near to being out of stock), the name and address of the supplier, discount rates for multiple purchases, etc&lt;/p&gt;&lt;p&gt;Barcodes such as 5000119004048 can be interpreted as whole numbers. Whole numbers are called &lt;b&gt;integers&lt;/b&gt;. Integers may be positive, negative or zero. (The codes for weighed items are also usually whole numbers.)&lt;/p&gt;&lt;p&gt;Prices and weights are not ordinarily presented as whole numbers. In &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt;, the item price of walnut bread is shown as &amp;#xA3;1.49; the unit price of organic courgettes is &amp;#xA3;3.49 per kg and the weight of organic courgettes purchased is 0.41 kg (kg is the standard abbreviation for kilogram).&lt;/p&gt;&lt;p&gt;A number with a fractional part such as 1.49 is an example of a real number. The real numbers include numbers such as 3.497825 (and numbers such as &amp;#x221A;2, which cannot be expressed exactly as any fraction or decimal). Computers cannot represent such real numbers exactly. When dealing with a real number, we can only rely on a computer storing and manipulating an approximation of the number. Even though the extent of the approximation may seem small, this can present problems to the unwary software developer. To avoid problems here, we will represent prices as a whole number of pence, and weights as a whole number of grams. So, for example, the bill in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt; includes a purchase of 335 grams of walnuts at 299 pence per kg.&lt;/p&gt;&lt;p&gt;As the items in a basket or trolley are scanned one after another, the till stores a &lt;b&gt;sequence&lt;/b&gt; of codes. We use a precise notation to indicate a sequence. Suppose that the item codes scanned so far are 50773, 50412, 50330, 33777, 50773. If the codes were scanned in this order, then the till would store the sequence [50773, 50412, 50330, 33777, 50773]. If the same codes were scanned in a different order, then the till might store the sequence [50773, 50773, 50412, 50330, 33777]. Barcodes normally contain more digits. In our illustrative examples, we shall use shorter codes that are easier to read.&lt;/p&gt;&lt;p&gt;A sequence is a collection of items in a particular order. We shall write the items in a sequence between square brackets [ and ], and commas are used to separate the items in it (in other texts, you may see angled brackets &amp;#x3008; and &amp;#x3009; used to show a sequence, rather than [ and ]). These items are called the &lt;b&gt;elements&lt;/b&gt; of the sequence. The order in which items appear in a sequence is important, so that [50773, 50412, 50330, 33777, 50773] is not the same as the sequence [50773, 50773, 50412, 50330, 33777]. Of course, the order in which the cashier checks your purchases does not matter in terms of the final cost. But, while the items are being entered, the order will often matter. For example, if an error occurs in scanning or weighing, the last item entered can usually be corrected using a &amp;#x2018;Cancel Last Item’ key on the till. Also, the itemised bill that you receive usually gives the items in the order in which they have been processed.&lt;/p&gt;&lt;p&gt;Item descriptions in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt; include &amp;#x201C;ORGANIC SOUP&amp;#x201D; and &amp;#x201C;OLIVE OIL&amp;#x201D;. These descriptions are formed from &lt;b&gt;characters&lt;/b&gt; that can be typed from a computer keyboard (possibly with the Shift key pressed). There are various points to note about characters. For example, upper- and lower-case versions of the same letter, such as &amp;#x2018;P’ and &amp;#x2018;p’, are different characters. A digit such as &amp;#x2018;5’ can be entered from the keyboard as a character, and it is vital to be clear that, in terms of its storage in computer memory, this is not the same thing as the number 5. This means that &amp;#x201C;SOUP&amp;#x201D;, for example, also forms a sequence. It is a sequence of characters, and could be written as [&amp;#x2018;S’, &amp;#x2018;O’, &amp;#x2018;U’, &amp;#x2018;P’]. However, to do this would be tedious, since we will use sequences of characters frequently. So we often use the notation &amp;#x201C;SOUP&amp;#x201D;, just to make life easier! When we do this, we usually refer to the sequence of characters as a &lt;b&gt;string&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Note that we have introduced a number of notational conventions. An individual character is written between single inverted commas, as in &amp;#x2018;P’ or &amp;#x2018;q’. Double inverted commas are used to show a sequence of characters such as &amp;#x201C;ORGANIC&amp;#x201D;. If we write out in full the string &amp;#x201C;ORGANIC COURGETTES 0.41kg @ &amp;#xA3;3.49/kg&amp;#x201D;, it is necessary to deal with the spaces between words. This use of double inverted commas only applies to sequences of &lt;b&gt;characters&lt;/b&gt;. All other sequences are written using the square bracket notation introduced above. Spaces are characters like any others; they are obtained by pressing the space-bar on the keyboard. It is often desirable to indicate the space character explicitly by adopting a special symbol. We shall use &amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’. Thus, we may write [&amp;#x2018;O’, &amp;#x2018;R’, &amp;#x2018;G’, &amp;#x2018;A’, &amp;#x2018;N’, &amp;#x2018;I’, &amp;#x2018;C’, &amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’, &amp;#x2018;C’, &amp;#x2018;O’, &amp;#x2018;U’, &amp;#x2018;R’, &amp;#x2018;G’, &amp;#x2018;E’, &amp;#x2018;T’, &amp;#x2018;T’, &amp;#x2018;E’, &amp;#x2018;S’, &amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’, &amp;#x2018;0’, &amp;#x2018;.’, &amp;#x2018;4’, &amp;#x2018;1’, &amp;#x2018;k’, &amp;#x2018;g’, &amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’, &amp;#x2018;@’, &amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,&amp;#x2018;&amp;#xA3;’, &amp;#x2018;3’, &amp;#x2018;.’, &amp;#x2018;4’ &amp;#x2018;9’, &amp;#x2018;/’, &amp;#x2018;k’, &amp;#x2018;g’].&lt;/p&gt;&lt;p&gt;Imagine you are at the fifth till in the supermarket, and the data that constitutes your transaction is recorded by the supermarket's computer using the &lt;b&gt;identifier&lt;/b&gt; &lt;i&gt;till5&lt;/i&gt;. This is the name of an area in the computer's memory devoted to storing your transaction details. The data stored in &lt;i&gt;till5&lt;/i&gt; changes each time an item is scanned or entered, and so we refer to &lt;i&gt;till5&lt;/i&gt; as a &lt;b&gt;variable&lt;/b&gt;. We call the data stored in the variable &lt;i&gt;till5&lt;/i&gt; at any moment in time the &lt;b&gt;state&lt;/b&gt; of &lt;i&gt;till5&lt;/i&gt;. Each time that the data stored by &lt;i&gt;till5&lt;/i&gt; changes, we say that the state of &lt;i&gt;till5&lt;/i&gt; has changed. You do not need to know anything about how the computer's electronic memory actually works.&lt;/p&gt;&lt;p&gt;These comments are not peculiar to the fifth till at the supermarket. The supermarket's computer stores data for each active till. The data for each till can be seen as a variable, and so needs its own identifier &amp;#x2014; such as &lt;i&gt;till1&lt;/i&gt;, &lt;i&gt;till2&lt;/i&gt;, and so on. Indeed, the term &lt;b&gt;variable&lt;/b&gt; is used for any named area of computer memory, storing data that may change.&lt;/p&gt;&lt;p&gt;Now suppose that the variable &lt;i&gt;till5&lt;/i&gt; stores a sequence of barcodes. When the cashier starts a new transaction, no items have been entered, so the state of the variable &lt;i&gt;till5&lt;/i&gt; needs to start as a sequence with no elements, which we call an &lt;b&gt;empty sequence&lt;/b&gt; and write as [ ]. If an item with code 50297 is then entered, then the state of &lt;i&gt;till5&lt;/i&gt; will change to [50297]. If an item with code 50152 is scanned next, then the state becomes [50297, 50152], and so on.&lt;/p&gt;&lt;p&gt;When a new item is recorded, the state of &lt;i&gt;till5&lt;/i&gt; changes, and changes in a way that is predictable. Specifically, the current state is changed by appending the newest item to the end of the sequence, giving a new state.&lt;/p&gt;&lt;p&gt;We have described the change of a till state in a way that is quite general. The description is not peculiar to the fifth till in the supermarket: it applies equally well to a transaction in progress at any till. Indeed, it describes a process that adds a new item to any variable storing data as a sequence.&lt;/p&gt;&lt;div class="oucontent-table oucontent-s-normal noborder oucontent-s-box" id="tab001"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Table 1: Prices of items&lt;/h3&gt;&lt;div class="oucontent-table-wrapper"&gt;&lt;table&gt;&lt;tr&gt;
&lt;th scope="col"&gt;&lt;b&gt;Item code&lt;/b&gt;&lt;/th&gt;
&lt;th scope="col"&gt;&lt;b&gt;Item price (pence)&lt;/b&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;33050&lt;/td&gt;
&lt;td class="oucontent-tableright "&gt;299&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;53151&lt;/td&gt;
&lt;td class="oucontent-tableright "&gt;440&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;77502&lt;/td&gt;
&lt;td class="oucontent-tableright "&gt;89&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="oucontent-source-reference"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Now suppose the computer stores the prices of certain items as given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#tab001"&gt;Table 1&lt;/a&gt;. To calculate the bill corresponding to purchases read by the cashier as [77502, 53151, 33050, 77502], we need to store the price associated with each item purchased. Let us assume that a second sequence is also being generated as each item is recorded, giving the price of the item. Suppose that this is stored as a variable &lt;i&gt;price5&lt;/i&gt;. If the sequence of item codes were [77502, 53151, 33050, 77502], then the sequence of prices would be [89, 440, 299, 89]. Given this sequence, the total bill is obtained by simply finding the total of all the values in the sequence &lt;i&gt;price5&lt;/i&gt;:&lt;/p&gt;&lt;p&gt;89 + 440 + 299 + 89 = 917 pence.&lt;/p&gt;&lt;p&gt;For simplicity, assume that there are no weighed items and no special offers.&lt;/p&gt;&lt;p&gt;This calculation does not change the state of the variable &lt;i&gt;price5&lt;/i&gt;, but the value calculated certainly does depend upon the state of that variable.&lt;/p&gt;&lt;p&gt;Appending a new item at the end of a sequence, or adding a sequence of numbers, are both examples of the sort of processes that software needs to carry out time and time again. Recognising generality, and forms of data and processes on data that can be reused, are key skills in learning to design large and complex software systems.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act001"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 1&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Consider a process that changes the state of a variable storing a sequence by removing the last item from the sequence. So, for example, if the state of the variable was [22, 31, 53, 22, 13], then applying the process would change the state to [22, 31, 53, 22]. Suppose that this process is applied four more times. Write out the state of the variable after each application.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h4 class="oucontent-h4"&gt;Discussion&lt;/h4&gt;
&lt;p&gt;The state starts as [22, 31, 53, 22]. After one more application of this process the state is [22, 31, 53]. If the process is applied again, the state becomes [22, 31]. If the process is applied again, the state becomes [22]. If the process is applied one more time, then the last item in the sequence is removed. We are left with a sequence containing no items, the empty sequence, which we write as [ ].&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Since we use double inverted commas for strings, i.e. sequences of characters, we will use &amp;#x201C; &amp;#x201D; to denote the empty string in this course. In many computing texts, the symbol &amp;#x3BE; is used.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act002"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 2&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;How many characters are there in the string &amp;#x201C;I am it.&amp;#x201D;? Using the notational conventions introduced above for writing sequences and characters (including the space character), write this string out in full as a sequence of characters.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h4 class="oucontent-h4"&gt;Discussion&lt;/h4&gt;
&lt;p&gt;This string includes eight characters in all, including two space characters and a full stop. Written in full, it is the following sequence of characters:&lt;/p&gt;
&lt;p&gt;[&amp;#x2018;I’,&amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,&amp;#x2018;a’,&amp;#x2018;m’,&amp;#x2018; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,&amp;#x2018;i’,&amp;#x2018;t’,&amp;#x2018;.’].&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1</guid>
    <dc:title>1.1 Number sequences</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Imagine that you are at a modern supermarket and the cashier is processing the items from your basket or trolley. The electronic till (which is a form of computer) records each item that you have bought. Most items are scanned using a device that can read the barcode printed on the item.&lt;/p&gt;&lt;div class="oucontent-figure" style="width:511px;" id="fig001"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7400f745/m263_1_001i.jpg" alt="Figure 1" width="511" height="54" style="max-width:511px;" class="oucontent-figure-image oucontent-media-wide"/&gt;&lt;div class="oucontent-figure-text"&gt;&lt;div class="oucontent-caption oucontent-nonumber"&gt;&lt;span class="oucontent-figure-caption"&gt;Figure 1 An example of a barcode. Today, nearly every product has a barcode, although not all stores use them. A laser scanner is used to convert the pattern of light and dark bars into a number stored in the till. The number, printed as part of the barcode, may be entered manually if an electronic scanner is unavailable. A computerised till uses this code to look up the price that a shop wishes to charge for the item.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Items that need to be weighed (such as loose fruit and vegetables) do not have a barcode printed on them. Instead, the cashier looks up a different sort of code for these items and enters this manually at the till, together with the weight of the item purchased. If an error is made, the cashier may cancel the item just entered and try again. When all the items you have purchased have been processed, your final bill is calculated and you receive an itemised receipt (Figure 2).&lt;/p&gt;&lt;div class="oucontent-figure" style="width:511px;" id="fig002"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/62109d25/m263_1_002i.jpg" alt="Figure 2" width="511" height="584" style="max-width:511px;" class="oucontent-figure-image oucontent-media-wide"/&gt;&lt;div class="oucontent-figure-text"&gt;&lt;div class="oucontent-caption oucontent-nonumber"&gt;&lt;span class="oucontent-figure-caption"&gt;Figure 2: An example of a supermarket till receipt. (Note the two weighed items.)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Let us look a little more formally at some of the data that the supermarket computer system must store and use. As we do this, you will begin to get a flavour of the rigour that underpins the design of modern software. You will meet new vocabulary and concepts, try to get a general sense of what each new term means.&lt;/p&gt;&lt;p&gt;Each type of item stocked by the supermarket needs to be identified. As we have seen, this is done either using barcodes or, for weighed items, item codes of a different sort. Associated with each code is a variety of other item-related information. Perhaps the most obvious information is the price, and the description that appears on the receipt. (In the case of weighed items, the price is a unit price, giving the price per kilogram, for instance.) Other information associated with any item code might include the current stock level (so that new stock can be ordered as items are near to being out of stock), the name and address of the supplier, discount rates for multiple purchases, etc&lt;/p&gt;&lt;p&gt;Barcodes such as 5000119004048 can be interpreted as whole numbers. Whole numbers are called &lt;b&gt;integers&lt;/b&gt;. Integers may be positive, negative or zero. (The codes for weighed items are also usually whole numbers.)&lt;/p&gt;&lt;p&gt;Prices and weights are not ordinarily presented as whole numbers. In &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt;, the item price of walnut bread is shown as £1.49; the unit price of organic courgettes is £3.49 per kg and the weight of organic courgettes purchased is 0.41 kg (kg is the standard abbreviation for kilogram).&lt;/p&gt;&lt;p&gt;A number with a fractional part such as 1.49 is an example of a real number. The real numbers include numbers such as 3.497825 (and numbers such as √2, which cannot be expressed exactly as any fraction or decimal). Computers cannot represent such real numbers exactly. When dealing with a real number, we can only rely on a computer storing and manipulating an approximation of the number. Even though the extent of the approximation may seem small, this can present problems to the unwary software developer. To avoid problems here, we will represent prices as a whole number of pence, and weights as a whole number of grams. So, for example, the bill in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt; includes a purchase of 335 grams of walnuts at 299 pence per kg.&lt;/p&gt;&lt;p&gt;As the items in a basket or trolley are scanned one after another, the till stores a &lt;b&gt;sequence&lt;/b&gt; of codes. We use a precise notation to indicate a sequence. Suppose that the item codes scanned so far are 50773, 50412, 50330, 33777, 50773. If the codes were scanned in this order, then the till would store the sequence [50773, 50412, 50330, 33777, 50773]. If the same codes were scanned in a different order, then the till might store the sequence [50773, 50773, 50412, 50330, 33777]. Barcodes normally contain more digits. In our illustrative examples, we shall use shorter codes that are easier to read.&lt;/p&gt;&lt;p&gt;A sequence is a collection of items in a particular order. We shall write the items in a sequence between square brackets [ and ], and commas are used to separate the items in it (in other texts, you may see angled brackets 〈 and 〉 used to show a sequence, rather than [ and ]). These items are called the &lt;b&gt;elements&lt;/b&gt; of the sequence. The order in which items appear in a sequence is important, so that [50773, 50412, 50330, 33777, 50773] is not the same as the sequence [50773, 50773, 50412, 50330, 33777]. Of course, the order in which the cashier checks your purchases does not matter in terms of the final cost. But, while the items are being entered, the order will often matter. For example, if an error occurs in scanning or weighing, the last item entered can usually be corrected using a ‘Cancel Last Item’ key on the till. Also, the itemised bill that you receive usually gives the items in the order in which they have been processed.&lt;/p&gt;&lt;p&gt;Item descriptions in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt; include “ORGANIC SOUP” and “OLIVE OIL”. These descriptions are formed from &lt;b&gt;characters&lt;/b&gt; that can be typed from a computer keyboard (possibly with the Shift key pressed). There are various points to note about characters. For example, upper- and lower-case versions of the same letter, such as ‘P’ and ‘p’, are different characters. A digit such as ‘5’ can be entered from the keyboard as a character, and it is vital to be clear that, in terms of its storage in computer memory, this is not the same thing as the number 5. This means that “SOUP”, for example, also forms a sequence. It is a sequence of characters, and could be written as [‘S’, ‘O’, ‘U’, ‘P’]. However, to do this would be tedious, since we will use sequences of characters frequently. So we often use the notation “SOUP”, just to make life easier! When we do this, we usually refer to the sequence of characters as a &lt;b&gt;string&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Note that we have introduced a number of notational conventions. An individual character is written between single inverted commas, as in ‘P’ or ‘q’. Double inverted commas are used to show a sequence of characters such as “ORGANIC”. If we write out in full the string “ORGANIC COURGETTES 0.41kg @ £3.49/kg”, it is necessary to deal with the spaces between words. This use of double inverted commas only applies to sequences of &lt;b&gt;characters&lt;/b&gt;. All other sequences are written using the square bracket notation introduced above. Spaces are characters like any others; they are obtained by pressing the space-bar on the keyboard. It is often desirable to indicate the space character explicitly by adopting a special symbol. We shall use ‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’. Thus, we may write [‘O’, ‘R’, ‘G’, ‘A’, ‘N’, ‘I’, ‘C’, ‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’, ‘C’, ‘O’, ‘U’, ‘R’, ‘G’, ‘E’, ‘T’, ‘T’, ‘E’, ‘S’, ‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’, ‘0’, ‘.’, ‘4’, ‘1’, ‘k’, ‘g’, ‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’, ‘@’, ‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,‘£’, ‘3’, ‘.’, ‘4’ ‘9’, ‘/’, ‘k’, ‘g’].&lt;/p&gt;&lt;p&gt;Imagine you are at the fifth till in the supermarket, and the data that constitutes your transaction is recorded by the supermarket's computer using the &lt;b&gt;identifier&lt;/b&gt; &lt;i&gt;till5&lt;/i&gt;. This is the name of an area in the computer's memory devoted to storing your transaction details. The data stored in &lt;i&gt;till5&lt;/i&gt; changes each time an item is scanned or entered, and so we refer to &lt;i&gt;till5&lt;/i&gt; as a &lt;b&gt;variable&lt;/b&gt;. We call the data stored in the variable &lt;i&gt;till5&lt;/i&gt; at any moment in time the &lt;b&gt;state&lt;/b&gt; of &lt;i&gt;till5&lt;/i&gt;. Each time that the data stored by &lt;i&gt;till5&lt;/i&gt; changes, we say that the state of &lt;i&gt;till5&lt;/i&gt; has changed. You do not need to know anything about how the computer's electronic memory actually works.&lt;/p&gt;&lt;p&gt;These comments are not peculiar to the fifth till at the supermarket. The supermarket's computer stores data for each active till. The data for each till can be seen as a variable, and so needs its own identifier — such as &lt;i&gt;till1&lt;/i&gt;, &lt;i&gt;till2&lt;/i&gt;, and so on. Indeed, the term &lt;b&gt;variable&lt;/b&gt; is used for any named area of computer memory, storing data that may change.&lt;/p&gt;&lt;p&gt;Now suppose that the variable &lt;i&gt;till5&lt;/i&gt; stores a sequence of barcodes. When the cashier starts a new transaction, no items have been entered, so the state of the variable &lt;i&gt;till5&lt;/i&gt; needs to start as a sequence with no elements, which we call an &lt;b&gt;empty sequence&lt;/b&gt; and write as [ ]. If an item with code 50297 is then entered, then the state of &lt;i&gt;till5&lt;/i&gt; will change to [50297]. If an item with code 50152 is scanned next, then the state becomes [50297, 50152], and so on.&lt;/p&gt;&lt;p&gt;When a new item is recorded, the state of &lt;i&gt;till5&lt;/i&gt; changes, and changes in a way that is predictable. Specifically, the current state is changed by appending the newest item to the end of the sequence, giving a new state.&lt;/p&gt;&lt;p&gt;We have described the change of a till state in a way that is quite general. The description is not peculiar to the fifth till in the supermarket: it applies equally well to a transaction in progress at any till. Indeed, it describes a process that adds a new item to any variable storing data as a sequence.&lt;/p&gt;&lt;div class="oucontent-table oucontent-s-normal noborder oucontent-s-box" id="tab001"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Table 1: Prices of items&lt;/h3&gt;&lt;div class="oucontent-table-wrapper"&gt;&lt;table&gt;&lt;tr&gt;
&lt;th scope="col"&gt;&lt;b&gt;Item code&lt;/b&gt;&lt;/th&gt;
&lt;th scope="col"&gt;&lt;b&gt;Item price (pence)&lt;/b&gt;&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;33050&lt;/td&gt;
&lt;td class="oucontent-tableright "&gt;299&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;53151&lt;/td&gt;
&lt;td class="oucontent-tableright "&gt;440&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;77502&lt;/td&gt;
&lt;td class="oucontent-tableright "&gt;89&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="oucontent-source-reference"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Now suppose the computer stores the prices of certain items as given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#tab001"&gt;Table 1&lt;/a&gt;. To calculate the bill corresponding to purchases read by the cashier as [77502, 53151, 33050, 77502], we need to store the price associated with each item purchased. Let us assume that a second sequence is also being generated as each item is recorded, giving the price of the item. Suppose that this is stored as a variable &lt;i&gt;price5&lt;/i&gt;. If the sequence of item codes were [77502, 53151, 33050, 77502], then the sequence of prices would be [89, 440, 299, 89]. Given this sequence, the total bill is obtained by simply finding the total of all the values in the sequence &lt;i&gt;price5&lt;/i&gt;:&lt;/p&gt;&lt;p&gt;89 + 440 + 299 + 89 = 917 pence.&lt;/p&gt;&lt;p&gt;For simplicity, assume that there are no weighed items and no special offers.&lt;/p&gt;&lt;p&gt;This calculation does not change the state of the variable &lt;i&gt;price5&lt;/i&gt;, but the value calculated certainly does depend upon the state of that variable.&lt;/p&gt;&lt;p&gt;Appending a new item at the end of a sequence, or adding a sequence of numbers, are both examples of the sort of processes that software needs to carry out time and time again. Recognising generality, and forms of data and processes on data that can be reused, are key skills in learning to design large and complex software systems.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act001"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 1&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Consider a process that changes the state of a variable storing a sequence by removing the last item from the sequence. So, for example, if the state of the variable was [22, 31, 53, 22, 13], then applying the process would change the state to [22, 31, 53, 22]. Suppose that this process is applied four more times. Write out the state of the variable after each application.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h4 class="oucontent-h4"&gt;Discussion&lt;/h4&gt;
&lt;p&gt;The state starts as [22, 31, 53, 22]. After one more application of this process the state is [22, 31, 53]. If the process is applied again, the state becomes [22, 31]. If the process is applied again, the state becomes [22]. If the process is applied one more time, then the last item in the sequence is removed. We are left with a sequence containing no items, the empty sequence, which we write as [ ].&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Since we use double inverted commas for strings, i.e. sequences of characters, we will use “ ” to denote the empty string in this course. In many computing texts, the symbol ξ is used.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act002"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 2&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;How many characters are there in the string “I am it.”? Using the notational conventions introduced above for writing sequences and characters (including the space character), write this string out in full as a sequence of characters.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h4 class="oucontent-h4"&gt;Discussion&lt;/h4&gt;
&lt;p&gt;This string includes eight characters in all, including two space characters and a full stop. Written in full, it is the following sequence of characters:&lt;/p&gt;
&lt;p&gt;[‘I’,‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,‘a’,‘m’,‘ &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,‘i’,‘t’,‘.’].&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Objectives for Section 1</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.2</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise the terminology: character; string; integer; sequence; element (of a sequence); variable; identifier (of a variable); state (of a variable).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use and interpret the notational conventions:&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;single inverted commas to show a character;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;double inverted commas to show a string (sequence of characters);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’ to make explicit a space character;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;the brackets [ and ] to delimit a sequence.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.2</guid>
    <dc:title>Objectives for Section 1</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise the terminology: character; string; integer; sequence; element (of a sequence); variable; identifier (of a variable); state (of a variable).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use and interpret the notational conventions:&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;single inverted commas to show a character;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;double inverted commas to show a string (sequence of characters);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’ to make explicit a space character;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;the brackets [ and ] to delimit a sequence.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Exercises on Section 1</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.3</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq001"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 1&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) How many characters are there in the string &amp;#x201C;This text.&amp;#x201D;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Which of the following are integers: 3, 0, 98, 4, –22,&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, &amp;#x2018;7’, [56]?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) How many integers are there in the sequence [11, 23, 4, 56, 32]?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) There are ten characters: four in each word, a space, and a full stop.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Each of 3, 0, 98, 4 and &amp;#x2212;22 is an integer. &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; is not an integer because it is not a whole number. &amp;#x2018;7’ is a character, and is not an integer. [56] is a sequence containing one integer, but is not an integer.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) There are five integers in the sequence.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq002"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 2&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that the variable &lt;i&gt;till2&lt;/i&gt; holds data in the form of a sequence of barcodes. When an item is read at the checkout, the state of &lt;i&gt;till2&lt;/i&gt; is changed by appending the barcode of the item to the end of the sequence giving the state of &lt;i&gt;till2&lt;/i&gt;. Suppose that &lt;i&gt;till2&lt;/i&gt; currently has the state [50222, 50345], and that an item with barcode 50111 is read, and then an item with barcode 50456 is read. Write out the state of the variable &lt;i&gt;till2&lt;/i&gt; at each stage.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;In turn, the state takes the following values:&lt;/p&gt;
&lt;div class="oucontent-table oucontent-s-normal noborder oucontent-s-box" id="tab002"&gt;&lt;div class="oucontent-table-wrapper"&gt;&lt;table&gt;&lt;tr&gt;
&lt;td&gt;[50222, 50345]&lt;/td&gt;
&lt;td&gt;(at the start).&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;[50222, 50345, 50111]&lt;/td&gt;
&lt;td&gt;(after 50111 is read).&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;[50222, 50345, 50111, 50456]&lt;/td&gt;
&lt;td&gt;(after 50456 is read).&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="oucontent-source-reference"&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq003"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 3&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;With item prices as given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#tab001"&gt;Table 1&lt;/a&gt;, what is the sequence of prices corresponding to the sequence of barcodes [33050, 33050, 77502, 53151, 77502]? What is the total price of the items given by this sequence?&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;The sequence of prices (given as integer numbers of pence, as in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#tab001"&gt;Table 1&lt;/a&gt;) is: [299, 299, 89, 440, 89]. The total price (in pence) is 1216 (or &amp;#xA3;12.16).&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.3</guid>
    <dc:title>Exercises on Section 1</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq001"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 1&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) How many characters are there in the string “This text.”?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Which of the following are integers: 3, 0, 98, 4, –22,&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, ‘7’, [56]?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) How many integers are there in the sequence [11, 23, 4, 56, 32]?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) There are ten characters: four in each word, a space, and a full stop.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Each of 3, 0, 98, 4 and −22 is an integer. &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; is not an integer because it is not a whole number. ‘7’ is a character, and is not an integer. [56] is a sequence containing one integer, but is not an integer.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) There are five integers in the sequence.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq002"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 2&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that the variable &lt;i&gt;till2&lt;/i&gt; holds data in the form of a sequence of barcodes. When an item is read at the checkout, the state of &lt;i&gt;till2&lt;/i&gt; is changed by appending the barcode of the item to the end of the sequence giving the state of &lt;i&gt;till2&lt;/i&gt;. Suppose that &lt;i&gt;till2&lt;/i&gt; currently has the state [50222, 50345], and that an item with barcode 50111 is read, and then an item with barcode 50456 is read. Write out the state of the variable &lt;i&gt;till2&lt;/i&gt; at each stage.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;In turn, the state takes the following values:&lt;/p&gt;
&lt;div class="oucontent-table oucontent-s-normal noborder oucontent-s-box" id="tab002"&gt;&lt;div class="oucontent-table-wrapper"&gt;&lt;table&gt;&lt;tr&gt;
&lt;td&gt;[50222, 50345]&lt;/td&gt;
&lt;td&gt;(at the start).&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;[50222, 50345, 50111]&lt;/td&gt;
&lt;td&gt;(after 50111 is read).&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;[50222, 50345, 50111, 50456]&lt;/td&gt;
&lt;td&gt;(after 50456 is read).&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="oucontent-source-reference"&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq003"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 3&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;With item prices as given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#tab001"&gt;Table 1&lt;/a&gt;, what is the sequence of prices corresponding to the sequence of barcodes [33050, 33050, 77502, 53151, 77502]? What is the total price of the items given by this sequence?&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;The sequence of prices (given as integer numbers of pence, as in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#tab001"&gt;Table 1&lt;/a&gt;) is: [299, 299, 89, 440, 89]. The total price (in pence) is 1216 (or £12.16).&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>2.1 Numbers</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.1</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;The supermarket example discussed in Section 1 involves various forms of data that a computer may need to handle. Some of these, such as numbers and characters, are simple but fundamental. Other forms of data, such as sequences, involve more complicated structure. In this section, we will introduce &lt;b&gt;sets&lt;/b&gt;, which are a variety of data collection that is different from sequences. But first we will look more carefully at numbers and characters.&lt;/p&gt;&lt;p&gt;When developing software we need to distinguish between different sorts of numbers, not least because computers represent and process them differently. Whole numbers (positive, negative or zero) are called integers. We shall use &lt;i&gt;Int&lt;/i&gt; to denote the collection (or set) of all integers. In principle, digital computers can represent integers exactly, no matter how large or small. In practice, however, most programming languages place restrictions on the size of an integer (positive or negative) that can be stored. Many texts use &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/914d85a4/doublestrike_z.gif" alt="" width="10" height="11" style="max-width:10px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; instead of &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Sometimes, we need to work with numbers that are not integers. Measured quantities, such as weights or distances, are often presented as non-integer values. More profoundly, even if one starts with whole numbers, some arithmetic processes, such as division or finding a square root, may yield results that are not integers (see &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.1#act004"&gt;Activity 3&lt;/a&gt;). The real numbers are a wider collection of numbers used in mathematics. A &lt;b&gt;real number&lt;/b&gt; is conveniently thought of as a decimal, such as 435.5218 or –29.333344, but not every real number can be written as a decimal of a finite length. For example, &amp;#x221A;2 (the square root of 2) and the number &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/3200b4b1/pi.gif" alt="" width="7" height="7" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (pi) are real numbers that are non-terminating decimals. Such numbers can never be expressed exactly as a finite decimal.&lt;/p&gt;&lt;p&gt;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/3200b4b1/pi.gif" alt="" width="7" height="7" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; is approximately equal to 3.142. You may have met it in calculating the circumference or area of a circle.&lt;/p&gt;&lt;p&gt;Digital computers cannot store real numbers exactly. They need to work with approximations to the real numbers. These approximations may be stored in the computer as &lt;b&gt;floating point numbers&lt;/b&gt;. You can get a feeling for the sorts of issues that arise through the following example. Suppose (for the purposes of illustration) that we can only store a real number to an accuracy of four decimal places. Then the number 435.5218 might be stored as 0.4355 &amp;#xD7; 10&lt;sup&gt;3&lt;/sup&gt;. But 435.48336 (a different number) would also be stored as 0.4355 &amp;#xD7; 10&lt;sup&gt;3&lt;/sup&gt;.&lt;/p&gt;&lt;p&gt;If a software application really does need to deal with real numbers, then great care needs to be taken to ensure that the effects of (repeated) approximations are managed in a way that is well understood. This is especially true for safety critical applications, where people's lives may depend upon the behaviour of the software. However, in this course, we shall largely exclude further consideration of real numbers.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act004"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 3&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;If &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; may each take any integer value, which of the following will always give an integer result and which may give a result that is not an integer? If you are not sure, try to choose values of &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; that do not give integer answers.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;x &amp;#x2212; y&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;x &amp;#xD7; y&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;x/y&lt;/i&gt;. (&lt;i&gt;x&lt;/i&gt; divided by &lt;i&gt;y&lt;/i&gt;.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(f) &amp;#x221A;&lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h4 class="oucontent-h4"&gt;Discussion&lt;/h4&gt;
&lt;p&gt;If &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are integers, then (a) &lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt;, (b) &lt;i&gt;x &amp;#x2212; y&lt;/i&gt; and (c) &lt;i&gt;x&lt;/i&gt; &amp;#xD7; &lt;i&gt;y&lt;/i&gt; will always be integers. In (e), &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; means &lt;i&gt;x&lt;/i&gt; &amp;#xD7; &lt;i&gt;x&lt;/i&gt;, and if &lt;i&gt;x&lt;/i&gt; is an integer then &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; will be an integer. However, in (d), choosing &lt;i&gt;x&lt;/i&gt; = 1 and &lt;i&gt;y&lt;/i&gt; = 4 (both integers) gives &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; or 0.25, which is not an integer. (In (d), if &lt;i&gt;y&lt;/i&gt; is chosen to be 0, the result is undefined. Software that performs division should always ensure that division by 0 is not attempted.) In (f), choosing &lt;i&gt;x&lt;/i&gt; = 8 (for example) gives &amp;#x221A;8, which is 2.828 (to an accuracy of 4 figures) and is not an integer.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.1</guid>
    <dc:title>2.1 Numbers</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;The supermarket example discussed in Section 1 involves various forms of data that a computer may need to handle. Some of these, such as numbers and characters, are simple but fundamental. Other forms of data, such as sequences, involve more complicated structure. In this section, we will introduce &lt;b&gt;sets&lt;/b&gt;, which are a variety of data collection that is different from sequences. But first we will look more carefully at numbers and characters.&lt;/p&gt;&lt;p&gt;When developing software we need to distinguish between different sorts of numbers, not least because computers represent and process them differently. Whole numbers (positive, negative or zero) are called integers. We shall use &lt;i&gt;Int&lt;/i&gt; to denote the collection (or set) of all integers. In principle, digital computers can represent integers exactly, no matter how large or small. In practice, however, most programming languages place restrictions on the size of an integer (positive or negative) that can be stored. Many texts use &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/914d85a4/doublestrike_z.gif" alt="" width="10" height="11" style="max-width:10px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; instead of &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Sometimes, we need to work with numbers that are not integers. Measured quantities, such as weights or distances, are often presented as non-integer values. More profoundly, even if one starts with whole numbers, some arithmetic processes, such as division or finding a square root, may yield results that are not integers (see &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.1#act004"&gt;Activity 3&lt;/a&gt;). The real numbers are a wider collection of numbers used in mathematics. A &lt;b&gt;real number&lt;/b&gt; is conveniently thought of as a decimal, such as 435.5218 or –29.333344, but not every real number can be written as a decimal of a finite length. For example, √2 (the square root of 2) and the number &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/3200b4b1/pi.gif" alt="" width="7" height="7" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (pi) are real numbers that are non-terminating decimals. Such numbers can never be expressed exactly as a finite decimal.&lt;/p&gt;&lt;p&gt;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/3200b4b1/pi.gif" alt="" width="7" height="7" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; is approximately equal to 3.142. You may have met it in calculating the circumference or area of a circle.&lt;/p&gt;&lt;p&gt;Digital computers cannot store real numbers exactly. They need to work with approximations to the real numbers. These approximations may be stored in the computer as &lt;b&gt;floating point numbers&lt;/b&gt;. You can get a feeling for the sorts of issues that arise through the following example. Suppose (for the purposes of illustration) that we can only store a real number to an accuracy of four decimal places. Then the number 435.5218 might be stored as 0.4355 × 10&lt;sup&gt;3&lt;/sup&gt;. But 435.48336 (a different number) would also be stored as 0.4355 × 10&lt;sup&gt;3&lt;/sup&gt;.&lt;/p&gt;&lt;p&gt;If a software application really does need to deal with real numbers, then great care needs to be taken to ensure that the effects of (repeated) approximations are managed in a way that is well understood. This is especially true for safety critical applications, where people's lives may depend upon the behaviour of the software. However, in this course, we shall largely exclude further consideration of real numbers.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act004"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 3&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;If &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; may each take any integer value, which of the following will always give an integer result and which may give a result that is not an integer? If you are not sure, try to choose values of &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; that do not give integer answers.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;x − y&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;x × y&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;x/y&lt;/i&gt;. (&lt;i&gt;x&lt;/i&gt; divided by &lt;i&gt;y&lt;/i&gt;.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(f) √&lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h4 class="oucontent-h4"&gt;Discussion&lt;/h4&gt;
&lt;p&gt;If &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are integers, then (a) &lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt;, (b) &lt;i&gt;x − y&lt;/i&gt; and (c) &lt;i&gt;x&lt;/i&gt; × &lt;i&gt;y&lt;/i&gt; will always be integers. In (e), &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; means &lt;i&gt;x&lt;/i&gt; × &lt;i&gt;x&lt;/i&gt;, and if &lt;i&gt;x&lt;/i&gt; is an integer then &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; will be an integer. However, in (d), choosing &lt;i&gt;x&lt;/i&gt; = 1 and &lt;i&gt;y&lt;/i&gt; = 4 (both integers) gives &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; or 0.25, which is not an integer. (In (d), if &lt;i&gt;y&lt;/i&gt; is chosen to be 0, the result is undefined. Software that performs division should always ensure that division by 0 is not attempted.) In (f), choosing &lt;i&gt;x&lt;/i&gt; = 8 (for example) gives √8, which is 2.828 (to an accuracy of 4 figures) and is not an integer.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>2.2 Characters</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Characters are another fundamental form of data. Computers store characters as integers, and system hardware and software translate these integer codes so that monitors and printers can display them.&lt;/p&gt;&lt;p&gt;As well as the familiar characters appearing on a keyboard, the current international standard (UNICODE) includes codes for characters from a variety of languages and alphabets (such as &amp;#xEA; and &amp;#xF6;). For simplicity, examples in this course will use only a part of this code, as given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;. This is confined to printable symbols that appear on a standard computer keyboard (for an English-speaking user).&lt;/p&gt;&lt;p&gt;We will denote by &lt;i&gt;Char&lt;/i&gt; the set of characters appearing in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;. We will call the codes in the table the &lt;b&gt;ASCII codes&lt;/b&gt; of the characters.&lt;/p&gt;&lt;p&gt;The original ASCII set (developed by ANSI, the American National Standards Institute) was finalised in 1968, and provides a basic (but by no means complete) character set for English. With the development of the Internet and a more global economy, efforts are being made to create a standard character set, catering more completely for many languages, and bringing together hundreds of incompatible standards from different countries. UNICODE is the result of this development, but it still only represents some of the written characters of our languages, currently standing at about 94,000 symbols. No existing character set caters for all languages.&lt;/p&gt;&lt;div class="oucontent-table oucontent-s-normal noborder oucontent-s-box" id="tab003"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Table 2: The ASCII encoding of characters (in part).&lt;/h2&gt;&lt;div class="oucontent-table-wrapper"&gt;&lt;table&gt;&lt;tr&gt;
&lt;th scope="col"&gt;Code&lt;/th&gt;
&lt;th scope="col"&gt;Character&lt;/th&gt;
&lt;th scope="col"&gt;Code&lt;/th&gt;
&lt;th scope="col"&gt;Character&lt;/th&gt;
&lt;th scope="col"&gt;Code&lt;/th&gt;
&lt;th scope="col"&gt;Character&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;32&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;64&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;@&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;96&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;'&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;33&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;!&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;65&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;A&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;97&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;a&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;34&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;"&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;66&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;B&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;98&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;b&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;35&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;#&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;67&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;C&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;99&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;c&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;36&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;$&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;68&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;D&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;100&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;d&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;37&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;%&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;69&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;E&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;101&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;e&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;38&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&amp;amp;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;70&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;F&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;102&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;f&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;39&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;’&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;71&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;G&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;103&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;g&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;40&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;(&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;72&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;H&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;104&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;h&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;41&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;)&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;73&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;I&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;105&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;i&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;42&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;*&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;74&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;J&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;106&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;j&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;43&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;+&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;75&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;K&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;107&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;k&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;44&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;,&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;76&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;L&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;108&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;l&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;45&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&amp;#x2212;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;77&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;M&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;109&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;m&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;46&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;.&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;78&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;N&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;110&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;n&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;47&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;/&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;79&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;O&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;111&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;o&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;48&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;0&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;80&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;P&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;112&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;p&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;49&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;1&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;81&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;Q&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;113&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;q&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;50&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;2&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;82&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;R&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;114&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;r&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;51&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;3&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;83&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;S&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;115&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;s&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;52&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;4&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;84&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;T&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;116&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;t&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;53&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;5&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;85&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;U&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;117&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;u&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;54&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;6&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;86&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;V&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;118&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;v&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;55&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;7&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;87&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;W&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;119&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;w&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;56&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;8&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;88&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;X&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;120&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;x&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;57&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;9&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;89&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;Y&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;121&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;y&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;58&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;:&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;90&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;Z&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;122&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;z&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;59&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;91&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;[&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;123&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;{&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;60&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&amp;lt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;92&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;\ &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/707a380c/backslash.gif" alt="" width="5" height="9" style="max-width:5px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;124&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;|&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;61&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;=&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;93&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;]&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;125&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;}&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;62&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&amp;gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;94&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;^&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;126&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&amp;#x2DC;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;63&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;?&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;95&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;–&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="oucontent-source-reference"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The character with ASCII code 32 is the space character, which, when we need to write it explicitly, will appear as &amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act005"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 4&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) What character has ASCII code 91?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) What are the ASCII codes of the characters &amp;#x2018;A’ and &amp;#x2018;a’?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) What is the ASCII code of the character &amp;#x2018;7’?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) The character &amp;#x2018;[’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) 65 and 97, respectively.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) 55.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2</guid>
    <dc:title>2.2 Characters</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Characters are another fundamental form of data. Computers store characters as integers, and system hardware and software translate these integer codes so that monitors and printers can display them.&lt;/p&gt;&lt;p&gt;As well as the familiar characters appearing on a keyboard, the current international standard (UNICODE) includes codes for characters from a variety of languages and alphabets (such as ê and ö). For simplicity, examples in this course will use only a part of this code, as given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;. This is confined to printable symbols that appear on a standard computer keyboard (for an English-speaking user).&lt;/p&gt;&lt;p&gt;We will denote by &lt;i&gt;Char&lt;/i&gt; the set of characters appearing in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;. We will call the codes in the table the &lt;b&gt;ASCII codes&lt;/b&gt; of the characters.&lt;/p&gt;&lt;p&gt;The original ASCII set (developed by ANSI, the American National Standards Institute) was finalised in 1968, and provides a basic (but by no means complete) character set for English. With the development of the Internet and a more global economy, efforts are being made to create a standard character set, catering more completely for many languages, and bringing together hundreds of incompatible standards from different countries. UNICODE is the result of this development, but it still only represents some of the written characters of our languages, currently standing at about 94,000 symbols. No existing character set caters for all languages.&lt;/p&gt;&lt;div class="oucontent-table oucontent-s-normal noborder oucontent-s-box" id="tab003"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Table 2: The ASCII encoding of characters (in part).&lt;/h2&gt;&lt;div class="oucontent-table-wrapper"&gt;&lt;table&gt;&lt;tr&gt;
&lt;th scope="col"&gt;Code&lt;/th&gt;
&lt;th scope="col"&gt;Character&lt;/th&gt;
&lt;th scope="col"&gt;Code&lt;/th&gt;
&lt;th scope="col"&gt;Character&lt;/th&gt;
&lt;th scope="col"&gt;Code&lt;/th&gt;
&lt;th scope="col"&gt;Character&lt;/th&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;32&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;64&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;@&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;96&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;'&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;33&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;!&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;65&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;A&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;97&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;a&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;34&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;"&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;66&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;B&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;98&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;b&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;35&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;#&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;67&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;C&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;99&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;c&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;36&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;$&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;68&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;D&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;100&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;d&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;37&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;%&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;69&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;E&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;101&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;e&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;38&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&amp;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;70&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;F&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;102&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;f&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;39&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;’&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;71&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;G&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;103&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;g&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;40&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;(&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;72&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;H&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;104&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;h&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;41&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;)&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;73&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;I&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;105&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;i&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;42&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;*&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;74&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;J&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;106&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;j&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;43&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;+&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;75&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;K&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;107&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;k&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;44&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;,&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;76&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;L&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;108&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;l&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;45&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;−&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;77&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;M&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;109&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;m&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;46&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;.&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;78&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;N&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;110&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;n&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;47&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;/&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;79&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;O&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;111&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;o&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;48&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;0&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;80&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;P&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;112&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;p&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;49&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;1&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;81&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;Q&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;113&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;q&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;50&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;2&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;82&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;R&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;114&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;r&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;51&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;3&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;83&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;S&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;115&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;s&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;52&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;4&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;84&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;T&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;116&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;t&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;53&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;5&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;85&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;U&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;117&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;u&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;54&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;6&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;86&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;V&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;118&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;v&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;55&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;7&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;87&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;W&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;119&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;w&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;56&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;8&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;88&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;X&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;120&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;x&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;57&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;9&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;89&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;Y&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;121&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;y&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;58&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;:&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;90&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;Z&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;122&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;z&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;59&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;91&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;[&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;123&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;{&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;60&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&lt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;92&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;\ &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/707a380c/backslash.gif" alt="" width="5" height="9" style="max-width:5px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;124&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;|&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;61&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;=&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;93&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;]&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;125&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;}&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;62&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;94&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;^&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;126&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;˜&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td class="oucontent-tablemiddle "&gt;63&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;?&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;95&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;–&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&lt;/td&gt;
&lt;td class="oucontent-tablemiddle "&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="oucontent-source-reference"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The character with ASCII code 32 is the space character, which, when we need to write it explicitly, will appear as ‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act005"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 4&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) What character has ASCII code 91?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) What are the ASCII codes of the characters ‘A’ and ‘a’?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) What is the ASCII code of the character ‘7’?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) The character ‘[’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) 65 and 97, respectively.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) 55.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>2.3 Truth values</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.3</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;We will want to distinguish between statements that are true and statements that are false. Another fundamental form of data allows us to do this. This form of data consists of just two values, which we shall write as &lt;b&gt;true&lt;/b&gt; and &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Not all texts use the same notation: some use &lt;b&gt;T&lt;/b&gt; and &lt;b&gt;F&lt;/b&gt;; others may use &lt;b&gt;0&lt;/b&gt; for &lt;b&gt;false&lt;/b&gt; and &lt;b&gt;1&lt;/b&gt; for &lt;b&gt;true&lt;/b&gt; (or the reverse!).&lt;/p&gt;&lt;p&gt;We may refer to &lt;b&gt;true&lt;/b&gt; and &lt;b&gt;false&lt;/b&gt; as truth values, or Boolean values. We will denote the collection (set) of truth values as &lt;i&gt;Bool&lt;/i&gt;, after the mathematician George Boole. We write:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo001"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;Bool&lt;/i&gt; = {&lt;b&gt;true&lt;/b&gt;, &lt;b&gt;false&lt;/b&gt;}.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;This shows the collection &lt;i&gt;Bool&lt;/i&gt; as a set. We have already mentioned the word set in passing, and now want to look at this concept in more detail.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.3</guid>
    <dc:title>2.3 Truth values</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;We will want to distinguish between statements that are true and statements that are false. Another fundamental form of data allows us to do this. This form of data consists of just two values, which we shall write as &lt;b&gt;true&lt;/b&gt; and &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Not all texts use the same notation: some use &lt;b&gt;T&lt;/b&gt; and &lt;b&gt;F&lt;/b&gt;; others may use &lt;b&gt;0&lt;/b&gt; for &lt;b&gt;false&lt;/b&gt; and &lt;b&gt;1&lt;/b&gt; for &lt;b&gt;true&lt;/b&gt; (or the reverse!).&lt;/p&gt;&lt;p&gt;We may refer to &lt;b&gt;true&lt;/b&gt; and &lt;b&gt;false&lt;/b&gt; as truth values, or Boolean values. We will denote the collection (set) of truth values as &lt;i&gt;Bool&lt;/i&gt;, after the mathematician George Boole. We write:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo001"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;Bool&lt;/i&gt; = {&lt;b&gt;true&lt;/b&gt;, &lt;b&gt;false&lt;/b&gt;}.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;This shows the collection &lt;i&gt;Bool&lt;/i&gt; as a set. We have already mentioned the word set in passing, and now want to look at this concept in more detail.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>2.4 Sets</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.4</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;A set is a collection of items, and is a collection of a particular form. The items appearing in a set are referred to as the &lt;b&gt;elements&lt;/b&gt; (or &lt;b&gt;members&lt;/b&gt;) of the set. Examples of sets mentioned earlier are: &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;Char&lt;/i&gt; and &lt;i&gt;Bool&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;A &lt;b&gt;set&lt;/b&gt; is a collection in which repetition is not significant, nor is the order in which the items are given. For example, the supermarket might sell its own brand of Wheat Flakes in three sizes: large, medium and small. In a situation where we are interested in the types of product that are available, we are interested in the set of sizes. This set of sizes may be written as:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo002"&gt;&lt;blockquote&gt;&lt;p&gt;{large, medium, small}.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;We might choose to name the set:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo003"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;Sizes&lt;/i&gt; = {large, medium, small}.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;The order in which the elements are listed is of no significance, so we might equally well have written &lt;i&gt;Sizes&lt;/i&gt; = {small, medium, large}.&lt;/p&gt;&lt;p&gt;Notice the use of curly brackets {and} here. These are used as a signal that the collection is a set (as distinct from some other form of collection, such as a sequence). Note too the commas used to separate the elements.&lt;/p&gt;&lt;p&gt;We would not usually give any repetitions when writing a set, but if one were to do so, repetition of an element would be of no significance. We could write a set as&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo004"&gt;&lt;blockquote&gt;&lt;p&gt;{large, small, large, medium, small}&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;but this set is the same as &lt;i&gt;Sizes&lt;/i&gt; and has three members, not five!&lt;/p&gt;&lt;p&gt;We write &lt;i&gt;a&lt;/i&gt; &amp;#x2208; &lt;i&gt;X&lt;/i&gt; to mean that the item &lt;i&gt;a&lt;/i&gt; is a member of the set &lt;i&gt;X&lt;/i&gt; (we say &amp;#x201C;&lt;i&gt;a&lt;/i&gt; is in the set &lt;i&gt;X&lt;/i&gt;&amp;#x201D;, or just &amp;#x201C;&lt;i&gt;a&lt;/i&gt; is in &lt;i&gt;X&lt;/i&gt;&amp;#x201D;). So, for example, we might write small &amp;#x2208; &lt;i&gt;Sizes&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;It was easy to write out the set &lt;i&gt;Sizes&lt;/i&gt; in full because it has only three elements. Imagine having to write out the set of all barcodes used at a large supermarket. It would not be practicable! We have another notation for such sets, that is sets whose members can be precisely described. Suppose that, a little unrealistically, a store (YtoZ Groceries) stocks just 90000 items, which happen to have barcodes that are consecutive integers between 10000 and 99999. Then the set of barcodes used by the store may be written:&lt;/p&gt;&lt;p&gt;&lt;i&gt;YtoZBarcodes&lt;/i&gt; = { &lt;i&gt;n&lt;/i&gt; &amp;#x2208; &lt;i&gt;Int&lt;/i&gt; : 10000 &amp;#x2264; &lt;i&gt;n&lt;/i&gt; and &lt;i&gt;n&lt;/i&gt; &amp;#x2264; 99999}.&lt;/p&gt;&lt;p&gt;A rather literal reading of this notation would be: &amp;#x201C;&lt;i&gt;YtoZBarcodes&lt;/i&gt; is the set of values, &lt;i&gt;n&lt;/i&gt;, in the set of integers, such that &lt;i&gt;n&lt;/i&gt; is greater than or equal to 10000 and less than or equal to 99999.&amp;#x201D;. (We read the first curly bracket as &amp;#x201C;the set of&amp;#x201D; and the colon as &amp;#x201C;such that&amp;#x201D;.) More casually, we might say: &amp;#x201C;&lt;i&gt;YtoZBarcodes&lt;/i&gt; is the set of integers between 10000 and 99999, inclusive.&amp;#x201D;. (The word inclusive makes it clear that the numbers 10000 and 99999 are each included in the set.)&lt;/p&gt;&lt;p&gt;Alternatively, the condition 10000 &amp;#x2264; &lt;i&gt;n&lt;/i&gt; and &lt;i&gt;n&lt;/i&gt; &amp;#x2264; 99999 can be written as 10000 &amp;#x2264; &lt;i&gt;n&lt;/i&gt; &amp;#x2264; 99999.&lt;/p&gt;&lt;p&gt;A set need not have any members. (The set {&lt;i&gt;n&lt;/i&gt; &amp;#x2208; &lt;i&gt;Int : n&lt;/i&gt; &amp;gt; 100 and &lt;i&gt;n&lt;/i&gt; &amp;lt; 50} is an example of a set with no members.) A set with no members is called an &lt;b&gt;empty set&lt;/b&gt;. We will write this as { }.&lt;/p&gt;&lt;p&gt;Sometimes we need to say how many elements there are in a set. For example, the set &lt;i&gt;Sizes&lt;/i&gt;, as above, has 3 elements, while the set &lt;i&gt;YtoZBarcodes&lt;/i&gt; has 90000 members. The number of elements in a set is called the &lt;b&gt;cardinality&lt;/b&gt; of the set. The cardinality of the empty set is 0. (We shall only talk about the cardinality of a finite set. The set &lt;i&gt;Int&lt;/i&gt;, for example, does not have a finite number of elements.) If the members of a set have been written out with some elements repeated, then remember to count each repeated element only once when finding the set's cardinality. In other texts, you may see the symbol &amp;#x2205; used to denote an empty set.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act006"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 5&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Write out in full the set {&lt;i&gt;n&lt;/i&gt; &amp;#x2208; &lt;i&gt;Int&lt;/i&gt; : 5 &amp;#x2264; &lt;i&gt;n&lt;/i&gt; and &lt;i&gt;n&lt;/i&gt; &amp;lt; 9}.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Write out in full the set {&lt;i&gt;c&lt;/i&gt; &amp;#x2208; &lt;i&gt;Char&lt;/i&gt; : the ASCII code of &lt;i&gt;c&lt;/i&gt; is between 40 and 43, inclusive}.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Which of the following is true?&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) 7 &amp;#x2208; &lt;i&gt;Int.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &amp;#x2018;7’ &amp;#x2208; &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) Let &lt;i&gt;Lowercase&lt;/i&gt; = {&lt;i&gt;c&lt;/i&gt; &amp;#x2208; &lt;i&gt;Char&lt;/i&gt; : the ASCII code of &lt;i&gt;c&lt;/i&gt; is strictly greater than 96 and strictly less than 123}.&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) Is &amp;#x2018;C’ &amp;#x2208; &lt;i&gt;Lowercase&lt;/i&gt; true?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) What is the cardinality of the set &lt;i&gt;Lowercase&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) Let &lt;i&gt;A&lt;/i&gt; be the set of characters that appear in the string &amp;#x201C;aardvark&amp;#x201D;. What is the cardinality of &lt;i&gt;A&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This set contains those integers that are both greater than or equal to 5, and strictly less than 9. We can write this set in full as {5, 6, 7, 8}. (Alternatively, it could be written with the elements in some other order, such as {8, 7, 5, 6}.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) {&amp;#x2018;(&amp;#x2018;, &amp;#x2018;)’, &amp;#x2018;*’, &amp;#x2018;+’}. (Remember that we write characters in single inverted commas.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) 7 is an integer, but &amp;#x2018;7’ is a character. So 7 &amp;#x2208; &lt;i&gt;Int&lt;/i&gt; is true, but &amp;#x2018;7’ &amp;#x2208; &lt;i&gt;Int&lt;/i&gt; is false.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) (i) The ASCII code of &amp;#x2018;C’ is 67 and so &amp;#x2018;C’ is not a member of the set &lt;i&gt;Lowercase&lt;/i&gt;. So &amp;#x2018;C’ &amp;#x2208; &lt;i&gt;Lowercase&lt;/i&gt; is false.&lt;/p&gt; &lt;p&gt;(ii) There are 26 integers which are strictly greater than 96 and strictly less than 123. So &lt;i&gt;Lowercase&lt;/i&gt; has cardinality 26.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) The set of characters that appear in the string &amp;#x201C;aardvark&amp;#x201D; is: {&amp;#x2018;a’, &amp;#x2018;r’, &amp;#x2018;d’, &amp;#x2018;v’, &amp;#x2018;k’}. This set has cardinality 5.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.4</guid>
    <dc:title>2.4 Sets</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;A set is a collection of items, and is a collection of a particular form. The items appearing in a set are referred to as the &lt;b&gt;elements&lt;/b&gt; (or &lt;b&gt;members&lt;/b&gt;) of the set. Examples of sets mentioned earlier are: &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;Char&lt;/i&gt; and &lt;i&gt;Bool&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;A &lt;b&gt;set&lt;/b&gt; is a collection in which repetition is not significant, nor is the order in which the items are given. For example, the supermarket might sell its own brand of Wheat Flakes in three sizes: large, medium and small. In a situation where we are interested in the types of product that are available, we are interested in the set of sizes. This set of sizes may be written as:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo002"&gt;&lt;blockquote&gt;&lt;p&gt;{large, medium, small}.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;We might choose to name the set:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo003"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;Sizes&lt;/i&gt; = {large, medium, small}.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;The order in which the elements are listed is of no significance, so we might equally well have written &lt;i&gt;Sizes&lt;/i&gt; = {small, medium, large}.&lt;/p&gt;&lt;p&gt;Notice the use of curly brackets {and} here. These are used as a signal that the collection is a set (as distinct from some other form of collection, such as a sequence). Note too the commas used to separate the elements.&lt;/p&gt;&lt;p&gt;We would not usually give any repetitions when writing a set, but if one were to do so, repetition of an element would be of no significance. We could write a set as&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo004"&gt;&lt;blockquote&gt;&lt;p&gt;{large, small, large, medium, small}&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;but this set is the same as &lt;i&gt;Sizes&lt;/i&gt; and has three members, not five!&lt;/p&gt;&lt;p&gt;We write &lt;i&gt;a&lt;/i&gt; ∈ &lt;i&gt;X&lt;/i&gt; to mean that the item &lt;i&gt;a&lt;/i&gt; is a member of the set &lt;i&gt;X&lt;/i&gt; (we say “&lt;i&gt;a&lt;/i&gt; is in the set &lt;i&gt;X&lt;/i&gt;”, or just “&lt;i&gt;a&lt;/i&gt; is in &lt;i&gt;X&lt;/i&gt;”). So, for example, we might write small ∈ &lt;i&gt;Sizes&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;It was easy to write out the set &lt;i&gt;Sizes&lt;/i&gt; in full because it has only three elements. Imagine having to write out the set of all barcodes used at a large supermarket. It would not be practicable! We have another notation for such sets, that is sets whose members can be precisely described. Suppose that, a little unrealistically, a store (YtoZ Groceries) stocks just 90000 items, which happen to have barcodes that are consecutive integers between 10000 and 99999. Then the set of barcodes used by the store may be written:&lt;/p&gt;&lt;p&gt;&lt;i&gt;YtoZBarcodes&lt;/i&gt; = { &lt;i&gt;n&lt;/i&gt; ∈ &lt;i&gt;Int&lt;/i&gt; : 10000 ≤ &lt;i&gt;n&lt;/i&gt; and &lt;i&gt;n&lt;/i&gt; ≤ 99999}.&lt;/p&gt;&lt;p&gt;A rather literal reading of this notation would be: “&lt;i&gt;YtoZBarcodes&lt;/i&gt; is the set of values, &lt;i&gt;n&lt;/i&gt;, in the set of integers, such that &lt;i&gt;n&lt;/i&gt; is greater than or equal to 10000 and less than or equal to 99999.”. (We read the first curly bracket as “the set of” and the colon as “such that”.) More casually, we might say: “&lt;i&gt;YtoZBarcodes&lt;/i&gt; is the set of integers between 10000 and 99999, inclusive.”. (The word inclusive makes it clear that the numbers 10000 and 99999 are each included in the set.)&lt;/p&gt;&lt;p&gt;Alternatively, the condition 10000 ≤ &lt;i&gt;n&lt;/i&gt; and &lt;i&gt;n&lt;/i&gt; ≤ 99999 can be written as 10000 ≤ &lt;i&gt;n&lt;/i&gt; ≤ 99999.&lt;/p&gt;&lt;p&gt;A set need not have any members. (The set {&lt;i&gt;n&lt;/i&gt; ∈ &lt;i&gt;Int : n&lt;/i&gt; &gt; 100 and &lt;i&gt;n&lt;/i&gt; &lt; 50} is an example of a set with no members.) A set with no members is called an &lt;b&gt;empty set&lt;/b&gt;. We will write this as { }.&lt;/p&gt;&lt;p&gt;Sometimes we need to say how many elements there are in a set. For example, the set &lt;i&gt;Sizes&lt;/i&gt;, as above, has 3 elements, while the set &lt;i&gt;YtoZBarcodes&lt;/i&gt; has 90000 members. The number of elements in a set is called the &lt;b&gt;cardinality&lt;/b&gt; of the set. The cardinality of the empty set is 0. (We shall only talk about the cardinality of a finite set. The set &lt;i&gt;Int&lt;/i&gt;, for example, does not have a finite number of elements.) If the members of a set have been written out with some elements repeated, then remember to count each repeated element only once when finding the set's cardinality. In other texts, you may see the symbol ∅ used to denote an empty set.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act006"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 5&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Write out in full the set {&lt;i&gt;n&lt;/i&gt; ∈ &lt;i&gt;Int&lt;/i&gt; : 5 ≤ &lt;i&gt;n&lt;/i&gt; and &lt;i&gt;n&lt;/i&gt; &lt; 9}.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Write out in full the set {&lt;i&gt;c&lt;/i&gt; ∈ &lt;i&gt;Char&lt;/i&gt; : the ASCII code of &lt;i&gt;c&lt;/i&gt; is between 40 and 43, inclusive}.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Which of the following is true?&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) 7 ∈ &lt;i&gt;Int.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) ‘7’ ∈ &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) Let &lt;i&gt;Lowercase&lt;/i&gt; = {&lt;i&gt;c&lt;/i&gt; ∈ &lt;i&gt;Char&lt;/i&gt; : the ASCII code of &lt;i&gt;c&lt;/i&gt; is strictly greater than 96 and strictly less than 123}.&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) Is ‘C’ ∈ &lt;i&gt;Lowercase&lt;/i&gt; true?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) What is the cardinality of the set &lt;i&gt;Lowercase&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) Let &lt;i&gt;A&lt;/i&gt; be the set of characters that appear in the string “aardvark”. What is the cardinality of &lt;i&gt;A&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This set contains those integers that are both greater than or equal to 5, and strictly less than 9. We can write this set in full as {5, 6, 7, 8}. (Alternatively, it could be written with the elements in some other order, such as {8, 7, 5, 6}.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) {‘(‘, ‘)’, ‘*’, ‘+’}. (Remember that we write characters in single inverted commas.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) 7 is an integer, but ‘7’ is a character. So 7 ∈ &lt;i&gt;Int&lt;/i&gt; is true, but ‘7’ ∈ &lt;i&gt;Int&lt;/i&gt; is false.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) (i) The ASCII code of ‘C’ is 67 and so ‘C’ is not a member of the set &lt;i&gt;Lowercase&lt;/i&gt;. So ‘C’ ∈ &lt;i&gt;Lowercase&lt;/i&gt; is false.&lt;/p&gt; &lt;p&gt;(ii) There are 26 integers which are strictly greater than 96 and strictly less than 123. So &lt;i&gt;Lowercase&lt;/i&gt; has cardinality 26.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) The set of characters that appear in the string “aardvark” is: {‘a’, ‘r’, ‘d’, ‘v’, ‘k’}. This set has cardinality 5.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>2.5 Sequences</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.5</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;You have already met sequences briefly, and have seen that a sequence contains items given in a particular order, and that repetitions are of significance.&lt;/p&gt;&lt;p&gt;One might have a sequence containing integers, such as [22, &amp;#x2212;31, 44, 0, 2, 0, 11] or a sequence containing characters, such as [&amp;#x2018;W’,&amp;#x2018;o’,&amp;#x2018;r’,&amp;#x2018;d’]. However, we will aim to avoid mixing the forms of data in a sequence. A sequence of characters may also be referred to as a string, and that &amp;#x201C;Word&amp;#x201D; is another notation for the sequence [&amp;#x2018;W’,&amp;#x2018;o’,&amp;#x2018;r’,&amp;#x2018;d’].&lt;/p&gt;&lt;p&gt;The items in a sequence are enumerated from the left. Thus in the sequence [&amp;#x2018;W’,&amp;#x2018;o’,&amp;#x2018;r’,&amp;#x2018;d’], the first item is &amp;#x2018;W’, the second item is &amp;#x2018;o’, and so on. The items in a sequence may also be referred to as the &lt;b&gt;elements&lt;/b&gt; (or sometimes &lt;b&gt;members&lt;/b&gt;) of the sequence. The number of items in a sequence is called its &lt;b&gt;length&lt;/b&gt;. So, for example, the length of the sequence [&amp;#x2018;W’,&amp;#x2018;o’,&amp;#x2018;r’,&amp;#x2018;d’] is 4. &lt;/p&gt;&lt;p&gt;We do count repeated items when calculating the length of a sequence. So, for example, the sequence of numbers [22, &amp;#x2212;31, 44, 0, 2, 0, 11] has length 7, while the sequence of characters &amp;#x201C;aardvark&amp;#x201D; has length 8.&lt;/p&gt;&lt;p&gt;Incidentally, we are only concerned in this course with &lt;b&gt;finite&lt;/b&gt; sequences. If you study mathematics in other contexts, you may meet sequences that &amp;#x201C;go on forever&amp;#x201D;, such as the sequence of real numbers: 1, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/c513c058/m263_1_i003e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/98a36168/m263_1_i004e.gif" alt="" width="10" height="26" style="max-width:10px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/21abde66/m263_1_i005e.gif" alt="" width="10" height="26" style="max-width:10px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, ... (where the general term is &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/2fabf825/m263_1_i006e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; where &lt;i&gt;n&lt;/i&gt; is a positive integer). Any form of data stored on a computer as a sequence will contain a finite number of items, so a sequence describing a form of data stored on a computer will be finite. A finite sequence will have a length that is a positive integer.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act007"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 6&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Let &lt;i&gt;s&lt;/i&gt; be the sequence &lt;i&gt;s&lt;/i&gt; = [44, 21, 77, 77, 41].&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) What is the third member of &lt;i&gt;s&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) What is the fourth member of &lt;i&gt;s&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) What is the length of &lt;i&gt;s&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Let &lt;i&gt;t&lt;/i&gt; be the sequence of characters &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;This sentence.&amp;#x201D;&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) What is the fifth member of &lt;i&gt;t&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) What is the length of &lt;i&gt;t&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) What is the fifteenth member of &lt;i&gt;t&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Let &lt;i&gt;A&lt;/i&gt; be the set of items appearing in the sequence &lt;i&gt;s&lt;/i&gt; = [41, 21, 77, 77, 41]. What is the cardinality of &lt;i&gt;A&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) The third member of &lt;i&gt;s&lt;/i&gt; is 77.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) The fourth member of &lt;i&gt;s&lt;/i&gt; is also 77.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) The sequence &lt;i&gt;s&lt;/i&gt; contains 5 items, so the length of &lt;i&gt;s&lt;/i&gt; is 5.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) The fifth member of &lt;i&gt;t&lt;/i&gt; is the space character, which we write as &amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) The length of &lt;i&gt;t&lt;/i&gt; is 14. (You need to count the space character and the full stop as well as the letters.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) There is no fifteenth character in &lt;i&gt;t&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) The set &lt;i&gt;A&lt;/i&gt; takes no notice of the order in which the items appear in &lt;i&gt;s&lt;/i&gt;, nor of repeated items. The set &lt;i&gt;A&lt;/i&gt; is {21, 41, 77}, and this has cardinality 3.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The set A could equally well be written as {41, 21, 77}, for example.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;We have introduced notations for the set of all integers, &lt;i&gt;Int&lt;/i&gt;, and for the set of characters, &lt;i&gt;Char&lt;/i&gt;. It is convenient also to have a notation for sequences. This will need to tell us two things: first, that we are referring to a set of sequences; and second, the set from which the members of the sequence come. Thus we write &lt;i&gt;SeqOfInt&lt;/i&gt; for the set of all sequences of integers. So, for example, [22, &amp;#x2212;31, 44, 0, 2, 0, 11] is in &lt;i&gt;SeqOfInt&lt;/i&gt;. Similarly, we write &lt;i&gt;SeqOfChar&lt;/i&gt; for the set of all sequences of characters. The sequence [&amp;#x2018;W’,&amp;#x2018;o’,&amp;#x2018;r’,&amp;#x2018;d’] is in &lt;i&gt;SeqOfChar&lt;/i&gt; (and not in &lt;i&gt;SeqOfInt&lt;/i&gt;), because it is a sequence that contains characters, not integers.&lt;/p&gt;&lt;p&gt;There are a couple of points to note here. First, the number 22 is not in &lt;i&gt;SeqOfInt&lt;/i&gt;, because 22 is not a sequence, it is an integer. However, [22] is in &lt;i&gt;SeqOfInt&lt;/i&gt;. This is a sequence that happens to contain just one integer. Second, both &lt;i&gt;SeqOfInt&lt;/i&gt; and &lt;i&gt;SeqOfChar&lt;/i&gt; include an empty sequence, [].&lt;/p&gt;&lt;p&gt;More generally, we write &lt;i&gt;SeqOfX&lt;/i&gt; for the set containing all sequences of items from the set &lt;i&gt;X&lt;/i&gt;. Here &lt;i&gt;X&lt;/i&gt; might be any set. For example, &lt;i&gt;SeqOfBool&lt;/i&gt; contains all sequences whose members are from &lt;i&gt;Bool&lt;/i&gt;, that is, whose members are Boolean values.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act008"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 7&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) Is &amp;#x2018;a’ in the set &lt;i&gt;SeqOfChar&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) Is &amp;#x201C;a&amp;#x201D; in the set &lt;i&gt;SeqOfChar&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Give an example of a member of the set &lt;i&gt;SeqOfBool&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) No. The single quotes here show that &amp;#x2018;a’ is a character, from the set &lt;i&gt;Char&lt;/i&gt;. Just as there is a distinction between a single integer such as 22 and a sequence containing one integer such as [22], there is a corresponding distinction between a single character and a sequence containing one character.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) The double quotes here show we have a string; that is, a sequence of characters. So &amp;#x201C;a&amp;#x201D; is in &lt;i&gt;SeqOfChar&lt;/i&gt;. The notation &amp;#x201C;a&amp;#x201D; means the same as [&amp;#x2018;a’]: each is the sequence containing the single character &amp;#x2018;a’.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) A suitable example is [&lt;b&gt;true&lt;/b&gt;, &lt;b&gt;true&lt;/b&gt;, &lt;b&gt;false&lt;/b&gt;, &lt;b&gt;true&lt;/b&gt;], but there are an infinite number of possible examples (including, if you chose to be contrary, the empty sequence [ ], containing no Boolean values!).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.5</guid>
    <dc:title>2.5 Sequences</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;You have already met sequences briefly, and have seen that a sequence contains items given in a particular order, and that repetitions are of significance.&lt;/p&gt;&lt;p&gt;One might have a sequence containing integers, such as [22, −31, 44, 0, 2, 0, 11] or a sequence containing characters, such as [‘W’,‘o’,‘r’,‘d’]. However, we will aim to avoid mixing the forms of data in a sequence. A sequence of characters may also be referred to as a string, and that “Word” is another notation for the sequence [‘W’,‘o’,‘r’,‘d’].&lt;/p&gt;&lt;p&gt;The items in a sequence are enumerated from the left. Thus in the sequence [‘W’,‘o’,‘r’,‘d’], the first item is ‘W’, the second item is ‘o’, and so on. The items in a sequence may also be referred to as the &lt;b&gt;elements&lt;/b&gt; (or sometimes &lt;b&gt;members&lt;/b&gt;) of the sequence. The number of items in a sequence is called its &lt;b&gt;length&lt;/b&gt;. So, for example, the length of the sequence [‘W’,‘o’,‘r’,‘d’] is 4. &lt;/p&gt;&lt;p&gt;We do count repeated items when calculating the length of a sequence. So, for example, the sequence of numbers [22, −31, 44, 0, 2, 0, 11] has length 7, while the sequence of characters “aardvark” has length 8.&lt;/p&gt;&lt;p&gt;Incidentally, we are only concerned in this course with &lt;b&gt;finite&lt;/b&gt; sequences. If you study mathematics in other contexts, you may meet sequences that “go on forever”, such as the sequence of real numbers: 1, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/c513c058/m263_1_i003e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/98a36168/m263_1_i004e.gif" alt="" width="10" height="26" style="max-width:10px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/e00cd7a9/m263_1_i002e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/21abde66/m263_1_i005e.gif" alt="" width="10" height="26" style="max-width:10px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;, ... (where the general term is &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/2fabf825/m263_1_i006e.gif" alt="" width="12" height="26" style="max-width:12px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; where &lt;i&gt;n&lt;/i&gt; is a positive integer). Any form of data stored on a computer as a sequence will contain a finite number of items, so a sequence describing a form of data stored on a computer will be finite. A finite sequence will have a length that is a positive integer.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act007"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 6&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Let &lt;i&gt;s&lt;/i&gt; be the sequence &lt;i&gt;s&lt;/i&gt; = [44, 21, 77, 77, 41].&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) What is the third member of &lt;i&gt;s&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) What is the fourth member of &lt;i&gt;s&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) What is the length of &lt;i&gt;s&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Let &lt;i&gt;t&lt;/i&gt; be the sequence of characters &lt;i&gt;t&lt;/i&gt; = “This sentence.”&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) What is the fifth member of &lt;i&gt;t&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) What is the length of &lt;i&gt;t&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) What is the fifteenth member of &lt;i&gt;t&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Let &lt;i&gt;A&lt;/i&gt; be the set of items appearing in the sequence &lt;i&gt;s&lt;/i&gt; = [41, 21, 77, 77, 41]. What is the cardinality of &lt;i&gt;A&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) The third member of &lt;i&gt;s&lt;/i&gt; is 77.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) The fourth member of &lt;i&gt;s&lt;/i&gt; is also 77.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) The sequence &lt;i&gt;s&lt;/i&gt; contains 5 items, so the length of &lt;i&gt;s&lt;/i&gt; is 5.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) The fifth member of &lt;i&gt;t&lt;/i&gt; is the space character, which we write as ‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) The length of &lt;i&gt;t&lt;/i&gt; is 14. (You need to count the space character and the full stop as well as the letters.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) There is no fifteenth character in &lt;i&gt;t&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) The set &lt;i&gt;A&lt;/i&gt; takes no notice of the order in which the items appear in &lt;i&gt;s&lt;/i&gt;, nor of repeated items. The set &lt;i&gt;A&lt;/i&gt; is {21, 41, 77}, and this has cardinality 3.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The set A could equally well be written as {41, 21, 77}, for example.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;We have introduced notations for the set of all integers, &lt;i&gt;Int&lt;/i&gt;, and for the set of characters, &lt;i&gt;Char&lt;/i&gt;. It is convenient also to have a notation for sequences. This will need to tell us two things: first, that we are referring to a set of sequences; and second, the set from which the members of the sequence come. Thus we write &lt;i&gt;SeqOfInt&lt;/i&gt; for the set of all sequences of integers. So, for example, [22, −31, 44, 0, 2, 0, 11] is in &lt;i&gt;SeqOfInt&lt;/i&gt;. Similarly, we write &lt;i&gt;SeqOfChar&lt;/i&gt; for the set of all sequences of characters. The sequence [‘W’,‘o’,‘r’,‘d’] is in &lt;i&gt;SeqOfChar&lt;/i&gt; (and not in &lt;i&gt;SeqOfInt&lt;/i&gt;), because it is a sequence that contains characters, not integers.&lt;/p&gt;&lt;p&gt;There are a couple of points to note here. First, the number 22 is not in &lt;i&gt;SeqOfInt&lt;/i&gt;, because 22 is not a sequence, it is an integer. However, [22] is in &lt;i&gt;SeqOfInt&lt;/i&gt;. This is a sequence that happens to contain just one integer. Second, both &lt;i&gt;SeqOfInt&lt;/i&gt; and &lt;i&gt;SeqOfChar&lt;/i&gt; include an empty sequence, [].&lt;/p&gt;&lt;p&gt;More generally, we write &lt;i&gt;SeqOfX&lt;/i&gt; for the set containing all sequences of items from the set &lt;i&gt;X&lt;/i&gt;. Here &lt;i&gt;X&lt;/i&gt; might be any set. For example, &lt;i&gt;SeqOfBool&lt;/i&gt; contains all sequences whose members are from &lt;i&gt;Bool&lt;/i&gt;, that is, whose members are Boolean values.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act008"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 7&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) Is ‘a’ in the set &lt;i&gt;SeqOfChar&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) Is “a” in the set &lt;i&gt;SeqOfChar&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Give an example of a member of the set &lt;i&gt;SeqOfBool&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;(i) No. The single quotes here show that ‘a’ is a character, from the set &lt;i&gt;Char&lt;/i&gt;. Just as there is a distinction between a single integer such as 22 and a sequence containing one integer such as [22], there is a corresponding distinction between a single character and a sequence containing one character.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) The double quotes here show we have a string; that is, a sequence of characters. So “a” is in &lt;i&gt;SeqOfChar&lt;/i&gt;. The notation “a” means the same as [‘a’]: each is the sequence containing the single character ‘a’.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) A suitable example is [&lt;b&gt;true&lt;/b&gt;, &lt;b&gt;true&lt;/b&gt;, &lt;b&gt;false&lt;/b&gt;, &lt;b&gt;true&lt;/b&gt;], but there are an infinite number of possible examples (including, if you chose to be contrary, the empty sequence [ ], containing no Boolean values!).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>2.6 Associations: tuples and Cartesian products</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.6</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Consider an item of shopping that is weighed at the supermarket checkout, such as 335 grams of walnuts. This item of shopping has two features: the type of item purchased (walnuts), and the weight of that item (335 grams). To record a weighed item of shopping we need to note both these features. This can be done using an ordered pair: (&amp;#x201C;WALNUTS&amp;#x201D;, 335).&lt;/p&gt;&lt;p&gt;The first item in this ordered pair gives the type of item purchased. Let &lt;i&gt;WeighedItems&lt;/i&gt; be the set of items stocked by the supermarket that need to be weighed. The first item comes from this set, while the second item in the ordered pair comes from the set &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;We call the set containing all such pairs the &lt;b&gt;Cartesian product&lt;/b&gt; of the two sets. (&amp;#x2018;Cartesian’ after the famous French philosopher and mathematician Ren&amp;#xE9; Descartes.) This set of pairs is written as &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;. So the set &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt; consists of all pairs (&lt;i&gt;w, n&lt;/i&gt;), where &lt;i&gt;w&lt;/i&gt; comes from the set &lt;i&gt;WeighedItems&lt;/i&gt;, and &lt;i&gt;n&lt;/i&gt; comes from the set &lt;i&gt;Int&lt;/i&gt;. We refer to (&lt;i&gt;w, n&lt;/i&gt;) as an &lt;b&gt;ordered pair&lt;/b&gt;. The word pair here indicates that there are two items grouped together. The word ordered indicates that the order in which the two items are given matters. The pair (&amp;#x201C;WALNUTS&amp;#x201D;, 335) is not the same as the pair (335, &amp;#x201C;WALNUTS&amp;#x201D;). Similarly, the set &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt; is different from the set &lt;i&gt;Int &amp;#xD7; WeighedItems&lt;/i&gt;, which consists of pairs giving: first an integer, then a type of weighed item.&lt;/p&gt;&lt;p&gt;Use of the symbol &amp;#xD7; here has nothing to do with multiplication of numbers!&lt;/p&gt;&lt;p&gt;We can form the Cartesian product of any two sets. The Cartesian product of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; is written as &lt;i&gt;X &amp;#xD7; Y&lt;/i&gt; , and consists of all ordered pairs (&lt;i&gt;x, y&lt;/i&gt;) where &lt;i&gt;x&lt;/i&gt; is from the set &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; is from the set &lt;i&gt;Y&lt;/i&gt;. &lt;i&gt;X&lt;/i&gt; &amp;#xD7; &lt;i&gt;Y&lt;/i&gt; can be read as &amp;#x201C; &lt;i&gt;X&lt;/i&gt; cross &lt;i&gt;Y&lt;/i&gt;&amp;#x201D;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;An ordered pair gives an association between two items. There are situations where we may want to associate more than two things. Consider items stocked by the supermarket that have barcodes. The supermarket will be interested in a number of features associated with each item of this type. Three such features are:&lt;/p&gt;&lt;ol class="oucontent-numbered"&gt;&lt;li&gt;&lt;p&gt;The barcode (taken to be an integer).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The name of the item, to be printed on the till receipt (as a string).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The price of an item of this type (taken to be an integer number of pence).&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;A natural way to associate these three features is to write them together as an &lt;b&gt;ordered triple&lt;/b&gt;, or &lt;b&gt;3-tuple&lt;/b&gt;, such as (13151, &amp;#x201C;ORGANIC SOUP&amp;#x201D;, 179). Note the use of round brackets here. These are used for tuples, in distinction to square brackets [ and ] for sequences, or curly brackets { and } for sets. The terminology &amp;#x2018;ordered triple’ indicates that we are now writing three items, each from a specified set, in a given order. We may want to associate four items, or five, or more. The terminology &amp;#x2018;tuple’ extends conveniently to this general case, where we talk about 4-tuples, or 5-tuples, and, in general, &lt;b&gt; &lt;i&gt;n&lt;/i&gt;-tuples&lt;/b&gt; (where &lt;i&gt;n&lt;/i&gt; might be 2, or 3, or any larger integer).&lt;/p&gt;&lt;p&gt;The set of all 3-tuples of the same form as (13151, &amp;#x201C;ORGANIC SOUP&amp;#x201D;, 179) is again a Cartesian product, in this case a product of three sets. The barcode is from &lt;i&gt;Int&lt;/i&gt;, the item name is a string (from &lt;i&gt;SeqOfChar&lt;/i&gt;) and the price is an integer. So this 3-tuple comes from the set &lt;i&gt;Int &amp;#xD7; SeqOfChar &amp;#xD7; Int&lt;/i&gt;.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act009"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 8&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Taking the code for olive oil as 43202, and referring to the receipt in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt;, write down the ordered triple from the set &lt;i&gt;Int &amp;#xD7; SeqOfChar &amp;#xD7; Int&lt;/i&gt; that represents the association between the code, the description and the price of the olive oil.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Making sure that the description is written as a string, and that the price is in pence, the triple should be (43202, &amp;#x201C;OLIVE OIL&amp;#x201D;, 178).&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;As another example, suppose that a shop has just three members of staff, Jo, Jessica and Wesley, and just two tills, &lt;i&gt;T1&lt;/i&gt; and &lt;i&gt;T2&lt;/i&gt;. We could represent a situation where Jo is operating the till &lt;i&gt;T2&lt;/i&gt; by the ordered pair, or 2-tuple (&lt;i&gt;T2&lt;/i&gt;, Jo). Clearly, there are a variety of ways in which a member of staff can be assigned to a till. If &lt;i&gt;Tills&lt;/i&gt; is the set {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;} and &lt;i&gt;Staff&lt;/i&gt; is the set {Jo, Jessica, Wesley}, then the set of all possible assignments of a member of staff to a till is &lt;i&gt;Tills &amp;#xD7; Staff&lt;/i&gt; . If we write this set out in full, we obtain:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Tills &amp;#xD7; Staff&lt;/i&gt; = {(&lt;i&gt;T1&lt;/i&gt;, Jo), (&lt;i&gt;T1&lt;/i&gt;, Jessica), (&lt;i&gt;T1&lt;/i&gt;, Wesley), (&lt;i&gt;T2&lt;/i&gt;, Jo), (&lt;i&gt;T2&lt;/i&gt;, Jessica), (&lt;i&gt;T2&lt;/i&gt;, Wesley)}.&lt;/p&gt;&lt;p&gt;Note the use of different brackets: curly brackets delimit the set, round brackets delimit each of the tuples. Note also that the use of &lt;i&gt;Tills &amp;#xD7; Staff&lt;/i&gt; to represent assignment of a staff member to a till means that we must write the till first in each ordered pair.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act010"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 9&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give an example of a member of the set &lt;i&gt;Staff &amp;#xD7; Tills&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) If the supermarket were to install another till, and recruit two more members of staff, and we redefine the sets &lt;i&gt;Staff&lt;/i&gt; and &lt;i&gt;Tills&lt;/i&gt; to include these, how many ordered pairs would be in the set &lt;i&gt;Tills &amp;#xD7; Staff&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) In &lt;i&gt;Staff &amp;#xD7; Tills&lt;/i&gt;, the member of staff should be given first. Suitable examples would be (Jo, &lt;i&gt;T1&lt;/i&gt;), or (Wesley, &lt;i&gt;T2&lt;/i&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) There would then be 3 tills and 5 staff. Each till can appear with each member of staff in an ordered pair, so there would be 3 &amp;#xD7; 5 = 15 ordered pairs in &lt;i&gt;Tills &amp;#xD7; Staff.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.6</guid>
    <dc:title>2.6 Associations: tuples and Cartesian products</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Consider an item of shopping that is weighed at the supermarket checkout, such as 335 grams of walnuts. This item of shopping has two features: the type of item purchased (walnuts), and the weight of that item (335 grams). To record a weighed item of shopping we need to note both these features. This can be done using an ordered pair: (“WALNUTS”, 335).&lt;/p&gt;&lt;p&gt;The first item in this ordered pair gives the type of item purchased. Let &lt;i&gt;WeighedItems&lt;/i&gt; be the set of items stocked by the supermarket that need to be weighed. The first item comes from this set, while the second item in the ordered pair comes from the set &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;We call the set containing all such pairs the &lt;b&gt;Cartesian product&lt;/b&gt; of the two sets. (‘Cartesian’ after the famous French philosopher and mathematician René Descartes.) This set of pairs is written as &lt;i&gt;WeighedItems × Int&lt;/i&gt;. So the set &lt;i&gt;WeighedItems × Int&lt;/i&gt; consists of all pairs (&lt;i&gt;w, n&lt;/i&gt;), where &lt;i&gt;w&lt;/i&gt; comes from the set &lt;i&gt;WeighedItems&lt;/i&gt;, and &lt;i&gt;n&lt;/i&gt; comes from the set &lt;i&gt;Int&lt;/i&gt;. We refer to (&lt;i&gt;w, n&lt;/i&gt;) as an &lt;b&gt;ordered pair&lt;/b&gt;. The word pair here indicates that there are two items grouped together. The word ordered indicates that the order in which the two items are given matters. The pair (“WALNUTS”, 335) is not the same as the pair (335, “WALNUTS”). Similarly, the set &lt;i&gt;WeighedItems × Int&lt;/i&gt; is different from the set &lt;i&gt;Int × WeighedItems&lt;/i&gt;, which consists of pairs giving: first an integer, then a type of weighed item.&lt;/p&gt;&lt;p&gt;Use of the symbol × here has nothing to do with multiplication of numbers!&lt;/p&gt;&lt;p&gt;We can form the Cartesian product of any two sets. The Cartesian product of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; is written as &lt;i&gt;X × Y&lt;/i&gt; , and consists of all ordered pairs (&lt;i&gt;x, y&lt;/i&gt;) where &lt;i&gt;x&lt;/i&gt; is from the set &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; is from the set &lt;i&gt;Y&lt;/i&gt;. &lt;i&gt;X&lt;/i&gt; × &lt;i&gt;Y&lt;/i&gt; can be read as “ &lt;i&gt;X&lt;/i&gt; cross &lt;i&gt;Y&lt;/i&gt;”.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;An ordered pair gives an association between two items. There are situations where we may want to associate more than two things. Consider items stocked by the supermarket that have barcodes. The supermarket will be interested in a number of features associated with each item of this type. Three such features are:&lt;/p&gt;&lt;ol class="oucontent-numbered"&gt;&lt;li&gt;&lt;p&gt;The barcode (taken to be an integer).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The name of the item, to be printed on the till receipt (as a string).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The price of an item of this type (taken to be an integer number of pence).&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;A natural way to associate these three features is to write them together as an &lt;b&gt;ordered triple&lt;/b&gt;, or &lt;b&gt;3-tuple&lt;/b&gt;, such as (13151, “ORGANIC SOUP”, 179). Note the use of round brackets here. These are used for tuples, in distinction to square brackets [ and ] for sequences, or curly brackets { and } for sets. The terminology ‘ordered triple’ indicates that we are now writing three items, each from a specified set, in a given order. We may want to associate four items, or five, or more. The terminology ‘tuple’ extends conveniently to this general case, where we talk about 4-tuples, or 5-tuples, and, in general, &lt;b&gt; &lt;i&gt;n&lt;/i&gt;-tuples&lt;/b&gt; (where &lt;i&gt;n&lt;/i&gt; might be 2, or 3, or any larger integer).&lt;/p&gt;&lt;p&gt;The set of all 3-tuples of the same form as (13151, “ORGANIC SOUP”, 179) is again a Cartesian product, in this case a product of three sets. The barcode is from &lt;i&gt;Int&lt;/i&gt;, the item name is a string (from &lt;i&gt;SeqOfChar&lt;/i&gt;) and the price is an integer. So this 3-tuple comes from the set &lt;i&gt;Int × SeqOfChar × Int&lt;/i&gt;.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act009"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 8&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Taking the code for olive oil as 43202, and referring to the receipt in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt;, write down the ordered triple from the set &lt;i&gt;Int × SeqOfChar × Int&lt;/i&gt; that represents the association between the code, the description and the price of the olive oil.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Making sure that the description is written as a string, and that the price is in pence, the triple should be (43202, “OLIVE OIL”, 178).&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;As another example, suppose that a shop has just three members of staff, Jo, Jessica and Wesley, and just two tills, &lt;i&gt;T1&lt;/i&gt; and &lt;i&gt;T2&lt;/i&gt;. We could represent a situation where Jo is operating the till &lt;i&gt;T2&lt;/i&gt; by the ordered pair, or 2-tuple (&lt;i&gt;T2&lt;/i&gt;, Jo). Clearly, there are a variety of ways in which a member of staff can be assigned to a till. If &lt;i&gt;Tills&lt;/i&gt; is the set {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;} and &lt;i&gt;Staff&lt;/i&gt; is the set {Jo, Jessica, Wesley}, then the set of all possible assignments of a member of staff to a till is &lt;i&gt;Tills × Staff&lt;/i&gt; . If we write this set out in full, we obtain:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Tills × Staff&lt;/i&gt; = {(&lt;i&gt;T1&lt;/i&gt;, Jo), (&lt;i&gt;T1&lt;/i&gt;, Jessica), (&lt;i&gt;T1&lt;/i&gt;, Wesley), (&lt;i&gt;T2&lt;/i&gt;, Jo), (&lt;i&gt;T2&lt;/i&gt;, Jessica), (&lt;i&gt;T2&lt;/i&gt;, Wesley)}.&lt;/p&gt;&lt;p&gt;Note the use of different brackets: curly brackets delimit the set, round brackets delimit each of the tuples. Note also that the use of &lt;i&gt;Tills × Staff&lt;/i&gt; to represent assignment of a staff member to a till means that we must write the till first in each ordered pair.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act010"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 9&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give an example of a member of the set &lt;i&gt;Staff × Tills&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) If the supermarket were to install another till, and recruit two more members of staff, and we redefine the sets &lt;i&gt;Staff&lt;/i&gt; and &lt;i&gt;Tills&lt;/i&gt; to include these, how many ordered pairs would be in the set &lt;i&gt;Tills × Staff&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) In &lt;i&gt;Staff × Tills&lt;/i&gt;, the member of staff should be given first. Suitable examples would be (Jo, &lt;i&gt;T1&lt;/i&gt;), or (Wesley, &lt;i&gt;T2&lt;/i&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) There would then be 3 tills and 5 staff. Each till can appear with each member of staff in an ordered pair, so there would be 3 × 5 = 15 ordered pairs in &lt;i&gt;Tills × Staff.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Objectives for Section 2</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.7</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: real number; set; element or member of a set; empty set; length of a sequence; empty sequence, ordered pair, &lt;i&gt;n&lt;/i&gt;-tuple, Cartesian product.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Appreciate that use of precise notation such as the use of different types of bracket conveys important information when using formal notation. For example, square brackets [ and ] denote a sequence, while curly brackets { and } denote a set.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use and interpret various pieces of notation:&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;curly brackets to denote a set;&lt;/p&gt; &lt;p&gt;– definition of a set by using a condition;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;{ } to denote the empty set;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;[ ] to denote an empty sequence;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;SeqOfX&lt;/i&gt; to denote the set of all sequences with members from &lt;i&gt;X&lt;/i&gt;;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(&lt;i&gt;x, y&lt;/i&gt;) to denote an ordered pair or 2-tuple; (&lt;i&gt;x, y, z&lt;/i&gt;) to denote a 3-tuple, etc.;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;X &amp;#xD7; Y&lt;/i&gt; to denote the Cartesian product of the sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; .&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Determine the cardinality of a given set and the length of a given sequence.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Given &lt;i&gt;i&lt;/i&gt;, determine the &lt;i&gt;i&lt;/i&gt;th element of a given sequence.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Be aware of the ASCII character codes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Appreciate that some sets are finite and some are not.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.7</guid>
    <dc:title>Objectives for Section 2</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: real number; set; element or member of a set; empty set; length of a sequence; empty sequence, ordered pair, &lt;i&gt;n&lt;/i&gt;-tuple, Cartesian product.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Appreciate that use of precise notation such as the use of different types of bracket conveys important information when using formal notation. For example, square brackets [ and ] denote a sequence, while curly brackets { and } denote a set.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use and interpret various pieces of notation:&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;curly brackets to denote a set;&lt;/p&gt; &lt;p&gt;– definition of a set by using a condition;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;{ } to denote the empty set;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;[ ] to denote an empty sequence;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;SeqOfX&lt;/i&gt; to denote the set of all sequences with members from &lt;i&gt;X&lt;/i&gt;;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(&lt;i&gt;x, y&lt;/i&gt;) to denote an ordered pair or 2-tuple; (&lt;i&gt;x, y, z&lt;/i&gt;) to denote a 3-tuple, etc.;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;X × Y&lt;/i&gt; to denote the Cartesian product of the sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; .&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Determine the cardinality of a given set and the length of a given sequence.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Given &lt;i&gt;i&lt;/i&gt;, determine the &lt;i&gt;i&lt;/i&gt;th element of a given sequence.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Be aware of the ASCII character codes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Appreciate that some sets are finite and some are not.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Exercises on Section 2</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.8</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq004"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 4&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Let &lt;i&gt;A&lt;/i&gt; be the set of integers between 100 and 999 inclusive.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Express &lt;i&gt;A&lt;/i&gt; in the form &lt;i&gt;A&lt;/i&gt; = {&lt;i&gt;x&lt;/i&gt; &amp;#x2208; ?? : &lt;i&gt;condition&lt;/i&gt;}&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) What is the cardinality of &lt;i&gt;A&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;A&lt;/i&gt; = {&lt;i&gt;x&lt;/i&gt; &amp;#x2208; &lt;i&gt;Int&lt;/i&gt; : 100 &amp;#x2264; &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;x&lt;/i&gt; &amp;#x2264; 999}. (There are other correct solutions.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) There are 999 integers between 1 and 999 inclusive. The set &lt;i&gt;A&lt;/i&gt; does not contain the integers between 1 and 99 inclusive, and there are 99 of these. So &lt;i&gt;A&lt;/i&gt; has cardinality 999&amp;#xA0;&amp;#x2212;&amp;#xA0;99 =&amp;#xA0;900.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq005"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 5&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;If &lt;i&gt;B&lt;/i&gt; = {&lt;i&gt;s&lt;/i&gt; &amp;#x2208; &lt;i&gt;SeqOfChar&lt;/i&gt; : &lt;i&gt;s&lt;/i&gt; starts with &amp;#x2018;T’ and &lt;i&gt;s&lt;/i&gt; has length 4}, which of the following is a member of the set &lt;i&gt;B&lt;/i&gt;?&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &amp;#x201C;This&amp;#x201D;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [&amp;#x2018;T’, &amp;#x2018;h’, &amp;#x2018;i’, &amp;#x2018;s’, &amp;#x2018;.’].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [&amp;#x201C;T&amp;#x201D;, &amp;#x201C;h&amp;#x201D;, &amp;#x201C;i&amp;#x201D;, &amp;#x201C;s&amp;#x201D;].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &amp;#x201C;This&amp;#x201D; is in &lt;i&gt;B&lt;/i&gt;. It is a string (a sequence of characters), it contains four characters (so has length 4), and it starts with the character &amp;#x2018;T’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [&amp;#x2018;T’, &amp;#x2018;h’, &amp;#x2018;i’, &amp;#x2018;s’, &amp;#x2018;.’] is not in &lt;i&gt;B&lt;/i&gt;. It is a string starting with &amp;#x2018;T’, but it contains five characters (has length 5). (Do not forget to count the character &amp;#x2018;.’.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [&amp;#x201C;T&amp;#x201D;, &amp;#x201C;h&amp;#x201D;, &amp;#x201C;i&amp;#x201D;, &amp;#x201C;s&amp;#x201D;] is not in &lt;i&gt;B&lt;/i&gt;. Each member of this sequence is a string, not a character. (Note that &amp;#x201C;T&amp;#x201D;, etc, are enclosed in &lt;i&gt;double&lt;/i&gt; inverted commas.)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq006"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 6&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that each possible time of the day is stored as a pair of integers, where the first integer gives the hour and the second integer gives the minute. For example, (14, 45) represents a quarter to three in the afternoon. (Midnight is (0, 0) rather than (24, 00).) Express the set of possible times of the day in the form {(&lt;i&gt;h, m&lt;/i&gt;) &amp;#x2208; ?? : &lt;i&gt;condition&lt;/i&gt;}.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;The set is {(&lt;i&gt;h, m&lt;/i&gt;) &amp;#x2208; &lt;i&gt;Int &amp;#xD7; Int&lt;/i&gt; : 0 &amp;#x2264; &lt;i&gt;h&lt;/i&gt; and &lt;i&gt;h&lt;/i&gt; &amp;lt; 24 and 0 &amp;#x2264; &lt;i&gt;m&lt;/i&gt; and &lt;i&gt;m&lt;/i&gt; &amp;lt; 60}.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.8</guid>
    <dc:title>Exercises on Section 2</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq004"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 4&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Let &lt;i&gt;A&lt;/i&gt; be the set of integers between 100 and 999 inclusive.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Express &lt;i&gt;A&lt;/i&gt; in the form &lt;i&gt;A&lt;/i&gt; = {&lt;i&gt;x&lt;/i&gt; ∈ ?? : &lt;i&gt;condition&lt;/i&gt;}&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) What is the cardinality of &lt;i&gt;A&lt;/i&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;A&lt;/i&gt; = {&lt;i&gt;x&lt;/i&gt; ∈ &lt;i&gt;Int&lt;/i&gt; : 100 ≤ &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;x&lt;/i&gt; ≤ 999}. (There are other correct solutions.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) There are 999 integers between 1 and 999 inclusive. The set &lt;i&gt;A&lt;/i&gt; does not contain the integers between 1 and 99 inclusive, and there are 99 of these. So &lt;i&gt;A&lt;/i&gt; has cardinality 999 − 99 = 900.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq005"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 5&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;If &lt;i&gt;B&lt;/i&gt; = {&lt;i&gt;s&lt;/i&gt; ∈ &lt;i&gt;SeqOfChar&lt;/i&gt; : &lt;i&gt;s&lt;/i&gt; starts with ‘T’ and &lt;i&gt;s&lt;/i&gt; has length 4}, which of the following is a member of the set &lt;i&gt;B&lt;/i&gt;?&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) “This”.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [‘T’, ‘h’, ‘i’, ‘s’, ‘.’].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [“T”, “h”, “i”, “s”].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) “This” is in &lt;i&gt;B&lt;/i&gt;. It is a string (a sequence of characters), it contains four characters (so has length 4), and it starts with the character ‘T’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [‘T’, ‘h’, ‘i’, ‘s’, ‘.’] is not in &lt;i&gt;B&lt;/i&gt;. It is a string starting with ‘T’, but it contains five characters (has length 5). (Do not forget to count the character ‘.’.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [“T”, “h”, “i”, “s”] is not in &lt;i&gt;B&lt;/i&gt;. Each member of this sequence is a string, not a character. (Note that “T”, etc, are enclosed in &lt;i&gt;double&lt;/i&gt; inverted commas.)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq006"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 6&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that each possible time of the day is stored as a pair of integers, where the first integer gives the hour and the second integer gives the minute. For example, (14, 45) represents a quarter to three in the afternoon. (Midnight is (0, 0) rather than (24, 00).) Express the set of possible times of the day in the form {(&lt;i&gt;h, m&lt;/i&gt;) ∈ ?? : &lt;i&gt;condition&lt;/i&gt;}.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;The set is {(&lt;i&gt;h, m&lt;/i&gt;) ∈ &lt;i&gt;Int × Int&lt;/i&gt; : 0 ≤ &lt;i&gt;h&lt;/i&gt; and &lt;i&gt;h&lt;/i&gt; &lt; 24 and 0 ≤ &lt;i&gt;m&lt;/i&gt; and &lt;i&gt;m&lt;/i&gt; &lt; 60}.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Structuring data</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.1</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;In Section 2, we considered integers, characters and truth values. We shall refer to these as &lt;b&gt;primitive&lt;/b&gt; forms of data. We also looked at two forms of data collection, sets and sequences, and at the association of different data items in a tuple. In this section, we will look briefly at some other ways in which data may be structured.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.1</guid>
    <dc:title>Structuring data</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;In Section 2, we considered integers, characters and truth values. We shall refer to these as &lt;b&gt;primitive&lt;/b&gt; forms of data. We also looked at two forms of data collection, sets and sequences, and at the association of different data items in a tuple. In this section, we will look briefly at some other ways in which data may be structured.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>3.1 Sets of sets</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.2</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;In Section 2, all the sets and sequences we considered had primitive forms of data as their elements. However, sets and sequences may contain non-primitive forms of data. Let us look first at a situation in which we may find it useful to have a set whose members are themselves sets.&lt;/p&gt;&lt;p&gt;Think again about a shop with just three members of staff, given in the set &lt;i&gt;Staff&lt;/i&gt; = {Jo, Jessica, Wesley}. Now let &lt;i&gt;at WorkStaff&lt;/i&gt; be the set of staff currently at work. Clearly, &lt;i&gt;at WorkStaff&lt;/i&gt; may take a range of values. If just Jo and Wesley are at work, then &lt;i&gt;at WorkStaff&lt;/i&gt; is {Jo, Wesley}. If Jessica were to start work and Jo were to leave, then &lt;i&gt;at WorkStaff&lt;/i&gt; becomes {Jessica, Wesley}.&lt;/p&gt;&lt;p&gt;Now any combination of staff from the set &lt;i&gt;Staff&lt;/i&gt; = {Jo, Jessica, Wesley} might be at work at the same time. Possibilities include all these staff (when &lt;i&gt;at WorkStaff&lt;/i&gt; is {Jo, Jessica, Wesley}), and none of them (in which case &lt;i&gt;at WorkStaff&lt;/i&gt; is { }). The full list of possibilities (giving the possible values of &lt;i&gt;at WorkStaff&lt;/i&gt; ) is given below.&lt;/p&gt;&lt;p&gt;{ }, {Jo}, {Jessica}, {Wesley}, {Jo, Jessica}, {Jo, Wesley}, {Jessica, Wesley}, {Jo, Jessica, Wesley}&lt;/p&gt;&lt;p&gt;Here, we have written out all the sets with members taken from the set &lt;i&gt;Staff&lt;/i&gt; = {Jo, Jessica, Wesley}. We can form a set whose members are these sets. We will denote this set by &lt;i&gt;SetOfStaff&lt;/i&gt; . So:&lt;/p&gt;&lt;p&gt;&lt;i&gt;SetOfStaff&lt;/i&gt; = {{ }, {Jo}, {Jessica}, {Wesley}, {Jo, Jessica}, {Jo, Wesley}, {Jessica, Wesley}, {Jo, Jessica, Wesley}}.&lt;/p&gt;&lt;p&gt;The outer curly brackets here delimit the members of the set &lt;i&gt;SetOfStaff&lt;/i&gt;. Each of these members is itself a set, and the inner curly brackets delimit each of these member sets. We will not often need to list the members of a set of sets like this. But it is useful to be aware that we can form a set in this way. We might have a variable &lt;i&gt;atWorkStaff&lt;/i&gt;, giving the set of staff currently at work. The set giving all possible states of this variable is then &lt;i&gt;SetOfStaff.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;In general, we will use &lt;i&gt;SetOfX&lt;/i&gt; to denote the set consisting of all the sets drawn from some given set, &lt;i&gt;X&lt;/i&gt;. &lt;i&gt;SetOfX&lt;/i&gt; is also known as the &lt;b&gt;power set&lt;/b&gt; of &lt;i&gt;X&lt;/i&gt;. Various other notations are used for this, including &lt;b&gt;P&lt;/b&gt;(&lt;i&gt;X&lt;/i&gt;) and 2&lt;sup&gt; &lt;i&gt;X&lt;/i&gt; &lt;/sup&gt;. The latter is sometimes used since, if &lt;i&gt;X&lt;/i&gt; has cardinality &lt;i&gt;n&lt;/i&gt;, then &lt;i&gt;SetOfX&lt;/i&gt; has cardinality 2&lt;sup&gt; &lt;i&gt;n&lt;/i&gt; &lt;/sup&gt;. For example &lt;i&gt;Staff&lt;/i&gt; has cardinality 3 and &lt;i&gt;SetOfStaff&lt;/i&gt; has cardinality 8, which is 2&lt;sup&gt;3&lt;/sup&gt;.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act011"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 10&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that the set of tills in a supermarket is &lt;i&gt;Tills&lt;/i&gt; = {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;} and &lt;i&gt;active Tills&lt;/i&gt; is a variable giving the set of tills that are staffed at any one time. Write out in full the set of possible states for &lt;i&gt;active Tills&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;The set of possible states is the set &lt;i&gt;SetOfTills&lt;/i&gt;. Written in full, this is:&lt;/p&gt;
&lt;p&gt;{{}, {&lt;i&gt;T1&lt;/i&gt;}, {&lt;i&gt;T2&lt;/i&gt;}, {&lt;i&gt;T3&lt;/i&gt; }, {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;}, {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;}, {&lt;i&gt;T2&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;}, {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;}}.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.2</guid>
    <dc:title>3.1 Sets of sets</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;In Section 2, all the sets and sequences we considered had primitive forms of data as their elements. However, sets and sequences may contain non-primitive forms of data. Let us look first at a situation in which we may find it useful to have a set whose members are themselves sets.&lt;/p&gt;&lt;p&gt;Think again about a shop with just three members of staff, given in the set &lt;i&gt;Staff&lt;/i&gt; = {Jo, Jessica, Wesley}. Now let &lt;i&gt;at WorkStaff&lt;/i&gt; be the set of staff currently at work. Clearly, &lt;i&gt;at WorkStaff&lt;/i&gt; may take a range of values. If just Jo and Wesley are at work, then &lt;i&gt;at WorkStaff&lt;/i&gt; is {Jo, Wesley}. If Jessica were to start work and Jo were to leave, then &lt;i&gt;at WorkStaff&lt;/i&gt; becomes {Jessica, Wesley}.&lt;/p&gt;&lt;p&gt;Now any combination of staff from the set &lt;i&gt;Staff&lt;/i&gt; = {Jo, Jessica, Wesley} might be at work at the same time. Possibilities include all these staff (when &lt;i&gt;at WorkStaff&lt;/i&gt; is {Jo, Jessica, Wesley}), and none of them (in which case &lt;i&gt;at WorkStaff&lt;/i&gt; is { }). The full list of possibilities (giving the possible values of &lt;i&gt;at WorkStaff&lt;/i&gt; ) is given below.&lt;/p&gt;&lt;p&gt;{ }, {Jo}, {Jessica}, {Wesley}, {Jo, Jessica}, {Jo, Wesley}, {Jessica, Wesley}, {Jo, Jessica, Wesley}&lt;/p&gt;&lt;p&gt;Here, we have written out all the sets with members taken from the set &lt;i&gt;Staff&lt;/i&gt; = {Jo, Jessica, Wesley}. We can form a set whose members are these sets. We will denote this set by &lt;i&gt;SetOfStaff&lt;/i&gt; . So:&lt;/p&gt;&lt;p&gt;&lt;i&gt;SetOfStaff&lt;/i&gt; = {{ }, {Jo}, {Jessica}, {Wesley}, {Jo, Jessica}, {Jo, Wesley}, {Jessica, Wesley}, {Jo, Jessica, Wesley}}.&lt;/p&gt;&lt;p&gt;The outer curly brackets here delimit the members of the set &lt;i&gt;SetOfStaff&lt;/i&gt;. Each of these members is itself a set, and the inner curly brackets delimit each of these member sets. We will not often need to list the members of a set of sets like this. But it is useful to be aware that we can form a set in this way. We might have a variable &lt;i&gt;atWorkStaff&lt;/i&gt;, giving the set of staff currently at work. The set giving all possible states of this variable is then &lt;i&gt;SetOfStaff.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;In general, we will use &lt;i&gt;SetOfX&lt;/i&gt; to denote the set consisting of all the sets drawn from some given set, &lt;i&gt;X&lt;/i&gt;. &lt;i&gt;SetOfX&lt;/i&gt; is also known as the &lt;b&gt;power set&lt;/b&gt; of &lt;i&gt;X&lt;/i&gt;. Various other notations are used for this, including &lt;b&gt;P&lt;/b&gt;(&lt;i&gt;X&lt;/i&gt;) and 2&lt;sup&gt; &lt;i&gt;X&lt;/i&gt; &lt;/sup&gt;. The latter is sometimes used since, if &lt;i&gt;X&lt;/i&gt; has cardinality &lt;i&gt;n&lt;/i&gt;, then &lt;i&gt;SetOfX&lt;/i&gt; has cardinality 2&lt;sup&gt; &lt;i&gt;n&lt;/i&gt; &lt;/sup&gt;. For example &lt;i&gt;Staff&lt;/i&gt; has cardinality 3 and &lt;i&gt;SetOfStaff&lt;/i&gt; has cardinality 8, which is 2&lt;sup&gt;3&lt;/sup&gt;.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act011"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 10&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that the set of tills in a supermarket is &lt;i&gt;Tills&lt;/i&gt; = {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;} and &lt;i&gt;active Tills&lt;/i&gt; is a variable giving the set of tills that are staffed at any one time. Write out in full the set of possible states for &lt;i&gt;active Tills&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;The set of possible states is the set &lt;i&gt;SetOfTills&lt;/i&gt;. Written in full, this is:&lt;/p&gt;
&lt;p&gt;{{}, {&lt;i&gt;T1&lt;/i&gt;}, {&lt;i&gt;T2&lt;/i&gt;}, {&lt;i&gt;T3&lt;/i&gt; }, {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;}, {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;}, {&lt;i&gt;T2&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;}, {&lt;i&gt;T1&lt;/i&gt;, &lt;i&gt;T2&lt;/i&gt;, &lt;i&gt;T3&lt;/i&gt;}}.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>3.2 Combining data structures</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.3</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;In Section 2, we introduced the notation &lt;i&gt;SeqOfX&lt;/i&gt; for the set of all sequences whose members come from the set X. In Section 2, we looked only at sequences whose members were of one of the primitive forms of data (integers, characters or Booleans). We can have sequences whose members are themselves data with a more complicated form. For example, suppose that Jo is working at the till &lt;i&gt;T1&lt;/i&gt; and is replaced by Jessica. We might represent this handover by the 3-tuple (Jo, &lt;i&gt;T1&lt;/i&gt;, Jessica). Now suppose that we want to give all the handovers that occur during a particular day, in the order in which they occur. We could give this information in a sequence. This sequence would come from the set &lt;i&gt;SeqOfX&lt;/i&gt; , where &lt;i&gt;X&lt;/i&gt; is the Cartesian product &lt;i&gt;Staff &amp;#xD7; Tills &amp;#xD7; Staff&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;As another example, one might think of a sentence as a sequence of words, where each word is seen as a sequence of characters. If we did this, then the sentence would be regarded as coming from the set &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;. We can use notations introduced earlier to show when we want to see a sentence in this way, and when it is to be regarded as a single string (from &lt;i&gt;SeqOfChar&lt;/i&gt;).&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act012"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 11&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Which of the following is a member of the set &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;?&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) [&amp;#x2018;W’,&amp;#x2018;o’,&amp;#x2018;r’,&amp;#x2018;d’].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &amp;#x201C;This is a sentence.&amp;#x201D;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [&amp;#x201C;This&amp;#x201D;,&amp;#x201C;is&amp;#x201D;,&amp;#x201C;a&amp;#x201D;,&amp;#x201C;sentence&amp;#x201D;].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Only (c) is a member of &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This is a sequence of characters and so a member of &lt;i&gt;SeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) This is a string, so is again a sequence of characters (written in our more compact notation).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) This is a sequence each of whose members is a string. Thus each item in the sequence in (c) comes from &lt;i&gt;SeqOfChar&lt;/i&gt;. The sequence itself comes from &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Consider a computer system which has a finite set of error messages, each of which may be displayed to a cashier at the till. Suppose these messages are: &amp;#x201C;Barcode error&amp;#x201D;; &amp;#x201C;Item code not recognised&amp;#x201D; and &amp;#x201C;System error 1234&amp;#x201D;. This set of error messages can be represented thus:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Errors&lt;/i&gt; = {&amp;#x201C;Barcode error&amp;#x201D;, &amp;#x201C;Item code not recognised&amp;#x201D;, &amp;#x201C;System error 1234&amp;#x201D;}.&lt;/p&gt;&lt;p&gt;Each of these messages is given as a string, that is, as a sequence of characters. So &lt;i&gt;Errors&lt;/i&gt; is a set of sequences of characters.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.3</guid>
    <dc:title>3.2 Combining data structures</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;In Section 2, we introduced the notation &lt;i&gt;SeqOfX&lt;/i&gt; for the set of all sequences whose members come from the set X. In Section 2, we looked only at sequences whose members were of one of the primitive forms of data (integers, characters or Booleans). We can have sequences whose members are themselves data with a more complicated form. For example, suppose that Jo is working at the till &lt;i&gt;T1&lt;/i&gt; and is replaced by Jessica. We might represent this handover by the 3-tuple (Jo, &lt;i&gt;T1&lt;/i&gt;, Jessica). Now suppose that we want to give all the handovers that occur during a particular day, in the order in which they occur. We could give this information in a sequence. This sequence would come from the set &lt;i&gt;SeqOfX&lt;/i&gt; , where &lt;i&gt;X&lt;/i&gt; is the Cartesian product &lt;i&gt;Staff × Tills × Staff&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;As another example, one might think of a sentence as a sequence of words, where each word is seen as a sequence of characters. If we did this, then the sentence would be regarded as coming from the set &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;. We can use notations introduced earlier to show when we want to see a sentence in this way, and when it is to be regarded as a single string (from &lt;i&gt;SeqOfChar&lt;/i&gt;).&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act012"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 11&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Which of the following is a member of the set &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;?&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) [‘W’,‘o’,‘r’,‘d’].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) “This is a sentence.”.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [“This”,“is”,“a”,“sentence”].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Only (c) is a member of &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This is a sequence of characters and so a member of &lt;i&gt;SeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) This is a string, so is again a sequence of characters (written in our more compact notation).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) This is a sequence each of whose members is a string. Thus each item in the sequence in (c) comes from &lt;i&gt;SeqOfChar&lt;/i&gt;. The sequence itself comes from &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Consider a computer system which has a finite set of error messages, each of which may be displayed to a cashier at the till. Suppose these messages are: “Barcode error”; “Item code not recognised” and “System error 1234”. This set of error messages can be represented thus:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Errors&lt;/i&gt; = {“Barcode error”, “Item code not recognised”, “System error 1234”}.&lt;/p&gt;&lt;p&gt;Each of these messages is given as a string, that is, as a sequence of characters. So &lt;i&gt;Errors&lt;/i&gt; is a set of sequences of characters.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>3.3 Mixing different forms of data: disjoint union of sets</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.4</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;At the supermarket checkout, some items need to be weighed (organic courgettes for example) and some do not. Let &lt;i&gt;BarcodedItems&lt;/i&gt; be the set of items that do not need to be weighed, and &lt;i&gt;WeighedItems&lt;/i&gt; be the set of items that must be weighed. When a weighed item is recorded at the till, we must record both the item type and the weight of the item that has been purchased. Earlier, we saw that such a purchase can be seen as an ordered pair, such as (&amp;#x201C;WALNUTS&amp;#x201D;, 335), that comes from the set &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Suppose now that we want to form the set of all items that might appear in a transaction at a till. We might call this set &lt;i&gt;TillItems&lt;/i&gt;. Specifying this set &lt;i&gt;TillItems&lt;/i&gt; poses a complication, since there are two different types of element that might appear in it. An item from the set &lt;i&gt;TillItems&lt;/i&gt; will come either from &lt;i&gt;BarcodedItems&lt;/i&gt; or from &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;. We express this relationship by saying that &lt;i&gt;TillItems&lt;/i&gt; is the &lt;b&gt;disjoint union&lt;/b&gt; of &lt;i&gt;BarcodedItems&lt;/i&gt; and &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;. We write this as:&lt;/p&gt;&lt;p&gt;You can read &lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt; as &amp;#x201C;&lt;i&gt;X&lt;/i&gt; or &lt;i&gt;Y&lt;/i&gt;.&amp;#x201D;&lt;/p&gt;&lt;p&gt;&lt;i&gt;TillItems&lt;/i&gt; = &lt;i&gt;BarcodedItems&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (&lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;).&lt;/p&gt;&lt;p&gt;In general, the disjoint union of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; , written &lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt; , is the set consisting of all items that are either from &lt;i&gt;X&lt;/i&gt; or from &lt;i&gt;Y&lt;/i&gt; . The term &amp;#x201C;disjoint&amp;#x201D; reflects the fact that an item could not come both from &lt;i&gt;BarcodedItems&lt;/i&gt; and from &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;. These sets contain different forms of data and have nothing in common. (We will only use disjoint union to combine sets containing different forms of data.)&lt;/p&gt;&lt;p&gt;As in Section 1, suppose that &lt;i&gt;till1&lt;/i&gt; is a variable representing a transaction in progress at till 1. The state of &lt;i&gt;till1&lt;/i&gt; will give the items recorded so far, in the order in which they were entered into the till, either by reading the barcode, or as a weighed item. So we can describe the state of &lt;i&gt;till1&lt;/i&gt; as a sequence of till items. The set of all possible states of &lt;i&gt;till1&lt;/i&gt; is &lt;i&gt;SeqOfTillItems&lt;/i&gt;, where &lt;i&gt;TillItems&lt;/i&gt; is &lt;i&gt;BarcodedItems&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (&lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;).&lt;/p&gt;&lt;p&gt;As noted earlier, we usually want to avoid mixing data of different forms in a collection such as a sequence. But if we need to do this, we can first use a disjoint union to combine the different forms of data into a single set. So, for example, if we needed to form a sequence whose members might be either characters or integers, then this sequence would come from a set &lt;i&gt;SeqOfMix&lt;/i&gt;, where &lt;i&gt;Mix&lt;/i&gt; is the disjoint union &lt;i&gt;Int&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Char&lt;/i&gt;.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act013"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 12&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Let &lt;i&gt;TillItems&lt;/i&gt; = &lt;i&gt;BarcodedItems&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (&lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;), and suppose that &lt;i&gt;BarcodedItems&lt;/i&gt; is represented as the set of integers between 10000 and 99999 and &lt;i&gt;WeighedItems&lt;/i&gt; as the set of integers between 100 and 999. Which of the sequences given in (a)–(c) below is a member of the set &lt;i&gt;SeqOfTillItems&lt;/i&gt;?&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) [1, &amp;#x2212;740, (22, 300)]&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [11, &amp;#x2018;2’, &amp;#x2018;w’, 33000, &amp;#x2212;22]&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [11023, 11023, (998, 12), 22375, (217, 147)]&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Only the sequence in (c) is in &lt;i&gt;SeqOfTillItems&lt;/i&gt;.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) According to the statement, a barcoded item is represented by an integer with five digits. So 1 and &lt;i&gt;&amp;#x2212;&lt;/i&gt;740 are not from the set &lt;i&gt;BarcodedItems&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) This sequence contains some characters, which are neither from the set &lt;i&gt;BarcodedItems&lt;/i&gt; nor from &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Each of the integers 11023 and 22375 lies between 10000 and 99999, and so comes from the set &lt;i&gt;BarcodedItems&lt;/i&gt;. The first entry in each of the pairs (998, 12) and (217, 147) is an integer between 100 and 999, so comes from &lt;i&gt;WeighedItems&lt;/i&gt;. Thus each of these ordered pairs comes from &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;. So each item in the sequence is either from &lt;i&gt;BarcodedItems&lt;/i&gt; or from &lt;i&gt;WeighedItems &amp;#xD7; Int&lt;/i&gt;, and so comes from &lt;i&gt;TillItems&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.4</guid>
    <dc:title>3.3 Mixing different forms of data: disjoint union of sets</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;At the supermarket checkout, some items need to be weighed (organic courgettes for example) and some do not. Let &lt;i&gt;BarcodedItems&lt;/i&gt; be the set of items that do not need to be weighed, and &lt;i&gt;WeighedItems&lt;/i&gt; be the set of items that must be weighed. When a weighed item is recorded at the till, we must record both the item type and the weight of the item that has been purchased. Earlier, we saw that such a purchase can be seen as an ordered pair, such as (“WALNUTS”, 335), that comes from the set &lt;i&gt;WeighedItems × Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Suppose now that we want to form the set of all items that might appear in a transaction at a till. We might call this set &lt;i&gt;TillItems&lt;/i&gt;. Specifying this set &lt;i&gt;TillItems&lt;/i&gt; poses a complication, since there are two different types of element that might appear in it. An item from the set &lt;i&gt;TillItems&lt;/i&gt; will come either from &lt;i&gt;BarcodedItems&lt;/i&gt; or from &lt;i&gt;WeighedItems × Int&lt;/i&gt;. We express this relationship by saying that &lt;i&gt;TillItems&lt;/i&gt; is the &lt;b&gt;disjoint union&lt;/b&gt; of &lt;i&gt;BarcodedItems&lt;/i&gt; and &lt;i&gt;WeighedItems × Int&lt;/i&gt;. We write this as:&lt;/p&gt;&lt;p&gt;You can read &lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt; as “&lt;i&gt;X&lt;/i&gt; or &lt;i&gt;Y&lt;/i&gt;.”&lt;/p&gt;&lt;p&gt;&lt;i&gt;TillItems&lt;/i&gt; = &lt;i&gt;BarcodedItems&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (&lt;i&gt;WeighedItems × Int&lt;/i&gt;).&lt;/p&gt;&lt;p&gt;In general, the disjoint union of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; , written &lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt; , is the set consisting of all items that are either from &lt;i&gt;X&lt;/i&gt; or from &lt;i&gt;Y&lt;/i&gt; . The term “disjoint” reflects the fact that an item could not come both from &lt;i&gt;BarcodedItems&lt;/i&gt; and from &lt;i&gt;WeighedItems × Int&lt;/i&gt;. These sets contain different forms of data and have nothing in common. (We will only use disjoint union to combine sets containing different forms of data.)&lt;/p&gt;&lt;p&gt;As in Section 1, suppose that &lt;i&gt;till1&lt;/i&gt; is a variable representing a transaction in progress at till 1. The state of &lt;i&gt;till1&lt;/i&gt; will give the items recorded so far, in the order in which they were entered into the till, either by reading the barcode, or as a weighed item. So we can describe the state of &lt;i&gt;till1&lt;/i&gt; as a sequence of till items. The set of all possible states of &lt;i&gt;till1&lt;/i&gt; is &lt;i&gt;SeqOfTillItems&lt;/i&gt;, where &lt;i&gt;TillItems&lt;/i&gt; is &lt;i&gt;BarcodedItems&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (&lt;i&gt;WeighedItems × Int&lt;/i&gt;).&lt;/p&gt;&lt;p&gt;As noted earlier, we usually want to avoid mixing data of different forms in a collection such as a sequence. But if we need to do this, we can first use a disjoint union to combine the different forms of data into a single set. So, for example, if we needed to form a sequence whose members might be either characters or integers, then this sequence would come from a set &lt;i&gt;SeqOfMix&lt;/i&gt;, where &lt;i&gt;Mix&lt;/i&gt; is the disjoint union &lt;i&gt;Int&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Char&lt;/i&gt;.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act013"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 12&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Let &lt;i&gt;TillItems&lt;/i&gt; = &lt;i&gt;BarcodedItems&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; (&lt;i&gt;WeighedItems × Int&lt;/i&gt;), and suppose that &lt;i&gt;BarcodedItems&lt;/i&gt; is represented as the set of integers between 10000 and 99999 and &lt;i&gt;WeighedItems&lt;/i&gt; as the set of integers between 100 and 999. Which of the sequences given in (a)–(c) below is a member of the set &lt;i&gt;SeqOfTillItems&lt;/i&gt;?&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) [1, −740, (22, 300)]&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [11, ‘2’, ‘w’, 33000, −22]&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [11023, 11023, (998, 12), 22375, (217, 147)]&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Only the sequence in (c) is in &lt;i&gt;SeqOfTillItems&lt;/i&gt;.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) According to the statement, a barcoded item is represented by an integer with five digits. So 1 and &lt;i&gt;−&lt;/i&gt;740 are not from the set &lt;i&gt;BarcodedItems&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) This sequence contains some characters, which are neither from the set &lt;i&gt;BarcodedItems&lt;/i&gt; nor from &lt;i&gt;WeighedItems × Int&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Each of the integers 11023 and 22375 lies between 10000 and 99999, and so comes from the set &lt;i&gt;BarcodedItems&lt;/i&gt;. The first entry in each of the pairs (998, 12) and (217, 147) is an integer between 100 and 999, so comes from &lt;i&gt;WeighedItems&lt;/i&gt;. Thus each of these ordered pairs comes from &lt;i&gt;WeighedItems × Int&lt;/i&gt;. So each item in the sequence is either from &lt;i&gt;BarcodedItems&lt;/i&gt; or from &lt;i&gt;WeighedItems × Int&lt;/i&gt;, and so comes from &lt;i&gt;TillItems&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>3.4 Representing data in applications</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.5</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Suppose that you are designing software for some application. You will be working with a programming language that enables you to communicate instructions to a computer. In this programming language, certain forms of data will already be represented electronically. These will include common forms of data, such as numbers, characters and sequences. In any particular application, you are likely also to be concerned with forms of data that are peculiar to that application. Having identified some form of data that you need to be able to handle, you will then need to represent this in terms of what is available; that is, in terms of forms of data that have already been represented electronically.&lt;/p&gt;&lt;p&gt;As a simple example, imagine that integers, characters and strings are available forms of data, and that you want to represent the days of the week.&lt;/p&gt;&lt;p&gt;One natural form of representation is as strings: &amp;#x201C;Monday&amp;#x201D;, &amp;#x201C;Tuesday&amp;#x201D;, &amp;#x201C;Wednesday&amp;#x201D;, and so on. But other forms of representation are possible. The full names can be inconvenient because they involve a lot of writing, so one might choose to use shortened versions, such as: &amp;#x201C;Mon&amp;#x201D;, &amp;#x201C;Tues&amp;#x201D;, &amp;#x201C;Wed&amp;#x201D;, etc. We could be awkward (from the viewpoint of an English speaker), and use the strings: &amp;#x201C;Lundi&amp;#x201D;, &amp;#x201C;Mardi&amp;#x201D;, &amp;#x201C;Mercredi&amp;#x201D;, and so on. Or we could use integers, and represent Monday as 1, Tuesday as 2, Wednesday as 3, etc. This might be very convenient at times, but one then needs to remember which number represents which day.&lt;/p&gt;&lt;p&gt;There are times when it is important to distinguish between a form of data derived from an application situation and the concrete representation you have chosen for it. We might refer to the idea of the days of the week as an &lt;b&gt;abstraction&lt;/b&gt;, in distinction to their &lt;b&gt;representation&lt;/b&gt;, perhaps as the strings &amp;#x201C;Mon&amp;#x201D;, &amp;#x201C;Tues&amp;#x201D;, &amp;#x201C;Wed&amp;#x201D;, etc.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act014"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 13&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;A compact form of representation for days of the week might be to use the first character of the name: &amp;#x2018;M’ for Monday, &amp;#x2018;T’ for Tuesday, and so on. Why would this be a bad idea?&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Because we could not tell whether &amp;#x2018;T’ meant Tuesday or Thursday (or whether &amp;#x2018;S’ meant Saturday or Sunday). Different entities in the abstract set of application data need to have different representations.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;One additional point of importance about any form of data in an application concerns the ways in which we need to be able to manipulate it. We turn to processes on data in the next section.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.5</guid>
    <dc:title>3.4 Representing data in applications</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Suppose that you are designing software for some application. You will be working with a programming language that enables you to communicate instructions to a computer. In this programming language, certain forms of data will already be represented electronically. These will include common forms of data, such as numbers, characters and sequences. In any particular application, you are likely also to be concerned with forms of data that are peculiar to that application. Having identified some form of data that you need to be able to handle, you will then need to represent this in terms of what is available; that is, in terms of forms of data that have already been represented electronically.&lt;/p&gt;&lt;p&gt;As a simple example, imagine that integers, characters and strings are available forms of data, and that you want to represent the days of the week.&lt;/p&gt;&lt;p&gt;One natural form of representation is as strings: “Monday”, “Tuesday”, “Wednesday”, and so on. But other forms of representation are possible. The full names can be inconvenient because they involve a lot of writing, so one might choose to use shortened versions, such as: “Mon”, “Tues”, “Wed”, etc. We could be awkward (from the viewpoint of an English speaker), and use the strings: “Lundi”, “Mardi”, “Mercredi”, and so on. Or we could use integers, and represent Monday as 1, Tuesday as 2, Wednesday as 3, etc. This might be very convenient at times, but one then needs to remember which number represents which day.&lt;/p&gt;&lt;p&gt;There are times when it is important to distinguish between a form of data derived from an application situation and the concrete representation you have chosen for it. We might refer to the idea of the days of the week as an &lt;b&gt;abstraction&lt;/b&gt;, in distinction to their &lt;b&gt;representation&lt;/b&gt;, perhaps as the strings “Mon”, “Tues”, “Wed”, etc.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act014"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 13&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;A compact form of representation for days of the week might be to use the first character of the name: ‘M’ for Monday, ‘T’ for Tuesday, and so on. Why would this be a bad idea?&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Because we could not tell whether ‘T’ meant Tuesday or Thursday (or whether ‘S’ meant Saturday or Sunday). Different entities in the abstract set of application data need to have different representations.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;One additional point of importance about any form of data in an application concerns the ways in which we need to be able to manipulate it. We turn to processes on data in the next section.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Objectives for Section 3</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.6</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: disjoint union; power set (of a set); representation (of a data abstraction).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use and interpret the notation:&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt; for the disjoint union of the sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; ;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;SeqOfSetOfInt&lt;/i&gt; for the set consisting of all sequences whose members are sets of integers (and similar notations).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.6</guid>
    <dc:title>Objectives for Section 3</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: disjoint union; power set (of a set); representation (of a data abstraction).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use and interpret the notation:&lt;/p&gt; &lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt; for the disjoint union of the sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; ;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;SeqOfSetOfInt&lt;/i&gt; for the set consisting of all sequences whose members are sets of integers (and similar notations).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Exercises on Section 3</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.7</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq007"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 7&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Each of (a)–(c) is a member of one of the sets given in (i)–(iii). Say which item comes from which set.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Sets&lt;/i&gt;: (i) &lt;i&gt;SetOfSeqOfChar&lt;/i&gt;. (ii) &lt;i&gt;SeqOfSetOfChar&lt;/i&gt;. (iii) &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) {&amp;#x201C;error1&amp;#x201D;, &amp;#x201C;error2&amp;#x201D;, &amp;#x201C;error3&amp;#x201D;}.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [&amp;#x201C;error1&amp;#x201D;, &amp;#x201C;error2&amp;#x201D;, &amp;#x201C;error3&amp;#x201D;].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [{&amp;#x2018;e’,&amp;#x2018;1’}, {&amp;#x2018;T’}, {&amp;#x2018;q’,&amp;#x2018;w’,&amp;#x2018;e’,&amp;#x2018;r’,&amp;#x2018;t’,&amp;#x2018;y’}].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This is a set, as shown by the outer curly brackets. Each member of this set is a string, that is, a sequence of characters. So (a) is a set of sequences of characters. It is a member of &lt;i&gt;SetOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) This is a sequence, as shown by the outer square brackets. It is a sequence of strings. So (b) is a sequence of sequences of characters. It comes from &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) This is again a sequence. Each member of this sequence is a set of characters. So (c) comes from &lt;i&gt;SeqOfSetOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq008"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 8&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Let &lt;i&gt;Mix&lt;/i&gt; be the disjoint union &lt;i&gt;Int&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Char&lt;/i&gt;. What is the length of the following sequence from &lt;i&gt;SeqOfMix&lt;/i&gt;?&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo005"&gt;&lt;blockquote&gt;&lt;p&gt;[555, &amp;#x2018;5’, &amp;#x2018;5’, &amp;#x2018;5’, 11, 1].&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;There are six items in the sequence [555,&amp;#x2018;5’,&amp;#x2018;5’,&amp;#x2018;5’,11,1] (three integers and three characters), so the length of this sequence is 6.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-4.7</guid>
    <dc:title>Exercises on Section 3</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq007"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 7&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Each of (a)–(c) is a member of one of the sets given in (i)–(iii). Say which item comes from which set.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Sets&lt;/i&gt;: (i) &lt;i&gt;SetOfSeqOfChar&lt;/i&gt;. (ii) &lt;i&gt;SeqOfSetOfChar&lt;/i&gt;. (iii) &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) {“error1”, “error2”, “error3”}.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) [“error1”, “error2”, “error3”].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) [{‘e’,‘1’}, {‘T’}, {‘q’,‘w’,‘e’,‘r’,‘t’,‘y’}].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This is a set, as shown by the outer curly brackets. Each member of this set is a string, that is, a sequence of characters. So (a) is a set of sequences of characters. It is a member of &lt;i&gt;SetOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) This is a sequence, as shown by the outer square brackets. It is a sequence of strings. So (b) is a sequence of sequences of characters. It comes from &lt;i&gt;SeqOfSeqOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) This is again a sequence. Each member of this sequence is a set of characters. So (c) comes from &lt;i&gt;SeqOfSetOfChar&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq008"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 8&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Let &lt;i&gt;Mix&lt;/i&gt; be the disjoint union &lt;i&gt;Int&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Char&lt;/i&gt;. What is the length of the following sequence from &lt;i&gt;SeqOfMix&lt;/i&gt;?&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo005"&gt;&lt;blockquote&gt;&lt;p&gt;[555, ‘5’, ‘5’, ‘5’, 11, 1].&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;There are six items in the sequence [555,‘5’,‘5’,‘5’,11,1] (three integers and three characters), so the length of this sequence is 6.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Processes that can be applied to data</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Having looked at some forms of data, we now turn our attention to processes that can be applied to data. Each process that we consider in this section will input data of a specified form, and will result in a corresponding value. For example, one process, which we will call &lt;i&gt;ASC&lt;/i&gt;, takes a character as input, and has as its resulting value the integer giving the ASCII code of the input character (as listed in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;). Another process, which we will call &lt;i&gt;SIZE&lt;/i&gt;, takes a sequence as input, and has as its resulting value the length of the sequence (which will be an integer).&lt;/p&gt;&lt;p&gt;It is important to distinguish between a description of the outcome required when a process is applied to a form of data, and a description of the exact steps to be taken to achieve the desired outcome. Here, we are concerned only with the first of these; that is, with providing an overview of a computing process. You might like to think of this as a &amp;#x201C;black box&amp;#x201D; view of the process. We do not, at this stage, care how one obtains the output value.&lt;/p&gt;&lt;p&gt;Certain processes change the state of a named variable. For now, though, we shall not think about processes in that way. Each process that we are concerned with here simply produces a value that depends on one (or more) input value(s). Another important feature of the processes that we shall consider is that they result in a value that is entirely predictable. One can envisage a process that takes a string as input, and which results in a value that is a character that appears in the string. With input &amp;#x201C;This&amp;#x201D;, the value resulting from such a process might be any of the four characters &amp;#x2018;T’, &amp;#x2018;h’, &amp;#x2018;i’ or &amp;#x2018;s’. We will not consider a process such as that. Our attention will be confined to processes that, if given the same input twice, will produce the same resulting value each time.&lt;/p&gt;&lt;p&gt;Below, we give a number of examples of processes that may be applied to numbers, characters or sequences. Focus first on Example 1(a) below This process is applied to an &lt;b&gt;input&lt;/b&gt;, comprising data of a specified form (a sequence of integers). Application of the process results in a value (the sum of the integers in the input sequence). This resulting value will be referred to as the value &lt;b&gt;returned&lt;/b&gt; by the process. Similar comments apply to each of these examples. Each process takes data of a specified form as an input, and each process returns a value, based on this input data. The returned value may also be called the &lt;b&gt;output&lt;/b&gt; of the process.&lt;/p&gt;&lt;div class="oucontent-example oucontent-s-heavybox1 oucontent-s-box " id="exa001"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Example 1&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Given a sequence of integers, return the sum of all the numbers in the sequence. For example, given [6, 2, 5, 6] the value returned is 19.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Given a string, return the first upper-case letter that appears in the string. For example, given the string &amp;#x201C;my name is Bob&amp;#x201D;, the value returned is &amp;#x2018;B’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Given a string, return the first character in the string. For example, given the string &amp;#x201C;This is a sentence.&amp;#x201D;, the value returned is &amp;#x2018;T’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) Given some integer, &lt;i&gt;x&lt;/i&gt;, say, return the integer &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; + &lt;i&gt;x&lt;/i&gt;. For example, given the number 4, the value returned is 4&lt;sup&gt;2&lt;/sup&gt; + 4 = 20.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) Given a sequence of items from a set &lt;i&gt;X&lt;/i&gt;, and another item from the set &lt;i&gt;X&lt;/i&gt;, return the sequence formed by placing the item at the end of the sequence. For example, given the sequence of integers [6, 2, 5, 6] and the integer 1, the value returned is [6, 2, 5, 6, 1].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(f) Given a string and a character, return the position in the string where the given character first occurs (counting characters from the front of the string). For example, if the string &amp;#x201C;This is a sentence.&amp;#x201D; and the character &amp;#x2018;s’ are given, then the value returned is 4, since the first occurrence of &amp;#x2018;s’ in the string is at the fourth place in the sequence [&amp;#x2018;T’,&amp;#x2018;h’,&amp;#x2018;i’,&amp;#x2018;s’,&amp;#x2018;&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,&amp;#x2018;i’,&amp;#x2018;s’, . . . ].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Here are some key questions to consider about each process.&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;How many inputs are required, and of what type?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What type of value does the process return?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is the relationship between the returned value and the input(s)?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Are there any restrictions on the input(s)?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Does the process always produce an output? Given any permitted input, is there an associated returned value?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Is the output produced predictable? Given the same input, will the process always return the same value?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For example, consider &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(b)&lt;/a&gt; above. In that case the questions can be answered as follows. The process has just one input and this is a sequence of characters. It outputs a character. The output value is the first upper-case letter that appears in the sequence of characters. For this description of the output to yield any value, the input sequence needs to contain at least one upper-case letter. Given that restriction on the input, there will always be an output. The output is predictable.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1</guid>
    <dc:title>Processes that can be applied to data</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Having looked at some forms of data, we now turn our attention to processes that can be applied to data. Each process that we consider in this section will input data of a specified form, and will result in a corresponding value. For example, one process, which we will call &lt;i&gt;ASC&lt;/i&gt;, takes a character as input, and has as its resulting value the integer giving the ASCII code of the input character (as listed in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;). Another process, which we will call &lt;i&gt;SIZE&lt;/i&gt;, takes a sequence as input, and has as its resulting value the length of the sequence (which will be an integer).&lt;/p&gt;&lt;p&gt;It is important to distinguish between a description of the outcome required when a process is applied to a form of data, and a description of the exact steps to be taken to achieve the desired outcome. Here, we are concerned only with the first of these; that is, with providing an overview of a computing process. You might like to think of this as a “black box” view of the process. We do not, at this stage, care how one obtains the output value.&lt;/p&gt;&lt;p&gt;Certain processes change the state of a named variable. For now, though, we shall not think about processes in that way. Each process that we are concerned with here simply produces a value that depends on one (or more) input value(s). Another important feature of the processes that we shall consider is that they result in a value that is entirely predictable. One can envisage a process that takes a string as input, and which results in a value that is a character that appears in the string. With input “This”, the value resulting from such a process might be any of the four characters ‘T’, ‘h’, ‘i’ or ‘s’. We will not consider a process such as that. Our attention will be confined to processes that, if given the same input twice, will produce the same resulting value each time.&lt;/p&gt;&lt;p&gt;Below, we give a number of examples of processes that may be applied to numbers, characters or sequences. Focus first on Example 1(a) below This process is applied to an &lt;b&gt;input&lt;/b&gt;, comprising data of a specified form (a sequence of integers). Application of the process results in a value (the sum of the integers in the input sequence). This resulting value will be referred to as the value &lt;b&gt;returned&lt;/b&gt; by the process. Similar comments apply to each of these examples. Each process takes data of a specified form as an input, and each process returns a value, based on this input data. The returned value may also be called the &lt;b&gt;output&lt;/b&gt; of the process.&lt;/p&gt;&lt;div class="oucontent-example oucontent-s-heavybox1 oucontent-s-box " id="exa001"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h3 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Example 1&lt;/h3&gt;&lt;div class="oucontent-inner-box"&gt;&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Given a sequence of integers, return the sum of all the numbers in the sequence. For example, given [6, 2, 5, 6] the value returned is 19.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Given a string, return the first upper-case letter that appears in the string. For example, given the string “my name is Bob”, the value returned is ‘B’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Given a string, return the first character in the string. For example, given the string “This is a sentence.”, the value returned is ‘T’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) Given some integer, &lt;i&gt;x&lt;/i&gt;, say, return the integer &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; + &lt;i&gt;x&lt;/i&gt;. For example, given the number 4, the value returned is 4&lt;sup&gt;2&lt;/sup&gt; + 4 = 20.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) Given a sequence of items from a set &lt;i&gt;X&lt;/i&gt;, and another item from the set &lt;i&gt;X&lt;/i&gt;, return the sequence formed by placing the item at the end of the sequence. For example, given the sequence of integers [6, 2, 5, 6] and the integer 1, the value returned is [6, 2, 5, 6, 1].&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(f) Given a string and a character, return the position in the string where the given character first occurs (counting characters from the front of the string). For example, if the string “This is a sentence.” and the character ‘s’ are given, then the value returned is 4, since the first occurrence of ‘s’ in the string is at the fourth place in the sequence [‘T’,‘h’,‘i’,‘s’,‘&lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/b36106a4/box.gif" alt="" width="7" height="8" style="max-width:7px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt;’,‘i’,‘s’, . . . ].&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Here are some key questions to consider about each process.&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;How many inputs are required, and of what type?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What type of value does the process return?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What is the relationship between the returned value and the input(s)?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Are there any restrictions on the input(s)?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Does the process always produce an output? Given any permitted input, is there an associated returned value?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Is the output produced predictable? Given the same input, will the process always return the same value?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For example, consider &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(b)&lt;/a&gt; above. In that case the questions can be answered as follows. The process has just one input and this is a sequence of characters. It outputs a character. The output value is the first upper-case letter that appears in the sequence of characters. For this description of the output to yield any value, the input sequence needs to contain at least one upper-case letter. Given that restriction on the input, there will always be an output. The output is predictable.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>4.1 Functions</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.2</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;A &lt;b&gt;function&lt;/b&gt; is a process that, when given an input of a specified type, yields a &lt;b&gt;unique&lt;/b&gt; output. This is a key idea in providing a precise, mathematical, description of processes in computing.&lt;/p&gt;&lt;p&gt;To describe a particular function, we first give the set from which the input will be drawn and the set from which the output is drawn. This information is called the &lt;b&gt;signature&lt;/b&gt; of the function. An example will make this clearer. &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(b)&lt;/a&gt;, on the previous screen, requires an input that is a string, that is, a sequence of characters. The set containing all possible sequences of characters is &lt;i&gt;SeqOfChar&lt;/i&gt;. Example 1(b) produces an output that is a character, so this output is in the set &lt;i&gt;Char&lt;/i&gt;. We write the signature of this function as &lt;i&gt;SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;Char&lt;/i&gt;. The set to the left of the arrow is called the &lt;b&gt;input set&lt;/b&gt; of the function and the set to the right is called the &lt;b&gt;output set&lt;/b&gt;. Some texts use &lt;b&gt;source set&lt;/b&gt; rather than input set, and &lt;b&gt;target set&lt;/b&gt; rather than output set. It is usual to include an identifier for the function itself in the signature. Suppose we call this function &lt;i&gt;FIRSTCAP&lt;/i&gt;. Then its full signature is:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo006"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;FIRSTCAP&lt;/i&gt;: &lt;i&gt;SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;Char&lt;/i&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;&lt;i&gt;SeqOfChar&lt;/i&gt; comprises all sequences of characters, and so includes some sequences that have no upper-case letters.&lt;/p&gt;&lt;p&gt;The second piece of information required in describing a function is any restriction on the input(s). The informal description of &lt;i&gt;FIRSTCAP&lt;/i&gt; states only that the first upper-case letter is returned. It does not specify what happens if there is no upper-case letter in the input. Accordingly, a sensible condition on the set of inputs to &lt;i&gt;FIRSTCAP&lt;/i&gt; is that the input sequence must contain at least one upper-case letter. This condition on the input value is called the &lt;b&gt;precondition&lt;/b&gt; of the function &lt;i&gt;FIRSTCAP&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;The third and final piece of information required is the relationship between output and input values. This relationship is referred to as the &lt;b&gt;semantics&lt;/b&gt; of the function. The semantics must ensure that there is a unique output for any given input. We can describe the function &lt;i&gt;FIRSTCAP&lt;/i&gt; like this:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo007"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;FIRSTCAP&lt;/i&gt; has signature &lt;i&gt;SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;Char&lt;/i&gt;; its input sequence must contain at least one upper-case letter, and it returns the first upper-case letter appearing in the input sequence.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;However, it is not always easy to extract key pieces of information from such a description. We shall usually describe functions using a standard layout, as in the description of &lt;i&gt;FIRSTCAP&lt;/i&gt; given below. In exercises, to signal that we want the description of a function to be laid out as below, we will ask for a &lt;b&gt;full description&lt;/b&gt; of the function.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FIRSTCAP&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;s&lt;/i&gt; contains at least one upper-case letter.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the first upper-case letter appearing in s.&lt;/p&gt;&lt;p&gt;The signature of the function &lt;i&gt;FIRSTCAP&lt;/i&gt; is implicit in the first line of this description. (The signature is &lt;i&gt;FIRSTCAP&lt;/i&gt; : &lt;i&gt;SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;Char&lt;/i&gt;.) This line shows that the function has an input (with identifier &lt;i&gt;s&lt;/i&gt;) that comes from &lt;i&gt;SeqOfChar&lt;/i&gt;. So its input set is &lt;i&gt;SeqOfChar&lt;/i&gt;. The function returns a value in &lt;i&gt;Char&lt;/i&gt;. So its output set is &lt;i&gt;Char&lt;/i&gt;. We refer to the first line in the full description as the &lt;b&gt;signature line&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;The input value &lt;i&gt;s&lt;/i&gt; must satisfy the condition given in the line starting &lt;b&gt;pre&lt;/b&gt;. This line gives the precondition of the function. The semantics of the function are given in the line starting &lt;b&gt;post&lt;/b&gt;. The statement in this line is referred to as the &lt;b&gt;postcondition&lt;/b&gt; of the function.&lt;/p&gt;&lt;p&gt;Here, &amp;#x201C;pre&amp;#x201D; and &amp;#x201C;post&amp;#x201D; are used in the sense of &amp;#x201C;before&amp;#x201D; and &amp;#x201C;after&amp;#x201D;. Before &lt;i&gt;FIRSTCAP&lt;/i&gt; can be applied to a value, that value must satisfy the precondition. After &lt;i&gt;FIRSTCAP&lt;/i&gt; has been applied, the returned value will satisfy the postcondition.&lt;/p&gt;&lt;p&gt;Sometimes, we want to refer to the set of input values for which a function is defined. This is called the &lt;b&gt;domain&lt;/b&gt; of the function, and is the set of values in the input set that satisfy the precondition of the function.&lt;/p&gt;&lt;p&gt;A function that is defined for all elements in its input set is called a &lt;b&gt;total function&lt;/b&gt;. For a total function, no precondition is required on the input value (beyond requiring that it is in the input set). We show this by writing &lt;b&gt;pre true&lt;/b&gt; (since the precondition is automatically true).&lt;/p&gt;&lt;p&gt;As another example, consider the process 4.1(d) given earlier. It stated:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo008"&gt;&lt;blockquote&gt;&lt;p&gt;given some integer, &lt;i&gt;x&lt;/i&gt;, say, return the integer &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; + &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;A full description of this function is given below. We will give it the identifier &lt;i&gt;FORMULA&lt;/i&gt;. The rule for producing an output works for any integer, so we can write &lt;b&gt;true&lt;/b&gt; for the precondition.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FORMULA&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &amp;#xA0; &lt;b&gt; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; + &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act015"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 14&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Call the function associated with &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(c)&lt;/a&gt; on the previous screen, &lt;i&gt;FIRSTCHAR&lt;/i&gt;. Give the signature of this function. Write out a full description of it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Suggest a full description of a function &lt;i&gt;SUMSEQ&lt;/i&gt;, associated with the &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(a)&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Suitable descriptions are given below.&lt;/p&gt;
&lt;p&gt;(a) &lt;i&gt;FIRSTCHAR&lt;/i&gt; inputs a string (sequence of characters), and returns a character. So its signature is &lt;i&gt;FIRSTCHAR : SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;Char&lt;/i&gt;. To have a &amp;#x201C;first character&amp;#x201D;, the input sequence needs to contain at least one character, so the function needs a corresponding precondition.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FIRSTCHAR&lt;/i&gt;(s &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; Char&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;s&lt;/i&gt; contains at least one character.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the first character appearing in &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;The choice of identifier for the input is arbitrary. You may well have used some identifier other than s in your answer.&lt;/p&gt;
&lt;p&gt;(b) Note that &lt;i&gt;SUMSEQ&lt;/i&gt; inputs a sequence of integers, and returns an integer. A suitable description is given below.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;SUMSEQ&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfInt&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is the total of the numbers appearing in &lt;i&gt;s&lt;/i&gt;. If &lt;i&gt;s&lt;/i&gt; contains no members, then the returned value is 0.&lt;/p&gt;
&lt;p&gt;You might have chosen to say that the input sequence should not be empty, since the idea of &amp;#x201C;the total of the numbers&amp;#x201D; might seem unclear if there are no numbers to add up! That would be fine. We have chosen to regard the &amp;#x201C;total of no numbers&amp;#x201D; as 0, and have said so explicitly in the semantics. Sometimes, one needs to make more precise an informal idea of a process. Deciding whether to add a precondition, or to explain what happens in special cases, is the sort of clarification that may be needed.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The value obtained when some function &lt;i&gt;F&lt;/i&gt; is applied to an input &lt;i&gt;x&lt;/i&gt; is written &lt;i&gt;F&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt;). So, for example, &lt;i&gt;FIRSTCAP&lt;/i&gt;(&amp;#x201C;a1wQ2*&amp;#x201D;) means the result of applying the function &lt;i&gt;FIRSTCAP&lt;/i&gt; to the string &amp;#x201C;a1wQ2*&amp;#x201D;. The value obtained in that case is the first upper-case letter in &amp;#x201C;a1wQ2*&amp;#x201D;, and so is &amp;#x2018;Q’.&lt;/p&gt;&lt;p&gt;The &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;example process 1(f)&lt;/a&gt;, given earlier, was:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo009"&gt;&lt;blockquote&gt;&lt;p&gt;Given a string and a character, return the position in the string where the character first occurs.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;For example, if the string &amp;#x201C;This is a sentence.&amp;#x201D; and the character &amp;#x2018;s’ are given, then the value returned is 4. This function requires two inputs: a string (a sequence of characters), and a character. We can describe the function as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FIRSTAT&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;,&lt;i&gt;t&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; The character &lt;i&gt;c&lt;/i&gt; appears at least once in the sequence &lt;i&gt;t&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the integer &lt;i&gt;n&lt;/i&gt; satisfying the condition that the &lt;i&gt;n&lt;/i&gt;th character in the sequence &lt;i&gt;t&lt;/i&gt; is &lt;i&gt;c&lt;/i&gt;, and this is the first occurrence of &lt;i&gt;c&lt;/i&gt; in &lt;i&gt;t&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Where a function requires more than one input, the input set is taken to be a Cartesian product of sets, one for each input. For this example, the input set is &lt;i&gt;Char &amp;#xD7; SeqOfChar&lt;/i&gt;. The output set is &lt;i&gt;Int&lt;/i&gt;, so the signature of the function is &lt;i&gt;FIRSTAT&lt;/i&gt; : &lt;i&gt;Char &amp;#xD7; SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;We can, for example, apply this function in the form&lt;/p&gt;&lt;p&gt;&lt;i&gt;FIRSTAT&lt;/i&gt;(&amp;#x2018;s’, &amp;#x201C;This is a sentence.&amp;#x201D;). However, we cannot apply it in the form &lt;i&gt;FIRSTAT&lt;/i&gt;(&amp;#x201C;This is a sentence.&amp;#x201D;, &amp;#x2018;s’). The order of the two inputs given in the signature line in the description of &lt;i&gt;FIRSTAT&lt;/i&gt; must be adhered to.&lt;/p&gt;&lt;p&gt;(We could have described a function accepting the inputs in a different order, with the sequence first and the character second. But this would be another function, different from &lt;i&gt;FIRSTAT&lt;/i&gt;, just as reversing the order in which two sets are written in a Cartesian product produces a different set.)&lt;/p&gt;&lt;p&gt;Look now at &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(e)&lt;/a&gt;, repeated below.&lt;/p&gt;&lt;p&gt;Given a sequence of items from a set &lt;i&gt;X&lt;/i&gt;, and another item from the set &lt;i&gt;X&lt;/i&gt;, return the sequence formed by placing the item at the end of the sequence. For example, given the sequence of integers [6,2,5,6] and the integer 1, the value returned is [6,2,5,6,1].&lt;/p&gt;&lt;p&gt;Note that this description is not confined to sequences of numbers. It can be used for sequences with members from any set. This general set is represented here by &lt;i&gt;X&lt;/i&gt;. We can describe a function &lt;i&gt;ADDLAST&lt;/i&gt; corresponding to this process as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ADDLAST&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt; , &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is formed by placing the item &lt;i&gt;x&lt;/i&gt; at the end of the sequence &lt;i&gt;s&lt;/i&gt;. For example, &lt;i&gt;ADDLAST&lt;/i&gt;(1,[6, 2, 5, 6]) = [6, 2, 5, 6, 1].&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act016"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 15&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give the signature of the function ADDLAST.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) What are the values:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) ADDLAST(7,[1, 4, 3, 2]);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;ADDLAST&lt;/i&gt;(&amp;#x2018;y’,&amp;#x201C;qwert&amp;#x201D;);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;ADDLAST&lt;/i&gt;(&amp;#x201C;qwert&amp;#x201D;,&amp;#x2018;y’)?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) The signature is &lt;i&gt;ADDLAST : X &amp;#xD7; SeqOfX&lt;/i&gt; &amp;#x2192; &lt;i&gt;SeqOfX&lt;/i&gt; . (The order of the sets in the Cartesian product corresponds to the order of the inputs given in the description above.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) We have:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;ADDLAST&lt;/i&gt;(7, [1, 4, 3, 2]) = [1, 4, 3, 2, 7];&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;ADDLAST&lt;/i&gt;(&amp;#x2018;y’, &amp;#x201C;qwert&amp;#x201D;) = &amp;#x201C;qwerty&amp;#x201D;;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;ADDLAST&lt;/i&gt;(&amp;#x201C;qwert&amp;#x201D;,&amp;#x2018;y’) cannot be formed. The inputs are given in the wrong order.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act017"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 16&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;This activity concerns the three functions on sequences given below. In each case, the sequence members come from an arbitrary set, &lt;i&gt;X&lt;/i&gt;. You will meet these functions again later in the course.&lt;/p&gt;
&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;A function &lt;i&gt;SIZE&lt;/i&gt;, which, given a sequence, returns the number of members in it (that is, it returns the length of the sequence). So, for example, &lt;i&gt;SIZE&lt;/i&gt;([1, 11, &amp;#x2212;32, 4, 12, 1]) = 6.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A function &lt;i&gt;AT&lt;/i&gt;, which returns the item that is at a specified position in a sequence. So, for example, &lt;i&gt;AT&lt;/i&gt;(4, &amp;#x201C;author&amp;#x201D;) = &amp;#x2018;h’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A function &lt;i&gt;PUT&lt;/i&gt;, which replaces the item that is at a specified position in a sequence with an item supplied as an input. So, for example, &lt;i&gt;PUT&lt;/i&gt;(4,&amp;#x201C;author&amp;#x201D;,&amp;#x2018;q’) = &amp;#x201C;autqor&amp;#x201D;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give the values of:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;SIZE&lt;/i&gt;(&amp;#x201C;author&amp;#x201D;);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;AT&lt;/i&gt;(3,[1, 11&lt;i&gt;, -&lt;/i&gt;32, 4]);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;PUT&lt;/i&gt;(3,&amp;#x201C;paan&amp;#x201D;,&amp;#x2018;i’);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iv) &lt;i&gt;PUT&lt;/i&gt;(2, [1, 8, 2, 4], 3).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Give the signature of each of the three functions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Give full descriptions of each of the three functions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;(a) (i) 6 (the number of characters in the string &amp;#x201C;author&amp;#x201D;).&lt;/p&gt;
&lt;p&gt;(ii) &amp;#x2212;32 (the third item in the sequence [1, 11, &amp;#x2212;32, 4]).&lt;/p&gt;
&lt;p&gt;(iii) We replace the character at the third place in the string &amp;#x201C;paan&amp;#x201D; by the input character &amp;#x2018;i’, to get &amp;#x201C;pain&amp;#x201D;.&lt;/p&gt;
&lt;p&gt;(iv) The first number gives the position of the item to be changed and the final number is the replacement item. So the value is [1, 3, 2, 4].&lt;/p&gt;
&lt;p&gt;(b) &lt;i&gt;SIZE&lt;/i&gt; has one input, from &lt;i&gt;SeqOfX&lt;/i&gt; , and returns a value in &lt;i&gt;Int&lt;/i&gt;. The signature is &lt;i&gt;SIZE : SeqOfX&lt;/i&gt; &amp;#x2192; &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;The function &lt;i&gt;AT&lt;/i&gt; inputs an integer and a sequence and returns a value from &lt;i&gt;X&lt;/i&gt;, so the signature is &lt;i&gt;AT : Int &amp;#xD7; SeqOfX&lt;/i&gt; &amp;#x2192; &lt;i&gt;X&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;For the function &lt;i&gt;PUT&lt;/i&gt;, the input set is a Cartesian product of three sets, one for each of the three inputs.&lt;/p&gt;
&lt;p&gt;The signature is PUT : Int &amp;#xD7; SeqOfX &amp;#xD7; X &amp;#x2192; SeqOfX .&lt;/p&gt;
&lt;p&gt;(c) Suitable descriptions are given below.&lt;/p&gt;
&lt;p&gt;For &lt;i&gt;SIZE&lt;/i&gt;, recall that the number of elements in the empty sequence is 0, so this is a total function.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &amp;#xA0; &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is the number of items in the sequence &lt;i&gt;s&lt;/i&gt;. If &lt;i&gt;s&lt;/i&gt; contains no members then the returned value is 0.&lt;/p&gt;
&lt;p&gt;For &lt;i&gt;AT&lt;/i&gt;, the semantics only make sense if the integer input gives a position actually in the sequence. So we give a precondition that the input integer is at least 1 (when the first item in the sequence will be returned), and that the input integer is not bigger than the number of items in the sequence. If we use another function in a description, as we use &lt;i&gt;SIZE&lt;/i&gt; here in describing &lt;i&gt;AT&lt;/i&gt;, then we must describe that function too. &lt;i&gt;SIZE&lt;/i&gt; was described above.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;AT&lt;/i&gt;(&lt;i&gt;i&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 1&amp;#x2264; &lt;i&gt;i&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt;&amp;#x2264; &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;).&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the &lt;i&gt;i&lt;/i&gt;th item in the sequence &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;The function &lt;i&gt;PUT&lt;/i&gt; has three inputs, an integer (giving the position of the item to be changed), the sequence to be modified, and the replacement item (from the set &lt;i&gt;X&lt;/i&gt;). It requires the same precondition as &lt;i&gt;AT&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;PUT&lt;/i&gt;(&lt;i&gt;i&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; , &lt;i&gt;x&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 1 &amp;#x2264; &lt;i&gt;i&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt; &amp;#x2264; &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;).&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the sequence formed by replacing the &lt;i&gt;i&lt;/i&gt;th item in &lt;i&gt;s&lt;/i&gt; by &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.2</guid>
    <dc:title>4.1 Functions</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;A &lt;b&gt;function&lt;/b&gt; is a process that, when given an input of a specified type, yields a &lt;b&gt;unique&lt;/b&gt; output. This is a key idea in providing a precise, mathematical, description of processes in computing.&lt;/p&gt;&lt;p&gt;To describe a particular function, we first give the set from which the input will be drawn and the set from which the output is drawn. This information is called the &lt;b&gt;signature&lt;/b&gt; of the function. An example will make this clearer. &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(b)&lt;/a&gt;, on the previous screen, requires an input that is a string, that is, a sequence of characters. The set containing all possible sequences of characters is &lt;i&gt;SeqOfChar&lt;/i&gt;. Example 1(b) produces an output that is a character, so this output is in the set &lt;i&gt;Char&lt;/i&gt;. We write the signature of this function as &lt;i&gt;SeqOfChar&lt;/i&gt; → &lt;i&gt;Char&lt;/i&gt;. The set to the left of the arrow is called the &lt;b&gt;input set&lt;/b&gt; of the function and the set to the right is called the &lt;b&gt;output set&lt;/b&gt;. Some texts use &lt;b&gt;source set&lt;/b&gt; rather than input set, and &lt;b&gt;target set&lt;/b&gt; rather than output set. It is usual to include an identifier for the function itself in the signature. Suppose we call this function &lt;i&gt;FIRSTCAP&lt;/i&gt;. Then its full signature is:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo006"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;FIRSTCAP&lt;/i&gt;: &lt;i&gt;SeqOfChar&lt;/i&gt; → &lt;i&gt;Char&lt;/i&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;&lt;i&gt;SeqOfChar&lt;/i&gt; comprises all sequences of characters, and so includes some sequences that have no upper-case letters.&lt;/p&gt;&lt;p&gt;The second piece of information required in describing a function is any restriction on the input(s). The informal description of &lt;i&gt;FIRSTCAP&lt;/i&gt; states only that the first upper-case letter is returned. It does not specify what happens if there is no upper-case letter in the input. Accordingly, a sensible condition on the set of inputs to &lt;i&gt;FIRSTCAP&lt;/i&gt; is that the input sequence must contain at least one upper-case letter. This condition on the input value is called the &lt;b&gt;precondition&lt;/b&gt; of the function &lt;i&gt;FIRSTCAP&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;The third and final piece of information required is the relationship between output and input values. This relationship is referred to as the &lt;b&gt;semantics&lt;/b&gt; of the function. The semantics must ensure that there is a unique output for any given input. We can describe the function &lt;i&gt;FIRSTCAP&lt;/i&gt; like this:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo007"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;FIRSTCAP&lt;/i&gt; has signature &lt;i&gt;SeqOfChar&lt;/i&gt; → &lt;i&gt;Char&lt;/i&gt;; its input sequence must contain at least one upper-case letter, and it returns the first upper-case letter appearing in the input sequence.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;However, it is not always easy to extract key pieces of information from such a description. We shall usually describe functions using a standard layout, as in the description of &lt;i&gt;FIRSTCAP&lt;/i&gt; given below. In exercises, to signal that we want the description of a function to be laid out as below, we will ask for a &lt;b&gt;full description&lt;/b&gt; of the function.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FIRSTCAP&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;s&lt;/i&gt; contains at least one upper-case letter.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the first upper-case letter appearing in s.&lt;/p&gt;&lt;p&gt;The signature of the function &lt;i&gt;FIRSTCAP&lt;/i&gt; is implicit in the first line of this description. (The signature is &lt;i&gt;FIRSTCAP&lt;/i&gt; : &lt;i&gt;SeqOfChar&lt;/i&gt; → &lt;i&gt;Char&lt;/i&gt;.) This line shows that the function has an input (with identifier &lt;i&gt;s&lt;/i&gt;) that comes from &lt;i&gt;SeqOfChar&lt;/i&gt;. So its input set is &lt;i&gt;SeqOfChar&lt;/i&gt;. The function returns a value in &lt;i&gt;Char&lt;/i&gt;. So its output set is &lt;i&gt;Char&lt;/i&gt;. We refer to the first line in the full description as the &lt;b&gt;signature line&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;The input value &lt;i&gt;s&lt;/i&gt; must satisfy the condition given in the line starting &lt;b&gt;pre&lt;/b&gt;. This line gives the precondition of the function. The semantics of the function are given in the line starting &lt;b&gt;post&lt;/b&gt;. The statement in this line is referred to as the &lt;b&gt;postcondition&lt;/b&gt; of the function.&lt;/p&gt;&lt;p&gt;Here, “pre” and “post” are used in the sense of “before” and “after”. Before &lt;i&gt;FIRSTCAP&lt;/i&gt; can be applied to a value, that value must satisfy the precondition. After &lt;i&gt;FIRSTCAP&lt;/i&gt; has been applied, the returned value will satisfy the postcondition.&lt;/p&gt;&lt;p&gt;Sometimes, we want to refer to the set of input values for which a function is defined. This is called the &lt;b&gt;domain&lt;/b&gt; of the function, and is the set of values in the input set that satisfy the precondition of the function.&lt;/p&gt;&lt;p&gt;A function that is defined for all elements in its input set is called a &lt;b&gt;total function&lt;/b&gt;. For a total function, no precondition is required on the input value (beyond requiring that it is in the input set). We show this by writing &lt;b&gt;pre true&lt;/b&gt; (since the precondition is automatically true).&lt;/p&gt;&lt;p&gt;As another example, consider the process 4.1(d) given earlier. It stated:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo008"&gt;&lt;blockquote&gt;&lt;p&gt;given some integer, &lt;i&gt;x&lt;/i&gt;, say, return the integer &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; + &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;A full description of this function is given below. We will give it the identifier &lt;i&gt;FORMULA&lt;/i&gt;. The rule for producing an output works for any integer, so we can write &lt;b&gt;true&lt;/b&gt; for the precondition.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FORMULA&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt;   &lt;b&gt; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;i&gt;x&lt;/i&gt; &lt;sup&gt;2&lt;/sup&gt; + &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act015"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 14&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Call the function associated with &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(c)&lt;/a&gt; on the previous screen, &lt;i&gt;FIRSTCHAR&lt;/i&gt;. Give the signature of this function. Write out a full description of it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Suggest a full description of a function &lt;i&gt;SUMSEQ&lt;/i&gt;, associated with the &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(a)&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Suitable descriptions are given below.&lt;/p&gt;
&lt;p&gt;(a) &lt;i&gt;FIRSTCHAR&lt;/i&gt; inputs a string (sequence of characters), and returns a character. So its signature is &lt;i&gt;FIRSTCHAR : SeqOfChar&lt;/i&gt; → &lt;i&gt;Char&lt;/i&gt;. To have a “first character”, the input sequence needs to contain at least one character, so the function needs a corresponding precondition.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FIRSTCHAR&lt;/i&gt;(s &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; Char&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;s&lt;/i&gt; contains at least one character.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the first character appearing in &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;The choice of identifier for the input is arbitrary. You may well have used some identifier other than s in your answer.&lt;/p&gt;
&lt;p&gt;(b) Note that &lt;i&gt;SUMSEQ&lt;/i&gt; inputs a sequence of integers, and returns an integer. A suitable description is given below.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;SUMSEQ&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfInt&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is the total of the numbers appearing in &lt;i&gt;s&lt;/i&gt;. If &lt;i&gt;s&lt;/i&gt; contains no members, then the returned value is 0.&lt;/p&gt;
&lt;p&gt;You might have chosen to say that the input sequence should not be empty, since the idea of “the total of the numbers” might seem unclear if there are no numbers to add up! That would be fine. We have chosen to regard the “total of no numbers” as 0, and have said so explicitly in the semantics. Sometimes, one needs to make more precise an informal idea of a process. Deciding whether to add a precondition, or to explain what happens in special cases, is the sort of clarification that may be needed.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The value obtained when some function &lt;i&gt;F&lt;/i&gt; is applied to an input &lt;i&gt;x&lt;/i&gt; is written &lt;i&gt;F&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt;). So, for example, &lt;i&gt;FIRSTCAP&lt;/i&gt;(“a1wQ2*”) means the result of applying the function &lt;i&gt;FIRSTCAP&lt;/i&gt; to the string “a1wQ2*”. The value obtained in that case is the first upper-case letter in “a1wQ2*”, and so is ‘Q’.&lt;/p&gt;&lt;p&gt;The &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;example process 1(f)&lt;/a&gt;, given earlier, was:&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo009"&gt;&lt;blockquote&gt;&lt;p&gt;Given a string and a character, return the position in the string where the character first occurs.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;For example, if the string “This is a sentence.” and the character ‘s’ are given, then the value returned is 4. This function requires two inputs: a string (a sequence of characters), and a character. We can describe the function as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;FIRSTAT&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;,&lt;i&gt;t&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; The character &lt;i&gt;c&lt;/i&gt; appears at least once in the sequence &lt;i&gt;t&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the integer &lt;i&gt;n&lt;/i&gt; satisfying the condition that the &lt;i&gt;n&lt;/i&gt;th character in the sequence &lt;i&gt;t&lt;/i&gt; is &lt;i&gt;c&lt;/i&gt;, and this is the first occurrence of &lt;i&gt;c&lt;/i&gt; in &lt;i&gt;t&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Where a function requires more than one input, the input set is taken to be a Cartesian product of sets, one for each input. For this example, the input set is &lt;i&gt;Char × SeqOfChar&lt;/i&gt;. The output set is &lt;i&gt;Int&lt;/i&gt;, so the signature of the function is &lt;i&gt;FIRSTAT&lt;/i&gt; : &lt;i&gt;Char × SeqOfChar&lt;/i&gt; → &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;We can, for example, apply this function in the form&lt;/p&gt;&lt;p&gt;&lt;i&gt;FIRSTAT&lt;/i&gt;(‘s’, “This is a sentence.”). However, we cannot apply it in the form &lt;i&gt;FIRSTAT&lt;/i&gt;(“This is a sentence.”, ‘s’). The order of the two inputs given in the signature line in the description of &lt;i&gt;FIRSTAT&lt;/i&gt; must be adhered to.&lt;/p&gt;&lt;p&gt;(We could have described a function accepting the inputs in a different order, with the sequence first and the character second. But this would be another function, different from &lt;i&gt;FIRSTAT&lt;/i&gt;, just as reversing the order in which two sets are written in a Cartesian product produces a different set.)&lt;/p&gt;&lt;p&gt;Look now at &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.1#exa001"&gt;Example 1(e)&lt;/a&gt;, repeated below.&lt;/p&gt;&lt;p&gt;Given a sequence of items from a set &lt;i&gt;X&lt;/i&gt;, and another item from the set &lt;i&gt;X&lt;/i&gt;, return the sequence formed by placing the item at the end of the sequence. For example, given the sequence of integers [6,2,5,6] and the integer 1, the value returned is [6,2,5,6,1].&lt;/p&gt;&lt;p&gt;Note that this description is not confined to sequences of numbers. It can be used for sequences with members from any set. This general set is represented here by &lt;i&gt;X&lt;/i&gt;. We can describe a function &lt;i&gt;ADDLAST&lt;/i&gt; corresponding to this process as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ADDLAST&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt; , &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is formed by placing the item &lt;i&gt;x&lt;/i&gt; at the end of the sequence &lt;i&gt;s&lt;/i&gt;. For example, &lt;i&gt;ADDLAST&lt;/i&gt;(1,[6, 2, 5, 6]) = [6, 2, 5, 6, 1].&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act016"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 15&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give the signature of the function ADDLAST.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) What are the values:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) ADDLAST(7,[1, 4, 3, 2]);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;ADDLAST&lt;/i&gt;(‘y’,“qwert”);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;ADDLAST&lt;/i&gt;(“qwert”,‘y’)?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) The signature is &lt;i&gt;ADDLAST : X × SeqOfX&lt;/i&gt; → &lt;i&gt;SeqOfX&lt;/i&gt; . (The order of the sets in the Cartesian product corresponds to the order of the inputs given in the description above.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) We have:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;ADDLAST&lt;/i&gt;(7, [1, 4, 3, 2]) = [1, 4, 3, 2, 7];&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;ADDLAST&lt;/i&gt;(‘y’, “qwert”) = “qwerty”;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;ADDLAST&lt;/i&gt;(“qwert”,‘y’) cannot be formed. The inputs are given in the wrong order.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act017"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 16&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;This activity concerns the three functions on sequences given below. In each case, the sequence members come from an arbitrary set, &lt;i&gt;X&lt;/i&gt;. You will meet these functions again later in the course.&lt;/p&gt;
&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;A function &lt;i&gt;SIZE&lt;/i&gt;, which, given a sequence, returns the number of members in it (that is, it returns the length of the sequence). So, for example, &lt;i&gt;SIZE&lt;/i&gt;([1, 11, −32, 4, 12, 1]) = 6.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A function &lt;i&gt;AT&lt;/i&gt;, which returns the item that is at a specified position in a sequence. So, for example, &lt;i&gt;AT&lt;/i&gt;(4, “author”) = ‘h’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A function &lt;i&gt;PUT&lt;/i&gt;, which replaces the item that is at a specified position in a sequence with an item supplied as an input. So, for example, &lt;i&gt;PUT&lt;/i&gt;(4,“author”,‘q’) = “autqor”.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give the values of:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;SIZE&lt;/i&gt;(“author”);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;AT&lt;/i&gt;(3,[1, 11&lt;i&gt;, -&lt;/i&gt;32, 4]);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;PUT&lt;/i&gt;(3,“paan”,‘i’);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iv) &lt;i&gt;PUT&lt;/i&gt;(2, [1, 8, 2, 4], 3).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Give the signature of each of the three functions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Give full descriptions of each of the three functions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;(a) (i) 6 (the number of characters in the string “author”).&lt;/p&gt;
&lt;p&gt;(ii) −32 (the third item in the sequence [1, 11, −32, 4]).&lt;/p&gt;
&lt;p&gt;(iii) We replace the character at the third place in the string “paan” by the input character ‘i’, to get “pain”.&lt;/p&gt;
&lt;p&gt;(iv) The first number gives the position of the item to be changed and the final number is the replacement item. So the value is [1, 3, 2, 4].&lt;/p&gt;
&lt;p&gt;(b) &lt;i&gt;SIZE&lt;/i&gt; has one input, from &lt;i&gt;SeqOfX&lt;/i&gt; , and returns a value in &lt;i&gt;Int&lt;/i&gt;. The signature is &lt;i&gt;SIZE : SeqOfX&lt;/i&gt; → &lt;i&gt;Int&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;The function &lt;i&gt;AT&lt;/i&gt; inputs an integer and a sequence and returns a value from &lt;i&gt;X&lt;/i&gt;, so the signature is &lt;i&gt;AT : Int × SeqOfX&lt;/i&gt; → &lt;i&gt;X&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;For the function &lt;i&gt;PUT&lt;/i&gt;, the input set is a Cartesian product of three sets, one for each of the three inputs.&lt;/p&gt;
&lt;p&gt;The signature is PUT : Int × SeqOfX × X → SeqOfX .&lt;/p&gt;
&lt;p&gt;(c) Suitable descriptions are given below.&lt;/p&gt;
&lt;p&gt;For &lt;i&gt;SIZE&lt;/i&gt;, recall that the number of elements in the empty sequence is 0, so this is a total function.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt;   &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is the number of items in the sequence &lt;i&gt;s&lt;/i&gt;. If &lt;i&gt;s&lt;/i&gt; contains no members then the returned value is 0.&lt;/p&gt;
&lt;p&gt;For &lt;i&gt;AT&lt;/i&gt;, the semantics only make sense if the integer input gives a position actually in the sequence. So we give a precondition that the input integer is at least 1 (when the first item in the sequence will be returned), and that the input integer is not bigger than the number of items in the sequence. If we use another function in a description, as we use &lt;i&gt;SIZE&lt;/i&gt; here in describing &lt;i&gt;AT&lt;/i&gt;, then we must describe that function too. &lt;i&gt;SIZE&lt;/i&gt; was described above.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;AT&lt;/i&gt;(&lt;i&gt;i&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 1≤ &lt;i&gt;i&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt;≤ &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;).&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the &lt;i&gt;i&lt;/i&gt;th item in the sequence &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;The function &lt;i&gt;PUT&lt;/i&gt; has three inputs, an integer (giving the position of the item to be changed), the sequence to be modified, and the replacement item (from the set &lt;i&gt;X&lt;/i&gt;). It requires the same precondition as &lt;i&gt;AT&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;PUT&lt;/i&gt;(&lt;i&gt;i&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; , &lt;i&gt;x&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 1 ≤ &lt;i&gt;i&lt;/i&gt; and &lt;i&gt;i&lt;/i&gt; ≤ &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;).&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the sequence formed by replacing the &lt;i&gt;i&lt;/i&gt;th item in &lt;i&gt;s&lt;/i&gt; by &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>4.2 Functions defined through cases</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.3</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;In each of the examples considered so far, the function has had its semantics expressed using a formula or a general rule. Some functions have their semantics expressed simply by listing the output for each possible input. For example, let &lt;i&gt;Days&lt;/i&gt; be the set of days of the week, and the function &lt;i&gt;TOMORROW&lt;/i&gt; have signature &lt;i&gt;Days&lt;/i&gt; &amp;#x2192; &lt;i&gt;Days&lt;/i&gt;, and return the day following the input day. If we represent &lt;i&gt;Days&lt;/i&gt; using the strings {&amp;#x201C;Mon&amp;#x201D;, &amp;#x201C;Tues&amp;#x201D;, &amp;#x201C;Wed&amp;#x201D;, &amp;#x201C;Thurs&amp;#x201D;, &amp;#x201C;Fri&amp;#x201D;, &amp;#x201C;Sat&amp;#x201D;, &amp;#x201C;Sun&amp;#x201D;}, then we can describe the corresponding representation of the function &lt;i&gt;TOMORROW&lt;/i&gt; as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;TOMORROW1&lt;/i&gt;(&lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;d&lt;/i&gt; is in the set {&amp;#x201C;Mon&amp;#x201D;,&amp;#x201C;Tues&amp;#x201D;,&amp;#x201C;Wed&amp;#x201D;,&amp;#x201C;Thurs&amp;#x201D;,&amp;#x201C;Fri&amp;#x201D;,&amp;#x201C;Sat&amp;#x201D;,&amp;#x201C;Sun&amp;#x201D;}.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;t&lt;/i&gt;, where:&lt;/p&gt;&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = &amp;#x201C;Mon&amp;#x201D; then &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;Tues&amp;#x201D;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = &amp;#x201C;Tues&amp;#x201D; then &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;Wed&amp;#x201D;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = &amp;#x201C;Wed&amp;#x201D; then &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;Thurs&amp;#x201D;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = &amp;#x201C;Thurs&amp;#x201D; then &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;Fri&amp;#x201D;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = &amp;#x201C;Fri&amp;#x201D; then &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;Sat&amp;#x201D;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = &amp;#x201C;Sat&amp;#x201D; then &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;Sun&amp;#x201D;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = &amp;#x201C;Sun&amp;#x201D; then &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;Mon&amp;#x201D;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We distinguish the abstraction (the function &lt;i&gt;TOMORROW&lt;/i&gt;) from its representation (the function &lt;i&gt;TOMORROW1&lt;/i&gt;), because different representations of the set Days will lead to different representations of the function &lt;i&gt;TOMORROW&lt;/i&gt; (see, for example, Exercise 2).&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act018"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 17&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that a particular breakfast cereal is sold in sizes Small, Medium and Large, and that we choose to represent these by the characters &amp;#x2018;S’, &amp;#x2018;M’ and &amp;#x2018;L’. Their respective prices, in pence, are 89 for &amp;#x2018;S’, 119 for &amp;#x2018;M’ and 159 for &amp;#x2018;L’. Describe a function &lt;i&gt;CEREALPRICE&lt;/i&gt; that takes a size as input and returns the associated price.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;We can describe this function as follows.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;CEREALPRICE&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;c&lt;/i&gt; is in the set {&amp;#x2018;S’, &amp;#x2018;M’, &amp;#x2018;L’}.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;p&lt;/i&gt;, where:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;c&lt;/i&gt; = &amp;#x2018;S’ then &lt;i&gt;p&lt;/i&gt; = 89&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;c&lt;/i&gt; = &amp;#x2018;M’ then &lt;i&gt;p&lt;/i&gt; = 119&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;c&lt;/i&gt; = &amp;#x2018;L’ then &lt;i&gt;p&lt;/i&gt; = 159.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.3</guid>
    <dc:title>4.2 Functions defined through cases</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;In each of the examples considered so far, the function has had its semantics expressed using a formula or a general rule. Some functions have their semantics expressed simply by listing the output for each possible input. For example, let &lt;i&gt;Days&lt;/i&gt; be the set of days of the week, and the function &lt;i&gt;TOMORROW&lt;/i&gt; have signature &lt;i&gt;Days&lt;/i&gt; → &lt;i&gt;Days&lt;/i&gt;, and return the day following the input day. If we represent &lt;i&gt;Days&lt;/i&gt; using the strings {“Mon”, “Tues”, “Wed”, “Thurs”, “Fri”, “Sat”, “Sun”}, then we can describe the corresponding representation of the function &lt;i&gt;TOMORROW&lt;/i&gt; as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;TOMORROW1&lt;/i&gt;(&lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;d&lt;/i&gt; is in the set {“Mon”,“Tues”,“Wed”,“Thurs”,“Fri”,“Sat”,“Sun”}.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;t&lt;/i&gt;, where:&lt;/p&gt;&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = “Mon” then &lt;i&gt;t&lt;/i&gt; = “Tues”&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = “Tues” then &lt;i&gt;t&lt;/i&gt; = “Wed”&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = “Wed” then &lt;i&gt;t&lt;/i&gt; = “Thurs”&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = “Thurs” then &lt;i&gt;t&lt;/i&gt; = “Fri”&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = “Fri” then &lt;i&gt;t&lt;/i&gt; = “Sat”&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = “Sat” then &lt;i&gt;t&lt;/i&gt; = “Sun”&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = “Sun” then &lt;i&gt;t&lt;/i&gt; = “Mon”.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We distinguish the abstraction (the function &lt;i&gt;TOMORROW&lt;/i&gt;) from its representation (the function &lt;i&gt;TOMORROW1&lt;/i&gt;), because different representations of the set Days will lead to different representations of the function &lt;i&gt;TOMORROW&lt;/i&gt; (see, for example, Exercise 2).&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act018"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 17&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that a particular breakfast cereal is sold in sizes Small, Medium and Large, and that we choose to represent these by the characters ‘S’, ‘M’ and ‘L’. Their respective prices, in pence, are 89 for ‘S’, 119 for ‘M’ and 159 for ‘L’. Describe a function &lt;i&gt;CEREALPRICE&lt;/i&gt; that takes a size as input and returns the associated price.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;We can describe this function as follows.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;CEREALPRICE&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;c&lt;/i&gt; is in the set {‘S’, ‘M’, ‘L’}.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;p&lt;/i&gt;, where:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;c&lt;/i&gt; = ‘S’ then &lt;i&gt;p&lt;/i&gt; = 89&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;c&lt;/i&gt; = ‘M’ then &lt;i&gt;p&lt;/i&gt; = 119&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;c&lt;/i&gt; = ‘L’ then &lt;i&gt;p&lt;/i&gt; = 159.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>4.3 Character code functions</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.4</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Many programming languages provide two functions associated with the character codes (see &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;). We shall call these functions &lt;i&gt;ASC&lt;/i&gt; and &lt;i&gt;CHR. ASC&lt;/i&gt; takes a character as input, and returns the integer giving the ASCII code of the input character. &lt;i&gt;CHR&lt;/i&gt; returns the character whose ASCII code is the input integer. These functions are described below. We have set a precondition on &lt;i&gt;CHR&lt;/i&gt; to conform to our earlier restriction on the set of characters that we will consider in this course.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is the &lt;b&gt;ASCII&lt;/b&gt; code of &lt;i&gt;c&lt;/i&gt;, as given in Table 2.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 32 &amp;#x2264; &lt;i&gt;n&lt;/i&gt; &amp;#x2264; 126.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the character with ASCII code &lt;i&gt;n&lt;/i&gt;, as given in Table 2.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act019"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 18&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Find each of:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;ASC&lt;/i&gt;(&amp;#x2018;j’);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;CHR&lt;/i&gt;(43);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(43));&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&amp;#x2018;j’)).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Referring to &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;, &lt;i&gt;ASC&lt;/i&gt;(&amp;#x2018;j’) = 106.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;CHR&lt;/i&gt;(43) = &amp;#x2018;+’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(43)) means the result of applying the function &lt;i&gt;ASC&lt;/i&gt; to &lt;i&gt;CHR&lt;/i&gt;(43). So &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(43)) = &lt;i&gt;ASC&lt;/i&gt;(&amp;#x2018;+’) = 43.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&amp;#x2018;j’)) = &lt;i&gt;CHR&lt;/i&gt;(106) = &amp;#x2018;j’.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Looking up the ASCII code of a character, and then looking to see the character corresponding to the number you just found, will always take you back to the character you started with. We can express this in a general equation, as &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt;)) = &lt;i&gt;c&lt;/i&gt;. (This holds for any character &lt;i&gt;c&lt;/i&gt;.)&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;As illustrated in Activity 18, the two functions &lt;i&gt;ASC&lt;/i&gt; and &lt;i&gt;CHR&lt;/i&gt; are closely related. Each reverses the effect of the other. We can express this relationship by writing the two equations below (which hold for every &lt;i&gt;c&lt;/i&gt; in &lt;i&gt;Char&lt;/i&gt; and for every &lt;i&gt;n&lt;/i&gt; in &lt;i&gt;Int&lt;/i&gt; satisfying the condition 32 &amp;#x2264; &lt;i&gt;n&lt;/i&gt; &amp;#x2264; 126).&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo010"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;)) = &lt;i&gt;n&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt;)) = &lt;i&gt;c&lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;We say that &lt;i&gt;ASC&lt;/i&gt; and &lt;i&gt;CHR&lt;/i&gt; are &lt;b&gt;inverse functions&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Not every function can be paired up with an inverse function in this way. For example, the function &lt;i&gt;FIRSTCHAR&lt;/i&gt; returns the first character in a string. Now different strings may have the same first character. (&amp;#x201C;This&amp;#x201D; and &amp;#x201C;The&amp;#x201D; both start with &amp;#x2018;T’, but are different strings.) With input &amp;#x2018;T’, a process attempting to reverse the effect of &lt;i&gt;FIRSTCHAR&lt;/i&gt; would not know whether to return &amp;#x201C;This&amp;#x201D; or &amp;#x201C;The&amp;#x201D; (or &amp;#x201C;To&amp;#x201D;, or &amp;#x201C;Tom&amp;#x201D;, etc). The function &lt;i&gt;FIRSTCHAR&lt;/i&gt; has no inverse function.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act020"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 19&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;A simple cipher replaces each lower-case letter with the next one in alphabetical order. So &amp;#x2018;a’ is replaced by &amp;#x2018;b’, &amp;#x2018;b’ by &amp;#x2018;c’,. . . , &amp;#x2018;t’ by &amp;#x2018;u’, and so on. The letter z &amp;#x2018; ’ is replaced by &amp;#x2018;a’. The function &lt;i&gt;NEXT&lt;/i&gt;, specified below, corresponds to this coding.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;NEXT&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; in &lt;i&gt;Char&lt;/i&gt;) return in &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;c&lt;/i&gt; is a lower-case letter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; If &lt;i&gt;c&lt;/i&gt; lies between &amp;#x2018;a’ and &amp;#x2018;y’ then the returned value is the letter following &lt;i&gt;c&lt;/i&gt; in alphabetical order. If &lt;i&gt;c&lt;/i&gt; = &amp;#x2018;z’ then the returned value is &amp;#x2018;a’.&lt;/p&gt;
&lt;p&gt;Does the function &lt;i&gt;NEXT&lt;/i&gt; have an inverse function? If it does, describe this inverse function.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;We can reverse the effect of &lt;i&gt;NEXT&lt;/i&gt; by moving each character back one place in alphabetical order. This time, the special case is &amp;#x2018;a’, which must be moved to &amp;#x2018;z’. So &lt;i&gt;NEXT&lt;/i&gt; does have an inverse function. If we call it &lt;i&gt;BEFORE&lt;/i&gt;, it can be described as below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;BEFORE&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; in &lt;i&gt;Char&lt;/i&gt;) return in &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;c&lt;/i&gt; is a lower-case letter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; If &lt;i&gt;c&lt;/i&gt; lies between &amp;#x2018;b’ and &amp;#x2018;z ’ then the returned value is the letter preceding &lt;i&gt;c&lt;/i&gt; in alphabetical order. If &lt;i&gt;c&lt;/i&gt; = &amp;#x2018;a’ then the returned value is &amp;#x2018;z’.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.4</guid>
    <dc:title>4.3 Character code functions</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Many programming languages provide two functions associated with the character codes (see &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;). We shall call these functions &lt;i&gt;ASC&lt;/i&gt; and &lt;i&gt;CHR. ASC&lt;/i&gt; takes a character as input, and returns the integer giving the ASCII code of the input character. &lt;i&gt;CHR&lt;/i&gt; returns the character whose ASCII code is the input integer. These functions are described below. We have set a precondition on &lt;i&gt;CHR&lt;/i&gt; to conform to our earlier restriction on the set of characters that we will consider in this course.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is the &lt;b&gt;ASCII&lt;/b&gt; code of &lt;i&gt;c&lt;/i&gt;, as given in Table 2.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 32 ≤ &lt;i&gt;n&lt;/i&gt; ≤ 126.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is the character with ASCII code &lt;i&gt;n&lt;/i&gt;, as given in Table 2.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act019"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 18&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Find each of:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;ASC&lt;/i&gt;(‘j’);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;CHR&lt;/i&gt;(43);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(43));&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(‘j’)).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Referring to &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.2#tab003"&gt;Table 2&lt;/a&gt;, &lt;i&gt;ASC&lt;/i&gt;(‘j’) = 106.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;CHR&lt;/i&gt;(43) = ‘+’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(43)) means the result of applying the function &lt;i&gt;ASC&lt;/i&gt; to &lt;i&gt;CHR&lt;/i&gt;(43). So &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(43)) = &lt;i&gt;ASC&lt;/i&gt;(‘+’) = 43.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(‘j’)) = &lt;i&gt;CHR&lt;/i&gt;(106) = ‘j’.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Looking up the ASCII code of a character, and then looking to see the character corresponding to the number you just found, will always take you back to the character you started with. We can express this in a general equation, as &lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt;)) = &lt;i&gt;c&lt;/i&gt;. (This holds for any character &lt;i&gt;c&lt;/i&gt;.)&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;As illustrated in Activity 18, the two functions &lt;i&gt;ASC&lt;/i&gt; and &lt;i&gt;CHR&lt;/i&gt; are closely related. Each reverses the effect of the other. We can express this relationship by writing the two equations below (which hold for every &lt;i&gt;c&lt;/i&gt; in &lt;i&gt;Char&lt;/i&gt; and for every &lt;i&gt;n&lt;/i&gt; in &lt;i&gt;Int&lt;/i&gt; satisfying the condition 32 ≤ &lt;i&gt;n&lt;/i&gt; ≤ 126).&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo010"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;)) = &lt;i&gt;n&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;CHR&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt;)) = &lt;i&gt;c&lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;We say that &lt;i&gt;ASC&lt;/i&gt; and &lt;i&gt;CHR&lt;/i&gt; are &lt;b&gt;inverse functions&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Not every function can be paired up with an inverse function in this way. For example, the function &lt;i&gt;FIRSTCHAR&lt;/i&gt; returns the first character in a string. Now different strings may have the same first character. (“This” and “The” both start with ‘T’, but are different strings.) With input ‘T’, a process attempting to reverse the effect of &lt;i&gt;FIRSTCHAR&lt;/i&gt; would not know whether to return “This” or “The” (or “To”, or “Tom”, etc). The function &lt;i&gt;FIRSTCHAR&lt;/i&gt; has no inverse function.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act020"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 19&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;A simple cipher replaces each lower-case letter with the next one in alphabetical order. So ‘a’ is replaced by ‘b’, ‘b’ by ‘c’,. . . , ‘t’ by ‘u’, and so on. The letter z ‘ ’ is replaced by ‘a’. The function &lt;i&gt;NEXT&lt;/i&gt;, specified below, corresponds to this coding.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;NEXT&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; in &lt;i&gt;Char&lt;/i&gt;) return in &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;c&lt;/i&gt; is a lower-case letter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; If &lt;i&gt;c&lt;/i&gt; lies between ‘a’ and ‘y’ then the returned value is the letter following &lt;i&gt;c&lt;/i&gt; in alphabetical order. If &lt;i&gt;c&lt;/i&gt; = ‘z’ then the returned value is ‘a’.&lt;/p&gt;
&lt;p&gt;Does the function &lt;i&gt;NEXT&lt;/i&gt; have an inverse function? If it does, describe this inverse function.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;We can reverse the effect of &lt;i&gt;NEXT&lt;/i&gt; by moving each character back one place in alphabetical order. This time, the special case is ‘a’, which must be moved to ‘z’. So &lt;i&gt;NEXT&lt;/i&gt; does have an inverse function. If we call it &lt;i&gt;BEFORE&lt;/i&gt;, it can be described as below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;BEFORE&lt;/i&gt;(&lt;i&gt;c&lt;/i&gt; in &lt;i&gt;Char&lt;/i&gt;) return in &lt;i&gt;Char&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;c&lt;/i&gt; is a lower-case letter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; If &lt;i&gt;c&lt;/i&gt; lies between ‘b’ and ‘z ’ then the returned value is the letter preceding &lt;i&gt;c&lt;/i&gt; in alphabetical order. If &lt;i&gt;c&lt;/i&gt; = ‘a’ then the returned value is ‘z’.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>4.4 Functions returning true or false</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.5</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Consider a function, say &lt;i&gt;ISIN&lt;/i&gt; , associated with following process.&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo011"&gt;&lt;blockquote&gt;&lt;p&gt;Given a character and a string, determine whether the character appears in the string.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;This function has two inputs, a character and a string (sequence of characters), so we can take the input set to be &lt;i&gt;Char&lt;/i&gt; &amp;#xD7; &lt;i&gt;SeqOfChar&lt;/i&gt;. But what is the output set? If the character does appear in the string, then the function can return the value &lt;b&gt;true&lt;/b&gt;, and if the character does not appear in the string, then the function can return the value &lt;b&gt;false&lt;/b&gt;. So a suitable output set is &lt;i&gt;Bool&lt;/i&gt;. Then &lt;i&gt;ISIN&lt;/i&gt; has signature &lt;i&gt;Char&lt;/i&gt; &amp;#xD7; &lt;i&gt;SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;Bool&lt;/i&gt;. We can describe the function &lt;i&gt;ISIN&lt;/i&gt; as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ISIN&lt;/i&gt; (&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;, &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;true&lt;/b&gt; if the character &lt;i&gt;c&lt;/i&gt; appears in the sequence &lt;i&gt;s&lt;/i&gt; at least once, and is &lt;b&gt;false&lt;/b&gt; if &lt;i&gt;c&lt;/i&gt; does not appear at all in &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;(If &lt;i&gt;s&lt;/i&gt; is the empty string, then it contains no characters, and &lt;i&gt;ISIN&lt;/i&gt; (&lt;i&gt;c, s&lt;/i&gt;) will be &lt;b&gt;false&lt;/b&gt; whatever the character &lt;i&gt;c&lt;/i&gt; is.)&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act021"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 20&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suggest a description for a function &lt;i&gt;ISEMPTY&lt;/i&gt; corresponding to the following process.&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo012"&gt;&lt;blockquote&gt;&lt;p&gt;Determine whether or not a given sequence is empty.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;The function will input a sequence (which might contain elements from any set, say &lt;i&gt;X&lt;/i&gt;). It can return &lt;b&gt;true&lt;/b&gt; if the sequence is empty, and &lt;b&gt;false&lt;/b&gt; if it is not empty. So we can use the following description of &lt;i&gt;ISEMPTY&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ISEMPTY&lt;/i&gt; (&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;true&lt;/b&gt; if the sequence &lt;i&gt;s&lt;/i&gt; contains no members, and is &lt;b&gt;false&lt;/b&gt; if &lt;i&gt;s&lt;/i&gt; contains one or more members.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.5</guid>
    <dc:title>4.4 Functions returning true or false</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Consider a function, say &lt;i&gt;ISIN&lt;/i&gt; , associated with following process.&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo011"&gt;&lt;blockquote&gt;&lt;p&gt;Given a character and a string, determine whether the character appears in the string.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;p&gt;This function has two inputs, a character and a string (sequence of characters), so we can take the input set to be &lt;i&gt;Char&lt;/i&gt; × &lt;i&gt;SeqOfChar&lt;/i&gt;. But what is the output set? If the character does appear in the string, then the function can return the value &lt;b&gt;true&lt;/b&gt;, and if the character does not appear in the string, then the function can return the value &lt;b&gt;false&lt;/b&gt;. So a suitable output set is &lt;i&gt;Bool&lt;/i&gt;. Then &lt;i&gt;ISIN&lt;/i&gt; has signature &lt;i&gt;Char&lt;/i&gt; × &lt;i&gt;SeqOfChar&lt;/i&gt; → &lt;i&gt;Bool&lt;/i&gt;. We can describe the function &lt;i&gt;ISIN&lt;/i&gt; as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ISIN&lt;/i&gt; (&lt;i&gt;c&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;, &lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfChar&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;true&lt;/b&gt; if the character &lt;i&gt;c&lt;/i&gt; appears in the sequence &lt;i&gt;s&lt;/i&gt; at least once, and is &lt;b&gt;false&lt;/b&gt; if &lt;i&gt;c&lt;/i&gt; does not appear at all in &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;(If &lt;i&gt;s&lt;/i&gt; is the empty string, then it contains no characters, and &lt;i&gt;ISIN&lt;/i&gt; (&lt;i&gt;c, s&lt;/i&gt;) will be &lt;b&gt;false&lt;/b&gt; whatever the character &lt;i&gt;c&lt;/i&gt; is.)&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act021"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 20&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suggest a description for a function &lt;i&gt;ISEMPTY&lt;/i&gt; corresponding to the following process.&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo012"&gt;&lt;blockquote&gt;&lt;p&gt;Determine whether or not a given sequence is empty.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;The function will input a sequence (which might contain elements from any set, say &lt;i&gt;X&lt;/i&gt;). It can return &lt;b&gt;true&lt;/b&gt; if the sequence is empty, and &lt;b&gt;false&lt;/b&gt; if it is not empty. So we can use the following description of &lt;i&gt;ISEMPTY&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;ISEMPTY&lt;/i&gt; (&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;true&lt;/b&gt; if the sequence &lt;i&gt;s&lt;/i&gt; contains no members, and is &lt;b&gt;false&lt;/b&gt; if &lt;i&gt;s&lt;/i&gt; contains one or more members.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Objectives for Section 4</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.6</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: function, signature, domain, semantics, input set, output set, precondition, postcondition.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Suggest appropriate signatures and preconditions for functions corresponding to a variety of processes on numbers, characters and sequences, including those with more than one input and those that return a Boolean value.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;For given inputs, give the value returned by various functions described in this section, in particular: &lt;i&gt;AT&lt;/i&gt;, &lt;i&gt;PUT&lt;/i&gt;, &lt;i&gt;SIZE&lt;/i&gt;, &lt;i&gt;ASC&lt;/i&gt;, &lt;i&gt;CHR&lt;/i&gt;, &lt;i&gt;ADDLAST&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.6</guid>
    <dc:title>Objectives for Section 4</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: function, signature, domain, semantics, input set, output set, precondition, postcondition.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Suggest appropriate signatures and preconditions for functions corresponding to a variety of processes on numbers, characters and sequences, including those with more than one input and those that return a Boolean value.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;For given inputs, give the value returned by various functions described in this section, in particular: &lt;i&gt;AT&lt;/i&gt;, &lt;i&gt;PUT&lt;/i&gt;, &lt;i&gt;SIZE&lt;/i&gt;, &lt;i&gt;ASC&lt;/i&gt;, &lt;i&gt;CHR&lt;/i&gt;, &lt;i&gt;ADDLAST&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Exercises on Section 4</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.7</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq009"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 9&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;For each of the following functions, give the signature and suggest a suitable precondition.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;TOUPPER&lt;/i&gt;, which changes a string, containing only lower-case letters, into the corresponding string consisting of upper-case letters. (So, for example, &lt;i&gt;TOUPPER&lt;/i&gt;(&amp;#x201C;word&amp;#x201D;) = &amp;#x201C;WORD&amp;#x201D;.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;REMOVELAST&lt;/i&gt;, which, given a sequence, deletes its last member.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;LAST&lt;/i&gt;, which returns the last member of a sequence.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This function inputs a string and outputs a string, therefore it has signature &lt;i&gt;TOUPPER : SeqOfChar&lt;/i&gt; &amp;#x2192; &lt;i&gt;SeqOfChar&lt;/i&gt;. It requires a precondition that the input sequence consists entirely of lower-case letters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) The members of the sequence may come from any set, which we will denote by &lt;i&gt;X&lt;/i&gt;. The input is a sequence and the returned value is also a sequence. So the signature is &lt;i&gt;REMOVELAST : SeqOfX&lt;/i&gt; &amp;#x2192; &lt;i&gt;SeqOfX&lt;/i&gt; . The input sequence should contain at least one member (otherwise there is no last member to delete), so we need a precondition that the input sequence is not empty.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) This is similar to (a), except that the returned value is an item from &lt;i&gt;X&lt;/i&gt;, rather than a sequence. The signature is &lt;i&gt;LAST : SeqOfX&lt;/i&gt; &amp;#x2192; &lt;i&gt;X&lt;/i&gt;. We again need the precondition that the input sequence is not empty.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq010"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 10&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that the days of the week are represented by numbers, with Mon-day represented by 1, Tuesday represented by 2, and so on, with Sunday represented by 7. Describe a function &lt;i&gt;TOMORROW2&lt;/i&gt;, giving the next day with &lt;i&gt;Days&lt;/i&gt; represented in this way.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;You may have given this description.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;TOMORROW2&lt;/i&gt;(&lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;d&lt;/i&gt; is in the set {1,2,3,4,5,6,7}.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;t&lt;/i&gt;, where:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 1 then &lt;i&gt;t&lt;/i&gt; = 2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 2 then &lt;i&gt;t&lt;/i&gt; = 3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 3 then &lt;i&gt;t&lt;/i&gt; = 4&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 4 then &lt;i&gt;t&lt;/i&gt; = 5&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 5 then &lt;i&gt;t&lt;/i&gt; = 6&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 6 then &lt;i&gt;t&lt;/i&gt; = 7&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 7 then &lt;i&gt;t&lt;/i&gt; = 1.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Or you may have given a shorter description, such as:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;TOMORROW2&lt;/i&gt;(&lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 1 &amp;#x2264; &lt;i&gt;d&lt;/i&gt; &amp;#x2264; 7.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;t&lt;/i&gt;, where:&lt;/p&gt;
&lt;p&gt;&lt;i&gt;t&lt;/i&gt; = &lt;i&gt;d&lt;/i&gt; + 1 if 1 &lt;i&gt;= d =&lt;/i&gt; 6;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;t&lt;/i&gt; = 1 if &lt;i&gt;d&lt;/i&gt; = 7.&lt;/p&gt;
&lt;p&gt;Either of these answers is fine.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq011"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 11&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) With &lt;i&gt;s&lt;/i&gt; = &amp;#x201C;abcd&amp;#x201D;, evaluate each of:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;AT&lt;/i&gt;(1&lt;i&gt;, s&lt;/i&gt;);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) PUT(2, s, AT(1, s)).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) For a general sequence &lt;i&gt;s&lt;/i&gt;, describe how the sequence &lt;i&gt;PUT&lt;/i&gt;(2&lt;i&gt;, s, AT&lt;/i&gt;(1&lt;i&gt;, s&lt;/i&gt;)) is obtained from &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The functions &lt;i&gt;AT&lt;/i&gt; and &lt;i&gt;PUT&lt;/i&gt; were described in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.2#act017"&gt;Activity 16&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)(i) With &lt;i&gt;s&lt;/i&gt; = &amp;#x201C;abcd&amp;#x201D;, &lt;i&gt;AT&lt;/i&gt;(1,&lt;i&gt;s&lt;/i&gt;) = &amp;#x2018;a’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) Then &lt;i&gt;PUT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;,&lt;i&gt;AT&lt;/i&gt;(1,&lt;i&gt;s&lt;/i&gt;)) = &lt;i&gt;PUT&lt;/i&gt;(2,&amp;#x201C;abcd&amp;#x201D;,&amp;#x2018;a’) = &amp;#x201C;aacd&amp;#x201D;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) In general, &lt;i&gt;PUT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;,&lt;i&gt;AT&lt;/i&gt;(1,&lt;i&gt;s&lt;/i&gt;)) is formed by replacing the second member of the sequence &lt;i&gt;s&lt;/i&gt; with a copy of the first member of &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.7</guid>
    <dc:title>Exercises on Section 4</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq009"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 9&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;For each of the following functions, give the signature and suggest a suitable precondition.&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;TOUPPER&lt;/i&gt;, which changes a string, containing only lower-case letters, into the corresponding string consisting of upper-case letters. (So, for example, &lt;i&gt;TOUPPER&lt;/i&gt;(“word”) = “WORD”.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;REMOVELAST&lt;/i&gt;, which, given a sequence, deletes its last member.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;LAST&lt;/i&gt;, which returns the last member of a sequence.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) This function inputs a string and outputs a string, therefore it has signature &lt;i&gt;TOUPPER : SeqOfChar&lt;/i&gt; → &lt;i&gt;SeqOfChar&lt;/i&gt;. It requires a precondition that the input sequence consists entirely of lower-case letters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) The members of the sequence may come from any set, which we will denote by &lt;i&gt;X&lt;/i&gt;. The input is a sequence and the returned value is also a sequence. So the signature is &lt;i&gt;REMOVELAST : SeqOfX&lt;/i&gt; → &lt;i&gt;SeqOfX&lt;/i&gt; . The input sequence should contain at least one member (otherwise there is no last member to delete), so we need a precondition that the input sequence is not empty.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) This is similar to (a), except that the returned value is an item from &lt;i&gt;X&lt;/i&gt;, rather than a sequence. The signature is &lt;i&gt;LAST : SeqOfX&lt;/i&gt; → &lt;i&gt;X&lt;/i&gt;. We again need the precondition that the input sequence is not empty.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq010"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 10&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Suppose that the days of the week are represented by numbers, with Mon-day represented by 1, Tuesday represented by 2, and so on, with Sunday represented by 7. Describe a function &lt;i&gt;TOMORROW2&lt;/i&gt;, giving the next day with &lt;i&gt;Days&lt;/i&gt; represented in this way.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;You may have given this description.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;TOMORROW2&lt;/i&gt;(&lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &lt;i&gt;d&lt;/i&gt; is in the set {1,2,3,4,5,6,7}.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;t&lt;/i&gt;, where:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 1 then &lt;i&gt;t&lt;/i&gt; = 2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 2 then &lt;i&gt;t&lt;/i&gt; = 3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 3 then &lt;i&gt;t&lt;/i&gt; = 4&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 4 then &lt;i&gt;t&lt;/i&gt; = 5&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 5 then &lt;i&gt;t&lt;/i&gt; = 6&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 6 then &lt;i&gt;t&lt;/i&gt; = 7&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;d&lt;/i&gt; = 7 then &lt;i&gt;t&lt;/i&gt; = 1.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Or you may have given a shorter description, such as:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;TOMORROW2&lt;/i&gt;(&lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; 1 ≤ &lt;i&gt;d&lt;/i&gt; ≤ 7.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;t&lt;/i&gt;, where:&lt;/p&gt;
&lt;p&gt;&lt;i&gt;t&lt;/i&gt; = &lt;i&gt;d&lt;/i&gt; + 1 if 1 &lt;i&gt;= d =&lt;/i&gt; 6;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;t&lt;/i&gt; = 1 if &lt;i&gt;d&lt;/i&gt; = 7.&lt;/p&gt;
&lt;p&gt;Either of these answers is fine.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq011"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 11&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) With &lt;i&gt;s&lt;/i&gt; = “abcd”, evaluate each of:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;AT&lt;/i&gt;(1&lt;i&gt;, s&lt;/i&gt;);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) PUT(2, s, AT(1, s)).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) For a general sequence &lt;i&gt;s&lt;/i&gt;, describe how the sequence &lt;i&gt;PUT&lt;/i&gt;(2&lt;i&gt;, s, AT&lt;/i&gt;(1&lt;i&gt;, s&lt;/i&gt;)) is obtained from &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The functions &lt;i&gt;AT&lt;/i&gt; and &lt;i&gt;PUT&lt;/i&gt; were described in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.2#act017"&gt;Activity 16&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a)(i) With &lt;i&gt;s&lt;/i&gt; = “abcd”, &lt;i&gt;AT&lt;/i&gt;(1,&lt;i&gt;s&lt;/i&gt;) = ‘a’.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) Then &lt;i&gt;PUT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;,&lt;i&gt;AT&lt;/i&gt;(1,&lt;i&gt;s&lt;/i&gt;)) = &lt;i&gt;PUT&lt;/i&gt;(2,“abcd”,‘a’) = “aacd”.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) In general, &lt;i&gt;PUT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;,&lt;i&gt;AT&lt;/i&gt;(1,&lt;i&gt;s&lt;/i&gt;)) is formed by replacing the second member of the sequence &lt;i&gt;s&lt;/i&gt; with a copy of the first member of &lt;i&gt;s&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Seeing processes as functions</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.1</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Addition of numbers is a process that one would expect a computer to be able to perform. Now we write the result of adding the numbers 5 and 2 as 5 + 2, for example. The symbol +, which represents the process of addition, appears between the two numbers being added. This is known as &lt;b&gt;infix&lt;/b&gt; notation. Infix notation may be used for processes that combine two data items of the same type. Addition, subtraction and multiplication of numbers are familiar examples. We also use infix notation when writing a comparison of the size of two numbers, such as 5 &amp;lt; 9.&lt;/p&gt;&lt;p&gt;In this section, we shall show that a process such as addition of numbers is a function. Perhaps more surprisingly, a process such as &amp;lt; can also be seen as a function. This perception is a necessary preliminary to seeing how such a process can be implemented by a computer.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.1</guid>
    <dc:title>Seeing processes as functions</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Addition of numbers is a process that one would expect a computer to be able to perform. Now we write the result of adding the numbers 5 and 2 as 5 + 2, for example. The symbol +, which represents the process of addition, appears between the two numbers being added. This is known as &lt;b&gt;infix&lt;/b&gt; notation. Infix notation may be used for processes that combine two data items of the same type. Addition, subtraction and multiplication of numbers are familiar examples. We also use infix notation when writing a comparison of the size of two numbers, such as 5 &lt; 9.&lt;/p&gt;&lt;p&gt;In this section, we shall show that a process such as addition of numbers is a function. Perhaps more surprisingly, a process such as &lt; can also be seen as a function. This perception is a necessary preliminary to seeing how such a process can be implemented by a computer.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>5.1 Arithmetic operations</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.2</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Processes such as addition of numbers are called &lt;b&gt;binary operations&lt;/b&gt;. (The word &amp;#x201C;binary&amp;#x201D; here reflects the fact that a binary operation combines &lt;i&gt;two&lt;/i&gt; data items.) A binary operation is a particular form of function. To see this, we need to recognise the appropriate signature.&lt;/p&gt;&lt;p&gt;If you add two integers, then the resulting value is also an integer. So addition of integers takes two integers and returns an integer value. Thus adding integers is a function with signature &lt;i&gt;Int &amp;#xD7; Int&lt;/i&gt; &amp;#x2192; &lt;i&gt;Int&lt;/i&gt;. We can add any two integers, so addition is a total function (that is, has precondition &lt;b&gt;true&lt;/b&gt;). We can describe a function, +, corresponding to addition of integers, as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt; on &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is the result of adding &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Where we use infix notation to write the value returned by a function, we will set out the signature line in the function description in a slightly different way from that used in Section 4, as illustrated above.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act022"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 21&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Describe a function, &amp;#x2212;, corresponding to integer subtraction written using infix notation.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Subtraction again combines two integers to produce an integer value. We can subtract any two integers, so this is again a total function.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; &amp;#x2212; &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is the result of subtracting &lt;i&gt;y&lt;/i&gt; from &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;We saw in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.1#act004"&gt;Activity 3&lt;/a&gt; that division of one integer by another does not necessarily result in an integer. For example, 2 &amp;#xF7; 4 = 0.5 and 0.5 is not an integer. This means that we cannot define a function for what we might call &amp;#x201C;everyday division&amp;#x201D; that returns an integer value for integer inputs.&lt;/p&gt;&lt;p&gt;Sometimes, we need a form of division of integers that does yield an integer result. For example, suppose our supermarket features a special &amp;#x2018;buy 4, get 1 free’ order on bottles of wine. If a customer comes to the till with nine bottles of wine, then the till needs to calculate how many free bottles they should receive. Now nine bottles of wine contain two lots of four bottles (with one bottle left over). So the customer receives two free bottles of wine. This is an example of &lt;b&gt;integer division&lt;/b&gt;. Integer division of 9 by 4 gives the result 2. (Hopefully, the cashier will point out to the customer with 9 bottles of wine that they are entitled to another free bottle!)&lt;/p&gt;&lt;p&gt;As another example, suppose that we want to perform integer division of 29 by 8. Now 3 &amp;#xD7; 8 = 24, while 4 &amp;#xD7; 8 = 32. When we perform integer division of 29 by 8 we obtain the result 3. Since 29 &amp;#x2212; 3 &amp;#xD7; 8 = 5, dividing 29 by 8 leaves a &lt;b&gt;remainder&lt;/b&gt; of 5. Notice that the remainder, 5, satisfies the condition that 0 &amp;#x2264; 5 &amp;lt; 8.&lt;/p&gt;&lt;p&gt;Integer division has two integers as input. It is a binary operation on &lt;i&gt;Int&lt;/i&gt;, so we could use infix notation to write integer division. Now, many programming languages use / as an infix notation for both integer division and for real number division. In such cases, it is vital to appreciate that these are &lt;i&gt;different&lt;/i&gt; processes, whose precise behaviour depends upon the type of the values supplied. To emphasise that integer division is not the familiar process of &amp;#x201C;everyday division&amp;#x201D;, we will write it as &lt;i&gt;DIV&lt;/i&gt;, and use function rather than infix notation to give its values. For example, &lt;i&gt;DIV&lt;/i&gt; (29, 8) = 3.&lt;/p&gt;&lt;p&gt;How can we describe integer division in general? To do this, some vocabulary is useful. In writing &lt;i&gt;DIV&lt;/i&gt; (29, 8) = 3, the number 8 is called the &lt;b&gt;divisor&lt;/b&gt;, and 3 is called the &lt;b&gt;quotient&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;We can generalise the equation 29 = 3 &amp;#xD7; 8 + 5 to give &lt;i&gt;n&lt;/i&gt; = &lt;i&gt;q &amp;#xD7; d&lt;/i&gt; + &lt;i&gt;r&lt;/i&gt; (where &lt;i&gt;d&lt;/i&gt; is the divisor, &lt;i&gt;q&lt;/i&gt; is the quotient and &lt;i&gt;r&lt;/i&gt; the remainder). The remainder must not be too large. In this example, the remainder 5 is less than 8. In general, the remainder &lt;i&gt;r&lt;/i&gt; must be less than the divisor, &lt;i&gt;d&lt;/i&gt;. Also, the remainder &lt;i&gt;r&lt;/i&gt; is not negative. We can express these conditions on &lt;i&gt;r&lt;/i&gt; algebraically as 0 &amp;#x2264; &lt;i&gt;r&lt;/i&gt; &amp;lt; &lt;i&gt;d&lt;/i&gt;. So, in general, the quotient, &lt;i&gt;q&lt;/i&gt;, is the largest integer by which we can multiply the divisor, &lt;i&gt;d&lt;/i&gt;, while leaving a remainder that is not negative. If we subtract (&lt;i&gt;q &amp;#xD7; d&lt;/i&gt;) from &lt;i&gt;n&lt;/i&gt;, the resulting remainder needs to be non-negative and less than &lt;i&gt;d&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Integer division has two integers as inputs and returns an integer. So the integer division function has signature &lt;i&gt;DIV : Int &amp;#xD7; Int&lt;/i&gt; &amp;#x2192; &lt;i&gt;Int&lt;/i&gt;. Since we write &lt;i&gt;DIV&lt;/i&gt; using function notation, we can describe this function as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &amp;#xA0; &lt;i&gt;d&lt;/i&gt; &amp;gt; 0.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value &lt;i&gt;q&lt;/i&gt; is the result of integer division of &lt;i&gt;n&lt;/i&gt; by &lt;i&gt;d&lt;/i&gt;. It satisfies the condition that if &lt;i&gt;r&lt;/i&gt; = &lt;i&gt;n&lt;/i&gt; &amp;#x2212; (&lt;i&gt;q&lt;/i&gt; &amp;#xD7; &lt;i&gt;d&lt;/i&gt;), then we have 0 &amp;#x2264; &lt;i&gt;r&lt;/i&gt; &amp;lt; &lt;i&gt;d&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Notice that we only consider the case where the divisor, &lt;i&gt;d&lt;/i&gt;, is strictly greater than 0. There is no restriction on the number &lt;i&gt;n&lt;/i&gt; that is being divided, though. The examples we have considered so far have &lt;i&gt;n&lt;/i&gt; positive.&lt;/p&gt;&lt;p&gt;What do these semantics give if &lt;i&gt;n&lt;/i&gt; &amp;lt; 0? As an example, consider &lt;i&gt;n&lt;/i&gt; = &amp;#x2212;29 and &lt;i&gt;d&lt;/i&gt; = 8. We have &amp;#x2212;29 = &amp;#x2212;4 &amp;#xD7; 8 + 3 and the semantics give &lt;i&gt;DIV&lt;/i&gt; (&amp;#x2212;29, 8) = &amp;#x2212;4. (Note that the remainder, &lt;i&gt;r&lt;/i&gt; = 3, satisfies the condition 0 &amp;#x2264; &lt;i&gt;r&lt;/i&gt; &amp;lt; &lt;i&gt;d&lt;/i&gt;, which is 0 &amp;#x2264; &lt;i&gt;r&lt;/i&gt; &amp;lt; 8 in this case.)&lt;/p&gt;&lt;p&gt;If &lt;i&gt;n&lt;/i&gt; = 0, we have &lt;i&gt;DIV&lt;/i&gt; (0, &lt;i&gt;d&lt;/i&gt;) = 0 for any &lt;i&gt;d&lt;/i&gt; that satisfies the precondition.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act023"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 22&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give the following values:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;DIV&lt;/i&gt; (27,4).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;DIV&lt;/i&gt; (32,17).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;DIV&lt;/i&gt; (&amp;#x2212;27, 4).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;DIV&lt;/i&gt; (0,6).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) &lt;i&gt;DIV&lt;/i&gt; (3,0).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;DIV&lt;/i&gt; (27,4) = 6, since 27 = 6 &amp;#xD7; 4 + 3, where 0 &amp;#x2264; 3 &amp;lt; 4.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;DIV&lt;/i&gt; (32,17) = 1, since 32 = 1 &amp;#xD7; 17 + 15, where 0 &amp;#x2264; 15 &amp;lt; 17.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;DIV&lt;/i&gt; (&amp;#x2212;27, 4) = &amp;#x2212;7, since &amp;#x2212;27 = &amp;#x2212;7 &amp;#xD7; 4 + 1, where 0 &amp;#x2264; 1 &amp;lt; 4.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;DIV&lt;/i&gt; (0,6) = 0.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) This is undefined (because of the precondition on &lt;i&gt;DIV&lt;/i&gt; ).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;A second process associated with integer division returns the remainder rather than the quotient. This is again a binary operation. We will write this operation as &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n, d&lt;/i&gt;). This operation can be described as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &amp;#xA0; &lt;i&gt;d&lt;/i&gt; &amp;gt; 0.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value &lt;i&gt;r&lt;/i&gt; is the remainder after integer division of &lt;i&gt;n&lt;/i&gt; by &lt;i&gt;d&lt;/i&gt;. It satisfies the conditions 0 &amp;#x2264; &lt;i&gt;r&lt;/i&gt; &amp;lt; &lt;i&gt;d&lt;/i&gt; and &lt;i&gt;r&lt;/i&gt; = &lt;i&gt;n -&lt;/i&gt; (&lt;i&gt;q&lt;/i&gt; &amp;#xD7; &lt;i&gt;d&lt;/i&gt;), where &lt;i&gt;q&lt;/i&gt; is an integer. The remainder &lt;i&gt;MOD(n, d)&lt;/i&gt; is sometimes called the value of &lt;i&gt;n&lt;/i&gt; &lt;b&gt;modulo&lt;/b&gt; &lt;i&gt;d&lt;/i&gt;, or more briefly &lt;i&gt;n&lt;/i&gt; mod &lt;i&gt;d&lt;/i&gt;. Many programming languages use the infix notation &lt;i&gt;n&lt;/i&gt; % &lt;i&gt;d&lt;/i&gt; for this operation.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act024"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 23&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give the following values:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;MOD&lt;/i&gt;(67, 10).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;MOD&lt;/i&gt;(55, 5).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;MOD&lt;/i&gt;(&amp;#x2212;27, 4).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;MOD&lt;/i&gt;(67, 10) = 7 (since 67 = 6 &amp;#xD7; 10 + 7; the remainder on division of 67 by 10 is 7).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;MOD&lt;/i&gt;(55, 5) = 0 (since 55 = 11 &amp;#xD7; 5 + 0).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;MOD&lt;/i&gt;(&amp;#x2212;27, 4) = 1 because, as noted in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.2#act023"&gt;Activity 22&lt;/a&gt;(c), we have &amp;#x2212;27 = &amp;#x2212;7 &amp;#xD7; 4 + 1.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act025"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 24&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Suppose that you buy 335 grams of walnuts at 299 pence per kg, and the price of this purchase is expressed as a whole number of pence by ignoring any fraction. What is the cost of this purchase?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Now consider a general purchase of this form, of &lt;i&gt;weight&lt;/i&gt; grams of a product costing &lt;i&gt;price&lt;/i&gt; pence per kilogram. Using the function &lt;i&gt;DIV&lt;/i&gt; , give a formula for the cost of such a purchase.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) 335 grams is 0.335 kilograms, so this purchase should cost 0.335 &amp;#xD7; 299 = 100.464 pence, which will be rounded to 100 pence. (Reassuringly, this is the same as the cost given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt;.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) In general we multiply &lt;i&gt;weight&lt;/i&gt; and &lt;i&gt;price&lt;/i&gt;, and divide the result by 1000, ignoring any fractional part of the result. So the required value is given by the expression &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;weight &amp;#xD7; price&lt;/i&gt;,1000).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.2</guid>
    <dc:title>5.1 Arithmetic operations</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Processes such as addition of numbers are called &lt;b&gt;binary operations&lt;/b&gt;. (The word “binary” here reflects the fact that a binary operation combines &lt;i&gt;two&lt;/i&gt; data items.) A binary operation is a particular form of function. To see this, we need to recognise the appropriate signature.&lt;/p&gt;&lt;p&gt;If you add two integers, then the resulting value is also an integer. So addition of integers takes two integers and returns an integer value. Thus adding integers is a function with signature &lt;i&gt;Int × Int&lt;/i&gt; → &lt;i&gt;Int&lt;/i&gt;. We can add any two integers, so addition is a total function (that is, has precondition &lt;b&gt;true&lt;/b&gt;). We can describe a function, +, corresponding to addition of integers, as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt; on &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is the result of adding &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Where we use infix notation to write the value returned by a function, we will set out the signature line in the function description in a slightly different way from that used in Section 4, as illustrated above.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act022"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 21&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Describe a function, −, corresponding to integer subtraction written using infix notation.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;Subtraction again combines two integers to produce an integer value. We can subtract any two integers, so this is again a total function.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; − &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is the result of subtracting &lt;i&gt;y&lt;/i&gt; from &lt;i&gt;x&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;We saw in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-3.1#act004"&gt;Activity 3&lt;/a&gt; that division of one integer by another does not necessarily result in an integer. For example, 2 ÷ 4 = 0.5 and 0.5 is not an integer. This means that we cannot define a function for what we might call “everyday division” that returns an integer value for integer inputs.&lt;/p&gt;&lt;p&gt;Sometimes, we need a form of division of integers that does yield an integer result. For example, suppose our supermarket features a special ‘buy 4, get 1 free’ order on bottles of wine. If a customer comes to the till with nine bottles of wine, then the till needs to calculate how many free bottles they should receive. Now nine bottles of wine contain two lots of four bottles (with one bottle left over). So the customer receives two free bottles of wine. This is an example of &lt;b&gt;integer division&lt;/b&gt;. Integer division of 9 by 4 gives the result 2. (Hopefully, the cashier will point out to the customer with 9 bottles of wine that they are entitled to another free bottle!)&lt;/p&gt;&lt;p&gt;As another example, suppose that we want to perform integer division of 29 by 8. Now 3 × 8 = 24, while 4 × 8 = 32. When we perform integer division of 29 by 8 we obtain the result 3. Since 29 − 3 × 8 = 5, dividing 29 by 8 leaves a &lt;b&gt;remainder&lt;/b&gt; of 5. Notice that the remainder, 5, satisfies the condition that 0 ≤ 5 &lt; 8.&lt;/p&gt;&lt;p&gt;Integer division has two integers as input. It is a binary operation on &lt;i&gt;Int&lt;/i&gt;, so we could use infix notation to write integer division. Now, many programming languages use / as an infix notation for both integer division and for real number division. In such cases, it is vital to appreciate that these are &lt;i&gt;different&lt;/i&gt; processes, whose precise behaviour depends upon the type of the values supplied. To emphasise that integer division is not the familiar process of “everyday division”, we will write it as &lt;i&gt;DIV&lt;/i&gt;, and use function rather than infix notation to give its values. For example, &lt;i&gt;DIV&lt;/i&gt; (29, 8) = 3.&lt;/p&gt;&lt;p&gt;How can we describe integer division in general? To do this, some vocabulary is useful. In writing &lt;i&gt;DIV&lt;/i&gt; (29, 8) = 3, the number 8 is called the &lt;b&gt;divisor&lt;/b&gt;, and 3 is called the &lt;b&gt;quotient&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;We can generalise the equation 29 = 3 × 8 + 5 to give &lt;i&gt;n&lt;/i&gt; = &lt;i&gt;q × d&lt;/i&gt; + &lt;i&gt;r&lt;/i&gt; (where &lt;i&gt;d&lt;/i&gt; is the divisor, &lt;i&gt;q&lt;/i&gt; is the quotient and &lt;i&gt;r&lt;/i&gt; the remainder). The remainder must not be too large. In this example, the remainder 5 is less than 8. In general, the remainder &lt;i&gt;r&lt;/i&gt; must be less than the divisor, &lt;i&gt;d&lt;/i&gt;. Also, the remainder &lt;i&gt;r&lt;/i&gt; is not negative. We can express these conditions on &lt;i&gt;r&lt;/i&gt; algebraically as 0 ≤ &lt;i&gt;r&lt;/i&gt; &lt; &lt;i&gt;d&lt;/i&gt;. So, in general, the quotient, &lt;i&gt;q&lt;/i&gt;, is the largest integer by which we can multiply the divisor, &lt;i&gt;d&lt;/i&gt;, while leaving a remainder that is not negative. If we subtract (&lt;i&gt;q × d&lt;/i&gt;) from &lt;i&gt;n&lt;/i&gt;, the resulting remainder needs to be non-negative and less than &lt;i&gt;d&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Integer division has two integers as inputs and returns an integer. So the integer division function has signature &lt;i&gt;DIV : Int × Int&lt;/i&gt; → &lt;i&gt;Int&lt;/i&gt;. Since we write &lt;i&gt;DIV&lt;/i&gt; using function notation, we can describe this function as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt;   &lt;i&gt;d&lt;/i&gt; &gt; 0.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value &lt;i&gt;q&lt;/i&gt; is the result of integer division of &lt;i&gt;n&lt;/i&gt; by &lt;i&gt;d&lt;/i&gt;. It satisfies the condition that if &lt;i&gt;r&lt;/i&gt; = &lt;i&gt;n&lt;/i&gt; − (&lt;i&gt;q&lt;/i&gt; × &lt;i&gt;d&lt;/i&gt;), then we have 0 ≤ &lt;i&gt;r&lt;/i&gt; &lt; &lt;i&gt;d&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Notice that we only consider the case where the divisor, &lt;i&gt;d&lt;/i&gt;, is strictly greater than 0. There is no restriction on the number &lt;i&gt;n&lt;/i&gt; that is being divided, though. The examples we have considered so far have &lt;i&gt;n&lt;/i&gt; positive.&lt;/p&gt;&lt;p&gt;What do these semantics give if &lt;i&gt;n&lt;/i&gt; &lt; 0? As an example, consider &lt;i&gt;n&lt;/i&gt; = −29 and &lt;i&gt;d&lt;/i&gt; = 8. We have −29 = −4 × 8 + 3 and the semantics give &lt;i&gt;DIV&lt;/i&gt; (−29, 8) = −4. (Note that the remainder, &lt;i&gt;r&lt;/i&gt; = 3, satisfies the condition 0 ≤ &lt;i&gt;r&lt;/i&gt; &lt; &lt;i&gt;d&lt;/i&gt;, which is 0 ≤ &lt;i&gt;r&lt;/i&gt; &lt; 8 in this case.)&lt;/p&gt;&lt;p&gt;If &lt;i&gt;n&lt;/i&gt; = 0, we have &lt;i&gt;DIV&lt;/i&gt; (0, &lt;i&gt;d&lt;/i&gt;) = 0 for any &lt;i&gt;d&lt;/i&gt; that satisfies the precondition.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act023"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 22&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give the following values:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;DIV&lt;/i&gt; (27,4).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;DIV&lt;/i&gt; (32,17).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;DIV&lt;/i&gt; (−27, 4).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;DIV&lt;/i&gt; (0,6).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) &lt;i&gt;DIV&lt;/i&gt; (3,0).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;DIV&lt;/i&gt; (27,4) = 6, since 27 = 6 × 4 + 3, where 0 ≤ 3 &lt; 4.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;DIV&lt;/i&gt; (32,17) = 1, since 32 = 1 × 17 + 15, where 0 ≤ 15 &lt; 17.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;DIV&lt;/i&gt; (−27, 4) = −7, since −27 = −7 × 4 + 1, where 0 ≤ 1 &lt; 4.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(d) &lt;i&gt;DIV&lt;/i&gt; (0,6) = 0.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(e) This is undefined (because of the precondition on &lt;i&gt;DIV&lt;/i&gt; ).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;A second process associated with integer division returns the remainder rather than the quotient. This is again a binary operation. We will write this operation as &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n, d&lt;/i&gt;). This operation can be described as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;, &lt;i&gt;d&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre&lt;/b&gt;   &lt;i&gt;d&lt;/i&gt; &gt; 0.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value &lt;i&gt;r&lt;/i&gt; is the remainder after integer division of &lt;i&gt;n&lt;/i&gt; by &lt;i&gt;d&lt;/i&gt;. It satisfies the conditions 0 ≤ &lt;i&gt;r&lt;/i&gt; &lt; &lt;i&gt;d&lt;/i&gt; and &lt;i&gt;r&lt;/i&gt; = &lt;i&gt;n -&lt;/i&gt; (&lt;i&gt;q&lt;/i&gt; × &lt;i&gt;d&lt;/i&gt;), where &lt;i&gt;q&lt;/i&gt; is an integer. The remainder &lt;i&gt;MOD(n, d)&lt;/i&gt; is sometimes called the value of &lt;i&gt;n&lt;/i&gt; &lt;b&gt;modulo&lt;/b&gt; &lt;i&gt;d&lt;/i&gt;, or more briefly &lt;i&gt;n&lt;/i&gt; mod &lt;i&gt;d&lt;/i&gt;. Many programming languages use the infix notation &lt;i&gt;n&lt;/i&gt; % &lt;i&gt;d&lt;/i&gt; for this operation.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act024"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 23&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give the following values:&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;MOD&lt;/i&gt;(67, 10).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;MOD&lt;/i&gt;(55, 5).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;MOD&lt;/i&gt;(−27, 4).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) &lt;i&gt;MOD&lt;/i&gt;(67, 10) = 7 (since 67 = 6 × 10 + 7; the remainder on division of 67 by 10 is 7).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) &lt;i&gt;MOD&lt;/i&gt;(55, 5) = 0 (since 55 = 11 × 5 + 0).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;MOD&lt;/i&gt;(−27, 4) = 1 because, as noted in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.2#act023"&gt;Activity 22&lt;/a&gt;(c), we have −27 = −7 × 4 + 1.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act025"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 24&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Suppose that you buy 335 grams of walnuts at 299 pence per kg, and the price of this purchase is expressed as a whole number of pence by ignoring any fraction. What is the cost of this purchase?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Now consider a general purchase of this form, of &lt;i&gt;weight&lt;/i&gt; grams of a product costing &lt;i&gt;price&lt;/i&gt; pence per kilogram. Using the function &lt;i&gt;DIV&lt;/i&gt; , give a formula for the cost of such a purchase.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) 335 grams is 0.335 kilograms, so this purchase should cost 0.335 × 299 = 100.464 pence, which will be rounded to 100 pence. (Reassuringly, this is the same as the cost given in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-2.1#fig002"&gt;Figure 2&lt;/a&gt;.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) In general we multiply &lt;i&gt;weight&lt;/i&gt; and &lt;i&gt;price&lt;/i&gt;, and divide the result by 1000, ignoring any fractional part of the result. So the required value is given by the expression &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;weight × price&lt;/i&gt;,1000).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>5.2 Operations on Boolean values</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.3</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;The idea of a binary operation, and the use of infix notation, is not confined to numbers. Infix notation may be used for any process with two inputs from the same set. We look now at two binary operations on Boolean values that are often used.&lt;/p&gt;&lt;p&gt;The first of these takes two Boolean values, and returns &lt;b&gt;true&lt;/b&gt; if &lt;i&gt;both&lt;/i&gt; of the input values are &lt;b&gt;true&lt;/b&gt; and returns &lt;b&gt;false&lt;/b&gt; otherwise. It is a binary operation, and we shall write it using the infix notation &amp;#x2227;, where the symbol &amp;#x2227; can be read as &amp;#x201C;and&amp;#x201D;. So &lt;i&gt;a&lt;/i&gt; &amp;#x2227; &lt;i&gt;b&lt;/i&gt; is &lt;b&gt;true&lt;/b&gt; only when &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; are both &lt;b&gt;true&lt;/b&gt;. We can describe the function corresponding to this operation as below (The operation &amp;#x2227; is also known as &lt;b&gt;conjunction&lt;/b&gt;).&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;a&lt;/i&gt; &amp;#x2227; &lt;i&gt;b&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;true&lt;/b&gt; if both &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;, and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;Alternatively, we could give the semantics of &amp;#x2227; by listing the returned value in each of four cases, giving the four possible combinations of input values. Using this approach, we could express the postcondition as follows.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;c&lt;/i&gt;, where&lt;/p&gt;&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A second binary operation on Boolean values returns &lt;b&gt;true&lt;/b&gt; if either (or both) of the two Boolean values is &lt;b&gt;true&lt;/b&gt;. We write this operation using the infix symbol &amp;#x2228; , where &amp;#x2227; can be read as &amp;#x201C;or&amp;#x201D;. The corresponding function is described below. The operation &amp;#x2228; is also known as &lt;b&gt;disjunction&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;a&lt;/i&gt; &amp;#x2228; &lt;i&gt;b&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;false&lt;/b&gt; if both &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;, and is &lt;b&gt;true&lt;/b&gt; otherwise.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act026"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 25&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give the semantics of &amp;#x2228; by listing the returned value in each of four cases, giving the four possible combinations of input values.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;We can express the postcondition in the description above as follows.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;c&lt;/i&gt;, where&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Another useful process on Boolean values inputs a single Boolean value, and returns the reverse of that value. This process, called &lt;b&gt;negation&lt;/b&gt;, is not a binary operation, since it has one input only. We call this function &lt;i&gt;NOT&lt;/i&gt;, and we have&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo013"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;NOT&lt;/i&gt;(&lt;b&gt;false&lt;/b&gt;) = &lt;b&gt;true&lt;/b&gt;, and &lt;i&gt;NOT&lt;/i&gt;(&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act027"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 26&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give a full description of the function &lt;i&gt;NOT&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) If &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;, evaluate each of:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;a&lt;/i&gt; &amp;#x2228; &lt;i&gt;b&lt;/i&gt;;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;a&lt;/i&gt; &amp;#x2228; &lt;i&gt;b&lt;/i&gt;);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;a&lt;/i&gt; &amp;#x2227; (&lt;i&gt;a&lt;/i&gt; &amp;#x2228; &lt;i&gt;b&lt;/i&gt;).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;(a) A description is given below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;a&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;false&lt;/b&gt; if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and is &lt;b&gt;true&lt;/b&gt; if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;(b) (i) Substituting for &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt;, we have &lt;b&gt;true&lt;/b&gt; &amp;#x2228; &lt;b&gt;false&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;(ii) We should evaluate the term in brackets first: &lt;b&gt;true&lt;/b&gt; &amp;#x2228; &lt;b&gt;false&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;. Then &lt;i&gt;NOT&lt;/i&gt;(&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;. So &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;a&lt;/i&gt; &amp;#x2228; &lt;i&gt;b&lt;/i&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;(iii) Again, evaluate the term in brackets first: (&lt;b&gt;true&lt;/b&gt; &amp;#x2228; &lt;b&gt;false&lt;/b&gt;) = &lt;b&gt;true&lt;/b&gt;. Then the given expression becomes &lt;b&gt;true&lt;/b&gt; &amp;#x2227; &lt;b&gt;true&lt;/b&gt; which evaluates to &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.3</guid>
    <dc:title>5.2 Operations on Boolean values</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;The idea of a binary operation, and the use of infix notation, is not confined to numbers. Infix notation may be used for any process with two inputs from the same set. We look now at two binary operations on Boolean values that are often used.&lt;/p&gt;&lt;p&gt;The first of these takes two Boolean values, and returns &lt;b&gt;true&lt;/b&gt; if &lt;i&gt;both&lt;/i&gt; of the input values are &lt;b&gt;true&lt;/b&gt; and returns &lt;b&gt;false&lt;/b&gt; otherwise. It is a binary operation, and we shall write it using the infix notation ∧, where the symbol ∧ can be read as “and”. So &lt;i&gt;a&lt;/i&gt; ∧ &lt;i&gt;b&lt;/i&gt; is &lt;b&gt;true&lt;/b&gt; only when &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt; are both &lt;b&gt;true&lt;/b&gt;. We can describe the function corresponding to this operation as below (The operation ∧ is also known as &lt;b&gt;conjunction&lt;/b&gt;).&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;a&lt;/i&gt; ∧ &lt;i&gt;b&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;true&lt;/b&gt; if both &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;, and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;Alternatively, we could give the semantics of ∧ by listing the returned value in each of four cases, giving the four possible combinations of input values. Using this approach, we could express the postcondition as follows.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;c&lt;/i&gt;, where&lt;/p&gt;&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A second binary operation on Boolean values returns &lt;b&gt;true&lt;/b&gt; if either (or both) of the two Boolean values is &lt;b&gt;true&lt;/b&gt;. We write this operation using the infix symbol ∨ , where ∧ can be read as “or”. The corresponding function is described below. The operation ∨ is also known as &lt;b&gt;disjunction&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;a&lt;/i&gt; ∨ &lt;i&gt;b&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;false&lt;/b&gt; if both &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;, and is &lt;b&gt;true&lt;/b&gt; otherwise.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act026"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 25&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give the semantics of ∨ by listing the returned value in each of four cases, giving the four possible combinations of input values.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;We can express the postcondition in the description above as follows.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; The returned value is &lt;i&gt;c&lt;/i&gt;, where&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt; then &lt;i&gt;c&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Another useful process on Boolean values inputs a single Boolean value, and returns the reverse of that value. This process, called &lt;b&gt;negation&lt;/b&gt;, is not a binary operation, since it has one input only. We call this function &lt;i&gt;NOT&lt;/i&gt;, and we have&lt;/p&gt;&lt;div class="oucontent-quote oucontent-s-box" id="quo013"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;NOT&lt;/i&gt;(&lt;b&gt;false&lt;/b&gt;) = &lt;b&gt;true&lt;/b&gt;, and &lt;i&gt;NOT&lt;/i&gt;(&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act027"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 26&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) Give a full description of the function &lt;i&gt;NOT&lt;/i&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) If &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and &lt;i&gt;b&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;, evaluate each of:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;a&lt;/i&gt; ∨ &lt;i&gt;b&lt;/i&gt;;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;a&lt;/i&gt; ∨ &lt;i&gt;b&lt;/i&gt;);&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;a&lt;/i&gt; ∧ (&lt;i&gt;a&lt;/i&gt; ∨ &lt;i&gt;b&lt;/i&gt;).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;(a) A description is given below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;a&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;false&lt;/b&gt; if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;true&lt;/b&gt; and is &lt;b&gt;true&lt;/b&gt; if &lt;i&gt;a&lt;/i&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;(b) (i) Substituting for &lt;i&gt;a&lt;/i&gt; and &lt;i&gt;b&lt;/i&gt;, we have &lt;b&gt;true&lt;/b&gt; ∨ &lt;b&gt;false&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;(ii) We should evaluate the term in brackets first: &lt;b&gt;true&lt;/b&gt; ∨ &lt;b&gt;false&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;. Then &lt;i&gt;NOT&lt;/i&gt;(&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;. So &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;a&lt;/i&gt; ∨ &lt;i&gt;b&lt;/i&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;(iii) Again, evaluate the term in brackets first: (&lt;b&gt;true&lt;/b&gt; ∨ &lt;b&gt;false&lt;/b&gt;) = &lt;b&gt;true&lt;/b&gt;. Then the given expression becomes &lt;b&gt;true&lt;/b&gt; ∧ &lt;b&gt;true&lt;/b&gt; which evaluates to &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>5.3 Comparison functions</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.4</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Another situation where we use infix notation is in writing comparisons, such as &lt;i&gt;x &amp;lt; y&lt;/i&gt;, where &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are numbers. Such a comparison is either true or false. For example, 5 &amp;lt; 9 is true but 5 &amp;lt; 2 is false. To describe a corresponding function, we take the output set to be &lt;i&gt;Bool&lt;/i&gt; = {&lt;b&gt;true&lt;/b&gt;, &lt;b&gt;false&lt;/b&gt;}. Thus the comparison &amp;lt; on integers corresponds to a function, which we can describe as follows.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x &amp;lt; Int y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;true&lt;/b&gt; if &lt;i&gt;x&lt;/i&gt; &amp;lt; &lt;i&gt;y&lt;/i&gt; and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;Equality is also a comparison function. This is normally written using the infix symbol =. If &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are numbers, then &lt;i&gt;x&lt;/i&gt; = &lt;i&gt;y&lt;/i&gt; is true if the numbers &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are the same and is false if they are not. If one is working with real numbers on a computer, then one needs to be very careful with tests of equality. There will be an element of approximation in the way real numbers are stored, and this may result in a computer reporting real numbers as equal when they are only approximately equal. However, we shall confine our attention to integers, where there is no such problem in deciding whether two numbers are the same.&lt;/p&gt;&lt;p&gt;Sometimes we may wish to test to see whether two characters are the same. (This can be done by comparing their ASCII codes, for example.) A computer will need to work in a different way when comparing two integers for equality from that needed when comparing two characters for equality. These are different processes. Equality of numbers is a function with signature &lt;i&gt;Int &amp;#xD7; Int&lt;/i&gt; &amp;#x2192; &lt;i&gt;Bool&lt;/i&gt;; equality of characters, on the other hand, has signature &lt;i&gt;Char &amp;#xD7; Char&lt;/i&gt; &amp;#x2192; &lt;i&gt;Bool&lt;/i&gt;. Since these are different functions, we will give them different identifiers. We will write =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; for equality of integers and =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; for equality of characters.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;true&lt;/b&gt; if the integers &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are equal and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is &lt;b&gt;true&lt;/b&gt; if the characters &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are the same and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;One could give a binary operation &amp;lt; that compares characters by comparing their ASCII codes. Again, this is a different function from that of comparing integers (which is why we used a subscript &lt;i&gt;Int&lt;/i&gt; in the identifier &amp;lt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; for comparison of integers above).&lt;/p&gt;&lt;p&gt;Note that in mathematics the term binary operation would only be used for a total function whose return type is the same as the type of the inputs.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act028"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 27&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give a full description of an infix function corresponding to &amp;lt;&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; comparing two characters by comparing their ASCII codes.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;A description is given below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; &amp;lt;&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is true if &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt;) &amp;lt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;ASC&lt;/i&gt; (&lt;i&gt;y&lt;/i&gt;) and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;In practice, a variety of different comparisons are used on integers (and other forms of data, such as characters), including: &amp;gt; (strictly greater than), &amp;#x2264; (less than or equal), &amp;#x2265; (greater then or equal), and &amp;#x2260; (not equal). Functions may be described for each of these, but we shall not do so here.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.4</guid>
    <dc:title>5.3 Comparison functions</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Another situation where we use infix notation is in writing comparisons, such as &lt;i&gt;x &lt; y&lt;/i&gt;, where &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are numbers. Such a comparison is either true or false. For example, 5 &lt; 9 is true but 5 &lt; 2 is false. To describe a corresponding function, we take the output set to be &lt;i&gt;Bool&lt;/i&gt; = {&lt;b&gt;true&lt;/b&gt;, &lt;b&gt;false&lt;/b&gt;}. Thus the comparison &lt; on integers corresponds to a function, which we can describe as follows.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x &lt; Int y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;true&lt;/b&gt; if &lt;i&gt;x&lt;/i&gt; &lt; &lt;i&gt;y&lt;/i&gt; and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;Equality is also a comparison function. This is normally written using the infix symbol =. If &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are numbers, then &lt;i&gt;x&lt;/i&gt; = &lt;i&gt;y&lt;/i&gt; is true if the numbers &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are the same and is false if they are not. If one is working with real numbers on a computer, then one needs to be very careful with tests of equality. There will be an element of approximation in the way real numbers are stored, and this may result in a computer reporting real numbers as equal when they are only approximately equal. However, we shall confine our attention to integers, where there is no such problem in deciding whether two numbers are the same.&lt;/p&gt;&lt;p&gt;Sometimes we may wish to test to see whether two characters are the same. (This can be done by comparing their ASCII codes, for example.) A computer will need to work in a different way when comparing two integers for equality from that needed when comparing two characters for equality. These are different processes. Equality of numbers is a function with signature &lt;i&gt;Int × Int&lt;/i&gt; → &lt;i&gt;Bool&lt;/i&gt;; equality of characters, on the other hand, has signature &lt;i&gt;Char × Char&lt;/i&gt; → &lt;i&gt;Bool&lt;/i&gt;. Since these are different functions, we will give them different identifiers. We will write =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; for equality of integers and =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; for equality of characters.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;true&lt;/b&gt; if the integers &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are equal and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is &lt;b&gt;true&lt;/b&gt; if the characters &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; are the same and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;&lt;p&gt;One could give a binary operation &lt; that compares characters by comparing their ASCII codes. Again, this is a different function from that of comparing integers (which is why we used a subscript &lt;i&gt;Int&lt;/i&gt; in the identifier &lt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; for comparison of integers above).&lt;/p&gt;&lt;p&gt;Note that in mathematics the term binary operation would only be used for a total function whose return type is the same as the type of the inputs.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act028"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 27&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give a full description of an infix function corresponding to &lt;&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; comparing two characters by comparing their ASCII codes.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;p&gt;A description is given below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x&lt;/i&gt; &lt;&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Char&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Bool&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is true if &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;x&lt;/i&gt;) &lt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;ASC&lt;/i&gt; (&lt;i&gt;y&lt;/i&gt;) and is &lt;b&gt;false&lt;/b&gt; otherwise.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;In practice, a variety of different comparisons are used on integers (and other forms of data, such as characters), including: &gt; (strictly greater than), ≤ (less than or equal), ≥ (greater then or equal), and ≠ (not equal). Functions may be described for each of these, but we shall not do so here.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>5.4 Expressions</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.5</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;In computer code, one may want to formulate an expression to achieve some particular purpose, such as to express some condition about the states of variables involved in the code. For example, suppose that you want to express the condition that a sequence &lt;i&gt;s&lt;/i&gt; contains at least two members, and that the second member of &lt;i&gt;s&lt;/i&gt; is not the space character (with ASCII code 32). This condition holds when the expression below is &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;(&lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &amp;gt; &lt;sub&gt;&lt;i&gt;Int&lt;/i&gt;&lt;/sub&gt; 1) &amp;#x2227; (&lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;)) = &lt;sub&gt;&lt;i&gt;Int&lt;/i&gt;&lt;/sub&gt; 32))&lt;/p&gt;&lt;p&gt;When writing expressions involving functions and binary operations, there are some points to be careful about. One needs to be careful to use brackets as necessary to ensure that operations are applied in the desired order. This is particularly important in expressions using infix notation. You also need to apply each process in a way that is consistent with its signature. And you must apply each process in a way that is consistent with any precondition that it has. We say that an expression is &lt;b&gt;not valid&lt;/b&gt; if it uses a function in a way that is inconsistent with its signature or its precondition. For example, &amp;#x2018;Q’ =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 32 is not valid, since =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; compares two integers, and &amp;#x2018;Q’ is a character, while &lt;i&gt;PUT&lt;/i&gt;(7, &amp;#x201C;This&amp;#x201D;, &amp;#x2018;Q’) is not valid, since 7 does not satisfy the precondition of &lt;i&gt;PUT&lt;/i&gt;. (The precondition of &lt;i&gt;PUT&lt;/i&gt; requires that 7&amp;#x2264; &lt;i&gt;SIZE&lt;/i&gt;(&amp;#x201C;This&amp;#x201D;), but &lt;i&gt;SIZE&lt;/i&gt;(&amp;#x201C;This&amp;#x201D;) is 4.)&lt;/p&gt;&lt;p&gt;The functions &lt;i&gt;SIZE&lt;/i&gt; and &lt;i&gt;AT&lt;/i&gt; were described in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.2#act017"&gt;Activity 16&lt;/a&gt;, and the function &lt;i&gt;ASC&lt;/i&gt; was described in Section 4.3. The binary operations =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt;, &amp;gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; and &amp;#x2227; are defined earlier in this section.&lt;/p&gt;&lt;div class="&amp;#10;            oucontent-activity&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="act029"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 28&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) With &lt;i&gt;s&lt;/i&gt; = &amp;#x201C;I#am.&amp;#x201D;, evaluate each of the expressions:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iv) &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(v) (&lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &amp;gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3) &amp;#x2227; (&lt;i&gt;NOT&lt;/i&gt; (&lt;i&gt;ASC&lt;/i&gt; (&lt;i&gt;AT&lt;/i&gt; (2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35)).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Let &lt;i&gt;s&lt;/i&gt; be a general string. Under what circumstances does the expression in (a) (v) give the value &lt;b&gt;true&lt;/b&gt;? Under what circumstances is that expression valid?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) With &lt;i&gt;s&lt;/i&gt; = &amp;#x201C;I#am.&amp;#x201D;, why is it not possible to evaluate the expression&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;)) = &lt;sub&gt;&lt;i&gt;Int&lt;/i&gt;&lt;/sub&gt; 35)?&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) (i) &lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;) = &amp;#x2018;#’.&lt;/p&gt; &lt;p&gt;(ii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) = 35.&lt;/p&gt; &lt;p&gt;(iii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35 becomes 35 =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35, which evaluates to &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt; &lt;p&gt;(iv) &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35) becomes &lt;i&gt;NOT&lt;/i&gt; (&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt; &lt;p&gt;(v) We have &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) = 5 (the number of characters in the string &amp;#x201C;I#am.&amp;#x201D;), so (&lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &amp;gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3) becomes (5 &amp;gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3) which is &lt;b&gt;true&lt;/b&gt;. So the expression in (v) becomes &lt;b&gt;true&lt;/b&gt; &amp;#x2227; &lt;b&gt;false&lt;/b&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) The given expression will be &lt;b&gt;true&lt;/b&gt; only if each of &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &amp;gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3 and &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35) is &lt;b&gt;true&lt;/b&gt;. The first of these is &lt;b&gt;true&lt;/b&gt; if the string &lt;i&gt;s&lt;/i&gt; contains at least four characters. The second is &lt;b&gt;true&lt;/b&gt; if the second character is &lt;i&gt;s&lt;/i&gt; is not the character &amp;#x2018;#’. So the expression in (a) (v) will be &lt;b&gt;true&lt;/b&gt; if:&lt;/p&gt; &lt;p&gt;the string &lt;i&gt;s&lt;/i&gt; contains at least four characters and its second character is not &amp;#x2018;#’.&lt;/p&gt; &lt;p&gt;The precondition of &lt;i&gt;AT&lt;/i&gt; requires here that the string &lt;i&gt;s&lt;/i&gt; contains at least two characters. The expression in (a) (v) will be valid so long as this is true. (All the other functions in the expression are total. The example in part (a) indicates that the expression is put together in a way that is consistent with the signatures of the functions.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;) = &amp;#x2018;#’. Then &lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35 becomes &amp;#x2018;#’ =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35. This expression is not valid, since =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; requires two integers as inputs, and &amp;#x2018;#’ is a character. So the given expression is not valid.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Notice how important the brackets are in a complicated expression. The order in which the bits of the overall expression are to be evaluated is determined by the way the brackets appear in the expression. We need to follow this carefully in evaluating an expression such as that in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.5#act029"&gt;Activity 28&lt;/a&gt; (a) (v). A slip in placing one bracket can easily lead to an expression that is not valid, as in (c) above. On the whole, it is good practice when writing computing code to seek to avoid writing complicated expressions. Usually one can split the code into intermediate steps, as indicated by the steps in the evaluation in (a) above.&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.5</guid>
    <dc:title>5.4 Expressions</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;In computer code, one may want to formulate an expression to achieve some particular purpose, such as to express some condition about the states of variables involved in the code. For example, suppose that you want to express the condition that a sequence &lt;i&gt;s&lt;/i&gt; contains at least two members, and that the second member of &lt;i&gt;s&lt;/i&gt; is not the space character (with ASCII code 32). This condition holds when the expression below is &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;(&lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &gt; &lt;sub&gt;&lt;i&gt;Int&lt;/i&gt;&lt;/sub&gt; 1) ∧ (&lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;)) = &lt;sub&gt;&lt;i&gt;Int&lt;/i&gt;&lt;/sub&gt; 32))&lt;/p&gt;&lt;p&gt;When writing expressions involving functions and binary operations, there are some points to be careful about. One needs to be careful to use brackets as necessary to ensure that operations are applied in the desired order. This is particularly important in expressions using infix notation. You also need to apply each process in a way that is consistent with its signature. And you must apply each process in a way that is consistent with any precondition that it has. We say that an expression is &lt;b&gt;not valid&lt;/b&gt; if it uses a function in a way that is inconsistent with its signature or its precondition. For example, ‘Q’ =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 32 is not valid, since =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; compares two integers, and ‘Q’ is a character, while &lt;i&gt;PUT&lt;/i&gt;(7, “This”, ‘Q’) is not valid, since 7 does not satisfy the precondition of &lt;i&gt;PUT&lt;/i&gt;. (The precondition of &lt;i&gt;PUT&lt;/i&gt; requires that 7≤ &lt;i&gt;SIZE&lt;/i&gt;(“This”), but &lt;i&gt;SIZE&lt;/i&gt;(“This”) is 4.)&lt;/p&gt;&lt;p&gt;The functions &lt;i&gt;SIZE&lt;/i&gt; and &lt;i&gt;AT&lt;/i&gt; were described in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-5.2#act017"&gt;Activity 16&lt;/a&gt;, and the function &lt;i&gt;ASC&lt;/i&gt; was described in Section 4.3. The binary operations =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt;, &gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; and ∧ are defined earlier in this section.&lt;/p&gt;&lt;div class="
            oucontent-activity
           oucontent-s-heavybox1 oucontent-s-box " id="act029"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Activity 28&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) With &lt;i&gt;s&lt;/i&gt; = “I#am.”, evaluate each of the expressions:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(iv) &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(v) (&lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3) ∧ (&lt;i&gt;NOT&lt;/i&gt; (&lt;i&gt;ASC&lt;/i&gt; (&lt;i&gt;AT&lt;/i&gt; (2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35)).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Let &lt;i&gt;s&lt;/i&gt; be a general string. Under what circumstances does the expression in (a) (v) give the value &lt;b&gt;true&lt;/b&gt;? Under what circumstances is that expression valid?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) With &lt;i&gt;s&lt;/i&gt; = “I#am.”, why is it not possible to evaluate the expression&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;)) = &lt;sub&gt;&lt;i&gt;Int&lt;/i&gt;&lt;/sub&gt; 35)?&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-discussion" data-showtext="Reveal discussion" data-hidetext="Hide discussion"&gt;&lt;h3 class="oucontent-h4"&gt;Discussion&lt;/h3&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) (i) &lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;) = ‘#’.&lt;/p&gt; &lt;p&gt;(ii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) = 35.&lt;/p&gt; &lt;p&gt;(iii) &lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35 becomes 35 =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35, which evaluates to &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt; &lt;p&gt;(iv) &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35) becomes &lt;i&gt;NOT&lt;/i&gt; (&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt; &lt;p&gt;(v) We have &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) = 5 (the number of characters in the string “I#am.”), so (&lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3) becomes (5 &gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3) which is &lt;b&gt;true&lt;/b&gt;. So the expression in (v) becomes &lt;b&gt;true&lt;/b&gt; ∧ &lt;b&gt;false&lt;/b&gt; = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) The given expression will be &lt;b&gt;true&lt;/b&gt; only if each of &lt;i&gt;SIZE&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) &gt;&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 3 and &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;ASC&lt;/i&gt;(&lt;i&gt;AT&lt;/i&gt;(2, &lt;i&gt;s&lt;/i&gt;)) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35) is &lt;b&gt;true&lt;/b&gt;. The first of these is &lt;b&gt;true&lt;/b&gt; if the string &lt;i&gt;s&lt;/i&gt; contains at least four characters. The second is &lt;b&gt;true&lt;/b&gt; if the second character is &lt;i&gt;s&lt;/i&gt; is not the character ‘#’. So the expression in (a) (v) will be &lt;b&gt;true&lt;/b&gt; if:&lt;/p&gt; &lt;p&gt;the string &lt;i&gt;s&lt;/i&gt; contains at least four characters and its second character is not ‘#’.&lt;/p&gt; &lt;p&gt;The precondition of &lt;i&gt;AT&lt;/i&gt; requires here that the string &lt;i&gt;s&lt;/i&gt; contains at least two characters. The expression in (a) (v) will be valid so long as this is true. (All the other functions in the expression are total. The example in part (a) indicates that the expression is put together in a way that is consistent with the signatures of the functions.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) &lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;) = ‘#’. Then &lt;i&gt;AT&lt;/i&gt;(2,&lt;i&gt;s&lt;/i&gt;) =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35 becomes ‘#’ =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; 35. This expression is not valid, since =&lt;sub&gt; &lt;i&gt;Int&lt;/i&gt; &lt;/sub&gt; requires two integers as inputs, and ‘#’ is a character. So the given expression is not valid.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Notice how important the brackets are in a complicated expression. The order in which the bits of the overall expression are to be evaluated is determined by the way the brackets appear in the expression. We need to follow this carefully in evaluating an expression such as that in &lt;a class="oucontent-crossref" href="https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.5#act029"&gt;Activity 28&lt;/a&gt; (a) (v). A slip in placing one bracket can easily lead to an expression that is not valid, as in (c) above. On the whole, it is good practice when writing computing code to seek to avoid writing complicated expressions. Usually one can split the code into intermediate steps, as indicated by the steps in the evaluation in (a) above.&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Objectives for Section 5</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.6</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: binary operation, infix notation, quotient and remainder (associated with integer division).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use the notation for various binary operations introduced in the text, in particular &lt;i&gt;DIV&lt;/i&gt; and &lt;i&gt;MOD&lt;/i&gt; on integers; and &amp;#x2227; (and) and &amp;#x2228; (or) on Boolean values.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Suggest appropriate signatures and preconditions for functions corresponding to binary operations, including comparisons that return Boolean values.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Evaluate expressions involving functions and binary operations introduced in the text. Take note of where brackets appear in an expression.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Recognise an expression that is invalid because it uses a process in a way inconsistent with its signature or precondition.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.6</guid>
    <dc:title>Objectives for Section 5</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;&lt;b&gt;After studying this section you should be able to do the following.&lt;/b&gt;&lt;/p&gt;&lt;ul class="oucontent-bulleted"&gt;&lt;li&gt;&lt;p&gt;Recognise and use the terminology: binary operation, infix notation, quotient and remainder (associated with integer division).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use the notation for various binary operations introduced in the text, in particular &lt;i&gt;DIV&lt;/i&gt; and &lt;i&gt;MOD&lt;/i&gt; on integers; and ∧ (and) and ∨ (or) on Boolean values.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Suggest appropriate signatures and preconditions for functions corresponding to binary operations, including comparisons that return Boolean values.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Evaluate expressions involving functions and binary operations introduced in the text. Take note of where brackets appear in an expression.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Recognise an expression that is invalid because it uses a process in a way inconsistent with its signature or precondition.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Exercises on Section 5</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.7</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq012"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 12&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give a full description of a function (using the infix notation &amp;#xD7;) corresponding to multiplication of integers.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;A suitable description of integer multiplication is given below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x &amp;#xD7; y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre &amp;#xA0; true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is the result of multiplying &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq013"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 13&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;With &lt;i&gt;n&lt;/i&gt; = 966, evaluate each of:&lt;/p&gt;
&lt;p&gt;(a) &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n,&lt;/i&gt; 10);&lt;/p&gt;
&lt;p&gt;(b) &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n,&lt;/i&gt; 10);&lt;/p&gt;
&lt;p&gt;(c) &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n,&lt;/i&gt; 10), 10).&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;966 = 96 &amp;#xD7; 10 + 6. So (a) &lt;i&gt;MOD&lt;/i&gt;(966, 10) = 6 (the remainder when 966 is divided by 10), and (b) &lt;i&gt;DIV&lt;/i&gt; (966,10) = 96. Then (c) &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;DIV&lt;/i&gt; (966, 10), 10) becomes &lt;i&gt;MOD&lt;/i&gt;(96, 10). This evaluates to 6, which is the remainder when 96 is divided by 10.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="&amp;#10;            oucontent-saq&amp;#10;           oucontent-s-heavybox1 oucontent-s-box " id="saq014"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 14&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;The function &lt;i&gt;LAST&lt;/i&gt; is described below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt; &amp;#xA0; &lt;i&gt;s&lt;/i&gt; is not empty.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt; &amp;#xA0; The returned value is the last element in &lt;i&gt;s&lt;/i&gt;. For example, &lt;i&gt;LAST&lt;/i&gt;([1, 2, 3]) = 3.&lt;/p&gt;
&lt;p&gt;Consider the expression &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;LAST&lt;/i&gt; (&lt;i&gt;t&lt;/i&gt;)).&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) What is the value of this expression if &lt;i&gt;s&lt;/i&gt; is &amp;#x201C;the&amp;#x201D; and &lt;i&gt;t&lt;/i&gt; is:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) &amp;#x201C;same&amp;#x201D;;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) &amp;#x201C;different&amp;#x201D;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Under what circumstances does this expression have the value &lt;b&gt;true&lt;/b&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Is this expression valid with &lt;i&gt;s&lt;/i&gt; = [1,2] and &lt;i&gt;t&lt;/i&gt; = [1,8,4,2]?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;(a) If &lt;i&gt;s&lt;/i&gt; = &amp;#x201C;the&amp;#x201D; then &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) = &amp;#x2018;e’. (i) With &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;same&amp;#x201D;, we have &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) = &amp;#x2018;e’, and the given expression becomes&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo014"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;NOT&lt;/i&gt;(&amp;#x2018;e’ =&lt;sub&gt;Char&lt;/sub&gt; &amp;#x2018;e’) = &lt;i&gt;NOT&lt;/i&gt; (&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;p&gt;(i) With &lt;i&gt;t&lt;/i&gt; = &amp;#x201C;different&amp;#x201D;, we have &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) = &amp;#x2018;t’, and the given expression becomes&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo015"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;NOT&lt;/i&gt;(&amp;#x2018;e’ =&lt;sub&gt;Char&lt;/sub&gt; &amp;#x2018;t’) = &lt;i&gt;NOT&lt;/i&gt; (&lt;b&gt;false&lt;/b&gt;) = &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;p&gt;(b) The given expression is &lt;b&gt;true&lt;/b&gt; if the strings &lt;i&gt;s&lt;/i&gt; and &lt;i&gt;t&lt;/i&gt; have different last letters.&lt;/p&gt;
&lt;p&gt;(c) With these values of &lt;i&gt;s&lt;/i&gt; and &lt;i&gt;t&lt;/i&gt;, the given expression becomes &lt;i&gt;NOT&lt;/i&gt;(2 =&lt;sub&gt;Char&lt;/sub&gt; 2). Now =&lt;sub&gt;Char&lt;/sub&gt; compares two characters, and 2 is an integer. So this expression is not valid. (For the given expression to be valid, we need &lt;i&gt;s&lt;/i&gt; and &lt;i&gt;t&lt;/i&gt; to be sequences of characters, and to be non-empty, so that the precondition of &lt;i&gt;LAST&lt;/i&gt; is satisfied.)&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.7</guid>
    <dc:title>Exercises on Section 5</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq012"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 12&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;Give a full description of a function (using the infix notation ×) corresponding to multiplication of integers.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;A suitable description of integer multiplication is given below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; (&lt;b&gt;infix&lt;/b&gt;) (&lt;i&gt;x × y&lt;/i&gt; &lt;b&gt;on&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;Int&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre   true&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is the result of multiplying &lt;i&gt;x&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq013"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 13&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;With &lt;i&gt;n&lt;/i&gt; = 966, evaluate each of:&lt;/p&gt;
&lt;p&gt;(a) &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n,&lt;/i&gt; 10);&lt;/p&gt;
&lt;p&gt;(b) &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n,&lt;/i&gt; 10);&lt;/p&gt;
&lt;p&gt;(c) &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n,&lt;/i&gt; 10), 10).&lt;/p&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;966 = 96 × 10 + 6. So (a) &lt;i&gt;MOD&lt;/i&gt;(966, 10) = 6 (the remainder when 966 is divided by 10), and (b) &lt;i&gt;DIV&lt;/i&gt; (966,10) = 96. Then (c) &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;DIV&lt;/i&gt; (966, 10), 10) becomes &lt;i&gt;MOD&lt;/i&gt;(96, 10). This evaluates to 6, which is the remainder when 96 is divided by 10.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="
            oucontent-saq
           oucontent-s-heavybox1 oucontent-s-box " id="saq014"&gt;&lt;div class="oucontent-outer-box"&gt;&lt;h2 class="oucontent-h3 oucontent-heading oucontent-nonumber"&gt;Exercise 14&lt;/h2&gt;&lt;div class="oucontent-inner-box"&gt;&lt;div class="oucontent-saq-question"&gt;
&lt;p&gt;The function &lt;i&gt;LAST&lt;/i&gt; is described below.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;function&lt;/b&gt; &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt; &lt;b&gt;in&lt;/b&gt; &lt;i&gt;SeqOfX&lt;/i&gt; ) &lt;b&gt;return in&lt;/b&gt; &lt;i&gt;X&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;pre&lt;/b&gt;   &lt;i&gt;s&lt;/i&gt; is not empty.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;post&lt;/b&gt;   The returned value is the last element in &lt;i&gt;s&lt;/i&gt;. For example, &lt;i&gt;LAST&lt;/i&gt;([1, 2, 3]) = 3.&lt;/p&gt;
&lt;p&gt;Consider the expression &lt;i&gt;NOT&lt;/i&gt;(&lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; &lt;i&gt;LAST&lt;/i&gt; (&lt;i&gt;t&lt;/i&gt;)).&lt;/p&gt;
&lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(a) What is the value of this expression if &lt;i&gt;s&lt;/i&gt; is “the” and &lt;i&gt;t&lt;/i&gt; is:&lt;/p&gt; &lt;ul class="oucontent-unnumbered"&gt;&lt;li&gt;&lt;p&gt;(i) “same”;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(ii) “different”?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(b) Under what circumstances does this expression have the value &lt;b&gt;true&lt;/b&gt;?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(c) Is this expression valid with &lt;i&gt;s&lt;/i&gt; = [1,2] and &lt;i&gt;t&lt;/i&gt; = [1,8,4,2]?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;div class="oucontent-saq-answer" data-showtext="Reveal answer" data-hidetext="Hide answer"&gt;&lt;h3 class="oucontent-h4"&gt;Answer&lt;/h3&gt;
&lt;h3 class="oucontent-h4 oucontent-basic"&gt;Solution&lt;/h3&gt;
&lt;p&gt;(a) If &lt;i&gt;s&lt;/i&gt; = “the” then &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;s&lt;/i&gt;) = ‘e’. (i) With &lt;i&gt;t&lt;/i&gt; = “same”, we have &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) = ‘e’, and the given expression becomes&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo014"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;NOT&lt;/i&gt;(‘e’ =&lt;sub&gt;Char&lt;/sub&gt; ‘e’) = &lt;i&gt;NOT&lt;/i&gt; (&lt;b&gt;true&lt;/b&gt;) = &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;p&gt;(i) With &lt;i&gt;t&lt;/i&gt; = “different”, we have &lt;i&gt;LAST&lt;/i&gt;(&lt;i&gt;t&lt;/i&gt;) = ‘t’, and the given expression becomes&lt;/p&gt;
&lt;div class="oucontent-quote oucontent-s-box" id="quo015"&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;NOT&lt;/i&gt;(‘e’ =&lt;sub&gt;Char&lt;/sub&gt; ‘t’) = &lt;i&gt;NOT&lt;/i&gt; (&lt;b&gt;false&lt;/b&gt;) = &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;
&lt;p&gt;(b) The given expression is &lt;b&gt;true&lt;/b&gt; if the strings &lt;i&gt;s&lt;/i&gt; and &lt;i&gt;t&lt;/i&gt; have different last letters.&lt;/p&gt;
&lt;p&gt;(c) With these values of &lt;i&gt;s&lt;/i&gt; and &lt;i&gt;t&lt;/i&gt;, the given expression becomes &lt;i&gt;NOT&lt;/i&gt;(2 =&lt;sub&gt;Char&lt;/sub&gt; 2). Now =&lt;sub&gt;Char&lt;/sub&gt; compares two characters, and 2 is an integer. So this expression is not valid. (For the given expression to be valid, we need &lt;i&gt;s&lt;/i&gt; and &lt;i&gt;t&lt;/i&gt; to be sequences of characters, and to be non-empty, so that the precondition of &lt;i&gt;LAST&lt;/i&gt; is satisfied.)&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Conclusion</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.8</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;ol class="oucontent-numbered"&gt;&lt;li&gt;&lt;p&gt;We discussed forms of data and processes relevant to an electronic till in a supermarket. In particular, we introduced the idea of a sequence of data items.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A number of fundamental forms of data were introduced. We distinguished two types of number: integers (positive or negative whole numbers, or 0), and real numbers (thought of as decimal numbers and approximated in computers as floating point numbers). Characters may be thought of as symbols that may be entered from a computer keyboard by a single keystroke. Each character is associated with an integer code and we introduced one such encoding called the ASCII code. The Boolean values &lt;b&gt;true&lt;/b&gt; and &lt;b&gt;false&lt;/b&gt; form another fundamental form of data.&lt;/p&gt; &lt;p&gt;Data may be structured in a collection. Different forms of collection are possible. We looked at two: sets and sequences. In a sequence, the order in which the items appear in the collection is important and an item may appear more than once. In a set, one is only interested in the different items appearing in the collection, and the order in which these items are listed is of no significance, nor is repetition of an item.&lt;/p&gt; &lt;p&gt;The Cartesian product of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; is written &lt;i&gt;X &amp;#xD7; Y&lt;/i&gt; , and is the set consisting of all ordered pairs (&lt;i&gt;x, y&lt;/i&gt;), where &lt;i&gt;x&lt;/i&gt; is in &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; is in &lt;i&gt;Y&lt;/i&gt; . An ordered pair is also called a 2-tuple. More generally, an &lt;i&gt;n&lt;/i&gt;-tuple is an association of &lt;i&gt;n&lt;/i&gt; items, each taken from a specified set. An &lt;i&gt;n&lt;/i&gt;-tuple is written in round brackets, and is a member of a Cartesian product set combining &lt;i&gt;n&lt;/i&gt; component sets. For example, a member of the set &lt;i&gt;Int &amp;#xD7; Char &amp;#xD7; Int &amp;#xD7; SeqOfChar&lt;/i&gt; would be a 4-tuple, such as (121, &amp;#x2018;y’, 6, &amp;#x201C;Qwerty&amp;#x201D;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The disjoint union of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt;, written &lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt;, consists of all items that come either from &lt;i&gt;X&lt;/i&gt; or from &lt;i&gt;Y&lt;/i&gt; (where &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; have nothing in common). This is useful when we want to mix different forms of data in a sequence.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A function is a process that returns a unique value for each permitted input. To give a full description of a function, we give: its signature (name, and input and output sets), a precondition (which may be &lt;b&gt;true&lt;/b&gt;), and a postcondition giving its semantics. The semantics should be an unambiguous statement of the relationship between the returned value and the input(s).&lt;/p&gt; &lt;p&gt;If a function has more than one input, then its input set will be a Cartesian product. If a function returns a value that is &lt;b&gt;true&lt;/b&gt; or &lt;b&gt;false&lt;/b&gt;, then the output set will be &lt;i&gt;Bool&lt;/i&gt;. Usually, the semantics of a function are given by a general rule, or possibly by a formula. However, in some cases we need to list the returned value for each possible input. For example, this would be the case for a function returning the price of each barcoded product stocked by a supermarket.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A binary operation is a process, such as addition of integers, that inputs two data items of the same type. A binary operation can be written using infix notation (as in &lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt;, for example). Addition of integers corresponds to a function with signature &lt;i&gt;Int &amp;#xD7; Int&lt;/i&gt; &amp;#x2192; &lt;i&gt;Int&lt;/i&gt;. We described integer division. Integer division of &lt;i&gt;n&lt;/i&gt; by &lt;i&gt;d&lt;/i&gt; returns an integer, written &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n, d&lt;/i&gt;). It also leaves a remainder, denoted by &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n, d&lt;/i&gt;).&lt;/p&gt; &lt;p&gt;We noted that binary operations are not confined to those on numbers. We described two binary operations on Boolean values that are frequently useful: &amp;#x2228; (read as &amp;#x201C;or&amp;#x201D;) and &amp;#x2227; (read as &amp;#x201C;and&amp;#x201D;). We also introduced the function &lt;i&gt;NOT&lt;/i&gt; on Booleans.&lt;/p&gt; &lt;p&gt;Comparisons, such as &amp;lt; or =, are operations returning values in the output set &lt;i&gt;Bool&lt;/i&gt;. For example, =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; , a test of whether two characters are identical, corresponds to a function with signature &lt;i&gt;Char &amp;#xD7; Char&lt;/i&gt; &amp;#x2192; &lt;i&gt;Bool.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section-6.8</guid>
    <dc:title>Conclusion</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;ol class="oucontent-numbered"&gt;&lt;li&gt;&lt;p&gt;We discussed forms of data and processes relevant to an electronic till in a supermarket. In particular, we introduced the idea of a sequence of data items.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A number of fundamental forms of data were introduced. We distinguished two types of number: integers (positive or negative whole numbers, or 0), and real numbers (thought of as decimal numbers and approximated in computers as floating point numbers). Characters may be thought of as symbols that may be entered from a computer keyboard by a single keystroke. Each character is associated with an integer code and we introduced one such encoding called the ASCII code. The Boolean values &lt;b&gt;true&lt;/b&gt; and &lt;b&gt;false&lt;/b&gt; form another fundamental form of data.&lt;/p&gt; &lt;p&gt;Data may be structured in a collection. Different forms of collection are possible. We looked at two: sets and sequences. In a sequence, the order in which the items appear in the collection is important and an item may appear more than once. In a set, one is only interested in the different items appearing in the collection, and the order in which these items are listed is of no significance, nor is repetition of an item.&lt;/p&gt; &lt;p&gt;The Cartesian product of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; is written &lt;i&gt;X × Y&lt;/i&gt; , and is the set consisting of all ordered pairs (&lt;i&gt;x, y&lt;/i&gt;), where &lt;i&gt;x&lt;/i&gt; is in &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;y&lt;/i&gt; is in &lt;i&gt;Y&lt;/i&gt; . An ordered pair is also called a 2-tuple. More generally, an &lt;i&gt;n&lt;/i&gt;-tuple is an association of &lt;i&gt;n&lt;/i&gt; items, each taken from a specified set. An &lt;i&gt;n&lt;/i&gt;-tuple is written in round brackets, and is a member of a Cartesian product set combining &lt;i&gt;n&lt;/i&gt; component sets. For example, a member of the set &lt;i&gt;Int × Char × Int × SeqOfChar&lt;/i&gt; would be a 4-tuple, such as (121, ‘y’, 6, “Qwerty”).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The disjoint union of sets &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt;, written &lt;i&gt;X&lt;/i&gt; &lt;span class="oucontent-inlinefigure"&gt;&lt;img src="https://www.open.edu/openlearn/ocw/pluginfile.php/70251/mod_oucontent/oucontent/531/0bc8896c/7c241102/disjointunion.gif" alt="" width="11" height="10" style="max-width:11px;" class="oucontent-inlinefigure-image"/&gt;&lt;/span&gt; &lt;i&gt;Y&lt;/i&gt;, consists of all items that come either from &lt;i&gt;X&lt;/i&gt; or from &lt;i&gt;Y&lt;/i&gt; (where &lt;i&gt;X&lt;/i&gt; and &lt;i&gt;Y&lt;/i&gt; have nothing in common). This is useful when we want to mix different forms of data in a sequence.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A function is a process that returns a unique value for each permitted input. To give a full description of a function, we give: its signature (name, and input and output sets), a precondition (which may be &lt;b&gt;true&lt;/b&gt;), and a postcondition giving its semantics. The semantics should be an unambiguous statement of the relationship between the returned value and the input(s).&lt;/p&gt; &lt;p&gt;If a function has more than one input, then its input set will be a Cartesian product. If a function returns a value that is &lt;b&gt;true&lt;/b&gt; or &lt;b&gt;false&lt;/b&gt;, then the output set will be &lt;i&gt;Bool&lt;/i&gt;. Usually, the semantics of a function are given by a general rule, or possibly by a formula. However, in some cases we need to list the returned value for each possible input. For example, this would be the case for a function returning the price of each barcoded product stocked by a supermarket.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A binary operation is a process, such as addition of integers, that inputs two data items of the same type. A binary operation can be written using infix notation (as in &lt;i&gt;x&lt;/i&gt; + &lt;i&gt;y&lt;/i&gt;, for example). Addition of integers corresponds to a function with signature &lt;i&gt;Int × Int&lt;/i&gt; → &lt;i&gt;Int&lt;/i&gt;. We described integer division. Integer division of &lt;i&gt;n&lt;/i&gt; by &lt;i&gt;d&lt;/i&gt; returns an integer, written &lt;i&gt;DIV&lt;/i&gt; (&lt;i&gt;n, d&lt;/i&gt;). It also leaves a remainder, denoted by &lt;i&gt;MOD&lt;/i&gt;(&lt;i&gt;n, d&lt;/i&gt;).&lt;/p&gt; &lt;p&gt;We noted that binary operations are not confined to those on numbers. We described two binary operations on Boolean values that are frequently useful: ∨ (read as “or”) and ∧ (read as “and”). We also introduced the function &lt;i&gt;NOT&lt;/i&gt; on Booleans.&lt;/p&gt; &lt;p&gt;Comparisons, such as &lt; or =, are operations returning values in the output set &lt;i&gt;Bool&lt;/i&gt;. For example, =&lt;sub&gt; &lt;i&gt;Char&lt;/i&gt; &lt;/sub&gt; , a test of whether two characters are identical, corresponds to a function with signature &lt;i&gt;Char × Char&lt;/i&gt; → &lt;i&gt;Bool.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
    <item>
      <title>Acknowledgements</title>
      <link>https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section---acknowledgements</link>
      <pubDate>Tue, 12 Apr 2016 23:00:00 GMT</pubDate>
      <description>&lt;p&gt;Except for third party materials and otherwise stated (see &lt;span class="oucontent-linkwithtip"&gt;&lt;a class="oucontent-hyperlink" href="http://www.open.ac.uk/conditions"&gt;terms and conditions&lt;/a&gt;&lt;/span&gt;), this content is made available under a &lt;a class="oucontent-hyperlink" href="https://creativecommons.org/licenses/by-nc-sa/4.0/"&gt;Creative Commons Attribution-NonCommercial-ShareAlike 4.0 Licence&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Course image: &lt;a class="oucontent-hyperlink" href="https://www.flickr.com/photos/creative_stock/"&gt;Creativity103&lt;/a&gt; in Flickr made available under &lt;a class="oucontent-hyperlink" href="https://creativecommons.org/licenses/by/2.0/"&gt;Creative Commons Attribution 2.0 Licence&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;All materials included in this course are derived from content originated at the Open University.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Don't miss out:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;If reading this text has inspired you to learn more, you may be interested in joining the millions of people who discover our free learning resources and qualifications by visiting The Open University - &lt;a class="oucontent-hyperlink" href="http://www.open.edu/openlearn/free-courses?utm_source=openlearn&amp;amp;utm_campaign=ol&amp;amp;utm_medium=ebook"&gt;www.open.edu/&lt;span class="oucontent-hidespace"&gt; &lt;/span&gt;openlearn/&lt;span class="oucontent-hidespace"&gt; &lt;/span&gt;free-courses&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="true">https://www.open.edu/openlearn/science-maths-technology/computing-ict/data-and-processes-computing/content-section---acknowledgements</guid>
    <dc:title>Acknowledgements</dc:title><dc:identifier>M263_1</dc:identifier><dc:description>&lt;p&gt;Except for third party materials and otherwise stated (see &lt;span class="oucontent-linkwithtip"&gt;&lt;a class="oucontent-hyperlink" href="http://www.open.ac.uk/conditions"&gt;terms and conditions&lt;/a&gt;&lt;/span&gt;), this content is made available under a &lt;a class="oucontent-hyperlink" href="https://creativecommons.org/licenses/by-nc-sa/4.0/"&gt;Creative Commons Attribution-NonCommercial-ShareAlike 4.0 Licence&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Course image: &lt;a class="oucontent-hyperlink" href="https://www.flickr.com/photos/creative_stock/"&gt;Creativity103&lt;/a&gt; in Flickr made available under &lt;a class="oucontent-hyperlink" href="https://creativecommons.org/licenses/by/2.0/"&gt;Creative Commons Attribution 2.0 Licence&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;All materials included in this course are derived from content originated at the Open University.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Don't miss out:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;If reading this text has inspired you to learn more, you may be interested in joining the millions of people who discover our free learning resources and qualifications by visiting The Open University - &lt;a class="oucontent-hyperlink" href="http://www.open.edu/openlearn/free-courses?utm_source=openlearn&amp;utm_campaign=ol&amp;utm_medium=ebook"&gt;www.open.edu/&lt;span class="oucontent-hidespace"&gt; &lt;/span&gt;openlearn/&lt;span class="oucontent-hidespace"&gt; &lt;/span&gt;free-courses&lt;/a&gt;&lt;/p&gt;</dc:description><dc:publisher>The Open University</dc:publisher><dc:creator>The Open University</dc:creator><dc:type>Course</dc:type><dc:format>text/html</dc:format><dc:language>en-GB</dc:language><dc:source>Data and processes in computing - M263_1</dc:source><cc:license>Copyright © 2016 The Open University</cc:license></item>
  </channel>
</rss>
