
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= y -9.5e+242)
t_0
(if (<= y -3.5e+196)
(* y z)
(if (<= y -1.6e+124)
t_0
(if (<= y -4e-50)
(* y z)
(if (<= y 1.65e-24)
x
(if (or (<= y 1.06e+89)
(and (not (<= y 1.2e+161)) (<= y 7.5e+278)))
(* y z)
t_0))))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -9.5e+242) {
tmp = t_0;
} else if (y <= -3.5e+196) {
tmp = y * z;
} else if (y <= -1.6e+124) {
tmp = t_0;
} else if (y <= -4e-50) {
tmp = y * z;
} else if (y <= 1.65e-24) {
tmp = x;
} else if ((y <= 1.06e+89) || (!(y <= 1.2e+161) && (y <= 7.5e+278))) {
tmp = y * z;
} else {
tmp = 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
real(8) :: t_0
real(8) :: tmp
t_0 = x * -y
if (y <= (-9.5d+242)) then
tmp = t_0
else if (y <= (-3.5d+196)) then
tmp = y * z
else if (y <= (-1.6d+124)) then
tmp = t_0
else if (y <= (-4d-50)) then
tmp = y * z
else if (y <= 1.65d-24) then
tmp = x
else if ((y <= 1.06d+89) .or. (.not. (y <= 1.2d+161)) .and. (y <= 7.5d+278)) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -9.5e+242) {
tmp = t_0;
} else if (y <= -3.5e+196) {
tmp = y * z;
} else if (y <= -1.6e+124) {
tmp = t_0;
} else if (y <= -4e-50) {
tmp = y * z;
} else if (y <= 1.65e-24) {
tmp = x;
} else if ((y <= 1.06e+89) || (!(y <= 1.2e+161) && (y <= 7.5e+278))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if y <= -9.5e+242: tmp = t_0 elif y <= -3.5e+196: tmp = y * z elif y <= -1.6e+124: tmp = t_0 elif y <= -4e-50: tmp = y * z elif y <= 1.65e-24: tmp = x elif (y <= 1.06e+89) or (not (y <= 1.2e+161) and (y <= 7.5e+278)): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -9.5e+242) tmp = t_0; elseif (y <= -3.5e+196) tmp = Float64(y * z); elseif (y <= -1.6e+124) tmp = t_0; elseif (y <= -4e-50) tmp = Float64(y * z); elseif (y <= 1.65e-24) tmp = x; elseif ((y <= 1.06e+89) || (!(y <= 1.2e+161) && (y <= 7.5e+278))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (y <= -9.5e+242) tmp = t_0; elseif (y <= -3.5e+196) tmp = y * z; elseif (y <= -1.6e+124) tmp = t_0; elseif (y <= -4e-50) tmp = y * z; elseif (y <= 1.65e-24) tmp = x; elseif ((y <= 1.06e+89) || (~((y <= 1.2e+161)) && (y <= 7.5e+278))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -9.5e+242], t$95$0, If[LessEqual[y, -3.5e+196], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.6e+124], t$95$0, If[LessEqual[y, -4e-50], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.65e-24], x, If[Or[LessEqual[y, 1.06e+89], And[N[Not[LessEqual[y, 1.2e+161]], $MachinePrecision], LessEqual[y, 7.5e+278]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{+242}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{+196}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{+124}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -4 \cdot 10^{-50}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{+89} \lor \neg \left(y \leq 1.2 \cdot 10^{+161}\right) \land y \leq 7.5 \cdot 10^{+278}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -9.49999999999999995e242 or -3.4999999999999998e196 < y < -1.59999999999999996e124 or 1.05999999999999997e89 < y < 1.1999999999999999e161 or 7.49999999999999949e278 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around 0 81.0%
associate-*r*81.0%
mul-1-neg81.0%
Simplified81.0%
if -9.49999999999999995e242 < y < -3.4999999999999998e196 or -1.59999999999999996e124 < y < -4.00000000000000003e-50 or 1.64999999999999992e-24 < y < 1.05999999999999997e89 or 1.1999999999999999e161 < y < 7.49999999999999949e278Initial program 100.0%
Taylor expanded in x around 0 73.6%
if -4.00000000000000003e-50 < y < 1.64999999999999992e-24Initial program 100.0%
Taylor expanded in y around 0 80.6%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.6e-49) (not (<= y 8.8e-16))) (* y (- z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.6e-49) || !(y <= 8.8e-16)) {
tmp = y * (z - 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 <= (-4.6d-49)) .or. (.not. (y <= 8.8d-16))) then
tmp = y * (z - x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.6e-49) || !(y <= 8.8e-16)) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.6e-49) or not (y <= 8.8e-16): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.6e-49) || !(y <= 8.8e-16)) tmp = Float64(y * Float64(z - x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.6e-49) || ~((y <= 8.8e-16))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.6e-49], N[Not[LessEqual[y, 8.8e-16]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{-49} \lor \neg \left(y \leq 8.8 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.5999999999999998e-49 or 8.80000000000000001e-16 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
if -4.5999999999999998e-49 < y < 8.80000000000000001e-16Initial program 100.0%
Taylor expanded in y around 0 80.6%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -48000000000.0) (not (<= y 7.5e-12))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -48000000000.0) || !(y <= 7.5e-12)) {
tmp = y * (z - x);
} 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 ((y <= (-48000000000.0d0)) .or. (.not. (y <= 7.5d-12))) then
tmp = y * (z - x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -48000000000.0) || !(y <= 7.5e-12)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -48000000000.0) or not (y <= 7.5e-12): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -48000000000.0) || !(y <= 7.5e-12)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -48000000000.0) || ~((y <= 7.5e-12))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -48000000000.0], N[Not[LessEqual[y, 7.5e-12]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -48000000000 \lor \neg \left(y \leq 7.5 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -4.8e10 or 7.5e-12 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
if -4.8e10 < y < 7.5e-12Initial program 100.0%
flip--59.9%
associate-*r/59.9%
+-commutative59.9%
Applied egg-rr59.9%
associate-/l*59.9%
difference-of-squares60.2%
+-commutative60.2%
associate-/r*99.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.25e-48) (* y z) (if (<= y 1.05e-14) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.25e-48) {
tmp = y * z;
} else if (y <= 1.05e-14) {
tmp = x;
} else {
tmp = 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 (y <= (-2.25d-48)) then
tmp = y * z
else if (y <= 1.05d-14) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.25e-48) {
tmp = y * z;
} else if (y <= 1.05e-14) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.25e-48: tmp = y * z elif y <= 1.05e-14: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.25e-48) tmp = Float64(y * z); elseif (y <= 1.05e-14) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.25e-48) tmp = y * z; elseif (y <= 1.05e-14) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.25e-48], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.05e-14], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{-48}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.24999999999999994e-48 or 1.0499999999999999e-14 < y Initial program 100.0%
Taylor expanded in x around 0 58.1%
if -2.24999999999999994e-48 < y < 1.0499999999999999e-14Initial program 100.0%
Taylor expanded in y around 0 80.6%
Final simplification68.2%
(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%
Final simplification100.0%
(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 38.5%
Final simplification38.5%
herbie shell --seed 2023173
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))