On Wed, 31 Mar 2021 at 15:05, JSS95 <[email protected]> wrote:
>
> Assumptions are used only in ask() and refine(), so  __new__() does not need 
> to take assumptions. Besides, using new assumption in __new__() will make 
> everything extremely slow so I'd say __new__() must not take assumptions.

Agreed

> My idea is to make eval() method, not __new__(), able to take assumptions. 
> __new__() will call eval() without assumption, using old assumptions system 
> (and thus without any speed issue).
> ask() or refine() will call eval() with assumption, using new assumptions 
> system.

I agree. That's what I was hinting at.

> IMO this topic needs to be resolved first in order to implement _eval_new() 
> method suggested in #17280.

I think that the two ideas go together. There needs to be a hook for
refine to call into and that needs to be shared with  __new__. Then
what we are talking about is moving the code that is currently in
__new__ into that hook. How easy that is to do without churning
everything depends on the answer to your questions above. Version 3
that you have shown requires hefty churn because every
expr.is_positive needs to be changed to
expr.check_positive(assumptions).

Note that your benchmark is flawed since it creates an
AssumptionsWrapper each time in the timing loop. If we only want to
make a single call to is_positive then we could have a function that
does that without creating a new Basic instance. Otherwise the
AssumptionsWrapper is created so that multiple assumptions queries can
be made. We can also optimise AssumptionsWrapper to inherit the
assumptions dict of the object it wraps.

We could make a method like eval as already used by Function. Would it
need to be a classmethod or an instance method?

Note that a classmethod would only have access to the args whereas an
instance method can also use the methods, attributes and properties of
the instance. I think that the reason a classmethod is used for eval
is because it potentially avoids the cost of Basic.__new__ but I'm not
sure how significant that actually is in any reasonable benchmark
(maybe it's more significant for Function than for other Basic
classes).


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/CAHVvXxQjNj%3D8_7odN_ViQJBJ1eo_-rvELCa4sdVdbGT%3D65Wg2w%40mail.gmail.com.

Reply via email to