\chapter{CDS File - convolution.cds}
When presentations are created in the CDS development environment, they
can be saved and loaded back into CDS. The file format is
an ASCII file format, which itself can be edited to alter the CDS
presentation, if desired. The following listing is a printout of the
file {\tt /mit/cds/beta/demo/convolution.cds} which is the file version
of the convolution application.


\begin{footnotesize}
\begin{singlespace}
\begin{verbatim}
\CDS_Version "b47"

\begin_outline
"Adding independent random variables using convolution."
"A bit of preliminary explanation."
"Defining and adding independent random variables."
"The convolution algorithm at work."
"Play time!"
"A Final Word"
\end_outline


\begin_node{untitled0}
\title{Adding independent random variables using convolution.}
\page_constructor_text "(eval-file '/mit/cds/beta/demo/convolution.scm)"
\begin_screen

\begin_figure {XmLabel}
\widget_name "intro" 
\mapping "True"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "Convolution is your new best friend.";
leftPosition "0";
topPosition "608";
rightPosition "992";
bottomPosition "688";
\end_figure

\begin_figure {XmLabel}
\widget_name "logo" 
\mapping "True"
borderWidth "0";
labelPixmap "/mit/cds/beta/pixmaps/mit-logo";
labelType "PIXMAP";
marginHeight "14";
marginTop "10";
leftPosition "192";
topPosition "272";
rightPosition "800";
bottomPosition "608";
\end_figure
\end_screen
\end_node

\begin_node{untitled1}
\title{A bit of preliminary explanation.}
\begin_screen

\begin_figure {FormattedText}
\widget_name "explanation" 
\mapping "True"
borderWidth "0";
label "@^6[The convolution operation...]
@.
@.
@^6[@c[@i[p]@-[@i[c]](@i[w]@-[0]) = 
@Int[From[@i[x]@-[0] = 0]
To[@Infty]]@#@#@i[p]@-[@i[a]](@i[x]@-[0])
*@i[p]@-[@i[b]](@i[w]@-[0] - @i[x]@-[0])d@i[x]@-[0]]]
@.
@.
@^6[@c[@i[p]@-[@i[c]](@i[w]@-[0]) = 
@Sum[From[@i[x]@-[0] = 0]
To[@Infty]]@#@#@i[p]@-[@i[a]](@i[x]@-[0])*
@i[p]@-[@i[b]](@i[w]@-[0] - @i[x]@-[0])]]
@.
@.
@>[@^6[  ...for @i[c] = @i[a] + @i[b] 
and @i[a], @i[b] independent@#@#@#@#@#@#]]
@.";
fontSize "biggest";
xFlag "left";
leftPosition "32";
topPosition "16";
rightPosition "960";
bottomPosition "976";
\end_figure
\end_screen
\end_node

\begin_node{untitled2}
\title{Defining and adding independent random variables.}
\page_constructor_text "(for (i 0 3)
   (set-resource (nth pmfa_scale_list i) 'value (* 10 (nth pmfa_list i)))
   (set-resource (nth pmfb_scale_list i) 'value (* 10 (nth pmfb_list i))))
(set-resource 'scale_numa 'value 2)
(set-resource 'scale_numb 'value 4)
(update-pmfa-text numa)
(update-pmfb-text numb)
(update-border 'pmfa_text)
(update-border 'pmfb_text)
(barchart 'pmfa pmfa_list)
(barchart 'pmfb pmfb_list)"
\begin_screen
\begin_figure {AtPlotter}
\widget_name "PMFA" 
\mapping "True"
\constructor_text "(add-barchart 'PMFA 'pmfa 4)
(set-barchart-resource 'pmfa 'xMin 0)
(set-barchart-resource 'pmfa 'xMax 3)
(set-barchart-resource 'pmfa 'density .7)                                 "
title "PMF A";
xaxis.label "x = possible values for random variable A";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "4";
leftPosition "0";
topPosition "0";
rightPosition "496";
bottomPosition "384";
\end_figure\begin_figure {AtPlotter}
\widget_name "PMFB" 
\mapping "True"
\constructor_text "(add-barchart 'PMFB 'pmfb 4)
(set-barchart-resource 'pmfb 'xMin 0)
(set-barchart-resource 'pmfb 'xMax 3)
(set-barchart-resource 'pmfb 'denisty 0.7)                                 "
title "PMF B";
legendTitle "";
xaxis.label "x = possible values for random variable B";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "4";
leftPosition "496";
topPosition "0";
rightPosition "976";
bottomPosition "384";
\end_figure\begin_figure {XmPushButton}
\widget_name "Define_PMFs" 
\mapping "True"
\action "Arm" "(hide-widget  'Define_PMFs)
(hide-widget 'Show_Stats)
(hide-widget 'Show_PMFC)
(for (i 0 (- numa 1))
   (show-widget (nth pmfa_scale_list i)))
(for (i 0 (- numb 1))
      (show-widget (nth pmfb_scale_list i)))
(show-widget 'pmfa_text)
(show-widget 'pmfb_text)
(show-widget 'scale_numa)
(show-widget 'scale_numb)
(show-widget 'done)                                     "
fontList "*lucida-*-r-*-*-24-*";
labelString "Define PMF's";
leftPosition "0";
topPosition "896";
rightPosition "336";
bottomPosition "976";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pa[1]" 
\mapping "False"
\action "Drag" "(set! pmfa_list (replace-nth pmfa_list 1
	(get-slider-value 'scale_Pa[1])))
(barchart 'pmfa (head pmfa_list numa))                            
(set!  suma (total pmfa_list numa))
(update-pmfa-text numa)
(update-border 'pmfa_text)    "
\action "Value Changed" "(activate-widget 'scale_Pa[1] 'Drag)    "
borderWidth "0";
value "3";
decimalPoints "1";
maximum "10";
titleString "P(1)";
leftPosition "176";
topPosition "512";
rightPosition "256";
bottomPosition "896";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pb[1]" 
\mapping "False"
\action "Drag" "(set! pmfb_list (replace-nth pmfb_list 1
	(get-slider-value 'scale_Pb[1])))
(barchart 'pmfb (head pmfb_list numb))                            
(set!  sumb (total pmfb_list numb))
(update-pmfb-text numb)
(update-border 'pmfb_text)    "
\action "Value Changed" "(activate-widget 'scale_Pb[1] 'Drag)    "
borderWidth "0";
value "5";
decimalPoints "1";
maximum "10";
titleString "P(1)";
leftPosition "640";
topPosition "512";
rightPosition "720";
bottomPosition "896";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pb[0]" 
\mapping "False"
\action "Drag" " (set! pmfb_list (replace-nth pmfb_list 0 
	(get-slider-value 'scale_Pb[0])))
(barchart 'pmfb (head pmfb_list numb))
(set!  sumb (total pmfb_list numb))
(update-pmfb-text numb)
(update-border 'pmfb_text)       "
\action "Value Changed" "(activate-widget 'scale_Pb[0] 'Drag)    "
borderWidth "0";
decimalPoints "1";
maximum "10";
titleString "P(0)";
leftPosition "560";
topPosition "512";
rightPosition "640";
bottomPosition "896";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pb[2]" 
\mapping "False"
\action "Drag" "(set! pmfb_list (replace-nth pmfb_list 2
	(get-slider-value 'scale_Pb[2])))
(barchart 'pmfb (head pmfb_list numb))                            
(set!  sumb (total pmfb_list numb))
(update-pmfb-text numb)
(update-border 'pmfb_text)    "
\action "Value Changed" "(activate-widget 'scale_Pb[2] 'Drag)    "
borderWidth "0";
value "3";
decimalPoints "1";
maximum "10";
titleString "P(2)";
leftPosition "720";
topPosition "512";
rightPosition "800";
bottomPosition "896";
\end_figure\begin_figure {XmPushButton}
\widget_name "done" 
\mapping "False"
\action "Arm" "(if  (not (and (= suma 1) (= sumb 1)))
    (for (i 1 1)
        (show-widget 'warning)
        (show-widget 'warning_ok)
        (show-widget 'yoda)
        (hide-widget 'done))
    (for (i 1 1)   
        (for (j 0 3)
               (hide-widget (nth pmfa_scale_list j))
               (hide-widget (nth pmfb_scale_list j)))
        (hide-widget 'pmfa_text)
        (hide-widget 'pmfb_text)
        (hide-widget 'scale_numa)
        (hide-widget 'scale_numb)
        (show-widget 'Define_PMFs)
        (show-widget 'Show_Stats)
        (show-widget 'Show_PMFC)
        (hide-widget 'done)
        (set! pmfa_list (head pmfa_list numa))
        (set! pmfb_list (head pmfb_list numb))))"
fontList "*lucida-*-r-*-*-24-*";
labelString "DONE";
leftPosition "432";
topPosition "896";
rightPosition "560";
bottomPosition "992";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pa[0]" 
\mapping "False"
\action "Drag" "(set! pmfa_list (replace-nth pmfa_list 0
	(get-slider-value 'scale_Pa[0])))
(barchart 'pmfa (head pmfa_list numa))
(set!  suma (total pmfa_list numa))
(update-pmfa-text numa)
(update-border 'pmfa_text)       "
\action "Value Changed" "(activate-widget 'scale_Pa[0] 'Drag)            "
borderWidth "0";
value "7";
decimalPoints "1";
maximum "10";
titleString "P(0)";
leftPosition "80";
topPosition "512";
rightPosition "176";
bottomPosition "896";
\end_figure\begin_figure {XmPushButton}
\widget_name "warning_ok" 
\mapping "False"
\action "Arm" "(hide-widget 'warning_ok)
(hide-widget 'warning)
(hide-widget 'yoda)
(show-widget 'done)"
fontList "*lucida-*-r-*-*-24-*";
labelString "OK";
leftPosition "912";
topPosition "832";
rightPosition "976";
bottomPosition "896";
\end_figure\begin_figure {XmLabel}
\widget_name "warning" 
\mapping "False"
fontList "*lucida-*-r-*-*-24-*";
labelString "The sum of the probabilities of all values of 
random variables A and B equal to 1 must be!";
leftPosition "48";
topPosition "400";
rightPosition "976";
bottomPosition "896";
\end_figure\begin_figure {FormattedText}
\widget_name "pmfb_text" 
\mapping "False"
borderWidth "6";
label "0@#+@#0.5@#+@#0.3@#+@#0.2@#=@#1";
fontSize "big";
leftPosition "576";
topPosition "896";
rightPosition "896";
bottomPosition "992";
\end_figure\begin_figure {FormattedText}
\widget_name "pmfa_text" 
\mapping "False"
borderWidth "6";
label "0.7@#+@#0.3@#=@#1";
fontSize "big";
leftPosition "112";
topPosition "896";
rightPosition "416";
bottomPosition "992";
\end_figure\begin_figure {XmPushButton}
\widget_name "Show_Stats" 
\mapping "True"
\action "Arm" "(set! temp 0)
(set! height (/ (- bottom top) (* numa numb)))
(hide-widget 'Define_PMFs)
(hide-widget 'Show_PMFC)
(hide-widget 'Show_Stats)
(for (i 0 (- numa 1))
    (for (j 0 (- numb 1))
       (make-label-box i j  temp  height)
       (make-prob-box i j temp height)
       (make-sum-box i j temp height)
       (set! temp (+ 1 temp))))
(set! height 
    (/ (- (- bottom top) 50) (- (+ numa numb) 1)))
(for (i 0 (- (+ numa numb) 2))
  (make-csum-box i i height))
(show-widget 'stats_header)
(show-widget 'stats_done)
(show-widget 'csum_header)"
fontList "*lucida-*-r-*-*-24-*";
labelString "Show Statistics";
leftPosition "336";
topPosition "896";
rightPosition "672";
bottomPosition "976";
\end_figure\begin_figure {XmLabel}
\widget_name "stats_header" 
\mapping "False"
alignment "ALIGNMENT_BEGINNING";
fontList "*times-*-r-*-*-24-*";
labelString "          Event Space                 Probability                       Sum";
leftPosition "0";
topPosition "383";
rightPosition "660";
bottomPosition "459";
\end_figure\begin_figure {XmPushButton}
\widget_name "stats_done" 
\mapping "False"
\action "Arm" "(hide-widget 'stats_header)
(hide-widget 'stats_done)
(hide-widget 'csum_header)
(for (i 0 (- numa 1))
   (for (j 0 (- numb 1))
        (cut-widget (concat '[  i ', j ']))
        (cut-widget (concat 'prob i j))
        (cut-widget (concat 'sum i j))))
(for (i 0 (- (+ numa numb) 2))
      (cut-widget (concat 'C i)))
(show-widget 'Define_PMFs)
(show-widget 'Show_Stats)
(show-widget 'Show_PMFC)
           "
fontList "*lucida-*-r-*-*-24-*";
labelString "DONE";
leftPosition "661";
topPosition "943";
rightPosition "978";
bottomPosition "991";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pb[3]" 
\mapping "False"
\action "Drag" "(set! pmfb_list (replace-nth pmfb_list 3 
	(get-slider-value 'scale_Pb[3])))
(barchart 'pmfb (head pmfb_list numb))                            
(set!  sumb (total pmfb_list numb))
(update-pmfb-text numb)
(update-border 'pmfb_text)    "
\action "Value Changed" "(activate-widget 'scale_Pb[3] 'Drag)"
borderWidth "0";
value "2";
decimalPoints "1";
maximum "10";
titleString "P(3)";
leftPosition "800";
topPosition "512";
rightPosition "880";
bottomPosition "896";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pa[3]" 
\mapping "False"
\action "Drag" "(set! pmfa_list (replace-nth pmfa_list 3
	(get-slider-value 'scale_Pa[3])))
(barchart 'pmfa (head pmfa_list numa))                            
(set!  suma (total pmfa_list numa))
(update-pmfa-text numa)
(update-border 'pmfa_text)    "
\action "Value Changed" "(activate-widget 'scale_Pa[3] 'Drag)"
borderWidth "0";
decimalPoints "1";
maximum "10";
titleString "P(3)";
leftPosition "336";
topPosition "512";
rightPosition "416";
bottomPosition "896";
\end_figure\begin_figure {XmScale}
\widget_name "scale_Pa[2]" 
\mapping "False"
\action "Drag" "(set! pmfa_list (replace-nth pmfa_list 2
	(get-slider-value 'scale_Pa[2])))
(barchart 'pmfa (head pmfa_list numa))                            
(set!  suma (total pmfa_list numa))
(update-pmfa-text numa)
(update-border 'pmfa_text)    "
\action "Value Changed" "(activate-widget 'scale_Pa[2] 'Drag)"
borderWidth "0";
decimalPoints "1";
maximum "10";
titleString "P(2)";
leftPosition "256";
topPosition "512";
rightPosition "336";
bottomPosition "896";
\end_figure\begin_figure {XmScale}
\widget_name "scale_numa" 
\mapping "False"
\action "Drag" "(set! temp (get-slider-value 'scale_numa))
(if (>  temp numa)
      (for (i  numa (- temp 1))
            (show-widget (nth pmfa_scale_list i))
	    (set! pmfa_list (replace-nth pmfa_list i 
			(get-slider-value (nth pmfa_scale_list i))))))
(if (< temp numa)
       (for (i  temp 3)
                 (hide-widget (nth pmfa_scale_list i))))
(set! numa temp)
(barchart 'pmfa (head pmfa_list numa))
(set! suma (total pmfa_list numa))
(update-pmfa-text numa)
(update-border 'pmfa_text)
"
\action "Value Changed" "(activate-widget 'scale_numa 'Drag)"
value "2";
maximum "4";
minimum "1";
orientation "HORIZONTAL";
processingDirection "MAX_ON_RIGHT";
titleString "# of possible values for random variable A";
leftPosition "112";
topPosition "400";
rightPosition "416";
bottomPosition "512";
\end_figure\begin_figure {XmScale}
\widget_name "scale_numb" 
\mapping "False"
\action "Drag" "(set! temp (get-slider-value 'scale_numb))
(if (>  temp numb)
        (for (i  numb (- temp 1))
            (show-widget (nth pmfb_scale_list i))
	    (set! pmfb_list (replace-nth pmfb_list i 
			(get-slider-value (nth pmfb_scale_list i))))))
(if (< temp numb)
    (for (i  temp 3)
                 (hide-widget (nth pmfb_scale_list i))))
(set! numb temp)
(barchart 'pmfb (head pmfb_list numb))
(set! sumb (total pmfb_list numb))
(update-pmfb-text numb)
(update-border 'pmfb_text)"
\action "Value Changed" "(activate-widget 'scale_numb 'Drag)"
value "4";
maximum "4";
minimum "1";
orientation "HORIZONTAL";
processingDirection "MAX_ON_RIGHT";
titleString "# of possible values for random variable B";
leftPosition "576";
topPosition "400";
rightPosition "880";
bottomPosition "512";
\end_figure\begin_figure {FormattedText}
\widget_name "csum_header" 
\mapping "False"
label "@b{C = A + B }";
fontSize "medbig";
leftPosition "661";
topPosition "383";
rightPosition "977";
bottomPosition "458";
\end_figure\begin_figure {XmPushButton}
\widget_name "Show_PMFC" 
\mapping "True"
\action "Arm" "(hide-widget 'Define_PMFs)
(hide-widget 'Show_Stats)
(hide-widget 'Show_PMFC)
(show-widget 'PMFC)
(show-widget 'pmfc_done)
(show-widget 'pmf_list)
(define a (convolve (head  pmfa_list numa)
                    (head pmfb_list numb)))
(set-resource 'pmf_list 'label
   (concat '@b{@c[  (quote PMF A = ) 
     (sublist pmfa_list numa) newline newline
     (quote PMF B = ) (sublist pmfb_list numb)
      newline newline
     (quote PMF C =) (sublist a(-(+ numa numb)1))
      ']}))
(barchart 'pmfc a)"
fontList "*lucida-*-r-*-*-24-*";
labelString "Show PMF C";
leftPosition "672";
topPosition "896";
rightPosition "992";
bottomPosition "976";
\end_figure\begin_figure {AtPlotter}
\widget_name "PMFC" 
\mapping "False"
\constructor_text "(add-barchart 'PMFC 'pmfc 7)
(set-barchart-resource 'pmfc  'xMin 0)
(set-barchart-resource 'pmfc 'xMax 6)
(set-barchart-resource 'pmfc 'density .7)"
title "PMF A + PMF B = PMF C";
xaxis.label "x = possible values for random variable C";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "7";
leftPosition "0";
topPosition "384";
rightPosition "496";
bottomPosition "768";
\end_figure\begin_figure {XmPushButton}
\widget_name "pmfc_done" 
\mapping "False"
\action "Arm" "(hide-widget 'PMFC)
(hide-widget 'pmfc_done)
(hide-widget 'pmf_list)
(show-widget 'Show_Stats)
(show-widget 'Define_PMFs)
(show-widget 'Show_PMFC)"
fontList "*lucida-*-r-*-*-24-*";
labelString "DONE";
leftPosition "256";
topPosition "768";
rightPosition "736";
bottomPosition "864";
\end_figure\begin_figure {FormattedText}
\widget_name "pmf_list" 
\mapping "False"
label "@b{@c[PMF A = (0.7 0.3)@.@.PMF B = (0 0.5 0.3 0.2)@.@.PMF C =(0 0.35 0.36 0.23 0.06)]}";
fontSize "medbig";
leftPosition "496";
topPosition "384";
rightPosition "976";
bottomPosition "768";
\end_figure\begin_figure {XmLabel}
\widget_name "yoda" 
\mapping "False"
borderWidth "0";
labelPixmap "/mit/cds/beta/pixmaps/yoda";
labelType "PIXMAP";
leftPosition "59";
topPosition "462";
rightPosition "206";
bottomPosition "813";
\end_figure

\end_screen
\end_node

\begin_node{untitled1}
\title{The convolution algorithm at work.}
\page_constructor_text "(define amax -1)
(set-resource 'slide_a 'set 'true)"
\page_entry_text "(set! pmfc_list (convolve pmfa_list pmfb_list))
(define slid_pmf 'a)
(set! amax -1)
(set-resource 'pmfa_label 'label
  (concat '@b{ (list-to-string (map prec2 (reverse pmfa_list))) '} ))
(set-resource 'pmfb_label 'label
  (concat '@b{ (list-to-string (map prec2 pmfb_list)) '}))
(position-pmfa-label -1)
(position-pmfb-label 3)
(show-widget 'pmfa_label)
(show-widget 'pmfb_label)
(show-widget 'PMFA2)
(show-widget 'PMFB2)
(show-widget 'convolve_chart)
(show-widget 'PMFC2)
(show-widget 'slide_a)
(show-widget 'slide_b)
(show-widget 'scale_i)
(show-widget 'label_c)
(show-widget 'label_b)
(show-widget 'label_a)
(update-ith-sum-label -1)
(update-pmfc-label -1)
(barchart 'pmfa2 pmfa_list)
(barchart 'pmfb2 pmfb_list)
(barchart 'convb pmfb_list)
(barchart 'conva (reverse pmfa_list))
(set-barchart-resource 'conva 'xMin -4)
(set-barchart-resource 'conva 'xMax -1)
(set-barchart-resource 'convb 'xMin 0)
(set-barchart-resource 'convb 'xMax 3)
(set-resource 'scale_i 'value -1)
(set-resource 'slide_a 'set 'true)
(set-resource 'slide_b 'set 'false)
(barchart 'pmfc2 (head pmfc_list 0))"
\begin_screen
\begin_figure {AtPlotter}
\widget_name "PMFA2" 
\mapping "True"
\constructor_text "(add-barchart 'PMFA2 'pmfa2 4)
(set-barchart-resource 'pmfa2 'shading 'true)
(set-barchart-resource 'pmfa2 'pattern 'AtGRAY5)
(set-barchart-resource 'pmfa2 'xMin 0)
(set-barchart-resource 'pmfa2 'xMax 3)"
title "PMF A";
xaxis.label "x = possible values for random variable A";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "4";
leftPosition "0";
topPosition "0";
rightPosition "496";
bottomPosition "352";
\end_figure\begin_figure {AtPlotter}
\widget_name "PMFC2" 
\mapping "True"
\constructor_text "(add-barchart 'PMFC2 'pmfc2 7)
(set-barchart-resource 'pmfc2 'xMin 0)
(set-barchart-resource 'pmfc2 'xMax 6)
(add-barchart 'PMFC2 'current_c 7)
(set-barchart-resource 'current_c 'xMin 0)
(set-barchart-resource 'current_c 'xMax 6)
(set-barchart-resource 'current_c 'shading 'true)
(set-barchart-resource 'current_c 'pattern 'AtGRAY0)"
title "PMFA + PMF B = PMF C";
xaxis.label "x = possible values for random variable c";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "7";
leftPosition "496";
topPosition "352";
rightPosition "976";
bottomPosition "704";
\end_figure\begin_figure {AtPlotter}
\widget_name "PMFB2" 
\mapping "True"
\constructor_text "(add-barchart 'PMFB2 'pmfb2 4)
(set-barchart-resource 'pmfb2 'shading 'true)
(set-barchart-resource 'pmfb2 'xMin 0)
(set-barchart-resource 'pmfb2 'xMax 3)
(set-barchart-resource 'pmfb2 'pattern 'AtGRAY0)"
title "PMF B";
xaxis.label "x = possible values for random variable b";
xaxis.min "-1";
xaxis.max "4";
leftPosition "496";
topPosition "0";
rightPosition "976";
bottomPosition "352";
\end_figure\begin_figure {XmScale}
\widget_name "scale_i" 
\mapping "True"
\action "Drag" "(set!  amax (get-slider-value 'scale_i))
(if (eq? slid_pmf  'a) (for (i 0 0)
       (barchart 'conva (reverse pmfa_list))
       (barchart 'convb pmfb_list)
       (set-barchart-resource 'convb 'xMin 0)
       (set-barchart-resource 'convb 'xMax 3)
       (set-barchart-resource 'conva 'xMin (- amax 3))
       (set-barchart-resource 'conva 'xMax amax)
       (position-pmfa-label amax))
     (for (i 0 0)
     (barchart 'convb (reverse pmfb_list))
     (barchart 'conva pmfa_list)
     (set-barchart-resource 'convb 'xMin (- amax 3))
     (set-barchart-resource 'convb 'xMax amax)
     (set-barchart-resource 'conva 'xMin 0)
     (set-barchart-resource 'conva 'xMax 3)
     (position-pmfb-label amax)))  
(update-ith-sum-label amax)
(barchart 'pmfc2 (head pmfc_list (+ 1 amax)))
(barchart 'current_c 
    (replace-nth (list 0 0 0 0 0 ) amax
                                    (nth pmfc_list amax)))
(update-pmfc-label amax)"
\action "Value Changed" "(activate-widget 'scale_i 'Drag)"
borderWidth "0";
maximum "6";
minimum "-2";
orientation "HORIZONTAL";
processingDirection "MAX_ON_RIGHT";
titleString "C(w)";
leftPosition "64";
topPosition "704";
rightPosition "496";
bottomPosition "800";
\end_figure\begin_figure {AtPlotter}
\widget_name "convolve_chart" 
\mapping "True"
\constructor_text "(add-barchart 'convolve_chart 'convb 4)
(add-barchart 'convolve_chart 'conva 4)
(set-barchart-resource 'conva 'shading 'true)
(set-barchart-resource 'conva 'pattern 'AtGRAY5)
(set-barchart-resource 'conva 'density .5)
(set-barchart-resource 'convb 'shading 'true)
(set-barchart-resource 'convb 'pattern 'AtGRAY0)
(set-barchart-resource 'convb 'density .8)"
title "Convolving PMF A and PMF B";
xaxis.label "x = possible values for randomvariables a and b";
yaxis.label "P(x)";
xaxis.min "-2";
xaxis.max "6";
leftPosition "0";
topPosition "352";
rightPosition "496";
bottomPosition "704";
\end_figure\begin_figure {XmToggleButton}
\widget_name "slide_b" 
\mapping "True"
\action "Value Changed" "(if (eq? slid_pmf  'a)
      (for (i 0 0)
         (set-resource 'slide_b 'set 'true)
         (set! slid_pmf 'b)
         (set-resource 'slide_a 'set 'false)
         (barchart 'convb (reverse(head pmfb_list numb)))
         (barchart 'conva (head pmfa_list numa))
         (set-barchart-resource 'conva 'xMin 0)
         (set-barchart-resource 'conva 'xMax 3)
         (set-barchart-resource 'convb 'xMax amax)
         (set-barchart-resource 'convb 'xMin (- amax 3))
         (set-resource 'pmfa_label 'label 
               (concat '@b{ 
               (list-to-string (map prec2 pmfa_list)) '}))
         (set-resource 'pmfb_label 'label
               (concat '@b{ (list-to-string 
                (map prec2 (reverse pmfb_list))) '}))
         (position-pmfb-label amax)
         (position-pmfa-label 3)
         (update-ith-sum-label amax))
       (set-resource 'slide_b 'set 'true))"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "Slide PMF B";
set "true";
leftPosition "720";
topPosition "704";
rightPosition "912";
bottomPosition "800";
\end_figure\begin_figure {XmToggleButton}
\widget_name "slide_a" 
\mapping "True"
\action "Value Changed" "(if (eq? slid_pmf  'b)
      (for (i 0 0)
         (set-resource 'slide_a 'set 'true)  
         (set! slid_pmf 'a)
         (set-resource 'slide_b 'set 'false)
         (barchart 'conva (reverse(head pmfa_list numa)))
         (barchart 'convb (head pmfb_list numb))
         (set-barchart-resource 'convb 'xMin 0)
         (set-barchart-resource 'convb 'xMax 3)
         (set-barchart-resource 'conva 'xMax amax)
         (set-barchart-resource 'conva 'xMin (- amax 3))
         (set-resource 'pmfa_label 'label
                           (concat '@b{ (list-to-string 
                          (map prec2 (reverse pmfa_list))) '}))
         (set-resource 'pmfb_label 'label
                  (concat '@b{
            (list-to-string (map prec2 pmfb_list)) '}))
         (position-pmfb-label 3)
         (position-pmfa-label amax)
         (update-ith-sum-label amax))
        (set-resource 'slide_a 'set 'true))"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "Slide PMF A";
set "false";
leftPosition "528";
topPosition "704";
rightPosition "720";
bottomPosition "800";
\end_figure\begin_figure {FormattedText}
\widget_name "pmfc_label" 
\mapping "True"
label "@b{0.00}";
fontSize "medbig";
xFlag "left";
leftPosition "88";
topPosition "944";
rightPosition "688";
bottomPosition "992";
\end_figure\begin_figure {FormattedText}
\widget_name "ith_sum_label" 
\mapping "True"
label "@b{0.00@#=@#0}";
fontSize "medbig";
xFlag "left";
leftPosition "394";
topPosition "896";
rightPosition "810";
bottomPosition "944";
\end_figure\begin_figure {FormattedText}
\widget_name "pmfb_label" 
\mapping "True"
label "@b{0.20___0.30___0.50___0.00}";
fontSize "medbig";
xFlag "left";
leftPosition "136";
topPosition "848";
rightPosition "444";
bottomPosition "896";
\end_figure\begin_figure {FormattedText}
\widget_name "pmfa_label" 
\mapping "True"
label "@b{0.70___0.30___0.00___0.00}";
fontSize "medbig";
xFlag "left";
leftPosition "394";
topPosition "800";
rightPosition "702";
bottomPosition "848";
\end_figure\begin_figure {XmLabel}
\widget_name "label_c" 
\mapping "True"
fontList "*lucida-*-r-*-*-24-*";
labelString "PMFC";
leftPosition "0";
topPosition "944";
rightPosition "84";
bottomPosition "992";
\end_figure\begin_figure {XmLabel}
\widget_name "label_b" 
\mapping "True"
fontList "*lucida-*-r-*-*-24-*";
labelString "PMFB";
leftPosition "0";
topPosition "848";
rightPosition "84";
bottomPosition "896";
\end_figure\begin_figure {XmLabel}
\widget_name "label_a" 
\mapping "True"
fontList "*lucida-*-r-*-*-24-*";
labelString "PMFA";
leftPosition "0";
topPosition "800";
rightPosition "84";
bottomPosition "848";
\end_figure

\end_screen
\end_node

\begin_node{untitled1}
\title{Play time!}
\page_constructor_text "(define current_pmf 'a)
(define pmf_type 'bernoulli)
(define pmfa3_list (append pmfa_list (list 0 0 0 0 0 0)))
(define pmfb3_list (append pmfb_list (list 0 0 0 0 0 0)))
(define pmfc3_list (convolve pmfa3_list pmfb3_list))
(set-resource 'define_a 'set 'true)
(set-resource 'define_b 'set 'false)
(set-resource 'PMFA3 'borderWidth 4)
(set-resource 'PMFB3 'borderWidth 1)
(add-menu-pane 'PMFs)
(add-menu-item 'PMFs 'Bernoulli)
(add-menu-item 'PMFs 'Binomial)
(add-menu-item 'PMFs 'Geometric)
(add-menu-item 'PMFs 'Pascal)
(add-menu-item 'PMFs 'PMFC)
(add-menu-item 'PMFs 'Random)
(barchart 'pmfa3 pmfa3_list)
(barchart 'pmfb3 pmfb3_list)
(barchart 'pmfc3 pmfc3_list)"
\page_entry_text "(add-menu-function 'PMFs 'Binomial set-binomial)
(add-menu-function 'PMFs 'Bernoulli set-bernoulli)
(add-menu-function 'PMFs 'Geometric set-geometric)
(add-menu-function 'PMFs 'Pascal set-pascal)
(add-menu-function 'PMFs 'PMFC set-c)
(add-menu-function 'PMFs 'Random set-random)"
\page_exit_text "(remove-menu-function 'PMFs 'Binomial )
(remove-menu-function 'PMFs 'Bernoulli )
(remove-menu-function 'PMFs 'Geometric )
(remove-menu-function 'PMFs 'Pascal )
(remove-menu-function 'PMFs 'PMFC )
(remove-menu-function 'PMFs 'Random )"
\begin_screen
\begin_figure {AtPlotter}
\widget_name "PMFC3" 
\mapping "True"
\constructor_text "(add-barchart 'PMFC3 'pmfc3 18)
(set-barchart-resource 'pmfc3 'xMin 0)
(set-barchart-resource 'pmfc3 'xMax 17) "
title "PMFC = PMF A + PMF B";
xaxis.label "x = possible values of random variable C";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "19";
leftPosition "0";
topPosition "416";
rightPosition "496";
bottomPosition "912";
\end_figure\begin_figure {AtPlotter}
\widget_name "PMFA3" 
\mapping "True"
\constructor_text "(add-barchart 'PMFA3 'pmfa3 10)
(set-barchart-resource 'pmfa3 'xMin 0)
(set-barchart-resource 'pmfa3 'xMax 9)
"
borderWidth "4";
title "PMF A";
xaxis.label "x = possible values of random variable A";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "11";
leftPosition "0";
topPosition "0";
rightPosition "496";
bottomPosition "416";
\end_figure\begin_figure {AtPlotter}
\widget_name "PMFB3" 
\mapping "True"
\constructor_text "(add-barchart 'PMFB3 'pmfb3 10)
(set-barchart-resource 'pmfb3 'xMin 0)
(set-barchart-resource 'pmfb3 'xMax 9)"
title "PMF B";
xaxis.label "x = possible values of random variable B";
yaxis.label "P(x)";
xaxis.min "-1";
xaxis.max "11";
leftPosition "496";
topPosition "0";
rightPosition "992";
bottomPosition "416";
\end_figure\begin_figure {XmToggleButton}
\widget_name "define_b" 
\mapping "True"
\action "Value Changed" "(if (eq? current_pmf 'b)
      (set-resource 'define_b 'set 'true)
      (for (i 0 0)
           (set! current_pmf 'b)
           (set-resource 'define_a 'set 'False)
           (set-resource 'PMFA3 'borderWidth 1)
           (set-resource 'PMFB3 'borderWidth 4)
           (barchart 'pmfa3 pmfa3_list)
           (barchart 'pmfb3 pmfb3_list)))"
fontList "*lucida-*-r-*-*-24-*";
labelString "Define PMF B";
set "false";
leftPosition "748";
topPosition "416";
rightPosition "992";
bottomPosition "512";
\end_figure\begin_figure {XmToggleButton}
\widget_name "define_a" 
\mapping "True"
\action "Value Changed" "(if (eq? current_pmf 'a)
      (set-resource 'define_a 'set 'true)
      (for (i 0 0)
           (set! current_pmf 'a)
           (set-resource 'define_b 'set 'false)
           (set-resource 'PMFA3 'borderWidth 4)
           (set-resource 'PMFB3 'borderWidth 1)
           (barchart 'pmfa3 pmfa3_list)
           (barchart 'pmfb3 pmfb3_list)))"
fontList "*lucida-*-r-*-*-24-*";
labelString "Define PMF A";
set "true";
leftPosition "496";
topPosition "416";
rightPosition "748";
bottomPosition "512";
\end_figure\begin_figure {XmScale}
\widget_name "scale_n" 
\mapping "False"
\action "Drag" "(define n (get-slider-value 'scale_n))
(define p (get-slider-value 'scale_p))
(set! pmf_list (binomial p n 10))
(if (eq? current_pmf 'a) 
      (for (i 0 0)
        (set! pmfa3_list pmf_list)
        (barchart 'pmfa3 pmfa3_list))
       (for (i 0 0)
        (set! pmfb3_list pmf_list)
        (barchart 'pmfb3 pmfb3_list)))
(set! pmfc3_list (convolve pmfa3_list pmfb3_list))
(barchart 'pmfc3  pmfc3_list)"
\action "Value Changed" "(activate-widget 'scale_n 'Drag)"
borderWidth "0";
value "5";
maximum "9";
minimum "1";
titleString "N";
leftPosition "656";
topPosition "512";
rightPosition "736";
bottomPosition "912";
\end_figure\begin_figure {XmScale}
\widget_name "scale_r" 
\mapping "False"
\action "Drag" "(define pmf_list (list 0 0 0 0 0 0 0 0 0 0 ))
(define p (get-slider-value 'scale_p))
(define r (get-slider-value 'scale_r))
(set! pmf_list (pascal p r 10))
(if (eq? current_pmf 'a) 
      (for (i 0 0)
        (set! pmfa3_list pmf_list)
        (barchart 'pmfa3 pmfa3_list))
       (for (i 0 0)
        (set! pmfb3_list pmf_list)
        (barchart 'pmfb3 pmfb3_list)))
(set! pmfc3_list (convolve pmfa3_list pmfb3_list))
(barchart 'pmfc3 pmfc3_list)"
\action "Value Changed" "(activate-widget 'scale_r  'Drag)"
borderWidth "0";
value "8";
maximum "10";
minimum "1";
titleString "R";
leftPosition "672";
topPosition "512";
rightPosition "752";
bottomPosition "912";
\end_figure\begin_figure {XmScale}
\widget_name "scale_p" 
\mapping "True"
\action "Drag" "(define pmf_list (list 0 0 0 0 0 0 0 0 0 0))
(define p (get-slider-value 'scale_p))
(if (eq? pmf_type 'bernoulli) (for (i 0 0)
      (set! pmf_list (replace-nth pmf_list 0 (- 1 p)))
      (set! pmf_list (replace-nth pmf_list 1 p))))
(if (eq? pmf_type 'binomial) (for (i 0 0)
      (define n (get-slider-value 'scale_n))
      (set! pmf_list (binomial p n 10))))
(if (eq? pmf_type 'geometric) (for (i 0 0)
      (set! pmf_list (geometric p 10))))
(if (eq? pmf_type 'pascal) (for (i 0 0)
      (define r (get-slider-value 'scale_r))
      (set! pmf_list (pascal p r 10))))
(if (eq? current_pmf 'a) 
      (for (i 0 0)
        (set! pmfa3_list pmf_list)
        (barchart 'pmfa3 pmfa3_list))
       (for (i 0 0)
        (set! pmfb3_list pmf_list)
        (barchart 'pmfb3 pmfb3_list)))
(set! pmfc3_list (convolve pmfa3_list pmfb3_list))
(barchart 'pmfc3  pmfc3_list)"
\action "Value Changed" "(activate-widget 'scale_p 'Drag)"
borderWidth "0";
value "31";
decimalPoints "2";
titleString "P";
leftPosition "576";
topPosition "512";
rightPosition "656";
bottomPosition "912";
\end_figure\begin_figure {XmScale}
\widget_name "scale_num_points" 
\mapping "False"
\action "Drag" "(define num_p (get-slider-value 'scale_num_points))
(define pmf_list (list 0 0 0 0 0 0 0 0 0 0))
(if (eq? pmf_type 'random)
      (for (i 0 0)
         (for (i 0 (- num_p 1))
              (set! pmf_list (replace-nth pmf_list i (random))))
         (set! pmf_list (map (lambda (x) 
               (/ x (total pmf_list 10))) pmf_list))
         (if (eq? current_pmf 'a)
             (for (i 0 0)
                (set! pmfa3_list pmf_list)
                (barchart 'pmfa3 pmfa3_list))
             (for (i 0 0)
                (set! pmfb3_list pmf_list)
                (barchart 'pmfb3 pmfb3_list)))
          (set! pmfc3_list (convolve pmfa3_list pmfb3_list))
          (barchart 'pmfc3 pmfc3_list)))"
\action "Value Changed" "(activate-widget 'scale_num_points 'Drag)"
borderWidth "0";
value "6";
maximum "10";
minimum "1";
titleString "# points...";
leftPosition "576";
topPosition "512";
rightPosition "704";
bottomPosition "912";
\end_figure\begin_figure {XmScale}
\widget_name "scale_start_at" 
\mapping "False"
borderWidth "0";
value "2";
maximum "9";
titleString "... starting at";
leftPosition "704";
topPosition "512";
rightPosition "864";
bottomPosition "912";
\end_figure\begin_figure {XmLabel}
\widget_name "label_random" 
\mapping "False"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "RANDOM";
leftPosition "656";
topPosition "848";
rightPosition "848";
bottomPosition "928";
\end_figure\begin_figure {XmLabel}
\widget_name "label_PMFC" 
\mapping "False"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "PMFC";
leftPosition "784";
topPosition "832";
rightPosition "896";
bottomPosition "928";
\end_figure\begin_figure {XmLabel}
\widget_name "label_pascal" 
\mapping "False"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "PASCAL";
leftPosition "768";
topPosition "816";
rightPosition "944";
bottomPosition "912";
\end_figure\begin_figure {XmLabel}
\widget_name "label_geometric" 
\mapping "False"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "GEOMETRIC";
leftPosition "672";
topPosition "816";
rightPosition "864";
bottomPosition "912";
\end_figure\begin_figure {XmLabel}
\widget_name "label_binomial" 
\mapping "False"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "BINOMIAL";
leftPosition "736";
topPosition "816";
rightPosition "944";
bottomPosition "912";
\end_figure\begin_figure {XmLabel}
\widget_name "label_bernoulli" 
\mapping "True"
borderWidth "0";
fontList "*lucida-*-r-*-*-24-*";
labelString "BERNOULLI";
leftPosition "656";
topPosition "832";
rightPosition "848";
bottomPosition "912";
\end_figure\begin_figure {XmPushButton}
\widget_name "set_to_this" 
\mapping "False"
\action "Arm" "(define pmf_list (list 0 0 0 0 0 0 0 0 0 0))
(define num_p (get-slider-value 'scale_num_points))
(define at (get-slider-value 'scale_start_at))
(for (j  0 (-  num_p 1))
         (set! pmf_list (replace-nth pmf_list j 
                (nth pmfc3_list (+ j at)))))
(if (eq? current_pmf  'a) 
      (for (i 0 0)
        (set! pmfa3_list pmf_list)
        (barchart 'pmfa3 pmfa3_list))
      (for (i 0 0)
        (set! pmfb3_list pmf_list)
        (barchart 'pmfb3 pmfb3_list)))
(set! pmfc3_list (convolve pmfa3_list pmfb3_list))
(barchart 'pmfc3 pmfc3_list)"
fontList "*lucida-*-r-*-*-24-*";
labelString "SET TO THIS";
leftPosition "592";
topPosition "928";
rightPosition "784";
bottomPosition "992";
\end_figure

\end_screen
\end_node

\begin_node{untitled1}
\title{A Final Word}
\begin_screen

\begin_figure {FormattedText}
\widget_name "credits" 
\mapping "True"
borderWidth "0";
label "@c[
@b(CDS) is the result of years of hard work by students,
staff, and faculty.   Members of @b(Project CDS)  are:
@b( )
Al Drake,
Ed Moriarty,
Dept. of Electrical Engineering & Computer Science
@b()
Jon C. Haass
Dept. of Mathematics
@b( )
Joe Wang
Sourabh Niyogi
Marc Schaub
John Piscitello
Jason Beardsley
Jeff Turcotte
Adam Feder
@b( )
A special thanks is extended to the @b(UROP)
office, whose funding and support is
greatly appreciated.]";
leftPosition "0";
topPosition "0";
rightPosition "992";
bottomPosition "992";
\end_figure\begin_figure {XmLabel}
\widget_name "fuzzy" 
\mapping "True"
borderWidth "0";
labelPixmap "/mit/cds/beta/pixmaps/fuzzball";
labelType "PIXMAP";
leftPosition "48";
topPosition "304";
rightPosition "240";
bottomPosition "816";
\end_figure
\end_screen
\end_node

\end{verbatim}
\end{singlespace}
\end{footnotesize}
