CS 345H: Programming Languages (Honors) Spring 2024
Homework 1: Denotational Semantics and Rosette
Due date: February 15, 6pm
Grading: 15% (CS 345H) or 9% (CS 386L) of your course grade
In this homework, we'll continue our exploration of denotational semantics, a style of programming language semantics that uses mathematical functions to define the meaning of programs.
The homework is in three parts (but only two files):
- In Part 1, we'll extend the expression language expr semantics we studied in lecture to include support for variables, and add some program optimizations to the language.
- In Part 2, we'll develop the syntax and semantics for a new register machine language, and then build and prove a compiler from exprs to this language.
- In Part 3, we'll bring our semantics over to Rosette and see how we can use automated programming tools to build a compiler without hand-writing it.
Table of contents
Preparation
First, make sure you have Coq installed and working, following the instructions from Homework 0.
We'll also be working with Rosette in this homework, so we need to get the Racket programming language and Rosette itself set up on your system. Start by installing Racket (at least v8.1). On a Mac, you can get it from Homebrew:
brew install --cask racket
On Linux or Windows (or Mac, if you don't use Homebrew), download and run the appropriate installer from from the Racket website. If you're on Linux, don't get Racket from your package manager—most of them have very outdated versions of Racket that won't work.
We'll need access to the raco command-line tool that comes with Racket. Try running:
raco help
from a terminal. If it works, jump down to installing Rosette below. If not, you need to get the directory you installed Racket into onto your PATH. The Beautiful Racket book has some good instructions on how to do this.
Install Rosette
To install Rosette from the command line:
raco pkg install --auto rosette
You can test that it worked correctly by running something like:
racket -I rosette -e 1
If you just see 1 as output, you're good to go. Otherwise, something went wrong when installing Rosette—try to read back through the output of the installation and debug (or ask for help).
Choosing a Rosette IDE
Racket comes with the DrRacket IDE, which might be a good place to start, especially if you've never written Racket before. It comes with a bunch of useful features like highlighting the source of bindings (try mousing over stuff!). On a Mac, DrRacket will be in the /Applications/Racket v8.11 folder.
The Magic Racket extension for Visual Studio Code is also a pretty good option.
Get the code
We'll be using GitHub Classroom to check out and submit this homework. Follow the GitHub Classroom URL on Ed to create your private copy of the homework repository, and then clone that repository to your machine. For example, the repository it created for me is called hw1-jamesbornholt, so I would do:
git clone [email protected]:utcs345h-24sp/hw1-jamesbornholt.git cd hw1-jamesbornholt
To make sure everything's working with your Rosette install, run:
raco test Homework.rkt
You should see 31 failing tests. You'll know you've finished the Rosette part of the homework when all these tests pass!
Complete the homework
In your repository, there are two files you'll need to edit. Homework.v is the Coq file for Parts 1 and 2 of the homework, and Homework.rkt is the Rosette file for Part 3. Both files use comments to explain what's going on and list the problems you need to solve. A few of the problems in both files ask for English answers rather than code; for those questions, you should just add your answer in the file as a comment.
Resources for writing Coq
Coq has a slightly steep learning curve. Here are some resources you could reference if you need help understanding how to write Coq or Coq proofs:
- UW's CSE 505 has some great notes on Coq in their first few lectures.
- The first chapter of Software Foundations is a crash course on both Coq programming and proofs.
-
If you're trying to find tactics to use in proofs:
- Joe Redmon's Coq Tactics Index is somewhat (in)famous
- Cornell's CS3110 has a Coq tactics cheatsheet
- Coq's standard library documentation is extensive. Use it to find helpful lemmas about data structures you're using from the standard library (which, in this homework, is just nat from the Arith module).
- You can also try Coq's built-in Search command, as this blog post explains
Resources for writing Rosette
Rosette is a language we haven't spent much time talking about, so here are a few references for learning Racket and Rosette:
-
The official Racket Guide is very thorough and useful
- The official Racket Reference gives more details about Racket
- The "Explainers" section of Beautiful Racket has nice introductions to Racket language features
- For Rosette, the official documentation is pretty good
- There is also a Rosette tutorial from CAV 2019
- How can I resist this opportunity to promote my blog about Rosette to a captive audience?
What to submit
Submit your solutions by committing your changes in Git and pushing them to the private repository GitHub Classroom created for you in the Get the code step.
The only files you should need to modify are Homework.v and Homework.rkt.
GitHub Classroom will automatically select your most recent pushed commit before the deadline as your submission. There's no need to manually submit anything else via Canvas or GitHub.
GitHub Classroom also has a simple autograder for Coq proofs and Rosette code using GitHub Actions. It will pass as long as your Homework.v file compiles, and your Homework.rkt tests pass. This is only a partial grader, so just because the autograder passes doesn't mean you'll get full points—we will still read your code by hand. Also, the autograder does not grade the extra credit question.