Standard Library

All relations are part of the sterling:stdLib reasoning module. Then, for example, the full name of the relation listed below as lookup is sterling:stdLib:lookup.

File: lists.sos

Module sterling:stdLib

/*
  Common judgments for lists
*/

/*Find the first item associated with the key*/
Fixed Judgment lookup : [(Key, Item)] Key Item

/*Holds if no items are associated with the key*/
Fixed Judgment no_lookup : [(Key, Item)] Key

/*Holds if the item is in the list*/
Fixed Judgment mem : Item [Item]

/*Holds if the item is NOT in the list*/
Fixed Judgment not_mem : Item [Item]

/*Splits the list into the item plus the rest of the list around it:
  select A Rest L*/
Fixed Judgment select : Item [Item] [Item]

/*Holds if the second list contains everything in the first list
  Permits duplication in the subset (e.g. subset [A, A] [A] holds)*/
Fixed Judgment subset : [A] [A]

/*Holds if the first list contains everything in the second list and
  the second list contains everything in the first list*/
Fixed Judgment permutation : [A] [A]

/*Count how many times an item occurs in a list*/
Fixed Judgment count : A [A] int

/*Domain of a list (first element of each pair)*/
Fixed Judgment domain : [(A, B)] [A]

/*Values of a pair list (second element of each pair)*/
Fixed Judgment values : [(A, B)] [B]

/*Combine two lists into a list of pairs*/
Fixed Judgment zip : [A] [B] [(A, B)]

/*Drop the first N elements of a list:
  drop N L Rest*/
Fixed Judgment drop : int [A] [A]

/*Take the first N elements of a list:
  take N L FirstN*/
Fixed Judgment take : int [A] [A]

/*Build a range list, inclusive*/
Fixed Judgment range : int int [int]



/*
  Rules
*/


=================================== [Lkp-Here]
lookup (Key, Value)::Rest Key Value


K != Key
lookup Rest Key Value
============================= [Lkp-Later]
lookup (K, V)::Rest Key Value




================ [NLkp-Nil]
no_lookup [] Key


K != Key
no_lookup Rest Key
========================== [NLkp-Cons]
no_lookup (K, V)::Rest Key




=================== [Mem-Here]
mem Item Item::Rest


mem Item Rest
================ [Mem-Later]
mem Item I::Rest




=============== [NMem-Nil]
not_mem Item []


I != Item
not_mem Item Rest
==================== [NMem-Cons]
not_mem Item I::Rest




=========================== [Slct-First]
select Item Rest Item::Rest


select Item L1 L2
======================= [Slct-Later]
select Item I::L1 I::L2




=========== [Sbst-Nil]
subset [] L


mem X Supset
subset Rest Supset
===================== [Sbst-Cons]
subset X::Rest Supset




================= [Prm-Nil]
permutation [] []


select A L2 L
permutation Rest L2
======================= [Prm-Cons]
permutation (A::Rest) L




============ [Cnt-Nil]
count X [] 0


count X Rest N
1 + N = N1
================== [Cnt-ConsEq]
count X X::Rest N1


X != Y
count X Rest N
================= [Cnt-ConsNEq]
count X Y::Rest N




============ [Dmn-Nil]
domain [] []


domain Rest DRest
============================ [Dmn-Cons]
domain (A, B)::Rest A::DRest




============ [Vals-Nil]
values [] []


values Rest VRest
============================ [Vals-Cons]
values (A, B)::Rest B::VRest




============ [Zip-Nil]
zip [] [] []


zip ARest BRest Rest
================================== [Zip-Cons]
zip A::ARest B::BRest (A, B)::Rest




========== [Drop-0]
drop 0 L L


1 + N1 = N
drop N1 L R
============= [Drop-Step]
drop N X::L R




=========== [Take-0]
take 0 L []


1 + N1 = N
take N1 L F
================ [Take-Step]
take N X::L X::F




Low > High
================= [Range-End]
range Low High []


Low <= High
1 + Low = PlusOne
range PlusOne High Rest
======================== [Range-Step]
range Low High Low::Rest

Extensibella Properties about the Standard Library

The Sterling standard library module also includes an Extensibella reasoning module with properties about its relations. These properties are all proven to hold.

Properties