我一直在谷歌搜索一段时间没有相关的结果.什么是采取图像的命令,通过X,Y像素的偏移移动/平移它并保存结果?
假设我们有一个简单的语法规范.有一种方法可以枚举该语法的术语,通过对角迭代来保证任何有限项都具有有限的位置.例如,对于以下语法:
S ::= add
add ::= mul | add + mul
mul ::= term | mul * term
term ::= number | ( S )
number ::= digit | digit number
digit ::= 0 | 1 | ... | 9
Run Code Online (Sandbox Code Playgroud)
您可以枚举这样的术语:
0
1
0+0
0*0
0+1
(0)
1+0
0*1
0+0*0
00
... etc
Run Code Online (Sandbox Code Playgroud)
我的问题是:有没有办法做相反的事情?也就是说,采用该语法的有效术语,比如说0+0*0,并在这样的枚举中找到它的位置 - 在这种情况下,9?
是否有更快的替代以下表达式:
Math.pow(2,Math.floor(Math.log(x)/Math.log(2)))
Run Code Online (Sandbox Code Playgroud)
也就是说,取最接近(较小)的2的整数倍?我在内循环中有这样的表达.我怀疑它可能会快得多,考虑到可以从双尾的IEEE 754表示中获取尾数.
我不是varargs的最大粉丝,但我一直认为applicative(f <$> x <*> y)和idiom([i| f x y |])样式都有太多的符号.我通常喜欢liftA2 f x y这样做,但我也认为A2有点难看.从这个问题,我已经了解到可以在Haskell中实现vararg函数.这样,是否可以使用相同的原理来实现提升功能,例如:
lift f a b == pure f <*> a <*> b
Run Code Online (Sandbox Code Playgroud)
我试过替换引用代码的+by <*>:
class Lift r where
lift :: a -> r
instance Lift a where
lift = id
instance (Lift r) => Lift (a -> r) where
lift x y = lift (x <*> y)
Run Code Online (Sandbox Code Playgroud)
但我无法让这些类型正确......
我最近在lambda演算中编写了很多程序,我希望我可以实时运行其中一些程序.然而,尽管趋势功能范例基于lambda演算和B减少规则,但我找不到一个不是玩具的单一评估者,而不是效率.功能语言应该很快,但我知道的那些实际上并不提供对普通表单的访问(参见Haskell的惰性求值程序,Scheme的闭包等),因此不能用作LC求值程序.
这让我想知道:只是不可能有效地评估lambda演算术语,它只是一个历史事故/缺乏兴趣,没有人决定为它创建一个快速评估者,或者我只是缺少一些东西?
algorithm lambda computer-science functional-programming lambda-calculus
请注意以下课程:
class ListIsomorphic l where
toList :: l a -> [a]
fromList :: [a] -> l a
Run Code Online (Sandbox Code Playgroud)
我也要求toList . fromList == id.如何编写重写规则来告诉GHC进行替换?
假设您想要找到T满足以下等式的λ演算程序:
(T (? f x . x)) = (? a t . a)
(T (? f x . (f x))) = (? a t . (t a))
(T (? f x . (f (f x)))) = (? a b t . (t a b))
(T (? f x . (f (f (f x)))) = (? a b c t . (t a b c))
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我手动找到了这个解决方案:
T = (? t . (t (? b c d . (b (? …Run Code Online (Sandbox Code Playgroud) haskell functional-programming equation lambda-calculus solver
int eq3(int a, int b, int c, int d, int e, int f){
return a == d || a == e || a == f
|| b == d || b == e || b == f
|| c == d || c == e || c == f;
}
Run Code Online (Sandbox Code Playgroud)
如果3个第一个int中的任何一个等于3个最后一个int中的任何一个,则此函数接收6个int并返回true.是否有任何类似的方式使其更快?
我采用了AndrásKovács的DBIndex.hs,这是一个非常简单的依赖类型核心的实现,并且尽可能地进一步简化它,而不是"破坏"类型系统.经过几次简化后,我留下了更小的东西:
{-# language LambdaCase, ViewPatterns #-}
data Term
= V !Int
| A Term Term
| L Term Term
| S
| E
deriving (Eq, Show)
data VTerm
= VV !Int
| VA VTerm VTerm
| VL VTerm (VTerm -> VTerm)
| VS
| VE
type Ctx = ([VTerm], [VTerm], Int)
eval :: Bool -> Term -> Term
eval typ term = err (quote 0 (eval term typ ([], [], 0))) where
eval :: Term -> …Run Code Online (Sandbox Code Playgroud) In JavaScript, the NaN value can be represented by a wide range of 64-bit doubles internally. Specifically, any double with the following bitwise representation:
x111 1111 1111 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
Run Code Online (Sandbox Code Playgroud)
Is interpreted as a NaN. My question is: suppose I cast two 32-bit uints to a JS Number using ArrayBuffers, pass it around, then cast it back to two 32-bit uints. Will the recovered bits be the same as the …
haskell ×5
algorithm ×2
ieee-754 ×2
javascript ×2
agda ×1
applicative ×1
c ×1
double ×1
equation ×1
ghc ×1
grammar ×1
imagemagick ×1
lambda ×1
move ×1
offset ×1
optimization ×1
performance ×1
solver ×1
typeclass ×1
types ×1