Introduction to Sets and Logic - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Sets and Logic

Description:

Introduction to Sets and Logic Why do we need to know a bit of set theory? Set theory allows us to describe and classify entities So it allows us to describe and ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 19
Provided by: HPAuthor592
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Sets and Logic


1
Introduction to Sets and Logic
  • Why do we need to know a bit of set theory?
  • Set theory allows us to describe and classify
    entities
  • So it allows us to describe and group the data
    that we may need to use for testing
  • Set theory allows us to operate on groups of
    entities
  • So it allows us to operate on groupings of test
    data
  • Set theory allows us to extend the study to
    relations and functions
  • So it allows us to relate test data or test
    scenarios and expected results
  • Why do we need to know a bit about logic?
  • Propositional logic allows us to manipulate
    statements and truth values of the statements
    predicate logic allows us to introduce
    quantifiers such as there exists or all
  • So it allows us to describe and combine test
    conditions and deduce validity of test coverage
    or validity of test results.

Set theory and logic, while useful for all
aspects of testing, it is most useful with
functional testing (black box testing)
2
What is a set ?
  • A set is a collection or a group of something.
  • For example a set of items in a classroom may
    be represented as follows.
  • Classrooom_items chair1, chair2, desk1,
    student 1, student2, desk2, desk3, chair3,
    instructor, whiteboard, computer
  • Student_ages 18, 17, 23, 19
  • A word of caution a set can not have repetition.
  • If you had two students of the same age, then you
    may be tempted to say
  • Student_ages 17, 18, 18, 23
  • but in set theory you can only say
  • Student_ages 17, 18, 23

incorrect
correct
3
Different Ways to Represent a Set
  • A) Listing the elements that belong to the set,
    just as shown earlier
  • my_lucky_ numbers 3, 106, 7689, -4
  • B) Providing a decision rule that defines the set
  • possible_male_ages age 0 lt age 200
  • C) Combinations of or redefinition of sets
  • students_in_class boy_students U girl_students

There is a special set called the empty set which
contains no element. It is represented with the
symbol, Ø. For example the set,
possible_male_age age age -3, is an
empty set. So this set is Ø.
4
Common Set Operations
  • Union union of set A and set B is the
    combination of sets A and B, represented as A U
    B.
  • If A apple, orange, grapes and B shoe,
    tie, shirt, then AUB apple, orange, grapes,
    shoe, tie, shirt
  • Intersection intersection of set A and B is the
    set whose elements are composed of only the
    common elements from set A and set B, represented
    as A n B.
  • If A and B are as defined above, then AnB
    Ø
  • If A apple, grape, orange and B
    tomato, grape, lettuce, then AnB grape
  • Complement complement of a set A is the set that
    has all the elements that are not in A,
    represented as A or A
  • If A numbers numbers gt 0 , then A
    numbers numbers 0

5
Some more Set Operations
  • Minus set A minus set B is the set which
    contains all elements in A that is not in B,
    represented as (A B). this set is sometimes
    known as relative complement of B with respect
    to A.
  • If A 2, 34, 67, 98, -3, -54, -300 and B
    integers integers 0, then (A B)
    2,34,67,98
  • Symmetric Difference the symmetric difference of
    sets A and B, represented as A B, is a set
    that is defined as the result of operations, A
    U B A n B
  • If A apple, orange, grape and B pear,
    grape, orange, then A B apple, pear



6
Specification vs Implementation vs Test Cases
Specification
Implementation
Actual
Expected
2
3
1
5
4
6
7
Look at this earlier Venn Diagram
Tested
The area represented by number 2 may be
represented as Expected nActual Tested
Test Cases
7
A few More Definitions
  • Set A is a subset of set B, written A B, if
    every element in A is also an element in B.
  • Set A is a proper subset of set B, written A
    B, if it is a subset of B and there exists at
    least one element in B that is not in A (or B A
    ? Ø).
  • Set A and set B are equal, written A B, if
    every element in A is in B and vise versa.

8
Set Partition
  • A partitioning of a set is a division of a set
    into groups. This is a useful concept for many
    areas where we want to take samples from groups
    formed based on some criteria.
  • Example performing an opinion survey of
    teenagers on clothes. We may partition the survey
    by
  • Age groups - 13 to 15 , 16 to 17, 18 to
    19
  • Gender - male , female
  • Types of schools - Catholic, Jewish,
    Baptist, non-religious public
  • This concept is important when we have to design
    test cases based on picking the input data.
  • Formally, a dividing of a set X into subset x1,
    x2, - - - xn is called a partitioning of X if the
    following is true
  • a) x1 U x2 U - - - U xn X
  • b) for any xi and xk , where i ?
    k , xi n xk Ø

For later Discuss - partitioning the outputs of
the triangle problem for testing
9
Some Rules about sets
  • A U Ø A
  • A n Ø Ø
  • (A) A
  • Commutative rules A U B B U A A n B B n A
  • Associative rules A U (B U C) (A U B) U C
  • A n (B n C)
    (A n B) n C
  • Distributive rules A n (B U C) (A n B) U (A n
    C)
  • A U (B n C) (A U
    B) n (A U C)
  • DeMorgans rules (A U B) A n B
  • (A n B)
    A U B

10
Informally - Relation
  • A Relation is, as the English word says, a
    connection between two sets.
  • Given a set A Tom, Sam, Sally, Jane and a set
    B (Joe, Mary, Abe, then a relation such as
    parent of may be defined between these set B and
    A. If Joe is the father of Sam and Mary is the
    mother of Tom, then the relation, B parent of
    A, is true with some of the elements.
  • For the above sets of A and B, there may or may
    not be any meaningful relation.

11
Relationship between Two Sets
SWE_students
Good_Programs
written by
The arrows represent the relationship, written
by. Then one can see that 3 of the
Good_Programs are written by 2 of the SWE
students.
12
Relation (more formally)
  • Given two sets A and B, the cross-product of A x
    B is the set composed of paired items, where
    first element of the pair is from A and the
    second element of the pair is from B.
  • Example A 3. 4, 8 and B mod_x, mod_y
    then cross-product of A x B (3, mod_x), (4,
    mod_x), (8,mod_x),
  • (3,
    mod_y), (4, mod_y) , (8, mod_y)
  • Given a set A and a set B, a relation, R, is a
    subset of cross-product of A and B. So R A x
    B .
  • Example A tom, mary and B abu, kathy,
    A x B (tom, abu), (tom, kathy), (mary, abu),
    (mary, kathy) .
  • If kathy is the sister of tom, then a
    relation, R, called brother of is a subset of A
    x B where brother of (tom, kathy)

13
Some Properties of Relation
  • A relation, R1, defined over a set A, is said to
    be reflexive if for every a in set A, (a,a) is in
    R1.
  • Example If A is set of positive integers and R1
    is the relation, then R1 is reflexive because
    every positive integer itself. But if R1 were
    defined as gt, then R1 is not reflexive.
  • A relation, R2, is said to be symmetric if for
    every (a,b) in R2, (b,a) is also inR2.
  • Example if for (a,b) in R2 means a is bs
    classmate, then b is also as classmate. Thus
    (b,a) is also in R2. But if R2 is defined as
    (a,b) mean a is bs father, the R2 is not
    symmetric.
  • A relation, R3, is said to be transitive if for
    every (a.b) and (b,c) in R3 implies that (a,c) is
    in R3.
  • Example If R3 is defined as gt, then (7,4) and
    (4,2) in R3 implies that (7,2) is also in R3
    because 7 gt 2.
  • Example R3 defined as mother of relation is
    not transitive

There is a relation called equivalence relation
which is reflexive, symmetric, and transitive. We
will use the partitioning of test data into
subsets that are each considered to be an
equivalence class and pick a test case from each
class.
14
Function
  • Function is a special type of relation.
  • A relation, RF, is a function if for every (x,y)
    in RF and (x,z) in RF implies that y z.

RF is a function
RF is a non-function
Is the inverse, RF-1, a function?
Is the inverse, RF-1, a function?
15
Simple Logic Propositional Calculus
  • A proposition is a statement.
  • A proposition, just like a statement, carries the
    value of True or False, but not both.
  • Example Let X be the proposition, Howard is a
    student in SWE 3643. Then X is either True or
    False.
  • Example Let Y be the proposition, It will rain
    tomorrow. Is Y True or False ?

Note that it will rain tomorrow is not a
proposition that can be handled by propositional
calculus because its truth vale can not
determined until tomorrow.
16
Basic Operators of Propositional Calculus
  • Let P and Q be propositions, then the truth
    values of 5 logical operators (NOT,AND, OR,
    Exclusive OR, Implies) is shown in the following
    truth table.

p
q
P ? q
q
P v q
P q

P ? q
T
T
F
T
T
F
T
T
T
F
F
T
T
F
F
T
F
F
T
T
T
F
T
T
F
F
F
F
Legend is NOT ? is logical AND v is
logical OR is logical Exclusive OR ? is
logical Implies.

17
Logical Implies
  • All the truth operations are quite intuitive,
    except for implies, also known as if ---then
  • P implies Q intuitively says that when P is true
    then Q must be true
  • It is also intuitive that when P is true then Q
    can not be false.
  • What happens when P is NOT True?
  • Propositional Calculus defines this situation as
    True regardless of the truth value of Q.
  • Sometimes P implies Q, P ?Q, is stated as
    (P AND Q ) OR (NOT P) .

Look at the previous truth table for (P? Q) OR (
P)
18
Some Logical Expression Rules
  • Simple ones
  • P ? True P
  • P v False P
  • P v True True
  • P ? False False
  • ( P) P
  • P ? Q Q ? P
  • P v Q Q v P
  • Associative (P v Q) v R P v (Q v R) (
    P ? Q) ? R P ? (Q ? R)
  • Distributive P ? (Q v R) (P ? Q) v (P ? R)
  • P v (Q ? R) (P v Q)
    ? (P v R)
  • Demorgans Law (P ? Q) P v Q
  • (P v
    Q) P ? Q

Use the truth table to prove to yourself one of
the DeMorgans Law
Write a Comment
User Comments (0)
About PowerShow.com