====================================================================
BasicStochasticDifferential examples
====================================================================

Based on Symbol: a domain of symbols representing basic stochastic
differentials, used in StochasticDifferential(R) in the underlying
sparse multivariate polynomial representation.

We create new BSD only by coercion from Symbol using a special
function introduce! first of all to add to a private set SDset. We
allow a separate function convertIfCan which will check whether the
argument has previously been declared as a BSD.

The copyBSD() returns setBSD as a list of BSD.
Initially the BSD table of symbols is empty:
   print copyBSD() 
      []

as is the Ito table. The copyIto() returns the table relating 
semimartingales to basic stochastic differentials.
   print copyIto()
      table()

We introduce a new stochastic differential:
   dX:=introduce!(X,dX) -- dX is a new stochastic differential
      dX

and now it is in the BSD table of symbols:
   print copyBSD() 
      [dX]

and the Ito table:
   print copyIto() 
      table(X= dX)


The getSmgl(bsd) returns the semimartingale S related to the basic
stochastic differential bsd by introduce!:
   getSmgl(dX)
      X

Note that the dX symbol is of type BasicStochasticDifferential:
   print domainOf(dX)
     BasicStochasticDifferential()

The d function, d(X) returns dX if tableIto(X)=dX otherwise 0:
   print d X
      dX

and we can specify the domain:
   print ((d$BSD) X) 
      dX

which clearly is of domain BasicStochasticDifferential
   print domainOf((d$BSD) X)
      BasicStochasticDifferential()

The introduce!(X,dX) returns dX as BSD if it isn't already in BSD
   introduce!(t,dt) -- dt is a new stochastic differential
       dt

Now we can see that dt is in the BSD table:
   print copyBSD() 
       [dX,dt]

and the Ito table:
   print copyIto()
       table(t= dt,X= dX)

You cannot repeat an introduce! for an existing entry:
   introduce!(t,dt)
       "failed"

Regular symbols can be added, especially with subscripts:
   [introduce!(A[i],dA[i]) for i in 1..2]
            [dA ,dA ]
               1   2

And we can see them in the BSD table:
   print copyBSD()
      [dA ,dA ,dX,dt]
         1   2

and the Ito table:
   print copyIto()
      table(A = dA ,A = dA ,t= dt,X= dX)
             2    2  1    1

The d function can extract these symbols:
   [d A[i] for i in 1..2]
       [dA ,dA ]
          1   2

See Also:
o )show BasicStochasticDifferential

