Description | Tasks | Deliverables and Turnin | Resources
| Date | Description |
| 16-Jan-07 | Palindromic numbers are natural numbers, that is integers greater than 0. Hence only natural numbers will be tested, and a similar rationale applies to the reverse( ) function. [SBB] |
| 12-Jan-07 | Fixed a typo with the reverse function declaration in part 3 [NF] |
| 10-Jan-07 | Original Winter 2007 release. |
The first class assignment is intended to familiarize you with the Onyx programming language as well as OXML. Onyx is a derived from XQuery, the W3C Standard XML query language. We have set up a web interface at the URL http://ieng6.ucsd.edu:6606/interpreter.jsp to enable you to submit Onyx programs. (The built-in document( ) function is not usable via this interface, but is not needed in the assignment)
This assignment will give you a firm foundation for building your own Onyx interpreter, which you will implement in stages in three subsequent assignments.
Onyx provides several useful built-in functions for constructing OXML documents and for expressing powerful database queries. In this assignment, we'll restrict ourselves to OXML document construction and return to queries later on. We'll exercise the various parts of the Onyx language, including: expression evaluation, FLWR expressions, Onyx intrinsic (built-in) functions, and user-defined functions.
This assignment contains 4 tasks. See the Deliverables and Turnin section below for how to turn in the assignment.
Part 1: Recall Euclidean Algorithm for computing the greatest common divisor (GCD) of two numbers:
function gcd(a, b) if b = 0 return a else return gcd(b, a mod b)
Write an Onyx function to compute the GCD of its two arguments a and b.
Technical Details - Your solution program (A0-1.xqy) must define a function gcd() with signature
gcd($a as onyx.types.Integer, $b as onyx.types.Integer) as onyx.types.Integer
which returns the gcd of $a and $b. There should only be function definitions in the submitted file-- remove any program body before submission.
Part 2: Write an Onyx function to check if a natural number (integer greater than zero) is a palindromic number. [1/16/007] A number is palindromic if its first and last digits are the same, and the remaining digits between them are also a palindromic number. Thus, 1234321 is palindromic, but 1234123 is not. You may adapt the string algorithm located at http://cse.unl.edu/~dsadofs/RecursionTutorial/index.php?s=algorithms for this assignment, but you are free to use whatever algorithm you wish. Be sure to document, in your TeamEval document, the source of any algorithm you used (that document is described below).
Technical Details - Your solution program (A0-2.xqy) must define the function
which returns true if $a is a palindromic number, and false otherwise. There should only be function definitions in the submitted file-- remove any program body before submission. palindrome($a as onyx.types.Integer) as onyx.types.BooleanPart 3: Write an Onyx program to reverse the digits of an integer, ie. reverse(56798) = 89765
Technical Details - This function will not be tested against numbers ending in one or more zeros, since the leading zeros won't appear in the Onyx output line. Only natural numbers (positive integers) will be tested. [1/16/007] Your solution code (A0-3.xqy) must contain a function
which returns the 'reverse' of $a. There should only be function definitions in the submitted file-- remove any program body before submission. reverse($a as onyx.types.Integer) as onyx.types.Integer [1/12/07]Part 4. Write an Onyx function to generate a square multiplication table for the integers 1 through n. That is, the table will be n × n. Use the format shown as follows, which is given for the case of an 8x8 table.
<?xml version="1.0" encoding="UTF-8"?>
<onyx-result>
<mpy-table>
<x1>[1 2 3 4 5 6 7 8]</x1>
<x2>[2 4 6 8 10 12 14 16]</x2>
<x3>[3 6 9 12 15 18 21 24]</x3>
<x4>[4 8 12 16 20 24 28 32]</x4>
<x5>[5 10 15 20 25 30 35 40]</x5>
<x6>[6 12 18 24 30 36 42 48]</x6>
<x7>[7 14 21 28 35 42 49 56]</x7>
<x8>[8 16 24 32 40 48 56 64]</x8>
</mpy-table>
</onyx-result>
Note the appearance of the square brackets. This comes as a result of the rules that Onyx uses to convert from Sequence to String (This offers a hint of how to proceed).
Technical Details - Your solution program (A0-4.xqy) must define a function
table($n as onyx.types.Integer) as onyx.types.ENode
which returns the top level tag <mpy-table> square multiplication table of size $n × $n. There should only be function definitions in the submitted file-- remove any program body before submission.
To write this code, you'll need to use built-in functions for generating XML content: constructors enode() and tnode() as well as addChildNode(). These are documented in the Onyx2 Semantic Specification. Break down the programming task into pieces. First, write code to generate the lone <mpy-table> element. Then, write the code to generate the row elements <x1>, <x2>, and so on. Finally, populate the table.
Provide four XQuery program files to be turned in, each corresponding to one part of the assignment. They should be named as follows:
Onyx writes its results to standard output and standard error. The generated output to these streams will be used for grading. We will compare your output to a reference output (our solution). For this assignment, output files that are equivalent according to xmldiff -ns will be counted as equivalent.
In addition to your assignment, you must include three other files:
Complete the documents. These are required files!Assignments that do not include a properly completed DECLARATION, MEMBERS, and TeamEval files will not receive a grade and will be treated as late assignments.
Turnin Procedure
+ Make sure to prep into cs131w, as this sets up the environment. (issue prep
cs131w if not already done so)
+ From the directory containing your .xqy, MEMBERS, DELCARATION and TeamEval
files, run the command TURNIN.A0 and follow the dialog.
You can run this command as many times as you want up until the assignment deadline;
any earlier turnin of yours will just be overwritten. We recommended that you
run the command early, as soon as you have a partial solution to the assignment.
This will help you establish that the turnin mechanism is working for you.
DON'T WAIT UNTIL THE LAST MINUTE TO RUN TURNIN FOR THE FIRST TIME!!!
Often problems are uncovered when running TURNIN. You'll need to resolve these problems before your submission can be accepted. Waiting until the last minute to run TURNIN.A0 for the first time per assignment is done at your own risk!
Late assignments will not be accepted.
You may wish to use the utilities xmlpp and xmldiff, described on the Resources page.