如何以Z表示法设计搜索操作,搜索功能至少需要一个细节?

时间:2015-04-20 05:20:50

标签: formal-methods z-notation

这是我的约会数据库的Z架构。

|--AppointmentDB----------------
|attendees : P Person /** those involved in the appointment **/
|
|/** a new TYPE object to store attendees, schedule and purpose **/
|appointments : P APPOINTMENT
|hasAppointment : Person <-> APPOINTMENT
|schedule : APPOINTMENT -> DateTime
|purpose : APPOINTMENT -> Report 
|
|/** a forward relation compositions to relate attendees with purpose and schedule **/
|attendeePurpose : hasAppointment;purpose 
|attendeeSchedule : hasAppointment;schedule 
|-----------------------------
|attendees ⊆ dom(hasAppointment)
|attendees ⊆ dom(attendeePurpose)
|appointments ⊆ ran(hasAppointment)
|-----------------------------

我想创建一个搜索功能,根据attendees的名称查找约会。

  1. 我希望搜索功能返回约会对象的所有细节。
  2. 我该如何设计?


    以下是我的观点:

    |--FindAppointment---------------------------------------------------
    |ΞAppointmentDB
    |attendees? : Person
    |appointmentAttendees! : P Person
    |appointmentPurpose! : Report
    |appointmentSchedule! : DateTime
    |-----------------------------
    |/** if name of any attendees is given, then it must exist in appointments' domain
    |respectively before this function can run**/
    |attendees? ∈ dom(attendees)
    |
    |/** return the set of attendees of the same APPOINTMENT using attendees? as input **/
    |appointmentAttendees! = hasAppointment~(|{attendees?}|)
    |
    |/** Get the image of both forward relational compositions according to set of 
    |attendees?**/
    |appointmentPurpose! =  attendeePurpose(|{attendees?}|)
    |appointmentSchedule! = attendeeSchedule(|{attendees?}|)
    |----------------------------------------------------------------------
    

1 个答案:

答案 0 :(得分:1)

您是否键入了检查规格? 您的声明subject? : P Person声明subject?是一组人,但subject? : dom(attendees)表示subject?是一个人。

  • 如果你想要一个人或一个人,你可以在函数式编程语言中引入类似于Maybe monad的数据类型(或其他编程语言中的null值):

    MaybePerson ::= NoPerson | JustPerson <<Person>>
    

    然后你可以声明像

    这样的输入
    subject? : MaybePerson
    

    然后我建议限制一个输入的可能解决方案

    subject? : ran(JustPerson) => schedule! : schedule(|{ JustPerson~ subject? }|)
    
  • 如果subject?是一组人,您可以通过以下方式实现相同目标:

    subject? /= {} => schedule! : schedule(|subject?|)
    

然后就其他可能的输入做同样的事情。您还可以添加一个条件,而不是两个条目都应该NoPerson。并非两个输入集都应为空。