在Prolog中写数学功能
我需要在Prolog中写一个功能,但是我不明白如何返回R的值并将其放入最终功能中。我得到prolog不返回值,但我仍然无法弄清楚。
这就是我现在拥有的:
run:- write('Input X, Z:'), nl,
read(X), number(X),
read(Z), number(Z),
func(X,Y),
write('Y='), write(Y), nl.
countR(X,Z,R):- X^2>=Z, R is Z*X.
countR(X,Z,R):- X^2<Z, R is Z*e^-X.
func(X,Y):- X>R, Y is 1-X^R.
func(X,Y):- X=<R, Y is 1-X^-R.
I need to write a function in Prolog, but I don't understand how to return the value of R and put it in the final function. I get that Prolog doesn't return values, but I still can't figure it out.
This is what I have now:
run:- write('Input X, Z:'), nl,
read(X), number(X),
read(Z), number(Z),
func(X,Y),
write('Y='), write(Y), nl.
countR(X,Z,R):- X^2>=Z, R is Z*X.
countR(X,Z,R):- X^2<Z, R is Z*e^-X.
func(X,Y):- X>R, Y is 1-X^R.
func(X,Y):- X=<R, Y is 1-X^-R.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类似于:
“如果
countR
对于 X、Z、R 成立且 X 大于 R 并且 Y 为 1-X^,则func
对于 X、Z 和 Y 成立R”,其他情况也有相同的模式。
It would be like:
"
func
holds for X, Z and Y ifcountR
holds for X, Z, R and X is greater than R and Y is 1-X^R"and same pattern for the other cases.