miaou — le blogv1.0.3

gen_draw.miaou

← Le code · src/outil/miaou/gen_draw.miaou · 25 lignes

(node gen_draw
  (params (mt Mt) (lo Grand) (pas Grand) (haut Grand) (n Nat))
  (returns Gt)
  (intent "n tirages d'un (draw x (range lo hi pas)) : lo + pas × randint(0, haut), chacun un cas d'un seul argument, et l'état d'après")
  (origin "phase 8f6 : les générateurs en miaou, d'après c_entrees de l'outil inter")
  (effects)
  (uses h_entier gr_add gr_mul gr_de_nat)
  (requires
    true)
  (ensures
    true)
  (decreases n)
  (examples
    (ex ((record Mt (mots (list)) (i 0)) (record Grand (neg false) (mots (list 5))) (record Grand (neg false) (mots (list 1))) (record Grand (neg false) (mots (list))) 0)
      (record Gt (args (list)) (mt (record Mt (mots (list)) (i 0))))))
  (equivalence exact)
  (body.high
    (if (eq n 0)
      (record Gt (args (list)) (mt mt))
      (let ((r (h_entier mt (gr_de_nat 0) haut)))
        (let ((suite (gen_draw (get r mt) lo pas haut (sub n 1))))
          (record Gt
            (args (cons (variant W w_suite (els (list (variant W w_ent (g (gr_add lo (gr_mul pas (get r g)))))))) (get suite args)))
            (mt (get suite mt)))))))
  (end node gen_draw))