applied-ai-018 commited on
Commit
3d3ace9
·
verified ·
1 Parent(s): e5ed7cf

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/__init__.cpython-310.pyc +0 -0
  2. llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/ast_parser.cpython-310.pyc +0 -0
  3. llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/mathematica.cpython-310.pyc +0 -0
  4. llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/maxima.cpython-310.pyc +0 -0
  5. llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/sym_expr.cpython-310.pyc +0 -0
  6. llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/sympy_parser.cpython-310.pyc +0 -0
  7. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_build_autolev_antlr.cpython-310.pyc +0 -0
  8. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/README.txt +9 -0
  9. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest11.cpython-310.pyc +0 -0
  10. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest12.cpython-310.pyc +0 -0
  11. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest2.cpython-310.pyc +0 -0
  12. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest3.cpython-310.pyc +0 -0
  13. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest5.cpython-310.pyc +0 -0
  14. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/chaos_pendulum.cpython-310.pyc +0 -0
  15. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/double_pendulum.cpython-310.pyc +0 -0
  16. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/mass_spring_damper.cpython-310.pyc +0 -0
  17. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/non_min_pendulum.cpython-310.pyc +0 -0
  18. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/chaos_pendulum.al +33 -0
  19. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/chaos_pendulum.py +55 -0
  20. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/double_pendulum.al +25 -0
  21. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/double_pendulum.py +39 -0
  22. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/mass_spring_damper.al +19 -0
  23. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/mass_spring_damper.py +31 -0
  24. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/non_min_pendulum.al +20 -0
  25. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/non_min_pendulum.py +36 -0
  26. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest1.al +8 -0
  27. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest10.py +64 -0
  28. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest11.py +14 -0
  29. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest12.al +7 -0
  30. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest12.py +14 -0
  31. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest2.py +22 -0
  32. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest3.al +25 -0
  33. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest3.py +37 -0
  34. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest4.al +20 -0
  35. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest4.py +20 -0
  36. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest5.al +32 -0
  37. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest5.py +33 -0
  38. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest6.al +41 -0
  39. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest6.py +36 -0
  40. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest7.al +39 -0
  41. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest7.py +35 -0
  42. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest8.py +49 -0
  43. llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest9.al +54 -0
  44. llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/__init__.py +1 -0
  45. llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/__init__.cpython-310.pyc +0 -0
  46. llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/c_parser.cpython-310.pyc +0 -0
  47. llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/c_parser.py +1090 -0
  48. llmeval-env/lib/python3.10/site-packages/sympy/parsing/fortran/__init__.py +1 -0
  49. llmeval-env/lib/python3.10/site-packages/sympy/parsing/fortran/__pycache__/__init__.cpython-310.pyc +0 -0
  50. llmeval-env/lib/python3.10/site-packages/sympy/parsing/fortran/__pycache__/fortran_parser.cpython-310.pyc +0 -0
llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (327 Bytes). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/ast_parser.cpython-310.pyc ADDED
Binary file (3.14 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/mathematica.cpython-310.pyc ADDED
Binary file (29 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/maxima.cpython-310.pyc ADDED
Binary file (2.48 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/sym_expr.cpython-310.pyc ADDED
Binary file (8.67 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/__pycache__/sympy_parser.cpython-310.pyc ADDED
Binary file (30.6 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/__pycache__/_build_autolev_antlr.cpython-310.pyc ADDED
Binary file (2.5 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/README.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # parsing/tests/test_autolev.py uses the .al files in this directory as inputs and checks
2
+ # the equivalence of the parser generated codes and the respective .py files.
3
+
4
+ # By default, this directory contains tests for all rules of the parser.
5
+
6
+ # Additional tests consisting of full physics examples shall be made available soon in
7
+ # the form of another repository. One shall be able to copy the contents of that repo
8
+ # to this folder and use those tests after uncommenting the respective code in
9
+ # parsing/tests/test_autolev.py.
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest11.cpython-310.pyc ADDED
Binary file (780 Bytes). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest12.cpython-310.pyc ADDED
Binary file (814 Bytes). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest2.cpython-310.pyc ADDED
Binary file (1.03 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest3.cpython-310.pyc ADDED
Binary file (1.5 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/__pycache__/ruletest5.cpython-310.pyc ADDED
Binary file (2.61 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/chaos_pendulum.cpython-310.pyc ADDED
Binary file (2.12 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/double_pendulum.cpython-310.pyc ADDED
Binary file (1.59 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/mass_spring_damper.cpython-310.pyc ADDED
Binary file (1.56 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/__pycache__/non_min_pendulum.cpython-310.pyc ADDED
Binary file (1.61 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/chaos_pendulum.al ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CONSTANTS G,LB,W,H
2
+ MOTIONVARIABLES' THETA'',PHI'',OMEGA',ALPHA'
3
+ NEWTONIAN N
4
+ BODIES A,B
5
+ SIMPROT(N,A,2,THETA)
6
+ SIMPROT(A,B,3,PHI)
7
+ POINT O
8
+ LA = (LB-H/2)/2
9
+ P_O_AO> = LA*A3>
10
+ P_O_BO> = LB*A3>
11
+ OMEGA = THETA'
12
+ ALPHA = PHI'
13
+ W_A_N> = OMEGA*N2>
14
+ W_B_A> = ALPHA*A3>
15
+ V_O_N> = 0>
16
+ V2PTS(N, A, O, AO)
17
+ V2PTS(N, A, O, BO)
18
+ MASS A=MA, B=MB
19
+ IAXX = 1/12*MA*(2*LA)^2
20
+ IAYY = IAXX
21
+ IAZZ = 0
22
+ IBXX = 1/12*MB*H^2
23
+ IBYY = 1/12*MB*(W^2+H^2)
24
+ IBZZ = 1/12*MB*W^2
25
+ INERTIA A, IAXX, IAYY, IAZZ
26
+ INERTIA B, IBXX, IBYY, IBZZ
27
+ GRAVITY(G*N3>)
28
+ ZERO = FR() + FRSTAR()
29
+ KANE()
30
+ INPUT LB=0.2,H=0.1,W=0.2,MA=0.01,MB=0.1,G=9.81
31
+ INPUT THETA = 90 DEG, PHI = 0.5 DEG, OMEGA=0, ALPHA=0
32
+ INPUT TFINAL=10, INTEGSTP=0.02
33
+ CODE DYNAMICS() some_filename.c
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/chaos_pendulum.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ g, lb, w, h = _sm.symbols('g lb w h', real=True)
7
+ theta, phi, omega, alpha = _me.dynamicsymbols('theta phi omega alpha')
8
+ theta_d, phi_d, omega_d, alpha_d = _me.dynamicsymbols('theta_ phi_ omega_ alpha_', 1)
9
+ theta_dd, phi_dd = _me.dynamicsymbols('theta_ phi_', 2)
10
+ frame_n = _me.ReferenceFrame('n')
11
+ body_a_cm = _me.Point('a_cm')
12
+ body_a_cm.set_vel(frame_n, 0)
13
+ body_a_f = _me.ReferenceFrame('a_f')
14
+ body_a = _me.RigidBody('a', body_a_cm, body_a_f, _sm.symbols('m'), (_me.outer(body_a_f.x,body_a_f.x),body_a_cm))
15
+ body_b_cm = _me.Point('b_cm')
16
+ body_b_cm.set_vel(frame_n, 0)
17
+ body_b_f = _me.ReferenceFrame('b_f')
18
+ body_b = _me.RigidBody('b', body_b_cm, body_b_f, _sm.symbols('m'), (_me.outer(body_b_f.x,body_b_f.x),body_b_cm))
19
+ body_a_f.orient(frame_n, 'Axis', [theta, frame_n.y])
20
+ body_b_f.orient(body_a_f, 'Axis', [phi, body_a_f.z])
21
+ point_o = _me.Point('o')
22
+ la = (lb-h/2)/2
23
+ body_a_cm.set_pos(point_o, la*body_a_f.z)
24
+ body_b_cm.set_pos(point_o, lb*body_a_f.z)
25
+ body_a_f.set_ang_vel(frame_n, omega*frame_n.y)
26
+ body_b_f.set_ang_vel(body_a_f, alpha*body_a_f.z)
27
+ point_o.set_vel(frame_n, 0)
28
+ body_a_cm.v2pt_theory(point_o,frame_n,body_a_f)
29
+ body_b_cm.v2pt_theory(point_o,frame_n,body_a_f)
30
+ ma = _sm.symbols('ma')
31
+ body_a.mass = ma
32
+ mb = _sm.symbols('mb')
33
+ body_b.mass = mb
34
+ iaxx = 1/12*ma*(2*la)**2
35
+ iayy = iaxx
36
+ iazz = 0
37
+ ibxx = 1/12*mb*h**2
38
+ ibyy = 1/12*mb*(w**2+h**2)
39
+ ibzz = 1/12*mb*w**2
40
+ body_a.inertia = (_me.inertia(body_a_f, iaxx, iayy, iazz, 0, 0, 0), body_a_cm)
41
+ body_b.inertia = (_me.inertia(body_b_f, ibxx, ibyy, ibzz, 0, 0, 0), body_b_cm)
42
+ force_a = body_a.mass*(g*frame_n.z)
43
+ force_b = body_b.mass*(g*frame_n.z)
44
+ kd_eqs = [theta_d - omega, phi_d - alpha]
45
+ forceList = [(body_a.masscenter,body_a.mass*(g*frame_n.z)), (body_b.masscenter,body_b.mass*(g*frame_n.z))]
46
+ kane = _me.KanesMethod(frame_n, q_ind=[theta,phi], u_ind=[omega, alpha], kd_eqs = kd_eqs)
47
+ fr, frstar = kane.kanes_equations([body_a, body_b], forceList)
48
+ zero = fr+frstar
49
+ from pydy.system import System
50
+ sys = System(kane, constants = {g:9.81, lb:0.2, w:0.2, h:0.1, ma:0.01, mb:0.1},
51
+ specifieds={},
52
+ initial_conditions={theta:_np.deg2rad(90), phi:_np.deg2rad(0.5), omega:0, alpha:0},
53
+ times = _np.linspace(0.0, 10, 10/0.02))
54
+
55
+ y=sys.integrate()
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/double_pendulum.al ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MOTIONVARIABLES' Q{2}', U{2}'
2
+ CONSTANTS L,M,G
3
+ NEWTONIAN N
4
+ FRAMES A,B
5
+ SIMPROT(N, A, 3, Q1)
6
+ SIMPROT(N, B, 3, Q2)
7
+ W_A_N>=U1*N3>
8
+ W_B_N>=U2*N3>
9
+ POINT O
10
+ PARTICLES P,R
11
+ P_O_P> = L*A1>
12
+ P_P_R> = L*B1>
13
+ V_O_N> = 0>
14
+ V2PTS(N, A, O, P)
15
+ V2PTS(N, B, P, R)
16
+ MASS P=M, R=M
17
+ Q1' = U1
18
+ Q2' = U2
19
+ GRAVITY(G*N1>)
20
+ ZERO = FR() + FRSTAR()
21
+ KANE()
22
+ INPUT M=1,G=9.81,L=1
23
+ INPUT Q1=.1,Q2=.2,U1=0,U2=0
24
+ INPUT TFINAL=10, INTEGSTP=.01
25
+ CODE DYNAMICS() some_filename.c
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/double_pendulum.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ q1, q2, u1, u2 = _me.dynamicsymbols('q1 q2 u1 u2')
7
+ q1_d, q2_d, u1_d, u2_d = _me.dynamicsymbols('q1_ q2_ u1_ u2_', 1)
8
+ l, m, g = _sm.symbols('l m g', real=True)
9
+ frame_n = _me.ReferenceFrame('n')
10
+ frame_a = _me.ReferenceFrame('a')
11
+ frame_b = _me.ReferenceFrame('b')
12
+ frame_a.orient(frame_n, 'Axis', [q1, frame_n.z])
13
+ frame_b.orient(frame_n, 'Axis', [q2, frame_n.z])
14
+ frame_a.set_ang_vel(frame_n, u1*frame_n.z)
15
+ frame_b.set_ang_vel(frame_n, u2*frame_n.z)
16
+ point_o = _me.Point('o')
17
+ particle_p = _me.Particle('p', _me.Point('p_pt'), _sm.Symbol('m'))
18
+ particle_r = _me.Particle('r', _me.Point('r_pt'), _sm.Symbol('m'))
19
+ particle_p.point.set_pos(point_o, l*frame_a.x)
20
+ particle_r.point.set_pos(particle_p.point, l*frame_b.x)
21
+ point_o.set_vel(frame_n, 0)
22
+ particle_p.point.v2pt_theory(point_o,frame_n,frame_a)
23
+ particle_r.point.v2pt_theory(particle_p.point,frame_n,frame_b)
24
+ particle_p.mass = m
25
+ particle_r.mass = m
26
+ force_p = particle_p.mass*(g*frame_n.x)
27
+ force_r = particle_r.mass*(g*frame_n.x)
28
+ kd_eqs = [q1_d - u1, q2_d - u2]
29
+ forceList = [(particle_p.point,particle_p.mass*(g*frame_n.x)), (particle_r.point,particle_r.mass*(g*frame_n.x))]
30
+ kane = _me.KanesMethod(frame_n, q_ind=[q1,q2], u_ind=[u1, u2], kd_eqs = kd_eqs)
31
+ fr, frstar = kane.kanes_equations([particle_p, particle_r], forceList)
32
+ zero = fr+frstar
33
+ from pydy.system import System
34
+ sys = System(kane, constants = {l:1, m:1, g:9.81},
35
+ specifieds={},
36
+ initial_conditions={q1:.1, q2:.2, u1:0, u2:0},
37
+ times = _np.linspace(0.0, 10, 10/.01))
38
+
39
+ y=sys.integrate()
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/mass_spring_damper.al ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CONSTANTS M,K,B,G
2
+ MOTIONVARIABLES' POSITION',SPEED'
3
+ VARIABLES O
4
+ FORCE = O*SIN(T)
5
+ NEWTONIAN CEILING
6
+ POINTS ORIGIN
7
+ V_ORIGIN_CEILING> = 0>
8
+ PARTICLES BLOCK
9
+ P_ORIGIN_BLOCK> = POSITION*CEILING1>
10
+ MASS BLOCK=M
11
+ V_BLOCK_CEILING>=SPEED*CEILING1>
12
+ POSITION' = SPEED
13
+ FORCE_MAGNITUDE = M*G-K*POSITION-B*SPEED+FORCE
14
+ FORCE_BLOCK>=EXPLICIT(FORCE_MAGNITUDE*CEILING1>)
15
+ ZERO = FR() + FRSTAR()
16
+ KANE()
17
+ INPUT TFINAL=10.0, INTEGSTP=0.01
18
+ INPUT M=1.0, K=1.0, B=0.2, G=9.8, POSITION=0.1, SPEED=-1.0, O=2
19
+ CODE DYNAMICS() dummy_file.c
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/mass_spring_damper.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ m, k, b, g = _sm.symbols('m k b g', real=True)
7
+ position, speed = _me.dynamicsymbols('position speed')
8
+ position_d, speed_d = _me.dynamicsymbols('position_ speed_', 1)
9
+ o = _me.dynamicsymbols('o')
10
+ force = o*_sm.sin(_me.dynamicsymbols._t)
11
+ frame_ceiling = _me.ReferenceFrame('ceiling')
12
+ point_origin = _me.Point('origin')
13
+ point_origin.set_vel(frame_ceiling, 0)
14
+ particle_block = _me.Particle('block', _me.Point('block_pt'), _sm.Symbol('m'))
15
+ particle_block.point.set_pos(point_origin, position*frame_ceiling.x)
16
+ particle_block.mass = m
17
+ particle_block.point.set_vel(frame_ceiling, speed*frame_ceiling.x)
18
+ force_magnitude = m*g-k*position-b*speed+force
19
+ force_block = (force_magnitude*frame_ceiling.x).subs({position_d:speed})
20
+ kd_eqs = [position_d - speed]
21
+ forceList = [(particle_block.point,(force_magnitude*frame_ceiling.x).subs({position_d:speed}))]
22
+ kane = _me.KanesMethod(frame_ceiling, q_ind=[position], u_ind=[speed], kd_eqs = kd_eqs)
23
+ fr, frstar = kane.kanes_equations([particle_block], forceList)
24
+ zero = fr+frstar
25
+ from pydy.system import System
26
+ sys = System(kane, constants = {m:1.0, k:1.0, b:0.2, g:9.8},
27
+ specifieds={_me.dynamicsymbols('t'):lambda x, t: t, o:2},
28
+ initial_conditions={position:0.1, speed:-1*1.0},
29
+ times = _np.linspace(0.0, 10.0, 10.0/0.01))
30
+
31
+ y=sys.integrate()
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/non_min_pendulum.al ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MOTIONVARIABLES' Q{2}''
2
+ CONSTANTS L,M,G
3
+ NEWTONIAN N
4
+ POINT PN
5
+ V_PN_N> = 0>
6
+ THETA1 = ATAN(Q2/Q1)
7
+ FRAMES A
8
+ SIMPROT(N, A, 3, THETA1)
9
+ PARTICLES P
10
+ P_PN_P> = Q1*N1>+Q2*N2>
11
+ MASS P=M
12
+ V_P_N>=DT(P_P_PN>, N)
13
+ F_V = DOT(EXPRESS(V_P_N>,A), A1>)
14
+ GRAVITY(G*N1>)
15
+ DEPENDENT[1] = F_V
16
+ CONSTRAIN(DEPENDENT[Q1'])
17
+ ZERO=FR()+FRSTAR()
18
+ F_C = MAG(P_P_PN>)-L
19
+ CONFIG[1]=F_C
20
+ ZERO[2]=CONFIG[1]
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/pydy-example-repo/non_min_pendulum.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ q1, q2 = _me.dynamicsymbols('q1 q2')
7
+ q1_d, q2_d = _me.dynamicsymbols('q1_ q2_', 1)
8
+ q1_dd, q2_dd = _me.dynamicsymbols('q1_ q2_', 2)
9
+ l, m, g = _sm.symbols('l m g', real=True)
10
+ frame_n = _me.ReferenceFrame('n')
11
+ point_pn = _me.Point('pn')
12
+ point_pn.set_vel(frame_n, 0)
13
+ theta1 = _sm.atan(q2/q1)
14
+ frame_a = _me.ReferenceFrame('a')
15
+ frame_a.orient(frame_n, 'Axis', [theta1, frame_n.z])
16
+ particle_p = _me.Particle('p', _me.Point('p_pt'), _sm.Symbol('m'))
17
+ particle_p.point.set_pos(point_pn, q1*frame_n.x+q2*frame_n.y)
18
+ particle_p.mass = m
19
+ particle_p.point.set_vel(frame_n, (point_pn.pos_from(particle_p.point)).dt(frame_n))
20
+ f_v = _me.dot((particle_p.point.vel(frame_n)).express(frame_a), frame_a.x)
21
+ force_p = particle_p.mass*(g*frame_n.x)
22
+ dependent = _sm.Matrix([[0]])
23
+ dependent[0] = f_v
24
+ velocity_constraints = [i for i in dependent]
25
+ u_q1_d = _me.dynamicsymbols('u_q1_d')
26
+ u_q2_d = _me.dynamicsymbols('u_q2_d')
27
+ kd_eqs = [q1_d-u_q1_d, q2_d-u_q2_d]
28
+ forceList = [(particle_p.point,particle_p.mass*(g*frame_n.x))]
29
+ kane = _me.KanesMethod(frame_n, q_ind=[q1,q2], u_ind=[u_q2_d], u_dependent=[u_q1_d], kd_eqs = kd_eqs, velocity_constraints = velocity_constraints)
30
+ fr, frstar = kane.kanes_equations([particle_p], forceList)
31
+ zero = fr+frstar
32
+ f_c = point_pn.pos_from(particle_p.point).magnitude()-l
33
+ config = _sm.Matrix([[0]])
34
+ config[0] = f_c
35
+ zero = zero.row_insert(zero.shape[0], _sm.Matrix([[0]]))
36
+ zero[zero.shape[0]-1] = config[0]
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest1.al ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ % ruletest1.al
2
+ CONSTANTS F = 3, G = 9.81
3
+ CONSTANTS A, B
4
+ CONSTANTS S, S1, S2+, S3+, S4-
5
+ CONSTANTS K{4}, L{1:3}, P{1:2,1:3}
6
+ CONSTANTS C{2,3}
7
+ E1 = A*F + S2 - G
8
+ E2 = F^2 + K3*K2*G
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest10.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ x, y = _me.dynamicsymbols('x y')
7
+ a, b = _sm.symbols('a b', real=True)
8
+ e = a*(b*x+y)**2
9
+ m = _sm.Matrix([e,e]).reshape(2, 1)
10
+ e = e.expand()
11
+ m = _sm.Matrix([i.expand() for i in m]).reshape((m).shape[0], (m).shape[1])
12
+ e = _sm.factor(e, x)
13
+ m = _sm.Matrix([_sm.factor(i,x) for i in m]).reshape((m).shape[0], (m).shape[1])
14
+ eqn = _sm.Matrix([[0]])
15
+ eqn[0] = a*x+b*y
16
+ eqn = eqn.row_insert(eqn.shape[0], _sm.Matrix([[0]]))
17
+ eqn[eqn.shape[0]-1] = 2*a*x-3*b*y
18
+ print(_sm.solve(eqn,x,y))
19
+ rhs_y = _sm.solve(eqn,x,y)[y]
20
+ e = (x+y)**2+2*x**2
21
+ e.collect(x)
22
+ a, b, c = _sm.symbols('a b c', real=True)
23
+ m = _sm.Matrix([a,b,c,0]).reshape(2, 2)
24
+ m2 = _sm.Matrix([i.subs({a:1,b:2,c:3}) for i in m]).reshape((m).shape[0], (m).shape[1])
25
+ eigvalue = _sm.Matrix([i.evalf() for i in (m2).eigenvals().keys()])
26
+ eigvec = _sm.Matrix([i[2][0].evalf() for i in (m2).eigenvects()]).reshape(m2.shape[0], m2.shape[1])
27
+ frame_n = _me.ReferenceFrame('n')
28
+ frame_a = _me.ReferenceFrame('a')
29
+ frame_a.orient(frame_n, 'Axis', [x, frame_n.x])
30
+ frame_a.orient(frame_n, 'Axis', [_sm.pi/2, frame_n.x])
31
+ c1, c2, c3 = _sm.symbols('c1 c2 c3', real=True)
32
+ v = c1*frame_a.x+c2*frame_a.y+c3*frame_a.z
33
+ point_o = _me.Point('o')
34
+ point_p = _me.Point('p')
35
+ point_o.set_pos(point_p, c1*frame_a.x)
36
+ v = (v).express(frame_n)
37
+ point_o.set_pos(point_p, (point_o.pos_from(point_p)).express(frame_n))
38
+ frame_a.set_ang_vel(frame_n, c3*frame_a.z)
39
+ print(frame_n.ang_vel_in(frame_a))
40
+ point_p.v2pt_theory(point_o,frame_n,frame_a)
41
+ particle_p1 = _me.Particle('p1', _me.Point('p1_pt'), _sm.Symbol('m'))
42
+ particle_p2 = _me.Particle('p2', _me.Point('p2_pt'), _sm.Symbol('m'))
43
+ particle_p2.point.v2pt_theory(particle_p1.point,frame_n,frame_a)
44
+ point_p.a2pt_theory(particle_p1.point,frame_n,frame_a)
45
+ body_b1_cm = _me.Point('b1_cm')
46
+ body_b1_cm.set_vel(frame_n, 0)
47
+ body_b1_f = _me.ReferenceFrame('b1_f')
48
+ body_b1 = _me.RigidBody('b1', body_b1_cm, body_b1_f, _sm.symbols('m'), (_me.outer(body_b1_f.x,body_b1_f.x),body_b1_cm))
49
+ body_b2_cm = _me.Point('b2_cm')
50
+ body_b2_cm.set_vel(frame_n, 0)
51
+ body_b2_f = _me.ReferenceFrame('b2_f')
52
+ body_b2 = _me.RigidBody('b2', body_b2_cm, body_b2_f, _sm.symbols('m'), (_me.outer(body_b2_f.x,body_b2_f.x),body_b2_cm))
53
+ g = _sm.symbols('g', real=True)
54
+ force_p1 = particle_p1.mass*(g*frame_n.x)
55
+ force_p2 = particle_p2.mass*(g*frame_n.x)
56
+ force_b1 = body_b1.mass*(g*frame_n.x)
57
+ force_b2 = body_b2.mass*(g*frame_n.x)
58
+ z = _me.dynamicsymbols('z')
59
+ v = x*frame_a.x+y*frame_a.z
60
+ point_o.set_pos(point_p, x*frame_a.x+y*frame_a.y)
61
+ v = (v).subs({x:2*z, y:z})
62
+ point_o.set_pos(point_p, (point_o.pos_from(point_p)).subs({x:2*z, y:z}))
63
+ force_o = -1*(x*y*frame_a.x)
64
+ force_p1 = particle_p1.mass*(g*frame_n.x)+ x*y*frame_a.x
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest11.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ x, y = _me.dynamicsymbols('x y')
7
+ a11, a12, a21, a22, b1, b2 = _sm.symbols('a11 a12 a21 a22 b1 b2', real=True)
8
+ eqn = _sm.Matrix([[0]])
9
+ eqn[0] = a11*x+a12*y-b1
10
+ eqn = eqn.row_insert(eqn.shape[0], _sm.Matrix([[0]]))
11
+ eqn[eqn.shape[0]-1] = a21*x+a22*y-b2
12
+ eqn_list = []
13
+ for i in eqn: eqn_list.append(i.subs({a11:2, a12:5, a21:3, a22:4, b1:7, b2:6}))
14
+ print(_sm.linsolve(eqn_list, x,y))
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest12.al ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ VARIABLES X,Y
2
+ CONSTANTS A,B,R
3
+ EQN[1] = A*X^3+B*Y^2-R
4
+ EQN[2] = A*SIN(X)^2 + B*COS(2*Y) - R^2
5
+ INPUT A=2.0, B=3.0, R=1.0
6
+ INPUT X = 30 DEG, Y = 3.14
7
+ CODE NONLINEAR(EQN,X,Y) some_filename.c
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest12.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ x, y = _me.dynamicsymbols('x y')
7
+ a, b, r = _sm.symbols('a b r', real=True)
8
+ eqn = _sm.Matrix([[0]])
9
+ eqn[0] = a*x**3+b*y**2-r
10
+ eqn = eqn.row_insert(eqn.shape[0], _sm.Matrix([[0]]))
11
+ eqn[eqn.shape[0]-1] = a*_sm.sin(x)**2+b*_sm.cos(2*y)-r**2
12
+ matrix_list = []
13
+ for i in eqn:matrix_list.append(i.subs({a:2.0, b:3.0, r:1.0}))
14
+ print(_sm.nsolve(matrix_list,(x,y),(_np.deg2rad(30),3.14)))
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest2.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ x1, x2 = _me.dynamicsymbols('x1 x2')
7
+ f1 = x1*x2+3*x1**2
8
+ f2 = x1*_me.dynamicsymbols._t+x2*_me.dynamicsymbols._t**2
9
+ x, y = _me.dynamicsymbols('x y')
10
+ x_d, y_d = _me.dynamicsymbols('x_ y_', 1)
11
+ y_dd = _me.dynamicsymbols('y_', 2)
12
+ q1, q2, q3, u1, u2 = _me.dynamicsymbols('q1 q2 q3 u1 u2')
13
+ p1, p2 = _me.dynamicsymbols('p1 p2')
14
+ p1_d, p2_d = _me.dynamicsymbols('p1_ p2_', 1)
15
+ w1, w2, w3, r1, r2 = _me.dynamicsymbols('w1 w2 w3 r1 r2')
16
+ w1_d, w2_d, w3_d, r1_d, r2_d = _me.dynamicsymbols('w1_ w2_ w3_ r1_ r2_', 1)
17
+ r1_dd, r2_dd = _me.dynamicsymbols('r1_ r2_', 2)
18
+ c11, c12, c21, c22 = _me.dynamicsymbols('c11 c12 c21 c22')
19
+ d11, d12, d13 = _me.dynamicsymbols('d11 d12 d13')
20
+ j1, j2 = _me.dynamicsymbols('j1 j2')
21
+ n = _sm.symbols('n')
22
+ n = _sm.I
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest3.al ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ruletest3.al
2
+ FRAMES A, B
3
+ NEWTONIAN N
4
+
5
+ VARIABLES X{3}
6
+ CONSTANTS L
7
+
8
+ V1> = X1*A1> + X2*A2> + X3*A3>
9
+ V2> = X1*B1> + X2*B2> + X3*B3>
10
+ V3> = X1*N1> + X2*N2> + X3*N3>
11
+
12
+ V> = V1> + V2> + V3>
13
+
14
+ POINTS C, D
15
+ POINTS PO{3}
16
+
17
+ PARTICLES L
18
+ PARTICLES P{3}
19
+
20
+ BODIES S
21
+ BODIES R{2}
22
+
23
+ V4> = X1*S1> + X2*S2> + X3*S3>
24
+
25
+ P_C_SO> = L*N1>
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest3.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ frame_a = _me.ReferenceFrame('a')
7
+ frame_b = _me.ReferenceFrame('b')
8
+ frame_n = _me.ReferenceFrame('n')
9
+ x1, x2, x3 = _me.dynamicsymbols('x1 x2 x3')
10
+ l = _sm.symbols('l', real=True)
11
+ v1 = x1*frame_a.x+x2*frame_a.y+x3*frame_a.z
12
+ v2 = x1*frame_b.x+x2*frame_b.y+x3*frame_b.z
13
+ v3 = x1*frame_n.x+x2*frame_n.y+x3*frame_n.z
14
+ v = v1+v2+v3
15
+ point_c = _me.Point('c')
16
+ point_d = _me.Point('d')
17
+ point_po1 = _me.Point('po1')
18
+ point_po2 = _me.Point('po2')
19
+ point_po3 = _me.Point('po3')
20
+ particle_l = _me.Particle('l', _me.Point('l_pt'), _sm.Symbol('m'))
21
+ particle_p1 = _me.Particle('p1', _me.Point('p1_pt'), _sm.Symbol('m'))
22
+ particle_p2 = _me.Particle('p2', _me.Point('p2_pt'), _sm.Symbol('m'))
23
+ particle_p3 = _me.Particle('p3', _me.Point('p3_pt'), _sm.Symbol('m'))
24
+ body_s_cm = _me.Point('s_cm')
25
+ body_s_cm.set_vel(frame_n, 0)
26
+ body_s_f = _me.ReferenceFrame('s_f')
27
+ body_s = _me.RigidBody('s', body_s_cm, body_s_f, _sm.symbols('m'), (_me.outer(body_s_f.x,body_s_f.x),body_s_cm))
28
+ body_r1_cm = _me.Point('r1_cm')
29
+ body_r1_cm.set_vel(frame_n, 0)
30
+ body_r1_f = _me.ReferenceFrame('r1_f')
31
+ body_r1 = _me.RigidBody('r1', body_r1_cm, body_r1_f, _sm.symbols('m'), (_me.outer(body_r1_f.x,body_r1_f.x),body_r1_cm))
32
+ body_r2_cm = _me.Point('r2_cm')
33
+ body_r2_cm.set_vel(frame_n, 0)
34
+ body_r2_f = _me.ReferenceFrame('r2_f')
35
+ body_r2 = _me.RigidBody('r2', body_r2_cm, body_r2_f, _sm.symbols('m'), (_me.outer(body_r2_f.x,body_r2_f.x),body_r2_cm))
36
+ v4 = x1*body_s_f.x+x2*body_s_f.y+x3*body_s_f.z
37
+ body_s_cm.set_pos(point_c, l*frame_n.x)
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest4.al ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ruletest4.al
2
+
3
+ FRAMES A, B
4
+ MOTIONVARIABLES Q{3}
5
+ SIMPROT(A, B, 1, Q3)
6
+ DCM = A_B
7
+ M = DCM*3 - A_B
8
+
9
+ VARIABLES R
10
+ CIRCLE_AREA = PI*R^2
11
+
12
+ VARIABLES U, A
13
+ VARIABLES X, Y
14
+ S = U*T - 1/2*A*T^2
15
+
16
+ EXPR1 = 2*A*0.5 - 1.25 + 0.25
17
+ EXPR2 = -X^2 + Y^2 + 0.25*(X+Y)^2
18
+ EXPR3 = 0.5E-10
19
+
20
+ DYADIC>> = A1>*A1> + A2>*A2> + A3>*A3>
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest4.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ frame_a = _me.ReferenceFrame('a')
7
+ frame_b = _me.ReferenceFrame('b')
8
+ q1, q2, q3 = _me.dynamicsymbols('q1 q2 q3')
9
+ frame_b.orient(frame_a, 'Axis', [q3, frame_a.x])
10
+ dcm = frame_a.dcm(frame_b)
11
+ m = dcm*3-frame_a.dcm(frame_b)
12
+ r = _me.dynamicsymbols('r')
13
+ circle_area = _sm.pi*r**2
14
+ u, a = _me.dynamicsymbols('u a')
15
+ x, y = _me.dynamicsymbols('x y')
16
+ s = u*_me.dynamicsymbols._t-1/2*a*_me.dynamicsymbols._t**2
17
+ expr1 = 2*a*0.5-1.25+0.25
18
+ expr2 = -1*x**2+y**2+0.25*(x+y)**2
19
+ expr3 = 0.5*10**(-10)
20
+ dyadic = _me.outer(frame_a.x, frame_a.x)+_me.outer(frame_a.y, frame_a.y)+_me.outer(frame_a.z, frame_a.z)
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest5.al ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ruletest5.al
2
+ VARIABLES X', Y'
3
+
4
+ E1 = (X+Y)^2 + (X-Y)^3
5
+ E2 = (X-Y)^2
6
+ E3 = X^2 + Y^2 + 2*X*Y
7
+
8
+ M1 = [E1;E2]
9
+ M2 = [(X+Y)^2,(X-Y)^2]
10
+ M3 = M1 + [X;Y]
11
+
12
+ AM = EXPAND(M1)
13
+ CM = EXPAND([(X+Y)^2,(X-Y)^2])
14
+ EM = EXPAND(M1 + [X;Y])
15
+ F = EXPAND(E1)
16
+ G = EXPAND(E2)
17
+
18
+ A = FACTOR(E3, X)
19
+ BM = FACTOR(M1, X)
20
+ CM = FACTOR(M1 + [X;Y], X)
21
+
22
+ A = D(E3, X)
23
+ B = D(E3, Y)
24
+ CM = D(M2, X)
25
+ DM = D(M1 + [X;Y], X)
26
+ FRAMES A, B
27
+ A_B = [1,0,0;1,0,0;1,0,0]
28
+ V1> = X*A1> + Y*A2> + X*Y*A3>
29
+ E> = D(V1>, X, B)
30
+ FM = DT(M1)
31
+ GM = DT([(X+Y)^2,(X-Y)^2])
32
+ H> = DT(V1>, B)
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest5.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ x, y = _me.dynamicsymbols('x y')
7
+ x_d, y_d = _me.dynamicsymbols('x_ y_', 1)
8
+ e1 = (x+y)**2+(x-y)**3
9
+ e2 = (x-y)**2
10
+ e3 = x**2+y**2+2*x*y
11
+ m1 = _sm.Matrix([e1,e2]).reshape(2, 1)
12
+ m2 = _sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)
13
+ m3 = m1+_sm.Matrix([x,y]).reshape(2, 1)
14
+ am = _sm.Matrix([i.expand() for i in m1]).reshape((m1).shape[0], (m1).shape[1])
15
+ cm = _sm.Matrix([i.expand() for i in _sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)]).reshape((_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[0], (_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[1])
16
+ em = _sm.Matrix([i.expand() for i in m1+_sm.Matrix([x,y]).reshape(2, 1)]).reshape((m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[0], (m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[1])
17
+ f = (e1).expand()
18
+ g = (e2).expand()
19
+ a = _sm.factor((e3), x)
20
+ bm = _sm.Matrix([_sm.factor(i, x) for i in m1]).reshape((m1).shape[0], (m1).shape[1])
21
+ cm = _sm.Matrix([_sm.factor(i, x) for i in m1+_sm.Matrix([x,y]).reshape(2, 1)]).reshape((m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[0], (m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[1])
22
+ a = (e3).diff(x)
23
+ b = (e3).diff(y)
24
+ cm = _sm.Matrix([i.diff(x) for i in m2]).reshape((m2).shape[0], (m2).shape[1])
25
+ dm = _sm.Matrix([i.diff(x) for i in m1+_sm.Matrix([x,y]).reshape(2, 1)]).reshape((m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[0], (m1+_sm.Matrix([x,y]).reshape(2, 1)).shape[1])
26
+ frame_a = _me.ReferenceFrame('a')
27
+ frame_b = _me.ReferenceFrame('b')
28
+ frame_b.orient(frame_a, 'DCM', _sm.Matrix([1,0,0,1,0,0,1,0,0]).reshape(3, 3))
29
+ v1 = x*frame_a.x+y*frame_a.y+x*y*frame_a.z
30
+ e = (v1).diff(x, frame_b)
31
+ fm = _sm.Matrix([i.diff(_sm.Symbol('t')) for i in m1]).reshape((m1).shape[0], (m1).shape[1])
32
+ gm = _sm.Matrix([i.diff(_sm.Symbol('t')) for i in _sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)]).reshape((_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[0], (_sm.Matrix([(x+y)**2,(x-y)**2]).reshape(1, 2)).shape[1])
33
+ h = (v1).dt(frame_b)
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest6.al ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ruletest6.al
2
+ VARIABLES Q{2}
3
+ VARIABLES X,Y,Z
4
+ Q1 = X^2 + Y^2
5
+ Q2 = X-Y
6
+ E = Q1 + Q2
7
+ A = EXPLICIT(E)
8
+ E2 = COS(X)
9
+ E3 = COS(X*Y)
10
+ A = TAYLOR(E2, 0:2, X=0)
11
+ B = TAYLOR(E3, 0:2, X=0, Y=0)
12
+
13
+ E = EXPAND((X+Y)^2)
14
+ A = EVALUATE(E, X=1, Y=Z)
15
+ BM = EVALUATE([E;2*E], X=1, Y=Z)
16
+
17
+ E = Q1 + Q2
18
+ A = EVALUATE(E, X=2, Y=Z^2)
19
+
20
+ CONSTANTS J,K,L
21
+ P1 = POLYNOMIAL([J,K,L],X)
22
+ P2 = POLYNOMIAL(J*X+K,X,1)
23
+
24
+ ROOT1 = ROOTS(P1, X, 2)
25
+ ROOT2 = ROOTS([1;2;3])
26
+
27
+ M = [1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16]
28
+
29
+ AM = TRANSPOSE(M) + M
30
+ BM = EIG(M)
31
+ C1 = DIAGMAT(4, 1)
32
+ C2 = DIAGMAT(3, 4, 2)
33
+ DM = INV(M+C1)
34
+ E = DET(M+C1) + TRACE([1,0;0,1])
35
+ F = ELEMENT(M, 2, 3)
36
+
37
+ A = COLS(M)
38
+ BM = COLS(M, 1)
39
+ CM = COLS(M, 1, 2:4, 3)
40
+ DM = ROWS(M, 1)
41
+ EM = ROWS(M, 1, 2:4, 3)
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest6.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ q1, q2 = _me.dynamicsymbols('q1 q2')
7
+ x, y, z = _me.dynamicsymbols('x y z')
8
+ e = q1+q2
9
+ a = (e).subs({q1:x**2+y**2, q2:x-y})
10
+ e2 = _sm.cos(x)
11
+ e3 = _sm.cos(x*y)
12
+ a = (e2).series(x, 0, 2).removeO()
13
+ b = (e3).series(x, 0, 2).removeO().series(y, 0, 2).removeO()
14
+ e = ((x+y)**2).expand()
15
+ a = (e).subs({q1:x**2+y**2,q2:x-y}).subs({x:1,y:z})
16
+ bm = _sm.Matrix([i.subs({x:1,y:z}) for i in _sm.Matrix([e,2*e]).reshape(2, 1)]).reshape((_sm.Matrix([e,2*e]).reshape(2, 1)).shape[0], (_sm.Matrix([e,2*e]).reshape(2, 1)).shape[1])
17
+ e = q1+q2
18
+ a = (e).subs({q1:x**2+y**2,q2:x-y}).subs({x:2,y:z**2})
19
+ j, k, l = _sm.symbols('j k l', real=True)
20
+ p1 = _sm.Poly(_sm.Matrix([j,k,l]).reshape(1, 3), x)
21
+ p2 = _sm.Poly(j*x+k, x)
22
+ root1 = [i.evalf() for i in _sm.solve(p1, x)]
23
+ root2 = [i.evalf() for i in _sm.solve(_sm.Poly(_sm.Matrix([1,2,3]).reshape(3, 1), x),x)]
24
+ m = _sm.Matrix([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).reshape(4, 4)
25
+ am = (m).T+m
26
+ bm = _sm.Matrix([i.evalf() for i in (m).eigenvals().keys()])
27
+ c1 = _sm.diag(1,1,1,1)
28
+ c2 = _sm.Matrix([2 if i==j else 0 for i in range(3) for j in range(4)]).reshape(3, 4)
29
+ dm = (m+c1)**(-1)
30
+ e = (m+c1).det()+(_sm.Matrix([1,0,0,1]).reshape(2, 2)).trace()
31
+ f = (m)[1,2]
32
+ a = (m).cols
33
+ bm = (m).col(0)
34
+ cm = _sm.Matrix([(m).T.row(0),(m).T.row(1),(m).T.row(2),(m).T.row(3),(m).T.row(2)])
35
+ dm = (m).row(0)
36
+ em = _sm.Matrix([(m).row(0),(m).row(1),(m).row(2),(m).row(3),(m).row(2)])
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest7.al ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ruletest7.al
2
+ VARIABLES X', Y'
3
+ E = COS(X) + SIN(X) + TAN(X)&
4
+ + COSH(X) + SINH(X) + TANH(X)&
5
+ + ACOS(X) + ASIN(X) + ATAN(X)&
6
+ + LOG(X) + EXP(X) + SQRT(X)&
7
+ + FACTORIAL(X) + CEIL(X) +&
8
+ FLOOR(X) + SIGN(X)
9
+
10
+ E = SQR(X) + LOG10(X)
11
+
12
+ A = ABS(-1) + INT(1.5) + ROUND(1.9)
13
+
14
+ E1 = 2*X + 3*Y
15
+ E2 = X + Y
16
+
17
+ AM = COEF([E1;E2], [X,Y])
18
+ B = COEF(E1, X)
19
+ C = COEF(E2, Y)
20
+ D1 = EXCLUDE(E1, X)
21
+ D2 = INCLUDE(E1, X)
22
+ FM = ARRANGE([E1,E2],2,X)
23
+ F = ARRANGE(E1, 2, Y)
24
+ G = REPLACE(E1, X=2*X)
25
+ GM = REPLACE([E1;E2], X=3)
26
+
27
+ FRAMES A, B
28
+ VARIABLES THETA
29
+ SIMPROT(A,B,3,THETA)
30
+ V1> = 2*A1> - 3*A2> + A3>
31
+ V2> = B1> + B2> + B3>
32
+ A = DOT(V1>, V2>)
33
+ BM = DOT(V1>, [V2>;2*V2>])
34
+ C> = CROSS(V1>,V2>)
35
+ D = MAG(2*V1>) + MAG(3*V1>)
36
+ DYADIC>> = 3*A1>*A1> + A2>*A2> + 2*A3>*A3>
37
+ AM = MATRIX(B, DYADIC>>)
38
+ M = [1;2;3]
39
+ V> = VECTOR(A, M)
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest7.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ x, y = _me.dynamicsymbols('x y')
7
+ x_d, y_d = _me.dynamicsymbols('x_ y_', 1)
8
+ e = _sm.cos(x)+_sm.sin(x)+_sm.tan(x)+_sm.cosh(x)+_sm.sinh(x)+_sm.tanh(x)+_sm.acos(x)+_sm.asin(x)+_sm.atan(x)+_sm.log(x)+_sm.exp(x)+_sm.sqrt(x)+_sm.factorial(x)+_sm.ceiling(x)+_sm.floor(x)+_sm.sign(x)
9
+ e = (x)**2+_sm.log(x, 10)
10
+ a = _sm.Abs(-1*1)+int(1.5)+round(1.9)
11
+ e1 = 2*x+3*y
12
+ e2 = x+y
13
+ am = _sm.Matrix([e1.expand().coeff(x), e1.expand().coeff(y), e2.expand().coeff(x), e2.expand().coeff(y)]).reshape(2, 2)
14
+ b = (e1).expand().coeff(x)
15
+ c = (e2).expand().coeff(y)
16
+ d1 = (e1).collect(x).coeff(x,0)
17
+ d2 = (e1).collect(x).coeff(x,1)
18
+ fm = _sm.Matrix([i.collect(x)for i in _sm.Matrix([e1,e2]).reshape(1, 2)]).reshape((_sm.Matrix([e1,e2]).reshape(1, 2)).shape[0], (_sm.Matrix([e1,e2]).reshape(1, 2)).shape[1])
19
+ f = (e1).collect(y)
20
+ g = (e1).subs({x:2*x})
21
+ gm = _sm.Matrix([i.subs({x:3}) for i in _sm.Matrix([e1,e2]).reshape(2, 1)]).reshape((_sm.Matrix([e1,e2]).reshape(2, 1)).shape[0], (_sm.Matrix([e1,e2]).reshape(2, 1)).shape[1])
22
+ frame_a = _me.ReferenceFrame('a')
23
+ frame_b = _me.ReferenceFrame('b')
24
+ theta = _me.dynamicsymbols('theta')
25
+ frame_b.orient(frame_a, 'Axis', [theta, frame_a.z])
26
+ v1 = 2*frame_a.x-3*frame_a.y+frame_a.z
27
+ v2 = frame_b.x+frame_b.y+frame_b.z
28
+ a = _me.dot(v1, v2)
29
+ bm = _sm.Matrix([_me.dot(v1, v2),_me.dot(v1, 2*v2)]).reshape(2, 1)
30
+ c = _me.cross(v1, v2)
31
+ d = 2*v1.magnitude()+3*v1.magnitude()
32
+ dyadic = _me.outer(3*frame_a.x, frame_a.x)+_me.outer(frame_a.y, frame_a.y)+_me.outer(2*frame_a.z, frame_a.z)
33
+ am = (dyadic).to_matrix(frame_b)
34
+ m = _sm.Matrix([1,2,3]).reshape(3, 1)
35
+ v = m[0]*frame_a.x +m[1]*frame_a.y +m[2]*frame_a.z
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest8.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sympy.physics.mechanics as _me
2
+ import sympy as _sm
3
+ import math as m
4
+ import numpy as _np
5
+
6
+ frame_a = _me.ReferenceFrame('a')
7
+ c1, c2, c3 = _sm.symbols('c1 c2 c3', real=True)
8
+ a = _me.inertia(frame_a, 1, 1, 1)
9
+ particle_p1 = _me.Particle('p1', _me.Point('p1_pt'), _sm.Symbol('m'))
10
+ particle_p2 = _me.Particle('p2', _me.Point('p2_pt'), _sm.Symbol('m'))
11
+ body_r_cm = _me.Point('r_cm')
12
+ body_r_f = _me.ReferenceFrame('r_f')
13
+ body_r = _me.RigidBody('r', body_r_cm, body_r_f, _sm.symbols('m'), (_me.outer(body_r_f.x,body_r_f.x),body_r_cm))
14
+ frame_a.orient(body_r_f, 'DCM', _sm.Matrix([1,1,1,1,1,0,0,0,1]).reshape(3, 3))
15
+ point_o = _me.Point('o')
16
+ m1 = _sm.symbols('m1')
17
+ particle_p1.mass = m1
18
+ m2 = _sm.symbols('m2')
19
+ particle_p2.mass = m2
20
+ mr = _sm.symbols('mr')
21
+ body_r.mass = mr
22
+ i1 = _sm.symbols('i1')
23
+ i2 = _sm.symbols('i2')
24
+ i3 = _sm.symbols('i3')
25
+ body_r.inertia = (_me.inertia(body_r_f, i1, i2, i3, 0, 0, 0), body_r_cm)
26
+ point_o.set_pos(particle_p1.point, c1*frame_a.x)
27
+ point_o.set_pos(particle_p2.point, c2*frame_a.y)
28
+ point_o.set_pos(body_r_cm, c3*frame_a.z)
29
+ a = _me.inertia_of_point_mass(particle_p1.mass, particle_p1.point.pos_from(point_o), frame_a)
30
+ a = _me.inertia_of_point_mass(particle_p2.mass, particle_p2.point.pos_from(point_o), frame_a)
31
+ a = body_r.inertia[0] + _me.inertia_of_point_mass(body_r.mass, body_r.masscenter.pos_from(point_o), frame_a)
32
+ a = _me.inertia_of_point_mass(particle_p1.mass, particle_p1.point.pos_from(point_o), frame_a) + _me.inertia_of_point_mass(particle_p2.mass, particle_p2.point.pos_from(point_o), frame_a) + body_r.inertia[0] + _me.inertia_of_point_mass(body_r.mass, body_r.masscenter.pos_from(point_o), frame_a)
33
+ a = _me.inertia_of_point_mass(particle_p1.mass, particle_p1.point.pos_from(point_o), frame_a) + body_r.inertia[0] + _me.inertia_of_point_mass(body_r.mass, body_r.masscenter.pos_from(point_o), frame_a)
34
+ a = body_r.inertia[0] + _me.inertia_of_point_mass(body_r.mass, body_r.masscenter.pos_from(point_o), frame_a)
35
+ a = body_r.inertia[0]
36
+ particle_p2.point.set_pos(particle_p1.point, c1*frame_a.x+c2*frame_a.y)
37
+ body_r_cm.set_pos(particle_p1.point, c3*frame_a.x)
38
+ body_r_cm.set_pos(particle_p2.point, c3*frame_a.y)
39
+ b = _me.functions.center_of_mass(point_o,particle_p1, particle_p2, body_r)
40
+ b = _me.functions.center_of_mass(point_o,particle_p1, body_r)
41
+ b = _me.functions.center_of_mass(particle_p1.point,particle_p1, particle_p2, body_r)
42
+ u1, u2, u3 = _me.dynamicsymbols('u1 u2 u3')
43
+ v = u1*frame_a.x+u2*frame_a.y+u3*frame_a.z
44
+ u = (v+c1*frame_a.x).normalize()
45
+ particle_p1.point.set_vel(frame_a, u1*frame_a.x)
46
+ a = particle_p1.point.partial_velocity(frame_a, u1)
47
+ m = particle_p1.mass+body_r.mass
48
+ m = particle_p2.mass
49
+ m = particle_p1.mass+particle_p2.mass+body_r.mass
llmeval-env/lib/python3.10/site-packages/sympy/parsing/autolev/test-examples/ruletest9.al ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ruletest9.al
2
+ NEWTONIAN N
3
+ FRAMES A
4
+ A> = 0>
5
+ D>> = EXPRESS(1>>, A)
6
+
7
+ POINTS PO{2}
8
+ PARTICLES P{2}
9
+ MOTIONVARIABLES' C{3}'
10
+ BODIES R
11
+ P_P1_PO2> = C1*A1>
12
+ V> = 2*P_P1_PO2> + C2*A2>
13
+
14
+ W_A_N> = C3*A3>
15
+ V> = 2*W_A_N> + C2*A2>
16
+ W_R_N> = C3*A3>
17
+ V> = 2*W_R_N> + C2*A2>
18
+
19
+ ALF_A_N> = DT(W_A_N>, A)
20
+ V> = 2*ALF_A_N> + C2*A2>
21
+
22
+ V_P1_A> = C1*A1> + C3*A2>
23
+ A_RO_N> = C2*A2>
24
+ V_A> = CROSS(A_RO_N>, V_P1_A>)
25
+
26
+ X_B_C> = V_A>
27
+ X_B_D> = 2*X_B_C>
28
+ A_B_C_D_E> = X_B_D>*2
29
+
30
+ A_B_C = 2*C1*C2*C3
31
+ A_B_C += 2*C1
32
+ A_B_C := 3*C1
33
+
34
+ MOTIONVARIABLES' Q{2}', U{2}'
35
+ Q1' = U1
36
+ Q2' = U2
37
+
38
+ VARIABLES X'', Y''
39
+ SPECIFIED YY
40
+ Y'' = X*X'^2 + 1
41
+ YY = X*X'^2 + 1
42
+
43
+ M[1] = 2*X
44
+ M[2] = 2*Y
45
+ A = 2*M[1]
46
+
47
+ M = [1,2,3;4,5,6;7,8,9]
48
+ M[1, 2] = 5
49
+ A = M[1, 2]*2
50
+
51
+ FORCE_RO> = Q1*N1>
52
+ TORQUE_A> = Q2*N3>
53
+ FORCE_RO> = Q2*N2>
54
+ F> = FORCE_RO>*2
llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """Used for translating C source code into a SymPy expression"""
llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (258 Bytes). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/__pycache__/c_parser.cpython-310.pyc ADDED
Binary file (26.2 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/c/c_parser.py ADDED
@@ -0,0 +1,1090 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.external import import_module
2
+ import os
3
+
4
+ cin = import_module('clang.cindex', import_kwargs = {'fromlist': ['cindex']})
5
+
6
+ """
7
+ This module contains all the necessary Classes and Function used to Parse C and
8
+ C++ code into SymPy expression
9
+ The module serves as a backend for SymPyExpression to parse C code
10
+ It is also dependent on Clang's AST and SymPy's Codegen AST.
11
+ The module only supports the features currently supported by the Clang and
12
+ codegen AST which will be updated as the development of codegen AST and this
13
+ module progresses.
14
+ You might find unexpected bugs and exceptions while using the module, feel free
15
+ to report them to the SymPy Issue Tracker
16
+
17
+ Features Supported
18
+ ==================
19
+
20
+ - Variable Declarations (integers and reals)
21
+ - Assignment (using integer & floating literal and function calls)
22
+ - Function Definitions and Declaration
23
+ - Function Calls
24
+ - Compound statements, Return statements
25
+
26
+ Notes
27
+ =====
28
+
29
+ The module is dependent on an external dependency which needs to be installed
30
+ to use the features of this module.
31
+
32
+ Clang: The C and C++ compiler which is used to extract an AST from the provided
33
+ C source code.
34
+
35
+ References
36
+ ==========
37
+
38
+ .. [1] https://github.com/sympy/sympy/issues
39
+ .. [2] https://clang.llvm.org/docs/
40
+ .. [3] https://clang.llvm.org/docs/IntroductionToTheClangAST.html
41
+
42
+ """
43
+
44
+ if cin:
45
+ from sympy.codegen.ast import (Variable, Integer, Float,
46
+ FunctionPrototype, FunctionDefinition, FunctionCall,
47
+ none, Return, Assignment, intc, int8, int16, int64,
48
+ uint8, uint16, uint32, uint64, float32, float64, float80,
49
+ aug_assign, bool_, While, CodeBlock)
50
+ from sympy.codegen.cnodes import (PreDecrement, PostDecrement,
51
+ PreIncrement, PostIncrement)
52
+ from sympy.core import Add, Mod, Mul, Pow, Rel
53
+ from sympy.logic.boolalg import And, as_Boolean, Not, Or
54
+ from sympy.core.symbol import Symbol
55
+ from sympy.core.sympify import sympify
56
+ from sympy.logic.boolalg import (false, true)
57
+ import sys
58
+ import tempfile
59
+
60
+ class BaseParser:
61
+ """Base Class for the C parser"""
62
+
63
+ def __init__(self):
64
+ """Initializes the Base parser creating a Clang AST index"""
65
+ self.index = cin.Index.create()
66
+
67
+ def diagnostics(self, out):
68
+ """Diagostics function for the Clang AST"""
69
+ for diag in self.tu.diagnostics:
70
+ print('%s %s (line %s, col %s) %s' % (
71
+ {
72
+ 4: 'FATAL',
73
+ 3: 'ERROR',
74
+ 2: 'WARNING',
75
+ 1: 'NOTE',
76
+ 0: 'IGNORED',
77
+ }[diag.severity],
78
+ diag.location.file,
79
+ diag.location.line,
80
+ diag.location.column,
81
+ diag.spelling
82
+ ), file=out)
83
+
84
+ class CCodeConverter(BaseParser):
85
+ """The Code Convereter for Clang AST
86
+
87
+ The converter object takes the C source code or file as input and
88
+ converts them to SymPy Expressions.
89
+ """
90
+
91
+ def __init__(self):
92
+ """Initializes the code converter"""
93
+ super().__init__()
94
+ self._py_nodes = []
95
+ self._data_types = {
96
+ "void": {
97
+ cin.TypeKind.VOID: none
98
+ },
99
+ "bool": {
100
+ cin.TypeKind.BOOL: bool_
101
+ },
102
+ "int": {
103
+ cin.TypeKind.SCHAR: int8,
104
+ cin.TypeKind.SHORT: int16,
105
+ cin.TypeKind.INT: intc,
106
+ cin.TypeKind.LONG: int64,
107
+ cin.TypeKind.UCHAR: uint8,
108
+ cin.TypeKind.USHORT: uint16,
109
+ cin.TypeKind.UINT: uint32,
110
+ cin.TypeKind.ULONG: uint64
111
+ },
112
+ "float": {
113
+ cin.TypeKind.FLOAT: float32,
114
+ cin.TypeKind.DOUBLE: float64,
115
+ cin.TypeKind.LONGDOUBLE: float80
116
+ }
117
+ }
118
+
119
+ def parse(self, filenames, flags):
120
+ """Function to parse a file with C source code
121
+
122
+ It takes the filename as an attribute and creates a Clang AST
123
+ Translation Unit parsing the file.
124
+ Then the transformation function is called on the translation unit,
125
+ whose reults are collected into a list which is returned by the
126
+ function.
127
+
128
+ Parameters
129
+ ==========
130
+
131
+ filenames : string
132
+ Path to the C file to be parsed
133
+
134
+ flags: list
135
+ Arguments to be passed to Clang while parsing the C code
136
+
137
+ Returns
138
+ =======
139
+
140
+ py_nodes: list
141
+ A list of SymPy AST nodes
142
+
143
+ """
144
+ filename = os.path.abspath(filenames)
145
+ self.tu = self.index.parse(
146
+ filename,
147
+ args=flags,
148
+ options=cin.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD
149
+ )
150
+ for child in self.tu.cursor.get_children():
151
+ if child.kind == cin.CursorKind.VAR_DECL:
152
+ self._py_nodes.append(self.transform(child))
153
+ elif (child.kind == cin.CursorKind.FUNCTION_DECL):
154
+ self._py_nodes.append(self.transform(child))
155
+ else:
156
+ pass
157
+ return self._py_nodes
158
+
159
+ def parse_str(self, source, flags):
160
+ """Function to parse a string with C source code
161
+
162
+ It takes the source code as an attribute, stores it in a temporary
163
+ file and creates a Clang AST Translation Unit parsing the file.
164
+ Then the transformation function is called on the translation unit,
165
+ whose reults are collected into a list which is returned by the
166
+ function.
167
+
168
+ Parameters
169
+ ==========
170
+
171
+ source : string
172
+ Path to the C file to be parsed
173
+
174
+ flags: list
175
+ Arguments to be passed to Clang while parsing the C code
176
+
177
+ Returns
178
+ =======
179
+
180
+ py_nodes: list
181
+ A list of SymPy AST nodes
182
+
183
+ """
184
+ file = tempfile.NamedTemporaryFile(mode = 'w+', suffix = '.cpp')
185
+ file.write(source)
186
+ file.seek(0)
187
+ self.tu = self.index.parse(
188
+ file.name,
189
+ args=flags,
190
+ options=cin.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD
191
+ )
192
+ file.close()
193
+ for child in self.tu.cursor.get_children():
194
+ if child.kind == cin.CursorKind.VAR_DECL:
195
+ self._py_nodes.append(self.transform(child))
196
+ elif (child.kind == cin.CursorKind.FUNCTION_DECL):
197
+ self._py_nodes.append(self.transform(child))
198
+ else:
199
+ pass
200
+ return self._py_nodes
201
+
202
+ def transform(self, node):
203
+ """Transformation Function for Clang AST nodes
204
+
205
+ It determines the kind of node and calls the respective
206
+ transformation function for that node.
207
+
208
+ Raises
209
+ ======
210
+
211
+ NotImplementedError : if the transformation for the provided node
212
+ is not implemented
213
+
214
+ """
215
+ try:
216
+ handler = getattr(self, 'transform_%s' % node.kind.name.lower())
217
+ except AttributeError:
218
+ print(
219
+ "Ignoring node of type %s (%s)" % (
220
+ node.kind,
221
+ ' '.join(
222
+ t.spelling for t in node.get_tokens())
223
+ ),
224
+ file=sys.stderr
225
+ )
226
+ handler = None
227
+ if handler:
228
+ result = handler(node)
229
+ return result
230
+
231
+ def transform_var_decl(self, node):
232
+ """Transformation Function for Variable Declaration
233
+
234
+ Used to create nodes for variable declarations and assignments with
235
+ values or function call for the respective nodes in the clang AST
236
+
237
+ Returns
238
+ =======
239
+
240
+ A variable node as Declaration, with the initial value if given
241
+
242
+ Raises
243
+ ======
244
+
245
+ NotImplementedError : if called for data types not currently
246
+ implemented
247
+
248
+ Notes
249
+ =====
250
+
251
+ The function currently supports following data types:
252
+
253
+ Boolean:
254
+ bool, _Bool
255
+
256
+ Integer:
257
+ 8-bit: signed char and unsigned char
258
+ 16-bit: short, short int, signed short,
259
+ signed short int, unsigned short, unsigned short int
260
+ 32-bit: int, signed int, unsigned int
261
+ 64-bit: long, long int, signed long,
262
+ signed long int, unsigned long, unsigned long int
263
+
264
+ Floating point:
265
+ Single Precision: float
266
+ Double Precision: double
267
+ Extended Precision: long double
268
+
269
+ """
270
+ if node.type.kind in self._data_types["int"]:
271
+ type = self._data_types["int"][node.type.kind]
272
+ elif node.type.kind in self._data_types["float"]:
273
+ type = self._data_types["float"][node.type.kind]
274
+ elif node.type.kind in self._data_types["bool"]:
275
+ type = self._data_types["bool"][node.type.kind]
276
+ else:
277
+ raise NotImplementedError("Only bool, int "
278
+ "and float are supported")
279
+ try:
280
+ children = node.get_children()
281
+ child = next(children)
282
+ #ignoring namespace and type details for the variable
283
+ while child.kind == cin.CursorKind.NAMESPACE_REF:
284
+ child = next(children)
285
+
286
+ while child.kind == cin.CursorKind.TYPE_REF:
287
+ child = next(children)
288
+
289
+ val = self.transform(child)
290
+
291
+ supported_rhs = [
292
+ cin.CursorKind.INTEGER_LITERAL,
293
+ cin.CursorKind.FLOATING_LITERAL,
294
+ cin.CursorKind.UNEXPOSED_EXPR,
295
+ cin.CursorKind.BINARY_OPERATOR,
296
+ cin.CursorKind.PAREN_EXPR,
297
+ cin.CursorKind.UNARY_OPERATOR,
298
+ cin.CursorKind.CXX_BOOL_LITERAL_EXPR
299
+ ]
300
+
301
+ if child.kind in supported_rhs:
302
+ if isinstance(val, str):
303
+ value = Symbol(val)
304
+ elif isinstance(val, bool):
305
+ if node.type.kind in self._data_types["int"]:
306
+ value = Integer(0) if val == False else Integer(1)
307
+ elif node.type.kind in self._data_types["float"]:
308
+ value = Float(0.0) if val == False else Float(1.0)
309
+ elif node.type.kind in self._data_types["bool"]:
310
+ value = sympify(val)
311
+ elif isinstance(val, (Integer, int, Float, float)):
312
+ if node.type.kind in self._data_types["int"]:
313
+ value = Integer(val)
314
+ elif node.type.kind in self._data_types["float"]:
315
+ value = Float(val)
316
+ elif node.type.kind in self._data_types["bool"]:
317
+ value = sympify(bool(val))
318
+ else:
319
+ value = val
320
+
321
+ return Variable(
322
+ node.spelling
323
+ ).as_Declaration(
324
+ type = type,
325
+ value = value
326
+ )
327
+
328
+ elif child.kind == cin.CursorKind.CALL_EXPR:
329
+ return Variable(
330
+ node.spelling
331
+ ).as_Declaration(
332
+ value = val
333
+ )
334
+
335
+ else:
336
+ raise NotImplementedError("Given "
337
+ "variable declaration \"{}\" "
338
+ "is not possible to parse yet!"
339
+ .format(" ".join(
340
+ t.spelling for t in node.get_tokens()
341
+ )
342
+ ))
343
+
344
+ except StopIteration:
345
+ return Variable(
346
+ node.spelling
347
+ ).as_Declaration(
348
+ type = type
349
+ )
350
+
351
+ def transform_function_decl(self, node):
352
+ """Transformation Function For Function Declaration
353
+
354
+ Used to create nodes for function declarations and definitions for
355
+ the respective nodes in the clang AST
356
+
357
+ Returns
358
+ =======
359
+
360
+ function : Codegen AST node
361
+ - FunctionPrototype node if function body is not present
362
+ - FunctionDefinition node if the function body is present
363
+
364
+
365
+ """
366
+
367
+ if node.result_type.kind in self._data_types["int"]:
368
+ ret_type = self._data_types["int"][node.result_type.kind]
369
+ elif node.result_type.kind in self._data_types["float"]:
370
+ ret_type = self._data_types["float"][node.result_type.kind]
371
+ elif node.result_type.kind in self._data_types["bool"]:
372
+ ret_type = self._data_types["bool"][node.result_type.kind]
373
+ elif node.result_type.kind in self._data_types["void"]:
374
+ ret_type = self._data_types["void"][node.result_type.kind]
375
+ else:
376
+ raise NotImplementedError("Only void, bool, int "
377
+ "and float are supported")
378
+ body = []
379
+ param = []
380
+ try:
381
+ children = node.get_children()
382
+ child = next(children)
383
+
384
+ # If the node has any children, the first children will be the
385
+ # return type and namespace for the function declaration. These
386
+ # nodes can be ignored.
387
+ while child.kind == cin.CursorKind.NAMESPACE_REF:
388
+ child = next(children)
389
+
390
+ while child.kind == cin.CursorKind.TYPE_REF:
391
+ child = next(children)
392
+
393
+
394
+ # Subsequent nodes will be the parameters for the function.
395
+ try:
396
+ while True:
397
+ decl = self.transform(child)
398
+ if (child.kind == cin.CursorKind.PARM_DECL):
399
+ param.append(decl)
400
+ elif (child.kind == cin.CursorKind.COMPOUND_STMT):
401
+ for val in decl:
402
+ body.append(val)
403
+ else:
404
+ body.append(decl)
405
+ child = next(children)
406
+ except StopIteration:
407
+ pass
408
+ except StopIteration:
409
+ pass
410
+
411
+ if body == []:
412
+ function = FunctionPrototype(
413
+ return_type = ret_type,
414
+ name = node.spelling,
415
+ parameters = param
416
+ )
417
+ else:
418
+ function = FunctionDefinition(
419
+ return_type = ret_type,
420
+ name = node.spelling,
421
+ parameters = param,
422
+ body = body
423
+ )
424
+ return function
425
+
426
+ def transform_parm_decl(self, node):
427
+ """Transformation function for Parameter Declaration
428
+
429
+ Used to create parameter nodes for the required functions for the
430
+ respective nodes in the clang AST
431
+
432
+ Returns
433
+ =======
434
+
435
+ param : Codegen AST Node
436
+ Variable node with the value and type of the variable
437
+
438
+ Raises
439
+ ======
440
+
441
+ ValueError if multiple children encountered in the parameter node
442
+
443
+ """
444
+ if node.type.kind in self._data_types["int"]:
445
+ type = self._data_types["int"][node.type.kind]
446
+ elif node.type.kind in self._data_types["float"]:
447
+ type = self._data_types["float"][node.type.kind]
448
+ elif node.type.kind in self._data_types["bool"]:
449
+ type = self._data_types["bool"][node.type.kind]
450
+ else:
451
+ raise NotImplementedError("Only bool, int "
452
+ "and float are supported")
453
+ try:
454
+ children = node.get_children()
455
+ child = next(children)
456
+
457
+ # Any namespace nodes can be ignored
458
+ while child.kind in [cin.CursorKind.NAMESPACE_REF,
459
+ cin.CursorKind.TYPE_REF,
460
+ cin.CursorKind.TEMPLATE_REF]:
461
+ child = next(children)
462
+
463
+ # If there is a child, it is the default value of the parameter.
464
+ lit = self.transform(child)
465
+ if node.type.kind in self._data_types["int"]:
466
+ val = Integer(lit)
467
+ elif node.type.kind in self._data_types["float"]:
468
+ val = Float(lit)
469
+ elif node.type.kind in self._data_types["bool"]:
470
+ val = sympify(bool(lit))
471
+ else:
472
+ raise NotImplementedError("Only bool, int "
473
+ "and float are supported")
474
+
475
+ param = Variable(
476
+ node.spelling
477
+ ).as_Declaration(
478
+ type = type,
479
+ value = val
480
+ )
481
+ except StopIteration:
482
+ param = Variable(
483
+ node.spelling
484
+ ).as_Declaration(
485
+ type = type
486
+ )
487
+
488
+ try:
489
+ self.transform(next(children))
490
+ raise ValueError("Can't handle multiple children on parameter")
491
+ except StopIteration:
492
+ pass
493
+
494
+ return param
495
+
496
+ def transform_integer_literal(self, node):
497
+ """Transformation function for integer literal
498
+
499
+ Used to get the value and type of the given integer literal.
500
+
501
+ Returns
502
+ =======
503
+
504
+ val : list
505
+ List with two arguments type and Value
506
+ type contains the type of the integer
507
+ value contains the value stored in the variable
508
+
509
+ Notes
510
+ =====
511
+
512
+ Only Base Integer type supported for now
513
+
514
+ """
515
+ try:
516
+ value = next(node.get_tokens()).spelling
517
+ except StopIteration:
518
+ # No tokens
519
+ value = node.literal
520
+ return int(value)
521
+
522
+ def transform_floating_literal(self, node):
523
+ """Transformation function for floating literal
524
+
525
+ Used to get the value and type of the given floating literal.
526
+
527
+ Returns
528
+ =======
529
+
530
+ val : list
531
+ List with two arguments type and Value
532
+ type contains the type of float
533
+ value contains the value stored in the variable
534
+
535
+ Notes
536
+ =====
537
+
538
+ Only Base Float type supported for now
539
+
540
+ """
541
+ try:
542
+ value = next(node.get_tokens()).spelling
543
+ except (StopIteration, ValueError):
544
+ # No tokens
545
+ value = node.literal
546
+ return float(value)
547
+
548
+ def transform_string_literal(self, node):
549
+ #TODO: No string type in AST
550
+ #type =
551
+ #try:
552
+ # value = next(node.get_tokens()).spelling
553
+ #except (StopIteration, ValueError):
554
+ # No tokens
555
+ # value = node.literal
556
+ #val = [type, value]
557
+ #return val
558
+ pass
559
+
560
+ def transform_character_literal(self, node):
561
+ """Transformation function for character literal
562
+
563
+ Used to get the value of the given character literal.
564
+
565
+ Returns
566
+ =======
567
+
568
+ val : int
569
+ val contains the ascii value of the character literal
570
+
571
+ Notes
572
+ =====
573
+
574
+ Only for cases where character is assigned to a integer value,
575
+ since character literal is not in SymPy AST
576
+
577
+ """
578
+ try:
579
+ value = next(node.get_tokens()).spelling
580
+ except (StopIteration, ValueError):
581
+ # No tokens
582
+ value = node.literal
583
+ return ord(str(value[1]))
584
+
585
+ def transform_cxx_bool_literal_expr(self, node):
586
+ """Transformation function for boolean literal
587
+
588
+ Used to get the value of the given boolean literal.
589
+
590
+ Returns
591
+ =======
592
+
593
+ value : bool
594
+ value contains the boolean value of the variable
595
+
596
+ """
597
+ try:
598
+ value = next(node.get_tokens()).spelling
599
+ except (StopIteration, ValueError):
600
+ value = node.literal
601
+ return True if value == 'true' else False
602
+
603
+ def transform_unexposed_decl(self,node):
604
+ """Transformation function for unexposed declarations"""
605
+ pass
606
+
607
+ def transform_unexposed_expr(self, node):
608
+ """Transformation function for unexposed expression
609
+
610
+ Unexposed expressions are used to wrap float, double literals and
611
+ expressions
612
+
613
+ Returns
614
+ =======
615
+
616
+ expr : Codegen AST Node
617
+ the result from the wrapped expression
618
+
619
+ None : NoneType
620
+ No childs are found for the node
621
+
622
+ Raises
623
+ ======
624
+
625
+ ValueError if the expression contains multiple children
626
+
627
+ """
628
+ # Ignore unexposed nodes; pass whatever is the first
629
+ # (and should be only) child unaltered.
630
+ try:
631
+ children = node.get_children()
632
+ expr = self.transform(next(children))
633
+ except StopIteration:
634
+ return None
635
+
636
+ try:
637
+ next(children)
638
+ raise ValueError("Unexposed expression has > 1 children.")
639
+ except StopIteration:
640
+ pass
641
+
642
+ return expr
643
+
644
+ def transform_decl_ref_expr(self, node):
645
+ """Returns the name of the declaration reference"""
646
+ return node.spelling
647
+
648
+ def transform_call_expr(self, node):
649
+ """Transformation function for a call expression
650
+
651
+ Used to create function call nodes for the function calls present
652
+ in the C code
653
+
654
+ Returns
655
+ =======
656
+
657
+ FunctionCall : Codegen AST Node
658
+ FunctionCall node with parameters if any parameters are present
659
+
660
+ """
661
+ param = []
662
+ children = node.get_children()
663
+ child = next(children)
664
+
665
+ while child.kind == cin.CursorKind.NAMESPACE_REF:
666
+ child = next(children)
667
+ while child.kind == cin.CursorKind.TYPE_REF:
668
+ child = next(children)
669
+
670
+ first_child = self.transform(child)
671
+ try:
672
+ for child in children:
673
+ arg = self.transform(child)
674
+ if (child.kind == cin.CursorKind.INTEGER_LITERAL):
675
+ param.append(Integer(arg))
676
+ elif (child.kind == cin.CursorKind.FLOATING_LITERAL):
677
+ param.append(Float(arg))
678
+ else:
679
+ param.append(arg)
680
+ return FunctionCall(first_child, param)
681
+
682
+ except StopIteration:
683
+ return FunctionCall(first_child)
684
+
685
+ def transform_return_stmt(self, node):
686
+ """Returns the Return Node for a return statement"""
687
+ return Return(next(node.get_children()).spelling)
688
+
689
+ def transform_compound_stmt(self, node):
690
+ """Transformation function for compond statemets
691
+
692
+ Returns
693
+ =======
694
+
695
+ expr : list
696
+ list of Nodes for the expressions present in the statement
697
+
698
+ None : NoneType
699
+ if the compound statement is empty
700
+
701
+ """
702
+ try:
703
+ expr = []
704
+ children = node.get_children()
705
+ for child in children:
706
+ expr.append(self.transform(child))
707
+ except StopIteration:
708
+ return None
709
+ return expr
710
+
711
+ def transform_decl_stmt(self, node):
712
+ """Transformation function for declaration statements
713
+
714
+ These statements are used to wrap different kinds of declararions
715
+ like variable or function declaration
716
+ The function calls the transformer function for the child of the
717
+ given node
718
+
719
+ Returns
720
+ =======
721
+
722
+ statement : Codegen AST Node
723
+ contains the node returned by the children node for the type of
724
+ declaration
725
+
726
+ Raises
727
+ ======
728
+
729
+ ValueError if multiple children present
730
+
731
+ """
732
+ try:
733
+ children = node.get_children()
734
+ statement = self.transform(next(children))
735
+ except StopIteration:
736
+ pass
737
+
738
+ try:
739
+ self.transform(next(children))
740
+ raise ValueError("Don't know how to handle multiple statements")
741
+ except StopIteration:
742
+ pass
743
+
744
+ return statement
745
+
746
+ def transform_paren_expr(self, node):
747
+ """Transformation function for Parenthesized expressions
748
+
749
+ Returns the result from its children nodes
750
+
751
+ """
752
+ return self.transform(next(node.get_children()))
753
+
754
+ def transform_compound_assignment_operator(self, node):
755
+ """Transformation function for handling shorthand operators
756
+
757
+ Returns
758
+ =======
759
+
760
+ augmented_assignment_expression: Codegen AST node
761
+ shorthand assignment expression represented as Codegen AST
762
+
763
+ Raises
764
+ ======
765
+
766
+ NotImplementedError
767
+ If the shorthand operator for bitwise operators
768
+ (~=, ^=, &=, |=, <<=, >>=) is encountered
769
+
770
+ """
771
+ return self.transform_binary_operator(node)
772
+
773
+ def transform_unary_operator(self, node):
774
+ """Transformation function for handling unary operators
775
+
776
+ Returns
777
+ =======
778
+
779
+ unary_expression: Codegen AST node
780
+ simplified unary expression represented as Codegen AST
781
+
782
+ Raises
783
+ ======
784
+
785
+ NotImplementedError
786
+ If dereferencing operator(*), address operator(&) or
787
+ bitwise NOT operator(~) is encountered
788
+
789
+ """
790
+ # supported operators list
791
+ operators_list = ['+', '-', '++', '--', '!']
792
+ tokens = list(node.get_tokens())
793
+
794
+ # it can be either pre increment/decrement or any other operator from the list
795
+ if tokens[0].spelling in operators_list:
796
+ child = self.transform(next(node.get_children()))
797
+ # (decl_ref) e.g.; int a = ++b; or simply ++b;
798
+ if isinstance(child, str):
799
+ if tokens[0].spelling == '+':
800
+ return Symbol(child)
801
+ if tokens[0].spelling == '-':
802
+ return Mul(Symbol(child), -1)
803
+ if tokens[0].spelling == '++':
804
+ return PreIncrement(Symbol(child))
805
+ if tokens[0].spelling == '--':
806
+ return PreDecrement(Symbol(child))
807
+ if tokens[0].spelling == '!':
808
+ return Not(Symbol(child))
809
+ # e.g.; int a = -1; or int b = -(1 + 2);
810
+ else:
811
+ if tokens[0].spelling == '+':
812
+ return child
813
+ if tokens[0].spelling == '-':
814
+ return Mul(child, -1)
815
+ if tokens[0].spelling == '!':
816
+ return Not(sympify(bool(child)))
817
+
818
+ # it can be either post increment/decrement
819
+ # since variable name is obtained in token[0].spelling
820
+ elif tokens[1].spelling in ['++', '--']:
821
+ child = self.transform(next(node.get_children()))
822
+ if tokens[1].spelling == '++':
823
+ return PostIncrement(Symbol(child))
824
+ if tokens[1].spelling == '--':
825
+ return PostDecrement(Symbol(child))
826
+ else:
827
+ raise NotImplementedError("Dereferencing operator, "
828
+ "Address operator and bitwise NOT operator "
829
+ "have not been implemented yet!")
830
+
831
+ def transform_binary_operator(self, node):
832
+ """Transformation function for handling binary operators
833
+
834
+ Returns
835
+ =======
836
+
837
+ binary_expression: Codegen AST node
838
+ simplified binary expression represented as Codegen AST
839
+
840
+ Raises
841
+ ======
842
+
843
+ NotImplementedError
844
+ If a bitwise operator or
845
+ unary operator(which is a child of any binary
846
+ operator in Clang AST) is encountered
847
+
848
+ """
849
+ # get all the tokens of assignment
850
+ # and store it in the tokens list
851
+ tokens = list(node.get_tokens())
852
+
853
+ # supported operators list
854
+ operators_list = ['+', '-', '*', '/', '%','=',
855
+ '>', '>=', '<', '<=', '==', '!=', '&&', '||', '+=', '-=',
856
+ '*=', '/=', '%=']
857
+
858
+ # this stack will contain variable content
859
+ # and type of variable in the rhs
860
+ combined_variables_stack = []
861
+
862
+ # this stack will contain operators
863
+ # to be processed in the rhs
864
+ operators_stack = []
865
+
866
+ # iterate through every token
867
+ for token in tokens:
868
+ # token is either '(', ')' or
869
+ # any of the supported operators from the operator list
870
+ if token.kind == cin.TokenKind.PUNCTUATION:
871
+
872
+ # push '(' to the operators stack
873
+ if token.spelling == '(':
874
+ operators_stack.append('(')
875
+
876
+ elif token.spelling == ')':
877
+ # keep adding the expression to the
878
+ # combined variables stack unless
879
+ # '(' is found
880
+ while (operators_stack
881
+ and operators_stack[-1] != '('):
882
+ if len(combined_variables_stack) < 2:
883
+ raise NotImplementedError(
884
+ "Unary operators as a part of "
885
+ "binary operators is not "
886
+ "supported yet!")
887
+ rhs = combined_variables_stack.pop()
888
+ lhs = combined_variables_stack.pop()
889
+ operator = operators_stack.pop()
890
+ combined_variables_stack.append(
891
+ self.perform_operation(
892
+ lhs, rhs, operator))
893
+
894
+ # pop '('
895
+ operators_stack.pop()
896
+
897
+ # token is an operator (supported)
898
+ elif token.spelling in operators_list:
899
+ while (operators_stack
900
+ and self.priority_of(token.spelling)
901
+ <= self.priority_of(
902
+ operators_stack[-1])):
903
+ if len(combined_variables_stack) < 2:
904
+ raise NotImplementedError(
905
+ "Unary operators as a part of "
906
+ "binary operators is not "
907
+ "supported yet!")
908
+ rhs = combined_variables_stack.pop()
909
+ lhs = combined_variables_stack.pop()
910
+ operator = operators_stack.pop()
911
+ combined_variables_stack.append(
912
+ self.perform_operation(
913
+ lhs, rhs, operator))
914
+
915
+ # push current operator
916
+ operators_stack.append(token.spelling)
917
+
918
+ # token is a bitwise operator
919
+ elif token.spelling in ['&', '|', '^', '<<', '>>']:
920
+ raise NotImplementedError(
921
+ "Bitwise operator has not been "
922
+ "implemented yet!")
923
+
924
+ # token is a shorthand bitwise operator
925
+ elif token.spelling in ['&=', '|=', '^=', '<<=',
926
+ '>>=']:
927
+ raise NotImplementedError(
928
+ "Shorthand bitwise operator has not been "
929
+ "implemented yet!")
930
+ else:
931
+ raise NotImplementedError(
932
+ "Given token {} is not implemented yet!"
933
+ .format(token.spelling))
934
+
935
+ # token is an identifier(variable)
936
+ elif token.kind == cin.TokenKind.IDENTIFIER:
937
+ combined_variables_stack.append(
938
+ [token.spelling, 'identifier'])
939
+
940
+ # token is a literal
941
+ elif token.kind == cin.TokenKind.LITERAL:
942
+ combined_variables_stack.append(
943
+ [token.spelling, 'literal'])
944
+
945
+ # token is a keyword, either true or false
946
+ elif (token.kind == cin.TokenKind.KEYWORD
947
+ and token.spelling in ['true', 'false']):
948
+ combined_variables_stack.append(
949
+ [token.spelling, 'boolean'])
950
+ else:
951
+ raise NotImplementedError(
952
+ "Given token {} is not implemented yet!"
953
+ .format(token.spelling))
954
+
955
+ # process remaining operators
956
+ while operators_stack:
957
+ if len(combined_variables_stack) < 2:
958
+ raise NotImplementedError(
959
+ "Unary operators as a part of "
960
+ "binary operators is not "
961
+ "supported yet!")
962
+ rhs = combined_variables_stack.pop()
963
+ lhs = combined_variables_stack.pop()
964
+ operator = operators_stack.pop()
965
+ combined_variables_stack.append(
966
+ self.perform_operation(lhs, rhs, operator))
967
+
968
+ return combined_variables_stack[-1][0]
969
+
970
+ def priority_of(self, op):
971
+ """To get the priority of given operator"""
972
+ if op in ['=', '+=', '-=', '*=', '/=', '%=']:
973
+ return 1
974
+ if op in ['&&', '||']:
975
+ return 2
976
+ if op in ['<', '<=', '>', '>=', '==', '!=']:
977
+ return 3
978
+ if op in ['+', '-']:
979
+ return 4
980
+ if op in ['*', '/', '%']:
981
+ return 5
982
+ return 0
983
+
984
+ def perform_operation(self, lhs, rhs, op):
985
+ """Performs operation supported by the SymPy core
986
+
987
+ Returns
988
+ =======
989
+
990
+ combined_variable: list
991
+ contains variable content and type of variable
992
+
993
+ """
994
+ lhs_value = self.get_expr_for_operand(lhs)
995
+ rhs_value = self.get_expr_for_operand(rhs)
996
+ if op == '+':
997
+ return [Add(lhs_value, rhs_value), 'expr']
998
+ if op == '-':
999
+ return [Add(lhs_value, -rhs_value), 'expr']
1000
+ if op == '*':
1001
+ return [Mul(lhs_value, rhs_value), 'expr']
1002
+ if op == '/':
1003
+ return [Mul(lhs_value, Pow(rhs_value, Integer(-1))), 'expr']
1004
+ if op == '%':
1005
+ return [Mod(lhs_value, rhs_value), 'expr']
1006
+ if op in ['<', '<=', '>', '>=', '==', '!=']:
1007
+ return [Rel(lhs_value, rhs_value, op), 'expr']
1008
+ if op == '&&':
1009
+ return [And(as_Boolean(lhs_value), as_Boolean(rhs_value)), 'expr']
1010
+ if op == '||':
1011
+ return [Or(as_Boolean(lhs_value), as_Boolean(rhs_value)), 'expr']
1012
+ if op == '=':
1013
+ return [Assignment(Variable(lhs_value), rhs_value), 'expr']
1014
+ if op in ['+=', '-=', '*=', '/=', '%=']:
1015
+ return [aug_assign(Variable(lhs_value), op[0], rhs_value), 'expr']
1016
+
1017
+ def get_expr_for_operand(self, combined_variable):
1018
+ """Gives out SymPy Codegen AST node
1019
+
1020
+ AST node returned is corresponding to
1021
+ combined variable passed.Combined variable contains
1022
+ variable content and type of variable
1023
+
1024
+ """
1025
+ if combined_variable[1] == 'identifier':
1026
+ return Symbol(combined_variable[0])
1027
+ if combined_variable[1] == 'literal':
1028
+ if '.' in combined_variable[0]:
1029
+ return Float(float(combined_variable[0]))
1030
+ else:
1031
+ return Integer(int(combined_variable[0]))
1032
+ if combined_variable[1] == 'expr':
1033
+ return combined_variable[0]
1034
+ if combined_variable[1] == 'boolean':
1035
+ return true if combined_variable[0] == 'true' else false
1036
+
1037
+ def transform_null_stmt(self, node):
1038
+ """Handles Null Statement and returns None"""
1039
+ return none
1040
+
1041
+ def transform_while_stmt(self, node):
1042
+ """Transformation function for handling while statement
1043
+
1044
+ Returns
1045
+ =======
1046
+
1047
+ while statement : Codegen AST Node
1048
+ contains the while statement node having condition and
1049
+ statement block
1050
+
1051
+ """
1052
+ children = node.get_children()
1053
+
1054
+ condition = self.transform(next(children))
1055
+ statements = self.transform(next(children))
1056
+
1057
+ if isinstance(statements, list):
1058
+ statement_block = CodeBlock(*statements)
1059
+ else:
1060
+ statement_block = CodeBlock(statements)
1061
+
1062
+ return While(condition, statement_block)
1063
+
1064
+
1065
+
1066
+ else:
1067
+ class CCodeConverter(): # type: ignore
1068
+ def __init__(self, *args, **kwargs):
1069
+ raise ImportError("Module not Installed")
1070
+
1071
+
1072
+ def parse_c(source):
1073
+ """Function for converting a C source code
1074
+
1075
+ The function reads the source code present in the given file and parses it
1076
+ to give out SymPy Expressions
1077
+
1078
+ Returns
1079
+ =======
1080
+
1081
+ src : list
1082
+ List of Python expression strings
1083
+
1084
+ """
1085
+ converter = CCodeConverter()
1086
+ if os.path.exists(source):
1087
+ src = converter.parse(source, flags = [])
1088
+ else:
1089
+ src = converter.parse_str(source, flags = [])
1090
+ return src
llmeval-env/lib/python3.10/site-packages/sympy/parsing/fortran/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """Used for translating Fortran source code into a SymPy expression. """
llmeval-env/lib/python3.10/site-packages/sympy/parsing/fortran/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (272 Bytes). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/parsing/fortran/__pycache__/fortran_parser.cpython-310.pyc ADDED
Binary file (8.79 kB). View file