(side note: Q is generally considered a PID, but indeed it makes little 
sense worrying about Smith normal form over it)

Concerning the slow performance: from the documentation, 
R._matrix_smith_form would allow an optimized routine to kick in. That 
doesn't exist, though. 
ZZ doesn't have it either, but there is a whole different class for that in 
sage/matrix/matrix_integer_dense.pyx that provides a specific-for-ZZ smith 
form algorithm. For QQ['t'] you end up with the generic algorithm, which is 
liable to be inefficient and have quirks such having large variations in 
runtime, depending on the specific input.

So: it makes sense it's not very optimal (yet?). It would require work to 
get a better implementation specific for QQ['t']. This could be worthwhile 
to do well. Summer of Code?


On Thursday 14 December 2023 at 04:05:47 UTC+13 Enrique Artal wrote:

> It is over the ring of polynomials in one variable over Q.
>
> El miércoles, 13 de diciembre de 2023 a las 15:05:00 UTC+1, Dima Pasechnik 
> escribió:
>
>> On Wed, Dec 13, 2023 at 10:55 AM Enrique Artal <enriqu...@gmail.com> 
>> wrote: 
>> > 
>> > I have the toy example belowto compare the direct use of smith_form and 
>> the combination of hermite_form and smith_form. 
>> > 
>> > Last execution (there are random inputs) gave: 
>> > CPU times: user 2.22 s, sys: 5.93 ms, total: 2.23 s Wall time: 2.23 s 
>> CPU times: user 454 ms, sys: 990 µs, total: 455 ms Wall time: 456 ms 
>> > 
>> > %%%%%%%%%%%%%%%%%%%%% 
>> > R.<t> = QQ[] 
>> > n = 3 
>> > m = 5 
>> > ds = (n, m) 
>> > M = MatrixSpace(R, n, m) 
>> > V = random_vector(R, n) 
>> > A0 = Matrix(R, n, m) 
>> > A0[0, 0] = R.random_element() 
>> > for j in range(1, n): 
>> > A0[j, j] = A0[j -1, j - 1] * R.random_element() 
>> > def par(n): 
>> > i1 = ZZ.random_element(0,n) 
>> > j1 = i1 
>> > while j1 == i1: 
>> > j1 = ZZ.random_element(0,n) 
>> > return (i1, j1) 
>> > def smith_hermite(A): 
>> > D1, U1 = A.hermite_form(transformation=True) 
>> > D, U2, V = D1.smith_form() 
>> > U = U2 * U1 
>> > return D, U, V 
>> > P = {j: identity_matrix(R, ds[j]) for j in range(2)} 
>> > s = 20 
>> > for k in range(2): 
>> > for a in range(s): 
>> > i, j = par(n) 
>> > f = R.random_element() 
>> > P[k].add_multiple_of_row(i, j ,f) 
>> > i, j = par(n) 
>> > P[k].swap_rows(i, j) 
>> > i, j = par(n) 
>> > f = R.random_element() 
>> > P[k].add_multiple_of_column(i, j ,f) 
>> > i, j = par(n) 
>> > P[0].swap_columns(i, j) 
>> > A = P[0] * A0 * P[1] 
>> > %time D, U, V = A.smith_form() 
>> > %time D1, U1, V1 = smith_hermite(A) 
>>
>> hmm, what's Smith form of a matrix over Q ? 
>> Q is not a PID. 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups "sage-support" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to sage-support...@googlegroups.com. 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sage-support/dec24250-3a00-4c3e-a2e6-e352cde6ff2bn%40googlegroups.com.
>>  
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/eae0bd95-4ba8-4e8e-a5c7-c6ec8d83518an%40googlegroups.com.

Reply via email to