2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
11 #include <isl_map_private.h>
12 #include <isl_union_map_private.h>
13 #include <isl_polynomial_private.h>
14 #include <isl_point_private.h>
15 #include <isl_space_private.h>
16 #include <isl_lp_private.h>
18 #include <isl_mat_private.h>
19 #include <isl_val_private.h>
20 #include <isl_vec_private.h>
21 #include <isl_config.h>
23 enum isl_fold
isl_fold_type_negate(enum isl_fold type
)
34 isl_die(NULL
, isl_error_internal
, "unhandled isl_fold type", abort());
37 static __isl_give isl_qpolynomial_fold
*qpolynomial_fold_alloc(
38 enum isl_fold type
, __isl_take isl_space
*dim
, int n
)
40 isl_qpolynomial_fold
*fold
;
45 isl_assert(dim
->ctx
, n
>= 0, goto error
);
46 fold
= isl_calloc(dim
->ctx
, struct isl_qpolynomial_fold
,
47 sizeof(struct isl_qpolynomial_fold
) +
48 (n
- 1) * sizeof(struct isl_qpolynomial
*));
64 isl_ctx
*isl_qpolynomial_fold_get_ctx(__isl_keep isl_qpolynomial_fold
*fold
)
66 return fold
? fold
->dim
->ctx
: NULL
;
69 __isl_give isl_space
*isl_qpolynomial_fold_get_domain_space(
70 __isl_keep isl_qpolynomial_fold
*fold
)
72 return fold
? isl_space_copy(fold
->dim
) : NULL
;
75 __isl_give isl_space
*isl_qpolynomial_fold_get_space(
76 __isl_keep isl_qpolynomial_fold
*fold
)
81 space
= isl_space_copy(fold
->dim
);
82 space
= isl_space_from_domain(space
);
83 space
= isl_space_add_dims(space
, isl_dim_out
, 1);
87 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_reset_domain_space(
88 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_space
*dim
)
92 fold
= isl_qpolynomial_fold_cow(fold
);
96 for (i
= 0; i
< fold
->n
; ++i
) {
97 fold
->qp
[i
] = isl_qpolynomial_reset_domain_space(fold
->qp
[i
],
103 isl_space_free(fold
->dim
);
108 isl_qpolynomial_fold_free(fold
);
113 /* Reset the space of "fold". This function is called from isl_pw_templ.c
114 * and doesn't know if the space of an element object is represented
115 * directly or through its domain. It therefore passes along both.
117 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_reset_space_and_domain(
118 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_space
*space
,
119 __isl_take isl_space
*domain
)
121 isl_space_free(space
);
122 return isl_qpolynomial_fold_reset_domain_space(fold
, domain
);
125 int isl_qpolynomial_fold_involves_dims(__isl_keep isl_qpolynomial_fold
*fold
,
126 enum isl_dim_type type
, unsigned first
, unsigned n
)
132 if (fold
->n
== 0 || n
== 0)
135 for (i
= 0; i
< fold
->n
; ++i
) {
136 int involves
= isl_qpolynomial_involves_dims(fold
->qp
[i
],
138 if (involves
< 0 || involves
)
144 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_set_dim_name(
145 __isl_take isl_qpolynomial_fold
*fold
,
146 enum isl_dim_type type
, unsigned pos
, const char *s
)
150 fold
= isl_qpolynomial_fold_cow(fold
);
153 fold
->dim
= isl_space_set_dim_name(fold
->dim
, type
, pos
, s
);
157 for (i
= 0; i
< fold
->n
; ++i
) {
158 fold
->qp
[i
] = isl_qpolynomial_set_dim_name(fold
->qp
[i
],
166 isl_qpolynomial_fold_free(fold
);
170 /* Given a dimension type for an isl_qpolynomial_fold,
171 * return the corresponding type for the domain.
173 static enum isl_dim_type
domain_type(enum isl_dim_type type
)
175 if (type
== isl_dim_in
)
180 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_drop_dims(
181 __isl_take isl_qpolynomial_fold
*fold
,
182 enum isl_dim_type type
, unsigned first
, unsigned n
)
185 enum isl_dim_type set_type
;
192 set_type
= domain_type(type
);
194 fold
= isl_qpolynomial_fold_cow(fold
);
197 fold
->dim
= isl_space_drop_dims(fold
->dim
, set_type
, first
, n
);
201 for (i
= 0; i
< fold
->n
; ++i
) {
202 fold
->qp
[i
] = isl_qpolynomial_drop_dims(fold
->qp
[i
],
210 isl_qpolynomial_fold_free(fold
);
214 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_insert_dims(
215 __isl_take isl_qpolynomial_fold
*fold
,
216 enum isl_dim_type type
, unsigned first
, unsigned n
)
222 if (n
== 0 && !isl_space_is_named_or_nested(fold
->dim
, type
))
225 fold
= isl_qpolynomial_fold_cow(fold
);
228 fold
->dim
= isl_space_insert_dims(fold
->dim
, type
, first
, n
);
232 for (i
= 0; i
< fold
->n
; ++i
) {
233 fold
->qp
[i
] = isl_qpolynomial_insert_dims(fold
->qp
[i
],
241 isl_qpolynomial_fold_free(fold
);
245 /* Determine the sign of the constant quasipolynomial "qp".
252 * For qp == 0, we can return either -1 or 1. In practice, we return 1.
253 * For qp == NaN, the sign is undefined, so we return 0.
255 static int isl_qpolynomial_cst_sign(__isl_keep isl_qpolynomial
*qp
)
257 struct isl_upoly_cst
*cst
;
259 if (isl_qpolynomial_is_nan(qp
))
262 cst
= isl_upoly_as_cst(qp
->upoly
);
266 return isl_int_sgn(cst
->n
) < 0 ? -1 : 1;
269 static int isl_qpolynomial_aff_sign(__isl_keep isl_set
*set
,
270 __isl_keep isl_qpolynomial
*qp
)
272 enum isl_lp_result res
;
277 aff
= isl_qpolynomial_extract_affine(qp
);
283 res
= isl_set_solve_lp(set
, 0, aff
->el
+ 1, aff
->el
[0],
285 if (res
== isl_lp_error
)
287 if (res
== isl_lp_empty
||
288 (res
== isl_lp_ok
&& !isl_int_is_neg(opt
))) {
293 res
= isl_set_solve_lp(set
, 1, aff
->el
+ 1, aff
->el
[0],
295 if (res
== isl_lp_ok
&& !isl_int_is_pos(opt
))
304 /* Determine, if possible, the sign of the quasipolynomial "qp" on
307 * If qp is a constant, then the problem is trivial.
308 * If qp is linear, then we check if the minimum of the corresponding
309 * affine constraint is non-negative or if the maximum is non-positive.
311 * Otherwise, we check if the outermost variable "v" has a lower bound "l"
312 * in "set". If so, we write qp(v,v') as
314 * q(v,v') * (v - l) + r(v')
316 * if q(v,v') and r(v') have the same known sign, then the original
317 * quasipolynomial has the same sign as well.
324 static int isl_qpolynomial_sign(__isl_keep isl_set
*set
,
325 __isl_keep isl_qpolynomial
*qp
)
330 struct isl_upoly_rec
*rec
;
333 enum isl_lp_result res
;
336 is
= isl_qpolynomial_is_cst(qp
, NULL
, NULL
);
340 return isl_qpolynomial_cst_sign(qp
);
342 is
= isl_qpolynomial_is_affine(qp
);
346 return isl_qpolynomial_aff_sign(set
, qp
);
348 if (qp
->div
->n_row
> 0)
351 rec
= isl_upoly_as_rec(qp
->upoly
);
355 d
= isl_space_dim(qp
->dim
, isl_dim_all
);
356 v
= isl_vec_alloc(set
->ctx
, 2 + d
);
360 isl_seq_clr(v
->el
+ 1, 1 + d
);
361 isl_int_set_si(v
->el
[0], 1);
362 isl_int_set_si(v
->el
[2 + qp
->upoly
->var
], 1);
366 res
= isl_set_solve_lp(set
, 0, v
->el
+ 1, v
->el
[0], &l
, NULL
, NULL
);
367 if (res
== isl_lp_ok
) {
368 isl_qpolynomial
*min
;
369 isl_qpolynomial
*base
;
370 isl_qpolynomial
*r
, *q
;
373 min
= isl_qpolynomial_cst_on_domain(isl_space_copy(qp
->dim
), l
);
374 base
= isl_qpolynomial_var_pow_on_domain(isl_space_copy(qp
->dim
),
377 r
= isl_qpolynomial_alloc(isl_space_copy(qp
->dim
), 0,
378 isl_upoly_copy(rec
->p
[rec
->n
- 1]));
379 q
= isl_qpolynomial_copy(r
);
381 for (i
= rec
->n
- 2; i
>= 0; --i
) {
382 r
= isl_qpolynomial_mul(r
, isl_qpolynomial_copy(min
));
383 t
= isl_qpolynomial_alloc(isl_space_copy(qp
->dim
), 0,
384 isl_upoly_copy(rec
->p
[i
]));
385 r
= isl_qpolynomial_add(r
, t
);
388 q
= isl_qpolynomial_mul(q
, isl_qpolynomial_copy(base
));
389 q
= isl_qpolynomial_add(q
, isl_qpolynomial_copy(r
));
392 if (isl_qpolynomial_is_zero(q
))
393 sgn
= isl_qpolynomial_sign(set
, r
);
394 else if (isl_qpolynomial_is_zero(r
))
395 sgn
= isl_qpolynomial_sign(set
, q
);
398 sgn_r
= isl_qpolynomial_sign(set
, r
);
399 sgn_q
= isl_qpolynomial_sign(set
, q
);
404 isl_qpolynomial_free(min
);
405 isl_qpolynomial_free(base
);
406 isl_qpolynomial_free(q
);
407 isl_qpolynomial_free(r
);
417 /* Combine "fold1" and "fold2" into a single reduction, eliminating
418 * those elements of one reduction that are already covered by the other
419 * reduction on "set".
421 * If "fold1" or "fold2" is an empty reduction, then return
422 * the other reduction.
423 * If "fold1" or "fold2" is a NaN, then return this NaN.
425 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_fold_on_domain(
426 __isl_keep isl_set
*set
,
427 __isl_take isl_qpolynomial_fold
*fold1
,
428 __isl_take isl_qpolynomial_fold
*fold2
)
432 struct isl_qpolynomial_fold
*res
= NULL
;
435 if (!fold1
|| !fold2
)
438 isl_assert(fold1
->dim
->ctx
, fold1
->type
== fold2
->type
, goto error
);
439 isl_assert(fold1
->dim
->ctx
, isl_space_is_equal(fold1
->dim
, fold2
->dim
),
442 better
= fold1
->type
== isl_fold_max
? -1 : 1;
444 if (isl_qpolynomial_fold_is_empty(fold1
) ||
445 isl_qpolynomial_fold_is_nan(fold2
)) {
446 isl_qpolynomial_fold_free(fold1
);
450 if (isl_qpolynomial_fold_is_empty(fold2
) ||
451 isl_qpolynomial_fold_is_nan(fold1
)) {
452 isl_qpolynomial_fold_free(fold2
);
456 res
= qpolynomial_fold_alloc(fold1
->type
, isl_space_copy(fold1
->dim
),
457 fold1
->n
+ fold2
->n
);
461 for (i
= 0; i
< fold1
->n
; ++i
) {
462 res
->qp
[res
->n
] = isl_qpolynomial_copy(fold1
->qp
[i
]);
463 if (!res
->qp
[res
->n
])
469 for (i
= 0; i
< fold2
->n
; ++i
) {
470 for (j
= n1
- 1; j
>= 0; --j
) {
473 equal
= isl_qpolynomial_plain_is_equal(res
->qp
[j
],
479 d
= isl_qpolynomial_sub(
480 isl_qpolynomial_copy(res
->qp
[j
]),
481 isl_qpolynomial_copy(fold2
->qp
[i
]));
482 sgn
= isl_qpolynomial_sign(set
, d
);
483 isl_qpolynomial_free(d
);
488 isl_qpolynomial_free(res
->qp
[j
]);
490 res
->qp
[j
] = res
->qp
[n1
- 1];
492 if (n1
!= res
->n
- 1)
493 res
->qp
[n1
] = res
->qp
[res
->n
- 1];
498 res
->qp
[res
->n
] = isl_qpolynomial_copy(fold2
->qp
[i
]);
499 if (!res
->qp
[res
->n
])
504 isl_qpolynomial_fold_free(fold1
);
505 isl_qpolynomial_fold_free(fold2
);
509 isl_qpolynomial_fold_free(res
);
510 isl_qpolynomial_fold_free(fold1
);
511 isl_qpolynomial_fold_free(fold2
);
515 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_add_qpolynomial(
516 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_qpolynomial
*qp
)
523 if (isl_qpolynomial_is_zero(qp
)) {
524 isl_qpolynomial_free(qp
);
528 fold
= isl_qpolynomial_fold_cow(fold
);
532 for (i
= 0; i
< fold
->n
; ++i
) {
533 fold
->qp
[i
] = isl_qpolynomial_add(fold
->qp
[i
],
534 isl_qpolynomial_copy(qp
));
539 isl_qpolynomial_free(qp
);
542 isl_qpolynomial_fold_free(fold
);
543 isl_qpolynomial_free(qp
);
547 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_add_on_domain(
548 __isl_keep isl_set
*dom
,
549 __isl_take isl_qpolynomial_fold
*fold1
,
550 __isl_take isl_qpolynomial_fold
*fold2
)
553 isl_qpolynomial_fold
*res
= NULL
;
555 if (!fold1
|| !fold2
)
558 if (isl_qpolynomial_fold_is_empty(fold1
)) {
559 isl_qpolynomial_fold_free(fold1
);
563 if (isl_qpolynomial_fold_is_empty(fold2
)) {
564 isl_qpolynomial_fold_free(fold2
);
568 if (fold1
->n
== 1 && fold2
->n
!= 1)
569 return isl_qpolynomial_fold_add_on_domain(dom
, fold2
, fold1
);
572 res
= isl_qpolynomial_fold_add_qpolynomial(fold1
,
573 isl_qpolynomial_copy(fold2
->qp
[0]));
574 isl_qpolynomial_fold_free(fold2
);
578 res
= isl_qpolynomial_fold_add_qpolynomial(
579 isl_qpolynomial_fold_copy(fold1
),
580 isl_qpolynomial_copy(fold2
->qp
[0]));
582 for (i
= 1; i
< fold2
->n
; ++i
) {
583 isl_qpolynomial_fold
*res_i
;
584 res_i
= isl_qpolynomial_fold_add_qpolynomial(
585 isl_qpolynomial_fold_copy(fold1
),
586 isl_qpolynomial_copy(fold2
->qp
[i
]));
587 res
= isl_qpolynomial_fold_fold_on_domain(dom
, res
, res_i
);
590 isl_qpolynomial_fold_free(fold1
);
591 isl_qpolynomial_fold_free(fold2
);
594 isl_qpolynomial_fold_free(res
);
595 isl_qpolynomial_fold_free(fold1
);
596 isl_qpolynomial_fold_free(fold2
);
600 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_substitute_equalities(
601 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_basic_set
*eq
)
608 fold
= isl_qpolynomial_fold_cow(fold
);
612 for (i
= 0; i
< fold
->n
; ++i
) {
613 fold
->qp
[i
] = isl_qpolynomial_substitute_equalities(fold
->qp
[i
],
614 isl_basic_set_copy(eq
));
619 isl_basic_set_free(eq
);
622 isl_basic_set_free(eq
);
623 isl_qpolynomial_fold_free(fold
);
627 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_gist(
628 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_set
*context
)
632 if (!fold
|| !context
)
635 fold
= isl_qpolynomial_fold_cow(fold
);
639 for (i
= 0; i
< fold
->n
; ++i
) {
640 fold
->qp
[i
] = isl_qpolynomial_gist(fold
->qp
[i
],
641 isl_set_copy(context
));
646 isl_set_free(context
);
649 isl_set_free(context
);
650 isl_qpolynomial_fold_free(fold
);
654 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_gist_params(
655 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_set
*context
)
657 isl_space
*space
= isl_qpolynomial_fold_get_domain_space(fold
);
658 isl_set
*dom_context
= isl_set_universe(space
);
659 dom_context
= isl_set_intersect_params(dom_context
, context
);
660 return isl_qpolynomial_fold_gist(fold
, dom_context
);
663 #define isl_qpolynomial_fold_involves_nan isl_qpolynomial_fold_is_nan
668 #define PW isl_pw_qpolynomial_fold
670 #define EL isl_qpolynomial_fold
672 #define EL_IS_ZERO is_empty
676 #define IS_ZERO is_zero
679 #undef DEFAULT_IS_ZERO
680 #define DEFAULT_IS_ZERO 1
686 #include <isl_pw_templ.c>
687 #include <isl_pw_eval.c>
690 #define UNION isl_union_pw_qpolynomial_fold
692 #define PART isl_pw_qpolynomial_fold
694 #define PARTS pw_qpolynomial_fold
698 #include <isl_union_single.c>
699 #include <isl_union_eval.c>
701 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_empty(enum isl_fold type
,
702 __isl_take isl_space
*dim
)
704 return qpolynomial_fold_alloc(type
, dim
, 0);
707 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_alloc(
708 enum isl_fold type
, __isl_take isl_qpolynomial
*qp
)
710 isl_qpolynomial_fold
*fold
;
715 fold
= qpolynomial_fold_alloc(type
, isl_space_copy(qp
->dim
), 1);
724 isl_qpolynomial_fold_free(fold
);
725 isl_qpolynomial_free(qp
);
729 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_copy(
730 __isl_keep isl_qpolynomial_fold
*fold
)
739 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_dup(
740 __isl_keep isl_qpolynomial_fold
*fold
)
743 isl_qpolynomial_fold
*dup
;
747 dup
= qpolynomial_fold_alloc(fold
->type
,
748 isl_space_copy(fold
->dim
), fold
->n
);
753 for (i
= 0; i
< fold
->n
; ++i
) {
754 dup
->qp
[i
] = isl_qpolynomial_copy(fold
->qp
[i
]);
761 isl_qpolynomial_fold_free(dup
);
765 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_cow(
766 __isl_take isl_qpolynomial_fold
*fold
)
774 return isl_qpolynomial_fold_dup(fold
);
777 void isl_qpolynomial_fold_free(__isl_take isl_qpolynomial_fold
*fold
)
786 for (i
= 0; i
< fold
->n
; ++i
)
787 isl_qpolynomial_free(fold
->qp
[i
]);
788 isl_space_free(fold
->dim
);
792 int isl_qpolynomial_fold_is_empty(__isl_keep isl_qpolynomial_fold
*fold
)
800 /* Does "fold" represent max(NaN) or min(NaN)?
802 isl_bool
isl_qpolynomial_fold_is_nan(__isl_keep isl_qpolynomial_fold
*fold
)
805 return isl_bool_error
;
807 return isl_bool_false
;
808 return isl_qpolynomial_is_nan(fold
->qp
[0]);
811 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_fold(
812 __isl_take isl_qpolynomial_fold
*fold1
,
813 __isl_take isl_qpolynomial_fold
*fold2
)
816 struct isl_qpolynomial_fold
*res
= NULL
;
818 if (!fold1
|| !fold2
)
821 isl_assert(fold1
->dim
->ctx
, fold1
->type
== fold2
->type
, goto error
);
822 isl_assert(fold1
->dim
->ctx
, isl_space_is_equal(fold1
->dim
, fold2
->dim
),
825 if (isl_qpolynomial_fold_is_empty(fold1
)) {
826 isl_qpolynomial_fold_free(fold1
);
830 if (isl_qpolynomial_fold_is_empty(fold2
)) {
831 isl_qpolynomial_fold_free(fold2
);
835 res
= qpolynomial_fold_alloc(fold1
->type
, isl_space_copy(fold1
->dim
),
836 fold1
->n
+ fold2
->n
);
840 for (i
= 0; i
< fold1
->n
; ++i
) {
841 res
->qp
[res
->n
] = isl_qpolynomial_copy(fold1
->qp
[i
]);
842 if (!res
->qp
[res
->n
])
847 for (i
= 0; i
< fold2
->n
; ++i
) {
848 res
->qp
[res
->n
] = isl_qpolynomial_copy(fold2
->qp
[i
]);
849 if (!res
->qp
[res
->n
])
854 isl_qpolynomial_fold_free(fold1
);
855 isl_qpolynomial_fold_free(fold2
);
859 isl_qpolynomial_fold_free(res
);
860 isl_qpolynomial_fold_free(fold1
);
861 isl_qpolynomial_fold_free(fold2
);
865 __isl_give isl_pw_qpolynomial_fold
*isl_pw_qpolynomial_fold_fold(
866 __isl_take isl_pw_qpolynomial_fold
*pw1
,
867 __isl_take isl_pw_qpolynomial_fold
*pw2
)
870 struct isl_pw_qpolynomial_fold
*res
;
876 isl_assert(pw1
->dim
->ctx
, isl_space_is_equal(pw1
->dim
, pw2
->dim
), goto error
);
878 if (isl_pw_qpolynomial_fold_is_zero(pw1
)) {
879 isl_pw_qpolynomial_fold_free(pw1
);
883 if (isl_pw_qpolynomial_fold_is_zero(pw2
)) {
884 isl_pw_qpolynomial_fold_free(pw2
);
888 if (pw1
->type
!= pw2
->type
)
889 isl_die(pw1
->dim
->ctx
, isl_error_invalid
,
890 "fold types don't match", goto error
);
892 n
= (pw1
->n
+ 1) * (pw2
->n
+ 1);
893 res
= isl_pw_qpolynomial_fold_alloc_size(isl_space_copy(pw1
->dim
),
896 for (i
= 0; i
< pw1
->n
; ++i
) {
897 set
= isl_set_copy(pw1
->p
[i
].set
);
898 for (j
= 0; j
< pw2
->n
; ++j
) {
899 struct isl_set
*common
;
900 isl_qpolynomial_fold
*sum
;
901 set
= isl_set_subtract(set
,
902 isl_set_copy(pw2
->p
[j
].set
));
903 common
= isl_set_intersect(isl_set_copy(pw1
->p
[i
].set
),
904 isl_set_copy(pw2
->p
[j
].set
));
905 if (isl_set_plain_is_empty(common
)) {
906 isl_set_free(common
);
910 sum
= isl_qpolynomial_fold_fold_on_domain(common
,
911 isl_qpolynomial_fold_copy(pw1
->p
[i
].fold
),
912 isl_qpolynomial_fold_copy(pw2
->p
[j
].fold
));
914 res
= isl_pw_qpolynomial_fold_add_piece(res
, common
, sum
);
916 res
= isl_pw_qpolynomial_fold_add_piece(res
, set
,
917 isl_qpolynomial_fold_copy(pw1
->p
[i
].fold
));
920 for (j
= 0; j
< pw2
->n
; ++j
) {
921 set
= isl_set_copy(pw2
->p
[j
].set
);
922 for (i
= 0; i
< pw1
->n
; ++i
)
923 set
= isl_set_subtract(set
, isl_set_copy(pw1
->p
[i
].set
));
924 res
= isl_pw_qpolynomial_fold_add_piece(res
, set
,
925 isl_qpolynomial_fold_copy(pw2
->p
[j
].fold
));
928 isl_pw_qpolynomial_fold_free(pw1
);
929 isl_pw_qpolynomial_fold_free(pw2
);
933 isl_pw_qpolynomial_fold_free(pw1
);
934 isl_pw_qpolynomial_fold_free(pw2
);
938 __isl_give isl_union_pw_qpolynomial_fold
*isl_union_pw_qpolynomial_fold_fold_pw_qpolynomial_fold(
939 __isl_take isl_union_pw_qpolynomial_fold
*u
,
940 __isl_take isl_pw_qpolynomial_fold
*part
)
942 struct isl_hash_table_entry
*entry
;
944 u
= isl_union_pw_qpolynomial_fold_cow(u
);
948 if (isl_space_check_equal_params(part
->dim
, u
->space
) < 0)
951 entry
= isl_union_pw_qpolynomial_fold_find_part_entry(u
, part
->dim
, 1);
958 entry
->data
= isl_pw_qpolynomial_fold_fold(entry
->data
,
959 isl_pw_qpolynomial_fold_copy(part
));
962 isl_pw_qpolynomial_fold_free(part
);
967 isl_pw_qpolynomial_fold_free(part
);
968 isl_union_pw_qpolynomial_fold_free(u
);
972 static isl_stat
fold_part(__isl_take isl_pw_qpolynomial_fold
*part
, void *user
)
974 isl_union_pw_qpolynomial_fold
**u
;
975 u
= (isl_union_pw_qpolynomial_fold
**)user
;
977 *u
= isl_union_pw_qpolynomial_fold_fold_pw_qpolynomial_fold(*u
, part
);
982 __isl_give isl_union_pw_qpolynomial_fold
*isl_union_pw_qpolynomial_fold_fold(
983 __isl_take isl_union_pw_qpolynomial_fold
*u1
,
984 __isl_take isl_union_pw_qpolynomial_fold
*u2
)
986 u1
= isl_union_pw_qpolynomial_fold_cow(u1
);
991 if (isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(u2
,
992 &fold_part
, &u1
) < 0)
995 isl_union_pw_qpolynomial_fold_free(u2
);
999 isl_union_pw_qpolynomial_fold_free(u1
);
1000 isl_union_pw_qpolynomial_fold_free(u2
);
1004 __isl_give isl_pw_qpolynomial_fold
*isl_pw_qpolynomial_fold_from_pw_qpolynomial(
1005 enum isl_fold type
, __isl_take isl_pw_qpolynomial
*pwqp
)
1008 isl_pw_qpolynomial_fold
*pwf
;
1013 pwf
= isl_pw_qpolynomial_fold_alloc_size(isl_space_copy(pwqp
->dim
),
1016 for (i
= 0; i
< pwqp
->n
; ++i
)
1017 pwf
= isl_pw_qpolynomial_fold_add_piece(pwf
,
1018 isl_set_copy(pwqp
->p
[i
].set
),
1019 isl_qpolynomial_fold_alloc(type
,
1020 isl_qpolynomial_copy(pwqp
->p
[i
].qp
)));
1022 isl_pw_qpolynomial_free(pwqp
);
1027 __isl_give isl_pw_qpolynomial_fold
*isl_pw_qpolynomial_fold_add(
1028 __isl_take isl_pw_qpolynomial_fold
*pwf1
,
1029 __isl_take isl_pw_qpolynomial_fold
*pwf2
)
1031 return isl_pw_qpolynomial_fold_union_add_(pwf1
, pwf2
);
1034 /* Compare two quasi-polynomial reductions.
1036 * Return -1 if "fold1" is "smaller" than "fold2", 1 if "fold1" is "greater"
1037 * than "fold2" and 0 if they are equal.
1039 int isl_qpolynomial_fold_plain_cmp(__isl_keep isl_qpolynomial_fold
*fold1
,
1040 __isl_keep isl_qpolynomial_fold
*fold2
)
1051 if (fold1
->n
!= fold2
->n
)
1052 return fold1
->n
- fold2
->n
;
1054 for (i
= 0; i
< fold1
->n
; ++i
) {
1057 cmp
= isl_qpolynomial_plain_cmp(fold1
->qp
[i
], fold2
->qp
[i
]);
1065 int isl_qpolynomial_fold_plain_is_equal(__isl_keep isl_qpolynomial_fold
*fold1
,
1066 __isl_keep isl_qpolynomial_fold
*fold2
)
1070 if (!fold1
|| !fold2
)
1073 if (fold1
->n
!= fold2
->n
)
1076 /* We probably want to sort the qps first... */
1077 for (i
= 0; i
< fold1
->n
; ++i
) {
1078 int eq
= isl_qpolynomial_plain_is_equal(fold1
->qp
[i
], fold2
->qp
[i
]);
1086 __isl_give isl_val
*isl_qpolynomial_fold_eval(
1087 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_point
*pnt
)
1094 ctx
= isl_point_get_ctx(pnt
);
1095 isl_assert(pnt
->dim
->ctx
, isl_space_is_equal(pnt
->dim
, fold
->dim
), goto error
);
1096 isl_assert(pnt
->dim
->ctx
,
1097 fold
->type
== isl_fold_max
|| fold
->type
== isl_fold_min
,
1101 v
= isl_val_zero(ctx
);
1104 v
= isl_qpolynomial_eval(isl_qpolynomial_copy(fold
->qp
[0]),
1105 isl_point_copy(pnt
));
1106 for (i
= 1; i
< fold
->n
; ++i
) {
1108 v_i
= isl_qpolynomial_eval(
1109 isl_qpolynomial_copy(fold
->qp
[i
]),
1110 isl_point_copy(pnt
));
1111 if (fold
->type
== isl_fold_max
)
1112 v
= isl_val_max(v
, v_i
);
1114 v
= isl_val_min(v
, v_i
);
1117 isl_qpolynomial_fold_free(fold
);
1118 isl_point_free(pnt
);
1122 isl_qpolynomial_fold_free(fold
);
1123 isl_point_free(pnt
);
1127 size_t isl_pw_qpolynomial_fold_size(__isl_keep isl_pw_qpolynomial_fold
*pwf
)
1132 for (i
= 0; i
< pwf
->n
; ++i
)
1133 n
+= pwf
->p
[i
].fold
->n
;
1138 __isl_give isl_val
*isl_qpolynomial_fold_opt_on_domain(
1139 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_set
*set
, int max
)
1148 opt
= isl_val_zero(isl_set_get_ctx(set
));
1150 isl_qpolynomial_fold_free(fold
);
1154 opt
= isl_qpolynomial_opt_on_domain(isl_qpolynomial_copy(fold
->qp
[0]),
1155 isl_set_copy(set
), max
);
1156 for (i
= 1; i
< fold
->n
; ++i
) {
1158 opt_i
= isl_qpolynomial_opt_on_domain(
1159 isl_qpolynomial_copy(fold
->qp
[i
]),
1160 isl_set_copy(set
), max
);
1162 opt
= isl_val_max(opt
, opt_i
);
1164 opt
= isl_val_min(opt
, opt_i
);
1168 isl_qpolynomial_fold_free(fold
);
1173 isl_qpolynomial_fold_free(fold
);
1177 /* Check whether for each quasi-polynomial in "fold2" there is
1178 * a quasi-polynomial in "fold1" that dominates it on "set".
1180 static int qpolynomial_fold_covers_on_domain(__isl_keep isl_set
*set
,
1181 __isl_keep isl_qpolynomial_fold
*fold1
,
1182 __isl_keep isl_qpolynomial_fold
*fold2
)
1187 if (!set
|| !fold1
|| !fold2
)
1190 covers
= fold1
->type
== isl_fold_max
? 1 : -1;
1192 for (i
= 0; i
< fold2
->n
; ++i
) {
1193 for (j
= 0; j
< fold1
->n
; ++j
) {
1197 d
= isl_qpolynomial_sub(
1198 isl_qpolynomial_copy(fold1
->qp
[j
]),
1199 isl_qpolynomial_copy(fold2
->qp
[i
]));
1200 sgn
= isl_qpolynomial_sign(set
, d
);
1201 isl_qpolynomial_free(d
);
1212 /* Check whether "pwf1" dominated "pwf2", i.e., the domain of "pwf1" contains
1213 * that of "pwf2" and on each cell, the corresponding fold from pwf1 dominates
1216 int isl_pw_qpolynomial_fold_covers(__isl_keep isl_pw_qpolynomial_fold
*pwf1
,
1217 __isl_keep isl_pw_qpolynomial_fold
*pwf2
)
1220 isl_set
*dom1
, *dom2
;
1231 dom1
= isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf1
));
1232 dom2
= isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf2
));
1233 is_subset
= isl_set_is_subset(dom2
, dom1
);
1237 if (is_subset
< 0 || !is_subset
)
1240 for (i
= 0; i
< pwf2
->n
; ++i
) {
1241 for (j
= 0; j
< pwf1
->n
; ++j
) {
1246 common
= isl_set_intersect(isl_set_copy(pwf1
->p
[j
].set
),
1247 isl_set_copy(pwf2
->p
[i
].set
));
1248 is_empty
= isl_set_is_empty(common
);
1249 if (is_empty
< 0 || is_empty
) {
1250 isl_set_free(common
);
1255 covers
= qpolynomial_fold_covers_on_domain(common
,
1256 pwf1
->p
[j
].fold
, pwf2
->p
[i
].fold
);
1257 isl_set_free(common
);
1258 if (covers
< 0 || !covers
)
1266 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_morph_domain(
1267 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_morph
*morph
)
1272 if (!fold
|| !morph
)
1275 ctx
= fold
->dim
->ctx
;
1276 isl_assert(ctx
, isl_space_is_equal(fold
->dim
, morph
->dom
->dim
), goto error
);
1278 fold
= isl_qpolynomial_fold_cow(fold
);
1282 isl_space_free(fold
->dim
);
1283 fold
->dim
= isl_space_copy(morph
->ran
->dim
);
1287 for (i
= 0; i
< fold
->n
; ++i
) {
1288 fold
->qp
[i
] = isl_qpolynomial_morph_domain(fold
->qp
[i
],
1289 isl_morph_copy(morph
));
1294 isl_morph_free(morph
);
1298 isl_qpolynomial_fold_free(fold
);
1299 isl_morph_free(morph
);
1303 enum isl_fold
isl_qpolynomial_fold_get_type(__isl_keep isl_qpolynomial_fold
*fold
)
1306 return isl_fold_list
;
1310 enum isl_fold
isl_union_pw_qpolynomial_fold_get_type(
1311 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
1314 return isl_fold_list
;
1318 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_lift(
1319 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_space
*dim
)
1326 if (isl_space_is_equal(fold
->dim
, dim
)) {
1327 isl_space_free(dim
);
1331 fold
= isl_qpolynomial_fold_cow(fold
);
1335 isl_space_free(fold
->dim
);
1336 fold
->dim
= isl_space_copy(dim
);
1340 for (i
= 0; i
< fold
->n
; ++i
) {
1341 fold
->qp
[i
] = isl_qpolynomial_lift(fold
->qp
[i
],
1342 isl_space_copy(dim
));
1347 isl_space_free(dim
);
1351 isl_qpolynomial_fold_free(fold
);
1352 isl_space_free(dim
);
1356 isl_stat
isl_qpolynomial_fold_foreach_qpolynomial(
1357 __isl_keep isl_qpolynomial_fold
*fold
,
1358 isl_stat (*fn
)(__isl_take isl_qpolynomial
*qp
, void *user
), void *user
)
1363 return isl_stat_error
;
1365 for (i
= 0; i
< fold
->n
; ++i
)
1366 if (fn(isl_qpolynomial_copy(fold
->qp
[i
]), user
) < 0)
1367 return isl_stat_error
;
1372 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_move_dims(
1373 __isl_take isl_qpolynomial_fold
*fold
,
1374 enum isl_dim_type dst_type
, unsigned dst_pos
,
1375 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1378 enum isl_dim_type set_src_type
, set_dst_type
;
1383 fold
= isl_qpolynomial_fold_cow(fold
);
1387 set_src_type
= domain_type(src_type
);
1388 set_dst_type
= domain_type(dst_type
);
1390 fold
->dim
= isl_space_move_dims(fold
->dim
, set_dst_type
, dst_pos
,
1391 set_src_type
, src_pos
, n
);
1395 for (i
= 0; i
< fold
->n
; ++i
) {
1396 fold
->qp
[i
] = isl_qpolynomial_move_dims(fold
->qp
[i
],
1397 dst_type
, dst_pos
, src_type
, src_pos
, n
);
1404 isl_qpolynomial_fold_free(fold
);
1408 /* For each 0 <= i < "n", replace variable "first" + i of type "type"
1409 * in fold->qp[k] by subs[i].
1411 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_substitute(
1412 __isl_take isl_qpolynomial_fold
*fold
,
1413 enum isl_dim_type type
, unsigned first
, unsigned n
,
1414 __isl_keep isl_qpolynomial
**subs
)
1421 fold
= isl_qpolynomial_fold_cow(fold
);
1425 for (i
= 0; i
< fold
->n
; ++i
) {
1426 fold
->qp
[i
] = isl_qpolynomial_substitute(fold
->qp
[i
],
1427 type
, first
, n
, subs
);
1434 isl_qpolynomial_fold_free(fold
);
1438 static isl_stat
add_pwqp(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
1440 isl_pw_qpolynomial_fold
*pwf
;
1441 isl_union_pw_qpolynomial_fold
**upwf
;
1442 struct isl_hash_table_entry
*entry
;
1444 upwf
= (isl_union_pw_qpolynomial_fold
**)user
;
1446 entry
= isl_union_pw_qpolynomial_fold_find_part_entry(*upwf
,
1451 pwf
= isl_pw_qpolynomial_fold_from_pw_qpolynomial((*upwf
)->type
, pwqp
);
1455 entry
->data
= isl_pw_qpolynomial_fold_add(entry
->data
, pwf
);
1457 return isl_stat_error
;
1458 if (isl_pw_qpolynomial_fold_is_zero(entry
->data
))
1459 *upwf
= isl_union_pw_qpolynomial_fold_remove_part_entry(
1465 isl_pw_qpolynomial_free(pwqp
);
1466 return isl_stat_error
;
1469 __isl_give isl_union_pw_qpolynomial_fold
*isl_union_pw_qpolynomial_fold_add_union_pw_qpolynomial(
1470 __isl_take isl_union_pw_qpolynomial_fold
*upwf
,
1471 __isl_take isl_union_pw_qpolynomial
*upwqp
)
1473 upwf
= isl_union_pw_qpolynomial_fold_align_params(upwf
,
1474 isl_union_pw_qpolynomial_get_space(upwqp
));
1475 upwqp
= isl_union_pw_qpolynomial_align_params(upwqp
,
1476 isl_union_pw_qpolynomial_fold_get_space(upwf
));
1478 upwf
= isl_union_pw_qpolynomial_fold_cow(upwf
);
1479 if (!upwf
|| !upwqp
)
1482 if (isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &add_pwqp
,
1486 isl_union_pw_qpolynomial_free(upwqp
);
1490 isl_union_pw_qpolynomial_fold_free(upwf
);
1491 isl_union_pw_qpolynomial_free(upwqp
);
1495 static isl_bool
join_compatible(__isl_keep isl_space
*space1
,
1496 __isl_keep isl_space
*space2
)
1499 m
= isl_space_has_equal_params(space1
, space2
);
1502 return isl_space_tuple_is_equal(space1
, isl_dim_out
,
1503 space2
, isl_dim_in
);
1506 /* Compute the intersection of the range of the map and the domain
1507 * of the piecewise quasipolynomial reduction and then compute a bound
1508 * on the associated quasipolynomial reduction over all elements
1509 * in this intersection.
1511 * We first introduce some unconstrained dimensions in the
1512 * piecewise quasipolynomial, intersect the resulting domain
1513 * with the wrapped map and the compute the sum.
1515 __isl_give isl_pw_qpolynomial_fold
*isl_map_apply_pw_qpolynomial_fold(
1516 __isl_take isl_map
*map
, __isl_take isl_pw_qpolynomial_fold
*pwf
,
1526 ctx
= isl_map_get_ctx(map
);
1530 map_dim
= isl_map_get_space(map
);
1531 pwf_dim
= isl_pw_qpolynomial_fold_get_space(pwf
);
1532 ok
= join_compatible(map_dim
, pwf_dim
);
1533 isl_space_free(map_dim
);
1534 isl_space_free(pwf_dim
);
1538 isl_die(ctx
, isl_error_invalid
, "incompatible dimensions",
1541 n_in
= isl_map_dim(map
, isl_dim_in
);
1542 pwf
= isl_pw_qpolynomial_fold_insert_dims(pwf
, isl_dim_in
, 0, n_in
);
1544 dom
= isl_map_wrap(map
);
1545 pwf
= isl_pw_qpolynomial_fold_reset_domain_space(pwf
,
1546 isl_set_get_space(dom
));
1548 pwf
= isl_pw_qpolynomial_fold_intersect_domain(pwf
, dom
);
1549 pwf
= isl_pw_qpolynomial_fold_bound(pwf
, tight
);
1554 isl_pw_qpolynomial_fold_free(pwf
);
1558 __isl_give isl_pw_qpolynomial_fold
*isl_set_apply_pw_qpolynomial_fold(
1559 __isl_take isl_set
*set
, __isl_take isl_pw_qpolynomial_fold
*pwf
,
1562 return isl_map_apply_pw_qpolynomial_fold(set
, pwf
, tight
);
1565 struct isl_apply_fold_data
{
1566 isl_union_pw_qpolynomial_fold
*upwf
;
1567 isl_union_pw_qpolynomial_fold
*res
;
1572 static isl_stat
pw_qpolynomial_fold_apply(
1573 __isl_take isl_pw_qpolynomial_fold
*pwf
, void *user
)
1577 struct isl_apply_fold_data
*data
= user
;
1580 map_dim
= isl_map_get_space(data
->map
);
1581 pwf_dim
= isl_pw_qpolynomial_fold_get_space(pwf
);
1582 ok
= join_compatible(map_dim
, pwf_dim
);
1583 isl_space_free(map_dim
);
1584 isl_space_free(pwf_dim
);
1587 return isl_stat_error
;
1589 pwf
= isl_map_apply_pw_qpolynomial_fold(isl_map_copy(data
->map
),
1590 pwf
, data
->tight
? &data
->tight
: NULL
);
1591 data
->res
= isl_union_pw_qpolynomial_fold_fold_pw_qpolynomial_fold(
1594 isl_pw_qpolynomial_fold_free(pwf
);
1599 static isl_stat
map_apply(__isl_take isl_map
*map
, void *user
)
1601 struct isl_apply_fold_data
*data
= user
;
1605 r
= isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(
1606 data
->upwf
, &pw_qpolynomial_fold_apply
, data
);
1612 __isl_give isl_union_pw_qpolynomial_fold
*isl_union_map_apply_union_pw_qpolynomial_fold(
1613 __isl_take isl_union_map
*umap
,
1614 __isl_take isl_union_pw_qpolynomial_fold
*upwf
, int *tight
)
1618 struct isl_apply_fold_data data
;
1620 upwf
= isl_union_pw_qpolynomial_fold_align_params(upwf
,
1621 isl_union_map_get_space(umap
));
1622 umap
= isl_union_map_align_params(umap
,
1623 isl_union_pw_qpolynomial_fold_get_space(upwf
));
1626 data
.tight
= tight
? 1 : 0;
1627 dim
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
1628 type
= isl_union_pw_qpolynomial_fold_get_type(upwf
);
1629 data
.res
= isl_union_pw_qpolynomial_fold_zero(dim
, type
);
1630 if (isl_union_map_foreach_map(umap
, &map_apply
, &data
) < 0)
1633 isl_union_map_free(umap
);
1634 isl_union_pw_qpolynomial_fold_free(upwf
);
1637 *tight
= data
.tight
;
1641 isl_union_map_free(umap
);
1642 isl_union_pw_qpolynomial_fold_free(upwf
);
1643 isl_union_pw_qpolynomial_fold_free(data
.res
);
1647 __isl_give isl_union_pw_qpolynomial_fold
*isl_union_set_apply_union_pw_qpolynomial_fold(
1648 __isl_take isl_union_set
*uset
,
1649 __isl_take isl_union_pw_qpolynomial_fold
*upwf
, int *tight
)
1651 return isl_union_map_apply_union_pw_qpolynomial_fold(uset
, upwf
, tight
);
1654 /* Reorder the dimension of "fold" according to the given reordering.
1656 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_realign_domain(
1657 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_reordering
*r
)
1662 fold
= isl_qpolynomial_fold_cow(fold
);
1666 for (i
= 0; i
< fold
->n
; ++i
) {
1667 fold
->qp
[i
] = isl_qpolynomial_realign_domain(fold
->qp
[i
],
1668 isl_reordering_copy(r
));
1673 space
= isl_reordering_get_space(r
);
1674 fold
= isl_qpolynomial_fold_reset_domain_space(fold
, space
);
1676 isl_reordering_free(r
);
1680 isl_qpolynomial_fold_free(fold
);
1681 isl_reordering_free(r
);
1685 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_mul_isl_int(
1686 __isl_take isl_qpolynomial_fold
*fold
, isl_int v
)
1690 if (isl_int_is_one(v
))
1692 if (fold
&& isl_int_is_zero(v
)) {
1693 isl_qpolynomial_fold
*zero
;
1694 isl_space
*dim
= isl_space_copy(fold
->dim
);
1695 zero
= isl_qpolynomial_fold_empty(fold
->type
, dim
);
1696 isl_qpolynomial_fold_free(fold
);
1700 fold
= isl_qpolynomial_fold_cow(fold
);
1704 if (isl_int_is_neg(v
))
1705 fold
->type
= isl_fold_type_negate(fold
->type
);
1706 for (i
= 0; i
< fold
->n
; ++i
) {
1707 fold
->qp
[i
] = isl_qpolynomial_mul_isl_int(fold
->qp
[i
], v
);
1714 isl_qpolynomial_fold_free(fold
);
1718 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_scale(
1719 __isl_take isl_qpolynomial_fold
*fold
, isl_int v
)
1721 return isl_qpolynomial_fold_mul_isl_int(fold
, v
);
1724 /* Multiply "fold" by "v".
1726 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_scale_val(
1727 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_val
*v
)
1734 if (isl_val_is_one(v
)) {
1738 if (isl_val_is_zero(v
)) {
1739 isl_qpolynomial_fold
*zero
;
1740 isl_space
*space
= isl_qpolynomial_fold_get_domain_space(fold
);
1741 zero
= isl_qpolynomial_fold_empty(fold
->type
, space
);
1742 isl_qpolynomial_fold_free(fold
);
1746 if (!isl_val_is_rat(v
))
1747 isl_die(isl_qpolynomial_fold_get_ctx(fold
), isl_error_invalid
,
1748 "expecting rational factor", goto error
);
1750 fold
= isl_qpolynomial_fold_cow(fold
);
1754 if (isl_val_is_neg(v
))
1755 fold
->type
= isl_fold_type_negate(fold
->type
);
1756 for (i
= 0; i
< fold
->n
; ++i
) {
1757 fold
->qp
[i
] = isl_qpolynomial_scale_val(fold
->qp
[i
],
1767 isl_qpolynomial_fold_free(fold
);
1771 /* Divide "fold" by "v".
1773 __isl_give isl_qpolynomial_fold
*isl_qpolynomial_fold_scale_down_val(
1774 __isl_take isl_qpolynomial_fold
*fold
, __isl_take isl_val
*v
)
1779 if (isl_val_is_one(v
)) {
1783 if (!isl_val_is_rat(v
))
1784 isl_die(isl_qpolynomial_fold_get_ctx(fold
), isl_error_invalid
,
1785 "expecting rational factor", goto error
);
1786 if (isl_val_is_zero(v
))
1787 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
1788 "cannot scale down by zero", goto error
);
1790 return isl_qpolynomial_fold_scale_val(fold
, isl_val_inv(v
));
1793 isl_qpolynomial_fold_free(fold
);