From a2e6a7c3164ebf32be0e8cd277247af99115d4c2 Mon Sep 17 00:00:00 2001 From: Lucas <lucas.heublein@t-online.de> Date: Fri, 18 Aug 2023 16:38:06 +0200 Subject: [PATCH] Added the 2D wall Bouncing Scroll (WBouncingScroll) and a new StepUntil Function that also takes constant values --- .../kwarc/mmt/frameit/rules/StepUntilX.scala | 65 +++++++++++++++ source/DefaultSituationSpace.mmt | 1 + source/IntegrationTests/DynamicsDebug.mmt | 65 ++++++++++++++- source/Scrolls/WBouncingScroll.mmt | 83 +++++++++++++++++++ source/dynamics.mmt | 6 +- 5 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 scala/info/kwarc/mmt/frameit/rules/StepUntilX.scala create mode 100644 source/Scrolls/WBouncingScroll.mmt diff --git a/scala/info/kwarc/mmt/frameit/rules/StepUntilX.scala b/scala/info/kwarc/mmt/frameit/rules/StepUntilX.scala new file mode 100644 index 0000000..5f9208c --- /dev/null +++ b/scala/info/kwarc/mmt/frameit/rules/StepUntilX.scala @@ -0,0 +1,65 @@ +package info.kwarc.mmt.frameit.rules + +import info.kwarc.mmt.api.checking._ +import info.kwarc.mmt.api.{DPath, GlobalName, LocalName, ParametricRule, Rule, RuleSet} +import info.kwarc.mmt.api.frontend.Controller +import info.kwarc.mmt.api.objects._ +import Conversions._ +import info.kwarc.mmt.api.uom.{Simplifiability, Simplify} +import info.kwarc.mmt.lf.{Apply, ApplySpine, Arrow, OfType, Pi} +import info.kwarc.mmt.LFX.datatypes.{Listtype, Ls} +import info.kwarc.mmt.api.utils.URI + +import scala.collection.mutable + +object StepUntilX { + val ns: DPath = DPath(URI.http colon "mathhub.info") / "FrameIT" / "frameworld" + val path: GlobalName = ns ? "StepUntilX" ? "stepUntilX" + val rawhead: OMID = OMS(path) + def apply(tpA: Term, tpB: Term, tpC: Term, vB: Term, vC: Term, vA: Term, f: Term, tC: Term): Term = + ApplySpine(this.rawhead, tpA, tpB, tpC, vB, vC, vA, f, tC) + def unapply(tm : Term) : Option[(Term, Term, Term, Term, Term, Term, Term, Term)] = tm match { + case ApplySpine(this.rawhead, List(tpA, tpB, tpC, vB, vC, vA, f, tC)) => Some((tpA, tpB, tpC, vB, vC, vA, f, tC)) + case _ => None + } +} + +object StepUntilXRule extends ParametricRule { + // todo: document + private val DEBUG_MAX_ITER_COUNT = 100 + + override def apply(controller: Controller, home: Term, args: List[Term]): Rule = args match { + case List(truetm) => + RuleSet(StepUntilXComp(truetm)) + case _ => + ??? + } + + case class StepUntilXComp(truetm: Term) extends ComputationRule(StepUntilX.path) { + override def applicable(t: Term): Boolean = t match { + case StepUntilX(_, _, _, _, _, _, _, _) => true + case _ => false + } + override def apply(check: CheckingCallback)(tm: Term, covered: Boolean)(implicit stack: Stack, history: History): Simplifiability = tm match { + case StepUntilX(_, _, _, vB, vC, vA, f, tC) => + val values = mutable.ListBuffer[Term]() + val valB = check.simplify(vB) + val valC = check.simplify(vC) + var iter = 0 + var cur = check.simplify(vA) + while (iter < DEBUG_MAX_ITER_COUNT) { + iter += 1 + check.tryToCheckWithoutDelay(Equality(stack, Apply(tC, cur), truetm, None)) match { + case Some(true) => + return Simplify(Ls(values.toSeq : _*)) + case Some(false) | None => + values += cur + cur = check.simplify(ApplySpine(f, valB, valC, cur)) + } + } + // todo: try to log something via stack, history, check, or this + Simplify(Ls(values.toSeq : _*)) + case _ => Simplifiability.NoRecurse + } + } +} \ No newline at end of file diff --git a/source/DefaultSituationSpace.mmt b/source/DefaultSituationSpace.mmt index 4bad740..2c66635 100644 --- a/source/DefaultSituationSpace.mmt +++ b/source/DefaultSituationSpace.mmt @@ -16,6 +16,7 @@ theory DefaultSituationSpace = include ?Midpoint â™ include ?CircleScroll â™ include ?BouncingScroll â™ + include ?WBouncingScroll â™ // include ?SinOppositeLeg â™ include ?CircleLineAngleScroll â™ include ?CircleAreaScroll â™ diff --git a/source/IntegrationTests/DynamicsDebug.mmt b/source/IntegrationTests/DynamicsDebug.mmt index 50266db..b75c102 100644 --- a/source/IntegrationTests/DynamicsDebug.mmt +++ b/source/IntegrationTests/DynamicsDebug.mmt @@ -2,12 +2,13 @@ namespace http://mathhub.info/FrameIT/frameworld/integrationtests/dynamicsdebug rule scala://parser.api.mmt.kwarc.info?MMTURILexer âš +import rules scala://datatypes.LFX.mmt.kwarc.info âš import frameworld http://mathhub.info/FrameIT/frameworld âš fixmeta http://mathhub.info/FrameIT/frameworld?FrameworldMeta âš theory IfElseDebug = include ☞http://mathhub.info/FrameIT/frameworld?IfThenElseX â™ - c: ℠☠= ifx (leq_real_lit 20.0 10.0) thenx 1.0 elsex 0.0 â™ + c: ℠☠= â„ ifx (leq_real_lit 20.0 10.0) thenx 1.0 elsex 0.0 â™ âš theory StepUntilDebug = @@ -16,3 +17,65 @@ theory StepUntilDebug = my_list: List[â„] ☠= stepUntil â„ 0.0 ([x: â„] plus_real_lit x 1.0) ([x: â„] leq_real_lit 10.0 x) â™ //my_list: ℠☠= stepUntil â„ 0.0 ([x: â„] plus_real_lit x 1.0) ([x: â„] leq_real_lit 10.0 x) â™ âš + +theory StepUntilXDebug = + include ☞http://mathhub.info/FrameIT/frameworld?StepUntilX â™ + //my_list: List[â„] ☠= (cons 0.0 (cons 2.0 nil)) map ([x: â„] plus_real_lit x 1.0) â™ + my_list: List[â„] ☠= stepUntilX â„ List[â„] (℠× â„) (cons 1.0 nil) ⟨2.0, 1.0⟩ 0.0 ([x: List[â„], y: ℠× â„, z: â„] times_real_lit (plus_real_lit (x fold 0.0 ([curr: â„][acc: â„] plus_real_lit curr acc)) z) (Ï€l y)) ([x: â„] leq_real_lit 50.0 x) â™ + //my_list: ℠☠= stepUntil â„ 0.0 ([x: â„] plus_real_lit x 1.0) ([x: â„] leq_real_lit 10.0 x) â™ +âš +theory StepUntilX2Debug = + include ☞http://mathhub.info/FrameIT/frameworld?StepUntilX â™ + include ☞http://mathhub.info/FrameIT/frameworld?IfThenElseX â™ + rule rules?FilterRule (true) â™ + calc_new_vals : (℠× â„) ⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ ((℠× â„) × (℠× â„)) ☠= + [bv, v] ⟨⟨plus_real_lit (Ï€l (Ï€l v)) (times_real_lit (Ï€l (Ï€l (Ï€r v))) (Ï€l (Ï€r (Ï€r v)))), plus_real_lit (plus_real_lit (Ï€r (Ï€l v)) (times_real_lit (Ï€r (Ï€l (Ï€r v))) (Ï€l (Ï€r (Ï€r v))))) (times_real_lit (times_real_lit 0.5 (Ï€l bv)) (times_real_lit (Ï€l (Ï€r (Ï€r v))) (Ï€l (Ï€r (Ï€r v)))))⟩, ⟨ times_real_lit (Ï€r bv) (plus_real_lit (Ï€l (Ï€l (Ï€r v))) (times_real_lit (times_real_lit (times_real_lit 2.0 (Ï€r (Ï€r (Ï€r v)))) (plus_real_lit (Ï€r (Ï€l (Ï€r v))) (minus_real_lit (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€l (Ï€l (Ï€r v))))))) (inv_real_lit (plus_real_lit 1.0 (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€r (Ï€r (Ï€r v)))))))), times_real_lit (Ï€r bv) (plus_real_lit (plus_real_lit (Ï€r (Ï€l (Ï€r v))) (times_real_lit (Ï€l bv) (Ï€l (Ï€r (Ï€r v))))) (minus_real_lit (times_real_lit (times_real_lit 2.0 (plus_real_lit (plus_real_lit (Ï€r (Ï€l (Ï€r v))) (times_real_lit (Ï€l bv) (Ï€l (Ï€r (Ï€r v))))) (minus_real_lit (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€l (Ï€l (Ï€r v))))))) (inv_real_lit (plus_real_lit 1.0 (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€r (Ï€r (Ï€r v)))))))))⟩⟩ â™ + fold_func : (((℠× â„) × (℠× â„)) × â„) ⟶ (℠× â„) ⟶ (℠× â„) ☠= + [cur][acc] (℠× â„) ifx (leq_real_lit (Ï€l acc) (Ï€r (Ï€l (Ï€l cur)))) thenx acc elsex ⟨πr (Ï€l (Ï€l cur)), Ï€r cur⟩ â™ + check_hit : ((℠× â„) × (℠× â„)) ⟶ bool ☠= + [p] leq_real_lit 0.000001 (Ï€r (Ï€l p)) â™ + check_hit2 : ((℠× â„) × (℠× â„)) ⟶ bool ☠= + [p] leq_real_lit (Ï€l (Ï€r p)) (Ï€l (Ï€l p)) â™ + check_hit3 : ((℠× â„) × (℠× â„)) ⟶ bool ☠= + [p] leq_real_lit (Ï€l (Ï€l p)) (Ï€r (Ï€r p)) â™ + get_hit_time_pos : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠☠= + [wi, x, y, xv, yv, g] times_real_lit (inv_real_lit g) (plus_real_lit (plus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv) (minus_real_lit yv)) (sqrt ( plus_real_lit (times_real_lit (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv))) (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv)))) (minus_real_lit (times_real_lit (times_real_lit 2.0 g) (plus_real_lit (plus_real_lit y (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) x))) (minus_real_lit (Ï€r (Ï€l wi))))))))) â™ + get_hit_time_neg : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠☠= + [wi, x, y, xv, yv, g] times_real_lit (inv_real_lit g) (plus_real_lit (plus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv) (minus_real_lit yv)) (minus_real_lit (sqrt ( plus_real_lit (times_real_lit (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv))) (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv)))) (minus_real_lit (times_real_lit (times_real_lit 2.0 g) (plus_real_lit (plus_real_lit y (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) x))) (minus_real_lit (Ï€r (Ï€l wi)))))))))) â™ + get_x_ht : ℠⟶ ℠⟶ ℠⟶ ℠☠= [x, xv, ht] plus_real_lit x (times_real_lit xv ht) â™ + + combine_ht_info_pos : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ (((℠× â„) × (℠× â„)) × â„) ☠= + [wi, x, y, xv, yv, g] ⟨⟨⟨get_x_ht x xv (get_hit_time_pos wi x y xv yv g), get_hit_time_pos wi x y xv yv g⟩, ⟨(Ï€l (Ï€r wi)), (Ï€r (Ï€r wi))⟩⟩, (Ï€l (Ï€l wi))⟩ â™ + combine_ht_info_neg : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ (((℠× â„) × (℠× â„)) × â„) ☠= + [wi, x, y, xv, yv, g] ⟨⟨⟨get_x_ht x xv (get_hit_time_neg wi x y xv yv g), get_hit_time_neg wi x y xv yv g⟩, ⟨(Ï€l (Ï€r wi)), (Ï€r (Ï€r wi))⟩⟩, (Ï€l (Ï€l wi))⟩ â™ + + get_m : ((℠× â„) × (℠× â„)) ⟶ ℠☠= [w] times_real_lit (plus_real_lit (Ï€r (Ï€r w)) (minus_real_lit (Ï€r (Ï€l w)))) (inv_real_lit (plus_real_lit (Ï€l (Ï€r w)) (minus_real_lit (Ï€l (Ï€l w))))) â™ + get_c : (℠× â„) ⟶ ℠⟶ ℠☠= [w][m] plus_real_lit (Ï€r w) (minus_real_lit (times_real_lit (Ï€l w) m)) â™ + get_mc : ((℠× â„) × (℠× â„)) ⟶ ((℠× â„) × (℠× â„)) ☠= [w] ⟨⟨get_m w, get_c (Ï€l w) (get_m w)⟩, ⟨πl (Ï€l w), Ï€l (Ï€r w)⟩⟩ â™ + + reduce_list_ht_pos : List[(℠× â„) × (℠× â„)] ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ List[((℠× â„) × (℠× â„)) × â„] ☠= + [wsi, x, y, xv, yv, g] (((wsi map ([wi] combine_ht_info_pos wi x y xv yv g)) filter ([wib] check_hit (Ï€l wib))) filter ([wib] check_hit2 (Ï€l wib))) filter ([wib] check_hit3 (Ï€l wib)) â™ + reduce_list_ht_neg : List[(℠× â„) × (℠× â„)] ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ List[((℠× â„) × (℠× â„)) × â„] ☠= + [wsi, x, y, xv, yv, g] (((wsi map ([wi] combine_ht_info_neg wi x y xv yv g)) filter ([wib] check_hit (Ï€l wib))) filter ([wib] check_hit2 (Ï€l wib))) filter ([wib] check_hit3 (Ï€l wib)) â™ + prep : List[(℠× â„) × (℠× â„)] ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ☠= + [wsi, x, y, xv, yv, g] ⟨⟨x, y⟩, ⟨xv, yv⟩, (reduce_list_ht_pos wsi x y xv yv g) fold ((reduce_list_ht_neg wsi x y xv yv g) fold ⟨99999.9, -1.0⟩ fold_func) fold_func ⟩ â™ + get_next_vals : List[(℠× â„) × (℠× â„)] ⟶ (℠× â„) ⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ☠= + [wsi, bv, v] ([x : ((℠× â„) × (℠× â„))] ⟨⟨πl (Ï€l x), Ï€r (Ï€l x)⟩, ⟨πl (Ï€r x), Ï€r (Ï€r x)⟩, (reduce_list_ht_pos wsi (Ï€l (Ï€l x)) (Ï€r (Ï€l x)) (Ï€l (Ï€r x)) (Ï€r (Ï€r x)) (Ï€l bv)) fold ((reduce_list_ht_neg wsi (Ï€l (Ï€l x)) (Ï€r (Ï€l x)) (Ï€l (Ï€r x)) (Ï€r (Ï€r x)) (Ï€l bv)) fold ⟨99999.9, -1.0⟩ fold_func) fold_func ⟩) (calc_new_vals bv v) â™ + end_cond : ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ bool ☠= + [vals] leq_real_lit (Ï€l (Ï€r (Ï€r vals))) 0.1 â™ + red_ht : ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ ℠☠= + [cele] Ï€l (Ï€r (Ï€r cele)) â™ + get_pos_fun: ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ (℠⟶ (℠× â„)) ☠= + [x,y,xv,yv,g] ([t] ⟨plus_real_lit x (times_real_lit xv t), plus_real_lit (times_real_lit (times_real_lit 0.5 g) (times_real_lit t t)) (plus_real_lit y (times_real_lit yv t))⟩ ) â™ + my_list: List[(℠× â„) × (℠× â„) × (℠× â„)] ☠= stepUntilX ((℠× â„) × (℠× â„) × (℠× â„)) List[(℠× â„) × (℠× â„)] (℠× â„) ((cons ⟨⟨-10000.0, 0.0⟩, ⟨10000.0, 0.0⟩⟩ (cons ⟨⟨0.0, -1000.0⟩, ⟨0.1, 1000.0⟩⟩ (cons ⟨⟨50.0, -150.0⟩, ⟨50.1, 150.0⟩⟩ nil))) map get_mc) ⟨-200.0, 0.5⟩ (prep ((cons ⟨⟨-10000.0, 0.0⟩, ⟨10000.0, 0.0⟩⟩ (cons ⟨⟨0.0, -1000.0⟩, ⟨0.1, 1000.0⟩⟩ (cons ⟨⟨50.0, -150.0⟩, ⟨50.1, 150.0⟩⟩ nil))) map get_mc) 200.0 300.0 (-100.0) 100.0 (-200.0)) get_next_vals end_cond â™ + //my_list: ℠☠= stepUntil â„ 0.0 ([x: â„] plus_real_lit x 1.0) ([x: â„] leq_real_lit 10.0 x) â™ + // full_list + : List[ â„×â„×(â„×â„)×(â„×â„)] + = stepUntilX (â„×â„×(â„×â„)×(â„×â„)) List[ â„×â„×(â„×â„)] (â„×â„) cons ⟨⟨0.0,0.0⟩,⟨-10000.0,10000.0⟩⟩ nil ⟨-200.0,0.5⟩ ⟨⟨200.0,300.0⟩,⟨-100.0,100.0⟩,⟨2.302775638,0.0⟩⟩ [wsi,bv,v]([xt:â„×â„×(â„×â„)]⟨⟨πl Ï€l xt,Ï€r Ï€l xt⟩,⟨πl Ï€r xt,Ï€r Ï€r xt⟩,(([wsit,x,y,xv,yv,g]wsit map [wi]([wi,x,y,xv,yv,g]⟨⟨⟨([x,xv,ht]x+(xv×ht)) x xv (([wi,x,y,xv,yv,g]gâ»Â¹Ã—((Ï€l Ï€l wi)×xv)+-yv+-(sqrt (yv+-((Ï€l Ï€l wi)×xv)×yv+-((Ï€l Ï€l wi)×xv))+-(2.0×g×y+-((Ï€l Ï€l wi)×x)+-Ï€r Ï€l wi))) wi x y xv yv g),([wi,x,y,xv,yv,g]gâ»Â¹Ã—((Ï€l Ï€l wi)×xv)+-yv+-(sqrt (yv+-((Ï€l Ï€l wi)×xv)×yv+-((Ï€l Ï€l wi)×xv))+-(2.0×g×y+-((Ï€l Ï€l wi)×x)+-Ï€r Ï€l wi))) wi x y xv yv g⟩,⟨πl Ï€r wi,Ï€r Ï€r wi⟩⟩,Ï€l Ï€l wi⟩) wi x y xv yv g) wsi (Ï€l Ï€l xt) (Ï€r Ï€l xt) (Ï€l Ï€r xt) (Ï€r Ï€r xt) Ï€l bv) fold ⟨99999.9,-1.0⟩ [cur][acc](â„×â„) ifx (leq_real_lit (Ï€l acc) Ï€r Ï€l Ï€l cur) thenx acc elsex ⟨πr Ï€l Ï€l cur,Ï€r cur⟩⟩) (([bv,v]⟨⟨(Ï€l Ï€l v)+((Ï€l Ï€l Ï€r v)×πl Ï€r Ï€r v),(Ï€r Ï€l v)+((Ï€r Ï€l Ï€r v)×πl Ï€r Ï€r v)+(0.5×πl bv×((Ï€l Ï€r Ï€r v)×πl Ï€r Ï€r v))⟩,⟨(Ï€r bv)×(Ï€l Ï€l Ï€r v)+(2.0×πr Ï€r Ï€r v×(Ï€r Ï€l Ï€r v)+-((Ï€r Ï€r Ï€r v)×πl Ï€l Ï€r v)×(1.0+((Ï€r Ï€r Ï€r v)×πr Ï€r Ï€r v))â»Â¹),(Ï€r bv)×(Ï€r Ï€l Ï€r v)+((Ï€l bv)×πl Ï€r Ï€r v)+-(2.0×(Ï€r Ï€l Ï€r v)+((Ï€l bv)×πl Ï€r Ï€r v)+-((Ï€r Ï€r Ï€r v)×πl Ï€l Ï€r v)×(1.0+((Ï€r Ï€r Ï€r v)×πr Ï€r Ï€r v))â»Â¹)⟩⟩) bv v) [vals]leq_real_lit (Ï€l Ï€r Ï€r vals) 0.1 â™ + + //iterated_fun: List[ â„×â„×(â„×â„)] ⟶ (â„×â„) ⟶ (â„×â„×(â„×â„)×(â„×â„)) ⟶ (â„×â„×(â„×â„)) ⟶ (â„×â„×(â„×â„)×(â„×â„)) ☠+ = [wsi,bv,v,xt] ⟨⟨πl Ï€l xt,Ï€r Ï€l xt⟩,⟨πl Ï€r xt,Ï€r Ï€r xt⟩,(([wsit: List[(℠× â„) × (℠× â„)],x: â„,y: â„,xv: â„,yv: â„,g: â„]wsit map [wi: (℠× â„) × (℠× â„)]([wi: (℠× â„) × (℠× â„), x: â„,y: â„, xv: â„, yv: â„, g: â„]⟨⟨⟨([x: â„,xv: â„,ht: â„]x+(xv×ht)) x xv (([wi: (℠× â„) × (℠× â„), x: â„,y: â„, xv: â„, yv: â„, g: â„]gâ»Â¹Ã—((Ï€l Ï€l wi)×xv)+-yv+-(sqrt (yv+-((Ï€l Ï€l wi)×xv)×yv+-((Ï€l Ï€l wi)×xv))+-(2.0×g×y+-((Ï€l Ï€l wi)×x)+-Ï€r Ï€l wi))) wi x y xv yv g),([wi: (℠× â„) × (℠× â„), x: â„,y: â„, xv: â„, yv: â„, g: â„]gâ»Â¹Ã—((Ï€l Ï€l wi)×xv)+-yv+-(sqrt (yv+-((Ï€l Ï€l wi)×xv)×yv+-((Ï€l Ï€l wi)×xv))+-(2.0×g×y+-((Ï€l Ï€l wi)×x)+-Ï€r Ï€l wi))) wi x y xv yv g⟩,⟨πl Ï€r wi,Ï€r Ï€r wi⟩⟩,Ï€l Ï€l wi⟩) wi x y xv yv g) wsi (Ï€l Ï€l xt) (Ï€r Ï€l xt) (Ï€l Ï€r xt) (Ï€r Ï€r xt) Ï€l bv) fold ⟨99999.9,-1.0⟩ [cur: ((℠× â„) × (℠× â„)) × â„][acc: ℠× â„](â„×â„) ifx (leq_real_lit (Ï€l acc) Ï€r Ï€l Ï€l cur) thenx acc elsex ⟨πr Ï€l Ï€l cur,Ï€r cur⟩⟩ â™ + + + // (([bv,v]⟨⟨(Ï€l Ï€l v)+((Ï€l Ï€l Ï€r v)×πl Ï€r Ï€r v),(Ï€r Ï€l v)+((Ï€r Ï€l Ï€r v)×πl Ï€r Ï€r v)+(0.5×πl bv×((Ï€l Ï€r Ï€r v)×πl Ï€r Ï€r v))⟩,⟨(Ï€r bv)×(Ï€l Ï€l Ï€r v)+(2.0×πr Ï€r Ï€r v×(Ï€r Ï€l Ï€r v)+-((Ï€r Ï€r Ï€r v)×πl Ï€l Ï€r v)×(1.0+((Ï€r Ï€r Ï€r v)×πr Ï€r Ï€r v))â»Â¹),(Ï€r bv)×(Ï€r Ï€l Ï€r v)+((Ï€l bv)×πl Ï€r Ï€r v)+-(2.0×(Ï€r Ï€l Ï€r v)+((Ï€l bv)×πl Ï€r Ï€r v)+-((Ï€r Ï€r Ï€r v)×πl Ï€l Ï€r v)×(1.0+((Ï€r Ï€r Ï€r v)×πr Ï€r Ï€r v))â»Â¹)⟩⟩) bv v) â™ +âš diff --git a/source/Scrolls/WBouncingScroll.mmt b/source/Scrolls/WBouncingScroll.mmt new file mode 100644 index 0000000..6c645cd --- /dev/null +++ b/source/Scrolls/WBouncingScroll.mmt @@ -0,0 +1,83 @@ +namespace http://mathhub.info/FrameIT/frameworld âš + +import base http://mathhub.info/MitM/Foundation âš +import arith http://mathhub.info/MitM/core/arithmetics âš +import rules scala://datatypes.LFX.mmt.kwarc.info âš + +fixmeta ?FrameworldMeta âš + +theory WBouncingScroll = + meta ?MetaAnnotations?problemTheory ?WBouncingScroll/Problem â™ + meta ?MetaAnnotations?solutionTheory ?WBouncingScroll/Solution â™ + rule rules?FilterRule (true) â™ + include ?IfThenElseX â™ + include ?StepUntilX â™ + + theory funcs = + calc_new_vals : (℠× â„) ⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ ((℠× â„) × (℠× â„)) ☠= + [bv, v] ⟨⟨plus_real_lit (Ï€l (Ï€l v)) (times_real_lit (Ï€l (Ï€l (Ï€r v))) (Ï€l (Ï€r (Ï€r v)))), plus_real_lit (plus_real_lit (Ï€r (Ï€l v)) (times_real_lit (Ï€r (Ï€l (Ï€r v))) (Ï€l (Ï€r (Ï€r v))))) (times_real_lit (times_real_lit 0.5 (Ï€l bv)) (times_real_lit (Ï€l (Ï€r (Ï€r v))) (Ï€l (Ï€r (Ï€r v)))))⟩, ⟨ times_real_lit (Ï€r bv) (plus_real_lit (Ï€l (Ï€l (Ï€r v))) (times_real_lit (times_real_lit (times_real_lit 2.0 (Ï€r (Ï€r (Ï€r v)))) (plus_real_lit (plus_real_lit (Ï€r (Ï€l (Ï€r v))) (times_real_lit (Ï€l bv) (Ï€l (Ï€r (Ï€r v))))) (minus_real_lit (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€l (Ï€l (Ï€r v))))))) (inv_real_lit (plus_real_lit 1.0 (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€r (Ï€r (Ï€r v)))))))), times_real_lit (Ï€r bv) (plus_real_lit (plus_real_lit (Ï€r (Ï€l (Ï€r v))) (times_real_lit (Ï€l bv) (Ï€l (Ï€r (Ï€r v))))) (minus_real_lit (times_real_lit (times_real_lit 2.0 (plus_real_lit (plus_real_lit (Ï€r (Ï€l (Ï€r v))) (times_real_lit (Ï€l bv) (Ï€l (Ï€r (Ï€r v))))) (minus_real_lit (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€l (Ï€l (Ï€r v))))))) (inv_real_lit (plus_real_lit 1.0 (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€r (Ï€r (Ï€r v)))))))))⟩⟩ â™ + fold_func : (((℠× â„) × (℠× â„)) × â„) ⟶ (℠× â„) ⟶ (℠× â„) ☠= + [cur][acc] (℠× â„) ifx (leq_real_lit (Ï€l acc) (Ï€r (Ï€l (Ï€l cur)))) thenx acc elsex ⟨πr (Ï€l (Ï€l cur)), Ï€r cur⟩ â™ + check_hit : ((℠× â„) × (℠× â„)) ⟶ bool ☠= + [p] leq_real_lit 0.000001 (Ï€r (Ï€l p)) â™ + check_hit2 : ((℠× â„) × (℠× â„)) ⟶ bool ☠= + [p] leq_real_lit (Ï€l (Ï€r p)) (Ï€l (Ï€l p)) â™ + check_hit3 : ((℠× â„) × (℠× â„)) ⟶ bool ☠= + [p] leq_real_lit (Ï€l (Ï€l p)) (Ï€r (Ï€r p)) â™ + get_hit_time_pos : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠☠= + [wi, x, y, xv, yv, g] times_real_lit (inv_real_lit g) (plus_real_lit (plus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv) (minus_real_lit yv)) (sqrt ( plus_real_lit (times_real_lit (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv))) (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv)))) (minus_real_lit (times_real_lit (times_real_lit 2.0 g) (plus_real_lit (plus_real_lit y (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) x))) (minus_real_lit (Ï€r (Ï€l wi))))))))) â™ + get_hit_time_neg : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠☠= + [wi, x, y, xv, yv, g] times_real_lit (inv_real_lit g) (plus_real_lit (plus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv) (minus_real_lit yv)) (minus_real_lit (sqrt ( plus_real_lit (times_real_lit (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv))) (plus_real_lit yv (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) xv)))) (minus_real_lit (times_real_lit (times_real_lit 2.0 g) (plus_real_lit (plus_real_lit y (minus_real_lit (times_real_lit (Ï€l (Ï€l wi)) x))) (minus_real_lit (Ï€r (Ï€l wi)))))))))) â™ + get_x_ht : ℠⟶ ℠⟶ ℠⟶ ℠☠= [x, xv, ht] plus_real_lit x (times_real_lit xv ht) â™ + + combine_ht_info_pos : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ (((℠× â„) × (℠× â„)) × â„) ☠= + [wi, x, y, xv, yv, g] ⟨⟨⟨get_x_ht x xv (get_hit_time_pos wi x y xv yv g), get_hit_time_pos wi x y xv yv g⟩, ⟨(Ï€l (Ï€r wi)), (Ï€r (Ï€r wi))⟩⟩, (Ï€l (Ï€l wi))⟩ â™ + combine_ht_info_neg : ((℠× â„) × (℠× â„)) ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ (((℠× â„) × (℠× â„)) × â„) ☠= + [wi, x, y, xv, yv, g] ⟨⟨⟨get_x_ht x xv (get_hit_time_neg wi x y xv yv g), get_hit_time_neg wi x y xv yv g⟩, ⟨(Ï€l (Ï€r wi)), (Ï€r (Ï€r wi))⟩⟩, (Ï€l (Ï€l wi))⟩ â™ + + get_m : ((℠× â„) × (℠× â„)) ⟶ ℠☠= [w] times_real_lit (plus_real_lit (Ï€r (Ï€r w)) (minus_real_lit (Ï€r (Ï€l w)))) (inv_real_lit (plus_real_lit (Ï€l (Ï€r w)) (minus_real_lit (Ï€l (Ï€l w))))) â™ + get_c : (℠× â„) ⟶ ℠⟶ ℠☠= [w][m] plus_real_lit (Ï€r w) (minus_real_lit (times_real_lit (Ï€l w) m)) â™ + get_mc : ((℠× â„) × (℠× â„)) ⟶ ((℠× â„) × (℠× â„)) ☠= [w] ⟨⟨get_m w, get_c (Ï€l w) (get_m w)⟩, ⟨πl (Ï€l w), Ï€l (Ï€r w)⟩⟩ â™ + + reduce_list_ht_pos : List[(℠× â„) × (℠× â„)] ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ List[((℠× â„) × (℠× â„)) × â„] ☠= + [wsi, x, y, xv, yv, g] (((wsi map ([wi] combine_ht_info_pos wi x y xv yv g)) filter ([wib] check_hit (Ï€l wib))) filter ([wib] check_hit2 (Ï€l wib))) filter ([wib] check_hit3 (Ï€l wib)) â™ + reduce_list_ht_neg : List[(℠× â„) × (℠× â„)] ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ List[((℠× â„) × (℠× â„)) × â„] ☠= + [wsi, x, y, xv, yv, g] (((wsi map ([wi] combine_ht_info_neg wi x y xv yv g)) filter ([wib] check_hit (Ï€l wib))) filter ([wib] check_hit2 (Ï€l wib))) filter ([wib] check_hit3 (Ï€l wib)) â™ + prep : List[(℠× â„) × (℠× â„)] ⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ☠= + [wsi, x, y, xv, yv, g] ⟨⟨x, y⟩, ⟨xv, yv⟩, (reduce_list_ht_pos wsi x y xv yv g) fold ((reduce_list_ht_neg wsi x y xv yv g) fold ⟨99999.9, -1.0⟩ fold_func) fold_func ⟩ â™ + get_next_vals : List[(℠× â„) × (℠× â„)] ⟶ (℠× â„) ⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ ((℠× â„) × (℠× â„) × (℠× â„)) ☠= + [wsi, bv, v] ([x : ((℠× â„) × (℠× â„))] ⟨⟨πl (Ï€l x), Ï€r (Ï€l x)⟩, ⟨πl (Ï€r x), Ï€r (Ï€r x)⟩, (reduce_list_ht_pos wsi (Ï€l (Ï€l x)) (Ï€r (Ï€l x)) (Ï€l (Ï€r x)) (Ï€r (Ï€r x)) (Ï€l bv)) fold ((reduce_list_ht_neg wsi (Ï€l (Ï€l x)) (Ï€r (Ï€l x)) (Ï€l (Ï€r x)) (Ï€r (Ï€r x)) (Ï€l bv)) fold ⟨99999.9, -1.0⟩ fold_func) fold_func ⟩) (calc_new_vals bv v) â™ + end_cond : ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ bool ☠= + [vals] leq_real_lit (Ï€l (Ï€r (Ï€r vals))) 0.1 â™ + red_ht : ((℠× â„) × (℠× â„) × (℠× â„)) ⟶ ℠☠= + [cele] Ï€l (Ï€r (Ï€r cele)) â™ + get_pos_fun: ℠⟶ ℠⟶ ℠⟶ ℠⟶ ℠⟶ (℠⟶ (℠× â„)) ☠= + [x,y,xv,yv,g] ([t] ⟨plus_real_lit x (times_real_lit xv t), plus_real_lit (times_real_lit (times_real_lit 0.5 g) (times_real_lit t t)) (plus_real_lit y (times_real_lit yv t))⟩ ) â™ + âš + // start position and velocity â™ + theory Problem = + include ?WBouncingScroll/funcs â™ + xposition: ℠☠meta ?MetaAnnotations?label "X" â™ + yposition: ℠☠meta ?MetaAnnotations?label "Y" â™ + xvelocity: ℠☠meta ?MetaAnnotations?label "XV" â™ + yvelocity: ℠☠meta ?MetaAnnotations?label "YV" â™ + g_base: ℠☠meta ?MetaAnnotations?label "G" â™ + bounce: ℠☠meta ?MetaAnnotations?label "BO" â™ + walls: List[(℠× â„) × (℠× â„)] ☠meta ?MetaAnnotations?label "Walls" â™ + âš + + // the output of the scroll â™ + + theory Solution = + include ?WBouncingScroll/Problem â™ + //mcws : List[(℠× â„) × (℠× â„)] ☠= get_mc_list walls â™ + //basev : ((℠× â„) × (℠× â„) × (℠× â„)) ☠= prep (walls map get_mc) xposition yposition xvelocity yvelocity g_base â™ + //nextv : ((℠× â„) × (℠× â„) × (℠× â„)) ☠= get_next_vals (walls map get_mc ) ⟨g_base, bounce⟩ basev â™ + //nextv2 : ((℠× â„) × (℠× â„) × (℠× â„)) ☠= get_next_vals (walls map get_mc ) ⟨g_base, bounce⟩ nextv â™ + full_list: List[(℠× â„) × (℠× â„) × (℠× â„)] ☠= stepUntilX ((℠× â„) × (℠× â„) × (℠× â„)) List[(℠× â„) × (℠× â„)] (℠× â„) (walls map get_mc) ⟨g_base, bounce⟩ (prep (walls map get_mc) xposition yposition xvelocity yvelocity g_base) get_next_vals end_cond â™ + ht_list: List[â„] ☠= full_list map ([xele] red_ht xele) â™ + fun_list : List[℠⟶ (℠× â„)] ☠= full_list map ([vals] get_pos_fun (Ï€l (Ï€l vals)) (Ï€r (Ï€l vals)) (Ï€l (Ï€l (Ï€r vals))) (Ï€r (Ï€l (Ï€r vals))) g_base) â™ + meta ?MetaAnnotations?label "WBouncingScroll" â™ + meta ?MetaAnnotations?description s"Bouncing " â™ + âš +âš \ No newline at end of file diff --git a/source/dynamics.mmt b/source/dynamics.mmt index 31bf8cf..48c12aa 100644 --- a/source/dynamics.mmt +++ b/source/dynamics.mmt @@ -10,8 +10,12 @@ theory StepUntil = //stepUntil : {X: type} X ⟶ (X ⟶ X) ⟶ (X ⟶ bool) ⟶ X ☠# stepUntil 1 2 3 4 â™ rule rules?StepUntilRule (true) â™ âš +theory StepUntilX = + stepUntilX : {A: type}{B: type}{C: type} B ⟶ C ⟶ A ⟶ (B ⟶ C ⟶ A ⟶ A) ⟶ (A ⟶ bool) ⟶ List[A] ☠# stepUntilX 1 2 3 4 5 6 7 8 â™ + rule rules?StepUntilXRule (true) â™ +âš theory IfThenElseX = // {X: type} X ⟶ (X ⟶ X) ⟶ (X ⟶ bool) ⟶ List[X] â™ - ifthenelsex : {X: type} bool ⟶ X ⟶ X ⟶ X ☠# ifx 2 thenx 3 elsex 4 â™ + ifthenelsex : {X: type} bool ⟶ X ⟶ X ⟶ X ☠# 1 ifx 2 thenx 3 elsex 4 â™ rule rules?IfThenElseRuleX (true) (false) â™ âš -- GitLab