@@ -92,6 +92,10 @@ function get_exp(x::BasicSymbolic)
9292 x. impl. exp
9393end
9494
95+ function get_val (x:: BasicSymbolic )
96+ x. impl. val
97+ end
98+
9599# Same but different error messages
96100@noinline error_on_type () = error (" Internal error: unreachable reached!" )
97101@noinline error_sym () = error (" Sym doesn't have a operation or arguments!" )
@@ -327,7 +331,7 @@ function _isequal(a, b, E)
327331 a2 = arguments (b)
328332 isequal (operation (a), operation (b)) && _allarequal (a1, a2)
329333 elseif E === CONST
330- isequal (a . impl . val, b . impl . val )
334+ isequal (get_val (a), get_val (b) )
331335 else
332336 error_on_type ()
333337 end
@@ -378,7 +382,7 @@ function Base.hash(s::BasicSymbolic, salt::UInt)::UInt
378382 s. hash[] = h′
379383 return h′
380384 elseif E === CONST
381- return hash (s . impl . val , salt ⊻ COS_SALT)
385+ return hash (get_val (s) , salt ⊻ COS_SALT)
382386 else
383387 error_on_type ()
384388 end
@@ -452,14 +456,14 @@ end
452456
453457function _iszero (x:: BasicSymbolic )
454458 @match x. impl begin
455- Const (_... ) => iszero (x . impl . val )
459+ Const (_... ) => iszero (get_val (x) )
456460 _ => false
457461 end
458462end
459463
460464function _isone (x:: BasicSymbolic )
461465 @match x. impl begin
462- Const (_... ) => isone (x . impl . val )
466+ Const (_... ) => isone (get_val (x) )
463467 _ => false
464468 end
465469end
@@ -833,7 +837,7 @@ const show_simplified = Ref(false)
833837isnegative (t:: Real ) = t < 0
834838function isnegative (t)
835839 if isconst (t)
836- val = t . impl . val
840+ val = get_val (t)
837841 return isnegative (val)
838842 end
839843 if iscall (t) && operation (t) === (* )
@@ -872,7 +876,7 @@ function remove_minus(t)
872876 args = arguments (t)
873877 arg1 = args[1 ]
874878 if isconst (arg1)
875- arg1 = arg1. impl . val
879+ arg1 = get_val ( arg1)
876880 end
877881 @assert arg1 < 0
878882 Any[- arg1, args[2 : end ]. .. ]
@@ -911,14 +915,14 @@ end
911915
912916function show_mul (io, args)
913917 if isconst (args)
914- print (io, args. impl . val )
918+ print (io, get_val ( args) )
915919 return
916920 end
917921 length (args) == 1 && return print_arg (io, * , args[1 ])
918922
919923 arg1 = args[1 ]
920924 if isconst (arg1)
921- arg1 = arg1. impl . val
925+ arg1 = get_val ( arg1)
922926 end
923927
924928 minus = arg1 isa Number && arg1 == - 1
@@ -930,7 +934,7 @@ function show_mul(io, args)
930934
931935 nostar = minus || unit ||
932936 (! paren_scalar && arg1 isa Number &&
933- ! (isconst (args[2 ]) && args[2 ]. impl . val isa Number))
937+ ! (isconst (args[2 ]) && get_val ( args[2 ]) isa Number))
934938
935939 for (i, t) in enumerate (args)
936940 if i != 1
@@ -1021,7 +1025,7 @@ showraw(t) = showraw(stdout, t)
10211025function Base. show (io:: IO , v:: BasicSymbolic )
10221026 @match v. impl begin
10231027 Sym (_... ) => Base. show_unquoted (io, get_name (v))
1024- Const (_... ) => print (io, v . impl . val )
1028+ Const (_... ) => print (io, get_val (v) )
10251029 _ => show_term (io, v)
10261030 end
10271031end
@@ -1235,10 +1239,10 @@ sub_t(a) = promote_symtype(-, symtype(a))
12351239import Base: (+ ), (- ), (* ), (// ), (/ ), (\ ), (^ )
12361240function + (a:: SN , b:: SN )
12371241 if isconst (a)
1238- return a . impl . val + b
1242+ return get_val (a) + b
12391243 end
12401244 if isconst (b)
1241- return b . impl . val + a
1245+ return get_val (b) + a
12421246 end
12431247 ! issafecanon (+ , a, b) && return term (+ , a, b) # Don't flatten if args have metadata
12441248 if isadd (a) && isadd (b)
@@ -1255,7 +1259,7 @@ function +(a::SN, b::SN)
12551259end
12561260function + (a:: Number , b:: SN )
12571261 if isconst (b)
1258- return a + b . impl . val
1262+ return a + get_val (b)
12591263 end
12601264 ! issafecanon (+ , b) && return term (+ , a, b) # Don't flatten if args have metadata
12611265 iszero (a) && return b
@@ -1270,7 +1274,7 @@ end
12701274
12711275function - (a:: SN )
12721276 if isconst (a)
1273- v = a . impl . val
1277+ v = get_val (a)
12741278 mv = - v
12751279 return _Const (mv)
12761280 end
@@ -1299,10 +1303,10 @@ mul_t(a) = promote_symtype(*, symtype(a))
12991303
13001304function * (a:: SN , b:: SN )
13011305 if isconst (a)
1302- return a . impl . val * b
1306+ return get_val (a) * b
13031307 end
13041308 if isconst (b)
1305- return b . impl . val * a
1309+ return get_val (b) * a
13061310 end
13071311 # Always make sure Div wraps Mul
13081312 ! issafecanon (* , a, b) && return term (* , a, b)
@@ -1333,7 +1337,7 @@ function *(a::SN, b::SN)
13331337end
13341338function * (a:: Number , b:: SN )
13351339 if isconst (b)
1336- return a * b . impl . val
1340+ return a * get_val (b)
13371341 end
13381342 ! issafecanon (* , b) && return term (* , a, b)
13391343 if iszero (a)
0 commit comments