From 22956c9e13abaa75b8982fce3350e3266bb85742 Mon Sep 17 00:00:00 2001 From: apocalypse9949 Date: Sat, 14 Mar 2026 23:51:45 +0530 Subject: [PATCH 1/3] unionfind func branch commit --- unionfind/unionfind.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/unionfind/unionfind.go b/unionfind/unionfind.go index 0b49089..9c2afe6 100644 --- a/unionfind/unionfind.go +++ b/unionfind/unionfind.go @@ -161,16 +161,22 @@ func UnifyTerms(xs []ast.BaseTerm, ys []ast.BaseTerm) (UnionFind, error) { return uf, unifyTermsUpdate(newXs, newYs, uf) } +// Copy returns a new UnionFind that is a copy of this one. +func (uf UnionFind) Copy() UnionFind { + newUf := UnionFind{make(map[ast.BaseTerm]ast.BaseTerm, len(uf.parent))} + for k, v := range uf.parent { + newUf.parent[k] = v + } + return newUf +} + // UnifyTermsExtend unifies two same-length lists of relational terms, returning // an extended UnionFind. It does not handle apply-expressions. func UnifyTermsExtend(xs []ast.BaseTerm, ys []ast.BaseTerm, base UnionFind) (UnionFind, error) { if len(xs) != len(ys) { return UnionFind{}, fmt.Errorf("not of equal size") } - uf := UnionFind{make(map[ast.BaseTerm]ast.BaseTerm)} - for k, v := range base.parent { - uf.parent[k] = v - } + uf := base.Copy() var newXs []ast.BaseTerm var newYs []ast.BaseTerm for i, x := range xs { From 5090b24bb4ff1c5ed2e959f1a350a29623dd7b09 Mon Sep 17 00:00:00 2001 From: apocalypse9949 Date: Sat, 14 Mar 2026 22:24:56 +0530 Subject: [PATCH 2/3] detailed --- unionfind/unionfind.go | 1 + 1 file changed, 1 insertion(+) diff --git a/unionfind/unionfind.go b/unionfind/unionfind.go index 9c2afe6..b1f934d 100644 --- a/unionfind/unionfind.go +++ b/unionfind/unionfind.go @@ -172,6 +172,7 @@ func (uf UnionFind) Copy() UnionFind { // UnifyTermsExtend unifies two same-length lists of relational terms, returning // an extended UnionFind. It does not handle apply-expressions. +// The caller needs to ensure that none of the variables is "_" and none of the variables appears among the terms. func UnifyTermsExtend(xs []ast.BaseTerm, ys []ast.BaseTerm, base UnionFind) (UnionFind, error) { if len(xs) != len(ys) { return UnionFind{}, fmt.Errorf("not of equal size") From 4ec4277a7dd3b63bb1d02eb2cafb93d1aaa44b60 Mon Sep 17 00:00:00 2001 From: apocalypse9949 Date: Sat, 14 Mar 2026 23:47:01 +0530 Subject: [PATCH 3/3] de --- unionfind/unionfind.go | 1 + 1 file changed, 1 insertion(+) diff --git a/unionfind/unionfind.go b/unionfind/unionfind.go index b1f934d..d15167c 100644 --- a/unionfind/unionfind.go +++ b/unionfind/unionfind.go @@ -173,6 +173,7 @@ func (uf UnionFind) Copy() UnionFind { // UnifyTermsExtend unifies two same-length lists of relational terms, returning // an extended UnionFind. It does not handle apply-expressions. // The caller needs to ensure that none of the variables is "_" and none of the variables appears among the terms. +// The caller also needs to ensure that the base UnionFind is consistent with the new terms. func UnifyTermsExtend(xs []ast.BaseTerm, ys []ast.BaseTerm, base UnionFind) (UnionFind, error) { if len(xs) != len(ys) { return UnionFind{}, fmt.Errorf("not of equal size")