?

Average Error: 0.2 → 0.2
Time: 8.8s
Precision: binary64
Cost: 6848

?

\[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
\[\mathsf{fma}\left(\frac{-4}{y}, z - x, 4\right) \]
(FPCore (x y z)
 :precision binary64
 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
(FPCore (x y z) :precision binary64 (fma (/ -4.0 y) (- z x) 4.0))
double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
double code(double x, double y, double z) {
	return fma((-4.0 / y), (z - x), 4.0);
}
function code(x, y, z)
	return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y))
end
function code(x, y, z)
	return fma(Float64(-4.0 / y), Float64(z - x), 4.0)
end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(-4.0 / y), $MachinePrecision] * N[(z - x), $MachinePrecision] + 4.0), $MachinePrecision]
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\mathsf{fma}\left(\frac{-4}{y}, z - x, 4\right)

Error?

Derivation?

  1. Initial program 0.2

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
  2. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-4}{y}, z - x, 4\right)} \]
    Proof

    [Start]0.2

    \[ 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]

    +-commutative [=>]0.2

    \[ \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]

    associate-*l/ [<=]0.2

    \[ \color{blue}{\frac{4}{y} \cdot \left(\left(x + y \cdot 0.75\right) - z\right)} + 1 \]

    fma-def [=>]0.2

    \[ \color{blue}{\mathsf{fma}\left(\frac{4}{y}, \left(x + y \cdot 0.75\right) - z, 1\right)} \]

    metadata-eval [<=]0.2

    \[ \mathsf{fma}\left(\frac{4}{y}, \left(x + y \cdot 0.75\right) - z, \color{blue}{--1}\right) \]

    fma-neg [<=]0.2

    \[ \color{blue}{\frac{4}{y} \cdot \left(\left(x + y \cdot 0.75\right) - z\right) - -1} \]

    +-commutative [=>]0.2

    \[ \frac{4}{y} \cdot \left(\color{blue}{\left(y \cdot 0.75 + x\right)} - z\right) - -1 \]

    associate--l+ [=>]0.2

    \[ \frac{4}{y} \cdot \color{blue}{\left(y \cdot 0.75 + \left(x - z\right)\right)} - -1 \]

    distribute-lft-in [=>]0.2

    \[ \color{blue}{\left(\frac{4}{y} \cdot \left(y \cdot 0.75\right) + \frac{4}{y} \cdot \left(x - z\right)\right)} - -1 \]

    +-commutative [=>]0.2

    \[ \color{blue}{\left(\frac{4}{y} \cdot \left(x - z\right) + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right)} - -1 \]

    *-commutative [<=]0.2

    \[ \left(\color{blue}{\left(x - z\right) \cdot \frac{4}{y}} + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right) - -1 \]

    associate--l+ [=>]0.2

    \[ \color{blue}{\left(x - z\right) \cdot \frac{4}{y} + \left(\frac{4}{y} \cdot \left(y \cdot 0.75\right) - -1\right)} \]
  3. Final simplification0.2

    \[\leadsto \mathsf{fma}\left(\frac{-4}{y}, z - x, 4\right) \]

Alternatives

Alternative 1
Error31.2
Cost1244
\[\begin{array}{l} t_0 := \frac{-4}{y} \cdot z\\ t_1 := 4 \cdot \frac{x}{y}\\ \mathbf{if}\;x \leq -2.5 \cdot 10^{+40}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.5 \cdot 10^{-42}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{-188}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 10^{-275}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+14}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{+64}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error31.2
Cost1244
\[\begin{array}{l} t_0 := \frac{z}{\frac{y}{-4}}\\ t_1 := 4 \cdot \frac{x}{y}\\ \mathbf{if}\;x \leq -4.2 \cdot 10^{+41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-41}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq -6.4 \cdot 10^{-74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-188}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-275}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{+14}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 5.05 \cdot 10^{+64}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error17.0
Cost977
\[\begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+132}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+46} \lor \neg \left(y \leq 10^{+97}\right) \land y \leq 5.5 \cdot 10^{+178}:\\ \;\;\;\;-4 \cdot \frac{z - x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
Alternative 4
Error11.1
Cost977
\[\begin{array}{l} t_0 := -4 \cdot \frac{z - x}{y}\\ \mathbf{if}\;x \leq -3.5 \cdot 10^{+41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-74}:\\ \;\;\;\;4 + -4 \cdot \frac{z}{y}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+40} \lor \neg \left(x \leq 10^{+102}\right):\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error11.5
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+41} \lor \neg \left(x \leq 5.6 \cdot 10^{+60}\right):\\ \;\;\;\;-4 \cdot \frac{z - x}{y}\\ \mathbf{else}:\\ \;\;\;\;4 + -4 \cdot \frac{z}{y}\\ \end{array} \]
Alternative 6
Error29.8
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{+40} \lor \neg \left(x \leq 4.3 \cdot 10^{+64}\right):\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
Alternative 7
Error0.2
Cost576
\[4 + \frac{-4}{y} \cdot \left(z - x\right) \]
Alternative 8
Error36.3
Cost64
\[4 \]

Error

Reproduce?

herbie shell --seed 2023020 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
  :precision binary64
  (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))