I tried it... it appears to be (and gives a solid speed-up!)

but it'd be great to confirm that I'm not potentially running into race conditions. thanks in advance

I have a polynomial, where I can cancel out "e0":

_x(2)*_z(1)*e0*e1-_y(2)*_z(1)*e0**2+_x(1)*_y(2)*e0*e2+_y(1)*_z(2)*e0**2-_x(2)*_y(1)*e0*e2-_x(1)*_z(2)*e0*e1

_x(2)

but division gives the error: what: divisor in series division does not consist of a single coefficient

is there any other way to remove e0 from each term?

@andrewcorrigan that type of multithreaded usage is supported by piranha, so you should be safe

for that simple case of division, what you can do is to raise "e0" to -1 and multiply the polynomial by it

ah but you want to remove different powers of e0 from the expression? In that case you can substitute "e0" with 1 as an alternative

I want to just divide by e0, sorry my wording was imprecise, I'll try multiplying by e0^-1

Hmm. so I have: d *= m.pow(-1); and get: "what: invalid argument for series exponentiation: negative integral value"

d and m are both: piranha::polynomial<piranha::rational,piranha::monomial<int>>

OK: so I put together a simple reproducer and your suggestion worked, what happened is that it then stopped later, where the denominator is a more complex polynomial

and for that the .pow(-1) also fails

I am guessing I need to do polynomial division?

it failed specifically for dividing by a polynomial: y*e0-x*e1

thanks for your help with this, and sorry for moving the goalposts

I tried to use piranha::math::div3, same error

right, the negative exponentiation works only for monomials, it's not a real division algorithm

so the story here is that at one point piranha did implement a real polynomial division algorithm, but I removed the functionality eventually for a variety of reasons (but mostly because with piranha's data structures it is tricky to implement division efficiently, and I felt piranha was starting to stray too far away from its original focus)

in the specific case you mention above, perhaps you could do a substitution such as:

$m = ye_0-xe_1 \rightarrow y = \left(m + xe_1\right) e_0^{-1}$

and then multiply the original expression by $m^{-1}$?

$m = ye_0-xe_1 \rightarrow y = \left(m + xe_1\right) e_0^{-1}$

and then multiply the original expression by $m^{-1}$?

the problem is these are all procedurally generated expressions, so I think the general algorithm would be needed

but I understand if general polynomial division is outside of the scope of piranha

thank you for explaining the background to me

you know beforehand all polynomial divisions are exact or are there remainders as well?

I think they would all be exact... basically I'm computing a determinant using the bareiss algorithm (in sympy/symengine), but on a matrix of piranha polynomials

so I'm not sure why this division even arises

I thought the Bareiss algorithm actually employs divisions (guaranteed to be exact)?

but in any case you could use a piranha version in which the poly division is available

are you using the latest git?

this is the corresponding line in symengine where it happens btw: https://github.com/symengine/symengine/blob/1a797b3c864473a6fff3c5aaccf018bfb374fc9d/symengine/dense_matrix.cpp#L1326

are you suggesting to revert to an older version of Piranha?

the latest official version still has the division code: https://github.com/bluescarni/piranha/releases/tag/v0.10

thank you -- for now, I hand-coded a 4x4 determinant, which is high as I need at the moment, but if it comes up again I will definitely try that out

ok, no problem. I might consider re-adding the division code if I can figure out how to make it good enough. At the time it felt like I was getting into feature-creep mode, but if it turns out that it's useful.. why not

thank you

just for historical context... the division code was part of an attempt to implement rational functions in piranha, together with polynomial GCD. As it turns out, efficient polynomial GCD is still pretty much a research topic, and piranha's data structures are not the best for this type of application. I got it working eventually, but it was far from optimal and I decided to ditch the whole subject to refocus on the core bits of piranha

sure no problem! any time just drop by and ask here, I should be able to reply relatively fast normally