# ================================================
# Complex numbers
# See https://en.wikipedia.org/wiki/Complex_number
# ================================================
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix complex: <https://eyereasoner.github.io/eye/complex#>.
@prefix : <http://example.org/#>.

{
    ((?A ?B) (?C ?D)) complex:exponentiation (?E ?F).
} <= {
    (?A ?B) complex:polar (?R ?T).
    (?R ?C) math:exponentiation ?Z1.
    ?D math:negation ?Z2.
    (?Z2 ?T) math:product ?Z3.
    (2.718281828459045 ?Z3) math:exponentiation ?Z4.
    (2.718281828459045 ?Z5) math:exponentiation ?R.
    (?D ?Z5) math:product ?Z6.
    (?C ?T) math:product ?Z7.
    (?Z6 ?Z7) math:sum ?Z8.
    ?Z8 math:cos ?Z9.
    (?Z1 ?Z4 ?Z9) math:product ?E.
    ?Z8 math:sin ?Z10.
    (?Z1 ?Z4 ?Z10) math:product ?F.
}.

{
    (?A ?B) complex:asin (?C ?D).
} <= {
    (1 ?A) math:sum ?Z1.
    (?Z1 2) math:exponentiation ?Z2.
    (?B 2) math:exponentiation ?Z3.
    (?Z2 ?Z3) math:sum ?Z4.
    (?Z4 0.5) math:exponentiation ?Z5.
    (1 ?A) math:difference ?Z6.
    (?Z6 2) math:exponentiation ?Z7.
    (?Z7 ?Z3) math:sum ?Z8.
    (?Z8 0.5) math:exponentiation ?Z9.
    (?Z5 ?Z9) math:difference ?Z10.
    (?Z10 2) math:quotient ?E.
    (?Z5 ?Z9) math:sum ?Z11.
    (?Z11 2) math:quotient ?F.
    ?E math:asin ?C.
    (?F 2) math:exponentiation ?Z12.
    (?Z12 1) math:difference ?Z13.
    (?Z13 0.5) math:exponentiation ?Z14.
    (?F ?Z14) math:sum ?Z15.
    (2.718281828459045 ?D) math:exponentiation ?Z15.
}.

{
    (?A ?B) complex:acos (?C ?D).
} <= {
    (1 ?A) math:sum ?Z1.
    (?Z1 2) math:exponentiation ?Z2.
    (?B 2) math:exponentiation ?Z3.
    (?Z2 ?Z3) math:sum ?Z4.
    (?Z4 0.5) math:exponentiation ?Z5.
    (1 ?A) math:difference ?Z6.
    (?Z6 2) math:exponentiation ?Z7.
    (?Z7 ?Z3) math:sum ?Z8.
    (?Z8 0.5) math:exponentiation ?Z9.
    (?Z5 ?Z9) math:difference ?Z10.
    (?Z10 2) math:quotient ?E.
    (?Z5 ?Z9) math:sum ?Z11.
    (?Z11 2) math:quotient ?F.
    ?E math:acos ?C.
    (?F 2) math:exponentiation ?Z12.
    (?Z12 1) math:difference ?Z13.
    (?Z13 0.5) math:exponentiation ?Z14.
    (?F ?Z14) math:sum ?Z15.
    (2.718281828459045 ?U) math:exponentiation ?Z15.
    ?U math:negation ?D.
}.

{
    (?X ?Y) complex:polar(?R ?Tp).
} <= {
    (?X 2) math:exponentiation ?Z1.
    (?Y 2) math:exponentiation ?Z2.
    (?Z1 ?Z2) math:sum ?Z3.
    (?Z3 0.5) math:exponentiation ?R.
    ?X math:absoluteValue ?Z4.
    (?Z4 ?R) math:quotient ?Z5.
    ?Z5 math:acos ?T.
    (?X ?Y ?T) complex:dial ?Tp.
}.

{
    (?X ?Y ?T) complex:dial ?Tp.
} <= {
    ?X math:notLessThan 0.
    ?Y math:notLessThan 0.
    (0 ?T) math:sum ?Tp.
}.

{
    (?X ?Y ?T) complex:dial ?Tp.
} <= {
    ?X math:lessThan 0.
    ?Y math:notLessThan 0.
    (3.141592653589793 ?T) math:difference ?Tp.
}.

{
    (?X ?Y ?T) complex:dial ?Tp.
} <= {
    ?X math:lessThan 0.
    ?Y math:lessThan 0.
    (3.141592653589793 ?T) math:sum ?Tp.
}.

{
    (?X ?Y ?T) complex:dial ?Tp.
} <= {
    ?X math:notLessThan 0.
    ?Y math:lessThan 0.
    (3.141592653589793 2) math:product ?Z1.
    (?Z1 ?T) math:difference ?Tp.
}.

# test
{
    ((-1 0) (0.5 0)) complex:exponentiation ?C1.
    ((2.718281828459045 0) (0 3.141592653589793)) complex:exponentiation ?C2.
    ((0 1) (0 1)) complex:exponentiation ?C3.
    ((2.718281828459045 0) (-1.57079632679 0)) complex:exponentiation ?C4.
    (2 0) complex:asin ?C5.
    (2 0) complex:acos ?C6.
} => {
    :test :is {
        ((-1 0) (0.5 0)) complex:exponentiation ?C1.
        ((2.718281828459045 0) (0 3.141592653589793)) complex:exponentiation ?C2.
        ((0 1) (0 1)) complex:exponentiation ?C3.
        ((2.718281828459045 0) (-1.57079632679 0)) complex:exponentiation ?C4.
        (2 0) complex:asin ?C5.
        (2 0) complex:acos ?C6.
    }.
}.
