<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Mathematica Journal</title>
	<atom:link href="http://www.mathematica-journal.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mathematica-journal.com</link>
	<description></description>
	<lastBuildDate>Wed, 15 May 2013 18:56:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Strings</title>
		<link>http://www.mathematica-journal.com/2013/04/strings/</link>
		<comments>http://www.mathematica-journal.com/2013/04/strings/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 23:46:29 +0000</pubDate>
		<dc:creator>Paul Wellin</dc:creator>
				<category><![CDATA[Volume 15]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=33708</guid>
		<description><![CDATA[This article is an excerpt from the recently released book, Programming with Mathematica: An Introduction by Paul Wellin © 2013 [1]. The book, which follows on the well-known An Introduction to Mathematica Programming, provides an example-driven primer on the foundations of the Mathematica programming language.
Strings are used across many disciplines to represent filenames, data, and [...]]]></description>
			<content:encoded><![CDATA[<p>This article is an excerpt from the recently released book, <em>Programming with Mathematica: An Introduction</em> by Paul Wellin © 2013 [<a href="#Ref:1">1</a>]. The book, which follows on the well-known <em>An Introduction to Mathematica Programming</em>, provides an example-driven primer on the foundations of the <em>Mathematica</em> programming language.</p>
<p>Strings are used across many disciplines to represent filenames, data, and other objects: linguists working with text data study representation, classification, and patterns involved in audio and text usage; biologists dealing with genomic data as strings are interested in sequence structure and assembly and perform extensive statistical analysis of their data; programmers operate on string data for such tasks as text search, file manipulation, and text processing. Strings are so ubiquitous that almost every modern programming language has a string datatype and dozens of functions for operating on and with strings.<span id="more-33708"></span></p>
<h3>Introduction</h3>
<p>In <em>Mathematica</em>, strings are represented by any concatenation of characters enclosed in double quotes.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_1.gif" alt="" width="366" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_1.gif" alt="" width="29" height="13" /></p>
<p>Strings are also used to represent file names that you import and export.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_2.gif" alt="" width="229" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_2.gif" alt="" width="66" height="66" /></p>
<p>Strings are used as arguments, option values, and as the output to many functions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_3.gif" alt="" width="158" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_3.gif" alt="" width="540" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_4.gif" alt="" width="71" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_4.gif" alt="" width="29" height="13" /></p>
<p>In this chapter we will introduce the tools available for working with strings in <em>Mathematica</em>. We will begin with a look at the structure and syntax of strings, then move on to a discussion of the many high-level functions that are optimized for string manipulation. String patterns follow on the discussion of patterns in Chapter 4 and we will introduce an alternative syntax (regular expressions) that provides a very compact mechanism for working with strings. The chapter closes with several applied examples drawn from computer science (checksums) as well as bioinformatics (working with DNA sequences) and also word games (anagrams, blanagrams).</p>
<h3>9.1. Structure and Syntax</h3>
<p>Strings are expressions consisting of a number of characters enclosed in quotes. The characters can be anything you can type from your keyboard, including uppercase and lowercase letters, numbers, punctuation marks, and spaces. For example, here is the standard set of printable Ascii characters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_5.gif" alt="" width="168" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_5.gif" alt="" width="580" height="45" /></p>
<p>Other character sets are available as well. For example, here are the lowercase Greek letters. These are typically entered from one of <em>Mathematica</em>&#8217;s many built-in character palettes, or using a keyboard shortcut such as <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/EscapeKey.gif" alt="" width="14" height="18" />-<tt>a</tt>-<img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/EscapeKey.gif" alt="" width="14" height="18" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_1.gif" alt="" width="7" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_6.gif" alt="" width="168" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_6.gif" alt="" width="453" height="14" /></p>
<p>When <em>Mathematica</em> displays a string in output, it appears without the quotes. This is the default behavior of the formatting rules for <tt>OutputForm</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_7.gif" alt="" width="302" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_7.gif" alt="" width="288" height="14" /></p>
<p>Use <tt>InputForm</tt> or <tt>FullForm</tt> to display these quotes in output.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_8.gif" alt="" width="374" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_8.gif" alt="" width="302" height="14" /></p>
<p>Various predicates test whether a string consists entirely of letters, or uppercase and lowercase letters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_9.gif" alt="" width="143" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_9.gif" alt="" width="29" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_10.gif" alt="" width="92" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_10.gif" alt="" width="36" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_11.gif" alt="" width="150" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_11.gif" alt="" width="29" height="13" /></p>
<p>Use <tt>===</tt> (<tt>SameQ</tt>) to test for equality of strings.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_12.gif" alt="" width="109" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_12.gif" alt="" width="36" height="13" /></p>
<p>Several functions are available for working with the structure of strings.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_13.gif" alt="" width="345" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_13.gif" alt="" width="43" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_14.gif" alt="" width="402" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_14.gif" alt="" width="14" height="13" /></p>
<p><tt>StringLength</tt> also works with lists of strings. In other words, it has the <tt>Listable</tt> attribute.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_15.gif" alt="" width="458" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_15.gif" alt="" width="129" height="13" /></p>
<h4>Character Codes</h4>
<p>One way to work with strings is to convert them to a list of character codes and then operate on the codes using mathematical functions. Each character in a computer&#8217;s character set is assigned a number, called its <em>character code</em>. By general agreement, almost all computers use the same character codes, called the <em>Ascii code</em>. In this code, the uppercase letters <em>A</em>, <em>B</em>, &#8230;, <em>Z</em> are assigned the numbers 65, 66, &#8230;, 90 while the lowercase letters <em>a</em>, <em>b</em>, &#8230;, <em>z</em> have the numbers 97, 98, &#8230;, 122 (note that the number of an uppercase letter is 32 less than its lowercase version). The numbers 0, 1, &#8230;, 9 are coded as 48, 49, &#8230;, 57 while the punctuation marks period, comma, and exclamation point have the codes 46, 44, and 33, respectively. The space character is represented by the code 32. Table 9.1 shows the characters and their codes.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_PlacedGraphics_1.gif" alt="" width="201" height="154" /></p>
<div class="NumberedTableCaption"><strong>Table 9.1.</strong> Ascii character codes</div>
<p>Here are the printable Ascii characters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_16.gif" alt="" width="233" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_16.gif" alt="" width="580" height="46" /></p>
<p><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_2.gif" alt="" width="144" height="13" /> converts any string character <em>char</em> to its Ascii code.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_17.gif" alt="" width="129" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_17.gif" alt="" width="580" height="59" /></p>
<p>You can also get a list of the characters in a range if you know how they are ordered by their character codes.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_18.gif" alt="" width="168" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_18.gif" alt="" width="471" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_19.gif" alt="" width="193" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_19.gif" alt="" width="466" height="29" /></p>
<p>Characters from other languages can also be used, for example, Greek and Japanese.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_20.gif" alt="" width="248" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_20.gif" alt="" width="580" height="32" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_21.gif" alt="" width="273" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_21.gif" alt="" width="252" height="15" /></p>
<p>Unicode charts for many languages are available online (for example, <a href="http://www.unicode.org/charts" target="blank">www.unicode.org/charts)</a>. With these charts you can find the hexadecimal code for characters in many different languages. For Gujarati, the first character in its code table has hex value 0A90. Here we convert from base 16 and then display the character.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_22.gif" alt="" width="58" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_22.gif" alt="" width="29" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_23.gif" alt="" width="143" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_23.gif" alt="" width="9" height="15" /></p>
<p>Using the character code representation of characters, the following series of computations changes a word from lowercase to uppercase.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_24.gif" alt="" width="215" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_24.gif" alt="" width="334" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_25.gif" alt="" width="34" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_25.gif" alt="" width="278" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_26.gif" alt="" width="143" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_26.gif" alt="" width="79" height="13" /></p>
<p>Or, simply use a built-in function that is designed specifically for this task.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_27.gif" alt="" width="186" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_27.gif" alt="" width="79" height="13" /></p>
<h4>Sorting Lists of Characters</h4>
<p>As a practical example of the use of character codes, we will extend the simple sorting function from Chapter 4 to work with lists of string characters. Although written to operate on numbers, this rule can be overloaded to work on characters by making only a few small changes. Here is the original rule from Section 4.3.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_28.gif" alt="" width="506" height="14" /></p>
<p>The first change is to check that the patterns <tt>a</tt> and <tt>b</tt> have head <tt>String</tt> instead of testing for numbers with the predicate <tt>NumericQ</tt>. Second, instead of the numerical comparison <tt>b &lt; a</tt>, we need to compare their character codes.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_29.gif" alt="" width="189" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_28.gif" alt="" width="97" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_30.gif" alt="" width="486" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_29.gif" alt="" width="478" height="30" /></p>
<p>Here is a list of characters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_31.gif" alt="" width="413" height="14" /></p>
<p>Here is the sort.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_32.gif" alt="" width="124" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_30.gif" alt="" width="201" height="14" /></p>
<p>Section 9.5 explores the use of character codes to create hash tables, or checksums.</p>
<h4>Ordered Words</h4>
<p>When studying word or language structure, a common task is to find all words within a corpus that meet some criteria you are interested in. In this brief example, we will use character codes to search for words whose letters are &#8220;in order&#8221; when read from the first letter to the last. We will create a Boolean function <tt>OrderedWordQ</tt> that returns <tt>True</tt> or <tt>False</tt> depending upon whether its argument is in alphabetic order. So <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_3.gif" alt="" width="143" height="13" /> would return <tt>True</tt> but <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_4.gif" alt="" width="143" height="14" /> would return <tt>False</tt>. Then we will use this predicate to find all words in a dictionary that are ordered in this sense.</p>
<p>Start by getting a list of all words in the dictionary using <tt>DictionaryLookup</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_33.gif" alt="" width="187" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_31.gif" alt="" width="551" height="46" /></p>
<p>Alternatively, you can use the data in <tt>WordData</tt>, which contains phrases in addition to words. You could use any similar resource for your list of words.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_34.gif" alt="" width="162" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_32.gif" alt="" width="577" height="46" /></p>
<p>First, consider the character code of a string.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_35.gif" alt="" width="165" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_33.gif" alt="" width="127" height="13" /></p>
<p>Then we only need to know if this list of codes is in order.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_36.gif" alt="" width="79" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_34.gif" alt="" width="29" height="13" /></p>
<p>Here is a predicate that returns <tt>True</tt> if its argument is ordered in this alphabetic sense.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_37.gif" alt="" width="425" height="14" /></p>
<p>Now we will find all the words in the dictionary file that comes with <em>Mathematica</em> that are ordered in this way; we will use <tt>Select</tt> to return those words that pass the test. Finally, we randomly sample 40 of them.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_38.gif" alt="" width="298" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_39.gif" alt="" width="211" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_35.gif" alt="" width="535" height="46" /></p>
<p>Almost correct! In the English character code set, capitals appear before lowercase letters. So, although our words are ordered in the sense of character codes, they are not ordered in the commonly-used sense.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_40.gif" alt="" width="143" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_36.gif" alt="" width="28" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_41.gif" alt="" width="143" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_37.gif" alt="" width="28" height="13" /></p>
<p>One approach to resolving this issue is to only work with words of the same case. We could either convert words of the form uppercase/lowercase to lowercase/lowercase or we could select only words from the dictionary that match a pattern that codes for this. We will wait until the discussion of string patterns in Section 9.3 to correct this issue.</p>
<h5>Exercises</h5>
<ol class="ItemNumbered">
<li>Convert the first character in a string (which you may assume to be a lowercase letter) to uppercase.</li>
<li>Given a string of digits of arbitrary length, convert it to its integer value. (Hint: you may find that the <tt>Dot</tt> function is helpful.)</li>
<li>Create a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_5.gif" alt="" width="142" height="14" /> that takes a string as its argument and returns a list of the unique characters in that string. For example, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_6.gif" alt="" width="222" height="14" /> should return <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_7.gif" alt="" width="75" height="14" />.</li>
</ol>
<h3>9.2. Operations on Strings</h3>
<p>Strings are expressions and, like other expressions (such as numbers and lists), there are built-in functions available to operate on them. Many of these functions are very similar to those for operating on lists. In this section we will first look at some of these basic functions for operating on strings and then use them on some nontrivial examples: analyzing a large piece of text, encoding strings, creating index variables, and finally, a word game for creating anagrams.</p>
<h4>Basic String Operations</h4>
<p><tt>StringTake</tt>, which has a similar syntax to <tt>Take</tt>, is used to extract parts of a string. The second argument specifies the positions of the characters to extract. So, for example, this takes the first twelve characters in this string.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_42.gif" alt="" width="333" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_38.gif" alt="" width="86" height="14" /></p>
<p>And this takes the last twelve characters from the string.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_43.gif" alt="" width="341" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_39.gif" alt="" width="86" height="13" /></p>
<p>A list of the individual characters is returned by <tt>Characters</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_44.gif" alt="" width="308" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_40.gif" alt="" width="525" height="14" /></p>
<p><tt>StringJoin</tt> concatenates strings.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_45.gif" alt="" width="267" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_41.gif" alt="" width="43" height="14" /></p>
<p>The shorthand notation for <tt>StringJoin</tt> is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_8.gif" alt="" width="69" height="14" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_46.gif" alt="" width="69" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_42.gif" alt="" width="22" height="13" /></p>
<p>The following functions mirror those for list operations.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_47.gif" alt="" width="158" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_43.gif" alt="" width="36" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_48.gif" alt="" width="162" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_44.gif" alt="" width="29" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_49.gif" alt="" width="204" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_45.gif" alt="" width="53" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_50.gif" alt="" width="319" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_46.gif" alt="" width="7" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_51.gif" alt="" width="200" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_47.gif" alt="" width="43" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_52.gif" alt="" width="242" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_48.gif" alt="" width="36" height="13" /></p>
<p>Some functions are quite specific to strings and do not have analogs with lists. For example, conversion to uppercase and lowercase.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_53.gif" alt="" width="143" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_49.gif" alt="" width="36" height="13" /></p>
<p>This trims substrings from a string using alternative patterns (discussed further in Section 9.3). So if either <tt>"http://"</tt> or <tt>"/"</tt> is found, they will be trimmed.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_54.gif" alt="" width="367" height="15" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_50.gif" alt="" width="101" height="14" /></p>
<h4>Strings vs. Lists</h4>
<p>For some computations, you might be tempted to convert a string to a list of characters and then operate on the list using some list manipulation functions. For example, this first constructs a list of the individual characters and then uses <tt>Count</tt> to get the number of occurrences of the letter <em>B</em> in the list of characters from the text of Charles Darwin&#8217;s <em>On the Origin of Species</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_55.gif" alt="" width="334" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_51.gif" alt="" width="546" height="46" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_56.gif" alt="" width="262" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_52.gif" alt="" width="105" height="13" /></p>
<p>Since the string functions in <em>Mathematica</em> are optimized for working on strings directly you will often find that they are much faster than the more general list manipulation functions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_57.gif" alt="" width="219" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_53.gif" alt="" width="105" height="13" /></p>
<p>This speedup results from the fact that the string pattern matching algorithms are operating only on a well-defined finite alphabet and string expressions are essentially flat structures, whereas the algorithms for more general expression matching are designed to operate on arbitrary expressions with potentially much more complicated structures.</p>
<p>Converting to lists and using list manipulation functions will often be more cumbersome than working with the string functions directly. For example, counting the occurrences of a word within a chunk of text by first converting to a list of characters would be quite indirect and computationally more taxing than simply using <tt>StringCount</tt> directly.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_58.gif" alt="" width="277" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_54.gif" alt="" width="105" height="13" /></p>
<p>In fact, sometimes you will even find it more efficient to convert a numerical problem to one involving strings, do the work with string manipulation functions, and then convert back to numbers as in the subsequence example in Section 9.5.</p>
<h4>Encoding Text</h4>
<p>In this example, we will develop functions for coding and decoding strings of text. The particular coding that we will use is quite simplistic compared with contemporary commercial-grade ciphers, but it will give us a chance to see how to combine string manipulation, the use of functional programming constructs, and rule-based programming all in a very practical example that should be accessible to anyone.</p>
<p>The problem in encryption is to develop an algorithm that can be used to encode a string of text and then a dual algorithm that can be used to decode the encrypted message. Typically, the input string is referred to as the <em>plaintext</em> and the encoded output as the <em>ciphertext</em>.</p>
<p>To start, we will limit ourselves to the 26 lowercase letters of the alphabet.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_59.gif" alt="" width="244" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_55.gif" alt="" width="471" height="14" /></p>
<p>One of the simplest encryption schemes is attributed to Julius Caesar who is said to have used this cipher to encode communications with his generals. The scheme is simply to shift each letter of the alphabet some fixed number of places to the left and is commonly referred to as a substitution cipher. Using <tt>Thread</tt>, we can set up rules that implement this shift, here just shifting one place to the left.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_60.gif" alt="" width="399" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_56.gif" alt="" width="550" height="30" /></p>
<p>The decoding rules are simply to reverse the encoding rules.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_61.gif" alt="" width="342" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_57.gif" alt="" width="550" height="30" /></p>
<p>To code a string, we will decompose the string into individual characters, apply the code rules, and then join up the resulting characters in a &#8220;word.&#8221;</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_62.gif" alt="" width="136" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_58.gif" alt="" width="93" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_63.gif" alt="" width="137" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_59.gif" alt="" width="93" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_64.gif" alt="" width="93" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_60.gif" alt="" width="36" height="14" /></p>
<p>Here is the function to accomplish this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_65.gif" alt="" width="515" height="14" /></p>
<p>Similarly, here is the decoding function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_66.gif" alt="" width="544" height="14" /></p>
<p>Let us try it out on a phrase.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_67.gif" alt="" width="327" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_61.gif" alt="" width="137" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_68.gif" alt="" width="197" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_62.gif" alt="" width="137" height="14" /></p>
<p>In this example, we have shifted one position for each letter to encode (and decode). It is thought that Caesar (or his cryptographers) used a shift of length three to encode his military messages. In the exercises, you are asked to implement a different shift length in the encoding and decoding functions.</p>
<p>Even with longer shifts, the Caesar cipher is terribly insecure and highly prone to cracking since there are only 26 possible shifts with this simple cipher. A slightly more secure cipher involves permuting the letters of the alphabet.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_69.gif" alt="" width="180" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_63.gif" alt="" width="471" height="14" /></p>
<p>Using <tt>Thread</tt>, we create a rule for each letter paired up with the corresponding letter from the permutation <tt>p</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_70.gif" alt="" width="298" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_64.gif" alt="" width="550" height="30" /></p>
<p>Again, the decoding rules are obtained by simply reversing the above rules.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_71.gif" alt="" width="312" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_65.gif" alt="" width="550" height="30" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_72.gif" alt="" width="363" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_66.gif" alt="" width="137" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_73.gif" alt="" width="233" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_67.gif" alt="" width="137" height="14" /></p>
<p>Although these substitution ciphers are not terribly difficult to crack, they should give you some good practice in working with strings and the various <em>Mathematica</em> programming constructs. Modern commercial-grade ciphers such as public-key ciphers are often based on the difficulty of factoring large integers. For a basic introduction to the history of ciphers, see Sinkov (1966) [<a href="#Sinkov66">2</a>]. A more thorough treatment can be found in Paar and Pelzl (2010) [<a href="#Paar10">3</a>].</p>
<h4>Indexed Symbols</h4>
<p>When developing algorithms that operate on large structures (for example, large systems of equations), it is often helpful to be able to create a set of unique symbols with which to work. As an example of operations on strings, we will use some of the functions discussed in this section to develop a little utility function that creates unique symbols. Although there is a built-in function, <tt>Unique</tt>, that does this, it has some limitations for this particular task.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_74.gif" alt="" width="160" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_68.gif" alt="" width="227" height="13" /></p>
<p>One potential limitation of <tt>Unique</tt> is that it uses the first <em>unused</em> symbol of a particular form. It does this to avoid overwriting existing symbols.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_75.gif" alt="" width="160" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_69.gif" alt="" width="267" height="13" /></p>
<p>However, if you want to explicitly create a list of indexed symbols with a set of specific indices, it is useful to create a different function. First, note that a string can be converted to a symbol using <tt>ToExpression</tt> or by wrapping the string in <tt>Symbol</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_76.gif" alt="" width="71" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_70.gif" alt="" width="43" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_77.gif" alt="" width="179" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_71.gif" alt="" width="43" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_78.gif" alt="" width="136" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_72.gif" alt="" width="43" height="14" /></p>
<p><tt>StringJoin</tt> is used to concatenate strings. So, let us concatenate the variable with the index, first with one number and then with a range of numbers.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_79.gif" alt="" width="219" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_73.gif" alt="" width="28" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_80.gif" alt="" width="342" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_74.gif" alt="" width="327" height="13" /></p>
<p>We put all the pieces of code together.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_81.gif" alt="" width="580" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_82.gif" alt="" width="140" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_75.gif" alt="" width="474" height="30" /></p>
<p>Let us create an additional rule for this function that takes a range specification as its second argument.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_83.gif" alt="" width="419" height="30" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_84.gif" alt="" width="179" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_76.gif" alt="" width="520" height="14" /></p>
<p>Note that we have not been too careful about argument checking.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_85.gif" alt="" width="173" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_77.gif" alt="" width="245" height="14" /></p>
<p>In the exercises you are asked to correct this.</p>
<h4>Anagrams</h4>
<p>Anagrams are words that have the same set of letters but in a different order. Good Scrabble players are adept at anagram creation. Anagrams can be created by taking a word, extracting and permuting its characters, and then finding which permutations are real words.</p>
<p>Start by getting the characters in a word.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_86.gif" alt="" width="180" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_78.gif" alt="" width="75" height="13" /></p>
<p>Permute the characters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_87.gif" alt="" width="158" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_79.gif" alt="" width="520" height="59" /></p>
<p>Concatenate the characters in each list.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_88.gif" alt="" width="177" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_80.gif" alt="" width="524" height="29" /></p>
<p>Now, which of these &#8220;words&#8221; are really words? One way to check is to select those that are in the dictionary. Those elements in <span>words</span> that are not in the dictionary will return <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_9.gif" alt="" width="14" height="13" /> when run against <tt>DictionaryLookup</tt>, so we omit those using <tt>≠</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_89.gif" alt="" width="409" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_81.gif" alt="" width="203" height="13" /></p>
<p>Putting all the pieces together, we have the function <tt>Anagrams</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_90.gif" alt="" width="462" height="62" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_91.gif" alt="" width="201" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_82.gif" alt="" width="391" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_92.gif" alt="" width="122" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_83.gif" alt="" width="238" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_93.gif" alt="" width="144" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_84.gif" alt="" width="210" height="13" /></p>
<p>Other than extracting the characters of a word and joining the permuted list of characters, the operations here are essentially those on lists (of strings) and pattern matching. Exercise <a href="#9.2 Exercises">2</a> in Section 9.5 discusses a more direct approach to this problem, one that avoids the creation of permutations of the characters in the word.</p>
<h5>Exercises<a name="9.2 Exercises"></a></h5>
<ol class="ItemNumbered">
<li>Create a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_10.gif" alt="" width="106" height="13" /> that returns a value of <tt>True</tt> if its argument <span style="font-family: times;"><em>str</em></span> is a palindrome, that is, if the string <span style="font-family: times;"><em>str</em></span> is the same forward and backward. For example, <em>refer</em> is a palindrome.</li>
<li>Create a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_11.gif" alt="" width="159" height="14" /> that takes a string <span style="font-family: times;"><em>str</em></span>, and returns a string with the characters rotated to the left <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_12.gif" alt="" width="6" height="12" /> places. For example:</li>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_94.gif" alt="" width="336" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_85.gif" alt="" width="172" height="14" /></p>
<li>In creating the function <tt>MakeVarList</tt> in this section, we were not careful about the arguments that might be passed. Correct this problem using pattern matching on the arguments to this function to insure that the indices are positive integers only.</li>
<li>Create a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_13.gif" alt="" width="123" height="14" /> that pads the end of a string with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_14.gif" alt="" width="6" height="12" /> whitespace characters. Then create a second rule <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_15.gif" alt="" width="109" height="14" /> that pads the string out to length <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_16.gif" alt="" width="6" height="12" />. If the input string has length greater than <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_17.gif" alt="" width="6" height="12" />, issue a warning message. Finally, mirroring the argument structure for the built-in <tt>PadLeft</tt>, create a third rule <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_18.gif" alt="" width="129" height="14" /> that pads with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_19.gif" alt="" width="6" height="12" /> whitespaces at the front and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_20.gif" alt="" width="9" height="12" /> whitespaces at the end of the string.</li>
<li>Modify the Caesar cipher so that it encodes by shifting five places to the right. Include the space character in the alphabet.</li>
<li>A mixed-alphabet cipher is created by first writing a keyword followed by the remaining letters of the alphabet and then using this as the substitution (or cipher) text. For example, if the keyword is <em>django</em>, the cipher text alphabet would be:</li>
<div class="SubitemParagraph"><tt>djangobcefhiklmpqrstuvwxyz</tt></div>
<div class="ItemParagraph">So, <em>a</em> is replaced with <em>d</em>, <em>b</em> is replaced with <em>j</em>, <em>c</em> is replaced with <em>a</em>, and so on. As an example, the piece of text</div>
<div class="SubitemParagraph"><em>the sheik of araby</em></div>
<div class="ItemParagraph">would then be encoded as</div>
<div class="SubitemParagraph"><em>tcg scgeh mo drdjy</em></div>
<div class="ItemParagraph">Implement this cipher and go one step further to output the cipher text in blocks of length five, omitting spaces and punctuation.</div>
<li>Modify the alphabet permutation cipher so that instead of being based on single letters, it is instead based on adjacent pairs of letters. The single letter cipher will have <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_27.gif" alt="" width="207" height="12" /> permutations; the adjacent pairs cipher will have <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_28.gif" alt="" width="179" height="15" /> permutations.</li>
</ol>
<h3>9.3. String Patterns</h3>
<p>Most of the string operations we have looked at up until this point have involved literal strings. For example, in string replacement, we have specified both the explicit string that we are operating on as well as the replacement string.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_95.gif" alt="" width="263" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_86.gif" alt="" width="71" height="13" /></p>
<p>But the real power of programming with strings comes with the use of patterns to represent different classes of strings. A string pattern is a string expression that contains symbolic patterns. Much of the pattern matching discussed in the previous chapters extends to strings in a very powerful manner. For example, this uses patterns to change the first letter in a string to uppercase.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_96.gif" alt="" width="324" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_97.gif" alt="" width="387" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_87.gif" alt="" width="266" height="14" /></p>
<p>Or, use a conditional pattern to check if a word begins with an uppercase character.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_98.gif" alt="" width="337" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_88.gif" alt="" width="29" height="13" /></p>
<p>To get started, you might find it helpful to think of strings as a sequence of characters and use the same general principles on these expressions as you do with lists.</p>
<p>For example, the expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_29.gif" alt="" width="111" height="13" /> matches the pattern <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_30.gif" alt="" width="107" height="14" /> because it is a list that starts with a sequence of one or more elements, it contains an element repeated once, and then ends with a sequence of one or more elements.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_99.gif" alt="" width="286" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_89.gif" alt="" width="29" height="13" /></p>
<p>If we now use a string instead of a list and <tt>StringMatchQ</tt> instead of <tt>MatchQ</tt>, we get a similar result using the shorthand notation <tt>~~</tt> for <tt>StringExpression</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_100.gif" alt="" width="294" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_90.gif" alt="" width="29" height="13" /></p>
<p><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_31.gif" alt="" width="60" height="14" /> is shorthand notation for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_32.gif" alt="" width="189" height="14" />, which, for the purpose of pattern matching, represents a sequence of strings.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_101.gif" alt="" width="64" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_91.gif" alt="" width="14" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_102.gif" alt="" width="186" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_92.gif" alt="" width="182" height="14" /></p>
<p><tt>StringExpression</tt> is quite similar to <tt>StringJoin</tt> (both can be used to concatenate strings) except that with <tt>StringExpression</tt>, you can concatenate nonstrings.</p>
<p>The next example also shows the similarity between the general expression pattern matching that we explored earlier in Chapter 4 and string patterns. Using <tt>Cases</tt>, the following returns all those expressions that match the pattern <tt>_Symbol</tt>, that is, pick out all symbols from the list.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_103.gif" alt="" width="259" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_93.gif" alt="" width="75" height="14" /></p>
<p>With strings we use <tt>StringCases</tt> whose second argument is a pattern that represents a class of characters to match. <tt>StringCases</tt> returns those substrings that match a given pattern. Many named patterns are available for various purposes. For example, <tt>LetterCharacter</tt> matches a single letter.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_104.gif" alt="" width="283" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_94.gif" alt="" width="75" height="14" /></p>
<p>Match single digits with <tt>DigitCharacter</tt> and one or more digits with <tt>NumberString</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_105.gif" alt="" width="276" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_95.gif" alt="" width="75" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_106.gif" alt="" width="261" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_96.gif" alt="" width="64" height="13" /></p>
<p>To see the generality and power of working with string patterns, suppose we were looking for a nucleotide sequence in a gene consisting of a repetition of A followed by any character, followed by T. Using a gene from the human genome, the following string pattern neatly does the job.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_107.gif" alt="" width="194" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_97.gif" alt="" width="580" height="59" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_108.gif" alt="" width="234" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_98.gif" alt="" width="243" height="13" /></p>
<p>Here are the starting and ending positions of these substrings. <tt>StringPosition</tt> takes the same syntax as <tt>StringCases</tt>, analogous to <tt>Position</tt> and <tt>Cases</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_109.gif" alt="" width="256" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_99.gif" alt="" width="565" height="13" /></p>
<p>And if you wanted to return those characters that follow all occurrences of the string <tt>"GTC"</tt>, you can name the pattern and use a rule to return it.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_110.gif" alt="" width="307" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_100.gif" alt="" width="203" height="13" /></p>
<p>In this example, the pattern is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_33.gif" alt="" width="108" height="14" />. This pattern is named <tt>pat</tt> and it consists of the string GTC which is then followed by any character. That character is named <tt>x</tt> so that we can refer to it in the replacement expression on the right-hand side of the rule. The replacement expression is the pattern <tt>pat</tt> concatenated with the character named <tt>x</tt>.</p>
<p>As another example of the use of string patterns, suppose you were interested in scraping phone numbers off of a web page; you need to construct a pattern that matches the form of the phone numbers you are looking for. In this case we use the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_34.gif" alt="" width="102" height="12" /> which matches the form of North American phone numbers. <tt>NumberString</tt> comes in handy as it picks up strings of numbers of any length. Otherwise you would have to use <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_35.gif" alt="" width="118" height="14" /> which matches repeating digits.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_111.gif" alt="" width="500" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_112.gif" alt="" width="557" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_101.gif" alt="" width="241" height="13" /></p>
<h4>Finding Subsequences with Strings</h4>
<p>In this section we will explore a related problem to the one in Section 4.3, where we searched for subsequences within a sequence of numbers. Here we will transform the problem from working with lists of digits to one where we work with strings.</p>
<p>Using pattern matching it is not too difficult to construct the pattern of interest. For example, suppose we were looking for the substring <em>are</em> within a larger string. Using the special named string pattern <tt>WordBoundary</tt> which matches the beginning or end of a word, we concatenate (<tt>StringJoin</tt>) the patterns we need. See Table 9.3 in the next section for a listing of other named patterns.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_113.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_102.gif" alt="" width="36" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_114.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_103.gif" alt="" width="67" height="13" /></p>
<p>To start, we will prototype with a short sequence of digits of <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Pi.gif" alt="" width="6" height="19" />, converted to a string.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_115.gif" alt="" width="163" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_104.gif" alt="" width="367" height="13" /></p>
<p>Check that the output is in fact a string.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_116.gif" alt="" width="191" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_105.gif" alt="" width="449" height="14" /></p>
<p>For our purposes here, we are only interested in the digits following the decimal point. We can extract them by splitting the string of digits on the decimal point and then taking the second part of that expression. This will generalize for numbers with an arbitrary number of digits before the decimal point.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_117.gif" alt="" width="147" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_106.gif" alt="" width="385" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_118.gif" alt="" width="68" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_107.gif" alt="" width="353" height="13" /></p>
<p>The subsequence 3238 occurs starting 15 positions to the right of the decimal point.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_119.gif" alt="" width="176" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_108.gif" alt="" width="67" height="13" /></p>
<p>Collecting the code fragments, we turn this into a function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_120.gif" alt="" width="580" height="46" /></p>
<p>Let us try it out on a more challenging example: finding occurrences of the sequence 314159 in the decimal expansion of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_36.gif" alt="" width="6" height="12" /> to ten million places.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_121.gif" alt="" width="96" height="18" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_122.gif" alt="" width="257" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_109.gif" alt="" width="580" height="29" /></p>
<p>Comparing with the function that takes lists of digits developed in Section 4.3, our string implementation is about twice as fast.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_123.gif" alt="" width="444" height="94" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_110.gif" alt="" width="580" height="29" /></p>
<h4>Alternatives</h4>
<p>We have already seen general patterns with alternatives discussed in Chapter 4. Here we will use alternatives with string patterns. The idea is quite similar. For example, a common task in genome analysis is determining the GC content or ratios of the nucleobases guanine (G) and cytosine (C) to all four bases in a given fragment of genetic material.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_124.gif" alt="" width="209" height="14" /></p>
<p>You could count the occurrences of G and the occurrences of C and add them together.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_125.gif" alt="" width="321" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_111.gif" alt="" width="14" height="13" /></p>
<p>But it is much easier to use alternatives to indicate that you want to count all occurrences of either G or C. The syntax for using alternative string patterns is identical to that for general expressions that we introduced in Section 4.1.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_126.gif" alt="" width="188" height="15" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_112.gif" alt="" width="14" height="13" /></p>
<p>We will return to the computation of GC content in Section 9.5.</p>
<p>As a slightly more involved example, suppose you are interested in tallying the lengths of words in a corpus. You might start by using <tt>StringSplit</tt> to split the large string into a list of words.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_127.gif" alt="" width="334" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_128.gif" alt="" width="187" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_113.gif" alt="" width="580" height="62" /></p>
<p>Looking at the result, you will see that some elements of this list include various types of punctuation. For example, <tt>StringSplit</tt>, with default delimiters, missed certain hyphenated words and some punctuation.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_129.gif" alt="" width="132" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_114.gif" alt="" width="197" height="14" /></p>
<p>There are 149863 elements in this split list.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_130.gif" alt="" width="100" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_115.gif" alt="" width="45" height="13" /></p>
<p>Fortunately, <tt>StringSplit</tt> takes a second argument that specifies the delimiters to match. The pattern is given as a set of alternatives followed by the repeated operator to catch one or more repetitions of any of these delimiters. Searching through the text will help to come up with this list of alternatives.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_131.gif" alt="" width="580" height="15" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_132.gif" alt="" width="133" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_116.gif" alt="" width="580" height="46" /></p>
<p>Notice that this list contains many more elements than the initial approach given above.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_133.gif" alt="" width="122" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_117.gif" alt="" width="45" height="13" /></p>
<p>Finally, here is a histogram showing the distribution of word lengths in the text, <em>On the Origin of Species</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_134.gif" alt="" width="580" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_118.gif" alt="" width="206" height="130" /></p>
<p>Let us compare this with a different text: <em>A Portrait of the Artist as a Young Man</em>, by James Joyce [<a href="#Joyce1939">4</a>] (available online at Project Gutenberg [<a href="#ProjectGutenberg">5</a>]). We are postprocessing here by removing metadata at the beginning and at the end of the file.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_135.gif" alt="" width="580" height="46" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_119.gif" alt="" width="502" height="30" /></p>
<p>An alternative syntax uses a list of delimiters as given by <tt>Characters</tt>. The repeated pattern, <tt>..</tt>, helps to catch such constructions as &#8220;<tt>--</tt>&#8220;, &#8220;<tt>::</tt>&#8221; and double-spaces.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_136.gif" alt="" width="580" height="46" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_120.gif" alt="" width="206" height="130" /></p>
<p>In the next section, on regular expressions, we will see that there are more compact ways of accomplishing some of these tasks.</p>
<h5>Exercises</h5>
<ol class="ItemNumbered">
<li>At the end of Section 9.1 we created a predicate <tt>OrderedWordQ</tt> to find all words in a dictionary whose letters are in alphabetic order. This predicate used character codes and returned incorrect results for words that started with a capital letter. Correct this error by only selecting words from the dictionary that start with a lowercase letter. Consider using a conditional string pattern involving the built-in function <tt>LowerCaseQ</tt>.</li>
<li>Given a list of words, some of which start with uppercase characters, convert them all to words in which the first character is lowercase. You can use the words in the dictionary as a good sample set.</li>
<li>Create a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_37.gif" alt="" width="99" height="13" /> that finds all palindromic words of length <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_38.gif" alt="" width="6" height="12" /> in the dictionary. For example, <em>kayak</em> is a five-letter palindrome.</li>
<li>Find the number of unique words in a body of text such as <em>Alice in Wonderland</em>.</li>
</ol>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_137.gif" alt="" width="348" height="14" /></p>
<p>After splitting the text into words, convert all uppercase characters to lowercase so that you count words such as <em>hare</em> and <em>Hare</em> as the same word.</p>
<p>Such computations are important in information retrieval systems, for example, in building term-document incidence matrices used to compare the occurrence of certain terms across a set of documents (Manning, Raghavan, and Schütze 2008 [<a href="#Manning08">6</a>]).</p>
<h3>9.4. Regular Expressions</h3>
<p>In addition to the use of string patterns discussed up to this point, you can also specify string patterns using what are known as <em>regular expressions</em>. Regular expressions in <em>Mathematica</em> follow a syntax very close to that of the <span class="SmallCaps">Perl</span> programming language. This syntax is quite compact and powerful but it comes at the cost of readability &#8211; regular expressions tend to be quite cryptic to humans. As a result, we will only cover a few examples of their use here and refer the interested reader to the <em>Mathematica</em> documentation on string patterns (Working with String Patterns, WMDC [<a href="#Working with String Patterns: WMDC">7</a>]).</p>
<p>You should think of regular expressions as an alternative syntax for string pattens. To indicate that you are using a regular expression, wrap the expression in <tt>RegularExpression</tt>. For example, the regular expression <tt>.</tt> is a wildcard character. It matches any single character except a newline. To use it as a string pattern, write <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_39.gif" alt="" width="157" height="14" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_138.gif" alt="" width="289" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_121.gif" alt="" width="29" height="13" /></p>
<p>The string <tt>"abc"</tt> does not match the pattern because it does not consist of a single character.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_139.gif" alt="" width="304" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_122.gif" alt="" width="36" height="13" /></p>
<p>You can also match a set or range of characters. For example, this matches any of the characters <em>a</em> through <em>z</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_140.gif" alt="" width="317" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_123.gif" alt="" width="29" height="13" /></p>
<p>Certain constructs give patterns with repeating elements. For example, <tt>"c*"</tt> is a pattern matched by a string with character <em>c</em> repeated zero or more times; <tt>"c+"</tt> stands in for the character <em>c</em> repeated one or more times.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_141.gif" alt="" width="303" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_124.gif" alt="" width="29" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_142.gif" alt="" width="318" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_125.gif" alt="" width="36" height="13" /></p>
<p>You can also match on concatenated characters using the syntax <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_44.gif" alt="" width="39" height="14" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_143.gif" alt="" width="456" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_126.gif" alt="" width="117" height="13" /></p>
<p>Several constructs are available for classes of characters. The named classes in the last two entries of Table 9.2 include <em>alpha</em>, <em>ascii</em>, <em>blank</em>, <em>digit</em>, <em>space</em>, <em>word</em>, and several more.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_PlacedGraphics_2.gif" alt="" width="270" height="186" /></p>
<div class="NumberedTableCaption"><strong>Table 9.2.</strong> Regular expressions classes of characters</div>
<p>The regular expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_45.gif" alt="" width="23" height="13" /> matches any expression beginning with the character <em>a</em> followed by any sequence of characters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_144.gif" alt="" width="411" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_127.gif" alt="" width="29" height="13" /></p>
<p>The regular expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_47.gif" alt="" width="24" height="13" /> represents any digit 0 through 9.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_145.gif" alt="" width="346" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_128.gif" alt="" width="75" height="13" /></p>
<p>The regular expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_48.gif" alt="" width="46" height="13" /> matches any expression beginning with an <em>a</em>, followed by any character repeated one or more times, followed by a digit.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_146.gif" alt="" width="418" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_129.gif" alt="" width="86" height="13" /></p>
<p>Let us try something more ambitious. This finds all words in <tt>text</tt> that are of length 16 to 18.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_147.gif" alt="" width="533" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_130.gif" alt="" width="580" height="30" /></p>
<p>The regular expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_50.gif" alt="" width="24" height="13" /> matches any word boundary (typically whitespace, period, comma, etc.) and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_51.gif" alt="" width="80" height="13" /> matches any word of length 16 to 18.</p>
<p>Various shortcuts exist for some commonly used patterns (Table 9.3).</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_PlacedGraphics_3.gif" alt="" width="238" height="110" /></p>
<div class="NumberedTableCaption"><strong>Table 9.3.</strong> Patterns for special locations within strings</div>
<p>Conveniently, you can mix regular expressions and other string patterns in various ways. This accomplishes the same thing as the previous computation, but using <tt>WordBoundary</tt>, instead of the regular expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_52.gif" alt="" width="24" height="13" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_148.gif" alt="" width="580" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_131.gif" alt="" width="580" height="30" /></p>
<p>Sometimes you will need to refer to the pattern by name in order to perform some operation on it. This is similar to the situation with regular named patterns. For example, given a list of words, some of which are uppercase/lowercase, this uses string patterns to transform the list to all lowercase words, naming the pattern that is matched by the first character after a word boundary, <tt>a</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_149.gif" alt="" width="580" height="30" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_150.gif" alt="" width="396" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_132.gif" alt="" width="534" height="30" /></p>
<p>So how do we name a pattern with regular expressions so that we can refer to it on the right-hand side of a rule? The syntax using regular expressions is to wrap the pattern in parentheses and then refer to it using <tt>"$</tt><span style="font-family: times;"><em>n</em></span><tt>"</tt> , where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_54.gif" alt="" width="6" height="12" /> is the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_55.gif" alt="" width="6" height="12" />th occurrence of such patterns. For example, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_56.gif" alt="" width="65" height="13" /> is a named pattern that is matched by an expression consisting of a word boundary followed by a word character. The subexpression matching <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_57.gif" alt="" width="38" height="13" /> is referenced by <tt>"$1"</tt> on the right-hand side of the rule.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_151.gif" alt="" width="500" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_133.gif" alt="" width="534" height="30" /></p>
<p>To change the second character after the word boundary to uppercase, use <tt>"$2"</tt> to refer to the expression that matches the second <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_58.gif" alt="" width="38" height="13" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_152.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_134.gif" alt="" width="534" height="30" /></p>
<p>A particularly useful construct in many situations is the lookahead/lookbehind construct. <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_59.gif" alt="" width="58" height="14" /> is used when the following text must match <span style="font-family: times;"><em>patt</em></span> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_60.gif" alt="" width="74" height="14" /> is used when the preceding text must match <span style="font-family: times;"><em>patt</em></span>. For example, this finds all those words in some example text that follow <tt>"Raven,  "</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_153.gif" alt="" width="284" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_154.gif" alt="" width="279" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_135.gif" alt="" width="111" height="14" /></p>
<p>There are many more constructs available for doing quite sophisticated things with regular expressions. We will explore some of these in the examples and exercises below as well as in the applications in Section 9.5. For a more detailed discussion, see the tutorials Regular Expressions (WMDC [<a href="#Regular Expressions: WMDC">8</a>]) and Working with String Patterns (WMDC [<a href="#Working with String Patterns: WMDC">7</a>]).</p>
<h4>Word Stemming</h4>
<p>Many aspects of linguistic analysis include a study of the words used in a piece of text or in a speech. For example, you might be interested in comparing the complexity of articles written in two different newspapers. The length and frequency of certain words might be a useful measure for such an analysis. Patterns in usage of certain word combinations can be used to identify authenticity or the identity of an author of a work.</p>
<p>There are some basic issues that arise again and again in such analyses. For example, what should be done with contractions such as <em>shouldn&#8217;t</em>? What about sets of words such as <em>run</em>, <em>runs</em>, <em>ran</em>, <em>running</em>. Are they considered distinct? One approach in language processing is to strip suffixes and reduce alternate forms to some <em>stem</em>. This process, known as word stemming, is extensively used in many online search systems to try to distill user&#8217;s queries to some basic form that can be processed and operated on. It is a bit tricky, as natural languages are notorious for exceptions to almost any rule. For example, although the word <em>entertainment</em> can sensibly be stemmed to <em>entertain</em>, the stem of <em>comment</em> is certainly not <em>com</em>. In other words, a rule that dropped the suffix <em>ment</em> is too broad and returns nonwords in many cases. In most word stemming algorithms, there are numerous rules for the many cases that need to be examined; and there are many special cases. In this section, we will create a set of rules for word stemming to show how these rules are described and how the string pattern constructs in <em>Mathematica</em> provide a good set of tools to implement these concepts. A full-fledged stemming application would include hundreds of rules for each language, so we will only give a small set here to indicate the general process.</p>
<h5><span class="SubsubBold">Words Ending in &#8230;xes</span></h5>
<p>The first set of stemming rules we will create involves a relatively small set of words in the English language &#8211; those ending in <em>xes</em>, such as <em>boxes</em> or <em>complexes</em>. The rule is to strip off the <em>es</em>.</p>
<p>To prototype, we collect all the words in the dictionary that end in <em>xes</em>. We will also restrict ourselves to words that are all lowercase. <tt>Quiet</tt> is used here to suppress the error messages that arise when <tt>StringTake</tt> operates on words of length less than three. Alternatively, you could put an extra clause (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_61.gif" alt="" width="129" height="14" />) in the conjunction.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_155.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_136.gif" alt="" width="580" height="206" /></p>
<p>Here is the replacement rule. The regular expression <tt>"(\\w)(x)es"</tt> will be matched by any word character followed by <em>xes</em>. It is replaced by that word character followed only by <em>x</em>. On the right-hand side of the rule, <tt>$1</tt> refers to the first pattern on the left, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_63.gif" alt="" width="38" height="13" />; and <tt>$2</tt> refers to the second pattern on the left, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_64.gif" alt="" width="21" height="13" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_156.gif" alt="" width="339" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_157.gif" alt="" width="256" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_137.gif" alt="" width="580" height="158" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_158.gif" alt="" width="372" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_138.gif" alt="" width="227" height="14" /></p>
<p>This is pretty good; it appears only four stemmed words are not in the dictionary; although <em>max</em> might be considered an abbreviation, <em>postfix</em> is certainly a word! Nonetheless, these sorts of exceptions are common and will need to be dealt with separately.</p>
<h5>Plural Nouns Ending &#8230;mming</h5>
<p>A word such as <em>programming</em> has a stem of <em>program</em>; so the rule for words ending in &#8230;<em>mming</em> could be: drop the <em>ming</em>. Start by gathering all the words in the dictionary that end with &#8230;<em>mming</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_159.gif" alt="" width="482" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_139.gif" alt="" width="580" height="94" /></p>
<p>Recall the regular expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_65.gif" alt="" width="34" height="13" /> represents a word character repeated some number of times; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_66.gif" alt="" width="24" height="13" /> represents a word boundary; the <tt>$1</tt> refers to the first expression <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_67.gif" alt="" width="48" height="13" />, that is, the characters up to the <em>mming</em>. These characters will be joined with a single <em>m</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_160.gif" alt="" width="396" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_161.gif" alt="" width="191" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_140.gif" alt="" width="542" height="62" /></p>
<p>Again, this is quite good although the word <em>lemming</em> has been stemmed to the nonword <em>lem</em>, something that will need to be dealt with as a special case. The way to do that is to order the rules so that the special cases are caught first.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_162.gif" alt="" width="362" height="46" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_163.gif" alt="" width="191" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_141.gif" alt="" width="542" height="62" /></p>
<h5>Words Ending in &#8230;otes</h5>
<p>Numerous rules are needed for turning plural words into their singular stems. To see this, consider a naive rule that simply drops the <em>s</em> for any such words.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_164.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_142.gif" alt="" width="158" height="14" /></p>
<p>This is clearly too general a rule. In fact, several different rules are needed for words that end in <em>s</em>, depending upon the preceding characters. Here, we will only deal with words that end in &#8230;<em>otes</em>. First gather the words in the dictionary that match this pattern.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_165.gif" alt="" width="580" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_143.gif" alt="" width="528" height="62" /></p>
<p>Here is the replacement rule.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_166.gif" alt="" width="354" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_167.gif" alt="" width="191" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_144.gif" alt="" width="580" height="46" /></p>
<p>Stemming <em>litotes</em> gives the nonword <em>litote.</em> This can again be resolved by adding some specific rules for these not uncommon situations.</p>
<h5>Plural to Singular</h5>
<p>Let us try to deal with the general problem of stemming plural forms to singular. This is a more difficult scenario to deal with as there are many rules and even more exceptions. We will begin by showing how the order of the replacement rules matters in the stemming process.</p>
<p>You might imagine the rules given in Table 9.4 being used to stem plurals (these are not complete, but they will get us started). In fact, these are step 1a of the commonly-used Porter&#8217;s algorithm for word stemming in the English language.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_PlacedGraphics_4.gif" alt="" width="203" height="122" /></p>
<div class="NumberedTableCaption"><strong>Table 9.4.</strong> Stemming rules, plural to singular</div>
<p>The order in which such rules are used is important. You do not want the last rule being used before any of the others. As we saw with the previous set of rules, <em>Mathematica</em> will apply rules in the order in which they are given, assuming that they have roughly the same level of specificity. Note also that some of these rules are designed to leave certain words unchanged. For example neither <em>pass</em> nor <em>abacus</em> are plural and they should not be stemmed.</p>
<p>Here then is a rough attempt at stemming plural words. First we gather the words from the dictionary that end in <em>s</em> and display a random sample of them.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_168.gif" alt="" width="580" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_145.gif" alt="" width="580" height="62" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_169.gif" alt="" width="352" height="126" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_170.gif" alt="" width="220" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_146.gif" alt="" width="560" height="62" /></p>
<p>This process of word stemming requires a lot of trial and error and the creation of many rules for the exceptions. Another approach, called <em>lemmatization</em>, does a more careful and thorough job by working with vocabularies and performing morphological analysis of the words to better understand how to reduce them to a root. For more information, see Manning, Raghavan, and Schütze (2008) [<a href="#Manning08">6</a>].</p>
<h5>Exercises</h5>
<ol class="ItemNumbered">
<li>Rewrite the genomic example in Section 9.3 to use regular expressions instead of string patterns to find all occurrences of the sequence <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_68.gif" alt="" width="68" height="14" />. Here is the example using general string patterns.</li>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_171.gif" alt="" width="201" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_172.gif" alt="" width="234" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_147.gif" alt="" width="243" height="13" /></p>
<li>Rewrite the web page example in Section 9.3 to use regular expressions to find all phone numbers on the page, that is, expressions of the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_69.gif" alt="" width="72" height="12" />. Modify accordingly for other web pages and phone numbers formatted for other regions.</li>
<li>Create a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_70.gif" alt="" width="68" height="13" /> that takes its argument <span style="font-family: times;"><em>word</em></span> and returns the word with the first letter uppercase and the rest of the letters lowercase.</li>
<li>Use a regular expression to find all words given by <tt>DictionaryLookup</tt> that consist only of the letters <em>a</em>, <em>e</em>, <em>i</em>, <em>o</em>, <em>u</em>, and <em>y</em> in any order with any number of repetitions of the letters.</li>
<li>The basic rules for pluralizing words in the English language are roughly, as follows: if a noun ends in <em>ch</em>, <em>s</em>, <em>sh</em>, <em>j</em>, <em>x</em>, or <em>z</em>, it is made plural by adding <em>es</em> to the end. If the noun ends in <em>y</em> and is preceded by a consonant, replace the <em>y</em> with <em>ies</em>. If the word ends in <em>ium</em>, replace with <em>ia </em>(<em>Chicago Manual of Style</em> 2010 [<a href="#Chicago10">9</a>]). Of course, there are many more rules and even more exceptions, but you can implement a basic set of rules to convert singular words to plural based on these rules and then try them out on the following list of words.</li>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_173.gif" alt="" width="580" height="14" /></p>
<li>A common task in transcribing audio is cleaning up text, removing certain phrases such as <em>um</em>, <em>er</em>, and so on, and other tags that are used to make a note of some sort. For example, the following transcription of a lecture from the University of Warwick, Centre for Applied Linguistics (BASE Corpus [<a href="#BASE">10</a>]), contains quite a few fragments that should be removed, including newline characters, parenthetical remarks, and nonwords. Use <tt>StringReplace</tt> with the appropriate rules to &#8220;clean&#8221; this text and then apply your code to a larger corpus.</li>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_174.gif" alt="" width="580" height="126" /></p>
<li>Find the distribution of sentence lengths for any given piece of text. <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_71.gif" alt="" width="136" height="14" /> contains several well-known books and documents that you can use. You will need to think about and identify sentence delimiters carefully. Take care to deal properly with words such as <em>Mr</em>., <em>Dr</em>., and so on that might incorrectly trigger a sentence-ending detector.</li>
<li>In web searches and certain problems in natural language processing (NLP), it is often useful to filter out certain words prior to performing the search or processing of the text to help with the performance of the algorithms. Words such as <em>the</em>, <em>and</em>, <em>is</em>, and so on are commonly referred to as <em>stop words</em> for this purpose. Lists of stop words are almost always created manually based on the constraints of a particular application. We will assume you can import a list of stop words as they are commonly available across the internet. For our purposes here, we will use one such list that comes with the materials for this book.</li>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_175.gif" alt="" width="344" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_148.gif" alt="" width="580" height="14" /></p>
<div class="ItemParagraph">Using the above list of stop words, or any other that you are interested in, first filter some sample &#8220;search phrases&#8221; and then remove all stop words from a larger piece of text.</div>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_176.gif" alt="" width="479" height="30" /></p>
<li>Modify the previous exercise so that the user can supply a list of punctuation in addition to the list of stop words to be used to filter the text.</li>
</ol>
<h3>9.5. Examples and Applications</h3>
<p>This section puts together many of the concepts and techniques developed earlier in the chapter to solve several nontrivial applied problems. The first example creates a function to generate random strings, mirroring the syntax of the built-in random number functions. People who work with large strings, such as those in genomic research, often partition their strings into small blocks and then perform some analysis on those substrings. We develop functions for partitioning strings as well as several examples for analyzing sequences of genetic code. An additional example covers checksums, which are used to verify stored and transmitted data. Finally, a word game is included in which we create blanagrams, a variant of anagrams.</p>
<h4>Random Strings</h4>
<blockquote>
<div class="Quote"><em>A blasphemous sect suggested &#8230;that all men should juggle letters and symbols until they constructed, by an improbable gift of chance, these canonical books.</em><br />
&#8212; Jorge L. Borges, <em>The Library of Babel </em>[<a href="#Borges83">11</a>]</div>
</blockquote>
<p>Those who work with genomic data often need to test their algorithms on strings. While it may be sensible to test against real data &#8211; for example, using genes on the human genome &#8211; random data might be more appropriate to quickly test and measure the efficiency of an algorithm. Although <em>Mathematica</em> has a variety of functions for creating random numbers, random variates, and so on, it does not have a function to create random sequences of strings. In this section we will create one.</p>
<p>To start, we will choose the characters A, C, T, and G &#8211; representing the nucleotide, or DNA, bases &#8211; as our alphabet, that is, the letters in the random strings we will create.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_177.gif" alt="" width="189" height="13" /></p>
<p>The key observation is that we want to choose one character at random from this list. Since we need to repeat this <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_72.gif" alt="" width="6" height="12" /> times, we need to randomly choose with replacement. That is the purpose of <tt>RandomChoice</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_178.gif" alt="" width="161" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_149.gif" alt="" width="183" height="13" /></p>
<p>This expression is a list of strings.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_179.gif" alt="" width="79" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_150.gif" alt="" width="352" height="13" /></p>
<p>Finally, we concatenate the strings.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_180.gif" alt="" width="173" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_151.gif" alt="" width="86" height="13" /></p>
<p>So a first attempt at putting these pieces together would look like this. Note the use of a default value of 1 for the optional argument <tt>n</tt> (see Section 6.1 for a discussion of default values for arguments to functions).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_181.gif" alt="" width="527" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_182.gif" alt="" width="264" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_152.gif" alt="" width="580" height="89" /></p>
<p>The default value of the second argument gives one choice.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_183.gif" alt="" width="231" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_153.gif" alt="" width="7" height="13" /></p>
<p>We can make the arguments a bit more general using structured patterns. The first argument in this next version must be a list consisting of a sequence of one or more strings.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_184.gif" alt="" width="136" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_185.gif" alt="" width="533" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_186.gif" alt="" width="224" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_154.gif" alt="" width="86" height="13" /></p>
<p>Here is a ten-character password generator.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_187.gif" alt="" width="476" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_155.gif" alt="" width="72" height="14" /></p>
<p>It is not hard to extend this function to create <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_73.gif" alt="" width="6" height="12" /> random strings of a given length. We essentially pass that argument structure to <tt>RandomChoice</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_188.gif" alt="" width="384" height="30" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_189.gif" alt="" width="288" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_156.gif" alt="" width="391" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_190.gif" alt="" width="288" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_157.gif" alt="" width="490" height="29" /></p>
<p>The exercises at the end of this section include a problem that asks you to add an option that provides a mechanism to weight the individual characters in the random string.</p>
<h4>Partitioning Strings</h4>
<p>Some string analysis requires strings to be broken up into blocks of a certain size and then computations are performed on those blocks. Although there is no built-in function for partitioning strings, we can easily create one, taking advantage of the syntax and speed of the built-in <tt>Partition</tt> function.</p>
<p>The <tt>Partition</tt> function requires a list as its first argument. To start, we will give it a list of the characters in a prototype string, a gene on the human genome.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_191.gif" alt="" width="219" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_158.gif" alt="" width="279" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_192.gif" alt="" width="202" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_159.gif" alt="" width="580" height="29" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_193.gif" alt="" width="108" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_160.gif" alt="" width="562" height="74" /></p>
<p>Now, partition this list of characters into lists of length 4 with offset 1.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_194.gif" alt="" width="241" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_161.gif" alt="" width="580" height="89" /></p>
<p>Because the number of characters in <tt>str</tt> is not a multiple of 4, this use of <tt>Partition</tt> has padded the last sublist with the first two characters from the original string; in other words, this has treated the list cyclically; not quite what we want here.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_195.gif" alt="" width="201" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_162.gif" alt="" width="36" height="13" /></p>
<p>A slightly different syntax for <tt>Partition</tt> gives an uneven subset at the end. We will need to use this form so as not to lose or introduce any spurious information.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_196.gif" alt="" width="317" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_163.gif" alt="" width="580" height="89" /></p>
<p>Finally, convert each sublist into a contiguous string.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_197.gif" alt="" width="155" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_164.gif" alt="" width="524" height="44" /></p>
<p>This puts everything together in a function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_198.gif" alt="" width="509" height="30" /></p>
<p>This partitions the string into nonoverlapping blocks of length 12.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_199.gif" alt="" width="169" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_165.gif" alt="" width="580" height="29" /></p>
<p>This function operates on large strings fairly fast. Here we partition a random string of length ten million into nonoverlapping blocks of length ten.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_200.gif" alt="" width="313" height="18" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_201.gif" alt="" width="240" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_166.gif" alt="" width="112" height="13" /></p>
<h4>Adler Checksum</h4>
<p>Checksums, or hashes, are commonly used to check the integrity of data when that data are either stored or transmitted. A checksum might be created, for example, when some data are stored on a disk. To check the integrity of that data, the checksum can be recomputed and if it differs from the stored value, there is a very high probability that the data was tampered with. Hash functions are used to create hash tables which are used for record lookup in large arrays of data. As an example of the use of character codes, we will implement a basic checksum algorithm, the Adler checksum.</p>
<p><em>Mathematica</em> has a built-in function, <tt>Hash</tt>, that can be used to create hash codes, or checksums.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_202.gif" alt="" width="136" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_167.gif" alt="" width="150" height="13" /></p>
<p>If the string is changed, its checksum changes accordingly.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_203.gif" alt="" width="136" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_168.gif" alt="" width="150" height="13" /></p>
<p>We will implement a basic hash code, known as the Adler-32 checksum algorithm. Given a string <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_74.gif" alt="" width="49" height="12" /> consisting of concatenated characters <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_75.gif" alt="" width="9" height="12" />, we form two 16-bit sums <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_76.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_77.gif" alt="" width="6" height="12" /> as follows:</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_DisplayFormula_204.gif" alt="" width="371" height="31" /></p>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_78.gif" alt="" width="15" height="12" /> is the character code for the character <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_79.gif" alt="" width="9" height="12" />. The number 65521 is chosen as it is the largest prime smaller than <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_80.gif" alt="" width="16" height="15" />. Choosing primes for this task seems to reduce the probability that an interchange of two bytes will not be detected. Finally, the Adler checksum is given by</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_DisplayFormula_205.gif" alt="" width="61" height="12" /></p>
<p>Let us take <em>Mathematica</em> as our test word. We start by getting the Ascii character codes for each character.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_206.gif" alt="" width="195" height="29" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_169.gif" alt="" width="326" height="13" /></p>
<p>The number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_81.gif" alt="" width="9" height="12" /> above is given by the cumulative sums of the character codes, with 1 prepended to that list. (This step could also be done using <tt>FoldList</tt>.)</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_207.gif" alt="" width="248" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_170.gif" alt="" width="390" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_208.gif" alt="" width="101" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_171.gif" alt="" width="29" height="13" /></p>
<p>The number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_82.gif" alt="" width="6" height="12" /> is given by the cumulative sums from this last list, omitting the 1 at the beginning as it is already part of the cumulative sums.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_209.gif" alt="" width="216" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_172.gif" alt="" width="407" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_210.gif" alt="" width="101" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_173.gif" alt="" width="29" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_211.gif" alt="" width="68" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_174.gif" alt="" width="69" height="13" /></p>
<p>We can check our result against the algorithm implemented in the <tt>Hash</tt> function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_212.gif" alt="" width="211" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_175.gif" alt="" width="69" height="13" /></p>
<p>Finally, this puts these steps together in a reusable function. Our prototype worked with small numbers and so the need to work mod 65521 was not necessary. For general inputs, the arithmetic will be done using this modulus.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_213.gif" alt="" width="349" height="90" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_214.gif" alt="" width="201" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_176.gif" alt="" width="69" height="13" /></p>
<p>As an aside, here is its hash code in hexadecimal.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_215.gif" alt="" width="140" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_177.gif" alt="" width="57" height="13" /></p>
<p>And here is a lengthier example.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_216.gif" alt="" width="580" height="62" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_178.gif" alt="" width="78" height="13" /></p>
<h4>Search for Substrings</h4>
<p>As we have seen in this chapter, string patterns provide a powerful and compact mechanism for operating on text data. In this example, we will create a function that searches the dictionary for words containing a specified substring.</p>
<p>If our test substring is <em>cite</em>, here is how we would find all words that end in <em>cite</em>. Note the triple blank pattern to match any sequence of zero or more characters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_217.gif" alt="" width="216" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_179.gif" alt="" width="569" height="14" /></p>
<p>Here are all words that begin with <em>cite</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_218.gif" alt="" width="216" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_180.gif" alt="" width="137" height="13" /></p>
<p>And this gives all words that have <em>cite</em> somewhere in them, at the beginning, middle, or end.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_219.gif" alt="" width="260" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_181.gif" alt="" width="580" height="62" /></p>
<p>Using the double blank gives words that have <em>cite</em> in them but not beginning or ending with <em>cite</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_220.gif" alt="" width="246" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_182.gif" alt="" width="580" height="46" /></p>
<p>Let us put these pieces together in a reusable function <tt>FindWordsContaining</tt>. We will include one option, <tt>WordPosition</tt> that identifies where in the word the substring is expected to occur.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_221.gif" alt="" width="391" height="14" /></p>
<p>Depending upon the value of the option <tt>WordPosition</tt>, <tt>Which</tt> directs which expression will be evaluated.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_222.gif" alt="" width="580" height="110" /></p>
<p>Using the default value for <tt>WordPosition</tt>, this finds all words in the dictionary that start with the string <em>cite</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_223.gif" alt="" width="194" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_183.gif" alt="" width="137" height="13" /></p>
<p>And this finds all words that have <em>cite</em> anywhere in the word.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_224.gif" alt="" width="381" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_184.gif" alt="" width="580" height="62" /></p>
<p>Finally, here is a dynamic interface that includes a text field in which you can enter an input string; tabs are used to specify in which part of the word you expect the string to occur.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_225.gif" alt="" width="580" height="62" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_185.gif" alt="" width="324" height="208" /></p>
<p>For more on the creation of these sorts of dynamic interfaces, see Chapter 11.</p>
<h4>DNA Sequence Analysis</h4>
<p>DNA molecules are composed of sequences of the nitrogenous bases guanine, cytosine, thymine, and adenine. Guanine and cytosine bond with three hydrogen bonds and thymine and adenine bond with two. Research has indicated that high GC content (guanine and cytosine) DNA is more stable than that with lower GC. The exact reasons for this are not completely understood and determining the GC content of various DNA materials is an active area of biomolecular research. GC content is often described as a percentage of the guanine and cytosine nucleotides compared to the entire nucleotide content (Cristianini and Hahn 2007 [<a href="#Cristianini07">12</a>]). In this section we will create a function to compute the ratio of GC in any given DNA sequence or fragment.</p>
<p>We will start by importing a FASTA file consisting of human mitochondrial DNA, displaying some information about the contents of this file.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_226.gif" alt="" width="358" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_227.gif" alt="" width="436" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_186.gif" alt="" width="532" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_228.gif" alt="" width="143" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_187.gif" alt="" width="52" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_229.gif" alt="" width="162" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_188.gif" alt="" width="580" height="89" /></p>
<p>We use <tt>StringCount</tt> to count the number of occurrences of G or C in this sequence.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_230.gif" alt="" width="231" height="15" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_189.gif" alt="" width="43" height="13" /></p>
<p>And here is the number of occurrences of A or T.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_231.gif" alt="" width="231" height="15" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_190.gif" alt="" width="43" height="13" /></p>
<p>The GC percentage is given by the following ratio.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_232.gif" alt="" width="67" height="32" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_191.gif" alt="" width="72" height="13" /></p>
<p>Here then is an auxiliary function we will use in what follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_233.gif" alt="" width="265" height="78" /></p>
<p>Note that <tt>gcRatio</tt> expects a string as an argument, but this fails with <tt>hsMito</tt>, imported from an external source.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_234.gif" alt="" width="175" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_192.gif" alt="" width="580" height="105" /></p>
<p>It fails because <tt>Import</tt> returns a list consisting of a string, not a raw string. We can remedy this by writing a rule to deal with this argument structure and then call the first rule.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_235.gif" alt="" width="258" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_236.gif" alt="" width="107" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_193.gif" alt="" width="58" height="13" /></p>
<p>Typically, researchers are interested in studying the GC ratio on particular fragments of DNA and comparing it with similar fragments on another molecule. One common way of doing this is to compute the GC ratio for blocks of nucleotides of some given length. We will use the function <tt>StringPartition</tt>, developed earlier to partition the sequence into blocks of a given size. We will work with a small random sequence to prototype.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_237.gif" alt="" width="308" height="46" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_194.gif" alt="" width="549" height="29" /></p>
<p>Here are the GC ratios for each of the blocks given by <tt>lis</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_238.gif" alt="" width="119" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_195.gif" alt="" width="432" height="13" /></p>
<p>Finally, it is helpful to be able to identify each block by its starting position. So we first create a list of the starting positions for each block and then transpose that with the ratios.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_239.gif" alt="" width="316" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_196.gif" alt="" width="345" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_240.gif" alt="" width="539" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_197.gif" alt="" width="532" height="29" /></p>
<p>Here are all the pieces in one function, <tt>GCRatio</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_241.gif" alt="" width="442" height="78" /></p>
<p>And again, a second rule in case the string is wrapped in a list.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_242.gif" alt="" width="467" height="14" /></p>
<p>Let us try it out first on our prototype sequence.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_243.gif" alt="" width="111" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_198.gif" alt="" width="532" height="29" /></p>
<p>And then on the human mitochondrial DNA with block size 1000.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_244.gif" alt="" width="205" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_199.gif" alt="" width="580" height="44" /></p>
<p>Various types of analysis can then be performed on these blocks. For example, using <tt>Select</tt>, this quickly finds regions of high GC content.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_245.gif" alt="" width="216" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_200.gif" alt="" width="315" height="13" /></p>
<p>Here is a quick visualization of the GC content across the blocks.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_246.gif" alt="" width="222" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_201.gif" alt="" width="360" height="223" /></p>
<p>Numerous comparative studies have been done looking at the GC content for different organisms. One much-studied organism is <em>Thermoplasma volcanium</em>, a bacterium-like organism that exists in very high-acid and high-temperature environments. To accommodate the extreme conditions, organisms in such environments often have high GC content which has a higher thermal stability. The following sequence is in the public domain and was obtained courtesy of the National Center for Biotechnology Information (NCBI Nucleotide Database [<a href="#Nucleotide Database">13</a>]).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_247.gif" alt="" width="471" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_202.gif" alt="" width="580" height="44" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_248.gif" alt="" width="217" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_203.gif" alt="" width="55" height="13" /></p>
<p>Here is the GC ratio for the entire sequence.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_249.gif" alt="" width="136" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_204.gif" alt="" width="58" height="13" /></p>
<p>And here are the ratios for block sizes of 100000.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_250.gif" alt="" width="240" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_205.gif" alt="" width="576" height="59" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_251.gif" alt="" width="580" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_206.gif" alt="" width="360" height="219" /></p>
<h4>Displaying DNA Sequences</h4>
<p>DNA sequences are typically long strings of nucleotides that are difficult to visualize simply by looking at the string of characters. Various visualization tools have been used to work with these sequences and in this section we will look at a common way of viewing them in a formatted table.</p>
<p>As before, we will prototype with a short random string consisting of nucleotide characters G, C, A, and T.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_252.gif" alt="" width="301" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_207.gif" alt="" width="580" height="29" /></p>
<p>Using <tt>StringPartition</tt> developed earlier in this chapter, we split the string into blocks of a desired size.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_253.gif" alt="" width="213" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_208.gif" alt="" width="549" height="29" /></p>
<p>We have 13 blocks here, but for readability purposes, we will put five blocks on each line of output. We use the blank string <tt>" "</tt> to pad out any string shorter than the blocksize, in this case 10.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_254.gif" alt="" width="238" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_209.gif" alt="" width="433" height="44" /></p>
<p>The following code gives the starting positions for each line once we have set the block length and row length.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_255.gif" alt="" width="522" height="46" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_210.gif" alt="" width="79" height="13" /></p>
<p>We prepend the starting position of each row at the head of the row. Recall, the second argument to <tt>Prepend</tt> is the expression you wish to put in front (the indices) of your target expression (the rows).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_256.gif" alt="" width="280" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_211.gif" alt="" width="458" height="44" /></p>
<p>This is what the formatted output should look like.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_257.gif" alt="" width="337" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_212.gif" alt="" width="422" height="44" /></p>
<p>Finally, let us put this all together, setting up an option, <tt>BlockSize</tt> that is combined with the inherited options from <tt>Grid</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_258.gif" alt="" width="430" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_213.gif" alt="" width="564" height="94" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_259.gif" alt="" width="580" height="141" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_260.gif" alt="" width="301" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_214.gif" alt="" width="580" height="29" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_261.gif" alt="" width="130" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_215.gif" alt="" width="433" height="70" /></p>
<p>Let us exercise some of the options.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_262.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_216.gif" alt="" width="343" height="38" /></p>
<h4>Blanagrams</h4>
<p>A blanagram is an anagram for another word except for the substitution of one letter. Think of Scrabble with a blank square (blank + anagram = blanagram). For example, <em>phyla</em> is a blanagram of <em>glyph</em>: replace the <em>g</em> with an <em>a</em> and find anagrams. In this section we will create a function that finds all blanagrams of a given word.</p>
<p>We will prototype with a simple word, <em>glyph</em>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_263.gif" alt="" width="136" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_217.gif" alt="" width="93" height="14" /></p>
<p>Start by replacing the first letter in <em>glyph</em> with an <em>a</em> and then finding all anagrams (using <tt>Anagrams</tt> from Section 9.2). The third argument to <tt>StringReplacePart</tt> is a list of beginning and ending positions for the replacement.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_264.gif" alt="" width="268" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_218.gif" alt="" width="36" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_265.gif" alt="" width="79" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_219.gif" alt="" width="97" height="14" /></p>
<p>Now do the same for each character position in the word.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_266.gif" alt="" width="526" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_220.gif" alt="" width="238" height="14" /></p>
<p>Running <tt>Anagrams</tt> on each of these strings, only two appear as words in the dictionary.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_267.gif" alt="" width="176" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_221.gif" alt="" width="97" height="14" /></p>
<p>Having done this for the letter <em>a</em>, we now repeat for all other single characters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_268.gif" alt="" width="168" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_222.gif" alt="" width="471" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_269.gif" alt="" width="546" height="46" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_223.gif" alt="" width="502" height="206" /></p>
<p>Because of the extra nesting (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_83.gif" alt="" width="93" height="14" />) we need to flatten the output at a deeper level; and delete duplicates.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_270.gif" alt="" width="374" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_224.gif" alt="" width="238" height="14" /></p>
<p>Finally, put all the pieces together to create the function <tt>Blanagrams</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_271.gif" alt="" width="519" height="94" /></p>
<p>This turns out to be fairly quick for small words, but it bogs down for larger words.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_272.gif" alt="" width="201" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_225.gif" alt="" width="321" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_273.gif" alt="" width="208" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_226.gif" alt="" width="302" height="14" /></p>
<p>We will wait until Section 12.3 to optimize this code by profiling (identifying slow computational chunks) and taking advantage of parallel processing built into <em>Mathematica</em>.</p>
<h5>Exercises</h5>
<ol class="ItemNumbered">
<li>Generalize the <tt>RandomString</tt> function to allow for a <tt>Weights</tt> option so that you can provide a weight for each character in the generated string. Include a rule to generate a message if the number of weights does not match the number of characters. For example:</li>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_274.gif" alt="" width="438" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_227.gif" alt="" width="216" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_275.gif" alt="" width="470" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Output_228.gif" alt="" width="418" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Input_276.gif" alt="" width="420" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Message_277.gif" alt="" width="553" height="24" /></p>
<li>Write the function <tt>Anagrams</tt> developed in Section 9.2 without resorting to the use of <tt>Permutations</tt>. Consider using the <tt>Sort</tt> function to sort the characters. Note the difference in speed of the two approaches: one involving string functions and the other list functions that operate on lists of characters. Increase the efficiency of your search by only searching for words of the same length as your source word.</li>
<li>Rewrite the function <tt>FindWordsContaining</tt> using regular expressions instead of the patterns used in this section.</li>
<li>Using the text from several different sources, compute and then compare the number of punctuation characters per 1000 characters of text. <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_84.gif" alt="" width="136" height="14" /> gives a listing of many different texts that you can use.</li>
<li>The function <tt>StringPartition</tt> was developed specifically to deal with genomic data where one often needs uniformly-sized blocks to work with. Generalize <tt>StringPartition</tt> to fully accept the same argument structure as the built-in <tt>Partition</tt>.</li>
<li>Rewrite the text encoding example from Section 9.2 using <tt>StringReplace</tt> and regular expressions. First create an auxiliary function to encode a single character based on a key list of the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_85.gif" alt="" width="94" height="15" /> where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_86.gif" alt="" width="15" height="12" /> is a plaintext character and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_87.gif" alt="" width="13" height="12" /> is its ciphertext encoding. For example, the pair <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_88.gif" alt="" width="36" height="13" /> would indicate the character <em>z</em> in the plaintext will be encoded as an <em>a</em> in the ciphertext. Then create an encoding function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/04/Wellin_Math_91.gif" alt="" width="97" height="14" /> using regular expressions to encode any string <em>str</em> using the <em>key</em> consisting of the plaintext/ciphertext character pairs.</li>
</ol>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Ref:1">[1] </a></td>
<td>P. Wellin, <em>Programming with Mathematica</em>®<em>: An Introduction</em>, Cambridge, UK: Cambridge University Press, 2013. <a href="http://www.cambridge.org/wellin" target="blank">www.cambridge.org/wellin</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Sinkov66">[2] </a></td>
<td><span class="SmallCaps">A. Sinkov, </span><em>Elementary Cryptanalysis: A Mathematical Approach</em>, Washington, DC: The Mathematical Association of America, <span class="OsF">1966.</span></td>
</tr>
<tr>
<td class="Reference"><a name="Paar10">[3] </a></td>
<td><span class="SmallCaps">C. Paar</span> and <span class="SmallCaps">J. Pelzl, </span><em>Understanding Cryptography: A Textbook for Students and Practitioners,</em> New York: Springer, <span class="OsF">2010.</span></td>
</tr>
<tr>
<td class="Reference"><a name="Joyce1939">[4] </a></td>
<td><span class="SmallCaps">J. Joyce, </span><em>Finnegans Wake</em>, New York: Viking Penguin Inc., <span class="SmallCaps">1939.</span></td>
</tr>
<tr>
<td class="Reference"><a name="ProjectGutenberg">[5] </a></td>
<td><span class="SmallCaps">Project Gutenberg. (Apr 3, 2013) </span><a href="http://www.gutenberg.org/wiki/Main_Page" target="blank">www.gutenberg.org</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Manning08">[6] </a></td>
<td><span class="SmallCaps">C. D. Manning, P. Raghavan,</span> and <span class="SmallCaps">H. Schütze.</span> <em>Introduction to Information Retrieval,</em> New York: Cambridge University Press, <span class="OsF">2008.</span></td>
</tr>
<tr>
<td class="Reference"><a name="Working with String Patterns: WMDC">[7] </a></td>
<td><span class="SmallCaps">Wolfram Research. &#8220;Working with String Patterns</span>&#8221; from the Wolfram <em>Mathematica</em> Documentation Center&#8212;A Wolfram Web Resource. <a href="http://reference.wolfram.com/mathematica/tutorial/WorkingWithStringPatternsOverview.html">reference.wolfram.com/mathematica/tutorial/WorkingWithStringPatternsOverview.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Regular Expressions: WMDC">[8] </a></td>
<td><span class="SmallCaps">Wolfram Research. &#8220;Regular Expression</span>&#8221; from the Wolfram <em>Mathematica</em> Documentation Center&#8212;A Wolfram Web Resource. <a href="http://reference.wolfram.com/mathematica/tutorial/RegularExpressions.html">reference.wolfram.com/mathematica/tutorial/RegularExpressions.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Chicago10">[9] </a></td>
<td><span class="SmallCaps">University of Chicago Press,</span><em> The Chicago Manual of Style</em>, 16th ed., Chicago: University of Chicago Press, <span class="SmallCaps">2010.</span></td>
</tr>
<tr>
<td class="Reference"><a name="BASE">[10] </a></td>
<td>Centre for Applied Linguistics, University of Warwick. &#8220;<span class="SmallCaps">British Academic Spoken English (BASE)</span> and <span class="SmallCaps">BASE Plus Collections</span>.&#8221; <span class="SmallCaps">(Apr 3, 2013)</span> <a href="http://www2.warwick.ac.uk/fac/soc/al/research/collect/base/" target="blank">www2.warwick.ac.uk/fac/soc/al/research/collect/base</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Borges83">[11] </a></td>
<td><span class="SmallCaps">J. L. Borges, &#8220;</span>The Library of Babel,&#8221; in <em>Labyrinths: Selected Stories &amp; Other Writings,</em> New York: Modern Library, <span class="OsF">1983.</span></td>
</tr>
<tr>
<td class="Reference"><a name="Cristianini07">[12] </a></td>
<td><span class="SmallCaps">N. Cristianini</span> and <span class="SmallCaps">M. W. Hahn,</span> <em>Introduction to Computational Genomics: A Case Studies Approach</em>. New York: Cambridge University Press, <span class="OsF">2007.</span></td>
</tr>
<tr>
<td class="Reference"><a name="Nucleotide Database">[13] </a></td>
<td>National Center for Biotechnology Information. &#8220;<span class="SmallCaps">Nucleotide</span>.&#8221; <span class="SmallCaps">(Apr 3, 2013)</span> <a href="http://www.ncbi.nlm.nih.gov/nuccore" target="blank">www.ncbi.nlm.nih.gov/nuccore</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">P. Wellin, &#8220;Strings,&#8221; <em>The Mathematica Journal</em>, 2013. dx.doi.org/doi:10.3888/tmj.15-4.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">List of Additional Material</h3>
<p>Additional electronic files:</p>
<ol class="ItemNumbered">
<li> <a href="http://www.mathematica-journal.com/data/uploads/2013/04/638154522.tar.gz">www.mathematica-journal.com/data/uploads/2013/04/638154522.tar.gz</a></li>
<li> <a href="http://www.mathematica-journal.com/data/uploads/2013/04/StopWords.dat">www.mathematica-journal.com/data/uploads/2013/04/StopWords.dat</a></li>
</ol>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p>Paul Wellin worked for Wolfram Research from the early 1990s through 2011, directing the <em>Mathematica</em> training efforts with the Wolfram Education Group. Prior to that, he taught mathematics at both public school and at the university level for over 12 years. He has given talks, workshops, and seminars around the world on the integration of technical computing and education and he has served on numerous government advisory panels on these issues. He is the author or coauthor of several books on <em>Mathematica. </em>In addition to his writing, he is currently involved with several consulting projects, as well as book design and composition projects.</p>
<p class="TextAboutAuthor"><strong>Paul Wellin</strong><br />
<em>Chico, California</em><br />
<em><a href="mailto:paulwellin@gmail.com">paulwellin@gmail.com</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2013/04/strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling Robots Built with the LEGO&#174; MINDSTORMS&#174; NXT Brick</title>
		<link>http://www.mathematica-journal.com/2013/03/controlling-robots-built-with-the-lego-mindstorms-nxt-brick/</link>
		<comments>http://www.mathematica-journal.com/2013/03/controlling-robots-built-with-the-lego-mindstorms-nxt-brick/#comments</comments>
		<pubDate>Wed, 20 Mar 2013 18:42:51 +0000</pubDate>
		<dc:creator>Denis Cousineau</dc:creator>
				<category><![CDATA[Volume 15]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=33194</guid>
		<description><![CDATA[The NXT is a general-purpose processor that can be used to control motors and sensors; it is ideal for building autonomous robots. It can also communicate with more elaborate software located on a computer, using a Bluetooth communication port. In this article, we show how to communicate with the NXT by sending the correct bytes. [...]]]></description>
			<content:encoded><![CDATA[<p>The NXT is a general-purpose processor that can be used to control motors and sensors; it is ideal for building autonomous robots. It can also communicate with more elaborate software located on a computer, using a Bluetooth communication port. In this article, we show how to communicate with the NXT by sending the correct bytes. We also introduce a package that manages all the exchanges through functions. These functions can be used in conjunction with dynamic cells to display the robot&#8217;s status and control the robot&#8217;s motor.<span id="more-33194"></span></p>
<h3>Introduction</h3>
<p>Robots are ideal vehicles for testing cognitive theories regarding learning, adaptations, and classification of environmental stimuli. Most robots are built around a central processor in charge of dealing with the motor output and the sensory input. To that end, in 2006 LEGO released a new programmable brick, the LEGO MINDSTORMS NXT. This brick, equipped with four sensor inputs and three motor outputs, has 256 kilobytes of flash memory in which files can be stored. It can run programs compiled for the brick (files ending with the .rxe extension and compiled for this system using LEGO LabVIEW or third-party compilers such as NBC or NXC). The versatility and low cost of this brick has made it an ideal vehicle for developing robotic projects.</p>
<p>The NXT is well-suited for developing autonomous robots such as scouting robots. Learning algorithms can also be tested; for example, to find the exit of a maze more aptly than by trial and error. Finally, the NXT can also be used to study social cognition models, in which multiple robots must interact to enhance the group survival rate.</p>
<p>This article shows how to control the brick over a Bluetooth communication link. We also introduce the <em>Math4NXT</em> package, which makes the task easier. Used in conjunction with <em>Mathematica</em>&#8217;s built-in <tt>Dynamic</tt> command, controlling a LEGO robot becomes very simple.</p>
<h3>Establishing a Communication Link</h3>
<p>The first time you start the NXT brick, use your computer&#8217;s Bluetooth tools to look for the brick and establish a communication link. On that very first use, you have to provide a passkey on the brick (default is &#8220;1234&#8243;) and on the computer. Then you need to choose the &#8220;Dev&#8221; service available on the brick. At that point, a virtual serial communication port (a COM port) is allocated to serve as a communication link between the computer and the brick. The exact COM port given is variable (e.g. COM11) but remains constant for this NXT-computer pair (detailed instructions to achieve the pairing can be found in [<a href="#MathWorks">1</a>]). Once you know which COM port to use, you do not need to repeat the process.</p>
<p>The NXT brick has an operating system (firmware) that immediately handles requests received from the COM port. It does so even if the brick is currently running a program. These commands are called <em>direct commands</em> in the LEGO documentation [<a href="#TheLEGOGroup">2</a>]. Direct commands include file manipulation, motor control, sensor configuration and reading, and communication between bricks. Commands are sent over the COM port as <em>telegrams</em> composed of a succession of bytes (numbers between 0 and 255). For some commands, a reply can be returned by the brick, also in the form of a telegram. Each telegram is preceded by the length of the telegram, given as a WORD number, that is, using two bytes. Hence, controlling the NXT brick is simply a matter of sending the correct bytes in the correct order over a serial port.</p>
<p>In order to use a serial COM port, use the <em>Mathematica</em> package called SerialIO [<a href="#Raguet-Schofield">3</a>]. This package has two parts. The first is an executable program, suited for your computer&#8217;s processor and operating system. SerialIO provides such programs for Linux and Windows OS (both 32 and 64 bit) as well as for Mac OS X. The second part has the <em>Mathematica</em> functions that can be used in your project. It includes the commands <tt>SerialOpen</tt> and <tt>SerialClose</tt> to open and close a communication link on a given COM port, and <tt>SerialWrite</tt> and <tt>SerialRead</tt> to send or receive bytes from the COM port. The following figure illustrates the different layers through which information goes during a communication between an NXT brick and a computer.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_PlacedGraphics_1.gif" alt="" width="580" height="343" /></p>
<p class="NumberedFigureCaption"><strong>Figure 1.</strong> The software architecture by which an NXT brick and a computer can communicate. The last three boxes on the right represent <em>Mathematica</em> programs, and the last two are given by the package <em>Math4NXT</em> described next.</p>
<p>Get the package SerialIO from Wolfram Library Archive and install it in a folder of your choice (a good place is in the <em>Mathematica</em> AddOns folder, under the ExtraPackages subfolder). For convenience, you can set your working directory to this path so that the <em>MathLink</em>-compatible program is located automatically using the following instruction.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_1.gif" alt="" width="580" height="30" /></p>
<p>Then load the package with <tt>Needs</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_2.gif" alt="" width="129" height="13" /></p>
<p>The command is successful if you can see a process named SerialIO running in the background of your computer. The following command opens a COM port and therefore establishes a communication link with the brick (it must be turned on).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_3.gif" alt="" width="209" height="14" /></p>
<p>If you have an NXT brick and wish to evaluate the input cells in this article, select any input cell while holding the Alt key; that selects all input cells. Then from the <em>Mathematica</em> menu, choose Cell ▶ Cell Properties ▶ Evaluatable. Without an NXT brick, running these commands returns error messages or unevaluated input.</p>
<p>To see if the connection is open, look at the brick LCD display in the upper-left corner. If you see <span><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_1.gif" alt="" width="13" height="18" /></span>&lt;, it means the connection is not established. However, <span><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_3.gif" alt="" width="13" height="18" /></span>&lt;&gt; means that the connection is established. The variable <tt>mybrick</tt> contains the stream descriptor of the COM port and is used in all subsequent communications. Closing the COM port is done with the following instruction.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_4.gif" alt="" width="144" height="14" /></p>
<p>Exiting <em>Mathematica</em> (or ending the kernel) also closes the COM port and purges the process SerialIO running in the background.</p>
<h3>Sending a Telegram and Getting the Reply</h3>
<p>The SerialIO package was made to send text over the COM port (either individual characters or strings of text). However, for controlling the NXT, it makes more sense to send numbers directly. Hence, we need to convert numbers to the corresponding letters in the ASCII code before sending them. This is a bit awkward and we propose a neater solution later.</p>
<p>A telegram always begins with one byte indicating whether the NXT should return a reply telegram or not. This is your choice, but many commands sent to the brick only return a status byte (0 for success, or an error message). In the case of a status byte, the reply telegram is not useful. To ask for a reply, the first byte must be 0; 128 means that the NXT must not send a reply.</p>
<p>The second byte of a telegram is always the command number. These numbers are given in the LEGO Group documentation [<a href="#TheLEGOGroup">2</a>]. The subsequent bytes depend on the command sent.</p>
<p>For example, asking the NXT to play a sound is achieved by the direct command PlayTone. Its command number is 3. Then two parameters must be provided: the tone frequency (a number between 200 and 14000) and the tone duration (in milliseconds, a number between 0 and 65535). These two parameters are coded as UWORD (unsigned WORD), that is, over two bytes, the least significant byte first. For convenience, we write a conversion function <tt>toUWORD</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_5.gif" alt="" width="400" height="14" /></p>
<p>Hence, a tone frequency of 480 Hz for a duration of two seconds corresponds to the following bytes.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_6.gif" alt="" width="93" height="29" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_1.gif" alt="" width="54" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_2.gif" alt="" width="54" height="13" /></p>
<p>The whole telegram would then correspond to the following.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_7.gif" alt="" width="221" height="14" /></p>
<p>It must be preceded by the telegram length, obtained with the following instruction.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_8.gif" alt="" width="295" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_3.gif" alt="" width="39" height="13" /></p>
<p>We concatenate the two parts to get a complete message, and get a list of the characters corresponding to the numbers given (those characters may not be viewable on your computer system) with this line of code.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_9.gif" alt="" width="483" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_4.gif" alt="" width="126" height="13" /></p>
<p>Let us send those characters to the NXT brick, one by one.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_10.gif" alt="" width="271" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_5.gif" alt="" width="126" height="13" /></p>
<p>You should hear a tone now. Because we asked for a reply (the first byte was zero), we need to read it.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_11.gif" alt="" width="188" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_6.gif" alt="" width="21" height="13" /></p>
<p>Again, the reply is composed of text (the characters of which may not be easily viewable). Let us convert them to a list of numbers.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_12.gif" alt="" width="158" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_7.gif" alt="" width="93" height="13" /></p>
<p>The bytes returned are, in order: the length of the returned telegram, coded over two bytes in UWORD (here 3, 0 means a telegram of length 3); the number 2 indicates that this is a reply telegram; the number 3 indicates the command number that issued a reply (here, 3 is the number for the command PlayTone); and finally, the status of the command (where 0 indicates a success). The command PlayTone does not return other information; some direct commands may return more complex telegrams.</p>
<p>As an example, we send the command GetBatteryLevel. This command has number 11 and requires no parameters (no extra information). If a reply is asked for (but it is pointless to send this command and not ask for a reply), it returns the status of the command (0 for success) followed by two bytes indicating the voltage of the batteries on the NXT in millivolts. To decipher the voltage, let us create another conversion function, <tt>fromUWORD</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_13.gif" alt="" width="391" height="16" /></p>
<p>Let us assemble the telegram, concatenate the telegram length, convert this to a list of characters, and send them.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_14.gif" alt="" width="490" height="62" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_8.gif" alt="" width="61" height="13" /></p>
<p>Now, let us read the reply and convert it to numbers.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_15.gif" alt="" width="318" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_9.gif" alt="" width="158" height="13" /></p>
<p>The first two bytes are the reply length (5 bytes); 2 and 11 indicate that this is a reply for a GetBatteryLevel command; 0 indicates that the command was successful; and finally, 247 and 27 indicate the battery voltage, which we convert to a number with <tt>fromUWORD</tt>, defined above.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_16.gif" alt="" width="126" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_10.gif" alt="" width="29" height="13" /></p>
<p>Hence, the batteries convey 7.16 volts, much below the expected 9 volts for fresh batteries.</p>
<h3>Override <tt>SerialWrite</tt> to Send an Integer or a List of Integers</h3>
<p>Because it is more convenient to think in terms of numbers sent to the brick rather than characters, we expand the command <tt>SerialWrite</tt> contained in the package SerialIO to include the possibility of sending individual integers between 0 and 255 (bytes), and also to send a list of bytes.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_17.gif" alt="" width="468" height="142" /></p>
<p>With this expansion, a whole message (composed of bytes) can be sent in one call to <tt>SerialWrite</tt>. For example, the following instructions assemble again the PlayTone command (this time without a reply).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_18.gif" alt="" width="443" height="77" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_11.gif" alt="" width="192" height="13" /></p>
<p>The whole message is sent with one command call.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_19.gif" alt="" width="213" height="14" /></p>
<h3>The Direct Commands Provided in <em>Math4NXT</em></h3>
<p>The above shows how any command can be sent to the NXT brick and its reply read. Afterward, it is simply a question of assembling a telegram in the right order with the right information, and&#8212;if asked for&#8212;reading the reply and segmenting it into the correct information. To that end, the documentation provided by the LEGO Group ([<a href="#TheLEGOGroup">2</a>], particularly the appendix 2) is quite complete.</p>
<p>To make things simpler, we coded all the direct commands in a package called <em>Math4NXT</em>. First get the package <em>Math4NXT</em>. Since it uses the package SerialIO in the background, also install this package in a path that is searched by <em>Mathematica</em> (e.g. <tt>FileNameJoin[{$InstallationDirectory, "AddOns", "ExtraPackages", "SerialIO"}]</tt> ). Then load <em>Math4NXT</em> using the following instruction.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_20.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_12.gif" alt="" width="539" height="45" /></p>
<p>Since we did not place the package <em>Math4NXT</em> in a folder searched by <em>Mathematica</em>, we provided its path in the <tt>Needs</tt> instruction. Then open the serial port (if this was not already done) as before.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_21.gif" alt="" width="209" height="14" /></p>
<p>All the direct commands begin with the letters <tt>NXT</tt>. Hence, to read the battery level, the command in the package is called <tt>NXTGetBatteryLevel</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_22.gif" alt="" width="142" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Print_23.gif" alt="" width="425" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_24.gif" alt="" width="232" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_13.gif" alt="" width="338" height="14" /></p>
<p>By default, the command returns the answer using named strings (e.g. <tt>"Status"</tt>). You can extract one piece of information as usual.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_25.gif" alt="" width="123" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_14.gif" alt="" width="29" height="13" /></p>
<p>This format can be changed, for example to raw (i.e. bytes as in the previous two sections), using the option <tt>ResultFormat</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_26.gif" alt="" width="331" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_15.gif" alt="" width="158" height="13" /></p>
<p>Alternatively, the bytes sent and received can be displayed in a separate window using the option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Math_2.gif" alt="" width="75" height="13" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_27.gif" alt="" width="281" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_16.gif" alt="" width="338" height="14" /></p>
<p>This option opens the Messages window.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_PlacedGraphics_2.gif" alt="" width="580" height="168" /></p>
<p class="NumberedFigureCaption"><strong>Figure 2.</strong> The Messages window opens automatically when the option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Math_3.gif" alt="" width="61" height="12" /> is used.</p>
<p>All the direct commands are accessible.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_28.gif" alt="" width="41" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Print_29.gif" alt="" width="580" height="259" /></p>
<h3>Extending the Direct Commands</h3>
<p>The direct commands have many limitations. For one, due to the nature of the COM port, messages cannot be longer than 253 bytes. This is a big limitation when dealing with files that can be much longer. Also, the LEGO sensors all work in very different ways; some sensors are passive, not requiring power, while others are active, and still others are programmable, like the I2C sensors. To make use of the commands more uniformly and to avoid the length limitation, we programmed higher-level commands that deal internally with these difficulties.</p>
<p>The names of all of these commands begin with <tt>M4N</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_30.gif" alt="" width="41" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Print_31.gif" alt="" width="580" height="97" /></p>
<p>One example is the command <tt>M4NFileNames</tt> that lists all the files present on the brick (optionally with the file size).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_32.gif" alt="" width="99" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Print_33.gif" alt="" width="478" height="28" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_34.gif" alt="" width="414" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_17.gif" alt="" width="193" height="158" /></p>
<p>This command works by calling the direct commands <tt>NXTFindFirst</tt> (command number 134), <tt>NXTFindNext</tt> (135), and <tt>NXTClose</tt> (132), using the algorithm given in Program 1. To see the multiple calls to NXT commands, use the option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Math_4.gif" alt="" width="75" height="13" /> in <tt>M4NFileNames</tt>.</p>
<div class="Program">
<pre>res=NXTFindFirst[mybrick,"*.*"];
While [("Status"/.res)=0,
    res=NXTFindNext[mybrick,"Handle"/.res]
]
NXTClose[mybrick];</pre>
</div>
<div class="NumberedProgramCaption"><strong>Program 1.</strong> General algorithm used by <tt>M4NFileNames</tt> to retrieve all the file names present on the NXT brick. This algorithm does not show how to gather the file names (contained as bytes in <tt>res</tt>) into a list.</div>
<p>Likewise, to facilitate the use of sensors, a command is provided that informs <em>Mathematica</em> of the sensor types connected. Afterward, reading the sensor is done according to the type of sensor connected. To set the sensor type, use <tt>M4NSetSensor</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_35.gif" alt="" width="309" height="14" /></p>
<p>After this, reading the sensor is done with a universal command, <tt>M4NReadSensor</tt>. To keep in line with the convention of direct commands, the first sensor is on the NXT input port <tt>0</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_36.gif" alt="" width="177" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_18.gif" alt="" width="7" height="13" /></p>
<p>The result is either <tt>1</tt> for &#8220;pressed&#8221; or <tt>0</tt> for &#8220;unpressed.&#8221; This command works the same way whatever type of sensor is connected. Hence, if you connect the ultrasound sensor on the third sensor input, you can issue the following two commands.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_37.gif" alt="" width="431" height="14" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_38.gif" alt="" width="263" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_19.gif" alt="" width="7" height="13" /></p>
<p>The ultrasound sensor is a complex sensor aimed at detecting the distance of obstacles in front of it (in centimeters). It is equipped with a microprocessor that follows the I2C protocol. It must first be powered up and time given to it to boot up before a reading can be made. Using the option <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Math_5.gif" alt="" width="75" height="13" />, you see that much more exchange of information is needed to initialize an ultrasound sensor than to initialize a touch sensor. Yet, all these transactions are completely invisible with the <tt>M4N</tt> commands.</p>
<h3>Working with Motors</h3>
<p>Another limitation of the direct commands provided by the NXT&#8217;s firmware concerns the motor control. The new LEGO motors contain tacho counters that keep track of the number of degrees of rotation executed. However, the direct command can only stop a motor once a target number of degrees is reached, so that in effect, the motor overturns.</p>
<p>PID control of a motor is a more effective way of controlling rotation. It sets a target number of degrees and adjusts the power of the motor so that it slows down when the target is almost reached (using integral and derivative; see [<a href="#Sluka">4</a>, <a href="#Artus">5</a>]).</p>
<p>The authors of [<a href="#Artus">5</a>] developed a PID controller for the NXT. This controller is located on the NXT brick; the computer sends a target movement, and the controller takes control of the motor, adjusting the power until the target number of degrees is reached. The controller program is called MotorControl22.rxe<em>, </em>for Version 2.2.</p>
<p>Get the program MotorControl22.rxe and transfer it to the brick. To do so, import the contents of the file into <em>Mathematica</em> and download this to the NXT. Once set (this step may take a few minutes over Bluetooth as the controller is 37 kilobytes long), start the controller. Here are the instructions to do so; the first part checks that the file is not already on the brick.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_39.gif" alt="" width="460" height="78" /></p>
<p>Finally, inform your program of what type of motors you have and to which port they are connected using <tt>M4NSetMotor</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_40.gif" alt="" width="445" height="14" /></p>
<p>Incidentally, <tt>M4NSetMotor</tt> uploads MotorControl22.rxe if it is not present on the brick, and starts this program if it is not currently running. Therefore, you do not have to worry about these technicalities and can rely on <tt>M4NSetMotor</tt> alone.</p>
<p>Now that the controller is up and running, you can send orders to it using commands related to motors.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_41.gif" alt="" width="84" height="13" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Print_42.gif" alt="" width="580" height="61" /></p>
<p><tt>M4NRunMotor</tt>, <tt>M4NStopMotor</tt>, and <tt>M4NBrakeMotor</tt> can be used on regular motors as well as on tacho motors. However, <tt>M4NRunMotorFor</tt> can only be used with tacho motors and involves the PID controller. Once a motor is controlled by the PID controller, you should not send other instructions to it. Therefore, the predicate <tt>M4NRunMotorFreeQ</tt> can be used to check if the controller is done.</p>
<p>The following instruction starts the two motors.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_43.gif" alt="" width="194" height="14" /></p>
<p>Stop the motors using two different modes (<tt>M4NBrakeMotor</tt> locks the motor, whereas <tt>M4NStopMotor</tt> ceases to power the motor).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_44.gif" alt="" width="214" height="30" /></p>
<p>The following instructions check that motor <tt>MOTORA</tt> is free before a movement, during the movement (10 complete turns), and six seconds after the movement began.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_45.gif" alt="" width="472" height="78" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_20.gif" alt="" width="29" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_21.gif" alt="" width="36" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_22.gif" alt="" width="29" height="13" /></p>
<h3>Configuring a Robot</h3>
<p>At the level of the program, a robot has a certain configuration, defined by what sensors are connected to the input and what motors are connected to the output. We showed two commands earlier that can be used to define the sensors and the motors.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_46.gif" alt="" width="445" height="30" /></p>
<p>We created a general command, <tt>M4NInitialize</tt>, whose purpose is to set all these items in one command. In addition, it can also be used to set the volume level and give a name to the brick (if you have many bricks, a good habit is to rename them by the COM port to which they are connected).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_47.gif" alt="" width="580" height="30" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_23.gif" alt="" width="107" height="14" /></p>
<p>In addition, <tt>M4NInitialize</tt> checks that the firmware version on the NXT is compatible with this package and checks that the battery has enough charge (it returns a warning if not). It is also possible to give the path of the folder containing the controller MotorControl22.rxe with the option <tt>MotorControlPath</tt> in case it is not already on the NXT.</p>
<h3>Dynamic Control of the Robot</h3>
<p>The <tt>M4N</tt> and <tt>NXT</tt> commands can be used dynamically. For example, to get the current state of the touch sensors, you can follow these steps.</p>
<p>First, initialize the sensors using <tt>M4NInitialize</tt> or <tt>M4NSetSensor</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_48.gif" alt="" width="580" height="30" /></p>
<p>The <tt>ShowSensor</tt> function creates a panel with a title containing <tt>On</tt> or <tt>Off</tt>, based on the sensor value. This function uses some options for aesthetic purposes only.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_49.gif" alt="" width="580" height="46" /></p>
<p>Then, we can use <tt>ShowSensor</tt> four times in a row to get a row of indicators.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_50.gif" alt="" width="578" height="46" /></p>
<p>The option <tt>UpdateInterval</tt> determines at what interval the sensors are consulted.</p>
<p>As a last example, we create a joystick that controls two motors. The speed of rotation of the motor (adjusted by the <tt>MotorPower</tt> option) depends on the up/down position of the joystick. In addition, the motors move synchronously if the left/right position of the joystick is centered.</p>
<p>We first define an extended <tt>ClickPane</tt> that responds to more events than the regular <tt>ClickPane</tt> function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_51.gif" alt="" width="506" height="379" /></p>
<p>We must not forget to initialize the motors (so that the PID controller is turned on).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_52.gif" alt="" width="453" height="14" /></p>
<p>That is it. The following shows a panel with a red dot (the top of the joystick). It constantly sets the motor power to be proportional to the position of the joystick. In addition, if the joystick is released, it returns to the center with an exponential function implemented by the variable <tt>mult</tt>. Finally, if you click the pane anywhere, the joystick instantly returns to the center with a beep.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_53.gif" alt="" width="580" height="301" /></p>
<h3>A Line-Follower Project</h3>
<p>To illustrate a simple example of an autonomous robot, we program the line-follower robot. This robot&#8217;s purpose is to follow the edge of a line. The line should be dark on a light background (or vice versa; the contrast along the edge is the important factor). To achieve this, you need a robot equipped in the front with a light detector (see, for example, the assembly instructions given on p. 33 of the MINDSTORMS education booklet [<a href="#TheLEGOGroup">2</a>]).</p>
<p>For this project, the configuration requires a light sensor and two motors, which we initialize.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_54.gif" alt="" width="580" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_24.gif" alt="" width="107" height="14" /></p>
<p>In a first phase, we need to calibrate the sensor so that the readings on light and dark surfaces are known. Use the following to average 100 readings while you move the robot over a white surface.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_55.gif" alt="" width="405" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_25.gif" alt="" width="36" height="13" /></p>
<p>Then use this while moving the robot over a dark surface.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_56.gif" alt="" width="405" height="14" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_26.gif" alt="" width="22" height="13" /></p>
<p>The mean of the above two values is the critical value. For a robot that follows the left edge of a dark line, for readings lighter than the mean, we want the robot to steer to the right (and for readings darker than the mean, we want the robot to steer to the left).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_57.gif" alt="" width="161" height="13" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Output_27.gif" alt="" width="43" height="13" /></p>
<p>The following short program moves the robot at a moderate speed (the variable <tt>basespeed</tt> is set to 20) and adjusts the base speed according to the difference between the current reading and the mean.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/03/Cousineau_Input_58.gif" alt="" width="545" height="141" /></p>
<p>The constant <tt>mult</tt> is used to control the magnitude of the steering. Larger values result in a robot&#8217;s making abrupt changes in direction. This quantity should be small for smooth movement. Yet, if there are abrupt curves in the trajectory, a small multiplier gives a robot that cannot turn enough to find the edge again. See the conclusion for more discussion.</p>
<h3>Technical Limitations</h3>
<p>There are a few direct commands that we chose not to implement in this package. These are concerned with rebooting the NXT brick, changing its firmware, erasing the flash memory, or executing a reset. In essence, these commands destroy the robot.</p>
<p>With the <tt>M4N</tt> commands and the <tt>NXT</tt> commands, the robot can be controlled very efficiently and very easily. However, the COM port is not very fast. Crucially, each switch in the direction of communication of the port requires 6 ms. This is the reason why replies should be avoided unless they are absolutely necessary. In some applications, these delays may be so important that the program must be moved to the brick in whole or in part. The PID controller MotorControl22.rxe is an example where the program is distributed over the two machines: the computer sends target moves and the brick executes the decisions millisecond by millisecond to achieve the requested move.</p>
<h3>Conclusion</h3>
<p>One recent theory in cognitive science is the embodiment theory. It states that a cognitive system must be in an interactive relation with the world to develop a meaningful representation of the world. This view contradicts the classical artificial intelligence (AI) view in which cognitive agents manipulate tokens or symbols that may not necessarily be related to aspects of the outside world. Hence, according to the AI view, the sensors and actuators are independent of the cognitive functions and may be built separately. This view is tenable as long as we are devising cognitive systems in a virtual world (e.g. using computer-based simulations). However, as soon as physical robots are actually constructed, we see how difficult it is to hold this position.</p>
<p>The simple line-follower program shows this. In a virtual environment, the line-follower simulator can be run at full speed and steering can be made as abrupt as desired, because there is no inertia and no risk that the robot falls over. When the physical robot is built, these become very serious concerns. Of course, the programmer adapts the program to take these risks into account (reducing the speed and lowering the multiplier factor). Likewise, the <tt>white</tt> and <tt>black</tt> readings are calibrated by the programmer in a very simple way. Yet, if the ambient lighting changes, the calibration must be done again. Further, as said earlier, if the multiplier <tt>mult</tt> is too small, the robot may not be able to steer quickly enough around a sharp curve. Finally, the line-follower robot uses wheels. If it used legs instead, flexibility and possible muscle tear would come into play.</p>
<p>All the above concerns can be seen at worst as annoyances, at best as challenges for the programmer. Yet, the simplest animals are immune to all of these concerns. The embodiment theory holds that organisms developed adequate representations by interacting with the world, and that those representations became robust with regard to all the possible sources of fault. Representations and algorithms given by a programmer, on the other hand, may not respond to real-life tests, however simple or elegant they are.</p>
<p>The NXT is a simple yet complete platform to test robots in real life. Combined with <em>Mathematica</em>&#8217;s computational power, it is easy to develop adaptive algorithms such as neural networks and see what kind of representations are self-constructed by the robot. It remains to be seen what the simplest adaptive line-follower program looks like.</p>
<h3>Acknowledgments</h3>
<p>The author would like to thank Vincent Brault, Dominic Langlois, and Sylvain Chartier from the CONEC laboratory, University of Ottawa, for their help during the development of the <em>Math4NXT</em> package.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="MathWorks">[1] </a></td>
<td>MathWorks. &#8220;Set Up a Bluetooth Connection.&#8221; (Feb 4, 2013) <a href="http://www.mathworks.com/help/simulink/ug/bluetooth-communications.html" target="blank">www.mathworks.com/help/simulink/ug/bluetooth-communications.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="TheLEGOGroup">[2] </a></td>
<td>The LEGO Group. &#8220;LEGO MINDSTORMS NXT Bluetooth Developer Kit.&#8221; (Jan 7, 2013) <a href="http://mindstorms.LEGO.com/en-us/support/files/default.aspx" target="blank">mindstorms.LEGO.com/en-us/support/files/default.aspx</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Raguet-Schofield">[3] </a></td>
<td>R. Raguet-Schofield. &#8220;SerialIO.&#8221; Wolfram Library Archive. (Jan 7, 2013) <a href="http://library.wolfram.com/infocenter/MathSource/5726">library.wolfram.com/infocenter/MathSource/5726</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Sluka">[4] </a></td>
<td>J. Sluka. &#8220;A PID Controller For LEGO MINDSTORMS Robots.&#8221; (Jan 7, 2013) <a href="http://www.inpharmix.com/jps/PID_Controller_For_Lego_Mindstorms_Robots.html" target="blank">www.inpharmix.com/jps/PID_Controller_For _Lego _Mindstorms _Robots.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Artus">[5] </a></td>
<td>Institute of Imaging &amp; Computer Vision. &#8220;RWTH&#8212;MINDSTORMS NXT Toolbox.&#8221; (Jan 7, 2013) <a href="http://www.mindstorms.rwth-aachen.de/trac/wiki/MotorControl" target="blank">www.mindstorms.rwth-aachen.de/trac/wiki/MotorControl</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">D. Cousineau, &#8220;Controlling Robots Built with the LEGO® MINDSTORMS® NXT Brick,&#8221; <em>The Mathematica Journal</em>, 2013. dx.doi.org/doi:10.3888/tmj.15-3.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">Denis Cousineau is a professor at the University of Ottawa in cognitive psychology. He runs research in artificial intelligence as well as on human categorization processes.</p>
<p class="TextAboutAuthor"><strong>Denis Cousineau</strong><br />
<em>École de psychologie<br />
Université d&#8217;Ottawa<br />
136, rue Jean-Jacques Lussier<br />
Ottawa (ON), K1N 6N5, CANADA</em><br />
<em><a href="mailto:Denis.Cousineau@UOttawa.ca">Denis.Cousineau@UOttawa.ca</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2013/03/controlling-robots-built-with-the-lego-mindstorms-nxt-brick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced Animation in Mathematica</title>
		<link>http://www.mathematica-journal.com/2013/02/advanced-animation-in-mathematica/</link>
		<comments>http://www.mathematica-journal.com/2013/02/advanced-animation-in-mathematica/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 21:32:24 +0000</pubDate>
		<dc:creator>Stewart Dickson</dc:creator>
				<category><![CDATA[Volume 15]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=32957</guid>
		<description><![CDATA[The motivation for this article lies in 3D computer graphics animation systems that were developed twenty to thirty years ago. The author particularly sees the connection between Mathematica and the animation system that ran in Genera Lisp on the Symbolics platform. This article presents a method for programmatically operating on an animation scene graph in [...]]]></description>
			<content:encoded><![CDATA[<p>The motivation for this article lies in 3D computer graphics animation systems that were developed twenty to thirty years ago. The author particularly sees the connection between <em>Mathematica</em> and the animation system that ran in Genera Lisp on the Symbolics platform. This article presents a method for programmatically operating on an animation scene graph in <em>Mathematica</em> represented in the X3D extension of the Extensible Markup Language (XML). Below is presented historical and conceptual background on the animation scene graph and a contemporary example. Further motivation came from comparing the user interface design of a current, advanced animation system to an animation scene graph implemented in X3D and uploaded to Wolfram|Alpha Pro. Finally, this article presents an instance where an X3D scene graph was used in the &#8220;Fingerspelling Sign Language&#8221; Demonstration [<a href="#DicksonMartell">1</a>].<span id="more-32957"></span></p>
<p><em>Mathematica</em> organizes text, computable mathematical typesetting, and graphics as a notebook document. 3D computer graphics simulation, animation, and rendering systems organize graphics primitives so as to give the user a handle on the complexity required to model reality&#8212;a formidable task. An animation system, such as Autodesk Maya [<a href="#Maya">2</a>], presents complexity in a hierarchical way such that it can be selectively hidden, but subparts of it can be easily navigated to in order to manipulate the graphics primitives that make up the simulated 3D graphic scene.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_PlacedGraphics_1.gif" alt="" width="512" height="408" /></p>
<p class="NumberedFigureCaption"><strong>Figure 1.</strong> Pt. Reyes [<a href="#Reyes">3</a>, <a href="#Cook">4</a>].</p>
<p>In <em>Mathematica</em> and in an advanced 3D graphics animation or simulation system, the task of representing 3D graphics primitives for manipulation and then passing them off to graphics hardware or to an external system for high-quality rendering is the same, but a high-performance animation system approaches the task differently from <em>Mathematica</em>. In the early 1990s, Silicon Graphics, Inc. (SGI) devised the scene graph as a hierarchical mechanism for organizing complex 3D graphics simulations. The scene graph model has been adopted by most powerful animation systems. But, expressions in Autodesk Maya&#8212;the language it provides to extend its capabilities to model real-world processes&#8212;are very limited. The high-performance animation system is optimized to manipulate complexity, but not to generate it.</p>
<p>The <em>Mathematica</em> language&#8217;s ability to computationally model reality is absolutely unlimited. Circa 1993, the Symbolics S-Graphics package was widely thought to contain the best geometrical modeling system available for animation [<a href="#Symbolics">5</a>]. Symbolics spawned the Open Genera Lisp system and the Macsyma computer algebra system. The bottom-level string-rewriting system of <em>Mathematica</em> is like Lisp. <em>Mathematica</em>&#8217;s programming paradigm promotes use of (lambda) functions. I think that these parallels between <em>Mathematica</em> and a very advanced, albeit historically early, computer animation system should not be dismissed.</p>
<p>Advanced 3D graphics animation and simulation systems can benefit from <em>Mathematica</em>&#8217;s programming language and <em>Mathematica</em> graphics can benefit from the hierarchical organization of the animation scene graph. It is easy to get started using a scene graph in <em>Mathematica</em>. I used this technique in the animated hand model of the &#8220;Fingerspelling Sign Language&#8221; Wolfram Demonstration [<a href="#DicksonMartell">1</a>].</p>
<p>The scene graph is a basic structure of the SGI Open Inventor system [<a href="#Wernecke">6</a>]. (See Figure 2 and also the Coin3D project) [<a href="#Kongsberg1">7</a>]. These systems render graphic primitives interactively by traversing the scene graph (it is a tree structure) and emitting OpenGL code (a language understood by graphics hardware) [<a href="#SiliconGraphics">8</a>] for the graph Shape node entities as they are traversed [<a href="#Kongsberg2">9</a>]. Graphics Shape primitives are animated by placing 3D coordinate Transform nodes ahead of them in the scene graph [<a href="#Kongsberg3">10</a>]. A transformation stack is accumulated as the traversal descends tree branches, and the stack of transforms is applied to the graphics shape primitives and emitted as OpenGL (or other RenderAction) directives as they are encountered [<a href="#Kongsberg4">11</a>].</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_PlacedGraphics_2.gif" alt="" width="422" height="496" /></p>
<p class="NumberedFigureCaption"><strong>Figure 2.</strong> &#8220;Example of a Scene Graph&#8221; (Chapter 1, Figure 1-2 , [<a href="#Wernecke">6</a>]).</p>
<p>Open Inventor 2.0 became the basis for the first version of the Virtual Reality Modeling Language (VRML 1.0) [<a href="#VRML">12</a>]; X3D [<a href="#Web3D">13</a>] is the latest successor to VRML Version 2.0 [<a href="#Ames">14</a>] (1997) and it is implemented in XML. In Open Inventor, Separator [<a href="#Kongsberg5">15</a>] nodes are objects that inherit from the Group class (e.g., a Separator node is a kind of Group object) [<a href="#Kongsberg6">16</a>]. In VRML 2.0, Transform nodes also act implicitly as a Group mechanism in the hierarchy as well. Property nodes include Materials, which specify object surface illumination and appearance properties to be applied to subsequent Shape nodes in the scene graph tree.</p>
<p>If the Computable Document Format (CDF) is <em>Mathematica</em>&#8217;s answer to the Portable Document Format (PDF), then CDF organizes <tt>Graphics3D</tt> objects in it as a two-dimensional document. The X3D Document Object Model (DOM) [<a href="#w3schools">17</a>] could be <em>Mathematica</em>&#8217;s answer to organizing <tt>Graphics3D</tt> objects in the animation scene graph to represent a virtual world.</p>
<p>The key to this observation was the work I did on the Wolfram|Alpha Pro XML file upload scanner [<a href="#WolframRef16">18</a>]. As of the time of this writing, Wolfram|Alpha and the Wolfram Demonstrations Project are compatible with <em>Mathematica</em> 8. In this version<em>, Mathematica</em> does not yet have an X3D importer, but I have discovered that it is actually much more powerful to import an animation scene graph implemented in X3D using <em>Mathematica</em>&#8217;s quite excellent XML importer. All you have to do to use it is to rename the X3D file to use the .xml extension instead. The XML importer preserves the tree hierarchy of the XML Document Object Model (DOM) and allows you to traverse the X3D animation scene graph in <em>Mathematica</em> after the style of an advanced animation system such as Autodesk Maya.</p>
<p>Figure 3 shows the Maya outliner user interface view of an animation rig to articulate a &#8220;sausage&#8221; hand model constructed of Non-Uniform Rational B-Spline (NURBS) sphere primitives. The tree structure represents the parent-child hierarchy of sphere geometry nodes and their 3D coordinate transforms. The nodes in the graph are selectable and, when selected, provide access to the Maya animation channel editor for the transform values (translation, rotation, scale) for each node.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_PlacedGraphics_3.gif" alt="" width="335" height="531" /></p>
<p class="NumberedFigureCaption"><strong>Figure 3.</strong> Outliner user interface in Autodesk Maya 2013.</p>
<p>Figure 4 shows the <tt>ExpressionTreePlot</tt> seen when you upload to Wolfram|Alpha Pro the X3D scene graph for the hand model of the &#8220;Fingerspelling Sign Language&#8221; Demonstration as an XML file. This file is supplied in the additional electronic files accompanying this article.</p>
<p>The Wolfram|Alpha XML Pro upload response shows an <tt>ExpressionTreePlot</tt>, restyled for Wolfram|Alpha, of a simplification of the XML DOM tree.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_PlacedGraphics_4.gif" alt="" width="572" height="1215" /></p>
<p class="NumberedFigureCaption"><strong>Figure 4.</strong> The response to uploading an X3D hand animation rig as XML to Wolfram|Alpha Pro.</p>
<p>The XML file itself is of the following form.</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&#8230;<br />
&lt;!DOCTYPE X3D PUBLIC &#8220;ISO//Web3D//DTD X3D 3.0//EN&#8221; &#8230;<br />
&#8230;<br />
&lt;head&gt;<br />
&#8230;<br />
&lt;/head&gt;<br />
&lt;Scene&gt;<br />
&lt;Group&gt;<br />
&#8230;<br />
&lt;Transform DEF=&#8217;Relbow&#8217; translation=&#8217;0.0 0.0 0.0&#8242;<br />
rotation=&#8217;0.0 0.0 1.0 0.0&#8242;&gt;<br />
&#8230;<br />
&lt;Shape DEF=&#8217;Rhand_thumbMcarpalGeom&#8217;&gt;<br />
&lt;Sphere DEF=&#8217;Rhand_thumbMcarpalSphere&#8217;/&gt;<br />
&lt;/Shape&gt;<br />
&#8230;<br />
&lt;/Transform&gt;<br />
&#8230;<br />
&lt;/Group&gt;<br />
&lt;/Scene&gt;<br />
&lt;/X3D&gt;</p>
<p>The XML should be imported into the <em>Mathematica</em> &#8220;Fingerspelling Sign Language&#8221; Demonstration notebook source as follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Input_1.gif" alt="" width="526" height="385" /></p>
<p>The <tt>handXML</tt> expression is paraphrased for readability. Please see the &#8220;Fingerspelling Sign Language&#8221; Demonstration notebook source for the complete expression. Where hierarchy in the XML file is denoted by &lt;tag&gt;&#8230;&lt;/tag&gt;, hierarchy in the <em>Mathematica</em> <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Math_1.gif" alt="" width="217" height="14" /> structure is denoted by bracketed lists. The complete structure of the <tt>handXML</tt> expression is depicted in the <tt>ExpressionTreePlot</tt> in the Wolfram|Alpha XML file upload result.</p>
<p>In order to generate <tt>Graphics</tt> from the XML object hierarchy, functions must be written to translate X3D Transform and Shape nodes into the <em>Mathematica</em> <tt>Graphics3D</tt> equivalents. I provide some of these functions in the downloadable source code for the &#8220;Fingerspelling&#8221; Demonstration. In the X3D file, the Transform and Shape nodes are all named using the &#8220;DEF&#8221; rule. In an advanced animation system like Maya, names carry a huge amount of information and are absolutely essential.</p>
<p>A node selection user interface for the Animated Hand Model of the &#8220;Fingerspelling&#8221; Demonstration using a hierarchy of <tt>OpenerView</tt> instead of a static <tt>Grid</tt> of <tt>Checkbox</tt> can be constructed automatically in <em>Mathematica</em> by recursively traversing the X3D DOM tree (scene graph) using <tt>XMLObject</tt>. The structural hierarchy required to articulate the hand bones through a kinematic transform stack is reflected in the structure of the node selection user interface. Compare these graphics to the Outliner node selection user interface from Autodesk Maya, which was built precisely for the task of managing kinematic animation on a complex rig.</p>
<p><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_PlacedGraphics_5.gif" alt="" width="446" height="516" /></p>
<p class="NumberedFigureCaption"><strong>Figure 5.</strong> A node selection user interface for the Animated Hand Model of the &#8220;Fingerspelling&#8221; Demonstration using a hierarchy of <tt>OpenerView</tt>.</p>
<p>See also the Demonstrations &#8220;3D Skeletal Anatomy of the Arm&#8221; and &#8220;3D Skeletal Anatomy of the Torso&#8221; [<a href="#Dickson1">19</a>, <a href="#Dickson2">20</a>], which use a similar <tt>Graphics3D</tt> node selection user interface.</p>
<p>In the &#8220;Fingerspelling&#8221; Demonstration, I stored animation channels for keyframes as lists of node name and channel value rules.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Input_2.gif" alt="" width="567" height="94" /></p>
<p>Similarly, the node selection state is keyed by the Shape node name. The <tt>staticSelection</tt> list contains twenty <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Math_2.gif" alt="" width="82" height="13" /> rules in the &#8220;Fingerspelling&#8221; Demonstration source, paraphrased here for readability.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Input_3.gif" alt="" width="311" height="174" /></p>
<p>I apply the animated transform values to the X3D scene graph as imported into <em>Mathematica</em> using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Math_3.gif" alt="" width="524" height="14" />, a recursive function. Then I use <tt>collectTransforms</tt> to collect a stack of geometric coordinate transforms from the XML transform elements descending a branch. Then I apply <tt>Sow</tt> to a function that applies <em>Mathematica</em> geometric transforms to every XML Shape node encountered. To show the <tt>Graphics3D</tt>, I apply <tt>Reap</tt> to the results of <tt>ApplyXFormStack</tt> as follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Input_4.gif" alt="" width="499" height="78" /></p>
<p>Again, <tt>ApplyXFormStack</tt> calls <tt>collectTransforms</tt> descending the branches of the scene graph tree&#8212;analogous to glPushMatrix of OpenGL&#8212;and applies that transform stack to each Shape node it traverses. In the &#8220;Fingerspelling&#8221; Demonstration, we do ease-in/ease-out interpolation between <tt>anim</tt> lists containing keyframe poses corresponding to letters of the alphabet, then apply the interpolated rotation angle value to the joint transform of the same name.</p>
<p>Reading X3D as XML fully exposes all of the security vulnerabilities inherent in importing XML files into <em>Mathematica</em>. The <em>Mathematica</em> XML importer initially reads all of the Graphics Coordinate, Coordinate Index, and Transform fields as strings, which then must be converted to lists of numerical values using either <tt>ToExpression</tt> or <tt>Read</tt>. It is easy to encode expressions into an XML file that can do damage to a computer execution environment or file system when <em>Mathematica</em> runs <tt>Read</tt> or <tt>ToExpression</tt> on them. For similar reasons, <tt>Read</tt> and <tt>ToExpression</tt> are prohibited from Wolfram Demonstration notebooks.</p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/02/Dickson_Output_1.gif" alt="" width="448" height="512" /></p>
<p class="NumberedFigureCaption"><strong>Figure 6.</strong> An animated clip from the &#8220;Fingerspelling&#8221; Demonstration.</p>
<p>In &#8220;Fingerspelling Sign Language Using an Animated Hand Model,&#8221; keyframed animation curves are simple, sinusoidal ease-in/ease-out moves, whereas Maya uses cubic spline curves to interpolate animation channels. But the key point here is what is required to organize and animate multiple <tt>GraphicsComplex</tt> subparts of a complex <tt>Graphics3D</tt> object in <em>Mathematica</em>. In my opinion, the X3D incarnation of VRML represented in the XML DOM tree is an excellent model for doing this.</p>
<h3>Acknowledgments</h3>
<p>Thanks to George Fann, who first suggested that I look at X3D.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="DicksonMartell">[1] </a></td>
<td>S. Dickson and S. Martell. &#8220;Fingerspelling Sign Language Using an Animated Hand Model&#8221; from the Wolfram Demonstrations Project&#8212;A Wolfram Web Resource. <a href="http://demonstrations.wolfram.com/FingerspellingSignLanguageUsingAHandModel/">www.demonstrations.wolfram.com/FingerspellingSignLanguageUsingAHandModel</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Maya">[2] </a></td>
<td>Autodesk. &#8220;Maya.&#8221; (Feb 1, 2013) <a href="http://usa.autodesk.com/maya/" target="blank">usa.autodesk.com/maya</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Reyes">[3] </a></td>
<td>Wikipedia. &#8220;Reyes Rendering.&#8221; (Feb 1, 2013) <a href="http://en.wikipedia.org/wiki/Reyes_rendering" target="blank">en.wikipedia.org/wiki/Reyes_rendering</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Cook">[4] </a></td>
<td>R. Cook, L. Carpenter, T. Porter, B. Reeves, D. Salesin, and A. R. Smith. &#8220;Pt. Reyes.&#8221; (Feb 14, 2013) <a href="http://alvyray.com/Art/PtReyes.htm" target="blank">alvyray.com/Art/PtReyes.htm</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Symbolics">[5] </a></td>
<td>Wikipedia. &#8220;Symbolics.&#8221; (Feb 1, 2013 ) <a href="http://en.wikipedia.org/wiki/Symbolics" target="blank">en.wikipedia.org/wiki/Symbolics</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Wernecke">[6] </a></td>
<td>J. Wernecke, &#8220;The Inventor Mentor: Programming Object-Oriented 3D Graphics with Open Inventor<img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Trademark.gif" alt="" width="12" height="19" />, Release 2,&#8221; Redwood City, CA: Addison-Wesley, 1994.<br />
<a href="http://techpubs.sgi.com/library/dynaweb_docs/0630/SGI_Developer/books/Inv_Mentor/sgi_html/index.html" target="blank">techpubs.sgi.com/library/dynaweb_docs/0630/SGI_Developer/books/Inv_Mentor/sgi_html/index.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Kongsberg1">[7] </a></td>
<td>Kongsberg Oil &amp; Gas Technologies. &#8220;Coin3D.&#8221; (Feb 1, 2013) <a href="https://bitbucket.org/Coin3D/coin/wiki/Home" target="blank">bitbucket.org/Coin3D/coin/wiki/Home</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="SiliconGraphics">[8] </a></td>
<td>Silicon Graphics, Inc. &#8220;OpenGL: The Industry&#8217;s Foundation for High Performance Graphics.&#8221; (Feb 1, 2013) <a href="http://www.opengl.org/" target="blank">www.opengl.org</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Kongsberg2">[9] </a></td>
<td>Kongsberg Oil &amp; Gas Technologies. &#8220;SoShape Class Reference [Node Classes].&#8221; (Feb 1, 2013) <a href="http://doc.coin3d.org/Coin/classSoShape.html" target="blank">doc.coin3d.org/Coin/classSoShape.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Kongsberg3">[10] </a></td>
<td>Kongsberg Oil &amp; Gas Technologies. &#8220;SoTransform Class Reference [Node Classes].&#8221; (Feb 1, 2013) <a href="http://doc.coin3d.org/Coin/classSoTransform.html" target="blank">doc.coin3d.org/Coin/classSoTransform.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Kongsberg4">[11] </a></td>
<td>Kongsberg Oil &amp; Gas Technologies. &#8220;SoGLRenderAction Class Reference [Action Classes].&#8221; (Feb 1, 2013) <a href="http://doc.coin3d.org/Coin/classSoGLRenderAction.html" target="blank">doc.coin3d.org/Coin/classSoGLRenderAction.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="VRML">[12] </a></td>
<td>VRML.org. &#8220;Virtual Reality Modeling Language.&#8221; (Feb 18, 2013) <a href="http://web.archive.org/web/20121017095254/http://www.vrml.org" target="blank">web.archive.org/web/20121017095254/http://www.vrml.org</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Web3D">[13] </a></td>
<td>Web3D Consortium. &#8220;X3D Developers.&#8221; (Feb 4, 2013) <a href="http://www.web3d.org/x3d/" target="blank">www.web3d.org/x3d</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ames">[14] </a></td>
<td>A. Ames, D. Nadeau, and J. Moreland, <em>VRML 2.0 Sourcebook</em>, New York: John Wiley &amp; Sons, 1996. <a href="http://www.web3d.org/x3d/content/examples/Vrml2.0Sourcebook/index.html" target="blank">www.web3d.org/x3d/content/examples/Vrml2.0Sourcebook/index.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Kongsberg5">[15] </a></td>
<td>Kongsberg Oil &amp; Gas Technologies. &#8220;SoSeparator Class Reference [Node Classes].&#8221; (Feb 4, 2013) <a href="http://doc.coin3d.org/Coin/classSoSeparator.html" target="blank">doc.coin3d.org/Coin/classSoSeparator.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Kongsberg6">[16] </a></td>
<td>Kongsberg Oil &amp; Gas Technologies. &#8220;SoGroup Class Reference [Node Classes].&#8221; (Feb 4, 2013) <a href="http://doc.coin3d.org/Coin/classSoGroup.html" target="blank">doc.coin3d.org/Coin/classSoGroup.html</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="w3schools">[17] </a></td>
<td>w3schools.com. &#8220;XML DOM Tutorial.&#8221; (Feb 5, 2013) <a href="http://www.w3schools.com/dom/default.asp" target="blank">www.w3schools.com/dom/default.asp</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="WolframRef16">[18] </a></td>
<td>Wolfram Research. &#8220;Wolfram|Alpha Pro XML File Upload Example.&#8221; (Feb 4, 2013) <a href="http://www.wolframalpha.com/input/?i=+&amp;examplefile=1&amp;lk=3&amp;fileinput=FileUpload%2FAnimatedMethane.xml">www.wolframalpha.com/input/?i=+&amp;examplefile=1&amp;lk=3&amp;fileinput=FileUpload%2FAnimatedMethane.xml</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Dickson1">[19] </a></td>
<td>S. Dickson. &#8220;3D Skeletal Anatomy of the Arm&#8221; from the Wolfram Demonstrations Project&#8212;A Wolfram Web Resource. <a href="http://demonstrations.wolfram.com/3DSkeletalAnatomyOfTheArm/">demonstrations.wolfram.com/3DSkeletalAnatomyOfTheArm</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Dickson2">[20] </a></td>
<td>S. Dickson. &#8220;3D Skeletal Anatomy of the Torso&#8221; from the Wolfram Demonstrations Project&#8212;A Wolfram Web Resource. <a href="http://demonstrations.wolfram.com/3DSkeletalAnatomyOfTheTorso/">demonstrations.wolfram.com/3DSkeletalAnatomyOfTheTorso</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">S. Dickson, &#8220;Advanced Animation in <em>Mathematica</em>,&#8221; <em>The Mathematica Journal</em>, 2013. dx.doi.org/doi:10.3888/tmj.15-2.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">List of Additional Material</h3>
<p>Additional electronic files:</p>
<p><strong>1.</strong> <a href="http://www.mathematica-journal.com/data/uploads/2013/02/RHandTootsie2scale.xml">www.mathematica-journal.com/data/uploads/2013/02/RHandTootsie2scale.xml</a></p>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">Stewart Dickson was a programmer of 3D computer graphics and animation for broadcast video, theatrical film, digital cinema, and location-based entertainment from 1984 to 2002. He was a pioneer in digital sculpture from 1989. He has worked at Walt Disney Feature Animation, Oak Ridge National Laboratory, and the NOAA National Climatic Data Center. He has worked at Wolfram Research since 2011.</p>
<p class="TextAboutAuthor"><strong>Stewart Dickson</strong><em><br />
Wolfram Research, Inc.<br />
100 Trade Center Drive<br />
Champaign, IL 61820-7237</em><br />
<em><a href="mailto:sdickson@wolfram.com">sdickson@wolfram.com</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2013/02/advanced-animation-in-mathematica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evaluation of Gaussian Molecular Integrals</title>
		<link>http://www.mathematica-journal.com/2013/01/evaluation-of-gaussian-molecular-integrals-2/</link>
		<comments>http://www.mathematica-journal.com/2013/01/evaluation-of-gaussian-molecular-integrals-2/#comments</comments>
		<pubDate>Thu, 31 Jan 2013 12:00:30 +0000</pubDate>
		<dc:creator>Minhhuy Hô</dc:creator>
				<category><![CDATA[Volume 15]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=32662</guid>
		<description><![CDATA[II. Kinetic-Energy Integrals
This article carries out the evaluation of kinetic energy integrals using Gaussian-type functions with arbitrary Cartesian angular values. As an example, we calculate the kinetic matrix for the water molecule in the STO-3G basis set.
Introduction
In this article, the second of a series describing algorithms for evaluating molecular integrals, we detail the evaluation of [...]]]></description>
			<content:encoded><![CDATA[<h2>II. Kinetic-Energy Integrals</h2>
<p>This article carries out the evaluation of kinetic energy integrals using Gaussian-type functions with arbitrary Cartesian angular values. As an example, we calculate the kinetic matrix for the water molecule in the STO-3G basis set.<span id="more-32662"></span></p>
<h3>Introduction</h3>
<p>In this article, the second of a series describing algorithms for evaluating molecular integrals, we detail the evaluation of the kinetic energy integrals. Detailed accounts of molecular integrals can be found in the references of [<a href="#Ref:1">1</a>]. The electronic kinetic energy in atomic units (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_1.gif" alt="" width="128" height="12" />) involves integrals of the type</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_1.gif" alt="" width="248" height="32" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.1">(1)</a></td>
</tr>
</tbody>
</table>
<p>in which <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_2.gif" alt="" width="27" height="12" /> is an unnormalized Cartesian Gaussian <em>primitive</em> centered at the nucleus <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_3.gif" alt="" width="84" height="18" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_2.gif" alt="" width="397" height="76" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.2">(2)</a></td>
</tr>
</tbody>
</table>
<p>Here <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Alpha.gif" alt="" width="7" height="19" /> is the orbital exponent and the polynomial represents the angular part, in that the sum of the Cartesian angular momenta <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_4.gif" alt="" width="135" height="14" /> corresponds to functions of type <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_5.gif" alt="" width="5" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_6.gif" alt="" width="7" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_7.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_8.gif" alt="" width="7" height="12" />, &#8230;. One notable property of the Gaussian function, which will be used here, is that the derivative of a Gaussian function can be expressed as a sum containing Gaussians of lower and higher Cartesian angular values. In particular,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_3.gif" alt="" width="350" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.3">(3)</a></td>
</tr>
</tbody>
</table>
<p>Similarly, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_9.gif" alt="" width="210" height="26" />. This property is useful in integrals involving differential operators, such as the kinetic energy; in calculations involving the gradient of the energy or Hamiltonian; and in deriving one of the most important algorithms of Gaussian function computation, the recurrence relation.</p>
<p>The kinetic operator, expressed in Cartesian coordinates as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_10.gif" alt="" width="155" height="30" />, enables separation of the kinetic integrals into three components <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_11.gif" alt="" width="86" height="14" />. For example,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_4.gif" alt="" width="250" height="37" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.4">(4)</a></td>
</tr>
</tbody>
</table>
<p>Furthermore, if we also separate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_12.gif" alt="" width="14" height="12" /> into its Cartesian components, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_13.gif" alt="" width="13" height="12" /> becomes a product of three integrals</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_5.gif" alt="" width="377" height="77" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.5">(5)</a></td>
</tr>
</tbody>
</table>
<h3>Derivative of Gaussian Functions</h3>
<p>The last two integrals in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_14.gif" alt="" width="13" height="12" /> are simply overlap integrals and can be evaluated as outlined in [<a href="#Ref:1">1</a>]. Integrating by parts, the first integral is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_6.gif" alt="" width="511" height="72" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.6">(6)</a></td>
</tr>
</tbody>
</table>
<p>where, according to the property mentioned above, the first term can be expanded into two Gaussian products, which vanish at the integral limits.</p>
<p>Next, we consider the first term of the integrand. Expressing equation (<a href="#Eq.3">3</a>) in terms of (<a href="#Eq.1">1</a>) and rearranging, we get</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_7.gif" alt="" width="457" height="65" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.7">(7)</a></td>
</tr>
</tbody>
</table>
<p>Substituting the result into equation (<a href="#Eq.6">6</a>), we have</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_8.gif" alt="" width="481" height="32" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.8">(8)</a></td>
</tr>
</tbody>
</table>
<p>and expanding the polynomial part yields</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_9.gif" alt="" width="475" height="59" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.9">(9)</a></td>
</tr>
</tbody>
</table>
<p>We can now express the first integral of equation (<a href="#Eq.5">5</a>) in terms of one-dimensional Gaussian primitives:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_10.gif" alt="" width="443" height="106" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.10">(10)</a></td>
</tr>
</tbody>
</table>
<h3>Kinetic-Energy Integral</h3>
<p>We have now shown that the kinetic-energy integral can be written as a product of overlap integrals. The <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_15.gif" alt="" width="6" height="12" /> component, for example, is given by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_11.gif" alt="" width="473" height="136" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.11">(11)</a></td>
</tr>
</tbody>
</table>
<h4>Recurrence Relations</h4>
<p>Using the notation of [<a href="#Ref:1">1</a>], where the overlap integral of two Gaussians is expressed in terms of its orthogonal components,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_12.gif" alt="" width="457" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.12">(12)</a></td>
</tr>
</tbody>
</table>
<p>the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_16.gif" alt="" width="6" height="12" /> component of the kinetic-energy integral, equation (<a href="#Eq.11">11</a>), can be written as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_13.gif" alt="" width="490" height="81" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.13">(13)</a></td>
</tr>
</tbody>
</table>
<p>where the factor <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_17.gif" alt="" width="9" height="23" /> has been absorbed into the definition of the kinetic integral <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_18.gif" alt="" width="48" height="12" />. We will derive the recurrence relation for this term <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_19.gif" alt="" width="48" height="12" />. For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_20.gif" alt="" width="56" height="12" />, the first three terms of equation (<a href="#Eq.13">13</a>) are zero, and we are left with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_21.gif" alt="" width="115" height="12" />. Analogously, for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_22.gif" alt="" width="31" height="12" /> or <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_23.gif" alt="" width="31" height="12" />, we have</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_14.gif" alt="" width="253" height="28" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.14">(14)</a></td>
</tr>
</tbody>
</table>
<p>and the recurrence relation for the kinetic integral function with any two Cartesian angular momenta generalizes to</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_15.gif" alt="" width="319" height="55" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.15">(15)</a></td>
</tr>
</tbody>
</table>
<h4>Implementation</h4>
<p>The function <tt>Kin</tt> evaluates the kinetic integral of two Gaussian primitives; here <tt>alpha</tt>, <tt>beta</tt>, <tt>RA</tt>, <tt>RB</tt>, <tt>LA</tt>, and <tt>LB</tt> are <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_24.gif" alt="" width="7" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_25.gif" alt="" width="7" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_26.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_27.gif" alt="" width="8" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_28.gif" alt="" width="6" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_29.gif" alt="" width="7" height="12" /> as defined earlier. The first step is the evaluation of the overlap integral as described in [<a href="#Ref:1">1</a>].</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_1.gif" alt="" width="533" height="628" /></p>
<p>We describe in detail the evaluation of the kinetic-energy matrix for the water molecule (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_30.gif" alt="" width="96" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_31.gif" alt="" width="92" height="12" />, the geometry optimized at the HF/STO-3G level). The molecule lies in the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_32.gif" alt="" width="6" height="12" />-<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_33.gif" alt="" width="5" height="12" /> plane with Cartesian coordinates in atomic units.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_2.gif" alt="" width="245" height="43" /></p>
<p>In the STO-3G basis set, each atomic orbital is approximated by a sum of three Gaussians; their unnormalized primitive contraction coefficients and orbital exponents (taken from [<a href="#Ref:2">2</a>]) are as follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_3.gif" alt="" width="392" height="223" /></p>
<p>Here are basis function origins and Cartesian angular values of the orbitals, listed in the order <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_34.gif" alt="" width="38" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_35.gif" alt="" width="36" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_36.gif" alt="" width="36" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_37.gif" alt="" width="36" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_38.gif" alt="" width="43" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_39.gif" alt="" width="43" height="18" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_40.gif" alt="" width="43" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_4.gif" alt="" width="446" height="43" /></p>
<p>Specifically, for the kinetic-energy integral of the first primitive of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_41.gif" alt="" width="13" height="12" /> orbital of hydrogen atom 1, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_42.gif" alt="" width="31" height="12" />, and the first primitive of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_43.gif" alt="" width="20" height="12" /> orbital of the oxygen atom, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_44.gif" alt="" width="31" height="12" />,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_16.gif" alt="" width="468" height="67" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.16">(16)</a></td>
</tr>
</tbody>
</table>
<p>where the indices <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_45.gif" alt="" width="16" height="15" /> indicate primitive <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_46.gif" alt="" width="5" height="12" /> of basis function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_47.gif" alt="" width="3" height="12" />. The kinetic integral in terms of the kinetic and overlap function is then</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_17.gif" alt="" width="459" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.17">(17)</a></td>
</tr>
</tbody>
</table>
<p>We start with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_48.gif" alt="" width="60" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_49.gif" alt="" width="60" height="12" />, and from the first four equations of the module, we use the recurrence scheme to build up the overlap values needed for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_50.gif" alt="" width="38" height="12" />. We will need values up to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_51.gif" alt="" width="37" height="12" />,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_18.gif" alt="" width="372" height="181" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.18">(18)</a></td>
</tr>
</tbody>
</table>
<p>leading to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_52.gif" alt="" width="263" height="12" />.</p>
<p>Similarly, for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_53.gif" alt="" width="38" height="12" />, we will need <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_54.gif" alt="" width="37" height="12" /> which, in turn, comes from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_55.gif" alt="" width="37" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_56.gif" alt="" width="37" height="12" />. We have</p>
<p class="input">
<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_57.gif" alt="" width="57" height="12" />,
</p>
<p class="input">
<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_58.gif" alt="" width="102" height="12" />,
</p>
<p class="input">
<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_59.gif" alt="" width="102" height="12" />,
</p>
<p>leading to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_60.gif" alt="" width="168" height="12" />.</p>
<p>For the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_61.gif" alt="" width="6" height="12" /> component,</p>
<p class="input">
<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_62.gif" alt="" width="105" height="14" />,
</p>
<p class="input">
<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_63.gif" alt="" width="96" height="14" />,
</p>
<p class="input">
<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_64.gif" alt="" width="96" height="14" />,
</p>
<p>leading to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_65.gif" alt="" width="91" height="14" />.</p>
<p>With <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_66.gif" alt="" width="99" height="12" />, the kinetic integral of equation (<a href="#Eq.16">16</a>) is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_67.gif" alt="" width="80" height="12" />, which we can also obtain from the module <tt>Kin</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_5.gif" alt="" width="557" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Output_1.gif" alt="" width="72" height="12" /></p>
<p>Three Gaussian primitives <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_68.gif" alt="" width="27" height="12" /> for each atomic orbital <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_69.gif" alt="" width="24" height="12" /> result in nine integrals of the type that we have just evaluated. For example, the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_70.gif" alt="" width="18" height="12" /> element of the kinetic-energy matrix,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_DisplayFormulaNumbered_19.gif" alt="" width="299" height="42" /></td>
<td class="DisplayFormulaNumberedLabel"></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.19">(19)</a></td>
</tr>
</tbody>
</table>
<p>is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_71.gif" alt="" width="130" height="24" />, derived via a contraction scheme that requires the following normalization factor.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_6.gif" alt="" width="556" height="38" /></p>
<p>This calculates <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_72.gif" alt="" width="18" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_7.gif" alt="" width="311" height="133" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Output_2.gif" alt="" width="66" height="12" /></p>
<p>For larger basis sets, one needs only to replace the summation upper limit 3 in equation (<a href="#Eq.19">19</a>) with the appropriate number of primitives belonging to a particular basis function and an additional summation for the basis functions.</p>
<p>Finally, here is the resulting kinetic energy matrix.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Input_8.gif" alt="" width="426" height="133" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Output_3.gif" alt="" width="556" height="110" /></p>
<p>Since the kinetic-energy matrix is symmetrical, we need only to calculate the upper elements. The value of the elements <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_73.gif" alt="" width="109" height="12" /> hartree is the electronic kinetic energy of the hydrogen atom described by the STO-3G basis set (compared to the exact value of 0.5 hartree). Analogously, the element <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_74.gif" alt="" width="18" height="12" /> is the corresponding kinetic energy of an electron in the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2013/01/Ho_Kinetic_Math_75.gif" alt="" width="13" height="12" /> orbital of the oxygen atom, and so forth.</p>
<h3>Conclusion</h3>
<p>We have provided an introduction to the evaluation of kinetic-energy integrals involving Gaussian-type basis functions both analytically and by use of recurrence relations. The results are sufficiently general so that no modification of the algorithm is needed when larger basis sets with more Gaussian primitives or primitives with larger angular momenta are employed.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Ref:1">[1] </a></td>
<td>M. Hô and J. M. Hernández-Pérez, &#8220;Evaluation of Gaussian Molecular Integrals I,&#8221; <em>The Mathematica Journal</em>, 2012. <a href="http://dx.doi.org/doi:10.3888/tmj.14-3">doi:10.3888/tmj.14-3</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref:2">[2] </a></td>
<td>&#8220;Basis Set Exchange.&#8221; (April 12, 2012) <a href="https://bse.pnl.gov/bse/portal" target="blank">bse.pnl.gov/bse/portal</a>.</td>
</tr>
</tbody>
</table>
<p>M. Hô and J. M. Hernández-Pérez, &#8220;Evaluation of Gaussian Molecular Integrals II,&#8221; <em>The Mathematica Journal</em>, 2013. dx.doi.org/doi:10.3888/tmj.15-1.</p>
<h3 class="SectionAboutAuthor">About the Authors</h3>
<p class="TextAboutAuthor">Minhhuy Hô received his Ph.D. in theoretical chemistry at Queen&#8217;s University, Kingston, Ontario, Canada in 1998. He is currently a professor at the Centro de Investigaciones Químicas at the Universidad Autónoma del Estado de Morelos in Cuernavaca, Morelos, México.</p>
<p class="TextAboutAuthor">Julio-Manuel Hernández-Pérez obtained his Ph.D. at the Universidad Autónoma del Estado de Morelos in 2008. He has been a professor of chemistry at the Facultad de Ciencias Químicas at the Benemérita Universidad Autónoma de Puebla since 2010.</p>
<p class="TextAboutAuthor"><strong>Minhhuy Hô</strong><br />
<em>Universidad Autónoma del Estado de Morelos<br />
Centro de Investigaciones Químicas<br />
Ave</em>. <em>Universidad</em>, <em>No</em>. <em>1001</em>, <em>Col</em>. <em>Chamilpa<br />
Cuernavaca</em>, <em>Morelos</em>, <em>Mexico CP 92010<br />
</em><em><a href="mailto:homh@uaem.mx">homh@uaem.mx</a></em></p>
<p class="TextAboutAuthor"><strong>Julio-Manuel Hernández-Pérez<br />
</strong><em>Benemérita Universidad Autónoma de Puebla<br />
Facultad de Ciencias Químicas<br />
Ciudad Universitaria</em>, <em>Col</em>. <em>San Manuel<br />
Puebla</em>, <em>Puebla</em>, <em>Mexico CP 72570<br />
</em><em><a href="mailto:julio.hernandez@correo.buap.mx ">julio.hernandez@correo.buap.mx </a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2013/01/evaluation-of-gaussian-molecular-integrals-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the Integral of the Product of Three Bessel Functions over an Infinite Domain</title>
		<link>http://www.mathematica-journal.com/2012/12/on-the-integral-of-the-product-of-three-bessel-functions-over-an-infinite-domain/</link>
		<comments>http://www.mathematica-journal.com/2012/12/on-the-integral-of-the-product-of-three-bessel-functions-over-an-infinite-domain/#comments</comments>
		<pubDate>Thu, 20 Dec 2012 02:14:32 +0000</pubDate>
		<dc:creator>S. K. H. Auluck</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=32196</guid>
		<description><![CDATA[Fourier-Space Representation of Nonlinear Dynamics of Continuous Media in Cylindrical Geometry
Fourier-space representation of the partial differential equations describing nonlinear dynamics of continuous media in cylindrical geometry can be achieved using Chandrasekhar-Kendall (C-K) functions defined over infinite domain as an orthogonal basis for solenoidal vector fields and their generating function and its gradient as orthogonal bases [...]]]></description>
			<content:encoded><![CDATA[<h3>Fourier-Space Representation of Nonlinear Dynamics of Continuous Media in Cylindrical Geometry</h3>
<p>Fourier-space representation of the partial differential equations describing nonlinear dynamics of continuous media in cylindrical geometry can be achieved using Chandrasekhar-Kendall (C-K) functions defined over infinite domain as an orthogonal basis for solenoidal vector fields and their generating function and its gradient as orthogonal bases for scalar and irrotational vector fields, respectively. All differential and integral operations involved in translating the partial differential equations into transform space are then carried out on the basis functions, leaving a set of time evolution equations, which describe the rate of change of the spectral coefficient of an evolving mode in terms of an aggregate effect of pairs of interacting modes computed as an integral over a product of spectral coefficients of two physical quantities along with a kernel, which involves the following integral:</p>
<p class="input"><img class="alignnone size-full wp-image-32272" title="Auluck_Math_1" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_1.gif" alt="" width="330" height="20" /></p>
<p>involving the product of three Bessel functions of the first kind of integer order. This article looks at this integral&#8217;s properties using a semi-empirical approach supported by numerical experiments. It is shown that this integral has well-characterized singular behavior. Significant reduction in computational complexity is possible using the proposed empirical approximation to this integral.<span id="more-32196"></span></p>
<h3>Introduction</h3>
<p>Fourier-space representation of the nonlinear dynamics of continuous media is useful in studies on turbulent or self-organizing behavior that looks at the transport of energy across a wide range of scale lengths. Many problems in physics possess a native cylindrical geometry, and for such cases Chandrasekhar-Kendall (C-K) functions [<a href="#Ref-1">1</a>] (curl eigenfunctions) provide a complete orthogonal basis [<a href="#Ref-2">2</a>] for solenoidal fields, under appropriate boundary conditions. C-K functions defined over a finite cylinder have been used as an orthogonal basis for spatial-spectral expansion methods in plasma physics, usually in the incompressible regime [<a href="#Ref-3">3</a>, <a href="#Ref-4">4</a>, <a href="#Ref-5">5</a>], which neglects the role of irrotational fields in plasma dynamics. However, there are important physical effects [<a href="#Ref-6">6</a>] that involve a nonlinear interaction between solenoidal and irrotational fields, which can be studied only if both irrotational and solenoidal fields are taken into account on an equal footing.</p>
<p>The limitation to incompressible flows (or solenoidal fields in general) in spatial-spectral methods referred to above arises from the fact that the radial component of C-K functions and the radial derivative of their generating function (scalar potential solution of the Helmholtz equation) cannot both be zero on the same finite cylinder, so that the gradient of the generating function does not provide an orthogonal basis for irrotational flow. In contrast, when defined over an infinite domain, the generating function and its gradient do serve as orthogonal bases for scalar and irrotational vector fields, respectively. This is equivalent to Fourier-space representation in cylindrical geometry.</p>
<p>Although the mathematics of Fourier-space representation deals with spatial dimensions of the system and Fourier-space coordinates ranging from zero to infinity, no physical system has infinite size, and physical models of continuous media often stipulate a lower bound on scale lengths as a condition for their applicability. An infinite domain thus has a utilitarian meaning within the context of a physical theory: the upper and lower limits of integral transforms used in a physical theory are physically meaningful large and small numbers; mathematical zero and infinity are used to obtain the limit of a sequence of calculations with increasingly smaller and larger limits of integration in the interest of obtaining a tractable model and experimentally verifiable predictions [<a href="#Ref-7">7</a>].</p>
<p>The C-K functions, eigenfunctions of the curl operator in cylindrical geometry (defined by unit vectors <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_2.gif" alt="" width="5" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_3.gif" alt="" width="6" height="16" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_4.gif" alt="" width="5" height="14" /> and with coordinates <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_5.gif" alt="" width="37" height="12" />) are defined as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_6.gif" alt="" width="68" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_7.gif" alt="" width="91" height="12" />. The set of eigenfunctions, labeled by the four parameters <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_8.gif" alt="" width="9" height="12" />,<em> </em><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_9.gif" alt="" width="5" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_10.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_11.gif" alt="" width="5" height="12" />, is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32237" title="Auluck_DisplayFormulaNumbered_1" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_1.gif" alt="" width="363" height="62" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-1">(1)</a></td>
</tr>
</tbody>
</table>
<p>The parameter <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_12.gif" alt="" width="5" height="12" /> labels circular polarizations and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_13.gif" alt="" width="9" height="12" /> is the azimuthal mode number; the radial mode number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_14.gif" alt="" width="6" height="12" /> and axial mode number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_15.gif" alt="" width="5" height="12" /> are related to the magnitude of the eigenvalue by the relation <span><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Image_2.gif" alt="" width="71" height="23" /></span>. The orthogonality relations over an infinite cylinder are:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_2.gif" alt="" width="458" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-2">(2)</a></td>
</tr>
</tbody>
</table>
<p>For the infinite domain, the generating function of C-K functions</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_3.gif" alt="" width="184" height="15" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-3">(3)</a></td>
</tr>
</tbody>
</table>
<p>satisfies the relation</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_4.gif" alt="" width="412" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-4">(4)</a></td>
</tr>
</tbody>
</table>
<p>and its gradient satisfies the following relations</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32258" title="Auluck_DisplayFormulaNumbered_5" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_51.gif" alt="" width="516" height="122" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-5">(5)</a></td>
</tr>
</tbody>
</table>
<p>The orthogonality between the gradient of the generating function and the C-K functions is an exact consequence of their structure and does not depend on their asymptotic behavior. Partial differential equations of the nonlinear dynamics of continuous media can be translated into cylindrical Fourier space by performing all differential and integral operations with respect to spatial variables on the basis functions, leaving a set of time evolution equations. As an example, the equation of continuity,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_6.gif" alt="" width="89" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-6">(6)</a></td>
</tr>
</tbody>
</table>
<p>can be written in transform space as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32239" title="Auluck_DisplayFormulaNumbered_7" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_7.gif" alt="" width="489" height="115" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-7">(7)</a></td>
</tr>
</tbody>
</table>
<p>with the following shorthand notation: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_16.gif" alt="" width="159" height="18" />. The spectral coefficient of density is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_17.gif" alt="" width="50" height="12" />, that of solenoidal velocity is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_18.gif" alt="" width="58" height="12" />, and that of irrotational velocity is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_19.gif" alt="" width="50" height="12" />. The functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_20.gif" alt="" width="64" height="15" /> of mode numbers used in equation (<a href="#eq-7">7</a>) are defined as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_8.gif" alt="" width="475" height="104" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-8">(8)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32241" title="Auluck_DisplayFormulaNumbered_9" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_9.gif" alt="" width="419" height="101" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-9">(9)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32242" title="Auluck_DisplayFormulaNumbered_10" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_10.gif" alt="" width="307" height="51" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-10">(10)</a></td>
</tr>
</tbody>
</table>
<p>Time-evolution equations like (<a href="#eq-7">7</a>) describe the rate of change of the spectral coefficient of an evolving mode on the left-hand side (LHS) in terms of an aggregate effect of pairs of interacting modes on the right-hand side (RHS) computed as an integral over a product of spectral coefficients of two physical quantities along with a kernel. The physics contained in the vector and differential operators of the partial differential equations is transferred to the functions of mode numbers similar to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_21.gif" alt="" width="64" height="15" />, which involve the following integral over an infinite domain consisting of products of three Bessel functions of the first kind of integer order,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_11.gif" alt="" width="328" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-11">(11)</a></td>
</tr>
</tbody>
</table>
<p>This integral, referred to in the next section as the triple-Bessel (or 3B) integral, belongs to a class of integrals discussed by Watson [<a href="#Ref-9">9</a>, <a href="#Ref-10">10</a>], whose analytical theory is not known and is the subject of this article. From (<a href="#eq-7">7</a>), its properties as a distribution are seen to be relevant, but not its numerical value as a conventional Riemann integral, which may not exist for some values of its arguments. The comment made above concerning the utilitarian meaning of infinity in physical theory applies in this context, where properties of a sequence of integrals similar to (<a href="#eq-11">11</a>) with increasingly larger but finite upper limit can be investigated usefully. The upper limit of integration is therefore mentioned as an argument in (<a href="#eq-11">11</a>). Whenever the argument is not mentioned, it is implied to be infinity.</p>
<p>Transformation of the equations of continuity and momentum conservation in the two-fluid model of plasma into cylindrical Fourier space involves 115 instances of the 3B integral in 19 expressions similar to those described in equations (<a href="#eq-8">8</a>)-(<a href="#eq-10">10</a>) [<a href="#Ref-8">8</a>]. Investigations of plasma phenomena involving nonlinear interaction between solenoidal and irrotational fields, such as self-organization or turbulence in the two-fluid plasma model, would benefit considerably if an adequate approximation of the 3B integral becomes available. This is the motivation of the present work.</p>
<h3>Properties of the Triple-Bessel Integral</h3>
<p>The 3B integral is trivially invariant under permutation of pairs of arguments <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_22.gif" alt="" width="30" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_23.gif" alt="" width="36" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_24.gif" alt="" width="40" height="12" />. If the arguments <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_25.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_26.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_27.gif" alt="" width="11" height="12" /> are scaled as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_28.gif" alt="" width="34" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_29.gif" alt="" width="40" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_30.gif" alt="" width="46" height="14" />, then the integral scales as</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormula_1.gif" alt="" width="345" height="17" /></p>
<p>Since azimuthal mode numbers can be positive or negative integers or zero,</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormula_2.gif" alt="" width="369" height="15" /></p>
<p>reflecting the property of Bessel functions of integer orders: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_31.gif" alt="" width="101" height="12" />.</p>
<p>Using the known relations for Bessel functions</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_12.gif" alt="" width="382" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-12">(12)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_13.gif" alt="" width="198" height="38" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-13">(13)</a></td>
</tr>
</tbody>
</table>
<p>the following properties of the triple-Bessel integral can be derived as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32243" title="Auluck_DisplayFormulaNumbered_14" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_14.gif" alt="" width="303" height="65" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-14">(14)</a></td>
</tr>
</tbody>
</table>
<p>The 3B integral is thus the Hankel transform of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Image_3.gif" alt="" width="81" height="12" /> of order <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_32.gif" alt="" width="9" height="12" />, and its inverse Hankel transform is also seen to exist.</p>
<p>Relations (<a href="#eq-12">12</a>) and (<a href="#eq-13">13</a>) yield</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_15.gif" alt="" width="481" height="74" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-15">(15)</a></td>
</tr>
</tbody>
</table>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_33.gif" alt="" width="26" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_34.gif" alt="" width="69" height="15" />. If in addition <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_35.gif" alt="" width="40" height="12" />,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_16.gif" alt="" width="270" height="18" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-16">(16)</a></td>
</tr>
</tbody>
</table>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_36.gif" alt="" width="29" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_37.gif" alt="" width="40" height="12" />, the following result is known [<a href="#Ref-10">10</a>, p. 412] in terms of Legendre functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_38.gif" alt="" width="35" height="17" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_17.gif" alt="" width="482" height="141" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-17">(17)</a></td>
</tr>
</tbody>
</table>
<p>The following simpler case is also known, corresponding to the case <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_39.gif" alt="" width="26" height="12" />, equation 3 in Watson&#8217;s treatise [<a href="#Ref-10">10</a>, p. 411]:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_18.gif" alt="" width="394" height="55" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-18">(18)</a></td>
</tr>
</tbody>
</table>
<p>where <span><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Image_6.gif" alt="" width="302" height="23" /></span></p>
<p>Relations (<a href="#eq-15">15</a>)-(<a href="#eq-18">18</a>) point to the existence of singular behavior of the 3B integral at specific values of its arguments. While (<a href="#eq-17">17</a>) and (<a href="#eq-18">18</a>) are formulas for the 3B integrals in the sense of Riemann integrals, (<a href="#eq-15">15</a>) and (<a href="#eq-16">16</a>) refer to them in the sense of distributions.</p>
<h3>Approximation to the Triple-Bessel Integral</h3>
<p>This integral occurs as part of a kernel in an integral over the mode numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_40.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_41.gif" alt="" width="11" height="12" /> over the interval <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_42.gif" alt="" width="31" height="12" />, which itself is a term in a summation over azimuthal mode numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_43.gif" alt="" width="12" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_44.gif" alt="" width="14" height="12" /> (integers) from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_45.gif" alt="" width="19" height="12" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_46.gif" alt="" width="19" height="12" />. Although the exact evaluation of this integral in the sense of a Riemann integral is probably not possible [<a href="#Ref-9">9</a>], the existence of the singular behavior noted above suggests that its behavior in the neighborhood of singularities provides the dominant contribution. In view of known difficulties in the analytical approach [<a href="#Ref-10">10</a>] and the availability of the sophisticated numerical integrator in <em>Mathematica</em> 8.0.4, a semi-empirical approach [<a href="#Ref-11">11</a>] is chosen. The upper limit of integration is taken as a large but finite number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_47.gif" alt="" width="8" height="12" />, so that the required integral can be treated as the limit of a sequence for increasing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_48.gif" alt="" width="8" height="12" />.</p>
<p>For large values of argument, the Bessel function can be approximated as [<a href="#Ref-10">10</a>]:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_19.gif" alt="" width="233" height="51" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-19">(19)</a></td>
</tr>
</tbody>
</table>
<p>The scaling property of the 3B integral discussed above suggests that the radial mode numbers can always be scaled so that approximation (<a href="#eq-19">19</a>) becomes a good approximation in most of the infinite domain of integration (except perhaps in a small region around <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_49.gif" alt="" width="25" height="12" />). This yields</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32259" title="Auluck_DisplayFormulaNumbered_20" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_201.gif" alt="" width="445" height="322" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-20">(20)</a></td>
</tr>
</tbody>
</table>
<p>Each integral on the right-hand side of (<a href="#eq-21">21</a>) is of the form</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_21.gif" alt="" width="453" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-21">(21)</a></td>
</tr>
</tbody>
</table>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_50.gif" alt="" width="27" height="12" />,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_22.gif" alt="" width="231" height="17" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-22">(22)</a></td>
</tr>
</tbody>
</table>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_51.gif" alt="" width="27" height="12" />,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32244" title="Auluck_DisplayFormulaNumbered_23" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_23.gif" alt="" width="321" height="198" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-23">(23)</a></td>
</tr>
</tbody>
</table>
<p>The functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_52.gif" alt="" width="117" height="18" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_53.gif" alt="" width="114" height="18" /> are the Fresnel cosine and sine integrals. Applying (<a href="#eq-24">24</a>) to (<a href="#eq-21">21</a>),</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32245" title="Auluck_DisplayFormulaNumbered_24" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_24.gif" alt="" width="520" height="544" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-24">(24)</a></td>
</tr>
</tbody>
</table>
<p>This can be simplified as follows: When <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_54.gif" alt="" width="59" height="12" /> is an odd integer, the cosine term in the ratio</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormula_3.gif" alt="" width="239" height="51" /></p>
<p>is zero, so that the ratio is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_55.gif" alt="" width="15" height="12" />. Similarly, if this number is an even integer or zero, the sine term is zero, so that the ratio must be <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_56.gif" alt="" width="15" height="12" />. Hence this ratio can be represented as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_57.gif" alt="" width="65" height="15" />. Applying this logic to (<a href="#eq-25">25</a>),</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32246" title="Auluck_DisplayFormulaNumbered_25" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_25.gif" alt="" width="486" height="376" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-25">(25)</a></td>
</tr>
</tbody>
</table>
<p>Equation (<a href="#eq-25">25</a>) has the advantage that both its sides can be independently computed, and their numerical equivalence and computational time can be compared, particularly at the singular points. Each term in (<a href="#eq-25">25</a>) has a factor of the form</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_26.gif" alt="" width="365" height="56" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-26">(26)</a></td>
</tr>
</tbody>
</table>
<p>The functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_58.gif" alt="" width="30" height="12" />, which are mirror images of each other, are plotted in Figure 1 and some numerical values are shown in Table 1.</p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Output_1.gif" alt="" width="459" height="290" /></p>
<p class="NumberedFigureCaption"><strong>Figure 1.</strong> Plot of functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_59.gif" alt="" width="25" height="13" />.</p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Image_7.gif" alt="" width="400" height="196" /></p>
<div id="144881643" class="NumberedTableCaption"><a name="Table1"></a><a name="144881643"></a><strong>Table 1.</strong> Numerical values of functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_60.gif" alt="" width="25" height="13" />.</div>
<p>For a large but finite number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_61.gif" alt="" width="8" height="12" />, only one term out of four in (<a href="#eq-25">25</a>) dominates when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_62.gif" alt="" width="121" height="15" />, and then the integral has the value</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32247" title="Auluck_DisplayFormulaNumbered_27" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_27.gif" alt="" width="393" height="74" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-27">(27)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32248" title="Auluck_DisplayFormulaNumbered_28" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_28.gif" alt="" width="392" height="89" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-28">(28)</a></td>
</tr>
</tbody>
</table>
<p>The full width at half maximum (FWHM) of the peaks of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_63.gif" alt="" width="152" height="12" /> as a function of any one of the radial mode number arguments is seen to be <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_64.gif" alt="" width="38" height="15" />, irrespective of other arguments. The semi-empirical relations (<a href="#eq-27">27</a>) and (<a href="#eq-28">28</a>), based on a large but finite upper limit of integration, are numerically validated in the next section, showing that (<a href="#eq-20">20</a>) is a reasonably good approximation near the upper and lower singularities at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_65.gif" alt="" width="32" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_66.gif" alt="" width="38" height="12" />.</p>
<p>When <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_67.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_68.gif" alt="" width="11" height="12" /> are equal, the last two terms in (<a href="#eq-25">25</a>) become comparable, and (<a href="#eq-28">28</a>) breaks down. However, the question of how close <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_69.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_70.gif" alt="" width="11" height="12" /> can be before (<a href="#eq-28">28</a>) breaks down can form the basis of a numerical experiment. Set <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_71.gif" alt="" width="98" height="18" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_72.gif" alt="" width="6" height="12" /> is a sufficiently large positive number. Then (<a href="#eq-28">28</a>) takes the form</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_29.gif" alt="" width="504" height="69" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-29">(29)</a></td>
</tr>
</tbody>
</table>
<p>The ratio of the numerically evaluated LHS and RHS for randomly selected parameters can be plotted against <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_73.gif" alt="" width="55" height="12" /> by varying <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_74.gif" alt="" width="6" height="12" /> over many decades. This is considered in the next section. The value of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_75.gif" alt="" width="6" height="12" /> above which the formula breaks down is seen to be of the order of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_76.gif" alt="" width="22" height="15" />, <em>irrespective of the upper limit of integration</em>, which is varied over five decades. The numerical experiments show that (<a href="#eq-28">28</a>) remains valid for increasingly close values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_77.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_78.gif" alt="" width="11" height="12" /> as the limit of integration is increased.</p>
<p>The limit <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_79.gif" alt="" width="34" height="12" /> requires some care. It is seen from (<a href="#eq-27">27</a>) and (<a href="#eq-28">28</a>) that the maximum of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_80.gif" alt="" width="152" height="12" /> at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_81.gif" alt="" width="139" height="15" /> shifts to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_82.gif" alt="" width="84" height="12" /> and tends to infinity. At the same time, the FWHM of the peak tends to zero. The weighted area of the peak at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_83.gif" alt="" width="55" height="12" /><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/RightBracketingBar.gif" alt="" width="3" height="19" /> for a smooth weight function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_84.gif" alt="" width="24" height="12" /> is defined in terms of an arbitrarily small positive number <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_85.gif" alt="" width="6" height="12" /> and a function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_86.gif" alt="" width="20" height="12" /> where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_87.gif" alt="" width="75" height="12" /> as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32249" title="Auluck_DisplayFormulaNumbered_30" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_30.gif" alt="" width="308" height="101" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-30">(30)</a></td>
</tr>
</tbody>
</table>
<p>For smooth weight functions, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_88.gif" alt="" width="152" height="18" /> in the limit as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_89.gif" alt="" width="34" height="12" />, and the integral on the RHS of (<a href="#eq-29">29</a>) can be written as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_31.gif" alt="" width="514" height="78" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-31">(31)</a></td>
</tr>
</tbody>
</table>
<p>Observing that the integral <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_90.gif" alt="" width="63" height="18" /> does not converge, choose <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_91.gif" alt="" width="89" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_92.gif" alt="" width="86" height="18" /> in order to ensure convergence in the infinite limit of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_93.gif" alt="" width="8" height="12" />. The integral on the RHS of (<a href="#eq-30">30</a>) is then evaluated with infinite limits</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_32.gif" alt="" width="384" height="40" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-32">(32)</a></td>
</tr>
</tbody>
</table>
<p>The weighted area under the peak is therefore given by the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_94.gif" alt="" width="34" height="12" /> limit of (<a href="#eq-31">31</a>)</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32250" title="Auluck_DisplayFormulaNumbered_33" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_33.gif" alt="" width="357" height="90" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-33">(33)</a></td>
</tr>
</tbody>
</table>
<p>Similar logic can be applied to (<a href="#eq-28">28</a>) when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_95.gif" alt="" width="38" height="12" /> is treated as a fixed nonzero number</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32251" title="Auluck_DisplayFormulaNumbered_34" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_34.gif" alt="" width="386" height="106" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-34">(34)</a></td>
</tr>
</tbody>
</table>
<p>The region away from singularities does not need a finite upper limit of integration. For this case, a better approximation for the 3B integral can be constructed by applying (<a href="#eq-19">19</a>) to only two out of three Bessel functions:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32252" title="Auluck_DisplayFormulaNumbered_35" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_35.gif" alt="" width="509" height="143" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-35">(35)</a></td>
</tr>
</tbody>
</table>
<p>This can be computed by recognizing that (for positive <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_96.gif" alt="" width="9" height="12" />)</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_36.gif" alt="" width="514" height="65" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-36">(36)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_37.gif" alt="" width="511" height="65" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-37">(37)</a></td>
</tr>
</tbody>
</table>
<p>The Heaviside <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_97.gif" alt="" width="8" height="12" />-function in (<a href="#eq-36">36</a>) and (<a href="#eq-37">37</a>) excludes the singular points. Some general features of this approximate expression require attention. For all pairs of primed azimuthal mode numbers whose sum is even (or odd), the expression is unchanged. For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_98.gif" alt="" width="34" height="12" />, the third term in (<a href="#eq-35">35</a>) varies as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_99.gif" alt="" width="36" height="15" />, and the fourth term is zero. For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_100.gif" alt="" width="63" height="12" />, the expression oscillates rapidly as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_101.gif" alt="" width="132" height="18" /> and at the same time falls off in magnitude as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_102.gif" alt="" width="18" height="15" />. For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_103.gif" alt="" width="81" height="12" />, the last terms of (<a href="#eq-36">36</a>) and (<a href="#eq-37">37</a>) provide a sharp fall. Significant magnitude of the expression is thus expected only in the region satisfying the triangle inequality: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_104.gif" alt="" width="112" height="12" /> as in the analytical results (<a href="#eq-17">17</a>) and (<a href="#eq-18">18</a>).</p>
<p>A computational survey of the behavior of the above approximation to the 3B integral can be graphically presented in terms of scaled parameters <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_105.gif" alt="" width="52" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_106.gif" alt="" width="56" height="15" />, making use of the scaling relation mentioned above:</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormula_4.gif" alt="" width="339" height="17" /></p>
<p>This may be conveniently displayed in terms of the scaled <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_107.gif" alt="" width="6" height="14" />:</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormula_5.gif" alt="" width="192" height="16" /></p>
<p>This parameter is negative below the lower singularity and greater than 1 above the upper singularity.</p>
<p>This is considered in the next section.</p>
<h3>Numerical Exploration of the Triple-Bessel Integral</h3>
<p>Numerical exploration of the triple-Bessel integral, treated as a function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_108.gif" alt="" width="6" height="12" /> for given values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_109.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_110.gif" alt="" width="11" height="12" />, uses <em>Mathematica</em> 8.0.4, which implements sophisticated algorithms for numerical integration of highly oscillating functions with user-defined precision. Since the integral is expected to diverge at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_111.gif" alt="" width="58" height="12" />, the upper limit of numerical integration is kept at a high but finite number, which is also a parameter varied in the study.</p>
<p>Although the <tt>NIntegrate</tt> function in <em>Mathematica</em> is well tested, it is nevertheless prudent to benchmark it against the known result (<a href="#eq-18">18</a>) in order to confirm that its options and parameters are correctly chosen for the intended application. The result of benchmark calculations is displayed in Figure 2, which summarizes the results of thousands of calculations with randomly generated arguments satisfying the triangle inequality and located near the lower singularity, upper singularity, or between the singularities. It is seen that there is quite good, but not perfect, agreement between the numerically calculated result and the formula for the following options: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_112.gif" alt="" width="132" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_113.gif" alt="" width="117" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_114.gif" alt="" width="125" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_115.gif" alt="" width="146" height="12" />, which were chosen after a few trials.</p>
<p>Outside the triangle inequality region, <tt>NIntegrate</tt> gives very small values, consistent with the zero value from the analytical formula.</p>
<p>The upper limit of integration used in these calculations is symbolic <tt>Infinity</tt>, which is interpreted by <tt>NIntegrate</tt> as a large number that delivers the requested performance. The upper limit thus may not be the same in all calculations of the triple-Bessel integral. <em>Using arbitrary fixed large numbers for the upper limit, however, gives absurd results.</em></p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Output_2.gif" alt="" width="450" height="314" /></p>
<p class="NumberedFigureCaption"><strong>Figure 2.</strong> Result of 3600 calculations of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_116.gif" alt="" width="115" height="12" /> with randomly chosen <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_117.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_118.gif" alt="" width="10" height="12" /> in various decade ranges and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_119.gif" alt="" width="5" height="12" /> randomly chosen to lie in the region between <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_120.gif" alt="" width="32" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_121.gif" alt="" width="34" height="12" />.</p>
<p>Figures 3 and 4 show the detail of the variation (magnified <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_122.gif" alt="" width="18" height="15" /> times) of the triple-Bessel integral, treated as a function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_123.gif" alt="" width="6" height="12" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_124.gif" alt="" width="38" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_125.gif" alt="" width="40" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_126.gif" alt="" width="32" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_127.gif" alt="" width="34" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_128.gif" alt="" width="29" height="12" /> in the neighborhood of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_129.gif" alt="" width="40" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_130.gif" alt="" width="38" height="12" /> , with integration limit <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_131.gif" alt="" width="22" height="15" />. The relevant <em>Mathematica</em> code is shown in Appendix 2. Figure 3 took over six hours to generate on a Core-2 Duo, 2 GHz, 4 GB ram machine. The resemblance of the shape of the plot to the functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_132.gif" alt="" width="30" height="12" /> is evident. Note the glitches at values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_133.gif" alt="" width="6" height="12" /> away from the singularity, showing that the numerical integrator does not work well for some values of the parameters. Since <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_134.gif" alt="" width="52" height="12" />, the sign of the singularity in Figure 4 (time of computation: nearly nine hours) is negative for the given values of azimuthal mode numbers, as predicted by (<a href="#eq-29">29</a>).</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_6.gif" alt="" width="450" height="287" /></p>
<p class="NumberedFigureCaption"><strong>Figure 3. </strong><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_135.gif" alt="" width="16" height="13" /> magnification detail in the neighborhood of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_136.gif" alt="" width="34" height="12" />: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_137.gif" alt="" width="31" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_138.gif" alt="" width="33" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_139.gif" alt="" width="25" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_140.gif" alt="" width="27" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_141.gif" alt="" width="22" height="12" />. Time required: about 22000 seconds.</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_7.gif" alt="" width="450" height="283" /></p>
<p class="NumberedFigureCaption"><strong>Figure 4. </strong><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_142.gif" alt="" width="16" height="13" /> magnification detail in the neighborhood of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_143.gif" alt="" width="32" height="12" />: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_144.gif" alt="" width="31" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_145.gif" alt="" width="33" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_146.gif" alt="" width="25" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_147.gif" alt="" width="27" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_148.gif" alt="" width="22" height="12" />. Time required: about 31000 seconds.</p>
<p>A randomized parameter space survey of (<a href="#eq-27">27</a>) was carried out using the following protocol: 200 values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_149.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_150.gif" alt="" width="11" height="12" /> were chosen randomly in each of four decades from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_151.gif" alt="" width="24" height="15" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_152.gif" alt="" width="18" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_153.gif" alt="" width="6" height="12" /> was chosen randomly in the range <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_154.gif" alt="" width="21" height="12" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_155.gif" alt="" width="12" height="12" />, and integers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_156.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_157.gif" alt="" width="12" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_158.gif" alt="" width="14" height="12" /> were chosen randomly in the range 0 to 100. For each set of parameters, the result of numerical integration over the limit <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_159.gif" alt="" width="17" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_160.gif" alt="" width="5" height="12" /> in the range of 9-12, divided by the value calculated using (<a href="#eq-27">27</a>), was plotted against the latter. The result is summarized in Figure 5. A similar exercise for equation (<a href="#eq-28">28</a>) is summarized in Figure 6. The code used is described in Appendix 3. It is seen that a higher integration limit gives less deviation from the formula.</p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Output_3.gif" alt="" width="525" height="270" /></p>
<p class="NumberedFigureCaption"><strong>Figure 5. </strong>Randomized parameter space survey of formula (<a href="#eq-27">27</a>).</p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Output_4.gif" alt="" width="525" height="270" /></p>
<p class="NumberedFigureCaption"><strong>Figure 6. </strong>Randomized parameter space survey of formula (<a href="#eq-28">28</a>).</p>
<p>As discussed in the previous section, (<a href="#eq-28">28</a>) is expected to break down when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_161.gif" alt="" width="11" height="12" />and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_162.gif" alt="" width="11" height="12" /> are sufficiently close, since the assumption concerning domination of only one term of (<a href="#eq-25">25</a>) fails. This phenomenon is explored in the following test. (See Appendix 4).</p>
<p>The closeness of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_163.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_164.gif" alt="" width="11" height="12" /> is quantified in terms of a multiple <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_165.gif" alt="" width="6" height="12" /> of the parameter <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_166.gif" alt="" width="28" height="15" />, which scans the width of the peak by setting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_167.gif" alt="" width="98" height="18" />. For a set of randomly selected parameters <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_168.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_169.gif" alt="" width="12" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_170.gif" alt="" width="14" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_171.gif" alt="" width="9" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_172.gif" alt="" width="6" height="12" />, the ratio of values obtained from numerical integration and (<a href="#eq-28">28</a>) is plotted against <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_173.gif" alt="" width="6" height="12" />, which varies over 11 decades from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_174.gif" alt="" width="18" height="15" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_175.gif" alt="" width="22" height="15" />. This plot is generated for five values of upper integration limit <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_176.gif" alt="" width="22" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_177.gif" alt="" width="22" height="16" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_178.gif" alt="" width="22" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_179.gif" alt="" width="22" height="15" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_180.gif" alt="" width="22" height="15" /> for the same set of randomly selected parameters, This is repeated for many randomly selected sets of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_181.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_182.gif" alt="" width="12" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_183.gif" alt="" width="14" height="12" /> in the range 0 to 100, 50 random values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_184.gif" alt="" width="9" height="12" /> in each of four decades from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_185.gif" alt="" width="24" height="15" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_186.gif" alt="" width="18" height="15" />, and<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_187.gif" alt="" width="8" height="12" /> in the range <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_188.gif" alt="" width="21" height="12" /> to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_189.gif" alt="" width="15" height="12" /> The result is shown in Figure 7. The formula is seen to hold good when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_190.gif" alt="" width="6" height="12" /> is above <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_191.gif" alt="" width="22" height="15" />, <em>irrespective of the limit of integration</em>.</p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Output_5.gif" alt="" width="525" height="270" /></p>
<p class="NumberedFigureCaption"><strong>Figure 7. </strong>Randomized parameter space survey of formula (<a href="#eq-28">28</a>) with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_192.gif" alt="" width="83" height="16" />.</p>
<p>The same dataset is displayed as a function of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_193.gif" alt="" width="55" height="12" /> in Figure 8 for different values of the upper limit of integration.</p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Output_6.gif" alt="" width="515" height="406" /></p>
<p class="NumberedFigureCaption"><strong>Figure 8. </strong>Randomized parameter space survey of formula (<a href="#eq-28">28</a>) with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_194.gif" alt="" width="83" height="16" />. The agreement between numerical integration and formula becomes better at closer values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_195.gif" alt="" width="45" height="12" /> as the limit of integration is increased.</p>
<p>Formula (<a href="#eq-28">28</a>) is seen to be valid for increasingly smaller values of difference in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_196.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_197.gif" alt="" width="11" height="12" /> as the limit of integration is increased: less than a few parts per million when the integration limit is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_198.gif" alt="" width="22" height="15" />. For infinite limit of integration, the formula should therefore hold for arbitrarily close <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_199.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_200.gif" alt="" width="11" height="12" />.</p>
<p>The significance of numerical validation of (<a href="#eq-27">27</a>) and (<a href="#eq-28">28</a>) demonstrated above is that the dependence of the polarity of the peak on the three azimuthal mode numbers is correctly reproduced <em>without a single error in several thousand calculations</em> (where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_201.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_202.gif" alt="" width="11" height="12" /> differ more than a few parts per million), in addition to a reasonable agreement with peak amplitude and shape, for a large number of randomly selected parameters.</p>
<p>A similar exercise for the better approximation for regions away from singularities, formula (<a href="#eq-35">35</a>), gives a very different picture: the formula overestimates the numerically calculated integral by several orders of magnitude. In order to understand this, a randomized survey of the approximation (<a href="#eq-35">35</a>) and the numerical integration with upper limits <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_203.gif" alt="" width="22" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_204.gif" alt="" width="22" height="15" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_205.gif" alt="" width="22" height="15" /> was carried out and is summarized below. The program used in this survey is given in Appendix 5. The parameters used in the survey were: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_206.gif" alt="" width="132" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_207.gif" alt="" width="117" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_208.gif" alt="" width="125" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_209.gif" alt="" width="154" height="12" />. <tt>NIntegrate</tt> did not report any errors. Consistency of the trend in the survey suggests that the 3B integral tends to zero for the infinite upper limit of integration when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_210.gif" alt="" width="58" height="12" />: a (tentative) conclusion, which is predicated on the assumption that <tt>NIntegrate</tt> works correctly in these kinds of calculations. That can, in principle, be further examined by repeating this test for a much larger number of calculations and many different sets of options.</p>
<p>Using symbolic <tt>Infinity</tt> for the upper limit in these calculations is found to give absurd results. There is thus a distinct possibility that <tt>NIntegrate</tt> sometimes behaves in an anomalous manner while calculating the triple-Bessel integral.</p>
<p class="output"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Output_7.gif" alt="" width="525" height="250" /></p>
<p class="NumberedFigureCaption"><strong>Figure 9. </strong>Randomized survey of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_211.gif" alt="" width="126" height="17" /> as functions of scaled <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_212.gif" alt="" width="5" height="12" />, which are <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_213.gif" alt="" width="156" height="14" /> for various upper limits compared with (<a href="#eq-35">35</a>).</p>
<p>The reasonable degree of agreement between the results of three theoretical formulas ((<a href="#eq-18">18</a>), (<a href="#eq-27">27</a>), and (<a href="#eq-28">28</a>)) and numerical integration (with symbolic <tt>Infinity</tt> as the upper limit for (<a href="#eq-18">18</a>) and a large number as the upper limit in (<a href="#eq-27">27</a>) and (<a href="#eq-28">28</a>)), with randomly selected parameters, tends to establish the credibility of numerical integration. At the same time, the fact that absurd results are produced by using a large number as the upper limit in the test for (<a href="#eq-18">18</a>) and symbolic <tt>Infinity</tt> as the upper limit in the above test suggests that there is scope for improvement in the implementation of <tt>NIntegrate</tt>.</p>
<h3>Proposed Approximate Formula for the Triple-Bessel Integral</h3>
<p>The above discussion and numerical experimentation lead to the following observations, subject to the caveat concerning the correct behavior of <tt>NIntegrate</tt>:</p>
<ol class="ItemNumbered">
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_214.gif" alt="" width="154" height="12" /> tends to infinity as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_215.gif" alt="" width="60" height="12" />.</li>
<li>The FWHM of the peak of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_216.gif" alt="" width="152" height="12" /> at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_217.gif" alt="" width="58" height="12" /> tends to zero as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_218.gif" alt="" width="34" height="12" />.</li>
<li>The weighted integrals (<a href="#eq-32">32</a>) and (<a href="#eq-33">33</a>) over this peak converge to finite values for smooth weight functions.</li>
<li>Both outside and within the triangle inequality region <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_219.gif" alt="" width="112" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_220.gif" alt="" width="154" height="12" /> is negligibly small.</li>
</ol>
<p>These observations suggest the following approximate semi-empirical representation of the 3B integral in the sense of distribution with respect to <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Gamma.gif" alt="" width="6" height="19" /> for smooth weight functions:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_38.gif" alt="" width="446" height="157" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-38">(38)</a></td>
</tr>
</tbody>
</table>
<p>Here, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_221.gif" alt="" width="44" height="12" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_222.gif" alt="" width="26" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_223.gif" alt="" width="44" height="12" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_224.gif" alt="" width="26" height="12" />. Note the inclusion of the case <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_225.gif" alt="" width="34" height="12" />: this is proposed as the generalization of the results displayed in Figure 8 to the infinite integration limit. Putting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_226.gif" alt="" width="26" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_227.gif" alt="" width="29" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_228.gif" alt="" width="40" height="12" /> in (<a href="#eq-38">38</a>) recovers the usual orthogonality formula (<a href="#eq-12">12</a>) for Bessel functions, supporting the discussion concerning equation (<a href="#eq-33">33</a>) and also the inclusion of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_229.gif" alt="" width="34" height="12" /> case.</p>
<p><em>Its only claim to merit is that it is a less restrictive approximation than the total neglect of irrotational and scalar fields in spatial-spectral treatments of nonlinear dynamics of continuous media</em>. Adoption of (<a href="#eq-38">38</a>) as a kind of tentative semi-empirical model for the triple-Bessel integral, at least until a better replacement becomes available, would enable construction of a theoretical framework for studying effects arising out of the nonlinear interaction of solenoidal and irrotational electron modes in the two-fluid plasma model in cylindrical geometry [<a href="#Ref-6">6</a>], which is currently an intractable problem. This framework can be improved if and when further research, hopefully motivated by this discussion, leads to a better representation of (<a href="#eq-38">38</a>).</p>
<h3>Discussion</h3>
<p>The insight gained above about the properties and numerical behavior of the 3B integral has significant implications concerning the usefulness of the Fourier space representation of nonlinear dynamics of continuous media in cylindrical geometry. The question, how far is infinity?, in the context of a physical theory, is seen to have an answer in terms of the error with which a physical quantity, such as radial mode number, might be defined using an experimental procedure. Two radial mode numbers may then be considered equivalent if their difference lies within the error band. The reciprocal of this error band would then represent the order of magnitude of the limit of integration in coordinate space, which reproduces, within experimental errors, the result that nonlinear interaction of these modes generates a near-zero radial-mode-number mode.</p>
<p>The origin of the singularities in this integral, treated as a function of three radial and three azimuthal mode numbers, can be seen from (<a href="#eq-20">20</a>) to lie in resonant interaction between three waves of radial mode numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_231.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_232.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_233.gif" alt="" width="11" height="12" />, having phases governed by the azimuthal mode numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_234.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_235.gif" alt="" width="12" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_236.gif" alt="" width="14" height="12" />, when any radial mode number equals the sum or difference of the other two radial mode numbers.</p>
<p>The triple-Bessel integral occurs in expressions that describe how the rate of change of the spectrum of a given quantity (the evolving mode), labeled by mode numbers <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_237.gif" alt="" width="54" height="12" /> without primes, depends on the interaction between the spectra of two other quantities, labeled by primed mode numbers (the interacting modes) and is accompanied by the factor <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_238.gif" alt="" width="40" height="15" />. The semi-empirical model (<a href="#eq-38">38</a>) then takes on a much simpler form, expressed below as a distribution with respect to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_239.gif" alt="" width="11" height="12" /> using the invariance with respect to a permutation of pairs of arguments <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_240.gif" alt="" width="30" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_241.gif" alt="" width="36" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_242.gif" alt="" width="40" height="12" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32254" title="Auluck_DisplayFormulaNumbered_39" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_39.gif" alt="" width="481" height="59" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-39">(39)</a></td>
</tr>
</tbody>
</table>
<p>According to the model formula (<a href="#eq-40">40</a>), the contribution of the 3B integral to the evolution of the spectrum is governed by two singularities. One evolves the spectrum toward higher radial mode numbers than the radial mode numbers of interacting quantities, generating smaller radial scale lengths and steeper gradients as in shock formation or turbulence. The other evolves the spectrum toward radial scale lengths larger than the radial scale lengths of the interacting modes, indicating the formation of a larger structure, as in self-organization. The tendencies toward turbulence/shock formation or self-organization are influenced by azimuthal mode numbers.</p>
<p>The computational advantage of the semi-empirical model of the 3B integral presented above can be judged by comparison with the approach of Chen, Shan, and Montgomery (CSM) [<a href="#Ref-4">4</a>, <a href="#Ref-5">5</a>]. The first advantage over the method of CSM is that the spatial-spectral representation of irrotational vector fields as well as scalar fields becomes possible in addition to solenoidal fields: while the CSM method is limited to solenoidal fields only, over the infinite domain, an orthogonal basis becomes simultaneously available for scalar, irrotational, and solenoidal fields, facilitating the investigation of effects due to their nonlinear interaction [<a href="#Ref-6">6</a>]. The second advantage is that rather than computing a table of numerical values of coupling coefficients for an infinity (or a suitably large number) of azimuthal mode numbers, the dependence on azimuthal mode numbers is reduced to a simple computation of sign of a term. The semi-empirical formula (<a href="#eq-40">40</a>) takes on the role of the table of coupling coefficients in the Galerkin approach of CSM [<a href="#Ref-4">4</a>, <a href="#Ref-5">5</a>].</p>
<p>The spatial-spectral representation of the equation of continuity then becomes</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-32255" title="Auluck_DisplayFormulaNumbered_40" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormulaNumbered_40.gif" alt="" width="485" height="228" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="eq-40">(40)</a></td>
</tr>
</tbody>
</table>
<p>The third advantage is the significant reduction in the computational complexity of equation (<a href="#eq-7">7</a>) noticed in its reduced form (<a href="#eq-40">40</a>): reduction in the number of integrations, simpler dependence on azimuthal mode numbers, and simpler form of the coupling factors. This opens up the possibility of doing computations similar to those of CSM without the restriction to incompressible flow and with a much larger number of modes.</p>
<h3>Summary and Conclusion</h3>
<p>This article concerns the integral of the product of three Bessel functions of the first kind of integer orders over the semi-infinite domain <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_243.gif" alt="" width="31" height="12" />, which is encountered when transforming a system of nonlinear partial differential equations containing solenoidal vector fields, scalar fields, and irrotational vector fields, using Chandrasekhar-Kendall functions, their generating function, and its gradient as orthogonal bases over the semi-infinite domain. Known properties of this integral, which show singular behavior, are summarized. Using the approximation of Bessel functions for large arguments, it is shown that the triple-Bessel integral represents resonant three-wave interaction that leads to singularities when one argument equals the sum or difference of the other two arguments. Numerical investigations using <em>Mathematica</em> have been used to validate a scaling formula for the polarity, absolute magnitude, and shape of the singular peak with a large finite upper limit of integration. A semi-empirical approximate formula of the integral has been suggested in terms of the Dirac delta function for regions near the singularities for smooth weight functions. It is shown that the computational complexity of a cylindrical Fourier-space representation of the equation of continuity is reduced considerably using this formulation. This opens up the possibility of computational efforts similar to those of CSM without restriction to incompressible dynamics for a much larger number of modes.</p>
<h3>Appendix 1</h3>
<p>This generates Figure 2.</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_8.gif" alt="" width="580" height="683" /></p>
<h3>Appendix 2</h3>
<p>This generates Figures 3 and 4.</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_9.gif" alt="" width="580" height="247" /></p>
<h3>Appendix 3</h3>
<p>This generates Figure 5.</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_10.gif" alt="" width="580" height="601" /></p>
<p>This generates Figure 6.</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_11.gif" alt="" width="580" height="721" /></p>
<h3>Appendix 4</h3>
<p>This generates Figures 7 and 8.</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_12.gif" alt="" width="580" height="1062" /></p>
<h3>Appendix 5</h3>
<p>This generates Figure 9.</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Input_13.gif" alt="" width="580" height="820" /></p>
<h3>Appendix 6</h3>
<p>The following outlines an argument in support of the assumption that the 3B integral is zero outside the triangle inequality region. Using the integral representation of the Bessel function</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormula_14.gif" alt="" width="231" height="33" /></p>
<p>the 3B integral can be written as</p>
<p class="input"><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_DisplayFormula_15.gif" alt="" width="580" height="120" /></p>
<p>The integral would be zero if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/12/Auluck_Math_244.gif" alt="" width="133" height="12" /> has no zeros. This would correspond to the region outside the triangle inequality.</p>
<h3>Acknowledgments</h3>
<p>This article owes its origin to the following insightful question from an anonymous referee of <em>Physics of Plasmas</em>: &#8220;How far is infinity?&#8221; The help given by William Rummler of Wolfram Technical Support is gratefully acknowledged.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Ref-1">[1] </a></td>
<td>S. Chandrasekhar and P. C. Kendall, &#8220;On Force-Free Magnetic Fields,&#8221; <em>Astrophysical Journal</em>, <strong>126</strong>, 1957 pp. 457-460. <a href="http://dx.doi.org/10.1086/146413" target="blank">doi:10.1086/146413</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-2">[2] </a></td>
<td>Z. Yoshida, &#8220;Eigenfunction Expansions Associated with the Curl Derivatives in Cylindrical Geometries: Completeness of Chandrasekhar-Kendall Eigenfunctions,&#8221; <em>Journal of Mathematical Physics</em>, <strong>33</strong>(4), 1992 pp. 1252-1256. <a href="http://dx.doi.org/10.1063/1.529703" target="blank">doi:10.1063/1.529703</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-3">[3] </a></td>
<td>D. Montgomery, L. Turner, and G. Vahala, &#8220;Three Dimensional Magnetohydrodynamic Turbulence in Cylindrical Geometry,&#8221;<em> Physics of Fluids</em>, <strong>21</strong>(5), 1978 pp. 757-764. <a href="http://dx.doi.org/10.1063/1.862295" target="blank">doi:10.1063/1.862295</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-4">[4] </a></td>
<td>H. Chen, X. Shan, and D. Montgomery, &#8220;Galerkin Approximations for Dissipative Magnetohydrodynamics,&#8221; <em>Physical Review A</em>, <strong>42</strong>(10), 1990 pp. 6158-6165. <a href="http://dx.doi.org/10.1103/PhysRevA.42.6158" target="blank">doi:10.1103/PhysRevA.42.6158</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-5">[5] </a></td>
<td>X. Shan, D. Montgomery, and H. Chen, &#8220;Nonlinear Magnetohydrodynamics by Galerkin-Method Computation,&#8221; <em>Physical Review A</em>, <strong>44</strong>(10), 1991 pp. 6800-6818. <a href="http://dx.doi.org/10.1103/PhysRevA.44.6800" target="blank">doi:10.1103/PhysRevA.44.6800</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-6">[6] </a></td>
<td>S. K. H. Auluck, &#8220;Role of Electron-Inertia-Linked Current Source Terms in the Physics of Cylindrically Symmetric Imploding Snowplow Shocks,&#8221; <em>Physics of Plasma</em>, <strong>9</strong>(11), 2002<br /> pp. 4488-4494. <a href="http://dx.doi.org/10.1063/1.1508775" target="blank">doi:10.1063/1.1508775</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-7">[7] </a></td>
<td>P. M. Morse and H. Feshbach, <em>Methods of Theoretical Physics, Part I</em>, New York: McGraw-Hill, 1953 p. 3.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-8">[8] </a></td>
<td>S. K. H. Auluck, &#8220;Coherent Effects in the Stochastic Electrodynamics of Two-Fluid Plasma.&#8221; <a href="http://arxiv.org/abs/1208.1573" target="blank">arxiv.org/abs/1208.1573</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-9">[9] </a></td>
<td>G. N. Watson, &#8220;An Infinite Integral Involving Bessel Functions,&#8221; <em>Journal of the London Mathematical Society</em>, <strong>s1-9</strong>(1), 1934 pp. 16-22.<br /><a href="http://jlms.oxfordjournals.org/content/s1-9/1/16.extract" target="blank">jlms.oxfordjournals.org/content/s1-9/1/16.extract</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-10">[10] </a></td>
<td>G. N. Watson, <em>A Treatise on the Theory of Bessel Functions</em>, 2nd ed., London: Cambridge University Press, 1944.</td>
</tr>
<tr>
<td class="Reference"><a name="Ref-11">[11] </a></td>
<td>D. H. Bailey, J. M. Borwein, N. J. Calkin, R. Girgensohn, D. R. Luke, and V. H. Moll, <em>Experimental Mathematics in Action</em>, Wellesley, MA: <span style="font-family: sans-serif;">A. K. Peters,</span> 2007.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">S. K. H. Auluck, &#8220;On the Integral of the Product of Three Bessel Functions over an Infinite Domain,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-15.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">The author holds the designation Outstanding Scientist in the Physics Group at Bhabha Atomic Research Centre, Mumbai, India and is a professor at the Homi Bhabha National Institute, Mumbai, a deemed university. He is the representative of India on the International Scientific Committee for Dense Magnetised Plasmas (ISC-DMP), which oversees the scientific programs of the International Center for Dense Magnetised Plasmas established at Warsaw under an agreement between UNESCO and the Polish National Atomic Energy Agency in 1999.</p>
<p class="TextAboutAuthor"><strong>S. K. H. Auluck</strong><br />
<em>Physics Group<br />
Bhabha Atomic Research Centre<br />
Mumbai 400085, India<br />
</em><em><a href="mailto:skhauluck@gmail.com">skhauluck@gmail.com</a></em><em><br />
</em><em><a href="mailto:skauluck@barc.gov.in">skauluck@barc.gov.in</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/12/on-the-integral-of-the-product-of-three-bessel-functions-over-an-infinite-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clusters Produced by Placing Rhombic Triacontahedra at the Vertices of Polyhedra</title>
		<link>http://www.mathematica-journal.com/2012/09/clusters-produced-by-placing-rhombic-triacontahedra-at-the-vertices-of-polyhedra/</link>
		<comments>http://www.mathematica-journal.com/2012/09/clusters-produced-by-placing-rhombic-triacontahedra-at-the-vertices-of-polyhedra/#comments</comments>
		<pubDate>Tue, 11 Sep 2012 16:18:36 +0000</pubDate>
		<dc:creator>Sándor Kabai</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=30028</guid>
		<description><![CDATA[In this article we explore possible clusters of rhombic triacontahedra (RTs), usually by connecting them face to face, which happens when they are placed at the vertices of certain polyhedra. The edge length of such polyhedra is set to be twice the distance of a face of an RT from the origin (about 2.7527). The [...]]]></description>
			<content:encoded><![CDATA[<p>In this article we explore possible clusters of rhombic triacontahedra (RTs), usually by connecting them face to face, which happens when they are placed at the vertices of certain polyhedra. The edge length of such polyhedra is set to be twice the distance of a face of an RT from the origin (about 2.7527). The clusters thus produced can be used to build further clusters using an RT and a rhombic hexecontahedron (RH), the logo of Wolfram|Alpha. We briefly look at other kinds of connections and produce new clusters from old by using matching polyhedra instead of RTs.<span id="more-30028"></span></p>
<h3>Rhombic Triacontahedra (RT) and Rhombic Hexecontahedron (RH)</h3>
<p>Here are the RT and RH.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_1.gif" alt="" width="384" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_1.gif" alt="" width="360" height="414" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_2.gif" alt="" width="200" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_2.gif" alt="" width="360" height="361" /></p>
<p>To find the possible candidate polyhedra, let us summarize the angles of face centers relative to the center of a single face of RT, as seen from the origin.</p>
<p><img style="vertical-align: middle;" title="face radians degrees; 1 0 0 degrees; 1 pi 180 degrees; 4 pi/2 90 degrees; 4 pi/5 36 degrees; 4 2pi/5 72 degrees; 4 3pi/5 108 degrees; 4 4pi/5 154 degrees; 4 pi/3 60 degrees; 4 2pi/3 120 degrees" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Image_1.gif" alt="face radians degrees; 1 0 0 degrees; 1 pi 180 degrees; 4 pi/2 90 degrees; 4 pi/5 36 degrees; 4 2pi/5 72 degrees; 4 3pi/5 108 degrees; 4 4pi/5 154 degrees; 4 pi/3 60 degrees; 4 2pi/3 120 degrees" width="115" height="165" /></p>
<p>The dimensions applicable in the clusters can be determined on the basis of the relationship of the cube and RT. For instance, the cube edge is equal to the longer diagonal of the face of the RT (a golden rhombus), <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_1.gif" alt="" width="147" height="12" />. The diagonal of the cube equals the distance between opposite threefold vertices of the RT.</p>
<p>Additional information for finding possible candidate polyhedra comes from a chart of truncations prepared by Szaniszló Bérczi. Figure 1 shows regular (Platonic) solids projected on a sphere. Archimedean solids are deduced from the regular solids by the truncation operation. A Platonic or Archimedean solid can be identified by its vertex configuration, because it is uniform; this is given by the Steiner symbol, which lists the faces that meet at a vertex. For example, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_2.gif" alt="" width="40" height="12" /> is the Steiner symbol for the cube, because three squares (4-sided faces) meet at each vertex. The RT-related structures should be arranged according to the third row of the table: <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_3.gif" alt="" width="40" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_4.gif" alt="" width="53" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_5.gif" alt="" width="52" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_6.gif" alt="" width="40" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_7.gif" alt="" width="53" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Math_8.gif" alt="" width="46" height="12" />.</p>
<p><a href="http://www.mathematica-journal.com/data/uploads/2012/09/KabaiFigure1.gif"><img class="alignnone size-full wp-image-30471" title="KabaiFigure1" src="http://www.mathematica-journal.com/data/uploads/2012/09/KabaiFigure1.gif" alt="" /></a></p>
<p class="NumberedFigureCaption"><strong>Figure 1.</strong> The periodic table of Platonic and Archimedean solids and tessellations supplemented by the sequence of one of the infinite numbers of two-dimensional hyperbolic tessellations. In order to emerge, the regular solids are given in their projected-onto-sphere form.</p>
<p>For more help, we can consider the relationship of RT to cube and to RH, on the basis of which all necessary dimensions can be calculated.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_3.gif" alt="" width="134" height="58" /></p>
<p>This is the length of the cube edge.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_4.gif" alt="" width="103" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_3.gif" alt="" width="43" height="12" /></p>
<p>This is the length of the cube diagonal, which is equal to the length of the threefold axis diagonal of the RT.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_5.gif" alt="" width="99" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_4.gif" alt="" width="50" height="12" /></p>
<p>This is the face distance of the RT.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_6.gif" alt="" width="53" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_5.gif" alt="" width="50" height="12" /></p>
<p>This is the length of the fivefold axis diagonal of the RT.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_7.gif" alt="" width="145" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_6.gif" alt="" width="50" height="12" /></p>
<p>The relationship of the RT, cube, and a golden rectangle can be used to determine dimensions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_8.gif" alt="" width="580" height="118" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_7.gif" alt="" width="360" height="360" /></p>
<p>The relationship of the RT, RH, and a plane perpendicular to the threefold axis that cuts the RT and RH in half can be used to determine the angles between the RT faces.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_9.gif" alt="" width="580" height="133" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_8.gif" alt="" width="360" height="360" /></p>
<p>Here are the definitions used in the constructions.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_10.gif" alt="" width="413" height="163" /></p>
<h3>Icosahedron (ICO)</h3>
<p>The icosahedron (ICO) is one of the five Platonic solids.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_11.gif" alt="" width="208" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_9.gif" alt="" width="360" height="414" /></p>
<p>Twelve RTs placed at the vertices of the icosahedron enclose an RH. Such RT clusters appear in photos of certain quasicrystals.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_12.gif" alt="" width="580" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_10.gif" alt="" width="360" height="360" /></p>
<p>Here is a cluster of 12 RHs without transparency.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_13.gif" alt="" width="571" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_11.gif" alt="" width="360" height="360" /></p>
<p>When dodecahedra are used instead of RTs, they are attached to each other along their edges.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_14.gif" alt="" width="545" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_12.gif" alt="" width="360" height="360" /></p>
<h3>Truncated Icosahedron (TICO) (5, 6, 6)</h3>
<p>The truncated icosahedron (TICO) is the shape most widely used for a soccer ball. It is also the overall structure of the C60 molecule, Buckminsterfullerene.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_15.gif" alt="" width="580" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_13.gif" alt="" width="360" height="360" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_16.gif" alt="" width="580" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_14.gif" alt="" width="360" height="360" /></p>
<p>Here ICOs replace RTs; the ICOs meet along their edges.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_17.gif" alt="" width="580" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_15.gif" alt="" width="360" height="360" /></p>
<h3><span class="Section">Icosidodecahedron (ID) (3, 5, 3, 5)</span></h3>
<p>The icosidodecahedron (ID) can be constructed as a truncation of either an icosahedron or a dodecahedron.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_18.gif" alt="" width="200" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_16.gif" alt="" width="360" height="376" /></p>
<p>Here is the corresponding cluster.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_19.gif" alt="" width="520" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_17.gif" alt="" width="360" height="360" /></p>
<p>Let us add 12 RTs at the vertices of the ICO.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_20.gif" alt="" width="546" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_18.gif" alt="" width="360" height="360" /></p>
<p>Now add 12 RHs at the vertices of the DOD.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_21.gif" alt="" width="580" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_19.gif" alt="" width="360" height="360" /></p>
<p>Add some more RTs at the vertices of an ID. This construction can be continued by adding more RTs and RHs.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_22.gif" alt="" width="580" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_20.gif" alt="" width="360" height="360" /></p>
<h3><span class="Section">Truncated Dodecahedron (TD) (3, 10, 10)</span></h3>
<p>This is a special case of dodecahedron truncation, when the edge length is uniform.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_23.gif" alt="" width="200" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_21.gif" alt="" width="360" height="368" /></p>
<p>This cluster of 60 RTs can be interpreted as being assembled from 20 sets of three RTs.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_24.gif" alt="" width="556" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_22.gif" alt="" width="360" height="360" /></p>
<h3><span class="Section">Dodecahedron (DOD) (5, 5, 5)</span></h3>
<p>The usual pentagonal dodecahedron is one of the five Platonic solids.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_25.gif" alt="" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_23.gif" alt="" width="360" height="361" /></p>
<p>Here is its associated cluster.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_26.gif" alt="" width="580" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_24.gif" alt="" width="360" height="360" /></p>
<p>This investigates how the basic polyhedron relates to its associated cluster.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_27.gif" alt="" width="580" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_25.gif" alt="" /></p>
<p>The cluster of 20 RTs can be fitted with 12 RHs placed at the vertices of an ICO.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_28.gif" alt="" width="558" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_26.gif" alt="" width="360" height="360" /></p>
<h3>Great Rhombicosidodecahedron (GRID) (4, 6, 10)</h3>
<p>This is a beautiful shape. Somewhat similar shapes can be seen in some photographs of quasicrystals.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_29.gif" alt="" width="553" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_27.gif" alt="" width="360" height="360" /></p>
<p>Here is its associated cluster.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_30.gif" alt="" width="580" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_28.gif" alt="" width="360" height="360" /></p>
<h3>Small Rhombicosidodecahedron (SRID) (3, 4, 5, 4)</h3>
<p>An SRID has 60 vertices. In the related cluster, each RT is connected to four adjacent RTs, as opposed to the TICO-based cluster, where each RT is connected to only three adjacent RTs.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_31.gif" alt="" width="553" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_29.gif" alt="" width="360" height="360" /></p>
<p>Here is its associated cluster.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_32.gif" alt="" width="580" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_30.gif" alt="" width="360" height="360" /></p>
<p>This cluster can also be extended by adding RHs, for example at the vertices of an ICO.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_33.gif" alt="" width="580" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_31.gif" alt="" width="360" height="360" /></p>
<h3>Summary of Truncations and Their Clusters</h3>
<p>Here is a summary of the clusters that correspond to the various truncations.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_34.gif" alt="" width="458" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_32.gif" alt="" width="400" height="232" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_35.gif" alt="" width="472" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_33.gif" alt="" width="400" height="219" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_36.gif" alt="" width="443" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_34.gif" alt="" width="400" height="215" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_37.gif" alt="" width="443" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_35.gif" alt="" width="400" height="210" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_38.gif" alt="" width="458" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_36.gif" alt="" width="400" height="210" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_39.gif" alt="" width="472" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_37.gif" alt="" width="400" height="219" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_40.gif" alt="" width="472" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_38.gif" alt="" width="400" height="219" /></p>
<h3>Cube (4, 4, 4)</h3>
<p>The cube is one of the five Platonic solids.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_41.gif" alt="" width="546" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_39.gif" alt="" width="360" height="360" /></p>
<p>Here is its associated cluster.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_42.gif" alt="" width="571" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_40.gif" alt="" width="360" height="360" /></p>
<h3>Two Johnson Solids</h3>
<p>A number of Johnson solids can be considered as parts of the above polyhedra. The two shown here could be used as structures.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_43.gif" alt="" width="429" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_41.gif" alt="" width="360" height="284" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_44.gif" alt="" width="208" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_42.gif" alt="" width="360" height="391" /></p>
<p>Here are their clusters.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_45.gif" alt="" width="563" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_43.gif" alt="" width="360" height="360" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_46.gif" alt="" width="563" height="58" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_44.gif" alt="" width="360" height="360" /></p>
<h3>Connections with Vertices</h3>
<p>Interesting clusters can also be produced when the RTs meet at their vertices. For instance, RTs at RT vertices meet with their fivefold tips.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_47.gif" alt="" width="580" height="73" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_45.gif" alt="" width="360" height="360" /></p>
<p>RTs at the vertices of a rhombic dodecahedron (RD) meet with their threefold tips. Adjacent pairs of RTs overlap in a flat golden rhombohedron, creating another closed structure.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Input_48.gif" alt="" width="580" height="223" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/09/Kabai_Output_46.gif" alt="" /></p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Bérczi">[1] </a></td>
<td>Sz. Bérczi, “From the Periodic System of Platonic and Archimedean Solids and Tessellations to the 4D Regular Polyhedra and Tessellations (with Extensions to Some 5D Polytopes),” <span><em>Symmetry: Culture and Science</em></span>, <span><strong>11</strong></span>(1–4), 2003 pp. 125–137.</td>
</tr>
<tr>
<td class="Reference"><a name="Kabai">[2] </a></td>
<td>S. Kabai. “21609 Clusters of Polyhedra” from the Wolfram Demonstrations Project—A Wolfram Web Resource. <span><a href="http://demonstrations.wolfram.com/21609ClustersOfPolyhedra/"><span class="HyperlinkInline">www.demonstrations.wolfram.com/21609ClustersOfPolyhedra</span></a></span>.</td>
</tr>
<tr>
<td class="Reference"><a name="Gévay">[3] </a></td>
<td>G. Gévay, “Icosahedral Morphology,” <span><em>Fivefold Symmetry</em> </span>(I. Hargitai, ed.), Singapore: World Scientific, 1992.</td>
</tr>
<tr></tr>
</tbody>
</table>
<p class="DOIReference1">S. Kabai, Sz. Bérczi, and L. Szilassi, “Some Clusters Produced by Placing Rhombic Triacontahedra at the Vertices of Polyhedra,” <span><em>The Mathematica Journal</em></span>, 2012. dx.doi.org/doi:10.3888/tmj.14-14.</p>
<h4>Image Reference:</h4>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference">1.</td>
<td>Sz. Bérczi, “A szabályos és féligszabályos (platoni és archimedészi) testek és mozaikok periódusos rendszere,” <span><em>Középiskolai Matematikai Lapok</em></span>, <span><strong>59</strong></span>(5), 1979 pp. 193–199.</td>
</tr>
<tr></tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Authors</h3>
<p class="TextAboutAuthor">Sándor Kabai is a retired engineer who received his B.Sc. in manufacturing technology from Bánki College in Hungary in 1970. He has written many Demonstrations for the Wolfram Demonstrations Project; see <a href="http://demonstrations.wolfram.com/search.html?query=kabai">demonstrations</a>. He consults in space research-related education in Hungary.</p>
<p class="TextAboutAuthor">Szaniszló Bérczi received his M.Sc. in physics and astronomy at Eötvös Loránd University in 1974 and his Ph.D. in geology (planetary science) at the Hungarian Academy of Science in 1994. He has achievements in several fields of science. He made a new synthesis of the evolution of matter according to the material hierarchy versus great structure building periods. This model is a part of his Lecture Note Series at Eötvös Loránd University. He also organized a research group on the evolution of matter within the Geonomy Scientific Committee of the Hungarian Academy of Science (with Béla Lukács). He wrote the first book in Hungary about planetary science, <em>From Crystals to Planetary Bodies</em> (in Hungarian). At Eötvös Loránd University, he initiated and built (with colleagues) the Hungarian University Surveyor (Hunveyor) experimental space probe model and the Husar rover (Hungarian University Surface Analysis Rover) for training teachers, and developed new technologies for measurement. He wrote the first lecture note book in Hungarian on symmetry and structure building, which uses symmetry principles in forming cellular automata models. He organized the loan of NASA lunar samples from Houston JSC and NIPR Antarctic meteorites from the Tokyo Antarctic Meteorite Center to Eötvös Loránd University, and initiated planetary materials studies and comparisons on industrial materials and technologies. His booklet series on ancient Eurasian art surveys both figurative and ornamental arts of great Eurasian regions. His studies on ethnomathematics cover ancient Eurasian cultures.</p>
<p class="TextAboutAuthor">Lajos Szilassi received an M.Sc. in constructive geometry from the University of Szeged, Hungary in 1966, and a Ph.D. in 2006. He is now an emeritus professor at the University of Szeged. His main teaching areas include geometry, elementary mathematics, and computer applications. His research fields are in computer-aided solutions of mathematical and geometrical problems, with visualization of the solutions. In 1977 he found a way to construct a toroidal heptahedron, which is known now as the Szilassi polyhedron.</p>
<p class="TextAboutAuthor"><strong>Sándor Kabai<br />
</strong><em>1203 Budapest<br />
Határ 9<br />
Hungary</em><br />
<a href="http://www.kabai.hu" target="blank">www.kabai.hu</a><br />
<em><a href="mailto:unico@t-online.hu">unico@t-online.hu</a></em></p>
<p class="TextAboutAuthor"><strong>Szaniszló Bérczi</strong><strong><br />
</strong><em>Eötvös Loránd University, Faculty of Science<br />
Institute of Physics, Dept. Materials Physics<br />
Pázmány Péter sétány 1/a. H-1117<br />
Budapest, Hungary</em><br />
<em><a href="mailto:bercziszani@ludens.elte.hu">bercziszani@ludens.elte.hu</a></em></p>
<p class="TextAboutAuthor"><strong>Lajos Szilassi</strong><br />
<em><a href="mailto:szilassi@jgytf.u-szeged.hu">szilassi@jgytf.u-szeged.hu</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/09/clusters-produced-by-placing-rhombic-triacontahedra-at-the-vertices-of-polyhedra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Soft Landing on the Moon with Mathematica</title>
		<link>http://www.mathematica-journal.com/2012/08/soft-landing-on-the-moon-with-mathematica/</link>
		<comments>http://www.mathematica-journal.com/2012/08/soft-landing-on-the-moon-with-mathematica/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 20:38:23 +0000</pubDate>
		<dc:creator>Marian Muresan</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=29654</guid>
		<description><![CDATA[We consider the problem of landing a spacecraft on the Moon, assuming that aerodynamic and gravitational forces of bodies other than the Moon are negligible, and lateral motion can be ignored. Accordingly, the descent trajectory is vertical, and the thrust vector is tangent to the trajectory.
Because the spacecraft is near the Moon, we assume that [...]]]></description>
			<content:encoded><![CDATA[<p>We consider the problem of landing a spacecraft on the Moon, assuming that aerodynamic and gravitational forces of bodies other than the Moon are negligible, and lateral motion can be ignored. Accordingly, the descent trajectory is vertical, and the thrust vector is tangent to the trajectory.</p>
<p>Because the spacecraft is near the Moon, we assume that the lunar acceleration of gravity has the constant value <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_1.gif" alt="" width="44" height="13" />, that the relative velocity of the exhaust gases with respect to the spacecraft is constant, and that the mass rate <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_2.gif" alt="" width="26" height="13" /> is constrained by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_3.gif" alt="" width="78" height="13" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_4.gif" alt="" width="8" height="13" /> is constant and gives the maximum rate of change of the mass due to burning the fuel.<br />
<span id="more-29654"></span></p>
<h3>Mathematical Approach to a Soft Landing</h3>
<p>The problem is to make a soft landing on the surface of the Moon with the minimum amount of fuel.</p>
<p>Here is a sketch of the system immediately preceding the landing.</p>
<p><img class="alignnone size-full wp-image-29715" title="Muresan_Input_1" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Input_1.gif" alt="" width="660" height="283" /><br />
<img class="alignnone size-full wp-image-29837" title="Muresan_Output_1" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Output_1.gif" alt="" width="360" height="250" /></p>
<p>Following [<a href="#Kirk">1</a>, pp. 247-248] and [<a href="#Meditch">2</a>], we introduce the following notation and assumptions:</p>
<ul>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_5.gif" alt="" width="4" height="12" /> is time</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_6.gif" alt="" width="21" height="12" /> is the mass of the spacecraft, which varies as fuel is burned</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_7.gif" alt="" width="26" height="12" /> is the rate of change of mass, constrained by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_8.gif" alt="" width="76" height="12" /></li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_9.gif" alt="" width="41" height="12" />, the gravitational constant near the Moon</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_10.gif" alt="" width="6" height="12" /> is a constant, the relative velocity of the exhaust gases with respect to the spacecraft</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_11.gif" alt="" width="77" height="12" />, the thrust</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_12.gif" alt="" width="18" height="12" /> is the the height, with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_13.gif" alt="" width="38" height="12" /></li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_14.gif" alt="" width="54" height="12" />, the velocity</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_15.gif" alt="" width="58" height="12" />, the control function</li>
</ul>
<p>Recalling our assumptions, aerodynamic forces and gravitational forces of bodies other than the Moon are negligible and lateral motion is ignored. Thus the descent trajectory is vertical and the thrust vector is perpendicular to the ground.</p>
<p>We also suppose that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_16.gif" alt="" width="97" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_17.gif" alt="" width="11" height="12" /> is the mass of the spacecraft without fuel and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_18.gif" alt="" width="8" height="12" /> is the initial mass of fuel; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_19.gif" alt="" width="46" height="12" />, since as we expect that the spacecraft will return to Earth, it needs some fuel for takeoff.</p>
<h3>Equations of Motion</h3>
<p>By Newton&#8217;s second law ([<a href="#Leitmann">3</a>, p. 128] and [<a href="#Meditch">2</a>]),</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29693" title="Muresan_DisplayFormulaNumbered_1" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_1.gif" alt="" width="233" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>which can be written as a system of equations</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29694" title="Muresan_DisplayFormulaNumbered_2" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_2.gif" alt="" width="57" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29695" title="Muresan_DisplayFormulaNumbered_3" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_3.gif" alt="" width="99" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29697" title="Muresan_DisplayFormulaNumbered_4" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_4.gif" alt="" width="67" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_20.gif" alt="" width="6" height="12" /> is a constant. The third equation states that the loss of mass per second (the fuel burned by the jet per second) is proportional to the thrust of the jet.</p>
<h3>The Optimal Control Problem</h3>
<p>Our goal is to minimize the fuel consumption, so the cost functional is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29698" title="Muresan_DisplayFormulaNumbered_5" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_5.gif" alt="" width="220" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:5">(5)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_21.gif" alt="" width="6" height="12" /> is the first time for which</p>
<p class="input"><img class="alignnone size-full wp-image-29657" title="Muresan_DisplayFormula_2" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_2.gif" alt="" width="76" height="14" /></p>
<p>Thus the horizon is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_22.gif" alt="" width="27" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_23.gif" alt="" width="6" height="12" /> remains to be determined.</p>
<p>In vector form, if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_24.gif" alt="" width="218" height="12" />, then</p>
<p class="input"><img class="alignnone size-full wp-image-29671" title="Muresan_DisplayFormula_3" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_3.gif" alt="" width="102" height="12" /></p>
<p>and the problem can be written</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29699" title="Muresan_DisplayFormulaNumbered_6" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_6.gif" alt="" width="255" height="140" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:6">(6)</a></td>
</tr>
</tbody>
</table>
<p>and finally,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29894" title="Muresan_DisplayFormulaNumbered_7" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_71.gif" alt="" width="361" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:7">(7)</a></td>
</tr>
</tbody>
</table>
<p>From (<a href="#Eq:3">3</a>) we have that</p>
<p class="input"><img class="alignnone size-full wp-image-29658" title="Muresan_DisplayFormula_4" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_4.gif" alt="" width="130" height="33" /></p>
<p>and by integration over the interval <img class="alignnone size-full wp-image-29744" style="vertical-align: middle;" title="Muresan_Math_25" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_25.gif" alt="" width="25" height="12" />, we get that</p>
<p class="input"><img class="alignnone size-full wp-image-29672" title="Muresan_DisplayFormula_5" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_5.gif" alt="" width="164" height="34" /></p>
<p>It follows that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_26.gif" alt="" width="45" height="12" /> if and only if</p>
<p class="input"><img class="alignnone size-full wp-image-29673" title="Muresan_DisplayFormula_6" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_6.gif" alt="" width="122" height="35" /></p>
<p>Solving for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_27.gif" alt="" width="23" height="12" />,</p>
<p class="input"><img class="alignnone size-full wp-image-29674" title="Muresan_DisplayFormula_7" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_7.gif" alt="" width="114" height="23" /></p>
<p>Now we substitute this into (<a href="#Eq:5">5</a>) to get</p>
<p class="input"><img class="alignnone size-full wp-image-29659" title="Muresan_DisplayFormula_8" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_8.gif" alt="" width="140" height="32" /></p>
<p>This result was published in [<a href="#Meditch">2</a>].</p>
<p><strong>Theorem 1</strong></p>
<div id="324568568" class="Theorem"><a name="324568568"></a>Consider equation (<a href="#Eq:5">5</a>) with conditions (<a href="#Eq:6">6</a>) and (<a href="#Eq:7">7</a>). Then for some given <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_28.gif" alt="" width="20" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_29.gif" alt="" width="25" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_30.gif" alt="" width="6" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_31.gif" alt="" width="6" height="12" />, the amount of fuel required to stop the spacecraft, that is, to force <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_32.gif" alt="" width="73" height="12" />, is a strictly increasing monotonic function of the terminal time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_33.gif" alt="" width="6" height="12" />.</div>
<p><strong>Corollary 1</strong></p>
<div id="1150009375" class="Corollary"><a name="1150009375"></a>Minimizing the terminal time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_34.gif" alt="" width="6" height="12" /> for equation (<a href="#Eq:5">5</a>) with (<a href="#Eq:6">6</a>) and (<a href="#Eq:7">7</a>) is equivalent to minimizing the fuel consumption.</div>
<p>From here it follows that instead of (<a href="#Eq:7">7</a>) we can consider the following cost functional</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29701" title="Muresan_DisplayFormulaNumbered_8" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_8.gif" alt="" width="178" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:8">(8)</a></td>
</tr>
</tbody>
</table>
<p>and thus equation (<a href="#Eq:6">6</a>) with (<a href="#Eq:7">7</a>) becomes (<a href="#Eq:6">6</a>) with (<a href="#Eq:8">8</a>). This is a Mayer optimal control problem (see Chapter 4 of [<a href="#Cesari">4</a>]).</p>
<h3>Necessary Conditions for the Mayer Problem</h3>
<p>To avoid a lengthy discussion, we state a short version of theorem 4.2.i in [<a href="#Cesari">4</a>]. Let the Mayer problem be expressed as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29854" title="Muresan_DisplayFormulaNumbered_9" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_9.gif" alt="" width="224" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:9">(9)</a></td>
</tr>
</tbody>
</table>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-29896" title="Muresan_DisplayFormulaNumbered_10" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormulaNumbered_10.gif" alt="" width="407" height="83" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:10">(10)</a></td>
</tr>
</tbody>
</table>
<p>A pair <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_35.gif" alt="" width="51" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_36.gif" alt="" width="44" height="12" />, is said to be <em>admissible</em> or <em>feasible</em> provided <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_37.gif" alt="" width="71" height="12" /> is absolutely continuous [<a href="#Muresan">5</a>], <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_38.gif" alt="" width="72" height="12" /> is measurable, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_39.gif" alt="" width="6" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_40.gif" alt="" width="6" height="12" /> satisfy (<a href="#Eq:10">10</a>). Let <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_41.gif" alt="" width="9" height="12" /> be the class of admissible pairs <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_42.gif" alt="" width="27" height="12" />. The goal is to find the minimum of the cost functional <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_43.gif" alt="" width="36" height="12" /> over <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_44.gif" alt="" width="9" height="12" />, that is, to find an element <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_45.gif" alt="" width="60" height="12" /> such that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_46.gif" alt="" width="129" height="12" /> for all <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_47.gif" alt="" width="50" height="12" />. We introduce the variables <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_48.gif" alt="" width="81" height="12" />, called <em>multipliers</em>, and an auxiliary function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_49.gif" alt="" width="62" height="12" />, called the <em>Hamiltonian</em>, defined on <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_50.gif" alt="" width="56" height="12" /> by</p>
<p class="input"><img class="alignnone size-full wp-image-29675" title="Muresan_DisplayFormula_9" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_9.gif" alt="" width="155" height="38" /></p>
<p>We define</p>
<p class="input"><img class="alignnone size-full wp-image-29676" title="Muresan_DisplayFormula_10" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_10.gif" alt="" width="159" height="22" /></p>
<p>More assumptions are necessary:</p>
<ol class="ItemNumbered">
<li>There exists an element <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_51.gif" alt="" width="60" height="12" /> such that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_52.gif" alt="" width="129" height="12" /> for all <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_53.gif" alt="" width="50" height="12" />.</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_54.gif" alt="" width="8" height="12" /> is closed in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_55.gif" alt="" width="26" height="15" />.</li>
<li>The set <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_56.gif" alt="" width="116" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_57.gif" alt="" width="45" height="12" /> is closed in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_58.gif" alt="" width="38" height="15" />.</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_59.gif" alt="" width="65" height="15" />.</li>
<li>Notation:</li>
<div id="88795491" class="ItemParagraph"><a name="88795491"></a><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_60.gif" alt="" width="43" height="24" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_61.gif" alt="" width="50" height="29" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_62.gif" alt="" width="121" height="29" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_63.gif" alt="" width="107" height="24" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_64.gif" alt="" width="77" height="29" />.</div>
<li>The graph <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_65.gif" alt="" width="101" height="14" /> of the optimal trajectory <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_66.gif" alt="" width="11" height="12" /> belongs to the interior of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_67.gif" alt="" width="8" height="12" />.</li>
<li><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_68.gif" alt="" width="9" height="12" /> does not depend on time and is a closed set.</li>
<li>The end point <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_69.gif" alt="" width="135" height="12" /> of the optimal trajectory <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_70.gif" alt="" width="11" height="12" /> is a point of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_71.gif" alt="" width="7" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_72.gif" alt="" width="7" height="12" /> possesses a tangent variety <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_73.gif" alt="" width="10" height="12" /> (of some dimension <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_74.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_75.gif" alt="" width="72" height="12" />), whose vectors are denoted by</li>
</ol>
<p class="input"><img class="alignnone size-full wp-image-29899" title="Muresan_DisplayFormula_11" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_11.gif" alt="" width="282" height="18" /></p>
<div id="551110924" class="ItemParagraph"><a name="551110924"><br />
</a><span style="margin-left: 40px;">or by</span></p>
<p class="input"><img class="alignnone size-full wp-image-29900" title="Muresan_DisplayFormula_12" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_12.gif" alt="" width="338" height="18" /></p>
<p><strong>Theorem 2</strong></p>
<div id="132391683" class="Theorem"><a name="132391683"></a>Assume these eight hypotheses and let <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_76.gif" alt="" width="32" height="12" /> be an optimal pair of the Mayer problem (<a href="#Eq:9">9</a>) and (<a href="#Eq:10">10</a>). Then the optimal pair <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_77.gif" alt="" width="37" height="12" /> necessarily has the following properties:</div>
<div id="313957889" class="TheoremContinuation"><a name="313957889"></a>(a) There is an absolutely continuous function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_78.gif" alt="" width="93" height="12" /> such that</div>
<p class="input"><img class="alignnone size-full wp-image-29660" title="Muresan_DisplayFormula_13" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_13.gif" alt="" width="274" height="33" /></p>
<div id="322919744" class="TheoremContinuation"><a name="322919744"></a>If <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_79.gif" alt="" width="12" height="12" /> is not identically zero at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_80.gif" alt="" width="24" height="12" />, then <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_81.gif" alt="" width="19" height="12" /> is never zero in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_82.gif" alt="" width="27" height="12" />.</div>
<div id="620961439" class="TheoremContinuation"><a name="620961439"></a>(b) For almost any fixed <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_83.gif" alt="" width="45" height="12" /> (a.e.), the Hamiltonian (as a function depending only on <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_84.gif" alt="" width="6" height="12" />) takes its minimum value in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_85.gif" alt="" width="9" height="12" /> at the optimal strategy <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_86.gif" alt="" width="48" height="12" />, that is, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_87.gif" alt="" width="243" height="12" /> (a.e.).</div>
<div id="1875864500" class="TheoremContinuation"><a name="1875864500"></a>(c) The function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_88.gif" alt="" width="113" height="12" /> coincides a.e. in <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_89.gif" alt="" width="27" height="12" /> with an absolutely continuous function and</div>
<p class="input"><img class="alignnone size-full wp-image-29679" title="Muresan_DisplayFormula_14" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_14.gif" alt="" width="322" height="33" /></p>
<p>The Hamiltonian and the equations for the multipliers to (<a href="#Eq:6">6</a>) and (<a href="#Eq:7">7</a>) are</p>
<p class="input"><img class="alignnone size-full wp-image-29680" title="Muresan_DisplayFormula_15" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_15.gif" alt="" width="365" height="18" /></p>
<p class="input"><img class="alignnone size-full wp-image-29681" title="Muresan_DisplayFormula_16" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_16.gif" alt="" width="180" height="17" /></p>
<p>so that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_90.gif" alt="" width="38" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_91.gif" alt="" width="76" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_92.gif" alt="" width="44" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_93.gif" alt="" width="11" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_94.gif" alt="" width="11" height="12" /> are constants.</p>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_95.gif" alt="" width="95" height="17" />, the minimum of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_96.gif" alt="" width="10" height="12" /> is attained with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_97.gif" alt="" width="26" height="12" />, and then</p>
<p class="input"><img class="alignnone size-full wp-image-29682" title="Muresan_DisplayFormula_17" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_17.gif" alt="" width="87" height="12" /></p>
<p>This corresponds to <em>free fall</em> for the spacecraft.</p>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_98.gif" alt="" width="93" height="17" />, the minimum of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_99.gif" alt="" width="10" height="12" /> is attained with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_100.gif" alt="" width="36" height="12" />, and then</p>
<p class="input"><img class="alignnone size-full wp-image-29661" title="Muresan_DisplayFormula_18" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_18.gif" alt="" width="363" height="18" /></p>
<p>Thus we find that the control function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_101.gif" alt="" width="6" height="12" /> takes only extreme values <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_102.gif" alt="" width="6" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_103.gif" alt="" width="7" height="12" />.</p>
<p>If on an interval <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_104.gif" alt="" width="39" height="12" /> we have that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_105.gif" alt="" width="26" height="12" />, and hence</p>
<p class="input"><img class="alignnone size-full wp-image-29662" title="Muresan_DisplayFormula_19" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_19.gif" alt="" width="180" height="12" /></p>
<p>then for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_106.gif" alt="" width="59" height="12" />, we have</p>
<p class="input"><img class="alignnone size-full wp-image-29683" title="Muresan_DisplayFormula_20" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_20.gif" alt="" width="73" height="12" /></p>
<p class="input"><img class="alignnone size-full wp-image-29684" title="Muresan_DisplayFormula_21" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_21.gif" alt="" width="127" height="12" /></p>
<p class="input"><img class="alignnone size-full wp-image-29685" title="Muresan_DisplayFormula_22" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_22.gif" alt="" width="247" height="15" /></p>
<p>In this case, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_107.gif" alt="" width="39" height="12" /> describes an arc of a parabola of equation</p>
<p class="input"><img class="alignnone size-full wp-image-29992" style="vertical-align: middle;" title="Muresan_DisplayFormula_23A" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_23A.gif" alt="" width="137" height="17" /> with <img class="alignnone size-full wp-image-29993" style="margin-left: 0px; vertical-align: middle;" title="Muresan_DisplayFormula_23B" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_23B.gif" alt="" width="40" height="17" /></p>
<p>If on an interval <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_108.gif" alt="" width="39" height="12" /> we have <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_109.gif" alt="" width="36" height="12" />, and hence</p>
<p class="input"><img class="alignnone size-full wp-image-29687" title="Muresan_DisplayFormula_24" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_24.gif" alt="" width="196" height="17" /></p>
<p>then for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_110.gif" alt="" width="59" height="12" />, we find</p>
<p class="input"><img class="alignnone size-full wp-image-29688" title="Muresan_DisplayFormula_25" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_25.gif" alt="" width="128" height="12" /></p>
<p class="input"><img class="alignnone size-full wp-image-29689" title="Muresan_DisplayFormula_26" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_26.gif" alt="" width="265" height="18" /></p>
<p class="input"><img class="alignnone size-full wp-image-29690" title="Muresan_DisplayFormula_27" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_27.gif" alt="" width="540" height="18" /></p>
<p><strong>Theorem 3</strong></p>
<div id="400047151" class="Theorem"><a name="400047151"></a>If all the assumptions in the section Mathematical Approach to a Soft Landing are satisfied, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_111.gif" alt="" width="6" height="12" /> is the time of ignition of the engine, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_112.gif" alt="" width="6" height="12" /> is the time of landing, that is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_113.gif" alt="" width="86" height="12" />, and if the system of equations</div>
<p class="input"><img class="alignnone size-full wp-image-29691" title="Muresan_DisplayFormula_28" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_28.gif" alt="" width="233" height="18" /></p>
<p class="input"><img class="alignnone size-full wp-image-29692" title="Muresan_DisplayFormula_29" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_DisplayFormula_29.gif" alt="" width="493" height="18" /></p>
<div id="936116903" class="TheoremContinuation"><a name="936116903"></a>for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_114.gif" alt="" width="6" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_115.gif" alt="" width="12" height="12" /> is solvable, then there exists an optimal pair <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Math_116.gif" alt="" width="37" height="12" /> that solves the optimal control problem given by (<a href="#Eq:6">6</a>) and (<a href="#Eq:8">8</a>).</div>
<h3>Program for Soft Landing on the Moon</h3>
<p><tt>MoonLanding</tt> is a <em>Mathematica</em> program for a soft landing on the Moon. Here <tt>h0</tt> is the initial height, <tt>v0</tt> is the initial velocity, <tt>mass</tt> is the mass of the lander without fuel, <tt>fuel</tt> is the initial fuel, <tt>g</tt> is acceleration due to gravity, <tt>k</tt> is the relative velocity of the exhaust gases, and <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Mu.gif" alt="" width=" 6" height="19" /></tt> is the rate of change of the mass by burning.</p>
<p>The correctness of the results drastically depends on the initial values of the variables <tt>z</tt> and <tt>g</tt> that we use in solving the nonlinear system of equations in the program.</p>
<p class="input"><img class="alignnone size-full wp-image-29716" title="Muresan_Input_30" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Input_30.gif" alt="" width="662" height="778" /></p>
<p class="input"><img class="alignnone size-full wp-image-29717" title="Muresan_Input_31" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Input_31.gif" alt="" width="400" height="12" /></p>
<p class="output"><img class="alignnone size-full wp-image-29891" title="Muresan_Output_2" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Output_2.gif" alt="" width="420" height="297" /></p>
<p>This <tt>Manipulate</tt> lets you vary the parameters in real time.</p>
<p class="input"><img class="alignnone size-full wp-image-29718" title="Muresan_Input_32" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Input_32.gif" alt="" width="654" height="163" /></p>
<p class="output"><img class="alignnone size-full wp-image-29888" title="Muresan_Output_3" src="http://www.mathematica-journal.com/data/uploads/2012/07/Muresan_Output_3.gif" alt="" width="463" height="551" /></p>
<h3>Acknowledgments</h3>
<p>The author expresses his gratitude to Horia F. Pop from Babes-Bolyai University, Faculty of Mathematics and Computer Science in Cluj-Napoca, Romania, for valuable discussions.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Kirk">[1] </a></td>
<td>D. E. Kirk, <em>Optimal Control Theory</em>, Englewood Cliffs, NJ: Prentice-Hall, Inc., 1970.</td>
</tr>
<tr>
<td class="Reference"><a name="Meditch">[2] </a></td>
<td>J. Meditch, &#8220;On the Problem of Optimal Thrust Programming for a Lunar Soft Landing,&#8221; <em>IEEE Transactions on Automatic Control</em>, <strong>9</strong>(4), 1964 pp. 477-484. <a href="http://dx.doi.org/10.1109/TAC.1964.1105758" target="blank">doi:10.1109/TAC.1964.1105758</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Leitmann">[3] </a></td>
<td>G. Leitmann (ed.), <em>Optimization Techniques: With</em> <em>Applications to Aerospace</em> <em>Systems</em>, <em>Mathematics in Science and Engineering</em>, Vol. 5, New York: Academic Press, 1962.</td>
</tr>
<tr>
<td class="Reference"><a name="Cesari">[4] </a></td>
<td>L. Cesari, <em>Optimization&#8212;Theory and Applications, Problems with Ordinary Differential Equations, Applications of Mathematics</em>, Vol. 17, New York: Springer, 1983.</td>
</tr>
<tr>
<td class="Reference"><a name="Muresan">[5] </a></td>
<td>M. Mureşan, <em>A Concrete Approach to Classical Analysis</em>, New York: Springer, 2009.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">Marian Mureşan, &#8220;Soft Landing on the Moon with <em>Mathematica</em>,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-13.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">Marian Mureşan is affiliated with Babes-Bolyai University, Faculty of Mathematics and Computer Science, in Cluj-Napoca, Romania. He is interested in analysis, nonsmooth analysis, calculus of variations, and optimal control.</p>
<p class="TextAboutAuthor"><strong>Marian </strong><strong>Mureşan</strong><br />
<em>Babes-Bolyai University<br />
Faculty of Mathematics and Computer Science<br />
1, M. Kogalniceanu str., 400084, Cluj-Napoca<br />
Romania<br />
</em><em><a href="mailto:mmarianus24@yahoo.com">mmarianus24@yahoo.com</a></em><br />
<em><a href="mailto:mmarian@math.ubbcluj.ro">mmarian@math.ubbcluj.ro</a></em></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/08/soft-landing-on-the-moon-with-mathematica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Walker Function</title>
		<link>http://www.mathematica-journal.com/2012/06/the-walker-function/</link>
		<comments>http://www.mathematica-journal.com/2012/06/the-walker-function/#comments</comments>
		<pubDate>Mon, 04 Jun 2012 18:53:32 +0000</pubDate>
		<dc:creator>Mikhail D. Mikhailov</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=25183</guid>
		<description><![CDATA[The special function  (the Walker function) and its derivatives are important for the description of near-wall turbulent flows. This article gives exact expressions for these functions, based on original identities for the hypergeometric functions  and . We also introduce a new initial value problem that generates interpolating functions for  and its derivatives.
Introduction
The [...]]]></description>
			<content:encoded><![CDATA[<p>The special function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_1.gif" alt="" width="22" height="13" /> (the Walker function) and its derivatives are important for the description of near-wall turbulent flows. This article gives exact expressions for these functions, based on original identities for the hypergeometric functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_2.gif" alt="" width="20" height="13" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_3.gif" alt="" width="21" height="16" />. We also introduce a new initial value problem that generates interpolating functions for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_4.gif" alt="" width="22" height="13" /> and its derivatives.<span id="more-25183"></span><\p></p>
<h3><span class="Section">Introduction</span></h3>
<p>The quantitative description of turbulent flows is known to be severely hampered by the extremely rapid variations in the mean and higher-order statistics in the near-wall region. Some very early studies [<a href="#Prandtl1929">1</a>, <a href="#Kármán1930">2</a>, <a href="#Millikan1939">3</a>] showed that the basic structure of an attached turbulent boundary layer consists of a viscous wall layer, in which the turbulent and laminar stresses are of comparable magnitude, and a defect layer, in which the velocity profile may be expressed in terms of a small perturbation to the external flow solution [<a href="#Loureiro&amp;Freire2011">4</a>]. Also, [<a href="#Prandtl1929">1</a>, <a href="#Kármán1930">2</a>, <a href="#Millikan1939">3</a>] showed that this structure naturally leads to a universal velocity solution that has logarithmic behavior and depends on the velocity and length scales based on the friction velocity.</p>
<p>For separated flows, this picture changes dramatically; the friction velocity reduces to zero, so that a new scaling procedure based on the local pressure gradient at the wall needs to be introduced. The logarithmic solution is then reduced to a square-root velocity profile. Aspects of the complex flow structure due to separation are thoroughly discussed in [<a href="#Loureiro&amp;Freire2011">4</a>].</p>
<p>To incorporate the structure of organized motion into a near-wall analytical model, Walker et al. [<a href="#WalkerEtcAIAAJ1987">5</a>] proposed a time-dependent formulation based on the dynamical features of the wall layer. Following the general description commonly found in the literature, the flow dynamics are considered to be dominated by two features: wall layer streaks and the bursting phenomenon. The streaks are elongated in the flow direction, with length of the order of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_5.gif" alt="" width="39" height="14" /> (where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_6.gif" alt="" width="52" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_7.gif" alt="" width="6" height="12" /> is the kinematic viscosity, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_8.gif" alt="" width="11" height="12" /> is the friction velocity), and can be observed over a large characteristic time, the quiescent period [<a href="#KlineEtc1967">6</a>].</p>
<p>Analytical near-wall solutions for turbulent flows are of central significance, since the extreme thinness of the viscous sublayer naturally demands the use of exceptionally fine meshes in the numerical computation of problems of practical relevance. This difficulty can be naturally overcome, provided the local analytical solutions are used to bridge the viscous-dominated region.</p>
<p>In [<a href="#WalkerEtcAIAAJ1987">5</a>], the duration of the quiescent period is assumed to be much larger than the duration of the bursting process, so that solutions for the unsteady Navier-Stokes equations can be given in terms of the flow development between pairs of streaks. The analysis resorts to standard methods for orthogonal functions to arrive at a set of three nonlinear governing equations that have to be solved numerically. In addition, a semi-similarity procedure is proposed, resulting in a solution that includes <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_9.gif" alt="" width="21" height="12" />. This function is a similarity solution of the linear diffusion equation that behaves logarithmically for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_10.gif" alt="" width="6" height="12" /> and vanishes at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_11.gif" alt="" width="26" height="12" />. Mean velocity profiles are obtained by evaluating a time-average of the solution over the period between bursts, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_12.gif" alt="" width="15" height="16" />.</p>
<p>In mathematics <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_13.gif" alt="" width="7" height="12" /> is generally used to denote a variant of the Riemann zeta function. Here, no confusion should arise: the function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_14.gif" alt="" width="7" height="12" />, as defined in [<a href="#WalkerEtcAIAAJ1987">5</a>], is given by the equation <tt>e1</tt> below.</p>
<p>Instantaneous and averaged velocity profiles are presented for four combinations of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_15.gif" alt="" width="14" height="14" /> (the dimensionless pressure gradient parameter) and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_16.gif" alt="" width="15" height="16" /> in accordance with typically measured values. For constant pressure flow (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_17.gif" alt="" width="37" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_18.gif" alt="" width="56" height="16" />), the canonical boundary layer structure is well reproduced. Under a favorable pressure gradient (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_19.gif" alt="" width="64" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_20.gif" alt="" width="47" height="16" />), the instantaneous profiles are accelerated as expected. For adverse pressure gradients (<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_21.gif" alt="" width="49" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_22.gif" alt="" width="50" height="16" />; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_23.gif" alt="" width="43" height="14" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_24.gif" alt="" width="41" height="16" />), <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_25.gif" alt="" width="15" height="16" /> decreases and, for the latter case, reverse instantaneous flow is observed over the latter part of the cycle.</p>
<p>Here, we develop a new version of the near-wall turbulent velocity profile shown in [<a href="#WalkerEtcAIAAJ1987">5</a>], in particular, of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_26.gif" alt="" width="21" height="12" /> function. This article introduces the required features of function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_27.gif" alt="" width="21" height="12" /> and its derivatives. In addition, we present some original identities for the hypergeometric functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_28.gif" alt="" width="22" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_29.gif" alt="" width="22" height="14" />.</p>
<h3>Identity Involving <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_30.gif" alt="" width="24" height="16" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_31.gif" alt="" width="29" height="19" /></h3>
<p>The function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_32.gif" alt="" width="21" height="12" /> is of particular relevance, being the only known similarity solution of the linear diffusion equation that behaves logarithmically for large <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_33.gif" alt="" width="6" height="12" /> and vanishes at <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_34.gif" alt="" width="26" height="12" /> [<a href="#WalkerEtcAIAAJ1987">5</a>].</p>
<p>The <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_35.gif" alt="" width="21" height="12" /> function can be defined either in terms of an expansion or an integral, as shown in [<a href="#WalkerEtcAIAAJ1987">5</a>] (equations (44) and (42)). In the latter form, the triple integral can be rearranged to a single integral.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_1.gif" alt="" width="398" height="47" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_1.gif" alt="" width="549" height="42" /></p>
<p>The coefficients <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_36.gif" alt="" width="28" height="12" /> are defined by a recurrence relation.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_2.gif" alt="" width="246" height="12" /></p>
<p>The sum in <tt>e1</tt> is uniformly convergent for all <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_37.gif" alt="" width="6" height="12" />. This is particularly useful in the evaluation of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_38.gif" alt="" width="21" height="12" /> for small to moderate values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_39.gif" alt="" width="6" height="12" /> [<a href="#WalkerEtcAIAAJ1987">5</a>].</p>
<p>This solves the recurrence equation.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_3.gif" alt="" width="210" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_2.gif" alt="" width="254" height="12" /></p>
<p><tt>FullSimplify</tt> shows that the coefficients <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_40.gif" alt="" width="28" height="12" /> are the harmonic numbers.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_4.gif" alt="" width="310" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_3.gif" alt="" width="167" height="12" /></p>
<p>After substituting equation <tt>e4</tt> into equation <tt>e1</tt>, the <tt>sum</tt> turns out to be a hypergeometric function.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_5.gif" alt="" width="79" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_4.gif" alt="" width="353" height="68" /></p>
<p>This is the second term of <tt>e5</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_6.gif" alt="" width="49" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_5.gif" alt="" width="277" height="31" /></p>
<p>This is difficult to calculate for large numerical values of <tt><img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Eta.gif" alt="" width="6" height="19" /></tt>, because <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_41.gif" alt="" width="24" height="19" /> is extremely small, while the hypergeometric function is extremely large. To remove <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_42.gif" alt="" width="24" height="19" /> from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_43.gif" alt="" width="49" height="12" />, we use the following identity.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_7.gif" alt="" width="567" height="25" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_6.gif" alt="" width="29" height="12" /></p>
<p>Take the derivative of <tt>e6</tt> with respect to <tt><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_IF_10.gif" alt="" width="7" height="12" /></tt> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_44.gif" alt="" width="29" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_45.gif" alt="" width="47" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_8.gif" alt="" width="258" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_7.gif" alt="" width="510" height="31" /></p>
<p>Use <tt>e7</tt> to substitute into <tt>e5</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_9.gif" alt="" width="79" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_8.gif" alt="" width="580" height="32" /></p>
<p>To verify that <tt>e8</tt> is an identity, we evaluate its right-hand side for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_46.gif" alt="" width="47" height="12" /> with <tt>100</tt> digits of precision.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_10.gif" alt="" width="57" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_9.gif" alt="" width="580" height="32" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_11.gif" alt="" width="135" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_10.gif" alt="" width="29" height="12" /></p>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_47.gif" alt="" width="32" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_48.gif" alt="" width="36" height="12" />, <em>Mathematica</em> 8 gives the following.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_12.gif" alt="" width="151" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_11.gif" alt="" width="580" height="31" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_13.gif" alt="" width="90" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_12.gif" alt="" width="580" height="31" /></p>
<p><em>Mathematica</em> 8 can evaluate <tt>e9</tt> and <tt>e10</tt> for numerical values of <tt><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_IF_27.gif" alt="" width="7" height="12" /></tt>. The following rule generates derivatives of order <tt>n</tt> that earlier versions of <em>Mathematica</em> can evaluate.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_14.gif" alt="" width="580" height="43" /></p>
<p>For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_49.gif" alt="" width="32" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_50.gif" alt="" width="36" height="12" />, the function <tt>WalkerDerivative</tt> gives the following.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_15.gif" alt="" width="191" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_13.gif" alt="" width="580" height="58" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_16.gif" alt="" width="191" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_14.gif" alt="" width="559" height="80" /></p>
<p>To verify that the right-hand sides of <tt>e9</tt> and <tt>e11</tt> are equal and that the right-hand sides of <tt>e10</tt> and <tt>e12</tt> are equal, we evaluate them for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_51.gif" alt="" width="47" height="12" /> with 100 digits of precision.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_17.gif" alt="" width="441" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_15.gif" alt="" width="83" height="12" /></p>
<h3>Initial Value Problem</h3>
<p>To derive the initial value problem for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_52.gif" alt="" width="28" height="12" />, we use <tt>e8</tt> and its derivatives.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_18.gif" alt="" width="126" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_16.gif" alt="" width="391" height="32" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_19.gif" alt="" width="98" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_17.gif" alt="" width="361" height="31" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_20.gif" alt="" width="155" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_18.gif" alt="" width="446" height="31" /></p>
<p>To obtain the desired initial value problem, we eliminate from <tt>e14</tt> and <tt>e15</tt> the hypergeometric function and replace <tt><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_IF_27.gif" alt="" width="7" height="12" /></tt> by <tt>0</tt> in <tt>e13</tt> and <tt>e14</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_21.gif" alt="" width="520" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_19.gif" alt="" width="348" height="31" /></p>
<p>The resulting ordinary differential equation is equivalent to equations (40) and (41) in [<a href="#WalkerEtcAIAAJ1987">5</a>]. The condition <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_53.gif" alt="" width="53" height="12" /> is also given in [<a href="#WalkerEtcAIAAJ1987">5</a>]. However, the condition <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_54.gif" alt="" width="57" height="12" /> is missing in [<a href="#WalkerEtcAIAAJ1987">5</a>], where no attempt is made to obtain a numerical solution.</p>
<p>We plot the function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_55.gif" alt="" width="28" height="12" /> (blue) and its derivative <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_56.gif" alt="" width="32" height="12" /> (purple).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Input_22.gif" alt="" width="580" height="193" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Output_20.gif" alt="" width="403" height="333" /></p>
<h3>Conclusion</h3>
<p>Exact expressions for the Walker function <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_56.gif" alt="" width="21" height="12" /> and its derivatives are obtained. From a computational point of view, an important result is the specification of the initial value problem, for it allows extremely fast interpolating functions to be generated. From a mathematical point of view, some new identities between the two hypergeometric functions <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_57.gif" alt="" width="20" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Mikhailov_Math_58.gif" alt="" width="22" height="14" /> are presented. These identities were revealed by the built-in <em>Mathematica</em> functions <tt>RSolve</tt>, <tt>Sum</tt>, and <tt>FullSimplify</tt>. Of possible interest is the application of the techniques to discover new identities and to the problems described in the book by Petkovšek et al. [<a href="#A=B">7</a>].</p>
<h3>Acknowledgments</h3>
<p>The first author is thankful to the Brazilian National Research Council (CNPq) and the Brazilian National Institute of Standards (INMETRO) for their financial support of this research through a CNPq Research Fellowship-Edital MCT/CNPq/Inmetro nº 059/2010-PROMETRO Processo Nº 563061/2010-3.</p>
<p>The second author is grateful to the Brazilian National Research Council (CNPq) for the award of a Research Fellowship (Grant No. 303982/2009-8). The work was financially supported by the Rio de Janeiro Research Foundation (FAPERJ) through Grant E-26/170.005/2008.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Prandtl1929">[1] </a></td>
<td>L. Prandtl, &#8220;Über die ausgebildete Turbulenz,&#8221; <em>ZAMM: Journal of Applied Mathematics and Mechanics/Zeitschrift für Angewandte Mathematik und Mechanik</em>, <strong>5</strong>, 1925 pp. 136-139.</td>
</tr>
<tr>
<td class="Reference"><a name="Kármán1930">[2] </a></td>
<td>T. von Kármán, &#8220;Mechanische Aehnlichkeit und Turbulenz,&#8221; <em>Proceedings of the Third International Congress for Applied Mechanics</em>, Vol. 1, Stockholm, 1930 (C. W. Oseen and W. Weibull, eds.), Stockholm: AB. Sveriges Litografiska Tryckerier, 1931 pp. 79-93 (in German).</td>
</tr>
<tr>
<td class="Reference"><a name="Millikan1939">[3] </a></td>
<td>C. B. Millikan, &#8220;A Critical Discussion of Turbulent Flow in Channels and Circular Tubes,&#8221; <em>Proceedings of the 5th International Congress for Applied Mechanics</em>, Cambridge, MA, 1938, New York: Wiley, 1939 pp. 386-392.</td>
</tr>
<tr>
<td class="Reference"><a name="Loureiro&amp;Freire2011">[4] </a></td>
<td>J. B. R. Loureiro, A. P. Silva Freire, &#8220;Scaling of Turbulent Separating Flows,&#8221; <em>International Journal of Engineering Science</em>, <strong>49</strong>(5), 2011 pp. 397-410.<br />
<a href="http://dx.doi.org/10.1016/j.ijengsci.2010.12.001" target="blank">doi:10.1016/j.ijengsci.2010.12.001</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="WalkerEtcAIAAJ1987">[5] </a></td>
<td>J. D. A. Walker, D. E. Abbott, R. K. Scharnhorst, and G. G. Weigand, &#8220;Wall-Layer Model for the Velocity Profile in Turbulent Flows,&#8221; <em>American Institute of Aeronautics and Astronautics Journal</em>, <strong>27</strong>(2), 1989 pp. 140-149.</td>
</tr>
<tr>
<td class="Reference"><a name="KlineEtc1967">[6] </a></td>
<td>S. J. Kline, W. C. Reynolds, F. A. Schraub, and P. W. Rundstadler, &#8220;The Structure of Turbulent Boundary Layers,&#8221; <em>Journal of Fluid Mechanics</em>, <strong>30</strong>(4), 1967 pp. 741-773.<br />
<a href="http://journals.cambridge.org/abstract_S0022112067001740" target="blank">journals.cambridge.org/abstract_S0022112067001740</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="A=B">[7] </a></td>
<td>M. Petkovšek, H. S. Wilf, D. Zeilberger, <em>A=B</em>, Wellesley, MA: A. K. Peters, 1996.<br />
<a href="http://www.cis.upenn.edu/~wilf/AeqB.html" target="blank">www.cis.upenn.edu/~wilf/AeqB.html</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">M. D. Mikhailov and A. P. Silva Freire, &#8220;The Walker Function,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-11.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Authors</h3>
<p class="TextAboutAuthor"><strong>M. D. Mikhailov<br />
</strong><em>INMETRO&#8212;Divisão de Metrologia em Dinâmica de Fluidos<br />
Dimci/Dinam, Prédio 3, Av. Nossa Senhora das Graças 50<br />
Duque de Caxias, 25250-020<br />
Rio de Janeiro, Brasil<br />
</em><em><a href="mailto:m.d.mikhailov@gmail.com">m.d.mikhailov@gmail.com</a></em></p>
<p class="TextAboutAuthor"><strong>Atila P. Silva Freire<br />
</strong><em>Mechanical Engineering Program (PEM/COPPE/UFRJ)<br />
C.P. 68503, 21941-972<br />
Rio de Janeiro, Brazil<br />
</em><em><a href="mailto:atila@mecanica.coppe.ufrj.br">atila@mecanica.coppe.ufrj.br</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/06/the-walker-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Relativistic Motion of a Charged Particle and Pauli Algebra</title>
		<link>http://www.mathematica-journal.com/2012/05/relativistic-motion-of-a-charged-particle-and-pauli-algebra/</link>
		<comments>http://www.mathematica-journal.com/2012/05/relativistic-motion-of-a-charged-particle-and-pauli-algebra/#comments</comments>
		<pubDate>Wed, 09 May 2012 17:55:49 +0000</pubDate>
		<dc:creator>Jan Vrbik</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=25514</guid>
		<description><![CDATA[We introduce some key formulas of special relativity and apply them to the motion of a spinless, charged point particle of unit mass, subject to the Lorentz force due to an external electromagnetic field. 
Pauli Algebra
An element of Pauli algebra consists of a complex scalar, say , and a three-dimensional complex vector , denoted , [...]]]></description>
			<content:encoded><![CDATA[<p>We introduce some key formulas of special relativity and apply them to the motion of a spinless, charged point particle of unit mass, subject to the Lorentz force due to an external electromagnetic field. <span id="more-25514"></span></p>
<h3>Pauli Algebra</h3>
<p>An element of Pauli algebra consists of a complex scalar, say <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_1.gif" alt="" width="8" height="12" />, and a three-dimensional complex vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_2.gif" alt="" width="6" height="12" />, denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_3.gif" alt="" width="52" height="12" />, which thus has eight real dimensions. In effect, this is a generalization of quaternion algebra, but with complex instead of real components. In this article, we call these elements &#8220;spinors.&#8221;</p>
<p>A product of two spinors is a spinor defined by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_1.gif" alt="" width="236" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:1">(1)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/CenterDot.gif" alt="" width="3" height="19" /> and <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/Cross.gif" alt="" width="6" height="19" /> are the dot and cross products, respectively. Note that this multiplication is associative, implying that we do not need parentheses when multiplying three or more spinors. But multiplication is not commutative (the result depends on the order of factors).</p>
<p>There are two important unary (single-argument) operations on spinors: the first is called a reflection (denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_4.gif" alt="" width="16" height="12" />), which changes the sign of the vector part, that is, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_5.gif" alt="" width="68" height="12" />; the second takes the complex conjugate of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_6.gif" alt="" width="8" height="12" /> and of each component of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_7.gif" alt="" width="6" height="12" />; it is denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_8.gif" alt="" width="14" height="12" />. Finally, just for convenience, we let <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_9.gif" alt="" width="16" height="14" /> denote the combination of both of these, that is, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_10.gif" alt="" width="75" height="12" /> Note that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_2.gif" alt="" width="124" height="45" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:2">(2)</a></td>
</tr>
</tbody>
</table>
<p>which are quite easy to verify.</p>
<p>The corresponding <em>Mathematica</em> routines look and work like this.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_1.gif" alt="" width="415" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_1.gif" alt="" width="256" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_2.gif" alt="" width="213" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_2.gif" alt="" width="215" height="12" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_3.gif" alt="" width="364" height="28" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_3.gif" alt="" width="207" height="12" /></p>
<p>From now on we consider a three-dimensional vector to be a special case of a spinor, meaning that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_11.gif" alt="" width="6" height="12" /> is shorthand for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_12.gif" alt="" width="27" height="12" />. We can easily compute various functions of spinors (and of three-dimensional vectors, as a special case). Thus, for example, assuming that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_13.gif" alt="" width="6" height="12" /> is a three-dimensional vector with real components, we find</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_3.gif" alt="" width="580" height="39" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:3">(3)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_14.gif" alt="" width="6" height="12" /> is the length of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_15.gif" alt="" width="6" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_16.gif" alt="" width="29" height="24" /> is a unit vector in the same direction.</p>
<p>Similarly, for a three-dimensional vector with pure imaginary components (which we express in the form <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_17.gif" alt="" width="12" height="12" /> to keep the elements of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_18.gif" alt="" width="7" height="12" /> real), the same kind of expansion yields</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_4.gif" alt="" width="580" height="39" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:4">(4)</a></td>
</tr>
</tbody>
</table>
<p>again where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_19.gif" alt="" width="7" height="12" /> is the length of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_20.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_21.gif" alt="" width="32" height="21" /> is a unit vector in the same direction.</p>
<p>This can be easily extended to a complex-vector argument, as follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_4.gif" alt="" width="423" height="35" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_4.gif" alt="" width="400" height="40" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_5.gif" alt="" width="125" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_5.gif" alt="" width="419" height="40" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_6.gif" alt="" width="214" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_6.gif" alt="" width="580" height="12" /></p>
<h3>Special Relativity</h3>
<p>The basic idea of Einstein&#8217;s theory is to unite space and time into a single entity of spacetime, whose &#8220;points&#8221; (or events) can then be represented by <em>real</em> spinors of type <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_22.gif" alt="" width="48" height="12" />. The separation between any two such events constitutes a so-called 4-vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_23.gif" alt="" width="81" height="12" /> that, when multiplied (in the spinor sense) by its own reflection, yields a pure scalar <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_24.gif" alt="" width="149" height="15" />. It is now postulated that this quantity must be invariant (having the same value) in all inertial coordinate systems (i.e. those that differ from each other by a fixed rotation and/or a boost&#8212;a motion at constant velocity). For simplicity, our choice of units sets the speed of light (which must be the same in all inertial systems) equal to 1.</p>
<p>The question is: how do we transform 4-vectors from one inertial frame to another, while maintaining this invariance? The answer is provided by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_5.gif" alt="" width="85" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:5">(5)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_25.gif" alt="" width="9" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_26.gif" alt="" width="12" height="12" /> represent a 4-vector in the old and new frame of reference, respectively, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_27.gif" alt="" width="7" height="12" /> is a spinor such that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_28.gif" alt="" width="104" height="12" />. It is obvious that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_29.gif" alt="" width="12" height="12" /> remains real whenever <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_35.gif" alt="" width="9" height="12" /> is real, and that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_6.gif" alt="" width="488" height="14" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:6">(6)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_30.gif" alt="" width="59" height="12" /> (the scalar invariant of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_31.gif" alt="" width="9" height="12" />). This shows that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_32.gif" alt="" width="6" height="12" /> has the same value in all inertial frames of reference. Requiring reflection to be a frame-independent operation (meaning that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_33.gif" alt="" width="68" height="12" /> for every 4-vector) leads to</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_7.gif" alt="" width="204" height="14" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:7">(7)</a></td>
</tr>
</tbody>
</table>
<p>From this, we can see that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_34.gif" alt="" width="16" height="12" /> transforms differently from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_35.gif" alt="" width="9" height="12" />, being an example of a four-dimensional <em>covector</em> (a <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_36.gif" alt="" width="13" height="12" />-vector, in our notation). Another important example of a <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_37.gif" alt="" width="13" height="12" />-vector is the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_38.gif" alt="" width="34" height="12" /> operator, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_39.gif" alt="" width="8" height="12" /> stands for the usual three-dimensional (spatial) gradient (the collection of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_40.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_41.gif" alt="" width="6" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_42.gif" alt="" width="5" height="12" /> partial derivatives).</p>
<p>One can show that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_43.gif" alt="" width="55" height="12" /> if and only if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_44.gif" alt="" width="55" height="24" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_2.gif" alt="" width="6" height="12" /> is a &#8220;pure&#8221; vector (i.e. three dimensional, but potentially complex valued). This is a fully general but rather inconvenient form of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_45.gif" alt="" width="7" height="12" />; fortunately, one can prove that any such <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_46.gif" alt="" width="7" height="12" /> can be expressed as a product of an ordinary three-dimensional rotation <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_47.gif" alt="" width="40" height="24" /> and a boost <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_48.gif" alt="" width="34" height="24" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_49.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_50.gif" alt="" width="6" height="12" /> are real-valued vectors. To see that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_51.gif" alt="" width="40" height="24" /> results in an ordinary rotation of the vector part of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_52.gif" alt="" width="9" height="12" /> (where the magnitude of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_53.gif" alt="" width="8" height="12" /> specifies the angle and the direction of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_54.gif" alt="" width="8" height="12" /> defines the axis of rotation), consider</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_8.gif" alt="" width="460" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:8">(8)</a></td>
</tr>
</tbody>
</table>
<p>where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_Math_56.gif" alt="" width="60" height="15" /> is the decomposition of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_56.gif" alt="" width="7" height="12" /> into components parallel and perpendicular to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_57.gif" alt="" width="8" height="12" />, respectively. Note that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_Math_59.gif" alt="" width="37" height="19" /> commutes with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_60.gif" alt="" width="8" height="12" /> (and any function thereof); consequently, it remains unchanged by this transformation. On the other hand, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_59.gif" alt="" width="14" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_60.gif" alt="" width="8" height="12" /> anticommute (i.e. <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_61.gif" alt="" width="94" height="12" />), implying</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_9.gif" alt="" width="172" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:9">(9)</a></td>
</tr>
</tbody>
</table>
<p>and, consequently, the rest of (<a href="#Eq:8">8</a>). One can thus see that this transformation leaves the scalar part of a 4-vector intact, and rotates the vector part using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_62.gif" alt="" width="8" height="14" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_63.gif" alt="" width="7" height="12" /> as the axis and angle of rotation (of the old frame, with respect to the new one), respectively.</p>
<p>Similarly, using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_64.gif" alt="" width="55" height="24" />, we get</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_10.gif" alt="" width="533" height="33" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:10">(10)</a></td>
</tr>
</tbody>
</table>
<p>Here, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_65.gif" alt="" width="6" height="12" /> can be replaced by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_66.gif" alt="" width="50" height="15" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_67.gif" alt="" width="6" height="15" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_68.gif" alt="" width="45" height="12" /> represent the unit direction and the magnitude of a three-dimensional vector (a velocity of the old frame with respect to the new one), respectively. This leads to the following simplified (and physically more meaningful) result of such a boost, applied to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_69.gif" alt="" width="9" height="12" />:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_11.gif" alt="" width="146" height="48" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:11">(11)</a></td>
</tr>
</tbody>
</table>
<h4>Electromagnetic Fields</h4>
<p>A 4-vector field of central significance is the electromagnetic potential <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_70.gif" alt="" width="31" height="12" />, where <img style="vertical-align: middle;" src="http://reference.wolfram.com/chars/CurlyPhi.gif" alt="" width="7" height="19" /> and each component of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_71.gif" alt="" width="9" height="12" /> are real-valued functions of a spacetime location (i.e. of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_72.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_73.gif" alt="" width="6" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_74.gif" alt="" width="5" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_75.gif" alt="" width="4" height="12" />). Now comes an important point: within the current framework, it is physically meaningless to multiply two 4-vectors (we would not know how to transform such a product from one inertial frame to another), but it is possible to multiply a <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_76.gif" alt="" width="13" height="12" />-vector by a 4-vector, creating what we call a mixed vector. It is thus quite legitimate to do</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_12.gif" alt="" width="261" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:12">(12)</a></td>
</tr>
</tbody>
</table>
<p>creating a mixed vector, which has its own new way of transforming (shown shortly).</p>
<p>To physically interpret the right-hand side of (<a href="#Eq:12">12</a>), we first impose the so-called Lorenz condition (often misattributed to the more famous Lorentz) of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_77.gif" alt="" width="75" height="12" /> (we prove shortly that this condition is frame invariant), and identify <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_78.gif" alt="" width="91" height="12" /> with <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_79.gif" alt="" width="42" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_80.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_81.gif" alt="" width="8" height="12" /> are the resulting (real-valued) electric and magnetic fields, respectively.</p>
<p>One can now show rather easily that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_82.gif" alt="" width="61" height="24" /> will simply rotate the two fields. On the other hand, a boost <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_83.gif" alt="" width="55" height="24" /> results in</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/05/Vrbik_Relativistic_DisplayFormulaNumbered_13.gif" alt="" width="242" height="99" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:13">(13)</a></td>
</tr>
</tbody>
</table>
<p>since transforming a mixed vector <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_84.gif" alt="" width="9" height="12" /> is done by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_85.gif" alt="" width="84" height="12" />. In both cases (rotation and boost), the scalar part remains equal to zero, thus proving invariance of the Lorenz condition.</p>
<p>Unlike 4-vectors, mixed vectors can be multiplied, yielding a new mixed vector (in terms of its transformation properties). Thus, for example,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_14.gif" alt="" width="263" height="18" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:14">(14)</a></td>
</tr>
</tbody>
</table>
<p>tells us that both <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_86.gif" alt="" width="40" height="15" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_87.gif" alt="" width="23" height="12" /> are invariant scalar fields.</p>
<p>Similarly, multiplying a 4-vector by a mixed vector returns a 4-vector; for example,</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_15.gif" alt="" width="363" height="12" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:15">(15)</a></td>
</tr>
</tbody>
</table>
<p>This time, the result must equal the charge/current density (yet another basic 4-vector of the theory); this results in a compact, Dirac-algebra formulation of the usual Maxwell equations. As an example, the following program computes the electromagnetic field of a point-like massive particle of a unit charge, moving at a uniform speed <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_88.gif" alt="" width="5" height="12" /> along the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_89.gif" alt="" width="5" height="12" /> axis; it also verifies that the result satisfies Maxwell&#8217;s equations.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_7.gif" alt="" width="464" height="68" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_7.gif" alt="" width="580" height="48" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_8.gif" alt="" width="354" height="18" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_8.gif" alt="" width="89" height="12" /></p>
<h3>Dynamics of a Point-Like Charged Particle</h3>
<p>We choose units in which both the rest mass and the charge of the particle equal 1. Its instantaneous location is denoted <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_90.gif" alt="" width="48" height="12" />, where the three components of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_91.gif" alt="" width="5" height="12" /> are functions of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_92.gif" alt="" width="4" height="12" />. To make the subsequent equations frame independent (having the same form in all inertial frames), we now need to introduce the particle&#8217;s so-called proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_93.gif" alt="" width="6" height="12" /> by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_16.gif" alt="" width="102" height="50" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:16">(16)</a></td>
</tr>
</tbody>
</table>
<p>We already know that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_94.gif" alt="" width="38" height="12" /> transforms as a 4-vector; <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_95.gif" alt="" width="183" height="18" />, thus <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_96.gif" alt="" width="49" height="15" /> and, consequently, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_97.gif" alt="" width="57" height="24" /> are relativistically invariant (the dot over <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_98.gif" alt="" width="5" height="12" /> implies differentiation with respect to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_99.gif" alt="" width="4" height="12" />). Proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_100.gif" alt="" width="6" height="12" /> is then computed by the corresponding integral, namely</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_17.gif" alt="" width="92" height="31" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:17">(17)</a></td>
</tr>
</tbody>
</table>
<p>which, being a &#8220;sum&#8221; of invariant quantities, is an invariant scalar as well. This implies that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_18.gif" alt="" width="169" height="48" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:18">(18)</a></td>
</tr>
</tbody>
</table>
<p>transforms as a 4-vector (we call it the 4-momentum of the moving particle).</p>
<p>The motion of the charged particle in a given electromagnetic field can now be established by solving</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_19.gif" alt="" width="130" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:19">(19)</a></td>
</tr>
</tbody>
</table>
<p>where the right-hand side is the so-called Lorentz force, and &#8220;<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_101.gif" alt="" width="13" height="12" />&#8221; takes the real part of its argument (also a 4-vector). Note that &#8220;<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_102.gif" alt="" width="13" height="12" />&#8221; applied to a 4-vector remains a 4-vector (since the complex conjugate of a 4-vector transforms as a 4-vector, as one can readily verify).</p>
<p>Based on (<a href="#Eq:18">18</a>), the right-hand side of (<a href="#Eq:19">19</a>) equals</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_20.gif" alt="" width="118" height="48" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:20">(20)</a></td>
</tr>
</tbody>
</table>
<p>For a particle with a negative unit charge, the sign of this 4-vector would be reversed.</p>
<p>One way of solving the resulting 4-vector equation is to expand the left-hand side of (<a href="#Eq:19">19</a>):</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_21.gif" alt="" width="331" height="47" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:21">(21)</a></td>
</tr>
</tbody>
</table>
<p>which has to equal (20). Canceling the scalar factor of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_103.gif" alt="" width="37" height="29" />, we get</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_22.gif" alt="" width="255" height="44" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:22">(22)</a></td>
</tr>
</tbody>
</table>
<p>Finally, the first (scalar part) of these four equations can be obtained by taking the dot product of the remaining three equations (the vector part) and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_104.gif" alt="" width="5" height="14" />, and is therefore redundant. All we need to solve in the end is</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_23.gif" alt="" width="145" height="44" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:23">(23)</a></td>
</tr>
</tbody>
</table>
<p>or, equivalently (by solving for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_105.gif" alt="" width="5" height="15" />),</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_24.gif" alt="" width="163" height="24" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:24">(24)</a></td>
</tr>
</tbody>
</table>
<p>the correctness of which can be easily verified by substituting this <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_106.gif" alt="" width="5" height="15" /> into the left-hand side of (<a href="#Eq:23">23</a>) and obtaining the right-hand side. These equations can, in general, be solved only numerically. The resulting <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_107.gif" alt="" width="5" height="12" /> will be a three-component function of a frame-dependent time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_108.gif" alt="" width="4" height="12" /> (proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_109.gif" alt="" width="6" height="12" /> was used only as an intermediate tool to assure agreement between inertial frames of reference; our solution remains correct in any other such frame, after the corresponding transformation). The following program finds the motion of a negatively charged particle (chosen because an attractive force makes the resulting path somehow more interesting, compared to the same-charge repulsion) in the field of the previous section.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_9.gif" alt="" width="580" height="115" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_9.gif" alt="" width="400" height="310" /></p>
<p>The originally stationary unit-mass particle has been &#8220;captured&#8221; by the moving massive particle (which is assumed to be so heavy that its own motion remains unaffected), and will continue orbiting it (while following its uniform motion). It is important to realize that this formulation of the problem has ignored the fact that a moving particle generates (and radiates) an electromagnetic field of its own, which would further modify its motion. More importantly, we also know that, at an atomic level, the world is governed by quantum mechanics, ultimately resulting in a totally different description of an orbiting particle. This is the reason why the last solution is only of mathematical interest. Under a wide range of initial conditions, the light particle would be drawn to collide with the heavy one.</p>
<h4>Motion in a Constant Electromagnetic Field</h4>
<p>Things become easier when <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_110.gif" alt="" width="8" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_111.gif" alt="" width="8" height="12" /> are both constant fields (in space and time). One can then express <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_112.gif" alt="" width="7" height="12" /> as <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_113.gif" alt="" width="62" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_114.gif" alt="" width="13" height="12" /> is the initial value of the particle&#8217;s 4-momentum, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_115.gif" alt="" width="8" height="12" /> is a spinor analogous to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_116.gif" alt="" width="7" height="12" /> that (instead of transforming 4-vectors between inertial frames) advances <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_117.gif" alt="" width="7" height="12" /> to its current location. This time we find it more convenient to make both <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_118.gif" alt="" width="7" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_119.gif" alt="" width="8" height="12" /> functions of proper time <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_120.gif" alt="" width="6" height="12" />. Also, one must not forget to meet the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_121.gif" alt="" width="67" height="12" /> condition, which is then automatically maintained by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_122.gif" alt="" width="7" height="12" /> at all future times.</p>
<p>Expanding the right-hand side of (<a href="#Eq:19">19</a>) yields</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_25.gif" alt="" width="480" height="32" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:25">(25)</a></td>
</tr>
</tbody>
</table>
<p>This should equal the left-hand side of (<a href="#Eq:19">19</a>), namely</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_26.gif" alt="" width="163" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:26">(26)</a></td>
</tr>
</tbody>
</table>
<p>which implies that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_27.gif" alt="" width="117" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:27">(27)</a></td>
</tr>
</tbody>
</table>
<p>having the obvious solution</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_DisplayFormulaNumbered_28.gif" alt="" width="105" height="30" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq:29">(28)</a></td>
</tr>
</tbody>
</table>
<p>a function of a mixed vector transforms as a mixed vector. After computing <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_123.gif" alt="" width="8" height="12" /> and, consequently, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_124.gif" alt="" width="62" height="12" />, all we need to do is to integrate this last expression in terms of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_125.gif" alt="" width="6" height="12" /> to get a solution for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Math_126.gif" alt="" width="24" height="12" />. A simple example follows.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_10.gif" alt="" width="580" height="43" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_10.gif" alt="" width="580" height="88" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Input_11.gif" alt="" width="239" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Vrbik_Relativistic_Output_11.gif" alt="" width="450" height="205" /></p>
<p>In this example, we have been able to obtain an explicit analytic solution.</p>
<p>In most textbooks (e.g., [<a href="#Goldstein">1</a>], [<a href="#Jackson">2</a>]), the treatment we have described is done using conventional tensor analysis, with covariant and contravariant vectors. It is always illuminating, however, to obtain the same results using a completely different approach, such as the one favored by Hestenes [<a href="#Hestenes">3</a>]. We have shown that <em>Mathematica</em> is capable of handling computations in any of several formalisms.</p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Goldstein">[1] </a></td>
<td>H. Goldstein, <em>Classical Mechanics</em>, 2nd ed., Reading, MA: Addison-Wesley Publishing Company, 1980.</td>
</tr>
<tr>
<td class="Reference"><a name="Jackson">[2] </a></td>
<td>J. D. Jackson, <em>Classical Electrodynamics</em>, New York: John Wiley, 1962.</td>
</tr>
<tr>
<td class="Reference"><a name="Hestenes">[3] </a></td>
<td>D. Hestenes, <em>New Foundations for Classical Mechanics</em>, 2nd ed., Dordrecht/Boston: Kluwer Academic Publishers, 1999.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">J. Vrbik, &#8220;Relativistic Motion of a Charged Particle and Pauli Algebra,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-10.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor"><strong>Jan Vrbik</strong><br />
<em>Department of Mathematics, Brock University<br />
500 Glenridge Ave., St. Catharines<br />
Ontario, Canada, L2S 3A1<br />
</em><em><a href="mailto:jvrbik@brocku.ca">jvrbik@brocku.ca</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/05/relativistic-motion-of-a-charged-particle-and-pauli-algebra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Integrals Involving Symmetric-Top Eigenfunctions</title>
		<link>http://www.mathematica-journal.com/2012/05/some-integrals-involving-symmetric-top-eigenfunctions/</link>
		<comments>http://www.mathematica-journal.com/2012/05/some-integrals-involving-symmetric-top-eigenfunctions/#comments</comments>
		<pubDate>Mon, 07 May 2012 15:16:32 +0000</pubDate>
		<dc:creator>Russell A. Bonham</dc:creator>
				<category><![CDATA[Volume 14]]></category>

		<guid isPermaLink="false">http://www.internal.mathematica-journal.com/?p=25706</guid>
		<description><![CDATA[Using closure over a complete set of rotational states for methane to evaluate the intensity for quasi-elastic electron scattering in the first Born approximation, a number of integrals were encountered that appear not to have been evaluated previously. Mathematica was employed to evaluate these and similar integrals, and it was discovered that in all the [...]]]></description>
			<content:encoded><![CDATA[<p>Using closure over a complete set of rotational states for methane to evaluate the intensity for quasi-elastic electron scattering in the first Born approximation, a number of integrals were encountered that appear not to have been evaluated previously. <em>Mathematica</em> was employed to evaluate these and similar integrals, and it was discovered that in all the cases studied the results could be represented by simple formulas.<span id="more-25706"></span></p>
<h3>Details of the Integral Evaluations</h3>
<p>The integrals discussed here are related to averages over the spherical matrix elements <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_1.gif" alt="" width="76" height="20" /> [<a href="#Brink-Satchler">1</a>, <a href="#Bonham">2</a>] defined by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_1.gif" alt="" width="221" height="20" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.1">(1)</a></td>
</tr>
</tbody>
</table>
<p>which are symmetric-top eigenfunctions with eigenvalues <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_2.gif" alt="" width="38" height="12" /> and a degeneracy <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_3.gif" alt="" width="46" height="15" />. The function <span><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Image_2.gif" alt="" width="47" height="20" /></span> is defined [<a href="#Brink-Satchler">1</a>, <a href="#Bonham">2</a>] as</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_2.gif" alt="" width="510" height="46" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.2">(2)</a></td>
</tr>
</tbody>
</table>
<p>where the sum is over all integer values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_4.gif" alt="" width="4" height="12" /> from 0 to the first negative factorial that occurs in the denominator. In the impulse approximation for quasi-elastic electron scattering [<a href="#Watson-Phys">3</a>], averages over the rotational motion of a spherical top molecule such as methane are integrals of the following form:</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_3.gif" alt="" width="280" height="32" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.3">(3)</a></td>
</tr>
</tbody>
</table>
<p>where</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_4.gif" alt="" width="139" height="36" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.4">(4)</a></td>
</tr>
</tbody>
</table>
<p>is the Hamiltonian operator whose eigenfunctions are the Legendre polynomials <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_5.gif" alt="" width="27" height="12" /> with eigenvalues <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_6.gif" alt="" width="38" height="12" />. Equation (<a href="#Eq.4">4</a>) is also a part of the Hamiltonian for which the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_7.gif" alt="" width="78" height="20" /> are solutions, but the <span><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Image_4.gif" alt="" width="47" height="20" /></span> are not eigenfunctions of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_8.gif" alt="" width="10" height="12" />(<img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_9.gif" alt="" width="6" height="12" />). The occurrence of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_10.gif" alt="" width="10" height="12" /> arises in the treatment of the scattering problem in the impulse approximation [<a href="#Watson-Phys">3</a>]. By use of <em>Mathematica</em> it was possible to prove that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_5.gif" alt="" width="271" height="43" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.5">(5)</a></td>
</tr>
</tbody>
</table>
<p>where the normalization factor <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_11.gif" alt="" width="40" height="16" /> is given by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_6.gif" alt="" width="243" height="41" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.6">(6)</a></td>
</tr>
</tbody>
</table>
<p>for all values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_12.gif" alt="" width="16" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_13.gif" alt="" width="16" height="12" />. For integer <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_14.gif" alt="" width="26" height="12" /> the results are</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_7.gif" alt="" width="289" height="43" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.7">(7)</a></td>
</tr>
</tbody>
</table>
<p>where</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_8.gif" alt="" width="106" height="35" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.8">(8)</a></td>
</tr>
</tbody>
</table>
<p>The use of the word &#8220;prove&#8221; is based on the results from a <em>Mathematica</em> program. All of these expressions occur as ratios of positive integers and were found to be in exact agreement with the results on the right-hand sides in equation (<a href="#Eq.7">7</a>) for values of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_15.gif" alt="" width="6" height="12" /> from 0 through 18.</p>
<p>Note that the same result can be obtained for the case where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_16.gif" alt="" width="46" height="18" /> is replaced by <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_17.gif" alt="" width="19" height="15" /> if <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_18.gif" alt="" width="22" height="12" /> is replaced by</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_9.gif" alt="" width="91" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.9">(9)</a></td>
</tr>
</tbody>
</table>
<p>Except for the factor of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_19.gif" alt="" width="9" height="23" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_20.gif" alt="" width="44" height="18" /> and for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_21.gif" alt="" width="19" height="15" /> in the definitions of the <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_22.gif" alt="" width="24" height="12" />, the remaining parts are equivalent to the integrals</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_10.gif" alt="" width="156" height="35" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.10">(10)</a></td>
</tr>
</tbody>
</table>
<p>and</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_11.gif" alt="" width="125" height="34" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.11">(11)</a></td>
</tr>
</tbody>
</table>
<p>Further investigation using <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_23.gif" alt="" width="80" height="30" /> found the same result with</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_12.gif" alt="" width="117" height="35" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.12">(12)</a></td>
</tr>
</tbody>
</table>
<p>where it is noted that</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_13.gif" alt="" width="214" height="35" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.13">(13)</a></td>
</tr>
</tbody>
</table>
<p>Define the double sum over the integral</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_14.gif" alt="" width="333" height="43" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.14">(14)</a></td>
</tr>
</tbody>
</table>
<p>and</p>
<table class="DisplayFormulaNumbered">
<tbody>
<tr>
<td><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_DisplayFormulaNumbered_15.gif" alt="" width="250" height="32" /></td>
<td class="DisplayFormulaNumberedLabel"><a name="Eq.15">(15)</a></td>
</tr>
</tbody>
</table>
<p>These results suggest the conjecture that <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_24.gif" alt="" width="111" height="12" />, where <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_25.gif" alt="" width="14" height="12" /> is a constant. For <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_26.gif" alt="" width="42" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_27.gif" alt="" width="39" height="12" />, the constant factor <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_28.gif" alt="" width="14" height="12" /> was found to be <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_29.gif" alt="" width="9" height="23" /> for <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_30.gif" alt="" width="65" height="12" />, as shown in the next section.</p>
<h3>Implementation</h3>
<p>The function <tt>d</tt> is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_31.gif" alt="" width="47" height="20" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_1.gif" alt="" width="580" height="88" /></p>
<p>The functions <tt>d1</tt> and <tt>d2</tt> are the first and second derivatives of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_32.gif" alt="" width="47" height="20" /> with respect to <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_33.gif" alt="" width="6" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_2.gif" alt="" width="301" height="28" /></p>
<p>The function <tt>h</tt> is the result of the Hamiltonian <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_34.gif" alt="" width="10" height="12" /> operating on <tt>d</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_3.gif" alt="" width="453" height="12" /></p>
<p>Define the integral <tt>a</tt>.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_4.gif" alt="" width="517" height="12" /></p>
<p>The function <tt>int1</tt> is the integral in equation (<a href="#Eq.14">14</a>).</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_5.gif" alt="" width="580" height="28" /></p>
<p>The function <tt>int2</tt> is the normalization integral of the square of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_35.gif" alt="" width="47" height="20" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_6.gif" alt="" width="532" height="12" /></p>
<p>The function <tt>s</tt><img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_36.gif" alt="" width="1" height="12" /> is the sum of the ratios of the integrals <tt>int1</tt> and <tt>int2</tt> over <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_37.gif" alt="" width="16" height="12" /> and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_38.gif" alt="" width="16" height="12" />.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_7.gif" alt="" width="580" height="28" /></p>
<p>For various choices of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_39.gif" alt="" width="9" height="12" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_40.gif" alt="" width="6" height="12" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_41.gif" alt="" width="6" height="12" />, the table compares the exact evaluation of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_42.gif" alt="" width="40" height="12" /> (equation (<a href="#Eq.14">14</a>)) with the proposed result <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_43.gif" alt="" width="41" height="12" /> (equation (<a href="#Eq.15">15</a>)) and shows that the ratio of the two is a constant, which in this case is <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_44.gif" alt="" width="37" height="23" />. The evaluation of <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_45.gif" alt="" width="75" height="12" /> takes some time.</p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_8.gif" alt="" width="580" height="237" /></p>
<p class="input"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Input_9.gif" alt="" width="75" height="12" /></p>
<p class="output"><img src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Output_1.gif" alt="" width="178" height="449" /></p>
<h3>References</h3>
<table class="ReferenceTable">
<tbody>
<tr>
<td class="Reference"><a name="Brink-Satchler">[1] </a></td>
<td>D. M. Brink and G. R. Satchler, <em>Angular Momentum</em>, Oxford: Clarendon Press, 1979 pp. 21-25.</td>
</tr>
<tr>
<td class="Reference"><a name="Bonham">[2] </a></td>
<td>R. A. Bonham, G. Cooper, and A. P. Hitchcock, &#8220;Electron Compton-like Quasielastic Scattering from <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_46.gif" alt="" width="12" height="13" />, <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_47.gif" alt="" width="12" height="13" />, and <img style="vertical-align: middle;" src="http://www.mathematica-journal.com/data/uploads/2012/04/Bonham_Math_48.gif" alt="" width="15" height="12" />,&#8221; <em>Journal of Chemical Physics</em>, 130 144303, 2009.<br />
<a href="http://dx.doi.org/10.1063/1.3108490" target="blank">dx.doi.org/10.1063/1.3108490</a>.</td>
</tr>
<tr>
<td class="Reference"><a name="Watson-Phys">[3] </a></td>
<td>G. I. Watson, &#8220;Neutron Compton Scattering,&#8221; <em>Journal of Physics: Condensed Matter</em>, <strong>8</strong>(33) 5955, 1996. <a href="http://iopscience.iop.org/0953-8984/8/33/005" target="blank">iopscience.iop.org/0953-8984/8/33/005</a>.</td>
</tr>
<tr>
<td class="DOIReference" colspan="2">R. A. Bonham, &#8220;Some Integrals Involving Symmetric-Top Eigenfunctions,&#8221; <em>The Mathematica Journal</em>, 2012. dx.doi.org/doi:10.3888/tmj.14-12.</td>
</tr>
</tbody>
</table>
<h3 class="SectionAboutAuthor">About the Author</h3>
<p class="TextAboutAuthor">Russell A. Bonham received his Ph.D. in physical chemistry from Iowa State University in 1957. He is the author of more than 200 articles on all aspects of electron scattering from free atoms and molecules. He is currently a professor emeritus at Indiana University and an adjunct professor at the Illinois Institute of Technology.</p>
<p class="TextAboutAuthor"><strong>R. A. Bonham<br />
</strong><em>Department of Biological, Chemical, and Physical Sciences<br />
Illinois Institute of Technology<br />
3101 South Dearborn Street<br />
Chicago, IL 60616</em><br />
<em><a href="mailto:bonham@iit.edu">bonham@iit.edu</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mathematica-journal.com/2012/05/some-integrals-involving-symmetric-top-eigenfunctions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
