Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abbreviation of evaluated conflicts with built-in function eval #22

Open
linuxrider opened this issue Jan 23, 2024 · 2 comments
Open

Abbreviation of evaluated conflicts with built-in function eval #22

linuxrider opened this issue Jan 23, 2024 · 2 comments

Comments

@linuxrider
Copy link

The abbreviation of evaluated conflicts with typst built-in function eval.

@Leedehai
Copy link
Owner

Leedehai commented Jan 24, 2024

I'd prefer not to rename physica's eval because

  • Typst's eval is not that frequently used, and
  • I'd like to keep the name short and memorable, especially eval is the macro name in the LaTeX physics package

As a workaround, you may rename eval while importing if you would also want to keep access to Typst's eval at the same time.

#import "@preview/physica:0.9.2": .., eval as evalat

I understand users like doing wildcard imports (that is, import everything: #import "...": *), so I proposed typst/typst#3068 to optionally hide symbols after discovering they'd like to use some symbols eclipsed by the import (instead of having to delete the * and write out every symbol they have ever used in the doc -- very bad UX), like the Dart language. But that proposal was "not liked at all" and my reasons were deemed "completely unfounded", so it was closed.

Maybe give a bump to Typst's typst/typst#1639, which proposes another way to access the native Typst symbols that are otherwise eclipsed by imports :)

@linuxrider
Copy link
Author

I understand. Is this naming conflict documented somewhere?

This is my use case of typst's eval.

#import "@preview/cetz:0.2.0": canvas, plot, draw

#let E-hermitepsi = ((0, "1/(calc.sqrt(calc.sqrt(calc.pi)))*(1 * f)"), (1, "1/(calc.sqrt(calc.sqrt(4*calc.pi)))*(2 * y * f)"), (2, "1/(calc.sqrt(calc.sqrt(64*calc.pi)))*(4 * y * y - 2) * f"), (3, "1/(calc.sqrt(calc.sqrt(2304*calc.pi)))*(8 * y * y * y - 12 * y)*f"))
#figure(
  grid(
    columns: 2,     // 2 means 2 auto-sized columns
    gutter: 2mm,    // space between columns
    canvas(length: 1.2cm, {
      import draw: *
      plot.plot(
        size: (5, 10),
        x-tick-step: 2,
        x-label: [$y$],
        // x-ticks: ( (0, $0$), (1, $a$)),
        y-label: [$V(x)$, #text([$E$], fill:blue), #text([$psi(y)$], fill:red)],
        y-tick-step: none,
        y-ticks: ((0.5, $v=0$), (1.5, $v=1$), (2.5, $v=2$), (3.5, $v=3$)),
        x-min: -4,
        x-max: 4,
        y-min: 0,
        // y-max: 12,
        {  
          plot.add(style: (stroke: (paint:black)),
            domain: (-3, 3), samples: 100, y => 0.5*y*y
          )
          for (v, hermitepsi) in E-hermitepsi {
            let E = v + 1/2
            let psi(y) = eval(hermitepsi, scope: (y:y, f: calc.exp(-y*y/2)))
              plot.add(style: (stroke: (paint:blue)),
                domain: (-4, 4), samples: 10, y => E
              )
              plot.add(style: (stroke: (paint:red)),
               domain: (-4, 4), samples: 100, y => psi(y) + E
              )
          }
        }
      )
      line(style: (stroke: (thickness: 5pt)), (2.5, 0), (2.5, 10))  
    }),
    canvas(length: 1.2cm, {
      import draw: *
      plot.plot(
        size: (5, 10),
        x-tick-step: 2,
        x-label: [$y$],
        y-label: [$V(x)$, #text([$E$], fill:blue), #text([$psi^2(y)$], fill:red)],
        y-tick-step: none,
        y-ticks: ( (0.5, $v=0$), (1.5, $v=1$),(2.5, $v=2$),(3.5, $v=3$)),
        x-min: -4,
        x-max: 4,
        y-min: 0,
        // y-max: 12,
        {  
          plot.add(style: (stroke: (paint:black)),
            domain: (-3, 3), samples: 100, y => 0.5*y*y
          )
          for (v, hermitepsi) in E-hermitepsi {
            let E = v + 1/2
            let psi(y) = eval(hermitepsi, scope: (y:y, f: calc.exp(-y*y/2), E: E))
            plot.add(style: (stroke: (paint:blue)),
              domain: (-4, 4), samples: 10, y => E
            )
            plot.add(style: (stroke: (paint:red)),
             domain: (-4, 4), samples: 100, y => psi(y) * psi(y) +  E
            )
          }
        }
      )
      line(style: (stroke: (thickness: 5pt)), (2.5, 0), (2.5, 10))
    })
  )
)

harmonic_oscillator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants