| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.1 Bit-Twiddling 'logical 4.2 Modular Arithmetic 'modular 4.3 Prime Numbers 'factor 4.4 Random Numbers 'random 4.5 Fast Fourier Transform 'fft 4.6 Cyclic Checksum 'make-crc 4.7 Plotting 'charplot 4.8 Solid Modeling VRML97 4.9 Color 4.10 Root Finding 'root 4.11 Minimizing 'minimize 4.12 Commutative Rings 'commutative-ring 4.15 Matrix Algebra 'determinant
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The bit-twiddling functions are made available through the use of the
logical package. logical is loaded by inserting
(require 'logical) before the code that uses these
functions. These functions behave as though operating on integers
in two's-complement representation.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Example:
(number->string (logand #b1100 #b1010) 2) => "1000" |
Example:
(number->string (logior #b1100 #b1010) 2) => "1110" |
Example:
(number->string (logxor #b1100 #b1010) 2) => "110" |
Example:
(number->string (lognot #b10000000) 2) => "-10000001" (number->string (lognot #b0) 2) => "-1" |
(logtest j k) == (not (zero? (logand j k))) (logtest #b0100 #b1011) => #f (logtest #b0100 #b0111) => #t |
Example:
(logcount #b10101010) => 4 (logcount 0) => 0 (logcount -2) => 1 |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(logbit? index j) == (logtest (integer-expt 2 index) j) (logbit? 0 #b1101) => #t (logbit? 1 #b1101) => #f (logbit? 2 #b1101) => #t (logbit? 3 #b1101) => #t (logbit? 4 #b1101) => #f |
#t and 0 if bit is #f.
Example:
(number->string (copy-bit 0 0 #t) 2) => "1" (number->string (copy-bit 2 0 #t) 2) => "100" (number->string (copy-bit 2 #b1111 #f) 2) => "1011" |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function was called bit-extract in previous versions of SLIB.
Example:
(number->string (bit-field #b1101101010 0 4) 2) => "1010" (number->string (bit-field #b1101101010 4 9) 2) => "10110" |
Example:
(number->string (copy-bit-field #b1101101010 0 4 0) 2)
=> "1101100000"
(number->string (copy-bit-field #b1101101010 0 4 -1) 2)
=> "1101101111"
|
(inexact->exact (floor (* int (expt 2 count)))).
Example:
(number->string (ash #b1 3) 2) => "1000" (number->string (ash #b1010 -1) 2) => "101" |
Example:
(integer-length #b10101010) => 8 (integer-length 0) => 0 (integer-length #b1111) => 4 |
Example:
(integer-expt 2 5) => 32 (integer-expt -3 3) => -27 |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(number->string (bit-reverse 8 #xa7) 16) => "e5" |
integer->list returns a list of len booleans corresponding
to each bit of the given integer. #t is coded for each 1; #f for 0.
The len argument defaults to (integer-length k).
list->integer returns an integer formed from the booleans in the
list list, which must be a list of booleans. A 1 bit is coded for
each #t; a 0 bit for #f.
integer->list and list->integer are inverses so far as
equal? is concerned.
For any non-negative integers k and count:
(eqv? k (bitwise:laminate (bitwise:delaminate count k))) |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A Gray code is an ordering of non-negative integers in which exactly one bit differs between each pair of successive elements. There are multiple Gray codings. An n-bit Gray code corresponds to a Hamiltonian cycle on an n-dimensional hypercube.
Gray codes find use communicating incrementally changing values between asynchronous agents. De-laminated Gray codes comprise the coordinates of Hilbert's space-filling curves.
integer-length as
k.
integer-length as k.
For any non-negative integer k,
(eqv? k (gray-code->integer (integer->gray-code k))) |
For any non-negative integers k1 and k2, the Gray code
predicate of (integer->gray-code k1) and
(integer->gray-code k2) will return the same value as the
corresponding predicate of k1 and k2.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These procedures implement the Common-Lisp functions of the same names.
The real number x2 must be non-zero.
mod returns (- x1 (* x2 (floor (/ x1 x2)))).
rem returns (- x1 (* x2 (truncate (/ x1 x2)))).
If x1 and x2 are integers, then mod behaves like
modulo and rem behaves like remainder.
(mod -90 360) => 270 (rem -90 180) => -90 (mod 540 360) => 180 (rem 540 360) => 180 (mod (* 5/2 pi) (* 2 pi)) => 1.5707963267948965 (rem (* -5/2 pi) (* 2 pi)) => -1.5707963267948965 |
(d x y) such that d = gcd(n1,
n2) = n1 * x + n2 * y.
(quotient (+ -1 n) -2) for positive odd integer n.
modular: procedures.
(modulo n (modulus->integer
modulus)) in the representation specified by modulus.
The rest of these functions assume normalized arguments; That is, the arguments are constrained by the following table:
For all of these functions, if the first argument (modulus) is:
positive?
zero?
negative?
(+ 1 (* -2 modulus)), but with symmetric
representation; i.e. (<= (- modulus) n
modulus).
If all the arguments are fixnums the computation will use only fixnums.
#t if there exists an integer n such that k * n
== 1 mod modulus, and #f otherwise.
The Scheme code for modular:* with negative modulus is not
completed for fixnum-only implementations.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
prime:prngs is the random-state (see section 4.4 Random Numbers) used by these
procedures. If you call these procedures from more than one thread
(or from interrupt), random may complain about reentrant
calls.
Returns the value (+1, -1, or 0) of the Jacobi-Symbol of exact non-negative integer p and exact positive odd integer q.
prime:trials the maxinum number of iterations of Solovay-Strassen that will be done to test a number for primality.
Returns #f if n is composite; #t if n is prime.
There is a slight chance (expt 2 (- prime:trials)) that a
composite will return #t.
Returns a list of the first count prime numbers less than start. If there are fewer than count prime numbers less than start, then the returned list will have fewer than start elements.
Returns a list of the first count prime numbers greater than start.
Returns a list of the prime factors of k. The order of the
factors is unspecified. In order to obtain a sorted list do
(sort! (factor k) <).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A pseudo-random number generator is only as good as the tests it passes. George Marsaglia of Florida State University developed a battery of tests named DIEHARD (http://stat.fsu.edu/~geo/diehard.html). `diehard.c' has a bug which the patch http://swissnet.ai.mit.edu/ftpdir/users/jaffer/diehard.c.pat corrects.
SLIB's new PRNG generates 8 bits at a time. With the degenerate seed `0', the numbers generated pass DIEHARD; but when bits are combined from sequential bytes, tests fail. With the seed `http://swissnet.ai.mit.edu/~jaffer/SLIB.html', all of those tests pass.
random are uniformly distributed from 0 to n.
The optional argument state must be of the type returned by
(seed->random-state) or (make-random-state). It defaults
to the value of the variable *random-state*. This object is used
to maintain the state of the pseudo-random-number generator and is
altered as a side effect of calls to random.
random uses by default. The nature
of this data structure is implementation-dependent. It may be printed
out and successfully read back in, but may or may not function correctly
as a random-number state object in another implementation.
Returns a new copy of argument state.
*random-state*.
Returns a new object of type suitable for use as the value of the
variable *random-state* or as a second argument to random.
The number or string seed is used to initialize the state. If
seed->random-state is called twice with arguments which are
equal?, then the returned data structures will be equal?.
Calling seed->random-state with unequal arguments will nearly
always return unequal states.
*random-state* or as a second argument to random.
If the optional argument obj is given, it should be a printable
Scheme object; the first 50 characters of its printed representation
will be used as the seed. Otherwise the value of *random-state*
is used as the seed.
If inexact numbers are supported by the Scheme implementation, `randinex.scm' will be loaded as well. `randinex.scm' contains procedures for generating inexact distributions.
(* u (random:exp)).
(+ m (* d (random:normal))).
(vector-length vect), the coordinates are
uniformly distributed over the surface of the unit n-shere.
(vector-length vect), the
coordinates are uniformly distributed within the unit n-shere.
The sum of the squares of the numbers is returned.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(expt 2 n) numbers. fft
returns an array of complex numbers comprising the Discrete Fourier
Transform of array.
fft-1 returns an array of complex numbers comprising the inverse
Discrete Fourier Transform of array.
(fft-1 (fft array)) will return an array of values close to
array.
(fft '#(1 0+i -1 0-i 1 0+i -1 0-i)) => #(0.0 0.0 0.0+628.0783185208527e-18i 0.0 0.0 0.0 8.0-628.0783185208527e-18i 0.0) (fft-1 '#(0 0 0 0 0 0 8 0)) => #(1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i 1.0 -61.23031769111886e-18+1.0i -1.0 61.23031769111886e-18-1.0i) |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The integer degree, if given, specifies the degree of the polynomial being computed -- which is also the number of bits computed in the checksums. The default value is 32.
The integer generator specifies the polynomial being computed. The power of 2 generating each 1 bit is the exponent of a term of the polynomial. The value of generator must be larger than 127.
The integer generator specifies the polynomial being computed. The power of 2 generating each 1 bit is the exponent of a term of the polynomial. The bit at position degree is implicit and should not be part of generator. This allows systems with numbers limited to 32 bits to calculate 32 bit checksums. The default value of generator when degree is 32 (its default) is:
(make-port-crc 32 #b00000100110000010001110110110111) |
Creates a procedure to calculate the P1003.2/D11.2 (POSIX.2) 32-bit checksum from the polynomial:
32 26 23 22 16 12 11
( x + x + x + x + x + x + x +
10 8 7 5 4 2 1
x + x + x + x + x + x + x + 1 ) mod 2
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The default value for charplot:dimensions is the
output-port-height and output-port-width of
current-output-port.
Example:
(plot sin 0 (* 2 pi))
-|
____________________________________________
1.25|-: |
| : |
1|-: **** |
| : ** ** |
0.75|-: * * |
| : * * |
0.5|-: ** ** |
| : * * |
0.25|-:** ** |
| :* * |
0|-*------------------*-----------------------|
| : * * |
-0.25|-: ** ** |
| : * * |
-0.5|-: * ** |
| : * * |
-0.75|-: * ** |
| : ** ** |
-1|-: **** |
|_:_____._____:_____._____:_____._____:_____.|
0 2 4 6
|
(require 'random)
(histograph (do ((idx 99 (+ -1 idx))
(lst '() (cons (* .02 (random:normal)) lst)))
((negative? idx) lst))
"normal")
-|
____________________________________________
9|- : |
| : |
8|- I : |
| I : |
7|- III II I |
| III II I |
6|- III II I I |
| III II I I |
5|- III II I III |
| III II I III |
4|- IIII IIIII III |
| IIII IIIII III |
3|- IIII IIIIIIIII |
| IIII IIIIIIIII |
2|- IIIIIII IIIIIIIII I I I |
| IIIIIII IIIIIIIII I I I |
1|-II I III IIIIIII IIIIIIIIIII IIIIIII |
| II I III IIIIIII IIIIIIIIIII IIIIIII |
0|-IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII-------|
|____.____:____.____:____.____:____.____:____|
normal -0.025 0 0.025 0.05
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
http://swissnet.ai.mit.edu/~jaffer/Solid/#Example gives an example use of this package.
VRML97 strings passed to vrml and vrml-to-file as
arguments will appear in the resulting VRML code. This string turns
off the headlight at the viewpoint:
" NavigationInfo {headlight FALSE}"
|
colors is a list of color objects. Each may be of type color, a 24-bit sRGB integer, or a list of 3 numbers between 0.0 and 1.0.
angles is a list of non-increasing angles the same length as colors. Each angle is between 90 and -90 degrees. If 90 or -90 are not elements of angles, then the color at the zenith and nadir are taken from the colors paired with the angles nearest them.
scene:sphere fills horizontal bands with interpolated colors on the backgroud
sphere encasing the world.
latitude is the virtual place's latitude in degrees. julian-day is an integer from 0 to 366, the day of the year. hour is a real number from 0 to 24 for the time of day; 12 is noon. turbidity is the degree of fogginess described in See section turbidity.
scene:sun returns a bright yellow, distant sphere where the sun would be at
hour on julian-day at latitude. If strength is positive, included is a light source of strength
(default 1).
latitude is the virtual place's latitude in degrees. julian-day is an integer from 0 to 366, the day of the year. hour is a real number from 0 to 24 for the time of day; 12 is noon. turbidity is the degree of cloudiness described in See section turbidity.
scene:overcast returns an overcast sky as it might look at hour on julian-day at latitude. If strength
is positive, included is an ambient light source of strength (default 1).
In VRML97, lights shine only on objects within the same children node
and descendants of that node. Although it would have been convenient
to let light direction be rotated by solid:rotation, this
restricts a rotated light's visibility to objects rotated with it.
To workaround this limitation, these directional light source
procedures accept either Cartesian or spherical coordinates for
direction. A spherical coordinate is a list (theta
azimuth); where theta is the angle in degrees from the
zenith, and azimuth is the angle in degrees due west of south.
It is sometimes useful for light sources to be brighter than `1'. When intensity arguments are greater than 1, these functions gang multiple sources to reach the desired strength.
color is a an object of type color, a 24-bit sRGB integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f, then the default color will be used. intensity is a real non-negative number defaulting to `1'.
light:ambient returns a light source or sources of color with total strength of intensity
(or 1 if omitted).
color is a an object of type color, a 24-bit sRGB integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f, then the default color will be used.
direction must be a list or vector of 2 or 3 numbers specifying the direction to this light. If direction has 2 numbers, then these numbers are the angle from zenith and the azimuth in degrees; if direction has 3 numbers, then these are taken as a Cartesian vector specifying the direction to the light source. The default direction is upwards; thus its light will shine down.
intensity is a real non-negative number defaulting to `1'.
light:directional returns a light source or sources of color with total strength of intensity,
shining from direction.
attenuation is a list or vector of three nonnegative real numbers specifying the reduction of intensity, the reduction of intensity with distance, and the reduction of intensity as the square of distance. radius is the distance beyond which the light does not shine. radius defaults to `100'.
aperture is a real number between 0 and 180, the angle centered on the light's axis through which it sheds some light. peak is a real number between 0 and 90, the angle of greatest illumination.
Point light radiates from location, intensity decreasing with distance, towards all objects with which it is grouped.
color is a an object of type color, a 24-bit sRGB
integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f,
then the default color will be used. intensity is a real non-negative number
defaulting to `1'. beam is a structure returned by
light:beam or #f.
light:point returns a light source or sources at location of color with total strength
intensity and beam properties. Note that the pointlight itself is not visible.
To make it so, place an object with emissive appearance at location.
Spot light radiates from location towards direction, intensity decreasing with distance, illuminating objects with which it is grouped.
direction must be a list or vector of 2 or 3 numbers specifying the direction to this light. If direction has 2 numbers, then these numbers are the angle from zenith and the azimuth in degrees; if direction has 3 numbers, then these are taken as a Cartesian vector specifying the direction to the light source. The default direction is upwards; thus its light will shine down.
color is a an object of type color, a 24-bit sRGB integer, or a list of 3 numbers between 0.0 and 1.0. If color is #f, then the default color will be used.
intensity is a real non-negative number defaulting to `1'.
light:spot returns a light source or sources at location of direction with total strength
color. Note that the spotlight itself is not visible. To make it so,
place an object with emissive appearance at location.
solid:box returns a cube with sides of length geometry centered on the
origin. Otherwise, solid:box returns a rectangular box with dimensions geometry
centered on the origin. appearance determines the surface properties of the
returned object.
(abs height)
centered on the origin. If height is positive, then the cylinder ends
will be capped. appearance determines the surface properties of the returned
object.
solid:disk returns a circular disk
with dimensions radius and thickness centered on the origin. appearance determines the
surface properties of the returned object.
solid:ellipsoid returns a sphere of diameter geometry centered on the origin.
Otherwise, solid:ellipsoid returns an ellipsoid with diameters geometry centered on the
origin. appearance determines the surface properties of the returned object.
Returns an appearance, the optical properties of the objects with which it is associated. ambientIntensity, shininess, and transparency must be numbers between 0 and 1. diffuseColor, specularColor, and emissiveColor are objects of type color, 24-bit sRGB integers or lists of 3 numbers between 0.0 and 1.0. If a color argument is omitted or #f, then the default color will be used.
Returns an appearance, the optical properties of the objects
with which it is associated. image is a string naming a JPEG or PNG
image resource. color is #f, a color, or the string returned by
solid:color. The rest of the optional arguments specify
2-dimensional transforms applying to the image.
scale must be #f, a number, or list or vector of 2 numbers specifying the scale to apply to image. rotation must be #f or the number of degrees to rotate image. center must be #f or a list or vector of 2 numbers specifying the center of image relative to the image dimensions. translation must be #f or a list or vector of 2 numbers specifying the translation to apply to image.
center must be a list or vector of three numbers. Returns an upward pointing metallic arrow centered at center.
solid:translation Returns an
aggregate of solids, ... with their origin moved to center.
solid:scale
Returns an aggregate of solids, ... scaled per scale.
solid:rotation Returns an
aggregate of solids, ... rotated angle degrees around the axis axis.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
http://swissnet.ai.mit.edu/~jaffer/Color
The goals of this package are to provide methods to specify, compute, and transform colors in a core set of additive color spaces. The color spaces supported should be sufficient for working with the color data encountered in practice and the literature.
4.9.1 Color Data-Type 'color 4.9.2 Color Spaces XYZ, L*a*b*, L*u*v*, L*C*h, RGB709, sRGB 4.9.3 Spectra Color Temperatures and CIEXYZ(1931) 4.9.4 Color Difference Metrics Society of Dyers and Colorists 4.9.5 Color Conversions Low-level 4.9.6 Color Names in relational databases 4.9.7 Daylight Sunlight and sky colors
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
color-precision returns the
number of bits used for each of the R, G, and B channels of the
encoding. Otherwise, color-precision returns #f
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Each color encoding has an external, case-insensitive representation. To ensure portability, the white-point for all color strings is D65. (2)
| Color Space | External Representation |
| CIEXYZ | CIEXYZ:<X>/<Y>/<Z> |
| RGB709 | RGBi:<R>/<G>/<B> |
| L*a*b* | CIELAB:<L>/<a>/<b> |
| L*u*v* | CIELuv:<L>/<u>/<v> |
| L*C*h | CIELCh:<L>/<C>/<h> |
The X, Y, Z, L, a, b, u, v, C, h, R, G, and B fields are (Scheme) real numbers within the appropriate ranges.
| Color Space | External Representation |
| sRGB | sRGB:<R>/<G>/<B> |
| e-sRGB10 | e-sRGB10:<R>/<G>/<B> |
| e-sRGB12 | e-sRGB12:<R>/<G>/<B> |
| e-sRGB16 | e-sRGB16:<R>/<G>/<B> |
The R, G, and B, fields are non-negative exact decimal integers within the appropriate ranges.
Several additional syntaxes are supported by string->color:
| Color Space | External Representation |
| sRGB | sRGB:<RRGGBB> |
| sRGB | #<RRGGBB> |
| sRGB | 0x<RRGGBB> |
| sRGB | #x<RRGGBB> |
Where RRGGBB is a non-negative six-digit hexadecimal number.
string->color
returns #f.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
We experience color relative to the illumination around us. CIEXYZ coordinates, although subject to uniform scaling, are objective. Thus other color spaces are specified relative to a white point in CIEXYZ coordinates.
The white point for digital color spaces is set to D65. For the other spaces a white-point argument can be specified. The default if none is specified is the white-point with which the color was created or last converted; and D65 if none has been specified.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The tristimulus color spaces are those whose component values are proportional measurements of light intensity. The CIEXYZ(1931) system provides 3 sets of spectra to convolve with a spectrum of interest. The result of those convolutions is coordinates in CIEXYZ space. All tristimuls color spaces are related to CIEXYZ by linear transforms, namely matrix multiplication. Of the color spaces listed here, CIEXYZ and RGB709 are tristimulus spaces.
CIEXYZ is a list of three inexact numbers between 0 and 1.1. '(0. 0. 0.) is black; '(1. 1. 1.) is white.
xyz must be a list of 3 numbers. If xyz is valid CIEXYZ coordinates,
then ciexyz->color returns the color specified by xyz; otherwise returns #f.
Returns the CIEXYZ color composed of x, y, z. If the coordinates do not encode a valid CIEXYZ color, then an error is signaled.
An RGB709 color is represented by a list of three inexact numbers between 0 and 1. '(0. 0. 0.) is black '(1. 1. 1.) is white.
rgb must be a list of 3 numbers. If rgb is valid RGB709 coordinates,
then rgb709->color returns the color specified by rgb; otherwise returns #f.
Returns the RGB709 color composed of r, g, b. If the coordinates do not encode a valid RGB709 color, then an error is signaled.
Although properly encoding the chromaticity, tristimulus spaces do not match the logarithmic response of human visual systems to intensity. Minimum detectable differences between colors correspond to a smaller range of distances (6:1) in the L*a*b* and L*u*v* spaces than in tristimulus spaces (80:1). For this reason, color distances are computed in L*a*b* (or L*C*h).
L*a*b* must be a list of 3 numbers. If L*a*b* is valid L*a*b* coordinates,
then l*a*b*->color returns the color specified by L*a*b*; otherwise returns #f.
Returns the L*a*b* color composed of L*, a*, b* with white-point.
Returns the list of 3 numbers encoding color in L*a*b* with white-point.
L*u*v* must be a list of 3 numbers. If L*u*v* is valid L*u*v* coordinates,
then l*u*v*->color returns the color specified by L*u*v*; otherwise returns #f.
Returns the L*u*v* color composed of L*, u*, v* with white-point.
Returns the list of 3 numbers encoding color in L*u*v* with white-point.
HSL (Hue Saturation Lightness), HSV (Hue Saturation Value), HSI (Hue Saturation Intensity) and HCI (Hue Chroma Intensity) are cylindrical color spaces (with angle hue). But these spaces are all defined in terms device-dependent RGB spaces.
One might wonder if there is some fundamental reason why intuitive specification of color must be device-dependent. But take heart! A cylindrical system can be based on L*a*b* and is used for predicting how close colors seem to observers.
The colors by quadrant of h are:
| 0 | red, orange, yellow | 90 |
| 90 | yellow, yellow-green, green | 180 |
| 180 | green, cyan (blue-green), blue | 270 |
| 270 | blue, purple, magenta | 360 |
L*C*h must be a list of 3 numbers. If L*C*h is valid L*C*h coordinates,
then l*c*h->color returns the color specified by L*C*h; otherwise returns #f.
Returns the L*C*h color composed of L*, C*, h with white-point.
Returns the list of 3 numbers encoding color in L*C*h with white-point.
The color spaces discussed so far are impractical for image data because of numerical precision and computational requirements. In 1998 the IEC adopted A Standard Default Color Space for the Internet - sRGB (http://www.w3.org/Graphics/Color/sRGB). sRGB was cleverly designed to employ the 24-bit (256x256x256) color encoding already in widespread use; and the 2.2 gamma intrinsic to CRT monitors.
Conversion from CIEXYZ to digital (sRGB) color spaces is accomplished by conversion first to a RGB709 tristimulus space with D65 white-point; then each coordinate is individually subjected to the same non-linear mapping. Inverse operations in the reverse order create the inverse transform.
rgb must be a list of 3 numbers. If rgb is valid sRGB coordinates,
then srgb->color returns the color specified by rgb; otherwise returns #f.
Returns the sRGB color composed of r, g, b. If the coordinates do not encode a valid sRGB color, then an error is signaled.
Returns the list of 3 integers encoding color in sRGB.
Returns the sRGB color composed of the 24-bit integer k.
A triplet of integers represent e-sRGB colors. Three precisions are supported:
e-srgb->color returns the color
specified by rgb; otherwise returns #f.
Returns the e-sRGB10 color composed of integers r, g, b.
color->e-srgb returns the list of 3
integers encoding color in sRGB10, sRGB12, or sRGB16.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following functions compute colors from spectra, scale color luminance, and extract chromaticity. XYZ is used in the names of procedures for unnormalized colors; the coordinates of CIEXYZ colors are constrained as described in 4.9.2 Color Spaces.
(require 'color-space)
A spectrum may be represented as:
CIEXYZ values are calculated as dot-product with the X, Y (Luminance), and Z Spectral Tristimulus Values. The files `cie1931.xyz' and `cie1964.xyz' in the distribution contain these CIE-defined values.
(require 'cie1964) or (require 'cie1931) will load
specific values used by the following spectrum conversion procedures.
The spectrum conversion procedures (require 'ciexyz) to assure
that a set is loaded.
spectrum->XYZ
computes the CIEXYZ(1931) values for the spectrum returned by proc
when called with arguments from 380e-9 to 780e-9, the wavelength in
meters.
spectrum->XYZ returns the
CIEXYZ(1931) values for a light source with spectral values proportional
to the elements of spectrum at evenly spaced wavelengths between
x1 and x2.
Compute the colors of 6500.K and 5000.K blackbody radiation:
(require 'color-space)
(define xyz (spectrum->XYZ (blackbody-spectrum 6500)))
(define y_n (cadr xyz))
(map (lambda (x) (/ x y_n)) xyz)
=> (0.9687111145512467 1.0 1.1210875945303613)
(define xyz (spectrum->XYZ (blackbody-spectrum 5000)))
(map (lambda (x) (/ x y_n)) xyz)
=> (0.2933441826889158 0.2988931825387761 0.25783646831201573)
|
spectrum->CIEXYZ computes the CIEXYZ(1931) values for the
spectrum, scaled so their sum is 1.
wavelength->XYZ returns (unnormalized) XYZ values for a
monochromatic light source with wavelength w.
wavelength->chromaticity returns the chromaticity for a
monochromatic light source with wavelength w.
wavelength->CIEXYZ returns XYZ values for the saturated color
having chromaticity of a monochromatic light source with wavelength
w.
The optional argument span is the wavelength analog of bandwidth. With the default span of 1.nm (1e-9.m), the values returned by the procedure correspond to the power of the photons with wavelengths w to w+1e-9.
temperature->XYZ computes the CIEXYZ(1931) values for the
spectrum of a black body at temperature x.
Compute the chromaticities of 6500.K and 5000.K blackbody radiation:
(require 'color-space)
(XYZ->chromaticity (temperature->XYZ 6500))
=> (0.3135191660557008 0.3236456786200268)
(XYZ->chromaticity (temperature->XYZ 5000))
=> (0.34508082841161052 0.3516084965163377)
|
temperature->CIEXYZ computes the CIEXYZ(1931) values for the
spectrum of a black body at temperature x, scaled to be just
inside the RGB709 gamut.
XYZ:normalize returns a list of numbers proportional to
xyz; scaled so their sum is 1.
XYZ:normalize-colors
scales all the triples by a common factor such that the maximum sum of
numbers in a scaled triple is 1.
Many color datasets are expressed in xyY format; chromaticity with CIE luminance (Y). But xyY is not a CIE standard like CIEXYZ, CIELAB, and CIELUV. Although chrominance is well defined, the luminance component is sometimes scaled to 1, sometimes to 100, but usually has no obvious range. With no given whitepoint, the only reasonable course is to ascertain the luminance range of a dataset and normalize the values to lie from 0 to 1.
xyY:normalize-colors
scales each chromaticity so it sums to 1 or less; and divides the
Y values by the maximum Y in the dataset, so all lie between
0 and 1.
xyY:normalize-colors divides
the Y values by n times the maximum Y in the dataset.
If n is an exact non-positive integer, then
xyY:normalize-colors divides the Y values by the maximum of
the Ys in the dataset excepting the -n largest Y
values.
In all cases, returned Y values are limited to lie from 0 to 1.
Why would one want to normalize to other than 1? If the sun or its reflection is the brightest object in a scene, then normalizing to its luminance will tend to make the rest of the scene very dark. As with photographs, limiting the specular highlights looks better than darkening everything else.
The results of measurements being what they are,
xyY:normalize-colors is extremely tolerant. Negative numbers are
replaced with zero, and chromaticities with sums greater than one are
scaled to sum to one.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
CIE:DE*94 measures distance in the L*C*h cylindrical color-space.
The three axes are individually scaled (depending on C*) in their
contributions to the total distance.
The CIE has defined reference conditions under which the metric with default parameters can be expected to perform well. These are:
The parametric-factors argument is a list of 3 quantities kL, kC and kH. parametric-factors independently adjust each colour-difference term to account for any deviations from the reference viewing conditions. Under the reference conditions explained above, the default is kL = kC = kH = 1.
The Color Measurement Committee of The Society of Dyers and Colorists in Great Britain created a more sophisticated color-distance function for use in judging the consistency of dye lots. With CMC:DE* it is possible to use a single value pass/fail tolerance for all shades.
CMC:DE* is also a L*C*h metric. The parametric-factors
argument is a list of 2 numbers l and c. l and
c parameterize this metric. 1 and 1 are recommended for
perceptibility; the default, 2 and 1, for acceptability.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This package contains the low-level color conversion and color metric routines operating on lists of 3 numbers. There is no type or range checking.
(require 'color-space)
Do not convert e-sRGB precision through e-sRGB->sRGB then
sRGB->e-sRGB -- values would be truncated to 8-bits!
e-sRGB->e-sRGB converts srgb to e-sRGB of precision
n2.
L*C*h:DE*94 measures distance in the L*C*h cylindrical color-space
between lch1 and lch2. The three axes are individually
scaled (depending on C*) in their contributions to the total distance.
CMC:DE is a L*C*h metric. The parametric-factors
argument is a list of 2 numbers l and c. l and
c parameterize this metric. 1 and 1 are recommended for
perceptibility; the default, 2 and 1, for acceptability.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Rather than ballast the color dictionaries with numbered grays,
file->color-dictionary discards them. They are provided
through the grey procedure:
Returns (inexact->exact (round (* k 2.55))), the X11 color
grey<k>.
The column names in a color dictionary are unimportant; the first field is the key, and the second is the color-string.
table1, table2, ... must be color-dictionary tables. color-name->color searches for the
canonical form of name in table1, table2, ... in order; returning the
color-string of the first matching record; #f otherwise.
table1, table2, ... must be color-dictionary tables. color-dictionaries->lookup returns a
procedure which searches for the canonical form of its string argument
in table1, table2, ...; returning the color-string of the first matching
record; and #f otherwise.
rdb must be a string naming a relational database file; and the symbol
name a table therein. The database will be opened as
base-table-type. color-dictionary returns the read-only table name in database
name if it exists; #f otherwise.
rdb must be an open relational database or a string naming a relational
database file; and the symbol name a table therein. color-dictionary returns the
read-only table name in database name if it exists; #f otherwise.
rdb must be a string naming a relational database file; and the symbol
name a table therein. If the symbol base-table-type is provided, the database will
be opened as base-table-type. load-color-dictionary creates a top-level definition of the symbol name
to a lookup procedure for the color dictionary name in rdb.
The value returned by load-color-dictionary is unspecified.
rdb must be an open relational database or a string naming a relational
database file, table-name a symbol, and the string file must name an existing
file with colornames and their corresponding xRGB (6-digit hex)
values. file->color-dictionary creates a table table-name in rdb and enters the associations found
in file into it.
rdb must be an open relational database or a string naming a relational
database file and table-name a symbol. url->color-dictionary retrieves the resource named by the
string url using the wget program; then calls
file->color-dictionary to enter its associations in table-name in url.
http://swissnet.ai.mit.edu/~jaffer/Color/Dictionaries.html
Describes and evaluates several color-name dictionaries on the web. The following procedure creates a database containing two of these dictionaries.
Creates an alist-table relational database in library-vicinity containing the Resene and saturate color-name dictionaries.
If the files `resenecolours.txt' and `saturate.txt' exist in
the library-vicinity, then they used as the source of color-name
data. Otherwise, make-slib-color-name-db calls url->color-dictionary with the URLs of
appropriate source files.
| reddish orange | orange | yellowish orange | yellow |
| greenish yellow | yellow green | yellowish green | green |
| bluish green | blue green | greenish blue | blue |
| purplish blue | bluish purple | purple | reddish purple |
| red purple | purplish red | red |
(http://swissnet.ai.mit.edu/~jaffer/Color/saturate.pdf). If name is found, the corresponding color is returned. Otherwise #f is returned. Use saturate only for light source colors.
Resene Paints Limited, New Zealand's largest privately-owned and operated paint manufacturing company, has generously made their Resene RGB Values List available.
If you include the Resene RGB Values List in binary form in a program, then you must include its license with your program:
Resene RGB Values List
For further information refer to http://www.resene.co.nz
Copyright Resene Paints Ltd 2001Permission to copy this dictionary, to modify it, to redistribute it, to distribute modified versions, and to use it for any purpose is granted, subject to the following restrictions and understandings.
- Any text copy made of this dictionary must include this copyright notice in full.
- Any redistribution in binary form must reproduce this copyright notice in the documentation or other materials provided with the distribution.
- Resene Paints Ltd makes no warrantee or representation that this dictionary is error-free, and is under no obligation to provide any services, by way of maintenance, update, or otherwise.
- There shall be no use of the name of Resene or Resene Paints Ltd in any advertising, promotional, or sales literature without prior written consent in each case.
- These RGB colour formulations may not be used to the detriment of Resene Paints Ltd.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This package calculates the colors of sky as detailed in:
http://www.cs.utah.edu/vissim/papers/sunsky/sunsky.pdf
A Practical Analytic Model for Daylight
A. J. Preetham, Peter Shirley, Brian Smits
Returns the solar-time in hours given the integer julian-day in the range 1 to 366, and the local time in hours.
To be meticulous, subtract 4 minutes for each degree of longitude west of the standard meridian of your time zone.
Turbidity is a measure of the fraction of scattering due to haze as opposed to molecules. This is a convenient quantity because it can be estimated based on visibility of distant objects. This model fails for turbidity values less than 1.3.
_______________________________________________________________
512|-: |
| * pure-air |
256|-:** |
| : ** exceptionally-clear |
128|-: * |
| : ** |
64|-: * |
| : ** very-clear |
32|-: ** |
| : ** |
16|-: *** clear |
| : **** |
8|-: **** |
| : **** light-haze |
4|-: **** |
| : ****** |
2|-: ******** haze thin-|
| : *********** fog |
1|-:----------------------------------------------------*******--|
|_:____.____:____.____:____.____:____.____:____.____:____.____:_|
1 2 4 8 16 32 64
Meterorological range (km) versus Turbidity
|
sunlight-ciexyz returns the CIEXYZ triple for color of
sunlight scaled to be just inside the RGB709 gamut.
overcast-sky-color-xyy returns a function of one angle theta, the angle from the
zenith of the viewing direction (in degrees); and returning the xyY
value for light coming from that elevation of the sky.
clear-sky-color-xyy returns a function of two angles, theta and phi which
specify the angles from the zenith and south meridian of the viewing
direction (in degrees); returning the xyY value for light coming from
that direction of the sky.
sky-color-xyY calls overcast-sky-color-xyY for
turbidity <= 20; otherwise the clear-sky-color-xyy function.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#f if such an integer can't be found.
To find the closest integer to a given integers square root:
(define (integer-sqrt y) (newton:find-integer-root (lambda (x) (- (* x x) y)) (lambda (x) (* 2 x)) (ash 1 (quotient (integer-length y) 2)))) (integer-sqrt 15) => 4 |
abs(f(x)) is less than prec; or
returns #f if such a real can't be found.
If prec is instead a negative integer, newton:find-root
returns the result of -prec iterations.
H. J. Orchard, The Laguerre Method for Finding the Zeros of Polynomials, IEEE Transactions on Circuits and Systems, Vol. 36, No. 11, November 1989, pp 1377-1381.
There are 2 errors in Orchard's Table II. Line k=2 for starting value of 1000+j0 should have Z_k of 1.0475 + j4.1036 and line k=2 for starting value of 0+j1000 should have Z_k of 1.0988 + j4.0833.
magnitude(f(z)) is less than prec; or returns
#f if such a number can't be found.
If prec is instead a negative integer, laguerre:find-root
returns the result of -prec iterations.
magnitude(f(z)) is less than prec; or
returns #f if such a number can't be found.
If prec is instead a negative integer,
laguerre:find-polynomial-root returns the result of -prec
iterations.
(abs (f x)) is less than prec; or returns
#f if such a real can't be found.
If x0 and x1 are chosen such that they bracket a root, that is
(or (< (f x0) 0 (f x1))
(< (f x1) 0 (f x0)))
|
secant:find-bracketed-root will return #f unless x0
and x1 bracket a root.
The secant method is used until a bracketing interval is found, at which point a modified regula falsi method is used.
If prec is instead a negative integer, secant:find-root
returns the result of -prec iterations.
If prec is a procedure it should accept 5 arguments: x0
f0 x1 f1 and count, where f0 will be
(f x0), f1 (f x1), and count the number of
iterations performed so far. prec should return non-false
if the iteration should be stopped.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Golden Section Search (4) algorithm finds minima of functions which are expensive to compute or for which derivatives are not available. Although optimum for the general case, convergence is slow, requiring nearly 100 iterations for the example (x^3-2x-5).
If the derivative is available, Newton-Raphson is probably a better choice. If the function is inexpensive to compute, consider approximating the derivative.
x_0 are x_1 real numbers. The (single argument) procedure f is unimodal over the open interval (x_0, x_1). That is, there is exactly one point in the interval for which the derivative of f is zero.
golden-section-search returns a pair (x . f(x)) where f(x)
is the minimum. The prec parameter is the stop criterion. If
prec is a positive number, then the iteration continues until
x is within prec from the true value. If prec is
a negative integer, then the procedure will iterate -prec
times or until convergence. If prec is a procedure of seven
arguments, x0, x1, a, b, fa, fb,
and count, then the iterations will stop when the procedure
returns #t.
Analytically, the minimum of x^3-2x-5 is 0.816497.
(define func (lambda (x) (+ (* x (+ (* x x) -2)) -5)))
(golden-section-search func 0 1 (/ 10000))
==> (816.4883855245578e-3 . -6.0886621077391165)
(golden-section-search func 0 1 -5)
==> (819.6601125010515e-3 . -6.088637561916407)
(golden-section-search func 0 1
(lambda (a b c d e f g ) (= g 500)))
==> (816.4965933140557e-3 . -6.088662107903635)
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scheme provides a consistent and capable set of numeric functions. Inexacts implement a field; integers a commutative ring (and Euclidean domain). This package allows one to use basic Scheme numeric functions with symbols and non-numeric elements of commutative rings.
The commutative-ring package makes the procedures +,
-, *, /, and ^ careful in the sense
that any non-numeric arguments they do not reduce appear in the
expression output. In order to see what working with this package is
like, self-set all the single letter identifiers (to their corresponding
symbols).
(define a 'a) ... (define z 'z) |
Or just (require 'self-set). Now try some sample expressions:
(+ (+ a b) (- a b)) => (* a 2) (* (+ a b) (+ a b)) => (^ (+ a b) 2) (* (+ a b) (- a b)) => (* (+ a b) (- a b)) (* (- a b) (- a b)) => (^ (- a b) 2) (* (- a b) (+ a b)) => (* (+ a b) (- a b)) (/ (+ a b) (+ c d)) => (/ (+ a b) (+ c d)) (^ (+ a b) 3) => (^ (+ a b) 3) (^ (+ a 2) 3) => (^ (+ 2 a) 3) |
Associative rules have been applied and repeated addition and multiplication converted to multiplication and exponentiation.
We can enable distributive rules, thus expanding to sum of products form:
(set! *ruleset* (combined-rulesets distribute* distribute/)) (* (+ a b) (+ a b)) => (+ (* 2 a b) (^ a 2) (^ b 2)) (* (+ a b) (- a b)) => (- (^ a 2) (^ b 2)) (* (- a b) (- a b)) => (- (+ (^ a 2) (^ b 2)) (* 2 a b)) (* (- a b) (+ a b)) => (- (^ a 2) (^ b 2)) (/ (+ a b) (+ c d)) => (+ (/ a (+ c d)) (/ b (+ c d))) (/ (+ a b) (- c d)) => (+ (/ a (- c d)) (/ b (- c d))) (/ (- a b) (- c d)) => (- (/ a (- c d)) (/ b (- c d))) (/ (- a b) (+ c d)) => (- (/ a (+ c d)) (/ b (+ c d))) (^ (+ a b) 3) => (+ (* 3 a (^ b 2)) (* 3 b (^ a 2)) (^ a 3) (^ b 3)) (^ (+ a 2) 3) => (+ 8 (* a 12) (* (^ a 2) 6) (^ a 3)) |
Use of this package is not restricted to simple arithmetic expressions:
(require 'determinant) (determinant '((a b c) (d e f) (g h i))) => (- (+ (* a e i) (* b f g) (* c d h)) (* a f h) (* b d i) (* c e g)) |
Currently, only +, -, *, /, and ^
support non-numeric elements. Expressions with - are converted
to equivalent expressions without -, so behavior for - is
not defined separately. / expressions are handled similarly.
This list might be extended to include quotient, modulo,
remainder, lcm, and gcd; but these work only for
the more restrictive Euclidean (Unique Factorization) Domain.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The commutative-ring package allows control of ring properties through the use of rulesets.
cring:define-rule are stored within the value of *ruleset* at the
time cring:define-rule is called. If *ruleset* is
#f, then no rules apply.
cring:define-rule to each 4-element list argument rule. If
the first argument to make-ruleset is a symbol, then the database
table created for the new ruleset will be named name. Calling
make-ruleset with no rule arguments creates an empty ruleset.
combined-ruleset is a symbol, then the database table created for
the new ruleset will be named name. Calling
combined-ruleset with no ruleset arguments creates an empty
ruleset.
Two rulesets are defined by this package.
Take care when using both distribute* and distribute/
simultaneously. It is possible to put / into an infinite loop.
You can specify how sum and product expressions containing non-numeric
elements simplify by specifying the rules for + or * for
cases where expressions involving objects reduce to numbers or to
expressions involving different non-numeric elements.
cars are sub-op1 and
sub-op2, respectively. The argument reduction is a
procedure accepting 2 arguments which will be lists whose cars
are sub-op1 and sub-op2.
car is sub-op1, and
some other argument. Reduction will be called with the list whose
car is sub-op1 and some other argument.
If reduction returns #f, the reduction has failed and other
reductions will be tried. If reduction returns a non-false value,
that value will replace the two arguments in arithmetic (+,
-, and *) calculations involving non-numeric elements.
The operations + and * are assumed commutative; hence both
orders of arguments to reduction will be tried if necessary.
The following rule is the definition for distributing * over
+.
(cring:define-rule '* '+ 'identity (lambda (exp1 exp2) (apply + (map (lambda (trm) (* trm exp2)) (cdr exp1)))))) |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The first step in creating your commutative ring is to write procedures to create elements of the ring. A non-numeric element of the ring must be represented as a list whose first element is a symbol or string. This first element identifies the type of the object. A convenient and clear convention is to make the type-identifying element be the same symbol whose top-level value is the procedure to create it.
(define (n . list1)
(cond ((and (= 2 (length list1))
(eq? (car list1) (cadr list1)))
0)
((not (term< (first list1) (last1 list1)))
(apply n (reverse list1)))
(else (cons 'n list1))))
(define (s x y) (n x y))
(define (m . list1)
(cond ((neq? (first list1) (term_min list1))
(apply m (cyclicrotate list1)))
((term< (last1 list1) (cadr list1))
(apply m (reverse (cyclicrotate list1))))
(else (cons 'm list1))))
|
Define a procedure to multiply 2 non-numeric elements of the ring. Other multiplicatons are handled automatically. Objects for which rules have not been defined are not changed.
(define (n*n ni nj)
(let ((list1 (cdr ni)) (list2 (cdr nj)))
(cond ((null? (intersection list1 list2)) #f)
((and (eq? (last1 list1) (first list2))
(neq? (first list1) (last1 list2)))
(apply n (splice list1 list2)))
((and (eq? (first list1) (first list2))
(neq? (last1 list1) (last1 list2)))
(apply n (splice (reverse list1) list2)))
((and (eq? (last1 list1) (last1 list2))
(neq? (first list1) (first list2)))
(apply n (splice list1 (reverse list2))))
((and (eq? (last1 list1) (first list2))
(eq? (first list1) (last1 list2)))
(apply m (cyclicsplice list1 list2)))
((and (eq? (first list1) (first list2))
(eq? (last1 list1) (last1 list2)))
(apply m (cyclicsplice (reverse list1) list2)))
(else #f))))
|
Test the procedures to see if they work.
;;; where cyclicrotate(list) is cyclic rotation of the list one step
;;; by putting the first element at the end
(define (cyclicrotate list1)
(append (rest list1) (list (first list1))))
;;; and where term_min(list) is the element of the list which is
;;; first in the term ordering.
(define (term_min list1)
(car (sort list1 term<)))
(define (term< sym1 sym2)
(string<? (symbol->string sym1) (symbol->string sym2)))
(define first car)
(define rest cdr)
(define (last1 list1) (car (last-pair list1)))
(define (neq? obj1 obj2) (not (eq? obj1 obj2)))
;;; where splice is the concatenation of list1 and list2 except that their
;;; common element is not repeated.
(define (splice list1 list2)
(cond ((eq? (last1 list1) (first list2))
(append list1 (cdr list2)))
(else (error 'splice list1 list2))))
;;; where cyclicsplice is the result of leaving off the last element of
;;; splice(list1,list2).
(define (cyclicsplice list1 list2)
(cond ((and (eq? (last1 list1) (first list2))
(eq? (first list1) (last1 list2)))
(butlast (splice list1 list2) 1))
(else (error 'cyclicsplice list1 list2))))
(N*N (S a b) (S a b)) => (m a b)
|
Then register the rule for multiplying type N objects by type N objects.
(cring:define-rule '* 'N 'N N*N)) |
Now we are ready to compute!
(define (t)
(define detM
(+ (* (S g b)
(+ (* (S f d)
(- (* (S a f) (S d g)) (* (S a g) (S d f))))
(* (S f f)
(- (* (S a g) (S d d)) (* (S a d) (S d g))))
(* (S f g)
(- (* (S a d) (S d f)) (* (S a f) (S d d))))))
(* (S g d)
(+ (* (S f b)
(- (* (S a g) (S d f)) (* (S a f) (S d g))))
(* (S f f)
(- (* (S a b) (S d g)) (* (S a g) (S d b))))
(* (S f g)
(- (* (S a f) (S d b)) (* (S a b) (S d f))))))
(* (S g f)
(+ (* (S f b)
(- (* (S a d) (S d g)) (* (S a g) (S d d))))
(* (S f d)
(- (* (S a g) (S d b)) (* (S a b) (S d g))))
(* (S f g)
(- (* (S a b) (S d d)) (* (S a d) (S d b))))))
(* (S g g)
(+ (* (S f b)
(- (* (S a f) (S d d)) (* (S a d) (S d f))))
(* (S f d)
(- (* (S a b) (S d f)) (* (S a f) (S d b))))
(* (S f f)
(- (* (S a d) (S d b)) (* (S a b) (S d d))))))))
(* (S b e) (S c a) (S e c)
detM
))
(pretty-print (t))
-|
(- (+ (m a c e b d f g)
(m a c e b d g f)
(m a c e b f d g)
(m a c e b f g d)
(m a c e b g d f)
(m a c e b g f d))
(* 2 (m a b e c) (m d f g))
(* (m a c e b d) (m f g))
(* (m a c e b f) (m d g))
(* (m a c e b g) (m d f)))
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(require 'determinant)
A Matrix can be either a list of lists (rows) or an array. As with linear-algebra texts, this package uses 1-based coordinates.
Returns the list-of-lists form of matrix.
Returns the (ones-based) array form of matrix.
matrix must be a square matrix.
determinant returns the determinant of matrix.
(require 'determinant) (determinant '((1 2) (3 4))) => -2 (determinant '((1 2 3) (4 5 6) (7 8 9))) => 0 |
Returns a copy of matrix flipped over the diagonal containing the 1,1 element.
Returns the product of matrices m1 and m2.
matrix must be a square matrix.
If matrix is singlar, then matrix:inverse returns #f; otherwise matrix:inverse returns the
matrix:product inverse of matrix.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |