#!/usr/bin/env clojure ;; Fermats' Christmas Theorem: Windmills ;; Sorry for the delay, I had COVID. I'm fine, don't worry! ;; Let's pick an arbitrary number of the form 4n+1, say 29 ;; Precisely because it's of form 4n+1, we can split it into a central square and four identical ;; blocks, in this case, a 1x1 square and four 1x7 blocks ;; 29 = 1*1 + 4 * (1 * 7) (+ (* 1 1) (* 4 (* 1 7))) ; 29 ;; Let's draw that: ;; I'm not going to explain how the svg making thing works, but see: ;; http://www.learningclojure.com/2010/10/generatingxmltomakesvgvector.html ;; if you're curious about the details (require 'clojure.xml) (def squaresize 10) (defn makerect [i j colour] {:tag :rect :attrs {:x (str (* i squaresize)) :y (str (* j squaresize)) :width (str squaresize) :height (str squaresize) :style (str "fill:", colour, ";stroke:black;strokewidth:1px;strokelinecap:butt;strokelinejoin:miter;strokeopacity:1")}}) ;; SVG coordinates have 0,0 in the top left corner, whereas I like my origin in the middle, ;; and with the vertical component increasing as we go up, so this is a coordinate transform ;; That converts my system to SVG's system. (defn adjustlist [rectlist] (let [hmin (apply min (map first rectlist)) vmax (apply max (map second rectlist))] (for [[a b c] rectlist] [( a hmin) ( vmax b) c]))) (defn makesvg [objects] {:tag :svg :attrs {:width "100%" :height "100%" :version "1.1" :xmlns "http://www.w3.org/2000/svg"} :content (for [[i j c] (adjustlist objects)] (makerect i j c))}) (defn svgfile [filename objects] (spit (str filename ".svg") (withoutstr (clojure.xml/emit (makesvg objects))))) (defn orange [n] (if (< n 0) (range 0 n 1) (range 0 n 1))) (defn makecompositerectangle [h v hsquares vsquares colour] (for [i (orange hsquares) j (orange vsquares)] [(+ i h) (+ j v) colour])) ;; With this drawing code in hand we can diagram 29 = 1 * 1 + 4 * (1 * 7) ;; As this windmill shape: (svgfile "windmill291" (concat (makecompositerectangle 0 0 1 1 "red") (makecompositerectangle 1 0 7 1 "white") (makecompositerectangle 1 0 7 1 "white") (makecompositerectangle 0 1 1 7 "green") (makecompositerectangle 0 1 1 7 "green"))) ;; Or alternatively we could show it as 29 = 1*1 + 4 * (1 * 7) (svgfile "windmill292" (concat (makecompositerectangle 0 0 1 1 "red") (makecompositerectangle 1 0 1 7 "white") (makecompositerectangle 1 0 1 7 "white") (makecompositerectangle 0 1 7 1 "green") (makecompositerectangle 0 1 7 1 "green"))) ;; Now we notice that there's a 3x3 square in the middle, so what about: (svgfile "windmill293" (concat (makecompositerectangle 1 1 3 3 "red") (makecompositerectangle 1 2 1 5 "white") (makecompositerectangle 1 2 1 5 "white") (makecompositerectangle 2 1 5 1 "green") (makecompositerectangle 2 1 5 1 "green"))) ;; Which is equivalent to 29 = 3*3 + 4* (1 * 5) ;; And then of course we can flatten the arms again: ;; 29 = 3*3 + 4 * ( 5 * 1 ) (svgfile "windmill294" (concat (makecompositerectangle 1 1 3 3 "red") (makecompositerectangle 1 2 5 1 "white") (makecompositerectangle 1 2 5 1 "white") (makecompositerectangle 2 1 1 5 "green") (makecompositerectangle 2 1 1 5 "green"))) ;; And we see a 5*5 square now, so ;; 29 = 5*5 + 4 * ( 1 * 1) (svgfile "windmill295" (concat (makecompositerectangle 2 2 5 5 "red") (makecompositerectangle 3 2 1 1 "white") (makecompositerectangle 3 2 1 1 "white") (makecompositerectangle 2 3 1 1 "green") (makecompositerectangle 2 3 1 1 "green"))) ;; Notice now that our diagram is one big odd square, and four little squares ;; Four little squares can be combined into one big even square ;; 4*1*1 is also equal to 2*2*1*1, = (2*1)*(2*1) = 2*2 ;; so 29 = 5*5+2*2 ;; Which is to say that 29, a prime number of form 4n + 1, is equal to the sum of an odd and an even square. ;; 29 = 25 + 4 ;; These windmill drawings form the core of the proof of the Christmas Theorem. Try the technique out on some other numbers!
Blog Archive

▼
2021
(12)

▼
December
(11)
 Clojure Setup from Scratch on a Clean Install of D...
 Fermat's Christmas Theorem : Fixed Points Come In ...
 Christmas Theorem: Some Early Orbits
 Chrismas Theorem: Automatic Windmills
 Christmas Theorem: Principled Windmills
 Fermat's Christmas Theorem: Windmills
 A Festive Theorem
 A test program
 Emacs, even
 Clojure Shell Scripts on Debian
 Hello Again World (2nd December 2021) Setting Up C...

▼
December
(11)
Search This Blog
Sunday, December 19, 2021
Fermat's Christmas Theorem: Windmills
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment