SIGOURE Benoit sigoure.benoit@lrde.epita.fr writes:
https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog from SIGOURE Benoit sigoure.benoit@lrde.epita.fr
Add the rand() builtin.
- src/lib/xrm/pp/xrm-expression.str: Add boxing for the rand builtin.
- src/str/xrm-to-prism.str: Split xrm-to-prism-desugar in several rules. Add rand(N) and rand(from, to) builtin.
- src/str/ice.str: Add not-implemented() strategy.
- src/str/eval-meta-code.str: Nothing.
- src/syn/xrm/XRM-Expression.sdf: Add the rand builtin.
- src/syn/prism/PRISM-MetaVars.sdf: Add a meta-var.
- src/syn/prism/StrategoPRISM.sdf: Ditto.
- tests/xrm/rand.xpm: New.
- tests/prism/formula.pm: New.
- TODO: Update.
Marvelous, thanks a lot ! Et mes amitiés à ta copine ! ;-)
On 2006-05-26, Michaël Cadilhac michael.cadilhac@lrde.org wrote:
SIGOURE Benoit sigoure.benoit@lrde.epita.fr writes:
https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog from SIGOURE Benoit sigoure.benoit@lrde.epita.fr
Add the rand() builtin.
- src/lib/xrm/pp/xrm-expression.str: Add boxing for the rand builtin.
- src/str/xrm-to-prism.str: Split xrm-to-prism-desugar in several rules. Add rand(N) and rand(from, to) builtin.
- src/str/ice.str: Add not-implemented() strategy.
- src/str/eval-meta-code.str: Nothing.
- src/syn/xrm/XRM-Expression.sdf: Add the rand builtin.
- src/syn/prism/PRISM-MetaVars.sdf: Add a meta-var.
- src/syn/prism/StrategoPRISM.sdf: Ditto.
- tests/xrm/rand.xpm: New.
- tests/prism/formula.pm: New.
- TODO: Update.
Marvelous, thanks a lot ! Et mes amities =E0 ta copine ! ;-)
Hmm y'a un bug dans ce commit :)
rand(low, hi) produit un chiffre aleatoire entre low et high (inclus) donc chaque chiffre a une probabilite de sortir qui est de 1/(high-low+1) et non pas 1/(high-low) comme je l'ai fais ici.
Ce bug est fixed dans ma working copy a la maison, et il viendra avec la revision 42 \o/ la revision magique
en attendant:
Index: src/str/xrm-to-prism.str =================================================================== --- src/str/xrm-to-prism.str (revision 41) +++ src/str/xrm-to-prism.str (working copy) @@ -111,10 +111,8 @@ " arguments must be statically evaluable"]) ; !current-term; debug; <xtc-exit> 4 end - ; <debug> ifrom - ; <debug> ito ; <newname> "__rand" => rand-var - ; !ProbUpdate( Div(Int("1"), Int( <subtS>(ito, ifrom) )) + ; !ProbUpdate( Div(Int("1"), Int( <addS>(<subtS>(ito, ifrom), "1") )) , UpdateList([UpdateElement(IdentifierPrime(rand-var), FIXME())])) ; {| RandUpdateList: for-loop(gen-rand-update-list | ifrom, ito, "1", [])
Tsuna tsuna@lrde.epita.fr writes:
On 2006-05-26, Michaël Cadilhac michael.cadilhac@lrde.org wrote:
SIGOURE Benoit sigoure.benoit@lrde.epita.fr writes:
https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog from SIGOURE Benoit sigoure.benoit@lrde.epita.fr
Add the rand() builtin.
- src/lib/xrm/pp/xrm-expression.str: Add boxing for the rand builtin.
- src/str/xrm-to-prism.str: Split xrm-to-prism-desugar in several rules. Add rand(N) and rand(from, to) builtin.
- src/str/ice.str: Add not-implemented() strategy.
- src/str/eval-meta-code.str: Nothing.
- src/syn/xrm/XRM-Expression.sdf: Add the rand builtin.
- src/syn/prism/PRISM-MetaVars.sdf: Add a meta-var.
- src/syn/prism/StrategoPRISM.sdf: Ditto.
- tests/xrm/rand.xpm: New.
- tests/prism/formula.pm: New.
- TODO: Update.
Marvelous, thanks a lot ! Et mes amities =E0 ta copine ! ;-)
Hmm y'a un bug dans ce commit :)
rand(low, hi) produit un chiffre aleatoire entre low et high (inclus) donc chaque chiffre a une probabilite de sortir qui est de 1/(high-low+1) et non pas 1/(high-low) comme je l'ai fais ici.
Quelques commentaires :
1) Ça ne marche pas parce que AMPC ne fait pas avancer chaque module à chaque tick, mais un au hazard. Il se peut que ton nombre aléatoire ne soit jamais changé.
Plusieurs solutions à ça:
- Synchronisation, mais on a vu que ça posé problème. - Faire a' = rand(N) -> 1/N: a' = 0 + 1/N a' = 1, mais on a vu que ça contraignait beaucoup de choses. - Faire qqc comme ça:
---------------------------------------------------------------------- [] Conditions -> Update & a' = rand(N) & Update; ----------------------------------------------------------------------
devient
---------------------------------------------------------------------- [] Conditions & NewRandom_COUNT -> Update & a' = rand_COUNT & NewRandom_COUNT '= false
module rand_COUNT rand_COUNT : [0..N] init 0; NewRandom_COUNT : bool init false;
[] NewRandom_COUNT = false -> 1/N: (rand_COUNT' = 0 & NewRandom_COUNT' = true) + ... endmodule
----------------------------------------------------------------------
avec COUNT comme tu l'avais géré. Ça te permet d'éviter tous les problèmes de synchro, tous les problèmes d'update dans un rand qui contient des + (...) et ainsi de suite.
2) J'aimerai pouvoir plus parentheser, puisque j'utilise des #define.
3) Si j'ai des valeurs constantes, j'aimerai pouvoir écrire: a = Val1,Val2 puisque tu le permets avec des littéraux.
4) Je veux pouvoir utiliser des nombres négatifs.