1- using SymbolicUtils
2- using SymbolicUtils. Rewriters
3- using Symbolics
4- # using SymbolicNumericIntegration
51
6- using PyCall
7- sympy = pyimport (" sympy" )
82
93@variables x a b c d e p t m n z
104
@@ -15,16 +9,18 @@ function convert_axiom(name::AbstractString)
159
1610 D = Dict {Any,Int} ()
1711
18- for (lineno,line) in enumerate (readlines (fd))
12+ for (lineno, line) in enumerate (readlines (fd))
1913 line = strip (line)
20- if length (line) < 3 || line[1 : 2 ] == " --" continue end
14+ if length (line) < 3 || line[1 : 2 ] == " --"
15+ continue
16+ end
2117 ma = match (re, line)
2218
2319 if ma != nothing
2420 line = ma. match
2521 println (line)
2622 line = replace (line, " %e" => MathConstants. e)
27- line = replace (line, " %i" => im)
23+ line = replace (line, " %i" => im)
2824
2925 try
3026 expr = Meta. parse (line)
@@ -41,7 +37,7 @@ function convert_axiom(name::AbstractString)
4137 P[1 ] = substitute (P[1 ], D)
4238 P[4 ] = substitute (P[4 ], D)
4339
44- printstyled (length (L)+ 1 , " : " ; color= :red )
40+ printstyled (length (L) + 1 , " : " ; color= :red )
4541 println (P[1 ])
4642 push! (L, P)
4743 catch err
@@ -83,16 +79,16 @@ function convert_axiom(sym)
8379 " Wester Problems.input"
8480 end
8581
86- name = joinpath (" test/0" , name)
87- println (name)
88- return convert_axiom (name)
82+ name = joinpath (" test/0" , name)
83+ println (name)
84+ return convert_axiom (name)
8985end
9086
9187function test_point (complex_plane, radius)
9288 if complex_plane
93- return radius * sqrt (rand ()) * cis (2 π* rand ())
89+ return radius * sqrt (rand ()) * cis (2 π * rand ())
9490 else
95- return Complex (radius * (2 * rand () - 1 ))
91+ return Complex (radius * (2 * rand () - 1 ))
9692 end
9793end
9894
@@ -116,36 +112,37 @@ function test_axiom(L, try_sympy=true; kwargs...)
116112 n_diff = 0
117113 n_catch = 0
118114
119- for (i,p) in enumerate (L)
115+ for (i, p) in enumerate (L)
120116 # try
121- printstyled (i, " : " ; color= :yellow )
122- eq = p[1 ]
123- x = p[2 ]
124- ans = p[4 ]
125-
126- printstyled (eq, ' \n ' ; color= :green )
127- sol = integrate (eq, x; kwargs... )[1 ]
128-
129- println (" >>>>" , sol)
130-
131- if isequal (sol, 0 )
132- printstyled (" \t Failure\n " ; color= :red )
133- n_fail += 1
134- elseif accept_integral (value (sol), value (ans), x)
135- printstyled (" \t Success:\t " , sol, ' \n ' ; color= :cyan )
136- n_ok += 1
137- else
138- printstyled (" \t Discrepancy:\t " , sol, ' \n ' ; color= :yellow )
139- n_diff += 1
140- end
117+ printstyled (i, " : " ; color= :yellow )
118+ eq = p[1 ]
119+ x = p[2 ]
120+ ans = p[4 ]
121+
122+ printstyled (eq, ' \n ' ; color= :green )
123+ sol = integrate (eq, x; kwargs... )[1 ]
124+
125+ println (" >>>>" , sol)
126+
127+ if isequal (sol, 0 )
128+ printstyled (" \t Failure\n " ; color= :red )
129+ n_fail += 1
130+ elseif accept_integral (value (sol), value (ans), x)
131+ printstyled (" \t Success:\t " , sol, ' \n ' ; color= :cyan )
132+ n_ok += 1
133+ else
134+ printstyled (" \t Discrepancy:\t " , sol, ' \n ' ; color= :yellow )
135+ n_diff += 1
136+ end
141137
142- if try_sympy
143- s = pythonize (eq)
144- py = sympy. integrate (s, sympy. Symbol (string (x)))
145- printstyled (" \t SymPy :\t " , string (py)[10 : end ], ' \n ' ; color= :magenta )
146- end
138+ if try_sympy
139+ s = Symbolics. symbolics_to_sympy (s)
140+ s_x = Symbolics. symbolics_to_sympy (x)
141+ py = SymPy. integrate (s, s_x)
142+ printstyled (" \t SymPy :\t " , string (py)[10 : end ], ' \n ' ; color= :magenta )
143+ end
147144
148- printstyled (" \t Answer: \t " , ans, ' \n ' ; color= :blue )
145+ printstyled (" \t Answer: \t " , ans, ' \n ' ; color= :blue )
149146 # catch e
150147 # printstyled(i, ": ", e, '\n'; color=:red)
151148 # n_catch += 1
@@ -158,22 +155,3 @@ function test_axiom(L, try_sympy=true; kwargs...)
158155 printstyled (" Discrepancy = " , n_diff, ' \n ' ; color= :yellow )
159156 printstyled (" Exception = " , n_catch, ' \n ' ; color= :cyan )
160157end
161-
162- # ############################################################################
163-
164- pythonize (eq:: SymbolicUtils.Add ) = " (" * join (pythonize .(arguments (eq)), " )+(" ) * " )"
165- pythonize (eq:: SymbolicUtils.Mul ) = " (" * join (pythonize .(arguments (eq)), " )*(" ) * " )"
166-
167- function pythonize (eq:: SymbolicUtils.Pow )
168- a = pythonize .(arguments (eq))
169- " (" * a[1 ] * " )**(" * a[2 ] * " )"
170- end
171-
172- pythonize (eq:: SymbolicUtils.Term ) = string (operation (eq)) * ' (' * pythonize (arguments (eq)[1 ]) * ' )'
173-
174- function pythonize (eq)
175- s = string (eq)
176- s = replace (s, " π" => " pi" )
177- s = replace (s, " im" => " j" )
178- s
179- end
0 commit comments