commutativity

Understanding functor laws: is this a functor?

断了今生、忘了曾经 提交于 2021-02-08 08:48:18
问题 The following code is written in javascript. This question involves an attempt to dive into some category theory, maybe a haskeller or someone more familiar with the mathematical aspects of this question can help me out? I'm trying to wrap my head around the idea that a functor is a mapping between categories that preserves structure. More specifically - according to my understanding - a functor in a programming language is an endofunctor. By this it is meant that functors in programming

Non-commutative sympify (or simplify)

情到浓时终转凉″ 提交于 2021-02-06 09:28:09
问题 I would like to be able to simplify mathematical expressions from a string in Python. There are several "commutative" ways of doing it. Is there a non-commutative function for that? I know that sympify from sympy can do some non-commutative jobs, here you have an example: from sympy import * x=Symbol('x',commutative=False) y=Symbol('y',commutative=False) print sympify(3*x*y - y*x - 2*x*y) it will print x y -y x, however if we apply sympify to the string, that is, print sympify('3*x*y - y*x -

isabelle proving commutativity for add

被刻印的时光 ゝ 提交于 2019-12-23 14:56:11
问题 Im trying to prove commutativity in Isabelle/HOL for a self-defined add function. I managed to prove associativity but I'm stuck on this. The definition of add : fun add :: "nat ⇒ nat ⇒ nat" where "add 0 n = n" | "add (Suc m) n = Suc(add m n)" The proof of associativity: lemma add_Associative: "add(add k m) z = add k (add m z)" apply(induction k) apply(auto) done The proof of commutativity: theorem add_commutativity: "add k m = add m k" apply(induction k) apply(induction m) apply(auto) I get

Babel plugins run order

北城余情 提交于 2019-12-21 07:08:41
问题 TL;DR: Is there a way how to specify the order in which the Babel plugins are supposed to be run? How does Babel determine this order? Is there any spec how this works apart from diving into Babel sources? I'm developing my own Babel plugin. I noticed, that when I run it, my plugin is run before other es2015 plugins. For example having code such as: const a = () => 1 and visitor such as: visitor: { ArrowFunctionExpression(path) { console.log('ArrowFunction') }, FunctionExpression(path) {

Does boost offer make_zip_range?

瘦欲@ 提交于 2019-12-19 10:08:36
问题 At this answer here on SO, there's a comment suggesting a useful C++ construct, similar to make_zip_iterator , but for ranges: It takes a tuple of ranges and produces a new range - whose begin() and end() iterators are the appropriate zip iterators. Now, this should not be too difficult to implement, but I was wondering - Isn't already offered already by Boost somehow? 回答1: Boost.Range is providing combine() function as zip_iterator 's range. http://www.boost.org/doc/libs/1_56_0/libs/range

3 Equals or Case Equality operator

狂风中的少年 提交于 2019-12-17 19:31:46
问题 In Ruby Integer === 5 returns true . Similarly String === "karthik" returns true . However, 5 === Integer returns false . And "karthik" === String . Why is the operator not commutative? 回答1: The simple answer is: because it doesn't make sense. The relationship the operator describes is not commutative, why should the operator be? Just look at your own examples: 5 is an Integer . But is Integer a 5 ? What does that even mean ? === is the case subsumption operator , and subsumption doesn't

Trying to implement commutativity in Prolog

泪湿孤枕 提交于 2019-12-11 15:09:11
问题 I am trying to create a knowledge base. My problem has terminal/1 and connected/2 and I have defined the following rule: connected(X,Y) :- connected(Y,X). For reasons I now understand (I think), this went into an infinite recursion. Then, I tried search SO and found this question: Alternative to express "Commutativity" in Prolog? . Based on the answers provided, I tried to change my above fact to the following: connected(X, Y) :- is_connected(Y, X) /\ is_connected(X, Y). is_connected(X, Y) :-

Make all symbols commutative in a sympy expression

左心房为你撑大大i 提交于 2019-12-11 02:22:50
问题 Say you have a number of non commutative symbols within a sympy expression, something like a, c = sympy.symbols('a c', commutative=False) b = sympy.Symbol('b') expr = a * c + b * c What is the preferred way to make all symbols in the expression commutative, so that, for example, sympy.simplify(allcommutative(expr)) = c * (a + b) ? In this answer it is stated that there is no way to change the commutativity of a symbol after creation without replacing a symbol, but maybe there is an easy way

Native implementation of reduceRight in JavaScript is wrong

半世苍凉 提交于 2019-12-07 21:48:54
问题 For an associative operation f over the elements of array a , the following relation should hold true: a.reduce(f) should be equivalent to a.reduceRight(f) . Indeed, it does hold true for operations that are both associative and commutative. For example: var a = [1,2,3,4,5,6,7,8,9,0]; alert(a.reduce(add) === a.reduceRight(add)); function add(a, b) { return a + b; } However it doesn't hold true for operations that are associative but not commutative. For example: var a = [[1,2],[3,4],[5,6],[7

Alternative to express “Commutativity” in Prolog?

本秂侑毒 提交于 2019-12-06 23:54:00
问题 as a beginner to Prolog, I found the commutative expression in Prolog are quite not intuitive. for example if I want to express X and Y are in one family, like: family(X,Y) :- married(X,Y); relative(X,Y); father_son(X,Y). I should also add the following to the definition, in order to make it "commutative": married(Y,X); relative(Y,X); father_son(Y,X). But we use Prolog, because we want to write elegant code... so, I'd hope to add only one line(instead of the above three) to the original :