Skip to main content
Commonmark migration
Source Link

#Mathematica 56-3 = 53

Mathematica 56-3 = 53

Update: I added a second method, of precisely the same code size, that uses a named function. It employs an Array rather than a Table but follows the same logic. (See below.)

Method 1

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers. Anonymous functions such as the following, are most useful if they are used only once in a program. Otherwise it makes more sense to use a named function.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2


Method 2 (Also 56-3 = 53)

This works similarly to Method 1. But it requires less code when called. And the cells are addressable, unlike cells in a table. This method is better to use if the function will be used more than once.

a_~f~b_:=Grid@Array[If[#>a,a,b]If[#2>a,b,a]&,{a+b,a+b}] 

The examples from above are produced by the following:

Ex 1:

f[4,3] 

Ex 2:

f[0,3] 

#Mathematica 56-3 = 53

Update: I added a second method, of precisely the same code size, that uses a named function. It employs an Array rather than a Table but follows the same logic. (See below.)

Method 1

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers. Anonymous functions such as the following, are most useful if they are used only once in a program. Otherwise it makes more sense to use a named function.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2


Method 2 (Also 56-3 = 53)

This works similarly to Method 1. But it requires less code when called. And the cells are addressable, unlike cells in a table. This method is better to use if the function will be used more than once.

a_~f~b_:=Grid@Array[If[#>a,a,b]If[#2>a,b,a]&,{a+b,a+b}] 

The examples from above are produced by the following:

Ex 1:

f[4,3] 

Ex 2:

f[0,3] 

Mathematica 56-3 = 53

Update: I added a second method, of precisely the same code size, that uses a named function. It employs an Array rather than a Table but follows the same logic. (See below.)

Method 1

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers. Anonymous functions such as the following, are most useful if they are used only once in a program. Otherwise it makes more sense to use a named function.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2


Method 2 (Also 56-3 = 53)

This works similarly to Method 1. But it requires less code when called. And the cells are addressable, unlike cells in a table. This method is better to use if the function will be used more than once.

a_~f~b_:=Grid@Array[If[#>a,a,b]If[#2>a,b,a]&,{a+b,a+b}] 

The examples from above are produced by the following:

Ex 1:

f[4,3] 

Ex 2:

f[0,3] 
added 555 characters in body
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106

#Mathematica 56-3 = 53

Update: I added a second method, of precisely the same code size, that uses a named function. It employs an Array rather than a Table but follows the same logic. (See below.)

Method 1

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers. Anonymous functions such as the following, are most useful if they are used only once in a program. Otherwise it makes more sense to use a named function.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2


Method 2 (Also 56-3 = 53)

This works similarly to Method 1. But it requires less code when called. And the cells are addressable, unlike cells in a table. This method is better to use if the function will be used more than once.

a_~f~b_:=Grid@Array[If[#>a,a,b]If[#2>a,b,a]&,{a+b,a+b}] 

The examples from above are produced by the following:

Ex 1:

f[4,3] 

Ex 2:

f[0,3] 

#Mathematica 56-3 = 53

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2

#Mathematica 56-3 = 53

Update: I added a second method, of precisely the same code size, that uses a named function. It employs an Array rather than a Table but follows the same logic. (See below.)

Method 1

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers. Anonymous functions such as the following, are most useful if they are used only once in a program. Otherwise it makes more sense to use a named function.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2


Method 2 (Also 56-3 = 53)

This works similarly to Method 1. But it requires less code when called. And the cells are addressable, unlike cells in a table. This method is better to use if the function will be used more than once.

a_~f~b_:=Grid@Array[If[#>a,a,b]If[#2>a,b,a]&,{a+b,a+b}] 

The examples from above are produced by the following:

Ex 1:

f[4,3] 

Ex 2:

f[0,3] 
added 305 characters in body
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106

#Mathematica 56-3 = 53

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers.

Each factor is an If-then statement. If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.

If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2

#Mathematica 56-3 = 53

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers.

Each factor is an If-then statement. If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.

If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Example 1

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2

#Mathematica 56-3 = 53

This makes a table of products, the factors of which depend on the row, column values. The pair of numbers is entered as a list of integers.

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]& 

Each factor is an If-then statement:

  • If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
  • If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1

 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3} 

ex1


Example 2

Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3} 

ex2

added 305 characters in body
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106
Loading
added 326 characters in body
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106
Loading
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106
Loading