Published in "Computers and Geology -- 25 years of Progress"
Edited by John C. Davis and Ute C. Herzfeld
Oxford University Press, New York, 1993, Chapter 19, p.231-240

        (Copyright 1993 Oxford University Press.  Used by permission.)

          An Executable Notation, with Illustrations from Elementary
                                Crystallography

                               Donald B. McIntyre

                       Luachmhor, Church Road, Kinfauns,
                         Perth PH2  7LD, SCOTLAND, U.K.

                                    ABSTRACT

       Elementary crystallography is an ideal context for introducing
       students to mathematical geology.   Students meet crystallography
       early because rocks are made of crystalline minerals.   Moreover
       morphological crystallography is largely the study of lines and
       planes in real 3-dimensional space, and visualizing the
       relationships is excellent training for other aspects of geology;
       many algorithms learned in crystallography (e.g. rotation of
       arrays) apply also to structural geology and plate tectonics.

       Sets of lines and planes should be treated as entities, and
       crystallography is an ideal environment for introducing what
       Sylvester called "Universal Algebra or the Algebra of multiple
       quantity" (1884).   In modern terminology, we need SIMD (Single
       Instruction, Multiple Data) or even MIMD.   This approach,
       initiated by W.L. Bond in 1946, dispels the mysticism
       unnecessarily associated with Miller Indices and the reciprocal
       lattice;  edges and face-normals are vectors in the same space.


       A Simple, Consistent, Executable Notation:

       The growth of mathematical notation has been haphazard, new
       symbols often being introduced before the full significance of the
       functions they represent had been understood [Cajori, 1951;
       McIntyre, 1991b].   Iverson introduced a consistent notation in
       1960 [e.g. Iverson 1960, 1962, 1980].   His language, now greatly
       extended in the executable form called J [Iverson, 1993], is used
       here.   For information on its availability as Shareware see the
       Appendix.   Publications suitable as tutorials in J are available
       [e.g. Iverson, 1991;  McIntyre, 1991, 1992, 1993].


       Crystallographic Axes:

       Crystals are periodic structures consisting of unit cells
       (parallelepipeds) repeated by translation along axes parallel to
       the cell edges.   These edges define the crystallographic axes.
       In a crystal of cubic symmetry they are orthogonal and equal in
       length (Cartesian).   Those of a triclinic crystal, on the other
       hand, are unequal in length and not at right angles.   The
       triclinic system is the general case;  others are special cases.

       The formal description of a crystal gives prominent place to the
       lengths of the axes (a, b, and c) and the interaxial angles (, ,
       and GAMMA).  A canonical form groups these values into a 2 by 3
       table (matrix), the first row being the lengths and the second the
       angles.   For example, the canonical form of chalcanthite,

       CuSO4.5H2O, [J.D. Dana, 1951, Vol.2, p.489] is:
             <"0 chalcanthite=. 6.11 10.673 5.95,: 97.583 107.167 77.55

       Ŀ
       6.11  10.673 5.95 
       Ĵ
       97.583107.16777.55
       
             (;:'a b c'),: ;:'alpha beta gamma'
       Ŀ
       a    b   c    
       Ĵ
       alphabetagamma
       

       The corners of the unit cell are lattice points;  i.e. points with
       identical environments.   Further points are found by taking
       integer multiples of each axis and adding these in all
       combinations.   The resulting array is the direct lattice.   The
       axes can be referred to an imaginary Cartesian framework, x, y,
       and z, with its origin at a corner of the unit cell.   By
       convention the +x-axis is towards the observer, the +y-axis to the
       right, and the +z-axis vertically upwards.    In the 2-dimensional
       example of Figure 1, the coordinates of the lattice points are
       given with reference both to Cartesian reference axes, x and y
       (coordinates to the upper right) and to crystallographic axes, a
       and b (coordinates to the lower left).   The Cartesian coordinates
       of the crystallographic axes a and b are:
             a=. 1.75 0.5       and      b=. 0.25 2

       The lattice is therefore defined by a matrix;  the items (rows)
       refer to the axes, and the columns give Cartesian coordinates.   I
       call it the "d-matrix", because it describes the direct lattice as
       opposed to the reciprocal lattice of X-ray crystallographers.
       Bond was the first to point out the computational advantage of
       matrix methods in crystallography [Bond, 1946; Terpstra and Codd,
       1961; McIntyre, 1978].
             <"0 d=. a,:b
       Ŀ
       1.750.5
       Ĵ
       0.252  
       

       Points on the lattice rows that extend the crystallographic axes
       are given by integer multiples of a and b:
             ]p=. a*/i.4                   ]q=. b*/i.5
       0 1.75 3.5 5.25               0 0.25 0.5 0.75 1
       0  0.5   1  1.5               0    2   4    6 8

       The outer product of p and q give other lattice points:
             $p+/q
       2 4 2 5

       The shape of the outer product is 2 4 2 5 because p+/q not only
       adds x to x and y to y, but x to y and y to x.   A dyadic
       transpose takes a rank-3 cut through this rank-4 array to give the
       Cartesian coordinates of the lattice points:

             $x=. (<0 2):(a*/i.4)+/(b*/i.5)
       4 5 2
             x
          0   0
       0.25   2
        0.5   4
       0.75   6
          1   8
           etc

       The coordinates can also be computed using an inner product:
             ip=. +/ .*
             d ip~ 4 5#:i.20


       Vector Lengths and Angles:

       Because the norm (length) of a vector is the square root of the
       sum of squares of its components, the axial lengths are easily
       computed from the d-matrix:
          norm=. +/&.*:"1
          norm d
       1.82003 2.01556

       Dividing each axis by its norm we obtain the direction vectors:
          dv=. %"1 0 norm
          dv d
       0.961524 0.274721
       0.124035 0.992278

       Define the function angles to compute interaxial angles:

          ipt=. ip :        NB. inner product with transpose
          arcos=. _2&o.      NB. arcosine:  angle in radians
          real=. {."1@+.     NB. imaginary parts may come from rounding
          rfd=. %&180@o.     NB. radians from degrees
          dfr=. rfd^:_1      NB. degrees from radians (inverse of rfd)
          clean=. ] * (<:)  NB. set small values to zero
          angles=. 1e_6&clean@dfr@real@arcos@ipt@dv
          angles d
             0 66.9296
       66.9296       0

       The result gives the angles between each item (row) in the
       argument and every other item, though in this case there are only
       two items.   The angle between the crystallographic a-axis and the
       Cartesian x-axis is given by:
          dfr arcos 1 0 ip dv a
       15.9454


       Rotation to a Standard Setting:

       In the conventional setting, the lattice is rotated with respect
       to the Cartesian axes so that the a-axis is parallel to the x-axis
       (or lies in the x-z plane in 3-dimensions).   We achieve this with
       a rotation matrix of the form:

                 Ŀ
                 cos -sin
                 Ĵ
                 sin  cos
                 
          rot=. '(cos,-sin),:(''sin'';''cos'')=. 1 2 o. rfd y.' : ''
       or alternatively
          rot=. (1 _1,:1 1)&*@((2 1,:1 2)&o. @ rfd)

       A table of old and new coordinates is given by:
         6.2 6.2 8.2 6.2 ": x,"1 x ip rot 15.9454
         0.00  0.00    0.00  0.00
         0.25  2.00    0.79  1.85
         0.50  4.00    1.58  3.71
                    etc

       In the standard setting of a triclinic crystal the c-axis is
       oriented parallel to the vertical z-axis;  the crystal is then
       rotated about z until the a-axis lies in the x-z plane with +a
       towards the observer and the angle between +a and +z not less than
       90.   This fixes the position of the b-axis.


       Computing the d-matrix from the canonical form:

       Every crystal description should include the d-matrix;  but as
       this is rarely done, the function dmat is given here so that d-
       matrices can be computed from canonical forms.  Terpstra and Codd
       (1961) give the necessary spherical trigonometry.

          rfd=. %&180@o.      NB. Radians From Degrees
          sin=. 1&o.          NB. sine of angle in radians
          cos=. 2&o.          NB. cosine of angle in radians
          SinCos=. 1 2&o.     NB. sine and cosine

       Crystallographic axes (lengths) or interaxial angles:
          a=. 0&{
          b=. 1&{
          c=. 2&{
          ab=. a,b
          axisa=. 1 0 2&{@(0&,@SinCos@b)

       cos(rho) and cos(sigma) are based on Terpstra & Codd (1961) p.287
          CosRho=. (cos@c - */@cos@ab) % */@sin@b
          CosSigma=. sin@b %~ %:@(>:@+:@(*/@cos) - +/@*:@cos)
          axisb=. CosRho,CosSigma,cos@a

          dm=. ,&0 0 1 @(axisa,:axisb)@rfd@b
          dmat=. ({. *"0 1 dm) f.

       Test data:  chalcanthite from J.D. Dana Vol. 2 (1951) p.489,
       ch (chalcanthite) and anorthite from Terpstra (1961) p.290
          chalcanthite=. 6.11 10.673 5.95,: 97.583 107.167 77.55
          ch=. 0.5705 1 0.5565,: 82.367 107.433 102.55
          anorthite=. 0.6344 1 0.5505,:93.15 115.9833 91.2

       Note that dmat produces the d-matrix for any number of crystals
       simultaneously; e.g.

          dmat chalcanthite
       5.83779      0 _1.80341
       1.97316 10.394 _1.40843
             0      0     5.95

          dmat"2 chalcanthite, ch,: anorthite
       This expression computes the d-matrices for each crystal.


       Canonical from the d-matrix:
          canon=. norm,:5 2 1&{@,@angles

       This is the inverse of dmat:
          chalcanthite-: canon dmat chalcanthite
       1


       Volume of the Unit Cell:

       The determinant of the d-matrix is the area (2-dimensional) or
       volume (3-dimensional) of the unit cell:
          vol=. det=. -/ .*
          vol dmat chalcanthite
       361.035


       Cozonal Faces, and the Angles on a Cubic Crystal:

       It follows that the determinant can be used to determine whether
       three crystal faces are cozonal;  i.e. whether their normals are
       coplanar:
             det 1 2 2, 3 1 1,: 0 1 1
       0
             det 1 2 1, 3 1 1,: 0 1 1
       _3
       The faces in the first set are cozonal;  those in the second are
       not.

       Because the axes of a cubic crystal are already Cartesian, the
       function (verb) angles determines the angles between face normals:

          cubic=. 1 0 0,1 1 0,1 1 1,0 1 0,0 1 1,1 _1 1,: 3 1 2
          (3 ":cubic),"( 1) 8.2 ": 1e_4 clean angles cubic
         1  0  0    0.00   45.00   54.74   90.00   90.00   54.74   36.70
         1  1  0   45.00    0.00   35.26   45.00   60.00   90.00   40.89
         1  1  1   54.74   35.26    0.00   54.74   35.26   70.53   22.21
                        etc

       The angles from the front face of the cube to the other faces are
       given in degrees, minutes, and seconds by:
          4 ": cubic,"(1) 0 60 60 #: 60*60* 0{angles cubic
          1   0   0   0   0   0
          1   1   0  45   0   0
          1   1   1  54  44   8
                  etc


       The Direct Lattice:  Bond Lengths and Angles:

       The positions of atoms within the cell are given with respect to
       the axes of the direct lattice;  for example (0 0 0) is a corner
       and (0.5 0.5 0.5) the center of the cell, irrespective of cell
       size or shape.   Because edges have simple rational indices with
       respect to the direct lattice, calculations involving either edges
       or atomic positions are straightforward.

       Consider the tetragonal mineral Rutile (TiO2) [Bunn, 1961, p.226]
       with d-matrix:  d=. 4.58 0 0,0 4.58 0,:0 0 2.98.   A titanium at
       (0.5 0.5 0.5) is surrounded by six oxygens, with  coordinates:
          O=. 0.31 0.31 0, 0.69 0.69 0,: 0.81 0.19 0.5
          O=. O, 0.19 0.81 0.5, 0.31 0.31 1,: 0.69 0.69 1

       To find the Ti-O bond lengths, move the origin to the central
       titanium, and convert to Cartesian coordinates.
         6.2": O,"1 0 norm x=. (O-0.5) ip d
         0.31  0.31  0.00  1.93
         0.69  0.69  0.00  1.93
         0.81  0.19  0.50  2.01
                 etc

       Angles between bonds radiating from the titanium are given by:
          BondAngles=. 9.2&":@angles@dv
          BondAngles x
            0.00    79.11    90.00    90.00   100.89   180.00
                 etc


       The Reciprocal Lattice:

       The axes of the reciprocal lattice are normal to the faces of the
       unit cell, and their lengths are the reciprocals of the spacings
       of planes in the set;  i.e.  the distances between a face on one
       side of the unit cell and the corresponding face on the other
       side.   Because they  determine whether X-rays of given wave-
       length will be reflected, these distances (d-spacings) are
       important in X-ray Crystallography.

       In the direct lattice, edges are vectors whose coordinates are
       simple rational numbers, whereas in the reciprocal lattice face-
       normals are vectors whose coordinates are the Miller Indices.
       Consequently problems formerly requiring considerable ingenuity
       and skill in spherical trigonometry can now be solved by simple
       matrix methods.

       The d-matrix of chalcanthite [data from Berry and Mason, 1959,
       p.435], is:
        d=. 5.84927 0 _1.80693, 1.97722 10.4155 _1.41139,: 0 0 5.96

       The reciprocal lattice is defined by a corresponding matrix (the
       r-matrix) which gives the coordinates of the axes (a*, b*, c*) of
       the reciprocal lattice with respect to the Cartesian frame.   The
       r-matrix is simply the transpose of the inverse of the d-matrix, a
       relationship worth exploring, but space does not allow further
       elaboration here.

       For chalcanthite (Berry and Mason's data), we have:
             <"0 r=.  1e_10 clean : %. d

                       x         y        z
                   Ŀ
               a*  0.170962 _0.03245450       
                   Ĵ
               b*  0        0.0960112 0       
                   Ĵ
               c*  0.05183140.0128971 0.167785
                   

       Because the axes are expressed with reference to a Cartesian
       frame, their lengths and interaxial angles are obtained as they
       were for the d-matrix:
          canon r
       0.174015 0.0960108 0.176082
        85.7997   74.0061  100.749


       Interfacial Angles

       Berry and Mason give some of the angles between the following
       faces:
          m=. 1 0 0, 1 _1 0, _1 _1 1, 0 1 0, 1 1 0,: 1 3 0

       Because the inner product of Miller Indices and the r-matrix
       converts the face-normals to a Cartesian frame, all these angles
       are easily computed:
          (3 3 3,6#9.2)":m,"(1) angles m ip r
         1  0  0     0.00    26.17   120.51   100.75    31.14    66.97
                             etc


       Computation of d-spacing in a Triclinic Crystal:

       The high symmetry of cubic crystals makes computation of the
       spacings of crystal planes easy, but the calculations become more
       difficult with decreasing symmetry.   As Bunn pointed out,  "For
       monoclinic and triclinic cells, the formulae for the spacings are
       very unwieldy.   Graphical methods based on the conception of the
       reciprocal lattice are recommended"  (Bunn, 1945, p.378; 1961,
       p.456).

       This difficulty vanishes when we follow Bond in recognizing Miller
       Indices as defining true vectors in the reciprocal lattice.   The
       Miller Indices are converted to Cartesian by taking the inner
       product with the r-matrix, and calculation of lengths and angles
       is then trivial.

       As an example consider chalcanthite.   The Joint Committee on X-
       ray Powder Diffraction Standards uses a different cell (JCPDS 11-
       646) from that given by Dana.   Computing the r-matrix from the
       JCPDS data:
           r=. : %. dmat 7.155 10.71 5.955,: 97.63 125.32 94.32

       JCPDS give the first 11 lines of the diffraction pattern as:
           hkl=. 0 1 0,1 0 0,1 0 _1,1 _1 0,0 2 0,1 1 _1,1 _1 _1,0 1 _1,
                 0 0 1,1 1 0,:1 _2 0

       The d-spacings of these planes are then:


          3 3 3 8.2 ": hkl,"1 0 % norm hkl ip r
         0  1  0   10.43
         1  0  0    5.73
         1  0 _1    5.67
               etc


       Transformation of Settings:

       When crystals have low symmetry (monoclinic and triclinic)
       authorities often differ in their choice of unit cell.   The
       determinants of the various d-matrices make it possible to compare
       the cell volumes.  Transformation matrices make it simple to
       convert Miller Indices from one setting to another.   Moreover, if
       a face has the same Indices in two settings, its normal must be an
       eigenvector of the transformation matrix.   Space does not allow
       examples here.


       Conclusions:

       Despite the advantages of Bond's matrix methods, textbooks
       continue to give only the canonical form:  axial lengths and
       interaxial angles.   This is unfortunate, because it is easier to
       go from the d-matrix to canonical form than to go in the opposite
       direction.   Starting with the d-matrix, we can use matrix methods
       immediately;  whereas if we begin with the canonical form, we must
       use algorithms derived from spherical trigonometry.

       In the review of a mineralogy textbook, Derek Flinn (1972) wrote:

           "I believe that the mystical approach to Miller Indices should
           be abandoned and that the student should be told that they are
           face-normal vectors, that they belong to the same vector space
           as the zone axis indices and that the addition and
           multiplication of these indices are elementary operations in
           vector algebra."

       Quoting this 15 years ago, I said "Flinn is correct, and I can
       testify that APL makes what he recommends easy and natural"
       (McIntyre, 1978, p.250).   Today J provides further testimony.

       In his 1977 Turing Award paper, John Backus (1978) advocated a new
       functional style of programming.   I have show here how this style
       has been achieved in a consistent executable notation in which
       there is no explicit reference to function arguments [Hui et al,
       1991].


       ACKNOWLEDGEMENTS:

       Kenneth Iverson, Roger Hui, and E.E. McDonnell went out of their
       way to tutor me in J, but they are not responsible for any
       stylistic failures in the use of their language.

       I am indebted to many students who took my Crystallography class
       at Pomona College, and in particular to George Clark '46,  Donald
       McIsaac '59, James Kelley '63, Steve Norwick '65, David Pollard
       '65,  Jim Kauahikaua '73, Paul Delaney '73, Allen Glazner '76, Tom
       Hoisch '79,  and Peter Christiansen '87, for their special
       interest and stimulation.   My colleague Paul Yale, Mathematics
       Department, gave suggestions and encouragement over many years.
       Through the support of the Mellon Foundation, Don L. Orth, IBM,
       audited my class at a critical time 17 years ago when we had newly
       adopted Iverson's system of Direct Definition, then implemented on
       one of IBM's earliest desktop computers.


       References:

       Backus, John, 1978, Can programming be liberated from the Von
       Neumann style?   A functional style and its algebra of programs,
       1977 Turing Award Lecture.  Comm. of the ACM, v. 21, number 8, p.
       613-641.

       Berry, L.G. and Mason, Brian, 1959, Mineralogy, W.H. Freeman and
       Co., San Francisco  612 pp.

       Bond, W.L., 1946, Computation of interfacial angles, interzonal
       angles, and clinographic projection  by matrix methods, American
       Mineralogist, v. 31, pp.31-42.

       Bunn, C.W., 1945, Chemical Crystallography, Oxford University
       Press, New York, [2nd Edition (1961).   Appendix 2, "The spacings
       of crystal planes"], 422 pp.

       Cajori, Florian, 1951, A History of Mathematical Notations, The
       Open Court Publishing Company, La Salle, Illinois. Vol. 1: [First
       published 1928.] 451 pp.   Volume 2 (1952) 367pp.  First published
       1929.

       Cajori, Florian, 1952, A History of Mathematical Notations, The
       Open Court Publishing Company, La Salle, Illinois. Vol. 2: [First
       published 1929.] 367 pp.

       Dana, J.D., 1951, The System of Mineralogy, Vol. 2: [7th Ed.] John
       Wiley & Sons, New York, 1124 pp.

       Flinn, Derek, 1972, Review of M.H. Battey's "Mineralogy for
       Students", Geological Journal, v. 8 (April), p. v-vi.

       Hui, R.K.W., Iverson, K.E., and McDonnell, E.E., 1991, Tacit
       Definition, APL Quote Quad, v.21, no.4, Assoc. Computing Machinery
       Press, p.202-211.

       Iverson, K.E., 1960, The Description of Finite Sequential
       Processes, in Cherry, Colin, and Jackson, Willis (eds),
       Proceedings of a Conference on Information Theory, Imperial
       College, London, August 1960, p.447-457.

       Iverson, K.E., 1962,  A Programming Language: John Wiley & Sons,
       New York, 286 pp.

       Iverson, K.E., 1980, Notation as a tool of thought, [1979 Turing
       Award Paper]:  Comm. of the A.C.M., v.23, no. 8, p.444-465.

       Iverson, K.E., 1991, Programming in J, Iverson Software Inc.,
       Toronto, 72 pp.

       Iverson, K.E., 1993, J: Introduction and Dictionary, Version 6.2,
       Iverson Software Inc., Toronto, 105 pp.

       McIntyre, D.B., 1978, The Architectural Elegance of Crystals made
       clear by APL:  Proceedings of an APL Users' Meeting, Toronto,
       September 1978,  (1978) Sponsored by I.P. Sharp Associates Ltd.,
       p. 233-250.

       McIntyre, D.B., 1991a, Mastering J:  APL Quote Quad, v. 21, no. 4,
       Assoc. Computing Machinery Press, p.264-273.

       McIntyre, D.B., 1991b, Language as an Intellectual Tool:  From
       hieroglyphics to APL, IBM Systems Journal, v. 30, no. 4, p. 554-
       581.

       McIntyre, D.B., 1992a, Hooks and Forks and the Teaching of
       Elementary Arithmetic, Vector, v. 8, no. 3, p. 101-123.

       McIntyre, D.B., 1992b, Using J with External Data: Two Examples,
       Vector, v. 8, no. 4, p. 97-110.

       McIntyre, D.B., 1992c, Using J's Boxed Arrays, Vector, v. 9, no.
       1, p. 92-105.

       McIntyre, D.B., 1993, Jacobi's method for Eigenvalues: an
       Illustration of J, Vector, v.9, no.3 p. 125-133.

       Terpstra, P., & Codd, L.W., 1961, Crystallometry, Academic Press,
       New York, 420 pp., Chapter 8.


                                    APPENDIX

       For a summary of the notation see Hui [Hui and others, 1991].
       For a complete description see Iverson [Iverson, 1993].   The
       words used as J symbols are spelled as single ASCII characters
       either alone or immediately followed by a period or colon.

       J is available as Shareware for most computers from Iverson
       Software Inc., 33 Major Street, Toronto, Ontario, Canada M5S  2K9.
       The examples given in this paper were revised to execute with
       Version 6.1 (November 1992).

       The J system for IBM compatible machines, and script files of
       tutorial material, including executable versions of all examples
       in this paper, are available on the J Conference maintained by
       ALMAC BBS Ltd., 141 Bo'ness Road, Grangemouth FK3 9BF, Scotland.
       For access telephone +44 (0) 324-665-371, complete the two online
       questionaires, and join the J conference by entering  J J


       FIGURE:

       A 2-dimensional example showing lattice points.   Coordinates  are
       given with reference both to Cartesian reference axes, x and y
       (coordinates are on the upper right) and to crystallographic axes,
       a and b (coordinates are on the lower left).


       FOOTNOTE:


       Donald B. McIntyre is Emeritus Professor, Pomona College, and Honorary
       Fellow at the Universities of St. Andrews and Edinburgh.


       KEY WORDS:

       crystallography mineralogy teaching lattice notation language J
