APRONXX  0.9.7
/builddir/build/BUILD/apron-0.9.10/apronxx/apxx_texpr0.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * apxx_texpr0.hh
3  *
4  * APRON Library / C++ class wrappers
5  *
6  * Copyright (C) Antoine Mine' 2007
7  *
8  */
9 /* This file is part of the APRON Library, released under LGPL license
10  with an exception allowing the redistribution of statically linked
11  executables.
12 
13  Please read the COPYING file packaged in the distribution.
14 */
15 
16 #ifndef __APXX_TEXPR0_HH
17 #define __APXX_TEXPR0_HH
18 
19 #include <vector>
20 
21 #include "ap_texpr0.h"
22 #include "ap_linearize.h"
23 
24 #include "apxx_linexpr0.hh"
25 #include "apxx_environment.hh"
26 
27 namespace apron {
28 
29 class abstract0;
30 
31 
33 class dim {
34 
35 public:
36 
37  ap_dim_t d;
38 
40  dim(ap_dim_t d);
41 
46  dim(const environment& e, const var& v);
47 };
48 
49 
50 
52 bool is_unop(ap_texpr_op_t op);
53 
55  bool is_binop(ap_texpr_op_t op);
56 
57 
58 
59 
60 /* ================================= */
61 /* texpr0 */
62 /* ================================= */
63 
64 
92 class texpr0 : public use_malloc {
93 
94 protected:
95 
96  ap_texpr0_t l;
97 
99  texpr0(ap_texpr0_t* x);
100 
102  void init_from(ap_texpr0_t* x);
104 public:
105 
106  class builder;
107  class iterator;
108  class const_iterator;
109 
110 
111  /* constructors */
112  /* ============ */
113 
116 
122  texpr0(const builder& x);
123 
125  texpr0(const texpr0& x);
126 
128  texpr0(const const_iterator& x);
129 
134  texpr0(const linexpr0& l);
135 
136 
141  texpr0(const texpr0& x, const dimchange& d, bool add=true);
144  texpr0(const texpr0& x, const dimperm& d);
145 
147  texpr0(const texpr0& x, ap_dim_t dim, const texpr0& dst);
148 
150 
151 
152  /* destructor */
153  /* ========== */
154 
157 
159  ~texpr0();
160 
162 
163  /* assignment */
164  /* ========== */
165 
168 
170  texpr0& operator=(const texpr0& x);
171 
173  texpr0& operator=(const const_iterator& x);
174 
176  texpr0& operator=(const builder& x);
182  texpr0& operator= (const linexpr0& x);
183 
185 
186 
188  /* iterators */
189  /* ========= */
190 
191 
194 
213  protected:
214 
215  ap_texpr0_t* l;
216 
218  const_iterator(ap_texpr0_t* l);
219 
220  friend class texpr0;
221  friend class tcons0;
222  friend class texpr1;
223  friend class tcons1;
224 
225  public:
226 
227  /* constructors */
228  /* ============ */
229 
232 
234  const_iterator(const texpr0& e);
235 
237  const_iterator(const const_iterator& i);
238 
240 
241 
242  /* access */
243  /* ====== */
244 
247 
248 
254  ap_texpr_discr_t get_discr() const;
255 
260  const coeff& get_coeff() const;
261 
266  ap_dim_t get_dim() const;
267 
274  ap_texpr_op_t get_op() const;
275 
282  ap_texpr_rtype_t get_rtype() const;
283 
289  ap_texpr_rdir_t get_rdir() const;
290 
292 
293 
294  /* traversal */
295  /* ========= */
296 
301  const_iterator& operator=(const const_iterator& i);
302 
307  const_iterator child() const;
308 
314  const_iterator left() const;
315 
321  const_iterator right() const;
322 
324 
326  /* tests, size, dimensions */
327  /* ======================= */
328 
331 
332 
334  bool equal(const texpr0& x) const;
335 
337  bool is_zero() const;
338 
340  size_t depth() const;
343  size_t size() const;
344 
346  ap_dim_t max_dim() const;
349  bool has_dim(ap_dim_t d) const;
350 
354  std::vector<ap_dim_t> dimlist() const;
355 
357  bool is_interval_cst() const;
358 
360  bool is_interval_linear() const;
361 
363  bool is_interval_polynomial() const;
364 
366  bool is_interval_polyfrac() const;
367 
369  bool is_scalar() const;
370 
372 
373 
374  /* print */
375  /* ===== */
376 
379 
384  friend std::ostream& operator<< (std::ostream& os, const const_iterator& s);
385 
387  void print(char** name_of_dim = NULL, FILE* stream=stdout) const;
390 
391 
392  /* C-level compatibility */
393  /* ===================== */
394 
397 
399  ap_texpr0_t* get_ap_texpr0_t();
400 
402  const ap_texpr0_t* get_ap_texpr0_t() const;
403 
405 
406  };
407 
408 
413  class iterator : public const_iterator {
414 
415  protected:
416 
418  iterator(ap_texpr0_t* l);
419 
420  friend class tcons0;
421  friend class texpr1;
422  friend class tcons1;
423 
424  public:
425 
426  /* constructors */
427  /* ============ */
428 
431 
433  iterator(texpr0& e);
434 
436  iterator(const iterator& i);
437 
439 
441  /* substitution */
442  /* ============ */
443 
446 
452  iterator& operator= (const builder& c);
453 
456 
457  /* access */
458  /* ====== */
459 
462 
467  coeff& get_coeff() const;
468 
473  ap_dim_t& get_dim() const;
474 
481  ap_texpr_op_t& get_op() const;
482 
489  ap_texpr_rtype_t& get_rtype() const;
490 
496  ap_texpr_rdir_t& get_rdir() const;
497 
499 
501  /* traversal */
502  /* ========= */
503 
506 
508  iterator& operator=(const iterator& i);
514  iterator child() const;
515 
521  iterator left() const;
522 
528  iterator right() const;
529 
531 
533  /* C-level compatibility */
534  /* ===================== */
535 
538 
540  ap_texpr0_t* get_ap_texpr0_t();
541 
543  const ap_texpr0_t* get_ap_texpr0_t() const;
544 
546 
547  };
548 
549 
551  const_iterator root() const;
552 
554  iterator root();
555 
558 
559 
560  /* builders */
561  /* ======== */
562 
565 
581  class builder : public use_malloc {
582 
583  friend class texpr1;
584 
585  protected:
586 
587  ap_texpr0_t* l;
588 
589 
591  builder& operator= (const builder& x) { assert(0); return *this; }
594  void init_from(ap_texpr0_t* x);
595 
597  builder(ap_texpr0_t* x);
598 
599  public:
600 
601  /* constructors */
602  /* ============ */
603 
606 
608  builder(const builder& x);
609 
611  builder(const const_iterator& x);
612 
614  builder(const texpr0& x);
617  builder(const coeff& x);
618 
620  builder(const scalar& x);
621 
623  builder(const mpq_class& x);
624 
626  builder(mpfr_t x);
629  builder(int x);
630 
632  builder(long x);
633 
635  builder(double x);
636 
638  builder(const frac& x);
639 
641  builder(const interval& x);
642 
644  builder(const scalar& inf, const scalar& sup);
645 
647  builder(const mpq_class& inf, const mpq_class& sup);
648 
650  builder(mpfr_t inf, mpfr_t sup);
653  builder(int inf, int sup);
654 
656  builder(long inf, long sup);
657 
659  builder(double inf, double sup);
660 
662  builder(const frac& inf, const frac& sup);
663 
666 
668  builder(dim d);
671  builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
672 
674  builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
675 
678 
679  /* destructor */
680  /* ========== */
684 
686  ~builder();
687 
690 
691  /* C-level compatibility */
692  /* ===================== */
696 
698  ap_texpr0_t* get_ap_texpr0_t();
699 
701  const ap_texpr0_t* get_ap_texpr0_t() const;
704 
705 
706  /* 'Intelligent' constructors */
707  /* ========================== */
708 
727  friend builder unary(ap_texpr_op_t op, const builder& a,
728  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
729 
745  friend builder binary(ap_texpr_op_t op, const builder& a, const builder& b,
746  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
747 
749  friend builder add(const builder& a, const builder& b,
750  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
751 
753  friend builder sub(const builder& a, const builder& b,
754  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
755 
757  friend builder mul(const builder& a, const builder& b,
758  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
759 
761  friend builder div(const builder& a, const builder& b,
762  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
763 
765  friend builder mod(const builder& a, const builder& b,
766  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
767 
769  friend builder pow(const builder& a, const builder& b,
770  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
771 
773  friend builder neg(const builder& a,
774  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
775 
777  friend builder cast(const builder& a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
778 
780  friend builder floor(const builder& a);
781 
783  friend builder ceil(const builder& a);
784 
786  friend builder trunc(const builder& a);
787 
789  friend builder sqrt(const builder& a,
790  ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir);
791 
793  friend builder operator+(const builder& a);
794 
796  friend builder operator-(const builder& a);
797 
799  friend builder operator+(const builder& a, const builder& b);
802  friend builder operator-(const builder& a, const builder& b);
803 
805  friend builder operator*(const builder& a, const builder& b);
806 
808  friend builder operator/(const builder& a, const builder& b);
809 
811  friend builder operator%(const builder& a, const builder& b);
812 
814  friend builder operator^(const builder& a, const builder& b);
815 
817 
818 
820  bool is_zero() const;
822  };
823 
824 
825 
826  /* print */
827  /* ===== */
828 
831 
836  friend std::ostream& operator<< (std::ostream& os, const texpr0& s);
839  void print(char** name_of_dim = NULL, FILE* stream=stdout) const;
840 
843 
844  /* tests, size, dimensions */
845  /* ======================= */
846 
850 
852  bool equal(const texpr0& x) const;
853 
855  bool is_zero() const;
856 
858  size_t depth() const;
861  size_t size() const;
862 
864  ap_dim_t max_dim() const;
865 
867  bool has_dim(ap_dim_t d) const;
868 
872  std::vector<ap_dim_t> dimlist() const;
873 
875  bool is_interval_cst() const;
876 
878  bool is_interval_linear() const;
881  bool is_interval_polynomial() const;
882 
884  bool is_interval_polyfrac() const;
885 
887  bool is_scalar() const;
888 
890 
891  /* operations */
892  /* ========== */
896 
898  void substitute(ap_dim_t dim, const texpr0& dst);
899 
900 #if 0
901 
907  interval eval(manager& m, const abstract0& a, ap_scalar_discr_t discr=AP_SCALAR_DOUBLE,
908  bool* pexact=NULL) const;
909 
910  linexpr0 intlinearize(manager& m, const abstract0& a, ap_scalar_discr_t discr=AP_SCALAR_DOUBLE,
911  bool quasilinearize=false, bool* pexact=NULL) const;
912 #endif
915  long hash() const;
916 
919  /* change of dimension */
920  /* =================== */
921 
924 
926  void add_dimensions(const dimchange& d);
927 
932  void remove_dimensions(const dimchange& d);
933 
935  void permute_dimensions(const dimperm& d);
936 
938 
939 
940  /* C-level compatibility */
941  /* ===================== */
942 
945 
947  ap_texpr0_t* get_ap_texpr0_t();
948 
950  const ap_texpr0_t* get_ap_texpr0_t() const;
951 
953 
954 };
955 
956 #include "apxx_texpr0_inline.hh"
957 
958 }
959 
960 #endif /* __APXX_TEXPR0_HH */
ap_texpr0_t l
Structure managed by APRON.
Definition: apxx_texpr0.hh:96
Iterators to traverse and mutate an expression tree.
Definition: apxx_texpr0.hh:413
bool is_binop(ap_texpr_op_t op)
Whether the operator is binary.
Definition: apxx_texpr0.hh:38
Dimension permutation object (ap_dimperm_t wrapper).
Definition: apxx_dimension.hh:292
Dimension change object (ap_dimchange_t wrapper).
Definition: apxx_dimension.hh:102
texpr0::builder pow(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:807
texpr0::builder ceil(const texpr0::builder &a)
Definition: apxx_texpr0.hh:832
Definition: apxx_abstract0.hh:27
ap_texpr0_t * l
Definition: apxx_texpr0.hh:215
Variable name (ap_var_t wrapper).
Definition: apxx_var.hh:39
texpr0::builder cast(const texpr0::builder &a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:821
bool equal(const linexpr0 &x, const linexpr0 &y)
Definition: apxx_linexpr0.hh:294
texpr0::builder sub(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:779
texpr0::builder add(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:772
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition: apxx_abstract0.hh:293
texpr0::builder neg(const texpr0::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:814
Level 0 abstract value (ap_abstract0_t* wrapper).
Definition: apxx_abstract0.hh:78
texpr0::builder operator%(const texpr0::builder &a, const texpr0::builder &b)
Definition: apxx_texpr0.hh:879
texpr0::builder operator-(const texpr0::builder &a)
Definition: apxx_texpr0.hh:854
dim(ap_dim_t d)
Standard constructor.
Definition: apxx_texpr0.hh:20
bool is_unop(ap_texpr_op_t op)
Whether the operator is unary.
Definition: apxx_texpr0.hh:33
Library manager (ap_manager_t wrapper).
Definition: apxx_manager.hh:137
texpr0::builder operator^(const texpr0::builder &a, const texpr0::builder &b)
Definition: apxx_texpr0.hh:884
texpr0::builder trunc(const texpr0::builder &a)
Definition: apxx_texpr0.hh:837
texpr0::builder binary(ap_texpr_op_t op, const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:764
texpr0::builder div(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:793
abstract0 & add_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d, bool project=false)
Definition: apxx_abstract0.hh:1038
Iterators to traverse a constant expression tree.
Definition: apxx_texpr0.hh:211
texpr0::builder mod(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:800
Level 1 environment (ap_environment_t wrapper).
Definition: apxx_environment.hh:51
ap_texpr0_t * l
Definition: apxx_texpr0.hh:587
ap_dim_t d
Dimension index.
Definition: apxx_texpr0.hh:37
texpr0::builder mul(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:786
abstract0 & permute_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimperm &d)
Definition: apxx_abstract0.hh:1061
texpr0::builder floor(const texpr0::builder &a)
Definition: apxx_texpr0.hh:827
dimperm operator*(const dimperm &x, const dimperm &y)
Definition: apxx_dimension.hh:393
Level 0 arbitrary expression tree (ap_texpr0_t wrapper).
Definition: apxx_texpr0.hh:92
Coefficient (ap_coeff_t wrapper).
Definition: apxx_coeff.hh:36
Full interval (]-oo,+oo[) or domain, to simplify initialisations and assignments. ...
Definition: apxx_interval.hh:27
texpr0::builder sqrt(const texpr0::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:842
Level 0 arbitrary constraint (ap_tcons0_t wrapper).
Definition: apxx_tcons0.hh:47
Interval (ap_interval_t wrapper).
Definition: apxx_interval.hh:47
Inherited by most wrappers to map new and delete to malloc and free.
Definition: apxx_scalar.hh:69
A fraction with native int coefficients, to simplify initialisations and assignments.
Definition: apxx_scalar.hh:41
abstract0 & substitute(manager &m, abstract0 &dst, const abstract0 &src, ap_dim_t dim, const linexpr0 &l, const abstract0 &inter=abstract0::null)
Definition: apxx_abstract0.hh:860
texpr0::builder operator+(const texpr0::builder &a)
Definition: apxx_texpr0.hh:849
Level 1 arbitrary expression tree (ap_texpr1_t wrapper).
Definition: apxx_texpr1.hh:42
texpr0::builder operator/(const texpr0::builder &a, const texpr0::builder &b)
Definition: apxx_texpr0.hh:874
Level 1 arbitrary constraint (ap_tcons1_t wrapper).
Definition: apxx_tcons1.hh:39
abstract0 & remove_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d)
Definition: apxx_abstract0.hh:1050
Represents a dimension (i.e., variable by index) in an expression tree.
Definition: apxx_texpr0.hh:33
Temporary expression nodes used when constructing a texpr0.
Definition: apxx_texpr0.hh:581
texpr0::builder unary(ap_texpr_op_t op, const texpr0::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:757
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition: apxx_linexpr0.hh:44
Scalar (ap_scalar_t wrapper).
Definition: apxx_scalar.hh:89