Presentation is loading. Please wait.

Presentation is loading. Please wait.

What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.

Similar presentations


Presentation on theme: "What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019."— Presentation transcript:

1 What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019 מבוא מורחב

2 Declarative Knowledge
“What is true” knowledge 2/23/2019 מבוא מורחב

3 Imperative Knowledge “How to” knowledge
To find an approximation of square root of x: Make a guess G Improve the guess by averaging G and x/G Keep improving the guess until it is good enough X = 2 G = 1 X/G = 2 G = ½ (1+ 2) = 1.5 X/G = 4/3 G = ½ (3/2 + 4/3) = 17/12 = X/G = 24/17 G = ½ (17/ /17) = 577/408 = 2/23/2019 מבוא מורחב

4 “How to” knowledge Process – series of specific, mechanical steps for deducing information, based on simpler data and set of operations Procedure – particular way of describing the steps a process will evolve through Need a language for description: vocabulary rules for connecting elements – syntax rules for assigning meaning to constructs – semantics Using language of procedures to solve problems 2/23/2019 מבוא מורחב

5 Scheme Basics Rules for Scheme
Legal expressions have rules for constructing from simpler pieces (Almost) every expression has a value, which is “returned” when an expression is “evaluated”. Every value has a type. 2/23/2019 מבוא מורחב

6 Language Elements Primitives Means of combination Means of abstraction
2/23/2019 מבוא מורחב

7 Language elements -- primitives
Numbers – self-evaluating rule 23  23 -36  -36 Names for built-in procedures +, *, /, -, =, … What is the value of such an expression? +  [#procedure …] Evaluating by looking up value associated with name 2/23/2019 מבוא מורחב

8 Language elements – combinations
How do we create expressions using these procedures? (+ 2 3) Close paren Open paren Expression whose value is a procedure Other expressions Evaluate by getting values of subexpressions, then apply operator to values of arguments 2/23/2019 מבוא מורחב

9 Language elements - combinations
Can use nested combinations – just apply rules recursively (+ (* 2 3) 4) 10 (* (+ 3 4) (- 8 2)) 42 2/23/2019 מבוא מורחב

10 Language elements -- abstractions
In order to abstract an expression, need way to give it a name (define score 23) This is a special form Does not evaluate second expression Rather, it pairs that name with the value of the third expression in an environment Return value is unspecified 2/23/2019 מבוא מורחב

11 Language elements -- abstractions
To get the value of a name, just look up pairing in environment score  23 Note that we already did this for +, *, … (define total ( )) (* 100 (/ score total))  92 can create a complex thing, name it, treat it as primitive 2/23/2019 מבוא מורחב

12 Scheme Basics Rules for evaluation If self-evaluating, return value.
If a name, return value associated with name in environment. If a special form, do something special. If a combination, then a. Evaluate all of the subexpressions of combination (in any order) b. apply the operator to the values of the operands (arguments) and return result 2/23/2019 מבוא מורחב

13 Capturing common patterns
Here are some common patterns (* 5 5) (* 23 23) (* score score) (* x x) How do we generalize (e.g. the last expression)? 2/23/2019 מבוא מורחב

14 Language elements -- abstractions
Need to capture ways of doing things – use procedures (lambda (x) (* x x)) parameters body To process something multiply it by itself Special form – creates a procedure and returns it as value 2/23/2019 מבוא מורחב

15 Language elements -- abstractions
Use this anywhere you would use a proceduure ((lambda (x) (* x x)) 5) 2/23/2019 מבוא מורחב

16 Scheme Basics Rules for evaluation Rules for application
If self-evaluating, return value. If a name, return value associated with name in environment. If a special form, do something special. If a combination, then a. Evaluate all of the subexpressionss of combination (in any order) b. apply the operator to the values of the operands (arguments) and return result Rules for application If procedure is primitive procedure, just do it. If procedure is a compound procedure, then: evaluate the body of the procedure with each formal parameter replaced by the corresponding actual argument value. 2/23/2019 מבוא מורחב

17 Language elements -- abstractions
Use this anywhere you would use a proceduure ((lambda (x) (* x x)) 5) (* 5 5) 25 Can give it a name (define square (lambda (x) (* x x))) (square 5)  25 2/23/2019 מבוא מורחב

18 Taxonomy of Expressions
Primitive Expressions Constants (self-evaluating) Numerals, e.g.17 == Sch-Num 7 Strings, e.g. “hello” == Sch-String hello Booleans, e.g. #f, #t == Sch-Bool Names E.g. + == primitive procedure E.g. x == variable created by define or procedure application Compound Expressions Combinations: (<operator> <operand> <operand> …) Special forms: Define: (define <name> <exp>) Lambda: (lambda (<formal1> <formal2> …) <body>) If: (if <predicate> <consequent> <alternative>) …. More to come 2/23/2019 מבוא מורחב


Download ppt "What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019."

Similar presentations


Ads by Google