[GiNaC-devel] Simplifying powers

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Wed Aug 7 21:44:19 CEST 2013


Hi, Vladimir,

I've got a few comments regarding the mul::info() patches.

> diff --git a/ginac/mul.cpp b/ginac/mul.cpp
> index cee5cd7..3ec279d 100644
> --- a/ginac/mul.cpp
> +++ b/ginac/mul.cpp
> @@ -307,6 +307,11 @@ bool mul::info(unsigned inf) const
>  		}
>  		case info_flags::positive:
>  		case info_flags::negative: {
> +			if ((inf==info_flags::positive) && (flags & status_flags::is_positive))
> +				return true;
> +			else if ((inf==info_flags::negative) && (flags & status_flags::is_negative))
> +				return true;
> +

Perhaps we can add

if (flags & status_flags::purely_indefinite)
	return false;

>  			bool pos = true;
>  			epvector::const_iterator i = seq.begin(), end = seq.end();
>  			while (i != end) {
> @@ -320,9 +325,12 @@ bool mul::info(unsigned inf) const
>  			}
>  			if (overall_coeff.info(info_flags::negative))
>  				pos = !pos;
> +			flags |= (pos? status_flags::is_positive : status_flags::is_negative);
>  			return (inf ==info_flags::positive? pos : !pos);
>  		}
>  		case info_flags::nonnegative: {
> +			if  (flags & status_flags::is_positive)
> +				return true;
>  			bool pos = true;
>  			epvector::const_iterator i = seq.begin(), end = seq.end();
>  			while (i != end) {
> @@ -373,6 +381,9 @@ bool mul::info(unsigned inf) const
>  				return false;
>  			return pos; 
>  		}
> +		case info_flags::indefinite: {
> +			return (flags & status_flags::purely_indefinite);

The proper calculation of purely_indefinite flag is missing (the flag is set
only by power::expand()), so mul::info(info_flags::indefinite) returns false
more often than not. For instance

symbol x("x"), y("y");
ex e = x*y;
if (!e.info(info_flags::indefinite)) {
	std::cerr << "Oops" << std::endl;
}

Best regards,
	Alexei




More information about the GiNaC-devel mailing list