18
Invariant Based Invariant Based Programming Programming in Education in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Embed Size (px)

Citation preview

Page 1: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Invariant Based Invariant Based Programming Programming in Educationin Education

Tutorial, FM’08Linda Mannila

26.5.2008

Page 2: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

BackgroundBackgroundChallenges at CS departments

◦ First year students have weak skills in logic, formal reasoning, writing proofs etc.

◦ Students do not see a connection between theoretical and practical courses

Goal◦ Giving students hands-on skills in

constructing proofs and reasoning about correctness early on

◦ Linking theory with practice

Page 3: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

IBP in EducationIBP in EducationCourse for PhD students in 200515 case study sessions with

faculty, students, researchersUndergraduate course, given

twice, starting in spring 2007

Page 4: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Undergraduate CourseUndergraduate CourseElective (~15 students/course)Prerequisities:

◦ Introductory programming◦Logic

17 interactive, example-driven sessions ◦4 (7) sessions with SOCOS

Addition, ..., linear search, ..., sortingEvaluation

◦questionnaires, interviews, observations, assignments, exam

Page 5: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Experienced benefits (+)Experienced benefits (+)Introduction to program correctness and formal verification

Good introduction to formal verification and how tools can be used in that context

Helps remove errors in the algorithm that could lead to bugsA practical method for introducing program correctness

IBP summarizes the proof conditions in a good way IBP is intuitive

Introduction to a more abstract view of programming Learning to think about how a program works in general,

without a given programming language Learned to think about a program as states and transitions

instead of merely as transitions as is usually the caseMore tangible overview of the program structure

Learning to draw a program makes it easier to see its structure

Makes it easy to keep the track of the various parts of a program

New and useful contents

Page 6: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Experienced difficulties (-)Experienced difficulties (-)Syntax and notation

◦ It’s difficult to formulate one’s programs according to the standard

◦Since I have programmed previously e.g. the Java way of expressing things is quite ingrained

Proofs◦Proving programs by hand is very work

intense◦Proving complex programs is difficult

Finding the correct invariant and postcondition

Using SOCOS

Page 7: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Preliminary error analysisPreliminary error analysisOnly minor problems related to the

◦ Method (e.g. the syntax)◦ Algorithm

Main problem◦ Weak logical background◦ Interpreting and constructing quantified

expressions◦ Understanding when to use quantifiers◦ Understanding which one to use

Problems with logic affect other aspects ◦ Unclear invariants (not necessarily weak)◦ Unclear proofs

Page 8: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

ConclusionsConclusionsLearning IBP is not difficult

◦Students get the big picture rather quickly◦Appreciate the diagrammatic notation

Main difficulties related to predicate logic◦More focus on using logic in practice◦Students need more practice in reading

and constructing quantified expressionsRemedy?

◦Split the course into two parts: 1) manual and 2) with tool support

More time for practice

Page 9: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Assignment Results Assignment Results (2007)(2007)Scores

◦ Average 25.5 (max 40) ◦ Seven students > 30 points

Most common errors◦ Syntax related (e.g. using Java like syntax

or not following the given proof format)Other errors

◦ Incomplete invariants ◦ Problems with the algorithm◦ Using undeclared variables◦ One “off by one” error

Page 10: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008
Page 11: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008
Page 12: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008
Page 13: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Error analysis (2008)Error analysis (2008)Jonas Erikson, Master’s ThesisAnalyzed student solutions to four

assignments (all in all ~50 solutions)

Three main error categories:◦Syntax (related to the diagram

representation)◦Reasoning (related to misconceptions

and weak understanding)◦Logical background (related to having a

weak background in expressing logical statements)

Page 14: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Total number of errorsTotal number of errors

Nested loops

Page 15: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Related to syntaxRelated to syntax

Page 16: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Related to reasoningRelated to reasoning

Nested loops

Page 17: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

Related to logical backgroundRelated to logical background

Define own predicates,use quantifiers to a larger extent

Page 18: Invariant Based Programming in Education Tutorial, FM’08 Linda Mannila 26.5.2008

DiscussionDiscussionCould IBP be introduced at high

school level?◦As a course in mathematics?◦Would the method need to be

simplified? How?