File:  [CENS] / python / pyGiNaC / wrappers3 / mul_py.cpp
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Thu Apr 26 19:44:48 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Impl. pseries,ncmul. Preparing for a release.

/*
# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.4 $
# $Id: mul_py.cpp,v 1.4 2001-04-26 19:44:48 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.
#
*/
/*DT
  Mul
  ---

  >>> from ginac import mul,symbol,numeric,ex,is_mul,is_numeric
  >>> c = mul(symbol('a'),numeric(3,4))
  >>> c
  mul([symbol('a'), numeric('3/4')])
  >>> c.is_mul(), ex().is_mul()
  (1, 0)
  >>> d = mul(3,4)
  >>> d
  numeric('12')
  >>> is_numeric(d), is_mul(d), is_mul({})
  (1, 0, 0)
  >>> mul([])
  numeric('1')
  >>> mul(3)
  numeric('3')
  >>> mul([symbol('a'), numeric('3/4')])
  mul([symbol('a'), numeric('3/4')])
  >>> mul()
  numeric('1')
  >>> mul({})
  Traceback (most recent call last):
  ...
  TypeError: ex_from_ref() argument must be number|string|ex|sequence (got <type 'dictionary'>)
*/


#ifdef PYGINAC_DEFS
this_module.def(&mul_0, "mul");
this_module.def(&mul_1, "mul");
this_module.def(&mul_2ex, "mul");
this_module.def(&mul_2, "mul");
ex_class.def(&ex::is_mul, "is_mul");
this_module.def(&ex::is_mul, "is_mul");
this_module.def(&return_false, "is_mul");
#else

#ifdef PYGINAC_EX_PROTOS
#define PYGINAC_PROTOS
#endif

#ifdef PYGINAC_PROTOS

#ifdef PYGINAC_EX_PROTOS
bool is_mul(void) const;
#else // PYGINAC_EX_PROTOS
GiNaC::ex mul_0(void);
GiNaC::ex mul_1(const GiNaC::mul & e);
GiNaC::ex mul_2ex(const GiNaC::ex & l, const GiNaC::ex & r);
GiNaC::ex mul_2(py::ref l, py::ref r);
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
GiNaC::mul from_python (PyObject* o, py::type<const GiNaC::mul &>);
BOOST_PYTHON_END_CONVERSION_NAMESPACE
#endif // !PYGINAC_EX_PROTOS

#else  // PYGINAC_PROTOS
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
GiNaC::mul from_python (PyObject* o, py::type<const GiNaC::mul &>) {
  return GiNaC::mul(from_python(o, py::type<const GiNaC::exvector &>()));
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
/*F_DT is_mul(obj)
  Check if `obj' is mul.
*/
/*M_DT is_mul(self)
  Check if object is mul.
*/
bool ex::is_mul(void) const { return is_ex_exactly_of_type(*this, mul); }

/*F_DT mul(*args)
  mul() - return numeric('1').
  mul([]) - return numeric('1').
  mul(l,r) - multiply two expressions.
    If `l' and/or `r' are Python objects, they are converted to ex objects.
  mul(seq) - product of expressions in a sequence `seq'.
  mul(mul(...)) -> mul(...)
*/
GiNaC::ex mul_0(void) {
  return GiNaC::numeric(1);
}
GiNaC::ex mul_1(const GiNaC::mul & e) {
  return e;
}
GiNaC::ex mul_2ex(const GiNaC::ex & l, const GiNaC::ex & r) {
  return GiNaC::mul(l,r);
}
GiNaC::ex mul_2(py::ref l, py::ref r) {
  return GiNaC::mul(ex_from_ref(l), ex_from_ref(r));
}

#endif // !PYGINAC_PROTOS
#endif // !PYGINAC_DEFS




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