অভিব্যক্তি সমতার জন্য একটি কার্যকর অ্যালগরিদম আছে?


14

যেমন ?xy+x+y=x+y(x+1)

অভিব্যক্তিগুলি সাধারণ উচ্চ-বিদ্যুত বীজগণিত থেকে, তবে গাণিতিক সংযোজন এবং গুণ (যেমন ), কোনও বিপরীত, বিয়োগ বা বিভাজন ছাড়া সীমাবদ্ধ । চিঠিগুলি ভেরিয়েবল হয়।2+2=4;2.3=6

যদি এটি সহায়তা করে তবে আমরা বাদে সংখ্যাসূচক মানগুলির সাথে উপস্থাপনযোগ্য কোনও অভিব্যক্তি নিষিদ্ধ করতে পারি1; i.e. not x2 nor 3x nor 4:

  • multilinear, no powers other than 1: x+xyx1+x1y1 is OK, but not x2+x3y4, and not anything that could be represented as that, as in a full expansion to sum-of-products e.g. not x(x+y)x2+y;
  • all one, no coefficients other than 1: x+xy1.x+1.xy is OK, but not 2x+3xy, and not anything that could be represented as that, as in a full expansion to sum-of-products e.g. not a(x+y)+x(a+b)2ax+ay+bx ; and
  • no constants other than 1: again, in the fully expanded sum-of-products e.g. not (a+1)+(b+1)a+b+2

Q. Is there an efficient algorithm to determine if two expressions are equivalent?


To illustrate, here's an inefficient brute-force algorithm with exponential time:

expand both expressions fully to sum-of-products, which can easily be checked for equivalence (just ignore order, since commute/associate can reorder).

e.g.
(a+b)(x+y)ax+ay+bx+by
a(x+y)+b(x+y)ax+ay+bx+by


This seems a well-known problem - even high school students are taught manual ways to solve it. It's also solved by automated theorem provers/checkers, but they concentrate on more sophisticated aspects.

Here's a working online automated theorem prover: http://tryacl2.org/, which shows equivalence by finding a sequence of commute/associate/distribute etc:

xy+x+y=x+y(x+1) ?
(thm (= (+ (* x y) x y) (+ x (* y (+ x 1))) )) --- 188 steps

y+x(y+1)=x+y(x+1) ?
(thm (= (+ y (* x (+ y 1))) (+ x (* y (+ x 1))) )) --- 325 steps

This is my first question here, so please let me know if I've chosen the wrong place, wrong tags, wrong way of describing/asking etc. Thanks!
NB: this question has been rewritten in response to comments
Thanks to all responders! I've learned a lot.


3
The question here needs some clarification. What field are you operating over? Are the objects such as "a" and "b" in your expressions elements of the field or variables? Is it actually a field (i.e., do addition and multiplication have inverses)? Note that sum-of-products doesn't help because (a1+b1)(a2+b2)(an+bn) has exponetially many terms.
David Richerby

4
If the objects are variables, and subtraction is allowed, then you're essentially asking about polynomial identity testing, which has a randomized polynomial time algorithm by the Schwartz–Zippel lemma. f(x)=g(x) iff f(x)g(x)=0 and the basic idea is that a polynomial that isn't identically zero doesn't have many roots so, if you start guessing roots at random and find a lot of roots, there's a high probability that your polynomial was identically zero.
David Richerby

2
I'm surprised nobody mentioned this yet, but "if it is in NP I don't need to worry about finding a polynomial algorithm" doesn't make sense. Every problem in P is also in NP. You probably meant to ask whether the problem is NP-complete (or -hard).
Tom van der Zanden

2
If you struggle with the basics, our reference questions may be helpful to you.
Raphael

2
@hyperpallium Before asking if a language (i.e. a decision problem) is in NP, it's best if you understood what this means. Perhaps the reference questions that Raphael linked to would help.
Yuval Filmus

উত্তর:


9

Your problem reduces to zero testing of multivariate polynomials, for which there are efficient randomized algorithms.

Your expressions are all multivariate polynomials. Apparently, your expressions are built up by the following rules: (a) if x is a variable, then x is an expression; (b) if c is a constant, then c is an expression; (c) if e1,e2 are expressions, then e1+e2 and e1e2 are expressions. If that's indeed what you intended, every expression is a multivariate polynomial over the variables.

Now, you want to know if two expressions are equivalent. This amounts to testing whether two multivariate polynomials are equivalent: given p1(x1,,xn) and p2(x1,,xn), you want to know if these two polynomials are equivalent. You can test this by subtracting them and checking whether the result is identically zero: define

q(x1,,xn)=p1(x1,,xn)p2(x1,,xn).

Now p1,p2 are equivalent if and only if q is the zero polynomial.

Testing whether q is identically zero is the zero testing problem for multivariate polynomials. There are efficient algorithms for that. For instance, one example algorithm is to evaluate q(x1,,xn) at many random values of x1,,xn. If you find a value of x1,,xn such that q(x1,,xn), then you know that q is not identically zero, i.e., p1,p2 are not equivalent. If after many trials they are all zero, then you can conclude that q is identically zero (if q is not identically zero, the probability that all of those trials yield zero can be made exponentially low). The number of iterations you need to do is related to the degree of q; see the literature on polynomial identity testing for details.

For instance, see https://en.wikipedia.org/wiki/Schwartz%E2%80%93Zippel_lemma and http://rjlipton.wordpress.com/2009/11/30/the-curious-history-of-the-schwartz-zippel-lemma/

These algorithms apply if you are working over a finite field. You didn't state what field/ring you are working in, and whether you are are treating these expressions as formal expressions (e.g., polynomials as abstract objects) or as functions from FnF. If you are working over a finite field, the methods above apply immediately.

If you're treating the expressions as formal objects, then your expressions are equivalent to multivariate polynomials with integer coefficients. You can test equivalence of these by choosing a large random prime r and testing equivalence modulo r, i.e., in the field Z/rZ. Repeat this polynomially many times, with different random values of r, and you should get an efficient randomized algorithm for testing equivalence of these formal expressions.


1
On the other hand, it would be hard to prove that for each identically-zero expression, there is a not-too-long proof that the expression is identically zero.

@RickyDemer, great point! Nice observation. I interpreted the question as asking about testing equivalence rather than proving it, but that's a very nice observation. (If you wanted to exhibit a proof of equivalence in practice, I suspect it's feasible to exhibit such a proof if you're willing to make cryptographic assumptions, for some definition of "proof" -- e.g., a scheme that achieves soundness in the random oracle model.)
D.W.

1
Thanks! I'm treating them as formal objects, without inverses, division or subtraction (but using high school algebra for this question; seems more likely to be already solved). Do you mean, keep choosing large random primes r, and this is treating the expressions as if they were finite fields over the underlying set of integers [0..r1]? That wiki link says there's no known sub-exponential deterministic algorithm for this zero-testing. Do you know if that applies to my problem?
hyperpallium

1
@hyperpallium, yes exactly that's what I mean. Yes, I believe that applies to your problem, too. That's why I suggested a randomized algorithm -- there are efficient randomized algorithms, even though there are no known efficient deterministic algorithms.
D.W.

As pointed out in a comment above, the OP is not working in a finite field, but rather a commutative semiring. This means that additive inverses are not guaranteed to exist, so "subtracting" the expressions to check equality with zero is not a valid operation.
apnorton

0

To follow up on the one-power, one-coefficent and one-constants constraints in the question:

These define a subset the problem of polynomial identity testing. Clearly, they can be solved with a technique that solves the general problem. The question is whether they form a subset that is more easily solved.

one-coefficient: in problems without this, terms might be combined, making the problem easier. Consider the Binomial Theorem/Pascal's triangle for (a+b)n. This can be expanded one factor at a time, producing terms with overlapping orders e.g. (a+b)(a+b)=aa+ab+ab+bb=aa+2ab+bb The fewer terms make it easier to expand with the next factor: (aa+2ab+bb)(a+b)=aaa+2aab+abb+aab+2abb+bbb=aaa+3aab+3abb+bbb and again terms are combined, making a smaller simpler problem. This combining of terms is a form of dynamic programming.

That is, the possibility of combining terms, creating a non-one coefficient, makes the problem easier not harder.

(Although there is more work in calculation in multiplying non-one coefficients)

non-one constants are included in the above argument by considering constants as variables with zero exponent.

one-power I don't think this makes any difference. Although non-one exponents can be created in more than one way (e.g. a4=a2a2=a1a3), and this can lead to overlap and combination (as in the Binomial Theorm/Pascal's triangle above), actual combination is only possible if non-one coefficients are allowed.

The above is not a formal or rigorous argument. It rests on an assumption about what makes the problem difficult. But it does seem to me that combining terms only makes for an easier problem - so preventing this by the one coefficient constraint is not going to make the subset easier.

আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.