From 637219d9068f8b2e9fd619a3e9c10168b7ecfdee Mon Sep 17 00:00:00 2001 From: Pat Morin Date: Mon, 3 Jun 2013 16:07:23 -0400 Subject: [PATCH] Lots of changes for AU press formatting and fixes --- java/junk/GeomVector.java | 3 +- java/junk/Point3D.java | 13 +- java/ods/ArrayDeque.java | 8 +- java/ods/BTree.java | 4 +- java/ods/BinaryTrie.java | 4 +- java/ods/LinearHashTable.java | 10 +- java/ods/RedBlackTree.java | 2 +- java/ods/SEList.java | 8 +- java/ods/SkiplistList.java | 4 +- java/ods/SkiplistSSet.java | 10 +- java/ods/XFastTrie.java | 6 +- latex/binarytrees.tex | 201 +-- latex/btree.tex | 2 +- latex/figs/24rb.ipe | 2 +- latex/figs/24tree-add.ipe | 2 +- latex/figs/24tree-remove.ipe | 2 +- latex/figs/arraydeque.ipe | 2 +- latex/figs/arrayqueue.ipe | 2 +- latex/figs/arraystack.ipe | 2 +- latex/figs/avl-rebalance.ipe | 2 +- latex/figs/binarytree-numbering.ipe | 2 +- latex/figs/binarytrie-add.ipe | 2 +- latex/figs/binarytrie-ex.ipe | 2 +- latex/figs/binarytrie-remove.ipe | 2 +- latex/figs/binarytrie.ipe | 2 +- latex/figs/bintree-traverse.ipe | 2 +- latex/figs/bintree.ipe | 2 +- latex/figs/bplustree.ipe | 2 +- latex/figs/bst-balanced.ipe | 2 +- latex/figs/bst-delete.ipe | 2 +- latex/figs/bst-example.ipe | 2 +- latex/figs/bst-path.ipe | 2 +- latex/figs/bst-splice.ipe | 2 +- latex/figs/bst-template-small.ipe | 2 +- latex/figs/bst-template.ipe | 2 +- latex/figs/btree-add.ipe | 2 +- latex/figs/btree-borrow.ipe | 9 +- latex/figs/btree-merge.ipe | 7 +- latex/figs/btree-remove-full.ipe | 2 +- latex/figs/btree-remove.ipe | 2 +- latex/figs/btree-split.ipe | 101 +- latex/figs/btree.ipe | 2 +- latex/figs/chainedhashtable.ipe | 2 +- latex/figs/comparison-tree-b.ipe | 2 +- latex/figs/comparison-tree.ipe | 2 +- latex/figs/countingsort.ipe | 2 +- latex/figs/dependencies.ipe | 2 +- latex/figs/dfs-cycle.ipe | 2 +- latex/figs/dllist-addbefore.ipe | 2 +- latex/figs/dllist.ipe | 2 +- latex/figs/dllist2.ipe | 2 +- latex/figs/dt.ipe | 2 +- latex/figs/dualarraydeque.ipe | 2 +- latex/figs/em.ipe | 2 +- latex/figs/eytzinger.ipe | 2 +- latex/figs/findit.ipe | 2 +- latex/figs/flippullpush.ipe | 2 +- latex/figs/flowchart.ipe | 2 +- latex/figs/gauss.ipe | 2 +- latex/figs/graph-bfs.ipe | 2 +- latex/figs/graph-dfs.ipe | 2 +- latex/figs/graph-example2.ipe | 2 +- latex/figs/graph.ipe | 2 +- latex/figs/harmonic.ipe | 2 +- latex/figs/heap-insert.ipe | 2 +- latex/figs/heap-remove.ipe | 2 +- latex/figs/heapsort.ipe | 2 +- latex/figs/list.ipe | 2 +- latex/figs/mathastext.sty | 1876 ++++++++++++++++++++++++ latex/figs/meldable-merge.ipe | 2 +- latex/figs/mergesort-recursion.ipe | 2 +- latex/figs/mergesort.ipe | 2 +- latex/figs/prioqueue.ipe | 2 +- latex/figs/queue.ipe | 2 +- latex/figs/quicksort.ipe | 2 +- latex/figs/radixsort.ipe | 2 +- latex/figs/rb-addfix.ipe | 2 +- latex/figs/rb-removefix.ipe | 2 +- latex/figs/rb-split.ipe | 2 +- latex/figs/rbst-probs-a.ipe | 2 +- latex/figs/rbst-probs-b.ipe | 2 +- latex/figs/rbst-records.ipe | 2 +- latex/figs/redblack-example.ipe | 2 +- latex/figs/rootisharraystack.ipe | 2 +- latex/figs/rotation.ipe | 2 +- latex/figs/scapegoat-insert.ipe | 2 +- latex/figs/selist-add-a.ipe | 2 +- latex/figs/selist-add-b.ipe | 2 +- latex/figs/selist-add-c.ipe | 2 +- latex/figs/selist-remove-a.ipe | 2 +- latex/figs/selist-remove-b.ipe | 2 +- latex/figs/selist-remove-c.ipe | 2 +- latex/figs/sim.ipe | 2 +- latex/figs/skiplist-add.ipe | 2 +- latex/figs/skiplist-addix.ipe | 2 +- latex/figs/skiplist-lengths-splice.ipe | 2 +- latex/figs/skiplist-lengths.ipe | 2 +- latex/figs/skiplist-remove.ipe | 2 +- latex/figs/skiplist-removei.ipe | 2 +- latex/figs/skiplist-searchpath.ipe | 2 +- latex/figs/skiplist-splice.ipe | 2 +- latex/figs/skiplist.ipe | 2 +- latex/figs/sllist.ipe | 2 +- latex/figs/split.ipe | 2 +- latex/figs/stack.ipe | 2 +- latex/figs/treap-delete-a.ipe | 2 +- latex/figs/treap-delete-b.ipe | 2 +- latex/figs/treap-delete-c.ipe | 2 +- latex/figs/treap-delete-d.ipe | 2 +- latex/figs/treap-insert-a.ipe | 2 +- latex/figs/treap-insert-b.ipe | 2 +- latex/figs/treap-insert-c.ipe | 2 +- latex/figs/treap-insert.ipe | 2 +- latex/figs/treap.ipe | 2 +- latex/figs/xfast-path.ipe | 2 +- latex/figs/yfast-add.ipe | 2 +- latex/figs/yfast-remove.ipe | 2 +- latex/figs/yfast-sample.ipe | 2 +- latex/figs/yfast.ipe | 2 +- latex/hashing.tex | 127 +- latex/heaps.tex | 82 +- latex/intro.tex | 2 +- latex/linkedlists.tex | 170 +-- latex/mathastext.sty | 1876 ++++++++++++++++++++++++ latex/ods.tex | 7 +- latex/rbs.tex | 23 +- latex/redblack.tex | 395 ++--- latex/scapegoat.tex | 44 +- latex/skiplists.tex | 133 +- latex/snarf-java.pl | 4 +- latex/sorting.tex | 76 +- 131 files changed, 4596 insertions(+), 815 deletions(-) create mode 100644 latex/figs/mathastext.sty create mode 100644 latex/mathastext.sty diff --git a/java/junk/GeomVector.java b/java/junk/GeomVector.java index d31cc0c8..be3c329a 100644 --- a/java/junk/GeomVector.java +++ b/java/junk/GeomVector.java @@ -21,7 +21,8 @@ public int hashCode() { long s = 0; long zi = 1; for (int i = 0; i < x.length; i++) { - long xi = (x[i].hashCode() * z2) >>> 1; // reduce to 31 bits + // reduce to 31 bits + long xi = (x[i].hashCode() * z2) >>> 1; s = (s + zi * xi) % p; zi = (zi * z) % p; } diff --git a/java/junk/Point3D.java b/java/junk/Point3D.java index 14ee0f36..6d7dfe7b 100644 --- a/java/junk/Point3D.java +++ b/java/junk/Point3D.java @@ -9,14 +9,17 @@ public boolean equals(Object o) { } public int hashCode() { - long[] z = {0x2058cc50L, 0xcb19137eL, 0x2cb6b6fdL}; // random - long zz = 0xbea0107e5067d19dL; // random - - long h0 = x0.hashCode() & ((1L<<32)-1); // unsigned int to long + // random numbers from rand.org + long[] z = {0x2058cc50L, 0xcb19137eL, 0x2cb6b6fdL}; + long zz = 0xbea0107e5067d19dL; + + // convert (unsigned) hashcodes to long + long h0 = x0.hashCode() & ((1L<<32)-1); long h1 = x1.hashCode() & ((1L<<32)-1); long h2 = x2.hashCode() & ((1L<<32)-1); - return (int)(((z[0]*h0 + z[1]*h1 + z[2]*h2)*zz) >>> 32); + return (int)(((z[0]*h0 + z[1]*h1 + z[2]*h2)*zz) + >>> 32); } public static void main(String[] args) { diff --git a/java/ods/ArrayDeque.java b/java/ods/ArrayDeque.java index 9d31c2c7..5fb77435 100644 --- a/java/ods/ArrayDeque.java +++ b/java/ods/ArrayDeque.java @@ -75,11 +75,11 @@ public T set(int i, T x) { public void add(int i, T x) { if (i < 0 || i > n) throw new IndexOutOfBoundsException(); if (n+1 > a.length) resize(); - if (i < n/2) { // shift a[0],..,a[i-1] left one position - j = (j == 0) ? a.length - 1 : j - 1; // (j-1) mod a.length + if (i < n/2) { // shift a[0],..,a[i-1] left one position + j = (j == 0) ? a.length - 1 : j - 1; //(j-1)mod a.length for (int k = 0; k <= i-1; k++) a[(j+k)%a.length] = a[(j+k+1)%a.length]; - } else { // shift a[i],..,a[n-1] right one position + } else { // shift a[i],..,a[n-1] right one position for (int k = n; k > i; k--) a[(j+k)%a.length] = a[(j+k-1)%a.length]; } @@ -94,7 +94,7 @@ public T remove(int i) { for (int k = i; k > 0; k--) a[(j+k)%a.length] = a[(j+k-1)%a.length]; j = (j + 1) % a.length; - } else { // shift a[i+1],..,a[n-1] left one position + } else { // shift a[i+1],..,a[n-1] left one position for (int k = i; k < n-1; k++) a[(j+k)%a.length] = a[(j+k+1)%a.length]; } diff --git a/java/ods/BTree.java b/java/ods/BTree.java index 4ee695c4..1f640e69 100644 --- a/java/ods/BTree.java +++ b/java/ods/BTree.java @@ -371,7 +371,7 @@ protected void merge(Node u, int i, Node v, Node w) { protected void checkUnderflowNonZero(Node u, int i) { Node w = bs.readBlock(u.children[i]); // w is child of u if (w.size() < B-1) { // underflow at w - Node v = bs.readBlock(u.children[i-1]); // v is left sibling of w + Node v = bs.readBlock(u.children[i-1]); // v left of w if (v.size() > B) { // w can borrow from v shiftLR(u, i-1, v, w); } else { // v will absorb w @@ -412,7 +412,7 @@ protected void shiftLR(Node u, int i, Node v, Node w) { protected void checkUnderflowZero(Node u, int i) { Node w = bs.readBlock(u.children[i]); // w is child of u if (w.size() < B-1) { // underflow at w - Node v = bs.readBlock(u.children[i+1]); // v is right sibling of w + Node v = bs.readBlock(u.children[i+1]); // v right of w if (v.size() > B) { // w can borrow from v shiftRL(u, i, v, w); } else { // w will absorb w diff --git a/java/ods/BinaryTrie.java b/java/ods/BinaryTrie.java index 24c7da76..2e4e32c7 100644 --- a/java/ods/BinaryTrie.java +++ b/java/ods/BinaryTrie.java @@ -93,8 +93,8 @@ public boolean add(T x) { if (u.child[c] == null) break; u = u.child[c]; } - if (i == w) return false; // trie already contains x - abort - Node pred = (c == right) ? u.jump : u.jump.child[0]; // save for step 3 + if (i == w) return false; // already contains x - abort + Node pred = (c == right) ? u.jump : u.jump.child[0]; u.jump = null; // u will have two children shortly // 2 - add path to ix for (; i < w; i++) { diff --git a/java/ods/LinearHashTable.java b/java/ods/LinearHashTable.java index 24ad2396..ee170be9 100644 --- a/java/ods/LinearHashTable.java +++ b/java/ods/LinearHashTable.java @@ -87,7 +87,7 @@ public boolean addSlow(T x) { int i = hash(x); while (t[i] != null) { if (t[i] != del && x.equals(t[i])) return false; - i = (i == t.length-1) ? 0 : i + 1; // increment i (mod t.length) + i = (i == t.length-1) ? 0 : i + 1; // increment i } t[i] = x; n++; q++; @@ -100,7 +100,7 @@ public boolean add(T x) { if (2*(q+1) > t.length) resize(); // max 50% occupancy int i = hash(x); while (t[i] != null && t[i] != del) - i = (i == t.length-1) ? 0 : i + 1; // increment i (mod t.length) + i = (i == t.length-1) ? 0 : i + 1; // increment i if (t[i] == null) q++; n++; t[i] = x; @@ -118,7 +118,7 @@ public boolean add2(T x) { while (t[i] != null) { if (t[i] == del && j == -1) j = i; if (t[i] != del && t[i].equals(x)) return false; - i = (i == t.length-1) ? 0 : i + 1; // increment i (mod t.length) + i = (i == t.length-1) ? 0 : i + 1; // increment i } t[j == -1 ? i : j] = x; n++; q++; @@ -131,7 +131,7 @@ public T find(T x) { int i = hash(x); while (t[i] != null) { if (t[i] != del && x.equals(t[i])) return t[i]; - i = (i == t.length-1) ? 0 : i + 1; // increment i (mod t.length) + i = (i == t.length-1) ? 0 : i + 1; // increment i } return null; } @@ -146,7 +146,7 @@ public T remove(T x) { if (8*n < t.length) resize(); // min 12.5% occupancy return y; } - i = (i == t.length-1) ? 0 : i + 1; // increment i (mod t.length) + i = (i == t.length-1) ? 0 : i + 1; // increment i } return null; } diff --git a/java/ods/RedBlackTree.java b/java/ods/RedBlackTree.java index 1b7243cf..2e38778a 100644 --- a/java/ods/RedBlackTree.java +++ b/java/ods/RedBlackTree.java @@ -146,7 +146,7 @@ protected void removeFixup(Node u) { u = removeFixupCase3(u); } } - if (u != r) { // restore left-leaning property, if necessary + if (u != r) { // restore left-leaning property if needed Node w = u.parent; if (w.right.color == red && w.left.color == black) { flipLeft(w); diff --git a/java/ods/SEList.java b/java/ods/SEList.java index 8a7d5f7b..7edacb2c 100644 --- a/java/ods/SEList.java +++ b/java/ods/SEList.java @@ -176,14 +176,14 @@ public void add(int i, T x) { u = u.next; r++; } - if (r == b) { // found b blocks each with b+1 elements + if (r == b) { // b blocks each with b+1 elements spread(l.u); u = l.u; } - if (u == dummy) { // ran off the end of the list - add new node + if (u == dummy) { // ran off the end - add new node u = addBefore(u); } - while (u != l.u) { // work backwards, shifting an element at each step + while (u != l.u) { // work backwards, shifting elements u.d.add(0, u.prev.d.remove(u.prev.d.size()-1)); u = u.prev; } @@ -201,7 +201,7 @@ public T remove(int i) { u = u.next; r++; } - if (r == b) { // found b blocks each with b-1 elements + if (r == b) { // b blocks each with b-1 elements gather(l.u); } u = l.u; diff --git a/java/ods/SkiplistList.java b/java/ods/SkiplistList.java index 32f1cbc4..c9c635c6 100644 --- a/java/ods/SkiplistList.java +++ b/java/ods/SkiplistList.java @@ -71,7 +71,7 @@ public SkiplistList() { protected Node findPred(int i) { Node u = sentinel; int r = h; - int j = -1; // the index of the current node in list 0 + int j = -1; // index of the current node in list 0 while (r >= 0) { while (u.next[r] != null && j + u.length[r] < i) { j += u.length[r]; @@ -111,7 +111,7 @@ protected Node add(int i, Node w) { j += u.length[r]; u = u.next[r]; } - u.length[r]++; // to account for new node in list 0 + u.length[r]++; // accounts for new node in list 0 if (r <= k) { w.next[r] = u.next[r]; u.next[r] = w; diff --git a/java/ods/SkiplistSSet.java b/java/ods/SkiplistSSet.java index 7c850c73..8bcde8ae 100644 --- a/java/ods/SkiplistSSet.java +++ b/java/ods/SkiplistSSet.java @@ -153,14 +153,15 @@ public boolean remove(T x) { int r = h; int comp = 0; while (r >= 0) { - while (u.next[r] != null && (comp = c.compare(u.next[r].x, x)) < 0) { + while (u.next[r] != null + && (comp = c.compare(u.next[r].x, x)) < 0) { u = u.next[r]; } if (u.next[r] != null && comp == 0) { removed = true; u.next[r] = u.next[r].next[r]; if (u == sentinel && u.next[r] == null) - h--; // skiplist height has gone down + h--; // height has gone down } r--; } @@ -241,14 +242,15 @@ public boolean add(T x) { int r = h; int comp = 0; while (r >= 0) { - while (u.next[r] != null && (comp = c.compare(u.next[r].x,x)) < 0) + while (u.next[r] != null + && (comp = c.compare(u.next[r].x,x)) < 0) u = u.next[r]; if (u.next[r] != null && comp == 0) return false; stack[r--] = u; // going down, store u } Node w = new Node(x, pickHeight()); while (h < w.height()) - stack[++h] = sentinel; // increasing height of skiplist + stack[++h] = sentinel; // height increased for (int i = 0; i < w.next.length; i++) { w.next[i] = stack[i].next[i]; stack[i].next[i] = w; diff --git a/java/ods/XFastTrie.java b/java/ods/XFastTrie.java index b855846a..3601c05e 100644 --- a/java/ods/XFastTrie.java +++ b/java/ods/XFastTrie.java @@ -129,8 +129,10 @@ public T find(T x) { } } if (l == w) return u.x; - Node pred = (((ix >>> w-l-1) & 1) == 1) ? u.jump : u.jump.child[0]; - return (pred.child[next] == dummy) ? null : pred.child[next].x; + Node pred = (((ix >>> w-l-1) & 1) == 1) + ? u.jump : u.jump.child[0]; + return (pred.child[next] == dummy) + ? null : pred.child[next].x; } public static void main(String[] args) { diff --git a/latex/binarytrees.tex b/latex/binarytrees.tex index ed3ba307..3c8b826e 100644 --- a/latex/binarytrees.tex +++ b/latex/binarytrees.tex @@ -3,12 +3,13 @@ \chapter{Binary Trees} This chapter introduces one of the most fundamental structures in computer science: binary trees. The use of the word \emph{tree} here comes from -the fact that, when we draw them, the resulting drawing often resembles -the trees we find in a forest. There are lots of ways of defining -binary trees. Mathematically, a \emph{binary tree} is a connected undirected -finite graph with no cycles, and no vertex of degree greater than three. +the fact that, when we draw them, the resultant drawing often resembles +the trees found in a forest. There are many ways of ways of defining +binary trees. Mathematically, a \emph{binary tree} is a connected, +undirected, finite graph with no cycles, and no vertex of degree greater +than three. -For most computer science applications, binary trees are \emph{rooted}: +For most computer science applications, binary trees are \emph{rooted:} A special node, #r#, of degree at most two is called the \emph{root} of the tree. For every node, $#u#\neq #r#$, the second node on the path from #u# to #r# is called the \emph{parent} of #u#. Each of the @@ -19,8 +20,8 @@ \chapter{Binary Trees} In illustrations, binary trees are usually drawn from the root downward, with the root at the top of the drawing and the left and right children respectively given by left and right positions in the drawing -(\figref{bintree-orientation}). A binary tree with nine nodes is drawn -this way in \figref{binary-tree}.a. +(\figref{bintree-orientation}). For example, \figref{binary-tree}.a shows +a binary tree with nine nodes. \begin{figure} \begin{center} @@ -44,33 +45,34 @@ \chapter{Binary Trees} \figlabel{binary-tree} \end{figure} -Binary trees are so important that a terminology has developed around them: -The \emph{depth} of a node, #u#, in a binary tree is the length of the -path from #u# to the root of the tree. If a node, #w#, is on the path -from #u# to #r# then #w# is called an \emph{ancestor} of #u# and #u# -a \emph{descendant} of #w#. The \emph{subtree} of a node, #u#, is the -binary tree that is rooted at #u# and contains all of #u#'s descendants. -The \emph{height} of a node, #u#, is the length of the longest path from -#u# to one of its descendants. The height of a tree is the height of its root. -A node, #u#, is a \emph{leaf} if it has no children. +Because binary trees are so important, a certain terminology has developed +for them: The \emph{depth} of a node, #u#, in a binary tree is the +length of the path from #u# to the root of the tree. If a node, #w#, +is on the path from #u# to #r#, then #w# is called an \emph{ancestor} +of #u# and #u# a \emph{descendant} of #w#. The \emph{subtree} of a +node, #u#, is the binary tree that is rooted at #u# and contains all +of #u#'s descendants. The \emph{height} of a node, #u#, is the length +of the longest path from #u# to one of its descendants. The height of +a tree is the height of its root. A node, #u#, is a \emph{leaf} if it +has no children. We sometimes think of the tree as being augmented with \emph{external -nodes}. Any node that does not have a left child has an external node -as its left child and any node that does not have a right child has an -external node as its right child (see \figref{binary-tree}.b). It is -easy to verify, by induction, that a binary tree having $#n#\ge 1$ -real nodes has $#n#+1$ external nodes. +nodes}. Any node that does not have a left child has an external +node as its left child, and, correspondinly, any node that does +not have a right child has an external node as its right child (see +\figref{binary-tree}.b). It is easy to verify, by induction, that a +binary tree with $#n#\ge 1$ real nodes has $#n#+1$ external nodes. \section{#BinaryTree#: A Basic Binary Tree} -The simplest way to represent a node, #u#, in a binary tree is -to store the (at most three) neighbours of #u# explicitly: +The simplest way to represent a node, #u#, in a binary tree is to +explicitly store the (at most three) neighbours of #u#: \javaimport{ods/BinaryTree.BTNode #u.x#$ then the search proceeds to #u.right#; -\item If $#x#= #u.x#$ then we have found the node #u# containing #x#. +\item If $#x#< #u.x#$, then the search proceeds to #u.left#; +\item If $#x#> #u.x#$, then the search proceeds to #u.right#; +\item If $#x#= #u.x#$, then we have found the node #u# containing #x#. \end{enumerate} The search terminates when Case~3 occurs or when #u=nil#. In the former case, we found #x#. In the latter case, we conclude that #x# @@ -203,15 +208,15 @@ \subsection{Searching} \codeimport{ods/BinarySearchTree.findEQ(x)} Two examples of searches in a binary search tree are shown in -\figref{bst-search}. As the second example shows, even if we don't find #x# -in the tree, we still gain some valuable information. If we look at -the last node, #u#, at which Case~1 occurred, we see that #u.x# is the smallest -value in the tree that is greater than #x#. Similarly, the last node -at which Case~2 occurred contains the largest value in the tree that is -less than #x#. Therefore, by keeping track of the last node, #z#, -at which Case~1 occurs, a #BinarySearchTree# can implement the #find(x)# -operation that returns the smallest value stored in the tree that is -greater than or equal to #x#: +\figref{bst-search}. As the second example shows, even if we don't +find #x# in the tree, we still gain some valuable information. If we +look at the last node, #u#, at which Case~1 occurred, we see that #u.x# +is the smallest value in the tree that is greater than #x#. Similarly, +the last node at which Case~2 occurred contains the largest value in the +tree that is less than #x#. Therefore, by keeping track of the last +node, #z#, at which Case~1 occurs, a #BinarySearchTree# can implement +the #find(x)# operation that returns the smallest value stored in the +tree that is greater than or equal to #x#: \codeimport{ods/BinarySearchTree.find(x)} \begin{figure} @@ -237,9 +242,9 @@ \subsection{Addition} \codeimport{ods/BinarySearchTree.findLast(x)} \codeimport{ods/BinarySearchTree.addChild(p,u)} An example is shown in \figref{bst-insert}. The most time-consuming -part of this process is the initial search for #x#, which takes time -proportional to the height of the newly added node #u#. In the worst -case, this is equal to the height of the #BinarySearchTree#. +part of this process is the initial search for #x#, which takes an +amount of time proportional to the height of the newly added node #u#. +In the worst case, this is equal to the height of the #BinarySearchTree#. \begin{figure} @@ -275,8 +280,8 @@ \subsection{Removal} the simplest thing to do is to find a node, #w#, that has less than two children such that we can replace #u.x# with #w.x#. To maintain the binary search tree property, the value #w.x# should be close to the -value of #u.x#. For example, picking #w# such that #w.x# is the smallest -value greater than #u.x# will do. Finding the node #w# is easy; it is +value of #u.x#. For example, choosing #w# such that #w.x# is the smallest +value greater than #u.x# will work. Finding the node #w# is easy; it is the smallest value in the subtree rooted at #u.right#. This node can be easily removed because it has no left child. (See \figref{bst-remove}) \codeimport{ods/BinarySearchTree.remove(u)} @@ -323,7 +328,7 @@ \subsection{Summary} time operations can be achieved with partial rebuilding operations. In \chapref{redblack} we show how $O(\log #n#)$ \emph{worst-case} time operations can be achieved by simulating a tree that is not binary: -a tree in which nodes can have up to four children. +one in which nodes can have up to four children. \section{Discussion and Exercises} @@ -343,31 +348,31 @@ \section{Discussion and Exercises} subsequent chapters. When implementing a binary tree from scratch, there are several design -decisions to be made. One of these is the question of whether or not each -node stores a pointer to its parent. If most of the operations simply -follow a root-to-leaf path, then parent pointers are unnecessary, and -are a potential source of coding errors. On the other hand, the lack of -parent pointers means that tree traversals must be done recursively or -with the use of an explicit stack. Some other methods (like inserting -or deleting into some kinds of balanced binary search trees) are also -complicated by the lack of parent pointers. - -Another design decision is concerned with how to store the parent, -left child, and right child pointers at a node. In the implementation -given here, they are stored as separate variables. Another option is -to store them in an array, #p#, of length 3, so that #u.p[0]# is the -left child of #u#, #u.p[1]# is the right child of #u#, and #u.p[2]# -is the parent of #u#. Using an array this way means that some sequences -of if statements can be simplified into algebraic expressions. +decisions to be made. One of these is the question of whether or not +each node stores a pointer to its parent. If most of the operations +simply follow a root-to-leaf path, then parent pointers are unnecessary, +waste space, and are a potential source of coding errors. On the other +hand, the lack of parent pointers means that tree traversals must be done +recursively or with the use of an explicit stack. Some other methods +(like inserting or deleting into some kinds of balanced binary search +trees) are also complicated by the lack of parent pointers. + +Another design decision is concerned with how to store the parent, left +child, and right child pointers at a node. In the implementation given +here, these pointers are stored as separate variables. Another option +is to store them in an array, #p#, of length 3, so that #u.p[0]# is the +left child of #u#, #u.p[1]# is the right child of #u#, and #u.p[2]# is +the parent of #u#. Using an array this way means that some sequences +of #if# statements can be simplified into algebraic expressions. An example of such a simplification occurs during tree traversal. If a traversal arrives at a node #u# from #u.p[i]#, then the next node in the traversal is $#u.p#[(#i#+1)\bmod 3]$. Similar examples occur when there is left-right symmetry. For example, the sibling of #u.p[i]# is -$#u.p#[(#i#+1)\bmod 2]$. This works whether #u.p[i]# is a left child -($#i#=0$) or a right child ($#i#=1$) of #u#. In some cases this means -that some complicated code that would otherwise need to have both a left -version and right version can be written only once. See the methods +$#u.p#[(#i#+1)\bmod 2]$. This trick works whether #u.p[i]# is a left +child ($#i#=0$) or a right child ($#i#=1$) of #u#. In some cases this +means that some complicated code that would otherwise need to have both a +left version and right version can be written only once. See the methods #rotateLeft(u)# and #rotateRight(u)# on page~\pageref{page:rotations} for an example. @@ -444,7 +449,7 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Suppose we are given a binary tree with pre- post- and in-order numbers + Suppose we are given a binary tree with pre-, post-, and in-order numbers assigned to the nodes. Show how these numbers can be used to answer each of the following questions in constant time: \begin{enumerate} diff --git a/latex/btree.tex b/latex/btree.tex index 0c92802d..1024b3a9 100644 --- a/latex/btree.tex +++ b/latex/btree.tex @@ -560,7 +560,7 @@ \subsection{Amortized Analysis of $B$-Trees} Since at most $3m$ credits are ever created and each split, merge, and borrow is paid for with with 2 credits, it follows that at most $3m/2$ splits, merges, and borrows are performed. - These credits are illustrated using the \textcent\ symbol in + These credits are illustrated using the \cent\ symbol in Figures~\ref{fig:btree-split}, \ref{fig:btree-borrow}, and \ref{fig:btree-merge}. diff --git a/latex/figs/24rb.ipe b/latex/figs/24rb.ipe index 2f61f7cb..a6cb39ca 100644 --- a/latex/figs/24rb.ipe +++ b/latex/figs/24rb.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/24tree-add.ipe b/latex/figs/24tree-add.ipe index b9ec62f0..1446862c 100644 --- a/latex/figs/24tree-add.ipe +++ b/latex/figs/24tree-add.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/24tree-remove.ipe b/latex/figs/24tree-remove.ipe index 2a862d2e..4e778aa9 100644 --- a/latex/figs/24tree-remove.ipe +++ b/latex/figs/24tree-remove.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/arraydeque.ipe b/latex/figs/arraydeque.ipe index 4bba6c1e..ef85f918 100644 --- a/latex/figs/arraydeque.ipe +++ b/latex/figs/arraydeque.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/arrayqueue.ipe b/latex/figs/arrayqueue.ipe index c26417d1..c70e1b51 100644 --- a/latex/figs/arrayqueue.ipe +++ b/latex/figs/arrayqueue.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/arraystack.ipe b/latex/figs/arraystack.ipe index 42b5cd9a..0852432d 100644 --- a/latex/figs/arraystack.ipe +++ b/latex/figs/arraystack.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/avl-rebalance.ipe b/latex/figs/avl-rebalance.ipe index a57819de..b089236f 100644 --- a/latex/figs/avl-rebalance.ipe +++ b/latex/figs/avl-rebalance.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/binarytree-numbering.ipe b/latex/figs/binarytree-numbering.ipe index 3fe572de..3e3c3c7b 100644 --- a/latex/figs/binarytree-numbering.ipe +++ b/latex/figs/binarytree-numbering.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/binarytrie-add.ipe b/latex/figs/binarytrie-add.ipe index 2e1d3844..0723a73d 100644 --- a/latex/figs/binarytrie-add.ipe +++ b/latex/figs/binarytrie-add.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/binarytrie-ex.ipe b/latex/figs/binarytrie-ex.ipe index b872dbf0..12ccd0f9 100644 --- a/latex/figs/binarytrie-ex.ipe +++ b/latex/figs/binarytrie-ex.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/binarytrie-remove.ipe b/latex/figs/binarytrie-remove.ipe index a9f0f660..c2a3bd18 100644 --- a/latex/figs/binarytrie-remove.ipe +++ b/latex/figs/binarytrie-remove.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/binarytrie.ipe b/latex/figs/binarytrie.ipe index d6d8b1aa..e04daf35 100644 --- a/latex/figs/binarytrie.ipe +++ b/latex/figs/binarytrie.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bintree-traverse.ipe b/latex/figs/bintree-traverse.ipe index 94dbd6d8..b206a5eb 100644 --- a/latex/figs/bintree-traverse.ipe +++ b/latex/figs/bintree-traverse.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bintree.ipe b/latex/figs/bintree.ipe index 8b73c16f..6685b0f0 100644 --- a/latex/figs/bintree.ipe +++ b/latex/figs/bintree.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bplustree.ipe b/latex/figs/bplustree.ipe index 427c5756..6b297c71 100644 --- a/latex/figs/bplustree.ipe +++ b/latex/figs/bplustree.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bst-balanced.ipe b/latex/figs/bst-balanced.ipe index ab64e9bd..1f97b3de 100644 --- a/latex/figs/bst-balanced.ipe +++ b/latex/figs/bst-balanced.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bst-delete.ipe b/latex/figs/bst-delete.ipe index 290f2c26..5693339c 100644 --- a/latex/figs/bst-delete.ipe +++ b/latex/figs/bst-delete.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bst-example.ipe b/latex/figs/bst-example.ipe index 8ce8390e..4547b8f4 100644 --- a/latex/figs/bst-example.ipe +++ b/latex/figs/bst-example.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bst-path.ipe b/latex/figs/bst-path.ipe index b23b1814..247a4e16 100644 --- a/latex/figs/bst-path.ipe +++ b/latex/figs/bst-path.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bst-splice.ipe b/latex/figs/bst-splice.ipe index 4a6d5f3b..3eab3cfd 100644 --- a/latex/figs/bst-splice.ipe +++ b/latex/figs/bst-splice.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bst-template-small.ipe b/latex/figs/bst-template-small.ipe index 88dac99e..52c1ddc0 100644 --- a/latex/figs/bst-template-small.ipe +++ b/latex/figs/bst-template-small.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/bst-template.ipe b/latex/figs/bst-template.ipe index d4751e23..b35eafc1 100644 --- a/latex/figs/bst-template.ipe +++ b/latex/figs/bst-template.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/btree-add.ipe b/latex/figs/btree-add.ipe index 925939e5..c5e72ab2 100644 --- a/latex/figs/btree-add.ipe +++ b/latex/figs/btree-add.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/btree-borrow.ipe b/latex/figs/btree-borrow.ipe index bbc38fa3..b40f3cfd 100644 --- a/latex/figs/btree-borrow.ipe +++ b/latex/figs/btree-borrow.ipe @@ -2,7 +2,8 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} +\usepackage{wasysym} @@ -727,8 +728,8 @@ h 304 656 l $\mathtt{\color{blue}u}$ -\textcent -\textcent -\textcent +\cent +\cent +\cent diff --git a/latex/figs/btree-merge.ipe b/latex/figs/btree-merge.ipe index 7ef907b8..f476f6e1 100644 --- a/latex/figs/btree-merge.ipe +++ b/latex/figs/btree-merge.ipe @@ -2,7 +2,8 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} +\usepackage{wasysym} @@ -639,7 +640,7 @@ h 240 688 m 240 656 l -\textcent -\textcent +\cent +\cent diff --git a/latex/figs/btree-remove-full.ipe b/latex/figs/btree-remove-full.ipe index f97a4372..a2dfb2ba 100644 --- a/latex/figs/btree-remove-full.ipe +++ b/latex/figs/btree-remove-full.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/btree-remove.ipe b/latex/figs/btree-remove.ipe index 073f3cd5..d8c047f1 100644 --- a/latex/figs/btree-remove.ipe +++ b/latex/figs/btree-remove.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/btree-split.ipe b/latex/figs/btree-split.ipe index 6e176038..fb89040a 100644 --- a/latex/figs/btree-split.ipe +++ b/latex/figs/btree-split.ipe @@ -1,8 +1,9 @@ - -\usepackage{kpfonts} + +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} +\usepackage{wasysym} @@ -266,7 +267,7 @@ h 80 752 l h -h +h 64 752 m 64 736 l @@ -274,7 +275,7 @@ h 80 752 l h -j +j 64 752 m 64 736 l @@ -282,7 +283,7 @@ h 80 752 l h -m +m 64 752 m 64 736 l @@ -290,7 +291,7 @@ h 80 752 l h -o +o 64 752 m 64 736 l @@ -298,7 +299,7 @@ h 80 752 l h -q +q 64 752 m 64 736 l @@ -306,7 +307,7 @@ h 80 752 l h -s +s 176 592 m 192 624 l @@ -384,7 +385,7 @@ h 80 752 l h -b +b 64 752 m 64 736 l @@ -392,7 +393,7 @@ h 80 752 l h -d +d 64 752 m 64 736 l @@ -400,7 +401,7 @@ h 80 752 l h -f +f 64 752 m 64 736 l @@ -408,7 +409,7 @@ h 80 752 l h -u +u 240 688 m 240 656 l @@ -453,17 +454,17 @@ h 256 688 m 320 656 l -A -C -E -V -G -I -K -N -P -R -T +A +C +E +V +G +I +K +N +P +R +T 64 752 m 64 736 l @@ -471,7 +472,7 @@ h 80 752 l h -h +h 64 752 m 64 736 l @@ -479,8 +480,8 @@ h 80 752 l h -j -m +j +m 64 752 m 64 736 l @@ -488,7 +489,7 @@ h 80 752 l h -o +o 64 752 m 64 736 l @@ -496,7 +497,7 @@ h 80 752 l h -q +q 64 752 m 64 736 l @@ -504,7 +505,7 @@ h 80 752 l h -s +s 176 592 m 192 624 l @@ -582,7 +583,7 @@ h 80 752 l h -b +b 64 752 m 64 736 l @@ -590,7 +591,7 @@ h 80 752 l h -d +d 64 752 m 64 736 l @@ -598,7 +599,7 @@ h 80 752 l h -f +f 64 752 m 64 736 l @@ -606,7 +607,7 @@ h 80 752 l h -m +m 64 752 m 64 736 l @@ -638,18 +639,18 @@ h 144 592 l h -A -C -E -V -G -I -K -N -P -R -T -u +A +C +E +V +G +I +K +N +P +R +T +u 192 528 m 192 512 l @@ -695,14 +696,14 @@ h 272 688 m 400 656 l -$\mathtt{\color{blue}u}$ -$\mathtt{\color{blue}w}$ -$\mathtt{\color{blue}u}$ +$\mathtt{\color{blue}u}$ +$\mathtt{\color{blue}w}$ +$\mathtt{\color{blue}u}$ 336 640 m 336 624 l -\textcent\textcent\textcent -\textcent +\cent\cent\cent +\cent diff --git a/latex/figs/btree.ipe b/latex/figs/btree.ipe index 0f416a9c..39c78015 100644 --- a/latex/figs/btree.ipe +++ b/latex/figs/btree.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/chainedhashtable.ipe b/latex/figs/chainedhashtable.ipe index 78e5c815..221b7c77 100644 --- a/latex/figs/chainedhashtable.ipe +++ b/latex/figs/chainedhashtable.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/comparison-tree-b.ipe b/latex/figs/comparison-tree-b.ipe index cd42c3cc..b9ff0efa 100644 --- a/latex/figs/comparison-tree-b.ipe +++ b/latex/figs/comparison-tree-b.ipe @@ -2,7 +2,7 @@ -\usepackage{amssymb}\usepackage{kpfonts} +\usepackage{amssymb}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/comparison-tree.ipe b/latex/figs/comparison-tree.ipe index 68b7cd9d..829f1c74 100644 --- a/latex/figs/comparison-tree.ipe +++ b/latex/figs/comparison-tree.ipe @@ -2,7 +2,7 @@ -\usepackage{amssymb}\usepackage{kpfonts} +\usepackage{amssymb}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/countingsort.ipe b/latex/figs/countingsort.ipe index 61ce4c5f..89a053e3 100644 --- a/latex/figs/countingsort.ipe +++ b/latex/figs/countingsort.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/dependencies.ipe b/latex/figs/dependencies.ipe index 5a101bdf..a0774600 100644 --- a/latex/figs/dependencies.ipe +++ b/latex/figs/dependencies.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/dfs-cycle.ipe b/latex/figs/dfs-cycle.ipe index ed023a2d..ac04e64d 100644 --- a/latex/figs/dfs-cycle.ipe +++ b/latex/figs/dfs-cycle.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/dllist-addbefore.ipe b/latex/figs/dllist-addbefore.ipe index 6bce33a1..459b91e5 100644 --- a/latex/figs/dllist-addbefore.ipe +++ b/latex/figs/dllist-addbefore.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/dllist.ipe b/latex/figs/dllist.ipe index 90f2bcb5..8112e2b8 100644 --- a/latex/figs/dllist.ipe +++ b/latex/figs/dllist.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/dllist2.ipe b/latex/figs/dllist2.ipe index 4f00fbff..5592e9c7 100644 --- a/latex/figs/dllist2.ipe +++ b/latex/figs/dllist2.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/dt.ipe b/latex/figs/dt.ipe index 9b31920c..355e88ee 100644 --- a/latex/figs/dt.ipe +++ b/latex/figs/dt.ipe @@ -2,7 +2,7 @@ -\usepackage{amssymb}\usepackage{kpfonts} +\usepackage{amssymb}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/dualarraydeque.ipe b/latex/figs/dualarraydeque.ipe index 7a6d8b6f..cfa5871a 100644 --- a/latex/figs/dualarraydeque.ipe +++ b/latex/figs/dualarraydeque.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/em.ipe b/latex/figs/em.ipe index e239661e..a51afd3f 100644 --- a/latex/figs/em.ipe +++ b/latex/figs/em.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/eytzinger.ipe b/latex/figs/eytzinger.ipe index 85f0b948..d269d35a 100644 --- a/latex/figs/eytzinger.ipe +++ b/latex/figs/eytzinger.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/findit.ipe b/latex/figs/findit.ipe index 7e32a25a..6db8bfda 100644 --- a/latex/figs/findit.ipe +++ b/latex/figs/findit.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/flippullpush.ipe b/latex/figs/flippullpush.ipe index cbbdd4b9..0b7e51d7 100644 --- a/latex/figs/flippullpush.ipe +++ b/latex/figs/flippullpush.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/flowchart.ipe b/latex/figs/flowchart.ipe index b5eeca3b..451301f3 100644 --- a/latex/figs/flowchart.ipe +++ b/latex/figs/flowchart.ipe @@ -4,7 +4,7 @@ \usepackage{xr} \externaldocument[X-]{../ods-java} -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/gauss.ipe b/latex/figs/gauss.ipe index 4daa79d7..f7e46d4c 100644 --- a/latex/figs/gauss.ipe +++ b/latex/figs/gauss.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/graph-bfs.ipe b/latex/figs/graph-bfs.ipe index 152aa1bc..d235a5cf 100644 --- a/latex/figs/graph-bfs.ipe +++ b/latex/figs/graph-bfs.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/graph-dfs.ipe b/latex/figs/graph-dfs.ipe index 3888f891..0bf13698 100644 --- a/latex/figs/graph-dfs.ipe +++ b/latex/figs/graph-dfs.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/graph-example2.ipe b/latex/figs/graph-example2.ipe index cee8f991..1c8a7cc1 100644 --- a/latex/figs/graph-example2.ipe +++ b/latex/figs/graph-example2.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/graph.ipe b/latex/figs/graph.ipe index ad8bc468..14652443 100644 --- a/latex/figs/graph.ipe +++ b/latex/figs/graph.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/harmonic.ipe b/latex/figs/harmonic.ipe index c09d14d2..14ddf159 100644 --- a/latex/figs/harmonic.ipe +++ b/latex/figs/harmonic.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/heap-insert.ipe b/latex/figs/heap-insert.ipe index 3bf76954..313813fe 100644 --- a/latex/figs/heap-insert.ipe +++ b/latex/figs/heap-insert.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/heap-remove.ipe b/latex/figs/heap-remove.ipe index 2274f7ae..8e9d5bc2 100644 --- a/latex/figs/heap-remove.ipe +++ b/latex/figs/heap-remove.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/heapsort.ipe b/latex/figs/heapsort.ipe index d35b1813..4a20281f 100644 --- a/latex/figs/heapsort.ipe +++ b/latex/figs/heapsort.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/list.ipe b/latex/figs/list.ipe index 195d77d7..9bbb0aa5 100644 --- a/latex/figs/list.ipe +++ b/latex/figs/list.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/mathastext.sty b/latex/figs/mathastext.sty new file mode 100644 index 00000000..b94db878 --- /dev/null +++ b/latex/figs/mathastext.sty @@ -0,0 +1,1876 @@ +%% +%% This is file `mathastext.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% mathastext.dtx (with options: `package') +%% +%% IMPORTANT NOTICE: +%% +%% For the copyright see the source file. +%% +%% Any modified versions of this file must be renamed +%% with new filenames distinct from mathastext.sty. +%% +%% For distribution of the original source see the terms +%% for copying and modification in the file mathastext.dtx. +%% +%% This generated file may be distributed as long as the +%% original source files, as listed above, are part of the +%% same distribution. (The sources need not necessarily be +%% in the same archive or directory.) +%% +\ProvidesPackage{mathastext} + [2013/01/21 v1.2f Use the text font in math mode (jfB)] +%% +%% Package `mathastext' by Jean-Francois Burnol +%% Copyright (C) 2011, 2012 by Jean-Francois Burnol +%% +\NeedsTeXFormat{LaTeX2e} +\newif\ifmst@XeTeX +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname XeTeXinterchartoks\endcsname\relax + \mst@XeTeXfalse +\else + \mst@XeTeXtrue +\fi +\newif\ifmst@LuaTeX +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname directlua\endcsname\relax + \mst@LuaTeXfalse +\else + \mst@LuaTeXtrue +\fi +\def\mst@oti{OT1}\def\mst@ti{T1}\def\mst@lyi{LY1} +\def\mst@eui{EU1}\def\mst@euii{EU2} +\newif\ifmst@goahead +\newif\ifmst@abort +\newif\ifmst@optionalparam + \def\mst@enc{\encodingdefault} + \def\mst@fam{\familydefault} + \def\mst@ser{\seriesdefault} + \def\mst@opsh{\shapedefault} %% will be default shape for operator names + \def\mst@bold{\bfdefault} + \def\mst@ltsh{\shapedefault} %% will be default shape for letters + \edef\mst@greekfont{\familydefault} %% v 1.15c +\newif\ifmst@italic +\newif\ifmst@frenchmath + \DeclareOption{italic}{\mst@italictrue + \def\mst@ltsh{\itdefault}} + \DeclareOption{frenchmath}{\mst@frenchmathtrue\mst@italictrue + \def\mst@ltsh{\itdefault}} +%% +\newif\ifmst@endash\mst@endashtrue + \DeclareOption{endash}{\mst@endashtrue} + \DeclareOption{noendash}{\mst@endashfalse} +\newif\ifmst@emdash + \DeclareOption{emdash}{\mst@emdashtrue\mst@endashfalse} +%% +\newif\ifmst@alldelims +\edef\mst@tmp{\encodingdefault}\ifx\mst@oti\mst@tmp\else\mst@alldelimstrue\fi + \DeclareOption{alldelims}{\mst@alldelimstrue} + \DeclareOption{nolessnomore}{\mst@alldelimsfalse} +%% new with 1.2 +\newif\ifmst@nosmalldelims + \DeclareOption{nosmalldelims}{\mst@nosmalldelimstrue} +%% +\newif\ifmst@noplus + \DeclareOption{noplus}{\mst@noplustrue} +\newif\ifmst@nominus + \DeclareOption{nominus}{\mst@nominustrue} +\DeclareOption{noplusnominus}{\ExecuteOptions{noplus,nominus}} +%% +\newif\ifmst@noparen + \DeclareOption{noparenthesis}{\mst@noparentrue} +\newif\ifmst@nopunct + \DeclareOption{nopunctuation}{\mst@nopuncttrue} +\newif\ifmst@noequal + \DeclareOption{noequal}{\mst@noequaltrue} +\newif\ifmst@noexclam + \DeclareOption{noexclam}{\mst@noexclamtrue} +\newif\ifmst@asterisk + \DeclareOption{noasterisk}{\PackageWarningNoLine{mathastext} + {option `noasterisk\string' is deprecated.^^J\space\space\space + Check the documentation}} + \DeclareOption{asterisk}{\mst@asterisktrue + \AtBeginDocument{ + \everymath\expandafter{\the\everymath \mst@doasterisk + \let\mst@doasterisk\relax} + \everydisplay\expandafter{\the\everydisplay \mst@doasterisk + \let\mst@doasterisk\relax}}} +\newif\ifmst@nospecials + \DeclareOption{nospecials}{\mst@nospecialstrue} +\DeclareOption{basic}{\ExecuteOptions{noparenthesis,nopunctuation,% +noplusnominus,noequal,noexclam,nospecials,nolessnomore}} +%% +\newif\ifmst@nohbar + \DeclareOption{nohbar}{\mst@nohbartrue} +\newif\ifmst@nodigits + \DeclareOption{nodigits}{\mst@nodigitstrue} +\newif\ifmst@defaultimath + \DeclareOption{defaultimath}{\mst@defaultimathtrue} +\newif\ifmst@mathaccents + \DeclareOption{mathaccents}{\mst@mathaccentstrue} +%% +\newif\ifmst@needsymbol +\newif\ifmst@symboldelimiters + \DeclareOption{symboldelimiters}{\mst@needsymboltrue\mst@symboldelimiterstrue} +\newif\ifmst@symboldigits + \DeclareOption{symboldigits}{\mst@needsymboltrue\mst@symboldigitstrue} +\newif\ifmst@symbolgreek + \DeclareOption{symbolgreek}{\mst@needsymboltrue\mst@symbolgreektrue} +\newif\ifmst@symbolre + \DeclareOption{symbolre}{\mst@needsymboltrue\mst@symbolretrue} +\newif\ifmst@symbolmisc + \DeclareOption{symbolmisc}{\mst@needsymboltrue\mst@symbolmisctrue} +\DeclareOption{symbol}{\ExecuteOptions{symbolgreek,symbolmisc,symbolre}} +\DeclareOption{symbolmax}{\ExecuteOptions{symbol,symboldelimiters}} +%% +\newif\ifmst@needeuler +\newif\ifmst@eulerdigits + \DeclareOption{eulerdigits}{\mst@needeulertrue\mst@eulerdigitstrue} +\newif\ifmst@eulergreek + \DeclareOption{eulergreek}{\mst@needeulertrue\mst@eulergreektrue} +%% +\newif\ifmst@selfGreek + \DeclareOption{selfGreek}{\mst@selfGreektrue} +\newif\ifmst@selfGreeks + \DeclareOption{selfGreeks}{\mst@selfGreekstrue\mst@selfGreektrue} +\newif\ifmst@LGRgreek + \DeclareOption{LGRgreek}{\mst@LGRgreektrue} +\newif\ifmst@LGRgreeks + \DeclareOption{LGRgreeks}{\mst@LGRgreekstrue\mst@LGRgreektrue} +%% +\def\mst@greek@select{0} +\newif\ifmst@itgreek +\newif\ifmst@upgreek + \DeclareOption{itgreek}{\mst@itgreektrue} + \DeclareOption{upgreek}{\mst@upgreektrue} + \DeclareOption{itGreek}{\def\mst@greek@select{1}} + \DeclareOption{upGreek}{\def\mst@greek@select{2}} +%% +\newif\ifmst@defaultnormal + \DeclareOption{defaultnormal}{\mst@defaultnormaltrue} +\newif\ifmst@defaultrm + \DeclareOption{defaultrm}{\mst@defaultrmtrue} +\newif\ifmst@defaultbf + \DeclareOption{defaultbf}{\mst@defaultbftrue} +\newif\ifmst@defaultit + \DeclareOption{defaultit}{\mst@defaultittrue} +\newif\ifmst@defaultsf + \DeclareOption{defaultsf}{\mst@defaultsftrue} +\newif\ifmst@defaulttt + \DeclareOption{defaulttt}{\mst@defaulttttrue} +\newif\ifmst@nonormalbold +\DeclareOption{defaultalphabets}{\ExecuteOptions{defaultnormal,defaultrm,% +defaultbf,defaultit,defaultsf,defaulttt}\mst@nonormalboldtrue} +\newif\ifmst@defaultsizes + \DeclareOption{defaultmathsizes}{\mst@defaultsizestrue} +\newif\ifmst@twelve + \DeclareOption{12pt}{\mst@twelvetrue} +\newif\ifmst@fouriervec + \DeclareOption{fouriervec}{\mst@fouriervectrue} +\newif\ifmst@subdued + \DeclareOption{subdued}{\mst@subduedtrue} +\DeclareOption*{\PackageWarningNoLine{mathastext}{Unknown option `\CurrentOption\string'}} +\ProcessOptions\relax +\newmuskip\mst@exists@muskip %% v 1.15e +\newmuskip\mst@forall@muskip +\def\mst@exists@skip{1mu} +\def\mst@forall@skip{.6667mu} +\ifmst@italic\ifmst@frenchmath\else + \def\mst@exists@skip{0mu}\def\mst@forall@skip{0mu}\def\mst@prime@skip{0mu} +\fi\fi +\AtEndOfPackage{% must be at end of code +\let\mst@stdexists\exists +\let\mst@stdforall\forall +\renewcommand\exists{\mst@stdexists\mskip\mst@exists@muskip} +\renewcommand\forall{\mst@stdforall\mskip\mst@forall@muskip} +} +\newmuskip\mst@prime@muskip %% v 1.2 +\def\mst@prime@skip{.5mu} +\ifmst@italic\ifmst@frenchmath\else\def\mst@prime@skip{0mu}\fi\fi +\def\mst@active@math@prime{\sp\bgroup\mskip\mst@prime@muskip\prim@s} +{\catcode`\'=12 +\gdef\mst@modifyprime{\mst@mathactivate'{}\mst@active@math@prime}} +\AtBeginDocument{ +\everymath\expandafter{\the\everymath \mst@modifyprime \MTnormalprime} +\everydisplay\expandafter{\the\everydisplay \mst@modifyprime \MTnormalprime} +} +\newcommand*\MTnormalprime{\let\mst@modifyprime\relax} +\newcommand*\MTexistsskip[1]{\edef\mst@exists@skip{#1}% + \mst@exists@muskip\mst@exists@skip\relax} +\newcommand*\MTforallskip[1]{\edef\mst@forall@skip{#1}% + \mst@forall@muskip\mst@forall@skip\relax} +\newcommand*\MTprimeskip[1]{\edef\mst@prime@skip{#1}% + \mst@prime@muskip\mst@prime@skip\relax} +\let\Mathastextexistsskip\MTexistsskip +\let\Mathastextforallskip\MTforallskip +\let\Mathastextprimeskip\MTprimeskip +\let\mathastextexistsskip\MTexistsskip +\let\mathastextforallskip\MTforallskip +\let\mathastextprimeskip\MTprimeskip +\ifmst@noparen\else +\AtBeginDocument{ +\@ifundefined{resetMathstrut@}{}{% + \PackageWarningNoLine{mathastext}{a custom version of the amsmath macro^^J% + \space\space\space\string\resetMathstrut@\space will replace the original} + \ifmst@symboldelimiters + \def\resetMathstrut@{% + \setbox\z@\hbox{\the\textfont\symmtpsymbol\char40 + \the\textfont\symmtoperatorfont\char40 + \the\textfont\symoperators\char40}% + \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@} + \else + \def\resetMathstrut@{% + \setbox\z@\hbox{\the\textfont\symmtoperatorfont\char40 + \the\textfont\symoperators\char40}% + \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@} + \fi}} +\fi +\newtoks\mst@do@nonletters +\newtoks\mst@do@easynonletters +\newtoks\mst@do@az +\newtoks\mst@do@AZ +\newcommand*\MTnonlettersdonotobeymathxx{\let\mst@the\@gobble} +\newcommand*\MTnonlettersobeymathxx{\let\mst@the\the} +\newcommand*\MTeasynonlettersdonotobeymathxx{\let\mst@theeasy\@gobble} +\newcommand*\MTeasynonlettersobeymathxx{\let\mst@theeasy\the} +\MTnonlettersdonotobeymathxx % 1.2c !!! +\MTeasynonlettersobeymathxx +\newcommand*\MTicinmath{% + \let\mst@thef\the + \let\mst@theF\the + \def\mst@itcorr{\ifnum\fam=\m@ne\/\else\ifnum\fam=\symmtletterfont\/\fi\fi}% + \let\mst@ITcorr\mst@itcorr} +\newcommand*\MTnoicinmath{% also usable in math mode + \def\mst@itcorr{}\def\mst@ITcorr{}% + \let\mst@thef\@gobble\let\mst@theF\@gobble} +\newcommand*\MTICinmath{% + \let\mst@theF\the + \def\mst@ITcorr{\ifnum\fam=\m@ne\/\fi}} +\newcommand*\MTnoICinmath{% also usable in math mode + \def\mst@ITcorr{}% + \let\mst@theF\@gobble} +\newcommand*\MTicalsoinmathxx{% + \ifx\mst@itcorr\@empty\else\def\mst@itcorr{\/}\fi + \ifx\mst@ITcorr\@empty\else\def\mst@ITcorr{\/}\fi} +\AtBeginDocument{ +\everymath\expandafter{\the\everymath + \mst@the\mst@do@nonletters \let\mst@the\@gobble + \mst@theeasy\mst@do@easynonletters \let\mst@theeasy\@gobble + \mst@thef\mst@do@az \let\mst@thef\@gobble + \mst@theF\mst@do@AZ \let\mst@theF\@gobble} +\everydisplay\expandafter{\the\everydisplay + \mst@the\mst@do@nonletters \let\mst@the\@gobble + \mst@theeasy\mst@do@easynonletters \let\mst@theeasy\@gobble + \mst@thef\mst@do@az \let\mst@thef\@gobble + \mst@theF\mst@do@AZ \let\mst@theF\@gobble} +} +\def\mst@magic@v #1#2#3#4#5{#1#3#4} +\def\mst@magic@vi #1#2#3#4#5#6{#1#2#4#5} +\def\mst@fork{\ifmmode\mst@magic@v\fi\@thirdofthree} +\def\mst@safefork{\ifmmode\if@safe@actives\else\mst@magic@vi\fi\fi\@thirdofthree} +\def\mst@do@activecase#1#2#3{% #1 is a category 11 or 12 character token + \@ifundefined{active@char#1}{}{% + \ifcat #1a\mathcode`#1=#2\else + \ifx\relax #2\relax\mathcode`#1=`#1 \else\mathcode`#1=#3\fi\fi + \expandafter\expandafter\expandafter\let\expandafter\expandafter + \csname mst@orig@user@active#1\endcsname + \csname user@active#1\endcsname + \expandafter\expandafter\expandafter\let\expandafter\expandafter + \csname mst@orig@normal@char#1\endcsname + \csname normal@char#1\endcsname + \ifcat #1a% + \expandafter\edef\csname user@active#1\endcsname + {\noexpand\mst@fork {{#2\noexpand#3}}{}\expandafter + \noexpand\csname mst@orig@user@active#1\endcsname + }% + \expandafter\edef\csname normal@char#1\endcsname + {\noexpand\mst@safefork {{#2\noexpand#3}}{}\expandafter + \noexpand\csname mst@orig@normal@char#1\endcsname + }% + \else + \expandafter\edef\csname user@active#1\endcsname + {\noexpand\mst@fork {#2}\noexpand#3\expandafter + \noexpand\csname mst@orig@user@active#1\endcsname + }% + \expandafter\edef\csname normal@char#1\endcsname + {\noexpand\mst@safefork {#2}\noexpand#3\expandafter + \noexpand\csname mst@orig@normal@char#1\endcsname + }% + \fi}} +\begingroup % make sure ~ is active at mathastext loading time + \catcode`~=\active + \def\x{\endgroup + \def\mst@mathactivate##1##2##3{% ##1 guaranteed of cat 11 or 12 + \begingroup + \lccode`~=`##1 + \lccode`##1=`##1 + \lowercase{\endgroup + \ifnum\catcode`##1=\active + \mst@do@activecase ##1{##2}##3 + % careful as ##2 is empty in the asterisk and + % prime case! + \else + \mathcode`##1="8000 + % I use " many times later, \string" everywhere would be a pain + \ifcat##1a\def~{{##2##3}}\else\def~{##2##3}\fi + \fi}}} +\x +\def\mst@addtodo@nonletters#1#2#3{% + % #1 will be of cat 11 or 12. + % #2 is empty for asterisk and right quote + \mst@do@nonletters\expandafter{\the\mst@do@nonletters + \mst@mathactivate#1{#2}#3}% +} +\def\mst@addtodo@easynonletters#1#2{% #1 is a one char control sequence + \mst@do@easynonletters\expandafter{\the\mst@do@easynonletters\mathcode`#1=#2}% +} +\def\mst@addtodo@az#1#2#3{% + \mst@do@az\expandafter{\the\mst@do@az\mst@mathactivate#1#2#3} +} +\def\mst@addtodo@AZ#1#2#3{% + \mst@do@AZ\expandafter{\the\mst@do@AZ\mst@mathactivate#1#2#3}% +} +\@ifpackageloaded{amsmath} +{\let\newmcodes@\relax} % brutal, but bye bye and don't come back. +{} +\ifmst@subdued + \def\mst@reserved#1\getanddefine@fonts\symletters#2#3\@nil{% + \def\mst@normalmv@letter{#2}} + \expandafter\mst@reserved\mv@normal\@nil + \def\mst@reserved#1\getanddefine@fonts\symletters#2#3\@nil{% + \def\mst@boldmv@letter{#2}} + \expandafter\mst@reserved\mv@bold\@nil + \def\mst@reserved#1\getanddefine@fonts\symoperators#2#3\@nil{% + \def\mst@normalmv@operator{#2}} + \expandafter\mst@reserved\mv@normal\@nil + \def\mst@reserved#1\getanddefine@fonts\symoperators#2#3\@nil{% + \def\mst@boldmv@operator{#2}} + \expandafter\mst@reserved\mv@bold\@nil +%% + \edef\mst@tmp{\encodingdefault} + \def\mst@reserved#1/#2/#3/#4/{\gdef\mst@debut{#1}\gdef\mst@reste{#2/#3/#4}} + \begingroup\escapechar\m@ne + \xdef\mst@funnyoti{\expandafter\string\csname OT1\endcsname} + \expandafter\expandafter\expandafter + \mst@reserved\expandafter\string\mst@normalmv@operator/ + \endgroup + \ifx\mst@debut\mst@funnyoti\ifx\mst@tmp\mst@oti\def\mst@tmp{T1}\fi\fi + \edef\mst@normalmv@operator{\expandafter\noexpand\csname + \mst@tmp/\mst@reste\endcsname} + \begingroup\escapechar\m@ne + \expandafter\expandafter\expandafter + \mst@reserved\expandafter\string\mst@boldmv@operator/ + \endgroup + \ifx\mst@debut\mst@funnyoti\ifx\mst@tmp\mst@oti\def\mst@tmp{T1}\fi\fi + \edef\mst@boldmv@operator{\expandafter\noexpand\csname + \mst@tmp/\mst@reste\endcsname} + \AtEndOfPackage{ + \typeout{** ...entering subdued mode...} + \expandafter\SetSymbolFont@ \expandafter\mv@normal\mst@normalmv@letter\symmtletterfont + \expandafter\SetSymbolFont@ \expandafter\mv@bold\mst@boldmv@letter\symmtletterfont + \expandafter\SetSymbolFont@ \expandafter\mv@normal\mst@normalmv@operator\symmtoperatorfont + \expandafter\SetSymbolFont@ \expandafter\mv@bold\mst@boldmv@operator\symmtoperatorfont + \typeout{** ...done.} + } +\fi % fin de ce \ifmst@subdued +\DeclareSymbolFont{mtoperatorfont} + {\mst@enc}{\mst@fam}{\mst@ser}{\mst@opsh} +\newcommand*{\MTmathoperatorsobeymathxx} +{\def\operator@font{\mathgroup\ifnum\fam=\m@ne\symmtoperatorfont\else\fam\fi}} +\newcommand*{\MTmathoperatorsdonotobeymathxx} +{\def\operator@font{\mathgroup\symmtoperatorfont}} +\MTmathoperatorsobeymathxx +\DeclareSymbolFont{mtletterfont} + {\mst@enc}{\mst@fam}{\mst@ser}{\mst@ltsh} +\let\mst@alph@omicron\mathnormal +\@ifpackageloaded{fourier}{\ifsloped\else\let\mst@alph@omicron\mathrm\fi}{} +\DeclareSymbolFontAlphabet{\Mathnormal}{mtletterfont} +\DeclareSymbolFontAlphabet{\Mathrm}{mtoperatorfont} +\ifmst@nonormalbold\else + \DeclareMathAlphabet{\mathnormalbold}{\mst@enc}{\mst@fam}{\mst@bold}{\mst@ltsh} +\fi\ifmst@defaultbf\else + \DeclareMathAlphabet{\Mathbf}{\mst@enc}{\mst@fam}{\mst@bold}{\mst@opsh} +\fi\ifmst@defaultit\else + \DeclareMathAlphabet{\Mathit}{\mst@enc}{\mst@fam}{\mst@ser}{\itdefault} +\fi\ifmst@defaultsf\else + \DeclareMathAlphabet{\Mathsf}{\mst@enc}{\sfdefault}{\mst@ser}{\mst@opsh} +\fi\ifmst@defaulttt\else + \DeclareMathAlphabet{\Mathtt}{\mst@enc}{\ttdefault}{\mst@ser}{\mst@opsh} +\fi +\let\mst@original@normal\mathnormal +\let\mst@original@rm\mathrm +\let\mst@original@bf\mathbf +\let\mst@original@it\mathit +\let\mst@original@sf\mathsf +\let\mst@original@tt\mathtt +\def\mst@restorealphabets{% for subdued + \let\mathnormal\mst@original@normal + \let\mathrm\mst@original@rm + \let\mathbf\mst@original@bf + \let\mathit\mst@original@it + \let\mathsf\mst@original@sf + \let\mathtt\mst@original@tt} +\def\mst@setalphabets{% + \ifmst@defaultnormal\else\renewcommand{\mathnormal}{\Mathnormal}\fi + \ifmst@defaultrm\else\renewcommand{\mathrm}{\Mathrm}\fi + \ifmst@defaultbf\else\renewcommand{\mathbf}{\Mathbf}\fi + \ifmst@defaultit\else\renewcommand{\mathit}{\Mathit}\fi + \ifmst@defaultsf\else\renewcommand{\mathsf}{\Mathsf}\fi + \ifmst@defaulttt\else\renewcommand{\mathtt}{\Mathtt}\fi} +\ifmst@subdued\else\mst@setalphabets\fi +\def\mst@update@greeksh{ + \def\mst@greek@lsh{\mst@ltsh} %% default behavior + \def\mst@greek@ush{\mst@opsh} + \ifmst@itgreek\def\mst@greek@lsh{\itdefault} + \def\mst@greek@ush{\itdefault}\fi + \ifmst@upgreek\def\mst@greek@lsh{\updefault} + \def\mst@greek@ush{\updefault}\fi + \ifmst@frenchmath + \ifmst@itgreek\else + \ifmst@upgreek\else + \def\mst@greek@lsh{\mst@opsh} + \def\mst@greek@ush{\mst@opsh} + \fi\fi + \fi + \ifcase\mst@greek@select + \or\def\mst@greek@ush{\itdefault} + \or\def\mst@greek@ush{\updefault} + \fi} +\mst@update@greeksh +\ifmst@LGRgreek + \DeclareFontEncoding{LGR}{}{} + \DeclareSymbolFont{mtlgrfontlower}{LGR} + {\mst@fam}{\mst@ser}{\mst@greek@lsh} + \DeclareSymbolFont{mtlgrfontupper}{LGR} + {\mst@fam}{\mst@ser}{\mst@greek@ush} +\else +\ifmst@selfGreek + \DeclareSymbolFont{mtselfGreekfont}{OT1} + {\mst@fam}{\mst@ser}{\mst@greek@ush} +\fi\fi +\ifmst@needeuler\typeout{** will use Euler font; command \string\MTEulerScale} +\DeclareSymbolFont{mteulervm}{U}{zeur}{m}{n} +\DeclareSymbolFontAlphabet{\MathEuler}{mteulervm} +\DeclareMathAlphabet{\MathEulerBold}{U}{zeur}{\mst@bold}{n} +\fi +\newcommand*\MTEulerScale[1]{\edef\zeu@Scale{#1}} +\let\MathastextEulerScale\MTEulerScale +\ifmst@needsymbol\typeout{** will use Symbol font; command \string\MTSymbolScale} + \def\psy@scale{1} + \DeclareSymbolFont{mtpsymbol}{U}{psy}{m}{n} + \DeclareSymbolFontAlphabet{\MathPSymbol}{mtpsymbol} +\AtBeginDocument{ + \DeclareFontFamily{U}{psy}{} + \DeclareFontShape{U}{psy}{m}{n}{<->s*[\psy@scale] psyr}{} +} +\fi +\newcommand*\MTSymbolScale[1]{\edef\psy@scale{#1}} +\let\MathastextSymbolScale\MTSymbolScale +\DeclareRobustCommand*\pmvec[1]{\mathord{\stackrel{\raisebox{-.5ex}% +{\tiny\boldmath$\mathord{\rightarrow}$}}{{}#1}}} +\ifmst@fouriervec + \DeclareFontEncoding{FML}{}{} + \DeclareFontSubstitution{FML}{futm}{m}{it} + \DeclareSymbolFont{mathastextfourier}{FML}{futm}{m}{it} + \SetSymbolFont{mathastextfourier}{bold}{FML}{futm}{b}{it} + \DeclareMathAccent{\fouriervec}{\mathord}{mathastextfourier}{"7E} +\fi +\newcommand*\MTencoding[1]{\def\mst@enc{#1}} +\newcommand*\MTfamily[1]{\def\mst@fam{#1}} +\newcommand*\MTseries[1]{\def\mst@ser{#1}} +\newcommand*\MTshape[1]{\def\mst@opsh{#1} + \ifmst@italic\else\def\mst@ltsh{#1}\fi} +\newcommand*\MTboldvariant[1]{\def\mst@bold{#1}} +\newcommand*\MTlettershape[1]{\def\mst@ltsh{#1}} +\@onlypreamble\MTencoding +\@onlypreamble\MTfamily +\@onlypreamble\MTseries +\@onlypreamble\MTshape +\@onlypreamble\MTboldvariant +\@onlypreamble\MTlettershape +\let\Mathastextencoding\MTencoding +\let\Mathastextfamily\MTfamily +\let\Mathastextseries\MTseries +\let\Mathastextshape\MTshape +\let\Mathastextboldvariant\MTboldvariant +\let\Mathastextlettershape\MTlettershape + \newcommand*\MTitgreek{% +\mst@itgreektrue\mst@upgreekfalse\def\mst@greek@select{0}} + \newcommand*\MTupgreek{% +\mst@upgreektrue\mst@itgreekfalse\def\mst@greek@select{0}} + \newcommand*\MTitGreek{\def\mst@greek@select{1}} + \newcommand*\MTupGreek{\def\mst@greek@select{2}} +\@onlypreamble\MTitgreek +\@onlypreamble\MTupgreek +\@onlypreamble\MTitGreek +\@onlypreamble\MTitGreek +\let\Mathastextitgreek\MTitgreek +\let\Mathastextupgreek\MTupgreek +\let\MathastextitGreek\MTitGreek +\let\MathastextupGreek\MTupGreek + \newcommand*\MTgreekfont[1]{\def\mst@greekfont{#1}} +\@onlypreamble\MTgreekfont +\let\Mathastextgreekfont\MTgreekfont +\newcommand*\MTWillUse[5][\empty]{ + \MTencoding{#2} + \MTfamily{#3} + \MTseries{#4} + \MTshape{#5} + \ifmst@italic\MTlettershape{\itdefault}\fi % was missing in v 1.14 and prior + \ifx\empty#1 + \else +%% we check if optional argument was [], this does not detect [ ] + \def\mst@tmp{#1} + \ifx\empty\mst@tmp\else\MTlettershape{#1}\fi + \fi + \Mathastext} +\@onlypreamble\MTWillUse +\let\MathastextWillUse\MTWillUse +\let\Mathastextwilluse\MTWillUse +\newcommand*\Mathastext[1][\empty]{ +\ifx\empty#1 % no optional argument + \mst@update@greeksh + \edef\mst@encoding@normal{\mst@enc} + \edef\mst@family@normal{\mst@fam} + \edef\mst@series@normal{\mst@ser} + \edef\mst@shape@normal{\mst@opsh} + \edef\mst@ltshape@normal{\mst@ltsh} + \edef\mst@itdefault@normal{\itdefault} + \edef\mst@rmdefault@normal{\rmdefault} + \edef\mst@sfdefault@normal{\sfdefault} + \edef\mst@ttdefault@normal{\ttdefault} + \edef\mst@boldvariant@normal{\mst@bold} + \edef\mst@exists@skip@normal{\mst@exists@skip} + \edef\mst@forall@skip@normal{\mst@forall@skip} + \edef\mst@prime@skip@normal{\mst@prime@skip} + \edef\mst@encoding@bold{\mst@enc} + \edef\mst@family@bold{\mst@fam} + \edef\mst@series@bold{\mst@bold} + \edef\mst@shape@bold{\mst@opsh} + \edef\mst@ltshape@bold{\mst@ltsh} + \edef\mst@boldvariant@bold{\mst@bold} + \edef\mst@itdefault@bold{\itdefault} + \edef\mst@rmdefault@bold{\rmdefault} + \edef\mst@sfdefault@bold{\sfdefault} + \edef\mst@ttdefault@bold{\ttdefault} + \edef\mst@exists@skip@bold{\mst@exists@skip} + \edef\mst@forall@skip@bold{\mst@forall@skip} + \edef\mst@prime@skip@bold{\mst@prime@skip} + \MTicinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@ltshape@normal\MTnoicinmath\fi}% + \ifmst@frenchmath + \MTICinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@shape@normal\MTnoICinmath\fi}% + \fi + \ifmst@subdued + \MTeasynonlettersdonotobeymathxx + \MTnonlettersdonotobeymathxx + \MTmathoperatorsdonotobeymathxx + \MTnoicinmath + \ifmst@asterisk\let\mst@doasterisk\relax\fi + \def\mst@exists@skip@normal{0mu} + \def\mst@forall@skip@normal{0mu} + \def\mst@prime@skip@normal{0mu} + \def\mst@exists@skip@bold{0mu} + \def\mst@forall@skip@bold{0mu} + \def\mst@prime@skip@bold{0mu} + \else % not subdued + \ifmst@italic + \ifmst@frenchmath + \mst@exists@muskip\mst@exists@skip\relax + \mst@forall@muskip\mst@forall@skip\relax + \mst@prime@muskip\mst@prime@skip\relax + \else + \def\mst@exists@skip@normal{0mu} + \def\mst@forall@skip@normal{0mu} + \def\mst@prime@skip@normal{0mu} + \def\mst@exists@skip@bold{0mu} + \def\mst@forall@skip@bold{0mu} + \def\mst@prime@skip@bold{0mu} + \fi + \else + \mst@exists@muskip\mst@exists@skip\relax + \mst@forall@muskip\mst@forall@skip\relax + \mst@prime@muskip\mst@prime@skip\relax + \fi + \fi +%% v1.15f +\ifmst@nonormalbold\else + \SetMathAlphabet{\mathnormalbold}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@boldvariant@normal} + {\mst@ltshape@normal} + \SetMathAlphabet{\mathnormalbold}{bold}{\mst@encoding@bold} + {\mst@family@bold} + {\mst@boldvariant@bold} + {\mst@ltshape@bold} +\fi +%% v1.15f adds \ifmst@default.. checks +\ifmst@subdued\else + \SetSymbolFont{mtletterfont}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@normal} + {\mst@ltshape@normal} + \SetSymbolFont{mtletterfont}{bold} {\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@ltshape@bold} + \SetSymbolFont{mtoperatorfont}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@normal} + {\mst@shape@normal} + \SetSymbolFont{mtoperatorfont}{bold} {\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@shape@bold} +\ifmst@defaultbf\else + \SetMathAlphabet{\Mathbf}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@bold} + {\mst@shape@normal} + \SetMathAlphabet{\Mathbf}{bold}{\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@shape@bold} +\fi\ifmst@defaultit\else + \SetMathAlphabet{\Mathit}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@normal} + {\mst@itdefault@normal} + \SetMathAlphabet{\Mathit}{bold}{\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@itdefault@bold} +\fi\ifmst@defaultsf\else + \SetMathAlphabet{\Mathsf}{normal}{\mst@encoding@normal} + {\mst@sfdefault@normal} + {\mst@series@normal} + {\mst@shape@normal} + \SetMathAlphabet{\Mathsf}{bold}{\mst@encoding@bold} + {\mst@sfdefault@bold} + {\mst@series@bold} + {\mst@shape@bold} +\fi\ifmst@defaulttt\else + \SetMathAlphabet{\Mathtt}{normal}{\mst@encoding@normal} + {\mst@ttdefault@normal} + {\mst@series@normal} + {\mst@shape@normal} + \SetMathAlphabet{\Mathtt}{bold}{\mst@encoding@bold} + {\mst@ttdefault@bold} + {\mst@series@bold} + {\mst@shape@bold} +\fi\fi % de \ifmst@subdued + \ifmst@needeuler + \SetSymbolFont{mteulervm}{bold}{U}{zeur}{\mst@boldvariant@normal}{n} + \SetMathAlphabet{\MathEulerBold}{normal} + {U}{zeur}{\mst@boldvariant@normal}{n} + \SetMathAlphabet{\MathEulerBold}{bold} + {U}{zeur}{\mst@boldvariant@normal}{n} + \fi + \ifmst@needsymbol\SetSymbolFont{mtpsymbol}{bold} + {U}{psy}{\mst@boldvariant@normal}{n} + \fi +\ifmst@subdued\else +\ifmst@LGRgreek + \SetSymbolFont{mtlgrfontlower}{normal}{LGR} + {\mst@greekfont}{\mst@series@normal}{\mst@greek@lsh} + \SetSymbolFont{mtlgrfontlower}{bold}{LGR} + {\mst@greekfont}{\mst@boldvariant@normal}{\mst@greek@lsh} + \SetSymbolFont{mtlgrfontupper}{normal}{LGR} + {\mst@greekfont}{\mst@series@normal}{\mst@greek@ush} + \SetSymbolFont{mtlgrfontupper}{bold}{LGR} + {\mst@greekfont}{\mst@boldvariant@bold}{\mst@greek@ush} + \else +\ifmst@selfGreek + \SetSymbolFont{mtselfGreekfont}{normal}{OT1} + {\mst@greekfont}{\mst@series@normal}{\mst@greek@ush} + \SetSymbolFont{mtselfGreekfont}{bold}{OT1} + {\mst@greekfont}{\mst@boldvariant@bold}{\mst@greek@ush} +\fi\fi\fi +\ifmst@subdued +\typeout{** subdued mode will be activated for the normal and bold math versions} +\else +\typeout{** Latin letters in the normal (resp. bold) math versions are now^^J% + ** set up to use the fonts +\mst@encoding@normal/\mst@family@normal/\mst@series@normal% +(\mst@boldvariant@normal)/\mst@ltshape@normal} +\ifmst@LGRgreek\typeout{** Greek letters (\mst@greek@lsh/\mst@greek@ush) +will use LGR/\mst@greekfont} +\fi +\ifmst@nodigits\else\typeout{** Other characters (digits, ...) +and \protect\log-like names will be^^J% +** typeset with the \mst@shape@normal\space shape.} +\fi +\fi +\else % optional argument, then we rather do DeclareVersion + \edef\mst@tmp{#1} + \ifx\mst@tmp\empty + \Mathastext % no infinite loop! + \else + \MTDeclareVersion[\mst@ltsh]{#1} + {\mst@enc}{\mst@fam}{\mst@ser}{\mst@opsh} + \fi +\fi +} +\@onlypreamble\Mathastext +\let\mathastext\Mathastext +\newcommand*\MTDeclareVersion[6][\empty]{ + \edef\mst@version{#2} + \DeclareMathVersion{\mst@version} + \expandafter\edef\csname mst@encoding@\mst@version\endcsname{#3} + \expandafter\edef\csname mst@family@\mst@version\endcsname{#4} + \expandafter\edef\csname mst@series@\mst@version\endcsname{#5} + \expandafter\edef\csname mst@shape@\mst@version\endcsname{#6} + \expandafter\edef\csname mst@boldvariant@\mst@version\endcsname{\mst@bold} + \expandafter\edef\csname mst@itdefault@\mst@version\endcsname{\itdefault} + \expandafter\edef\csname mst@rmdefault@\mst@version\endcsname{\rmdefault} + \expandafter\edef\csname mst@sfdefault@\mst@version\endcsname{\sfdefault} + \expandafter\edef\csname mst@ttdefault@\mst@version\endcsname{\ttdefault} + \expandafter\edef\csname mst@exists@skip@\mst@version\endcsname + {\mst@exists@skip} + \expandafter\edef\csname mst@forall@skip@\mst@version\endcsname + {\mst@forall@skip} + \expandafter\edef\csname mst@prime@skip@\mst@version\endcsname + {\mst@prime@skip} + \mst@optionalparamfalse + \ifx\empty#1 + \else % we check nevertheless for [] situation, will not work with [ ] + \def\mst@tmp{#1} + \ifx\mst@tmp\empty\else\mst@optionalparamtrue\fi + \fi + \ifmst@optionalparam + \SetSymbolFont{mtletterfont}{#2}{#3}{#4}{#5}{#1} + \typeout{** Latin letters in math version `#2\string' will use the font + #3/#4/#5/#1^^J% + ** Other characters (digits, ...) and \protect\log-like + names will be in #6 shape.} + \expandafter\edef\csname mst@ltshape@\mst@version\endcsname{#1} + \else + \ifmst@italic + \SetSymbolFont{mtletterfont}{#2}{#3}{#4}{#5}{\mst@ltsh} + \typeout{** Latin letters in math version `#2\string' will use the font + #3/#4/#5/\mst@ltsh^^J% + ** Other characters (digits, ...) and \protect\log-like names + will be in #6 shape.} + \expandafter\edef\csname mst@ltshape@\mst@version\endcsname{\mst@ltsh} + \else + \SetSymbolFont{mtletterfont}{#2}{#3}{#4}{#5}{#6} + \typeout{** Latin letters in math version `#2\string' will use the fonts + #3/#4/#5(\mst@bold)/#6} + \expandafter\edef\csname mst@ltshape@\mst@version\endcsname{#6} + \fi + \fi + \ifmst@nonormalbold\else + \SetMathAlphabet{\mathnormalbold}{#2}{#3}{#4}{\mst@bold} + {\csname + mst@ltshape@\mst@version\endcsname} + \fi + \SetSymbolFont{mtoperatorfont}{#2}{#3}{#4}{#5}{#6} + \ifmst@defaultbf\else\SetMathAlphabet{\Mathbf}{#2}{#3}{#4}{\mst@bold}{#6}\fi + \ifmst@defaultit\else\SetMathAlphabet{\Mathit}{#2}{#3}{#4}{#5}{\itdefault}\fi + \ifmst@defaultsf\else\SetMathAlphabet{\Mathsf}{#2}{#3}{\sfdefault}{#5}{#6}\fi + \ifmst@defaulttt\else\SetMathAlphabet{\Mathtt}{#2}{#3}{\ttdefault}{#5}{#6}\fi + \ifmst@needeuler + \SetMathAlphabet{\MathEulerBold}{#2}{U}{zeur}{\mst@bold}{n} + \fi + \def\mst@greek@lsh@loc{\csname mst@ltshape@\mst@version\endcsname} + \def\mst@greek@ush@loc{\csname mst@shape@\mst@version\endcsname} + \ifmst@itgreek\def\mst@greek@lsh@loc{\itdefault} + \def\mst@greek@ush@loc{\itdefault}\fi + \ifmst@upgreek\def\mst@greek@lsh@loc{\updefault} + \def\mst@greek@ush@loc{\updefault}\fi + \ifmst@frenchmath + \ifmst@itgreek\else + \ifmst@upgreek\else + \def\mst@greek@lsh@loc{\csname mst@shape@\mst@version\endcsname} + \def\mst@greek@ush@loc{\csname mst@shape@\mst@version\endcsname} + \fi\fi + \fi + \ifcase\mst@greek@select + \or\def\mst@greek@ush@loc{\itdefault} + \or\def\mst@greek@ush@loc{\updefault} + \fi + \ifmst@LGRgreeks + \SetSymbolFont{mtlgrfontlower}{#2}{LGR}{#4}{#5}{\mst@greek@lsh@loc} + \SetSymbolFont{mtlgrfontupper}{#2}{LGR}{#4}{#5}{\mst@greek@ush@loc} + \typeout{** Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) will use + LGR font #4} + \else + \ifmst@selfGreeks + \SetSymbolFont{mtselfGreekfont}{#2}{OT1}{#4}{#5}{\mst@greek@ush@loc} + \typeout{** Capital Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) + will use OT1 font #4} + \else + \ifmst@LGRgreek + \SetSymbolFont{mtlgrfontlower}{#2}{LGR}{\mst@greekfont}{#5}{\mst@greek@lsh@loc} + \SetSymbolFont{mtlgrfontupper}{#2}{LGR}{\mst@greekfont}{#5}{\mst@greek@ush@loc} + \typeout{** Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) will use + LGR font \mst@greekfont} + \else + \ifmst@selfGreek + \SetSymbolFont{mtselfGreekfont}{#2}{OT1}{\mst@greekfont}{#5}{\mst@greek@ush@loc} + \typeout{** Capital Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) + will use OT1 font \mst@greekfont} + \fi\fi\fi\fi +} +\@onlypreamble\MTDeclareVersion +\let\MathastextDeclareVersion\MTDeclareVersion +\newcommand*\MTVersion[2][\empty]{% + \mathversion{#2}% + \ifx\empty#1% no optional argument + \def\mst@tmp{#2}% + \else% we check nevertheless for [] situation, will not work with [ ] + \def\mst@tmpa{#1}% + \ifx\mst@tmpa\empty\def\mst@tmp{#2}% + \else\def\mst@tmp{#1}% + \fi% + \fi% + \usefont{\csname mst@encoding@\mst@tmp\endcsname}% + {\csname mst@family@\mst@tmp\endcsname}% + {\csname mst@series@\mst@tmp\endcsname}% + {\csname mst@shape@\mst@tmp\endcsname}% + \edef\mst@@encoding{\csname mst@encoding@\mst@tmp\endcsname}% + \renewcommand{\encodingdefault}{\mst@@encoding}% +%% some modifications for v1.15b + \edef\mst@@famdefault{\csname mst@family@\mst@tmp\endcsname}% + \renewcommand{\familydefault}{\mst@@famdefault}% + \edef\mst@@series{\csname mst@series@\mst@tmp\endcsname}% + \renewcommand{\mddefault}{\mst@@series}% + \edef\mst@@shape{\csname mst@shape@\mst@tmp\endcsname}% + \renewcommand{\shapedefault}{\mst@@shape}% + \edef\mst@@boldvariant{\csname mst@boldvariant@\mst@tmp\endcsname}% + \renewcommand{\bfdefault}{\mst@@boldvariant}% + \edef\mst@@itdefault{\csname mst@itdefault@\mst@tmp\endcsname}% + \renewcommand{\itdefault}{\mst@@itdefault}% + \edef\mst@@rmdefault{\csname mst@rmdefault@\mst@tmp\endcsname}% + \renewcommand{\rmdefault}{\mst@@rmdefault}% + \edef\mst@@sfdefault{\csname mst@sfdefault@\mst@tmp\endcsname}% + \renewcommand{\sfdefault}{\mst@@sfdefault}% + \edef\mst@@ttdefault{\csname mst@ttdefault@\mst@tmp\endcsname}% + \renewcommand{\ttdefault}{\mst@@ttdefault}% + \edef\mst@tmp{#2}% +%% v1.15e: muskips + \expandafter + \mst@exists@muskip\csname mst@exists@skip@\mst@tmp\endcsname\relax + \expandafter + \mst@forall@muskip\csname mst@forall@skip@\mst@tmp\endcsname\relax +%% v1.2: muskip for \cs{prime} + \expandafter + \mst@prime@muskip\csname mst@prime@skip@\mst@tmp\endcsname\relax +%% v1.2b: italic corrections except for italic/slanted (sic) letters, and of +%% course except in the subdued normal and bold math versions + \edef\mst@tmpa{\csname mst@ltshape@\mst@tmp\endcsname}% + \edef\mst@tmpb{\csname mst@shape@\mst@tmp\endcsname}% + \MTicinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@tmpa\MTnoicinmath\fi}% + \ifmst@frenchmath + \MTICinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@tmpb\MTnoICinmath\fi}% + \fi +%% v1.15c: extending subdued to LGRgreek +%% v1.15f: subdueing math alphabets in a simpler way than in 1.15e +%% v1.2b: subdueing the activation of characters in math mode +%% v1.2d: special treatment of the asterisk + \MTmathoperatorsobeymathxx + \MTeasynonlettersobeymathxx + \ifmst@asterisk\let\mst@doasterisk\mst@@doasterisk\fi + \ifmst@subdued + \edef\mst@tmp{#2}\def\mst@tmpa{normal}% + \ifx\mst@tmp\mst@tmpa + \mst@restorealphabets + \MTmathoperatorsdonotobeymathxx + \MTnonlettersdonotobeymathxx + \MTeasynonlettersdonotobeymathxx + \MTnoicinmath + \ifmst@asterisk\let\mst@doasterisk\relax\fi + \ifmst@LGRgreek\mst@restoregreek\fi + \else + \def\mst@tmpa{bold}% + \ifx\mst@tmp\mst@tmpa + \mst@restorealphabets + \MTmathoperatorsdonotobeymathxx + \MTnonlettersdonotobeymathxx + \MTeasynonlettersdonotobeymathxx + \MTnoicinmath + \ifmst@asterisk\let\mst@doasterisk\relax\fi + \ifmst@LGRgreek\mst@restoregreek\fi + \else + \mst@setalphabets + \ifmst@LGRgreek\mst@setuplgrgreek\fi + \fi\fi\fi +} +\let\MathastextVersion\MTVersion +\let\Mathastextversion\MTVersion +\let\MTversion\MTVersion +\let\mathastextversion\MTVersion +\Mathastext +\ifmst@eulergreek + \typeout{** Greek letters will use the Euler font. Use^^J% +** \protect\MathastextEulerScale{} to scale the font.} +\else +\ifmst@symbolgreek + \typeout{** Greek letters will use the PostScript Symbol font. Use^^J% +** \protect\MathastextSymbolScale{} to scale the font.} +\fi\fi +\def\mst@DeclareMathSymbol#1#2#3#4{% + \DeclareMathSymbol{#1}{#2}{#3}{#4} + \expandafter\DeclareMathSymbol\csname mst@#1\endcsname{#2}{#3}{#4} + \expandafter\mst@addtodo@az + \expandafter#1\csname mst@#1\endcsname\mst@itcorr} +\mst@DeclareMathSymbol{a}{\mathalpha}{mtletterfont}{`a} +\mst@DeclareMathSymbol{b}{\mathalpha}{mtletterfont}{`b} +\mst@DeclareMathSymbol{c}{\mathalpha}{mtletterfont}{`c} +\mst@DeclareMathSymbol{d}{\mathalpha}{mtletterfont}{`d} +\mst@DeclareMathSymbol{e}{\mathalpha}{mtletterfont}{`e} +\mst@DeclareMathSymbol{f}{\mathalpha}{mtletterfont}{`f} +\mst@DeclareMathSymbol{g}{\mathalpha}{mtletterfont}{`g} +\mst@DeclareMathSymbol{h}{\mathalpha}{mtletterfont}{`h} +\mst@DeclareMathSymbol{i}{\mathalpha}{mtletterfont}{`i} +\mst@DeclareMathSymbol{j}{\mathalpha}{mtletterfont}{`j} +\mst@DeclareMathSymbol{k}{\mathalpha}{mtletterfont}{`k} +\mst@DeclareMathSymbol{l}{\mathalpha}{mtletterfont}{`l} +\mst@DeclareMathSymbol{m}{\mathalpha}{mtletterfont}{`m} +\mst@DeclareMathSymbol{n}{\mathalpha}{mtletterfont}{`n} +\mst@DeclareMathSymbol{o}{\mathalpha}{mtletterfont}{`o} +\mst@DeclareMathSymbol{p}{\mathalpha}{mtletterfont}{`p} +\mst@DeclareMathSymbol{q}{\mathalpha}{mtletterfont}{`q} +\mst@DeclareMathSymbol{r}{\mathalpha}{mtletterfont}{`r} +\mst@DeclareMathSymbol{s}{\mathalpha}{mtletterfont}{`s} +\mst@DeclareMathSymbol{t}{\mathalpha}{mtletterfont}{`t} +\mst@DeclareMathSymbol{u}{\mathalpha}{mtletterfont}{`u} +\mst@DeclareMathSymbol{v}{\mathalpha}{mtletterfont}{`v} +\mst@DeclareMathSymbol{w}{\mathalpha}{mtletterfont}{`w} +\mst@DeclareMathSymbol{x}{\mathalpha}{mtletterfont}{`x} +\mst@DeclareMathSymbol{y}{\mathalpha}{mtletterfont}{`y} +\mst@DeclareMathSymbol{z}{\mathalpha}{mtletterfont}{`z} +\ifmst@frenchmath\def\mst@font@tbu{mtoperatorfont} + \else\def\mst@font@tbu{mtletterfont}\fi +\def\mst@DeclareMathSymbol#1#2#3#4{% + \DeclareMathSymbol{#1}{#2}{#3}{#4} + \expandafter\DeclareMathSymbol\csname mst@#1\endcsname{#2}{#3}{#4} + \expandafter\mst@addtodo@AZ + \expandafter#1\csname mst@#1\endcsname\mst@ITcorr} +\mst@DeclareMathSymbol{A}{\mathalpha}{\mst@font@tbu}{`A} +\mst@DeclareMathSymbol{B}{\mathalpha}{\mst@font@tbu}{`B} +\mst@DeclareMathSymbol{C}{\mathalpha}{\mst@font@tbu}{`C} +\mst@DeclareMathSymbol{D}{\mathalpha}{\mst@font@tbu}{`D} +\mst@DeclareMathSymbol{E}{\mathalpha}{\mst@font@tbu}{`E} +\mst@DeclareMathSymbol{F}{\mathalpha}{\mst@font@tbu}{`F} +\mst@DeclareMathSymbol{G}{\mathalpha}{\mst@font@tbu}{`G} +\mst@DeclareMathSymbol{H}{\mathalpha}{\mst@font@tbu}{`H} +\mst@DeclareMathSymbol{I}{\mathalpha}{\mst@font@tbu}{`I} +\mst@DeclareMathSymbol{J}{\mathalpha}{\mst@font@tbu}{`J} +\mst@DeclareMathSymbol{K}{\mathalpha}{\mst@font@tbu}{`K} +\mst@DeclareMathSymbol{L}{\mathalpha}{\mst@font@tbu}{`L} +\mst@DeclareMathSymbol{M}{\mathalpha}{\mst@font@tbu}{`M} +\mst@DeclareMathSymbol{N}{\mathalpha}{\mst@font@tbu}{`N} +\mst@DeclareMathSymbol{O}{\mathalpha}{\mst@font@tbu}{`O} +\mst@DeclareMathSymbol{P}{\mathalpha}{\mst@font@tbu}{`P} +\mst@DeclareMathSymbol{Q}{\mathalpha}{\mst@font@tbu}{`Q} +\mst@DeclareMathSymbol{R}{\mathalpha}{\mst@font@tbu}{`R} +\mst@DeclareMathSymbol{S}{\mathalpha}{\mst@font@tbu}{`S} +\mst@DeclareMathSymbol{T}{\mathalpha}{\mst@font@tbu}{`T} +\mst@DeclareMathSymbol{U}{\mathalpha}{\mst@font@tbu}{`U} +\mst@DeclareMathSymbol{V}{\mathalpha}{\mst@font@tbu}{`V} +\mst@DeclareMathSymbol{W}{\mathalpha}{\mst@font@tbu}{`W} +\mst@DeclareMathSymbol{X}{\mathalpha}{\mst@font@tbu}{`X} +\mst@DeclareMathSymbol{Y}{\mathalpha}{\mst@font@tbu}{`Y} +\mst@DeclareMathSymbol{Z}{\mathalpha}{\mst@font@tbu}{`Z} +%% +\ifmst@nodigits\else +\def\mst@font@tbu{mtoperatorfont} +\ifmst@symboldigits \def\mst@font@tbu{mtpsymbol} \fi +\ifmst@eulerdigits \def\mst@font@tbu{mteulervm} \fi +\DeclareMathSymbol{0}{\mathalpha}{\mst@font@tbu}{`0} +\DeclareMathSymbol{1}{\mathalpha}{\mst@font@tbu}{`1} +\DeclareMathSymbol{2}{\mathalpha}{\mst@font@tbu}{`2} +\DeclareMathSymbol{3}{\mathalpha}{\mst@font@tbu}{`3} +\DeclareMathSymbol{4}{\mathalpha}{\mst@font@tbu}{`4} +\DeclareMathSymbol{5}{\mathalpha}{\mst@font@tbu}{`5} +\DeclareMathSymbol{6}{\mathalpha}{\mst@font@tbu}{`6} +\DeclareMathSymbol{7}{\mathalpha}{\mst@font@tbu}{`7} +\DeclareMathSymbol{8}{\mathalpha}{\mst@font@tbu}{`8} +\DeclareMathSymbol{9}{\mathalpha}{\mst@font@tbu}{`9} +\fi +\ifmst@symboldelimiters +\def\mst@font@tbu{mtpsymbol} +\mst@endashfalse +\mst@emdashfalse +\else +\def\mst@font@tbu{mtoperatorfont} +\fi +\ifmst@noexclam\else\typeout{** \string! and \string?} +\DeclareMathSymbol{!}{\mathclose}{\mst@font@tbu}{"21} +\DeclareMathSymbol{\mst@varfam@exclam}{\mathalpha}{\mst@font@tbu}{"21} +\expandafter\mst@addtodo@nonletters\string!\mathclose\mst@varfam@exclam +\DeclareMathSymbol{?}{\mathclose}{\mst@font@tbu}{"3F} +\DeclareMathSymbol{\mst@varfam@question}{\mathalpha}{\mst@font@tbu}{"3F} +\expandafter\mst@addtodo@nonletters\string?\mathclose\mst@varfam@question +\fi +\def\mst@@doasterisk{\let\ast\mst@ast\mst@mathactivate*{}\mst@ast} +\ifmst@asterisk\typeout{** asterisk: \string\ast\space and *} + \ifmst@symbolmisc + \def\mst@bin@ast{% + \mathbin{\mathchoice{\raisebox{-.1\height} + {\the\textfont\symmtpsymbol\char42}} + {\raisebox{-.1\height} + {\the\textfont\symmtpsymbol\char42}} + {\raisebox{-.1\height} + {\the\scriptfont\symmtpsymbol\char42}} + {\raisebox{-.1\height} + {\the\scriptscriptfont\symmtpsymbol\char42}}}} + \else + \def\mst@bin@ast{% + \mathbin{\mathchoice{\raisebox{-\mst@lowerast} + {\the\textfont\symmtoperatorfont\char42}} + {\raisebox{-\mst@lowerast} + {\the\textfont\symmtoperatorfont\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptfont\symmtoperatorfont\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptscriptfont\symmtoperatorfont\char42}}}} + \fi + \def\mst@varfam@ast{\ifnum\fam=\m@ne\mst@bin@ast\else + \mathbin{\mathchoice{\raisebox{-\mst@lowerast} + {\the\textfont\fam\char42}} + {\raisebox{-\mst@lowerast} + {\the\textfont\fam\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptfont\fam\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptscriptfont\fam\char42}}}\fi} + \let\mst@doasterisk\mst@@doasterisk + \DeclareRobustCommand*{\mst@ast}{\mst@bin@ast} + \newcommand*\MTlowerast[1]{\def\mst@lowerast{#1}} + \MTlowerast{.3\height} + \mst@do@easynonletters\expandafter{\the\mst@do@easynonletters + \expandafter\def\csname mst@ast \endcsname{\mst@varfam@ast}} +\fi +\ifmst@nopunct\else\typeout{** punctuation\string: \string, \string. \string: \string; and \string\colon} +\DeclareMathSymbol{,}{\mathpunct}{\mst@font@tbu}{"2C} +\DeclareMathSymbol{\mst@varfam@comma}{\mathalpha}{\mst@font@tbu}{"2C} +\expandafter\mst@addtodo@nonletters\string,\mathpunct\mst@varfam@comma +\DeclareMathSymbol{.}{\mathord}{\mst@font@tbu}{"2E} +\DeclareMathSymbol{\mst@varfam@dot}{\mathalpha}{\mst@font@tbu}{"2E} +\mst@addtodo@easynonletters\.\mst@varfam@dot +\DeclareMathSymbol{:}{\mathrel}{\mst@font@tbu}{"3A} % relation spacing +\DeclareMathSymbol{\mst@varfam@colon}{\mathalpha}{\mst@font@tbu}{"3A} +\expandafter\mst@addtodo@nonletters\string:\mathrel\mst@varfam@colon +\@ifpackageloaded{amsmath} +{} % \colon defined in amsmath.sty in terms of : with some enlarged explicit + % spacing. No need to intervene. +{% no amsmath, use standard punctuation spacing +\let\colon\undefined + % the reason is if some package has redefined \colon which then + % can not be used in \cs{DeclareMathSymbol} anymore (we + % shamelessly overwrite...) + \DeclareMathSymbol{\colon}{\mathpunct}{\mst@font@tbu}{"3A} + \mst@do@nonletters\expandafter{\the\mst@do@nonletters + \def\colon{\mathpunct{\mst@varfam@colon}}}} +\DeclareMathSymbol{;}{\mathpunct}{\mst@font@tbu}{"3B} +\DeclareMathSymbol{\mst@varfam@pointvirgule}{\mathalpha}{\mst@font@tbu}{"3B} +\expandafter\mst@addtodo@nonletters\string;\mathpunct\mst@varfam@pointvirgule +\fi +\ifmst@nominus\else +\ifmst@XeTeX +\XeTeXmathcharnumdef\mst@minus@sign=\XeTeXmathcodenum`\-\relax +\else +\ifmst@LuaTeX +%% \luatexUmathcharnumdef\mst@minus@sign=\luatexUmathcodenum`\-\relax ne +%% marche pas pour le moment car \luatexUmathcodenum retourne parfois un +%% legacy mathcode, parfois un Unicode mathcode, \`a mon avis c'est un bug +%% de LuaLatex. En fait Taco H me dit que la prochaine version +%% r\'eglera ce probl\`eme. \luatexUmathchardef\mst@minus@sign="2 "2 "0\relax +\mathchardef\mst@minus@sign=8704\relax % "2200 +\else +\mathchardef\mst@minus@sign=\mathcode`\-\relax +\fi\fi +\@ifpackageloaded{amsmath} +{\def\relbar{\mathrel{\mathpalette\mathsm@sh\mst@minus@sign}}} +{\DeclareRobustCommand\relbar{\mathrel{\smash\mst@minus@sign}}} +\def\rightarrowfill{$\m@th\mathord{\relbar}\mkern-7mu% + \cleaders\hbox{$\mkern-2mu\relbar\mkern-2mu$}\hfill + \mkern-7mu\mathord\rightarrow$} +\def\leftarrowfill{$\m@th\mathord\leftarrow\mkern-7mu% + \cleaders\hbox{$\mkern-2mu\relbar\mkern-2mu$}\hfill + \mkern-7mu\mathord{\relbar}$} +\fi +\def\do@the@endashstuff{\edef\mst@tmp@enc{\encodingdefault} + \ifx\mst@tmp@enc\mst@eui % xetex+fontspec + \AtBeginDocument{% + \XeTeXmathcode`\-="2 \symmtoperatorfont "2013\relax + \XeTeXmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2013\relax + } +\else + \ifx\mst@tmp@enc\mst@euii % luatex+fontspec + \AtBeginDocument{% + \luatexUmathcode`\-="2 \symmtoperatorfont "2013\relax + \luatexUmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2013\relax + } +\else + \ifx\mst@tmp@enc\mst@ti % T1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{21} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{21} +\else + \ifx\mst@tmp@enc\mst@oti % OT1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{123} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{123} +\else + \ifx\mst@tmp@enc\mst@lyi % LY1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{150} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{150} +\else % make sure we have neither xetex nor luatex + \ifmst@XeTeX\mst@aborttrue\else\ifmst@LuaTeX\mst@aborttrue\else + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\textendash\endcsname} + \fi\fi +\fi\fi\fi\fi\fi} +\def\do@the@emdashstuff{\edef\mst@tmp@enc{\encodingdefault} +\ifx\mst@tmp@enc\mst@eui % xetex+fontspec + \AtBeginDocument{% + \XeTeXmathcode`\-="2 \symmtoperatorfont "2014\relax + \XeTeXmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2014\relax + } +\else +\ifx\mst@tmp@enc\mst@euii % luatex+fontspec + \AtBeginDocument{% + \luatexUmathcode`\-="2 \symmtoperatorfont "2014\relax + \luatexUmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2014\relax + } +\else + \ifx\mst@tmp@enc\mst@ti % T1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{22} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{22} +\else +\ifx\mst@tmp@enc\mst@oti % OT1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{124} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{124} +\else +\ifx\mst@tmp@enc\mst@lyi % LY1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{151} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{151} +\else % make sure we have neither xetex nor luatex + \ifmst@XeTeX\mst@aborttrue\else\ifmst@LuaTeX\mst@aborttrue\else + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\textemdash\endcsname} + \fi\fi +\fi\fi\fi\fi\fi} +\ifmst@nominus\else\typeout{** minus as endash} +\mst@abortfalse +\ifmst@endash\do@the@endashstuff\else +\ifmst@emdash\do@the@emdashstuff\else + \DeclareMathSymbol{-}{\mathbin}{\mst@font@tbu}{"2D} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{\mst@font@tbu}{"2D} +\fi\fi +\ifmst@abort + \DeclareMathSymbol{-}{\mathbin}{\mst@font@tbu}{"2D} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{\mst@font@tbu}{"2D} +\fi +\expandafter\mst@addtodo@nonletters\string-\mathbin\mst@varfam@minus +\fi +%%\def\hbar{{\mathchar'26\mkern-9muh}} % (original definition from latex.ltx) +\def\mst@mathrlap{\mathpalette\mst@mathrlapinternal} +\def\mst@mathrlapinternal#1#2{\rlap{$\mathsurround=0pt#1{#2}$}} +\def\do@the@hbarstuff{\edef\mst@tmp@enc{\encodingdefault} +\ifx\mst@tmp@enc\mst@eui % xetex and unicode font + \XeTeXmathchardef\hbar="7 \symmtletterfont "0127 \relax +\else +\ifx\mst@tmp@enc\mst@euii % luatex and unicode font + \luatexUmathchardef\hbar="7 \symmtletterfont "0127 \relax %% or 210F? +\else % I must leave open the T1, OT1 possibility also for XeTeX or LuaTeX + \ifx\mst@ti\mst@tmp@enc + \DeclareMathAccent{\mst@ltbar}{\mathalpha}{mtletterfont}{9} + \else %% assume OT1. Bad idea? Should not provoke an error anyhow + \DeclareMathAccent{\mst@ltbar}{\mathalpha}{mtletterfont}{22} + \fi + \def\hbar{\mst@mathrlap{\mst@ltbar{\ }}h} +\fi\fi} +\ifmst@nohbar\else\typeout{** \string\hbar}\do@the@hbarstuff\fi +\ifmst@noplus\else\typeout{** \string+ and \string=} +\DeclareMathSymbol{+}{\mathbin}{\mst@font@tbu}{"2B} +\DeclareMathSymbol{\mst@varfam@plus}{\mathalpha}{\mst@font@tbu}{"2B} +\expandafter\mst@addtodo@nonletters\string+\mathbin\mst@varfam@plus +\fi +\ifmst@noequal\else +\ifmst@XeTeX +\XeTeXmathcharnumdef\mst@equal@sign=\XeTeXmathcodenum`\=\relax +\else +\ifmst@LuaTeX +%% 12 octobre 2012 \luatexUmathcodenum`\= +%% ne marche pas pour le moment \`a cause du fait que \luatexUmathcodenum +%% donne un mathcode sur 8bit ou un Unicode mathcode sans qu'on puisse +%% savoir lequel +%% \luatexUmathchardef\mst@equal@sign="3 "0 "3D\relax +\mathchardef\mst@equal@sign=12349\relax +\else +\mathchardef\mst@equal@sign=\mathcode`\=\relax +\fi\fi +\@ifpackageloaded{amsmath} +{\def\Relbar{\mathrel\mst@equal@sign}} +{\DeclareRobustCommand\Relbar{\mathrel{\mst@equal@sign}}} +\DeclareMathSymbol{=}{\mathrel}{\mst@font@tbu}{"3D} +\DeclareMathSymbol{\mst@varfam@equal}{\mathalpha}{\mst@font@tbu}{"3D} +\typeout{** adding \string= \string; and \string+ to \string\nfss@catcodes} +\g@addto@macro\nfss@catcodes{% + \@makeother\=% + \@makeother\;% + \@makeother\+% +} +\expandafter\mst@addtodo@nonletters\string=\mathrel\mst@varfam@equal +\fi +\ifmst@noparen\else\typeout{** parentheses \string( \string) \string[ \string] and slash \string/} +\ifmst@nosmalldelims + \DeclareMathSymbol{(}{\mathopen}{\mst@font@tbu}{"28} + \DeclareMathSymbol{)}{\mathclose}{\mst@font@tbu}{"29} + \DeclareMathSymbol{[}{\mathopen} {\mst@font@tbu}{"5B} + \DeclareMathSymbol{]}{\mathclose}{\mst@font@tbu}{"5D} + \DeclareMathSymbol{/}{\mathord}{\mst@font@tbu}{"2F} +\else + \DeclareMathDelimiter{(}{\mathopen}{\mst@font@tbu}{"28}{largesymbols}{"00} + \DeclareMathDelimiter{)}{\mathclose}{\mst@font@tbu}{"29}{largesymbols}{"01} + \DeclareMathDelimiter{[}{\mathopen} {\mst@font@tbu}{"5B}{largesymbols}{"02} + \DeclareMathDelimiter{]}{\mathclose}{\mst@font@tbu}{"5D}{largesymbols}{"03} + \DeclareMathDelimiter{/}{\mathord}{\mst@font@tbu}{"2F}{largesymbols}{"0E} +\fi +\DeclareMathSymbol{\mst@varfam@lparen}{\mathalpha}{\mst@font@tbu}{40} +\DeclareMathSymbol{\mst@varfam@rparen}{\mathalpha}{\mst@font@tbu}{41} +\DeclareMathSymbol{\mst@varfam@lbrack}{\mathalpha}{\mst@font@tbu}{"5B} +\DeclareMathSymbol{\mst@varfam@rbrack}{\mathalpha}{\mst@font@tbu}{"5D} +\DeclareMathSymbol{\mst@varfam@slash}{\mathalpha}{\mst@font@tbu}{"2F} +\expandafter\mst@addtodo@nonletters\string(\mathopen\mst@varfam@lparen +\expandafter\mst@addtodo@nonletters\string)\mathclose\mst@varfam@rparen +\expandafter\mst@addtodo@nonletters\string[\mathopen\mst@varfam@lbrack +\expandafter\mst@addtodo@nonletters\string]\mathclose\mst@varfam@rbrack +\mst@addtodo@easynonletters\/\mst@varfam@slash +\fi +\ifmst@alldelims\typeout{** alldelims: \string< \string> + \string\backslash\space\string\setminus\space| + \string\vert\space\string\mid\space\string\{\space and \string\}} +\ifmst@nosmalldelims + \DeclareMathDelimiter{\mst@varfam@backslash} + {\mathalpha}{symbols}{"6E}{largesymbols}{"0F} +\else + \DeclareMathDelimiter{<}{\mathopen}{\mst@font@tbu}{"3C}{largesymbols}{"0A} + \DeclareMathDelimiter{>}{\mathclose}{\mst@font@tbu}{"3E}{largesymbols}{"0B} + \expandafter\DeclareMathDelimiter\@backslashchar + {\mathord}{mtoperatorfont}{"5C}{largesymbols}{"0F} + \DeclareMathDelimiter{\backslash} + {\mathord}{mtoperatorfont}{"5C}{largesymbols}{"0F} + \DeclareMathDelimiter{\mst@varfam@backslash} + {\mathalpha}{mtoperatorfont}{"5C}{largesymbols}{"0F} +\fi +\DeclareMathSymbol{<}{\mathrel}{\mst@font@tbu}{"3C} +\DeclareMathSymbol{>}{\mathrel}{\mst@font@tbu}{"3E} +\DeclareMathSymbol{\mst@varfam@less}{\mathalpha}{\mst@font@tbu}{"3C} +\DeclareMathSymbol{\mst@varfam@more}{\mathalpha}{\mst@font@tbu}{"3E} +\expandafter\mst@addtodo@nonletters\string<\mathrel\mst@varfam@less +\expandafter\mst@addtodo@nonletters\string>\mathrel\mst@varfam@more +\mst@do@easynonletters\expandafter{\the\mst@do@easynonletters + \let\backslash\mst@varfam@backslash} +\DeclareMathSymbol{\setminus}{\mathbin}{mtoperatorfont}{"5C} +\DeclareMathSymbol{\mst@varfam@setminus}{\mathalpha}{mtoperatorfont}{"5C} +\mst@do@nonletters\expandafter{\the\mst@do@nonletters + \def\setminus{\mathbin{\mst@varfam@setminus}}} +\ifmst@XeTeX +\XeTeXmathcharnumdef\mst@vert@bar=\XeTeXmathcodenum`\|\relax +\else +\ifmst@LuaTeX +%% \luatexUmathchardef\mst@vert@bar="0 "2 "006A\relax +\mathchardef\mst@vert@bar=618\relax +\else\mathchardef\mst@vert@bar=\mathcode`\|\relax +\fi\fi +\DeclareRobustCommand\models{\mathrel{\mst@vert@bar}\joinrel\Relbar} +\ifmst@nosmalldelims + \DeclareMathSymbol{|}{\mathord}{\mst@font@tbu}{124} +\else + \DeclareMathDelimiter{|}{\mathord}{\mst@font@tbu}{124}{largesymbols}{"0C} +\fi +\def\vert{|} +\DeclareMathSymbol{\mst@varfam@vbar}{\mathalpha}{\mst@font@tbu}{124} +\mst@addtodo@easynonletters\|\mst@varfam@vbar +\DeclareMathSymbol{\mid}{\mathrel}{\mst@font@tbu}{124} +\mst@do@nonletters\expandafter{\the\mst@do@nonletters + \def\mid{\mathrel\mst@varfam@vbar}} +\ifmst@nosmalldelims + \DeclareMathSymbol{\lbrace}{\mathopen}{\mst@font@tbu}{123} + \DeclareMathSymbol{\rbrace}{\mathclose}{\mst@font@tbu}{125} +\else + \DeclareMathDelimiter{\lbrace} + {\mathopen}{\mst@font@tbu}{123}{largesymbols}{"08} + \DeclareMathDelimiter{\rbrace} + {\mathclose}{\mst@font@tbu}{125}{largesymbols}{"09} +\fi +\DeclareMathSymbol{\mst@varfam@lbrace}{\mathalpha}{\mst@font@tbu}{123} +\DeclareMathSymbol{\mst@varfam@rbrace}{\mathalpha}{\mst@font@tbu}{125} +\DeclareRobustCommand*{\mst@lbrace} + {\ifmmode\mathopen\mst@varfam@lbrace\else\textbraceleft\fi} +\DeclareRobustCommand*{\mst@rbrace} + {\ifmmode\mathclose\mst@varfam@rbrace\else\textbraceright\fi} +\mst@do@nonletters\expandafter{\the\mst@do@nonletters + \mst@dobraces{\let\{\mst@lbrace\let\}\mst@rbrace}} +\fi % end of \ifmst@alldelims +\newcommand*{\MTexplicitbracesobeymathxx}{\let\mst@dobraces\@firstofone} +\newcommand*{\MTexplicitbracesdonotobeymathxx}{\let\mst@dobraces\@gobble} +\MTexplicitbracesdonotobeymathxx +\ifmst@nospecials\else\typeout{** \string\#\space\string\mathdollar\space\string\%\space\string\&\space} +\count255=\symmtoperatorfont +\multiply\count255 by 256 +\advance\count255 by 35 + \mathcode`\#\count255 +\advance\count255 by 1 + \mathchardef\mathdollar\count255 +\advance\count255 by 1 + \mathcode`\%\count255 +\advance\count255 by 1 + \mathcode`\&\count255 +\count255=\symmtoperatorfont +\multiply\count255 by 256 +\advance\count255 by 28707 % = "7023 + \mathchardef\mst@varfam@mathhash\count255 +\advance\count255 by 1 + \mathchardef\mst@varfam@mathdollar\count255 +\advance\count255 by 1 + \mathchardef\mst@varfam@mathpercent\count255 +\advance\count255 by 1 + \mathchardef\mst@varfam@mathampersand\count255 +\mst@do@easynonletters\expandafter{\the\mst@do@easynonletters + \mathcode`\#=\mst@varfam@mathhash + \let\mathdollar\mst@varfam@mathdollar + \mathcode`\%=\mst@varfam@mathpercent + \mathcode`\&=\mst@varfam@mathampersand} +\fi +\ifmst@symbolmisc\typeout{** symbolmisc: miscellaneous math symbols from Symbol font} +\let\mst@prod\prod +\let\defaultprod\prod +\DeclareMathSymbol{\prodpsy}{\mathop}{mtpsymbol}{213} +\renewcommand*{\prod}{\ifinner\prodpsy\else\mst@prod\fi} +\let\mst@sum\sum +\let\defaultsum\sum +\DeclareMathSymbol{\sumpsy}{\mathop}{mtpsymbol}{229} +\renewcommand*{\sum}{\ifinner\sumpsy\else\mst@sum\fi} +\DeclareMathSymbol{\mst@implies}{\mathrel}{mtpsymbol}{222} +\DeclareRobustCommand*{\implies}{\;\mst@implies\;} +\DeclareMathSymbol{\mst@impliedby}{\mathrel}{mtpsymbol}{220} +\DeclareRobustCommand*{\impliedby}{\;\mst@impliedby\;} +\DeclareRobustCommand*{\iff}{\;\mst@impliedby\mathrel{\mkern-3mu}\mst@implies\;} +\DeclareMathSymbol{\mst@iff}{\mathrel}{mtpsymbol}{219} +\DeclareRobustCommand*{\shortiff}{\;\mst@iff\;} +\DeclareMathSymbol{\mst@to}{\mathrel}{mtpsymbol}{174} +\DeclareMathSymbol{\mst@trait}{\mathrel}{mtpsymbol}{190} +\DeclareRobustCommand*\to{\mst@to} +\DeclareRobustCommand*\longto{\mkern2mu\mst@trait\mathrel{\mkern-10mu}\mst@to} +\DeclareRobustCommand*\mapsto{\mapstochar\mathrel{\mkern0.2mu}\mst@to} +\DeclareRobustCommand*\longmapsto{% +\mapstochar\mathrel{\mkern2mu}\mst@trait\mathrel{\mkern-10mu}\mst@to} +\DeclareMathSymbol{\aleph}{\mathord}{mtpsymbol}{192} +\DeclareMathSymbol{\inftypsy}{\mathord}{mtpsymbol}{165} +\DeclareMathSymbol{\emptyset}{\mathord}{mtpsymbol}{198} +\let\varnothing\emptyset +\DeclareMathSymbol{\nabla}{\mathord}{mtpsymbol}{209} +\DeclareMathSymbol{\surd}{\mathop}{mtpsymbol}{214} +\let\angle\undefined +\DeclareMathSymbol{\angle}{\mathord}{mtpsymbol}{208} +\DeclareMathSymbol{\forall}{\mathord}{mtpsymbol}{34} +\DeclareMathSymbol{\exists}{\mathord}{mtpsymbol}{36} +\DeclareMathSymbol{\neg}{\mathord}{mtpsymbol}{216} +\DeclareMathSymbol{\clubsuit}{\mathord}{mtpsymbol}{167} +\DeclareMathSymbol{\diamondsuit}{\mathord}{mtpsymbol}{168} +\DeclareMathSymbol{\heartsuit}{\mathord}{mtpsymbol}{169} +\DeclareMathSymbol{\spadesuit}{\mathord}{mtpsymbol}{170} +\DeclareMathSymbol{\smallint}{\mathop}{mtpsymbol}{242} +\DeclareMathSymbol{\wedge}{\mathbin}{mtpsymbol}{217} +\DeclareMathSymbol{\vee}{\mathbin}{mtpsymbol}{218} +\DeclareMathSymbol{\cap}{\mathbin}{mtpsymbol}{199} +\DeclareMathSymbol{\cup}{\mathbin}{mtpsymbol}{200} +\DeclareMathSymbol{\bullet}{\mathbin}{mtpsymbol}{183} +\DeclareMathSymbol{\div}{\mathbin}{mtpsymbol}{184} +\DeclareMathSymbol{\otimes}{\mathbin}{mtpsymbol}{196} +\DeclareMathSymbol{\oplus}{\mathbin}{mtpsymbol}{197} +\DeclareMathSymbol{\pm}{\mathbin}{mtpsymbol}{177} +\DeclareMathSymbol{\times}{\mathbin}{mtpsymbol}{180} +\DeclareMathSymbol{\proptopsy}{\mathrel}{mtpsymbol}{181} +\DeclareMathSymbol{\mid}{\mathrel}{mtpsymbol}{124} +\DeclareMathSymbol{\leq}{\mathrel}{mtpsymbol}{163} +\DeclareMathSymbol{\geq}{\mathrel}{mtpsymbol}{179} +\DeclareMathSymbol{\approx}{\mathrel}{mtpsymbol}{187} +\DeclareMathSymbol{\supset}{\mathrel}{mtpsymbol}{201} +\DeclareMathSymbol{\subset}{\mathrel}{mtpsymbol}{204} +\DeclareMathSymbol{\supseteq}{\mathrel}{mtpsymbol}{202} +\DeclareMathSymbol{\subseteq}{\mathrel}{mtpsymbol}{205} +\DeclareMathSymbol{\in}{\mathrel}{mtpsymbol}{206} +\DeclareMathSymbol{\sim}{\mathrel}{mtpsymbol}{126} +\let\cong\undefined +\DeclareMathSymbol{\cong}{\mathrel}{mtpsymbol}{64} +\DeclareMathSymbol{\perp}{\mathrel}{mtpsymbol}{94} +\DeclareMathSymbol{\equiv}{\mathrel}{mtpsymbol}{186} +\let\notin\undefined +\DeclareMathSymbol{\notin}{\mathrel}{mtpsymbol}{207} +\DeclareMathDelimiter{\rangle} + {\mathclose}{mtpsymbol}{241}{largesymbols}{"0B} +\DeclareMathDelimiter{\langle} + {\mathopen}{mtpsymbol}{225}{largesymbols}{"0A} +\fi +\ifmst@symbolre\typeout{** symbolre: \string\Re\space and \string\Im\space from Symbol font} +\DeclareMathSymbol{\Re}{\mathord}{mtpsymbol}{"C2} +\DeclareMathSymbol{\Im}{\mathord}{mtpsymbol}{"C1} +\DeclareMathSymbol{\DotTriangle}{\mathord}{mtpsymbol}{92} +\fi +\let\mst@mathord\mathalpha +\mst@goaheadtrue +\ifmst@selfGreek + \def\mst@font@tbu{mtselfGreekfont} + \else +\ifmst@eulergreek + \def\mst@font@tbu{mteulervm} + \else +\ifmst@symbolgreek + \def\mst@font@tbu{mtpsymbol} + \let\mst@mathord\mathord + \else +\ifmst@LGRgreek + \mst@goaheadfalse + \else + \mst@goaheadfalse + \ifx\omicron\undefined + \newcommand*{\omicron}{\mst@alph@omicron{o}} + \fi +\fi\fi\fi\fi +\ifmst@goahead +\DeclareMathSymbol{\Alpha}{\mst@mathord}{\mst@font@tbu}{"41} +\DeclareMathSymbol{\Beta}{\mst@mathord}{\mst@font@tbu}{"42} +\DeclareMathSymbol{\Epsilon}{\mst@mathord}{\mst@font@tbu}{"45} +\DeclareMathSymbol{\Zeta}{\mst@mathord}{\mst@font@tbu}{"5A} +\DeclareMathSymbol{\Eta}{\mst@mathord}{\mst@font@tbu}{"48} +\DeclareMathSymbol{\Iota}{\mst@mathord}{\mst@font@tbu}{"49} +\DeclareMathSymbol{\Kappa}{\mst@mathord}{\mst@font@tbu}{"4B} +\DeclareMathSymbol{\Mu}{\mst@mathord}{\mst@font@tbu}{"4D} +\DeclareMathSymbol{\Nu}{\mst@mathord}{\mst@font@tbu}{"4E} +\DeclareMathSymbol{\Omicron}{\mst@mathord}{\mst@font@tbu}{"4F} +\DeclareMathSymbol{\Rho}{\mst@mathord}{\mst@font@tbu}{"50} +\DeclareMathSymbol{\Tau}{\mst@mathord}{\mst@font@tbu}{"54} +\DeclareMathSymbol{\Chi}{\mst@mathord}{\mst@font@tbu}{"58} +\ifx\mst@mathord\mathord +%% attention le P de Symbol est un \Pi pas un \Rho +\DeclareMathSymbol{\Rho}{\mathord}{mtpsymbol}{"52} +%% attention le X de Symbol est un \Xi pas un \Chi +\DeclareMathSymbol{\Chi}{\mathord}{mtpsymbol}{"43} +%% attention le F de Symbol est un \Phi. Il n'y a pas de \Digamma +\DeclareMathSymbol{\Gamma}{\mathord}{mtpsymbol}{"47} +\DeclareMathSymbol{\Delta}{\mathord}{mtpsymbol}{"44} +\DeclareMathSymbol{\Theta}{\mathord}{mtpsymbol}{"51} +\DeclareMathSymbol{\Lambda}{\mathord}{mtpsymbol}{"4C} +\DeclareMathSymbol{\Xi}{\mathord}{mtpsymbol}{"58} +\DeclareMathSymbol{\Pi}{\mathord}{mtpsymbol}{"50} +\DeclareMathSymbol{\Sigma}{\mathord}{mtpsymbol}{"53} +\DeclareMathSymbol{\Upsilon}{\mathord}{mtpsymbol}{"A1} +\DeclareMathSymbol{\Phi}{\mathord}{mtpsymbol}{"46} +\DeclareMathSymbol{\Psi}{\mathord}{mtpsymbol}{"59} +\DeclareMathSymbol{\Omega}{\mathord}{mtpsymbol}{"57} +\else +\DeclareMathSymbol{\Digamma}{\mathalpha}{\mst@font@tbu}{"46} +\DeclareMathSymbol\Gamma {\mathalpha}{\mst@font@tbu}{"00} +\DeclareMathSymbol\Delta {\mathalpha}{\mst@font@tbu}{"01} +\DeclareMathSymbol\Theta {\mathalpha}{\mst@font@tbu}{"02} +\DeclareMathSymbol\Lambda {\mathalpha}{\mst@font@tbu}{"03} +\DeclareMathSymbol\Xi {\mathalpha}{\mst@font@tbu}{"04} +\DeclareMathSymbol\Pi {\mathalpha}{\mst@font@tbu}{"05} +\DeclareMathSymbol\Sigma {\mathalpha}{\mst@font@tbu}{"06} +\DeclareMathSymbol\Upsilon {\mathalpha}{\mst@font@tbu}{"07} +\DeclareMathSymbol\Phi {\mathalpha}{\mst@font@tbu}{"08} +\DeclareMathSymbol\Psi {\mathalpha}{\mst@font@tbu}{"09} +\DeclareMathSymbol\Omega {\mathalpha}{\mst@font@tbu}{"0A} +\fi +\fi +\ifmst@goahead +\ifmst@eulergreek +\DeclareMathSymbol{\alpha} {\mathalpha}{mteulervm}{"0B} +\DeclareMathSymbol{\beta} {\mathalpha}{mteulervm}{"0C} +\DeclareMathSymbol{\gamma} {\mathalpha}{mteulervm}{"0D} +\DeclareMathSymbol{\delta} {\mathalpha}{mteulervm}{"0E} +\DeclareMathSymbol{\epsilon}{\mathalpha}{mteulervm}{"0F} +\DeclareMathSymbol{\zeta} {\mathalpha}{mteulervm}{"10} +\DeclareMathSymbol{\eta} {\mathalpha}{mteulervm}{"11} +\DeclareMathSymbol{\theta} {\mathalpha}{mteulervm}{"12} +\DeclareMathSymbol{\iota} {\mathalpha}{mteulervm}{"13} +\DeclareMathSymbol{\kappa} {\mathalpha}{mteulervm}{"14} +\DeclareMathSymbol{\lambda} {\mathalpha}{mteulervm}{"15} +\DeclareMathSymbol{\mu} {\mathalpha}{mteulervm}{"16} +\DeclareMathSymbol{\nu} {\mathalpha}{mteulervm}{"17} +\DeclareMathSymbol{\xi} {\mathalpha}{mteulervm}{"18} +\let\omicron\undefined +\DeclareMathSymbol{\omicron}{\mathalpha}{mteulervm}{"6F} +\DeclareMathSymbol{\pi} {\mathalpha}{mteulervm}{"19} +\DeclareMathSymbol{\rho} {\mathalpha}{mteulervm}{"1A} +\DeclareMathSymbol{\sigma} {\mathalpha}{mteulervm}{"1B} +\DeclareMathSymbol{\tau} {\mathalpha}{mteulervm}{"1C} +\DeclareMathSymbol{\upsilon}{\mathalpha}{mteulervm}{"1D} +\DeclareMathSymbol{\phi} {\mathalpha}{mteulervm}{"1E} +\DeclareMathSymbol{\chi} {\mathalpha}{mteulervm}{"1F} +\DeclareMathSymbol{\psi} {\mathalpha}{mteulervm}{"20} +\DeclareMathSymbol{\omega} {\mathalpha}{mteulervm}{"21} +\DeclareMathSymbol{\varepsilon}{\mathalpha}{mteulervm}{"22} +\DeclareMathSymbol{\vartheta}{\mathalpha}{mteulervm}{"23} +\DeclareMathSymbol{\varpi} {\mathalpha}{mteulervm}{"24} +\let\varrho=\rho +\let\varsigma=\sigma +\DeclareMathSymbol{\varphi} {\mathalpha}{mteulervm}{"27} +\DeclareMathSymbol{\partial}{\mathalpha}{mteulervm}{"40} +\DeclareMathSymbol{\wp}{\mathalpha}{mteulervm}{"7D} +\DeclareMathSymbol{\ell}{\mathalpha}{mteulervm}{"60} +\else +\ifmst@symbolgreek +\DeclareMathSymbol{\alpha}{\mathord}{mtpsymbol}{"61} +\DeclareMathSymbol{\beta}{\mathord}{mtpsymbol}{"62} +\DeclareMathSymbol{\gamma}{\mathord}{mtpsymbol}{"67} +\DeclareMathSymbol{\delta}{\mathord}{mtpsymbol}{"64} +\DeclareMathSymbol{\epsilon}{\mathord}{mtpsymbol}{"65} +\DeclareMathSymbol{\zeta}{\mathord}{mtpsymbol}{"7A} +\DeclareMathSymbol{\eta}{\mathord}{mtpsymbol}{"68} +\DeclareMathSymbol{\theta}{\mathord}{mtpsymbol}{"71} +\DeclareMathSymbol{\iota}{\mathord}{mtpsymbol}{"69} +\DeclareMathSymbol{\kappa}{\mathord}{mtpsymbol}{"6B} +\DeclareMathSymbol{\lambda}{\mathord}{mtpsymbol}{"6C} +\DeclareMathSymbol{\mu}{\mathord}{mtpsymbol}{"6D} +\DeclareMathSymbol{\nu}{\mathord}{mtpsymbol}{"6E} +\DeclareMathSymbol{\xi}{\mathord}{mtpsymbol}{"78} +\let\omicron\undefined +\DeclareMathSymbol{\omicron}{\mathord}{mtpsymbol}{"6F} +\DeclareMathSymbol{\pi}{\mathord}{mtpsymbol}{"70} +\DeclareMathSymbol{\rho}{\mathord}{mtpsymbol}{"72} +\DeclareMathSymbol{\sigma}{\mathord}{mtpsymbol}{"73} +\DeclareMathSymbol{\tau}{\mathord}{mtpsymbol}{"74} +\DeclareMathSymbol{\upsilon}{\mathord}{mtpsymbol}{"75} +\DeclareMathSymbol{\phi}{\mathord}{mtpsymbol}{"66} +\DeclareMathSymbol{\chi}{\mathord}{mtpsymbol}{"63} +\DeclareMathSymbol{\psi}{\mathord}{mtpsymbol}{"79} +\DeclareMathSymbol{\omega}{\mathord}{mtpsymbol}{"77} +\let\varepsilon=\epsilon +\DeclareMathSymbol{\vartheta}{\mathord}{mtpsymbol}{"4A} +\DeclareMathSymbol{\varpi}{\mathord}{mtpsymbol}{"76} +\let\varrho=\rho +\DeclareMathSymbol{\varsigma}{\mathord}{mtpsymbol}{"56} +\DeclareMathSymbol{\varphi}{\mathord}{mtpsymbol}{"6A} +\DeclareMathSymbol{\partial}{\mathord}{mtpsymbol}{"B6} +\DeclareMathSymbol{\wp}{\mathord}{mtpsymbol}{"C3} +\fi\fi\fi +%% +\ifmst@LGRgreek % internal names for subdued implementation (1.15c-1.15e) +\let\mst@origAlpha\Alpha +\let\mst@origBeta\Beta +\let\mst@origGamma\Gamma +\let\mst@origDelta\Delta +\let\mst@origEpsilon\Epsilon +\let\mst@origZeta\Zeta +\let\mst@origEta\Eta +\let\mst@origTheta\Theta +\let\mst@origIota\Iota +\let\mst@origKappa\Kappa +\let\mst@origLambda\Lambda +\let\mst@origMu\Mu +\let\mst@origNu\Nu +\let\mst@origXi\Xi +\let\mst@origOmicron\Omicron +\let\mst@origPi\Pi +\let\mst@origRho\Rho +\let\mst@origSigma\Sigma +\let\mst@origTau\Tau +\let\mst@origUpsilon\Upsilon +\let\mst@origPhi\Phi +\let\mst@origChi\Chi +\let\mst@origPsi\Psi +\let\mst@origOmega\Omega +\let\mst@origalpha\alpha +\let\mst@origbeta\beta +\let\mst@origgamma\gamma +\let\mst@origdelta\delta +\let\mst@origepsilon\epsilon +\let\mst@origzeta\zeta +\let\mst@origeta\eta +\let\mst@origtheta\theta +\let\mst@origiota\iota +\let\mst@origkappa\kappa +\let\mst@origlambda\lambda +\let\mst@origmu\mu +\let\mst@orignu\nu +\let\mst@origxi\xi +\let\mst@origomicron\omicron +\let\mst@origpi\pi +\let\mst@origrho\rho +\let\mst@origvarsigma\varsigma +\let\mst@origsigma\sigma +\let\mst@origtau\tau +\let\mst@origupsilon\upsilon +\let\mst@origphi\phi +\let\mst@origchi\chi +\let\mst@origpsi\psi +\let\mst@origomega\omega +\let\mst@origDigamma\Digamma +\let\mst@origdigamma\digamma +%% +\def\mst@restoregreek{% +\let\Alpha\mst@origAlpha +\let\Beta\mst@origBeta +\let\Gamma\mst@origGamma +\let\Delta\mst@origDelta +\let\Epsilon\mst@origEpsilon +\let\Zeta\mst@origZeta +\let\Eta\mst@origEta +\let\Theta\mst@origTheta +\let\Iota\mst@origIota +\let\Kappa\mst@origKappa +\let\Lambda\mst@origLambda +\let\Mu\mst@origMu +\let\Nu\mst@origNu +\let\Xi\mst@origXi +\let\Omicron\mst@origOmicron +\let\Pi\mst@origPi +\let\Rho\mst@origRho +\let\Sigma\mst@origSigma +\let\Tau\mst@origTau +\let\Upsilon\mst@origUpsilon +\let\Phi\mst@origPhi +\let\Chi\mst@origChi +\let\Psi\mst@origPsi +\let\Omega\mst@origOmega +\let\alpha\mst@origalpha +\let\beta\mst@origbeta +\let\gamma\mst@origgamma +\let\delta\mst@origdelta +\let\epsilon\mst@origepsilon +\let\zeta\mst@origzeta +\let\eta\mst@origeta +\let\theta\mst@origtheta +\let\iota\mst@origiota +\let\kappa\mst@origkappa +\let\lambda\mst@origlambda +\let\mu\mst@origmu +\let\nu\mst@orignu +\let\xi\mst@origxi +\let\omicron\mst@origomicron +\let\pi\mst@origpi +\let\rho\mst@origrho +\let\varsigma\mst@origvarsigma +\let\sigma\mst@origsigma +\let\tau\mst@origtau +\let\upsilon\mst@origupsilon +\let\phi\mst@origphi +\let\chi\mst@origchi +\let\psi\mst@origpsi +\let\omega\mst@origomega +\let\Digamma\mst@origDigamma +\let\digamma\mst@origdigamma +} +%% +\def\mst@setuplgrgreek{% +\let\Alpha\mst@Alpha +\let\Beta\mst@Beta +\let\Gamma\mst@Gamma +\let\Delta\mst@Delta +\let\Epsilon\mst@Epsilon +\let\Zeta\mst@Zeta +\let\Eta\mst@Eta +\let\Theta\mst@Theta +\let\Iota\mst@Iota +\let\Kappa\mst@Kappa +\let\Lambda\mst@Lambda +\let\Mu\mst@Mu +\let\Nu\mst@Nu +\let\Xi\mst@Xi +\let\Omicron\mst@Omicron +\let\Pi\mst@Pi +\let\Rho\mst@Rho +\let\Sigma\mst@Sigma +\let\Tau\mst@Tau +\let\Upsilon\mst@Upsilon +\let\Phi\mst@Phi +\let\Chi\mst@Chi +\let\Psi\mst@Psi +\let\Omega\mst@Omega +\let\alpha\mst@alpha +\let\beta\mst@beta +\let\gamma\mst@gamma +\let\delta\mst@delta +\let\epsilon\mst@epsilon +\let\zeta\mst@zeta +\let\eta\mst@eta +\let\theta\mst@theta +\let\iota\mst@iota +\let\kappa\mst@kappa +\let\lambda\mst@lambda +\let\mu\mst@mu +\let\nu\mst@nu +\let\xi\mst@xi +\let\omicron\mst@omicron +\let\pi\mst@pi +\let\rho\mst@rho +\let\varsigma\mst@varsigma +\let\sigma\mst@sigma +\let\tau\mst@tau +\let\upsilon\mst@upsilon +\let\phi\mst@phi +\let\chi\mst@chi +\let\psi\mst@psi +\let\omega\mst@omega +\let\Digamma\mst@Digamma +\let\digamma\mst@digamma +} +%% +\DeclareMathSymbol{\mst@Alpha}{\mathalpha}{mtlgrfontupper}{65} +\DeclareMathSymbol{\mst@Beta}{\mathalpha}{mtlgrfontupper}{66} +\DeclareMathSymbol{\mst@Gamma}{\mathalpha}{mtlgrfontupper}{71} +\DeclareMathSymbol{\mst@Delta}{\mathalpha}{mtlgrfontupper}{68} +\DeclareMathSymbol{\mst@Epsilon}{\mathalpha}{mtlgrfontupper}{69} +\DeclareMathSymbol{\mst@Zeta}{\mathalpha}{mtlgrfontupper}{90} +\DeclareMathSymbol{\mst@Eta}{\mathalpha}{mtlgrfontupper}{72} +\DeclareMathSymbol{\mst@Theta}{\mathalpha}{mtlgrfontupper}{74} +\DeclareMathSymbol{\mst@Iota}{\mathalpha}{mtlgrfontupper}{73} +\DeclareMathSymbol{\mst@Kappa}{\mathalpha}{mtlgrfontupper}{75} +\DeclareMathSymbol{\mst@Lambda}{\mathalpha}{mtlgrfontupper}{76} +\DeclareMathSymbol{\mst@Mu}{\mathalpha}{mtlgrfontupper}{77} +\DeclareMathSymbol{\mst@Nu}{\mathalpha}{mtlgrfontupper}{78} +\DeclareMathSymbol{\mst@Xi}{\mathalpha}{mtlgrfontupper}{88} +\DeclareMathSymbol{\mst@Omicron}{\mathalpha}{mtlgrfontupper}{79} +\DeclareMathSymbol{\mst@Pi}{\mathalpha}{mtlgrfontupper}{80} +\DeclareMathSymbol{\mst@Rho}{\mathalpha}{mtlgrfontupper}{82} +\DeclareMathSymbol{\mst@Sigma}{\mathalpha}{mtlgrfontupper}{83} +\DeclareMathSymbol{\mst@Tau}{\mathalpha}{mtlgrfontupper}{84} +\DeclareMathSymbol{\mst@Upsilon}{\mathalpha}{mtlgrfontupper}{85} +\DeclareMathSymbol{\mst@Phi}{\mathalpha}{mtlgrfontupper}{70} +\DeclareMathSymbol{\mst@Chi}{\mathalpha}{mtlgrfontupper}{81} +\DeclareMathSymbol{\mst@Psi}{\mathalpha}{mtlgrfontupper}{89} +\DeclareMathSymbol{\mst@Omega}{\mathalpha}{mtlgrfontupper}{87} +\DeclareMathSymbol{\mst@alpha}{\mathalpha}{mtlgrfontlower}{97} +\DeclareMathSymbol{\mst@beta}{\mathalpha}{mtlgrfontlower}{98} +\DeclareMathSymbol{\mst@gamma}{\mathalpha}{mtlgrfontlower}{103} +\DeclareMathSymbol{\mst@delta}{\mathalpha}{mtlgrfontlower}{100} +\DeclareMathSymbol{\mst@epsilon}{\mathalpha}{mtlgrfontlower}{101} +\DeclareMathSymbol{\mst@zeta}{\mathalpha}{mtlgrfontlower}{122} +\DeclareMathSymbol{\mst@eta}{\mathalpha}{mtlgrfontlower}{104} +\DeclareMathSymbol{\mst@theta}{\mathalpha}{mtlgrfontlower}{106} +\DeclareMathSymbol{\mst@iota}{\mathalpha}{mtlgrfontlower}{105} +\DeclareMathSymbol{\mst@kappa}{\mathalpha}{mtlgrfontlower}{107} +\DeclareMathSymbol{\mst@lambda}{\mathalpha}{mtlgrfontlower}{108} +\DeclareMathSymbol{\mst@mu}{\mathalpha}{mtlgrfontlower}{109} +\DeclareMathSymbol{\mst@nu}{\mathalpha}{mtlgrfontlower}{110} +\DeclareMathSymbol{\mst@xi}{\mathalpha}{mtlgrfontlower}{120} +\DeclareMathSymbol{\mst@omicron}{\mathalpha}{mtlgrfontlower}{111} +\DeclareMathSymbol{\mst@pi}{\mathalpha}{mtlgrfontlower}{112} +\DeclareMathSymbol{\mst@rho}{\mathalpha}{mtlgrfontlower}{114} +\DeclareMathSymbol{\mst@varsigma}{\mathalpha}{mtlgrfontlower}{99} +\DeclareMathSymbol{\mst@sigma}{\mathalpha}{mtlgrfontlower}{115} +\DeclareMathSymbol{\mst@tau}{\mathalpha}{mtlgrfontlower}{116} +\DeclareMathSymbol{\mst@upsilon}{\mathalpha}{mtlgrfontlower}{117} +\DeclareMathSymbol{\mst@phi}{\mathalpha}{mtlgrfontlower}{102} +\DeclareMathSymbol{\mst@chi}{\mathalpha}{mtlgrfontlower}{113} +\DeclareMathSymbol{\mst@psi}{\mathalpha}{mtlgrfontlower}{121} +\DeclareMathSymbol{\mst@omega}{\mathalpha}{mtlgrfontlower}{119} +\DeclareMathSymbol{\mst@digamma}{\mathalpha}{mtlgrfontlower}{147} +\DeclareMathSymbol{\mst@Digamma}{\mathalpha}{mtlgrfontlower}{195} +\ifmst@subdued\else\mst@setuplgrgreek\fi +\fi +\edef\mst@tmp@enc{\encodingdefault} +\mst@goaheadtrue +\ifx\mst@tmp@enc\mst@eui % xetex and unicode font + \XeTeXmathchardef\inodot="7 \symmtletterfont "0131 \relax + \XeTeXmathchardef\jnodot="7 \symmtletterfont "0237 \relax +\else +\ifx\mst@tmp@enc\mst@euii % luatex and unicode font + \luatexUmathchardef\inodot="7 \symmtletterfont "0131 \relax + \luatexUmathchardef\jnodot="7 \symmtletterfont "0237 \relax +\else +\ifx\mst@tmp@enc\mst@ti % T1 + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont}{25} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont}{26} +\else +\ifx\mst@tmp@enc\mst@oti % OT1 + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont}{16} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont}{17} +\else +\ifx\mst@tmp@enc\mst@lyi % LY1 + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont}{16} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont}{17} +\else + \ifmst@XeTeX\mst@goaheadfalse\else\ifmst@LuaTeX\mst@goaheadfalse\else + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\i\endcsname} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\j\endcsname} + \fi\fi +\fi\fi\fi\fi\fi +\ifmst@defaultimath\else\typeout{** \string\i\space and \string\j\space} + \ifmst@goahead + \renewcommand*{\imath}{\inodot} + \renewcommand*{\jmath}{\jnodot} + \let\mst@oldi\i \let\mst@oldj\j + \DeclareRobustCommand*{\i}{\ifmmode\inodot\else\mst@oldi\fi} + \DeclareRobustCommand*{\j}{\ifmmode\jnodot\else\mst@oldj\fi} + \fi +\fi +\edef\mst@tmp@enc{\encodingdefault} %% rather one too many than sorry +\ifmst@mathaccents\typeout{** math accents} +\ifx\mst@ti\mst@tmp@enc +\DeclareMathAccent{\acute}{\mathalpha}{mtoperatorfont}{1} +\DeclareMathAccent{\grave}{\mathalpha}{mtoperatorfont}{0} +\DeclareMathAccent{\ddot}{\mathalpha}{mtoperatorfont}{4} +\DeclareMathAccent{\tilde}{\mathalpha}{mtoperatorfont}{3} +\DeclareMathAccent{\bar}{\mathalpha}{mtoperatorfont}{9} +\DeclareMathAccent{\breve}{\mathalpha}{mtoperatorfont}{8} +\DeclareMathAccent{\check}{\mathalpha}{mtoperatorfont}{7} +\DeclareMathAccent{\hat}{\mathalpha}{mtoperatorfont}{2} +\DeclareMathAccent{\dot}{\mathalpha}{mtoperatorfont}{10} +\DeclareMathAccent{\mathring}{\mathalpha}{mtoperatorfont}{6} +\else +\DeclareMathAccent{\acute}{\mathalpha}{mtoperatorfont}{19} +\DeclareMathAccent{\grave}{\mathalpha}{mtoperatorfont}{18} +\DeclareMathAccent{\ddot}{\mathalpha}{mtoperatorfont}{127} +\DeclareMathAccent{\tilde}{\mathalpha}{mtoperatorfont}{126} +\DeclareMathAccent{\bar}{\mathalpha}{mtoperatorfont}{22} +\DeclareMathAccent{\breve}{\mathalpha}{mtoperatorfont}{21} +\DeclareMathAccent{\check}{\mathalpha}{mtoperatorfont}{20} +\DeclareMathAccent{\hat}{\mathalpha}{mtoperatorfont}{94} +\DeclareMathAccent{\dot}{\mathalpha}{mtoperatorfont}{95} +\DeclareMathAccent{\mathring}{\mathalpha}{mtoperatorfont}{23} + \ifx\mst@lyi\mst@tmp@enc % LY1 encoding + \DeclareMathAccent{\dot}{\mathalpha}{mtoperatorfont}{5} + \else + \ifx\mst@oti\mst@tmp@enc\else + \typeout{** mathastext: math accents have been assumed to be^^J% + ** as in OT1 encoding.} + \fi + \fi +\fi\fi +\ifmst@defaultsizes\else +\providecommand\@xxxpt{29.86} +\providecommand\@xxxvipt{35.83} +\ifmst@twelve + \def\Huge{\@setfontsize\Huge\@xxxpt{36}} + \def\HUGE{\@setfontsize\HUGE\@xxxvipt{43}} +\typeout{** \protect\Huge\space and \protect\HUGE\space have been (re)-defined.} +\else + \def\HUGE{\@setfontsize\HUGE\@xxxpt{36}} +\typeout{** \protect\HUGE\space has been (re)-defined.} +\fi +\def\defaultscriptratio{.8333} +\def\defaultscriptscriptratio{.7} +\DeclareMathSizes{9}{9}{7}{5} +\DeclareMathSizes{\@xpt}{\@xpt}{8}{6} +\DeclareMathSizes{\@xipt}{\@xipt}{9}{7} +\DeclareMathSizes{\@xiipt}{\@xiipt}{10}{8} +\DeclareMathSizes{\@xivpt}{\@xivpt}{\@xiipt}{10} +\DeclareMathSizes{\@xviipt}{\@xviipt}{\@xivpt}{\@xiipt} +\DeclareMathSizes{\@xxpt}{\@xxpt}{\@xviipt}{\@xivpt} +\DeclareMathSizes{\@xxvpt}{\@xxvpt}{\@xxpt}{\@xviipt} +\DeclareMathSizes{\@xxxpt}{\@xxxpt}{\@xxvpt}{\@xxpt} +\DeclareMathSizes{\@xxxvipt}{\@xxxvipt}{\@xxxpt}{\@xxvpt} +\typeout{** mathastext has declared larger sizes for subscripts.^^J% +** To keep LaTeX defaults, use option `defaultmathsizes\string'.} +\fi +\endinput +%% +%% End of file `mathastext.sty'. diff --git a/latex/figs/meldable-merge.ipe b/latex/figs/meldable-merge.ipe index a55e40c3..9bcc300b 100644 --- a/latex/figs/meldable-merge.ipe +++ b/latex/figs/meldable-merge.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/mergesort-recursion.ipe b/latex/figs/mergesort-recursion.ipe index 231cb542..6de5e651 100644 --- a/latex/figs/mergesort-recursion.ipe +++ b/latex/figs/mergesort-recursion.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/mergesort.ipe b/latex/figs/mergesort.ipe index 576d4ea9..a0b4dd18 100644 --- a/latex/figs/mergesort.ipe +++ b/latex/figs/mergesort.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/prioqueue.ipe b/latex/figs/prioqueue.ipe index a8de4081..3563bb3d 100644 --- a/latex/figs/prioqueue.ipe +++ b/latex/figs/prioqueue.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/queue.ipe b/latex/figs/queue.ipe index 4600e628..be9df7a6 100644 --- a/latex/figs/queue.ipe +++ b/latex/figs/queue.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/quicksort.ipe b/latex/figs/quicksort.ipe index 6a088fac..ffa954ff 100644 --- a/latex/figs/quicksort.ipe +++ b/latex/figs/quicksort.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/radixsort.ipe b/latex/figs/radixsort.ipe index f3b5e120..abac99e9 100644 --- a/latex/figs/radixsort.ipe +++ b/latex/figs/radixsort.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rb-addfix.ipe b/latex/figs/rb-addfix.ipe index 64d629c2..568c9b01 100644 --- a/latex/figs/rb-addfix.ipe +++ b/latex/figs/rb-addfix.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rb-removefix.ipe b/latex/figs/rb-removefix.ipe index f6fe0e3e..3b8782c7 100644 --- a/latex/figs/rb-removefix.ipe +++ b/latex/figs/rb-removefix.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rb-split.ipe b/latex/figs/rb-split.ipe index 07b7f33e..3bd0d043 100644 --- a/latex/figs/rb-split.ipe +++ b/latex/figs/rb-split.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rbst-probs-a.ipe b/latex/figs/rbst-probs-a.ipe index cda2a962..562fd668 100644 --- a/latex/figs/rbst-probs-a.ipe +++ b/latex/figs/rbst-probs-a.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rbst-probs-b.ipe b/latex/figs/rbst-probs-b.ipe index 6a3c67bb..4ad55d4b 100644 --- a/latex/figs/rbst-probs-b.ipe +++ b/latex/figs/rbst-probs-b.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rbst-records.ipe b/latex/figs/rbst-records.ipe index 2804b12a..9dbbf101 100644 --- a/latex/figs/rbst-records.ipe +++ b/latex/figs/rbst-records.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/redblack-example.ipe b/latex/figs/redblack-example.ipe index db3dc73a..92f0723d 100644 --- a/latex/figs/redblack-example.ipe +++ b/latex/figs/redblack-example.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rootisharraystack.ipe b/latex/figs/rootisharraystack.ipe index d19e2dfb..1266dcf0 100644 --- a/latex/figs/rootisharraystack.ipe +++ b/latex/figs/rootisharraystack.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/rotation.ipe b/latex/figs/rotation.ipe index 236075a9..ac1017fe 100644 --- a/latex/figs/rotation.ipe +++ b/latex/figs/rotation.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/scapegoat-insert.ipe b/latex/figs/scapegoat-insert.ipe index a67a6773..0e0250bb 100644 --- a/latex/figs/scapegoat-insert.ipe +++ b/latex/figs/scapegoat-insert.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/selist-add-a.ipe b/latex/figs/selist-add-a.ipe index 94fce908..2777b062 100644 --- a/latex/figs/selist-add-a.ipe +++ b/latex/figs/selist-add-a.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/selist-add-b.ipe b/latex/figs/selist-add-b.ipe index c3cc6889..aa65db41 100644 --- a/latex/figs/selist-add-b.ipe +++ b/latex/figs/selist-add-b.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/selist-add-c.ipe b/latex/figs/selist-add-c.ipe index 3b8cbedf..9cb35c89 100644 --- a/latex/figs/selist-add-c.ipe +++ b/latex/figs/selist-add-c.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/selist-remove-a.ipe b/latex/figs/selist-remove-a.ipe index d98bf06d..9e6bc68f 100644 --- a/latex/figs/selist-remove-a.ipe +++ b/latex/figs/selist-remove-a.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/selist-remove-b.ipe b/latex/figs/selist-remove-b.ipe index 0f367116..a3c3867d 100644 --- a/latex/figs/selist-remove-b.ipe +++ b/latex/figs/selist-remove-b.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/selist-remove-c.ipe b/latex/figs/selist-remove-c.ipe index d6ee524e..b00ff97f 100644 --- a/latex/figs/selist-remove-c.ipe +++ b/latex/figs/selist-remove-c.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/sim.ipe b/latex/figs/sim.ipe index 47e297cb..9f2b5ea9 100644 --- a/latex/figs/sim.ipe +++ b/latex/figs/sim.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-add.ipe b/latex/figs/skiplist-add.ipe index c117eca1..ebc2821c 100644 --- a/latex/figs/skiplist-add.ipe +++ b/latex/figs/skiplist-add.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-addix.ipe b/latex/figs/skiplist-addix.ipe index 34ba8af6..e23ad557 100644 --- a/latex/figs/skiplist-addix.ipe +++ b/latex/figs/skiplist-addix.ipe @@ -2,7 +2,7 @@ -\usepackage{ulem}\usepackage{kpfonts} +\usepackage{ulem}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-lengths-splice.ipe b/latex/figs/skiplist-lengths-splice.ipe index 8d86ee54..6e5534ad 100644 --- a/latex/figs/skiplist-lengths-splice.ipe +++ b/latex/figs/skiplist-lengths-splice.ipe @@ -2,7 +2,7 @@ -\usepackage{ulem}\usepackage{kpfonts} +\usepackage{ulem}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-lengths.ipe b/latex/figs/skiplist-lengths.ipe index fcee5c3e..c040c6ff 100644 --- a/latex/figs/skiplist-lengths.ipe +++ b/latex/figs/skiplist-lengths.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-remove.ipe b/latex/figs/skiplist-remove.ipe index 80f9d593..91af2f8d 100644 --- a/latex/figs/skiplist-remove.ipe +++ b/latex/figs/skiplist-remove.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-removei.ipe b/latex/figs/skiplist-removei.ipe index 27dff2f8..d62ec0ad 100644 --- a/latex/figs/skiplist-removei.ipe +++ b/latex/figs/skiplist-removei.ipe @@ -2,7 +2,7 @@ -\usepackage{ulem}\usepackage{kpfonts} +\usepackage{ulem}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-searchpath.ipe b/latex/figs/skiplist-searchpath.ipe index 9a2a4fcf..33d84e94 100644 --- a/latex/figs/skiplist-searchpath.ipe +++ b/latex/figs/skiplist-searchpath.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist-splice.ipe b/latex/figs/skiplist-splice.ipe index 872a0c97..04c3bcad 100644 --- a/latex/figs/skiplist-splice.ipe +++ b/latex/figs/skiplist-splice.ipe @@ -2,7 +2,7 @@ -\usepackage{ulem}\usepackage{kpfonts} +\usepackage{ulem}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/skiplist.ipe b/latex/figs/skiplist.ipe index 990048df..6d71b5dc 100644 --- a/latex/figs/skiplist.ipe +++ b/latex/figs/skiplist.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/sllist.ipe b/latex/figs/sllist.ipe index 689f824f..9e371645 100644 --- a/latex/figs/sllist.ipe +++ b/latex/figs/sllist.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/split.ipe b/latex/figs/split.ipe index a0669409..296695b5 100644 --- a/latex/figs/split.ipe +++ b/latex/figs/split.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/stack.ipe b/latex/figs/stack.ipe index bb93d381..4efac1ec 100644 --- a/latex/figs/stack.ipe +++ b/latex/figs/stack.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-delete-a.ipe b/latex/figs/treap-delete-a.ipe index 2e817459..f2d5176a 100644 --- a/latex/figs/treap-delete-a.ipe +++ b/latex/figs/treap-delete-a.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-delete-b.ipe b/latex/figs/treap-delete-b.ipe index 7025912f..8026dcfe 100644 --- a/latex/figs/treap-delete-b.ipe +++ b/latex/figs/treap-delete-b.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-delete-c.ipe b/latex/figs/treap-delete-c.ipe index c55fd10d..e65ef39a 100644 --- a/latex/figs/treap-delete-c.ipe +++ b/latex/figs/treap-delete-c.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-delete-d.ipe b/latex/figs/treap-delete-d.ipe index 9e43a9ae..d9a42270 100644 --- a/latex/figs/treap-delete-d.ipe +++ b/latex/figs/treap-delete-d.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-insert-a.ipe b/latex/figs/treap-insert-a.ipe index 458d2699..7a69b175 100644 --- a/latex/figs/treap-insert-a.ipe +++ b/latex/figs/treap-insert-a.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-insert-b.ipe b/latex/figs/treap-insert-b.ipe index cbde19e5..c9a5afa9 100644 --- a/latex/figs/treap-insert-b.ipe +++ b/latex/figs/treap-insert-b.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-insert-c.ipe b/latex/figs/treap-insert-c.ipe index fa3a1473..cbd44341 100644 --- a/latex/figs/treap-insert-c.ipe +++ b/latex/figs/treap-insert-c.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap-insert.ipe b/latex/figs/treap-insert.ipe index 3d3896fb..cb87f71b 100644 --- a/latex/figs/treap-insert.ipe +++ b/latex/figs/treap-insert.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/treap.ipe b/latex/figs/treap.ipe index 8813acdc..7c4cb602 100644 --- a/latex/figs/treap.ipe +++ b/latex/figs/treap.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/xfast-path.ipe b/latex/figs/xfast-path.ipe index 0761cd47..b1b7e379 100644 --- a/latex/figs/xfast-path.ipe +++ b/latex/figs/xfast-path.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/yfast-add.ipe b/latex/figs/yfast-add.ipe index cac7e240..3794016c 100644 --- a/latex/figs/yfast-add.ipe +++ b/latex/figs/yfast-add.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/yfast-remove.ipe b/latex/figs/yfast-remove.ipe index 75f1c5d5..15bdeb8d 100644 --- a/latex/figs/yfast-remove.ipe +++ b/latex/figs/yfast-remove.ipe @@ -2,7 +2,7 @@ -\usepackage{ulem}\usepackage{kpfonts} +\usepackage{ulem}\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/yfast-sample.ipe b/latex/figs/yfast-sample.ipe index 47478b45..f809275c 100644 --- a/latex/figs/yfast-sample.ipe +++ b/latex/figs/yfast-sample.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/figs/yfast.ipe b/latex/figs/yfast.ipe index 7350bf43..28f08e8c 100644 --- a/latex/figs/yfast.ipe +++ b/latex/figs/yfast.ipe @@ -2,7 +2,7 @@ -\usepackage{kpfonts} +\usepackage[math]{iwona}\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n}\usepackage[T1]{fontenc} diff --git a/latex/hashing.tex b/latex/hashing.tex index eb127e33..0f37abb2 100644 --- a/latex/hashing.tex +++ b/latex/hashing.tex @@ -8,9 +8,9 @@ \chapter{Hash Tables} This chapter focuses on one of the most common implementations of hash tables, namely hashing with chaining. -Very often hash tables store data that are not integers. In this case, -an integer \emph{hash code} is associated with each data item and this -hash code is used in the hash table. The second part of this chapter +Very often hash tables store types of data that are not integers. +In this case, an integer \emph{hash code} is associated with each data +item and is used in the hash table. The second part of this chapter discusses how such hash codes are generated. Some of the methods used in this chapter require random choices of @@ -43,14 +43,14 @@ \section{#ChainedHashTable#: Hashing with Chaining} so that the average number of elements stored in one of these lists is $#n#/#t.length# \le 1$. -To add an element, #x#, to the hash table, we first check if the length -of #t# needs to be increased and, if so, we grow #t#. With -this out of the way we hash #x# to get an integer, #i#, in the range -$\{0,\ldots,#t.length#-1\}$ and we append #x# to the list #t[i]#: -\codeimport{ods/ChainedHashTable.add(x)} -Growing the table, if necessary, involves doubling the length of #t# -and reinserting all elements into the new table. This is exactly the -same strategy used in the implementation of #ArrayStack# and the same +To add an element, #x#, to the hash table, we first check if +the length of #t# needs to be increased and, if so, we grow #t#. +With this out of the way we hash #x# to get an integer, #i#, in the +range $\{0,\ldots,#t.length#-1\}$, and we append #x# to the list +#t[i]#: \codeimport{ods/ChainedHashTable.add(x)} Growing the table, +if necessary, involves doubling the length of #t# and reinserting +all elements into the new table. This strategy is exactly the same +as the one used in the implementation of #ArrayStack# and the same result applies: The cost of growing is only constant when amortized over a sequence of insertions (see~\lemref{arraystack-amortized} on page~\pageref{lem:arraystack-amortized}). @@ -60,7 +60,7 @@ \section{#ChainedHashTable#: Hashing with Chaining} the list implementations described in Chapters~\ref{chap:arrays} or \ref{chap:linkedlists}, this takes only constant time. -To remove an element #x# from the hash table we iterate over the list +To remove an element, #x#, from the hash table, we iterate over the list #t[hash(x)]# until we find #x# so that we can remove it: \codeimport{ods/ChainedHashTable.remove(x)} This takes $O(#n#_{#hash(x)#})$ time, where $#n#_{#i#}$ denotes the length @@ -172,7 +172,7 @@ \subsection{Multiplicative Hashing} We use $\star$ to denote a bit of unknown value. \begin{lem}\lemlabel{hashing-mapping} - Let $S$ be the set of odd integers in $\{1,\ldots,2^{#w#}-1\}$, Let $q$ + Let $S$ be the set of odd integers in $\{1,\ldots,2^{#w#}-1\}$; let $q$ and $i$ be any two elements in $S$. Then there is exactly one value $#z#\in S$ such that $#z#q\bmod 2^{#w#} = i$. \end{lem} @@ -202,7 +202,7 @@ \subsection{Multiplicative Hashing} so that the #w# trailing bits in the binary representation of $(#z#-#z#')q$ are all 0's. - Furthermore $k\neq 0$ since $q\neq 0$ and $#z#-#z#'\neq 0$. Since $q$ + Furthermore $k\neq 0$, since $q\neq 0$ and $#z#-#z#'\neq 0$. Since $q$ is odd, it has no trailing 0's in its binary representation: \[ q = (\star,\ldots,\star,1)_2 \enspace . @@ -272,7 +272,7 @@ \subsection{Multiplicative Hashing} like \myeqref{all-zeros} or \myeqref{all-ones} is 0. If $#r#=#w#-#d#$, then the probability of looking like \myeqref{all-zeros} is 0, but the probability of looking like \myeqref{all-ones} is $1/2^{#d#-1}=2/2^{#d#}$ - (since we must have $b_1,\ldots,b_{d-1}=1,\ldots,1$). If $r < #w#-#d#$ + (since we must have $b_1,\ldots,b_{d-1}=1,\ldots,1$). If $r < #w#-#d#$, then we must have $b_{#w#-r-1},\ldots,b_{#w#-r-#d#}=0,\ldots,0$ or $b_{#w#-r-1},\ldots,b_{#w#-r-#d#}=1,\ldots,1$. The probability of each of these cases is $1/2^{#d#}$ and they are mutually exclusive, so the @@ -302,16 +302,16 @@ \section{#LinearHashTable#: Linear Probing} list stores all elements #x# such that $#hash(x)#=#i#$. An alternative, called \emph{open addressing} is to store the elements directly in an array, #t#, with each array location in #t# storing at most one value. -This is the approach taken by the #LinearHashTable# described in this +This approach is taken by the #LinearHashTable# described in this section. In some places, this data structure is described as \emph{open addressing with linear probing}. The main idea behind a #LinearHashTable# is that we would, ideally, like to store the element #x# with hash value #i=hash(x)# in the table location -#t[i]#. If we can't do this (because some element is already stored +#t[i]#. If we cannot do this (because some element is already stored there) then we try to store it at location $#t#[(#i#+1)\bmod#t.length#]$; -if that's not possible, then we try $#t#[(#i#+2)\bmod#t.length#]$, and -so on, until we find a place for #x#. +if that's not possible, then we try $#t#[(#i#+2)\bmod#t.length#]$, +and so on, until we find a place for #x#. There are three types of entries stored in #t#: \begin{enumerate} @@ -333,7 +333,7 @@ \section{#LinearHashTable#: Linear Probing} data elements, and integers #n# and #q# that keep track of the number of data elements and non-#null# values of #t#, respectively. Because many hash functions only work for table sizes that are a power of 2, we also -keep an integer #d# and maintain the invariant that #t.length=2^d#. +keep an integer #d# and maintain the invariant that $#t.length#=2^#d#$. \codeimport{ods/LinearHashTable.t.n.q.d} The #find(x)# operation in a #LinearHashTable# is simple. We start @@ -371,9 +371,9 @@ \section{#LinearHashTable#: Linear Probing} less than #t.length/8#. The #resize()# method works like the #resize()# methods in other array-based data structures. We find the smallest non-negative integer #d# such that $2^{#d#} \ge 3#n#$. We reallocate -the array #t# so that it has size $2^{#d#}$ and then we insert all the +the array #t# so that it has size $2^{#d#}$, and then we insert all the elements in the old version of #t# into the newly-resized copy of #t#. -While doing this we reset #q# equal to #n# since the newly-allocated #t# +While doing this, we reset #q# equal to #n# since the newly-allocated #t# has no #del# values. \codeimport{ods/LinearHashTable.resize()} @@ -384,7 +384,7 @@ \subsection{Analysis of Linear Probing} The intuition behind the analysis of linear probing is that, since at least half the elements in #t# are equal to #null#, an operation should not take long to complete because it will very quickly come across a -#null# entry. We shouldn't rely too heavily on this intuition though, +#null# entry. We shouldn't rely too heavily on this intuition, though, because it would lead us to (the incorrect) conclusion that the expected number of locations in #t# examined by an operation is at most 2. @@ -453,11 +453,11 @@ \subsection{Analysis of Linear Probing} Using \lemref{linear-probing} to prove upper-bounds on the expected running time of #find(x)#, #add(x)#, and #remove(x)# is now fairly -straight-forward. Consider the simplest case, where we execute +straightforward. Consider the simplest case, where we execute #find(x)# for some value #x# that has never been stored in the #LinearHashTable#. In this case, $#i#=#hash(x)#$ is a random value in $\{0,\ldots,#t.length#-1\}$ independent of the contents of #t#. If #i# -is part of a run of length $k$ then the time it takes to execute the +is part of a run of length $k$, then the time it takes to execute the #find(x)# operation is at most $O(1+k)$. Thus, the expected running time can be upper-bounded by \[ @@ -479,7 +479,7 @@ \subsection{Analysis of Linear Probing} Therefore, we conclude that the expected running time of the #find(x)# operation for a value #x# that is not contained in a #LinearHashTable# is $O(1)$. -If we ignore the cost of the #resize()# operation, the above +If we ignore the cost of the #resize()# operation, then the above analysis gives us all we need to analyze the cost of operations on a #LinearHashTable#. @@ -516,12 +516,12 @@ \subsection{Tabulation Hashing} While analyzing the #LinearHashTable# structure, we made a very strong assumption: That for any set of elements, $\{#x_1#,\ldots,#x_n#\}$, -the hash values $#hash(x_1)#,\ldots,#hash(x_n)#$ are independently -and uniformly distributed over $\{0,\ldots,#t.length#-1\}$. One way -to imagine getting this is to have a giant array, #tab#, of length -$2^{#w#}$, where each entry is a random #w#-bit integer, independent -of all the other entries. In this way, we could implement #hash(x)# -by extracting a #d#-bit integer from #tab[x.hashCode()]#: +the hash values $#hash(x_1)#,\ldots,#hash(x_n)#$ are independently and +uniformly distributed over the set $\{0,\ldots,#t.length#-1\}$. One way to +achieve this is to store a giant array, #tab#, of length $2^{#w#}$, +where each entry is a random #w#-bit integer, independent of all the +other entries. In this way, we could implement #hash(x)# by extracting +a #d#-bit integer from #tab[x.hashCode()]#: \codeimport{ods/LinearHashTable.idealHash(x)} Unfortunately, storing an array of size $2^{#w#}$ is prohibitive in terms @@ -535,7 +535,7 @@ \subsection{Tabulation Hashing} values with the bitwise exclusive-or operator to obtain #hash(x)#. The following code shows how this works when $#w#=32$ and $#r#=4$: \codeimport{ods/LinearHashTable.hash(x)} -In this case, #tab# is a 2-dimensional array with 4 columns and +In this case, #tab# is a two-dimensional array with four columns and $2^{32/4}=256$ rows. One can easily verify that, for any #x#, #hash(x)# is uniformly @@ -685,7 +685,7 @@ \subsection{Hash Codes for Arrays and Strings} The method from the previous section works well for objects that have a fixed, constant, number of components. However, it breaks down when we -want to use it with objects that have a variable number of components +want to use it with objects that have a variable number of components, since it requires a random #w#-bit integer $#z#_i$ for each component. We could use a pseudorandom sequence to generate as many $#z#_i$'s as we need, but then the $#z#_i$'s are not mutually independent, and it becomes @@ -789,20 +789,18 @@ \subsection{Hash Codes for Arrays and Strings} from \secref{multihash}, with $#d#=31$ to reduce #x[i].hashCode()# to a 31-bit value. This is so that the additions and multiplications that are done modulo the prime $#p#=2^{32}-5$ can be carried out using unsigned -63-bit arithmetic. This means that the probability of two different -sequences, the longer of which has length $r$, having the same hash code -is at most +63-bit arithmetic. Thus the probability of two different sequences, +the longer of which has length $r$, having the same hash code is at most \[ 2/2^{31} + r/(2^{32}-5) \] -rather -than the $r/(2^{32}-5)$ specified in \thmref{stringhash}. +rather than the $r/(2^{32}-5)$ specified in \thmref{stringhash}. \section{Discussion and Exercises} -Hash tables and hash codes are an enormous and active area of research -that is just touched upon in this chapter. The online Bibliography on -Hashing \cite{hashing} contains nearly 2000 entries. +Hash tables and hash codes represent an enormous and active field +of research that is just touched upon in this chapter. The online +Bibliography on Hashing \cite{hashing} contains nearly 2000 entries. A variety of different hash table implementations exist. The one described in \secref{hashtable} is known as \emph{hashing with chaining} @@ -818,7 +816,7 @@ \section{Discussion and Exercises} a group at IBM in the 1950s. Open addressing schemes must deal with the problem of \emph{collision resolution}: the case where two values hash to the same array location. Different strategies exist for collision -resolution and these provide different performance guarantees and often +resolution; these provide different performance guarantees and often require more sophisticated hash functions than the ones described here. Yet another category of hash table implementations are the so-called @@ -831,7 +829,7 @@ \section{Discussion and Exercises} and \emph{cuckoo hashing} \cite{pr04}. The hash functions presented in this chapter are probably among the most -practical currently known methods that can be proven to work well for any +practical methods currently known that can be proven to work well for any set of data. Other provably good methods date back to the pioneering work of Carter and Wegman who introduced the notion of \emph{universal hashing} and described several hash functions for different scenarios \cite{cw79}. @@ -845,7 +843,7 @@ \section{Discussion and Exercises} idea of choosing the multiplier #z# to be a random \emph{odd} number, and the analysis in \secref{multihash} is due to Dietzfelbinger \etal\ \cite{dhkp97}. This version of multiplicative hashing is one of the -simplest, but its collision probability of $2/2^{#d#}$ is a factor of 2 +simplest, but its collision probability of $2/2^{#d#}$ is a factor of two larger than what one could expect with a random function from $2^{#w#}\to 2^{#d#}$. The \emph{multiply-add hashing} method uses the function \[ @@ -874,8 +872,8 @@ \section{Discussion and Exercises} The method from \secref{polyhash} of using polynomials over prime fields to hash variable-length arrays and strings is due to Dietzfelbinger \etal\ -\cite{dgmp92}. It is, unfortunately, not very fast. This is due to its -use of the $\bmod$ operator which relies on a costly machine instruction. +\cite{dgmp92}. Due to its use of the $\bmod$ operator which relies +on a costly machine instruction, it is, unfortunately, not very fast. Some variants of this method choose the prime #p# to be one of the form $2^{#w#}-1$, in which case the $\bmod$ operator can be replaced with addition (#+#) and bitwise-and (#&#) operations \cite[Section~3.6]{k97v2}. @@ -886,13 +884,13 @@ \section{Discussion and Exercises} \begin{exc} - A certain university assigns each of its students student numbers the first - time they register for any course. These numbers are sequential + A certain university assigns each of its students student numbers the + first time they register for any course. These numbers are sequential integers that started at 0 many years ago and are now in the millions. - Suppose we have a class of 100 first year students and we want to - assign them hash codes based on their student numbers. Does it make - more sense to use the first two digits or the last two digits of their - student number? Justify your answer. + Suppose we have a class of one hundred first year students and we want + to assign them hash codes based on their student numbers. Does it + make more sense to use the first two digits or the last two digits of + their student number? Justify your answer. \end{exc} \begin{exc} @@ -910,11 +908,11 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Prove that the bound $2/2^{#d#}$ in \lemref{universal-hashing} is the - best possible by showing that, if $x=2^{#w#-#d#-2}$ and $#y#=3#x#$, - then $\Pr\{#hash(x)#=#hash(y)#\}=2/2^{#d#}$. (Hint look at the binary - representations of $#zx#$ and $#z#3#x#$ and use the fact that $#z#3#x# - = #z#x#+2#z#x#$.) + Prove that the bound $2/2^{#d#}$ in \lemref{universal-hashing} is + the best possible bound by showing that, if $x=2^{#w#-#d#-2}$ and + $#y#=3#x#$, then $\Pr\{#hash(x)#=#hash(y)#\}=2/2^{#d#}$. (Hint look + at the binary representations of $#zx#$ and $#z#3#x#$ and use the fact + that $#z#3#x# = #z#x#+2#z#x#$.) \end{exc} \begin{exc}\exclabel{linear-probing} @@ -923,7 +921,7 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Consider the following the simplified version of the code for adding + Consider the following simplified version of the code for adding an element #x# to a #LinearHashTable#, which simply stores #x# in the first #null# array entry it finds. Explain why this could be very slow by giving an example of a sequence of $O(#n#)$ #add(x)#, #remove(x)#, @@ -934,10 +932,11 @@ \section{Discussion and Exercises} \begin{exc} Early versions of the Java #hashCode()# method for the #String# class - worked by not using all characters of long strings. For example, for - a 16 character string, the hash code was computed using only the 8 - even-indexed characters. Explain why this was a very bad idea by Giving - an example of large set of strings that all have the same hash code. + worked by not using all of the characters found in long strings. For + example, for a sixteen character string, the hash code was computed + using only the eight even-indexed characters. Explain why this was a + very bad idea by giving an example of large set of strings that all + have the same hash code. \end{exc} \begin{exc}\exclabel{hash-hack-first} @@ -983,7 +982,7 @@ \section{Discussion and Exercises} Find some commonly-used hash table implementation (\javaonly{The Java Collection Framework #HashMap#}\cpponly{The C++ STL #unordered\_map#} or the #HashTable# or #LinearHashTable# implementations in this book, - for example) and design a program that stores integers in this data + for example, and design a program that stores integers in this data structure so that there are integers, #x#, such that #find(x)# takes linear time. That is, find a set of #n# integers for which there are $c#n#$ elements that hash to the same table location. diff --git a/latex/heaps.tex b/latex/heaps.tex index 8517f3b0..e2e2abcc 100644 --- a/latex/heaps.tex +++ b/latex/heaps.tex @@ -4,11 +4,11 @@ \chapter{Heaps} In this chapter, we discuss two implementations of the extremely useful priority #Queue# data structure. Both of these structures are a special kind of binary tree called a \emph{heap}, which means ``a disorganized -pile.'' This is in contrast to binary search trees that can thought of -as a highly organized pile. +pile.'' This is in contrast to binary search trees that can be thought +of as a highly organized pile. -The first heap implementation uses an array to simulate a complete -binary tree. It is very fast and is the basis of one of the fastest +The first heap implementation uses an array to simulate a complete binary +tree. This very fast implementation is the basis of one of the fastest known sorting algorithms, namely heapsort (see \secref{heapsort}). The second implementation is based on more flexible binary trees. It supports a #meld(h)# operation that allows the priority queue to @@ -17,14 +17,14 @@ \chapter{Heaps} \section{#BinaryHeap#: An Implicit Binary Tree} \seclabel{binaryheap} -Our first implementation of a (priority) #Queue# is based on a -technique that is over 400 years old. \emph{Eytzinger's method} -allows us to represent a complete binary tree as an array. This is -done by laying out the nodes of the tree in breadth-first order (see -\secref{bintree:traversal}) in the array. In this way, the root is -stored at position 0, the root's left child is stored at position 1, -the root's right child at position 2, the left child of the left child -of the root is stored at position 3, and so on. See \figref{eytzinger}. +Our first implementation of a (priority) #Queue# is based on a technique +that is over four hundred years old. \emph{Eytzinger's method} allows us +to represent a complete binary tree as an array by laying out the nodes +of the tree in breadth-first order (see \secref{bintree:traversal}). +In this way, the root is stored at position 0, the root's left child is +stored at position 1, the root's right child at position 2, the left +child of the left child of the root is stored at position 3, and so +on. See \figref{eytzinger}. \begin{figure} \begin{center} @@ -34,10 +34,11 @@ \section{#BinaryHeap#: An Implicit Binary Tree} \figlabel{eytzinger} \end{figure} -If we do this for a large enough tree, some patterns emerge. The left -child of the node at index #i# is at index $#left(i)#=2#i#+1$ and the -right child of the node at index #i# is at index $#right(i)#=2#i#+2$. -The parent of the node at index #i# is at index $#parent(i)#=(#i#-1)/2$. +If we apply Eytzinger's method to sufficiently large tree, some +patterns emerge. The left child of the node at index #i# is at index +$#left(i)#=2#i#+1$ and the right child of the node at index #i# is at +index $#right(i)#=2#i#+2$. The parent of the node at index #i# is at +index $#parent(i)#=(#i#-1)/2$. \codeimport{ods/BinaryHeap.left(i).right(i).parent(i)} A #BinaryHeap# uses this technique to implicitly represent a complete @@ -51,7 +52,7 @@ \section{#BinaryHeap#: An Implicit Binary Tree} \codeimport{ods/BinaryHeap.a.n} Implementing the #add(x)# operation is fairly straightforward. As with -all array-based structures, we first check if #a# is full (because +all array-based structures, we first check to see if #a# is full (because $#a.length#=#n#$) and, if so, we grow #a#. Next, we place #x# at location #a[n]# and increment #n#. At this point, all that remains is to ensure that we maintain the heap property. We do this by repeatedly swapping @@ -97,7 +98,7 @@ \section{#BinaryHeap#: An Implicit Binary Tree} As with other array-based structures, we will ignore the time spent in -calls to #resize()#, since these can be accounted for with the amortization +calls to #resize()#, since these can be accounted for using the amortization argument from \lemref{arraystack-amortized}. The running times of both #add(x)# and #remove()# then depend on the height of the (implicit) binary tree. Luckily, this is a \emph{complete} binary tree; every level @@ -143,12 +144,12 @@ \section{#MeldableHeap#: A Randomized Meldable Heap} node that is the root of a heap that contains all elements in the subtree rooted at #h1# and all elements in the subtree rooted at #h2#. -The nice thing about a #merge(h1,h2)# operation is that it can be defined -recursively. See \figref{meldable-merge}. If either of #h1# or #h2# -is #nil#, then we are merging with an empty set, so we return #h2# +The nice thing about a #merge(h1,h2)# operation is that it can be +defined recursively. See \figref{meldable-merge}. If either #h1# or +#h2# is #nil#, then we are merging with an empty set, so we return #h2# or #h1#, respectively. Otherwise, assume $#h1.x# \le #h2.x#$ since, if $#h1.x# > #h2.x#$, then we can reverse the roles of #h1# and #h2#. -Then we know that the root of the merged heap will contain #h1.x# and +Then we know that the root of the merged heap will contain #h1.x#, and we can recursively merge #h2# with #h1.left# or #h1.right#, as we wish. This is where randomization comes in, and we toss a coin to decide whether to merge #h2# with #h1.left# or #h1.right#: @@ -185,11 +186,11 @@ \section{#MeldableHeap#: A Randomized Meldable Heap} \subsection{Analysis of #merge(h1,h2)#} The analysis of #merge(h1,h2)# is based on the analysis of a random walk -in a binary tree. A \emph{random walk} in a binary tree is a walk that -starts at the root of the tree. At each step in the walk, a coin is -tossed and the walk proceeds to the left or right child of the current -node depending on the result of this coin toss. The walk ends when it -falls off the tree (the current node becomes #nil#). +in a binary tree. A \emph{random walk} in a binary tree starts at the +root of the tree. At each step in the random walk, a coin is tossed and, +depending on the result of this coin toss, the walk proceeds to the left +or to the right child of the current node. The walk ends when it falls +off the tree (the current node becomes #nil#). The following lemma is somewhat remarkable because it does not depend at all on the shape of the binary tree: @@ -285,9 +286,10 @@ \subsection{Summary} \section{Discussion and Exercises} The implicit representation of a complete binary tree as an array, -or list, seems to have been first proposed by Eytzinger \cite{e1590}, -as a representation for pedigree family trees. The #BinaryHeap# data -structure described here was first introduced by Williams \cite{w64}. +or list, seems to have been first proposed by Eytzinger \cite{e1590}. +He used this representation in books containing pedigree family trees +of noble families. The #BinaryHeap# data structure described here was +first introduced by Williams \cite{w64}. The randomized #MeldableHeap# data structure described here appears to have first been proposed by Gambin and Malinowski \cite{gm98}. @@ -299,14 +301,14 @@ \section{Discussion and Exercises} Some of the above structures also support a #decreaseKey(u,y)# operation in which the value stored at node #u# is decreased to #y#. (It is a -pre-condition that $#y#\le#u.x#$.) This operation can be implemented -in $O(\log #n#)$ time in most of the above structures by removing node +pre-condition that $#y#\le#u.x#$.) In most of the preceding structures, +this operation can be supported in $O(\log #n#)$ time by removing node #u# and adding #y#. However, some of these structures can implement #decreaseKey(u,y)# more efficiently. In particular, #decreaseKey(u,y)# takes $O(1)$ amortized time in Fibonacci heaps and $O(\log\log #n#)$ amortized time in a special version of pairing heaps \cite{e09}. This more efficient #decreaseKey(u,y)# operation has applications in -speeding up several graph algorithms including Dijkstra's shortest path +speeding up several graph algorithms, including Dijkstra's shortest path algorithm \cite{ft87}. \begin{exc} @@ -361,19 +363,19 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Show how, in a #BinaryHeap# or #MeldableHeap#, to find the second - smallest value in constant time. + Show how to find the second smallest value in a #BinaryHeap# or + #MeldableHeap# in constant time. \end{exc} \begin{exc} - Show how, in a #BinaryHeap# or #MeldableHeap#, to find the $k$th - smallest value in $O(k\log k)$ time. (Hint: Using another heap might - help.) + Show how to find the $k$th smallest value in a #BinaryHeap# or + #MeldableHeap# in $O(k\log k)$ time. (Hint: Using another heap + might help.) \end{exc} \begin{exc} - Suppose you are given #k# sorted lists, of total length #n#. Show how, - using a heap, to merge these into a single sorted list in $O(n\log + Suppose you are given #k# sorted lists, of total length #n#. Using + a heap, show how to merge these into a single sorted list in $O(n\log k)$ time. (Hint: Starting with the case $k=2$ can be instructive.) \end{exc} diff --git a/latex/intro.tex b/latex/intro.tex index d56ba5c6..5a3b1601 100644 --- a/latex/intro.tex +++ b/latex/intro.tex @@ -538,7 +538,7 @@ \subsection{Asymptotic Notation} \cppimport{ods/Simple.snippet()} One execution of this method involves \begin{itemize} - \item $1$ assignment (#int i = 0#), + \item $1$ assignment (#int\, i\, =\, 0#), \item $#n#+1$ comparisons (#i < n#), \item #n# increments (#i++#), \item #n# array offset calculations (#a[i]#), and diff --git a/latex/linkedlists.tex b/latex/linkedlists.tex index db8dfa26..18564e97 100644 --- a/latex/linkedlists.tex +++ b/latex/linkedlists.tex @@ -230,7 +230,7 @@ \section{#SEList#: A Space-Efficient Linked List} elements that are deep within the list) is their space usage. Each node in a #DLList# requires an additional two references to the next and previous nodes in the list. Two of the fields in a #Node# are dedicated -to maintaining the list and only one of the fields is for storing data! +to maintaining the list, and only one of the fields is for storing data! An #SEList# (space-efficient list) reduces this wasted space using a simple idea: Rather than store individual elements in a #DLList#, @@ -238,15 +238,14 @@ \section{#SEList#: A Space-Efficient Linked List} #SEList# is parameterized by a \emph{block size} #b#. Each individual node in an #SEList# stores a block that can hold up to #b+1# elements. -It will turn out, for reasons that become clear later, that it will -be helpful if we can do #Deque# operations on each block. The data -structure we choose for this is a #BDeque# (bounded deque), derived -from the #ArrayDeque# structure described in \secref{arraydeque}. -The #BDeque# differs from the #ArrayDeque# in one small way: When a -new #BDeque# is created, the size of the backing array #a# -is fixed at #b+1# and it never grows or shrinks. -The important property of a #BDeque# is that it allows for the addition or -removal of elements at either the front or back in constant time. This +For reasons that will become clear later, it will be helpful if we +can do #Deque# operations on each block. The data structure we choose +for this is a #BDeque# (bounded deque), derived from the #ArrayDeque# +structure described in \secref{arraydeque}. The #BDeque# differs from the +#ArrayDeque# in one small way: When a new #BDeque# is created, the size +of the backing array #a# is fixed at #b+1# and never grows or shrinks. +The important property of a #BDeque# is that it allows for the addition +or removal of elements at either the front or back in constant time. This will be useful as elements are shifted from one block to another. @@ -267,25 +266,29 @@ \subsection{Space Requirements} #n#/(#b#-1) + 1 = O(#n#/#b#) \] blocks. The #BDeque# for each block contains an array of length $#b#+1$ -but, for all blocks except the last, at most a constant amount of +but, for every blocks except the last, at most a constant amount of space is wasted in this array. The remaining memory used by a block is also constant. This means that the wasted space in an #SEList# is only $O(#b#+#n#/#b#)$. By choosing a value of #b# within a constant factor -of $\sqrt{#n#}$ we can make the space-overhead of an SEList approach +of $\sqrt{#n#}$, we can make the space-overhead of an SEList approach the $\sqrt{#n#}$ lower bound given in \secref{rootishspaceusage}. \subsection{Finding Elements} The first challenge we face with an #SEList# is finding the list item with a given index #i#. Note that the location of an element consists -of two parts: The node #u# that contains the block that contains the -element as well as the index #j# of the element within its block. +of two parts: +\begin{enumerate} + \item The node #u# that contains the block that contains the element + with index #i#; and + \item the index #j# of the element within its block. +\end{enumerate} \codeimport{ods/SEList.Location} -To find the block that contains a particular element, we proceed in the -same way as in a #DLList#. We either start at the front of the list and -traverse in the forward direction or at the back of the list and traverse +To find the block that contains a particular element, we proceed the same +way as we do in a #DLList#. We either start at the front of the list and +traverse in the forward direction, or at the back of the list and traverse backwards until we reach the node we want. The only difference is that, each time we move from one node to the next, we skip over a whole block of elements. @@ -296,11 +299,11 @@ \subsection{Finding Elements} Remember that, with the exception of at most one block, each block contains at least $#b#-1$ elements, so each step in our search gets us $#b#-1$ elements closer to the element we are looking for. If we -are searching forward, this means we reach the node we want after -$O(1+#i#/#b#)$ steps. If we search backwards, we reach the node we want -after $O(1+(#n#-#i#)/#b#)$ steps. The algorithm takes the smaller of -these two quantities depending on the value of #i#, so the time to locate -the item with index #i# is $O(1+\min\{#i#,#n#-#i#\}/#b#)$. +are searching forward, this means that we reach the node we want after +$O(1+#i#/#b#)$ steps. If we search backwards, then we reach the node we +want after $O(1+(#n#-#i#)/#b#)$ steps. The algorithm takes the smaller +of these two quantities depending on the value of #i#, so the time to +locate the item with index #i# is $O(1+\min\{#i#,#n#-#i#\}/#b#)$. Once we know how to locate the item with index #i#, the #get(i)# and #set(i,x)# operations translate into getting or setting a particular @@ -314,13 +317,13 @@ \subsection{Finding Elements} \subsection{Adding an Element} -Things start to get complicated when adding elements to an #SEList#. -Before considering the general case, we consider the easier operation, -#add(x)#, in which #x# is added to the end of the list. If the last -block is full (or does not exist because there are no blocks yet), -then we first allocate a new block and append it to the list of blocks. -Now that we are sure that the last block exists and is not full, we -append #x# to the last block. +Adding elements to an #SEList# is a little more complicated. Before +considering the general case, we consider the easier operation, #add(x)#, +in which #x# is added to the end of the list. If the last block is full +(or does not exist because there are no blocks yet), then we first +allocate a new block and append it to the list of blocks. Now that +we are sure that the last block exists and is not full, we append #x# +to the last block. \codeimport{ods/SEList.add(x)} @@ -382,17 +385,16 @@ \subsection{Adding an Element} \subsection{Removing an Element} -Removing an element, using the #remove(i)# method from an #SEList# -is similar to adding an element. We first locate the node #u# that -contains the element with index #i#. Now, we have to be prepared for -the case where we cannot remove an element from #u# without causing #u#'s -block to have size less than $#b#-1$, which is not allowed. +Removing an element from an #SEList# is similar to adding an element. +We first locate the node #u# that contains the element with index #i#. +Now, we have to be prepared for the case where we cannot remove an element +from #u# without causing #u#'s block to become smaller than $#b#-1$. Again, let $#u#_0,#u#_1,#u#_2,\ldots$ denote #u#, #u.next#, #u.next.next#, -We examine $#u#_0,#u#_1,#u#_2,\ldots$ in order looking for a node from -which we can borrow an element to make the size of $#u#_0$'s block larger -than $#b#-1$. There are three cases to consider -(see \figref{selist-remove}): +and so on. We examine $#u#_0,#u#_1,#u#_2,\ldots$ in order to look +for a node from which we can borrow an element to make the size of +$#u#_0$'s block at least $#b#-1$. There are three cases to consider +(see \figref{selist-remove}): \begin{figure} \noindent @@ -411,23 +413,24 @@ \subsection{Removing an Element} \begin{enumerate} \item We quickly (in $r+1\le #b#$ steps) find a node whose block contains more than $#b#-1$ elements. In this case, we perform $r$ shifts of an -element from one block into the previous, so that the extra element in -$#u#_r$ becomes an extra element in $#u#_0$. We can then remove the +element from one block into the previous one, so that the extra element +in $#u#_r$ becomes an extra element in $#u#_0$. We can then remove the appropriate element from $#u#_0$'s block. -\item We quickly (in $r+1\le #b#$ steps) run off the end of the list of blocks. -In this case, $#u#_r$ is the last block, and there is no requirement that -$#u#_r$'s block contain at least $#b#-1$ elements. Therefore, we proceed -as above, borrowing an element from $#u#_r$ to make an extra element in -$#u#_0$. If this causes $#u#_r$'s block to become empty, then we remove it. +\item We quickly (in $r+1\le #b#$ steps) run off the end of the list of +blocks. In this case, $#u#_r$ is the last block, and there is no need +for $#u#_r$'s block to contain at least $#b#-1$ elements. Therefore, +we proceed as above, borrowing an element from $#u#_r$ to make an extra +element in $#u#_0$. If this causes $#u#_r$'s block to become empty, +then we remove it. -\item After #b# steps we do not find any block containing more than +\item After #b# steps, we do not find any block containing more than $#b#-1$ elements. In this case, $#u#_0,\ldots,#u#_{#b#-1}$ is a sequence of #b# blocks that each contain $#b#-1$ elements. We \emph{gather} these $#b#(#b#-1)$ elements into $#u#_0,\ldots,#u#_{#b#-2}$ so that each of these $#b#-1$ blocks contains exactly #b# elements and we remove $#u#_{#b#-1}$, which is now empty. Now $#u#_0$'s block contains #b# -elements so we can remove the appropriate element from it. +elements and we can then remove the appropriate element from it. \end{enumerate} \codeimport{ods/SEList.remove(i)} @@ -438,13 +441,15 @@ \subsection{Removing an Element} \subsection{Amortized Analysis of Spreading and Gathering} -Next, we consider the cost of the #gather(u)# and #spread(u)# methods that may be executed by the #add(i,x)# and #remove(i)# methods. For completeness, here they are: +Next, we consider the cost of the #gather(u)# and #spread(u)# methods +that may be executed by the #add(i,x)# and #remove(i)# methods. For the +sake of completeness, here they are: \codeimport{ods/SEList.spread(u)} \codeimport{ods/SEList.gather(u)} The running time of each of these methods is dominated by the two -nested loops. Both the inner loop and outer loop execute at most +nested loops. Both the inner and outer loops execute at most $#b#+1$ times, so the total running time of each of these methods is $O((#b#+1)^2)=O(#b#^2)$. However, the following lemma shows that these methods execute on at most one out of every #b# calls to #add(i,x)# @@ -470,9 +475,9 @@ \subsection{Amortized Analysis of Spreading and Gathering} only one node, $#u#_r$ has the size of its block changed. Therefore, at most one node, namely $#u#_r$, goes from being rugged to being fragile. If Case~2 occurs, then a new node is created, and this node - is fragile, but no other node changes sizes, so the number of fragile + is fragile, but no other node changes size, so the number of fragile nodes increases by one. Thus, in either Case~1 or Case~2 the potential - of the SEList increases by at most 1. + of the SEList increases by at most one. Finally, if Case~3 occurs, it is because $#u#_0,\ldots,#u#_{#b#-1}$ are all fragile nodes. Then $#spread(#u_0#)#$ is called and these #b# @@ -513,23 +518,23 @@ \subsection{Summary} \end{thm} The #SEList# is a tradeoff between an #ArrayList# and a #DLList# where -the relative mix of these two structures depends on the block size -#b#. At the extreme $#b#=2$, each #SEList# node stores at most 3 -values, which is really not much different than a #DLList#. At the other -extreme, $#b#>#n#$, all the elements are stored in a single array, -just like in an #ArrayList#. In between these two extremes lies a -tradeoff between the time it takes to add or remove a list item and -the time it takes to locate a particular list item. +the relative mix of these two structures depends on the block size #b#. +At the extreme $#b#=2$, each #SEList# node stores at most three values, +which is not much different than a #DLList#. At the other extreme, +$#b#>#n#$, all the elements are stored in a single array, just like in +an #ArrayList#. In between these two extremes lies a tradeoff between +the time it takes to add or remove a list item and the time it takes to +locate a particular list item. \section{Discussion and Exercises} -Both singly-linked and doubly-linked lists are folklore, having been -used in programs for over 40 years. They are discussed, for example, -by Knuth \cite[Sections~2.2.3--2.2.5]{k97v1}. Even the #SEList# data -structure seems to be a well-known data structures exercise. +Both singly-linked and doubly-linked lists are established techniques, +having been used in programs for over 40 years. They are discussed, +for example, by Knuth \cite[Sections~2.2.3--2.2.5]{k97v1}. Even the +#SEList# data structure seems to be a well-known data structures exercise. \begin{exc} - Why is it not possible, in an #SLList# to use a dummy node to avoid + Why is it not possible to use a dummy node in an #SLList# to avoid all the special cases that occur in the operations #push(x)#, #pop()#, #add(x)#, and #remove()#? \end{exc} @@ -562,17 +567,17 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Without referring to this chapter, try to recreate the code for the - #addBefore(w)# operation, that creates a node, #u#, and adds it just - before the node #w# in a #DLList#. If your code does not exactly match - the code given in this book it may still be correct. Test it and see - if it works. + Try to recreate the code for the #addBefore(w)# operation that creates a + node, #u#, and adds it in a #DLList# just before the node #w#. Do not + refer to this chapter. Even if your code does not exactly match the + code given in this book it may still be correct. Test it and see if + it works. \end{exc} The next few exercises involve performing manipulations on #DLList#s. -These should all be done without allocating any new nodes or temporary -arrays. More specifically, they can all be done only by changing -the #prev# and #next# values of existing nodes. +You should complete them without allocating any new nodes or temporary +arrays. They can all be done only by changing the #prev# and #next# +values of existing nodes. \begin{exc} Write a #DLList# method #isPalindrome()# that returns #true# if the @@ -591,8 +596,8 @@ \section{Discussion and Exercises} \begin{exc}\exclabel{linkedlist-truncate} Write a method, #truncate(i)#, that truncates a #DLList# at position - #i#. After the execution of this method, the size of the list is #i# - and it contains only the elements at indices $0,\ldots,#i#-1$. The + #i#. After executing this method, the size of the list will be #i# and + it should contain only the elements at indices $0,\ldots,#i#-1$. The return value is another #DLList# that contains the elements at indices $#i#,\ldots,#n#-1$. This method should run in $O(\min\{#i#,#n#-#i#\})$ time. @@ -620,7 +625,7 @@ \section{Discussion and Exercises} \end{exc} \begin{exc}\exclabel{dllist-sort} - This exercises walks you through an implementation of the merge sort + This exercise walks you through an implementation of the merge sort algorithm for sorting a #DLList#, as discussed in \secref{merge-sort}. \javaonly{In your implementation, perform comparisons between elements using the #compareTo(x)# method so that the resulting implementation can @@ -636,13 +641,14 @@ \section{Discussion and Exercises} list containing the result. This causes #l1# and #l2# to be emptied in the proces. For example, if #l1# contains $a,c,d$ and #l2# contains $b,e,f$, then this method returns a new list containing $a,b,c,d,e,f$. - \item Write a #DLList# method #sort()# that sorts the elements contained - in the list using the merge sort algorithm. This recursive algorithm works as following: + \item Write a #DLList# method #sort()# that sorts the elements + contained in the list using the merge sort algorithm. + This recursive algorithm works in the following way: \begin{enumerate} \item If the list contains 0 or 1 elements then there is nothing to do. Otherwise, - \item Split the list into two approximately equal length lists - #l1# and #l2# using the #truncate(size()/2)# method; + \item Using the #truncate(size()/2)# method, split the list + into two lists of approximately equal length, #l1# and #l2#; \item Recursively sort #l1#; \item Recursively sort #l2#; and, finally, \item Merge #l1# and #l2# into a single sorted list. @@ -664,7 +670,7 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Design an implement a #MinQueue# data structure that can store + Design and implement a #MinQueue# data structure that can store comparable elements and supports the queue operations #add(x)#, #remove()#, and #size()#, as well as the #min()# operation, which returns the minimum value currently stored in the data structure. @@ -672,7 +678,7 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Design an implement a #MinDeque# data structure that can store + Design and implement a #MinDeque# data structure that can store comparable elements and supports the queue operations #addFirst(x)#, #addLast(x)# #removeFirst()#, #removeLast()# and #size()#, as well as the #min()# operation, which returns the minimum value currently @@ -681,7 +687,7 @@ \section{Discussion and Exercises} \end{exc} The next exercises are designed to test the reader's understanding of -the implementation an analysis of the space-efficient #SEList#: +the implementation and analysis of the space-efficient #SEList#: \begin{exc} Prove that, if an #SEList# is used like a #Stack# (so that the @@ -691,7 +697,7 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Design an implement of a version of an #SEList# that supports all + Design and implement of a version of an #SEList# that supports all the #Deque# operations in constant amortized time per operation, independent of the value of #b#. \end{exc} diff --git a/latex/mathastext.sty b/latex/mathastext.sty new file mode 100644 index 00000000..b94db878 --- /dev/null +++ b/latex/mathastext.sty @@ -0,0 +1,1876 @@ +%% +%% This is file `mathastext.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% mathastext.dtx (with options: `package') +%% +%% IMPORTANT NOTICE: +%% +%% For the copyright see the source file. +%% +%% Any modified versions of this file must be renamed +%% with new filenames distinct from mathastext.sty. +%% +%% For distribution of the original source see the terms +%% for copying and modification in the file mathastext.dtx. +%% +%% This generated file may be distributed as long as the +%% original source files, as listed above, are part of the +%% same distribution. (The sources need not necessarily be +%% in the same archive or directory.) +%% +\ProvidesPackage{mathastext} + [2013/01/21 v1.2f Use the text font in math mode (jfB)] +%% +%% Package `mathastext' by Jean-Francois Burnol +%% Copyright (C) 2011, 2012 by Jean-Francois Burnol +%% +\NeedsTeXFormat{LaTeX2e} +\newif\ifmst@XeTeX +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname XeTeXinterchartoks\endcsname\relax + \mst@XeTeXfalse +\else + \mst@XeTeXtrue +\fi +\newif\ifmst@LuaTeX +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname directlua\endcsname\relax + \mst@LuaTeXfalse +\else + \mst@LuaTeXtrue +\fi +\def\mst@oti{OT1}\def\mst@ti{T1}\def\mst@lyi{LY1} +\def\mst@eui{EU1}\def\mst@euii{EU2} +\newif\ifmst@goahead +\newif\ifmst@abort +\newif\ifmst@optionalparam + \def\mst@enc{\encodingdefault} + \def\mst@fam{\familydefault} + \def\mst@ser{\seriesdefault} + \def\mst@opsh{\shapedefault} %% will be default shape for operator names + \def\mst@bold{\bfdefault} + \def\mst@ltsh{\shapedefault} %% will be default shape for letters + \edef\mst@greekfont{\familydefault} %% v 1.15c +\newif\ifmst@italic +\newif\ifmst@frenchmath + \DeclareOption{italic}{\mst@italictrue + \def\mst@ltsh{\itdefault}} + \DeclareOption{frenchmath}{\mst@frenchmathtrue\mst@italictrue + \def\mst@ltsh{\itdefault}} +%% +\newif\ifmst@endash\mst@endashtrue + \DeclareOption{endash}{\mst@endashtrue} + \DeclareOption{noendash}{\mst@endashfalse} +\newif\ifmst@emdash + \DeclareOption{emdash}{\mst@emdashtrue\mst@endashfalse} +%% +\newif\ifmst@alldelims +\edef\mst@tmp{\encodingdefault}\ifx\mst@oti\mst@tmp\else\mst@alldelimstrue\fi + \DeclareOption{alldelims}{\mst@alldelimstrue} + \DeclareOption{nolessnomore}{\mst@alldelimsfalse} +%% new with 1.2 +\newif\ifmst@nosmalldelims + \DeclareOption{nosmalldelims}{\mst@nosmalldelimstrue} +%% +\newif\ifmst@noplus + \DeclareOption{noplus}{\mst@noplustrue} +\newif\ifmst@nominus + \DeclareOption{nominus}{\mst@nominustrue} +\DeclareOption{noplusnominus}{\ExecuteOptions{noplus,nominus}} +%% +\newif\ifmst@noparen + \DeclareOption{noparenthesis}{\mst@noparentrue} +\newif\ifmst@nopunct + \DeclareOption{nopunctuation}{\mst@nopuncttrue} +\newif\ifmst@noequal + \DeclareOption{noequal}{\mst@noequaltrue} +\newif\ifmst@noexclam + \DeclareOption{noexclam}{\mst@noexclamtrue} +\newif\ifmst@asterisk + \DeclareOption{noasterisk}{\PackageWarningNoLine{mathastext} + {option `noasterisk\string' is deprecated.^^J\space\space\space + Check the documentation}} + \DeclareOption{asterisk}{\mst@asterisktrue + \AtBeginDocument{ + \everymath\expandafter{\the\everymath \mst@doasterisk + \let\mst@doasterisk\relax} + \everydisplay\expandafter{\the\everydisplay \mst@doasterisk + \let\mst@doasterisk\relax}}} +\newif\ifmst@nospecials + \DeclareOption{nospecials}{\mst@nospecialstrue} +\DeclareOption{basic}{\ExecuteOptions{noparenthesis,nopunctuation,% +noplusnominus,noequal,noexclam,nospecials,nolessnomore}} +%% +\newif\ifmst@nohbar + \DeclareOption{nohbar}{\mst@nohbartrue} +\newif\ifmst@nodigits + \DeclareOption{nodigits}{\mst@nodigitstrue} +\newif\ifmst@defaultimath + \DeclareOption{defaultimath}{\mst@defaultimathtrue} +\newif\ifmst@mathaccents + \DeclareOption{mathaccents}{\mst@mathaccentstrue} +%% +\newif\ifmst@needsymbol +\newif\ifmst@symboldelimiters + \DeclareOption{symboldelimiters}{\mst@needsymboltrue\mst@symboldelimiterstrue} +\newif\ifmst@symboldigits + \DeclareOption{symboldigits}{\mst@needsymboltrue\mst@symboldigitstrue} +\newif\ifmst@symbolgreek + \DeclareOption{symbolgreek}{\mst@needsymboltrue\mst@symbolgreektrue} +\newif\ifmst@symbolre + \DeclareOption{symbolre}{\mst@needsymboltrue\mst@symbolretrue} +\newif\ifmst@symbolmisc + \DeclareOption{symbolmisc}{\mst@needsymboltrue\mst@symbolmisctrue} +\DeclareOption{symbol}{\ExecuteOptions{symbolgreek,symbolmisc,symbolre}} +\DeclareOption{symbolmax}{\ExecuteOptions{symbol,symboldelimiters}} +%% +\newif\ifmst@needeuler +\newif\ifmst@eulerdigits + \DeclareOption{eulerdigits}{\mst@needeulertrue\mst@eulerdigitstrue} +\newif\ifmst@eulergreek + \DeclareOption{eulergreek}{\mst@needeulertrue\mst@eulergreektrue} +%% +\newif\ifmst@selfGreek + \DeclareOption{selfGreek}{\mst@selfGreektrue} +\newif\ifmst@selfGreeks + \DeclareOption{selfGreeks}{\mst@selfGreekstrue\mst@selfGreektrue} +\newif\ifmst@LGRgreek + \DeclareOption{LGRgreek}{\mst@LGRgreektrue} +\newif\ifmst@LGRgreeks + \DeclareOption{LGRgreeks}{\mst@LGRgreekstrue\mst@LGRgreektrue} +%% +\def\mst@greek@select{0} +\newif\ifmst@itgreek +\newif\ifmst@upgreek + \DeclareOption{itgreek}{\mst@itgreektrue} + \DeclareOption{upgreek}{\mst@upgreektrue} + \DeclareOption{itGreek}{\def\mst@greek@select{1}} + \DeclareOption{upGreek}{\def\mst@greek@select{2}} +%% +\newif\ifmst@defaultnormal + \DeclareOption{defaultnormal}{\mst@defaultnormaltrue} +\newif\ifmst@defaultrm + \DeclareOption{defaultrm}{\mst@defaultrmtrue} +\newif\ifmst@defaultbf + \DeclareOption{defaultbf}{\mst@defaultbftrue} +\newif\ifmst@defaultit + \DeclareOption{defaultit}{\mst@defaultittrue} +\newif\ifmst@defaultsf + \DeclareOption{defaultsf}{\mst@defaultsftrue} +\newif\ifmst@defaulttt + \DeclareOption{defaulttt}{\mst@defaulttttrue} +\newif\ifmst@nonormalbold +\DeclareOption{defaultalphabets}{\ExecuteOptions{defaultnormal,defaultrm,% +defaultbf,defaultit,defaultsf,defaulttt}\mst@nonormalboldtrue} +\newif\ifmst@defaultsizes + \DeclareOption{defaultmathsizes}{\mst@defaultsizestrue} +\newif\ifmst@twelve + \DeclareOption{12pt}{\mst@twelvetrue} +\newif\ifmst@fouriervec + \DeclareOption{fouriervec}{\mst@fouriervectrue} +\newif\ifmst@subdued + \DeclareOption{subdued}{\mst@subduedtrue} +\DeclareOption*{\PackageWarningNoLine{mathastext}{Unknown option `\CurrentOption\string'}} +\ProcessOptions\relax +\newmuskip\mst@exists@muskip %% v 1.15e +\newmuskip\mst@forall@muskip +\def\mst@exists@skip{1mu} +\def\mst@forall@skip{.6667mu} +\ifmst@italic\ifmst@frenchmath\else + \def\mst@exists@skip{0mu}\def\mst@forall@skip{0mu}\def\mst@prime@skip{0mu} +\fi\fi +\AtEndOfPackage{% must be at end of code +\let\mst@stdexists\exists +\let\mst@stdforall\forall +\renewcommand\exists{\mst@stdexists\mskip\mst@exists@muskip} +\renewcommand\forall{\mst@stdforall\mskip\mst@forall@muskip} +} +\newmuskip\mst@prime@muskip %% v 1.2 +\def\mst@prime@skip{.5mu} +\ifmst@italic\ifmst@frenchmath\else\def\mst@prime@skip{0mu}\fi\fi +\def\mst@active@math@prime{\sp\bgroup\mskip\mst@prime@muskip\prim@s} +{\catcode`\'=12 +\gdef\mst@modifyprime{\mst@mathactivate'{}\mst@active@math@prime}} +\AtBeginDocument{ +\everymath\expandafter{\the\everymath \mst@modifyprime \MTnormalprime} +\everydisplay\expandafter{\the\everydisplay \mst@modifyprime \MTnormalprime} +} +\newcommand*\MTnormalprime{\let\mst@modifyprime\relax} +\newcommand*\MTexistsskip[1]{\edef\mst@exists@skip{#1}% + \mst@exists@muskip\mst@exists@skip\relax} +\newcommand*\MTforallskip[1]{\edef\mst@forall@skip{#1}% + \mst@forall@muskip\mst@forall@skip\relax} +\newcommand*\MTprimeskip[1]{\edef\mst@prime@skip{#1}% + \mst@prime@muskip\mst@prime@skip\relax} +\let\Mathastextexistsskip\MTexistsskip +\let\Mathastextforallskip\MTforallskip +\let\Mathastextprimeskip\MTprimeskip +\let\mathastextexistsskip\MTexistsskip +\let\mathastextforallskip\MTforallskip +\let\mathastextprimeskip\MTprimeskip +\ifmst@noparen\else +\AtBeginDocument{ +\@ifundefined{resetMathstrut@}{}{% + \PackageWarningNoLine{mathastext}{a custom version of the amsmath macro^^J% + \space\space\space\string\resetMathstrut@\space will replace the original} + \ifmst@symboldelimiters + \def\resetMathstrut@{% + \setbox\z@\hbox{\the\textfont\symmtpsymbol\char40 + \the\textfont\symmtoperatorfont\char40 + \the\textfont\symoperators\char40}% + \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@} + \else + \def\resetMathstrut@{% + \setbox\z@\hbox{\the\textfont\symmtoperatorfont\char40 + \the\textfont\symoperators\char40}% + \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@} + \fi}} +\fi +\newtoks\mst@do@nonletters +\newtoks\mst@do@easynonletters +\newtoks\mst@do@az +\newtoks\mst@do@AZ +\newcommand*\MTnonlettersdonotobeymathxx{\let\mst@the\@gobble} +\newcommand*\MTnonlettersobeymathxx{\let\mst@the\the} +\newcommand*\MTeasynonlettersdonotobeymathxx{\let\mst@theeasy\@gobble} +\newcommand*\MTeasynonlettersobeymathxx{\let\mst@theeasy\the} +\MTnonlettersdonotobeymathxx % 1.2c !!! +\MTeasynonlettersobeymathxx +\newcommand*\MTicinmath{% + \let\mst@thef\the + \let\mst@theF\the + \def\mst@itcorr{\ifnum\fam=\m@ne\/\else\ifnum\fam=\symmtletterfont\/\fi\fi}% + \let\mst@ITcorr\mst@itcorr} +\newcommand*\MTnoicinmath{% also usable in math mode + \def\mst@itcorr{}\def\mst@ITcorr{}% + \let\mst@thef\@gobble\let\mst@theF\@gobble} +\newcommand*\MTICinmath{% + \let\mst@theF\the + \def\mst@ITcorr{\ifnum\fam=\m@ne\/\fi}} +\newcommand*\MTnoICinmath{% also usable in math mode + \def\mst@ITcorr{}% + \let\mst@theF\@gobble} +\newcommand*\MTicalsoinmathxx{% + \ifx\mst@itcorr\@empty\else\def\mst@itcorr{\/}\fi + \ifx\mst@ITcorr\@empty\else\def\mst@ITcorr{\/}\fi} +\AtBeginDocument{ +\everymath\expandafter{\the\everymath + \mst@the\mst@do@nonletters \let\mst@the\@gobble + \mst@theeasy\mst@do@easynonletters \let\mst@theeasy\@gobble + \mst@thef\mst@do@az \let\mst@thef\@gobble + \mst@theF\mst@do@AZ \let\mst@theF\@gobble} +\everydisplay\expandafter{\the\everydisplay + \mst@the\mst@do@nonletters \let\mst@the\@gobble + \mst@theeasy\mst@do@easynonletters \let\mst@theeasy\@gobble + \mst@thef\mst@do@az \let\mst@thef\@gobble + \mst@theF\mst@do@AZ \let\mst@theF\@gobble} +} +\def\mst@magic@v #1#2#3#4#5{#1#3#4} +\def\mst@magic@vi #1#2#3#4#5#6{#1#2#4#5} +\def\mst@fork{\ifmmode\mst@magic@v\fi\@thirdofthree} +\def\mst@safefork{\ifmmode\if@safe@actives\else\mst@magic@vi\fi\fi\@thirdofthree} +\def\mst@do@activecase#1#2#3{% #1 is a category 11 or 12 character token + \@ifundefined{active@char#1}{}{% + \ifcat #1a\mathcode`#1=#2\else + \ifx\relax #2\relax\mathcode`#1=`#1 \else\mathcode`#1=#3\fi\fi + \expandafter\expandafter\expandafter\let\expandafter\expandafter + \csname mst@orig@user@active#1\endcsname + \csname user@active#1\endcsname + \expandafter\expandafter\expandafter\let\expandafter\expandafter + \csname mst@orig@normal@char#1\endcsname + \csname normal@char#1\endcsname + \ifcat #1a% + \expandafter\edef\csname user@active#1\endcsname + {\noexpand\mst@fork {{#2\noexpand#3}}{}\expandafter + \noexpand\csname mst@orig@user@active#1\endcsname + }% + \expandafter\edef\csname normal@char#1\endcsname + {\noexpand\mst@safefork {{#2\noexpand#3}}{}\expandafter + \noexpand\csname mst@orig@normal@char#1\endcsname + }% + \else + \expandafter\edef\csname user@active#1\endcsname + {\noexpand\mst@fork {#2}\noexpand#3\expandafter + \noexpand\csname mst@orig@user@active#1\endcsname + }% + \expandafter\edef\csname normal@char#1\endcsname + {\noexpand\mst@safefork {#2}\noexpand#3\expandafter + \noexpand\csname mst@orig@normal@char#1\endcsname + }% + \fi}} +\begingroup % make sure ~ is active at mathastext loading time + \catcode`~=\active + \def\x{\endgroup + \def\mst@mathactivate##1##2##3{% ##1 guaranteed of cat 11 or 12 + \begingroup + \lccode`~=`##1 + \lccode`##1=`##1 + \lowercase{\endgroup + \ifnum\catcode`##1=\active + \mst@do@activecase ##1{##2}##3 + % careful as ##2 is empty in the asterisk and + % prime case! + \else + \mathcode`##1="8000 + % I use " many times later, \string" everywhere would be a pain + \ifcat##1a\def~{{##2##3}}\else\def~{##2##3}\fi + \fi}}} +\x +\def\mst@addtodo@nonletters#1#2#3{% + % #1 will be of cat 11 or 12. + % #2 is empty for asterisk and right quote + \mst@do@nonletters\expandafter{\the\mst@do@nonletters + \mst@mathactivate#1{#2}#3}% +} +\def\mst@addtodo@easynonletters#1#2{% #1 is a one char control sequence + \mst@do@easynonletters\expandafter{\the\mst@do@easynonletters\mathcode`#1=#2}% +} +\def\mst@addtodo@az#1#2#3{% + \mst@do@az\expandafter{\the\mst@do@az\mst@mathactivate#1#2#3} +} +\def\mst@addtodo@AZ#1#2#3{% + \mst@do@AZ\expandafter{\the\mst@do@AZ\mst@mathactivate#1#2#3}% +} +\@ifpackageloaded{amsmath} +{\let\newmcodes@\relax} % brutal, but bye bye and don't come back. +{} +\ifmst@subdued + \def\mst@reserved#1\getanddefine@fonts\symletters#2#3\@nil{% + \def\mst@normalmv@letter{#2}} + \expandafter\mst@reserved\mv@normal\@nil + \def\mst@reserved#1\getanddefine@fonts\symletters#2#3\@nil{% + \def\mst@boldmv@letter{#2}} + \expandafter\mst@reserved\mv@bold\@nil + \def\mst@reserved#1\getanddefine@fonts\symoperators#2#3\@nil{% + \def\mst@normalmv@operator{#2}} + \expandafter\mst@reserved\mv@normal\@nil + \def\mst@reserved#1\getanddefine@fonts\symoperators#2#3\@nil{% + \def\mst@boldmv@operator{#2}} + \expandafter\mst@reserved\mv@bold\@nil +%% + \edef\mst@tmp{\encodingdefault} + \def\mst@reserved#1/#2/#3/#4/{\gdef\mst@debut{#1}\gdef\mst@reste{#2/#3/#4}} + \begingroup\escapechar\m@ne + \xdef\mst@funnyoti{\expandafter\string\csname OT1\endcsname} + \expandafter\expandafter\expandafter + \mst@reserved\expandafter\string\mst@normalmv@operator/ + \endgroup + \ifx\mst@debut\mst@funnyoti\ifx\mst@tmp\mst@oti\def\mst@tmp{T1}\fi\fi + \edef\mst@normalmv@operator{\expandafter\noexpand\csname + \mst@tmp/\mst@reste\endcsname} + \begingroup\escapechar\m@ne + \expandafter\expandafter\expandafter + \mst@reserved\expandafter\string\mst@boldmv@operator/ + \endgroup + \ifx\mst@debut\mst@funnyoti\ifx\mst@tmp\mst@oti\def\mst@tmp{T1}\fi\fi + \edef\mst@boldmv@operator{\expandafter\noexpand\csname + \mst@tmp/\mst@reste\endcsname} + \AtEndOfPackage{ + \typeout{** ...entering subdued mode...} + \expandafter\SetSymbolFont@ \expandafter\mv@normal\mst@normalmv@letter\symmtletterfont + \expandafter\SetSymbolFont@ \expandafter\mv@bold\mst@boldmv@letter\symmtletterfont + \expandafter\SetSymbolFont@ \expandafter\mv@normal\mst@normalmv@operator\symmtoperatorfont + \expandafter\SetSymbolFont@ \expandafter\mv@bold\mst@boldmv@operator\symmtoperatorfont + \typeout{** ...done.} + } +\fi % fin de ce \ifmst@subdued +\DeclareSymbolFont{mtoperatorfont} + {\mst@enc}{\mst@fam}{\mst@ser}{\mst@opsh} +\newcommand*{\MTmathoperatorsobeymathxx} +{\def\operator@font{\mathgroup\ifnum\fam=\m@ne\symmtoperatorfont\else\fam\fi}} +\newcommand*{\MTmathoperatorsdonotobeymathxx} +{\def\operator@font{\mathgroup\symmtoperatorfont}} +\MTmathoperatorsobeymathxx +\DeclareSymbolFont{mtletterfont} + {\mst@enc}{\mst@fam}{\mst@ser}{\mst@ltsh} +\let\mst@alph@omicron\mathnormal +\@ifpackageloaded{fourier}{\ifsloped\else\let\mst@alph@omicron\mathrm\fi}{} +\DeclareSymbolFontAlphabet{\Mathnormal}{mtletterfont} +\DeclareSymbolFontAlphabet{\Mathrm}{mtoperatorfont} +\ifmst@nonormalbold\else + \DeclareMathAlphabet{\mathnormalbold}{\mst@enc}{\mst@fam}{\mst@bold}{\mst@ltsh} +\fi\ifmst@defaultbf\else + \DeclareMathAlphabet{\Mathbf}{\mst@enc}{\mst@fam}{\mst@bold}{\mst@opsh} +\fi\ifmst@defaultit\else + \DeclareMathAlphabet{\Mathit}{\mst@enc}{\mst@fam}{\mst@ser}{\itdefault} +\fi\ifmst@defaultsf\else + \DeclareMathAlphabet{\Mathsf}{\mst@enc}{\sfdefault}{\mst@ser}{\mst@opsh} +\fi\ifmst@defaulttt\else + \DeclareMathAlphabet{\Mathtt}{\mst@enc}{\ttdefault}{\mst@ser}{\mst@opsh} +\fi +\let\mst@original@normal\mathnormal +\let\mst@original@rm\mathrm +\let\mst@original@bf\mathbf +\let\mst@original@it\mathit +\let\mst@original@sf\mathsf +\let\mst@original@tt\mathtt +\def\mst@restorealphabets{% for subdued + \let\mathnormal\mst@original@normal + \let\mathrm\mst@original@rm + \let\mathbf\mst@original@bf + \let\mathit\mst@original@it + \let\mathsf\mst@original@sf + \let\mathtt\mst@original@tt} +\def\mst@setalphabets{% + \ifmst@defaultnormal\else\renewcommand{\mathnormal}{\Mathnormal}\fi + \ifmst@defaultrm\else\renewcommand{\mathrm}{\Mathrm}\fi + \ifmst@defaultbf\else\renewcommand{\mathbf}{\Mathbf}\fi + \ifmst@defaultit\else\renewcommand{\mathit}{\Mathit}\fi + \ifmst@defaultsf\else\renewcommand{\mathsf}{\Mathsf}\fi + \ifmst@defaulttt\else\renewcommand{\mathtt}{\Mathtt}\fi} +\ifmst@subdued\else\mst@setalphabets\fi +\def\mst@update@greeksh{ + \def\mst@greek@lsh{\mst@ltsh} %% default behavior + \def\mst@greek@ush{\mst@opsh} + \ifmst@itgreek\def\mst@greek@lsh{\itdefault} + \def\mst@greek@ush{\itdefault}\fi + \ifmst@upgreek\def\mst@greek@lsh{\updefault} + \def\mst@greek@ush{\updefault}\fi + \ifmst@frenchmath + \ifmst@itgreek\else + \ifmst@upgreek\else + \def\mst@greek@lsh{\mst@opsh} + \def\mst@greek@ush{\mst@opsh} + \fi\fi + \fi + \ifcase\mst@greek@select + \or\def\mst@greek@ush{\itdefault} + \or\def\mst@greek@ush{\updefault} + \fi} +\mst@update@greeksh +\ifmst@LGRgreek + \DeclareFontEncoding{LGR}{}{} + \DeclareSymbolFont{mtlgrfontlower}{LGR} + {\mst@fam}{\mst@ser}{\mst@greek@lsh} + \DeclareSymbolFont{mtlgrfontupper}{LGR} + {\mst@fam}{\mst@ser}{\mst@greek@ush} +\else +\ifmst@selfGreek + \DeclareSymbolFont{mtselfGreekfont}{OT1} + {\mst@fam}{\mst@ser}{\mst@greek@ush} +\fi\fi +\ifmst@needeuler\typeout{** will use Euler font; command \string\MTEulerScale} +\DeclareSymbolFont{mteulervm}{U}{zeur}{m}{n} +\DeclareSymbolFontAlphabet{\MathEuler}{mteulervm} +\DeclareMathAlphabet{\MathEulerBold}{U}{zeur}{\mst@bold}{n} +\fi +\newcommand*\MTEulerScale[1]{\edef\zeu@Scale{#1}} +\let\MathastextEulerScale\MTEulerScale +\ifmst@needsymbol\typeout{** will use Symbol font; command \string\MTSymbolScale} + \def\psy@scale{1} + \DeclareSymbolFont{mtpsymbol}{U}{psy}{m}{n} + \DeclareSymbolFontAlphabet{\MathPSymbol}{mtpsymbol} +\AtBeginDocument{ + \DeclareFontFamily{U}{psy}{} + \DeclareFontShape{U}{psy}{m}{n}{<->s*[\psy@scale] psyr}{} +} +\fi +\newcommand*\MTSymbolScale[1]{\edef\psy@scale{#1}} +\let\MathastextSymbolScale\MTSymbolScale +\DeclareRobustCommand*\pmvec[1]{\mathord{\stackrel{\raisebox{-.5ex}% +{\tiny\boldmath$\mathord{\rightarrow}$}}{{}#1}}} +\ifmst@fouriervec + \DeclareFontEncoding{FML}{}{} + \DeclareFontSubstitution{FML}{futm}{m}{it} + \DeclareSymbolFont{mathastextfourier}{FML}{futm}{m}{it} + \SetSymbolFont{mathastextfourier}{bold}{FML}{futm}{b}{it} + \DeclareMathAccent{\fouriervec}{\mathord}{mathastextfourier}{"7E} +\fi +\newcommand*\MTencoding[1]{\def\mst@enc{#1}} +\newcommand*\MTfamily[1]{\def\mst@fam{#1}} +\newcommand*\MTseries[1]{\def\mst@ser{#1}} +\newcommand*\MTshape[1]{\def\mst@opsh{#1} + \ifmst@italic\else\def\mst@ltsh{#1}\fi} +\newcommand*\MTboldvariant[1]{\def\mst@bold{#1}} +\newcommand*\MTlettershape[1]{\def\mst@ltsh{#1}} +\@onlypreamble\MTencoding +\@onlypreamble\MTfamily +\@onlypreamble\MTseries +\@onlypreamble\MTshape +\@onlypreamble\MTboldvariant +\@onlypreamble\MTlettershape +\let\Mathastextencoding\MTencoding +\let\Mathastextfamily\MTfamily +\let\Mathastextseries\MTseries +\let\Mathastextshape\MTshape +\let\Mathastextboldvariant\MTboldvariant +\let\Mathastextlettershape\MTlettershape + \newcommand*\MTitgreek{% +\mst@itgreektrue\mst@upgreekfalse\def\mst@greek@select{0}} + \newcommand*\MTupgreek{% +\mst@upgreektrue\mst@itgreekfalse\def\mst@greek@select{0}} + \newcommand*\MTitGreek{\def\mst@greek@select{1}} + \newcommand*\MTupGreek{\def\mst@greek@select{2}} +\@onlypreamble\MTitgreek +\@onlypreamble\MTupgreek +\@onlypreamble\MTitGreek +\@onlypreamble\MTitGreek +\let\Mathastextitgreek\MTitgreek +\let\Mathastextupgreek\MTupgreek +\let\MathastextitGreek\MTitGreek +\let\MathastextupGreek\MTupGreek + \newcommand*\MTgreekfont[1]{\def\mst@greekfont{#1}} +\@onlypreamble\MTgreekfont +\let\Mathastextgreekfont\MTgreekfont +\newcommand*\MTWillUse[5][\empty]{ + \MTencoding{#2} + \MTfamily{#3} + \MTseries{#4} + \MTshape{#5} + \ifmst@italic\MTlettershape{\itdefault}\fi % was missing in v 1.14 and prior + \ifx\empty#1 + \else +%% we check if optional argument was [], this does not detect [ ] + \def\mst@tmp{#1} + \ifx\empty\mst@tmp\else\MTlettershape{#1}\fi + \fi + \Mathastext} +\@onlypreamble\MTWillUse +\let\MathastextWillUse\MTWillUse +\let\Mathastextwilluse\MTWillUse +\newcommand*\Mathastext[1][\empty]{ +\ifx\empty#1 % no optional argument + \mst@update@greeksh + \edef\mst@encoding@normal{\mst@enc} + \edef\mst@family@normal{\mst@fam} + \edef\mst@series@normal{\mst@ser} + \edef\mst@shape@normal{\mst@opsh} + \edef\mst@ltshape@normal{\mst@ltsh} + \edef\mst@itdefault@normal{\itdefault} + \edef\mst@rmdefault@normal{\rmdefault} + \edef\mst@sfdefault@normal{\sfdefault} + \edef\mst@ttdefault@normal{\ttdefault} + \edef\mst@boldvariant@normal{\mst@bold} + \edef\mst@exists@skip@normal{\mst@exists@skip} + \edef\mst@forall@skip@normal{\mst@forall@skip} + \edef\mst@prime@skip@normal{\mst@prime@skip} + \edef\mst@encoding@bold{\mst@enc} + \edef\mst@family@bold{\mst@fam} + \edef\mst@series@bold{\mst@bold} + \edef\mst@shape@bold{\mst@opsh} + \edef\mst@ltshape@bold{\mst@ltsh} + \edef\mst@boldvariant@bold{\mst@bold} + \edef\mst@itdefault@bold{\itdefault} + \edef\mst@rmdefault@bold{\rmdefault} + \edef\mst@sfdefault@bold{\sfdefault} + \edef\mst@ttdefault@bold{\ttdefault} + \edef\mst@exists@skip@bold{\mst@exists@skip} + \edef\mst@forall@skip@bold{\mst@forall@skip} + \edef\mst@prime@skip@bold{\mst@prime@skip} + \MTicinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@ltshape@normal\MTnoicinmath\fi}% + \ifmst@frenchmath + \MTICinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@shape@normal\MTnoICinmath\fi}% + \fi + \ifmst@subdued + \MTeasynonlettersdonotobeymathxx + \MTnonlettersdonotobeymathxx + \MTmathoperatorsdonotobeymathxx + \MTnoicinmath + \ifmst@asterisk\let\mst@doasterisk\relax\fi + \def\mst@exists@skip@normal{0mu} + \def\mst@forall@skip@normal{0mu} + \def\mst@prime@skip@normal{0mu} + \def\mst@exists@skip@bold{0mu} + \def\mst@forall@skip@bold{0mu} + \def\mst@prime@skip@bold{0mu} + \else % not subdued + \ifmst@italic + \ifmst@frenchmath + \mst@exists@muskip\mst@exists@skip\relax + \mst@forall@muskip\mst@forall@skip\relax + \mst@prime@muskip\mst@prime@skip\relax + \else + \def\mst@exists@skip@normal{0mu} + \def\mst@forall@skip@normal{0mu} + \def\mst@prime@skip@normal{0mu} + \def\mst@exists@skip@bold{0mu} + \def\mst@forall@skip@bold{0mu} + \def\mst@prime@skip@bold{0mu} + \fi + \else + \mst@exists@muskip\mst@exists@skip\relax + \mst@forall@muskip\mst@forall@skip\relax + \mst@prime@muskip\mst@prime@skip\relax + \fi + \fi +%% v1.15f +\ifmst@nonormalbold\else + \SetMathAlphabet{\mathnormalbold}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@boldvariant@normal} + {\mst@ltshape@normal} + \SetMathAlphabet{\mathnormalbold}{bold}{\mst@encoding@bold} + {\mst@family@bold} + {\mst@boldvariant@bold} + {\mst@ltshape@bold} +\fi +%% v1.15f adds \ifmst@default.. checks +\ifmst@subdued\else + \SetSymbolFont{mtletterfont}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@normal} + {\mst@ltshape@normal} + \SetSymbolFont{mtletterfont}{bold} {\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@ltshape@bold} + \SetSymbolFont{mtoperatorfont}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@normal} + {\mst@shape@normal} + \SetSymbolFont{mtoperatorfont}{bold} {\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@shape@bold} +\ifmst@defaultbf\else + \SetMathAlphabet{\Mathbf}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@bold} + {\mst@shape@normal} + \SetMathAlphabet{\Mathbf}{bold}{\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@shape@bold} +\fi\ifmst@defaultit\else + \SetMathAlphabet{\Mathit}{normal}{\mst@encoding@normal} + {\mst@family@normal} + {\mst@series@normal} + {\mst@itdefault@normal} + \SetMathAlphabet{\Mathit}{bold}{\mst@encoding@bold} + {\mst@family@bold} + {\mst@series@bold} + {\mst@itdefault@bold} +\fi\ifmst@defaultsf\else + \SetMathAlphabet{\Mathsf}{normal}{\mst@encoding@normal} + {\mst@sfdefault@normal} + {\mst@series@normal} + {\mst@shape@normal} + \SetMathAlphabet{\Mathsf}{bold}{\mst@encoding@bold} + {\mst@sfdefault@bold} + {\mst@series@bold} + {\mst@shape@bold} +\fi\ifmst@defaulttt\else + \SetMathAlphabet{\Mathtt}{normal}{\mst@encoding@normal} + {\mst@ttdefault@normal} + {\mst@series@normal} + {\mst@shape@normal} + \SetMathAlphabet{\Mathtt}{bold}{\mst@encoding@bold} + {\mst@ttdefault@bold} + {\mst@series@bold} + {\mst@shape@bold} +\fi\fi % de \ifmst@subdued + \ifmst@needeuler + \SetSymbolFont{mteulervm}{bold}{U}{zeur}{\mst@boldvariant@normal}{n} + \SetMathAlphabet{\MathEulerBold}{normal} + {U}{zeur}{\mst@boldvariant@normal}{n} + \SetMathAlphabet{\MathEulerBold}{bold} + {U}{zeur}{\mst@boldvariant@normal}{n} + \fi + \ifmst@needsymbol\SetSymbolFont{mtpsymbol}{bold} + {U}{psy}{\mst@boldvariant@normal}{n} + \fi +\ifmst@subdued\else +\ifmst@LGRgreek + \SetSymbolFont{mtlgrfontlower}{normal}{LGR} + {\mst@greekfont}{\mst@series@normal}{\mst@greek@lsh} + \SetSymbolFont{mtlgrfontlower}{bold}{LGR} + {\mst@greekfont}{\mst@boldvariant@normal}{\mst@greek@lsh} + \SetSymbolFont{mtlgrfontupper}{normal}{LGR} + {\mst@greekfont}{\mst@series@normal}{\mst@greek@ush} + \SetSymbolFont{mtlgrfontupper}{bold}{LGR} + {\mst@greekfont}{\mst@boldvariant@bold}{\mst@greek@ush} + \else +\ifmst@selfGreek + \SetSymbolFont{mtselfGreekfont}{normal}{OT1} + {\mst@greekfont}{\mst@series@normal}{\mst@greek@ush} + \SetSymbolFont{mtselfGreekfont}{bold}{OT1} + {\mst@greekfont}{\mst@boldvariant@bold}{\mst@greek@ush} +\fi\fi\fi +\ifmst@subdued +\typeout{** subdued mode will be activated for the normal and bold math versions} +\else +\typeout{** Latin letters in the normal (resp. bold) math versions are now^^J% + ** set up to use the fonts +\mst@encoding@normal/\mst@family@normal/\mst@series@normal% +(\mst@boldvariant@normal)/\mst@ltshape@normal} +\ifmst@LGRgreek\typeout{** Greek letters (\mst@greek@lsh/\mst@greek@ush) +will use LGR/\mst@greekfont} +\fi +\ifmst@nodigits\else\typeout{** Other characters (digits, ...) +and \protect\log-like names will be^^J% +** typeset with the \mst@shape@normal\space shape.} +\fi +\fi +\else % optional argument, then we rather do DeclareVersion + \edef\mst@tmp{#1} + \ifx\mst@tmp\empty + \Mathastext % no infinite loop! + \else + \MTDeclareVersion[\mst@ltsh]{#1} + {\mst@enc}{\mst@fam}{\mst@ser}{\mst@opsh} + \fi +\fi +} +\@onlypreamble\Mathastext +\let\mathastext\Mathastext +\newcommand*\MTDeclareVersion[6][\empty]{ + \edef\mst@version{#2} + \DeclareMathVersion{\mst@version} + \expandafter\edef\csname mst@encoding@\mst@version\endcsname{#3} + \expandafter\edef\csname mst@family@\mst@version\endcsname{#4} + \expandafter\edef\csname mst@series@\mst@version\endcsname{#5} + \expandafter\edef\csname mst@shape@\mst@version\endcsname{#6} + \expandafter\edef\csname mst@boldvariant@\mst@version\endcsname{\mst@bold} + \expandafter\edef\csname mst@itdefault@\mst@version\endcsname{\itdefault} + \expandafter\edef\csname mst@rmdefault@\mst@version\endcsname{\rmdefault} + \expandafter\edef\csname mst@sfdefault@\mst@version\endcsname{\sfdefault} + \expandafter\edef\csname mst@ttdefault@\mst@version\endcsname{\ttdefault} + \expandafter\edef\csname mst@exists@skip@\mst@version\endcsname + {\mst@exists@skip} + \expandafter\edef\csname mst@forall@skip@\mst@version\endcsname + {\mst@forall@skip} + \expandafter\edef\csname mst@prime@skip@\mst@version\endcsname + {\mst@prime@skip} + \mst@optionalparamfalse + \ifx\empty#1 + \else % we check nevertheless for [] situation, will not work with [ ] + \def\mst@tmp{#1} + \ifx\mst@tmp\empty\else\mst@optionalparamtrue\fi + \fi + \ifmst@optionalparam + \SetSymbolFont{mtletterfont}{#2}{#3}{#4}{#5}{#1} + \typeout{** Latin letters in math version `#2\string' will use the font + #3/#4/#5/#1^^J% + ** Other characters (digits, ...) and \protect\log-like + names will be in #6 shape.} + \expandafter\edef\csname mst@ltshape@\mst@version\endcsname{#1} + \else + \ifmst@italic + \SetSymbolFont{mtletterfont}{#2}{#3}{#4}{#5}{\mst@ltsh} + \typeout{** Latin letters in math version `#2\string' will use the font + #3/#4/#5/\mst@ltsh^^J% + ** Other characters (digits, ...) and \protect\log-like names + will be in #6 shape.} + \expandafter\edef\csname mst@ltshape@\mst@version\endcsname{\mst@ltsh} + \else + \SetSymbolFont{mtletterfont}{#2}{#3}{#4}{#5}{#6} + \typeout{** Latin letters in math version `#2\string' will use the fonts + #3/#4/#5(\mst@bold)/#6} + \expandafter\edef\csname mst@ltshape@\mst@version\endcsname{#6} + \fi + \fi + \ifmst@nonormalbold\else + \SetMathAlphabet{\mathnormalbold}{#2}{#3}{#4}{\mst@bold} + {\csname + mst@ltshape@\mst@version\endcsname} + \fi + \SetSymbolFont{mtoperatorfont}{#2}{#3}{#4}{#5}{#6} + \ifmst@defaultbf\else\SetMathAlphabet{\Mathbf}{#2}{#3}{#4}{\mst@bold}{#6}\fi + \ifmst@defaultit\else\SetMathAlphabet{\Mathit}{#2}{#3}{#4}{#5}{\itdefault}\fi + \ifmst@defaultsf\else\SetMathAlphabet{\Mathsf}{#2}{#3}{\sfdefault}{#5}{#6}\fi + \ifmst@defaulttt\else\SetMathAlphabet{\Mathtt}{#2}{#3}{\ttdefault}{#5}{#6}\fi + \ifmst@needeuler + \SetMathAlphabet{\MathEulerBold}{#2}{U}{zeur}{\mst@bold}{n} + \fi + \def\mst@greek@lsh@loc{\csname mst@ltshape@\mst@version\endcsname} + \def\mst@greek@ush@loc{\csname mst@shape@\mst@version\endcsname} + \ifmst@itgreek\def\mst@greek@lsh@loc{\itdefault} + \def\mst@greek@ush@loc{\itdefault}\fi + \ifmst@upgreek\def\mst@greek@lsh@loc{\updefault} + \def\mst@greek@ush@loc{\updefault}\fi + \ifmst@frenchmath + \ifmst@itgreek\else + \ifmst@upgreek\else + \def\mst@greek@lsh@loc{\csname mst@shape@\mst@version\endcsname} + \def\mst@greek@ush@loc{\csname mst@shape@\mst@version\endcsname} + \fi\fi + \fi + \ifcase\mst@greek@select + \or\def\mst@greek@ush@loc{\itdefault} + \or\def\mst@greek@ush@loc{\updefault} + \fi + \ifmst@LGRgreeks + \SetSymbolFont{mtlgrfontlower}{#2}{LGR}{#4}{#5}{\mst@greek@lsh@loc} + \SetSymbolFont{mtlgrfontupper}{#2}{LGR}{#4}{#5}{\mst@greek@ush@loc} + \typeout{** Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) will use + LGR font #4} + \else + \ifmst@selfGreeks + \SetSymbolFont{mtselfGreekfont}{#2}{OT1}{#4}{#5}{\mst@greek@ush@loc} + \typeout{** Capital Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) + will use OT1 font #4} + \else + \ifmst@LGRgreek + \SetSymbolFont{mtlgrfontlower}{#2}{LGR}{\mst@greekfont}{#5}{\mst@greek@lsh@loc} + \SetSymbolFont{mtlgrfontupper}{#2}{LGR}{\mst@greekfont}{#5}{\mst@greek@ush@loc} + \typeout{** Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) will use + LGR font \mst@greekfont} + \else + \ifmst@selfGreek + \SetSymbolFont{mtselfGreekfont}{#2}{OT1}{\mst@greekfont}{#5}{\mst@greek@ush@loc} + \typeout{** Capital Greek letters (\mst@greek@lsh@loc/\mst@greek@ush@loc) + will use OT1 font \mst@greekfont} + \fi\fi\fi\fi +} +\@onlypreamble\MTDeclareVersion +\let\MathastextDeclareVersion\MTDeclareVersion +\newcommand*\MTVersion[2][\empty]{% + \mathversion{#2}% + \ifx\empty#1% no optional argument + \def\mst@tmp{#2}% + \else% we check nevertheless for [] situation, will not work with [ ] + \def\mst@tmpa{#1}% + \ifx\mst@tmpa\empty\def\mst@tmp{#2}% + \else\def\mst@tmp{#1}% + \fi% + \fi% + \usefont{\csname mst@encoding@\mst@tmp\endcsname}% + {\csname mst@family@\mst@tmp\endcsname}% + {\csname mst@series@\mst@tmp\endcsname}% + {\csname mst@shape@\mst@tmp\endcsname}% + \edef\mst@@encoding{\csname mst@encoding@\mst@tmp\endcsname}% + \renewcommand{\encodingdefault}{\mst@@encoding}% +%% some modifications for v1.15b + \edef\mst@@famdefault{\csname mst@family@\mst@tmp\endcsname}% + \renewcommand{\familydefault}{\mst@@famdefault}% + \edef\mst@@series{\csname mst@series@\mst@tmp\endcsname}% + \renewcommand{\mddefault}{\mst@@series}% + \edef\mst@@shape{\csname mst@shape@\mst@tmp\endcsname}% + \renewcommand{\shapedefault}{\mst@@shape}% + \edef\mst@@boldvariant{\csname mst@boldvariant@\mst@tmp\endcsname}% + \renewcommand{\bfdefault}{\mst@@boldvariant}% + \edef\mst@@itdefault{\csname mst@itdefault@\mst@tmp\endcsname}% + \renewcommand{\itdefault}{\mst@@itdefault}% + \edef\mst@@rmdefault{\csname mst@rmdefault@\mst@tmp\endcsname}% + \renewcommand{\rmdefault}{\mst@@rmdefault}% + \edef\mst@@sfdefault{\csname mst@sfdefault@\mst@tmp\endcsname}% + \renewcommand{\sfdefault}{\mst@@sfdefault}% + \edef\mst@@ttdefault{\csname mst@ttdefault@\mst@tmp\endcsname}% + \renewcommand{\ttdefault}{\mst@@ttdefault}% + \edef\mst@tmp{#2}% +%% v1.15e: muskips + \expandafter + \mst@exists@muskip\csname mst@exists@skip@\mst@tmp\endcsname\relax + \expandafter + \mst@forall@muskip\csname mst@forall@skip@\mst@tmp\endcsname\relax +%% v1.2: muskip for \cs{prime} + \expandafter + \mst@prime@muskip\csname mst@prime@skip@\mst@tmp\endcsname\relax +%% v1.2b: italic corrections except for italic/slanted (sic) letters, and of +%% course except in the subdued normal and bold math versions + \edef\mst@tmpa{\csname mst@ltshape@\mst@tmp\endcsname}% + \edef\mst@tmpb{\csname mst@shape@\mst@tmp\endcsname}% + \MTicinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@tmpa\MTnoicinmath\fi}% + \ifmst@frenchmath + \MTICinmath + \@for\mst@tmp:=it,sl\do{\ifx\mst@tmp\mst@tmpb\MTnoICinmath\fi}% + \fi +%% v1.15c: extending subdued to LGRgreek +%% v1.15f: subdueing math alphabets in a simpler way than in 1.15e +%% v1.2b: subdueing the activation of characters in math mode +%% v1.2d: special treatment of the asterisk + \MTmathoperatorsobeymathxx + \MTeasynonlettersobeymathxx + \ifmst@asterisk\let\mst@doasterisk\mst@@doasterisk\fi + \ifmst@subdued + \edef\mst@tmp{#2}\def\mst@tmpa{normal}% + \ifx\mst@tmp\mst@tmpa + \mst@restorealphabets + \MTmathoperatorsdonotobeymathxx + \MTnonlettersdonotobeymathxx + \MTeasynonlettersdonotobeymathxx + \MTnoicinmath + \ifmst@asterisk\let\mst@doasterisk\relax\fi + \ifmst@LGRgreek\mst@restoregreek\fi + \else + \def\mst@tmpa{bold}% + \ifx\mst@tmp\mst@tmpa + \mst@restorealphabets + \MTmathoperatorsdonotobeymathxx + \MTnonlettersdonotobeymathxx + \MTeasynonlettersdonotobeymathxx + \MTnoicinmath + \ifmst@asterisk\let\mst@doasterisk\relax\fi + \ifmst@LGRgreek\mst@restoregreek\fi + \else + \mst@setalphabets + \ifmst@LGRgreek\mst@setuplgrgreek\fi + \fi\fi\fi +} +\let\MathastextVersion\MTVersion +\let\Mathastextversion\MTVersion +\let\MTversion\MTVersion +\let\mathastextversion\MTVersion +\Mathastext +\ifmst@eulergreek + \typeout{** Greek letters will use the Euler font. Use^^J% +** \protect\MathastextEulerScale{} to scale the font.} +\else +\ifmst@symbolgreek + \typeout{** Greek letters will use the PostScript Symbol font. Use^^J% +** \protect\MathastextSymbolScale{} to scale the font.} +\fi\fi +\def\mst@DeclareMathSymbol#1#2#3#4{% + \DeclareMathSymbol{#1}{#2}{#3}{#4} + \expandafter\DeclareMathSymbol\csname mst@#1\endcsname{#2}{#3}{#4} + \expandafter\mst@addtodo@az + \expandafter#1\csname mst@#1\endcsname\mst@itcorr} +\mst@DeclareMathSymbol{a}{\mathalpha}{mtletterfont}{`a} +\mst@DeclareMathSymbol{b}{\mathalpha}{mtletterfont}{`b} +\mst@DeclareMathSymbol{c}{\mathalpha}{mtletterfont}{`c} +\mst@DeclareMathSymbol{d}{\mathalpha}{mtletterfont}{`d} +\mst@DeclareMathSymbol{e}{\mathalpha}{mtletterfont}{`e} +\mst@DeclareMathSymbol{f}{\mathalpha}{mtletterfont}{`f} +\mst@DeclareMathSymbol{g}{\mathalpha}{mtletterfont}{`g} +\mst@DeclareMathSymbol{h}{\mathalpha}{mtletterfont}{`h} +\mst@DeclareMathSymbol{i}{\mathalpha}{mtletterfont}{`i} +\mst@DeclareMathSymbol{j}{\mathalpha}{mtletterfont}{`j} +\mst@DeclareMathSymbol{k}{\mathalpha}{mtletterfont}{`k} +\mst@DeclareMathSymbol{l}{\mathalpha}{mtletterfont}{`l} +\mst@DeclareMathSymbol{m}{\mathalpha}{mtletterfont}{`m} +\mst@DeclareMathSymbol{n}{\mathalpha}{mtletterfont}{`n} +\mst@DeclareMathSymbol{o}{\mathalpha}{mtletterfont}{`o} +\mst@DeclareMathSymbol{p}{\mathalpha}{mtletterfont}{`p} +\mst@DeclareMathSymbol{q}{\mathalpha}{mtletterfont}{`q} +\mst@DeclareMathSymbol{r}{\mathalpha}{mtletterfont}{`r} +\mst@DeclareMathSymbol{s}{\mathalpha}{mtletterfont}{`s} +\mst@DeclareMathSymbol{t}{\mathalpha}{mtletterfont}{`t} +\mst@DeclareMathSymbol{u}{\mathalpha}{mtletterfont}{`u} +\mst@DeclareMathSymbol{v}{\mathalpha}{mtletterfont}{`v} +\mst@DeclareMathSymbol{w}{\mathalpha}{mtletterfont}{`w} +\mst@DeclareMathSymbol{x}{\mathalpha}{mtletterfont}{`x} +\mst@DeclareMathSymbol{y}{\mathalpha}{mtletterfont}{`y} +\mst@DeclareMathSymbol{z}{\mathalpha}{mtletterfont}{`z} +\ifmst@frenchmath\def\mst@font@tbu{mtoperatorfont} + \else\def\mst@font@tbu{mtletterfont}\fi +\def\mst@DeclareMathSymbol#1#2#3#4{% + \DeclareMathSymbol{#1}{#2}{#3}{#4} + \expandafter\DeclareMathSymbol\csname mst@#1\endcsname{#2}{#3}{#4} + \expandafter\mst@addtodo@AZ + \expandafter#1\csname mst@#1\endcsname\mst@ITcorr} +\mst@DeclareMathSymbol{A}{\mathalpha}{\mst@font@tbu}{`A} +\mst@DeclareMathSymbol{B}{\mathalpha}{\mst@font@tbu}{`B} +\mst@DeclareMathSymbol{C}{\mathalpha}{\mst@font@tbu}{`C} +\mst@DeclareMathSymbol{D}{\mathalpha}{\mst@font@tbu}{`D} +\mst@DeclareMathSymbol{E}{\mathalpha}{\mst@font@tbu}{`E} +\mst@DeclareMathSymbol{F}{\mathalpha}{\mst@font@tbu}{`F} +\mst@DeclareMathSymbol{G}{\mathalpha}{\mst@font@tbu}{`G} +\mst@DeclareMathSymbol{H}{\mathalpha}{\mst@font@tbu}{`H} +\mst@DeclareMathSymbol{I}{\mathalpha}{\mst@font@tbu}{`I} +\mst@DeclareMathSymbol{J}{\mathalpha}{\mst@font@tbu}{`J} +\mst@DeclareMathSymbol{K}{\mathalpha}{\mst@font@tbu}{`K} +\mst@DeclareMathSymbol{L}{\mathalpha}{\mst@font@tbu}{`L} +\mst@DeclareMathSymbol{M}{\mathalpha}{\mst@font@tbu}{`M} +\mst@DeclareMathSymbol{N}{\mathalpha}{\mst@font@tbu}{`N} +\mst@DeclareMathSymbol{O}{\mathalpha}{\mst@font@tbu}{`O} +\mst@DeclareMathSymbol{P}{\mathalpha}{\mst@font@tbu}{`P} +\mst@DeclareMathSymbol{Q}{\mathalpha}{\mst@font@tbu}{`Q} +\mst@DeclareMathSymbol{R}{\mathalpha}{\mst@font@tbu}{`R} +\mst@DeclareMathSymbol{S}{\mathalpha}{\mst@font@tbu}{`S} +\mst@DeclareMathSymbol{T}{\mathalpha}{\mst@font@tbu}{`T} +\mst@DeclareMathSymbol{U}{\mathalpha}{\mst@font@tbu}{`U} +\mst@DeclareMathSymbol{V}{\mathalpha}{\mst@font@tbu}{`V} +\mst@DeclareMathSymbol{W}{\mathalpha}{\mst@font@tbu}{`W} +\mst@DeclareMathSymbol{X}{\mathalpha}{\mst@font@tbu}{`X} +\mst@DeclareMathSymbol{Y}{\mathalpha}{\mst@font@tbu}{`Y} +\mst@DeclareMathSymbol{Z}{\mathalpha}{\mst@font@tbu}{`Z} +%% +\ifmst@nodigits\else +\def\mst@font@tbu{mtoperatorfont} +\ifmst@symboldigits \def\mst@font@tbu{mtpsymbol} \fi +\ifmst@eulerdigits \def\mst@font@tbu{mteulervm} \fi +\DeclareMathSymbol{0}{\mathalpha}{\mst@font@tbu}{`0} +\DeclareMathSymbol{1}{\mathalpha}{\mst@font@tbu}{`1} +\DeclareMathSymbol{2}{\mathalpha}{\mst@font@tbu}{`2} +\DeclareMathSymbol{3}{\mathalpha}{\mst@font@tbu}{`3} +\DeclareMathSymbol{4}{\mathalpha}{\mst@font@tbu}{`4} +\DeclareMathSymbol{5}{\mathalpha}{\mst@font@tbu}{`5} +\DeclareMathSymbol{6}{\mathalpha}{\mst@font@tbu}{`6} +\DeclareMathSymbol{7}{\mathalpha}{\mst@font@tbu}{`7} +\DeclareMathSymbol{8}{\mathalpha}{\mst@font@tbu}{`8} +\DeclareMathSymbol{9}{\mathalpha}{\mst@font@tbu}{`9} +\fi +\ifmst@symboldelimiters +\def\mst@font@tbu{mtpsymbol} +\mst@endashfalse +\mst@emdashfalse +\else +\def\mst@font@tbu{mtoperatorfont} +\fi +\ifmst@noexclam\else\typeout{** \string! and \string?} +\DeclareMathSymbol{!}{\mathclose}{\mst@font@tbu}{"21} +\DeclareMathSymbol{\mst@varfam@exclam}{\mathalpha}{\mst@font@tbu}{"21} +\expandafter\mst@addtodo@nonletters\string!\mathclose\mst@varfam@exclam +\DeclareMathSymbol{?}{\mathclose}{\mst@font@tbu}{"3F} +\DeclareMathSymbol{\mst@varfam@question}{\mathalpha}{\mst@font@tbu}{"3F} +\expandafter\mst@addtodo@nonletters\string?\mathclose\mst@varfam@question +\fi +\def\mst@@doasterisk{\let\ast\mst@ast\mst@mathactivate*{}\mst@ast} +\ifmst@asterisk\typeout{** asterisk: \string\ast\space and *} + \ifmst@symbolmisc + \def\mst@bin@ast{% + \mathbin{\mathchoice{\raisebox{-.1\height} + {\the\textfont\symmtpsymbol\char42}} + {\raisebox{-.1\height} + {\the\textfont\symmtpsymbol\char42}} + {\raisebox{-.1\height} + {\the\scriptfont\symmtpsymbol\char42}} + {\raisebox{-.1\height} + {\the\scriptscriptfont\symmtpsymbol\char42}}}} + \else + \def\mst@bin@ast{% + \mathbin{\mathchoice{\raisebox{-\mst@lowerast} + {\the\textfont\symmtoperatorfont\char42}} + {\raisebox{-\mst@lowerast} + {\the\textfont\symmtoperatorfont\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptfont\symmtoperatorfont\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptscriptfont\symmtoperatorfont\char42}}}} + \fi + \def\mst@varfam@ast{\ifnum\fam=\m@ne\mst@bin@ast\else + \mathbin{\mathchoice{\raisebox{-\mst@lowerast} + {\the\textfont\fam\char42}} + {\raisebox{-\mst@lowerast} + {\the\textfont\fam\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptfont\fam\char42}} + {\raisebox{-\mst@lowerast} + {\the\scriptscriptfont\fam\char42}}}\fi} + \let\mst@doasterisk\mst@@doasterisk + \DeclareRobustCommand*{\mst@ast}{\mst@bin@ast} + \newcommand*\MTlowerast[1]{\def\mst@lowerast{#1}} + \MTlowerast{.3\height} + \mst@do@easynonletters\expandafter{\the\mst@do@easynonletters + \expandafter\def\csname mst@ast \endcsname{\mst@varfam@ast}} +\fi +\ifmst@nopunct\else\typeout{** punctuation\string: \string, \string. \string: \string; and \string\colon} +\DeclareMathSymbol{,}{\mathpunct}{\mst@font@tbu}{"2C} +\DeclareMathSymbol{\mst@varfam@comma}{\mathalpha}{\mst@font@tbu}{"2C} +\expandafter\mst@addtodo@nonletters\string,\mathpunct\mst@varfam@comma +\DeclareMathSymbol{.}{\mathord}{\mst@font@tbu}{"2E} +\DeclareMathSymbol{\mst@varfam@dot}{\mathalpha}{\mst@font@tbu}{"2E} +\mst@addtodo@easynonletters\.\mst@varfam@dot +\DeclareMathSymbol{:}{\mathrel}{\mst@font@tbu}{"3A} % relation spacing +\DeclareMathSymbol{\mst@varfam@colon}{\mathalpha}{\mst@font@tbu}{"3A} +\expandafter\mst@addtodo@nonletters\string:\mathrel\mst@varfam@colon +\@ifpackageloaded{amsmath} +{} % \colon defined in amsmath.sty in terms of : with some enlarged explicit + % spacing. No need to intervene. +{% no amsmath, use standard punctuation spacing +\let\colon\undefined + % the reason is if some package has redefined \colon which then + % can not be used in \cs{DeclareMathSymbol} anymore (we + % shamelessly overwrite...) + \DeclareMathSymbol{\colon}{\mathpunct}{\mst@font@tbu}{"3A} + \mst@do@nonletters\expandafter{\the\mst@do@nonletters + \def\colon{\mathpunct{\mst@varfam@colon}}}} +\DeclareMathSymbol{;}{\mathpunct}{\mst@font@tbu}{"3B} +\DeclareMathSymbol{\mst@varfam@pointvirgule}{\mathalpha}{\mst@font@tbu}{"3B} +\expandafter\mst@addtodo@nonletters\string;\mathpunct\mst@varfam@pointvirgule +\fi +\ifmst@nominus\else +\ifmst@XeTeX +\XeTeXmathcharnumdef\mst@minus@sign=\XeTeXmathcodenum`\-\relax +\else +\ifmst@LuaTeX +%% \luatexUmathcharnumdef\mst@minus@sign=\luatexUmathcodenum`\-\relax ne +%% marche pas pour le moment car \luatexUmathcodenum retourne parfois un +%% legacy mathcode, parfois un Unicode mathcode, \`a mon avis c'est un bug +%% de LuaLatex. En fait Taco H me dit que la prochaine version +%% r\'eglera ce probl\`eme. \luatexUmathchardef\mst@minus@sign="2 "2 "0\relax +\mathchardef\mst@minus@sign=8704\relax % "2200 +\else +\mathchardef\mst@minus@sign=\mathcode`\-\relax +\fi\fi +\@ifpackageloaded{amsmath} +{\def\relbar{\mathrel{\mathpalette\mathsm@sh\mst@minus@sign}}} +{\DeclareRobustCommand\relbar{\mathrel{\smash\mst@minus@sign}}} +\def\rightarrowfill{$\m@th\mathord{\relbar}\mkern-7mu% + \cleaders\hbox{$\mkern-2mu\relbar\mkern-2mu$}\hfill + \mkern-7mu\mathord\rightarrow$} +\def\leftarrowfill{$\m@th\mathord\leftarrow\mkern-7mu% + \cleaders\hbox{$\mkern-2mu\relbar\mkern-2mu$}\hfill + \mkern-7mu\mathord{\relbar}$} +\fi +\def\do@the@endashstuff{\edef\mst@tmp@enc{\encodingdefault} + \ifx\mst@tmp@enc\mst@eui % xetex+fontspec + \AtBeginDocument{% + \XeTeXmathcode`\-="2 \symmtoperatorfont "2013\relax + \XeTeXmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2013\relax + } +\else + \ifx\mst@tmp@enc\mst@euii % luatex+fontspec + \AtBeginDocument{% + \luatexUmathcode`\-="2 \symmtoperatorfont "2013\relax + \luatexUmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2013\relax + } +\else + \ifx\mst@tmp@enc\mst@ti % T1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{21} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{21} +\else + \ifx\mst@tmp@enc\mst@oti % OT1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{123} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{123} +\else + \ifx\mst@tmp@enc\mst@lyi % LY1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{150} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{150} +\else % make sure we have neither xetex nor luatex + \ifmst@XeTeX\mst@aborttrue\else\ifmst@LuaTeX\mst@aborttrue\else + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\textendash\endcsname} + \fi\fi +\fi\fi\fi\fi\fi} +\def\do@the@emdashstuff{\edef\mst@tmp@enc{\encodingdefault} +\ifx\mst@tmp@enc\mst@eui % xetex+fontspec + \AtBeginDocument{% + \XeTeXmathcode`\-="2 \symmtoperatorfont "2014\relax + \XeTeXmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2014\relax + } +\else +\ifx\mst@tmp@enc\mst@euii % luatex+fontspec + \AtBeginDocument{% + \luatexUmathcode`\-="2 \symmtoperatorfont "2014\relax + \luatexUmathchardef\mst@varfam@minus="7 \symmtoperatorfont "2014\relax + } +\else + \ifx\mst@tmp@enc\mst@ti % T1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{22} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{22} +\else +\ifx\mst@tmp@enc\mst@oti % OT1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{124} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{124} +\else +\ifx\mst@tmp@enc\mst@lyi % LY1 + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont}{151} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont}{151} +\else % make sure we have neither xetex nor luatex + \ifmst@XeTeX\mst@aborttrue\else\ifmst@LuaTeX\mst@aborttrue\else + \DeclareMathSymbol{-}{\mathbin}{mtoperatorfont} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{mtoperatorfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\textemdash\endcsname} + \fi\fi +\fi\fi\fi\fi\fi} +\ifmst@nominus\else\typeout{** minus as endash} +\mst@abortfalse +\ifmst@endash\do@the@endashstuff\else +\ifmst@emdash\do@the@emdashstuff\else + \DeclareMathSymbol{-}{\mathbin}{\mst@font@tbu}{"2D} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{\mst@font@tbu}{"2D} +\fi\fi +\ifmst@abort + \DeclareMathSymbol{-}{\mathbin}{\mst@font@tbu}{"2D} + \DeclareMathSymbol{\mst@varfam@minus}{\mathalpha}{\mst@font@tbu}{"2D} +\fi +\expandafter\mst@addtodo@nonletters\string-\mathbin\mst@varfam@minus +\fi +%%\def\hbar{{\mathchar'26\mkern-9muh}} % (original definition from latex.ltx) +\def\mst@mathrlap{\mathpalette\mst@mathrlapinternal} +\def\mst@mathrlapinternal#1#2{\rlap{$\mathsurround=0pt#1{#2}$}} +\def\do@the@hbarstuff{\edef\mst@tmp@enc{\encodingdefault} +\ifx\mst@tmp@enc\mst@eui % xetex and unicode font + \XeTeXmathchardef\hbar="7 \symmtletterfont "0127 \relax +\else +\ifx\mst@tmp@enc\mst@euii % luatex and unicode font + \luatexUmathchardef\hbar="7 \symmtletterfont "0127 \relax %% or 210F? +\else % I must leave open the T1, OT1 possibility also for XeTeX or LuaTeX + \ifx\mst@ti\mst@tmp@enc + \DeclareMathAccent{\mst@ltbar}{\mathalpha}{mtletterfont}{9} + \else %% assume OT1. Bad idea? Should not provoke an error anyhow + \DeclareMathAccent{\mst@ltbar}{\mathalpha}{mtletterfont}{22} + \fi + \def\hbar{\mst@mathrlap{\mst@ltbar{\ }}h} +\fi\fi} +\ifmst@nohbar\else\typeout{** \string\hbar}\do@the@hbarstuff\fi +\ifmst@noplus\else\typeout{** \string+ and \string=} +\DeclareMathSymbol{+}{\mathbin}{\mst@font@tbu}{"2B} +\DeclareMathSymbol{\mst@varfam@plus}{\mathalpha}{\mst@font@tbu}{"2B} +\expandafter\mst@addtodo@nonletters\string+\mathbin\mst@varfam@plus +\fi +\ifmst@noequal\else +\ifmst@XeTeX +\XeTeXmathcharnumdef\mst@equal@sign=\XeTeXmathcodenum`\=\relax +\else +\ifmst@LuaTeX +%% 12 octobre 2012 \luatexUmathcodenum`\= +%% ne marche pas pour le moment \`a cause du fait que \luatexUmathcodenum +%% donne un mathcode sur 8bit ou un Unicode mathcode sans qu'on puisse +%% savoir lequel +%% \luatexUmathchardef\mst@equal@sign="3 "0 "3D\relax +\mathchardef\mst@equal@sign=12349\relax +\else +\mathchardef\mst@equal@sign=\mathcode`\=\relax +\fi\fi +\@ifpackageloaded{amsmath} +{\def\Relbar{\mathrel\mst@equal@sign}} +{\DeclareRobustCommand\Relbar{\mathrel{\mst@equal@sign}}} +\DeclareMathSymbol{=}{\mathrel}{\mst@font@tbu}{"3D} +\DeclareMathSymbol{\mst@varfam@equal}{\mathalpha}{\mst@font@tbu}{"3D} +\typeout{** adding \string= \string; and \string+ to \string\nfss@catcodes} +\g@addto@macro\nfss@catcodes{% + \@makeother\=% + \@makeother\;% + \@makeother\+% +} +\expandafter\mst@addtodo@nonletters\string=\mathrel\mst@varfam@equal +\fi +\ifmst@noparen\else\typeout{** parentheses \string( \string) \string[ \string] and slash \string/} +\ifmst@nosmalldelims + \DeclareMathSymbol{(}{\mathopen}{\mst@font@tbu}{"28} + \DeclareMathSymbol{)}{\mathclose}{\mst@font@tbu}{"29} + \DeclareMathSymbol{[}{\mathopen} {\mst@font@tbu}{"5B} + \DeclareMathSymbol{]}{\mathclose}{\mst@font@tbu}{"5D} + \DeclareMathSymbol{/}{\mathord}{\mst@font@tbu}{"2F} +\else + \DeclareMathDelimiter{(}{\mathopen}{\mst@font@tbu}{"28}{largesymbols}{"00} + \DeclareMathDelimiter{)}{\mathclose}{\mst@font@tbu}{"29}{largesymbols}{"01} + \DeclareMathDelimiter{[}{\mathopen} {\mst@font@tbu}{"5B}{largesymbols}{"02} + \DeclareMathDelimiter{]}{\mathclose}{\mst@font@tbu}{"5D}{largesymbols}{"03} + \DeclareMathDelimiter{/}{\mathord}{\mst@font@tbu}{"2F}{largesymbols}{"0E} +\fi +\DeclareMathSymbol{\mst@varfam@lparen}{\mathalpha}{\mst@font@tbu}{40} +\DeclareMathSymbol{\mst@varfam@rparen}{\mathalpha}{\mst@font@tbu}{41} +\DeclareMathSymbol{\mst@varfam@lbrack}{\mathalpha}{\mst@font@tbu}{"5B} +\DeclareMathSymbol{\mst@varfam@rbrack}{\mathalpha}{\mst@font@tbu}{"5D} +\DeclareMathSymbol{\mst@varfam@slash}{\mathalpha}{\mst@font@tbu}{"2F} +\expandafter\mst@addtodo@nonletters\string(\mathopen\mst@varfam@lparen +\expandafter\mst@addtodo@nonletters\string)\mathclose\mst@varfam@rparen +\expandafter\mst@addtodo@nonletters\string[\mathopen\mst@varfam@lbrack +\expandafter\mst@addtodo@nonletters\string]\mathclose\mst@varfam@rbrack +\mst@addtodo@easynonletters\/\mst@varfam@slash +\fi +\ifmst@alldelims\typeout{** alldelims: \string< \string> + \string\backslash\space\string\setminus\space| + \string\vert\space\string\mid\space\string\{\space and \string\}} +\ifmst@nosmalldelims + \DeclareMathDelimiter{\mst@varfam@backslash} + {\mathalpha}{symbols}{"6E}{largesymbols}{"0F} +\else + \DeclareMathDelimiter{<}{\mathopen}{\mst@font@tbu}{"3C}{largesymbols}{"0A} + \DeclareMathDelimiter{>}{\mathclose}{\mst@font@tbu}{"3E}{largesymbols}{"0B} + \expandafter\DeclareMathDelimiter\@backslashchar + {\mathord}{mtoperatorfont}{"5C}{largesymbols}{"0F} + \DeclareMathDelimiter{\backslash} + {\mathord}{mtoperatorfont}{"5C}{largesymbols}{"0F} + \DeclareMathDelimiter{\mst@varfam@backslash} + {\mathalpha}{mtoperatorfont}{"5C}{largesymbols}{"0F} +\fi +\DeclareMathSymbol{<}{\mathrel}{\mst@font@tbu}{"3C} +\DeclareMathSymbol{>}{\mathrel}{\mst@font@tbu}{"3E} +\DeclareMathSymbol{\mst@varfam@less}{\mathalpha}{\mst@font@tbu}{"3C} +\DeclareMathSymbol{\mst@varfam@more}{\mathalpha}{\mst@font@tbu}{"3E} +\expandafter\mst@addtodo@nonletters\string<\mathrel\mst@varfam@less +\expandafter\mst@addtodo@nonletters\string>\mathrel\mst@varfam@more +\mst@do@easynonletters\expandafter{\the\mst@do@easynonletters + \let\backslash\mst@varfam@backslash} +\DeclareMathSymbol{\setminus}{\mathbin}{mtoperatorfont}{"5C} +\DeclareMathSymbol{\mst@varfam@setminus}{\mathalpha}{mtoperatorfont}{"5C} +\mst@do@nonletters\expandafter{\the\mst@do@nonletters + \def\setminus{\mathbin{\mst@varfam@setminus}}} +\ifmst@XeTeX +\XeTeXmathcharnumdef\mst@vert@bar=\XeTeXmathcodenum`\|\relax +\else +\ifmst@LuaTeX +%% \luatexUmathchardef\mst@vert@bar="0 "2 "006A\relax +\mathchardef\mst@vert@bar=618\relax +\else\mathchardef\mst@vert@bar=\mathcode`\|\relax +\fi\fi +\DeclareRobustCommand\models{\mathrel{\mst@vert@bar}\joinrel\Relbar} +\ifmst@nosmalldelims + \DeclareMathSymbol{|}{\mathord}{\mst@font@tbu}{124} +\else + \DeclareMathDelimiter{|}{\mathord}{\mst@font@tbu}{124}{largesymbols}{"0C} +\fi +\def\vert{|} +\DeclareMathSymbol{\mst@varfam@vbar}{\mathalpha}{\mst@font@tbu}{124} +\mst@addtodo@easynonletters\|\mst@varfam@vbar +\DeclareMathSymbol{\mid}{\mathrel}{\mst@font@tbu}{124} +\mst@do@nonletters\expandafter{\the\mst@do@nonletters + \def\mid{\mathrel\mst@varfam@vbar}} +\ifmst@nosmalldelims + \DeclareMathSymbol{\lbrace}{\mathopen}{\mst@font@tbu}{123} + \DeclareMathSymbol{\rbrace}{\mathclose}{\mst@font@tbu}{125} +\else + \DeclareMathDelimiter{\lbrace} + {\mathopen}{\mst@font@tbu}{123}{largesymbols}{"08} + \DeclareMathDelimiter{\rbrace} + {\mathclose}{\mst@font@tbu}{125}{largesymbols}{"09} +\fi +\DeclareMathSymbol{\mst@varfam@lbrace}{\mathalpha}{\mst@font@tbu}{123} +\DeclareMathSymbol{\mst@varfam@rbrace}{\mathalpha}{\mst@font@tbu}{125} +\DeclareRobustCommand*{\mst@lbrace} + {\ifmmode\mathopen\mst@varfam@lbrace\else\textbraceleft\fi} +\DeclareRobustCommand*{\mst@rbrace} + {\ifmmode\mathclose\mst@varfam@rbrace\else\textbraceright\fi} +\mst@do@nonletters\expandafter{\the\mst@do@nonletters + \mst@dobraces{\let\{\mst@lbrace\let\}\mst@rbrace}} +\fi % end of \ifmst@alldelims +\newcommand*{\MTexplicitbracesobeymathxx}{\let\mst@dobraces\@firstofone} +\newcommand*{\MTexplicitbracesdonotobeymathxx}{\let\mst@dobraces\@gobble} +\MTexplicitbracesdonotobeymathxx +\ifmst@nospecials\else\typeout{** \string\#\space\string\mathdollar\space\string\%\space\string\&\space} +\count255=\symmtoperatorfont +\multiply\count255 by 256 +\advance\count255 by 35 + \mathcode`\#\count255 +\advance\count255 by 1 + \mathchardef\mathdollar\count255 +\advance\count255 by 1 + \mathcode`\%\count255 +\advance\count255 by 1 + \mathcode`\&\count255 +\count255=\symmtoperatorfont +\multiply\count255 by 256 +\advance\count255 by 28707 % = "7023 + \mathchardef\mst@varfam@mathhash\count255 +\advance\count255 by 1 + \mathchardef\mst@varfam@mathdollar\count255 +\advance\count255 by 1 + \mathchardef\mst@varfam@mathpercent\count255 +\advance\count255 by 1 + \mathchardef\mst@varfam@mathampersand\count255 +\mst@do@easynonletters\expandafter{\the\mst@do@easynonletters + \mathcode`\#=\mst@varfam@mathhash + \let\mathdollar\mst@varfam@mathdollar + \mathcode`\%=\mst@varfam@mathpercent + \mathcode`\&=\mst@varfam@mathampersand} +\fi +\ifmst@symbolmisc\typeout{** symbolmisc: miscellaneous math symbols from Symbol font} +\let\mst@prod\prod +\let\defaultprod\prod +\DeclareMathSymbol{\prodpsy}{\mathop}{mtpsymbol}{213} +\renewcommand*{\prod}{\ifinner\prodpsy\else\mst@prod\fi} +\let\mst@sum\sum +\let\defaultsum\sum +\DeclareMathSymbol{\sumpsy}{\mathop}{mtpsymbol}{229} +\renewcommand*{\sum}{\ifinner\sumpsy\else\mst@sum\fi} +\DeclareMathSymbol{\mst@implies}{\mathrel}{mtpsymbol}{222} +\DeclareRobustCommand*{\implies}{\;\mst@implies\;} +\DeclareMathSymbol{\mst@impliedby}{\mathrel}{mtpsymbol}{220} +\DeclareRobustCommand*{\impliedby}{\;\mst@impliedby\;} +\DeclareRobustCommand*{\iff}{\;\mst@impliedby\mathrel{\mkern-3mu}\mst@implies\;} +\DeclareMathSymbol{\mst@iff}{\mathrel}{mtpsymbol}{219} +\DeclareRobustCommand*{\shortiff}{\;\mst@iff\;} +\DeclareMathSymbol{\mst@to}{\mathrel}{mtpsymbol}{174} +\DeclareMathSymbol{\mst@trait}{\mathrel}{mtpsymbol}{190} +\DeclareRobustCommand*\to{\mst@to} +\DeclareRobustCommand*\longto{\mkern2mu\mst@trait\mathrel{\mkern-10mu}\mst@to} +\DeclareRobustCommand*\mapsto{\mapstochar\mathrel{\mkern0.2mu}\mst@to} +\DeclareRobustCommand*\longmapsto{% +\mapstochar\mathrel{\mkern2mu}\mst@trait\mathrel{\mkern-10mu}\mst@to} +\DeclareMathSymbol{\aleph}{\mathord}{mtpsymbol}{192} +\DeclareMathSymbol{\inftypsy}{\mathord}{mtpsymbol}{165} +\DeclareMathSymbol{\emptyset}{\mathord}{mtpsymbol}{198} +\let\varnothing\emptyset +\DeclareMathSymbol{\nabla}{\mathord}{mtpsymbol}{209} +\DeclareMathSymbol{\surd}{\mathop}{mtpsymbol}{214} +\let\angle\undefined +\DeclareMathSymbol{\angle}{\mathord}{mtpsymbol}{208} +\DeclareMathSymbol{\forall}{\mathord}{mtpsymbol}{34} +\DeclareMathSymbol{\exists}{\mathord}{mtpsymbol}{36} +\DeclareMathSymbol{\neg}{\mathord}{mtpsymbol}{216} +\DeclareMathSymbol{\clubsuit}{\mathord}{mtpsymbol}{167} +\DeclareMathSymbol{\diamondsuit}{\mathord}{mtpsymbol}{168} +\DeclareMathSymbol{\heartsuit}{\mathord}{mtpsymbol}{169} +\DeclareMathSymbol{\spadesuit}{\mathord}{mtpsymbol}{170} +\DeclareMathSymbol{\smallint}{\mathop}{mtpsymbol}{242} +\DeclareMathSymbol{\wedge}{\mathbin}{mtpsymbol}{217} +\DeclareMathSymbol{\vee}{\mathbin}{mtpsymbol}{218} +\DeclareMathSymbol{\cap}{\mathbin}{mtpsymbol}{199} +\DeclareMathSymbol{\cup}{\mathbin}{mtpsymbol}{200} +\DeclareMathSymbol{\bullet}{\mathbin}{mtpsymbol}{183} +\DeclareMathSymbol{\div}{\mathbin}{mtpsymbol}{184} +\DeclareMathSymbol{\otimes}{\mathbin}{mtpsymbol}{196} +\DeclareMathSymbol{\oplus}{\mathbin}{mtpsymbol}{197} +\DeclareMathSymbol{\pm}{\mathbin}{mtpsymbol}{177} +\DeclareMathSymbol{\times}{\mathbin}{mtpsymbol}{180} +\DeclareMathSymbol{\proptopsy}{\mathrel}{mtpsymbol}{181} +\DeclareMathSymbol{\mid}{\mathrel}{mtpsymbol}{124} +\DeclareMathSymbol{\leq}{\mathrel}{mtpsymbol}{163} +\DeclareMathSymbol{\geq}{\mathrel}{mtpsymbol}{179} +\DeclareMathSymbol{\approx}{\mathrel}{mtpsymbol}{187} +\DeclareMathSymbol{\supset}{\mathrel}{mtpsymbol}{201} +\DeclareMathSymbol{\subset}{\mathrel}{mtpsymbol}{204} +\DeclareMathSymbol{\supseteq}{\mathrel}{mtpsymbol}{202} +\DeclareMathSymbol{\subseteq}{\mathrel}{mtpsymbol}{205} +\DeclareMathSymbol{\in}{\mathrel}{mtpsymbol}{206} +\DeclareMathSymbol{\sim}{\mathrel}{mtpsymbol}{126} +\let\cong\undefined +\DeclareMathSymbol{\cong}{\mathrel}{mtpsymbol}{64} +\DeclareMathSymbol{\perp}{\mathrel}{mtpsymbol}{94} +\DeclareMathSymbol{\equiv}{\mathrel}{mtpsymbol}{186} +\let\notin\undefined +\DeclareMathSymbol{\notin}{\mathrel}{mtpsymbol}{207} +\DeclareMathDelimiter{\rangle} + {\mathclose}{mtpsymbol}{241}{largesymbols}{"0B} +\DeclareMathDelimiter{\langle} + {\mathopen}{mtpsymbol}{225}{largesymbols}{"0A} +\fi +\ifmst@symbolre\typeout{** symbolre: \string\Re\space and \string\Im\space from Symbol font} +\DeclareMathSymbol{\Re}{\mathord}{mtpsymbol}{"C2} +\DeclareMathSymbol{\Im}{\mathord}{mtpsymbol}{"C1} +\DeclareMathSymbol{\DotTriangle}{\mathord}{mtpsymbol}{92} +\fi +\let\mst@mathord\mathalpha +\mst@goaheadtrue +\ifmst@selfGreek + \def\mst@font@tbu{mtselfGreekfont} + \else +\ifmst@eulergreek + \def\mst@font@tbu{mteulervm} + \else +\ifmst@symbolgreek + \def\mst@font@tbu{mtpsymbol} + \let\mst@mathord\mathord + \else +\ifmst@LGRgreek + \mst@goaheadfalse + \else + \mst@goaheadfalse + \ifx\omicron\undefined + \newcommand*{\omicron}{\mst@alph@omicron{o}} + \fi +\fi\fi\fi\fi +\ifmst@goahead +\DeclareMathSymbol{\Alpha}{\mst@mathord}{\mst@font@tbu}{"41} +\DeclareMathSymbol{\Beta}{\mst@mathord}{\mst@font@tbu}{"42} +\DeclareMathSymbol{\Epsilon}{\mst@mathord}{\mst@font@tbu}{"45} +\DeclareMathSymbol{\Zeta}{\mst@mathord}{\mst@font@tbu}{"5A} +\DeclareMathSymbol{\Eta}{\mst@mathord}{\mst@font@tbu}{"48} +\DeclareMathSymbol{\Iota}{\mst@mathord}{\mst@font@tbu}{"49} +\DeclareMathSymbol{\Kappa}{\mst@mathord}{\mst@font@tbu}{"4B} +\DeclareMathSymbol{\Mu}{\mst@mathord}{\mst@font@tbu}{"4D} +\DeclareMathSymbol{\Nu}{\mst@mathord}{\mst@font@tbu}{"4E} +\DeclareMathSymbol{\Omicron}{\mst@mathord}{\mst@font@tbu}{"4F} +\DeclareMathSymbol{\Rho}{\mst@mathord}{\mst@font@tbu}{"50} +\DeclareMathSymbol{\Tau}{\mst@mathord}{\mst@font@tbu}{"54} +\DeclareMathSymbol{\Chi}{\mst@mathord}{\mst@font@tbu}{"58} +\ifx\mst@mathord\mathord +%% attention le P de Symbol est un \Pi pas un \Rho +\DeclareMathSymbol{\Rho}{\mathord}{mtpsymbol}{"52} +%% attention le X de Symbol est un \Xi pas un \Chi +\DeclareMathSymbol{\Chi}{\mathord}{mtpsymbol}{"43} +%% attention le F de Symbol est un \Phi. Il n'y a pas de \Digamma +\DeclareMathSymbol{\Gamma}{\mathord}{mtpsymbol}{"47} +\DeclareMathSymbol{\Delta}{\mathord}{mtpsymbol}{"44} +\DeclareMathSymbol{\Theta}{\mathord}{mtpsymbol}{"51} +\DeclareMathSymbol{\Lambda}{\mathord}{mtpsymbol}{"4C} +\DeclareMathSymbol{\Xi}{\mathord}{mtpsymbol}{"58} +\DeclareMathSymbol{\Pi}{\mathord}{mtpsymbol}{"50} +\DeclareMathSymbol{\Sigma}{\mathord}{mtpsymbol}{"53} +\DeclareMathSymbol{\Upsilon}{\mathord}{mtpsymbol}{"A1} +\DeclareMathSymbol{\Phi}{\mathord}{mtpsymbol}{"46} +\DeclareMathSymbol{\Psi}{\mathord}{mtpsymbol}{"59} +\DeclareMathSymbol{\Omega}{\mathord}{mtpsymbol}{"57} +\else +\DeclareMathSymbol{\Digamma}{\mathalpha}{\mst@font@tbu}{"46} +\DeclareMathSymbol\Gamma {\mathalpha}{\mst@font@tbu}{"00} +\DeclareMathSymbol\Delta {\mathalpha}{\mst@font@tbu}{"01} +\DeclareMathSymbol\Theta {\mathalpha}{\mst@font@tbu}{"02} +\DeclareMathSymbol\Lambda {\mathalpha}{\mst@font@tbu}{"03} +\DeclareMathSymbol\Xi {\mathalpha}{\mst@font@tbu}{"04} +\DeclareMathSymbol\Pi {\mathalpha}{\mst@font@tbu}{"05} +\DeclareMathSymbol\Sigma {\mathalpha}{\mst@font@tbu}{"06} +\DeclareMathSymbol\Upsilon {\mathalpha}{\mst@font@tbu}{"07} +\DeclareMathSymbol\Phi {\mathalpha}{\mst@font@tbu}{"08} +\DeclareMathSymbol\Psi {\mathalpha}{\mst@font@tbu}{"09} +\DeclareMathSymbol\Omega {\mathalpha}{\mst@font@tbu}{"0A} +\fi +\fi +\ifmst@goahead +\ifmst@eulergreek +\DeclareMathSymbol{\alpha} {\mathalpha}{mteulervm}{"0B} +\DeclareMathSymbol{\beta} {\mathalpha}{mteulervm}{"0C} +\DeclareMathSymbol{\gamma} {\mathalpha}{mteulervm}{"0D} +\DeclareMathSymbol{\delta} {\mathalpha}{mteulervm}{"0E} +\DeclareMathSymbol{\epsilon}{\mathalpha}{mteulervm}{"0F} +\DeclareMathSymbol{\zeta} {\mathalpha}{mteulervm}{"10} +\DeclareMathSymbol{\eta} {\mathalpha}{mteulervm}{"11} +\DeclareMathSymbol{\theta} {\mathalpha}{mteulervm}{"12} +\DeclareMathSymbol{\iota} {\mathalpha}{mteulervm}{"13} +\DeclareMathSymbol{\kappa} {\mathalpha}{mteulervm}{"14} +\DeclareMathSymbol{\lambda} {\mathalpha}{mteulervm}{"15} +\DeclareMathSymbol{\mu} {\mathalpha}{mteulervm}{"16} +\DeclareMathSymbol{\nu} {\mathalpha}{mteulervm}{"17} +\DeclareMathSymbol{\xi} {\mathalpha}{mteulervm}{"18} +\let\omicron\undefined +\DeclareMathSymbol{\omicron}{\mathalpha}{mteulervm}{"6F} +\DeclareMathSymbol{\pi} {\mathalpha}{mteulervm}{"19} +\DeclareMathSymbol{\rho} {\mathalpha}{mteulervm}{"1A} +\DeclareMathSymbol{\sigma} {\mathalpha}{mteulervm}{"1B} +\DeclareMathSymbol{\tau} {\mathalpha}{mteulervm}{"1C} +\DeclareMathSymbol{\upsilon}{\mathalpha}{mteulervm}{"1D} +\DeclareMathSymbol{\phi} {\mathalpha}{mteulervm}{"1E} +\DeclareMathSymbol{\chi} {\mathalpha}{mteulervm}{"1F} +\DeclareMathSymbol{\psi} {\mathalpha}{mteulervm}{"20} +\DeclareMathSymbol{\omega} {\mathalpha}{mteulervm}{"21} +\DeclareMathSymbol{\varepsilon}{\mathalpha}{mteulervm}{"22} +\DeclareMathSymbol{\vartheta}{\mathalpha}{mteulervm}{"23} +\DeclareMathSymbol{\varpi} {\mathalpha}{mteulervm}{"24} +\let\varrho=\rho +\let\varsigma=\sigma +\DeclareMathSymbol{\varphi} {\mathalpha}{mteulervm}{"27} +\DeclareMathSymbol{\partial}{\mathalpha}{mteulervm}{"40} +\DeclareMathSymbol{\wp}{\mathalpha}{mteulervm}{"7D} +\DeclareMathSymbol{\ell}{\mathalpha}{mteulervm}{"60} +\else +\ifmst@symbolgreek +\DeclareMathSymbol{\alpha}{\mathord}{mtpsymbol}{"61} +\DeclareMathSymbol{\beta}{\mathord}{mtpsymbol}{"62} +\DeclareMathSymbol{\gamma}{\mathord}{mtpsymbol}{"67} +\DeclareMathSymbol{\delta}{\mathord}{mtpsymbol}{"64} +\DeclareMathSymbol{\epsilon}{\mathord}{mtpsymbol}{"65} +\DeclareMathSymbol{\zeta}{\mathord}{mtpsymbol}{"7A} +\DeclareMathSymbol{\eta}{\mathord}{mtpsymbol}{"68} +\DeclareMathSymbol{\theta}{\mathord}{mtpsymbol}{"71} +\DeclareMathSymbol{\iota}{\mathord}{mtpsymbol}{"69} +\DeclareMathSymbol{\kappa}{\mathord}{mtpsymbol}{"6B} +\DeclareMathSymbol{\lambda}{\mathord}{mtpsymbol}{"6C} +\DeclareMathSymbol{\mu}{\mathord}{mtpsymbol}{"6D} +\DeclareMathSymbol{\nu}{\mathord}{mtpsymbol}{"6E} +\DeclareMathSymbol{\xi}{\mathord}{mtpsymbol}{"78} +\let\omicron\undefined +\DeclareMathSymbol{\omicron}{\mathord}{mtpsymbol}{"6F} +\DeclareMathSymbol{\pi}{\mathord}{mtpsymbol}{"70} +\DeclareMathSymbol{\rho}{\mathord}{mtpsymbol}{"72} +\DeclareMathSymbol{\sigma}{\mathord}{mtpsymbol}{"73} +\DeclareMathSymbol{\tau}{\mathord}{mtpsymbol}{"74} +\DeclareMathSymbol{\upsilon}{\mathord}{mtpsymbol}{"75} +\DeclareMathSymbol{\phi}{\mathord}{mtpsymbol}{"66} +\DeclareMathSymbol{\chi}{\mathord}{mtpsymbol}{"63} +\DeclareMathSymbol{\psi}{\mathord}{mtpsymbol}{"79} +\DeclareMathSymbol{\omega}{\mathord}{mtpsymbol}{"77} +\let\varepsilon=\epsilon +\DeclareMathSymbol{\vartheta}{\mathord}{mtpsymbol}{"4A} +\DeclareMathSymbol{\varpi}{\mathord}{mtpsymbol}{"76} +\let\varrho=\rho +\DeclareMathSymbol{\varsigma}{\mathord}{mtpsymbol}{"56} +\DeclareMathSymbol{\varphi}{\mathord}{mtpsymbol}{"6A} +\DeclareMathSymbol{\partial}{\mathord}{mtpsymbol}{"B6} +\DeclareMathSymbol{\wp}{\mathord}{mtpsymbol}{"C3} +\fi\fi\fi +%% +\ifmst@LGRgreek % internal names for subdued implementation (1.15c-1.15e) +\let\mst@origAlpha\Alpha +\let\mst@origBeta\Beta +\let\mst@origGamma\Gamma +\let\mst@origDelta\Delta +\let\mst@origEpsilon\Epsilon +\let\mst@origZeta\Zeta +\let\mst@origEta\Eta +\let\mst@origTheta\Theta +\let\mst@origIota\Iota +\let\mst@origKappa\Kappa +\let\mst@origLambda\Lambda +\let\mst@origMu\Mu +\let\mst@origNu\Nu +\let\mst@origXi\Xi +\let\mst@origOmicron\Omicron +\let\mst@origPi\Pi +\let\mst@origRho\Rho +\let\mst@origSigma\Sigma +\let\mst@origTau\Tau +\let\mst@origUpsilon\Upsilon +\let\mst@origPhi\Phi +\let\mst@origChi\Chi +\let\mst@origPsi\Psi +\let\mst@origOmega\Omega +\let\mst@origalpha\alpha +\let\mst@origbeta\beta +\let\mst@origgamma\gamma +\let\mst@origdelta\delta +\let\mst@origepsilon\epsilon +\let\mst@origzeta\zeta +\let\mst@origeta\eta +\let\mst@origtheta\theta +\let\mst@origiota\iota +\let\mst@origkappa\kappa +\let\mst@origlambda\lambda +\let\mst@origmu\mu +\let\mst@orignu\nu +\let\mst@origxi\xi +\let\mst@origomicron\omicron +\let\mst@origpi\pi +\let\mst@origrho\rho +\let\mst@origvarsigma\varsigma +\let\mst@origsigma\sigma +\let\mst@origtau\tau +\let\mst@origupsilon\upsilon +\let\mst@origphi\phi +\let\mst@origchi\chi +\let\mst@origpsi\psi +\let\mst@origomega\omega +\let\mst@origDigamma\Digamma +\let\mst@origdigamma\digamma +%% +\def\mst@restoregreek{% +\let\Alpha\mst@origAlpha +\let\Beta\mst@origBeta +\let\Gamma\mst@origGamma +\let\Delta\mst@origDelta +\let\Epsilon\mst@origEpsilon +\let\Zeta\mst@origZeta +\let\Eta\mst@origEta +\let\Theta\mst@origTheta +\let\Iota\mst@origIota +\let\Kappa\mst@origKappa +\let\Lambda\mst@origLambda +\let\Mu\mst@origMu +\let\Nu\mst@origNu +\let\Xi\mst@origXi +\let\Omicron\mst@origOmicron +\let\Pi\mst@origPi +\let\Rho\mst@origRho +\let\Sigma\mst@origSigma +\let\Tau\mst@origTau +\let\Upsilon\mst@origUpsilon +\let\Phi\mst@origPhi +\let\Chi\mst@origChi +\let\Psi\mst@origPsi +\let\Omega\mst@origOmega +\let\alpha\mst@origalpha +\let\beta\mst@origbeta +\let\gamma\mst@origgamma +\let\delta\mst@origdelta +\let\epsilon\mst@origepsilon +\let\zeta\mst@origzeta +\let\eta\mst@origeta +\let\theta\mst@origtheta +\let\iota\mst@origiota +\let\kappa\mst@origkappa +\let\lambda\mst@origlambda +\let\mu\mst@origmu +\let\nu\mst@orignu +\let\xi\mst@origxi +\let\omicron\mst@origomicron +\let\pi\mst@origpi +\let\rho\mst@origrho +\let\varsigma\mst@origvarsigma +\let\sigma\mst@origsigma +\let\tau\mst@origtau +\let\upsilon\mst@origupsilon +\let\phi\mst@origphi +\let\chi\mst@origchi +\let\psi\mst@origpsi +\let\omega\mst@origomega +\let\Digamma\mst@origDigamma +\let\digamma\mst@origdigamma +} +%% +\def\mst@setuplgrgreek{% +\let\Alpha\mst@Alpha +\let\Beta\mst@Beta +\let\Gamma\mst@Gamma +\let\Delta\mst@Delta +\let\Epsilon\mst@Epsilon +\let\Zeta\mst@Zeta +\let\Eta\mst@Eta +\let\Theta\mst@Theta +\let\Iota\mst@Iota +\let\Kappa\mst@Kappa +\let\Lambda\mst@Lambda +\let\Mu\mst@Mu +\let\Nu\mst@Nu +\let\Xi\mst@Xi +\let\Omicron\mst@Omicron +\let\Pi\mst@Pi +\let\Rho\mst@Rho +\let\Sigma\mst@Sigma +\let\Tau\mst@Tau +\let\Upsilon\mst@Upsilon +\let\Phi\mst@Phi +\let\Chi\mst@Chi +\let\Psi\mst@Psi +\let\Omega\mst@Omega +\let\alpha\mst@alpha +\let\beta\mst@beta +\let\gamma\mst@gamma +\let\delta\mst@delta +\let\epsilon\mst@epsilon +\let\zeta\mst@zeta +\let\eta\mst@eta +\let\theta\mst@theta +\let\iota\mst@iota +\let\kappa\mst@kappa +\let\lambda\mst@lambda +\let\mu\mst@mu +\let\nu\mst@nu +\let\xi\mst@xi +\let\omicron\mst@omicron +\let\pi\mst@pi +\let\rho\mst@rho +\let\varsigma\mst@varsigma +\let\sigma\mst@sigma +\let\tau\mst@tau +\let\upsilon\mst@upsilon +\let\phi\mst@phi +\let\chi\mst@chi +\let\psi\mst@psi +\let\omega\mst@omega +\let\Digamma\mst@Digamma +\let\digamma\mst@digamma +} +%% +\DeclareMathSymbol{\mst@Alpha}{\mathalpha}{mtlgrfontupper}{65} +\DeclareMathSymbol{\mst@Beta}{\mathalpha}{mtlgrfontupper}{66} +\DeclareMathSymbol{\mst@Gamma}{\mathalpha}{mtlgrfontupper}{71} +\DeclareMathSymbol{\mst@Delta}{\mathalpha}{mtlgrfontupper}{68} +\DeclareMathSymbol{\mst@Epsilon}{\mathalpha}{mtlgrfontupper}{69} +\DeclareMathSymbol{\mst@Zeta}{\mathalpha}{mtlgrfontupper}{90} +\DeclareMathSymbol{\mst@Eta}{\mathalpha}{mtlgrfontupper}{72} +\DeclareMathSymbol{\mst@Theta}{\mathalpha}{mtlgrfontupper}{74} +\DeclareMathSymbol{\mst@Iota}{\mathalpha}{mtlgrfontupper}{73} +\DeclareMathSymbol{\mst@Kappa}{\mathalpha}{mtlgrfontupper}{75} +\DeclareMathSymbol{\mst@Lambda}{\mathalpha}{mtlgrfontupper}{76} +\DeclareMathSymbol{\mst@Mu}{\mathalpha}{mtlgrfontupper}{77} +\DeclareMathSymbol{\mst@Nu}{\mathalpha}{mtlgrfontupper}{78} +\DeclareMathSymbol{\mst@Xi}{\mathalpha}{mtlgrfontupper}{88} +\DeclareMathSymbol{\mst@Omicron}{\mathalpha}{mtlgrfontupper}{79} +\DeclareMathSymbol{\mst@Pi}{\mathalpha}{mtlgrfontupper}{80} +\DeclareMathSymbol{\mst@Rho}{\mathalpha}{mtlgrfontupper}{82} +\DeclareMathSymbol{\mst@Sigma}{\mathalpha}{mtlgrfontupper}{83} +\DeclareMathSymbol{\mst@Tau}{\mathalpha}{mtlgrfontupper}{84} +\DeclareMathSymbol{\mst@Upsilon}{\mathalpha}{mtlgrfontupper}{85} +\DeclareMathSymbol{\mst@Phi}{\mathalpha}{mtlgrfontupper}{70} +\DeclareMathSymbol{\mst@Chi}{\mathalpha}{mtlgrfontupper}{81} +\DeclareMathSymbol{\mst@Psi}{\mathalpha}{mtlgrfontupper}{89} +\DeclareMathSymbol{\mst@Omega}{\mathalpha}{mtlgrfontupper}{87} +\DeclareMathSymbol{\mst@alpha}{\mathalpha}{mtlgrfontlower}{97} +\DeclareMathSymbol{\mst@beta}{\mathalpha}{mtlgrfontlower}{98} +\DeclareMathSymbol{\mst@gamma}{\mathalpha}{mtlgrfontlower}{103} +\DeclareMathSymbol{\mst@delta}{\mathalpha}{mtlgrfontlower}{100} +\DeclareMathSymbol{\mst@epsilon}{\mathalpha}{mtlgrfontlower}{101} +\DeclareMathSymbol{\mst@zeta}{\mathalpha}{mtlgrfontlower}{122} +\DeclareMathSymbol{\mst@eta}{\mathalpha}{mtlgrfontlower}{104} +\DeclareMathSymbol{\mst@theta}{\mathalpha}{mtlgrfontlower}{106} +\DeclareMathSymbol{\mst@iota}{\mathalpha}{mtlgrfontlower}{105} +\DeclareMathSymbol{\mst@kappa}{\mathalpha}{mtlgrfontlower}{107} +\DeclareMathSymbol{\mst@lambda}{\mathalpha}{mtlgrfontlower}{108} +\DeclareMathSymbol{\mst@mu}{\mathalpha}{mtlgrfontlower}{109} +\DeclareMathSymbol{\mst@nu}{\mathalpha}{mtlgrfontlower}{110} +\DeclareMathSymbol{\mst@xi}{\mathalpha}{mtlgrfontlower}{120} +\DeclareMathSymbol{\mst@omicron}{\mathalpha}{mtlgrfontlower}{111} +\DeclareMathSymbol{\mst@pi}{\mathalpha}{mtlgrfontlower}{112} +\DeclareMathSymbol{\mst@rho}{\mathalpha}{mtlgrfontlower}{114} +\DeclareMathSymbol{\mst@varsigma}{\mathalpha}{mtlgrfontlower}{99} +\DeclareMathSymbol{\mst@sigma}{\mathalpha}{mtlgrfontlower}{115} +\DeclareMathSymbol{\mst@tau}{\mathalpha}{mtlgrfontlower}{116} +\DeclareMathSymbol{\mst@upsilon}{\mathalpha}{mtlgrfontlower}{117} +\DeclareMathSymbol{\mst@phi}{\mathalpha}{mtlgrfontlower}{102} +\DeclareMathSymbol{\mst@chi}{\mathalpha}{mtlgrfontlower}{113} +\DeclareMathSymbol{\mst@psi}{\mathalpha}{mtlgrfontlower}{121} +\DeclareMathSymbol{\mst@omega}{\mathalpha}{mtlgrfontlower}{119} +\DeclareMathSymbol{\mst@digamma}{\mathalpha}{mtlgrfontlower}{147} +\DeclareMathSymbol{\mst@Digamma}{\mathalpha}{mtlgrfontlower}{195} +\ifmst@subdued\else\mst@setuplgrgreek\fi +\fi +\edef\mst@tmp@enc{\encodingdefault} +\mst@goaheadtrue +\ifx\mst@tmp@enc\mst@eui % xetex and unicode font + \XeTeXmathchardef\inodot="7 \symmtletterfont "0131 \relax + \XeTeXmathchardef\jnodot="7 \symmtletterfont "0237 \relax +\else +\ifx\mst@tmp@enc\mst@euii % luatex and unicode font + \luatexUmathchardef\inodot="7 \symmtletterfont "0131 \relax + \luatexUmathchardef\jnodot="7 \symmtletterfont "0237 \relax +\else +\ifx\mst@tmp@enc\mst@ti % T1 + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont}{25} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont}{26} +\else +\ifx\mst@tmp@enc\mst@oti % OT1 + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont}{16} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont}{17} +\else +\ifx\mst@tmp@enc\mst@lyi % LY1 + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont}{16} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont}{17} +\else + \ifmst@XeTeX\mst@goaheadfalse\else\ifmst@LuaTeX\mst@goaheadfalse\else + \DeclareMathSymbol{\inodot}{\mathalpha}{mtletterfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\i\endcsname} + \DeclareMathSymbol{\jnodot}{\mathalpha}{mtletterfont} +{\expandafter\the\expandafter\csname\mst@tmp@enc\string\j\endcsname} + \fi\fi +\fi\fi\fi\fi\fi +\ifmst@defaultimath\else\typeout{** \string\i\space and \string\j\space} + \ifmst@goahead + \renewcommand*{\imath}{\inodot} + \renewcommand*{\jmath}{\jnodot} + \let\mst@oldi\i \let\mst@oldj\j + \DeclareRobustCommand*{\i}{\ifmmode\inodot\else\mst@oldi\fi} + \DeclareRobustCommand*{\j}{\ifmmode\jnodot\else\mst@oldj\fi} + \fi +\fi +\edef\mst@tmp@enc{\encodingdefault} %% rather one too many than sorry +\ifmst@mathaccents\typeout{** math accents} +\ifx\mst@ti\mst@tmp@enc +\DeclareMathAccent{\acute}{\mathalpha}{mtoperatorfont}{1} +\DeclareMathAccent{\grave}{\mathalpha}{mtoperatorfont}{0} +\DeclareMathAccent{\ddot}{\mathalpha}{mtoperatorfont}{4} +\DeclareMathAccent{\tilde}{\mathalpha}{mtoperatorfont}{3} +\DeclareMathAccent{\bar}{\mathalpha}{mtoperatorfont}{9} +\DeclareMathAccent{\breve}{\mathalpha}{mtoperatorfont}{8} +\DeclareMathAccent{\check}{\mathalpha}{mtoperatorfont}{7} +\DeclareMathAccent{\hat}{\mathalpha}{mtoperatorfont}{2} +\DeclareMathAccent{\dot}{\mathalpha}{mtoperatorfont}{10} +\DeclareMathAccent{\mathring}{\mathalpha}{mtoperatorfont}{6} +\else +\DeclareMathAccent{\acute}{\mathalpha}{mtoperatorfont}{19} +\DeclareMathAccent{\grave}{\mathalpha}{mtoperatorfont}{18} +\DeclareMathAccent{\ddot}{\mathalpha}{mtoperatorfont}{127} +\DeclareMathAccent{\tilde}{\mathalpha}{mtoperatorfont}{126} +\DeclareMathAccent{\bar}{\mathalpha}{mtoperatorfont}{22} +\DeclareMathAccent{\breve}{\mathalpha}{mtoperatorfont}{21} +\DeclareMathAccent{\check}{\mathalpha}{mtoperatorfont}{20} +\DeclareMathAccent{\hat}{\mathalpha}{mtoperatorfont}{94} +\DeclareMathAccent{\dot}{\mathalpha}{mtoperatorfont}{95} +\DeclareMathAccent{\mathring}{\mathalpha}{mtoperatorfont}{23} + \ifx\mst@lyi\mst@tmp@enc % LY1 encoding + \DeclareMathAccent{\dot}{\mathalpha}{mtoperatorfont}{5} + \else + \ifx\mst@oti\mst@tmp@enc\else + \typeout{** mathastext: math accents have been assumed to be^^J% + ** as in OT1 encoding.} + \fi + \fi +\fi\fi +\ifmst@defaultsizes\else +\providecommand\@xxxpt{29.86} +\providecommand\@xxxvipt{35.83} +\ifmst@twelve + \def\Huge{\@setfontsize\Huge\@xxxpt{36}} + \def\HUGE{\@setfontsize\HUGE\@xxxvipt{43}} +\typeout{** \protect\Huge\space and \protect\HUGE\space have been (re)-defined.} +\else + \def\HUGE{\@setfontsize\HUGE\@xxxpt{36}} +\typeout{** \protect\HUGE\space has been (re)-defined.} +\fi +\def\defaultscriptratio{.8333} +\def\defaultscriptscriptratio{.7} +\DeclareMathSizes{9}{9}{7}{5} +\DeclareMathSizes{\@xpt}{\@xpt}{8}{6} +\DeclareMathSizes{\@xipt}{\@xipt}{9}{7} +\DeclareMathSizes{\@xiipt}{\@xiipt}{10}{8} +\DeclareMathSizes{\@xivpt}{\@xivpt}{\@xiipt}{10} +\DeclareMathSizes{\@xviipt}{\@xviipt}{\@xivpt}{\@xiipt} +\DeclareMathSizes{\@xxpt}{\@xxpt}{\@xviipt}{\@xivpt} +\DeclareMathSizes{\@xxvpt}{\@xxvpt}{\@xxpt}{\@xviipt} +\DeclareMathSizes{\@xxxpt}{\@xxxpt}{\@xxvpt}{\@xxpt} +\DeclareMathSizes{\@xxxvipt}{\@xxxvipt}{\@xxxpt}{\@xxvpt} +\typeout{** mathastext has declared larger sizes for subscripts.^^J% +** To keep LaTeX defaults, use option `defaultmathsizes\string'.} +\fi +\endinput +%% +%% End of file `mathastext.sty'. diff --git a/latex/ods.tex b/latex/ods.tex index 7163a193..7c493215 100644 --- a/latex/ods.tex +++ b/latex/ods.tex @@ -1,8 +1,8 @@ \documentclass[10pt]{book} +\usepackage[math]{iwona} +\SetMathAlphabet{\mathtt}{iwona}{OT1}{\ttdefault}{m}{n} +\usepackage[T1]{fontenc} - -%\usepackage{html} -\usepackage{kpfonts} \usepackage{amsopn} \usepackage{amsmath} \usepackage{amsthm} @@ -12,6 +12,7 @@ \usepackage{amsfonts} \usepackage{graphicx} \usepackage{threeparttable} +\usepackage{wasysym} %% This code allows dynamic scaling of images to fit the page %% Usage: \includegraphics[width=\ScaleIfNeeded]{figs/figure} diff --git a/latex/rbs.tex b/latex/rbs.tex index ceb592e9..5d3cde62 100644 --- a/latex/rbs.tex +++ b/latex/rbs.tex @@ -7,10 +7,10 @@ \chapter{Random Binary Search Trees} \section{Random Binary Search Trees} \seclabel{rbst} -Consider the two binary search trees shown in \figref{rbs-lvc}. The one -on the left is a list and the other is a perfectly balanced binary search -tree. The one on the left has height $#n#-1=14$ and the one on the right -has height three. +Consider the two binary search trees shown in \figref{rbs-lvc}, each of +which has $#n#=15$ nodes. The one on the left is a list and the other +is a perfectly balanced binary search tree. The one on the left has a +height of $#n#-1=14$ and the one on the right has a height of three. \begin{figure} \begin{center} @@ -48,7 +48,7 @@ \section{Random Binary Search Trees} The above example gives some anecdotal evidence that, if we choose a random permutation of $0,\ldots,14$, and add it into a binary search -tree then we are more likely to get a very balanced tree (the right +tree, then we are more likely to get a very balanced tree (the right side of \figref{rbs-lvc}) than we are to get a very unbalanced tree (the left side of \figref{rbs-lvc}). @@ -122,7 +122,7 @@ \section{Random Binary Search Trees} us the same thing about searching for a value not stored in the tree. When we compare the two parts of the lemma, we see that it is only slightly faster to search for something that is in the tree compared to -something that is not in the tree. +something that is not. \subsection{Proof of \lemref{rbs}} @@ -334,10 +334,9 @@ \section{#Treap#: A Randomized Binary Search Tree} \figlabel{rotations} \end{figure} -The code that implements this has to handle these two possibilities -and be careful of a boundary -case (when #u# is the root) so the actual code is a little longer than -\figref{rotations} would lead a reader to believe: +The code that implements this has to handle these two possibilities and +be careful of a boundary case (when #u# is the root), so the actual code +is a little longer than \figref{rotations} would lead a reader to believe: \codeimport{ods/BinarySearchTree.rotateLeft(u).rotateRight(u)} \label{page:rotations} In terms of the #Treap# data structure, the most important property of a @@ -406,7 +405,7 @@ \section{#Treap#: A Randomized Binary Search Tree} \end{figure} The trick to analyze the running time of the #remove(x)# operation is -to notice that this operation is the reverse of the #add(x)# operation. +to notice that this operation reverses the #add(x)# operation. In particular, if we were to reinsert #x#, using the same priority #u.p#, then the #add(x)# operation would do exactly the same number of rotations and would restore the #Treap# to exactly the same state it was in before @@ -583,7 +582,7 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Design an implement an algorithm that constructs a #Treap# from a + Design and implement an algorithm that constructs a #Treap# from a sorted array, #a#, of #n# elements. This method should run in $O(#n#)$ worst-case time and should construct a #Treap# that is indistinguishable from one in which the elements of #a# were added one at a time using diff --git a/latex/redblack.tex b/latex/redblack.tex index 4b1b3f7a..a423ae99 100644 --- a/latex/redblack.tex +++ b/latex/redblack.tex @@ -2,12 +2,12 @@ \chapter{Red-Black Trees} \chaplabel{redblack} In this chapter, we present red-black trees, a version of binary search -trees that have logarithmic depth. Red-black trees are one of the most -widely-used data structures in practice. They appear as the primary -search structure in many library implementations, including the Java -Collections Framework and several implementations of the C++ Standard -Template Library. They are also used within the Linux operating system -kernel. There are several reasons for the popularity of red-black trees: +trees with logarithmic height. Red-black trees are one of the most +widely-used data structures. They appear as the primary search structure +in many library implementations, including the Java Collections Framework +and several implementations of the C++ Standard Template Library. They +are also used within the Linux operating system kernel. There are +several reasons for the popularity of red-black trees: \begin{enumerate} \item A red-black tree storing #n# values has height at most $2\log #n#$. \item The #add(x)# and #remove(x)# operations on a red-black tree run @@ -29,14 +29,14 @@ \chapter{Red-Black Trees} However, the nice properties of red-black trees come with a price: implementation complexity. Maintaining a bound of $2\log #n#$ on the height is not easy. It requires a careful analysis of a number of cases -and it requires that the implementation does exactly the right thing -in each case. One misplaced rotation or change of color produces a bug -that can be very difficult to understand and track down. +and. We must make sure that the implementation does exactly the right +thing in each case. One misplaced rotation or change of colour produces +a bug that can be very difficult to understand and track down. -Rather than jumping directly into the implementation of red-black trees, we -will first provide some background on a related data structure: 2-4 trees. -This will give some insight into how red-black trees were discovered -and why efficiently maintaining red-black trees is even possible. +Rather than jumping directly into the implementation of red-black trees, +we will first provide some background on a related data structure: +2-4 trees. This will give some insight into how red-black trees were +discovered and why efficiently maintaining them is even possible. \section{2-4 Trees} \seclabel{twofour} @@ -76,17 +76,18 @@ \subsection{Adding a Leaf} Adding a leaf to a 2-4 tree is easy (see \figref{twofour-add}). If we want to add a leaf #u# as the child of some node #w# on the second-last -level, we simply make #u# a child of #w#. This certainly maintains -the height property, but could violate the degree property; if #w# had -4 children prior to adding #u#, then #w# now has 5 children. In this -case, we split #w# into two nodes, #w# and #w#', having 2 and 3 children, -respectively. But now #w#' has no parent, so we recursively make #w#' -a child of #w#'s parent. Again, this may cause #w#'s parent to have too -many children in which case we split it. This process goes on until we -reach a node that has fewer than 4 children, or until we split the root, -#r#, into two nodes #r# and #r'#. In the latter case, we make a new -root that has #r# and #r'# as children. This simultaneously increases -the depth of all leaves and so maintains the height property. +level, then we simply make #u# a child of #w#. This certainly maintains +the height property, but could violate the degree property; if #w# +had four children prior to adding #u#, then #w# now has five children. +In this case, we split #w# into two nodes, #w# and #w#', having +two and three children, respectively. But now #w#' has no parent, +so we recursively make #w#' a child of #w#'s parent. Again, this may +cause #w#'s parent to have too many children in which case we split it. +This process goes on until we reach a node that has fewer than 4 children, +or until we split the root, #r#, into two nodes #r# and #r'#. In the +latter case, we make a new root that has #r# and #r'# as children. +This simultaneously increases the depth of all leaves and so maintains +the height property. \begin{figure} \begin{center} @@ -111,6 +112,7 @@ \subsection{Removing a Leaf} \figref{twofour-remove}). To remove a leaf #u# from its parent #w#, we just remove it. If #w# had only two children prior to the removal of #u#, then #w# is left with only one child and violates the degree property. + \begin{figure} \begin{center} \begin{tabular}{c} @@ -121,23 +123,26 @@ \subsection{Removing a Leaf} \includegraphics[height=\FifthHeightScaleIfNeeded]{figs/24tree-remove-5} \\ \end{tabular} \end{center} - \caption[Removing a leaf from a 2-4 Tree]{Removing a leaf from a 2-4 Tree. This process goes all the way to the root because all of #u#'s ancestors and their siblings have degree 2.} + \caption[Removing a leaf from a 2-4 Tree]{Removing a leaf from a + 2-4 Tree. This process goes all the way to the root because each of + #u#'s ancestors and their siblings have only two children.} \figlabel{twofour-remove} \end{figure} -To correct this, we look at #w#'s sibling, #w'#. The node #w'# is sure -to exist since #w#'s parent has at least 2 children. If #w'# has 3 or -4 children, then we take one of these children from #w'# and give it to -#w#. Now #w# has 2 children and #w'# has 2 or 3 children and we are done. - -On the other hand, if #w'# has only two children, then we merge #w# and -#w'# into a single node, #w#, that has 3 children. Next we recursively -remove #w'# from the parent of #w'#. This process ends when we reach -a node, #u#, where #u# or its sibling has more than 2 children; or we -reach the root. In the latter case, if the root is left with only 1 -child, then we delete the root and make its child the new root. Again, -this simultaneously decreases the height of every leaf and therefore -maintains the height property. +To correct this, we look at #w#'s sibling, #w'#. The node #w'# is +sure to exist since #w#'s parent had at least two children. If #w'# +has three or four children, then we take one of these children from #w'# +and give it to #w#. Now #w# has two children and #w'# has two or three +children and we are done. + +On the other hand, if #w'# has only two children, then we merge #w# +and #w'# into a single node, #w#, that has three children. Next we +recursively remove #w'# from the parent of #w'#. This process ends when +we reach a node, #u#, where #u# or its sibling has more than two children; +or we reach the root. In the latter case, if the root is left with only +one child, then we delete the root and make its child the new root. +Again, this simultaneously decreases the height of every leaf and +therefore maintains the height property. Again, since the height of the tree is never more than $\log #n#$, the process of removing a leaf finishes after at most $\log #n#$ steps. @@ -146,30 +151,30 @@ \section{#RedBlackTree#: A Simulated 2-4 Tree} \seclabel{redblacktree} A red-black tree is a binary search tree in which each node, #u#, -has a \emph{color} which is either \emph{red} or \emph{black}. Red is +has a \emph{colour} which is either \emph{red} or \emph{black}. Red is represented by the value $0$ and black by the value $1$. \javaimport{ods/RedBlackTree.red.black.Node} \cppimport{ods/RedBlackTree.RedBlackNode.red.black} Before and after any operation on a red-black tree, the following two properties are satisfied. Each property is defined both in terms of the -colors red and black, and in terms of the numeric values 0 and 1. +colours red and black, and in terms of the numeric values 0 and 1. \begin{prp}[black-height] There are the same number of black nodes on every root to leaf - path. (The sum of the colors on any root to leaf path is the same.) + path. (The sum of the colours on any root to leaf path is the same.) \end{prp} \begin{prp}[no-red-edge] No two red nodes are adjacent. (For any node #u#, except the root, - $#u.color# + #u.parent.color# \ge 1$.) + $#u.colour# + #u.parent.colour# \ge 1$.) \end{prp} -Notice that we can always color the root, #r#, of a red-black tree black +Notice that we can always colour the root, #r#, of a red-black tree black without violating either of these two properties, so we will assume that the root is black, and the algorithms for updating a red-black tree will maintain this. Another trick that simplifies red-black trees is to treat the external nodes (represented by #nil#) as black nodes. This way, every real node, #u#, of a red-black tree has exactly two -children, each with a well-defined color. An example of a red-black +children, each with a well-defined colour. An example of a red-black tree is shown in \figref{redblack-example}. \begin{figure} @@ -205,14 +210,14 @@ \subsection{Red-Black Trees and 2-4 Trees} \figlabel{twofour-redblack} \end{figure} -Every internal node in $T'$ has 2, 3, or 4 children: A black node that -started out with two black children will still have two black children -after this transformation. A black node that started out with one red -and one black child will have three children after this transformation. -A black node that started out with two red children will have 4 children -after this transformation. Furthermore, the black-height property now -guarantees that every root-to-leaf path in $T'$ has the same length. -In other words, $T'$ is a 2-4 tree! +Every internal node in $T'$ has two, three, or four children: A black +node that started out with two black children will still have two +black children after this transformation. A black node that started +out with one red and one black child will have three children after this +transformation. A black node that started out with two red children will +have 4 children after this transformation. Furthermore, the black-height +property now guarantees that every root-to-leaf path in $T'$ has the +same length. In other words, $T'$ is a 2-4 tree! The 2-4 tree $T'$ has $#n#+1$ leaves that correspond to the $#n#+1$ external nodes of the red-black tree. Therefore, this tree has height @@ -236,11 +241,11 @@ \subsection{Red-Black Trees and 2-4 Trees} We have already seen that adding an element in a #BinarySearchTree# can be done by adding a new leaf. Therefore, to implement #add(x)# in a -red-black tree we need a method of simulating splitting a degree 5 node -in a 2-4 tree. A degree 5 node is represented by a black node that has -two red children one of which also has a red child. We can ``split'' -this node by coloring it red and coloring its two children black. -An example of this is shown in \figref{rb-split}. +red-black tree we need a method of simulating splitting a node with five +children in a 2-4 tree. A 2-4 tree node with five children is represented +by a black node that has two red children, one of which also has a red +child. We can ``split'' this node by colouring it red and colouring its +two children black. An example of this is shown in \figref{rb-split}. \begin{figure} \begin{center} @@ -250,34 +255,36 @@ \subsection{Red-Black Trees and 2-4 Trees} \includegraphics{figs/rb-split-3} \\ \end{tabular} \end{center} - \caption[Simulating a 2-4 tree]{Simulating a 2-4 tree split operation during an addition in a - red-black tree. (This simulates the 2-4 tree addition shown in \figref{twofour-add}.)} + \caption[Simulating a 2-4 tree]{Simulating a 2-4 tree split operation + during an addition in a red-black tree. (This simulates the 2-4 + tree addition shown in \figref{twofour-add}.)} \figlabel{rb-split} \end{figure} -Similarly, implementing #remove(x)# requires a method of merging two -nodes and borrowing a child from a sibling. Merging two nodes is the -inverse of a split (shown in \figref{rb-split}), and involves coloring -two (black) siblings red and coloring their (red) parent black. -Borrowing from a sibling is the most complicated of the procedures and involves both rotations and recoloring of nodes. +Similarly, implementing #remove(x)# requires a method of merging two nodes +and borrowing a child from a sibling. Merging two nodes is the inverse of +a split (shown in \figref{rb-split}), and involves colouring two (black) +siblings red and colouring their (red) parent black. Borrowing from +a sibling is the most complicated of the procedures and involves both +rotations and recolouring nodes. Of course, during all of this we must still maintain the no-red-edge property and the black-height property. While it is no longer surprising that this can be done, there are a large number of cases that have to -be considered if we try to do a direct simulation of a 2-4 tree by -a red-black tree. At some point, it just becomes simpler to forget -about the underlying 2-4 tree and work directly towards maintaining the -red-black tree properties. +be considered if we try to do a direct simulation of a 2-4 tree by a +red-black tree. At some point, it just becomes simpler disregard the +underlying 2-4 tree and work directly towards maintaining the properties +of the red-black tree. \subsection{Left-Leaning Red-Black Trees} -There is no single definition of a red-black tree. Rather, -there are a family of structures that manage to maintain the -black-height and no-red-edge properties during #add(x)# and #remove(x)# -operations. Different structures go about it in different ways. Here, we -implement a data structure that we call a #RedBlackTree#. This structure -implements a particular variant of red-black trees that satisfies an -additional property: +No single definition of a red-black trees exists. Rather, there are +a family of structures that manage to maintain the black-height +and no-red-edge properties during #add(x)# and #remove(x)# +operations. Different structures do this in different ways. +Here, we implement a data structure that we call a #RedBlackTree#. +This structure implements a particular variant of red-black trees that +satisfies an additional property: \begin{prp}[left-leaning]\prplabel{left-leaning}\prplabel{redblack-last} At any node #u#, if #u.left# is black, then #u.right# is black. \end{prp} @@ -287,18 +294,18 @@ \subsection{Left-Leaning Red-Black Trees} The reason for maintaining the left-leaning property is that it reduces the number of cases encountered when updating the tree during #add(x)# -and #remove(x)# operations. In terms of 2-4 trees, it implies that -every 2-4 tree has a unique representation: A node of degree 2 becomes -a black node with 2 black children. A node of degree 3 becomes a black -node whose left child is red and whose right child is black. A node of -degree 4 becomes a black node with two red children. +and #remove(x)# operations. In terms of 2-4 trees, it implies that every +2-4 tree has a unique representation: A node of degree two becomes +a black node with two black children. A node of degree three becomes +a black node whose left child is red and whose right child is black. +A node of degree four becomes a black node with two red children. Before we describe the implementation of #add(x)# and #remove(x)# in detail, we first present some simple subroutines used by these methods that are illustrated in \figref{redblack-flippullpush}. The first two -subroutines are for manipulating colors while preserving the black-height +subroutines are for manipulating colours while preserving the black-height property. The #pushBlack(u)# method takes as input a black node #u# -that has two red children and colors #u# red and its two children black. +that has two red children and colours #u# red and its two children black. The #pullBlack(u)# method reverses this operation: \codeimport{ods/RedBlackTree.pushBlack(u).pullBlack(u)} @@ -310,32 +317,30 @@ \subsection{Left-Leaning Red-Black Trees} \figlabel{redblack-flippullpush} \end{figure} -The #flipLeft(u)# method swaps the colors of #u# and #u.right# and -then performs a left rotation at #u#. This reverses the colors -of these two nodes as well as their parent-child relationship: -\codeimport{ods/RedBlackTree.flipLeft(u)} -The #flipLeft(u)# operation is especially useful in restoring the -left-leaning property at a node $u$ that violates it (because #u.left# -is black and #u.right# is red). In this special case, we can be assured -this operation preserves both the black-height and no-red-edge properties. -The #flipRight(u)# operation is symmetric to #flipLeft(u)# with the -roles of left and right reversed. +The #flipLeft(u)# method swaps the colours of #u# and #u.right# +and then performs a left rotation at #u#. This method reverses the +colours of these two nodes as well as their parent-child relationship: +\codeimport{ods/RedBlackTree.flipLeft(u)} The #flipLeft(u)# operation +is especially useful in restoring the left-leaning property at a node +$u$ that violates it (because #u.left# is black and #u.right# is red). +In this special case, we can be assured that this operation preserves both +the black-height and no-red-edge properties. The #flipRight(u)# operation +is symmetric with #flipLeft(u)# then the roles of left and right reversed. \codeimport{ods/RedBlackTree.flipRight(u)} \subsection{Addition} To implement #add(x)# in a #RedBlackTree#, we perform a standard -#BinarySearchTree# insertion, which adds a new leaf, #u#, with $#u.x#=#x#$ -and set $#u.color#=#red#$. Note that this does not change the black -height of any node, so it does not violate the black-height property. -It may, however, violate the left-leaning property (if #u# is the -right child of its parent) and it may violate the no-red-edge property -(if #u#'s parent is #red#). To restore these properties, we call the -method #addFixup(u)#. +#BinarySearchTree# insertion to add a new leaf, #u#, with $#u.x#=#x#$ and +set $#u.colour#=#red#$. Note that this does not change the black height +of any node, so it does not violate the black-height property. It may, +however, violate the left-leaning property (if #u# is the right child of +its parent), and it may violate the no-red-edge property (if #u#'s parent +is #red#). To restore these properties, we call the method #addFixup(u)#. \codeimport{ods/RedBlackTree.add(x)} -The #addFixup(u)# method, illustrated in \figref{rb-addfix}, takes -as input a node #u# whose color is red and which may be violating the +Illustrated in \figref{rb-addfix}, the #addFixup(u)# method takes +as input a node #u# whose colour is red and which may violate the no-red-edge property and/or the left-leaning property. The following discussion is probably impossible to follow without referring to \figref{rb-addfix} or recreating it on a piece of paper. Indeed, the @@ -350,18 +355,17 @@ \subsection{Addition} \figlabel{rb-addfix} \end{figure} -If #u# is the root of the tree, then we can color #u# black and this -restores both properties. If #u#'s sibling is also red, then #u#'s -parent must be black, so both the left-leaning and no-red-edge properties -already hold. +If #u# is the root of the tree, then we can colour #u# black to restore +both properties. If #u#'s sibling is also red, then #u#'s parent must be +black, so both the left-leaning and no-red-edge properties already hold. Otherwise, we first determine if #u#'s parent, #w#, violates the left-leaning property and, if so, perform a #flipLeft(w)# operation and set $#u#=#w#$. This leaves us in a well-defined state: #u# is the left child of its parent, #w#, so #w# now satisfies the left-leaning property. -All that remains is to ensure the no-red-edge property at #u#. -We only have to worry about the case where #w# is red, since otherwise -#u# already satisfies the no-red-edge property. +All that remains is to ensure the no-red-edge property at #u#. We only +have to worry about the case in which #w# is red, since otherwise #u# +already satisfies the no-red-edge property. Since we are not done yet, #u# is red and #w# is red. The no-red-edge property (which is only violated by #u# and not by #w#) implies that @@ -378,43 +382,44 @@ \subsection{Addition} \codeimport{ods/RedBlackTree.addFixup(u)} The #insertFixup(u)# method takes constant time per iteration and each -iteration either finishes or moves #u# closer to the root. This implies -that the #insertFixup(u)# method finishes after $O(\log #n#)$ iterations -in $O(\log #n#)$ time. +iteration either finishes or moves #u# closer to the root. Therefore, +the #insertFixup(u)# method finishes after $O(\log #n#)$ iterations in +$O(\log #n#)$ time. \subsection{Removal} The #remove(x)# operation in a #RedBlackTree# is the most complicated -operation to implement, and this is true of all known implementations. -Like #remove(x)# in a \texttt{BinarySearchTree}, this operation boils -down to finding a node #w# with only one child, #u#, and splicing #w# -out of the tree by having #w.parent# adopt #u#. +to implement, and this is true of all known implementations. Like +#remove(x)# in a \texttt{BinarySearchTree}, this operation boils down +to finding a node #w# with only one child, #u#, and splicing #w# out of +the tree by having #w.parent# adopt #u#. The problem with this is that, if #w# is black, then the black-height -property will now be violated at #w.parent#. We get around this -problem, temporarily, by adding #w.color# to #u.color#. Of course, this -introduces two other problems: (1)~#u# and #w# both started out black, -then $#u.color#+#w.color#=2$ (double black), which is an invalid color. +property will now be violated at #w.parent#. We may avoid this problem, +temporarily, by adding #w.colour# to #u.colour#. Of course, this introduces +two other problems: (1)~if #u# and #w# both started out black, then +$#u.colour#+#w.colour#=2$ (double black), which is an invalid colour. If #w# was red, then it is replaced by a black node #u#, which may -violate the left-leaning property at $#u.parent#$. Both of these problems -are resolved with a call to the #removeFixup(u)# method. +violate the left-leaning property at $#u.parent#$. Both of these +problems can be resolved with a call to the #removeFixup(u)# method. \codeimport{ods/RedBlackTree.remove(x)} -The #removeFixup(u)# method takes as input a node #u# whose color is black +The #removeFixup(u)# method takes as its input a node #u# whose colour is black (1) or double-black (2). If #u# is double-black, then #removeFixup(u)# -performs a series of rotations and recoloring operations that move the -double-black node up the tree until it can be gotten rid of. During this +performs a series of rotations and recolouring operations that move the +double-black node up the tree until it can be eliminated. During this process, the node #u# changes until, at the end of this process, #u# refers to the root of the subtree that has been changed. The root of -this subtree may have changed color. In particular, it may have gone +this subtree may have changed colour. In particular, it may have gone from red to black, so the #removeFixup(u)# method finishes by checking -if #u#'s parent violates the left-leaning property and, if so, fixes it. +if #u#'s parent violates the left-leaning property and, if so, fixing it. \codeimport{ods/RedBlackTree.removeFixup(u)} The #removeFixup(u)# method is illustrated in \figref{rb-removefix}. Again, the following text will be very difficult, if not impossible, to follow without referring constantly to \figref{rb-removefix}. -Each iteration of the loop in #removeFixup(u)# processes the double-black node #u# based on one of four cases. +Each iteration of the loop in #removeFixup(u)# processes the double-black +node #u#, based on one of four cases: \begin{figure} \begin{center} @@ -426,31 +431,32 @@ \subsection{Removal} \end{figure} \noindent -Case 0: #u# is the root. This is the easiest case to treat. We recolor #u# to be black and this does not violate any of the red-black tree properties. +Case 0: #u# is the root. This is the easiest case to treat. We recolour +#u# to be black (this does not violate any of the red-black tree +properties). \noindent Case 1: #u#'s sibling, #v#, is red. In this case, #u#'s sibling is the left child of its parent, #w# (by the left-leaning property). We perform a right-flip at #w# and then proceed to the next iteration. Note that -this causes #w#'s parent to violate the left-leaning property and it -causes the depth of #u# to increase. However, it also implies that the -next iteration will be in Case~3 with #w# colored red. When examining -Case~3, below, we will see that this means the process will stop during -the next iteration. +this action causes #w#'s parent to violate the left-leaning property and +the depth of #u# to increase. However, it also implies that the next +iteration will be in Case~3 with #w# coloured red. When examining Case~3 +below, we will see that the process will stop during the next iteration. \codeimport{ods/RedBlackTree.removeFixupCase1(u)} \noindent -Case 2: #u#'s sibling, #v#, is black and #u# is the left child of its +Case 2: #u#'s sibling, #v#, is black, and #u# is the left child of its parent, #w#. In this case, we call #pullBlack(w)#, making #u# black, -#v# red, and darkening the color of #w# to black or double-black. +#v# red, and darkening the colour of #w# to black or double-black. At this point, #w# does not satisfy the left-leaning property, so we call #flipLeft(w)# to fix this. -At this point, #w# is red and #v# is the root of the subtree we started -with. We need to check if #w# causes no-red-edge property to be violated. -We do this by inspecting #w#'s right child, #q#. If #q# is black, -then #w# satisfies the no-red-edge property and we can continue to the -next iteration with $#u#=#v#$. +At this point, #w# is red and #v# is the root of the subtree with which +we started. We need to check if #w# causes no-red-edge property to +be violated. We do this by inspecting #w#'s right child, #q#. If #q# +is black, then #w# satisfies the no-red-edge property and we can continue +to the next iteration with $#u#=#v#$. Otherwise (#q# is red), both the no-red-edge property and the left-leaning property are violated at #q# and #w#, respectively. A call to @@ -459,13 +465,13 @@ \subsection{Removal} #v# and #w# is the left child of #q#, #q# and #w# are both red and #v# is black or double-black. A #flipRight(v)# makes #q# the parent of both #v# and #w#. Following this up by a #pushBlack(q)# makes both #v# -and #w# black and sets the color of #q# back to the original color of #w#. +and #w# black and sets the colour of #q# back to the original colour of #w#. -At this point, there is no more double-black node and the no-red-edge and -black-height properties are reestablished. The only possible problem -that remains is that the right child of #v# may be red, in which case -the left-leaning property is violated. We check this and perform a -#flipLeft(v)# to correct it if necessary. +At this point, the double-black node is has been eliminated and the +no-red-edge and black-height properties are reestablished. There remains +only one possible problem: the right child of #v# may be red, in which +case the left-leaning property would be violated. We check this and +perform a #flipLeft(v)# to correct it if necessary. \codeimport{ods/RedBlackTree.removeFixupCase2(u)} \noindent @@ -477,19 +483,19 @@ \subsection{Removal} As before, we begin with a call to #pullBlack(w)#, which makes #v# red and #u# black. A call to #flipRight(w)# promotes #v# to the root of the subtree. At this point #w# is red, and the code branches two ways -depending on the color of #w#'s left child, #q#. +depending on the colour of #w#'s left child, #q#. -If #q# is red, then the code finishes up exactly the same way that -Case~2 finishes up, but is even simpler since there is no danger of #v# -not satisfying the left-leaning property. +If #q# is red, then the code finishes up exactly the same way as Case~2 +finishes up, but is even simpler since there is no danger of #v# not +satisfying the left-leaning property. The more complicated case occurs when #q# is black. In this case, -we examine the color of #v#'s left child. If it is red, then #v# has +we examine the colour of #v#'s left child. If it is red, then #v# has two red children and its extra black can be pushed down with a call to -#pushBlack(v)#. At this point, #v# now has #w#'s original color and we +#pushBlack(v)#. At this point, #v# now has #w#'s original colour, and we are done. -If #v#'s left child is black then #v# violates the left-leaning property +If #v#'s left child is black, then #v# violates the left-leaning property, and we restore this with a call to #flipLeft(v)#. The next iteration of #removeFixup(u)# then continues with $#u#=#v#$. \codeimport{ods/RedBlackTree.removeFixupCase3(u)}. @@ -513,7 +519,7 @@ \section{Summary} #n#)$ worst-case time per operation. \end{thm} -Not included in the above theorem is the extra bonus +Not included in the above theorem is the following extra bonus: \begin{thm}\thmlabel{redblack-amortized} Beginning with an empty #RedBlackTree#, any sequence of $m$ @@ -522,16 +528,17 @@ \section{Summary} \end{thm} We will only sketch a proof of \thmref{redblack-amortized}. By comparing -#addFixup(u)# and #removeFixup(u)# with the algorithms for adding -or removing a leaf in a 2-4 tree, we can convince ourselves that this -property is something that is inherited from a 2-4 tree. In particular, -if we can show that the total time spent splitting, merging, and borrowing -in a 2-4 tree is $O(m)$, then this implies \thmref{redblack-amortized}. - -The proof of this for 2-4 trees uses the potential method of amortized -analysis.\footnote{See the proofs of \lemref{dualarraydeque-amortized} -and \lemref{selist-amortized} for other applications of the potential -method.} Define the potential of an internal node #u# in a 2-4 tree as +#addFixup(u)# and #removeFixup(u)# with the algorithms for adding or +removing a leaf in a 2-4 tree, we can convince ourselves that this +property is inherited from a 2-4 tree. In particular, if we can show +that the total time spent splitting, merging, and borrowing in a 2-4 +tree is $O(m)$, then this implies \thmref{redblack-amortized}. + +The proof of this theorem for 2-4 trees uses the potential +method of amortized analysis.\footnote{See the proofs of +\lemref{dualarraydeque-amortized} and \lemref{selist-amortized} for +other applications of the potential method.} Define the potential of an +internal node #u# in a 2-4 tree as \[ \Phi(#u#) = \begin{cases} @@ -541,25 +548,25 @@ \section{Summary} \end{cases} \] and the potential of a 2-4 tree as the sum of the potentials of its nodes. -When a split occurs, it is because a node of degree 4 becomes two nodes, -one of degree 2 and one of degree 3. This means that the overall -potential drops by $3-1-0 = 2$. When a merge occurs, two nodes that -used to have degree 2 are replaced by one node of degree 3. The result is -a drop in potential of $2-0=2$. Therefore, for every split or merge, -the potential decreases by $2$. - -Next notice that, if we ignore splitting and merging of nodes, there -are only a constant number of nodes whose number of children is changed -by the addition or removal of a leaf. When adding a node, one node -has its number of children increase by 1, increasing the potential by -at most $3$. During the removal of a leaf, one node has its number of -children decrease by 1, increasing the potential by at most $1$, and two -nodes may be involved in a borrowing operation, increasing their total -potential by at most $1$. +When a split occurs, it is because a node with four children becomes +two nodes, with two and three children. This means that the overall +potential drops by $3-1-0 = 2$. When a merge occurs, two nodes that used +to have two children are replaced by one node with three children. The +result is a drop in potential of $2-0=2$. Therefore, for every split +or merge, the potential decreases by two. + +Next notice that, if we ignore splitting and merging of nodes, there are +only a constant number of nodes whose number of children is changed by +the addition or removal of a leaf. When adding a node, one node has +its number of children increase by one, increasing the potential by +at most three. During the removal of a leaf, one node has its number +of children decrease by one, increasing the potential by at most one, +and two nodes may be involved in a borrowing operation, increasing their +total potential by at most one. To summarize, each merge and split causes the potential to drop by -at least 2. Ignoring merging and splitting, each addition or removal -causes the potential to rise by at most 3, and the potential is always +at least two. Ignoring merging and splitting, each addition or removal +causes the potential to rise by at most three, and the potential is always non-negative. Therefore, the number of splits and merges caused by $m$ additions or removals on an initially empty tree is at most $3m/2$. \thmref{redblack-amortized} is a consequence of this analysis and the @@ -603,15 +610,15 @@ \section{Discussion and Exercises} The height-balanced property can be maintained during #add(x)# and #remove(x)# operations by walking back up the path to the root and performing a rebalancing operation at each node #u# where the height of -#u#'s left and right subtrees differ by 2. See \figref{avl-rebalance}. +#u#'s left and right subtrees differ by two. See \figref{avl-rebalance}. \begin{figure} \begin{center} \includegraphics{figs/avl-rebalance} \end{center} - \caption{Rebalancing in an AVL tree. At most 2 rotations are required - to convert a node whose subtrees have height $h$ and $h+2$ into a node - whose subtrees each have height at most $h+1$.} + \caption{Rebalancing in an AVL tree. At most two rotations are required + to convert a node whose subtrees have a height of $h$ and $h+2$ into a node + whose subtrees each have a height of at most $h+1$.} \figlabel{avl-rebalance} \end{figure} @@ -623,7 +630,7 @@ \section{Discussion and Exercises} \begin{figure} \centering{\includegraphics{figs/redblack-example}} - \caption{A red-black tree to practice on.} + \caption{A red-black tree on which to practice.} \figlabel{redblack-example2} \end{figure} @@ -672,18 +679,18 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Suppose you are given a binary search tree with #n# nodes and height - at most $2\log #n#-2$. Is it always possible to color the nodes red - and black so that the tree satisfies the black-height and no-red-edge - properties? If so, can it also be made to satisfy the left-leaning - property? + Suppose you are given a binary search tree with #n# nodes and a + height of at most $2\log #n#-2$. Is it always possible to colour the + nodes red and black so that the tree satisfies the black-height and + no-red-edge properties? If so, can it also be made to satisfy the + left-leaning property? \end{exc} \begin{exc}\exclabel{redblack-merge} Suppose you have two red-black trees $T_1$ and $T_2$ that have the - same black height, $h$, and that the largest key in $T_1$ is smaller + same black height, $h$, and such that the largest key in $T_1$ is smaller than the smallest key in $T_2$. Show how to merge $T_1$ and $T_2$ - in into a single red-black tree in $O(h)$ time. + into a single red-black tree in $O(h)$ time. \end{exc} \begin{exc} @@ -696,7 +703,7 @@ \section{Discussion and Exercises} \begin{exc} Prove that, during an #add(x)# operation, an AVL tree must perform - at most one rebalancing operation (that involves at most 2 rotations; + at most one rebalancing operation (that involves at most two rotations; see \figref{avl-rebalance}). Give an example of an AVL tree and a #remove(x)# operation on that tree that requires on the order of $\log #n#$ rebalancing operations. diff --git a/latex/scapegoat.tex b/latex/scapegoat.tex index d9a16afb..592c19bc 100644 --- a/latex/scapegoat.tex +++ b/latex/scapegoat.tex @@ -2,11 +2,10 @@ \chapter{Scapegoat Trees} \chaplabel{scapegoat} In this chapter, we study a binary search tree data structure, the -#ScapegoatTree#. -This structure is based on the common wisdom that, when something goes -wrong, the first thing we should do is find someone to blame it on (the -\emph{scapegoat}). Once blame is firmly established, we can leave the -scapegoat to fix the problem. +#ScapegoatTree#. This structure is based on the common wisdom that, +when something goes wrong, the first thing people tend to do is find +someone to blame (the \emph{scapegoat}). Once blame is firmly +established, we can leave the scapegoat to fix the problem. A #ScapegoatTree# keeps itself balanced by \emph{partial rebuilding operations}. During a partial rebuilding operation, an entire subtree is @@ -65,11 +64,11 @@ \section{#ScapegoatTree#: A Binary Search Tree with Partial Rebuilding} anything else. Unfortunately, it will sometimes happen that $#depth(u)# > \log_{3/2} -#q#$. In this case we need to do something to reduce the height. -This isn't a big job; there is only one node, namely #u#, whose depth -exceeds $\log_{3/2} #q#$. To fix #u#, we walk from #u# back up to the -root looking for a \emph{scapegoat}, #w#. The scapegoat, #w#, is a very -unbalanced node. It has the property that +#q#$. In this case, we need to reduce the height. This isn't a big +job; there is only one node, namely #u#, whose depth exceeds $\log_{3/2} +#q#$. To fix #u#, we walk from #u# back up to the root looking for a +\emph{scapegoat}, #w#. The scapegoat, #w#, is a very unbalanced node. +It has the property that \begin{equation} \frac{#size(w.child)#}{#size(w)#} > \frac{2}{3} \enspace , \eqlabel{scapegoat} @@ -102,7 +101,7 @@ \section{#ScapegoatTree#: A Binary Search Tree with Partial Rebuilding} The implementation of #remove(x)# in a #ScapegoatTree# is very simple. We search for #x# and remove it using the usual algorithm for removing a node from a #BinarySearchTree#. (Note that this can never increase the -height of the tree.) Next, we decrement #n# but leave #q# unchanged. +height of the tree.) Next, we decrement #n#, but leave #q# unchanged. Finally, we check if $#q# > 2#n#$ and, if so, we \emph{rebuild the entire tree} into a perfectly balanced binary search tree and set $#q#=#n#$. \codeimport{ods/ScapegoatTree.remove(x)} @@ -112,7 +111,7 @@ \section{#ScapegoatTree#: A Binary Search Tree with Partial Rebuilding} \subsection{Analysis of Correctness and Running-Time} -In this section we analyze the correctness and amortized running time +In this section, we analyze the correctness and amortized running time of operations on a #ScapegoatTree#. We first prove the correctness by showing that, when the #add(x)# operation results in a node that violates Condition \myeqref{scapegoat-height}, then we can always find a scapegoat: @@ -149,7 +148,7 @@ \subsection{Analysis of Correctness and Running-Time} \] \end{proof} -Next, we analyze the parts of the running time that we have not yet +Next, we analyze the parts of the running time that are not yet accounted for. There are two parts: The cost of calls to #size(u)# when search for scapegoat nodes, and the cost of calls to #rebuild(w)# when we find a scapegoat #w#. The cost of calls to #size(u)# can be @@ -206,7 +205,7 @@ \subsection{Analysis of Correctness and Running-Time} During an insertion or deletion, we give one credit to each node on the path to the inserted node, or deleted node, #u#. In this way we hand out at most $\log_{3/2}#q#\le \log_{3/2}m$ credits per operation. - During a deletion we also store an additional 1 credit ``on the side.'' + During a deletion we also store an additional credit ``on the side.'' Thus, in total we give out at most $O(m\log m)$ credits. All that remains is to show that these credits are sufficient to pay for all calls to #rebuild(u)#. @@ -244,7 +243,7 @@ \subsection{Analysis of Correctness and Running-Time} call #rebuild(u)#. If we call #rebuild(u)# during a deletion, it is because $#q# > 2#n#$. - In this case, we have $#q#-#n#> #n#$ credits stored ``on the side'' and + In this case, we have $#q#-#n#> #n#$ credits stored ``on the side,'' and we use these to pay for the $O(#n#)$ time it takes to rebuild the root. This completes the proof. \end{proof} @@ -290,8 +289,8 @@ \section{Discussion and Exercises} that there are sequences of #n# operations in which a #ScapegoatTree# will spend on the order of $#n#\log #n#$ time in calls to #rebuild(u)#. This is in contrast to other #SSet# implementations discussed in this -book that only make $O(#n#)$ structural changes during a sequence of -#n# operations. This is, unfortunately, a necessary consequence of +book, which only make $O(#n#)$ structural changes during a sequence +of #n# operations. This is, unfortunately, a necessary consequence of the fact that a #ScapegoatTree# does all its restructuring by calls to #rebuild(u)# \cite{d90}. @@ -335,12 +334,11 @@ \section{Discussion and Exercises} \begin{exc}\exclabel{scapegoat-quicksize} Modify the #add(x)# method of the #ScapegoatTree# so that it does not - waste any time recomputing the sizes of subtrees that it has already - computed the size of. This is possible because, by the time the method + waste any time recomputing the sizes of subtrees that have already + been computed. This is possible because, by the time the method wants to compute #size(w)#, it has already computed #size(w.left)# - or #size(w.right)#. - Compare the performance of your modified implementation with the - implementation given here. + or #size(w.right)#. Compare the performance of your modified + implementation with the implementation given here. \end{exc} \begin{exc}\exclabel{scapegoat-explicitsize} @@ -430,6 +428,6 @@ \section{Discussion and Exercises} in the sequence. To implement #testBefore(e1,e2)# in constant time, each element #e# is labelled with an integer that encodes the path from the root to #e#. In this way, #testBefore(e1,e2)# can be implemented - just by comparing the labels of #e1# and #e2#. + by comparing the labels of #e1# and #e2#. \end{exc} diff --git a/latex/skiplists.tex b/latex/skiplists.tex index 42c89383..c5513930 100644 --- a/latex/skiplists.tex +++ b/latex/skiplists.tex @@ -3,21 +3,20 @@ \chapter{Skiplists} \chaplabel{skiplists} In this chapter, we discuss a beautiful data structure: the skiplist, -that has a variety of applications. Using a skiplist we can implement -a #List# that is fast for all the operations #get(i)#, #set(i,x)#, -#add(i,x)#, and #remove(i)#. We can also implement an #SSet# in which -all operations run in $O(\log #n#)$ expected time. +which has a variety of applications. Using a skiplist we can implement a +#List# that has fast implementations of #get(i)#, #set(i,x)#, #add(i,x)#, +and #remove(i)#. We can also implement an #SSet# in which all operations +run in $O(\log #n#)$ expected time. %Finally, a skiplist can be used to implement a #Rope# in which all %operations run in $O(\log #n#)$ time. -Skiplists rely on \emph{randomization} for their efficiency. -In particular, a skiplist uses random coin tosses when an element is -inserted to determine the height of that element. The performance -of skiplists is expressed in terms of \emph{expected} running times -and lengths of paths. This expectation is taken over the random coin -tosses used by the skiplist. In the implementation, the random coin -tosses used by a skiplist are simulated using a pseudo-random number -(or bit) generator. +The efficiency of skiplists relies on their use of \emph{randomization}. +When a new element is added to a skiplist, the skiplist uses random coin +tosses to determine the height of the new element. The performance of +skiplists is expressed in terms of \emph{expected} running times and path +lengths. This expectation is taken over the random coin tosses used by +the skiplist. In the implementation, the random coin tosses used by a +skiplist are simulated using a pseudo-random number (or bit) generator. \section{The Basic Structure} @@ -26,7 +25,7 @@ \section{The Basic Structure} in $L_{r-1}$. We start with the input list $L_0$ that contains #n# items and construct $L_1$ from $L_0$, $L_2$ from $L_1$, and so on. The items in $L_r$ are obtained by tossing a coin for each element, #x#, -in $L_{r-1}$ and including #x# in $L_r$ if the coin comes up heads. +in $L_{r-1}$ and including #x# in $L_r$ if the coin turns up as heads. This process ends when we create a list $L_r$ that is empty. An example of a skiplist is shown in \figref{skiplist}. @@ -42,10 +41,10 @@ \section{The Basic Structure} largest value $r$ such that #x# appears in $L_r$. Thus, for example, elements that only appear in $L_0$ have height $0$. If we spend a few moments thinking about it, we notice that the height of #x# corresponds -to the following experiment: Toss a coin repeatedly until the first time -it comes up tails. How many times did it come up heads? The answer, -not surprisingly, is that the expected height of a node is 1. (We expect -to toss the coin twice before getting tails, but we don't count the last +to the following experiment: Toss a coin repeatedly until it comes +up as tails. How many times did it come up as heads? The answer, not +surprisingly, is that the expected height of a node is 1. (We expect to +toss the coin twice before getting tails, but we don't count the last toss.) The \emph{height} of a skiplist is the height of its tallest node. At the head of every list is a special node, called the \emph{sentinel}, @@ -57,7 +56,7 @@ \section{The Basic Structure} and always go right unless that would overshoot #u#, in which case you should take a step down into the list below. -More precisely, to construct the search path for the node #u# in $L_0$ +More precisely, to construct the search path for the node #u# in $L_0$, we start at the sentinel, #w#, in $L_h$. Next, we examine #w.next#. If #w.next# contains an item that appears before #u# in $L_0$, then we set $#w#=#w.next#$. Otherwise, we move down and continue the search @@ -101,7 +100,7 @@ \section{#SkiplistSSet#: An Efficient #SSet# Implementation} \seclabel{skiplistset} A #SkiplistSSet# uses a skiplist structure to implement the #SSet# -interface. When used this way, the list $L_0$ stores the elements of +interface. When used in this way, the list $L_0$ stores the elements of the #SSet# in sorted order. The #find(x)# method works by following the search path for the smallest value #y# such that $#y#\ge#x#$: @@ -109,14 +108,15 @@ \section{#SkiplistSSet#: An Efficient #SSet# Implementation} Following the search path for #y# is easy: when situated at some node, #u#, in $L_{#r#}$, we look right to #u.next[r].x#. -If $#x#>#u.next[r].x#$, then we take a step to the right in $L_{#r#}$, -otherwise we move down into $L_{#r#-1}$. Each step (right or down) in -this search takes only constant time so, by \lemref{skiplist-searchpath}, -the expected running time of #find(x)# is $O(\log #n#)$. +If $#x#>#u.next[r].x#$, then we take a step to the right in +$L_{#r#}$; otherwise, we move down into $L_{#r#-1}$. Each step +(right or down) in this search takes only constant time; thus, by +\lemref{skiplist-searchpath}, the expected running time of #find(x)# +is $O(\log #n#)$. Before we can add an element to a #SkipListSSet#, we need a method to simulate tossing coins to determine the height, #k#, of a new node. -We do this by picking a random integer, #z#, and counting the number of +We do so by picking a random integer, #z#, and counting the number of trailing $1$s in the binary representation of #z#:\footnote{This method does not exactly replicate the coin-tossing experiment since the value of #k# will always be less than the number of bits in an #int#. However, @@ -174,10 +174,11 @@ \subsection{Summary} \section{#SkiplistList#: An Efficient Random-Access #List# Implementation} \seclabel{skiplistlist} -A #SkiplistList# implements the #List# interface on top of a skiplist structure. -In a #SkiplistList#, $L_0$ contains the elements of the -list in the order they appear in the list. Just like with a #SkiplistSSet#, -elements can be added, removed, and accessed in $O(\log #n#)$ time. +A #SkiplistList# implements the #List# interface using a skiplist +structure. In a #SkiplistList#, $L_0$ contains the elements of the +list in the order in which they appear in the list. As in a +#SkiplistSSet#, elements can be added, removed, and accessed in $O(\log +#n#)$ time. For this to be possible, we need a way to follow the search path for the #i#th element in $L_0$. The easiest way to do this is to define @@ -205,9 +206,8 @@ \section{#SkiplistList#: An Efficient Random-Access #List# Implementation} edge of length $\ell$, then we move to a node whose position, in $L_0$, is $#j#+\ell$. In this way, while following a search path, we can keep track of the position, #j#, of the current node in $L_0$. When at a -node, #u#, in $L_{#r#}$, we go right if #j# -plus the length of the edge #u.next[r]# is less than #i#, otherwise we go -down into $L_{#r#-1}$. +node, #u#, in $L_{#r#}$, we go right if #j# plus the length of the edge +#u.next[r]# is less than #i#. Otherwise, we go down into $L_{#r#-1}$. \codeimport{ods/SkiplistList.findPred(i)} \codeimport{ods/SkiplistList.get(i).set(i,x)} @@ -221,7 +221,7 @@ \section{#SkiplistList#: An Efficient Random-Access #List# Implementation} node will actually be added, so we can do the addition at the same time as we search for the new node's location. We first pick the height, #k#, of the newly inserted node, #w#, and then follow the search path for #i#. -Anytime the search path moves down from $L_{#r#}$ with $#r#\le #k#$, we +Any time the search path moves down from $L_{#r#}$ with $#r#\le #k#$, we splice #w# into $L_{#r#}$. The only extra care needed is to ensure that the lengths of edges are updated properly. See \figref{skiplist-addix}. @@ -253,7 +253,7 @@ \section{#SkiplistList#: An Efficient Random-Access #List# Implementation} \figlabel{skiplist-lengths-splice} \end{figure} -This sounds more complicated than it actually is and the code is actually +This sounds more complicated than it is, for the code is actually quite simple: \codeimport{ods/SkiplistList.add(i,x)} @@ -399,15 +399,15 @@ \section{Analysis of Skiplists} The number of nodes that the reverse search path visits at a particular level, #r#, is related to the following experiment: Toss a coin. - If the coin comes up heads then go up and stop, otherwise go left and - repeat the experiment. The number of coin tosses before the heads then - represents the number of steps to the left that a reverse search path - takes at a particular level.\footnote{Note that this might overcount - the number of steps to the left, since the experiment should end either at - the first heads or when the search path reaches the sentinel, whichever - comes first. This is not a problem since the lemma is only stating an - upper bound.} \lemref{coin-tosses} tells us that the expected number - of coin tosses before the first heads is 1. + If the coin comes up as heads, then move up and stop. Otherwise, move + left and repeat the experiment. The number of coin tosses before + the heads represents the number of steps to the left that a reverse + search path takes at a particular level.\footnote{Note that this + might overcount the number of steps to the left, since the experiment + should end either at the first heads or when the search path reaches + the sentinel, whichever comes first. This is not a problem since the + lemma is only stating an upper bound.} \lemref{coin-tosses} tells us + that the expected number of coin tosses before the first heads is 1. Let $S_{#r#}$ denote the number of steps the forward search path takes at level $#r#$ that go to the right. We have just argued that $\E[S_{#r#}]\le @@ -455,12 +455,12 @@ \section{Discussion and Exercises} Skiplists were introduced by Pugh \cite{p91} who also presented a number of applications of skiplists \cite{p89}. Since then they have been studied extensively. Several researchers have done very -precise analysis of the expected length and variance in length of the +precise analyses of the expected length and variance of the length of the search path for the #i#th element in a skiplist \cite{kp94,kmp95,pmp92}. Deterministic versions \cite{mps92}, biased versions \cite{bbg02,esss01}, and self-adjusting versions \cite{bdl08} of skiplists have all been developed. Skiplist implementations have been written for various -languages and frameworks and have seen use in open-source database +languages and frameworks and have been used in open-source database systems \cite{skipdb,redis}. A variant of skiplists is used in the HP-UX operating system kernel's process management structures \cite{hpux}. \javaonly{Skiplists are even part of the Java 1.6 API \cite{oracle_jdk6}.} @@ -472,8 +472,8 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Illustrate the addition of the values 0.5 (with height 1) and then 3.5 - (with height 2) to the skiplist in \figref{skiplist}. + Illustrate the addition of the values 0.5 (with a height of 1) and + then 3.5 (with a height of 2) to the skiplist in \figref{skiplist}. \end{exc} \begin{exc} @@ -545,13 +545,14 @@ \section{Discussion and Exercises} It is possible to prove that the expected number of steps required for a finger search is $O(1+\log r)$, where $r$ is the number values in $L_0$ between #x# and the value pointed to by the finger. - + Implement a subclass of #Skiplist# called #SkiplistWithFinger# that - does all #find(x)# operations using an internal finger. This class - stores a finger and does every search as a finger search. During the - search it also updates the finger so that each #find(x)# operation - uses, as a starting point, a finger that points to the result of the - previous #find(x)# operation. + implements #find(x)# operations using an internal finger. This subclass + stores a finger, which is then used so that every #find(x)# operation + is implemented as a finger search. During each #find(x)# operation + the finger is updated so that each #find(x)# operation uses, as a + starting point, a finger that points to the result of the previous + #find(x)# operation. \end{exc} \begin{exc}\exclabel{skiplist-truncate} @@ -573,12 +574,12 @@ \section{Discussion and Exercises} \end{exc} \begin{exc} - Using the ideas from the space-efficient linked-list, #SEList#, - design and implement a space-efficient #SSet#, #SESSet#. Do this by - storing the data, in order, in an #SEList# and then storing the blocks - of this #SEList# in an #SSet#. If the original #SSet# implementation - uses $O(#n#)$ space to store #n# elements, then the #SESSet# will use - enough space for #n# elements plus $O(#n#/#b#+#b#)$ wasted space. + Using the ideas from the space-efficient linked-list, #SEList#, design + and implement a space-efficient #SSet#, #SESSet#. To do this, store the + data, in order, in an #SEList#, and store the blocks of this #SEList# + in an #SSet#. If the original #SSet# implementation uses $O(#n#)$ + space to store #n# elements, then the #SESSet# will use enough space + for #n# elements plus $O(#n#/#b#+#b#)$ wasted space. \end{exc} \begin{exc} @@ -594,20 +595,20 @@ \section{Discussion and Exercises} \noindent Hint 2: Any suffix can be represented compactly as a single integer indicating where the suffix begins in the text. - \noindent Test your application on some large texts like some of the books - available at Project Gutenberg \cite{gutenberg}. If done correctly, your - applications will be very responsive; there should be no noticeable lag - between typing keystrokes and the results appearing. + \noindent Test your application on some large texts, such as some of + the books available at Project Gutenberg \cite{gutenberg}. If done + correctly, your applications will be very responsive; there should be + no noticeable lag between typing keystrokes and seeing the results. \end{exc} \begin{exc} - (This excercise is to be done after reading about binary search trees, + (This excercise should be done after reading about binary search trees, in \secref{binarysearchtree}.) Compare skiplists with binary search trees in the following ways: \begin{enumerate} - \item Explain how removing some edges of a skiplist lead to - a structure that looks like a binary tree and that is similar to - a binary search tree. + \item Explain how removing some edges of a skiplist leads to + a structure that looks like a binary tree and is similar to a + binary search tree. \item Skiplists and binary search trees each use about the same number of pointers (2 per node). Skiplists make better use of those pointers, though. Explain why. diff --git a/latex/snarf-java.pl b/latex/snarf-java.pl index 27f04407..6813d79d 100755 --- a/latex/snarf-java.pl +++ b/latex/snarf-java.pl @@ -126,7 +126,7 @@ ($$) $inside = color($inside); $inside =~ s/([%&])/\\$1/g; $inside =~ s/(\\\&|\\\%|<<|>>>?)/\\text{\\ttfamily $1}/g; - $inside = "\\ensuremath{\\mathtt{$inside}}"; + $inside = "\\ensuremath{\\mathtt{$inside}}"; # should be mathtt } $line =~ s/#([^#])*#/$inside/; } @@ -140,7 +140,7 @@ ($$) #print('\renewcommand{\baselinestretch}{1}'."\n"); #print("\\resizebox{.98\\textwidth}{!}{"); print("\ \\hspace{.5ex}\n"); - print("\\begin{Verbatim}[fontsize=\\small,gobble=1,tabsize=2,frame=single"); + print("\\begin{Verbatim}[gobble=1,tabsize=2,frame=single"); print(',commandchars=\\\\@\\$'); print(",label=\\texttt{$class},labelposition=topline"); print("]\n"); diff --git a/latex/sorting.tex b/latex/sorting.tex index fec0fa60..d24be78e 100644 --- a/latex/sorting.tex +++ b/latex/sorting.tex @@ -12,7 +12,7 @@ \chapter{Sorting Algorithms} comparisons and presents three algorithms that run in $O(#n#\log #n#)$ time. As it turns out, all three algorithms are asymptotically optimal; no algorithm that uses only comparisons can avoid doing roughly $#n#\log -#n#$ comparisons in the worst-case and even the average-case. +#n#$ comparisons in the worst case and even the average case. Before continuing, we should note that any of the #SSet# or priority #Queue# implementations presented in previous chapters can also @@ -37,12 +37,12 @@ \chapter{Sorting Algorithms} \section{Comparison-Based Sorting} In this section, we present three sorting algorithms: merge-sort, -quicksort, and heap-sort. All these algorithms take an input array #a# +quicksort, and heap-sort. Each of these algorithms take an input array #a# and sort the elements of #a# into non-decreasing order in $O(#n#\log #n#)$ (expected) time. These algorithms are all \emph{comparison-based}. \javaonly{Their second argument, #c#, is a #Comparator# that implements the #compare(a,b)# method.} These algorithms don't care what type -of data is being sorted, the only operation they do on the data is +of data is being sorted; the only operation they do on the data is comparisons using the #compare(a,b)# method. Recall, from \secref{sset}, that #compare(a,b)# returns a negative value if $#a#<#b#$, a positive value if $#a#>#b#$, and zero if $#a#=#b#$. @@ -79,14 +79,14 @@ \subsection{Merge-Sort} To understand the running-time of merge-sort, it is easiest to think of it in terms of its recursion tree. Suppose for now that #n# is a -power of 2, so that $#n#=2^{\log #n#}$, and $\log #n#$ is an integer. +power of two, so that $#n#=2^{\log #n#}$, and $\log #n#$ is an integer. Refer to \figref{mergesort-recursion}. Merge-sort turns the problem of -sorting #n# elements into 2 problems, each of sorting $#n#/2$ elements. -These two subproblem are then turned into 2 problems each, for a total -of 4 subproblems, each of size $#n#/4$. These 4 subproblems become 8 +sorting #n# elements into two problems, each of sorting $#n#/2$ elements. +These two subproblem are then turned into two problems each, for a total +of four subproblems, each of size $#n#/4$. These four subproblems become eight subproblems, each of size $#n#/8$, and so on. At the bottom of this process, -$#n#/2$ subproblems, each of size 2, are converted into #n# problems, -each of size $#1#$. For each subproblem of size $#n#/2^{i}$, the time +$#n#/2$ subproblems, each of size two, are converted into #n# problems, +each of size one. For each subproblem of size $#n#/2^{i}$, the time spent merging and copying data is $O(#n#/2^i)$. Since there are $2^i$ subproblems of size $#n#/2^i$, the total time spent working on problems of size $2^i$, not counting recursive calls, is @@ -132,7 +132,7 @@ \subsection{Merge-Sort} &< #n#\log #n# \enspace . \end{align*} The case where $#n#$ is odd is slightly more complicated. For this case, -we use two inequalities, that are easy to verify: +we use two inequalities that are easy to verify: \begin{equation} \log(x+1) \le \log(x) + 1 \enspace , \eqlabel{log-ineq-a} \end{equation} @@ -161,7 +161,7 @@ \subsection{Quicksort} The \emph{quicksort} algorithm is another classic divide and conquer algorithm. Unlike merge-sort, which does merging after solving the two -subproblems, quicksort does all its work upfront. +subproblems, quicksort does all of its work upfront. Quicksort is simple to describe: Pick a random \emph{pivot} element, #x#, from #a#; partition #a# into the set of elements less than #x#, the @@ -197,8 +197,8 @@ \subsection{Quicksort} first and last of these conditions. At each step, the element at position #j# is either moved to the front, left where it is, or moved to the back. In the first two cases, #j# is incremented, while in the last case, #j# -is not incremented since the new element at position #j# has not been -processed yet. +is not incremented since the new element at position #j# has not yet been +processed. Quicksort is very closely related to the random binary search trees studied in \secref{rbst}. In fact, if the input to quicksort consists @@ -207,7 +207,7 @@ \subsection{Quicksort} binary search tree the first thing we do is pick a random element #x# and make it the root of the tree. After this, every element will eventually be compared to #x#, with smaller elements going into the left subtree -and larger elements going into the right subtree. +and larger elements into the right. In quicksort, we select a random element #x# and immediately compare everything to #x#, putting the smaller elements at the beginning of @@ -226,7 +226,7 @@ \subsection{Quicksort} to a pivot element is at most $H_{#i#+1} + H_{#n#-#i#}$. \end{lem} -A little summing of harmonic numbers gives us the following theorem +A little summing up of harmonic numbers gives us the following theorem about the running time of quicksort: \begin{thm}\thmlabel{quicksort-i} @@ -250,7 +250,7 @@ \subsection{Quicksort} all distinct. When the input array, #a#, contains duplicate elements, the expected running time of quicksort is no worse, and can be even better; any time a duplicate element #x# is chosen as a pivot, all -occurrences of #x# get grouped together and don't take part in either +occurrences of #x# get grouped together and do not take part in either of the two subproblems. \begin{thm}\thmlabel{quicksort} @@ -306,7 +306,7 @@ \subsection{Heap-sort} of size 1. Now, working backwards, we can call #trickleDown(i)# for each $#i#\in\{\lfloor #n#/2\rfloor-1,\ldots,0\}$. This works, because by the time we call #trickleDown(i)#, each of the two children of #a[i]# -are the root of a sub-heap so calling #trickleDown(i)# makes #a[i]# +are the root of a sub-heap, so calling #trickleDown(i)# makes #a[i]# into the root of its own subheap. \javaimport{ods/BinaryHeap.BinaryHeap(a,c)} \cppimport{ods/BinaryHeap.BinaryHeap(b)} @@ -314,8 +314,8 @@ \subsection{Heap-sort} The interesting thing about this bottom-up strategy is that it is more efficient than calling #add(x)# #n# times. To see this, notice that, for $#n#/2$ elements, we do no work at all, for $#n#/4$ elements, we call -#trickleDown(i)# on a subheap rooted at #a[i]# and whose height is 1, for -$#n#/8$ elements, we call #trickleDown(i)# on a subheap whose height is 2, +#trickleDown(i)# on a subheap rooted at #a[i]# and whose height is one, for +$#n#/8$ elements, we call #trickleDown(i)# on a subheap whose height is two, and so on. Since the work done by #trickleDown(i)# is proportional to the height of the sub-heap rooted at #a[i]#, this means that the total work done is at most @@ -327,7 +327,7 @@ \subsection{Heap-sort} \] The second-last equality follows by recognizing that the sum $\sum_{i=1}^{\infty} i/2^{i}$ is equal, by definition, to the expected -number times we toss a coin up to and including the first time the coin +number of times we toss a coin up to and including the first time the coin comes up as heads and applying \lemref{coin-tosses}. The following theorem describes the performance of #heapSort(a,c)#. @@ -337,7 +337,7 @@ \subsection{Heap-sort} \end{thm} \begin{proof} -The algorithm runs in 3 steps: (1)~Transforming #a# into a heap, +The algorithm runs in three steps: (1)~transforming #a# into a heap, (2)~repeatedly extracting the minimum element from #a#, and (3)~reversing the elements in #a#. We have just argued that step~1 takes $O(#n#)$ time and performs $O(#n#)$ comparisons. Step~3 takes $O(#n#)$ time and @@ -358,7 +358,7 @@ \subsection{A Lower-Bound for Comparison-Based Sorting} We have now seen three comparison-based sorting algorithms that each run in $O(#n#\log #n#)$ time. By now, we should be wondering if faster algorithms exist. The short answer to this question is no. If the -only operations allowed on the elements of #a# are comparisons then no +only operations allowed on the elements of #a# are comparisons, then no algorithm can avoid doing roughly $#n#\log #n#$ comparisons. This is not difficult to prove, but requires a little imagination. Ultimately, it follows from the fact that @@ -389,7 +389,7 @@ \subsection{A Lower-Bound for Comparison-Based Sorting} If $#a[u.i]#<#a[u.j]#$ the algorithm proceeds to the left subtree, otherwise it proceeds to the right subtree. Each leaf #w# of this tree is labelled with a permutation $#w.p[0]#,\ldots,#w.p[n-1]#$ of -$0,\ldots,#n#-1$. This permutation represents the permutation that is +$0,\ldots,#n#-1$. This permutation represents the one that is required to sort #a# if the comparison tree reaches this leaf. That is, \[ #a[w.p[0]]#<#a[w.p[1]]#<\cdots<#a[w.p[n-1]]# \enspace . @@ -405,13 +405,13 @@ \subsection{A Lower-Bound for Comparison-Based Sorting} \end{figure} The comparison tree for a sorting algorithm tells us everything about -the algorithm. It tells us exactly the sequence of comparisons that will -be performed for any input array, #a#, having #n# distinct elements and -it tells us how the algorithm will reorder #a# to sort it. An immediate -consequence of this is that the comparison tree must have at least $#n#!$ -leaves; if not, then there are two distinct permutations that lead to -the same leaf, so the algorithm does not correctly sort at least one of -these permutations. +the algorithm. It tells us exactly the sequence of comparisons that +will be performed for any input array, #a#, having #n# distinct elements +and it tells us how the algorithm will reorder #a# in order to sort it. +Consequently, the comparison tree must have at least $#n#!$ leaves; +if not, then there are two distinct permutations that lead to the same +leaf, so the algorithm does not correctly sort at least one of these +permutations. For example, the comparison tree in \figref{comparison-tree-2} has only $4< 3!=6$ leaves. Inspecting this tree, we see that the two input arrays @@ -440,7 +440,7 @@ \subsection{A Lower-Bound for Comparison-Based Sorting} \begin{proof} By the above discussion, the comparison tree defined by $\mathcal{A}$ must have at least $#n#!$ leaves. An easy inductive proof shows - that any binary tree with $k$ leaves has height at least $\log k$. + that any binary tree with $k$ leaves has a height of at least $\log k$. Therefore, the comparison tree for $\mathcal{A}$ has a leaf, #w#, of depth at least $\log(#n#!)$ and there is an input array #a# that leads to this leaf. The input array #a# is an input for which $\mathcal{A}$ @@ -454,7 +454,7 @@ \subsection{A Lower-Bound for Comparison-Based Sorting} The answer, again, is no. Again, the way to prove it is to think differently about what a randomized algorithm is. -In the following discussion, we will implicitly assume that our decision +In the following discussion, we will assume that our decision trees have been ``cleaned up'' in the following way: Any node that can not be reached by some input array #a# is removed. This cleaning up implies that the tree has exactly $#n#!$ leaves. It has at least $#n#!$ leaves @@ -464,12 +464,12 @@ \subsection{A Lower-Bound for Comparison-Based Sorting} We can think of a randomized sorting algorithm $\mathcal{R}$ as a deterministic algorithm that takes two inputs: The input array #a# -that should be sorted and a long sequence $b=b_1,b_2,b_3,\ldots,b_m$ of -random real numbers in the range $[0,1]$. The random numbers provide -the randomization. When the algorithm wants to toss a coin or make a -random choice, it does so by using some element from $b$. For example, -to compute the index of the first pivot in quicksort, the algorithm -could use the formula $\lfloor n b_1\rfloor$. +that should be sorted and a long sequence $b=b_1,b_2,b_3,\ldots,b_m$ +of random real numbers in the range $[0,1]$. The random numbers provide +the randomization for the algorithm. When the algorithm wants to toss a +coin or make a random choice, it does so by using some element from $b$. +For example, to compute the index of the first pivot in quicksort, +the algorithm could use the formula $\lfloor n b_1\rfloor$. Now, notice that if we fix $b$ to some particular sequence $\hat{b}$ then $\mathcal{R}$ becomes a deterministic sorting algorithm,