Testing export and normalization of isles

When we have variables such as $A: Type$, $a : A$ and $B: Type$, we test whether we correctly:

  • export equations, so that variables end up in islands
  • normalize isle names.

This time the test is more refined. Namely,

  • We generate with the equations after exporting and just $Type$ as the initial distribution.
  • We check that all terms are independent of the variables.
  • Generate with equations after normalization.
  • Make the same tests.
  • Also test if the distribution after normalization is approximately the same as before.
In [1]:
import $cp.bin.`provingground-core-jvm-4240e21976.fat.jar`
import provingground._ , interface._, HoTT._, learning._ 
repl.pprinter() = {
  val p = repl.pprinter()
  p.copy(
    additionalHandlers = p.additionalHandlers.orElse {
      translation.FansiShow.fansiHandler
    }
  )
}
Out[1]:
import $cp.$                                              

import provingground._ , interface._, HoTT._, learning._ 
In [2]:
val A = "A" :: Type
val B = "B" :: Type
val a = "a" :: A
val ts = TermState(FiniteDistribution.unif(a), FiniteDistribution.unif(A, B), vars = Vector(A, B, a), context = Context.Empty.addVariable(A).addVariable(B).addVariable(a))
Out[2]:
A: Typ[Term] = A
B: Typ[Term] = B
a: Term = a
ts: TermState = TermState(
  FiniteDistribution(Vector(Weighted(a, 1.0))),
  FiniteDistribution(Vector(Weighted(A, 0.5), Weighted(B, 0.5))),
  Vector(A, B, a),
  FiniteDistribution(Vector()),
  FiniteDistribution(Vector()),
  AppendVariable(AppendVariable(AppendVariable(Empty, A), B), a)
)
In [3]:
val lp = LocalProver(ts)
Out[3]:
lp: LocalProver = LocalProver(
  TermState(
    FiniteDistribution(Vector(Weighted(a, 1.0))),
    FiniteDistribution(Vector(Weighted(A, 0.5), Weighted(B, 0.5))),
    Vector(A, B, a),
    FiniteDistribution(Vector()),
    FiniteDistribution(Vector()),
    AppendVariable(AppendVariable(AppendVariable(Empty, A), B), a)
  ),
  TermGenParams(
    0.1,
    0.1,
    0.1,
    0.1,
    0.1,
    0.05,
    0.05,
    0.05,
    0.0,
    0.0,
    0.0,
    0.0,
    0.3,
    0.7,
    0.5,
    0.0,
    0.0,
    0.0,
    OrElse(
      OrElse(OrElse(OrElse(<function1>, <function1>), <function1>), <function1>),
      <function1>
    )
  ),
  1.0E-4,
  None,
  12 minutes,
  1.01,
  1.0,
...
In [4]:
ts.vars
import TermData._
val datT = termData(lp)
Out[4]:
res3_0: Vector[Term] = Vector(A, B, a)
import TermData._

datT: monix.eval.Task[(TermState, Set[EquationNode])] = FlatMap(
  Async(<function2>, false, true, true),
  provingground.learning.TermData$$$Lambda$2566/2124479365@309a5ef6
)
In [5]:
import monix.execution.Scheduler.Implicits.global
val td = datT.runSyncUnsafe()
Out[5]:
import monix.execution.Scheduler.Implicits.global

td: (TermState, Set[EquationNode]) = (
  TermState(
    FiniteDistribution(
      Vector(
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗB) ā†¦ a,
          8.675006846432388E-4
        ),
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : B) ā†¦ @a,
          0.0010674443639559507
        ),
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : BƗA) ā†¦ (```@a_1 , @a_2),
          3.7178600770424526E-4
        ),
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗA) ā†¦ (``@a_1 , @a_2),
          3.7178600770424526E-4
        ),
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ a,
          0.035508944319399785
        ),
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((`@a_1 , @a_2) : AƗA) ā†¦ a,
          8.675006846432388E-4
        ),
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ @a,
          5.872312326815773E-4
        ),
        Weighted(
          (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ @a,
          6.940005477145914E-4
        ),
        Weighted(
...
In [6]:
val (ns, eqs) = td
Out[6]:
ns: TermState = TermState(
  FiniteDistribution(
    Vector(
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗB) ā†¦ a,
        8.675006846432388E-4
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : B) ā†¦ @a,
        0.0010674443639559507
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : BƗA) ā†¦ (```@a_1 , @a_2),
        3.7178600770424526E-4
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗA) ā†¦ (``@a_1 , @a_2),
        3.7178600770424526E-4
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ a,
        0.035508944319399785
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((`@a_1 , @a_2) : AƗA) ā†¦ a,
        8.675006846432388E-4
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ @a,
        5.872312326815773E-4
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ @a,
        6.940005477145914E-4
      ),
      Weighted(
        (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ B)) ā†¦ a,
...
eqs: Set[EquationNode] = Set(
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              InIsle(
                Elem(@a, Terms),
                @a,
                Island(
                  AtCoord(FuncsWithDomain, A :: HNil),
                  ConstRandVar(Terms),
                  AddVar(A),
                  Lambda,
                  EnterIsle
                )
              ),
              @a,
              Island(Terms, ConstRandVar(Terms), AddVar(B), Lambda, EnterIsle)
            ),
            a,
            Island(
              Terms,
              ConstRandVar(Terms),
              provingground.learning.ExpressionEval$$Lambda$2817/905264381@5257f595,
              Lambda,
              EnterIsle
            )
          ),
          B,
          Island(
            Terms,
            ConstRandVar(Terms),
            provingground.learning.ExpressionEval$$Lambda$2817/905264381@55d64a8b,
            Lambda,
            EnterIsle
...
In [7]:
val atoms = (eqs.map(_.rhs).flatMap(Expression.varVals(_)) union eqs.map(_.lhs).flatMap(Expression.varVals(_))).map(_.variable)
Out[7]:
atoms: Set[GeneratorVariables.Variable[Any]] = Set(
  InIsle(
    InIsle(
      InIsle(
        Elem(BƗ(B ā†’ B), Typs),
        a,
        Island(
          Typs,
          ConstRandVar(Typs),
          provingground.learning.ExpressionEval$$Lambda$2811/1006068907@7f51a7e2,
          Pi,
          EnterIsle
        )
      ),
      B,
      Island(
        Terms,
        ConstRandVar(Terms),
        provingground.learning.ExpressionEval$$Lambda$2817/905264381@55d64a8b,
        Lambda,
        EnterIsle
      )
    ),
    A,
    Island(
      Typs,
      ConstRandVar(Typs),
      provingground.learning.ExpressionEval$$Lambda$2811/1006068907@5083d5b9,
      Pi,
      EnterIsle
    )
  ),
  InIsle(
    InIsle(
      InIsle(
        Elem(BƗ(A ā†’ B), Typs),
        a,
        Island(
...
In [8]:
import TermRandomVars._, GeneratorVariables._
val elemTerms = atoms.collect{case Elem(t: Term, Terms) => t}
Out[8]:
import TermRandomVars._, GeneratorVariables._

elemTerms: Set[Term] = Set(
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : B) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : B) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ B)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ B)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((`@a_1 , @a_2) : AƗA) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((`@a_1 , @a_2) : BƗB) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗB) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : BƗA) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ B)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ B)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : BƗA) ā†¦ (```@a_1 , @a_2),
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : AƗB) ā†¦ (```@a_1 , @a_2),
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : BƗB) ā†¦ (``@a_1 , @a_2),
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗA) ā†¦ (``@a_1 , @a_2)
)
In [9]:
elemTerms.exists(_.dependsOn(A))
Out[9]:
res8: Boolean = false

First check

None of the terms depends on the variables

In [10]:
atoms.size
Out[10]:
res9: Int = 4527
In [11]:
val elemTyps = atoms.collect{case Elem(t: Typ[Term], Typs) => t}
Out[11]:
elemTyps: Set[Typ[Term]] = Set()
In [12]:
val normEqs = eqs.map(eq => TermData.isleNormalize(eq))
Out[12]:
normEqs: Set[EquationNode] = Set(
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@a, Typs),
              @a,
              Island(
                Typs,
                ConstRandVar(Typs),
                AddVar((@b ā†’ @a)),
                Sigma,
                EnterIsle
              )
            ),
            @a,
            Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
          ),
          @b,
          Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
        ),
        @a,
        Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
      )
    ),
    Product(
      IsleScale(@a, Elem(A, Typs)),
      InitialVal(
        InIsle(
          InIsle(
            InIsle(
              Elem(@a, Typs),
              @a,
              Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
            ),
            @b,
            Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
...
In [13]:
val normAtoms = (normEqs.map(_.rhs).flatMap(Expression.varVals(_)) union normEqs.map(_.lhs).flatMap(Expression.varVals(_))).map(_.variable)
Out[13]:
normAtoms: Set[Variable[Any]] = Set(
  InIsle(
    InIsle(
      InIsle(
        Elem((@b ā†’ (@a ā†’ @a)), Typs),
        @a,
        Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
      ),
      @b,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    ),
    @a,
    Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
  ),
  InIsle(
    InIsle(
      InIsle(
        Elem((@b ā†’ (@b ā†’ @a)), Typs),
        @a,
        Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
      ),
      @b,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    ),
    @a,
    Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
  ),
  InIsle(
    InIsle(
      InIsle(
        Elem((@a ā†’ (@b ā†’ @a)), Typs),
        @a,
        Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
      ),
      @b,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    ),
    @a,
    Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
...
In [14]:
val normElemTerms = normAtoms.collect{case Elem(t: Term, Terms) => t}
Out[14]:
normElemTerms: Set[Term] = Set(
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : B) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ (@a : B) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ B)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ B)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((`@a_1 , @a_2) : AƗA) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : BƗA) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((`@a_1 , @a_2) : BƗB) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗB) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ B)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ B)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ @a,
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : AƗB) ā†¦ (```@a_1 , @a_2),
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : BƗB) ā†¦ (``@a_1 , @a_2),
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗA) ā†¦ (``@a_1 , @a_2),
  (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : BƗA) ā†¦ (```@a_1 , @a_2)
)
In [15]:
show(normEqs.take(10).map(_.lhs))
Set(
  FinalVal(
    InIsle(
      InIsle(
        InIsle(
          Elem(@bƗ@bƗ@b, Typs),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
    )
  ),
  FinalVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@a, Typs),
              @b,
              Island(Typs, ConstRandVar(Typs), AddVar(@b), Sigma, EnterIsle)
            ),
            @a,
            Island(Typs, ConstRandVar(Typs), AddVar(@b), Pi, EnterIsle)
          ),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
    )
  ),
  FinalVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            Elem(Wrap((@a : @b) ā†¦ @a), Funcs),
            @a,
            Island(Terms, ConstRandVar(Terms), AddVar(@b), Lambda, EnterIsle)
          ),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
    )
  ),
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            Elem(@a, Typs),
            @a,
            Island(
              Typs,
              ConstRandVar(Typs),
              AddVar((@b ā†’ @a)),
              Sigma,
              EnterIsle
            )
          ),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    )
  ),
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            Elem(@a, Typs),
            @a,
            Island(
              Typs,
              ConstRandVar(Typs),
              AddVar((@a ā†’ @a)),
              Sigma,
              EnterIsle
            )
          ),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    )
  ),
  FinalVal(
    InIsle(
      InIsle(
        InIsle(
          Elem((@a : @a) ā†¦ (@a : @a) ā†¦ @a, Terms),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    )
  ),
  FinalVal(
    InIsle(
      InIsle(
        InIsle(
          Elem((@a ā†’ @bƗ@b), Typs),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    )
  ),
  FinalVal(
    InIsle(
      InIsle(
        InIsle(
          Elem((@a : (@b ā†’ @b)) ā†¦ @a, Terms),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    )
  ),
  FinalVal(
    InIsle(
      InIsle(
        InIsle(
          Elem((@a : (@a ā†’ @b)) ā†¦ @a, Terms),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Typs, ConstRandVar(Typs), AddVar(š’° ), Pi, EnterIsle)
    )
  ),
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Typs),
              @b,
              Island(Typs, ConstRandVar(Typs), AddVar(@a), Sigma, EnterIsle)
            ),
            @a,
            Island(Typs, ConstRandVar(Typs), AddVar(@b), Sigma, EnterIsle)
          ),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
      ),
      @a,
      Island(Terms, ConstRandVar(Terms), AddVar(š’° ), Lambda, EnterIsle)
    )
  )
)
In [16]:
elemTerms == normElemTerms
Out[16]:
res15: Boolean = true

Next conclusion

  • terms are generated correctly
  • however, this does not test deeper generation, for which we must generate with the equations.
In [17]:
val ts0 = TermState(FiniteDistribution.empty, FiniteDistribution.unif(Type))
Out[17]:
ts0: TermState = TermState(
  FiniteDistribution(Vector()),
  FiniteDistribution(Vector(Weighted(š’° , 1.0))),
  Vector(),
  FiniteDistribution(Vector()),
  FiniteDistribution(Vector()),
  Empty
)
In [18]:
val ev = ExpressionEval.fromInitEqs(ts0, Equation.group(eqs), TermGenParams(), decayS = 0.95)
Out[18]:
ev: ExpressionEval = provingground.learning.ExpressionEval$$anon$2@5c8dfa6f
In [19]:
val termsT = ev.finalTerms
Out[19]:
termsT: FiniteDistribution[Term] = FiniteDistribution(
  Vector(
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : BƗA) ā†¦ (```@a_1 , @a_2),
      0.023783361218616697
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗA) ā†¦ (``@a_1 , @a_2),
      0.023783346929568194
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : BƗB) ā†¦ (``@a_1 , @a_2),
      0.023786541590912733
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : AƗB) ā†¦ (```@a_1 , @a_2),
      0.023786520883480558
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ @a,
      0.04758154345221369
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ @a,
      0.04758142786902684
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ B)) ā†¦ @a,
      0.04759436016007325
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ B)) ā†¦ @a,
      0.04759419256878797
    ),
    Weighted(
...
In [24]:
val evN = ExpressionEval.fromInitEqs(ts0, Equation.group(normEqs), TermGenParams(), decayS = 0.95)
Out[24]:
evN: ExpressionEval = provingground.learning.ExpressionEval$$anon$2@295b075
In [25]:
val termsN = evN.finalTerms
Out[25]:
termsN: FiniteDistribution[Term] = FiniteDistribution(
  Vector(
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : BƗA) ā†¦ (```@a_1 , @a_2),
      0.021427818142670963
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : BƗB) ā†¦ (``@a_1 , @a_2),
      0.021430696963074085
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((```@a_1 , @a_2) : AƗB) ā†¦ (```@a_1 , @a_2),
      0.021430678902601065
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ ((``@a_1 , @a_2) : AƗA) ā†¦ (``@a_1 , @a_2),
      0.02142780590265384
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ B)) ā†¦ @a,
      0.042880191056144476
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ A)) ā†¦ @a,
      0.042868736079918056
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (A ā†’ A)) ā†¦ @a,
      0.04286863716011596
    ),
    Weighted(
      (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : (B ā†’ B)) ā†¦ @a,
      0.04288033712339029
    ),
    Weighted(
...
In [27]:
termsT.support == termsN.support
Out[27]:
res26: Boolean = true
In [28]:
ExpressionEval.mapRatio(termsT.toMap, termsN.toMap)
Out[28]:
res27: Double = 4.6001650461794075
In [29]:
val bigT = termsT.support.maxBy(t => termsT(t) / termsN(t))
Out[29]:
bigT: Term = (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : B) ā†¦ a
In [30]:
termsT(bigT)
termsN(bigT)
Out[30]:
res29_0: Double = 0.03520116836582195
res29_1: Double = 0.031162283724873487
In [31]:
val bigN = termsT.support.maxBy(t => termsN(t) / termsT(t))
Out[31]:
bigN: Term = (A : š’° ) ā†¦ (B : š’° ) ā†¦ (a : A) ā†¦ (@a : A) ā†¦ (@a : A) ā†¦ a
In [32]:
termsT(bigN)
termsN(bigN)
Out[32]:
res31_0: Double = 0.002380181625229522
res31_1: Double = 0.01094922831593934

Partial bug fix

  • the crash has stopped
  • however, it is clear that variable names are being reused incorrectly.
In [33]:
val ns = lp.nextState.runSyncUnsafe()
Out[33]:
ns: TermState = TermState(
  FiniteDistribution(
    Vector(
      Weighted(((@a_1 , @a_2) : AƗB) ā†¦ a, 8.675006846432388E-4),
      Weighted((@a : B) ā†¦ (@a : B) ā†¦ @a, 0.0010674443639559507),
      Weighted(((`@a_1 , @a_2) : BƗA) ā†¦ (`@a_1 , @a_2), 3.7178600770424526E-4),
      Weighted(((`@a_1 , @a_2) : AƗA) ā†¦ (`@a_1 , @a_2), 3.7178600770424526E-4),
      Weighted((@a : B) ā†¦ a, 0.035508944319399785),
      Weighted(((@a_1 , @a_2) : AƗA) ā†¦ a, 8.675006846432388E-4),
      Weighted((@a : (A ā†’ A)) ā†¦ @a, 5.872312326815773E-4),
      Weighted((@a : (B ā†’ A)) ā†¦ @a, 6.940005477145914E-4),
      Weighted((@a : (A ā†’ B)) ā†¦ a, 0.001370206209590347),
      Weighted((@a : (B ā†’ B)) ā†¦ a, 0.0016193346113340464),
      Weighted((@a : A) ā†¦ @a, 0.02245098635849324),
      Weighted((@a : A) ā†¦ (@a : A) ā†¦ @a, 0.0011041153249291451),
      Weighted(((`@a_1 , @a_2) : BƗB) ā†¦ (`@a_1 , @a_2), 3.7178600770424526E-4),
      Weighted((@a : A) ā†¦ (@a : A) ā†¦ a, 0.0010608166847358453),
      Weighted((@a : (A ā†’ A)) ā†¦ @a(a), 3.558977167767136E-4),
      Weighted((@a : A) ā†¦ (@a : B) ā†¦ @a, 6.494796028994972E-4),
      Weighted((@a : B) ā†¦ (@a : A) ā†¦ @a, 4.3953591457009735E-4),
      Weighted(a, 0.8658912103781063),
      Weighted((@a : B) ā†¦ (@a : B) ā†¦ a, 0.0010255838006635605),
      Weighted((@a : (A ā†’ A)) ā†¦ a, 0.001370206209590347),
      Weighted((@a : (B ā†’ A)) ā†¦ a, 0.0016193346113340464),
      Weighted((@a : (B ā†’ B)) ā†¦ @a, 6.940005477145914E-4),
      Weighted((@a : (A ā†’ B)) ā†¦ @a, 5.872312326815773E-4),
      Weighted((@a : A) ā†¦ (@a : B) ā†¦ a, 0.0010608166847358453),
      Weighted((@a : B) ā†¦ (@a : A) ā†¦ a, 0.0010255838006635605),
      Weighted(((`@a_1 , @a_2) : AƗB) ā†¦ (`@a_1 , @a_2), 3.7178600770424526E-4),
      Weighted((@a : A) ā†¦ a, 0.03721737508977956),
      Weighted((@a : B) ā†¦ @a, 0.016205076100067474),
      Weighted((@a : A) ā†¦ (@a : B) ā†¦ @a, 4.546357220296481E-4),
      Weighted((@a : B) ā†¦ (@a : A) ā†¦ @a, 6.279084493858533E-4),
      Weighted(((@a_1 , @a_2) : BƗA) ā†¦ a, 8.675006846432388E-4),
      Weighted(((@a_1 , @a_2) : BƗB) ā†¦ a, 8.675006846432388E-4),
      Weighted((@a : (A ā†’ B)) ā†¦ @a(a), 3.558977167767136E-4)
    )
  ),
  FiniteDistribution(
...
In [34]:
val x = nextVar(A, Vector())
Out[34]:
x: Term = @a
In [35]:
val ctx = Context.Empty.addVariable(x)
val y = nextVar(A, ctx.variables)
Out[35]:
ctx: Context.AppendVariable[Term] = AppendVariable(Empty, @a)
y: Term = @b

The error may be because of two independent ways in which variables are generated.