fmpz_mat_snf_diagonal (and Nemo is_diagonal (not used))

18 views
Skip to first unread message

Grégory Vanuxem

unread,
Jun 21, 2026, 4:14:32 PM (9 days ago) Jun 21
to flint...@googlegroups.com
Hi,

I am writing an interface to Julia for FriCAS, and so also parts of
Nemo. And I wonder if this is the behavior you want, that is,
fmpz_mat_snf_diagonal does not check if the entry matrix is diagonal.
That is not a problem for me I will just code something like:

smithDiagonal(m) ==
diagonal?(m) => junfunc("snf_diagonal", m)
error "smithDiagonal: not a diagonal matrix"

Greg

================================================================

Nemo:

snf_diagonal(x::ZZMatrix)

Given a diagonal matrix $x$ compute the Smith normal form of $x$.
"""
function snf_diagonal(x::ZZMatrix)
z = similar(x)
@ccall libflint.fmpz_mat_snf_diagonal(z::Ref{ZZMatrix},
x::Ref{ZZMatrix})::Nothing
return z
end

jlFriCAS:

a:=matrix([[1,4],[7,9]])

+1 4+
(2) | |
+7 9+

Type: Matrix(Integer)
(3) -> a:=matrix([[1,4],[7,9]])@JLMatrix(NMInteger)

(3)

[1 4]
[7 9]

Type: JLMatrix(NMInteger)

(4) -> smith a

(4)

[1 0]
[0 19]

Type: JLMatrix(NMInteger)
(5) -> smithDiagonal a

(5)

[1 4]
[7 9]

Type: JLMatrix(NMInteger)
(6) -> diagonal? a

(6) false

Type: Boolean
(7) -> jlType a

(7) ZZMatrix

Type: Symbol

Edgar Costa

unread,
Jun 21, 2026, 4:31:30 PM (9 days ago) Jun 21
to flint...@googlegroups.com
That is the intent, in general ,the user is the one responsible to provide valid input. 
--

---
You received this message because you are subscribed to the Google Groups "flint-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flint-devel...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/flint-devel/CAHnU2dax9W9dJt_84B7aUtXzC8PVO52PuoQio_xNx77TXTa6Sw%40mail.gmail.com.

Albin Ahlbäck

unread,
Jun 21, 2026, 4:32:04 PM (9 days ago) Jun 21
to flint...@googlegroups.com
Hi Grégory,

I will read this as: "Is it expected that `fmpz_mat_snf_diagonal' does
not check that the matrix is indeed diagonal?"

Usually we do not check things if an argument is called (varies a bit
throughout FLINT, but in general this is a good strategy if it can be
easily checked beforehand). However, the docstring could reflect this
better.

Best,
Albin

Grégory Vanuxem

unread,
Jun 21, 2026, 6:40:04 PM (9 days ago) Jun 21
to flint...@googlegroups.com
Le dim. 21 juin 2026 à 22:31, Edgar Costa <edgardi...@gmail.com> a écrit :
>
> That is the intent, in general ,the user is the one responsible to provide valid input.

This is what I guessed in fact, and finally I also used this strategy.
In (jl)FriCAS there are also some routines that do not perform checks,
this is usually stated in the documentation. This is what I did, as
evoked by Albin.

Greg
> To view this discussion, visit https://groups.google.com/d/msgid/flint-devel/CA%2BiQ7x4m1sQ3wquYSgiAiKDrV0mEv%2Bwc-HHdYCY0aivzwDVRow%40mail.gmail.com.

Grégory Vanuxem

unread,
Jun 21, 2026, 6:51:11 PM (9 days ago) Jun 21
to flint...@googlegroups.com
Le dim. 21 juin 2026 à 22:32, Albin Ahlbäck <albin....@gmail.com> a écrit :
>
> Hi Grégory,
>
> I will read this as: "Is it expected that `fmpz_mat_snf_diagonal' does
> not check that the matrix is indeed diagonal?"

Right!

> Usually we do not check things if an argument is called (varies a bit
> throughout FLINT, but in general this is a good strategy if it can be
> easily checked beforehand). However, the docstring could reflect this
> better.
>

I also did that. And about performance, FLINT is intended to be highly
efficient and it is, I also think that here it is up to the user to
know what it is doing. Checking everything would be counterproductive.

Thanks for your responses.

Greg
Reply all
Reply to author
Forward
0 new messages