# "=" vs "==" - when to use what?

i am confused as to when to use "=" and when "==" is correct. My most recent model has been that "=" means "is defined as", while "==" means "evaluates to the same as".

But that does not make sense either, since for example stuff like

plot(f.subs(a == 3), (x, -1, +1)) is clearly a definition, not an evaluation.

So please someone explain this to me.

edit retag close merge delete

Sort by » oldest newest most voted

I agree that f.subs(a == 3) is bad syntax and should probably be deprecated. For substitutions, it is much clearer to use a Python dictionary:

sage: a, b = var('a b')
sage: f = a*x + b
sage: f.subs({a: 3})
b + 3*x
sage: f.subs({a: 3, b: -2})
3*x - 2

more

Actually, in Python = has another meaning when calling a function or a method: it is used to pass a value to a parameter, that is, if a function f has two parameters m and n, and you want to evaluate it with $m=1$ and $n=4$, you can do:

f(m=1, n=4)


I would say that f(m==1) is a attempt to be nice with the newcomer, but it would not mean anything outside the symbolic ring (that keeps m==1 as a symbolic expression with two operands), since in general this will just reduce to f(True) or f(False). There is nothing interesting to understand here, this is not Pythonic, and reserved to a dark part of Sage.

more

1

that makes the scope of my question bigger, and i would love to hear a good answer.