X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fbasic.cpp;h=fb73096fa70a4796e301ade46306d53849d25068;hp=f8839db976a87b9c456ded4c8521b761cb176c1e;hb=b3f0d2416a7a0195446e410ebba10ec2c51cbd37;hpb=b11c30cf00d90113c924e4a96e8fed0341c246c6 diff --git a/ginac/basic.cpp b/ginac/basic.cpp index f8839db9..fb73096f 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's ABC. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,30 +34,28 @@ #include "lst.h" #include "ncmul.h" #include "relational.h" +#include "wildcard.h" #include "print.h" #include "archive.h" #include "utils.h" -#include "debugmsg.h" namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(basic, void) ////////// -// default ctor, dtor, copy ctor assignment operator and helpers +// default ctor, dtor, copy ctor, assignment operator and helpers ////////// // public basic::basic(const basic & other) : tinfo_key(TINFO_basic), flags(0), refcount(0) { - debugmsg("basic copy ctor", LOGLEVEL_CONSTRUCT); copy(other); } const basic & basic::operator=(const basic & other) { - debugmsg("basic operator=", LOGLEVEL_ASSIGNMENT); if (this != &other) { destroy(true); copy(other); @@ -82,8 +80,6 @@ const basic & basic::operator=(const basic & other) /** Construct object from archive_node. */ basic::basic(const archive_node &n, const lst &sym_lst) : flags(0), refcount(0) { - debugmsg("basic ctor from archive_node", LOGLEVEL_CONSTRUCT); - // Reconstruct tinfo_key from class name std::string class_name; if (n.find_string("class", class_name)) @@ -101,12 +97,6 @@ void basic::archive(archive_node &n) const n.add_string("class", class_name()); } -////////// -// functions overriding virtual functions from bases classes -////////// - -// none - ////////// // new virtual functions which can be overridden by derived classes ////////// @@ -119,8 +109,6 @@ void basic::archive(archive_node &n) const * level for placing parentheses and formatting */ void basic::print(const print_context & c, unsigned level) const { - debugmsg("basic print", LOGLEVEL_PRINT); - if (is_of_type(c, print_tree)) { c.s << std::string(level, ' ') << class_name() @@ -166,7 +154,6 @@ unsigned basic::precedence(void) const * construction of an ex from a basic. */ basic * basic::duplicate() const { - debugmsg("basic duplicate",LOGLEVEL_DUPLICATE); return new basic(*this); } @@ -202,9 +189,9 @@ ex & basic::let_op(int i) ex basic::operator[](const ex & index) const { - if (is_exactly_of_type(*index.bp,numeric)) - return op(static_cast(*index.bp).to_int()); - + if (is_ex_exactly_of_type(index,numeric)) + return op(ex_to(index).to_int()); + throw(std::invalid_argument("non-numeric indices not supported by this type")); } @@ -219,9 +206,8 @@ ex basic::operator[](int i) const * but e.has(x+y) is false. */ bool basic::has(const ex & pattern) const { - GINAC_ASSERT(pattern.bp!=0); lst repl_lst; - if (match(*pattern.bp, repl_lst)) + if (match(pattern, repl_lst)) return true; for (unsigned i=0; i(s)) ? 1 : 0; } /** Return degree of lowest power in object s. */ int basic::ldegree(const ex & s) const { - return 0; + return is_equal(ex_to(s)) ? 1 : 0; } /** Return coefficient of degree n in object s. */ ex basic::coeff(const ex & s, int n) const { - return n==0 ? *this : _ex0(); + if (is_equal(ex_to(s))) + return n==1 ? _ex1 : _ex0; + else + return n==0 ? *this : _ex0; } /** Sort expanded expression in terms of powers of some object(s). @@ -301,7 +290,7 @@ ex basic::collect(const ex & s, bool distributed) const while (true) { // Calculate coeff*x1^c1*...*xn^cn - ex y = _ex1(); + ex y = _ex1; for (int i=0; i(repl_lst.op(i).op(1))); } repl_lst.append(pattern == *this); return true; @@ -485,7 +474,7 @@ bool basic::match(const ex & pattern, lst & repl_lst) const } else { // Expression must be of the same type as the pattern - if (tinfo() != pattern.bp->tinfo()) + if (tinfo() != ex_to(pattern).tinfo()) return false; // Number of subexpressions must match @@ -495,10 +484,10 @@ bool basic::match(const ex & pattern, lst & repl_lst) const // No subexpressions? Then just compare the objects (there can't be // wildcards in the pattern) if (nops() == 0) - return is_equal_same_type(*pattern.bp); + return is_equal_same_type(ex_to(pattern)); // Check whether attributes that are not subexpressions match - if (!match_same_type(*pattern.bp)) + if (!match_same_type(ex_to(pattern))) return false; // Otherwise the subexpressions must match one-to-one @@ -519,14 +508,14 @@ ex basic::subs(const lst & ls, const lst & lr, bool no_pattern) const if (no_pattern) { for (unsigned i=0; i(ls.op(i)))) return lr.op(i); } } else { for (unsigned i=0; isubs(repl_lst, true); // avoid infinite recursion when re-substituting the wildcards + if (match(ex_to(ls.op(i)), repl_lst)) + return lr.op(i).subs(repl_lst, true); // avoid infinite recursion when re-substituting the wildcards } } @@ -586,7 +575,7 @@ struct derivative_map_function : public map_function { ex basic::derivative(const symbol & s) const { if (nops() == 0) - return _ex0(); + return _ex0; else { derivative_map_function map_derivative(s); return map(map_derivative); @@ -681,7 +670,7 @@ ex basic::expand(unsigned options) const return (options == 0) ? setflag(status_flags::expanded) : *this; else { expand_map_function map_expand(options); - return map(map_expand).bp->setflag(options == 0 ? status_flags::expanded : 0); + return ex_to(map(map_expand)).setflag(options == 0 ? status_flags::expanded : 0); } }