Order-incompleteness and finite lambda reduction models
- 格式:pdf
- 大小:170.32 KB
- 文档页数:15
lambda表达式的运算符-回复lambda表达式是一种简洁而强大的函数定义方式,它引入了一些特殊的运算符以帮助我们更灵活地定义函数。
本文将以中括号内的内容为主题,详细介绍lambda表达式中的运算符,并逐步回答相关问题。
首先,我们需要了解lambda表达式的基本结构。
一个lambda表达式由关键字lambda、参数列表、冒号和函数体组成,它的一般形式为:lambda 参数列表: 函数体。
lambda表达式可以定义匿名函数,它们不需要通过def关键字定义,也不需要给函数命名,因此更加简洁和直观。
[lambda表达式的运算符]:1. 算术运算符:- 加法:+- 减法:-- 乘法:*- 除法:/- 取模:- 幂运算:这些算术运算符在lambda表达式中的使用与普通的函数定义一致,可以进行加、减、乘、除、取模和幂运算等基本计算操作。
下面我们将通过示例来展示它们的用法。
示例1:lambda表达式中使用加法运算符pythonadd = lambda x, y: x + yprint(add(2, 3)) 输出5示例2:lambda表达式中使用除法运算符pythondivide = lambda x, y: x / yprint(divide(10, 2)) 输出5.0示例3:lambda表达式中使用取模运算符pythonmod = lambda x, y: x yprint(mod(10, 3)) 输出12. 比较运算符:- 相等:==- 不等:!=- 大于:>- 小于:<- 大于等于:>=- 小于等于:<=比较运算符常用于条件判断,用于比较两个值的大小或相等性,并返回相应的布尔值。
在lambda表达式中,我们可以使用这些比较运算符进行条件判断,根据比较结果返回不同的值。
下面是一些示例:示例4:lambda表达式中使用相等运算符pythonis_equal = lambda x, y: x == yprint(is_equal(2, 2)) 输出Trueprint(is_equal(2, 3)) 输出False示例5:lambda表达式中使用不等运算符pythonnot_equal = lambda x, y: x != yprint(not_equal(2, 2)) 输出Falseprint(not_equal(2, 3)) 输出True示例6:lambda表达式中使用大于等于运算符pythongreater_than_equal = lambda x, y: x >= yprint(greater_than_equal(2, 2)) 输出Trueprint(greater_than_equal(2, 3)) 输出False3. 逻辑运算符:- 与:and- 或:or- 非:not逻辑运算符用于进行逻辑运算,根据条件的真假返回相应的布尔值。
python里lambda表达式用法摘要:mbda 表达式的定义与特点mbda 表达式的语法mbda 表达式的使用场景mbda 表达式与函数的比较mbda 表达式的优缺点正文:mbda 表达式的定义与特点在Python 编程语言中,Lambda 表达式是一种简洁的、能够定义在一行代码内的匿名函数。
Lambda 表达式主要用于需要一个小型函数的场景,例如对列表进行排序或过滤等。
Lambda 表达式的特点是:定义简单、使用方便、功能强大。
mbda 表达式的语法Lambda 表达式的基本语法为:lambda arguments: expression。
其中,arguments 表示传入的参数,expression 表示执行的操作。
例如,定义一个计算平方的Lambda 表达式可以写作:lambda x: x**2。
mbda 表达式的使用场景Lambda 表达式可以用于各种需要函数的场景,例如:- 排序:使用sorted() 函数对列表进行排序时,可以提供一个Lambda 表达式作为键函数。
例如,对一个列表中的元组按第二个元素进行排序可以写作:sorted(data, key=lambda x: x[1])。
- 过滤:使用list() 函数对列表进行过滤时,可以提供一个Lambda 表达式作为条件。
例如,筛选出一个列表中的偶数可以写作:list(filter(lambda x: x % 2 == 0, numbers)))。
- 映射:使用map() 函数对列表进行映射时,可以提供一个Lambda 表达式作为变换函数。
例如,将一个列表中的每个元素平方可以写作:list(map(lambda x: x**2, numbers))。
mbda 表达式与函数的比较Lambda 表达式与普通函数在某些方面有相似之处,但也存在一些不同。
与普通函数相比,Lambda 表达式更简洁、定义更简单,但它的功能有限,只能包含一个表达式,且不能有复杂的逻辑控制结构。
lambda表达式分类汇总-回复什么是lambda表达式?Lambda表达式是一种匿名函数的表示方式,在许多编程语言中都有使用。
它可以简洁地表示一个函数,通常用于函数式编程和一些需要使用函数作为参数的场景中。
在Python中,lambda表达式提供了一种简洁的方式来定义匿名函数,使得代码更为简洁和易读。
lambda表达式的语法格式如下:lambda arguments: expression其中,`arguments`是函数的参数列表,可以有多个参数,用逗号隔开。
`expression`是一个表达式,用于定义函数的返回值。
lambda表达式整体上可以看作是一个函数对象,可以将其赋值给一个变量,也可以直接调用它。
在Python中,lambda表达式主要应用于以下几个场景:1. 函数作为参数:lambda表达式常常用于函数的参数中,可以避免定义单独的函数,使代码更为简洁。
例如,在使用内置函数`map()`时,可以使用lambda表达式来定义需要对每个元素进行的操作。
pythonnumbers = [1, 2, 3, 4, 5]squared_numbers = list(map(lambda x: x2, numbers))print(squared_numbers) # 输出[1, 4, 9, 16, 25]2. 函数作为返回值:lambda表达式也可以作为函数的返回值,提供了一种在程序运行时动态生成函数的方式。
这在一些需要根据不同条件生成不同函数的场景中非常有用。
pythondef get_operation(operator):if operator == '+':return lambda x, y: x + yelif operator == '-':return lambda x, y: x - yadd_function = get_operation('+')print(add_function(1, 2)) # 输出3subtract_function = get_operation('-')print(subtract_function(5, 3)) # 输出23. 简化代码:lambda表达式可以帮助简化代码,特别是对于一些简单的函数。
一、什么是lambda表达式1.1 定义在编程中,lambda表达式是一种匿名函数,也称为lambda函数。
它是一种构建函数的简便方式, 可以用于定义短小的,一次性的函数。
1.2 语法lambda表达式的一般语法为:lambda 参数列表: 表达式二、lambda表达式的基本用法2.1 作为函数参数lambda表达式可以直接作为函数的参数使用,这样可以避免定义一个单独的函数。
2.2 作为返回值同样,lambda表达式也可以作为另一个函数的返回值,这样可以动态生成函数。
三、lambda表达式在条件写法中的应用3.1 基本语法lambda表达式可以结合条件语句,实现特定条件下的函数操作。
3.2 语法示例lambda表达式加条件写法的一般形式为:lambda 参数列表: 条件表达式1 if 条件1 else 条件表达式2四、lambda表达式加条件写法的实际应用4.1 筛选操作在对列表、元组等数据进行筛选时,lambda表达式加条件写法可以简化代码逻辑。
4.2 数据转换lambda表达式加条件写法还可以用于进行数据的动态转换,根据不同条件返回不同的结果。
4.3 排序操作lambda表达式加条件写法同样可以应用于对数据进行排序,根据不同条件实现动态排序。
五、实例演示5.1 筛选操作实例以对一个列表进行筛选操作为例,展示lambda表达式加条件写法的具体应用。
5.2 数据转换实例以对一个包含数字的列表进行动态转换为例,展示lambda表达式加条件写法的具体应用。
5.3 排序操作实例以对一个列表进行动态排序为例,展示lambda表达式加条件写法的具体应用。
六、总结lambda表达式加条件写法是一种简洁而灵活的函数定义方式,可以方便地实现特定条件下的函数操作,适用于筛选、转换、排序等各种场景。
通过实例演示,我们可以更加直观地理解lambda表达式加条件写法的实际应用,并且在日常编程中灵活运用,提高代码的简洁性和可读性。
2024年9月青少年软件编程Python等级考试四级真题(含答案)一、单选题(共25题,共50分)。
1.一款经典的猜数字游戏:甲先在50以内随意写一个数字,乙开始猜,如果乙猜的比甲写的数大了,甲就说大了,反之,则说小了。
请问根据对分查找思想,乙最多用多少次能猜出甲写的正确数字?()。
A. 10B. 8C. 6D. 4标准答案:C。
2.二分查找法是利用了哪种算法思想?()。
A. 动态规划B. 分治算法C. 递推算法D. 递归算法标准答案:B。
3.运行下列程序后,输出的结果是?()。
def f(n):if(n==1):return 1return n*f(n-1)print(f(5))A. 24B. 120C. 15D. 5标准答案:B。
4.下列定义计算圆周长的匿名函数中,正确的是?()。
标准答案:D。
5.有如下程序段,在调用函数sjc时实参是?()。
def sjc(x):a,b=1,1print(a,b,x)sjc(20)A. 20B. 1C. aD. b标准答案:A。
6.下列有关匿名函数lambda的描述,错误的是?()。
A. lambda表达式可以包含一个表达式B. 在匿名函数中需要使用return来返回值C. lambda表达式可以调用其他函数D. 定义匿名函数时,要将它赋值给一个变量。
标准答案:B。
7.下列程序,运行的结果是?()。
def qh(a,b,c=5):return a+b+cprint(qh(5,10),qh(10,10,10))A. 15 25B. 20 25C. 20 30D. 15 30标准答案:C。
8.有如下程序段,执行该程序段后的结果是?()。
标准答案:A。
9.题fun函数可以传入的参数a不确定有多少个,划线处的代码正确的是?()。
def fun(___):passA. aB. a[]C. a()D. *a标准答案:D。
10.请选择下面代码的输出结果是?()。
def f(n):n += 1return nx = 10y = f(x)print(y)A. 10B. 11C. 12D. None标准答案:B。
lamda准则
Lambda 准则是一种常用于分类问题中的准则,特别是在决策树分类器中。
Lambda 准则的主要思想是:在任何节点分裂时,应尽可能使分裂后的信息增益最小。
Lambda 准则定义如下:设D 是样本集,G 是Gini 指数,则节点的λ 值为λ = 1 - Gini(D),其中Gini(D) 是样本集D 的Gini 指数。
当样本集D 中所有样本都属于同一类别时,Gini(D) 最小,为0;当样本集D 中两个类别的样本数量相等时,Gini(D) 最大,为0.5。
因此,λ 的值域为[0,1]。
Lambda 准则选择分裂信息最大的属性作为最优划分属性,即选取能使分裂后的Gini 值最小(即λ 值最大)的属性作为划分属性。
这样做的目的是为了提高分类的准确性。
需要注意的是,Lambda 准则仅适用于分类问题,并且是在决策树算法中使用的。
在其他机器学习算法中,可能会有其他的准则和优化方法。
pythonlambda排序用法Python中的lambda函数是一种匿名函数,其语法简洁,使用方便。
在进行排序时,lambda函数可以用来定义排序规则。
本文将详细介绍Python中lambda函数的排序用法。
一、 lambda函数的基本语法在Python中,使用lambda关键字来定义一个匿名函数。
其基本语法如下:```lambda arguments: expression```其中,arguments表示传入的参数,可以有多个参数,也可以没有参数;expression表示该函数要执行的操作。
例如:```f = lambda x, y : x + yprint(f(1, 2)) # 输出3```二、使用lambda函数进行排序在Python中,内置了许多排序方法,例如sort()和sorted()等方法。
这些方法都可以接受一个key参数,用来指定排序规则。
1. sort()方法sort()方法是列表对象的一个方法,在原地对列表进行排序。
其语法如下:```list.sort(key=None, reverse=False)```其中,key参数用来指定排序规则,默认为None;reverse参数用来指定是否逆序,默认为False。
使用lambda函数作为key参数时,需要注意以下几点:- lambda函数必须返回一个值;- lambda函数可以有多个参数;- lambda函数的返回值类型必须与待排序对象中元素类型相同。
例如:```a = [('apple', 3), ('banana', 2), ('orange', 4)]a.sort(key=lambda x: x[1])print(a) # 输出[('banana', 2), ('apple', 3), ('orange', 4)]```2. sorted()函数sorted()函数是Python内置的一个函数,可以对任意可迭代对象进行排序。
lambda实现原理Lambda 表达式实现什么是 Lambda 表达式Lambda 表达式是一种匿名函数,即没有函数名的函数。
它允许我们以更简洁的方式编写代码,并提供了一种模块化和简化代码的方式。
为什么使用 Lambda 表达式Lambda 表达式在代码中具有很多好处,包括:•代码更简练:相比于传统的函数定义,使用 Lambda 表达式可以减少代码量。
•代码更易读:Lambda 表达式可以更清晰地表达代码的意图,使代码更易于理解。
•代码更灵活:可以将 Lambda 表达式作为参数传递给其他函数,使代码更具可复用性和可扩展性。
Lambda 表达式的语法Lambda 表达式的语法如下所示:(parameter1, parameter2, ...) => expression其中,parameter1, parameter2, ...是函数的参数列表,expression是函数体。
Lambda 表达式的实现Lambda 表达式的实现涉及到两个重要的概念:函数式接口和函数引用。
函数式接口函数式接口是指只包含一个抽象方法的接口。
在 Lambda 表达式的实现中,我们需要使用函数式接口来指定 Lambda 表达式的类型。
Java 提供了一些常用的函数式接口,如Runnable、Consumer、Supplier等。
我们也可以自定义函数式接口来满足特定需求。
函数引用函数引用是指在 Lambda 表达式中调用一个已经存在的方法。
通过函数引用,我们可以避免重复实现一些已有的逻辑。
Java 中有四种函数引用的方式:•静态方法引用:ClassName::staticMethodName•实例方法引用:instance::methodName•类的任意对象方法引用:ClassName::methodName•构造方法引用:ClassName::newLambda 表达式的用法Lambda 表达式在不同的场景下具有不同的用法。
lambda方法的基本原理
Lambda方法是C++11标准中新增的语法糖,也称为lambda表达式或匿名函数。
Lambda方法具有距离近、简洁、高效和功能强大的特点。
Lambda表达式的语法如下:参数列表、参数列表是可选的,类似于普通函数的参数列表,如果没有参数列表,括号可以省略不写。
Lambda函数不能有默认参数,所有参数必须有参数名,且不支持可变参数。
Lambda函数可以用后置的方法书写返回类型,类似于普通函数的返回类型,如果不写返回类型,编译器会根据函数体中的代码推断出来。
Lambda表达式的原理是,它会被编译生成为当前类的一个私有方法。
Lambda表达式内直接引用局部变量本质是一种隐式传参,编译时会自动将引用的局部变量放到参数列表中(Lambda方法多了个参数),而引用的实例变量并不需要放到参数列表,因为方法内可以直接引用。
造成直接引用的局部变量需要final修饰的原因应该和这种隐式传参有关。
以上内容仅供参考,建议查阅C++书籍或咨询编程专家,以获取更准确的信息。
lambda表达式实现原理Lambda表达式实现原理什么是Lambda表达式?Lambda表达式是一种简洁的匿名函数表示方法,它可以被当作一个变量使用,具有函数体、参数和返回值。
在函数式编程中,Lambda 表达式常常用于简化代码,增加可读性和代码的精简度。
Lambda表达式的语法结构Lambda表达式的语法结构如下:(parameters) -> expression其中,parameters为参数列表,expression为函数体表达式。
Lambda表达式可以有零个或多个参数,参数之间用逗号隔开。
Lambda表达式的实质Lambda表达式实际上是一个对象,它是一个函数式接口的实例。
所谓函数式接口,就是只包含一个抽象方法的接口。
Lambda表达式可以被转化为函数式接口的实例,进而可以赋值给一个该接口类型的变量。
Lambda表达式本质上是通过接口的实现类来实现的。
Lambda表达式的工作原理Lambda表达式背后的实现原理可以分为以下步骤:1.解析Lambda表达式结构:根据Lambda表达式的外观,解析出参数和函数体等结构。
2.创建函数式接口的实例:根据Lambda表达式的结构,创建一个匿名类的实例,该实例实现了函数式接口。
3.调用接口的方法:通过创建的实例,调用函数式接口中的抽象方法,执行Lambda表达式的函数体。
Lambda表达式的解析和创建过程是在编译阶段进行的,而实际执行则是在运行阶段。
Lambda表达式的优点•减少了代码的冗余:Lambda表达式可以大大减少代码的长度,增加了代码的可读性和简洁度。
•便于并行处理:Lambda表达式可以方便地实现并行处理,提升程序的性能。
•更好地支持函数式编程:Lambda表达式是函数式编程的重要特性,在某些场景下可以更方便地使用函数式编程的思想。
总结本文介绍了Lambda表达式的实现原理及其优点。
Lambda表达式是一种简洁的匿名函数表示方法,其实质是一个函数式接口的实例。
To appear in Theoretical Computer Science.Order-Incompleteness and Finite Lambda Reduction ModelsPeter SelingerAbstractMany familiar models of the untyped lambda calculus are constructed by order theoretic methods.This paper pro-vides some basic new facts about ordered models of the lambda calculus.We show that in any partially ordered modelthat is complete for the theory of-or-conversion,the partial order is trivial on term denotations.Equivalently,theopen and closed term algebras of the untyped lambda calculus cannot be non-trivially partially ordered.Our secondresult is a syntactical characterization,in terms of so-called generalized Mal’cev operators,of those lambda theorieswhich cannot be induced by any non-trivially partially ordered model.We also consider a notion offinite models forthe untyped lambda calculus,or more precisely,finite models of reduction.We demonstrate how such models can beused as practical tools for givingfinitary proofs of term inequalities.1IntroductionPerhaps the most important contribution in the area of mathematical programming semantics was the discovery,by D.Scott in the late1960’s,that models for the untyped lambda calculus could be obtained by a combination of order-theoretic and topological methods.A long tradition of research in domain theory ensued,and Scott’s methods havebeen successfully applied to many aspects of programming semantics.On the other hand,there are results that indicate that Scott’s methods may not in general be complete:Honsell andRonchi Della Rocca[8]have shown that there exists a lambda theory that does not arise as the theory of a reflexive model in the cartesian-closed category of complete partial orders and Scott-continuous functions.Moreover,there aredesirable properties of a model that are incompatible with the presence of a partial order:for instance,Plotkin[13],answering a question of H.Friedman,has recently shown that there exists an extensional lambda algebra which is finitely separable.Afinitely separable algebra can never be non-trivially partially ordered.In this paper we establish some basic new facts about ordered models of the untyped lambda calculus.We showthat the standard open and closed term algebras are unorderable,i.e.,they cannot be non-trivially partially ordered as combinatory algebras.Recall that the standard term algebras are made up from lambda terms,taken up to-or -equivalence.It follows that if a partially ordered model of the untyped lambda calculus is complete for one of the theories,then the denotations of closed terms in that model are pairwise incomparable,i.e.,the termdenotations form an anti-chain.We also consider the related question of order-incompleteness:does there exist a lambda theory(possibly with constants)which does not arise as the theory of a non-trivially ordered model?Equivalently,does there exist a lambda algebra which cannot be embedded in a non-trivially ordered model?Let us call such an algebra absolutely unorder-able.Plotkin conjectures in[13]that an absolutely unorderable lambda algebra exists.Here,we give an algebraic characterization,in terms of so-called Mal’cev operators,of the absolutely unorderable-algebras in any algebraic variety.This reduces the question of order-incompleteness for the lambda calculus to the question whether one can consistently add a family of Mal’cev operators to the lambda calculus.The answer is still unknown in the general case,but we prove that it is inconsistent for.The characterization of absolutely unorderable-algebras in terms of Mal’cev operators leads to an interesting technical observation about free order-algebras and dcpo-algebras.In a given variety of order-algebras,one may consider the free order-algebra ord generated by a poset.The question arises under what conditions ord is conservative over,i.e.,under what conditions the canonical map ord is order-reflecting.An analogous1question can be asked for dcpo-algebras.Here,we give a necessary and sufficient condition:we show that the answeris completely determined by whether the given variety has a family of Mal’cev operators.In the last part of this paper,we introduce a novel technique for proving inequalities of lambda terms.At the heart of this technique is the notion of afinite lambda reduction model.It is well-known that a model of an equationaltheory of the lambda calculus can never befinite or even recursive[2].Instead,we consider models of reduction, which are not subject to the same limitations on size and complexity.A model of reduction is equipped with a partial order,and it satisfies a soundness property of the form,where denotes e.g.-or-reduction[6,10,12].One can understand such models as making precise certain invariants of terms under reduction. By combining this with the Church-Rosser property,one recovers a limited form of reasoning about convertibility.Our key observation is that models of reduction,unlike models of conversion,may befinite,and that even afinite such model can carry non-trivial information.We give a practical method for constructing such models,and we give two examples in which we usefinite reduction models to demonstrate the inequality of some unsolvable lambda terms.2UnorderabilityThe main result of this section is that the open and closed term algebras of the untyped lambda calculus do not admit anon-trivial partial order compatible with the model structure.We follow Barendregt’s notation for the lambda calculus [2].Let us begin byfixing some terminology.A preorder is said to be discrete if implies,indiscreteif holds for all,and symmetric if.By a trivial preorder,we mean either the discrete or indiscrete preorder.A partial order is of course trivial iff it is discrete iff it is symmetric.Recall that a combinatory algebra consists of a set,a binary operation,anddistinguished elements satisfying and.As usual,we write for and for .We say that a preorder on a combinatory algebra is compatible if application is monotone in both arguments,i.e.,and implies.A combinatory algebra is called unorderable if every compatible partial order on it is trivial.It is known that such algebras exist.For example,Plotkin[13]has recently constructed afinitely separable algebra,a property which implies unorderability.Here is said to befinitely separable if for everyfinite subset,every function is the restriction of some,meaning that for all,.Finitely separable combinatory algebras do not allow non-trivial preorders,because if for some,then for all via some with and.The present result differs from this,because our unorderable algebras,the open and closed term algebras of the untyped lambda calculus,occur“naturally”.2.1Lambda terms cannot be orderedLet be the set of(-equivalence classes of)untyped lambda terms,build from a set of constant symbols and a countable supply of variables.Let be the subset of closed terms.Definition.The open term algebra of the-calculus is the combinatory algebra,where is the application operation on terms,and and are the terms and,respectively.The closed term algebra is defined analogously,and similarly for the-calculus.Note that these term algebras are notfinitely separable:e.g.the terms and cannot be separated,since thefirst one is unsolvable[2].Also,the term algebras allow non-trivial pre orders:for instance, two terms are ordered if and only if their meanings in the standard-model are ordered.Suppose now that we want to construct a partial order on,say,the open term algebra of the-calculus.An obvious approach is the following:take two distinct variables and,and let be the preorder generated by a single inequation.It is not hard to see that for this preorder,one has iff is obtained from up to-equivalence by replacing some,but not necessarily all occurrences of the variable by.More precisely,iff there is a term(not itself containing or)such that and.It follows that,and thus this preorder is non-trivial.However,the following proposition implies that is not a partial order.2Proposition2.1.There exists a closed term of the untyped lambda calculus,such that,but ,for variables.Proof.The idea of the proof is as follows:Via afixpoint combinator,define a term such thatfor variables.In other words,any three applications of are equivalent to a single application.Now let.Then clearly.It remains to be shown that.We delay the proof of this inequality until Section4.4.2below,where we prove it using the notion offinite lambda reduction models.Note that the proposition implies that is not a partial ly,one has,but since,the preorder is not antisymmetric.By the same reasoning,and cannot be related in any compatible partial order on open terms.Thus any such partial order is discrete on variables.To show this section’s main result,we need to lift this reasoning from variables to arbitrary terms.This is achieved by the following lemma,which states that,if is a fresh variable,then and behave essentially like indeterminates:any equation that holds for and will hold for variables and .Let be one of the theories,and let be the corresponding reduction relation.Lemma2.2.Let be terms that are distinct in,and let be a variable not free in.Then for all terms with FV,and for variables,impliesProof.Let FV.In the following,we assume without loss of generality that the names of all bound variables are different from elements of.Let be the set of all lambda terms with the following property:the variable occurs only in subterms of the form,where for some.For each,let be the lambda term obtained from by replacing each subterm of the form by if.Formally ,,,if,and if.Then the following hold:(a)For all and,and.(b)For all,if then and.(c)For all,if then.(a)and(b)are easily proved by induction.(c)follows from(b)by the Church-Rosser property of.Finally, the lemma follows by observing that and are in,and and.Theorem2.3.Let be the open or the closed term algebra of the-or-calculus.Then does not allow a non-trivial compatible partial order.Proof.Let be a compatible partial order on.Let,and assume,by way of contradiction,that .Let be as in Proposition2.1,and let be a fresh variable.Then by compatibility,hence,by antisymmetry,Applying Lemma2.2to and,one gets for variables and, contradicting the choice of.Consequently,the order is trivial.Corollary2.4.In any partially ordered model of the untyped lambda calculus whose theory is,the deno-tations of closed terms are pairwise incomparable.32.2Lambda unorderabilityWe have called a preorder on a combinatory algebra compatible if it respects the application operation.In addition,one can require that also respects abstraction.Abstraction is a well-defined operation if is a lambda algebra[2,14].Thus,we define a lambda preorder on a lambda algebra to be a compatible preorder such thatmodels:an unorderable model can still arise from an order-theoretic construction,for instance as a subalgebra of some orderable model.Indeed,it is not hard to see that the open and closed term algebras,as considered in the previous section,can be embedded in an orderable model:this follows e.g.from Theorem3.4below.A different(and,from a model-theoretic point of view,more interesting)construction of an ordered model in which the open term algebra is embedded can be found in Di Gianantonio et al.[5].This leads us to the related question of absolute unorderability:a model is absolutely unorderable if it cannot be embedded in an orderable one.Plotkin conjectures in[13]that an absolutely unorderable combinatory algebra exists,but the question is still open whether this is so.In this section,we present what is known:we give a syntactic characterization of the absolutely unorderable algebras in any algebraic variety in terms of the existence of a family of Mal’cev operators.Plotkin’s conjecture is thus reduced to the question whether Mal’cev operators are consistent with the lambda calculus.The question of absolute unorderability can also be formulated in terms of theories,rather than models.In this form,we refer to it as the order-incompleteness question:does there exist a lambda theory(possibly with constants) which does not arise as the theory of an ordered model?This question is obviously equivalent to the question of the existence of an absolutely unorderable algebra.A property that is related to order-incompleteness,but much weaker,is the well-known topological incompleteness. Addressing the latter,Honsell and Ronchi Della Rocca[8]have shown that there is a lambda theory which is not the theory of any reflexive CPO-model.However,their theory is not order-incomplete,and the methods used in investigating topological incompleteness are quite different from those used here.We should mention that the question whether arises as the theory of a reflexive CPO-model is still open.3.1A characterization of absolutely unorderable algebrasLet be an algebraic variety(given by a signature and equations).We say that a preorder on a-algebra is compatible if for implies,for each-ary function symbol in the signature of.Notice that compatible preorders are closed under arbitrary intersections.If is compatible,then so is the dual preorder.Every compatible preorder determines a congruence on,which is the intersection of and.Also notice that naturally defines a partial order on.A-algebra is said to be unorderable if it does not allow a non-trivial compatible partial order.Also,is said to be absolutely unorderable if for any embedding of-algebras,is unorderable.Now consider a-algebra.As usual,denotes the-algebra obtained from by freely adjoining indeterminates.We regard as a subset of.Let be the smallest compatible preorder on such that.Lemma3.1.is discrete on,i.e.,for.Proof.Let be the kernel of the canonical homomorphism which sends both and to.Then and is discrete on.Lemma3.2.is absolutely unorderable if and only if.Proof.For the left-to-right implication,suppose is absolutely unorderable.Consider the natural map .Lemma3.1implies that the composition is an embedding,hence must be discrete as a partial order on.Equivalently,as a preorder on is symmetric,and thus.For the converse,suppose is not absolutely unorderable.Then there is an embedding of-algebras where has a non-trivial compatible partial order.Choose such that,and consider the unique map such that,and.Define in iff in.Then is a compatible preorder on with,hence is contained in.But,hence.Further,has the following explicit description:On,define if and only if there is a polynomial such that and.Lemma3.3.is the transitive closure of.5Proof.Let be the transitive closure.Clearly,is a preorder contained in,and it satisfies.Moreover,, and thus,is compatible,as can be seen by considering terms of the formfor each-ary function symbol.Since is smallest with these properties,it follows that.Putting together Lemmas3.2and3.3,we get the following characterization of absolutely unorderable algebras. We say that an equation holds absolutely in if it holds in.Theorem3.4.Characterization of absolutely unorderable-algebras.Let be an algebraic variety.A-algebra is absolutely unorderable if and only if,for some,there exist polynomials M, for,such that the following equations hold absolutely in:MM MM M(2)...MProof.By Lemmas3.2and3.3,is absolutely unorderable if and only if there are such that .The theorem follows by definition of.In the case,the equations(2)have the simple form M and M.A ternary operator M satisfying these equations is called a Mal’cev operator,after A.I.Mal’cev,who studied such operators to characterize varieties of congruence-permutable algebras[11].Accordingly,we call M M satisfying(2)a family of gen-eralized Mal’cev operators,and we call the equations(2)the generalized Mal’cev axioms.Hagemann and Mitschke [7]have shown that an algebraic variety has-permutable congruences if and only if it has a family of generalized Mal’cev operators.It was proved by W.Taylor[15,4]that algebras in a variety with-permutable congruences are unorderable;however,the converse is a new result.Also note that Theorem3.4characterizes individual algebras that are absolutely unorderable,rather than varieties of unorderable algebras.3.2An application to order-algebras and dcpo-algebrasA compatibly partially ordered algebra over a given signature is called an-order-algebra.Moreover,it is called a-dcpo-algebra if the order is directed complete and the algebra operations are continuous.Let be a set of inequations between terms in the language of.A-order-algebra satisfying these inequations is called a -order-algebra,and similarly for dcpo-algebras.For more details,see[1]or[14].Fix and.For any poset,there exists a free-order-algebra ord,with a canonical monotone mapord.Similarly,for any dcpo,there exists a free-dcpo-algebra dcpo with a canonical continuous map dcpo[1].One may ask under which circumstances the canonical map is order-reflecting,i.e.,under what conditions the free order-or dcpo-algebra conservatively extends the order on the generators.The following theorem shows that the answer depends only on the presence of generalized Mal’cev operators in.Recall that a-ary operation in is simply a term in the signature.Theorem3.5.Let be a signature and a set of inequations.Let be a non-trivially ordered dcpo,and let be a non-trivially ordered poset.The following are equivalent:1.The canonical map dcpo from into the free-dcpo-algebra is not order-reflecting.2.Every-dcpo-algebra is trivially ordered.3.The canonical map dcpo from into the free-order-algebra is not order-reflecting.4.Every-order-algebra is trivially ordered.65.There are ternary operations M M in such that entailsMM MM M(3)...MProof.1. 2.:Suppose is a non-trivially ordered-dcpo-algebra with elements.We show that is order-reflecting.Let with.Define byififThen is continuous;therefore,by the universal property of dcpo,there exists a unique continuous homomorphismdcpo such that.By monotonicity of,we get,hence .2. 1.:A map dcpo from a non-trivially ordered set into a trivially ordered one cannot be order-reflecting.3. 4.:Same as1. 2.,replacing the word“continuous”by“monotone”.2. 4.:Suppose there is a non-trivially ordered-order-algebra.We consider the ideal completion of:A subset is an ideal if it is downward closed and directed.Let Idl be the ideal completion of,i.e.,the set of all ideals,ordered by inclusion.Abramsky and Jung[1]prove that Idl is a-dcpo-algebra.Moreover,the map Idl is order preserving and reflecting,and hence Idl is non-trivially ordered.4. 5.:Let be a countable set of variables,and let ord be the free-order-algebra over discrete.If every-order-algebra is trivially ordered,then so is ord,which implies that ineq iff ineq.We can therefore regard as a set of equations.The claim follows by applying Theorem3.4to ord.5. 2.:Suppose has operators satisfying(3).Then for any-dcpo-algebra,if,thenM M M,hence is trivially ordered.Remark.Notice that the implication5. 4.shows that the inequalities(3)already imply the corresponding equalities (2).3.3Absolute unorderability and the lambda calculusIn the lambda calculus,a term M can be expressed in curried form as M.Plotkin posed the question whether an absolutely unorderable lambda algebra exists[13].Clearly,this is the case if and only if,for some,the equations(2)are consistent with the lambda calculus.Unfortunately,it is not known whether this is true except in the cases and.In these cases,(2)is inconsistent with the lambda calculus,as we will now show.Notice that if the axioms are consistent for some,then also for all,by letting M MLet be anyfixpoint operator of combinatory logic,for instance the paradoxicalfixpoint combinator.We write for.The operator satisfies thefixpoint property:(fix)The diagonal axiom isLemma3.6(Plotkin,Simpson).Assuming the diagonal axiom,the generalized Mal’cev axioms(2)are inconsistent with the lambda calculus for all.7Proof.Let be arbitrary.ThenM by(2)M byM by(fix)M by(2)Mby(2).Hence for all,which is an inconsistency.Theorem3.7(Plotkin,Simpson).For,the Mal’cev axioms are inconsistent with the lambda calculus. Proof.Suppose M is a Mal’cev operator.Let be arbitrary and let M.Then(fix)M(fix)Mhence M M.Theorem3.8(Plotkin,Selinger).For,the generalized Mal’cev axioms are inconsistent with the lambda calculus.Proof.Suppose M and M are operators satisfying the generalized Mal’cev axioms(2).Define and by mutual recursion such thatM MM MThenM M by(fix)M M by(2)by(fix).So M M M M,which is the diagonal axiom.By Lemma3.6,this leads to an inconsistency.4Finite Lambda Reduction ModelsIt is well-known that a model of the untyped lambda calculus,in the traditional equational sense,can never befinite or even recursive[2].Consequently,model constructions of the lambda calculus typically involve passing to an infinite limit,yielding unwieldy models in which term denotations or equality of terms are not effectively computable.By contrast,if one considers models of reduction,rather than of conversion,there is no such limitation on size or complexity.As we will see,it is quite possible for a model of reduction to befinite and yet rmally,by a model of conversion,we mean a model with a soundness property of the formwhere is e.g.-or-convertibility,and is the semantic interpretation function.On the other hand,a model of reduction has an underlying partial order and a soundness property of the formwhere is e.g.-or-reduction.Models of reduction have been considered by different authors[6,10,12].We will focus here on a formulation which was given by Plotkin[12]in the spirit of the familiar syntactical lambda models [2].84.1Syntactical models of reductionAs before,let be the set of variables of the lambda calculus,and let be the set of untyped lambda terms up to -equivalence.To keep the notation simple,we do not consider constant symbols in this section,although they could be easily added.For a partially ordered set,let be the set of all valuations,i.e.,functions from to.Definition.(Plotkin[12])A syntactical model of-reduction consists of a poset,a monotone binary operation,and an interpretation functionsuch that the following properties are satisfied:1.2.3.,for all4.FV FV5.Moreover,we say is a syntactical model of-reduction,if it also satisfies the property6.,if FV.The usual syntactical lambda models(of conversion)[2]arise as the special case where is discretely ordered.Note that properties1.–3.do not form an inductive definition of the function.In general,is not uniquely determined by.Notice that the partial order on a model of reduction differs from the partial order on a model of conversion,as considered in thefirst part of this paper.The order on an ordered model of conversion is commonly understood as an information order,where means that is“less defined”than.On the other hand,models of reduction have a reduction order,where means reduces to.One has the following soundness properties:Proposition4.1(Plotkin[12]).The following are properties of syntactical models of-reduction:1.Monotonicity.If for all,then.2.Substitution..3.Soundness for reduction.If,then.In a syntactical model of-reduction:If,then.The soundness property for reduction does not in general yield useful information about convertibility,since in-terconvertible terms may have different denotations.However,if the reduction relation satisfies the Church-Rosser property,as is the case for-and-reduction,then implies that and for some term.Thus,in a model of-or-reduction,we get the following,restricted form of soundness for convertibility. Recall that two elements and in a poset are called compatible,in symbols,if there exists with and .(4)This property can be useful for reasoning about non-equality of terms,particularly if the underlying poset has many pairs of incompatible elements.For this reason,we will be especially interested in the cases where is aflat partial order,or a tree,or more generally,a bounded complete domain.Recall that a bounded complete domain is a non-empty poset in which all bounded subsets and all directed subsets have a least upper bound.Note that any bounded complete domain has a least element.94.2Constructing models of-reductionSyntactical models of-reduction are constructed much more easily than models of conversion.To start with a trivial example,take any pointed poset and monotone function,and define,somewhat uningeniously, .Among the possible interpretation functions for given and,this choice is the minimal one.Much more interesting is the situation in which there exists a maximal choice for.Note that,in light of the soundness property for convertibility(4),it is desirable for to be as large as possible,so as to discriminate more terms.We will now explore a sufficient condition for a maximal to exist,in the case where is a bounded complete domain.Definition.A monotone function is compatible-extensional if for all,The construction in Proposition4.2yields a model of-reduction if is order-extensional.More generally: Lemma4.4.If is a syntactical model of-reduction and is order-extensional,then is a model of-reduction.10Table1:Multiplication table for aflat model.. ................Proof.Suppose FV.Then for all,,hence .We note that in the special case where is a tree,order-extensionality is a consequence of compatible-extensionality and extensionality:Lemma4.5.If is a tree,and if is compatible-extensional and extensional,then it is also order-extensional. Proof.Suppose for all,,hence,hence by compatible-extensionality.Since is a tree,either or.In thefirst case,we are done;in the second case,,and hence,for all,which implies by extensionality.4.4Examples:twoflat modelsIn the following examples,we consider models where the underlying poset isflat,i.e.,for a discrete set, and where the application operation is strict in both arguments.We call these modelsflat models,and remark that the application operation on such a model is equivalently given by a partial function.If isfinite,the function can be given by a“multiplication table”,and it is easy to read properties such as compatible-extensionality from the defining table.For instance,is compatible-extensional if no two rows of the table are compatible,and it is order-extensional if no row is subsumed by another.In particular,if the table is everywhere defined,then both compatible-extensionality and order-extensionality coincide with(ordinary)extensionality.4.4.1A class offinite models to distinguish the termsLet be a variable and define and for.Let and.None of these terms,for,have a normal form,e.g.reduces only to itself.The terms are unsolvable; therefore,their interpretations coincide with in the-model[9,16].We will now give a class offiniteflat models that distinguishes them.Fix an integer and let,regarded as integers modulo with addition and subtraction. Define byififA“multiplication table”for this operation is shown in Table1.Clearly,the application operation defined in this way is compatible-extensional and order-extensional.Define as in Proposition4.2to get a model of-reduction.For ,we calculate and for.Hence,for all and,11Table2:Values for andHence,for,and we have iff.Thus,each pair of terms,is distinguished in one of these models.Note that the syntactic invariant picked out by these models can also be formulated syntactically,approximately as follows:in a term of the form,pick out the last subterm,and determine the power of in it.In general,the invariants picked out by afinite model can be much more complex.4.4.2Proof of Proposition2.1:A non-trivial3-element modelIn this section,we will apply afinite model of reduction tofinish the proof of Proposition2.1.Recall that we are showing that there exists a closed term of the untyped lambda calculus,such that,but ,for variables.As outlined before,the idea is to let,where is a term such that.Such an can be easily constructed via afixpoint combinator.We define via the paradoxicalfixpoint combinator,which leads to the following concrete term for:,where.Clearly.To see that for variables and,we will construct a3-elementflat model.Let,and let be defined by the following“multiplication table”:。