Skip to content

Enable number field diagram search via computed discriminant axes (LMFDB#6985)#34

Open
roed-math wants to merge 4 commits into
mainfrom
ai/t45-nf-diagram-search
Open

Enable number field diagram search via computed discriminant axes (LMFDB#6985)#34
roed-math wants to merge 4 commits into
mainfrom
ai/t45-nf-diagram-search

Conversation

@roed-math

Copy link
Copy Markdown
Owner

The number field diagram search was disabled because choosing discriminant as an axis did
not work: the database stores the sign and absolute value of the discriminant in separate
columns, so the signed discriminant is not a plain column and could not be selected — and
the configured default even made the page 500 with KeyError: 'disc'. This adds a reusable
computed_cols option to diagram_opts (handled in SearchWrapper._diagram_search) that
registers axes whose values are derived from one or more database columns via a function,
adds those columns to the projection, and evaluates the function when building the diagram
data. Number fields use it for the signed discriminant (disc_sign * disc_abs) and the
absolute discriminant, and the diagram page is re-enabled. Empty result sets and unknown
axis keys now degrade cleanly instead of erroring, and pages that do not set computed_cols
are unaffected. Verified with the flask test client (default/signed/absolute discriminant
axes render correct plots, existing axes and the elliptic-curve/groups diagrams unchanged,
degenerate cases return 200); added test_diagram_search; number_fields tests and pyflakes
pass. Addresses LMFDB#6985.

🤖 Generated with Claude Code

The diagram search axis options are built from SearchColumns whose name is a
real database column. Number fields expose a "disc" column (a MultiProcessedCol
combining the separately-stored disc_sign and disc_abs), which is not a database
column, so it was filtered out of the axis choices -- yet it was the configured
x_axis_default, making the default diagram request 500 with KeyError: 'disc'.
The page was consequently disabled via NFSearchArray.has_diagram = False.

Add a reusable "computed_cols" option to diagram_opts (handled in
SearchWrapper._diagram_search): a mapping from an axis key to {label, cols, func,
type} that registers axes whose values are derived from one or more database
columns via a function. Number fields use it for the signed discriminant
(disc = disc_sign * disc_abs) and the absolute discriminant, and re-enable the
diagram page. Also make the empty-result path hand the template an empty list
rather than None, and fall back to the raw axis key for unknown axis labels, so
degenerate cases degrade cleanly. Pages that don't set computed_cols are
unaffected.

Verified with the flask test client: default and explicit signed/absolute
discriminant axes render correct plots, existing axes (rd/regulator/num_ram) and
the elliptic-curve/groups diagrams are unchanged, empty result sets and
single-value axes return 200. Added test_diagram_search; full number_fields
test suite passes; pyflakes clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread lmfdb/number_fields/number_field.py Outdated
jump_knowl = "nf.search_input"
jump_prompt = "Label, name, polynomial, or comma-separated list"
has_diagram = False
has_diagram = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is superfluous, has_diagram is true by default.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — removed in c0019dc; has_diagram defaults to True via getattr(self, "has_diagram", True).

Comment thread lmfdb/number_fields/number_field.py Outdated
# discriminant is a plain column that can be selected as an axis.
"computed_cols": {
"disc": {
"label": "Discriminant",

@havarddj havarddj Jul 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Discriminant" (and "Absolute discriminant") below should be lower case to be consistent with the other labels.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1bb8aa9 — both labels are now lowercase ("discriminant", "absolute discriminant"), matching the sort labels.

@havarddj havarddj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the slightly cosmetic comments above, this looks great to me!

roed314 and others added 3 commits July 24, 2026 10:58
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

3 participants