diff --git a/src/test/should_work/packEnvTest/contractForElementSelectionInArray/packageTableau.lus b/src/test/should_work/packEnvTest/contractForElementSelectionInArray/packageTableau.lus index 8a0dd77eab31428925d15ee60b75cd492c29814d..84730f71fe5c7949229c7ec3fd3fc3cd579a3bf3 100644 --- a/src/test/should_work/packEnvTest/contractForElementSelectionInArray/packageTableau.lus +++ b/src/test/should_work/packEnvTest/contractForElementSelectionInArray/packageTableau.lus @@ -6,7 +6,7 @@ needs node _isGreaterThan_(e1 : elementType; e2 : elementType) returns (isgreaterthan : bool); provides - type arrayType; + type arrayType = elementType^size; node selectElementOfRank_inArray_(rankToSelect : int;array : arrayType) returns (elementSelected : elementType); node getMaximumIn_(array : arrayType) returns (maximumElement : elementType); node getRank_ofMaximumIn_(array : arrayType) returns (rankOfMaximumElement : int); @@ -37,10 +37,10 @@ provides body ---node _isGreaterOrEqualTo_(e1, e2 : elementType) returns (ge : bool); ---let --- ge = _isGreaterThan_(e1, e2) or _isEqualTo_(e1, e2); ---tel +node _isGreaterOrEqualTo_(e1, e2 : elementType) returns (ge : bool); +let + ge = _isGreaterThan_(e1, e2) or _isEqualTo_(e1, e2); +tel -- Type fourni: le type "tableau d'éléments elementType" type arrayType = elementType^size; @@ -268,7 +268,7 @@ var -- localTab : tableau calculé (trié un cran plus loin) let -- je commence par trouver le minimum à partir de accu_in.CurrentRank - accu_out_min = red<<minFromRank, size>>(Sort_accu{MinVal = 0; + accu_out_min = red<<minFromRank, size>>(MinFR_accu{MinVal = 0; MinRank = accu_in.CurrentRank; RankFrom = accu_in.CurrentRank; Rank = 0}, @@ -283,7 +283,7 @@ let -- puis j'échange le minimum trouvé et l'élement de rang courant -- (courant dans l'itération de UnarySort) - accu_out_exchange, localTab = map_red<<Exchange_i_j, size>>(Exchange_accu{MinVal = accu_out_min.MinVal; + accu_out_exchange, localTab = fillred<<Exchange_i_j, size>>(Exchange_accu{MinVal = accu_out_min.MinVal; MinRank = accu_out_min.MinRank; RankFrom = accu_out_select.RankToFind; CurrentVal = accu_out_select.Val; diff --git a/src/test/test.res.exp b/src/test/test.res.exp index 1a863289fcc34498eb68b2262fdb2f2d1df181f7..b8088f6d3dc5f3c096136a2b1c9272fcdc7a6815 100644 --- a/src/test/test.res.exp +++ b/src/test/test.res.exp @@ -13150,8 +13150,6 @@ const intArray__size = 10; type intArray__arrayType = int^10; Exported constants: Exported nodes: -*** Error in file "should_work/packEnvTest/contractForElementSelectionInArray/packageTableau.lus", line 215, col 31 to 50, token '_isGreaterOrEqualTo_': unknown node (_isGreaterOrEqualTo_) - node util__igt(i:int; j:int) returns (res:bool); let res = (i > j); @@ -13191,6 +13189,287 @@ let tel -- end of node intArray___isElementOf_ type intArray__forSortingAlgo = intArray::forSortingAlgo {previousElement : int; sortedUpToHere : bool}; +node intArray___isGreaterOrEqualTo_(e1:int; e2:int) returns (ge:bool); +let + ge = (intArray___isGreaterThan_(e1, e2) or intArray___isEqualTo_(e1, e2)); +tel +-- end of node intArray___isGreaterOrEqualTo_ + +node intArray__isLocallyLoselySorted( + acc_in:intArray::forSortingAlgo {previousElement : int; + sortedUpToHere : bool}; + elt:int) +returns ( + acc_out:intArray::forSortingAlgo {previousElement : int; + sortedUpToHere : bool}); +let + acc_out = + forSortingAlgo{previousElement=elt;sortedUpToHere=(intArray___isGreaterOrEqualTo_(elt, + acc_in.previousElement) and acc_in.sortedUpToHere)}; +tel +-- end of node intArray__isLocallyLoselySorted + +node intArray___isLoselySorted( + array:int^10) +returns ( + array_isLoselySorted:bool); +var + result:intArray::forSortingAlgo {previousElement : int; sortedUpToHere : bool}; +let + result = red<<node intArray__isLocallyLoselySorted, const + 10>>(forSortingAlgo{previousElement=array[0];sortedUpToHere=true}, array); + array_isLoselySorted = result.sortedUpToHere; +tel +-- end of node intArray___isLoselySorted +type intArray__Sort_accu = intArray::Sort_accu {CurrentRank : int; Tab : int^10}; +type intArray__Select_accu = intArray::Select_accu {RankToFind : int; CurrentRank : int; Val : int}; +type intArray__MinFR_accu = intArray::MinFR_accu {MinVal : int; MinRank : int; RankFrom : int; Rank : int}; +type intArray__Exchange_accu = intArray::Exchange_accu {MinVal : int; MinRank : int; RankFrom : int; CurrentVal : int; Rank : int}; + +node intArray__minFromRank( + accu_in:intArray::MinFR_accu {MinVal : int; + MinRank : int; + RankFrom : int; + Rank : int}; + TabEltIn:int) +returns ( + accu_out:intArray::MinFR_accu {MinVal : int; + MinRank : int; + RankFrom : int; + Rank : int}); +let + accu_out = MinFR_accu{MinVal= if ((accu_in.Rank <= accu_in.RankFrom)) then + (TabEltIn) else ( if ((accu_in.Rank >= accu_in.RankFrom)) then ( if + ((TabEltIn < accu_in.MinVal)) then (TabEltIn) else (accu_in.MinVal)) else + (accu_in.MinVal));MinRank= if ((accu_in.Rank > accu_in.RankFrom)) then ( if + ((TabEltIn < accu_in.MinVal)) then (accu_in.Rank) else (accu_in.MinRank)) + else (accu_in.MinRank);RankFrom=accu_in.RankFrom;Rank=(accu_in.Rank + 1)}; +tel +-- end of node intArray__minFromRank + +node intArray__select( + accu_in:intArray::Select_accu {RankToFind : int; + CurrentRank : int; + Val : int}; + elt:int) +returns ( + accu_out:intArray::Select_accu {RankToFind : int; + CurrentRank : int; + Val : int}); +let + accu_out = + Select_accu{RankToFind=accu_in.RankToFind;CurrentRank=(accu_in.CurrentRank + + 1);Val= if ((accu_in.RankToFind = accu_in.CurrentRank)) then (elt) else + (accu_in.Val)}; +tel +-- end of node intArray__select + +node intArray__Exchange_i_j( + accu_in:intArray::Exchange_accu {MinVal : int; + MinRank : int; + RankFrom : int; + CurrentVal : int; + Rank : int}; + eltIn:int) +returns ( + accu_out:intArray::Exchange_accu {MinVal : int; + MinRank : int; + RankFrom : int; + CurrentVal : int; + Rank : int}; + eltOut:int); +let + accu_out = + Exchange_accu{MinVal=accu_in.MinVal;MinRank=accu_in.MinRank;RankFrom=accu_in.RankFrom;CurrentVal=accu_in.CurrentVal;Rank=(accu_in.Rank + + 1)}; + eltOut = if ((accu_in.Rank = accu_in.MinRank)) then (accu_in.CurrentVal) + else ( if ((accu_in.Rank = accu_in.RankFrom)) then (accu_in.MinVal) else + (eltIn)); +tel +-- end of node intArray__Exchange_i_j + +node intArray__UnarySort( + accu_in:intArray::Sort_accu {CurrentRank : int; + Tab : int^10}; + eltIn:int) +returns ( + accu_out:intArray::Sort_accu {CurrentRank : int; + Tab : int^10}); +var + accu_out_select:intArray::Select_accu {RankToFind : int; CurrentRank : int; Val : int}; + accu_out_min:intArray::MinFR_accu {MinVal : int; MinRank : int; RankFrom : int; Rank : int}; + accu_out_exchange:intArray::Exchange_accu {MinVal : int; MinRank : int; RankFrom : int; CurrentVal : int; Rank : int}; + localTab:int^10; +let + accu_out_min = red<<node intArray__minFromRank, const + 10>>(MinFR_accu{MinVal=0;MinRank=accu_in.CurrentRank;RankFrom=accu_in.CurrentRank;Rank=0}, + accu_in.Tab); + accu_out_select = red<<node intArray__select, const + 10>>(Select_accu{RankToFind=accu_in.CurrentRank;CurrentRank=0;Val=0}, + accu_in.Tab); + (accu_out_exchange, localTab) = fillred<<node intArray__Exchange_i_j, + const + 10>>(Exchange_accu{MinVal=accu_out_min.MinVal;MinRank=accu_out_min.MinRank;RankFrom=accu_out_select.RankToFind;CurrentVal=accu_out_select.Val;Rank=0}, + accu_in.Tab); + accu_out = Sort_accu{CurrentRank=(accu_in.CurrentRank + 1);Tab=localTab}; +tel +-- end of node intArray__UnarySort +node intArray__sort_(array:int^10) returns (arraySorted:int^10); +var + UnarySort_accu_out:intArray::Sort_accu {CurrentRank : int; Tab : int^10}; +let + UnarySort_accu_out = red<<node intArray__UnarySort, const + 10>>(Sort_accu{CurrentRank=0;Tab=array}, array); + arraySorted = UnarySort_accu_out.Tab; +tel +-- end of node intArray__sort_ +node intArray__selectMax(e1:int; e2:int) returns (e:int); +let + e = if (intArray___isGreaterThan_(e1, e2)) then (e1) else (e2); +tel +-- end of node intArray__selectMax +node intArray__getMaximumIn_(array:int^10) returns (maximumElement:int); +let + maximumElement = red<<node intArray__selectMax, const 10>>(array[0], + array); +tel +-- end of node intArray__getMaximumIn_ +type intArray__iteratedStruct = intArray::iteratedStruct {currentRank : int; rankToSelect : int; elementSelected : int}; + +node intArray__selectOneStage( + acc_in:intArray::iteratedStruct {currentRank : int; + rankToSelect : int; + elementSelected : int}; + currentElt:int) +returns ( + acc_out:intArray::iteratedStruct {currentRank : int; + rankToSelect : int; + elementSelected : int}); +let + acc_out = iteratedStruct{currentRank=(acc_in.currentRank + + 1);rankToSelect=acc_in.rankToSelect;elementSelected= if + ((acc_in.currentRank = acc_in.rankToSelect)) then (currentElt) else + (acc_in.elementSelected)}; +tel +-- end of node intArray__selectOneStage + +node intArray__selectElementOfRank_inArray_( + rankToSelect:int; + array:int^10) +returns ( + elementSelected:int); +var + iterationResult:intArray::iteratedStruct {currentRank : int; rankToSelect : int; elementSelected : int}; +let + iterationResult = red<<node intArray__selectOneStage, const + 10>>(iteratedStruct{currentRank=0;rankToSelect=rankToSelect;elementSelected=array[0]}, + array); + elementSelected = iterationResult.elementSelected; +tel +-- end of node intArray__selectElementOfRank_inArray_ +node intArray__selectMin(e1:int; e2:int) returns (e:int); +let + e = if (intArray___isGreaterThan_(e1, e2)) then (e2) else (e1); +tel +-- end of node intArray__selectMin +node intArray__getMinimumIn_(array:int^10) returns (minimumElement:int); +var + maximum:int; +let + maximum = intArray__getMaximumIn_(array); + minimumElement = red<<node intArray__selectMin, const 10>>(maximum, + array); +tel +-- end of node intArray__getMinimumIn_ +type intArray__currentRank_withMemorizedRank = intArray::currentRank_withMemorizedRank {currentRank : int; rankOfMemorizedVal : int; memorizedVal : int}; + +node intArray__selectMaxRank( + acc_in:intArray::currentRank_withMemorizedRank {currentRank : int; + rankOfMemorizedVal : int; + memorizedVal : int}; + e1:int) +returns ( + acc_out:intArray::currentRank_withMemorizedRank {currentRank : int; + rankOfMemorizedVal : int; + memorizedVal : int}); +let + acc_out = currentRank_withMemorizedRank{currentRank=(acc_in.currentRank + + 1);rankOfMemorizedVal= if (intArray___isGreaterThan_(e1, + acc_in.memorizedVal)) then (acc_in.currentRank) else + (acc_in.rankOfMemorizedVal);memorizedVal= if (intArray___isGreaterThan_(e1, + acc_in.memorizedVal)) then (e1) else (acc_in.memorizedVal)}; +tel +-- end of node intArray__selectMaxRank + +node intArray__getRank_ofMaximumIn_( + array:int^10) +returns ( + rankOfMaximumElement:int); +var + local:intArray::currentRank_withMemorizedRank {currentRank : int; rankOfMemorizedVal : int; memorizedVal : int}; +let + local = red<<node intArray__selectMaxRank, const + 10>>(currentRank_withMemorizedRank{currentRank=0;rankOfMemorizedVal=0;memorizedVal=array[0]}, + array); + rankOfMaximumElement = local.rankOfMemorizedVal; +tel +-- end of node intArray__getRank_ofMaximumIn_ + +node intArray__selectMinRank( + acc_in:intArray::currentRank_withMemorizedRank {currentRank : int; + rankOfMemorizedVal : int; + memorizedVal : int}; + elt:int) +returns ( + acc_out:intArray::currentRank_withMemorizedRank {currentRank : int; + rankOfMemorizedVal : int; + memorizedVal : int}); +let + acc_out = currentRank_withMemorizedRank{currentRank=(acc_in.currentRank + + 1);rankOfMemorizedVal= if (intArray___isEqualTo_(acc_in.memorizedVal, elt)) + then (acc_in.currentRank) else + (acc_in.rankOfMemorizedVal);memorizedVal=acc_in.memorizedVal}; +tel +-- end of node intArray__selectMinRank + +node intArray__getRank_ofMinimumIn_( + array:int^10) +returns ( + rankOfMinimumElement:int); +var + minElement:int; +let + minElement = intArray__getMinimumIn_(array); + rankOfMinimumElement = red<<node intArray__selectMinRank, const + 10>>(currentRank_withMemorizedRank{currentRank=0;rankOfMemorizedVal=0;memorizedVal=minElement}, + array).rankOfMemorizedVal; +tel +-- end of node intArray__getRank_ofMinimumIn_ + * package util + Exported types: + Exported constants: + Exported nodes: + * package main + Exported types: + Exported constants: + Exported nodes: + +node main__main( + a:int^10) +returns ( + tri:int^10; + pos_min:int; + min:int; + pos_max:int; + max:int); +let + min = intArray__getMinimumIn_(a); + pos_min = intArray__getRank_ofMinimumIn_(a); + max = intArray__getMaximumIn_(a); + pos_max = intArray__getRank_ofMaximumIn_(a); + tri = intArray__sort_(a); +tel +-- end of node main__main ---------------------------------------------------------------------- ====> ../lus2lic -vl 3 --compile-all-items should_work/packEnvTest/contractForElementSelectionInArray/noeudsIndependants.lus