summaryrefslogtreecommitdiff
path: root/morphology/examples/demo_full.rs
diff options
context:
space:
mode:
authorjacksonfu14 <jackson@fashionunited.com>2025-11-06 07:04:52 +0100
committerJackson Moore <jacksonmoore@tuta.io>2025-11-06 07:04:52 +0100
commitc20b1fe88b0ab1469300bd53be14faa6a5b917a0 (patch)
tree9e41975e6f6852146216a05ba4cef09436688aa2 /morphology/examples/demo_full.rs
initial commit
Diffstat (limited to 'morphology/examples/demo_full.rs')
-rw-r--r--morphology/examples/demo_full.rs220
1 files changed, 220 insertions, 0 deletions
diff --git a/morphology/examples/demo_full.rs b/morphology/examples/demo_full.rs
new file mode 100644
index 0000000..fcb4d82
--- /dev/null
+++ b/morphology/examples/demo_full.rs
@@ -0,0 +1,220 @@
+//! Comprehensive demonstration of the meta_affine library - All 3 Phases
+//!
+//! Compile and run:
+//! rustc examples/demo_full.rs -L . --extern meta_affine=libmeta_affine.rlib -o demo_full
+//! ./demo_full
+
+extern crate meta_affine;
+
+use meta_affine::{Value, ValidSet, Sequence};
+use meta_affine::value::get_minimum_derivation_path;
+use meta_affine::set::generate_valid_sets;
+use meta_affine::sequence::{generate_sequences, generate_all_sequences};
+
+fn main() {
+ println!("\n{}", "=".repeat(70));
+ println!("Meta-Affine Library - Complete Demonstration (Phases 1-3)");
+ println!("{}\n", "=".repeat(70));
+
+ // ========================================================================
+ // Phase 1: Core Data Structures
+ // ========================================================================
+
+ println!("PHASE 1: Core Data Structures (Value)\n");
+
+ let v1 = Value::new(2, 3);
+ println!("1. Value: {}", v1);
+
+ let path = get_minimum_derivation_path(v1);
+ print!(" Derivation path: ");
+ for (i, value) in path.iter().enumerate() {
+ print!("{}", value);
+ if i < path.len() - 1 {
+ print!(" → ");
+ }
+ }
+ println!("\n Length: {}\n", path.len());
+
+ // ========================================================================
+ // Phase 2: Valid Set Generation
+ // ========================================================================
+
+ println!("{}", "=".repeat(70));
+ println!("PHASE 2: Valid Set Generation\n");
+
+ let set1 = ValidSet::origin_set();
+ println!("2. Origin set: {:?}", set1.values_sorted());
+
+ let set2 = set1.add_value_with_dependencies(Value::new(1, 1));
+ println!(" Extended set: {:?}", set2.values_sorted());
+ println!(" Size: {}, Valid: {}\n", set2.size(), set2.is_valid());
+
+ println!("3. All valid sets up to size 4:");
+ let all_sets = generate_valid_sets(4);
+ for size in 0..=4 {
+ let count = all_sets.iter().filter(|s| s.size() == size).count();
+ println!(" Size {}: {} sets", size, count);
+ }
+ println!();
+
+ // ========================================================================
+ // Phase 3: Valid Sequence Generation
+ // ========================================================================
+
+ println!("{}", "=".repeat(70));
+ println!("PHASE 3: Valid Sequence Generation\n");
+
+ // Example 1: Simple set, length 1
+ println!("4. Sequences from {{(0,0)}} with length 1:");
+ let simple_set = ValidSet::origin_set();
+ let seqs1 = generate_sequences(&simple_set, 1);
+ println!(" Count: {}", seqs1.len());
+ for seq in &seqs1 {
+ print!(" [");
+ for (i, v) in seq.values().iter().enumerate() {
+ print!("{}", v);
+ if i < seq.values().len() - 1 {
+ print!(", ");
+ }
+ }
+ println!("]");
+ }
+ println!();
+
+ // Example 2: Two-element set, length 2
+ println!("5. Sequences from {{(0,0), (1,0)}} with length 2:");
+ let mut set_vals = std::collections::HashSet::new();
+ set_vals.insert(Value::new(0, 0));
+ set_vals.insert(Value::new(1, 0));
+ let two_set = ValidSet::from_values(set_vals).unwrap();
+ let seqs2 = generate_sequences(&two_set, 2);
+ println!(" Count: {}", seqs2.len());
+ for seq in &seqs2 {
+ print!(" [");
+ for (i, v) in seq.values().iter().enumerate() {
+ print!("{}", v);
+ if i < seq.values().len() - 1 {
+ print!(", ");
+ }
+ }
+ println!("]");
+ }
+ println!();
+
+ // Example 3: Complex set with inner values
+ println!("6. Sequences from {{(0,0), (1,0), (1,1)}} with length 3:");
+ let mut set_vals = std::collections::HashSet::new();
+ set_vals.insert(Value::new(0, 0));
+ set_vals.insert(Value::new(1, 0));
+ set_vals.insert(Value::new(1, 1));
+ let complex_set = ValidSet::from_values(set_vals).unwrap();
+ let seqs3 = generate_sequences(&complex_set, 3);
+ println!(" Count: {}", seqs3.len());
+ if seqs3.len() <= 10 {
+ for seq in &seqs3 {
+ print!(" [");
+ for (i, v) in seq.values().iter().enumerate() {
+ print!("{}", v);
+ if i < seq.values().len() - 1 {
+ print!(", ");
+ }
+ }
+ println!("]");
+ }
+ } else {
+ for seq in seqs3.iter().take(5) {
+ print!(" [");
+ for (i, v) in seq.values().iter().enumerate() {
+ print!("{}", v);
+ if i < seq.values().len() - 1 {
+ print!(", ");
+ }
+ }
+ println!("]");
+ }
+ println!(" ... and {} more", seqs3.len() - 5);
+ }
+ println!();
+
+ // Example 4: All sequences of a given length
+ println!("7. All valid sequences of length 2 (from all possible sets):");
+ let all_seqs2 = generate_all_sequences(2);
+ println!(" Total count: {}", all_seqs2.len());
+ println!(" Sample sequences:");
+ for seq in all_seqs2.iter().take(5) {
+ print!(" [");
+ for (i, v) in seq.values().iter().enumerate() {
+ print!("{}", v);
+ if i < seq.values().len() - 1 {
+ print!(", ");
+ }
+ }
+ println!("]");
+ }
+ if all_seqs2.len() > 5 {
+ println!(" ... and {} more", all_seqs2.len() - 5);
+ }
+ println!();
+
+ // ========================================================================
+ // Constraint Demonstration
+ // ========================================================================
+
+ println!("{}", "=".repeat(70));
+ println!("CONSTRAINT VALIDATION DEMONSTRATION\n");
+
+ use meta_affine::sequence::*;
+
+ println!("8. Constraint checking examples:");
+
+ // Valid sequence
+ let valid_seq = Sequence::new(vec![Value::new(1, 0), Value::new(0, 0)]);
+ println!(" Sequence: [(1,0), (0,0)]");
+ println!(" - Coverage: {}", check_coverage(&valid_seq, &two_set));
+ println!(" - No consecutive duplicates: {}", check_no_consecutive_duplicates(&valid_seq));
+ println!(" - Terminal (0,0): {}", check_terminal(&valid_seq));
+ println!(" - Outer constraint: {}", check_outer_value_constraint(&valid_seq));
+ println!(" Overall valid: {}", valid_seq.is_valid(&two_set));
+ println!();
+
+ // Invalid sequence (doesn't end with (0,0))
+ let invalid_seq1 = Sequence::new(vec![Value::new(0, 0), Value::new(1, 0)]);
+ println!(" Sequence: [(0,0), (1,0)]");
+ println!(" - Terminal (0,0): {}", check_terminal(&invalid_seq1));
+ println!(" Overall valid: {}", invalid_seq1.is_valid(&two_set));
+ println!();
+
+ // Invalid sequence (consecutive duplicates)
+ let invalid_seq2 = Sequence::new(vec![Value::new(0, 0), Value::new(0, 0)]);
+ println!(" Sequence: [(0,0), (0,0)]");
+ println!(" - No consecutive duplicates: {}", check_no_consecutive_duplicates(&invalid_seq2));
+ println!(" Overall valid: {}", invalid_seq2.is_valid(&simple_set));
+ println!();
+
+ // ========================================================================
+ // Statistics
+ // ========================================================================
+
+ println!("{}", "=".repeat(70));
+ println!("STATISTICS\n");
+
+ println!("9. Sequence counts by length:");
+ for length in 1..=4 {
+ let count = generate_all_sequences(length).len();
+ println!(" Length {}: {} sequences", length, count);
+ }
+ println!();
+
+ println!("10. Growth comparison:");
+ println!(" Sets up to size 3: {} valid sets", generate_valid_sets(3).len());
+ println!(" Sets up to size 4: {} valid sets", generate_valid_sets(4).len());
+ println!(" Sets up to size 5: {} valid sets", generate_valid_sets(5).len());
+ println!();
+
+ println!("{}", "=".repeat(70));
+ println!("COMPLETE! All three phases demonstrated.");
+ println!("- Phase 1: Core data structures (Values and paths)");
+ println!("- Phase 2: Valid set generation with downward-closure");
+ println!("- Phase 3: Valid sequence generation with 4 constraints");
+ println!("{}\n", "=".repeat(70));
+}