Trits: minus one, zero, one
You will learn
How a trit is written as a small signed constant and why 27 shows up everywhere.
A bit has two values; a trit has three: minus one, zero and one. The lesson spec writes them as i8 constants NEG, ZERO and POS, the way the tutorial specs of t27 do. Adding POS and NEG gives ZERO. Three trits have 3 times 3 times 3 combinations, which is 27: the number of lessons in this course and the cells of a TRI-27 word.
Try it
Write an assert that POS minus NEG equals 2, and check it passes.

The three values of a trit as t27 constants, and how three trits give 27 combinations. Lesson 8 of the t27 basics course.
specs/basics/08_trits.t27
// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 8: Trits: minus one, zero, one.
; A trit has three values, and three trits give 27 combinations.
module basics_08_trits;
pub const NEG : i8 = -1;
pub const ZERO : i8 = 0;
pub const POS : i8 = 1;
pub const VALUES_PER_TRIT : u8 = 3;
test opposite_trits_cancel {
assert POS + NEG == ZERO;
assert NEG < ZERO;
}
test three_trits_give_27 {
assert VALUES_PER_TRIT * VALUES_PER_TRIT * VALUES_PER_TRIT == 27;
}
All lessons
Module 1 · A spec file
What a .t27 file holds: a module line, prose lines and comments.
Module 2 · Values and types
Constants, the width of a whole number, and true, false and text.
Module 3 · Arrays, trits and expressions
Lists of values, the three values of a trit, and what operators compute.
Module 4 · Tests and functions
A test block, several small tests in one spec, and a function with typed inputs.
Module 5 · Inside a function
Names with let and var, choices with if and switch, and loops.
Module 6 · Visibility and your own types
What pub shares with other modules, and the structs and enums you declare.
Module 7 · Modules, rules and gen-ts
Reading another module, stating a rule that always holds, and a spec turned into TypeScript.
Module 8 · The compiler and tri
The backends t27c writes, the stages it reads a spec in, and the tri command.
Module 9 · Errors, a program, what next
Reading a compiler error, one small complete program, and the course to take next.