(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



(* :Name: EPM`Lists` *)


(* :Book: Essentials of Programming in Mathematica *)


(* :Author: Paul Wellin *)


(* :Summary: This package contains the functions defined in Chapter 3 Lists. *)


(* :Context: EPM`Lists` *)


(* :Package Version: 1.0 *)


(* :Copyright: Copyright 2015, Paul R Wellin *)


(* :History: Version 1.0 by Paul Wellin, Dec 2012 *)


(* :Keywords: integer lattice, palindromes, Pascal's triangle, Ngrams *)


(* :Source: Lists.nb *)


(* :Mathematica Version: 10.2 *)


(* Tested in Mathematica 11.1 *)


Remove[AddColumn,Lattice,NGrams,palindromeQ,PascalTable,TriangleForm]


(*BeginPackage["EPM`Lists`"]*)


AddColumn::usage="AddColumn[\!\(\*
StyleBox[\"mat\", \"TI\"]\), \!\(\*
StyleBox[\"col\", \"TI\"]\), \!\(\*
StyleBox[\"pos\", \"TI\"]\)] inserts the column vector \!\(\*
StyleBox[\"col\", \"TI\"]\) to the matrix \!\(\*
StyleBox[\"mat\", \"TI\"]\) at position \!\(\*
StyleBox[\"pos\", \"TI\"]\).";


Lattice::usage="Lattice[{{\!\(\*
StyleBox[\"xmin\", \"TI\"]\), \!\(\*
StyleBox[\"xmax\", \"TI\"]\)},{\!\(\*
StyleBox[\"ymin\", \"TI\"]\), \!\(\*
StyleBox[\"ymax\", \"TI\"]\)}}] creates a two-dimensional rectangular lattice.";


NGrams::usage="NGrams[\!\(\*
StyleBox[\"text\", \"TI\"]\), \!\(\*
StyleBox[\"n\", \"TI\"]\)] splits \!\(\*
StyleBox[\"text\", \"TI\"]\) into overlapping lists of \!\(\*
StyleBox[\"n\", \"TI\"]\) words.";


palindromeQ::usage="palindromeQ[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if the \!\(\*
StyleBox[\"n\", \"TI\"]\) is a palindromic number.";


If[$VersionNumber<10.3,
PalindromeQ::usage="PalindromeQ[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if the \!\(\*
StyleBox[\"n\", \"TI\"]\) is a palindromic number.";,
palindromeQ::usage="palindromeQ[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if the \!\(\*
StyleBox[\"n\", \"TI\"]\) is a palindromic number.";
]


PascalTable::usage="PascalTable[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns the first \!\(\*
StyleBox[\"n\", \"TI\"]\) rows of Pascal's Triangle, where the \!\(\*
StyleBox[\"n\", \"TI\"]\)th row consists of the coefficients of the expansion of the polynomial (1\[VeryThinSpace]+\[VeryThinSpace]\!\(\*
StyleBox[\"x\", \"TI\"]\)\!\(\*SuperscriptBox[\()\), 
StyleBox[\"n\", \"TI\"]]\).";


TriangleForm::usage="TriangleForm[\!\(\*
StyleBox[\"lis\", \"TI\"]\)] displays the list \!\(\*
StyleBox[\"lis\", \"TI\"]\) in a triangular form, padding shorter rows to the same length as the longest row.";


Begin["`Private`"]


AddColumn[mat_,col_,pos_]/;Length[col]==Length[mat]:=Transpose[Insert[Transpose[mat],col,pos]]


Lattice[{{xmin_,xmax_},{ymin_,ymax_}}]:=Module[{coords},
coords=CoordinateBoundsArray[{{xmin,xmax},{ymin,ymax}}];
Graphics[{
Line[coords],Line[Transpose[coords]],
PointSize[Medium],Point[Flatten[coords,1]]
}]]


Lattice[{xdim_,ydim_}]:=Module[{coords},
coords=Table[{i,j},{i,1,xdim},{j,1,ydim}];
Graphics[{
Line[coords],Line[Transpose[coords]],
PointSize[Medium],Point[Flatten[coords,1]]
}]]


NGrams[text_,n_]:=Partition[TextWords[text],n,1]


If[$VersionNumber<10.3, 
	PalindromeQ[num_Integer]:=IntegerDigits[num]==Reverse[IntegerDigits[num]];,
palindromeQ[num_Integer]:=IntegerDigits[num]==Reverse[IntegerDigits[num]];
]


PascalTable[rows_]:=Table[Binomial[n,m],{n,0,rows},{m,0,n}]


TriangleForm[expr_]:=Block[{rows=Length[expr]},DisplayForm[GridBox[Map[PadLeft[Rest[Flatten[Map[{"",#}&,#]]],2rows+1,"",rows-Length[#]+1]&,expr]]]]


End[]


(*EndPackage[]*)



