Commit Graph

55 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Neil Toronto
897ebeae83 Remove now-extraneous use of `flvector->list' in examples 2012-12-03 22:45:31 -07:00
Neil Toronto
d935bc0643 Split "mpfr.rkt" into "gmp.rkt" and "mpfr.rkt"
Fixed bigfloat functions that assumed (fixnum? x) means x fits in a _long
(not true on Win64)

Hopefully fixed dangling pointer errors that broke `math/bigfloat' on Win64.
It apparently had no _long/_int mismatches, but GC on Win64 will run between
creating an `_mpz' and using its value after passing it as an output argument
to MPFR functions. That doesn't seem to happen on 64-bit Linux or Mac. No
idea why, but Win64 exposed the problem so... that's good, I guess.

Rewrote `rational->bigfloat' to not use GMP's rationals

More/better bigfloat tests

Added bigfloat stress test w/ weak leak detection

Reenabled custodian shutdown callback that clears MPFR constants, because it
seems to work now

Removed `mpfr-available?' because it would only return non-#f
2012-12-03 22:45:31 -07:00
Neil Toronto
e4f5a0598f Changed how array strictness works: `array-strict' now makes the
original array strict instead of returning a new strict array.
(Finally!) The hard part is keeping the Array type covariant. The
solution is to keep the store in the closure of the array's
procedure instead of in the Array struct itself.
2012-11-29 22:17:06 -09:00
Neil Toronto
0182a6c491 Worked around new typed/rackunit limitations in "array-tests.rkt" and
"mandelbrot-test.rkt"

Fixed error in `array-count' revealed by correctly failing test

Simplified Mandelbrot test
2012-11-29 15:45:17 -07:00
Neil Toronto
5a43f2c6bc Finished array documentation!
Cleaned up other docs in preparation for alpha-testing announcement

Created `math/utils' module for stuff that doesn't go anywhere else (e.g.
FFT scaling convention, max-math-threads parameters)

Reduced the number of macros that expand to applications of `array-map'

Added `flvector-sum', defined `flsum' in terms of it

Reduced the number of pointwise `flvector', `flarray' and `fcarray' operations

Reworked `inline-build-flvector' and `inline-flvector-map' to be faster and
expand to less code in both typed and untyped Racket

Redefined conversions like `list->flvector' in terms of for loops (can do
it now that TR has working `for/flvector:', etc.)
2012-11-29 15:45:17 -07:00
Neil Toronto
cd002d5830 Documented `math/array' folds
Refactored many of the fold functions (e.g. `array-axis-andmap' is gone,
replaced by short-cutting `array-axis-and', which is sufficient because the
result of `array-map' is non-strict; added `array-count', `array-all-fold';
removed `array-all=' and friends)

Turned common folds into macros (preserves return types better, speeds up
compilation time)

Exposed a safe variant of `unsafe-array-axis-reduce'
2012-11-29 15:45:17 -07:00
Neil Toronto
9249929c45 Documented array printing, broadcasting, and transformations 2012-11-29 15:45:17 -07:00
Neil Toronto
7aadf33ead Implemented `flmultinomial' (not accurately, but it's there); changed
argument types to match `multinomial'
2012-11-29 15:45:16 -07:00
Neil Toronto
96d1400654 Renamed functions
* bernoulli -> bernoulli-number
 * farey -> farey-sequence
 * fibonacci/mod -> modular-fibonacci
 * order -> unit-group-order
 * orders -> unit-group-orders

Documented `make-fibonacci' and `make-modular-fibonacci'

Reworked text about loading external libraries in docs for `math/bigfloat'

Removed type aliases like Z, Q, Prime (I like them, but TR was printing them
in unexpected places like array return types)
2012-11-27 22:23:42 -07:00
Neil Toronto
6f1ffecc23 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)
2012-11-27 18:05:38 -07:00
Neil Toronto
2d34811ab6 Finished `math/distributions' documentation!
Fixed a few limit cases in some distributions (e.g. (uniform-dist 0 0) didn't
act like a delta distribution, (beta-dist 0 0) and (beta-dist +inf.0 +inf.0)
pretended to be defined by unique limits even though they can't be)

Made integer distributions' pdfs return +nan.0 when given non-integers

Added "private/statistics/counting.rkt", for hashing and binning samples

Added `flvector-sums' (cumulative sums with single rounding error)

Added `flinteger?', `flnan?' and `flrational?', which are faster than their
non-flonum counterparts (at least in Typed Racket; haven't tested untyped)
2012-11-27 13:44:15 -07:00
Neil Toronto
8aa623c2e8 Made plots in plot' and math' render nicely in PDFs (plots in docs are picts now)
Fixed errors in `linear-seq' when end <= start
2012-11-25 22:32:07 -08:00
Neil Toronto
3670916a11 Initial commit for `math/array' documentation; about 65% finished
Replaced pointwise operators with macros that expand to applications of `array-map'; allows more precise return types and reduces compilation time

Changed literal array syntax to use #() to delimit rows instead of [] (still suggest using square parens, though)

Minor refactoring

Fixed a macro so that the only problem with "array-tests.rkt" now is that typed/rackunit is b0rked
2012-11-24 22:13:24 -07:00
Jens Axel Søgaard
7ef4bec534 Added more margin notes 2012-11-24 14:00:34 +01:00
Jens Axel Søgaard
50c03c3622 Renamed polygonal functions to include -number the name. 2012-11-23 16:09:28 +01:00
Jens Axel Søgaard
fdfaf6bee0 Added von Mangoldt function 2012-11-23 16:04:37 +01:00
Neil Toronto
0936d8c20b Reworked distribution API, finally happy with it (as happy as I can be without being able to partially instantiate polymorphic parent struct types)
Added docs for math/distributions (about 75% finished)
Started docs for math/array (very incomplete)
2012-11-21 21:16:35 -07:00
Neil Toronto
68af24780d Manually applied Jens Axel's patch to add `random-prime' 2012-11-17 21:19:46 -09:00
Jens Axel Søgaard
e655e97a83 Better example for prime-omega 2012-11-17 21:03:47 -09:00
Jens Axel Søgaard
69f6d8ce52 Added prime-omega 2012-11-17 21:02:59 -09:00
Neil Toronto
1e52736089 Documentation style changes
Fixes after merge weirdness from pull request (specifically, removed `bfrandom' from "mpfr.rkt" again)
Removed dependence of math/flonum on math/bigfloat (better build parallelization)
Changed `divides?' to return #f when its first argument is 0
Made return type of `quadratic-character' more precise
Made argument types more permissive:
 * second argument to `solve-chinese'
 * second argument to `next-primes'
 * second argument to `prev-primes'
2012-11-17 21:02:37 -09:00
Jens Axel Søgaard
db500e8b58 Fixed next-prime and prev-prime problem 2012-11-17 21:02:37 -09:00
Jens Axel Søgaard
7e89adece4 Moved links to margin. Added more links 2012-11-17 21:02:37 -09:00
Jens Axel Søgaard
f208d0dae8 Add note about untyped- in docs for next-prime and prev-prime 2012-11-17 21:02:37 -09:00
Jens Axel Søgaard
bbef490fb0 Fixed missing import for curry 2012-11-17 21:02:36 -09:00
Jens Axel Søgaard
2178282fd6 Documentation for order, orders, primitive-root, exists-primitive-root?, primitive-roots 2012-11-17 21:02:36 -09:00
Jens Axel Søgaard
0af1cb034e Documentation of tangent-number, quadratic-solutions, quadratic-residue and quadratic-character 2012-11-17 21:02:36 -09:00
Jens Axel Søgaard
63b5f47989 Documentation on mediant 2012-11-17 21:02:36 -09:00