|
| 1 | +"""Commutative algebra operation declarations.""" |
| 2 | + |
| 3 | +from collections.abc import Callable |
| 4 | +from typing import Any |
| 5 | + |
| 6 | +from jacobian._models import StrictModel |
| 7 | +from jacobian.catalog._examples import example |
| 8 | +from jacobian.catalog.models import MathTool, OperationExample |
| 9 | +from jacobian.math.commutative_algebra_ops._models import ( |
| 10 | + IdealQuotientRequest, |
| 11 | + IdealQuotientResult, |
| 12 | + IdealRadicalMembershipResult, |
| 13 | + IdealRadicalRequest, |
| 14 | + IdealRadicalResult, |
| 15 | + IdealRequest, |
| 16 | +) |
| 17 | +from jacobian.math.commutative_algebra_ops._operations import ( |
| 18 | + compute_ideal_quotient, |
| 19 | + compute_ideal_radical, |
| 20 | + compute_ideal_radical_membership, |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +def _op[RequestT: StrictModel, ResultT: StrictModel]( |
| 25 | + operation_id: str, |
| 26 | + title: str, |
| 27 | + description: str, |
| 28 | + request_model: type[RequestT], |
| 29 | + result_model: type[ResultT], |
| 30 | + operation: Callable[[RequestT], ResultT], |
| 31 | + *tags: str, |
| 32 | + examples: tuple[OperationExample, ...] = (), |
| 33 | + version: str = "1", |
| 34 | +) -> MathTool[RequestT, ResultT]: |
| 35 | + return MathTool( |
| 36 | + operation_id=operation_id, |
| 37 | + version=version, |
| 38 | + title=title, |
| 39 | + description=description, |
| 40 | + request_type=request_model, |
| 41 | + result_type=result_model, |
| 42 | + run=operation, |
| 43 | + tags=tags, |
| 44 | + examples=examples, |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +TOOLS: tuple[MathTool[Any, Any], ...] = ( |
| 49 | + _op( |
| 50 | + "polynomial.ideal.radical.compute", |
| 51 | + "Compute the radical of an ideal", |
| 52 | + "Compute the radical √I of a polynomial ideal using SymPy's " |
| 53 | + "Gröbner basis machinery.", |
| 54 | + IdealRadicalRequest, |
| 55 | + IdealRadicalResult, |
| 56 | + compute_ideal_radical, |
| 57 | + "commutative-algebra", |
| 58 | + "radical", |
| 59 | + "exact", |
| 60 | + examples=( |
| 61 | + example( |
| 62 | + "ideal_xy", |
| 63 | + "Radical of <x^2, xy> in Q[x,y].", |
| 64 | + { |
| 65 | + "variables": ["x", "y"], |
| 66 | + "generators": ["x**2", "x*y"], |
| 67 | + }, |
| 68 | + ), |
| 69 | + ), |
| 70 | + ), |
| 71 | + _op( |
| 72 | + "polynomial.ideal.radical_membership.decide", |
| 73 | + "Check membership in the radical of an ideal", |
| 74 | + "Check whether a polynomial f lies in the radical √I.", |
| 75 | + IdealRequest, |
| 76 | + IdealRadicalMembershipResult, |
| 77 | + compute_ideal_radical_membership, |
| 78 | + "commutative-algebra", |
| 79 | + "radical-membership", |
| 80 | + "exact", |
| 81 | + examples=( |
| 82 | + example( |
| 83 | + "membership_xy", |
| 84 | + "Check if x is in sqrt(<x^2>) in Q[x].", |
| 85 | + { |
| 86 | + "variables": ["x"], |
| 87 | + "generators": ["x**2"], |
| 88 | + }, |
| 89 | + ), |
| 90 | + ), |
| 91 | + ), |
| 92 | + _op( |
| 93 | + "polynomial.ideal.quotient.compute", |
| 94 | + "Compute the ideal quotient (I : J)", |
| 95 | + "Compute the colon ideal (I : J) = {f : f*J ⊆ I} using SymPy.", |
| 96 | + IdealQuotientRequest, |
| 97 | + IdealQuotientResult, |
| 98 | + compute_ideal_quotient, |
| 99 | + "commutative-algebra", |
| 100 | + "ideal-quotient", |
| 101 | + "exact", |
| 102 | + examples=( |
| 103 | + example( |
| 104 | + "quotient_xy", |
| 105 | + "Compute (<x^2, xy> : <x>) in Q[x,y].", |
| 106 | + { |
| 107 | + "variables": ["x", "y"], |
| 108 | + "generators_a": ["x**2", "x*y"], |
| 109 | + "generators_b": ["x"], |
| 110 | + }, |
| 111 | + ), |
| 112 | + ), |
| 113 | + ), |
| 114 | +) |
| 115 | + |
| 116 | +__all__ = ["TOOLS"] |
0 commit comments