@@ -256,23 +256,13 @@ public CelVerificationResult verifyEquivalence(
256256 switch (result .outcome ) {
257257 case EXACT_MATCH :
258258 return CelVerificationResult .failed (
259- "Equivalence violation detected." ,
260- getCounterexampleString (
261- ctx ,
262- translator .getTypeSystem (),
263- result .model ,
264- /* isApproximate= */ false ,
265- /* isCounterexample= */ true ));
259+ "Equivalence violation detected." , extractWitness (ctx , translator , result .model ));
266260 case APPROXIMATE_MATCH :
267261 return CelVerificationResult .inconclusive (
268262 "Inconclusive: a divergence may exist, but it depends on approximations, missing"
269263 + " theories, or loop bounds." ,
270- getCounterexampleString (
271- ctx ,
272- translator .getTypeSystem (),
273- result .model ,
274- /* isApproximate= */ true ,
275- /* isCounterexample= */ true ));
264+ extractWitness (ctx , translator , result .model ),
265+ /* isCounterexample= */ true );
276266 case TRUNCATED :
277267 return CelVerificationResult .inconclusive (
278268 "Inconclusive: expressions are equivalent within the current loop unroll limit, but"
@@ -343,22 +333,13 @@ CelVerificationResult verifyImplication(
343333 case EXACT_MATCH :
344334 return CelVerificationResult .failed (
345335 String .format ("%s violation detected." , subjectName ),
346- getCounterexampleString (
347- ctx ,
348- translator .getTypeSystem (),
349- result .model ,
350- /* isApproximate= */ false ,
351- /* isCounterexample= */ true ));
336+ extractWitness (ctx , translator , result .model ));
352337 case APPROXIMATE_MATCH :
353338 return CelVerificationResult .inconclusive (
354339 "Inconclusive: a counterexample may exist, but it depends on approximations, missing"
355340 + " theories, or loop bounds." ,
356- getCounterexampleString (
357- ctx ,
358- translator .getTypeSystem (),
359- result .model ,
360- /* isApproximate= */ true ,
361- /* isCounterexample= */ true ));
341+ extractWitness (ctx , translator , result .model ),
342+ /* isCounterexample= */ true );
362343 case TRUNCATED :
363344 return CelVerificationResult .inconclusive (
364345 String .format (
@@ -403,23 +384,10 @@ private CelVerificationResult checkSatisfiability(
403384
404385 switch (result .outcome ) {
405386 case EXACT_MATCH :
387+ CelWitness witness = extractWitness (ctx , translator , result .model );
406388 return searchForCounterexample
407- ? CelVerificationResult .failed (
408- "Condition is not always true." ,
409- getCounterexampleString (
410- ctx ,
411- translator .getTypeSystem (),
412- result .model ,
413- /* isApproximate= */ false ,
414- /* isCounterexample= */ true ))
415- : CelVerificationResult .verified (
416- "Condition is satisfiable."
417- + getCounterexampleString (
418- ctx ,
419- translator .getTypeSystem (),
420- result .model ,
421- /* isApproximate= */ false ,
422- /* isCounterexample= */ false ));
389+ ? CelVerificationResult .failed ("Condition is not always true." , witness )
390+ : CelVerificationResult .verified ("Condition is satisfiable." , witness );
423391
424392 case APPROXIMATE_MATCH :
425393 String prefix =
@@ -430,12 +398,8 @@ private CelVerificationResult checkSatisfiability(
430398 + " approximations, missing theories, or loop bounds." ;
431399 return CelVerificationResult .inconclusive (
432400 prefix ,
433- getCounterexampleString (
434- ctx ,
435- translator .getTypeSystem (),
436- result .model ,
437- /* isApproximate= */ true ,
438- /* isCounterexample= */ searchForCounterexample ));
401+ extractWitness (ctx , translator , result .model ),
402+ /* isCounterexample= */ searchForCounterexample );
439403
440404 case TRUNCATED :
441405 return CelVerificationResult .inconclusive (
@@ -538,14 +502,13 @@ private CelAstToZ3Translator newTranslator(Context ctx, boolean parameterizeUnkn
538502 parameterizeUnknowns );
539503 }
540504
541- private static String getCounterexampleString (
542- Context ctx ,
543- CelZ3TypeSystem typeSystem ,
544- Model model ,
545- boolean isApproximate ,
546- boolean isCounterexample ) {
505+ private CelWitness extractWitness (Context ctx , CelAstToZ3Translator translator , Model model ) {
547506 return CelZ3CounterexampleGenerator .generate (
548- ctx , typeSystem , model , isApproximate , isCounterexample );
507+ ctx ,
508+ translator .getTypeSystem (),
509+ model ,
510+ comprehensionUnrollLimit ,
511+ translator .getInputVariables ());
549512 }
550513
551514 private enum SolverOutcome {
0 commit comments