Rename *ll* and *ul* to ll and ul in in-interval
[maxima.git] / share / pytranslate / cantorr.py
blobdef0f740cc46600378c4addfd470047b99b2748d
1 from pytranslate import *
3 #########################
4 ### Cantorr2 Function ###
5 #########################
6 def block17340(v):
7 v = Stack({}, v)
8 if ((v["x"] > 0) and (v["x"] <= (1 / 3))):
9 v["ret"] = cantorr2((3 * v["x"]), (v["n"] + (-1)))
10 if (((1 / 3) < v["x"]) and (v["x"] < (2 / 3))):
11 v["ret"] = 1
12 if ((v["x"] >= (2 / 3)) and (v["x"] < 1)):
13 v["ret"] = (1 + cantorr2(((3 * v["x"]) + (-2)), (v["n"] + (-1))))
14 return((v["ret"] / 2))
15 def cantorr2(x, n, v = v):
16 v = Stack({}, v)
17 v.ins({"x" : x, "n" : n})
18 v.ins({"ret" : 0, "k" : 0})
19 if not(f["numberp"](v["x"])):
20 return(f["cantorr2"](v["x"], v["n"]))
21 if (v["x"] == 0):
22 return(0)
23 if (v["x"] == 1):
24 return(1)
25 f["print"](v["x"], v["n"])
26 return((block17340(v) if (v["n"] > 0) else v["x"]))
27 f["cantorr2"] = cantorr2
30 #########################
31 ### Cantorri Function ###
32 #########################
33 def block34784(v):
34 v = Stack({}, v)
35 v["ret"] = 0
36 return(v["ret"])
37 def cantorri(x, n, v = v):
38 v = Stack({}, v)
39 v.ins({"x" : x, "n" : n})
40 v.ins({"ret" : 1, "q" : None})
41 if not(f["numberp"](v["x"])):
42 return(f["cantorri"](v["x"], v["n"]))
43 if ((v["x"] == 0) or (v["x"] == 1)):
44 return(1)
45 v["x"] = f["mod"](v["x"], 1)
46 for v["i"] in range(1, (v["n"] + 1)):
47 v["x"] = (3 * v["x"])
48 v["q"] = math.floor(v["x"])
50 if (v["q"] == 1):
51 return(block34784(v))
52 v["x"] = (v["x"] + (-v["q"]))
53 return(v["ret"])
54 f["cantorri"] = cantorri
56 #########################
57 ### Cantorrd Function ###
58 #########################
59 def block47665(v):
60 v = Stack({}, v)
61 if ((v["x"] > 0) and (v["x"] <= (1 / 3))):
62 v["ret"] = cantorrd((3 * v["x"]), (v["n"] + (-1)))
63 if (((1 / 3) < v["x"]) and (v["x"] < (2 / 3))):
64 v["ret"] = 0
65 if (((2 / 3) <= v["x"]) and (v["x"] < 1)):
66 v["ret"] = cantorrd(((3 * v["x"]) + (-2)), (v["n"] + (-1)))
67 return(v["ret"])
68 def cantorrd(x, *n, v = v):
69 v = Stack({}, v)
70 v.ins({"x" : x, "n" : list(n)})
71 v.ins({"ret" : 0})
72 if f["emptyp"](v["n"]):
73 v["n"] = v["fpprec"]
74 else:
75 v["n"] = f["first"](v["n"])
76 if not(f["numberp"](v["x"])):
77 return(f["cantorrd"](v["x"], v["n"]))
78 if (v["x"] == 0):
79 return(1)
80 if (v["x"] == 1):
81 return(1)
82 v["x"] = f["mod"](v["x"], 1)
83 return((block47665(v) if (v["n"] > 0) else 1))
84 f["cantorrd"] = cantorrd
86 ########################
87 ## Cantorr_p Function ##
88 ########################
89 def block71117(v):
90 v = Stack({}, v)
91 v["p"] = f["denom"](v["b"])
92 v["q"] = f["num"](v["b"])
93 if ((v["x"] > 0) and (v["x"] < v["b"])):
94 v["ret"] = cantorr_p((v["p"] * v["x"]), v["b"], (v["n"] + (-1)))
95 if ((v["b"] <= v["x"]) and (v["x"] <= (1 + (-v["b"])))):
96 v["ret"] = 1
97 if ((v["x"] > (1 + (-v["b"]))) and (v["x"] < 1)):
98 v["ret"] = (1 + cantorr_p(((v["p"] * v["x"]) + (-(v["p"] + (-v["q"])))), v["b"], (v["n"] + (-1))))
99 return((v["ret"] / 2))
100 def cantorr_p(x, b, n, v = v):
101 v = Stack({}, v)
102 v.ins({"x" : x, "b" : b, "n" : n})
103 v.ins({"ret" : 0, "p" : None, "q" : None, "d" : None})
104 if not(f["numberp"](v["x"])):
105 return(f["cantorr_p"](v["x"], v["b"], v["n"]))
106 if (v["x"] == 0):
107 return(0)
108 if (v["x"] == 1):
109 return(1)
110 if (v["b"] > (1 / 2)):
111 v["b"] = (1 + (-f["mod"](v["b"], 1)))
112 return((block71117(v) if (v["n"] > 0) else v["x"]))
114 #########################
115 ## gcantorseq Function ##
116 #########################
117 def block85290(v):
118 v = Stack({}, v)
119 v["s"] = f["append"](gcantorseq(v["u"], (v["q"] + (-(v["p"] / 2))), (v["p"] * v["r"]), v["r"], (v["n"] + (-1))), gcantorseq((v["q"] + (v["p"] / 2)), v["w"], (v["p"] * v["r"]), v["r"], (v["n"] + (-1))))
120 return(v["s"])
121 def gcantorseq(u, w, p, r, n, v = v):
122 v = Stack({}, v)
123 v.ins({"u" : u, "w" : w, "p" : p, "r" : r, "n" : n})
124 v.ins({"s" : None, "q" : None})
126 if not(f["integerp"](v["n"])):
127 return(None)
128 v["q"] = ((v["u"] + v["w"]) / 2)
129 v["s"] = [v["u"], v["w"]]
130 return((block85290(v) if (v["n"] > 1) else v["s"]))
132 ########################
133 ## cantorseq Function ##
134 ########################
135 def cantorseq(n, v = v):
136 v = Stack({}, v)
137 v.ins({"n" : n})
138 v.ins({"seq" : [0, 1], "l" : [], "r" : []})
139 if not(f["integerp"](v["n"])):
140 return(f["cantorseq"](v["n"]))
141 for v["k"] in range(1, ((v["n"] + (-1)) + 1)):
142 v["r"] = v["seq"]
143 # Map divide using Lambda in the following
144 v["l"] = (v["r"] / 3)
145 v["r"] = f["reverse"]((1 + (-v["l"])))
146 v["seq"] = f["append"](v["l"], v["r"])
147 return(v["seq"])
149 f["plot2d"](lambda x, v = Stack({}, v): f["cantorr2"](x, 10), ['x', 0, 1])
150 f["plot2d"](lambda x, v = Stack({}, v): f["cantorrd"](x, 10), ['x', 0, 1])
151 f["plot2d"](lambda x, v = Stack({}, v): f["cantorri"](x, 10), ['x', 0, 1])