File:  [CENS] / python / pyGiNaC / wrappers3 / inifcns_py.cpp
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Apr 25 19:22:25 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Finished matrix, impl. lsolve, removed redudant Py_INCREF

/*
# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.2 $
# $Id: inifcns_py.cpp,v 1.2 2001-04-25 19:22:25 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
  Functions
  ---------

  >>> from ginac import abs,csgn,sin,cos,tan,exp,log,asin,acos,atan,atan2
  >>> from ginac import sinh,cosh,tanh,asinh,acosh,atanh
  >>> from ginac import Li2,Li3,zeta,lgamma,tgamma,psi
  >>> from ginac import factorial,binomial,Order,Derivative
  >>> from ginac import lsolve,symbol,lst,subs
  >>> s = [symbol('a'),symbol('b'),symbol('c')]
  >>> eqns = [s[0]+2*s[1]+3,s[1]-3*s[2]-5]
  >>> print lst(eqns)
  [3 + 2 * b + a, -5 - 3 * c + b]
  >>> print lsolve(eqns,s)
  [a == -13 - 6 * c, b == 5 + 3 * c, c == c]
  >>> print lsolve(eqns,s[:2])
  [a == -13 - 6 * c, b == 5 + 3 * c]
  >>> print lsolve(eqns,s[1:])
  [b == -3/2 - 1/2 * a, c == -13/6 - 1/6 * a]
  >>> sol = lsolve(eqns,s)
  >>> print subs(eqns, sol)
  [0, 0]
 */


#ifdef PYGINAC_DEFS
this_module.def(&abs_1, "abs");
this_module.def(&csgn_1, "csgn");
this_module.def(&sin_1, "sin");
this_module.def(&cos_1, "cos");
this_module.def(&tan_1, "tan");
this_module.def(&exp_1, "exp");
this_module.def(&log_1, "log");
this_module.def(&asin_1, "asin");
this_module.def(&acos_1, "acos");
this_module.def(&atan_1, "atan");
this_module.def(&atan2_2, "atan2");
this_module.def(&sinh_1, "sinh");
this_module.def(&cosh_1, "cosh");
this_module.def(&tanh_1, "tanh");
this_module.def(&asinh_1, "asinh");
this_module.def(&acosh_1, "acosh");
this_module.def(&atanh_1, "atanh");
this_module.def(&Li2_1, "Li2");
this_module.def(&Li3_1, "Li3");
this_module.def(&zeta_1, "zeta");
this_module.def(&zeta_2, "zeta");
this_module.def(&lgamma_1, "lgamma");
this_module.def(&tgamma_1, "tgamma");
this_module.def(&psi_1, "psi");
this_module.def(&psi_2, "psi");
this_module.def(&factorial_1, "factorial");
this_module.def(&binomial_2, "binomial");
this_module.def(&Order_1, "Order");
this_module.def(&Derivative_2, "Derivative");
this_module.def(&lsolve_2, "lsolve");
#else
#ifdef PYGINAC_EX_PROTOS
#define PYGINAC_PROTOS
#endif
#ifdef PYGINAC_PROTOS
#ifdef PYGINAC_EX_PROTOS

#else // PYGINAC_EX_PROTOS
GiNaC::ex abs_1(py::ref obj);
GiNaC::ex csgn_1(py::ref obj);
GiNaC::ex sin_1(py::ref obj);
GiNaC::ex cos_1(py::ref obj);
GiNaC::ex tan_1(py::ref obj);
GiNaC::ex exp_1(py::ref obj);
GiNaC::ex log_1(py::ref obj);
GiNaC::ex asin_1(py::ref obj);
GiNaC::ex acos_1(py::ref obj);
GiNaC::ex atan_1(py::ref obj);
GiNaC::ex atan2_2(py::ref obj1, py::ref obj2);
GiNaC::ex sinh_1(py::ref obj);
GiNaC::ex cosh_1(py::ref obj);
GiNaC::ex tanh_1(py::ref obj);
GiNaC::ex asinh_1(py::ref obj);
GiNaC::ex acosh_1(py::ref obj);
GiNaC::ex atanh_1(py::ref obj);
GiNaC::ex Li2_1(py::ref obj);
GiNaC::ex Li3_1(py::ref obj);
GiNaC::ex zeta_1(py::ref obj);
GiNaC::ex zeta_2(py::ref obj, py::ref nth);
GiNaC::ex tgamma_1(py::ref obj);
GiNaC::ex lgamma_1(py::ref obj);
GiNaC::ex psi_1(py::ref obj);
GiNaC::ex psi_2(py::ref obj, py::ref nth);
GiNaC::ex factorial_1(py::ref obj);
GiNaC::ex binomial_2(py::ref obj1, py::ref obj2);
GiNaC::ex Order_1(py::ref obj);
GiNaC::ex Derivative_2(const GiNaC::function & f, const GiNaC::lst & l);
GiNaC::ex lsolve_2(const GiNaC::lst & eqns, const GiNaC::lst & syms);
#endif // !PYGINAC_EX_PROTOS
#else  // PYGINAC_PROTOS
#define PYGINAC_FUNC_1P(NAME) \
GiNaC::ex NAME##_1(py::ref obj) { \
  return GiNaC::NAME(ex_from_ref(obj)); \
}
#define PYGINAC_FUNC_2P(NAME) \
GiNaC::ex NAME##_2(py::ref obj1, py::ref obj2) { \
  return GiNaC::NAME(ex_from_ref(obj1), ex_from_ref(obj2)); \
}

/*F_DT abs(x)
  Absolute value. */
PYGINAC_FUNC_1P(abs);

/*F_DT csgn(x)
  Complex sign. */
PYGINAC_FUNC_1P(csgn);

/*F _DT Eta function: log(a*b) == log(a) + log(b) + eta(a, b). */
PYGINAC_FUNC_2P(eta);

/*F_DT sin(x)
  Sine. */
PYGINAC_FUNC_1P(sin);

/*F_DT cos(x)
  Cosine. */
PYGINAC_FUNC_1P(cos);

/*F_DT tan(x)
  Tangent. */
PYGINAC_FUNC_1P(tan);

/*F_DT exp(x)
  Exponential function. */
PYGINAC_FUNC_1P(exp);

/*F_DT log(x)
  Natural logarithm. */
PYGINAC_FUNC_1P(log);

/*F_DT asin(x)
  Inverse sine (arc sine). */
PYGINAC_FUNC_1P(asin);

/*F_DT acos(x)
  Inverse cosine (arc cosine). */
PYGINAC_FUNC_1P(acos);

/*F_DT atan(x)
  Inverse tangent (arc tangent). */
PYGINAC_FUNC_1P(atan);

/*F_DT atan2(x,y)
  Inverse tangent with two arguments. */
PYGINAC_FUNC_2P(atan2);

/*F_DT sinh(x)
  Hyperbolic Sine. */
PYGINAC_FUNC_1P(sinh);

/*F_DT cosh(x)
  Hyperbolic Cosine. */
PYGINAC_FUNC_1P(cosh);

/*F_DT tanh(x)
  Hyperbolic Tangent. */
PYGINAC_FUNC_1P(tanh);

/*F_DT asinh(x)
  Inverse hyperbolic Sine (area hyperbolic sine). */
PYGINAC_FUNC_1P(asinh);

/*F_DT acosh(x)
  Inverse hyperbolic Cosine (area hyperbolic cosine). */
PYGINAC_FUNC_1P(acosh);

/*F_DT atanh(x)
  Inverse hyperbolic Tangent (area hyperbolic tangent). */
PYGINAC_FUNC_1P(atanh);

/*F_DT Li2(x)
  Dilogarithm. */
PYGINAC_FUNC_1P(Li2);

/*F_DT Li3(x)
  Trilogarithm. */
PYGINAC_FUNC_1P(Li3);

/*F_DT zeta(x, nth=0)
  Riemann's Zeta-function and its derivatives. */
PYGINAC_FUNC_1P(zeta);

GiNaC::ex zeta_2(py::ref obj, py::ref nth) {
  return GiNaC::zeta(ex_from_ref(nth), ex_from_ref(obj));
}

/*F_DT lgamma(x)
  Gamma-function. */
PYGINAC_FUNC_1P(lgamma);

/*F_DT tgamma(x)
  Gamma-function. */
PYGINAC_FUNC_1P(tgamma);

/*F_DT psi(x, nth=0)
    Psi-function (aka digamma-function) and its derivatives. */
PYGINAC_FUNC_1P(psi);

GiNaC::ex psi_2(py::ref obj, py::ref nth) {
  return GiNaC::psi(ex_from_ref(nth), ex_from_ref(obj));
}

/*F_DT factorial(x)
  Factorial function. */
PYGINAC_FUNC_1P(factorial);

/*F_DT binomial(n, k)
  Binomial function. */
PYGINAC_FUNC_2P(binomial);

/*F_DT Order(x)
  Order term function (for truncated power series). */
PYGINAC_FUNC_1P(Order);

/*F_DT Derivative(f, l)
  Inert partial differentiation operator. */
GiNaC::ex Derivative_2(const GiNaC::function & f, const GiNaC::lst & l) {
  return GiNaC::Derivative(f, l);
}
/*F_DT lsolve(eqns,syms)
  Solve linear system.
  eqns - list of expressions or/and ex(relational) objects.
  syms - list of symbols.
  Return solution as a GiNaC list of ex(relational) objects.
  If sol = lsolve(eqns,syms), then subs(eqns, sol) returns list of zeros.
 */
GiNaC::ex lsolve_2(const GiNaC::lst & eqns, const GiNaC::lst & syms) {
  GiNaC::exlist eq(0);
  for (unsigned i=0; i<eqns.nops(); ++i)
    if (is_ex_exactly_of_type(eqns.op(i), relational))
      eq.push_back(eqns.op(i));
    else
      eq.push_back(GiNaC::ex(GiNaC::relational(eqns.op(i),GiNaC::numeric())));
  return GiNaC::lsolve(GiNaC::lst(eq,true),syms);
}
#endif // !PYGINAC_PROTOS
#endif // !PYGINAC_DEFS




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