Jacinto Velasco
Claude Opus 5 (1M context)
Aplicacion de Fundamentos Matematicos de la Ingenieria I
357f247 Download pruebas_ejercicios.py from OncomIA01/Calculus: direct link, hf CLI and curl.
- Browser
- Download file 11 kB
-
https://huggingface.co/spaces/OncomIA01/Calculus/resolve/main/pruebas_ejercicios.py
- Command line
-
hf download hf://spaces/OncomIA01/Calculus/pruebas_ejercicios.py
-
curl -L -o pruebas_ejercicios.py https://huggingface.co/spaces/OncomIA01/Calculus/resolve/main/pruebas_ejercicios.py
11 kB
| # -*- coding: utf-8 -*- | |
| """ | |
| pruebas_ejercicios.py -- La aplicaci贸n contra los ejercicios propuestos | |
| de los apuntes. | |
| No son casos inventados: son los enunciados que van a hacer en clase, sacados | |
| de los apartados 芦Ejercicios propuestos禄 de los temas 1 a 6, con la soluci贸n | |
| resuelta a mano y escrita aqu铆 al lado. | |
| python pruebas_ejercicios.py | |
| """ | |
| from __future__ import print_function | |
| import sys | |
| import traceback | |
| import sympy as sp | |
| from calculo import continuidad, derivadas, inecuaciones, representacion | |
| from calculo.entrada import X, lee_funcion, lee_relacion | |
| fallos = [] | |
| total = [0] | |
| def comprueba(tema, enunciado, funcion, esperado): | |
| total[0] += 1 | |
| try: | |
| obtenido = funcion() | |
| except Exception: | |
| fallos.append((tema, enunciado, traceback.format_exc())) | |
| print(" FALLA %-52s (excepci贸n)" % enunciado) | |
| return | |
| bien = obtenido == esperado | |
| if not bien and hasattr(obtenido, "equals"): | |
| try: | |
| bien = bool(sp.simplify(obtenido - esperado) == 0) | |
| except Exception: | |
| bien = False | |
| if bien: | |
| print(" ok %s" % enunciado) | |
| else: | |
| fallos.append((tema, enunciado, | |
| "esperaba %s\n ha salido %s" | |
| % (esperado, obtenido))) | |
| print(" DISTINTO %s\n esperaba %s\n ha salido %s" | |
| % (enunciado, esperado, obtenido)) | |
| def solucion(texto): | |
| return inecuaciones.resuelve(lee_relacion(texto)).solucion | |
| # ========================================================================== | |
| print("\n=== TEMA 1 路 INECUACIONES (ejercicio 1.x) ===") | |
| # ========================================================================== | |
| comprueba(1, "(x+3)(x-4)/(x^3-2x^2-3x) < 0", | |
| lambda: solucion("(x+3)(x-4)/(x^3-2x^2-3x) < 0"), | |
| sp.Union(sp.Interval.open(-sp.oo, -3), sp.Interval.open(-1, 0), | |
| sp.Interval.open(3, 4))) | |
| comprueba(1, "(x-2)^2 >= 1", | |
| lambda: solucion("(x-2)^2 >= 1"), | |
| sp.Union(sp.Interval(-sp.oo, 1), sp.Interval(3, sp.oo))) | |
| print("\n=== TEMA 1 路 VALOR ABSOLUTO ===") | |
| from calculo import absolutos # noqa: E402 | |
| comprueba(1, "|3x-1| > |2x-4|", | |
| lambda: absolutos.resuelve(lee_relacion("|3x-1| > |2x-4|")).solucion, | |
| sp.Union(sp.Interval.open(-sp.oo, -3), sp.Interval.open(1, sp.oo))) | |
| comprueba(1, "||x-1| - |x+1|| <= 1", | |
| lambda: sp.simplify( | |
| absolutos.resuelve(lee_relacion("||x-1|-|x+1|| <= 1")).solucion), | |
| sp.Interval(sp.Rational(-1, 2), sp.Rational(1, 2))) | |
| print("\n=== TEMA 1 路 DOMINIOS ===") | |
| def dominio(texto): | |
| return representacion.estudia(lee_funcion(texto)).dominio | |
| comprueba(1, "dominio de raiz(4-x^2)/(x-1)", | |
| lambda: dominio("raiz(4-x^2)/(x-1)"), | |
| sp.Union(sp.Interval.Ropen(-2, 1), sp.Interval.Lopen(1, 2))) | |
| comprueba(1, "dominio de ln(x^2-5x+6)", | |
| lambda: dominio("ln(x^2-5x+6)"), | |
| sp.Union(sp.Interval.open(-sp.oo, 2), sp.Interval.open(3, sp.oo))) | |
| comprueba(1, "dominio de ln(1-|x-2|)", | |
| lambda: dominio("ln(1-|x-2|)"), | |
| sp.Interval.open(1, 3)) | |
| comprueba(1, "dominio de arcsen((x-1)/2)", | |
| lambda: dominio("arcsen((x-1)/2)"), | |
| sp.Interval(-1, 3)) | |
| comprueba(1, "dominio de raiz(x/(x^2-1))", | |
| lambda: dominio("raiz(x/(x^2-1))"), | |
| sp.Union(sp.Interval.Lopen(-1, 0), sp.Interval.open(1, sp.oo))) | |
| print("\n=== TEMA 1 路 RECORRIDOS ===") | |
| comprueba(1, "recorrido de (2x+3)/(x+1)", | |
| lambda: representacion.estudia(lee_funcion("(2x+3)/(x+1)")).recorrido, | |
| sp.Union(sp.Interval.open(-sp.oo, 2), sp.Interval.open(2, sp.oo))) | |
| # ========================================================================== | |
| print("\n=== TEMA 2 路 L脥MITES ===") | |
| # ========================================================================== | |
| from calculo import limites # noqa: E402 | |
| def limite(texto, punto): | |
| return limites.estudia(lee_funcion(texto), sp.sympify(punto)).limite | |
| def forma(texto, punto): | |
| return limites.estudia(lee_funcion(texto), sp.sympify(punto)).forma | |
| casos_limites = [ | |
| ("(2x^3-x+1)/(5x^3+x^2)", sp.oo, sp.Rational(2, 5), "oo/oo"), | |
| ("(x^2+1)/(x^3-x)", sp.oo, sp.Integer(0), "oo/oo"), | |
| ("(3x^4-x)/(x^3+2)", -sp.oo, -sp.oo, "oo/oo"), | |
| ("raiz(x^2+x)-x", sp.oo, sp.Rational(1, 2), "oo-oo"), | |
| ("raiz(x^2+3x)-raiz(x^2-x)", sp.oo, sp.Integer(2), "oo-oo"), | |
| ("arctg(3x)/sen(5x)", sp.Integer(0), sp.Rational(3, 5), "0/0"), | |
| ("(1-cos(x))/(x*sen(x))", sp.Integer(0), sp.Rational(1, 2), "0/0"), | |
| ("(e^(x^2)-1)/(1-cos(x))", sp.Integer(0), sp.Integer(2), "0/0"), | |
| ("ln(1+3x)/(2^x-1)", sp.Integer(0), 3 / sp.log(2), "0/0"), | |
| ] | |
| for texto, punto, valor, tipo in casos_limites: | |
| comprueba(2, "lim %s cuando x->%s" % (texto, punto), | |
| lambda t=texto, p=punto: limite(t, p), valor) | |
| comprueba(2, " ...y reconoce la indeterminaci贸n %s" % tipo, | |
| lambda t=texto, p=punto: forma(t, p), tipo) | |
| comprueba(2, "(1+1/x)^x cuando x->oo -> e (indeterminaci贸n 1^oo)", | |
| lambda: (limite("(1+1/x)^x", sp.oo), forma("(1+1/x)^x", sp.oo)), | |
| (sp.E, "1^oo")) | |
| comprueba(2, "sen(x)/x cuando x->pi NO es indeterminado (vale 0)", | |
| lambda: (limite("sen(x)/x", sp.pi), forma("sen(x)/x", sp.pi)), | |
| (sp.Integer(0), None)) | |
| # ========================================================================== | |
| print("\n=== TEMA 3 路 DERIVADAS ===") | |
| # ========================================================================== | |
| def derivada_en(texto, punto): | |
| f = lee_funcion(texto) | |
| return sp.simplify(sp.diff(f, X).subs(X, punto)) | |
| comprueba(3, "f'(1) de raiz(3x+1) -> 3/4", | |
| lambda: derivada_en("raiz(3x+1)", 1), sp.Rational(3, 4)) | |
| comprueba(3, "f'(0) de x|x| -> 0", | |
| lambda: continuidad.estudia(lee_funcion("x*|x|"), sp.Integer(0)).der_izq, | |
| sp.Integer(0)) | |
| comprueba(3, "x|x| ES derivable en 0", | |
| lambda: continuidad.estudia(lee_funcion("x*|x|"), | |
| sp.Integer(0)).derivable, True) | |
| comprueba(3, "raiz3(x) NO es derivable en 0 (tangente vertical)", | |
| lambda: continuidad.estudia(lee_funcion("x^(1/3)"), | |
| sp.Integer(0)).derivable, False) | |
| comprueba(3, "tangente a x^3-2x en x=1 -> y = x-2", | |
| lambda: representacion.estudia(lee_funcion("x^3-2x"), | |
| sp.Integer(1)).tangente, | |
| X - 2) | |
| # ========================================================================== | |
| print("\n=== TEMA 4 路 CONTINUIDAD: clasificar y dar el l铆mite ===") | |
| # ========================================================================== | |
| def estudio(texto, punto): | |
| return continuidad.estudia(lee_funcion(texto), sp.sympify(punto)) | |
| comprueba(4, "(x^3-8)/(x^2-4) en x=2: evitable, l铆mite 3", | |
| lambda: (estudio("(x^3-8)/(x^2-4)", 2).tipo, | |
| estudio("(x^3-8)/(x^2-4)", 2).limite), | |
| ("Discontinuidad evitable", sp.Integer(3))) | |
| comprueba(4, "(1-cos x)/x^2 en x=0: evitable, l铆mite 1/2", | |
| lambda: (estudio("(1-cos(x))/x^2", 0).tipo, | |
| estudio("(1-cos(x))/x^2", 0).limite), | |
| ("Discontinuidad evitable", sp.Rational(1, 2))) | |
| comprueba(4, "x/(e^(2x)-1) en x=0: evitable, l铆mite 1/2", | |
| lambda: (estudio("x/(e^(2x)-1)", 0).tipo, | |
| estudio("x/(e^(2x)-1)", 0).limite), | |
| ("Discontinuidad evitable", sp.Rational(1, 2))) | |
| comprueba(4, "(raiz(1+x)-raiz(1-x))/x en x=0: evitable, l铆mite 1", | |
| lambda: (estudio("(raiz(1+x)-raiz(1-x))/x", 0).tipo, | |
| estudio("(raiz(1+x)-raiz(1-x))/x", 0).limite), | |
| ("Discontinuidad evitable", sp.Integer(1))) | |
| comprueba(4, "x/|x| en x=0: salto finito, laterales -1 y +1", | |
| lambda: (estudio("x/|x|", 0).tipo, | |
| estudio("x/|x|", 0).lim_izq, estudio("x/|x|", 0).lim_der), | |
| ("Discontinuidad de salto finito", sp.Integer(-1), sp.Integer(1))) | |
| comprueba(4, "x路sen(1/x) en x=0: evitable, l铆mite 0", | |
| lambda: (estudio("x*sen(1/x)", 0).tipo, | |
| estudio("x*sen(1/x)", 0).limite), | |
| ("Discontinuidad evitable", sp.Integer(0))) | |
| # ========================================================================== | |
| print("\n=== TEMA 6 路 REPRESENTACI脫N ===") | |
| # ========================================================================== | |
| def estudia_f(texto, punto=None): | |
| return representacion.estudia(lee_funcion(texto), punto) | |
| e1 = estudia_f("(x^2-1)/(x^2-4)") | |
| comprueba(6, "(x^2-1)/(x^2-4): as铆ntotas verticales x=-2 y x=2", | |
| lambda: sorted([a for a, _, _ in e1.asint_verticales], | |
| key=lambda v: sp.N(v)), | |
| [sp.Integer(-2), sp.Integer(2)]) | |
| comprueba(6, "(x^2-1)/(x^2-4): as铆ntota horizontal y=1 por los dos lados", | |
| lambda: [v for _, v in e1.asint_horizontales], | |
| [sp.Integer(1), sp.Integer(1)]) | |
| comprueba(6, "(x^2-1)/(x^2-4): es par", | |
| lambda: e1.simetria.startswith("Par"), True) | |
| e2 = estudia_f("x^3-4x") | |
| comprueba(6, "x^3-4x: cortes en -2, 0, 2", | |
| lambda: e2.cortes_x, [sp.Integer(-2), sp.Integer(0), sp.Integer(2)]) | |
| comprueba(6, "x^3-4x: es impar", | |
| lambda: e2.simetria.startswith("Impar"), True) | |
| comprueba(6, "x^3-4x: inflexi贸n en x=0", | |
| lambda: [c for c, _ in e2.inflexiones], [sp.Integer(0)]) | |
| comprueba(6, "x^3-4x: m谩ximo en -2/raiz(3), m铆nimo en 2/raiz(3)", | |
| lambda: ([sp.simplify(c) for c, _ in e2.maximos], | |
| [sp.simplify(c) for c, _ in e2.minimos]), | |
| ([-2 * sp.sqrt(3) / 3], [2 * sp.sqrt(3) / 3])) | |
| e3 = estudia_f("ln(x^2-3x+2)") | |
| comprueba(6, "ln(x^2-3x+2): dominio (-oo,1) U (2,+oo)", | |
| lambda: e3.dominio, | |
| sp.Union(sp.Interval.open(-sp.oo, 1), sp.Interval.open(2, sp.oo))) | |
| comprueba(6, "ln(x^2-3x+2): as铆ntotas verticales x=1 y x=2", | |
| lambda: sorted([a for a, _, _ in e3.asint_verticales], | |
| key=lambda v: sp.N(v)), | |
| [sp.Integer(1), sp.Integer(2)]) | |
| e4 = estudia_f("raiz((x-1)/(x+2))") | |
| comprueba(6, "raiz((x-1)/(x+2)): dominio (-oo,-2) U [1,+oo)", | |
| lambda: e4.dominio, | |
| sp.Union(sp.Interval.open(-sp.oo, -2), sp.Interval(1, sp.oo))) | |
| comprueba(6, "raiz((x-1)/(x+2)): as铆ntota horizontal y=1", | |
| lambda: sorted(set(v for _, v in e4.asint_horizontales), | |
| key=lambda v: sp.N(v)), | |
| [sp.Integer(1)]) | |
| e5 = estudia_f("(x^2-4)/(x^2-x-2)") | |
| comprueba(6, "(x^2-4)/(x^2-x-2): as铆ntota vertical solo en x=-1", | |
| lambda: [a for a, _, _ in e5.asint_verticales], [sp.Integer(-1)]) | |
| # ========================================================================== | |
| print("\n" + "=" * 74) | |
| if fallos: | |
| print("%d de %d ejercicios NO salen bien:\n" % (len(fallos), total[0])) | |
| for tema, enunciado, detalle in fallos: | |
| print("[tema %d] %s\n %s\n" % (tema, enunciado, detalle)) | |
| sys.exit(1) | |
| print("Los %d ejercicios salen bien." % total[0]) | |