https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
mathematics
  • s

    Simon Schubert

    10/21/2019, 4:30 PM
    Today I tried to get the decimal of a float. Particularly I want to check if the decimal is
    33
    or
    66
    . So I wrote a function like
    value - value.toInt()
    which returns e.g.
    0.33f
    . I thought it works fine. But today I noticed that for some values it doesn’t work. For example:
    8.33 returns 0.32999992
    . I assume it's already a known bug? Anyway I found that very odd. Whats an efficient workaround?
    for(i in 0..8) {
        println("${8.33f - i}")
    }
    returns
    8.33
    7.33
    6.33
    5.33
    4.33
    3.33
    2.33
    1.3299999
    0.32999992
    1.3.50 jvm
    e
    • 2
    • 4
  • a

    altavir

    12/07/2019, 8:40 AM
    @breandan today I had a very brief discussion with Breslav and @elizarov about type-safe matrix dimensions. They think that it could make sense for some tasks, so I will probably will give another try to your idea. Currently 2D-strucutres are thin inline wrappers around ND-structures, so it should be quite easy to add another inline wrapper with type-based dimensions without breaking anything. I will create a prototype based on your ideas and we can discuss it after that.
    b
    • 2
    • 1
  • a

    altavir

    12/08/2019, 2:24 PM
    I was running some performance tests on https://github.com/JetBrains-Research/viktor (it adds native SIMD support to simple matrix operations) with GraalVM. While without GraalVM, native SIMD is slightly faster (less than 2 times), with it, JVM runs two times faster without native boost (kmath
    RealField
    ). It is not a conclussion, we need to test it further, but I think it is time to forget "native means fast". I've already showed some tests, where kotlin code runs faster than numpy.
    👍 1
    a
    • 2
    • 23
  • a

    altavir

    12/09/2019, 12:42 PM
    @Aleksei Dievskii For log I get comparable results: Automatic field log completed in 7721 millis Raw Viktor log completed in 7067 millis
    a
    • 2
    • 8
  • a

    altavir

    12/09/2019, 4:59 PM
    I've merged type-safe dimensions for matrices which I've prepared some time ago: https://github.com/mipt-npm/kmath/blob/dev/examples/src/main/kotlin/scientifik/kmath/structures/typeSafeDimensions.kt. It is in separate module and is more like a toy example for now. I need more use cases to understand what other wrappers are needed.
    👍 3
    • 1
    • 1
  • j

    Jérémie Labroquère

    01/04/2020, 12:37 PM
    Hi @altavir. It seems that your approach on polynom is fine. A polynom has to be distinguished to a polynomial function. These are two different objects. The former is composed of coefficients (a11, a12, a22, etc.) which are taken from a set such as a commutative ring, and of indeterminates (X, Y...). The second is basically a function, which takes arguments and returns a value. Making the distinction between the two allows you to deal with much more complex polynoms, for example truncated polynom algebra, in example : https://darioizzo.github.io/audi/theory_algebra.html I have a bunch of applications with these....
    a
    • 2
    • 1
  • a

    altavir

    01/29/2020, 3:37 PM
    I am spending some time on working on tables API. The question is about missing values. Does it make sense to add them in API? I mean, that coulmn type is
    T:Any
    , what should be default cell value return type
    T
    or
    T?
    ?
    a
    p
    • 3
    • 8
  • a

    altavir

    04/30/2020, 8:43 AM
    Published a dev build of kmath: https://bintray.com/mipt-npm/dev/kmath-core/0.1.4-dev-4. A lot of new (and very experimental) features since 0.1.3. As always, I really need some discussion to understand where to go first. Currently I am doing some work on distributions and very crude geomertry. Here are the release notest for the pre-release: https://github.com/mipt-npm/kmath/releases/tag/0.1.4-dev-4
    👍 3
    • 1
    • 1
  • a

    altavir

    05/05/2020, 4:22 PM
    Some feedback needed here: https://github.com/mipt-npm/kmath/issues/89. @Peter Klimai wants to implement interface level with krangl. Obviously we need this integration when we want to peform some kind of performance-critical mathematic operations on krangl data. The question is when we should do it and which structures are important.
    p
    • 2
    • 3
  • a

    altavir

    06/10/2020, 5:21 AM
    A vote: `tan`(👈 ) or `tg`(👉 )
    👈 13
    z
    z
    i
    • 4
    • 4
  • a

    altavir

    06/13/2020, 8:07 AM
    @breandan We are in a process of adding AST functionality to kmath: https://github.com/mipt-npm/kmath/tree/adv-expr/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast (inspired by a great contribution by @Iaroslav Postovalov). In KotlinGrad you are probably using something for AST representation. Could you reference tha place in the code and any comments if you have them? I also wonder if we can connect kmath and kotlingrad via AST. We will be able to generate computable expressions from AST for any Algebras and it is possible in some cases to decompile existing expressions to AST.
    👍 4
    b
    • 2
    • 17
  • b

    breandan

    06/23/2020, 9:31 AM
    Someone interested in PL theory might want to check out this stuff: • Describing the syntax of programming languages using conjunctive and Boolean grammars • Formal languages over GF(2) One thing we were trying to do with Kotlingrad was build a mathematically sound representation between functions and fields. The direct way is (1) to define
    Fun<X>: Field<X>
    where
    X
    is a member of some algebra over the reals equipped with the usual operators (when you apply an operator, it is evaluated and you get
    X
    back). Another way is (2) to treat the function as a member of a field whose elements are themselves functions, e.g.
    Fun<X>: Field<Fun<X>>
    , and instead of returning
    X
    , applying an operator instead returns
    Fun<X>
    which can be later evaluated by calling
    invoke(...)
    , returning
    X
    (so
    X
    and
    Fun<X>
    are both fields). It turns out the second representation comes from finite field theory, which has important implications for expression parsing and language design. It would be useful to understand this connection more deeply.
    🤔 1
    a
    • 2
    • 2
  • a

    altavir

    06/27/2020, 2:23 PM
    We-ve just merged an important feature into the kmath dev branch: https://github.com/mipt-npm/kmath/tree/dev/kmath-ast The general idea is to introduce an AST for mathematics (I called it MST). It covers generic singular (constant, numbers), unary operators and binary operators. Using this representation we can now: • parse string expressions (not yet fully functional, we need to update the parser) • Optimize the exression (like caclulate numeric expressions). • Execute it on a given algebra dynamically or even generate a bytecode for optimized computations in ASM. The feature is rather important for integration with automatic differentiation like @breandan's kotlingrad and other powerfull tools, maybe even symbolic algebra. The asm feature was fully contributed by @Iaroslav Postovalov and he did a lot to drive the feature. I've made a dev release especially for the feature: https://github.com/mipt-npm/kmath/releases/tag/0.1.4-dev-8 (it is available on the bintray in dev repository). It is not by any means finished, since we still need to improve it and understand how to work with it better. Any feedback is really appreciated.
    👍 6
    z
    • 2
    • 2
  • i

    Iaroslav Postovalov

    06/27/2020, 2:26 PM
    Partial documentation for
    kmath-ast
    module: https://github.com/mipt-npm/kmath/blob/dev/kmath-ast/README.md
    ✔️ 3
    🎉 2
    👍 1
    p
    a
    • 3
    • 3
  • b

    breandan

    07/26/2020, 4:11 PM
    @altavir @Iaroslav Postovalov Not sure if you’ve heard of it, but there was an old DSL at Sun called Fortress, parts of which may be useful for KMath. It had some similar design goals: stephane.ducasse.free.fr/Teaching/CoursAnnecy/0506-Master/ForPresentations/Fortress-PLDITutorialSlides9Jun2006.pdf
    a
    i
    • 3
    • 9
  • b

    breandan

    07/26/2020, 7:13 PM
    https://github.com/eobermuhlner/kotlin-big-math#comparison-with-standard-kotlin-library
    i
    u
    a
    • 4
    • 14
  • a

    altavir

    07/29/2020, 10:03 AM
    Here is the promised article by @Iaroslav Postovalov about AST-based optimization of kmath expressions during runtime: https://medium.com/@postovalovya/expression-optimization-with-jvm-bytecode-generation-b50304b96619
    👍 4
    i
    i
    • 3
    • 18
  • e

    emedinaa

    08/20/2020, 3:07 PM
    hi! , playing with bezier curve https://github.com/emedinaa/math-experiments
    bezier_smile.mov
    i
    a
    • 3
    • 8
  • b

    breandan

    08/22/2020, 6:05 AM
    https://github.com/ytheohar/koptim
    a
    р
    • 3
    • 14
  • b

    breandan

    08/22/2020, 6:17 AM
    https://softwareengineering.stackexchange.com/questions/316969/why-do-most-mainstream-languages-not-support-x-y-z-syntax-for-3-way-boolea
    a
    • 2
    • 2
  • a

    altavir

    09/13/2020, 12:09 PM
    Considering Big Numbers. @Iaroslav Postovalov made some benchmarks for kmath BigInt implemented by Robert Drynkin and @Peter Klimai, JDK BigInt and https://github.com/ionspin/kotlin-multiplatform-bignum by @Ugi. It seems that our implementation is even a bit faster than JDK and much faster (two times) than the one by @Ugi. I intended to drop our implementation in favor of extenral library, but now it does not make sense to do that. Kmath relies on a tiny fraction of BigInt functionality and we do not intend to support the whole spectrum of fetures, so I am not sure what to do next. Should we maintain two separate multiplatform bigint implementations (one for special features and one for Algebra compatibility or try to improve @Ugi implementation?
    u
    • 2
    • 3
  • a

    altavir

    10/04/2020, 8:40 AM
    Talking-kotlin issue with @breandan: https://talkingkotlin.com/maths-and-kotlin/
    🎉 4
    i
    • 2
    • 1
  • b

    bjonnh

    10/12/2020, 11:14 PM
    Do we have something equivalent to scipy.optimize.curve_fit ?
    a
    • 2
    • 1
  • b

    bjonnh

    10/12/2020, 11:32 PM
    I'm surprised to not even find a Java library that can do that (automatic differentiation and all of that)
    a
    b
    • 3
    • 22
  • b

    bjonnh

    10/20/2020, 7:54 PM
    and you can write your equations using basic python syntax
    a
    • 2
    • 3
  • b

    bjonnh

    10/20/2020, 7:55 PM
    I can get inspiration from that
    a
    • 2
    • 4
  • a

    altavir

    10/22/2020, 6:39 AM
    This snipped shows different ways of bindings. The first example shows standard eager binding( forward declaration. It could be made in a type safe way as shown in the original file. The second example shows lazy binding via expression API. Againg, you thoghts are really appreciated.
    bindings.kt
    b
    • 2
    • 4
  • a

    altavir

    10/24/2020, 5:30 PM
    @bjonnh I was playing with new symbol API and I managed to befriend it with autodiff and commons math optimization. It is still very preliminary since I did not manage to make commons-math optimization safe enough, but the example from this test works fine both with simplex and gradient descent.
    optimization API
    b
    • 2
    • 5
  • b

    breandan

    10/29/2020, 4:11 AM
    Hi @Iaroslav Postovalov, great question! It depends on what you mean by "order" as the term is slightly overloaded. If you mean the order of partial derivative evaluation, then under some weak assumptions, the derivative operator is commutative. This result (see Clairaut-Schwarz) holds on all twice-differentiable functions. However, it is not necessarily true on all differentiable functions! I.e it is possible to have a continuously differentiable function whose partials are defined everywhere but the permuted partials are unequal ∂F²/∂x∂y ≠ ∂F²/∂y∂x. For some examples of continuously differentiable functions where the derivative operator is noncommutative, see Tolstov (1949, 1949). On the other hand, if by "order", you mean "higher order derivatives", then this is a slightly different (although related) question. In general, I find it is helpful to first write down a test case describing the behavior you expect, e.g.:
    assertEquals(f.derivativeOrNull(mapOf(x to 2)), f.derivativeOrNull(mapOf(x to 1)).derivativeOrNull(mapOf(x to 1)))
    . This helps to clarify what is meant by
    derivativeOrNull(orders: Map<Symbol, Int>): Expression<T>
    and suggests one possible implementation. Assuming you only care about
    SFun
    and
    SVar
    then it should be possible to define
    derivativeOrNull
    using
    fold
    , noting the above restrictions on evaluation order. More generally, due to the semantics of mixing partial derivatives, depending how
    Map
    is implemented, you cannot assume
    f.derivativeOrNull(mapOf(y to 1)).derivativeOrNull(mapOf(x to 1)) == f.derivativeOrNull(mapOf(x to 1, y to 1))
    without knowing more about the function under differentiation. To implement
    derivativeOrNull
    correctly, you would need a data structure whose traversal order preserves the semantics of the end-user program. Although it is possible to implement something like
    OrderPreservingMap
    , I would just use
    List<Symbol>
    . Then your implementation becomes cleaner:
    public override fun derivativeOrNull(orders: List<Symbol>): Expression<T> = 
        orders.map { MstAlgebra.symbol(it.identity).toSVar(proto) }
          .fold(mst.toSFun(proto)) { result, sVar -> result.d(sVar) } // This will produce Derivative(...Derivative(mst.toSFun(proto))...)
          .invoke() // Do you want to evaluate it?
          .toKMathExpression()
    i
    a
    • 3
    • 10
  • i

    Iaroslav Postovalov

    10/29/2020, 5:15 PM
    @breandan what does it mean? Declared repositories are
    a
    b
    • 3
    • 9
Powered by Linen
Title
i

Iaroslav Postovalov

10/29/2020, 5:15 PM
@breandan what does it mean? Declared repositories are
a

altavir

10/29/2020, 5:19 PM
The jitpack is not stable. You need to check the build status there. https://jitpack.io/#com.github.breandan/kotlingrad
b

breandan

10/29/2020, 5:19 PM
I guess you may need to add
implementation("com.github.breandan:kaliningraph:0.1.2")
to the dependency block of your
build.gradle.kts
file
Weird, thanks for reporting
We used to build a fatjar, but I recently fiddled with the build process so maybe something was broken
a

altavir

10/29/2020, 5:22 PM
You are using composite build here: https://github.com/breandan/kotlingrad/blob/736d6c0924d238dc5c954e72c472a79c21705a18/settings.gradle.kts#L5-L9
Why do you need fatjar? Why not deploy all required artifacts?
b

breandan

10/29/2020, 5:24 PM
I forget exactly why but think there was a version conflict in one of the dependencies, it needs to be reconsidered in the next release
I just tested this build script on a new project which seemed to work: https://gist.github.com/breandan/bea383441918f424b54afac632c757a9
i

Iaroslav Postovalov

10/29/2020, 5:33 PM
That was jitpack glitch.
👍 2
View count: 4