Coq --- Arguments directive - arguments

I am reading Software foundations book and I came across a command that declares parameters
as implicit:
Arguments nil {X}.
where, for example:
Inductive list (X:Type) : Type :=
| nil : list X
| cons : X -> list X -> list X.
However, whenever I try to execute such commands I get the following message:
Error: No focused proof (No proof-editing in progress).
The same message appears even if I try to compile scripts that come with the book. What could be the problem?
I am using Coq version 8.3pl4 and CoqIDE editor.

I just tried it on my (somewhat old) Coq 8.4 and I don't have any problem with the implicit declaration.
However if I write Argument instead of Arguments (notice the lack of "s"), I get
Error: Unknown command of the non proof-editing mode.
Did you correctly spelled it ?
EDIT: sorry, I miss-read your version. It seems that the Arguments command has been added post 8.4 (it does not appear here but appears here. I advise you update your Coq version if possible, or restrict to using 8.3 Implicit related commands (wild guess: Implicit Arguments foo.)

Related

Why do I get the error of "expr: syntax error" in a simple shell script [duplicate]

This question already has answers here:
macOS Mojave version 10.14.1 bash-3.2 expr: syntax error
(1 answer)
Bash: Find position of character in a string under OS X
(2 answers)
Closed 2 years ago.
My script is
#! /bin/bash
v1="hello"
v2="world1"
subIndex=`expr index "${v1}" "${v2}"`
echo $subIndex
and I got the error of "expr: syntax error"
It looks like you're using a version of expr which doesn't have an index operator.
As you can see in the POSIX standard man page there's no index in the table of operators. The only mention of index in that document says that the behaviour is undefined. We can assume that the standardisation process saw that only some implementations supported index and some or all of the participants did not want to add the additional functionality.
Some other implementations contain additional functionality above and beyond what is specified in the standard. You'll need to install one of these implementations or change your code. GNU expr is one implementation that does have index, length, etc..

Ghostscript -d vs -s command line parameters

I recently upgraded Ghostscript from 9.10 to 9.53.3 (also tried 9.50 first). Scripts that have run for years started failing with
Unrecoverable error: rangecheck in .putdeviceprops
After some research and trial and error testing, it seems that Ghostscript changed some of the command line switches from "-s" to "-d". for example:
-sGrayImageResolution=600 now errors but -dGrayImageResolution=600 does not.
Some switches appear to accept either form. For example:
-sColorImageResolution=600 and -dColorImageResolution=600 both work.
(Note: When I say "work" I mean they do not throw the error.)
I have 2 questions
Where can I find a complete list of Ghostscript command line parameters? The Ghostscript documents seem to be incomplete.
What is the difference between -s and -d for a switch? (this is really just a curiosity question)
Thanks
The ColorImageResolution and GrayImageResolution are PostScript distiller parameters found in the VectorDevices.htm#PDFWRITE so are used with setdistillerparams and currentdistillerparams in the PostScript code for -sDEVICE=pdfwrite. Also see TN 5151 Acrobat Distiller Parameters. For example:
<< /MonoImageResolution 72 >> setdistillerparams
EDIT: Here are some more: distillerparams
Some settings can be defined in the system dictionary without error except are never used for anything. Be sure to check all of the documentation. There are some settings not listed in the documentation that can be found by searching in the ghostscript Resource/Init files especially for advanced users. Some of these are unique to ghostscript and beyond normal PostScript.
This is from the ghostscript Use.htm#Options :
-Dname
-dname
Define a name in systemdict with value=true.
-Dname=token
-dname=token
Define a name in systemdict with the given value. The value must be a valid PostScript token (as defined by the token operator). If the
token is a non-literal name, it must be true, false, or null. It is
recommeded that this is used only for simple values -- use -c (above)
for complex values such as procedures, arrays or dictionaries.
Note that these values are defined before other names in systemdict, so any name that conflicts with one usually in systemdict
will be replaced by the normal definition during the interpreter
initialization.
-Sname=string
-sname=string
Define a name in systemdict with a given string as value. This is different from -d. For example, -dXYZ=35 on the command line is
equivalent to the program fragment
/XYZ 35 def
whereas -sXYZ=35 is equivalent to
/XYZ (35) def

Go programs won't run after MacOS Catalina upgrade

This might be a weird question, but some programs written in Go won't run on my MacBook Pro after MacOS Catalina upgrade.
However a basic "Hello World" program runs, but then I am using the writing a program using net/http package I get the following error:
Note: The programs are correct, they run fine inside a Docker container
Output (IntelliJ):
# runtime/cgo
In file included from gcc_darwin_amd64.c:6:
/usr/local/include/pthread.h:331:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:2: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
/usr/local/include/pthread.h:331:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:34: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
/usr/local/include/pthread.h:540:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:2: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
/usr/local/include/pthread.h:540:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:34: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
Things that I have already tried:
Reinstall go
Reinstall xcode
Check if GOPATH & GOROOT are properly set
Used:
MacOS version - Catalina 10.15.6
Go version - go1.15.2 darwin/amd64
Type xcode-select -print-path in terminal window and check your installed directory. In my case the output was: /Applications/Xcode.app/Contents/Developer
If it's the same case then using the following command on your terminal can fix things:
sudo xcode-select --switch /Library/Developer/CommandLineTools
Another option is to use CGO_CPPFLAGS as mentioned in this issue, but it would work within the session:
export CGO_CPPFLAGS="-Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined -Wno-builtin-requires-header"
Sadly, none of the tryouts worked.
I have been using IntelliJ IDEA Ultimate for sometime now.. so I tried to setup Go SDK, GOROOT and GOPATH using the IDE (just a thought came to my mind).
I uninstalled/deleted everything related to Go on my MacBook.
Then I installed the Go plugin on IntelliJ IDEA and as expected it prompted that Go SDK is not available, neither GOROOT and GOPATH are set.
I followed the instructions and IntelliJ IDEA took care of the rest!
It downloaded and installed Go SDK, asked me to select GOPATH, it indexed stuff and now every thing is working like a charm!
This is a bug in the <pthread.h> that ships with macOS tools:
This macro is even bogus for more than one reason! The definition in <pthread.h> is this:
#define _PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT \
defined(SWIFT_CLASS_EXTRA) && (!defined(SWIFT_SDK_OVERLAY_PTHREAD_EPOCH) || (SWIFT_SDK_OVERLAY_PTHREAD_EPOCH < 1))
The macro expansion is not properly parenthesized. The macro is used this way in the same file:
#if !_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT
Which expands to:
#if !defined(SWIFT_CLASS_EXTRA) && (!defined(SWIFT_SDK_OVERLAY_PTHREAD_EPOCH) || (SWIFT_SDK_OVERLAY_PTHREAD_EPOCH < 1))
The ! only applies to the first test defined(SWIFT_CLASS_EXTRA) not to the whole boolean expression.
The compiler does not detect this problem, it just complains about the defined preprocessor operator coming from a macro expansion, which has undefined behavior as specified in the C Standard:
6.10.1 Conditional inclusion
[...]
Constraints
1 The expression that controls conditional inclusion shall be an integer constant expression except that: identifiers (including those lexically identical to keywords) are interpreted as described below; and it may contain unary operator expressions of the form
defined identifier
or
defined ( identifier )
which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is predefined or if it has been the subject of a #define preprocessing directive without an intervening #undef directive with the same subject identifier), 0 if it is not.
2 Each preprocessing token that remains (in the list of preprocessing tokens that will become the controlling expression) after all macro replacements have occurred shall be in the lexical form of a token (6.4).
Semantics
3 Preprocessing directives of the forms
# if constant-expression new-line groupopt
# elif constant-expression new-line groupopt
check whether the controlling constant expression evaluates to nonzero.
4 Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the defined unary operator), just as in normal text. If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined. After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0, and then each preprocessing token is converted into a token. The resulting tokens compose the controlling constant expression which is evaluated according to the rules of 6.6. For the purposes of this token conversion and evaluation, all signed integer types and all unsigned integer types act as if they have the same representation as, respectively, the types intmax_t and uintmax_t defined in the header <stdint.h>. This includes interpreting character constants, which may involve converting escape sequences into execution character set members. Whether the numeric value for these character constants matches the value obtained when an identical character constant occurs in an expression (other than within a #if or #elif directive) is implementation-defined. Also, whether a single-character character constant may have a negative value is implementation-defined.
This relevant phrase is If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined.
It is unclear if generated just means produced as part of the macro expansion or more specifically produced by token pasting. clang seems to consider that any defined token produced coming from a macro expansion has undefined behavior in a #if controlling expression.
For both reasons, this seems to be a bug in <pthread.h> for Apple to fix.

Erlang dbg – Debugging on production OTP system with remote shell

I have an OTP based Erlang application that seems to behave weird.
I want to connect to the erlang shell and trace exactly what is happening.
I can do all my calls to dbg:tracer(), dbg:tp() etc. just fine, however no output is sent to my shell.
I think this might be, because I am connecting via a remote shell.
However, when I call dbg:n(wiwob#vlxd38-wob). I get an error:
** exception error: bad argument in an arithmetic expression
in operator -/2
called as wiwob#vlxd38 - wob
How can I find out which shell the output is sent to and pipe it to my shell?
The argument to dbg:n/1 must be an atom and wiwob#vlxd38-wob is not an atom, it needs to quoted like 'wiwob#vlxd38-wob'. For the syntax of an atom, and other data types, see Atoms.
I cannot help you for the dbg problem, you do not give enough information about how you connect the debugger to a process, module ...
For the second point the error is self explanatory, parsing the expression wiwob#vlxd38-wob, the shell try to execute
wiwob#vlxd38 minus wob, which is impossible with 2 atoms.
the function dbg:n/1 has the folowing specs:
n(Nodename) -> {ok, Nodename} | {error, Reason}
Nodename = atom()
Reason = term()
so you must write your node name as 'wiwob#vlxd38-wob' in order to force the whole expression to be a single atom.

How do I show the results of pattern-matching goals with several free variables in SWI-Prolog from a shell invocation?

Let's use the following prolog base :
father(anakinSkywalker, princessLeia).
father(anakinSkywalker, lukeSkywalker).
saysOhNo(lukeSkywalker).
sdesciencelover asked how to show the results of pattern-matching goals in swi-prolog from a shell invocation, and got an answer giving a manual transformation on the query, to isue a write.
swipl -q -s kb.pl -t "father(anakinSkywalker,X), writeln(X), false"
Result:
princessLeia
lukeSkywalker
This works fine when one only has a few queries with a single free variable, but manually transforming each one becomes tedious, and if we want proper output with the name of each variable along with its result, it soon becomes very annoying. For example to run the query father(AVariable, Another), one needs to write:
swipl -q -s kb.pl -t "father(AVariable,Another), write('AVariable='), write(AVariable), write(', Another='), writeln(Another), false"
Result:
AVariable=anakinSkywalker, Another=princessLeia
AVariable=anakinSkywalker, Another=lukeSkywalker
I tried to feed it the commands from a pipe, but it doesn't work great (I can't detect when it has finished writing the results, so it just hangs afterwards, and no newline separates the answers) :
(echo "father(X,Y)."; while true; do echo ";"; done) | swipl -q -s kb.pl
Result :
X = anakinSkywalker,
Y = princessLeia X = anakinSkywalker,
Y = lukeSkywalker.
swipl hangs here, and needs to be stopped with Control-C.
I know I could use a sed script to pre-process queries, adding the necessary code to print the variables in capital letters, but it would need a fair amount of work to work on complex queries, for example where two predicates must be satisfied :
father(X,Y), saysOhNo(Y).
To always give correct results, one would need to write a parser for prolog, which would be useless work since prolog already know how to do this interactively.
So here's my question : is there a way to tell GNU prolog or SWI prolog (or any other free version that can be easily installed on linux) to run some queries and print the results, just like they would do interactively, but without requiring me to type (or copy-paste) each query by hand ?
Edit : a way to store a series of queries in a file (either in the kb.pl file or an auxiliary file) and run them all, showing their results would be even better.
So far, here are the methods I found :
In gprolog
Using false's answer, I found that one must add a line at the top of the kb.pl file:
a(_) :- fail.
and then use ./query.sh kb.pl "father(X,Y), saysOhNo(Y)", where query.sh is:
#!/bin/sh
echo "a(fail)." | gprolog --query-goal "consult('$1'), $2"
When the query returns immediately (i.e. no results or a single result and gprolog managed to detect it was the last one), this will run the query consult('kb.pl'), actual_query., and then run the query a(fail). which will simply print an extraneous no on the console, thanks to the always-false predicate we added at the top of the file.
When gprolog asks what to do (i.e. several results, or a single result and gprolog couldn't detect it was the last one), this will run the query consult('kb.pl'), actual_query., read the a which asks gprolog to print all results, and then it will run the query (fail). which will simply print an extraneous no on the console, because these are just grouping parenthesis, so the query is equivalent to fail..
In xsb
One can use ./query.sh kb.pl "father(X,Y), saysOhNo(Y)", where query.sh is:
#!/bin/sh
(echo "consult('$1'), ${2%.}."; yes halt.) | xsb --noprompt --quietload --nobanner
When xsb asks what to do next, if the user types a non-empty string, followed by enter, it will print the next result, otherwise it will stop searching solutions to the current query. Therefore, with the yes halt. command, we type an infinite stream of non-empty lines. xsb will print all results to the query (each time reading halt., so as it is a non-empty string, it will continue with the next result), and return to its prompt. Then, the following halt. it receives will tell it to quit.
In swi-prolog
I haven't found a solution yet.
[rant]All this would be so much simpler, if the people building prolog implementations actually thought about using them non-interactively, like it's possible with most other languages.[/rant]
You can use the command-line option --query-goal in GNU. Like so:
$ echo a| gprolog --query-goal 'X = 1 ; X =2'
GNU Prolog 1.4.1
By Daniel Diaz
Copyright (C) 1999-2012 Daniel Diaz
| ?- X = 1 ; X =2.
X = 1 ? a
X = 2
yes
You may have found a solution for your problem but anyway, here goes my approach. You can always recurse to the bagof built-in predicate. You may read what it does in the docs, this way you will learn more about it.
swipl -q -s starwars.pl -t "bagof(X, Y^father(X,Y), BagOfFathers), bagof(Y, X^father(X,Y), BagOfChildren), writeln(BagOfFathers), writeln(BagOfChildren)."
[anakinSkywalker,anakinSkywalker]
[princessLeia,lukeSkywalker]
You can also process it later as a mapping or whatever you want, the relations are 1:1 (No sure if is the correct way of stating it but I hope you get it)
you can use the following bash script for swi-prolog:
#!/bin/sh
exec swipl -q -f none -g "load_files([interface],[silent(true)])" \
-t interface:get_args -- $*
this will load the file interface.pl and call the predicate get_args/0
to get the command line arguments you can call:
current_prolog_flag(argv, Arguments)
of course you can change the names of the predicates/files loaded.
the silent(true) arguments suppresses informational messages such as the intro text
edit:
the error message you get is cause you probably dont have an interface.pl file (neither a get_args/0 predicate).
you will have to replace interface with kb (or however you name the file) and interface:get_args with kb:father(X,Y), saysOhNo(Y) or use an auxiliary predicate within your prolog file such as run(X,Y):- father(X,Y), saysOhNo(Y) (which may be kinda cleaner)

Resources