File:  [CENS] / python / pyGiNaC / wrappers / indexed.py
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Wed Apr 11 20:31:30 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Exposed lots of functions. Documented most important classes/functions. minor_version = 2

# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.3 $
# $Id: indexed.py,v 1.3 2001-04-11 20:31:30 pearu Exp $
#
# Copyright 2001 Pearu Peterson all rights reserved,
# Pearu Peterson <pearu@cens.ioc.ee>
# Permission to use, modify, and distribute this software is given under the
# terms of the LGPL.  See http://www.fsf.org
#
# NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
#
# TODO:
# Expose function simplify_indexed


depends = ['basic']

uses = ['ex','exvector','idx']



#STARTPROTO

class indexed(exprseq):
    """An indexed expression.
    It consists of a 'base' expression (the expression being indexed)
    which can be accessed as op(0), and n (n >= 0) indices (all of
    class idx), accessible as op(1)..op(n).
"""
    def __init__(self,base,*args):
        """indexed(b) - constructs indexed object with no index.
    indexed(b,i1) - constructs indexed object with one index.
    indexed(b,i1,i2) - constructs indexed object with two indices.
    indexed(b,i1,i2,i3) - constructs indexed object with three indices.
    indexed(b,i1,i2,i3,i4) - constructs indexed object with four indices.
    indexed(b,iv) - construct indexed object with a specified vector of indices.
    indexed(b,symm,i1,i2) - construct indexed object with two indices
        and a specified symmetry.
    indexed(b,symm,i1,i2,i3) - construct indexed object with four indices
        and a specified symmetry.
    indexed(b,symm,i1,i2,i3,i4) - construct indexed object with four indices
        and a specified symmetry.
    indexed(b,symm,iv) - construct indexed object with a specified vector of indices
        and a specified symmetry.
    indexed(symm,seq)
    
    b - Base expression
    i1 - First index.
    i2 - Second index.
    i3 - Third index.
    i4 - Fourth index.
    symm - Symmetry of indices.

    Valid symmetry values are indexed.[unknown,symmetric,antisymmetric,mixed]
    """
    def get_indices(self):
        """Return an exvector containing the object's indices."""
    def get_dummy_indices(self, other=None):
        """Return a vector containing the dummy indices ...
    other is None:   ... of the object, if any.
    otherwise:       ... in the contraction with another indexed object.
    """

def simplify_indexed(e, sp=None):
    """Simplify/canonicalize expression containing indexed objects. This
    performs contraction of dummy indices where possible and checks whether
    the free indices in sums are consistent.
    And automatically replaces scalar products by known values if desired.
    [NotImplemented]
    """

class color(indexed):
    """Holds a generator T_a or the unity element of the Lie algebra
    of SU(3), as used for calculations in quantum chromodynamics.

    A representation label (an unsigned integer) is used to
    distinguish elements from different Lie algebra representations
    (only objects with the same label "interact" with each
    other). These objects implement an abstract representation of the
    group, not a specific matrix representation. The indices used for
    color objects should not have a variance.    
    """
    def __init__(self,base,*args):
        """color(base,rl=0) - construct object with no index.
    color(base,i1,rl=0) - construct object with one color index.
    color(rl,v)
    This constructor is for internal use only. Use the
    color_T() function instead.
    """

def color_ONE(rl=0):
    """Create the su(3) unity element. This is an indexed object,
    although it has no indices.
    rl - Representation label.
    Returns newly constructed unity element.
    """
def color_T(a,rl=0):
    """Create an su(3) generator.
    a   - Index
    rl  - Representation label
    Returns newly constructed unity generator.
    """
def color_f(a,b,c):
    """Create an su(3) antisymmetric structure constant.
    a First index
    b Second index
    c Third index
    Returns newly constructed structure constant.
    """
def color_d(a,b,c):
    """Create an su(3) symmetric structure constant.
    a First index
    b Second index
    c Third index
    Returns newly constructed structure constant.
    """
def color_h(a,b,c):
    """This returns the linear combination d.a.b.c+I*f.a.b.c."""

class clifford(indexed):
    """Holds an object representing an element of the Clifford algebra
    (the Dirac gamma matrices).
    These objects only carry Lorentz indices. Spinor indices are hidden.
    """
    def __init__(self,base,mu=None):
        """clifford(base) - construct object without any indices.
    clifford(base,mu)
    clifford(v)
    This constructor is for internal use only. Use the dirac_one()
    function instead.
    """

def dirac_one():
    """Create a Clifford unity object.
    Returns newly constructed object.
    """
def dirac_gamma(mu):
    """Create a Dirac gamma object.
    mu    - Index (must be of class varidx or a derived class).
    Returns newly constructed gamma object.
    """

#ENDPROTO


wrapperclass = '''

static GiNaC::indexed ex_to_indexed_or_ex_w(const GiNaC::ex &);

class indexed_w : public GiNaC::indexed {
  PyObject * self;
public:
  indexed_w(python::ref v)
  : GiNaC::indexed(ex_w(v)) {
    DEBUG_C("indexed_w(raw:ref)");
  }
  indexed_w(PyObject * self_, const GiNaC::ex & m)
  : GiNaC::indexed(ex_to_indexed_or_ex_w(m)), self(self_) {
    DEBUG_C("indexed_w(ex(indexed|*))");
  }
  indexed_w(PyObject * self_, const GiNaC::basic & m)
  : GiNaC::indexed(ex_to_indexed_or_ex_w(GiNaC::ex(m))), self(self_) {
    DEBUG_C("indexed_w(basic)");
  }
  indexed_w(PyObject * self_, python::ref m)
  : GiNaC::indexed(ex_w(m)), self(self_) {
    DEBUG_C("indexed_w(ref)");
  }
  indexed_w(PyObject * self_, python::ref b, python::ref iv)
  : GiNaC::indexed(ex_w(b),exvector_w(iv)), self(self_) {
    DEBUG_C("indexed_w(ref,ref)");
  }
  indexed_w(PyObject * self_, python::ref b, python::ref i1, python::ref i2)
  : GiNaC::indexed(ex_w(b),ex_w(i1),ex_w(i2)), self(self_) {
    DEBUG_C("indexed_w(ref,2*ref)");
  }
  indexed_w(PyObject * self_, python::ref b, python::ref i1, python::ref i2, python::ref i3)
  : GiNaC::indexed(ex_w(b),ex_w(i1),ex_w(i2),ex_w(i3)), self(self_) {
    DEBUG_C("indexed_w(ref,3*ref)");
  }
  indexed_w(PyObject * self_, python::ref b, python::ref i1, python::ref i2, python::ref i3, python::ref i4)
  : GiNaC::indexed(ex_w(b),ex_w(i1),ex_w(i2),ex_w(i3),ex_w(i4)), self(self_) {
    DEBUG_C("indexed_w(ref,4*ref)");
  }
  indexed_w(PyObject * self_, python::ref b, symmetry_type symm, python::ref iv)
  : GiNaC::indexed(ex_w(b),symm, exvector_w(iv)), self(self_) {
    DEBUG_C("indexed_w(ref,symm,ref)");
  }
  indexed_w(PyObject * self_, python::ref b, symmetry_type symm, python::ref i1, python::ref i2)
  : GiNaC::indexed(ex_w(b),symm, ex_w(i1), ex_w(i2)), self(self_) {
    DEBUG_C("indexed_w(ref,symm,2*ref)");
  }
  indexed_w(PyObject * self_, python::ref b, symmetry_type symm, python::ref i1, python::ref i2, python::ref i3)
  : GiNaC::indexed(ex_w(b),symm, ex_w(i1), ex_w(i2), ex_w(i3)), self(self_) {
    DEBUG_C("indexed_w(ref,symm,3*ref)");
  }
  indexed_w(PyObject * self_, python::ref b, symmetry_type symm, python::ref i1, python::ref i2, python::ref i3, python::ref i4)
  : GiNaC::indexed(ex_w(b),symm, ex_w(i1), ex_w(i2), ex_w(i3), ex_w(i4)), self(self_) {
    DEBUG_C("indexed_w(ref,symm,4*ref)");
  }
  ~indexed_w() {
    DEBUG_C("indexed_w::~indexed_w()");
  }
  inline GiNaC::indexed::symmetry_type get_symmetry(void) const { return this->symmetry; }
  inline GiNaC::exvector get_dummy_indices0_w(void) const {return this->get_dummy_indices(); }
  inline GiNaC::exvector get_dummy_indices1_w(python::ref other) const {return this->get_dummy_indices(indexed_w(other)); }

};
template class python::enum_as_int_converters<GiNaC::indexed::symmetry_type>;

'''

builder = '''
python::class_builder<indexed_w> indexed_w_class(this_module, "_indexed_w");
python::class_builder<GiNaC::indexed, indexed_w> indexed_class(this_module, "indexed");
indexed_py_class = python::as_object(indexed_class.get_extension_class());
indexed_class.declare_base(indexed_w_class);
indexed_class.declare_base(basic_class);
'''

constructors = '''
indexed_class.def(python::constructor<const GiNaC::basic &>());
indexed_class.def(python::constructor<const GiNaC::ex &>());
indexed_class.def(python::constructor<python::ref>());
indexed_class.def(python::constructor<python::ref, GiNaC::indexed::symmetry_type, python::ref>());
indexed_class.def(python::constructor<python::ref, GiNaC::indexed::symmetry_type, python::ref, python::ref>());
indexed_class.def(python::constructor<python::ref, GiNaC::indexed::symmetry_type, python::ref, python::ref, python::ref>());
indexed_class.def(python::constructor<python::ref, GiNaC::indexed::symmetry_type, python::ref, python::ref, python::ref, python::ref>());
indexed_class.def(python::constructor<python::ref, python::ref>());
indexed_class.def(python::constructor<python::ref, python::ref, python::ref>());
indexed_class.def(python::constructor<python::ref, python::ref, python::ref, python::ref>());
indexed_class.def(python::constructor<python::ref, python::ref, python::ref, python::ref, python::ref>());


'''

defs = '''
indexed_class.def(&basic_w::python_str, "__str__");
indexed_class.def(&basic_w::python_repr, "__repr__");

             
indexed_class.def(&indexed_w::all_index_values_are, "all_index_values_are");
indexed_class.def(&indexed_w::get_indices, "get_indices");
indexed_class.def(&indexed_w::get_dummy_indices0_w, "get_dummy_indices");
indexed_class.def(&indexed_w::get_dummy_indices1_w, "get_dummy_indices");

indexed_class.add(PyInt_FromLong(indexed_w::unknown), "unknown");
indexed_class.add(PyInt_FromLong(indexed_w::symmetric), "symmetric");
indexed_class.add(PyInt_FromLong(indexed_w::antisymmetric), "antisymmetric");
indexed_class.add(PyInt_FromLong(indexed_w::mixed), "mixed");
'''

protos = '''
'''

implementation = '''
EX_TO_BASIC(indexed)

static GiNaC::indexed ex_to_indexed_or_ex_w(const GiNaC::ex & ib) {
  if (is_ex_exactly_of_type(ib, indexed))
    return GiNaC::ex_to_indexed(ib);
  else
    return GiNaC::indexed(ib);
}
'''

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>