from abe import * def nombre_opérateurs(A): if est_feuille(A): return 0 else: g = nombre_opérateurs(fg(A)) d = nombre_opérateurs(fd(A)) return 1 + g + d def est_arithmétique(A): if est_feuille(A): return type(A) == int else: g = est_arithmétique(fg(A)) d = est_arithmétique(fd(A)) return g and d def est_arithmétique(A): if est_feuille(A): return type(A) == int else: return est_arithmétique(fg(A)) and est_arithmétique(fd(A)) ## Question 6.1 def min_feuille(A): # A est supposé arithmétique if est_feuille(A): return A else: mg = min_feuille(fg(A)) md = min_feuille(fd(A)) return min(mg, md) ## Question 6.2 def min_feuille2(A): # A n'est plus supposé arithmétique if est_feuille(A): if type(A) == int: return A else: raise ValueError('Pas de feuille entière') else: try: mg = min_feuille2(fg(A)) except: return min_feuille2(fd(A)) try: md = min_feuille2(fd(A)) except: return mg return min(mg, md) import math def min_feuille2_2(A) : def aux(A) : if est_feuille(A) : if type(A) == int : return A else : return math.inf # infini else : return min(aux(fg(A)), aux(fd(A))) res = aux(A) if res == math.inf : raise ValueError("pas de feuille entiere") else : return res # Question 7.1 def pp_infix(A): if est_feuille(A): return [A] else: return pp_infix(fg(A)) + [racine(A)] + pp_infix(fd(A)) ## Question 7.2 def repr_math_0(A): if est_feuille(A): return str(A) else: rg = repr_math(fg(A)) rd = repr_math(fd(A)) o = racine(A) return f'({rg}{o}{rd})' def repr_math(A): if est_feuille(A): return str(A) else: if est_feuille(fg(A)): rg = repr_math(fg(A)) else: rg = '(' + repr_math(fg(A)) + ')' if est_feuille(fd(A)): rd = repr_math(fd(A)) else: rd = '(' + repr_math(fd(A)) + ')' o = racine(A) return f'{rg}{o}{rd}' def arboriser(A): # A est une liste while len(A)>2: L=[] i=0 while i