Content deleted Content added
Nils Grimsmo (talk | contribs) m removed "compu-stub" |
Cosmoose312 (talk | contribs) No edit summary Tags: Mobile edit Mobile app edit Android app edit |
||
(44 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 15 ⟶ 24:
initially
n = 20 #
<
assign
<#
end
===
Program
declare
n: integer,
A,R: array [0..n-1] of integer
initially
n =
<
A[i], R[i] = rand() % 100, i > assign
<
#
▲ A[i], A[i+1] := A[i+1], A[i] if A[i] > A[i+1] > >
end
===Floyd–Warshall algorithm===
Using the [[
Program
declare
n,
initially
n =
<|| i,j : 0 <=
D[i,j] = rand() % 100 >
assign
<||
k := k + 1 if
▲ if A[S[s+a]+sa] <= A[S[s+b]] ||
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.
▲ <|| sb : 0 < sb < N[s+b] ::
Program shortestpath2
declare
n: integer,
D: array [0..n-1,
initially
▲ N[s/2] := N[s] + N[s+1] > ||
n = 10 #
D[i,j] = rand() % 10 >
▲ end
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:
|