| Author | Joep Suijs, Copyright © 2009, all rights reserved. |
| Adapted-by | |
| Compiler | >=2.4i |
this library provides a (one) byte fifo queue. This queue is interrupt-safe in the sense that you can write to the queue from the interrupt and read from the main program or vice versa without special precautions. Reading (or writing) from both interrupt and main program might not work properly. The basic interface is pseudo var: queue06 = x -- put x into queue; block if queue is full x = queue06 -- read x from queue; block if queue is empty non-blocking access to the same queue is provided by queue06_nb_put() and queue06_nb_get() other methods: queue06_clear() -- clear queue (makes queue empty) queue06_empty() -- returns true if queue is emtpy (depricated, use queue1_is_empty()) queue06_is_empty() -- returns true if queue is emtpy queue06_is_full() -- returns true if queue is full queue06_nr_free() -- returns nr of free places in queue queue06_nr_used() -- returns nr of used places in queue
No dependency found
var volatile byte queue06_in_pointer = 0 ; wijst naar vrije locatie
var volatile byte queue06_data[queue06_size + 1]
var volatile byte queue06_out_pointer = 0 ; wijst naar databyte
queue06_is_empty() return bit
queue06_is_full() return bit
queue06_empty() return bit
queue06_nr_used() return byte
queue06_nb_get(byte out v) return bit
queue06_nb_put(byte in v) return bit
queue06'get() return byte
queue06_nr_free() return byte
queue06_nb'get() return byte
var volatile byte queue06_in_pointer = 0 ; wijst naar vrije locatie
No documentation found
var volatile byte queue06_data[queue06_size + 1]
queue vars
var volatile byte queue06_out_pointer = 0 ; wijst naar databyte
No documentation found
queue06_nb'put(byte in v)
queue06_nb'put - put one byte into queue (non-blocking)
queue06'put(byte in v)
queue06'put - put one byte into queue When the queue is full, it waits until a byte is removed from the queue.
queue06_clear()
deprecated
queue06_is_empty() return bit
queue06_is_empty() -- returns true if queue is emtpy
queue06_is_full() return bit
queue06_is_full() -- returns true if queue is full
queue06_empty() return bit
queue06_nr_used() return byte
queue06_nr_used - returns nr of used places in queue
queue06_nb_get(byte out v) return bit
queue06_nb_get - get one byte from queue (non-blocking) The byte read is put into v (calling param) returns: true when we read a byte from the queue false when the queue is empty (byte is not read from queue)
queue06_nb_put(byte in v) return bit
queue06_nb_put - put one byte into queue (non-blocking) return: true when the byte is put into the queue false when the queue is full (byte is not put in queue)
queue06'get() return byte
queue06'get - get one byte from queue returns byte from queue. When the queue is empty, it waits until a byte is put into the queue.
queue06_nr_free() return byte
queue06_nr_free - returns nr of free places in queue
queue06_nb'get() return byte
queue06_nb'get - get one byte from queue (non-blocking) returns byte from queue, 0 if queue empty


| < Day Day Up > |
Chapter 11. Rule-Based AIIn this chapter we're going to study rule-based AI systems. Rule-based AI systems are probably the most widely used AI systems for both real-world and game AI applications. In their simplest form, rule-based systems consist of a set of if-then style rules that are used to make inferences or action decisions. Technically, we've already looked at one form of rule-based system in Chapter 9 on finite state machines. There we used rules to handle state transitions. We also looked at another type of rule-based system in the previous chapter on fuzzy logic, Chapter 10. In this chapter, we're going to look specifically at rule-based systems that commonly are used in so-called expert systems. Examples of real-world, rule-based expert systems include medical diagnosis, fraud protection, and engineering fault analysis. One advantage of rule-based systems is that they mimic the way people tend to think and reason given a set of known facts and their knowledge about the particular problem domain. Another advantage of this sort of rule-based system is that it is fairly easy to program and manage because the knowledge encoded in the rules is modular and rules can be coded in any order. This gives some flexibility both when coding the system and modifying the system at a later time. These advantages hopefully will become clearer to you as we move through the material in this chapter. Before we get into the details, though, let's discuss a couple of game examples that can use rule-based systems. Imagine you're writing a real-time strategy simulation game involving the typical technology tree, whereby players must train peasants, build facilities, and harvest resources. An illustrative technology tree is shown in Figure 11-1. Figure 11-1. Example technology treeWhat we aim to do here is enable the computer opponent to keep track of the player's current state of technology so that the computer opponent can plan and deploy offensive and defensive resources accordingly. Now, you could cheat and give the computer opponent perfect knowledge of the player's state of technology. However, it would be fair and more realistic to have the computer gain knowledge and make inferences on the state of the player's technology in much the same way that the player will have to so that she can assess the computer opponent's state of technology. Both player and computer will have to send out scouts to collect information and then make inferences given the information as it is received. We can achieve this using a fairly simple rule-based system, as you'll see in this chapter. Let's consider another example. Say you're writing a martial arts fighting game and you want to give the computer the ability to anticipate the player's next strike so that the computer opponent can make the appropriate countermove, such as a counter strike, a dodge, or a parry. The trick here is to somehow keep track of the player's strike patterns—combinations of kicks and punches—and to learn which strike most likely will follow an observed set of previous strikes. For example, if during the fight the player throws a punch, punch combination, what will the player most likely throw next: a punch, a low kick, or a high kick? We can use a rule-based system to achieve such anticipation. We'll come back to this example in much more detail later in this chapter. |
| < Day Day Up > |


| Contact name | City | Country | Is Promoted |
|---|---|---|---|
| Maria Anders | Berlin | Germany | |
| Ana Trujillo | México D.F. | Mexico | |
| Antonio Moreno | México D.F. | Mexico | |
| Thomas Hardy | London | UK |
| Contact name | City | Country | Is Promoted |
|---|---|---|---|
| Maria Anders | Berlin | Germany | |
| Ana Trujillo | México D.F. | Mexico | |
| Antonio Moreno | México D.F. | Mexico | |
| Thomas Hardy | London | UK |


Approximate matrix multiplication [AMM]: In this work, I have focused on computing approximate matrix products that are provably accurate. While working on this problem, I came across the applicability of matrix sketching techniques in this task. This led me to develop an AMM algorithm based on the matrix sketching algorithm mentioned earlier (βFD). Theoretical guarantees with respect to its accuracy were proved and its superior experimental results over the state of the art was demonstrated.


Home
Camera
Gallery
About
Filter Me!
Get Started!
v2.4.1
Warm
Grayscale
Blue
Previous
Next
Simple & Unique —
Our camera app brings in high-end technology as it implements voice recognition to change filters for you!
Learn More


{% extends "home.html" %}
{% block title %}
About the Developer
{% endblock %}
{% block head %}
{{super()}}
{% endblock %}
{% block page_content %}
Mike Caffrey
I am a hardworking senior majoring in Management Information Systems with a concentration in Marketing at the University of Delaware.
I plan to pursue a career in Software Sales after graduation.
The best way to contact me is by email, which is, mcaffrey@udel.edu.


Premium Materials
Our trombones use the shiniest brass which is sourced locally. This will increase the longevity of your purchase.
Our trombones use the shiniest brass which is sourced locally. This will increase the longevity of your purchase.
We make sure you recieve your trombone as soon as we have finished making it. We also provide free returns if you are not satisfied.
For every purchase you make, we will ensure there are no damages or faults and we will check and test the pitch of your instrument.
600$
Lorem Ipsum.
Lorem Ipsum.
Lorem Ipsum Dolor.
Lorem Ipsum.
900$
Lorem Ipsum.
Lorem Ipsum.
Lorem Ipsum Dolor.
Lorem Ipsum.
1200$
Plays similiar to a Trumpet
Great for Jazz Bands
Lorem Ipsum Dolor.
Lorem Ipsum.


Speech-to-Text: Text is displayed on the video closed caption above as the same context is actually spoken on the video. This is achieved by Azure Media Indexer 2 Media Processor (MP) which generates closed captioning tracks. [note] Supported languages include English, Spanish, French, German, Italian, Chinese, Portuguese and Arabic
Text Search: You can search for words or phrases on visual text appears on the video by typing keywords on the search form above. This is achieved by Azure search which indexes digital text generated from Azure Media Indexer 2 and makes them searchable


After graduating from the University of Alabama with a BFA in Graphic Design in 2012 I got a job working for Halifax Media Group doing Graphic Design. I got an opportunity to do web development for them in 2013. Since then, I have built web applications, created rich media ad types, designed splash pages, constructed HTML emails, trained fellow co-workers, and done anything else my swiss army knife of a position required.
I just recently received a promotion to Digital Product Specialist & Frontend Dev with the company that bought Halifax Media Group (Gatehouse) in 2015 where I will continue to do what I do, but on a larger scale.
Outside of work, I enjoy stout beers, coffee, Adventure Time, video games, and sometimes all four at once. The only "sport" I'm any good at is Ping Pong, but I also enjoy disc golf, tennis, kayaking, and really anything where I can run around outside.


Comapny Name |
|
Industry |
|
Website |
|
HQ Phone |
|
Address1 |
|
Address 2 |
|
city |
|
State |
|
Zip Code |
|
Direct Deposit |
John Doe, *****1234, |
|
Paypal |
<EMAIL_ADDRESS>|
|
Updates about my project orders |
|
Occassional emails about the company (products, features, discounts, etc) |
under construction
PayPal is an online payment processing service that allows you to receive paments from Aerial Applications. To use Paypal with Aerial Applications, you must have an existing account with Paypal. Enter the email address associated with your PayPal account.
Is this the correct email address for your existing PayPal account?.
<EMAIL_ADDRESS>PayPal is an online payment processing service that allows you to receive paments from Aerial Applications. To use Paypal with Aerial Applications, you must have an existing account with Paypal. Enter the email address associated with your PayPal account.
Is this the correct email address for your existing PayPal account?.
dronepilot@gmail.com


Mail checks, made payable to First Presbyterian Church, to:
Children are recommended by the Family Resource & Youth Service Center Coordinators at each school. A Place to Sleep has helped children from every shcool in the Shelby County School System, as well as, the immediate surrounding counties.
Some children too young to be enrolled in school have been recommended by Head Start, the Salvation Army, ALC Pregnancy Center, and Seven County Services. On occasion, referrals come from other agencies such as churches, Operation Care, and The Serenity Center. These famileis are still required to work with the Family Resource/Youth Service Centers for an officeial referral. This insures that the children are enrolled and attending school, and enables the schools to help the family find other needed resources.


Heber Jimenez
Contact
Portfolio
About
Portfolio
Hangman
RPG Game
Trivia Game
Rutgers Info Widget
Rock Paper Scissors


Curb Your Litter Mapillary Test -- June 11, 2016
Snapshots (Before & After)
Bedford & Manhattan
Manhattan & Nasau
Nassau & Leonard
Manhattan & Meserole
Full photowalks
June 10, 2016 (Before)
June 11, 2016 (After)


This week in The Dabbler I conduct a long-overdue inquiry into the death of Virginia Woolf. If everything goes according to plan, this should be the first in a series of inquiries into the deaths of the great modernists, a necessary step, surely, into any proper understanding of postmodernism. I have convinced myself that, once I fully grasp every last little detail of the deaths of the modernists, I will be in a much better position to winkle some meaning out of the endless clogged blather of standard po-mo prose. Some would say it is not worth the effort, and they are probably correct, so perhaps I ought to put the whole project into a dustbin or wastepaper basket. What a quandary!


--- layout: page permalink: "/personal/inbetween/" ---
A study of memory loss in people with early onset dementia. A year and a half collaboration with two local Oxfordshire support groups, The Clive Project (now known as Young Dementia UK) and SPECAL. Some Clive Project members chose to take their own photographs and / or tell their story through images, words and video. The former expressions were made into a book, an essential part of an Exhibition which took place in May 2006 at the Jacqueline du Pré Music Building, Oxford.


Aset Kayamas
Home
(current)
Register
FAQ
Contact Us
About Us
Booking
Login
Username
Password
Login
Remember me
Cancel
Forgot Password?


Examples
Printing Text
Custom HTTP Request
Launching a Task
Log
Links Parser
Tab Object
Browser Library
Console Library
All Functions & Libraries
Catalunya Functions


doctools::tcl::parse - Processing text in 'subst -novariables' format
This package provides commands for parsing text with embedded Tcl commands as accepted by the Tcl builtin command subst -novariables. The result of the parsing is an abstract syntax tree.
This is an internal package of doctools, for use by the higher level parsers processing the docidx, doctoc, and doctools markup languages.
The command takes the text and parses it under the assumption that it contains a string acceptable to the Tcl builtin command subst -novariables. Errors are thrown otherwise during the parsing. The format used for these errors in described in section Error format.
The command returns the empty string as it result. The actual result of the parsing is entered into the tree structure tree, under the node root. If root is not specified the root of tree is used. The tree has to exist and be the command of a tree object which supports the same methods as trees created by the package struct::tree.
In case of errors tree will be left in an undefined state.
The same as text, except that the text to parse is read from the file specified by path.
When the parser encounters a problem in the input it will throw an error using the format described here.
The message will contain the reason for the problem (unexpected character or end of input in input), the character in question, if any, and the line and column the problem was found at, in a human readable form. This part is not documented further as its format may change as we see fit. It is intended for human consumption, not machine.
The error code however will contain a machine-readable representation of the problem, in the form of a 5-element list containing, in the order listed below
the constant string doctools::tcl::parse
the cause of the problem, one of
Unexpected character in input
Unexpected end of the input
The location of the problem as offset from the beginning of the input, counted in characters. Note: Line markers count as one character.
The line the problem was found on (counted from 1 (one)),
The column the problem was found at (counted from 0 (zero))
After successfully parsing a string the generated tree will have the following structure:
In the following items the word 'root' refers to the node which was specified as the root of the tree when invoking either text or file. This may be the actual root of the tree.
All the following items further ignore the possibility of pre-existing attributes in the pre-existing nodes. If attributes exists with the same names as the attributes used by the parser the pre-existing values are written over. Attributes with names not clashing with the parser's attributes are not touched.
The root node has no attributes.
All other nodes have the attributes
The value is a string from the set { Command , Text , Word }
The value is either empty or a 2-element list containing integer numbers. The numbers are the offsets of the first and last character in the input text, of the token described by the node,.
The value is an integer, it describes the line in the input the token described by the node ends on. Lines are counted from 1 (one).
The value is an integer, it describes the column in the line in the input the token described by the node ends on. Columns are counted from 0 (zero).
The children of the root, if any, are of type Command and Text, in semi-alternation. This means: After a Text node a Command node has to follow, and anything can follow a Command node, a Text or other Command node.
The children of a Command node, if any, are of type Command, and Text, and Word, they describe the arguments of the command.
The children of a Word node, if any, are of type Command, Text, in semi-alternation. This means: After a Text node a Command node has to follow, and anything can follow a Command node, a Text or other Command node.
A Word node without children represents the empty string.
All Text nodes are leaves of the tree.
All leaves of the tree are either Text or Command nodes. Word nodes cannot be leaves.
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category doctools of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.
Documentation tools
Copyright © 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>


The "I Know Stuff" Library
Title
Author
Pages
Read
Delete
New Book
Select status
Read
Not Read
Submit


Use the charts below to explore the dataset
| Belly Button Sample Data |
|---|
| Age: |
| BBTYPE: |
| Ethnicity: |
| Gender: |
| Location: |
| Sample: |
| Run the routes to get data |
|---|
| Routes to test the python json construction to build plotly charts |
| /otu - get the details on the bacteria |
| /metadata/ |
| /metadata/ |
| /samples/ |


SweetFreeStuff.com
///////////////////////////////////////////
Free Sample Friskies 7 Cat Food
Posted: 24 Jun 2015 11:00 AM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Free Sample of Friskies 7 Cat Food
The post Free Sample Friskies 7 Cat Food appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Free Rachael Ray Nutrish for Cats Sample
Posted: 24 Jun 2015 10:00 AM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Select the free sample offer and complete the form. Free Rachael Ray
Nutrish for Cats Sample
The post Free Rachael Ray Nutrish for Cats Sample appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Free Benefit Cosmetics Luggage Tag at Sephora inside JCPenney
Posted: 24 Jun 2015 09:28 AM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
No purchase necessary. Must be a registered Beauty Insider to redeem. Offer
valid at Sephora inside JCPenney stores starting 6/22 through 7/23/15,
while supplies last. Free Benefit Cosmetics Luggage Tag at Sephora inside
JCPenney
The post Free Benefit Cosmetics Luggage Tag at Sephora inside JCPenney
appeared first on SweetFreeStuff.com.
///////////////////////////////////////////
Free Stuff for Joining TNT Club
Posted: 24 Jun 2015 07:27 AM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Join the TNT Club to receive free gifts and special offers like posters,
stickers, magnets, tattoos and more. Free Stuff for Joining TNT Club
The post Free Stuff for Joining TNT Club appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Free Paul Mitchell Mirror Smooth Sample
Posted: 24 Jun 2015 06:09 AM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Free Paul Mitchell Mirror Smooth Sample
The post Free Paul Mitchell Mirror Smooth Sample appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Free Always Discreet Sample Pack
Posted: 24 Jun 2015 01:00 AM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
They have underwear sample packs available. Free Always Discreet Sample Pack
The post Free Always Discreet Sample Pack appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Free Poise Pad Sample Kit
Posted: 24 Jun 2015 12:00 AM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
The post Free Poise Pad Sample Kit appeared first on SweetFreeStuff.com.
///////////////////////////////////////////
Free LOreal Hair Care Samples
Posted: 23 Jun 2015 11:42 PM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Free L’Oreal Hair Care Samples
The post Free L’Oreal Hair Care Samples appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Free Nordic Naturals Wellness Sample Kit
Posted: 23 Jun 2015 10:05 PM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Click Free Sample on the lower right side of the page,
The post Free Nordic Naturals Wellness Sample Kit appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Free RedBox DVD Rental
Posted: 23 Jun 2015 07:00 PM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Text message: FREEBIE to 727272 for a free 1 night rental. Expires June
30th. Free RedBox DVD Rental
The post Free RedBox DVD Rental appeared first on SweetFreeStuff.com.
///////////////////////////////////////////
Free Thumb Socks from DoSomething.org
Posted: 23 Jun 2015 06:52 PM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
For ages 13-25.
The post Free Thumb Socks from DoSomething.org appeared first on
SweetFreeStuff.com.
///////////////////////////////////////////
Earn Cash and Prizes for Scanning your Purchases - NCP
Posted: 23 Jun 2015 04:03 PM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Earn Free Cash and Prizes from National Consumer Panel Click Here to Sign
up! As a panel member, the National Consumer Panel will provide you with a
hand-held scanner. Every time you or members of your household shop, youll
use the scanner to scan the barcodes on all of your purchases. Then, once
a Continue reading Earn Cash and Prizes for Scanning your Purchases NCP
The post Earn Cash and Prizes for Scanning your Purchases NCP appeared
first on SweetFreeStuff.com.
///////////////////////////////////////////
Free Atkins Quick Start Kit
Posted: 22 Jun 2015 11:04 PM PDT
http://feedproxy.google.com/&edburner&utm_medium=email
Register for the Atkins Community to get your Free Atkins Quick Start Kit
The post Free Atkins Quick Start Kit appeared first on SweetFreeStuff.com.


Bus Router
Options
Bus Route
Select Bus Route
Tester
Old Online Api versions
Select Stop
Select Stop


Great white sharks are moving to Florida for the winter
KEY WEST, Fla. (AP) - Like snowbirds, there's another group that's moving the Florida for the winter: sharks.
Shark experts say the coast of Florida is starting to heat up with white shark activity. OCSEARCH , a research group, says the annual migration to warmer waters off the Florida and Carolinas coasts is underway.
The Palm Beach Post reports that eight white sharks tagged by the Utah-based research group were spotted from New Jersey to Florida in the last week.
Three other sharks that had been tagged were detected Wednesday in waters on North Carolina beaches, and two more sharks -Helena and the 2,076-pound Unama'ki -made their presence known with toothy grins just west of Key West in September.
Unama'ki had been tagged off Nova Scotia in September. She's a big girl -some 15-feet, 5-inches.
It's not unusual for great whites to call southern waters home during winter and sightings are common near popular fishing and diving spots in Florida through spring.
___
Information from: The Palm Beach (Fla.) Post, http://www.pbpost.com
(Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.)


The idea here is to only use the d attribute of the svg shape and cache the filters, templates and gradients so loading an svg is almost as cheap as loading a string
| radius : | 50 |
| strokeWidth : | 1 |
| ringStrokeWidth : | 0 |
| ringStroke : | "#777" |
| ringFill : | "#777" |
| shape : | "cube" |
| fill : | "rgba(92, 69, 84, 0.2)" |
| stroke : | "#777" |
| viewBox : | "0 0 64 64" |


KEYS:
+ : add new anchor at mouse position
- : delete selected anchor
q/a : increase/decrease exponent for matrix distance weighting
w/s : increase/decrease exponent for point weighting
MOUSE:
click or drag: drag anchor origin or target


Selected Tutorials
- Elemental Selenium
- Free Code Camp
- Harvard/Yale CS50
- Testing React components With Enzyme and Jest
- Easy Node Authentication
- CodePen Challenges
- Accessibility Testing
- How to test Storybook components in Angular applications
- Test Automation U
- Intern Tutorial
- XPath in Selenium WebDriver
- Getting Started with AWS Lambda
- React Boot Camp
- Building a CRUD application with Flask and SQLAlchemy
- Your First Progressive Web App
- A Tour of Go
- JavaScript DOM Tutorial
- 2018 Fall Online Test Conference
- Web App Security Fundamentals
- TCP/IP
- The Full JavaScript & ES6 Tutorial
- Introduction to jQuery


Computer Architecture
[Unit-1:Introduction]
1.) Expanded Structure of IAS computer
Fig: Expanded structure of IAS computer Memory buffer register
(MBR):-
Contains a word to be stored in memory or sent to the I/O unit, or is used to receive a word from memory or from the I/O unit.Memory address register (MAR) :-
Specifies the address of memory in the word to be written from or read into the MBR.Instruction register (IR) :-
Contains the 8 bits Opcode instruction being executed.Instruction buffer register (IBR):-
Employed to hold temporarily the right- hand instruction from a word in memory..
Program counter (PC):-
Contains the address of the next instruction-pair to be fetched from memory.Accumulator (AC) and multiplier quotient (MQ):-
Employed to hold temporarily operands and results of ALU operations. For example, the result of multiplying two 40-bit numbers is an 80-bit number; the most significant 40 bits are stored in the AC and the least significant in the MQ.Central processing unit (CPU):-
Controls the operation of the computer and performs its data processing functions; often simply referred to as processor.I/O:-
Moves data between the computer and its external environment.2.) Flow chart of IAS Computer:-
The IAs operates by respectively performing as instruction cycle. Each instruction cycle consists of two sub-cycles.
Fetch Cycle:-
The opcode of next instruction is loaded into the IR and the address portion is loaded into the MAR. This instruction may be taken from the IBR, or it can be obtained from memory by loading a word into the MBR, and then down to the IBR, IR and MAR.Execute Cycle
The control circuitry interprets the Opcode & executes the instruction by sending out the appropriate control signals to cause data to be moved or an operation to be performed by the ALU.3.)IAS instruction format:-
The memory of IAS consists of 1000 storage locations called words of 40 binary digits each. Both data & instructin are stored there, Number are represented in binary form.Fig. IAS Format
Each number is represented by a sign bit and a 39 bit value. A word may also contain 20 bit instruction consisting of an 8 bit operation code(opcode) specifying the operation to be performed and 12 bit address designing one of the words in memory (numbered from 0 to 999)
IAS computer had a total of 21 instruction that can be grouped as follows.
Data transfer:-
Move data between memory and ALU register or between two ALU registers.Unconditional branch:-
The control unit executes instruction in sequence from memory. There sequence can be changed by a branch instruction which facilitates repetitive operations.Conditional branch:-
Branch can be made dependent on a condition thus allowing decision part.Arithmetic:-
It comprises operation performed by ALUAddress modify:-
It permits address to be computed in ALU and then inserted into instruction stored in memory.4.) The difference between computer Organization and Computer Architecture:-
Computer organization
- Deals with all physical components of computer systems that interacts with each other to perform various functionalities.- The lower level of computer organization is known as micro- architecture which is more detailed and concrete.
- Examples of Organizational attributes includes Hardware details transparent to the programmer such as control signal and peripheral.
Computer architecture
- Refers as a set of attributes of a system as seen by programmer- Examples of the Architectural attributes include the instruction set, the no of bits used to represent the data types, Input Output mechanism and technique for addressing memories.
The difference between architecture and organization is best described by a non-computer example. Is the gear level in a motorcycle part of it is architecture or organization? The architecture of a motorcycle is simple; it transports you from A to B. The gear level belongs to the motorcycle's organization because it implements the function of a motorcycle but is not part of that function
5.)Scale Of Integration:-
The number of components fitted into a standard size IC represents its integration scale, in other words it’s a density of components. It is classified as follows: SSI – Small Scale Integration
It have less than 100 components (about 10 gates).
MSI – Medium Scale Integration
It contains less than 500 components or have more than 10 but less than 100 gates.
LSI – Large Scale Integration
Here number of components is between 500 and 300000 or have more than 100 gates.
VLSI – Very Large Scale Integration
It contains more than 300000 components per chip
VVLSI - Very Very Large Scale Integration
It contains more than 1500000 components per chip.


This packages contents are automatically generated and provide base classes for MOD:CA objects.
A Base class is either a {@link org.afplib.base.SF} (structured field) or a {@link org.afplib.base.Triplet} which represents a MOD:CA triplet, SDF, CS or GOCA Command


Once you've downloaded mui, here's what to do next.Once you've downloaded mui, here's what to do next
166个浏览


Home
Search
Libraries
Instruments
Get In
Music Gives You Wings!!
MUSIC IS LIFE
THAT'S WHY HEARTS HAVE BEATS
Hearts Matter !
Discover Music
Instruments lookup
MUSIC IS LIFE
THAT'S WHY HEARTS HAVE BEATS
Hearts Matter !
Discover Music
Instruments lookup
MUSIC IS LIFE
THAT'S WHY HEARTS HAVE BEATS
Hearts Matter !
Discover Music
Instruments lookup


Distributions that are typically used for exposure rating in general insurance, in particular to price reinsurance contracts. The vignettes show code snippets to fit the distribution to empirical data.
| Version: | <IP_ADDRESS> |
| Depends: | R (≥ 3.4), fitdistrplus (≥ 1.0-7), alabama |
| Imports: | Rcpp, utils, actuar, gsl, MASS |
| LinkingTo: | Rcpp |
| Suggests: | testthat, copula, pander, knitcitations, rmarkdown, knitr, lattice |
| Published: | 2018-08-01 |
| Author: | Giorgio Spedicato [aut, cre], Christophe Dutang [aut], Markus Gesmann [ctb] |
| Maintainer: | Giorgio Spedicato <spedicato_giorgio at yahoo.it> |
| Contact: | Giorgio Spedicato<EMAIL_ADDRESS>|
| BugReports: | http://github.com/spedygiorgio/mbbefd/issues |
| License: | GPL-2 |
| URL: | http://github.com/spedygiorgio/mbbefd |
| NeedsCompilation: | yes |
| SystemRequirements: | GNU make |
| Materials: | README NEWS ChangeLog |
| In views: | Distributions |
| CRAN checks: | mbbefd results |
| Reference manual: | mbbefd.pdf |
| Vignettes: |
Exposure rating, destruction rate models and the mbbefd package test-beta |
| Package source: | mbbefd_<IP_ADDRESS>.tar.gz |
| Windows binaries: | r-devel: mbbefd_<IP_ADDRESS>.zip, r-release: mbbefd_<IP_ADDRESS>.zip, r-oldrel: mbbefd_<IP_ADDRESS>.zip |
| OS X binaries: | r-release: mbbefd_<IP_ADDRESS>.tgz, r-oldrel: mbbefd_<IP_ADDRESS>.tgz |
| Old sources: | mbbefd archive |
Please use the canonical form https://CRAN.R-project.org/package=mbbefd to link to this page.


ImpSimple Imperative Programs
(* $Date: 2011-10-10 12:42:15 -0400 (Mon, 10 Oct 2011) $ *)
In this chapter, we begin a new direction that we'll
continue for the rest of the course: up to now we've been mostly
studying Coq itself, but from now on we'll mostly be using Coq to
formalize other things.
Our first case study is a simple imperative programming language
called Imp. Here is a familiar mathematical function written in
Imp.
A minor technical point: Instead of asking Coq to import our
earlier definitions from Logic.v, we import a small library
called Sflib.v, containing just a few definitions and theorems
from earlier chapters that we'll actually use in the rest of the
course. You won't notice much difference, since most of what's
missing from Sflib has identical definitions in the Coq standard
library. The main reason for doing this is to tidy the global Coq
environment so that, for example, it is easier to search for
relevant theorems.
Z ::= X;
Y ::= 1;
WHILE not (Z = 0) DO
Y ::= Y * Z;
Z ::= Z - 1
END
This chapter looks at how to define the syntax and semantics
of Imp; the chapters that follow develop a theory of program
equivalence and introduce Hoare Logic, the best known logic for
reasoning about imperative programs.
Y ::= 1;
WHILE not (Z = 0) DO
Y ::= Y * Z;
Z ::= Z - 1
END
Sflib
Arithmetic and Boolean Expressions
Inductive aexp : Type :=
| ANum : nat → aexp
| APlus : aexp → aexp → aexp
| AMinus : aexp → aexp → aexp
| AMult : aexp → aexp → aexp.
Inductive bexp : Type :=
| BTrue : bexp
| BFalse : bexp
| BEq : aexp → aexp → bexp
| BLe : aexp → aexp → bexp
| BNot : bexp → bexp
| BAnd : bexp → bexp → bexp.
In this chapter, we'll elide the translation from the
concrete syntax that a programmer would actually write to these
abstract syntax trees — the process that, for example, would
translate the string "1+2*3" to the AST APlus (ANum
1) (AMult (ANum 2) (ANum 3)). The file ImpParser.v develops a
simple implementation of a lexical analyzer and parser that can
perform this translation. You do not need to understand that
file to understand this one, but if you haven't taken a course
where these techniques are covered (e.g., a compilers course) you
may want to skim it.
For comparison, here's a conventional BNF (Backus-Naur Form)
grammar defining the same abstract syntax:
Compared to the Coq version above...
It's good to be comfortable with both sorts of notations: informal
ones for communicating between humans and formal ones for carrying
out implementations and proofs.
Evaluating an arithmetic expression reduces it to a single number.
aexp ::= nat
| aexp '+' aexp
| aexp '-' aexp
| aexp '*' aexp
bexp ::= true
| false
| aexp '=' aexp
| aexp '<=' aexp
| bexp 'and' bexp
| 'not' bexp
| aexp '+' aexp
| aexp '-' aexp
| aexp '*' aexp
bexp ::= true
| false
| aexp '=' aexp
| aexp '<=' aexp
| bexp 'and' bexp
| 'not' bexp
- The BNF is more informal — for example, it gives some
suggestions about the surface syntax of expressions (like the
fact that the addition operation is written + and is an
infix symbol) while leaving other aspects of lexical analysis
and parsing (like the relative precedence of +, -, and
*) unspecified. Some additional information — and human
intelligence — would be required to turn this description
into a formal definition (when implementing a compiler, for
example).
The Coq version consistently omits all this information and concentrates on the abstract syntax only.
- On the other hand, the BNF version is lighter and arguably
easier to read. Its informality makes it flexible, which is
a huge advantage in situations like discussions at the
blackboard, where conveying general ideas is more important
than getting every detail nailed down precisely.
Indeed, there are dozens of BNF-like notations and people switch freely among them, usually without bothering to say which form of BNF they're using because there is no need to: a rough-and-ready informal understanding is all that's needed.
Evaluation
Fixpoint aeval (e : aexp) : nat :=
match e with
| ANum n => n
| APlus a1 a2 => (aeval a1) + (aeval a2)
| AMinus a1 a2 => (aeval a1) - (aeval a2)
| AMult a1 a2 => (aeval a1) * (aeval a2)
end.
Example test_aeval1:
aeval (APlus (ANum 2) (ANum 2)) = 4.
Proof. reflexivity. Qed.
Similarly, evaluating a boolean expression yields a boolean.
Fixpoint beval (e : bexp) : bool :=
match e with
| BTrue => true
| BFalse => false
| BEq a1 a2 => beq_nat (aeval a1) (aeval a2)
| BLe a1 a2 => ble_nat (aeval a1) (aeval a2)
| BNot b1 => negb (beval b1)
| BAnd b1 b2 => andb (beval b1) (beval b2)
end.
Optimization
Fixpoint optimize_0plus (e:aexp) : aexp :=
match e with
| ANum n =>
ANum n
| APlus (ANum 0) e2 =>
optimize_0plus e2
| APlus e1 e2 =>
APlus (optimize_0plus e1) (optimize_0plus e2)
| AMinus e1 e2 =>
AMinus (optimize_0plus e1) (optimize_0plus e2)
| AMult e1 e2 =>
AMult (optimize_0plus e1) (optimize_0plus e2)
end.
To make sure our optimization is doing the right thing we
can test it on some examples and see if the output looks OK.
Example test_optimize_0plus:
optimize_0plus (APlus (ANum 2)
(APlus (ANum 0)
(APlus (ANum 0) (ANum 1))))
= APlus (ANum 2) (ANum 1).
Proof. reflexivity. Qed.
But if we want to be sure the optimization is correct —
i.e., that evaluating an optimized expression gives the same
result as the original — we should prove it.
Theorem optimize_0plus_sound: ∀ e,
aeval (optimize_0plus e) = aeval e.
Proof.
intros e. induction e.
Case "ANum". reflexivity.
Case "APlus". destruct e1.
SCase "e1 = ANum n". destruct n.
SSCase "n = 0". simpl. apply IHe2.
SSCase "n <> 0". simpl. rewrite IHe2. reflexivity.
SCase "e1 = APlus e1_1 e1_2".
simpl. simpl in IHe1. rewrite IHe1.
rewrite IHe2. reflexivity.
SCase "e1 = AMinus e1_1 e1_2".
simpl. simpl in IHe1. rewrite IHe1.
rewrite IHe2. reflexivity.
SCase "e1 = AMult e1_1 e1_2".
simpl. simpl in IHe1. rewrite IHe1.
rewrite IHe2. reflexivity.
Case "AMinus".
simpl. rewrite IHe1. rewrite IHe2. reflexivity.
Case "AMult".
simpl. rewrite IHe1. rewrite IHe2. reflexivity. Qed.
Coq Automation
Tacticals
The try Tactical
The ; Tactical
T; [T1 | T2 | ... | Tn]
is a tactic that first performs T and then performs T1 on the
first subgoal generated by T, performs T2 on the second
subgoal, etc.
T; [T' | T' | ... | T']
That is, if T and T' are tactics, then T;T' is a tactic that
first performs T and then performs T' on each subgoal
generated by T. This is the form of ; that is used most often
in practice.
Lemma foo : ∀ n, ble_nat 0 n = true.
Proof.
intros.
destruct n.
(* Leaves two subgoals... *)
Case "n=0". simpl. reflexivity.
Case "n=Sn'". simpl. reflexivity.
(* ... which are discharged similarly *)
Qed.
We can simplify the proof above using the ; tactical.
Lemma foo' : ∀ n, ble_nat 0 n = true.
Proof.
intros.
(* Apply destruct to the current goal *)
destruct n;
(* then apply simpl to each resulting subgoal *)
simpl;
(* then apply reflexivity to each resulting subgoal *)
reflexivity.
Qed.
Using try and ; together, we can get rid of the repetition in
the proof that was bothering us a little while ago.
Theorem optimize_0plus_sound': ∀ e,
aeval (optimize_0plus e) = aeval e.
Proof.
intros e.
induction e;
(* Most cases follow directly by the IH *)
try (simpl; rewrite IHe1; rewrite IHe2; reflexivity).
Case "ANum". reflexivity.
Case "APlus".
destruct e1;
(* Most cases follow directly by the IH *)
try (simpl; simpl in IHe1; rewrite IHe1; rewrite IHe2; reflexivity).
(* The interesting case, on which the above fails, is
when e1 = ANum n. In this case, we have to destruct n
(to see whether the optimization applies) and rewrite
with the induction hypothesis. *)
SCase "e1 = ANum n". destruct n;
simpl; rewrite IHe2; reflexivity. Qed.
In practice, Coq experts often use try with a tactic like
induction to take care of many similar "straightforward" cases
all at once. Naturally, this practice has an analog in informal
proofs. Here is an informal proof of this theorem that
matches the structure of the formal one:
Theorem: For all arithmetic expressions e,
This proof can still be improved: the first case (for e = ANum
n) is very trivial — even more trivial than the cases that we
said simply followed from the IH — yet we have chosen to write it
out in full. It would be better and clearer to drop it and just
say, at the top, "Most cases are either immediate or direct from
the IH. The only interesting case is the one for APlus..." We
can make the same improvement in our formal proof too. Here's how
it looks:
aeval (optimize_0plus e) = aeval e.
Proof: By induction on e. The AMinus and AMult cases
follow directly from the IH. The remaining cases are as follows:
- Suppose e = ANum n for some n. We must show
aeval (optimize_0plus (ANum n)) = aeval (ANum n).This is immediate from the definition of optimize_0plus.
- Suppose e = APlus e1 e2 for some e1 and e2. We
must show
aeval (optimize_0plus (APlus e1 e2))Consider the possible forms of e1. For most of them, optimize_0plus simply calls itself recursively for the subexpressions and rebuilds a new expression of the same form as e1; in these cases, the result follows directly from the IH.
= aeval (APlus e1 e2).The interesting case is when e1 = ANum n for some n. If n = ANum 0, thenoptimize_0plus (APlus e1 e2) = optimize_0plus e2and the IH for e2 is exactly what we need. On the other hand, if n = S n' for some n', then again optimize_0plus simply calls itself recursively, and the result follows from the IH. ☐
Theorem optimize_0plus_sound'': ∀ e,
aeval (optimize_0plus e) = aeval e.
Proof.
intros e.
induction e;
(* Most cases follow directly by the IH *)
try (simpl; rewrite IHe1; rewrite IHe2; reflexivity);
(* ... or are immediate by definition *)
try reflexivity.
(* The interesting case is when e = APlus e1 e2. *)
Case "APlus".
destruct e1; try (simpl; simpl in IHe1; rewrite IHe1;
rewrite IHe2; reflexivity).
SCase "e1 = ANum n". destruct n;
simpl; rewrite IHe2; reflexivity. Qed.
Defining New Tactic Notations
- The Tactic Notation command gives a handy way to define
"shorthand tactics" that, when invoked, apply several tactics
at the same time.
- For more sophisticated programming, Coq offers a small
built-in programming language called Ltac with primitives
that can examine and modify the proof state. The details are
a bit too complicated to get into here (and it is generally
agreed that Ltac is not the most beautiful part of Coq's
design!), but they can be found in the reference manual, and
there are many examples of Ltac definitions in the Coq
standard library that you can use as examples.
- There is also an OCaml API that can be used to build new tactics that access Coq's internal structures at a lower level, but this is seldom worth the trouble for ordinary Coq users.
Tactic Notation "simpl_and_try" tactic(c) :=
simpl;
try c.
This defines a new tactical called simpl_and_try which
takes one tactic c as an argument, and is defined to be
equivalent to the tactic simpl; try c. For example, writing
"simpl_and_try reflexivity." in a proof would be the same as
writing "simpl; try reflexivity."
The next subsection gives a more sophisticated use of this
feature...
Being able to deal with most of the cases of an induction or
destruct all at the same time is very convenient, but it can
also be a little confusing. One problem that often comes up is
that maintaining proofs written in this style can be difficult.
For example, suppose that, later, we extended the definition of
aexp with another constructor that also required a special
argument. The above proof might break because Coq generated the
subgoals for this constructor before the one for APlus, so that,
at the point when we start working on the APlus case, Coq is
actually expecting the argument for a completely different
constructor. What we'd like is to get a sensible error message
saying "I was expecting the AFoo case at this point, but the
proof script is talking about APlus." Here's a nice little
trick that smoothly achieves this.
Bulletproofing Case Analyses
Tactic Notation "aexp_cases" tactic(first) ident(c) :=
first;
[ Case_aux c "ANum" | Case_aux c "APlus"
| Case_aux c "AMinus" | Case_aux c "AMult" ].
(Case_aux implements the common functionality of Case,
SCase, SSCase, etc. For example, Case "foo" is defined as
Case_aux Case "foo".)
For example, if e is a variable of type aexp, then doing
aexp_cases (induction e) Case
will perform an induction on e (the same as if we had just typed
induction e) and also add a Case tag to each subgoal
generated by the induction, labeling which constructor it comes
from. For example, here is yet another proof of
optimize_0plus_sound, using aexp_cases:
Theorem optimize_0plus_sound''': ∀ e,
aeval (optimize_0plus e) = aeval e.
Proof.
intros e.
aexp_cases (induction e) Case;
try (simpl; rewrite IHe1; rewrite IHe2; reflexivity);
try reflexivity.
(* At this point, there is already an "APlus" case name in the
context. The Case "APlus" here in the proof text has the
effect of a sanity check: if the "Case" string in the context is
anything _other_ than "APlus" (for example, because we added a
clause to the definition of aexp and forgot to change the
proof) we'll get a helpful error at this point telling us that
this is now the wrong case. *)
Case "APlus".
aexp_cases (destruct e1) SCase;
try (simpl; simpl in IHe1; rewrite IHe1; rewrite IHe2; reflexivity).
SCase "ANum". destruct n;
simpl; rewrite IHe2; reflexivity. Qed.
Exercise: 3 stars (optimize_0plus_b)
Since the optimize_0plus tranformation doesn't change the value of aexps, we should be able to apply it to all the aexps that appear in a bexp without changing the bexp's value. Write a function which performs that transformation on bexps, and prove it is sound. Use the tacticals we've just seen to make the proof as elegant as possible.(* FILL IN HERE *)
☐
(* FILL IN HERE *)
☐
The omega tactic implements a decision procedure for a subset of
first-order logic called Presburger arithmetic. It is based on
the Omega algorithm invented in 1992 by William Pugh.
If the goal is a universally quantified formula made out of
then invoking omega will either solve the goal or tell you that
it is actually false.
Exercise: 4 stars, optional (optimizer)
Design exercise: The optimization implemented by our optimize_0plus function is only one of many imaginable optimizations on arithmetic and boolean expressions. Write a more sophisticated optimizer and prove it correct.☐
The omega Tactic
- numeric constants, addition (+ and S), subtraction (-
and pred), and multiplication by constants (this is what
makes it Presburger arithmetic),
- equality (= and <>) and inequality (<=), and
- the logical connectives ∧, ∨, ~, and →,
Example silly_presburger_example : ∀ m n o p,
m + n <= n + o ∧ o + 3 = p + 3 →
m <= p.
Proof.
intros. omega.
Qed.
Andrew Appel calls this the "Santa Claus tactic."
Finally, here are some miscellaneous tactics that you may find
convenient.
We'll see many examples of these in the proofs below.
We have presented aeval and beval as functions defined by
Fixpoints. An alternative way to think about evaluation is as a
relation between expressions and their values.
This leads naturally to Coq Inductive definitions like the
following one for arithmetic expressions...
A Few More Handy Tactics
- clear H: Delete hypothesis H from the context.
- subst x: Find an assumption x = e or e = x in the
context, replace x with e throughout the context and
current goal, and clear the assumption.
- subst: Substitute away all assumptions of the form x = e
or e = x.
- rename... into...: Change the name of a hypothesis in the
proof context. For example, if the context includes a variable
named x, then rename x into y will change all occurrences
of x to y.
- assumption: Try to find a hypothesis H in the context that
exactly matches the goal; if one is found, behave just like
apply H.
- contradiction: Try to find a hypothesis H in the current
context that is equivalent to False. If one is found, solve
the goal.
- constructor: Try to find a constructor c (from some Inductive definition in the current environment) that can be applied to solve the current goal. If one is found, behave like apply c.
Evaluation as a Relation
Module aevalR_first_try.
Inductive aevalR : aexp → nat → Prop :=
| E_ANum : ∀ (n: nat),
aevalR (ANum n) n
| E_APlus : ∀ (e1 e2: aexp) (n1 n2: nat),
aevalR e1 n1 →
aevalR e2 n2 →
aevalR (APlus e1 e2) (n1 + n2)
| E_AMinus: ∀ (e1 e2: aexp) (n1 n2: nat),
aevalR e1 n1 →
aevalR e2 n2 →
aevalR (AMinus e1 e2) (n1 - n2)
| E_AMult : ∀ (e1 e2: aexp) (n1 n2: nat),
aevalR e1 n1 →
aevalR e2 n2 →
aevalR (AMult e1 e2) (n1 * n2).
As is often the case with relations, we'll find it
convenient to define infix notation for aevalR. We'll write e
⇓ n to mean that arithmetic expression e evaluates to value
n. (This notation is one place where the limitation to ascii
symbols becomes a little bothersome. The standard notation for
the evaluation relation is a double down-arrow. We'll typeset it
like this in the HTML version of the notes and use a double
vertical bar as the closest approximation in ascii .v files.)
In fact, Coq provides a way to use this notation in the definition
of aevalR itself. This avoids situations where we're working on
a proof involving statements in the form e ⇓ n but we have to
refer back to a definition written using the form aevalR e n.
We do this by first "reserving" the notation, then giving the
definition together with a declaration of what the notation
means.
Reserved Notation "e '⇓' n" (at level 50, left associativity).
Inductive aevalR : aexp → nat → Prop :=
| E_ANum : ∀ (n:nat),
(ANum n) ⇓ n
| E_APlus : ∀ (e1 e2: aexp) (n1 n2 : nat),
(e1 ⇓ n1) → (e2 ⇓ n2) → (APlus e1 e2) ⇓ (n1 + n2)
| E_AMinus : ∀ (e1 e2: aexp) (n1 n2 : nat),
(e1 ⇓ n1) → (e2 ⇓ n2) → (AMinus e1 e2) ⇓ (n1 - n2)
| E_AMult : ∀ (e1 e2: aexp) (n1 n2 : nat),
(e1 ⇓ n1) → (e2 ⇓ n2) → (AMult e1 e2) ⇓ (n1 * n2)
where "e '⇓' n" := (aevalR e n) : type_scope.
Tactic Notation "aevalR_cases" tactic(first) ident(c) :=
first;
[ Case_aux c "E_ANum" | Case_aux c "E_APlus"
| Case_aux c "E_AMinus" | Case_aux c "E_AMult" ].
It is straightforward to prove that the relational and functional
definitions of evaluation agree on all possible arithmetic
expressions...
Theorem aeval_iff_aevalR : ∀ a n,
(a ⇓ n) ↔ aeval a = n.
Proof.
split.
Case "→".
intros H.
aevalR_cases (induction H) SCase; simpl.
SCase "E_ANum".
reflexivity.
SCase "E_APlus".
rewrite IHaevalR1. rewrite IHaevalR2. reflexivity.
SCase "E_AMinus".
rewrite IHaevalR1. rewrite IHaevalR2. reflexivity.
SCase "E_AMult".
rewrite IHaevalR1. rewrite IHaevalR2. reflexivity.
Case "←".
generalize dependent n.
aexp_cases (induction a) SCase;
simpl; intros; subst.
SCase "ANum".
apply E_ANum.
SCase "APlus".
apply E_APlus.
apply IHa1. reflexivity.
apply IHa2. reflexivity.
SCase "AMinus".
apply E_AMinus.
apply IHa1. reflexivity.
apply IHa2. reflexivity.
SCase "AMult".
apply E_AMult.
apply IHa1. reflexivity.
apply IHa2. reflexivity.
Qed.
A shorter proof making more aggressive use of tacticals:
Theorem aeval_iff_aevalR' : ∀ a n,
(a ⇓ n) ↔ aeval a = n.
Proof.
(* WORKED IN CLASS *)
split.
Case "→".
intros H; induction H; subst; reflexivity.
Case "←".
generalize dependent n.
induction a; simpl; intros; subst; constructor;
try apply IHa1; try apply IHa2; reflexivity.
Qed.
Exercise: 2 stars, optional (bevalR)
Write a relation bevalR in the same style as aevalR, and prove that it is equivalent to beval.(*
Inductive bevalR:
(* FILL IN HERE *)
(** *)
*)
For the definitions of evaluation for arithmetic and boolean
expressions, the choice of whether to use functional or relational
definitions is mainly a matter of taste. In general, Coq has
somewhat better support for working with relations; in particular,
we can more readily do induction over them. On the other hand, in
some sense function definitions carry more information, because
functions are necessarily deterministic and defined on all
arguments; for a relation we have to show these properties
explicitly if we need them.
However, there are circumstances where relational definitions of
evaluation are greatly preferable to functional ones, as we'll see
shortly.
In informal discussions, it is convenient write the rules for
aevalR and similar relations in a more readable "graphical" form
called inference rules, where the premises above the line allow
you to derive the conclusion below the line. For example, the
constructor E_APlus...
Formally, there is nothing very deep about inference rules: they
are just implications. You can read the rule name on the right as
the name of the constructor and read each of the linebreaks
between the premises above the line and the line itself as →.
All the variables mentioned in the rule (e1, n1, etc.) are
implicitly bound by universal quantifiers at the beginning. The
whole collection of rules is understood as being wrapped in an
Inductive declaration (this is either left completely implicit
or else indicated informally by saying something like "Let
aevalR be the smallest relation closed under the following
rules...").
For example, ⇓ is the smallest relation closed under these
rules:
Inference Rule Notation
| E_APlus : ∀ (e1 e2: aexp) (n1 n2: nat),
aevalR e1 n1 →
aevalR e2 n2 →
aevalR (APlus e1 e2) (n1 + n2)
...would be written like this as an inference rule:
aevalR e1 n1 →
aevalR e2 n2 →
aevalR (APlus e1 e2) (n1 + n2)
| e1 ⇓ n1 | |
| e2 ⇓ n2 | (E_APlus) |
| APlus e1 e2 ⇓ n1+n2 |
| (E_ANum) | |
| ANum n ⇓ n |
| e1 ⇓ n1 | |
| e2 ⇓ n2 | (E_APlus) |
| APlus e1 e2 ⇓ n1+n2 |
| e1 ⇓ n1 | |
| e2 ⇓ n2 | (E_AMinus) |
| AMinus e1 e2 ⇓ n1-n2 |
| e1 ⇓ n1 | |
| e2 ⇓ n2 | (E_AMult) |
| AMult e1 e2 ⇓ n1*n2 |
Expressions With Variables
Identifiers
We define a new inductive datatype Id so that we won't confuse
identifiers and numbers.
Inductive id : Type :=
Id : nat → id.
Definition beq_id X1 X2 :=
match (X1, X2) with
(Id n1, Id n2) => beq_nat n1 n2
end.
Now, having "wrapped" numbers as identifiers in this way, it
is convenient to recapitulate a few properties of numbers as
analogous properties of identifiers, so that we can work with
identifiers in definitions and proofs abstractly, without
unwrapping them to expose the underlying numbers. Since all we
need to know about identifiers is whether they are the same or
different, just a few basic facts are all we need.
Exercise: 1 star, optional (beq_id_eq)
For this and the following exercises, do not use induction, but rather apply similar results already proved for natural numbers. Some of the tactics mentioned above may prove useful.
Theorem beq_id_false_not_eq : ∀ i1 i2,
beq_id i1 i2 = false → i1 <> i2.
Proof.
(* FILL IN HERE *) Admitted.
beq_id i1 i2 = false → i1 <> i2.
Proof.
(* FILL IN HERE *) Admitted.
Theorem not_eq_beq_id_false : ∀ i1 i2,
i1 <> i2 → beq_id i1 i2 = false.
Proof.
(* FILL IN HERE *) Admitted.
i1 <> i2 → beq_id i1 i2 = false.
Proof.
(* FILL IN HERE *) Admitted.
☐
States
Definition state := id → nat.
Definition empty_state : state :=
fun _ => 0.
Definition update (st : state) (X:id) (n : nat) : state :=
fun X' => if beq_id X X' then n else st X'.
Theorem update_neq : ∀ V2 V1 n st,
beq_id V2 V1 = false →
(update st V2 n) V1 = (st V1).
Proof.
(* FILL IN HERE *) Admitted.
beq_id V2 V1 = false →
(update st V2 n) V1 = (st V1).
Proof.
(* FILL IN HERE *) Admitted.
☐
Exercise: 2 stars, optional (update_example)
Before starting to play with tactics, make sure you understand exactly what the theorem is saying!Theorem update_example : ∀ (n:nat),
(update empty_state (Id 2) n) (Id 3) = 0.
Proof.
(* FILL IN HERE *) Admitted.
Theorem update_shadow : ∀ x1 x2 k1 k2 (f : state),
(update (update f k2 x1) k2 x2) k1 = (update f k2 x2) k1.
Proof.
(* FILL IN HERE *) Admitted.
(update (update f k2 x1) k2 x2) k1 = (update f k2 x2) k1.
Proof.
(* FILL IN HERE *) Admitted.
Theorem update_same : ∀ x1 k1 k2 (f : state),
f k1 = x1 →
(update f k1 x1) k2 = f k2.
Proof.

Proof.
(* FILL IN HERE *) Admitted.
Theorem update_permute : ∀ x1 x2 k1 k2 k3 f,
beq_id k2 k1 = false →
(update (update f k2 x1) k1 x2) k3 = (update (update f k1 x2) k2 x1) k3.
Proof.
(* FILL IN HERE *) Admitted.
beq_id k2 k1 = false →
(update (update f k2 x1) k1 x2) k3 = (update (update f k1 x2) k2 x1) k3.
Proof.
(* FILL IN HERE *) Admitted.
☐
We can add variables to the arithmetic expressions we had before by
simply adding one more constructor:
Syntax
Inductive aexp : Type :=
| ANum : nat → aexp
| AId : id → aexp (* <----- NEW *)
| APlus : aexp → aexp → aexp
| AMinus : aexp → aexp → aexp
| AMult : aexp → aexp → aexp.
Tactic Notation "aexp_cases" tactic(first) ident(c) :=
first;
[ Case_aux c "ANum" | Case_aux c "AId" | Case_aux c "APlus"
| Case_aux c "AMinus" | Case_aux c "AMult" ].
Shorthands for variables:
(This convention for naming program variables (X, Y,
Z) clashes a bit with our earlier use of uppercase letters for
types. Since we're not using polymorphism heavily in this part of
the course, this overloading should not cause confusion.)
The definition of bexps is the same as before (using the new
aexps):
Inductive bexp : Type :=
| BTrue : bexp
| BFalse : bexp
| BEq : aexp → aexp → bexp
| BLe : aexp → aexp → bexp
| BNot : bexp → bexp
| BAnd : bexp → bexp → bexp.
Tactic Notation "bexp_cases" tactic(first) ident(c) :=
first;
[ Case_aux c "BTrue" | Case_aux c "BFalse" | Case_aux c "BEq"
| Case_aux c "BLe" | Case_aux c "BNot" | Case_aux c "BAnd" ].
Fixpoint aeval (st : state) (e : aexp) : nat :=
match e with
| ANum n => n
| AId X => st X (* <----- NEW *)
| APlus a1 a2 => (aeval st a1) + (aeval st a2)
| AMinus a1 a2 => (aeval st a1) - (aeval st a2)
| AMult a1 a2 => (aeval st a1) * (aeval st a2)
end.
Fixpoint beval (st : state) (e : bexp) : bool :=
match e with
| BTrue => true
| BFalse => false
| BEq a1 a2 => beq_nat (aeval st a1) (aeval st a2)
| BLe a1 a2 => ble_nat (aeval st a1) (aeval st a2)
| BNot b1 => negb (beval st b1)
| BAnd b1 b2 => andb (beval st b1) (beval st b2)
end.
Example aexp1 :
aeval (update empty_state X 5)
(APlus (ANum 3) (AMult (AId X) (ANum 2)))
= 13.
Proof. reflexivity. Qed.
Example bexp1 :
beval (update empty_state X 5)
(BAnd BTrue (BNot (BLe (AId X) (ANum 4))))
= true.
Proof. reflexivity. Qed.
Commands
Syntax
com ::= 'SKIP'
| X '::=' aexp
| com ';' com
| 'WHILE' bexp 'DO' com 'END'
| 'IFB' bexp 'THEN' com 'ELSE' com 'FI'
For example, here's the factorial function in Imp.
| X '::=' aexp
| com ';' com
| 'WHILE' bexp 'DO' com 'END'
| 'IFB' bexp 'THEN' com 'ELSE' com 'FI'
Z ::= X;
Y ::= 1;
WHILE not (Z = 0) DO
Y ::= Y * Z;
Z ::= Z - 1
END
When this command terminates, the variable Y will contain the
factorial of the variable X.
Y ::= 1;
WHILE not (Z = 0) DO
Y ::= Y * Z;
Z ::= Z - 1
END
Inductive com : Type :=
| CSkip : com
| CAss : id → aexp → com
| CSeq : com → com → com
| CIf : bexp → com → com → com
| CWhile : bexp → com → com.
Tactic Notation "com_cases" tactic(first) ident(c) :=
first;
[ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";"
| Case_aux c "IFB" | Case_aux c "WHILE" ].
As usual, we can use a few Notation declarations to make things
more readable. However, we need to be a bit careful to avoid
conflicts with Coq's built-in notations, so we'll keep this
light — in particular, we won't introduce any notations for
aexps and bexps to avoid confusion with the numerical and
boolean operators we've already defined. (We use the keyword
IFB for conditionals instead of the usual IF for similar
reasons.)
Notation "'SKIP'" :=
CSkip.
Notation "X '::=' a" :=
(CAss X a) (at level 60).
Notation "c1 ; c2" :=
(CSeq c1 c2) (at level 80, right associativity).
Notation "'WHILE' b 'DO' c 'END'" :=
(CWhile b c) (at level 80, right associativity).
Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" :=
(CIf e1 e2 e3) (at level 80, right associativity).
For example, here is the factorial function again, written as a
formal definition to Coq:
Definition fact_in_coq : com :=
Z ::= AId X;
Y ::= ANum 1;
WHILE BNot (BEq (AId Z) (ANum 0)) DO
Y ::= AMult (AId Y) (AId Z);
Z ::= AMinus (AId Z) (ANum 1)
END.
Definition plus2 : com :=
X ::= (APlus (AId X) (ANum 2)).
Definition XtimesYinZ : com :=
Z ::= (AMult (AId X) (AId Y)).
Definition subtract_slowly_body : com :=
Z ::= AMinus (AId Z) (ANum 1) ;
X ::= AMinus (AId X) (ANum 1).
Loops:
Definition subtract_slowly : com :=
WHILE BNot (BEq (AId X) (ANum 0)) DO
subtract_slowly_body
END.
Definition subtract_3_from_5_slowly : com :=
X ::= ANum 3 ;
Z ::= ANum 5 ;
subtract_slowly.
An infinite loop:
Factorial again (broken up into smaller pieces this time, for
convenience when we come back to proving things about it
later).
Definition fact_body : com :=
Y ::= AMult (AId Y) (AId Z) ;
Z ::= AMinus (AId Z) (ANum 1).
Definition fact_loop : com :=
WHILE BNot (BEq (AId Z) (ANum 0)) DO
fact_body
END.
Definition fact_com : com :=
Z ::= AId X ;
Y ::= ANum 1 ;
fact_loop.
Evaluation
Evaluation Function
Fixpoint ceval_step1 (st : state) (c : com) : state :=
match c with
| SKIP =>
st
| l ::= a1 =>
update st l (aeval st a1)
| c1 ; c2 =>
let st' := ceval_step1 st c1 in
ceval_step1 st' c2
| IFB b THEN c1 ELSE c2 FI =>
if (beval st b)
then ceval_step1 st c1
else ceval_step1 st c2
| WHILE b1 DO c1 END =>
st (* bogus *)
end.
Second try, using an extra numeric argument as a "step index" to
ensure that evaluation always terminates.
Fixpoint ceval_step2 (st : state) (c : com) (i : nat) : state :=
match i with
| O => empty_state
| S i' =>
match c with
| SKIP =>
st
| l ::= a1 =>
update st l (aeval st a1)
| c1 ; c2 =>
let st' := ceval_step2 st c1 i' in
ceval_step2 st' c2 i'
| IFB b THEN c1 ELSE c2 FI =>
if (beval st b)
then ceval_step2 st c1 i'
else ceval_step2 st c2 i'
| WHILE b1 DO c1 END =>
if (beval st b1)
then let st' := ceval_step2 st c1 i' in
ceval_step2 st' c i'
else st
end
end.
Note: It is tempting to think that the index i here is
counting the "number of steps of evaluation." But if you look
closely you'll see that this is not the case: for example, in the
rule for sequencing, the same i is passed to both recursive
calls. Understanding the exact way that i is treated will be
important in the proof of ceval__ceval_step, which is given as
an exercise below.
Third try, returning an option state instead of just a state
so that we can distinguish between normal and abnormal
termination.
Fixpoint ceval_step3 (st : state) (c : com) (i : nat)
: option state :=
match i with
| O => None
| S i' =>
match c with
| SKIP =>
Some st
| l ::= a1 =>
Some (update st l (aeval st a1))
| c1 ; c2 =>
match (ceval_step3 st c1 i') with
| Some st' => ceval_step3 st' c2 i'
| None => None
end
| IFB b THEN c1 ELSE c2 FI =>
if (beval st b)
then ceval_step3 st c1 i'
else ceval_step3 st c2 i'
| WHILE b1 DO c1 END =>
if (beval st b1)
then match (ceval_step3 st c1 i') with
| Some st' => ceval_step3 st' c i'
| None => None
end
else Some st
end
end.
We can improve the readability of this definition by introducing a
bit of auxiliary notation to hide the "plumbing" involved in
repeatedly matching against optional states.
Notation "'LETOPT' x <== e1 'IN' e2"
:= (match e1 with
| Some x => e2
| None => None
end)
(right associativity, at level 60).
Fixpoint ceval_step (st : state) (c : com) (i : nat)
: option state :=
match i with
| O => None
| S i' =>
match c with
| SKIP =>
Some st
| l ::= a1 =>
Some (update st l (aeval st a1))
| c1 ; c2 =>
LETOPT st' <== ceval_step st c1 i' IN
ceval_step st' c2 i'
| IFB b THEN c1 ELSE c2 FI =>
if (beval st b)
then ceval_step st c1 i'
else ceval_step st c2 i'
| WHILE b1 DO c1 END =>
if (beval st b1)
then LETOPT st' <== ceval_step st c1 i' IN
ceval_step st' c i'
else Some st
end
end.
Definition test_ceval (st:state) (c:com) :=
match ceval_step st c 500 with
| None => None
| Some st => Some (st X, st Y, st Z)
end.
(*
Eval compute in
(test_ceval empty_state
(X ::= ANum 2;
IFB BLe (AId X) (ANum 1)
THEN Y ::= ANum 3
ELSE Z ::= ANum 4
FI)).
====>
Some (2, 0, 4)
*)
Exercise: 2 stars, recommended (pup_to_n)
Write an Imp program that sums the numbers from 1 to X (inclusive: 1 + 2 + ... + X) in the variable Y. Make sure your solution satisfies the test that follows.Definition pup_to_n : com :=
(* FILL IN HERE *) admit.
(*
Example pup_to_n_1 :
test_ceval (update empty_state X 5) pup_to_n
= Some (0, 15, 0).
Proof. reflexivity. Qed.
*)
☐
Exercise: 2 stars, optional (peven)
Write a While program that sets Z to 0 if X is even and sets Z to 1 otherwise. Use ceval_test to test your program.(* FILL IN HERE *)
☐
Here's a better way: define ceval as a relation rather than a
function — i.e., define it in Prop instead of Type, as we
did for aevalR and bevalR above.
This is an important change. Besides freeing us from the
silliness of passing around step indices all over the place, it
gives us a lot more flexibility in the definition. For example,
if we added concurrency features to the language, we'd want the
definition of evaluation to be non-deterministic — i.e., not only
would it not be total, it would not even be a partial function!
We'll use the notation c / st ⇓ st' for our ceval relation,
that is c / st ⇓ st' means that executing program c in a
starting state st results in an ending state st'. This can be
pronounced "c takes state st to st'".
Here is the formal definition. (Make sure you understand
how it corresponds to the inference rules.)
Evaluation as a Relation
| (E_Skip) | |
| SKIP / st ⇓ st |
| aeval st a1 = n | (E_Ass) |
| l := a1 / st ⇓ (update st l n) |
| c1 / st ⇓ st' | |
| c2 / st' ⇓ st'' | (E_Seq) |
| c1;c2 / st ⇓ st'' |
| beval st b1 = true | |
| c1 / st ⇓ st' | (E_IfTrue) |
| IF b1 THEN c1 ELSE c2 FI / st ⇓ st' |
| beval st b1 = false | |
| c2 / st ⇓ st' | (E_IfFalse) |
| IF b1 THEN c1 ELSE c2 FI / st ⇓ st' |
| beval st b1 = false | (E_WhileEnd) |
| WHILE b1 DO c1 END / st ⇓ st |
| beval st b1 = true | |
| c1 / st ⇓ st' | |
| WHILE b1 DO c1 END / st' ⇓ st'' | (E_WhileLoop) |
| WHILE b1 DO c1 END / st ⇓ st'' |
Reserved Notation "c1 '/' st '⇓' st'" (at level 40, st at level 39).
Inductive ceval : com → state → state → Prop :=
| E_Skip : ∀ st,
SKIP / st ⇓ st
| E_Ass : ∀ st a1 n l,
aeval st a1 = n →
(l ::= a1) / st ⇓ (update st l n)
| E_Seq : ∀ c1 c2 st st' st'',
c1 / st ⇓ st' →
c2 / st' ⇓ st'' →
(c1 ; c2) / st ⇓ st''
| E_IfTrue : ∀ st st' b1 c1 c2,
beval st b1 = true →
c1 / st ⇓ st' →
(IFB b1 THEN c1 ELSE c2 FI) / st ⇓ st'
| E_IfFalse : ∀ st st' b1 c1 c2,
beval st b1 = false →
c2 / st ⇓ st' →
(IFB b1 THEN c1 ELSE c2 FI) / st ⇓ st'
| E_WhileEnd : ∀ b1 st c1,
beval st b1 = false →
(WHILE b1 DO c1 END) / st ⇓ st
| E_WhileLoop : ∀ st st' st'' b1 c1,
beval st b1 = true →
c1 / st ⇓ st' →
(WHILE b1 DO c1 END) / st' ⇓ st'' →
(WHILE b1 DO c1 END) / st ⇓ st''
where "c1 '/' st '⇓' st'" := (ceval c1 st st').
Tactic Notation "ceval_cases" tactic(first) ident(c) :=
first;
[ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq"
| Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse"
| Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" ].
The cost of defining evaluation as a relation instead of a
function is that we now need to construct proofs that some
program evaluates to some result state, rather than just letting
Coq's computation mechanism do it for us.
Example ceval_example1:
(X ::= ANum 2;
IFB BLe (AId X) (ANum 1)
THEN Y ::= ANum 3
ELSE Z ::= ANum 4
FI)
/ empty_state
⇓ (update (update empty_state X 2) Z 4).
Proof.
(* We must supply the intermediate state *)
apply E_Seq with (update empty_state X 2).
Case "assignment command".
apply E_Ass. reflexivity.
Case "if command".
apply E_IfFalse.
reflexivity.
apply E_Ass. reflexivity. Qed.
Example ceval_example2:
(X ::= ANum 0; Y ::= ANum 1; Z ::= ANum 2) / empty_state ⇓
(update (update (update empty_state X 0) Y 1) Z 2).
Proof.
(* FILL IN HERE *) Admitted.
(X ::= ANum 0; Y ::= ANum 1; Z ::= ANum 2) / empty_state ⇓
(update (update (update empty_state X 0) Y 1) Z 2).
Proof.
(* FILL IN HERE *) Admitted.
☐
As with arithmetic and boolean expressions, we'd hope that
the two alternative definitions of evaluation actually boil down
to the same thing. This section shows that this is the case.
Make sure you understand the statements of the theorems and can
follow the structure of the proofs.
Equivalence of Relational and Step-Indexed Evaluation
Theorem ceval_step__ceval: ∀ c st st',
(∃ i, ceval_step st c i = Some st') →
c / st ⇓ st'.
Proof.
intros c st st' H.
inversion H as [i E].
clear H.
generalize dependent st'.
generalize dependent st.
generalize dependent c.
induction i as [| i' ].
Case "i = 0 -- contradictory".
intros c st st' H. inversion H.
Case "i = S i'".
intros c st st' H.
com_cases (destruct c) SCase;
simpl in H; inversion H; subst; clear H.
SCase "SKIP". apply E_Skip.
SCase "::=". apply E_Ass. reflexivity.
SCase ";".
remember (ceval_step st c1 i') as r1. destruct r1.
SSCase "Evaluation of r1 terminates normally".
apply E_Seq with s.
apply IHi'. rewrite Heqr1. reflexivity.
apply IHi'. simpl in H1. assumption.
SSCase "Otherwise -- contradiction".
inversion H1.
SCase "IFB".
remember (beval st b) as r. destruct r.
SSCase "r = true".
apply E_IfTrue. rewrite Heqr. reflexivity.
apply IHi'. assumption.
SSCase "r = false".
apply E_IfFalse. rewrite Heqr. reflexivity.
apply IHi'. assumption.
SCase "WHILE". remember (beval st b) as r. destruct r.
SSCase "r = true".
remember (ceval_step st c i') as r1. destruct r1.
SSSCase "r1 = Some s".
apply E_WhileLoop with s. rewrite Heqr. reflexivity.
apply IHi'. rewrite Heqr1. reflexivity.
apply IHi'. simpl in H1. assumption.
SSSCase "r1 = None".
inversion H1.
SSCase "r = false".
inversion H1.
apply E_WhileEnd.
rewrite Heqr. subst. reflexivity. Qed.
Exercise: 4 stars (ceval_step__ceval_inf)
Write an informal proof of ceval_step__ceval, following the usual template. (The template for case analysis on an inductively defined value should look the same as for induction, except that there is no induction hypothesis.) Make your proof communicate the main ideas to a human reader; do not simply transcribe the steps of the formal proof.☐
Theorem ceval_step_more: ∀ i1 i2 st st' c,
i1 <= i2 →
ceval_step st c i1 = Some st' →
ceval_step st c i2 = Some st'.
Proof.
induction i1 as [|i1']; intros i2 st st' c Hle Hceval.
Case "i1 = 0".
inversion Hceval.
Case "i1 = S i1'".
destruct i2 as [|i2']. inversion Hle.
assert (Hle': i1' <= i2') by omega.
com_cases (destruct c) SCase.
SCase "SKIP".
simpl in Hceval. inversion Hceval.
reflexivity.
SCase "::=".
simpl in Hceval. inversion Hceval.
reflexivity.
SCase ";".
simpl in Hceval. simpl.
remember (ceval_step st c1 i1') as st1'o.
destruct st1'o.
SSCase "st1'o = Some".
symmetry in Heqst1'o.
apply (IHi1' i2') in Heqst1'o; try assumption.
rewrite Heqst1'o. simpl. simpl in Hceval.
apply (IHi1' i2') in Hceval; try assumption.
SSCase "st1'o = None".
inversion Hceval.
SCase "IFB".
simpl in Hceval. simpl.
remember (beval st b) as bval.
destruct bval; apply (IHi1' i2') in Hceval; assumption.
SCase "WHILE".
simpl in Hceval. simpl.
destruct (beval st b); try assumption.
remember (ceval_step st c i1') as st1'o.
destruct st1'o.
SSCase "st1'o = Some".
symmetry in Heqst1'o.
apply (IHi1' i2') in Heqst1'o; try assumption.
rewrite → Heqst1'o. simpl. simpl in Hceval.
apply (IHi1' i2') in Hceval; try assumption.
SSCase "i1'o = None".
simpl in Hceval. inversion Hceval. Qed.
Exercise: 3 stars, recommended (ceval__ceval_step)
Finish the following proof. You'll need ceval_step_more in a few places, as well as some basic facts about <= and plus.Theorem ceval__ceval_step: ∀ c st st',
c / st ⇓ st' →
∃ i, ceval_step st c i = Some st'.
Proof.
intros c st st' Hce.
ceval_cases (induction Hce) Case.
(* FILL IN HERE *) Admitted.
☐
Theorem ceval_and_ceval_step_coincide: ∀ c st st',
c / st ⇓ st'
↔ ∃ i, ceval_step st c i = Some st'.
Proof.
intros c st st'.
split. apply ceval__ceval_step. apply ceval_step__ceval.
Qed.
Determinacy of Evaluation
Theorem ceval_deterministic: ∀ c st st1 st2,
c / st ⇓ st1 →
c / st ⇓ st2 →
st1 = st2.
Proof.
intros c st st1 st2 E1 E2.
generalize dependent st2.
ceval_cases (induction E1) Case;
intros st2 E2; inversion E2; subst.
Case "E_Skip". reflexivity.
Case "E_Ass". reflexivity.
Case "E_Seq".
assert (st' = st'0) as EQ1.
SCase "Proof of assertion". apply IHE1_1; assumption.
subst st'0.
apply IHE1_2. assumption.
Case "E_IfTrue".
SCase "b1 evaluates to true".
apply IHE1. assumption.
SCase "b1 evaluates to false (contradiction)".
rewrite H in H5. inversion H5.
Case "E_IfFalse".
SCase "b1 evaluates to true (contradiction)".
rewrite H in H5. inversion H5.
SCase "b1 evaluates to false".
apply IHE1. assumption.
Case "E_WhileEnd".
SCase "b1 evaluates to true".
reflexivity.
SCase "b1 evaluates to false (contradiction)".
rewrite H in H2. inversion H2.
Case "E_WhileLoop".
SCase "b1 evaluates to true (contradiction)".
rewrite H in H4. inversion H4.
SCase "b1 evaluates to false".
assert (st' = st'0) as EQ1.
SSCase "Proof of assertion". apply IHE1_1; assumption.
subst st'0.
apply IHE1_2. assumption. Qed.
Here's a slicker proof, using the fact that the relational and
step-indexed definition of evaluation are the same.
Theorem ceval_deterministic' : ∀ c st st1 st2,
c / st ⇓ st1 →
c / st ⇓ st2 →
st1 = st2.
Proof.
intros c st st1 st2 He1 He2.
apply ceval__ceval_step in He1.
apply ceval__ceval_step in He2.
inversion He1 as [i1 E1].
inversion He2 as [i2 E2].
apply ceval_step_more with (i2 := i1 + i2) in E1.
apply ceval_step_more with (i2 := i1 + i2) in E2.
rewrite E1 in E2. inversion E2. reflexivity.
omega. omega. Qed.
Reasoning About Programs
Basic Examples
Theorem plus2_spec : ∀ st n st',
st X = n →
plus2 / st ⇓ st' →
st' X = n + 2.
Proof.
intros st n st' HX Heval.
(* Inverting Heval essentially forces Coq to expand one
step of the ceval computation - in this case revealing
that st' must be st extended with the new value of X,
since plus2 is an assignment *)
inversion Heval. subst.
apply update_eq. Qed.
Exercise: 3 stars, recommended (XtimesYinZ_spec)
State and prove a specification of the XtimesYinZ Imp program.(* FILL IN HERE *)
Theorem loop_never_stops : ∀ st st',
~(loop / st ⇓ st').
Proof.
intros st st' contra. unfold loop in contra.
remember (WHILE BTrue DO SKIP END) as loopdef.
(* Proceed by induction on the assumed derivation showing that
loopdef terminates. Most of the cases are immediately
contradictory (and so can be solved in one step with
inversion). *)
(* FILL IN HERE *) Admitted.
~(loop / st ⇓ st').
Proof.
intros st st' contra. unfold loop in contra.
remember (WHILE BTrue DO SKIP END) as loopdef.
(* Proceed by induction on the assumed derivation showing that
loopdef terminates. Most of the cases are immediately
contradictory (and so can be solved in one step with
inversion). *)
(* FILL IN HERE *) Admitted.
☐
Fixpoint no_whiles (c : com) : bool :=
match c with
| SKIP => true
| _ ::= _ => true
| c1 ; c2 => andb (no_whiles c1) (no_whiles c2)
| IFB _ THEN ct ELSE cf FI => andb (no_whiles ct) (no_whiles cf)
| WHILE _ DO _ END => false
end.
Exercise: 2 stars, optional (no_whilesR)
The no_whiles property yields true on just those programs that have no while loops. Using Inductive, write a property no_whilesR such that no_whilesR c is provable exactly when c is a program with no while loops. Then prove its equivalence with no_whiles.Inductive no_whilesR: com → Prop :=
(* FILL IN HERE *)
.
Theorem no_whiles_eqv:
∀ c, no_whiles c = true ↔ no_whilesR c.
Proof.
(* FILL IN HERE *) Admitted.
☐
Exercise: 4 stars, optional (no_whiles_terminating)
Imp programs that don't involve while loops always terminate. State and prove a theorem that says this. (Use either no_whiles or no_whilesR, as you prefer.)(* FILL IN HERE *)
Print fact_body. Print fact_loop. Print fact_com.
Here is an alternative "mathematical" definition of the factorial
function:
We would like to show that they agree — if we start fact_com in
a state where variable X contains some number x, then it will
terminate in a state where variable Y contains the factorial of
x.
To show this, we rely on the critical idea of a loop
invariant.
Definition fact_invariant (x:nat) (st:state) :=
(st Y) * (real_fact (st Z)) = real_fact x.
Theorem fact_body_preserves_invariant: ∀ st st' x,
fact_invariant x st →
st Z <> 0 →
fact_body / st ⇓ st' →
fact_invariant x st'.
Proof.
unfold fact_invariant, fact_body.
intros st st' x Hm HZnz He.
inversion He; subst; clear He.
inversion H1; subst; clear H1.
inversion H4; subst; clear H4.
unfold update. simpl.
(* Show that st Z = S z' for some z' *)
destruct (st Z) as [| z'].
apply ex_falso_quodlibet. apply HZnz. reflexivity.
rewrite ← Hm. rewrite ← mult_assoc.
replace (S z' - 1) with z' by omega.
reflexivity. Qed.
Theorem fact_loop_preserves_invariant : ∀ st st' x,
fact_invariant x st →
fact_loop / st ⇓ st' →
fact_invariant x st'.
Proof.
intros st st' x H Hce.
remember fact_loop as c.
ceval_cases (induction Hce) Case;
inversion Heqc; subst; clear Heqc.
Case "E_WhileEnd".
(* trivial when the loop doesn't run... *)
assumption.
Case "E_WhileLoop".
(* if the loop does run, we know that fact_body preserves
fact_invariant -- we just need to assemble the pieces *)
apply IHHce2.
apply fact_body_preserves_invariant with st;
try assumption.
intros Contra. simpl in H0; subst.
rewrite Contra in H0. inversion H0.
reflexivity. Qed.
Theorem guard_false_after_loop: ∀ b c st st',
(WHILE b DO c END) / st ⇓ st' →
beval st' b = false.
Proof.
intros b c st st' Hce.
remember (WHILE b DO c END) as cloop.
ceval_cases (induction Hce) Case;
inversion Heqcloop; subst; clear Heqcloop.
Case "E_WhileEnd".
assumption.
Case "E_WhileLoop".
apply IHHce2. reflexivity. Qed.
Patching it all together...
Theorem fact_com_correct : ∀ st st' x,
st X = x →
fact_com / st ⇓ st' →
st' Y = real_fact x.
Proof.
intros st st' x HX Hce.
inversion Hce; subst; clear Hce.
inversion H1; subst; clear H1.
inversion H4; subst; clear H4.
inversion H1; subst; clear H1.
rename st' into st''. simpl in H5.
(* The invariant is true before the loop runs... *)
remember (update (update st Z (st X)) Y 1) as st'.
assert (fact_invariant (st X) st').
subst. unfold fact_invariant, update. simpl. omega.
(* ...so when the loop is done running, the invariant
is maintained *)
assert (fact_invariant (st X) st'').
apply fact_loop_preserves_invariant with st'; assumption.
unfold fact_invariant in H0.
(* Finally, if the loop terminated, then Z is 0; so Y must be
factorial of X *)
apply guard_false_after_loop in H5. simpl in H5.
destruct (st'' Z).
Case "st'' Z = 0". simpl in H0. omega.
Case "st'' Z > 0 (impossible)". inversion H5.
Qed.
One might wonder whether all this work with poking at states and
unfolding definitions could be ameliorated with some more powerful
lemmas and/or more uniform reasoning principles... Indeed, this is
exactly the topic of the next chapter (Hoare.v)!
Exercise: 4 stars, optional (subtract_slowly_spec)
Prove a specification for subtract_slowly, using the above specification of fact_com and the invariant below as guides.Definition ss_invariant (x:nat) (z:nat) (st:state) :=
minus (st Z) (st X) = minus z x.
(* FILL IN HERE *)
☐
A for loop should be parameterized by (a) a statement executed
initially, (b) a test that is run on each iteration of the loop to
determine whether the loop should continue, (c) a statement
executed at the end of each loop iteration, and (d) a statement
that makes up the body of the loop. (You don't need to worry
about making up a concrete Notation for for loops, but feel free
to play with this too if you like.)
Additional Exercises
Exercise: 4 stars, optional (add_for_loop)
Add C-style for loops to the language of commands, update the ceval definition to define the semantics of for loops, and add cases for for loops as needed so that all the proofs in this file are accepted by Coq.(* FILL IN HERE *)
☐
Write an alternate version of beval that performs short-circuit
evaluation of BAnd in this manner, and prove that it is
equivalent to beval.
Exercise: 3 stars, optional (short_circuit)
Most modern programming languages use a "short-circuit" evaluation rule for boolean and: to evaluate BAnd b1 b2, first evaluate b1. If it evaluates to false, then the entire BAnd expression evaluates to false immediately, without evaluating b2. Otherwise, b2 is evaluated to determine the result of the BAnd expression.(* FILL IN HERE *)
Exercise: 4 stars, recommended (stack_compiler)
HP Calculators, programming languages like Forth and Postscript, and abstract machines like the Java Virtual Machine all evaluate arithmetic expressions using a stack. For instance, the expression(2*3)+(3*(4-2))would be entered as
2 3 * 3 4 2 - * +and evaluated like this:
[] | 2 3 * 3 4 2 - * + [2] | 3 * 3 4 2 - * + [3, 2] | * 3 4 2 - * + [6] | 3 4 2 - * + [3, 6] | 4 2 - * + [4, 3, 6] | 2 - * + [2, 4, 3, 6] | - * + [2, 3, 6] | * + [6, 6] | + [12] |
- SPush n: Push the number n on the stack.
- SLoad X: Load the identifier X from the store and push it on the stack
- SPlus: Pop the two top numbers from the stack, add them, and push the result onto the stack.
- SMinus: Similar, but subtract.
- SMult: Similar, but multiply.
Inductive sinstr : Type :=
| SPush : nat → sinstr
| SLoad : id → sinstr
| SPlus : sinstr
| SMinus : sinstr
| SMult : sinstr.
Write a function to evaluate programs in the stack language. It
takes as input a state, a stack represented as a list of
numbers (top stack item is the head of the list), and a program
represented as a list of instructions, and returns the stack after
executing the program. Test your function on the examples below.
Note that the specification leaves unspecified what to do when
encountering an SPlus, SMinus, or SMult instruction if the
stack contains less than two elements. In a sense it is
immaterial, since our compiler will never emit such a malformed
program. However, when you do the correctness proof you may find
some choices makes the proof easier than others.
Fixpoint s_execute (st : state) (stack : list nat)
(prog : list sinstr)
: list nat :=
(* FILL IN HERE *) admit.
Example s_execute1 :
s_execute empty_state []
[SPush 5, SPush 3, SPush 1, SMinus]
= [2, 5].
(* FILL IN HERE *) Admitted.
Example s_execute2 :
s_execute (update empty_state X 3) [3,4]
[SPush 4, SLoad X, SMult, SPlus]
= [15, 4].
(* FILL IN HERE *) Admitted.
Next, write a function which compiles an aexp into a stack
machine program. The effect of running the program should be the
same as pushing the value of the expression on the stack.
Fixpoint s_compile (e : aexp) : list sinstr :=
(* FILL IN HERE *) admit.
(*
Example s_compile1 :
s_compile (AMinus (AId X) (AMult (ANum 2) (AId Y)))
= SLoad X, SPush 2, SLoad Y, SMult, SMinus.
Proof. reflexivity. Qed.
*)
Finally, prove the following theorem, stating that the compile
function behaves correctly. You will need to start by stating a
more general lemma to get a usable induction hypothesis.
(* FILL IN HERE *)
Theorem s_compile_correct : ∀ (st : state) (e : aexp),
s_execute st [] (s_compile e) = [ aeval st e ].
Proof.
(* FILL IN HERE *) Admitted.
☐


{% include 'match_details_roster.html' with id='home' team=match.home_team players=players_home is_staff=home_is_stuff %}
{% include 'match_details_roster.html' with id='guest' team=match.guest_team players=players_guest is_staff=guest_is_staff %}
{% if user.is_staff %}