quantifiers

Closures and universal quantification

不问归期 提交于 2019-12-03 07:26:35
问题 I've been trying to work out how to implement Church-encoded data types in Scala. It seems that it requires rank-n types since you would need a first-class const function of type forAll a. a -> (forAll b. b -> b) . However, I was able to encode pairs thusly: import scalaz._ trait Compose[F[_],G[_]] { type Apply = F[G[A]] } trait Closure[F[_],G[_]] { def apply[B](f: F[B]): G[B] } def pair[A,B](a: A, b: B) = new Closure[Compose[({type f[x] = A => x})#f, ({type f[x] = B => x})#f]#Apply, Id] {

Closures and universal quantification

断了今生、忘了曾经 提交于 2019-12-02 20:58:00
I've been trying to work out how to implement Church-encoded data types in Scala. It seems that it requires rank-n types since you would need a first-class const function of type forAll a. a -> (forAll b. b -> b) . However, I was able to encode pairs thusly: import scalaz._ trait Compose[F[_],G[_]] { type Apply = F[G[A]] } trait Closure[F[_],G[_]] { def apply[B](f: F[B]): G[B] } def pair[A,B](a: A, b: B) = new Closure[Compose[({type f[x] = A => x})#f, ({type f[x] = B => x})#f]#Apply, Id] { def apply[C](f: A => B => C) = f(a)(b) } For lists, I was able to encode cons : def cons[A](x: A) = {

Best way to perform universal instantiation in Coq

谁说胖子不能爱 提交于 2019-12-02 02:59:49
问题 Suppose I have an hypothesis H : forall ( x : X ), P x and a variable x : X in the context. I want to perform universal instantiation and obtain a new hypothesis H' : P x . What is the most painless way to do this? Apparently apply H in x does not work. assert ( P x ) followed by apply H does, but it can get very messy if P is complex. There's a similar question that seems somewhat related. Not sure if it can be applied here, though. 回答1: pose proof (H x) as H'. The parentheses are optional.

Surprising behaviour when trying to prove a forall

微笑、不失礼 提交于 2019-12-01 21:51:23
Consider the following SMT-LIB code: (set-option :auto_config false) (set-option :smt.mbqi false) ; (set-option :smt.case_split 3) (set-option :smt.qi.profile true) (declare-const x Int) (declare-fun trigF (Int Int Int) Bool) (declare-fun trigF$ (Int Int Int) Bool) (declare-fun trigG (Int) Bool) (declare-fun trigG$ (Int) Bool) ; Essentially noise (declare-const y Int) (assert (! (not (= x y)) :named foo )) ; Essentially noise (assert (forall ((x Int) (y Int) (z Int)) (! (= (trigF$ x y z) (trigF x y z)) :pattern ((trigF x y z)) :qid |limited-F| ))) ; Essentially noise (assert (forall ((x Int))

What's the theoretical basis for existential types?

风流意气都作罢 提交于 2019-11-29 19:04:42
The Haskell Wiki does a good job of explaining how to use existential types, but I don't quite grok the theory behind them. Consider this example of an existential type: data S = forall a. Show a => S a -- (1) to define a type wrapper for things that we can convert to a String . The wiki mentions that what we really want to define is a type like data S = S (exists a. Show a => a) -- (2) i.e. a true "existential" type - loosely I think of this as saying "the data constructor S takes any type for which a Show instance exists and wraps it". In fact, you could probably write a GADT as follows:

JavaScript: Invalid quantifier in regex

拟墨画扇 提交于 2019-11-29 10:09:45
The regex is constructed on the fly, but I've output it to firebug: (.{1,38})(+|$\n?) the error is invalid quantifier +|$\n?) I'm not sure where to start. The actual code is: var re = top.RegExp; var regex = new re("(.{1," + len + "})(+|$\\n?)", "gm"); UPDATE: Per Bennor McCarthy's instructions, I changed the code to this: var regex = new re("(.{1," + len + "})(\+|\$\\n?)", "gm"); Firebug still tells me this: invalid quantifier +|$\n?) [Break on this error] var regex = new re("(.{1," + len + "})(\+|\$\\n?)", "gm"); ANOTHER UPDATE Looks Like I had to double slash it and this solved the problem!

What's the theoretical basis for existential types?

為{幸葍}努か 提交于 2019-11-28 14:24:40
问题 The Haskell Wiki does a good job of explaining how to use existential types, but I don't quite grok the theory behind them. Consider this example of an existential type: data S = forall a. Show a => S a -- (1) to define a type wrapper for things that we can convert to a String . The wiki mentions that what we really want to define is a type like data S = S (exists a. Show a => a) -- (2) i.e. a true "existential" type - loosely I think of this as saying "the data constructor S takes any type

JavaScript: Invalid quantifier in regex

北城余情 提交于 2019-11-28 03:32:16
问题 The regex is constructed on the fly, but I've output it to firebug: (.{1,38})(+|$\n?) the error is invalid quantifier +|$\n?) I'm not sure where to start. The actual code is: var re = top.RegExp; var regex = new re("(.{1," + len + "})(+|$\\n?)", "gm"); UPDATE: Per Bennor McCarthy's instructions, I changed the code to this: var regex = new re("(.{1," + len + "})(\+|\$\\n?)", "gm"); Firebug still tells me this: invalid quantifier +|$\n?) [Break on this error] var regex = new re("(.{1," + len +

Capturing Quantifiers and Quantifier Arithmetic

删除回忆录丶 提交于 2019-11-27 04:01:21
At the outset, let me explain that this question is neither about how to capture groups, nor about how to use quantifiers, two features of regex I am perfectly familiar with. It is more of an advanced question for regex lovers who may be familiar with unusual syntax in exotic engines. Capturing Quantifiers Does anyone know if a regex flavor allows you to capture quantifiers? By this, I mean that the number of characters matched by quantifiers such as + and * would be counted, and that this number could be used again in another quantifier. For instance, suppose you wanted to make sure you have

How does the ? make a quantifier lazy in regex

只愿长相守 提交于 2019-11-26 21:46:03
问题 I've been looking into regex lately and figured that the ? operator makes the * , + , or ? lazy. My question is how does it do that? Is it that *? for example is a special operator, or does the ? have an effect on the * ? In other words, does regex recognize *? as one operator in itself, or does regex recognize *? as the two separate operators * and ? ? If it is the case that *? is being recognized as two separate operators, how does the ? affect the * to make it lazy. If ? means that the *