In [77]:
import sollya
In [78]:
dir(sollya)
Out[78]:
['Interval',
 'RD',
 'RN',
 'RU',
 'RZ',
 'S2',
 'SollyaObject',
 'SollyaOperator',
 'SollyaStructureWrapper',
 '__Settings',
 '__builtin__',
 '__builtins__',
 '__displayhook',
 '__doc__',
 '__file__',
 '__name__',
 '__package__',
 '__test__',
 '_x_',
 'abs',
 'absolute',
 'acos',
 'acosh',
 'annotatefunction',
 'append',
 'approx',
 'asciiplot',
 'asin',
 'asinh',
 'atan',
 'atanh',
 'atexit',
 'autodiff',
 'autoprint',
 'bashevaluate',
 'bashexecute',
 'binary',
 'binary128',
 'binary16',
 'binary32',
 'binary64',
 'binary80',
 'canonical',
 'ceil',
 'chebyshevform',
 'checkinfnorm',
 'coeff',
 'collections',
 'composepolynomials',
 'cos',
 'cosh',
 'decimal',
 'default',
 'degree',
 'denominator',
 'diff',
 'dirtyfindzeros',
 'dirtyinfnorm',
 'dirtyintegral',
 'dirtysimplify',
 'double',
 'double_double',
 'doubledouble',
 'doubleextended',
 'dyadic',
 'erf',
 'erfc',
 'error',
 'evaluate',
 'execute',
 'exp',
 'expand',
 'expm1',
 'exponent',
 'externalplot',
 'file',
 'findzeros',
 'fixed',
 'floating',
 'floor',
 'fpminimax',
 'function',
 'getbacktrace',
 'getsuppressedmessages',
 'guessdegree',
 'halfprecision',
 'head',
 'hexadecimal',
 'horner',
 'implementconstant',
 'implementpoly',
 'inf',
 'infnorm',
 'inspect',
 'integral',
 'itertools',
 'length',
 'libraryconstant',
 'log',
 'log10',
 'log1p',
 'log2',
 'mantissa',
 'max',
 'mid',
 'min',
 'nearestint',
 'numberroots',
 'numerator',
 'off',
 'on',
 'parse',
 'perturb',
 'pi',
 'plot',
 'postscript',
 'postscriptfile',
 'powers',
 'precision',
 'prepend',
 'printdouble',
 'printexpansion',
 'printsingle',
 'printxml',
 'quad',
 'rationalapprox',
 'readxml',
 'relative',
 'remez',
 'revert',
 'round',
 'roundcoefficients',
 'roundcorrectly',
 'searchgal',
 'settings',
 'simplify',
 'simplifysafe',
 'sin',
 'single',
 'sinh',
 'sort',
 'sqrt',
 'subpoly',
 'substitute',
 'sup',
 'supnorm',
 'suppressmessage',
 'sys',
 'tail',
 'tan',
 'tanh',
 'taylor',
 'taylorform',
 'traceback',
 'triple_double',
 'tripledouble',
 'types',
 'unsuppressmessage',
 'warnings',
 'x',
 'zerodenominators']
In [79]:
sollya.SollyaObject(42) + 17
Out[79]:
59
In [80]:
type(_)
Out[80]:
sollya.SollyaObject
In [81]:
int(sollya.SollyaObject(42) + 17)
Out[81]:
59
In [82]:
sollya.sin(1)#.approx()
# terminal: sys.displayhook = sollya.autoprint
Out[82]:
sin(1)
In [83]:
from sollya import *
In [84]:
sin(Interval(1, 2))
Out[84]:
[0.84147098480789650665250232163029899962256306079835;1]
In [85]:
f = sin(1 + exp(x))
evaluate(f, 4)
Out[85]:
-0.81371655140175448871553013334315708186522755964095
In [86]:
f
Out[86]:
sin(1 + exp(_x_))
In [87]:
fp = diff(f)
fp(0)
Out[87]:
cos(2)
In [88]:
g = sin(cos(x/3) - 1)
g(SollyaObject(2)**(-3000)).approx()
Out[88]:
-3.6707390421142527733796653495536131777290030585503e-1808
In [89]:
Interval(2, 3) + Interval(4, 5)
Out[89]:
[6;8]
In [90]:
sin(Interval(-3, 0.5))
Out[90]:
[-1;0.4794255386042030002732879352155713880818033679406]
In [91]:
f = x - sin(x)
f(Interval(-2**(-5), 2**(-5)))
Out[91]:
[-5.0860146739212604188787425355353739218812010691378e-6;5.0860146739212604188787425355353739218812010691378e-6]
In [92]:
sollya.settings.prec
Out[92]:
165
In [93]:
f = sin(cos(x/3) - 1)
f(1).approx()
Out[93]:
-5.501526355908266391152772814019516251695908603806e-2
In [94]:
sollya.settings.prec = 1000
f(1).approx()
Out[94]:
-5.501526355908266391152772814019516251695908603805905088725075252049985504528317579852395927511980192277611652640495829333507662997685389596204298153802812709307542580858728755496284042230877769757369477459165543247482676358999029132617139095509066958794105199781707261616997622409598671121861981853163e-2
In [95]:
sollya.settings.prec = default
In [96]:
a = log2(17)/log2(13)
b = log(17)/log(13)
(a - b).approx() # on aurait le warning en console
Out[96]:
0
In [97]:
sollya.settings.display
Out[97]:
decimal
In [98]:
sollya.settings.display = binary
SollyaObject(17.25)
Out[98]:
1.000101_2 * 2^(4)
In [99]:
del sollya.settings.display
In [100]:
printdouble(17.25) # en console
In [101]:
parse("0x3ff00000cafebabe")
Out[101]:
1.00000075621544182169486703060101717710494995117187
In [102]:
s = SollyaObject("Hello world")
t = SollyaObject("Salut les copains")
s
Out[102]:
Hello world
In [103]:
str(s) + " --- " + str(t)
Out[103]:
'Hello world --- Salut les copains'
In [104]:
str(s)[4]
Out[104]:
'o'
In [105]:
SollyaObject(True)
Out[105]:
true
In [106]:
if SollyaObject(True): print "a"
if SollyaObject(False): print "b"
a

In [107]:
exp(17) < 2**42
Out[107]:
True
In [108]:
1 + x + x**2 == 1 + x + x**2
Out[108]:
True
In [109]:
SollyaObject("Salut") == "Salut", SollyaObject("Salut") == "Privet"
Out[109]:
(True, False)
In [110]:
l = SollyaObject([1, 2, 3, "Coucou", exp(x)])
l
Out[110]:
[|1, 2, 3, "Coucou", exp(_x_)|]
In [111]:
[sin(x) + 1] + l
Out[111]:
[sin(_x_) + 1, 1, 2, 3, Coucou, exp(_x_)]
In [112]:
tail(l)
Out[112]:
[|2, 3, "Coucou", exp(_x_)|]
In [113]:
l[3]
Out[113]:
Coucou
In [114]:
#l[3] = "Fromage"
In [115]:
SollyaObject(range(1, 18))
Out[115]:
[|1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17|]
In [116]:
l = SollyaObject(["Salut", exp(x), 17, True, nearestint(exp(5)), Ellipsis])
l[1520]
Out[116]:
1664
In [117]:
a = SollyaObject({
    "f": exp(x),
    "I": Interval(-1, 1)
})
a
Out[117]:
{ .f = exp(_x_), .I = [-1;1] }
In [118]:
a.struct.f
Out[118]:
exp(_x_)
In [119]:
a.struct.I = Interval(-2, 2)
a.struct.accuracy = 2**-45
a
Out[119]:
{ .accuracy = 2.8421709430404007434844970703125e-14, .f = exp(_x_), .I = [-2;2] }
In [120]:
dict(a)
Out[120]:
{'I': [-2;2], 'accuracy': 2.8421709430404007434844970703125e-14, 'f': exp(_x_)}
In [121]:
succ = parse("proc(i) { return i+1; };")
succ(1)
Out[121]:
2
In [122]:
succ
Out[122]:
proc(i)
{
nop;
return (i) + (1);
}
In [123]:
eval_at_one = parse("""
   proc(fun) {
       return fun(1);
   };
""")

def myfun(x):
    return 2*x

eval_at_one(myfun)
Out[123]:
2
In [124]:
obj = exp(x)
In [125]:
obj.is_list()
Out[125]:
False
In [126]:
obj.is_function()
Out[126]:
True
In [127]:
obj.operator()
Out[127]:
EXP
In [128]:
obj.arity()
Out[128]:
1
In [129]:
obj.operands()
Out[129]:
[_x_]
In [130]:
def mymatcher(expr):
    op = expr.operator()
    if op == SollyaOperator('EXP'):
        return 1
    elif op == SollyaOperator('SIN'):
        return 2
    else:
        return 3

mymatcher(exp(x)), mymatcher(sin(x))
Out[130]:
(1, 2)
In [131]:
def transform(expr):
    op = expr.operator()
    return op(*[sin(a) for a in expr.operands()])

transform(x + exp(x))
Out[131]:
sin(_x_) + sin(exp(_x_))
In [132]:
f = sin(cos(x/3) - 1)
I = Interval(-1/4, 1/4)
plot(f, I)
In [133]:
p = remez(f, 5, I)
delta = p - f
plot(p - f, I)
In [134]:
def mypi(prec): return 3
foo = libraryconstant(mypi)
foo
Out[134]:
mypi_0
In [135]:
foo.approx()
Out[135]:
3
In [135]: