Lecture 11 - Formal Methods Flashcards

(18 cards)

1
Q

How bad can bugs be?

A

REFER TO NOTES FOR EXAMPELS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What can we do about bugs?

A

REFER TO NOTES FOR THE EXAMPLE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are formal methods?

A

Formal methods are a collection of methods by which we can take a computer programs and a set of properties that we know should hold of it and obtain strong guarantees that the program satisfies those properties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is formal verification?

A

All software is really very complicated mathematical functions.

  1. Make a mathematical model of our software
    • ideally automatically from your program
  2. Write down the property that you want to hold
    • using some form of logic (e.g. predicate logic)
  3. Proving that the model satisfies the property
    • either done manually or automatically or some form of both.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the formal verification spectrum?

A

Formal methods exists broadly on the following spectrum.
- 1. Testing – no property, no proof
○ Not property, not proof, just random test case or values
- 2. Property-based testing – property but no proof
○ Write down your property you want to hold, computer will generate will generate the tests, but no proofs (might find bugs in manual testing)
- 3. Model checking – property and unknown proof
○ Write down a property (what you want your program to hold) and the computer will automatically go away and try to find that proof that satisfies that property, but it wont tell you the proof (tell you yes or no and trust the computer that it works)
- 4. Interactive Theorem Provers – property and known proof

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the steps to property based testing?

A
  1. User: Define a property P(x).
  2. User: Choose a strategy for generating values for x.
  3. Library: Use the strategy to generate x1 , x2 , … and test P(x1 ), P(x2 ), …
    • The strategy may use the results of the previous tests to inform the generation of the next test.
  4. Library: If a counter-example xi is found, automatically shrink xi to be as simple as possible, and then fail the test.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Property-based testing?

A

Key idea:
- You write down the property.
- The computer generates test cases automatically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the pros and cons of property based testing?

A
  • Pros:
    ○ 1. Write a single test and test many values at the same time.
    ○ 2. Intelligently test a much larger range of values and find many more bugs
    ○ 3. Often quicker to write than normal tests.
    • Cons:
      ○ 1. For complex inputs, defining a strategy for generating data can be complicated.
      ○ 2. Still no hard guarantees
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are Model-checking tools?

A

Key idea:
- You write down the property
- The computer proves it automatically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does model checking work?

A

Procedure for a domain-specific tool:
- 1. User: writes down their property in a high-level language.
- 2. Tool: compiles down the property to a set of SMTLIB queries.
- 3. Tool: calls an SMT solver to answer the queries.
- 4. Tool: converts any counter-example found back into a form understandable by the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the pros and cons of model-checking?

A
  • Pros:
    ○ 1. Formal guarantee of correctness.
    ○ 2. (Sometimes) don’t have to alter your program.
    • Cons:
      ○ 1. Cannot prove more complicated properties
      § see CITS2211 for non-computable problems, e.g. the halting problem.
      ○ 2. Sometimes you are forced to rewrite your program to make life easier for the model checker.
      ○ 3. A counter-example doesn’t immediately tell you why your program has gone wrong.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is interactive theorem provers?

A

Key idea:
- You provide the proof.
- The computer checks it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the problem and solution to interactive theorem provers?

A

Problem: Standard programming languages not designed to write proofs!
Solution: Custom program languages called theorem provers in which you can write both proofs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the pros and cons of interactive theorem provers?

A
  • Pros:
    ○ 1. Formal guarantee of correctness.
    ○ 2. Can represent pretty much any proof or argument.
    ○ 3. Can be used to prove mathematical theorems as well!
    • Cons:
      ○ 1. Writing down a correct proof is 100 times more time-consuming than writing the program!
      ○ 2. You must write your program in specialised languages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Advice on using formal methods

A

REFER TO NOTES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the limitations of formal methods?

A
  • All these methods check whether the program obeys your property
    • None of them guarantee that the property itself is correct
16
Q

How to Uses of LLMs in Formal method?

A

What not to do:
- Ask the LLM “Is this code correct?”

Hot research fields:
- Using LLMs to generate formal properties from human text.
- Automatic program repair based on formal properties.
- Using LLMs as generating strategies in property-based testing.

17
Q

What should the LLM do?

A

When you ask an LLM to “generate code that does X”, the LLM should:
1. Translate X into a formal specification.
2. Generate code that does X.
3. Generate a proof that the code satisfies the specification.
4. Give the proof to an Interactive Theorem Prover to check.
5. (Optional but recommended!) The user checks that the specification means X.