We illustrate some key features of proving by learning with generative models based on Dependent Type Theory in the ProvingGround project. Some details of the project are available on its website.
We have a set $M$ with a binary operation $*$, and given elements $e_l$ and $e_m$. We also have terms correspoding to the assumptions
From these, we conclude that basic algebraic result that $e_l = e_r$. Note that the proof in its fully expanded form is fairly long, involving the correct instantiations of each of the identity axioms, a use of symmetry of equality and a use of transitivity of equality. In particular it has very low weight in a direct generative model.
However, our system finds the proof quite readily (much less than a minute even running synchronously in the notebook), due to a few key principles.
We import the locally published core of ProvingGround.
In [1]:
import $ivy.`io.github.siddhartha-gadgil::provingground-core-jvm:0.1.1-SNAPSHOT`
Out[1]:
We import the relevant packages, including the one with our example.
In [2]:
import provingground._ , interface._, HoTT._
import learning._
import library._, MonoidSimple._
Out[2]:
In [3]:
repl.pprinter.bind(translation.FansiShow.fansiPrint)
To set up a generator. For simplicity in this demo, we are not generating $\lambda$'s and $\Pi$-types
In [4]:
val tg = TermGenParams(lmW=0, piW=0)
Out[4]:
We set up the initial state for learning.
In [5]:
val ts = TermState(dist1, dist1.map(_.typ))
Out[5]:
We use the monix library for concurrency, though in this notebook we run code synchronously.
In [6]:
import monix.execution.Scheduler.Implicits.global
Out[6]:
We synchronously evolve to the next state with our generative model.
In [7]:
val evT = tg.evolvedStateTask(ts, 0.00003)
Out[7]:
In [8]:
val ev = evT.runSyncUnsafe()
Out[8]:
We identify lemmas as types that we know to be inhabited but are not inhabited by terms in the generating set. We have kept things simple, so there are fewer lemmas to start with. But the main step is learning the weights of the lemmas.
The evolution of weights is generated as an iterator. As this is a structure that is generated just once, we store it as a stream, which is a lazy, infinite list.
In [9]:
import EntropyAtomWeight._
val its = evolvedLemmaIters(ev, 1, 1)
Out[9]:
In [10]:
val streams = its.map{case (tp, it) => (tp, it.toStream)}
Out[10]:
We see three snapshots of the evolution of weights, at times $0$, $1000$ and $10000$. We also plot the evolution below.
In [11]:
streams.map{case (tp, s) => (tp, s(0), s(1000), s(10000))}
Out[11]:
In [12]:
import $ivy.`org.plotly-scala::plotly-almond:0.5.2`
import plotly._
import plotly.element._
import plotly.layout._
import plotly.Almond._
Out[12]:
In [13]:
val scatters = streams.map{case (typ, s) => Scatter((1 to 50).map(i => (i * 50)), (1 to 50).map(i => s(i * 50)), name=typ.toString )}
val tsdata = Seq(scatters: _*)
Out[13]:
In [14]:
tsdata.plot(title="Evolution of the lemma coefficients")
Out[14]:
We pick the lemma that will give us the result. Note that there are four lemmas that have high weight after the evolution, two of which will work, so one could evolve along all of them (which we do in the interactive code).
In [15]:
val pf = "lemma" :: toTyp(streams(8)._1)
pf.typ
Out[15]:
In [16]:
val tt = tg.nextTangStateTask(ev.result, TermState(FiniteDistribution.unif(pf), FiniteDistribution.empty), math.pow(10.0, -4))
Out[16]:
In [17]:
val tts = tt.runSyncUnsafe()
Out[17]:
In [18]:
tts.terms.filter(_.typ == eqM(l)(r))
Out[18]:
In [19]:
val ss = streams.filter{case (tp, s) => s(10000) > s(1000)}.map{case (tp, s) => (tp, s(10000))}
Out[19]:
In [20]:
val ls = FiniteDistribution(ss.map{case (tp, p) => Weighted("lemma" :: tp, p * 10)})
Out[20]:
In [21]:
val ts1 = TermState((dist1 ++ ls).normalized(), dist1.map(_.typ))
Out[21]:
In [22]:
val evT1 = tg.evolvedStateTask(ts1, 0.000003)
Out[22]:
In [23]:
val ev1 = evT1.runSyncUnsafe()
Out[23]:
In [24]:
ev1.result.terms.filter(_.typ == eqM(l)(r))
Out[24]:
In [25]:
ev1.result.terms.map(_.typ).entropyVec
Out[25]:
In [26]:
import Unify._
Out[26]:
In [27]:
unifApply(trans, "lemma" :: ss(0)._1, Vector())
Out[27]:
In [28]:
ss(0)._1
trans.typ
Out[28]:
In [29]:
unifApply(sym, "lemma" :: ss(0)._1, Vector())
Out[29]:
In [30]:
import Fold._
domain(trans)
Out[30]:
In [31]:
val arg = "lemma" :: ss(0)._1
Out[31]:
In [32]:
unify(M, arg.typ, _ => false)
Out[32]:
In [33]:
arg.typ
Out[33]:
In [34]:
appln(sym, arg)
Out[34]:
In [35]:
appln(trans, arg)
Out[35]:
In [36]:
val fn = appln(trans, arg).get
fn.typ
Out[36]:
In [ ]: