問題タブ [logic-programming]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
2 に答える
152 参照

haskell - 与えられたステートメントの正しいプログラムはどれですか?

問題文:

すべての辺が整数で、すべての辺が10以下で、周囲長が24である直角三角形を見つけます。

次の2つの解決策のうち、問題を正しく解釈し、正しい答えを与えるのはどれですか?

最初の解決策が正しくない場合、同様のシナリオでそのようなプログラミングエラーを回避するにはどうすればよいですか?

最初の解決策:

2番目の解決策:

0 投票する
4 に答える
1036 参照

prolog - Prolog-どのような文を表現できないのか

Prologではどんな文章が表現できないのかしら?私は一般的な論理プログラミングを研究してきましたが、一階述語論理は、Prologが基づいている明確な論理(ホーン節)と比較してより表現力があることを学びました。頭を動かすのは難しいテーマです。

したがって、たとえば、次の文を表現できます。

もしそうなら、表現できない他の文章はありますか?そうでない場合、なぜですか?

0 投票する
1 に答える
860 参照

functional-programming - 純粋に宣言型の汎用プログラミング言語はありますか?

私は宣言型言語を研究してきましたが、宣言型は論理言語と関数型言語の両方を包括する用語のようです。それとも私が間違っていますか?機能的または論理的 (al) として分類できず、単に「宣言的」である汎用宣言型プログラミング言語はありますか?

0 投票する
1 に答える
316 参照

clojure - core.logic を使用して一意の DAG 親を一覧表示する

これは、(願わくば) 単純な論理プログラムで、私がしばらくの間行き詰っています。

親ノードのリストを生成するときに、core.logic のエッジ リレーションによって表される DAG があります。グラフに「ダイヤモンド シェイプ」があると、重複が発生します (ここではサイクルについて話しているわけではありません)。

この場合、親の個別のリストを生成する方法はありますか (parento を書き直すなど)?

(:b :c :a) を取得したいのですが、run* ステートメント内で実行したいと考えています (つまり、結果をセットにラップすることは、私が目指していることではありません)。

また、「^:tabled」をparentoに追加するとうまくいくようですが、tabledが導入するメモ化はしたくありません。

0 投票する
2 に答える
1755 参照

prolog - プロローグ: 失敗によるループ

次の障害駆動ループを使用して、セミコロンを使用せずにすべてをリストしました。

クエリモードでは、期待どおりにこれを取得します

これらの数値を画面に書き込むのではなく、リストに挿入するにはどうすればよいですか? someGoalバックトラッキングは暗黙のように見えるため、これを処理できませんでした。

0 投票する
1 に答える
367 参照

programming-languages - リストベースのツリーの統合アルゴリズム

次の状況を処理するには、統合アルゴリズムが必要です。

式ツリーの各ノードには、子のリスト (連想) またはセット (連想および可換) があります。特定のパターンに可能なすべての一致を取得したいと思います。

ここに例があります。+ が可換で * が可換でない行列を扱っていると仮定しましょう。

表現:A + B*C*D + E

または:Add(A, Mul(B, C, D), E)

パターン:X + Y*Z

2試合見た

質問: これを処理する標準アルゴリズムはありますか?

0 投票する
1 に答える
948 参照

prolog - プロローグ: 再帰的なヘルパー述語を取り除く

そのため、split 内で直接ソート ライブラリ述語を使用して、ラッパー句を取り除こうとしています。split とは、次のようなリストから数値のリストを生成することです: [1:2,3:2,4:6] ---split--> [1,2,3,2,4,6] ]。しかし、生成されたリストには重複が含まれており、それは望ましくないため、ラッパーを使用して分割と並べ替えを組み合わせ、目的の結果 [1,2,3,4,6] を生成しています。

ラッパーを取り除き、分割内で並べ替えを使用したいのですが、「エラー: sort/2: 引数が十分にインスタンス化されていません」というメッセージが表示され続けます。何か案は?ありがとう :)

0 投票する
3 に答える
2811 参照

prolog - プロローグ通訳者を探しています

私はプロローグが初めてで、いくつかのロジックプログラムを試して、素敵なプロローグインタープリターを探しています。なにか提案を?

0 投票する
4 に答える
3020 参照

haskell - Haskell's type system and logic programming - how to port Prolog programs to type level

I'm trying to understand the relation between a logic programming language(Prolog in my case) and Haskell's type system.

I know both use unification and variables to find values(or types, in Haskell's type system) depending on relations. As an exercise to understand similarities and differences between them better, I tried to rewrite some simple prolog programs in Haskell's type level, but I'm having trouble with some parts.

First, I rewrote this simple prolog program:

as:

it works fine, but I couldn't extend it with this Prolog:

What I tried was this:

The problem with this code is that last two instances are causing fundep conflict. I can understand why, but it seems to me that it shouldn't be a problem since their guard parts(or whatever it's called it, I mean the (Greaterthan a b c) => part) are different, so that as and bs in last two insance declarations are actually different values and there are no conflicts.


Another program I tried to rewrite was this:

(btw, examples are from Learn Prolog Now book)

And I'm getting "duplicate instances" error in last line. I think it's a similar problem, even if I have a different guard parts, I'm getting errors because body parts(I mean Descend a b parts) are the same.

So I'm looking for ways to port that Prolog programs to Haskell's type level, if possible. Any help will be appreciated.

EDIT:

Ed'ka's solution works but in a completely different way. I'm still trying to understand when we can run a Prolog program in type-system, when/why we need to write a different algorithm to make it work(like in Ed'ka's solution), and when/why there's no way to implemenet a program in Haskell's type-system.

Maybe I can find some pointers about this after reading "Fun With Functional Dependencies".