How to resolve the algorithm Arithmetic/Complex step by step in the Bracmat programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Arithmetic/Complex step by step in the Bracmat programming language

Table of Contents

Problem Statement

A   complex number   is a number which can be written as:

a + b × i

{\displaystyle a+b\times i}

(sometimes shown as:

b + a × i

{\displaystyle b+a\times i}

where

a

{\displaystyle a}

and

b

{\displaystyle b}

are real numbers,   and

i

{\displaystyle i}

is   √ -1

Typically, complex numbers are represented as a pair of real numbers called the "imaginary part" and "real part",   where the imaginary part is the number to be multiplied by

i

{\displaystyle i}

.

By definition, the   complex conjugate   of

a + b i

{\displaystyle a+bi}

is

a − b i

{\displaystyle a-bi}

Some languages have complex number libraries available.   If your language does, show the operations.   If your language does not, also show the definition of this type.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Arithmetic/Complex step by step in the Bracmat programming language

Source code in the bracmat programming language

  (add=a b.!arg:(?a,?b)&!a+!b)
& ( multiply
  = a b.!arg:(?a,?b)&1+!a*!b+-1
  )
& (negate=.1+-1*!arg+-1)
& ( conjugate
  =   a b
    .   !arg:i&-i
      | !arg:-i&i
      | !arg:?a_?b&(conjugate$!a)_(conjugate$!b)
      | !arg
  )
& ( invert
  =   conjugated
    .   conjugate$!arg:?conjugated
      & multiply$(!arg,!conjugated)^-1*!conjugated
  )
& out$("(a+i*b)+(a+i*b) =" add$(a+i*b,a+i*b))
& out$("(a+i*b)+(a+-i*b) =" add$(a+i*b,a+-i*b))
& out$("(a+i*b)*(a+i*b) =" multiply$(a+i*b,a+i*b))
& out$("(a+i*b)*(a+-i*b) =" multiply$(a+i*b,a+-i*b))
& out$("-1*(a+i*b) =" negate$(a+i*b))
& out$("-1*(a+-i*b) =" negate$(a+-i*b))
& out$("sin$x = " sin$x)
& out$("conjugate sin$x  =" conjugate$(sin$x))
&   out
  $ ("sin$x minus conjugate sin$x =" sin$x+negate$(conjugate$(sin$x)))
& done;

  

You may also check:How to resolve the algorithm String case step by step in the E programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the Chapel programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm String matching step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Comments step by step in the FUZE BASIC programming language