Commit Graph

91 Commits

Author SHA1 Message Date
Eric Dobson
9c71dafb63 Fix require/untyped-contract to generate better names in contracts.
Related to PR 13716.
2013-05-01 20:35:20 -07:00
Eric Dobson
67dd956b6a Don't let map introduce type variables.
Closes PR 13581.
2013-04-24 20:13:39 -07:00
Eli Barzilay
f57fbd94a6 Fix old pointers to COPYING.txt that should go to COPYING_LESSER.txt. 2013-04-09 05:41:07 -04:00
Eli Barzilay
af6be85ff5 Fix lots of indentation mistakes.
(Found by my ayatollah script...)
2013-03-14 10:55:47 -04:00
Robby Findler
8adbd7e836 Adjusted a literal scribble tabular to use 2d 2013-03-12 14:53:15 -05:00
Eli Barzilay
cec73f5652 Newlines at EOFs scan. 2013-02-23 02:09:56 -05:00
Neil Toronto
aed3b39546 Added flexp2', fllog2', `fllogb'; refactored and documented flonum testing
Note: With this refactoring, `math/utils' no longer depends on `rackunit'.

* (flexp2 x) computes (flexpt 2.0 x) but in about 1/3 the time for integer
  `x' using a lookup table. Written for exact argument reduction in `fllog2'
  after discovering that (flexpt 2.0 x) was the main performance bottleneck.

* (fllog2 x) computes (/ (fllog x) (fllog 2.0)) with near perfect accuracy.
  Invented an algorithm to compute it with at least 8 extra bits before
  final rounding; quite pleased with the result. Needed `fllog2' to ensure
  (fllogb 2.0 x) would be exact when `x' is a power of two.

* (fllogb b x) computes (/ (fllog x) (fllog b)) with better accuracy, and
  also handles limit values in a way that's consistent with the mathematical
  limits. When those are ambiguous, it's consistent with `flexpt', which
  follows IEEE 754 and C99. Otherwise returns +nan.0. See docs for details.

* `bflogb' is currently just for testing `fllogb'.

* Refactored FPU testing and documented it. So far, the only documented way
  to do it is by calling `test-floating-point', which runs a comprehensive
  deterministic+randomized suite of tests and returns a list representing
  failed tests. I'll document individual tests after I document flonum
  expansions and result/error functions like `fl+/error'.

* Added `fllog2' and `fllogb' to the flonum tests.
2013-01-28 17:44:33 -07:00
Neil Toronto
f42cc6f14a Fixed major performance issue with matrix arithmetic; please merge to 5.3.2
The fix consists of three parts:

1. Rewriting `inline-matrix*'. The material change here is that the
   expansion now contains only direct applications of `+' and `*'.
   TR's optimizer replaces them with `unsafe-fx+' and `unsafe-fx*',
   which keeps intermediate flonum values from being boxed.

2. Making the types of all functions that operate on (Matrix Number)
   values more precise. Now TR can prove that matrix operations preserve
   inexactness. For example, matrix-conjugate : (Matrix Flonum) ->
   (Matrix Flonum) and three other cases for Real, Float-Complex, and
   Number.

3. Changing the return types of some functions that used to return
   things like (Matrix (U A 0)). Now that we worry about preserving
   inexactness, we can't have `matrix-upper-triangle' always return a
   matrix that contains exact zeros. It now accepts an optional `zero'
   argument of type A.
2013-01-21 22:04:04 -07:00
Neil Toronto
ed01f70872 Bumped error bounds up a bit more 2013-01-19 19:01:24 -07:00
Neil Toronto
ddec613dc9 Fixed type error in "bernoulli.rkt"
If you merge e1b6e84089, please merge this as well (or math won't
compile)
2013-01-19 18:56:37 -07:00
Neil Toronto
564f589601 Fixed some limits and accuracy issues with flonum expansions 2013-01-19 18:09:44 -07:00
Neil Toronto
24561e25e4 Finished matrix documentation, attendant fixes; please merge to 5.3.2
* Narrowed type of `submatrix' to only sensible argument types

* `matrix-invertible?' now returns #f when given a non-square matrix
  instead of raising an error

* Allowed `matrix-diagonal' to operate on non-square matrices
2013-01-17 19:08:11 -07:00
Neil Toronto
f40ad2ca9d `math/matrix' fixes; please merge to 5.3.2.
* Fixed type of `matrix-expt'

* Made matrix functions respect `array-strictness' parameter (mostly
  wrapping functions with `parameterize' and return values with
  `array-default-strictness'; reindentation makes changes look larger)

* Added strictness tests
2013-01-16 16:40:43 -07:00
Neil Toronto
986e695bd5 Made arrays strict by default; please merge to release
* Added parameter `array-strictness', default #t

* Added `array-default-strict!' and `array-default-strict', which act
  like the functions without "default" in the name when
  `array-strictness' is #t; otherwise they do nothing

* Lots of small changes to existing array functions, mostly to ensure
  computations are done using nonstrict arrays, but return values are
  strict when `array-strictness' is #t

* Added strictness tests

* Added tests to ensure untyped code can use `math/array'

* Rewrote `array-map' exported to untyped code using untyped Racket

* Rearranged a lot of `math/array' documentation
2013-01-15 13:53:28 -07:00
Neil Toronto
441ad6eff4 MPFR custodian shutdown procedure tries to clear the constants cache
even when MPFR isn't loaded; this should close PR 13423
2013-01-09 11:21:58 -07:00
Matthew Flatt
cd73a8b02a math/matrix: fix some duplicate documentation tags 2013-01-04 08:12:47 -07:00
Jens Axel Søgaard
69d7cb2e82 More matrix documentation 2013-01-03 18:03:28 +01:00
Jens Axel Søgaard
9465bc0196 Documentation for inner product space operations 2013-01-02 22:44:39 +01:00
Neil Toronto
cfa9bd9a81 Exported `matrix-basis-cos-angle' with a contractable type 2013-01-02 13:20:42 -07:00
Jens Axel Søgaard
69406bf156 Documentation on basic matrix operations and matrix-qr. 2013-01-02 19:28:05 +01:00
Jens Axel Søgaard
715b0a7be7 Documentation for polymorphic matrix functions 2013-01-02 18:02:03 +01:00
Neil Toronto
e5eb9751f0 Initial `math/matrix' documentation, and some changes
* At least stubbed out all (or almost all) `math/matrix' exports; many
  have complete documentation (e.g. types, predicates, accessors,
  constructors, for loops, conversion, much of "Comparing Matrices")

* Moved `matrix-zero?' and fixed to use (matrix-error-norm) as its norm

* Added `matrix-basis-cos-angle' (currently a stub; should return smallest
  singular value of a certain matrix multiplication)
2013-01-01 18:19:43 -07:00
Neil Toronto
5981535686 Made Gaussian elimination faster (half the scaled additions) and more
accurate (always produces zeros in the lower half)
2013-01-01 18:19:43 -07:00
Neil Toronto
c29c4056a1 Added back partial pivoting to Gaussian elimination 2013-01-01 12:12:07 -07:00
Neil Toronto
c8e3b45e38 Added QR decomposition tests (mostly a pretty thorough randomized test);
fixed error in `matrix-cols-orthogonal?' revealed by testing
2012-12-31 15:20:25 -07:00
Neil Toronto
f5fa93572d Moar `math/matrix' review/refactoring
* Gram-Schmidt using vector type

* QR decomposition

* Operator 1-norm and maximum norm; stub for 2-norm and angle between
  subspaces (`matrix-basis-angle')

* `matrix-absolute-error' and `matrix-relative-error'; also predicates
  based on them, such as `matrix-identity?'

* Lots of shuffling code about

* Types that can have contracts, and an exhaustive test to make sure
  every value exported by `math/matrix' has a contract when used in
  untyped code

* Some more tests (still needs some)
2012-12-31 14:17:17 -07:00
Neil Toronto
7ac8e1bbce Slightly more `math/matrix'
* Moved to-do list in "matrix-operations.rkt" to the wiki

* Added more mutating vector ops

* Added "matrix-basis.rkt" (unfinished)
2012-12-27 17:30:04 -07:00
Neil Toronto
e55a31480e Precise flonum tests (error usually must be <= 0.5 ulp), and prerequisite
additions/changes

* More accurate `flulp-error'

* Added `flonum->fields', `fields->flonum', `flonum->sig+exp',
  `sig+exp->flonum' (currently undocumented)

* Correctly rounded, robust `bigfloat->fl2' and `fl2'

* Correctly rounded, robust `fl+/error', `fl-/error', `fl*/error',
  `flsqr/error', `fl//error'

* Much faster but slightly less accurate fl2 ops (shamelessly stolen from
  crlibm, which is LGPL)

* Added `fl2ulp', `fl2ulp-error', `fl2?' (which detects overlap),
  `+max-fl2-subnormal.0' (which was tricky), `fl2abs'

* Added deterministic and randomized flonum op tests (against MPFR)

* Added deterministic and randomized flonum/error op tests (against MPFR)

* Added deterministic and randomized fl2 op tests (against MPFR)

* Exposed FPU tests in `math/utils' (currently undocumented)
2012-12-27 17:30:04 -07:00
Neil Toronto
fc02d40a66 Faster LU decomposition 2012-12-27 17:30:03 -07:00
Neil Toronto
1aebd171c5 Moar matrix review/refactoring
* Consolidated Gauss and Gauss-Jordan elimination

* Fixed Gaussian elimination to return all indexes for pivotless columns,
  not just those < m

* Consolidated `matrix-row-echelon' and `matrix-reduced-row-echelon'

* Specialized row reduction for determinants; removed option to not do
  partial pivoting (it's never necessary otherwise)

* Added `matrix-invertible?'

* Removed `matrix-solve-many'; now `matrix-solve' solves for multiple
  columns

* Gave `matrix-inverse' and `matrix-solve' optional failure thunk arguments

* Made some functions that return multiple columns return arrays instead
  (i.e. `matrix-column-space')

* Added more tests
2012-12-21 22:59:59 -07:00
Neil Toronto
3bc4c1ffdc More efficient Gaussian elimination using vectors of vectors (non-strict
arrays can't help an inherently sequential algorithm)
2012-12-21 22:59:59 -07:00
Neil Toronto
8d5a069d41 Moar `math/matrix' review/refactoring
* Split "matrix-constructors.rkt" into three parts:
 * "matrix-constructors.rkt"
 * "matrix-conversion.rkt"
 * "matrix-syntax.rkt"

* Made `matrix-map' automatically inline (it's dirt simple)

* Renamed a few things, changed some type signatures

* Fixed error in `matrix-dot' caught by testing (it was broadcasting)

* Rewrote matrix comprehensions in terms of array comprehensions

* Removed `in-column' and `in-row' (can use `in-array', `matrix-col' and
  `matrix-row')

* Tons of new rackunit tests: only "matrix-2d.rkt" and
  "matrix-operations.rkt" are left (though the latter is large)
2012-12-20 17:32:16 -07:00
Neil Toronto
155ec7dc41 Reviewing and refactoring `math/matrix', part 1
* Finally added `array-axis-expand' as a dual for `array-axis-reduce'
  in order to implement `vandermonde-matrix' elegantly

* Better, shorter matrix multiply; reworked all matrix arithmetic

* Split "matrix-operations.rkt" into at least 5 parts:
 * "matrix-operations.rkt"
 * "matrix-basic.rkt"
 * "matrix-comprehension.rkt"
 * "matrix-sequences.rkt"
 * "matrix-column.rkt"

Added "matrix-constructors.rkt"

Added `matrix', `row-matrix', and `col-matrix' macros

A lot of other little changes

Currently, `in-row' and `in-column' are broken. I intend to implement
them in a way that makes them work in untyped and Typed Racket.
2012-12-20 17:32:16 -07:00
Neil Toronto
b8efd58aca Array changes in response to user feedback (and my personal neuroses)
* `list->array' now accepts an optional shape argument, and always returns
  an immutable array

* `vector->array' now accepts an optional shape argument, and always
  returns a mutable array

* Removed `make-mutable-array' because `vector->array' does its job now (I
  never liked the name anyway)

* Renamed `unsafe-mutable-array' to `unsafe-vector->array'

* Added optional type annotation to `array' macro to match `mutable-array'

* Reworded error messages in array broadcasting functions

* Made minor array doc fixes
2012-12-17 15:54:29 -07:00
Neil Toronto
60dd8d065f Fixes for errors Pierpaolo Bernardi found by reviewing the docs; also,
renamed `partition-count' to `partitions' to be consistent with
`permutations', and gave better examples in `multinomial' docs

 * (flulp-error +inf.0 +nan.0) was returning +nan.0 instead of +inf.0

 * Type of `multinomial' didn't match its docs or `flmultinomial'

 * Reworded docs for `diagonal-array'

 * Reworked/reordered quite a few things in docs for `math/bigfloat'

 * Fixed first identity given in `gamma-inc' docs

 * Fixed descrption for `+max.0', etc.
2012-12-17 11:40:37 -07:00
Jens Axel Søgaard
e5016951d0 Improved performance of prime? for small numbers 2012-12-11 19:45:39 +01:00
Matthew Flatt
5d57f6e497 ffi/unsafe/custodian: fix weak-reference problem
Also fix a related problem in the `math' MPFR binding (which was
masked by the `ffi/unsafe/custodian' bug).
2012-12-11 09:30:15 -07:00
Neil Toronto
764f6930ce Minor `math/statistics' doc fixups 2012-12-10 18:25:40 -07:00
Neil Toronto
9865182df4 Fixes, docs, and API changes for `math/statistics'
* Fixed and added tests for `quantile' and `median', documented them

* Added `sort-samples', documented it

* Removed `real-quantile' and `real-median' (too many design choices
  right now; will revisit when implementing Kernel Density Estimators)

* Documented `absdev' and `absdev/median'

* Fixed `update-statistics*': now uses O(1) space as advertised (if the
  sequences of values and weights both use O(1) space)

* Changed types of binning functions: allows using #:key in the future
  (when TR supports function type cases that differ only by keyword
  argument types better), places optional weights at the end like other
  statistics functions

* Clarified binning docs about sort stability and half-open intervals
2012-12-10 16:45:18 -07:00
Neil Toronto
04fbb02f63 Changed argument order of binning functions for consistency with other
math/statistics functions
2012-12-08 22:50:13 -07:00
Neil Toronto
af8d02146d Documented correlation and covariance 2012-12-08 22:36:11 -07:00
Neil Toronto
73395eed94 Finished and documented counting and binning functions in `math/statistics' 2012-12-08 22:11:41 -07:00
Neil Toronto
fff521212f Fixed infinite printing loop
When libmpfr wasn't available, the function created by `make-not-available'
would try to print any _mpfr arguments, which would call the custom _mpfr
printer, which would try to use a libmpfr function, which would call the
function created by `make-not-available', which would try to print...
2012-12-07 11:48:46 -07:00
Neil Toronto
769e8b47ec Added `array->list-array'
Cleaned up expected value code a little

Refactored running statistics objects (hid private fields, added
`update-statistics*')

Documented expected value functions and running statistics

Removed `bfpsi0' from bigfloat tests (DrDr's libmpfr doesn't have it)

Commented out custodian shutdown callback that frees MPFR's cache
(something's broken)
2012-12-06 22:52:22 -07:00
Neil Toronto
f607a3b061 Added stress test: libmpfr C struct accessor vs. Racket struct accessor 2012-12-06 22:52:22 -07:00
Neil Toronto
6e02d12beb Reimplemented `mpfr_set_z_2exp' in Racket as a fallback for older versions
of libmpfr (like DrDr's) that don't have it

Reimplemented really simple FFI functions (e.g. mpfr-prec, mpfr-exp) to
avoid calling overhead

Renamed `bigfloat-sign' to `bigfloat-signbit'

Renamed `bigfloat-sig+exp' to `bigfloat->sig+exp' (for symmetry with
`sig+exp->bigfloat')
2012-12-06 13:43:23 -07:00
Neil Toronto
2ac2262f00 Removed fallback to 'mpfr_set_z_exp - didn't work, probably never existed 2012-12-05 22:31:07 -07:00
Neil Toronto
fcc08fa89e Fixed bigfloats on Win64. Win64's long type is 32 bits and GMP's default is to
use longs for the "limbs" of bigints. However, when GMP's configure script
detects that mingw64 is compiling, it defines LONG_LONG_LIMB, which makes the
type of limbs long long, or 64 bits. This is fine; a 64-bit machine should use
64-bit ints for the digits of its bigints. It would have been nice to know
this special case earlier, though I can see why it's not advertised: most
users don't need to know, and it seems like it's obviously the right choice to
make when dealing with Win64's annoying ABI.

Made "mpfr.rkt" search for 'mpfr_set_z_exp if 'mpfr_set_z_2exp isn't found.
Hopefully this allows the bigfloat tests to finish on DrDr. If not, DrDr
will need a libmpfr upgrade.

Made some minor doc fixups
2012-12-05 20:29:59 -07:00
Neil Toronto
055512b4e8 Renamed make-flexp/base' to make-flexpt'
Renamed `dist' struct type to `distribution' ("dist" is too common)
2012-12-03 22:45:31 -07:00
Neil Toronto
6ca52be0ae Stopped exporting `slice-indexes-array' 2012-12-03 22:45:31 -07:00