## [Reduce-algebra-developers] Abs operator and domain elements

 [Reduce-algebra-developers] Abs operator and domain elements From: Rainer Schöpf - 2013-02-07 21:23:55 ```The recent bug report https://sourceforge.net/p/reduce-algebra/bugs/44/ unconvered a problem with the abs operator: Applying the abs operator to certain domain elements yields inconsistent results, e.g. for domain mode ps or atensor. -------------------------------------------- 1: load atensor; 2: tensor a2; 3: a2(k,k); a2(k,k) 4: abs(ws); a2(k,k) 5: abs(-ws); - a2(k,k) -------------------------------------------- The reason: all domain elements of type ps or atensor are considered positive (by virtue of the corresponding "minusp" function), so that abs always returns its argument. For ps, taking the sign of the constant term of a power series as "sign" of the whole series might be a solution. In general, the only solution I can think of is to add an optional "abs" property to a domain mode, pointing to a function that returns a sensible result (or an error). Rainer ```

 [Reduce-algebra-developers] Abs operator and domain elements From: Rainer Schöpf - 2013-02-07 21:23:55 ```The recent bug report https://sourceforge.net/p/reduce-algebra/bugs/44/ unconvered a problem with the abs operator: Applying the abs operator to certain domain elements yields inconsistent results, e.g. for domain mode ps or atensor. -------------------------------------------- 1: load atensor; 2: tensor a2; 3: a2(k,k); a2(k,k) 4: abs(ws); a2(k,k) 5: abs(-ws); - a2(k,k) -------------------------------------------- The reason: all domain elements of type ps or atensor are considered positive (by virtue of the corresponding "minusp" function), so that abs always returns its argument. For ps, taking the sign of the constant term of a power series as "sign" of the whole series might be a solution. In general, the only solution I can think of is to add an optional "abs" property to a domain mode, pointing to a function that returns a sensible result (or an error). Rainer ```
 Re: [Reduce-algebra-developers] Abs operator and domain elements From: Alan Barnes - 2013-02-09 11:07:55 ```Regarding the 'feature' when the operator abs is applied to ps domain elements, I agree with Rainer that taking the sign of the coefficient of the lowest order term would be a quick fix when the coefficient is numeric. When the coefficient is algebraic, abs could simply return abs of its argument as it does for 'normal' algebraic expressions . Alternatively abs could simply return abs of its argument; correct but not very useful! The first approach would have the desirable property that abs(ps1*ps2) = abs(ps1)*abs(ps2) but, of course, evaluations of the resulting power series at even 'small' values of the expansion variable would not necessarily be positive. When the ps package was written (was it really 26 years ago?), the ideas of representing power series by domain elements and using simulated lazy evaluation (so that the series were extendible) were experimental. Prior to that domain elements were always constant. The experiment was, I think, only moderately successful and if I were writing the package now, I would use some other representation (but retain the lazy evaluation approach). Although the ps code works reasonably well when the underlying domain is constant (rational, complex, complex rational etc), the idea of representing a bivariate power series as a univariate power series over a univariate power series domain (etc.) opened a 'can of worms' as there is no support in Reduce for parameterised domains. Alan Barnes On 07/02/2013 21:23, Rainer Schöpf wrote: > The recent bug report > > https://sourceforge.net/p/reduce-algebra/bugs/44/ > > unconvered a problem with the abs operator: Applying the abs operator to certain > domain elements yields inconsistent results, e.g. for domain mode ps or atensor. > > -------------------------------------------- > 1: load atensor; > 2: tensor a2; > > 3: a2(k,k); > > a2(k,k) > > 4: abs(ws); > > a2(k,k) > > 5: abs(-ws); > > - a2(k,k) > -------------------------------------------- > > The reason: all domain elements of type ps or atensor are considered positive > (by virtue of the corresponding "minusp" function), so that abs always returns > its argument. > > For ps, taking the sign of the constant term of a power series as "sign" of the > whole series might be a solution. > > In general, the only solution I can think of is to add an optional "abs" > property to a domain mode, pointing to a function that returns a sensible result > (or an error). > > Rainer > > ------------------------------------------------------------------------------ > Free Next-Gen Firewall Hardware Offer > Buy your Sophos next-gen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophos-d2d-feb > _______________________________________________ > Reduce-algebra-developers mailing list > Reduce-algebra-developers@... > https://lists.sourceforge.net/lists/listinfo/reduce-algebra-developers > ```
 Re: [Reduce-algebra-developers] Abs operator and domain elements From: Rainer Schöpf - 2013-02-12 08:51:46 ```On Sat, 9 Feb 2013 at 10:52 -0000, Alan Barnes wrote: > Regarding the 'feature' when the operator abs is applied to ps domain > elements, I agree with Rainer that taking the sign of the coefficient of > the lowest order term would be a quick fix when the coefficient is > numeric. When the coefficient is algebraic, abs could simply return abs > of its argument as it does for 'normal' algebraic expressions . The problem is that the current code for computing the absolute value of a domain element uses the only interface the domain mode code offers: a function returning t when a domain element is positive, nil otherwise. This approach doesn't really work for non-constant domain elements. So, yes, the quick fix works for the case in question, but it requires already a couple of changes to the tps code to make that one example work. I'm not sure what other places in the code there are that might be affected. > Alternatively abs could simply return abs of its argument; correct but > not very useful! Yes, but what can one do in general? The more I think about this, the more I believe that "abs" is another special case that needs its own (optional) domain mode function, like for "expt". It is then the responsibility of the specific domain element code to compute the absolute value of a domain element. It might even be a good idea to have a "constant/nonconstant" flag for a domain mode. To give one reason: the function constant_exprp returns t for an integer argument, but nil for a constant domaion element like (!:rd!: . 1.0) . Rainer ```