unification

Unification with STO detection

扶醉桌前 提交于 2021-01-20 18:52:47
问题 In ISO Prolog unification is defined only for those cases that are NSTO (not subject to occurs-check). The idea behind is to cover those cases of unifications that are mostly used in programs and that are actually supported by all Prolog systems. More specifically, ISO/IEC 13211-1:1995 reads: 7.3.3 Subject to occurs-check (STO) and not subject to occurs-check (NSTO) A set of equations (or two terms) is "subject to occurs- check" (STO) iff there exists a way to proceed through the steps of the

Unification with STO detection

拥有回忆 提交于 2021-01-20 18:50:00
问题 In ISO Prolog unification is defined only for those cases that are NSTO (not subject to occurs-check). The idea behind is to cover those cases of unifications that are mostly used in programs and that are actually supported by all Prolog systems. More specifically, ISO/IEC 13211-1:1995 reads: 7.3.3 Subject to occurs-check (STO) and not subject to occurs-check (NSTO) A set of equations (or two terms) is "subject to occurs- check" (STO) iff there exists a way to proceed through the steps of the

Unification with STO detection

本小妞迷上赌 提交于 2021-01-20 18:46:41
问题 In ISO Prolog unification is defined only for those cases that are NSTO (not subject to occurs-check). The idea behind is to cover those cases of unifications that are mostly used in programs and that are actually supported by all Prolog systems. More specifically, ISO/IEC 13211-1:1995 reads: 7.3.3 Subject to occurs-check (STO) and not subject to occurs-check (NSTO) A set of equations (or two terms) is "subject to occurs- check" (STO) iff there exists a way to proceed through the steps of the

How can Prolog derive nonsense results such as 3 < 2?

心已入冬 提交于 2020-12-26 07:13:42
问题 A paper I'm reading says the following: Plaisted [3] showed that it is possible to write formally correct PROLOG programs using first-order predicate-calculus semantics and yet derive nonsense results such as 3 < 2. It is referring to the fact that Prologs didn't use the occurs check back then (the 1980s). Unfortunately, the paper it cites is behind a paywall. I'd still like to see an example such as this. Intuitively, it feels like the omission of the occurs check just expands the universe

Implementing the Prolog Unification algorithm in Python? Backtracking

*爱你&永不变心* 提交于 2020-08-21 10:44:31
问题 I'm trying to implement Unification, but having problems.. already got dozen of examples,but all they do is to muddy the water. I get more confused than enlightened : http://www.cs.trincoll.edu/~ram/cpsc352/notes/unification.html https://www.doc.ic.ac.uk/~sgc/teaching/pre2012/v231/lecture8.html [code below is based on this intro] http://www.cs.bham.ac.uk/research/projects/poplog/paradigms_lectures/lecture20.html#representing https://norvig.com/unify-bug.pdf How can I implement the unification

`case` that refines arguments

孤街浪徒 提交于 2020-01-15 02:00:28
问题 In this answer on a question about the totality checker, a workaround involving using case instead of with was recommended. However, in situations where the result of the match refines the type of other arguments, this transformation is not straightforward to make. For example, given the following definitions: data IsEven : Nat -> Nat -> Type where Times2 : (n : Nat) -> IsEven (n + n) n data IsOdd : Nat -> Nat -> Type where Times2Plus1 : (n : Nat) -> IsOdd (S (n + n)) n total parity : (n :

Which is the type of (flip .)?

我们两清 提交于 2019-12-31 07:37:05
问题 I'm trying to understand why the type of: (flip .) is: (a -> a1 -> b -> c) -> a -> b -> a1 -> c First of all, the type of: flip: is (a -> b -> c) -> b -> a -> c (.): is (b -> c) -> (a -> b) -> a -> c I will rename the variables to be more clear in my explanation, so the types: flip: is (ax -> bx -> cx) -> bx -> ax -> cx (.): is (by -> cy) -> (ay -> by) -> ay -> cy Then I try substituing like this: ax = (by -> cy) bx = (ay -> by) cx = ay -> cy So the resulting type is: (ay -> by) (by -> cy) ->

Which is the type of (flip .)?

人盡茶涼 提交于 2019-12-31 07:37:03
问题 I'm trying to understand why the type of: (flip .) is: (a -> a1 -> b -> c) -> a -> b -> a1 -> c First of all, the type of: flip: is (a -> b -> c) -> b -> a -> c (.): is (b -> c) -> (a -> b) -> a -> c I will rename the variables to be more clear in my explanation, so the types: flip: is (ax -> bx -> cx) -> bx -> ax -> cx (.): is (by -> cy) -> (ay -> by) -> ay -> cy Then I try substituing like this: ax = (by -> cy) bx = (ay -> by) cx = ay -> cy So the resulting type is: (ay -> by) (by -> cy) ->

Haskell: how to infer the type of an expression manually

你。 提交于 2019-12-28 12:28:52
问题 Given ist the Haskell function: head . filter fst The question is now how to find the type "manually" by hand. If I let Haskell tell me the type I get: head . filter fst :: [(Bool, b)] -> (Bool, b) But I want to understand how this works using only the signatures of the used functions which are defined as follows: head :: [a] -> a (.) :: (b -> c) -> (a -> b) -> a -> c filter :: (a -> Bool) -> [a] -> [a] fst :: (a, b) -> a Edit: so many very good explanations ... it's not easy to select the

Manual derivation of the type for `f1 x xs = (filter . (<)) x xs`

旧巷老猫 提交于 2019-12-25 02:19:32
问题 I want to manually derive the type of: f1 x xs = (filter . (<)) x xs First time we see x , so: x :: t1 Then (<) has this type: (<) :: Ord a1 => a1 -> a1 -> Bool We can only say (< x) if the following types can be unified: t1 ~ a1 Then x :: a1 So (<x) :: Ord a1 => a1 -> Bool Filter has this type filter :: (a2 -> Bool) -> [a2] -> [a2] First time to see xs, so: xs :: t2 We can only say (filter . (<)) x xs if the following types can be unified: a1 -> Bool ~ a2 -> Bool t2 ~ [a2] So I get that f1 :