Testing export and normalization of isles

This is after correcting the issue with context variables. There are still a couple of things to test and correct.

  • No final types in equations
  • Check if difference in weights after normalizing is due to an error.

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-68f2b038f1.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))
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()),
  Empty
)
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()),
    Empty
  ),
  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$2549/1882352798@46e04ad5
)
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.671859432529369E-4
        ),
        Weighted((B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @b, 6.25946582994212E-4),
        Weighted((B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @a, 4.3816260809594835E-4),
        Weighted(
          (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((```@a_1 , @a_2) : B×A) ↦ (```@a_1 , @a_2),
          3.71651118536973E-4
        ),
        Weighted(
          (A : 𝒰 ) ↦ ((``@a_1 , @a_2) : A×A) ↦ (``@a_1 , @a_2),
          3.71651118536973E-4
        ),
        Weighted(
          (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ a,
          0.0384282501336959
        ),
        Weighted(
          (A : 𝒰 ) ↦ (a : A) ↦ ((`@a_1 , @a_2) : A×A) ↦ a,
          8.671859432529369E-4
        ),
        Weighted((A : 𝒰 ) ↦ (@a : (A → A)) ↦ @a, 5.870181769712191E-4),
        Weighted(
          (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (B → A)) ↦ @a,
          6.937487546023499E-4
        ),
        Weighted(
          (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (B → B)) ↦ a,
          0.0016187470940721494
        ),
        Weighted(
          (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → B)) ↦ a,
          0.0013697090795995112
        ),
...
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.671859432529369E-4
      ),
      Weighted((B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @b, 6.25946582994212E-4),
      Weighted((B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @a, 4.3816260809594835E-4),
      Weighted(
        (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((```@a_1 , @a_2) : B×A) ↦ (```@a_1 , @a_2),
        3.71651118536973E-4
      ),
      Weighted(
        (A : 𝒰 ) ↦ ((``@a_1 , @a_2) : A×A) ↦ (``@a_1 , @a_2),
        3.71651118536973E-4
      ),
      Weighted(
        (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ a,
        0.0384282501336959
      ),
      Weighted(
        (A : 𝒰 ) ↦ (a : A) ↦ ((`@a_1 , @a_2) : A×A) ↦ a,
        8.671859432529369E-4
      ),
      Weighted((A : 𝒰 ) ↦ (@a : (A → A)) ↦ @a, 5.870181769712191E-4),
      Weighted(
        (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (B → A)) ↦ @a,
        6.937487546023499E-4
      ),
      Weighted(
        (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (B → B)) ↦ a,
        0.0016187470940721494
      ),
      Weighted(
        (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → B)) ↦ a,
        0.0013697090795995112
      ),
      Weighted((A : 𝒰 ) ↦ (@b : A) ↦ @b, 0.012675323748495152),
...
eqs: Set[EquationNode] = Set(
  EquationNode(
    FinalVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@a, Terms),
              @b,
              Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
            ),
            @a,
            Island(Typs, ConstRandVar(Typs), AddVar(A), Pi, EnterIsle)
          ),
          B,
          Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
        ),
        A,
        Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
      )
    ),
    Product(
      Coeff(Init(Terms)),
      InitialVal(
        InIsle(
          InIsle(
            InIsle(
              InIsle(
                Elem(@a, Terms),
                @b,
                Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
              ),
              @a,
              Island(Typs, ConstRandVar(Typs), AddVar(A), Pi, EnterIsle)
            ),
            B,
            Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
          ),
          A,
...
In [7]:
val nonDetOpt = eqs.find(eq =>  TermData.isleNormalize(eq) != TermData.isleNormalize(eq))
Out[7]:
nonDetOpt: Option[EquationNode] = None
In [8]:
show(nonDetOpt)
None
In [9]:
show(nonDetOpt.map(eq => TermData.isleNormalize(eq)))
None
In [10]:
val atoms = (eqs.map(_.rhs).flatMap(Expression.varVals(_)) union eqs.map(_.lhs).flatMap(Expression.varVals(_))).map(_.variable)
Out[10]:
atoms: Set[GeneratorVariables.Variable[Any]] = Set(
  InIsle(
    InIsle(
      InIsle(
        Elem((@b : B) ↦ @a, Terms),
        @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)
  ),
  InIsle(
    InIsle(
      Elem((@a : A) ↦ @a, Terms),
      B,
      Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
    ),
    A,
    Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
  ),
  InIsle(
    InIsle(
      InIsle(
        InIsle(
          Elem(A, Typs),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(A), Pi, 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)
...
In [11]:
import TermRandomVars._, GeneratorVariables._
val elemTerms = atoms.collect{case Elem(t: Term, Terms) => t}
Out[11]:
import TermRandomVars._, GeneratorVariables._

elemTerms: Set[Term] = Set(
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@b : B) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@b : B) ↦ @b,
  (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 : B) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@a : A) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@b : 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 : A) ↦ (@b : A) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ @b,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ a,
  (A : 𝒰 ) ↦ (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 : (B → A)) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → A)) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (B → A)) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (A → A)) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (B → B)) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (A → B)) ↦ @a,
  (B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @b,
  (B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → B)) ↦ @a(a),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → A)) ↦ @a(a),
  (B : 𝒰 ) ↦ ((``@a_1 , @a_2) : B×B) ↦ (``@a_1 , @a_2),
  (@a : B) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((``@a_1 , @a_2) : A×A) ↦ (``@a_1 , @a_2),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((```@a_1 , @a_2) : A×B) ↦ (```@a_1 , @a_2),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((``@a_1 , @a_2) : B×B) ↦ (``@a_1 , @a_2),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((```@a_1 , @a_2) : B×A) ↦ (```@a_1 , @a_2),
  (A : 𝒰 ) ↦ (a : A) ↦ A,
  (@a : (A → B)) ↦ a,
  (@a : (B → B)) ↦ a,
  (A : 𝒰 ) ↦ (a : A) ↦ (@a : (A → A)) ↦ @a,
  (@a : A) ↦ @a,
  (B : 𝒰 ) ↦ B,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ A,
...
In [12]:
elemTerms.exists(_.dependsOn(A))
Out[12]:
res11: Boolean = true

First checks

  • None of the terms depends on the variables
  • The duplication in generated variables has stopped.
In [13]:
atoms.size
Out[13]:
res12: Int = 10020
In [14]:
val elemTyps = atoms.collect{case Elem(t: Typ[Term], Typs) => t}
Out[14]:
elemTyps: Set[Typ[Term]] = Set(
  A,
  ∏(A : 𝒰 ){ A×A×A },
  ∏(A : 𝒰 ){ A×A×A },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×A×A) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → A×B×A) } },
  ∏(A : 𝒰 ){ (𝒰  → (A → A×A×A)) },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → A×B×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×A×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×B×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×B×A) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → A×A×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×B×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×A×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → A×A×B) } },
  ∏(A : 𝒰 ){ (𝒰  → (A → A×A×A)) },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → A×B×A) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → A×B×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×A×A) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×B×A) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → (B → A×A)) } },
  ∏(A : 𝒰 ){ (𝒰  → (A → (A → A×A))) },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → (B → A×B)) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → (A → A×B)) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → (B → B×B)) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → (A → B×B)) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → (A → B×A)) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → (B → B×A)) } },
  ∏(A : 𝒰 ){ (A → (A → A×A)) },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (B → A×A) } },
  ∏(A : 𝒰 ){ (𝒰  → (A → A×A)) },
  (𝒰  → ∏(B : 𝒰 ){ (B → B×B) }),
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (B → A×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → A×B) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (A → B×A) } },
  ∏(A : 𝒰 ){ ∏(B : 𝒰 ){ (B → B×A) } },
  ∏(B : 𝒰 ){ (B → (B → B)) },
  ∏(A : 𝒰 ){ (A → (((A → A) → A) → A)) },
...
In [15]:
val normEqs = eqs.map(eq => TermData.isleNormalize(eq))
Out[15]:
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 [16]:
val normAtoms = (normEqs.map(_.rhs).flatMap(Expression.varVals(_)) union normEqs.map(_.lhs).flatMap(Expression.varVals(_))).map(_.variable)
Out[16]:
normAtoms: Set[Variable[Any]] = Set(
  InIsle(
    InIsle(
      InIsle(
        InIsle(
          Elem(@b, Typs),
          @b,
          Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
        ),
        @a,
        Island(Typs, ConstRandVar(Typs), AddVar(@a), Sigma, EnterIsle)
      ),
      @b,
      Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
    ),
    @a,
    Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, 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)
  ),
  InIsle(
    InIsle(
      InIsle(
        Elem((@a → (@a → @a)), Typs),
        @a,
        Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
      ),
      @b,
...
In [17]:
val normElemTerms = normAtoms.collect{case Elem(t: Term, Terms) => t}
Out[17]:
normElemTerms: Set[Term] = Set(
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@b : B) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@b : B) ↦ @b,
  (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 : B) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@a : A) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ @b,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@b : B) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@a : B) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : B) ↦ (@a : A) ↦ @a,
  (A : 𝒰 ) ↦ (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 : (B → A)) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → A)) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (B → B)) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (A → B)) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (B → A)) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (@a : (A → A)) ↦ @a,
  (B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @b,
  (B : 𝒰 ) ↦ (@a : B) ↦ (@b : B) ↦ @a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → A)) ↦ @a(a),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ (@a : (A → B)) ↦ @a(a),
  (B : 𝒰 ) ↦ ((``@a_1 , @a_2) : B×B) ↦ (``@a_1 , @a_2),
  (@a : B) ↦ a,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((``@a_1 , @a_2) : A×A) ↦ (``@a_1 , @a_2),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((``@a_1 , @a_2) : B×B) ↦ (``@a_1 , @a_2),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((```@a_1 , @a_2) : A×B) ↦ (```@a_1 , @a_2),
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ ((```@a_1 , @a_2) : B×A) ↦ (```@a_1 , @a_2),
  (A : 𝒰 ) ↦ (a : A) ↦ A,
  (@a : (A → B)) ↦ a,
  (@a : (B → B)) ↦ a,
  (A : 𝒰 ) ↦ (a : A) ↦ (@a : (A → A)) ↦ @a,
  (@a : A) ↦ @a,
  (B : 𝒰 ) ↦ B,
  (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ B,
...
In [18]:
elemTerms == normElemTerms
Out[18]:
res17: Boolean = true

Next conclusion

  • terms are generated correctly
  • however, this does not test deeper generation, for which we must generate with the equations.
In [19]:
val ts0 = TermState(FiniteDistribution.empty, FiniteDistribution.unif(Type))
Out[19]:
ts0: TermState = TermState(
  FiniteDistribution(Vector()),
  FiniteDistribution(Vector(Weighted(𝒰 , 1.0))),
  Vector(),
  FiniteDistribution(Vector()),
  FiniteDistribution(Vector()),
  Empty
)
In [20]:
val ev = ExpressionEval.fromInitEqs(ts0, Equation.group(eqs), TermGenParams(), decayS = 0.95)
Out[20]:
ev: ExpressionEval = provingground.learning.ExpressionEval$$anon$2@4d50d08d
In [21]:
val termsT = ev.finalTerms
Out[21]:
termsT: FiniteDistribution[Term] = FiniteDistribution(
  Vector(
    Weighted(
      (A : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ @a,
      9.276485722945591E-4
    ),
    Weighted(
      (A : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ @b,
      0.001325217461338344
    ),
    Weighted(
      (A : 𝒰 ) ↦ (a : A) ↦ (@a : A) ↦ (@b : A) ↦ a,
      6.551449356602914E-4
    ),
    Weighted(
      (A : 𝒰 ) ↦ (a : A) ↦ ((``@a_1 , @a_2) : A×A) ↦ (``@a_1 , @a_2),
      0.006482343732652738
    ),
    Weighted(
      (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ ((```@a_1 , @a_2) : A×B) ↦ (```@a_1 , @a_2),
      6.482328556913037E-4
    ),
    Weighted(
      (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ ((``@a_1 , @a_2) : B×B) ↦ (``@a_1 , @a_2),
      6.482334239667172E-4
    ),
    Weighted(
      (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ ((```@a_1 , @a_2) : B×A) ↦ (```@a_1 , @a_2),
      6.481468665912907E-4
    ),
    Weighted(
      (A : 𝒰 ) ↦ (B : 𝒰 ) ↦ (a : A) ↦ ((``@a_1 , @a_2) : A×A) ↦ (``@a_1 , @a_2),
      6.481464725181117E-4
    ),
    Weighted(
...
In [22]:
val evN = ExpressionEval.fromInitEqs(ts0, Equation.group(normEqs), TermGenParams(), decayS = 0.95)
Out[22]:
evN: ExpressionEval = provingground.learning.ExpressionEval$$anon$2@23655098
In [22]:
// val termsN = evN.finalTerms
In [23]:
evN.init
Out[23]:
res22: Map[Expression, Double] = Map(
  Coeff(
    BaseThenCondition(
      FiberProductMap(domOf, TermsWithTyp, Appln, TypFamilies, Terms),
      Typs,
      Restrict(TypOpt)
    )
  ) -> 0.1,
  IsleScale(@a, Elem(@a, Terms)) -> 0.7,
  Coeff(
    BaseThenCondition(
      FiberProductMap(typeOf(_), FuncsWithDomain, FlipAppn, Terms, Terms),
      AtCoord(FuncsWithDomain, A :: HNil),
      Restrict(FuncWithDom(A))
    )
  ) -> 0.1,
  IsleScale(a, Elem(a, AtCoord(TermsWithTyp, A :: HNil))) -> 0.7,
  IsleScale(@a, Elem(B, Typs)) -> 0.7,
  IsleScale(@a, Elem(B, Typs)) -> 0.7,
  IsleScale(@a, Elem(B, Typs)) -> 0.7,
  IsleScale(@a, Elem(B, Typs)) -> 0.7,
  IsleScale(@a, Elem(B, Typs)) -> 0.7,
  IsleScale(@a, Elem(B, Typs)) -> 0.7,
  InitialVal(Elem(Wrap(@a), Funcs)) -> 0.4285714285714286,
  InitialVal(Elem(Wrap(@a), Funcs)) -> 0.4285714285714286,
  IsleScale(@a, Elem(a, Terms)) -> 0.7,
  IsleScale(@a, Elem(a, Terms)) -> 0.7,
  IsleScale((@a_1 , @a_2), Elem((@a_1 , @a_2), Terms)) -> 0.7,
  IsleScale(@b, Elem(@a, Terms)) -> 0.7,
  Coeff(
    Island(
      AtCoord(FuncsWithDomain, (B → A) :: HNil),
      ConstRandVar(Terms),
      AddVar((B → A)),
      Lambda,
      EnterIsle
    )
  ) -> 0.1,
  Coeff(
...
In [24]:
import ExpressionEval._
Out[24]:
import ExpressionEval._
In [25]:
evN.equations
Out[25]:
res24: Set[Equation] = Set(
  Equation(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
            ),
            @a,
            Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
          ),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(A), Pi, EnterIsle)
        ),
        @a,
        Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
      )
    ),
    Sum(Literal(1.0), Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0)))
  ),
  Equation(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@a, Typs),
              @a,
              Island(
                Typs,
                ConstRandVar(Typs),
                AddVar((@b → @a)),
                Sigma,
                EnterIsle
              )
            ),
...
In [26]:
val m1 = nextMap(evN.init, evN.equations)
Out[26]:
m1: Map[Expression, Double] = Map(
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            Elem(@a, Terms),
            @a,
            Island(Typs, ConstRandVar(Typs), AddVar(@a), Pi, EnterIsle)
          ),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(@b), Pi, EnterIsle)
        ),
        @b,
        Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
      ),
      @a,
      Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
    )
  ) -> 0.30000000000000004,
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(
                AtCoord(FuncsWithDomain, @a :: HNil),
                ConstRandVar(Terms),
                AddVar(@a),
                Lambda,
                EnterIsle
              )
            ),
            @a,
            Island(Terms, ConstRandVar(Terms), AddVar(@b), Lambda, EnterIsle)
          ),
...
In [27]:
m1.values
Out[27]:
res26: Iterable[Double] = MapLike.DefaultValuesIterable(
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  -0.3999999999999999,
  0.30000000000000004,
  -0.3999999999999999,
  0.30000000000000004,
  0.1,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  -0.3999999999999999,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.7,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.1,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
...
In [28]:
val exp = m1.find(_._2 < 0).get._1
Out[28]:
exp: Expression = InitialVal(
  InIsle(
    InIsle(
      InIsle(
        InIsle(
          Elem(@b, Terms),
          @b,
          Island(
            AtCoord(FuncsWithDomain, @a :: HNil),
            ConstRandVar(Terms),
            AddVar(@a),
            Lambda,
            EnterIsle
          )
        ),
        @a,
        Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
      ),
      @b,
      Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
    ),
    @a,
    Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
  )
)
In [29]:
val rhs = evN.equations.find(_.lhs == exp).map(_.rhs).get
Out[29]:
rhs: Expression = Sum(
  Sum(Literal(1.0), Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0))),
  Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
)
In [30]:
normEqs.filter(_.lhs == exp)
Out[30]:
res29: Set[EquationNode] = Set(
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(
                AtCoord(FuncsWithDomain, @a :: HNil),
                ConstRandVar(Terms),
                AddVar(@a),
                Lambda,
                EnterIsle
              )
            ),
            @a,
            Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
          ),
          @b,
          Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
        ),
        @a,
        Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
      )
    ),
    Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
  ),
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(
                AtCoord(FuncsWithDomain, @a :: HNil),
...
In [31]:
normEqs.filter(_.lhs == exp).size
Out[31]:
res30: Int = 3
In [32]:
val baseEqs = eqs.filter(eq => TermData.isleNormalize(eq).lhs == exp)
Out[32]:
baseEqs: Set[EquationNode] = Set(
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(
                AtCoord(FuncsWithDomain, A :: HNil),
                ConstRandVar(Terms),
                AddVar(A),
                Lambda,
                EnterIsle
              )
            ),
            @a,
            Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
          ),
          B,
          Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
        ),
        A,
        Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
      )
    ),
    Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0))
  ),
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@a, Terms),
              @a,
              Island(
                AtCoord(FuncsWithDomain, A :: HNil),
...
In [33]:
baseEqs.size
Out[33]:
res32: Int = 4
In [34]:
show(baseEqs.map(_.rhs))
Set(
  Literal(1.0),
  Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0)),
  Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
)
In [35]:
val mm1 = nextMap(ev.init, ev.equations)
Out[35]:
mm1: Map[Expression, Double] = Map(
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
            ),
            @a,
            Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
          ),
          a,
          Island(Typs, ConstRandVar(Typs), AddVar(A), Pi, EnterIsle)
        ),
        B,
        Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
      ),
      A,
      Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
    )
  ) -> 0.30000000000000004,
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          Elem(@a, Terms),
          @a,
          Island(Typs, ConstRandVar(Typs), AddVar(A), Pi, EnterIsle)
        ),
        a,
        Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
      ),
      A,
      Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
    )
  ) -> 0.30000000000000004,
...
In [36]:
mm1.values
Out[36]:
res35: Iterable[Double] = MapLike.DefaultValuesIterable(
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.1,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.7,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
  0.30000000000000004,
...
In [37]:
mm1.filter(_._2 < 0)
Out[37]:
res36: Map[Expression, Double] = Map()

Bug narrowing

  • We get negative values after normalizing the expression
  • We do not get these before.
In [40]:
baseEqs.map(_.mapVars(v => TermRandomVars.isleNormalizeVars(v, Vector()))
).map(_.rhs)
Out[40]:
res39: Set[Expression] = Set(
  Literal(1.0),
  Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0)),
  Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
)
In [41]:
normEqs.filter(_.lhs == exp).map(_.rhs)
Out[41]:
res40: Set[Expression] = Set(
  Literal(1.0),
  Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0)),
  Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
)
In [42]:
evN.equations.filter(_.lhs == exp).map(_.rhs)
Out[42]:
res41: Set[Expression] = Set(
  Sum(
    Sum(Literal(1.0), Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0))),
    Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
  )
)
In [43]:
baseEqs.map(_.lhs).size
Out[43]:
res42: Int = 2
In [44]:
baseEqs.map(_.rhs)
Out[44]:
res43: Set[Expression] = Set(
  Literal(1.0),
  Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0)),
  Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
)
In [46]:
baseEqs.map(_.rhs).map(e =>  recExp(ev.init, e))
Out[46]:
res45: Set[Double] = Set(1.0, -0.7)
In [47]:
val imEqs = normEqs.filter(_.lhs == exp)
Out[47]:
imEqs: Set[EquationNode] = Set(
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(
                AtCoord(FuncsWithDomain, @a :: HNil),
                ConstRandVar(Terms),
                AddVar(@a),
                Lambda,
                EnterIsle
              )
            ),
            @a,
            Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
          ),
          @b,
          Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
        ),
        @a,
        Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
      )
    ),
    Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
  ),
  EquationNode(
    InitialVal(
      InIsle(
        InIsle(
          InIsle(
            InIsle(
              Elem(@b, Terms),
              @b,
              Island(
                AtCoord(FuncsWithDomain, @a :: HNil),
...
In [48]:
imEqs.map(_.rhs).map(e =>  recExp(evN.init, e))
Out[48]:
res47: Set[Double] = Set(1.0, -0.7)
In [49]:
evN.equations.find(_.lhs == exp).size
Out[49]:
res48: Int = 1
In [57]:
val eqq = evN.equations.find(_.lhs == exp).head
Out[57]:
eqq: Equation = Equation(
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            Elem(@b, Terms),
            @b,
            Island(
              AtCoord(FuncsWithDomain, @a :: HNil),
              ConstRandVar(Terms),
              AddVar(@a),
              Lambda,
              EnterIsle
            )
          ),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(@a), Lambda, EnterIsle)
        ),
        @b,
        Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
      ),
      @a,
      Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
    )
  ),
  Sum(
    Sum(Literal(1.0), Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0))),
    Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
  )
)
In [58]:
recExp(evN.init, eqq.rhs)
Out[58]:
res57: Double = -0.3999999999999999
In [55]:
evN.init.get(exp)
Out[55]:
res54: Option[Double] = None
In [56]:
stabRecExp(evN.init, exp, None)
Out[56]:
res55: Double = 0.0
In [54]:
m1(exp)
Out[54]:
res53: Double = -0.3999999999999999
In [ ]:
nextMap(evN.init, evN.equations, )
In [39]:
baseEqs.head
Out[39]:
res38: EquationNode = EquationNode(
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            Elem(@b, Terms),
            @b,
            Island(
              AtCoord(FuncsWithDomain, A :: HNil),
              ConstRandVar(Terms),
              AddVar(A),
              Lambda,
              EnterIsle
            )
          ),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
        ),
        B,
        Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
      ),
      A,
      Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
    )
  ),
  Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0))
)
In [59]:
imEqs.map(_.rhs).map(e =>  e -> recExp(evN.init, e))
Out[59]:
res58: Set[(Expression, Double)] = Set(
  (Literal(1.0), 1.0),
  (Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0)), -0.7),
  (Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0)), -0.7)
)
In [60]:
baseEqs.map(_.rhs).map(e => e -> recExp(ev.init, e))
Out[60]:
res59: Set[(Expression, Double)] = Set(
  (Literal(1.0), 1.0),
  (Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0)), -0.7),
  (Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0)), -0.7)
)
In [61]:
eqq.rhs
Out[61]:
res60: Expression = Sum(
  Sum(Literal(1.0), Product(IsleScale(@b, Elem(@b, Terms)), Literal(-1.0))),
  Product(IsleScale(@a, Elem(@a, Terms)), Literal(-1.0))
)
In [62]:
show(baseEqs.map(_.lhs))
Set(
  InitialVal(
    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(A), Lambda, EnterIsle)
        ),
        B,
        Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
      ),
      A,
      Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
    )
  ),
  InitialVal(
    InIsle(
      InIsle(
        InIsle(
          InIsle(
            Elem(@b, Terms),
            @b,
            Island(
              AtCoord(FuncsWithDomain, A :: HNil),
              ConstRandVar(Terms),
              AddVar(A),
              Lambda,
              EnterIsle
            )
          ),
          @a,
          Island(Terms, ConstRandVar(Terms), AddVar(A), Lambda, EnterIsle)
        ),
        B,
        Island(Typs, ConstRandVar(Typs), AddVar(𝒰 ), Pi, EnterIsle)
      ),
      A,
      Island(Terms, ConstRandVar(Terms), AddVar(𝒰 ), Lambda, EnterIsle)
    )
  )
)

Bug diagnosed

  • There are two equations whose left hand sides merge, as do the terms Literal(1) on the right-hand side.
  • However, the terms IsleScale(@b, Elem(@b, Terms) and IsleScale(@a, Elem(@a, Terms) do not merge.
  • Correct behaviour: This should also have substitution.
  • Implementation: Avoid the small savings with mapVars and instead recurse over expressions with substitutions, including IsleScale in an obvious ways.