+ All Categories
Home > Documents > Aprendendo AL Com ISETL

Aprendendo AL Com ISETL

Date post: 14-Apr-2018
Category:
Upload: jeancampos
View: 222 times
Download: 0 times
Share this document with a friend

of 401

Transcript
  • 7/29/2019 Aprendendo AL Com ISETL

    1/400

    Learning Linear Algebrawith ISETL

  • 7/29/2019 Aprendendo AL Com ISETL

    2/400

  • 7/29/2019 Aprendendo AL Com ISETL

    3/400

    Learning Linear Algebrawith ISETL

    Kirk Weller Aaron MontgomeryUniversity of North Texas Central Washington University

    Julie Clark Jim CottrillHollins University Illinois State University

    Maria Trigueros Ilana ArnonInstituto Tecnologico Autonomo

    de Mexico

    Centre for Educational

    Technology

    Ed DubinskyRUMEC

    Preliminary Version 3July 31, 2002

  • 7/29/2019 Aprendendo AL Com ISETL

    4/400

    c 2002 by Research in Undergraduate Mathematics Education CommunityAll rights reserved.

  • 7/29/2019 Aprendendo AL Com ISETL

    5/400

    Preface

    The authors wish to express thanks to Don Muench of St. John Fisher College(Rochester, NY) whose work with linear algebra and ISETL gave us the basisfor our work. His code was written at Gettysburg College in 1991 withstudents there, so we thank Jared Colflesh, Ben Papada, Julie Leese, andDave Riihimaki.

    This work is a collaborative effort both in authorship and its conception.We acknowledge the assistance of the following members of RUMEC whohave worked with us at various stages of the project:

    Broni Czarnocha David DeVries Clare HemenwayGeorge Litman Sergio Loch Rob MerkovskySteve Morics Asuman Oktac Vrunda PrabhuKeith Schwingendorf

    Many students and faculty have used these materials and have helped usto refine their intent and presentation. Those members of RUMEC who haveimplemented some or all of these sections are Ilana Arnon, Julie Clark, SergioLoch, Steve Morics, Keith Schwingendorf, and Kirk Weller. Our specialthanks go to the brave faculty who are implementing this approach and itsmaterials from beyond RUMEC. They and their students will guide us intaking this preliminary version to its next level.

    Robert Acar University of Puerto Rico-Mayaguez

    Felix Almendra Arao Unidad Profesional Interdisplinaria en Ingenieriay Tecnologias Avanzadas, Mexico

  • 7/29/2019 Aprendendo AL Com ISETL

    6/400

    vi

  • 7/29/2019 Aprendendo AL Com ISETL

    7/400

    v

    Contents

    Preface v

    1 Functions and Structures 11.1 Introduction to ISETL . . . . . . . . . . . . . . . . . . . . . . 2

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    Getting Started . . . . . . . . . . . . . . . . . . . . . . 8Simple Objects and Operations . . . . . . . . . . . . . 10

    Modular arithmetic. . . . . . . . . . . . . . . . . 10Variables. . . . . . . . . . . . . . . . . . . . . . 11Boolean. . . . . . . . . . . . . . . . . . . . . . . 11

    Control Statements . . . . . . . . . . . . . . . . . . . . 12if

    statements. . . . . . . . . . . . . . . . . . . . 12for loops. . . . . . . . . . . . . . . . . . . . . . 13Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    1.2 Structures and Operations . . . . . . . . . . . . . . . . . . . . 19Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Tuple and Set Formers . . . . . . . . . . . . . . . . . . 25Set Operations . . . . . . . . . . . . . . . . . . . . . . 26Tuple and Set Operations . . . . . . . . . . . . . . . . 27

    Sets of Tuples . . . . . . . . . . . . . . . . . . . . . . . 27Quantification . . . . . . . . . . . . . . . . . . . . . . . 28Modular Arithmetic . . . . . . . . . . . . . . . . . . . 29

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

  • 7/29/2019 Aprendendo AL Com ISETL

    8/400

    viii

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Funcs and Their Syntax Options . . . . . . . . . . . . 42Funcs for Binary Operations . . . . . . . . . . . . . . . 43Funcs to Test Properties . . . . . . . . . . . . . . . . . 44Tuples and Smaps . . . . . . . . . . . . . . . . . . . . 45Procs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45The Fields Zp . . . . . . . . . . . . . . . . . . . . . . . 46Polynomials and Polynomial Functions . . . . . . . . . 47

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    2 Vectors and Vector Spaces 51

    2.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

    2.2 Introduction to Vector Spaces . . . . . . . . . . . . . . . . . . 60Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

    Finite Vector Spaces . . . . . . . . . . . . . . . . . . . 64Infinite Vector Spaces . . . . . . . . . . . . . . . . . . . 67Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 69

    Basic Properties of Vector Spaces . . . . . . . . . . . . 70name vector space . . . . . . . . . . . . . . . . . . . . 71Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

    2.3 Subspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

    Determination of Subspaces . . . . . . . . . . . . . . . 76Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 78

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

    3 First Look at Systems 81

    3.1 Systems of Equations . . . . . . . . . . . . . . . . . . . . . . . 82Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

    Algebraic Expressions and Linear Equations . . . . . . 86Forms of Solution Sets . . . . . . . . . . . . . . . . . . 89

  • 7/29/2019 Aprendendo AL Com ISETL

    9/400

    Systems of Linear Equations . . . . . . . . . . . . . . . 92

    Summarizing the Process for Finding the Solution of aSystems of Equations . . . . . . . . . . . . . . 98Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

    3.2 Solving Systems Using Augmented Matrices . . . . . . . . . . 109Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

    Using Augmented Matrices . . . . . . . . . . . . . . . . 113Summarizing the Process for Finding the Solution of

    a System of Equations Using an AugmentedMatrix . . . . . . . . . . . . . . . . . . . . . . 120

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

    3.3 A Geometric View of Systems . . . . . . . . . . . . . . . . . . 130Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

    Equations in Two Unknowns . . . . . . . . . . . . . . . 137Equations in Three Unknowns . . . . . . . . . . . . . . 140Systems of Three Equations in Three Unknowns . . . . 142

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

    4 Linearity and Span 1474.1 Linear Combinations . . . . . . . . . . . . . . . . . . . . . . . 148

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

    The Difference Between a Set and a Sequence . . . . . 152Forming Linear Combinations . . . . . . . . . . . . . . 153Simplified Single-Vector Representations . . . . . . . . 154Geometric Representation . . . . . . . . . . . . . . . . 155Vectors Generated by a Set of VectorsSpan . . . . . 161What Vectors Can You Get from Linear Combinations? 162Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 163

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1644.2 Linear Independence . . . . . . . . . . . . . . . . . . . . . . . 168

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

    Definition of Linear Independent and Linear Dependent 172Geometric Interpretation/Generating Sets . . . . . . . 177Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 180

  • 7/29/2019 Aprendendo AL Com ISETL

    10/400

    x

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

    4.3 Generating Sets and Linear Independence . . . . . . . . . . . 185Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

    Generating Sets and Their Spans . . . . . . . . . . . . 188Constructing Linearly Independent Generating Sets . . 190Properties of Linear Independence and Linear Depen-

    dence . . . . . . . . . . . . . . . . . . . . . . 191Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 193

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1934.4 Bases and Dimension . . . . . . . . . . . . . . . . . . . . . . . 197

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

    Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Summation Notation . . . . . . . . . . . . . . . . . . . 200Bases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202Expansion of a Vector with respect to a Basis. . . . . . 205

    Representation of a vector space as Kn. . . . . . 205Finding a Basis . . . . . . . . . . . . . . . . . . . . . . 206

    Finite dimensional vector spaces. . . . . . . . . 206Characterizations of bases. . . . . . . . . . . . . 207

    Dimension . . . . . . . . . . . . . . . . . . . . . . . . . 207Dimensions of Euclidean spaces. . . . . . . . . . 210

    Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 211Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

    5 Linear Transformations 2175.1 Introduction to Linear Transformations . . . . . . . . . . . . . 218

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

    Functions between Vector Spaces . . . . . . . . . . . . 222Definition and Significance of Linear Transformations . 223Component Functions and Linear Transformations . . . 230Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 232

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2335.2 Kernel and Range . . . . . . . . . . . . . . . . . . . . . . . . . 238

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

    The Kernel of a Linear Transformation . . . . . . . . . 240

  • 7/29/2019 Aprendendo AL Com ISETL

    11/400

    x

    The Image Space of a Linear Transformation . . . . . . 244

    Bases for the Kernel and Image Space . . . . . . . . . 245The General Form of a System of Linear Equations . . 252Non-Tuple Vector Spaces . . . . . . . . . . . . . . . . . 256

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2565.3 New Constructions from Old . . . . . . . . . . . . . . . . . . . 263

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

    Scalar Multiple of a Linear Transformation . . . . . . . 268The Sum of Two Linear Transformations . . . . . . . . 270Equality of Linear Transformations . . . . . . . . . . . 271A Set of Linear Transformations as a Vector Space . . 271

    Creating New Linear Transformations . . . . . . . . . . 272Compositions of Linear Transformations . . . . . . . . 273

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

    6 Systems, Transformations and Matrices 2816.1 Vector Spaces of Matrices . . . . . . . . . . . . . . . . . . . . 282

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

    Vector Spaces of Matrices . . . . . . . . . . . . . . . . 284Subspaces of Matrices . . . . . . . . . . . . . . . . . . 286Summation Notation . . . . . . . . . . . . . . . . . . . 287Dimensions of Matrix Vector Spaces . . . . . . . . . . . 288Linear Transformations of Matrices . . . . . . . . . . . 289

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2906.2 Transformations and Matrices . . . . . . . . . . . . . . . . . . 293

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298

    The Rank of a Matrix . . . . . . . . . . . . . . . . . . 298The Matrix of a Linear Transformation . . . . . . . . . 301Properties of Matrix Representations . . . . . . . . . . 303Retrospection . . . . . . . . . . . . . . . . . . . . . . . 305

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3056.3 Matrix Multiplication . . . . . . . . . . . . . . . . . . . . . . . 311

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315

    Matrix Multiplication . . . . . . . . . . . . . . . . . . . 315

  • 7/29/2019 Aprendendo AL Com ISETL

    12/400

    xii

    Multiplication as Composition . . . . . . . . . . . . . . 318

    Invertible Matrices and Change of Bases . . . . . . . . 320Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3256.4 Determinants . . . . . . . . . . . . . . . . . . . . . . . . . . . 331

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333

    7 Getting to Second Bases 3357.1 Change of Basis . . . . . . . . . . . . . . . . . . . . . . . . . . 336

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339

    Coordinate Vectors . . . . . . . . . . . . . . . . . . . . 339Alias and alibi. . . . . . . . . . . . . . . . . . . 343

    Matrix Representations . . . . . . . . . . . . . . . . . . 344Matrices with Special Forms . . . . . . . . . . . . . . . 347

    Triangular matrices. . . . . . . . . . . . . . . . . 348Diagonal matrices. . . . . . . . . . . . . . . . . 349

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3527.2 Eigenvalues and Eigenvectors . . . . . . . . . . . . . . . . . . 357

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358

    Basic Ideas . . . . . . . . . . . . . . . . . . . . . . . . 358Bases of Eigenvectors . . . . . . . . . . . . . . . . . . . 360What Can Happen? . . . . . . . . . . . . . . . . . . . 364

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3657.3 Diagonalization and Applications . . . . . . . . . . . . . . . . 370

    Activities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373

    Relationship between Diagonalizability and Eigenvalues 373Conditions that Guarantee Diagonalizability . . . . . . 375A Procedure Diagonalizing a Transformation . . . . . . 379Using Diagonalization to Solve a System of Differential

    Equations . . . . . . . . . . . . . . . . . . . . 381Markov Chains . . . . . . . . . . . . . . . . . . . . . . 384

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386

  • 7/29/2019 Aprendendo AL Com ISETL

    13/400

    Chapter 1

    Functions and Structures

    ISETL is a Mathematical Programing Language.Before you run away, the emphasis is on theMathematical aspects. ISETL is a tool forconstructing mathematics using a computer.However it is a language for programing the

    computer, so you will need to learn somecommands and syntax. This chapter assumes noprior knowledge of ISETL or of programing. Itgets you started in a gentle manner and sets youon your way to learn linear algebra. Rest assuredthat you will be learning plenty of linear algebrain this chapter, too.

  • 7/29/2019 Aprendendo AL Com ISETL

    14/400

    2

    1.1 Introduction to ISETL

    Activities

    1. Use the documentation provided for your computer to make sure thatyou can answer the following questions.

    (a) How do you turn the computer on?

    (b) How do you turn the computer off?

    (c) How do you enter information? From the keyboard? A mouse?Disks?

    (d) How do you move around the screen? With keys? A mouse?

    (e) How do you make files, and how are they organized?

    (f) How do you save, back-up or discard files?

    2. Use the documentation provided for ISETL to make sure that you cananswer the following questions.

    (a) How do you start an ISETL session?

    (b) How do you end an ISETL session?

    (c) How do you enter information to the system by typing directly?

    (d) How do you transfer information from a file to the system?

    (e) How do you make changes, correct errors, add or delete material?

    (f) How do you save the work that you do in a session?

    (g) How do you print from a file or windows?

    3. Following is data that can appear on the screen when you are in ISETL.The code on a line beginning with a > or >> prompt must be entered byyou. (The symbols > or >> are ISETL prompts. You do not enter theprompt; ISETL will provide it for you.) The end of such a line indicates

    that you should press Return or Enter. The other lines are put onthe screen by ISETL.

    Start ISETL and operate interactively to enter the appropriate linesand obtain the indicated responses (note that the number of decimalplaces may vary).

  • 7/29/2019 Aprendendo AL Com ISETL

    15/400

    1.1 Introduction to ISETL

    >

    > $NUMBERS>

    > 7 + 18;

    25;

    > 13 * (-233.8);

    -3039.400;

    > 170

    >> + 237 - 460

    >> * 2

    >> ;

    -513;

    > 3 + 2; 2 +5;

    >> 1;

    3;

    > 3 + $this is a comment

    >> 2;

    5;

    > 9/3;

    3.000;

    > 9/4;

    2.250;> 9/0;

    !Error: Divide by zero

    > 3 ** 2;

    9

    > 3**(1.2);

    3.737;

    > 9**(1/2);

    3.000;

    > (-1)**(1/2);

    OM;

    >> $VARIABLES

    >

    > x := 2;

    > x;

  • 7/29/2019 Aprendendo AL Com ISETL

    16/400

    4 CHAPTER 1. FUNCTIONS AND STRUCTURES

    2;

    > X;OM;

    > a := 1; b := 2; a := b; b := a;

    > a; b;

    2;

    2;

    >

    > $BOOLEANS

    >

    > 6 = 2 * 3;

    true;

    > 5 >= 2* 3;false;

    > is_integer(3/2);

    false;

    > is_integer(9/3);

    true;

    > is_integer(4.00);

    true;

    > x := 2;

    > x < 3 and x > 1;

    true;> x > 2 and x < 2;

    false;

    > x < 0 or x > 1;

    true;

    > x < 1 impl x > 3;

    true;

    > not true and false;

    false;

    > not (true and false);

    true;

    >> $IF

    >

    > x := 2;

    > if x > 2 then

  • 7/29/2019 Aprendendo AL Com ISETL

    17/400

    1.1 Introduction to ISETL

    >> write "x is larger than 2";

    >> else>> write "x is 2 or smaller";

    >> end if;

    x is 2 or smaller

    > x := 4;

    > if x > 2 then

    >> write "x is larger than 2";

    >> elseif x > 3 then

    >> write "x is larger than 3";

    >> end if;

    x is larger than 2

    > if x > 2 then

    >> write "x is in (2, infinity)";

    >> elseif x > 1 then

    >> write "x is in (1, 2]";

    >> elseif x > 0 then

    >> write "x is in (0, 1]";

    >> else

    >> write "x is in (-infinity, 0]";

    >> end if;x is in (2, infinity)

    > x := 1;

    > if x > 2 then

    >> write "x is in (2, infinity)";

    >> elseif x > 1 then

    >> write "x is in (1, 2]";

    >> elseif x > 0 then

    >> write "x is in (0, 1]";

    >> else

    >> write "x is in (-infinity, 0]";>> end if;

    x is in (0, 1]

  • 7/29/2019 Aprendendo AL Com ISETL

    18/400

    6 CHAPTER 1. FUNCTIONS AND STRUCTURES

    > $FOR LOOPS

    > S := {2..6};> y := 1;

    > for x in S do

    >> y := x * y;

    >> end for;

    > y;

    720;

    > S := {1..3};

    > a := 0;

    > for x, y in S do

    >> a := a + x + y;

    >> end for;> a;

    36;

    4. In parts (a)(g), you will be asked to work with code involving modulararithmetic. Modular arithmetic will be used throughout this course.

    (a) Following is a list of items for you to enter into ISETL. Beforeentering, guess and write down what the response in ISETL willbe. In any case where the response is different from what youpredicted, try to understand why.

    > 5 mod 5;

    > 7 mod 5;

    > 7 mod 7;

    > 3 mod 5;

    > (2 + 3) mod 5;

    > -2 mod 5;

    (b) Do you understand the meaning of the operation mod? Write anexplanation of this operation.

    (c) There are several ways to visualize the operation mod. We shallstart with one method of visualization, and present another laterin the chapter.

    To draw numbers mod 7 (here 7 is the right operand) draw anumber line and mark 0 and consecutive multiples of 7 (both

  • 7/29/2019 Aprendendo AL Com ISETL

    19/400

    1.1 Introduction to ISETL

    negative and positive, on both sides of 0) as long as your page

    permits. Leave reasonable and (approximately) equal distancesbetween every two consecutive multiples. (Why equal distances?)

    Choose any integer n (try first an integer which is not a multipleof 7), which is in the range of your number line.

    Draw your integer approximately on the line. How did you knowwhere to locate n: Between which two multiples of 7? Nearer towhich of the two?

    Shift your integer by multiples of 7 until it reaches within the in-terval [0, 7). The number corresponding to this location of yourshifted integer n is n mod 7. According to the drawing in Fig-

    -21 -14 -7 0 7 14 21

    n = 206 = 20mod7

    Figure 1.1: A number line for mod 7

    ure 1.1, 20 mod 7 = 6. Check this answer in ISETL.

    (d) Choose three more integers n1, n2, n3, among them a multiple of7 and a negative. Locate them also on the number line, shift, andfind ni mod 7. Check your answers in ISETL.

    (e) Following is another list of items for you to enter into ISETL.Before entering, use number lines to predict and write down whatthe response in ISETL will be. In any case where the response isdifferent from what you predicted, try to understand why.

    (f) > 21 mod 7;> (3 + 4) mod 7;

    > 3 = - 4 m o d 7

    > (1 + 6) mod 7

    > 1 = - 6 m o d 7

    > (4 * 2) mod 7;

    > (2 + 5) mod 6;

    > (2 * 5) mod 6;

    > 2/3 mod 6;

    > 2 * 1 = ( 2 * 4 ) m o d 6 ;

  • 7/29/2019 Aprendendo AL Com ISETL

    20/400

    8 CHAPTER 1. FUNCTIONS AND STRUCTURES

    > 2 * 4 = ( 2 * 1 ) m o d 6 ;

    > (2 * 4) mod 6 = (2 * 1) mod 6;(g) What did your number line look like for the last set of ISETL code

    given in (f)? Why?

    5. Following again is a list of items for you to enter into ISETL. Beforeentering, predict and write down what the response in ISETL will be.In any case where the response is different from what you predicted,try to understand why.

    It may be more convenient for you to work with a file and to copy itemsto the screen as you enter them. The specific instructions for doing thiswill vary with the system.

    (a) > b := 10;> b;

    > b + 2 0 ;

    > b : = b - 4 ; b ; B ;

    (b) > (2 /= 3) and ((5.2/3.1) > 0.9);> (3 (3 (3 > 3) impl (3 = 2 + 1);

    > (3 > 3) impl (not (3 = 2 + 1));

    (c) > 7 mod 4; 11 mod 4; -1 mod 4;> (23 + 17) mod 3;

    (d) > a : = O ; b : = 1 ; c : = 2 ; d : = 3 ;> a : = d ; b : = c ; c : = b ; d : = a ;

    > a; b; c; d;

    (e) > is_integer(5); is_integer(-13);> is_integer(6/4); is_integer(6/3);

    Discussion

    Getting Started

    Interaction with ISETL through the execution window follows a simple pat-tern:

  • 7/29/2019 Aprendendo AL Com ISETL

    21/400

    1.1 Introduction to ISETL

    ISETL provides you with a prompt (>);

    You type and edit a line, and end by pressing Return or Enter. (Onceyou type Return or Enter, you cannot edit the line any further. Ifyou attempt to do so, ISETL will not recognize the changes.);

    ISETL reads the line and attempts to execute any complete statementsthat it finds (complete statements end with semi-colons);

    If you have an incomplete statement and press Return or Enter,ISETL provides you with a double prompt (>>) with which to continueyour statement;

    If at the end of the line, you have produced something which cannotbe the start of a correct statement, ISETL returns some funny wordsand tosses out all of your input back to the last complete statement itexecuted;

    The cycle starts again.

    Since statements may be long and you will lose all of the intermediatework if you make an error on a line, it is a good idea to first type the intendedstatements somewhere other than the execution window. ISETL allows you

    to open plain text windows for this purpose. The method for transferringcode from a plain text window to the execution window is dependent uponthe system.

    Another reason to keep your work in a separate window is that ISETLdeletes the contents of the Execution Window when it gets too long. Infact, ISETL may not provide you with any warning until after it has donethis. In order to retain your work, you will need to make it a habit to savethe contents of your Execution Window at regular intervals. Furthermore,you will need to save those contents to a different file each time ISETL hastruncated the text (or you will overwrite the file containing the old text).Note that while it tosses out the contents of the execution window, it does

    not remove the effects of those contents. For example, if you set b to 3 earlyin the session and that line is discarded by ISETL, then b will remain 3 evenafter the window has been truncated.

    Other than commands, there are two different types of instructions thatyou can give to ISETL: directives and comments. Directives adjust the ISETL

  • 7/29/2019 Aprendendo AL Com ISETL

    22/400

    10 CHAPTER 1. FUNCTIONS AND STRUCTURES

    environment and follow a slightly different set of rules than commands. Di-

    rectives always start at the first ! on the line and continue until the end ofthe line. Everything on the line after the directive will be discarded. Com-ments are ignored by ISETL. They start at the first $ on the line and continueuntil the end of the line.

    Simple Objects and Operations

    The first simple object ISETL supports is the symbol OM which means thatthe result of the computation is undefined.

    ISETL supports a number of different types of objects, as well as operatorswhich act on those objects. The most common object for you to manipulate

    in ISETL will probably be numbers. There are three different types of num-bers that ISETL deals with: integers, fractions, and decimals. The specialsymbol OM means that the object is undefined.

    As you would expect, the symbols in ISETL for addition and subtractionare + and -, respectively. In ISETL, multiplication is represented with a*. Placing two numbers next to each other without the * is not supported(you will get an error message about a Bad Mapping or OM). Division is in-dicated by the slash symbol (/). ISETL also supports exponentiation usingthe exponential operator (**).

    Modular arithmetic. One arithmetic operator which you may not havebeen introduced to before is the mod operator. In Activity 4, you were shownhow to use number lines to elaborate mod expressions. You may have realizedthat to elaborate an n mod k expression you need a number line with k-multiples. After locating n between the appropriate k-multiples, you shift nby multiples of k to the interval [0, k). n mod k equals the value of the newlocation of n following the shift into [0, k).

    Is it possible to find n mod k on the number line without shifting n tothe interval [0, k)? Just by locating n between the appropriate k-multiples?Try out some examples of your own to answer this question. Use ISETL tocheck your answers.

    You may have found out that mod corresponds to the distance betweenn and the nearest multiple of k to its left. Namely, mod reduces its leftoperand to the remainder upon division by its right operand: to find 20 mod 7you located 20 between 14 and 21. You can represent 20 as 20 = 2 7 + 6,hence 20 mod 7 = 6. This is the general interpretation of mod: n mod k = r

  • 7/29/2019 Aprendendo AL Com ISETL

    23/400

    1.1 Introduction to ISETL 1

    if and only if there exists an integer a and an integer r, 0 r < k , such thatn = a k + r. Check both the graphical and arithmetic descriptions withexamples of your own. Use ISETL to verify your calculations.

    Variables. In Activity 5, you worked on the code:

    > a : = O ; b : = 1 ; c : = 2 ; d : = 3 ;

    > a : = d ; b : = c ; c : = b ; d : = a ;

    > a; b; c; d;

    Were you surprised by the result of this code? Do you think that this result iswhat the programmer had in mind? Can you guess what was intended? How

    would you make it right? ISETL objects may be named either literally (e.g.,using the symbol 22 to refer to the number twenty-two) or using variables.A variable is a sequence of letters, digits, underscores ( ), carets (^) andprimes () which begins with a letter and is not a reserved word in ISETL.Upper and lower case letters are considered different when determining avariables value and so drat and DrAt refer to different objects. Any objectcan be assigned (or bound) to a variable and this is done in ISETL with theassignment operator (:=). Once this is done, the value of the variable willequal the value of the object. The value of the variable is determined at thetime the variable is assigned and will remain until the variable is explicitlyreassigned.

    Boolean. ISETL also supports boolean values (true and false). Onemeans of generating a boolean value (true and false) is the use of com-parison operators on numbers. These are summarized in the table below:

    operator meaning= equality

    /= inequality< strictly less than

    strictly greater than

    >= greater than or equal

    Boolean values also have their own operators: and, or, not and impl. Thefirst three are fairly clear in meaning. The last one, impl, requires someexplanation. The implication operator is false only when a true statement is

  • 7/29/2019 Aprendendo AL Com ISETL

    24/400

    12 CHAPTER 1. FUNCTIONS AND STRUCTURES

    said to imply a false statement. Based on this, a false statement is said to

    imply either a true statement or a false statement. The other feature of theimpl operator is that it completely evaluates both expressions before testingthe implication. This means that a statement like

    x < 1 impl x > 3

    is only tested for the particular value of x at the time of the test. In thiscase, if x were the value 2, then the truth value of the statement above wouldbe true. As a result, the ISETL statement does not have the same meaningas the statement if x < 1 then x > 3, where x is implicitly assumed to beany possible number. The impl operator is most useful where the variable

    ranges over all possible values of a particular set. The code to do this willbe discussed in the next section.

    Control Statements

    Control statements allow you to direct activities in ISETL. Here we will learnto work with if and for statements.

    if statements. An if statement consists of a sequence of branches. Eachbranch consists of a condition and a statement block. ISETL will test eachcondition until it finds one which is true, and it will execute the statement

    block associated with that condition. The first branch is indicated with anif condition then construction, and later branches are indicated with anelseif condition then construction. A final branch can be indicated by anelse construction, and it will be executed if no other branch is executed.

    The order of the branches may be important since only the block asso-ciated to the first matching (true) condition will be executed. This meansthat while the following is a valid statement in ISETL, it is unlikely that itdoes what the writer intended:

    > if x > 2 then

    >> write "x is larger than 2";

    >> elseif x > 3 then>> write "x is larger than 3";

    >> end if;

    A more complex example was given in Activity 3:

  • 7/29/2019 Aprendendo AL Com ISETL

    25/400

    1.1 Introduction to ISETL 1

    > if x > 2 then

    >> write "x is in (2, infinity)";>> elseif x > 1 then

    >> write "x is in (1, 2]";

    >> elseif x > 0 then

    >> write "x is in (0, 1]";

    >> else

    >> write "x is in (-infinity, 0]";

    >> end if;

    The general structure of an if statement code is:

    > if (boolean expression) then

    >> (statements)

    >> elseif (boolean expression) then

    >> (statements)

    > end if;

    for loops. A for loop is used to repeat execution of a list of statements afixed number of times. A for loop begins with the key word for followed by

    an iterator. An iterator is a domain specification of one or more variables ina tuple or set. (You will see how tuples and sets work in the next section.)In Activity 3 you elaborated the code

    > S := {1..3};

    > a := 0;

    > for x, y in S do

    >> a := a + x + y;

    >> end for;

    > a;

    In this example, when the two variables are iterated over the set S, ISETLselects a value ofx and then iterates over all of the values for y. Then a secondvalue for x is selected and ISETL iterates again over all values for y. This isrepeated for each value of x. One possible order of selection might produce

  • 7/29/2019 Aprendendo AL Com ISETL

    26/400

    14 CHAPTER 1. FUNCTIONS AND STRUCTURES

    the following solution:

    a = 0 + 1 + 1 = 2

    a = 2 + 1 + 2 = 5

    a = 5 + 1 + 3 = 9

    a = 9 + 2 + 1 = 12

    a = 12 + 2 + 2 = 16

    a = 16 + 2 + 3 = 21

    a = 21 + 3 + 1 = 25

    a = 25 + 3 + 2 = 30

    a = 30 + 3 + 3 = 36.Hence the output of this code is 36. After the iterator, the for loop has thekeyword do, followed by a list of commands (the last example consists of butone command: a := a + x + y).

    A code of a for loop structure is completed by the keyword end for.The general structure of a for loop code is:

    > for (variables) in (tuple or set) do

    >> (statements)

    >> end for;

    Exercises

    1. In your own words, write out explanations for each of the followingterms. Note that anything here which is in typewriter font is con-sidered to be an ISETL keyword.

    (a) prompt

    (b) true

    (c) om

    (d) mod

    (e) boolean

    (f) if statement

    (g) for loop

  • 7/29/2019 Aprendendo AL Com ISETL

    27/400

    1.1 Introduction to ISETL 1

    (h) input

    (i) objects

    (j) operations

    (k) ;

    (l) impl

    2. Read the following code, and follow the instructions and/or answer thequestions listed after the code.

    rp := om;

    x := 12;y := 18;

    if is_integer(x) and is_integer(y) and x > 0 and y > 0

    then rp := true;

    for i in [2..min(x, y)] do

    if (x mod i = 0) and (y mod i = 0) then

    rp := false;

    end;

    end;

    end;

    x; y; rp;

    (a) Run the code several times, with different initial values for x, y.

    (b) In your own words, write out an explanation of what this codedoes. In particular, explain how the code gets data to work on,what it does with the data, and what is the meaning of the result.

    (c) Place this code in an external file. Exit ISETL and then re-enterISETL to run this code without retyping it.

    (d) What does it mean to say that this code tests its input?

    (e) Suppose that you run this code and that the value of y you enteris always twice the value of x. Can you be sure of what the valueof rp will be? Why?

    (f) Add a statement to the code that will display a meaningful an-nouncement about the result.

  • 7/29/2019 Aprendendo AL Com ISETL

    28/400

    16 CHAPTER 1. FUNCTIONS AND STRUCTURES

    (g) List some relationships between the values of x and y for which

    you can always be sure of the value of rp at the end.(h) Suppose that values a, b for x, y result in rp having the value

    true. Suppose that this is still the case for values b, c for x, y.What will happen if you give x, y the values a, c?

    3. Look at each of the following sets of ISETL code. Predict what will bethe result if the code is entered. Then enter it and note if you wereright or wrong. In either case, explain why.

    12 div 4; 12 div 5; 12 div -5; -12 div 5; -12 div -4;

    12 div 0;12 mod 4; 9 mod 4; 6 mod 4; 3 mod 4; -2 mod 4;

    -4 mod 4; -7 mod 4;

    2 = 3; (4 + 5) /= -123; (12 mod 4) >= (12 div 4);

    even(2**14); odd(187965*45);

    max(-27, 27); min(-27, max(27, -27));

    abs(min(-10, 12) - max(-10, 12));

    4. Write a for loop which adds up all the numbers between 1 and 100.

    5. Find the value of x mod 6 for x = - 7, -6, ... 6, 7.

    6. Describe all possible integer values of a for which a m o d 6 = 0.

    7. Describe all possible integer values of b for which b m o d 6 = 4.

    8. The following is another visualization of the operator mod . Choose aninteger k between 5 and 20. Like a number line with k-multiples, thefollowing drawing will serve as a representation of mod k.

    Draw a circle and mark on it k arbitrary points, in (approximately)equal distances. Write next to one of the points, outside the circle, the

    number 0. Continue labeling the other points, moving in a constantdirection (clockwise or counter-clockwise), writing each consecutive in-teger in its turn next to the following point. After k steps you willwrite the number k next to the point 0, behind it. An example of adrawing for mod k, with k = 7, is given in Figure 1.2.

  • 7/29/2019 Aprendendo AL Com ISETL

    29/400

    1.1 Introduction to ISETL 1

    0

    1

    2

    34

    5

    6

    7

    Figure 1.2: A circular representation

    Continue writing numbers for at least two tours around the circle. Canyou describe the numbers that accumulate behind a specific point?Could you continue the list of numbers behind a particular point with-out moving all the way around the circle? Could you write a mathe-matical (algebraic) description of the set of the numbers for a specificpoint?

    Choose a point on your circle, and write an ISETL code which constructsthe set of the numbers of this point up to 100. Compare the output of

    this code with the numbers you have written in your drawing.

    9. Look at each of the following sets of ISETL code. Predict what will bethe result if the code is entered. Then enter it and note if you wereright or wrong. In either case, explain why.

    (a) n := 58; (n div 3) * 3 + n mod 3;

    (b) is integer(-1020.0) and is integer(-1020);

    (c) true impl true; true impl false; false impl true;false impl false;

    (d) (23 + 5) mod 7 = 0 impl 7 mod 7 = 1;(e) (1 + 6) mod 7 = 0 impl (1 + 5) mod 6 = 0;

    (f) (23 + 5) mod 7 = 1 impl -70 mod 7 = 1;

    (g) (2 + 3) mod 5 = 0 and (2 * 3) mod 5 = 1;

  • 7/29/2019 Aprendendo AL Com ISETL

    30/400

    18 CHAPTER 1. FUNCTIONS AND STRUCTURES

    10. Write ISETL code that will run through all of the integers from 1 to 50

    and, each time the integer is even, will write out its square.

    11. Change your code in the previous problem so that instead of even inte-gers, it will write out the square each time the integer gives a remainderof 3 when divided by 7.

    12. Use ISETL to determine the larger of the fractions 23

    + 89

    , 45

    + 67

    Do yousee a pattern in the choice of the four fractions? Run several variationsof the pattern and see if you can find a general rule.

  • 7/29/2019 Aprendendo AL Com ISETL

    31/400

    1

    1.2 Structures and Operations

    Activities

    1. Following is a list of items for you to enter into ISETL. Before entering,guess and write down what the response of ISETL will be. In case theresponse is different from your prediction, try to understand why.

    T1 := [0..19]; T1;

    T2 := [0, 2..19]; T2;

    T3 := [2, 8..21]; T3;

    T4 := [3, -5, 1];T5 :=[2**i + 1 : i in [0..4]]; T5;

    T1(5); T2(5); T3(5);

    T4(3); T4(1); T5(1);

    T3(8);

    #T1; #T2; #T3; #T4; #T5;

    U:=[1, 2, T2, 3 < 2, [3.5, -100]];

    U(7); #U; U(5); U(5)(2);

    2 in U; false in U; -100 in U; -100 in U(5);

    Z20 := {0..19};

    T1; T1; T1; T1;

    Z20; Z20; Z20; Z20;

    T1(5); Z20(5);

    E := [2, 1 > 2, [1, 2]]; E1 := [1 > 2, 2, [1, 2]];

    E2 := [2, 1 > 2, [1, 2], 2];

    E = E1; E = E2; E1 = E2;

    F := {2, 1 > 2, [1, 2]}; F1 := {1 > 2, 2, [1, 2]};F2 := {2, 1 > 2, [1, 2], 2};

    F = F1; F = F2; F1 = F2;

    N := {O, 1, {0, 1}}; R := [0, 1, {0, 1}];

    N = R ;

  • 7/29/2019 Aprendendo AL Com ISETL

    32/400

    20 CHAPTER 1. FUNCTIONS AND STRUCTURES

    B := [1, 2, 1, 3, 1, 4];

    C := {1, 2, 1, 3, 1, 4};#B; #C; B; B; B; C; C; C;

    K1 := {1, 3, 2} with 5;

    #K1; K1;

    L1 := [1, 3, 2] with 5;

    #L1; L1;

    K2 := {1, 3, 2} with 3;

    #K2; K2; K2; K2;

    L2 := [1, 3, 2] with 3;

    #L2; L2; L2; L2;

    2. Write a few paragraphs describing your experience with Activity 1.What did you predict? What happened? How do you explain whatISETL did? Rather than just reporting events in chronological order,try to organize your description in some logical order and suggest gener-alizations. Include a description of the main differences between using[..] (which constructs a tuple or sequence) and {..} (which constructsa set).

    3. Write out a verbal explanation of the result of giving each of the fol-

    lowing input lines to ISETL.

    p := [1, 1, 0]; q := [1, 0, 1];

    r := [(p(i) + q(i)) mod 2 : i in [1..3]]; r;

    s := [1, 2, 0];

    s1 := [(3 * s(i)) mod 5 : i in [1..3]]; s1;

    G := {[a, b, c] : a, b, c in [0, 2, 4]};

    H := {[a, b, c] : a, b, c in [1, 3]};

    K := {[a, b, c] : a, b, c in [1..3]};

    H union K; H union G; K union G;K inter H; H inter G;

    H subset K; G subset H;

    Z20 := {0..19};

  • 7/29/2019 Aprendendo AL Com ISETL

    33/400

    1.2 Structures and Operations 2

    L := {g * h : g, h in Z20 | even(g) and h < 10};

    L1 := {g * h : g, h in Z20 | even(g)};L1 subset L; L subset L1;

    Z20 - {0}; 0 in Z20; 0 in Z20 - {0};

    S := pow({0, 1, 2, 3}); {0, 1} in S; {} in S;

    arb(Z20); arb(Z20); arb(Z20); arb(Z20);

    %+[1..10]; %*[l..6]; %or[2=1, 2=2, 2=3, 2=4];

    %+{1..10}; %*{l..6}; %or{2=1, 2=2, 2=3, 2=4};

    4. (a) Let Z2 3 be the set of all the 3-tuples (tuples with 3 elements)with elements in {1, 2}. How many elements are there in Z2 3?

    (b) Write ISETL code that constructs Z2 3, and use it to check yourconjecture.

    5. Write out a verbal explanation of the result of giving each of the fol-lowing input lines to ISETL.

    Z20 := {0..19};

    Z2_3 := {[a,b,c] : a,b,c in [0,1]}; Z2_3;

    forall x in Z20 | (x + 0) mod 20 = x;

    forall x in Z20 | (x + 3) mod 20 = x;

    exists p in Z2_3 | p(l) < p(2);

    exists p in Z2_3 | p(l) = p(2);

    exists e in Z20 | (forall g in Z20 | (e + g) mod 20 = g);

    forall g in Z20 | (exists g in Z20 |

    (g + g) mod 20 = 0);

    forall p, q in Z2_3 |

    [(p(i) + q(i)) mod 2 : i in [1..3]] in Z2_3;

    choose e in Z20 | (forall g in Z20 | (e + g) mod 20 = g);

    e := choose x in Z20 |(forall g in Z20 | (x + g) mod 20 = g); e;

    6. Write out a verbal explanation of the result of giving each of the fol-lowing input lines to ISETL.

  • 7/29/2019 Aprendendo AL Com ISETL

    34/400

    22 CHAPTER 1. FUNCTIONS AND STRUCTURES

    Z5 := {a mod 5 : a in [-30..50]};

    A := {a mod 5 : a in [-100..100]};#Z5; #A; A = Z5;

    C := {c : c in Z5 | (exists d in Z5 | (c + d) mod 5 = 0)};

    C;

    G := {g : g in Z5 | (exists d in Z5 | (g * d) mod 5 = 1)};

    G;

    C = Z5; G = Z5; G = Z 5 - {0}; # G;

    forall a in Z5 | (exists d in Z5 | (a + d) mod 5=0);

    forall a in Z5 | (exists d in Z5 | (a * d) mod 5=1);

    Z6 := {a mod 6 : a in [-100..100]}; Z6; #Z6;

    M := {m : m in Z6 | (exists d in Z6 | (m + d) mod 6 = 0)};

    M;

    N := {n : n in Z6 | (exists d in Z6 | (n * d) mod 6 = 1)};

    N;

    M = Z6; N = Z6; N = Z6 - {0};

    forall a in Z6 | (exists d in Z6 | (a + d) mod 6 = 0);

    forall a in Z6 | (exists d in Z6 | (a * d) mod 6 = 1);

    Z7 := {g mod 7 : g in [-50..50]}; Z7;

    K := {(5 * g) mod 7 : g in Z7}; K;

    H := {(2 * g) mod 7 : g in Z7}; H;

    Z5 := {g mod 5 : g in [-50..50]}; Z5;

    K1 := {(3 * g) mod 5 : g in Z5}; K1;

    H1 := {(2 * g) mod 5 : g in Z5}; H1;

    Z20 := {g mod 20 : g in [-50..50]}; Z20;

    K2 := {(5 * g) mod 20 : g in Z20}; K2;

    H2 := {(2 * g) mod 20 : g in Z20}; H2;

    Z6 := {0..5};

    K3 := {(5 * g) mod 6 : g in Z6}; K3;H3 := {(4 * g) mod 6 : g in Z6}; H3;

    7. Write ISETL code that will construct the following sets. Run your codeto check that it is correct.

  • 7/29/2019 Aprendendo AL Com ISETL

    35/400

    1.2 Structures and Operations 2

    (a) The set of all integers from 1 to 1000 whose squares mod 20 are

    greater than 14.(b) The set Z2 4 of all 4-tuples (tuples with four elements) with entries

    from Z2.

    (c) The set of all sums of the tuple p with the tuple qwhere p, qrunthrough all elements of Z2 3.

    (d) The set of all elements of the form [[x, y], (x + y) mod 6]where x, y run through all the elements of Z6.

    8. Write ISETL code that will test the truth or falsity of the followingstatements. Run your code to check that it is correct.

    (a) Every element of Z20 is even.

    (b) Every element of Z2 3 is a tuple.

    (c) Some element of Z20 is a tuple.

    (d) Some elements of Z20 are odd.

    (e) The product mod 20 of every pair of elements of Z20 - {0} isagain in Z20 - {0}.

    (f) Every element of Z20 has a corresponding element which whenadded to it mod 20 gives the result 0.

    (g) There is an element of Z20 which when added to any element ofZ20 does not change it.

    Discussion

    Tuples

    The ISETL object called tuple is used to represent a finite sequence. In Activ-ity 1, the code for T1 yields the sequence given by the first 19 whole numbers.

    Similarly, [-30..50] would yield the sequence of consecutive integers whosefirst term is 30 and whose last term is 50. In general, any tuple givenby [a..b], where a and b are integers and b > a, will yield a consecutivesequence of integers that begins with a and ends with b. What happens ifb < a?

  • 7/29/2019 Aprendendo AL Com ISETL

    36/400

    24 CHAPTER 1. FUNCTIONS AND STRUCTURES

    T2 in Activity 1 differs from T1 in that the difference between successive

    terms is 2. Upon receiving input such as [4, 7..15], ISETL constructs thesequence [4, 7, 10, 13]. In general, ifa < b < c, with a, b, and c integers,the ISETL tuple [a, b..c] returns an arithmetic sequence with commondifference b a whose first two terms are a and b and whose last term doesnot exceed c. What does ISETL return if a < b < c does not hold?

    How would a decreasing sequence be constructed? Non-arithmetic se-quences can also be constructed by simply listing all of the elements (T4 inActivity 1 is an example) or by using a formula (T5 in Activity 1 is an exam-ple). Of course, arithmetic sequences can also be expressed in either of theseways.

    The components of a tuple do not have to be integers, or even numbers.

    They can be any ISETL objects, including other tuples. U in Activity 1 issuch an example: The first term of this sequence is 1, the second is 2, thethird is the tuple T2, the fourth is the proposition 3 < 2, and the fifth is thetuple whose elements are the numbers 3.5 and 100.

    One of the most important facts about tuples is that their elements comein a fixed, definite order. Each time you evaluate a tuple, you get the samesequence in the same order. This should not be surprising, since a sequenceis a function whose domain is the set of integers: the output correspondingto the integer 1 is the first element of the sequence, the output correspondingto the integer 2 is the second element of the sequence, and so on. Since tuples

    retain their original ordering, it is possible to access specified components ofa tuple. As you discovered in Activity 1, the value of the expression T1(5) isthe value of the fifth component of the tuple T1. What would be the valueof the seventh component of U?

    Sets

    The ISETL object set is exactly the same as a finite set in mathematics. Theelements of a set can be any ISETL objects, including other sets, as in theset N of Activity 1. This includes the empty set {}, as in {1, {}, {1,2}}.Sets can also have tuples for elements, as in Z2 3 of Activities 4 and 5. Sets

    can also be elements of tuples. Can you construct such an example?As with tuples, a code of the form {a .. b}; returns the set of consec-

    utive integers starting with a and ending with b, provided that a and b areintegers and a < b. Ifb < a, then ISETL will return the empty set. Similarly,ifa, b and c are integers and a < b < c, the set {a, b..c}; will return a and

  • 7/29/2019 Aprendendo AL Com ISETL

    37/400

    1.2 Structures and Operations 2

    b, with subsequent elements obtained by adding the constant difference b asuch that no term exceeds c. What elements are returned if the conditiona < b < c does not hold?

    Sets and tuples differ in two important ways. In a set, order and repetitiondo not matter, while the opposite is true for tuples. For instance, the set{1, 2, 3} is equal to any set consisting of any permutation of the elements1, 2, and 3. For example, {1, 2, 3} = {2, 3, 1} . On the other hand, thetuple, or sequence, [1, 2, 3] is not equal to the tuple [3, 2, 1]. This is what youdiscovered in Activity 1: the terms of the tuple T1 are always presented inthe order in which they were entered. This is not the case with the set Z20;ISETL lists the elements of Z20 in varying order.

    Repetition, like order, is a second distinguishing characteristic of se-

    quences. This is why the sequences E and E2 in Activity 1 are not equal.However, when the elements of E and E2 were entered as sets, to produceF and F2, the result was different: You had found that F = F 2 is true. Re-peated elements of a set are disregarded: When one uses the code #, withwhich ISETL produces the number of elements, one can see that a repeatedelement in a set is counted but once, while in a tuple it is counted as manytimes as it appears. As a result, tuples and sets react differently to the opera-tion with. What is the difference? Use the results you obtained in Activity 1to explain this difference.

    Tuple and Set FormersIn addition to defining sets and sequences by listing their elements or terms,the set and tuple objects can be defined using former notation. In Activity 3,the sets Z20, H, K, L, HK and S are all defined using set-former notation.Whether a set or a tuple, the former has three parts. The first is an expres-sion. Every variable that appears in the expression must either have beenassigned values previously or appear in the second part of the former. Thefirst part of the former is completed with a colon (:). The second part, calledthe domain specification, takes unassigned variables in the expression anditerates them through previously defined sets or tuples. For the set HK :=

    {6 * n : n in [1..5]}, the first part of the former is the expression 6 *n, and the second part indicates that n is an element of the tuple [1..5].Although it is not necessary for every variable that appears in the domainspecifier to appear in the expression, it is required that every unassignedvariable that appears in the expression must also appear in the domain spec-

  • 7/29/2019 Aprendendo AL Com ISETL

    38/400

    26 CHAPTER 1. FUNCTIONS AND STRUCTURES

    ifier. For example, the tuple r:=[p(i) + q(i) : i in [1..3]] given in

    Activity 3 is the component-wise sum of previously defined tuples p and q.As a result, p and q do not need to appear in the domain specifier. Theindex i is the undefined variable iterating through [1..3]. The last partof the former notation is optional. If present, it begins with the symbol (|)and is followed by a boolean expression, that is, an expression whose value istrue or false. For example, L := {g * h : g, h in Z20 | even(g) andh < 1 0} is the set of all the numbers produced from the expression g * hby substituting all the possible combinations of even elements in Z20 for g,and elements smaller than 10 in G for h.

    When presented with former notation, ISETL constructs the set (or tu-ple) by iterating through all possible combinations of values of the variables

    defined in the domain specification. For each combination of values of thevariables, the boolean expression in the third part is evaluated. If the thirdpart is not present, then the boolean value is automatically assumed to betrue. If the result of evaluating the boolean expression is false, then noth-ing more is done, and ISETL moves on to the next combination of valuesfor the variables. If the boolean expression is true (or not present), thenISETL evaluates the expression and returns the result as an element of theset. Thus, the value of a former expression is the set of all values of theexpression obtained by iterating the variables through their domains suchthat the condition in the third part holds. This is similar to what you were

    asked to do in Activity 7.

    Set Operations

    ISETL can perform usual set operations. You used these operations in Ac-tivity 3. Recall, as you read the following summary, that the convention inthis text is that any word in typewriter font is an ISETL keyword.

    1. The basic idea of a set is that any object is either in the set or it is notin the set. You can test for set membership using the operation in.

    2. The union (union) of two sets A and B is the set of all values which are

    elements of A, B, or both. The intersection (inter) of two sets A and Bis the set of all elements which are contained in both A and B.

    3. A set A is a subset (subset) of a set B if every element of A is also anelement of B.

  • 7/29/2019 Aprendendo AL Com ISETL

    39/400

    1.2 Structures and Operations 2

    4. The difference between two sets A and B (-) is the set of all elements

    which are in A but not in B.

    5. The value in ISETL of {} is the empty setthe set which has no ele-ments.

    6. The cardinality operator (#) applied to a set A returns the number ofelements in A.

    7. The operation pow applied to a set A constructs the set of all subsetsof A. This is called the power set of A, denoted in ISETL by pow(A).

    When the set A is finite, pow(A) can be worked out by first putting into

    it the empty set {}, then all one-element sets consisting of one of theelements of A, then all the possible two-element subsets of A (consistingof two of the elements of A), and so on, until the largest subset of A, theone of greatest cardinality, which is A itself. What is the cardinality ofthe power set of an arbitrary, finite set?

    8. The operation arb selects an arbitrary element of a set.

    Tuple and Set Operations

    In Activity 1, you were introduced to operations applied to tuples. For

    instance the code %+[3..9] tells ISETL to find the sum of the terms ofthe sequence 3, 4, 5, 6, 7, 8, 9. If the addition sign were replaced with amultiplication sign, then ISETL would find the product of the terms of thesequence.

    If the terms of a tuple consist of boolean expressions, that is, statementsthat can be judged to either true or false, code such as %or[3 < 2, 2 > 1,6 = 7 ] instructs ISETL to return the value true if one of the statements istrue. What would the code %and[3 < 2, 2 > 1, 6 = 7] yield?

    Sets of Tuples

    In Activities 4 and 5, you instructed ISETL to construct the set Z2 3. Whenyou typed Z2 3, ISETL returned the set of all possible combinations of 3-tuples (tuples with three components) whose entries were either 0 or 1. Asdiscussed in the previous subsection on sets, the elements of a set in ISETLcan be any ISETL objects, including, as you saw in these activities, tuples.

  • 7/29/2019 Aprendendo AL Com ISETL

    40/400

    28 CHAPTER 1. FUNCTIONS AND STRUCTURES

    There are a variety of ways to represent a set of tuples. One is to simply

    list each tuple given in the set. For example, if A is the set of all 2-tuples(tuples consisting of two components) of all possible two-element orderingsof the first three counting numbers, then we could represent A in ISETL bylisting each element:

    A := {[1, 1], [1, 2], [1, 3], [2, 1], [2, 2],

    [2, 3], [3 ,1], [3, 2], [3, 3]};

    On the other hand, it would be more convenient to use former notation:

    A := {[a, b] : a, b in {1, 2, 3}};

    Whenever defining a set of tuples using former notation, the expression, orfirst part of the set former, will consist of a tuple whose components arevarious expressions. For instance, if we want to define a set B consisting ofall 3-tuples (tuples with three components) of elements of Z20 in which thefirst component is always zero, the second is always even, and the third istwo more than 3 times the second, then, using set former notation, we wouldwrite:

    B := {[0, b, ((3 * b) + 2) mod 20] : b in Z20 | even(b)};

    Tuples will be used frequently throughout the text. Tuples constitute a

    special and important kind of vectors. Vectors are important objects ofstudy in linear algebra. Sets of tuples will often constitute a vector space.A vector space is a set of vectors with two operations that satisfy certainconditions.

    Quantification

    Quantified logical statements are used in mathematics to express conditions,usually in a definition, statement of a property, or a construction. forallinvolves a universal quantifier. In order for a statement involving a universalquantifier to be true, the condition must hold for all possible values of the

    variable attributed to it. exists involves an existential quantifier. In orderfor a statement involving an existential quantifier to be true, only one of thevalues of the variable attributed it has to be true.

    In Activity 5, you were asked to evaluate several statements involvinguniversal quantification. The ISETL statement forall x in Z20 | (x +

  • 7/29/2019 Aprendendo AL Com ISETL

    41/400

    1.2 Structures and Operations 2

    0) mod 20 = x illustrates the standard form of a universal quantifier: the

    first part begins with the key word forall and is followed by a domainspecification. The domain specification is completed with the symbol |. Thesecond part of the quantifying statement is a boolean expression, that is, thecondition that the variable must satisfy.

    To evaluate a universal quantification expression, ISETL iterates throughthe values of the variable in the domain specifier. Thus, in this example,it considers every value of x in the set Z20. For each value, the booleanexpression is evaluated. If the boolean expression is found to be false for

    just one x, then the entire universal quantification statement is false. If theboolean expression is true for every x given by the domain specifier, then thevalue of the quantification is true.

    The existential quantifier is similar, except that it returns true if the valueof the boolean expression is true at least once. Consequently, an existentialquantifier returns false only when the boolean expression is false for everysingle value of the variable.

    The operation choose is a useful alternative to exists. The syntaxis exactly the same, and choose performs the same internal operation asexists. Instead of returning true or false, however, choose will select andsubsequently return one value of the variable that makes the condition true.If there is no such value, choose will return OM. Thus, in the case of thefollowing statement from Activity 5, e := choose x in Z20 | (forall g

    in Z20 | (x + g) mod 20 = g); ISETL will return the value of 0 for e.

    Modular Arithmetic

    In Activity 6 you could see differences between multiplication mod 7 andmod 5 in Z7 and Z5 respectively on the one hand, and multiplication mod 20and mod 6 in Z20 and Z6 respectively on the other hand. These differencescan be seen when comparing these sets

    K := {(5 * g) mod 7 : g in Z7};

    H := {(2 * g) mod 7 : g in Z7};

    K1 := {(3 * g) mod 5 : g in Z5};

    H1 := {(2 * g) mod 5 : g in Z5};

    With the following sets:

    K2 := {(5 * g) mod 20 : g in Z20};

  • 7/29/2019 Aprendendo AL Com ISETL

    42/400

    30 CHAPTER 1. FUNCTIONS AND STRUCTURES

    H2 := {(2 * g) mod 20 : g in Z20};

    K3 := {(5 * g) mod 6 : g in Z6};H3 := {(4 * g) mod 6 : g in Z6};

    What are the differences between them? Notice that H, for example, is asubset of Z7, and is determined by multiplication mod 7. Similarly, each ofthe other sets is a subset of some Zn and determined by multiplication modthat same n. What differences do you see in the relation between these setsand the Zn they are subsets of?

    Exercises

    1. How many elements are there in the following set? Use the # operatorin ISETL to check your answer.

    {2, 3, 6 mod 4, {[1, 1] {-1, 2..5}}, {}};

    2. List the elements in each of the following sets and note the number ofelements in each. Use ISETL to check your answers. If a set is empty,explain why.

    {2..12}

    {4..4}

    {10..1}

    {-2, 4..38}

    {0, 3..-1}

    {100, 90..-5}

    {100, 90..100}

    {100, 90..101}

    {10 ,9..0}

    {4, 4..8}

    3. For each of the following sets of code, predict what result will be re-

    turned by ISETL and then check your answer on the computer.

    T := {[3, 4], 3 + 4, 8};

    7 in T; 4 in T; (1 + 7) in T;

    3 + 5 notin T; 7 notin T;

  • 7/29/2019 Aprendendo AL Com ISETL

    43/400

  • 7/29/2019 Aprendendo AL Com ISETL

    44/400

  • 7/29/2019 Aprendendo AL Com ISETL

    45/400

    1.2 Structures and Operations 3

    (c) Write a verbal description of all the differences you found between

    these tables: Compare the addition tables to the multiplicationtables; Compare the tables of mod 5 (in Z5) to those of mod 6 (inZ6).

    8. Write ISETL set former expressions for each of the following.

    (a) The set of all 3-tuples of elements from a given set of integers K.

    (b) The set of all possible sums of two elements, one taken from agiven set of integers S and one from a given set of integers T.

    (c) The set of all 4-tuples of those elements from a given set of integersK that are even.

    (d) The set of all subsets {a, b} of Z5, for which (a b) mod 5 = 1.(e) The set of all subsets {a, b} of Z5, for which (a + b) mod 5 = 0.(f) The set of all subsets {a, b} of Z6, for which (a b) mod 6 = 1.(g) The set of all subsets {a, b} of Z6, for which (a + b) mod 6 = 0.

    9. Compare the sets you constructed in Exercise 8, parts (d)(g), to thetables you had constructed in Exercise 7.

    10. Assume that S is a set and T is a tuple, both of which have been pre-viously defined in ISETL. Write an ISETL expression that will evaluate

    to a tuple whose components are the elements of S and the set whoseelements are the components of T.

    11. Evaluate the following tuples and then use ISETL to check your answers.

    (a) [x**2 : x in [1, 3..10]];

    (b) [[1..r] : r in [0, 2..6]];

    (c) [N + 2 < 2**N : N in [0..20]];

    (d) [u * v : u in [-5..0], v in [-5..(u + l)] |(u + v) mod 3 = 0];

    12. Use the ISETL forall, exists, and choose constructs to write a codethat implements the following statements. Assume that S is the set ofmultiples of 3 from 0 to 49.

    (a) Every odd number in {0 . . . 50} is in S.

  • 7/29/2019 Aprendendo AL Com ISETL

    46/400

    34 CHAPTER 1. FUNCTIONS AND STRUCTURES

    (b) Every even number in S is divisible by 6.

    (c) It is not the case that every even number in S is divisible by 6.

    (d) There is an odd number in S, which is divisible by 5.

    (e) There is an even number in S, which is divisible by 5.

    (f) There is an element m of S such that the number of elements ofS that are less than m is twice the number of elements of S thatare greater than m.

    (g) An element a ofS exists such that for every element x ofS, thereis an element y of S such that the average of x and y is a.

  • 7/29/2019 Aprendendo AL Com ISETL

    47/400

  • 7/29/2019 Aprendendo AL Com ISETL

    48/400

  • 7/29/2019 Aprendendo AL Com ISETL

    49/400

  • 7/29/2019 Aprendendo AL Com ISETL

    50/400

    38 CHAPTER 1. FUNCTIONS AND STRUCTURES

    Keep the codes you constructed here for future use.

    (c) Repeat Activities 4(a) and 4(b) with Z6. Check the values youobtained with your multiplication-mod-6 table. How are theseresults reflected in this table?

    You may wish to keep these codes as well.

    (d) Write a comparison between the behavior of the functions inv 7and inv 6. How are they similar? How different?

    (e) Repeat Activities 4(a) and 4(b) with Z5. Check the values youobtained with your multiplication-mod-5 table.

    Keep the codes you constructed here for future use.

    (f) What is the function inv 5 like: inv 6 or inv 7? Explain.

    5. Write ISETL funcs with the given names according to each of the follow-ing specifications. In each case, set up specific values for the parametersand run your code to check that it works.

    (a) The func is closed has two input parameters: a set G and afunc o which is some operation on two variables from G such asthe one in Activity 3. The action of is closed is to determinewhether the result of o, when applied to two elements of G, is

    always an element of G. This is indicated by returning the valuetrue or false.

    (b) The func is commutative has two input parameters: a set G anda func o which is some operation on two elements from G such asthe operations in Activity 3. The action of is commutative isto determine whether or not the result of o depends on the orderof the elements. This is indicated by returning the value true orfalse.

    (c) The func identity has two input parameters: a set G and afunc o which is some operation on two variables from G such as

    the operations in Activity 3. The action of identity is to searchfor an element e of G which has the property that for any elementg of G, the result of the operation o applied to e and g is again g.This is indicated by returning the value of e if it exists or OM if itdoes not.

  • 7/29/2019 Aprendendo AL Com ISETL

    51/400

  • 7/29/2019 Aprendendo AL Com ISETL

    52/400

    40 CHAPTER 1. FUNCTIONS AND STRUCTURES

    Write an explanation: What did the expression p(i) do for the

    tuple p? What did the expression s(i) do for the set of tuples s?

    s := s with [1, 5]; s;

    s(3); s(1);

    st := [s(i) : i in [1..4]]; st;

    st(1); st(3);

    (b) next := func(n);if n in [1..10] then return n + 1;

    end;

    end;

    mnext := {[n, n+1] : n in [1..10]};

    mnext;

    next(6); mnext(6); next(9); mnext(9);

    next(11); mnext(11);

    forall n in [0..11] | mnext(n) = next(n);

    (c) G := {1..12};

    o := func(x,y);if (x in G and y in G) then

    return (x * y) mod 13;

    end;

    end;

    m13 := {[[x, y], x .o y] : x, y in G};

    m13;

    m13(3, 5); m13(2, 4);

    3 .m13 5; 2 .m13 4;

    forall x, y in G | x .m13 y = x .o y;

    8. Construct functions of your own, with the following specifications:

    (a) The function takes two tuples for input, and returns a tuple con-sisting of the sum of each pair of their components for output.

  • 7/29/2019 Aprendendo AL Com ISETL

    53/400

    1.3 Functions 4

    (b) The function takes a tuple and a number for input, and returns a

    tuple consisting of the product of the number and each componentof the tuple for output.

    (c) The function takes two tuples and two numbers for input, andreturns a tuple for output. This function should multiply the firstnumber with the first tuple (as in part (b)), multiply the secondnumber and tuple, and then add the results as in part (a).

    9. Describe what the following code is doing.

    SetNot := proc(pair);

    G := pair(1); o := pair(2);e := choose x in G | (forall g in G | x .o g = g);

    inv := {[g, choose g in G | g .o g = e] : g in G};

    end;

    pair := [ ];

    pair(1) := {0..5};

    pair(2) := func(x, y);

    if (x in G and y in G) then

    return (x * y) mod 6;

    end;

    end;

    pair;SetNot(pair);

    G; e; inv(5); inv(2);

    What would happen if, after running this code (and defining the funcsin Activity 5), you entered statements such as 3 . o 5, is closed(G,o), is commutative(G, o), identity(G,o)?

    Can you imagine why we might want to go to all the trouble of some-thing like SetNot?

    10. An ISETL func can also return a func. Look at the following code andwrite down an explanation of what it does:

    add_a := func(a);

    return func(x);

  • 7/29/2019 Aprendendo AL Com ISETL

    54/400

  • 7/29/2019 Aprendendo AL Com ISETL

    55/400

  • 7/29/2019 Aprendendo AL Com ISETL

    56/400

  • 7/29/2019 Aprendendo AL Com ISETL

    57/400

    1.3 Functions 4

    Activity 5(a) for example, had two input parameters, a set G and a binary

    operation o. It was assumed that before you call this func you would havedefined a set and a binary operation. The definition of the func would containa single boolean expression. The value of this expression was returned as theresult of a call to this func. Look back at the funcs you constructed inActivity 5, and write a description of the property that is tested by each ofthe funcs you were asked to construct in this activity.

    Tuples and Smaps

    In Activity 7(b) you compared two ISETL objects: the func next, whichassigns to each number in [1..10] the next larger number, and the set of

    ordered pairs mnext := {[n, n+1] : n in [1..10]}; Hopefully you alsodiscovered that expressions like mnext(6) = next(6) return true.

    In ISETL, an ordered pair is a tuple with only two components defined.A set of pairs is a called a map. The map gives us one more way to representfunctions in ISETLas in mathematics. As you can see in the above example,the way a map represents a function is that it assigns the second componentof each ordered pair to the first component of the same pair. However, notevery map represents a function. Since a function assigns to each elements inits domain a single value, in order for a map to represent a function it musthave the following additional property:

    No value appears as a first component of more than one pair inthe map.

    A map with this property is called an smap (single-valued-map). Any timean smap is constructed and assigned to a variable, that variable can be usedas a function.

    We have seen before, (in Section 1.2, Activity 1) that tuples too can beused as functions. Use the examples of Activity 6(c) to discuss the differencesbetween the way tuples operate like functions, and the way smaps do.

    ProcsActivity 7 has an example of an ISETL proc or procedure. A procedure is thesame as a func except that it has no return statement and does not returna value. It is used to perform some internal operations such as establishingthe values of certain variables. In our example, it establishes the value of G,

  • 7/29/2019 Aprendendo AL Com ISETL

    58/400

  • 7/29/2019 Aprendendo AL Com ISETL

    59/400

    1.3 Functions 4

    In the rest of the course we will learn about structures named vector

    spaces. These structures are constructed upon (and rely on) structures ofnumbers called fields. Fields have some important characteristics. Let usexplain these characteristics.

    A field consists of a set K and two binary operations operating on it; Both operations are closed (see Activity 5); Each operation is commutative and associative (see Activity 5); There is a relation between the two operations called distributivity,

    which you probably know but with which we will not now deal;

    Each operation has an identity; For one of the operations every element has an inverse and the identity

    of this operation is usually denoted by 0;

    As for the second operation, all the elements ofK {0} have inverses.That means that every element has an inverse, except the identity ofthe first operation!

    We will not keep working with fields. Such work belongs to anotheralgebra course. For the time being, we need to know which Zns are fields,

    and hence, can build vector spaces upon them.From your work with Zn and their operations, you could see that Z6 is

    not a field. Although it has an identity for every operation, not every elementofZ6 {0} is invertible in relation to multiplication mod 6. Which elementsof Z6 are not invertible?

    We will not prove this here, but it can be proved, that like in our examples,when n is prime, Zn is a field. Examples are Z5 and Z7. We will use themto construct vector spaces upon. Can you think of more examples of fields?

    But when n is not prime, like Z6 (because 6 = 2 3), Zn is not a field.Likewise are Z12 and Z4 with which you worked. We will not use them for theconstruction of vector spaces. Can you think of other examples of non-fields?

    Polynomials and Polynomial Functions

    An important collection of functions which can be implemented in ISETL arethe polynomial functions. We start with the definition of a polynomial.

  • 7/29/2019 Aprendendo AL Com ISETL

    60/400

    48 CHAPTER 1. FUNCTIONS AND STRUCTURES

    Definition 1.3.1. A polynomial in x is an expression of the form

    a0 + a1x + a2x2 + a3x

    3 + . . . anxn.

    The values ai are called the coefficients of the polynomial. The polynomialis said to be over the numbers K if all of the coefficients are in the set K. Apolynomial for which an = 0 but am = 0 for all m > n is said to have degreen.

    Notice that a polynomial is not a function, it is only an expression usingthe variable x. Two polynomials are equal if and only if all of their coefficientsmatch. In ISETL, a polynomial is implemented as a tuple of scalars in orderof increasing degree. For example, the polynomial 2 + 3x2 is implemented as

    the scalar [2, 0, 3]. The collection of all polynomials of degree less thanor equal to n over the numbers K is denoted by Pn(K). The collection of allpolynomials over K is denoted by P(K).

    Each polynomial expression has an interpretation as a function. We nowdefine a polynomial function.

    Definition 1.3.2. A polynomial function is a function p where p(x) is apolynomial in x.

    In ISETL, polynomial functions are represented as funcs. Over the realnumbers, different polynomials lead to different polynomial functions. How-

    ever, over the finite fields Zp polynomial functions can behave in rather un-expected ways. For example, over Z5, consider the polynomial functions pand q where p(x) = x and q(x) = x5. Compute p(a) and q(a) for everya Z5. You should discover that p = q despite the fact that the polynomials

    p(x) and q(x) are different. As a result, defining the degree of a polynomialfunction is more complicated than it seems.

    Definition 1.3.3. A polynomial function has degree n if it is the interpreta-tion of an n degree polynomial and not an interpretation of any lesser degreepolynomial.

    The collection of all polynomial functions of degree less than or equal to nover the numbers K is denoted by P Fn(K). The collection of all polynomialsover K is denoted by P F(K).

    Theorem 1.3.1. Over the field Zp, the polynomial functions x x andx xp are the same. As a result, P F(Zp) = P Fp1(Zp).

  • 7/29/2019 Aprendendo AL Com ISETL

    61/400

    1.3 Functions 4

    Exercises

    1. Each of the following is a description of a function. Use an ISETL functo implement it, with a restricted domain where appropriate. Calculatethe value of the function on at least three values of the domain in twoways: first with paper and pencil, using the given verbal description andsecond, on the computer, using your func. Explain any discrepancies.

    (a) The function takes a 4-tuple (a tuple with four elements) whosecomponents are positive integers and computes the sum of thecubes of the components.

    (b) The domain of the function is the set of all points of the squarecentered at the origin of a rectangular coordinate system with sidesparallel to the coordinate axes and having length 2. The action ofthe function is to rotate the square counterclockwise through anangle of 180.

    (c) The function determines the number of non-OM components of atuple. (Note that not all of the components of a tuple betweenthe first and last must be defined).

    2. Write ISETL funcs with the given names according to each of the follow-

    ing specifications. In each case, set up specific values for the parametersand run your code to check that it works.

    (a) The func is associative has two input parameters: a set Gand a binary operation o. The action of is associative is todetermine whether the operation represented by o is associative.This is indicated by returning the value true or false.

    (b) Construct a func add 7 that implements addition mod 7 in Z7.Use your construction in ISETL code that shows that every elementin Z7 has an inverse in relation to add 7.

    (c) Repeat part (b) with Z6 and add 6.

    3. Write an ISETL map that implements the function whose domain is Z20and assigns to each element x an element y such that (x + y) mod 20 =0. Is this an smap? Explain.

  • 7/29/2019 Aprendendo AL Com ISETL

    62/400

    50 CHAPTER 1. FUNCTIONS AND STRUCTURES

    4. Do the same as the previous exercise with addition replaced by multi-

    plication and 0 replaced by 1.

    5. Write an ISETL smap that implements the operation of addition mod20 in Z20.

    6. Write an ISETL func that accepts a pair consisting of a set G and abinary operation o on G. The action of the func is to convert this pairinto an smap which implements the operation. Use your func to do theprevious exercise.

    7. Construct a function takes a tuple (of any length) for input and returnsa set all of the components of the tuple for output.

    8. Look again at the func Av of Activity 1(c). Is it or is it not a binaryoperation? Write an explanation. If it is, use it with several appropriateinputs as an operation written between the two parameters. If it is not,what modifications need to be done to Av in order to produce a similarfunction (say, AvBin) which could be used as a binary operation, inparticular in the method described above.

    9. Write a tuple and a smap of your own. Operate both as functions.For each of them, write an explanation: What are the inputs of thefunction? What is its domain? (The domain is the set of elements you

    can input in the function). What are its outputs?

  • 7/29/2019 Aprendendo AL Com ISETL

    63/400

    Chapter 2

    Vectors and Vector Spaces

    You have seen vectors in your physics classes, inmultivariable calculus and perhaps in othercourses. In those cases, vectors were probablyconsidered to be things with direction andmagnitude and were usually represented as

    directed line segments. In this chapter andbeyond, we will be working with vectors in anabstract sense. Certainly the vectors with whichyou are already familiar will be included in ourwork (although they will all have their tails atthe origin). However, as we work with vectorsand vector spaces, you will find that polynomialsand infinitely differentiable functions are alsovectors.

  • 7/29/2019 Aprendendo AL Com ISETL

    64/400

  • 7/29/2019 Aprendendo AL Com ISETL

    65/400

    2.1 Vectors 5

    Use va to add the following tuples in (Z5)n. Can you add these tuples

    using vec add?

    (a) [2, 2, 1] + [3, 0, 4]

    (b) [0, 1, 0, 1] + [1, 2, 3, 4]

    (c) [1, 2] + [2, 1]

    5. (a) Write an ISETL func sm that accepts an element k from Z5 anda tuple v, and returns the tuple kv in which each component ofvhas been multiplied (mod 5) by k.

    (b) Test your func for k = 3 and v = [2, 4].

    (c) Test your func for k = 0 and v = [1, 3, 3].(d) Test your func for k = 1 and v = [3, 2, 4, 1].

    6. (a) Write an ISETL func is closed va that accepts a set V of tuplesand an operation va (vector addition). Your func should testwhether the sum of any two tuples in V is again in V.

    (b) Test your func on V = (Z5)2, with va defined in Activity 4.

    (c) Test your func on V = (Z3)3. Modify va appropriately, using

    mod 3 arithmetic.

    (d) Test your func on V = (Z2)4. Modify va appropriately, using

    mod 2 arithmetic.

    7. (a) Write an ISETL func is commutative that accepts a set V ofvectors (tuples) and an operation va and determines whether ornot the operation va is commutative on V.

    (b) Test your func on V = (Z5)2 and va.

    (c) Test your func on V = (Z3)3 and an appropriately modified va.

    (d) Test your func on V = (Z2)4 and an appropriately modified va.

    8. (a) Write an ISETL func is associative va that accepts a set V ofvectors (tuples) and an operation va, and determines whether ornot va is associative on V.

    (b) Test your func on V = (Z5)2 and va.

    (c) Test your func on V = (Z2)2 and an appropriately modified va.

  • 7/29/2019 Aprendendo AL Com ISETL

    66/400

    54 CHAPTER 2. VECTORS AND VECTOR SPACES

    9. Explain the following ISETL code. What are the inputs to this func?

    What does this func return?

    has_zerovec := func(V, va);

    VZERO := choose z in V | forall v in V | (v .va z) = v;

    return VZERO;

    end;

    10. (a) Use the func has zerovec to write a new func has vinversesthat accepts a set V of tuples and operation va and determineswhether or not for each x in V there is an y in V with the propertythat va(x, y) = the result of has zerovec(V, va).

    (b) Test your func on V = (Z5)2 and va.

    (c) Test your func on V


Recommended