Content deleted Content added
Nils Grimsmo (talk | contribs) m Removed a section. Minor fixes. |
Cosmoose312 (talk | contribs) No edit summary Tags: Mobile edit Mobile app edit Android app edit |
||
(43 intermediate revisions by 31 users not shown) | |||
Line 1:
{{Short description|Theoretical programming language for describing concurrent computations}}
{{about|the 1988 theoretical language|other uses|Unity (disambiguation)#Software{{!}}Unity § Software}}
{{multiple issues|
{{technical|date=September 2011}}
{{primary sources|date=July 2019}}
}}
'''UNITY''' is a programming language constructed by [[K. Mani Chandy]] and [[Jayadev Misra]] for their book ''Parallel Program Design: A Foundation''. It is a theoretical language which focuses on ''what'', instead of ''where'', ''when'' or ''how''. The language contains no method of [[flow control (data)|flow control]], and program [[statement (programming)|statement]]s run in a [[Nondeterministic programming|nondeterministic]] way until statements cease to cause changes during execution. This allows for programs to run indefinitely, such as auto-pilot or power plant safety systems, as well as programs that would normally terminate (which here converge to a [[Fixed point combinator|fixed point]]).
All statements are assignments, and are separated by <code>#</code>. A statement can consist of multiple assignments, on the form <code>a,b,c := x,y,z</code>, or <code>a := x || b := y || c := z</code>. You can also have a ''quantified statement list'', for example <code><# x,y : 0 < x < y < n :: ''statement''></code>, where x and y are chosen randomly among the values that satisfy the quantification. A ''quantified assignment'' is similar. In <code><|| x,y : 0 < x < y < n :: ''statement'' ><code>, the statement is executed simultaneously for ''all'' <code>x</code> and <code>y</code> satisfying <code>0 > x > y < n</code>.▼
== Description ==
▲All statements are
==Examples==
===
[[
Program
declare
n: integer,
Line 16 ⟶ 24:
initially
n = 20 #
<
assign
<# k : 0 <= k < 2 ::
<|| i : i % 2 = k and 0 <= i < n - 1 ::
A[i], A[i+1] := A[i+1], A[i]
if A[i] > A[i+1] > > end
===
Program
declare
n
A,
initially
n =
assign
<||
R[i] := <
<|| <|| sb : 0 < sb < N[s+b] ::▼
===Floyd–Warshall algorithm===
Using the [[Floyd–Warshall algorithm]] all pairs [[Shortest path problem|shortest path]] algorithm, we include intermediate nodes iteratively, and get <math>\Theta(n)</math> time, using <math>\Theta(n^2)</math> processors and <math>\Theta(n^3)</math> work.
Program shortestpath
S[s/2] := S[s] ||▼
declare
N[s/2] := N[s] + N[s+1] > ||▼
n,k: integer,
initially
▲ end
n = 10 #
k = 0 #
<|| i,j : 0 <= i < n and 0 <= j < n ::
D[i,j] = rand() % 100 >
assign
k := k + 1 if k < n - 1
end
We can do this even faster. The following programs computes all pairs shortest path in <math>\Theta(\log^2 n)</math> time, using <math>\Theta(n^3)</math> processors and <math>\Theta(n^3 \log n)</math> work.
Program shortestpath2
declare
n: integer,
D: array [0..n-1, 0..n-1] of integer
initially
n = 10 #
<|| i,j : 0 <= i < n and 0 <= j < n ::
assign
<|| i,j : 0 <= i < n and 0 <= j < n ::
D[i,j] := min(D[i,j], <min k : 0 <= k < n :: D[i,k] + D[k,j] >) >
end
After round <math>r</math>, <code>D[i,j]</code> contains the length of the shortest path from <math>i</math> to <math>j</math> of length <math>0 \dots r</math>. In the next round, of length <math>0 \dots 2r</math>, and so on.
==References==
* K. Mani Chandy and Jayadev Misra (1988) ''Parallel Program Design: A Foundation''.
[[Category:
|