list of numbers
From Wiki
This article or section is in the middle of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article has not been edited in several days, please remove this template. This page was last edited by Holy (talk| contribs) ago. (Purge) |
Numbers are a means to add some programmatic functionality to Sword of Moonlight via calculator like mathematical expressions. Numbers are typically setup inside of an Ex.ini file. This list contains built in and so-called system numbers only.
Preface |
---|
Because there is an all-in-one quality to the concept of a number as conceptualized by the programming framework as presented here. It is important to first agree on some specialized terminology. Elements of which may (or may not) appear italicized throughout this page. |
Number |
We should avoid the word "number" at all cost. Since it is just about meaningless. It represents an identifier, or symbol, in programming speak. It is best reserved to describe the final output of a calculation. |
Subscript |
Using Sword of Moonlight's "counters" as an example. There are 1024 of them. They are represented by a single "number", name, identifier, or symbol, take your pick. The value of each of the 1024 counters are represented by a subscript. So when we talk about values, we should prefer the word "subscript" (in other words each number is in actuality a 1D table with any number of "rows" identified by numerical IDs) |
Function |
A "subscript" may be more than a mere number. It may be a numerical expression, or even a mathematical function receiving input parameters, or both. We should take it for granted that a subscript may be an expression. We should use the word "function" to refer to the latter case. |
Set |
In addition to numbers, expressions, and functions, a "subscript" may be a "set". From a programming perspective sets facilitate aliases, pass-by-reference, and packing many values into a single argument: sometimes called arrays, containers, vectors, matrices, trees, relational sets, and so on. |
Sword of Moonlight
Variables
c
pc
npc
Constants
Legend | |
---|---|
SOM_SYS | settings part of SOM_SYS (SOM_SYS.exe) usually kept in the Sys.dat file. |
m/s | the constants units are meters per second. |
c/s | the constants units are radians per second. Note that constants based on figures originally in degrees are converted to radians. |
- _WALK (SOM_SYS; m/s)
- the player character walking speed.
- _DASH (SOM_SYS; m/s)
- the player character dashing speed.
- _TURN (SOM_SYS; c/s)
- the player character turning speed.
Serialization
It is possible to write a series of numbers. Care must be taken to not do so accidentally. The following table demonstrates the rules that must be observed. However the basic rules are pretty simple. If a mathematical operator has a space on one side, then it must have a space on its other side, and vice versa. In other words, 1 + 2 or 1+2. If a positive (+) or negative (-) sign appears in front of a number it must be flush with the number, or -1, not - 1.
input | produces | output |
---|---|---|
1 2 | => | 1, 2 |
2 +3 | => | 2, 3 |
3 + 4 | => | 3+4 |
4 + -5 | => | 4-5 |
input | produces | output |
---|---|---|
5 +-6 | => | 5, -6 |
-6+7 | => | -6+7 |
-7--8 | => | -7+8 |
-8 --9 | => | -8, 9 |
If you experience different results then that is a software bug that should not be relied upon in order to ensure you expressions continue to work correctly in the future.
Tip: where there is no empty space an expression cannot be interpreted as a series. 2(X) is 2*X, (X)(Y) is X*Y, and Y(2)X is X[Y(2)] and 2XY is XY[2]. This all works because plain numbers when written as a function behave as if multiplied. The rest is explained by #subscripts.
Space and separators
Spacing characters include space ( ), tab, carriage-return, new-line, and any other character that produces empty space wherever it appears. Note that tab and other kinds of characters sometimes appear as zero width spaces. This can be a nuisance as they will nonetheless be interpreted as space.
End of the line characters (carriage-return and new-line) are ignored along with any spacing characters that follow. When working with multiple lines care must be taken to observe spacing rules precisely. When a series is spread over multiple lines an explicit separator (#,;) should be placed between the last element on the line and the first element on the next line. A semicolon (;) at the end of the line is recommended for this.
Like with HTML (except for following the end of a line where empty space is ignored) one space, or two spaces, or any number of spacing characters (and or separators) is collapsed into a single space for purposes of serialization.
,;
The colon (,) and semicolon (;) are reserved separators. They are strictly equivalent to a space ( ) character, except you can see them as written. In other words 1 2 or 1,2 or 1;2 it doesn't matter. If necessary more separators can be added or an extension can be provided to allow for the definition of custom separators.
Note that separators are simply filtered out. So if you write 1,+,2 this is equivalent to 1+2. Care should still be taken to observe the rules of serialization and cautions about working with multiple lines in the previous section.
Subscripts and labels
A named number can be written with a subscript. When not so, the subscript is 0. Subscripts must be positive whole numbers. In reality each number is a 1D table of numbers, or numerical values, each distinguished by its subscript. Built in numbers (including functions and operators) almost always make use of only the 0 subscript.
Built in mathematical operators like + (plus) are the same, except with the further limitation that (because of #placeholders) it is not even possible to refer to them with subscripts. That said, were it possible to overwrite them, internally (from within their own assignments) they can refer to their own subscripts. Refer to #_ #_S and #_$.
In other words, the number itself has no value, but rather its subscripts do. The value of a number without an expressed subscript is the value of its first (0) subscript. Without introducing extended Unicode characters a subscript can be written in the following ways:
notation | interpretation |
---|---|
A[0] | 0th subscript of A |
B | 0th subscript of B |
C[1] | 1st subscript of C |
1D | 1st subscript of D |
E[1][1] | 2nd subscript of E |
F[1+1] | 2nd subscript of F |
notation | interpretation |
---|---|
1G[2] | 3rd subscript of G |
H[f(X)] | "f of Xth" subscript of H |
f(X)I | "f of Xth" subscript of I |
f(X)J[+1] | "f of X plus 1th" subscript of J |
K[-1] | Not a Number (not allowed) |
L[0.5] | 0th subscript of L |
[]
Mathematics
With math it is possible to write a number as a mathematical expression with 0 or more input parameters. Refer to #_.
Calculations
A basic expression should appear familiar to everyone who has ever relied on a calculator to make it through a grade school math course. In fact it is never necessary to deviate from standard calculator notation. What follows is a refresher course along with an introduction to some quirkier ways to write expressions that can either be enlightening or treacherous, depending on how you look at it.
Grouping semantics allow expressions to contain subexpressions. Series within a subexpression are interpreted as input parameters. Refer to #() and #||.
An expression is made up of numerical terms held together by mathematical operators. A term can be a single number or a group of numbers. Operators resemble punctuation. For example: 1+2 includes two terms, 1 and 2, and one operator, +, or plus.
This distinction is stressed because each expression is a kind of computer program where each character in the program must be strictly interpreted. There is no tolerance for error, and in 9 out of 10 cases no red flags to be raised in case of error. Intolerance is a feature of all programming languages, and is nonnegotiable. Red flags on the other hand, can be supplied on demand (at the cost of alternative ways to write expressions.)
Numbers directly adjacent to (but not inside of) parentheses become a function of the inner terms of the parentheses, or the function's input parameters. Plain numbers, such as 1 or 1.5, share a built in function; multiplication. Other numbers can only be written with the parentheses on their right. Refer to #() (when written on the left the result is a #subscript; not a function at all.)
While operators technically are functions, they are not usually written as such. However it is possible to do so. For example, 1+(2,3) adds together 1 2 and 3.
Wherever a term should logically appear but is omitted a 0 is provided. For instance. Operators always have a left term and a right term. And groups are not allowed to be empty. Consider -1+2. Which becomes (0-1)+2. Note that it does not become 0-1+2. The distinction can sometimes make a difference. Though less common, the same rule applies on the right: 1- becomes 1-0. Here parentheses are not needed. And last but not least: () becomes 0 (so consider that f() becomes f(0) where f is some mathematical function.)
Likewise terms and operators must always appear together. If an operator is omitted then a + is provided. So (1,2) becomes 0+(1,2) adding together 0 1 and 2 (and 1 becomes 0+1. Rules are rules.)
Arithmetic
Basic arithmetic includes the + - * and / operators used for addition, subtraction, multiplication, and division respectively. The operations are carried out from left to right, except that * and / have a higher what-is-called precedence, and are therefore always carried out first (barring grouping. Refer to #().)
these | equal | this |
---|---|---|
1+2 | = | 3 |
2-3 | = | -1 |
3*4 | = | 12 |
4/5 | = | 0.8 |
these | equal | this |
---|---|---|
1+2*3 | = | 7 |
(1+2)*3 | = | 9 |
3/0 | = | #inf |
0/0 | = | #nan |
When written with input parameters these operators can operate over more than two values. For example, (1,2)+(3,4,5) equals the sum of 1+2+3+4+5. The same is true for * - and / (for example (1,2)*(3,4,5) equals 1*2*3*4*5.)
Tip: note that +(3,4,5) equals 0+3+4+5. This is inconsequential, however *(3,4,5) may produce unexpected results since 0*3*4*5 is 0. As is *3 (on the other hand. Consider *[+1][+2][+3]+<your actual expression with #placeholders here>. Here we have three internal parameters front loaded with nearly unmistakable intent.)
()
||
Enclosing an expression within two vertical bars (|) yields its absolute value. For example, |-7| makes 7. But you must beware that nesting without parentheses (#()) is not supported. Something like |c[|A|]| also works where square brackets are able to be used in place of parentheses.
In other words: |(|A|-|B|)| does work. While ||A|-|B|| does not work. Alternatively consider #abs(|A|-|B|).
abs
Decision trees
?:
if
Logical operations
_E
and
nand
or
nor
xor
xnor
Complex numbers
x
y
iy
Identity coalescence and inequality
nan
inf
not
neg
Reflection and recursion
_
_S
_$
_N
Statistical analysis
n
int
mod
min
max
r
Transcendental functions
^
cos
exp
log
pow
sin
Sets
Sets are a proposed feature. Implementation (and finalization) is to be delayed until thought necessary.
Proposal
A set here is not a set of number values. It is a multiset of named number and subscript pair references referred to as elements below. If a plain number is added to a set it is said to be anonymous. The individual numbers of a set are accessed by ordinal with #el.
Sets and #subscripts are incompatible. In other words, el(A,1)[2] does not work (where el(A[2],1) does—just to be 100% clear—but means something completely different beside the point. Bottom line, subscripts are for numbers. Also note that el(A,1)[2] does not produce an error as [2] is interpreted as a #placeholder.)
Where a set is operated upon like a number it is equivalent to its 0 ordinal element. And if that element is itself a set, the 0 ordinal element of that set. And so on.
Tip: a named set B equal to {A} becomes the functional equivalent of A. Although references to A remain distinct from references to B (consider #no(C,{A}) where C contains references to B but not A. Note that neither does this extend to subscripts. Therefore B[2] is not by extension functionally equivalent to A[2].)
Elements default to a single element set containing #nan. It is explained below that this can be written {nan}. Note that nan is not a value. But yields the value NaN when expressed without input parameters.
{:}
An empty set is written as {}. A two element set is written as {A,B} or {A B}. Here A is assigned ordinal 0, and B is assigned ordinal 1. Ordinals can be skipped by writing {A,2:B}. Here A is again assigned ordinal 0, and B is instead assigned ordinal 2. Ordinals must be positive whole numbers.
If A is itself a set then this must be acknowledged by writing {A} or {{A},B} or else A will be taken as the 0 ordinal element of set A. This does not introduce an intermediary set. Too add an anonymous set write {{A,1,2},B} or {{{A},1,2},B} depending on whether element A is to be a set or number reference.
el
el yields undefined behavior. el(A) yields A as a set, or {A}. el(A,1) yields the ordinal 1 element of the set A as a set. el(A,1,2) yields the ordinal 2 element of the ordinal 1 set of set A.
no
no yields undefined behavior. no(A) yields one more than the greatest ordinal of set A, or 0 if A is the empty set {}, or 1 if A is in fact not a set.
no(A,1) yields the number of elements equal to the number 1 with respect to #_E. no(A,1,2) yields the number of elements between the range of 1 and 2. no(A,1,2,0) yields the number of elements between 1 and 2 with a precision of 0, or 0 is used in place of _E.
no(A,{B}) yields the number of elements of set A that reference B. no(A,{B,C}) is equivalent to no(A,{B})+no(A,{C}).
Tip: no(A)-no(A,nan) yields the number of non-NaN elements in set A. But this looks for the value NaN. Since ordinals default to {nan} you may want to look for no(A,{nan}) instead.