def axiome_init(): """ """ v = myVars() print('\n\nAXIOME_INIT') print('Pour un complexe cartesien :') z = Complexe(v.f1, v.s1, 1) _ = "" _ += "%r " % (z.reel == v.f1) _ += "%r " % (z.imag == v.s1) _ += "%r " % (z.isCartesien == 1) print(_ + "\n") _ = "" print('Pour un complexe polaire : ') z = Complexe(v.f4, v.s4, 0) _ += "%r " % (z.module == v.f4) _ += "%r " % (round(abs(z.argument - v.s4 % (2 * pi)), 9) == 0) _ += "%r " % (z.isCartesien == 0) print(_ + "\n") _ = "" print('Pour un complexe cartesien : par defaut') z = Complexe(v.f1, v.s1) _ += "%r " % (z.isCartesien == 1) print(_ + "\n")
def axiome_mul(): """ """ print('\n\nAXIOME_MUL') v = myVars() print('Avec un complexe cartesien en premier : ') print('Transmission isCartesien : ', (v.zCart * v.zCart2).isCartesien == 1) print( 'Element neutre : ', v.zCart * Complexe(1, 0, 1) == v.zCart * Complexe(1, 0, 0) == v.zCart) print('Commutativite : ', v.zCart * v.zCart2 == v.zCart2 * v.zCart) print('Associativite : ', v.zCart * (v.zCart2 * v.zCart3) == (v.zCart * v.zCart2) * v.zCart3) print( "Distributive par rapport à l'addition : ", v.zCart * (v.zCart2 + v.zCart3) == (v.zCart * v.zCart2) + (v.zCart * v.zCart3)) print('Avec un complexe polaire en premier : ') print('Transmission isPolaire : ', (v.zPol * v.zCart2).isCartesien == 0) print('Element neutre : ', v.zPol * Complexe(1, 0, 1) == v.zPol * Complexe(1, 0, 0) == v.zPol) print('Commutativite : ', v.zPol * v.zPol2 == v.zPol2 * v.zPol) print('Associativite : ', v.zPol * (v.zPol2 * v.zPol3) == (v.zPol * v.zPol2) * v.zPol3) print("Distributive par rapport à l'addition : ", v.zPol * (v.zPol2 + v.zPol3) == (v.zPol * v.zPol2) + (v.zPol * v.zPol3)) #PROBLEME
def axiome_conjugue(): """ """ print('\n\nAXIOME_CONJUGUE') v = myVars() z = v.zCart y = v.zPol _ = "" _ += "%r " % (z * z.conjugue == Complexe(z.module**2, 0, 1)) _ += "%r " % (z.conjugue.conjugue == z) _ += "%r " % (v.zR.conjugue == v.zR) _ += "%r " % (v.zIm.conjugue == v.zIm.oppose) _ += "%r " % ((z + z.conjugue) == Complexe(2 * z.reel, 0, 1)) _ += "%r " % ((z - z.conjugue) == Complexe(0, 2 * z.imag, 1)) _ += "%r " % ((z + y).conjugue == z.conjugue + y.conjugue) _ += "%r " % ((z * y).conjugue == z.conjugue * y.conjugue) _ += "%r " % (v.zPos.inverse.conjugue == v.zPos.conjugue.inverse) _ += "%r " % ((z**v.n).conjugue == z.conjugue**v.n) _ += "%r " % ((z / v.zPos).conjugue == z.conjugue / v.zPos.conjugue) print(_ + "\n") _ = "" print('Pour un complexe cartesien :') _ += "%r " % (v.zCart.conjugue.reel == v.zCart.reel) _ += "%r " % (v.zCart.conjugue.imag == (-v.zCart.imag)) _ += "%r " % (v.zCart.conjugue.isCartesien == 1) print(_ + "\n") _ = "" print('Pour un complexe polaire : ') _ += "%r " % (v.zPol.conjugue.module == v.zPol.module) _ += "%r " % (round( abs(v.zPol.conjugue.argument - (-v.zPol.argument) % (2 * pi)), 10) == 0) _ += "%r " % (v.zPol.conjugue.isCartesien == 0) print(_ + "\n")
def axiome_find(): """ """ print('\n\nAXIOME_FIND') _="" v=myVars() l=[v.zCart,v.zPol,v.zCart2,v.zPol2,v.zCart3,v.zPol3,v.zPos,v.zPosPol, v.zUn,v.zIm,v.zR,v.zI,v.zZero] random.shuffle(l) i=random.randint(0,len(l)-1) a=l[i] _+="%r "%(a.find(l)==i) g=[v.zUn,v.zIm,v.zR,v.zI,v.zZero] a=Complexe(4,1,1) _+="%r "%(a.find(g)==None) print(_+"\n")
def axiome_find(): """ """ print('\n\nAXIOME_FIND') _ = "" v = myVars() l = [ v.zCart, v.zPol, v.zCart2, v.zPol2, v.zCart3, v.zPol3, v.zPos, v.zPosPol, v.zUn, v.zIm, v.zR, v.zI, v.zZero ] random.shuffle(l) i = random.randint(0, len(l) - 1) a = l[i] _ += "%r " % (a.find(l) == i) g = [v.zUn, v.zIm, v.zR, v.zI, v.zZero] a = Complexe(4, 1, 1) _ += "%r " % (a.find(g) == None) print(_ + "\n")
def axiome_lt(): """ """ print('\n\nAXIOME_LT') v = myVars() print('Pour un complexe cartesien :') z = v.zPos _ = "" _ += "%r " % ((z < z) == 0) u = Complexe(z.reel / 5, z.imag / 5, 1) _ += "%r " % ((u < z) == 1) t = Complexe(z.reel, z.imag / 5, 1) _ += "%r " % ((t < z) == 1) print(_ + "\n") _ = "" print('Pour un complexe polaire : ') z = v.zPosPol _ += "%r " % ((z < z) == 0) u = Complexe(z.module / 5, z.argument, 0) _ += "%r " % ((u < z) == 1) t = Complexe(z.module, -z.argument, 0) _ += "%r " % ((t < z) == 1) print(_ + "\n")
def axiome_truediv(): """ """ print("\n\nAXIOME_TRUEDIV") v = myVars() _ = "" _ += "%r " % (v.zCart / Complexe(1, 0, 1) == v.zCart / Complexe(1, 0, 0) == v.zCart) _ += "%r " % (Complexe(0, 0, 1) / v.zCart == Complexe(0, 0, 0)) _ += "%r " % (v.zCart.conjugue.isCartesien == 1) _ += "%r " % (v.zCart / v.zCart2 == v.zCart * v.zCart2.inverse) print(_ + "\n") _ = "" _ += "%r " % (v.zPol / Complexe(1, 0, 1) == v.zPol / Complexe(1, 0, 0) == v.zPol) _ += "%r " % (Complexe(0, 0, 1) / v.zPol == Complexe(0, 0, 0)) _ += "%r " % (v.zPol / v.zPol2 == v.zPol * v.zPol2.inverse) _ += "%r " % (v.zCart.conjugue.isCartesien == 1) print(_ + "\n")
def main_basique(): print('INIT et GETTER SETTER') print('A DEVIENT EST CARTESIEN') a = Complexe(0, 0, 1) print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print("a.isCartesien : ", a.isCartesien) print("a.isPolaire : ", a.isPolaire) print('A DEVIENT I+1') a.reel = 1 a.imag = 1 print("a.reel=1; a.reel : ", a.reel) print("a.imag=1; a.imag : ", a.imag) print('pi/4 : ', pi / 4) print('sqrt(2) : ', sqrt(2)) print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print('MODULE DEVIENT 1') a.module = 1 print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print('argument DEVIENT pi/2') a.argument = pi / 2 print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print() #TESTS print('TESTS') print('Cartesien : ') a = Complexe(1, 2, True) b = Complexe(1, 2, True) c = Complexe(1, 1, True) print('a : ', a) print('b : ', b) print('c : ', c) print('a==b : ', a == b) print('a==c : ', a == c) print('a<b : ', a < b) print('c<a : ', c < a) print('Polaire : ') a = Complexe(1.0, pi / 4, 0) b = Complexe(2, pi / 4, 0) c = Complexe(2, pi / 2, 0) print('a==b : ', a == b) print('a==c : ', a == c) print('a<b : ', a < b) print('c<a : ', c < a) print() #ADDITION: print('ADDITION') print('Cartesien ') a = Complexe(1, 2, True) b = Complexe(1, 2, True) print('a : ', a) print('b : ', b) print('a+b :', a + b) print('Polaire ') a = Complexe(2, pi / 2, False) b = Complexe(2, pi / 4, 0) print('a : ', a) print('b : ', b) print('a+b : ', a + b) print() #MULTIPLICATION print('MULTIPLICATION') print('Cartesien ') a = Complexe(1, 1, True) b = Complexe(1, 1, True) print('a : ', a) print('b : ', b) print('a*b : ', a * b) a = Complexe(1, 2, True) b = Complexe(1, 2, True) print('a : ', a) print('b : ', b) print('a*b : ', a * b) print('Polaire ') a = Complexe(1, pi / 2, 0) b = Complexe(2, pi / 4, 0) print('a : ', a) print('b : ', b) print('3pi/4 : ', 3 * pi / 4) print('a*b : ', a * b) print() #OPPOSE print('OPPOSE') print('Cartesien : ') a = Complexe(-3, 0, True) print('a : ', a) print('a.oppose : ', a.oppose) print('a.cartesien : ', a.cartesien) print('a.polaire : ', a.polaire) print('a.oppose.cartesien : ', a.oppose.cartesien) print('a.oppose.polaire : ', a.oppose.polaire) print('Polaire : ') a = Complexe(2, pi, 0) print('a : ', a) print('a.oppose : ', a.oppose) print('a.cartesien : ', a.cartesien) print('a.polaire : ', a.polaire) print('a.oppose.cartesien : ', a.oppose.cartesien) print('a.oppose.polaire : ', a.oppose.polaire) print() #INVERSE print('INVERSE') print('Cartesien ') a = Complexe(1, 1, 1) print('a : ', a) print(a.inverse) print('Polaire ') a = Complexe(2, 2 * pi / 3, 0) print('a : ', a) print(a.inverse) print() #CONJUGUE print('CONJUGUE') print('Cartesien') a = Complexe(1, 2, 1) print('a : ', a) print(a.conjugue) print('Polaire') a = Complexe(1, 5 * pi / 6, 0) print('a : ', a) print(a.conjugue) print() #VALEUR ABSOLUE print('VALEUR ABSOLUE') print('Cartesien') a = Complexe(1, 1, 1) print('a : ', a) print(abs(a)) print(sqrt(0.5)) print(abs(a.inverse)) print('Polaire') a = Complexe(87, pi / 3, 0) print('a : ', a) print(abs(a)) print() #SOUSTRACTION print('SOUSTRACTION') print('Cartesien') a = Complexe(1, 1, 1) b = Complexe(1, -3, 1) print('a : ', a) print('b : ', b) print('a-b : ', a - b) print('Polaire') a = Complexe(sqrt(2), pi / 4, 0) b = Complexe(1, pi / 2, 0) print('a : ', a) print('b : ', b) print('a-b : ', a - b) print() #DIVISION print('DIVISION') print('Cartesien: ') a = Complexe(1, 1, 1) print('a : ', a) print('a/a : ', a / a) print('Polaire : ') a = Complexe(42, pi / 2, 0) b = Complexe(2, pi / 4, 0) print('a : ', a) print('b : ', b) print('pi/4 ', (pi / 4)) print('a/b : ', a / b) print() #PUISSANCE ENTIERE print('PUISSANCE ENTIERE') print('Cartesien') a = Complexe(1, 1, 1) print('a : ', a) print('a**2 : ', a**2) print('a**3 : ', a**3) print('a**4 : ', a**4) print('Polaire') a = Complexe(1, pi, 0) print('a : ', a) print('a**2 : ', a**2) print('a**3 : ', a**3) print('a**4 : ', a**4) print() #CHERCHE DANS LISTE DE COMPLEXES print('CHERCHE') l = [Complexe(i, j, 1) for i in range(2) for j in range(5)] print(l) print() g = [Complexe(i, j, 0) for i in range(2) for j in range(5)] print(g) a = Complexe(1, 4, 1) print('a : ', a) print('a.find(l) : ', a.find(l)) print('a.find(g) : ', a.find(g)) a = Complexe(1, 4, 0) print('a : ', a) print('a.find(g) : ', a.find(g)) print() #TRI LISTE DE COMPLEXES print('TRI LISTE') print('Cartesien') print('Liste:') y = [Complexe(1, 1, 1), Complexe(2, 1, 1), Complexe(1, 3, 1)] print(y) r = tri(y) print('tri de la liste') print(r) print() print('Nouvelle liste:') u = [Complexe(1, 1, 1), Complexe(2, 1, 1), Complexe(1, 3, 1)] * 3 print(u) o = tri(u) print('tri de la liste') print(o) print() print('Polaire') print('Nouvelle liste:') g = [Complexe(1, pi / 4, 0), Complexe(2, pi / 4, 0), Complexe(1, pi, 0)] print(g) h = tri(g) print('tri de la liste') print(h) print() print('Nouvelle liste:') q = [Complexe(1, pi / 4, 0), Complexe(2, pi / 4, 0), Complexe(1, pi, 0)] * 3 print(q) j = tri(q) print('tri de la liste') print(j) print() a = Complexe(1, 4 * pi, 0) b = Complexe(1, -10 * pi, 0) print('a : ', a) print('b : ', b) print('a==b :', a == b) a = Complexe(1, 1, 1) b = Complexe(sqrt(2), pi / 4 + 1000 * pi, 0) print('a : ', a) print('b : ', b) print('a==b :', a == b)
def __init__(self): self.f1 = round(random.uniform(-10, 10), 10) #cartesiens self.s1 = round(random.uniform(-10, 10), 10) self.f2 = round(random.uniform(-10, 10), 10) self.s2 = round(random.uniform(-10, 10), 10) self.f3 = round(random.uniform(-10, 10), 10) self.s3 = round(random.uniform(-10, 10), 10) self.f4 = round(random.uniform(0, 10), 10) #polaires self.s4 = round(random.uniform(-10, 10), 10) self.f5 = round(random.uniform(0, 10), 10) self.s5 = round(random.uniform(-10, 10), 10) self.f6 = round(random.uniform(0, 10), 10) self.s6 = round(random.uniform(-10, 10), 10) self.f7 = round(random.uniform(1, 10), 10) self.s7 = round(random.uniform(1, 10), 10) self.f8 = round(random.uniform(1, 10), 10) self.s8 = round(random.uniform(0, pi / 2), 10) self.n = random.randint(0, 10) self.zCart = Complexe(self.f1, self.s1, 1) #un complexe cartesien self.zCart2 = Complexe(self.f2, self.s2, 1) #un autre complexe cartesien self.zCart3 = Complexe(self.f3, self.s3, 1) #un autre complexe cartesien self.zPol = Complexe(self.f4, self.s4, 0) #un complexe polaire self.zPol2 = Complexe(self.f5, self.s5, 0) #un autre complexe polaire self.zPol3 = Complexe(self.f6, self.s6, 0) #un autre complexe polaire self.zR = Complexe(self.f1, 0, 1) #un complexe reel self.zIm = Complexe(0, self.s1, 1) #un complexe imaginaire pur self.zPos = Complexe(self.f7, self.s7, 1) #un complexe cartesien strictement positif self.zPosPol = Complexe(self.f8, self.s8, 0) #un complexe polaire strictement positif self.zUn = Complexe(1, 0, 0) # 1 self.zI = Complexe(0, 1, 1) # i self.zZero = Complexe(0, 0, 1) # 0
def main_basique(): print("INIT et GETTER SETTER") print("A DEVIENT EST CARTESIEN") a = Complexe(0, 0, 1) print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print("a.isCartesien : ", a.isCartesien) print("a.isPolaire : ", a.isPolaire) print("A DEVIENT I+1") a.reel = 1 a.imag = 1 print("a.reel=1; a.reel : ", a.reel) print("a.imag=1; a.imag : ", a.imag) print("pi/4 : ", pi / 4) print("sqrt(2) : ", sqrt(2)) print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print("MODULE DEVIENT 1") a.module = 1 print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print("argument DEVIENT pi/2") a.argument = pi / 2 print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print() # TESTS print("TESTS") print("Cartesien : ") a = Complexe(1, 2, True) b = Complexe(1, 2, True) c = Complexe(1, 1, True) print("a : ", a) print("b : ", b) print("c : ", c) print("a==b : ", a == b) print("a==c : ", a == c) print("a<b : ", a < b) print("c<a : ", c < a) print("Polaire : ") a = Complexe(1.0, pi / 4, 0) b = Complexe(2, pi / 4, 0) c = Complexe(2, pi / 2, 0) print("a==b : ", a == b) print("a==c : ", a == c) print("a<b : ", a < b) print("c<a : ", c < a) print() # ADDITION: print("ADDITION") print("Cartesien ") a = Complexe(1, 2, True) b = Complexe(1, 2, True) print("a : ", a) print("b : ", b) print("a+b :", a + b) print("Polaire ") a = Complexe(2, pi / 2, False) b = Complexe(2, pi / 4, 0) print("a : ", a) print("b : ", b) print("a+b : ", a + b) print() # MULTIPLICATION print("MULTIPLICATION") print("Cartesien ") a = Complexe(1, 1, True) b = Complexe(1, 1, True) print("a : ", a) print("b : ", b) print("a*b : ", a * b) a = Complexe(1, 2, True) b = Complexe(1, 2, True) print("a : ", a) print("b : ", b) print("a*b : ", a * b) print("Polaire ") a = Complexe(1, pi / 2, 0) b = Complexe(2, pi / 4, 0) print("a : ", a) print("b : ", b) print("3pi/4 : ", 3 * pi / 4) print("a*b : ", a * b) print() # OPPOSE print("OPPOSE") print("Cartesien : ") a = Complexe(-3, 0, True) print("a : ", a) print("a.oppose : ", a.oppose) print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print("a.oppose.cartesien : ", a.oppose.cartesien) print("a.oppose.polaire : ", a.oppose.polaire) print("Polaire : ") a = Complexe(2, pi, 0) print("a : ", a) print("a.oppose : ", a.oppose) print("a.cartesien : ", a.cartesien) print("a.polaire : ", a.polaire) print("a.oppose.cartesien : ", a.oppose.cartesien) print("a.oppose.polaire : ", a.oppose.polaire) print() # INVERSE print("INVERSE") print("Cartesien ") a = Complexe(1, 1, 1) print("a : ", a) print(a.inverse) print("Polaire ") a = Complexe(2, 2 * pi / 3, 0) print("a : ", a) print(a.inverse) print() # CONJUGUE print("CONJUGUE") print("Cartesien") a = Complexe(1, 2, 1) print("a : ", a) print(a.conjugue) print("Polaire") a = Complexe(1, 5 * pi / 6, 0) print("a : ", a) print(a.conjugue) print() # VALEUR ABSOLUE print("VALEUR ABSOLUE") print("Cartesien") a = Complexe(1, 1, 1) print("a : ", a) print(abs(a)) print(sqrt(0.5)) print(abs(a.inverse)) print("Polaire") a = Complexe(87, pi / 3, 0) print("a : ", a) print(abs(a)) print() # SOUSTRACTION print("SOUSTRACTION") print("Cartesien") a = Complexe(1, 1, 1) b = Complexe(1, -3, 1) print("a : ", a) print("b : ", b) print("a-b : ", a - b) print("Polaire") a = Complexe(sqrt(2), pi / 4, 0) b = Complexe(1, pi / 2, 0) print("a : ", a) print("b : ", b) print("a-b : ", a - b) print() # DIVISION print("DIVISION") print("Cartesien: ") a = Complexe(1, 1, 1) print("a : ", a) print("a/a : ", a / a) print("Polaire : ") a = Complexe(42, pi / 2, 0) b = Complexe(2, pi / 4, 0) print("a : ", a) print("b : ", b) print("pi/4 ", (pi / 4)) print("a/b : ", a / b) print() # PUISSANCE ENTIERE print("PUISSANCE ENTIERE") print("Cartesien") a = Complexe(1, 1, 1) print("a : ", a) print("a**2 : ", a ** 2) print("a**3 : ", a ** 3) print("a**4 : ", a ** 4) print("Polaire") a = Complexe(1, pi, 0) print("a : ", a) print("a**2 : ", a ** 2) print("a**3 : ", a ** 3) print("a**4 : ", a ** 4) print() # CHERCHE DANS LISTE DE COMPLEXES print("CHERCHE") l = [Complexe(i, j, 1) for i in range(2) for j in range(5)] print(l) print() g = [Complexe(i, j, 0) for i in range(2) for j in range(5)] print(g) a = Complexe(1, 4, 1) print("a : ", a) print("a.find(l) : ", a.find(l)) print("a.find(g) : ", a.find(g)) a = Complexe(1, 4, 0) print("a : ", a) print("a.find(g) : ", a.find(g)) print() # TRI LISTE DE COMPLEXES print("TRI LISTE") print("Cartesien") print("Liste:") y = [Complexe(1, 1, 1), Complexe(2, 1, 1), Complexe(1, 3, 1)] print(y) r = tri(y) print("tri de la liste") print(r) print() print("Nouvelle liste:") u = [Complexe(1, 1, 1), Complexe(2, 1, 1), Complexe(1, 3, 1)] * 3 print(u) o = tri(u) print("tri de la liste") print(o) print() print("Polaire") print("Nouvelle liste:") g = [Complexe(1, pi / 4, 0), Complexe(2, pi / 4, 0), Complexe(1, pi, 0)] print(g) h = tri(g) print("tri de la liste") print(h) print() print("Nouvelle liste:") q = [Complexe(1, pi / 4, 0), Complexe(2, pi / 4, 0), Complexe(1, pi, 0)] * 3 print(q) j = tri(q) print("tri de la liste") print(j) print() a = Complexe(1, 4 * pi, 0) b = Complexe(1, -10 * pi, 0) print("a : ", a) print("b : ", b) print("a==b :", a == b) a = Complexe(1, 1, 1) b = Complexe(sqrt(2), pi / 4 + 1000 * pi, 0) print("a : ", a) print("b : ", b) print("a==b :", a == b)