Skip to content

Commit 38ec2bb

Browse files
authored
Merge pull request #596 from JuliaSymbolics/s/remove-TI-depwarns
remove TermInterface related depwarns
2 parents edb1689 + 6367804 commit 38ec2bb

21 files changed

+123
-142
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SymbolicUtils"
22
uuid = "d1185830-fcd6-423d-90d6-eec64667417b"
33
authors = ["Shashi Gowda"]
4-
version = "1.6.0"
4+
version = "1.7.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -22,7 +22,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2222
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2323
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2424
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
25-
TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
2625
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
2726
Unityper = "a7c27f48-0311-42f6-a7f8-2c11e75eb415"
2827

@@ -43,7 +42,6 @@ Setfield = "0.7, 0.8, 1"
4342
SpecialFunctions = "0.10, 1.0, 2"
4443
StaticArrays = "0.12, 1.0"
4544
SymbolicIndexingInterface = "0.3"
46-
TermInterface = "0.4"
4745
TimerOutputs = "0.5"
4846
Unityper = "0.1.2"
4947
julia = "1.3"

docs/src/api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ SymbolicUtils.Pow
1212
SymbolicUtils.promote_symtype
1313
```
1414

15+
## Interfacing
16+
17+
```@docs
18+
SymbolicUtils.istree
19+
SymbolicUtils.operation
20+
SymbolicUtils.arguments
21+
SymbolicUtils.similarterm
22+
```
23+
1524
## Rewriters
1625

1726
```@docs

docs/src/index.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,15 @@ g(2//5, g(1, β))
108108

109109
Symbolic expressions are of type `Term{T}`, `Add{T}`, `Mul{T}`, `Pow{T}` or `Div{T}` and denote some function call where one or more arguments are themselves such expressions or `Sym`s. See more about the representation [here](/representation/).
110110

111-
All the expression types support the [TermInterface.jl](https://github.com/0x0f0f0f/TermInterface.jl) interface.
112-
Please refer to the package for the complete reference of the interface.
111+
All the expression types support the following:
112+
113+
- `istree(x)` -- always returns `true` denoting, `x` is not a leaf node like Sym or a literal.
114+
- `operation(x)` -- the function being called
115+
- `arguments(x)` -- a vector of arguments
116+
- `symtype(x)` -- the "inferred" type (`T`)
117+
118+
See more on the interface [here](/interface)
119+
113120

114121
## Term rewriting
115122

src/SymbolicUtils.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@ $(DocStringExtensions.README)
44
module SymbolicUtils
55

66
using DocStringExtensions
7-
87
export @syms, term, showraw, hasmetadata, getmetadata, setmetadata
98

109
using Unityper
11-
using TermInterface
10+
11+
# Sym, Term,
12+
# Add, Mul and Pow
1213
using DataStructures
1314
using Setfield
1415
import Setfield: PropertyLens
1516
using SymbolicIndexingInterface
1617
import Base: +, -, *, /, //, \, ^, ImmutableDict
1718
using ConstructionBase
18-
using TermInterface
19-
import TermInterface: iscall, isexpr, issym, symtype, head, children,
20-
operation, arguments, metadata, maketerm
21-
22-
Base.@deprecate_binding istree iscall
23-
export istree, operation, arguments, unsorted_arguments, similarterm
24-
# Sym, Term,
25-
# Add, Mul and Pow
19+
include("interface.jl")
2620
include("types.jl")
21+
export istree, operation, arguments, similarterm
2722

2823
# Methods on symbolic objects
2924
using SpecialFunctions, NaNMath

src/code.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export toexpr, Assignment, (←), Let, Func, DestructuredArgs, LiteralExpr,
88

99
import ..SymbolicUtils
1010
import ..SymbolicUtils.Rewriters
11-
import SymbolicUtils: @matchable, BasicSymbolic, Sym, Term, iscall, operation, arguments, issym,
11+
import SymbolicUtils: @matchable, BasicSymbolic, Sym, Term, istree, operation, arguments, issym,
1212
symtype, similarterm, unsorted_arguments, metadata, isterm, term
1313

1414
##== state management ==##
@@ -162,7 +162,7 @@ end
162162
toexpr(O::Expr, st) = O
163163

164164
function substitute_name(O, st)
165-
if (issym(O) || iscall(O)) && haskey(st.rewrites, O)
165+
if (issym(O) || istree(O)) && haskey(st.rewrites, O)
166166
st.rewrites[O]
167167
else
168168
O
@@ -176,13 +176,13 @@ function toexpr(O, st)
176176
end
177177
O = substitute_name(O, st)
178178

179-
!iscall(O) && return O
179+
!istree(O) && return O
180180
op = operation(O)
181181
expr′ = function_to_expr(op, O, st)
182182
if expr′ !== nothing
183183
return expr′
184184
else
185-
!iscall(O) && return O
185+
!istree(O) && return O
186186
args = arguments(O)
187187
return Expr(:call, toexpr(op, st), map(x->toexpr(x, st), args)...)
188188
end
@@ -221,7 +221,7 @@ get_rewrites(args::DestructuredArgs) = ()
221221
function get_rewrites(args::Union{AbstractArray, Tuple})
222222
cflatten(map(get_rewrites, args))
223223
end
224-
get_rewrites(x) = iscall(x) ? (x,) : ()
224+
get_rewrites(x) = istree(x) ? (x,) : ()
225225
cflatten(x) = Iterators.flatten(x) |> collect
226226

227227
# Used in Symbolics
@@ -691,7 +691,7 @@ end
691691
@inline newsym(::Type{T}) where T = Sym{T}(gensym("cse"))
692692

693693
function _cse!(mem, expr)
694-
iscall(expr) || return expr
694+
istree(expr) || return expr
695695
op = _cse!(mem, operation(expr))
696696
args = map(Base.Fix1(_cse!, mem), arguments(expr))
697697
t = similarterm(expr, op, args)
@@ -742,7 +742,7 @@ end
742742

743743

744744
function cse_state!(state, t)
745-
!iscall(t) && return t
745+
!istree(t) && return t
746746
state[t] = Base.get(state, t, 0) + 1
747747
foreach(x->cse_state!(state, x), unsorted_arguments(t))
748748
end
@@ -758,7 +758,7 @@ function cse_block!(assignments, counter, names, name, state, x)
758758
counter[] += 1
759759
return sym
760760
end
761-
elseif iscall(x)
761+
elseif istree(x)
762762
args = map(a->cse_block!(assignments, counter, names, name, state,a), unsorted_arguments(x))
763763
if isterm(x)
764764
return term(operation(x), args...)

src/inspect.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import AbstractTrees
22

33
const inspect_metadata = Ref{Bool}(false)
44
function AbstractTrees.nodevalue(x::Symbolic)
5-
iscall(x) ? operation(x) : isexpr(x) ? head(x) : x
5+
istree(x) ? operation(x) : x
66
end
77

88
function AbstractTrees.nodevalue(x::BasicSymbolic)
9-
str = if !iscall(x)
9+
str = if !istree(x)
1010
string(exprtype(x), "(", x, ")")
1111
elseif isadd(x)
1212
string(exprtype(x),
@@ -27,7 +27,7 @@ function AbstractTrees.nodevalue(x::BasicSymbolic)
2727
end
2828

2929
function AbstractTrees.children(x::Symbolic)
30-
iscall(x) ? arguments(x) : isexpr(x) ? children(x) : ()
30+
istree(x) ? arguments(x) : ()
3131
end
3232

3333
"""

src/interface.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
iscall(x)
2+
istree(x)
33
44
Returns `true` if `x` is a term. If true, `operation`, `arguments`
55
must also be defined for `x` appropriately.
66
"""
7-
iscall(x) = false
7+
istree(x) = false
88

99
"""
1010
symtype(x)
@@ -29,7 +29,7 @@ issym(x) = false
2929
"""
3030
operation(x)
3131
32-
If `x` is a term as defined by `iscall(x)`, `operation(x)` returns the
32+
If `x` is a term as defined by `istree(x)`, `operation(x)` returns the
3333
head of the term if `x` represents a function call, for example, the head
3434
is the function being called.
3535
"""
@@ -38,14 +38,14 @@ function operation end
3838
"""
3939
arguments(x)
4040
41-
Get the arguments of `x`, must be defined if `iscall(x)` is `true`.
41+
Get the arguments of `x`, must be defined if `istree(x)` is `true`.
4242
"""
4343
function arguments end
4444

4545
"""
4646
unsorted_arguments(x::T)
4747
48-
If x is a term satisfying `iscall(x)` and your term type `T` provides
48+
If x is a term satisfying `istree(x)` and your term type `T` provides
4949
an optimized implementation for storing the arguments, this function can
5050
be used to retrieve the arguments when the order of arguments does not matter
5151
but the speed of the operation does.

src/matchers.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# 3. Callback: takes arguments Dictionary × Number of elements matched
77
#
88
function matcher(val::Any)
9-
iscall(val) && return term_matcher(val)
9+
istree(val) && return term_matcher(val)
1010
function literal_matcher(next, data, bindings)
1111
islist(data) && isequal(car(data), val) ? next(bindings, 1) : nothing
1212
end
@@ -89,7 +89,7 @@ function term_matcher(term)
8989
function term_matcher(success, data, bindings)
9090

9191
!islist(data) && return nothing
92-
!iscall(car(data)) && return nothing
92+
!istree(car(data)) && return nothing
9393

9494
function loop(term, bindings′, matchers′) # Get it to compile faster
9595
if !islist(matchers′)

src/ordering.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
function get_degrees(expr)
2121
if issym(expr)
2222
((Symbol(expr),) => 1,)
23-
elseif iscall(expr)
23+
elseif istree(expr)
2424
op = operation(expr)
2525
args = arguments(expr)
2626
if operation(expr) == (^) && args[2] isa Number
@@ -62,7 +62,7 @@ function lexlt(degs1, degs2)
6262
return false # they are equal
6363
end
6464

65-
_arglen(a) = iscall(a) ? length(unsorted_arguments(a)) : 0
65+
_arglen(a) = istree(a) ? length(unsorted_arguments(a)) : 0
6666

6767
function <(a::Tuple, b::Tuple)
6868
for (x, y) in zip(a, b)

src/polyform.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Bijections
66
77
Abstracts a [MultivariatePolynomials.jl](https://juliaalgebra.github.io/MultivariatePolynomials.jl/stable/) as a SymbolicUtils expression and vice-versa.
88
9-
The SymbolicUtils term interface (`isexpr`/`iscall`, `operation, and `arguments`) works on PolyForm lazily:
9+
The SymbolicUtils term interface (`istree`, `operation, and `arguments`) works on PolyForm lazily:
1010
the `operation` and `arguments` are created by converting one level of arguments into SymbolicUtils expressions. They may further contain PolyForm within them.
1111
We use this to hold polynomials in memory while doing `simplify_fractions`.
1212
@@ -97,7 +97,7 @@ _isone(p::PolyForm) = isone(p.p)
9797
function polyize(x, pvar2sym, sym2term, vtype, pow, Fs, recurse)
9898
if x isa Number
9999
return x
100-
elseif iscall(x)
100+
elseif istree(x)
101101
if !(symtype(x) <: Number)
102102
error("Cannot convert $x of symtype $(symtype(x)) into a PolyForm")
103103
end
@@ -170,10 +170,8 @@ function PolyForm(x,
170170
PolyForm{symtype(x)}(p, pvar2sym, sym2term, metadata)
171171
end
172172

173-
isexpr(x::Type{<:PolyForm}) = true
174-
isexpr(x::PolyForm) = true
175-
iscall(x::Type{<:PolyForm}) = true
176-
iscall(x::PolyForm) = true
173+
istree(x::Type{<:PolyForm}) = true
174+
istree(x::PolyForm) = true
177175

178176
function similarterm(t::PolyForm, f, args, symtype; metadata=nothing)
179177
basic_similarterm(t, f, args, symtype; metadata=metadata)
@@ -183,7 +181,6 @@ function similarterm(::PolyForm, f::Union{typeof(*), typeof(+), typeof(^)},
183181
f(args...)
184182
end
185183

186-
head(::PolyForm) = PolyForm
187184
operation(x::PolyForm) = MP.nterms(x.p) == 1 ? (*) : (+)
188185

189186
function arguments(x::PolyForm{T}) where {T}
@@ -230,7 +227,6 @@ function arguments(x::PolyForm{T}) where {T}
230227
PolyForm{T}(t, x.pvar2sym, x.sym2term, nothing)) for t in ts]
231228
end
232229
end
233-
children(x::PolyForm) = [operation(x); arguments(x)]
234230

235231
Base.show(io::IO, x::PolyForm) = show_term(io, x)
236232

@@ -340,7 +336,7 @@ function simplify_fractions(x; polyform=false)
340336
end
341337

342338
function add_with_div(x, flatten=true)
343-
(!iscall(x) || operation(x) != (+)) && return x
339+
(!istree(x) || operation(x) != (+)) && return x
344340
aa = unsorted_arguments(x)
345341
!any(a->isdiv(a), aa) && return x # no rewrite necessary
346342

@@ -365,26 +361,26 @@ function flatten_fractions(x)
365361
end
366362

367363
function fraction_iszero(x)
368-
!iscall(x) && return _iszero(x)
364+
!istree(x) && return _iszero(x)
369365
ff = flatten_fractions(x)
370366
# fast path and then slow path
371367
any(_iszero, numerators(ff)) ||
372368
any(_iszeroexpand, numerators(ff))
373369
end
374370

375371
function fraction_isone(x)
376-
!iscall(x) && return _isone(x)
372+
!istree(x) && return _isone(x)
377373
_isone(simplify_fractions(flatten_fractions(x)))
378374
end
379375

380376
function needs_div_rules(x)
381377
(isdiv(x) && !(x.num isa Number) && !(x.den isa Number)) ||
382-
(iscall(x) && operation(x) === (+) && count(has_div, unsorted_arguments(x)) > 1) ||
383-
(iscall(x) && any(needs_div_rules, unsorted_arguments(x)))
378+
(istree(x) && operation(x) === (+) && count(has_div, unsorted_arguments(x)) > 1) ||
379+
(istree(x) && any(needs_div_rules, unsorted_arguments(x)))
384380
end
385381

386382
function has_div(x)
387-
return isdiv(x) || (iscall(x) && any(has_div, unsorted_arguments(x)))
383+
return isdiv(x) || (istree(x) && any(has_div, unsorted_arguments(x)))
388384
end
389385

390386
flatten_pows(xs) = map(xs) do x

0 commit comments

Comments
 (0)