> Lord, you reveal your glory in everything you made
Let us today engage with this creation so that we may participate in your beauty and wisdom
May the technology we use or even develop point us toward that,
Instead of dragging us towards our own vicious desires and illusions of freedom
Help us, and our society, to know your ways and be still, for yours is the glory
And our hearts are restless till they find rest in You.
Amen.
# Code review
# Inline if-elses
An inline `if-else` expression (also called **ternary operator**) is a concise way to handle simple conditional logic. It uses the syntax:
```python
value_if_true if condition else value_if_false
```
This is a simple expression that will “evaluate” to the right value given a condition (in other programming languages, it is called ternary operator).
For example:
```python
name = input("What is your last name?")
is_doctor = input("Are you a doctor?")
print("Hello, " + ("Dr. " if is_doctor.lower()=="yes" else "") + name)
```
- Differently from the other if syntax, in this case YOU NEED to include the "else" clause!
- Careful with operator precedence! Ternary operators have the lowest precedence!
# Nesting if-elses
Let's say we need to implement a system that monitors the oil quality in an industrial machine. It will check different parameters and show alerts:
1. **Oil temperature**:
- Safe if the oil temperature is **less than 90°C**.
- If the temperature is **90°C or higher**, check the oil **pressure**.
2. **Oil pressure**:
- Safe if the pressure is **greater than 40 psi**.
- If the pressure is **40 psi or lower**, the machine must stop and an alert should be issued.
3. **Oil contamination**:
- If the temperature and pressure are safe, check the **oil contamination level**.
- The machine can run if the contamination level is **less than 10%**.
- If the contamination is **10% or higher**, maintenance is required.
Task:
1. Write a Python program using **nested if-else statements** to check the parameters of the oil quality.
2. Use the following variables:
- `oil_temperature`: the current oil temperature (in degrees Celsius).
- `oil_pressure`: the current oil pressure (in psi).
- `contamination_level`: the oil contamination level (as a percentage).
3. The program should print:
- "Machine is operating safely." if all parameters are within safe limits.
- "Immediate maintenance required: High oil temperature and low pressure." if the oil temperature is too high and the pressure is too low.
- "Maintenance required: High oil contamination." if the oil contamination level is too high.
- "Machine is operating, but monitor oil temperature." if the temperature is high but pressure is safe.
- Which tests should you make to ensure the program is working correctly? Each test like this is called a **test case**. In software, it is very important to check them!
## Loading files
Suppose we now have a list of machines and their parameters, stored in the following way:
```python
machines = [(oil_temp1, oil_pressure1, cont_level1), (oil_temp2, oil_pressure2, oil_pressure2), ...]
```
Let’s say that this data is stored in an Excel file, with this table:
| Machine ID | Oil Temperature (°C) | Oil Pressure (psi) | Contamination Level (%) |
| --- | --- | --- | --- |
| Machine_1 | 85 | 50 | 5 |
| Machine_2 | 95 | 45 | 8 |
| Machine_3 | 78 | 55 | 3 |
| Machine_4 | 102 | 35 | 12 |
| Machine_5 | 88 | 60 | 7 |
| Machine_6 | 91 | 40 | 9 |
| Machine_7 | 105 | 38 | 15 |
| Machine_8 | 87 | 52 | 4 |
| Machine_9 | 80 | 48 | 2 |
| Machine_10 | 92 | 44 | 11 |
Save this table in an Excel file.
The code to load the file in your program and save it as the list we want is:
```python
import pandas as pd
# Load the Excel file
df_loaded = pd.read_excel("path_to_your_file.xlsx")
# Convert the DataFrame into a list of tuples
machines = list(zip(df_loaded["Oil Temperature (°C)"],
df_loaded["Oil Pressure (psi)"],
df_loaded["Contamination Level (%)"]))
print(machines)
```
Now, your task is to check if every machine is correctly working.
To go through each machine, use this syntax:
```python
for machine in machines:
print("Machine parameters:", machine)
# write your code inside this
```
## Raising flags
Now, suppose we want to raise an alarm at the end of all the checking, in case there is a problem with one of the machines. We declare a variable called `problem = False`. Observe:
```python
problem = False
for machine in machines:
print("Machine parameters:", machine)
# write your code inside this
if problem:
print("One of the machines is not safe. Stop production.")
```
What do we need to do with the boolean variable problem, inside the checking code, to make this application work?
The name we usually give to this boolean variable is **a flag** (since we are raising it at some point). It is a common programming pattern that can solve lots of problems!
# Conditionals are discriminations
[Amy Ko reflects](https://criticallyconsciouscomputing.org/control) on the attempt to generate an algorithm for deciding over administrative issues.
> "In 2006, the U.S. state of Indiana began a major digitization initiative to reduce administrative costs of its welfare system through automation.
This information the caseworker reviewed included things like:
> - Proof of Indiana residency,
> - How many people live in the applicant’s household,
> - Whether the household has dependent children less than 18 years of age, and
> - The gross earned monthly income of the household in the current or next month.
>
> The case worker:
> - was available by phone for questions,
> - to resolve any ambiguities in an application, and
> - to help explain the state’s eligibility decisions.
>
> The process was not perfect, but the experience of applying for benefits involved interacting with a person who could guide the applicant through the process, fix any misinterpretations by the applicants about how to fill out the form, and address any exceptional circumstances not anticipated by the program, its processes, or the laws that shaped it.
>Indiana’s digitization efforts sought to automate the application process, having applicants submit data through a website, then having an algorithm use that data to decide whether the applicant was eligible.
> The hope was that the algorithm could replicate the caseworker’s eligibility decision, but do it more consistently, more quickly, and more fairly than a case worker could do, and possibly free caseworkers to spend their time handling more complex cases. [...]
> [However, what happened is that] fewer people were being approved, and residents had less clarity about why they were being denied. The decisions that the algorithm was making were, in general, *less flexible, less explainable, and less transparent than the decisions that caseworkers made**. The result was that Indiana denied more than a million applications for food stamps and other aid, a 54% increase in denials compared to the three years before the automation was launched. From the conservative governor’s standpoint, however, it was a success: the state and federal government had never spent less on food security for its citizens since the program had started.
## Can't we just refine the logic?
* The algorithm described failed because it couldn't deal with exceptional cases, personal histories, etc.
* Can't we just add these exceptions to the logic?
There are reasons to believe this won't be sufficient.
> Automating decision making can also be problematic when it completely **stamps out any room for discretion**. While human discretion presents its own issues, as described above, it can be useful when it is difficult or impossible to fully specify how decisions should be made in accordance with the goals and principles of the institution. Automation requires that an institution determine in advance all of the criteria that a decision-making scheme will take into account; there is no room to consider the relevance of additional details that might not have been considered or anticipated at the time that the software was developed.
> Automated decision-making is thus likely to be much more brittle than decision-making that involves manual review because it limits the opportunity for decision subjects to introduce information into the decision-making process. People are confined to providing evidence that corresponds to a pre-established field in the software. Such constraints can result in absurd situations in which the strict application of decision-making rules leads to outcomes that are directly counter to the goals behind these rules. New evidence that would immediately reverse the assessment of a human decision maker may have no place in automated decision making. For example, in an automated system to assess people with illnesses to determine eligibility for a state-provided caregiver, one field asked if there were any foot problems. An assessor visited a certain person and filled out the field to indicate that they didn’t have any problems — because they were an amputee. - Solon Barocas, Moritz Hardt, Arvind Narayanan, [*When is automated decision making legitimate?*](https://fairmlbook.org/legitimacy.html)
## The awkward student experiment
* Philosopher Ludwig Wittgenstein (1889-1951) wrote: “no course of action could be determined by a rule, because *any* course of action can be made out to accord with the rule” (Philosophical Investigations §201a). In other words: **“rules do not contain the rules for its own application”**
* Example: the **akward student experiment** (Harry Collins, "Changing Order"): “given the sequence ‘2, 4, 6, 8’, continue it in the same way.”
> “We know how to go on in the ‘same way’ because we share a ‘form of life’. The rightness of ‘10, 12, 14, 16’ as the continuation of ‘2, 4, 6, 8’ resides in its rightness for everyone sharing our culture.” (Harry Collins)
* In a similar way, an algorithm will follow rules in the way we think it should follow rules (i.e., ignoring lots of exceptional situations). But without a shared culture, for understanding context and then how to apply the rule, it will operate almost "blindly"...

## If-elses are value judgements
> “The power that algorithms offer is not without consequences. They take processes that we used to be able to see people do and hide them behind code. **They take procedures that used to be controlled by every individual who executed them and centralize and standardize this execution in the hands of software developers often in private organizations**. And this shift of power, from the collective to developers, had a price: the knowledge those individuals have of what they need is no longer brought to bear on the processes that algorithms automate. Instead, it’s up to those few developers to proactively learn that knowledge and **translate it into uniform step-by-step instructions that likely don’t account for the diversity of needs and contexts in the world.** The critical question about algorithms, then, is not how to automate something with an algorithm, but whether to and why.” - Amy J. Ko, Critically Conscious Computing
* What are the **value judgements** when we encode intelligence in algorithms?
* **If-else** statements are **distinction judgments**, or in other words, **DISCRIMINATIONS**. Are these judgments fair? Do they really take what is needed into account?
* **As Christians**, are we being fair with the diversity and complexity of the world, or are we trying to code everything into simplistic operations just in order to better control life situations?