LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/fp - fp_expand_defs.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 51 54 94.4 %
Date: 2026-01-30 12:59:30 Functions: 4 4 100.0 %
Branches: 32 66 48.5 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Aina Niemetz, Andrew Reynolds
       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                 :            :  * Expand definitions for floating-point arithmetic.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "theory/fp/fp_expand_defs.h"
      17                 :            : 
      18                 :            : #include "expr/skolem_manager.h"
      19                 :            : #include "expr/sort_to_term.h"
      20                 :            : #include "util/floatingpoint.h"
      21                 :            : 
      22                 :            : namespace cvc5::internal {
      23                 :            : namespace theory {
      24                 :            : namespace fp {
      25                 :            : 
      26                 :         12 : Node FpExpandDefs::minMaxUF(TNode node)
      27                 :            : {
      28                 :         12 :   Kind kind = node.getKind();
      29 [ -  + ][ -  - ]:         12 :   Assert(kind == Kind::FLOATINGPOINT_MIN || kind == Kind::FLOATINGPOINT_MAX);
         [ -  + ][ -  - ]
      30                 :            : 
      31                 :         12 :   TypeNode type = node.getType();
      32 [ -  + ][ -  + ]:         12 :   Assert(type.getKind() == Kind::FLOATINGPOINT_TYPE);
                 [ -  - ]
      33                 :            : 
      34                 :            :   return d_nm->mkNode(Kind::APPLY_UF,
      35         [ -  + ]:         24 :                       d_nm->getSkolemManager()->mkSkolemFunction(
      36                 :            :                           kind == Kind::FLOATINGPOINT_MIN
      37         [ -  - ]:          0 :                                   || kind == Kind::FLOATINGPOINT_MIN_TOTAL
      38                 :            :                               ? SkolemId::FP_MIN_ZERO
      39                 :            :                               : SkolemId::FP_MAX_ZERO,
      40                 :         24 :                           {d_nm->mkConst(SortToTerm(type))}),
      41                 :            :                       node[0],
      42                 :         48 :                       node[1]);
      43                 :            : }
      44                 :            : 
      45                 :         29 : Node FpExpandDefs::toUbvSbvUF(TNode node)
      46                 :            : {
      47                 :         29 :   Kind kind = node.getKind();
      48 [ +  + ][ -  + ]:         29 :   Assert(kind == Kind::FLOATINGPOINT_TO_UBV
         [ -  + ][ -  - ]
      49                 :            :          || kind == Kind::FLOATINGPOINT_TO_SBV);
      50                 :            : 
      51                 :         29 :   TypeNode type = node.getType();
      52 [ -  + ][ -  + ]:         29 :   Assert(type.getKind() == Kind::BITVECTOR_TYPE);
                 [ -  - ]
      53                 :            : 
      54                 :            :   return d_nm->mkNode(
      55                 :            :       Kind::APPLY_UF,
      56 [ +  + ][ +  + ]:        174 :       d_nm->getSkolemManager()->mkSkolemFunction(
                 [ -  - ]
      57                 :            :           kind == Kind::FLOATINGPOINT_TO_SBV ? SkolemId::FP_TO_SBV
      58                 :            :                                              : SkolemId::FP_TO_UBV,
      59                 :         58 :           {d_nm->mkConst(SortToTerm(node[1].getType())),
      60                 :        116 :            d_nm->mkConst(SortToTerm(type))}),
      61                 :            :       node[0],
      62                 :        116 :       node[1]);
      63                 :            : }
      64                 :            : 
      65                 :         18 : Node FpExpandDefs::toRealUF(TNode node)
      66                 :            : {
      67 [ -  + ][ -  + ]:         18 :   Assert(node.getKind() == Kind::FLOATINGPOINT_TO_REAL);
                 [ -  - ]
      68                 :         18 :   TypeNode type = node[0].getType();
      69 [ -  + ][ -  + ]:         18 :   Assert(type.getKind() == Kind::FLOATINGPOINT_TYPE);
                 [ -  - ]
      70                 :            : 
      71                 :            :   return d_nm->mkNode(
      72                 :            :       Kind::APPLY_UF,
      73                 :         36 :       d_nm->getSkolemManager()->mkSkolemFunction(
      74                 :         36 :           SkolemId::FP_TO_REAL, {d_nm->mkConst(SortToTerm(type))}),
      75                 :         72 :       node[0]);
      76                 :            : }
      77                 :            : 
      78                 :       2644 : Node FpExpandDefs::expandDefinition(Node node)
      79                 :            : {
      80         [ +  - ]:       5288 :   Trace("fp-expandDefinition")
      81                 :       2644 :       << "FpExpandDefs::expandDefinition(): " << node << std::endl;
      82                 :            : 
      83                 :       5288 :   Node res = node;
      84                 :       2644 :   Kind kind = node.getKind();
      85         [ +  + ]:       2644 :   if (kind == Kind::FLOATINGPOINT_MIN)
      86                 :            :   {
      87                 :         24 :     res = d_nm->mkNode(
      88                 :         36 :         Kind::FLOATINGPOINT_MIN_TOTAL, node[0], node[1], minMaxUF(node));
      89                 :            :   }
      90         [ -  + ]:       2632 :   else if (kind == Kind::FLOATINGPOINT_MAX)
      91                 :            :   {
      92                 :          0 :     res = d_nm->mkNode(
      93                 :          0 :         Kind::FLOATINGPOINT_MAX_TOTAL, node[0], node[1], minMaxUF(node));
      94                 :            :   }
      95         [ +  + ]:       2632 :   else if (kind == Kind::FLOATINGPOINT_TO_UBV)
      96                 :            :   {
      97                 :         72 :     res = d_nm->mkNode(  // Kind::FLOATINGPOINT_TO_UBV_TOTAL,
      98                 :         36 :         d_nm->mkConst(FloatingPointToUBVTotal(
      99                 :         36 :             node.getOperator().getConst<FloatingPointToUBV>())),
     100                 :            :         node[0],
     101                 :            :         node[1],
     102                 :         54 :         toUbvSbvUF(node));
     103                 :            :   }
     104         [ +  + ]:       2614 :   else if (kind == Kind::FLOATINGPOINT_TO_SBV)
     105                 :            :   {
     106                 :         44 :     res = d_nm->mkNode(  // Kind::FLOATINGPOINT_TO_SBV_TOTAL,
     107                 :         22 :         d_nm->mkConst(FloatingPointToSBVTotal(
     108                 :         22 :             node.getOperator().getConst<FloatingPointToSBV>())),
     109                 :            :         node[0],
     110                 :            :         node[1],
     111                 :         33 :         toUbvSbvUF(node));
     112                 :            :   }
     113         [ +  + ]:       2603 :   else if (kind == Kind::FLOATINGPOINT_TO_REAL)
     114                 :            :   {
     115                 :         36 :     res = d_nm->mkNode(
     116                 :         54 :         Kind::FLOATINGPOINT_TO_REAL_TOTAL, node[0], toRealUF(node));
     117                 :            :   }
     118                 :            : 
     119         [ +  + ]:       2644 :   if (res != node)
     120                 :            :   {
     121         [ +  - ]:        118 :     Trace("fp-expandDefinition") << "FpExpandDefs::expandDefinition(): " << node
     122                 :         59 :                                  << " rewritten to " << res << std::endl;
     123                 :         59 :     return res;
     124                 :            :   }
     125                 :       2585 :   return Node::null();
     126                 :            : }
     127                 :            : 
     128                 :            : }  // namespace fp
     129                 :            : }  // namespace theory
     130                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14