@@ -255,23 +255,13 @@ public CelVerificationResult verifyEquivalence(
255255 switch (result .outcome ) {
256256 case EXACT_MATCH :
257257 return CelVerificationResult .failed (
258- "Equivalence violation detected." ,
259- getCounterexampleString (
260- ctx ,
261- translator .getTypeSystem (),
262- result .model ,
263- /* isApproximate= */ false ,
264- /* isCounterexample= */ true ));
258+ "Equivalence violation detected." , extractWitness (ctx , translator , result .model ));
265259 case APPROXIMATE_MATCH :
266260 return CelVerificationResult .inconclusive (
267261 "Inconclusive: a divergence may exist, but it depends on approximations, missing"
268262 + " theories, or loop bounds." ,
269- getCounterexampleString (
270- ctx ,
271- translator .getTypeSystem (),
272- result .model ,
273- /* isApproximate= */ true ,
274- /* isCounterexample= */ true ));
263+ extractWitness (ctx , translator , result .model ),
264+ /* isCounterexample= */ true );
275265 case TRUNCATED :
276266 return CelVerificationResult .inconclusive (
277267 "Inconclusive: expressions are equivalent within the current loop unroll limit, but"
@@ -342,22 +332,13 @@ CelVerificationResult verifyImplication(
342332 case EXACT_MATCH :
343333 return CelVerificationResult .failed (
344334 String .format ("%s violation detected." , subjectName ),
345- getCounterexampleString (
346- ctx ,
347- translator .getTypeSystem (),
348- result .model ,
349- /* isApproximate= */ false ,
350- /* isCounterexample= */ true ));
335+ extractWitness (ctx , translator , result .model ));
351336 case APPROXIMATE_MATCH :
352337 return CelVerificationResult .inconclusive (
353338 "Inconclusive: a counterexample may exist, but it depends on approximations, missing"
354339 + " theories, or loop bounds." ,
355- getCounterexampleString (
356- ctx ,
357- translator .getTypeSystem (),
358- result .model ,
359- /* isApproximate= */ true ,
360- /* isCounterexample= */ true ));
340+ extractWitness (ctx , translator , result .model ),
341+ /* isCounterexample= */ true );
361342 case TRUNCATED :
362343 return CelVerificationResult .inconclusive (
363344 String .format (
@@ -402,23 +383,10 @@ private CelVerificationResult checkSatisfiability(
402383
403384 switch (result .outcome ) {
404385 case EXACT_MATCH :
386+ CelWitness witness = extractWitness (ctx , translator , result .model );
405387 return searchForCounterexample
406- ? CelVerificationResult .failed (
407- "Condition is not always true." ,
408- getCounterexampleString (
409- ctx ,
410- translator .getTypeSystem (),
411- result .model ,
412- /* isApproximate= */ false ,
413- /* isCounterexample= */ true ))
414- : CelVerificationResult .verified (
415- "Condition is satisfiable."
416- + getCounterexampleString (
417- ctx ,
418- translator .getTypeSystem (),
419- result .model ,
420- /* isApproximate= */ false ,
421- /* isCounterexample= */ false ));
388+ ? CelVerificationResult .failed ("Condition is not always true." , witness )
389+ : CelVerificationResult .verified ("Condition is satisfiable." , witness );
422390
423391 case APPROXIMATE_MATCH :
424392 String prefix =
@@ -429,12 +397,8 @@ private CelVerificationResult checkSatisfiability(
429397 + " approximations, missing theories, or loop bounds." ;
430398 return CelVerificationResult .inconclusive (
431399 prefix ,
432- getCounterexampleString (
433- ctx ,
434- translator .getTypeSystem (),
435- result .model ,
436- /* isApproximate= */ true ,
437- /* isCounterexample= */ searchForCounterexample ));
400+ extractWitness (ctx , translator , result .model ),
401+ /* isCounterexample= */ searchForCounterexample );
438402
439403 case TRUNCATED :
440404 return CelVerificationResult .inconclusive (
@@ -537,14 +501,13 @@ private CelAstToZ3Translator newTranslator(Context ctx, boolean parameterizeUnkn
537501 parameterizeUnknowns );
538502 }
539503
540- private static String getCounterexampleString (
541- Context ctx ,
542- CelZ3TypeSystem typeSystem ,
543- Model model ,
544- boolean isApproximate ,
545- boolean isCounterexample ) {
504+ private CelWitness extractWitness (Context ctx , CelAstToZ3Translator translator , Model model ) {
546505 return CelZ3CounterexampleGenerator .generate (
547- ctx , typeSystem , model , isApproximate , isCounterexample );
506+ ctx ,
507+ translator .getTypeSystem (),
508+ model ,
509+ comprehensionUnrollLimit ,
510+ translator .getInputVariables ());
548511 }
549512
550513 private enum SolverOutcome {
0 commit comments