Type list->tbf.

This commit is contained in:
Sergiu Ivanov 2022-04-21 15:00:50 +02:00
parent cbede999df
commit d9734a5a35
2 changed files with 22 additions and 14 deletions

View file

@ -27,7 +27,8 @@
enumerate-boolean-functions/pv enumerate-boolean-functions/list enumerate-boolean-functions/pv enumerate-boolean-functions/list
random-boolean-table random-boolean-function random-boolean-function/list random-boolean-table random-boolean-function random-boolean-function/list
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean) (struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf)
(module+ test (module+ test
(require typed/rackunit)) (require typed/rackunit))
@ -394,6 +395,15 @@
(check-equal? (tabulate/pv/boolean 2 (pvλ (x y) (apply-tbf/boolean f1 (vector x y)))) (check-equal? (tabulate/pv/boolean 2 (pvλ (x y) (apply-tbf/boolean f1 (vector x y))))
'((#f #f #f) (#f #t #f) (#t #f #t) (#t #t #f))))) '((#f #f #f) (#f #t #f) (#t #f #t) (#t #t #f)))))
(: list->tbf (-> (Listof Real) tbf))
(define (list->tbf lst)
(define-values (w θ) (split-at-right lst 1))
(tbf (list->vector w) (car θ)))
(module+ test
(test-case "list->tbf"
(check-equal? (list->tbf '(1 2 3)) (tbf #(1 2) 3))))
(module untyped racket (module untyped racket
(module+ test (module+ test
(require rackunit)) (require rackunit))
@ -480,7 +490,8 @@
enumerate-boolean-functions/pv enumerate-boolean-functions/list enumerate-boolean-functions/pv enumerate-boolean-functions/list
random-boolean-table random-boolean-function random-boolean-function/list random-boolean-table random-boolean-function random-boolean-function/list
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean) (struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf)
(require (rename-in (submod 'typed untyped) (require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped] [tabulate tabulate/untyped]
@ -489,7 +500,6 @@
(provide (provide
;; Functions ;; Functions
(contract-out (contract-out
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)]
[lists->tbfs (-> (listof (listof number?)) (listof tbf?))] [lists->tbfs (-> (listof (listof number?)) (listof tbf?))]
[read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))] [read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))]
[tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))] [tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))]
@ -510,17 +520,6 @@
;;; Threshold Boolean functions ;;; Threshold Boolean functions
;;; =========================== ;;; ===========================
;;; Converts a list of numbers to a TBF. The last element of the list
;;; is taken to be the threshold, while the other elements are taken
;;; to be the weights.
(define (list->tbf lst)
(define-values (w θ) (split-at-right lst 1))
(tbf (list->vector w) (car θ)))
(module+ test
(test-case "list->tbf"
(check-equal? (list->tbf '(1 2 3)) (tbf #(1 2) 3))))
;;; Reads a list of TBF from an Org-mode table read by ;;; Reads a list of TBF from an Org-mode table read by
;;; read-org-sexp. ;;; read-org-sexp.
(define lists->tbfs ((curry map) list->tbf)) (define lists->tbfs ((curry map) list->tbf))

View file

@ -415,6 +415,15 @@ a Boolean value.
(tabulate/pv/boolean 2 (pvλ (x y) (apply-tbf/boolean simple-tbf (vector x y)))) (tabulate/pv/boolean 2 (pvλ (x y) (apply-tbf/boolean simple-tbf (vector x y))))
]} ]}
@defproc[(list->tbf [lst (Listof Real)]) tbf]{
Converts a list of numbers to a TBF. The last element of the list is taken to
be the threshold, while the other elements are taken to be the weights.
@examples[#:eval functions-evaluator
(list->tbf '(1 2 3))
]}
@section[#:tag "fuctions/untyped"]{Untyped definitions} @section[#:tag "fuctions/untyped"]{Untyped definitions}
@defmodule[(submod dds/functions typed untyped)] @defmodule[(submod dds/functions typed untyped)]