Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-28 Thread Aaron Meurer
On Wed, Feb 28, 2024 at 2:23 PM Chris Smith wrote: > > > I might not be following > > Say a current test is `assert ans == 2*x + 2*y`. That isn't going to pass > when distribution is off. I was imagining that there was some way you could > write a decorator that would be able to convert that

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-28 Thread Chris Smith
> I might not be following Say a current test is `assert ans == 2*x + 2*y`. That isn't going to pass when distribution is off. I was imagining that there was some way you could write a decorator that would be able to convert that to `assert f(ans) == f(2*x+2*y)` where `f` is something like

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-26 Thread Aaron Meurer
On Mon, Feb 26, 2024 at 1:54 PM Chris Smith wrote: > > It seems that the tests could be marked as passing for both forms to see > where tests fail because a routine is broken. Broken routines could be fixed > (as necessary) so they are not assuming distribution. Would the decorator > need to

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-26 Thread Chris Smith
It seems that the tests could be marked as passing for both forms to see where tests fail because a routine is broken. Broken routines could be fixed (as necessary) so they are not assuming distribution. Would the decorator need to be taken off routines once everything was passing? Except for

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-22 Thread Aaron Meurer
I don't think we need to try to check the code for everywhere a multiplication happens. We can rely on the tests sufficiently covering the code. So what you would do is set the global distribute flag to False, run the tests, and see what fails. Then as you fix certain tests that are broken, add a

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-22 Thread Chris Smith
In order to solve the issue incrementally, it seems like we would need to identify every line where multiplication is used (on arguments that could possibly be Number and Add) and have them call `Mul` with a `distribute=True` option. How to identify where the multiplication lines are located?

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-21 Thread Aaron Meurer
On Wed, Feb 21, 2024 at 4:09 PM Chris Smith wrote: > > > There is a distribute() context manager > > I had forgotten about that, thanks for the reminder! We probably shouldn't advertise it too widely. Like I said, it's not as bad as the evaluate() context manager, but it has some of the same

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-21 Thread Chris Smith
> There is a distribute() context manager I had forgotten about that, thanks for the reminder! /c On Wednesday, February 21, 2024 at 4:39:22 PM UTC-6 Aaron Meurer wrote: > There is a distribute() context manager which lets you disable > automatic distribution, though it's not pretty: > > >>>

Re: [sympy] Re: How to avoid distributing a constant factor after differentiation?

2024-02-21 Thread Aaron Meurer
There is a distribute() context manager which lets you disable automatic distribution, though it's not pretty: >>> from sympy.core.parameters import distribute >>> with distribute(False): ... print(expr.diff(t)) 3*a*(t - t0)**2 + 2*b*(t - t0) While this is less dangerous than the similar