
\section{Transcription Adhoc Examples to C++}

\subsection*{Example}

\begin{verbatim}
  array float a {3 : x} ;
  array float b [x] ;
  ...
  at({3 : x})
    a = 23 + b ;
\end{verbatim}
translates to
\begin{verbatim}
  Embed a_e(3, x, NULL) ;
  Array<0, float> a(&a_e) ;
  Array<1, float> b(x) ;
  ...
  if(a_e)
    a() = 23 + b(a_e) ;
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  range x(12 # t_1) ;
  array float u [x] ;
  range x_internal(10 : base 1 : x) ;
  array float n [x_internal] ;
  array float p [x_internal] ;
  ...
  for( ; ; ) {
    remap(n, u [10 : base 0]) ;
    remap(p, u [10 : base 2]) ;
    where(x_internal)
      u = 0.5 * (n + p) ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  Range x(12, t_1) ;
  Array<1, float> u(x) ;
  Range x_internal(10, 1, 1, x) ;
  Array<1, float> n(x_internal) ;
  Array<1, float> p(x_internal) ;
  ...
  for( ; ; ) {
    remap(n, Section<1, float> (u, Range(10, 0, 1, x))) ;
    remap(p, Section<1, float> (u, Range(10, 2, 1, x))) ;
    for(x_internal.first() ; x_internal ; x_internal++)
      u(x_internal) = 0.5 * (n(x_internal) + p(x_internal)) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  range x_a(n # t_1) ;
  range y_a(n # t_2) ;
  array float a [x_a, y_a] ;

  range x_b(n * n # s_1) ;
  array float b [x_b] ;

  ...

  array int subscript [x_a, y_a] ;
  where(x_a)
    where(y_a)
      subscript = n * x_a + y_a ;
  scatter(a, b, subscript) ;
\end{verbatim}
translates to
\begin{verbatim}
  Range x_a(n, t_1) ;
  Range y_a(n, t_2) ;
  Array<2, float> a(x_a, y_a) ;

  Range x_b(n * n, s_1) ;
  Array<1, float> b(x_b) ;
 
  ...

  Array<2, int> subscript(x_a, y_a) ;
  for(x_a.first() ; x_a ; x_a++)
    for(y_a.first() ; y_a ; y_a++)
      subscript(x_a, y_a) = x_a() + y_a() ;
  scatter(a, b, subscript) ;
\end{verbatim}

\subsection*{Example}

\begin{verbatim}
  array float c [x_a] ;

  ...

  gather(c, a, x_a, x_a) ;
\end{verbatim}
translates to
\begin{verbatim}
  Array<1, float> c(x_a) ;

  ...

  gather(c, a, Index(x_a), Index(x_a))
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  range x_d(m :: x_a) ;
  range y_d(m :: y_a) ;
  array float d [x_d, y_d] ;

  ...

  array int subscript2 [x_d, y_d] ;
  where(x_d)
    where(y_d)
      subscript2 = x_d + y_d ;
  gather(d, a, x_d, subscript2) ;
\end{verbatim}
translates to
\begin{verbatim}
  Range x_d(m, 0, 1, x_a) ;
  Range y_d(m, 0, 1, y_a) ;
  Array<2, float> d(x_d, y_d) ;

  ...

  Array<2, int> subscript2(x_d, y_d) ;
  for(x_d.first() ; x_d ; x_d++)
    for(y_d.first() ; y_d ; y_d++)
      subscript2(x_d, y_d) = x_d() + y_d() ;
  gather(d, a, Index(x_d), subscript2) ;
\end{verbatim}
This doesn't add much new, but the equivalent code
\begin{verbatim}
  where(x_d)
    remap(d, a [m : base x_d : y_a]) ;
\end{verbatim}
translates to
\begin{verbatim}
  for(x_d.first() ; x_d ; x_d++)
    remap(Section<1, float>(d, x_d, y_d),
          Section<1, float>(a, x_d, Range(m, x_d(), 1, y_a)) ;
\end{verbatim}
which is slightly more interesting.


\subsection*{Example}

\begin{verbatim}
  alloc float a [_ # t_1, _ # t_2] ;
  ...
  a <- new array float [10 # t_1, 10 # t_2] ;
  ...
  delete a ;
\end{verbatim}
translates to
\begin{verbatim}
  Array<2, float>* a ;
  ...
  a = new Array<2, float>(Range(10, t_1), Range(10, t_2)) ;
  ...
  delete a ;
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  range x_b(10 # t_1) ;
  range y_b(10 # t_2) ;

  array float b [x_b, y_b] [_ # t_3] ;

  ...

  where(x_b)
    where(y_b)
      b <- new array float [x_b + y_b # t_3] ;

  ...

  where(x_b)
    where(y_b)
      delete b ;
\end{verbatim}
translates to
\begin{verbatim}
  Range x_b(10, t_1) ;
  Range y_b(10, t_2) ;

  Aggregate<2> b(x_b, y_b) ;

  ...

  for(x_b.first() ; x_b ; x_b++)
    for(y_b.first() ; y_b ; y_b++)
      b(x_b, y_b) =
        new Array<1, float>(Range(x_b() + y_b(), t_3)) ;
    
  ...

  for(x_b.last() ; x_b ; x_b--)
    for(y_b.last() ; y_b ; y_b--)
      delete b(x_b, y_b) ;
\end{verbatim}
Notice the use of the \verb$last$ and $--$ iterators in the
deallocation loops.  This isn't an essential refinement at this stage,
but respecting the a first-allocated-last-deallocated regime where
possible allows temporary variables to be allocated on a stack.

\subsection*{Example}

\begin{verbatim}
  procs p(4, 4) ;
  dimension p_1(p.dim(1)) ;
  dimension p_2(p.dim(2)) ;

  range i_a(16 #blk p_1) ;
  range j_a(16 #blk p_2) ;
  array int a [i_a, j_a] ;
  
  range i_b(8 : base 5 : j_a) ;
  range j_b(4 : base 3 step 3 : i_a) ;
  array int b [i_b, j_b] ;

  array int c {2 : i_b} ;
\end{verbatim}
translates to
\begin{verbatim}
  Procs p(2, 4, 4) ;
  Dimension p_1(p.dim(1)) ;
  Dimension p_2(p.dim(2)) ;

  Range i_a(16, p_1, blk) ;
  Range j_a(16, p_2, blk) ;
  Array<2, int> a(i_a, j_a) ;
  
  Range i_b(8, 5, 1, j_a) ;
  Range j_b(4, 3, 3, i_a) ;
  Array<2, int> b(i_b, j_b) ;

  Embed c_e(2, i_b, NULL) ;
  Array<0, int> c(&c_e) ;
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  procs p(4, 4) ;

  array int a [16 #blk p.dim(1), 16 #blk p.dim(2)] ;
  
  array int b [8 : base 5 : a.rng(2),
               4 : base 3 step 3 : a.rng(1)] ;

  array int c {2 : b.rng(1)} ;
\end{verbatim}
translates to
\begin{verbatim}
  Procs p(2, 4, 4) ;

  Array<2, int> a(Range(16, p.dim(1), blk),
                  Range(16, p.dim(2), blk)) ;
  
  Array<2, int> b(Range(8, 5, 1, a.rng(2)),
                  Range(4, 3, 3, a.rng(1))) ;

  Embed c_e(2, b.rng(1), NULL) ;
  Array<0, int> c(&c_e) ;
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void mingo(array float m [100 #blk def2d_1, 100 #blk def2d_1])
    ...
  }
\end{verbatim}
translates to
\begin{verbatim}
  void mingo(Array<2, float>& m)
    ...
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void _mingo(array float _m _ [100 :: _, 100 :: _]) {
    array float m [100 # def2d_1, 100 # def2d_2] ;
    remap(m, _m) ;
    ...
    remap(_m, m) ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  void _mingo(Array<2, float>& _m) {
    Array<2, float> m(Range(100, def2d_1), Range(100, def2d_2)) ;
    remap(m, _m) ;
    ...
    remap(_m, m) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void rickard(array float r [100 #blk def2d_1,
                              100 #blk def2d_2])
    ...
  }
\end{verbatim}
translates to
\begin{verbatim}
  void rickard(Array<2, float>& r)
    ...
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void jaffee(array float j _ [100 :: _, 100 :: _]) {
    ...
  }
\end{verbatim}
translates to
\begin{verbatim}
  void jaffee(Array<2, float>& j) {
    ...
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void melvin(
      array float axolotl [_ : _ #blk def2d_1,
                           _ : _ #blk def2d_2],
      array float poiuytt [axolotl.rng(1), axolotl.rng(2)]) {
    ...
  }
\end{verbatim}
translates to
\begin{verbatim}
  void melvin(Array<2, float>& axolotl, Array<2, float>& poiuytt) {
    ...
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  array float dough [100 #blk(10) def1d_1] ;
  probate(dough [9 : base 6 step 2]) ;
  ...
  void probate(array float bread _ [9 :: _]) {
    ...
\end{verbatim}
translates to
\begin{verbatim}
  Array<1, float> dough(Range(100, def1d_1, blk, 10)) ;
  probate(Section<1, float>(dough,
                            Range(9, 6, 2, dough.rng(1)))) ;
  ...
  void probate(Array<1, float>& bread) {
    ...
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  procs dance_floor(16) ;
  range i_frug(128 #blk dance_floor.dim(1)) ;
  array int frug [i_frug] ;
  array int twist [i_frug] ;
  _terpsichore(frug [13 : step 3], twist [13 : step 3]) ;

  void _terpsichore(array int _foxtrot _ [_],
                    array int tango _ [_]) {
    dimension def0d_1 of def0d ;
    array int foxtrot [_foxtrot.rng(1).size() #* def0d_1] ;
    remap(foxtrot, _foxtrot) ;
    ...
    remap(_foxtrot, foxtrot) ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  Procs dance_floor(1, 16) ;
  Range i_frug(128, dance_floor.dim(1), blk) ;
  Array<1, int> frug(i_frug) ;
  Array<1, int> twist(i_frug) ;
  _terpsichore(Section<1, int>(frug,
                               Range(13, 0, 3, frug.rng(1))),
               Section<1, int>(twist,
                               Range(13, 0, 3, frug.rng(1))))

  void _terpsichore(Array<1, int>& _foxtrot,
                    Array<1, int>& tango) {
    Dimension def0d_1(def0d) ;
    Array<1, int> foxtrot(Range(_foxtrot.rng(1).size(),
                                def0d_1)) ;
    remap(foxtrot, _foxtrot) ;
    ...
    remap(_foxtrot, foxtrot) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  procs dance_floor(16) ;
  range i_frug(128 #blk dance_floor.dim(1)) ;
  array int frug [i_frug] ;
  array int twist [i_frug] ;
  {
    dimension def0d_1 of def0d ;
    array int temp1 [13 #* def0d_1] ;
    range i_temp2(13 : step 3 : i_frug) ;
    remap(temp1, frug [i_temp2]) ;
    terpsichore(temp1, twist [i_temp2]) ;
    remap(frug [i_temp2], temp1) ;
  }

  void terpsichore(array int foxtrot [_ #* _],
                   array int tango _ [_]) {
    ...
  }
\end{verbatim}
translates to
\begin{verbatim}
  Procs dance_floor(1, 16) ;
  Range i_frug(128, dance_floor.dim(1), blk) ;
  Array<1, int> frug(i_frug) ;
  Array<1, int> twist(i_frug) ;
  {
    Dimension def0d_1(def0d) ;
    Array<1, int> temp1(Range(13, def0d_1)) ;
    Range i_temp2(13, 0, step 3, i_frug) ;
    remap(temp1, Section<1, int>(frug, i_temp2)) ;
    terpsichore(temp1, Section<1, int>(twist, i_temp2)) ;
    remap(Section<1, int>(frug, i_temp2), temp1) ;
  }

  void terpsichore(Array<1, int>& foxtrot,
                   Array<1, int>& tango) {
    ...
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  procs dance_floor(16) ;
  range i_frug(128 # dance_floor.dim(1)) ;
  array int frug [i_frug] ;
  array int twist [i_frug] ;
  {
    int temp1 [13] ;
    range i_temp2(13 : step 3 : i_frug) ;
    broadcast(temp1, frug [i_temp2]) ;
    terpsichore(temp1, twist [i_temp2]) ;
    where(i_temp2)
      frug = temp1 [i_temp2] ;
  }

  void terpsichore(int foxtrot [], array int tango _ [_]) {
    ...
  }
\end{verbatim}
translates to
\begin{verbatim}
  Procs dance_floor(1, 16) ;
  Range i_frug(128, dance_floor.dim(1), blk) ;
  Array<1, int> frug(i_frug) ;
  Array<1, int> twist(i_frug) ;
  {
    int temp1 [13] ;
    Range i_temp2(13, 0, 3, i_frug) ;
    broadcast(temp1, Section<1, int>(frug, i_temp2)) ;
    terpsichore(temp1, Section<1, int>(twist, i_temp2)) ;
    for(i_temp2.first() ; i_temp2 ; i_temp2++)
      frug(i_temp2) = temp1 [i_temp2()] ;
  }

  void terpsichore(int foxtrot [], Array<1, int>& tango) {
    ...
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  dimension def1d_2 of def1d ;
  array float troggs [1024 #blk def1d_1, 473 #* def1d_2] ;
  for (j = 0; j < 473 ; j++)
    wild_thing(troggs [ : , j]) ;
  ...

  void wild_thing(array float groovy [_ #blk def1d_2])
    ...
\end{verbatim}
translates to
\begin{verbatim}
  Dimension def1d_2(def1d) ;
  Array<2, float> troggs(Range(1024, def1d_1, blk),
                         Range(473, def1d_2)) ;
  for (j = 0; j < 473 ; j++)
    wild_thing(Section<1, float>(troggs, trogg.rng(1),
                                     Embed(j, trogg.rng(2)))) ;
  ...

  void wild_thing(Array<1, float>& groovy)
    ...
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void grunge(array float plunge _ [1000 :: _],
              array float sponge plunge.emb() [plunge.rng(1)]) {
    ...

  array float 
     squeegee fiji.emb() [2000 : base 1 step 2 : fiji.rng(1)] ;
  grunge(fiji [1000 : base 2001 step 2],
                             squeegee [1000 : base 1000]) ;
  ...
\end{verbatim}
translates to
\begin{verbatim}
  void grunge(Array<1, float> plunge, Array<1, float> sponge) {
    ...

  Array<1, float> squeegee(fiji.emb(),
                           Range(2000, 1, 2, fiji.rng(1))) ;
  grunge(Section<1, float>(fiji.emb(), fiji,
                           Range(1000, 2001, 2, fiji.rng(1)))
         Section<1, float>(squeegee.emb(), squeegee,
                     Range(1000, 1000, 1, squegee.rng(1)))) ;
  ...
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void copy(array int u _ [_], array int v u.emb() [u.rng(1)]) {
    ...
  }

  void foo(int n, array int foo_res [n #cyc def1d_1]) {
    ...
  }

  array int a [10 #blk def1d_1] ;
  ...
  {
    array int temp1 [10 #cyc def1d_1] ;
    foo(10, temp1) ;
    array int temp2 [10 #blk def1d_1] ;
    remap(temp2, temp1) ;
    copy(a, temp2) ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  void copy(Array<1, int>& u, Array<1, int>& v) {
    ...
  }

  void foo(int n, Array<1, int>& foo_res) {
    ...
  }

  Array<1, int> a(Range(10 def1d_1, blk)) ;
  ...
  {
    Array<1, int> temp1(Range(10, def1d_1, cyc)) ;
    foo(10, temp1) ;
    Array<1, int> temp2(Range(10, def1d_1, blk)) ;
    remap(temp2, temp1) ;
    copy(a, temp2) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  int sum(array int u _ [_]) {
    ...
  }

  array int a [10 #blk def2d_1, 10 #blk def2d_2] ;
  array int v [5 #blk def1d_1] ;
  int x ;
  ...
  {
    embed e_t1(4 : a.rng(1)) ;
    range i_t1(f(x) - 1 : base 1 step 2 : a.rng(2)) ;
    array int temp1 e_t1 [i_t1] ;
    remap(temp1, v [g(x) - 1 : base 1]) ;
    at({e_t1})
      where(i_t1)
        temp1 += a ;
    x = sum(temp1) ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  int sum(Array<1, int>& u) {
    ...
  }

  Array<2, int> a(Range(10, def2d_1, blk),
                  Range(10, def2d_2, blk)) ;
  Array<1, int> v(Range(5, def1d_1, blk)) ;
  int x ;
  ...
  {
    Embed e_t1(4, a.rng(1), NULL) ;
    Range i_t1(f(x) - 1, 1, 2, a.rng(2)) ;
    Array<1, int> temp1(&e_t1, i_t1) ;
    remap(temp1,
      Section<1, int>(v, Range(g(x) - 1, 1, 1, v.rng(1)))) ;
    if(e_t1)
      for(i_t1.first() ; i_t1 ; i_t1++)
        temp1(i_t1) += a(e_t1, i_t1) ;
    x = sum(temp1) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  array int a [100 #blk p_1, 10 #blk p_2] ;
  array int b [10 #blk q_1, 10 #blk q_2] ;
  ...
  {
    range x_t1(b.rng(1)) ;
    range y_t1(b.rng(2)) ;
    dimension q_3 of q ;
    range z_t1 (20 #* q_3) ;
    array int temp1 [x_t1, y_t1, z_t1] ;

    // temp1 [x, y, z] = b [x, y] + f(y + 1, z + 1)
    where(x_t1)
      where(y_t1)
        where(z_t1)
          temp1 = b + f(y_t1 + 1, z_t1 + 1) ;

    array int temp2 [x_t1, y_t1] ;

    // temp2 [x, y] = 10 * x + y
    where(x_t1)
      where(y_t1)
        temp2 = 10 * x_t1 + y_t1

    // a [10 * x + y, z] = temp1 [x, y, z]
    scatter(temp1, a, temp2, z_t1) ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  Array<2, int> a(Range(100, p_1, blk), Range(10, p_2, blk)) ;
  Array<2, int> b(Range(10, q_1, blk), Range(10, q_2, blk)) ;
  ...
  {
    Range x_t1(b.rng(1)) ;
    Range y_t1(b.rng(2)) ;
    Dimension q_3(q) ;
    Range z_t1(20, q_3) ;
    Array<3, int> temp1(x_t1, y_t1, z_t1) ;

    // temp1 [x, y, z] = b [x, y] + f(y + 1, z + 1)
    for(x_t1.first() ; x_t1 ; x_t1++)
      for(y_t1.first() ; y_t1 ; y_t1++)
        for(z_t1.first() ; z_t1 ; z_t1++)
          temp1(x_t1, y_t1, z_t1) = b(x_t1, y_t1) +
                                    f(y_t1() + 1, z_t1() + 1) ;

    Array<2, int> temp2(x_t1, y_t1) ;

    // temp2 [x, y] = 10 * x + y
    for(x_t1.first() ; x_t1 ; x_t1++)
      for(y_t1.first() ; y_t1 ; y_t1++)
        temp2(x_t1, y_t1) = 10 * x_t1() + y_t1()

    // a [10 * x + y, z] = temp1 [x, y, z]
    scatter(temp1, a, temp2, Index(z_t1)) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  where(y_t1)
    where(z_t1) {
      int temp2 = f(y_t1 + 1, z_t1 + 1) ;
      where(x_t1)
        temp1 = b + temp2 ;
    }
\end{verbatim}
translates to
\begin{verbatim}
  for(y_t1.first() ; y_t1 ; y_t1++)
    for(z_t1.first() ; z_t1 ; z_t1++) {
      int temp2 = f(y_t1() + 1, z_t1() + 1) ;
      for(x_t1.first() ; x_t1 ; x_t1++)
        temp1(x_t1, y_t1, z_t1) = b(x_t1, y_t1) + temp2 ;
    }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  {
    array int temp2 [y_t1, z_t1] ;

    // temp2 [y, z] = f(y + 1, z + 1)
    where(y_t1) {
      range z_t3(20 #blk q_1) ;
      array int temp3 [z_t3] ;

      // temp3 [z] = f (y + 1, z + 1)
      where(z_t3)
        temp3 = f(y_t1 + 1, z_t3 + 1) ;

      remap(temp2, temp3) ;
    }

    // temp1 [x, y, z] = b [x, y] + temp2 [y, z]
    where(y_t1)
      where(z_t1)
        where(x_t1)
          temp1 = b + temp2 ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  {
    Array<2, int> temp2(y_t1, z_t1) ;

    // temp2 [y, z] = f(y + 1, z + 1)
    for(y_t1.first() ; y_t1 ; y_t1++) {
      Range z_t3(20, q_1, blk) ;
      Array<1, int> temp3(z_t3) ;

      // temp3 [z] = f (y + 1, z + 1)
      for(z_t3.first() ; z_t3 ; z_t3++)
        temp3(z_t3) = f(y_t1() + 1, z_t3() + 1) ;

      remap(Section<1, int>(temp2, y_t1, z_t1), temp3) ;
    }

    // temp1 [x, y, z] = b [x, y] + temp2 [y, z]
    for(x_t1.first() ; x_t1 ; x_t1++)
      for(y_t1.first() ; y_t1 ; y_t1++)
        for(z_t1.first() ; z_t1 ; z_t1++)
          temp1(x_t1, y_t1, z_t1) =
                   b(x_t1, y_t1) + temp2(x_t1, z_t1) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void foo(int n, dimension d, alloc int foo_res [_ #* d]) {
    foo_res <- new array int [f(n) #* d] ;
    ...
  }

  array int a [10 #blk p_1, 10 #blk p_2] ;
  array int b [10 #blk q_1] ;
  ...
  {
    range x_t1(b.rng(1)) ;
    dimension q_2 of q ;
    array int temp1 [x_t1] [_ #* q_2] ;

    // temp1 [x] [i] = b [foo(x) [i]]
    {
      array int temp2 [x_t1] [_ #* q_2] ;

      // temp2 [x] [i] = foo(x) [i]
      where(x_t1)
        foo(x_t1 + 1, q_2, temp2) ;

      // temp1 [x] [i] = b [temp2 [x] [i]]
      gather(temp1, b, temp2) ;

      where(x_t1)
        delete temp2 ;
    }

    array int temp2 [x_t1] [_ #* q_2] ;

    // temp2 [x] [i] = i
    where(x_t1)
      temp2 <- new range(f(x_t1 + 1) #* q_2) ;

    // a [x, temp2 [x] [i]] = temp1 [x] [i]
    scatter(temp1, a, x_t1, temp2) ;

    where(x_t1)
      delete temp2 ;

    where(x_t1)
      delete temp1 ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  void foo(int n, Dimension& d, Array<1, int>* foo_res) {
    foo_res = new Array<1, int>(f(n), d) ;
    ...
  }

  Array<2, int> a(Range(10, p_1, blk), Range(10, p_2, blk)) ;
  Array<1, int> b(Range(10, q_1, blk) ;
  ...
  {
    Range x_t1(b.rng(1)) ;
    Dimension q_2(q) ;
    Aggregate<1> temp1(x_t1) ;

    // temp1 [x] [i] = b [foo(x) [i]]
    {
      Aggregate<1> temp2(x_t1) ;

      // temp2 [x] [i] = foo(x) [i]
      for(x_t1.first() ; x_t1 ; x_t1++)
        foo(x_t1() + 1, q_2, temp2(x_t1)) ;

      // temp1 [x] [i] = b [temp2 [x] [i]]
      gather(temp1, b, temp2) ;

      for(x_t1.last() ; x_t1 ; x_t1--)
        delete temp2(x_t1) ;
    }

    Aggregate<1> temp2(x_t1) ;

    // temp2 [x] [i] = i
    for(x_t1.first() ; x_t1 ; x_t1++)
      temp2(x_t1) = new Index(Range(f(x_t1() + 1), q_2)) ;

    // a [x, temp2 [x] [i]] = temp1 [x] [i]
    scatter(temp1, a, Index(x_t1), temp2) ;

    for(x_t1.last() ; x_t1 ; x_t1--)
      delete temp2(x_t1) ;

    for(x_t1.last() ; x_t1 ; x_t1--)
      delete temp1(x_t1) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  array int a [10 #blk p_1, 10 #blk p_2] ;
  array int b [10 #blk q_1, 10 #blk q_2] ;
  ...
  {
    range x_t1(b.rng(1)) ;
    dimension q_3 of q ;
    array int temp1 [x_t1] [_ #* q_3] ;
    array int temp2 [x_t1] [_ #* q_3] ;

    // temp1 [x] [y] = b [x, y] + f(x) + g(y)
    // temp2 [x] [y] = y
    {
      where(x_t1) {
        range y_t1(x_t1 + 1 #* q_3) ;

        temp1 <- new array int [y_t1] ;

        array int temp2 [yt_1] ;

        // temp2 [y] = b [x, y]
        remap(temp2, b [y_t1]) ;

        // temp3 = f(x + 1)
        int temp3 = f(x_t1 + 1) ;

        where(y_t1)
          temp1 = b + temp3 + g(y_t1 + 1) ;

        temp2 <- new range(y_t1) ;
      }
    }

    // a [x] [y] = temp1 [x] [y]
    scatter(temp1, a, x_t1, temp2) ;

    where(x_t1) {
      delete temp2 ;
      delete temp1 ;
    }
  }
\end{verbatim}
translates to
\begin{verbatim}
  Array<2, int> a(Range(10, p_1, blk), Range(10, p_2, blk)) ;
  Array<2, int> b(Range(10, q_1, blk), Range(10, q_2, blk)) ;
  ...
  {
    Range x_t1(b.rng(1)) ;
    Dimension q_3(q) ;
    Aggregate<1> temp1(x_t1) ;
    Aggregate<1> temp2(x_t1) ;

    // temp1 [x] [y] = b [x, y] + f(x) + g(y)
    // temp2 [x] [y] = y
    {
      for(x_t1.first() ; x_t1 ; x_t1++) {
        Range y_t1(x_t1() + 1, q_3) ;

        temp1(x_t1) = new Array<1, int>(y_t1) ;

        Array<1, int> temp2(yt_1) ;

        // temp2 [y] = b [x, y]
        remap(temp2, Section<1, int>(b, x_t1, y_t1)) ;

        // temp3 = f(x + 1)
        int temp3 = f(x_t1() + 1) ;

        for(y_t1.first() ; y_t1 ; y_t1)
          temp1(x_t1)(y_t1) =
                       b(x_t1, y_t1) + temp3 + g(y_t1() + 1) ;

        temp2 = new Index(y_t1) ;
      }
    }

    // a [x] [y] = temp1 [x] [y]
    scatter(temp1, a, Index(x_t1), temp2) ;

    for(x_t1.last() ; x_t1 ; x_t1--) {
      delete temp2(x_t1) ;
      delete temp1(x_t1) ;
    }
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  array int a [10 #blk p_1, 10 #blk p_2] ;
  array int b [10 #blk q_1, 10 #blk q_2] ;
  ...
  {
    range x_t1(b.rng(1)) ;
    range y_t1(b.rng(2)) ;
    array int temp1 [x_t1, y_t1] ;

    // temp1 [x] [y] = b [x, y] + f(x) + g(y)
    {
      array int temp2 [y_t1] ;

      // temp2 [y] = g(y + 1)
      where(y_t1)
        temp2 = g(y_t1 + 1) ;

      where(x_t1) {

        // temp3 = f(x + 1)
        int temp3 = f(x_t1 + 1) ;

        // temp1 [x, y] = b [x, y] + temp3 + temp2 [y] ;
        where(y_t1)
          if(y_t1 <= x_t1)
            temp1 = b + temp3 + temp2 ;
      }
    }

    range x_t2(a.rng(1)) ;
    range y_t2(a.rng(2)) ;
    array int temp2 [x_t2, y_t2] ;

    // temp2 [x, y] = temp1 [x, y] 
    remap(temp2, temp1) ;

    // a [x, y] = temp2 [x, y]
    where(x_t2)
      where(y_t2)
        if(y_t2 <= x_t2)
          a = temp2 ;
  }
\end{verbatim}
translates to
\begin{verbatim}
  Array<2, int> a(Range(10, p_1, blk), Range(10, p_2, blk)) ;
  Array<2, int> b(Range(10, q_1, blk), Range(10, q_2, blk)) ;
  ...
  {
    Range x_t1(b.rng(1)) ;
    Range y_t1(b.rng(2)) ;
    Array<2, int> temp1(x_t1, y_t1) ;

    // temp1 [x] [y] = b [x, y] + f(x) + g(y)
    {
      Array<1, int> temp2(y_t1) ;

      // temp2 [y] = g(y + 1)
      for(y_t1.first() ; y_t1 ; y_t1++)
        temp2(y_t1) = g(y_t1() + 1) ;

      for(x_t1.first() ; x_t1 ; x_t1++) {

        // temp3 = f(x + 1)
        int temp3 = f(x_t1() + 1) ;

        // temp1 [x, y] = b [x, y] + temp3 + temp2 [y] ;
        for(y_t1.first() ; y_t1 ; y_t1++)
          if(y_t1() <= x_t1())
            temp1(x_t1, y_t1) =
                        b(x_t1, y_t1) + temp3 + temp2(y_t1) ;
      }
    }

    Range x_t2(a.rng(1)) ;
    Range y_t2(a.rng(2)) ;
    Array<2, int> temp2(x_t2, y_t2) ;

    // temp2 [x, y] = temp1 [x, y] 
    remap(temp2, temp1) ;

    // a [x, y] = temp2 [x, y]
    for(x_t2.first() ; x_t2 ; x_t2++)
      for(y_t2.first() ; y_t2 ; y_t2++)
        if(y_t2() <= x_t2())
          a(x_t2, y_t2) = temp2(x_t2, y_t2) ;
  }
\end{verbatim}


\subsection*{Example}

\begin{verbatim}
  void foo (array int a _ [10 :: _, 10 :: _]) {
    array int b a.emb() [a.rng(2)] ;
    ...
    at(a.emb()) {
      range x(a.rng(1)) ;
      where(x) {
        int temp1 = f(x + 1) ;
        where(a.rng(1))
          a = b + temp1 ;
    }
  }
\end{verbatim}
translates to
\begin{verbatim}
  void foo (Array<2, int>& a) {
    Array<1, int> b(a.emb(), a.rng(2)) ;
    ...
    Embed* e = a.emb() ;
    while(*e)
      if(e = e.next())
        ;
      else {
        Range x(a.rng(1)) ;
        Range y(a.rng(2)))
        for(x.first() ; x ; x++) {
          int temp1 = f(x() + 1) ;
          for(y.first() ; y ; y++) {
            a(x, y) = b(y) + temp1 ;
        }
        break ;
      }
  }
\end{verbatim}

