G2 Lab 1
Creating a Graphical
Language
You will create a graphical calculator language.
I have created a knowledgebase called GRAPHIC-LANGUAGE.KB. It is the beginning of a graphical language for performing numerical calculations. This kb is in the same directory as g2 ( /usr/local/gensym/g2-8.0r1/g2/ ).
When you load the GRAPHIC-LANGUAGE.KB, start g2 and wait for the initialization to occur. I have used some Gensym modules (specifically for the little dialog I use to enter data) in this kb, and those modules need to initialize themselves at the start. You will know initialization is complete when a row of menu choices appears at the top of the screen.
On the workspace called DEFINITIONS I have started a class hierarchy of GRAPHIC-LANGUAGE-BLOCK, and I have created a subclass of CONNECTION called DATA-CONDUIT that I use to connect instances of GRAPHIC-LANGUAGE-BLOCKs. I have also created a number of rules and procedures that work with the classes to allow users to enter data, create sums, and display results.
Look at the class definitions and note the class-specific-attributes of each class. Read and understand the way the rules and procedures work. The rules are “whenever” rules that respond to events. In this example, all the events concern the arrival of new data for an attribute of an object or connection.
On the workspace called LOGIC you will find an example of some DATA-ENTRY blocks feeding numbers to an ADDITION block, which then passes the total on to a DATA-DISPLAY block.
Add to the DEFINIONS workspace classes for SUBTRACTION, MULTIPLICATION, DIVISION, SQUARE-ROOT, AVERAGE, POWER, FACTORIAL, and MOD. Add appropriate rules and procedures to make them work with the other GRAPHIC-LANGUAGE-BLOCKs. Use a data type of FLOAT to permit computation with large numbers.
Your MULTIPLICATION and AVERAGE class should work for any number of connected data sources (e.g., 2 * 5 * 7 * 3 is OK).
Your DIVISION, SUBTRACTION, POWER, and MOD blocks should have only 2 inputs, and it must be clear which is which. Find a way to make it clear on the class instance icon which stub is for which purpose. For example, it is important to know which input is the dividend, and which is the divisor, in the case of the DIVISION block. Likewise, it is important to know which input of the SUBTRACTION block will be subtracted from the other, and it is important to know which input of the POWER block is the base and which is the exponent, etc.
If your DIVISION block detects a zero in the divisor, it should not compute an answer, and should instead issue a message using ‘inform the operator that “...”’. Likewise, if the SQUARE-ROOT block is asked to compute the square root of a negative number, it should refuse and ‘inform the operator that “...”’.
Your SQUARE-ROOT and FACTORIAL blocks should have only 1 input.
All your GRAPHIC-LANGUAGE-BLOCKs should have a single output of connection class DATA-CONDUIT.
If the DEFINITIONS workspace gets too big and busy to be convenient, go ahead and move some of the definitions onto another workspace. Remember to name the workspace so that you can find it again later.
Your kb
should be named XYZ-GRAPHIC-LANGUAGE.KB, where ‘XYZ’ are your initials.
After loading the initial kb from the g2 directory, save your kb in your
own directory structure.
Required: Your LOGIC workspace should implement a solution to the combination problem of finding the number of combinations of 30 things taken 2 at a time. The formula for the number of combinations of n things taken k at a time is: n!/(k!(n-k)!)
Think of this as the count of all pairs of people in a room of thirty. As an additional learning outcome, think of what the answer means for the probability of some two people in a room sharing a birthday. This knowledge make a good "bar trick." Challenge the customers of a gathering place with a bet that some pair of people in the room will share a birthday. Take whatever wagers you can get, because the probability that at least one pair of people will share a birthday is almost a certainty, if the room contains about 30 people!
You should
also create various diagrams on your LOGIC workspace to verify the correct operation of your blocks.
Submit
your work by attaching your kb to an e-mail to me.
12.5
points for each GRAPHIC-LANGUAGE-BLOCK class.