File:  [CENS] / python / pyGiNaC / wrappers / idx.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: idx.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 functions find_dummy_indices,count_dummy_indices,count_free_indices,
# index_set_difference,find_free_and_dummy.


depends = ['basic']
uses = ['ex']

#STARTPROTO

class idx(basic):
    """Holds one index of an indexed object.
    Indices can theoretically consist of any symbolic expression but
    they are usually only just a symbol (e.g. "mu", "i") or numeric
    (integer). Indices belong to a space with a certain numeric or
    symbolic dimension.
    """
    def __init__(self,value,dim):
        """idx(v,dim) - constructs index with given value and dimension.
    idx(ex(idx(...))) - returns idx(...)
    value  - Value of index (numeric or symbolic)
    dim    - Dimension of index space (numeric or symbolic)
    """
    def get_value(self):
        """Get value of index."""
    def get_dim(self):
        """Get dimension of index space."""
    def is_numeric(self):
        """Check whether the index is numeric."""
    def is_symbolic(self):
        """Check whether the index is symbolic."""
    def is_dim_numeric(self):
        """Check whether the dimension is numeric."""
    def is_dim_symbolic(self):
        """Check whether the dimension is symbolic."""
    def is_dummy_pair_same_type(self,other):
        """Check whether the index forms a dummy index pair with
    another index of the same type."""

class varidx(idx):
    """An index with a variance (co- or contravariant).
    There is an associated metric tensor that can be used to
    raise/lower indices. 
    """
    def __init__(self,value,dim,covariant=0):
        """varidx(v,dim,covariant) - constructs index with given value, dimension,
        and variance.
    varidx(ex(varidx(...))) - returns varidx(...)
    value     - Value of index (numeric or symbolic)
    dim       - Dimension of index space (numeric or symbolic)
    covariant - Make covariant index (default is contravariant)
    """
    def is_covariant(self):
        """Check whether the index is covariant."""
    def is_contravariant(self):
        """Check whether the index is contravariant."""
    def toggle_variance(self):
        """Returns a new index with the same value but the opposite variance."""

def is_dummy_pair(i1,i2):
    """Check whether two indices/expressions form a dummy pair."""

#ENDPROTO

wrapperclass = '''
class idx_w : public GiNaC::idx {
  PyObject * self;
public:
  idx_w(python::ref r) {
    DEBUG_C("idx_w(raw:ref)");
    PyErr_SetString(PyExc_NotImplementedError, "idx(raw:ref)");
    throw python::error_already_set();
  }
  idx_w(PyObject * self_, const GiNaC::ex & v, const GiNaC::ex & dim)
  : GiNaC::idx(v,dim), self(self_) {
    DEBUG_C("idx_w(ex,ex)");
  }
  idx_w(PyObject * self_, const GiNaC::idx & i)
  : GiNaC::idx(i), self(self_) {
    DEBUG_C("idx_w(ex)");
  }
  idx_w(PyObject * self_, const GiNaC::ex & i)
  : GiNaC::idx(ex_to_idx_w(i)), self(self_) {
    DEBUG_C("idx_w(ex)");
  }
  idx_w(PyObject * self_, python::ref v, python::ref dim)
  : GiNaC::idx(ex_w(v),ex_w(dim)), self(self_) {
    DEBUG_C("idx_w(ref,ref)");
  }
  ~idx_w() {
    DEBUG_C("idx_w::~idx_w()");
  }
};

inline long is_dummy_pair1_w(const GiNaC::idx & e1, const GiNaC::idx & e2) {
  return GiNaC::is_dummy_pair(e1,e2);
}
inline long is_dummy_pair2_w(python::ref e1, python::ref e2) {
  return GiNaC::is_dummy_pair(ex_w(e1),ex_w(e2));
}
/*
#ifdef PYGINAC_exvector
python::tuple find_free_and_dummy_w(python::ref obj) {
  GiNaC::exvector out_free = GiNaC::exvector(0);
  GiNaC::exvector out_dummy = GiNaC::exvector(0);
  GiNaC::find_free_and_dummy(as_exvector_w(obj),out_free,out_dummy);
  return python::tuple(out_free,out_dummy);
}
#endif
*/
'''

builder = '''
python::class_builder<idx_w> idx_w_class(this_module, "_idx_w");
python::class_builder<GiNaC::idx, idx_w> idx_class(this_module, "idx");
idx_py_class = python::as_object(idx_class.get_extension_class());
idx_class.declare_base(idx_w_class);
idx_class.declare_base(basic_class);
'''

constructors = '''
idx_class.def(python::constructor<const GiNaC::idx &>());
idx_class.def(python::constructor<const GiNaC::ex &>());
idx_class.def(python::constructor<const GiNaC::ex &,const GiNaC::ex>());
idx_class.def(python::constructor<python::ref, python::ref>());
'''

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

idx_class.def(&idx_w::get_value, "get_value");
idx_class.def(&idx_w::get_dim, "get_dim");
idx_class.def(&idx_w::is_numeric, "is_numeric");
idx_class.def(&idx_w::is_symbolic, "is_symbolic");
idx_class.def(&idx_w::is_dim_numeric, "is_dim_numeric");
idx_class.def(&idx_w::is_dim_symbolic, "is_dim_symbolic");
idx_class.def(&idx_w::is_dummy_pair_same_type, "is_dummy_pair_same_type");

this_module.def(is_dummy_pair1_w,"is_dummy_pair");
this_module.def(is_dummy_pair2_w,"is_dummy_pair");
/*
#ifdef PYGINAC_exvector
this_module.add(find_free_and_dummy_w ,"find_free_and_dummy");
#endif
*/
'''

implementation = '''
EX_TO_BASIC(idx)
'''

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