APRONXX 0.9.14
/builddir/build/BUILD/apron-0.9.15-build/apron-0.9.15/apronxx/apxx_texpr1_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_texpr1_inline.hh
3 *
4 * APRON Library / C++ inline functions
5 *
6 * DO NOT INCLUDE THIS FILE DIRECTLY
7 *
8 * Copyright (C) Antoine Mine' 2007
9 *
10 */
11/* This file is part of the APRON Library, released under LGPL license
12 with an exception allowing the redistribution of statically linked
13 executables.
14
15 Please read the COPYING file packaged in the distribution.
16*/
17
18inline void texpr1::init_from(ap_environment_t* e, ap_texpr0_t* x)
19{
20 l.env = e;
21 l.texpr0 = x;
22}
23
24inline void texpr1::init_from(ap_texpr1_t* x)
25{
26 l = *x;
27 free(x);
28}
29
30inline texpr1::texpr1(ap_texpr1_t* x)
31{
32 init_from(x);
33}
34
35inline texpr1::texpr1(const texpr1& x)
36{
37 init_from(ap_texpr1_copy(const_cast<ap_texpr1_t*>(&x.l)));
38}
39
40inline texpr1::texpr1(const builder& x)
41{
42 init_from(ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t())));
43}
44
45inline texpr1::texpr1(const const_iterator& x)
46{
47 init_from(ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t())));
48}
49
50inline texpr1::texpr1(const environment& e, const var& v)
51{
52 ap_texpr1_t* ll =
53 ap_texpr1_var(const_cast<ap_environment_t*>(e.get_ap_environment_t()), v.get_ap_var_t());
54 if (!ll) throw(std::invalid_argument("apron::texpr1::texpr1(const environment&, const var&) variable not in environment"));
55 init_from(ll);
56}
57
58inline texpr1::texpr1(const environment& e, const texpr0& x)
59{
60 init_from(ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t())),
61 ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t())));
62}
63
64inline texpr1::texpr1(const environment& e, const texpr0::const_iterator& x)
65{
66 init_from(ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t())),
67 ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t())));
68}
69
70inline texpr1::texpr1(const environment& e, const texpr0::builder& c)
71{
72 init_from(ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t())),
73 ap_texpr0_copy(const_cast<ap_texpr0_t*>(c.get_ap_texpr0_t())));
74}
75
76
77inline texpr1::texpr1(const linexpr1& l)
78{
79 init_from(ap_texpr1_from_linexpr1(const_cast<ap_linexpr1_t*>(l.get_ap_linexpr1_t())));
80}
81
82inline texpr1::texpr1(const texpr1& x, const environment& e)
83{
84 ap_texpr1_t* ll =
85 ap_texpr1_extend_environment(const_cast<ap_texpr1_t*>(&x.l),
86 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
87 if (!ll)
88 throw std::invalid_argument("apron::texpr1::texpr1(const texpr1&, const environment&) not a super-environment");
89 init_from(ll);
90}
91
92inline texpr1::texpr1(const texpr1& x, const var& src, const texpr1& dst)
93{
94 ap_texpr1_t* ll =
95 ap_texpr1_substitute(const_cast<ap_texpr1_t*>(&x.l),
96 const_cast<ap_var_t>(src.get_ap_var_t()),
97 const_cast<ap_texpr1_t*>(&dst.l));
98 if (!ll)
99 throw std::invalid_argument("apron::texpr1::texpr1(const texpr1&, const var&, const texpr1&)");
100 init_from(ll);
101}
102
103
104/* destructor */
105/* ========== */
106
107inline texpr1::~texpr1()
108{
109 ap_environment_free(l.env);
110 ap_texpr0_free(l.texpr0);
111}
112
113
114/* assignment */
115/* ========== */
116
117inline texpr1& texpr1::operator=(const texpr1& x)
118{
119 ap_texpr1_t* c = ap_texpr1_copy(const_cast<ap_texpr1_t*>(&x.l));
120 ap_environment_free(l.env);
121 ap_texpr0_free(l.texpr0);
122 init_from(c);
123 return *this;
124}
125
126inline texpr1& texpr1::operator=(const builder& x)
127{
128 ap_texpr1_t* c = ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
129 ap_environment_free(l.env);
130 ap_texpr0_free(l.texpr0);
131 init_from(c);
132 return *this;
133}
134
135inline texpr1& texpr1::operator=(const const_iterator& x)
136{
137 ap_texpr1_t* c = ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
138 ap_environment_free(l.env);
139 ap_texpr0_free(l.texpr0);
140 init_from(c);
141 return *this;
142}
143
144inline texpr1& texpr1::operator= (const linexpr1& x)
145{
146 ap_environment_free(l.env);
147 ap_texpr0_free(l.texpr0);
148 init_from(ap_texpr1_from_linexpr1(const_cast<ap_linexpr1_t*>(x.get_ap_linexpr1_t())));
149 return *this;
150}
151
152
153
154/* print */
155/* ===== */
156
157extern void apxx_texpr0_env_ostream(std::ostream& os, ap_environment_t* env, ap_texpr0_t* a);
158
159inline std::ostream& operator<< (std::ostream& os, const texpr1& s)
160{
161 return os << s.root();
162}
163
164inline void texpr1::print(FILE* stream) const
165{
166 root().print(stream);
167}
168
169
170
171/* dimension operations */
172/* ==================== */
173
174inline void texpr1::extend_environment(const environment& e)
175{
176 bool r =
177 ap_texpr1_extend_environment_with(&l,
178 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
179 if (r)
180 throw std::invalid_argument("apron::texpr1::extend_environment(const environment&) not a super-environment");
181}
182
183
184/* access */
185/* ====== */
186
187inline environment texpr1::get_environment() const
188{
189 return root().get_environment();
190}
191
192inline texpr0::const_iterator texpr1::get_texpr0() const
193{
194 return root().get_texpr0();
195}
196
197inline texpr0::iterator texpr1::get_texpr0()
198{
199 return root().get_texpr0();
200}
201
202inline bool texpr1::equal(const texpr1& x) const
203{
204 return root().equal(x);
205}
206
207inline size_t texpr1::depth() const
208{
209 return root().depth();
210}
211
212inline bool texpr1::is_zero() const
213{
214 return root().is_zero();
215}
216
217inline size_t texpr1::size() const
218{
219 return root().size();
220}
221
222inline bool texpr1::has_var(const var& v) const
223{
224 return root().has_var(v);
225}
226
227inline bool texpr1::is_interval_cst() const
228{
229 return root().is_interval_cst();
230}
231
232inline bool texpr1::is_interval_linear() const
233{
234 return root().is_interval_linear();
235}
236
237inline bool texpr1::is_interval_polynomial() const
238{
239 return root().is_interval_polynomial();
240}
241
242inline bool texpr1::is_interval_polyfrac() const
243{
244 return root().is_interval_polyfrac();
245}
246
247inline bool texpr1::is_scalar() const
248{
249 return root().is_scalar();
250}
251
252
253/* operations */
254/* ========== */
255
256inline void texpr1::substitute(const var& src, const texpr1& dst)
257{
258 bool r =
259 ap_texpr1_substitute_with(const_cast<ap_texpr1_t*>(&l),
260 const_cast<ap_var_t>(src.get_ap_var_t()),
261 const_cast<ap_texpr1_t*>(&dst.l));
262 if (r)
263 throw std::invalid_argument("apron::texpr1::substitute(const var&, const texpr1&)");
264}
265
266
267/* C-level compatibility */
268/* ===================== */
269
270
271inline ap_texpr1_t* texpr1::get_ap_texpr1_t()
272{
273 return &l;
274}
275
276inline const ap_texpr1_t* texpr1::get_ap_texpr1_t() const
277{
278 return &l;
279}
280
281
282
283
284
285
286/* ========= */
287/* iterators */
288/* ========= */
289
290
291
292/* constructors */
293/* ============ */
294
295inline texpr1::const_iterator texpr1::root() const
296{
297 return const_iterator(const_cast<ap_texpr1_t*>(&l));
298}
299
300inline texpr1::const_iterator::const_iterator(ap_texpr0_t* ll, ap_environment_t* ee)
301{
302 l.texpr0 = ll;
303 l.env = ee;
304}
305
306inline texpr1::const_iterator::const_iterator(ap_texpr1_t* l)
307 : l(*l)
308{}
309
313
317
318
319/* access */
320/* ====== */
321
323{
324 return ap_environment_copy(l.env);
325}
326
328{
329 return l.texpr0;
330}
331
332inline ap_texpr_discr_t texpr1::const_iterator::get_discr() const
333{
334 return l.texpr0->discr;
335}
336
338{
339 if (l.texpr0->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr1::const_iterator::get_coeff()"));
340 return reinterpret_cast<coeff&>(l.texpr0->val.cst);
341}
342
344{
345 if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::const_iterator::get_var()"));
346 return *reinterpret_cast<var*>(&l.env->var_of_dim[l.texpr0->val.dim]);
347}
348
349inline ap_dim_t texpr1::const_iterator::get_dim() const
350{
351 if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::const_iterator::get_dim()"));
352 return l.texpr0->val.dim;
353}
354
355inline ap_texpr_op_t texpr1::const_iterator::get_op() const
356{
357 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_op()"));
358 return l.texpr0->val.node->op;
359}
360
361inline ap_texpr_rtype_t texpr1::const_iterator::get_rtype() const
362{
363 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_type()"));
364 return l.texpr0->val.node->type;
365}
366
367inline ap_texpr_rdir_t texpr1::const_iterator::get_rdir() const
368{
369 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_dir()"));
370 return l.texpr0->val.node->dir;
371}
372
373
374/* traversal */
375/* ========= */
376
378{
379 l = i.l;
380 return *this;
381}
382
384{
385 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::child()"));
386 if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::const_iterator::child()"));
387 return const_iterator(l.texpr0->val.node->exprA, l.env);
388}
389
391{
392 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::left()"));
393 if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::const_iterator::left()"));
394 return const_iterator(l.texpr0->val.node->exprA, l.env);
395}
396
398{
399 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::right()"));
400 if (!l.texpr0->val.node->exprB) throw(std::out_of_range("apron::texpr1::const_iterator::right()"));
401 return const_iterator(l.texpr0->val.node->exprB, l.env);
402}
403
404
405
406
407/* print */
408/* ===== */
409
410inline std::ostream& operator<< (std::ostream& os, const texpr1::const_iterator& s)
411{
412 ap_texpr1_t* x = const_cast<ap_texpr1_t*>(s.get_ap_texpr1_t());
413 apxx_texpr0_env_ostream(os, x->env, x->texpr0);
414 return os;
415}
416
417inline void texpr1::const_iterator::print(FILE* stream) const
418{
419 ap_texpr1_fprint(stream, const_cast<ap_texpr1_t*>(&l));
420}
421
422
423/* tests, size */
424/* =========== */
425
426inline bool texpr1::const_iterator::equal(const texpr1& x) const
427{
428 return ap_texpr1_equal(const_cast<ap_texpr1_t*>(&l),
429 const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
430}
431
432inline size_t texpr1::const_iterator::depth() const
433{
434 return ap_texpr0_depth(const_cast<ap_texpr0_t*>(l.texpr0));
435}
436
438{
439 return l.texpr0->discr==AP_TEXPR_CST && ap_coeff_zero(&const_cast<ap_texpr0_t*>(l.texpr0)->val.cst);
440}
441
442inline size_t texpr1::const_iterator::size() const
443{
444 return ap_texpr0_size(const_cast<ap_texpr0_t*>(l.texpr0));
445}
446
447inline bool texpr1::const_iterator::has_var(const var& v) const
448{
449 return ap_texpr1_has_var(const_cast<ap_texpr1_t*>(&l),
450 const_cast<ap_var_t>(v.get_ap_var_t()));
451}
452
454{
455 return ap_texpr1_is_interval_cst(const_cast<ap_texpr1_t*>(&l));
456}
457
459{
460 return ap_texpr1_is_interval_linear(const_cast<ap_texpr1_t*>(&l));
461}
462
464{
465 return ap_texpr1_is_interval_polynomial(const_cast<ap_texpr1_t*>(&l));
466}
467
469{
470 return ap_texpr1_is_interval_polyfrac(const_cast<ap_texpr1_t*>(&l));
471}
472
474{
475 return ap_texpr1_is_scalar(const_cast<ap_texpr1_t*>(&l));
476}
477
478
479/* C-level compatibility */
480/* ===================== */
481
483{
484 return &l;
485}
486
487inline const ap_texpr1_t* texpr1::const_iterator::get_ap_texpr1_t() const
488{
489 return &l;
490}
491
492
493/* constructors */
494/* ============ */
495
497{
498 return iterator(&l);
499}
500
501inline texpr1::iterator::iterator(ap_texpr0_t* l, ap_environment_t* e)
502 : texpr1::const_iterator(l,e)
503{}
504
505inline texpr1::iterator::iterator(ap_texpr1_t* l)
507{}
508
509
513
517
518
519
520/* substitution */
521/* ============ */
522
524{
525 ap_texpr0_t* cc = ap_texpr0_copy(c.get_ap_texpr1_t()->texpr0);
526 ap_texpr0_clear(l.texpr0);
527 *l.texpr0 = *cc;
528 free(cc);
529 return *this;
530}
531
532
533/* access */
534/* ====== */
535
537{
538 return l.texpr0;
539}
540
541
543{
544 if (l.texpr0->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr1::iterator::get_coeff()"));
545 return reinterpret_cast<coeff&>(l.texpr0->val.cst);
546}
547
548inline void texpr1::iterator::set_var(const var& v) const
549{
550 if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::iterator::set_var(const var&)"));
551 ap_dim_t d = ap_environment_dim_of_var(l.env, v.get_ap_var_t());
552 if (d==AP_DIM_MAX) throw(std::invalid_argument("apron::texpr1::iterator::set_var(const var&) variable not in environment"));
553 l.texpr0->val.dim = d;
554}
555
556inline ap_dim_t& texpr1::iterator::get_dim() const
557{
558 if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::iterator::get_dim()"));
559 return l.texpr0->val.dim;
560}
561
562inline ap_texpr_op_t& texpr1::iterator::get_op() const
563{
564 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_op()"));
565 return l.texpr0->val.node->op;
566}
567
568inline ap_texpr_rtype_t& texpr1::iterator::get_rtype() const
569{
570 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_type()"));
571 return l.texpr0->val.node->type;
572}
573
574inline ap_texpr_rdir_t& texpr1::iterator::get_rdir() const
575{
576 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_dir()"));
577 return l.texpr0->val.node->dir;
578}
579
580
581/* traversal */
582/* ========= */
583
585{
586 l = i.l;
587 return *this;
588}
589
591{
592 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::child()"));
593 if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::iterator::child()"));
594 return iterator(l.texpr0->val.node->exprA, l.env);
595}
596
598{
599 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::left()"));
600 if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::iterator::left()"));
601 return iterator(l.texpr0->val.node->exprA, l.env);
602}
603
605{
606 if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::right()"));
607 if (!l.texpr0->val.node->exprB) throw(std::out_of_range("apron::texpr1::iterator::right()"));
608 return iterator(l.texpr0->val.node->exprB, l.env);
609}
610
611
612/* C-level compatibility */
613/* ===================== */
614
616{
617 return &l;
618}
619
620inline const ap_texpr1_t* texpr1::iterator::get_ap_texpr1_t() const
621{
622 return &l;
623}
624
625
626/* ================================= */
627/* builder */
628/* ================================= */
629
630inline void texpr1::builder::init_from(ap_texpr1_t* x)
631{
632 l.env = x->env;
633 switch (x->texpr0->discr) {
634 case AP_TEXPR_DIM: l.texpr0 = ap_texpr0_dim(x->texpr0->val.dim); break;
635 case AP_TEXPR_CST: l.texpr0 = ap_texpr0_cst(const_cast<ap_coeff_t*>(&x->texpr0->val.cst)); break;
636 case AP_TEXPR_NODE:
637 l.texpr0 = ap_texpr0_node(x->texpr0->val.node->op,
638 x->texpr0->val.node->type, x->texpr0->val.node->dir,
639 x->texpr0->val.node->exprA, x->texpr0->val.node->exprB);
640 break;
641 default: throw std::invalid_argument("apron::texpr1::builder::init_from(ap_texpr1_t*) invalid discriminant");
642 }
643}
644
645inline void texpr1::builder::init_from(ap_environment_t* e, ap_texpr0_t* x)
646{
647 ap_texpr1_t ll;
648 ll.texpr0 = x;
649 ll.env = e;
650 init_from(&ll);
651}
652
653inline texpr1::builder::builder(ap_texpr1_t* x)
654{
655 init_from(x);
656}
657
659{
660 init_from(const_cast<ap_texpr1_t*>(&x.l));
661}
662
664{
665 init_from(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
666}
667
669{
670 init_from(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
671}
672
674{
675 init_from(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
676 const_cast<ap_texpr0_t*>(b.get_ap_texpr0_t()));
677}
678
680{
681 init_from(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
682 const_cast<ap_texpr0_t*>(b.get_ap_texpr0_t()));
683}
684
686{
687 init_from(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
688 const_cast<ap_texpr0_t*>(b.get_ap_texpr0_t()));
689}
690
692{
693 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
694 l.texpr0 = ap_texpr0_cst(const_cast<ap_coeff_t*>(x.get_ap_coeff_t()));
695}
696
698{
699 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
700 l.texpr0 = ap_texpr0_cst_scalar(const_cast<ap_scalar_t*>(x.get_ap_scalar_t()));
701}
702
703inline texpr1::builder::builder(const environment& e, const mpq_class& x)
704{
705 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
706 l.texpr0 = ap_texpr0_cst_scalar_mpq(const_cast<mpq_class&>(x).get_mpq_t());
707}
708
709inline texpr1::builder::builder(const environment& e, mpfr_t x)
710{
711 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
712 l.texpr0 = ap_texpr0_cst_scalar_mpfr(x);
713}
714
716{
717 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
718 l.texpr0 = ap_texpr0_cst_scalar_int(x);
719}
720
721inline texpr1::builder::builder(const environment& e, long x)
722{
723 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
724 l.texpr0 = ap_texpr0_cst_scalar_int(x);
725}
726
727inline texpr1::builder::builder(const environment& e, double x)
728{
729 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
730 l.texpr0 = ap_texpr0_cst_scalar_double(x);
731}
732
733inline texpr1::builder::builder(const environment& e, const frac& x)
734{
735 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
736 l.texpr0 = ap_texpr0_cst_scalar_frac(x.num, x.den);
737}
738
740{
741 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
742 l.texpr0 = ap_texpr0_cst_interval(const_cast<ap_interval_t*>(x.get_ap_interval_t()));
743}
744
745inline texpr1::builder::builder(const environment& e, const scalar& inf, const scalar& sup)
746{
747 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
748 l.texpr0 = ap_texpr0_cst_interval_scalar(const_cast<ap_scalar_t*>(inf.get_ap_scalar_t()),
749 const_cast<ap_scalar_t*>(sup.get_ap_scalar_t()));
750}
751
752inline texpr1::builder::builder(const environment& e, const mpq_class& inf, const mpq_class& sup)
753{
754 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
755 l.texpr0 = ap_texpr0_cst_interval_mpq(const_cast<mpq_class&>(inf).get_mpq_t(),
756 const_cast<mpq_class&>(sup).get_mpq_t());
757}
758
759inline texpr1::builder::builder(const environment& e, mpfr_t inf, mpfr_t sup)
760{
761 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
762 l.texpr0 = ap_texpr0_cst_interval_mpfr(inf,sup);
763}
764
765inline texpr1::builder::builder(const environment& e, int inf, int sup)
766{
767 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
768 l.texpr0 = ap_texpr0_cst_interval_int(inf, sup);
769}
770
771inline texpr1::builder::builder(const environment& e, long inf, long sup)
772{
773 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
774 l.texpr0 = ap_texpr0_cst_interval_int(inf, sup);
775}
776
777inline texpr1::builder::builder(const environment& e, double inf, double sup)
778{
779 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
780 l.texpr0 = ap_texpr0_cst_interval_double(inf, sup);
781}
782
783inline texpr1::builder::builder(const environment& e, const frac& inf, const frac& sup)
784{
785 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
786 l.texpr0 = ap_texpr0_cst_interval_frac(inf.num, inf.den, sup.num, sup.den);
787}
788
790{
791 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
792 l.texpr0 = ap_texpr0_cst_interval_top();
793}
794
795inline texpr1::builder::builder(const environment& e, const var& v)
796{
797 l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
798 ap_dim_t d = ap_environment_dim_of_var(l.env, v.get_ap_var_t());
799 if (d==AP_DIM_MAX)
800 throw std::invalid_argument("texpr1::builder::builder(const environment&, const var&) variable not in environment");
801 l.texpr0 = ap_texpr0_dim(d);
802}
803
804inline texpr1::builder::builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir)
805{
806 if (!ap_texpr_is_unop(op))
807 throw std::invalid_argument("apron::texpr1::builder::builder(ap_texpr_op_t, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a unary operator");
808 l.env = argA.l.env;
809 l.texpr0 = ap_texpr0_unop(op,
810 const_cast<ap_texpr0_t*>(argA.l.texpr0),
811 rtype, rdir);
812}
813
814inline texpr1::builder::builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir)
815{
816 if (!ap_texpr_is_binop(op))
817 throw std::invalid_argument("apron::texpr1::builder::builder(ap_texpr_op_t, const builder&, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a binary operator");
818 l.env = argA.l.env;
819 l.texpr0 = ap_texpr0_binop(op,
820 const_cast<ap_texpr0_t*>(argA.l.texpr0),
821 const_cast<ap_texpr0_t*>(argB.l.texpr0),
822 rtype, rdir);
823}
824
825
826/* 'intelligent' constructors */
827
828inline texpr1::builder unary(ap_texpr_op_t op, const texpr1::builder& a,
829 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
830 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
831{
832 return texpr1::builder(op, a, rtype, rdir);
833}
834
835inline texpr1::builder binary(ap_texpr_op_t op, const texpr1::builder& a, const texpr1::builder& b,
836 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
837 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
838{
839 return texpr1::builder(op, a, b, rtype, rdir);
840}
841
842
843inline texpr1::builder add(const texpr1::builder& a, const texpr1::builder& b,
844 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
845 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
846{
847 return texpr1::builder(AP_TEXPR_ADD, a, b, rtype, rdir);
848}
849
850inline texpr1::builder sub(const texpr1::builder& a, const texpr1::builder& b,
851 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
852 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
853{
854 return texpr1::builder(AP_TEXPR_SUB, a, b, rtype, rdir);
855}
856
857inline texpr1::builder mul(const texpr1::builder& a, const texpr1::builder& b,
858 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
859 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
860{
861 return texpr1::builder(AP_TEXPR_MUL, a, b, rtype, rdir);
862}
863
864inline texpr1::builder div(const texpr1::builder& a, const texpr1::builder& b,
865 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
866 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
867{
868 return texpr1::builder(AP_TEXPR_DIV, a, b, rtype, rdir);
869}
870
871inline texpr1::builder mod(const texpr1::builder& a, const texpr1::builder& b,
872 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
873 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
874{
875 return texpr1::builder(AP_TEXPR_MOD, a, b, rtype, rdir);
876}
877
878inline texpr1::builder pow(const texpr1::builder& a, const texpr1::builder& b,
879 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
880 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
881{
882 return texpr1::builder(AP_TEXPR_POW, a, b, rtype, rdir);
883}
884
885inline texpr1::builder neg(const texpr1::builder& a,
886 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
887 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
888{
889 return texpr1::builder(AP_TEXPR_NEG, a, rtype, rdir);
890}
891
892inline texpr1::builder cast(const texpr1::builder& a, ap_texpr_rtype_t rtype,
893 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
894{
895 return texpr1::builder(AP_TEXPR_CAST, a, rtype, rdir);
896}
897
898inline texpr1::builder floor(const texpr1::builder& a)
899{
900 return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_DOWN);
901}
902
903inline texpr1::builder ceil(const texpr1::builder& a)
904{
905 return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_UP);
906}
907
908inline texpr1::builder trunc(const texpr1::builder& a)
909{
910 return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_ZERO);
911}
912
913inline texpr1::builder sqrt(const texpr1::builder& a,
914 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
915 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
916{
917 return texpr1::builder(AP_TEXPR_SQRT, a, rtype, rdir);
918}
919
920inline texpr1::builder operator+(const texpr1::builder& a)
921{
922 return a;
923}
924
925inline texpr1::builder operator-(const texpr1::builder& a)
926{
927 return neg(a);
928}
929
930inline texpr1::builder operator+(const texpr1::builder& a, const texpr1::builder& b)
931{
932 return add(a,b);
933}
934
935inline texpr1::builder operator-(const texpr1::builder& a, const texpr1::builder& b)
936{
937 return sub(a,b);
938}
939
940inline texpr1::builder operator*(const texpr1::builder& a, const texpr1::builder& b)
941{
942 return mul(a,b);
943}
944
945inline texpr1::builder operator/(const texpr1::builder& a, const texpr1::builder& b)
946{
947 return div(a,b);
948}
949
950inline texpr1::builder operator%(const texpr1::builder& a, const texpr1::builder& b)
951{
952 return mod(a,b);
953}
954
955inline texpr1::builder operator^(const texpr1::builder& a, const texpr1::builder& b)
956{
957 return pow(a,b);
958}
959
960
961/* tests */
962/* ===== */
963
964inline bool texpr1::builder::is_zero() const
965{
966 return l.texpr0->discr==AP_TEXPR_CST && ap_coeff_zero(const_cast<ap_coeff_t*>(&l.texpr0->val.cst));
967}
968
969
970/* destructor */
971/* ========== */
972
974{
975 switch(l.texpr0->discr){
976 case AP_TEXPR_CST: ap_coeff_clear(&l.texpr0->val.cst); break;
977 case AP_TEXPR_DIM: break;
978 case AP_TEXPR_NODE: free(l.texpr0->val.node); break;
979 default: assert(false);
980 }
981 free(l.texpr0);
982}
983
984
985/* C-level compatibility */
986/* ===================== */
987
989{
990 return &l;
991}
992
993inline const ap_texpr1_t* texpr1::builder::get_ap_texpr1_t() const
994{
995 return &l;
996}
dimperm operator*(const dimperm &x, const dimperm &y)
Definition apxx_dimension_inline.hh:392
texpr0::builder floor(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:826
texpr0::builder trunc(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:836
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_inline.hh:841
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_inline.hh:778
texpr0::builder operator/(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_texpr0_inline.hh:873
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_inline.hh:792
texpr0::builder cast(const texpr0::builder &a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition apxx_texpr0_inline.hh:820
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_inline.hh:763
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_inline.hh:806
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_inline.hh:771
texpr0::builder operator%(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_texpr0_inline.hh:878
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_inline.hh:756
texpr0::builder operator^(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_texpr0_inline.hh:883
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_inline.hh:799
texpr0::builder operator+(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:848
texpr0::builder operator-(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:853
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_inline.hh:813
texpr0::builder ceil(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:831
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_inline.hh:785
std::ostream & operator<<(std::ostream &os, const texpr1 &s)
Definition apxx_texpr1_inline.hh:159
void apxx_texpr0_env_ostream(std::ostream &os, ap_environment_t *env, ap_texpr0_t *a)
Exception raised when an operation is incompatible with a discriminant.
Definition apxx_scalar.hh:55
Coefficient (ap_coeff_t wrapper).
Definition apxx_coeff.hh:36
const ap_coeff_t * get_ap_coeff_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_coeff_inline.hh:483
Level 1 environment (ap_environment_t wrapper).
Definition apxx_environment.hh:51
const ap_environment_t * get_ap_environment_t() const
Returns a pointer to the internal APRON object pointed by *this.
Definition apxx_environment_inline.hh:425
Interval (ap_interval_t wrapper).
Definition apxx_interval.hh:47
const ap_interval_t * get_ap_interval_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_interval_inline.hh:336
Level 1 linear expression (ap_linexpr1_t wrapper).
Definition apxx_linexpr1.hh:39
const ap_linexpr1_t * get_ap_linexpr1_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_linexpr1_inline.hh:321
Scalar (ap_scalar_t wrapper).
Definition apxx_scalar.hh:89
const ap_scalar_t * get_ap_scalar_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_scalar_inline.hh:449
Temporary expression nodes used when constructing a texpr0.
Definition apxx_texpr0.hh:581
ap_texpr0_t * get_ap_texpr0_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_texpr0_inline.hh:912
Iterators to traverse a constant expression tree.
Definition apxx_texpr0.hh:211
bool equal(const texpr0 &x) const
Whether two expressions are syntactically, structurally equal.
Definition apxx_texpr0_inline.hh:428
ap_texpr0_t * get_ap_texpr0_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_texpr0_inline.hh:494
Iterators to traverse and mutate an expression tree.
Definition apxx_texpr0.hh:413
Level 0 arbitrary expression tree (ap_texpr0_t wrapper).
Definition apxx_texpr0.hh:92
ap_texpr0_t * get_ap_texpr0_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_texpr0_inline.hh:293
Temporary expression nodes used when constructing a texpr1.
Definition apxx_texpr1.hh:561
builder(ap_texpr1_t *x)
Internal use only: makes a shallow copy, copying only the root node and referencing the environment.
Definition apxx_texpr1_inline.hh:653
void init_from(ap_texpr1_t *x)
Internal use only: makes a shallow copy, copying only the root node and referencing the environment.
Definition apxx_texpr1_inline.hh:630
~builder()
Frees the memory occupied by the node, not its sub-expressions.
Definition apxx_texpr1_inline.hh:973
ap_texpr1_t l
Definition apxx_texpr1.hh:567
bool is_zero() const
Whether the expression is a single coefficient node with 0 value.
Definition apxx_texpr1_inline.hh:964
ap_texpr1_t * get_ap_texpr1_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_texpr1_inline.hh:988
Iterators to traverse a constant expression tree.
Definition apxx_texpr1.hh:183
const coeff & get_coeff() const
Returns a reference to the coefficient of a constant node.
Definition apxx_texpr1_inline.hh:337
const_iterator right() const
Constructs a const_iterator to the right sub-expression argument of a binary operator node.
Definition apxx_texpr1_inline.hh:397
ap_texpr_rdir_t get_rdir() const
Returns the rounding direction of an operator node.
Definition apxx_texpr1_inline.hh:367
ap_texpr_op_t get_op() const
Returns the operator kind of an operator node.
Definition apxx_texpr1_inline.hh:355
const_iterator left() const
Constructs a const_iterator to the only of left sub-expression of an operator node.
Definition apxx_texpr1_inline.hh:390
bool is_scalar() const
Whether all occurring constants are scalar.
Definition apxx_texpr1_inline.hh:473
bool is_interval_linear() const
Whether the expression is linear and there is no rounding.
Definition apxx_texpr1_inline.hh:458
bool is_zero() const
Whether the expression is a single coefficient node with 0 value.
Definition apxx_texpr1_inline.hh:437
const_iterator(ap_texpr1_t *l)
Internal use only.
Definition apxx_texpr1_inline.hh:306
bool has_var(const var &v) const
Whether the given variable name occurs in the expression.
Definition apxx_texpr1_inline.hh:447
bool equal(const texpr1 &x) const
Whether two expressions are syntactically, structurally equal.
Definition apxx_texpr1_inline.hh:426
const_iterator & operator=(const const_iterator &i)
Resets the const_iterator at position i.
Definition apxx_texpr1_inline.hh:377
ap_dim_t get_dim() const
Returns the dimension of a dimension node.
Definition apxx_texpr1_inline.hh:349
ap_texpr1_t * get_ap_texpr1_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_texpr1_inline.hh:482
texpr0::const_iterator get_texpr0() const
Returns a constant iterator at the root of the underlying texpr0.
Definition apxx_texpr1_inline.hh:327
const var & get_var() const
Returns a (unmodifiable) reference to the variable name of a dimension node.
Definition apxx_texpr1_inline.hh:343
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_texpr1_inline.hh:417
ap_texpr1_t l
Definition apxx_texpr1.hh:187
bool is_interval_cst() const
Whether the expression is constant (i.e., has no dimension leaves).
Definition apxx_texpr1_inline.hh:453
size_t size() const
Returns the number of operator nodes in the expression tree.
Definition apxx_texpr1_inline.hh:442
ap_texpr_discr_t get_discr() const
Returns the node kind.
Definition apxx_texpr1_inline.hh:332
environment get_environment() const
Returns (a copy of) the environment associated with the expression.
Definition apxx_texpr1_inline.hh:322
bool is_interval_polynomial() const
Whether the expression is polynomial and there is no rounding.
Definition apxx_texpr1_inline.hh:463
size_t depth() const
Returns the depth of the expression tree (counting only operator nodes).
Definition apxx_texpr1_inline.hh:432
bool is_interval_polyfrac() const
Whether the expression is a polynomial fraction and there is no rounding.
Definition apxx_texpr1_inline.hh:468
const_iterator child() const
Constructs a const_iterator to the only or left sub-expression of an operator node.
Definition apxx_texpr1_inline.hh:383
ap_texpr_rtype_t get_rtype() const
Returns the destination type of an operator node.
Definition apxx_texpr1_inline.hh:361
Iterators to traverse and mutate an expression tree.
Definition apxx_texpr1.hh:386
iterator child() const
Constructs an iterator to the only or left sub-expression of an operator node.
Definition apxx_texpr1_inline.hh:590
iterator right() const
Constructs an iterator to the right sub-expression argument of a binary operator node.
Definition apxx_texpr1_inline.hh:604
texpr0::iterator get_texpr0() const
Returns an iterator at the root of the underlying texpr0.
Definition apxx_texpr1_inline.hh:536
iterator(ap_texpr1_t *l)
Internal use only.
Definition apxx_texpr1_inline.hh:505
iterator left() const
Constructs an iterator to the only of left sub-expression of an operator node.
Definition apxx_texpr1_inline.hh:597
coeff & get_coeff() const
Returns a (modifiable) reference to the coefficient of a constant node.
Definition apxx_texpr1_inline.hh:542
ap_dim_t & get_dim() const
Returns a (modifiable) reference to the dimension of a dimension node.
Definition apxx_texpr1_inline.hh:556
ap_texpr_rtype_t & get_rtype() const
Returns a (modifiable) reference to the destination type of an operator node.
Definition apxx_texpr1_inline.hh:568
iterator & operator=(const builder &x)
Replace the sub-expression at the iterator position with a (deep) copy of c.
ap_texpr1_t * get_ap_texpr1_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_texpr1_inline.hh:615
ap_texpr_op_t & get_op() const
Returns a (modifiable) reference to the operator kind of an operator node.
Definition apxx_texpr1_inline.hh:562
void set_var(const var &v) const
Sets the variable name of a dimension node.
Definition apxx_texpr1_inline.hh:548
ap_texpr_rdir_t & get_rdir() const
Returns a (modifiable) reference to the rounding direction of an operator node.
Definition apxx_texpr1_inline.hh:574
Level 1 arbitrary expression tree (ap_texpr1_t wrapper).
Definition apxx_texpr1.hh:42
const_iterator root() const
Returns a new iterator at the root of a constant expression tree.
Definition apxx_texpr1_inline.hh:295
friend std::ostream & operator<<(std::ostream &os, const texpr1 &s)
Printing.
void init_from(ap_environment_t *e, ap_texpr0_t *x)
Internal use only. Shallow copy.
Definition apxx_texpr1_inline.hh:18
ap_texpr1_t l
Structure managed by APRON.
Definition apxx_texpr1.hh:46
ap_texpr1_t * get_ap_texpr1_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_texpr1_inline.hh:271
Variable name (ap_var_t wrapper).
Definition apxx_var.hh:39
const ap_var_t & get_ap_var_t() const
Returns a reference to the APRON object wrapped (no copy).
Definition apxx_var_inline.hh:156
A fraction with native int coefficients, to simplify initialisations and assignments.
Definition apxx_scalar.hh:41
unsigned long den
Denominator.
Definition apxx_scalar.hh:44
long num
Numerator.
Definition apxx_scalar.hh:43
Full interval (]-oo,+oo[) or domain, to simplify initialisations and assignments.
Definition apxx_interval.hh:27