Skip to content

Add gr_vec_set_str and gr_mat_set_str#2747

Open
fredrik-johansson wants to merge 2 commits into
flintlib:mainfrom
fredrik-johansson:vecstr
Open

Add gr_vec_set_str and gr_mat_set_str#2747
fredrik-johansson wants to merge 2 commits into
flintlib:mainfrom
fredrik-johansson:vecstr

Conversation

@fredrik-johansson

@fredrik-johansson fredrik-johansson commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Allow parsing vectors and matrices from strings in the same format we print them ([a, b, c] for vectors, [[a, b], [c, d]] for matrices).

>>> Vec(ZZx)("[x+1, (x+1)^5]")
[x+1, x^5+5*x^4+10*x^3+10*x^2+5*x+1]

>>> Mat(RR)("[[1/3, 0], [[0 +/- 1], pi +/- 1/10^4]]")
[[[0.3333333333333333 +/- 7.04e-17], 0],
[[+/- 1.01], [3.142 +/- 5.08e-4]]]

>>> Mat(Qp_padic_radix(7))("[[1, 2], [3 + O(7^10), 4/5 - O(7^8)]]")
[[1, 2],
[3 + O(7^10), 1152961 + O(7^8)]]

>>> Vec(Mat(QQ, 2, 2))("[[[1,0],[0,1]], [[0,1],[-1,0]]]")
[[[1, 0],
[0, 1]], [[0, 1],
[-1, 0]]]

Straightforward, mostly AI-generated patch.

Note that gr_set_str is overloaded to call these methods for vector and matrix rings, but the generic gr_set_str doesn't yet handle vector or matrix subexpressions for generic rings. So it's still not possible to parse polynomials with matrix coefficients, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant