julia-Latest Programming language

36

Transcript of julia-Latest Programming language

PRESENTED BYNITHYA A.P

OVERVIEWOVERVIEW INTRODUCTIONINTRODUCTION FEATURESFEATURES DATA TYPESDATA TYPES MATHEMATICAL OPERATORSMATHEMATICAL OPERATORS COMPLEX AND RATIONAL NUMBERS’COMPLEX AND RATIONAL NUMBERS’ STRINGSSTRINGS FUNCTIONSFUNCTIONS CONTROL FLOWCONTROL FLOW JULIA STANDARD LibraryJULIA STANDARD Library SIMPLE PLOTINGSIMPLE PLOTING ADVANTAGESADVANTAGES CONCLUSIONCONCLUSION

INTRODUCTIONINTRODUCTION

Julia is a high-level, high-Julia is a high-level, high-performance dynamic performance dynamic programming language for programming language for technical computing, with technical computing, with syntax that is familiar to users syntax that is familiar to users of other technical computing of other technical computing environments. It provides a environments. It provides a sophisticated compiler, sophisticated compiler, distributed parallel execution, distributed parallel execution, numerical accuracy, and an numerical accuracy, and an extensive mathematical function extensive mathematical function library. library.

Appeared in 2012

Designed by Jeff Bezanson, Stefan Karpinski, Viral B. Shah, Alan Edelman (MIT Group Leader)

OS Linux, FreeBSD, Windows

Stable release

0.1.2 (March 7, 2013))

Typing discipline

Dynamic with optional type annotations and type inference

Influenced by

MATLAB, Scheme, Lisp, C Python Perl Ruby

License MIT LicenseUsual filename extensions

.jl

FEATURESFEATURES

High-Performance JIT CompilerHigh-Performance JIT Compiler Designed for Parallelism & Cloud Designed for Parallelism & Cloud

Computing Computing Free, Open Source & Library-Free, Open Source & Library-

FriendlyFriendly

DATATYPESDATATYPES

Integers and Floating-Point NumbersInteger Types

Int8— signed 8-bit integers ranging from -2^7 to 2^7 - 1.

Uint8 — unsigned 8-bit integers ranging from 0 to 2^8 - 1.

Int16 — signed 16-bit integers ranging from -2^15 to 2^15 - 1.

Uint16 — unsigned 16-bit integers ranging from 0 to 2^16 - 1

Int32 — signed 32-bit integers ranging from -2^31 to 2^31 - 1.

Uint32 — unsigned 32-bit integers ranging from 0 to 2^32 - 1.

Int64 — signed 64-bit integers ranging from -2^63 to 2^63 - 1.

Uint64 — unsigned 64-bit integers ranging from 0 to 2^64 - 1.

Int128 - signed 128-bit integers ranging from -2^127 to 2^127 - 1.

Uint128 - unsigned 128-bit integers ranging from 0 to 2^128 - 1.

Bool- either true or false, which correspond numerically to 1 and 0.

Char- a 32-bit numeric type representing a Unicode character.

Floating-point types: Float32- IEEE 754 32-bit floating-point

numbers. Float64-IEEE 754 64-bit floating-point

numbers.

Arbitrary Precision Arithmetic

allow computations with arbitrary precision integers and floating point numbers

The BigInt and BigFloat types are available in Julia for arbitrary precision integer and floating point numbers respectively.

Numeric Literal Coefficients

make common numeric formulas and expressions clearer

writing polynomial expressions much cleaner.

makes writing exponential functions more elegant.

Syntax ConflictsSyntax Conflicts The hexadecimal integer literal The hexadecimal integer literal

expression 0xff could be expression 0xff could be interpreted as the numeric literal interpreted as the numeric literal 0 multiplied by the variable xff.0 multiplied by the variable xff.

The floating-point literal The floating-point literal expression 1e10 could be expression 1e10 could be interpreted as the numeric literal interpreted as the numeric literal 1 multiplied by the variable e10, 1 multiplied by the variable e10, and similarly with the equivalent and similarly with the equivalent E form.E form.

MATHEMATICAL MATHEMATICAL OPERATORSOPERATORS

Arithmetic OperatorsArithmetic Operators Bitwise OperatorsBitwise Operators

Arithmetic operatorsArithmetic operators• • +x-unary plus is the identity operation.+x-unary plus is the identity operation.

• • x-unary minus maps values to their x-unary minus maps values to their additive inverses.additive inverses.

• • x + y-binary plus performs addition.x + y-binary plus performs addition.

• • x – y-binary minus performs subtraction.x – y-binary minus performs subtraction.

• • x * y- times performs multiplication.x * y- times performs multiplication.

• • x / y-divide performs division.x / y-divide performs division.

Bitwise OperatorsBitwise Operators

• • ~x~x bitwise not. bitwise not.

• • x & yx & y bitwise and.bitwise and.

• • x | yx | y bitwise or.bitwise or.

• • x $ y-x $ y-bitwise xor.bitwise xor.

• • x >> yx >> y logical shift right.logical shift right.

• • x >> y-x >> y- arithmetic shift right.arithmetic shift right.

• • x << y x << y logical/arithmetic shift logical/arithmetic shift left.left.

NUMERIC COMPARISONNUMERIC COMPARISON

Comparison OperatorsComparison Operators

• • ==equality.==equality.

• • != inequality.!= inequality.

• • <less than.<less than.

• • <=less than or equal to.<=less than or equal to.

• • >greater than.>greater than.

• • >=greater than or equal >=greater than or equal to.to.

MATHEMATICALFUNCTIONSMATHEMATICALFUNCTIONS

o Julia provides a comprehensive Julia provides a comprehensive collection of mathematical collection of mathematical functions and operatorsfunctions and operators

o All the standard trignometric All the standard trignometric functions are inludedfunctions are inluded

Some examplesSome examples

• • sqrt(x)— the square root of x.sqrt(x)— the square root of x.

• • cbrt(x)— the cube root of x.cbrt(x)— the cube root of x.

• • pow(x,y)—x raised to the pow(x,y)—x raised to the exponent y.exponent y.

• • exp(x)— the natural exponential exp(x)— the natural exponential function at x.function at x.

• • log(x)— the natural logarithm of log(x)— the natural logarithm of x.x.

Complex NumbersComplex Numbers We can perform all the standard We can perform all the standard

arithmetic operations with complex arithmetic operations with complex numbers:numbers:julia> (1 + 2im)*(2 - 3im)julia> (1 + 2im)*(2 - 3im)

8 + 1im8 + 1im

Standard functions to manipulate Standard functions to manipulate complex values are provided:complex values are provided:julia> real(1 + 2im)julia> real(1 + 2im)

11

Julia> imag(1 + 2iJulia> imag(1 + 2im)m)

22

julia> conj(1 + 2im)julia> conj(1 + 2im)

1 - 2im1 - 2im

Rational NumbersRational Numbers Julia has a rational number type to Julia has a rational number type to

represent exact ratios of integers. represent exact ratios of integers. Rationals are constructed using Rationals are constructed using the // operator:the // operator:

If the numerator and denominator of If the numerator and denominator of a rational have common factors, a rational have common factors, they are reduced to lowest terms they are reduced to lowest terms such that the denominator is non-such that the denominator is non-negative:negative:Julia> 6//9Julia> 6//9

2//32//3

julia> 5//-15julia> 5//-15

-1//3-1//3

STRINGSSTRINGSStrings are finite sequences of Strings are finite sequences of characters. Julia supports the full characters. Julia supports the full range of unicode characters:range of unicode characters:

• CharactersCharacters

A Char value represents a single A Char value represents a single character: it is just a 32-bit integer character: it is just a 32-bit integer with a special literal representation with a special literal representation and appropriate arithmetic and appropriate arithmetic behaviors, whose numeric value is behaviors, whose numeric value is interpreted as a Unicode code pointinterpreted as a Unicode code point

InterpolationInterpolation

To reduce the need for these To reduce the need for these verbose calls to strcat, Julia verbose calls to strcat, Julia allows interpolation into string allows interpolation into string literals using $, as in Perl:literals using $, as in Perl:

julia> "$greet, $whom.\n"julia> "$greet, $whom.\n" "Hello, world.\n""Hello, world.\n"

STRING FUNCTIONSSTRING FUNCTIONS strchr function:strchr function:

Julia> strchr("xylophone", ’x’)Julia> strchr("xylophone", ’x’)

11 repeat:repeat:

julia> repeat(".:Z:.", 10)julia> repeat(".:Z:.", 10)

".:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..".:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:.“:Z:..:Z:.“

••endof(str) gives the maximal endof(str) gives the maximal (byte) index that can be used to (byte) index that can be used to index into str.index into str.

• i = start(str) gives the first valid index at which a character can be found in str (typically 1).• c, j = next(str,i) returns next character at or after the index i and the next valid character index following that. With start and endof, can be used to iterate through the characters in str.• ind2chr(str,i) gives the number of characters in str up to and including any at index i• chr2ind(str,j) gives the index at which the jth character in str occurs.

FUNCTIONSFUNCTIONS

In Julia, a function is an object In Julia, a function is an object that maps a tuple of argument that maps a tuple of argument values to a return valuevalues to a return value

syntax for defining functions in syntax for defining functions in Julia is:Julia is:

function f(x,y)function f(x,y)

x + yx + y

endend

CONTROL FLOWCONTROL FLOW

• • Compound Expressions: begin Compound Expressions: begin and (;).and (;).

• • Conditional Evaluation: if-elseif-Conditional Evaluation: if-elseif-else and ?: (ternary operator).else and ?: (ternary operator).

• • Short-Circuit Evaluation: &&, || Short-Circuit Evaluation: &&, || and chained comparisons.and chained comparisons.

• • Repeated Evaluation: Loops: Repeated Evaluation: Loops: while and for.while and for.

Julia Standard LibraryJulia Standard LibraryThere are 65 pacages in Julia There are 65 pacages in Julia

some of them are:some of them are:

1.1. ArgPars- ArgPars-Package for parsing Package for parsing command-line arguments to command-line arguments to Julia programs.Julia programs.

2.2. Calculus- Calculus-Calculus functions Calculus functions in Juliain Julia

3.Calendar-3.Calendar-Calendar time Calendar time package for Juliapackage for Julia

4.4. Color- Color-Basic color Basic color manipulation utilitiesmanipulation utilities

5.Graph-Working with graphs in Julia6. HTTP-HTTP library (server, client, parser) for the Julia language7. Languages-A package for working with human language8.Sound-Reading and writing from WAV files (should probably be named WAV)9. Winston-2D plotting for Julia

Simple PlotingSimple PlotingTo plot To plot sin(x)sin(x) between 0 and 2π, between 0 and 2π,

you can go like thisyou can go like this

julia> xVector=[0:0.01:2*pi];julia> xVector=[0:0.01:2*pi];

julia> yVector=0.0*xVector;julia> yVector=0.0*xVector;

julia> for n=1:length(xVector):julia> for n=1:length(xVector):

yVector[n] = sin(xVector[n]);yVector[n] = sin(xVector[n]);

endend

julia> plot(xVector, yVector)julia> plot(xVector, yVector)

Advantages of JULIAAdvantages of JULIA• • Free and open source (MIT licensed)Free and open source (MIT licensed)

• • User-defined types are as fast and User-defined types are as fast and compact as built-inscompact as built-ins

• • Designed for parallelism and Designed for parallelism and distributed computationdistributed computation

• • Elegant and extensible conversions Elegant and extensible conversions and promotions for numeric and and promotions for numeric and other typesother types

• • Call C functions directlyCall C functions directly

  

CONCLUSIONJulia is a is a flexible dynamic language, appropriate for scientific and numerical computingJulia features optional typing, multiple dispatch, and good performance, achieved using type inference and just-intime (JIT) compilation.Julia combines the features of many other Programing languages like C,Matlab,java etc.Which is useful for scientific computing.It is a User friendly and easly Understandable Programming Language

REFERENCESREFERENCES

"The Julia Language""The Julia Language" (official website).  (official website).  O'Reilly Strata. Retrieved 7 February O'Reilly Strata. Retrieved 7 February 2013.  2013. 

Krill, Paul. Krill, Paul. "New Julia language seeks to "New Julia language seeks to be the C for scientists "be the C for scientists " InfoWorld. InfoWorld. Retrieved 7 February 2013.  Retrieved 7 February 2013. 

"Julia: A Fast Dynamic Language for "Julia: A Fast Dynamic Language for Technical Computing"Technical Computing" (PDF). 2012.  (PDF). 2012. 

"Why We Created Julia""Why We Created Julia"((World Wide WebWorld Wide Web log). Feb 2012. Retrieved 7 February log). Feb 2012. Retrieved 7 February 2013.  2013. 

"The Julia Studio""The Julia Studio" (official website).  (official website).  Julia Language Documentation Release Julia Language Documentation Release

developmentdevelopment

Any questions??????????