File: equal.c

package info (click to toggle)
calcium 0.4.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,756 kB
  • sloc: ansic: 62,836; python: 2,827; sh: 518; makefile: 163
file content (73 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
    Copyright (C) 2020 Fredrik Johansson

    This file is part of Calcium.

    Calcium is free software: you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.  See <http://www.gnu.org/licenses/>.
*/

#include "qqbar.h"

int
qqbar_equal(const qqbar_t x, const qqbar_t y)
{
    slong prec;
    acb_t z1, z2, z3;
    int res;

    if (x == y)
        return 1;

    if (!fmpz_poly_equal(QQBAR_POLY(x), QQBAR_POLY(y)))
        return 0;

    if (qqbar_degree(x) == 1)
        return 1;

    if (!acb_overlaps(QQBAR_ENCLOSURE(x), QQBAR_ENCLOSURE(y)))
        return 0;

    if (acb_contains(QQBAR_ENCLOSURE(x), QQBAR_ENCLOSURE(y)))
        return 1;

    if (acb_contains(QQBAR_ENCLOSURE(y), QQBAR_ENCLOSURE(x)))
        return 1;

    acb_init(z1);
    acb_init(z2);
    acb_init(z3);

    acb_set(z1, QQBAR_ENCLOSURE(x));
    acb_set(z2, QQBAR_ENCLOSURE(y));

    res = 0;
    for (prec = QQBAR_DEFAULT_PREC / 2; ; prec *= 2)
    {
        _qqbar_enclosure_raw(z1, QQBAR_POLY(x), z1, prec);
        _qqbar_enclosure_raw(z2, QQBAR_POLY(y), z2, prec);

        if (!acb_overlaps(z1, z2))
        {
            res = 0;
            break;
        }

        acb_union(z3, z1, z2, prec);

        if (_qqbar_validate_uniqueness(z3, QQBAR_POLY(x), z3, 2 * prec))
        {
            res = 1;
            break;
        }
    }

    acb_clear(z1);
    acb_clear(z2);
    acb_clear(z3);

    return res;
}