A pair combines two values, and a list is either the constant null or a pair whose second element is a list. Pairs and lists are transparent immutable values, and they may be concrete or symbolic. Two pairs or two lists are eq? (resp. equal? ) if their corresponding elements are eq? (resp. equal? ).
As values of unsolvable types, symbolic pairs and lists cannot be created via define-symbolic[*]. Instead, they are created by applying pair- or list-producing procedures to symbolic inputs, or by controlling the application of such procedures with symbolic values. This pattern for creating non-primitive symbolic values generalizes to all unsolvable datatypes.
'()
'(-1 0)
'(4 . #f)
'(1 . 2)
Additional Pair Operations
caar , cadr , cdar , cddr , caaar , caadr , cadar , caddr , cdaar , cdadr , cddar , cdddr , caaaar , caaadr , caadar , caaddr , cadaar , cadadr , caddar , cadddr , cdaaar , cdaadr , cdadar , cdaddr , cddaar , cddadr , cdddar , cddddr
Additional List Operations
cons? , empty? , first , rest , second , third , fourth , fifth , sixth , seventh , eighth , ninth , tenth , last , last-pair , take , drop , split-at , take-right , drop-right , split-at-right , add-between , append* , flatten , remove-duplicates , filter-map , count , partition , append-map , filter-not , shuffle , argmin , argmax , list-set
Rosette provides the following procedures for operating on lists using bitvector indices and lengths. These procedures produce symbolic values that avoid casting their bitvector arguments to integers, leading to more efficiently solvable queries.
> xs(union [b (1 2)] [(! b) (3 4 5 6)])
(integer->bitvector (ite b 2 4) (bitvector 4))
(ite b (bv #x2 4) (bv #x4 4))
procedure
( list-ref-bv lstpos)→any/c
lst:list?pos:bv?
;Uses a cast and generates a redundant assertion on the range of p:(ite*
(⊢ (= 0 (bitvector->natural p)) 1)
(⊢ (= 1 (bitvector->natural p)) 2)
(⊢ (= 2 (bitvector->natural p)) 3)
(⊢ (= 3 (bitvector->natural p)) 4))
(vc #t (&& (<= 0 (bitvector->natural p)) (< (bitvector->natural p) 4)))
;No cast and no redundant range assertion:(ite* (⊢ (bveq (bv #b0 1) p) 1) (⊢ (bveq (bv #b1 1) p) 2))
(vc #t #t)
;But the range assertion is generated when needed:(ite*
(⊢ (bveq (bv #x0 4) q) 1)
(⊢ (bveq (bv #x1 4) q) 2)
(⊢ (bveq (bv #x2 4) q) 3)
(⊢ (bveq (bv #x3 4) q) 4))
(vc #t (bvult q (bv #x4 4)))
procedure
( list-set-bv lstposval)→list?
lst:list?pos:bv?val:any/c
;Uses a cast and generates a redundant assertion on the range of p:(list
(ite (= 0 (bitvector->natural p)) 5 1)
(ite (= 1 (bitvector->natural p)) 5 2)
(ite (= 2 (bitvector->natural p)) 5 3)
(ite (= 3 (bitvector->natural p)) 5 4))
(vc #t (&& (<= 0 (bitvector->natural p)) (< (bitvector->natural p) 4)))
;No cast and no redundant range assertion:(list (ite (bveq (bv #b0 1) p) 5 1) (ite (bveq (bv #b1 1) p) 5 2) 3 4)
(vc #t #t)
;But the range assertion is generated when needed:(list
(ite (bveq (bv #x0 4) q) 5 1)
(ite (bveq (bv #x1 4) q) 5 2)
(ite (bveq (bv #x2 4) q) 5 3)
(ite (bveq (bv #x3 4) q) 5 4))
(vc #t (bvult q (bv #x4 4)))
;Uses a cast and generates a redundant assertion on the range of p:(union
[(= 0 (bitvector->natural p)) ()]
[(= 1 (bitvector->natural p)) (1)]
[(= 2 (bitvector->natural p)) (1 2)]
[(= 3 (bitvector->natural p)) (1 2 3)])
(vc #t (&& (<= 0 (bitvector->natural p)) (< (bitvector->natural p) 4)))
;No cast and no redundant range assertion:(union [(bveq (bv #b0 1) p) ()] [(bveq (bv #b1 1) p) (1)])
(vc #t #t)
;But the range assertion is generated when needed:(union
[(bveq (bv #x0 4) q) ()]
[(bveq (bv #x1 4) q) (1)]
[(bveq (bv #x2 4) q) (1 2)]
[(bveq (bv #x3 4) q) (1 2 3)])
(vc #t (bvule q (bv #x3 4)))
;Uses a cast and generates a redundant assertion on the range of p:(union [(= 0 (bitvector->natural p)) ()] [(= 1 (bitvector->natural p)) (1)])
(union [(= 0 (bitvector->natural p)) (1 . 2)] [(= 1 (bitvector->natural p)) 2])
(vc #t (&& (<= 0 (bitvector->natural p)) (< (bitvector->natural p) 2)))
;No cast and no redundant range assertion:(union [(bveq (bv #b0 1) p) ()] [(bveq (bv #b1 1) p) (1)])
(union [(bveq (bv #b0 1) p) (1 . 2)] [(bveq (bv #b1 1) p) 2])
(vc #t #t)
;But the range assertion is generated when needed:(union [(bveq (bv #x0 4) q) ()] [(bveq (bv #x1 4) q) (1)])
(union [(bveq (bv #x0 4) q) (1 . 2)] [(bveq (bv #x1 4) q) 2])
(vc #t (bvule q (bv #x1 4)))