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
@@ -619,11 +618,10 @@ end
619
618
# ## Base interface
620
619
# ##
621
620
622
- Base. isequal (:: Symbolic , x) = false
623
- Base. isequal (x, :: Symbolic ) = false
624
- Base. isequal (:: Symbolic , :: Missing ) = false
625
- Base. isequal (:: Missing , :: Symbolic ) = false
626
- Base. isequal (:: Symbolic , :: Symbolic ) = false
621
+ Base. isequal (:: BasicSymbolic , x) = false
622
+ Base. isequal (x, :: BasicSymbolic ) = false
623
+ Base. isequal (:: BasicSymbolic , :: Missing ) = false
624
+ Base. isequal (:: Missing , :: BasicSymbolic ) = false
627
625
628
626
const SCALAR_SYMTYPE_VARIANTS = [Number, Real, SafeReal, LiteralReal, Int, Float64, Bool]
629
627
const ARR_VARIANTS = [Vector, Matrix]
@@ -846,8 +844,8 @@ function Base.hash(s::BSImpl.Type, h::UInt)
846
844
hash_bsimpl (s, h, COMPARE_FULL[])
847
845
end
848
846
849
- Base. one ( s:: Union{Symbolic, BSImpl.Type} ) = one ( symtype (s))
850
- Base. zero (s:: Union{Symbolic, BSImpl.Type} ) = zero (symtype (s))
847
+ Base. one ( s:: BSImpl.Type ) = one ( symtype (s))
848
+ Base. zero (s:: BSImpl.Type ) = zero (symtype (s))
851
849
852
850
853
851
Base. nameof (s:: Union{BasicSymbolic, BSImpl.Type} ) = issym (s) ? s. name : error (" Non-Sym BasicSymbolic doesn't have a name" )
@@ -1103,7 +1101,7 @@ struct Div{T} end
1103
1101
1104
1102
function Const {T} (val) where {T}
1105
1103
val = unwrap (val)
1106
- val isa Symbolic && return val
1104
+ val isa BasicSymbolic && return val
1107
1105
BSImpl. Const {T} (convert (T, val))
1108
1106
end
1109
1107
@@ -1398,12 +1396,12 @@ julia> hasmetadata(x, Float64)
1398
1396
false
1399
1397
```
1400
1398
"""
1401
- function hasmetadata (s:: Symbolic , ctx)
1399
+ function hasmetadata (s:: BasicSymbolic , ctx)
1402
1400
metadata (s) isa AbstractDict && haskey (metadata (s), ctx)
1403
1401
end
1404
1402
1405
1403
issafecanon (f, s) = true
1406
- function issafecanon (f, s:: Symbolic )
1404
+ function issafecanon (f, s:: BasicSymbolic )
1407
1405
if metadata (s) === nothing || isempty (metadata (s)) || issym (s)
1408
1406
return true
1409
1407
else
@@ -1440,7 +1438,7 @@ julia> getmetadata(x, symtype) # Get the type metadata
1440
1438
Float64
1441
1439
```
1442
1440
"""
1443
- function getmetadata (s:: Symbolic , ctx)
1441
+ function getmetadata (s:: BasicSymbolic , ctx)
1444
1442
md = metadata (s)
1445
1443
if md isa AbstractDict
1446
1444
md[ctx]
@@ -1472,7 +1470,7 @@ julia> getmetadata(x, Float64, "no type")
1472
1470
"no type"
1473
1471
```
1474
1472
"""
1475
- function getmetadata (s:: Symbolic , ctx, default)
1473
+ function getmetadata (s:: BasicSymbolic , ctx, default)
1476
1474
md = metadata (s)
1477
1475
md isa AbstractDict ? get (md, ctx, default) : default
1478
1476
end
@@ -1525,7 +1523,7 @@ julia> getmetadata(x_with_meta, Float64)
1525
1523
"custom value"
1526
1524
```
1527
1525
"""
1528
- function setmetadata (s:: Symbolic , ctx:: DataType , val)
1526
+ function setmetadata (s:: BasicSymbolic , ctx:: DataType , val)
1529
1527
if s. metadata isa AbstractDict
1530
1528
@set s. metadata = assocmeta (s. metadata, ctx, val)
1531
1529
else
@@ -1789,9 +1787,9 @@ promote_symtype(f, Ts...) = Any
1789
1787
1790
1788
struct FnType{X<: Tuple ,Y,Z} end
1791
1789
1792
- (f:: Symbolic {<:FnType} )(args... ) = Term {promote_symtype(f, symtype.(args)...)} (f, SmallV {Any} (args))
1790
+ (f:: BasicSymbolic {<:FnType} )(args... ) = Term {promote_symtype(f, symtype.(args)...)} (f, SmallV {Any} (args))
1793
1791
1794
- function (f:: Symbolic )(args... )
1792
+ function (f:: BasicSymbolic )(args... )
1795
1793
error (" Sym $f is not callable. " *
1796
1794
" Use @syms $f (var1, var2,...) to create it as a callable." )
1797
1795
end
@@ -1816,7 +1814,7 @@ function promote_symtype(f::BasicSymbolic{<:FnType{X,Y}}, args...) where {X, Y}
1816
1814
return Y
1817
1815
end
1818
1816
1819
- function Base. show (io:: IO , f:: Symbolic {<:FnType{X,Y}} ) where {X,Y}
1817
+ function Base. show (io:: IO , f:: BasicSymbolic {<:FnType{X,Y}} ) where {X,Y}
1820
1818
print (io, nameof (f))
1821
1819
# Use `Base.unwrap_unionall` to handle `Tuple{T} where T`. This is not the
1822
1820
# best printing, but it's better than erroring.
@@ -1925,7 +1923,7 @@ end
1925
1923
# ##
1926
1924
# ## Arithmetic
1927
1925
# ##
1928
- const SN = Symbolic {<: Number }
1926
+ const SN = BasicSymbolic {<: Number }
1929
1927
# integration. Constructors of `Add, Mul, Pow...` from Base (+, *, ^, ...)
1930
1928
1931
1929
add_t (a:: Number ,b:: Number ) = promote_symtype (+ , symtype (a), symtype (b))
0 commit comments