How to use the symengine.symbols function in symengine

To help you get started, we’ve selected a few symengine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neurophysik / jitcdde / tests / test_jitcdde.py View on Github external
class TestGeneratorChunking(TestGenerator):
	def generator(self):
		self.DDE.compile_C(chunk_size=1, extra_compile_args=compile_args)


f_dict = { y(i):entry for i,entry in enumerate(f) }

class TestDictionary(TestIntegration):
	@classmethod
	def setUpClass(self):
		self.DDE = jitcdde(f_dict)
		self.DDE.set_integration_parameters(**test_parameters)


delayed_y, y3m10, coupling_term = symengine.symbols("delayed_y y3m10 coupling_term")
f_alt_helpers = [
		(delayed_y, y(0,t-delay)),
		(coupling_term, 0.25 * (delayed_y - y(3))),
		(y3m10, y(3)-10)
	]

f_alt = [
		omega[0] * (-y(1) - y(2)),
		omega[0] * (y(0) + 0.165 * y(1)),
		omega[0] * (0.2 + y(2) * (y(0) - 10.0)),
		omega[1] * (-y(4) - y(5)) + coupling_term,
		omega[1] * (y3m10 + 10 + 0.165 * y(4)),
		omega[1] * (0.2 + y(5) * y3m10)
	]

class TestHelpers(TestIntegration):
github neurophysik / jitcdde / tests / test_jitcdde.py View on Github external
def test_check_undefined_variable(self):
		x = symengine.symbols("x")
		DDE = jitcdde([x])
		with self.assertRaises(ValueError):
			DDE.check()
github neurophysik / jitcode / tests / scenarios.py View on Github external
# as dictionary
f_dict = { y(i):entry for i,entry in reversed(list(enumerate(f))) }
with_dictionary = {"f_sym": f_dict}

# with generator

def f_generator():
	for entry in f:
		yield entry

with_generator = { "f_sym":f_generator, "n":n }

# with helpers

f1, f2, f3, f4 = symbols("f1, f2, f3, f4")
coupling, first_y, first_y_sq = symbols("coupling, first_y, first_y_sq")
a_alt, b1_alt, b2_alt, c_alt, k_alt = symbols("a_alt, b1_alt, b2_alt, c_alt, k_alt")
f_alt = [ f1, f2, f3, f4 ]

f_alt_helpers = [
	( a_alt , a  ),
	( b1_alt, b1 ),
	( b2_alt, b2 ),
	( c_alt,  c  ),
	( k_alt,  k  ),
	( first_y, y(0) ),
	( first_y_sq, first_y**2 ),
	( coupling, k_alt*(y(2)-first_y) ),
	( f1, a_alt*first_y_sq - a_alt*first_y + coupling - first_y**3 + first_y_sq - y(1) ),
	( f2, b1_alt*first_y - c_alt*y(1)),
	( f3, y(2) * ( a_alt-y(2) ) * ( y(2)-1.0 ) - y(3) - coupling ),
github neurophysik / jitcode / tests / scenarios.py View on Github external
( k_alt,  k  ),
	( first_y, y(0) ),
	( first_y_sq, first_y**2 ),
	( coupling, k_alt*(y(2)-first_y) ),
	( f1, a_alt*first_y_sq - a_alt*first_y + coupling - first_y**3 + first_y_sq - y(1) ),
	( f2, b1_alt*first_y - c_alt*y(1)),
	( f3, y(2) * ( a_alt-y(2) ) * ( y(2)-1.0 ) - y(3) - coupling ),
	( f4, b2_alt*y(2) - c_alt*y(3) ),
]
shuffle(f_alt_helpers)

with_helpers = {"f_sym": f_alt, "helpers": f_alt_helpers}

# with parameters

a_par, c_par, k_par = symbols("a_par c_par k_par")
f_params_helpers = [ ( coupling, k_par*(y(2)-y(0)) ) ]
f_params = [
	y(0) * ( a_par-y(0) ) * ( y(0)-1.0 ) - y(1) + coupling,
	b1*y(0) - c_par*y(1),
	y(2) * ( a_par-y(2) ) * ( y(2)-1.0 ) - y(3) - coupling,
	b2*y(2) - c_par*y(3)
	]
params_args = (a,c,k)
n_params = 3

with_params = {
		"f_sym": f_params,
		"helpers": f_params_helpers,
		"control_pars": [a_par, c_par, k_par]
	}
github neurophysik / jitcdde / tests / test_jitcdde.py View on Github external
f_callback = [
		omega[0] * (-y(1) - y(2)),
		omega[0] * (y(0) + 0.165 * y(1)),
		omega[0] * (0.2 + y(2) * call_minus_ten(y(0))),
		call_fourth_component(y(0,t-delay)),
		omega[1] * (y(3) + 0.165 * y(4)),
		omega[1] * (0.2 + y(5) * call_minus_ten(y(3))),
	]

class TestCallback(TestIntegration):
	@classmethod
	def setUpClass(self):
		self.DDE = jitcdde(f_callback,callback_functions=callbacks)
		self.DDE.set_integration_parameters(**test_parameters)

a,b,c,k,tau = symengine.symbols("a b c k tau")
parameters = [0.165, 0.2, 10.0, 0.25, 4.5]
f_params = [
		omega[0] * (-y(1) - y(2)),
		omega[0] * (y(0) + a * y(1)),
		omega[0] * (b + y(2) * (y(0) - c)),
		omega[1] * (-y(4) - y(5)) + k * (y(0,t-tau) - y(3)),
		omega[1] * (y(3) + a * y(4)),
		omega[1] * (b + y(5) * (y(3) - c))
	]

class TestParameters(TestIntegration):
	@classmethod
	def setUpClass(self):
		self.DDE = jitcdde(f_params, control_pars=[a,b,c,k,tau],max_delay=parameters[-1])
		self.DDE.set_integration_parameters(**test_parameters)
github neurophysik / jitcode / tests / scenarios.py View on Github external
f_dict = { y(i):entry for i,entry in reversed(list(enumerate(f))) }
with_dictionary = {"f_sym": f_dict}

# with generator

def f_generator():
	for entry in f:
		yield entry

with_generator = { "f_sym":f_generator, "n":n }

# with helpers

f1, f2, f3, f4 = symbols("f1, f2, f3, f4")
coupling, first_y, first_y_sq = symbols("coupling, first_y, first_y_sq")
a_alt, b1_alt, b2_alt, c_alt, k_alt = symbols("a_alt, b1_alt, b2_alt, c_alt, k_alt")
f_alt = [ f1, f2, f3, f4 ]

f_alt_helpers = [
	( a_alt , a  ),
	( b1_alt, b1 ),
	( b2_alt, b2 ),
	( c_alt,  c  ),
	( k_alt,  k  ),
	( first_y, y(0) ),
	( first_y_sq, first_y**2 ),
	( coupling, k_alt*(y(2)-first_y) ),
	( f1, a_alt*first_y_sq - a_alt*first_y + coupling - first_y**3 + first_y_sq - y(1) ),
	( f2, b1_alt*first_y - c_alt*y(1)),
	( f3, y(2) * ( a_alt-y(2) ) * ( y(2)-1.0 ) - y(3) - coupling ),
	( f4, b2_alt*y(2) - c_alt*y(3) ),
]
github neurophysik / jitcode / tests / scenarios.py View on Github external
# as dictionary
f_dict = { y(i):entry for i,entry in reversed(list(enumerate(f))) }
with_dictionary = {"f_sym": f_dict}

# with generator

def f_generator():
	for entry in f:
		yield entry

with_generator = { "f_sym":f_generator, "n":n }

# with helpers

f1, f2, f3, f4 = symbols("f1, f2, f3, f4")
coupling, first_y, first_y_sq = symbols("coupling, first_y, first_y_sq")
a_alt, b1_alt, b2_alt, c_alt, k_alt = symbols("a_alt, b1_alt, b2_alt, c_alt, k_alt")
f_alt = [ f1, f2, f3, f4 ]

f_alt_helpers = [
	( a_alt , a  ),
	( b1_alt, b1 ),
	( b2_alt, b2 ),
	( c_alt,  c  ),
	( k_alt,  k  ),
	( first_y, y(0) ),
	( first_y_sq, first_y**2 ),
	( coupling, k_alt*(y(2)-first_y) ),
	( f1, a_alt*first_y_sq - a_alt*first_y + coupling - first_y**3 + first_y_sq - y(1) ),
	( f2, b1_alt*first_y - c_alt*y(1)),
	( f3, y(2) * ( a_alt-y(2) ) * ( y(2)-1.0 ) - y(3) - coupling ),
	( f4, b2_alt*y(2) - c_alt*y(3) ),
github symengine / symengine.py / benchmarks / expand6b.py View on Github external
def run_benchmark(n):
    a0 = symbols("a0")
    a1 = symbols("a1")
    e = a0 + a1
    f = 0;
    for i in range(2, n):
        s = symbols("a%s" % i)
        e = e + sin(s)
        f = f + sin(s)
    f = -f
    t1 = clock()
    e = expand(e**2)
    e = e.xreplace({a0: f})
    e = expand(e)
    t2 = clock()
    print("%s ms" % (1000 * (t2 - t1)))
github symengine / symengine.py / benchmarks / expand6b.py View on Github external
def run_benchmark(n):
    a0 = symbols("a0")
    a1 = symbols("a1")
    e = a0 + a1
    f = 0;
    for i in range(2, n):
        s = symbols("a%s" % i)
        e = e + sin(s)
        f = f + sin(s)
    f = -f
    t1 = clock()
    e = expand(e**2)
    e = e.xreplace({a0: f})
    e = expand(e)
    t2 = clock()
    print("%s ms" % (1000 * (t2 - t1)))