2 + 2

2 + 2;

x = 2

2 == 2

2 != 2

x = 2;
x^5

Out[5]

{1, 2, 3, 4}

1, 2, 3, 4

?FactorInteger

FactorInteger[10000]

?N

N[Pi]

N[Pi, 100]

N[E, 100]

N[{Pi, E}]

Table[i^2, {i, 1, 20}]

Sum[i^2, {i, 1, 20}]

Union[{a, c, a, c, b, c, a}]

?Range

Range[20]

Range[-5, 20]

Range[-5, 20, 2]

Range[20]^2

(((2  Range[20] + 1))^2)

Join[{a, b, c}, {1, 2, 3}]

?Part

{a, b, c, 1, 2, 3}[[3]]

Part[{a, b, c, 1, 2, 3}, 3]

Length[{a, b, c, 1, 2, 3}]

First[{a, b, c, 1, 2, 3}]

Rest[{a, b, c, 1, 2, 3}]

x = Range[5]

Table[x, {i, 1, 5}]

Flatten[%]

Transpose[%%]

f[x_] := x^2

f[9]

f[x]

?Rest

?Most

Differences[{e1, e2, ..., ek}] gives {e2 - e1, e3 - e2, ..., ek - e(k-1)}.

Differences[list_] := Rest[list] - Most[list]

Differences[Range[10]]

Table[i^3 - 2  i^2 + i - 5, {i, 0, 20}]

Differences[%]

Differences[%]

Differences[%]

?CoefficientList

CoefficientList[i^3 - 2  i^2 + i - 5, i]

FromCoefficientList reconstructs a polynomial from its list of coefficients.

FromCoefficientListSlow[list_, var_] := 
      Sum[list[[j]] var^(j - 1), {j, 1, Length[list]}]

FromCoefficientListSlow[list_, 
        var_] := (∑_(j = 1)^(Length[list]))list[[
            j]] (var^(j - 1))

FromCoefficientList[list_, var_] := 
      list . (var^Range)[0, Length[list] - 1]

Timing[
      Do[FromCoefficientList[{-5, 1, -2, 1, 3, 10, 44, -10, 2, 4, 
            1, 2, 3}, i], {100000}]]

Timing[
      Do[FromCoefficientListSlow[{-5, 1, -2, 1, 3, 10, 44, -10, 
            2, 4, 1, 2, 3}, i], {100000}]]

Every expression in Mathematica looks like f[a, b, c,  ... , z].

FullForm[a + b]

FullForm[a b]

FullForm[a^b]

FullForm[{a, b, c}]

?Apply

?f

Clear[f]

?f

f @@ g[a, b, c]

Times @@ {a, b, c}

Power @@ {a, b, c}

Power[a, b, c]

Total[{a, b, c, d}]

MyTotal finds the sum of the elements in a list.

MyTotal[list_] := Plus @@ list

MyTotal[Range[10]]

Head[a + b + c]

FullForm[a + b + c]

MyTotal[a + b + c]

MyTotal[a b c]

?FactorInteger

FactorInteger[10000]

?Apply

Apply[Power, {{2, 4}, {5, 4}}, {1}]

Times @@ %

ReassembleInteger re-constructs an integer from its FactorInteger output.

ReassembleInteger[list_] := Times @@ Apply[Power, list, {1}]

ReassembleInteger[list_] := Times @@ Power @@@ list

ReassembleInteger[{{2, 4}, {5, 4}}]

Timing[
      And @@ Table[
          ReassembleInteger[FactorInteger[n]] == n, {n, 1, 
            100000}]]

?Map

f /@ {a, b, c, d}

Map[f, {a, b, c, d}]

f[{a, b, c, d}]

SetAttributes[f, Listable]

f[{a, b, c, d}]

Attributes[Plus]

?Map

Radical[n] gives the product of the prime divisors of n.

Radical[n_] := Times @@ First /@ FactorInteger[n]

FullForm[Times @@ First /@ FactorInteger[n]]

FullForm[Hold[Times @@ First /@ FactorInteger[n]]]

ContinuedFraction[N[Pi, 100]]

ContinuedFraction[355/113]

ContinuedFraction[(1/3) (1 + (Sqrt[2]))]

?Nest

ClearAttributes[f, Listable]

Clear[x]

Nest[f, x, 5]

Fold[f, x, {a, b, c, d}]

(#1^-#2 &)[x, y]

ContinuedFraction[(1/3) (1 + (Sqrt[2]))]

MyFromContinuedFraction reconstructs a quadratic irrational from its periodic continued fraction representation.

ContinuedFraction[Sqrt[23]]

(1/(1 + (1/(3 + (1/(1 + (1/8)))))))

?FoldList

1/x == Fold[(1/(#1 + #2)) &, 0, Reverse[{a, b, c, d, x}]]

Solve[
      (1/x) == Fold[(1/(#1 + #2)) &, 0, Reverse[{1, 3, 1, 8, x}]], 
      x]

?ReplaceAll

x /. {{x -> (1/7) (4 - (Sqrt[23]))}, {x -> 
            (1/7) (4 + (Sqrt[23]))}}

ContinuedFraction[(1/3) (1 + (Sqrt[2]))]

Fold[(1/(#1 + #2)) &, 0, 
      Reverse[{a, b, c, d, 1/periodicpart}]]

?Most

MyFromContinuedFraction[
        list_] := 
Module[{x}, 
FullSimplify[
1/
            Fold[(1/(#1 + #2)) &, 0, 
              Reverse[Append[
                  Most[list], 
Last[(x /. 
                        Solve[
(1/x) == 
                            Fold[(1/(#1 + #2)) &, 0, 
                              Reverse[
                                Append[Last[list], x]]]
, 
                          x
])]
]]]
]
]

MyFromContinuedFraction[
      ContinuedFraction[(1/3) (1 + (Sqrt[2]))]]

Since the current version is sometimes off by -1, here is a version that uses both solutions from Solve:

MyFromContinuedFractionBoth[
        list_] := 
Module[{x}, 
(FullSimplify[
                1/Fold[(1/(#1 + #2)) &, 0, 
                    Reverse[
                      Append[Most[
                          list], #]]]] &) /@ 
(x /. 
              Solve[
(1/x) == 
                  Fold[(1/(#1 + #2)) &, 0, 
                    Reverse[
                      Append[Last[list], 
                        x]]], 
x
])
]

At least we're never wrong!...

MyFromContinuedFractionBoth[
      ContinuedFraction[(1/3) (1 + (Sqrt[2]))]]

MyFromContinuedFractionBoth[ContinuedFraction[(Sqrt[23])]]

MyFromContinuedFractionBoth[ContinuedFraction[-(Sqrt[23])]]

ContinuedFraction[{-(Sqrt[23]), (Sqrt[23])}]

?If

?For

?While

?Do

Cases[Range[100], _?EvenQ | _?PrimeQ]