# top[#grammar-invocation grammar and invocation] | [#var-expr variables and expressions] | [#arithmetic-logic arithmetic and logic] | [#strings strings] | [#dates-time dates and time] | [#multidimensional-arrays multidimensional arrays] | [#sets sets] | [#functions functions] | [#execution-control execution control] | [#file-handles file handles] | [#directories directories] | [#libraries-namespaces libraries and namespaces] | [#processes-environment processes and environment] _ _ [#optimization optimization] | [#linear-regression linear regression] _ _ [#bar-charts bar charts] | [#scatter-plots scatter plots] | [#line-surface-charts line and surface charts] | [#chart-options chart options]

||~ ||~ [#gnuplot gnuplot]||~ [#glpk glpk]|| ||# version-used[#version-used-note version used] _ @< >@||##gray|//5.0//##||##gray|//4.52//##|| ||# show-version[#show-version-note show version] _ @< >@||$ gnuplot @@–@@version||$ glpsol @@–@@version|| ||||||~ # grammar-invocation[#grammar-invocation-note grammar and invocation]|| ||~ ||~ gnuplot||~ glpk|| ||# interpreter[#interpreter-note interpreter] _ @< >@||$ cat hello.gnuplot _ print “Hello, World!” _ _ $ gnuplot hello.gnuplot _ Hello, World!||$ cat hello.model _ printf “Hello, World!\n”; _ end; _ _ $ glpsol -m hello.model _ Hello, World!|| ||# repl[#repl-note repl] _ @< >@||$ gnuplot||##gray|//none//##|| ||# compiler[#compiler-note compiler]||##gray|//none//##||##gray|//none//##|| ||# cmd-line-program[#cmd-line-program-note command line program] _ @< >@||$ gnuplot -e ‘print 1 + 1;’||##gray|//none//##|| ||# block-delimiters[#block-delimiters-note block delimiters] _ @< >@||{ }||{ } _ _ ##gray|//Curly braces are used to delimit the block of statements in the body of a// for //statement.//## _ _ ##gray|//Curly braces are also used in indexing expressions and set literals.//##|| ||# stmt-separator[#stmt-separator-note statement separator]||##gray|//newline or//## ; _ _ ##gray|//A newline preceded by a backslash is ignored.//##||;|| ||# eol-comment[#eol-comment-note end-of-line comment] _ @< >@||# ##gray|//comment//##||# ##gray|//comment//##|| ||# multiple-line-comment[#multiple-line-comment-note multiple line comment] _ @< >@||##gray|//none//##||/* ##gray|//comment line//## _ ##gray|//another comment//## */|| ||||||~ # var-expr[#var-expr-note variables and expressions]|| ||~ ||~ gnuplot||~ glpk|| ||# assignment[#assignment-note assignment]||x = 3.14||##gray|# parameters are write once:## _ param pi := 3.14;|| ||# null[#null-note null] _ @< >@||##gray|//none//##||##gray|//none//##|| ||# null-test[#null-test-note null test] _ @< >@||##gray|//none//##||##gray|//none//##|| ||# undef-var[#undef-var-note undefined variable access] _ @< >@||##gray|//causes error//##||##gray|//causes error//##|| ||# undef-var-test[#undef-var-test-note undefined variable test]||exists(“x”)||##gray|//none//##|| ||# rm-var-binding[#rm-var-binding-note remove variable binding]||undefine x||##gray|//none//##|| ||# cond-expr[#cond-expr-note conditional expression] _ @< >@||x > 0 : x : -x||if x > 0 then x else -x|| ||||||~ # arithmetic-logic[#arithmetic-logic-note arithmetic and logic]|| ||~ ||~ gnuplot||~ glpk|| ||# true-false[#true-false-note true and false] _ @< >@||1 0||1 0 _ _ ##gray|//The boolean values are distinct from the integers 1 and 0. When displayed by// printf ‘%s’ //they render as// T //and// F. //There are no boolean literals, however.//##|| ||# falsehoods[#falsehoods-note falsehoods] _ @< >@||0 _ _ ##gray|0.0 //is true//##||0 0.0|| ||# logical-op[#logical-op-note logical operators]||@@&& || !@@||and or not _ _ @@&& || !@@|| ||# relational-op[#relational-op-note relational operators]||== != < > <= >= _ _ ##gray|# string comparision:## _ eq ne||@@=@@ <> < > <= >= _ _ == ##gray|//and//## != ##gray|//are synonyms of//## = ##gray|//and//## <> || ||# arith-op[#arith-op-note arithmetic operators] _ _ ##gray|//addition, subtraction, multiplication, division, modulus//##||+ - * / %||+ - * / mod|| ||# int-div[#int-div-note integer division] _ @< >@||int(x) / int(y)||x div y|| ||# int-div-zero[#int-div-zero-note integer division by zero]||##gray|//error//##||##gray|//error//##|| ||# float-div[#float-div-note float division]||(1.0 * x) / y||7 / 3|| ||# float-div-zero[#float-div-zero-note float division by zero]||##gray|//error//##||##gray|//error//##|| ||# power[#power-note power]||2 ** 32||2 ^ 32 _ 2 ** 32|| ||# sqrt[#sqrt-note sqrt]||sqrt(2)||sqrt(2)|| ||# sqrt-negative-one[#sqrt-negative-one-note sqrt -1] _ @< >@||##gray|# evaluates to {0.0, 1.0}:## _ sqrt(-1) ||##gray|# error:## _ sqrt(-1)|| ||# transcendental-func[#transcendental-func-note transcendental functions]||exp() log log10() _ sin() cos() tan() _ asin() acos() atan() _ atan2()||exp() log() log10() _ sin() cos() ##gray|//none//## _ ##gray|//none//## ##gray|//none//## atan() _ atan(##gray|//y//##, ##gray|//x//##)|| ||# transcendental-const[#transcendental-const-note transcendental constants] _ ##gray|//e and pi//##||exp(1) _ pi||exp(1) _ 4 * atan(1)|| ||# float-truncation[#float-truncation-note float truncation] _ ##gray|//round towards zero, round to nearest integer, round down, round up//##||int(x) _ ##gray|//??//## _ floor(x) _ ceil(x)||trunc(x) _ round(x) _ floor(x) _ ceil(x) _ _ ##gray|# truncate/round to 2 decimal places:## _ trunc(x, 2) _ round(x, 2)|| ||# absolute-val[#absolute-val-note absolute value] _ ##gray|//and signum//##||abs(x) _ sgn(x)||abs(x) _ ##gray|//none//##|| ||# int-overflow[#int-overflow-note integer overflow] _ @< >@||##gray|//32 bit signed integers are used. Operations which overflow return a float.//## ||##gray|//conversion to float//##|| ||# float-overflow[#float-overflow-note float overflow] _ @< >@||##gray|//64 bit double precision floats are used. Operations which overflow raise an error.//##||##gray|//error//##|| ||# complex-construction[#complex-construction-note complex construction] _ @< >@||z = {1.0, 2.0}||##gray|//none//##|| ||# complex-decomposition[#complex-decomposition-note complex decomposition] _ ##gray|//real and imaginary part, argument and modulus, conjugate//##||real(z) _ imag(z) _ arg(z) _ abs(z) _ ##gray|//??//##||##gray|//none//##|| ||# random-num[#random-num-note random number] _ ##gray|//uniform integer, uniform float, standard normal//##||floor(rand(0) * 100) _ rand(0) _ ##gray|//none//##||##gray|# Irand224() generates integer in [0, 2^24):## _ Irand224() mod 100 _ Uniform01() _ Normal01()|| ||# random-seed[#random-seed-note random seed]||_ = rand(17)||$ glpsol @@–@@seed 17 -m foo.model|| ||# bit-op[#bit-op-note bit operators] _ @< >@||@@<< >> & | ^ ~@@||##gray|//none//##|| ||# binary-octal-hex-literals[#binary-octal-hex-literals-note binary, octal, and hex literals]||##gray|//none//## _ 052 _ 0x2a||##gray|//none//##|| ||||||~ # strings[#strings-note strings]|| ||~ ||~ gnuplot||~ glpk|| ||[#string-literals string literals]||"don’t say "no"” _ ‘don’’t say “no”’||"don’t say ““no””” _ ‘don’’t say “no”’ _ _ ##gray|//Quotes can be omitted in the data section when the contents of the string are alphanumeric or match the character class// [-+_.]##|| ||[#string-newline newline in literal]||##gray|//no//##||##gray|//no//##|| ||[#string-escapes string literal escapes]||##gray|# in double quotes:## _ \n \r \t ##gray|//o//## ##gray|//oo//## ##gray|//ooo//##||##gray|# in printf format:## _ \n \t|| ||[#string-length length]||strlen(“lorem ipsum”)||length(“lorem ipsum”)|| ||[#string-concatenate concatenate]||"lorem “ . “ipsum”||"lorem “ & “ipsum”|| ||[#index-substring index of substring]||##gray|# indices start at 1; _

returns 0 if not found:## _

strstrt(“foo bar”, “bar”, ||##gray|//none//##||

||[#extract-substring extract substring]||substr(“foo bar”, 5, 8)||substr(“foo bar”, 5, 3)|| ||# fmt-str[#fmt-str-note format string]||sprintf(“%d %.2f %s”, 7, 3.1415, “foo”)||##gray|//none//##|| ||# num-to-str[#num-to-str-note number to string]||"foo” . 4||##gray|//none//##|| ||# str-to-num[#str-to-num-note string to number]||"4” + 7 _ _ ##gray|# causes error:## _ “foo” + 7||##gray|//none//##|| ||||||~ # dates-time[#dates-time-note dates and time]|| ||~ ||~ gnuplot||~ glpk|| ||# current-time-unix-epoch[#current-time-unix-epoch-note current time as unix epoch]||##gray|# seconds since Jan 1, 2000## _ ##gray|# add 946684800.0 to get unix epoch:## _ now = time(0) _ _ ##gray|# as float:## _ real_now = time(0.0)||gmtime()|| ||# fmt-time[#fmt-time-note format time]||strftime(‘%Y-%m-%d %H:%M:%S’, now)||time2str(gmtime(), ‘%Y-%m-%d %H:%M:%S’)|| ||# parse-time[#parse-time-note parse time]||s = “2014-11-30 03:53:59” _ t = strptime(‘%Y-%m-%d %H:%M:%S’, s)||str2time(“2014-12-01 19:38:09”, “%Y-%m-%d %H:%M:%S”)|| ||# sleep[#sleep-note sleep]||pause 10 _ _ ##gray|# with message:## _ pause 10 ‘sleeping 10s@@…@@’||##gray|//none//##|| ||||||~ # multidimensional-arrays[#multidimensional-arrays-note multidimensional arrays]|| ||~ ||~ gnuplot||~ glpk|| ||2d literal||##gray|//in separate file; one line for each data point; whitespace delimited://## _ _ $ cat data.txt _ 7 8 _ 9 10 _ 11 12||##gray|# declare in model section:## _ param a {1..2, 1..2}; _ _ ##gray|# define in data section:## _ param a: 1@<  >@2 := _ @<  >@@<  >@@<  >@1@<  >@7@<  >@8 _ @<  >@@<  >@@<  >@2@<  >@9 10;|| ||3d literal||##gray|//in separate file; one line for each data point://## _ _ $ cat data.txt _

city data: _

“Los Angeles” 3 7 _ “New York” 8 4 _ “San Francisco” 12 1 _ _ ##gray|//comment lines are ignored; data which contains whitespace must be quoted//##|| || ||||||~ # sets[#sets-note sets]|| ||~ ||~ gnuplot||~ glpk|| ||literal|| ||set digits := {1, 2, 3, 4, 5};|| ||set from arithmetic sequence _ _ ##gray|//unit difference, non-unit difference//##|| ||set digits := {1 .. 5}; _ _ set leap_years := {2000 .. 2096 by 4};|| ||membership|| ||set s := {1, 2, 3}; _ set str := if 4 in s then ‘yes’ else ‘no’;|| ||intersection|| ||set s1 := {1, 2, 3}; _ set s2 := {2, 3, 4, 5}; _ _ set s3 := s1 inter s2;|| ||union|| ||set s3 := s1 union s2;|| ||relative complement, symmetric difference|| ||set s3 := s1 diff s2; _ set s4 := s1 symdiff s2;|| ||cartesian product|| ||##gray|# 12 pairs:## _ set s3 := s1 cross s2;|| ||map|| ||set s := 1 .. 10; _ set squares := setof {i in s} i * i;|| ||reduce|| ||set s := 1 .. 10; _ _ param n1 := min {i in s} i;@<  >@##gray|# 1## _ param n2 := max {i in s} i;@<  >@##gray|# 10## _ param n3 := sum {i in s} i;@<  >@##gray|# 55## _ param n4 := prod {i in s} i;@<  >@##gray|# 10!## _ _ ##gray|# sum of squares:## _ param n5 := sum {i in s} i * i;|| ||universal test|| ||set str1 := if (forall {i in s} i > 5) then ‘yes’ else ‘no’;|| ||existential test|| ||set str2 = if (exists {i in s} i > 5) then ‘yes’ else ‘no’;|| ||||||~ # functions[#functions-note functions]|| ||~ ||~ gnuplot||~ glpk|| ||[#function-definition define function]||##gray|# body of function must be an expression:## _ add(x, y) = x + y||##gray|//none//##|| ||[#function-invocation invoke function]||add(3, 7)||##gray|//none//##|| ||[#list-functions list functions]||show functions||##gray|//none//##|| ||# missing-arg[#missing-arg-note missing argument behavior]||##gray|//error//##||##gray|//none//##|| ||# extra-arg[#extra-arg-note extra argument behavior]||##gray|//error//##||##gray|//none//##|| ||[#return-value return value]||##gray|//value of the expression which is the function body//##||##gray|//none//##|| ||||||~ # execution-control[#execution-control-note execution control]|| ||~ ||~ gnuplot||~ glpk|| ||[#if if]||if (x > 0) { _ @<  >@print “positive” _ } _ else { _ @<  >@if (x < 0) { _ @<  >@@<  >@print “negative” _ @<  >@} _ @<  >@else { _ @<  >@@<  >@print “zero” _ @<  >@} _ }||##gray|//none//##|| ||[#while while]||i = 0 _ _ while (i < 10) { _ @<  >@print i _ @<  >@i = i + 1 _ }||##gray|//none//##|| ||[#for for]||do for [i = 1:10] { _ @<  >@print i _ }||for {i in {1..10}} _ { _ @<  >@printf “%d\n”, i; _ }|| ||break continue|| || || ||raise exception|| || || ||||||~ # file-handles[#file-handles-note file handles]|| ||~ ||~ gnuplot||~ glpk|| ||write line to stdout||print “Hello, World!”||printf “Hello, World!\n”;|| ||write formatted string to stdout|| ||printf “%d %.2f %s”, 7, 3.1415, ‘foo’;|| ||write to file|| ||##gray|# overwrites contents of /tmp/foo.txt:## _ printf “lorem ispum” > “/tmp/foo.txt”;|| ||append to file|| ||printf “dolor sit amet” @@>>@@ “/tmp/foo.txt”;|| ||pretty print|| ||set s := {1, 2, 3, 4, 5}; _ param x := 3; _ param str symbolic := ‘lorem ispum’; _ _ display “set: “, s, _ @<  >@"param: “, x, _ @<  >@"string: “, str;|| ||||||~ # directories[#directories-note directories]|| ||~ ||~ gnuplot||~ glpk|| ||working directory||##gray|# writes working dir to stdout:## _ pwd _ _ cd “/tmp”||##gray|//none//##|| ||||||~ # libraries-namespaces[#libraries-namespaces-note libraries and namespaces]|| ||~ ||~ gnuplot||~ glpk|| ||[#load load]||$ cat foo.gnuplot _ print “loaded!” _ _ $ cat main.gnuplot _ load ‘foo.gnuplot’ _ _ $ gnuplot main.gnuplot _ loaded!||##gray|//none//##|| ||||||~ # processes-environment[#processes-environment-note processes and environment]|| ||~ ||~ gnuplot||~ glpk|| ||# cmd-line-arg[#cmd-line-arg-note command line arguments]||$ cat test.gnuplot _ print foo _ print bar _ _ $ gnuplot -e ‘foo=3; bar=4’ test.gnuplot||##gray|//none//##|| ||# exit[#exit-note exit]||##gray|# no way to set exit status:## _ exit _ _ ##gray|# or:## _ quit||##gray|//none//##|| ||# cmd-subst[#cmd-subst-note command substitution]||ls_output = system(“ls”)||##gray|//none//##|| ||||||~ # optimization[#optimization-note optimization]|| ||~ ||~ gnuplot||~ glpk|| ||# linear-min[#linear-min-note linear minimization]|| ||var x1; _ var x2; _ var x3; _ _ minimize obj: x1 + x2 + x3; _ _ c1: x1 + x2 >= 1; _ c2: x2 + x3 >= 1; _ c3: x1 + x3 >= 1; _ _ solve; _ display obj, x1, x2, x3; _ end;|| ||# decision-var-array[#decision-vary-array-note decision variable array]|| ||set I := {1 .. 3}; _ var x{I}; _ _ minimize obj: sum{i in I} x[i]; _ _ c1: x[1] + x[2] >= 1; _ c2: x[2] + x[3] >= 1; _ c3: x[1] + x[3] >= 1; _ _ solve; _ display obj, x; _ end;|| ||# linear-max[#linear-max-note linear maximization]|| ||set I := {1 .. 3}; _ var x{I}; _ _ maximize obj: sum{i in I} x[i]; _ _ c1: x[1] + x[2] <= 1; _ c2: x[2] + x[3] <= 1; _ c3: x[1] + x[3] <= 1; _ _ solve; _ display obj, x; _ end;|| ||# var-declaration-constraint[#var-declaration-constraint-note constraint in variable declaration]|| ||set I := {1 .. 3}; _ var x{I} >= 0; _ _ minimize obj: sum{i in I} x[i]; _ _ c1: -x[1] + x[2] >= 1; _ c2: x[2] + x[3] >= 1; _ c3: -x[1] + x[3] >= 1; _ _ solve; _ display obj, x; _ end;|| ||# opt-unbounded-behavior[#opt-unbounded-behavior-note unbounded behavior] _ @< >@|| ||##gray|# Stops execution after solve statement with “LP HAS UNBOUNDED PRIMAL SOLUTION” message.##|| ||# opt-infeasible-behavior[#opt-infeasible-behavior-note infeasible behavior]|| ||##gray|# Stops execution after solve statement with “LP HAS NO PRIMAL FEASIBLE SOLUTION” message.##|| ||# int-decision-var[#int-decision-var-note integer decision variable]|| ||set I := {1 .. 3}; _ var x{I} integer; _ _ minimize obj: sum{i in I} x[i]; _ _ c1: x[1] + x[2] >= 1; _ c2: x[2] + x[3] >= 1; _ c3: x[1] + x[3] >= 1; _ _ solve; _ display obj, x; _ end;|| ||# int-binary-var[#int-binary-var-note binary decision variable]|| ||set I := {1 .. 3}; _ var x{I} binary; _ _ minimize obj: sum{i in I} x[i]; _ _ c1: x[1] + x[2] >= 1; _ c2: x[2] + x[3] >= 1; _ c3: x[1] + x[3] >= 1; _ _ solve; _ display obj, x; _ end;|| ||||||~ # linear-regression[#linear-regression-note linear regression]|| ||~ ||~ gnuplot||~ glpk|| ||||||~ # bar-charts[#bar-charts-note bar charts]|| ||~ ||~ gnuplot||~ glpk|| ||# vertical-bar-chartimage http://cdn.hyperpolyglot.org/images/vertical-bar-chart.jpg _ [#vertical-bar-chart-note vertical bar chart]||##gray|# echo $’7\n3\n8\n5\n5’ > data.txt## _ _ set terminal png size 400,300 _ set output “barchart.png” _ set boxwidth 0.9 _ set style fill solid 1.0 _ plot [0:6] [0:9] “data.txt” \ _ @<  >@using 0:1 notitle with boxes|| || ||# horizontal-bar-chartimage http://cdn.hyperpolyglot.org/images/horizontal-bar-chart.jpg _ [#horizontal-bar-chart-note horizontal bar chart]|| || || ||# stacked-bar-chartimage http://cdn.hyperpolyglot.org/images/stacked-bar-chart.jpg _ [#stacked-bar-chart-note stacked bar chart]|| || || ||# grouped-bar-chartimage http://cdn.hyperpolyglot.org/images/grouped-bar-chart.jpg _ [#grouped-bar-chart-note grouped bar chart]|| || || ||# pie-chartimage http://cdn.hyperpolyglot.org/images/pie-chart.jpg _ [#pie-chart-note pie chart]||##gray|//see note//##|| || ||# histogramimage http://cdn.hyperpolyglot.org/images/histogram.jpg _ [#histogram-note histogram]||##gray|# awk ‘{ print length($0)}’ /usr/share/dict/words > hist.txt## _ _ set terminal png size 400,300 _ set output “histogram.png” _ binwidth=1 _ bin(x,width)=width*floor(x/width) _ unset key _ plot “hist.txt” \ _ @<  >@using (bin($1,binwidth)):(1.0) \ _ @<  >@smooth freq with boxes|| || ||# box-plotimage http://cdn.hyperpolyglot.org/images/box-plot.jpg _ [#box-plot box plot]||##gray|# seq 100 | awk ‘{print rand() ** 3}’ > data.txt## _ _ set terminal png size 400,300 _ set output “boxplot.png” _ set style boxplot outliers pointtype 7 _ set style data boxplot _ set boxwidth 0.2 _ plot [0.5:1.5] [0.0:1.1] “data.txt” \ _ @<  >@using (1.0):1:(0.3) notitle|| || ||||||~ # scatter-plots[#scatter-plots-note scatter plots]|| ||~ ||~ gnuplot||~ glpk|| ||# scatter-plotimage http://cdn.hyperpolyglot.org/images/scatter-plot.jpg _ [#scatter-plot-note scatter plot]||##gray|# seq 50 | awk ‘{x=rand(); print x,x+rand()}’ > data.txt## _ _ set terminal png size 400,300 _ set output “scatter.png” _ unset key _ plot “data.txt”|| || ||[#bubble-chart bubble chart]|| || || ||[#3d-scatter-plot 3d scatter plot]|| || || ||# linear-regression-lineimage http://cdn.hyperpolyglot.org/images/linear-regression-line.jpg _ [#linear-regression-line linear regression line]|| || || ||# q-q-plotimage http://cdn.hyperpolyglot.org/images/q-q-plot.jpg _ [#q-q-plot-note quantile-quantile plot]|| || || ||||||~ # line-surface-charts[#line-surface-charts-note line and surface charts]|| ||~ ||~ gnuplot||~ glpk|| ||# polygonal-line-plotimage http://cdn.hyperpolyglot.org/images/polygonal-line-plot.jpg _ [#polygonal-line-plot-note polygonal line plot]||##gray|# seq 1 20 | awk ‘{print rand() + rand() + rand()}’ > data.txt## _ _ set terminal png size 400,300 _ set output “polygonal.png” _ unset key _ plot “data.txt” using 0:1 with lines|| || ||# additional-lineimage http://cdn.hyperpolyglot.org/images/additional-line.jpg _ [#additional-line-note additional line]||##gray|# seq 1 20 | awk ‘{print rand() + rand(), rand() + rand()}’ \ _ #@<   >@> data.txt## _ _ set terminal png size 400,300 _ set output “two-lines.png” _ unset key _ plot “data.txt” using 0:1 with lines, \ _ @<  >@"data.txt” using 0:2 with lines|| || ||line types|| || || ||# cubic-splineimage http://cdn.hyperpolyglot.org/images/cubic-spline.jpg _ [#cubic-spline-note cubic spline]|| || || ||# function-plotimage http://cdn.hyperpolyglot.org/images/function-plot.jpg _ [#function-plot-note function plot]||set terminal png size 400,300 _ set output ‘sin.png’ _ unset key _ plot [-4:4] sin(x)|| || ||# area-chartimage http://cdn.hyperpolyglot.org/images/area-chart.jpg width="75px” _ [#area-chart-note area chart]|| || || ||[#surface-plot surface plot]|| || || ||contour plot|| || || ||||||~ # chart-options[#chart-options-note chart-options]|| ||~ ||~ gnuplot||~ glpk|| ||[#univariate-title set chart title]||set title “a plot” _ plot “data.txt”|| || ||[#axis-label axis label]|| || || ||axis limits|| || || ||[#logarithmic-y-axis logarithmic y-axis]|| || || ||legend||##gray|# seq 1 20 | awk ‘{print rand() + rand(), rand() + rand()}’ \ _ #@<   >@> data.txt## _ _ set terminal png size 400,300 _ set output “legend.png” _ plot “data.txt” using 0:1 with lines title “first”, \ _ @<  >@"data.txt” using 0:2 with lines title “second”|| || ||legend options|| || || ||colors||##gray|# use a string to specify a color:## _ set terminal png background “black” _ set terminal png background “#000000” _ _ ##gray|# list recognized color names:## _ show colors|| || ||~ ||~ ##EFEFEF|@@________________________________________________________________@@##||~ ##EFEFEF|@@________________________________________________________________@@##||

# general-note + [#general General]

# version-used-note ++ [#version-used version used]

The version used to test examples in this sheet.

# show-version-note ++ [#show-version show version]

How to determine the version.

# grammar-invocation-note + [#grammar-invocation Grammar and Invocation]

# interpreter-note ++ [#interpreter interpreter]

How to execute a script.

pari/gp

The shebang style notation doesn’t work because GP doesn’t recognize the hash tag # as the start of a comment.

The {{-q}} option suppresses the GP startup message.

After the script finishes it will drop the user into the REPL unless there is a quit statement in the script:

code print(“Hello, World!”)

quit /code

# var-expr-note + [#var-expr Variables and Expressions]

# arithmetic-logic-note + [#arithmetic-logic Arithmetic and Logic]

# strings-note + [#strings Strings]

# dates-time-note + [#dates-time Dates and Time]

# multidimensional-arrays-note + [#multidimensional-arrays Multidimensional Arrays]

# sets-note + [#sets Sets]

# functions-note + [#functions Functions]

# execution-control-note + [#execution-control Execution Control]

# file-handles-note + [#file-handles File Handles]

# directories-note + [#directories Directories]

# libraries-namespaces-note + [#libraries-namespaces Libraries and Namespaces]

# processes-environment-note + [#processes-environment Processes and Environment]

# optimization-note + [#optimization Optimization]

# linear-regression-note + [#linear-regression Linear Regression]

# bar-charts-note + [#bar-charts Bar Charts]

# pie-chart-note ++ [#pie-chart pie chart]

gnuplot:

code set terminal png size 400,400 set output “piechart.png” set style fill solid 1.0 border -1

tot = 7 + 3 + 8 + 5 + 5 angle1 = 7.0 / tot * 360 angle2 = (7.0 + 3) / tot * 360 angle3 = (7.0 + 3 + 8) / tot * 360 angle4 = (7.0 + 3 + 8 + 5) / tot * 360

set object 1 circle at screen 0.5,0.5 size
screen 0.45 arc [0:angle1] fillcolor rgb “#FF0000” front set object 2 circle at screen 0.5,0.5 size
screen 0.45 arc [angle1:angle2] fillcolor rgb “yellow” front set object 3 circle at screen 0.5,0.5 size
screen 0.45 arc [angle2:angle3] fillcolor rgb “orange” front set object 4 circle at screen 0.5,0.5 size
screen 0.45 arc [angle3:angle4] fillcolor rgb “green” front set object 5 circle at screen 0.5,0.5 size
screen 0.45 arc [angle4:360] fillcolor rgb “blue” front

unset border unset tics unset key plot x with lines lc rgb “#ffffff” /code

# scatter-plots-note + [#scatter-plots Scatter Plots]

# line-surface-charts-note + [#line-surface-charts Line and Surface Charts]

# chart-options-note + [#chart-options Chart Options]

# gnuplot + [#top Gnuplot]

http://gnuplot.info/docs_5.0/gnuplot.pdf gnuplot 5.0

Gnuplot provides two plotting commands, {{plot}} for 2-dimensional plots and {{splot}} for 3-dimensional plots.

{{plot}} and {{splot}} can be used to plot data (1) generated by a function, (2) in a file, or (3) defined in the program using a named data block. The syntax for a named data block is similar to a shell script here document.

When the data to be plotted is in a file, {{plot}} or {{splot}} read the file directly. There is no way to read the data into a variable which can be manipulated by the program.

Data in a file must be in a tabular format. By default, whitespace is the column separator, but it can be changed to tabs, commas, or a set of characters specified with a string.

code set datafile separator “\t” /code

Headers and comments are permitted in the data file. By default, comments begin with a number sign {{#}}.

The type of plot created by {{plot}} or {{splot}} can be selected using the //set style// command. It can also be selected using a //with// clause in the {{plot}} or {{splot}} command. The default style is //points//. Here are some of the available styles:

||dots||scatterplot with single pixel points|| ||lines|| || ||points|| ||

//set and options//

# glpk + [#top GLPK]

http://www.cs.unb.ca/~bremner/docs/glpk/gmpl.pdf Modeling Language GNU MathProg

GLPK is a C library for solving linear programming problems, including mixed integer linear programming problems A command line interface called {{glpsol}} is also provided.

GLPK allows the problems to be specified in several formats, but we describe the MathProg or GMPL format, which is a subset of AMPL implemented by GLPK.

Input data is declared with the {{param}} statement, and values to be found by the solver are declared with the {{var}} statmement. Both parameters and variables can be scalars or multi-dimensional arrays. The types can be float, integer, binary, or string.

//sets//

//constraints and objective functions//

//data section; can everything be defined in model? data section or -d flag; what happens when data section misses parameters; data section limitations: parameters and sets, with just literals for values//