8

Bug introduced in 7.0 or earlier and fixed in 10.0.0


I have a rather ugly Mathematica expression (edit: shown below) that I would like to simplify with a time constraint; simplifying without a time constraint or memory constraint does not return as long as I've had the patience to wait (a couple of hours).

The problem, which I have not seen before, is that when I execute

Simplify[ expression, TimeConstraint -> 3]

I get an output that contains things like

...10000 E^(29599743/514000) Removed[$$Failure]...

The only warning message I receive during execution is

Simplify::time: Time spent on a transformation exceeded 3.` seconds, 
and the transformation was aborted. Increasing the value of TimeConstraint option may   
improve the result of simplification

Is this a known issue? I can't find anything about it. I expect when using TimeConstraint that I will not get the simplest answer back, but I also expect to get a usable answer (which this is not).

If you think it would be helpful to see the expression I'm trying to simplify, I can post it here. The simplest example in which I've had this problem has a LeafCount of 651 and ByteCount of 17312.

EDIT

On the suggestion of @JacobAkkerboom, I am adding some more information so someone can try to reproduce the effect. Here is a compressed version of expression.

expression=Uncompress["1:eJxTTMoPSmNiYGAoZgESATmlxWnMIB4rkAjJzE0thkhyAImgxJLM/LzEnMzEyQoMnsJAEUNzYzNDQ0MDS2NzUwMIgCgH6Q7IL08tKmYEslwzf////x/Vlsz/cCF0xSA+YUc84Q5hygwEKUV1PaZKT6CxnjxAEZgbwe5kJWQBJycDQ6bFLnV1NFdmcsEtRVEP8lAmEw4H4bNo/Xnbn5kNH34xYQ0OLBoMjgFtYmSE2YTP7MJrq5hIMlvgDobZ+DV8UAYGEzYNIG5AZuY/jKgn7Oqp3w4yeEoCRYxMTAxNDMyMkGMOWzIbTQODPg1AMjzBEG9YqMGYqc+AYdRoDA+NGAabUIk/8ghFiicfKBoNLUwQEQmOXmIdeyAW6liwiqo0RpjtzvnFGVjUg+QzL7ADLcCiEl+4gzWCEgo4GPxd0thQdGQm3sZRx5EQwqMJf0glfHgKCs7MIzKtIVSSktYg5SkzSRkrs/7wt/+eQkARYwNTQ3NTcwtDI7wNN4KJD57VCHtAnuvXf3CDDZZZsFhYiQhKUrItwcYiKI9kMoS80kINMLARhHVfff3nP7i9ixxeFAUbllQFKTHA3scaPqPlwNAoB9CSE85+DvakTrDUIBifoLaTJzeQMDQ2RU2ko2lnEKcdUkPkctGr/55iQBFjy9H+0XBIANgKDyxG/QQp/UKC3WiORRl/wdpYRyqd0GJptHU7YhMmeuuWzP4R9eq5QdBHJK/dDgDIdwSQ"];

As mentioned, I get the problem simply by running

Simplify[ expression, TimeConstraint -> 3 ]

(or any other value of TimeConstraint I've bothered to check)

expression contains standard arithmetic operations, the constants E and Pi, the operations Cosh and Sinh, and three variables named y, z, and OD (and yes, I should make OD lower case, but it's hard for me to see optical depth as anything but capitals).

FURTHER EDIT

I have now reproduced the problem in an expression without a time constraint. The new expression1 has a LeafCount of 186, so it's not really that complicated.

expression1=Uncompress["1:eJxTTMoPSmNiYGAoZgESATmlxWnMIB4rkAjJzE0thkhyAImgxJLM/LzEnMzEyQoMnsJAEUNzYzNDQ0MDS2NzUwMIgCgH6Q7IL08tKmYEslwzf////x/Vlsz/cCF0xSA+QgaXI36KMDBkNmjAlMJdj6myeas0g6cQUMTY3MTU0NDc0ALhWhYC1oD1WZobGaCCzO03mRnAzq1E8wOaa1gJmc8P5JgaWpggG+7JiBwASEGDxXMHYoHBwAiUBauoSmOEWe+cX5yBRT1IPvMCO9ACLCrxhTdYIxdIGCTn70LYa4JAjq6JGSK0wZ4DxRuxnvugjOy5SoSTgzPziPQcQiUpnoOkTmaSojKz/vC3/5B0ZmBqaG5qbmFohDdXEEy48Lgl7AGZL6v/ZgYixQ4WCyvBviI5nRAsDkDJNZMh5JUWaoCBjSDs8quv//z35AGKWBhbWBqYQYKMvPCCJxc0WyH+hgYMM6YU8YFFMN0RKk/ABYenGFDEDCVbGKAkFDx+BAcXH6jQsLQ0QpRkhGPpJ9A7mV9IKFkE7gA1IEITpeDGWvQhhRuppSANiwoySzfio3woFPHklYIAG9m/tw=="];
Simplify[ expression1 ]

This returns nearly instantly with three instances of Removed[$$Failure]. Since there is no TimeConstraint set here, I have no idea what the problem is. I submitted a help request to Mathematica, and I'll let you know if they give any useful response. In the meantime, thoughts are most welcome. Especially if you can tell me if the problem exists (or not) in other versions of Mathematica. I am running 9.0.1 on Mac OS 10.8.3. Thank you to Mr. Wizard for verifying the problem exists in MMA 7 on Windows.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
jkrich
  • 131
  • 2
  • 8
  • 2
    What version are you using? What functions is your expression composed of? For example, could you include the output of Union @ Cases[expression, _Symbol, {-1}, Heads -> True] ? – Mr.Wizard Aug 14 '13 at 16:43
  • 1
    @Mr.Wizard I am using 9.0.1.0. The output of your suggestion is {Cosh, E, OD, \[Pi], Plus, Power, Sinh, Times, y, z} – jkrich Aug 14 '13 at 16:48
  • What is OD? Also, what do you get from MemberQ[Names[], "$$Failure"] before running the Simplify line the first time (fresh session)? – Mr.Wizard Aug 14 '13 at 16:51
  • @Mr.Wizard OD is just another variable, like y or z. I know capital letters aren't standard Mathematica style, but old habits... MemberQ[Names[],"$$Failure"] gives False – jkrich Aug 14 '13 at 17:08
  • Okay, I'm out of ideas, and also using version 7. I hope someone is able to help you. – Mr.Wizard Aug 14 '13 at 17:18
  • @Mr.Wizard Thanks for trying. Have you ever seen anything like this before? I don't know what Removed[$$Failure] means. I guess that it replaced a part of my expression where Mathematica was trying a transformation when it hit the TimeConstraint. Rather than return the untransformed piece of the expression (like it should), it returned Return[$$Failure]. But I just made up that story. – jkrich Aug 14 '13 at 17:35
  • Well I know what Removed is; you'll get it when you reference a Symbol that has been removed with Remove (not the same as Removed). For example: a = b; Remove[b]; a returns Removed["b"]. Unfortunately I don't recall seeing $$Failure and I don't know why you're getting it. – Mr.Wizard Aug 14 '13 at 18:04
  • Hum, wild guess: maybe if you Remove and try to access a symbol in the same expression things fail? Then a symbol may have no Context, which could be a problem. Can somebody maybe try {Remove[a],a}? I have no MMA atm. I guess it makes sense to ask if you are using Remove anywhere in your code :) – Jacob Akkerboom Aug 14 '13 at 21:12
  • @JacobAkkerboom Running {Remove[a],a} returns simply {Null, Removed[a]}. There's no $$Failure anywhere. And I don't use Remove in my code. – jkrich Aug 15 '13 at 02:02
  • jkrich, ok that didn't help. Hm I would be interested to see more of your code. Maybe you could use Hold and Compress to post it in more compact form? People here tend not to like a lot of lines of code, but if it is necessary to understand the problem I am sure they will understand. – Jacob Akkerboom Aug 15 '13 at 13:45
  • 2
    Thanks for adding the expression. I can now confirm the behavior exists also in version 7 on Windows. – Mr.Wizard Aug 15 '13 at 14:58
  • 1
    I'm marking this as a bug. It hasn't been confirmed as one by a consensus or official word yet but since nobody can provide an explanation I'm going to make a presumption. Also, the bugs tag will make this easier to track/remember. – Mr.Wizard Aug 16 '13 at 20:26
  • @Mr.Wizard It certainly seems to be a bug, since it exists in multiple versions of MMA and @JacobAkkerboom found such a simple example of the problem. In the short term, this is causing me some problems. Do you know of any way to list and exclude particular built-in transformation rules in Simplify, as mentioned in my comment to Jacob Akkerboom's answer? Any other workaround you can think of? I'm interested in having Simplify use whatever rules it can and return a usable expression (perhaps no simpler than the original). – jkrich Aug 16 '13 at 20:41
  • 1
    I'm afraid I don't know of anything that will help. If you find other expressions that cause a problem and it is a specific pattern (e.g. is it always Cosh?) we may be able to shield it. – Mr.Wizard Aug 16 '13 at 20:55
  • @Mr.Wizard That's an excellent suggestion! I don't know what you meant by shielding it, but I just tried Simplify[ expression1 /. Cosh -> cosh, Sinh -> sinh] /. cosh -> Cosh /. sinh -> Sinh, and it returned a result without any $$Failure. It's only slightly simpler than the original expression (LeafCount down by 10%), but it seems to be formatted correctly, so I can continue using it! – jkrich Aug 16 '13 at 21:07
  • Yes, that's the kind of thing I had in mind. If this is a persistent problem you could write a wrapper for Simplify and FullSimplify that make such replacements automatically, and even include this in your init.m file. I've got several bug fixes in mine as I recall. – Mr.Wizard Aug 16 '13 at 21:11
  • @Mr.Wizard That's easy enough to do. I don't think I want to put this kind of shielding into my init.m, because someday I might want to actually simplify those functions; for this application, though, it seems to be working. I'm curious what other bug fixes you have in your init.m. I know it doesn't really fit in this forum, but maybe it would interesting for people to share their init.ms. I'm sure I'd learn a lot. Thanks again for the help. Also @JacobAkkerboom. – jkrich Aug 16 '13 at 21:20
  • I still use version 7 so they likely don't apply to you. Nevertheless a question (make it Community Wiki) asking for bug-fixes people load on start-up might be productive. – Mr.Wizard Aug 16 '13 at 21:25
  • 1
    Reported as a bug. Will be looked into. – Daniel Lichtblau Aug 19 '13 at 16:15
  • 1
    Seems like it has been fixed in version 10! – Jacob Akkerboom Jul 09 '14 at 21:12
  • If true, that's definitely reason for me to upgrade! I don't have access to 10 yet, though. – jkrich Jul 10 '14 at 01:53

1 Answers1

7

Not really an answer:

I get the same strange behavior, on Mac OSX v 9.0.0. The simplest case I could find where this happens is (thanks to @halirutan)

Simplify[Cosh[1/200] + E^(9200/257)]

Removed[$$Failure]/(2 E^(1/200))

Jacob Akkerboom
  • 12,215
  • 45
  • 79
  • Very peculiar... How did you track down this example? – sebhofer Aug 16 '13 at 12:02
  • @sebhofer Trial, error and patience I'm afraid :P. I just worked my way "down" from the simplest case the OP provides. – Jacob Akkerboom Aug 16 '13 at 12:09
  • Great effort :) – sebhofer Aug 16 '13 at 12:14
  • 1
    That's an excellent example. Is there any way to find out what transformation function Simplify is using when this error occurs? Relatedly, is there a way to get the full list of built-in TransformationFunctions for Simplify? Then maybe it is possible to exclude the offending function? – jkrich Aug 16 '13 at 20:00