ProgTutorial/Recipes/ExternalSolver.thy
author Norbert Schirmer <norbert.schirmer@web.de>
Thu, 16 May 2019 19:56:12 +0200
changeset 567 f7c97e64cc2a
parent 565 cecd7a941885
child 569 f875a25aa72d
permissions -rw-r--r--
tuned ML-antiquotations; added intro portions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     1
theory ExternalSolver
346
0fea8b7a14a1 tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
     2
imports "../Appendix"
61
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     3
begin
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     4
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
     5
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
     6
section \<open>Executing an External Application (TBD) \label{rec:external}\<close>
61
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     7
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
     8
text \<open>
61
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     9
  {\bf Problem:}
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    10
  You want to use an external application.
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    11
  \smallskip
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    12
472
1bbe4268664d updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
    13
  {\bf Solution:} The function @{ML bash_output in Isabelle_System} might be the right thing for
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    14
  you.
61
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    15
  \smallskip
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    16
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    17
  This function executes an external command as if printed in a shell. It
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    18
  returns the output of the program and its return value.
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    19
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    20
  For example, consider running an ordinary shell commands:
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    21
567
f7c97e64cc2a tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents: 565
diff changeset
    22
  @{ML_matchresult [display,gray] 
472
1bbe4268664d updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
    23
    "Isabelle_System.bash_output \"echo Hello world!\"" "(\"Hello world!\\n\", 0)"}
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    24
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    25
  Note that it works also fine with timeouts (see Recipe~\ref{rec:timeout}
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    26
  on Page~\pageref{rec:timeout}), i.e. external applications are killed
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    27
  properly. For example, the following expression takes only approximately
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    28
  one second:
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    29
567
f7c97e64cc2a tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents: 565
diff changeset
    30
  @{ML_matchresult_fake [display,gray] 
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 517
diff changeset
    31
    "Timeout.apply (Time.fromSeconds 1) Isabelle_System.bash_output \"sleep 30\"
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 517
diff changeset
    32
     handle TIMEOUT => (\"timeout\", ~1)" "(\"timeout\", ~1)"}
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    33
472
1bbe4268664d updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
    34
  The function @{ML bash_output in Isabelle_System} can also be used for more reasonable
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    35
  applications, e.g. coupling external solvers with Isabelle. In that case,
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    36
  one has to make sure that Isabelle can find the particular executable.
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    37
  One way to ensure this is by adding a Bash-like variable binding into
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    38
  one of Isabelle's settings file (prefer the user settings file usually to
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    39
  be found at \<open>$HOME/.isabelle/etc/settings\<close>).
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    40
  
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    41
  For example, assume you want to use the application \<open>foo\<close> which
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    42
  is here supposed to be located at \<open>/usr/local/bin/\<close>.
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    43
  The following line has to be added to one of Isabelle's settings file:
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    44
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    45
  \<open>FOO=/usr/local/bin/foo\<close>
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    46
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    47
  In Isabelle, this application may now be executed by
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    48
567
f7c97e64cc2a tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents: 565
diff changeset
    49
  @{ML_matchresult_fake [display,gray] "Isabelle_System.bash_output \"$FOO\"" "\<dots>"}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    50
\<close>
94
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    51
531e453c9d67 rewrote recipes describing external solvers
boehmes
parents: 83
diff changeset
    52
517
d8c376662bb4 removed special ML-setup and replaced it by explicit markups (i.e., %grayML)
Christian Urban <urbanc@in.tum.de>
parents: 472
diff changeset
    53
end