Difference between revisions of "VasCalc Documentation - vectorSpace"

From Drorbn
Jump to: navigation, search
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The vectorSpace package is a small package used to set up quotients of finite dimensional vector spaces. The source files for this package are
+
The vectorSpace package is a small part of the [[VasCalc]] project, used to set up quotients of finite dimensional vector spaces, with an interface through Mathematica. By default, vectorSpace works over arbitrarily-sized rationals, using the BigRational implementation written by Eric Laroche (see [[VasCalc - Bibliography]]).  See below for instructions on using other fields. The main advantage in using this package is that by being less general, it stands to perform much faster than similar functions in Mathematica.
  
*[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/Coefficient.java Coefficient.java],  
+
==Installation==
*[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/QuotientSpace.java QuotientSpace.java],  
+
If you wish to use this package on its own, follow the directions below.
*[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/AlgebraVector.java AlgebraVector.java].  
+
 
 +
Create a directory on your file system named <i>vectorSpace</i>, and download the following four files from the repository into it:
 +
 
 +
*[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/Coefficient.class Coefficient.class],  
 +
*[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/QuotientSpace.class QuotientSpace.class],  
 +
*[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/AlgebraVector.class AlgebraVector.class],
 +
*[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/BigRational.class BigRational.class].
 +
 
 +
Also, download [http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace.m vectorSpace.m] (the Mathematica interface) to any location.
  
The class contained in [http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/BigRational.java BigRational.java] contains Eric Laroche's implementation of arithemetic involving arbitrarily large rationals (see [[VasCalc - Bibliography]]), which is used as the default base field in vectorSpace. Additionally, there are two small test programs:[http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/testQuotSp.java testQuotSp.java] and [http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/testAlgVect.java testAlgVect.java].
 
 
==Usage==
 
==Usage==
 +
 +
In Mathematica, type
 +
{{In | n=1| in=<nowiki><</path_to/vectorSpace.m</nowiki>}}
 +
to load the definitions.
 +
We also need to specify where the vectorSpace package lives. Replace "/some_path" with the parent directory of the vectorSpace folder created earlier, retaining the quotes, in the following command:
 +
{{In| n=2|in = SetVectorSpacePath["/some_path"];}}
 +
 +
We need to start by setting up a finite-dim vector space to work with. The command NewVS[n] returns a reference to a Java instance of the class QuotientSpace. This class represents a v.s. of dimension n, along with any relations between the basis vectors (described below). Here we create a vector space of dimension 5:
 +
 +
{{In|n=3|in= qs = NewVectorSpace[5];}}
 +
 +
In the vector space package, vectors are stored as lists of ordered pairs {index, coeff}, where the index refers to a fixed implicit original basis. For convenience, the Mathematica interface allows one to label the basis elements with Mathematica symbols by passing a Basis[..] object to the operations described below, and hence you can use all of Mathematica's symbolic manipulations on these expressions. Note, however, that this labelling does not change the internal representation of the vectors; if you change the basis you use, it's unlikely you'll get meaningful results, as you may have already defined relations in terms of another basis.
 +
 +
To set up an initial basis, say of elements e0, ... , e4:
 +
{{In|n=4| in = b = Basis[e0,e1,e2,e3,e4];}}
 +
 +
Here are the operations one can perform:
 +
 +
*To introduce a relation, use <code>ModBy[v, quotientspace, basis]</code>, which introduces the relation v=0 (where v is written in terms of <code>basis</code>) in the given vector space <code>quotientspace</code>.
 +
 +
*The command <code>GetDimension[quotientspace]</code>, returns the dimension of the quotient (that is, taking into account the relations defined).
 +
 +
*The command <code>ReduceQuotient[v, quotientspace, basis]</code> returns a vector equivalent to v modulo the relations defined in <code>quotientspace</code>. Both v and the output are written as linear combinations in terms of the given basis.
 +
 +
*If you need it, the command <code>ResolveVector[v, basis]</code> converts a vector as a formal sum into a list of {index, coeff} pairs.
 +
 +
 +
Here are some examples, using the earlier setup:
 +
Let's introduce a relation
 +
 +
{{In|n=5| in = ModBy[3e0 + e3 - 2e4, qs, b];}}
 +
 +
Now the quotient space has one less dimension:
 +
{{InOut|n=6| in = GetDimension[qs]|out = 4}}
 +
 +
Reducing a vector in the quotient:
 +
{{InOut|n=7|in= ReduceQuotient[e0 + (1/3)e1 - e4, qs, b] //Simplify|
 +
out =(1/3)(e1 - e3 - e4)}}
 +
 +
==Changing the Coefficient Field==
 +
By default, vectorSpace works over an implementation of the rationals that allows for arbitrarily large numbers. If you wish to use a different field, you must
 +
# Download the source file [http://katlas.math.toronto.edu/svn/VasCalc/trunk/vectorSpace/Coefficient.java Coefficient.java], whose sole purpose is to provide a wrapper to the field. This file contains comments detailing the necessary modifications for a different field; basically one needs to define the arithmetic operations, and return the additive and multiplicative identities in a standard manner.
 +
# If you wish to use vectorSpace in Mathematica, you will also need to edit vectorSpace.m in order to manipulate your expressions properly in Mathematica. In particular, you will have to rewrite <code> ToJCoeff[c] </code> to create a instance of the Coefficient class from the Mathematica expression c; also, <code> ToMCoeff[c] </code> for the other direction.
 +
 +
If you succeed in getting another interesting field to work, feel free to add to this page.

Latest revision as of 16:59, 31 May 2006

The vectorSpace package is a small part of the VasCalc project, used to set up quotients of finite dimensional vector spaces, with an interface through Mathematica. By default, vectorSpace works over arbitrarily-sized rationals, using the BigRational implementation written by Eric Laroche (see VasCalc - Bibliography). See below for instructions on using other fields. The main advantage in using this package is that by being less general, it stands to perform much faster than similar functions in Mathematica.

Installation

If you wish to use this package on its own, follow the directions below.

Create a directory on your file system named vectorSpace, and download the following four files from the repository into it:

Also, download vectorSpace.m (the Mathematica interface) to any location.

Usage

In Mathematica, type

In[1]:= <</path_to/vectorSpace.m

to load the definitions. We also need to specify where the vectorSpace package lives. Replace "/some_path" with the parent directory of the vectorSpace folder created earlier, retaining the quotes, in the following command:

In[2]:= SetVectorSpacePath["/some_path"];

We need to start by setting up a finite-dim vector space to work with. The command NewVS[n] returns a reference to a Java instance of the class QuotientSpace. This class represents a v.s. of dimension n, along with any relations between the basis vectors (described below). Here we create a vector space of dimension 5:

In[3]:= qs = NewVectorSpace[5];

In the vector space package, vectors are stored as lists of ordered pairs {index, coeff}, where the index refers to a fixed implicit original basis. For convenience, the Mathematica interface allows one to label the basis elements with Mathematica symbols by passing a Basis[..] object to the operations described below, and hence you can use all of Mathematica's symbolic manipulations on these expressions. Note, however, that this labelling does not change the internal representation of the vectors; if you change the basis you use, it's unlikely you'll get meaningful results, as you may have already defined relations in terms of another basis.

To set up an initial basis, say of elements e0, ... , e4:

In[4]:= b = Basis[e0,e1,e2,e3,e4];

Here are the operations one can perform:

  • To introduce a relation, use ModBy[v, quotientspace, basis], which introduces the relation v=0 (where v is written in terms of basis) in the given vector space quotientspace.
  • The command GetDimension[quotientspace], returns the dimension of the quotient (that is, taking into account the relations defined).
  • The command ReduceQuotient[v, quotientspace, basis] returns a vector equivalent to v modulo the relations defined in quotientspace. Both v and the output are written as linear combinations in terms of the given basis.
  • If you need it, the command ResolveVector[v, basis] converts a vector as a formal sum into a list of {index, coeff} pairs.


Here are some examples, using the earlier setup: Let's introduce a relation

In[5]:= ModBy[3e0 + e3 - 2e4, qs, b];

Now the quotient space has one less dimension:

In[6]:= GetDimension[qs]
Out[6]= 4

Reducing a vector in the quotient:

In[7]:= ReduceQuotient[e0 + (1/3)e1 - e4, qs, b] //Simplify
Out[7]= (1/3)(e1 - e3 - e4)

Changing the Coefficient Field

By default, vectorSpace works over an implementation of the rationals that allows for arbitrarily large numbers. If you wish to use a different field, you must

  1. Download the source file Coefficient.java, whose sole purpose is to provide a wrapper to the field. This file contains comments detailing the necessary modifications for a different field; basically one needs to define the arithmetic operations, and return the additive and multiplicative identities in a standard manner.
  2. If you wish to use vectorSpace in Mathematica, you will also need to edit vectorSpace.m in order to manipulate your expressions properly in Mathematica. In particular, you will have to rewrite ToJCoeff[c] to create a instance of the Coefficient class from the Mathematica expression c; also, ToMCoeff[c] for the other direction.

If you succeed in getting another interesting field to work, feel free to add to this page.