lambdaway
::
hilbert_chatgpt
6
|
list
|
login
|
load
|
|
{center {svg {@ width="580px" height="580px" style="background:#666; color:#fff;"} {path {@ id="spline" d="M {turtle 10 10 0 {left 18 5}}" fill="transparent" stroke="#fff" stroke-width="3" }} }} {center {b [[chatgpt]] &} [[lambdatalk|?view=chatgpt_lambdatalk]] | [[roots|?view=chatgpt_20250220]] | [[langage|?view=chatgpt_langue]] | [[évaluation|?view=chatgpt_evaluation]] | [[hilbert|?view=hilbert_chatgpt]] | [[magali|?view=chatmag]] | [[relativité|?view=relativite_complexe]] | [[costa|?view=chatgpt_costa]] | [[feynman|?view=chatgpt_feynman]] | incertitude ([[1|?view=chatgpt_incertitude]],[[2|?view=chatgpt_incertitude_2]]) | hélices ([[1|?view=chatgpt_helices]],[[2|?view=chatgpt_helices2]]) | [[synthèse|?view=chatgpt_synthese]] |[[casteljau|?view=decasteljau4]] | [[soliton]] | [[dirac|?view=chatgpt_dirac]] | [[young|?view=chatgpt_young]] | [[relatif|?view=relativite_complexe_3]] | [[charon]] | [[compton|?view=chatgpt_compton]]} _h1 chatGPT & hilbert's curve _p Voir [[hilbert]]. _h2 1) λtalk {prewrap '{def left {lambda {:d :n} {if {< :n 1} then else T90 {right :d {- :n 1}} M:d T-90 {left :d {- :n 1}} M:d {left :d {- :n 1}} T-90 M:d {right :d {- :n 1}} T90 }}} -> {def left {lambda {:d :n} {if {< :n 1} then else T90 {right :d {- :n 1}} M:d T-90 {left :d {- :n 1}} M:d {left :d {- :n 1}} T-90 M:d {right :d {- :n 1}} T90}}} '{def right {lambda {:d :n} {if {< :n 1} then else T-90 {left :d {- :n 1}} M:d T90 {right :d {- :n 1}} M:d {right :d {- :n 1}} T90 M:d {left :d {- :n 1}} T-90 }}} -> {def right {lambda {:d :n} {if {< :n 1} then else T-90 {left :d {- :n 1}} M:d T90 {right :d {- :n 1}} M:d {right :d {- :n 1}} T90 M:d {left :d {- :n 1}} T-90}}} } _p The word {code Tθ} rotates the drawing direction of a pen from {b θ} degrees and the word {code Md} moves it on {b d} pixels. Writing {b '{left 18 5}} produces 2387 words begining with [T90 T-90 T90 T-90 T90 M10 T-90 M10 T-90 M10 T90 M10 T90 T-90 M10 T90 M10 T90 M10 T-90 M10 T-90 M10 T90 M10 T90 M10 T-90 T90 M10 T90 M10 T-90 M10 T-90 ...] which are sent to a graphic primitive, {b turtle}, which draws the curve in a SVG context. _p So writing: {pre '{center {svg {@ width="580px" height="580px" style="background:#666; color:#fff;"} {path {@ id="spline" d="M {turtle 10 10 0 {left 18 5}}" fill="transparent" stroke="#fff" stroke-width="3" }}}} } _p displays in real-time the picture on top of this wiki page. _h2 2) python _p Le code python suivant a été produit par ChatGPT le 19/02/2025, à partir du code lambdatalk que je lui ai donné en exemple. {pre import matplotlib.pyplot as plt import numpy as np # Initialisation des paramètres angle = 90 # Angle de rotation (90°) length = 10 # Longueur d'un segment iterations = 5 # Nombre de niveaux de récursion # Directions possibles (tortue LOGO) directions = '{ "T90": np.pi / 2, # Tourne de 90° à gauche "T-90": -np.pi / 2 # Tourne de 90° à droite } # Fonction récursive générant la courbe de Hilbert def hilbert_curve(order, length, angle, left=True): if order == 0: return [] if left: return [ "T90", *hilbert_curve(order-1, length, angle, not left), "M", length, "T-90", *hilbert_curve(order-1, length, angle, left), "M", length, *hilbert_curve(order-1, length, angle, left), "T-90", "M", length, *hilbert_curve(order-1, length, angle, not left), "T90" ] else: return [ "T-90", *hilbert_curve(order-1, length, angle, not left), "M", length, "T90", *hilbert_curve(order-1, length, angle, left), "M", length, *hilbert_curve(order-1, length, angle, left), "T90", "M", length, *hilbert_curve(order-1, length, angle, not left), "T-90" ] # Génération des instructions instructions = hilbert_curve(iterations, length, angle, left=True) # Dessin de la courbe avec une tortue virtuelle x, y = [0], [0] # Coordonnées initiales direction = 0 # Direction initiale (vers la droite) for instr in instructions: if instr == "T90" or instr == "T-90": direction += directions[instr] # Rotation de la direction elif instr == "M": # Calcul du déplacement new_x = x[-1] + np.cos(direction) * length new_y = y[-1] + np.sin(direction) * length x.append(new_x) y.append(new_y) # Affichage du tracé plt.figure(figsize=(6, 6)) plt.plot(x, y, 'b-', linewidth=2) plt.axis("equal") plt.axis("off") plt.title("Courbe de Hilbert - Niveau '{}".format(iterations)) plt.show() } _p Il est sensé produire le même résultat dans un environnement Python. _p {i alain marty | 2025/02/19}
lambdaway v.20211111