Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Julia 1.0 Programming
Julia 1.0 Programming

Julia 1.0 Programming: Dynamic and high-performance programming to build fast scientific applications , Second Edition

eBook
R$49.99 R$196.99
Paperback
R$245.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Julia 1.0 Programming

Variables, Types, and Operations

Julia is an optionally typed language, which means that the user can choose to specify the type of arguments passed to a function and the type of variables used inside a function. Julia's type system is the key for its performance; understanding it well is important, and it can pay off to use type annotations, not only for documentation or tooling, but also for execution speed. This chapter discusses the realm of elementary built-in types in Julia, the operations that can be performed on them, as well as the important concepts of types and scope.

The following topics are covered in this chapter:

  • Variables, naming conventions, and comments
  • Types
  • Integers
  • Floating point numbers
  • Elementary mathematical functions and operations
  • Rational and complex numbers
  • Characters
  • Strings
  • Regular expressions
  • Ranges and arrays
  • Dates and times
  • Scope and constants...

Variables, naming conventions, and comments

Data is stored in values such as 1, 3.14, and "Julia", and every other value has a type, for example, the type of 3.14 is Float64. Some other examples of elementary values and their data types are 42 of the Int64 type, true and false of the Bool type, and 'X' of the Char type.

Julia, unlike many modern programming languages, differentiates between single characters and strings. Strings can contain any number of characters, and are specified using double quotes—single quotes are only used for a character literal. Variables are the names that are bound to values by assignments, such as x = 42. They have the type of the value they contain (or reference); this type is given by the typeof function. For example, typeof(x) returns Int64.

The type of a variable can change, because putting x = "I am Julia...

Types

Julia's type system is unique. Julia behaves as a dynamically typed language (such as Python, for instance) most of the time. This means that a variable bound to an integer at one point might later be bound to a string. For example, consider the following:

julia> x = 10 
10 
julia> x = "hello" 
"hello" 

However, one can, optionally, add type information to a variable. This causes the variable to only accept values that match that specific type. This is done through a type of annotation. For instance, declaring x::String implies that only strings can be bound to x; in general, it looks like var::TypeName. These are used the most often to qualify the arguments a function can take. The extra type information is useful for documenting the code, and often allows the JIT compiler to generate better-optimized native code. It also allows the development...

Integers

Julia offers support for integer numbers ranging from types Int8 to Int128, with 8 to 128 representing the number of bits used, and with unsigned variants with a U prefix, such as UInt8. The default type (which can also be used as Int) is Int32 or Int64, depending on the target machine architecture. The bit width is given by the Sys.WORD_SIZE variable. The number of bits used by the integer affects the maximum and minimum value this integer can have. The minimum and maximum values are given by the typemin() and typemax() functions, respectively; for example, typemax(Int16) returns 32767.

If you try to store a number larger than that allowed by typemax, overflow occurs. For example, note the following:

julia> typemax(Int) 
9223372036854775807 # might be different on 32 bit platform 
julia> ans + 1 
-9223372036854775808 

Overflow checking is not automatic, so an explicit...

Floating point numbers

Floating point numbers follow the IEEE 754 standard and represent numbers with a decimal point, such as 3.14, or an exponent notation, such as 4e-14, and come in the types Float16 up to Float64, the last one being used for double precision.

Single precision is achieved through the use of the Float32 type. Single precision float literals must be written in scientific notation, such as 3.14f0, but with f, where one normally uses e. That is, 2.5f2 indicates 2.5*10^2 with single precision, while 2.5e2 indicates 2.5*10^2 in double precision. Julia also has a BigFloat type for arbitrary-precision floating numbers computations.

A built-in type promotion system takes care of all the numeric types that can work together seamlessly, so that there is no explicit conversion needed. Special values exist: Inf and -Inf are used for infinity, and NaN is used...

Elementary mathematical functions and operations

You can view the binary representation of any number (integer or float) with the bitstring function, for example, bitstring(3) returns "0000000000000000000000000000000000000000000000000000000000000011".

To round a number, use the round() function which returns a floating point number. All standard mathematical functions are provided, such as sqrt(), cbrt(), exp(), log(), sin(), cos(), tan(), erf() (the error function), and many more (refer to the URL mentioned at the end of this section). To generate a random number, use rand().

Use parentheses ( ) around expressions to enforce precedence. Chained assignments, such as a = b = c = d = 1, are allowed. The assignments are evaluated right-to-left. Assignments for different variables can be combined, as shown in the following example:

  a = 1; b = 2; c = 3; d =...

Rational and complex numbers

Julia supports these types out of the box. The global constant im represents the square root of -1, so that 3.2 + 7.1im is a complex number with floating point coefficients, so it is of the type Complex{Float64}.

This is the first example of a parametric type in Julia. For this example, we can write this as Complex{T}, where type T can take a number of different type values, such as Int32, Int64, or Float64.

All operations and elementary functions, such as exp(), sqrt(), sinh(), real(), imag(), abs(), and so on, are also defined on complex numbers; for example, abs(3.2 + 7.1im) = 7.787810988975015.

If a and b are two variables that contain a number, use complex(a,b) to form a complex number with them. Rational numbers are useful when you want to work with exact ratios of integers, for example, 3//4, which is of type Rational{Int64}.

Again, comparisons...

Characters

Like C or Java, but unlike Python, Julia implements a type for a single character, the Char type. A character literal is written as 'A', where typeof('A') returns Char. A Char value is a Unicode code point, and it ranges from '\0' to '\Uffffffff'. Convert this to its code point with Int(): Int('A') returns 65, and Int('α') returns 945, so this takes two bytes.

The reverse also works: Char(65) returns 'A', Char(945) returns '\u3b1', which is the code point for α (3b1 is hexadecimal for 945).

Unicode characters can be entered by a \u in single quotes, followed by four hexadecimal digits (ranging from 0-9 or A-F), or \U followed by eight hexadecimal digits. The isvalid(Char, value) function can test whether a number returns an existing Unicode character: isvalid(Char...

Variables, naming conventions, and comments


Data is stored in values such as1, 3.14, and "Julia", and every other value has a type, for example, the type of 3.14 isFloat64. Some other examples of elementary values and their data types are 42 of the Int64 type, true and false of the Bool type, and 'X' of the Char type.

Julia, unlike many modern programming languages, differentiates between single characters and strings. Strings can contain any number of characters, and are specified using double quotes—single quotes are only used for a character literal. Variables are the names that are bound to values by assignments, such asx = 42. They have the type of the value they contain (or reference); this type is given by the typeof function. For example, typeof(x) returns Int64.

The type of a variable can change, because putting x = "I am Julia" now results in typeof(x) returning String. In Julia, we don't have to declare a variable (that indicates its type) such as in C or Java, for instance, but...

Types


Julia's type system is unique. Julia behaves as a dynamically typed language (such as Python, for instance) most of the time. This means that a variable bound to an integer at one point might later be bound to a string. For example, consider the following:

julia> x = 1010julia> x = "hello""hello"

However, one can, optionally, add type information to a variable. This causes the variable to only accept values that match that specific type. This is done through a type of annotation. For instance, declaring x::String implies that only strings can be bound to x; in general, it looks like var::TypeName. These are used the most often to qualify the arguments a function can take. The extra type information is useful for documenting the code, and often allows the JIT compiler to generate better-optimized native code. It also allows the development environments to give more support, and code tools such as a linter that can check your code for possible wrong type use.

Here is an example: a...

Integers


Julia offers support for integer numbers ranging from types Int8 to Int128, with 8 to 128 representing the number of bits used, and with unsigned variants with a U prefix, such as UInt8. The default type (which can also be used as Int) is Int32 or Int64, depending on the target machine architecture. The bit width is given by the Sys.WORD_SIZE variable. The number of bits used by the integer affects the maximum and minimum value this integer can have. The minimum and maximum values are given by the typemin() and typemax() functions, respectively; for example, typemax(Int16) returns 32767.

If you try to store a number larger than that allowed by typemax, overflow occurs. For example, note the following:

julia> typemax(Int)9223372036854775807 # might be different on 32 bit platformjulia> ans + 1-9223372036854775808

Overflow checking is not automatic, so an explicit check (for example, the result has the wrong sign) is needed when this can occur. Integers can also be written in binary...

Floating point numbers


Floating point numbers follow the IEEE 754 standard and represent numbers with a decimal point, such as 3.14, or an exponent notation, such as 4e-14, and come in the types Float16 up to Float64, the last one being used for double precision.

 

 

Single precision is achieved through the use of the Float32 type. Single precision float literals must be written in scientific notation, such as 3.14f0, but with f, where one normally uses e. That is, 2.5f2 indicates 2.5*10^2 with single precision, while 2.5e2 indicates 2.5*10^2 in double precision. Julia also has a BigFloat type for arbitrary-precision floating numbers computations.

A built-in type promotion system takes care of all the numeric types that can work together seamlessly, so that there is no explicit conversion needed. Special values exist: Inf and -Inf are used for infinity, and NaN is used for "not a number" values such as the result of 0/0 or Inf - Inf.

Floating point arithmetic in all programming languages is often...

Elementary mathematical functions and operations


You can view the binary representation of any number (integer or float) with the bitstring function, for example, bitstring(3) returns "0000000000000000000000000000000000000000000000000000000000000011".

 

 

To round a number, use the round() function which returns a floating point number. All standard mathematical functions are provided, such as sqrt(), cbrt(), exp(), log(), sin(), cos(), tan(), erf() (the error function), and many more (refer to the URL mentioned at the end of this section). To generate a random number, use rand().

Use parentheses ( ) around expressions to enforce precedence. Chained assignments, such as a = b = c = d = 1, are allowed. The assignments are evaluated right-to-left. Assignments for different variables can be combined, as shown in the following example:

  a = 1; b = 2; c = 3; d = 4  a, b = c, d

Now, a has a value of 3 and b has a value of 4. In particular, this makes an easy swap possible:

  a, b = b, a   # now a is...

Rational and complex numbers


Julia supports these types out of the box. The global constantim represents the square root of -1, so that 3.2 + 7.1im is a complex number with floating point coefficients, so it is of the type Complex{Float64}.

This is the first example of a parametric type in Julia. For this example, we can write this asComplex{T}, where type T can take a number of different type values, such as Int32, Int64, or Float64.

All operations and elementary functions, such as exp(), sqrt(), sinh(), real(), imag(), abs(), and so on, are also defined on complex numbers; for example, abs(3.2 + 7.1im)= 7.787810988975015.

If a and b are two variables that contain a number, use complex(a,b) to form a complex number with them. Rational numbers are useful when you want to work with exact ratios of integers, for example, 3//4, which is of type Rational{Int64}.

Again, comparisons and standard operations are defined: float() converts to a floating point number, and num() and den() gives the numerator...

Left arrow icon Right arrow icon

Key benefits

  • Leverage Julia's high speed and efficiency for your applications
  • Work with Julia in a multi-core, distributed, and networked environment
  • Apply Julia to tackle problems concurrently and in a distributed environment

Description

The release of Julia 1.0 is now ready to change the technical world by combining the high productivity and ease of use of Python and R with the lightning-fast speed of C++. Julia 1.0 programming gives you a head start in tackling your numerical and data problems. You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. With the help of practical examples, this book walks you through two important collection types: arrays and matrices. In addition to this, you will be taken through how type conversions and promotions work. In the course of the book, you will be introduced to the homo-iconicity and metaprogramming concepts in Julia. You will understand how Julia provides different ways to interact with an operating system, as well as other languages, and then you'll discover what macros are. Once you have grasped the basics, you’ll study what makes Julia suitable for numerical and scientific computing, and learn about the features provided by Julia. By the end of this book, you will also have learned how to run external programs. This book covers all you need to know about Julia in order to leverage its high speed and efficiency for your applications.

Who is this book for?

Julia 1.0 Programming is for you if you are a statistician or data scientist who wants a crash course in the Julia programming language while building big data applications. A basic knowledge of mathematics is needed to understand the various methods that are used or created during the course of the book to exploit the capabilities that Julia is designed with.

What you will learn

  • Set up your Julia environment to achieve high productivity
  • Create your own types to extend the built-in type system
  • Visualize your data in Julia with plotting packages
  • Explore the use of built-in macros for testing and debugging, among other uses
  • Apply Julia to tackle problems concurrently
  • Integrate Julia with other languages such as C, Python, and MATLAB

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 24, 2018
Length: 196 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788990059
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 24, 2018
Length: 196 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788990059
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
R$500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts
R$800 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 791.97
Julia 1.0 Programming Cookbook
R$272.99
Julia Programming Projects
R$272.99
Julia 1.0 Programming
R$245.99
Total R$ 791.97 Stars icon
Banner background image

Table of Contents

11 Chapters
Installing the Julia Platform Chevron down icon Chevron up icon
Variables, Types, and Operations Chevron down icon Chevron up icon
Functions Chevron down icon Chevron up icon
Control Flow Chevron down icon Chevron up icon
Collection Types Chevron down icon Chevron up icon
More on Types, Methods, and Modules Chevron down icon Chevron up icon
Metaprogramming in Julia Chevron down icon Chevron up icon
I/O, Networking, and Parallel Computing Chevron down icon Chevron up icon
Running External Programs Chevron down icon Chevron up icon
The Standard Library and Packages Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(2 Ratings)
5 star 0%
4 star 50%
3 star 50%
2 star 0%
1 star 0%
Gianluigi Piva Jul 09, 2020
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Dopo Python, ritengo he per la parte matematica sia veramente notevole
Amazon Verified review Amazon
SaSy Mar 09, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Ein gutes Buch für den Einsteiger in die Julia-Programmierung. Ich würde aber definitiv mit dem Kauf bis zur nächsten Auflage warten, da noch einige Inkonsistenzen im Buch zu finden sind (ich habe die 2. Auflage). Offensichtlich ist das Buch ein Update für die Beschreibung der Version 0.6 (oder 0.7). Mit dem Wechsel auf 1.0 haben sich aber einige Befehle dauerhaft geändert (type heißt jetzt struct oder @parallel ist jetzt @distributed). Die Code-Beispiele berücksichtigen diese Änderungen. Der Text erwähnt allerdings noch die alten Befehle. Dies kann zu Verwirrungen führen. Ich benutze das Buch, wenn ich schnell eine Kleinigkeit nachschlagen will. Dafür ist es ganz gut. Bei Julia ist jedoch auch die Online-Dokumentation sehr gut verfasst. Das Buch ist natürlich demgegenüber übersichtlicher gestaltet, deckt aber auch nur einen Bruchteil ab.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.