(* ::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`Language` *)


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


(* :Author: Paul Wellin *)


(* :Summary: This package contains the functions defined in Chapter 2, The Mathematica language. *)


(* :Context: EPM`Language` *)


(* :Package Version: 1.0 *)


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


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


(* :Keywords: composite numbers, DenseGraphQ, digit sums, natural numbers, square numbers, triangular numbers, square triangular numbers  *)


(* :Source: Language.nb *)


(* :Mathematica Version: 10.3 *)


(* Tested in Mathematica 11.1 *)


Remove[compositeQ,DenseGraphQ,DigitSum,IntegerRotateRight,NaturalQ,RealPositiveQ,SquareNumberQ,SquareTriangularNumberQ,StringCharacterQ,TriangularNumberQ]


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


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


DenseGraphQ::usage="DenseGraphQ[\!\(\*
StyleBox[\"gr\", \"TI\"]\)] returns true if the graph \!\(\*
StyleBox[\"gr\", \"TI\"]\) is dense, i.e., if \!\(\*
StyleBox[\"gr\", \"TI\"]\) has density greater than or equal to 0.5";


DigitSum::usage="DigitSum[\!\(\*
StyleBox[\"n\", \"TI\"]\)\!\(\*
StyleBox[\",\", \"TI\"]\)\!\(\*
StyleBox[\" \", \"TI\"]\)\!\(\*
StyleBox[\"b\", \"TI\"]\)] returns the sum of the digits of the number \!\(\*
StyleBox[\"n\", \"TI\"]\) in base \!\(\*
StyleBox[\"b\", \"TI\"]\).";


IntegerRotateRight::usage="IntegerRotateRight[\!\(\*
StyleBox[\"n\", \"TI\"]\)] rotates the digits in the integer \!\(\*
StyleBox[\"n\", \"TI\"]\) one digit to the right.";


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


RealPositiveQ::usage="RealPositiveQ[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if the the number \!\(\*
StyleBox[\"n\", \"TI\"]\) is a positive real number.\nRealPositiveQ[\!\(\*
StyleBox[\"vec\", \"TI\"]\)] returns True if \!\(\*
StyleBox[\"vec\", \"TI\"]\) is a vector of numbers all of which are real and positive.";


SquareNumberQ::usage="SquareNumber[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if the square root of \!\(\*
StyleBox[\"n\", \"TI\"]\) is an integer.";


SquareTriangularNumberQ::usage="SquareTriangularNumberQ[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if \!\(\*
StyleBox[\"n\", \"TI\"]\) is both a square number and a triangular number.";


StringCharacterQ::usage="StringCharacterQ[\!\(\*
StyleBox[\"c\", \"TI\"]\)] returns True if \!\(\*
StyleBox[\"c\", \"TI\"]\) is a string of length one.";


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


Begin["`Private`"]


compositeQ[n_Integer/;n>1]:=Not[PrimeQ[n]]


DenseGraphQ[gr_Graph]:=2EdgeCount[gr]/(VertexCount[gr](VertexCount[gr]-1))>=0.5


DigitSum[n_,base_:10]:=Total[IntegerDigits[n,base]]


IntegerRotateRight[n_Integer]:=FromDigits[RotateRight[IntegerDigits[n]]]


NaturalQ[n_]:=IntegerQ[n]&&n>=0


RealPositiveQ[n_?NumericQ]:=Im[n]==0&&Positive[n]


RealPositiveQ[vec_?VectorQ]:=AllTrue[vec,RealPositiveQ]


SquareNumberQ[n_]:=IntegerQ[Sqrt[n]]


SquareTriangularNumberQ[n_]:=TriangularNumberQ[n]&&SquareNumberQ[n]


StringCharacterQ[ch_]:=StringQ[ch]&&StringLength[ch]==1


TriangularNumberQ[t_]:=OddQ[Sqrt[8t+1]]&&SquareNumberQ[8t+1]


End[]


(*EndPackage[]*)



