35
CAS Software Tasks Prime numbers Infinity Using a CAS Introduction to Mathematics for Software Engineering SET07106 Mathematics for Software Engineering School of Computing Edinburgh Napier University Module Leader: Uta Priss 2010 Copyright Edinburgh Napier University Introduction Slide 1/34

Introduction to Mathematics for Software Engineering - Uta Priss

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Introduction to Mathematics for SoftwareEngineering

SET07106 Mathematics for Software Engineering

School of ComputingEdinburgh Napier UniversityModule Leader: Uta Priss

2010

Copyright Edinburgh Napier University Introduction Slide 1/34

Page 2: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Outline

CAS Software

Tasks

Prime numbers

Infinity

Using a CAS

Copyright Edinburgh Napier University Introduction Slide 2/34

Page 3: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

What kind of maths skillsare needed by software engineers?

Copyright Edinburgh Napier University Introduction Slide 3/34

Page 4: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Computer Algebra System (CAS) software

I A software program that facilitates symbolic mathematics.

I Manipulation of mathematical expressions in symbolic form.

Copyright Edinburgh Napier University Introduction Slide 4/34

Page 5: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Examples of CAS software

I Commercial:I MATLAB (developed by The MathWorks)I Mathematica (Stephen Wolfram)I Maple

I Free: Sage (a front-end to several free CAS)

Copyright Edinburgh Napier University Introduction Slide 5/34

Page 6: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Tasks for CAS software

I simplification, modification of and substitution in expressions

I solution of equations, differentiation, integration

I series operations and limits

I matrix operations

I statistical and numerical operations

I logical operations, theorem proving

I plotting of graphs

Copyright Edinburgh Napier University Introduction Slide 6/34

Page 7: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Mathematical tasks for software engineers

Since CAS exists, what are the tasksthat are left for humans to do?

Copyright Edinburgh Napier University Introduction Slide 7/34

Page 8: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Problem solving example

How high above ground are we in this lecture room on the H floor?

Can you estimate?

If you were given half an hour time and access to some tools, howwould you determine the height?

Copyright Edinburgh Napier University Introduction Slide 8/34

Page 9: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Mathematical tasks for software engineers

I Modelling of problems and solutions

I Identifying the type of a problem in order to find the type ofthe solution

I Estimation of the results in order to verify that CAS result iscorrect

I Testing of results

I Mathematical thinking

Copyright Edinburgh Napier University Introduction Slide 9/34

Page 10: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Matching types of problems with types of solutions

type of problem type of solution

? differentiation? integration? functions? equationssudoku ?encryption ?expert systems, AI ?risk, life insurance ?

Copyright Edinburgh Napier University Introduction Slide 10/34

Page 11: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Estimation

I 1x , x →∞

I X 2, x →∞I What is larger 210 or 102?

I How much is 15% of 50?

I What is more probable: to win (a big prize) in the lottery orto have a car accident?

I What is the circumference of the Earth?

I How many times can you fold an A4 sheet of paper in half?If the paper is 0.1 mm thick and you were able to fold it 40times, how thick would it be?

(0.1× 240)

Copyright Edinburgh Napier University Introduction Slide 11/34

Page 12: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Estimation

I 1x , x →∞

I X 2, x →∞I What is larger 210 or 102?

I How much is 15% of 50?

I What is more probable: to win (a big prize) in the lottery orto have a car accident?

I What is the circumference of the Earth?

I How many times can you fold an A4 sheet of paper in half?If the paper is 0.1 mm thick and you were able to fold it 40times, how thick would it be? (0.1× 240)

Copyright Edinburgh Napier University Introduction Slide 11/34

Page 13: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Example 1: prime numbers

Numbers that are only divisible by 1 and by themselves.

2, 3, 5, 7, 11, 13, 17, ...

Copyright Edinburgh Napier University Introduction Slide 12/34

Page 14: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

An algorithm for finding prime numbers

2 3 4 5 6 7 8 9 1011 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 6061 62 63 64 65 66 67 68 69 70

Copyright Edinburgh Napier University Introduction Slide 13/34

Page 15: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

An algorithm for finding prime numbers (2)

2 3 �A4 5 �A6 7 �A8 9 ��ZZ1011 ��ZZ12 13 ��ZZ14 15 ��ZZ16 17 ��ZZ18 19 ��ZZ2021 ��ZZ22 23 ��ZZ24 25 ��ZZ26 27 ��ZZ28 29 ��ZZ3031 ��ZZ32 33 ��ZZ34 35 ��ZZ36 37 ��ZZ38 39 ��ZZ4041 ��ZZ42 43 ��ZZ44 45 ��ZZ46 47 ��ZZ48 49 ��ZZ5051 ��ZZ52 53 ��ZZ54 55 ��ZZ56 57 ��ZZ58 59 ��ZZ6061 ��ZZ62 63 ��ZZ64 65 ��ZZ66 67 ��ZZ68 69 ��ZZ70

Copyright Edinburgh Napier University Introduction Slide 14/34

Page 16: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

An algorithm for finding prime numbers (3)

2 3 �A4 5 �A6 7 �A8 �A9 ��ZZ1011 ��ZZ12 13 ��ZZ14 ��ZZ15 ��ZZ16 17 ��ZZ18 19 ��ZZ20

��ZZ21 ��ZZ22 23 ��ZZ24 25 ��ZZ26 ��ZZ27 ��ZZ28 29 ��ZZ3031 ��ZZ32 ��ZZ33 ��ZZ34 35 ��ZZ36 37 ��ZZ38 ��ZZ39 ��ZZ4041 ��ZZ42 43 ��ZZ44 ��ZZ45 ��ZZ46 47 ��ZZ48 49 ��ZZ50

��ZZ51 ��ZZ52 53 ��ZZ54 55 ��ZZ56 ��ZZ57 ��ZZ58 59 ��ZZ6061 ��ZZ62 ��ZZ63 ��ZZ64 65 ��ZZ66 67 ��ZZ68 ��ZZ69 ��ZZ70

Copyright Edinburgh Napier University Introduction Slide 15/34

Page 17: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

An algorithm for finding prime numbers (5)

2 3 �A4 5 �A6 7 �A8 �A9 ��ZZ1011 ��ZZ12 13 ��ZZ14 ��ZZ15 ��ZZ16 17 ��ZZ18 19 ��ZZ20

��ZZ21 ��ZZ22 23 ��ZZ24 ��ZZ25 ��ZZ26 ��ZZ27 ��ZZ28 29 ��ZZ3031 ��ZZ32 ��ZZ33 ��ZZ34 ��ZZ35 ��ZZ36 37 ��ZZ38 ��ZZ39 ��ZZ4041 ��ZZ42 43 ��ZZ44 ��ZZ45 ��ZZ46 47 ��ZZ48 49 ��ZZ50

��ZZ51 ��ZZ52 53 ��ZZ54 ��ZZ55 ��ZZ56 ��ZZ57 ��ZZ58 59 ��ZZ6061 ��ZZ62 ��ZZ63 ��ZZ64 ��ZZ65 ��ZZ66 67 ��ZZ68 ��ZZ69 ��ZZ70

Copyright Edinburgh Napier University Introduction Slide 16/34

Page 18: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

An algorithm for finding prime numbers (7)

2 3 �A4 5 �A6 7 �A8 �A9 ��ZZ1011 ��ZZ12 13 ��ZZ14 ��ZZ15 ��ZZ16 17 ��ZZ18 19 ��ZZ20

��ZZ21 ��ZZ22 23 ��ZZ24 ��ZZ25 ��ZZ26 ��ZZ27 ��ZZ28 29 ��ZZ3031 ��ZZ32 ��ZZ33 ��ZZ34 ��ZZ35 ��ZZ36 37 ��ZZ38 ��ZZ39 ��ZZ4041 ��ZZ42 43 ��ZZ44 ��ZZ45 ��ZZ46 47 ��ZZ48 ��ZZ49 ��ZZ50

��ZZ51 ��ZZ52 53 ��ZZ54 ��ZZ55 ��ZZ56 ��ZZ57 ��ZZ58 59 ��ZZ6061 ��ZZ62 ��ZZ63 ��ZZ64 ��ZZ65 ��ZZ66 67 ��ZZ68 ��ZZ69 ��ZZ70

This algorithm is called: the Sieve of Eratosthenes.

Copyright Edinburgh Napier University Introduction Slide 17/34

Page 19: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

How many prime numbers are there?

Copyright Edinburgh Napier University Introduction Slide 18/34

Page 20: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

How many prime numbers are there?

(1 * 2 * 3) + 1 = 7

(1 * 2 * 3 * 5) + 1 = 31

(1 * 2 * 3 * 5 * 7) + 1 = 211

(1 * 2 * 3 * 5 * 7 * 11) + 1 = 2311

Not all numbers in this list are prime numbers:(1 * 2 * 3 * 5 * 7 * 11 * 13) + 1 = 30031 = 59 * 509

But there cannot be a largest prime.

Copyright Edinburgh Napier University Introduction Slide 19/34

Page 21: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Example 2: infinity

How many ...

I integers

I even numbers

I rational numbers

I real numbers

Copyright Edinburgh Napier University Introduction Slide 20/34

Page 22: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

How many rational numbers?

...2/1 2/2 2/3 2/4 2/5 2/6 2/7 ...3/1 3/2 3/3 3/4 3/5 3/6 3/7 ...4/1 4/2 4/3 4/4 4/5 4/6 4/7 ...5/1 5/2 5/3 5/4 5/5 5/6 5/7 ...6/1 6/2 6/3 6/4 6/5 6/6 6/7 ...7/1 7/2 7/3 7/4 7/5 7/6 7/7 ...... ... ... ... ... ...

1/1 1/2 1/3 1/4 1/5 1/6 1/7 ...

Copyright Edinburgh Napier University Introduction Slide 21/34

Page 23: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

How many rational numbers?

...1/1 1/2 1/3 1/4 1/5 1/6 1/7 ...2/1 2/2 2/3 2/4 2/5 2/6 2/7 ...3/1 3/2 3/3 3/4 3/5 3/6 3/7 ...4/1 4/2 4/3 4/4 4/5 4/6 4/7 ...5/1 5/2 5/3 5/4 5/5 5/6 5/7 ...6/1 6/2 6/3 6/4 6/5 6/6 6/7 ...7/1 7/2 7/3 7/4 7/5 7/6 7/7 ...... ... ... ... ... ...

Copyright Edinburgh Napier University Introduction Slide 22/34

Page 24: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

How many integers, even numbers, rational numbers?

1 2 3 4 5 6 7 8 ...

2 4 6 8 10 12 14 16 ...

1/1 1/2 2/1 3/1 2/2 1/3 1/4 2/3 ...

Copyright Edinburgh Napier University Introduction Slide 23/34

Page 25: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Intuition for numbers

Copyright Edinburgh Napier University Introduction Slide 24/34

Page 26: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Intuition for numbers

Copyright Edinburgh Napier University Introduction Slide 25/34

Page 27: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Intuition for numbers

Intuitively: there should be twice as many integers than there areeven numbers.

But there are not!

Integers, even numbers, odd numbers, rational numbers are allcountably infinite.

Real numbers are not countable. There are more real numbersthan integers.

Copyright Edinburgh Napier University Introduction Slide 26/34

Page 28: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Numbers in programming languages

How large are integers and real numbers in a computer?

How much can be computed?

Copyright Edinburgh Napier University Introduction Slide 27/34

Page 29: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

The SAGE open-source CAS

A collection of tools all accessible through a Python interface.

I SymPy and Maxima for calculus

I SciPy and NumPy for optimisation, linear algebra, integration,matrices

I FLINT, NTL and Pari for Number Theory

I PyCrypto and OpenCDK for Cryptography

I GD - Dynamic graphics generation tool

I IML Integer Matrix Library

I NetworkX Graph theory

I Sqlalchemy and Sqlite for relational database and algebra

I ... and more!

Copyright Edinburgh Napier University Introduction Slide 28/34

Page 30: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Why Python?

I Python is a multi-purpose language which has many librariesfor mathematics, language, etc, but can also do web pages,AI, Unix scripting and much more.

I Python is pre-installed on Linux and Mac OS.

I Scripting languages are easy to learn and use.

I Only a very small subset of Python is needed for this module.

I Python has a datatype for Sets.

I Python supports some forms of functional programming

One notable difference between Python and other languages:Python uses code indentation instead of curly brackets {}.

Copyright Edinburgh Napier University Introduction Slide 29/34

Page 31: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Code indentation

for ... :while ... :

if ... :do something

if ... :do something

Copyright Edinburgh Napier University Introduction Slide 30/34

Page 32: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Elements and data types

Data types in programming languages: integer, float, string ...The data type determines the operations that are available.

In mathematics: elements are usually part of a mathematicalstructure. This is usually a class with some operations:

I integers with +,−, ∗I rational numbers with +,−, ∗, /I real numbers with +,−, ∗, /I sets with set operations

I graphs with graph operations

Copyright Edinburgh Napier University Introduction Slide 31/34

Page 33: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Division in programming languages

division 21 / 10 == 2.1integer division 21 // 10 == 2remainder 21 % 10 == 1

Copyright Edinburgh Napier University Introduction Slide 32/34

Page 34: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Arithmetical operator precedence

1. exponentiation **2. multiplication, division, remainder *, /, //, %3. addition, subtraction +, -4. comparison ==, <, <=, >, >=, ! =

What is

5− 23 ∗ 3 + 62

(5 - 2**3 * 3 + 6/2)

Copyright Edinburgh Napier University Introduction Slide 33/34

Page 35: Introduction to Mathematics for Software Engineering - Uta Priss

CAS Software Tasks Prime numbers Infinity Using a CAS

Variables

Programming language variables:

n1 = 4n2 = 5result = n1 * n2

Mathematical variables:

x = Symbol(’x’)y = Symbol(’y’)x**2 + 5 * y - 2

x2 + 5y − 2

Copyright Edinburgh Napier University Introduction Slide 34/34