ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 Apr 2013 06:37:59 -0500How should I write this algorithm?http://ask.sagemath.org/question/10022/how-should-i-write-this-algorithm/hello
I want to write this algorithm in sage, but I don't know how to write it as an algorithm in sage, could you please help me
Algorithm : update basis-update of intermediate basis G with reduct h
Given: a finite set G_old ? B[X] and the reduct 0!=h ? B[X]
Find: updates G_new ? B[X] of G_old
begin
1: G_new <-- Ø
2: while G_old !=Ø do
3: selecting from G_old ; G_old <-- G_old \{g}
4: if HT(h) not divisible HT(g) then
5: G_new <-- G_new U {g}
6: end
7:end
8: G_new <-- G_new U {h}
9: return G_new
end
thank you so muchSun, 14 Apr 2013 01:16:08 -0500http://ask.sagemath.org/question/10022/how-should-i-write-this-algorithm/Answer by slelievre for <p>hello
I want to write this algorithm in sage, but I don't know how to write it as an algorithm in sage, could you please help me</p>
<p>Algorithm : update basis-update of intermediate basis G with reduct h
Given: a finite set G_old ? B[X] and the reduct 0!=h ? B[X]</p>
<p>Find: updates G_new ? B[X] of G_old</p>
<p>begin</p>
<p>1: G_new <-- Ø</p>
<p>2: while G_old !=Ø do</p>
<p>3: selecting from G_old ; G_old <-- G_old {g}</p>
<p>4: if HT(h) not divisible HT(g) then</p>
<p>5: G_new <-- G_new U {g}</p>
<p>6: end</p>
<p>7:end</p>
<p>8: G_new <-- G_new U {h}</p>
<p>9: return G_new</p>
<p>end</p>
<p>thank you so much</p>
http://ask.sagemath.org/question/10022/how-should-i-write-this-algorithm/?answer=14784#post-id-14784Some of the code you wrote didn't make it. You should indent code so that it is displayed properly.
I don't exactly understand your algorithm, but from what I can grasp it might be something like this.
def update_basis(G,h):
G_old = G.copy()
G_new = []
while G_old:
g = G_old.pop()
if ht(h) % ht(g):
G_new.append(g)
G_new.append(h)
return G_new
Mon, 15 Apr 2013 00:35:34 -0500http://ask.sagemath.org/question/10022/how-should-i-write-this-algorithm/?answer=14784#post-id-14784Comment by Neda for <p>Some of the code you wrote didn't make it. You should indent code so that it is displayed properly.</p>
<p>I don't exactly understand your algorithm, but from what I can grasp it might be something like this.</p>
<pre><code>def update_basis(G,h):
G_old = G.copy()
G_new = []
while G_old:
g = G_old.pop()
if ht(h) % ht(g):
G_new.append(g)
G_new.append(h)
return G_new
</code></pre>
http://ask.sagemath.org/question/10022/how-should-i-write-this-algorithm/?comment=17895#post-id-17895thank you so so much, I think I should learn python programming ..Mon, 15 Apr 2013 06:37:59 -0500http://ask.sagemath.org/question/10022/how-should-i-write-this-algorithm/?comment=17895#post-id-17895