MCPcopy
hub / github.com/google/mangle / UnifyTerms

Function UnifyTerms

unionfind/unionfind.go:144–162  ·  view source on GitHub ↗

UnifyTerms unifies two same-length lists of relational terms. It does not handle apply-expressions.

(xs []ast.BaseTerm, ys []ast.BaseTerm)

Source from the content-addressed store, hash-verified

142// UnifyTerms unifies two same-length lists of relational terms. It does not handle
143// apply-expressions.
144func UnifyTerms(xs []ast.BaseTerm, ys []ast.BaseTerm) (UnionFind, error) {
145 if len(xs) != len(ys) {
146 return UnionFind{}, fmt.Errorf("not of equal size")
147 }
148 uf := UnionFind{make(map[ast.BaseTerm]ast.BaseTerm)}
149 var newXs []ast.BaseTerm
150 var newYs []ast.BaseTerm
151 for i, x := range xs {
152 y := ys[i]
153 if x.Equals(ast.Variable{"_"}) || y.Equals(ast.Variable{"_"}) {
154 continue
155 }
156 uf.parent[x] = x
157 uf.parent[y] = y
158 newXs = append(newXs, x)
159 newYs = append(newYs, y)
160 }
161 return uf, unifyTermsUpdate(newXs, newYs, uf)
162}
163
164// UnifyTermsExtend unifies two same-length lists of relational terms, returning
165// an extended UnionFind. It does not handle apply-expressions.

Callers 5

TestEmptyArrayProgramFunction · 0.92
CheckFactMethod · 0.92
TestUnifyPositiveFunction · 0.85
TestUnifyNegativeFunction · 0.85
unionFindFromMapFunction · 0.85

Calls 2

unifyTermsUpdateFunction · 0.85
EqualsMethod · 0.65

Tested by 4

TestEmptyArrayProgramFunction · 0.74
TestUnifyPositiveFunction · 0.68
TestUnifyNegativeFunction · 0.68
unionFindFromMapFunction · 0.68