#diagram #testing #algebra #proofs #integer #commutative

通勤者

提供测试交换图的工具,允许在代数系统中进行自动化测试

6 个版本

0.1.8 2023年1月16日
0.1.7 2023年1月13日

#647 in 数学

MIT 许可证

28KB
579

通勤者

测试交换图的工具

例如,以下测试在给定的(整数子集)上测试了结合性


 use itertools::Itertools;
 use commuter::diagram::{Diagram, Set, Map, diagram_commutes, CommutativeDiagramResult};

 let generating_integers: Vec<i32> = (0..20).collect();

 let left_add = |(a, b, c): &(i32, i32, i32)| (a + b, *c);
 let right_add = |(a, b, c): &(i32, i32, i32)| (*a, b + c);

 // Build the sets (triplets, pairs, integers) so that summing operations can be well-defined later
 let triplets: Vec<(i32, i32, i32)> = (generating_integers)
     .clone()
     .iter()
     .cartesian_product(generating_integers.clone())
     .cartesian_product(generating_integers.clone().iter())
     .map(|((a, b), c)| (*a, b, *c))
     .collect();

 // Construct the diagram
 let diagram = Diagram::new(
     vec[
         Set::new(triplets), // This set gets some generating elements, on which the diagram will be tested
         Set::<(i32, i32)>::new_no_generating_set(), // We only test on pairs that are generated by the given maps from the triplets, so no explicit elements are added here
         Set::new(vec[(5, 3), (100, 100)]), // We can also insert some additional generating elements into an intermediate set
         Set::<i32>::new_no_generating_set(),
     ],
     vec[
         Map::new(0, 1, left_add, "(+,id)"),
         Map::new(0, 2, right_add, "(id,+)"),
         Map::new(2, 3, |(a, b): &(i32, i32)| a + b, "(+)"),
         Map::new(1, 3, |(a, b): &(i32, i32)| a + b, "(+)"),
     ],
 );

 assert!(match diagram_commutes(&diagram).unwrap() {
     CommutativeDiagramResult::Commutes => true,
     CommutativeDiagramResult::DoesNotCommute(reason) => panic("{}", reason),
 });

依赖关系

~2MB
~43K SLoC