Average Error: 14.9 → 0.5
Time: 5.8s
Precision: binary64
Cost: 1360
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
\[\begin{array}{l} t_1 := \frac{x}{\frac{z}{y}}\\ \mathbf{if}\;\frac{y}{z} \leq -2 \cdot 10^{+188}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{y}{z} \leq -1 \cdot 10^{-274}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{y}{z} \leq 2 \cdot 10^{-240}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ x (/ z y))))
   (if (<= (/ y z) -2e+188)
     (/ y (/ z x))
     (if (<= (/ y z) -1e-274)
       t_1
       (if (<= (/ y z) 2e-240)
         (* y (/ x z))
         (if (<= (/ y z) 1e+151) t_1 (/ (* y x) z)))))))
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 = x / (z / y);
	double tmp;
	if ((y / z) <= -2e+188) {
		tmp = y / (z / x);
	} else if ((y / z) <= -1e-274) {
		tmp = t_1;
	} else if ((y / z) <= 2e-240) {
		tmp = y * (x / z);
	} else if ((y / z) <= 1e+151) {
		tmp = t_1;
	} else {
		tmp = (y * x) / z;
	}
	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 = x / (z / y)
    if ((y / z) <= (-2d+188)) then
        tmp = y / (z / x)
    else if ((y / z) <= (-1d-274)) then
        tmp = t_1
    else if ((y / z) <= 2d-240) then
        tmp = y * (x / z)
    else if ((y / z) <= 1d+151) then
        tmp = t_1
    else
        tmp = (y * x) / z
    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 = x / (z / y);
	double tmp;
	if ((y / z) <= -2e+188) {
		tmp = y / (z / x);
	} else if ((y / z) <= -1e-274) {
		tmp = t_1;
	} else if ((y / z) <= 2e-240) {
		tmp = y * (x / z);
	} else if ((y / z) <= 1e+151) {
		tmp = t_1;
	} else {
		tmp = (y * x) / z;
	}
	return tmp;
}
def code(x, y, z, t):
	return x * (((y / z) * t) / t)
def code(x, y, z, t):
	t_1 = x / (z / y)
	tmp = 0
	if (y / z) <= -2e+188:
		tmp = y / (z / x)
	elif (y / z) <= -1e-274:
		tmp = t_1
	elif (y / z) <= 2e-240:
		tmp = y * (x / z)
	elif (y / z) <= 1e+151:
		tmp = t_1
	else:
		tmp = (y * x) / z
	return tmp
function code(x, y, z, t)
	return Float64(x * Float64(Float64(Float64(y / z) * t) / t))
end
function code(x, y, z, t)
	t_1 = Float64(x / Float64(z / y))
	tmp = 0.0
	if (Float64(y / z) <= -2e+188)
		tmp = Float64(y / Float64(z / x));
	elseif (Float64(y / z) <= -1e-274)
		tmp = t_1;
	elseif (Float64(y / z) <= 2e-240)
		tmp = Float64(y * Float64(x / z));
	elseif (Float64(y / z) <= 1e+151)
		tmp = t_1;
	else
		tmp = Float64(Float64(y * x) / z);
	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 = x / (z / y);
	tmp = 0.0;
	if ((y / z) <= -2e+188)
		tmp = y / (z / x);
	elseif ((y / z) <= -1e-274)
		tmp = t_1;
	elseif ((y / z) <= 2e-240)
		tmp = y * (x / z);
	elseif ((y / z) <= 1e+151)
		tmp = t_1;
	else
		tmp = (y * x) / z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y / z), $MachinePrecision], -2e+188], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], -1e-274], t$95$1, If[LessEqual[N[(y / z), $MachinePrecision], 2e-240], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], 1e+151], t$95$1, N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision]]]]]]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\begin{array}{l}
t_1 := \frac{x}{\frac{z}{y}}\\
\mathbf{if}\;\frac{y}{z} \leq -2 \cdot 10^{+188}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\

\mathbf{elif}\;\frac{y}{z} \leq -1 \cdot 10^{-274}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\frac{y}{z} \leq 2 \cdot 10^{-240}:\\
\;\;\;\;y \cdot \frac{x}{z}\\

\mathbf{elif}\;\frac{y}{z} \leq 10^{+151}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{z}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.9
Target1.6
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;\frac{\frac{y}{z} \cdot t}{t} < -1.20672205123045 \cdot 10^{+245}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < -5.907522236933906 \cdot 10^{-275}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 5.658954423153415 \cdot 10^{-65}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 2.0087180502407133 \cdot 10^{+217}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 y z) < -2e188

    1. Initial program 38.3

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Taylor expanded in x around 0 1.5

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    3. Simplified1.3

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
      Proof
      (/.f64 y (/.f64 z x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) z)): 46 points increase in error, 70 points decrease in error

    if -2e188 < (/.f64 y z) < -9.99999999999999966e-275 or 1.9999999999999999e-240 < (/.f64 y z) < 1.00000000000000002e151

    1. Initial program 8.2

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified0.2

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Proof
      (/.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) z)): 49 points increase in error, 56 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 63 points increase in error, 41 points decrease in error
      (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 (/.f64 y z) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 (/.f64 y z) (Rewrite<= *-inverses_binary64 (/.f64 t t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (/.f64 y z) t) t))): 49 points increase in error, 1 points decrease in error

    if -9.99999999999999966e-275 < (/.f64 y z) < 1.9999999999999999e-240

    1. Initial program 19.5

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified16.2

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Proof
      (/.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) z)): 49 points increase in error, 56 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 63 points increase in error, 41 points decrease in error
      (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 (/.f64 y z) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 (/.f64 y z) (Rewrite<= *-inverses_binary64 (/.f64 t t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (/.f64 y z) t) t))): 49 points increase in error, 1 points decrease in error
    3. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]

    if 1.00000000000000002e151 < (/.f64 y z)

    1. Initial program 35.8

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified18.0

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Proof
      (/.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) z)): 49 points increase in error, 56 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 63 points increase in error, 41 points decrease in error
      (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 (/.f64 y z) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 (/.f64 y z) (Rewrite<= *-inverses_binary64 (/.f64 t t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (/.f64 y z) t) t))): 49 points increase in error, 1 points decrease in error
    3. Taylor expanded in x around 0 2.4

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} \leq -2 \cdot 10^{+188}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{y}{z} \leq -1 \cdot 10^{-274}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;\frac{y}{z} \leq 2 \cdot 10^{-240}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{+151}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error2.1
Cost1360
\[\begin{array}{l} t_1 := \frac{y}{z} \cdot x\\ t_2 := \frac{y \cdot x}{z}\\ \mathbf{if}\;\frac{y}{z} \leq -1 \cdot 10^{+96}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{y}{z} \leq -1 \cdot 10^{-299}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{-40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error6.1
Cost716
\[\begin{array}{l} t_1 := \frac{y \cdot x}{z}\\ t_2 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -2.4752804269230208 \cdot 10^{-276}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.003049411097889 \cdot 10^{-57}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 10^{+210}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error6.5
Cost320
\[\frac{y \cdot x}{z} \]

Error

Reproduce

herbie shell --seed 2022297 
(FPCore (x y z t)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B"
  :precision binary64

  :herbie-target
  (if (< (/ (* (/ y z) t) t) -1.20672205123045e+245) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) -5.907522236933906e-275) (* x (/ y z)) (if (< (/ (* (/ y z) t) t) 5.658954423153415e-65) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) 2.0087180502407133e+217) (* x (/ y z)) (/ (* y x) z)))))

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