Skip to main content

00_minimal_rule/
main.rs

1use tensorlogic_compiler::compile_to_einsum;
2use tensorlogic_ir::{TLExpr, Term};
3
4fn main() {
5    println!("=== Tensorlogic Example: Minimal Rule ===\n");
6
7    // Define a simple implication rule:
8    // Parent(a, b) → Ancestor(a, b)
9    // "If a is a parent of b, then a is an ancestor of b"
10
11    let parent = TLExpr::pred("Parent", vec![Term::var("a"), Term::var("b")]);
12
13    let ancestor = TLExpr::pred("Ancestor", vec![Term::var("a"), Term::var("b")]);
14
15    let rule = TLExpr::imply(parent, ancestor);
16
17    println!("Rule: Parent(a, b) → Ancestor(a, b)");
18    println!("Compiling logic rule to tensor graph...\n");
19
20    match compile_to_einsum(&rule) {
21        Ok(plan) => {
22            println!("Compilation successful!");
23            println!("  Tensors: {}", plan.tensors.len());
24            println!("  Nodes: {}", plan.nodes.len());
25            println!("\nGenerated tensors:");
26            for (i, tensor) in plan.tensors.iter().enumerate() {
27                println!("  {}: {}", i, tensor);
28            }
29            println!("\nGenerated nodes:");
30            for (i, node) in plan.nodes.iter().enumerate() {
31                println!("  {}: {:?} (inputs: {:?})", i, node.op, node.inputs);
32            }
33        }
34        Err(e) => {
35            eprintln!("Compilation error: {}", e);
36        }
37    }
38
39    println!("\n=== Compilation Complete ===");
40}