Outline Announcements: –Homework I on web, due Fri., 5PM by e-mail –Small error on homework –Wed and Fri in ACCEL, Attendance required –LAST DAY TO ADD/DROP!

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

MATH 224 – Discrete Mathematics
1 CS101 Introduction to Computing Lecture 17 Algorithms II.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
Chapter 10 Algorithmic Thinking. Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Learning Objectives List the five essential.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
© Janice Regan Problem-Solving Process 1. State the Problem (Problem Specification) 2. Analyze the problem: outline solution requirements and design.
Software Engineering and Design Principles Chapter 1.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Chapter 1 pp 1-14 Properties of Algorithms Pseudocode.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Program Design and Development
CS 201 Functions Debzani Deb.
CS 101 Problem Solving and Structured Programming in C Sami Rollins Spring 2003.
ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing.
C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.
1 L07SoftwareDevelopmentMethod.pptCMSC 104, Version 8/06 Software Development Method Topics l Software Development Life Cycle Reading l Section 1.4 – 1.5.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
1 Shawlands Academy Higher Computing Software Development Unit.
Simple Program Design Third Edition A Step-by-Step Approach
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Java: Chapter 1 Computer Systems Computer Programming II.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 1.2 Introduction to Algorithms.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Introduction to Problem Solving. Steps in Programming A Very Simplified Picture –Problem Definition & Analysis – High Level Strategy for a solution –Arriving.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Application: Correctness of Algorithms Lecture 22 Section 4.5 Fri, Mar 3, 2006.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
Reasoning about programs March CSE 403, Winter 2011, Brun.
The Software Development Process
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
ECSE Software Engineering 1I HO 4 © HY 2012 Lecture 4 Formal Methods A Library System Specification (Continued) From Specification to Design.
Introduction to programming Carl Smith National Certificate Year 2 – Unit 4.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
The Hashemite University Computer Engineering Department
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Outline Announcements: –HW I key online this afternoon –HW II due Friday –Sign up to discuss projects Debugging Testging for correctness.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Winter 2015.
Software Engineering Algorithms, Compilers, & Lifecycle.
Algorithms and Problem Solving
Unit 3: ALGORITHMS AND FLOWCHARTS
CSE101-Lec#2 Programming Methodologies
Coding Concepts (Basics)
Language Issues Misunderstimated? Sublimable? Hopefuller?
Algorithm and Ambiguity
Algorithms and Problem Solving
Outline Announcements Differences between FORTRAN and C
IS 135 Business Programming
Presentation transcript:

Outline Announcements: –Homework I on web, due Fri., 5PM by –Small error on homework –Wed and Fri in ACCEL, Attendance required –LAST DAY TO ADD/DROP! A Closer look at compilation What do I mean by “formal methods?” Specification Verification Practical formal methods

A Closer Look at Compilation Building an executable requires 2 steps –Compile--turn source code into low-level instructions (object files) cc -w or “compile” –Link--merge object files to form executable cc or “link”

A Closer Look at Compilation Why would you ever use -w? –Compilation is slow, linking is fast –Suppose program is split into several files: main.c, io.c, matrix.c Suppose we know the code in io.c and matrix.c work, but we’re unsure of main.c cc -w *.c --creates main.o, io.o, matrix.o If we make a change in main.c, we can just compile it: –cc-w main.c; cc *.o -omyapp

A Closer Look at Compilation What about simple programs? –cc -c firsttry.c produces firsttry.o –What’s missing? We called “printf” to write to the screen The low-level instructions for printf are in a library somewhere on your system. The linker gets those instructions and merges them with firsttry.o

Formal Methods As scientist we should be accustomed to precision –You must be able to describe the exact procedures used in your experiment/analysis –This is essential for reproducibility Reproducibility is equally important for computational work –Formal methods are a collection of techniques to describe precisely what a program should do

Importance of Formalism in Scientific Software Development A Scary Story: –You write a program to implement algorithm X (you think) –But, you actually implemented algorithm Y –It is possible that two similar algorithms can produce very different results (think chaos) –You publish a paper describing your results (from running algorithm Y), but in your methods you describe algorithm X –The results are spectacular. You get your Ph.D. and a tenure track job. –However, just as you’re being reviewed for tenure, a grad student in Afghanistan tries to repeat your experiments. Based on your paper, she correctly implements algorithm X and gets very different results. –Your tenure is denied, no one will hire you, you walk around campus with a “Will code for food” sign while the Afghani student takes your position.

Formal Methods Formal methods can be divided into two steps: –Specification: a precise statement of what a program (or subroutine) should do –Verification: a demonstration that the actual program satisfies the specification

Math/Logic is the preferred method –rigorous –Precise But, English has its place –Some would say, English is not formal –My view: a good English spec. is better than nothing at all You may actually write a spec in English Can include in comments Specification Methods

Describe the properties of the inputs and outputs –Data structures –Precision/type –Assumptions: sorted? symmetric? ≠0? Describe what will happen if assumptions violated –return error –return null value, NaN, -999 –throw exception Keys to Specification

Formal Specification –I=formal statement about input –O=formal statement about output –P=program –Says that if input conditions are given to program P, then the output conditions will be true This just says what a program should do, but says nothing about how it will get done –No details of P

A specification can take many forms: –English: “Given a sorted array of integers, the routine will return the location of k in the array, where k is provided by the user” –Logic: Specification

English: Given real-valued parameters a, b, and c, the routine returns the roots of the quadratic equation Math: Specification

Demonstrate (prove) that your program satisfies specification Keep the specification in mind as you develop your code –Lines or sections of code will establish different parts of the specification –Sometimes, it is easier to refine I (strengthen assumptions) than to satisfy it Verification

There are rigorous approaches to verification –Special types of logic that describe what code does Theoreticians have built “theorem provers” that can be used to automate this process –Theorem: Specification –Proof: Logical equivalent of specification should show that specification is true Formal Verification

This is a really cool idea –See NuPRL web sit – Prl/Intro/intro.html Not practical for most scientific programs Essential for software controlling costly or important actions –Airplanes –Space probes –Stock trades Formal Verification

Typing is very simple form of verification In a strongly-typed language (Java) –X=Y is allowed only if X and Y are the same type –This is very helpful, but doesn’t come close to guaranteeing that your program is correct: void BadFunction(int[] big){ int[] small=new int[5]; for(int j=0;j<big.length;j++){ small[j]=2*big[j]; } Free Verification

Ideally we would all conduct rigorous specification/verification of our programs But who are we kidding? In the real world, –1) Write a specification as formally as you can, and put an English approximation in the comments –2) As you write your code, prove to yourself that you are actually solving the problem You should include comments like “this line only works if X is true” and “this line makes sure X is true” Practical Formal Methods

A standard technique in formal methods is to search for invariant properties –An invariant is a property that doesn’t change –If a line of code violates the invariant, next one should reestablish it A Useful Technique

Specifying the Model Problem English: Given initial distribution of C defined on an evenly spaced grid of m points starting at 0 and ending at L (etc. for u, k and reaction), a time step dt, and an ending time T, RAD1d finds an approximate solution fo PDE at time T

Specifying RAD1d We know that C provided by user is an approximate solution at time 0. This suggests an invariant: –C is a solution for PDE a current time t We can use the invariant to help develop the code Get C at time 0 t=0---establishes invariant at start of loop while (t<T){ Build A, b Solve AC=b--invariant violated, C is sol’n at t+dt t=t+dt --invariant reestablished }