|
| 1 | +"""Galois theory 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.galois_theory._models import ( |
| 10 | + FrobeniusCycleRequest, |
| 11 | + FrobeniusCycleResult, |
| 12 | + GaloisFactorRequest, |
| 13 | + GaloisFactorResult, |
| 14 | + GaloisGroupRequest, |
| 15 | + GaloisGroupResult, |
| 16 | + SolvableRequest, |
| 17 | + SolvableResult, |
| 18 | +) |
| 19 | +from jacobian.math.galois_theory._operations import ( |
| 20 | + compute_frobenius_cycle, |
| 21 | + compute_galois_factor, |
| 22 | + compute_galois_group, |
| 23 | + compute_solvable, |
| 24 | +) |
| 25 | + |
| 26 | + |
| 27 | +def _op[RequestT: StrictModel, ResultT: StrictModel]( |
| 28 | + operation_id: str, |
| 29 | + title: str, |
| 30 | + description: str, |
| 31 | + request_model: type[RequestT], |
| 32 | + result_model: type[ResultT], |
| 33 | + operation: Callable[[RequestT], ResultT], |
| 34 | + *tags: str, |
| 35 | + examples: tuple[OperationExample, ...] = (), |
| 36 | + version: str = "1", |
| 37 | +) -> MathTool[RequestT, ResultT]: |
| 38 | + return MathTool( |
| 39 | + operation_id=operation_id, |
| 40 | + version=version, |
| 41 | + title=title, |
| 42 | + description=description, |
| 43 | + request_type=request_model, |
| 44 | + result_type=result_model, |
| 45 | + run=operation, |
| 46 | + tags=tags, |
| 47 | + examples=examples, |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +TOOLS: tuple[MathTool[Any, Any], ...] = ( |
| 52 | + _op( |
| 53 | + "polynomial.galois.factor_mod_p.compute", |
| 54 | + "Factor a polynomial over GF(p)", |
| 55 | + "Factor a polynomial over a prime finite field GF(p) using SymPy, " |
| 56 | + "returning the factorization and irreducibility.", |
| 57 | + GaloisFactorRequest, |
| 58 | + GaloisFactorResult, |
| 59 | + compute_galois_factor, |
| 60 | + "galois-theory", |
| 61 | + "factorization", |
| 62 | + "exact", |
| 63 | + examples=( |
| 64 | + example( |
| 65 | + "factor_x2_plus_1_over_f5", |
| 66 | + "Factor x^2 + 1 over F_5.", |
| 67 | + {"field_order": 5, "coefficients": [1, 0, 1]}, |
| 68 | + ), |
| 69 | + ), |
| 70 | + ), |
| 71 | + _op( |
| 72 | + "polynomial.galois.frobenius_cycle.compute", |
| 73 | + "Compute the Frobenius cycle type", |
| 74 | + "Compute the Frobenius cycle type from a factorization pattern over " |
| 75 | + "GF(p), returning the cycle type and irreducibility.", |
| 76 | + FrobeniusCycleRequest, |
| 77 | + FrobeniusCycleResult, |
| 78 | + compute_frobenius_cycle, |
| 79 | + "galois-theory", |
| 80 | + "frobenius", |
| 81 | + "exact", |
| 82 | + examples=( |
| 83 | + example( |
| 84 | + "irreducible_quadratic", |
| 85 | + "Frobenius cycle of an irreducible quadratic.", |
| 86 | + { |
| 87 | + "field_order": 3, |
| 88 | + "polynomial_degree": 2, |
| 89 | + "factorization_degrees": [2], |
| 90 | + }, |
| 91 | + ), |
| 92 | + ), |
| 93 | + ), |
| 94 | + _op( |
| 95 | + "polynomial.galois_group.compute", |
| 96 | + "Compute the Galois group of a polynomial over Q", |
| 97 | + "Compute the Galois group of a polynomial with rational coefficients " |
| 98 | + "using SymPy's galois_group function.", |
| 99 | + GaloisGroupRequest, |
| 100 | + GaloisGroupResult, |
| 101 | + compute_galois_group, |
| 102 | + "galois-theory", |
| 103 | + "galois-group", |
| 104 | + "exact", |
| 105 | + examples=( |
| 106 | + example( |
| 107 | + "galois_group_of_x2_minus_2", |
| 108 | + "Galois group of x^2 - 2 over Q.", |
| 109 | + {"coefficients": [-2, 0, 1]}, |
| 110 | + ), |
| 111 | + ), |
| 112 | + ), |
| 113 | + _op( |
| 114 | + "polynomial.solvable_by_radicals.decide", |
| 115 | + "Decide if a polynomial is solvable by radicals", |
| 116 | + "Check whether a polynomial is solvable by radicals based on its " |
| 117 | + "degree and Galois group solvability.", |
| 118 | + SolvableRequest, |
| 119 | + SolvableResult, |
| 120 | + compute_solvable, |
| 121 | + "galois-theory", |
| 122 | + "solvable", |
| 123 | + "exact", |
| 124 | + examples=( |
| 125 | + example( |
| 126 | + "x3_solvable", |
| 127 | + "Check x^3 - 2 is solvable by radicals.", |
| 128 | + {"coefficients": [-2, 0, 0, 1]}, |
| 129 | + ), |
| 130 | + ), |
| 131 | + ), |
| 132 | +) |
| 133 | + |
| 134 | +__all__ = ["TOOLS"] |
0 commit comments