1 / 21

Algebraic Example – OBJ3

Algebraic Example – OBJ3 . Tarang Garg Srikumar Nagaraj. OBJ3 - Revision. “ OBJ3 is a wide spectrum first order functional language that is rigorously based upon equational logic.” Based on order sorted equational logic

bobby
Télécharger la présentation

Algebraic Example – OBJ3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algebraic Example – OBJ3 Tarang Garg Srikumar Nagaraj cs599 - Formal Methods in Software Architecture

  2. OBJ3 - Revision “ OBJ3 is a wide spectrum first order functional language that is rigorously based upon equational logic.” • Based on order sorted equational logic • Provides notion of ‘Subsort’ that rigorously supports multiple inheritance • Exception handling and Overloading • It is a theorem prover • It gives powerful support for design and verification cs599 - Formal Methods in Software Architecture

  3. Cruise Control “ The objects are identified by the Nouns in the specification and the interaction between the objects are identified by the Verbs.” Objects : Vehicle (not a required object for specs) brake accelerator pedal CC(cruise control) button On /Off CC button Set/Accelerator CC button Resume/Decelerator cs599 - Formal Methods in Software Architecture

  4. Cruise Control Assumptions: *************************************************************************** 1. If cruise-speed = 0 then the car is not cruising and if cruise-speed <> 0 then the car is cruising. 2. cruise_state represents the button. 3. Max. allowed speed is 140 mph. 4. The car does not take any time to change speeds. **************************************************************************** th CAR-STATE is sort INT . protecting INT . protecting TRUTH-VALUE . op init1_ : INT  INT . op init2_ : TRUTH-VALUE  TRUTH-VALUE . vars curr_speed cruise_speed last_cruise_speed : INT . var cruise_state : TRUTH-VALUE . eq init1 curr_speed = 0 . eq init1 cruise_speed = 0 . eq init1 last_cruise_speed = 0 . eq init2 cruise_state = false . endth cs599 - Formal Methods in Software Architecture

  5. Cruise Control obj CC-ON-OFF[V-CAR-STATE :: CAR-STATE] . protecting TRUTH-VALUE . op cruise-press_ : TRUTH-VALUE  TRUTH-VALUE . var I : TRUTH-VALUE . cq cruise-press (cruise_state) = (I = false) *** This checks for the cruise control button if it is ON if cruise-state == true . eq cruise-state = I . cq cruise-press (cruise-state) = (I = false) and (last-cruise-speed = 0) *** This checks for the cruise control button if it is OFF if cruise-state == false . endo cs599 - Formal Methods in Software Architecture

  6. Cruise Control obj CC-SET-ACCELERATE[V-CAR-STATE :: CAR-STATE] . protecting INT . protecting TRUTH-VALUE . op button-press_ _ _ : INT INT TRUTH-VALUE  INT INT INT . op button-press_ _ : INT TRUTH-VALUE  INT INT . op time_ : INT  INT . vars X Y : INT . cq button-press (cruise-speed , curr-speed , cruise-state) = (cruise-speed = curr-speed) and (last-cruise-speed = cruise-speed) if (cruise-state == true) and (curr-speed > 30) and (curr-speed < 90) and (cruise-speed = 0) . cq button-press (cruise-speed , cruise-state) = (cruise-speed = cruise-speed + Y) and (last-cruise-speed = cruise-speed) if (cruise-state == true) and (cruise-speed > 30) and (cruise_speed < 90) . eq time X = Y . endo *** Assumption: Time is a function which takes time in seconds(X) for which SET is pressed & gives *** the speed factor(Y) to add to cruise-speed. cs599 - Formal Methods in Software Architecture

  7. Cruise Control obj CC-RESUME-DECELERATE[V-CAR-STATE :: CAR-STATE] . protecting INT . protecting TRUTH-VALUE . op button-press_ _ _ _ : INT INT INT TRUTH-VALUE  INT INT .. op button-press_ _ : INT TRUTH-VALUE  INT INT . op time_ : INT  INT . vars X Y : INT . cq button-press (cruise-speed , curr-speed , last-cruise-speed, cruise-state) = (cruise-speed = last-cruise-speed) if (cruise-state == true) and (curr-speed > 30) and (curr-speed < 90) and (cruise-speed == 0) and (last-cruise-speed =/= 0) . cq button-press (cruise-speed , cruise-state) = (cruise-speed = cruise-speed – Y ) and (last-cruise-speed = cruise-speed) if (cruise-state == true) and (cruise-speed =/= 0) . eq time X = Y . endo ***Assumption: Time is a function which takes time in seconds(X) for which RESUME is *** pressed and gives the speed factor(Y) to subtract to cruise-speed. cs599 - Formal Methods in Software Architecture

  8. Cruise Control obj ACCELERATOR-PEDAL[V-CAR-STATE :: CAR-STATE] . protecting INT . op pedal-press_ _ : INT INT  INT . op time_ : INT  INT . op uphill _ _ : INT INT  INT . vars X Y : INT . cq pedal-press (curr-speed , cruise-speed) = (curr-speed = curr-speed + Y) if (cruise-speed == 0) and (curr-speed < 140) . eq time X = Y . cq uphill (curr-speed, cruise-speed) = ( curr-speed = curr-speed + Z) and (cruise-speed = curr-speed) if (cruise-speed =/= 0) and (current-speed < cruise-speed) . endo *** Assumption: Time is an operation which takes time in seconds(X) for which pedal is *** pressed and returns the factor(Y) by which the speed is to be increased. *** ‘Z’ is a factor which gives the drop in the speed when the car goes uphill cs599 - Formal Methods in Software Architecture

  9. Cruise Control obj BRAKE-PEDAL[V-CAR-STATE :: CAR-STATE] . protecting INT . op pedal-press_ _ : INT INT  INT . op pedal-press_ : INT  INT INT INT . op time_ : INT  INT . op downhill _ _ : INT INT  INT . vars X Y : INT . cq pedal-press (curr-speed , cruise-speed) = (curr-speed = curr-speed – X) if (cruise-speed == 0) and (curr-speed > 0) . cq pedal-press (cruise-speed) = (cruise-speed = 0) and (last-cruise-speed = 0) if (cruise-speed =/= 0) . eq time X = Y . eq downhill (curr-speed, cruise-speed) = ( curr-speed = curr-speed - Z) and (cruise-speed = curr-speed) if (cruise-speed =/= 0) and (current-speed > cruise-speed) . endo *** Assumption: Time is an operation which takes time for which the pedal is pressed and *** returns the factor by which the speed is decreased. *** ‘Z’ is the factor which gives the increase in the speed when the car goes downhill cs599 - Formal Methods in Software Architecture

  10. Gas Station Assumptions ************************************************************************ 1. When the customer goes to the cashier & pays cash, the cashier allots a pump no. & a password to the customer. 2. Pump has one nozzle and three buttons for premium, plus & regular. 3. type-of-gas has integer values viz. plus  1 $1.90 per gallon regular  2 $ 1.80 per gallon premium  3 $ 2.00 per gallon ************************************************************************ Objects: pump nozzle customer cashier car (unnecessary) Gas tank car tank (unnecessary) sensor meter on the pump (unnecessary) cs599 - Formal Methods in Software Architecture

  11. Gas Station th PASSWORD is sort INT . protecting INT . protecting TRUTH-VALUE . op init1_ : TRUTH-VALUE  TRUTH-VALUE . op init2_ : INT  INT . var enable-pump : TRUTH-VALUE . vars pump-password-value customer-password-value : INT . eq init1 enable-pump = false . eq init2 pump-password-value = 0 . eq init2 customer-password-value = 0 . endth th TANK-STATES is sort INT . protecting INT . op init1_ : INT  INT . vars amount-gas-car-tank amount-gas-station-tank : INT . eq init1 amount-gas-car-tank = 0 . eq init1 amount-gas-station-tank > threshold . endth *** Assumption: threshold is some integer value which is pre-defined for the tank. *** Initially we are assuming that the gas in the GAS STATION TANK is greater than threshold. cs599 - Formal Methods in Software Architecture

  12. Gas Station th GAS-STATE is sort INT . protecting INT . protecting FLOAT . protecting TRUTH-VALUE . op init1_ : TRUTH-VALUE  TRUTH-VALUE . op init2_ : INT  INT . vars nozzle-up lever-press : TRUTH-VALUE . var type-of-gas amount-gas-dispensed : INT . var amount-charged : FLOAT . eq init1 nozzle-up = false . eq init1 lever-press = false . eq init2 type-of-gas = 0 . eq init2 amount-gas-dispensed = 0 . eq init2 amount-charged = 0 . endth *** the gas is not selected right now cs599 - Formal Methods in Software Architecture

  13. Gas Station th CASH-STATE is sort INT . protecting INT . protecting TRUTH-VALUE . op init1_ : TRUTH-VALUE  TRUTH-VALUE . op init2_ : INT  INT . vars cash-given-by-customer pump-number : INT . var receipt : TRUTH-VALUE . eq init1 receipt = false . eq init2 cash-given-by-customer = 0 . eq init2 cash-received-as-change = 0 . eq init2 pump-number = 0 . endth *** initially there is no cash transaction cs599 - Formal Methods in Software Architecture

  14. Gas Station obj PUMP[V-PASSWORD :: PASSWORD , V-GAS-STATE :: GAS-STATE] . protecting INT . protecting FLOAT . protecting TRUTH-VALUE . op give-receipt_ _ : INT INT  FLOAT . op choose-gas-type_ _ : TRUTH-VALUE TRUTH-VALUE  INT . op calculate-rate_ : FLOAT  FLOAT . var X : FLOAT . var Y : INT . cq give-receipt (amount-gas-dispensed , type-of-gas) = (amount-charged = (amount-gas-dispensed * X)) if (type-of-gas =/= 0) and (amount-gas-dispensed =/= 0) . cq choose-gas-type (nozzle-up , lever-press) = (type-of-gas = Y) if (nozzle-up == true) and (lever-press == false) . eq calculate-rate (type-of-gas) = (X = 1.80) if (type-of-gas == 2). eq calculate-rate (type-of-gas) = (X = 1.90) if (type-of-gas == 1). eq calculate-rate (type-of-gas) = (X = 2.00) if (type-of-gas == 3). endo *** ‘Y’ is 1 when type of gas chosen is ‘PLUS’ *** ‘Y’ is 2 when type of gas chosen is ‘REGULAR’ *** ‘Y’ is 3 when type of gas chosen is ‘PREMIUM’ cs599 - Formal Methods in Software Architecture

  15. Gas Station obj NOZZLE[V-GAS-STATE :: GAS-STATE] . protecting INT . protecting TRUTH-VALUE . op dispense-gas_ _ _ : TRUTH-VALUE TRUTH-VALUE INT  INT INT . op lift-nozzle_ _ : INT INT  TRUTH-VALUE . op keep-nozzle-back_ _ : TRUTH-VALUE TRUTH-VALUE  INT TRUTH-VALUE . op lever-press_ _ : TRUTH-VALUE INT  TRUTH-VALUE . op cal_ : INT  INT . vars X Y : INT . cq dispense-gas (nozzle-up , lever-press , type-of-gas) = (amount-gas-car-tank = amount-gas-car-tank + Y) and (amount-gas-station-tank = amount-gas-station-tank – Y) if (nozzle-up == true) and (lever-press == true) and (type-of-gas =/= 0) . cq lift-nozzle (pump-password-value , customer-password-value) = (nozzle-up = true) if (pump-password-value == customer-password-value) . cq keep-nozzle-back (nozzle-up , lever-press) = (customer-password-value = 0) and (nozzle-up = false) if (nozzle-up == true) and (lever-press == false) . cq lever-press (nozzle-up , type-of-gas) = (lever-press = true) if (nozzle-up == true) and (type-of gas =/= 0) . eq cal X = Y . endo *** cal is a function which calculates the amount of gas dispensed taking the time for which the nozzle is *** pressed. The customer comes to the pump assigned and enters the password for enabling the pump cs599 - Formal Methods in Software Architecture

  16. Gas Station obj CUSTOMER[V-CASH-STATE :: CASH-STATE] . protecting INT . protecting FLOAT . protecting TRUTH-VALUE . op gives-cash_ _ : INT INT  INT . op receives-balance_ _ _ : TRUTH-VALUE FLOAT FLOAT  TRUTH-VALUE FLOAT . op receives-receipt_ _ : TRUTH-VALUE INT  TRUTH-VALUE . var cash : FLOAT . cq gives-cash (customer-password-value , cash-given-by-customer) = (cash-given-by-customer = cash) if (customer-password-value == 0) and (cash-given-by-customer == 0) . cq receives-balance (nozzle-up, cash-given-by-customer, amount-charged) = (enable-pump = false) and (cash-received-as-change = cash-given-by-customer – amount-charged) and (customer-password-value = 0) if (nozzle-up == false) and (cash-given-by-customer =/= 0) and (cash-given-by-customer > amount-charged) . cq receives-receipt (nozzle , amount-gas-dispensed) = (receipt = true) if (nozzle-up == false) and (amount-gas-dispensed =/= 0) and (amount-charged =/= 0). endo *** cash is the amount of cash given by the customer to cashier for the gas.

  17. Gas Station obj CASHIER[V-CASH-STATE :: CASH-STATE] . protecting INT . protecting FLOAT . protecting TRUTH-VALUE . op receives-cash_ : INT  FLOAT INT INT TRUTH-VALUE . op gives-change_ _ _: TRUTH-VALUE INT FLOAT  TRUTH-VALUE INT INT INT . var cash : FLOAT . var pval : INT . cq receives-cash (cash-given-by-customer) = (cash-given-by-customer = cash ) and (pump-password-value = pval) and (customer-password-value = pval) and (enable-pump = true) if (cash-given-by-customer == 0) . cq gives-change (nozzle, amount-gas-dispensed, amount-charged) = (enable-pump = false) and (pump-password-value = 0 ) and (customer-password-value = 0) and (amount-gas-dispensed = 0) if (nozzle == false) and (amount-gas-dispensed =/= 0) and (amount-charged =/=0) . endo ***pval is a randomly generated number which is given as password to each customer. It *** never repeats. cs599 - Formal Methods in Software Architecture

  18. Gas Station obj GAS-TANK-PUMP[V-TANK-STATES :: TANK-STATES] . protected INT . op supply-gas-to-pump_ : INT  INT . var X : INT . cq supply-gas-to-pump (amount-gas-station-tank) = (amount-gas-station-tank = amount-gas-station-tank + X) if (amount-gas-station-tank < threshold) . endo *** Assumption: threshold is the pre-defined value for the tank. *** ‘X’ is the value of gas required to make the gas station tank full, it depends on the amount of gas already present in the tank. obj SENSOR[V-GAS-STATES :: GAS-STATES] . protecting INT . protecting TRUTH-VALUE. var max-tank-capacity : INT. op sense-gas-full_ : INT  TRUTH-VALUE . cq sense-gas-full (amount-gas-car-tank) = (lever-press = false) if (amount-gas-car-tank == max-tank-capacity) . endo *** max-tank-capacity is the maximum capacity of the gas car tank (dependent on the type of car), i.e. car specific. cs599 - Formal Methods in Software Architecture

  19. Inferences • It goes in a lot of details like the sorts and the subsorts • It is good in a place where accuracy is the prime issue and the details are the requirement while modeling the system. • Where lot of calculations are required. • It has got an Exceptional handling feature which can be very efficiently used to handle exceptions. • Very near to the implementation languages specially OOPS like C++ and Java, etc. • Would be liked by the coder.(directly lead to the code) • Not very good for state based problems, difficult to represent states. cs599 - Formal Methods in Software Architecture

  20. Our Approach • Dependent on OOPs • Chose the Objects (nouns of the specs) • Then chose the theories • Chose the operations for each object (interactions) • Then declared the objects with their operations. • Extensively used function overloading. • Made assumptions where ever required. cs599 - Formal Methods in Software Architecture

  21. Difficulties Faced • There is no form of diagrams here which explains the details of the problem. If the spec is very complicated then it is very difficult to understand. • It can be used in the intermediate stage of design and implementation, but not for design, if the specs are very complicated. • Did not understand the use of views. • Did not use any Exception handling feature of OBJ3. cs599 - Formal Methods in Software Architecture

More Related