本文整理汇总了Python中sage.all.var函数的典型用法代码示例。如果您正苦于以下问题:Python var函数的具体用法?Python var怎么用?Python var使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了var函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:Aang,项目名称:sympy,代码行数:7,代码来源:test_sage.py
示例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
开发者ID:malb,项目名称:publications,代码行数:26,代码来源:symbolic.py
示例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
开发者ID:uberparagon,项目名称:mgn,代码行数:26,代码来源:stratagraph.py
示例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)
开发者ID:Aang,项目名称:sympy,代码行数:26,代码来源:test_sage.py
示例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
开发者ID:malb,项目名称:publications,代码行数:34,代码来源:symbolic.py
示例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
开发者ID:nilsskoruppa,项目名称:psage,代码行数:10,代码来源:multiplier_systems.py
示例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
开发者ID:haraldschilly,项目名称:lmfdb,代码行数:53,代码来源:web_g2c.py
示例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)))
开发者ID:stakemori,项目名称:degree2,代码行数:26,代码来源:test_eigenforms.py
示例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
开发者ID:REMath,项目名称:implementations,代码行数:7,代码来源:dig_test.py
示例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))])
开发者ID:wangjiezhe,项目名称:ent_note,代码行数:7,代码来源:continued_fraction_of_e.py
示例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 \\)')
开发者ID:edgarcosta,项目名称:lmfdb,代码行数:8,代码来源:test_utils.py
示例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)
开发者ID:edgarcosta,项目名称:lmfdb,代码行数:8,代码来源:test_utils.py
示例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 \\)')
开发者ID:edgarcosta,项目名称:lmfdb,代码行数:8,代码来源:test_utils.py
示例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
开发者ID:StockpotCreative,项目名称:lmfdb,代码行数:9,代码来源:test_characters.py
示例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
开发者ID:jwbober,项目名称:lmfdb,代码行数:10,代码来源:test_characters.py
示例16: plotit
def plotit(k):
k = int(k[0])
# FIXME there could be a filename collission
fn = tempfile.mktemp(suffix=".png")
x = var('x')
p = plot(sin(k * x))
p.save(filename=fn)
data = file(fn).read()
os.remove(fn)
return data
开发者ID:CleryFabien,项目名称:lmfdb,代码行数:10,代码来源:plot_example.py
示例17: eqn_list_to_curve_plot
def eqn_list_to_curve_plot(L):
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')
return 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) for R in
plotzones)
开发者ID:akoutsianas,项目名称:lmfdb,代码行数:42,代码来源:web_g2c.py
示例18: test_web_latex_ideal_fact
def test_web_latex_ideal_fact(self):
r"""
Checking utility: web_latex_ideal_fact
"""
from sage.all import NumberField
x = var('x')
K = NumberField(x**2 - 5, 'a')
a = K.gen()
I = K.ideal(2/(5+a)).factor()
self.assertEqual(web_latex_ideal_fact(I),
'\\( \\left(-a\\right)^{-1} \\)')
开发者ID:edgarcosta,项目名称:lmfdb,代码行数:11,代码来源:test_utils.py
示例19: test_pol_to_html
def test_pol_to_html(self):
r"""
Checking utility: pol_to_html
"""
x = var('x')
f1 = x**2 + 2*x + 1
self.assertEqual(pol_to_html(f1),
'<i>x</i><sup>2</sup> + 2<i>x</i> + 1')
f2 = 'x^3 + 1'
self.assertEqual(pol_to_html(f2),
'<i>x</i><sup>3</sup> + 1')
开发者ID:edgarcosta,项目名称:lmfdb,代码行数:11,代码来源:test_utils.py
示例20: EC_R_plot
def EC_R_plot(ainvs, xmin, xmax, ymin, ymax, colour, legend):
x = var("x")
y = var("y")
c = (xmin + xmax) / 2
d = xmax - xmin
return implicit_plot(
y ** 2 + ainvs[0] * x * y + ainvs[2] * y - x ** 3 - ainvs[1] * x ** 2 - ainvs[3] * x - ainvs[4],
(x, xmin, xmax),
(y, ymin, ymax),
plot_points=1000,
aspect_ratio="automatic",
color=colour,
) + plot(
0,
xmin=c - 1e-5 * d,
xmax=c + 1e-5 * d,
ymin=ymin,
ymax=ymax,
aspect_ratio="automatic",
color=colour,
legend_label=legend,
) # Add an extra plot outside the visible frame because implicit plots are buggy: their legend does not show (http://trac.sagemath.org/ticket/15903)
开发者ID:roed314,项目名称:lmfdb,代码行数:22,代码来源:WebEllipticCurve.py
注:本文中的sage.all.var函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论