# Unexpected result in the evaluation of a function

I hope my question isn't stupid. Why does the following code result in 1 and not 3?

```
var('a b')
f(a, b) = gcd(a, b)
f(3, 6)
```

Unexpected result in the evaluation of a function

I hope my question isn't stupid. Why does the following code result in 1 and not 3?

```
var('a b')
f(a, b) = gcd(a, b)
f(3, 6)
```

add a comment

0

Your question is very much valid. This notation to define a function (which is specific to Sage, and which creates a kind of function object) sadly does not seem to behave well except in the simplest cases. This is a bug.

I recommend not using this function notation. Instead, for one-line functions try (as in Python):

```
f = lambda a, b: gcd(a, b)
```

and for more complicated ones:

```
def f(a, b):
# possibly more statements here
return gcd(a, b)
```

By the way, the result you got probably stems from the following:

```
sage: var('a b')
(a, b)
sage: gcd(a, b)
1
```

Asked: **
2018-12-30 08:50:53 -0500
**

Seen: **43 times**

Last updated: **Dec 30 '18**

function parameters as sum limits

Definite Integral Fails due to Runtime Error

Defining a function of vector variables

running sage from a Python script

A log(101,base=10) that doesn't reply log(101)/log(10)

How can you import C++ code into a Jupyter notebook?

defining function for graph (help needed)

density_plot + def'ed python function = TypeError?

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.