# strange behaviour of TemporalData

Bug persisting through 11.2.0

For example, we have

v = {10, 100};
u = {20, 2000};
t = {1, 2};


Then I construct two TemporalData

td1=TemporalData[{v,u},{t}]
td2=TemporalData[{v,u},-{t}]


I call td2 is reversed relative to td1, and

td1 // Normal
td2 // Normal


gives

{{{1, 10}, {2, 100}}, {{1, 20}, {2, 2000}}}
{{{-2, 100}, {-1, 10}}, {{-2, 2000}, {-1, 20}}}


Now comes the peculiar part:

first, obviously

{v, u} === td1["ValueList"]
t === td1["Times"]


gives

True
True


However,

TemporalData[td1["ValueList"], {td1["Times"]}] === td1
TemporalData[td1["ValueList"], -{td1["Times"]}] === td2


gives

True
False


What?! They suppose to be both true. Why the second identity is false?

I tried to Trace, but even as simple as TemporalData[{1}, {{1}}]//Trace will produce huge bulk of result, don't know what is going on there.

By the way, I also tried

Activate[Inactive[TemporalData][
td1["ValueList"], -{td1["Times"]}]] === td2


Also False.

So How can I create a function that serves to reverse TemporalData? The function below is not working, why?

Clear[reverseTemporalData];
reverseTemporalData[temporalData_] :=
Module[{valueList = temporalData["ValueList"],
times = temporalData["Times"]},
TemporalData[valueList, -{times}]]

reverseTemporalData[td1]===td2
(*False*)


PS. I am using Mathematica 11.2

• Looks like a bug/feature: it seems that you need to Reverse the values when you minus the times: TemporalData[td1["ValueList"], {-td1["Times"]}]==TemporalData[Reverse/@{v, u}, {-t}] gives True. – kglr Oct 2 '17 at 9:56
• @kglr But How to understand TemporalData[{{10, 100}, {20, 2000}}, {{-1, -2}}]===td2 give True? – matheorem Oct 2 '17 at 9:59
• @kglr and Clear[reverseTemporalData]; reverseTemporalData[temporalData_] := Module[{valueList = temporalData["ValueList"], times = temporalData["Times"]}, TemporalData[Reverse /@ valueList, {-times}]] doesn't work – matheorem Oct 2 '17 at 10:01
• maybe ClearAll[rubeGoldbergReverseTimesInTemporalData]; rubeGoldbergReverseTimesInTemporalData[t_TemporalData] :=TemporalData[ Reverse /@ Transpose[Reverse@Transpose@t["ValueList"]], {-t["Times"]}];rubeGoldbergReverseTimesInTemporalData[td1] ===td2?:) – kglr Oct 2 '17 at 10:56
• This also seems to work: TemporalData[Uncompress@Compress@td1["ValueList"], -{td1["Times"]}] === td2 - for some reason, destroying the "identity" of the value list helps TemporalData to behave properly... – Lukas Lang Oct 2 '17 at 13:50

Here's what's going on

TemporalData[DeveloperFromPackedArray@td1["ValueList"], -{td1["Times"]}] === td2
(* True *)


This is definitely a bug, and I have forward this to the relevant developers. My understanding is that the fact that first argument is packed is tricking the code into thinking the values are already sorted, even though they need to be re-sorted because the times have been reversed.

• Hi, @Itai Seggev. Thank you for explanation. But I don't quite understand the "re-sorted" procedure, could you explain a little why it needs resorting? What is more, I don't understand why Normal@Activate[ Inactive[TemporalData][td1["ValueList"], -{td1["Times"]}]] is not equal to Normal@TemporalData[{{10, 100}, {20, 2000}}, {{-1, -2}}]. It seems that it is consistent with functionality of Inactive and Activate – matheorem Oct 7 '17 at 7:30
• As for your second question, Activate[ Inactive[TemporalData][td1["ValueList"], -{td1["Times"]}]] is exactly equivalent to TemporalData[td1["ValueList"], {{-1, -2}}] and so this the same as above. Why would you expect inactivating and then activating somehow alter the behavior? – Itai Seggev Oct 7 '17 at 22:30
• As for your first, note that td1["ValueList"] and td2["ValueList"] are different. It needs to decide whether it has been given in the form of "ValueList" or tranposed, and is making different decisions based on whether the array is packed or not. – Itai Seggev Oct 7 '17 at 22:34
• Hi, @Itai Seggev. Thank you for explanation. But Normal@TemporalData[{{10, 100}, {20, 2000}}, {{-1, -2}}] gives different result from Normal@TemporalData[td1["ValueList"], {{-1, -2}}]. If you run Inactive[TemporalData][td1["ValueList"], -{td1["Times"]}], it is gives Inactive[TemporalData][{{10, 100}, {20, 2000}}, {{-1, -2}}]. Why you said it is equivalent to TemporalData[td1["ValueList"], {{-1, -2}}]? – matheorem Oct 8 '17 at 2:51
• That's not what I said. If you evaluate the two expressions I entered, you'll find they product exactly the same result as I claim. You are missing the point that TemporalData[td1["ValueList"], {{-1, -2}}] === TemporalData[{{10, 100}, {20, 2000}}, {{-1, -2}}] gives False, even though td1["ValueList"] === {{10, 100}, {20, 2000}} gives True. Activate & Inactive have nothing to do with the issue at hand. This is resolved by the fact that DeveloperPackedArrayQ /@ {td1["ValueList"], {{10, 100}, {20, 2000}}} gives {True,False} (still a bug, but explains what's going on). – Itai Seggev Oct 8 '17 at 4:05