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โ ๐ฝโ.
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.
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.
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:
(q, p) : Q โ P
. In this case the
consumer can and must consume (or return) both q
and p
;w : Q & P
. In this case the consumer
choses which one to take. It either consumes w
by w(ff) : Q
or by w(tt) : P
, but not both,
because w
cannot be used twice.This two binary connectives can be as well generalized to quantifiers where bounded variable is of a value type.
โ(tฬฒ : T) Q(t)
denotes a family of agents (each one has to be consumed exactly once);ฮ (tฬฒ : T) Q(t)
denotes a โfactory thatโ yields one agent of the type Q(t)
when given a t
.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 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.
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.).
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