Average Error: 9.8 → 0.0
Time: 8.1s
Precision: binary64
Cost: 704
\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[\frac{x}{z} + \left(1 - \frac{x}{z}\right) \cdot y \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z) :precision binary64 (+ (/ x z) (* (- 1.0 (/ x z)) y)))
double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
	return (x / z) + ((1.0 - (x / z)) * y);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + (y * (z - x))) / 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
    code = (x / z) + ((1.0d0 - (x / z)) * y)
end function
public static double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
public static double code(double x, double y, double z) {
	return (x / z) + ((1.0 - (x / z)) * y);
}
def code(x, y, z):
	return (x + (y * (z - x))) / z
def code(x, y, z):
	return (x / z) + ((1.0 - (x / z)) * y)
function code(x, y, z)
	return Float64(Float64(x + Float64(y * Float64(z - x))) / z)
end
function code(x, y, z)
	return Float64(Float64(x / z) + Float64(Float64(1.0 - Float64(x / z)) * y))
end
function tmp = code(x, y, z)
	tmp = (x + (y * (z - x))) / z;
end
function tmp = code(x, y, z)
	tmp = (x / z) + ((1.0 - (x / z)) * y);
end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := N[(N[(x / z), $MachinePrecision] + N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\frac{x + y \cdot \left(z - x\right)}{z}
\frac{x}{z} + \left(1 - \frac{x}{z}\right) \cdot y

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.8
Target0.0
Herbie0.0
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \]

Derivation

  1. Initial program 9.8

    \[\frac{x + y \cdot \left(z - x\right)}{z} \]
  2. Simplified9.8

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
    Proof
    (/.f64 (fma.f64 y (-.f64 z x) x) z): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (-.f64 z x)) x)) z): 2 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y (-.f64 z x)))) z): 0 points increase in error, 0 points decrease in error
  3. Taylor expanded in y around 0 0.0

    \[\leadsto \color{blue}{\left(1 - \frac{x}{z}\right) \cdot y + \frac{x}{z}} \]
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error0.5
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+69}:\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{elif}\;y \leq 747068185578.2307:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]
Alternative 2
Error7.8
Cost712
\[\begin{array}{l} t_0 := \frac{x}{z} + y\\ \mathbf{if}\;z \leq -7.5 \cdot 10^{-119}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-134}:\\ \;\;\;\;\frac{1 - y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error7.8
Cost712
\[\begin{array}{l} t_0 := \frac{x}{z} + y\\ \mathbf{if}\;z \leq -7.5 \cdot 10^{-119}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-134}:\\ \;\;\;\;\frac{x - x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.8
Cost712
\[\begin{array}{l} t_0 := \left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{if}\;y \leq -1.9246444292598104:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.365638802761727 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.8
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.9246444292598104:\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{elif}\;y \leq 4.365638802761727 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]
Alternative 6
Error19.5
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -9.460567059086065 \cdot 10^{-42}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.5406209979118953 \cdot 10^{-21}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 7
Error8.6
Cost320
\[\frac{x}{z} + y \]
Alternative 8
Error32.3
Cost64
\[y \]

Error

Reproduce

herbie shell --seed 2022316 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

  :herbie-target
  (- (+ y (/ x z)) (/ y (/ z x)))

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