[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

Algebraic Concepts |

The algebraic concepts describe requirements for algebraic types, that is for types that support arithmetic operations. The built-in types are concepts of AlgebraicField and DivisionAlgebra.

### Algebraic Ring

- A model of Algebraic Ring implements `Assignable`, `Default Constructible`, `Equality Comparable` and `Strict Weakly Comparable` as defined in the C++ standard (cf. the Standard Template Library documentation).

- A model of Algebraic Ring implements addition, subtraction and unary negation. The associated NumericTraits define a 'zero' element, the type of the result of addition and subtraction, and a type conversion function. Addition must be commutative.

          ModelOfAlgebraicRing a, b;
          NumericTraits<ModelOfAlgebraicRing>::Promote c;

          ModelOfAlgebraicRing zero = NumericTraits<ModelOfAlgebraicRing>::zero();

          b += a;
          b -= a;
          b = -a;
          c = a + b;
          c = a - b;
          c = a;
          a = NumericTraits<ModelOfAlgebraicRing>::fromPromote(c);

          assert(a + zero == a);
          assert(a + b == b + a);
          assert(a - b == a + (-b));

- If mixed-type addition and subtraction are supported, PromoteTraits define the result type:

          ModelOfAlgebraicRing1 a;
          ModelOfAlgebraicRing2 b;

          PromoteTraits<ModelOfAlgebraicRing1, ModelOfAlgebraicRing2>::Promote c;

          c = a + b;

- A model of Algebraic Ring implements multiplication. The associated NumericTraits define a 'one' element, the type of the result of multiplication, and a type conversion function.

          ModelOfAlgebraicRing a, b;
          NumericTraits<ModelOfAlgebraicRing>::RealPromote c;

          ModelOfAlgebraicRing one = NumericTraits<ModelOfAlgebraicRing>::one();

          b *= a;
          c = a * b;
          c = a;
          a = NumericTraits<ModelOfAlgebraicRing>::fromRealPromote(c);

          assert(a * one == a);

### Algebraic Field

- A model of Algebraic Field implements AlgebraicRing as defined above.

- A model of Algebraic Field implements division. Division is undefined if and only if the right operand is 'zero'.

          ModelOfAlgebraicField a, b;
          typename NumericTraits<ModelOfAlgebraicField>::RealPromote c;

          ModelOfAlgebraicField zero = NumericTraits<ModelOfAlgebraicField>::zero();

          if(a != zero) b /= a;
          if(a != zero) c = b / a;

### Linear Space

- A model of Linear Space implements `Assignable`, `Default Constructible` and `Equality Comparable` as defined in the C++ standard (cf. the Standard Template Library documentation).

- A model of Algebraic Ring implements addition, subtraction and unary negation. The associated NumericTraits define a 'zero' element, the type of the result of addition and subtraction, and a type conversion function. Addition must be commutative. (This part of the requirements is identical to AlgebraicRing above.)

          ModelOfAlgebraicRing a, b;
          NumericTraits<ModelOfAlgebraicRing>::Promote c;

          ModelOfAlgebraicRing zero = NumericTraits<ModelOfAlgebraicRing>::zero();

          b += a;
          b -= a;
          b = -a;
          c = a + b;
          c = a - b;
          c = a;
          a = NumericTraits<ModelOfAlgebraicRing>::fromPromote(c);

          assert(a + zero == a);
          assert(a + b == b + a);
          assert(a - b == a + (-b));

- If mixed-type addition and subtraction are supported, PromoteTraits define the result type:

          ModelOfAlgebraicRing1 a;
          ModelOfAlgebraicRing2 b;

          PromoteTraits<ModelOfAlgebraicRing1, ModelOfAlgebraicRing2>::Promote c;

          c = a + b;

- A model of Algebraic Ring implements multiplication and division with 'double'. (Note that the outer product could be defined with an arbitrary model of AlgebraicField. For simplicity, VIGRA restricts this to only 'double'.) The associated NumericTraits define the type of the results, and a type conversion function.

          ModelOfAlgebraicRing a;
          double f;
          NumericTraits<ModelOfAlgebraicRing>::RealPromote c;

          a *= f;
          c = a * f;
          c = f * a;

          if(f != 0.0) a /= f;
          if(f != 0.0) c = a / f;

          c = a;
          a = NumericTraits<ModelOfAlgebraicRing>::fromRealPromote(c);

### Linear Algebra

- A model of Linear Algebra implements LinearSpace and AlgebraicRing as defined above.

### Division Algebra

- A model of Division Algebra implements LinearSpace and AlgebraicField as defined above.

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.9.0 (Tue Nov 6 2012)