in Education by
I'm working through my AI textbook I got and I've come to the last homework problem for my section: "Implement the Unification Algorithm outlined on page 69 in any language of your choice." On page 69, you have the following pseudo-code for the unification algorithm: function unify(E1, E2); begin case both E1 and E2 are constants or the empty list: if E1 = E2 then return {} else return FAIL; E1 is a variable: if E1 occurs in E2 then return FAIL else return {E2/E1} E2 is a variable if E2 occurs in E1 then FAIL else return {E1/E2} either E1 or E2 are empty then return FAIL otherwise: begin HE1 := first element of E1; HE2 := first element of E2; SUBS1 := unify(HE1, HE2); if SUBS1 := FAIL then return FAIL; TE1 := apply(SUBS1, rest of E1); TE2 := apply(SUBS1, rest of E2); S UBS2 := unify(TE1, TE2); if SUBS2 = FAIL then return FAIL; else return composition(SUBS1, SUBS2) end end end Now, I understand the general concept of unification but I have absolutely no idea how I would even begin to implement this in a language like Java or C#. I'm not even sure what the method signature would look like. What type of variables would it take? I'm fairly certain I need to return lists to represent predicate calculus constructs but that is a guess. For example, when it says "E1 is a variable", well, if I'm passing it into the Unify method, how could it be anything but? I could check for null but would that be different than "empty list"? Can anyone help me or point me in the right direction for implementing the Unification algorithm in C# or Java? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Normally in the OOP concept, we typically create an abstract base class Expression and derive other classes from it like List, Variable, or Constant. However, in my opinion, this is overkill. I implemented this in C# using the dynamic keyword. The next question is what does it return? A list of bindings that can be implemented as a Dictionary. Below is a piece of code from the C# implementation of implementation from a library called Jigsaw that I am developing for teaching how to implement languages C#. public static Dictionary Unify(dynamic e1, dynamic e2) { if ((IsConstant(e1) && IsConstant(e2))) { if (e1 == e2) return new Dictionary(); throw new Exception("Unification failed"); } if (e1 is string) { if (e2 is List && Occurs(e1, e2)) throw new Exception("Cyclical binding"); return new Dictionary() { { e1, e2 } }; } if (e2 is string) { if (e1 is List && Occurs(e2, e1)) throw new Exception("Cyclical binding"); return new Dictionary() { { e2, e1 } }; } if (!(e1 is List) || !(e2 is List)) throw new Exception("Expected either list, string, or constant arguments"); if (e1.IsEmpty || e2.IsEmpty) { if (!e1.IsEmpty || !e2.IsEmpty) throw new Exception("Lists are not the same length"); return new Dictionary(); } var b1 = Unify(e1.Head, e2.Head); var b2 = Unify(Substitute(b1, e1.Tail), Substitute(b1, e2.Tail)); You can find the rest of the code in the following link: http://www.cs.trincoll.edu/~ram/cpsc352/notes/unification.html

Related questions

0 votes
    I try to learn and implement a simple genetic algorithm library for my project. At this time, evolution, ... Gaussian distribution?.) Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to implement stochastic gradient descent in MATLAB however I am not seeing any convergence. Mini-batch ... cost of 420. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am currently working on an AI Agent that will be able to identify both the start state and the goal ... be greatly appreciated. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    From what I've read so far they seem very similar. Differential evolution uses floating point numbers instead, and ... of both. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am searching for information on algorithms to process text sentences or to follow a structure when creating sentences ... be great. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I am a little confused about the Hill Climbing algorithm. I want to "run" the algorithm until I found the ... question is too simple. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    The problem is that I cannot make a script that makes the enemy rotate so that "up" is pointing against the ... something simple... Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I write programs to play a board game variants sometimes. The basic strategy is standard alpha-beta pruning or ... human players. Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    In the MNIST beginner tutorial, there is the statement accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) tf ... (x,1)? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am looking for an open source neural network library. So far, I have looked at FANN, WEKA, and OpenNN. Are the ... , and ease of use. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    What is the difference between informed and uninformed searches? Can you explain this with some examples? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Like lots of you guys on SO, I often write in several languages. And when it comes to planning stuff, (or ... to this being possible? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm looking for some examples of robot/AI programming using Lisp. Are there any good online examples available ... in nature)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm teaching a kid programming, and am introducing some basic artificial intelligence concepts at the moment. To begin ... and boxes)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm looking to try and write a chess AI. Is there something I can use on the .NET framework (or maybe ... making a chess game? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
...