Upload
faunus
View
86
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Tabular Representation. Based on: Ryszard Janicki, David L. Parnas, and Jeffery Zucker. Tabular Representations in Relational Documents. Relational Methods in Computer Science, Springer-Verlag, 1996. 1. 1. 1. Outline. Motivation Simple tabular notation (raw table) - PowerPoint PPT Presentation
Citation preview
111
Tabular Representation
Based on:
Ryszard Janicki, David L. Parnas, and Jeffery Zucker.Tabular Representations in Relational Documents. Relational Methods in Computer Science, Springer-Verlag, 1996.
1
222
Outline
• Motivation• Simple tabular notation (raw table)• Full tabular notation (well-done table)
– Cell connection graph– Table predicate rule– Table relation rule
2
333
Motivation---Modeling Requirements
• Monitored vs. controlled environmental quantities– Abstracted to mathematical variables whose values changed
over time, i.e., time function.– Monitored: to be measured by the system (mi)– Controlled: to be controlled by the system (ci)
• Requirements documented with two relations– NAT: describes the environment
• dom (NAT): set of vectors of time-function m’s• ran (NAT): set of vectors of time-function c’s• (m, c) NAT iff the environment allows
– REQ: describes the effect of the system• dom (REQ): set of vectors of time-function m’s• ran (REQ): set of vectors of time-function c’s considered permissible• (m, c) REQ iff the system should permit
3
444
Motivation---Modeling Requirements
• Monitored vs. controlled environmental quantities– Abstracted to mathematical variables whose values changed
over time, i.e., time function.– Monitored: to be measured by the system (mi)– Controlled: to be controlled by the system (ci)
• Requirements documented with two relations– NAT: describes the environment
• dom (NAT): set of vectors of time-function m’s• ran (NAT): set of vectors of time-function c’s• (m, c) NAT iff the environment allows
– REQ: describes the effect of the system• dom (NAT): set of vectors of time-function m’s• ran (NAT): set of vectors of time-function c’s considered permissible• (m, c) NAT iff the system should permit
4
Requirements can be documented as mathematical relations or functions!
55
Motivation
• Describe the following function in Z and OCL
f(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
66
Motivation
• Describe the following function in Z and OCL
f(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
77
In Z
f: Z Z Z
f(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
88
In Z
f: Z Z Z
x: Z, y: Z
(x 0 y = 10 f(x,y) = 0) (x < 0 y = 10 f(x,y) = x) (x 0 y > 10 f(x,y) = y2 ) (x 0 y < 10 f(x,y) = -y2) (x < 0 y > 10 f(x,y) = x + y) (x < 0 y < 10 f(x,y) = x – y)
f(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
99
In OCL
context Math::f(x: Integer, y: Integer): Integer
pre: true
post: result = if x >= 0 and y = 10 then 0 else
if x < 0 and y = 10 then x else
if x >= 0 and y > 10 then y*y else
if x >= 0 and y < 10 then –y*y else
if x < 0 and y > 10 then x + y else
if x < 0 and y < 10 then x – y else 0
endif endif endif endif endif endif
f(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
1010
In OCL
context Math::f(x: Integer, y: Integer): Integer
pre: true
post: result = if x >= 0 and y = 10 then 0 else
if x < 0 and y = 10 then x else
if x >= 0 and y > 10 then y*y else
if x >= 0 and y < 10 then –y*y else
if x < 0 and y > 10 then x + y else
if x < 0 and y < 10 then x – y else 0
endif endif endif endif endif endif
f(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
Not very readable or checkable!
1111
Use a Table?
y = 10 y > 10 y < 10
x 0
x < 0
f(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
x y2 x + y
x -y2 x - y
1212
Tabular RepresentationElements• Header: an indexed set of cells, H = {hi | i I}, where I = {1,2, …, k}• Grid indexed by headers H1, …, Hn, with Hj = {hi
j | i Ij}, j = 1,.., n: an indexed set of cells G = {g | g I}, where I = I1 … In
Raw table skeleton• A collection of headers plus a grid indexed by this collection
h11 h2
1 h31
h12
h22
g11 g21 g31
g12 g22 g32
H1 = {hi1 | i = 1, 2, 3}
H2 = {hi2 | i = 1, 2}
G = {gij | i = 1, 2, 3 and j = 1, 2}
1313
Why Tabular Representations of Relations?
• Conventional math descriptions– Too complex to parse to be really useful– Lengthy and hard to read and understand
• Digital system– Not continuous <-> continuous function of
analog– Domain and range: tuple of distinct types
1414
ExerciseUsing the tabular notation, specify a program that reserves a golf tee time. • The standard green fee is $65 on weekdays (Monday-Friday) and $80 on
weekend (Saturday and Sunday). • However, an El Paso resident pays a reduced green fee of $45 and $60 on
weekdays and weekend, respectively. • A senior (of age 60+) pays only $40 and $50 on weekdays and weekend,
respectively.• A junior (of age <17) pays only $20 and $30 on weekdays and weekend,
respectively.
1515
Sample Solution
weekdays weekend
age < 17 $20 $30
17 age < 60
and resident
$45 $60
17 age < 60
and non-resident
$65 $80
age 60 $40 $50
Q: Nested tables for resident/non-resident (thanks to Elsa)?
1616
Exercise
• Specify the following function.
g(x,y) = x + y if (x < 0 y 0) (x < y y < 0)
x - y if (0 x < y y 0) (y x < 0 y < 0)
y - x if (x y y 0) (x 0 y < 0)
1717
Inverted Table
• A header specifies the output of the function.
x + y x - y y - x
y 0
y < 0
x < 0 0 x < y x y
x < y y x < 0 x 0
H1
H2 G
1818
Cell Connection Graph (CCG)
• Characterizes information flow, i.e., where do I start reading the table and where do I get the result?
• A relation interpreted as an acyclic directed graph– Each arch must either start from or end at the grid G.
H1
H2 H3G
H1
H2 H3G
H1
H2 H3G
H1
H2 H3G
1919
Cell Connection Graph (CCG)
• Characterizes information flow, i.e., where do I start reading the table and where do I get the result?
• A relation interpreted as an acyclic directed graph– Each arch must either start from or end at the grid G.
H1
H2 H3G
H1
H2 H3G
H1
H2 H3G
H1
H2 H3G
But, how the domain and values of the relation specified are determined? E.g., how to combine the cells?
2020
Well-Done Table Skeleton
• Table skeleton with– Table predicate rule, PT specifying the domain
– Table relation rule, RT specifying the relation
H1
H2G
H1 H2
G
PT(H1,H2) = H1 H2
RT(G) = G
2121
Exercise
• Write the PT and RT of the following table and explain how to interpret the table.
H1
H2G
G
H1 H2
H1
H2G
H1
H2G
H1
H2
2222
Examplef(x,y) = 0 if x 0 y = 10
x if x < 0 y = 10
y2 if x 0 y > 10
-y2 if x 0 y < 10
x + y if x < 0 y > 10
x – y if x < 0 y < 10
y = 10 y > 10 y < 10
x 0
x < 0
x y2 x + y
x -y2 x - y
H1 H2
G
G
H1
H2
2323
ExerciseUsing the full tabular notation, specify a program that reserves a golf tee time. • The standard green fee is $65 on weekdays (Monday-Friday) and $80 on
weekend (Saturday and Sunday). • However, an El Paso resident pays a reduced green fee of $45 and $60 on
weekdays and weekend, respectively. • A senior (of age 60+) pays only $40 and $50 on weekdays and weekend,
respectively.• A junior (of age <17) pays only $20 and $30 on weekdays and weekend,
respectively.
2424
Exercise1. Using Z and the tabular notation, specify a program that hires an
employee for a company. The program takes an employee’s name, gender, SSN, job position, and salary, and adds the employee to the company’s employee database. It should detect when some of the employee’s information is missing or invalid:– when the gender is not specified– when the job position is not specified– when the salary is less than 0– when there already exists an employee with the same SSN
2. Compare the Z specification and the tabular specification. Is there any significant difference, and if so, which is better and why?
25
Solution
emps’ = emps {e} r = ok
emps’ = emps r {s_err, g_err}
emps’ = emps r {n_err, p_err}
emps’ = emps r ALL_ERR
e.gener e.gender =
e.ssn ok
e.ssn not ok
Assume a state variable emps, an input e and an output r. ALL_ERR denotes {n_err, s_err, g_err, p_err}.
e.pos
e.pos =
e.salary > 0 e.salary 0H1 H2 H3 H4
G
H1
H4
H3
H2 G
Incomplete
26
Solution
ssn ok pos ok
ssn ok (pos ok)
(ssn ok) pos ok
(ssn ok) (pos ok)
salary > 0 gender ok
salary < 0 (gender ok)
salary 0 gender ok
salary 0 (gender ok)
H1 H2
G
H1
H2 G
es’ = es {e} r = ok
es’ = es r {g_err}
es’ = es r {s_err}
es’ = es r {g_err, s_err}
es’ = es r {p_err}
es’ = es r {p_err, g_err}
es’ = es r {p_err, s_err}
es’ = es r {p_err, g_err,
s_err}
es’ = es r {n_err}
es’ = es r {n_err, g_err}
es’ = es r {n_err, s_err}
es’ = es r {n_err, g_err,
s_err}
es’ = es r {n_err, p_err}
es’ = es r {n_err, p_err,
g_err}
es’ = es r {n_err, p_err,
s_err}
es’ = es r {n_err, p_err,
g_err, s_err}