Arvutiteaduse instituut
  1. Kursused
  2. 2021/22 sügis
  3. Programmeerimiskeelte alused (LTAT.03.018)
EN
Logi sisse

Programmeerimiskeelte alused 2021/22 sügis

  • Info
  • Lectures&Homework

Lectures

Week Date Topic Notes
1. 1. sept Logical Foundations Basics, Induction,
2. 8. sept Lists, Polymorphism
3. 15. sept Tactics, Logics in Coq
4. 22. sept Inductively defined Propositions, ProofObjects
5. 29. sept (cont.) IndProp, ProofObjects
6. 6. oct Maps.
7. 13. oct Simple Imperative Programs, More Automation.
8. 20. oct Program Equivalence Tactics: specialize, pose,
remember, assert
9. 27. oct Hoare Logic I
10. 3. nov Hoare Logic I
11. 10. nov Hoare Logic II
12. 17. nov Small-step Operational Semantics
13. 24. nov Type Systems
14. 1. dec The Simply Typed Lambda-Calculus
15. 8. dec Properties of STLC
16. 15. dec delayed (daughter fell ill), will record and upload ASAP

Note: After "Properties of STLC" we have a few chapters to consider but it is not too important that we look at any of them. Probably we shift/extend deadlines by at least one week at some point.

You can browse the material here: Logical Foundations and Programming Language Foundations. To learn it you should download the source files and solve exercises in Coq: lf.tgz and plf.tgz. Submit completed files to Moodle (available soon).

Year 2023

Plan

  1. 2 lectures per week
  2. show terse, prove all
  3. students submit their versions

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Lectures

Lecture # Chapter Notes
1 Preface.v
Basics.v
Induction.v
Lists.v
Poly.v
Tactics.v
Logic.v
IndProp.v
Maps.v
Imp.v
AltAuto.v
AltAuto.v
Perm.v
Sort.v
Multiset.v
Selection.v
Merge.v
SearchTree.v
Extract.v
ADT.v
Redblack.v

LF

Preface.v

Basics.v

  • Goal: base FP language, proof language, simple proofs
  1. Data and Functions
    • Enum-like Inductive, Definition, Compute, bool, match-with-end
    • tactics: simpl, reflexivity
    • exercise: nandb, andb3
    • plus-, mult-like Inductive, nat-s, Fixpoint
    • exercise: factorial, ltb
  2. Proof by Simplification, Proof by Rewriting
    • tactics: intros
    • exercise: plus_id_exercise, mult_n_1
  3. Proof by Case Analysis
    • bullets
    • tactics: destruct X as eqn:Y
    • exercise: andb_true_elim2, zero_nbeq_plus_1, andb_eq_orb, identity_fn_applied_twice

Induction.v

  1. Goal: induction on nat-s
  2. Separate compilation
  3. Proof by Induction
    • tactics: induction
    • exercise: mul_0_r, plus_n_Sm, add_comm, add_assoc, double_plus
  4. Proofs Within Proofs
    • tactics: assert
  5. Formal vs. Informal Proof
  6. More exercises
    • tactics: replace
    • exercise: add_shuffle3, mul_comm, mult_assoc, leb_refl, eqb_refl

Lists.v

  1. Goal: data structures
  2. Pairs of Numbers
    • exercise: snd_fst_is_swap
  3. Lists of Numbers
    • exercise: list_funs, alternate,
  4. Bags via Lists
    • exercise: bag_functions
  5. Reasoning About Lists, Induction on Lists, List Exercises
    • exercise: list_exercises, eqblist, count_member_nonzero, rev_injective
  6. Options
    • exercise: hd_error
  7. Partial Maps
    • eqb_id_refl, update_eq, update_neq

Poly.v

  1. Goal: almost std. lib. definitions, exercises
  2. Polymorphic Lists
    • exercises: poly_exercises, more_poly_exercises
  3. Polymorphic Pairs
    • exercises: split
  4. Polymorphic Options, Functions as Data, Anonymous Functions
    • filter_even_gt7, partition
  5. Map
    • map_rev, flat_map
  6. Fold
    • fold_length
  7. Functions That Construct Functions

Tactics.v

  1. Goal: tools to prove almost anything
  2. The [apply] Tactic
    • tactics: apply
    • exercises: silly_ex, apply_exercise1
  3. The [apply with] Tactic
    • tactics: apply with
    • exercises: trans_eq_exercise
  4. The [injection] and [discriminate] Tactics
    • tactics: injection, discriminate
    • exercises: injection_ex3, discriminate_ex3
  5. Using Tactics on Hypotheses
    • tactics: apply in
  6. Varying the Induction Hypothesis
    • tactics: generalize dependent
    • exercises: eqb_true, gen_dep_practice
  7. Unfolding Definitions, Using [destruct] on Compound Expressions
    • tactics: unfold
    • exercises: combine_split, destruct_eqn_practice
  8. Additional Exercises
    • exercises: -eqb_sym, eqb_trans, filter_exercise

Logic.v

  1. Goal: tools for the logic idioms
  2. the Prop type, Logical Connectives
    • exercises: and_exercise, and_assoc, or_commut
  3. Falsehood and Negation
    • exercises: not_implies_our_not, contrapositive, not_both_true_and_false
  4. Truth, Logical Equivalence
    • exercises: iff_properties
  5. Setoids and Logical Equivalence
  6. Existential Quantification
    • exercises: dist_not_exists, dist_exists_or
  7. Programming with Propositions
    • exercises: In_map_iff (long?), All_In
  8. Applying Theorems to Arguments
  9. Functional Extensionality
    • exercises: tr_rev_correct, even_double_conv,
  10. Propositions vs. Booleans, Working with Decidable Properties
    • exercises: logical_connectives,eqb_list_true_iff, All_forallb,
  11. Classical vs. Constructive Logic
    • exercises: excluded_middle_irrefutable, not_exists_dist

IndProp.v

  1. Goal: Adding theories (safely)
  2. The Collatz Conjecture, Transitive Closure, Permutations, Evenness
    • exercises: ev_double
  3. Using Evidence in Proofs
    • inversion_practice, ev5_nonsense
  4. Induction on Evidence
    • ev_sum, ev_ev__ev
  5. Inductive Relations
    • le_exercises (not all induction H, e.g., Sn_le_Sm__n_le_m: inversion, lt_ge_cases, leb_complete: ind n+destr m), subsequence
  6. A Digression on Notation
  7. Case Study: Regular Expressions
    • tactics: remember
    • exp_match_ex1, re_not_empty, weak_pumping (hint: finish 1st App case and copy-paste the rest, lemmas: app_length, add_le_cases, rewrite app_assoc, plus_le, pumping_constant_0_false hint: destruct s1 in MStarApp case)
  8. Case Study: Improving Reflection
    • reflect_iff,eqbP_practice

Maps.v

  1. Goal: data structure, exercise
  2. The Coq Standard Library, Identifiers, Total Maps
    • t_apply_empty, t_update_eq, t_update_neq, t_update_shadow, t_update_same, t_update_permute
  3. Partial Maps

Imp.v

  1. Goal: exercise tactic(al)s and inductives
  2. Arithmetic and Boolean Expressions, Coq Automation
    • tactics: ;, try, repeat, lia, clear, rename, assumption, contradiction, constructor
    • optimize_0plus_b_sound
  3. Evaluation as a Relation
    • beval_iff_bevalR
  4. Expressions With Variables, Commands, Evaluating Commands
    • ceval_example2
  5. Additional Exercises
    • execute_app, s_compile_correct_aux, s_compile_correct

AltAuto.v

  1. Goal:
  2. Coq Automation
    • re_opt (keep toplevel struct., delay inversion)
  3. Decision Procedures, Search Tactics
    • tactics: lia, auto, info_auto.
    • weak_pumping (copy solution, then simplify)

AltAuto.v

VFA

Perm.v

  • Goal: Correctness proofs require us to state the correctness condition. Permutations can be used to specify sorting algorithms.
  1. The Less-Than Order on the Natural Numbers, Swapping, Permutations
    • permut_example, not_a_permutation
  2. Summary: Comparisons and Permutations
    • Forall_perm

Sort.v

  • Goal: One simple functional algorithm we can prove correct: Insertion sort.
  1. The Insertion-Sort Program, Specification of Correctness, Proof of Correctness
    • insert_sorted, sort_sorted, insert_perm, sort_perm, insertion_sort_correct
  2. Validating the Specification
    • sorted'_sorted

Multiset.v

  • Goal: An alternative way of specifying sorting algorithms.
  1. Multisets
    • union_assoc, union_comm, union_swap
  2. Specification of Sorting, Verification of Insertion Sort
    • insert_contents, sort_contents, insertion_sort_correct
  3. Equivalence of Permutation and Multiset Specifications
    • perm_contents
    • contents_nil_inv (hint: specialize), contents_cons_inv, contents_insert_other
    • contents_perm (hint: pose proof (H a) and specialize (H z))
    • same_contents_iff_perm, sort_specifications_equivalent

Selection.v

  • Goal: VFA practice, Function and termination measure
  1. The Selection-Sort Program, Proof of Correctness
    • select_perm (hint: eauto surprisingly powerful)
    • selsort_perm (hint: induction n, destruct l; use "apply select_perm in E" to fix the first element of the permutation; then use perm_skip and Permutation_length)
    • selection_sort_perm, select_rest_length, select_fst_leq, select_smallest, select_in,
    • cons_of_small_maintains_sort (hint: destruct on bl and its length; use select_in and Forall_forall)
    • selsort_sorted, selection_sort_sorted, selection_sort_is_correct

Recursive Functions That are Not Structurally Recursive selsort'_perm

Merge.v

  • Goal: More VFA practice; Functional induction
  1. Merge Sort
    • split_perm (hint: Permutation_trans and Permutation_middle)
    • sorted_merge1 (hint: bdestruct and auto do most work),
    • sorted_merge (hint: induction on l1 and l2, use sorted_merge1)
    • mergesort_sorts, merge_perm (hint: induction on l1 and l2)
    • mergesort_perm (hint: mergesort_ind)

SearchTree.v

  • Goal: Functional algorithms typically use non-trivial data structures -- which require specification.
  1. BST SearchTree, Invariant
    • empty_tree_BST, insert_BST
  2. Correctness of BST Operations
    • bound_default
  3. Converting a BST to a List
    • elements_complete (hint: in_app_iff),
    • elements_preserves_forall (hint: Forall_app),
    • elements_preserves_relation
    • elements_correct (Hint: induction on BST t, then use in_app_iff, then elements_preserves_relation + bdall)
    • elements_complete_inverse, elements_correct_inverse, sorted_app,
    • sorted_elements (hint: map_app, sorted_app, Forall_map, Forall_forall, elements_preserves_forall)
  4. A Faster [elements] Implementation
    • fast_elements_eq_elements
  5. An Algebraic Specification of [elements]
    • elements_empty,kvs_insert_split (hint: induction on e1, (b)destruct until you can rewrite IHe1; then bdall)
  6. Model-based Specifications
    • in_fst, in_map_of_list, not_in_map_of_list,bound_relate, lookup_relate, insert_relate
  7. Efficiency of Search Trees

Extract.v

  • Goal: We see how to use the verified functional algorithm.
  • Note: might need to change the working directory using 'Cd "...".'
  1. Extraction
  2. Lightweight Extraction to [int]
  3. Insertion Sort, Extracted
    • sort_int_correct
  4. Binary Search Trees, Extracted
    • lookup_insert_eq (hint: bdall), lookup_insert_neq (hint: bdall and Abs_inj)
  5. Performance Tests

ADT.v

  • Goal: How to write and prove modular code in Coq.
  1. The Table ADT, Implementing [Table] with Functions
    • NatFunTableExamples
  2. Implementing [Table] with Lists
    • lists_table
  3. Implementing [Table] with BSTs
  4. Tables with an [elements] Operation
  5. Model-based Specification
    • list_etable_abs
  6. Summary of ADT Verification

Redblack.v

  • Goal: Verifying Redblack searchtree operations (quite realistic algorithms)
  1. Implementation
  2. Case-Analysis Automation
  3. The BST Invariant
    • balanceP, insP, ins_BST
    • insert_BST (hint: destruct ins k v t and use ins_BST on some hypthesis)
  4. Verification
    • balance_lookup
    • lookup_ins_eq
    • lookup_ins_neq (hint: bdall and Abs_inj)
    • lookup_insert_eq, lookup_insert_neq (hint: destruct (ins k v t))
  5. Efficiency
    • RB_blacken_parent
    • RB_blacken_root
    • ins_RB (hint: similar start "destruct (IHt1 n0); clear IHt1. ..." in all 3 cases)
    • insert_RB
    • redblack_balanced
  6. Performance of Extracted Code
  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.
Courses’i keskkonna kasutustingimused