3

I have an assignment to write a prolog code to add, multiply, subtract and divide complex numbers. However, I'm not sure how to portray imaginary numbers in prolog!

kompl_mul(komplex(A1,B1),komplex(A2,B2),komplex(A,B)) :-
   A is A1*A2 - B1*B2,
   B is A1*B2 - A2*B1.

This is how I would start off with the multiplication rule, but how do I implement a+bi? How can I show that B is bi?

Thanks so much for the help!

CoderCat
  • 101
  • 1
  • 2
  • 9
  • 2
    It looks like you're off to a good start with a representation, which is that `a+bi` is represented as `komplex(a, b)`, yes? So your quesiton of *How can I show that B is bi* seems you're not understanding your representation? You do not need to literally represent it as `a+bi`. Or are you asking how to input and output that specific format to the user? You've shown a correct formula for multiplication. So if you have `komplex(A1, B1)` and `komplex(A2, B2)` what do you suppose `A` and `B` are in `komplex(A, B)` if it's the sum of the first two? – lurker Apr 22 '17 at 15:10
  • [This article](http://130.216.33.163/courses/compsci367s2c/resources/prologLectures/L7-OperatorsAndArithmetic.pdf) provides an implementation of arithmetic for complex numbers in Prolog. – Anderson Green Apr 22 '17 at 21:11

0 Answers0