-
Notifications
You must be signed in to change notification settings - Fork 3
VeLa
VeLa (VStar expression Language) is a general purpose programming language that, within VStar, can be used to:
- specify a numeric expression wherever a number can be used as input;
- create complex observation filter and search expressions;
- specify model functions;
- transform observations.
VeLa is a simple functional language with:
- integer, real, string, boolean, list, function types
- variables that take on the type of the value to which they are first bound via the
<-
binding (assignment) operator (e.g.n <- 1
) - named constants via the is operator (e.g.
π is 3.1415926
) - case insensitive, Unicode keyword, variable, and function names
- statically typed, recursive, higher order, named or anonymous functions that may be overloaded by parameter type
- selection (
when
) and iteration (while
) - numeric operators: + - * / ^
- string operators: +
in
- logical operators: not, and, or
- relational operators: = <> > < >= <= =~
- list operators:
in
- regular expressions (Java syntax) for use with =~ (approximately equal) operator
- intrinsic functions (see below)
VeLa can also be viewed as a domain specific language that tightly integrates with VStar. Many other languages are either too verbose (e.g. Java) or too weakly typed (e.g. JavaScript) for the intended purpose or for the developer's taste.
Here is the VeLa grammar (PDF).
Any text entry box in VStar that accepts a numeric value can instead receive a numeric VeLa expression.
Expressions such as 2457529.5-365.25*5
or today()-365.25*5
could be used as the minimum JD when loading a dataset from AID.
Note that localised real numbers can be used in VeLa, so that if the decimal point in the current locale is a comma, this can be used instead of .
, e.g. 4,2
vs 4.2
.
(obscode in ["CTIA" "SAH"] and band = "Johnson V" and uncertainty <= 0.01)
OR
(band = "Visual" and obscode = "BDJB")
This Boolean expression defines an observation filter in which:
- the observer code is CTIA or SAH and the band is Johnson V and the uncertainty is less than or equal to 0.01 or
- the band is Visual and the observer code is BDJB (the lead VStar developer)
Load eta Aquilae with a JD range of 2457529.5-365.25*5
to 2458259.5
and try this filter via VeLa Filter...
in the View
menu.
A VeLa observation filter has access to the properties of the currently loaded observations, such as time/JD, magnitude, observer code, band, and any properties peculiar to a particular observation source.
These expressions may also be used in the Observation List to restrict the set of observations, create selection filters, and exclude observations.
In addition, observation source dialogs allow a VeLa expression to be used to filter observations as they are loaded, rather than afterwards.
Applying DCDFT with Period Range to the eta Aql filtered observations above with a period range of 1 to 10 and a resolution of 0.01 will yield a period search top hit of 7.18.
This function defines a Fourier model obtained from a fundamental frequency of ~0.1393 (a period of 7.18) and two harmonics:
f(t:real) : real {
3.8893863
+0.1148971 * cos(2*PI*0.1392758*(t-2457506))-0.312022 * sin(2*PI*0.1392758*(t-2457506))
+0.0432131 * cos(2*PI*0.2785515*(t-2457506))-0.1196311 * sin(2*PI*0.2785515*(t-2457506))
+0.0370884 * cos(2*PI*0.4178273*(t-2457506))-0.0013007 * sin(2*PI*0.4178273*(t-2457506))
}
The VeLa observation transformation plugin requires a function to be defined to determine what transformation to apply to each observation.
Here is an example of how to use the scatter
API function with VeLa:
# This is a comment.
# y <- x^3
x is seq(1.0 1000.0 1.0)
y is map(function(n:real):real{n^3} x)
scatter("Cubes" "x" "x^3" x y)
After entering this code and clicking Run in the Tools
-> VeLa
... dialog, you will see a new Cubes tab with a plot of the cubes of x from 1 to 1000.
VeLa code can be entered into a dialog (Tools -> VeLa
) to test it before use in one of the contexts outlined above, e.g.
fact(n : integer) : integer {
when n = 0 -> 1
true -> n*fact(n-1)
}
map(fact [1 2 3 4 5 6 7 8 9 10])
π
pi
e
A range of in-built functions are available in VeLa and categorised below.
EVAL (STRING) : LIST
CHR (INTEGER) : STRING
FORMAT (STRING LIST) : STRING
ORD (STRING) : INTEGER
TODAY () : REAL
PRINT(...)
PRINTLN(...)
NEXTCHAR () : STRING
APPEND (LIST ANY) : LIST
CONCAT (LIST LIST) : LIST
FILTER (FUNCTION LIST) : LIST
FOR (FUNCTION LIST) : ANY
HEAD (LIST) : ANY
LENGTH (LIST) : INTEGER
MAP (FUNCTION LIST) : LIST
NTH (LIST INTEGER) : ANY
REDUCE (FUNCTION LIST ANY) : ANY
TAIL (LIST) : LIST
ABS (INTEGER) : INTEGER
ABS (REAL) : REAL
SIN (REAL) : REAL
COS (REAL) : REAL
TAN (REAL) : REAL
ATAN2 (REAL REAL) : REAL
SQRT (REAL) : REAL
LOG (REAL) : REAL
LOG10 (REAL) : REAL
POW (REAL REAL) : REAL
EXP (REAL) : REAL
MIN (REAL REAL) : REAL
MIN (INTEGER INTEGER) : INTEGER
MAX (REAL REAL) : REAL
MAX (INTEGER INTEGER) : INTEGER
ADDEXACT (INTEGER INTEGER) : INTEGER
DECREMENTEXACT (INTEGER) : INTEGER
INCREMENTEXACT (INTEGER) : INTEGER
MULTIPLYEXACT (INTEGER INTEGER) : INTEGER
NEGATEEXACT (INTEGER) : INTEGER
SUBTRACTEXACT (INTEGER INTEGER) : INTEGER
SCALB (REAL INTEGER) : REAL
COPYSIGN (REAL REAL) : REAL
GETEXPONENT (REAL) : INTEGER
SIGNUM (REAL) : REAL
ASIN (REAL) : REAL
ACOS (REAL) : REAL
ATAN (REAL) : REAL
TORADIANS (REAL) : REAL
TODEGREES (REAL) : REAL
CBRT (REAL) : REAL
IEEEREMAINDER (REAL REAL) : REAL
CEIL (REAL) : REAL
FLOOR (REAL) : REAL
RINT (REAL) : REAL
FLOORDIV (INTEGER INTEGER) : INTEGER
FLOORMOD (INTEGER INTEGER) : INTEGER
ULP (REAL) : REAL
SINH (REAL) : REAL
COSH (REAL) : REAL
TANH (REAL) : REAL
HYPOT (REAL REAL) : REAL
EXPM1 (REAL) : REAL
LOG1P (REAL) : REAL
NEXTAFTER (REAL REAL) : REAL
NEXTUP (REAL) : REAL
NEXTDOWN (REAL) : REAL
POWEROFTWOD (INTEGER) : REAL
COMPARETO (STRING STRING) : INTEGER
INDEXOF (STRING STRING INTEGER) : INTEGER
INDEXOF (INTEGER INTEGER STRING INTEGER) : INTEGER
INDEXOF (INTEGER INTEGER INTEGER INTEGER INTEGER) : INTEGER
INDEXOF (STRING INTEGER) : INTEGER
INDEXOF (STRING STRING) : INTEGER
INDEXOF (STRING INTEGER INTEGER) : INTEGER
VALUEOF (BOOLEAN) : STRING
VALUEOF (INTEGER INTEGER) : STRING
VALUEOF (REAL) : STRING
VALUEOF (INTEGER) : STRING
CODEPOINTAT (STRING INTEGER) : INTEGER
CODEPOINTBEFORE (STRING INTEGER) : INTEGER
CODEPOINTCOUNT (STRING INTEGER INTEGER) : INTEGER
OFFSETBYCODEPOINTS (STRING INTEGER INTEGER) : INTEGER
CONTENTEQUALS (STRING STRING) : BOOLEAN
EQUALSIGNORECASE (STRING STRING) : BOOLEAN
COMPARETOIGNORECASE (STRING STRING) : INTEGER
REGIONMATCHES (STRING INTEGER STRING INTEGER INTEGER) : BOOLEAN
REGIONMATCHES (STRING BOOLEAN INTEGER STRING INTEGER INTEGER) : BOOLEAN
STARTSWITH (STRING STRING) : BOOLEAN
STARTSWITH (STRING STRING INTEGER) : BOOLEAN
ENDSWITH (STRING STRING) : BOOLEAN
INDEXOFSUPPLEMENTARY (STRING INTEGER INTEGER) : INTEGER
LASTINDEXOF (STRING INTEGER INTEGER) : INTEGER
LASTINDEXOF (INTEGER INTEGER INTEGER INTEGER INTEGER) : INTEGER
LASTINDEXOF (INTEGER INTEGER STRING INTEGER) : INTEGER
LASTINDEXOF (STRING STRING INTEGER) : INTEGER
LASTINDEXOF (STRING INTEGER) : INTEGER
LASTINDEXOF (STRING STRING) : INTEGER
LASTINDEXOFSUPPLEMENTARY (STRING INTEGER INTEGER) : INTEGER
SUBSTRING (STRING INTEGER) : STRING
SUBSTRING (STRING INTEGER INTEGER) : STRING
SUBSEQUENCE (STRING INTEGER INTEGER) : STRING
CONCAT (STRING STRING) : STRING
REPLACE (STRING STRING STRING) : STRING
MATCHES (STRING STRING) : BOOLEAN
CONTAINS (STRING STRING) : BOOLEAN
REPLACEFIRST (STRING STRING STRING) : STRING
REPLACEALL (STRING STRING STRING) : STRING
COPYVALUEOF (INTEGER INTEGER) : STRING