Average Error: 5.7 → 0.3
Time: 9.0s
Precision: binary64
Cost: 968
\[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+155}:\\ \;\;\;\;x \cdot \left(\frac{x}{y} \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;x \leq 10^{+105}:\\ \;\;\;\;\frac{\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y}}{3}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.3333333333333333}{y}\right)\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))
(FPCore (x y)
 :precision binary64
 (if (<= x -1e+155)
   (* x (* (/ x y) 0.3333333333333333))
   (if (<= x 1e+105)
     (/ (/ (* (- 1.0 x) (- 3.0 x)) y) 3.0)
     (* x (* x (/ 0.3333333333333333 y))))))
double code(double x, double y) {
	return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
double code(double x, double y) {
	double tmp;
	if (x <= -1e+155) {
		tmp = x * ((x / y) * 0.3333333333333333);
	} else if (x <= 1e+105) {
		tmp = (((1.0 - x) * (3.0 - x)) / y) / 3.0;
	} else {
		tmp = x * (x * (0.3333333333333333 / y));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((1.0d0 - x) * (3.0d0 - x)) / (y * 3.0d0)
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-1d+155)) then
        tmp = x * ((x / y) * 0.3333333333333333d0)
    else if (x <= 1d+105) then
        tmp = (((1.0d0 - x) * (3.0d0 - x)) / y) / 3.0d0
    else
        tmp = x * (x * (0.3333333333333333d0 / y))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
public static double code(double x, double y) {
	double tmp;
	if (x <= -1e+155) {
		tmp = x * ((x / y) * 0.3333333333333333);
	} else if (x <= 1e+105) {
		tmp = (((1.0 - x) * (3.0 - x)) / y) / 3.0;
	} else {
		tmp = x * (x * (0.3333333333333333 / y));
	}
	return tmp;
}
def code(x, y):
	return ((1.0 - x) * (3.0 - x)) / (y * 3.0)
def code(x, y):
	tmp = 0
	if x <= -1e+155:
		tmp = x * ((x / y) * 0.3333333333333333)
	elif x <= 1e+105:
		tmp = (((1.0 - x) * (3.0 - x)) / y) / 3.0
	else:
		tmp = x * (x * (0.3333333333333333 / y))
	return tmp
function code(x, y)
	return Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / Float64(y * 3.0))
end
function code(x, y)
	tmp = 0.0
	if (x <= -1e+155)
		tmp = Float64(x * Float64(Float64(x / y) * 0.3333333333333333));
	elseif (x <= 1e+105)
		tmp = Float64(Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / y) / 3.0);
	else
		tmp = Float64(x * Float64(x * Float64(0.3333333333333333 / y)));
	end
	return tmp
end
function tmp = code(x, y)
	tmp = ((1.0 - x) * (3.0 - x)) / (y * 3.0);
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1e+155)
		tmp = x * ((x / y) * 0.3333333333333333);
	elseif (x <= 1e+105)
		tmp = (((1.0 - x) * (3.0 - x)) / y) / 3.0;
	else
		tmp = x * (x * (0.3333333333333333 / y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := N[(N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y * 3.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, -1e+155], N[(x * N[(N[(x / y), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1e+105], N[(N[(N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 3.0), $MachinePrecision], N[(x * N[(x * N[(0.3333333333333333 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+155}:\\
\;\;\;\;x \cdot \left(\frac{x}{y} \cdot 0.3333333333333333\right)\\

\mathbf{elif}\;x \leq 10^{+105}:\\
\;\;\;\;\frac{\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y}}{3}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{0.3333333333333333}{y}\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original5.7
Target0.1
Herbie0.3
\[\frac{1 - x}{y} \cdot \frac{3 - x}{3} \]

Derivation

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

    1. Initial program 64.0

      \[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
    2. Applied egg-rr0.6

      \[\leadsto \color{blue}{\frac{1 - x}{3 \cdot y} \cdot \left(3 - x\right)} \]
    3. Applied egg-rr64.0

      \[\leadsto \color{blue}{\frac{\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y}}{3}} \]
    4. Taylor expanded in x around inf 64.0

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{{x}^{2}}{y}} \]
    5. Simplified0.4

      \[\leadsto \color{blue}{x \cdot \left(\frac{x}{y} \cdot 0.3333333333333333\right)} \]
      Proof
      (*.f64 x (*.f64 (/.f64 x y) 1/3)): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= *-commutative_binary64 (*.f64 1/3 (/.f64 x y)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 1/3 x) y))): 30 points increase in error, 21 points decrease in error
      (*.f64 x (Rewrite=> associate-/l*_binary64 (/.f64 1/3 (/.f64 y x)))): 29 points increase in error, 26 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 1/3 (/.f64 y x)) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 1/3 x) (/.f64 y x))): 30 points increase in error, 27 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 1/3 (/.f64 x (/.f64 y x)))): 27 points increase in error, 28 points decrease in error
      (*.f64 1/3 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x x) y))): 51 points increase in error, 24 points decrease in error
      (*.f64 1/3 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) y)): 0 points increase in error, 0 points decrease in error

    if -1.00000000000000001e155 < x < 9.9999999999999994e104

    1. Initial program 0.3

      \[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
    2. Applied egg-rr0.4

      \[\leadsto \color{blue}{\frac{1 - x}{3 \cdot y} \cdot \left(3 - x\right)} \]
    3. Applied egg-rr0.3

      \[\leadsto \color{blue}{\frac{\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y}}{3}} \]

    if 9.9999999999999994e104 < x

    1. Initial program 37.2

      \[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
    2. Taylor expanded in x around inf 37.1

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{{x}^{2}}{y}} \]
    3. Simplified0.4

      \[\leadsto \color{blue}{x \cdot \left(x \cdot \frac{0.3333333333333333}{y}\right)} \]
      Proof
      (*.f64 x (*.f64 x (/.f64 1/3 y))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 1/3 y) x))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/r/_binary64 (/.f64 1/3 (/.f64 y x)))): 31 points increase in error, 24 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 1/3 (/.f64 y x)) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 1/3 x) (/.f64 y x))): 30 points increase in error, 27 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 1/3 (/.f64 x (/.f64 y x)))): 27 points increase in error, 28 points decrease in error
      (*.f64 1/3 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x x) y))): 51 points increase in error, 24 points decrease in error
      (*.f64 1/3 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) y)): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+155}:\\ \;\;\;\;x \cdot \left(\frac{x}{y} \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;x \leq 10^{+105}:\\ \;\;\;\;\frac{\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y}}{3}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.3333333333333333}{y}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.2
Cost840
\[\begin{array}{l} t_0 := \frac{\frac{x}{y} \cdot \left(x + -4\right)}{3}\\ \mathbf{if}\;x \leq -601.2260094468445:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.017164971766588922:\\ \;\;\;\;\frac{1 + x \cdot -1.3333333333333333}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error1.2
Cost840
\[\begin{array}{l} t_0 := \frac{\frac{x}{y} \cdot \left(x + -4\right)}{3}\\ \mathbf{if}\;x \leq -601.2260094468445:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.017164971766588922:\\ \;\;\;\;\frac{1}{y} + \frac{x}{y} \cdot -1.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error2.1
Cost712
\[\begin{array}{l} t_0 := x \cdot \frac{x}{\frac{y}{0.3333333333333333}}\\ \mathbf{if}\;x \leq -601.2260094468445:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.017164971766588922:\\ \;\;\;\;\frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error2.1
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -601.2260094468445:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{3}\\ \mathbf{elif}\;x \leq 0.017164971766588922:\\ \;\;\;\;\frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{x}{\frac{y}{0.3333333333333333}}\\ \end{array} \]
Alternative 5
Error1.7
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -601.2260094468445:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{3}\\ \mathbf{elif}\;x \leq 0.017164971766588922:\\ \;\;\;\;\frac{1 + x \cdot -1.3333333333333333}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{x}{\frac{y}{0.3333333333333333}}\\ \end{array} \]
Alternative 6
Error0.4
Cost704
\[\frac{1 - x}{3 \cdot y} \cdot \left(3 - x\right) \]
Alternative 7
Error22.2
Cost192
\[\frac{1}{y} \]

Error

Reproduce

herbie shell --seed 2022298 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:bezierFromSweepQ1 from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (* (/ (- 1.0 x) y) (/ (- 3.0 x) 3.0))

  (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))