CREST Examples -Basic Examples -Function Examples -Limitation Examples.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Lecture 12 Recursion part 1
PLDI’2005Page 1June 2005 Example (C code) int double(int x) { return 2 * x; } void test_me(int x, int y) { int z = double(x); if (z==y) { if (y == x+10)
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Function with Output Parameters 4 We have seen that functions can return a single value or no value (void return type) 4 It is quite often useful to be.
CS Data Structures Appendix 1 How to transfer a simple loop- expression to a recursive function (factorial calculation)
Pointers Pointer - A pointer is a derived data type; that is it is a data type built from one of the standard types. Its value is any of the addresses.
1 Lecture 9  Arrays  Declaration  Initialization  Applications  Pointers  Declaration  The & and * operators  NULL pointer  Initialization  Readings:
1 Functions and Structured Programming. 2 Structured Programming Structured programming is a problem-solving strategy and a programming methodology. –The.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
1 Review of Chapter 6: The Fundamental Data Types.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
CSCI 130 for Loops Chapter 7 - A. Execution of a C Program Execution starts in main( ) Top down style –sequential flow Unrealistic to expect sequence.
Pointers (Continuation) 1. Data Pointer A pointer is a programming language data type whose value refers directly to ("points to") another value stored.
CREST Internal Yunho Kim Provable Software Laboratory CS Dept. KAIST.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12: Recursion Problem Solving, Abstraction, and Design using C++
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
CMSC 104, Version 8/061L11Relational&LogicalOps.ppt Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
RELATIONAL OPERATORS LOGICAL OPERATORS CONDITION Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
WEEK 4 Class Activities Lecturer’s slides.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Review Binary Numbers Bit : 0 or 1 Byte: 8 bites 256 different values 2 8 KB : 1024 bytes 2 10 bytes MB : 1024 * 1024 bytes 2 10 * 2 10 (2 20 ) bytes GB.
Lecture 6 C++ Programming Arne Kutzner Hanyang University / Seoul Korea.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Recursion A recursive definition is one which uses the word or concept being defined in the definition itself Example: “A computer is a machine.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
DATA TYPE, MEMORY, AND FUNCTION Dong-Chul Kim BioMeCIS UTA 2/18/
Lesson 4 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
CMSC 104, Version 9/011 Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else Statement Nesting of.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
C++ Programming Lecture 12 Functions – Part IV
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Dr. Sajib Datta Jan 23,  A precedence for each operator ◦ Multiplication and division have a higher precedence than addition and subtraction.
1 CSE1301 Computer Programming Lecture 12 Functions (Part 1)
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
CS 116 Object Oriented Programming II Lecture 13 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Lecture 3.1 Operators and Expressions Structured Programming Instructor: Prof. K. T. Tsang 1.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
CS 1428 Final Exam Review. Exam Format 200 Total Points – 60 Points Writing Programs – 45 Points Tracing Algorithms and determining results – 20 Points.
Dr. Sajib Datta Sep 3,  A new operator used in C is modulus operator: %  % only used for integers, not floating-point  Gives the integer.
CSE 220 – C Programming Pointers.
Moonzoo Kim CS Dept. KAIST
Relational & Logical Operators
Relational and Logical Operators
Introduction to Programming
Relational and Logical Operators
C Operators, Operands, Expressions & Statements
LOOPS BY: LAUREN & ROMEO.
Basic Examples Function Examples Limitation Examples
Unit 3 Test: Friday.
Basic Examples Function Examples Limitation Examples
Relational and Logical Operators
Basic Examples Function Examples Limitation Examples
How to Seed an Initial Test Case to CREST
Exercise Arrays.
Relational and Logical Operators
Lecture 14: Problems with Lots of Similar Data
REPETITION Why Repetition?
Presentation transcript:

CREST Examples -Basic Examples -Function Examples -Limitation Examples

Basic Example 1 // Hello CREST example. // This example shows how to define a symbolic variable. #include // for CREST #include int main(){ int x; CREST_int(x); // Define x as a symbolic input. printf("x = %d\n", x); if (x > 100){ printf("x is greater than 100\n"); }else{ printf("x is less than or equal to 100\n"); } return 0; }

Basic Example 2 // Another Hello CREST example. // CREST can handle linear integer arithmetic expression // and nested condition statements #include int main() char x, y; CREST_char(x); CREST_char(y); printf("x, y = %d, %d\n", x, y); if (2 * x == y){ if (x != y + 10) printf("Fine here\n"); else printf("ERROR\n"); } return 0; }

Basic Example 3 // Symbolic value propagation example. // In an assign statement, if RHS has a symbolic variable and the symbolic // variable is used in linear integer arithmetic expression, LHS will be // a symbolic variable #include int main(){ int x, y; CREST_int(x); printf("x = %d\n", x); y = 2 * x + 3; if (y == 7) printf("y(=2x+3) is 7\n"); else printf("y(=2x+3) is NOT 7\n"); }

Function Example 1 // Simple function example // Symbolic variable can be passed into a function. #include void test_me(char x, char y){ // body of test_me is same to basic2 example if (2 * x == y){ if (x != y + 10){ printf("Fine here\n"); }else{ printf("ERROR\n"); } int main(){ char a, b; CREST_char(a); CREST_char(b); printf("a, b = %d, %d\n", a, b); test_me(a, b); return 0; }

Function Example 2 // Another simple function example. // A function can return a symbolic value #include int sign(int x){ return (x >= 0);} int main(){ int a; CREST_int(a); printf("a = %d\n", a); if (sign(a) == 0) printf(“%d is negative\n”, a); else printf(“%d is non-negative\n”,a); return 0; }

Function Example 3 // Recursive function example. // CREST can handle a recursive function. // A recursive function can generate infinite # of iterations. #include unsigned int fac(unsigned int n){ if (n == 0) return 1; else return n * fac(n-1); } int main(){ unsigned int a; CREST_unsigned_int(a); printf("a = %u\n", a); if (fac(a) == 24) printf("Reach!\n"); return 0; }

Limitation 1: No Real Numbers // Real numbers cannot be handled by CREST #include int main(){ int x; CREST_int(x); printf("x = %d\n", x); if (x == ){ printf("x is 4\n"); }else{ printf("x isn't 4\n"); } return 0; }

Limitation 2: No Non-linear Arithmetic Expression // CREST cannot handle a non-linear arithmetic expression #include int main(){ int x; CREST_int(x); printf("x = %d\n", x); if (x * x == 4){ printf("ERROR\n"); }else{ printf("Fine\n"); } return 0; }

Limitation 3: No External Binary Library // External library example. // When a target program calls an external library function, // CREST may occur 'prediction failure' error since CREST // does not know a body of the external function #include int main(){ int x; CREST_int(x); printf("x == %d\n"); if (x == abs(x)){ printf("x >= 0\n"); }else{ printf("x <= 0\n"); } return 0; }

Limitation 4: No Symbolic Dereference // Symbolic dereference is not supported. // If an array index is a symbolic variable, CREST cannot solve // the generated formula correctly. #include int main(){ int x; int array[4]; CREST_int(x); printf("x = %d\n", x); array[0] = 0; array[1] = 1; array[2] = 2; array[3] = x; if (array[x] == 3) printf("ERROR\n"); else printf("Fine\n"); }