本文整理汇总了Python中sage.all.var函数的典型用法代码示例。如果您正苦于以下问题:Python var函数的具体用法?Python var怎么用?Python var使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了var函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_issue924
def test_issue924():
sage.var("a x")
log = sage.log
i = sympy.integrate(log(x)/a, (x, a, a+1))
i2 = sympy.simplify(i)
s = sage.SR(i2)
assert s == (a*log(1+a) - a*log(a) + log(1+a) - 1)/a
示例2: symbolic_sis
def symbolic_sis(n, alpha, q, m=None, epsilon=None):
if epsilon is None:
epsilon = var("epsilon")
assume(epsilon>0)
assume(epsilon<ZZ(1)/2)
delta_0 = var("delta_0")
assume(delta_0>=1.0)
e = alpha*q/sqrt(2*pi)
if m is None:
m = sqrt(n*log(q)/log(delta_0))
v = e * delta_0**m * q**(n/m) # norm of the vector
# epsilon = exp(-pi*(|v|^2/q^2))
f = log(1/epsilon)/pi == (v/q)**2
# solve
f = 2* q**2 * m * f * pi
f = f.simplify_full()
f = f.solve(delta_0**(2*m))[0]
f = f.log().canonicalize_radical()
f = f.solve(log(delta_0))[0]
f = f.simplify_log()
return f
示例3: nice_matrix
def nice_matrix(self):
Mnice = Matrix(SR, self.M.nrows(), self.M.ncols())
for edge in range(1, self.num_edges()+1):
Mnice[0,edge] = self.M[0,edge]
for v in range(1, self.num_vertices()+1):
kappas = 1
for expon, coef in self.M[v,0].dict().items():
if expon[0]==0:
Mnice[v,0] += coef
else:
kappas *= var("ka{0}".format(expon[0]))**coef
if kappas != 1:
Mnice[v,0] += kappas
for edge in range(1, self.num_edges()+1):
psis = 1
for expon, coef in self.M[v,edge].dict().items():
if expon[0]==0:
Mnice[v,edge] += coef
elif expon[0]==1:
psis *= var(StrataGraph.ps_name)**coef
elif expon[0]==2:
psis *= var(StrataGraph.ps2_name)**coef
if psis != 1:
Mnice[v,edge] += psis
return Mnice
示例4: check_expression
def check_expression(expr, var_symbols):
"""Does eval(expr) both in Sage and SymPy and does other checks."""
# evaluate the expression in the context of Sage:
sage.var(var_symbols)
a = globals().copy()
# safety checks...
assert not "sin" in a
a.update(sage.__dict__)
assert "sin" in a
e_sage = eval(expr, a)
assert not isinstance(e_sage, sympy.Basic)
# evaluate the expression in the context of SymPy:
sympy.var(var_symbols)
b = globals().copy()
assert not "sin" in b
b.update(sympy.__dict__)
assert "sin" in b
b.update(sympy.__dict__)
e_sympy = eval(expr, b)
assert isinstance(e_sympy, sympy.Basic)
# Do the actual checks:
assert sympy.S(e_sage) == e_sympy
assert e_sage == sage.SR(e_sympy)
示例5: symbolic_modulus_switching
def symbolic_modulus_switching(n, alpha, q, h, m=None, epsilon=None):
if epsilon is None:
epsilon = var("epsilon")
assume(epsilon>0)
assume(epsilon<ZZ(1)/2)
delta_0 = var("delta_0")
assume(delta_0>=1.0)
if m is None:
m = sqrt(n*log(q)/log(delta_0))
e = alpha*q/sqrt(2*pi)
c = e * sqrt(m-n)/sqrt(h)
v = delta_0**m * (q/c)**(n/m) # norm of the vector
v_ = v**2/m # variance of each component
v_r = (m-n) * e**2 *v_ # noise contribution
v_l = h * v_ * c**2 # nose contribution of rounding noise
# epsilon = exp(-pi*(|v|^2/q^2))
f = log(1/epsilon)/pi == (v_l + v_r)/q**2
# solve
f = 2* q**2 * m * f * pi
f = f.simplify_full()
f = f.solve(delta_0**(2*m))[0]
f = f.log().canonicalize_radical()
f = f.solve(log(delta_0))[0]
f = f.simplify_log()
return f
示例6: q_expansion
def q_expansion(self,n=20):
r"""
Give the q-expansion of the quotient.
"""
var('q')
et = qexp_eta(ZZ[['q']],n)
etA= et.subs(q=q**self._arg_num).power_series(ZZ[['q']])
etB= et.subs(q=q**self._arg_den).power_series(ZZ[['q']])
res = etA**(self._exp_num)/etB**(self._exp_den)
return res
示例7: eqn_list_to_curve_plot
def eqn_list_to_curve_plot(L,rat_pts):
xpoly_rng = PolynomialRing(QQ,'x')
poly_tup = [xpoly_rng(tup) for tup in L]
f = poly_tup[0]
h = poly_tup[1]
g = f+h**2/4
if len(g.real_roots())==0 and g(0)<0:
return text("$X(\mathbb{R})=\emptyset$",(1,1),fontsize=50)
X0 = [real(z[0]) for z in g.base_extend(CC).roots()]+[real(z[0]) for z in g.derivative().base_extend(CC).roots()]
a,b = inflate_interval(min(X0),max(X0),1.5)
groots = [a]+g.real_roots()+[b]
if b-a<1e-7:
a=-3
b=3
groots=[a,b]
ngints = len(groots)-1
plotzones = []
npts = 100
for j in range(ngints):
c = groots[j]
d = groots[j+1]
if g((c+d)/2)<0:
continue
(c,d) = inflate_interval(c,d,1.1)
s = (d-c)/npts
u = c
yvals = []
for i in range(npts+1):
v = g(u)
if v>0:
v = sqrt(v)
w = -h(u)/2
yvals.append(w+v)
yvals.append(w-v)
u += s
(m,M) = inflate_interval(min(yvals),max(yvals),1.2)
plotzones.append((c,d,m,M))
x = var('x')
y = var('y')
plot=sum(implicit_plot(y**2 + y*h(x) - f(x), (x,R[0],R[1]),(y,R[2],R[3]), aspect_ratio='automatic', plot_points=500, zorder=1) for R in plotzones)
xmin=min([R[0] for R in plotzones])
xmax=max([R[1] for R in plotzones])
ymin=min([R[2] for R in plotzones])
ymax=max([R[3] for R in plotzones])
for P in rat_pts:
(x,y,z)=eval(P.replace(':',','))
z=ZZ(z)
if z: # Do not attempt to plot points at infinity
x=ZZ(x)/z
y=ZZ(y)/z**3
if x >= xmin and x <= xmax and y >= ymin and y <= ymax:
plot += point((x,y),color='red',size=40,zorder=2)
return plot
示例8: test_wt_20_eigen
def test_wt_20_eigen(self):
N20 = KlingenEisensteinAndCuspForms(20)
pl = N20.hecke_charpoly(2)
x = pl.parent().gens()[0]
pl1 = ((x + Integer(840960)) *
(x ** Integer(2) - Integer(1378464) * x + Integer(328189501440)))
self.assertTrue(pl == (x - Integer(119538120)) * pl1)
x = var("x")
f20_1 = N20.eigenform_with_eigenvalue_t2(alpha20_1)
f20_2 = N20.eigenform_with_eigenvalue_t2(alpha20_2)
f20_3 = N20.eigenform_with_eigenvalue_t2(alpha20_3)
l = [f20_1, f20_2, f20_3]
l = [f.normalize(f[(1, 1, 1)]) for f in l]
cons20[-1] = coerce_pol(cons20[-1], alpha20_3.parent())
self.assertTrue(cons20 == [f._construction for f in l])
self.assertTrue(all(polynomial_to_form(c, 4) == f
for c, f in zip(cons20, l)))
dcts = [f20_1_dct, f20_2_dct, f20_3_dct]
self.assertTrue(all(coerce_dict(d, f.base_ring) == f.fc_dct for d, f in zip(dcts, l)))
示例9: cohendiv
def cohendiv():
dig = DIG('../invgen/Traces/NLA/cohendiv.tcs')
rs = dig.getInvs(inv_typ='eqt', seed=0, vs=dig.vs, deg=2)
q,y,rvu,x,a,b = var('q,y,rvu,x,a,b')
expected_rs = [-q*y - rvu + x == 0, -a*y + b == 0, -q*y - 2*b + x >= 0, -2*a*y + rvu >= 0]
assert set(expected_rs) == set([r.inv for r in rs]), rs
示例10: main2
def main2():
t, n = var('t, n')
G = symbolic_expression(t**n * (t - Integer(1))**n /
factorial(n) * e**t).function(t)
T = symbolic_expression(G.integral(t, Integer(0), Integer(1))).function(n)
print([T(j) for j in range(Integer(10))])
print([T(j).n() for j in range(Integer(10))])
示例11: test_web_latex_split_on
def test_web_latex_split_on(self):
r"""
Checking utility: web_latex_split_on
"""
x = var('x')
self.assertEqual(web_latex_split_on("test string"), "test string")
self.assertEqual(web_latex_split_on(x**2 + 1),
'\\( x^{2} \\) + \\( 1 \\)')
示例12: test_web_latex_split_on_re
def test_web_latex_split_on_re(self):
r"""
Checking utility: web_latex_split_on_re
"""
x = var('x')
f = x**2 + 1
expected = '\\(x^{2} \\) \\(\\mathstrut+ 1 \\)'
self.assertEqual(web_latex_split_on_re(f), expected)
示例13: test_web_latex
def test_web_latex(self):
r"""
Checking utility: web_latex
"""
x = var('x')
self.assertEqual(web_latex("test string"), "test string")
self.assertEqual(web_latex(x**23 + 2*x + 1),
'\\( x^{23} + 2 \\, x + 1 \\)')
示例14: test_Heckemethods
def test_Heckemethods(self):
from sage.all import NumberField, var
x = var('x')
k = NumberField(x**3-x**2+x+1,'a')
modlabel, numlabel = '82.-5a0+1a2', '5.3.3'
mod = WebHecke.label2ideal(k, modlabel)
assert WebHecke.ideal2label(mod) == modlabel
num = WebHecke.label2number(numlabel)
assert WebHecke.number2label(num) == numlabel
示例15: test_Heckemethods
def test_Heckemethods(self):
from sage.all import NumberField, var
x = var("x")
k = NumberField(x ** 3 - x ** 2 + x + 1, "a")
modlabel, numlabel = "82.-5a0+1a2", "5.3.3"
mod = WebHecke.label2ideal(k, modlabel)
assert WebHecke.ideal2label(mod) == modlabel
num = WebHecke.label2number(numlabel)
assert WebHecke.number2label(num) == numlabel