1
1
use fp:: prime:: ValidPrime ;
2
2
use fp:: vector:: { Slice , SliceMut } ;
3
3
4
- use enum_dispatch:: enum_dispatch;
5
-
6
4
/// A graded algebra over F_p, finite dimensional in each degree, equipped with a choice of ordered
7
5
/// basis in each dimension. Basis elements of the algebra are referred to by their degree and
8
6
/// index, and general elements are referred to by the degree and an `FpVector` listing the
@@ -17,7 +15,6 @@ use enum_dispatch::enum_dispatch;
17
15
/// The algebra should also come with a specified choice of algebra generators, which are
18
16
/// necessarily basis elements. It gives us a simpler way of describing finite modules by only
19
17
/// specifying the action of the generators.
20
- #[ enum_dispatch]
21
18
pub trait Algebra : std:: fmt:: Display + Send + Sync + ' static {
22
19
/// Returns the prime the algebra is over.
23
20
fn prime ( & self ) -> ValidPrime ;
@@ -155,21 +152,19 @@ pub trait Algebra: std::fmt::Display + Send + Sync + 'static {
155
152
}
156
153
157
154
#[ cfg( feature = "json" ) ]
158
- #[ enum_dispatch]
159
155
pub trait JsonAlgebra : Algebra {
160
156
fn prefix ( & self ) -> & str ;
161
157
162
158
/// Converts a JSON object into a basis element. The way basis elements are represented by JSON
163
159
/// objects is to be specified by the algebra itself, and will be used by module
164
160
/// specifications.
165
- fn json_to_basis ( & self , _json : serde_json:: Value ) -> error:: Result < ( i32 , usize ) > ;
161
+ fn json_to_basis ( & self , json : serde_json:: Value ) -> error:: Result < ( i32 , usize ) > ;
166
162
167
- fn json_from_basis ( & self , _degree : i32 , _idx : usize ) -> serde_json:: Value ;
163
+ fn json_from_basis ( & self , degree : i32 , idx : usize ) -> serde_json:: Value ;
168
164
}
169
165
170
166
/// An algebra with a specified list of generators and generating relations. This data can be used
171
167
/// to specify modules by specifying the actions of the generators.
172
- #[ enum_dispatch]
173
168
pub trait GeneratedAlgebra : Algebra {
174
169
/// Given a degree `degree`, the function returns a list of algebra generators in that degree.
175
170
/// This return value is the list of indices of the basis elements that are generators. The
@@ -220,75 +215,62 @@ pub trait GeneratedAlgebra: Algebra {
220
215
221
216
#[ macro_export]
222
217
macro_rules! dispatch_algebra {
223
- ( $dispatch_macro : ident) => {
224
- fn prime( & self ) -> fp:: prime:: ValidPrime {
225
- $dispatch_macro!( prime, self , )
226
- }
227
-
228
- fn compute_basis( & self , degree: i32 ) {
229
- $dispatch_macro!( compute_basis, self , degree)
230
- }
231
-
232
- fn dimension( & self , degree: i32 , excess: i32 ) -> usize {
233
- $dispatch_macro!( dimension, self , degree, excess)
234
- }
235
-
236
- fn multiply_basis_elements(
237
- & self ,
238
- result: & mut FpVector ,
239
- coeff: u32 ,
240
- r_deg: i32 ,
241
- r_idx: usize ,
242
- s_deg: i32 ,
243
- s_idx: usize ,
244
- excess: i32 ,
245
- ) {
246
- $dispatch_macro!(
247
- multiply_basis_elements,
248
- self ,
249
- result,
250
- coeff,
251
- r_deg,
252
- r_idx,
253
- s_deg,
254
- s_idx,
255
- excess
256
- )
257
- }
218
+ ( $struct: ty, $dispatch_macro: ident) => {
219
+ impl Algebra for $struct {
220
+ $dispatch_macro! {
221
+ fn prime( & self ) -> ValidPrime ;
222
+ fn compute_basis( & self , degree: i32 ) ;
223
+ fn dimension( & self , degree: i32 , excess: i32 ) -> usize ;
224
+ fn multiply_basis_elements(
225
+ & self ,
226
+ result: SliceMut ,
227
+ coeff: u32 ,
228
+ r_degree: i32 ,
229
+ r_idx: usize ,
230
+ s_degree: i32 ,
231
+ s_idx: usize ,
232
+ excess: i32 ,
233
+ ) ;
258
234
259
- fn json_to_basis( & self , json: serde_json:: Value ) -> error:: Result <( i32 , usize ) > {
260
- $dispatch_macro!( json_to_basis, self , json)
261
- }
235
+ fn multiply_basis_element_by_element(
236
+ & self ,
237
+ result: SliceMut ,
238
+ coeff: u32 ,
239
+ r_degree: i32 ,
240
+ r_idx: usize ,
241
+ s_degree: i32 ,
242
+ s: Slice ,
243
+ excess: i32 ,
244
+ ) ;
262
245
263
- fn json_from_basis( & self , degree: i32 , idx: usize ) -> serde_json:: Value {
264
- $dispatch_macro!( json_from_basis, self , degree, idx)
265
- }
246
+ fn multiply_element_by_basis_element(
247
+ & self ,
248
+ result: SliceMut ,
249
+ coeff: u32 ,
250
+ r_degree: i32 ,
251
+ r: Slice ,
252
+ s_degree: i32 ,
253
+ s_idx: usize ,
254
+ excess: i32 ,
255
+ ) ;
266
256
267
- fn basis_element_to_string( & self , degree: i32 , idx: usize ) -> String {
268
- $dispatch_macro!( basis_element_to_string, self , degree, idx)
269
- }
257
+ fn multiply_element_by_element(
258
+ & self ,
259
+ result: SliceMut ,
260
+ coeff: u32 ,
261
+ r_degree: i32 ,
262
+ r: Slice ,
263
+ s_degree: i32 ,
264
+ s: Slice ,
265
+ excess: i32 ,
266
+ ) ;
270
267
271
- fn generators( & self , degree: i32 ) -> Vec <usize > {
272
- $dispatch_macro!( generators, self , degree)
273
- }
268
+ fn default_filtration_one_products( & self ) -> Vec <( String , i32 , usize ) >;
274
269
275
- fn string_to_generator<' a, ' b>(
276
- & ' a self ,
277
- input: & ' b str ,
278
- ) -> nom:: IResult <& ' b str , ( i32 , usize ) > {
279
- $dispatch_macro!( string_to_generator, self , input)
280
- }
281
-
282
- fn decompose_basis_element(
283
- & self ,
284
- degree: i32 ,
285
- idx: usize ,
286
- ) -> Vec <( u32 , ( i32 , usize ) , ( i32 , usize ) ) > {
287
- $dispatch_macro!( decompose_basis_element, self , degree, idx)
288
- }
270
+ fn basis_element_to_string( & self , degree: i32 , idx: usize ) -> String ;
289
271
290
- fn generating_relations ( & self , degree: i32 ) -> Vec < Vec < ( u32 , ( i32 , usize ) , ( i32 , usize ) ) >> {
291
- $dispatch_macro! ( generating_relations , self , degree )
272
+ fn element_to_string ( & self , degree: i32 , element : Slice ) -> String ;
273
+ }
292
274
}
293
275
} ;
294
276
}
0 commit comments