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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
Copyright (C) 2012 Fredrik Johansson
This file is part of FLINT.
FLINT 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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "acb.h"
void
acb_mul_naive(acb_t z, const acb_t x, const acb_t y, slong prec)
{
#define a acb_realref(x)
#define b acb_imagref(x)
#define c acb_realref(y)
#define d acb_imagref(y)
#define e acb_realref(z)
#define f acb_imagref(z)
if (arb_is_zero(b))
{
arb_mul(f, d, a, prec);
arb_mul(e, c, a, prec);
}
else if (arb_is_zero(d))
{
arb_mul(f, b, c, prec);
arb_mul(e, a, c, prec);
}
else if (arb_is_zero(a))
{
arb_mul(e, c, b, prec);
arb_mul(f, d, b, prec);
acb_mul_onei(z, z);
}
else if (arb_is_zero(c))
{
arb_mul(e, a, d, prec);
arb_mul(f, b, d, prec);
acb_mul_onei(z, z);
}
/* squaring = a^2-b^2, 2ab */
else if (x == y)
{
/* aliasing */
if (z == x)
{
arb_t t;
arb_init(t);
arb_mul(t, a, b, prec);
arb_mul_2exp_si(t, t, 1);
arb_mul(e, a, a, prec);
arb_mul(f, b, b, prec);
arb_sub(e, e, f, prec);
arb_swap(f, t);
arb_clear(t);
}
else
{
arb_mul(e, a, a, prec);
arb_mul(f, b, b, prec);
arb_sub(e, e, f, prec);
arb_mul(f, a, b, prec);
arb_mul_2exp_si(f, f, 1);
}
}
else
{
/* aliasing */
if (z == x)
{
arb_t t, u;
arb_init(t);
arb_init(u);
arb_mul(t, a, c, prec);
arb_mul(u, a, d, prec);
arb_mul(e, b, d, prec);
arb_sub(e, t, e, prec);
arb_mul(f, b, c, prec);
arb_add(f, u, f, prec);
arb_clear(t);
arb_clear(u);
}
else if (z == y)
{
arb_t t, u;
arb_init(t);
arb_init(u);
arb_mul(t, a, c, prec);
arb_mul(u, b, c, prec);
arb_mul(e, b, d, prec);
arb_sub(e, t, e, prec);
arb_mul(f, a, d, prec);
arb_add(f, u, f, prec);
arb_clear(t);
arb_clear(u);
}
else
{
arb_t t;
arb_init(t);
arb_mul(e, a, c, prec);
arb_mul(t, b, d, prec);
arb_sub(e, e, t, prec);
arb_mul(f, a, d, prec);
arb_mul(t, b, c, prec);
arb_add(f, f, t, prec);
arb_clear(t);
}
}
#undef a
#undef b
#undef c
#undef d
#undef e
#undef f
}