From: Christian Bauer Date: Tue, 18 Dec 2001 18:48:06 +0000 (+0000) Subject: - input parser recognizes "sqrt()", which is also used in the output X-Git-Tag: release_1-0-2~6 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=7bb797bc41e31fe098c94f0b5e57ddbba6cd26b6;ds=sidebyside - input parser recognizes "sqrt()", which is also used in the output - divide(a,b,q) only modifies q if the division succeeds; also, divide(a,b,a) works now - fixed small bug in dummy index renaming which could cause it to not recognize renamable indices in some cases - power::degree() and power::ldegree() throw an exception when encountering a non-integer exponent --- diff --git a/NEWS b/NEWS index b2ad1a42..7ca5aeb9 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,14 @@ This file records noteworthy changes. +1.0.2 () +* Input parser recognizes "sqrt()", which is also used in the output +* divide(a,b,q) only modifies q if the division succeeds; also, divide(a,b,a) + works now +* Fixed small bug in dummy index renaming which could cause it to not + recognize renamable indices in some cases +* power::degree() and power::ldegree() throw an exception when encountering + a non-integer exponent + 1.0.1 (22 November 2001) * Function sqrfree() handles a few more cases now. * Class relational has real canonical ordering now. diff --git a/ginac/flags.h b/ginac/flags.h index b7f6222d..4c4f7729 100644 --- a/ginac/flags.h +++ b/ginac/flags.h @@ -72,7 +72,7 @@ public: enum { dynallocated = 0x0001, ///< Heap-allocated (i.e. created by new if we want to be clever and bypass the stack, @see ex::construct_from_basic() ) evaluated = 0x0002, ///< .eval() has already done its job - expanded = 0x0004, ///< .expand() has already done its job + expanded = 0x0004, ///< .expand(0) has already done its job (other expand() options ignore this flag) hash_calculated = 0x0008 ///< .calchash() has already done its job }; }; diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index bc474f3d..87f53db3 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -539,7 +539,6 @@ static ex rename_dummy_indices(const ex & e, exvector & global_dummy_indices, ex } it++; } - shaker_sort(global_dummy_indices.begin(), global_dummy_indices.end(), ex_is_less(), ex_swap()); // If this is the first set of local indices, do nothing if (old_global_size == 0) @@ -554,6 +553,7 @@ static ex rename_dummy_indices(const ex & e, exvector & global_dummy_indices, ex shaker_sort(local_syms.begin(), local_syms.end(), ex_is_less(), ex_swap()); for (unsigned i=0; i($1).get_name(), $3.nops()); - $$ = function(i, ex_to($3)).eval(1); + string n = ex_to($1).get_name(); + if (n == "sqrt") { + if ($3.nops() != 1) + throw (std::runtime_error("too many arguments to sqrt()")); + $$ = sqrt($3.op(0)); + } else { + unsigned i = function::find_function(n, $3.nops()); + $$ = function(i, ex_to($3)).eval(1); + } } | exp T_EQUAL exp {$$ = $1 == $3;} | exp T_NOTEQ exp {$$ = $1 != $3;} diff --git a/ginac/normal.cpp b/ginac/normal.cpp index ee278681..a161f821 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -581,14 +581,15 @@ ex sprem(const ex &a, const ex &b, const symbol &x, bool check_args) * @param check_args check whether a and b are polynomials with rational * coefficients (defaults to "true") * @return "true" when exact division succeeds (quotient returned in q), - * "false" otherwise */ + * "false" otherwise (q left untouched) */ bool divide(const ex &a, const ex &b, ex &q, bool check_args) { - q = _ex0; if (b.is_zero()) throw(std::overflow_error("divide: division by zero")); - if (a.is_zero()) + if (a.is_zero()) { + q = _ex0; return true; + } if (is_ex_exactly_of_type(b, numeric)) { q = a / b; return true; @@ -611,8 +612,10 @@ bool divide(const ex &a, const ex &b, ex &q, bool check_args) // Polynomial long division (recursive) ex r = a.expand(); - if (r.is_zero()) + if (r.is_zero()) { + q = _ex0; return true; + } int bdeg = b.degree(*x); int rdeg = r.degree(*x); ex blcoeff = b.expand().coeff(*x, bdeg); diff --git a/ginac/power.cpp b/ginac/power.cpp index 58913a8b..78c9c969 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -238,8 +238,10 @@ int power::degree(const ex & s) const return ex_to(exponent).to_int(); else return basis.degree(s) * ex_to(exponent).to_int(); - } - return 0; + } else if (basis.has(s)) + throw(std::runtime_error("power::degree(): undefined degree because of non-integer exponent")); + else + return 0; } int power::ldegree(const ex & s) const @@ -249,8 +251,10 @@ int power::ldegree(const ex & s) const return ex_to(exponent).to_int(); else return basis.ldegree(s) * ex_to(exponent).to_int(); - } - return 0; + } else if (basis.has(s)) + throw(std::runtime_error("power::ldegree(): undefined degree because of non-integer exponent")); + else + return 0; } ex power::coeff(const ex & s, int n) const