Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. documentclass[tikz]{standalone}
  2. begin{document}
  3. begin{tikzpicture}[scale=12]
  4. draw (0,0) -- (1,0);
  5. draw (0,0) -- (0,.618);
  6. draw (1,0) -- (1,.618);
  7. draw (1,0) arc (0:180:.5);
  8.  
  9. draw [dotted] (0,0) -- (0,-.1) node[below]{$frac{0}{1}$};
  10. draw [dotted] (1,0) -- (1,-.1) node[below]{$frac{1}{1}$};
  11.  
  12. draw (1,0) arc (0:180:.25);
  13. draw [dotted] (.5,0) -- (.5,-.1) node[below]{$frac{1}{2}$};
  14. draw (.5,0) arc (0:180:.25);
  15.  
  16. draw (1,0) arc (0:180:1/6);
  17. draw [dotted] (2/3,0) -- (2/3,-.1) node[below]{$frac{2}{3}$};
  18. draw (2/3,0) arc (0:180:1/12);
  19.  
  20. draw (1/3,0) arc (0:180:1/6);
  21. draw [dotted] (1/3,0) -- (1/3,-.1) node[below]{$frac{1}{3}$};
  22. draw (1/2,0) arc (0:180:1/12);
  23.  
  24. end{tikzpicture}
  25. end{document}
  26.  
  27. documentclass[tikz]{standalone}
  28. newcountrecurdepth
  29. begin{document}
  30. begin{tikzpicture}[scale=2]
  31. draw[style=help lines] (0,0) grid[step=0.1cm] (1,0.5);
  32.  
  33. defmyrecur#1#2#3#4#5{
  34. recurdepth=#5
  35. ifnumtherecurdepth>1relax
  36. advancerecurdepth by-1relax
  37. edeftempnum{numbernumexpr#1+#3relax}%a+b
  38. edeftempden{numbernumexpr#2+#4relax}%c+d
  39. pgfmathparse{tempnum/tempden}edeftemp{pgfmathresult}%(a+b)/(c+d)
  40.  
  41. node[below=therecurdepth*1pt,scale=0.1*therecurdepth]at({(temp)*1cm},0){$frac{tempnum}{tempden}$};
  42. draw[ultra thin,opacity=therecurdepth/10] ({(temp)*1cm},0) arc (180:0:{((#3/#4)-temp)*0.5cm});
  43. draw[ultra thin,opacity=therecurdepth/10] ({(temp)*1cm},0) arc (0:180:{(temp-(#1/#2))*0.5cm});
  44. begingroup
  45. edefttempup{noexpandmyrecur{tempnum}{tempden}{#3}{#4}{therecurdepth}}
  46. edefttempdown{noexpandmyrecur{#1}{#2}{tempnum}{tempden}{therecurdepth}}
  47. ttempupttempdown
  48. endgroup
  49. fi
  50. }
  51.  
  52. myrecur{0}{1}{1}{1}{6}
  53.  
  54. end{tikzpicture}
  55. end{document}
  56.  
  57. documentclass[tikz]{standalone}
  58. begin{document}
  59. begin{tikzpicture}
  60. draw [ultra thick] (-8,0) -- (8,0);
  61. draw [ultra thick] (0,0) circle (8);
  62. foreach i in {0,1,2,3} {%
  63. draw [ultra thick] (90*i:8) arc (270+90*i:180+90*i:8);}
  64. foreach i in {0,1,...,7} {%
  65. draw [very thick] (45*i:8) arc (270+45*i:135+45*i:3.3);}
  66. foreach i in {0,1,...,15} {%
  67. draw [thick] (22.5*i:8) arc (270+22.5*i:112.5+22.5*i:1.6);}
  68. foreach i in {0,1,...,31} {%
  69. draw [thin] (11.25*i:8) arc (270+11.25*i:101.25+11.25*i:0.8);}
  70. foreach i in {0,1,...,63} {%
  71. draw [ultra thin] (5.625*i:8) arc (270+5.625*i:95.625+5.625*i:0.4);}
  72. end{tikzpicture}
  73. end{document}
  74.  
  75. input latexmp;
  76. setupLaTeXMP(packages="amsmath", options = "12pt", textextlabel = enable, mode = rerun);
  77.  
  78. numeric u, m;
  79. u = 20cm; % scale
  80. m = 8; % maximal denominator
  81.  
  82. % [a/b, c/d]: diameter, n: recursion level
  83. def farey_diagram(expr a, b, c, d, n) =
  84. draw halfcircle scaled ((c/d-a/b)*u) shifted (u*0.5[a/b,c/d], 0);
  85. if (n > 1) and (b+d <= m):
  86. label.bot("$dfrac{" & decimal(a+c) & "}{"& decimal(b+d) & "}$", u*((a+c)/(b+d), 0));
  87. farey_diagram(a, b, a+c, b+d, n-1); farey_diagram(a+c, b+d, c, d, n-1);
  88. fi;
  89. enddef;
  90.  
  91. beginfig(1);
  92. draw origin -- (u, 0);
  93. label.bot("$0$", origin); label.bot("$1$", (u, 0));
  94. % starting with 0/1 and 1/1; m levels of recursion needed
  95. farey_diagram(0, 1, 1, 1, m);
  96. endfig;
  97. end.
  98.  
  99. last_level = 10
  100. labelled_level = 3
  101.  
  102. label_dist = 0.1
  103. tikz_scale = 12
  104.  
  105. axis_height = 0.618
  106.  
  107. def farey_sequence(n):
  108. """Returns the nth Farey sequence in ascending order."""
  109. farey_list = []
  110. a, b, c, d = 0, 1, 1, n
  111. farey_list.append("%d/%d" % (a, b))
  112. while c <= n:
  113. k = int((n + b) / d)
  114. a, b, c, d = c, d, k * c - a, k * d - b
  115. farey_list.append("%d/%d" % (a, b))
  116.  
  117. return farey_list
  118.  
  119. def tikz_farey_sequence(n):
  120. """Returns the nth Farey sequence, suitable for processing in TikZ."""
  121. farey = farey_sequence(n)
  122. twinned_pairs = [farey[i] + '/' + farey[i+1] for i in xrange(len(farey) - 1)]
  123. return str(twinned_pairs)[1:-1].replace("'", "")
  124.  
  125. tikz_lines = [
  126. '\begin{tikzpicture}[scale=%d]' % tikz_scale,
  127. '',
  128. '\draw (0,%f) -- (0,0) -- (1,0) -- (1,%f);' % (axis_height, axis_height),
  129. ''
  130. ]
  131.  
  132. for lvl in range(last_level):
  133. new_lines = [
  134. '\foreach \a/\b/\c/\d in { %s } {' % tikz_farey_sequence(lvl + 1),
  135. ' \draw (\a/\b, 0) arc (180:0:\c / \d / 2 - \a / \b / 2);']
  136.  
  137. if lvl == labelled_level:
  138. new_lines.extend([
  139. ' \draw [dotted] (\a/\b, 0) -- (\a/\b, -%f) node [below] {$\frac{\a}{\b}$};' % label_dist,
  140. '}',
  141. '\draw [dotted] (1/1, 0) -- (1/1, -%f) node [below] {$\frac{1}{1}$};' % label_dist,
  142. ''])
  143. else:
  144. new_lines.extend(['}',''])
  145.  
  146.  
  147. tikz_lines.extend(new_lines)
  148.  
  149. tikz_lines.append('\end{tikzpicture}')
  150.  
  151. print 'n'.join(tikz_lines)
  152.  
  153. documentclass[border=5]{standalone}
  154. usepackage{pgffor}
  155. {catcode`%=11gdefpc{%}}
  156. directlua{
  157. Rational = {}
  158. Rational.__index = Rational
  159.  
  160. function Rational.new(p, q)
  161. local a, b, object
  162. a, b = p, q
  163. while b > 0 do
  164. a, b = b, a pc b
  165. end
  166. object = {p=p/a, q=q/a}
  167. setmetatable(object, Rational)
  168. return object
  169. end
  170.  
  171. function Rational:toString()
  172. return "" .. self.p .. "/" .. self.q
  173. end
  174.  
  175. function Rational.__eq(P, Q)
  176. return (P.p == Q.p) and (P.q == Q.q)
  177. end
  178.  
  179. function Rational.__add(P, Q)
  180. return Rational.new(P.p*Q.q + Q.p*P.q, P.q*Q.q)
  181. end
  182.  
  183. function Rational.__sub(P, Q)
  184. return Rational.new(P.p*Q.q - Q.p*P.q, P.q*Q.q)
  185. end
  186.  
  187. Sequence = {}
  188. Sequence.__index = Sequence
  189.  
  190. function Sequence.new()
  191. local object = {data={}, n=0}
  192. setmetatable(object, Sequence)
  193. return object
  194. end
  195.  
  196. function Sequence:get(i)
  197. return self.data[i]
  198. end
  199.  
  200. function Sequence:append(v)
  201. table.insert(self.data, v)
  202. self.n = self.n + 1
  203. end
  204.  
  205. function Sequence:toString()
  206. local s, i
  207. s = ""
  208. if self.n > 0 then
  209. s = s .. self.data[1]:toString()
  210. if self.n > 1 then
  211. for i = 2,self.n do
  212. s = s .. "," .. self.data[i]:toString()
  213. end
  214. end
  215. end
  216. return s
  217. end
  218.  
  219. function farey_sequence(n)
  220. local f1, f2, t1, t2, i, j
  221. f1 = Sequence.new()
  222. f1:append(Rational.new(0,1))
  223. f1:append(Rational.new(1,1))
  224. if n > 1 then
  225. for i = 1,n do
  226. f2 = f1
  227. f1 = Sequence.new()
  228. for j = 1, f2.n-1 do
  229. t1 = f2:get(j)
  230. t2 = f2:get(j+1)
  231. f1:append(t1)
  232. if (t2-t1 == Rational.new(1, t1.q*t2.q)) and t1.q+t2.q <= n then
  233. f1:append(Rational.new(t1.p+t2.p, t1.q+t2.q))
  234. end
  235. end
  236. f1:append(t2)
  237. end
  238. end
  239. return f1
  240. end
  241. }
  242.  
  243. defgetfareysequence#1#2{%
  244. edef#1{directlua{tex.print(farey_sequence(#2):toString())}}%
  245. }
  246. begin{document}
  247. begin{minipage}{4in}
  248. foreach i in {1,...,8}{
  249. getfareysequenceA{i}
  250. $F_{i}=left{foreach n/d [count=k] in A {ifnumk>1,fifrac{n}{d}}right}$
  251. \[.5ex]
  252. }
  253. end{minipage}
  254. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement