检查两个数学答案是否相等 [英] Check if two math answers are equivalent

查看:109
本文介绍了检查两个数学答案是否相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python编写一个小应用程序,它可以让用户回答数学问题.我遇到的问题是检查他们的答案.

I'm writing a small app in python which lets users answer math questions. The problem I'm having is checking their answers.

说有一个问题,例如:因素x^2 + 3x +2"

Say there's a question like: "Factorise x^2 + 3x +2"

有不同的回答方法;例如:

There are different ways to answer this; for example:

  • (x +1)(x + 2)
  • (x + 2)(x +1)
  • (2 + x)(x + 1)

有没有一个图书馆可以检查答案是否等同于另一个?特别是不能简化给定答案的一种.所以:

Is there a library which will check if an answer is equivalent to another? Particularly one which doesn't simplify the given answer; so:

(x + 1)(x + 2) === (2 + x)(x + 1)

但是

(x + 1)(x + 2)!== x^2 + 3x +2

我考虑过要使用wolframalpha,这有可能吗?如果可以,应该使用什么语法?

I thought about using wolframalpha for this — would this be possible — and if so what syntax should I use?

谢谢!

推荐答案

您可以尝试使用符号数学库,例如

You could try using a symbolic math library like sympy.

在答案和答案上均调用简化逻辑.由用户提供的一种.在两个逻辑上都运行逻辑解决了文档中提到的此问题:

Call the simplify logic on both your answer and the one supplied by the user. Running the logic on both addresses this issue noted in the documentation:

此功能尝试的确切策略可以在将来的版本中更改 的SymPy

exact strategies this function tries can change in the future versions of SymPy

这篇关于检查两个数学答案是否相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆