Author: Roman Plch
Views : 118
Description: Proměnné a jejich vyhodnocování v programu Sage
Compute Environment: Ubuntu 18.04 (Deprecated)
reset() #Resetuje všechny proměnné.

%typeset_mode True


a,b,c=var('a,b,c')

solve(a*x^2+b*x+c,x)

[$\displaystyle x = -\frac{b + \sqrt{b^{2} - 4 \, a c}}{2 \, a}$, $\displaystyle x = -\frac{b - \sqrt{b^{2} - 4 \, a c}}{2 \, a}$]
pol=9*x^3-37*x^2+47*x-19;pol

$\displaystyle 9 \, x^{3} - 37 \, x^{2} + 47 \, x - 19$
pol.roots()

[($\displaystyle \frac{19}{9}$, $\displaystyle 1$), ($\displaystyle 1$, $\displaystyle 2$)]


pol.subs(x=19/9)

$\displaystyle 0$
x;pol

$\displaystyle x$
$\displaystyle 9 \, x^{3} - 37 \, x^{2} + 47 \, x - 19$
x=19/9;x

$\displaystyle \frac{19}{9}$
pol

$\displaystyle 9 \, x^{3} - 37 \, x^{2} + 47 \, x - 19$
pol(x=19/9)

$\displaystyle 0$
x;'x'

$\displaystyle \frac{19}{9}$
x
x=x+1;x

$\displaystyle x + 2$


restore('x');x

$\displaystyle x$
'p+q-i-p+3*q'

p+q-i-p+3*q
reset()

var('a,b,c')

($\displaystyle a$, $\displaystyle b$, $\displaystyle c$)
a=b;b=c;c=3; print a,b,c

b c 3
a

$\displaystyle b$
eval(str(a)); print a

$\displaystyle c$
b

var('a,b,c')

($\displaystyle a$, $\displaystyle b$, $\displaystyle c$)
c=3;b=c;a=b; print a,b,c

3 3 3
reset()

var('a,b,c')

($\displaystyle a$, $\displaystyle b$, $\displaystyle c$)
c=3;b='c';a='b'; print a, b, c

b c 3
P.<x> = PolynomialRing(QQ)

f=x^3+x+1;g=x^2+x+1

f.quo_rem(g)

Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1234, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> NameError: name 'f' is not defined
k, i = var('k, i')

i=2;i

$\displaystyle 2$
sum(i, 'i',1,5)

$\displaystyle 10$
sum('i','i',1,5)

$\displaystyle 15$

#### Jména proměnných

Proměnné, kterým nebyla přiřazena hodnota, musí deklarovat příkazem var. Proměnné, kterým byla přiřazena hodnota, nazýváme objekty a nemusíme je předem deklarovat.
x=var('x')

x.is_real()

$\displaystyle \mathrm{False}$
x=var('x', domain='real')

x.is_real()

$\displaystyle \mathrm{True}$
'Odpoved:'

Odpoved:
type(pi)

<type 'sage.symbolic.expression.Expression'>
pi=3.14

type(pi)

<type 'sage.rings.real_mpfr.RealLiteral'>
restore('pi')

type(pi)

<type 'sage.symbolic.expression.Expression'>
reset()

var('m,n');simplify((-1)^(m+n))

($\displaystyle m$, $\displaystyle n$)
$\displaystyle \left(-1\right)^{m + n}$
assume(m,'odd');assume(n,'odd')

simplify((-1)^(m+n))

$\displaystyle 1$
assumptions()

m is odd n is odd
[]
assume(m>0)

assumptions()

m is odd n is odd
[$\displaystyle m > 0$]
forget()

assumptions()

[]
expr=sqrt(x^2)

simplify(expr)

$\displaystyle \sqrt{x^{2}}$
assume(x>0);simplify(expr)

$\displaystyle x$
forget();assume(x<0);simplify(expr);

$\displaystyle -x$
x.is_real()

$\displaystyle \mathrm{True}$
forget()

x.is_real()

$\displaystyle \mathrm{False}$
 maxima('features')

$\displaystyle \left[ {\it integer} , {\it noninteger} , {\it even} , {\it odd} , {\it rational} , {\it irrational} , {\it real} , {\it imaginary} , {\it complex} , {\it analytic} , {\it increasing} , {\it decreasing} , {\it oddfun} , {\it evenfun} , {\it posfun} , {\it constant} , {\it commutative} , {\it lassociative} , {\it rassociative} , {\it symmetric} , {\it antisymmetric} , {\it integervalued} \right]$
assume(x>0)

x.is_positive()

$\displaystyle \mathrm{True}$
assumptions()

[$\displaystyle x > 0$]
a,b,m,n=var('a,b,m,n')

assume(n+1>0,m+1>0);

integrate(a*x^n+b*x^m, x);

$\displaystyle \frac{b x^{m + 1}}{m + 1} + \frac{a x^{n + 1}}{n + 1}$
forget()

type(5.0)

<type 'sage.rings.real_mpfr.RealLiteral'>
type(1)

<type 'sage.rings.integer.Integer'>
type(1/2)

<type 'sage.rings.rational.Rational'>
(5.0).is_real()

$\displaystyle \mathrm{True}$
1.is_integer()

$\displaystyle \mathrm{True}$
from sage.rings.rational import is_Rational

is_Rational(1/2); 1/2 in QQ

$\displaystyle \mathrm{True}$
$\displaystyle \mathrm{True}$
(1+2*I) in CC

$\displaystyle \mathrm{True}$
0.75.exact_rational()

$\displaystyle \frac{3}{4}$