Scala objects are integrated with HoTT by using wrappers, combinators and implicit based convenience methods. In this note we look at the basic representations. The main power of this is to provide automatically (through implicits) types and scala bindings for functions from the basic ones.
A more advanced form of Scala representations also makes symbolic algebra simplifications. The basic form should be used, for example, for group presentations, where simplifications are not expected.
In [1]:
import $ivy.`io.github.siddhartha-gadgil::provingground-core-jvm:0.1.0`
import provingground._ , interface._, HoTT._
Out[1]:
In [2]:
import provingground._
import HoTT._, scalahott._
import ScalaRep._
Out[2]:
We consider the type of Natural numbers formed from Integers. This is defined in ScalaRep as:
case object NatInt extends ScalaTyp[Int]
Warning: This is an unsafe type, as Integers can overflow, and there is no checking for positivity.
In [3]:
NatInt
Out[3]:
In [4]:
import NatInt.rep
1.term
Out[4]:
In [5]:
val sum = ((n: Int) => (m: Int) => n + m).term
Out[5]:
In [6]:
sum(1.term)(2.term)
Out[6]:
In [7]:
val n = "n" :: NatInt
sum(n)(2.term)
Out[7]:
In [8]:
val s = lmbda(n)(sum(n)(2.term))
Out[8]:
In [9]:
s(3.term)
Out[9]:
We will also define the product
In [10]:
val prod = ((n : Int) => (m: Int) => n * m).term
Out[10]:
In [11]:
prod(2.term)(4.term)
Out[11]:
In [ ]: