# Why do certain fractional values in TriangleWave not evaluate?

Bug introduced in 8.0 or earlier and persisting through 11.0.1 or later

While answering another question I discovered that TriangleWave does not automatically evaluate when given certain fractional values, specifically fractions with a denominator of 20:

TriangleWave[ Range[8] / 20 ]

{TriangleWave[1/20], 2/5, TriangleWave[3/20], 4/5, 1, 4/5, TriangleWave[7/20], 2/5}


These are reduced by Simplify:

TriangleWave[ Range[8] / 20 ] // Simplify

{1/5, 2/5, 3/5, 4/5, 1, 4/5, 3/5, 2/5}


This appears to be the only denominator under 10,000 that does not automatically evaluate:

Cases[TriangleWave[1/Range[1*^5]], _TriangleWave]

{TriangleWave[1/20]}


Is there a reason to believe that this behavior is anything other than a bug in TriangleWave?

• It only seems to evaluate when (2 ArcSin[Sin[2 Pi t]])/Pi is an explicit NumberQ
– Rojo
Commented Jan 9, 2014 at 3:27
• Interesting question - I've wondered sometimes how MM decides (and why) to not simplify. E.G., 4/Pi (ArcSin[Sin[2/20 Pi]]) results in a trig form, while 4/Pi (ArcSin[Sin[3/20 Pi]]) simplifies, yet both are rationals...
– ciao
Commented Jan 9, 2014 at 4:00
• @rasher I have raised a question about that here. Commented Jan 9, 2014 at 9:11
• @Mr.Wizard I have added the bug header. Is the introduction version correct? I don't have access to earlier version than 9.0 at the moment.
– user31159
Commented Oct 8, 2016 at 12:00
• @Xavier, version 8 has the bug; since TriangleWave[] was introduced in version 7, testing that as well (by somebody other than you or me) should make for an accurate record. Commented Oct 8, 2016 at 12:09

Rojo's comment is spot on. If you look at the implementation of TriangleWave, you'll find something like this:

TriangleWave[t_?NumberQ] := With[{r = 2 ArcSin[Sin[2 π t]]/π}, r /; NumberQ[r]] /; Im[t] == 0


Note the use of NumberQ in the definition, which only checks if the argument is explicitly a number. For certain values of your input, ArcSin[Sin[2 π t]]/π is False for NumberQ:

{#, NumberQ@#}& /@ (ArcSin[Sin[2 π Range[8]/20]]/π) // TableForm


They should've used NumericQ instead of NumberQ.

• How do you find the implementation? Commented Jan 9, 2014 at 4:12
• @s0rce You can clear the attributes and look at the definitions.
– rm -rf
Commented Jan 9, 2014 at 4:13
• @s0rce Something like this peep[s_] := Module[{at}, at = Attributes[s]; ClearAttributes[s, at]; Print@Definition@s; SetAttributes[s, at]; ]; peep[TriangleWave] Commented Jan 9, 2014 at 5:34
• Thanks for the exploration. It sounds like you agree that this is a bug; is that correct? Commented Jan 9, 2014 at 8:48
• @Mr.Wizard Yes, I agree that it is a bug.
– rm -rf
Commented Jan 9, 2014 at 14:49