Let's build a bridge between
writing software and
doing mathematics
is a dependently typed
programming language and an
interactive theorem prover
Define natural number as an inductive datatype.
datatype Nat {
  zero: Nat
  add1(prev: Nat): Nat
}

function add(x: Nat, y: Nat): Nat {
  return recursion (x) {
    case zero => y
    case add1(prev, almost) =>
      add1(almost.prev)
  }
}
Prove the commutative property of addition for natural number, by defining a function.
function add_is_commutative(
  x: Nat, y: Nat,
): Equal(Nat, add(x, y), add(y, x)) {
  return induction (x) {
    motive (x) => Equal(Nat, add(x, y), add(y, x))
    case zero => add_is_commutative_on_zero(y)
    case add1(prev, almost) =>
      equal_compose(
        equal_map(almost.prev, add1),
        equal_swap(add_is_commutative_on_add1(y, prev)),
      )
  }
}
Define mathematics structures, such as Group, as a class. Note that, we can use extends to reuse already defined Monoid.
class Group extends Monoid {
  inv(x: Element): Element

  inv_left(x: Element):
    Equal(Element, mul(inv(x), x), id)

  inv_right(x: Element):
    Equal(Element, mul(x, inv(x)), id)

  div(x: Element, y: Element): Element {
    return mul(x, inv(y))
  }
}
Get Started
Copyright © 2021-2025 Xie Yuheng