Testing Software with Pexpect
|
|
- Rose Dalton
- 5 years ago
- Views:
Transcription
1 Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with Pexpect running the test on SymPy in Sage applying Pexpect to test the factorizations MCS 507 Lecture 39 Mathematical, Statistical and Scientific Software Jan Verschelde, 25 November 2013 Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
2 Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with Pexpect running the test on SymPy in Sage applying Pexpect to test the factorizations Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
3 testing software We distinguish between test to fail, e.g.: careless user, special cases, stress test,... test to pass, e.g.: meets specifications, regression test. In this lecture we will test to pass. In the course we have touched 6 computer algebra systems: Maxima, PARI/GP, GAP, Singular, SymPy, all available in Sage (the 7th computer algebra system). How do we test the systems systematically and automatically? prepare a test suite of problems, apply Pexpect to run the test scripts. Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
4 testing computer algebra Michael J. Wester: A Critique of the Mathematical Abilities of CA Systems, pages 25-60, published as chapter 3 in Computer Algebra Systems. A Practical Guide, edited by Michael J. Wester, Wiley This chapter contains 20 pages with tables of 542 test problems. We select problems C1 and C2 on numbers: 50! = = We will verify the results by visual inspection and assert that 1 50! is a number of 65 decimal places long; and 2 50! has 15 prime factors. Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
5 a script withsympy import sympy as sp N = sp.factorial(50) print 50! =, N print 50! has, len(str(n)), decimal places F = sp.factorint(n) K = F.keys() K.sort() L = [str(x)+ ^ +str(f[x]) for x in K] S =.join(l) print 50! =, S print 50! has, len(f.keys()), prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
6 running the script withsympy $ python factorial50_sympy.py 50! = \ ! has 65 decimal places 50! = 2^47 3^22 5^12 7^8 11^4 13^3 17^2 19^2 23^2 \ 29^1 31^1 37^1 41^1 43^1 47^1 50! has 15 prime factors $ We can run the same script in Sage. Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
7 Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with Pexpect running the test on SymPy in Sage applying Pexpect to test the factorizations Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
8 factoring 50! in Sage def run_sage(): Computes and factors 50! with sage. print print factorial 50 test with sage n = factorial(50) print 50! =, n print 50! has, len(str(n)), decimal places f = factor(n) s = str(f) L = s.split( * ) F =.join(l) print 50! =, F print 50! has, len(l), prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
9 the output ofrun_sage() factorial 50 test with sage 50! = \ ! has 65 decimal places 50! = 2^47 3^22 5^12 7^8 11^4 13^3 17^2 19^2 23^2 \ ! has 15 prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
10 factoring 50! with PARI/GP def run_gp(): Computes and factors 50! with gp. print print factorial 50 test with gp n = gp( 50! ) print 50! =, n print 50! has, len(str(n)), decimal places c = factor( + str(n) + ) f = gp(c) s = repr(f) L = s.split( ; ) r = for e in L: t = e.split(, ) r = r + t[0]+ ^ +t[1][1:] print 50! =, r[1:-1] print 50! has, len(l), prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
11 the output ofrun_gp() factorial 50 test with gp 50! = \ ! has 65 decimal places 50! = 2^47 3^22 5^12 7^8 11^4 13^3 17^2 19^2 23^2 \ 29^1 31^1 37^1 41^1 43^1 47^1 50! has 15 prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
12 factoring 50! with GAP def run_gap(): Computes and factors 50! with gap. print print factorial 50 test with gap n = gap("factorial(50)") print 50! =, n print 50! has, len(str(n)), decimal places c = FactorsInt( +str(n)+ ) f = gap(c) L = list(set(f)) L.sort() F = list(f) K = [str(e)+ ^ +str(f.count(e)) for e in L] r = for k in K: r = r + + k print 50! =, r[1:] print 50! has, len(l), prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
13 the output ofrun_gap() factorial 50 test with gap 50! = \ ! has 65 decimal places 50! = 2^47 3^22 5^12 7^8 11^4 13^3 17^2 19^2 23^2 \ 29^1 31^1 37^1 41^1 43^1 47^1 50! has 15 prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
14 factoring 50! with Maxima def run_maxima(): Computes and factors 50! with maxima. print print factorial 50 test with maxima n = maxima("50!") print 50! =, repr(n) print 50! has, len(repr(n)), decimal places c = factor( + repr(n) + ) f = maxima(c) print 50! =, repr(f) s = repr(f) L = s.split( * ) print 50! has, len(l), prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
15 the output ofrun_maxima() factorial 50 test with maxima 50! = \ ! has 65 decimal places 50! = 2^47*3^22*5^12*7^8*11^4*13^3*17^2*19^2*23^2 \ *29*31*37*41*43*47 50! has 15 prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
16 factoring 50! with Singular def run_singular(): Computes and factors 50! with singular. print print factorial 50 test with singular n = singular("factorial(50)") print 50! =, n print 50! has, len(str(n)), decimal places c = primefactors( + str(n) + ) f = singular(c) L = list([e for e in f[1]]) K = list([e for e in f[2]]) z = zip(l, K) r = for t in z: r = r + + str(t[0]) + ^ + str(t[1]) print 50! =, r[1:] print 50! has, len(f[1]), prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
17 the output ofrun_singular() factorial 50 test with singular 50! = \ ! has 65 decimal places 50! = 2^47 3^22 5^12 7^8 11^4 13^3 17^2 19^2 23^2 \ 29^1 31^1 37^1 41^1 43^1 47^1 50! has 15 prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
18 factoring 50! with SymPy def run_sympy(): Computes and factors 50! with sympy. print print factorial 50 test with sympy import sympy as sp N = sp.factorial(50) print 50! =, N print 50! has, len(str(n)), decimal places F = sp.factorint(n) K = F.keys(); K.sort() L = [str(x)+ ^ +str(f[x]) for x in K] S =.join(l) print 50! =, S print 50! has, len(f.keys()), prime factors Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
19 the output ofrun_sympy factorial 50 test with sympy 50! = \ ! has 65 decimal places 50! = 2^47 3^22 5^12 7^8 11^4 13^3 17^2 19^2 23^2 \ 29^1 31^1 37^1 41^1 43^1 47^1 50! has 15 prime factors $ Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
20 Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with Pexpect running the test on SymPy in Sage applying Pexpect to test the factorizations Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
21 replacing print with assert statements Instead of print statements, we assert that the number of decimal places in 50! is 65 and that 50! has 15 prime factors. $ sage factorial50_test.sage factorial 50 test with sage passed factorial 50 test with gp passed factorial 50 test with gap passed factorial 50 test with maxima passed factorial 50 test with singular passed factorial 50 test with sympy passed $ Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
22 the scriptfactorial50_test.sage def test_sage(): Tests the prime factorization of 50! with sage. print print factorial 50 test with sage, n = factorial(50) assert len(str(n)) == 65 f = factor(n) s = str(f) L = s.split( * ) F =.join(l) assert len(l) == 15 print passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
23 the scriptfactorial50_test.sage continued def test_gp(): Tests the prime factorization of 50! with gp. print print factorial 50 test with gp, n = gp( 50! ) assert len(str(n)) == 65 c = factor( + str(n) + ) f = gp(c) s = repr(f) L = s.split( ; ) len(l) r = for e in L: t = e.split(, ) r = r + t[0]+ ^ +t[1][1:] assert len(l) == 15 print passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
24 the scriptfactorial50_test.sage continued def test_gap(): Tests the prime factorization of 50! with gap. print print factorial 50 test with gap, n = gap("factorial(50)") assert len(str(n)) == 65 c = FactorsInt( +str(n)+ ) f = gap(c) L = list(set(f)) L.sort() F = list(f) K = [str(e)+ ^ +str(f.count(e)) for e in L] r = for k in K: r = r + + k assert len(l) == 15 print passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
25 the scriptfactorial50_test.sage continued def test_maxima(): Tests the prime factorization of 50! with maxima. print print factorial 50 test with maxima, n = maxima("50!") assert len(repr(n)) == 65 c = factor( + repr(n) + ) f = maxima(c) s = repr(f) L = s.split( * ) assert len(l) == 15 print passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
26 the scriptfactorial50_test.sage continued def test_singular(): Tests the prime factorization of 50! with singular. print print factorial 50 test with singular, n = singular("factorial(50)") assert len(str(n)) == 65 c = primefactors( + str(n) + ) f = singular(c) L = list([e for e in f[1]]) K = list([e for e in f[2]]) z = zip(l, K) r = for t in z: r = r + + str(t[0]) + ^ + str(t[1]) assert len(f[1]) == 15 print passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
27 the scriptfactorial50_test.sage continued def test_sympy(): Tests the prime factorization of 50! with sympy. print print factorial 50 test with sympy, import sympy as sp n = sp.factorial(50) assert len(str(n)) == 65 f = sp.factorint(n) K = f.keys(); K.sort() L = [str(x)+ ^ +str(f[x]) for x in K] s =.join(l) assert len(f.keys()) == 15 print passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
28 Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with Pexpect running the test on SymPy in Sage applying Pexpect to test the factorizations Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
29 automating tests with Pexpect Recall that Pexpect is used in Sage to connect with PARI/GP, GAP, Maxima, R, Singular. Sage is an interactive program and with Pexpect we can send the test commands one after the other. Instead of runningsage factorial50_test.sage the test program reads a script line by line and sends the lines tosage with Pexpect. Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
30 checking the version number of Sage Instead of runningsage factorial50_test.sage, we runpython factorial50_sage_test.py, a pure Python script that first checks whether sage is available. $ python sage_version_test.py Sage Version 5.10, Release Date: $ Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
31 the scriptsage_version_test.py import pexpect SAGE_PATH = /Users/jan/Desktop/Sage-5.10-OSX-64bit-10.8.app/ \ + Contents/Resources/sage/sage def sage_version(path): Returns a string containing sage version and release date or None if sage cannot be found at the execution path. try: child = pexpect.spawn(path) except: return None child.expect( sage ) first = child.before lines = first.split( ) return lines[1].strip() if name == " main ": print sage_version(sage_path) Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
32 Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with Pexpect running the test on SymPy in Sage applying Pexpect to test the factorizations Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
33 running the test on SymPy in Sage We keep the original script: import sympy as sp N = sp.factorial(50) print 50! =, N print 50! has, len(str(n)), decimal places f = sp.factorint(n) K = f.keys(); K.sort() L = [str(x)+ ^ +str(f[x]) for x in K] S =.join(l) print 50! =, S print 50! has, len(f.keys()), prime factors and feed the script to Sage with Pexpect. Instead of running the script withsage, we run the test statements one after the other in Python. Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
34 the scriptfactorial50_sympy_test.py SAGE_PATH = /Users/jan/Desktop/Sage-5.10-OSX-64bit-10.8.app/ + Contents/Resources/sage/sage import pexpect from sage_version_test import sage_version V = sage_version(sage_path) if(v == None): print Sage not installed? else: print V CHILD = pexpect.spawn(sage_path) CHILD.expect( sage: ) # print child.before SCRIPT = open( factorial50_sympy.py, r ) Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
35 factorial50_sympy_test.py continued while True: LINE = SCRIPT.readline() if(line == ""): break if LINE[0]!= # : CMD = LINE[:-1] # print executing, CMD CHILD.sendline(CMD) CHILD.expect( sage: ) if(cmd[:5] == print ): C = CHILD.before L = C.split(CMD) print L[1].strip() CHILD.close() print test passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
36 the output offactorial50_sympy_test.py $ python factorial50_sympy_test.py Sage Version 5.10, Release Date: ! = \ ! has 65 decimal places 50! = 2^47 3^22 5^12 7^8 11^4 13^3 17^2 19^2 23^2 \ 29^1 31^1 37^1 41^1 43^1 47^1 50! has 15 prime factors test passed $ Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
37 Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with Pexpect running the test on SymPy in Sage applying Pexpect to test the factorizations Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
38 the scriptfactorial50_sage_test.py All commands are infactorial50_run.sage. SAGE_PATH = /Users/jan/Desktop/Sage-5.10-OSX-64bit-10.8.app/ + Contents/Resources/sage/sage import pexpect from sage_version_test import sage_version V = sage_version(sage_path) if(v == None): print Sage not installed? else: print V CHILD = pexpect.spawn(sage_path) CHILD.expect( sage: ) SCRIPT = open( factorial50_run.sage, r ) Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
39 reading the commands line by line BUFFER = "" while True: if(buffer!= ""): LINE = BUFFER BUFFER = "" else: LINE = SCRIPT.readline() if(line == ""): break The bufferbis needed for thefor loops. Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
40 executing the commands if(line[0]!= # ): CMD = LINE[:-1] if(cmd[:3] == for ): while True: BUFFER = SCRIPT.readline() if BUFFER[:2]!= " ": break CMD = CMD + \n + BUFFER[:-1] CMD = CMD + \n CHILD.sendline(CMD) CHILD.expect( sage: ) Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
41 script continues if(cmd[:5] == print ): C = CHILD.before L = C.split(CMD) if(len(l) > 1): print L[1].strip() CHILD.close() print print test passed Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
42 Summary and Exercises Preparing test suites is necessary for software quality control. Testing software is an important part of software development. With Pexpect we automate the testing of software. 1 Considering adding timers to the tests, e.g.: every command should take no longer than 1 second to complete. 2 Take numbers larger than 50! and find out which computer algebra system is best at the factorization task. 3 Consider any of the remaining 540 problems of the paper of Michael J. Wester. Project Three due Wednesday 27 November at 9AM. Homework Six is due on Wednesday 4 December at 9AM: ex 3 of L-27; ex 2 of L-28; ex 1 of L-29; ex 1 of L-30; ex 2 of L-31; ex 3 of L-32; ex 1 of L-33; ex 2 of L-34; ex 1 of L-35; and ex 1 of L-36. Scientific Software (MCS 507 L-39) Testing with Pexpect 25 November / 42
User Interfaces. MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September Command Line Interfaces
User 1 2 MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September 2011 User 1 2 command line interfaces Many programs run without dialogue with user, as $ executable
More informationList Comprehensions and Simulations
List Comprehensions and Simulations 1 List Comprehensions examples in the Python shell zipping, filtering, and reducing 2 Monte Carlo Simulations testing the normal distribution the Mean Time Between Failures
More informationRoot Finding Methods. sympy and Sage. MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011
wrap Root Finding Methods 1 2 wrap MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011 Root Finding Methods 1 wrap 2 wrap wrap octave-3.4.0:1> p = [1,0,2,-1]
More informationDefining Functions. turning expressions into functions. writing a function definition defining and using modules
Defining Functions 1 Lambda Functions turning expressions into functions 2 Functions and Modules writing a function definition defining and using modules 3 Computing Series Developments exploring an example
More informationWeb Clients and Crawlers
Web Clients and Crawlers 1 Web Clients alternatives to web browsers opening a web page and copying its content 2 Scanning Files looking for strings between double quotes parsing URLs for the server location
More informationIntroduction to the SageMath software
Introduction to the SageMath software (https://www.sagemath.org) slides available at http://www.labri.fr/perso/vdelecro/teaching.html June 1st 2017, Mini-course HSE Moscow by Vincent Delecroix, CNRS researcher
More informationLists and Loops. browse Python docs and interactive help
Lists and Loops 1 Help in Python browse Python docs and interactive help 2 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 3 Loops in Python
More informationTuples and Nested Lists
stored in hash 1 2 stored in hash 3 and 4 MCS 507 Lecture 6 Mathematical, Statistical and Scientific Software Jan Verschelde, 2 September 2011 and stored in hash 1 2 stored in hash 3 4 stored in hash tuples
More informationprocessing data with a database
processing data with a database 1 MySQL and MySQLdb MySQL: an open source database running MySQL for database creation MySQLdb: an interface to MySQL for Python 2 CTA Tables in MySQL files in GTFS feed
More informationPHCpack, phcpy, and Sphinx
PHCpack, phcpy, and Sphinx 1 the software PHCpack a package for Polynomial Homotopy Continuation polyhedral homotopies the Python interface phcpy 2 Documenting Software with Sphinx Sphinx generates documentation
More informationcallback, iterators, and generators
callback, iterators, and generators 1 Adding a Callback Function a function for Newton s method a function of the user to process results 2 A Newton Iterator defining a counter class refactoring the Newton
More informationNumerical Integration
Numerical Integration 1 Functions using Functions functions as arguments of other functions the one-line if-else statement functions returning multiple values 2 Constructing Integration Rules with sympy
More informationInterval Arithmetic. MCS 507 Lecture 29 Mathematical, Statistical and Scientific Software Jan Verschelde, 28 October 2011
Naive Arithmetic 1 2 Naive 3 MCS 507 Lecture 29 Mathematical, Statistical and Scientific Software Jan Verschelde, 28 October 2011 Naive Arithmetic 1 2 Naive 3 an expression Naive Problem: Evaluate f(x,
More informationUser Interfaces. getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy
User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming
More informationWeb Interfaces. the web server Apache processing forms with Python scripts Python code to write HTML
Web Interfaces 1 Python Scripts in Browsers the web server Apache processing forms with Python scripts Python code to write HTML 2 Web Interfaces for the Determinant dynamic interactive forms passing data
More informationLists and Loops. defining lists lists as queues and stacks inserting and removing membership and ordering lists
Lists and Loops 1 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 2 Loops in Python for and while loops the composite trapezoidal rule MCS
More informationGraphical User Interfaces
to visualize Graphical User Interfaces 1 2 to visualize MCS 507 Lecture 12 Mathematical, Statistical and Scientific Software Jan Verschelde, 19 September 2011 Graphical User Interfaces to visualize 1 2
More informationoperator overloading algorithmic differentiation the class DifferentialNumber operator overloading
operator overloading 1 Computing with Differential Numbers algorithmic differentiation the class DifferentialNumber operator overloading 2 Computing with Double Doubles the class DoubleDouble defining
More informationBranching and Enumeration
Branching and Enumeration 1 Booleans and Branching computing logical expressions computing truth tables with Sage if, else, and elif 2 Timing Python Code try-except costs more than if-else 3 Recursive
More informationNgày 9 tháng 12 năm Discrete Mathematics Lecture-15
Discrete Mathematics Lecture-15 Ngày 9 tháng 12 năm 2011 ex ex ex a 1 mod b (gcd(a,b) = 1) ex a 1 mod b (gcd(a,b) = 1) Returns an integer c < b such that a c mod b = 1. ex a 1 mod b (gcd(a,b) = 1) Returns
More informationOpen source software and Sage 1
Open source software and Sage 1 http://www.sagemath.org/ David Joyner Math Dept USNA, Annapolis, MD May, 2009 1 Presentation for NSF CDI workshop David Joyner Open source software and Sage http://www.sagemath.org/
More informationturning expressions into functions symbolic substitution, series, and lambdify
Defining Functions 1 Lambda Functions turning expressions into functions symbolic substitution, series, and lambdify 2 Functions and Modules writing a function definition defining and using modules where
More informationphcpy: an API for PHCpack
phcpy: an API for PHCpack Jan Verschelde University of Illinois at Chicago Department of Mathematics, Statistics, and Computer Science http://www.math.uic.edu/ jan jan@math.uic.edu Graduate Computational
More informationRandom Walks & Cellular Automata
Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of
More informationOutline. software testing: search bugs black-box and white-box testing static and dynamic testing
Outline 1 Verification Techniques software testing: search bugs black-box and white-box testing static and dynamic testing 2 Programming by Contract assert statements in Python using preconditions and
More informationdifferentiation techniques
differentiation techniques 1 Callable Objects delayed execution of stored code 2 Numerical and Symbolic Differentiation numerical approximations for the derivative storing common code in a parent class
More informationDivide and Conquer. playing divide and conquer. searching in a sorted list membership in a sorted list
Divide and Conquer 1 Guessing a Secret playing divide and conquer 2 Binary Search searching in a sorted list membership in a sorted list 3 Bisection Search inverting a sampled function bisection search
More informationJohn Perry. Spring 2016
MAT 305: Introduction to Sage University of Southern Mississippi Spring 2016 Outline 1 2 3 4 5 Outline 1 2 3 4 5 Sage? Software for Algebra and Geometry Exploration Computer Algebra System started by William
More informationUnit 7 Day 4 Notes: graph coloring, Graph theory review & Quiz
Unit 7 Day 4 Notes: graph coloring, Graph theory review & Quiz Warm-Up Phones OFF & in Blue Pockets! Get out paper for notes! Agenda Notes first, Then do practice and HW questions Quiz at the end Notes:
More informationFloating-Point Arithmetic
Floating-Point Arithmetic 1 Numerical Analysis a definition sources of error 2 Floating-Point Numbers floating-point representation of a real number machine precision 3 Floating-Point Arithmetic adding
More informationJohn Perry. Spring 2017
MAT 305: Introduction to Sage University of Southern Mississippi Spring 2017 Outline 1 2 3 4 Outline 1 2 3 4 Sage? Software for Algebra and Geometry Exploration Computer Algebra System started by William
More informationRandom Walks & Cellular Automata
Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of
More informationprocessing data from the web
processing data from the web 1 CTA Tables general transit feed specification stop identification and name finding trips for a given stop 2 CTA Tables in MySQL files in GTFS feed are tables in database
More informationRunning Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions
Running Cython 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions 3 Using Cython
More informationHigh Level Parallel Processing
High Level Parallel Processing 1 GPU computing with Maple enabling CUDA in Maple 15 stochastic processes and Markov chains 2 Multiprocessing in Python scripting in computational science the multiprocessing
More informationProgramming with Python
Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2
More informationPython review. 1 Python basics. References. CS 234 Naomi Nishimura
Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not
More informationPython Programming Exercises 1
Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them
More informationCS1 Lecture 3 Jan. 22, 2018
CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow
More informationsolving polynomial systems in the cloud with phc
solving polynomial systems in the cloud with phc Jan Verschelde University of Illinois at Chicago Department of Mathematics, Statistics, and Computer Science http://www.math.uic.edu/ jan jan@math.uic.edu
More informationOutline. policies. with some potential answers... MCS 260 Lecture 19 Introduction to Computer Science Jan Verschelde, 24 February 2016
Outline 1 midterm exam on Friday 26 February 2016 policies 2 questions with some potential answers... MCS 260 Lecture 19 Introduction to Computer Science Jan Verschelde, 24 February 2016 Intro to Computer
More informationLecture 27. Lecture 27: Regular Expressions and Python Identifiers
Lecture 27 Lecture 27: Regular Expressions and Python Identifiers Python Syntax Python syntax makes very few restrictions on the ways that we can name our variables, functions, and classes. Variables names
More informationWelcome to MCS 275. Course Content Prerequisites & Expectations. Scripting in Python from OOP to LAMP example: Factorization in Primes
Welcome to MCS 275 1 About the Course Course Content Prerequisites & Expectations 2 Introduction to Programming Scripting in Python from OOP to LAMP example: Factorization in Primes 3 Summary MCS 275 Lecture
More informationReview for Second Midterm Exam
Review for Second Midterm Exam 1 Policies & Material 2 Questions modular design working with files object-oriented programming testing, exceptions, complexity GUI design and implementation MCS 260 Lecture
More informationWeb Clients and Crawlers
Web Clients and Crawlers 1 Web Clients alternatives to web browsers opening a web page and copying its content 2 Scanning files looking for strings between double quotes parsing URLs for the server location
More informationSage: an open-source mathematics software
2nd SCIEnce Workshop Palaiseau, France January 19, 2009 Disclaimer I m not the best person to talk about Sage Disclaimer I m not the best person to talk about Sage I m biased towards Sage for the following
More informationThis document describes how I implement the Newton method using Python and Fortran on the test function f(x) = (x 1) log 10 (x).
AMS 209 Foundations of Scientific Computing Homework 6 November 23, 2015 Cheng-Han Yu This document describes how I implement the Newton method using Python and Fortran on the test function f(x) = (x 1)
More informationPython lab session 1
Python lab session 1 Dr Ben Dudson, Department of Physics, University of York 28th January 2011 Python labs Before we can start using Python, first make sure: ˆ You can log into a computer using your username
More information[CALCULATOR OPERATIONS]
Example 1: Set up a table of values (with x-values between 3 and 3) and use it to draw the graph of 3. Press MENU 2: VIEW A: SHOW TABLE 1. Select the GRAPHS option: Or Press MENU 5: TRACE 1: GRAPH TRACE
More informationLecture 27: Streams and Lazy Evaluation
Lecture 27: Streams and Lazy Evaluation Some of the most interesting real-world problems in computer science center around sequential data. DNA sequences. Web and cell-phone traffic streams. The social
More informationOutline. measuring complexity: big-oh complexity classes counting flops: floating-point operations
Outline 1 Complexity and Cost measuring complexity: big-oh complexity classes counting flops: floating-point operations 2 Cost of Algorithms timing Python programs the unix command time try-except costs
More informationMunster Programming Training - Cycle 2
Munster Programming Training - Cycle 2 Lecture 3 - Binary Search & Queues & Stacks Bastien Pietropaoli bastien.pietropaoli@insight-centre.org Time complexity Previously On MPT Cycle 2 Recursions Exercise
More informationimmediate send and receive query the status of a communication MCS 572 Lecture 8 Introduction to Supercomputing Jan Verschelde, 9 September 2016
Data Partitioning 1 Data Partitioning functional and domain decomposition 2 Parallel Summation applying divide and conquer fanning out an array of data fanning out with MPI fanning in the results 3 An
More informationPhysics 514 Basic Python Intro
Physics 514 Basic Python Intro Emanuel Gull September 8, 2014 1 Python Introduction Download and install python. On Linux this will be done with apt-get, evince, portage, yast, or any other package manager.
More informationOutline. the try-except statement the try-finally statement. exceptions are classes raising exceptions defining exceptions
Outline 1 Exception Handling the try-except statement the try-finally statement 2 Python s Exception Hierarchy exceptions are classes raising exceptions defining exceptions 3 Anytime Algorithms estimating
More informationOutline. half adders adder circuits. the while loop the for loop. Euclid s algorithm approximating π
Outline 1 Digital Systems half adders adder circuits 2 Looping Constructs the while loop the for loop 3 Designing Loops Euclid s algorithm approximating π 4 Summary + Assignments MCS 260 Lecture 11 Introduction
More informationHashing. mapping data to tables hashing integers and strings. aclasshash_table inserting and locating strings. inserting and locating strings
Hashing 1 Hash Functions mapping data to tables hashing integers and strings 2 Open Addressing aclasshash_table inserting and locating strings 3 Chaining aclasshash_table inserting and locating strings
More informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
More informationLecture Notes, CSE 232, Fall 2014 Semester
Lecture Notes, CSE 232, Fall 2014 Semester Dr. Brett Olsen Week 11 - Number Theory Number theory is the study of the integers. The most basic concept in number theory is divisibility. We say that b divides
More informationModule 06. Topics: Iterative structure in Python Readings: ThinkP 7. CS116 Spring : Iteration
Module 06 Topics: Iterative structure in Python Readings: ThinkP 7 1 In Python, repetition can be recursive def count_down_rec(x): ''' Produces the list [x, x-1, x-2,..., 1,0] count_down:nat->(listof Nat)'''
More informationPIETRO, GIORGIO & MAX ROUNDING ESTIMATING, FACTOR TREES & STANDARD FORM
PIETRO, GIORGIO & MAX ROUNDING ESTIMATING, FACTOR TREES & STANDARD FORM ROUNDING WHY DO WE ROUND? We round numbers so that it is easier for us to work with. We also round so that we don t have to write
More informationTropical Implicitization
Tropical Implicitization Jan Verschelde University of Illinois at Chicago Department of Mathematics Statistics and Computer Science http://www.math.uic.edu/ jan jan@math.uic.edu Graduate Computational
More information61A Lecture 2. Wednesday, September 4, 2013
61A Lecture 2 Wednesday, September 4, 2013 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions:
More informationIntroduction to Problem Solving and Programming in Python.
Introduction to Problem Solving and Programming in Python http://cis-linux1.temple.edu/~tuf80213/courses/temple/cis1051/ Overview Types of errors Testing methods Debugging in Python 2 Errors An error in
More informationIntroduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15
1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details
More informationComputational Programming with Python
Numerical Analysis, Lund University, 2017 1 Computational Programming with Python Lecture 1: First steps - A bit of everything. Numerical Analysis, Lund University Lecturer: Claus Führer, Alexandros Sopasakis
More informationlambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
Outline 1 Guessing Secrets functions returning functions oracles and trapdoor functions 2 anonymous functions lambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
More informationRational numbers as decimals and as integer fractions
Rational numbers as decimals and as integer fractions Given a rational number expressed as an integer fraction reduced to the lowest terms, the quotient of that fraction will be: an integer, if the denominator
More informationReductions and Satisfiability
Reductions and Satisfiability 1 Polynomial-Time Reductions reformulating problems reformulating a problem in polynomial time independent set and vertex cover reducing vertex cover to set cover 2 The Satisfiability
More informationMultithreaded Servers
Multithreaded Servers 1 Serving Multiple Clients avoid to block clients with waiting using sockets and threads 2 Waiting for Data from 3 Clients running a simple multithreaded server code for client and
More informationIntroduction to Programming I
Still image from YouTube video P vs. NP and the Computational Complexity Zoo BBM 101 Introduction to Programming I Lecture #09 Development Strategies, Algorithmic Speed Erkut Erdem, Aykut Erdem & Aydın
More informationHashing. inserting and locating strings. MCS 360 Lecture 28 Introduction to Data Structures Jan Verschelde, 27 October 2010.
ing 1 2 3 MCS 360 Lecture 28 Introduction to Data Structures Jan Verschelde, 27 October 2010 ing 1 2 3 We covered STL sets and maps for a frequency table. The STL implementation uses a balanced search
More informationCSE 344 APRIL 20 TH RDBMS INTERNALS
CSE 344 APRIL 20 TH RDBMS INTERNALS ADMINISTRIVIA OQ5 Out Datalog Due next Wednesday HW4 Due next Wednesday Written portion (.pdf) Coding portion (one.dl file) TODAY Back to RDBMS Query plans and DBMS
More informationOpen Source Experience on Math Courses
Department of Mathematical Sciences, National Chengchi University, Taipei, Taiwan 政治大學應用數學系 July 17, 2007 @ Libre Software Meeting Introduction We are going to share our experience on a computer training
More informationCS116 - Module 5 - Accumulative Recursion
CS116 - Module 5 - Accumulative Recursion Cameron Morland Winter 2018 1 Cameron Morland CS116 - Module 5 - Accumulative Recursion Types of Recursion Structural Recursion Generative Recursion Accumulative
More informationEmil Sekerinski, McMaster University, Winter Term 16/17 COMP SCI 1MD3 Introduction to Programming
Emil Sekerinski, McMaster University, Winter Term 16/17 COMP SCI 1MD3 Introduction to Programming In Python, variables are names of objects base 5 >>> base = 5 >>> height = 4 >>> area = base*height/2 >>>
More informationCME 193: Introduction to Scientific Python Lecture 1: Introduction
CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements
More informationPhys Techniques of Radio Astronomy Part 1: Python Programming LECTURE 2
Phys 60441 Techniques of Radio Astronomy Part 1: Python Programming LECTURE 2 Tim O Brien Room 3.214 Alan Turing Building tim.obrien@manchester.ac.uk Lists A compound data type (elements can be same type
More informationPlay with Python: An intro to Data Science
Play with Python: An intro to Data Science Ignacio Larrú Instituto de Empresa Who am I? Passionate about Technology From Iphone apps to algorithmic programming I love innovative technology Former Entrepreneur:
More informationProgramming in MATLAB
8. Program Flow and Recursion Faculty of mathematics, physics and informatics Comenius University in Bratislava November 25th, 2015 Program Flow Program Flow in the first lecture: one command at a time
More informationScientific Computing: Lecture 1
Scientific Computing: Lecture 1 Introduction to course, syllabus, software Getting started Enthought Canopy, TextWrangler editor, python environment, ipython, unix shell Data structures in Python Integers,
More informationReview of the Lectures 21-26, 30-32
Review of the Lectures 21-26, 30-32 1 The Final Exam Monday 11 December, BSB 337, from 8AM to 10AM 2 Examples of Questions recursion and memoization enumeration trees, binary search trees, Huffman codes
More informationLecture 11. Asserts and Error Handling
Lecture 11 Asserts and Error Handling Announcements for Today Reading Reread Chapter 3 10.0-10.2, 10.4-10.6 for Thu Prelim, Oct 13 th 7:30-9:00 Material up October 4th Study guide next week Conflict with
More informationMidterm I Practice Problems
15-112 Midterm I Practice Problems Name: Section: andrewid: This PRACTICE midterm is not meant to be a perfect representation of the upcoming midterm! You are responsible for knowing all material covered
More informationOpen Source Software for Higher Mathematics
Open Source Software for Higher Mathematics An Overview of Available Tools CJ Fearnley LinuxForce, Inc. http://www.linuxforce.net 2 February 2005 / Philadelphia area Linux Users Group http://www.cjfearnley.com/higher.math.and.open.source.pdf
More informationfrom Recursion to Iteration
from Recursion to Iteration 1 Quicksort Revisited using arrays partitioning arrays via scan and swap recursive quicksort on arrays 2 converting recursion into iteration an iterative version with a stack
More informationCSC236 Week 5. Larry Zhang
CSC236 Week 5 Larry Zhang 1 Logistics Test 1 after lecture Location : IB110 (Last names A-S), IB 150 (Last names T-Z) Length of test: 50 minutes If you do really well... 2 Recap We learned two types of
More informationIntroduction to Scientific Computing with Python, part two.
Introduction to Scientific Computing with Python, part two. M. Emmett Department of Mathematics University of North Carolina at Chapel Hill June 20 2012 The Zen of Python zen of python... fire up python
More informationPIC 16, Fall Variables, Dynamically-typed, Mutable, Immutable, Functions. Michael Andrews. October 1, Department of Mathematics UCLA
PIC 16, Fall 2018 Variables, Dynamically-typed, Mutable, Immutable, Functions Michael Andrews Department of Mathematics UCLA October 1, 2018 Office hours reminder M 1:30-2:45pm (Michael) T 1-2pm (Sam),
More informationOverview.
Overview day one 0. getting set up 1. text output and manipulation day two 2. reading and writing files 3. lists and loops today 4. writing functions 5. conditional statements day four day five day six
More informationCS 4110 Programming Languages & Logics
CS 4110 Programming Languages & Logics Lecture 38 Typed Assembly Language 30 November 2012 Schedule 2 Monday Typed Assembly Language Wednesday Polymorphism Stack Types Today Compilation Course Review Certi
More informationPython: Short Overview and Recap
Python: Short Overview and Recap Benjamin Roth CIS LMU Benjamin Roth (CIS LMU) Python: Short Overview and Recap 1 / 39 Data Types Object type Example creation Numbers (int, float) 123, 3.14 Strings this
More informationAdvanced Web Programming
Advanced Web Programming 1 Advanced Web Programming what we have covered so far 2 The SocketServer Module simplified development of network servers a server tells clients the time 3 A Forking Server instead
More informationWebAssign hw2.3 (Homework)
WebAssign hw2.3 (Homework) Current Score : / 98 Due : Wednesday, May 31 2017 07:25 AM PDT Michael Lee Math261(Calculus I), section 1049, Spring 2017 Instructor: Michael Lee 1. /6 pointsscalc8 1.6.001.
More informationLecture 11. Asserts and Error Handling
Lecture 11 Asserts and Error Handling Announcements for Today Reading Reread Chapter 3 10.0-10.2, 10.4-10.6 for Thu Prelim, Oct 12 th 7:30-9:00 Material up October 3rd Study guide next week Conflict with
More informationConditionals: Making Choices
Announcements ry to get help from me and tutors Reading assignment for this week: Chapters 5 and 6 of Downey Conditionals: Making Choices When you see a page on the web, be sure to reload it to see the
More informationInstructors: Daniel Deutch, Amir Rubinstein, Teaching Assistants: Amir Gilad, Michal Kleinbort
Extended Introduction to Computer Science CS1001.py Lecture 10b: Recursion and Recursive Functions Instructors: Daniel Deutch, Amir Rubinstein, Teaching Assistants: Amir Gilad, Michal Kleinbort School
More informationCS1110 Lab 6 (Mar 17-18, 2015)
CS1110 Lab 6 (Mar 17-18, 2015) First Name: Last Name: NetID: The lab assignments are very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness does not matter.)
More informationAn Introduction to Open-Source Mathematics Software
1 An Introduction to Open-Source Mathematics Software (Specifically: GAP,, Macaulay2 and Sage) Jason B. Hill Slow Pitch Colloquium University of Colorado March 17, 2010 2 Outline 1 Introduction 2 GAP -
More information61A Lecture 3. Friday, September 5
61A Lecture 3 Friday, September 5 Announcements There's plenty of room in live lecture if you want to come (but videos are still better) Please don't make noise outside of the previous lecture! Homework
More information