|
DATA (and Frontier) datatypes, functions and formulas
Sections:
Data Types
Linear Regression
Logical operators
List functions
Mathematical functions
Mathematical operators
Scientific
Statistical
String operations
HTML Form Commands
Data Types
Explanation of the data type for numbers:
NUMBER, NUMBER() or NUMBER(FIELD) is the
integer data type. It's range is from -2 billion to + 2 billion.
DOUBLE() is the floating point data type. It's range is about 19
digits and ranges from 10 raised to the -77 to 10 raised to the
+77. Cannot use exponential notation! BOOLEAN data has the value
of true or false. Logical expressions can be constructed from the
logical operators AND (&&), OR (||) and NOT (!). LISTS are
ordered collections of items. Lists are delimited by curley braces
with items separated by commas.
DOUBLE, DOUBLE() or DOUBLE(FIELD) is the
floating point data type. It's range is about 19 digits and ranges
from 10 raised to the -77 to 10 raised to the +77. Numbers less
than one must have a leading 0 before the decimal point. Do NOT
compare two doubles for equality; instead, take the absolute value
of their difference and compare to see if the difference is less
than some small value (such as 0.000001). Cannot use exponential
notation (see scientific functions below)! DOUBLE("") gives an
error.
BOOLEAN or BOOLEAN(field) data has the value of
true or false. Logical expressions can be constructed from the
logical operators AND (&&), OR (||) and NOT (!).
STRING or STRINGS are characters surrounded by
double quotes. "FIELD01", "alpha", "CS 115", "my mother the car"
are three strings.
Lists or LISTS are ordered collections of items,
i.e. {field1, field2, field3}. Lists are delimited by curley
braces with items separated by commas. For example, {1,3,5,7} is a
list of four integers. {"alpha", "beta", "gamma"} is a list of
three strings. Multiple HTML form fields with the same name return
lists of strings.
isNumb(field) verifies the integer data type. It's range
is from -2 billion to + 2 billion. returns "true" if the number is
a correctly formatted integer value. isNumb("abc") returns
"false". isNumb("12") returns "true". isNumb(" 12") returns
"false" (because of the blank before the number). Use in
conjuntion with number() to avoid an error which would expose the
formula to the students (otherwise, it will return an error if
they type in text or a badly formulated number): isNumb(field05)
AND number(field05) == 1492
isDoub(field) verifies the floating point data type.
It's range is about 19 digits and ranges from 10 raised to the -77
to 10 raised to the +77. Numbers less than one must have a leading
0 before the decimal point. returns "true" if the number is a
correctly formatted double value. isDoub("abc") returns "false".
isDoub("1.2") returns "true". isDoub(" 1.2") returns "false"
(because of the blank before the number). Use in conjuntion with
double() to avoid an error which would expose the formula to the
students (otherwise, it will return an error if they type in text
or a badly formulated number): isDoub(field05) AND double(field05)
< 6.7
Linear Regression
regression.regress(indList, depList)
Performs a linear regression on two lists of data x[i] and y[i] to yield the coefficients in a linear relation y = b0 + b1 * x. The argument indlist is the list {x1, x2,..., xN }, while depList is { y1, y2, ..., yN }. It is an error if the two lists do not contain the same number of items.
Besides the intercept b0 and the slope b1, the function computes the standard error s of the computed y values and the correlation coefficient r. The results are returned as the list{ b0, b1, s, r }.
regression.regressOnN(numList) Performs a linear regression of numlist against the list of integers { 1, 2, ..., N } where N is the number of items in the list. Thus the function fits the items of numList to the relation y = b0 + b1 * i, where i is the index into the list.
Logical operators
These commands calculate logical functions. They are used
to return values of true or false. If the result of an expression
is true or false in the lab formulas, a phrase is substituted for
the appropriate result.
== Do NOT use a single equals sign. It means assignment.
Example: x = 5 does NOT compare x to 5. It changes the value of x
to 5. Use two equal signs, which returns a boolean value. Example:
x == 5 is true if x is a 5. "ABC" == "abc" is false.
!= Not equals Can use "notequals". Example: x != 5 is
true if x is not a 5. "ABC" != "abc" is true.
< Less than. Can use "lessthan" Examples: 2 < 5 is
true; "ABC" < "B" is true.
<= Less than or equal to. Examples: 5 <= 5 is
true; "ABC" <= "B" is true.
> Greater than. Can use "greaterthan" Examples: 7
> 5 is true; "XBC" > "B" is true.
>= Greater than or equal to. Examples: 5 >= 5 is
true; "ABC" >= "B" is false.
&& or () && () Logically combines
two expressions. If both expressions are true, the combined result
is true. Otherwise, it's false.
|| or () || () Logically combines two
expressions. If either expression is true, the combined result is
true. If both are false, the combined result is false.
! or ! () Logically complements a logical
expression. If the expression is true, the result is false. If the
expression is false, the result is true.
AND or (expression) AND (expression) Logically
combines two expressions. If both expressions are true, the
combined result is true. Otherwise, it's false.
OR or (expression) OR (expression) Logically
combines two expressions. If either expression is true, the
combined result is true. If both are false, the combined result is
false.
NOT or NOT (expression) Logically complements a logical
expression. If the expression is true, the result is false. If the
expression is false, the result is true.
1 <= x <= 10 or (1 <= x) AND (x <=
10) Comparison is true if x is in the range 1 through 10
inclusive. x < 5 OR x > 20 (x < 5) OR (x > 20)
Comparison is true if x is outside the range 5 through 20
inclusive.
beginsWith String comparison. Example: "ABC" beginsWith
"AB" is true.
contains String containment. Example: "ABC" contains "B"
is true.
endsWith String comparison. Example: "ABC" endsWith "BC"
is true.
List functions
These commands calculate functions on lists.
LISTS are ordered collections of items. Lists are
delimited by curley braces with items separated by commas. For
example, {1,3,5,7} is a list of four integers. {"alpha", "beta",
"gamma"} is a list of three strings.
listOps.dotProduct(list1, list2)
Returns the sum of products of the corresponding elements of list1 and list2.
listOps.fillList(x, n)
Creates a list of length n. Each element is the value of x.
listOps.invertList(theList)
Returns the list of reciprocals of the elements of theList. So if theList is {1, 2, 3}, the function returns {1.0, 0.5, 0.33333333}.
listOps.line (a, b, xList)
Taking a as the slope and b as the intercept, this function returns a list of y-values corresponding to the list of x-values passed in the list xList. The y -values are calculated according to the formula y = a * x + b.
listOps.listToPower(theList, x)
Returns a list consisting of the elements of theList raised to the power x. The exponent x does not need to be an integer.
listOps.max(numList)
Returns the maximum of the list numList as a double.
listOps.min(numList)
Returns the minimum of the list numList as a double.
listOps.ordList(N)
Returns the list {1, 2, 3, ... , N}.
listOps.scalarAdd(theList, x)
Adds x to each of the elements of theList and returns the result.
listOps.scalarMultiply (theList, x)
Multiplies each of the elements of theList by x and returns the result.
listOps.sumList (theList)
Returns the sum of the elements of theList .
listOps.vectorDiff (list1, list2)
Subtracts the elements of list2 from the corresponding elements list1 and returns the resulting list. vectorDiff({3, 4, 7.5, 6}, {1, 2, 3, 4}) == {2.0, 2.0, 4.5, 2.0}
listOps.vectorProd (list1, list2)
Multiplies the elements of list1 by the corresponding elements list2 and returns the resulting list.
listOps.vectorRatio (list1, list2)
Divides the elements of list1 by the corresponding elements list2 and returns the resulting list.
listOps.vectorSum (list1, list2)
Adds the elements of list2 to the corresponding elements list1 and returns the resulting list.
Mathematical functions
Functions that operate on numbers.
abs or abs(field) Absolute value of a number.
Example: abs (-3.20) == 3.2
asin or asin(field) Mathematical arcsine of a
number. The arcsine of x is the angle (angle must be in radians,
which means take the number times pi/180 [2.14159/180])
whose sine is x. Example: asin (sin (0.25)) == 0.25
acos or acos(field) Mathematical arccosine of a
number. The arccosine of x is the angle (angle must be in radians,
which means take the number times pi/180 [2.14159/180])
whose cosine is x. Example: acos (cos (0.25)) == 0.25
atan or atan(field) Mathematical arctangent of a
number. The arctangent of x is the angle (angle must be in
radians, which means take the number times pi/180
[3.14159/180]) whose tangent is x. Example: atan (tan
(0.25)) == 0.25
ceil or ceil(field) The floor function removes
the fractional part of a number by rounding up. Examples: ceil
(2.7) == 3.0, ceil (-5.4) == -5.0
cos or cos(field) Mathematical cosine of an angle
(angle must be in radians, which means take the number times
pi/180 [2.14159/180]). Example: cos (180*2.14159/180) ==
-1.0
cosh or cosh(field) Mathematical hyperbolic
cosine of a number. Examples: cosh (1) == 1.54308063, cosh (25) ==
36002449668.69293625
exp or exp(field) The exponential function raises
2.71 to a power. Example: exp (2.09) == 8.08491516
floor or floor(field) The floor function removes
the fractional part of a number by rounding down. Examples: floor
(2.7) == 2.0, floor (-5.4) == -6.0
log10 or log10(field) Logarithm base 10 of a
number. Examples: log10 (3.0) == 0.47712125, log10 (100.0) ==
2.0
sin or sin(field) Mathematical sine of an angle
(angle must be in radians, which means take the number times
pi/180 [2.14159/180]). Example: sin (13.5) ==
0.80378443
sinh or sinh(field) Mathematical hyperbolic sine
of a number. Example: sinh (3.0) == 10.01787493
sqrt or sqrt(field) The square root function
returns the square root of a number. The square root of a negative
number is an error. Examples: sqrt (2) == 1.41421356, sqrt (4) ==
2.0
tan or tan(field) Mathematical tangent of an
angle (angle must be in radians, which means take the number times
pi/180 [2.14159/180]). Example: tan (90*2.14159/180) ==
1.0
tanh or tanh(field) Mathematical hyperbolic
tangent of a number. Example: tanh (1) == 0.76159416
Mathematical operators
Operators that operate on numbers (+, -, *, /, %),
strings (+, -) and lists (+, -).
+ Plus sign with numbers is addition. Plus sign with
strings is concatenation. Plus sign with lists is concatenation.
Examples: 5 + 4 == 9; "Joh" + "n" == "John"; {1,3,5} + {2,4} ==
{1,3,5,2,4}
- Minus sign with numbers is subtraction. Minus sign
with strings is substring removal. Minus sign with lists is
sublist removal. Examples: 5 - 4 == 1; "John" - "h" == "Jon";
{1,3,5,2,4} - {5,2} == {1,3,4}
* Asterisk with numbers is multiplication. Example: 5 *
4 == 20;
/ Slash with numbers is division. Example: 5 / 4 ==
1.25;
% Percent sign with numbers is modulus. Modulus is the
remainder after dividing the left number by the right number. Can
also use mod(5,4). Examples: 5 % 4 == 1; 30 % 3 == 0; Any number
mod n always returns a positive value from 0 through n-1.
mod or mod(left,right) mod with numbers is
modulus. Modulus is the remainder after dividing the left number
by the right number. Can also use 5 % 4. Examples: mod(5,4) == 1;
mod(30,3) == 0; Any number mod n always returns a positive value
from 0 through n-1.
== Do NOT use a single equals sign. It means assignment.
Example: x = 5 does NOT compare x to 5. It changes the value of x
to 5. Use two equal signs, which returns a boolean value. Example:
x == 5 is true if x is a 5.
Scientific
Functions that work with scientific numbers.
power or power(base, exponent) Computes base
raised to exponent (base ** exponent in Fortran syntax). If base
is a positive value, exponent may be any double. Attempting to
take a non-integer power of a negative base is a script error.
power(2, 2) == 4.0; power(2, -2) == 0.25; power(2, 127) ==
170141183460469231731687303715884106000.0; power(37.555, 6.5) ==
17192557323.99222946; The following calls produce script errors:
power(-1, 0.25);
round or round (field) Produces true rounding of
the double num. The result is an integer, but itis returned as a
double. Thus round (-4.6) returns -5.0. round(67.543) == 68.0;
round(-4.65) == -5.0;
roundToPlaces or roundToPlaces (num, places)
Rounds num to the number of decimal places specified by places.
Thus, roundToPlaces (32.567823, 3) returns 32.568
conversion.sciNumber or sciNumber(str) Converts a string
representation of a number in scientific notation to a double.
Thus sciNumber("-2.34 E-3) gives -0.00234 as the result.
sciNumber("-2.34 E-3") == -0.00234; The following calls produce
script errors: sciNumber("");
conversion.sciString or conversion.sciString(num, places) Converts num
to a string representation in scientific notation with the
specified number of decimal places. Thus sciString(1325.642, 5)
gives "1.32564 E3" ; sciString(power(2, 127), 6) == "1.701412
E38"; sciString(1325.642, 5) == "1.32564 E3";
sign or sign(num) Returns -1 for negative numbers
and +1 for positive values. If num is 0,the value returned by sign
is 0. sign(-5.678392) == -1; sign(5.678392) == 1; sign(0) ==
0;
trunc or trunc(field) Truncates a number to an
integer value, although the integer is returned as a double rather
than a long. Thus, trunc(67.543) yields 67.0, while trunc(-4.65)
gives -4.0. trunc(67.543) == 67.0; trunc(-4.65) == -4.0;
Statistical
These commands calculate statistical functions.
statistics.mean(numList)
Returns the average of a list of numbers.
statistics.stdDeviation(numList)
Returns the sample standard deviation around the mean for a list of numbers. This function computes the sample standard deviation, that is, the squared deviations are averaged with N - 1, where N is the number of items in the number list.
statistics.popSD(numList)
Returns the population standard deviation with respect to the mean, that is, the squared deviations are averaged with N rather than N - 1, where N is the number of items in the number list.
The following functions are used by the linear regression scripts.
statistics.nthMoment(numList)
Computes the nth moment of the list items relative to the origin.
statistics.wgtdMean(weightList, numList)
Computes the weighted mean of the items of numList. The weights are the items of weightList. It is an error if weightList and numList contain different numbers of items.
Note: this function is not a true weighted mean, since we normalize with the number of items in numList rather than the sum of the weights. The function might better be described as a cross-correlation between the two lists that serve as the argument. We needed the function for the linear regression scripts, but it was hard to think of a suitable name - "wgtdMean" is a name that approximately describes the calculation of the result.
String operations
These commands are used to manipulate strings. Strings
are returned from HTML forms.
countFields or countFields (string,
delimiterChar) Returns the number of fields in "string" when
the delimiter character is "delimiterChar". Can be used to count
the number of words in a string: countFields("Four score and
seven", " ") == 4; countFields("a;b;c", ";") == 3;
countWords or countWords (string) Returns the
number of words in "string". countWords("Four score and seven", "
") == 4;
firstWord or firstWord (string) Returns the first
word in "string".
lastWord or lastWord (string) Returns the last
word in "string".
lower or lower (string) Returns the "string" with
all alphabetic characters converted to lowercase.
mid or mid (string, startIndex, count) Returns a
string consisting of "count" characters of "string" starting at
index "startIndex". It is not an error for count to be too large;
all of the string starting at startIndex is returned. It is not an
error for startIndex to be too large; zero is returned. Examples:
mid ("ABCDEFG", 3, infinity) == "CDEFG"; mid ("ABCDEFG", 3, 2) ==
"CD"; mid ("ABCDEFG", 3, 0) == ""; mid ("ABCDEFG", 30, 0) ==
"";
nthChar or nthChar (string, index) Returns the
character at "index" of "string". Examples: nthChar ("ABCDEFG", 3)
== 'C'; nthChar ("ABCDEFG", 22) == ''; nthChar ("ABCDEFG", 0) ==
"";
nthField or nthField (string, delimiterChar,
index) Returns the field at position "index" in "string" when
the delimiter character is "delimiterChar". Examples: nthField
("AB CDE FG", " ", 3) == 'FG'; nthField ("AB CDE FG", " ", 22) ==
''; nthField ("AB CDE FG", " ", 0) == "";
nthWord or nthWord (string) Returns the word at
position "index" in "string". Examples: nthWord ("AB CDE FG", " ",
3) == 'FG'; nthWord ("AB CDE FG", " ", 22) == ""; nthWord ("AB CDE
FG", " ", 0) == "";
sizeOf or sizeOf (string) Returns the number of
characters in "string". Examples: sizeOf ("ABXCDEYFG") == 9;
sizeOf ("") == 0;
upper or upper (string) Returns the "string" with
all alphabetic characters converted to uppercase.
HTML Form Commands
These commands are used to insert common HTML form
elements into a document. These are tags which are between
<>.
FORM or FORM method=POST
action="/NetForms.acgi$/doc.FDML" Inserts the required form
command and action parameter for NetForms into your form. If your
Web server is configured with an action so that the suffix ".fdml"
is automatically sent to NetForms the "/NetForms.acgi$" is not
necessary.
INPUT text or INPUT TYPE="text" NAME="name" SIZE="30"
MAXLENGTH="30" VALUE="" Inserts a single-line text entry box
into your form. SIZE is the length of the box that will be
displayed; MAXLENGTH is the maximum number of characters that can
be entered.
INPUT hidden or INPUT TYPE="hidden" NAME="name"
VALUE="" Inserts a hidden field into your form. Hidden fields
are submitted as part of the form, but the field and the
information in it are not displayed by the browser.
INPUT checkbox or INPUT TYPE="checkbox" NAME="name"
CHECKED VALUE="box1" Inserts a checkbox field into your form.
If the CHECKED parameter is specified, the box will be checked by
default.
INPUT radio or INPUT TYPE="radio" NAME="name" CHECKED
VALUE="button1" Inserts a radio button into your form. To link
several radio buttons, assign the same NAME but different VALUEs.
If the CHECKED parameter is specified, that button will be
selected by default.
INPUT password or INPUT TYPE="password"
NAME="name" Inserts a password entry box into your form.
Password boxes are identical to Text input boxes but the typing in
the box will be obscured.
TEXTAREA or TEXTAREA NAME="name" ROWS=5 COLS=40
Inserts a textarea entry box into your form. The ROWS and COLS
parameters set the size of the text area in rows and columns. The
WRAP parameter allows you to specify automatic text wrapping; a
value of "hard" or "physical" will automatically insert return
characters when the end of a line is reached; a value of "soft"
will wrap text at the end of the line without inserting return
characters; a value of "none" will not wrap text automatically. A
default value for the text area may be specified by placing the
default text in between the tags.
SUBMIT or INPUT type="submit" value="Submit"
Inserts a submit button into your form.
RESET or INPUT type="reset" value="Reset" Inserts
a reset button into your form.
|