GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/delta_rational.cpp Lines: 26 52 50.0 %
Date: 2021-09-29 Branches: 37 210 17.6 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Tim King, Morgan Deters
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * [[ Add one-line brief description here ]]
14
 *
15
 * [[ Add lengthier description here ]]
16
 * \todo document this file
17
 */
18
19
#include "theory/arith/delta_rational.h"
20
21
#include <sstream>
22
23
using namespace std;
24
25
namespace cvc5 {
26
27
std::ostream& operator<<(std::ostream& os, const DeltaRational& dq){
28
  return os << "(" << dq.getNoninfinitesimalPart()
29
            << "," << dq.getInfinitesimalPart() << ")";
30
}
31
32
33
std::string DeltaRational::toString() const {
34
  return "(" + getNoninfinitesimalPart().toString() + "," +
35
    getInfinitesimalPart().toString() + ")";
36
}
37
38
199106
void DeltaRational::seperatingDelta(Rational& res, const DeltaRational& a, const DeltaRational& b){
39
199106
  Assert(res.sgn() > 0);
40
41
199106
  int cmp = a.cmp(b);
42
199106
  if(cmp != 0){
43
199106
    bool aLeqB = cmp < 0;
44
45
199106
    const DeltaRational& min = aLeqB ? a : b;
46
199106
    const DeltaRational& max = aLeqB ? b : a;
47
48
199106
    const Rational& pinf = min.getInfinitesimalPart();
49
199106
    const Rational& cinf = max.getInfinitesimalPart();
50
51
199106
    const Rational& pmaj = min.getNoninfinitesimalPart();
52
199106
    const Rational& cmaj = max.getNoninfinitesimalPart();
53
54
199106
    if(pmaj == cmaj){
55
4122
      Assert(pinf < cinf);
56
      // any value of delta preserves the order
57
194984
    }else if(pinf == cinf){
58
185113
      Assert(pmaj < cmaj);
59
      // any value of delta preserves the order
60
    }else{
61
9871
      Assert(pinf != cinf && pmaj != cmaj);
62
19742
      Rational denDiffAbs = (cinf - pinf).abs();
63
64
19742
      Rational numDiff = (cmaj - pmaj);
65
9871
      Assert(numDiff.sgn() >= 0);
66
9871
      Assert(denDiffAbs.sgn() > 0);
67
19742
      Rational ratio = numDiff / denDiffAbs;
68
9871
      Assert(ratio.sgn() > 0);
69
70
9871
      if(ratio < res){
71
2083
        res = ratio;
72
      }
73
    }
74
  }
75
199106
}
76
77
DeltaRationalException::DeltaRationalException(const char* op,
78
                                               const DeltaRational& a,
79
                                               const DeltaRational& b)
80
{
81
  std::stringstream ss;
82
  ss << "Operation [" << op << "] between DeltaRational values ";
83
  ss << a << " and " << b << " is not a DeltaRational.";
84
  setMessage(ss.str());
85
}
86
87
DeltaRationalException::~DeltaRationalException() {}
88
Integer DeltaRational::euclidianDivideQuotient(const DeltaRational& y) const
89
{
90
  if(isIntegral() && y.isIntegral()){
91
    Integer ti = floor();
92
    Integer yi = y.floor();
93
    return ti.euclidianDivideQuotient(yi);
94
  }else{
95
    throw DeltaRationalException("euclidianDivideQuotient", *this, y);
96
  }
97
}
98
99
Integer DeltaRational::euclidianDivideRemainder(const DeltaRational& y) const
100
{
101
  if(isIntegral() && y.isIntegral()){
102
    Integer ti = floor();
103
    Integer yi = y.floor();
104
    return ti.euclidianDivideRemainder(yi);
105
  }else{
106
    throw DeltaRationalException("euclidianDivideRemainder", *this, y);
107
  }
108
}
109
110
22746
}  // namespace cvc5