Skip to content

Confusing synthesizer behavior (choosing integers vs. forms) #277

@jefftrull

Description

@jefftrull

I am trying to synthesize choices of integers as well as forms inside a grammar, by using both the ?? and (choose ... forms. I haven't been able to do it successfully yet. Below is a small test case. I am trying to map a struct consisting of three integers to another one where one of the integers has been copied to another. For example, I might specify that (A B C) should become (A B B) for all possible A, B, and C. The results are very strange. But first, the code:

#lang rosette/safe

(define-symbolic A B C integer?)
(struct state (A B C) #:transparent)

; sketch
(define (mover s)
  (synthesized s #:depth 1))

; checker
; implements B = A
(define (check-mover impl s)
  (let ((result (impl s)))
    (assert (= (state-A result) (state-A s)))
    (assert (= (state-B result) (state-A s)))
    (assert (= (state-C result) (state-C s)))
))

; an example that passes check-mover
(define (moveBtoA s)
  (state (state-A s) (state-A s) (state-C s)))

(check-mover moveBtoA (state 11 12 13))

(require rosette/lib/synthax)
(define-grammar (synthesized s)
  [expr
   (choose
    s
    ((uop) (expr)))]
  [uop
    ; PROBLEM AREA
   (lambda (s)
     ; perform a move from A, B, or C to A, B, or C determined by two integers
     (let* ((srcno (??))
            (dstno (??))
            (src (if (= srcno 0) (state-A s) (if (= srcno 1) (state-B s) (state-C s)))))
       ; restrict values
       (assert (and (>= dstno 0) (< dstno 3)
                    (>= srcno 0) (< srcno 3)))
       (state (if (= dstno 0) src (state-A s))
              (if (= dstno 1) src (state-B s))
              (if (= dstno 2) src (state-C s)))))
   )])

(define sol
  (synthesize
   #:forall (list A B C)
   #:guarantee (check-mover mover (state A B C))))

(if (sat? sol) (print-forms sol) (print "UNSAT"))

The result is quite peculiar:

(define (mover s) ((uop) s))

uop is a label inside the grammar. What is it doing as part of the synthesized function? Did I do something wrong?

If instead of asking the synthesizer to choose values for srcno and dstno I replace the code labeled PROBLEM AREA (the lambda) with a (choose... form that lists two possible implementations, it picks the correct one, and uop does not appear in the result:

   (choose
    (lambda (s)
      (state (state-A s) (state-B s) (state-A s)))  ; C = A
    (lambda (s)
      (state (state-A s) (state-A s) (state-C s)))  ; B = A
   )

Thanks for your help. I am excited to be getting started with Rosette.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions