DISCOVER - Discover

Definite integral is an important part of Mathematical Analysis. During Mathematical Analysis lessons, students always find it quite hard to calculate the definite integral. And the software Mathematic is so complex that very few students can master its usage.

Next is the format for all functions in this challenge:

There are six types of basic elementary function:

  1. constant function: C;
  2. power function: x^C;
  3. exponential function: e^x;
  4. logarithmic function: ln(x);
  5. trigonometric function: sin(x), cos(x), tan(x), cot(x), sec(x), cot(x);
  6. inverse circular trigonometric function: asin(x), acos(x), atan(x).

C is a constant integer number between -100 and 100.

Elementary function is basic elementary function and their composite functions. There are ten types of composite functions. (A and B represent elementary functions)

  1. A+B;
  2. A-B;
  3. -A;
  4. A*B;
  5. A/B;
  6. A^B;
  7. e^A;
  8. ln(A);
  9. sin(A), cos(A), tan(A), cot(A), sec(A), csc(A);
  10. asin(A), acos(A), atan(A).

Arithmetic priority: () > ^ > *,/ > +,-

 

In this problem, the task can be proper integral, improper integral; it is also possible that its indefinite integral isn´t even an elementary function. But you can assume that, if the integrating range is [a,b], then (a,b) will be a subset of the function´s definitions. You can also assume that for any improper integral, the result of it will converge. Finally, it is guaranteed that the final result is between -10,000 and 10,000.

Input

The input consists of several test cases. There is a single number above all, the number of cases. There are no more than 50 cases. Each case contains two lines. The first line contains the function f(x) in the format above. There are no more than 40 letters each. There aren´t any whitespaces in the function.

The second line contains a and b, both of which can be string "INF" or "-INF"(quotes for clarify) - positive infinity and negative infinity respectively, or a floating point number between -100 and 100.

Output

For each case, print the value of . The answer should be rounded to six digits to the right of the decimal point. Use the format in the sample.

Example

Input:
3
x
1 2
sin(x)^2/(sin(x)+cos(x))
0 1.5707963268
e^(-x)
0 INF

Output:
Case 1: 1.500000
Case 2: 0.623225
Case 3: 1.000000

The judge is "Score is source length".


Added by:Fudan University Problem Setters
Date:2008-05-24
Time limit:4s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:BF C CSHARP C++ 4.3.2 CPP CPP14 C99 HASK ICK JAVA PERL PYTHON WHITESPACE
Resource:A Chinese Invitation Contest in 2008

hide comments
2020-08-24 20:08:24 Mitch Schwartz
@Blue.Mary: I left an extensive comment in my first AC solution (ID 26477068) regarding two hard test cases that I DISCOVERed in the test data... Would it be possible to shed any light on what your intentions were regarding those tests? Did I miss something, and is it actually possible to handle those using a general purpose quadrature method (without a huge number of function evaluations)?

(I implemented a specialized method to handle those two tests, but it's a strange situation for golfing.)

Last edit: 2020-08-24 21:17:56
2020-08-10 00:31:54
ok ok, still hard af :)
2020-07-18 23:47:36 Mitch Schwartz
regarding "after 11 years" - this was not published here in 2008, that is merely when the problem id was created. i guess it was published sometime around april 2017 based on submission history of SINGLEL.
2019-11-15 15:18:24
alter 11 years ... :)
2019-11-15 15:12:18
for anyone trying to solve it ... please don't even try ;)
- check your evaluation function, so many many test cases...
- integration - you should be aware what happens if you use for example newton-coets method for such a beauty: https://www.wolframalpha.com/input/?i=integral+from+0+to+1+ln%28sin%28x%29%29
2019-11-15 15:10:09
this is just madness... finally got it :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.