test_assumptions.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. from sympy.core.mod import Mod
  2. from sympy.core.numbers import (I, oo, pi)
  3. from sympy.functions.combinatorial.factorials import factorial
  4. from sympy.functions.elementary.exponential import (exp, log)
  5. from sympy.functions.elementary.miscellaneous import sqrt
  6. from sympy.functions.elementary.trigonometric import (asin, sin)
  7. from sympy.simplify.simplify import simplify
  8. from sympy.core import Symbol, S, Rational, Integer, Dummy, Wild, Pow
  9. from sympy.core.assumptions import (assumptions, check_assumptions,
  10. failing_assumptions, common_assumptions, _generate_assumption_rules,
  11. _load_pre_generated_assumption_rules)
  12. from sympy.core.facts import InconsistentAssumptions
  13. from sympy.core.random import seed
  14. from sympy.combinatorics import Permutation
  15. from sympy.combinatorics.perm_groups import PermutationGroup
  16. from sympy.testing.pytest import raises, XFAIL
  17. def test_symbol_unset():
  18. x = Symbol('x', real=True, integer=True)
  19. assert x.is_real is True
  20. assert x.is_integer is True
  21. assert x.is_imaginary is False
  22. assert x.is_noninteger is False
  23. assert x.is_number is False
  24. def test_zero():
  25. z = Integer(0)
  26. assert z.is_commutative is True
  27. assert z.is_integer is True
  28. assert z.is_rational is True
  29. assert z.is_algebraic is True
  30. assert z.is_transcendental is False
  31. assert z.is_real is True
  32. assert z.is_complex is True
  33. assert z.is_noninteger is False
  34. assert z.is_irrational is False
  35. assert z.is_imaginary is False
  36. assert z.is_positive is False
  37. assert z.is_negative is False
  38. assert z.is_nonpositive is True
  39. assert z.is_nonnegative is True
  40. assert z.is_even is True
  41. assert z.is_odd is False
  42. assert z.is_finite is True
  43. assert z.is_infinite is False
  44. assert z.is_comparable is True
  45. assert z.is_prime is False
  46. assert z.is_composite is False
  47. assert z.is_number is True
  48. def test_one():
  49. z = Integer(1)
  50. assert z.is_commutative is True
  51. assert z.is_integer is True
  52. assert z.is_rational is True
  53. assert z.is_algebraic is True
  54. assert z.is_transcendental is False
  55. assert z.is_real is True
  56. assert z.is_complex is True
  57. assert z.is_noninteger is False
  58. assert z.is_irrational is False
  59. assert z.is_imaginary is False
  60. assert z.is_positive is True
  61. assert z.is_negative is False
  62. assert z.is_nonpositive is False
  63. assert z.is_nonnegative is True
  64. assert z.is_even is False
  65. assert z.is_odd is True
  66. assert z.is_finite is True
  67. assert z.is_infinite is False
  68. assert z.is_comparable is True
  69. assert z.is_prime is False
  70. assert z.is_number is True
  71. assert z.is_composite is False # issue 8807
  72. def test_negativeone():
  73. z = Integer(-1)
  74. assert z.is_commutative is True
  75. assert z.is_integer is True
  76. assert z.is_rational is True
  77. assert z.is_algebraic is True
  78. assert z.is_transcendental is False
  79. assert z.is_real is True
  80. assert z.is_complex is True
  81. assert z.is_noninteger is False
  82. assert z.is_irrational is False
  83. assert z.is_imaginary is False
  84. assert z.is_positive is False
  85. assert z.is_negative is True
  86. assert z.is_nonpositive is True
  87. assert z.is_nonnegative is False
  88. assert z.is_even is False
  89. assert z.is_odd is True
  90. assert z.is_finite is True
  91. assert z.is_infinite is False
  92. assert z.is_comparable is True
  93. assert z.is_prime is False
  94. assert z.is_composite is False
  95. assert z.is_number is True
  96. def test_infinity():
  97. oo = S.Infinity
  98. assert oo.is_commutative is True
  99. assert oo.is_integer is False
  100. assert oo.is_rational is False
  101. assert oo.is_algebraic is False
  102. assert oo.is_transcendental is False
  103. assert oo.is_extended_real is True
  104. assert oo.is_real is False
  105. assert oo.is_complex is False
  106. assert oo.is_noninteger is True
  107. assert oo.is_irrational is False
  108. assert oo.is_imaginary is False
  109. assert oo.is_nonzero is False
  110. assert oo.is_positive is False
  111. assert oo.is_negative is False
  112. assert oo.is_nonpositive is False
  113. assert oo.is_nonnegative is False
  114. assert oo.is_extended_nonzero is True
  115. assert oo.is_extended_positive is True
  116. assert oo.is_extended_negative is False
  117. assert oo.is_extended_nonpositive is False
  118. assert oo.is_extended_nonnegative is True
  119. assert oo.is_even is False
  120. assert oo.is_odd is False
  121. assert oo.is_finite is False
  122. assert oo.is_infinite is True
  123. assert oo.is_comparable is True
  124. assert oo.is_prime is False
  125. assert oo.is_composite is False
  126. assert oo.is_number is True
  127. def test_neg_infinity():
  128. mm = S.NegativeInfinity
  129. assert mm.is_commutative is True
  130. assert mm.is_integer is False
  131. assert mm.is_rational is False
  132. assert mm.is_algebraic is False
  133. assert mm.is_transcendental is False
  134. assert mm.is_extended_real is True
  135. assert mm.is_real is False
  136. assert mm.is_complex is False
  137. assert mm.is_noninteger is True
  138. assert mm.is_irrational is False
  139. assert mm.is_imaginary is False
  140. assert mm.is_nonzero is False
  141. assert mm.is_positive is False
  142. assert mm.is_negative is False
  143. assert mm.is_nonpositive is False
  144. assert mm.is_nonnegative is False
  145. assert mm.is_extended_nonzero is True
  146. assert mm.is_extended_positive is False
  147. assert mm.is_extended_negative is True
  148. assert mm.is_extended_nonpositive is True
  149. assert mm.is_extended_nonnegative is False
  150. assert mm.is_even is False
  151. assert mm.is_odd is False
  152. assert mm.is_finite is False
  153. assert mm.is_infinite is True
  154. assert mm.is_comparable is True
  155. assert mm.is_prime is False
  156. assert mm.is_composite is False
  157. assert mm.is_number is True
  158. def test_zoo():
  159. zoo = S.ComplexInfinity
  160. assert zoo.is_complex is False
  161. assert zoo.is_real is False
  162. assert zoo.is_prime is False
  163. def test_nan():
  164. nan = S.NaN
  165. assert nan.is_commutative is True
  166. assert nan.is_integer is None
  167. assert nan.is_rational is None
  168. assert nan.is_algebraic is None
  169. assert nan.is_transcendental is None
  170. assert nan.is_real is None
  171. assert nan.is_complex is None
  172. assert nan.is_noninteger is None
  173. assert nan.is_irrational is None
  174. assert nan.is_imaginary is None
  175. assert nan.is_positive is None
  176. assert nan.is_negative is None
  177. assert nan.is_nonpositive is None
  178. assert nan.is_nonnegative is None
  179. assert nan.is_even is None
  180. assert nan.is_odd is None
  181. assert nan.is_finite is None
  182. assert nan.is_infinite is None
  183. assert nan.is_comparable is False
  184. assert nan.is_prime is None
  185. assert nan.is_composite is None
  186. assert nan.is_number is True
  187. def test_pos_rational():
  188. r = Rational(3, 4)
  189. assert r.is_commutative is True
  190. assert r.is_integer is False
  191. assert r.is_rational is True
  192. assert r.is_algebraic is True
  193. assert r.is_transcendental is False
  194. assert r.is_real is True
  195. assert r.is_complex is True
  196. assert r.is_noninteger is True
  197. assert r.is_irrational is False
  198. assert r.is_imaginary is False
  199. assert r.is_positive is True
  200. assert r.is_negative is False
  201. assert r.is_nonpositive is False
  202. assert r.is_nonnegative is True
  203. assert r.is_even is False
  204. assert r.is_odd is False
  205. assert r.is_finite is True
  206. assert r.is_infinite is False
  207. assert r.is_comparable is True
  208. assert r.is_prime is False
  209. assert r.is_composite is False
  210. r = Rational(1, 4)
  211. assert r.is_nonpositive is False
  212. assert r.is_positive is True
  213. assert r.is_negative is False
  214. assert r.is_nonnegative is True
  215. r = Rational(5, 4)
  216. assert r.is_negative is False
  217. assert r.is_positive is True
  218. assert r.is_nonpositive is False
  219. assert r.is_nonnegative is True
  220. r = Rational(5, 3)
  221. assert r.is_nonnegative is True
  222. assert r.is_positive is True
  223. assert r.is_negative is False
  224. assert r.is_nonpositive is False
  225. def test_neg_rational():
  226. r = Rational(-3, 4)
  227. assert r.is_positive is False
  228. assert r.is_nonpositive is True
  229. assert r.is_negative is True
  230. assert r.is_nonnegative is False
  231. r = Rational(-1, 4)
  232. assert r.is_nonpositive is True
  233. assert r.is_positive is False
  234. assert r.is_negative is True
  235. assert r.is_nonnegative is False
  236. r = Rational(-5, 4)
  237. assert r.is_negative is True
  238. assert r.is_positive is False
  239. assert r.is_nonpositive is True
  240. assert r.is_nonnegative is False
  241. r = Rational(-5, 3)
  242. assert r.is_nonnegative is False
  243. assert r.is_positive is False
  244. assert r.is_negative is True
  245. assert r.is_nonpositive is True
  246. def test_pi():
  247. z = S.Pi
  248. assert z.is_commutative is True
  249. assert z.is_integer is False
  250. assert z.is_rational is False
  251. assert z.is_algebraic is False
  252. assert z.is_transcendental is True
  253. assert z.is_real is True
  254. assert z.is_complex is True
  255. assert z.is_noninteger is True
  256. assert z.is_irrational is True
  257. assert z.is_imaginary is False
  258. assert z.is_positive is True
  259. assert z.is_negative is False
  260. assert z.is_nonpositive is False
  261. assert z.is_nonnegative is True
  262. assert z.is_even is False
  263. assert z.is_odd is False
  264. assert z.is_finite is True
  265. assert z.is_infinite is False
  266. assert z.is_comparable is True
  267. assert z.is_prime is False
  268. assert z.is_composite is False
  269. def test_E():
  270. z = S.Exp1
  271. assert z.is_commutative is True
  272. assert z.is_integer is False
  273. assert z.is_rational is False
  274. assert z.is_algebraic is False
  275. assert z.is_transcendental is True
  276. assert z.is_real is True
  277. assert z.is_complex is True
  278. assert z.is_noninteger is True
  279. assert z.is_irrational is True
  280. assert z.is_imaginary is False
  281. assert z.is_positive is True
  282. assert z.is_negative is False
  283. assert z.is_nonpositive is False
  284. assert z.is_nonnegative is True
  285. assert z.is_even is False
  286. assert z.is_odd is False
  287. assert z.is_finite is True
  288. assert z.is_infinite is False
  289. assert z.is_comparable is True
  290. assert z.is_prime is False
  291. assert z.is_composite is False
  292. def test_I():
  293. z = S.ImaginaryUnit
  294. assert z.is_commutative is True
  295. assert z.is_integer is False
  296. assert z.is_rational is False
  297. assert z.is_algebraic is True
  298. assert z.is_transcendental is False
  299. assert z.is_real is False
  300. assert z.is_complex is True
  301. assert z.is_noninteger is False
  302. assert z.is_irrational is False
  303. assert z.is_imaginary is True
  304. assert z.is_positive is False
  305. assert z.is_negative is False
  306. assert z.is_nonpositive is False
  307. assert z.is_nonnegative is False
  308. assert z.is_even is False
  309. assert z.is_odd is False
  310. assert z.is_finite is True
  311. assert z.is_infinite is False
  312. assert z.is_comparable is False
  313. assert z.is_prime is False
  314. assert z.is_composite is False
  315. def test_symbol_real_false():
  316. # issue 3848
  317. a = Symbol('a', real=False)
  318. assert a.is_real is False
  319. assert a.is_integer is False
  320. assert a.is_zero is False
  321. assert a.is_negative is False
  322. assert a.is_positive is False
  323. assert a.is_nonnegative is False
  324. assert a.is_nonpositive is False
  325. assert a.is_nonzero is False
  326. assert a.is_extended_negative is None
  327. assert a.is_extended_positive is None
  328. assert a.is_extended_nonnegative is None
  329. assert a.is_extended_nonpositive is None
  330. assert a.is_extended_nonzero is None
  331. def test_symbol_extended_real_false():
  332. # issue 3848
  333. a = Symbol('a', extended_real=False)
  334. assert a.is_real is False
  335. assert a.is_integer is False
  336. assert a.is_zero is False
  337. assert a.is_negative is False
  338. assert a.is_positive is False
  339. assert a.is_nonnegative is False
  340. assert a.is_nonpositive is False
  341. assert a.is_nonzero is False
  342. assert a.is_extended_negative is False
  343. assert a.is_extended_positive is False
  344. assert a.is_extended_nonnegative is False
  345. assert a.is_extended_nonpositive is False
  346. assert a.is_extended_nonzero is False
  347. def test_symbol_imaginary():
  348. a = Symbol('a', imaginary=True)
  349. assert a.is_real is False
  350. assert a.is_integer is False
  351. assert a.is_negative is False
  352. assert a.is_positive is False
  353. assert a.is_nonnegative is False
  354. assert a.is_nonpositive is False
  355. assert a.is_zero is False
  356. assert a.is_nonzero is False # since nonzero -> real
  357. def test_symbol_zero():
  358. x = Symbol('x', zero=True)
  359. assert x.is_positive is False
  360. assert x.is_nonpositive
  361. assert x.is_negative is False
  362. assert x.is_nonnegative
  363. assert x.is_zero is True
  364. # TODO Change to x.is_nonzero is None
  365. # See https://github.com/sympy/sympy/pull/9583
  366. assert x.is_nonzero is False
  367. assert x.is_finite is True
  368. def test_symbol_positive():
  369. x = Symbol('x', positive=True)
  370. assert x.is_positive is True
  371. assert x.is_nonpositive is False
  372. assert x.is_negative is False
  373. assert x.is_nonnegative is True
  374. assert x.is_zero is False
  375. assert x.is_nonzero is True
  376. def test_neg_symbol_positive():
  377. x = -Symbol('x', positive=True)
  378. assert x.is_positive is False
  379. assert x.is_nonpositive is True
  380. assert x.is_negative is True
  381. assert x.is_nonnegative is False
  382. assert x.is_zero is False
  383. assert x.is_nonzero is True
  384. def test_symbol_nonpositive():
  385. x = Symbol('x', nonpositive=True)
  386. assert x.is_positive is False
  387. assert x.is_nonpositive is True
  388. assert x.is_negative is None
  389. assert x.is_nonnegative is None
  390. assert x.is_zero is None
  391. assert x.is_nonzero is None
  392. def test_neg_symbol_nonpositive():
  393. x = -Symbol('x', nonpositive=True)
  394. assert x.is_positive is None
  395. assert x.is_nonpositive is None
  396. assert x.is_negative is False
  397. assert x.is_nonnegative is True
  398. assert x.is_zero is None
  399. assert x.is_nonzero is None
  400. def test_symbol_falsepositive():
  401. x = Symbol('x', positive=False)
  402. assert x.is_positive is False
  403. assert x.is_nonpositive is None
  404. assert x.is_negative is None
  405. assert x.is_nonnegative is None
  406. assert x.is_zero is None
  407. assert x.is_nonzero is None
  408. def test_symbol_falsepositive_mul():
  409. # To test pull request 9379
  410. # Explicit handling of arg.is_positive=False was added to Mul._eval_is_positive
  411. x = 2*Symbol('x', positive=False)
  412. assert x.is_positive is False # This was None before
  413. assert x.is_nonpositive is None
  414. assert x.is_negative is None
  415. assert x.is_nonnegative is None
  416. assert x.is_zero is None
  417. assert x.is_nonzero is None
  418. @XFAIL
  419. def test_symbol_infinitereal_mul():
  420. ix = Symbol('ix', infinite=True, extended_real=True)
  421. assert (-ix).is_extended_positive is None
  422. def test_neg_symbol_falsepositive():
  423. x = -Symbol('x', positive=False)
  424. assert x.is_positive is None
  425. assert x.is_nonpositive is None
  426. assert x.is_negative is False
  427. assert x.is_nonnegative is None
  428. assert x.is_zero is None
  429. assert x.is_nonzero is None
  430. def test_neg_symbol_falsenegative():
  431. # To test pull request 9379
  432. # Explicit handling of arg.is_negative=False was added to Mul._eval_is_positive
  433. x = -Symbol('x', negative=False)
  434. assert x.is_positive is False # This was None before
  435. assert x.is_nonpositive is None
  436. assert x.is_negative is None
  437. assert x.is_nonnegative is None
  438. assert x.is_zero is None
  439. assert x.is_nonzero is None
  440. def test_symbol_falsepositive_real():
  441. x = Symbol('x', positive=False, real=True)
  442. assert x.is_positive is False
  443. assert x.is_nonpositive is True
  444. assert x.is_negative is None
  445. assert x.is_nonnegative is None
  446. assert x.is_zero is None
  447. assert x.is_nonzero is None
  448. def test_neg_symbol_falsepositive_real():
  449. x = -Symbol('x', positive=False, real=True)
  450. assert x.is_positive is None
  451. assert x.is_nonpositive is None
  452. assert x.is_negative is False
  453. assert x.is_nonnegative is True
  454. assert x.is_zero is None
  455. assert x.is_nonzero is None
  456. def test_symbol_falsenonnegative():
  457. x = Symbol('x', nonnegative=False)
  458. assert x.is_positive is False
  459. assert x.is_nonpositive is None
  460. assert x.is_negative is None
  461. assert x.is_nonnegative is False
  462. assert x.is_zero is False
  463. assert x.is_nonzero is None
  464. @XFAIL
  465. def test_neg_symbol_falsenonnegative():
  466. x = -Symbol('x', nonnegative=False)
  467. assert x.is_positive is None
  468. assert x.is_nonpositive is False # this currently returns None
  469. assert x.is_negative is False # this currently returns None
  470. assert x.is_nonnegative is None
  471. assert x.is_zero is False # this currently returns None
  472. assert x.is_nonzero is True # this currently returns None
  473. def test_symbol_falsenonnegative_real():
  474. x = Symbol('x', nonnegative=False, real=True)
  475. assert x.is_positive is False
  476. assert x.is_nonpositive is True
  477. assert x.is_negative is True
  478. assert x.is_nonnegative is False
  479. assert x.is_zero is False
  480. assert x.is_nonzero is True
  481. def test_neg_symbol_falsenonnegative_real():
  482. x = -Symbol('x', nonnegative=False, real=True)
  483. assert x.is_positive is True
  484. assert x.is_nonpositive is False
  485. assert x.is_negative is False
  486. assert x.is_nonnegative is True
  487. assert x.is_zero is False
  488. assert x.is_nonzero is True
  489. def test_prime():
  490. assert S.NegativeOne.is_prime is False
  491. assert S(-2).is_prime is False
  492. assert S(-4).is_prime is False
  493. assert S.Zero.is_prime is False
  494. assert S.One.is_prime is False
  495. assert S(2).is_prime is True
  496. assert S(17).is_prime is True
  497. assert S(4).is_prime is False
  498. def test_composite():
  499. assert S.NegativeOne.is_composite is False
  500. assert S(-2).is_composite is False
  501. assert S(-4).is_composite is False
  502. assert S.Zero.is_composite is False
  503. assert S(2).is_composite is False
  504. assert S(17).is_composite is False
  505. assert S(4).is_composite is True
  506. x = Dummy(integer=True, positive=True, prime=False)
  507. assert x.is_composite is None # x could be 1
  508. assert (x + 1).is_composite is None
  509. x = Dummy(positive=True, even=True, prime=False)
  510. assert x.is_integer is True
  511. assert x.is_composite is True
  512. def test_prime_symbol():
  513. x = Symbol('x', prime=True)
  514. assert x.is_prime is True
  515. assert x.is_integer is True
  516. assert x.is_positive is True
  517. assert x.is_negative is False
  518. assert x.is_nonpositive is False
  519. assert x.is_nonnegative is True
  520. x = Symbol('x', prime=False)
  521. assert x.is_prime is False
  522. assert x.is_integer is None
  523. assert x.is_positive is None
  524. assert x.is_negative is None
  525. assert x.is_nonpositive is None
  526. assert x.is_nonnegative is None
  527. def test_symbol_noncommutative():
  528. x = Symbol('x', commutative=True)
  529. assert x.is_complex is None
  530. x = Symbol('x', commutative=False)
  531. assert x.is_integer is False
  532. assert x.is_rational is False
  533. assert x.is_algebraic is False
  534. assert x.is_irrational is False
  535. assert x.is_real is False
  536. assert x.is_complex is False
  537. def test_other_symbol():
  538. x = Symbol('x', integer=True)
  539. assert x.is_integer is True
  540. assert x.is_real is True
  541. assert x.is_finite is True
  542. x = Symbol('x', integer=True, nonnegative=True)
  543. assert x.is_integer is True
  544. assert x.is_nonnegative is True
  545. assert x.is_negative is False
  546. assert x.is_positive is None
  547. assert x.is_finite is True
  548. x = Symbol('x', integer=True, nonpositive=True)
  549. assert x.is_integer is True
  550. assert x.is_nonpositive is True
  551. assert x.is_positive is False
  552. assert x.is_negative is None
  553. assert x.is_finite is True
  554. x = Symbol('x', odd=True)
  555. assert x.is_odd is True
  556. assert x.is_even is False
  557. assert x.is_integer is True
  558. assert x.is_finite is True
  559. x = Symbol('x', odd=False)
  560. assert x.is_odd is False
  561. assert x.is_even is None
  562. assert x.is_integer is None
  563. assert x.is_finite is None
  564. x = Symbol('x', even=True)
  565. assert x.is_even is True
  566. assert x.is_odd is False
  567. assert x.is_integer is True
  568. assert x.is_finite is True
  569. x = Symbol('x', even=False)
  570. assert x.is_even is False
  571. assert x.is_odd is None
  572. assert x.is_integer is None
  573. assert x.is_finite is None
  574. x = Symbol('x', integer=True, nonnegative=True)
  575. assert x.is_integer is True
  576. assert x.is_nonnegative is True
  577. assert x.is_finite is True
  578. x = Symbol('x', integer=True, nonpositive=True)
  579. assert x.is_integer is True
  580. assert x.is_nonpositive is True
  581. assert x.is_finite is True
  582. x = Symbol('x', rational=True)
  583. assert x.is_real is True
  584. assert x.is_finite is True
  585. x = Symbol('x', rational=False)
  586. assert x.is_real is None
  587. assert x.is_finite is None
  588. x = Symbol('x', irrational=True)
  589. assert x.is_real is True
  590. assert x.is_finite is True
  591. x = Symbol('x', irrational=False)
  592. assert x.is_real is None
  593. assert x.is_finite is None
  594. with raises(AttributeError):
  595. x.is_real = False
  596. x = Symbol('x', algebraic=True)
  597. assert x.is_transcendental is False
  598. x = Symbol('x', transcendental=True)
  599. assert x.is_algebraic is False
  600. assert x.is_rational is False
  601. assert x.is_integer is False
  602. def test_evaluate_false():
  603. # Previously this failed because the assumptions query would make new
  604. # expressions and some of the evaluation logic would fail under
  605. # evaluate(False).
  606. from sympy.core.parameters import evaluate
  607. from sympy.abc import x, h
  608. f = 2**x**7
  609. with evaluate(False):
  610. fh = f.xreplace({x: x+h})
  611. assert fh.exp.is_rational is None
  612. def test_issue_3825():
  613. """catch: hash instability"""
  614. x = Symbol("x")
  615. y = Symbol("y")
  616. a1 = x + y
  617. a2 = y + x
  618. a2.is_comparable
  619. h1 = hash(a1)
  620. h2 = hash(a2)
  621. assert h1 == h2
  622. def test_issue_4822():
  623. z = (-1)**Rational(1, 3)*(1 - I*sqrt(3))
  624. assert z.is_real in [True, None]
  625. def test_hash_vs_typeinfo():
  626. """seemingly different typeinfo, but in fact equal"""
  627. # the following two are semantically equal
  628. x1 = Symbol('x', even=True)
  629. x2 = Symbol('x', integer=True, odd=False)
  630. assert hash(x1) == hash(x2)
  631. assert x1 == x2
  632. def test_hash_vs_typeinfo_2():
  633. """different typeinfo should mean !eq"""
  634. # the following two are semantically different
  635. x = Symbol('x')
  636. x1 = Symbol('x', even=True)
  637. assert x != x1
  638. assert hash(x) != hash(x1) # This might fail with very low probability
  639. def test_hash_vs_eq():
  640. """catch: different hash for equal objects"""
  641. a = 1 + S.Pi # important: do not fold it into a Number instance
  642. ha = hash(a) # it should be Add/Mul/... to trigger the bug
  643. a.is_positive # this uses .evalf() and deduces it is positive
  644. assert a.is_positive is True
  645. # be sure that hash stayed the same
  646. assert ha == hash(a)
  647. # now b should be the same expression
  648. b = a.expand(trig=True)
  649. hb = hash(b)
  650. assert a == b
  651. assert ha == hb
  652. def test_Add_is_pos_neg():
  653. # these cover lines not covered by the rest of tests in core
  654. n = Symbol('n', extended_negative=True, infinite=True)
  655. nn = Symbol('n', extended_nonnegative=True, infinite=True)
  656. np = Symbol('n', extended_nonpositive=True, infinite=True)
  657. p = Symbol('p', extended_positive=True, infinite=True)
  658. r = Dummy(extended_real=True, finite=False)
  659. x = Symbol('x')
  660. xf = Symbol('xf', finite=True)
  661. assert (n + p).is_extended_positive is None
  662. assert (n + x).is_extended_positive is None
  663. assert (p + x).is_extended_positive is None
  664. assert (n + p).is_extended_negative is None
  665. assert (n + x).is_extended_negative is None
  666. assert (p + x).is_extended_negative is None
  667. assert (n + xf).is_extended_positive is False
  668. assert (p + xf).is_extended_positive is True
  669. assert (n + xf).is_extended_negative is True
  670. assert (p + xf).is_extended_negative is False
  671. assert (x - S.Infinity).is_extended_negative is None # issue 7798
  672. # issue 8046, 16.2
  673. assert (p + nn).is_extended_positive
  674. assert (n + np).is_extended_negative
  675. assert (p + r).is_extended_positive is None
  676. def test_Add_is_imaginary():
  677. nn = Dummy(nonnegative=True)
  678. assert (I*nn + I).is_imaginary # issue 8046, 17
  679. def test_Add_is_algebraic():
  680. a = Symbol('a', algebraic=True)
  681. b = Symbol('a', algebraic=True)
  682. na = Symbol('na', algebraic=False)
  683. nb = Symbol('nb', algebraic=False)
  684. x = Symbol('x')
  685. assert (a + b).is_algebraic
  686. assert (na + nb).is_algebraic is None
  687. assert (a + na).is_algebraic is False
  688. assert (a + x).is_algebraic is None
  689. assert (na + x).is_algebraic is None
  690. def test_Mul_is_algebraic():
  691. a = Symbol('a', algebraic=True)
  692. b = Symbol('b', algebraic=True)
  693. na = Symbol('na', algebraic=False)
  694. an = Symbol('an', algebraic=True, nonzero=True)
  695. nb = Symbol('nb', algebraic=False)
  696. x = Symbol('x')
  697. assert (a*b).is_algebraic is True
  698. assert (na*nb).is_algebraic is None
  699. assert (a*na).is_algebraic is None
  700. assert (an*na).is_algebraic is False
  701. assert (a*x).is_algebraic is None
  702. assert (na*x).is_algebraic is None
  703. def test_Pow_is_algebraic():
  704. e = Symbol('e', algebraic=True)
  705. assert Pow(1, e, evaluate=False).is_algebraic
  706. assert Pow(0, e, evaluate=False).is_algebraic
  707. a = Symbol('a', algebraic=True)
  708. azf = Symbol('azf', algebraic=True, zero=False)
  709. na = Symbol('na', algebraic=False)
  710. ia = Symbol('ia', algebraic=True, irrational=True)
  711. ib = Symbol('ib', algebraic=True, irrational=True)
  712. r = Symbol('r', rational=True)
  713. x = Symbol('x')
  714. assert (a**2).is_algebraic is True
  715. assert (a**r).is_algebraic is None
  716. assert (azf**r).is_algebraic is True
  717. assert (a**x).is_algebraic is None
  718. assert (na**r).is_algebraic is None
  719. assert (ia**r).is_algebraic is True
  720. assert (ia**ib).is_algebraic is False
  721. assert (a**e).is_algebraic is None
  722. # Gelfond-Schneider constant:
  723. assert Pow(2, sqrt(2), evaluate=False).is_algebraic is False
  724. assert Pow(S.GoldenRatio, sqrt(3), evaluate=False).is_algebraic is False
  725. # issue 8649
  726. t = Symbol('t', real=True, transcendental=True)
  727. n = Symbol('n', integer=True)
  728. assert (t**n).is_algebraic is None
  729. assert (t**n).is_integer is None
  730. assert (pi**3).is_algebraic is False
  731. r = Symbol('r', zero=True)
  732. assert (pi**r).is_algebraic is True
  733. def test_Mul_is_prime_composite():
  734. x = Symbol('x', positive=True, integer=True)
  735. y = Symbol('y', positive=True, integer=True)
  736. assert (x*y).is_prime is None
  737. assert ( (x+1)*(y+1) ).is_prime is False
  738. assert ( (x+1)*(y+1) ).is_composite is True
  739. x = Symbol('x', positive=True)
  740. assert ( (x+1)*(y+1) ).is_prime is None
  741. assert ( (x+1)*(y+1) ).is_composite is None
  742. def test_Pow_is_pos_neg():
  743. z = Symbol('z', real=True)
  744. w = Symbol('w', nonpositive=True)
  745. assert (S.NegativeOne**S(2)).is_positive is True
  746. assert (S.One**z).is_positive is True
  747. assert (S.NegativeOne**S(3)).is_positive is False
  748. assert (S.Zero**S.Zero).is_positive is True # 0**0 is 1
  749. assert (w**S(3)).is_positive is False
  750. assert (w**S(2)).is_positive is None
  751. assert (I**2).is_positive is False
  752. assert (I**4).is_positive is True
  753. # tests emerging from #16332 issue
  754. p = Symbol('p', zero=True)
  755. q = Symbol('q', zero=False, real=True)
  756. j = Symbol('j', zero=False, even=True)
  757. x = Symbol('x', zero=True)
  758. y = Symbol('y', zero=True)
  759. assert (p**q).is_positive is False
  760. assert (p**q).is_negative is False
  761. assert (p**j).is_positive is False
  762. assert (x**y).is_positive is True # 0**0
  763. assert (x**y).is_negative is False
  764. def test_Pow_is_prime_composite():
  765. x = Symbol('x', positive=True, integer=True)
  766. y = Symbol('y', positive=True, integer=True)
  767. assert (x**y).is_prime is None
  768. assert ( x**(y+1) ).is_prime is False
  769. assert ( x**(y+1) ).is_composite is None
  770. assert ( (x+1)**(y+1) ).is_composite is True
  771. assert ( (-x-1)**(2*y) ).is_composite is True
  772. x = Symbol('x', positive=True)
  773. assert (x**y).is_prime is None
  774. def test_Mul_is_infinite():
  775. x = Symbol('x')
  776. f = Symbol('f', finite=True)
  777. i = Symbol('i', infinite=True)
  778. z = Dummy(zero=True)
  779. nzf = Dummy(finite=True, zero=False)
  780. from sympy.core.mul import Mul
  781. assert (x*f).is_finite is None
  782. assert (x*i).is_finite is None
  783. assert (f*i).is_finite is None
  784. assert (x*f*i).is_finite is None
  785. assert (z*i).is_finite is None
  786. assert (nzf*i).is_finite is False
  787. assert (z*f).is_finite is True
  788. assert Mul(0, f, evaluate=False).is_finite is True
  789. assert Mul(0, i, evaluate=False).is_finite is None
  790. assert (x*f).is_infinite is None
  791. assert (x*i).is_infinite is None
  792. assert (f*i).is_infinite is None
  793. assert (x*f*i).is_infinite is None
  794. assert (z*i).is_infinite is S.NaN.is_infinite
  795. assert (nzf*i).is_infinite is True
  796. assert (z*f).is_infinite is False
  797. assert Mul(0, f, evaluate=False).is_infinite is False
  798. assert Mul(0, i, evaluate=False).is_infinite is S.NaN.is_infinite
  799. def test_Add_is_infinite():
  800. x = Symbol('x')
  801. f = Symbol('f', finite=True)
  802. i = Symbol('i', infinite=True)
  803. i2 = Symbol('i2', infinite=True)
  804. z = Dummy(zero=True)
  805. nzf = Dummy(finite=True, zero=False)
  806. from sympy.core.add import Add
  807. assert (x+f).is_finite is None
  808. assert (x+i).is_finite is None
  809. assert (f+i).is_finite is False
  810. assert (x+f+i).is_finite is None
  811. assert (z+i).is_finite is False
  812. assert (nzf+i).is_finite is False
  813. assert (z+f).is_finite is True
  814. assert (i+i2).is_finite is None
  815. assert Add(0, f, evaluate=False).is_finite is True
  816. assert Add(0, i, evaluate=False).is_finite is False
  817. assert (x+f).is_infinite is None
  818. assert (x+i).is_infinite is None
  819. assert (f+i).is_infinite is True
  820. assert (x+f+i).is_infinite is None
  821. assert (z+i).is_infinite is True
  822. assert (nzf+i).is_infinite is True
  823. assert (z+f).is_infinite is False
  824. assert (i+i2).is_infinite is None
  825. assert Add(0, f, evaluate=False).is_infinite is False
  826. assert Add(0, i, evaluate=False).is_infinite is True
  827. def test_special_is_rational():
  828. i = Symbol('i', integer=True)
  829. i2 = Symbol('i2', integer=True)
  830. ni = Symbol('ni', integer=True, nonzero=True)
  831. r = Symbol('r', rational=True)
  832. rn = Symbol('r', rational=True, nonzero=True)
  833. nr = Symbol('nr', irrational=True)
  834. x = Symbol('x')
  835. assert sqrt(3).is_rational is False
  836. assert (3 + sqrt(3)).is_rational is False
  837. assert (3*sqrt(3)).is_rational is False
  838. assert exp(3).is_rational is False
  839. assert exp(ni).is_rational is False
  840. assert exp(rn).is_rational is False
  841. assert exp(x).is_rational is None
  842. assert exp(log(3), evaluate=False).is_rational is True
  843. assert log(exp(3), evaluate=False).is_rational is True
  844. assert log(3).is_rational is False
  845. assert log(ni + 1).is_rational is False
  846. assert log(rn + 1).is_rational is False
  847. assert log(x).is_rational is None
  848. assert (sqrt(3) + sqrt(5)).is_rational is None
  849. assert (sqrt(3) + S.Pi).is_rational is False
  850. assert (x**i).is_rational is None
  851. assert (i**i).is_rational is True
  852. assert (i**i2).is_rational is None
  853. assert (r**i).is_rational is None
  854. assert (r**r).is_rational is None
  855. assert (r**x).is_rational is None
  856. assert (nr**i).is_rational is None # issue 8598
  857. assert (nr**Symbol('z', zero=True)).is_rational
  858. assert sin(1).is_rational is False
  859. assert sin(ni).is_rational is False
  860. assert sin(rn).is_rational is False
  861. assert sin(x).is_rational is None
  862. assert asin(r).is_rational is False
  863. assert sin(asin(3), evaluate=False).is_rational is True
  864. @XFAIL
  865. def test_issue_6275():
  866. x = Symbol('x')
  867. # both zero or both Muls...but neither "change would be very appreciated.
  868. # This is similar to x/x => 1 even though if x = 0, it is really nan.
  869. assert isinstance(x*0, type(0*S.Infinity))
  870. if 0*S.Infinity is S.NaN:
  871. b = Symbol('b', finite=None)
  872. assert (b*0).is_zero is None
  873. def test_sanitize_assumptions():
  874. # issue 6666
  875. for cls in (Symbol, Dummy, Wild):
  876. x = cls('x', real=1, positive=0)
  877. assert x.is_real is True
  878. assert x.is_positive is False
  879. assert cls('', real=True, positive=None).is_positive is None
  880. raises(ValueError, lambda: cls('', commutative=None))
  881. raises(ValueError, lambda: Symbol._sanitize({"commutative": None}))
  882. def test_special_assumptions():
  883. e = -3 - sqrt(5) + (-sqrt(10)/2 - sqrt(2)/2)**2
  884. assert simplify(e < 0) is S.false
  885. assert simplify(e > 0) is S.false
  886. assert (e == 0) is False # it's not a literal 0
  887. assert e.equals(0) is True
  888. def test_inconsistent():
  889. # cf. issues 5795 and 5545
  890. raises(InconsistentAssumptions, lambda: Symbol('x', real=True,
  891. commutative=False))
  892. def test_issue_6631():
  893. assert ((-1)**(I)).is_real is True
  894. assert ((-1)**(I*2)).is_real is True
  895. assert ((-1)**(I/2)).is_real is True
  896. assert ((-1)**(I*S.Pi)).is_real is True
  897. assert (I**(I + 2)).is_real is True
  898. def test_issue_2730():
  899. assert (1/(1 + I)).is_real is False
  900. def test_issue_4149():
  901. assert (3 + I).is_complex
  902. assert (3 + I).is_imaginary is False
  903. assert (3*I + S.Pi*I).is_imaginary
  904. # as Zero.is_imaginary is False, see issue 7649
  905. y = Symbol('y', real=True)
  906. assert (3*I + S.Pi*I + y*I).is_imaginary is None
  907. p = Symbol('p', positive=True)
  908. assert (3*I + S.Pi*I + p*I).is_imaginary
  909. n = Symbol('n', negative=True)
  910. assert (-3*I - S.Pi*I + n*I).is_imaginary
  911. i = Symbol('i', imaginary=True)
  912. assert ([(i**a).is_imaginary for a in range(4)] ==
  913. [False, True, False, True])
  914. # tests from the PR #7887:
  915. e = S("-sqrt(3)*I/2 + 0.866025403784439*I")
  916. assert e.is_real is False
  917. assert e.is_imaginary
  918. def test_issue_2920():
  919. n = Symbol('n', negative=True)
  920. assert sqrt(n).is_imaginary
  921. def test_issue_7899():
  922. x = Symbol('x', real=True)
  923. assert (I*x).is_real is None
  924. assert ((x - I)*(x - 1)).is_zero is None
  925. assert ((x - I)*(x - 1)).is_real is None
  926. @XFAIL
  927. def test_issue_7993():
  928. x = Dummy(integer=True)
  929. y = Dummy(noninteger=True)
  930. assert (x - y).is_zero is False
  931. def test_issue_8075():
  932. raises(InconsistentAssumptions, lambda: Dummy(zero=True, finite=False))
  933. raises(InconsistentAssumptions, lambda: Dummy(zero=True, infinite=True))
  934. def test_issue_8642():
  935. x = Symbol('x', real=True, integer=False)
  936. assert (x*2).is_integer is None, (x*2).is_integer
  937. def test_issues_8632_8633_8638_8675_8992():
  938. p = Dummy(integer=True, positive=True)
  939. nn = Dummy(integer=True, nonnegative=True)
  940. assert (p - S.Half).is_positive
  941. assert (p - 1).is_nonnegative
  942. assert (nn + 1).is_positive
  943. assert (-p + 1).is_nonpositive
  944. assert (-nn - 1).is_negative
  945. prime = Dummy(prime=True)
  946. assert (prime - 2).is_nonnegative
  947. assert (prime - 3).is_nonnegative is None
  948. even = Dummy(positive=True, even=True)
  949. assert (even - 2).is_nonnegative
  950. p = Dummy(positive=True)
  951. assert (p/(p + 1) - 1).is_negative
  952. assert ((p + 2)**3 - S.Half).is_positive
  953. n = Dummy(negative=True)
  954. assert (n - 3).is_nonpositive
  955. def test_issue_9115_9150():
  956. n = Dummy('n', integer=True, nonnegative=True)
  957. assert (factorial(n) >= 1) == True
  958. assert (factorial(n) < 1) == False
  959. assert factorial(n + 1).is_even is None
  960. assert factorial(n + 2).is_even is True
  961. assert factorial(n + 2) >= 2
  962. def test_issue_9165():
  963. z = Symbol('z', zero=True)
  964. f = Symbol('f', finite=False)
  965. assert 0/z is S.NaN
  966. assert 0*(1/z) is S.NaN
  967. assert 0*f is S.NaN
  968. def test_issue_10024():
  969. x = Dummy('x')
  970. assert Mod(x, 2*pi).is_zero is None
  971. def test_issue_10302():
  972. x = Symbol('x')
  973. r = Symbol('r', real=True)
  974. u = -(3*2**pi)**(1/pi) + 2*3**(1/pi)
  975. i = u + u*I
  976. assert i.is_real is None # w/o simplification this should fail
  977. assert (u + i).is_zero is None
  978. assert (1 + i).is_zero is False
  979. a = Dummy('a', zero=True)
  980. assert (a + I).is_zero is False
  981. assert (a + r*I).is_zero is None
  982. assert (a + I).is_imaginary
  983. assert (a + x + I).is_imaginary is None
  984. assert (a + r*I + I).is_imaginary is None
  985. def test_complex_reciprocal_imaginary():
  986. assert (1 / (4 + 3*I)).is_imaginary is False
  987. def test_issue_16313():
  988. x = Symbol('x', extended_real=False)
  989. k = Symbol('k', real=True)
  990. l = Symbol('l', real=True, zero=False)
  991. assert (-x).is_real is False
  992. assert (k*x).is_real is None # k can be zero also
  993. assert (l*x).is_real is False
  994. assert (l*x*x).is_real is None # since x*x can be a real number
  995. assert (-x).is_positive is False
  996. def test_issue_16579():
  997. # extended_real -> finite | infinite
  998. x = Symbol('x', extended_real=True, infinite=False)
  999. y = Symbol('y', extended_real=True, finite=False)
  1000. assert x.is_finite is True
  1001. assert y.is_infinite is True
  1002. # With PR 16978, complex now implies finite
  1003. c = Symbol('c', complex=True)
  1004. assert c.is_finite is True
  1005. raises(InconsistentAssumptions, lambda: Dummy(complex=True, finite=False))
  1006. # Now infinite == !finite
  1007. nf = Symbol('nf', finite=False)
  1008. assert nf.is_infinite is True
  1009. def test_issue_17556():
  1010. z = I*oo
  1011. assert z.is_imaginary is False
  1012. assert z.is_finite is False
  1013. def test_issue_21651():
  1014. k = Symbol('k', positive=True, integer=True)
  1015. exp = 2*2**(-k)
  1016. assert exp.is_integer is None
  1017. def test_assumptions_copy():
  1018. assert assumptions(Symbol('x'), {"commutative": True}
  1019. ) == {'commutative': True}
  1020. assert assumptions(Symbol('x'), ['integer']) == {}
  1021. assert assumptions(Symbol('x'), ['commutative']
  1022. ) == {'commutative': True}
  1023. assert assumptions(Symbol('x')) == {'commutative': True}
  1024. assert assumptions(1)['positive']
  1025. assert assumptions(3 + I) == {
  1026. 'algebraic': True,
  1027. 'commutative': True,
  1028. 'complex': True,
  1029. 'composite': False,
  1030. 'even': False,
  1031. 'extended_negative': False,
  1032. 'extended_nonnegative': False,
  1033. 'extended_nonpositive': False,
  1034. 'extended_nonzero': False,
  1035. 'extended_positive': False,
  1036. 'extended_real': False,
  1037. 'finite': True,
  1038. 'imaginary': False,
  1039. 'infinite': False,
  1040. 'integer': False,
  1041. 'irrational': False,
  1042. 'negative': False,
  1043. 'noninteger': False,
  1044. 'nonnegative': False,
  1045. 'nonpositive': False,
  1046. 'nonzero': False,
  1047. 'odd': False,
  1048. 'positive': False,
  1049. 'prime': False,
  1050. 'rational': False,
  1051. 'real': False,
  1052. 'transcendental': False,
  1053. 'zero': False}
  1054. def test_check_assumptions():
  1055. assert check_assumptions(1, 0) is False
  1056. x = Symbol('x', positive=True)
  1057. assert check_assumptions(1, x) is True
  1058. assert check_assumptions(1, 1) is True
  1059. assert check_assumptions(-1, 1) is False
  1060. i = Symbol('i', integer=True)
  1061. # don't know if i is positive (or prime, etc...)
  1062. assert check_assumptions(i, 1) is None
  1063. assert check_assumptions(Dummy(integer=None), integer=True) is None
  1064. assert check_assumptions(Dummy(integer=None), integer=False) is None
  1065. assert check_assumptions(Dummy(integer=False), integer=True) is False
  1066. assert check_assumptions(Dummy(integer=True), integer=False) is False
  1067. # no T/F assumptions to check
  1068. assert check_assumptions(Dummy(integer=False), integer=None) is True
  1069. raises(ValueError, lambda: check_assumptions(2*x, x, positive=True))
  1070. def test_failing_assumptions():
  1071. x = Symbol('x', positive=True)
  1072. y = Symbol('y')
  1073. assert failing_assumptions(6*x + y, **x.assumptions0) == \
  1074. {'real': None, 'imaginary': None, 'complex': None, 'hermitian': None,
  1075. 'positive': None, 'nonpositive': None, 'nonnegative': None, 'nonzero': None,
  1076. 'negative': None, 'zero': None, 'extended_real': None, 'finite': None,
  1077. 'infinite': None, 'extended_negative': None, 'extended_nonnegative': None,
  1078. 'extended_nonpositive': None, 'extended_nonzero': None,
  1079. 'extended_positive': None }
  1080. def test_common_assumptions():
  1081. assert common_assumptions([0, 1, 2]
  1082. ) == {'algebraic': True, 'irrational': False, 'hermitian':
  1083. True, 'extended_real': True, 'real': True, 'extended_negative':
  1084. False, 'extended_nonnegative': True, 'integer': True,
  1085. 'rational': True, 'imaginary': False, 'complex': True,
  1086. 'commutative': True,'noninteger': False, 'composite': False,
  1087. 'infinite': False, 'nonnegative': True, 'finite': True,
  1088. 'transcendental': False,'negative': False}
  1089. assert common_assumptions([0, 1, 2], 'positive integer'.split()
  1090. ) == {'integer': True}
  1091. assert common_assumptions([0, 1, 2], []) == {}
  1092. assert common_assumptions([], ['integer']) == {}
  1093. assert common_assumptions([0], ['integer']) == {'integer': True}
  1094. def test_pre_generated_assumption_rules_are_valid():
  1095. # check the pre-generated assumptions match freshly generated assumptions
  1096. # if this check fails, consider updating the assumptions
  1097. # see sympy.core.assumptions._generate_assumption_rules
  1098. pre_generated_assumptions =_load_pre_generated_assumption_rules()
  1099. generated_assumptions =_generate_assumption_rules()
  1100. assert pre_generated_assumptions._to_python() == generated_assumptions._to_python(), "pre-generated assumptions are invalid, see sympy.core.assumptions._generate_assumption_rules"
  1101. def test_ask_shuffle():
  1102. grp = PermutationGroup(Permutation(1, 0, 2), Permutation(2, 1, 3))
  1103. seed(123)
  1104. first = grp.random()
  1105. seed(123)
  1106. simplify(I)
  1107. second = grp.random()
  1108. seed(123)
  1109. simplify(-I)
  1110. third = grp.random()
  1111. assert first == second == third