📄 http:^^www.cs.washington.edu^education^courses^415^prog3.solution.html
字号:
Date: Mon, 02 Dec 1996 14:42:00 GMTServer: NCSA/1.4.2Content-type: text/html<HEADER><TITLE>CSE 415 Prog. Assignment 3 Sample Solution</TITLE></HEADER><BODY><pre>;First is the output from the listener(this was done on a mac).;Welcome to Macintosh Common Lisp Version 3.0!;? ;;Loading #P"Macintosh HD:Desktop Folder:trig_code.lisp"...;? (demonstration idtree features_20);FAMILIARIZATION HEURISTIC;SCORE 5 IDENTITY# 5 ;SIMPLIFICATION HEURISTIC;SCORE 0 IDENTITY# 4 ;SCORE 0 IDENTITY# 1 ;SCORE 0 IDENTITY# 2 ;SCORE 0 IDENTITY# 10 ;SCORE 0 IDENTITY# 6 ;SCORE -2 IDENTITY# (5) ;SCORE 0 IDENTITY# 3 ;SCORE 2 IDENTITY# (14) ;SCORE 0 IDENTITY# 11 ;SCORE -3 IDENTITY# (8) ;SCORE 0 IDENTITY# 9 ;SCORE 0 IDENTITY# 15 ;SCORE 0 IDENTITY# 12 ;SCORE 0 IDENTITY# 13 ;SCORE 0 IDENTITY# 7 ;BEST SCORE;SCORE 2 IDENTITY# (14) ;EFFECTIVENESS HEURISTIC;SCORE 0 IDENTITY# 4 ;SCORE 0 IDENTITY# 1 ;SCORE 0 IDENTITY# 2 ;SCORE 0 IDENTITY# 10 ;SCORE 0 IDENTITY# 6 ;SCORE 8 IDENTITY# 5 ;SCORE 0 IDENTITY# 3 ;SCORE 20 IDENTITY# 14 ;SCORE 0 IDENTITY# 11 ;SCORE 8 IDENTITY# 8 ;SCORE 0 IDENTITY# 9 ;SCORE 0 IDENTITY# 15 ;SCORE 0 IDENTITY# 12 ;SCORE 0 IDENTITY# 13 ;SCORE 0 IDENTITY# 7 ;BEST SCORE;SCORE 20 IDENTITY# 14 ;NIL;? (demonstration idtree features_28);FAMILIARIZATION HEURISTIC;SCORE 5 IDENTITY# 5 ;SIMPLIFICATION HEURISTIC;SCORE 0 IDENTITY# 4 ;SCORE 0 IDENTITY# 1 ;SCORE 0 IDENTITY# 2 ;SCORE 0 IDENTITY# 10 ;SCORE 0 IDENTITY# 6 ;SCORE 4 IDENTITY# (5) ;SCORE 0 IDENTITY# 3 ;SCORE 0 IDENTITY# 14 ;SCORE 0 IDENTITY# 11 ;SCORE -3 IDENTITY# (8) ;SCORE -3 IDENTITY# (9) ;SCORE 0 IDENTITY# 15 ;SCORE 0 IDENTITY# 12 ;SCORE 0 IDENTITY# 13 ;SCORE 0 IDENTITY# 7 ;BEST SCORE;SCORE 4 IDENTITY# (5) ;EFFECTIVENESS HEURISTIC;SCORE 0 IDENTITY# 4 ;SCORE 0 IDENTITY# 1 ;SCORE 0 IDENTITY# 2 ;SCORE 0 IDENTITY# 10 ;SCORE 0 IDENTITY# 6 ;SCORE 32 IDENTITY# 5 ;SCORE 0 IDENTITY# 3 ;SCORE 8 IDENTITY# 14 ;SCORE 0 IDENTITY# 11 ;SCORE 8 IDENTITY# 8 ;SCORE 4 IDENTITY# 9 ;SCORE 0 IDENTITY# 15 ;SCORE 0 IDENTITY# 12 ;SCORE 0 IDENTITY# 13 ;SCORE 0 IDENTITY# 7 ;BEST SCORE;SCORE 32 IDENTITY# 5 ;NIL;? (demonstration idtree features_38);FAMILIARIZATION HEURISTIC;SCORE 35 IDENTITY# 4 ;SIMPLIFICATION HEURISTIC;SCORE 1 IDENTITY# (4) ;SCORE 0 IDENTITY# 1 ;SCORE 0 IDENTITY# 2 ;SCORE 0 IDENTITY# 10 ;SCORE 0 IDENTITY# 6 ;SCORE 0 IDENTITY# 5 ;SCORE 0 IDENTITY# 3 ;SCORE 0 IDENTITY# 14 ;SCORE 0 IDENTITY# 11 ;SCORE 0 IDENTITY# 8 ;SCORE 0 IDENTITY# 9 ;SCORE 0 IDENTITY# 15 ;SCORE 0 IDENTITY# 12 ;SCORE 0 IDENTITY# 13 ;SCORE 0 IDENTITY# 7 ;BEST SCORE;SCORE 1 IDENTITY# (4) ;EFFECTIVENESS HEURISTIC;SCORE 8 IDENTITY# 4 ;SCORE 0 IDENTITY# 1 ;SCORE 0 IDENTITY# 2 ;SCORE 0 IDENTITY# 10 ;SCORE 0 IDENTITY# 6 ;SCORE 0 IDENTITY# 5 ;SCORE 0 IDENTITY# 3 ;SCORE 0 IDENTITY# 14 ;SCORE 0 IDENTITY# 11 ;SCORE 0 IDENTITY# 8 ;SCORE 0 IDENTITY# 9 ;SCORE 0 IDENTITY# 15 ;SCORE 0 IDENTITY# 12 ;SCORE 0 IDENTITY# 13 ;SCORE 0 IDENTITY# 7 ;BEST SCORE;SCORE 8 IDENTITY# 4 ;NIL;? ;NEXT IS my code:;; Program #3; CSE 415 - Holden;; TO TEST YOUR OWN ID - see the //// box below the data structure.; This program makes a heuristically guided choice of what identity to use ; in proving a new trig identity. The first piece of code sets up the data ; structure consisting of all the id's which are already known to be true. ; Each id is a sublist off the main list consisting of four items:; 1) Features of left side; 2) Features of right side; 3) Identity number; 4) Familiarity score (taken from copy packet 1);; Each feature list consists of an atom followed by it's simplification score; for that identity. After the first item's f-score, the next atom, and so on.(setq IDTREE `(((BF 1) (1 -1) 4 35) ((A -1) (BC 1) 1 17) ((AD 1) (B -1) 2 17) ((AC+B 3 AC -1 B -3) (F -3) 10 8) ((CD 1) (1 -1) 6 6) ((AA+BB 4 AA -2 BB -2) (1 -4) 5 5) ((AE 1) (1 -1) 3 5) ((CC+1 2 CC -2 1 -4) (FF -2) 14 4) ((A+BD 3 A -3 BD -1) (E -3) 11 2) ((AA+ABD 5 AA -3 ABD -1) (1 -5) 8 1) ((ABC+BB 5 ABC -1 BB -3) (1 -5) 9 1) ((DD+1 2 DD -2 1 -4) (EE -2) 15 -2) ((BC+BD 4 BC -2 BD -2) (E -4) 12 -3) ((AC+AD 4 AC -2 AD -2) (F -4) 13 -3) ((ABC+ABD 6 ABC -2 ABD -2) (1 -6) 7 -5) ) ); Next is the data structure for each identity to be tested. For each identity,; all features are in a single list in the following structure:; First is the feature, followed by an integer which = the number of symbols in; the atom. The third element is an integer which indicates where the given ; feature is located in the equation:; 1 = feature is on the left side only; 2 = feature is on both sides ; 3 = feature is on the right side only; The sequence repeats itself for each feature. The features are listed in ; sequential order by where they are located. In other words, features which ; are on the left side only are first, then those on both sides, and then those; on the right side only.(setq features_20 '(AA+AACC 7 1 CC+1 4 1 AACC 4 1 AA 2 1 CC 2 2))(setq features_28 '(AA+BB 5 1 AA 2 1 BB 2 2 BBFF 4 3 FF 2 3))(setq features_38 '(AF+BF 5 1 A+B 3 1 AF 2 1 BF 2 1 C+1 3 3));/////////////////////////////////////////////////////////////////////////////; TO TEST YOUR OWN ID, first put it in standard form. Next, make a list of the ; features which are in the id on either side. Next, order them according to ; descending weight by the number of symbols. Then, each feature should be ; followed by 2 numbers according to the description above. Finally, do any ; reordering necessary to ensure that the features are in order according to ; their third element. ie - the features on the left side only(1) followed; by those on both sides(2) followed by those only on the right side(3). To; test the id, type (demonstration idtree YOUR_ID'S_FEATURE_LIST). The program; will then demonstrate all 3 heuristics. You can use the 3 listed above this; box as examples on how to do the conversion.;/////////////////////////////////////////////////////////////////////////////;==============================================================================;; Output functions;==============================================================================;"print_cons_cell" takes, as an argument, a list which has already been tested ; for NIL and END_OF_LIST. It prints out the first set of values, tests for the; end of the list, and then recursively calls itself if not at the end. The ; format t statement is used to make pretty output on the terminal. Each ; heuristic will put its output in the form of a list of cons cells with ; END_OF_LIST as the last element in order to use this function.(defun print_cons_list (list) (format t "SCORE ~S IDENTITY# ~S ~%" (car (car list)) (cdr (car list))) (COND ((EQUAL (SECOND list) 'END_OF_LIST) NIL) ((EQUAL 1 1) (print_cons_list (cdr list)))));"print_output" takes a given heuristics output(a cons cell list), checks for an; empty list, and then calls print_cons_list to do its output.(defun print_output (list) (COND ((EQUAL list NIL) NIL) ((EQUAL list 'END_OF_LIST) 'NO_SOLUTION) ((EQUAL 1 1) (print_cons_list list))));"best_score" scans through a list of cons cells comparing each cons cell's ; left child. By using ><= it finds the left child of greatest value and ; returns that value.(defun best_score (list max_score) (COND ((EQUAL (FIRST list) 'END_OF_LIST) max_score) ((OR (> max_score (car (FIRST list))) (EQUAL max_score (car (FIRST list)))) (best_score (cdr list) max_score)) ((< max_score (car (car list)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -