[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [ MATHS ] / logic_30_Sets
[Contents] [Source Text] || [Notation] || [Copyright] || [Contact] [Search ]
Tue Sep 18 15:18:01 PDT 2007

Contents


    Sets

      This introduces set theory from the point of view of a computer professional using ASCII. For the traditional notation see [ sets.html ]

      There is a less formal introduction to this theory in [ intro_sets.html ]

      Rapid History

      Sets are implicit in much of Aristotlean logic (Ancient Greece... Medieval). George Cantor (1800's) developed the theory as part of his research into the mathematics of infinity. Sets rapidly became the language of modern mathematics. Russell (1990's) uncovered paradoxes in the Cantor theory. This lead to the Zermelo-Frankel axiomatic theory(THEORY below), Halmos's Naive set theory, and Whitehead and Russel's Theory of Types.

      Introduction

      These notes are about a language that lets talk both naturally and rigorously at the same time. Everyday language is full of references to sets of objects, classes, types of things, and on. The simple notation proposed here makes much of this rigorous. Sets also form a foundation for several more complex ideas which together form a simple yet effective way of talking about complex pieces of software - such IBM's CICS(Customer Information C?? Systems), elevators, or Hotel Bookings for example.

      For example, using the language of sets we can say:

    1. birds ==> fly, all birds fly.
    2. penguins ==> birds, penguins are birds.

      And so conclude (in the face of the evidence):

    3. penguins ==> fly.

      So we might rethink our assumptions:

    4. birds = flightless | flying. Birds are flying or flightless.

      This might lead us to think about how big the various sets are and conclude that most birds are not flightless...

      Types

      Every object belongs to a type T -- where the type describes the kind of things that can be done to the object or could produce objects of the type. For any type T there is an another type symbolized by @T with objects that are sets of objects of type T.

      .Note

    5. THEORY::=
      Net{
        The use of sets is only distantly related to the theories of sets developed my mathematicians and logicians between 1850 through about 1940: [ logic_32_Set_Theory.html ]


      }=::THEORY.
      A key point is that in theory one can re-express statements in MATHS that use sets into expressions that use predicates instead.

      Some sets are not types - A type by definition is a universal set or domain of discourse, but a set is determined by the type of element plus some rule(predicate) indicating what is in the set. We assume that whenever we have a set of some kind or other than it is a set of objects of the same type. However a subset (or a set for short) does belong to a type and so determines the types of the elements in it. It is therefore safe to use a subset of a type in a declaration of a variable of the right type, and with values/properties limited to those of the set(compare type and subtype in Ada).

      The restriction that each set has elements all of the same type is not a particularly restrictive rule given the freedom with which we can construct types as we need them.

      The main expressions involving sets in MATHS are:

      Set Expressions

        Constructors

        FormMeaningType(Notes)
        {} $() null set Ambiguous type.
        Tuniversal set @T
        {e1} $(e1) set(e1) singleton @T(e1:T)
        e1 {e1}@type(e1)(only if context requires a set)
        {e1,e2,e3,...} set(e1,e2,e3,...) $(e1,e2,e3,...) set of enumerated items@T(extension)
        {x:T || W(x)} {x:T. W(x)} $[x:T](W(x)) set(x:T WHERE W(x)) set of things satisfying a property W @T(intension)
        $ Net{...}structured settype(Net{...})
        $ Nameset of elements with structure Nametype(Name)

        There is also a more readable format that is suitable for large sets made up of complex objects -- [ Long Format ] below.

        Long Format Representation

        For example
      1. my_pets::@Animals=following,
        • stranger, AKA "Megan"
        • shadow
        • ginger

        The raw source code is:

         .Set
         	element
         	element, comment.
         	...
         .Close.Set
        An element in a long set can be several lines long. It starts with an indentation. Each element is an expression and may be terminated by a comma and a comment. Comments are ignored.

        Long sets are normally used with a definition like this:

         Name::@Type = following,
        When rendered for display or printing a long set should shown as an unordered list with each element marked with a bullet or similar marker.

        Enumerating Finite Sets

        In computing and software engineering we often need to introduce and then describe a finite set of distinct named elements. One way to this is:
          Instead of
           	T::Sets,
           	e1::T,
           	e2::T,
           	...
           	e[n]::T,
           	|- T = {e1,e2,...e[n]}.

        If the elements e1,e2,...,e[n] are distinct and free identifiers then the following syntax is natural short hand:
         	T::={e1,e2,...,e[n]}
        It defines T and declares the elements in T. For example:
         	Direction::={down, up}.
        means
           	Direction::Sets.
           	down::Direction.
           	up::Direction.
           	|- Direction={down, up}.

        Note, that the above does not guarantee that the elements have to be different -- even if we use different identifiers for the elements. As written, it is possible for some else to take our document and reuse it with a substitution which makes two variables the same. To stop this, and to be very clear about what we want we must add extra assumptions like this:

         	Direction::={down, up}.
         	|- down <> up.
        or
         	Lights::={Green, Amber, Red}.
         	|- 3 Lights.
        See Cardinality below. This is a little clumsy and counter-intuitive, and so I may add a new notation that handles this.

        If you want the elements to be in order then see [ math_77_Enumerations.html ]

        Set Operators

        SymbolsExampleMeaningType
        & ∩ ANDS1 & S2Intersection@T><@T->@T
        | ∪ ORS1|S2union@T><@T->@T
        ~ NOTS1 ~ S2Complement@T><@T->@T
        @ \powset SetOf@S1powerset,set_of_subsets@T->@@T
        >< ProductS1><S2Cartesian product@T><@T->@(T><T)

        Predicates

        SymbolsExampleMeaningType
        in ∈e1 in S1membershipT><@T->@
        <>S1 <> S2inequality@T><@T->@
        !=S1 != S2inequality@T><@T->@
        ==S1 == S2equality@T><@T->@
        ==> ARES1 ==> S2subset or equal@T><@T->@
        =>>S1 =>> S2proper subset@T><@T->@
        somesome S1S1<>{}@T->@
        -S1some S1@T->@
        nono S1S1={}@T->@
        allall S1S1=T@T->@
        andS1 and S2some(S1&S2)@T->@

      Syntax of Set Expressions

    6. propositional_expression::= set_theoretical_proposition |...,

    7. set_theoretical_proposition::= |[T:Types] (expression(T) "in" expression(@T) | expression(@T) "=" expression(@T) | expression(@T)),

    8. For T:Types, expression(@T)::= simple_set_expression | union | intersection,

    9. union::= SERIAL(intersection,"|"),
    10. intersection::= SERIAL(complementary_set_expression,"&"),
    11. complementary_set_expression::= Cartesian_product #(complement Cartesian_product)
    12. complement::="but_not" | "~", The text form is used in EBCDIC.
    13. Cartesian_product::= SERIAL(simple_set_expression, "><"). Note: Cartesian products are sets of pairs of elements and are actually a subset of a different type.

    14. simple_set_expression::=set_name | elementary_set |"("set_expression")" | set_of_sets | set_of_maps | set_of_relations | simple_set_expression"."relational_expression | relational_expression "("set_expression")".

    15. set_of_sets::= "@" simple_set_expression,

      New (Thu Aug 19 11:20:05 PDT 1999) and tentative alternative:


        A notation for all subsets of A with precisely n` elements: A@n.

      1. set_of_sets::= "@" simple_set_expression | simple_set_expression "@" expression(Nat).
      2. @A = { B | B==>A }.
      3. A@n = { B:@A | Card(B) = n }.

    16. elementary_set::= intention | extension | singleton | empty_set |type_name | "$"structure_description,
    17. empty_set::="{}"|"$()",
    18. intention::= "{" loose_binding #(","loose_binding ) "||" proposition "}" | "$" loose_bindings "(" proposition ")",
    19. extension::= finite_extension |informal_extension,
    20. finite_extension::="{" list_of_elements "}"| "$(" list_of_elements ")"
    21. informal_extension::= "{" list_of_elements "..." "}"|"$(" list_of_elements "..." ")",

      An informal extension will stop most automatic proof checkers from validating results.

    22. list_of_elements::= element #(punctuation element),
    23. singleton::= "{"element"}" | "$(" element ")".

    24. For Type T, e:T, e::@T={e}.

    25. element::= expression,

      MATHS has a special way to define a set - by describing it as a collection of tuples under some constraint. Any piece of documentation contains declarations and axioms that can be interpreted this way. Examples might be:

    26. my_circle::=$ Net{x,y:Real, x^2+y^2=y^2 },
    27. CIRCLE::=Net{x,y:Real, r:Real, x0,y0:Real, (x-x0)^2+(y-y0)^2=r^2 },
    28. (CIRCLE)|-my_circle=$ CIRCLE(r=>1, (x0,y0)=>(0,0)}

    29. structure_description::= "$" documentation, [ notn_13_Docn_Syntax.html ] and [ notn_14_Docn_Semantics.html ]

    30. structure_expression::=R(expression), [ notn_12_Expressions.html ]


    31. |-structure_expression= "(" identifier "=>" expression #( (|",") identifier "=>" expression) ")",

      Semantics of Set Expressions

        Definitions

        (intension_semantics): For Type T, W:predicate, x:variable(T), {x:T||W(x)}::@T= `set of all x in T that satisfy W(x)`.

        (in): For Type T, A:@T, t:T, t in A ::@=`it is true that t is a member of set A`.

      1. |- (set0): t in {x:T||W(x)} iff W(t).

        {}::@T= {x:T||false},

      2. T::@T= {x:T||true},

        (singleton_semantics): For a,b,c,...: T, {a}::@T={x:T||x=a}.

        (coerced_singleton): For a,b,c,...: T, a::@T={a}.

        (extension_semantics): For a,b,c,...: T, {a,b,c,...} ::@T= {a} | {b} | {c}|... .

        (projection_semantics): For f,x,W, {f(x) || for some x:T (W)}::= {y || for some x:T(y=f(x) and (W))}.

      3. For f,x,X,W, {f(x) || x:X}::= {y || for some x:X(y=f(x))}.

        Equality of sets


      4. |- (eqsets): for A,B:@T, if for all x:T(x in A iff x in B) then A=B.

        An object is a set when and only when membership solely determines equality. "Bags" have the same abstract operators as "Sets" but two bags are equal only when their members occur the same number of times in both Bags. Formally a "Bag of X's" is an object of type Nat^X. The most general form of this model will be found under [ semiring in math_41_Two_Operators ]

      5. For A,B:@T, A<>B iff not(A=B).

        Conveniences

      6. For x,y:T1, x is y::=(x = y),
      7. For x:T1,X:@T1, x is_a X::=(x in X).

        Cardinality

        How many elements are in this set?
      8. For X:@T, n:Nat0, |X| = n iff for n x:T (x:X).
      9. Card::@T->Nat0= map[X](|X|).

        Quantifiers expressed using sets

      10. For all X:@T, X=T iff for all x:T(x in X),

        A set in a context that demands a proposition is true iff there exists at least one member.

      11. For X:@T, X::@= for some x:T(x in X),

      12. For X:@T, for some x:T(x in X) = Card(X)>0.

      13. For X:@T, if |X|=1 then the(A)::= the(x:T||x in A).

        There are short hand ways of stating properties of sets so that they can be used easily:

      14. some(X)::= (X<>{}).
      15. no(X)::= (X={}).
      16. all(X)::= (X=T).
      17. A and B::= some (A & B).

        Here is a readable distfix expression:

      18. no A and B::= no (A & B).

        Set Operators

      19. For T:Types, A,B:@T, A & B::= {x:T || x in A and x in B} ,
      20. ::= "&".
      21. For T:Types, A,B:@T, A | B::= {x:T || x in A or x in B},
      22. ::= "|".
      23. For T:Types, A,B:@T, A ~ B::= {x:T || x in A and not x in B},
      24. "but_not"::="~".


      25. (above)|-(@T,|,{},&,T,~) in Boolean_algebra.


        (Cartesian products): these look like set expressions but are really part of the MATHS theory of types.

      26. For T:Types, A,B:@T, A><B::@(T><T)={ (a,b) || a in A and b in B }.


        (subset): predicates.

      27. For T:Types, A,B:@T, A==>B::= for all a in A(a in B),
      28. ::= "==>".
      29. A<==B::= B==>A.
      30. all A are B::= (A==>B).
      31. For T:Types, A,B:@T, A=>>B::= A ==>B and A<>B,
      32. ::= "=>>".
      33. A<<=B::= B=>>A.

        The Axiom of Choice

        MATHS assumes that given a collection of disjoint sets, then we can choose one member of each to be a representative of that set. Formally:

      34. Choice::@=For all A:Sets, π:partitions(A), some choice:π-->A, all B:π ( choice(B) in B).

        Notice that this assumption is obviously true for finite cases.... it is some the weirder infinite sets that make it doubtful.

        The following formally asserts that the axiom of choice is part of the MATHS system:

      35. |- (axiom_of_choice): Choice.

        This appears in other forms as part of the theory of relations and functions, [ Choice in logic_5_Maps ]

        See any good modern work on meta theory - Cohen.

        Also see Skolem functions in [ logic_5_Maps.html ]

      Proofs involving Sets

        The following proof patterns are common:
        To proveAssumeDeriveNotes
        A==>Ba:Ab:B
        no(A)a:ARAA
        A=Ba:Aa:BAnd also
        -b:Bb:A

        There are a large number of provable facts about sets

      1. (above)|- (glb): A<==A&B==>B.
      2. (above)|- (lub): A==>B|A<==B.

        There are also some easily proved derivation rules

      3. (above)|- (seteq): A=B iff A==>B and B==>A.
      4. (above)|- (converse): A==>B iff T~B==>T~A.
      5. (above)|- (barbara): If A==>B==>C then A==>C.
      6. (above)|- (celarent): If no A are B and all C are B then no C is B.
      7. (above)|- (darii): If all M is P and some S are M then some S are P.
      8. (above)|- (ferio): If no M is P and some S are M then some S are T~P.

        And so on thru most of the medieval catagorical syllogisms [ syllogisms.html ]

      Families of sets

      [ logic_31_Families_of_Sets.html ]

      MinTerms

    32. MINTERM::={ A:Sets, B:@A, p::=map[ a:A] (map b:B(a in b)). For each a in A there is an array of true/false values, one for each set in B, named p(a). We can partition A into cells of elements with the same array of values:
    33. P::=A/p Thus, given for a1,a2:A, a1 =/p a2, for all b:B, a1 in b iff a2 in b.


    }=::MINTERM.

    Tree by Knuth

      [Knuth 69, Vol 1, Section 2.3 Trees p305]

      A typical tree is T where


      1. T::=(nodes=>{1,1.1,1.2,1.2.3}, root=>1, m=>2, subtree=>(T1,T2)),
      2. T1:=(nodes=>{1.1}, root=>1.1, m=>0, subtree=>()),
      3. T2:=(nodes=>{1.2,1.2.3}, root=>1.2, m=>1, subtree=>(T3)),
      4. T3:=(nodes=>{1.2.3}, root=>1.2.3, m=>0, subtree=>()).

      Definition of a tree

    1. TREE::=
      Net{

      1. |-numbers.
      2. nodes::Finite(Sets),
      3. root::nodes,
      4. fan_out::Nat0,
      5. subtree::1..fan_out->@nodes, -- These are ordered trees
      6. |-nodes~{root}>== {subtree(i) || i:1..m},
      7. |-For all i:1..m, subtree(i) in $ TREE.

      }=::TREE.

      |-For T:$ TREE, i:Nat0, T[i]::=T.subtree[i].

      ??{convergence because lim |nodes|=0}??

    2. forest::={F:@TREES||for T1,T2:F(no T1&T2)}


    3. (above)|-if T:$ TREE then T~{root} in forest.

    Idea

    This is a new idea designed to handle natural expressions like flightless bird. An epithet is a word or phrase written in front of the name of a set (not an expression). It is always a subset of the named set.
  1. constrained_set_name::= #epithet set_name. Like this perhaps
  2. flightless bird

    There is a risk of confusion when talking about sets of strings.

    A formal justification for the syntax is by defining a prefix operator on sets of the correct type:

  3. flightless::prefix(@animal) = S+>{b:S. b can not fly}.
  4. For A:@Animal, flightless A::@Animal = {b:A. b can not fly}.

    Should this be abbreviated to

     		flightless::epithet(Animal) = `_ can not fly'.

. . . . . . . . . ( end of section Sets) <<Contents | End>>

Notes on MATHS Notation

Special characters are defined in [ intro_characters.html ] that also outlines the syntax of expressions and a document.

Proofs follow a natural deduction style that start with assumptions ("Let") and continue to a consequence ("Close Let") and then discard the assumptions and deduce a conclusion. Look here [ Block Structure in logic_25_Proofs ] for more on the structure and rules.

The notation also allows you to create a new network of variables and constraints. A "Net" has a number of variables (including none) and a number of properties (including none) that connect variables. You can give them a name and then reuse them. The schema, formal system, or an elementary piece of documentation starts with "Net" and finishes "End of Net". For more, see [ notn_13_Docn_Syntax.html ] for these ways of defining and reusing pieces of logic and algebra in your documents. A quick example: a circle = Net{radius:Positive Real, center:Point}.

For a complete listing of pages in this part of my site by topic see [ home.html ]

Notes on the Underlying Logic of MATHS

The notation used here is a formal language with syntax and a semantics described using traditional formal logic [ logic_0_Intro.html ] plus sets, functions, relations, and other mathematical extensions.

For a more rigorous description of the standard notations see

  • STANDARD::= See http://www.csci.csusb.edu/dick/maths/math_11_STANDARD.html

    Glossary

  • above::reason="I'm too lazy to work out which of the above statements I need here", often the last 3 or 4 statements. The previous and previous but one statments are shown as (-1) and (-2).
  • given::reason="I've been told that...", used to describe a problem.
  • given::variable="I'll be given a value or object like this...", used to describe a problem.
  • goal::theorem="The result I'm trying to prove right now".
  • goal::variable="The value or object I'm trying to find or construct".
  • let::reason="For the sake of argument let...", introduces a temporary hypothesis that survives until the end of the surrounding "Let...Close.Let" block or Case.
  • hyp::reason="I assumed this in my last Let/Case/Po/...".
  • QED::conclusion="Quite Easily Done" or "Quod Erat Demonstrandum", indicates that you have proved what you wanted to prove.
  • QEF::conclusion="Quite Easily Faked", -- indicate that you have proved that the object you constructed fitted the goal you were given.
  • RAA::conclusion="Reducto Ad Absurdum". This allows you to discard the last assumption (let) that you introduced.

    End