Skip to content

Rename set_from_* methods to set#63

Open
d-torrance wants to merge 4 commits into
MichaelABurr:aringsfrom
d-torrance:set-rename
Open

Rename set_from_* methods to set#63
d-torrance wants to merge 4 commits into
MichaelABurr:aringsfrom
d-torrance:set-rename

Conversation

@d-torrance

Copy link
Copy Markdown
Collaborator

This was originally part of #62, but I split it off.

We rename the various set_from_* methods (like set_from_long, set_from_double, etc.) to just set. The method names were redundant since the thing we're setting from is clear from the second argument. This point come up in our C++ factoring group discussion last Friday.

Similarly, the various get_from_* methods are renamed to try_set, since that's what they do -- they try calling set and return false if they can't.

One little wrinkle -- GFM2 (the "New" strategy for GF) uses int for its elements, but not how you'd expect. 1 isn't actually 1, but a^1, where a is a generator for the multplicative group of units. So there was some ambiguity -- should set(x, 1) mean "set x to be 1" or "set x to be a^1"?

We made the decision that, for consistency with all the other rings where setting from an int means promoting from ZZ, it should be the former. That messed up a few algorithms that called set to mean the latter thing, so we switched them to use copy instead.

Draft for now to test the builds

d-torrance and others added 3 commits June 23, 2026 19:17
Removes the redundant _from_X suffix from ARing conversion methods:
set_from_long, set_from_mpz, set_from_mpq, set_from_double,
set_from_doubles, set_from_BigReal, set_from_BigReals,
set_from_BigComplex, set_from_Interval, set_from_ComplexInterval,
and set_from_int (in tower/dpoly). The source type is already
encoded in the argument, making the suffix redundant.

As a prerequisite, removes set_from_complex_double (CC/CCC/CCi) and
set_from_complex_mpfr (CCC), which were duplicate methods with
identical implementations to set_from_doubles and set_from_BigReals
respectively, differing only in return type (bool vs void).

Retains has_set_from_* names for the concept detectors in
aring-translate.hpp (e.g. has_set_from_double, has_set_from_mpq),
reverting a mechanical has_set_* rename from an earlier draft. The
from_ infix is informative since these concepts detect set() overloads
for specific source types.

Fixes ARingZZ::invert to call fmpz_set directly rather than the
ambiguous set(ElementType&, ElementType) call, which becomes
ambiguous with set(ElementType&, long) after the rename since
ARingZZ::ElementType = fmpz = long.

Adds set(ElementType&, int) to ARingRR, ARingRRR, ARingRRi, ARingCC,
ARingCCC, ARingCCi, and ARingQQGMP, which all have both long and double
set overloads. Without it, set(elem, int_literal) is ambiguous since
int converts to both long and double.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The six free template functions get_from_double, get_from_BigReal,
get_from_Interval, get_from_complex_double, get_from_BigComplex, and
get_from_ComplexInterval are renamed to try_set. The name better
describes what they do: attempt R.set(elem, val) and return false if
the ring doesn't support that overload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rategy)

ARingGFM2 stores field elements as table indices (int), not integers.
set(elem&, elem) and set(elem&, long) had the same semantics as copy()
and fromZZTable() respectively, but after renaming set_from_long to
set(long), calls like ring().set(result, 1) resolved to the elem
overload (exact match on int), setting a raw index instead of converting
the integer through the GF table.

Fix: remove set(elem&, elem) from ARingGFM2 so that set() always means
"convert from integer". Replace all element-copy uses of ring().set()
with ring().copy() throughout the matrix and ring infrastructure:

- dmat-lu.hpp, dmat-lu-inplace.hpp: LU decomposition (original fix)
- mat-elem-ops.hpp: DMat getEntry, setEntry, and submatrix helpers
- mat-arith.hpp: matrix copy/assignment and transpose
- mat-util.hpp: matrix concatenation
- smat.hpp: sparse matrix lead_row and vec_set_entry
- dmat-lu-zzp-flint.hpp: solution extraction
- aring-glue.hpp: ConcreteRing::copy() virtual method

ConcreteRing::copy() now uses Element b(*R) + R->copy(b.value(), a)
instead of R->set(b, a), using b.value() to give copy() an unambiguous
ElementType& argument so template deduction resolves to the correct
per-ring copy overload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Like GFM2, elements are ints, but representing exponents instead of
actual integers.  We update set() to promote the integer and use
copy() in a few unit tests where we want to copy the exponent instead.
@d-torrance

Copy link
Copy Markdown
Collaborator Author

@d-torrance d-torrance marked this pull request as ready for review June 24, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant