On Tue, 30 Mar 2021 at 16:39, 'B A' via sympy <[email protected]> wrote:
>
> Here is one solution that seems to work. To simplify Z I use Z.replace(Abs,
> MyAbs) with
>
> 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
> Is this a reasonable way to go, or are there gotchas that I should be aware
> of?
That's one way to do it. It will only work for the `Abs` function
though. 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_
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()
Perhaps there should be an easier way to do this like NumberSymbol('a', 0.6).
Oscar
--
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/CAHVvXxSF-0uHXCv4Ehh1EFzyAMZA-vmkkwGXWc0Od-TMzUo-XA%40mail.gmail.com.