22# --------------------
33# ### Symbolic
44# --------------------
5- abstract type Symbolic{T} end
65
76# ################### SafeReal #########################
87export SafeReal, LiteralReal
5554
5655Core ADT for `BasicSymbolic`. `hash` and `isequal` compare metadata.
5756"""
58- @data mutable BasicSymbolicImpl{T} <: Symbolic{T} begin
57+ @data mutable BasicSymbolicImpl{T} begin
5958 struct Const
6059 const val:: T
6160 id:: IdentT
@@ -491,11 +490,10 @@ end
491490# ## Base interface
492491# ##
493492
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
499497
500498const SCALAR_SYMTYPE_VARIANTS = [Number, Real, SafeReal, LiteralReal, Int, Float64, Bool]
501499const ARR_VARIANTS = [Vector, Matrix]
@@ -718,8 +716,8 @@ function Base.hash(s::BSImpl.Type, h::UInt)
718716 hash_bsimpl (s, h, COMPARE_FULL[])
719717end
720718
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))
723721
724722
725723Base. 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
975973
976974function Const {T} (val) where {T}
977975 val = unwrap (val)
978- val isa Symbolic && return val
976+ val isa BasicSymbolic && return val
979977 BSImpl. Const {T} (convert (T, val))
980978end
981979
@@ -1227,12 +1225,12 @@ end
12271225metadata (s:: BSImpl.Type ) = isconst (s) ? nothing : s. metadata
12281226metadata (s:: BasicSymbolic , meta) = Setfield. @set! s. metadata = meta
12291227
1230- function hasmetadata (s:: Symbolic , ctx)
1228+ function hasmetadata (s:: BasicSymbolic , ctx)
12311229 metadata (s) isa AbstractDict && haskey (metadata (s), ctx)
12321230end
12331231
12341232issafecanon (f, s) = true
1235- function issafecanon (f, s:: Symbolic )
1233+ function issafecanon (f, s:: BasicSymbolic )
12361234 if metadata (s) === nothing || isempty (metadata (s)) || issym (s)
12371235 return true
12381236 else
@@ -1245,7 +1243,7 @@ _issafecanon(::typeof(^), s) = !iscall(s) || !(operation(s) in (*, ^))
12451243
12461244issafecanon (f, ss... ) = all (x-> issafecanon (f, x), ss)
12471245
1248- function getmetadata (s:: Symbolic , ctx)
1246+ function getmetadata (s:: BasicSymbolic , ctx)
12491247 md = metadata (s)
12501248 if md isa AbstractDict
12511249 md[ctx]
@@ -1254,7 +1252,7 @@ function getmetadata(s::Symbolic, ctx)
12541252 end
12551253end
12561254
1257- function getmetadata (s:: Symbolic , ctx, default)
1255+ function getmetadata (s:: BasicSymbolic , ctx, default)
12581256 md = metadata (s)
12591257 md isa AbstractDict ? get (md, ctx, default) : default
12601258end
@@ -1282,7 +1280,7 @@ function assocmeta(d::Base.ImmutableDict, ctx, val)::ImmutableDict{DataType,Any}
12821280 Base. ImmutableDict {DataType, Any} (d, ctx, val)
12831281end
12841282
1285- function setmetadata (s:: Symbolic , ctx:: DataType , val)
1283+ function setmetadata (s:: BasicSymbolic , ctx:: DataType , val)
12861284 if s. metadata isa AbstractDict
12871285 @set s. metadata = assocmeta (s. metadata, ctx, val)
12881286 else
@@ -1521,9 +1519,9 @@ promote_symtype(f, Ts...) = Any
15211519
15221520struct FnType{X<: Tuple ,Y,Z} end
15231521
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))
15251523
1526- function (f:: Symbolic )(args... )
1524+ function (f:: BasicSymbolic )(args... )
15271525 error (" Sym $f is not callable. " *
15281526 " Use @syms $f (var1, var2,...) to create it as a callable." )
15291527end
@@ -1548,7 +1546,7 @@ function promote_symtype(f::BasicSymbolic{<:FnType{X,Y}}, args...) where {X, Y}
15481546 return Y
15491547end
15501548
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}
15521550 print (io, nameof (f))
15531551 # Use `Base.unwrap_unionall` to handle `Tuple{T} where T`. This is not the
15541552 # best printing, but it's better than erroring.
@@ -1657,7 +1655,7 @@ end
16571655# ##
16581656# ## Arithmetic
16591657# ##
1660- const SN = Symbolic {<: Number }
1658+ const SN = BasicSymbolic {<: Number }
16611659# integration. Constructors of `Add, Mul, Pow...` from Base (+, *, ^, ...)
16621660
16631661add_t (a:: Number ,b:: Number ) = promote_symtype (+ , symtype (a), symtype (b))
0 commit comments