1 / 35

The Assistant Approach to Automatic Programming

The Assistant Approach to Automatic Programming. Yishai Feldman The Interdisciplinary Center Herzliya. Accounting Knowledge. brief, vague requirement. Accounting Expert. detailed requirement. System Analyst/Designer. Programming Knowledge. specification. Programmer. code.

dvallo
Télécharger la présentation

The Assistant Approach to Automatic Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Assistant Approachto Automatic Programming Yishai Feldman The Interdisciplinary Center Herzliya

  2. Accounting Knowledge brief, vague requirement Accounting Expert detailed requirement System Analyst/Designer Programming Knowledge specification Programmer code Programming Activitiesand Agents Non-accounting Manager

  3. Transformational Approaches clear efficient specification X ** 2 X * X m min(A) m  fori  1 to size(A) do ifA[i] < mthen m  A[i] implementation

  4. Precondition: Postcondition: Deductive Synthesis

  5. Very High Level Languages prev := {}; val := {}; val(x) := {x} ; (whilenewnodes {}) nfromnewnodes; ( m  graph {n}) newval := val(n) + cost(n, m); ifval(m) = om or val(m) > newvalthen val(m) := newval; prev(m) := n; if m  ythen newnodeswith:= m; end if; end if; end ; end while;

  6. 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

  7. 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))))))

  8. The Assistant Approach

  9. Delegating Workto the Apprentice • Productivity: Delegate routine details • Reliability: Standardization of common practices

  10. Example: Table-Lookup functiontable-lookup(table, key) bucket table[hash(key)] loop ifbucket = nilthen return nil entry head(bucket) ifkey(entry) = keythen return entry bucket  tail(bucket)

  11. Table-Insert proceduretable-insert(table, entry) push(entry, table[hash(key(entry))])

  12. Table-Delete proceduretable-delete(table, key) index hash(key) bucket table[index] ifkey(head(bucket)) = key thentable[index]  tail(bucket) elsebucket-delete(bucket, key) returntable

  13. Bucket-Delete procedurebucket-delete(bucket, key) previous bucket loop bucket tail(previous) ifbucket = nilthen return nil ifkey(head(bucket)) = keythen tail(previous) tail(tail(previous)) return nil previous bucket

  14. Linear Search Analysis: Table-Lookup functiontable-lookup(table, key) bucket table[hash(key)] loop ifbucket = nilthen return nil entry head(bucket) ifkey(entry) = keythen return entry bucket  tail(bucket)

  15. List Enumeration Analysis: Table-Lookup functiontable-lookup(table, key) bucket table[hash(key)] loop ifbucket = nilthen return nil entry head(bucket) ifkey(entry) = keythen return entry bucket  tail(bucket)

  16. List Enumeration Analysis: Table-Lookup functiontable-lookup(table, key) bucket table[hash(key)] loop ifbucket = nilthen return nil entry head(bucket) ifkey(entry) = keythen return entry bucket  tail(bucket) Linear Search

  17. Linear Search Analysis: Bucket-Delete procedurebucket-delete(bucket, key) previous bucket loop bucket tail(previous) ifbucket = nilthen return nil ifkey(head(bucket)) = keythen tail(previous) tail(tail(previous)) return nil previous bucket

  18. Trailing- Pointer List Enumeration Analysis: Bucket-Delete procedurebucket-delete(bucket, key) previous bucket loop bucket tail(previous) ifbucket = nilthen return nil ifkey(head(bucket)) = keythen tail(previous) tail(tail(previous)) return nil previous bucket

  19. Splice Out Analysis: Bucket-Delete procedurebucket-delete(bucket, key) previous bucket loop bucket tail(previous) ifbucket = nilthen return nil ifkey(head(bucket)) = keythen tail(previous) tail(tail(previous)) return nil previous bucket

  20. Analysis: Bucket-Delete procedurebucket-delete(bucket, key) previous bucket loop bucket tail(previous) ifbucket = nilthen return nil ifkey(head(bucket)) = keythen tail(previous) tail(tail(previous)) return nil previous bucket Trailing- Pointer List Enumeration Linear Search Splice Out

  21. The Plan Calculus • Wide-spectrum • Canonical • Language independent • Expressive • Convenient for manipulation

  22. The Knowledge-Based Editorin EMACS (KBEmacs)

  23. s-X Define a program REPORT-TIMINGS with a parameter TIMINGS. <end> (DEFUN REPORT-TIMINGS (TIMINGS))

  24. s-X Insert a simple-report. <end> (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:<~A~>~2%~66:<~A~>~%" 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:<~A~>~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}))))

  25. s-N Next Role direct editing (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:<~A~>~2%~66:<~A~>~%" 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:<~A~>~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}))))

  26. s-X Fill the enumerator with a list-enumeration of TIMINGS. <end> (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:<~A~>~2%~66:<~A~>~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50:<~A~>~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}))))

  27. s-X Remove the column-headings. <end> (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:<~A~>~2%~66:<~A~>~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50:<~A~>~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}))))

  28. s-F Fill the print-item with a print-out of "~&~5X~8:D". <end> (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:<~A~>~2%~66:<~A~>~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50:<~A~>~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}))))

  29. s-W What needs to be done? Fill the summary. s-N s-N direct editing (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:<~A~>~2%~66:<~A~>~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 63) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50:<~A~>~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)))))

  30. s-<end> Finish editing the function REPORT-TIMINGS (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:<~A~>~2%~66:<~A~>~%" TITLE DATE) (LOOP DO (IF (NULL LIST) (RETURN)) (WHEN (> LINE 62) (SETQ PAGE (+ PAGE 1)) (FORMAT REPORT "~|~%Page:~3D~50:<~A~>~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)))))

  31. 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 ... )

  32. 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.

  33. Automated Program Recognition (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))))) 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.

  34. 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

More Related