@@ -84,28 +84,28 @@ Core ADT for `BasicSymbolic`. `hash` and `isequal` compare metadata.
84
84
struct Sym
85
85
const name:: Symbol
86
86
const metadata:: MetadataT
87
- hash2:: UInt
88
87
const shape:: ShapeT
88
+ hash2:: UInt
89
89
id:: IdentT
90
90
end
91
91
struct Term
92
92
const f:: Any
93
93
const args:: ArgsT
94
94
const metadata:: MetadataT
95
+ const shape:: ShapeT
95
96
hash:: UInt
96
97
hash2:: UInt
97
- const shape:: ShapeT
98
98
id:: IdentT
99
99
end
100
100
struct AddOrMul
101
101
const variant:: AddMulVariant.T
102
102
const coeff:: T
103
103
const dict:: RODict{Symbolic, T}
104
- const args:: ArgsT
105
104
const metadata:: MetadataT
105
+ const shape:: ShapeT
106
+ const args:: ArgsT
106
107
hash:: UInt
107
108
hash2:: UInt
108
- const shape:: ShapeT
109
109
id:: IdentT
110
110
end
111
111
struct Div
@@ -119,16 +119,16 @@ Core ADT for `BasicSymbolic`. `hash` and `isequal` compare metadata.
119
119
# algorithms to not try to eliminate more.
120
120
const simplified:: Bool
121
121
const metadata:: MetadataT
122
- hash2:: UInt
123
122
const shape:: ShapeT
123
+ hash2:: UInt
124
124
id:: IdentT
125
125
end
126
126
struct Pow
127
127
const base:: Any
128
128
const exp:: Any
129
129
const metadata:: MetadataT
130
- hash2:: UInt
131
130
const shape:: ShapeT
131
+ hash2:: UInt
132
132
id:: IdentT
133
133
end
134
134
end
@@ -203,12 +203,6 @@ override_properties(obj::BSImpl.Type) = override_properties(MData.variant_type(o
203
203
204
204
function override_properties (obj:: Type{<:BSImpl.Variant} )
205
205
@match obj begin
206
- # Type{<:BSImpl.Const} => (; id = Ref{IdentT}(nothing))
207
- # ::Type{<:BSImpl.Sym} => (; id = Ref{IdentT}(nothing), hash2 = Ref{UInt}(0))
208
- # ::Type{<:BSImpl.Term} => (; id = Ref{IdentT}(nothing), hash = Ref{UInt}(0), hash2 = Ref{UInt}(0))
209
- # ::Type{<:BSImpl.AddOrMul} => (; id = Ref{IdentT}(nothing), hash = Ref{UInt}(0), hash2 = Ref{UInt}(0))
210
- # ::Type{<:BSImpl.Div} => (; id = Ref{IdentT}(nothing), hash2 = Ref{UInt}(0))
211
- # ::Type{<:BSImpl.Pow} => (; id = Ref{IdentT}(nothing), hash2 = Ref{UInt}(0))
212
206
:: Type{<:BSImpl.Sym} => (; id = nothing , hash2 = 0 )
213
207
:: Type{<:BSImpl.Term} => (; id = nothing , hash = 0 , hash2 = 0 )
214
208
:: Type{<:BSImpl.AddOrMul} => (; id = nothing , hash = 0 , hash2 = 0 )
@@ -218,6 +212,17 @@ function override_properties(obj::Type{<:BSImpl.Variant})
218
212
end
219
213
end
220
214
215
+ function ordered_override_properties (obj:: Type{<:BSImpl.Variant} )
216
+ @match obj begin
217
+ :: Type{<:BSImpl.Sym} => (0 , nothing )
218
+ :: Type{<:BSImpl.Term} => (0 , 0 , nothing )
219
+ :: Type{<:BSImpl.AddOrMul} => (ArgsT (), 0 , 0 , nothing )
220
+ :: Type{<:BSImpl.Div} => (0 , nothing )
221
+ :: Type{<:BSImpl.Pow} => (0 , nothing )
222
+ _ => throw (UnimplementedForVariantError (override_properties, obj))
223
+ end
224
+ end
225
+
221
226
function ConstructionBase. getproperties (obj:: BSImpl.Type )
222
227
@match obj begin
223
228
BSImpl. Sym (; name, metadata, hash2, shape, id) => (; name, metadata, hash2, shape, id)
@@ -419,10 +424,8 @@ function isequal_symdict(a::Dict, b::Dict, val)
419
424
end
420
425
421
426
function isequal_bsimpl (a:: BSImpl.Type , b:: BSImpl.Type , val)
422
- # @show "E"
423
427
full = isone (val)
424
428
partial = @match (a, b) begin
425
- # (BSImpl.Const(; val = v1), BSImpl.Const(; val = v2)) => return isequal(v1, v2)
426
429
(BSImpl. Sym (; name = n1, shape = s1), BSImpl. Sym (; name = n2, shape = s2)) => begin
427
430
n1 === n2 && s1 == s2
428
431
end
@@ -808,34 +811,38 @@ end
808
811
809
812
function BSImpl. Sym {T} (name:: Symbol ; metadata = nothing , shape = default_shape (T)) where {T}
810
813
metadata = parse_metadata (metadata)
811
- hashcons (BSImpl. Sym {T} (; name, metadata, shape, override_properties (BSImpl. Sym{T})... ))
814
+ props = ordered_override_properties (BSImpl. Sym)
815
+ hashcons (BSImpl. Sym {T} (name, metadata, shape, props... ))
812
816
end
813
817
814
818
function BSImpl. Term {T} (f, args; metadata = nothing , shape = default_shape (T)) where {T}
815
819
metadata = parse_metadata (metadata)
816
820
args = parse_args (args)
817
- hashcons (BSImpl. Term {T} (; f, args, metadata, shape, override_properties (BSImpl. Term{T})... ))
821
+ props = ordered_override_properties (BSImpl. Term)
822
+ hashcons (BSImpl. Term {T} (f, args, metadata, shape, props... ))
818
823
end
819
824
820
825
function BSImpl. AddOrMul {T} (variant:: AddMulVariant.T , coeff:: T , dict:: AbstractDict ; metadata = nothing , shape = default_shape (T)) where {T}
821
826
metadata = parse_metadata (metadata)
822
827
dict = parse_dict (T, dict)
823
- args = ArgsT ( )
824
- hashcons (BSImpl. AddOrMul {T} (; variant, coeff, dict, args, metadata, shape, override_properties (BSImpl . AddOrMul{T}) ... ))
828
+ props = ordered_override_properties (BSImpl . AddOrMul )
829
+ hashcons (BSImpl. AddOrMul {T} (variant, coeff, dict, metadata, shape, props ... ))
825
830
end
826
831
827
832
function BSImpl. Div {T} (num, den, simplified:: Bool ; metadata = nothing , shape = default_shape (T)) where {T}
828
833
metadata = parse_metadata (metadata)
829
834
num = parse_maybe_symbolic (num)
830
835
den = parse_maybe_symbolic (den)
831
- hashcons (BSImpl. Div {T} (; num, den, simplified, metadata, shape, override_properties (BSImpl. Div{T})... ))
836
+ props = ordered_override_properties (BSImpl. Div)
837
+ hashcons (BSImpl. Div {T} (num, den, simplified, metadata, shape, props... ))
832
838
end
833
839
834
840
function BSImpl. Pow {T} (base, exp; metadata = nothing , shape = default_shape (T)) where {T}
835
841
metadata = parse_metadata (metadata)
836
842
base = parse_maybe_symbolic (base)
837
843
exp = parse_maybe_symbolic (exp)
838
- hashcons (BSImpl. Pow {T} (; base, exp, metadata, shape, override_properties (BSImpl. Pow{T})... ))
844
+ props = ordered_override_properties (BSImpl. Pow)
845
+ hashcons (BSImpl. Pow {T} (base, exp, metadata, shape, props... ))
839
846
end
840
847
841
848
# struct Const{T} end
0 commit comments