Changeset 3919

Show
Ignore:
Timestamp:
07/03/09 00:18:48 (5 months ago)
Author:
emoken
Message:

GoGs? for 2D arrays (modified)

Location:
trunk/Library
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/Library/Generator22D.fsi

    r3917 r3919  
    7979rects[\ E, nat b0, nat s0, nat b1, nat s1 \](g : Array2[\E, b0, s0, b1, s1\]) : Rects[\E, b0, s0, b1, s1\] 
    8080 
     81trait AbideWith[\T\] end 
     82 
     83trait SomeMSS2DTuple[\T\] end 
     84 
     85mssBody[\T\](v:T) : SomeMSS2DTuple[\T\]  
     86 
     87object MSS2DReductionAbove[\T\](op, ot) extends { AssociativeReduction[\SomeMSS2DTuple[\T\]\], AbideWith[\MSS2DReductionBeside[\T\]\] } 
     88  getter asString(): String 
     89  simpleJoin(x: SomeMSS2DTuple[\T\], y: SomeMSS2DTuple[\T\]): SomeMSS2DTuple[\T\] 
    8190end 
     91 
     92object MSS2DReductionBeside[\T\](op, ot) extends { AssociativeReduction[\SomeMSS2DTuple[\T\]\], AbideWith[\MSS2DReductionAbove[\T\]\] } 
     93    getter asString(): String  
     94    simpleJoin(x: SomeMSS2DTuple[\T\], y: SomeMSS2DTuple[\T\]): SomeMSS2DTuple[\T\]  
     95end 
     96 
     97end 
  • trunk/Library/Generator22D.fss

    r3917 r3919  
    6868        rowsImpl[\ E \](g).generate[\ R \](r, body) 
    6969  end 
     70 
     71theorems[\R, L1, L2\]() = 
     72<|[\((ActualReduction[\ R, L1 \], ActualReduction[\ R, L2 \], E -> R)->Boolean, (ActualReduction[\ R, L1 \], ActualReduction[\ R, L2 \], E -> R)->R)\] 
     73(fn (r, q, f) => conditionAbiding[\ R, L1, L2 \](r, q, f), fn (r, q, f) => efficientImplAbiding[\ R, L1, L2 \](r, q, f)) 
     74|> 
     75   
     76  (*--- conditions ---*) 
     77  conditionAbiding[\ R, L1, L2 \](q : ActualReduction[\ R, L1 \], r : ActualReduction[\ R, L2 \], f : E -> R) : Boolean = abiding(q, r) 
     78 
     79  (*--- implementation using the abide-tree reduction  *) 
     80  efficientImplAbiding[\ R, L1, L2 \](q : ActualReduction[\ R, L1 \], r : ActualReduction[\ R, L2 \], f : E -> R) = do 
     81 
     82    (* println("Abide!") *) 
     83 
     84    (* we assume that two operators have the same lifting, i.e., L1 = L2 *) 
     85    r.unlift(GeneratorATWrapper(seed()).generateAT[\L1\](q, r, fn a => r.lift(f(a)))) 
     86  end 
     87 
    7088end 
    7189 
     
    93111        colsImpl[\ E \](g).generate[\ R \](r, body) 
    94112  end 
     113 
     114theorems[\R, L1, L2\]() = 
     115<|[\((ActualReduction[\ R, L1 \], ActualReduction[\ R, L2 \], E -> R)->Boolean, (ActualReduction[\ R, L1 \], ActualReduction[\ R, L2 \], E -> R)->R)\] 
     116(fn (r, q, f) => conditionAbiding[\ R, L1, L2 \](r, q, f), fn (r, q, f) => efficientImplAbiding[\ R, L1, L2 \](r, q, f)) 
     117|> 
     118   
     119  (*--- conditions ---*) 
     120  conditionAbiding[\ R, L1, L2 \](q : ActualReduction[\ R, L1 \], r : ActualReduction[\ R, L2 \], f : E -> R) : Boolean = abiding(q, r) 
     121 
     122  (*--- implementation using the abide-tree reduction  *) 
     123  efficientImplAbiding[\ R, L1, L2 \](q : ActualReduction[\ R, L1 \], r : ActualReduction[\ R, L2 \], f : E -> R) = do 
     124 
     125    (* println("Abide!") *) 
     126 
     127    (* we assume that two operators have the same lifting, i.e., L1 = L2 *) 
     128    r.unlift(GeneratorATWrapper(seed()).generateAT[\L1\](r, q, fn a => r.lift(f(a)))) 
     129  end 
     130 
    95131end 
    96132 
     
    330366) : SomeMSS2DTuple[\T\] = MSS2DTuple[\T, s0, s1\](b, n, s, e, w, ne, nw, se, nw, c, r) 
    331367 
    332 object MSS2DReductionAbove[\T\](op, ot) extends { AssociativeReduction[\SomeMSS2DTuple[\T\]\] } 
     368(* annotation for operators with the `abide' property*) 
     369trait AbideWith[\T\] end 
     370 
     371abiding[\R, Q\]( r : R, q : Q ) =  
     372typecase(r, q) of 
     373  (R, AbideWith[\R\]) => true 
     374  else => false 
     375end 
     376 
     377object MSS2DReductionAbove[\T\](op, ot) extends { AssociativeReduction[\SomeMSS2DTuple[\T\]\], AbideWith[\MSS2DReductionBeside[\T\]\] } 
    333378  getter asString(): String = "MSS2DReductionAbove" 
    334379  simpleJoin(x: SomeMSS2DTuple[\T\], y: SomeMSS2DTuple[\T\]): SomeMSS2DTuple[\T\] =  
     
    357402end 
    358403 
    359 object MSS2DReductionBeside[\T\](op, ot) extends { AssociativeReduction[\SomeMSS2DTuple[\T\]\] } 
     404object MSS2DReductionBeside[\T\](op, ot) extends { AssociativeReduction[\SomeMSS2DTuple[\T\]\], AbideWith[\MSS2DReductionAbove[\T\]\] } 
    360405    getter asString(): String = "MSS2DReductionBeside" 
    361406    simpleJoin(x: SomeMSS2DTuple[\T\], y: SomeMSS2DTuple[\T\]): SomeMSS2DTuple[\T\] =