Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Assistant Approach to Automatic Programming Yishai Feldman The Interdisciplinary Center Herzliya.

Similar presentations


Presentation on theme: "The Assistant Approach to Automatic Programming Yishai Feldman The Interdisciplinary Center Herzliya."— Presentation transcript:

1

2 The Assistant Approach to Automatic Programming Yishai Feldman The Interdisciplinary Center Herzliya

3 Programming Activities and Agents Non-accounting Manager brief, vague requirement detailed requirement specification code Accounting Expert System Analyst/Designer Programmer

4 Transformational Approaches specification implementation clearefficient X ** 2X * X m  min(A) m   for i  1 to size(A) do if A[i] < m then m  A[i]

5 Deductive Synthesis Precondition: Postcondition:

6 Very High Level Languages prev := {}; val := {}; val(x) := {x} ; (while newnodes  {}) n from newnodes; (  m  graph {n}) newval := val(n) + cost(n, m); if val(m) = om or val(m) > newval then val(m) := newval; prev(m) := n; if m  y then newnodes with := m; end if; end if; end  ; end while;

7 Natural Language Specification “The RATS transmission times are entered into the schedule” “Each RATS clock transmission times and transmission length is made a component of a new transmission entry which is entered into the transmission schceule” Problem is informality

8 Programming by Example {( )  ( ) (A B)  (A) (A B C D)  (A B) (A B C D E F)  (A B C)} (DEFUN HALF (X) (H X X)) (DEFUN H (X Y) (COND ((ATOM Y) NIL) (T (CONS (CAR X) (H (CDR X) (CDDR X))))))

9 The Assistant Approach

10 Delegating Work to the Apprentice Productivity: Delegate routine details Reliability: Standardization of common practices

11 Example: Table-Lookup function table-lookup(table, key) bucket  table[hash(key)] loop if bucket = nil then return nil entry  head(bucket) if key(entry) = key then return entry bucket  tail(bucket)

12 Table-Insert procedure table-insert(table, entry) push(entry, table[hash(key(entry))])

13 Table-Delete procedure table-delete(table, key) index  hash(key) bucket  table[index] if key(head(bucket)) = key then table[index]  tail(bucket) else bucket-delete(bucket, key) return table

14 Bucket-Delete procedure bucket-delete(bucket, key) previous  bucket loop bucket  tail(previous) if bucket = nil then return nil if key(head(bucket)) = key then tail(previous)  tail(tail(previous)) return nil previous  bucket

15 Analysis: Table-Lookup function table-lookup(table, key) bucket  table[hash(key)] loop if bucket = nil then return nil entry  head(bucket) if key(entry) = key then return entry bucket  tail(bucket)

16 Analysis: Table-Lookup function table-lookup(table, key) bucket  table[hash(key)] loop if bucket = nil then return nil entry  head(bucket) if key(entry) = key then return entry bucket  tail(bucket)

17 Analysis: Table-Lookup function table-lookup(table, key) bucket  table[hash(key)] loop if bucket = nil then return nil entry  head(bucket) if key(entry) = key then return entry bucket  tail(bucket)

18 Analysis: Bucket-Delete procedure bucket-delete(bucket, key) previous  bucket loop bucket  tail(previous) if bucket = nil then return nil if key(head(bucket)) = key then tail(previous)  tail(tail(previous)) return nil previous  bucket

19 Analysis: Bucket-Delete procedure bucket-delete(bucket, key) previous  bucket loop bucket  tail(previous) if bucket = nil then return nil if key(head(bucket)) = key then tail(previous)  tail(tail(previous)) return nil previous  bucket

20 Analysis: Bucket-Delete procedure bucket-delete(bucket, key) previous  bucket loop bucket  tail(previous) if bucket = nil then return nil if key(head(bucket)) = key then tail(previous)  tail(tail(previous)) return nil previous  bucket

21 Analysis: Bucket-Delete procedure bucket-delete(bucket, key) previous  bucket loop bucket  tail(previous) if bucket = nil then return nil if key(head(bucket)) = key then tail(previous)  tail(tail(previous)) return nil previous  bucket

22 The Plan Calculus Wide-spectrum Canonical Language independent Expressive Convenient for manipulation

23 The Knowledge-Based Editor in EMACS (KBEmacs)

24 (DEFUN REPORT-TIMINGS (TIMINGS)) s-X Define a program REPORT-TIMINGS with a parameter TIMINGS.

25 (DEFUN REPORT-TIMINGS (TIMINGS) (WITH-OPEN-FILE (REPORT "report.txt" ':OUT) (LET* ((DATE (TIME:PRINT-CURRENT-TIME NIL)) (LINE 66) (PAGE 0) (TITLE {the title}) (DATA {the input structure of the enumerator})) (FORMAT REPORT "~5%~66: ~2%~66: ~%" TITLE DATE) (LOOP DO (IF ({the empty-test of the enumerator} DATA) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50: ~17A~2%“ PAGE TITLE DATE) (SETQ LINE 3) ({the column-headings} {REPORT, modified} {LINE, modified})) ({the print-item} {REPORT, modified} {LINE, modified} ({the element-accessor of the enumerator} DATA)) (SETQ DATA ({the step of the enumerator} DATA))) ({the summary} {REPORT, modified})))) s-X Insert a simple-report.

26 (DEFUN REPORT-TIMINGS (TIMINGS) (WITH-OPEN-FILE (REPORT "report.txt" ':OUT) (LET* ((DATE (TIME:PRINT-CURRENT-TIME NIL)) (LINE 66) (PAGE 0) (TITLE "Report of Reaction Timings (in msec.)") (DATA {the input structure of the enumerator})) (FORMAT REPORT "~5%~66: ~2%~66: ~%" TITLE DATE) (LOOP DO (IF ({the empty-test of the enumerator} DATA) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50: ~17A~2%“ PAGE TITLE DATE) (SETQ LINE 3) ({the column-headings} {REPORT, modified} {LINE, modified})) ({the print-item} {REPORT, modified} {LINE, modified} ({the element-accessor of the enumerator} DATA)) (SETQ DATA ({the step of the enumerator} DATA))) ({the summary} {REPORT, modified})))) s-N Next Role direct editing

27 (DEFUN REPORT-TIMINGS (TIMINGS) (WITH-OPEN-FILE (REPORT "report.txt" ':OUT) (LET* ((DATE (TIME:PRINT-CURRENT-TIME NIL)) (LINE 66) (LIST TIMINGS) (PAGE 0) (TITLE "Report of Reaction Timings (in msec.)")) (FORMAT REPORT "~5%~66: ~2%~66: ~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50: ~17A~2%“ PAGE TITLE DATE) (SETQ LINE 3) ({the column-headings} {REPORT, modified} {LINE, modified})) ({the print-item} {REPORT, modified} {LINE, modified} {(CAR LIST), the output element}) (SETQ LIST (CDR LIST))) ({the summary} {REPORT, modified})))) s-X Fill the enumerator with a list-enumeration of TIMINGS.

28 (DEFUN REPORT-TIMINGS (TIMINGS) (WITH-OPEN-FILE (REPORT "report.txt" ':OUT) (LET* ((DATE (TIME:PRINT-CURRENT-TIME NIL)) (LINE 66) (LIST TIMINGS) (PAGE 0) (TITLE "Report of Reaction Timings (in msec.)")) (FORMAT REPORT "~5%~66: ~2%~66: ~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50: ~17A~2%“ PAGE TITLE DATE) (SETQ LINE 3)) ({the print-item} {REPORT, modified} {LINE, modified} {(CAR LIST), the output element}) (SETQ LIST (CDR LIST))) ({the summary} {REPORT, modified})))) s-X Remove the column-headings.

29 (DEFUN REPORT-TIMINGS (TIMINGS) (WITH-OPEN-FILE (REPORT "report.txt" ':OUT) (LET* ((DATE (TIME:PRINT-CURRENT-TIME NIL)) (LINE 66) (LIST TIMINGS) (PAGE 0) (TITLE "Report of Reaction Timings (in msec.)")) (FORMAT REPORT "~5%~66: ~2%~66: ~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50: ~17A~2%“ PAGE TITLE DATE) (SETQ LINE 3)) (FORMAT REPORT "~&~5X~8:D" {(CAR LIST), the output element}) (SETQ LINE (+ LINE 1)) (SETQ LIST (CDR LIST))) ({the summary} {REPORT, modified})))) s-F Fill the print-item with a print-out of "~&~5X~8:D".

30 (DEFUN REPORT-TIMINGS (TIMINGS) (WITH-OPEN-FILE (REPORT "report.txt" ':OUT) (LET* ((DATE (TIME:PRINT-CURRENT-TIME NIL)) (LINE 66) (LIST TIMINGS) (PAGE 0) (TITLE "Report of Reaction Timings (in msec.)")) (FORMAT REPORT "~5%~66: ~2%~66: ~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50: ~17A~2%“ PAGE TITLE DATE) (SETQ LINE 3)) (FORMAT REPORT "~&~5X~8:D" {(CAR LIST), the output element}) (SETQ LINE (+ LINE 1)) (SETQ LIST (CDR LIST))) (FORMAT REPORT "~2&~{mean:~8D (deviation: ~:D)~}" (MEAN-AND-DEVIATION TIMINGS))))) s-W What needs to be done? Fill the summary. s-N s-N direct editing

31 (DEFUN REPORT-TIMINGS (TIMINGS) (WITH-OPEN-FILE (REPORT "report.txt" ':OUT) (LET* ((DATE (TIME:PRINT-CURRENT-TIME NIL)) (LINE 66) (LIST TIMINGS) (PAGE 0) (TITLE "Report of Reaction Timings (in msec.)")) (FORMAT REPORT "~5%~66: ~2%~66: ~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 62) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50: ~17A~2%“ PAGE TITLE DATE) (SETQ LINE 3)) (FORMAT REPORT "~&~5X~8:D" (CAR LIST)) (SETQ LINE (+ LINE 1)) (SETQ LIST (CDR LIST))) (FORMAT REPORT "~2&~{mean:~8D (deviation: ~:D)~}" (MEAN-AND-DEVIATION TIMINGS))))) s- Finish editing the function REPORT-TIMINGS

32 KBEmacs Example: Summary Define a simple report program REPORT-TIMINGS with one parameter, a list of timings. Print the title "Report of Reaction Timings (in msec.)". Print each timing and then print a summary showing the mean and deviation of the timings. Do not print any column headings. Define a program REPORT-TIMINGS with a parameter TIMINGS. Insert a simple-report. Fill the title with "Report of Reaction Timings (in msec.)". Fill the enumerator with a list-enumeration of TIMINGS. Remove the column-headings. Fill the print-item with a print-out of "~&~5X~8:D". Fill the summary with (FORMAT... )

33 KBEmacs Example: ADA Define a simple report program UNIT_REPAIR_REPORT. Enumerate the chain of repairs associated with a unit record, printing each one. Query the user for the key (UNIT_KEY) of the unit record to start from. Print the title ("Report of Repairs on Unit " & UNIT_KEY). Do not print a summary. Define a simple_report procedure UNIT_REPAIR_REPORT. Fill the enumerator with a chain_enumeration of UNITS and REPAIRS. Fill the main_file_key with a query_user_for_key of UNITS. Share the first READ and the second READ. Fill the title with ("Report of Repairs on Unit " & UNIT_KEY) Remove the summary.

34 Automated Program Recognition HT-MEMBER is a Set Membership operation. It determines whether or not ELEMENT is an element of the set STRUCTURE. The Set is implemented as a Hash Table. The Hash Table is implemented as an Array of buckets, indexed by hash code. The buckets are implemented as Ordered Lists. They are ordered lexicographically. The elements in the buckets are strings. An Ordered List Membership is used to determine whether or not ELEMENT is in the fetched bucket, BUCKET. (DEFUN HT-MEMBER (STRUCTURE ELEMENT) (LET ((BUCKET (AREF STRUCTURE (HASH ELEMENT)))) (LOOP (IF (NULL BUCKET) (RETURN NIL)) (SETQ ENTRY (CAR BUCKET)) (COND ((STRING> ENTRY ELEMENT) (RETURN NIL)) ((EQUAL ENTRY ELEMENT) (RETURN T))) (SETQ BUCKET (CDR BUCKET)))))

35 And Also The Requirements Apprentice Bug Localization Debugging Reactive Systems Automatic Translation from Assembly to C Automatic Translation of Database Software from Network DML to Embedded SQL Automatic Discovery of Software Contracts


Download ppt "The Assistant Approach to Automatic Programming Yishai Feldman The Interdisciplinary Center Herzliya."

Similar presentations


Ads by Google