
(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 6 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 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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 + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.0)
(* x z)
(if (<= x -2.6e-101)
(- z)
(if (<= x -2.65e-142)
(* x y)
(if (<= x 2.65e-17)
(- z)
(if (or (<= x 480000.0) (not (<= x 1.06e+64))) (* x y) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= -2.6e-101) {
tmp = -z;
} else if (x <= -2.65e-142) {
tmp = x * y;
} else if (x <= 2.65e-17) {
tmp = -z;
} else if ((x <= 480000.0) || !(x <= 1.06e+64)) {
tmp = x * y;
} else {
tmp = 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 <= (-1.0d0)) then
tmp = x * z
else if (x <= (-2.6d-101)) then
tmp = -z
else if (x <= (-2.65d-142)) then
tmp = x * y
else if (x <= 2.65d-17) then
tmp = -z
else if ((x <= 480000.0d0) .or. (.not. (x <= 1.06d+64))) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= -2.6e-101) {
tmp = -z;
} else if (x <= -2.65e-142) {
tmp = x * y;
} else if (x <= 2.65e-17) {
tmp = -z;
} else if ((x <= 480000.0) || !(x <= 1.06e+64)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = x * z elif x <= -2.6e-101: tmp = -z elif x <= -2.65e-142: tmp = x * y elif x <= 2.65e-17: tmp = -z elif (x <= 480000.0) or not (x <= 1.06e+64): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * z); elseif (x <= -2.6e-101) tmp = Float64(-z); elseif (x <= -2.65e-142) tmp = Float64(x * y); elseif (x <= 2.65e-17) tmp = Float64(-z); elseif ((x <= 480000.0) || !(x <= 1.06e+64)) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.0) tmp = x * z; elseif (x <= -2.6e-101) tmp = -z; elseif (x <= -2.65e-142) tmp = x * y; elseif (x <= 2.65e-17) tmp = -z; elseif ((x <= 480000.0) || ~((x <= 1.06e+64))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.6e-101], (-z), If[LessEqual[x, -2.65e-142], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.65e-17], (-z), If[Or[LessEqual[x, 480000.0], N[Not[LessEqual[x, 1.06e+64]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-101}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq -2.65 \cdot 10^{-142}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.65 \cdot 10^{-17}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 480000 \lor \neg \left(x \leq 1.06 \cdot 10^{+64}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1 or 4.8e5 < x < 1.06e64Initial program 96.1%
Taylor expanded in y around 0 66.1%
Taylor expanded in x around inf 65.0%
*-commutative65.0%
Simplified65.0%
if -1 < x < -2.6000000000000001e-101 or -2.6499999999999999e-142 < x < 2.6499999999999999e-17Initial program 100.0%
Taylor expanded in x around 0 84.6%
mul-1-neg84.6%
Simplified84.6%
if -2.6000000000000001e-101 < x < -2.6499999999999999e-142 or 2.6499999999999999e-17 < x < 4.8e5 or 1.06e64 < x Initial program 98.6%
Taylor expanded in y around inf 62.7%
Final simplification72.3%
(FPCore (x y z)
:precision binary64
(if (or (<= x -0.0012)
(not
(or (<= x -2.6e-101) (and (not (<= x -2.65e-142)) (<= x 2.45e-17)))))
(* x (+ y z))
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0012) || !((x <= -2.6e-101) || (!(x <= -2.65e-142) && (x <= 2.45e-17)))) {
tmp = x * (y + z);
} 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.0012d0)) .or. (.not. (x <= (-2.6d-101)) .or. (.not. (x <= (-2.65d-142))) .and. (x <= 2.45d-17))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0012) || !((x <= -2.6e-101) || (!(x <= -2.65e-142) && (x <= 2.45e-17)))) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0012) or not ((x <= -2.6e-101) or (not (x <= -2.65e-142) and (x <= 2.45e-17))): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0012) || !((x <= -2.6e-101) || (!(x <= -2.65e-142) && (x <= 2.45e-17)))) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.0012) || ~(((x <= -2.6e-101) || (~((x <= -2.65e-142)) && (x <= 2.45e-17))))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0012], N[Not[Or[LessEqual[x, -2.6e-101], And[N[Not[LessEqual[x, -2.65e-142]], $MachinePrecision], LessEqual[x, 2.45e-17]]]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0012 \lor \neg \left(x \leq -2.6 \cdot 10^{-101} \lor \neg \left(x \leq -2.65 \cdot 10^{-142}\right) \land x \leq 2.45 \cdot 10^{-17}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -0.00119999999999999989 or -2.6000000000000001e-101 < x < -2.6499999999999999e-142 or 2.45000000000000006e-17 < x Initial program 97.3%
Taylor expanded in x around inf 95.5%
+-commutative95.5%
Simplified95.5%
if -0.00119999999999999989 < x < -2.6000000000000001e-101 or -2.6499999999999999e-142 < x < 2.45000000000000006e-17Initial program 100.0%
Taylor expanded in x around 0 84.6%
mul-1-neg84.6%
Simplified84.6%
Final simplification91.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -6e+24)
(and (not (<= x -9e-100))
(or (<= x -2.25e-142) (not (<= x 1.7e-27)))))
(* x (+ y z))
(* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e+24) || (!(x <= -9e-100) && ((x <= -2.25e-142) || !(x <= 1.7e-27)))) {
tmp = x * (y + z);
} 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 <= (-6d+24)) .or. (.not. (x <= (-9d-100))) .and. (x <= (-2.25d-142)) .or. (.not. (x <= 1.7d-27))) then
tmp = x * (y + z)
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 <= -6e+24) || (!(x <= -9e-100) && ((x <= -2.25e-142) || !(x <= 1.7e-27)))) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e+24) or (not (x <= -9e-100) and ((x <= -2.25e-142) or not (x <= 1.7e-27))): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e+24) || (!(x <= -9e-100) && ((x <= -2.25e-142) || !(x <= 1.7e-27)))) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e+24) || (~((x <= -9e-100)) && ((x <= -2.25e-142) || ~((x <= 1.7e-27))))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e+24], And[N[Not[LessEqual[x, -9e-100]], $MachinePrecision], Or[LessEqual[x, -2.25e-142], N[Not[LessEqual[x, 1.7e-27]], $MachinePrecision]]]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{+24} \lor \neg \left(x \leq -9 \cdot 10^{-100}\right) \land \left(x \leq -2.25 \cdot 10^{-142} \lor \neg \left(x \leq 1.7 \cdot 10^{-27}\right)\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -5.9999999999999999e24 or -9.0000000000000002e-100 < x < -2.25000000000000009e-142 or 1.69999999999999985e-27 < x Initial program 97.3%
Taylor expanded in x around inf 95.5%
+-commutative95.5%
Simplified95.5%
if -5.9999999999999999e24 < x < -9.0000000000000002e-100 or -2.25000000000000009e-142 < x < 1.69999999999999985e-27Initial program 100.0%
Taylor expanded in y around 0 86.5%
Final simplification91.7%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.15e+46)
(and (not (<= x -2.75e-101))
(or (<= x -2.65e-142) (not (<= x 1.62e-18)))))
(* x y)
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e+46) || (!(x <= -2.75e-101) && ((x <= -2.65e-142) || !(x <= 1.62e-18)))) {
tmp = x * y;
} 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 <= (-1.15d+46)) .or. (.not. (x <= (-2.75d-101))) .and. (x <= (-2.65d-142)) .or. (.not. (x <= 1.62d-18))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e+46) || (!(x <= -2.75e-101) && ((x <= -2.65e-142) || !(x <= 1.62e-18)))) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.15e+46) or (not (x <= -2.75e-101) and ((x <= -2.65e-142) or not (x <= 1.62e-18))): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.15e+46) || (!(x <= -2.75e-101) && ((x <= -2.65e-142) || !(x <= 1.62e-18)))) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.15e+46) || (~((x <= -2.75e-101)) && ((x <= -2.65e-142) || ~((x <= 1.62e-18))))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.15e+46], And[N[Not[LessEqual[x, -2.75e-101]], $MachinePrecision], Or[LessEqual[x, -2.65e-142], N[Not[LessEqual[x, 1.62e-18]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+46} \lor \neg \left(x \leq -2.75 \cdot 10^{-101}\right) \land \left(x \leq -2.65 \cdot 10^{-142} \lor \neg \left(x \leq 1.62 \cdot 10^{-18}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.15e46 or -2.74999999999999986e-101 < x < -2.6499999999999999e-142 or 1.62000000000000005e-18 < x Initial program 97.2%
Taylor expanded in y around inf 53.3%
if -1.15e46 < x < -2.74999999999999986e-101 or -2.6499999999999999e-142 < x < 1.62000000000000005e-18Initial program 100.0%
Taylor expanded in x around 0 81.1%
mul-1-neg81.1%
Simplified81.1%
Final simplification65.3%
(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 98.4%
Taylor expanded in x around 0 38.5%
mul-1-neg38.5%
Simplified38.5%
Final simplification38.5%
herbie shell --seed 2024079
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))