[NOTE: I mistakenly sent several replies to individuals rather than to the group. Several are moot, but I did not want to leave them off-list. So I am resending below. Sorry about that! Bruce]

Hi Oscar,

Thanks for your comments.

def MyAbs(x):
     x1=symbols('x1',real=True,positive=True)
     x1 = x.evalf(subs={a:0.573})
     if x1 < 0.0:
         return S(-1)*x
     else:
         return x

That's one way to do it. It will only work for the `Abs` function
though.

Abs() is the only function I have encountered where sympy's normal simplifications are not sufficient. This is because I have additional knowledge about the value and range of 'a'. So my only goal is to incorporate that additional information into the simplification process.

 It is possible to declare a symbol that has a numeric value
using NumberSymbol which is the superclass for both E and pi. You can
do it like this:

class A(NumberSymbol):
     def _as_mpf_val(self, prec):
         return Float('0.6', prec)._mpf_

I see...

All of the other expressions can simplify through evaluation which
implicitly uses the assumptions system which will in turn use
numerical evaluation when possible:

In [107]: a = A()

In [108]: Abs(a - 0.5)
Out[108]: -0.5 + A()

In [109]: Abs(a - 0.7)
Out[109]: 0.7 - A()

I need to experiment with this, but am worried that you can only simplify expressions that evaluate to floats. I need to simplify expressions that are exact. So I need to try

Abs(a - Rational(1,2)) and Abs(a - Rational(7,10))

Will those work in the same way as your examples above?

Perhaps there should be an easier way to do this like NumberSymbol('a', 0.6).

Something like that, which has limited scope (in my case, for determining the sign of Abs(...), would be useful. But I'm not sure that this occurs very often!

Cheers,
        Bruce

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/63317a7b-12d0-f6e1-96bf-372deba14e47%40googlemail.com.

Reply via email to