2
2
# --------------------
3
3
# ### Symbolic
4
4
# --------------------
5
- abstract type Symbolic{T} end
6
5
7
6
# ################### SafeReal #########################
8
7
export SafeReal, LiteralReal
55
54
56
55
Core ADT for `BasicSymbolic`. `hash` and `isequal` compare metadata.
57
56
"""
58
- @data mutable BasicSymbolicImpl{T} <: Symbolic{T} begin
57
+ @data mutable BasicSymbolicImpl{T} begin
59
58
struct Const
60
59
const val:: T
61
60
id:: IdentT
@@ -491,11 +490,10 @@ end
491
490
# ## Base interface
492
491
# ##
493
492
494
- Base. isequal (:: Symbolic , x) = false
495
- Base. isequal (x, :: Symbolic ) = false
496
- Base. isequal (:: Symbolic , :: Missing ) = false
497
- Base. isequal (:: Missing , :: Symbolic ) = false
498
- Base. isequal (:: Symbolic , :: Symbolic ) = false
493
+ Base. isequal (:: BasicSymbolic , x) = false
494
+ Base. isequal (x, :: BasicSymbolic ) = false
495
+ Base. isequal (:: BasicSymbolic , :: Missing ) = false
496
+ Base. isequal (:: Missing , :: BasicSymbolic ) = false
499
497
500
498
const SCALAR_SYMTYPE_VARIANTS = [Number, Real, SafeReal, LiteralReal, Int, Float64, Bool]
501
499
const ARR_VARIANTS = [Vector, Matrix]
@@ -718,8 +716,8 @@ function Base.hash(s::BSImpl.Type, h::UInt)
718
716
hash_bsimpl (s, h, COMPARE_FULL[])
719
717
end
720
718
721
- Base. one ( s:: Union{Symbolic, BSImpl.Type} ) = one ( symtype (s))
722
- Base. zero (s:: Union{Symbolic, BSImpl.Type} ) = zero (symtype (s))
719
+ Base. one ( s:: BSImpl.Type ) = one ( symtype (s))
720
+ Base. zero (s:: BSImpl.Type ) = zero (symtype (s))
723
721
724
722
725
723
Base. nameof (s:: Union{BasicSymbolic, BSImpl.Type} ) = issym (s) ? s. name : error (" Non-Sym BasicSymbolic doesn't have a name" )
@@ -975,7 +973,7 @@ struct Div{T} end
975
973
976
974
function Const {T} (val) where {T}
977
975
val = unwrap (val)
978
- val isa Symbolic && return val
976
+ val isa BasicSymbolic && return val
979
977
BSImpl. Const {T} (convert (T, val))
980
978
end
981
979
@@ -1227,12 +1225,12 @@ end
1227
1225
metadata (s:: BSImpl.Type ) = isconst (s) ? nothing : s. metadata
1228
1226
metadata (s:: BasicSymbolic , meta) = Setfield. @set! s. metadata = meta
1229
1227
1230
- function hasmetadata (s:: Symbolic , ctx)
1228
+ function hasmetadata (s:: BasicSymbolic , ctx)
1231
1229
metadata (s) isa AbstractDict && haskey (metadata (s), ctx)
1232
1230
end
1233
1231
1234
1232
issafecanon (f, s) = true
1235
- function issafecanon (f, s:: Symbolic )
1233
+ function issafecanon (f, s:: BasicSymbolic )
1236
1234
if metadata (s) === nothing || isempty (metadata (s)) || issym (s)
1237
1235
return true
1238
1236
else
@@ -1245,7 +1243,7 @@ _issafecanon(::typeof(^), s) = !iscall(s) || !(operation(s) in (*, ^))
1245
1243
1246
1244
issafecanon (f, ss... ) = all (x-> issafecanon (f, x), ss)
1247
1245
1248
- function getmetadata (s:: Symbolic , ctx)
1246
+ function getmetadata (s:: BasicSymbolic , ctx)
1249
1247
md = metadata (s)
1250
1248
if md isa AbstractDict
1251
1249
md[ctx]
@@ -1254,7 +1252,7 @@ function getmetadata(s::Symbolic, ctx)
1254
1252
end
1255
1253
end
1256
1254
1257
- function getmetadata (s:: Symbolic , ctx, default)
1255
+ function getmetadata (s:: BasicSymbolic , ctx, default)
1258
1256
md = metadata (s)
1259
1257
md isa AbstractDict ? get (md, ctx, default) : default
1260
1258
end
@@ -1282,7 +1280,7 @@ function assocmeta(d::Base.ImmutableDict, ctx, val)::ImmutableDict{DataType,Any}
1282
1280
Base. ImmutableDict {DataType, Any} (d, ctx, val)
1283
1281
end
1284
1282
1285
- function setmetadata (s:: Symbolic , ctx:: DataType , val)
1283
+ function setmetadata (s:: BasicSymbolic , ctx:: DataType , val)
1286
1284
if s. metadata isa AbstractDict
1287
1285
@set s. metadata = assocmeta (s. metadata, ctx, val)
1288
1286
else
@@ -1521,9 +1519,9 @@ promote_symtype(f, Ts...) = Any
1521
1519
1522
1520
struct FnType{X<: Tuple ,Y,Z} end
1523
1521
1524
- (f:: Symbolic {<:FnType} )(args... ) = Term {promote_symtype(f, symtype.(args)...)} (f, SmallV {Any} (args))
1522
+ (f:: BasicSymbolic {<:FnType} )(args... ) = Term {promote_symtype(f, symtype.(args)...)} (f, SmallV {Any} (args))
1525
1523
1526
- function (f:: Symbolic )(args... )
1524
+ function (f:: BasicSymbolic )(args... )
1527
1525
error (" Sym $f is not callable. " *
1528
1526
" Use @syms $f (var1, var2,...) to create it as a callable." )
1529
1527
end
@@ -1548,7 +1546,7 @@ function promote_symtype(f::BasicSymbolic{<:FnType{X,Y}}, args...) where {X, Y}
1548
1546
return Y
1549
1547
end
1550
1548
1551
- function Base. show (io:: IO , f:: Symbolic {<:FnType{X,Y}} ) where {X,Y}
1549
+ function Base. show (io:: IO , f:: BasicSymbolic {<:FnType{X,Y}} ) where {X,Y}
1552
1550
print (io, nameof (f))
1553
1551
# Use `Base.unwrap_unionall` to handle `Tuple{T} where T`. This is not the
1554
1552
# best printing, but it's better than erroring.
@@ -1657,7 +1655,7 @@ end
1657
1655
# ##
1658
1656
# ## Arithmetic
1659
1657
# ##
1660
- const SN = Symbolic {<: Number }
1658
+ const SN = BasicSymbolic {<: Number }
1661
1659
# integration. Constructors of `Add, Mul, Pow...` from Base (+, *, ^, ...)
1662
1660
1663
1661
add_t (a:: Number ,b:: Number ) = promote_symtype (+ , symtype (a), symtype (b))
0 commit comments