@@ -82,7 +82,7 @@ const DEFAULT_UNIVARIATE_OPERATORS = first.(SYMBOLIC_UNIVARIATE_EXPRESSIONS)
8282
8383The list of multivariate operators that are supported by default.
8484"""
85- const DEFAULT_MULTIVARIATE_OPERATORS = [:+ , :- , :* , :^ , :/ , :ifelse ]
85+ const DEFAULT_MULTIVARIATE_OPERATORS = [:+ , :- , :* , :^ , :/ , :ifelse , :atan ]
8686
8787"""
8888 OperatorRegistry()
@@ -544,6 +544,9 @@ function eval_multivariate_function(
544544 elseif op == :ifelse
545545 @assert length (x) == 3
546546 return ifelse (Bool (x[1 ]), x[2 ], x[3 ])
547+ elseif op == :atan
548+ @assert length (x) == 2
549+ return atan (x[1 ], x[2 ])
547550 end
548551 id = registry. multivariate_operator_to_id[op]
549552 offset = id - registry. multivariate_user_operator_start
@@ -619,6 +622,11 @@ function eval_multivariate_gradient(
619622 g[1 ] = zero (T) # It doesn't matter what this is.
620623 g[2 ] = x[1 ] == one (T)
621624 g[3 ] = x[1 ] == zero (T)
625+ elseif op == :atan
626+ @assert length (x) == 2
627+ base = x[1 ]^ 2 + x[2 ]^ 2
628+ g[1 ] = x[2 ] / base
629+ g[2 ] = - x[1 ] / base
622630 else
623631 id = registry. multivariate_operator_to_id[op]
624632 offset = id - registry. multivariate_user_operator_start
@@ -707,6 +715,18 @@ function eval_multivariate_hessian(
707715 d = 1 / x[2 ]^ 2
708716 H[2 , 1 ] = - d
709717 H[2 , 2 ] = 2 * x[1 ] * d / x[2 ]
718+ elseif op == :atan
719+ # f(x) = atan(y, x)
720+ #
721+ # ∇f(x) = +x/(x^2+y^2)
722+ # -y/(x^2+y^2)
723+ #
724+ # ∇²(x) = -(2xy)/(x^2+y^2)^2
725+ # (y^2-x^2)/(x^2+y^2)^2 (2xy)/(x^2+y^2)^2
726+ base = (x[1 ]^ 2 + x[2 ]^ 2 )^ 2
727+ H[1 , 1 ] = - 2 * x[2 ] * x[1 ] / base
728+ H[2 , 1 ] = (x[1 ]^ 2 - x[2 ]^ 2 ) / base
729+ H[2 , 2 ] = 2 * x[2 ] * x[1 ] / base
710730 else
711731 id = registry. multivariate_operator_to_id[op]
712732 offset = id - registry. multivariate_user_operator_start
0 commit comments