/[ascend]/trunk/doc/syntax.lyx
ViewVC logotype

Annotation of /trunk/doc/syntax.lyx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 828 - (hide annotations) (download) (as text)
Tue Aug 22 02:24:05 2006 UTC (18 years, 3 months ago) by johnpye
File MIME type: application/x-lyx
File size: 162966 byte(s)
Woops, forgot to copy this file to code/branches/extfn/doc.
1 johnpye 828 #LyX 1.4.1 created this file. For more info see http://www.lyx.org/
2     \lyxformat 245
3     \begin_document
4     \begin_header
5     \textclass book
6     \begin_preamble
7     \usepackage[bookmarks]{hyperref}
8     \usepackage{lmodern}
9     \end_preamble
10     \language english
11     \inputencoding auto
12     \fontscheme default
13     \graphics default
14     \paperfontsize default
15     \spacing single
16     \papersize default
17     \use_geometry false
18     \use_amsmath 1
19     \cite_engine basic
20     \use_bibtopic false
21     \paperorientation portrait
22     \secnumdepth 3
23     \tocdepth 3
24     \paragraph_separation indent
25     \defskip medskip
26     \quotes_language english
27     \papercolumns 1
28     \papersides 1
29     \paperpagestyle default
30     \tracking_changes false
31     \output_changes false
32     \end_header
33    
34     \begin_body
35    
36     \begin_layout Chapter
37     Syntax and semantics
38     \begin_inset LatexCommand \label{cha:ASCENDSyntax}
39    
40     \end_inset
41    
42    
43     \end_layout
44    
45     \begin_layout Standard
46     We shall present an informal description of the ASCEND IV language.
47     Being informal, we shall usually include examples and descriptions of the
48     intended semantics along with the syntax of the items.
49     At times the inclusion of semantics will seem to anticipate later definitions.
50     We do this because we would also like this chapter to be used as a reference
51     for the ASCEND language even after one generally understands it.
52     Often one will need to clarify a point about a particular item and will
53     not wish to have to search in several places to do so.
54     \end_layout
55    
56     \begin_layout Standard
57     Syntax
58     \begin_inset LatexCommand \index{syntax}
59    
60     \end_inset
61    
62     is the form or structure for the statements in ASCEND, where one worries
63     about the exact words one uses, their ordering, the punctuation, etc.
64     Semantics
65     \begin_inset LatexCommand \index{semantics}
66    
67     \end_inset
68    
69     describe the meaning of a statement.
70     \end_layout
71    
72     \begin_layout Standard
73     To distinguish between syntax and semantics, consider the statement
74     \end_layout
75    
76     \begin_layout LyX-Code
77     y IS_A fraction;
78     \end_layout
79    
80     \begin_layout Standard
81     Rules on the syntax for this statement tell us we need a user supplied instance
82     name, y, followed by the ASCEND operator IS_A, followed by a type name
83     (fraction).
84     The statement terminates with a semicolon.
85     The statement semantics says we are declaring the existence of an instance,
86     locally named y, of the type fraction as a part within the current model
87     definition and it is to be constructed when an instance of the current
88     model definition is constructed.
89     \end_layout
90    
91     \begin_layout Standard
92     The syntax for a computer language is often defined by using a Bachus-Naur
93     \begin_inset LatexCommand \index{Bachus-Naur}
94    
95     \end_inset
96    
97     formal (BNF
98     \begin_inset LatexCommand \index{BNF}
99    
100     \end_inset
101    
102     ) description.
103     The complete YACC
104     \begin_inset LatexCommand \index{YACC}
105    
106     \end_inset
107    
108     and FLEX
109     \begin_inset LatexCommand \index{FLEX}
110    
111     \end_inset
112    
113     description of the language described (as presently implemented) is available
114     by FTP and via the World Wide Web.
115     The semantics of a very high level modeling language such as ASCEND IV
116     are generally much more restrictive than the syntax.
117     For this reason we do not include a BNF description in this paper.
118     ASCEND IV is an experiment.
119     The language is under constant scrutiny and improvement, so this document
120     is under constant revision.
121    
122     \end_layout
123    
124     \begin_layout List
125     \labelwidthstring 00000.00000.00000.000
126     \InsetSpace ~
127    
128     \end_layout
129    
130     \begin_deeper
131     \begin_layout Section
132     Preliminaries
133     \end_layout
134    
135     \begin_layout Standard
136     We will start off with some background information and some tips that make
137     the rest of the chapter easier to read.
138     ASCEND is an object-oriented (OO) language for hierarchical modeling that
139     has been somewhat specialized for mathematical models.
140     Most of the specialization is in the implementation and the user interface
141     rather than the language definition.
142    
143     \end_layout
144    
145     \begin_layout Standard
146     We feel the single most distinguishing feature of mathematical models is
147     that solving them efficiently requires that the solving algorithms be able
148     to address the entire problem either simultaneously or in a decomposition
149     of the natural problem structure that the algorithm determines is best
150     for the machine(s) in use.
151     In the ASCEND language object-orientation is used to organize natural structure
152     s and make them easier to understand.
153     It is not used to hide the details of the objects.
154     The user (or machine) is free to ignore uninteresting details, and the
155     ASCEND environment provides tools for the runtime suppression of these.
156     \end_layout
157    
158     \begin_layout Standard
159     ASCEND is well into its 4th generation.
160     Some features we will describe are not yet implemented (some merely speculative
161     ) and these are clearly marked (* 4+ *).
162     Any feature not marked (* 4+ *)has been completely implemented, and thus
163     any mismatch between the description given here and the software we distribute
164     is a bug we want you to tell us about.
165    
166     \end_layout
167    
168     \begin_layout Standard
169     The syntax and semantics of ASCEND may seem at first a bit unusual.
170     However, do not be afraid to just try what comes naturally if what we write
171     here is unclear.
172     The parser and compiler of ASCEND IV really will help you get things right.
173     Of course if what we write here is unclear, please ask us about it because
174     we aim to continuously improve both this document and the language system
175     it describes.
176     \end_layout
177    
178     \begin_layout Standard
179     We will describe, starting in Section
180     \begin_inset LatexCommand \vref{sub:x.1.2Basic-Elements}
181    
182     \end_inset
183    
184     , the higher level concepts of ASCEND, but first some important punctuation
185     rules.
186     \end_layout
187    
188     \end_deeper
189     \begin_layout List
190     \labelwidthstring 00000.00000.00000.000
191     ASCEND\InsetSpace ~
192     is\InsetSpace ~
193     cAsE\InsetSpace ~
194     sensitive
195     \begin_inset LatexCommand \index{case sensitive}
196    
197     \end_inset
198    
199     !
200     \end_layout
201    
202     \begin_deeper
203     \begin_layout Standard
204     The keywords that are shown capitalized (or in lower case) in this chapter
205     are that way because ASCEND is case sensitive.
206     IS_A is an ASCEND keyword; isa, Is_a, and all the other permutations you
207     can think of are NOT equivalent to IS_A.
208     In declaring new types of models and variables the user is free to use
209     any style of capitalization he or she may prefer; however, they must remain
210     consistent or undefined types and instances will result.
211     \end_layout
212    
213     \begin_layout Standard
214     This case restriction makes our code very readable, but hard to type without
215     a smart editor.
216     We have kept the case-sensitivity because, like all mathematicians, we
217     find ourselves running out of good variable names if we are restricted
218     to a 26 letter alphabet.
219     We have developed smart add-ins for two UNIX editors, EMACS
220     \begin_inset LatexCommand \index{EMACS}
221    
222     \end_inset
223    
224     and vi
225     \begin_inset LatexCommand \index{vi}
226    
227     \end_inset
228    
229     , for handling the upper case keywords and some other syntax elements.
230     The use of these editors is described in another chapter.
231    
232     \end_layout
233    
234     \begin_layout Standard
235     The ASCEND IV parser is very picky and pedantic.
236     It also tries to give helpful messages and occasionally even suggestions.
237     New users should just dive in and make errors, letting the system help
238     them learn how to avoid errors.
239     \end_layout
240    
241     \begin_layout Subsection
242     Punctuation
243     \begin_inset LatexCommand \index{punctuation}
244    
245     \end_inset
246    
247    
248     \end_layout
249    
250     \begin_layout Standard
251     This section covers both the punctuation that must be understood to read
252     this document and the punctuation of ASCEND code.
253     \end_layout
254    
255     \end_deeper
256     \begin_layout List
257     \labelwidthstring 00000.00000.00000.000
258     keywords
259     \begin_inset LatexCommand \index{keywords}
260    
261     \end_inset
262    
263     : ASCEND keywords and type names are given in the left column in bold format.
264     It is generally clear from the main text which are keywords and which are
265     type names.
266     \end_layout
267    
268     \begin_layout List
269     \labelwidthstring 00000.00000.00000.000
270    
271     \bar under
272     Minor\InsetSpace ~
273     items:
274     \bar default
275     Minor headings that are helpful in finding details are given in the left
276     column in underline format.
277     \end_layout
278    
279     \begin_layout List
280     \labelwidthstring 00000.00000.00000.000
281     Tips: Special notes and hints are sometimes placed on the left.
282     \end_layout
283    
284     \begin_layout List
285     \labelwidthstring 00000.00000.00000.000
286    
287     \bar under
288     *3*
289     \begin_inset LatexCommand \index{*3*}
290    
291     \end_inset
292    
293     :
294     \bar default
295     This indicates that what follows is specific to ASCEND IIIc and may disappear
296     in a future version of ASCEND IV.
297     Generally ASCEND IV will provide some equivalent functionality at 1/10th
298     of the ASCEND III price.
299     \end_layout
300    
301     \begin_layout List
302     \labelwidthstring 00000.00000.00000.000
303    
304     \bar under
305     *4*
306     \bar default
307    
308     \begin_inset LatexCommand \index{*4*}
309    
310     \end_inset
311    
312     This indicates that what follows is specific to ASCEND IV and may not be
313     available in ASCEND IIIc.
314     Generally ASCEND III may provide some very klugey equivalent functionality,
315     often at a very high price in terms of increased compilation time or debugging
316     difficulty.
317     \end_layout
318    
319     \begin_layout List
320     \labelwidthstring 00000.00000.00000.000
321    
322     \bar under
323     *4+*
324     \bar default
325    
326     \begin_inset LatexCommand \index{*4+*}
327    
328     \end_inset
329    
330     ASCEND IV functionality that is not fully implemented at the time of this
331     writing.
332     The precise syntax of the final implementation may vary slightly from what
333     is presented here.
334     A revision of this document will be made at the time of implementation.
335     \end_layout
336    
337     \begin_layout List
338     \labelwidthstring 00000.00000.00000.000
339    
340     \bar under
341     LHS
342     \begin_inset LatexCommand \index{LHS}
343    
344     \end_inset
345    
346     :
347     \bar default
348     Left Hand Side.
349     Abbreviation used frequently.
350     \end_layout
351    
352     \begin_layout List
353     \labelwidthstring 00000.00000.00000.000
354    
355     \bar under
356     RHS
357     \begin_inset LatexCommand \index{RHS}
358    
359     \end_inset
360    
361     :
362     \bar default
363     Right Hand Side.
364     Abbreviation used frequently.
365     \end_layout
366    
367     \begin_layout List
368     \labelwidthstring 00000.00000.00000.000
369    
370     \bar under
371     Simple\InsetSpace ~
372     names
373     \begin_inset LatexCommand \index{simple names}
374    
375     \end_inset
376    
377     :
378     \bar default
379     In ASCEND simple names are made of the characters a through z, A through
380     Z, _, (*4+*: $).
381     The underscore is used as a letter, but it cannot be the first letter in
382     a name.
383     The $
384     \begin_inset LatexCommand \index{\$}
385    
386     \end_inset
387    
388     character is used exclusively as the first character in the name of system
389     defined built-in parts.
390     "$" is explained in more detail in Section
391     \begin_inset LatexCommand \vref{sub:x.6.2Supported-attributes}
392    
393     \end_inset
394    
395     .
396     Simple names should be no more than 80 characters long.
397    
398     \end_layout
399    
400     \begin_layout List
401     \labelwidthstring 00000.00000.00000.000
402    
403     \bar under
404     Compound\InsetSpace ~
405     names
406     \begin_inset LatexCommand \index{compound names}
407    
408     \end_inset
409    
410     :
411     \bar default
412     Compound names are simple names strung together with dots (.).
413     See the description of "." below.
414     \end_layout
415    
416     \begin_layout List
417     \labelwidthstring 00000.00000.00000.000
418    
419     \bar under
420     Groupings:
421     \end_layout
422    
423     \begin_layout List
424     \labelwidthstring 00000.00000.00000.000
425    
426     \bar under
427     «\InsetSpace ~
428     »
429     \bar default
430     In documentation optional fields
431     \begin_inset LatexCommand \index{optional fields}
432    
433     \end_inset
434    
435     are surrounded by these markers.
436     \end_layout
437    
438     \begin_layout List
439     \labelwidthstring 00000.00000.00000.000
440     (*\InsetSpace ~
441     *)
442     \begin_inset LatexCommand \index{(* *)}
443    
444     \end_inset
445    
446     Comment.
447     *3* Anything inside these is a comment.
448     Comments DO NOT nest in ASCEND IIIc.
449     Comments may extend over many lines.
450     *4* Comments DO nest
451     \begin_inset LatexCommand \index{nest}
452    
453     \end_inset
454    
455     in ASCEND IV.
456     \end_layout
457    
458     \begin_layout List
459     \labelwidthstring 00000.00000.00000.000
460     (\InsetSpace ~
461     )
462     \begin_inset LatexCommand \index{( )}
463    
464     \end_inset
465    
466     Rounded parentheses
467     \begin_inset LatexCommand \index{parentheses}
468    
469     \end_inset
470    
471    
472     \begin_inset LatexCommand \index{rounded parentheses}
473    
474     \end_inset
475    
476     .
477     Used to enclose arguments for functions or models where the order of the
478     arguments matters.
479     Also used to group terms in complex arithmetic, logical, or set expressions
480     where the order of operations needs to be specified.
481    
482     \end_layout
483    
484     \begin_layout List
485     \labelwidthstring 00000.00000.00000.000
486     Efficiency\InsetSpace ~
487     tip: The compiler can simplify relation definitions in a particularly
488     efficient manner if constants are grouped together.
489     \end_layout
490    
491     \begin_layout List
492     \labelwidthstring 00000.00000.00000.000
493     {\InsetSpace ~
494     }
495     \begin_inset LatexCommand \index{{ }}
496    
497     \end_inset
498    
499     Curly braces
500     \begin_inset LatexCommand \index{Curly braces}
501    
502     \end_inset
503    
504     .
505     Used to enclose units.
506     For example, 1 {kg_mole/s}.
507     Also used to enclose the body of annotations.
508     Note: Curly braces are also used in TCL, the language of the ASCEND user
509     interface, about which we will say more in another chapter.
510     \end_layout
511    
512     \begin_layout List
513     \labelwidthstring 00000.00000.00000.000
514     [\InsetSpace ~
515     ]
516     \begin_inset LatexCommand \index{[ ]}
517    
518     \end_inset
519    
520     Square brackets
521     \begin_inset LatexCommand \index{square brackets}
522    
523     \end_inset
524    
525     .
526     Used to enclose sets or elements of sets.
527     Examples: my_integer_set :== [1,2,3], demonstrates the use of square brackets
528     in the assignment of a set.
529     My_array[1] demonstrates the use of square brackets in naming an array
530     object indexed over an integer set which includes the element 1.
531     \end_layout
532    
533     \begin_layout List
534     \labelwidthstring 00000.00000.00000.000
535     .
536     \begin_inset LatexCommand \index{.}
537    
538     \end_inset
539    
540     Dot
541     \begin_inset LatexCommand \index{dot}
542    
543     \end_inset
544    
545     .
546     The dot is used, as in PASCAL and C, to construct the names of nested objects.
547     Examples: if object a has a part b, then the way to refer to b is as a.b.
548     Tray[1].vle shows a dot following a square bracket; here Tray[1] has a part
549     named vle.
550     \end_layout
551    
552     \begin_layout List
553     \labelwidthstring 00000.00000.00000.000
554     ..
555     \begin_inset LatexCommand \index{..}
556    
557     \end_inset
558    
559     Dot-dot or double dot
560     \begin_inset LatexCommand \index{double dot}
561    
562     \end_inset
563    
564     .
565     Integer range shorthand.
566     For example, my_integer_set :== [1,2,3] and my_integer_set :== [1..3] are
567     equivalent.
568     If ..
569     appears in a context requiring (), such as the ALIASES/IS_A statement,
570     then the range is expanded and ordered as we would naturally expect.
571     \end_layout
572    
573     \begin_layout List
574     \labelwidthstring 00000.00000.00000.000
575     :
576     \begin_inset LatexCommand \index{:}
577    
578     \end_inset
579    
580     Colon
581     \begin_inset LatexCommand \index{colon}
582    
583     \end_inset
584    
585     .
586     A separator used in various ways, principally to set the name of an arithmetic
587     relation apart from the definition.
588     \end_layout
589    
590     \begin_layout List
591     \labelwidthstring 00000.00000.00000.000
592     ::
593     \begin_inset LatexCommand \index{::}
594    
595     \end_inset
596    
597     Double colon
598     \begin_inset LatexCommand \index{double colon}
599    
600     \end_inset
601    
602     .
603     A separator used in the methods section for accessing methods defined on
604     types other than the type the method is part of.
605     Explained in Section
606     \begin_inset LatexCommand \vref{sec:x.4Procedural-statements}
607    
608     \end_inset
609    
610     .[
611     \end_layout
612    
613     \begin_layout List
614     \labelwidthstring 00000.00000.00000.000
615     ;
616     \begin_inset LatexCommand \index{;}
617    
618     \end_inset
619    
620     Semicolon
621     \begin_inset LatexCommand \index{semicolon}
622    
623     \end_inset
624    
625     .
626     The separator of statements.
627     \end_layout
628    
629     \begin_deeper
630     \begin_layout Subsection
631     Basic Elements
632     \begin_inset LatexCommand \index{basic elements}
633    
634     \end_inset
635    
636    
637     \begin_inset LatexCommand \label{sub:x.1.2Basic-Elements}
638    
639     \end_inset
640    
641    
642     \end_layout
643    
644     \end_deeper
645     \begin_layout List
646     \labelwidthstring 00000.00000.00000.000
647    
648     \bar under
649     Boolean\InsetSpace ~
650     value
651     \bar default
652    
653     \begin_inset LatexCommand \index{value, Boolean}
654    
655     \end_inset
656    
657    
658     \begin_inset LatexCommand \index{Boolean value}
659    
660     \end_inset
661    
662     TRUE
663     \begin_inset LatexCommand \index{TRUE}
664    
665     \end_inset
666    
667     or FALSE
668     \begin_inset LatexCommand \index{FALSE}
669    
670     \end_inset
671    
672     .
673     Can't get much simpler, eh? In the language definition TRUE and FALSE do
674     not map to 1 and 0 or any other type of numeric value.
675     (In the implementation, of course, they do.)
676     \end_layout
677    
678     \begin_layout List
679     \labelwidthstring 00000.00000.00000.000
680     User\InsetSpace ~
681     interface\InsetSpace ~
682     tip: The ASCEND user interface programmers have found it very
683     convenient, however, to allow T/F, 1/0, Y/N, and other obvious boolean
684     conventions as interactive input when assigning boolean values.
685     We are lazy users.
686     \end_layout
687    
688     \begin_layout List
689     \labelwidthstring 00000.00000.00000.000
690    
691     \bar under
692     Integer\InsetSpace ~
693     value
694     \bar default
695    
696     \begin_inset LatexCommand \index{value, integer}
697    
698     \end_inset
699    
700    
701     \begin_inset LatexCommand \index{integer value}
702    
703     \end_inset
704    
705     A signed whole number up to the maximum that can be represented by the
706     computer on which one is running ASCEND.
707     MAX_INTEGER
708     \begin_inset LatexCommand \index{MAX\_INTEGER}
709    
710     \end_inset
711    
712     is machine dependent.
713     Examples are:
714     \end_layout
715    
716     \begin_deeper
717     \begin_layout LyX-Code
718     \align block
719     123
720     \end_layout
721    
722     \begin_layout LyX-Code
723     \align block
724     -5
725     \end_layout
726    
727     \begin_layout LyX-Code
728     \align block
729     MAX_INTEGER, typically 2147483647.
730     \end_layout
731    
732     \end_deeper
733     \begin_layout List
734     \labelwidthstring 00000.00000.00000.000
735    
736     \bar under
737     Real\InsetSpace ~
738     value
739     \bar default
740    
741     \begin_inset LatexCommand \index{value. real}
742    
743     \end_inset
744    
745    
746     \begin_inset LatexCommand \index{real value}
747    
748     \end_inset
749    
750     ASCEND represents reals almost exactly as any other mathematically oriented
751     programming language does.
752     The mantissa
753     \begin_inset LatexCommand \index{mantissa}
754    
755     \end_inset
756    
757     has an optional negative sign followed by a string of digits and at most
758     one decimal point.
759     The exponent is the letter e or E followed by an integer.
760     The number must not exceed the largest the computer is able to handle.
761     There can be no blank characters in a real.
762     MAX_REAL
763     \begin_inset LatexCommand \index{MAX\_REAL}
764    
765     \end_inset
766    
767     is machine dependent.
768     The following are legitimate reals in ASCEND:
769     \end_layout
770    
771     \begin_deeper
772     \begin_layout LyX-Code
773     \align block
774     -1
775     \end_layout
776    
777     \begin_layout LyX-Code
778     \align block
779     1.2
780     \end_layout
781    
782     \begin_layout LyX-Code
783     \align block
784     1.3e-2
785     \end_layout
786    
787     \begin_layout LyX-Code
788     \align block
789     7.888888e+34
790     \end_layout
791    
792     \begin_layout LyX-Code
793     \align block
794     .6E21
795     \end_layout
796    
797     \begin_layout LyX-Code
798     \align block
799     MAX_REAL, typically about 1.79E+308.
800     \end_layout
801    
802     \begin_layout Standard
803     while the following are not:
804     \end_layout
805    
806     \begin_layout LyX-Code
807     \align block
808     1.
809     2 (*contains a blank within it*)
810     \end_layout
811    
812     \begin_layout LyX-Code
813     \align block
814     1.3e2.0 (*exponent has a decimal in it*)
815     \end_layout
816    
817     \begin_layout List
818     \labelwidthstring 00000.00000.00000.000
819     +1.3 (* illegal unary + sign.
820     x = +1.3 not allowed*)
821     \end_layout
822    
823     \end_deeper
824     \begin_layout List
825     \labelwidthstring 00000.00000.00000.000
826    
827     \bar under
828     Reals\InsetSpace ~
829     stored\InsetSpace ~
830     in\InsetSpace ~
831     SI
832     \begin_inset LatexCommand \index{SI}
833    
834     \end_inset
835    
836     \InsetSpace ~
837     units
838     \bar default
839    
840     \end_layout
841    
842     \begin_deeper
843     \begin_layout Standard
844     We store all real values as double precision
845     \begin_inset LatexCommand \index{double precision}
846    
847     \end_inset
848    
849     numbers in the MKS
850     \begin_inset LatexCommand \index{MKS}
851    
852     \end_inset
853    
854     system of units.
855     This eliminates many common errors in the modeling of physical systems.
856     Since we also place the burden of scaling equations on system routines
857     and a simple modeling methodology, the internal units are not of concern
858     to most users.
859     \end_layout
860    
861     \end_deeper
862     \begin_layout List
863     \labelwidthstring 00000.00000.00000.000
864    
865     \bar under
866     Dimensionality
867     \begin_inset LatexCommand \index{dimensionality}
868    
869     \end_inset
870    
871     :
872     \bar default
873     Real values have dimensionality such as length/time for velocity.
874     Dimensionality is to be distinguished from the units such as ft/s.
875     ASCEND takes care of mapping between units
876     \begin_inset LatexCommand \index{units}
877    
878     \end_inset
879    
880     and dimensions.
881     A value without units (this includes integer values) is taken to be dimensionle
882     ss
883     \begin_inset LatexCommand \index{dimensionless}
884    
885     \end_inset
886    
887     .
888     Dimensionality is built up from the following base dimensions:
889     \end_layout
890    
891     \begin_layout List
892     \labelwidthstring 00000.00000.00000.000
893     Name
894     \bar under
895     definition; typical units
896     \end_layout
897    
898     \begin_layout List
899     \labelwidthstring 00000.00000.00000.000
900     L
901     \begin_inset LatexCommand \index{L, length dimension}
902    
903     \end_inset
904    
905     length
906     \begin_inset LatexCommand \index{length}
907    
908     \end_inset
909    
910     ; meter, m
911     \end_layout
912    
913     \begin_layout List
914     \labelwidthstring 00000.00000.00000.000
915     M
916     \begin_inset LatexCommand \index{M, mass dimension}
917    
918     \end_inset
919    
920     mass
921     \begin_inset LatexCommand \index{mass}
922    
923     \end_inset
924    
925     ; kilogram, kg
926     \end_layout
927    
928     \begin_layout List
929     \labelwidthstring 00000.00000.00000.000
930     T
931     \begin_inset LatexCommand \index{T, time dimension}
932    
933     \end_inset
934    
935     time
936     \begin_inset LatexCommand \index{time}
937    
938     \end_inset
939    
940     ; second, s
941     \end_layout
942    
943     \begin_layout List
944     \labelwidthstring 00000.00000.00000.000
945     E
946     \begin_inset LatexCommand \index{E, electric current dimension}
947    
948     \end_inset
949    
950     electric current
951     \begin_inset LatexCommand \index{electric current}
952    
953     \end_inset
954    
955     ; ampere, A
956     \end_layout
957    
958     \begin_layout List
959     \labelwidthstring 00000.00000.00000.000
960     Q
961     \begin_inset LatexCommand \index{Q, quantity dimension}
962    
963     \end_inset
964    
965     quantity
966     \begin_inset LatexCommand \index{quantity}
967    
968     \end_inset
969    
970     ; mole, mole
971     \end_layout
972    
973     \begin_layout List
974     \labelwidthstring 00000.00000.00000.000
975     TMP
976     \begin_inset LatexCommand \index{TMP, temperature dimension}
977    
978     \end_inset
979    
980     temperature
981     \begin_inset LatexCommand \index{temperature}
982    
983     \end_inset
984    
985     ; Kelvin, K
986     \end_layout
987    
988     \begin_layout List
989     \labelwidthstring 00000.00000.00000.000
990     LUM
991     \begin_inset LatexCommand \index{LUM, luminous intensity dimension}
992    
993     \end_inset
994    
995     luminous intensity
996     \begin_inset LatexCommand \index{luminous intensity}
997    
998     \end_inset
999    
1000     ; candela, cd
1001     \end_layout
1002    
1003     \begin_layout List
1004     \labelwidthstring 00000.00000.00000.000
1005     P
1006     \begin_inset LatexCommand \index{P, phase angle dimension}
1007    
1008     \end_inset
1009    
1010     plane angle
1011     \begin_inset LatexCommand \index{plane angle}
1012    
1013     \end_inset
1014    
1015     ; radian, rad
1016     \end_layout
1017    
1018     \begin_layout List
1019     \labelwidthstring 00000.00000.00000.000
1020     S
1021     \begin_inset LatexCommand \index{S, solid angle dimension}
1022    
1023     \end_inset
1024    
1025     solid angle
1026     \begin_inset LatexCommand \index{solid angle}
1027    
1028     \end_inset
1029    
1030     ; steradian, srad
1031     \end_layout
1032    
1033     \begin_layout List
1034     \labelwidthstring 00000.00000.00000.000
1035     C
1036     \begin_inset LatexCommand \index{C, currency dimension}
1037    
1038     \end_inset
1039    
1040     currency
1041     \begin_inset LatexCommand \index{currency}
1042    
1043     \end_inset
1044    
1045     ; currency, CR
1046     \end_layout
1047    
1048     \begin_deeper
1049     \begin_layout Standard
1050     The atom and constant definitions in the library illustrate the use of dimension
1051     ality.
1052     \end_layout
1053    
1054     \begin_layout Standard
1055     Dimensions may be any combination of these symbols along with rounded parenthese
1056     s, (), and the operators *, ^ and /.
1057     Examples include M/T or M*L^2/T^2/TMP {this latter means (M*(L^2)/(T^2))/TMP}.
1058     The second operand for the to the power operator, ^, must be an integer
1059     value (e.g., -2 or 3) because fractional powers of dimensional numbers are
1060     physically undefined.
1061     \end_layout
1062    
1063     \begin_layout Standard
1064     If the dimensionality for a real value is undefined, then ASCEND gives it
1065     a wild card dimensionality
1066     \begin_inset LatexCommand \index{wild card dimensionality}
1067    
1068     \end_inset
1069    
1070     .
1071     If ASCEND can later deduce its dimensionality from its use in a model definitio
1072     n it will do so.
1073     For example consider the real variable a, suppose a has wild card dimensionalit
1074     y, b has dimensionality of L/T.
1075     Then the statement:
1076     \end_layout
1077    
1078     \end_deeper
1079     \begin_layout List
1080     \labelwidthstring 00000.00000.00000.000
1081     Example\InsetSpace ~
1082     of\InsetSpace ~
1083     a\InsetSpace ~
1084     dimensionally\InsetSpace ~
1085     consistent
1086     \begin_inset LatexCommand \index{dimensionally consistent}
1087    
1088     \end_inset
1089    
1090     \InsetSpace ~
1091     equation.
1092    
1093     \end_layout
1094    
1095     \begin_layout List
1096     \labelwidthstring 00000.00000.00000.000
1097     \InsetSpace ~
1098     a + b = 3 {ft/s};
1099     \end_layout
1100    
1101     \begin_deeper
1102     \begin_layout Standard
1103     requires that a have the same dimensionality as the other two terms, namely,
1104     L/T.
1105     ASCEND will assign this dimensionality to a.
1106     The user will be warned of dimensionally inconsistent equations.
1107     \end_layout
1108    
1109     \end_deeper
1110     \begin_layout List
1111     \labelwidthstring 00000.00000.00000.000
1112    
1113     \bar under
1114     Unit\InsetSpace ~
1115     expression
1116     \bar default
1117     A unit expression
1118     \begin_inset LatexCommand \index{unit expression}
1119    
1120     \end_inset
1121    
1122     may be composed of any combination of unit names defined by the system
1123     and any numerical constants combined with times (*), divide(/) and to the
1124     power (^) operators.
1125     The RHS of ^ must be an integer.
1126     Parentheses can be used to group subexpressions EXCEPT a divide operator
1127     may not be followed by a grouped subexpression.
1128    
1129     \end_layout
1130    
1131     \begin_deeper
1132     \begin_layout Standard
1133     So, {kg/m/s} is fine, but {kg/(m*s)} is not.
1134     Although the two expressions are mathematically equivalent, it makes the
1135     system programming and output formatting easier to code and faster to execute
1136     if we disallow expressions of the latter sort.
1137     \end_layout
1138    
1139     \begin_layout Standard
1140     The units understood by the system are defined in the
1141     \begin_inset Quotes eld
1142     \end_inset
1143    
1144     howTo
1145     \begin_inset LatexCommand \cite{key-1}
1146    
1147     \end_inset
1148    
1149    
1150     \begin_inset Quotes erd
1151     \end_inset
1152    
1153     book available on the ASCEND web site.
1154     Note that several units defined are really values of interesting constants
1155     in SI, e.g.
1156     R :== 1{GAS_C} yields the correct value of the thermodynamic gas constant.
1157     Users can define additional units.
1158     \end_layout
1159    
1160     \end_deeper
1161     \begin_layout List
1162     \labelwidthstring 00000.00000.00000.000
1163    
1164     \bar under
1165     Units
1166     \bar default
1167    
1168     \begin_inset LatexCommand \index{units}
1169    
1170     \end_inset
1171    
1172     A Unit expression unit expression must be enclosed in curly braces {}.
1173     When a real number is used in a mathematical expression in ASCEND, it must
1174     have a set of units expressed with it.
1175     If it does not, ASCEND assumes the number is dimensionless, which may not
1176     be the intent of the modeler.
1177     An example is shown in the dimensionally consistent equation above where
1178     the number 3 has the units {ft/s} associated with it.
1179    
1180     \end_layout
1181    
1182     \begin_deeper
1183     \begin_layout Standard
1184     Examples:
1185     \end_layout
1186    
1187     \begin_layout LyX-Code
1188     \align block
1189     {kg_mole/s/m} same as {(kg_mole/s)/m}
1190     \end_layout
1191    
1192     \begin_layout LyX-Code
1193     \align block
1194     {m^3/yr}
1195     \end_layout
1196    
1197     \begin_layout LyX-Code
1198     \align block
1199     {3/100*ft} same as {0.03*ft}
1200     \end_layout
1201    
1202     \begin_layout LyX-Code
1203     \align block
1204     {s^-1} same as {1/s}
1205     \end_layout
1206    
1207     \begin_layout Standard
1208     Illegal unit examples are
1209     \end_layout
1210    
1211     \begin_layout LyX-Code
1212     \align block
1213     {m/(K*kg_mole)}
1214     \end_layout
1215    
1216     \begin_deeper
1217     \begin_layout Standard
1218     grouped subexpression used in the denominator; should be written {m/K/kg_mole}.
1219     \end_layout
1220    
1221     \end_deeper
1222     \begin_layout LyX-Code
1223     \align block
1224     {m^3.5}
1225     \end_layout
1226    
1227     \begin_deeper
1228     \begin_layout Standard
1229     power of units or dimensions must be integer.
1230     \end_layout
1231    
1232     \end_deeper
1233     \end_deeper
1234     \begin_layout List
1235     \labelwidthstring 00000.00000.00000.000
1236    
1237     \bar under
1238     Symbol\InsetSpace ~
1239     Value
1240     \bar default
1241    
1242     \begin_inset LatexCommand \index{value, symbol}
1243    
1244     \end_inset
1245    
1246    
1247     \begin_inset LatexCommand \index{symbol value}
1248    
1249     \end_inset
1250    
1251     The format for a symbol is that of an arbitrary character string enclosed
1252     between two single quotes.
1253     There is no way to embed a single quote
1254     \begin_inset LatexCommand \index{'}
1255    
1256     \end_inset
1257    
1258    
1259     \begin_inset LatexCommand \index{single quote}
1260    
1261     \end_inset
1262    
1263     in a symbol: we are not in the escape sequence business at this time.
1264     The following are legal symbols in ASCEND:
1265     \end_layout
1266    
1267     \begin_deeper
1268     \begin_layout LyX-Code
1269     'H2O'
1270     \end_layout
1271    
1272     \begin_layout LyX-Code
1273     'r1'
1274     \end_layout
1275    
1276     \begin_layout LyX-Code
1277     'Bill said,foo to whom?'
1278     \end_layout
1279    
1280     \begin_layout Standard
1281     while the following are not legal symbol values:
1282     \end_layout
1283    
1284     \begin_layout LyX-Code
1285     "ethanol" (double quotes not allowed)
1286     \end_layout
1287    
1288     \begin_layout LyX-Code
1289     water (no single quotes given)
1290     \end_layout
1291    
1292     \begin_layout LyX-Code
1293     i cant do this (no embedded quotes)
1294     \end_layout
1295    
1296     \begin_layout Standard
1297     There is an arbitrary upper limit to the number of characters in a symbol
1298     (something like 10,000) so that we may detect a missing close quote in
1299     a bad input file without crashing.
1300     \end_layout
1301    
1302     \end_deeper
1303     \begin_layout List
1304     \labelwidthstring 00000.00000.00000.000
1305     Sets\InsetSpace ~
1306     values
1307     \begin_inset LatexCommand \index{values, set}
1308    
1309     \end_inset
1310    
1311    
1312     \begin_inset LatexCommand \index{set values}
1313    
1314     \end_inset
1315    
1316     Set values are lists of elements, all of type integer_constant or all of
1317     type symbol_constant, enclosed between square brackets [].
1318     The following are examples of sets:
1319     \end_layout
1320    
1321     \begin_deeper
1322     \begin_layout LyX-Code
1323     \align block
1324     ['methane', 'ethane', 'propane']
1325     \end_layout
1326    
1327     \begin_layout LyX-Code
1328     \align block
1329     [1..5, 7, 15]
1330     \end_layout
1331    
1332     \begin_layout LyX-Code
1333     \align block
1334     [2..n_stages]
1335     \end_layout
1336    
1337     \begin_layout LyX-Code
1338     \align block
1339     [1, 4, 2, 1, 16]
1340     \end_layout
1341    
1342     \begin_layout LyX-Code
1343     \align block
1344     []
1345     \end_layout
1346    
1347     \end_deeper
1348     \begin_layout List
1349     \labelwidthstring 00000.00000.00000.000
1350     More\InsetSpace ~
1351     about\InsetSpace ~
1352     sets
1353     \begin_inset LatexCommand \index{sets}
1354    
1355     \end_inset
1356    
1357     \InsetSpace ~
1358     in\InsetSpace ~
1359     Section\InsetSpace ~
1360    
1361     \begin_inset LatexCommand \vref{sub:x.2.2Sets}
1362    
1363     \end_inset
1364    
1365     .
1366     \end_layout
1367    
1368     \begin_deeper
1369     \begin_layout Standard
1370     The value range 1..5 is an allowable shorthand for the integers 1, 2, 3, 4
1371     and 5 while the value range 2..n_stages (where n_stages must be of type integer_c
1372     onstant) means all integers from 2 to n_stages.
1373     If n_stages is less than 2, then the third set is empty.
1374     The repeated occurrence of 1 in the fourth set is ignored.
1375     The fifth set is the empty set
1376     \begin_inset LatexCommand \index{empty set}
1377    
1378     \end_inset
1379    
1380    
1381     \begin_inset LatexCommand \index{set, empty}
1382    
1383     \end_inset
1384    
1385     .
1386     \end_layout
1387    
1388     \begin_layout Standard
1389     We use the term set in an almost pure mathematical sense.
1390     The elements have no order.
1391     One can only ask two things of a set: (1) if an element is a member of
1392     it and (2) its cardinality
1393     \begin_inset LatexCommand \index{cardinality}
1394    
1395     \end_inset
1396    
1397     (CARD
1398     \begin_inset LatexCommand \index{CARD}
1399    
1400     \end_inset
1401    
1402     (set)).
1403     Repeated elements used in defining a set are ignored.
1404     The elements of sets cannot themselves be sets in ASCEND; i.e., there can
1405     be no sets of set.
1406     \end_layout
1407    
1408     \end_deeper
1409     \begin_layout List
1410     \labelwidthstring 00000.00000.00000.000
1411     Sets\InsetSpace ~
1412     are\InsetSpace ~
1413     unordered.
1414     A set of integers may appear to be ordered to the modeler as the natural
1415     numbers have an order.
1416     However, it is the user imposing and using the ordering, not ASCEND.
1417     ASCEND sees these integers as elements in the set with NO ordering.
1418     Therefore, there are no operators in ASCEND such as successor or precursor
1419     member of a set.
1420     \end_layout
1421    
1422     \begin_layout List
1423     \labelwidthstring 00000.00000.00000.000
1424    
1425     \bar under
1426     Arrays
1427     \bar default
1428    
1429     \begin_inset LatexCommand \index{arrays}
1430    
1431     \end_inset
1432    
1433     An array is a list of instances indexed over a set, in computer-speak,
1434     an associative array of objects.
1435     The instances are all of the same base type (as that is the only way they
1436     can be defined).
1437     An individual member of a list may later be more refined than the other
1438     members (we shall illustrate that possibility).
1439     The following are arrays in ASCEND.
1440     \end_layout
1441    
1442     \begin_deeper
1443     \begin_layout LyX-Code
1444     \align block
1445     stage[1..n_stages]
1446     \end_layout
1447    
1448     \begin_layout LyX-Code
1449     \align block
1450     y[components]
1451     \end_layout
1452    
1453     \begin_layout LyX-Code
1454     \align block
1455     column[areas][processes]
1456     \end_layout
1457    
1458     \begin_layout Standard
1459     where components, areas and processes are sets.
1460     For example components could be the set of symbols ['ethylene', 'propylene'],
1461     areas the set of symbols ['feed_prep', 'prod_purification'] while processes
1462     could be the set ['alcohol_manuf', 'poly_propropylene_manuf'].
1463     Note that the third example (column) is a list of lists (the way that ASCEND
1464     permits a multiply subscripted array).
1465    
1466     \end_layout
1467    
1468     \begin_layout Standard
1469     The following are elements in the above arrays:
1470     \end_layout
1471    
1472     \begin_layout LyX-Code
1473     stage[1]
1474     \end_layout
1475    
1476     \begin_layout LyX-Code
1477     y['ethylene']
1478     \end_layout
1479    
1480     \begin_layout LyX-Code
1481     column['feed_prep'][alcohol_manuf']
1482     \end_layout
1483    
1484     \begin_layout Standard
1485     provided that n_stages is 1 or larger.
1486    
1487     \end_layout
1488    
1489     \begin_layout Standard
1490     There can be any number of subscripts
1491     \begin_inset LatexCommand \index{subscripts}
1492    
1493     \end_inset
1494    
1495     for an array.
1496     We point out, however, that in virtually every application of arrays requiring
1497     more than two subscripts, there is usually a some underlying concept that
1498     is much better modeled as an object than as part of a deeply subscripted
1499     \begin_inset LatexCommand \index{subscripted, deeply}
1500    
1501     \end_inset
1502    
1503    
1504     \begin_inset LatexCommand \index{deeply subscripted}
1505    
1506     \end_inset
1507    
1508     array.
1509     In the following jagged array example, there are really the concepts of
1510     unit operation and stream that would be better understood if made explicit.
1511     \end_layout
1512    
1513     \end_deeper
1514     \begin_layout List
1515     \labelwidthstring 00000.00000.00000.000
1516    
1517     \bar under
1518     Arrays\InsetSpace ~
1519     can\InsetSpace ~
1520     be\InsetSpace ~
1521     jagged
1522     \bar default
1523    
1524     \begin_inset LatexCommand \label{lyx:Arrays-can-be}
1525    
1526     \end_inset
1527    
1528     (* 4 *) Arrays can be sparse
1529     \begin_inset LatexCommand \index{sparse}
1530    
1531     \end_inset
1532    
1533     or jagged
1534     \begin_inset LatexCommand \index{jagged}
1535    
1536     \end_inset
1537    
1538     .
1539     For example:
1540     \end_layout
1541    
1542     \begin_deeper
1543     \begin_layout LyX-Code
1544     process[1..3] IS_A set OF integer;
1545     \end_layout
1546    
1547     \begin_layout LyX-Code
1548     process[1] :== [2];
1549     \end_layout
1550    
1551     \begin_layout LyX-Code
1552     process[2] :== [7,5,3];
1553     \end_layout
1554    
1555     \begin_layout LyX-Code
1556     process[3] :== [4,6];
1557     \end_layout
1558    
1559     \begin_layout LyX-Code
1560     FOR i in [1..3] CREATE
1561     \end_layout
1562    
1563     \begin_layout LyX-Code
1564     FOR j IN process[i] CREATE
1565     \end_layout
1566    
1567     \begin_layout LyX-Code
1568     flow[i][j] IS_A mass;
1569     \end_layout
1570    
1571     \begin_layout LyX-Code
1572     END FOR;
1573     \end_layout
1574    
1575     \begin_layout LyX-Code
1576     END FOR;
1577     \end_layout
1578    
1579     \begin_layout Standard
1580     process is an array of sets (not to be confused with a set of sets which
1581     ASCEND does not have) and flow is an array with six elements spread over
1582     three rows:
1583     \end_layout
1584    
1585     \begin_layout LyX-Code
1586     flow[1][2]
1587     \end_layout
1588    
1589     \begin_layout LyX-Code
1590     flow[2][7], flow[2][3], flow[2][5]
1591     \end_layout
1592    
1593     \begin_layout LyX-Code
1594     flow[3][4], flow[3][6]
1595     \end_layout
1596    
1597     \begin_layout Standard
1598     Sparse arrays of models and variables are new to ASCEND IV.
1599     \end_layout
1600    
1601     \end_deeper
1602     \begin_layout List
1603     \labelwidthstring 00000.00000.00000.000
1604     Arrays\InsetSpace ~
1605     are\InsetSpace ~
1606     also\InsetSpace ~
1607     instances
1608     \end_layout
1609    
1610     \begin_deeper
1611     \begin_layout Standard
1612     Each array is itself an object.
1613     That is, when you write "a[1..2] IS_A real;" three objects get created: a[1],
1614     a[2], and a.
1615     a is an array instance which has parts named [1] and [2] that are real
1616     instances.
1617     When a parameterized model requires an array, you pass it the single item
1618     a, not the elements a[1..2].
1619     \end_layout
1620    
1621     \end_deeper
1622     \begin_layout List
1623     \labelwidthstring 00000.00000.00000.000
1624     No\InsetSpace ~
1625     contiguous\InsetSpace ~
1626     storage
1627     \begin_inset LatexCommand \index{contiguous storage, no}
1628    
1629     \end_inset
1630    
1631    
1632     \end_layout
1633    
1634     \begin_deeper
1635     \begin_layout Standard
1636     Just in case you still have not caught on, ASCEND arrays are not blocks
1637     of memory such as are seen in low-level languages like C
1638     \begin_inset LatexCommand \index{C, computer language}
1639    
1640     \end_inset
1641    
1642     , FORTRAN
1643     \begin_inset LatexCommand \index{FORTRAN}
1644    
1645     \end_inset
1646    
1647     , and Matlab
1648     \begin_inset LatexCommand \index{Matlab}
1649    
1650     \end_inset
1651    
1652     .
1653     The modeling language does not provide things like MatMult
1654     \begin_inset LatexCommand \index{MatMult}
1655    
1656     \end_inset
1657    
1658     , Transpose
1659     \begin_inset LatexCommand \index{Transpose}
1660    
1661     \end_inset
1662    
1663     , and Inverse
1664     \begin_inset LatexCommand \index{Inverse}
1665    
1666     \end_inset
1667    
1668     because these are procedural solving tools.
1669     If you are dedicated, you could write METHODs that implement matrix algebra,
1670     but this is a really dumb idea.
1671     We aim to structure our software so that it can interact openly with separate,
1672     dedicated tools (such as Matlab) when those tools are needed.
1673     \end_layout
1674    
1675     \end_deeper
1676     \begin_layout List
1677     \labelwidthstring 00000.00000.00000.000
1678     Index\InsetSpace ~
1679     variable
1680     \begin_inset LatexCommand \index{index variable}
1681    
1682     \end_inset
1683    
1684     One can introduce a variable as an index ranging over a set.
1685     Index variables are local to the statements in which they occur.
1686     An example of using an index variable is the following FOR statement:
1687     \end_layout
1688    
1689     \begin_deeper
1690     \begin_layout LyX-Code
1691     FOR i IN components CREATE
1692     \end_layout
1693    
1694     \begin_layout LyX-Code
1695     VLE_equil[i]: y[i] = K[i]*x[i];
1696     \end_layout
1697    
1698     \begin_layout LyX-Code
1699     END FOR;
1700     \end_layout
1701    
1702     \begin_layout Standard
1703     In this example i implicitly is of the same type as the values in the set
1704     components.
1705     If another object i exists in the model containing the FOR loop, it is
1706     ignored while executing the statements in that loop.
1707     This may cause unexpected results and the compiler will generate warnings
1708     about loop index shadowed variables.
1709     \end_layout
1710    
1711     \end_deeper
1712     \begin_layout List
1713     \labelwidthstring 00000.00000.00000.000
1714     Label
1715     \begin_inset LatexCommand \index{label}
1716    
1717     \end_inset
1718    
1719     : One can label statements which define arithmetic relationships (objective
1720     functions, equalities, and inequalities) in ASCEND.
1721     Labeling is highly recommended because it makes models much more readable
1722     and more easily debugged.
1723     Labels are also necessary for relations which are going to be used in condition
1724     al modeling or differentiation functions.
1725     A label is a sequence of alphanumeric characters ending in a colon.
1726     An example of a labeled equation is:
1727     \end_layout
1728    
1729     \begin_deeper
1730     \begin_layout LyX-Code
1731     mass_balance: m_in = m_out;
1732     \end_layout
1733    
1734     \begin_layout Standard
1735     An example of a labeled objective function is:
1736     \end_layout
1737    
1738     \begin_layout LyX-Code
1739     obj1: MAXIMIZE revenue - cost;
1740     \end_layout
1741    
1742     \begin_layout Standard
1743     If a relation is defined within a FOR statement, it must have an array indexed
1744     label so that each instance created using the statement is distinguishable
1745     from the others.
1746     An example is:
1747     \end_layout
1748    
1749     \begin_layout LyX-Code
1750     FOR i IN components CREATE
1751     \end_layout
1752    
1753     \begin_layout LyX-Code
1754     equil[i]: y[i] = K[i]*x[i];
1755     \end_layout
1756    
1757     \begin_layout LyX-Code
1758     END FOR;
1759     \end_layout
1760    
1761     \begin_layout Standard
1762     The ASCEND interactive user interface identifies relationships by their
1763     labels.
1764     If one has not provided such a label, the system generates the label:
1765     \end_layout
1766    
1767     \begin_layout LyX-Code
1768    
1769     \emph on
1770     modelname_equationnumber
1771     \end_layout
1772    
1773     \begin_layout Standard
1774     where modelname and equationnumber are the name of the model and the equation
1775     number in the model.
1776     An example is
1777     \end_layout
1778    
1779     \begin_layout LyX-Code
1780     mixture_14
1781     \end_layout
1782    
1783     \begin_layout Standard
1784     for the unlabeled 14th relation in the mixture definition.
1785     If there is a conflict caused with an existing name, the generated name
1786     has enough letters added after equationnumber to make it a unique name.
1787     Remember that each model in a refinement hierarchy inherits the equations
1788     of its less refined ancestors, so the first equation appearing in the source
1789     code of a refining model may actually be the nth relation in that model.
1790     \end_layout
1791    
1792     \end_deeper
1793     \begin_layout List
1794     \labelwidthstring 00000.00000.00000.000
1795    
1796     \bar under
1797     Lists
1798     \bar default
1799    
1800     \begin_inset LatexCommand \index{lists}
1801    
1802     \end_inset
1803    
1804     Often in a statement one can include a list of names or expression.
1805     A name list is one or more names where multiple list entries are separated
1806     from each other by commas.
1807     Examples of a list of names are:
1808     \end_layout
1809    
1810     \begin_deeper
1811     \begin_layout LyX-Code
1812     \align block
1813     T1, inlet_T, outlet_T
1814     \end_layout
1815    
1816     \begin_layout LyX-Code
1817     \align block
1818     y[components], y_in
1819     \end_layout
1820    
1821     \begin_layout LyX-Code
1822     \align block
1823     stage[1..n_stages]
1824     \end_layout
1825    
1826     \end_deeper
1827     \begin_layout List
1828     \labelwidthstring 00000.00000.00000.000
1829    
1830     \bar under
1831     Ordered\InsetSpace ~
1832     lists
1833     \begin_inset LatexCommand \index{lists, ordered}
1834    
1835     \end_inset
1836    
1837    
1838     \begin_inset LatexCommand \index{ordered lists}
1839    
1840     \end_inset
1841    
1842     :
1843     \bar default
1844     If the ordering of names in a list matters, that list is enclosed in ().
1845     Order matters in: calling externally defined methods or models, calling
1846     most real-valued functions, passing parameters to ASCEND models or methods,
1847     and declaring the controlling parameters that SELECT, SWITCH, and WHEN
1848     statements make decisions on.
1849     \end_layout
1850    
1851     \begin_deeper
1852     \begin_layout Subsection
1853     Basic Concepts
1854     \end_layout
1855    
1856     \end_deeper
1857     \begin_layout List
1858     \labelwidthstring 00000.00000.00000.000
1859    
1860     \bar under
1861     Instances
1862     \begin_inset LatexCommand \index{instances}
1863    
1864     \end_inset
1865    
1866     \InsetSpace ~
1867     and\InsetSpace ~
1868     types
1869     \bar default
1870    
1871     \begin_inset LatexCommand \index{types}
1872    
1873     \end_inset
1874    
1875     This is an opportune time to emphasize the distinction between the terms
1876     instance and type.
1877     A type in ASCEND is what we define when we declare an ASCEND model or atom.
1878     It is the formal definition of the attributes (parts) and attribute default
1879     values that an object will have if it is created using the type definition.
1880     Methods are associated with types.
1881     \end_layout
1882    
1883     \begin_deeper
1884     \begin_layout Standard
1885     In ASCEND there are two meanings (closely related) of an instance.
1886    
1887     \end_layout
1888    
1889     \begin_layout Itemize
1890     An instance is a named part that exists within a type definition.
1891    
1892     \end_layout
1893    
1894     \begin_layout Itemize
1895     An instance is a compiled object.
1896    
1897     \end_layout
1898    
1899     \begin_layout Standard
1900     If one is in the context of the ASCEND interface, the system compiles an
1901     instance of a model type to create an object with which one carries out
1902     computations.
1903     The system requires the user to give a simple name for this simulation
1904     instance.
1905     This name given is then the first part of the qualified name for all the
1906     parts of the compiled object.
1907     \end_layout
1908    
1909     \end_deeper
1910     \begin_layout List
1911     \labelwidthstring 00000.00000.00000.000
1912    
1913     \bar under
1914     Implicit\InsetSpace ~
1915     types
1916     \bar default
1917    
1918     \begin_inset LatexCommand \index{types, implicit}
1919    
1920     \end_inset
1921    
1922    
1923     \begin_inset LatexCommand \index{types, implicit}
1924    
1925     \end_inset
1926    
1927     It is possible to create an instance that does not have a corresponding
1928     type definition in the library.
1929     The type of such an instance is said to be implicit.
1930     (Some people use the word anonymous
1931     \begin_inset LatexCommand \index{type, anonymous}
1932    
1933     \end_inset
1934    
1935    
1936     \begin_inset LatexCommand \index{anonymous type}
1937    
1938     \end_inset
1939    
1940     .
1941     However, no computable type is anonymous and the implicit type of an instance
1942     is theoretically computable).
1943     The simplest example of an implicit type is the type of an instance compiled
1944     from the built-in definition integer_constant.
1945     For example:
1946     \end_layout
1947    
1948     \begin_deeper
1949     \begin_layout LyX-Code
1950     i, j IS_A integer_constant;
1951     \end_layout
1952    
1953     \begin_layout LyX-Code
1954     i:== 2;
1955     \end_layout
1956    
1957     \begin_layout LyX-Code
1958     j:== 3;
1959     \end_layout
1960    
1961     \begin_layout Standard
1962     Instances i and j, though of the same formal type, are implicit type incompatibl
1963     e because they have been assigned distinct values.
1964     \end_layout
1965    
1966     \begin_layout Standard
1967     Instances which are either formally or implicitly type incompatible cannot
1968     be merged.
1969     This will be discussed further in Section
1970     \begin_inset LatexCommand \vref{sec:x.3Declarative-statements}
1971    
1972     \end_inset
1973    
1974     .
1975     \end_layout
1976    
1977     \end_deeper
1978     \begin_layout List
1979     \labelwidthstring 00000.00000.00000.000
1980     Parsing
1981     \begin_inset LatexCommand \index{parsing}
1982    
1983     \end_inset
1984    
1985     Most errors in the declaration of an ASCEND model can be caught at parse
1986     time because the object type of any well-formed name in an ASCEND definition
1987     can be resolved or proved ambiguous.
1988     We cannot prove at parse time whether a specific array element will exist,
1989     but we can know that should such an element exist, it must be of the type
1990     with which the array is defined.
1991    
1992     \end_layout
1993    
1994     \begin_deeper
1995     \begin_layout Standard
1996     Ambiguity is warned about loudly because it is caused by either misspelling
1997     or poor modeling style.
1998     The simplest example of ambiguity follows.
1999     \end_layout
2000    
2001     \begin_layout Standard
2002     Assume a type, stream, and a refinement of stream, heat_stream, which adds
2003     the new variable H.
2004     Now, if we write:
2005     \end_layout
2006    
2007     \begin_layout LyX-Code
2008     MODEL mixer;
2009     \end_layout
2010    
2011     \begin_layout LyX-Code
2012     input[1..2] IS_A stream;
2013     \end_layout
2014    
2015     \begin_layout LyX-Code
2016     output IS_A heat_stream;
2017     \end_layout
2018    
2019     \begin_layout LyX-Code
2020     input[1].H + input[2].H = output.H;
2021     \end_layout
2022    
2023     \begin_layout LyX-Code
2024     END mixer;
2025     \end_layout
2026    
2027     \begin_layout Standard
2028     We see the parser can find the definition of H in the type heat_stream,
2029     so output.H is well defined.
2030     The author of the mixer model may intend to refine input[1] and input[2]
2031     to be objects of different types, say steam_stream and electric_stream,
2032     where each defines an H suitable for use in the equation.
2033     The parser cannot read the authors mind, so it warns that input[1].H and
2034     input[2].H are ambiguous in the mixer definition.
2035     The mixer model is not highly reusable except by the author, but sometimes
2036     reusability is not a high priority objective.
2037     The mixer definition is allowed, but it may cause problems in instantiation
2038     if the author has forgotten the assumption that is not explicitly stated
2039     in the model and neglects to refine the input streams appropriately.
2040     \end_layout
2041    
2042     \end_deeper
2043     \begin_layout List
2044     \labelwidthstring 00000.00000.00000.000
2045    
2046     \bar under
2047     Instantiation
2048     \bar default
2049    
2050     \begin_inset LatexCommand \index{instantiation}
2051    
2052     \end_inset
2053    
2054     Creating an simulation based on a type definition is a multi-phase
2055     \begin_inset LatexCommand \index{multi-phase}
2056    
2057     \end_inset
2058    
2059     process called compiling
2060     \begin_inset LatexCommand \index{compiling}
2061    
2062     \end_inset
2063    
2064     (or instantiation).
2065     When an instantiation cannot be completed because some structural parameter
2066     (a symbol_constant, real_constant, boolean_constant, integer_constant,
2067     or set) does not have a value there will be PENDING
2068     \begin_inset LatexCommand \index{PENDING}
2069    
2070     \end_inset
2071    
2072     statements.
2073     The user interface will warn that something is incomplete.
2074     \end_layout
2075    
2076     \begin_deeper
2077     \begin_layout Standard
2078     In phase
2079     \begin_inset LatexCommand \index{phases, compiler}
2080    
2081     \end_inset
2082    
2083     1 all statements that create instance structures or assign constant values
2084     are executed.
2085     This phase theoretically requires an infinite number of passes through
2086     the structural statements of a definition.
2087     We allow a maximum of 5 and have never needed more than 3.
2088     There may be pending statements at the end of phase 1.
2089     The compiler or interface will issue warnings about pending statements,
2090     starting with warnings about unassigned constants.
2091     \end_layout
2092    
2093     \begin_layout Standard
2094     Phase 2 compiles as many real arithmetic relation definitions as possible.
2095     Some relations may be impossible to compile because the constants or sets
2096     they depend on do not have values assigned.
2097     Other relations may be impossible because they reference variables that
2098     do not exist.
2099     This is determined in a single pass.
2100     \end_layout
2101    
2102     \begin_layout Standard
2103     Phase 3 compiles as many logical arithmetic relation definitions as possible.
2104     Some relations may be impossible to compile because the constants or sets
2105     they depend on do not have values assigned.
2106     Other relations may be impossible because they reference real arithmetic
2107     relations that do not exist.
2108     This is determined in a single pass.
2109     \end_layout
2110    
2111     \begin_layout Standard
2112     Phase 4 compiles as many conditional programming statements (WHENs) as possible.
2113     Some WHEN relations may be impossible to compile because the discrete variables
2114     , models, or relations they depend on do not exist.
2115     This is determined in a single pass.
2116     \end_layout
2117    
2118     \begin_layout Standard
2119     Phase 5 executes the variable defaulting statements made in the declarative
2120     section of each model IF AND ONLY IF there are no pending statements from
2121     phases 1-4 anywhere in the simulation.
2122     \end_layout
2123    
2124     \end_deeper
2125     \begin_layout List
2126     \labelwidthstring 00000.00000.00000.000
2127     default_self
2128     \begin_inset LatexCommand \index{default\_self}
2129    
2130     \end_inset
2131    
2132     After all phases are done, the method default_self is called in the top-most
2133     model of the simulation, if this method exists.
2134     \end_layout
2135    
2136     \begin_deeper
2137     \begin_layout Standard
2138     The first occurrence of each impossible statement will be explained during
2139     a failed compilation.
2140     Impossible statements include:
2141     \end_layout
2142    
2143     \begin_layout Itemize
2144     Relations containing undefinable variables (often misspellings).
2145     \end_layout
2146    
2147     \begin_layout Itemize
2148     Assignments that are dimensionally inconsistent or containing mismatched
2149     types.
2150     \end_layout
2151    
2152     \begin_layout Itemize
2153     Structure building or modifying statements that refer to model parts which
2154     cannot exist or that require a type-incompatible argument, refinement,
2155     or merge.
2156     \end_layout
2157    
2158     \begin_layout Section
2159     Data Type Declarations
2160     \begin_inset LatexCommand \index{data type declarations}
2161    
2162     \end_inset
2163    
2164    
2165     \end_layout
2166    
2167     \begin_layout Standard
2168     In the spectrum of OO languages, ASCEND is best considered as being class-based
2169     \begin_inset LatexCommand \index{class-based}
2170    
2171     \end_inset
2172    
2173     , though it is rather more a hybrid.
2174     We have atom and model definitions, called types, and the compiled objects
2175     themselves, called instances.
2176     ASCEND instances have a record of what type they were constructed from.
2177     \end_layout
2178    
2179     \end_deeper
2180     \begin_layout List
2181     \labelwidthstring 00000.00000.00000.000
2182    
2183     \bar under
2184     Type\InsetSpace ~
2185     qualifiers
2186     \begin_inset LatexCommand \index{type qualifiers}
2187    
2188     \end_inset
2189    
2190     :
2191     \end_layout
2192    
2193     \begin_layout List
2194     \labelwidthstring 00000.00000.00000.000
2195     UNIVERSAL
2196     \begin_inset LatexCommand \index{UNIVERSAL}
2197    
2198     \end_inset
2199    
2200     Universal is an optional modifier of all ATOM, CONSTANT.
2201     and MODEL definitions.
2202     If UNIVERSAL precedes the definition, then ALL instances of that type will
2203     actually refer to the first instance of the type that is created.
2204     This saves memory and ensures global consistency of data.
2205    
2206     \end_layout
2207    
2208     \begin_deeper
2209     \begin_layout Standard
2210     Examples of universal type definitions are
2211     \end_layout
2212    
2213     \begin_layout LyX-Code
2214     UNIVERSAL MODEL methane
2215     \end_layout
2216    
2217     \begin_layout LyX-Code
2218     REFINES generic_component_model;
2219     \end_layout
2220    
2221     \begin_layout LyX-Code
2222     UNIVERSAL CONSTANT circle_constant
2223     \end_layout
2224    
2225     \begin_layout LyX-Code
2226     REFINES real_constant :== 1{PI};
2227     \end_layout
2228    
2229     \begin_layout LyX-Code
2230     UNIVERSAL ATOM counter_1
2231     \end_layout
2232    
2233     \begin_layout LyX-Code
2234     REFINES integer;
2235     \end_layout
2236    
2237     \end_deeper
2238     \begin_layout List
2239     \labelwidthstring 00000.00000.00000.000
2240     Tip:\InsetSpace ~
2241     Do\InsetSpace ~
2242     not\InsetSpace ~
2243     use\InsetSpace ~
2244     UNIVERSAL\InsetSpace ~
2245     variables\InsetSpace ~
2246     in\InsetSpace ~
2247     relations.
2248     \end_layout
2249    
2250     \begin_deeper
2251     \begin_layout Standard
2252     It is important to note that, because variables must store information about
2253     which relations they occur in, it is a very bad idea to use UNIVERSAL typed
2254     variables in relations.
2255     The construction and maintenance of the relation list becomes very expensive
2256     for universal variables.
2257     UNIVERSAL constants are fine to use, though, because there are no relation
2258     links for constants.
2259     \end_layout
2260    
2261     \begin_layout Subsection
2262     Models
2263     \end_layout
2264    
2265     \end_deeper
2266     \begin_layout List
2267     \labelwidthstring 00000.00000.00000.000
2268     MODEL
2269     \begin_inset LatexCommand \index{MODEL}
2270    
2271     \end_inset
2272    
2273     An ASCEND model has a declarative part and an optional procedural part
2274     headed by the METHODS word.
2275     Models are essentially containers for variables and relations.
2276     We will explain the various statements that can be made within models in
2277     Section
2278     \begin_inset LatexCommand \vref{sec:x.3Declarative-statements}
2279    
2280     \end_inset
2281    
2282     and Section
2283     \begin_inset LatexCommand \vref{sec:x.4Procedural-statements}
2284    
2285     \end_inset
2286    
2287     .
2288     \end_layout
2289    
2290     \begin_layout Standard
2291     Simple\InsetSpace ~
2292     models
2293     \begin_inset LatexCommand \index{models, simple}
2294    
2295     \end_inset
2296    
2297     :
2298     \end_layout
2299    
2300     \begin_layout List
2301     \labelwidthstring 00000.00000.00000.000
2302     foo
2303     \family typewriter
2304     \InsetSpace ~
2305     \InsetSpace ~
2306     \InsetSpace ~
2307     \InsetSpace ~
2308     MODEL foo;
2309     \end_layout
2310    
2311     \begin_deeper
2312     \begin_layout LyX-Code
2313     (* statements about foo go here*)
2314     \end_layout
2315    
2316     \begin_layout LyX-Code
2317     METHODS
2318     \end_layout
2319    
2320     \begin_layout LyX-Code
2321     (* METHODs for foo go here*)
2322     \end_layout
2323    
2324     \begin_layout LyX-Code
2325     END foo;
2326     \end_layout
2327    
2328     \end_deeper
2329     \begin_layout List
2330     \labelwidthstring 00000.00000.00000.000
2331     bar
2332     \family typewriter
2333     \InsetSpace ~
2334     \InsetSpace ~
2335     \InsetSpace ~
2336     \InsetSpace ~
2337     MODEL bar REFINES foo;
2338     \end_layout
2339    
2340     \begin_deeper
2341     \begin_layout LyX-Code
2342     (*additional statements about foo *)
2343     \end_layout
2344    
2345     \begin_layout LyX-Code
2346     METHODS
2347     \end_layout
2348    
2349     \begin_layout LyX-Code
2350     (* additional METHODs for bar *)
2351     \end_layout
2352    
2353     \begin_layout LyX-Code
2354     END bar;
2355     \end_layout
2356    
2357     \end_deeper
2358     \begin_layout List
2359     \labelwidthstring 00000.00000.00000.000
2360    
2361     \bar under
2362     Parameterized\InsetSpace ~
2363     Models
2364     \bar default
2365    
2366     \begin_inset LatexCommand \index{models, parameterized}
2367    
2368     \end_inset
2369    
2370     (* 4 *) Parameterizing models makes them easier to understand and faster
2371     for the system to compile.
2372     The syntax for a parameterized model vaguely resembles a function call
2373     in imperative languages, but it is NOT.
2374     When constructing a reusable model, all the constants that determine the
2375     sizes of arrays and other structures should be declared in the parameter
2376     list so that
2377     \end_layout
2378    
2379     \begin_deeper
2380     \begin_layout Itemize
2381     the user knows what is required to reuse the model.
2382     \end_layout
2383    
2384     \begin_layout Itemize
2385     the compiler knows what values must be set before it should bother attempting
2386     to compile the model.
2387     \end_layout
2388    
2389     \begin_layout Standard
2390     There is no reason that other items could not also go in the parameter list,
2391     such as key variables which might be considered inputs or outputs or control
2392     parameters in the mathematical application of the model.
2393     A simple example of parameterization would be:
2394     \end_layout
2395    
2396     \end_deeper
2397     \begin_layout List
2398     \labelwidthstring 00000.00000.00000.000
2399     column(n,s)
2400     \end_layout
2401    
2402     \begin_deeper
2403     \begin_layout LyX-Code
2404     MODEL column(
2405     \end_layout
2406    
2407     \begin_layout LyX-Code
2408     ntrays WILL_BE integer_constant;
2409     \end_layout
2410    
2411     \begin_layout LyX-Code
2412     components IS_A set of symbol_constant;
2413     \end_layout
2414    
2415     \begin_layout LyX-Code
2416     );
2417     \end_layout
2418    
2419     \begin_layout LyX-Code
2420     stage[1..ntrays] IS_A simple_tray;
2421     \end_layout
2422    
2423     \begin_layout LyX-Code
2424     END column;
2425     \end_layout
2426    
2427     \end_deeper
2428     \begin_layout List
2429     \labelwidthstring 00000.00000.00000.000
2430     flowsheet
2431     \end_layout
2432    
2433     \begin_deeper
2434     \begin_layout LyX-Code
2435     MODEL flowsheet;
2436     \end_layout
2437    
2438     \begin_layout LyX-Code
2439     tower4size IS_A integer_constant;
2440     \end_layout
2441    
2442     \begin_layout LyX-Code
2443     tower4size :== 22;
2444     \end_layout
2445    
2446     \begin_layout LyX-Code
2447     ct IS_A column(tower4size,[c5,c6]);
2448     \end_layout
2449    
2450     \begin_layout LyX-Code
2451     (* additional flowsheet statements *)
2452     \end_layout
2453    
2454     \begin_layout LyX-Code
2455     END flowsheet;
2456     \end_layout
2457    
2458     \begin_layout Standard
2459     In this example, the column model takes the first argument, ntrays, by reference.
2460     That is, ct.ntrays is an alias for the flowsheet instance tower4size.
2461     tower4size must be compiled and assigned a value before we will attempt
2462     to compile the column model instance ct.
2463     The second argument is taken by value, [c5,c6], and assigned to components,
2464     a column part that was declared with IS_A in the parameter list.
2465     There is only one name for this set, ct.components.
2466     Note that in the flowsheet model there is no part that is a set of symbol_const
2467     ant.
2468    
2469     \end_layout
2470    
2471     \begin_layout Standard
2472     The use of parameters in ASCEND modeling requires some thought, and we will
2473     present that set of thoughts in Section
2474     \begin_inset LatexCommand \vref{sec:x.5Parameterized-models}
2475    
2476     \end_inset
2477    
2478     .
2479     Beginners may wish to create new models without parameters until they are
2480     comfortable using the existing parameterized library definitions.
2481     Parameters are intended to support model reuse and efficient compilation
2482     which are not issues in the very earliest phase of developing novel models.
2483     \end_layout
2484    
2485     \begin_layout Subsection
2486     Sets
2487     \begin_inset LatexCommand \index{sets}
2488    
2489     \end_inset
2490    
2491    
2492     \begin_inset LatexCommand \label{sub:x.2.2Sets}
2493    
2494     \end_inset
2495    
2496    
2497     \end_layout
2498    
2499     \begin_layout Standard
2500     Arrays in ASCEND, as already discussed in Section
2501     \begin_inset LatexCommand \vref{sub:x.1.2Basic-Elements}
2502    
2503     \end_inset
2504    
2505     , are defined over sets.
2506     A set is simply an instance with a set value.
2507     The elements of sets are NOT instances or sets.
2508     \end_layout
2509    
2510     \end_deeper
2511     \begin_layout List
2512     \labelwidthstring 00000.00000.00000.000
2513    
2514     \bar under
2515     Set\InsetSpace ~
2516     Declaration:
2517     \bar default
2518     A set is made of either symbol_constants or integer_constants, so a set
2519     object is declared in one of two ways:
2520     \end_layout
2521    
2522     \begin_deeper
2523     \begin_layout LyX-Code
2524     my_integer_set IS_A set OF integer_constant;
2525     \end_layout
2526    
2527     \begin_layout Standard
2528     or
2529     \end_layout
2530    
2531     \begin_layout LyX-Code
2532     my_symbol_set IS_A set OF symbol_constant;
2533     \end_layout
2534    
2535     \end_deeper
2536     \begin_layout List
2537     \labelwidthstring 00000.00000.00000.000
2538     :==
2539     \begin_inset LatexCommand \index{:==}
2540    
2541     \end_inset
2542    
2543     A set is assigned a value like so:
2544     \end_layout
2545    
2546     \begin_deeper
2547     \begin_layout LyX-Code
2548     my_integer_set :== [1,4];
2549     \end_layout
2550    
2551     \begin_layout Standard
2552     The RHS of such an assignment must be either the name of another set instance
2553     or an expression enclosed in square brackets and made up of only set operators,
2554     other sets, and the names of integer_constants or symbol_constants.
2555     Sets can only be assigned once.
2556     \end_layout
2557    
2558     \end_deeper
2559     \begin_layout List
2560     \labelwidthstring 00000.00000.00000.000
2561    
2562     \bar under
2563     Set\InsetSpace ~
2564     Operations
2565     \bar default
2566     UNION
2567     \begin_inset LatexCommand \index{UNION}
2568    
2569     \end_inset
2570    
2571     [setlist]
2572     \end_layout
2573    
2574     \begin_deeper
2575     \begin_layout Standard
2576     A function taken over a list of sets.
2577     The result is the set that includes all the members of all the sets in
2578     the list.
2579     Note that the result of the UNION operation is an unordered set and the
2580     argument order to the union function does not matter.
2581     The syntax is:
2582     \end_layout
2583    
2584     \end_deeper
2585     \begin_layout List
2586     \labelwidthstring 00000.00000.00000.000
2587     +
2588     \begin_inset LatexCommand \index{+, sets}
2589    
2590     \end_inset
2591    
2592     UNION[list_of_sets]
2593     \end_layout
2594    
2595     \begin_layout List
2596     \labelwidthstring 00000.00000.00000.000
2597     A+B\InsetSpace ~
2598     is\InsetSpace ~
2599     shorthand\InsetSpace ~
2600     for UNION[A,B]
2601     \end_layout
2602    
2603     \begin_deeper
2604     \begin_layout Standard
2605     Consider the following sets for the examples to follow.
2606     \end_layout
2607    
2608     \begin_layout LyX-Code
2609     A := [1, 2, 3, 5, 9];
2610     \end_layout
2611    
2612     \begin_layout LyX-Code
2613     B := [2, 4, 6, 8];
2614     \end_layout
2615    
2616     \begin_layout Standard
2617     Then UNION[A, B] is equal to the set [1, 2, 3, 4, 5, 6, 8, 9] which equals
2618     [1..6, 8, 9] which equals [[1..9] - [7]].
2619     \end_layout
2620    
2621     \end_deeper
2622     \begin_layout List
2623     \labelwidthstring 00000.00000.00000.000
2624     INTERSECTION
2625     \begin_inset LatexCommand \index{INTERSECTION}
2626    
2627     \end_inset
2628    
2629     [] INTERSECTION[list of set expressions].
2630     Finds the intersection (and) of the sets listed.
2631    
2632     \end_layout
2633    
2634     \begin_layout List
2635     \labelwidthstring 00000.00000.00000.000
2636     *
2637     \begin_inset LatexCommand \index{*, sets}
2638    
2639     \end_inset
2640    
2641     Equivalent to INTERSECTION[list_of_sets].
2642     \end_layout
2643    
2644     \begin_layout List
2645     \labelwidthstring 00000.00000.00000.000
2646     A*B\InsetSpace ~
2647     is\InsetSpace ~
2648     shorthand\InsetSpace ~
2649     for\InsetSpace ~
2650     INTERSECTION[A,B]
2651     \end_layout
2652    
2653     \begin_deeper
2654     \begin_layout Standard
2655     For the sets A and B defined just above, INTERSECTION[A, B] is the set [2].
2656     The * shorthand for intersection is NOT recommended for use except in libraries
2657     no one will look at.
2658     \end_layout
2659    
2660     \end_deeper
2661     \begin_layout List
2662     \labelwidthstring 00000.00000.00000.000
2663     Set\InsetSpace ~
2664     difference
2665     \begin_inset LatexCommand \index{set difference}
2666    
2667     \end_inset
2668    
2669     : One can subtract one set from another.
2670     The result is the first set less any members in the set union of the first
2671     and second set.
2672     The syntax is
2673     \end_layout
2674    
2675     \begin_layout List
2676     \labelwidthstring 00000.00000.00000.000
2677     -
2678     \begin_inset LatexCommand \index{-, sets}
2679    
2680     \end_inset
2681    
2682    
2683     \family typewriter
2684     \InsetSpace ~
2685     \InsetSpace ~
2686     \InsetSpace ~
2687     first_set - second_set
2688     \end_layout
2689    
2690     \begin_deeper
2691     \begin_layout Standard
2692     For the sets A and B defined above, the set difference A - B is the set
2693     [1, 3, 5, 9] while the set difference B - A is the set [4, 6, 8].
2694     \end_layout
2695    
2696     \end_deeper
2697     \begin_layout List
2698     \labelwidthstring 00000.00000.00000.000
2699     CARD
2700     \begin_inset LatexCommand \index{CARD}
2701    
2702     \end_inset
2703    
2704     [set] Cardinality
2705     \begin_inset LatexCommand \index{cardinality}
2706    
2707     \end_inset
2708    
2709     .
2710     Returns an integer constant value that is the number of items in the set.
2711     \end_layout
2712    
2713     \begin_layout List
2714     \labelwidthstring 00000.00000.00000.000
2715     CHOICE
2716     \begin_inset LatexCommand \index{CHOICE}
2717    
2718     \end_inset
2719    
2720     [set] Choose one.
2721     The result of running the CHOICE function over a set is an arbitrary (but
2722     consistent: for any set instance you always get the same result) single
2723     element of that set.
2724    
2725     \end_layout
2726    
2727     \begin_deeper
2728     \begin_layout Standard
2729     Running CHOICE[A] gives any member from the set A.
2730     The result is a member, not a set.
2731     To make the result into a set, it must be enclosed in square brackets.
2732     Thus [CHOICE[A]] is a set with a single element arbitrarily chosen from
2733     the set A.
2734     Good modelers do not leave modeling decisions to the compiler; they do
2735     not use CHOICE[].
2736     We are stuck with it for historical reasons.
2737     \end_layout
2738    
2739     \begin_layout Standard
2740     To reduce a set by one element, one can use the following
2741     \end_layout
2742    
2743     \begin_layout LyX-Code
2744     A_less_one IS_A set OF integer;
2745     \end_layout
2746    
2747     \begin_layout LyX-Code
2748     A_less_one :== A - [CHOICE[A]];
2749     \end_layout
2750    
2751     \end_deeper
2752     \begin_layout List
2753     \labelwidthstring 00000.00000.00000.000
2754     IN
2755     \begin_inset LatexCommand \index{IN}
2756    
2757     \end_inset
2758    
2759     lhs IN rhs can only be well explained by examples.
2760     IN is used in index expressions.
2761     If lhs is a simple and not previously defined name, it is created as a
2762     temporary loop index which will take on the values of the rhs set definition.
2763     If lhs is something that already exists, the result of lhs IN rhs is a
2764     boolean value; stare at the model set_example below which demonstrates
2765     both IN and SUCH_THAT.
2766     If you still are not satisfied, you might examine [[westerbergksets]].
2767     \end_layout
2768    
2769     \begin_layout List
2770     \labelwidthstring 00000.00000.00000.000
2771     SUCH_THAT
2772     \begin_inset LatexCommand \index{SUCH\_THAT}
2773    
2774     \end_inset
2775    
2776     \InsetSpace ~
2777     (*\InsetSpace ~
2778     4\InsetSpace ~
2779     *) Set expressions can be rather clever.
2780     We will give a detailed example from chemistry because unordered sets are
2781     unfamiliar to most people and set arithmetic is quite powerful.
2782     In this example we see arrays of sets and sparse arrays.
2783    
2784     \end_layout
2785    
2786     \begin_layout LyX-Code
2787     MODEL set_example;
2788     \end_layout
2789    
2790     \begin_layout LyX-Code
2791     (* we define a sparse matrix of reaction
2792     \end_layout
2793    
2794     \begin_layout LyX-Code
2795     coefficient information and the species
2796     \end_layout
2797    
2798     \begin_layout LyX-Code
2799     balance equations.
2800     *)
2801     \end_layout
2802    
2803     \begin_layout LyX-Code
2804     rxns IS_A set OF integer_constant;
2805     \end_layout
2806    
2807     \begin_layout LyX-Code
2808     rxns :== [1..3];
2809     \end_layout
2810    
2811     \begin_layout LyX-Code
2812     species IS_A set OF symbol_constant;
2813     \end_layout
2814    
2815     \begin_layout LyX-Code
2816     species :== ['A','B','C','D'];
2817     \end_layout
2818    
2819     \begin_layout LyX-Code
2820     reactants[rxns] IS_A set OF symbol_constant; (* species
2821     \end_layout
2822    
2823     \begin_layout LyX-Code
2824     in each rxn_j *)
2825     \end_layout
2826    
2827     \begin_layout LyX-Code
2828     reactants[1] :== ['A','B','C'];
2829     \end_layout
2830    
2831     \begin_layout LyX-Code
2832     reactants[2] :== ['A','C'];
2833     \end_layout
2834    
2835     \begin_layout LyX-Code
2836     reactants[3] :== ['A','B','D'];
2837     \end_layout
2838    
2839     \begin_layout LyX-Code
2840     reactions[species] IS_A set OF integer_constant;
2841     \end_layout
2842    
2843     \begin_layout LyX-Code
2844     FOR i IN species CREATE (* rxns for each species i *)
2845     \end_layout
2846    
2847     \begin_layout LyX-Code
2848     reactions[i] :== [j IN rxns SUCH_THAT i IN reactants[j]];
2849     \end_layout
2850    
2851     \begin_layout LyX-Code
2852     END FOR;
2853     \end_layout
2854    
2855     \begin_layout LyX-Code
2856     (* Define sparse stoichiometric matrix.
2857     Values of eta_ij
2858     \end_layout
2859    
2860     \begin_layout LyX-Code
2861     set later.*)
2862     \end_layout
2863    
2864     \begin_layout LyX-Code
2865     FOR j IN rxns CREATE
2866     \end_layout
2867    
2868     \begin_layout LyX-Code
2869     FOR i IN reactants[j] CREATE
2870     \end_layout
2871    
2872     \begin_layout LyX-Code
2873     (* eta_ij --> mole i/mole rxn j*)
2874     \end_layout
2875    
2876     \begin_layout LyX-Code
2877     eta[i][j] IS_A real_constant;
2878     \end_layout
2879    
2880     \begin_layout LyX-Code
2881     END FOR;
2882     \end_layout
2883    
2884     \begin_layout LyX-Code
2885     END FOR;
2886     \end_layout
2887    
2888     \begin_layout LyX-Code
2889     production[species] IS_A molar_rate;
2890     \end_layout
2891    
2892     \begin_layout LyX-Code
2893     rate[rxns] IS_A molar_rate; (* mole rxn j/time *)
2894     \end_layout
2895    
2896     \begin_layout LyX-Code
2897     FOR i IN species CREATE
2898     \end_layout
2899    
2900     \begin_layout LyX-Code
2901     gen_eqn[i]: production[i] =
2902     \end_layout
2903    
2904     \begin_layout LyX-Code
2905     SUM[eta[i][j]*rate[j] | j IN reactions[i]];
2906     \end_layout
2907    
2908     \begin_layout LyX-Code
2909     END FOR;
2910     \end_layout
2911    
2912     \begin_layout LyX-Code
2913     END set_example;
2914     \end_layout
2915    
2916     \begin_layout List
2917     \labelwidthstring 00000.00000.00000.000
2918     "|
2919     \begin_inset LatexCommand \index{|}
2920    
2921     \end_inset
2922    
2923     " is shorthand for SUCH_THAT.
2924     \end_layout
2925    
2926     \begin_deeper
2927     \begin_layout Standard
2928     The array eta has only 8 elements, and we defined those elements in a set
2929     for each reaction.
2930     The equation needs to know about the set of reactions for a species i,
2931     and that set is calculated automatically in the models first FOR/CREATE
2932     statement.
2933    
2934     \end_layout
2935    
2936     \end_deeper
2937     \begin_layout List
2938     \labelwidthstring 00000.00000.00000.000
2939     |
2940     \end_layout
2941    
2942     \begin_deeper
2943     \begin_layout Standard
2944     The | symbol is the ASCEND III notation for SUCH_THAT.
2945     We noted that "|" is often read as "for all", which is different in that
2946     "for all" makes one think of a FOR loop where the loop index is on the
2947     left of an IN operator.
2948     For example, the j loop in the SUM of gen_eqn[i] above.
2949    
2950     \end_layout
2951    
2952     \begin_layout Subsection
2953     Constants
2954     \begin_inset LatexCommand \index{constants}
2955    
2956     \end_inset
2957    
2958    
2959     \end_layout
2960    
2961     \begin_layout Standard
2962     ASCEND supports real, integer, boolean and character string constants.
2963     Constants in ASCEND do not have any attributes other than their value.
2964     Constants are scalar quantities that can be assigned exactly once.
2965     Constants may only be assigned using the :== operator and the RHS expression
2966     they are assigned from must itself be constant.
2967     Constants do not have subparts.
2968     Integer and symbol constants may be used in determining the definitions
2969     of sets.
2970    
2971     \end_layout
2972    
2973     \begin_layout Standard
2974     Explicit refinements of the built-in constant types may be defined as exemplifie
2975     d in the description of real_constant.
2976     Implicit type refinements may be done by instantiating an incompletely
2977     defined constant and assigning its final value.
2978    
2979     \end_layout
2980    
2981     \begin_layout Standard
2982     Sets could be considered constant because they are assigned only once, however
2983     sets are described separately because they are not quite scalar quantities.
2984     \end_layout
2985    
2986     \end_deeper
2987     \begin_layout List
2988     \labelwidthstring 00000.00000.00000.000
2989     real_constant
2990     \begin_inset LatexCommand \index{real\_constant}
2991    
2992     \end_inset
2993    
2994     Real number with dimensionality.
2995     Note that the dimensionality of a real constant can be specified via the
2996     type definition without immediately defining the value, as in the following
2997     pair of definitions.
2998     \end_layout
2999    
3000     \begin_layout List
3001     \labelwidthstring 00000.00000.00000.000
3002    
3003     \bar under
3004     CONSTANT\InsetSpace ~
3005     declaration\InsetSpace ~
3006     example:
3007     \end_layout
3008    
3009     \begin_deeper
3010     \begin_layout LyX-Code
3011     CONSTANT molar_weight
3012     \end_layout
3013    
3014     \begin_layout LyX-Code
3015     REFINES real_constant DIMENSION M/Q;
3016     \end_layout
3017    
3018     \begin_layout LyX-Code
3019     CONSTANT hydrogen_weight
3020     \end_layout
3021    
3022     \begin_layout LyX-Code
3023     REFINES molar_weight :== 1.004{g/mole};
3024     \end_layout
3025    
3026     \end_deeper
3027     \begin_layout List
3028     \labelwidthstring 00000.00000.00000.000
3029     integer_constant
3030     \begin_inset LatexCommand \index{integer\_constant}
3031    
3032     \end_inset
3033    
3034     Integer number.
3035     Principally used in determining model structure.
3036     If appearing in equations, integers are evaluated as dimensionless reals.
3037     Typical use is inside a MODEL definition and looks like:
3038     \end_layout
3039    
3040     \begin_deeper
3041     \begin_layout LyX-Code
3042     n_trays IS_A integer_constant;
3043     \end_layout
3044    
3045     \begin_layout LyX-Code
3046     n_trays :== 50;
3047     \end_layout
3048    
3049     \begin_layout LyX-Code
3050     tray[1..n_trays] IS_A vl_equilibrium_tray;
3051     \end_layout
3052    
3053     \end_deeper
3054     \begin_layout List
3055     \labelwidthstring 00000.00000.00000.000
3056     symbol_constant
3057     \begin_inset LatexCommand \index{symbol\_constant}
3058    
3059     \end_inset
3060    
3061     Object with a symbol value.
3062     May be used in determining model structure.
3063     \end_layout
3064    
3065     \begin_layout List
3066     \labelwidthstring 00000.00000.00000.000
3067     boolean_constant
3068     \begin_inset LatexCommand \index{boolean\_constant}
3069    
3070     \end_inset
3071    
3072     Logical value.
3073     May be used in determining model structure.
3074     \end_layout
3075    
3076     \begin_layout List
3077     \labelwidthstring 00000.00000.00000.000
3078    
3079     \bar under
3080     Setting\InsetSpace ~
3081     constants
3082     \bar default
3083    
3084     \begin_inset LatexCommand \index{constants, setting}
3085    
3086     \end_inset
3087    
3088    
3089     \end_layout
3090    
3091     \begin_layout List
3092     \labelwidthstring 00000.00000.00000.000
3093     :==
3094     \begin_inset LatexCommand \index{:==}
3095    
3096     \end_inset
3097    
3098     Constant and set assignment operator.
3099    
3100     \end_layout
3101    
3102     \begin_deeper
3103     \begin_layout Standard
3104     It is suggested, but not required, that names of all types that refine the
3105     built-in constant types have names that end in _constant.
3106     \end_layout
3107    
3108     \begin_layout LyX-Code
3109     LHS_list :== RHS;
3110     \end_layout
3111    
3112     \begin_layout Standard
3113     Here it is required that the one or more items in the LHS be of the same
3114     constant type and that RHS is a single-valued expression made up of values,
3115     operators, and other constants.
3116     The :== is used to make clear to both the user and the system what scalar
3117     objects are constants.
3118    
3119     \end_layout
3120    
3121     \begin_layout Subsection
3122     Variables
3123     \begin_inset LatexCommand \index{variables}
3124    
3125     \end_inset
3126    
3127    
3128     \end_layout
3129    
3130     \begin_layout Standard
3131     There are four built-in types which may be used to construct variables:
3132     symbol, boolean, integer, and real.
3133     At this time symbol types have special restrictions.
3134     Refinements of these variable base types are defined with the ATOM statement.
3135     Atom types may declare attribute fields with types real, integer, boolean,
3136     symbol, and set.
3137     These attributes are NOT independent objects and therefore cannot be refined,
3138     merged, or put in a refinement clique (ARE_ALIKEd).
3139     \end_layout
3140    
3141     \end_deeper
3142     \begin_layout List
3143     \labelwidthstring 00000.00000.00000.000
3144     ATOM
3145     \begin_inset LatexCommand \index{ATOM}
3146    
3147     \end_inset
3148    
3149     The syntax for declaring a new atom type is
3150     \end_layout
3151    
3152     \begin_deeper
3153     \begin_layout LyX-Code
3154     ATOM
3155     \emph on
3156     atom_type_name
3157     \emph default
3158     REFINES
3159     \emph on
3160     variable_type
3161     \end_layout
3162    
3163     \begin_layout LyX-Code
3164     «DIMENSION
3165     \emph on
3166     dimension_expression
3167     \emph default
3168     »
3169     \end_layout
3170    
3171     \begin_layout LyX-Code
3172     «DEFAULT
3173     \emph on
3174     value
3175     \emph default
3176     »; (* note the ; *)
3177     \end_layout
3178    
3179     \begin_layout LyX-Code
3180     «
3181     \emph on
3182     initial attribute assignment
3183     \emph default
3184    
3185     \end_layout
3186    
3187     \begin_layout LyX-Code
3188     END
3189     \emph on
3190     atom_type_name
3191     \emph default
3192     ;
3193     \end_layout
3194    
3195     \end_deeper
3196     \begin_layout List
3197     \labelwidthstring 00000.00000.00000.000
3198     DEFAULT
3199     \begin_inset LatexCommand \index{DEFAULT}
3200    
3201     \end_inset
3202    
3203     ,\InsetSpace ~
3204     DIMENSION
3205     \begin_inset LatexCommand \index{DIMENSION}
3206    
3207     \end_inset
3208    
3209     ,\InsetSpace ~
3210     and\InsetSpace ~
3211     DIMENSIONLESS
3212     \begin_inset LatexCommand \index{DIMENSIONLESS}
3213    
3214     \end_inset
3215    
3216    
3217     \end_layout
3218    
3219     \begin_deeper
3220     \begin_layout Standard
3221     The DIMENSION attribute is for variables whose base type is real.
3222     It is an optional field.
3223     If not defined for any atom with base type real, the dimensions will be
3224     left as undefined.
3225     Any variable which is later declared to be one of these types will be given
3226     wild card dimensionality (represented in the interactive display by an
3227     asterisk (*)).
3228     The system will deduce the dimensionality from its use in the relationships
3229     in which it appears or in the declaring of default values for it, if possible.
3230     \end_layout
3231    
3232     \end_deeper
3233     \begin_layout List
3234     \labelwidthstring 00000.00000.00000.000
3235     solver_var
3236     \begin_inset LatexCommand \index{solver\_var}
3237    
3238     \end_inset
3239    
3240     is a special case of ATOM and we will say much more about it in Section
3241    
3242     \begin_inset LatexCommand \vref{sub:x.6.1Variables-for-solvers}
3243    
3244     \end_inset
3245    
3246     .
3247     \end_layout
3248    
3249     \begin_deeper
3250     \begin_layout LyX-Code
3251     ATOM solver_var REFINES real DEFAULT 0.5 {?
3252     \begin_inset LatexCommand \index{?}
3253    
3254     \end_inset
3255    
3256     };
3257     \end_layout
3258    
3259     \begin_layout LyX-Code
3260     lower_bound IS_A real;
3261     \end_layout
3262    
3263     \begin_layout LyX-Code
3264     upper_bound IS_A real;
3265     \end_layout
3266    
3267     \begin_layout LyX-Code
3268     nominal IS_A real;
3269     \end_layout
3270    
3271     \begin_layout LyX-Code
3272     fixed IS_A boolean;
3273     \end_layout
3274    
3275     \begin_layout LyX-Code
3276     fixed := FALSE;
3277     \end_layout
3278    
3279     \begin_layout LyX-Code
3280     lower_bound := -1e20 {?};
3281     \end_layout
3282    
3283     \begin_layout LyX-Code
3284     upper_bound := 1e20 {?};
3285     \end_layout
3286    
3287     \begin_layout LyX-Code
3288     nominal := 0.5 {?};
3289     \end_layout
3290    
3291     \begin_layout LyX-Code
3292     END solver_var;
3293     \end_layout
3294    
3295     \begin_layout Standard
3296     The default field is also optional.
3297     If the atom has a declared dimensionality, then this value must be expressed
3298     with units which are compatible with this dimensionality.
3299     In the solver_var example, we see a DEFAULT value of 0.5 with the unspecified
3300     unit
3301     \begin_inset LatexCommand \index{unit, unspecified}
3302    
3303     \end_inset
3304    
3305    
3306     \begin_inset LatexCommand \index{unspecified unit}
3307    
3308     \end_inset
3309    
3310     {?
3311     \begin_inset LatexCommand \index{}
3312    
3313     \end_inset
3314    
3315     } which leaves the dimensionality wild
3316     \begin_inset LatexCommand \index{wild dimensionality}
3317    
3318     \end_inset
3319    
3320     .
3321     \end_layout
3322    
3323     \end_deeper
3324     \begin_layout List
3325     \labelwidthstring 00000.00000.00000.000
3326     real
3327     \begin_inset LatexCommand \index{real}
3328    
3329     \end_inset
3330    
3331     Real valued variable quantity.
3332     At present, all variables that you want to be attended to by solver tools
3333     must be refinements of the type solver_var.
3334     This is so that modifiable parametric values can be included in equations
3335     without treating them as variables.
3336     Strictly speaking, this is a characteristic of the solver interface and
3337     not the ASCEND language.
3338     Each tool in the total ASCEND system may have its own semantics that go
3339     beyond the ASCEND object definition language.
3340     \end_layout
3341    
3342     \begin_layout List
3343     \labelwidthstring 00000.00000.00000.000
3344     integer
3345     \begin_inset LatexCommand \index{integer}
3346    
3347     \end_inset
3348    
3349     Integer valued variable quantity.
3350     We find these mighty convenient for use in certain procedural computations
3351     and as attributes of solver_var atoms.
3352     \end_layout
3353    
3354     \begin_layout List
3355     \labelwidthstring 00000.00000.00000.000
3356     boolean
3357     \begin_inset LatexCommand \index{boolean}
3358    
3359     \end_inset
3360    
3361     Truth valued variable quantity.
3362     These are principally used as flags on solver_vars and relations.
3363     They can also be used procedurally and as variables in logical programming
3364     models, subject to the logical solver tools semantics.
3365     (Compare solver_boolean and boolean_var in Section
3366     \begin_inset LatexCommand \vref{sec:x.6Miscellany}
3367    
3368     \end_inset
3369    
3370     .)
3371     \end_layout
3372    
3373     \begin_layout List
3374     \labelwidthstring 00000.00000.00000.000
3375     symbol
3376     \begin_inset LatexCommand \index{symbol}
3377    
3378     \end_inset
3379    
3380     * 4 * Symbol valued variable quantity.
3381     We do not yet have operators for building symbols out of other symbols.
3382     \end_layout
3383    
3384     \begin_layout List
3385     \labelwidthstring 00000.00000.00000.000
3386    
3387     \bar under
3388     Setting\InsetSpace ~
3389     variables
3390     \bar default
3391    
3392     \begin_inset LatexCommand \index{variables, setting}
3393    
3394     \end_inset
3395    
3396    
3397     \end_layout
3398    
3399     \begin_layout List
3400     \labelwidthstring 00000.00000.00000.000
3401     :=
3402     \begin_inset LatexCommand \index{:=}
3403    
3404     \end_inset
3405    
3406     Procedural equals
3407     \begin_inset LatexCommand \index{equals, procedural}
3408    
3409     \end_inset
3410    
3411     differs from the ordinary equals (=) in that it means the left-hand-side
3412     (LHS) variables are to be assigned the value of the right-hand-side (RHS)
3413     expression when this statement is processed.
3414     Processing happens in the last phase of compiling (instantiation) or when
3415     executing a method interactively through the ASCEND user interface.
3416     The order the system encounters these statements matters, therefore, with
3417     a later result overwriting an earlier one if both statements have the same
3418     the same LHS variable.
3419    
3420     \end_layout
3421    
3422     \begin_deeper
3423     \begin_layout Standard
3424     Note that variable assignments (also known as defaulting statements) written
3425     in the declarative section are executed only after an instance has been
3426     fully created.
3427     This is a frequent source of confusion and errors, therefore we recommend
3428     that you DO NOT ASSIGN VARIABLES IN THE DECLARATIVE SECTION.
3429    
3430     \end_layout
3431    
3432     \end_deeper
3433     \begin_layout List
3434     \labelwidthstring 00000.00000.00000.000
3435     Note\InsetSpace ~
3436     that\InsetSpace ~
3437     :=\InsetSpace ~
3438     IS\InsetSpace ~
3439     NOT\InsetSpace ~
3440     =.
3441     \end_layout
3442    
3443     \begin_deeper
3444     \begin_layout Standard
3445     We use an ordinary equals (=) when defining a real valued equation to state
3446     that the LHS expression is to equal the RHS expression at the solution
3447     for the model.
3448     We use == for logical equations.
3449     \end_layout
3450    
3451     \end_deeper
3452     \begin_layout List
3453     \labelwidthstring 00000.00000.00000.000
3454    
3455     \bar under
3456     Tabular\InsetSpace ~
3457     assignments
3458     \bar default
3459    
3460     \begin_inset LatexCommand \index{assignments, tabular}
3461    
3462     \end_inset
3463    
3464     (* 4+ *) Assigning values en masse to arrays of variables that are defined
3465     associatively on sets without order presents a minor challenge.
3466     The solution proposed in ASCEND IV (but not yet implemented as weve not
3467     had time or significant user demand) is to allow a tabular data statement
3468     to be used to assign the elements of arrays of variables or constants.
3469     The DATA statement may be used to assign variables in the declarative or
3470     methods section of a model (though we discourage its use declaratively
3471     for variable initialization) or to assign constant arrays of any type,
3472     including sets, in the declarative section.
3473     Here are some examples:
3474     \end_layout
3475    
3476     \begin_deeper
3477     \begin_layout LyX-Code
3478     DATA ~(* ~4+ ~*)
3479     \end_layout
3480    
3481     \begin_layout LyX-Code
3482     MODEL tabular_ex;
3483     \end_layout
3484    
3485     \begin_layout LyX-Code
3486     lset,rset,cset IS_A set OF integer_constant;
3487     \end_layout
3488    
3489     \begin_layout LyX-Code
3490     rset :== [1..3];
3491     \end_layout
3492    
3493     \begin_layout LyX-Code
3494     cset :== rset - [2];
3495     \end_layout
3496    
3497     \begin_layout LyX-Code
3498     lset :== [5,7];
3499     \end_layout
3500    
3501     \begin_layout LyX-Code
3502     a[rset][cset] IS_A real;
3503     \end_layout
3504    
3505     \begin_layout LyX-Code
3506     b[lset][cset][rset] IS_A real_constant;
3507     \end_layout
3508    
3509     \begin_layout LyX-Code
3510     (* rectangle table *)
3511     \end_layout
3512    
3513     \begin_layout LyX-Code
3514     DATA FOR a:
3515     \end_layout
3516    
3517     \begin_layout LyX-Code
3518     COLUMNS 1,3; (*order last subscript cset*)
3519     \end_layout
3520    
3521     \begin_layout LyX-Code
3522     UNITS {kg/s}, {s}; (* columnar units *)
3523     \end_layout
3524    
3525     \begin_layout LyX-Code
3526     (* give leading subscripts *)
3527     \end_layout
3528    
3529     \begin_layout LyX-Code
3530     [1] 2.8, 0.3;
3531     \end_layout
3532    
3533     \begin_layout LyX-Code
3534     [2] 2.7, 1.3;
3535     \end_layout
3536    
3537     \begin_layout LyX-Code
3538     [3] 3.3, 0.6;
3539     \end_layout
3540    
3541     \begin_layout LyX-Code
3542     END DATA;
3543     \end_layout
3544    
3545     \begin_layout LyX-Code
3546     (* 2 layer rectangle table *)
3547     \end_layout
3548    
3549     \begin_layout LyX-Code
3550     CONSTANT DATA FOR b:
3551     \end_layout
3552    
3553     \begin_layout LyX-Code
3554     COLUMNS 1..3; (* order last subscript
3555     \end_layout
3556    
3557     \begin_layout LyX-Code
3558     rset *)
3559     \end_layout
3560    
3561     \begin_layout LyX-Code
3562     (* UNITS omitted, so either the user gives
3563     \end_layout
3564    
3565     \begin_layout LyX-Code
3566     value in the table or values given are
3567     \end_layout
3568    
3569     \begin_layout LyX-Code
3570     DIMENSIONLESS.
3571     *)
3572     \end_layout
3573    
3574     \begin_layout LyX-Code
3575     (* ordering over [lset][cset] required *)
3576     \end_layout
3577    
3578     \begin_layout LyX-Code
3579     [5][1] 3 {m}, 2{m}, 1{m};
3580     \end_layout
3581    
3582     \begin_layout LyX-Code
3583     [5][3] 0.1, 0.2, 0.3;
3584     \end_layout
3585    
3586     \begin_layout LyX-Code
3587     [7][1] -3 {m/s}, -2{m/s}, -1{m/s};
3588     \end_layout
3589    
3590     \begin_layout LyX-Code
3591     [7][3] 4.1 {1/s}, 4.2 {1/s}, 4.3 {1/s};
3592     \end_layout
3593    
3594     \begin_layout LyX-Code
3595     END DATA;
3596     \end_layout
3597    
3598     \begin_layout LyX-Code
3599     END tabular_ex;
3600     \end_layout
3601    
3602     \begin_layout Standard
3603     For sparse arrays of variables or constants, the COLUMNS and (possibly)
3604     UNITS keywords are omitted and the array subscripts are simply enumerated
3605     along with the values to be assigned.
3606     \end_layout
3607    
3608     \begin_layout Subsection
3609     Relations
3610     \begin_inset LatexCommand \index{relations}
3611    
3612     \end_inset
3613    
3614    
3615     \end_layout
3616    
3617     \end_deeper
3618     \begin_layout List
3619     \labelwidthstring 00000.00000.00000.000
3620    
3621     \bar under
3622     Mathematical\InsetSpace ~
3623     expression
3624     \begin_inset LatexCommand \index{mathematical expression}
3625    
3626     \end_inset
3627    
3628    
3629     \begin_inset LatexCommand \index{expression, math}
3630    
3631     \end_inset
3632    
3633     :
3634     \end_layout
3635    
3636     \begin_deeper
3637     \begin_layout Standard
3638     The syntax for a mathematical expression is any legal combination of variable
3639     names and arithmetic operators in the normal notation.
3640     An expression may contain any number of matched rounded parentheses, (),
3641     to clarify meaning.
3642     The following is a legal arithmetic expression:
3643     \end_layout
3644    
3645     \begin_layout LyX-Code
3646     y^2+(sin(x)-tan(z))*q
3647     \end_layout
3648    
3649     \begin_layout Standard
3650     Each additive term in a mathematical expression (terms are separated by
3651     + or - operators) must have the same dimensionality.
3652     \end_layout
3653    
3654     \begin_layout Standard
3655     An expression may contain an index variable as a part of the calculation
3656     if that index variable is over a set whose elements are of type integer.
3657     (See the FOR/CREATE and FOR/DO statements below.) An example is:
3658     \end_layout
3659    
3660     \begin_layout LyX-Code
3661     term[i] = a[i]*x^(i-1);
3662     \end_layout
3663    
3664     \end_deeper
3665     \begin_layout List
3666     \labelwidthstring 00000.00000.00000.000
3667    
3668     \bar under
3669     Numerical\InsetSpace ~
3670     relations
3671     \bar default
3672    
3673     \begin_inset LatexCommand \index{relations, numerical}
3674    
3675     \end_inset
3676    
3677    
3678     \begin_inset LatexCommand \index{numerical relations}
3679    
3680     \end_inset
3681    
3682    
3683     \end_layout
3684    
3685     \begin_deeper
3686     \begin_layout Standard
3687     The syntax for a numeric relation is either
3688     \end_layout
3689    
3690     \begin_layout LyX-Code
3691    
3692     \emph on
3693     optional_label
3694     \emph default
3695     :
3696     \emph on
3697     LHS relational_operator RHS
3698     \emph default
3699     ;
3700     \end_layout
3701    
3702     \begin_layout Standard
3703     or
3704     \end_layout
3705    
3706     \begin_layout LyX-Code
3707    
3708     \emph on
3709     optional_label
3710     \emph default
3711     :
3712     \emph on
3713     objective_type LHS
3714     \emph default
3715     ;
3716     \end_layout
3717    
3718     \begin_layout Standard
3719     Objective_type is either MAXIMIZE or MINIMIZE.
3720     RHS and LHS must be one or more variables, constants, and operators in
3721     a normal algebraic expression.
3722     The operators allowed are defined below and in Section
3723     \begin_inset LatexCommand \vref{sub:x.6.3Single-operand-real}
3724    
3725     \end_inset
3726    
3727     .
3728     Variable integers, booleans, and symbols are not allowed as operands in
3729     numerical relations, nor are boolean constants.
3730     Integer indices declared in FOR/CREATE loops are allowed in relations,
3731     and they are treated as integer constants.
3732     \end_layout
3733    
3734     \end_deeper
3735     \begin_layout List
3736     \labelwidthstring 00000.00000.00000.000
3737    
3738     \bar under
3739     Relational\InsetSpace ~
3740     operators
3741     \begin_inset LatexCommand \index{operators, relational}
3742    
3743     \end_inset
3744    
3745    
3746     \begin_inset LatexCommand \index{relational operators}
3747    
3748     \end_inset
3749    
3750     :
3751     \end_layout
3752    
3753     \begin_layout List
3754     \labelwidthstring 00000.00000.00000.000
3755     =
3756     \begin_inset LatexCommand \index{=}
3757    
3758     \end_inset
3759    
3760     ,\InsetSpace ~
3761     >=
3762     \begin_inset LatexCommand \index{ >=}
3763    
3764     \end_inset
3765    
3766     ,\InsetSpace ~
3767     <=
3768     \begin_inset LatexCommand \index{<=}
3769    
3770     \end_inset
3771    
3772     ,\InsetSpace ~
3773     <
3774     \begin_inset LatexCommand \index{<}
3775    
3776     \end_inset
3777    
3778     ,\InsetSpace ~
3779     >
3780     \begin_inset LatexCommand \index{>}
3781    
3782     \end_inset
3783    
3784     ,\InsetSpace ~
3785     <>
3786     \begin_inset LatexCommand \index{<>}
3787    
3788     \end_inset
3789    
3790     These are the numerical relational operators for declarative use.
3791     \end_layout
3792    
3793     \begin_deeper
3794     \begin_layout LyX-Code
3795     Ftot*y['methane'] = m['methane'];
3796     \end_layout
3797    
3798     \begin_layout LyX-Code
3799     y['ethanol'] >= 0;
3800     \end_layout
3801    
3802     \begin_layout Standard
3803     Equations must be dimensionally correct.
3804     \end_layout
3805    
3806     \end_deeper
3807     \begin_layout List
3808     \labelwidthstring 00000.00000.00000.000
3809     MAXIMIZE
3810     \begin_inset LatexCommand \index{MAXIMIZE}
3811    
3812     \end_inset
3813    
3814     ,\InsetSpace ~
3815     MINIMIZE
3816     \begin_inset LatexCommand \index{MINIMIZE}
3817    
3818     \end_inset
3819    
3820    
3821     \end_layout
3822    
3823     \begin_deeper
3824     \begin_layout Standard
3825     Objective function indicators.
3826    
3827     \end_layout
3828    
3829     \end_deeper
3830     \begin_layout List
3831     \labelwidthstring 00000.00000.00000.000
3832    
3833     \bar under
3834     Binary\InsetSpace ~
3835     Operators
3836     \begin_inset LatexCommand \index{operators, binary}
3837    
3838     \end_inset
3839    
3840    
3841     \begin_inset LatexCommand \index{binary operators}
3842    
3843     \end_inset
3844    
3845     :
3846     \bar default
3847     +, -, *, /, ^.
3848     We follow the usual algebraic order of operations for binary operators.
3849     \end_layout
3850    
3851     \begin_layout List
3852     \labelwidthstring 00000.00000.00000.000
3853     +
3854     \begin_inset LatexCommand \index{+, binary math}
3855    
3856     \end_inset
3857    
3858     Plus.
3859     Numerical addition or set union.
3860     \end_layout
3861    
3862     \begin_layout List
3863     \labelwidthstring 00000.00000.00000.000
3864     -
3865     \begin_inset LatexCommand \index{-, binary math}
3866    
3867     \end_inset
3868    
3869     Minus.
3870     Numerical subtraction or set difference.
3871     \end_layout
3872    
3873     \begin_layout List
3874     \labelwidthstring 00000.00000.00000.000
3875     *
3876     \begin_inset LatexCommand \index{*, binary math}
3877    
3878     \end_inset
3879    
3880     Times.
3881     Numerical multiplication or set intersection.
3882     \end_layout
3883    
3884     \begin_layout List
3885     \labelwidthstring 00000.00000.00000.000
3886     /
3887     \begin_inset LatexCommand \index{/}
3888    
3889     \end_inset
3890    
3891     Divide.
3892     Numeric division.
3893     In most cases it implies real division and not integer division.
3894     \end_layout
3895    
3896     \begin_layout List
3897     \labelwidthstring 00000.00000.00000.000
3898     ^ Power
3899     \begin_inset LatexCommand \index{power}
3900    
3901     \end_inset
3902    
3903     .
3904     Numeric exponentiation.
3905     If the value of y in x^y is not integer, then x must be greater than 0.0
3906     and dimensionless.
3907     \end_layout
3908    
3909     \begin_layout List
3910     \labelwidthstring 00000.00000.00000.000
3911    
3912     \bar under
3913     Unary\InsetSpace ~
3914     Operators
3915     \begin_inset LatexCommand \index{operators, unary}
3916    
3917     \end_inset
3918    
3919    
3920     \begin_inset LatexCommand \index{unary operators}
3921    
3922     \end_inset
3923    
3924     :
3925     \bar default
3926     -
3927     \begin_inset LatexCommand \index{-, unary}
3928    
3929     \end_inset
3930    
3931     , ordered_function()
3932     \end_layout
3933    
3934     \begin_layout List
3935     \labelwidthstring 00000.00000.00000.000
3936     - Unary minus.
3937     Numeric negation.
3938     There is no unary +
3939     \begin_inset LatexCommand \index{+, math unary}
3940    
3941     \end_inset
3942    
3943     operator.
3944     \end_layout
3945    
3946     \begin_layout List
3947     \labelwidthstring 00000.00000.00000.000
3948     ordered_function
3949     \begin_inset LatexCommand \index{ordered\_function}
3950    
3951     \end_inset
3952    
3953     () unary real valued functions.
3954     The unary real functions we support are given in section Section
3955     \begin_inset LatexCommand \vref{sub:x.6.3Single-operand-real}
3956    
3957     \end_inset
3958    
3959     .
3960     \end_layout
3961    
3962     \begin_layout List
3963     \labelwidthstring 00000.00000.00000.000
3964     Real\InsetSpace ~
3965     functions\InsetSpace ~
3966     of\InsetSpace ~
3967     sets\InsetSpace ~
3968     of\InsetSpace ~
3969     real\InsetSpace ~
3970     terms:
3971     \end_layout
3972    
3973     \begin_layout List
3974     \labelwidthstring 00000.00000.00000.000
3975     SUM
3976     \begin_inset LatexCommand \index{SUM}
3977    
3978     \end_inset
3979    
3980     [term\InsetSpace ~
3981     set] Add all expressions in the functions list.
3982     \end_layout
3983    
3984     \begin_deeper
3985     \begin_layout Standard
3986     For the SUM, the base type real items can be arbitrary arithmetic expressions.
3987     The resulting items must all be dimensionally compatible.
3988     \end_layout
3989    
3990     \begin_layout Standard
3991     An examples of the use is:
3992     \end_layout
3993    
3994     \begin_layout LyX-Code
3995     SUM[y[components]] = 1;
3996     \end_layout
3997    
3998     \begin_layout Standard
3999     or, equivalently, one could write:
4000     \end_layout
4001    
4002     \begin_layout LyX-Code
4003     SUM[y[i] | i IN components] = 1;
4004     \end_layout
4005    
4006     \end_deeper
4007     \begin_layout List
4008     \labelwidthstring 00000.00000.00000.000
4009    
4010     \bar under
4011     Empty\InsetSpace ~
4012     SUM[]\InsetSpace ~
4013     yields\InsetSpace ~
4014     wild\InsetSpace ~
4015     0.
4016     \end_layout
4017    
4018     \begin_deeper
4019     \begin_layout Standard
4020     When a SUM is compiled over a list which is empty it generates a wild dimensione
4021     d 0.
4022     This will sometimes cause our dimension checking routines to fail.
4023     The best way to prevent this is to make sure the SUM never actually encounters
4024     an empty list.
4025     For example:
4026     \end_layout
4027    
4028     \begin_layout LyX-Code
4029     SUM[Q[possibly_empty_set], 0{watt}];
4030     \end_layout
4031    
4032     \begin_layout Standard
4033     In the above, the variables Q[i] (if they exist) have the dimensionality
4034     associated with an energy rate.
4035     When the set is empty, the 0 is the only term in the SUM and establishes
4036     the dimensionality of the result.
4037     When the set is NOT empty the compiler will simplify away the trailing
4038     0 in the sum.
4039     \end_layout
4040    
4041     \end_deeper
4042     \begin_layout List
4043     \labelwidthstring 00000.00000.00000.000
4044     PROD
4045     \begin_inset LatexCommand \index{PROD}
4046    
4047     \end_inset
4048    
4049     [term\InsetSpace ~
4050     set] Multiply all the expressions in the products list.
4051     The product of an empty list is a dimensionless value, 1.0.
4052     \end_layout
4053    
4054     \begin_layout List
4055     \labelwidthstring 00000.00000.00000.000
4056    
4057     \bar under
4058     Possible\InsetSpace ~
4059     future\InsetSpace ~
4060     functions:
4061     \end_layout
4062    
4063     \begin_deeper
4064     \begin_layout Standard
4065     (Not implemented - only under confused consideration at this time.) The following
4066     functions only work in methods as they are not smooth function and would
4067     destroy a Newton-based solution algorithm if used in defining a model equation:
4068     \end_layout
4069    
4070     \end_deeper
4071     \begin_layout List
4072     \labelwidthstring 00000.00000.00000.000
4073     MAX
4074     \begin_inset LatexCommand \index{MAX}
4075    
4076     \end_inset
4077    
4078     [term\InsetSpace ~
4079     set] (* 4+ *) maximum value on list of arguments
4080     \end_layout
4081    
4082     \begin_layout List
4083     \labelwidthstring 00000.00000.00000.000
4084     MIN
4085     \begin_inset LatexCommand \index{MIN}
4086    
4087     \end_inset
4088    
4089     [term\InsetSpace ~
4090     set] (* 4+ *) minimum value on list of arguments
4091     \end_layout
4092    
4093     \begin_deeper
4094     \begin_layout Subsection
4095     Derivatives
4096     \begin_inset LatexCommand \index{derivatives}
4097    
4098     \end_inset
4099    
4100     in relations (* 4+ *)
4101     \end_layout
4102    
4103     \begin_layout Standard
4104     Simply put, we would like to have general partial and full derivatives usable
4105     in writing equations, as there are many mathematically interesting things
4106     that can be said about both.
4107     We have not implemented such things yet for lack of time and because with
4108     several implementations (see gPROMS and OMOLA, among others) already out