Skip to content

Commit

Permalink
feat: Sqrt -> sqrt
Browse files Browse the repository at this point in the history
Add a mapping from Wolfram's `Sqrt` to Julia's `sqrt`.

This is correct for non-negative numbers but may have inconsistent
results for some complex arguments or output.
  • Loading branch information
musoke committed Nov 7, 2023
1 parent e506851 commit db07500
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/WolframExpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ function wexpr_to_expr(expr::MathLink.WExpr)::Expr
return Expr(:call, :^, map(wexpr_to_expr, expr.args)...)
elseif expr.head.name == "Rational"
return Expr(:call, ://, map(wexpr_to_expr, expr.args)...)
elseif expr.head.name == "Sqrt"
return Expr(:call, :sqrt, map(wexpr_to_expr, expr.args)...)
elseif expr.head.name == "Complex"
@assert length(expr.args) == 2
return Expr(:call, :Complex, map(wexpr_to_expr, expr.args)...)
Expand Down
3 changes: 3 additions & 0 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ f = string_to_function("1.+2I", [])
f = WolframExpr.string_to_function("x+y", [:x, :y])
@test f(1.2, 2) === 3.2

f = WolframExpr.string_to_function("Sqrt[x]", [:x])
@test f(2) === sqrt(2)

string_derivative = raw"""Derivative[0,1][f][x,y]"""
@test string_to_expr(string_derivative) == :(Derivative_0_1_f(x, y))

2 comments on commit db07500

@musoke
Copy link
Owner Author

@musoke musoke commented on db07500 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Pre-release version not allowed"

Please sign in to comment.