@@ -17,31 +17,18 @@ pub fn forall_inst(
17
17
18
18
assert_num_args ( args, bindings. len ( ) ) ?;
19
19
20
- // Since the bindings and arguments may not be in the same order, we collect the bindings into
21
- // a hash set, and remove each binding from it as we find the associated argument
22
- let mut bindings: IndexSet < _ > = bindings. iter ( ) . cloned ( ) . collect ( ) ;
23
- let substitution: IndexMap < _ , _ > = args
20
+ // iterate over the bindings and arguments simultaneously, building the substitution
21
+ let substitution: IndexMap < _ , _ > = bindings
24
22
. iter ( )
25
- . map ( |arg| {
26
- let ( arg_name, arg_value) = arg. as_assign ( ) ?;
27
- let arg_sort = pool. sort ( arg_value) ;
28
- rassert ! (
29
- bindings. remove( & ( arg_name. clone( ) , arg_sort. clone( ) ) ) ,
30
- QuantifierError :: NoBindingMatchesArg ( arg_name. clone( ) )
31
- ) ;
32
-
33
- let ident_term = ( arg_name. clone ( ) , arg_sort) . into ( ) ;
34
- Ok ( ( pool. add ( ident_term) , arg_value. clone ( ) ) )
23
+ . zip ( args)
24
+ . map ( |( ( var_name, sort) , value) | {
25
+ assert_eq ( sort, & pool. sort ( value) ) ?;
26
+ let var = pool. add ( Term :: new_var ( var_name, sort. clone ( ) ) ) ;
27
+ Ok ( ( var. clone ( ) , value. clone ( ) ) )
35
28
} )
36
29
. collect :: < Result < _ , CheckerError > > ( ) ?;
37
30
let mut substitution = Substitution :: new ( pool, substitution) ?;
38
31
39
- // All bindings were accounted for in the arguments
40
- rassert ! (
41
- bindings. is_empty( ) ,
42
- QuantifierError :: NoArgGivenForBinding ( bindings. iter( ) . next( ) . unwrap( ) . 0 . clone( ) )
43
- ) ;
44
-
45
32
// Equalities may be reordered, and the application of the substitution might rename bound
46
33
// variables, so we need to compare for alpha-equivalence here
47
34
let expected = substitution. apply ( pool, original) ;
@@ -325,47 +312,47 @@ mod tests {
325
312
" ,
326
313
"Simple working examples" {
327
314
"(step t1 (cl (or (not (forall ((p Bool)) p)) q))
328
- :rule forall_inst :args ((:= p q) ))" : true ,
315
+ :rule forall_inst :args (q ))" : true ,
329
316
330
317
"(step t1 (cl (or (not (forall ((x Real) (y Real)) (= x y))) (= a b)))
331
- :rule forall_inst :args ((:= x a) (:= y b) ))" : true ,
318
+ :rule forall_inst :args (a b ))" : true ,
332
319
333
320
"(step t1 (cl (or (not (forall ((x Real)) (= x a))) (= a a)))
334
- :rule forall_inst :args ((:= x a) ))" : true ,
321
+ :rule forall_inst :args (a ))" : true ,
335
322
336
323
"(step t1 (cl (or (not (forall ((p Bool)) p)) (ite q (= a b) (and (= a 0.0) true))))
337
- :rule forall_inst :args ((:= p ( ite q (= a b) (and (= a 0.0) true) ))))" : true ,
324
+ :rule forall_inst :args ((ite q (= a b) (and (= a 0.0) true))))" : true ,
338
325
}
339
326
"Equalities may be flipped" {
340
327
"(step t1 (cl (or (not (forall ((x Real) (y Real)) (and (= x y) (= 1 0))))
341
- (and (= b a) (= 1 0)))) :rule forall_inst :args ((:= x a) (:= y b) ))" : true ,
328
+ (and (= b a) (= 1 0)))) :rule forall_inst :args (a b ))" : true ,
342
329
}
343
330
"Bound variables may be renamed by substitution" {
344
331
// The variable shadowing makes it so the substitution applied by Carcara renames p
345
332
"(step t1 (cl (or
346
333
(not (forall ((p Bool) (r Bool)) (and p (forall ((p Bool)) p))))
347
334
(and q (forall ((p Bool)) p))
348
- )) :rule forall_inst :args ((:= p q) (:= r q) ))" : true ,
335
+ )) :rule forall_inst :args (q q ))" : true ,
349
336
}
350
337
"Argument is not in quantifier bindings" {
351
338
"(step t1 (cl (or (not (forall ((x Real)) (= x a))) (= b 0.0)))
352
- :rule forall_inst :args ((:= x b) (:= a 0.0) ))" : false ,
339
+ :rule forall_inst :args (b 0.0))" : false ,
353
340
}
354
341
"Binding has no associated substitution" {
355
342
"(step t1 (cl (or (not (forall ((x Real) (y Real)) (= x x))) (= a a)))
356
- :rule forall_inst :args ((:= x a) ))" : false ,
343
+ :rule forall_inst :args (a ))" : false ,
357
344
}
358
345
"Substitution was not applied" {
359
346
"(step t1 (cl (or (not (forall ((x Real) (y Real)) (= x y))) (= x b)))
360
- :rule forall_inst :args ((:= x a) (:= y b) ))" : false ,
347
+ :rule forall_inst :args (a b ))" : false ,
361
348
}
362
349
"Applied substitution was not passed as argument" {
363
350
"(step t1 (cl (or (not (forall ((x Real) (y Real)) (= x y))) (= a b)))
364
- :rule forall_inst :args ((:= x a) ))" : false ,
351
+ :rule forall_inst :args (a ))" : false ,
365
352
}
366
353
"Wrong type of rule argument" {
367
354
"(step t1 (cl (or (not (forall ((x Real) (y Real)) (= x y))) (= a b)))
368
- :rule forall_inst :args ((: = x a) b))" : false ,
355
+ :rule forall_inst :args ((= x a) b))" : false ,
369
356
}
370
357
}
371
358
}
0 commit comments