# Need help creating power function

**URL:** <https://swi-prolog.discourse.group/t/need-help-creating-power-function/3913>\
**Category:** Help!\
**Created:** [May 5, 2021, 10:46am UTC](https://swi-prolog.discourse.group/t/need-help-creating-power-function/3913 "2021-05-05T10:46:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![14071998a](https://avatars.discourse-cdn.com/v4/letter/1/71c47a/32.png) [@14071998a](https://swi-prolog.discourse.group/u/14071998a)\
**Post date:** [May 5, 2021, 10:46am UTC](https://swi-prolog.discourse.group/t/need-help-creating-power-function/3913/1 "2021-05-05T10:46:17Z")

</div>

Hello,  
I need your help with Prolog, please.

I have to define the power function using the product function.  
I implemented this way but I get a syntax error.

```prolog
summe(null, Y, Y).
summe(nach(X), Y, nach(Z)) :- 
   summe(X, Y, Z).

produkt(null,_,null).
produkt(nach(X), Y, Z) :- 
   produkt(X, Y, P),
   summe(P, Y, Z).

potenz(X,null,,1).
potenz(X,Y,Z) :-
   Y>0,
   K is X,
   Potenz(X,Y-1,produkt(X,K,Z))

```

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [May 5, 2021, 5:05pm UTC](https://swi-prolog.discourse.group/t/need-help-creating-power-function/3913/2 "2021-05-05T17:05:52Z")

</div>

The syntax errors point out exactly the line number and column where the errors occurred:

```prolog
ERROR: /tmp/power.pl:10:15: Syntax error: Operator expected
ERROR: /tmp/power.pl:14:31: Syntax error: Unexpected end of file

```

(There’s one more error that will show up when you fix those - the error message is a bit obscure: it’s caused by `Potenz` instead of `potenz`.)

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [May 6, 2021, 5:57am UTC](https://swi-prolog.discourse.group/t/need-help-creating-power-function/3913/3 "2021-05-06T05:57:23Z")

</div>

Hello,

Beside syntax you may also want to consider the meaning of the syntax you used.

I have a bit difficulty understand your intent in the code – perhaps you want to add some comments, to help explain what each line intends to do.

Btw, unlike many other languages, in prolog, for example, nach(X) when placed as an argument, is not a function call that returns a value, but simply a data structure that is used for matching during a predicate call – e.g. summe(nach(X), Y, nach(Z))

is matched by a call such as summe(nach(2), 3, nach(8)) … just to pick some numbers, but not by summe(2,3,5).

And similarly, product(X, K, Z) as argument isn’t a function call, but simply a data structure …

But, as mentioned, i don’t know what your intent was when you wrote these syntactic terms.

Dan
