Average Error: 2.7 → 1.6
Time: 8.4s
Precision: binary64
Cost: 6980
\[\frac{x \cdot \frac{\sin y}{y}}{z} \]
\[\begin{array}{l} t_0 := \frac{\sin y}{y}\\ \mathbf{if}\;x \leq -3 \cdot 10^{+14}:\\ \;\;\;\;\frac{x \cdot t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{t_0}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (sin y) y)))
   (if (<= x -3e+14) (/ (* x t_0) z) (/ x (/ z t_0)))))
double code(double x, double y, double z) {
	return (x * (sin(y) / y)) / z;
}
double code(double x, double y, double z) {
	double t_0 = sin(y) / y;
	double tmp;
	if (x <= -3e+14) {
		tmp = (x * t_0) / z;
	} else {
		tmp = x / (z / t_0);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * (sin(y) / y)) / z
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sin(y) / y
    if (x <= (-3d+14)) then
        tmp = (x * t_0) / z
    else
        tmp = x / (z / t_0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x * (Math.sin(y) / y)) / z;
}
public static double code(double x, double y, double z) {
	double t_0 = Math.sin(y) / y;
	double tmp;
	if (x <= -3e+14) {
		tmp = (x * t_0) / z;
	} else {
		tmp = x / (z / t_0);
	}
	return tmp;
}
def code(x, y, z):
	return (x * (math.sin(y) / y)) / z
def code(x, y, z):
	t_0 = math.sin(y) / y
	tmp = 0
	if x <= -3e+14:
		tmp = (x * t_0) / z
	else:
		tmp = x / (z / t_0)
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(sin(y) / y)) / z)
end
function code(x, y, z)
	t_0 = Float64(sin(y) / y)
	tmp = 0.0
	if (x <= -3e+14)
		tmp = Float64(Float64(x * t_0) / z);
	else
		tmp = Float64(x / Float64(z / t_0));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (sin(y) / y)) / z;
end
function tmp_2 = code(x, y, z)
	t_0 = sin(y) / y;
	tmp = 0.0;
	if (x <= -3e+14)
		tmp = (x * t_0) / z;
	else
		tmp = x / (z / t_0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[x, -3e+14], N[(N[(x * t$95$0), $MachinePrecision] / z), $MachinePrecision], N[(x / N[(z / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \frac{\sin y}{y}}{z}
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathbf{if}\;x \leq -3 \cdot 10^{+14}:\\
\;\;\;\;\frac{x \cdot t_0}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{t_0}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.7
Target0.3
Herbie1.6
\[\begin{array}{l} \mathbf{if}\;z < -4.2173720203427147 \cdot 10^{-29}:\\ \;\;\;\;\frac{x \cdot \frac{1}{\frac{y}{\sin y}}}{z}\\ \mathbf{elif}\;z < 4.446702369113811 \cdot 10^{+64}:\\ \;\;\;\;\frac{x}{z \cdot \frac{y}{\sin y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{1}{\frac{y}{\sin y}}}{z}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if x < -3e14

    1. Initial program 0.2

      \[\frac{x \cdot \frac{\sin y}{y}}{z} \]

    if -3e14 < x

    1. Initial program 3.4

      \[\frac{x \cdot \frac{\sin y}{y}}{z} \]
    2. Simplified2.0

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\frac{\sin y}{y}}}} \]
      Proof
      (/.f64 x (/.f64 z (/.f64 (sin.f64 y) y))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z)): 32 points increase in error, 28 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification1.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{+14}:\\ \;\;\;\;\frac{x \cdot \frac{\sin y}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{\frac{\sin y}{y}}}\\ \end{array} \]

Alternatives

Alternative 1
Error3.0
Cost7112
\[\begin{array}{l} t_0 := x \cdot \frac{\sin y}{y \cdot z}\\ \mathbf{if}\;y \leq -0.00024:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-5}:\\ \;\;\;\;\frac{x}{\frac{z}{1 + -0.16666666666666666 \cdot \left(y \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error3.0
Cost7112
\[\begin{array}{l} t_0 := \sin y \cdot \frac{x}{y \cdot z}\\ \mathbf{if}\;y \leq -0.000232:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-5}:\\ \;\;\;\;\frac{x}{\frac{z}{1 + -0.16666666666666666 \cdot \left(y \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error3.0
Cost7112
\[\begin{array}{l} \mathbf{if}\;y \leq -0.00022:\\ \;\;\;\;\sin y \cdot \frac{x}{y \cdot z}\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-26}:\\ \;\;\;\;\frac{x}{\frac{z}{1 + -0.16666666666666666 \cdot \left(y \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin y}{z} \cdot \frac{x}{y}\\ \end{array} \]
Alternative 4
Error3.0
Cost6848
\[\frac{x}{\frac{z}{\frac{\sin y}{y}}} \]
Alternative 5
Error22.6
Cost1096
\[\begin{array}{l} t_0 := \frac{x}{y \cdot \left(\left(y \cdot z\right) \cdot 0.16666666666666666 + \frac{z}{y}\right)}\\ \mathbf{if}\;y \leq -17000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{+18}:\\ \;\;\;\;\frac{x}{\frac{z}{1 + -0.16666666666666666 \cdot \left(y \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error23.0
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -17000:\\ \;\;\;\;\frac{y}{z \cdot \frac{y}{x}}\\ \mathbf{elif}\;y \leq 3600000000000:\\ \;\;\;\;\frac{x}{\frac{z}{1 + -0.16666666666666666 \cdot \left(y \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{y \cdot z}\\ \end{array} \]
Alternative 7
Error23.2
Cost712
\[\begin{array}{l} t_0 := y \cdot \frac{x}{y \cdot z}\\ \mathbf{if}\;y \leq -5 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+15}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error23.1
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -54000000000:\\ \;\;\;\;\left(1 + \frac{x}{z}\right) + -1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+15}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{y \cdot z}\\ \end{array} \]
Alternative 9
Error23.2
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{y}{z \cdot \frac{y}{x}}\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+15}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{y \cdot z}\\ \end{array} \]
Alternative 10
Error28.5
Cost192
\[\frac{x}{z} \]

Error

Reproduce

herbie shell --seed 2022329 
(FPCore (x y z)
  :name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< z -4.2173720203427147e-29) (/ (* x (/ 1.0 (/ y (sin y)))) z) (if (< z 4.446702369113811e+64) (/ x (* z (/ y (sin y)))) (/ (* x (/ 1.0 (/ y (sin y)))) z)))

  (/ (* x (/ (sin y) y)) z))