A Golang runtime and compilation backend for Delta Interaction Nets.

test non-canonical

+58
+4
cmd/gentests/tests/101_no_optimal/reduction_test.go
··· 10 10 //go:embed output.nix 11 11 var output string 12 12 13 + // Test_101_no_optimal_Reduction tests the reduction of a lambda term that has no optimal 14 + // reduction strategy in standard lambda calculus but can be optimally reduced in Delta-Nets. 15 + // This term is from the paper: ((λg.(g (g λx.x))) (λh.((λf.(f (f λz.z))) (λw.(h (w λy.y)))))) 16 + // It demonstrates Delta-Nets' ability to handle sharing optimally without unnecessary reductions. 13 17 func Test_101_no_optimal_Reduction(t *testing.T) { 14 18 gentests.CheckLambdaReduction(t, "101_no_optimal", input, output) 15 19 }
+1
cmd/gentests/tests/102_non_normalizing/input.nix
··· 1 + ((x: (x x)) (y: (y y)))
+47
cmd/gentests/tests/102_non_normalizing/reduction_test.go
··· 1 + package gentests 2 + 3 + import _ "embed" 4 + import "testing" 5 + import "github.com/vic/godnet/pkg/lambda" 6 + import "github.com/vic/godnet/pkg/deltanet" 7 + 8 + //go:embed input.nix 9 + var input string 10 + 11 + func Test_102_non_normalizing_ConstantMemory(t *testing.T) { 12 + // Parse input 13 + term, err := lambda.Parse(input) 14 + if err != nil { 15 + t.Fatalf("Parse error: %v", err) 16 + } 17 + 18 + // Convert to Net 19 + net := deltanet.NewNetwork() 20 + root, port := lambda.ToDeltaNet(term, net) 21 + 22 + // Connect to output 23 + output := net.NewVar() 24 + net.Link(root, port, output, 0) 25 + 26 + // Initial node count 27 + initialNodes := net.NodeCount() 28 + 29 + // Reduce for a few steps 30 + for i := 0; i < 10; i++ { 31 + prevOps := net.GetStats().TotalReductions 32 + net.ReduceAll() 33 + currOps := net.GetStats().TotalReductions 34 + if currOps == prevOps { 35 + // Converged 36 + break 37 + } 38 + 39 + // Check node count doesn't grow excessively 40 + currentNodes := net.NodeCount() 41 + if currentNodes > initialNodes+200 { // Allow some growth 42 + t.Errorf("Node count grew too much: initial %d, current %d at step %d", initialNodes, currentNodes, i) 43 + } 44 + } 45 + 46 + t.Logf("Non-normalizing test completed with constant memory") 47 + }
+6
pkg/deltanet/deltanet.go
··· 165 165 } 166 166 } 167 167 168 + func (n *Network) NodeCount() int { 169 + n.nodesMu.Lock() 170 + defer n.nodesMu.Unlock() 171 + return len(n.nodes) 172 + } 173 + 168 174 func (n *Network) nextNodeID() uint64 { 169 175 return atomic.AddUint64(&n.nextID, 1) 170 176 }