Diagrams.TwoD.Arc:bezierFromSweepQ1 from diagrams-lib-1.3.0.3

?

Percentage Accurate: 94.1% → 99.8%
Time: 11.3s
Precision: binary64
Cost: 704

?

\[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
\[\frac{1 - x}{y} \cdot \left(1 - \frac{x}{3}\right) \]
(FPCore (x y) :precision binary64 (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))
(FPCore (x y) :precision binary64 (* (/ (- 1.0 x) y) (- 1.0 (/ x 3.0))))
double code(double x, double y) {
	return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
double code(double x, double y) {
	return ((1.0 - x) / y) * (1.0 - (x / 3.0));
}
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
    code = ((1.0d0 - x) / y) * (1.0d0 - (x / 3.0d0))
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) {
	return ((1.0 - x) / y) * (1.0 - (x / 3.0));
}
def code(x, y):
	return ((1.0 - x) * (3.0 - x)) / (y * 3.0)
def code(x, y):
	return ((1.0 - x) / y) * (1.0 - (x / 3.0))
function code(x, y)
	return Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / Float64(y * 3.0))
end
function code(x, y)
	return Float64(Float64(Float64(1.0 - x) / y) * Float64(1.0 - Float64(x / 3.0)))
end
function tmp = code(x, y)
	tmp = ((1.0 - x) * (3.0 - x)) / (y * 3.0);
end
function tmp = code(x, y)
	tmp = ((1.0 - x) / y) * (1.0 - (x / 3.0));
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_] := N[(N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision] * N[(1.0 - N[(x / 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
\frac{1 - x}{y} \cdot \left(1 - \frac{x}{3}\right)

Local Percentage Accuracy?

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 16 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original94.1%
Target99.8%
Herbie99.8%
\[\frac{1 - x}{y} \cdot \frac{3 - x}{3} \]

Derivation?

  1. Initial program 94.2%

    \[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
  2. Simplified99.8%

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

    [Start]94.2

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

    times-frac [=>]99.8

    \[ \color{blue}{\frac{1 - x}{y} \cdot \frac{3 - x}{3}} \]

    div-sub [=>]99.8

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

    metadata-eval [=>]99.8

    \[ \frac{1 - x}{y} \cdot \left(\color{blue}{1} - \frac{x}{3}\right) \]
  3. Final simplification99.8%

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

Alternatives

Alternative 1
Accuracy98.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \lor \neg \left(x \leq 1.3\right):\\ \;\;\;\;\left(3 - x\right) \cdot \left(\frac{x}{y} \cdot -0.3333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 + x \cdot -1.3333333333333333}{y}\\ \end{array} \]
Alternative 2
Accuracy98.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \lor \neg \left(x \leq 1.3\right):\\ \;\;\;\;\left(3 - x\right) \cdot \left(\frac{x}{y} \cdot -0.3333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} + \frac{x}{y} \cdot -1.3333333333333333\\ \end{array} \]
Alternative 3
Accuracy98.4%
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3:\\ \;\;\;\;\frac{x}{y} \cdot \left(\frac{x}{3} + -1\right)\\ \mathbf{elif}\;x \leq 1.3:\\ \;\;\;\;\frac{1}{y} + \frac{x}{y} \cdot -1.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\left(3 - x\right) \cdot \left(\frac{x}{y} \cdot -0.3333333333333333\right)\\ \end{array} \]
Alternative 4
Accuracy97.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \lor \neg \left(x \leq 3\right):\\ \;\;\;\;\left(x \cdot \frac{x}{y}\right) \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{y}\\ \end{array} \]
Alternative 5
Accuracy97.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \lor \neg \left(x \leq 3\right):\\ \;\;\;\;0.3333333333333333 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - x}{y}\\ \end{array} \]
Alternative 6
Accuracy97.7%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;0.3333333333333333 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;x \leq 3:\\ \;\;\;\;\frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{x}{y} \cdot 0.3333333333333333\right)\\ \end{array} \]
Alternative 7
Accuracy97.7%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;0.3333333333333333 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;x \leq 3:\\ \;\;\;\;\frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{x}{\frac{y}{0.3333333333333333}}\\ \end{array} \]
Alternative 8
Accuracy97.7%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;0.3333333333333333 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;x \leq 3:\\ \;\;\;\;\frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{3}\\ \end{array} \]
Alternative 9
Accuracy98.3%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6:\\ \;\;\;\;0.3333333333333333 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;x \leq 3:\\ \;\;\;\;\frac{1 + x \cdot -1.3333333333333333}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{3}\\ \end{array} \]
Alternative 10
Accuracy98.3%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{3}{x}}\\ \mathbf{elif}\;x \leq 3:\\ \;\;\;\;\frac{1 + x \cdot -1.3333333333333333}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{3}\\ \end{array} \]
Alternative 11
Accuracy99.8%
Cost704
\[\left(3 - x\right) \cdot \frac{\frac{1 - x}{y}}{3} \]
Alternative 12
Accuracy57.8%
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -0.75:\\ \;\;\;\;\frac{x}{y} \cdot -1.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y}\\ \end{array} \]
Alternative 13
Accuracy57.8%
Cost388
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;-\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y}\\ \end{array} \]
Alternative 14
Accuracy56.9%
Cost320
\[\frac{1 - x}{y} \]
Alternative 15
Accuracy51.7%
Cost192
\[\frac{1}{y} \]

Reproduce?

herbie shell --seed 2023160 
(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)))