prolog

Prolog - Recursively append numbers to a list

点点圈 提交于 2020-12-11 08:58:05
问题 I am just starting to learn Prolog, and I am having troubles wrapping my head around recursive concepts. Right now, solely for the purpose of practice, I am trying to write a program that appends 10 numbers to a list and then prints out that list. The self-imposed rule for this program is that the list has to be 'declared' (I am not sure if that is the correct word for Prolog) in a main predicate, which calls another predicate to append numbers to the list. This is what I have so far, and I

How to find out if Prolog performs Tail Call Optimization

假如想象 提交于 2020-12-08 07:33:14
问题 Using the development version of SWI Prolog (Win x64), I wrote a DCG predicate for a deterministic lexer (hosted on github) (thus all external predicates leave no choice points): read_token(parser(Grammar, Tables), lexer(dfa-DFAIndex, last_accept-LastAccept, chars-Chars0), Token) --> ( [Input], { dfa:current(Tables, DFAIndex, DFA), char_and_code(Input, Char, Code), dfa:find_edge(Tables, DFA, Code, TargetIndex) } -> { table:item(dfa_table, Tables, TargetIndex, TargetDFA), dfa:accept(TargetDFA,

How to find out if Prolog performs Tail Call Optimization

泄露秘密 提交于 2020-12-08 07:33:02
问题 Using the development version of SWI Prolog (Win x64), I wrote a DCG predicate for a deterministic lexer (hosted on github) (thus all external predicates leave no choice points): read_token(parser(Grammar, Tables), lexer(dfa-DFAIndex, last_accept-LastAccept, chars-Chars0), Token) --> ( [Input], { dfa:current(Tables, DFAIndex, DFA), char_and_code(Input, Char, Code), dfa:find_edge(Tables, DFA, Code, TargetIndex) } -> { table:item(dfa_table, Tables, TargetIndex, TargetDFA), dfa:accept(TargetDFA,

How to find out if Prolog performs Tail Call Optimization

Deadly 提交于 2020-12-08 07:32:15
问题 Using the development version of SWI Prolog (Win x64), I wrote a DCG predicate for a deterministic lexer (hosted on github) (thus all external predicates leave no choice points): read_token(parser(Grammar, Tables), lexer(dfa-DFAIndex, last_accept-LastAccept, chars-Chars0), Token) --> ( [Input], { dfa:current(Tables, DFAIndex, DFA), char_and_code(Input, Char, Code), dfa:find_edge(Tables, DFA, Code, TargetIndex) } -> { table:item(dfa_table, Tables, TargetIndex, TargetDFA), dfa:accept(TargetDFA,

How to choose between bagof, setof and findall in Prolog

自闭症网瘾萝莉.ら 提交于 2020-12-08 06:46:33
问题 How does one choose between bagof, setof and findall? Are there any important differences? Which is most commonly used and which is the safest? Thanks for your comments/answers. I checked the SWI-Prolog manual page on findall/3 and found them to be very similar. 回答1: That's a great question! I am not attempting to give an exhaustive answer, but I would like to suggest a few lines of thought that can help you to understand these predicates better: Think about which of these predicates are more

Prolog implementation of Quine's algorithm for classical propositional logic (in Quine's “Methods of Logic”)

旧城冷巷雨未停 提交于 2020-12-05 05:00:05
问题 I know only one prover that translates the algorithm that Quine gave for classical propositional logic in his book Methods of Logic (Harvard University Press, 1982, ch. 1 sec. 5, pp. 33-40), this prover is in Haskell and it is here: Quine's algorithm in Haskell I tried to translate Quine's algorithm in Prolog, but until now I have not succeeded. It is a pity because it is an efficient algorithm and a Prolog translation would be interesting. I am going to describe this algorithm. The only

How to call a predicate from another predicate in Prolog?

戏子无情 提交于 2020-12-03 20:43:15
问题 So I just started Prolog and I was wondering two things: 1) Is there built in functions (or are they all called predicates?) for simple things like max of 2 numbers, or sine of a number, etc... If so, how do I access them? 2) How can I call a predicate from another one? I wrote two predicates called car and cdr. car returns the head of a list and cdr returns the list without the head. But now I want to call car on the cdr. Here are some examples for clarification: car([3,4,5,5], H). would

How to call a predicate from another predicate in Prolog?

泪湿孤枕 提交于 2020-12-03 20:26:09
问题 So I just started Prolog and I was wondering two things: 1) Is there built in functions (or are they all called predicates?) for simple things like max of 2 numbers, or sine of a number, etc... If so, how do I access them? 2) How can I call a predicate from another one? I wrote two predicates called car and cdr. car returns the head of a list and cdr returns the list without the head. But now I want to call car on the cdr. Here are some examples for clarification: car([3,4,5,5], H). would

Littlest JupyterHub| 06 使用conda,pip或apt方式安装依赖库

淺唱寂寞╮ 提交于 2020-11-19 10:47:23
在TLJH中,所有的用户使用的是同一个conda环境,用户可以调用环境中的所有软件包,管理员可以通过多种方式为用户安装所需要的软件环境。 通过pip安装依赖包 pip工具用于从Python Packaging Index(PyPI)中下载安装依赖,PyPI中有超过145000个软件包。 1、使用管理员权限登录JupyterHub并打开一个命令行窗口 2、输入安装命令 sudo -E pip install <packages-name> 根据需要将命令中尖括号部分进行替换,以安装numpy为例: 通过conda安装依赖包 conda可以安装来自其他语言中的软件包,如node,R等,特别是当依赖包需要链接到C/Fortran代码时,推荐使用conda而不是pip安装 1、使用管理员权限登录JupyterHub并打开一个命令行窗口 2、输入安装命令 sudo -E conda install -c conda-forge <package-name> 根据需要将命令中尖括号部分进行替换,以安装gdal为例: 通过apt安装依赖包 apt是 Ubuntu Linux 发行版的官方软件包管理器,它可以安装实用程序(如 vim、 sl、 htop 等)、服务器应用(postgres、 mysql、 nginx 等)、比 conda 支持更多的语言(haskell、 prolog、