logo_calcloop.gif

To the top page

Overview & Download
How to describe expressions
Version history

How to describe expressions

(The contents explained here are also usable for CalcLoop plus and ByeGraph.)


  1. Basis
  2. Usable key words
  3. Expression header
  4. Example -- File reading function
  5. Example -- Reading and displaying strings
  6. CalcEngine version history

1. Basis

As for multiple expressions like an example listed below, each expression is separated by @, and the last one includes y= at the beginning. A range of the loop variable is specified by using x=<::>. The arguments are start, end and step values from the left. Here, abc and def are user definition variables, and pi is a registered constant. (Both a user definition variable and a registered constant are configured by alphabetic characters only or those plus numeric characters.)

x = < -2*pi: 2*pi: 0.01*pi > @
abc = 2 * x @
def = 3 * x @
y = sin( abc ) + cos( def )

But when an expression is used alone as following, y= may be omitted. (It is imperative on ByeGraph.)

2+3*(log(sin(2*pi^2))+6.8)

Parameters are specified by ={,,,} and allowed to hold up to 16 elements. Each parameter can include user definition variables, functions and so on. Here, sita is a user definition variable, and kRad is a registered constant.

x = < 0: 360: 1 > @
sita = { 0, 45, 90 } @
y = sin( kRad * ( x + sita ) )


2. Usable key words

Kinds Key words, supplements
Variable x, y   Normally x is used as the loop variable. y is only used at the left side of the last expression line.
User definition variable alphabetic characters only or alphabetic + numeric characters.  [ex] var, abc01
Registered constant alphabetic characters only or alphabetic + numeric characters.  [ex] pi, K0, ep0
Global variable _M0 - _M15   For looping these value are kept. The initial values are 0 by default. '_M0(+)=A' and '_M0(-)=A' are also available.
Global variable initializer ginit<> initializes _M0~_M15 with particular values.  [ex] _M0=ginit<10>
Loop counter #LOOP contains the current loop count value. No substitution.
Parameter counter #PARAM contains the current parameter count value. No substitution.
Row depth constant for fread source #FREADMAX stands for the row's depth of the source data for fread/fread2.
Separator @
Substitution =
Range of loop variable <::>   Start, end and step values from the left.  [ex] x=<-2*pi:2*pi:0.01*pi>
Parameters {,,,}   Up to 16 elements are allowed.  [ex] sita={a,b,c}
Numeric value 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, e, E
Sign +, -
Operator +, -, *, /, ^
Relation operator >、<、≥、≤、=、≠
Parenthesis (,)
Math function ln(), log(), exp(), sin(), cos(), tan(), asin(), acos(), atan(), sqrt(), abs(), fmod(,), inv()
File reading function fread() requires an argument that is a column data number counting from zero. fread2(,) requires two arguments, for row and column. In these, you need to specify a file for reading data.
Array data reading function dread(,)   The array data defined in the %data header are read. Two arguments are respectively a row and a column data number counting from zero.
Sum function sum('exp',k=m:n)   The partial sum of 'exp' (m:start, n:end).
Switch function switch('test',A:B)   If 'test' results in true (>=1), it returns A. Otherwise, B.
Comment mark ! is inserted at the beginning of comment lines. But it is allowed to insert in the middle of a line except for the expression headers.
[Note] •• fmod(a,b) outputs the remainder of a ÷ b. •• Considering priority of operators ( +,- << *,/ << ^ ), evaluation for values is done from the left. Using parentheses, '()', the priority can be changed. •• Radian is used as a unit for an angle of trigonometric functions. •• <::>, {,,,} or ginit<> must be used alone on the right side of an expression. (=a*<::> is not allowed. ) •• The relation operators ( >、<、≥、≤、=、≠ ) are allowed to use only inside the 'test' expression of switch('test',A:B). •• The sum or switch function is not allowed to include itself in it.


3. Expression header

Expression headers are provided for specifying optional settings to expressions or their results.

Names Functions
%data The array data defined between %data and %end are read by dread(,) function.
%format Specify the formats of calculation results. As parameters, f (Real), e (Exponential real), d (Integer), y (Integer, divided every three figures) and s (Strings) are prepared.
%external Specify the source file for the file read functions (fread / fread2).
%statout
(Only for CalcLoop)
Calculate and output statistics constants (sum, average, and so on) for each column of calculation results after looping is completed.
%gout
(Only for CalcLoop)
Output values of the global variables under the calculation results after looping is completed.


4. Example -- File reading function

By using file reading functions in expressions you can add several calculation processes into original data which were taken by inquiry or experiment. There are two types of file reading functions: fread for sequential access and fread2 for random access. Applied examples of the fread function are shown below.

[Example] Read the x and y data, calculate omg=2*pi*x from x and multiply y and omg^2.

(Data in the source)
	0.0 1  2
	0.1 2  4
	0.2 3  6
	0.3 4  8
	0.4 5 10
	:   :  :

Specification for the loop variable x (x=<::>) is not necessary because data are read by the fread function. The loop count depends on the number of the row depth of the source file.

(Expressions)
! Specify formats
%format f e
x = fread(0) @
omg = 2*pi*x @
w = { 1, 2 } @
y = fread(w)*omg^2

The results are as follows.

(Results)
	0.0  0.000e+00 0.000e+00
	0.1  7.896e-01 1.579e+00
	0.2  4.737e+00 9.475e+00
	0.3  1.421e+01 2.842e+01
	0.4  3.158e+01 6.317e+01
	 :         :         :


5. Example -- Reading and displaying strings

From the version 1.8, reading strings becomes possible. Here is an example about it.

[Example] Let's try to add calculated column data newly into the 5th and 6th blank columns which have labels only. (These labels are made to remain.) And the %statout header is used for calculating statistics data for each column.

(Data in the source)
	Name    Math  English  Science  Total  Average
	JAMES     78      81      58
	MARY      68      83      63
	JOHN      72      77      71
	PATRICIA  91      68      69
	ROBERT    77      71      88
	LINDA     88      82      59
	MICHAEL   90      72      74
	BARBARA   69      71      58
	WILLIAM   78      79      63
	ELIZABETH 81      83      70
	DAVID     65      71      58
	JENNIFER  88      83      81

Being switched by the switch function in the following expressions, labels are outputted on the first row (the loop counter #LOOP=0) and then calculation results (the sum and average values among 2nd to 4th columns) are outputted on the other rows.

(Expressions)
%external "~/tmp/Grades.txt" 0
!
calculate statistics data for each column
%statout avg max min n dev
%format s d
x=fread(0)@
z=sum(fread(k),k=1:3)@
y={fread(1),fread(2),fread(3),
switch(#LOOP=0,fread(4):z),
switch(#LOOP=0,fread(5):z/3)}

The results are as follows.

(Results)
	Name      Math English Science Total Average
	JAMES       78      81      58   217      72
	MARY        68      83      63   214      71
	JOHN        72      77      71   220      73
	PATRICIA    91      68      69   228      76
	ROBERT      77      71      88   236      79
	LINDA       88      82      59   229      76
	MICHAEL     90      72      74   236      79
	BARBARA     69      71      58   198      66
	WILLIAM     78      79      63   220      73
	ELIZABETH   81      83      70   234      78
	DAVID       65      71      58   194      65
	JENNIFER    88      83      81   252      84
	--------- ---- ------- ------- ----- -------
	N           12      12      12    12      12
	AVG         79      77      68   223      74
	DEV          9       6      10    16       5
	MAX         91      83      88   252      84
	MIN         65      68      58   194      65


6. CalcEngine version history

CalcEngine is the expression analysis library used in CalcLoop, CalcLoop Plus and ByeGraph.

Version Corresponding version
to CalcLoop/ByeGraph
Additional functions
CE1.0
(2006/05/06)
CL1.0, BG1.0
CE2.0
(2007/07/26)
CL1.5, BG1.2, BG1.3, BG1.4, BG1.5 - dread function
- sum function
- switch function
- Expression headers
  + %data
  + %format (d/f/e/y) (BG, from ver.1.3)
  + %symbol (Only for BG)
  + %yscale (Only for BG)
CE2.1
(2008/12/15)
CL1.6, BG1.6 - Global variable initializer ginit
- fread2 function
- #LOOP counter, #PARAM counter
- #FREADMAX constant
- %format (s) header (CL, from ver.1.8)
- %xstrings header (Only for BG)
CE2.2
(2009/05/15)
BG1.7 - %external header (CL, from ver.1.8)
- Reading strings
CE2.3
(2009/06/30)
CL1.8 - %gout header (Only for CL)
- %statout header (Only for CL)
CE2.4
(2009/10/31)
BG1.8 - %label header (Improved)
CE2.4.1
(2010/04/10)
BG1.9 - %rangeLin/log, %axislabel headers