0
$\begingroup$

I have the code TensorDimensions[TensorContract[c, {{1, 2}}]]. It is in normal form. But if I add the rules:

Unprotect[TensorDimensions]
TensorDimensions[c] = {4, 4, 5}

then the code evaluates to {5}.

I was wondering, is there some specific language construct that would give me the result of the evaluation TensorDimensions[TensorContract[c, {{1, 2}}]] if I were to add those rules, without actually adding those rules in the global context?

I would like to see what would happen to the expression evaluation if the rules were added, but not add the rules. Is this possible? Like a "stronger" version of what ReplaceAll does.

$\endgroup$

1 Answer 1

1
$\begingroup$

Sounds like you want to use TensorReduce[] with assumptions:

Assuming[c ∈ Arrays[{4, 4, 5}],
        TensorReduce[TensorDimensions[TensorContract[c, {{1, 2}}]]]]
   {5}
$\endgroup$
1
  • $\begingroup$ This works for the particular case of TensorDimensions , however I'm still wondering if it's possible to have a general construct that operates like I've described in my post. I've tried using contexts with Begin and End, but it turns out if you're in a context and add rules to a function that's already defined in the global context, the rules "leak out" to the global context. Block and Module don't seem to work as would be needed also. The 'Unset` function seems like the most helpful for this kind of construct, but it unsets everithing, not just locally added rules. $\endgroup$ May 3, 2020 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.