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
|
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
# Nombre au carré << nombre10carre.py >>
from decimal import *
def resume():
print("""Le nombre_carre utilise le module decimal...
La racine carrée réelle a forme générique
Pour les opérations et les comparaisons
Le traité se porte sur le nombre (ex:13.25)
Les nombres négatifs en string dans le code
Au vu du capable complexe de nombre_carre...""")
def espec6(ome):
""" Séparation décimale pour typage(%6)
# *(_TableTypeGénéral = [0,1,2,3,4,5]_)*
# Type 6: Supérieur à *(_TTG_)"""
# Recherche du point décimal
if '.' in ome:
nentie = len(str(int(float(ome)))) # Poids.Entier.fort
if ome[0] == '-':
nentie += 1
else:
# Nombre.Entier
nentie = len(str(int(ome))) # Poids.Entier.faible
nmasse = len(ome) # Masse.Nombre
nmedif = nmasse - nentie # Mesure.Decimale
ndecim = ome[nentie + 1:] # Masse.Decimale
# Mesure.Decimale
if nmedif != 0:
fnd = 0
for nd in ndecim:
fnd += int(nd) # Addition ndecim(nd)
if fnd != 0: # Somme positive
break # Nombre.Décimal
if fnd == 0:
# Nombre.Entier
pass
else:
decim6[0] = int(ome[nentie + 1:]) % 6
# Condition nombre négatif
if ome[0] == '-':
decim6[0] = int(str('-' + str(decim6[0])))
def opera(nop):
"""Fonction opératoire"""
def addition(i, j):
return i + j
def soustraction(i, j):
return i - j
def multiplie(i, j):
return i * j
def expose(i, j):
return i ** j
def division(i, j):
return i / j
def diventier(i, j):
return i // j
def modulo(i, j):
return i % j
signe = {'+': addition, '-': soustraction, '*': multiplie,
'**': expose, '/': division, '//': diventier,
'%': modulo}
nbr1 = Decimal(nop[0])
operation = signe[nop[1]]
nbr2 = Decimal(nop[2])
opombre[0] = str(operation(nbr1, nbr2))
if 'E' in opombre[0] or 'e' in opombre[0]:
op_e = []
op_o = len(opombre[0])
for ie in range(op_o - 1, 0, -1):
if opombre[0][ie] in ("E", '+', '-'):
break
else:
op_e.append(opombre[0][ie])
op_r = list(reversed(op_e))
op_j = (''.join(str(o0) for o0 in op_r))
getcontext().prec = int(op_j) + op_o
opombre[0] = str(operation(nbr1, nbr2))
def nombre_carre(nbr):
""" Cette fonction produit la racine carrée du nombre, et
elle commence par définir la partie entière de la racine².
Qui en général a une virgule flottante ( point décimal )
La polarité du nombre signé, forme une transition (+-)
Analyse de la surface(Typique = Nombre % 6)
1 = 7 % 6 :7%6: Pôle positif naturel
-1 = -7 % -6 :-7%-6: Pôle négatif naturel
5 = -7 % 6 :-7%6: Transit positif naturel
-5 = 7 % -6 :7%-6: Transit négatif naturel
"""
nbr = Decimal(nbr)
if nbr <= -0:
nbr = Decimal(str(nbr)[1:])
rondeur[1] = 1
# Précision.Allusion.Illusion.
premax = 100000000
""" Modulation unaire"""
if len(str(nbr)) < 10:
precision = (len(str(nbr)) + 1) * 10
precisive = '(*10)'
elif 10 <= len(str(nbr)) < 50:
precision = int(len(str(nbr)) ** 2)
precisive = '(**2)'
elif 50 <= len(str(nbr)) < 100:
precision = int(len(str(nbr)) ** 1.75)
precisive = '(**1.75)'
elif 100 <= (int(len(str(nbr)))) < premax:
precision = int(len(str(nbr)) ** 1.25)
precisive = '(**1.25)'
else:
return
getcontext().prec = precision
# Maximum(machine locale) = 100000000
# Racine² décimale entière
wh = int(nbr ** Decimal(.5))
wh0 = (nbr ** Decimal(.5))
nbu = nbr
# Secteur décimal
decitab = []
if rondeur[1] == 1:
entiere[0] = str('-' + str(wh))
else:
entiere[0] = str(wh)
print('entiere =', entiere[0])
www = nbrdec = nc = top = 0
while image[0] ** 2 <= nbr and top == 0:
for img in range(1, 10):
if decitab:
image[0] = Decimal(entiere[0] + '.' + recital[0] + str(img))
else:
if not nc:
nbrdec += 1 # Unité décimale
nc = 1
image[0] = Decimal(entiere[0] + '.' + str(img))
if image[0] ** 2 > nbr:
decitab.append(img - 1)
nbrdec += 1 # Nombre de décimales
recital[0] = (''.join(str(d) for d in decitab))
image[0] = Decimal(entiere[0] + '.' + recital[0])
if image[0] ** 2 == nbr:
rondeur[0] = 'Juste racine² | nbr |'
top = 1
break
break
elif img == 9:
if image[0] ** 2 == nbr:
rondeur[0] = 'Juste racine² | i9 |'
top = 1
break
decitab.append(img)
nbrdec += 1 # Nombre de décimales
recital[0] = (''.join(str(d) for d in decitab))
image[0] = Decimal(entiere[0] + '.' + recital[0])
elif image[0] ** 2 == nbr:
rondeur[0] = 'Juste racine² | elif |'
top = 1
recital[0] = str(image[0])[len(entiere[0]) + 1:]
break
# print(www, '°°° **2 =', image[0] ** 2)
www += 1
else:
if len(str(rondeur[0])) < 1:
rondeur[2] = 'Variant racine² | not |'
nb0 = str(int(nbr) % 6)
if rondeur[1] == 1:
nbr = Decimal('-' + str(nbr))
wh0 = Decimal('-' + str(wh0))
nb0 = '-' + nb0
sq0 = wh0
if decim6[0] < 6:
print('Rnombre =', nbr, ';typo =', [nb0,
'.', str(decim6[0])])
else:
print('Rnombre =', nbr, ';typo =', [nb0])
if sq0 ** 2 == nbu:
print('_Rreelle_juste =', sq0)
else:
print('_Rracine =', sq0)
print('*... (', nbrdec, ') Precision', precision, precisive)
# Nombre à forme décimale
""" Une décimale au format texte a un meilleur suivi """
# :nombre = '22135323.12554':
# imageoo2 = 22135323.125540000000000000000000000000000000...
# ...00000000000000000000000000000000000000000000000000000000
# :nombre = 22135323.12554:
# imageoo2 = 22135323.125539999455213546752929687500000000...
# ...00000000000000000000000000000000000000000000000000000000
"""."""
# Parenthèses non gérées
nombre = '-.02'
# Point de dérivation décimale
"""Précision multimétrique du point '.'
Selon que {2: A, 2.: B, 2.0: C}:
Nul doute, l'unité du point est un premier pas,
pour arriver au zéro décimal en plusieurs fois."""
# Métrique du zéro décimal
if nombre[-1] == '.':
nombre += '0'
# Mathématique sur nombres
opsigne = ['+', '-', '*', '/', '%', '**', '//'] # Signes math
opforme = ['(', ')', '='] # Formes math
opserie = [] # Collecte éléments
opombre = ['']
nn0 = nn1 = nn2 = 0
oo0 = oo1 = ''
for no in nombre:
oo0 += no
nn2 += 1
if no in opsigne and nn0 != 0 \
and len(oo1) < 2:
oo1 += no
pp = len(oo0) - 1
if oo1 in opsigne:
if nn1 == 0:
opserie.append(oo0[:pp])
oo0 = ''
if oo1 not in opsigne and len(oo1) > 1:
oo0 = oo1[1]
oo1 = oo1[0]
nn1 = 1
nn1 = 1
elif no in opforme: # Gestion paranthèse
pass
elif no == ' ': # Gestion espace blanc
pass
else:
if nn1 == 1:
opserie.append(oo1)
oo1 = ''
nn1 = 0
nn0 += 1
if len(nombre) == nn2 and oo0 \
and oo0 != nombre:
opserie.append(oo0)
# Série opération
if opserie:
opera(opserie)
if opombre[0] != '':
nombre = opombre[0]
# Séparation décimale pour typage(%6)
decim6 = [6]
espec6(nombre)
image = {0: 0} # Dico.Nombre réel
rondeur = {0: '', 1: 0} # Dico.Comment
entiere = {0: ''} # Dico.Racine.Entier
recital = [0] # Table.Décimale
nombre_carre(nombre) # Appel principal
if recital[0] != 0:
recital[0] = str(image[0])[len(entiere[0]) + 1:]
print('Rrecital =', recital[0], '\n...*')
oo2 = image[0] ** 2
if rondeur[1] == 1:
oo2 = Decimal('-' + str(oo2))
print('Iimageoo1 =', image[0], '\n..**',
'\nIimageoo2 =', oo2)
print('.***')
if image[0]:
if rondeur[0]:
print('Rondeur 0:', rondeur[0])
elif rondeur[2]:
print('Rondeur 2:', rondeur[2], '\nReste =',
Decimal(nombre) - ((image[0]) ** 2))
else:
rondeur[0] = 'Valeur intervalle'
print('Rondeur 0:', rondeur[0], '\nReste =',
Decimal(nombre) - ((image[0]) ** 2))
else:
if float(nombre) == 0:
print('Rrondeur : Juste réro limite | zéro |')
else:
print('Rrondeur : Juste hors limite | premax |')
# resume()
# |
Partager