<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="stepper_quadratic.xsl"?>

<doc
  xmlns:m="http://www.w3.org/1998/Math/MathML"
  xmlns:s="http://flemingcnc.com/namespace/substitute"
  xmlns="http://www.w3.org/1999/xhtml">

    <html>
        <head><title>Driving Stepper Motors with Quadratic Equations</title></head>
        <body>
            <h1>Driving Stepper Motors with Quadratic Equations</h1>
            
            <p>Copyright 2002 Todd Fleming</p>
            
            <table>
                <tr><td colspan='2' style="border: black solid thin">Revision History</td></tr>
                <tr><td style="border: black solid thin">23-Dec-2002</td><td style="border: black solid thin">Initial Release</td></tr>
            </table>
            
            <h2>Introduction</h2>
            
            <p>This paper describes a technique for controlling stepper motors using 
            quadratic equations that are evaluated in real time without using multipliers.
            Digital stepper motor controllers can use this technique to generate
            smooth acceleration. It is an application of Dr. Jack Bresenham's work, which 
            I unfortunately don't have a reference for.</p>
            
            <h2>1. Rational Derivation</h2>
               
            <p>Let's declare a function, <m:math><s:x-at-t/></m:math>, which describes our 
            motor's target position at any time t. We would like a function that
            gives us a constant acceleration over its entire range. From Calculus, we know that 
            quadratics fill this need, thus we have 
            <m:math><s:x-eq/></m:math>, where <m:math><m:ci>a</m:ci></m:math>, 
            <m:math><m:ci>b</m:ci></m:math>, and <m:math><m:ci>c</m:ci></m:math> are constants.</p>

            <p>Let's figure out how to compute <m:math><m:ci>a</m:ci></m:math>, 
            <m:math><m:ci>b</m:ci></m:math>, and <m:math><m:ci>c</m:ci></m:math>. 
            To simplify derivation, let's set our reference
            point such that <m:math><m:apply><m:eq/><s:x-at-0/><m:cn>0</m:cn></m:apply></m:math>;
            thus <m:math><m:apply><m:eq/><m:ci>c</m:ci><m:cn>0</m:cn></m:apply></m:math>. Let's
            set the slope of <m:math><m:ci>x</m:ci></m:math> at time 0 to
            <m:math><s:slope-at-0/></m:math>, where <m:math><s:delta-x-at-0/></m:math> is an
            integer and <m:math><s:delta-t-at-0/></m:math> is a positive 
            integer. Let's also set the slope at some integer
            time <m:math><m:apply><m:gt/><m:ci>n</m:ci><m:cn>0</m:cn></m:apply></m:math> 
            to <m:math><s:slope-at-n/></m:math>, where
            <m:math><s:delta-x-at-n/></m:math> is an integer and 
            <m:math><s:delta-t-at-n/></m:math> is a positive integer. We know that the slope, 
            <m:math><s:s-at-t/></m:math>, of <m:math><s:x-at-t/></m:math> is 
            <m:math><s:slope-at-t-formula/></m:math>, thus
            <m:math><s:slope-at-0-eq/></m:math>. Given <m:math><s:slope-at-n-eq/></m:math>,
            it follows that <m:math><s:a-eq/></m:math>. The motor's acceleration will
            be <m:math><s:acceleration/></m:math>.</p>
            
            <p>Now that we have a formula, we need to consider how we can use it for controlling
            steppers. Stepper positions are discrete; the shaft of an ideal stepper can be positioned
            on a finite number of evenly spaced spots. In addition, clocked digital logic can only
            change the stepper's position at discrete points in time. Let's scale our function so 
            that integer values of <m:math><m:ci>t</m:ci></m:math> map to discrete time steps and 
            integer values of <m:math><m:ci>x</m:ci></m:math> map to discrete stepper positions.
            We need to design logic that causes the stepper's shaft to move to the integer position 
            closest to <m:math><m:ci>x</m:ci></m:math> at every integer time <m:math><m:ci>t</m:ci></m:math>.</p>
            
            <p>Let's restrict our stepper motor to move at most 1 position per time step. This fits
            well with most drivers since they accept a single-bit step input. Let's also restrict 
            <m:math><s:x-at-t/></m:math> such that it is non-negative and non-decreasing over the interval 
            <m:math><m:interval><m:cn>0</m:cn><m:ci>n</m:ci></m:interval></m:math>; 
            the motor direction will be constant while it is following a given quadratic. We declare two functions,
            <m:math><s:d-at-t/></m:math> and <m:math><s:e-at-t/></m:math>, defined at integer values of
            <m:math><m:ci>t</m:ci></m:math>. <m:math><s:d-at-t/></m:math> is the final distance between
            <m:math><m:ci>x</m:ci></m:math> and the stepper position <em>after</em> the controller has decided
            whether to step the motor at time <m:math><m:ci>t</m:ci></m:math> or not.
            <m:math><s:d-at-0-eq/></m:math>. <m:math><s:e-at-t/></m:math> is the distance between 
            <m:math><m:ci>x</m:ci></m:math> and the stepper position immediately <em>before</em> the 
            controller has decided whether to step the motor or not.</p>
            
            <p><m:math><s:e-eq-1/></m:math></p>
            <p><m:math><s:e-eq-2/></m:math></p>
            <p><m:math><s:e-eq-3/></m:math></p>

            <p>Since we want to minimize the distance between the stepper position and the quadratic after 
            each time step, we place the following restrictions on <m:math><s:d-at-t/></m:math>:
            <m:math><s:d-at-t-restriction-1/></m:math> and <m:math><s:d-at-t-restriction-2/></m:math>.
            If <m:math><s:e-at-t-plus-1-condition-1/></m:math> then <m:math><s:d-at-t-plus-1/></m:math> and
            <m:math><s:e-at-t-plus-1/></m:math> are the same and we don't need to step the motor. Otherwise,
            <m:math><s:d-eq-1/></m:math> and we need to step the motor.</p>
            
            <p><m:math><s:d-eq-2/></m:math></p>
            
            <p>Let's transform the condition <m:math><s:e-at-t-plus-1-condition-1/></m:math> to 
            <m:math><s:e-at-t-plus-1-condition-2/></m:math>. If we apply previous results we get the following.</p>
            
            <p><m:math><s:e-at-t-plus-1-condition-3/></m:math></p>
            <p><m:math><s:e-at-t-plus-1-condition-4/></m:math></p>
            
            <p>All of these divisions in the above equation run counter to our goal of using integer 
            arithmetic. We can eliminate them by multiplying both sides of the above inequality by
            <m:math><s:multiplier/></m:math>. This leads us to declare a new function, 
            <m:math><s:g-at-t/></m:math>, with the definition <m:math><s:g-at-t-eq-1/></m:math>.
            We can then apply previous results to get the following.</p>
            
            <p><m:math><s:g-at-t-plus-1-eq-1/></m:math></p>
            <p><m:math><s:g-at-t-plus-1-eq-2/></m:math></p>
            <p><m:math><s:g-at-t-plus-1-eq-3/></m:math></p>
            
            <p>We can simplify this last equation if we define three constants, <m:math><s:C1/></m:math>,
            <m:math><s:C2/></m:math>, and <m:math><s:C3/></m:math>:</p>
            
            <p><m:math><s:C1-eq/></m:math></p>
            <p><m:math><s:C2-eq/></m:math></p>
            <p><m:math><s:C3-eq/></m:math></p>
            
            <p>This leads us to</p>
            
            <p><m:math><s:g-at-t-plus-1-eq-4/></m:math></p>
            
            <p>Let's define yet another function, <m:math><s:f-at-t/></m:math>, such that
            <m:math><s:f-at-t-eq-1/></m:math>. We now have our final equation for
            <m:math><m:ci>g</m:ci></m:math>: <m:math><s:g-at-t-plus-1-eq-5/></m:math>.</p>
            
            <p>Let us turn our attention back to <m:math><m:ci>d</m:ci></m:math>. We have the following
            equation repeated from above:</p>

            <p><m:math><s:d-eq-2/></m:math></p>
            
            <p>If we multiply both sides by our magical expression <m:math><s:multiplier-2/></m:math>,
            we get:</p>
            
            <p><m:math><s:f-at-t-plus-1-eq-1/></m:math></p>
            
            <p>If we look at <m:math><s:g-at-t-eq-1/></m:math>, we'll notice that
            <m:math><s:e-at-t-eq/></m:math>. This leads to our final equation for
            <m:math><m:ci>f</m:ci></m:math>.</p>
            
            <p><m:math><s:f-at-t-plus-1-eq-2/></m:math></p>
            
            <h3>2.1. Rational Summary</h3>
            
            <p>The initial and final speeds are given by <m:math><s:slope-at-0/></m:math> and
            <m:math><s:slope-at-n/></m:math> respectively, where <m:math><s:delta-x-at-0/></m:math>
            and <m:math><s:delta-x-at-n/></m:math> are non-negative integers and 
            <m:math><s:delta-t-at-0/></m:math> and <m:math><s:delta-t-at-n/></m:math> are
            positive integers. <m:math><m:ci>n</m:ci></m:math>, a positive integer, is the amount 
            of time the move will take.</p>
            
            <p>The constants <m:math><s:C1/></m:math>, <m:math><s:C2/></m:math> and 
            <m:math><s:C3/></m:math> are defined by
            <m:math><s:C1-eq/></m:math>, <m:math><s:C2-eq/></m:math>, and <m:math><s:C3-eq/></m:math>. 
            <m:math><m:ci>n</m:ci></m:math>, <m:math><s:C1/></m:math>, <m:math><s:C2/></m:math>,
            and <m:math><s:C3/></m:math>
            can be computed offline then passed to the controller.</p>
            
            <p>The controller uses the following equations to control a stepper motor.
            The term <m:math><m:apply><m:times/><m:cn>2</m:cn><s:C1/><m:ci>t</m:ci></m:apply></m:math>
            can be replaced by an accumulator.</p>
            
            <p><m:math><s:f-at-0-eq/></m:math></p>
            <p><m:math><s:g-at-t-plus-1-eq-5/></m:math></p>
            <p><m:math><s:f-at-t-plus-1-eq-2/></m:math></p>
            
            <p>The controller sends a step pulse at time <m:math><s:t-plus-1/></m:math> if
            <m:math><m:apply><m:geq/><s:g-at-t-plus-1/><m:cn>0</m:cn></m:apply></m:math>.</p>
            
            <h2>2. Fixed-Point Derivation</h2>
            
            <p>In this section, I plan to show how switching to a fixed-point representation can
            save hardware. (Hint: imagine what will happen to the equations if
            <m:math><m:apply><m:eq/><s:delta-t-at-0/><s:delta-t-at-n/></m:apply></m:math>
            and they are a power of 2.) I'll also document the tradeoffs involved in selecting 
            the number of bits used in the constants.</p>
            
            <p>To be continued...</p>
        </body>
    </html>

    <s:t-plus-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <plus/>
            <ci>t</ci>
            <cn>1</cn>
        </apply>
    </s:t-plus-1>

    <s:x-at-t xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>x</ci>
            <ci>t</ci>
        </apply>
    </s:x-at-t>
    
    <s:x-at-0 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>x</ci>
            <cn>0</cn>
        </apply>
    </s:x-at-0>
    
    <s:x-at-t-plus-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>x</ci>
            <s:t-plus-1/>
        </apply>
    </s:x-at-t-plus-1>

    <s:x-at-t-definition xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <plus/>
            <apply>
                <times/>
                <ci>a</ci>
                <apply>
                    <power/>
                    <ci>t</ci>
                    <cn>2</cn>
                </apply>
            </apply>
            <apply>
                <times/>
                <ci>b</ci>
                <ci>t</ci>
            </apply>
            <ci>c</ci>
        </apply>
    </s:x-at-t-definition>

    <s:x-at-t-plus-1-definition xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <plus/>
            <apply>
                <times/>
                <ci>a</ci>
                <apply>
                    <power/>
                    <s:t-plus-1/>
                    <cn>2</cn>
                </apply>
            </apply>
            <apply>
                <times/>
                <ci>b</ci>
                <s:t-plus-1/>
            </apply>
            <ci>c</ci>
        </apply>
    </s:x-at-t-plus-1-definition>

    <s:x-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:x-at-t/>
            <s:x-at-t-definition/>
        </apply>
    </s:x-eq>
    
    <s:delta>&#x394;</s:delta>
    
    <s:delta-x-at-0 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <selector/>
            <ci><s:delta/>x</ci>
            <cn>0</cn>
        </apply>
    </s:delta-x-at-0>

    <s:delta-x-at-n xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <selector/>
            <ci><s:delta/>x</ci>
            <ci>n</ci>
        </apply>
    </s:delta-x-at-n>

    <s:delta-t-at-0 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <selector/>
            <ci><s:delta/>t</ci>
            <cn>0</cn>
        </apply>
    </s:delta-t-at-0>

    <s:delta-t-at-n xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <selector/>
            <ci><s:delta/>t</ci>
            <ci>n</ci>
        </apply>
    </s:delta-t-at-n>
    
    <s:slope-at-0 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <divide/>
            <s:delta-x-at-0/>
            <s:delta-t-at-0/>
        </apply>
    </s:slope-at-0>
    
    <s:slope-at-n xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <divide/>
            <s:delta-x-at-n/>
            <s:delta-t-at-n/>
        </apply>
    </s:slope-at-n>
    
    <s:s-at-t xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>s</ci>
            <cn>t</cn>
        </apply>
    </s:s-at-t>

    <s:s-at-0 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>s</ci>
            <ci>0</ci>
        </apply>
    </s:s-at-0>

    <s:s-at-n xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>s</ci>
            <cn>n</cn>
        </apply>
    </s:s-at-n>

    <s:slope-at-t-formula xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <plus/>
            <apply>
                <times/>
                <cn>2</cn>
                <ci>a</ci>
                <ci>t</ci>
            </apply>
            <ci>b</ci>
        </apply>
    </s:slope-at-t-formula>

    <s:slope-at-0-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:slope-at-0/>
            <s:s-at-0/>
            <ci>b</ci>
        </apply>
    </s:slope-at-0-eq>

    <s:slope-at-n-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:slope-at-n/>
            <s:s-at-n/>
            <apply>
                <plus/>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>a</ci>
                    <ci>n</ci>
                </apply>
                <ci>b</ci>
            </apply>
        </apply>
    </s:slope-at-n-eq>
    
    <s:a-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <ci>a</ci>
            <apply>
                <times/>
                <apply>
                    <divide/>
                    <cn>1</cn>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <ci>n</ci>
                    </apply>
                </apply>
                <apply>
                    <minus/>
                    <s:slope-at-n/>
                    <s:slope-at-0/>
                </apply>
            </apply>
        </apply>
    </s:a-eq>

    <s:acceleration xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <times/>
            <apply>
                <divide/>
                <cn>1</cn>
                <ci>n</ci>
            </apply>
            <apply>
                <minus/>
                <s:slope-at-n/>
                <s:slope-at-0/>
            </apply>
        </apply>
    </s:acceleration>

    <s:d-at-t xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>d</ci>
            <ci>t</ci>
        </apply>
    </s:d-at-t>
    
    <s:d-at-0 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>d</ci>
            <cn>0</cn>
        </apply>
    </s:d-at-0>
    
    <s:d-at-t-plus-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>d</ci>
            <s:t-plus-1/>
        </apply>
    </s:d-at-t-plus-1>
    
    <s:e-at-t xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>e</ci>
            <ci>t</ci>
        </apply>
    </s:e-at-t>

    <s:e-at-t-plus-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>e</ci>
            <s:t-plus-1/>
        </apply>
    </s:e-at-t-plus-1>

    <s:d-at-0-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:d-at-0/>
            <cn>0</cn>
        </apply>
    </s:d-at-0-eq>

    <s:e-eq-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:e-at-t-plus-1/>
            <apply>
                <plus/>
                <apply>
                    <minus/>
                    <s:x-at-t-plus-1/>
                    <s:x-at-t/>
                </apply>
                <s:d-at-t/>
            </apply>
        </apply>
    </s:e-eq-1>

    <s:e-eq-2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:e-at-t-plus-1/>
            <apply>
                <plus/>
                <apply>
                    <minus/>
                    <s:x-at-t-plus-1-definition/>
                    <s:x-at-t-definition/>
                </apply>
                <s:d-at-t/>
            </apply>
        </apply>
    </s:e-eq-2>

    <s:e-eq-3 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:e-at-t-plus-1/>
            <apply>
                <plus/>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>a</ci>
                    <ci>t</ci>
                </apply>
                <ci>a</ci>
                <ci>b</ci>
                <s:d-at-t/>
            </apply>
        </apply>
    </s:e-eq-3>

    <s:d-at-t-restriction-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <lt/>
            <s:d-at-t/>
            <apply>
                <divide/>
                <cn>1</cn>
                <cn>2</cn>
            </apply>
        </apply>
    </s:d-at-t-restriction-1>
    
    <s:d-at-t-restriction-2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <geq/>
            <s:d-at-t/>
            <apply>
                <minus/>
                <apply>
                    <divide/>
                    <cn>1</cn>
                    <cn>2</cn>
                </apply>
            </apply>
        </apply>
    </s:d-at-t-restriction-2>
    
    <s:e-at-t-plus-1-condition-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <lt/>
            <s:e-at-t-plus-1/>
            <apply>
                <divide/>
                <cn>1</cn>
                <cn>2</cn>
            </apply>
        </apply>
    </s:e-at-t-plus-1-condition-1>
    
    <s:d-eq-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:d-at-t-plus-1/>
            <apply>
                <minus/>
                <s:e-at-t-plus-1/>
                <cn>1</cn>
            </apply>
        </apply>
    </s:d-eq-1>
    
    <s:d-eq-2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:d-at-t-plus-1/>
            <piecewise>
                <piece>
                    <s:e-at-t-plus-1/>
                    <s:e-at-t-plus-1-condition-1/>
                </piece>
                <piece>
                    <apply>
                        <minus/>
                        <s:e-at-t-plus-1/>
                        <cn>1</cn>
                    </apply>
                    <apply>
                        <geq/>
                        <s:e-at-t-plus-1/>
                        <apply>
                            <divide/>
                            <cn>1</cn>
                            <cn>2</cn>
                        </apply>
                    </apply>
                </piece>
            </piecewise>
        </apply>
    </s:d-eq-2>

    <s:e-at-t-plus-1-condition-2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <lt/>
            <apply>
                <minus/>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <s:e-at-t-plus-1/>
                </apply>
                <cn>1</cn>
            </apply>
            <cn>0</cn>
        </apply>
    </s:e-at-t-plus-1-condition-2>

    <s:e-at-t-plus-1-condition-3 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <lt/>
            <apply>
                <plus/>
                <apply>
                    <times/>
                    <cn>4</cn>
                    <ci>t</ci>
                    <ci>a</ci>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>a</ci>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>b</ci>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <s:d-at-t/>
                </apply>
                <cn>-1</cn>
            </apply>
            <cn>0</cn>
        </apply>
    </s:e-at-t-plus-1-condition-3>
    
    <s:e-at-t-plus-1-condition-4 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <lt/>
            <apply>
                <plus/>
                <apply>
                    <divide/>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <ci>t</ci>
                        <s:delta-x-at-n/>
                    </apply>
                    <apply>
                        <times/>
                        <ci>n</ci>
                        <s:delta-t-at-n/>
                    </apply>
                </apply>
                <apply>
                    <divide/>
                    <apply>
                        <times/>
                        <cn>-2</cn>
                        <ci>t</ci>
                        <s:delta-x-at-0/>
                    </apply>
                    <apply>
                        <times/>
                        <ci>n</ci>
                        <s:delta-t-at-0/>
                    </apply>
                </apply>
                <apply>
                    <divide/>
                    <s:delta-x-at-n/>
                    <apply>
                        <times/>
                        <ci>n</ci>
                        <s:delta-t-at-n/>
                    </apply>
                </apply>
                <apply>
                    <divide/>
                    <apply>
                        <minus/>
                        <s:delta-x-at-0/>
                    </apply>
                    <apply>
                        <times/>
                        <ci>n</ci>
                        <s:delta-t-at-0/>
                    </apply>
                </apply>
                <apply>
                    <divide/>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <s:delta-x-at-0/>
                    </apply>
                    <s:delta-t-at-0/>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <s:d-at-t/>
                </apply>
                <cn>-1</cn>
            </apply>
            <cn>0</cn>
        </apply>
    </s:e-at-t-plus-1-condition-4>

    <s:multiplier xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <times/>
            <ci>n</ci>
            <s:delta-t-at-n/>
            <s:delta-t-at-0/>
        </apply>
    </s:multiplier>

    <s:multiplier-2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <times/>
            <cn>2</cn>
            <ci>n</ci>
            <s:delta-t-at-n/>
            <s:delta-t-at-0/>
        </apply>
    </s:multiplier-2>

    <s:g-at-t xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>g</ci>
            <ci>t</ci>
        </apply>
    </s:g-at-t>
    
    <s:g-at-t-plus-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>g</ci>
            <apply>
                <plus/>
                <ci>t</ci>
                <cn>1</cn>
            </apply>
        </apply>
    </s:g-at-t-plus-1>
    
    <s:g-at-t-eq-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:g-at-t/>
            <apply>
                <times/>
                <ci>n</ci>
                <s:delta-t-at-n/>
                <s:delta-t-at-0/>
                <apply>
                    <minus/>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <s:e-at-t/>
                    </apply>
                    <cn>1</cn>
                </apply>
            </apply>
        </apply>
    </s:g-at-t-eq-1>
    
    <s:g-at-t-plus-1-eq-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:g-at-t-plus-1/>
            <apply>
                <times/>
                <ci>n</ci>
                <s:delta-t-at-n/>
                <s:delta-t-at-0/>
                <apply>
                    <minus/>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <s:e-at-t-plus-1/>
                    </apply>
                    <cn>1</cn>
                </apply>
            </apply>
        </apply>
    </s:g-at-t-plus-1-eq-1>
    
    <s:g-at-t-plus-1-eq-2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:g-at-t-plus-1/>
            <apply>
                <times/>
                <ci>n</ci>
                <s:delta-t-at-n/>
                <s:delta-t-at-0/>
                <apply>
                    <plus/>
                    <apply>
                        <times/>
                        <cn>4</cn>
                        <ci>t</ci>
                        <ci>a</ci>
                    </apply>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <ci>a</ci>
                    </apply>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <ci>b</ci>
                    </apply>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <s:d-at-t/>
                    </apply>
                    <cn>-1</cn>
                </apply>
            </apply>
        </apply>
    </s:g-at-t-plus-1-eq-2>

    <s:g-at-t-plus-1-eq-3 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:g-at-t-plus-1/>
            <apply>
                <plus/>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>t</ci>
                    <s:delta-x-at-n/>
                    <s:delta-t-at-0/>
                </apply>
                <apply>
                    <times/>
                    <cn>-2</cn>
                    <ci>t</ci>
                    <s:delta-x-at-0/>
                    <s:delta-t-at-n/>
                </apply>
                <apply>
                    <times/>
                    <s:delta-x-at-n/>
                    <s:delta-t-at-0/>
                </apply>
                <apply>
                    <times/>
                    <cn>-1</cn>
                    <s:delta-x-at-0/>
                    <s:delta-t-at-n/>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>n</ci>
                    <s:delta-x-at-0/>
                    <s:delta-t-at-n/>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>n</ci>
                    <s:delta-t-at-n/>
                    <s:delta-t-at-0/>
                    <s:d-at-t/>
                </apply>
                <apply>
                    <times/>
                    <cn>-1</cn>
                    <ci>n</ci>
                    <s:delta-t-at-n/>
                    <s:delta-t-at-0/>
                </apply>
            </apply>
        </apply>
    </s:g-at-t-plus-1-eq-3>
    
    <s:C1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <selector/>
            <ci>C</ci>
            <cn>1</cn>
        </apply>
    </s:C1>

    <s:C2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <selector/>
            <ci>C</ci>
            <cn>2</cn>
        </apply>
    </s:C2>

    <s:C3 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <selector/>
            <ci>C</ci>
            <cn>3</cn>
        </apply>
    </s:C3>

    <s:C1-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:C1/>
            <apply>
                <minus/>
                <apply>
                    <times/>
                    <s:delta-t-at-0/>
                    <s:delta-x-at-n/>
                </apply>
                <apply>
                    <times/>
                    <s:delta-x-at-0/>
                    <s:delta-t-at-n/>
                </apply>
            </apply>
        </apply>
    </s:C1-eq>

    <s:C2-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:C2/>
            <s:multiplier/>
        </apply>
    </s:C2-eq>

    <s:C3-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:C3/>
            <apply>
                <plus/>
                <apply>
                    <times/>
                    <s:delta-x-at-n/>
                    <s:delta-t-at-0/>
                </apply>
                <apply>
                    <minus/>
                    <apply>
                        <times/>
                        <s:delta-t-at-n/>
                        <s:delta-x-at-0/>
                    </apply>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <ci>n</ci>
                    <s:delta-t-at-n/>
                    <s:delta-x-at-0/>
                </apply>
                <apply>
                    <minus/>
                    <apply>
                        <times/>
                        <ci>n</ci>
                        <s:delta-t-at-n/>
                        <s:delta-t-at-0/>
                    </apply>
                </apply>
            </apply>
        </apply>
    </s:C3-eq>

    <s:g-at-t-plus-1-eq-4 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:g-at-t-plus-1/>
            <apply>
                <plus/>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <s:C1/>
                    <ci>t</ci>
                </apply>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <s:C2/>
                    <s:d-at-t/>
                </apply>
                <s:C3/>
            </apply>
        </apply>
    </s:g-at-t-plus-1-eq-4>

    <s:f-at-t xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>f</ci>
            <ci>t</ci>
        </apply>
    </s:f-at-t>
    
    <s:f-at-0 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>f</ci>
            <cn>0</cn>
        </apply>
    </s:f-at-0>
    
    <s:f-at-t-plus-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <ci>f</ci>
            <apply>
                <plus/>
                <ci>t</ci>
                <cn>1</cn>
            </apply>
        </apply>
    </s:f-at-t-plus-1>
    
    <s:f-at-t-eq-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:f-at-t/>
            <apply>
                <times/>
                <cn>2</cn>
                <ci>n</ci>
                <s:delta-t-at-n/>
                <s:delta-t-at-0/>
                <s:d-at-t/>
            </apply>
        </apply>
    </s:f-at-t-eq-1>

    <s:g-at-t-plus-1-eq-5 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:g-at-t-plus-1/>
            <apply>
                <plus/>
                <apply>
                    <times/>
                    <cn>2</cn>
                    <s:C1/>
                    <ci>t</ci>
                </apply>
                <s:f-at-t/>
                <s:C3/>
            </apply>
        </apply>
    </s:g-at-t-plus-1-eq-5>

    <s:f-at-t-plus-1-eq-1 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:f-at-t-plus-1/>
            <piecewise>
                <piece>
                    <apply>
                        <times/>
                        <s:multiplier-2/>
                        <s:e-at-t-plus-1/>
                    </apply>
                    <s:e-at-t-plus-1-condition-1/>
                </piece>
                <piece>
                    <apply>
                        <times/>
                        <s:multiplier-2/>
                        <apply>
                            <minus/>
                            <s:e-at-t-plus-1/>
                            <cn>1</cn>
                        </apply>
                    </apply>
                    <apply>
                        <geq/>
                        <s:e-at-t-plus-1/>
                        <apply>
                            <divide/>
                            <cn>1</cn>
                            <cn>2</cn>
                        </apply>
                    </apply>
                </piece>
            </piecewise>
        </apply>
    </s:f-at-t-plus-1-eq-1>
    
    <s:e-at-t-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:e-at-t/>
            <apply>
                <plus/>
                <apply>
                    <divide/>
                    <s:g-at-t/>
                    <apply>
                        <times/>
                        <cn>2</cn>
                        <ci>n</ci>
                        <s:delta-t-at-n/>
                        <s:delta-t-at-0/>
                    </apply>
                </apply>
                <apply>
                    <divide/>
                    <cn>1</cn>
                    <cn>2</cn>
                </apply>
            </apply>
        </apply>
    </s:e-at-t-eq>
    
    <s:f-at-t-plus-1-eq-2 xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:f-at-t-plus-1/>
            <piecewise>
                <piece>
                    <apply>
                        <plus/>
                        <s:g-at-t-plus-1/>
                        <s:C2/>
                    </apply>
                    <apply>
                        <lt/>
                        <s:g-at-t-plus-1/>
                        <cn>0</cn>
                    </apply>
                </piece>
                <piece>
                    <apply>
                        <minus/>
                        <s:g-at-t-plus-1/>
                        <s:C2/>
                    </apply>
                    <apply>
                        <geq/>
                        <s:g-at-t-plus-1/>
                        <cn>0</cn>
                    </apply>
                </piece>
            </piecewise>
        </apply>
    </s:f-at-t-plus-1-eq-2>

    <s:f-at-0-eq xmlns="http://www.w3.org/1998/Math/MathML">
        <apply>
            <eq/>
            <s:f-at-0/>
            <cn>0</cn>
        </apply>
    </s:f-at-0-eq>
</doc>
