1.2 0.95

# We both think you did wrong - How agreement shapes and is shaped by indirect
reciprocity - DRAFT

Marcus Krellner1,⋆ and The Anh Han1

1 School Computing, Engineering and Digital Technologies, Teesside University
⋆ Corresponding authors<EMAIL_ADDRESS>
## Abstract

Humans judge each other’s actions, which at least partly functions to detect
and deter cheating and to enable helpfulness in an indirect reciprocity
fashion. However, most forms of judging do not only concern the action itself,
but also the moral status of the receiving individual (to deter cheating it
must be morally acceptable to withhold help from cheaters).

This is a problem, when not everybody agrees who is good and who is bad.
Although it has been widely acknowledged that disagreement may exist and that
it can be detrimental for indirect reciprocity, the details of this crucial
feature of moral judgments have never been studied in depth.

We show, that even when everybody assesses individually (aka privately), some
moral judgement systems (aka norms) can lead to high levels of agreement. We
give a detailed account of the mechanisms which cause it and we show how to
predict agreement analytically without requiring agent-based simulations, and
for any observation rate. Finally, we show that agreement may increase or
decrease reputations and therefore how much helpfulness (aka cooperation)
occurs.

Keywords:cooperation, evolutionary game theory, indirect reciprocity, donation
game, private assessments, analytical predictions

##  1 Introduction

From simplest replicators, evolution has worked its wonders and today we
marvel at the success, diversity and complexity of life. Many wonders of life
were enabled by cooperation. Cells work together to form multicellular
organisms, former bacteria serve as the powerplants of cells in exchange for
eternal protection from an outside world, and individual organism work
together in communities of thousands and millions to become the most
widespread forms of life there are, ants/wasps and, in similar but different
way, humans.

Indirect Reciprocity (IR) is one of the few other mechanisms to facilitate
cooperation among self-interested agents (Rand and Nowak,, 2013, Nowak and
Sigmund,, 2005, perc2017statistical). You help me, without receiving any
direct returns (that is, in that moment you behave altruistically). But you
will be rewarded by others in the future. Because others have observed your
behavior and will like you for it. I.e. they judge your action and form an
opinion about you. And because they like you, they decide to help you.
Indirect reciprocity allows cooperation (aka continued help amongst helpers)
in large groups of unrelated individuals, even if they do not interact enough
to establish direct reciprocity (Schmid et al.,, 2022). Hence, indirect
reciprocity has been the focus of many influential studies of evolutionary
game theory (Nowak and Sigmund, 1998a , Ohtsuki and Iwasa, (2004), see also
Sigmund, (2016)) and is even considered as an important foundation of human
morality (Nowak and Sigmund,, 2005).

Traditionally, studies simplified the mechanism of IR, assuming that judgments
are unanimous (also called public assessments). More realistically, everybody
would make their own judgements and therefore have their own opinions (aka
private assessments). When the public assessment assumption is removed,
dynamics and outcomes of IR models change (Brandt and Sigmund,, 2004, Okada,
2020b, ), often to the worse for the evolution of cooperation (Uchida and
Sasaki,, 2013, Hilbe et al.,, 2018). The main reason is the emergence and
spreading of disagreements about someone’s reputation, which had not been
possible with public assessments. Disagreements can significantly disturb IR
strategies that are stable under the public assessment regime, because they
hinder a universal principle: if you withhold help towards somebody bad, this
should not be judged as bad 111at least if done by somebody good, which can be
seen as in general judging it neutral or even good (Okada, 2020b, , Krellner
and Han,, 2022). (Panchanathan and Boyd,, 2003, Ohtsuki and Iwasa,, 2006). It
is problematic to apply this rule, if potential helpers and observers may
disagree. You withhold help to me, since you do not like me. But some
observers like me, so they will disapprove of your action. So, if there was
disagreement about my reputation, your reputation can get tainted.

In addition, a disagreement can cause further disagreements. If two observers
disagree about me, they may also judge you differently for withholding help.
That is, they now disagree about another person’s reputation. Even a single
disagreement can cascade through the population, even if no further errors
occur, so that all opinions become bad or essentially random (Hilbe et al.,,
2018).

Private assessment and disagreements are not only detrimental for IR
strategies, but also lead to new challenges for IR research. Whereas for
public assessment, there had long been exhaustive investigations of hundreds
of strategies (Ohtsuki and Iwasa,, 2004)[santos] using analytical models,
something similar for private assessment was only achieved in recent years
(Okada, 2020b, , Perret et al.,, 2021). And these models still require
restricting assumptions. Namely that, in an infinite population, only a finite
number of players observe. That is, the probability to observe $\psi$ and
hence also the fraction of opinions changed by a single interaction are
required to be negligible ($\psi\rightarrow 0$).

Analytical models and most models of IR in general (Okada, 2020a, ) consider
opinions as binary. That is, an individual is judged as either good (1) or bad
(0). To understand the state of opinions in a population, it is important to
know the average reputation $r$: the probability of a random opinion being
good, as well as the average probability of an agreement $a$: the probability
that two randomly selected players have the same opinion about another random
player.

The models mentioned above only considered $r$ (hence we shall call them
R-models for short). They assume that, when the observation probability is
very small ($\psi\to 0$), the probability of agreement $a$ only depends on $r$
and is given by $\widehat{a}=r^{2}+(1-r)^{2}$ (i.e. probability that two
random opinions are either both good or both bad) (Okada et al.,, 2018).

Figure 1:
a) Two dimensions of global opinion state. Graph shows agreement-reputation
space, with the solid lines $a=1$ and $a=\widehat{a}$ indicating outer borders
of possible agreement values in grey. (Subsequently, values above
$a=\widehat{a}+0.05$ will be considered as significant additional agreement,
since values very close to $\widehat{a}$ could conceivably be the result of
noise or finite properties of the simulations; or be just too insignificant to
make a difference). Case 1 has minimal agreement for the specific global
average reputation $r$. Case 3 has maximal agreement for the same $r$ and case
2 an intermediate one for the same $r$ still.
b) Model of simplified image matrices. We simplify the image matrices for the
three cases by removing all information about whose opinions it is and what
specific player it is about. We only consider whether the opinion is about a
player of group 1 or group 2 . The result can be imagined as two containers
(left and right, separated by the double line) holding good opinions (dark
blue areas). We may call the containers or groups ”lucky” on the left and
”unlucky” on the right. In case 1, both containers are filled to the same
height, representing that the reputations of lucky and unlucky group, $r_{L}$
and $r_{U}$, are equal to the global average. In case 2, some good opinions
from the unlucky container were ’poured’ into the lucky container, keeping $r$
unchanged since we do not add or remove any good opinions. In case 3, all
remaining of these good opinions were poured as well, filling the lucky
container exactly to the brim. It is apparent that in case 3, all players of
the lucky group have only good opinions about them, therefore agreement about
a player of this group is always $100\%$. The same applies to the unlucky
group, which has only bad opinions about them.
c) Size of the groups and precise state of agreement d. The complete
transition from case 1 to case 3 can only be achieved under a specific
condition. The size of the groups (the width of the containers) must be $r$
and $1-r$, respectively. With this, the areas $A_{L}$ and $A_{U}$ are of equal
size. That means, for minimal agreement as in case 1, there are exactly as
many good opinions about the unlucky group as there are bad opinions about the
lucky one. Therefore, they can be entirely exchanged. The central feature of
the analytical model introduced in this paper, is the parameter $d$, which
describes the percentage of good opinions from area $A_{U}$ exchanged with bad
opinions from area $A_{L}$. This parameter is independent of $r$ and can
obtain any value in the interval $[0,1]$ (note that both areas disappear for
the extreme cases $r=0$ and $r=1$, which is why $d$ is arbitrary in these
cases). For details see equations 2 and 4.

In theory, $a$ can be much higher. The population could for example consist of
two groups, one with perfect reputation, the other with an abysmal one, see
case 3 in Figure 1. The average reputation is still $r=0.6$. But all opinions
about a player of the unlucky group are bad. Which means that the opinions of
any two players about such a player will always be the same. This is similarly
true for the lucky group in which all opinions are good. In case 3, average
agreement is therefore 100%. There are of course also intermediate states,
such as case 2. The left side of the figure shows the entire agreement-
reputation space and how agreement can range anywhere between $\widehat{a}$
and 1. Note that $0.5\leq\widehat{a}\leq 1$ (since $0\leq r\leq 1$).

There are obvious mechanisms that cause disagreement and push state of the
population towards $\widehat{a}$, as discussed above. However, there could be
other mechanisms that increase agreement. For example, if you donated your
help, observers may not care about their current opinion about the recipient
and like you either way (which is the case for image scoring (Nowak and
Sigmund, 1998b, ) or standing (Sudgen,, 1986, Leimar and Hammerstein,, 2001)).
Hence, aside from a few who miss-perceive your action due to noise, all
observers will have the same opinion about you.

The existence of additional agreement, i.e. states where agreement is
significantly above $\widehat{a}$, was already implicitly shown by the work of
Fujimoto and Ohtsuki, (2022), who investigated the exact distributions of
reputations for four strategies. They found that even infinite populations
sometimes have two or even up to an infinite number of distinct reputation
states, that a player could be in. It was not stated by the authors but any
split of players into groups with different reputation states entails that the
opinions of this population have additional agreement (see a proof sketch in
Supplementary Information (SI)). Nevertheless, their seminal work included an
analytical model to predict distributions of strategies exactly, which will
likely be foundational for future analytical models of IR. Yet, two problems
remain. The number of strategies it can be applied to is small and the model
is limited to the condition of full observation (i.e., $\psi=1$).

In conclusion, in the literature so far, there have been only two types of
analytical models of private assessment, and they are all limited to either
$\psi=1$ or $\psi\to 0$. Both cases are extreme ends of possible natural
conditions. Full observation seems impossible due to physical constraints.
Even if all interactions between people were public, there are still
limitations to the attention observers can pay. Nominal observation rates, on
the other hand, make IR less effective in the short-term, and may cause it to
be replaced by direct reciprocity (Schmid et al., 2021a, ). As Fujimoto and
Ohtsuki, (2022) state themselves, a model for intermediate observation rates
is necessary, especially to study IR under private assessment in an exhaustive
fashion, like the defining work of Ohtsuki and Iwasa, (2004).

Overall, our investigation fills two major gaps in the literature. We provide
the first the exhaustive investigation of agreement in reputation dynamics
under private assessment. We test whether additional agreement is common for
high or intermediate observation rates, but also if the assumption of the
R-models always holds for $\psi\to 0$. We test this with simulations of a vast
number of strategies and conditions. Second, we define the first A-R-model,
that moves beyond the one-dimensional approach of the R-models, to capture the
two-dimensional space of agreement and reputation. It is capable of predicting
long-term behavior of said simulations. Both contributions advance the
understanding of indirect reciprocity under private assessment and lay
important groundwork for exhaustive evolutionary investigations.

##  2 Methods

###  2.1 Simulation

We examine if the average agreement $a$ is greater than assumed in the
R-model, $\widehat{a}=r^{2}+(1-r)^{2}$. For that, we run simulations with
different strategies and conditions. To limit complexity, following the
example of Fujimoto and Ohtsuki, (2022), we consider homogeneous populations,
i.e. within a simulation all agents follow the same strategy.

We have chosen a framework to model many different strategies. The first
characteristic of a strategy is its assessment rules, given by vector
$\alpha$. It defines how an observer judges the action, i.e. cooperation $C$
or defection $D$, depending on its opinion about the recipient, i.e. good $G$
or bad $B$. An assessment can be one of three forms: the action is approved of
(+1), disapproved of (-1) or ignored (0). If the player approves of an action,
their opinion of the donor will be good afterwards (which is the same as to
say that it has increased within the limit of the two opinion values, 0 and 1,
aka bad and good). If the action is disapproved of, the opinion will be bad.
And if the action is ignored, the opinion does not change.

The second characteristic of the strategy is given by its action rules
$\beta$. They define what players will do, when they meet a recipient they
like or dislike. These actions are cooperate (1) or defect (0). In the
following, if we refer to $\alpha$ and $\beta$ as a whole, in the order given
below. But we will sometimes refer to specific values or pairs of values, such
$\alpha_{CG}$: cooperation towards good. With this framework we can model 324
different strategies. For example the commonly studied strategy “staying”
(Okada et al.,, 2017, Sasaki et al.,, 2017) is described as follows:

$\begin{matrix}staying:&\begin{matrix}\alpha=\\{\alpha_{CG},\alpha_{DG},\alpha_{CB},\alpha_{DB}\\}=(1,-1,0,0)\\\
\beta=\\{\beta_{G},\beta_{B}\\}=(1,0)\end{matrix}\par\end{matrix}$ (1)

Of all the possible strategies of our framework, we study 171 strategies with
unique behavior. Each of the possible strategies has a mirror image, which
behaves equivalently in regard to cooperation. If we were to label opinion
states as blue and red (instead of good and bad), an mirror image would
cooperate in the exact same way to the same partners, but would think of them
as blue instead of red or vice versa. We obtain such a mirror image of a
strategy by exchanging the symbols +1 and -1 in the assessment rules and
flipping them for good and bad recipients
($\alpha_{m}=(x_{1},x_{2},x_{3},x_{4})$ to
$\alpha=(-x_{3},-x_{4},-x_{1},-x_{2})$) as well as flipping values of the
action rules ($\beta=(xy)$ to $\beta_{m}=(yx)$). Note, that some strategies
are their own mirror strategy. This focus on unique strategies conveniently
leaves us with only three possible action rules: (1,1): unconditional
cooperators or AllC, (1,0): conditional cooperators or Coco222sometimes,
somewhat unfortunately, called discriminators and (0,0): unconditional
defectors or AllD (see SI for examples of mirror images).

For our simulations, we consider a well-mixed population of size $N=100$.
Every agent can have either a good (1) or a bad (0) opinion about each other
agent. Hence, the state of the population can be described by the $N\times N$
image matrix $M(t)$ of the population at time $t$ (Uchida,, 2010). Initially
all entries are filled by a fair coin toss. Other studies have reported, that
other initial conditions almost never change the outcomes (Hilbe et al.,,
2018).

Time is discrete. In total, each time step consists of three parts. First, a
donor $do$ and a recipient $re$ are drawn at random from the population. The
donor then decides whether to cooperate. Note, these two steps are usually
referred to as the donation game. To apply IR, donors base their decision on
their action rule and their current opinion about the recipient. In the third
part, opinions about the donor are updated due to observations.

These observations and updating can be broken down further. First, for each
player (except the donor and recipient) it is decided if they will observe the
interaction. For each player, who observes, it is determined if it observes
accurately or if the observation is altered by a perception error, i.e. with a
probability $\epsilon$ they will perceive the opposite of what the donor is
actually doing. Next, individually perceived action and individual opinion of
the observer about the recipient are combined for the private assessment of
the donor. The opinion is updated if assessment is 1 or -1, but left as is if
assessment is 0. Finally, each observer (whether they made an assessment or
not) may change their opinion to a random value if they commit a cognitive
error with probability $\mu$.

We study the behavior of the simulation in the long term and extract precise
values for average reputation $r$ and average agreement $a$. In order to
ensure accurate and reliable results, the simulations are run until we are
reach an objective level of confidence about the measured average values (for
details see SI.)

Note, in our version of the donation game, the donor and recipient do not
update their opinion. I.e. players ignore the information of interactions they
are themselves involved. This means we study pure indirect reciprocity,
without any direct reciprocity (Schmid et al., 2021a, ). Because of that, the
diagonal of the image matrix is never updated nor used. We therefore exclude
it from all computations of averages. For a detailed motivation of this design
see SI.

###  2.2 Predictive A-R-Model

How could we define a new model which can represent both $r$ and $a$, but is
otherwise as simple as possible? It has to be able to represent a continuous
transition of $a$, from the baseline of the former prediction $\widehat{a}$ to
its maximum 1 (see transition from 1 to 3 in figure 1). The transition must be
possible for any $0\leq r\leq 1$ while keeping $r$ constant. As mentioned, we
could first nominally divide the population into two groups, lucky and
unlucky. To increase agreement a minimal step, we could take away a random
good opinion about an unlucky player and exchange with a bad opinion about a
lucky player. I.e. we decrease the average opinion of unlucky players and
increase the average opinion about lucky players. We could continue to do so
until lucky players have the average reputation $r_{L}=1$ and unlucky players
have the average reputation $r_{U}=0$, hence both agreement about lucky
players $a_{L}$ and agreement about unlucky players $a_{U}$ is 1.

We can do this only if the number of good opinions about unlucky players
$n_{GU}$ is equal to the number of bad opinions about the lucky players
$n_{BL}$. This is the case, if the size of the lucky group (or the percentage
of lucky players) is equal to $r$, hence the size of the unlucky group is
$1-r$. With this assumption, we may define a single value $d$, which is both
the percentage of good opinions about unlucky players stolen and the
percentage of bad opinions about lucky players replaced (see figure 1c).

$r_{L}=r+d(1-r)\quad\&\quad r_{U}=r-dr,\quad 0\leq d\leq 1.$ (2)

With this model we define the two dimensional space with just two variables.
We assume a specific distribution of reputations, namely that there are
exactly two groups (in general there could be up to $N$ groups in a population
of $N$ players). The goal of our model is not to represent the exact
distribution. Just to represent $a$ as well as $r$, for which the two-group
scenario provides a minimal model. It allows us to to model all agreement
states in all reputation states with a single parameter $d$.

Both $r$ and $d$ can range between 0 and 1 (whereas the minimum of $a$ would
depend on current $r$). Note that $d$ is undefined for $r=0$ and $r=1$ (see
equation 3), but it does not need to be. In the case of $r=0$, $d$ vanishes
from $r_{U}$ and the size of the lucky group is zero, hence $n_{GU}$ is zero
for any $d$. The opposite is true for $r=1$ respectively. Besides these
extreme cases, $d$ is given by

$d=\frac{2^{1/2}(r(1-r)(-2r^{2}+2r+a-1))^{1/2}}{2r(1-r)}=\left(1-\frac{1-a}{2r(1-r)}\right)^{1/2},\
0<r<1.$ (3)

This close form of $d$ is derived by solving the equation (4) below for $d$,
by replacing $r_{L}$ and $r_{U}$ with the equations in (2). The global average
agreement $a$ is given by the sum of agreements about members in each group
discounted by the group size, i.e. $a=ra_{L}+(1-r)a_{U}$. The agreement for a
group is derived by its average reputation, that is
$a_{L}=r_{L}^{2}+(1-r_{L})^{2}$ and $a_{U}=r_{U}^{2}+(1-r_{U})^{2}$. Thus,

$a=r(r_{L}^{2}+(1-r_{L})^{2})+(1-r)(r_{U}^{2}+(1-r_{U})^{2}).$ (4)

We will now use $r$, $r_{L}$ and $r_{U}$ to predict the probabilities of
events of our simulation, assuming an infinite population. To model a time
step of the simulation, we need to distinguish between onetime events and
repeated events. There are three events that happen only once per time step:
picking a donor, picking a recipient and the decision of the donor. For these
we need to know three kinds of probabilities for later computation. First, a
pair of probabilities $q$ about the donor’s group affiliation: $q_{L}=r$
(lucky group) and $q_{U}=1-r$ (unlucky group). Second, four probabilities $p$
representing the combinations of donor’s choice and recipient’s group. For
example, $p_{CL}$, the probability that the donor cooperates and the recipient
is in the lucky group (where $\beta$ is the set of the donor’s action rules
and $1-r_{L}$ is the chance the donor has a bad opinion of the recipient from
the lucky group), is given as follows

$p_{CL}=r\Big{(}r_{L}\beta_{G}+(1-r_{L})\beta_{B}\Big{)}$ (5)

or in general

$\begin{matrix}p_{jk}=q_{k}\Big{(}r_{k}c_{jG}+(1-r_{k})c_{jB}\Big{)},\\\
\text{where }j\in\\{C,D\\},\ k\in\\{L,U\\}\text{ and
}c_{Cx}=\beta_{x},c_{Dx}=1-\beta_{x}.\end{matrix}$ (6)

Third, a 2-by-4 matrix $G$ showing how likely the opinion of the donor is good
after assessment. It depends on the previous reputation of the donor’s group
$r_{i}$ and the four assessment rules $\alpha$ (see equation 1). For example,
since staying judges cooperation with bad recipient as neutral,
$\alpha_{CB}=0$, the probability to be considered good is equal to the
previous reputation, which is $r_{L}$ if the donor belongs to the lucky group

$G_{L,CB}=r_{L},$ (7)

or in general

$\begin{matrix}G_{i,mn}=\begin{matrix}1,&\text{if}&\alpha_{mn}=1\\\
r_{i},&\text{if}&\alpha_{mn}=0\\\ 0,&\text{if}&\alpha_{mn}=-1\end{matrix},\\\
\\\ \text{where }i\in\\{L,U\\},m\in\\{C,D\\},n\in\\{G,B\\}.\end{matrix}$ (8)

These are the probabilities that depend onetime events. There are also
probabilities of repeated events, namely observations, since there can be many
observers. Each observation includes the action the observer perceives and
what opinion it had about the recipient. Hence there can be four kinds of
observations, and we compute their probability $O$ for each of the four
combinations of onetime events $p$ described in equation 6. For example, in
the event that the donor cooperated with a lucky recipient, we can compute the
probability $O_{CL,CG}$, that the observer has a good opinion about this lucky
recipient and that the observer perceives the cooperation without a perception
error $\epsilon$.

$O_{CL,CG}=r_{L}(1-\epsilon),$ (9)

or in general

$\begin{matrix}O_{jk,mn}=r_{i}^{*}e,\\\ \\\
\begin{matrix}r_{x}^{*}=r_{x}&\text{if}&n=G\\\
r_{x}^{*}=1-r_{x}&\text{if}&n=B\\\ e=\epsilon&\text{if}&m\neq j\\\
e=1-\epsilon&\text{if}&m=j\\\ \end{matrix}\\\ \\\ \text{where
}j,m\in\\{C,D\\},k\in\\{L,U\\},n\in\\{G,B\\}.\end{matrix}$ (10)

We then take into account observation rates $\psi$ and cognitive errors $\mu$,
which are also repeated events. Each observation might not take place, leaving
opinions unchanged. When it takes place, the resulting opinion may be altered
by a cognitive error and its value would be reversed. We therefore adjust $G$
to $G^{*}$.

$G^{*}_{i,mn}=(1-\psi)r_{i}+\psi(G_{i,mn}(1-\mu)+(1-G_{i,mn})\mu).$ (11)

With these probabilities we can now compute the probability of the eight
possible interactions, that is, the combination of all three onetime events,
as follows

$\Pi_{ijk}=q_{i}p_{jk},$ (12)

and the expected reputation of the donor for each of these combinations

$\Gamma_{ijk}=\sum_{m,n}G^{*}_{i,mn}O_{jk,mn}.$ (13)

Finally, we can now compute the expected change of reputation

$\Delta_{r}=\Big{(}\sum_{i,j,k}\Gamma_{ijk}\Pi_{ijk}\Big{)}-r$ (14)

and the expected change of agreement

$\Delta_{a}=\Big{(}\sum_{i,j,k}((\Gamma_{ijk})^{2}+(1-\Gamma_{ijk})^{2})\Pi_{ijk}\Big{)}-a.$
(15)

Note, as it was when computing agreement in the simulation, the instances of
interaction have to be computed separately. Each of the eight possible
interactions predicts a specific agreement about a donor’s image. We compute
each instance and only then compute the expected value of $\Delta_{a}$. Note
also, that we do not assume that the donor can be attributed to the lucky or
unlucky group after assessment. These groups are simplifications of the real
image matrix that we use to describe its state with only two parameters.
Information about the exact expected reputations of the donor and hence the
agreement about it for the eight possible interactions is lost. Our model does
not give exact predictions.

To validate our analytical model, we create a numerical algorithm to find the
stable equilibria points in the $r\times a$ space (see SI for a detailed
description). We use it to find the equilibria for all cases which we
simulated and compare the results. For additional comparison we also use an
analytical approach that models agreement always as $\widehat{a}$, aka a
R-model (Perret et al.,, 2021), and compare the fit of both predictive models.

##  3 Results

(a) Simulations. Agreement and reputation averaged across runs for homogeneous
populations with 100 players. Not shown are cases where range of averaged
reputations between runs exceeded 0.1 (2.9% of cases for Cocos). For Cocos,
$25.2\%$ have significant additional agreement (above the broken line).

(b) Predictions. Unique stable states of the model for infinitely large
homogeneous populations. Not shown are cases where multiple equilibria were
found which ranged more than 0.01 in total distance in A-R space (for Cocos,
27 cases spread over only 3 strategies. See SI for some examples.)

Figure 2: Comparing results of simulations and analytical predictions. Values
for 171 unique strategies in 15 conditions (namely,
$\epsilon\in\\{0,0.001,0.01,0.05,0.1,0.2,0.4\\}$ and
$\mu\in\\{0.001,0.01,0.05\\}$). Reputation $r$ (x-axis) can range between $0$
and $1$. Agreement $a$ can range between $a=\widehat{a}$ and $a=1$ (solid
black lines). Values above $a_{th}=\widehat{a}+0.05$ (broken black line) are
considered as significant additional agreement. Figure 3: Results for Cocos
with other observation rates $\psi$. On the left are the simulation results,
and on the right, the predictions of the A-R-model. Values for all 81 unique
conditional cooperators, with conditions and excluding criteria the same as
those given in figure 2.

As described above, we studied 171 strategies with unique behavior. Each
homogeneous population of 100 players is first tested for the observation rate
$\psi=1$ in 15 conditions. The conditions span an exhaustive range of
perception errors $\epsilon\in\\{0,0.001,0.01,0.05,0.1,0.2,0.4\\}$ and a
reasonable range of cognitive error $\mu\in\\{0.001,0.01,0.05\\}$. Note, this
full observation is the natural opposite to limiting assumption of the R-model
where $\psi\to 0$.

Figure 2(a) shows the results of our simulations as reddish dots. They are
depicted separately for the three kinds as action rules: Coco, AllC and AllD.
For AllC and AllD, agreement is always virtually minimal. But for Coco
strategies, many points lay far above. Sometimes agreement is almost maximal
($a\to 1$), while $\widehat{a}$ predicted it to be the smallest possible value
($a=0.5$ at $r=0.5$). For Cocos, 25.2% of the measured agreements were at
least 0.05 higher than expected (indicated by the broken black line).

Note that we removed cases in which results differed significantly across
runs. Averaging them could give a false impression of average agreement. For
example, two runs with $r_{1}=0.3$ and $r_{2}=0.7$ and each minimal
$a_{i}\to\widehat{a}=0.58$ would average to $r=0.5$ and $a=0.58$. For this
averaged reputation, the minimal agreement would be $\widehat{a}=0.5$, so the
average measurement would be $0.08$ higher than that. In other words, although
the actual agreement in each run was minimal, the averaged agreement would
indicate additional agreement above the threshold. We exclude cases in which
the range of $r$ in a single condition is above $0.1$ ($2.8\%$ of cases in
condition $\psi=1$, see SI for examples of excluded cases and alternative
figure with cases included). It is clear that our findings are not caused by
such artifacts and that for $\psi=1$ results differed substantially from the
prediction $\widehat{a}$ with more agreement than expected for many
conditional cooperators.

Next, we show that these results can be replicated for $\psi=1$ by our A-R-
model, see blue dots in figure 2(b). Excluded are again cases for with
multiple equilibria (given the much higher precision of the analytical
approach we excluded all cases in which the total distance in the agreement-
reputation space, similar to equation 16, exceeded 0.01, see SI for examples
of excluded cases). The general patterns of the simulation could be
replicated. AllCs and AllDs have virtually no additional agreement whereas
Cocos do. The qualitative fit between simulation and model is striking.

Before we quantitatively describe the fit, we expand our investigation to
other observation rates. We show only results for Cocos, since these are the
most interesting cases, in figure 3. We studied three intermediate observation
rates $\psi\in\\{.75,.5,.25\\}$ as well as a special case, where every round
would have exactly one observer. A single observer is the smallest amount of
meaningful observation possible. No observation would simply not change the
image matrix and have no impact on reputation or agreement. It is the closest
one can get to the limiting assumption of the R-Model $\psi\to 0$.333Even
taking a very small probabilistic observation rate such as $\psi=0.0001$ would
have actually increased the number of observers. All rounds in which no
observation takes place are simply ignored. The rest may have one or more
observers. In addition, simulating many rounds just to be ignored would
increase the computational demand unnecessarily for no benefit.

Both simulation and prediction show a steady decline in agreement, until $a$
is virtually minimal when there is only a single observer. This is a
qualitative fit of what the R-model assumes. Adjusting the observation rate in
the A-R-model replicates it. For all observation rates, qualitative fit is
still high. And, similarly to full observation, intermediate observation rates
still show significant additional agreement.

We quantified the fit of simulation and predictions in two ways. Our A-R-model
makes predictions about agreement $a_{p}$ as well as reputation $r_{p}$. We
therefore compute the absolute distance to simulated agreement $a_{s}$ and
reputation $r_{s}$ by

$\Delta=\sqrt{(a_{p}-a_{s})^{2}+(r_{p}-r_{s})^{2}}.$ (16)

We excluded values not shown in figures 2 and 3 (if either simulation or
prediction had to be excluded, we excluded the entire pair). Results for all
observation rates are shown in the left of table 1. For both maximal and
intermediate observation range, the fits are excellent. The median of absolute
distance between the simulations and the model is 0.003. For 92.7-95.7% of
predictions, the deviation is smaller than 0.01. For the minimal observation
rate, fits are slightly worse. The median 0.005 and only 72.3% of predictions
are less than 0.01 of target.

We also compared the predictions of our A-R-model with predictions of the
R-model. Since the R-model can only predict reputation $r_{o}$, we compared
the two models in that regard. The difference in deviation is shown in the
right of table 1. Keep in mind that the R-model was designed only for $\psi\to
0$, which is most closely met in the single observer condition. The new A-R-
model is not often better as the R-model in this case. And at least for one
case, it is much worse, as indicated by the range. However, the A-R-model is
superior for all high and intermediate observation rates $\psi$. Its
predictions are better in $4.6\%$ to $11.5\%$ of all cases (AllD, AllC and
Cocos), and the accuracy is increased by as much as $0.5$, which is half of
the maximum range of $r$. Higher accuracy is especially prevalent for Cocos,
to which all evolutionary successful strategies belong, such as image scoring
(Nowak and Sigmund, 1998a, ) and the leading-eight (Ohtsuki and Iwasa,, 2006).
Here, for $\psi=1$, the A-R-model is better in $24\%$ of cases. Considering an
independently changing average agreement seems to have increased the
prediction of average reputation substantially.

Table 1: Deviations between Model Predictions and Simulation | A-R-model |  |  | Difference A-R-model minus R-model |  |
---|---|---|---|---|---|---
| absolute deviation |  |  | deviation in reputation |  |
| median |  $<.01$ | $<.05$ | $<-.01$ |  |
(A-R better) | $>.01$ |  |  |  |  |
(A-R worse) | range |  |  |  |  |
$\psi=1$ | 0.003 |  92.7% | 99% | 11.5% | 0% | -0.498:0.006
$\psi=0.75$ | 0.003 |  95.7% | 99% | 9.7% | 0.1% | -0.497:0.051
$\psi=0.5$ | 0.003 |  95.4% | 98.9% | 7.8% | 0.2% | -0.495:0.053
$\psi=0.25$ | 0.003 |  94.7% | 98.4% | 4.6% | 0.1% | -0.491:0.014
single observer | 0.005 |  72.3% | 86% | 1.2% | 0.4% | -0.034:0.334

##  4 Discussion

We now summarize our findings and their immediate implications, before
highlighting remaining issues and limitations. We further compare our A-R-
model with the recent model of Fujimoto and Ohtsuki, (2022) to highlight the
differences and common ground. We then discuss some important potential
extensions of the A-R-model, which would enable it to implement recently
proposed enhancements to IR strategies, such as generous assessment (Schmid et
al., 2021a, ) and pleasing (Krellner and Han,, 2021). We will close with
possible real world implications of the discovered additional agreement.

In the first part of our report, we showed that additional agreement can
emerge in indirect reciprocity under private assessment. For high or
intermediate observation rates, opinions about a person were shared much more
often than mere chance. Therefore, the assumption of the minimal agreement
$\widehat{a}$, on which most previous models (R-models) relied, cannot be
generalized to these circumstances. We could on the other hand confirm that
the assumption is reasonable for very low observation rates, such as a single
observer for each interaction. But we showed, that results about evolutionary
success with solitary observers (Okada et al.,, 2018, Okada, 2020b, , Perret
et al.,, 2021) cannot yet be generalized to other observation rates.

The second part of our report makes an important step towards that goal.
Previous R-models can only model average reputation and therefore must rely on
the assumption of minimal agreement. Our A-R-model is able to represent
average levels of agreement and reputation independently. It predicts both
with astounding accuracy and does so for any intermediate or high observation
rates. It outperforms the predictions of R-models in these circumstances by a
large margin.

Making precise measurements or predictions of reputation in particular is the
basis for studies on the evolutionary stability of any reputation-based IR
strategies (Okada, 2020a, ). An individual’s reputation directly corresponds
to how much cooperation they receive, hence it determines their payoffs and
even the payoffs of others (from which the may receive cooperation, hence
cause costs to them).

Parallel to this work, other researchers have discovered another way to
predict opinion dynamics more accurately than by average reputation alone.
Fujimoto and Ohtsuki, (2022) were able to predict precise distributions of
reputations, e.g. 80% of players who would have a reputation of about 0.8, 15%
of 0.2, and 5% of 0.25. This was another hugely important step for analytical
models of IR under private assessment and is, of course, closely related to
the current paper.

Our model assumes a simplified distribution of reputations. We treat the
populations as if there were at most two groups, and as if their size was
given by the average reputation. Fujimoto and Ohtsuki, (2022) show that this
is often not the case, that there can be more groups or other compositions.
Their analytical approach is exact and uses no simplification. However, as the
fit of our model shows, this level of detail may not be necessary.

And the level of detail in their model seems to come at a cost as their
analysis is limited to only four strategies. It seems reasonable however that
their framework could model all strategies, that care about action as well as
reputation of the recipient, but apply only binary assessment rules (i.e.
assess each action as either good or bad, but not as neutral). This would
cover 64 strategies (mirror images included) compared to the 324 of our
study.444Indeed, in a preprint, Fujimoto2023 modelled 16 strategies, focusing
on a single action rule, instead of four. If they had looked at all actions
rules and not exclude mirror images, they could have modelled 64 strategies.
However, since they were only concerned with levels of cooperation, the
limitation to Cocos ($\beta=(1,0)$) was perfectly justified. AllD and AllC
with different assessment rules may held different reputations, yet the all
cooperate the same.

Their model also covers only a single observation rate $\psi=1$. The authors
themselves state that being able to model arbitrary observation rates would be
a very important extension of their approach. Our A-R-model is already able to
do that. And, it seems at least possible, that their approach is not capable
of dealing with intermediate observation rates, i.e. $\psi<1$. Because their
model currently relies on the fact that the new reputation of the donor is
entirely independent of their current reputation. If some players do not
observe, their new opinions depend (entirely) on their current opinions, since
their opinions are just kept as they are. Their model could no longer be based
on one dimension (the current reputation of recipients) but would have to
incorporate entirely new dimension (the current reputation of the donor). This
increase in complexity might be a serious problem.

These problems for arbitrary observation rates also concern the modelling of
more complex, so-called 3rd-order strategies (Santos et al.,, 2021), which
also use the current reputation of the donor in their assessment. In contrast,
in our A-R-model, the current reputation of the donor is already incorporated.
It will be straightforward to extend our model to consider all 2048 3rd-order
strategies (mirror images included) (Ohtsuki,, 2004).

We envisage the following additional extensions of our model. First, we can
include strategies that do not use deterministic rules but probabilistic ones
(Schmid et al., 2021a, , Schmid et al., 2021b, ). Instead of assessing
defection always as bad, observers may only do so 80% of the time (in other
words they are sometimes generous in the judgment). The same could be applied
to their action rules. They may want to cooperate even with bad individuals
about 10% of the time. Second, we can include pleasing (Krellner and Han,,
2020, 2021). Instead of granting or refusing help only based on the donor’s
own opinion (which can be easily disturbed by perception error), the donor
pools some of the opinions of others and act like the majority would decide.
Some of these extensions are as easy as replacing -1, 0 or 1 in the action and
assessment rules of this paper with -0.8 and 0.1.

Figure 4: Detailed comparison between models for staying norm (see equation
1). Parameters are $\psi=1$, $\epsilon_{p}=0.1$ and $\mu=0.01$. Bottom graph
shows the two-dimensional space of the A-R-model. Dark blue areas indicate
likely changes in either agreement or reputation or both, whereas light yellow
areas indicate little to no change. Arrows indicate the direction of the
change. The precise predictions of the model is indicated by a blue x.
Simulations are shown in red, the averages of single runs are shown as red
circles and their total average as a red +. Top graph shows one-dimensional
R-model in comparison. Change in reputation and its direction is depicted on
the y-axis in addition to the arrows. The stable point (green x) is where the
x-axis is crossed with a downward slope. The white line in the A-R-model
indicates a shift from reputation decrease (below) to reputation increase
(above).

This paper is the first to study agreement in such detail. Agreement is the
key feature that distinguishes previous research on IR under public assessment
from the more recent research on private assessment. Public assessment fixes
agreement at its maximum (all agree all the time), but private assessment does
not fix it at the opposite state i.e. its minimum $\widehat{a}$. Public and
private are not opposite sides of the same coin. Rather private assessment
allows agreement to vary, opening a new dimension of complexity to the
dynamics of reputation-based IR.

Our A-R-model allows one to study agreement and reputation in even more detail
than was reported within the results of this paper. We focused on the stable
states of the population. But one could study the direction and likelihood of
change in each state, as seen in figure 4 for the example of the staying
strategy (see also SI for other important strategies, such as image scoring
(Nowak and Sigmund, 1998a, ) and the leading-eight (Ohtsuki and Iwasa,,
2006)). One important insight this grants is about the stability of other
regions. For staying, there exist somewhat stable areas with reputations lower
than $r=0.3$ and minimal agreement. The existence of additional relatively
stable regions has large implications for the short-term behavior of the
population.

Seeing the direction of change in the entire space also allows us to make
educated guesses about another dynamic. The white line in the A-R-model of
figure 4 indicates a shift from reputation decrease (below) to reputation
increase (above). This highlights how the trend in reputation depends on the
state of agreement. It seems reasonable, that increasing agreement could
increase reputation as well. Increase in agreement could be done by a form of
opinion synchronization, for example by some players gossiping about their
observation or opinions to make other opinions fall into line with their own.
Hilbe et al., (2018) suggested that any IR strategy would profit of, or indeed
rely on, some sort of opinion synchronization to maintain stable cooperation
under private assessment. With the A-R-model, we can visualize which
strategies can actually profit from such mechanisms. Some are not affected,
e.g. image scoring, some actually show the opposite pattern, such as ”GKGB”
(Okada, 2020b, ), which seems only stable under private assessment, but not
under public one (see SI for examples). In the future, we can seek a way to
incorporate a probability for opinion synchronization in the A-R-model, to
predict new stable points under various synchronization regimes.

Related to that is a last alteration of the model. In the current
investigation, we considered private assessment in accordance with most
literature (Okada, 2020a, ). Every individual or player in the population
observes independently. But we can imagine a situation, where only a few
players observe, who then share their assessment with many others. Consider
for example the extreme case of a single observer that shares with the entire
population. This would correspond to public assessment (Ohtsuki and Iwasa,,
2004), where no disagreement is possible ($a=1$). In a more realistic
scenario, multiple observers are at least possible, and they may judge the
interaction differently due to individual errors or different previously held
opinions. The information of their judgments may also fail to reach some
players. In such scenarios, disagreement can exist. However, all players who
got the news from the same observer will most likely have the same opinion
(even if information transfer is noisy). It is a form of built-in opinion
synchronization. We can therefore expect agreement to be higher than in the
scenario of the current paper. The amount of agreement reported here might
only be the lower end for private assessment scenarios.

Lastly, we look at the reasons additional agreement emerges. As discussed
above, there can be no additional agreement if every player has the same
reputation. Additional agreement requires at least two groups exist (but up to
$N$-many), with different average reputations. Such groups can only emerge, if
players with the same strategy face different fates. For example, a donor of
strategy $\alpha=(1,-1,1,-1)$ and $\beta=(1,0)$ (image scoring) can get lucky
by meeting a recipient they believe to be good. Hence the donor cooperates and
earns a high reputation (everybody who observes, and does not make an error,
believes the donor to be good). But another donor with the same strategy might
get unlucky, because they believe the recipient to be bad. Hence they defect
and most observers will now think this donor is bad.

In general, groups can emerge if different onetime events cause different
expected reputations. Such onetime event are which recipient is met or which
decision is made. In the image scoring example, if errors happen with
probability $0.1$, we expect the reputation of a donor to be either $0.1$ if
they defected or $0.9$ if they cooperated. Different decisions as donor seem
indeed to be the most important factor for additional agreement. That is why
only conditional cooperators (Coco) show additional agreement, but
unconditional cooperators (AllC) or defectors (AllD) show none. Because some
Cocos cooperate and some defect, they can form groups with different
reputations and therefore have additional agreement.

Is additional agreement a good thing? Our results for strategies such as
staying show that it can increase reputations. The reputations studied here
correspond to how often a player finds another player of the same strategy
worth of cooperation (and Cocos also act on it). More agreement can increase
reputations, hence increase cooperation rates within the strategy, hence
increase the stability of that strategy. This could keep defectors at bay and
increase cooperation in general. Evolutionary investigations need to confirm
these assumptions, but in that regard, agreement might be a good thing.

However, we also showed another consequence of agreement. It is connected with
differences in reputations. Such differences inevitably lead to short-term
inequality between players. Over the long run, each player of the same
strategy will alternate between being lucky and being unlucky, so each will
earn the same pay-offs. But some players may earn much less than others if
only a few consecutive interactions are considered. This can be a problem, if
the game (or life) would require a player to earn a minimal amount to sustain
themselves. It may also be a problem if such inequality itself has bad
consequences for individuals or society.

Research on IR seems to continue to converge (Okada, 2020a, , Krellner and
Han,, 2022). However, there seem to be still a lot of potential to deepen our
understanding of the processes, as demonstrated in Fujimoto and Ohtsuki,
(2022) and the current paper. The understanding of agreement is central for
any analytical model of IR under private assessment. It is central in
understanding what benefits or problems that opinion synchronization or
different observation rates may bring. And it is as central to all research on
reputation-based IR under private assessment, since agreement can change
independently of reputation and can significantly alter the latter as well.
Our A-R-models provides the means to study the evolutionary dynamics of
indirect reciprocity under private assessment for yet the largest strategy
space and widest range of conditions.

## References

  * Brandt and Sigmund, (2004) Brandt, H. and Sigmund, K. (2004).  The logic of reprobation: Assessment and action rules for indirect reciprocation.  Journal of Theoretical Biology, 231(4):475–486.
  * Fujimoto and Ohtsuki, (2022) Fujimoto, Y. and Ohtsuki, H. (2022).  Reputation structure in indirect reciprocity under noisy and private assessment.  Scientific Reports, 12(1):1–13.
  * Hilbe et al., (2018) Hilbe, C., Schmid, L., Tkadlec, J., Chatterjee, K., and Nowak, M. A. (2018).  Indirect reciprocity with private, noisy, and incomplete information.  Proceedings of the National Academy of Sciences, page 201810565\.
  * Krellner and Han, (2020) Krellner, M. and Han, T. A. (2020).  Putting oneself in everybody’s shoes - Pleasing enables indirect reciprocity under private assessments.  In The 2020 Conference on Artificial Life, pages 402–410, Cambridge, MA. MIT Press.
  * Krellner and Han, (2021) Krellner, M. and Han, T. A. (2021).  Pleasing Enhances Indirect Reciprocity-Based Cooperation Under Private Assessment.  Artificial Life, pages 1–31.
  * Krellner and Han, (2022) Krellner, M. and Han, T. A. (2022).  The Last One Standing? - Recent Findings on the Feasibility of Indirect Reciprocity under Private Assessment.  In The 2022 Conference on Artificial Life, volume 1, Cambridge, MA. MIT Press.
  * Leimar and Hammerstein, (2001) Leimar, O. and Hammerstein, P. (2001).  Evolution of cooperation through indirect reciprocity.
  * (8) Nowak, M. A. and Sigmund, K. (1998a).  Evolution of indirect reciprocity by image scoring.  Nature, 393(6685):573–577.
  * (9) Nowak, M. A. and Sigmund, K. (1998b).  The dynamics of indirect reciprocity.  Journal of Theoretical Biology, 194(4):561–574.
  * Nowak and Sigmund, (2005) Nowak, M. A. and Sigmund, K. (2005).  Evolution of indirect reciprocity.  Nature, 437(7063):1291–1298.
  * Ohtsuki, (2004) Ohtsuki, H. (2004).  Reactive strategies in indirect reciprocity.  Journal of Theoretical Biology, 227(3):299–314.
  * Ohtsuki and Iwasa, (2004) Ohtsuki, H. and Iwasa, Y. (2004).  How should we define goodness? - Reputation dynamics in indirect reciprocity.  Journal of Theoretical Biology, 231(1):107–120.
  * Ohtsuki and Iwasa, (2006) Ohtsuki, H. and Iwasa, Y. (2006).  The leading eight: Social norms that can maintain cooperation by indirect reciprocity.  Journal of Theoretical Biology, 239(4):435–444.
  * (14) Okada, I. (2020a).  A Review of Theoretical Studies on Indirect Reciprocity.  Games, 11(3):27.
  * (15) Okada, I. (2020b).  Two ways to overcome the three social dilemmas of indirect reciprocity.  Scientific Reports, 10(1).
  * Okada et al., (2017) Okada, I., Sasaki, T., and Nakai, Y. (2017).  Tolerant indirect reciprocity can boost social welfare through solidarity with unconditional cooperators in private monitoring.  Scientific Reports, 7(1):9737.
  * Okada et al., (2018) Okada, I., Sasaki, T., and Nakai, Y. (2018).  A solution for private assessment in indirect reciprocity using solitary observation.  Journal of Theoretical Biology, 455:7–15.
  * Panchanathan and Boyd, (2003) Panchanathan, K. and Boyd, R. (2003).  A tale of two defectors: The importance of standing for evolution of indirect reciprocity.  Journal of Theoretical Biology, 224(1):115–126.
  * Perret et al., (2021) Perret, C., Krellner, M., and Han, T. A. (2021).  The evolution of moral rules in a model of indirect reciprocity with private assessment - DRAFT.  Scientific Reports, 11(1).
  * Rand and Nowak, (2013) Rand, D. G. and Nowak, M. A. (2013).  Human cooperation.  Trends in Cognitive Sciences, 17(8):413–425.
  * Santos et al., (2021) Santos, F. P., Pacheco, J. M., and Santos, F. C. (2021).  The complexity of human cooperation under indirect reciprocity.  Philosophical Transactions of the Royal Society B: Biological Sciences, 376(1838).
  * Sasaki et al., (2017) Sasaki, T., Okada, I., and Nakai, Y. (2017).  The evolution of conditional moral assessment in indirect reciprocity.  Scientific Reports, 7(1):41870.
  * (23) Schmid, L., Chatterjee, K., Hilbe, C., and Nowak, M. A. (2021a).  A unified framework of direct and indirect reciprocity.  Nature Human Behaviour, 5(10):1292–1302.
  * Schmid et al., (2022) Schmid, L., Hilbe, C., Chatterjee, K., and Nowak, M. A. (2022).  Direct reciprocity between individuals that use different strategy spaces.  PLOS Computational Biology, 18(6):e1010149.
  * (25) Schmid, L., Shati, P., Hilbe, C., and Chatterjee, K. (2021b).  The evolution of indirect reciprocity under action and assessment generosity.  Scientific Reports, 11(1):1–14.
  * Sigmund, (2016) Sigmund, K. (2016).  The calculus of selflessness.  Princeton University Press.
  * Sudgen, (1986) Sudgen, R. (1986).  The Economics of Rights, Cooperation and Welfare.  Basic Blackwell.
  * Uchida, (2010) Uchida, S. (2010).  Effect of private information on indirect reciprocity.  Physical Review E, 82(3):036111.
  * Uchida and Sasaki, (2013) Uchida, S. and Sasaki, T. (2013).  Effect of assessment error and private information on stern-judging in indirect reciprocity.  Chaos, Solitons & Fractals, 56:175–180.


# LLMs Still Can’t Avoid Instanceof: An Investigation Into GPT-3.5, GPT-4 and
Bard’s Capacity to Handle Object-Oriented Programming Assignments

Bruno Pereira Cipriano<EMAIL_ADDRESS>0000-0002-2017-7511 Lusófona
University, COPELABSCampo Grande, 376LisbonPortugal1700-097 and  Pedro Alves
0000-0003-4054-0792<EMAIL_ADDRESS>Lusófona University,
COPELABSCampo Grande, 376LisbonPortugal1700-097

(2024)

###### Abstract.

Large Language Models (LLMs) have emerged as promising tools to assist
students while solving programming assignments. However, object-oriented
programming (OOP), with its inherent complexity involving the identification
of entities, relationships, and responsibilities, is not yet mastered by these
tools. Contrary to introductory programming exercises, there exists a research
gap with regard to the behavior of LLMs in OOP contexts. In this study, we
experimented with three prominent LLMs - GPT-3.5, GPT-4, and Bard - to solve
real-world OOP exercises used in educational settings, subsequently validating
their solutions using an Automatic Assessment Tool (AAT). The findings
revealed that while the models frequently achieved mostly working solutions to
the exercises, they often overlooked the best practices of OOP. GPT-4 stood
out as the most proficient, followed by GPT-3.5, with Bard trailing last. We
advocate for a renewed emphasis on code quality when employing these models
and explore the potential of pairing LLMs with AATs in pedagogical settings.
In conclusion, while GPT-4 showcases promise, the deployment of these models
in OOP education still mandates supervision.

programming assignments, teaching, object-oriented programming, object-
oriented design, OOP best practices, large language models, gpt-3, gpt-4, bard

††journalyear: 2024††copyright: rightsretained††conference: 46th International
Conference on Software Engineering: : Software Engineering Education and
Training; April 14–20, 2024; Lisbon, Portugal††booktitle: 46th International
Conference on Software Engineering: : Software Engineering Education and
Training (ICSE-SEET ’24), April 14–20, 2024, Lisbon, Portugal††doi:
10.1145/3639474.3640052††isbn: 979-8-4007-0498-7/24/04††ccs: Applied computing
Computer-assisted instruction

##  1\. Introduction

In the last few years, researchers introduced us to Large Language Models
(LLMs), which are tools that can predict the next word in a sequence, after
being trained on large amounts of data, and taking into consideration a large
number of parameters. Popular implementations of LLMs are ChatGPT, a chatbot
developed by OpenAI on top of their Generative Pre-trained Model (GPT), and
GitHub Copilot111https://github.com/features/copilot, a developer support tool
that can generate code from annotations and is also based on GPT.

As CS educators, we are interested in determining how these tools can be used
to support students in their programming learning process, both inside and
outside of the classroom. We are specifically interested in the possibilities
of using these tools for teaching and learning object-oriented design and
programming.

Previous research has shown that LLMs have the capacity to generate computer
program code from natural language descriptions (Xu et al., 2022).
Furthermore, GPT-based models, such as Codex, have been shown to be able to
solve most types of exercises that are used in introductory programming
classes (Finnie-Ansley et al., 2022). Additionally, researchers have reported
that GPT-3.5 can handle object-oriented programming assignments, managing to
reach decent to good scores, with the caveat that the generated code is not
up-to-par with the industry’s best practices of that paradigm (Cipriano and
Alves, 2023a).

However, both the availability and the capabilities of these tools are
increasing rapidly. Updated models, such as GPT-4222Launched on March 14,
2023, promise even better performance than their older versions (OpenAI, 2023;
Bubeck et al., 2023), while new tools, such as Bard333Launched in the US & UK
on Mar 21, 2023; in EU & Brazil on Jul 13, 2023., a chatbot developed by
Google on top of their Language Model for Dialogue Applications (LaMDA)
(Sundar, 2023; Thoppilan et al., 2022), are becoming available to the general
public. These new models justify performing further research on these topics,
to confirm and/or update the findings that resulted from the previous works.

Thus, we decided to explore these newer tools to learn their capabilities and
limitations, as well as identify opportunities to integrate them into our
courses, similarly to what is being done by other instructors (Lau and Guo,
2023; Denny et al., 2023; Daun and Brings, 2023; Leinonen et al., 2023;
Liffiton et al., 2023).

As such, we performed an evaluation of some of the most recently available
LLMs, GPT-4, and Bard, following previous research focused on object-oriented
design, programming and best-practices using GPT-3.5 (Cipriano and Alves,
2023a). This evaluation was based on assignments that are automatically graded
by an Automatic Assessment Tool (AAT).

This paper makes the following contributions:

  * •

Presents and compares the performance (as measured by an AAT) of GPT-3.5,
GPT-4, and Bard using 6 real-world assignments that have been used to grade
students in an Object-Oriented Programming university course;

  * •

Identifies and categorizes the errors found in the code generated by the
tested LLMs;

  * •

Provides full logs of the interactions used to get each model to solve one of
the assignments, in an annotated prompt/reply format;

  * •

Presents a set of recommendations for CS Educators wishing to adapt their
classes to the availability of these technologies.

##  2\. Related work

In the last couple of years, a relevant body of research related with
measuring LLMs’ ability to handle introductory programming exercises has been
published (Chen et al., 2021; Finnie-Ansley et al., 2022, 2023; OpenAI, 2023;
Reeves et al., 2023; Wermelinger, 2023; Destefanis et al., 2023). Those
introductory exercises are usually solved with a single function that receives
a set of parameters and transforms them into an expected output. For example,
in (Chen et al., 2021), researchers managed to solve 70% of 164 Python
programming exercises using code generated by Codex, a GPT-based language
model trained on code publicly available in GitHub. In (Finnie-Ansley et al.,
2022), Codex was evaluated using 23 introductory programming assignments, and
managed to make the 17th position when ranked alongside 71 students. The
authors of (Reeves et al., 2023) focused on Codex’s capacity to handle Python-
based Parsons problems (Parsons and Haden, 2006) and revealed that the model
solved 50% of the cases when indentation errors were considered, and 80% when
those errors were ignored. Finally, a study (Destefanis et al., 2023) based on
single-function Java exercises from CodingBat444https://codingbat.com,
reported that GPT-3.5 solved 90.6% of the functions, while Bard solved 53.1%.

Some papers have also delved into GPT’s capacity to handle OOP assignments,
which typically require the implementation of multiple classes that interact
with each other and have mutable states. In one of these studies (Savelka et
al., 2023b), researchers assessed the performance of two GPT-3.5 models
(“text-davinci-002” and “text-davinci-003”) on various introductory and
intermediate Python programming exercises. Some of the intermediate exercises
involved OOP, and the models’ solutions were evaluated using an AAT. The first
model achieved a success rate of 52.9% in the tests, while the second model
scored 70.6%. However, due to the unavailability of the exercise statements,
we could not ascertain whether the type of OOP exercises was equivalent to
those presented in this research paper. The same authors have updated their
research by performing the evaluations using GPT-4, which reached an improved
score of 82.4% (Savelka et al., 2023a). In another study (Ouh et al., 2023),
researchers attempted to utilize ChatGPT (versions 3.5 and 4) for solving OOP
exercises. Some of these exercises involved introductory-level object usage
without inheritance or polymorphism, and the chatbot managed to provide
partially correct solutions. Other exercises introduced inheritance, but a UML
class diagram with the solution was provided to the students, who only had to
implement the corresponding code. As it was not feasible to supply the UML
diagram to the model, the generated solution remained incomplete. Despite
encompassing OOP exercises, this study’s tasks are either very elementary or
highly guided. Another study (Cai et al., 2023), proposed the utilization of
LLMs as low-code tools. While directly using ChatGPT led to solutions with
weak object-oriented design, they were able to achieve good results by pre-
guiding the model on OOP best practices. Finally, the authors of (Cipriano and
Alves, 2023a), evaluated GPT-3.5 (“text-davinci-003”) using both functional as
well as code quality criteria and found that, although GPT-3.5 was able to
pass an average of 77.63% of unit tests, it only passed an average of 50% of
the code quality evaluations.

As far as we know, no research focused on Bard’s (or LaMDA’s) ability to
handle object-oriented assignments has been published.

##  3\. The assignments

This research was based on assignments used for student evaluation in a
Computer Engineering degree. The course occurs on the 2nd curricular year of
the degree and focus mostly on teaching Object-Oriented Design and Programming
using the Java programming language. In this course, students are expected to
learn how to implement object-oriented software solutions following the
paradigm’s best practices (Wegner, 1990), with a strong focus on issues like
code readability, modularity and extensibility. For example, students are
expected to understand the drawbacks of using type testing, such as those
permitted by ‘instanceof’, to decide program behaviors, since that technique
tends to make programs harder to modify.

The course’s assignments (e.g., tests and projects, among others) are
evaluated using an open-source AAT, called Drop Project (Cipriano et al.,
2022). It evaluates if the student’s code is respecting the assignment’s
requirements using teacher-defined unit tests. It is also capable of verifying
if the student’s code follows the expected code quality rules and guidelines.
In this course, some assignments are configured to warn the teacher about the
use of certain keywords that allow the program to work while disregarding some
of the aforementioned best practices. An example of this is the usage of the
‘instanceof’ keyword or the ‘getClass()’ function. Due to the limitations of
the plugin used by the AAT for the code quality validations (Checkstyle
(Ivanov et al., 2023)), some quality validations are implemented using unit
tests. A case in point is verifying whether a certain class has been declared
as abstract.

To evaluate the LLMs, a set of assignments that have been used in this course
as mini-tests focused on inheritance and polymorphism was used. Each
assignment has a different business domain, as well as different requirements.
All the assignments have the following goals: identify and implement entity
relationships (both composition and inheritance), implement some getters and
setters, implement a non-trivial ‘toString()’ function, and, implement some
functions that have to create, query and/or manipulate objects of several
classes. Note that the relationships aren’t directly provided to students, who
must infer which classes are the super and sub-classes. This approach sets our
study apart from others where assignments give more explicit directions (Ouh
et al., 2023).

⬇

We want to implement a software to help an IT company that provides
ITConsultant services with the management of their employees. In this
challenge, there exist two types of employees: those who pertain to the human
resources management area (HRWorker), and the IT (information technology)
experts, who pertain to ITConsultant.

The classes Employee, HRWorker and ITConsultant must be created (...) however
it should not be possible to instantiate an object using the super class’s
constructor.

A company is characterized by its name. A company can have multiple employees,
but each employee only the belongs to a single company.

A employee is identified by its id (int), name (String) and monthly salary
(int).

(...)

Add, to the appropriate classes, the following methods:

- A public int getId() method, which returns the employee’s ID.

- A public int getSalary() method, which returns the employee’s salary.

- A public int getValue() method, which returns the IT consultant’s hourly rate.

(...)

(Within the Company class) add a public String toString() method, which must
be implemented to return the following:

- "The company <name> does not have employees." - if the company does not have any employee;

- "The company <name> has <number_employees> employees:" - if the company has at least one employee. Besides that, the information for each employee should be display, considering the respective type.

Listing 1: Partial instructions for the ITCompany assignment

Moreover, each assignment has behaviors based on the object type to assess
whether students can devise solutions without resorting to explicit type
checks like those allowed by the ‘instanceof’ keyword and ‘getClass()’
function. Finally, in some cases, we ask for the student ID to be used as the
value of an object’s attribute, to guarantee unique solutions among students.

Listing 1 presents a partial example of an assignment’s text.

Six such assignments were used in this study. The selected assignments were
originally used to grade students in different school years (2018/19, 2021/22,
and 2022/23).

##  4\. Methodology

To interface with GPT-3.5, openAI’s Playground555available at
https://platform.openai.com/playground (free account) was used. The selected
model was “text-davinci-003”. The “temperature” parameter, which controls
randomness, was left at the default value of 0.7, and the “maximum length”
parameter was left at the default of 256. GPT-4 was studied using OpenAI’s
ChatGPT Plus666available at https://chat.openai.com/ (paid account). Finally,
to study Bard, we used the respective chat interface 777available at
https://bard.google.com/. Note that neither ChatGPT Plus nor Bard allows
changing the models’ parameters. The experiments were done in different time
periods, since we did them when the models became available to us: the
original experiment with GPT-3.5 was done in December 2022, the experiment
with GPT-4 was done in May 2023, and finally, the experiment with Bard was
done in July 2023. To evaluate the models’ output, version 0.9.7 of the Drop
Project AAT was used.

For each model and assignment, the following algorithm was performed:

  1. (1)

paste the assignment’s text into the LLM’s text input area

  2. (2)

submit it

  3. (3)

examine the output to determine whether all the mandatory classes and
functions are present

    1. (a)

if they are, move to step 4

    2. (b)

otherwise, prompt for the missing code and repeat step 3

  4. (4)

inspect the code for syntactic, logic, and output format errors

  5. (5)

manually fix any syntactic / compilation errors

  6. (6)

submit the LLM’s generated code to the AAT

  7. (7)

analyze the AAT’s output

##  5\. It works but it’s not OO - how LLM(s) tried to solve the IT Company
assignment

Figure 1. Simplified UML class diagram for the “IT Company” assignment,
excluding non-essential attributes, methods, and constructors. Students only
receive textual instructions, not this diagram.

This section presents a high level overview of our attempts to use each model
to solve one of the 6 assignments: the “IT Company” assignment. In this
assignment, students are expected to design the object model of an IT Company
with the following concepts: ‘Company’, ‘Employee’, ‘ITConsultant’, and
‘HRWorker’. The concepts and their attributes are explained to the students by
text. However, the text does not explicitly indicate the relations that exist
between the classes: it is up to the student to infer that there exists a
composition relationship — between the ‘Company’ and the ‘Employee’ classes —,
and an inheritance relationship where the ‘Employee’ class is the super-class
and the ‘ITConsultant’ and ‘HRWorker’ classes are the sub-classes. Students
are also expected to understand that the ‘Employee’ class should be abstract,
since the text mentions that it must not be possible to instantiate that
class. Finally, students must implement several mandatory functions,
identifying the class of the hierarchy where each function belongs. For
example, there is an attribute that only makes sense for the ‘ITConsultant’
class: the hourly rate. As such, only that class should have that attribute
and the respective getter, which must be called ‘getValue()’. Also mandatory
is the creation of a function called ‘getEmployeeHighestHourlyRate()‘ in the
‘Company’ class. This function must return the ‘Employee’ with the highest
hourly rate. However, since the hourly rate concept only applies to the
‘ITConsultant’ class, the student must find the proper Object-Oriented design
to implement this challenge. As such, if a student uses ‘instanceof’ or
‘getClass()’, a penalty will be applied to the respective grade. Figure 1
presents an overview of this assignment’s required classes, as well as the
most relevant design expectations. Listing 1 presents part of this
assignment’s instructions. A full version of the assignment, including both
instructions as well as unit tests is available
online.888https://github.com/drop-project-edu/itCompanyAssignment Refer to
(Anonymous, 2023) for full logs of these interactions.

###  5.1. Main analysis

GPT-3.5 required 18 interactions to generate a solution that included all
mandatory elements. Issues found in that solution:

  * •

Function ‘getEmployeeHighestHourlyRate()’ uses ‘instanceof’.

  * •

Fails 1 test because the ‘Employee’ class is not abstract.

  * •

Fails 2 tests because the package name was incorrectly included in
‘ITConsultant.toString()’ function’s return value.

  * •

Fails the test for the ‘Main.myCompany()’ function due to using an uninformed
number in the solution.999This problem was expected, since we did not input
the student ID to the models.

  * •

Failed to import the ‘ArrayList’ class.

Bard required 11 interactions to generate a solution that included all
mandatory elements. Issues found in that solution:

  * •

Function ‘getEmployeeHighestHourlyRate()’ uses ‘instanceof’.

  * •

Fails 1 test because the ‘Employee’ class is not abstract.

  * •

Fails 2 tests due to incorrect usage of the downcast operator in the
‘getEmployeeHighestHourlyRate()’.

  * •

Fails 2 tests due to not respecting the expected format of the
‘HRWorker.toString()’ and ‘Company.toString()’ functions.

  * •

Fails the same test related to the ‘Main.myCompany()’ function that the other
models failed, with a difference in the implementation: instead of guessing a
number, Bard’s code attempts to obtain the student ID by using
‘System.getEnv()’, resulting in a ‘NullPointerException’.101010See footnote 9

  * •

Failed to import the ‘ArrayList’ class.

  * •

Declared 3 attributes of the ‘Employee’ class as private, and tried to access
them directly in the ‘ITConsultant’ sub-class.

GPT-4 required 4 interactions to generate a solution that included all
mandatory elements. Issues found in that solution:

  * •

Function ‘getEmployeeHighestHourlyRate()’ uses ‘instanceof’.

  * •

Fails 1 unit test because it did not fully respect the format of the
‘Company.toString()’ function (a new line was missing).

  * •

Fails the test related to the ‘Main.myCompany()’ function due to using an
uninformed number in the code.111111See footnote 9

In summary… These experiments show that these 3 LLMs were able to partially
solve the ‘IT Company’ assignment, although with some errors, both in terms of
basic syntax (e.g. missing library importations), as well as more complex
object-oriented programming errors (e.g. not declaring a class as abstract, or
using explicit type testing to decide program behaviors). This is similar to
what happened in the other 5 assignments, as described in Section 6.

###  5.2. Attempts to improve the LLM(s)’ solutions

After obtaining each model’s solutions for the “IT Company” assignment and
verifying that all of them were breaking one of our code quality rules — the
restriction not to use ‘instanceof’ —, we attempted to guide the models toward
better solutions, similar to how we expect a student would do after seeing the
AAT’s feedback, and to get a better grade. Note that these extra prompts are
not part of our main methodology and are not represented in Table 1.

These attempts to improve the models’ solutions were done using an ad-hoc
methodology where we identified problems with each model’s solution, and
attempted to give it a direct indication of the problem, to see what it would
do. The first extra prompt was the same for all models: ‘Change the code to
not use instanceof’. Afterward, we re-prompted based on what each model gave
us. The prompts for GPT-3.5 and Bard ended up being similar because the
respective intermediate solutions had similar problems from the object-
oriented perspective: they both were assuming that all sub-classes of
‘Employee’ have the ‘getValue()’ function, which is not coherent with the rest
of the respective solutions.

Besides the initial extra prompt, GPT-3.5 required two more prompts to reach
an acceptable solution: as a reply to the third prompt, it suggested adding
the ‘getValue()’ function to both the super-class and the sub-class with an
implementation that would return 0. In this case, 0 is being used as a flag to
indicate that the object should be ignored, which is coherent with the model’s
implementation of ‘getEmployeeHighestHourlyRate()’. Although that solution is
more OO, it is somewhat risky: such a design would be problematic if a
function ‘getEmployeeLowestHourlyRate()’ is needed at some point in the
future.

Bard had a behavior similar to that of GPT-3.5, although it required a fourth
prompt to reach a solution acceptable from the OOP perspective. Bard’s fourth
solution was equivalent to GPT-3.5’s third solution, thus having the
equivalent problems. Note that, although the OO solution is acceptable, Bard
implemented the ‘getValue()’ function incorrectly: it is returning the value
of the salary instead of the value of the hourly rate. Since we were focused
on getting Bard to solve the OO issue, we ignored this implementation detail.

Finally, GPT-4 only needed the extra initial prompt to reach an acceptable OO
solution. The model suggested adding an abstract version of ‘getHourlyRate()’
to the ‘Employee’ class, as well as adding a concrete version of that function
(returning -1, which is much safer than returning 0) to the ‘HRWorker’ class.
It also gave us the code for those changes, as well as a version of the
‘getEmployeeHighestHourlyRate()’ function that only considers objects for
which ‘getValue()’ returns more than 0.

In summary… Our experiments show that it was possible and easy to guide GPT-4
towards a fully working solution that respects the object-oriented best
practice of avoiding explicit type testing. Also, while the other models also
managed to reach acceptable, although risky, OO solutions, they required more
effort (GPT-3.5: 3 prompts; Bard: 4 prompts) and generated some minor errors
(e.g. Bard’s incorrect return of the salary attribute in the ‘getValue()’
function). This extra effort is coherent with the findings from other
researchers (Wermelinger, 2023).

##  6\. Overall Findings

This section presents the 3 models’ performances across the 6 assignments. As
Table 1 shows, all models needed multiple prompts and no model passed all the
tests.

GPT-4 generally had the best performance, requiring fewer interactions than
the other models, generating fewer compilation errors and, in general, having
better results in the unit tests. Bard always had equal or worse unit test
results than GPT-3.5, except in the “Home Banking” assignment, where it
surpassed both GPT models.

In terms of the Code Quality validation, we observed that GPT-4 yields the
best results: while GPT-3.5 and Bard respected the code quality rules in 3 out
of the 6 assignments, GPT-4 did it in 4 out of 6 assignments. Listing 2 shows
an example of the type of code that these models tend to generate: it (mostly)
works, but tends to decide behaviors using explicit type testing, via
‘instanceof’ and/or ‘getClass()’ . In summary, similarly to what previous
research found for GPT-3.5 (Cipriano and Alves, 2023a), the two newer models
still can’t avoid using ‘instanceof’.

It should be noted that, in the “Condominium Mgt.” assignment, GPT-4 managed
to pass the code quality, as well as 13/14 tests. Considering that the single
test failure was expected121212See footnote 9, we can consider that GPT
successfully solved one of the OOP assignments.

Table 1. Evaluation of the 3 models’ solutions for each assignment. G-3.5 is GPT-3.5. The values are related to the first solution that contained all mandatory classes and functions. For example, GPT-3.5 needed 5 prompts to generate all classes and functions for the first assignment, that solution had 4 compilation errors, the code quality failed and it passed 8/13 unit tests. | Nr. of prompts | Nr. of Compilation errors | Code quality Ok? | Tests passed
---|---|---|---|---
Assignment | G-3.5 | GPT-4 | Bard | G-3.5 | GPT-4 | Bard | G-3.5 | GPT-4 | Bard | G-3.5 | GPT-4 | Bard
Realtor Agency | 5 | 2 | 2 | 4 | 0 | 8 | No | Yes | Yes |  | 8/13
---
(61.54%)
| 12/13
---
(92.31%)
| 7/13
---
(53.85%)
IT Company | 18 | 4 | 11 | 1 | 0 | 4 | No | No | No |  | 9/13
---
(69.23%)
| 11/13
---
(84.62%)
| 7/13
---
(53.85%)
Home Banking | 7 | 2 | 10 | 1 | 0 | 14 | Yes | Yes | Yes |  | 7/13
---
(53.85%)
| 7/13
---
(53.85%)
| 9/13
---
(69.23%)
Condominium Mgt. | 5 | 2 | 5 | 12 | 0 | 3 | Yes | Yes | Yes |  | 11/14
---
(78.57%)
| 13/14
---
(92.86%)
| 10/14
---
(71.43%)
Home Cinema A/V | 5 | 2 | 6 | 3 | 0 | 2 | Yes | Yes | No |  | 8/10
---
(80%)
| 9/10
---
(90%)
| 8/10
---
(80%)
Railway Co. Vehicles | 11 | 6 | 8 | 4 | 3 | 10 | No | No | No |  | 11/16
---
(68.75%)
| 12/16
---
(75%)
| 10/16
---
(62.5%)
Average | 8,5 | 3 | 7 | 4,17 | 0,5 | 6,83 | 50% | 66.67% | 50% | 68,66% | 81,44% | 65,14%
Listing 2: A function generated by Bard for the “Condominium Mgt.” assignment
that fails our Code Quality validations. Besides using explicit type-testing
(i.e. uses instanceof) Bard also failed to implement the proper business rules
since the formula for the ‘Garage’ should multiply the area by 3 instead of 4
(see line 3).

⬇

1public int calculateCondominiumPayment() {

2 int value = baseValue;

3 value += area * 4;

4 if (this instanceof Apartment) {

5 value += ((Apartment) this).getFloorNumber() * 3;

6 value += ((Apartment) this).getNrRooms() * 2;

7 }

8 else if (this instanceof Store) {

9 value += ((Store) this).getNrFronts() * 2;

10 value += ((Store) this).getNrDoors() * 2;

11 }

12 else if (this instanceof Garage) {

13 value += Math.abs(((Garage) this).getNrFloor()) * 2;

14 }

15 return value;

16}

###  6.1. Problem categorization

This section presents a brief categorization of the problems observed across
assignments and models. After each problem, we indicate which models displayed
it at least in one assignment.

Issues related with syntax

  * •

Failed to include library imports. [GPT-3.5, Bard]

  * •

Created minor compilation errors (e.g. missing “}”). [GPT-3.5, Bard]

  * •

Failed to declare a required package. [GPT-3.5]

  * •

Generated incoherent code (e.g. called a function with less arguments than it
receives). [Bard]

Issues related with OOP concepts

  * •

Used instanceof or getClass() to decide program behaviours. [all]

  * •

Failed to declare a class as abstract. [all]

  * •

Failed to correctly identify and implement business rules. [all]

  * •

Did not respect the ‘toString()’ function’s required format. [all]

  * •

Failed to apply inheritance best practices. [all]

  * •

Suggested solutions with code duplication. [all]

  * •

Accessed a super-class’s private fields from its sub-classes. [GPT-3.5, Bard]

  * •

Declared constructors with problems (e.g. added extra arguments). [GPT-3.5]

  * •

Failed to properly apply the downcast operator. [Bard]

  * •

Declared abstract methods in the super-class but failed to implement them in
the sub-classes. [GPT-4]

##  7\. Recommendations for CS Educators

Students are likely to misuse tools like GPT-3.5 and Bard, which offer decent-
to-good OOP code generation for free. Superior models like GPT-4 are currently
available at a cost. With the evident progress from GPT-3.5 to GPT-4, observed
both in other research (Savelka et al., 2023a) as well as in our study, we
believe that educators should adapt to this emerging landscape.

###  7.1. Give more weight to code quality evaluations

For educators focusing on object-oriented programming, given our observations,
as well as previous research (Keuning et al., 2023), we recommend putting more
weight on evaluating items such as code quality, design patterns and other
similar aspects. The course’s focus should change from just producing
“functional code” to producing “functional and high-quality code”. The
assessment work can be scaled using an AAT with the capacity to evaluate
functional and quality requirements.

###  7.2. Use LLMs in your classes

Consider embracing LLMs in your classes. One option is the adoption of in-
class exercises where students have to 1) interact with LLMs to generate code,
and then, 2) evaluate the respective solutions. This process would be
supervised by the teacher, who would help the students analyze and critique
the LLMs’ output. This has the advantage of showing students that these models
should not be trusted blindly, and that they should inspect and test the
generated code, possibly improving their critical thinking, similarly to other
mistake-finding exercises (Naumova, 2023). This exercise can be enhanced by
having students validate their findings through an AAT using teacher-defined
tests or by creating their own unit tests.

###  7.3. Adopt project-based learning

If you currently rely solely on using small assignments for assessments, we
recommend that you consider including also project-based evaluations. Projects
will require more complex code and interactions to be implemented, which will
possibly require more complex interactions with the LLMs to obtain a fully
working solution that respects the object-oriented best practices. The
projects can be incremental, in order to allow students to grow and apply
their knowledge incrementally. For example: consider having a first project
delivery where the students do not need to use inheritance, followed by
another delivery where inheritance is needed, followed by another delivery
where some of the requirements change, and so on. Although LLMs’ performance
over larger assignments has not yet been measured, there are known benefits to
project-based learning (Mills et al., 2003; Shin, 2018).

##  8\. On the importance of citing your sources

One of the interesting features of Bard is its ability to display sources for
parts of the generated content. In the case of the “IT Company” assignment,
Bard displayed a single source: a GitHub repository with a Java
course.131313https:github.com/camilaabrantes/CursoJava

We performed a brief analysis of the repository and found some OOP examples
that are incorrect. For example, the repository contains a class called
‘Product’ with a ‘getPrice()’ method, which is extended by the sub-class
‘ImportedProduct’ that redefines the price calculation formula to take into
account a customs fee. Instead of overriding the ‘getPrice()’,
‘ImportedProduct’ declares a new method ‘totalPrice()’. This is clearly wrong,
in light of OOP best practices.

Although we are unsure of how much of this repository actually contributed to
Bard’s reply, we suspect that it is the use of data sources that have not been
curated that results in the generation of code that does not follow the OOP
best practices.

Note that GPT-3.5 and GPT-4 do not disclose any information regarding their
sources. Since the only publicly available information are high-level
descriptions of the training datasets (e.g. a filtered version of Common Crawl
141414https://commoncrawl.org/the-data, English Wikipedia, among others)
(Brown et al., 2020), it was not possible to perform this analysis for those
models.

##  9\. Limitations

The 3 experiments were done using different interaction interfaces. This may
have some kind of impact on the model’s replies, namely in terms of the number
of prompts required to obtain a solution.

These models’ output is not deterministic: repeating the experiments for each
assignment might have led us to different results.

We did not employ any Prompt Engineering (PE) techniques. The models were
initially inputted with the original assignments’ text. The prompts used to
obtain missing elements or to guide the models’ toward better solutions
consisted of very literal and direct requests. It is possible that the models
would have given better if some PE techniques were applied.

##  10\. Conclusions and Future Work

In this work, we present the performance of 3 LLMs when solving several OOP
assignments.

From our observations, GPT-4 demonstrated better performance than GPT-3.5,
needing fewer interactions and producing code with fewer issues. Additionally,
GPT-4 consistently passed more unit tests than GPT-3.5. In comparison, Bard
lagged behind both GPT versions in number of issues, passed tests, and the
number of interactions needed to guide it toward a reasonable solution.

If the 3 models were students, we would say that GPT-3.5 is a student that has
learned the basics of programming but struggles with object-oriented design
and programming concepts; GPT-4 is a more experienced student who, with
minimal guidance, is able to achieve good solutions; and Bard is a student of
a level slightly below GPT-3.5, with less autonomy than the others and more
issues with basic programming elements. In the end, all these students
struggled somehow and made some mistakes.

But can we blame students for making mistakes when they had a bad teacher?
Perhaps the challenges encountered by LLMs in adhering to OOP best practices
are not due to inherent reasoning limitations often associated with this
technology but rather attributed to suboptimal choices in their information
resources. We have verified the poor quality of the source referenced by Bard,
and while GPT-3.5 and GPT-4 do not disclose their sources, it is plausible
that they too might have relied on inadequate references. The significance of
LLMs disclosing their sources, and the more general issue of explaining their
reasoning has been a topic of repeated discussion (Arrieta et al., 2020). We
not only endorse such explanations but also emphasize the necessity of
curating high quality sources for training these models.

As for future work, we plan to investigate how these models handle larger OOP
assignments (e.g. 10-15 classes) following our recommendation to switch to
project-based learning. We also plan on experimenting new ways of presenting
OOP exercises to the students, with the goal of creating barriers to naive
‘copy-and-prompt’ approaches. One of the possible approaches is the creation
of diagram-based and video-based assignments.

##  11\. Data Availability

Since this work is based on real assignments that we use for student
assessment in our course, publishing the full assignment and/or interactions
dataset would require us to fully recreate all the assignments, ensuring we
use unpublished materials when evaluating our students. As such, we have
decided to release just one of the assignments: the IT Company Assignment.
This was achieved by creating the respective GitHub repository
151515https://github.com/drop-project-edu/itCompanyAssignment, as well as
publishing the respective interaction logs, for each LLM, in Zenodo (Cipriano
and Alves, 2023b).

###### Acknowledgements.

This research was funded by the Fundação para a Ciência e a Tecnologia under
Grant No.: UIDB/04111/2020 (COPELABS).

## References

  * (1)
  * Anonymous (2023) Anonymous. 2023\.  How GPT-3.5, GPT-4 and Bard handled an Object Oriented Programming Assignment - Full Interaction Logs.  https://doi.org/10.5281/zenodo.8246165 This is the anonymized version to support peer review.
  * Arrieta et al. (2020) Alejandro Barredo Arrieta, Natalia Díaz-Rodríguez, Javier Del Ser, Adrien Bennetot, Siham Tabik, Alberto Barbado, Salvador García, Sergio Gil-López, Daniel Molina, Richard Benjamins, et al. 2020\.  Explainable Artificial Intelligence (XAI): Concepts, taxonomies, opportunities and challenges toward responsible AI.  _Information fusion_ 58 (2020), 82–115.
  * Brown et al. (2020) Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. 2020\.  Language Models are Few-Shot Learners.  _Advances in neural information processing systems_ 33 (2020), 1877–1901.
  * Bubeck et al. (2023) Sébastien Bubeck, Varun Chandrasekaran, Ronen Eldan, Johannes Gehrke, Eric Horvitz, Ece Kamar, Peter Lee, Yin Tat Lee, Yuanzhi Li, Scott Lundberg, et al. 2023\.  Sparks of Artificial General Intelligence: Early experiments with GPT-4.  _arXiv preprint arXiv:2303.12712_ (2023).
  * Cai et al. (2023) Yuzhe Cai, Shaoguang Mao, Wenshan Wu, Zehua Wang, Yaobo Liang, Tao Ge, Chenfei Wu, Wang You, Ting Song, Yan Xia, et al. 2023\.  Low-code LLM: Visual Programming over LLMs.  _arXiv preprint arXiv:2304.08103_ (2023).
  * Chen et al. (2021) Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde de Oliveira Pinto, Jared Kaplan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, et al. 2021\.  Evaluating Large Language Models Trained on Code.  _arXiv preprint arXiv:2107.03374_ (2021).
  * Cipriano and Alves (2023a) Bruno Pereira Cipriano and Pedro Alves. 2023a.  GPT-3 vs Object Oriented Programming Assignments: An Experience Report. In _Proceedings of the 2023 Conference on Innovation and Technology in Computer Science Education V. 1_ (Turku, Finland) _(ITiCSE 2023)_. Association for Computing Machinery, New York, NY, USA, 61–67.  https://doi.org/10.1145/3587102.3588814
  * Cipriano and Alves (2023b) Bruno Pereira Cipriano and Pedro Alves. 2023b.  How GPT-3.5, GPT-4 and Bard handled an Object Oriented Programming Assignment - Full Interaction Logs.  https://doi.org/10.5281/zenodo.8246165
  * Cipriano et al. (2022) Bruno Pereira Cipriano, Nuno Fachada, and Pedro Alves. 2022\.  Drop Project: An automatic assessment tool for programming assignments.  _SoftwareX_ 18 (2022), 101079.
  * Daun and Brings (2023) Marian Daun and Jennifer Brings. 2023.  How ChatGPT Will Change Software Engineering Education. In _Proceedings of the 2023 Conference on Innovation and Technology in Computer Science Education V. 1_. 110–116.
  * Denny et al. (2023) Paul Denny, Juho Leinonen, James Prather, Andrew Luxton-Reilly, Thezyrie Amarouche, Brett A Becker, and Brent N Reeves. 2023\.  Promptly: Using Prompt Problems to Teach Learners How to Effectively Utilize AI Code Generators.  _arXiv preprint arXiv:2307.16364_ (2023).
  * Destefanis et al. (2023) Giuseppe Destefanis, Silvia Bartolucci, and Marco Ortu. 2023\.  A Preliminary Analysis on the Code Generation Capabilities of GPT-3.5 and Bard AI Models for Java Functions.  _arXiv preprint arXiv:2305.09402_ (2023).
  * Finnie-Ansley et al. (2022) James Finnie-Ansley, Paul Denny, Brett A Becker, Andrew Luxton-Reilly, and James Prather. 2022\.  The Robots Are Coming: Exploring the Implications of OpenAI Codex on Introductory Programming. In _Proceedings of the 24th Australasian Computing Education Conference_. 10–19.
  * Finnie-Ansley et al. (2023) James Finnie-Ansley, Paul Denny, Andrew Luxton-Reilly, Eddie Antonio Santos, James Prather, and Brett A Becker. 2023.  My AI Wants to Know if This Will Be on the Exam: Testing OpenAI’s Codex on CS2 Programming Exercises. In _Proceedings of the 25th Australasian Computing Education Conference_. 97–104.
  * Ivanov et al. (2023) Roman Ivanov et al. 2023\.  Checkstyle.  https://checkstyle.org/.  [Online; last accessed 20-January-2023].
  * Keuning et al. (2023) Hieke Keuning, Johan Jeuring, and Bastiaan Heeren. 2023\.  A Systematic Mapping Study of Code Quality in Education. In _Proceedings of the 2023 Conference on Innovation and Technology in Computer Science Education V. 1_. 5–11.
  * Lau and Guo (2023) Sam Lau and Philip J Guo. 2023.  From” Ban It Till We Understand It” to” Resistance is Futile”: How University Programming Instructors Plan to Adapt as More Students Use AI Code Generation and Explanation Tools such as ChatGPT and GitHub Copilot.  (2023).
  * Leinonen et al. (2023) Juho Leinonen, Paul Denny, Stephen MacNeil, Sami Sarsa, Seth Bernstein, Joanne Kim, Andrew Tran, and Arto Hellas. 2023\.  Comparing Code Explanations Created by Students and Large Language Models.  _arXiv preprint arXiv:2304.03938_ (2023).
  * Liffiton et al. (2023) Mark Liffiton, Brad Sheese, Jaromir Savelka, and Paul Denny. 2023.  CodeHelp: Using Large Language Models with Guardrails for Scalable Support in Programming Classes.  _arXiv preprint arXiv:2308.06921_ (2023).
  * Mills et al. (2003) Julie E Mills, David F Treagust, et al. 2003\.  Engineering education—Is problem-based or project-based learning the answer.  _Australasian journal of engineering education_ 3, 2 (2003), 2–16.
  * Naumova (2023) Elena N Naumova. 2023\.  A mistake-find exercise: a teacher’s tool to engage with information innovations, ChatGPT, and their analogs.  _Journal of Public Health Policy_ 44, 2 (2023), 173–178.
  * OpenAI (2023) OpenAI. 2023.  GPT-4 Technical Report.  https://doi.org/10.48550/arXiv.2303.08774 arXiv:2303.08774 [cs].
  * Ouh et al. (2023) Eng Lieh Ouh, Benjamin Kok Siew Gan, Kyong Jin Shim, and Swavek Wlodkowski. 2023.  ChatGPT, Can You Generate Solutions for my Coding Exercises? An Evaluation on its Effectiveness in an undergraduate Java Programming Course.  _arXiv preprint arXiv:2305.13680_ (2023).
  * Parsons and Haden (2006) Dale Parsons and Patricia Haden. 2006.  Parson’s Programming Puzzles: A Fun and Effective Learning Tool for First Programming Courses. In _Proceedings of the 8th Australasian Conference on Computing Education-Volume 52_. 157–163.
  * Reeves et al. (2023) Brent Reeves, Sami Sarsa, James Prather, Paul Denny, Brett A Becker, Arto Hellas, Bailey Kimmel, Garrett Powell, and Juho Leinonen. 2023.  Evaluating the Performance of Code Generation Models for Solving Parsons Problems With Small Prompt Variations. In _Proceedings of the 2023 Conference on Innovation and Technology in Computer Science Education V. 1_. 299–305.
  * Savelka et al. (2023a) Jaromir Savelka, Arav Agarwal, Marshall An, Chris Bogart, and Majd Sakr. 2023a.  Thrilled by Your Progress! Large Language Models (GPT-4) No Longer Struggle to Pass Assessments in Higher Education Programming Courses.  _arXiv preprint arXiv:2306.10073_ (2023).
  * Savelka et al. (2023b) Jaromir Savelka, Arav Agarwal, Christopher Bogart, Yifan Song, and Majd Sakr. 2023b.  Can Generative Pre-trained Transformers (GPT) Pass Assessments in Higher Education Programming Courses?  _arXiv preprint arXiv:2303.09325_ (2023).
  * Shin (2018) Myeong-Hee Shin. 2018\.  Effects of Project-Based Learning on Students’ Motivation and Self-Efficacy.  _English Teaching_ 73, 1 (2018), 95–114.
  * Sundar (2023) Pichai Sundar. 2023\.  An important next step on our AI journey.  https://blog.google/technology/ai/bard-google-ai-search-updates/.  [Online; last accessed 10-August-2023].
  * Thoppilan et al. (2022) Romal Thoppilan, Daniel De Freitas, Jamie Hall, Noam Shazeer, Apoorv Kulshreshtha, Heng-Tze Cheng, Alicia Jin, Taylor Bos, Leslie Baker, Yu Du, et al. 2022\.  Lamda: Language Models for Dialog Applications.  _arXiv preprint arXiv:2201.08239_ (2022).
  * Wegner (1990) Peter Wegner. 1990\.  Concepts and Paradigms of Object-Oriented Programming.  _ACM Sigplan Oops Messenger_ 1, 1 (1990), 7–87.
  * Wermelinger (2023) Michel Wermelinger. 2023\.  Using GitHub Copilot to Solve Simple Programming Problems. In _Proceedings of the 54th ACM Technical Symposium on Computer Science Education V. 1_. 172–178.
  * Xu et al. (2022) Frank F Xu, Uri Alon, Graham Neubig, and Vincent Josua Hellendoorn. 2022.  A Systematic Evaluation of Large Language Models of Code. In _Proceedings of the 6th ACM SIGPLAN International Symposium on Machine Programming_. 1–10.