CS240A, Winter 98.


Project 1, Part 1

The first objective of this project is to add a time domain to Datalog. Although we will assume the Gregorian Calendar, and a very simplified temporal domain, the task is hardly trivial.

In Part 2 of this project, we use this representation for defining an extension of Datalog akin to TSQL2

Dates

Comparisons

When the dates being compared have different granularities, an implicit conversion to the coarser granularity is performed.

Intervals

These are represented by the following two terms: months(Months) and days(Days)

Thus we have two types of intervals, as in SQL2 (but we do not allow things such as YEAR TO MONTH)

Mixing Dates and Intervals in Computations

When the first two arguments have different granularities, an implicit conversion to the coarser granularity is performed.

Queries to be Implemented

You must implement the Gregorian Calendar (you can assume that the year is after 1800 AD) to support the following Queries:
  1. Given a year, and a month, print the calendar for that month: i.e., list the month, day, year, and day of the week.

  2. A bank keeps a database of CDs (certificates of deposit) as follows:

    cd(CD#, Deposit_Date, Duration, Interest_to_Maturity)

    (Duration is a time interval expressed in days)

    You must implement the following query which computes the actual interest paid at a given date.

    pay($CD, $Withd_date, Interest_paid)

    The rules to compute the interest are as follows:

    1. zero interest is paid if the CD is redeemed before half of its Duration days have elapsed,
    2. if the CD is redeemed after half of its Duration days have elapsed, but before maturity, then pay 0.01 % interest for each day between deposit and withdrawl,
    3. if the CD is redeemed at maturity, then pay the Interest_to_Maturity ,
    4. if the CD is redeemed after maturity, then pay the Interest_to_Maturity plus 0.01 % interest for each day after maturity.
    5. Use simple interest (no interest on interest).

    Project 1, Part 2

    Example 6.2 in the textbook is modified as follows:

    • drop the transaction time,

    • use a point-based representation of valid time (with granularities days).

    Thus short sample of the database might be as follows:

    prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1996,12,31)).
    prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,01)).
    prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,02)).
    
    prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,02)).
    prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,03)).
    
    prescript('Melanie', 'Beren', 'Prozac', 100mg, 360, date(1997,01,06)).
    
    prescript('Sally', 'Beren', 'Prozac', 100mg, 360, date(1997,01,03)).
    prescript('Sally', 'Beren', 'Prozac', 100mg, 360, date(1997,01,04)).
    prescript('Sally', 'Beren', 'Prozac', 100mg, 360, date(1997,01,0)).
    

    Define a LDL++ schema for this fact base, and then express the following queries:

    1. The queries in Examples 6.3, 6.5, and 6.6

    2. The queries in Examples 6.7, and 6.8 (You might want to use aggregates here. Also in Example 6.7 replace "six months" with "180 days", to avoid recasting)

    3. For a more challenging undertaing, express the query of Example 6.11 (also here, replace "six months" with "180 days")