mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Add support for compact string representation in the RCF API
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
		
							parent
							
								
									6c35e08e43
								
							
						
					
					
						commit
						742f2b07dd
					
				
					 5 changed files with 18 additions and 12 deletions
				
			
		| 
						 | 
					@ -268,13 +268,13 @@ extern "C" {
 | 
				
			||||||
        Z3_CATCH_RETURN(Z3_FALSE);
 | 
					        Z3_CATCH_RETURN(Z3_FALSE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a) {
 | 
					    Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a, Z3_bool compact) {
 | 
				
			||||||
        Z3_TRY;
 | 
					        Z3_TRY;
 | 
				
			||||||
        LOG_Z3_rcf_num_to_string(c, a);
 | 
					        LOG_Z3_rcf_num_to_string(c, a, compact);
 | 
				
			||||||
        RESET_ERROR_CODE();
 | 
					        RESET_ERROR_CODE();
 | 
				
			||||||
        reset_rcf_cancel(c);
 | 
					        reset_rcf_cancel(c);
 | 
				
			||||||
        std::ostringstream buffer;
 | 
					        std::ostringstream buffer;
 | 
				
			||||||
        rcfm(c).display(buffer, to_rcnumeral(a));
 | 
					        rcfm(c).display(buffer, to_rcnumeral(a), compact != 0);
 | 
				
			||||||
        return mk_c(c)->mk_external_string(buffer.str());
 | 
					        return mk_c(c)->mk_external_string(buffer.str());
 | 
				
			||||||
        Z3_CATCH_RETURN("");
 | 
					        Z3_CATCH_RETURN("");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,10 @@ class RCFNum:
 | 
				
			||||||
        return self.ctx.ref()
 | 
					        return self.ctx.ref()
 | 
				
			||||||
                  
 | 
					                  
 | 
				
			||||||
    def __repr__(self):
 | 
					    def __repr__(self):
 | 
				
			||||||
        return Z3_rcf_num_to_string(self.ctx_ref(), self.num)
 | 
					        return Z3_rcf_num_to_string(self.ctx_ref(), self.num, False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def compact_str(self):
 | 
				
			||||||
 | 
					        return Z3_rcf_num_to_string(self.ctx_ref(), self.num, True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __add__(self, other):
 | 
					    def __add__(self, other):
 | 
				
			||||||
        v = _to_rcfnum(other, self.ctx)
 | 
					        v = _to_rcfnum(other, self.ctx)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -173,9 +173,9 @@ extern "C" {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
       \brief Convert the RCF numeral into a string.
 | 
					       \brief Convert the RCF numeral into a string.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       def_API('Z3_rcf_num_to_string', STRING, (_in(CONTEXT), _in(RCF_NUM)))
 | 
					       def_API('Z3_rcf_num_to_string', STRING, (_in(CONTEXT), _in(RCF_NUM), _in(BOOL)))
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
    Z3_string Z3_API Z3_rcf_num_to_string(__in Z3_context c, __in Z3_rcf_num a);
 | 
					    Z3_string Z3_API Z3_rcf_num_to_string(__in Z3_context c, __in Z3_rcf_num a, __in Z3_bool compact);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
       \brief Convert the RCF numeral into a string in decimal notation.
 | 
					       \brief Convert the RCF numeral into a string in decimal notation.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5658,15 +5658,18 @@ namespace realclosure {
 | 
				
			||||||
                display(out, a.m_value, true);
 | 
					                display(out, a.m_value, true);
 | 
				
			||||||
                for (unsigned i = 0; i < c.m_found.size(); i++) {
 | 
					                for (unsigned i = 0; i < c.m_found.size(); i++) {
 | 
				
			||||||
                    algebraic * ext = c.m_found[i];
 | 
					                    algebraic * ext = c.m_found[i];
 | 
				
			||||||
                    out << ", r!" << ext->idx() << " = ";
 | 
					                    out << "; r!" << ext->idx() << " := ";
 | 
				
			||||||
                    display_algebraic_def(out, ext, true);
 | 
					                    display_algebraic_def(out, ext, true);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                out << "]";
 | 
					                out << "]";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void display(std::ostream & out, numeral const & a) const {
 | 
					        void display(std::ostream & out, numeral const & a, bool compact=false) const {
 | 
				
			||||||
            display(out, a.m_value, false);
 | 
					            if (compact)
 | 
				
			||||||
 | 
					                display_compact(out, a);
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                display(out, a.m_value, false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void display_non_rational_in_decimal(std::ostream & out, numeral const & a, unsigned precision) {
 | 
					        void display_non_rational_in_decimal(std::ostream & out, numeral const & a, unsigned precision) {
 | 
				
			||||||
| 
						 | 
					@ -5927,9 +5930,9 @@ namespace realclosure {
 | 
				
			||||||
        return gt(a, _b);
 | 
					        return gt(a, _b);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void manager::display(std::ostream & out, numeral const & a) const {
 | 
					    void manager::display(std::ostream & out, numeral const & a, bool compact) const {
 | 
				
			||||||
        save_interval_ctx ctx(this);
 | 
					        save_interval_ctx ctx(this);
 | 
				
			||||||
        m_imp->display(out, a);
 | 
					        m_imp->display(out, a, compact);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void manager::display_decimal(std::ostream & out, numeral const & a, unsigned precision) const {
 | 
					    void manager::display_decimal(std::ostream & out, numeral const & a, unsigned precision) const {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -252,7 +252,7 @@ namespace realclosure {
 | 
				
			||||||
        bool ge(numeral const & a, mpq const & b) { return !lt(a, b); }
 | 
					        bool ge(numeral const & a, mpq const & b) { return !lt(a, b); }
 | 
				
			||||||
        bool ge(numeral const & a, mpz const & b) { return !lt(a, b); }
 | 
					        bool ge(numeral const & a, mpz const & b) { return !lt(a, b); }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        void display(std::ostream & out, numeral const & a) const;
 | 
					        void display(std::ostream & out, numeral const & a, bool compact=false) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
           \brief Display a real number in decimal notation.
 | 
					           \brief Display a real number in decimal notation.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue