Correction to default probability calculation.

More tweaking of the profj grammars

svn: r7032
This commit is contained in:
Kathy Gray 2007-08-06 15:17:19 +00:00
parent aa871e90bd
commit dbe82ab7d7
2 changed files with 25 additions and 17 deletions

View File

@ -391,14 +391,12 @@
#;(when (pair? look-back)
(printf "look-back is a pair~n"))
#;(when (res? look-back)
(printf "lookbac is a res, ~a~n" (fail-type? (res-possible-error look-back))))
(printf "lookback is a res, ~a~n" (fail-type? (res-possible-error look-back))))
(let* ([seq-fail-maker
(lambda (fail)
(let-values ([(kind expected found) (get-fail-info fail)])
(make-sequence-fail
(cond
[(= 0 used) (fail-type-chance fail)]
[else (compute-chance len seen-len used alts (fail-type-chance fail))])
(compute-chance len seen-len used alts (fail-type-chance fail))
(fail-type-src fail)
name used
(+ used (fail-type-may-use fail) next-used)
@ -419,18 +417,20 @@
seq-fail))))]))))
(define (compute-chance expected-length seen-length used-toks num-alts sub-chance)
(let* ([revised-expectation (+ (- used-toks seen-length) expected-length)]
[probability-with-sub (* (/ (add1 used-toks) revised-expectation) (/ 1 num-alts))]
[probability-without-sub (* (/ used-toks revised-expectation) (/ 1 num-alts))]
[expected-sub probability-with-sub]
[expected-no-sub probability-without-sub]
[probability (/ (* expected-sub sub-chance) (+ (* expected-sub sub-chance)
(* expected-no-sub (- 1 sub-chance))))])
#;(printf "compute-chance: args ~a ~a ~a ~a ~a~n"
expected-length seen-length used-toks num-alts sub-chance)
#;(printf "compute-chance: intermediate values: ~a ~a ~a ~a ~a~n"
revised-expectation probability-with-sub probability-without-sub expected-sub expected-no-sub)
probability))
(if (zero? used-toks)
(* (* (/ 1 expected-length) (/ 1 num-alts)) sub-chance)
(let* ([revised-expectation (+ (- used-toks seen-length) expected-length)]
[probability-with-sub (* (/ (add1 used-toks) revised-expectation) (/ 1 num-alts))]
[probability-without-sub (* (/ used-toks revised-expectation) (/ 1 num-alts))]
[expected-sub probability-with-sub]
[expected-no-sub probability-without-sub]
[probability (/ (* expected-sub sub-chance) (+ (* expected-sub sub-chance)
(* expected-no-sub (- 1 sub-chance))))])
#;(printf "compute-chance: args ~a ~a ~a ~a ~a~n"
expected-length seen-length used-toks num-alts sub-chance)
#;(printf "compute-chance: intermediate values: ~a ~a ~a ~a ~a~n"
revised-expectation probability-with-sub probability-without-sub expected-sub expected-no-sub)
probability)))
;greedy-repeat: (list 'a) -> result -> (list 'a) -> result
(define (repeat-greedy sub)

View File

@ -777,7 +777,15 @@
(repeat-greedy (choose (class interface) "class or interface"))))
(define interact
(choose (field (statement-c #t) expression) "interactive program"))
(choose (field
(if-s (block #t) #f)
(return-s #t)
(assignment
(choose (identifier
(sequence (unique-base (repeat unique-end) field-access-end) id))
"assignee") EQUAL)
(block #t)
expression) "interactive program"))
)