Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning the answer of sin function to the term sin(X) in prolog

Tags:

prolog

I wrote a Prolog program to solve simple trigonometric equations. I wrote it to get the value of a trigonometric function. For example, I can obtain the value of sin(45), but I can't assign the value of sin(45) to the term sin(45). I tried the =,==,=:= operators, but they didn't work. Actually, I want to pass the value of sin(45) to the next codes of the program instead of the term sin(45). Thanks...

like image 416
Dilrukshi Silva Avatar asked Dec 12 '25 01:12

Dilrukshi Silva


1 Answers

arithmetic is carried on by some specialized builtins, like is/2, or (<)/2, that evaluate their right hand term as an expression, and unify the numeric value with their left hand side. The most common usage is assigning a value to a free variable, like in

?- X is sin(pi/2).
X = 1.0.

note the argument of sin/1 it's in radians. After the evaluation, you pass the variable, now bound to a numeric value, down to next code.

like image 154
CapelliC Avatar answered Dec 14 '25 15:12

CapelliC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!