1 Values, Types, Variables, Operators Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Relational Algebra Part II
(Fuzzy Set Operations)
Substitution.
Basic Java Constructs and Data Types – Nuts and Bolts
Classes and Objects in Java
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Copyright © 2003 Pearson Education, Inc. Slide 1.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
1 Average Case Analysis of an Exact String Matching Algorithm Advisor: Professor R. C. T. Lee Speaker: S. C. Chen.
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
Problem Solving & Program Design in C
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
ALGEBRAIC EXPRESSIONS
Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity.
5NF and other normal forms
1 Relational Algebra Hugh Darwen (invited lecturer) CS319: Relational Algebra (revisited, reviewed, revised,
1 Introduction to Relational Databases Hugh Darwen CS252.HACD: Fundamentals of Relational Databases.
1 Constraints and Updating Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section 7: Constraints.
1 Database Design Issues, Part I Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section.
1 Relational Algebra, Part III, and Other Operators Hugh Darwen CS252.HACD: Fundamentals of Relational.
1 Fundamentals of Relational Databases Hugh Darwen CS252.HACD: Relational Database Theory (focussing.
1 Relational Algebra, Principles and Part I Hugh Darwen CS252.HACD: Fundamentals of Relational Databases.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
Dr. A.I. Cristea CS 319: Theory of Databases: FDs.
1 Predicates and Propositions Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section 3:
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL3.
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL5.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
ZMQS ZMQS
ADTs unsorted List and Sorted List
Modern Programming Languages, 2nd ed.
ABC Technology Project
Day of the week 9:00 – 10:00 10: :00 12: :00 13: :00 14: :00 15: :00 16:00 – 17:00 17: :00 18:00 – 19:00 19:00 – 20:00.
1 / / / /. 2 (Object) (Object) –, 10 (Class) (Class) –, –, – (Variables) [ Data member Field Attribute](, ) – (Function) [ Member function Method Operation.
1 Structures. 2 Structure Basics A structure is a collection of data values, called data members, that form a single unit. Unlike arrays, the data members.
Basic Permutations and Combinations
Twenty Questions Subject: Twenty Questions
Squares and Square Root WALK. Solve each problem REVIEW:
1 Modeling and Simulation: Exploring Dynamic System Behaviour Chapter9 Optimization.
Chapter 5 Test Review Sections 5-1 through 5-4.
CSci 1130 Intro to Programming in Java
Addition 1’s to 20.
25 seconds left…...
EC-111 Algorithms & Computing Lecture #11 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Copyright © Cengage Learning. All rights reserved.
Test B, 100 Subtraction Facts
Week 1.
We will resume in: 25 Minutes.
FINAL EXAMINATION SCHEDULE SPRING 2009 MAY 15 – MAY 22 NOTE: A class that meets at more than one of the times on this final examination schedule will take.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Interprocedural Analysis. Currently, we only perform data-flow analysis on procedures one at a time. Such analyses are called intraprocedural analyses.
1 Administrivia Lecture hours –Monday, Wednesday, Thursday: 11-11:55am, in L7 –Come to the class in time Labs –2pm-5pm, –Monday: A5-A6, Tuesday: A7-A8,
1 Database Design Issues, Part II Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section.
Chapter 7 Simple Date Types J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Chapter 5 Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.5-2 Topics in this Chapter Values vs. Variables Types vs. Representations.
CS201 – Introduction to Computing – Sabancı University 1 Built-in Arrays l C++ native array type (not the class version) l Two versions ä fixed size arrays.
Pointers A pointer type variable holds the address of a data object or a function. A pointer can refer to an object of any one data type; it cannot refer.
Introduction to Relational Databases
Presentation transcript:

1 Values, Types, Variables, Operators Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section 2: Values, Types, Variables, Operators

2 Anatomy of an Imperative Example: Y := X + 1 ; Denotes a variable Denotes current value of a variable Denotes a value A read-only operator An update operator An invocation (of +) X and 1 are arguments to the invocation of + Y and X+1 are arguments to the invocation of :=

3 Important Distinctions The following very important distinctions emerge from all this and should be firmly taken on board: Value versus variable Variable versus variable reference Update operator versus read-only operator Operator versus invocation Parameter versus argument Parameter subject to update versus parameter not subject to update

4 A Closer Look at an Operator (+) abc and so on (ad infinitum) Look – its a relation! The predicate: a + b = c Attributes a and b can be considered as the parameters of +. Its also a function: no two tuples with the same a value also have the same b value, so, given an a and a b, we know the c.

5 An Operator Definition In Tutorial D: OPERATOR HIGHER_OF ( A INTEGER, B INTEGER ) RETURNS INTEGER ; IF A > B THEN RETURN A ; ELSE RETURN B ; END IF ; END OPERATOR ; So the invocation HIGHER_OF(2,3) = 3

6 What Is a Type? Examples: WEEKDAY: { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } INTEGER: { …, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, … } A type (= domain) is a named set of values. Monday etc. and -7 etc. are literals. Every value of every type should be able to be denoted by some literal.

7 What is a Type For? It is for constraining the values permitted for some purpose. For example, constraining: the values that can be assigned to a variable the values that can be substituted for a parameter the values that an operator can yield when invoked the values that can appear for a given attribute of a relation The declared type (of the variable, parameter, operator or attribute) constrains its possible values to be of that type.

8 What is the Type of This? StudentIdNameCourseId S1AnneC1 S1AnneC2 S2BorisC1 S3CindyC3 S4DevinderC1 Perhaps RELATION { StudentId SID, Name NAME, CourseId CID } where SID is the declared type of StudentId, NAME that of Name, and CID that of CourseId.

9 How to Write This as a Literal? StudentIdNameCourseId S1AnneC1 S1AnneC2 S2BorisC1 S3CindyC3 S4DevinderC1 See next slide …

10 A Relation Literal in Tutorial D RELATION { TUPLE { StudentId S1, CourseId C1, Name Anne }, TUPLE { StudentId S1, CourseId C2, Name Anne }, TUPLE { StudentId S2, CourseId C1, Name Boris }, TUPLE { StudentId S3, CourseId C3, Name Cindy }, TUPLE { StudentId S4, CourseId C1, Name Devinder } } Try: But this assumes that S1, C1, and Boris are themselves valid literals. They arent in most languages, including Tutorial D.

11 Literals for Student Ids, etc Recall the declared types of the attributes: SID, NAME, CID. Suppose that values of type SID are represented by character strings (values of type CHAR). Suppose that character strings are denoted by text in quotes, like this: S1. Then a literal for the student identifier S1 might be: SID ( S1 ) SID ( S1 ) is an invocation of an operator called SID whose single parameter is of type CHAR. We call SID a selector, because it can be used to select any value of type SID.

12 A Tuple Literal TUPLE { StudentId S1, CourseId C1, Name Anne } From our first try: We can now write this as: TUPLE { StudentId SID ( S1 ), CourseId CID ( C1 ), Name NAME( Anne ) } and thats just fine. (See the lecture Notes for the relation literal.) …

13 Types and Representations Consider the invocation SID ( S1 ), a literal of type SID. SID is an operator that, when invoked with a suitable character string, returns a value of type SID. Also, every value of type SID can be denoted by an invocation of operator SID. We call such an operator a selector (for values of the type in question). And the parameters (signature) of a selector we call a possible representation (possrep for short).

14 A Type Definition for SID In Tutorial D: TYPE SID POSSREP SID { C CHAR CONSTRAINT constraint to specify exactly which strings are suitable } ; The definition implies operator definitions: OPERATOR SID ( C CHAR ) RETURNS SID ; OPERATOR THE_C ( S SID ) RETURNS CHAR ; whereby, e.g., THE_C ( SID ( S1 ) ) = S1

15 Type Constraint for SID So, we can write the required type constraint something like this: CONSTRAINT LENGTH ( C ) <= 5 AND SUBSTRING ( C, 0, 1) = S AND IS_DIGITS (SUBSTRING ( C, 1 )) Where: SUBSTRING ( s, pos, 1) returns the substring specified by start position pos (base 0) and length l (or the remainder of s if l omitted), and IS_DIGITS(s) returns TRUE if every character of s is a digit, otherwise FALSE.

16 Defining a Subtype An alternative method for defining a type is available when the required values are a subset of an existing type. For example, positive integers: TYPE POSINT IS { INTEGER CONSTRAINT INTEGER > 0 }; Now: Attributes of type POSINT admit positive values only All operators on integers are available In fact, an expression of type POSINT is permitted wherever one of type INTEGER is permitted (substitutability) But type inheritance is a big subject, beyond the scope of CS252.

17 What Is a Variable? Here is a variable declaration in Tutorial D: VAR SN SID INIT SID ( S1 ) ; imperative key word variable name initial value So a variable has a name, a declared type, and a value. The value can change from time to time. The name and type cannot. declared type

18 Updating a Variable A value is assigned to a variable by invoking an update operator. E.g, assignment (available on variables of all types): SN := SID ( S2 ) ; SN := SID ( LEFT ( THE_C (SN), 1 ) || 5 ) ; Additional update operators might be defined, invoked via CALL: CALL SET_DIGITS ( SN, 23 ) ; Pseudovariable assignment might be supported: THE_C ( SN ) := S2 ; SUBSTR (THE_C ( SN ), 2 ) := 23 ;

19 Important Distinctions Arising You should now be able to distinguish clearly between: values and variables values and representations of values types and representations read-only operators and update operators parameters and arguments operators and invocations

20 EXERCISES (see Notes)