Send
Close Add comments:
(status displays here)
Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Logic programming overview
1. Logic programming overview
2. Greedy approach
A greedy approach takes the best local approach, which may not be the best global approach.
This approach is used often in algorithms and is mentioned only so that it is not confused with lazy and eager approaches.
3. Eager and lazy
Eager - do it now
Lazy - delay until needed
4. Call by value
Consider a call to function
f using the following call.
f(2+3+4)
In call by value, eager evaluation is used. That is, 2+3+4 evaluates to 9 before the call.
In lazy eval, as used by some functional languages, the expression is not evaluated until needed.
5. Imperative languages
In imperative/command based languages, there is an assignment statement that destructively updates memory.
6. Pure functional languages
In pure functional languages, there is no destructive update.
not as efficient
not as well-known
But it avoids a lot of programming issues (and errors).
7. Correctness
How do you know that a program is correct?
You cannot test it to show it correct.
You can prove it correct for deterministic (sequential) programs.
8. Program verification
Proving programs correct is a field called formal program verification.
The proof rules for imperative programs come from
axiomatic semantics proof rules that come from
denotational semantics theory of programming languages.
Have you ever heard of a loop invariant?
9. Loop invariants
A loop invariant is part of proving programs (with loops for iteration) correct.
Every well-defined loop (that computes a fixed point) has a loop invariant.
10. Functional programs
Functional programs do not have a destructive update nor loops.
inductive proofs
structural induction
11. Parallel programs
The problem is parallel programs.
You cannot prove parallel programs correct using axiomatic proof rules.
What is the solution?
12. Functional programming
The solution is to adopt functional programming techniques.
general: data flow techniques
We have seen this with logical expressions.
What is an easy way to think about this?
13. Thinking functionally
An easy way to think of functional programming is to write your program without ever assigning a variable a value more than once.
14. Logic programming
A related area is logic programming.
It has to with logic - truth tables.
15. Declarative systems
What is to be done: declarative
16. Control
How it is to be done : control issues
17. declarative systems:
Declarative systems:
spreadsheets
word processor
(pure) SQL
18. Logic languages:
Logic languages:
facts
rules
queries - questions
19. Expert systems
Expert systems:
rules-based - right-brained
pattern matching - left-brained
20. End of page