| Crates.io | hasse |
| lib.rs | hasse |
| version | 0.2.1 |
| created_at | 2025-10-18 22:55:26.415926+00 |
| updated_at | 2025-10-22 06:53:36.212049+00 |
| description | Hasse: utilities for working with partially ordered sets (posets) and Hasse diagrams. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1889723 |
| size | 41,300 |
A modern Rust implementation for visualizing Hasse diagrams and working with partially ordered sets (posets).
A Hasse diagram is a visual way to represent a finite partially ordered set. It shows relationships between elements while removing redundant information.
Hasse Diagram Properties:
Consider the divisibility relation on {1, 2, 3, 6}:
Before Reduction: After Reduction (Hasse Diagram):
6 6
/|\ / \
/ | \ / \
1 2 3 2 3
\ | / \ /
\|/ \ /
1 1
The "before" graph shows all divisibility relationships (1 divides everything, 2 and 3 both divide 6, etc.). The Hasse diagram removes redundant edges - we don't draw 1→6 because it's implied by 1→2→6 and 1→3→6.
This tool implements transitive reduction to create Hasse diagrams:
Complexity: O(V·E) where V is vertices and E is edges.
cargo build
cargo run
After entering your graph, you'll see an interactive menu:
=== Hasse Diagram Tool ===
1. Show graph information
2. Compute transitive reduction (Hasse diagram)
3. Compute transitive closure
4. Show topological sort
5. Display graph (GUI)
6. Exit
Option 1: Show graph information
Option 2: Compute transitive reduction
Option 3: Compute transitive closure
Option 4: Show topological sort
Option 5: Display graph (GUI)
Option 6: Exit
Closes the program
graphuse hasse::graph;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
graph()
.vertices(5)
.directed(true)
.edge(0, 1)
.edge(1, 2)
.edge(2, 4)
.edge(2, 3)
.show()?;
Ok(())
}
graph_withuse hasse::graph_with;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
graph_with::<&str>()
.directed(false)
.edge("Alice", "Bob")
.edge("Bob", "Charlie")
.show()?;
Ok(())
}
Visualize how subsets relate under inclusion.
Example: Power set of {a, b}
Vertices: 0=∅, 1={a}, 2={b}, 3={a,b}
Edges: 0→1, 0→2, 1→3, 2→3 (plus transitive 0→3)
Hasse diagram removes: 0→3
Show which numbers divide others.
Example: {1, 2, 3, 6}
Vertices: 0=1, 1=2, 2=3, 3=6
All divisibility edges, then reduce to minimal set
Represent inheritance or class relationships.
Show which tasks must complete before others (project management).
Algorithms Implemented:
cargo test
Tests verify:
Hasse diagrams are named after Helmut Hasse (1898-1979), though similar diagrams existed earlier. They're fundamental in:
The key insight: transitivity is redundant in visual representations. If you can "climb" from A to C via B, you don't need a direct A→C edge.
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
See the UNLICENSE file.
For more information, please refer to http://unlicense.org/
Improvements welcome! Potential enhancements: