ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 19 Jun 2021 11:08:38 +0200How tho pass an indexed variable to a function ?https://ask.sagemath.org/question/57624/how-tho-pass-an-indexed-variable-to-a-function/In his answer to a earlier question `file:///C:/Users/cyril/Downloads/sagemath%20ask/How%20to%20transform%20a%20derived%20set%20of%20inequation%20in%20the%20good%20polyhedron%20format%20-%20ASKSAGE%20Sage%20Q&A%20Forum.html`, SLelievre validated the following code.
def one_dimension_less(representationH):
x = list(var('x_%i' % i) for i in (0..2))
sol = [solve_ineq(ieq, [x[0]]) for ieq in Ineq]
sol_r = flatten([x[1] for x in sol])
ineq_ge = [z for z in sol_r if z.rhs() == x[0]]
ineq_le = [z for z in sol_r if z.lhs() == x[0]]
ineq_a = [z for z in sol_r if z.lhs() != x[0] and z.rhs() != x[0]]
ineq_aa = [(z.lhs()).full_simplify() >= 0 for z in ineq_a]
result = flatten(ineq_aa + [
[(ineq_le[j].rhs()-ineq_ge[i].lhs()).full_simplify() >= 0
for i in range(len(ineq_ge))]
for j in range(len(ineq_le))])
# result1 = [result[i].factor() for i in range(len(result))]
return result
But I realized that I should be able to choose the eliminated variable. So I code as follow :
def elim_x(representationH,elim_var,k):
x = vector(SR, SR.var('x_', 3))
ieqs = [[el.A()*x + el.b() >= 0] for el in DH]
sol = [solve_ineq(ieq, [elim_var]) for ieq in ieqs]
sol_r = flatten([x[1] for x in sol])
ineq_ge = [z for z in sol_r if z.rhs() == elim_var]
ineq_le = [z for z in sol_r if z.lhs() == elim_var]
ineq_a = [z for z in sol_r if z.lhs() != elim_var and z.rhs() != x[0]]
ineq_aa = [(z.lhs()).full_simplify() >= 0 for z in ineq_a]
result = flatten(ineq_aa + [[(ineq_le[j].rhs() - ineq_ge[i].lhs()).full_simplify() >= 0
for i in range(len(ineq_ge))] for j in range(len(ineq_le))])
reslhs=[el.lhs() for el in result]
if k==0 :
return result
if k==1 :
return reslhs
which generate no apparent error, and call this function by :
D = polytopes.dodecahedron()
DH = D.Hrepresentation()
el0=elim_x(DH,[x[0]],1)
el0[0]
but this call generate an error of the type :
`'sage.symbolic.expression.Expression' object is not subscriptable`
I am sorry not to understand by myself why since it is just a way to give a variable already inside the first function.CyrilleSat, 19 Jun 2021 11:08:38 +0200https://ask.sagemath.org/question/57624/elif in listhttps://ask.sagemath.org/question/54087/elif-in-list/Is it possible to use a recursive list. My problem is that I can code a list with an if condition. But I have not found the way to insert inside a list an `elif`.
For instance in pur Python to code `x[t] = a x[t-1] + b, x[0] given` is coded without any difficulties. But what I search is the list way as in Mathematica (<- I know my mother often told me not tell swear words).
In fact I have two problems the first is purely recursive like mathematica code
RecurrenceTable[{a[n + 1] == 3 a[n], a[1] == 7}, a, {n, 1, 10}]
here the `if` condition would be some thing like
A=[a[n + 1] == 3 a[n] for i in range(10) if n > 1 elif : a[n] == 7 if n in range(0)]
but also
A=[something(i) for i in range(..) if condition1 on something(i) elif condition2 on something(i)]CyrilleFri, 30 Oct 2020 09:24:03 +0100https://ask.sagemath.org/question/54087/To call a code from outside a notebookhttps://ask.sagemath.org/question/48173/to-call-a-code-from-outside-a-notebook/Suppose I have written a long piece of code. What is the standard procedure to call it from outside a notebook ?
An if it stays in the notebook, is there a way to hide an active cell ?CyrilleFri, 04 Oct 2019 03:55:52 +0200https://ask.sagemath.org/question/48173/