Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1

?

Percentage Accurate: 97.7% → 98.4%
Time: 12.6s
Precision: binary64
Cost: 1220

?

\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{+306}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ t (* (/ x y) (- z t)))))
   (if (<= t_1 5e+306) t_1 (/ (* x (- z t)) y))))
double code(double x, double y, double z, double t) {
	return ((x / y) * (z - t)) + t;
}
double code(double x, double y, double z, double t) {
	double t_1 = t + ((x / y) * (z - t));
	double tmp;
	if (t_1 <= 5e+306) {
		tmp = t_1;
	} else {
		tmp = (x * (z - t)) / y;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x / y) * (z - t)) + t
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = t + ((x / y) * (z - t))
    if (t_1 <= 5d+306) then
        tmp = t_1
    else
        tmp = (x * (z - t)) / y
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return ((x / y) * (z - t)) + t;
}
public static double code(double x, double y, double z, double t) {
	double t_1 = t + ((x / y) * (z - t));
	double tmp;
	if (t_1 <= 5e+306) {
		tmp = t_1;
	} else {
		tmp = (x * (z - t)) / y;
	}
	return tmp;
}
def code(x, y, z, t):
	return ((x / y) * (z - t)) + t
def code(x, y, z, t):
	t_1 = t + ((x / y) * (z - t))
	tmp = 0
	if t_1 <= 5e+306:
		tmp = t_1
	else:
		tmp = (x * (z - t)) / y
	return tmp
function code(x, y, z, t)
	return Float64(Float64(Float64(x / y) * Float64(z - t)) + t)
end
function code(x, y, z, t)
	t_1 = Float64(t + Float64(Float64(x / y) * Float64(z - t)))
	tmp = 0.0
	if (t_1 <= 5e+306)
		tmp = t_1;
	else
		tmp = Float64(Float64(x * Float64(z - t)) / y);
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = ((x / y) * (z - t)) + t;
end
function tmp_2 = code(x, y, z, t)
	t_1 = t + ((x / y) * (z - t));
	tmp = 0.0;
	if (t_1 <= 5e+306)
		tmp = t_1;
	else
		tmp = (x * (z - t)) / y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e+306], t$95$1, N[(N[(x * N[(z - t), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\
\mathbf{if}\;t_1 \leq 5 \cdot 10^{+306}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 12 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original97.7%
Target97.3%
Herbie98.4%
\[\begin{array}{l} \mathbf{if}\;z < 2.759456554562692 \cdot 10^{-282}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \mathbf{elif}\;z < 2.326994450874436 \cdot 10^{-110}:\\ \;\;\;\;x \cdot \frac{z - t}{y} + t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (+.f64 (*.f64 (/.f64 x y) (-.f64 z t)) t) < 4.99999999999999993e306

    1. Initial program 98.2%

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

    if 4.99999999999999993e306 < (+.f64 (*.f64 (/.f64 x y) (-.f64 z t)) t)

    1. Initial program 87.5%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)} \]
      Step-by-step derivation

      [Start]87.5%

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

      associate-*l/ [=>]100.0%

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

      *-commutative [=>]100.0%

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

      associate-*l/ [<=]99.9%

      \[ \color{blue}{\frac{z - t}{y} \cdot x} + t \]

      *-commutative [=>]99.9%

      \[ \color{blue}{x \cdot \frac{z - t}{y}} + t \]

      fma-def [=>]99.9%

      \[ \color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)} \]
    3. Applied egg-rr99.9%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{\frac{1}{y} \cdot \left(z - t\right)}, t\right) \]
      Step-by-step derivation

      [Start]99.9%

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

      clear-num [=>]99.9%

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

      associate-/r/ [=>]99.9%

      \[ \mathsf{fma}\left(x, \color{blue}{\frac{1}{y} \cdot \left(z - t\right)}, t\right) \]
    4. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left(z - t\right) \cdot x}{y}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t + \frac{x}{y} \cdot \left(z - t\right) \leq 5 \cdot 10^{+306}:\\ \;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.4%
Cost1220
\[\begin{array}{l} t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{+306}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \end{array} \]
Alternative 2
Accuracy63.6%
Cost2205
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot \left(-t\right)\\ \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{+124}:\\ \;\;\;\;\frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{+62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -0.0005:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-28}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+89} \lor \neg \left(\frac{x}{y} \leq 10^{+142}\right) \land \frac{x}{y} \leq 5 \cdot 10^{+206}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy63.4%
Cost2205
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{+124}:\\ \;\;\;\;\frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{+62}:\\ \;\;\;\;\frac{x \cdot \left(-t\right)}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -0.0005:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-28}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+89} \lor \neg \left(\frac{x}{y} \leq 10^{+142}\right) \land \frac{x}{y} \leq 5 \cdot 10^{+206}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-t\right)\\ \end{array} \]
Alternative 4
Accuracy62.8%
Cost1425
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -0.0005:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-28}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+89} \lor \neg \left(\frac{x}{y} \leq 10^{+142}\right):\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{-t}{y}\\ \end{array} \]
Alternative 5
Accuracy94.1%
Cost1096
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -40000000000:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{+27}:\\ \;\;\;\;t + \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(z - t\right) \cdot \frac{1}{y}\right)\\ \end{array} \]
Alternative 6
Accuracy94.3%
Cost969
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -40000000000 \lor \neg \left(\frac{x}{y} \leq 2 \cdot 10^{+23}\right):\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 7
Accuracy64.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -0.0005 \lor \neg \left(\frac{x}{y} \leq 2 \cdot 10^{-28}\right):\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 8
Accuracy64.3%
Cost840
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -0.0005:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-28}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \end{array} \]
Alternative 9
Accuracy63.1%
Cost840
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -0.0005:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-28}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \end{array} \]
Alternative 10
Accuracy85.3%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -6.7 \cdot 10^{-35} \lor \neg \left(z \leq 1.5 \cdot 10^{-115}\right):\\ \;\;\;\;t + \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t - \frac{x}{y} \cdot t\\ \end{array} \]
Alternative 11
Accuracy76.3%
Cost448
\[t + \frac{x}{y} \cdot z \]
Alternative 12
Accuracy37.8%
Cost64
\[t \]

Reproduce?

herbie shell --seed 2023263 
(FPCore (x y z t)
  :name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
  :precision binary64

  :herbie-target
  (if (< z 2.759456554562692e-282) (+ (* (/ x y) (- z t)) t) (if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) (+ (* (/ x y) (- z t)) t)))

  (+ (* (/ x y) (- z t)) t))