LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arith - delta_rational.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 26 54 48.1 %
Date: 2026-02-21 11:58:00 Functions: 1 8 12.5 %
Branches: 25 70 35.7 %

           Branch data     Line data    Source code
       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-2025 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::internal {
      26                 :            : 
      27                 :          0 : std::ostream& operator<<(std::ostream& os, const DeltaRational& dq){
      28                 :          0 :   return os << "(" << dq.getNoninfinitesimalPart()
      29                 :          0 :             << "," << dq.getInfinitesimalPart() << ")";
      30                 :            : }
      31                 :            : 
      32                 :            : 
      33                 :          0 : std::string DeltaRational::toString() const {
      34                 :          0 :   return "(" + getNoninfinitesimalPart().toString() + "," +
      35                 :          0 :     getInfinitesimalPart().toString() + ")";
      36                 :            : }
      37                 :            : 
      38                 :     993794 : void DeltaRational::seperatingDelta(Rational& res, const DeltaRational& a, const DeltaRational& b){
      39 [ -  + ][ -  + ]:     993794 :   Assert(res.sgn() > 0);
                 [ -  - ]
      40                 :            : 
      41                 :     993794 :   int cmp = a.cmp(b);
      42         [ +  - ]:     993794 :   if(cmp != 0){
      43                 :     993794 :     bool aLeqB = cmp < 0;
      44                 :            : 
      45         [ +  - ]:     993794 :     const DeltaRational& min = aLeqB ? a : b;
      46         [ +  - ]:     993794 :     const DeltaRational& max = aLeqB ? b : a;
      47                 :            : 
      48                 :     993794 :     const Rational& pinf = min.getInfinitesimalPart();
      49                 :     993794 :     const Rational& cinf = max.getInfinitesimalPart();
      50                 :            : 
      51                 :     993794 :     const Rational& pmaj = min.getNoninfinitesimalPart();
      52                 :     993794 :     const Rational& cmaj = max.getNoninfinitesimalPart();
      53                 :            : 
      54         [ +  + ]:     993794 :     if(pmaj == cmaj){
      55 [ -  + ][ -  + ]:      32247 :       Assert(pinf < cinf);
                 [ -  - ]
      56                 :            :       // any value of delta preserves the order
      57         [ +  + ]:     961547 :     }else if(pinf == cinf){
      58 [ -  + ][ -  + ]:     905309 :       Assert(pmaj < cmaj);
                 [ -  - ]
      59                 :            :       // any value of delta preserves the order
      60                 :            :     }else{
      61 [ +  - ][ +  - ]:      56238 :       Assert(pinf != cinf && pmaj != cmaj);
         [ -  + ][ -  + ]
                 [ -  - ]
      62                 :      56238 :       Rational denDiffAbs = (cinf - pinf).abs();
      63                 :            : 
      64                 :      56238 :       Rational numDiff = (cmaj - pmaj);
      65 [ -  + ][ -  + ]:      56238 :       Assert(numDiff.sgn() >= 0);
                 [ -  - ]
      66 [ -  + ][ -  + ]:      56238 :       Assert(denDiffAbs.sgn() > 0);
                 [ -  - ]
      67                 :      56238 :       Rational ratio = numDiff / denDiffAbs;
      68 [ -  + ][ -  + ]:      56238 :       Assert(ratio.sgn() > 0);
                 [ -  - ]
      69                 :            : 
      70         [ +  + ]:      56238 :       if(ratio < res){
      71                 :      11028 :         res = ratio;
      72                 :            :       }
      73                 :      56238 :     }
      74                 :            :   }
      75                 :     993794 : }
      76                 :            : 
      77                 :          0 : DeltaRationalException::DeltaRationalException(const char* op,
      78                 :            :                                                const DeltaRational& a,
      79                 :          0 :                                                const DeltaRational& b)
      80                 :            : {
      81                 :          0 :   std::stringstream ss;
      82                 :          0 :   ss << "Operation [" << op << "] between DeltaRational values ";
      83                 :          0 :   ss << a << " and " << b << " is not a DeltaRational.";
      84                 :          0 :   setMessage(ss.str());
      85                 :          0 : }
      86                 :            : 
      87                 :          0 : DeltaRationalException::~DeltaRationalException() {}
      88                 :          0 : Integer DeltaRational::euclidianDivideQuotient(const DeltaRational& y) const
      89                 :            : {
      90 [ -  - ][ -  - ]:          0 :   if(isIntegral() && y.isIntegral()){
                 [ -  - ]
      91                 :          0 :     Integer ti = floor();
      92                 :          0 :     Integer yi = y.floor();
      93                 :          0 :     return ti.euclidianDivideQuotient(yi);
      94                 :          0 :   }else{
      95                 :          0 :     throw DeltaRationalException("euclidianDivideQuotient", *this, y);
      96                 :            :   }
      97                 :            : }
      98                 :            : 
      99                 :          0 : Integer DeltaRational::euclidianDivideRemainder(const DeltaRational& y) const
     100                 :            : {
     101 [ -  - ][ -  - ]:          0 :   if(isIntegral() && y.isIntegral()){
                 [ -  - ]
     102                 :          0 :     Integer ti = floor();
     103                 :          0 :     Integer yi = y.floor();
     104                 :          0 :     return ti.euclidianDivideRemainder(yi);
     105                 :          0 :   }else{
     106                 :          0 :     throw DeltaRationalException("euclidianDivideRemainder", *this, y);
     107                 :            :   }
     108                 :            : }
     109                 :            : 
     110                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14