functions: Add list->sbf.

This commit is contained in:
Sergiu Ivanov 2020-07-14 23:37:38 +02:00
parent ac0f90ce23
commit bf45cf6382

View file

@ -40,7 +40,8 @@
[tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))] [tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))]
[tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))] [tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))]
[tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))] [tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))]
[sbf (-> (vectorof number?) tbf?)]) [sbf (-> (vectorof number?) tbf?)]
[list->sbf (-> (listof number?) sbf?)])
;; Predicates ;; Predicates
(contract-out (contract-out
[sbf? (-> any/c boolean?)])) [sbf? (-> any/c boolean?)]))
@ -383,3 +384,10 @@
(module+ test (module+ test
(check-equal? (sbf #(1 -1)) (tbf '#(1 -1) 0))) (check-equal? (sbf #(1 -1)) (tbf '#(1 -1) 0)))
;;; Converts a list of numbers to an SBF. The elements of the list
;;; are taken to be the weights of the SBF.
(define list->sbf (compose sbf list->vector))
(module+ test
(check-equal? (list->sbf '(1 -1)) (tbf '#(1 -1) 0)))