
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ y z) x (- z)))
double code(double x, double y, double z) {
return fma((y + z), x, -z);
}
function code(x, y, z) return fma(Float64(y + z), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y + z), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + z, x, -z\right)
\end{array}
Initial program 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
distribute-lft-in99.9%
*-commutative99.9%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -9.5e+72)
(* z x)
(if (<= x -0.0066)
(* y x)
(if (<= x 4.7e-138)
(- z)
(if (<= x 5e+62)
(* y x)
(if (or (<= x 1.16e+98)
(and (not (<= x 6.2e+112))
(or (<= x 5.6e+169)
(and (not (<= x 4.2e+238)) (<= x 2.95e+258)))))
(* z x)
(* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e+72) {
tmp = z * x;
} else if (x <= -0.0066) {
tmp = y * x;
} else if (x <= 4.7e-138) {
tmp = -z;
} else if (x <= 5e+62) {
tmp = y * x;
} else if ((x <= 1.16e+98) || (!(x <= 6.2e+112) && ((x <= 5.6e+169) || (!(x <= 4.2e+238) && (x <= 2.95e+258))))) {
tmp = z * x;
} else {
tmp = 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 <= (-9.5d+72)) then
tmp = z * x
else if (x <= (-0.0066d0)) then
tmp = y * x
else if (x <= 4.7d-138) then
tmp = -z
else if (x <= 5d+62) then
tmp = y * x
else if ((x <= 1.16d+98) .or. (.not. (x <= 6.2d+112)) .and. (x <= 5.6d+169) .or. (.not. (x <= 4.2d+238)) .and. (x <= 2.95d+258)) then
tmp = z * x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e+72) {
tmp = z * x;
} else if (x <= -0.0066) {
tmp = y * x;
} else if (x <= 4.7e-138) {
tmp = -z;
} else if (x <= 5e+62) {
tmp = y * x;
} else if ((x <= 1.16e+98) || (!(x <= 6.2e+112) && ((x <= 5.6e+169) || (!(x <= 4.2e+238) && (x <= 2.95e+258))))) {
tmp = z * x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.5e+72: tmp = z * x elif x <= -0.0066: tmp = y * x elif x <= 4.7e-138: tmp = -z elif x <= 5e+62: tmp = y * x elif (x <= 1.16e+98) or (not (x <= 6.2e+112) and ((x <= 5.6e+169) or (not (x <= 4.2e+238) and (x <= 2.95e+258)))): tmp = z * x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.5e+72) tmp = Float64(z * x); elseif (x <= -0.0066) tmp = Float64(y * x); elseif (x <= 4.7e-138) tmp = Float64(-z); elseif (x <= 5e+62) tmp = Float64(y * x); elseif ((x <= 1.16e+98) || (!(x <= 6.2e+112) && ((x <= 5.6e+169) || (!(x <= 4.2e+238) && (x <= 2.95e+258))))) tmp = Float64(z * x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.5e+72) tmp = z * x; elseif (x <= -0.0066) tmp = y * x; elseif (x <= 4.7e-138) tmp = -z; elseif (x <= 5e+62) tmp = y * x; elseif ((x <= 1.16e+98) || (~((x <= 6.2e+112)) && ((x <= 5.6e+169) || (~((x <= 4.2e+238)) && (x <= 2.95e+258))))) tmp = z * x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.5e+72], N[(z * x), $MachinePrecision], If[LessEqual[x, -0.0066], N[(y * x), $MachinePrecision], If[LessEqual[x, 4.7e-138], (-z), If[LessEqual[x, 5e+62], N[(y * x), $MachinePrecision], If[Or[LessEqual[x, 1.16e+98], And[N[Not[LessEqual[x, 6.2e+112]], $MachinePrecision], Or[LessEqual[x, 5.6e+169], And[N[Not[LessEqual[x, 4.2e+238]], $MachinePrecision], LessEqual[x, 2.95e+258]]]]], N[(z * x), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+72}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -0.0066:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{-138}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+62}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.16 \cdot 10^{+98} \lor \neg \left(x \leq 6.2 \cdot 10^{+112}\right) \land \left(x \leq 5.6 \cdot 10^{+169} \lor \neg \left(x \leq 4.2 \cdot 10^{+238}\right) \land x \leq 2.95 \cdot 10^{+258}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -9.50000000000000054e72 or 5.00000000000000029e62 < x < 1.15999999999999995e98 or 6.19999999999999965e112 < x < 5.6000000000000003e169 or 4.20000000000000015e238 < x < 2.95e258Initial program 96.3%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 71.8%
if -9.50000000000000054e72 < x < -0.0066 or 4.7000000000000001e-138 < x < 5.00000000000000029e62 or 1.15999999999999995e98 < x < 6.19999999999999965e112 or 5.6000000000000003e169 < x < 4.20000000000000015e238 or 2.95e258 < x Initial program 95.4%
Taylor expanded in y around inf 69.0%
if -0.0066 < x < 4.7000000000000001e-138Initial program 99.9%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
Final simplification72.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0066) (not (<= x 5.1e-138))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0066) || !(x <= 5.1e-138)) {
tmp = (y + z) * x;
} else {
tmp = -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 <= (-0.0066d0)) .or. (.not. (x <= 5.1d-138))) then
tmp = (y + z) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0066) || !(x <= 5.1e-138)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0066) or not (x <= 5.1e-138): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0066) || !(x <= 5.1e-138)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.0066) || ~((x <= 5.1e-138))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0066], N[Not[LessEqual[x, 5.1e-138]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0066 \lor \neg \left(x \leq 5.1 \cdot 10^{-138}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -0.0066 or 5.1000000000000002e-138 < x Initial program 95.8%
Taylor expanded in x around inf 93.2%
+-commutative93.2%
Simplified93.2%
if -0.0066 < x < 5.1000000000000002e-138Initial program 99.9%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.012) (not (<= x 1.15e-140))) (* (+ y z) x) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.012) || !(x <= 1.15e-140)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-0.012d0)) .or. (.not. (x <= 1.15d-140))) then
tmp = (y + z) * x
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.012) || !(x <= 1.15e-140)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.012) or not (x <= 1.15e-140): tmp = (y + z) * x else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.012) || !(x <= 1.15e-140)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.012) || ~((x <= 1.15e-140))) tmp = (y + z) * x; else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.012], N[Not[LessEqual[x, 1.15e-140]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.012 \lor \neg \left(x \leq 1.15 \cdot 10^{-140}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -0.012 or 1.1500000000000001e-140 < x Initial program 95.8%
Taylor expanded in x around inf 93.2%
+-commutative93.2%
Simplified93.2%
if -0.012 < x < 1.1500000000000001e-140Initial program 99.9%
Taylor expanded in y around 0 79.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.024) (not (<= x 4.2e-138))) (* (+ y z) x) (- (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.024) || !(x <= 4.2e-138)) {
tmp = (y + z) * x;
} else {
tmp = (z * x) - 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 <= (-0.024d0)) .or. (.not. (x <= 4.2d-138))) then
tmp = (y + z) * x
else
tmp = (z * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.024) || !(x <= 4.2e-138)) {
tmp = (y + z) * x;
} else {
tmp = (z * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.024) or not (x <= 4.2e-138): tmp = (y + z) * x else: tmp = (z * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.024) || !(x <= 4.2e-138)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(Float64(z * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.024) || ~((x <= 4.2e-138))) tmp = (y + z) * x; else tmp = (z * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.024], N[Not[LessEqual[x, 4.2e-138]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.024 \lor \neg \left(x \leq 4.2 \cdot 10^{-138}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x - z\\
\end{array}
\end{array}
if x < -0.024 or 4.19999999999999972e-138 < x Initial program 95.8%
Taylor expanded in x around inf 93.2%
+-commutative93.2%
Simplified93.2%
if -0.024 < x < 4.19999999999999972e-138Initial program 99.9%
Taylor expanded in y around 0 79.8%
sub-neg79.8%
metadata-eval79.8%
distribute-rgt-in79.8%
mul-1-neg79.8%
sub-neg79.8%
*-commutative79.8%
Simplified79.8%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (<= x -0.0066) (* y x) (if (<= x 5.1e-138) (- z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.0066) {
tmp = y * x;
} else if (x <= 5.1e-138) {
tmp = -z;
} else {
tmp = 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 <= (-0.0066d0)) then
tmp = y * x
else if (x <= 5.1d-138) then
tmp = -z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.0066) {
tmp = y * x;
} else if (x <= 5.1e-138) {
tmp = -z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.0066: tmp = y * x elif x <= 5.1e-138: tmp = -z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.0066) tmp = Float64(y * x); elseif (x <= 5.1e-138) tmp = Float64(-z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.0066) tmp = y * x; elseif (x <= 5.1e-138) tmp = -z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.0066], N[(y * x), $MachinePrecision], If[LessEqual[x, 5.1e-138], (-z), N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0066:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 5.1 \cdot 10^{-138}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -0.0066 or 5.1000000000000002e-138 < x Initial program 95.8%
Taylor expanded in y around inf 54.4%
if -0.0066 < x < 5.1000000000000002e-138Initial program 99.9%
Taylor expanded in x around 0 77.8%
mul-1-neg77.8%
Simplified77.8%
Final simplification62.4%
(FPCore (x y z) :precision binary64 (- (* (+ y z) x) z))
double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y + z) * x) - z
end function
public static double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
def code(x, y, z): return ((y + z) * x) - z
function code(x, y, z) return Float64(Float64(Float64(y + z) * x) - z) end
function tmp = code(x, y, z) tmp = ((y + z) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + z\right) \cdot x - z
\end{array}
Initial program 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
unsub-neg97.2%
associate-+r-97.2%
distribute-lft-out99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 97.2%
Taylor expanded in x around 0 32.4%
mul-1-neg32.4%
Simplified32.4%
Final simplification32.4%
herbie shell --seed 2023297
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))