Mathematical String Notation 7 January 2019 OSU CSE 1 String - - PowerPoint PPT Presentation

mathematical string notation
SMART_READER_LITE
LIVE PREVIEW

Mathematical String Notation 7 January 2019 OSU CSE 1 String - - PowerPoint PPT Presentation

Mathematical String Notation 7 January 2019 OSU CSE 1 String Theory A mathematical model that we will use often is that of mathematical strings A string can be thought of as a series of zero of more entries of any other mathematical


slide-1
SLIDE 1

Mathematical String Notation

7 January 2019 OSU CSE 1

slide-2
SLIDE 2

String Theory

  • A mathematical model that we will use
  • ften is that of mathematical strings
  • A string can be thought of as a series of

zero of more entries of any other mathematical type, say, T

– T is called the entry type – We will call this math type string of T

7 January 2019 OSU CSE 2

slide-3
SLIDE 3

String ≠ string

  • String is a programming type in Java,

and string is a mathematical type (often used to model program types)

  • Since we call the mathematical model of

the Java primitive type char by the name character, we have:

type String is modeled by string of character

7 January 2019 OSU CSE 3

slide-4
SLIDE 4

Math Notation for Strings

  • The following notations are used when we

write mathematics (e.g., in contract specifications) involving strings

  • Notice two important features of strings:

– There may be duplicate entries (in fact, there may be arbitrarily many of a given entry value) – The order of the entries is important

7 January 2019 OSU CSE 4

slide-5
SLIDE 5

The Empty String

  • The empty string, a string with no entries

at all, is denoted by < > or by empty_string

7 January 2019 OSU CSE 5

slide-6
SLIDE 6

Denoting a Specific String

  • A particular string can be described by

listing its entries between < and > separated by commas

  • Examples:

< 1, 2, 3, 2 > < 'G', 'o' > < >

7 January 2019 OSU CSE 6

slide-7
SLIDE 7

Denoting a Specific String

  • A particular string can be described by

listing its entries between < and > separated by commas

  • Examples:

< 1, 2, 3, 2 > < 'G', 'o' > < >

7 January 2019 OSU CSE 7

A string of integer value whose entries are the integer values 1, 2, 3, and 2.

slide-8
SLIDE 8

Denoting a Specific String

  • A particular string can be described by

listing its entries between < and > separated by commas

  • Examples:

< 1, 2, 3, 2 > < 'G', 'o' > < >

7 January 2019 OSU CSE 8

A string of character value whose entries are the character values 'G' and 'o'.

slide-9
SLIDE 9

Denoting a Specific String

  • A particular string can be described by

listing its entries between < and > separated by commas

  • Examples:

< 1, 2, 3, 2 > < 'G', 'o' > < >

7 January 2019 OSU CSE 9

We may also use the special notation "Go" for the same string of character value.

slide-10
SLIDE 10

Denoting a Specific String

  • A particular string can be described by

listing its entries between < and > separated by commas

  • Examples:

< 1, 2, 3, 2 > < 'G', 'o' > < >

7 January 2019 OSU CSE 10

Now it can be seen that this notation for empty_string is a special case of the string literal notation.

slide-11
SLIDE 11

Concatenation

  • The concatenation of strings s and t, a

string consisting of the entries of s followed by the entries of t, is denoted by s * t

  • Examples:

< 1, 2 > * < 3, 2 > = < 1, 2, 3, 2 > < 'G', 'o' > * < > = < 'G', 'o' > < > * < 5, 2, 13 > = <5, 2, 13 > < > * < > = < >

7 January 2019 OSU CSE 11

slide-12
SLIDE 12

Concatenation

  • The concatenation of strings s and t, a

string consisting of the entries of s followed by the entries of t, is denoted by s * t

  • Examples:

< 1, 2 > * < 3, 2 > = < 1, 2, 3, 2 > < 'G', 'o' > * < > = < 'G', 'o' > < > * < 5, 2, 13 > = <5, 2, 13 > < > * < > = < >

7 January 2019 OSU CSE 12

As before, we may use the special notation for a string of character value and say: "Go" * "" = "Go"

slide-13
SLIDE 13

Concatenation

  • The concatenation of strings s and t, a

string consisting of the entries of s followed by the entries of t, is denoted by s * t

  • Examples:

< 1, 2 > * < 3, 2 > = < 1, 2, 3, 2 > < 'G', 'o' > * < > = < 'G', 'o' > < > * < 5, 2, 13 > = <5, 2, 13 > < > * < > = < >

7 January 2019 OSU CSE 13

The concatenation of Java String values uses + instead!

slide-14
SLIDE 14

Substring, Prefix, Suffix

  • We say s is substring of t iff the

entries of s appear consecutively in t

  • We say s is prefix of t iff the entries
  • f s appear consecutively at the beginning
  • f t
  • We say s is suffix of t iff the entries
  • f s appear consecutively at the end of t

7 January 2019 OSU CSE 14

slide-15
SLIDE 15

Substring, Prefix, Suffix

  • We say s is substring of t iff the

entries of s appear consecutively in t

  • We say s is prefix of t iff the entries
  • f s appear consecutively at the beginning
  • f t
  • We say s is suffix of t iff the entries
  • f s appear consecutively at the end of t

7 January 2019 OSU CSE 15

We say is not ... for the negation of each.

slide-16
SLIDE 16

Length

  • The length of a string s, i.e., the number
  • f entries in s, is denoted by |s|
  • Examples:

|< 1, 2, 3, 2 >| = 4 |< 'G', 'o' >| = 2 |< >| = 0

7 January 2019 OSU CSE 16

slide-17
SLIDE 17

Concise Notation for Substrings

  • The substring of s starting at position i

(inclusive) and ending at position j (exclusive) is denoted by s[i, j)

7 January 2019 OSU CSE 17

slide-18
SLIDE 18

Concise Notation for Substrings

  • The substring of s starting at position i

(inclusive) and ending at position j (exclusive) is denoted by s[i, j)

7 January 2019 OSU CSE 18

The position k of an entry in a string is a number satisfying 0 <= k < |s|.

slide-19
SLIDE 19

Concise Notation for Substrings

  • The substring of s starting at position i

(inclusive) and ending at position j (exclusive) is denoted by s[i, j)

7 January 2019 OSU CSE 19

This notation is well-defined whenever 0 <= i <= j <= |s|; for all other cases, the designated substring may be defined to be <> (though we will avoid using this).

slide-20
SLIDE 20

Concise Notation for Substrings

  • The substring of s starting at position i

(inclusive) and ending at position j (exclusive) is denoted by s[i, j)

  • Examples with s = "GoBucks":

s[0, |s|) = "GoBucks" s[2, |s|-1) = "Buck" s[1, 1) = "" s[2, 3) * s[5, 7) = "Bks"

7 January 2019 OSU CSE 20

slide-21
SLIDE 21

Reverse

  • The reverse of a string s, i.e., the string

with the same entries as s but in the

  • pposite order, is denoted by rev(s)
  • Examples:

rev(< 1, 2, 3, 2 >) = < 2, 3, 2, 1 > rev(< 'G', 'o' >) = < 'o', 'G' > rev(< >) = < >

7 January 2019 OSU CSE 21

slide-22
SLIDE 22

Permutations

  • The question whether strings s1 and s2

are permutations, i.e., whether they are simply reorderings of one another, is denoted by perms(s1, s2)

  • Examples:

perms(< 1, 2, 3 >, < 3, 1, 2 >) not perms(< 2, 2, 1 >, < 2, 1 >) perms(< >, < >)

7 January 2019 OSU CSE 22

slide-23
SLIDE 23

Occurence Count

  • The occurence count of an entry x in a

string s, i.e., the number of times x appears as an entry in s, is denoted by count(s, x)

  • Examples:

count(< 2, 2, 2, 1 >, 2) = 3 count(< 2, 2, 2, 1 >, 4) = 0 count(< 'G', 'o' >, 'G') = 1 count(< >, 13) = 0

7 January 2019 OSU CSE 23