2

For this problem, I'm assigned to implement a function that decides the output of a decision tree given the data. The logic: If it's a symbol, then that's the value to output otherwise, lookup the value of varname in the memory, and if it's less than or equal to the threshold, look for the value in the left-tree, and if it's greater than the threshold, look for the value in the right-tree

A decision tree is either: A symbol, e.g, 'versicolor or [ varname threshold left-tree right-tree ]

Here is what I've already done,

(defun decision (tree memory)
  (if (not (equal (len tree) 0))
      (if (not (equal (first tree) (first memory)))
          (decision tree (rest memory))
          (if (<= (second tree) (second memory))
              (decision (third tree) memory)
              (decision (fourth tree) memory)))
      tree))

Here's one unit test:

(check-expect (decision *IRIS-DECISION-TREE* 
                        (search-list-to-tree '((petal-length 2) 
                                               (petal-width 2)
                                               (sepal-length 5)))) 
              'setosa)

Here is the definition of the constant used

(defconst *IRIS-DECISION-TREE*
  '(petal-length 245/100
    setosa
    (petal-width 175/100
      (petal-length 495/100
        (petal-width 165/100
          versicolor
          virginica)
        (petal-width 155/100
          virginica
          (sepal-length 695/100
            versicolor
            virginica)))
      (petal-length 485/100
        (sepal-length 595/100
          versicolor
          virginica)
        virginica))))

I keep getting errors when the function reaches the recursion call. It says "ACL2 Error in ( DEFUN DECISION ...): No :MEASURE was supplied with the definition of DECISION."

I tested every if statement to see if they work, and ran the logic of the code through my head multiple times and it seems like the only problem I might have could be an error in syntax but it all seems right.

GokRix
  • 65
  • 1
  • 11
  • 1
    The "No :measure" message leads to http://www.cs.utexas.edu/users/moore/acl2/v2-6/INTRODUCTION.html ; since you are trying to prove by induction, you need a strictly decreasing measure but ACL2 could not find one itself. Maybe the length of tree could be that measure, but I don't know enough about it to show an actual example. – coredump May 15 '19 at 20:23
  • 2
    The second `if` looks a bit suspicious. If there is no element in `memory` that is `equal` to `(first tree)`, the recursion will loop through `memory` until the `rest` starts returning `nil`, but there is no end condition, so the recursion will be infinite. – jkiiski May 16 '19 at 06:26

0 Answers0