点产品Prolog/3要求SUM提示

编程入门 行业动态 更新时间:2024-10-27 05:34:38
本文介绍了点产品Prolog/3要求SUM提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

美好的一天,我在序言中进行算术问题,是的,它是我搜索过的点积,发现一堆乱码与本书所要问的内容并不相等.它是/3,所以这是我到目前为止的结果,但我需要对两个列表的乘积结果求和.关于应该建议做什么的任何提示?

Good Day I am doing the problema of arithmetic in prolog and Yes its the dot Product I have Searched and found a mess of code that did not equal to what the book is asking me. Its a /3 so this is what i have so far but i need to sum the result of the product of both list. Any hint on what should be recommended to do?

dot([HD|TL],[HD2|TL2],Result):- Mul is HD2 * HD, dot(TL,TL2,Mul), Result is Mul + Reuslt2. dot([],[],0).

推荐答案

您的问题是,您两次使用Mul表示您打算一次使用它,而Reuslt2在任何地方都不存在.可能您的意思是:

Your problems are that you're using Mul twice where you mean to use it once, and Reuslt2 doesn't exist anywhere. Probably what you mean is:

dot([], [], 0). dot([H1|T1], [H2|T2], Result) :- Prod is H1 * H2, dot(T1, T2, Remaining), Result is Prod + Remaining.

更多推荐

点产品Prolog/3要求SUM提示

本文发布于:2023-07-05 06:51:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:提示   产品   Prolog   SUM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!