Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

## -*- encoding: utf-8 -*- 

""" 

Doctests from French Sage book 

Test file for chapter "Domaines de calcul" ("Computation Domains") 

 

Tests extracted from ./domaines.tex. 

 

Sage example in ./domaines.tex, line 6:: 

 

sage: x = var('x') 

 

Sage example in ./domaines.tex, line 38:: 

 

sage: o = 12/35 

sage: type(o) 

<type 'sage.rings.rational.Rational'> 

 

Sage example in ./domaines.tex, line 45:: 

 

sage: type(12/35) 

<type 'sage.rings.rational.Rational'> 

 

Sage example in ./domaines.tex, line 77:: 

 

sage: o = 720 

sage: o.factor() 

2^4 * 3^2 * 5 

 

Sage example in ./domaines.tex, line 85:: 

 

sage: type(o).factor(o) 

2^4 * 3^2 * 5 

 

Sage example in ./domaines.tex, line 95:: 

 

sage: 720.factor() 

2^4 * 3^2 * 5 

 

Sage example in ./domaines.tex, line 102:: 

 

sage: o = 720 / 133 

sage: o.numerator().factor() 

2^4 * 3^2 * 5 

 

Sage example in ./domaines.tex, line 140:: 

 

sage: 3 * 7 

21 

 

Sage example in ./domaines.tex, line 146:: 

 

sage: (2/3) * (6/5) 

4/5 

 

Sage example in ./domaines.tex, line 151:: 

 

sage: (1 + I) * (1 - I) 

2 

 

Sage example in ./domaines.tex, line 156:: 

 

sage: (x + 2) * (x + 1) 

(x + 2)*(x + 1) 

sage: (x + 1) * (x + 2) 

(x + 2)*(x + 1) 

 

Sage example in ./domaines.tex, line 177:: 

 

sage: def puissance_quatre(a): 

....: a = a * a 

....: a = a * a 

....: return a 

 

Sage example in ./domaines.tex, line 185:: 

 

sage: puissance_quatre(2) 

16 

sage: puissance_quatre(3/2) 

81/16 

sage: puissance_quatre(I) 

1 

sage: puissance_quatre(x+1) 

(x + 1)^4 

sage: M = matrix([[0,-1],[1,0]]); M 

[ 0 -1] 

[ 1 0] 

sage: puissance_quatre(M) 

[1 0] 

[0 1] 

 

Sage example in ./domaines.tex, line 215:: 

 

sage: t = type(5/1); t 

<type 'sage.rings.rational.Rational'> 

sage: t == type(5) 

False 

 

Sage example in ./domaines.tex, line 288:: 

 

sage: a = 5; a 

5 

sage: a.is_unit() 

False 

 

Sage example in ./domaines.tex, line 295:: 

 

sage: a = 5/1; a 

5 

sage: a.is_unit() 

True 

 

Sage example in ./domaines.tex, line 311:: 

 

sage: parent(5) 

Integer Ring 

sage: parent(5/1) 

Rational Field 

 

Sage example in ./domaines.tex, line 318:: 

 

sage: ZZ 

Integer Ring 

sage: QQ 

Rational Field 

 

Sage example in ./domaines.tex, line 326:: 

 

sage: QQ(5).parent() 

Rational Field 

sage: ZZ(5/1).parent() 

Integer Ring 

sage: ZZ(1/5) 

Traceback (most recent call last): 

... 

TypeError: no conversion of this rational to integer 

 

Sage example in ./domaines.tex, line 340:: 

 

sage: ZZ(1), QQ(1), RR(1), CC(1) 

(1, 1, 1.00000000000000, 1.00000000000000) 

 

Sage example in ./domaines.tex, line 355:: 

 

sage: cartesian_product([QQ, QQ]) 

The Cartesian product of (Rational Field, Rational Field) 

 

Sage example in ./domaines.tex, line 360:: 

 

sage: ZZ.fraction_field() 

Rational Field 

 

Sage example in ./domaines.tex, line 365:: 

 

sage: ZZ['x'] 

Univariate Polynomial Ring in x over Integer Ring 

 

Sage example in ./domaines.tex, line 373:: 

 

sage: Z5 = GF(5); Z5 

Finite Field of size 5 

sage: P = Z5['x']; P 

Univariate Polynomial Ring in x over Finite Field of size 5 

sage: M = MatrixSpace(P, 3, 3); M 

Full MatrixSpace of 3 by 3 dense matrices over 

Univariate Polynomial Ring in x over Finite Field of size 5 

 

Sage example in ./domaines.tex, line 383:: 

 

sage: M.random_element() # random 

[2*x^2 + 3*x + 4 4*x^2 + 2*x + 2 4*x^2 + 2*x] 

[ 3*x 2*x^2 + x + 3 3*x^2 + 4*x] 

[ 4*x^2 + 3 3*x^2 + 2*x + 4 2*x + 4] 

 

Sage example in ./domaines.tex, line 415:: 

 

sage: QQ.category() 

Join of Category of number fields 

and Category of quotient fields 

and Category of metric spaces 

 

Sage example in ./domaines.tex, line 421:: 

 

sage: QQ in Fields() 

True 

 

Sage example in ./domaines.tex, line 427:: 

 

sage: QQ in CommutativeAdditiveGroups() 

True 

 

Sage example in ./domaines.tex, line 432:: 

 

sage: QQ['x'] in EuclideanDomains() 

True 

 

Sage example in ./domaines.tex, line 514:: 

 

sage: 5.parent() 

Integer Ring 

 

Sage example in ./domaines.tex, line 521:: 

 

sage: type(factor(4)) 

<class 'sage.structure.factorization_integer.IntegerFactorization'> 

 

Sage example in ./domaines.tex, line 532:: 

 

sage: int(5) 

5 

sage: type(int(5)) 

<... 'int'> 

 

Sage example in ./domaines.tex, line 539:: 

 

sage: Integer(5) 

5 

sage: type(Integer(5)) 

<type 'sage.rings.integer.Integer'> 

 

Sage example in ./domaines.tex, line 551:: 

 

sage: factorial(99) / factorial(100) - 1 / 50 

-1/100 

 

Sage example in ./domaines.tex, line 574:: 

 

sage: 72/53-5/3*2.7 

-3.14150943396227 

 

Sage example in ./domaines.tex, line 580:: 

 

sage: cos(1), cos(1.) 

(cos(1), 0.540302305868140) 

 

Sage example in ./domaines.tex, line 589:: 

 

sage: pi.n(digits=50) # N(pi,digits=10^6) aussi possible 

3.1415926535897932384626433832795028841971693993751 

 

Sage example in ./domaines.tex, line 600:: 

 

sage: z = CC(1,2); z.arg() 

1.10714871779409 

 

Sage example in ./domaines.tex, line 608:: 

 

sage: I.parent() 

Symbolic Ring 

 

Sage example in ./domaines.tex, line 613:: 

 

sage: (1.+2.*I).parent() 

Symbolic Ring 

sage: CC(1.+2.*I).parent() 

Complex Field with 53 bits of precision 

 

Sage example in ./domaines.tex, line 623:: 

 

sage: z = 3 * exp(I*pi/4) 

sage: z.real(), z.imag(), z.abs().canonicalize_radical() 

(3/2*sqrt(2), 3/2*sqrt(2), 3) 

 

Sage example in ./domaines.tex, line 679:: 

 

sage: x, y = var('x, y') 

sage: bool( (x-y)*(x+y) == x^2-y^2 ) 

True 

 

Sage example in ./domaines.tex, line 697:: 

 

sage: Z4 = IntegerModRing(4); Z4 

Ring of integers modulo 4 

sage: m = Z4(7); m 

3 

 

Sage example in ./domaines.tex, line 706:: 

 

sage: 3 * m + 1 

2 

 

Sage example in ./domaines.tex, line 712:: 

 

sage: Z3 = GF(3); Z3 

Finite Field of size 3 

 

Sage example in ./domaines.tex, line 740:: 

 

sage: a = matrix(QQ, [[1,2,3],[2,4,8],[3,9,27]]) 

sage: (a^2 + 1) * a^(-1) 

[ -5 13/2 7/3] 

[ 7 1 25/3] 

[ 2 19/2 27] 

 

Sage example in ./domaines.tex, line 752:: 

 

sage: M = MatrixSpace(QQ,3,3) 

sage: M 

Full MatrixSpace of 3 by 3 dense matrices over Rational Field 

sage: a = M([[1,2,3],[2,4,8],[3,9,27]]) 

sage: (a^2 + 1) * a^(-1) 

[ -5 13/2 7/3] 

[ 7 1 25/3] 

[ 2 19/2 27] 

 

Sage example in ./domaines.tex, line 771:: 

 

sage: P = ZZ['x']; P 

Univariate Polynomial Ring in x over Integer Ring 

sage: F = P.fraction_field(); F 

Fraction Field of 

Univariate Polynomial Ring in x over Integer Ring 

sage: p = P(x+1) * P(x); p 

x^2 + x 

sage: p + 1/p 

(x^4 + 2*x^3 + x^2 + 1)/(x^2 + x) 

sage: parent(p + 1/p) 

Fraction Field of 

Univariate Polynomial Ring in x over Integer Ring 

 

Sage example in ./domaines.tex, line 826:: 

 

sage: k.<a> = NumberField(x^3 + x + 1); a^3; a^4+3*a 

-a - 1 

-a^2 + 2*a 

 

Sage example in ./domaines.tex, line 845:: 

 

sage: parent(sin(x)) 

Symbolic Ring 

 

Sage example in ./domaines.tex, line 850:: 

 

sage: SR 

Symbolic Ring 

 

Sage example in ./domaines.tex, line 855:: 

 

sage: SR.category() 

Category of commutative rings 

 

Sage example in ./domaines.tex, line 884:: 

 

sage: R = QQ['x1,x2,x3,x4']; R 

Multivariate Polynomial Ring in x1, x2, x3, x4 over Rational Field 

sage: x1, x2, x3, x4 = R.gens() 

 

Sage example in ./domaines.tex, line 890:: 

 

sage: x1 * (x2 - x3) 

x1*x2 - x1*x3 

 

Sage example in ./domaines.tex, line 895:: 

 

sage: (x1+x2)*(x1-x2) - (x1^2 -x2^2) 

0 

 

Sage example in ./domaines.tex, line 902:: 

 

sage: prod( (a-b) for (a,b) in Subsets([x1,x2,x3,x4],2) ) 

x1^3*x2^2*x3 - x1^2*x2^3*x3 - x1^3*x2*x3^2 + x1*x2^3*x3^2 

+ x1^2*x2*x3^3 - x1*x2^2*x3^3 - x1^3*x2^2*x4 + x1^2*x2^3*x4 

+ x1^3*x3^2*x4 - x2^3*x3^2*x4 - x1^2*x3^3*x4 + x2^2*x3^3*x4 

+ x1^3*x2*x4^2 - x1*x2^3*x4^2 - x1^3*x3*x4^2 + x2^3*x3*x4^2 

+ x1*x3^3*x4^2 - x2*x3^3*x4^2 - x1^2*x2*x4^3 + x1*x2^2*x4^3 

+ x1^2*x3*x4^3 - x2^2*x3*x4^3 - x1*x3^2*x4^3 + x2*x3^2*x4^3 

 

Sage example in ./domaines.tex, line 914:: 

 

# example slightly modified with respect to the book, since on some 

# machines we get a negative sign 

sage: x1, x2, x3, x4 = SR.var('x1, x2, x3, x4') 

sage: p = prod( (a-b) for (a,b) in Subsets([x1,x2,x3,x4],2) ) 

sage: bool(p == (x1 - x2)*(x1 - x3)*(x1 - x4)*(x2 - x3)*(x2 - x4)*(x3 - x4)) or bool(p == -(x1 - x2)*(x1 - x3)*(x1 - x4)*(x2 - x3)*(x2 - x4)*(x3 - x4)) 

True 

 

Sage example in ./domaines.tex, line 938:: 

 

sage: x = var('x') 

sage: p = 54*x^4+36*x^3-102*x^2-72*x-12 

sage: factor(p) 

6*(x^2 - 2)*(3*x + 1)^2 

 

Sage example in ./domaines.tex, line 963:: 

 

sage: R = ZZ['x']; R 

Univariate Polynomial Ring in x over Integer Ring 

 

Sage example in ./domaines.tex, line 968:: 

 

sage: q = R(p); q 

54*x^4 + 36*x^3 - 102*x^2 - 72*x - 12 

 

Sage example in ./domaines.tex, line 974:: 

 

sage: parent(q) 

Univariate Polynomial Ring in x over Integer Ring 

 

Sage example in ./domaines.tex, line 979:: 

 

sage: factor(q) 

2 * 3 * (3*x + 1)^2 * (x^2 - 2) 

 

Sage example in ./domaines.tex, line 985:: 

 

sage: R = QQ['x']; R 

Univariate Polynomial Ring in x over Rational Field 

sage: q = R(p); q 

54*x^4 + 36*x^3 - 102*x^2 - 72*x - 12 

sage: factor(q) 

(54) * (x + 1/3)^2 * (x^2 - 2) 

 

Sage example in ./domaines.tex, line 1001:: 

 

sage: R = ComplexField(16)['x']; R 

Univariate Polynomial Ring in x over Complex Field 

with 16 bits of precision 

sage: q = R(p); q 

54.00*x^4 + 36.00*x^3 - 102.0*x^2 - 72.00*x - 12.00 

sage: factor(q) 

(54.00) * (x - 1.414) * (x + 0.3333)^2 * (x + 1.414) 

 

Sage example in ./domaines.tex, line 1012:: 

 

sage: R = QQ[sqrt(2)]['x']; R 

Univariate Polynomial Ring in x over Number Field in sqrt2 

with defining polynomial x^2 - 2 

sage: q = R(p); q 

54*x^4 + 36*x^3 - 102*x^2 - 72*x - 12 

sage: factor(q) 

(54) * (x - sqrt2) * (x + sqrt2) * (x + 1/3)^2 

 

Sage example in ./domaines.tex, line 1025:: 

 

sage: R = GF(5)['x']; R 

Univariate Polynomial Ring in x over Finite Field of size 5 

sage: q = R(p); q 

4*x^4 + x^3 + 3*x^2 + 3*x + 3 

sage: factor(q) 

(4) * (x + 2)^2 * (x^2 + 3) 

 

"""