Download WGU D793 Formal Languages Task 1 and 2 Guide: Programming Paradigms Analysis and Code Con and more Exams English Language in PDF only on Docsity!
WGU D793 Formal Languages Task 1 and 2 Guide:
Programming Paradigms Analysis and Code Conversion from
FORTRAN to Python โ 2026 Updated with complete solutions.
WGU D793 Formal Languages - Complete 60-Page Case Study Guide Task 1 & Task 2: Programming Paradigms Analysis and FORTRAN to Python Conversion PART ONE: EXECUTIVE SUMMARY (Pages 1-3) Course Overview WGU D793 Formal Languages requires students to master two primary competencies:
- Task 1 : Analysis of programming paradigms and their application in language design
- Task 2 : Practical code conversion from legacy FORTRAN to modern Python This comprehensive 60-page case study provides complete solutions, step-by-step methodologies, and ready-to-use code templates for both tasks, updated for the 2026 curriculum. Key Learning Objectives Task Primary Focus Deliverable Task 1 Paradigm Analysis Comparative analysis essay (2,500-3,000 words) Task 2 Code Conversion Working Python code from FORTRAN source Why This Matters Understanding formal languages and programming paradigms is foundational to computer science. FORTRAN, despite being developed in the 1950s, remains
return reduce(lambda x, y: x + y, numbers, 0 ) # OBJECT-ORIENTED class SumCalculator: def init(self, numbers): self.numbers = numbers self.total = 0 def calculate(self): self.total = sum(self.numbers) return self.total # DECLARATIVE (using Python's declarative features) def sum_declarative(numbers): return sum(numbers) # The "what" not the "how" 1.3 Paradigm Comparison Matrix Aspect Imperative Functional OOP Declarative State Management Mutable Immutable Encapsulated Implicit Primary Abstraction Statements Functions Objects Rules Control Flow Explicit loops Recursion Method calls Pattern matching
Aspect Imperative Functional OOP Declarative Side Effects Permitted Discouraged Controlled Avoided FORTRAN Support Native Limited None None Python Support Native Strong Strong Moderate Chapter 2: Deep Dive - The Imperative Paradigm (Pages 9-14) 2.1 FORTRAN as the Quintessential Imperative Language FORTRAN (FORmula TRANslation) was designed in 1957 specifically for scientific computing. Its imperative nature manifests through: Sequential Execution fortran PROGRAM sequential_example IMPLICIT NONE INTEGER :: x, y, z x = 5_! Statement 1_ y = 10_! Statement 2_ z = x + y_! Statement 3_ PRINT *, z_! Statement 4_ END PROGRAM State Modification fortran
DO i = 1 , 10 DO j = 1 , 10 matrix(i, j) = i * j END DO END DO Chapter 3: Deep Dive - The Functional Paradigm (Pages 15-18) 3.1 Core Principles Functional programming treats computation as mathematical function evaluation. Key characteristics: Pure Functions python # Pure function - no side effects, same input = same output def pure_add(x, y): return x + y # Impure function - modifies external state counter = 0 def impure_add(x, y): global counter counter += 1 return x + y First-Class Functions python # Functions can be passed as arguments def apply_operation(operation, x, y):
return operation(x, y) result = apply_operation(lambda a, b: a * b, 5 , 3 ) # Returns 15 3.2 Python's Functional Features Feature Syntax Description map() map(func, iterable) Apply function to all items filter() filter(predicate, iterable) Select items meeting condition reduce() reduce(func, iterable) Accumulate values lambda lambda x: x2 Anonymous functions list comprehensions [x2 for x in list] Declarative list creation Chapter 4: Deep Dive - Object-Oriented Paradigm (Pages 19-22) 4.1 FORTRAN's OOP Limitations Traditional FORTRAN (pre-2003) has no native OOP support. This is a critical distinction for Task 1 analysis. FORTRAN 77 and 90:
- No classes
- No inheritance
- No polymorphism
- No encapsulation beyond module-level 4.2 Python's Comprehensive OOP python class ScientificCalculator:
return self._history.copy() # Encapsulated access class EnhancedCalculator(ScientificCalculator): # Inheritance def init(self, precision= 6 , mode='standard'): super().init(precision) self.mode = mode def calculate_with_logging(self, operation, *args): result = super().calculate(operation, *args) print(f"Calculation result: {result}") return result 4.3 Paradigm Transition Analysis Key Insight for Task 1 : When converting FORTRAN to Python, you're not just translating syntax - you're transitioning from imperative-only to multi- paradigm programming. This enables:
- Better encapsulation (module vs. class scope)
- Code reuse (no inheritance in legacy FORTRAN)
- Error handling (try/except vs. GOTO error handling)
- Dynamic typing vs. static typing Chapter 5: Complete Paradigm Analysis Template (Pages 23-25) Template for Task 1 Response Use this structured template to analyze any FORTRAN code block: markdown
Code Analysis: [Program Name]
FORTRAN Code:
[Copy the FORTRAN code here] **Imperative Characteristics Identified:** 1. [List sequential execution statements] 2. [Identify mutable state variables] 3. [Note explicit loop constructs] 4. [Document GOTO or conditional branches] **Python Implementation Analysis:** python [Your Python translation] **Paradigm Comparison:** Criterion FORTRAN (Imperative) Python Implementation State Management [Describe] [Describe] Control Flow [Describe] [Describe] Data Abstraction [Describe] [Describe] Code Organization [Describe] [Describe] **Paradigm Shift Observations:** [Explain how the Python version could leverage OOP or functional features] text PROGRAM main IMPLICIT NONE INTEGER :: i, n REAL :: x(100), result n = 100 DO i = 1, n x(i) = i * 2. END DO result = calculate_sum(x, n) PRINT *, 'Sum = ', result END PROGRAM FUNCTION calculate_sum(arr, n) IMPLICIT NONE INTEGER :: n, i REAL :: arr(n), calculate_sum, temp temp = 0. DO i = 1, n temp = temp + arr(i) END DO calculate_sum = temp END FUNCTION python _# STEP 2: Map FORTRAN types to Python_ _# FORTRAN Type - > Python Type # INTEGER - > int # REAL - > float # CHARACTER - > str # LOGICAL - > bool # DIMENSION - > list or numpy.array # STEP 3: Write equivalent Python_ import numpy as np def calculate_sum(arr): """Direct translation of FORTRAN function""" _# FORTRAN: temp = 0._ temp = 0. _# FORTRAN: DO i = 1, n_ for i in range(len(arr)): _# FORTRAN: temp = temp + arr(i)_ temp += arr[i] _# FORTRAN: calculate_sum = temp_ return temp def main(): _# FORTRAN: n = 100_ n = 100 FORTRAN Construct Python Equivalent Notes GOTO label **Avoid** - use functions/loops No direct equivalent SUBROUTINE name() def name(): Functions replace subroutines FUNCTION name() def name(): return Functions return values IMPLICIT NONE Not needed Python is dynamically typed INTEGER :: a(10) a = [0]*10 or np.zeros(10) List or numpy array READ(*,*) var var = input() Console input WRITE(*,*) var print(var) Console output OPEN(unit, file) with open(file) as f: Context manager .AND., .OR., .NOT. and, or, not Logical operators .EQ., .NE., .GT. ==, !=, > Comparison operators **Chapter 7: Complete Code Conversion Examples (Pages 36-50) 7.1 Example 1: Numerical Integration (Trapezoidal Rule) FORTRAN Source:** fortran PROGRAM trapezoidal IMPLICIT NONE REAL :: a, b, h, sum, x INTEGER :: n, i REAL, EXTERNAL :: f a = 0. b = 1. n = 1000 h = (b - a) / n sum = (f(a) + f(b)) / 2. DO i = 1 , n- 1 x = a + i * h sum = sum + f(x) END DO sum = sum * h PRINT *, 'Integral = ', sum END PROGRAM FUNCTION f(x) REAL :: f, x f = x** 2 + 2 *x + 1 END FUNCTION **Python Conversion (Imperative):** Pure functional version - no side effects """ h = (b - a) / n x_values = [a + i * h for i in range(n + 1 )] _# Using functional composition_ result = (f(a) + f(b)) / 2.0 + sum(f(x) for x in x_values[ 1 :- 1 ]) return result * h _# Usage_ result = trapezoidal_functional(lambda x: x** 2 + 2 *x + 1 , 0.0, 1.0, 1000 ) print(f'Integral = {result}') **Python Conversion (Object-Oriented):** python class NumericalIntegrator: """Encapsulates integration functionality""" def __init__(self, function, a, b, n= 1000 ): self.function = function self.a = a self.b = b self.n = n self._result = None def compute_trapezoidal(self): h = (self.b - self.a) / self.n total = (self.function(self.a) + self.function(self.b)) / 2. for i in range( 1 , self.n): x = self.a + i * h total += self.function(x) self._result = total * h return self._result @property def result(self): if self._result is None: self.compute_trapezoidal() return self._result class QuadraticFunction: def __call__(self, x): return x** 2 + 2 *x + 1 _# Usage_ integrator = NumericalIntegrator(QuadraticFunction(), 0.0, 1.0, 1000 ) print(f'Integral = {integrator.compute_trapezoidal()}')