M2 icon indicating copy to clipboard operation
M2 copied to clipboard

try fails to catch alarm

Open pzinn opened this issue 1 year ago • 3 comments

There are already existing open issues with alarm, this I think is a new one:

i1 : try (alarm 1; sleep 15;) else <<"should end up here (and does)"<<endl;
should end up here (and does)

i2 : try (alarm 1; sleep 15) else <<"should end up here (and doesn't)"<<endl;
stdio:2:51:(3): error: alarm occurred

This issue is presumably related to tail call optimisation (?). Note that I already submitted a PR a while ago about tail call, namely https://github.com/Macaulay2/M2/pull/3144, but it does not impact the issue described above.

I traced the issue to two different places that alarm is triggered, both in evaluate.d, namely evalraw in the first case, evalexcept in the second. I could try to fix something but first I would need to understand better the difference between these two functions. Note that evalraw has this comment

	  if test(exceptionFlag) && !steppingFurther(c) then (    -- compare this code to the code in evalexcept() below

presumably suggesting I should notice something that I don't...

pzinn avatar Jul 21 '24 09:07 pzinn

Bugs that are harder to fix

  • \frac{0}{1-1} and \frac{1-1}{0} (\frac{0}{0} works)
  • 2(x+h)^2-2x^2 ((x+h)^2-x^2 and 2(x+h)(x+h)-x^2 work)
  • \frac{\pi+1}{\pi+1} (\frac{\pi}{\pi} works)
  • \frac{x^2}{5x^2} (\frac{5x^2}{x^2} works)
  • (-1)^{3/5} (should be -1 not i)
  • \frac{\frac{1}{x^6}}{\frac{1}{y^4}} becomes \frac{y^4}{x^6} (good) but \left(\frac{x^3}{y^2}\right)^{-2} becomes \frac{\frac{1}{x^6}}{\frac{1}{y^4}} (should be \frac{y^4}{x^6})
  • exp(x)exp(2) (e^xe^2 works)
  • \frac{x+1-1+1}{x+1} (\frac{x+1-1+1}{x} works)
  • (-2x)^{3/5}x simplifies to (i)\sqrt{2}x^{8/5} not -2^{3/5}x^{8/5} ((2x)^{3/5}x works)
  • (x^3y^2)^2 ((x^3)^2(y^2)^2 and \left(\frac{x^3}{y^2}\right)^2 work)
  • \frac{2\sqrt{3}}{\sqrt{3}} becomes 2 (good) but \frac{\sqrt{12x}}{\sqrt{3x}} becomes \frac{2\sqrt{3}}{\sqrt{3}}
  • \sqrt{12} (\frac{\sqrt{12x}}{\sqrt{x}} works)
  • \sqrt{x^2y}
  • \sqrt{x^2}, \sqrt[4]{x^4} (missing absolute value)
  • \sqrt[4]{x^6} (missing absolute value inside of root)

Logs

  • log(e^xy) (ln(e^xy) works)
  • ln(\frac{x}{y}) (log(\frac{x}{y}) works)
  • log(xy)-log(x)-log(y) (ln(xy)-ln(x)-ln(y) works)
  • log(1) (ln(1) works)
  • log(e) (ln(e) works)
  • exp(log(x))
  • exp(clog(x))
  • exp(log(x)+y)
  • exp(log(x)-y)
  • log(exp(x)) (ln(exp(x)) works)
  • \log(\sqrt{2}) and \ln(\sqrt{2}) (\log(\sqrt{x}) and \ln(\sqrt{x}) work)

Negative Signs

  • (-x)(-6)
  • -\frac{-1}{x} (\frac{-1}{-x} works)
  • (-x)^2 ((-2x)^2 works)

Properties of Exponents

  • 2xx (xx works)
  • \frac{e^x}{e}
  • \frac{e}{e^x}
  • e^xe and e^xe^1 (e^xe^2 works)
  • \left(\frac{1}{x}\right)^{-1}

Other Powers

  • 0^0
  • 0^\pi (0^{3.1} works)

Infinity

  • \infty^0
  • \infty(1-1) (\infty(0) works)
  • 1^\infty
  • -\infty(-2) and \infty(-2) (-\infty(2) and \infty(2) work)
  • \frac{\infty}{2}
  • \frac{\infty}{\infty}
  • \frac{\infty}{\infty^{-2}}

Miscellaneous

  • \frac{1}{0}

Trig

  • sec(-x) is 1/cos(x) but I believe sec(x) is nicer
  • Similarly for csc(pi+x), tan(pi/2-x), sec(pi/2-x), csc(pi/2-x)
  • cot(pi+x) is supposed to be cot(x) but set to -cot(x)
  • tan(-x)cot(x) becomes -tan(x)cot(x) and tan(x)cot(x) becomes 1 but tan(-x)cot(x) doesn't become -1
  • sin^2(x) is simplified to 1/2(1-cos(2x)) but 2sin^2(x) is not simplified at all
  • sin(x)cos(x) is simplified to sin(2x)/2 but 2sin(x)cos(x) is not simplified at all

andrew-murdza avatar Jul 04 '24 23:07 andrew-murdza