Skip to content

Commit 18b050e

Browse files
authored
Merge pull request #17 from anurag-rai/unify
Add Unify markdown
2 parents cf19759 + 10ec6b1 commit 18b050e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ The file [aima3e-algorithms.pdf](https://github.com/aimacode/pseudocode/blob/mas
188188
<tr>
189189
<td colspan="3"><hr/></td>
190190
</tr>
191+
<tr>
192+
<td align="center">&bull;</td>
193+
<td align="center"></td>
194+
<td><a href="md/Unify.md">UNIFY</a></td>
195+
</tr>
191196
<tr>
192197
<td align="center">&bull;</td>
193198
<td align="center"></td>

md/Unify.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# UNIFY
2+
3+
## AIMA3e
4+
__function__ UNIFY(_x_, _y_, _&theta;_) __returns__ a substitution to make _x_ and _y_ identical
5+
&emsp;__inputs__: _x_, a variable, constant, list, or compound
6+
&emsp;&emsp;&emsp;&emsp;_y_, a variable, constant, list, or compound
7+
&emsp;&emsp;&emsp;&emsp;_&theta;_, the substitution built up so far (optional, defaults to empty)
8+
9+
&emsp;__if__ _&theta;_ = failure __then return__ failure
10+
&emsp;__else if__ _x_ = _y_ __then return__ _&theta;_
11+
&emsp;__else if__ VARIABLE?(_x_) __then return__ UNIVY-VAR(_x_, _y_, _&theta;_)
12+
&emsp;__else if__ VARIABLE?(_y_) __then return__ UNIFY-VAR(_y_, _x_, _&theta;_)
13+
&emsp;__else if__ COMPOUND?(_x_) and COMPOUND?(_y_) __then__
14+
&emsp;&emsp;&emsp;__return__ UNIFY(_x_.ARGS, _y_.ARGS, UNIFY(_x_.OP, _y_.OP, _&theta;_))
15+
&emsp;__else if__ LIST?(_x_) __and__ LIST?(_y_) __then__
16+
&emsp;&emsp;&emsp;__return__ UNIFY(_x_.REST, _y_.REST, UNIFY(_x_.FIRST, _y_.FIRST, _&theta;_))
17+
&emsp;__else return__ failure
18+
19+
---
20+
__function__ UNIFY-VAR(_var_, _x_, _&theta;_) __returns__ a substitution
21+
22+
&emsp;__if__ {_var_ / _val_} &isin; _&theta;_ __then return__ UNIFY(_val_, _x_, _&theta;_)
23+
&emsp;__else if__ {_x_ / _val_} &isin; _&theta;_ __then return__ UNIFY(_var_, _val_, _&theta;_)
24+
&emsp;__else if__ OCCUR-CHECK?(_var_, _x_) __then return__ failure
25+
&emsp;__else return__ add {_var_/_x_} to _&theta;_
26+
27+
---
28+
__Figure__ ?? The unification algorithm. The algorithm works by comparing the structures of the inputs, elements by element. The substitution _&theta;_ that is the argument to UNIFY is built up along the way and is used to make sure that later comparisons are consistent with bindings that were established earlier. In a compound expression, such as F(A, B), the OP field picks out the function symbol F and the ARGS field picks out the argument list (A, B).

0 commit comments

Comments
 (0)