## Documentation

### Miscellaneous Math Functions

#### Usage

(import math-utils)

#### log/base

log-with-base Bprocedure
log/base Bprocedure

Returns a function for the base B logarithm.

#### coprime?

(coprime? M [N0 ...]) -> booleanprocedure

Are the integers M N0 ... coprime?

#### pairwise-coprime?

(pairwise-coprime? M [N0 ...]) -> booleanprocedure

Are the pairs of integers in M N0 ... coprime?

#### fxcoprime?

fxcoprime? M Nprocedure

Are the fixnums M N coprime?

(import (only (srfi 1) filter iota))
(import (only (math-utils) fxcoprime?))

(define (coprimes n)
(filter (cut fxcoprime? n <>) (iota (- n 1) 1)) )
(import (only (streams derived) stream-range stream-filter))
(import (only (math-utils) fxcoprime?))

(define (coprime-numbers-stream n)
(stream-filter (cut fxcoprime? n <>) (stream-range 1 n)) )

#### simple-interest

simple-interest RATE TIME #!optional PRINprocedure

The accumulation function, the principle is assumed 1. Returns the simple interest for the RATE over TIME.

RATE ; number ; interest rate
TIME ; number ; time period to cover
PRIN ; number ; principle, default 1

#### compound-interest

compound-interest RATE FREQ TIME #!optional PRINprocedure

The accumulation function, the principle is assumed 1. Returns the compound interest for the RATE, applied with FREQ, over TIME.

RATE ; number ; interest rate
FREQ ; number ; compounding frequency
TIME ; number ; time period to cover
PRIN ; number ; principle, default 1
(compound-interest 0.043 4 6 1500)
;=> 1938.84 ;rounded to 2 places

#### fibonacci

fibonacci Nprocedure

Returns fibonacci of N.

#### fibonacci*

fibonacci* Nprocedure

Returns an approximate fibonacci of N.

#### binomial

binomial N1 N2procedure

Returns the Binomial in N1 to N2.

N1 ; integer
N2 ; integer

#### cross-ratio

cross-ratio N1 N2 N3 N4procedure

Returns the Cross-ratio of N1, N2 and N3, N4.

N1 ; number
N2 ; number
N3 ; number
N4 ; number

#### square

square Nprocedure

cube Nprocedure

#### average

average N1 N2 ...procedure
average NUMSprocedure
N1 ; number
N1 ; number
NUMS ; (list-of number)

#### least-squares

least-squares PNTSprocedure

Returns b & e such that y ~= b * x + e.

PNTS ; (list-of (pair number number))
list of x,y pairs

#### trapezoid

trapezoid F N1 N2procedure

Returns a function to calculate the area under F between N1 & N2 using the Trapezoid Rule. The function takes the number of estimations as an argument, larger for a "better" result.

F ; (number -> number)
N1 ; number
N2 ; number

#### factorial+

factorial Nprocedure
factorial- N1 FALLprocedure
factorial+ N1 RISEprocedure
N ; integer
FALL
number : falling factorial
RISE
number : rising factorial

#### harmonic

harmonic Nprocedure

Result of Harmonic series expansion to N terms.

N ; integer

#### big-pi

(big-pi F N1 N2) -> numbersyntax

Product of F in N1 to N2.

F
(number -> number) ;
N1
number ;
N2
number ;

#### big-sigma

(big-sigma F N1 N2) -> numbersyntax

Sum of F in N1 to N2.

F
(number -> number) ;
N1
number ;
N2
number ;

### Miscellaneous Vector Math Functions

#### Usage

(import (math-utils vector))

#### absolute-magnitude

absolute-magnitude NUMVECprocedure
NUMVEC ; (vector-of number)
.

#### cosine-similarity

cosine-similarity NUMVEC1 NUMVEC2procedure
NUMVEC1 ; (vector-of number)
.
NUMVEC2 ; (vector-of number)
.

Must be same vector-length.

#### vector-compare

vector-compare NUMVEC...procedure

Result is negative, zero, or positive. Comparison by length when unequal & element-wise when equal.

NUMVEC ; (vector-of number)
.

#### dot-product

dot-product NUMVEC1 NUMVEC2procedure
NUMVEC1 ; (vector-of number)
.
NUMVEC2 ; (vector-of number)
.

Must be same vector-length.

#### cross-product

cross-product NUMVEC1 NUMVEC2procedure
NUMVEC1 ; (vector-of number)
.
NUMVEC2 ; (vector-of number)
.

Must be same vector-length.

Only defined for a vector-length of (0 1 2), returning a number, and (3 4 8), returning a (vector-of number). All others generate an error.

#### vector-gcd

vector-mul NUMVEC...procedure
vector-sum NUMVEC...procedure
vector-div NUMVEC...procedure
vector-dif NUMVEC...procedure
vector-min NUMVEC...procedure
vector-max NUMVEC...procedure
vector-lcm NUMVEC...procedure
vector-gcd NUMVEC...procedure
NUMVEC ; (vector-of number)
.

Must be same vector-length.

#### vector-apply

vector-apply FUNC VEC1 VEC2 #!optional VEC...procedure
FUNC ; (* * !#rest * -> *)
.
VEC# ; vector
.

Must be same vector-length.

Kon Lovett

## Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/math-utils

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

## Version history

1.0.6
Remove mathh dependency since include is unreliable.
1.0.5
Use gcd based algorithm.
1.0.4