How to use 2NF definition to show that a relation is in 2NF - database-theory

I have this Relation:
(City, State, Governor, Population)
Given FDs:
City, State -> Population
State -> Governor
Governor -> State
I understand this to be the a minimal cover of FDs.
How do we show this is in 2NF?
Definition for 2NF from Wikipedia:
A relation is in the second normal form if it fulfills the following two requirements: It is in first normal form. It does not have any non-prime attribute that is functionally dependent on any proper subset of any candidate key of the relation.
So for this we need to look at all possible FDs we could arrive at by reformulating the original dependencies.
Applied to my example:
Candiate-Keys are: City, State and City, Governor
and the only non-prime attribute in my example is Population.
So we need to show that the FDs:
(City, State) -> Population ;
(City, Governor) -> Population
are contained in the closure of the set of functional dependencies above
if we reduce any attribute from the left side, that FD is not contained in the closure.
We can determine this with the closure algorithm by plugging in both left sides and showing that through the given dependencies we will arrive at population (the right side).
The closure of (City, State) and (City, Governor) both contain Population, respectively. But any subset of them will not.
Is this somewhat correct?

Related

Plantuml sequence diagram lifeline for async execution

Here is my sample shown also on picture below
#startuml
participant "Client" as C
participant "Server" as S
participant "Third Party" as 3PT
C -> S++: request money
S -> S: do I know you?
S -> 3PT++: give me money for client
return here you have money
S ->> S++ #005500: compute usage
S ->> 3PT: notify about computation details
deactivate S
return money
#enduml
Is it possible in PlantUml sequence diagram somehow define the lifeline for async operation to end after lifeline from which it was started? So in this case I'd like to finish the compute usage in green lifeline after return from request money lifeline. By that I would say that compute usage is asynchronous operation and can end at any time. Don't know whether this is valid from UML point of view though.
As I know there is no way for a reflexive message like S ->> S++:... or S ->> S:... to start from an OccurrenceSpecification and finish to an other (and that for a lot of tools, including mine), so the only way seems to represent the Server two times. To clearly indicate it is the same server you can indicate the name the instance, for instance (naming all instances):
#startuml
participant "c:Client" as C
participant "s:Server" as S
participant "tp:Third Party" as 3PT
participant "s:Server" as Sagain
C -> S++: request money
S -> S: do I know you?
S -> 3PT++: give me money for client
return here you have money
S ->> Sagain++: compute usage
C <-- S: money
deactivate S
Sagain ->> 3PT: notify about computation details
deactivate Sagain
#enduml
The norm says §17.12.17.1 lifelines represent only one interacting entity, but an entity can be presented by several lifelines :
norm § 17.12.17.4 (association ends of Lifeline)
represents : ConnectableElement [0..1] (opposite A_represents_lifeline::lifeline)
References the ConnectableElement within the classifier that contains the enclosing interaction
norm § 17.13.31.2 (Owned Ends of A_represents_lifeline)
lifeline : Lifeline [0..*] (opposite Lifeline::represents)
(notice the multiplicity 0..*)
Out of your problem it is strange to see the message do I know you? alone without consequences depending on the result, PlantUML manages combined fragment alt to indicate alternatives

UML Statemachine - Reuse state

I'm trying to model a state machine which reuses a state in order to reduce complexity.
I've got three states: State A, B and X.
My state X can either be entered via a transaction from state A or B.
State X includes multiple substates with lots of complexity and I don't wont to implement it twice.
After the process in state X is completed I need to transition back to back to state A or B based on which one was the previous state.
Is there a elegant way to solve this?
State X includes multiple substates with lots of complexity and I don't wont to implement it twice
Define a submachine corresponding to your state X and in your current machine use submachine state to instantiate it where you need
See §14.2.3.4.7 Submachine States and submachines page 311 in formal-17-12-05 :
Submachines are a means by which a single StateMachine specification can be reused multiple times. They are similar to encapsulated composite States in that they need to bind incoming and outgoing Transitions to their internal Vertices.
...
NOTE. Each submachine State represents a distinct instantiation of a submachine, even when two or more submachine States reference the same submachine.
A SubMachine will help you to reuse several time part of your state modelling.
But if you want to be able to enter into your state X from A or B and then retun to the previous state, ShallowHistory Would be a good idea.
In the following state machine, I modeled a SubMachine X referenced by both states X1 and X2. I also wanted to model the fact that state X2 in processed after A or B and then next state if the previous one.
Another solution consists in playing with transition guards or events/triggers. You must keep in mind that transitions are triggered when specific events occurs or when its guard is true cf. following screenshot.

How to create a 100% declarative model?

I am creating a simple model of a network. The network contains nodes. Nodes send and receive data.
Here's one way to model the network: Each node has a "data" field representing the data possessed by the node at time t. Each node also has a "send" field recording the data sent to other nodes at time t.
sig Node {
data: Data -> Time,
send: Data -> Node -> Time
}
In the spectrum between 100% declarative and 100% imperative, I don't think that that signature is at the 100% declarative side. In my first paragraph I said nothing about nodes having data stores, nothing about keeping a record of sent data.
Also, isn't "send" a verb? Isn't that a sign that the model is not as declarative as it could be? Shouldn't declarative models exclusively use nouns?
I want my model to be at the 100% declarative end of the spectrum. To achieve that, I must simply state what "is". Let's do it!
What is is there are nodes:
sig Node {}
What is is that at any time t, a node has data.
sig Node {
data: Data -> Time
}
What is is that the network has wires between nodes.
sig Network {
wire: Node -> Node
}
What is is that data d is on a wire between time t and t' ...
Let me stop there. Is the second approach that I sketched out more declarative? Is there an approach that is even more declarative?
How to model a network in a 100% declarative manner?
I think you need to separate the semantic content of the model, which is one issue, from the names used in it. To me, the essence of a declarative model is that it records observations -- which may be about state, or about dynamic things like transitions -- expressed in logic. The alternative, an operational model, is to describe behavior and states by building up sequences of primitive actions. A simple example: modeling an action that picks an element non-deterministically from a set. An operational spec might treat the set as ordered, and then use a loop to walk through the set, at each step tossing a coin, and returning the given element when the toss first comes up heads. This models the intuitive operational description: "go through the elements of the set one at a time, and pick one to return". A declarative spec would simply say that the returned value is an element of the set -- nothing else needs to be said.
Regarding the use of names in your particular model, it seems that a larger issue to me is whether the names convey directly what they mean. So send to me is not a very helpful name; a better one would be sentAt.

UML State Machine: Transition selection

I'm trying to collect informations to be able to program a correct transition selection algorithm for an UML State Machine.
The UML Superstructure Specification (15.3.12 StateMachine) states
Only transitions that occur in mutually orthogonal regions may be fired simultaneously.
Does "mutually orthogonal" imply that the regions are on the same nesting level?
For each state at a given level, all originating transitions are evaluated to determine if they are enabled.
This sounds to me like they have to be on the same nesting level. Right? Because if a transition is found on a certain nesting level, the search ends...
The seciton "Transition selection algorithm" once again is not totally clear to me:
The only non-trivial issue is resolving transition conflicts across orthogonal states on all levels. This is resolved by terminating the search in each orthogonal
state once a transition inside any one of its components is fired.
To make this a little more haptic I created 2 models:
Model 1
Model 2
Active state configuration:
State1, State3, State4, State7
Example 1a
In case of an event Event1 which transitions fire?
a. Does only the one from State7 to State 5 fire?
b. Or also then one from State3 to State8?
Both variations would yield in a legal active state configuration.
But my understanding is, that a is correct
Example 1b
Same for model 2.
Example 2a
In case of an event Event2 which transitions fire?
a. Does only the one from State7 to State 5 fire?
b. Or also then one from State3 to State2?
In this case I would say that b would lead to an illegal active state configuration.
Does this mean the model is ill-formed or would only one of the transitions be fired?
Example 2b
Same for model 2. Any difference?
I'd interpret mutually orthogonal to mean that the side effects of the transitions have no impact on each other.
So in either of your diagrams, the transitions triggered by Event1 can be deemed to be mutually orthogonal as the transitions are both contained within [A] and [B] and may be fired simultaneously. Event2 cannot as the transition from within [A] leaves A and State1 (and therefore also [B]).

Modelling a vending box using Alloy

I am trying to model a vending machine program using alloy . I wish to create a model in which I could insert some money and provide the machine a selection option for an item and it would provide me the same and in case the money supplied is less then nothing would be provided .
Here I am trying to input a coin along with a button as input and it should return the desired item from the vending machine provided the value ie. amount assigned to each item is provided as input. So here button a should require ten Rs, button b requires 5 rs, c requires 1 and d requires 2 . The op instance is the item returned once the money required is inserted. opc is the balance amount of coins to be returned. ip is input button and x is money input . How can I provide an instance such that it intakes multiple coins as input and also if the amount is greater than the item cost then it should return a no of coins back. If I could get some help it'll be greatly appreciated.
If I were you, I'd proceed by asking myself what kinds of entities I care about; you've done that (signatures for coins and items -- do you also need some notion of a customer?).
Next, I'd ask myself what constitutes a legal state for the system -- sometimes it helps to think about it backwards by asking what would constitute an illegal or unacceptable state.
Then I'd try to define operations -- you've already mentioned insertion of money and selection of an item -- as transitions from one legal state of the system to the next.
At each stage I'd use the Analyzer to examine instances of the model and see whether what I'd done so far makes sense. One example of this pattern of defining entities, states, and state transitions in that order is given in the Whirlwind Tour chapter of Daniel Jackson's Software Abstractions -- if you have access to that book, you will find it helpful to review that chapter.
Good luck!
module vending_machines
open util /ordering[Event]
fun fst:Event{ordering/first}
fun nxt:Event->Event{ordering/next}
fun upto[e:Event]:set Event{prevs[e]+e}
abstract sig Event{}
sig Coin extends Event{}
pred no_vendor_loss[product:set (Event-Coin)]
{
all e:Event | let pfx=upto[e] | #(product&pfx)<=#(Coin&pfx)

Resources