From 6f1ffecc2374f2874c1942fe0558420b74cbe223 Mon Sep 17 00:00:00 2001 From: Neil Toronto Date: Tue, 27 Nov 2012 18:04:45 -0700 Subject: [PATCH] Stubbed out missing `math/array' and `math/statistics' doc entries to clean up build Moved `float-complex?' and `number->float-complex' to `math/base', documented them Documented `flexpt1p' Removed `samples->immutable-hash' (not covariant anyway; not going to use hashes) --- collects/math/base.rkt | 18 ++++++-- collects/math/private/base/base-functions.rkt | 37 +++++++++++++++- .../math/private/flonum/flonum-functions.rkt | 18 -------- collects/math/private/statistics/counting.rkt | 17 +++----- collects/math/scribblings/math-array.scrbl | 34 ++++++++++++--- collects/math/scribblings/math-base.scrbl | 14 +++++- collects/math/scribblings/math-flonum.scrbl | 4 ++ .../math/scribblings/math-statistics.scrbl | 43 +++++++++++++++++++ collects/math/scribblings/math.scrbl | 1 + collects/typed/untyped-utils.rkt | 11 +++-- 10 files changed, 153 insertions(+), 44 deletions(-) create mode 100644 collects/math/scribblings/math-statistics.scrbl diff --git a/collects/math/base.rkt b/collects/math/base.rkt index c2c7e7114c..e85800d613 100644 --- a/collects/math/base.rkt +++ b/collects/math/base.rkt @@ -1,9 +1,12 @@ #lang racket/base -(require typed/untyped-utils +(require (for-syntax racket/base) + typed/untyped-utils racket/math - (except-in "private/base/base-functions.rkt" - asinh acosh atanh) + (rename-in + (except-in "private/base/base-functions.rkt" + asinh acosh atanh) + [number->float-complex typed:number->float-complex]) "private/base/base-random.rkt" "private/base/base-constants.rkt") @@ -13,9 +16,16 @@ [acosh (Number -> Number)] [atanh (Number -> Number)]) +(define-syntax (number->float-complex stx) + (syntax-case stx () + [(_ z-expr) (syntax/loc stx (inline-number->float-complex z-expr))] + [(_ . args) (syntax/loc stx (typed:number->float-complex . args))] + [_ (syntax/loc stx typed:number->float-complex)])) + (provide (all-from-out racket/math "private/base/base-functions.rkt" "private/base/base-random.rkt" "private/base/base-constants.rkt") - asinh acosh atanh) + asinh acosh atanh + number->float-complex) diff --git a/collects/math/private/base/base-functions.rkt b/collects/math/private/base/base-functions.rkt index f958096ff1..9535dd4b75 100644 --- a/collects/math/private/base/base-functions.rkt +++ b/collects/math/private/base/base-functions.rkt @@ -9,7 +9,10 @@ absolute-error relative-error sum - asinh acosh atanh) + asinh acosh atanh + float-complex? + inline-number->float-complex + number->float-complex) ;; Returns #t if x is an integer power of 2 (: power-of-two? (Real -> Boolean)) @@ -100,3 +103,35 @@ [(real? x) (flatanh (fl x))] [(float-complex? x) (* 0.5 (- (log (+ 1.0 x)) (log (- 1.0 x))))] [else (* 1/2 (- (log (+ 1 x)) (log (- 1 x))))])) + +;; =================================================================================================== +;; Float-Complex functions + +(define-predicate float-complex? Float-Complex) + +(module syntax-defs racket/base + (require (for-syntax racket/base + typed/untyped-utils) + (only-in typed/racket/base : Number let:) + racket/flonum) + + (provide inline-number->float-complex) + + (define-syntax (inline-number->float-complex stx) + (syntax-case stx () + [(_ z-expr) + (syntax/loc stx + (let: ([z : Number z-expr]) + (if (number? z) + (make-rectangular (real->double-flonum (real-part z)) + (real->double-flonum (imag-part z))) + (raise-argument-error 'number->float-complex "number?" z))))])) + + ) ; module + +(require 'syntax-defs) + +(: number->float-complex (Number -> Float-Complex)) +(define (number->float-complex z) + (make-rectangular (fl (real-part z)) + (fl (imag-part z)))) diff --git a/collects/math/private/flonum/flonum-functions.rkt b/collects/math/private/flonum/flonum-functions.rkt index 0fa00e37c6..c8b4257ecb 100644 --- a/collects/math/private/flonum/flonum-functions.rkt +++ b/collects/math/private/flonum/flonum-functions.rkt @@ -12,7 +12,6 @@ flsubnormal? flrational? flnan? flinteger? flnext* flprev* flulp-error - float-complex? (rename-out [inline-number->float-complex number->float-complex]) fleven? flodd? flsgn flhypot fllog/base flprobability? flsinpix flcospix fltanpix flcscpix flsecpix flcotpix) @@ -96,23 +95,6 @@ (/ (- (inexact->exact x) (inexact->exact r)) (inexact->exact (flulp x)))))])) -;; =================================================================================================== -;; Types, conversion - -(define-predicate float-complex? Float-Complex) - -(define-syntax (inline-number->float-complex stx) - (syntax-case stx () - [(_ z-expr) (syntax/loc stx - (let: ([z : Number z-expr]) - (make-rectangular (real->double-flonum (real-part z)) - (real->double-flonum (imag-part z)))))] - [(_ e ...) (syntax/loc stx (number->float-complex e ...))] - [_ (syntax/loc stx number->float-complex)])) - -(: number->float-complex (Number -> Float-Complex)) -(define (number->float-complex z) (inline-number->float-complex z)) - ;; =================================================================================================== ;; More floating-point functions diff --git a/collects/math/private/statistics/counting.rkt b/collects/math/private/statistics/counting.rkt index dc77d31d1d..9c9fb99caf 100644 --- a/collects/math/private/statistics/counting.rkt +++ b/collects/math/private/statistics/counting.rkt @@ -1,10 +1,11 @@ #lang typed/racket/base -(require racket/unsafe/ops - racket/list - racket/sequence) +(require racket/list + racket/sequence + "../../base.rkt" + "../unsafe.rkt") -(provide samples->immutable-hash samples->hash +(provide samples->hash count-samples (struct-out sample-bin) Real-Bin @@ -14,15 +15,9 @@ (define-type Real-Bin (sample-bin Real)) -(: samples->immutable-hash (All (A) ((Sequenceof A) -> (HashTable A Positive-Integer)))) -(define (samples->immutable-hash xs) - (define: h : (HashTable A Positive-Integer) (make-immutable-hash null)) - (for/fold: ([h : (HashTable A Positive-Integer) h]) ([x : A xs]) - (hash-set h x (unsafe-fx+ 1 (hash-ref h x (λ () 0)))))) - (: samples->hash (All (A) ((Sequenceof A) -> (HashTable A Positive-Integer)))) (define (samples->hash xs) - (define: h : (HashTable A Positive-Integer) (make-hash null)) + (define: h : (HashTable A Positive-Integer) (make-hash)) (for: ([x : A xs]) (hash-set! h x (unsafe-fx+ 1 (hash-ref h x (λ () 0))))) h) diff --git a/collects/math/scribblings/math-array.scrbl b/collects/math/scribblings/math-array.scrbl index 459696bff5..595f053c4c 100644 --- a/collects/math/scribblings/math-array.scrbl +++ b/collects/math/scribblings/math-array.scrbl @@ -929,7 +929,7 @@ Equivalent to @racket[(array-map f arr0 arr1 arrs ...)], where @racket[f] is res The short-cutting behavior of @racket[array-and], @racket[array-or] and @racket[array-if] can keep array arguments' elements from being referred to (and thus computed). However, they cannot be used to distinguish base and inductive cases in a recursive function, because -the array arguments are always evaluated. For example, this function never returns: +the array arguments are eagerly evaluated. For example, this function never returns: @racketblock[(: array-factorial ((Array Integer) -> (Array Integer))) (define (array-factorial arr) (array-if (array<= arr (array 0)) @@ -939,8 +939,10 @@ the array arguments are always evaluated. For example, this function never retur @subsection{Broadcasting} +@defparam[array-broadcasting broadcasting? (U Boolean 'permissive)]{ +} + @;{ -array-broadcasting array-shape-broadcast array-broadcast } @@ -1221,21 +1223,35 @@ array-axis-inverse-fft @section{Transformations} +@defidform[array-axis-insert]{ +} + +@defidform[array-axis-ref]{ +} + +@defidform[array-flatten]{ +} + @;{ array-transform array-axis-permute array-axis-swap -array-axis-insert -array-axis-ref array-append* array-reshape -array-flatten } @section{Subtypes} @subsection{Flonum Arrays} +@defidform[FlArray]{ +} + +@defproc[(array->flarray [arr (Array Real)]) FlArray]{ +Returns an flarray that has approximately the same elements as @racket[arr]. +The elements may lose precision during the conversion. +} + @;{ FlArray flarray-scale @@ -1275,6 +1291,14 @@ flarray>= @subsection{Float-Complex Arrays} +@defidform[FCArray]{ +} + +@defproc[(array->fcarray [arr (Array Number)]) FCArray]{ +Returns an fcarray that has approximately the same elements as @racket[arr]. +The elements may lose precision during the conversion. +} + @;{ FCArray fcarray-fft diff --git a/collects/math/scribblings/math-base.scrbl b/collects/math/scribblings/math-base.scrbl index 5235e2a263..83bc27473f 100644 --- a/collects/math/scribblings/math-base.scrbl +++ b/collects/math/scribblings/math-base.scrbl @@ -4,8 +4,9 @@ racket/sandbox (for-label racket/base math - (only-in typed/racket/base Real Boolean Integer Natural Number Listof - Positive-Flonum)) + (only-in typed/racket/base + Real Boolean Integer Natural Number Listof + Positive-Flonum Float-Complex Any)) "utils.rkt") @(define untyped-eval (make-untyped-math-eval)) @@ -50,6 +51,15 @@ An approximation of @italic{G}, or @hyperlink["http://en.wikipedia.org/wiki/Cata @section{Functions} +@defproc[(float-complex? [v Any]) Boolean]{ +Returns @racket[#t] when @racket[v] is of type @racket[Float-Complex]. Analogous to @racket[flonum?]. +} + +@defproc[(number->float-complex [x Number]) Float-Complex]{ +Returns a new complex number with a flonum real part and a flonum imaginary part. +Analogous to @racket[real->double-flonum]. +} + @defproc[(power-of-two? [x Real]) Boolean]{ Returns @racket[#t] when @racket[x] is an integer power of 2. @examples[#:eval untyped-eval diff --git a/collects/math/scribblings/math-flonum.scrbl b/collects/math/scribblings/math-flonum.scrbl index be4e451912..4bb073bd1f 100644 --- a/collects/math/scribblings/math-flonum.scrbl +++ b/collects/math/scribblings/math-flonum.scrbl @@ -153,6 +153,10 @@ of @racket[fllog1p], which avoids the error-prone subtraction: But see @racket[flexpt1p], which is more accurate still. } +@defproc[(flexpt1p [x Flonum] [y Flonum]) Flonum]{ +Like @racket[(flexpt (+ 1.0 x) y)], but accurate for any @racket[x] and @racket[y]. +} + @defproc[(make-flexp/base [x Real]) (Flonum -> Flonum)]{ Equivalent to @racket[(λ (y) (flexpt x y))] when @racket[x] is a flonum, but much more accurate for large @racket[y] when @racket[x] cannot be exactly represented diff --git a/collects/math/scribblings/math-statistics.scrbl b/collects/math/scribblings/math-statistics.scrbl new file mode 100644 index 0000000000..7390b634cd --- /dev/null +++ b/collects/math/scribblings/math-statistics.scrbl @@ -0,0 +1,43 @@ +#lang scribble/manual + +@(require scribble/eval + racket/sandbox + (for-label racket/base racket/promise racket/list + math plot + (only-in typed/racket/base + Flonum Real Boolean Any Listof Integer case-> -> U + Sequenceof Positive-Flonum Nonnegative-Flonum)) + "utils.rkt") + +@(define untyped-eval (make-untyped-math-eval)) +@interaction-eval[#:eval untyped-eval (require racket/list)] + +@title[#:tag "stats"]{Statistical Functions} +@(author-neil) + +@defmodule[math/statistics] + +xxx intro + +something about accepting weighted samples whenever it makes sense +(time it doesn't make sense: autocorrelation) + +@local-table-of-contents[] + +@section{Counting} + +@defthing[samples->hash Any]{ +} + +@defthing[count-samples Any]{ +} + +@section{Expected Values} + +@section{Running Expected Values} + +@section{Correlation} + +@section{Order Statistics} + +@(close-eval untyped-eval) diff --git a/collects/math/scribblings/math.scrbl b/collects/math/scribblings/math.scrbl index e2a7f01eac..c6c6f9b06d 100644 --- a/collects/math/scribblings/math.scrbl +++ b/collects/math/scribblings/math.scrbl @@ -40,4 +40,5 @@ be used in untyped Racket. Exceptions and performance warnings are in @bold{bold @include-section["math-number-theory.scrbl"] @include-section["math-bigfloat.scrbl"] @include-section["math-array.scrbl"] +@include-section["math-statistics.scrbl"] @include-section["math-distributions.scrbl"] diff --git a/collects/typed/untyped-utils.rkt b/collects/typed/untyped-utils.rkt index b03f598653..c663588f95 100644 --- a/collects/typed/untyped-utils.rkt +++ b/collects/typed/untyped-utils.rkt @@ -3,10 +3,15 @@ (require (for-syntax racket/base syntax/parse racket/syntax - typed-racket/utils/tc-utils)) + typed-racket/utils/tc-utils) + typed-racket/utils/tc-utils) -(provide require/untyped-contract - define-typed/untyped-identifier) +(provide syntax-local-typed-context? + define-typed/untyped-identifier + require/untyped-contract) + +(define (syntax-local-typed-context?) + (unbox typed-context?)) (define-for-syntax (rename-head stx id) (syntax-case stx ()