Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing operand order causes incorrect calculation of the infinity norm #907

Closed
macd opened this issue Aug 19, 2023 · 0 comments · Fixed by JuliaApproximation/ApproxFunBase.jl#570

Comments

@macd
Copy link
Contributor

macd commented Aug 19, 2023

When x = Fun() and a = abs(x) the value of norm(x - a, Inf) is incorrectly reported as 0.0, whereas norm(a - z, Inf) is correctly reported as 2.0. I found another example of this on the web. Details below.

macd@macd-NUC9:~$ julia19
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.2 (2023-07-05)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia @v1.9> using ApproxFun

julia @v1.9> x = Fun()
Fun(Chebyshev(), [0.0, 1.0])

julia @v1.9> a = abs(x)
Fun(ContinuousSpace{Float64, Float64, PiecewiseSegment{Float64, Vector{Float64}}}(PiecewiseSegment{Float64, Vector{Float64}}([-1.0, -0.0, 1.0])), [1.0, 5.55112e-17, 1.0])

julia @v1.9> norm(x - a, Inf)
0.0

julia @v1.9> norm(a - x, Inf)
2.0

julia @v1.9> # This behavior was noted before in:
             # https://www.cs.purdue.edu/homes/dgleich/cs514-2021/julia/Lecture-7-Approximation.html
             # (search for "why is this negative???")
             # But note that this works OK for the normal domain of [-1, 1]

             xx = Fun(Chebyshev(1..5))
Fun(Chebyshev(1 .. 5), [3.0, 2.0])

julia @v1.9> f = exp(xx);

julia @v1.9> g = exp(-xx);

julia @v1.9> norm(f - g, Inf)
148.40642115557753

julia @v1.9> norm(g - f, Inf)
-2.3504023872875983

julia @v1.9> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant