File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -60,3 +60,24 @@ function substitute(expr, dict; fold=true)
6060 expr
6161 end
6262end
63+
64+ """
65+ occursin(needle::Symbolic, haystack::Symbolic)
66+
67+ Determine whether the second argument contains the first argument. Note that
68+ this function doesn't handle associativity, commutativity, or distributivity.
69+ """
70+ Base. occursin (needle:: Symbolic , haystack:: Symbolic ) = _occursin (needle, haystack)
71+ Base. occursin (needle, haystack:: Symbolic ) = _occursin (needle, haystack)
72+ Base. occursin (needle:: Symbolic , haystack) = _occursin (needle, haystack)
73+ function _occursin (needle, haystack)
74+ isequal (needle, haystack) && return true
75+
76+ if istree (haystack)
77+ args = arguments (haystack)
78+ for arg in args
79+ occursin (needle, arg) && return true
80+ end
81+ end
82+ return false
83+ end
Original file line number Diff line number Diff line change 132132 @test substitute (exp (a), Dict (a=> 2 )) ≈ exp (2 )
133133end
134134
135+ @testset " occursin" begin
136+ @syms a b c
137+ @test occursin (a, a + b)
138+ @test ! occursin (sin (a), a + b + c)
139+ @test occursin (sin (a), a * b + c + sin (a^ 2 * sin (a)))
140+ end
141+
135142@testset " printing" begin
136143 @syms a b c
137144 @test repr (a+ b) == " a + b"
You can’t perform that action at this time.
0 commit comments