Difference between revisions of "Primitive Operators and Properties"

From Nova Documentation
Jump to: navigation, search
(Input/Output Primops)
(Mathematical Primops)
Line 63: Line 63:
  
 
;BINOMIAL(n, p)
 
;BINOMIAL(n, p)
:n is an integer; 0 ≤ p ≤ 1
+
:''n'' is an integer; ''0 ≤ p ≤ 1''
:Returns: a random number from the binomial distribution with n trials and success probability p.
+
:'''Returns''': a random number from the binomial distribution with ''n'' trials and success probability ''p''.
  
 
;COS(x)
 
;COS(x)
:Returns: the trigonometric cosine of x.
+
:'''Returns''': the trigonometric cosine of ''x''.
  
 
;COSWAVE(x, y)
 
;COSWAVE(x, y)
:Returns: x*cos(2π t/y), where t is the current time.
+
:'''Returns''': ''x*cos(2πt/y),'' where ''t'' is the current time.
  
 
;DERIVN(fn, n)
 
;DERIVN(fn, n)
:Returns: the value of the nth derivative of fn at the current time, with precision based on the value of dt.
+
:'''Returns''': the value of the ''nth'' derivative of ''fn'' at the current time, with precision based on the value of ''dt''.
  
 
;DISTANCE(x0, y0, x1, y1)
 
;DISTANCE(x0, y0, x1, y1)
:Returns: Euclidean distance between points (x0, y0) and (x1, y1).
+
:'''Returns''': Euclidean distance between points (''x0, y0'') and (''x1, y1'').
  
 
;Math.XXX
 
;Math.XXX
Line 82: Line 82:
  
 
;NORMAL(x, y)
 
;NORMAL(x, y)
:Returns: a random number from the normal distribution with mean x and standard deviation y.
+
:'''Returns''': a random number from the normal distribution with mean x and standard deviation y.
  
 
;POISSON(lambda)
 
;POISSON(lambda)
Returns: a random number from the Poisson distribution with density lambda.
+
:'''Returns''': a random number from the Poisson distribution with density lambda.
  
 
;RANDOM()
 
;RANDOM()
:Returns: a uniformly distributed random number between 0 and 1.
+
:'''Returns''': a uniformly distributed random number between 0 and 1.
  
 
;SEED(x)
 
;SEED(x)
:Returns: nothing; sets the seed of the random number generator. Should be part of simulation initialization.
+
:'''Returns''': nothing; sets the seed of the random number generator. Should be part of simulation initialization.
  
 
;SIN(x)
 
;SIN(x)
:Returns: the trigonometric sin of x.
+
:'''Returns''': the trigonometric sin of ''x''.
  
 
;SINWAVE(x, y)
 
;SINWAVE(x, y)
:Returns: x*sin(2π t/y), where t is the current time.
+
:'''Returns''': ''x*sin(2πt/y)'', where ''t'' is the current time.
  
 
;UNIFORM(x, y)
 
;UNIFORM(x, y)
:Returns: a uniformly distributed random variable between x and y.
+
:'''Returns''': a uniformly distributed random variable between ''x'' and ''y''.

Revision as of 19:48, 12 December 2014

The Properties/Primops list is correct as of Release 12, which became available on March 31, 2014
Primops added subsequently are identified by the version number in which they first appeared.

Nova supports a large set of primitives divided into properties and primitive operators, or primops.

A property is an identifier assigned a value at the beginning of a simulation run which is not expected to change. For example, the rows and cols properties of a CellMatrix are fixed at the start of a run and don’t change. A special type of property, called an state object, is used to look up the current values of components.

Primops are functions of zero or more arguments. Some primitives may be used without restriction; others make sense only in specific contexts; for example rows and cols are only useful in spatial contexts such as CellMatrices, AgentVectors and SimWorlds.

Here are the properties and primops supported by the current Nova implementation, organized by type and area of applicability. All properties begin with a lower case letter, state objects begin with a capital letter, and primops are composed entirely of capital letters. Primops are always functions, and therefore require an argument list (even if empty) in order to be invoked.

Notation: x, y represent values (numbers or string constants or expressions); fn represents a Javascript function; exp represents a string expression; [x, y] represents one or more optional arguments.

Universal Properties and Primops

These can be used in any expression in any component.

Properties

Self
The state object of the enclosing simulator (Capsule, CellMatrix, etc.) Used to look up component values (see the section on state objects, coming soon).

Control Primops

ALERT(s)
Displays message s in a dialog box.
COUNT(fn, l)
fn is a boolean function of one argument and a l is list.
Returns: COUNT(f, l) applies f to each element of l and returns the number of times the result is true.
DELAY(comp, x, [y])
Returns: the value of component comp delayed by x time units. Comp is a string naming a stateful component (i.e., stock, variable or sequence).
Optional y is returned if the current time is less than x. If y is omitted then 0 is returned.
PULSE(amount, start, interval)
Returns: amount when current time is start, start + interval, start + 2*interval, etc.; 0 otherwise
STEP(x, y)
Returns: the value of x if the current time is y or greater; 0 otherwise.
TOTAL(fn, l)
fn is a numerical function of one argument and a l is list.
Returns: TOTAL(fn, l) applies fn to each element of l and returns the sum of the results.

Convenience Primops

These primops perform useful functions that could otherwise be programmed.

FLIP(p)
Simulates a Bernoulli trial.
Returns: true with probability p and false with probability 1-p.
Available as of release 12.1.

Input/Output Primops

BASEDIR()
Returns: the current model directory.
LOAD(l)
l is a list of JavaScript or NovaScript filenames contained in the current model directory. Each is loaded into the runtime system. Should be part of simulation initialization.

In each of the following path designates a textfile. if path begins with “/” it is treated as an absolute pathname; otherwise it is treated as relative to the current model directory.

OPENREAD(path)
Opens path for reading and returns a Java BufferedReader object. The latter contains methods read and readLine to perform input. See http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html for complete details.
OPENWRITE(path)
Opens path for writing and returns a Java PrintWriter object. The latter contains methods print and println to perform output. See http://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html for complete details.
READFILE(path)
Returns: the content of the file path as a string.

Mathematical Primops

BINOMIAL(n, p)
n is an integer; 0 ≤ p ≤ 1
Returns: a random number from the binomial distribution with n trials and success probability p.
COS(x)
Returns: the trigonometric cosine of x.
COSWAVE(x, y)
Returns: x*cos(2πt/y), where t is the current time.
DERIVN(fn, n)
Returns: the value of the nth derivative of fn at the current time, with precision based on the value of dt.
DISTANCE(x0, y0, x1, y1)
Returns: Euclidean distance between points (x0, y0) and (x1, y1).
Math.XXX
The JavaScript Math functions and constants; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math.
NORMAL(x, y)
Returns: a random number from the normal distribution with mean x and standard deviation y.
POISSON(lambda)
Returns: a random number from the Poisson distribution with density lambda.
RANDOM()
Returns: a uniformly distributed random number between 0 and 1.
SEED(x)
Returns: nothing; sets the seed of the random number generator. Should be part of simulation initialization.
SIN(x)
Returns: the trigonometric sin of x.
SINWAVE(x, y)
Returns: x*sin(2πt/y), where t is the current time.
UNIFORM(x, y)
Returns: a uniformly distributed random variable between x and y.