Logging to /Users/s/tmp/pari-03.25 GPRC Done. GP/PARI CALCULATOR Version 2.13.1 (released) i386 running darwin (x86-64/GMP-6.2.1 kernel) 64-bit version compiled: Jan 25 2021, Apple clang version 12.0.0 (clang-1200.0.32.28) threading engine: single (readline v8.1 enabled, extended help enabled) Copyright (C) 2000-2020 The PARI Group PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY WARRANTY WHATSOEVER. Type ? for help, \q to quit. Type ?17 for how to get moral (and possibly technical) support. parisizemax = 900001792, primelimit = 1000000 (13:51) gp > 18541^2-12709^2 %1 = 182250000 (13:51) gp > issquare(%) %2 = 1 (13:51) gp > issquare(18541^2-12709^2) %3 = 1 (13:51) gp > ?issquare issquare(x,{&n}): true(1) if x is a square, false(0) if not. If n is given puts the exact square root there if it was computed. (13:51) gp > ??issquare issquare(x,{&n}): True (1) if x is a square, false (0) if not. What "being a square" means depends on the type of x: all t_COMPLEX are squares, as well as all nonnegative t_REAL; for exact types such as t_INT, t_FRAC and t_INTMOD, squares are numbers of the form s^2 with s in Z, Q and Z/NZ respectively. ? issquare(3) \\ as an integer %1 = 0 ? issquare(3.) \\ as a real number %2 = 1 ? issquare(Mod(7, 8)) \\ in Z/8Z %3 = 0 ? issquare( 5 + O(13^4) ) \\ in Q_13 %4 = 0 If n is given, a square root of x is put into n. ? issquare(4, &n) %1 = 1 ? n %2 = 2 For polynomials, either we detect that the characteristic is 2 (and check directly odd and even-power monomials) or we assume that 2 is /*-- (type RETURN to continue) --*/ invertible and check whether squaring the truncated power series for the square root yields the original input. For t_POLMOD x, we only support t_POLMODs of t_INTMODs encoding finite fields, assuming without checking that the intmod modulus p is prime and that the polmod modulus is irreducible modulo p. ? issquare(Mod(Mod(2,3), x^2+1), &n) %1 = 1 ? n %2 = Mod(Mod(2, 3)*x, Mod(1, 3)*x^2 + Mod(1, 3)) The library syntax is long issquareall(GEN x, GEN *n = NULL). Also available is long issquare(GEN x). Deprecated GP-specific functions GEN gissquare(GEN x) and GEN gissquareall(GEN x, GEN *pt) return gen_0 and gen_1 instead of a boolean value. (13:54) gp > issquare(18541^2-12709^2) %4 = 1 (13:54) gp > sqrt(18541^2-12709^2) %5 = 13500.000000000000000000000000000000000 (13:54) gp > 12709^2 %6 = 161518681 (13:54) gp > 13500^2 %7 = 182250000 (13:54) gp > 18541^2 %8 = 343768681 (13:54) gp > 12709^2+13500^2==18541^2 %9 = 1 (13:55) gp > 12709^2+13500^2-18541^2 %10 = 0 (13:55) gp > factor(13500) %11 = [2 2] [3 3] [5 3] (13:55) gp > 2^2*3^3*5^3 %12 = 13500