-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCh3.html
2519 lines (2483 loc) · 260 KB
/
Ch3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html>
<head>
<title>3 Operators and Expressions‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4</title>
<!--Generated on Tue Oct 10 11:49:58 2017 by LaTeXML (version 0.8.2) http://dlmf.nist.gov/LaTeXML/.-->
<!--Document created on October 10, 2017.-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="LaTeXML.css" type="text/css">
<link rel="stylesheet" href="ltx-report.css" type="text/css">
<link rel="stylesheet" href="ltx-listings.css" type="text/css">
<link rel="stylesheet" href="LaTeXML-navbar-left.css" type="text/css">
<script src="LatexML-maybeMathJax.js" type="text/javascript"></script>
<link rel="up" href="MSL.html" title="Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
<link rel="start" href="MSL.html" title="Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
<link rel="prev" href="Ch2.html" title="Chapter 2 Lexical Structure ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
<link rel="next" href="Ch4.html" title="Chapter 4 Classes, Predefined Types, and Declarations ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
<link rel="chapter" href="Chx1.html" title="Preface ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
<link rel="chapter" href="Ch1.html" title="Chapter 1 Introduction ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
<link rel="chapter" href="Ch2.html" title="Chapter 2 Lexical Structure ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
<link rel="chapter" href="Ch4.html" title="Chapter 4 Classes, Predefined Types, and Declarations ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4">
</head>
<body>
<nav class="ltx_page_navbar"><a href="MSL.html" title="Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref" rel="start"><span class="ltx_text ltx_ref_title">Modelica® - A Unified Object-Oriented Language for Systems Modeling<span class="ltx_text"> </span>Language Specification<span class="ltx_text"> </span>Version 3.4</span></a>
<div class="ltx_TOC">
<ul class="ltx_toclist">
<li class="ltx_tocentry ltx_tocentry_document">
<a href="MSL.html" title="Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">Modelica® - A Unified Object-Oriented Language for Systems Modeling<span class="ltx_text"> </span>Language Specification<span class="ltx_text"> </span>Version 3.4</span></a>
<ul class="ltx_toclist ltx_toclist_document">
<li class="ltx_tocentry ltx_tocentry_chapter"><a href="Chx1.html" title="Preface ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">Preface</span></a></li>
<li class="ltx_tocentry ltx_tocentry_chapter"><a href="Ch1.html" title="Chapter 1 Introduction ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">1 </span>Introduction</span></a></li>
<li class="ltx_tocentry ltx_tocentry_chapter"><a href="Ch2.html" title="Chapter 2 Lexical Structure ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2 </span>Lexical Structure</span></a></li>
<li class="ltx_tocentry ltx_tocentry_chapter ltx_ref_self">
<span class="ltx_ref ltx_ref_self"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3 </span>Operators and Expressions</span></span>
<ul class="ltx_toclist ltx_toclist_chapter">
<li class="ltx_tocentry ltx_tocentry_section"><a href="#S1" title="3.1 Expressions ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.1 </span>Expressions</span></a></li>
<li class="ltx_tocentry ltx_tocentry_section"><a href="#S2" title="3.2 Operator Precedence and Associativity ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.2 </span>Operator Precedence and Associativity</span></a></li>
<li class="ltx_tocentry ltx_tocentry_section">
<a href="#S3" title="3.3 Evaluation Order ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.3 </span>Evaluation Order</span></a>
<ul class="ltx_toclist ltx_toclist_section">
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S3.SS1" title="3.3.1 Example: Guarding Expressions Against Incorrect Evaluation ‣ 3.3 Evaluation Order ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.3.1 </span>Example: Guarding Expressions Against Incorrect Evaluation</span></a></li>
</ul>
</li>
<li class="ltx_tocentry ltx_tocentry_section"><a href="#S4" title="3.4 Arithmetic Operators ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.4 </span>Arithmetic Operators</span></a></li>
<li class="ltx_tocentry ltx_tocentry_section"><a href="#S5" title="3.5 Equality, Relational, and Logical Operators ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.5 </span>Equality, Relational, and Logical Operators</span></a></li>
<li class="ltx_tocentry ltx_tocentry_section">
<a href="#S6" title="3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6 </span>Miscellaneous Operators and Variables</span></a>
<ul class="ltx_toclist ltx_toclist_section">
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S6.SS1" title="3.6.1 String Concatenation ‣ 3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6.1 </span>String Concatenation</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S6.SS2" title="3.6.2 Array Constructor Operator ‣ 3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6.2 </span>Array Constructor Operator</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S6.SS3" title="3.6.3 Array Concatenation Operator ‣ 3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6.3 </span>Array Concatenation Operator</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S6.SS4" title="3.6.4 Array Range Operator ‣ 3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6.4 </span>Array Range Operator</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S6.SS5" title="3.6.5 If-Expressions ‣ 3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6.5 </span>If-Expressions</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S6.SS6" title="3.6.6 Member Access Operator ‣ 3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6.6 </span>Member Access Operator</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S6.SS7" title="3.6.7 Built-in Variable time ‣ 3.6 Miscellaneous Operators and Variables ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.6.7 </span>Built-in Variable time</span></a></li>
</ul>
</li>
<li class="ltx_tocentry ltx_tocentry_section">
<a href="#S7" title="3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.7 </span>Built-in Intrinsic Operators with Function Syntax</span></a>
<ul class="ltx_toclist ltx_toclist_section">
<li class="ltx_tocentry ltx_tocentry_subsection">
<a href="#S7.SS1" title="3.7.1 Numeric Functions and Conversion Functions ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.7.1 </span>Numeric Functions and Conversion Functions</span></a>
<ul class="ltx_toclist ltx_toclist_subsection">
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS1.SSS1" title="Event Triggering Mathematical Functions ‣ 3.7.1 Numeric Functions and Conversion Functions ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">Event Triggering Mathematical Functions</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS1.SSS2" title="Built-in Mathematical Functions and External Built-in Functions ‣ 3.7.1 Numeric Functions and Conversion Functions ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">Built-in Mathematical Functions and External Built-in Functions</span></a></li>
</ul>
</li>
<li class="ltx_tocentry ltx_tocentry_subsection">
<a href="#S7.SS2" title="3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.7.2 </span>Derivative and Special Purpose Operators with Function Syntax</span></a>
<ul class="ltx_toclist ltx_toclist_subsection">
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS2.SSS1" title="delay ‣ 3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">delay</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS2.SSS2" title="spatialDistribution ‣ 3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">spatialDistribution</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS2.SSS3" title="cardinality (deprecated) ‣ 3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">cardinality (deprecated)</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS2.SSS4" title="homotopy ‣ 3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">homotopy</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS2.SSS5" title="semiLinear ‣ 3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">semiLinear</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS2.SSS6" title="getInstanceName ‣ 3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">getInstanceName</span></a></li>
</ul>
</li>
<li class="ltx_tocentry ltx_tocentry_subsection">
<a href="#S7.SS3" title="3.7.3 Event-Related Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.7.3 </span>Event-Related Operators with Function Syntax</span></a>
<ul class="ltx_toclist ltx_toclist_subsection">
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS3.SSS1" title="pre ‣ 3.7.3 Event-Related Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">pre</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsubsection"><a href="#S7.SS3.SSS2" title="noEvent and smooth ‣ 3.7.3 Event-Related Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title">noEvent and smooth</span></a></li>
</ul>
</li>
</ul>
</li>
<li class="ltx_tocentry ltx_tocentry_section">
<a href="#S8" title="3.8 Variability of Expressions ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.8 </span>Variability of Expressions</span></a>
<ul class="ltx_toclist ltx_toclist_section">
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S8.SS1" title="3.8.1 Constant Expressions ‣ 3.8 Variability of Expressions ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.8.1 </span>Constant Expressions</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S8.SS2" title="3.8.2 Parameter Expressions ‣ 3.8 Variability of Expressions ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.8.2 </span>Parameter Expressions</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S8.SS3" title="3.8.3 Discrete-Time Expressions ‣ 3.8 Variability of Expressions ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.8.3 </span>Discrete-Time Expressions</span></a></li>
<li class="ltx_tocentry ltx_tocentry_subsection"><a href="#S8.SS4" title="3.8.4 Continuous-Time Expressions ‣ 3.8 Variability of Expressions ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.8.4 </span>Continuous-Time Expressions</span></a></li>
</ul>
</li>
</ul>
</li>
<li class="ltx_tocentry ltx_tocentry_chapter"><a href="Ch4.html" title="Chapter 4 Classes, Predefined Types, and Declarations ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4 </span>Classes, Predefined Types, and Declarations</span></a></li>
</ul>
</li>
</ul>
</div>
</nav>
<div class="ltx_page_main">
<header class="ltx_page_header">
<div>
<a href="MSL.html" title="Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref" rel="up"><span class="ltx_text ltx_ref_title">Modelica® - A Unified Object-Oriented Language for Systems Modeling<span class="ltx_text"> </span>Language Specification<span class="ltx_text"> </span>Version 3.4</span></a><a href="Ch2.html" title="Chapter 2 Lexical Structure ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref" rel="prev"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">2 </span>Lexical Structure</span></a><a href="Ch4.html" title="Chapter 4 Classes, Predefined Types, and Declarations ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref" rel="next"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">4 </span>Classes, Predefined Types, and Declarations</span></a>
</div></header>
<div class="ltx_page_content">
<section class="ltx_chapter ltx_authors_1line">
<h1 class="ltx_title ltx_title_chapter">
<span class="ltx_tag ltx_tag_chapter">Chapter 3 </span>Operators and Expressions</h1>
<div class="ltx_date ltx_role_creation"></div>
<div id="p1" class="ltx_para">
<p class="ltx_p"><a name="operators-and-expressions" id="operators-and-expressions" class="ltx_anchor"></a></p>
</div>
<div id="p2" class="ltx_para">
<p class="ltx_p">The lexical units are combined to form even larger building blocks such
as expressions according to the rules given by the expression part of
the Modelica grammar in Appendix B.</p>
</div>
<div id="p3" class="ltx_para">
<p class="ltx_p">This chapter describes the evaluation rules for expressions, the concept
of expression variability, built-in mathematical operators and
functions, and the built-in special Modelica operators with function
syntax.</p>
</div>
<div id="p4" class="ltx_para">
<p class="ltx_p">Expressions can contain variables and constants, which have types,
predefined or user defined. The predefined built-in types of Modelica
are Real, Integer, Boolean, String, and enumeration types which are
presented in more detail in Section <a href="Ch4.html#S8" title="4.8 Predefined Types ‣ Chapter 4 Classes, Predefined Types, and Declarations ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">4.8</span></a>. [<em class="ltx_emph">The abbreviated
predefined type information below is given as background information for
the rest of the presentation.</em>]</p>
</div>
<section id="S1" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3.1 </span>Expressions</h2>
<div id="S1.p1" class="ltx_para">
<p class="ltx_p">Modelica equations, assignments and declaration equations contain
expressions.</p>
</div>
<div id="S1.p2" class="ltx_para">
<p class="ltx_p">Expressions can contain basic operations, +, -, *, /, ^, etc. with
normal precedence as defined in the Table in Section <a href="#S2" title="3.2 Operator Precedence and Associativity ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">3.2</span></a> and the
grammar in Appendix B. The semantics of the operations is defined for
both scalar and array arguments in Section 10.6.</p>
</div>
<div id="S1.p3" class="ltx_para">
<p class="ltx_p">It is also possible to define functions and call them in a normal
fashion. The function call syntax for both positional and named
arguments is described in Section 12.4.1 and for vectorized calls in
Section 12.4.4. The built-in array functions are given in Section
10.1.1 and other built-in operators in Section <a href="#S7" title="3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref ltx_refmacro_nameref"><span class="ltx_text ltx_ref_title"><span class="ltx_tag ltx_tag_ref">3.7 </span>Built-in Intrinsic Operators with Function Syntax</span></a>.</p>
</div>
</section>
<section id="S2" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3.2 </span>Operator Precedence and Associativity</h2>
<div id="S2.p1" class="ltx_para">
<p class="ltx_p"><a name="operator-precedence" id="operator-precedence" class="ltx_anchor"></a></p>
</div>
<div id="S2.p2" class="ltx_para">
<p class="ltx_p">Operator precedence determines the order of evaluation of operators in
an expression. An operator with higher precedence is evaluated before an
operator with lower precedence in the same expression.</p>
</div>
<div id="S2.p3" class="ltx_para">
<p class="ltx_p">The following table presents all the expression operators in order of
precedence from highest to lowest, as derived from the Modelica grammar
in Appendix B. All operators are binary except the postfix operators
and those shown as unary together with <em class="ltx_emph">expr</em>, the conditional
operator, the array construction operator {} and concatenation
operator [ ], and the array range constructor which is either binary
or ternary. Operators with the same precedence occur at the same line of
the table:</p>
</div>
<figure id="T1" class="ltx_table">
<figcaption class="ltx_caption"><span class="ltx_tag ltx_tag_table">Table 3.1: </span>Operators</figcaption>
<table class="ltx_tabular ltx_guessed_headers ltx_align_middle">
<thead class="ltx_thead">
<tr class="ltx_tr">
<th class="ltx_td ltx_align_justify ltx_th ltx_th_column ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;"><em class="ltx_emph">Operator Group</em></th>
<th class="ltx_td ltx_align_justify ltx_th ltx_th_column ltx_border_r ltx_border_t" style="width:113.8pt;"><em class="ltx_emph">Operator Syntax</em></th>
<th class="ltx_td ltx_align_justify ltx_th ltx_th_column ltx_border_r ltx_border_t" style="width:99.6pt;"><em class="ltx_emph">Examples</em></th>
</tr>
</thead>
<tbody class="ltx_tbody">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">postfix array index operator</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">[]</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">arr[index]</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">postfix access operator</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">.</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">a.b</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">postfix function call</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">
<em class="ltx_emph">funcName</em>(<em class="ltx_emph">function-arguments</em>)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">sin(4.36)</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">array construct/concat</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">{<em class="ltx_emph">expressions</em>}[<em class="ltx_emph">expressions</em>] [<em class="ltx_emph">expressions</em>;<em class="ltx_emph">expressions</em>…]</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">{2,3} [5,6][2,3; 7,8]</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">exponentiation</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">^</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">2^3</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">multiplicative and array elementwise multiplicative</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">* / .* ./</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">2*3 2/3 [1,2;3,4].*[2,3;5,6]</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">additive and array elementwise additive</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">+ - +<em class="ltx_emph">expr</em> -<em class="ltx_emph">expr</em> .+ .-</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">[1,2;3,4].+[2,3;5,6]</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">relational</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">< <= > >= == <></td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">a<b, a<=b, a>b, …</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">unary negation</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">not <em class="ltx_emph">expr</em>
</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">not b1</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">logical and</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">and</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">b1 and b2</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">logical or</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">or</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">b1 or b2</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">array range</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">
<em class="ltx_emph">expr</em> : <em class="ltx_emph">expr</em>
<em class="ltx_emph">expr</em> : <em class="ltx_emph">expr</em> : <em class="ltx_emph">expr</em>
</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">1:5
start:step:stop</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">conditional</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:113.8pt;">if <em class="ltx_emph">expr</em> then <em class="ltx_emph">expr</em> else <em class="ltx_emph">expr</em>
</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:99.6pt;">if b
then 3 else x</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_b ltx_border_l ltx_border_r ltx_border_t" style="width:85.4pt;">named argument</td>
<td class="ltx_td ltx_align_justify ltx_border_b ltx_border_r ltx_border_t" style="width:113.8pt;">
<em class="ltx_emph">ident</em> = <em class="ltx_emph">expr</em>
</td>
<td class="ltx_td ltx_align_justify ltx_border_b ltx_border_r ltx_border_t" style="width:99.6pt;">x = 2.26</td>
</tr>
</tbody>
</table>
</figure>
<div id="S2.p4" class="ltx_para">
<p class="ltx_p">The conditional operator may also include elseif-clauses. Equality = and
assignment := are not expression operators since they are allowed only
in equations and in assignment statements respectively. All binary
expression operators are left associative, except exponentiation which
is non-associative. The array range operator is non-associative.</p>
</div>
<div id="S2.p5" class="ltx_para">
<p class="ltx_p">[<em class="ltx_emph">The unary minus and plus in Modelica is slightly different than
in Mathematica and in MATLAB</em><span class="ltx_note ltx_role_footnote"><sup class="ltx_note_mark">2</sup><span class="ltx_note_outer"><span class="ltx_note_content"><sup class="ltx_note_mark">2</sup>MATLAB is a registered trademark
of MathWorks Inc.</span></span></span><em class="ltx_emph">, since the following expressions are illegal
(whereas in Mathematica</em><span class="ltx_note ltx_role_footnote"><sup class="ltx_note_mark">3</sup><span class="ltx_note_outer"><span class="ltx_note_content"><sup class="ltx_note_mark">3</sup>Mathematica is a registered trademark
of Wolfram Research Inc.</span></span></span> <em class="ltx_emph">and in MATLAB these are valid
expressions):</em></p>
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,MiotMiAvLyA9IC00IGluIE1hdGhlbWF0aWNhL01BVExBQjsgaXMgaWxsZWdhbCBpbiBNb2RlbGlj%0AYQotLTIgLy8gPSAyIGluIE1hdGhlbWF0aWNhL01BVExBQjsgaXMgaWxsZWdhbCBpbiBNb2RlbGlj%0AYQorKzIgLy8gPSAyIGluIE1hdGhlbWF0aWNhL01BVExBQjsgaXMgaWxsZWdhbCBpbiBNb2RlbGlj%0AYQoyLS0yIC8vID0gNCBpbiBNYXRoZW1hdGljYS9NQVRMQUI7IGlzIGlsbGVnYWwgaW4gTW9kZWxp%0AY2E=%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text" style="font-size:80%;">2*-2</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>-4<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Mathematica/MATLAB;<span class="ltx_text ltx_lst_space"> </span>is<span class="ltx_text ltx_lst_space"> </span>illegal<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Modelica</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text" style="font-size:80%;">–2</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>2<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Mathematica/MATLAB;<span class="ltx_text ltx_lst_space"> </span>is<span class="ltx_text ltx_lst_space"> </span>illegal<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Modelica</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text" style="font-size:80%;">++2</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>2<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Mathematica/MATLAB;<span class="ltx_text ltx_lst_space"> </span>is<span class="ltx_text ltx_lst_space"> </span>illegal<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Modelica</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text" style="font-size:80%;">2–2</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>=<span class="ltx_text ltx_lst_space"> </span>4<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Mathematica/MATLAB;<span class="ltx_text ltx_lst_space"> </span>is<span class="ltx_text ltx_lst_space"> </span>illegal<span class="ltx_text ltx_lst_space"> </span>in<span class="ltx_text ltx_lst_space"> </span>Modelica</span>
</div>
</div>
<p class="ltx_p"><em class="ltx_emph">Non-associative exponentation and array range operator:</em></p>
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,eF55XnogLy8gTm90IGxlZ2FsLCB1c2UgcGFyZW50aGVzaXMgdG8gbWFrZSBpdCBjbGVhcgphOmI6%0AYzpkOmU6ZjpnIC8vIE5vdCBsZWdhbCwgYW5kIHNjYWxhciBhcmd1bWVudHMgZ2l2ZXMgbm8gbGVn%0AYWwKaW50ZXJwcmV0YXRpb24u%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">x</span><span class="ltx_text" style="font-size:80%;">^</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">y</span><span class="ltx_text" style="font-size:80%;">^</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">z</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>Not<span class="ltx_text ltx_lst_space"> </span>legal,<span class="ltx_text ltx_lst_space"> </span>use<span class="ltx_text ltx_lst_space"> </span>parenthesis<span class="ltx_text ltx_lst_space"> </span>to<span class="ltx_text ltx_lst_space"> </span>make<span class="ltx_text ltx_lst_space"> </span>it<span class="ltx_text ltx_lst_space"> </span>clear</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">a</span><span class="ltx_text" style="font-size:80%;">:</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">b</span><span class="ltx_text" style="font-size:80%;">:</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">c</span><span class="ltx_text" style="font-size:80%;">:</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">d</span><span class="ltx_text" style="font-size:80%;">:</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">e</span><span class="ltx_text" style="font-size:80%;">:</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">f</span><span class="ltx_text" style="font-size:80%;">:</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">g</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>Not<span class="ltx_text ltx_lst_space"> </span>legal,<span class="ltx_text ltx_lst_space"> </span>and<span class="ltx_text ltx_lst_space"> </span>scalar<span class="ltx_text ltx_lst_space"> </span>arguments<span class="ltx_text ltx_lst_space"> </span>gives<span class="ltx_text ltx_lst_space"> </span>no<span class="ltx_text ltx_lst_space"> </span>legal</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">interpretation.</span>
</div>
</div>
<p class="ltx_p"><em class="ltx_emph"></em>]</p>
</div>
</section>
<section id="S3" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3.3 </span>Evaluation Order</h2>
<div id="S3.p1" class="ltx_para">
<p class="ltx_p"><a name="evaluation-order" id="evaluation-order" class="ltx_anchor"></a>
</p>
</div>
<div id="S3.p2" class="ltx_para">
<p class="ltx_p">A tool is free to solve equations, reorder expressions and to not
evaluate expressions if their values do not influence the result (e.g.
short-circuit evaluation of Boolean expressions). If-statements and
if-expressions guarantee that their clauses are only evaluated if the
appropriate condition is true, but relational operators generating state
or time events will during continuous integration have the value from
the most recent event.</p>
</div>
<div id="S3.p3" class="ltx_para">
<p class="ltx_p">If a numeric operation overflows the result is undefined. For literals
it is recommended to automatically convert the number to another type
with greater precision.</p>
</div>
<section id="S3.SS1" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.3.1 </span>Example: Guarding Expressions Against Incorrect Evaluation</h3>
<div id="S3.SS1.p1" class="ltx_para">
<p class="ltx_p">[<em class="ltx_emph">Example. If one wants to guard an expression against incorrect
evaluation, it should be guarded by an if:</em></p>
</div>
<div id="S3.SS1.p2" class="ltx_para">
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,Qm9vbGVhbiB2W25dOwogIEJvb2xlYW4gYjsKICBJbnRlZ2VyIEk7CmVxdWF0aW9uCiAgeD12W0ld%0AIGFuZCAoST49MSBhbmQgSTw9bik7IC8vIEludmFsaWQKICB4PWlmIChJPj0xIGFuZCBJPD1uKSB0%0AaGVuIHZbSV0gZWxzZSBmYWxzZTsgLy8gQ29ycmVjdA==%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Boolean</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">v</span><span class="ltx_text" style="font-size:80%;">[</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">n</span><span class="ltx_text" style="font-size:80%;">];</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Boolean</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">b</span><span class="ltx_text" style="font-size:80%;">;</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Integer</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">I</span><span class="ltx_text" style="font-size:80%;">;</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">equation</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">x</span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">v</span><span class="ltx_text" style="font-size:80%;">[</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">I</span><span class="ltx_text" style="font-size:80%;">]</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">and</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">I</span><span class="ltx_text" style="font-size:80%;">>=1</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">and</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">I</span><span class="ltx_text" style="font-size:80%;"><=</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">n</span><span class="ltx_text" style="font-size:80%;">);</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>Invalid</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">x</span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">if</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">I</span><span class="ltx_text" style="font-size:80%;">>=1</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">and</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">I</span><span class="ltx_text" style="font-size:80%;"><=</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">n</span><span class="ltx_text" style="font-size:80%;">)</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">v</span><span class="ltx_text" style="font-size:80%;">[</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">I</span><span class="ltx_text" style="font-size:80%;">]</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">else</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">false</span><span class="ltx_text" style="font-size:80%;">;</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>Correct</span>
</div>
</div>
</div>
<div id="S3.SS1.p3" class="ltx_para">
<p class="ltx_p"><em class="ltx_emph">To guard square against square root of negative number use</em>
noEvent<em class="ltx_emph">:</em></p>
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,ICBkZXIoaCk9aWYgaD4wIHRoZW4gLWMqc3FydChoKSBlbHNlIDA7IC8vIEluY29ycmVjdAogIGRl%0AcihoKT1pZiBub0V2ZW50KGg+MCkgdGhlbiAtYypzcXJ0KGgpIGVsc2UgMDsgLy8gQ29ycmVjdA==%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">der</span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">h</span><span class="ltx_text" style="font-size:80%;">)=</span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">if</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">h</span><span class="ltx_text" style="font-size:80%;">>0</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">-</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">c</span><span class="ltx_text" style="font-size:80%;">*</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">sqrt</span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">h</span><span class="ltx_text" style="font-size:80%;">)</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">else</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">0;</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>Incorrect</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">der</span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">h</span><span class="ltx_text" style="font-size:80%;">)=</span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">if</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">noEvent</span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">h</span><span class="ltx_text" style="font-size:80%;">>0)</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">-</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">c</span><span class="ltx_text" style="font-size:80%;">*</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">sqrt</span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">h</span><span class="ltx_text" style="font-size:80%;">)</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">else</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">0;</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>Correct</span>
</div>
</div>
</div>
<div id="S3.SS1.p4" class="ltx_para">
<p class="ltx_p">]</p>
</div>
</section>
</section>
<section id="S4" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3.4 </span>Arithmetic Operators</h2>
<div id="S4.p1" class="ltx_para">
<p class="ltx_p">Modelica supports five binary arithmetic operators that operate on any
numerical type:</p>
</div>
<figure id="T2" class="ltx_table">
<table class="ltx_tabular">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left">^</td>
<td class="ltx_td ltx_align_left">Exponentiation</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td"></td>
<td class="ltx_td ltx_align_left">Multiplication</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left">/</td>
<td class="ltx_td ltx_align_left">Division</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left">+</td>
<td class="ltx_td ltx_align_left">Addition</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left">-</td>
<td class="ltx_td ltx_align_left">Subtraction</td>
</tr>
</table>
</figure>
<div id="S4.p2" class="ltx_para">
<p class="ltx_p">Some of these operators can also be applied to a combination of a scalar
type and an array type, see Section 10.6.</p>
</div>
<div id="S4.p3" class="ltx_para">
<p class="ltx_p">The syntax of these operators is defined by the following rules from the
Modelica grammar:</p>
<div class="ltx_listing ltx_lst_language_grammar ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,YXJpdGhtZXRpY19leHByZXNzaW9uIDoKICBbIGFkZF9vcCBdIHRlcm0geyBhZGRfb3AgdGVybSB9%0ACgphZGRfb3AgOgogICIrIiB8ICItIgoKdGVybSA6CiAgZmFjdG9yIHsgbXVsX29wIGZhY3RvciB9%0ACgptdWxfb3AgOgogICIqIiB8ICIvIgoKZmFjdG9yIDoKICBwcmltYXJ5IFsgIl4iIHByaW1hcnkg%0AXQ==%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">arithmetic_expression</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">[</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">add_op</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">]</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">term</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">{</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">add_op</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">term</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">}</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">add_op</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"+"</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">|</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"-"</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">term</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">factor</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">{</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">mul_op</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">factor</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">}</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">mul_op</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"*"</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">|</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"/"</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">factor</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">primary</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">[</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"^"</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">primary</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">]</span>
</div>
</div>
</div>
</section>
<section id="S5" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3.5 </span>Equality, Relational, and Logical Operators</h2>
<div id="S5.p1" class="ltx_para">
<p class="ltx_p"><a name="equality-relational-and-logical-operators" id="equality-relational-and-logical-operators" class="ltx_anchor"></a></p>
</div>
<div id="S5.p2" class="ltx_para">
<p class="ltx_p">Modelica supports the standard set of relational and logical operators,
all of which produce the standard boolean values true or false.</p>
</div>
<figure id="T3" class="ltx_table">
<table class="ltx_tabular">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left">></td>
<td class="ltx_td ltx_align_left">greater than</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left">>=</td>
<td class="ltx_td ltx_align_left">greater than or equal</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left"><</td>
<td class="ltx_td ltx_align_left">less than</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left"><=</td>
<td class="ltx_td ltx_align_left">less than or equal to</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left">==</td>
<td class="ltx_td ltx_align_left">equality within expressions</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left"><></td>
<td class="ltx_td ltx_align_left">Inequality</td>
</tr>
</table>
</figure>
<div id="S5.p3" class="ltx_para">
<p class="ltx_p">A single equals sign = is never used in relational expressions, only in
equations (Chapter 8, Section 10.6.1) and in function calls using
named parameter passing (Section 12.4.1).</p>
</div>
<div id="S5.p4" class="ltx_para">
<p class="ltx_p">The following logical operators are defined:</p>
</div>
<figure id="T4" class="ltx_table">
<table class="ltx_tabular">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left"><span class="ltx_text ltx_font_bold">not</span></td>
<td class="ltx_td ltx_align_left">negation, unary operator</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left"><span class="ltx_text ltx_font_bold">and</span></td>
<td class="ltx_td ltx_align_left">logical and</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_left"><span class="ltx_text ltx_font_bold">or</span></td>
<td class="ltx_td ltx_align_left">logical or</td>
</tr>
</table>
</figure>
<div id="S5.p5" class="ltx_para">
<p class="ltx_p">The grammar rules define the syntax of the relational and logical
operators.</p>
<div class="ltx_listing ltx_lst_language_grammar ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,bG9naWNhbF9leHByZXNzaW9uIDoKICBsb2dpY2FsX3Rlcm0geyBvciBsb2dpY2FsX3Rlcm0gfQoK%0AbG9naWNhbF90ZXJtIDoKICBsb2dpY2FsX2ZhY3RvciB7IGFuZCBsb2dpY2FsX2ZhY3RvciB9Cgps%0Ab2dpY2FsX2ZhY3RvciA6CiAgWyBub3QgXSByZWxhdGlvbgoKcmVsYXRpb24gOgogICBhcml0aG1l%0AdGljX2V4cHJlc3Npb24gWyByZWxfb3AgYXJpdGhtZXRpY19leHByZXNzaW9uIF0KCnJlbF9vcCA6%0ACiAgIjwiIHwgIjw9IiB8ICI+IiB8ICI+PSIgfCAiPT0iIHwgIjw+Ig==%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">logical_expression</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">logical_term</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">{</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">or</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">logical_term</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">}</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">logical_term</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">logical_factor</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">{</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">and</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">logical_factor</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">}</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">logical_factor</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">[</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">not</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">]</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">relation</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">relation</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">arithmetic_expression</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">[</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">rel_op</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">arithmetic_expression</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">]</span>
</div>
<div class="ltx_listingline">
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_identifier" style="font-size:80%;">rel_op</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">:</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"<"</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">|</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"<="</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">|</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">">"</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">|</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">">="</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">|</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"=="</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">|</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"<>"</span>
</div>
</div>
</div>
<div id="S5.p6" class="ltx_para">
<p class="ltx_p">The following holds for relational operators:</p>
</div>
<div id="S5.p7" class="ltx_para">
<ul id="I1" class="ltx_itemize">
<li id="I1.i1" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I1.i1.p1" class="ltx_para">
<p class="ltx_p">Relational operators <, <=, >,
>=, ==, <>, are only defined for
scalar operands of simple types. The result is Boolean and is true or
false if the relation is fulfilled or not, respectively.</p>
</div>
</li>
<li id="I1.i2" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I1.i2.p1" class="ltx_para">
<p class="ltx_p">For operands of type String, str1 op str2 is for each relational
operator, op, defined in terms of the C-function strcmp as
strcmp(str1,str2) op 0.</p>
</div>
</li>
<li id="I1.i3" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I1.i3.p1" class="ltx_para">
<p class="ltx_p">For operands of type Boolean, false<true.</p>
</div>
</li>
<li id="I1.i4" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I1.i4.p1" class="ltx_para">
<p class="ltx_p">For operands of enumeration types, the order is given by the order of
declaration of the enumeration literals.</p>
</div>
</li>
<li id="I1.i5" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I1.i5.p1" class="ltx_para">
<p class="ltx_p">In relations of the form v1 == v2 or v1 <> v2,
v1 or v2 shall, unless used in a function, not be a subtype of Real.
[<em class="ltx_emph">The reason for this rule is that relations with Real
arguments are transformed to state events (see Events, Section</em>
8.5<em class="ltx_emph">) and this transformation becomes unnecessarily complicated
for the == and <> relational operators (e.g.
two crossing functions instead of one crossing function needed,
epsilon strategy needed even at event instants). Furthermore, testing
on equality of Real variables is questionable on machines where the
number length in registers is different to number length in main
memory</em>].</p>
</div>
</li>
<li id="I1.i6" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I1.i6.p1" class="ltx_para">
<p class="ltx_p">Relations of the form ‘‘v1 rel_op v2’’, with v1 and v2 variables and
rel_op a relational operator are called elementary relations. If
either v1 or v2 or both variables are a subtype of Real, the relation
is called a Real elementary relation.</p>
</div>
</li>
</ul>
</div>
</section>
<section id="S6" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3.6 </span>Miscellaneous Operators and Variables</h2>
<div id="S6.p1" class="ltx_para">
<p class="ltx_p">Modelica also contains a few built-in operators which are not standard
arithmetic, relational, or logical operators. These are described below,
including time, which is a built-in variable, not an operator.</p>
</div>
<section id="S6.SS1" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.6.1 </span>String Concatenation</h3>
<div id="S6.SS1.p1" class="ltx_para">
<p class="ltx_p">Concatenation of strings (see the Modelica grammar) is denoted by the +
operator in Modelica [<em class="ltx_emph">e.g.</em> "a" + "b" <em class="ltx_emph">becomes</em> "ab"].</p>
</div>
</section>
<section id="S6.SS2" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.6.2 </span>Array Constructor Operator</h3>
<div id="S6.SS2.p1" class="ltx_para">
<p class="ltx_p">The array constructor operator { … } is described in Section 10.4.</p>
</div>
</section>
<section id="S6.SS3" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.6.3 </span>Array Concatenation Operator</h3>
<div id="S6.SS3.p1" class="ltx_para">
<p class="ltx_p">The array concatenation operator [ … ] is described in Section
10.4.2.</p>
</div>
</section>
<section id="S6.SS4" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.6.4 </span>Array Range Operator</h3>
<div id="S6.SS4.p1" class="ltx_para">
<p class="ltx_p">The array range constructor operator : is described in Section 10.4.3.</p>
</div>
</section>
<section id="S6.SS5" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.6.5 </span>If-Expressions</h3>
<div id="S6.SS5.p1" class="ltx_para">
<p class="ltx_p">An expression</p>
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,aWYgZXhwcmVzc2lvbjEgdGhlbiBleHByZXNzaW9uMiBlbHNlIGV4cHJlc3Npb24z%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">if</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">expression1</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">expression2</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">else</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">expression3</span>
</div>
</div>
</div>
<div id="S6.SS5.p2" class="ltx_para">
<p class="ltx_p">is one example of if-expression. First expression1, which must be
boolean expression, is evaluated. If expression1 is true expression2 is
evaluated and is the value of the if-expression, else expression3 is
evaluated and is the value of the if-expression. The two expressions,
expression2 and expression3, must be type compatible expressions
(Section 6.6) giving the type of the if-expression. If-expressions with
elseif are defined by replacing elseif by else if. [<em class="ltx_emph">Note:</em>
elseif <em class="ltx_emph">has been added for symmetry with if-clauses.</em>] For
short-circuit evaluation see Section <a href="#S3" title="3.3 Evaluation Order ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">3.3</span></a>.</p>
</div>
<div id="S6.SS5.p3" class="ltx_para">
<p class="ltx_p">[<em class="ltx_emph">Example</em>:
</p>
</div>
<div id="S6.SS5.p4" class="ltx_para">
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,SW50ZWdlciBpOwpJbnRlZ2VyIHNpZ25fb2ZfaTE9aWYgaTwwIHRoZW4gLTEgZWxzZWlmIGk9PTAg%0AdGhlbiAwIGVsc2UgMTsKSW50ZWdlciBzaWduX29mX2kyPWlmIGk8MCB0aGVuIC0xIGVsc2UgaWYg%0AaT09MCB0aGVuIDAgZWxzZSAxOw==%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Integer</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">i</span><span class="ltx_text" style="font-size:80%;">;</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Integer</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">sign_of_i1</span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">if</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">i</span><span class="ltx_text" style="font-size:80%;"><0</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">-1</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">elseif</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">i</span><span class="ltx_text" style="font-size:80%;">==0</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">0</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">else</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">1;</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Integer</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">sign_of_i2</span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">if</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">i</span><span class="ltx_text" style="font-size:80%;"><0</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">-1</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">else</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">if</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">i</span><span class="ltx_text" style="font-size:80%;">==0</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">then</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">0</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">else</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">1;</span>
</div>
</div>
</div>
</section>
<section id="S6.SS6" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.6.6 </span>Member Access Operator</h3>
<div id="S6.SS6.p1" class="ltx_para">
<p class="ltx_p">It is possible to access members of a class instance using dot notation,
i.e., the . operator.</p>
</div>
<div id="S6.SS6.p2" class="ltx_para">
<p class="ltx_p">[<em class="ltx_emph">Example:</em> R1.R <em class="ltx_emph">for accessing the resistance component</em> R
<em class="ltx_emph">of resistor</em> R1<em class="ltx_emph">. Another use of dot notation: local classes
which are members of a class can of course also be accessed using dot
notation on the name of the class, not on instances of the class.</em>]</p>
</div>
</section>
<section id="S6.SS7" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.6.7 </span>Built-in Variable time</h3>
<div id="S6.SS7.p1" class="ltx_para">
<p class="ltx_p">All declared variables are functions of the independent variable time.
The variable time is a built-in variable available in all models and
blocks, which is treated as an input variable. It is implicitly defined
as:</p>
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,aW5wdXQgUmVhbCB0aW1lIChmaW5hbCBxdWFudGl0eSA9ICJUaW1lIiwKICAgICAgICAgICAgICAg%0AICBmaW5hbCB1bml0ICAgICA9ICJzIik7%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">input</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Real</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">time</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">final</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">quantity</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"Time"</span><span class="ltx_text" style="font-size:80%;">,</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">final</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">unit</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_string" style="font-size:80%;color:#000000;">"s"</span><span class="ltx_text" style="font-size:80%;">);</span>
</div>
</div>
</div>
<div id="S6.SS7.p2" class="ltx_para">
<p class="ltx_p">The value of the start attribute of time is set to the time instant at
which the simulation is started.</p>
</div>
<div id="S6.SS7.p3" class="ltx_para">
<p class="ltx_p">[<em class="ltx_emph">Example</em>:</p>
<div class="ltx_listing ltx_lst_language_modelica ltx_lstlisting ltx_listing" style="background-color:#FFFFFF;">
<div class="ltx_listing_data"><a href="data:text/plain;base64,ZW5jYXBzdWxhdGVkIG1vZGVsIFNpbmVTb3VyY2UKICBpbXBvcnQgTW9kZWxpY2EuTWF0aC5zaW47%0ACiAgY29ubmVjdG9yIE91dFBvcnQ9b3V0cHV0IFJlYWw7CiAgT3V0UG9ydCB5PXNpbih0aW1lKTsg%0ALy8gVXNlcyB0aGUgYnVpbHQtaW4gdmFyaWFibGUgdGltZS4KZW5kIFNpbmVTb3VyY2U7%0A">⬇</a></div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">encapsulated</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">model</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">SineSource</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">import</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">Modelica.Math.sin</span><span class="ltx_text" style="font-size:80%;">;</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">connector</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">OutPort</span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">output</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">Real</span><span class="ltx_text" style="font-size:80%;">;</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">OutPort</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">y</span><span class="ltx_text" style="font-size:80%;">=</span><span class="ltx_text ltx_lst_keywords3" style="font-size:80%;color:#E60000;">sin</span><span class="ltx_text" style="font-size:80%;">(</span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">time</span><span class="ltx_text" style="font-size:80%;">);</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_comment" style="font-size:80%;color:#006600;">//<span class="ltx_text ltx_lst_space"> </span>Uses<span class="ltx_text ltx_lst_space"> </span>the<span class="ltx_text ltx_lst_space"> </span>built-in<span class="ltx_text ltx_lst_space"> </span>variable<span class="ltx_text ltx_lst_space"> </span>time.</span>
</div>
<div class="ltx_listingline">
<span class="ltx_text ltx_lst_keywords2 ltx_font_bold" style="font-size:80%;color:#000066;">end</span><span class="ltx_text ltx_lst_space" style="font-size:80%;"> </span><span class="ltx_text ltx_lst_identifier" style="font-size:80%;">SineSource</span><span class="ltx_text" style="font-size:80%;">;</span>
</div>
</div>
<p class="ltx_p">]</p>
</div>
</section>
</section>
<section id="S7" class="ltx_section">
<h2 class="ltx_title ltx_title_section">
<span class="ltx_tag ltx_tag_section">3.7 </span>Built-in Intrinsic Operators with Function Syntax</h2>
<div id="S7.p1" class="ltx_para">
<p class="ltx_p"><a name="built-in-intrinsic-operators-with-function-syntax" id="built-in-intrinsic-operators-with-function-syntax" class="ltx_anchor"></a></p>
</div>
<div id="S7.p2" class="ltx_para">
<p class="ltx_p">Certain built-in operators of Modelica have the same syntax as a
function call. However, they do not behave as a mathematical function,
because the result depends not only on the input arguments but also on
the status of the simulation.</p>
</div>
<div id="S7.p3" class="ltx_para">
<p class="ltx_p">There are also built-in functions that depend only on the input
argument, but also may trigger events in addition to returning a value.
Intrinsic means that they are defined at the Modelica language level,
not in the Modelica library. The following built-in intrinsic
operators/functions are available:</p>
</div>
<div id="S7.p4" class="ltx_para">
<ul id="I2" class="ltx_itemize">
<li id="I2.i1" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I2.i1.p1" class="ltx_para">
<p class="ltx_p">Mathematical functions and conversion functions, see Section <a href="#S7.SS1" title="3.7.1 Numeric Functions and Conversion Functions ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">3.7.1</span></a>.
below.</p>
</div>
</li>
</ul>
</div>
<div id="S7.p5" class="ltx_para">
<ul id="I3" class="ltx_itemize">
<li id="I3.i1" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I3.i1.p1" class="ltx_para">
<p class="ltx_p">Derivative and special purpose operators with function syntax, see
Section <a href="#S7.SS2" title="3.7.2 Derivative and Special Purpose Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">3.7.2</span></a> below.</p>
</div>
</li>
<li id="I3.i2" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I3.i2.p1" class="ltx_para">
<p class="ltx_p">Event-related operators with function syntax, see Section <a href="#S7.SS3" title="3.7.3 Event-Related Operators with Function Syntax ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">3.7.3</span></a>
below.</p>
</div>
</li>
<li id="I3.i3" class="ltx_item" style="list-style-type:none;">
<span class="ltx_tag ltx_tag_itemize">•</span>
<div id="I3.i3.p1" class="ltx_para">
<p class="ltx_p">Array operators/functions, see Section 10.1.1.</p>
</div>
</li>
</ul>
</div>
<div id="S7.p6" class="ltx_para">
<p class="ltx_p">With exception of built-in operator String(..), all operators in this
section can only be called with positional arguments.</p>
</div>
<section id="S7.SS1" class="ltx_subsection">
<h3 class="ltx_title ltx_title_subsection">
<span class="ltx_tag ltx_tag_subsection">3.7.1 </span>Numeric Functions and Conversion Functions</h3>
<div id="S7.SS1.p1" class="ltx_para">
<p class="ltx_p"><a name="numeric-functions-and-conversion-functions" id="numeric-functions-and-conversion-functions" class="ltx_anchor"></a>
</p>
</div>
<div id="S7.SS1.p2" class="ltx_para">
<p class="ltx_p">The following mathematical operators and functions, also including some
conversion functions, are predefined in Modelica, and are vectorizable
according to Section 12.4.6, except for the String function. The
functions which do not trigger events are described in the table below,
whereas the event-triggering mathematical functions are described in
Section <a href="#S7.SS1.SSS1" title="Event Triggering Mathematical Functions ‣ 3.7.1 Numeric Functions and Conversion Functions ‣ 3.7 Built-in Intrinsic Operators with Function Syntax ‣ Chapter 3 Operators and Expressions ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">3.7.1</span></a>.</p>
</div>
<figure id="T5" class="ltx_table">
<table class="ltx_tabular">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:99.6pt;">abs(v)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Is expanded into ‘‘noEvent(<span class="ltx_text ltx_font_bold">if</span> v >= 0
<span class="ltx_text ltx_font_bold">then</span> v <span class="ltx_text ltx_font_bold">else</span> –v)’’. Argument v needs to be an Integer
or Real expression.</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:99.6pt;">sign(v)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Is expanded into ‘‘noEvent(<span class="ltx_text ltx_font_bold">if</span> v>0
<span class="ltx_text ltx_font_bold">then</span> 1 <span class="ltx_text ltx_font_bold">else if</span> v<0 <span class="ltx_text ltx_font_bold">then</span> –1
<span class="ltx_text ltx_font_bold">else</span> 0)’’. Argument v needs to be an Integer or Real
expression.</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:99.6pt;">sqrt(v)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the square root of v if v>=0, otherwise
an error occurs. Argument v needs to be an Integer or Real
expression.</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_l ltx_border_r ltx_border_t" style="width:99.6pt;">Integer(e)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the ordinal number of the expression e of
enumeration type that evaluates to the enumeration value E.enumvalue,
where Integer(E.e1)=1, Integer(E.en)= n, for an enumeration type
E=enumeration(e1, …, en). See also Section <a href="Ch4.html#S8.SS5.SSS1" title="Attributes of Enumeration Types ‣ 4.8.5 Enumeration Types ‣ 4.8 Predefined Types ‣ Chapter 4 Classes, Predefined Types, and Declarations ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">4.8.5</span></a>.</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_justify ltx_border_b ltx_border_l ltx_border_r ltx_border_t" style="width:99.6pt;">String(b,<options>)String(i,<options>)String(r, significantDigits=d, options)String(r, format=s)String(e, <options>)</td>
<td class="ltx_td ltx_align_justify ltx_border_b ltx_border_r ltx_border_t" style="width:227.6pt;">Convert a scalar non-String expression to a String representation. The
first argument may be a Boolean b, an Integer i, a Real r or an
Enumeration e (Section <a href="Ch4.html#S8.SS5.SSS1" title="Attributes of Enumeration Types ‣ 4.8.5 Enumeration Types ‣ 4.8 Predefined Types ‣ Chapter 4 Classes, Predefined Types, and Declarations ‣ Modelica® - A Unified Object-Oriented Language for Systems Modeling Language Specification Version 3.4" class="ltx_ref"><span class="ltx_text ltx_ref_tag">4.8.5</span></a>). The other arguments must use named arguments. The optional
<options> are:
Integer minimumLength=0: minimum length of the resulting string. If
necessary, the blank character is used to fill up unused space.
Boolean leftJustified = true: if true, the converted result is left
justified in the string; if false it is right justified in the string.
For Real expressions the output shall be according to the Modelica
grammar. Integer significantDigits=6: defines the number of significant
digits in the result string. [<em class="ltx_emph">Examples: "</em>12.3456<em class="ltx_emph">",
"</em>0.0123456<em class="ltx_emph">", "</em>12345600<em class="ltx_emph">", "</em>1.23456E-10<em class="ltx_emph">"</em>]<em class="ltx_emph">.</em>
The format string corresponding to options is:
for Reals: (if leftJustified then "-" else
"")+String(minimumLength)+"."+ String(signficantDigits)+"g",
for Integers: (if leftJustified then "-" else
"")+String(minimumLength)+"d".
Format string: According to ANSI-C the format string specifies one
conversion specifier (excluding the leading %), may not contain length
modifiers, and may not use "*" for width and/or precision. For all
numeric values the format specifiers f, e, E, g, G are allowed. For
integral values it is also allowed to use the d, i, o, x, X, u, and
c-format specifiers (for non-integral values a tool may round, truncate
or use a different format if the integer conversion characters are
used).
The x,X-formats (hexa-decimal) and c (character) for Integers does not
lead to input that agrees with the Modelica-grammar.</td>
</tr>
</table>
</figure>
<section id="S7.SS1.SSS1" class="ltx_subsubsection">
<h4 class="ltx_title ltx_title_subsubsection">Event Triggering Mathematical Functions</h4>
<div id="S7.SS1.SSS1.p1" class="ltx_para">
<p class="ltx_p"><a name="event-triggering-mathematical-functions" id="event-triggering-mathematical-functions" class="ltx_anchor"></a></p>
</div>
<div id="S7.SS1.SSS1.p2" class="ltx_para">
<p class="ltx_p">The built-in operators in this section trigger state events if used
outside of a when-clause and outside of a clocked discrete-time
partition (see Section 16.8.1). [ <em class="ltx_emph">If this is not desired, the</em>
noEvent <em class="ltx_emph">function can be applied to them. E.g.</em> noEvent(integer(v))
]</p>
</div>
<figure id="T6" class="ltx_table">
<table class="ltx_tabular">
<tr class="ltx_tr">
<td class="ltx_td ltx_align_center ltx_border_l ltx_border_r ltx_border_t">div(x,y)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the algebraic quotient x/y with any fractional part
discarded (also known as truncation toward zero). [<em class="ltx_emph">Note: this is
defined for / in C99; in C89 the result for negative numbers is
implementation-defined, so the standard function div() must be
used.</em>]. Result and arguments shall have type Real or Integer. If
either of the arguments is Real the result is Real otherwise
Integer.</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_center ltx_border_l ltx_border_r ltx_border_t">mod(x,y)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the integer modulus of x/y, i.e.
mod(x,y)=x-floor(x/y)*y. Result and arguments shall have type Real or
Integer. If either of the arguments is Real the result is Real otherwise
Integer. [<em class="ltx_emph">Note, outside of a when-clause state events are
triggered when the return value changes discontinuously. Examples</em>
mod(3,1.4)=0.2<em class="ltx_emph">,</em> mod(-3,1.4)=1.2<em class="ltx_emph">,</em>
mod(3,-1.4)=-1.2]</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_center ltx_border_l ltx_border_r ltx_border_t">rem(x,y)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the integer remainder of x/y, such that div(x,y)*y +
rem(x, y) = x. Result and arguments shall have type Real or Integer. If
either of the arguments is Real the result is Real otherwise Integer.
[<em class="ltx_emph">Note, outside of a when-clause state events are triggered when
the return value changes discontinuously. Examples</em>
rem(3,1.4)=0.2<em class="ltx_emph">,</em> rem(-3,1.4)=-0.2]</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_center ltx_border_l ltx_border_r ltx_border_t">ceil(x)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the smallest integer not less than x. Result and
argument shall have type Real. [<em class="ltx_emph">Note, outside of a when-clause
state events are triggered when the return value changes
discontinuously.</em>]</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_center ltx_border_l ltx_border_r ltx_border_t">floor(x)</td>
<td class="ltx_td ltx_align_justify ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the largest integer not greater than x. Result and
argument shall have type Real. [<em class="ltx_emph">Note, outside of a when-clause
state events are triggered when the return value changes
discontinuously.</em>].</td>
</tr>
<tr class="ltx_tr">
<td class="ltx_td ltx_align_center ltx_border_b ltx_border_l ltx_border_r ltx_border_t">integer(x)</td>
<td class="ltx_td ltx_align_justify ltx_border_b ltx_border_r ltx_border_t" style="width:227.6pt;">Returns the largest integer not greater
than x. The argument shall have type Real. The result has type
Integer.[<em class="ltx_emph">Note, outside of a when-clause state
events are triggered when the return value changes
discontinuously.</em>].</td>
</tr>
</table>
</figure>
</section>
<section id="S7.SS1.SSS2" class="ltx_subsubsection">
<h4 class="ltx_title ltx_title_subsubsection">Built-in Mathematical Functions and External Built-in Functions</h4>
<div id="S7.SS1.SSS2.p1" class="ltx_para">
<p class="ltx_p"><a name="built-in-mathematical-functions-and-external-built-in-functions" id="built-in-mathematical-functions-and-external-built-in-functions" class="ltx_anchor"></a></p>