
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
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))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
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))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5e+117) (not (<= x 5.2e+53))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e+117) || !(x <= 5.2e+53)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-5d+117)) .or. (.not. (x <= 5.2d+53))) then
tmp = x * (1.0d0 - y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5e+117) || !(x <= 5.2e+53)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5e+117) or not (x <= 5.2e+53): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5e+117) || !(x <= 5.2e+53)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5e+117) || ~((x <= 5.2e+53))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5e+117], N[Not[LessEqual[x, 5.2e+53]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+117} \lor \neg \left(x \leq 5.2 \cdot 10^{+53}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -4.99999999999999983e117 or 5.19999999999999996e53 < x Initial program 100.0%
Taylor expanded in x around inf 89.9%
mul-1-neg89.9%
unsub-neg89.9%
Simplified89.9%
if -4.99999999999999983e117 < x < 5.19999999999999996e53Initial program 100.0%
Taylor expanded in z around inf 89.1%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.3e+117) (* x (- 1.0 y)) (if (<= x 7e+53) (+ x (* y z)) (- x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+117) {
tmp = x * (1.0 - y);
} else if (x <= 7e+53) {
tmp = x + (y * z);
} else {
tmp = x - (y * x);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-1.3d+117)) then
tmp = x * (1.0d0 - y)
else if (x <= 7d+53) then
tmp = x + (y * z)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+117) {
tmp = x * (1.0 - y);
} else if (x <= 7e+53) {
tmp = x + (y * z);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+117: tmp = x * (1.0 - y) elif x <= 7e+53: tmp = x + (y * z) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+117) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 7e+53) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e+117) tmp = x * (1.0 - y); elseif (x <= 7e+53) tmp = x + (y * z); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+117], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7e+53], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+117}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+53}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if x < -1.3e117Initial program 100.0%
Taylor expanded in x around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
Simplified89.0%
if -1.3e117 < x < 7.00000000000000038e53Initial program 100.0%
Taylor expanded in z around inf 89.1%
if 7.00000000000000038e53 < x Initial program 100.0%
Taylor expanded in x around inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
sub-neg90.4%
distribute-rgt-in90.5%
*-un-lft-identity90.5%
distribute-lft-neg-in90.5%
unsub-neg90.5%
Applied egg-rr90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e+14) (not (<= y 0.00035))) (* y (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e+14) || !(y <= 0.00035)) {
tmp = y * -x;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-9.5d+14)) .or. (.not. (y <= 0.00035d0))) then
tmp = y * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e+14) || !(y <= 0.00035)) {
tmp = y * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.5e+14) or not (y <= 0.00035): tmp = y * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e+14) || !(y <= 0.00035)) tmp = Float64(y * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.5e+14) || ~((y <= 0.00035))) tmp = y * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e+14], N[Not[LessEqual[y, 0.00035]], $MachinePrecision]], N[(y * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+14} \lor \neg \left(y \leq 0.00035\right):\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.5e14 or 3.49999999999999996e-4 < y Initial program 100.0%
Taylor expanded in x around inf 49.0%
mul-1-neg49.0%
unsub-neg49.0%
Simplified49.0%
Taylor expanded in y around inf 47.8%
neg-mul-147.8%
Simplified47.8%
if -9.5e14 < y < 3.49999999999999996e-4Initial program 100.0%
Taylor expanded in y around 0 61.8%
Final simplification54.6%
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
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))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (* x (- 1.0 y)))
double code(double x, double y, double z) {
return x * (1.0 - 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 * (1.0d0 - y)
end function
public static double code(double x, double y, double z) {
return x * (1.0 - y);
}
def code(x, y, z): return x * (1.0 - y)
function code(x, y, z) return Float64(x * Float64(1.0 - y)) end
function tmp = code(x, y, z) tmp = x * (1.0 - y); end
code[x_, y_, z_] := N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 55.8%
mul-1-neg55.8%
unsub-neg55.8%
Simplified55.8%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 31.3%
herbie shell --seed 2024112
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))