comb: any value above 40 returns infinity? not sure why

  • Last Update :
  • Techknowledgy :

Try this:

def B(x):
   product = 1
for i in range(x + 1):
   product *= comb(x, i, exact = True)
return int(product)

B(40)

Suggestion : 2

W3C Working Draft, 16 December 2021

example(first ? , second ? , third ? )
Value: collapse | separate

And here is an example of its use:

table {
   border - collapse: separate
}
.foo {
   --fg - color: blue;
}
device-cmyk
@color - profile--foo {
      src: url(https: //example.com/foo.icc); }
            .foo {
               color: color(--foo 1 0 .5 / .2);
            }
'\27'
content: "this is a 'string'.";
content: "this is a \"string\".";
content: 'this is a "string".';
content: 'this is a \'string\'.'

Example(s):

a[title = "a not s\
o very long title"] {
   /*...*/ }
a[title = "a not so very long title"] {
   /*...*/ }

Suggestion : 3

In that case, the starting row used by the PREV() function for its navigation is the last row mapped to pattern variable B.,The CLASSIFIER function returns a character string whose value is the name of the pattern variable to which a row is mapped. The CLASSIFIER function is allowed in both the MEASURES and the DEFINE clauses.,DEFINE is a required clause, used to specify the conditions that a row must meet to be mapped to a specific pattern variable.,This example declares a single union row pattern variable, STDN, and defines it as the union of the rows mapped to STRT and the rows mapped to DOWN. There can be multiple union row pattern variables in a query. For example:

Example 20-1 Pattern Match: Simple V-Shape with 1 Row Output per Match

CREATE TABLE Ticker(SYMBOL VARCHAR2(10), tstamp DATE, price NUMBER);

INSERT INTO Ticker VALUES('ACME', '01-Apr-11', 12);
INSERT INTO Ticker VALUES('ACME', '02-Apr-11', 17);
INSERT INTO Ticker VALUES('ACME', '03-Apr-11', 19);
INSERT INTO Ticker VALUES('ACME', '04-Apr-11', 21);
INSERT INTO Ticker VALUES('ACME', '05-Apr-11', 25);
INSERT INTO Ticker VALUES('ACME', '06-Apr-11', 12);
INSERT INTO Ticker VALUES('ACME', '07-Apr-11', 15);
INSERT INTO Ticker VALUES('ACME', '08-Apr-11', 20);
INSERT INTO Ticker VALUES('ACME', '09-Apr-11', 24);
INSERT INTO Ticker VALUES('ACME', '10-Apr-11', 25);
INSERT INTO Ticker VALUES('ACME', '11-Apr-11', 19);
INSERT INTO Ticker VALUES('ACME', '12-Apr-11', 15);
INSERT INTO Ticker VALUES('ACME', '13-Apr-11', 25);
INSERT INTO Ticker VALUES('ACME', '14-Apr-11', 25);
INSERT INTO Ticker VALUES('ACME', '15-Apr-11', 14);
INSERT INTO Ticker VALUES('ACME', '16-Apr-11', 12);
INSERT INTO Ticker VALUES('ACME', '17-Apr-11', 14);
INSERT INTO Ticker VALUES('ACME', '18-Apr-11', 24);
INSERT INTO Ticker VALUES('ACME', '19-Apr-11', 23);
INSERT INTO Ticker VALUES('ACME', '20-Apr-11', 22);

SELECT *
   FROM Ticker MATCH_RECOGNIZE(
      PARTITION BY symbol ORDER BY tstamp MEASURES STRT.tstamp AS start_tstamp,
      LAST(DOWN.tstamp) AS bottom_tstamp,
      LAST(UP.tstamp) AS end_tstamp ONE ROW PER MATCH AFTER MATCH SKIP TO LAST UP PATTERN(STRT DOWN + UP + ) DEFINE DOWN AS DOWN.price < PREV(DOWN.price),
      UP AS UP.price > PREV(UP.price)
   ) MR
ORDER BY MR.symbol, MR.start_tstamp;

SYMBOL START_TST BOTTOM_TS END_TSTAM
-- -- -- -- -- -- -- -- -- - -- -- -- -- - -- -- -- -- -
ACME 05 - APR - 11 06 - APR - 11 10 - APR - 11
ACME 10 - APR - 11 12 - APR - 11 13 - APR - 11
ACME 14 - APR - 11 16 - APR - 11 18 - APR - 11

The first line in this example is to improve formatting if you are using SQL*Plus.

column var_match format a4

SELECT *
   FROM Ticker MATCH_RECOGNIZE(
      PARTITION BY symbol ORDER BY tstamp MEASURES STRT.tstamp AS start_tstamp,
      FINAL LAST(DOWN.tstamp) AS bottom_tstamp,
      FINAL LAST(UP.tstamp) AS end_tstamp,
      MATCH_NUMBER() AS match_num,
      CLASSIFIER() AS var_match ALL ROWS PER MATCH AFTER MATCH SKIP TO LAST UP PATTERN(STRT DOWN + UP + ) DEFINE DOWN AS DOWN.price < PREV(DOWN.price),
      UP AS UP.price > PREV(UP.price)
   ) MR
ORDER BY MR.symbol, MR.match_num, MR.tstamp;

SYMBOL TSTAMP START_TST BOTTOM_TS END_TSTAM MATCH_NUM VAR_ PRICE
-- -- -- -- -- -- -- -- -- - -- -- -- -- - -- -- -- -- - -- -- -- -- - -- -- -- -- -- -- -- -- -- -- -- --
ACME 05 - APR - 11 05 - APR - 11 06 - APR - 11 10 - APR - 11 1 STRT 25
ACME 06 - APR - 11 05 - APR - 11 06 - APR - 11 10 - APR - 11 1 DOWN 12
ACME 07 - APR - 11 05 - APR - 11 06 - APR - 11 10 - APR - 11 1 UP 15
ACME 08 - APR - 11 05 - APR - 11 06 - APR - 11 10 - APR - 11 1 UP 20
ACME 09 - APR - 11 05 - APR - 11 06 - APR - 11 10 - APR - 11 1 UP 24
ACME 10 - APR - 11 05 - APR - 11 06 - APR - 11 10 - APR - 11 1 UP 25
ACME 10 - APR - 11 10 - APR - 11 12 - APR - 11 13 - APR - 11 2 STRT 25
ACME 11 - APR - 11 10 - APR - 11 12 - APR - 11 13 - APR - 11 2 DOWN 19
ACME 12 - APR - 11 10 - APR - 11 12 - APR - 11 13 - APR - 11 2 DOWN 15
ACME 13 - APR - 11 10 - APR - 11 12 - APR - 11 13 - APR - 11 2 UP 25
ACME 14 - APR - 11 14 - APR - 11 16 - APR - 11 18 - APR - 11 3 STRT 25
ACME 15 - APR - 11 14 - APR - 11 16 - APR - 11 18 - APR - 11 3 DOWN 14
ACME 16 - APR - 11 14 - APR - 11 16 - APR - 11 18 - APR - 11 3 DOWN 12
ACME 17 - APR - 11 14 - APR - 11 16 - APR - 11 18 - APR - 11 3 UP 14
ACME 18 - APR - 11 14 - APR - 11 16 - APR - 11 18 - APR - 11 3 UP 24

15 rows selected.

Example 20-3 highlights the use of aggregate functions in pattern matching queries.

SELECT *
   FROM Ticker MATCH_RECOGNIZE(
      PARTITION BY symbol ORDER BY tstamp MEASURES MATCH_NUMBER() AS match_num,
      CLASSIFIER() AS var_match,
      FINAL COUNT(UP.tstamp) AS up_days,
      FINAL COUNT(tstamp) AS total_days,
      RUNNING COUNT(tstamp) AS cnt_days,
      price - STRT.price AS price_dif ALL ROWS PER MATCH AFTER MATCH SKIP TO LAST UP PATTERN(STRT DOWN + UP + ) DEFINE DOWN AS DOWN.price < PREV(DOWN.price),
      UP AS UP.price > PREV(UP.price)
   ) MR
ORDER BY MR.symbol, MR.match_num, MR.tstamp;

SYMBOL TSTAMP MATCH_NUM VAR_ UP_DAYS TOTAL_DAYS CNT_DAYS PRICE_DIF PRICE
-- -- -- -- -- -- -- - -- -- -- -- - -- -- -- -- -- - -- -- -- -- -- -- -- -- -- -- -- -- -- - -- -- -
ACME 05 - APR - 11 1 STRT 4 6 1 0 25
ACME 06 - APR - 11 1 DOWN 4 6 2 - 13 12
ACME 07 - APR - 11 1 UP 4 6 3 - 10 15
ACME 08 - APR - 11 1 UP 4 6 4 - 5 20
ACME 09 - APR - 11 1 UP 4 6 5 - 1 24
ACME 10 - APR - 11 1 UP 4 6 6 0 25
ACME 10 - APR - 11 2 STRT 1 4 1 0 25
ACME 11 - APR - 11 2 DOWN 1 4 2 - 6 19
ACME 12 - APR - 11 2 DOWN 1 4 3 - 10 15
ACME 13 - APR - 11 2 UP 1 4 4 0 25
ACME 14 - APR - 11 3 STRT 2 5 1 0 25
ACME 15 - APR - 11 3 DOWN 2 5 2 - 11 14
ACME 16 - APR - 11 3 DOWN 2 5 3 - 13 12
ACME 17 - APR - 11 3 UP 2 5 4 - 11 14
ACME 18 - APR - 11 3 UP 2 5 5 - 1 24

15 rows selected.

This example illustrates a W-Shape.

SELECT *
   FROM Ticker MATCH_RECOGNIZE(
      PARTITION BY symbol ORDER BY tstamp MEASURES MATCH_NUMBER() AS match_num,
      CLASSIFIER() AS var_match,
      STRT.tstamp AS start_tstamp,
      FINAL LAST(UP.tstamp) AS end_tstamp ALL ROWS PER MATCH AFTER MATCH SKIP TO LAST UP PATTERN(STRT DOWN + UP + DOWN + UP + ) DEFINE DOWN AS DOWN.price < PREV(DOWN.price),
      UP AS UP.price > PREV(UP.price)
   ) MR
ORDER BY MR.symbol, MR.match_num, MR.tstamp;

SYMBOL TSTAMP MATCH_NUM VAR_ START_TST END_TSTAM PRICE
-- -- -- -- -- -- -- -- -- - -- -- -- -- -- -- -- -- -- -- -- - -- -- -- -- - -- -- -- -- --
ACME 05 - APR - 11 1 STRT 05 - APR - 11 13 - APR - 11 25
ACME 06 - APR - 11 1 DOWN 05 - APR - 11 13 - APR - 11 12
ACME 07 - APR - 11 1 UP 05 - APR - 11 13 - APR - 11 15
ACME 08 - APR - 11 1 UP 05 - APR - 11 13 - APR - 11 20
ACME 09 - APR - 11 1 UP 05 - APR - 11 13 - APR - 11 24
ACME 10 - APR - 11 1 UP 05 - APR - 11 13 - APR - 11 25
ACME 11 - APR - 11 1 DOWN 05 - APR - 11 13 - APR - 11 19
ACME 12 - APR - 11 1 DOWN 05 - APR - 11 13 - APR - 11 15
ACME 13 - APR - 11 1 UP 05 - APR - 11 13 - APR - 11 25

The pattern matching syntax is as follows:

table_reference:: = {
      only(query_table_expression) | query_table_expression
   } [flashback_query_clause]
   [pivot_clause | unpivot_clause | row_pattern_recognition_clause][t_alias]

row_pattern_recognition_clause:: =
   MATCH_RECOGNIZE(
      [row_pattern_partition_by]
      [row_pattern_order_by]
      [row_pattern_measures]
      [row_pattern_rows_per_match]
      [row_pattern_skip_to] PATTERN(row_pattern)[row_pattern_subset_clause] DEFINE row_pattern_definition_list
   )

row_pattern_partition_by:: =
   PARTITION BY column[, column]...

   row_pattern_order_by:: =
   ORDER BY column[, column]...

   row_pattern_measures:: =
   MEASURES row_pattern_measure_column[, row_pattern_measure_column]...

   row_pattern_measure_column:: =
   expression AS c_alias

row_pattern_rows_per_match:: =
   ONE ROW PER MATCH |
   ALL ROWS PER MATCH

row_pattern_skip_to:: =
   AFTER MATCH {
      SKIP TO NEXT ROW
         |
         SKIP PAST LAST ROW |
         SKIP TO FIRST variable_name |
         SKIP TO LAST variable_name |
         SKIP TO variable_name
   }

row_pattern:: =
   row_pattern_term |
   row_pattern "|"
row_pattern_term

row_pattern_term:: =
   row_pattern_factor |
   row_pattern_term row_pattern_factor

row_pattern_factor:: =
   row_pattern_primary[row_pattern_quantifier]

row_pattern_quantifier:: = *
   [ ? ] |
   +[ ? ] |
   ? [ ? ] |
   "{" [unsigned_integer], [unsigned_integer]
"}" [ ? ] |
"{"
unsigned_integer "}"

row_pattern_primary:: =
   variable_name |
   $ |
   ^
   |
   ([row_pattern]) |
   "{-"
row_pattern "-}" |
   row_pattern_permute

row_pattern_permute:: =
   PERMUTE(row_pattern[, row_pattern]...)

row_pattern_subset_clause:: =
   SUBSET row_pattern_subset_item[, row_pattern_subset_item]...

   row_pattern_subset_item:: =
   variable_name = (variable_name[, variable_name]...)

row_pattern_definition_list:: =
   row_pattern_definition[, row_pattern_definition]...

   row_pattern_definition:: =
   variable_name AS condition

The syntax for row pattern operations inside pattern matching is:

function:: =
single_row_function
   |
   aggregate_function |
   analytic_function |
   object_reference_function |
   model_function |
   user_defined_function |
   OLAP_function |
   data_cartridge_function |
   row_pattern_recognition_function

row_pattern_recognition_function:: =
   row_pattern_classifier_function |
   row_pattern_match_number_function |
   row_pattern_navigation_function |
   row_pattern_aggregate_function

row_pattern_classifier_function:: =
   CLASSIFIER()

row_pattern_match_number_function:: =
   MATCH_NUMBER()

row_pattern_navigation_function:: =
   row_pattern_navigation_logical |
   row_pattern_navigation_physical |
   row_pattern_navigation_compound

row_pattern_navigation_logical:: = [RUNNING | FINAL] {
   FIRST | LAST
}(expression[, offset])

row_pattern_navigation_physical:: = {
   PREV | NEXT
}(expression[, offset])

row_pattern_navigation_compound:: = {
   PREV | NEXT
}(
   [RUNNING | FINAL] {
      FIRST | LAST
   }(expression[, offset])[, offset])

The syntax for set function specification inside the pattern matching clause is:

row_pattern_aggregate_function:: = [RUNNING | FINAL] aggregate_function

The difference between greedy and reluctant quantifiers appended to a single pattern variable is illustrated as follows: A* tries to map as many rows as possible to A, whereas A*? tries to map as few rows as possible to A. For example:

PATTERN(X Y * Z)