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)
This commit is contained in:
parent
3e81924f84
commit
6f1ffecc23
|
@ -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)
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
43
collects/math/scribblings/math-statistics.scrbl
Normal file
43
collects/math/scribblings/math-statistics.scrbl
Normal file
|
@ -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)
|
|
@ -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"]
|
||||
|
|
|
@ -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 ()
|
||||
|
|
Loading…
Reference in New Issue
Block a user