Values
Expressions in Coach consist of a combination of primitive values (also collections of those) and operations between them. Below we will see what those primitive values are and some operations that can be performed on/between them.
Primitive values
Number
A number is either an integer or a fractional number (similar to what you input in a pocket calculator).
Example
12
6.33
3.12e-3 // Same as 0.00312
Operators
Numbers support the following operators
-
Arithmetic operators will always return Number values
Symbol Name Example Result +add 3.4 + 36.4-subtract 3 - 4.44-1.44*multiply 2.2 * 4.59.9/divide 7.84 / 23.92%remainder 44 % 31^power 2^416 -
Comparison operators will always return Boolean values
Symbol Name Example Result ==equals 4 == 4true<less than 2 < 4.333true>greater than 6.55 > 6.55false<=less than or equals 4.00001 <= 4false>=greater than or equals 5.34 >= 5.341false
Measurement
A measurement is a number together with a unit of measurement that should be convertible to the International System of Units.
Units
The unit is any expression between two vertical bars e.g. |m/s|. It contains
any alphabetic characters combined with any of the operators
| Symbol | Name | Example |
|---|---|---|
* |
multiply | kg*m |
/ |
divide | km/h |
^ |
power | kg*m/s^2 |
Different units may measure the same physical property. Coach performs dimensional analysis under the hood, so it knows that different units that measure the same physical property must have the same dimensions. This makes operations between measurements with different units (but with the same dimensions) possible.
The available units that Coach recognises are
| Symbol | Name | Prefix |
|---|---|---|
m |
meter | Yes |
ft |
foot | No |
in |
inch | No |
yd |
yard | No |
mi |
mile | No |
g |
gram | Yes |
lb |
pound | No |
oz |
ounce | No |
s |
second | Yes |
min |
minute | No |
h |
hour | No |
day |
day | No |
K |
Kelvin | Yes |
C |
Celsius | Yes |
F |
Fahrenheit | No |
J |
Joule | Yes |
cal |
calorie | Yes |
N |
Newton | Yes |
dyn |
Dyne | No |
kp |
Kilopond | No |
pdl |
Poundal | No |
lbf |
Pound-force | No |
W |
Watt | Yes |
Hz |
Hertz | Yes |
kph |
Kilometers per Hour | No |
mph |
Miles per Hour | No |
bpm |
Beats per Minute | No |
As you have noticed some of those units accept a prefix. The recognised prefixes are
| Symbol | Name | Multiplier |
|---|---|---|
Y |
Yotta | 1e24 |
Z |
Zetta | 1e21 |
E |
Exa | 1e18 |
P |
Peta | 1e15 |
T |
Tera | 1e12 |
G |
Giga | 1e9 |
M |
Mega | 1e6 |
k |
Kilo | 1e3 |
h |
Hecto | 1e2 |
da |
Deca | 1e1 |
d |
Deci | 1e-1 |
c |
Centi | 1e-2 |
m |
Milli | 1e-3 |
μ |
Micro | 1e-6 |
mu |
Micro | 1e-6 |
n |
Nano | 1e-9 |
p |
Pico | 1e-12 |
f |
Femto | 1e-15 |
a |
Atto | 1e-18 |
z |
Zepto | 1e-21 |
y |
Yocto | 1e-24 |
Example
5.45|kg|
23|kg*m/s^2| // same as 23|N|
12.3e-3|km/h|
67|bpm|
Operators
Measurements support arithmetic operators between a measurement and a number or between two measurements and comparison operators between measurements with the same dimensions. Arithmetic operators produce Measurement values while comparison operators Boolean values.
-
Arithmetic operators (Measurement - Measurement)
Arithmetic operators between measurements are performed on the magnitude and on the unit part respectively. If an operation is performed between two measurements with different units then the result is computed to the unit of the leftmost measurement. Addition and subtraction are allowed between measurements with the same dimensions. The result of multiplication and division has different dimensions from any of the two measurements.
Symbol Name Example Result +add 2|lb| + 3.2|kg|9.054792389916082|lb|-subtract 4|N| - 2|lb*yd/s^2|3.170470273744|N|*multiply 3|kg| * 2|m|6|kg*m|/divide 5.44|N| / 3|in|1.8133333333333|N/in| -
Arithmetic operators (Number - Measurement)
Symbol Name Example Result *multiply 4 * 1.1|kg|4.4|kg|/divide 1 / 4|N|0.25|N^(-1)|^power 2|lb|^24|lb^2|Note: If you try to exponentiate a number with a measurement it will produce an error because it makes no sense to have a measurement on the exponent.
-
Comparison operators
Measurements can be compared if and only if they have the same dimensions. If they have different dimensions then the operation will produce an error.
Symbol Name Example Result ==equals 4|m| == 4|m|true<less than 2|in| < 6.3|m|true>greater than 3|m/s| > 11|kph|false<=less than or equals 8|kg| <= 12|lb|true>=greater than or equals 60|bpm| >= 1|Hz|true
Range
A range represents a collection of contignuous sets of values (called subranges).
The notation of a simple range is: start..end for the open-ended one and start...end
for the close-ended one.
A range accepts only numbers and same-dimension measurements as its boundaries. A range
with no start is implied to start at the lowest value while a range with no end is
implied to end at the maximum value. Physical constraints are not imposed upon
the declaration of a measurement (one can declare a temperature to be -10|K|)
thus the lowest value is negative infinity and the maximum value positive
infinity.
Example
-2.5..8
10|min|...15|min|
5|lb|..20|kg|
...20
0|s|... // which is the same as 0|s|..
Operators
Composite ranges can be constructed from simple ranges using the operators + and -. For example
1...4 - 2..3
represents a range that contains the subranges 1..2 and 3...4.
-
Arithmetic operations (Range - Range)
Symbol Name Example Result +add 1..2 + 3...51..2, 3...5-subtract 3|lb|..10|kg| - 6|lb|..20|kg|3|lb|..6|lb| -
Arithmetic operations (Range - Number / Measurement)
Symbol Name Example Result +displace 1..2 + 34..5-displace 3|lb|..10|kg| - 6|lb|(-3|lb|)..8.63922289|kg| -
Comparison operators (Range - Range)
Symbol Name Example Result ==equals 1..2 == 1...2false<strictly less than 0..1 < 1..2true>strictly greater than 5..8 > 3..5true -
Containment operator (Number / Measurement - Range)
Symbol Name Example Result <>contained 2 <> 1...2true -
Containment operator (Range - Number / Measurement)
Symbol Name Example Result <>contains 1|kg|...2|kg| <> 4|lb|true
String
A string is any character sequence between double quotation marks "".
Example
"This is a string"
"日本人 are awesome"
Operations
| Symbol | Name | Example | Result |
|---|---|---|---|
+ |
concatenation | "Hello" + " world" |
"Hello world" |
Boolean
Boolean values are denoted with true and false.
Nil
nil is a special program value that denotes no value.
Collections
Coach supports grouping primitive values in two ways:
Array
An array is a collection of values indexed by contiguous integers starting with 0.
It is denoted by a comma separated list wrapped in square brackets and can also
contain other collections.
Example
let array = [12, 6|kg|, "a string", [4.3, true]]
NOTE: let just binds the array on the right of the = to the name on the left.
Access
The access operator is a dot followed by the index of the element that we want to extract
array.0 // 12
array.2 // "a string"
array.3.0 // 4.3
Assignment
One can also assign the value of an array entry to another one simply by using access together with assignment
array.0 = 13
array.5 = 4|kg|
Map
A map is a collection that maps keys to values. Keys are names and values can be expressions. A map is denoted the same way as the array with a comma separated list of key value pairs.
Example
let map = [
key1: "string",
key2: 3,
key3: (a > 2 ? 12|kg| : 15|kg|),
key4: [1, 2, 3],
key5: [foo: 4.5]
]
Access
The access notation is a dot followed by the key name
map.key1 // "string"
map.key5.foo // 4.5
If there is no value at the path the nil value is returned
map.key1.foo.bar.baz // nil
Assignment
As with the array one can also assign the value of a map entry to another one simply by using assignment on a path (note that if any intermediate value is missing a map will be put in the missing position):
map.key8.bar.baz = 1
/*
The above changes map to be:
[
key1: "string",
key2: 3,
key3: (a > 2 ? 12|kg| : 15|kg|),
key4: [1, 2, 3],
key5: [foo: 4.5],
key8: [bar: [baz: 1]]
]
*/
Feedback
Feedback values are special in Coach because they cannot be created or denoted by the user. A Feedback value is the value that is returned by the Apply command and contains the measurements that the athlete performed together with the specification (if it is an Exec application).
Example
Usually to access the Feedback we store it under a name after the Apply command. For example you can right-click on an Apply command, select Store result and give it a name (say fdb)


Then you can access the values of the measured inputs that the athlete has been instructed to measure and the specified outputs that the athlete has been given.
Measured Inputs
For example if we have instructed the athlete (via the Measure command) to measure the
input reps and the input weight then you can access those values via the access notation
fdb.reps // 8
fdb.weight // 65|kg|
Specified Outputs
But you can also access the value of the specified output for a specified action using the
spec operator & on the Feedback:
&fdb.Squat.reps // 10
You can use this information however you like. One way is to see if the athlete failed the exercise
&fdb.Squat.reps == fdb.reps // false
Generally Feedback values are very important when we need to make decisions based on athlete feedback; they are the backbone of automatic intelligent athletic programming!
Expressions
One very important fact that we have to mention is that whenever you are asked to provide a value you must provide an expression in the Coach language. An expression consists of one or a combination of (via operators mentioned above) the following
- A primitive value (number, measurement, string etc)
e.g.
12 35|m| "some text" - A name (called binding) that represents a primitive value, for example exec or group parameters and stored feedback (fdb mentioned above).
Example
The following are what expressions might look like
// Simple expressions
220|lb|
false
63 - 12
35|m| / 12|s|
// More involved expressions
12|min| <= 4*60|s|
athlete_weight <> 50|kg|...60|kg|
squat_fdb.reps == (10 + i)
&fdb.Jogging.duration == fdb.duration && athlete_age > 25