--> **************************************************************** --> Generic Sequences --> **************************************************************** --> ---------------------------------------------------------------- --> SEQ: sequences (i.e. associative list) with {id: emp} --> ---------------------------------------------------------------- mod! SEQ (X :: TRIV) { [Elt < Seq] -- empty Sequence op emp : -> Seq {constr} . op __ : Seq Seq -> Seq {constr assoc id: emp} . } --> ================================================================ --> basic tests for SEQ --> ---------------------------------------------------------------- open SEQ(NAT) . sh op __ . red (1 2) 3 = 1 (2 3) . red (1 2) (3 4) = 1 (2 3) 4 . red 1 2 emp = 1 emp 2 . close --> ================================================================ --> predicate to check --> whether there exit at least three 1s in a Seq --> ---------------------------------------------------------------- open SEQ(NAT) . pred atLeastThee1s : Seq . eq atLeastThee1s(S:Seq) = ((S1:Seq 1 S2:Seq 1 S3:Seq 1 S4:Seq) := S) . red atLeastThee1s(1 2 3) . red atLeastThee1s(1 1 1) . red atLeastThee1s(1 2 3 1 4) . red atLeastThee1s(1 2 3 1 4 1) . red atLeastThee1s(1 2 3 1 4 5 6 7 8 9 10) . close --> ---------------------------------------------------------------- --> TRIV=: TRIV with _=_ --> ---------------------------------------------------------------- mod* TRIV= { [Elt] -- equality on Elt pred _=e_ : Elt Elt {comm} . eq (E:Elt =e E) = true . cq [:nonexec]: E1:Elt = E2:Elt if (E1 =e E2) . } --> ---------------------------------------------------------------- --> SEQ=: SEQ with _=_ --> ---------------------------------------------------------------- mod! SEQ= (X :: TRIV=) { pr(SEQ(X)) -- equality on Seq pred _=s_ : Seq Seq {comm} . eq (S:Seq =s S:Seq) = true . cq [:nonexec]: S1:Seq = S2:Seq if (S1 =s S2) . -- for the case if either side is emp and other side is non-emp eq (emp =s (S1:Seq E:Elt S2:Seq)) = false . -- for the case if both sides are non-emp eq (E1:Elt S1:Seq =s E2:Elt S2:Seq) = ((E1 =e E2) and (S1 =s S2)) . } ** if _=e_ and _=s_ are not distinguished ** the last eq can be instantiated to ** eq (E1:Elt = E2:Elt) = (E1 = E2) . ** that causes an infinite loop --> ================================================================ --> basic tests for SEQ= --> ---------------------------------------------------------------- open SEQ=(NAT{op (E1:Elt =e E2:Elt) -> (E1:Nat = E2:Nat)}) . red 1 =s 2 . red 1 =s 1 2 . red 1 2 =s 1 3 . red 1 2 =s 1 2 . close open SEQ=(NAT{op (E1:Elt =e E2:Elt) -> (E1:Nat == E2:Nat)}) . red 1 =s 2 . red 1 =s 1 2 . red 1 2 =s 1 3 . red 1 2 =s 1 2 . close --> **************************************************************** --> end of file eof --> ****************************************************************