File: utils.c

package info (click to toggle)
cvc5 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 87,260 kB
  • sloc: cpp: 383,850; java: 12,207; python: 12,090; sh: 5,679; ansic: 4,729; lisp: 763; perl: 208; makefile: 38
file content (80 lines) | stat: -rw-r--r-- 2,383 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/******************************************************************************
 * Top contributors (to current version):
 *   Aina Niemetz
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2025 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * Implementations of utility methods.
 */

#include "utils.h"

#include <stdio.h>
#include <stdlib.h>

/**
 * Get the string version of define-fun command.
 * @param f       The function to print.
 * @param nparams The number of function parameters.
 * @param params  The function parameters.
 * @param body    The function body.
 * @return A string version of define-fun.
 */
void print_define_fun(const Cvc5Term f,
                      size_t nparams,
                      const Cvc5Term params[],
                      const Cvc5Term body)
{
  Cvc5Sort sort = cvc5_term_get_sort(f);
  if (cvc5_sort_is_fun(sort))
  {
    sort = cvc5_sort_fun_get_codomain(sort);
  }
  printf("(define-fun %s (", cvc5_term_to_string(f));
  for (size_t i = 0; i < nparams; i++)
  {
    printf("%s", i > 0 ? " " : "");
    printf("(%s %s)",
           cvc5_term_to_string(params[i]),
           cvc5_sort_to_string(cvc5_term_get_sort(params[i])));
  }
  printf(") %s %s)", cvc5_sort_to_string(sort), cvc5_term_to_string(body));
}

void print_synth_solutions(size_t nterms,
                           const Cvc5Term terms[],
                           const Cvc5Term sols[])
{
  printf("(\n");
  for (size_t i = 0; i < nterms; i++)
  {
    size_t nparams = 0;
    Cvc5Term* params = NULL;
    Cvc5Term body = sols[i];
    if (cvc5_term_get_kind(sols[i]) == CVC5_KIND_LAMBDA)
    {
      Cvc5Term psols = cvc5_term_get_child(sols[i], 0);
      nparams = cvc5_term_get_num_children(psols);
      params = (Cvc5Term*)malloc(nparams * sizeof(Cvc5Term));
      for (size_t k = 0; k < nparams; k++)
      {
        params[k] = cvc5_term_get_child(psols, k);
      }
      body = cvc5_term_get_child(sols[i], 1);
    }
    printf("  ");
    print_define_fun(terms[i], nterms, params, body);
    if (params)
    {
      free(params);
    }
    printf("\n");
  }
  printf(")\n");
}