HOCC

Speculations on Linear Dependent Types: Eventual Consistency, Entanglement, Quantum Fields, and ๐”ฝโ‚

In the present document I will sketch how to extend the Higher Observational Construction Calculus HOCC by single-use variables and types for them, outline how in this setting the univalent equality turns into entanglement and eventual consistency conditions, and speculate about connections to quantum computations, quantum fields and โ€field with one elementโ€™ ๐”ฝโ‚.

ยง Request Endpoints and Continuations

Assume you use a variant of intuitionistic type theory as a functional programming language but seek to go beyond functions that just calculate. You want to write down routines that interact with external agents. From now on we will be calling the types available in intuitionistic type theories value types, because weโ€™ll be introducing an additional kind of types: the agent types. In this setting user interaction will be also modelled as interaction with an agent of specified type but unknown and unknowable internal workings.

Interactions can be represented by performing requests and calculating with their results. For any to value types ReqT : ๐“ค and RespT : ๐“ค there will be an agent type ReqT โŠธ RespT describing request endpoints. A request endpoint f : ReqT โŠธ RespT can be used as you would normally use a function:

#let response = f(request)

But there is one caveat: the endpoint f : ReqT โŠธ RespT is a single-use variable, it can be used only once and it must be either โ€œconsumedโ€ or returned back to to the caller as a part of the return โ€œvalueโ€.

Continuations constitute a form of request endpoint. A routine anticipating continuation has the following signature:

proc(nฬฒoฬฒrฬฒmฬฒaฬฒlฬฒ-ฬฒaฬฒrฬฒgฬฒsฬฒ : X)[Tฬฒ](cฬฒoฬฒnฬฒtฬฒ : R โŠธ T) : T

 equaivalently

proc : ฮ (nฬฒoฬฒrฬฒmฬฒaฬฒlฬฒ-ฬฒaฬฒrฬฒgฬฒsฬฒ : X) โ‹‚(Tฬฒ) (R โŠธ T) โŠธ T

Certainly, response types can be dependent on request types:

 ReqT : ๐“ค   (r : ReqT) โŠข RespT(r)
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
    (rฬฒ : ReqT) โŠธ RespT(r) : ๐“›

For request endpoints that are not mandatory to use, one can use a special request to close them. You just wrap ReqT into a type with additional request Terminate, and wrap the type RespT into a type with additional responce Terminated which arizes iff the request was to close the endpoint:

#Inductive OptionalRec[RฬฒeฬฒqฬฒTฬฒ : *] : *
  Request(rฬฒ : T)
  Terminate

#Inductive Resp[RฬฒeฬฒsฬฒpฬฒTฬฒ : ReqT โ†’ *] : OptionalRec[ReqT] โ†’ *
  Terminate โ†ฆ Terminated
  Request(rฬฒ) โ†ฆ Response(rฬฒeฬฒsฬฒpฬฒ : ReqT(r))

now instead of `f : (rฬฒ : ReqT) โŠธ RespT(r)` you can
use `f : (rฬฒ : OptionalRec(ReqT)) โŠธ Resp[RespT](r)`
to have a closable request endpoint.

An endpoint can return another endpoints. For example, consider

random-number-generator : (nฬฒ : โ„•) โŠธ (๐Ÿ™ โŠธ Fin(100))โฟ

Given a natural number n it generates n independent endpoints, each of them has a trivial request type (the type ๐Ÿ™ with the single inhabitant () : ๐Ÿ™, and returns a number between 0 and 99 when invoked).

Endpoint factory has the type denoted !I. It produces any number of independent endpoints of identical type. A variable of a type x : !I is not single-use any more, it is allowed to be used any number of times. For value types A and B, the types A โ†’ B and !A โŠธ B are equivalent.

By returning a single endpoint as part of the responce, endpoints can represent communication streams. If an endpoint has a type I with property I = (rฬฒ : ReqT) โŠธ I ร— RespT(r), an endpoint s : I can be used as follows:

#let (sโ‚‚, responseโ‚) := s(requestโ‚)
#let (sโ‚ƒ, responseโ‚‚) := sโ‚‚(requestโ‚‚)
...

Since each sโ‚™ has the same name and the previous one is already consumed, one can actually suppress induces. Then we could write code like this:

#let (console, _)    := console(Print("Please, enter your name: "))
#let (console, name) := console(GetString)
#let (console, _)    := console(Print("Hello, [name]!"))

Since there is no way to close the running endpoint, at the end of such a routine you just return console back to the caller.

In general, type of the returned endpoint could also change. Assume we have the type โ€œStateโ€, the types ReqT(sฬฒ : State) and RespT(sฬฒ : State)(rฬฒ : Req(s)) now depend on the state of the endpoint, and we have the function next-state(sฬฒ : State, rฬฒ : ReqT(s)) : State. Now we can define the type I(sฬฒ : State) with the property

I(s) = (rฬฒ : ReqT(s)) โŠธ I(next-state(s, r)) ร— RespT(s)(r)

Such types are called session types. One also allow an endpoint to return multiple fresh endpoints or no endpoint at all closing the communication. With this generalization we obtain the linear counterpart of coinductive types. As coinductive types can be generalized to Equaliser Coinductive Types (the dual of Quotient Inductive Types) by equational conditions, session types can be generalized by conditions in terms of string diagrams (the linear counterpart of equations). These string diagrams specify required indepencence structure of returned endpoints, and as well as the eventual consistency structure. In other words, these are the rules specifying allowed out of order execution of requests.

ยง Double Sided Sequents: Pool of Processes

Judgements in intuitionistic type theories are one-sided sequents: there are several types on the left side (they represent the context), and a single type on the right side: the type of the expression being constructed:

x : X,..., z : Z โŠข expr : T

Concurrent interactive systems can be described by double-sided sequents, that is sequents with multiple expressions on the right side, which represent a pool of processes running in parallel:

x : X,..., z : Z โŠข procโ‚ : A,..., procโ‚™ : C

The context on the left side can be dependent: type annotations to the right of x : X can use x as a varable, and so on. Can the right side be dependent too?

Let us assume, you have a routine that requiers a request endpoint e : ๐Ÿ™ โŠธ โ„•. It can be viewed as a closes routine that opens a single-use channel of dual type โ„• โŠธ ๐Ÿ™ and waits for some other process to use this channel. We propose to call it co-lambda abstraction:

  ฮ“, e : ๐Ÿ™ โŠธ โ„• โŠข a(e) : A, ฮ”
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
 ฮ“ โŠข (ฤ“ : ๐Ÿ™ โŠธ โ„•; a(e) ) : A, ฮ”

Now the cocontext ฮ” can (and, actually must) use variable e defined in the first expression of the cocontext. Actually, the rule of inference as stated is incomplete. Thatโ€™s the complete version:

 ฮ“, e : ๐Ÿ™ โŠธ โ„• โŠข a(e) : A, ฮ”     ฮ“', e : โ„• โŠธ ๐Ÿ™ โŠข b(e) : B, ฮ”'
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
       ฮ“, ฮ“' โŠข (ฤ“ : ๐Ÿ™ โŠธ โ„•; a(e) ) : A, b(e) : B, ฮ”, ฮ”'

Of course it works not only for the type ๐Ÿ™ โŠธ โ„• but for all dualizable agent types including all session types. With co-lambda abstractions it is possible to implement coroutines.

ยง Operations on Agent Types

For two values types T Q : ๐“ค one can build their cartesian product T ร— Q containing pairs (t, q) of values t : T and q : Q. We can also build dependent pair types ฮฃ(tฬฒ : T) Q(t).

This trivially generalizes to the case when Q : ๐“› is an agent type. It allows to define disjunctive sum of two agent types Q โŠ• P := ฮฃ(tฬฒ : ๐”น) (ff โ†ฆ Q, tt โ†ฆ P). That is, an actor of type Q โŠ• P is either of type Q or of type P.

Now what about cartesian product of two agent types? There, we have to options:

This two binary connectives can be as well generalized to quantifiers where bounded variable is of a value type.

The operators โŠ•, โŠ—, & and โŠธ precisely reproduce the rules of Intuitionistic Linear Logic. See โ€œLinear Logic Propositions as Session Typesโ€ by L. Caires, F. Pfenning, and B. Toninho to see to complete calculus including constructors how to define particular processes and interactions. There you will find a calculus where one can spawn new processes/actors, pass messages and continuations, etc.

Yet, there is some assymetry: we have only three quantifiers instead of four. There is one more binary connective in the linear logic: the conjunctive sum โ…‹, which is interdefinable with โŠธ for dualizable agent types: (X โŠธ Y = XโŸ‚ โ…‹ Y, XโŸ‚ โ…‹ Y = XโŸ‚ โŠธ Y = YโŸ‚ โŠธ X).

P โ…‹ Q stands for โ€œa process eventually yielding a P and a process eventually yielding a Q running in parallelโ€. By virtue of being commutative and associative this binary connective can be also generalized to a quantifier โ…‹(tฬฒ : T) Q(t), where T is a value type.

An agent of the type w : โ…‹(tฬฒ : T) Q(t) in general requires the program to process all branches (as many as there are values t in T) with each branch consuming exactly one agent wโ‚œ : Q(q). โ…‹(tฬฒ : T) Q(t) represents a โ€œpoolโ€ where agents are running simultaneously, concurrently and interacting with each other. If one of the agents has type Y = A โŠธ B, it means that it currently awaits a value of the type A and not running, which can lead to another agent X in the โ€œpoolโ€ stuck. The handler of X โ…‹ Y knows how to process both actors independently, so it will feed a value of the type A into the actor Y, so that X can go on, and eventually its result will be also processed by the handler of X โ…‹ Y.

In type theory there is still one typeformer we have not mentioned so far: the equality. As with all other typeformers, this one will split into two duals: independence and eventual consistency.

Independence of agents x : X and y : Y is precisely what allows one to perform a multi-way join, that is handle (x โˆฅ y) : X โ…‹ Y by awaiting only x, only y, both, or โ€œwhatever comes firstโ€. In the last case you have to show that no race condition can occur or that it does not affect the result, which is the eventual consistency.

NB: Eventual consistency can play a role even in the intuitionistic setting when working with Turing-complete partial functions. Sometimes one can define two two partial functions on the Cauchy real numbers f g : โ„ -> Partial(T) with f being guaranteed to eventually yield a result for x >= 0 and g being guaranteed to yield a result for x <= 0. If they can be shown to agree in the case both yield a result, one can join them into a single function.

ยง Agents and Objects

Agents may be nondetermenistic and communicate with each other. For example, a particular request to one remote database yield different results if we previously requested another remote database, because they could have communicated behind the scenes. Agents that are independent from any other agents (that is, self-enclosed) are called objects. The property of being independent can be formulated within type theory. For objects, the concept of ownership makes sense, so that the โ€œpoolโ€ of agents running in parallel can be seen as a directed acyclic graph.

While all agents that can be constructed are certainly deterministic, in general both agents (think of the agent representing the user of an interactive application) and objects (think of the random number generator) are not required to. While objects are guaranteed not to communicate with each other, they still can be subject to eventual consistency conditions. Some algebraically admissible eventual consistency conditions cannot be ever achieved by deterministic (and thus computationally constructible) objects, but such objects are not impossible. They can be realized as nondetermenistic objects being in a state of quantum entanglement. Entangled objects can satisfy eventual consistency conditions without communicating.

ยง Element Classifier ๐”ฝโ‚ and Superposition Quantifier โ…‹

Subsets of a type T are classified by functions p : T โ†’ ฮฉ, where ฮฉ is the type of all propositions, also known as subobject classifier. In our generalized setting we can have the object type that classifies single elements of other types.

We want to define the object type ๐”ฝโ‚ with the property that in can be only inhabited by two objects 0โ‚ : ๐”ฝโ‚ and 1โ‚ : ๐”ฝโ‚, but no two 1โ‚ objects can ever exist at the same time, while at least one is guaranteed to exist. For an object with such properties the maps f : T โŠธ ๐”ฝโ‚ will exactly correspond to elements of T. As ฮฉ naturally has a structure of Heyting algebra, ๐”ฝโ‚ will naturally have a structure similar to a field, albeit with one element, see [https://en.wikipedia.org/wiki/Field_with_one_element].

That means, for a function v : T โŠธ ๐”ฝโ‚ and a family f : T โ†’ X there will be a pairing v โ‡ƒ f : X, and for each element t : T there will be a function ฮพ(t) : T โŠธ ๐”ฝโ‚, such that ฮพ(t) โ‡ƒ f = f(t).

Imagine that ๐”ฝโ‚ can act on processes by either terminating them (case of 0) or letting them run (case of 1). That is, for each q : ๐”ฝโ‚ and p : P we have qp : qP where the action of q on types is given by (0โ‚)P = ๐Ÿ™, and otherwise qP = P.

Now if we have a process factory f : ฮ (tฬฒ : T) Q(t) and a function v : T โŠธ ๐”ฝโ‚, we pair them to obtain p := โธฎ(tฬฒ : T โ†ฆ (v t)(f t)) : โ…‹(tฬฒ : T) (v t)Q(t).

We can define the following operations on the type ๐”ฝโ‚:

0โ‚ : ?๐”ฝโ‚
(+) : ๐”ฝโ‚ โ…‹ ๐”ฝโ‚ โŠธ ๐”ฝโ‚
(ยท) : ๐”ฝโ‚ โŠ— ๐”ฝโ‚ โŠธ ๐”ฝโ‚

One can show these operations to fulfill axioms of a commutative semiring.

Note that since will be is no rule allowing to introduce 1โ‚ : ๐”ฝโ‚, so it is impossible to form 2 := 1 + 1. The only definable polynomials are sums of distinct variables: To form 2a one would need to be able to write a + a, yet a is a single use variable and cannot be used twice. For the same reason it is impossible to form aยฒ := a ยท a. The element classifier ๐”ฝโ‚ is a field in the sense that every linear equation has a solution. Indeed, it is even an algebraically closed field in the sence that every non-constant polynomial has a solution.

In HOCC, non-dependent elimination motives of quotient inductive types precisely correspond to single-sorted algebraic theories, with quotient inductive type itself representing the initial โ€œsyntacticโ€ model of the theory. $S$-sorted algebraic theories can be described by quotient inductive type families indexed over $S$. Recently we proposed type theories by Reedy-inductive types. By making $S$ a Reedy-inductive type we can accomodate algebraic theories with dependent and possibly infinitary dependent signatures.

We conjecture that the linear counterpart of inductive types would correspond to Partial Algebraic Theories, that it is possible to develop their semantics over an arbitrary generalized field, and specializing to ๐”ฝโ‚ would recover the usual algebraic theories (Hopf algebra over ๐”ฝโ‚ is a group, etc.).

ยง Quantum Quantifiers

The type โ…‹(tฬฒ : T) Q(t) represents a superposition of simultaneous processes? Can we use it to represent superpositions of quantum states? If we somehow could, there will be a map |f> turning functions f : T โ†’ โ„‚ into states |f> : โ…‹(_ : T) ๐”ฝโ‚, and those states can be used to โ€˜probeโ€™ objects of ฯˆ : โ…‹(_ : T) ๐”ฝโ‚. By probing, we force ฯˆ into a new state (either |f> or |-f>) and get a bit value, if it was plus or minus f:

         ฯˆ : โ…‹(_ : T) ๐”ฝโ‚    f : T โ†’ โ„‚
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
 ฯˆ.measure(f) : ฮฃ(tฬฒ : ๐”น) (ff โ†ฆ {ฯˆ | ฯˆ = |f>},
                          tt โ†ฆ {ฯˆ | ฯˆ = |-f>})

If ฯˆ was already equal to |f>, weโ€™ll always land in tht tt branch:

 ฯˆ : โ…‹(tฬฒ : T) Q(t)     p : ฯˆ = |f>
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
    ฯˆ.measure(f) = (tt, |f>)

We have to take into account that quantum objects have non-trivial automorphisms, at least the โ€œinvisibleโ€ complex phase.

An object q : โ„ญ is said to be a linear U(1)-torsor, if itโ€™s automorphisms space (q)! = U(1) and it can be acted on by elements of U(1) = {cฬฒ : โ„‚ | |c| = 1 } associatively:

 q : โ„ญ    c : U(1)
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
     cq : โ„ญ

 q : โ„ญ    b c : U(1)
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
   b(cq) = (bc)q

Quantum objects belonging to the same system are equivariant with respect to simultaneous phase rotations. It means that all quantum objects a, b,.., c belonging to the system share the same object of automorphisms: a! = b! = ยทยทยท = c!, and it has the type a! : โ„ญ.

Quantum objects are precisely the objects with automorphism type being a linear type as well. Weโ€™ll be denoting the types of objects with automorphism object c by แถœI.

Only for objects sharing the same object of automorphisms we can define disjunctive sums and conjunctive products:

 c : โ„ญ    A B : ๐“›แถœ
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
      A โŠ•แถœ B

 c : โ„ญ    A B : ๐“›แถœ
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
     A โŠ—แถœ B

We also have equivariant quantifiers:

 T : ๐’ฐ    c : โ„ญ    t : T โŠข  แถœQ(t) : ๐“›
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
         ฮฃแถœ(tฬฒ : T) แถœQ(t)

 T : ๐’ฐ    c : โ„ญ    t : T โŠข  แถœQ(t) : ๐“›
โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
         โˆ€แถœ(tฬฒ : T) แถœQ(t)

Let แถœ๐”น denote the type of qbits. Then โˆ€แถœ(_ : Fin(n)) แถœ๐”น describes a a quantum register of $n$ qubits. For cohesive spaces โˆ€แถœ-quantifiers describe quantum fields over a given space.

Now the automorphism objects are not limited to โ„ญ. For spin-ยฝ particles it should already a torsor โ„ญยฒ of SU(2), but in general it can be at least any complex Lie group. In case of gauge quantum field theories, the automorphism object it in its turn a quantum field of gauge bosons.

The type of qubits can be defined by ๐”นแถœ := โ…‹แถœ(_ : ๐”น) ๐”ฝโ‚, where ๐”ฝโ‚ is the mystical field with one element. If c : โ„ญยฒ, ๐”ผแถœ := โ…‹แถœ(_ : โ„ยณ) ๐”ฝโ‚ is the state space of a spin-ยฝ particle on a 3d space. It might turn out to be possible to define states of particles (and ultimately also fields) on noncommutative spacetimes, which would allow to use a linear type as the bound in โ…‹ (and, dually, alsoฮ ) quantifiers, greatly improveing our understanding of the quantum field theory. The analogy between ๐”ฝโ‚ classifying elements of a value type T โŠธ ๐”ฝโ‚ and โ„‚ classifying states of a *-algebra ๐’œ โŠธ โ„‚ might shed some light on the possiblity of linearly dependent linear types.

See. http://boole.stanford.edu/pub/ql.pdf, https://www.cl.cam.ac.uk/~mpf23/papers/Types/diff.pdf, https://ncatlab.org/nlab/files/BPSLinear.pdf, https://math.ucr.edu/home/baez/bsz_new.pdf